Mercurial > hg > truffle
diff 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 |
line wrap: on
line diff
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java Tue Jan 27 20:28:19 2015 -0800 +++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java Tue Jan 27 20:28:43 2015 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,17 +24,21 @@ import java.io.*; import java.math.*; +import java.util.Scanner; import com.oracle.truffle.api.*; import com.oracle.truffle.api.dsl.*; +import com.oracle.truffle.api.instrument.*; import com.oracle.truffle.api.nodes.*; import com.oracle.truffle.api.source.*; +import com.oracle.truffle.api.tools.*; import com.oracle.truffle.sl.builtins.*; import com.oracle.truffle.sl.factory.*; import com.oracle.truffle.sl.nodes.*; import com.oracle.truffle.sl.nodes.call.*; import com.oracle.truffle.sl.nodes.controlflow.*; import com.oracle.truffle.sl.nodes.expression.*; +import com.oracle.truffle.sl.nodes.instrument.*; import com.oracle.truffle.sl.nodes.local.*; import com.oracle.truffle.sl.parser.*; import com.oracle.truffle.sl.runtime.*; @@ -111,9 +115,29 @@ * argument and adds them to the function registry. Functions that are already defined are replaced * with the new version. * </ul> + * + * <p> + * <b>Tools:</b><br> + * The use of some of Truffle's support for developer tools (based on the Truffle Instrumentation + * Framework) are demonstrated in this file, for example: + * <ul> + * <li>a {@linkplain NodeExecCounter counter for node executions}, tabulated by node type; and</li> + * <li>a simple {@linkplain CoverageTracker code coverage engine}.</li> + * </ul> + * In each case, the tool is enabled if a corresponding local boolean variable in this file is set + * to {@code true}. Results are printed at the end of the execution using each tool's + * <em>default printer</em>. + * */ public class SLMain { + /* Demonstrate per-type tabulation of node execution counts */ + private static boolean nodeExecCounts = false; + /* Demonstrate per-line tabulation of STATEMENT node execution counts */ + private static boolean statementCounts = false; + /* Demonstrate per-line tabulation of STATEMENT coverage */ + private static boolean coverage = false; + /** * The main entry point. Use the mx command "mx sl" to run it with the correct class path setup. */ @@ -146,6 +170,28 @@ // logOutput.println("Source = " + source.getCode()); } + if (statementCounts || coverage) { + Probe.registerASTProber(new SLStandardASTProber()); + } + + NodeExecCounter nodeExecCounter = null; + if (nodeExecCounts) { + nodeExecCounter = new NodeExecCounter(); + nodeExecCounter.install(); + } + + NodeExecCounter statementExecCounter = null; + if (statementCounts) { + statementExecCounter = new NodeExecCounter(StandardSyntaxTag.STATEMENT); + statementExecCounter.install(); + } + + CoverageTracker coverageTracker = null; + if (coverage) { + coverageTracker = new CoverageTracker(); + coverageTracker.install(); + } + /* Parse the SL source file. */ Parser.parseSL(context, source); @@ -187,6 +233,18 @@ } finally { printScript("after execution", context, logOutput, printASTToLog, printSourceAttributionToLog, dumpASTToIGV); } + if (nodeExecCounter != null) { + nodeExecCounter.print(System.out); + nodeExecCounter.dispose(); + } + if (statementExecCounter != null) { + statementExecCounter.print(System.out); + statementExecCounter.dispose(); + } + if (coverageTracker != null) { + coverageTracker.print(System.out); + coverageTracker.dispose(); + } return totalRuntime; } @@ -282,4 +340,5 @@ } return result.toString(); } + }