Mercurial > hg > truffle
comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java @ 21686:5fa7935c5de3
Truffle/Instrumentation: fix the small tool demonstration in SL
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Tue, 02 Jun 2015 17:41:19 -0700 |
parents | 1c76a5662753 |
children | ed234a3178af |
comparison
equal
deleted
inserted
replaced
21685:fd8a92655fbd | 21686:5fa7935c5de3 |
---|---|
137 public class SLMain extends TruffleLanguage { | 137 public class SLMain extends TruffleLanguage { |
138 private static SLMain LAST; | 138 private static SLMain LAST; |
139 private static List<NodeFactory<? extends SLBuiltinNode>> builtins = Collections.emptyList(); | 139 private static List<NodeFactory<? extends SLBuiltinNode>> builtins = Collections.emptyList(); |
140 private final SLContext context; | 140 private final SLContext context; |
141 | 141 |
142 /* Small tools that can be demonstrated */ | |
143 NodeExecCounter nodeExecCounter = null; | |
144 NodeExecCounter statementExecCounter = null; | |
145 CoverageTracker coverageTracker = null; | |
146 | |
147 public SLMain(Env env) { | 142 public SLMain(Env env) { |
148 super(env); | 143 super(env); |
149 context = SLContextFactory.create(new BufferedReader(env().stdIn()), new PrintWriter(env().stdOut(), true)); | 144 context = SLContextFactory.create(new BufferedReader(env().stdIn()), new PrintWriter(env().stdOut(), true)); |
150 LAST = this; | 145 LAST = this; |
151 for (NodeFactory<? extends SLBuiltinNode> builtin : builtins) { | 146 for (NodeFactory<? extends SLBuiltinNode> builtin : builtins) { |
152 context.installBuiltin(builtin); | 147 context.installBuiltin(builtin); |
153 } | 148 } |
154 } | 149 } |
155 | 150 |
156 /* Demonstrate per-type tabulation of node execution counts */ | 151 /* Enables demonstration of per-type tabulation of node execution counts */ |
157 private static boolean nodeExecCounts = false; | 152 private static boolean nodeExecCounts = false; |
158 /* Demonstrate per-line tabulation of STATEMENT node execution counts */ | 153 /* Enables demonstration of per-line tabulation of STATEMENT node execution counts */ |
159 private static boolean statementCounts = false; | 154 private static boolean statementCounts = false; |
160 /* Demonstrate per-line tabulation of STATEMENT coverage */ | 155 /* Enables demonstration of er-line tabulation of STATEMENT coverage */ |
161 private static boolean coverage = false; | 156 private static boolean coverage = false; |
157 | |
158 /* Small tools that can be installed for demonstration */ | |
159 private static NodeExecCounter nodeExecCounter = null; | |
160 private static NodeExecCounter statementExecCounter = null; | |
161 private static CoverageTracker coverageTracker = null; | |
162 | 162 |
163 /** | 163 /** |
164 * The main entry point. Use the mx command "mx sl" to run it with the correct class path setup. | 164 * The main entry point. Use the mx command "mx sl" to run it with the correct class path setup. |
165 * <p> | |
166 * Obsolete: being replaced with new TruffleLanguage API | |
167 */ | 165 */ |
168 @Deprecated | |
169 public static void main(String[] args) throws IOException { | 166 public static void main(String[] args) throws IOException { |
170 TruffleVM vm = TruffleVM.newVM().build(); | 167 TruffleVM vm = TruffleVM.newVM().build(); |
171 assert vm.getLanguages().containsKey("application/x-sl"); | 168 assert vm.getLanguages().containsKey("application/x-sl"); |
169 | |
170 setupToolDemos(); | |
172 | 171 |
173 int repeats = 1; | 172 int repeats = 1; |
174 if (args.length >= 2) { | 173 if (args.length >= 2) { |
175 repeats = Integer.parseInt(args[1]); | 174 repeats = Integer.parseInt(args[1]); |
176 } | 175 } |
185 throw new SLException("No function main() defined in SL source file."); | 184 throw new SLException("No function main() defined in SL source file."); |
186 } | 185 } |
187 while (repeats-- > 0) { | 186 while (repeats-- > 0) { |
188 main.invoke(null); | 187 main.invoke(null); |
189 } | 188 } |
189 reportToolDemos(); | |
190 } | 190 } |
191 | 191 |
192 /** | 192 /** |
193 * Temporary method during API evolution, supports debugger integration. | 193 * Temporary method during API evolution, supports debugger integration. |
194 */ | 194 */ |
357 return result.toString(); | 357 return result.toString(); |
358 } | 358 } |
359 | 359 |
360 @Override | 360 @Override |
361 protected Object eval(Source code) throws IOException { | 361 protected Object eval(Source code) throws IOException { |
362 | |
363 setupToolDemos(); | |
364 context.executeMain(code); | 362 context.executeMain(code); |
365 reportToolDemos(); | |
366 return null; | 363 return null; |
367 } | 364 } |
368 | 365 |
369 @Override | 366 @Override |
370 protected Object findExportedSymbol(String globalName) { | 367 protected Object findExportedSymbol(String globalName) { |
384 @Override | 381 @Override |
385 protected boolean isObjectOfLanguage(Object object) { | 382 protected boolean isObjectOfLanguage(Object object) { |
386 return object instanceof SLFunction; | 383 return object instanceof SLFunction; |
387 } | 384 } |
388 | 385 |
389 private void setupToolDemos() { | 386 private static void setupToolDemos() { |
390 if (statementCounts || coverage) { | 387 if (statementCounts || coverage) { |
391 Probe.registerASTProber(new SLStandardASTProber()); | 388 Probe.registerASTProber(new SLStandardASTProber()); |
392 } | 389 } |
393 if (nodeExecCounts) { | 390 if (nodeExecCounts) { |
394 nodeExecCounter = new NodeExecCounter(); | 391 nodeExecCounter = new NodeExecCounter(); |
404 coverageTracker = new CoverageTracker(); | 401 coverageTracker = new CoverageTracker(); |
405 coverageTracker.install(); | 402 coverageTracker.install(); |
406 } | 403 } |
407 } | 404 } |
408 | 405 |
409 private void reportToolDemos() { | 406 private static void reportToolDemos() { |
410 if (nodeExecCounter != null) { | 407 if (nodeExecCounter != null) { |
411 nodeExecCounter.print(System.out); | 408 nodeExecCounter.print(System.out); |
412 nodeExecCounter.dispose(); | 409 nodeExecCounter.dispose(); |
413 } | 410 } |
414 if (statementExecCounter != null) { | 411 if (statementExecCounter != null) { |