diff graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/impl/DefaultVisualizer.java @ 15450:be0c151d912b

Truffle/Instrumentation: API revisions
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Tue, 29 Apr 2014 12:05:58 -0700
parents 0c6d8a08e31b
children 8f09b84f325f
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/impl/DefaultVisualizer.java	Tue Apr 22 18:32:08 2014 -0700
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/instrument/impl/DefaultVisualizer.java	Tue Apr 29 12:05:58 2014 -0700
@@ -24,8 +24,12 @@
  */
 package com.oracle.truffle.api.instrument.impl;
 
+import java.io.*;
+
+import com.oracle.truffle.api.*;
 import com.oracle.truffle.api.frame.*;
 import com.oracle.truffle.api.instrument.*;
+import com.oracle.truffle.api.nodes.*;
 
 public class DefaultVisualizer implements Visualizer {
 
@@ -39,6 +43,43 @@
         return astPrinter;
     }
 
+    public String displaySourceLocation(Node node) {
+        if (node == null) {
+            return "<unknown>";
+        }
+        SourceSection section = node.getSourceSection();
+        boolean estimated = false;
+        if (section == null) {
+            section = node.getEncapsulatingSourceSection();
+            estimated = true;
+        }
+
+        String sourceString;
+        if (section == null || section.getSource() == null) {
+            sourceString = "<unknown source>";
+        } else {
+            String sourceName = new File(section.getSource().getName()).getName();
+            int startLine = section.getStartLine();
+            sourceString = String.format("%s:%d%s", sourceName, startLine, estimated ? "~" : "");
+        }
+        return sourceString;
+    }
+
+    public String displayMethodName(Node node) {
+        if (node == null) {
+            return null;
+        }
+        RootNode root = node.getRootNode();
+        if (root == null) {
+            return "unknown";
+        }
+        return root.getCallTarget().toString();
+    }
+
+    public String displayCallTargetName(CallTarget callTarget) {
+        return callTarget.toString();
+    }
+
     public String displayValue(Object value) {
         return value.toString();
     }