Permalink
Browse files

Make it possible to control bytecode printing from the command line

  • Loading branch information...
1 parent 4402709 commit d57cd587ac3516a7e43736a908b6bde7f36ef202 @olabini olabini committed Jul 29, 2011
@@ -0,0 +1,12 @@
+
+flat_short_scope_control = #(
+ x = 42
+)
+
+flat_short_scope = #(
+ x = 42
+ x. x. x. x. x. x. x. x. x. x. x. x. x. x. x. x. x. x. x. x.
+)
+
+benchmark("control", 10, 10000000, flat_short_scope_control)
+benchmark("variable reading", 10, 10000000, flat_short_scope)
@@ -14,15 +14,17 @@
public class Main {
private final static String HELP =
"Usage: seph [switches] -- [programfile] [arguments]\n" +
- " -h, --help help, this message\n" +
- " --tco force tail call optimization to be on [default: " + (SephConfig.DEFAULT_TAIL_CALL_OPTIMIZATION ? "on" : "off") + "]\n" +
- " --notco force tail call optimization to be off [default: " + (SephConfig.DEFAULT_TAIL_CALL_OPTIMIZATION ? "on" : "off") + "]\n" +
- " --lexmh force lexical lookup with method handles to be on [default: " + (SephConfig.DEFAULT_LEXICAL_METHOD_HANDLE_LOOKUP ? "on" : "off") + "]\n" +
- " --nolexmh force lexical lookup with method handles to be off [default: " + (SephConfig.DEFAULT_LEXICAL_METHOD_HANDLE_LOOKUP ? "on" : "off") + "]\n" +
- " --lexinvokemh force lexical invoke with method handles to be on [default: " + (SephConfig.DEFAULT_LEXICAL_METHOD_HANDLE_INVOKE ? "on" : "off") + "]\n" +
- " --nolexinvokemh force lexical invoke with method handles to be off [default: " + (SephConfig.DEFAULT_LEXICAL_METHOD_HANDLE_INVOKE ? "on" : "off") + "]\n" +
- " --copyright print the copyright\n" +
- " --version print current version\n";
+ " -h, --help help, this message\n" +
+ " --tco force tail call optimization to be on [default: " + (SephConfig.DEFAULT_TAIL_CALL_OPTIMIZATION ? "on" : "off") + "]\n" +
+ " --notco force tail call optimization to be off [default: " + (SephConfig.DEFAULT_TAIL_CALL_OPTIMIZATION ? "on" : "off") + "]\n" +
+ " --lexmh force lexical lookup with method handles to be on [default: " + (SephConfig.DEFAULT_LEXICAL_METHOD_HANDLE_LOOKUP ? "on" : "off") + "]\n" +
+ " --nolexmh force lexical lookup with method handles to be off [default: " + (SephConfig.DEFAULT_LEXICAL_METHOD_HANDLE_LOOKUP ? "on" : "off") + "]\n" +
+ " --lexinvokemh force lexical invoke with method handles to be on [default: " + (SephConfig.DEFAULT_LEXICAL_METHOD_HANDLE_INVOKE ? "on" : "off") + "]\n" +
+ " --nolexinvokemh force lexical invoke with method handles to be off [default: " + (SephConfig.DEFAULT_LEXICAL_METHOD_HANDLE_INVOKE ? "on" : "off") + "]\n" +
+ " --printbytecode force printing of bytecode to be on [default: " + (SephConfig.DEFAULT_PRINT_BYTECODE ? "on" : "off") + "]\n" +
+ " --noprintbytecode force printing of bytecode to be off [default: " + (SephConfig.DEFAULT_PRINT_BYTECODE ? "on" : "off") + "]\n" +
+ " --copyright print the copyright\n" +
+ " --version print current version\n";
public static void main(String[] args) throws Throwable {
int start = 0;
@@ -31,7 +33,7 @@ public static void main(String[] args) throws Throwable {
boolean tco = SephConfig.DEFAULT_TAIL_CALL_OPTIMIZATION;
boolean lexmh = SephConfig.DEFAULT_LEXICAL_METHOD_HANDLE_LOOKUP;
boolean lexinvokemh = SephConfig.DEFAULT_LEXICAL_METHOD_HANDLE_INVOKE;
-
+ boolean printBytecode = SephConfig.DEFAULT_PRINT_BYTECODE;
for(;!done && start<args.length;start++) {
String arg = args[start];
@@ -63,6 +65,10 @@ public static void main(String[] args) throws Throwable {
lexinvokemh = true;
} else if(arg.equals("--nolexinvokemh")) {
lexinvokemh = false;
+ } else if(arg.equals("--printbytecode")) {
+ printBytecode = true;
+ } else if(arg.equals("--noprintbytecode")) {
+ printBytecode = false;
} else {
System.err.println("Couldn't understand option: " + arg);
return;
@@ -82,7 +88,7 @@ public static void main(String[] args) throws Throwable {
file = file.substring(0, file.length()-1);
}
- SephConfig config = new SephConfig(tco, lexmh, lexinvokemh);
+ SephConfig config = new SephConfig(tco, lexmh, lexinvokemh, printBytecode);
Runtime r = new Runtime(config);
r.evaluateFile(file);
}
@@ -10,34 +10,38 @@
private final boolean tco;
private final boolean lexmh;
private final boolean lexinvokemh;
+ private final boolean printBytecode;
public final static boolean DEFAULT_TAIL_CALL_OPTIMIZATION = true;
public final static boolean DEFAULT_LEXICAL_METHOD_HANDLE_LOOKUP = true;
public final static boolean DEFAULT_LEXICAL_METHOD_HANDLE_INVOKE = true;
+ public final static boolean DEFAULT_PRINT_BYTECODE = false;
public SephConfig() {
this(DEFAULT_TAIL_CALL_OPTIMIZATION,
DEFAULT_LEXICAL_METHOD_HANDLE_LOOKUP,
- DEFAULT_LEXICAL_METHOD_HANDLE_INVOKE);
+ DEFAULT_LEXICAL_METHOD_HANDLE_INVOKE,
+ DEFAULT_PRINT_BYTECODE);
}
- public SephConfig(boolean tco, boolean lexmh, boolean lexinvokemh) {
+ public SephConfig(boolean tco, boolean lexmh, boolean lexinvokemh, boolean printBytecode) {
this.tco = tco;
this.lexmh = lexmh;
this.lexinvokemh = lexinvokemh;
+ this.printBytecode = printBytecode;
}
public boolean doTailCallOptimization() {
return tco;
}
public SephConfig withTailCallOptimization() {
- return new SephConfig(true, lexmh, lexinvokemh);
+ return new SephConfig(true, lexmh, lexinvokemh, printBytecode);
}
public SephConfig withoutTailCallOptimization() {
- return new SephConfig(false, lexmh, lexinvokemh);
+ return new SephConfig(false, lexmh, lexinvokemh, printBytecode);
}
@@ -47,11 +51,11 @@ public boolean doLexicalMethodHandleLookup() {
}
public SephConfig withLexicalMethodHandleLookup() {
- return new SephConfig(tco, true, lexinvokemh);
+ return new SephConfig(tco, true, lexinvokemh, printBytecode);
}
public SephConfig withoutLexicalMethodHandleLookup() {
- return new SephConfig(tco, false, lexinvokemh);
+ return new SephConfig(tco, false, lexinvokemh, printBytecode);
}
@@ -61,10 +65,24 @@ public boolean doLexicalMethodHandleInvoke() {
}
public SephConfig withLexicalMethodHandleInvoke() {
- return new SephConfig(tco, lexmh, true);
+ return new SephConfig(tco, lexmh, true, printBytecode);
}
public SephConfig withoutLexicalMethodHandleInvoke() {
- return new SephConfig(tco, lexmh, false);
+ return new SephConfig(tco, lexmh, false, printBytecode);
+ }
+
+
+
+ public boolean doPrintBytecode() {
+ return printBytecode;
+ }
+
+ public SephConfig withPrintBytecode() {
+ return new SephConfig(tco, lexmh, lexinvokemh, true);
+ }
+
+ public SephConfig withoutPrintBytecode() {
+ return new SephConfig(tco, lexmh, lexinvokemh, false);
}
}// SephConfig
@@ -146,7 +146,7 @@ private void generateAbstractionClass() {
final byte[] classBytes = cw.toByteArray();
- if(printThisClass || PRINT_COMPILE) {
+ if(printThisClass || PRINT_COMPILE || runtime.configuration().doPrintBytecode()) {
new ClassReader(classBytes).accept(new org.objectweb.asm.util.TraceClassVisitor(new java.io.PrintWriter(System.err)), 0);
// try {
// java.io.FileOutputStream ff = new java.io.FileOutputStream(className + ".class");

0 comments on commit d57cd58

Please sign in to comment.