Mercurial > hg > graal-compiler
comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java @ 21649:1c76a5662753
Merge with 645f170013a451083414ff695412c465e9d2ebf0
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Mon, 01 Jun 2015 17:47:28 -0700 |
parents | a880844225e4 |
children | 5fa7935c5de3 |
comparison
equal
deleted
inserted
replaced
21648:610d76a131cd | 21649:1c76a5662753 |
---|---|
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 | |
142 public SLMain(Env env) { | 147 public SLMain(Env env) { |
143 super(env); | 148 super(env); |
144 context = SLContextFactory.create(new BufferedReader(env().stdIn()), new PrintWriter(env().stdOut(), true)); | 149 context = SLContextFactory.create(new BufferedReader(env().stdIn()), new PrintWriter(env().stdOut(), true)); |
145 LAST = this; | 150 LAST = this; |
146 for (NodeFactory<? extends SLBuiltinNode> builtin : builtins) { | 151 for (NodeFactory<? extends SLBuiltinNode> builtin : builtins) { |
155 /* Demonstrate per-line tabulation of STATEMENT coverage */ | 160 /* Demonstrate per-line tabulation of STATEMENT coverage */ |
156 private static boolean coverage = false; | 161 private static boolean coverage = false; |
157 | 162 |
158 /** | 163 /** |
159 * 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 | |
160 */ | 167 */ |
168 @Deprecated | |
161 public static void main(String[] args) throws IOException { | 169 public static void main(String[] args) throws IOException { |
162 TruffleVM vm = TruffleVM.newVM().build(); | 170 TruffleVM vm = TruffleVM.newVM().build(); |
163 assert vm.getLanguages().containsKey("application/x-sl"); | 171 assert vm.getLanguages().containsKey("application/x-sl"); |
164 | 172 |
165 int repeats = 1; | 173 int repeats = 1; |
179 while (repeats-- > 0) { | 187 while (repeats-- > 0) { |
180 main.invoke(null); | 188 main.invoke(null); |
181 } | 189 } |
182 } | 190 } |
183 | 191 |
192 /** | |
193 * Temporary method during API evolution, supports debugger integration. | |
194 */ | |
184 public static void run(Source source) throws IOException { | 195 public static void run(Source source) throws IOException { |
185 TruffleVM vm = TruffleVM.newVM().build(); | 196 TruffleVM vm = TruffleVM.newVM().build(); |
186 assert vm.getLanguages().containsKey("application/x-sl"); | 197 assert vm.getLanguages().containsKey("application/x-sl"); |
187 vm.eval(new File(source.getPath()).toURI()); | 198 vm.eval(new File(source.getPath()).toURI()); |
188 Symbol main = vm.findGlobalSymbol("main"); | 199 Symbol main = vm.findGlobalSymbol("main"); |
200 builtins = currentBuiltins; | 211 builtins = currentBuiltins; |
201 | 212 |
202 if (logOutput != null) { | 213 if (logOutput != null) { |
203 logOutput.println("== running on " + Truffle.getRuntime().getName()); | 214 logOutput.println("== running on " + Truffle.getRuntime().getName()); |
204 // logOutput.println("Source = " + source.getCode()); | 215 // logOutput.println("Source = " + source.getCode()); |
205 } | |
206 | |
207 if (statementCounts || coverage) { | |
208 Probe.registerASTProber(new SLStandardASTProber()); | |
209 } | |
210 | |
211 NodeExecCounter nodeExecCounter = null; | |
212 if (nodeExecCounts) { | |
213 nodeExecCounter = new NodeExecCounter(); | |
214 nodeExecCounter.install(); | |
215 } | |
216 | |
217 NodeExecCounter statementExecCounter = null; | |
218 if (statementCounts) { | |
219 statementExecCounter = new NodeExecCounter(StandardSyntaxTag.STATEMENT); | |
220 statementExecCounter.install(); | |
221 } | |
222 | |
223 CoverageTracker coverageTracker = null; | |
224 if (coverage) { | |
225 coverageTracker = new CoverageTracker(); | |
226 coverageTracker.install(); | |
227 } | 216 } |
228 | 217 |
229 /* Parse the SL source file. */ | 218 /* Parse the SL source file. */ |
230 Object result = context.eval(source); | 219 Object result = context.eval(source); |
231 if (result != null) { | 220 if (result != null) { |
270 } | 259 } |
271 | 260 |
272 } finally { | 261 } finally { |
273 printScript("after execution", LAST.context, logOutput, printASTToLog, printSourceAttributionToLog, dumpASTToIGV); | 262 printScript("after execution", LAST.context, logOutput, printASTToLog, printSourceAttributionToLog, dumpASTToIGV); |
274 } | 263 } |
275 if (nodeExecCounter != null) { | |
276 nodeExecCounter.print(System.out); | |
277 nodeExecCounter.dispose(); | |
278 } | |
279 if (statementExecCounter != null) { | |
280 statementExecCounter.print(System.out); | |
281 statementExecCounter.dispose(); | |
282 } | |
283 if (coverageTracker != null) { | |
284 coverageTracker.print(System.out); | |
285 coverageTracker.dispose(); | |
286 } | |
287 return totalRuntime; | 264 return totalRuntime; |
288 } | 265 } |
289 | 266 |
290 /** | 267 /** |
291 * When dumpASTToIGV is true: dumps the AST of all functions to the IGV visualizer, via a socket | 268 * When dumpASTToIGV is true: dumps the AST of all functions to the IGV visualizer, via a socket |
380 return result.toString(); | 357 return result.toString(); |
381 } | 358 } |
382 | 359 |
383 @Override | 360 @Override |
384 protected Object eval(Source code) throws IOException { | 361 protected Object eval(Source code) throws IOException { |
362 | |
363 setupToolDemos(); | |
385 context.executeMain(code); | 364 context.executeMain(code); |
365 reportToolDemos(); | |
386 return null; | 366 return null; |
387 } | 367 } |
388 | 368 |
389 @Override | 369 @Override |
390 protected Object findExportedSymbol(String globalName) { | 370 protected Object findExportedSymbol(String globalName) { |
404 @Override | 384 @Override |
405 protected boolean isObjectOfLanguage(Object object) { | 385 protected boolean isObjectOfLanguage(Object object) { |
406 return object instanceof SLFunction; | 386 return object instanceof SLFunction; |
407 } | 387 } |
408 | 388 |
389 private void setupToolDemos() { | |
390 if (statementCounts || coverage) { | |
391 Probe.registerASTProber(new SLStandardASTProber()); | |
392 } | |
393 if (nodeExecCounts) { | |
394 nodeExecCounter = new NodeExecCounter(); | |
395 nodeExecCounter.install(); | |
396 } | |
397 | |
398 if (statementCounts) { | |
399 statementExecCounter = new NodeExecCounter(StandardSyntaxTag.STATEMENT); | |
400 statementExecCounter.install(); | |
401 } | |
402 | |
403 if (coverage) { | |
404 coverageTracker = new CoverageTracker(); | |
405 coverageTracker.install(); | |
406 } | |
407 } | |
408 | |
409 private void reportToolDemos() { | |
410 if (nodeExecCounter != null) { | |
411 nodeExecCounter.print(System.out); | |
412 nodeExecCounter.dispose(); | |
413 } | |
414 if (statementExecCounter != null) { | |
415 statementExecCounter.print(System.out); | |
416 statementExecCounter.dispose(); | |
417 } | |
418 if (coverageTracker != null) { | |
419 coverageTracker.print(System.out); | |
420 coverageTracker.dispose(); | |
421 } | |
422 } | |
423 | |
409 } | 424 } |