Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java @ 18990:d1c1cd2530d7
Truffle/Instrumentation: clean up and repair some old unit tests
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Tue, 27 Jan 2015 20:28:43 -0800 |
parents | cfb85e1f4ca5 |
children | 2170de9acab0 |
comparison
equal
deleted
inserted
replaced
18989:acd822f17ef5 | 18990:d1c1cd2530d7 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
22 */ | 22 */ |
23 package com.oracle.truffle.sl; | 23 package com.oracle.truffle.sl; |
24 | 24 |
25 import java.io.*; | 25 import java.io.*; |
26 import java.math.*; | 26 import java.math.*; |
27 import java.util.Scanner; | |
27 | 28 |
28 import com.oracle.truffle.api.*; | 29 import com.oracle.truffle.api.*; |
29 import com.oracle.truffle.api.dsl.*; | 30 import com.oracle.truffle.api.dsl.*; |
31 import com.oracle.truffle.api.instrument.*; | |
30 import com.oracle.truffle.api.nodes.*; | 32 import com.oracle.truffle.api.nodes.*; |
31 import com.oracle.truffle.api.source.*; | 33 import com.oracle.truffle.api.source.*; |
34 import com.oracle.truffle.api.tools.*; | |
32 import com.oracle.truffle.sl.builtins.*; | 35 import com.oracle.truffle.sl.builtins.*; |
33 import com.oracle.truffle.sl.factory.*; | 36 import com.oracle.truffle.sl.factory.*; |
34 import com.oracle.truffle.sl.nodes.*; | 37 import com.oracle.truffle.sl.nodes.*; |
35 import com.oracle.truffle.sl.nodes.call.*; | 38 import com.oracle.truffle.sl.nodes.call.*; |
36 import com.oracle.truffle.sl.nodes.controlflow.*; | 39 import com.oracle.truffle.sl.nodes.controlflow.*; |
37 import com.oracle.truffle.sl.nodes.expression.*; | 40 import com.oracle.truffle.sl.nodes.expression.*; |
41 import com.oracle.truffle.sl.nodes.instrument.*; | |
38 import com.oracle.truffle.sl.nodes.local.*; | 42 import com.oracle.truffle.sl.nodes.local.*; |
39 import com.oracle.truffle.sl.parser.*; | 43 import com.oracle.truffle.sl.parser.*; |
40 import com.oracle.truffle.sl.runtime.*; | 44 import com.oracle.truffle.sl.runtime.*; |
41 | 45 |
42 /** | 46 /** |
109 * nanoseconds. | 113 * nanoseconds. |
110 * <li>{@link SLDefineFunctionBuiltin defineFunction}: Parses the functions provided as a String | 114 * <li>{@link SLDefineFunctionBuiltin defineFunction}: Parses the functions provided as a String |
111 * argument and adds them to the function registry. Functions that are already defined are replaced | 115 * argument and adds them to the function registry. Functions that are already defined are replaced |
112 * with the new version. | 116 * with the new version. |
113 * </ul> | 117 * </ul> |
118 * | |
119 * <p> | |
120 * <b>Tools:</b><br> | |
121 * The use of some of Truffle's support for developer tools (based on the Truffle Instrumentation | |
122 * Framework) are demonstrated in this file, for example: | |
123 * <ul> | |
124 * <li>a {@linkplain NodeExecCounter counter for node executions}, tabulated by node type; and</li> | |
125 * <li>a simple {@linkplain CoverageTracker code coverage engine}.</li> | |
126 * </ul> | |
127 * In each case, the tool is enabled if a corresponding local boolean variable in this file is set | |
128 * to {@code true}. Results are printed at the end of the execution using each tool's | |
129 * <em>default printer</em>. | |
130 * | |
114 */ | 131 */ |
115 public class SLMain { | 132 public class SLMain { |
133 | |
134 /* Demonstrate per-type tabulation of node execution counts */ | |
135 private static boolean nodeExecCounts = false; | |
136 /* Demonstrate per-line tabulation of STATEMENT node execution counts */ | |
137 private static boolean statementCounts = false; | |
138 /* Demonstrate per-line tabulation of STATEMENT coverage */ | |
139 private static boolean coverage = false; | |
116 | 140 |
117 /** | 141 /** |
118 * The main entry point. Use the mx command "mx sl" to run it with the correct class path setup. | 142 * The main entry point. Use the mx command "mx sl" to run it with the correct class path setup. |
119 */ | 143 */ |
120 public static void main(String[] args) throws IOException { | 144 public static void main(String[] args) throws IOException { |
142 */ | 166 */ |
143 public static long run(SLContext context, Source source, PrintStream logOutput, int repeats) { | 167 public static long run(SLContext context, Source source, PrintStream logOutput, int repeats) { |
144 if (logOutput != null) { | 168 if (logOutput != null) { |
145 logOutput.println("== running on " + Truffle.getRuntime().getName()); | 169 logOutput.println("== running on " + Truffle.getRuntime().getName()); |
146 // logOutput.println("Source = " + source.getCode()); | 170 // logOutput.println("Source = " + source.getCode()); |
171 } | |
172 | |
173 if (statementCounts || coverage) { | |
174 Probe.registerASTProber(new SLStandardASTProber()); | |
175 } | |
176 | |
177 NodeExecCounter nodeExecCounter = null; | |
178 if (nodeExecCounts) { | |
179 nodeExecCounter = new NodeExecCounter(); | |
180 nodeExecCounter.install(); | |
181 } | |
182 | |
183 NodeExecCounter statementExecCounter = null; | |
184 if (statementCounts) { | |
185 statementExecCounter = new NodeExecCounter(StandardSyntaxTag.STATEMENT); | |
186 statementExecCounter.install(); | |
187 } | |
188 | |
189 CoverageTracker coverageTracker = null; | |
190 if (coverage) { | |
191 coverageTracker = new CoverageTracker(); | |
192 coverageTracker.install(); | |
147 } | 193 } |
148 | 194 |
149 /* Parse the SL source file. */ | 195 /* Parse the SL source file. */ |
150 Parser.parseSL(context, source); | 196 Parser.parseSL(context, source); |
151 | 197 |
184 } | 230 } |
185 } | 231 } |
186 | 232 |
187 } finally { | 233 } finally { |
188 printScript("after execution", context, logOutput, printASTToLog, printSourceAttributionToLog, dumpASTToIGV); | 234 printScript("after execution", context, logOutput, printASTToLog, printSourceAttributionToLog, dumpASTToIGV); |
235 } | |
236 if (nodeExecCounter != null) { | |
237 nodeExecCounter.print(System.out); | |
238 nodeExecCounter.dispose(); | |
239 } | |
240 if (statementExecCounter != null) { | |
241 statementExecCounter.print(System.out); | |
242 statementExecCounter.dispose(); | |
243 } | |
244 if (coverageTracker != null) { | |
245 coverageTracker.print(System.out); | |
246 coverageTracker.dispose(); | |
189 } | 247 } |
190 return totalRuntime; | 248 return totalRuntime; |
191 } | 249 } |
192 | 250 |
193 /** | 251 /** |
280 } | 338 } |
281 } | 339 } |
282 } | 340 } |
283 return result.toString(); | 341 return result.toString(); |
284 } | 342 } |
343 | |
285 } | 344 } |