Mercurial > hg > graal-jvmci-8
comparison graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java @ 13862:f9b934e1e172
SL: Make SL use the new UnsupportedSpecializationException#getSuppliedNodes() for error messages; Disabled dumping by default to IGV.
author | Christian Humer <christian.humer@gmail.com> |
---|---|
date | Mon, 03 Feb 2014 21:01:11 +0100 |
parents | 64c77f0577bb |
children | afd6fa5e8229 |
comparison
equal
deleted
inserted
replaced
13861:28479abd1a69 | 13862:f9b934e1e172 |
---|---|
152 throw new SLException("No function main() defined in SL source file."); | 152 throw new SLException("No function main() defined in SL source file."); |
153 } | 153 } |
154 | 154 |
155 /* Change to true if you want to see the AST on the console. */ | 155 /* Change to true if you want to see the AST on the console. */ |
156 boolean printASTToLog = false; | 156 boolean printASTToLog = false; |
157 | 157 /* Change to dump the AST to IGV over the network. */ |
158 printScript("before execution", context, logOutput, printASTToLog); | 158 boolean dumpASTToIGV = false; |
159 | |
160 printScript("before execution", context, logOutput, printASTToLog, dumpASTToIGV); | |
159 try { | 161 try { |
160 for (int i = 0; i < repeats; i++) { | 162 for (int i = 0; i < repeats; i++) { |
161 long start = System.nanoTime(); | 163 long start = System.nanoTime(); |
162 /* Call the main entry point, without any arguments. */ | 164 /* Call the main entry point, without any arguments. */ |
163 try { | 165 try { |
174 logOutput.println("== iteration " + (i + 1) + ": " + ((end - start) / 1000000) + " ms"); | 176 logOutput.println("== iteration " + (i + 1) + ": " + ((end - start) / 1000000) + " ms"); |
175 } | 177 } |
176 } | 178 } |
177 | 179 |
178 } finally { | 180 } finally { |
179 printScript("after execution", context, logOutput, printASTToLog); | 181 printScript("after execution", context, logOutput, printASTToLog, dumpASTToIGV); |
180 } | 182 } |
181 } | 183 } |
182 | 184 |
183 /** | 185 /** |
184 * Dumps the AST of all functions to the IGV visualizer, via a socket connection. IGV can be | 186 * Dumps the AST of all functions to the IGV visualizer, via a socket connection. IGV can be |
185 * started with the mx command "mx igv". Optionally, also prints the ASTs to the console. | 187 * started with the mx command "mx igv". Optionally, also prints the ASTs to the console. |
186 */ | 188 */ |
187 private static void printScript(String groupName, SLContext context, PrintStream logOutput, boolean printASTToLog) { | 189 private static void printScript(String groupName, SLContext context, PrintStream logOutput, boolean printASTToLog, boolean dumpASTToIGV) { |
188 GraphPrintVisitor graphPrinter = new GraphPrintVisitor(); | 190 if (dumpASTToIGV) { |
189 graphPrinter.beginGroup(groupName); | 191 GraphPrintVisitor graphPrinter = new GraphPrintVisitor(); |
190 for (SLFunction function : context.getFunctionRegistry().getFunctions()) { | 192 graphPrinter.beginGroup(groupName); |
191 RootCallTarget callTarget = function.getCallTarget(); | 193 for (SLFunction function : context.getFunctionRegistry().getFunctions()) { |
192 if (callTarget != null) { | 194 RootCallTarget callTarget = function.getCallTarget(); |
193 graphPrinter.beginGraph(function.toString()).visit(callTarget.getRootNode()); | 195 if (callTarget != null) { |
194 | 196 graphPrinter.beginGraph(function.toString()).visit(callTarget.getRootNode()); |
195 if (logOutput != null && printASTToLog) { | 197 } |
198 } | |
199 graphPrinter.printToNetwork(true); | |
200 } | |
201 if (printASTToLog && logOutput != null) { | |
202 for (SLFunction function : context.getFunctionRegistry().getFunctions()) { | |
203 RootCallTarget callTarget = function.getCallTarget(); | |
204 if (callTarget != null) { | |
196 logOutput.println("=== " + function); | 205 logOutput.println("=== " + function); |
197 NodeUtil.printTree(logOutput, callTarget.getRootNode()); | 206 NodeUtil.printTree(logOutput, callTarget.getRootNode()); |
198 } | 207 } |
199 } | 208 } |
200 } | 209 } |
201 graphPrinter.printToNetwork(true); | |
202 } | 210 } |
203 | 211 |
204 /** | 212 /** |
205 * Provides a user-readable message for run-time type errors. SL is strongly typed, i.e., there | 213 * Provides a user-readable message for run-time type errors. SL is strongly typed, i.e., there |
206 * are no automatic type conversions of values. Therefore, Truffle does the type checking for | 214 * are no automatic type conversions of values. Therefore, Truffle does the type checking for |
221 result.append(" \"").append(ex.getNode().getClass().getAnnotation(NodeInfo.class).shortName()).append("\""); | 229 result.append(" \"").append(ex.getNode().getClass().getAnnotation(NodeInfo.class).shortName()).append("\""); |
222 } | 230 } |
223 result.append(" not defined for"); | 231 result.append(" not defined for"); |
224 | 232 |
225 String sep = " "; | 233 String sep = " "; |
226 for (Object value : ex.getSuppliedValues()) { | 234 for (int i = 0; i < ex.getSuppliedValues().length; i++) { |
227 if (value != null) { | 235 Object value = ex.getSuppliedValues()[i]; |
236 Node node = ex.getSuppliedNodes()[i]; | |
237 if (node != null) { | |
228 result.append(sep); | 238 result.append(sep); |
229 sep = ", "; | 239 sep = ", "; |
230 | 240 |
231 if (value instanceof Long || value instanceof BigInteger) { | 241 if (value instanceof Long || value instanceof BigInteger) { |
232 result.append("Number ").append(value); | 242 result.append("Number ").append(value); |
236 result.append("String \"").append(value).append("\""); | 246 result.append("String \"").append(value).append("\""); |
237 } else if (value instanceof SLFunction) { | 247 } else if (value instanceof SLFunction) { |
238 result.append("Function ").append(value); | 248 result.append("Function ").append(value); |
239 } else if (value == SLNull.SINGLETON) { | 249 } else if (value == SLNull.SINGLETON) { |
240 result.append("NULL"); | 250 result.append("NULL"); |
251 } else if (value == null) { | |
252 // value is not evaluated because of short circuit evaluation | |
253 result.append("ANY"); | |
241 } else { | 254 } else { |
242 result.append(value); | 255 result.append(value); |
243 } | 256 } |
244 } | 257 } |
245 } | 258 } |