X-Git-Url: http://svarog.pmf.uns.ac.rs/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmjc2wsl.java;h=f754e4ef1d6c3cf719ca58c08bdb80fa06466ccf;hb=5ec7c0162c03b3229de5dd9bb5264b8f76ff695e;hp=77d1c2816e49705fcc0f29cd1f363ca0891025e6;hpb=e85269a73dc2ccb6f199555007677f39fb92e650;p=mjc2wsl.git
diff --git a/src/mjc2wsl.java b/src/mjc2wsl.java
index 77d1c28..f754e4e 100644
--- a/src/mjc2wsl.java
+++ b/src/mjc2wsl.java
@@ -1,25 +1,57 @@
+/*
+ Copyright (C) 2014 Doni Pracner
+
+ This file is part of mjc2wsl.
+
+ mjc2wsl is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ mjc2wsl is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with mjc2wsl. If not, see .
+*/
import java.io.*;
import java.util.*;
/**
- * This program converts file from compiled MicroJava bytecode (a subset used
- * in Compiler Construction courses by H. Moessenboeck, not "Java ME")
- * to WSL language which is a part of the FermaT Transformation system.
- *
+ * This program converts file from compiled MicroJava bytecode to WSL language
+ * which is a part of the FermaT Transformation system. MicroJava is a subset
+ * used in Compiler Construction courses by Hanspeter Moessenboeck, not
+ * "Java ME".
+ *
* @author Doni Pracner, http://perun.dmi.rs/pracner http://quemaster.com
*/
public class mjc2wsl{
- public static String versionN = "0.1.2";
-
- //regular comments from the original file
- //OC when original code is inserted in the file, next to the translations
- //SPEC special messages from the translator
- //ERR error messages from the transnlator
- public static final char C_REG = ' ', C_OC = '#', C_SPEC = '&', C_ERR = '!';
+ public static String versionN = "0.1.7";
+
+ private TransMessages messages = new TransMessages();
+ private boolean genPauseAfterEachAddress=false,
+ genPrintForEachAddress = false,
+ genPrintEStackOnChange = false;
+
+ private boolean genPopPush=false;
- /** instruction code */
- public static final int
+ /** Constant used for marking a regular comment from the original file */
+ public static final char C_REG = ' ';
+ /**
+ * Constant used for marking when original code is inserted in the file,
+ * next to the translations
+ */
+ public static final char C_OC = '#';
+ /** Constant used for marking special messages from the translator */
+ public static final char C_SPEC = '&';
+ /** Constant used for marking error messages from the translator */
+ public static final char C_ERR = '!';
+
+ /** instruction code in MicroJava bytecode. */
+ public static final int
load = 1,
load_0 = 2,
load_1 = 3,
@@ -78,23 +110,40 @@ public class mjc2wsl{
bprint = 56,
trap = 57;
- public String getStandardStart(){
- StringBuilder ret = new StringBuilder("C:\" This file automatically converted from microjava bytecode\";\n"
- +"C:\" with mjc2wsl v "+versionN+"\";\n");
-
- ret.append("VAR < tempa := 0, tempb := 0, tempres :=0,\n");
- for (int i=0;i<=3;i++) ret.append("loc"+i+" := 0, ");
- ret.append("\n estack := < >, t_e_m_p := 0 > :");
-
- return ret.toString();
+ private boolean originalInComments = false;
+
+ private HashMap opMap = null;
+
+ private String opCodeFile = "mj-bytecodes.properties";
+
+ private HashMap getOpMap() {
+ if (opMap == null) {
+ opMap = new HashMap(60, 0.98f);
+ try {
+ BufferedReader in = new BufferedReader(new InputStreamReader(
+ getClass().getResourceAsStream(opCodeFile)));
+ String str = in.readLine();
+ while (str != null) {
+ String[] ss = str.split("=");
+ opMap.put(Integer.parseInt(ss[0]), ss[1]);
+ str = in.readLine();
+ }
+ in.close();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+ return opMap;
+ }
+
+ public String getOpString(int op) {
+ return getOpMap().get(op);
}
- public String getStandardEnd(){
- return "SKIP\nENDVAR";
+ public String describeOpCode(int op) {
+ return op + " (" + getOpString(op) + ")";
}
- private boolean originalInComments = false;
-
private InputStream mainIn;
private PrintWriter out = null;
private int counter = -1;
@@ -116,27 +165,113 @@ public class mjc2wsl{
}
private int get() {
- int res = -1;
- try{
- res = mainIn.read();
- if (res>=0) res = res<<24>>>24;
- }catch (IOException ex){
- ex.printStackTrace();
- }
- counter++;
- return res;
+ int res = -1;
+ try {
+ res = mainIn.read();
+ if (res >= 0)
+ res = res << 24 >>> 24;
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ counter++;
+ return res;
}
private int get2() {
- return (get()*256 + get())<<16>>16;
+ return (get() * 256 + get()) << 16 >> 16;
}
-
+
private int get4() {
- return (get2()<<16) + (get2()<<16>>>16);
+ return (get2() << 16) + (get2() << 16 >>> 16);
}
- private String loc(int i){
- return "loc"+i;
+ public String createStandardStart(){
+ return createStandardStart(10);
+ }
+
+ public String createStandardStart(int numWords){
+ StringBuilder ret = new StringBuilder(
+ "C:\" This file automatically converted from microjava bytecode\";\n"
+ +"C:\" with mjc2wsl v "+versionN+"\";\n");
+
+ ret.append("\nBEGIN");
+ ret.append("\nVAR <\n\t");
+ ret.append("mjvm_locals := ARRAY(1,0),");
+ ret.append("\n\tmjvm_statics := ARRAY("+numWords+",0),");
+ ret.append("\n\tmjvm_arrays := < >,");
+ ret.append("\n\tmjvm_flag_jump := 0,");
+ ret.append("\n\tmjvm_objects := < >,");
+ ret.append("\n\tmjvm_estack := < >, mjvm_mstack := < > > :");
+
+ return ret.toString();
+ }
+
+ public String createAsciiString(){
+ StringBuilder ret = new StringBuilder("C:\"char array for ascii code conversions\";");
+ ret.append("\nascii := \"????????????????????????????????\"++\n");
+ ret.append("\" !\"++Quote++\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\";\n");
+
+ return ret.toString();
+ }
+
+ public String createStandardEnd(){
+ StringBuilder ret = new StringBuilder("SKIP\nENDVAR\n");
+ ret.append("\nWHERE\n");
+
+ ret.append("\nFUNCT CHR(num) ==:\n");
+ ret.append("\t@List_To_String(< num >)\n");
+ ret.append("END\n");
+
+ ret.append("\nPROC Print_MJ(val, format VAR)==\n");
+ ret.append(createComment("print spacing", C_SPEC));
+ ret.append("\n\tIF format>1 THEN\n\t\tFOR i:=2 TO ");
+ ret.append("format STEP 1 DO PRINFLUSH(\" \") OD\n");
+ ret.append("\tFI;\n\tPRINFLUSH(val)\nEND\n");
+
+ ret.append("\nPROC Print_MJ_CHAR(val, format VAR)==\n");
+ ret.append(createComment("print spacing", C_SPEC));
+ ret.append("\n\tIF format>1 THEN\n\t\tFOR i:=2 TO ");
+ ret.append("format STEP 1 DO PRINFLUSH(\" \") OD\n");
+ ret.append("\tFI;\n\tPRINFLUSH(CHR(val))\n");
+ ret.append("END\n");
+
+ ret.append("\nEND");
+ return ret.toString();
+ }
+
+ private String createStartVar(String... vars){
+ StringBuilder ret = new StringBuilder("VAR < ");
+ ret.append(vars[0] + " := 0");
+ for (int i=1; i : ");
+
+ return ret.toString();
+ }
+
+ private String createEndVar(){
+ return "ENDVAR;";
+ }
+
+ private String createLocal(int i) {
+ // arrays start at 1 in WSL, so we need an offset
+ return "mjvm_locals[" + (i + 1) + "]";
+ }
+
+ private String createStatic(int i) {
+ return "mjvm_statics[" + (i + 1) + "]";
+ }
+
+ private String createArray(int i) {
+ return "mjvm_arrays[" + i + "]";
+ }
+
+ private String createArray(String i) {
+ return "mjvm_arrays[" + i + "]";
+ }
+
+ private String createObject(String i) {
+ return "mjvm_objects[" + i + "]";
}
/**
@@ -153,203 +288,605 @@ public class mjc2wsl{
* in them, or additional comments regarding the translation
* process.
*/
- public static String createComment(String str, char type){
- return "C:\""+type+str.replace("\"", "''")+"\";";
+ public static String createComment(String str, char type) {
+ return "C:\"" + type + str.replace("\"", "''") + "\";";
}
- private String cmdToEStack(int i){
- return "estack := <"+i+" > ++ estack;";
- }
+ // generalised stack operations
- private String cmdToEStack(String i){
- return "estack := <"+i+" > ++ estack;";
+ private String createToStack(String stack, String var){
+ if (genPopPush)
+ return "PUSH("+stack+"," + var + ");";
+ else
+ return stack + " := <" + var + " > ++ " + stack +";";
}
-
- private String cmdFromEStack(String st){
- return st+" := HEAD(estack); estack := TAIL(estack);";
+
+ private String createFromStack(String stack, String var){
+ if (genPopPush)
+ return "POP("+ var + ", "+stack+");";
+ else
+ return var + ":= HEAD("+stack+"); "+stack+" := TAIL("+stack+");";
}
+//Expression stack
- private String getTopTwo(){
- return cmdFromEStack("tempa")+"\n"+cmdFromEStack("tempb");
+ private String createToEStack(int i) {
+ return createToEStack(i+"");
}
-
- private String getTop(){
- return cmdFromEStack("tempa");
+
+ private String createToEStack(String i) {
+ String res = createToStack("mjvm_estack", i);
+ if (genPrintEStackOnChange)
+ res += "PRINT(\"eStack\",mjvm_estack);";
+ return res;
+ }
+
+ private String createFromEStack(String st) {
+ String res = createFromStack("mjvm_estack",st);
+ if (genPrintEStackOnChange)
+ res += "PRINT(\"eStack\",mjvm_estack);";
+ return res;
+ }
+
+ private String createPopEStack() {
+ String res = "mjvm_estack := TAIL(mjvm_estack);";
+ if (genPrintEStackOnChange)
+ res += "PRINT(\"eStack\",mjvm_estack);";
+ return res;
+ }
+
+ private String createTopTwoEStack() {
+ return createFromEStack("tempa") + "\n" + createFromEStack("tempb");
+ }
+
+ private String createTopEStack() {
+ return createFromEStack("tempa");
}
- public void convertStream(InputStream ins){
+ //Method stack
+
+ private String createToMStack(int i) {
+ return createToMStack(i+"");
+ }
+
+ private String createToMStack(String i) {
+ return createToStack("mjvm_mstack", i);
+ }
+
+ private String createFromMStack(String st) {
+ return createFromStack("mjvm_mstack", st);
+ }
+
+ private String getRelationFor(int opcode) throws Exception {
+ switch (opcode) {
+ case jeq: return "=";
+ case jne: return "<>";
+ case jlt: return "<";
+ case jle: return "<=";
+ case jgt: return ">";
+ case jge: return ">=";
+ }
+ throw new Exception("Wrong opcode for a relation");
+ }
+
+ private boolean isJumpCode(int opcode) {
+ return (opcode >= jmp) && (opcode <= jge);
+ }
+
+ public void convertStream(InputStream ins) throws Exception{
mainIn = ins;
- //skip start TODO make better
- for (int i=0;i<14;i++) get();
+ //process start
+ byte m = (byte) get();
+ byte j = (byte) get();
+ if (m!='M' || j !='J')
+ throw new Exception("Wrong start of bytecode file");
+ int codesize = get4();
+ int numberOfWords = get4();
+ int mainAdr = get4();
- prl(getStandardStart());
- prl("SKIP;\n ACTIONS A_S_start:\n A_S_start == CALL a14 END");
+ prl(createStandardStart(numberOfWords));
+ prl("SKIP;\n ACTIONS a" + (14 + mainAdr) + " :");
int op = get();
- while (op>=0){
- if (originalInComments) prl(createComment(""+op,C_OC));
- prl("a"+counter+" == ");
- switch(op) {
- case load: {
- prl(cmdToEStack(loc(get())));
- break;
- }
- case load_0: case load_1: case load_2: case load_3: {
- prl(cmdToEStack(loc(op-load_0)));
- break;
- }
- case store: {
- prl(cmdFromEStack(loc(get())));
- break;
- }
- case store_0: case store_1: case store_2: case store_3: {
- prl(cmdFromEStack(loc(op-store_0)));
- break;
- }
- case const_: {
- prl(cmdToEStack(get4()));
- break;
- }
-
- case const_0: case const_1: case const_2:
- case const_3: case const_4: case const_5:{
- prl(cmdToEStack(op-const_0));
- break;
- }
-
- case jmp: {
- prl("CALL a"+(counter+get2())+";");
- break;
- }
-
- case jeq: case jne: case jlt:
- case jle: case jgt: case jge: {
- prl(getTopTwo());
- prl("IF tempb >= tempa THEN CALL a"+(counter+get2())+" FI;");
- break;
- }
-
- case add: {
- prl(getTopTwo());
- prl("tempres := tempb + tempa;");
- prl(cmdToEStack("tempres"));
- break;
- }
- case div: {
- prl(getTopTwo());
- prl("tempres := tempb / tempa;");
- prl(cmdToEStack("tempres"));
- break;
- }
-
- case enter: {
- prl(createComment("enter not fully procesed yet"));
- get();get();
- break;
- }
- case return_: {
- prl(createComment("return not fully procesed yet"));
- break;
- }
- case exit: {
- prl(createComment("exit not fully procesed yet"));
- break;
- }
-
- //the prints
- case bprint: {
- prl(getTopTwo());
- prl("PRINT(tempb);");
- break;
- }
- case print: {
- //TODO need to make it a char
- prl(getTopTwo());
- prl("PRINT(tempb);");
- break;
- }
-
- default: prl(createComment("unknown op error: "+op,C_ERR)); break;
- }
+ while (op >= 0) {
+ prl(" a" + counter + " ==");
+ if (originalInComments)
+ prl(createComment(describeOpCode(op), C_OC));
+ if (genPrintForEachAddress) {
+ prl("PRINT(\"a" + counter + "\");");
+ if (genPauseAfterEachAddress)
+ prl("debug_disposable_string := @Read_Line(Standard_Input_Port);");
+ }
+ switch (op) {
+ case load: {
+ prl(createToEStack(createLocal(get())));
+ break;
+ }
+ case load_0:
+ case load_1:
+ case load_2:
+ case load_3: {
+ prl(createStartVar("tempa"));
+ prl("tempa :="+createLocal(op - load_0)+";");
+ prl(createToEStack("tempa"));
+ prl(createEndVar());
+ break;
+ }
+ case store: {
+ prl(createFromEStack(createLocal(get())));
+ break;
+ }
+ case store_0:
+ case store_1:
+ case store_2:
+ case store_3: {
+ prl(createStartVar("tempa"));
+ prl(createFromEStack("tempa"));
+ prl(createLocal(op - store_0)+" := tempa;");
+ prl(createEndVar());
+ break;
+ }
+
+ case getstatic: {
+ prl(createToEStack(createStatic(get2())));
+ break;
+ }
+ case putstatic: {
+ prl(createFromEStack(createStatic(get2())));
+ break;
+ }
+
+ case getfield: {
+ int f = get2();
+ prl(createStartVar("tempa"));
+ prl(createTopEStack());
+ prl(createToEStack(createObject("tempa") + "[" + (f + 1) + "]"));
+ prl(createEndVar());
+ break;
+ }
+ case putfield: {
+ int f = get2();
+ prl(createStartVar("tempa", "tempb"));
+ prl(createTopTwoEStack());
+ prl(createObject("tempb") + "[" + (f + 1) + "]:=tempa;");
+ prl(createEndVar());
+ break;
+ }
+
+ case const_: {
+ prl(createToEStack(get4()));
+ break;
+ }
+
+ case const_m1: {
+ prl(createToEStack(-1));
+ break;
+ }
+
+ case const_0:
+ case const_1:
+ case const_2:
+ case const_3:
+ case const_4:
+ case const_5: {
+ prl(createToEStack(op - const_0));
+ break;
+ }
+
+ case add: {
+ prl(createStartVar("tempa", "tempb", "tempres"));
+ prl(createTopTwoEStack());
+ prl("tempres := tempb + tempa;");
+ prl(createToEStack("tempres"));
+ prl(createEndVar());
+ break;
+ }
+ case sub: {
+ prl(createStartVar("tempa", "tempb", "tempres"));
+ prl(createTopTwoEStack());
+ prl("tempres := tempb - tempa;");
+ prl(createToEStack("tempres"));
+ prl(createEndVar());
+ break;
+ }
+ case mul: {
+ prl(createStartVar("tempa", "tempb", "tempres"));
+ prl(createTopTwoEStack());
+ prl("tempres := tempb * tempa;");
+ prl(createToEStack("tempres"));
+ prl(createEndVar());
+ break;
+ }
+ case div: {
+ prl(createStartVar("tempa", "tempb", "tempres"));
+ prl(createTopTwoEStack());
+ prl("IF tempa = 0 THEN ERROR(\"division by zero\") FI;");
+ prl("tempres := tempb DIV tempa;");
+ prl(createToEStack("tempres"));
+ prl(createEndVar());
+ break;
+ }
+ case rem: {
+ prl(createStartVar("tempa", "tempb", "tempres"));
+ prl(createTopTwoEStack());
+ prl("IF tempa = 0 THEN ERROR(\"division by zero\") FI;");
+ prl("tempres := tempb MOD tempa;");
+ prl(createToEStack("tempres"));
+ prl(createEndVar());
+ break;
+ }
+
+ case neg: {
+ prl(createStartVar("tempa"));
+ prl(createTopEStack());
+ prl(createToEStack("-tempa"));
+ prl(createEndVar());
+ break;
+ }
+
+ case shl: {
+ prl(createStartVar("tempa", "tempb"));
+ prl(createTopTwoEStack());
+ prl("VAR :");
+ prl("\tFOR i:=1 TO tempa STEP 1 DO tempres := tempres * 2 OD;");
+ prl(createToEStack("tempres"));
+ prl("ENDVAR;");
+ prl(createEndVar());
+ break;
+ }
+ case shr: {
+ prl(createStartVar("tempa", "tempb"));
+ prl(createTopTwoEStack());
+ prl("VAR :");
+ prl("\tFOR i:=1 TO tempa STEP 1 DO tempres := tempres DIV 2 OD;");
+ prl(createToEStack("tempres"));
+ prl("ENDVAR;");
+ prl(createEndVar());
+ break;
+ }
+
+ case inc: {
+ int b1 = get(), b2 = get();
+ prl(createLocal(b1) + " := " + createLocal(b1) + " + " + b2 + ";");
+ break;
+ }
+
+ case new_: {
+ int size = get2();
+ // TODO maybe objects and arrays should be in the same list?
+ prl("mjvm_objects := mjvm_objects ++ < ARRAY(" + size
+ + ",0) >;");
+ prl(createToEStack("LENGTH(mjvm_objects)"));
+ break;
+ }
+ case newarray: {
+ get();// 0 - bytes, 1 - words; ignore for now
+ // TODO take into consideration 0/1
+ prl(createStartVar("tempa"));
+ prl(createTopEStack());
+ prl("mjvm_arrays := mjvm_arrays ++ < ARRAY(tempa,0) >;");
+ prl(createToEStack("LENGTH(mjvm_arrays)"));
+ prl(createEndVar());
+ break;
+ }
+
+ case aload:
+ case baload: {
+ prl(createStartVar("tempa", "tempb"));
+ prl(createTopTwoEStack());
+ prl(createToEStack(createArray("tempb") + "[tempa+1]"));
+ prl(createEndVar());
+ break;
+ }
+ case astore:
+ case bastore: {
+ prl(createStartVar("tempa", "tempb", "tempres"));
+ prl(createFromEStack("tempres"));
+ prl(createTopTwoEStack());
+ prl("mjvm_arrays[tempb][tempa+1]:=tempres;");
+ prl(createEndVar());
+ break;
+ }
+ case arraylength: {
+ prl(createStartVar("tempa", "tempb"));
+ prl(createTopEStack());
+ prl("tempb := LENGTH("+ createArray("tempa") + ");");
+ prl(createToEStack("tempb"));
+ prl(createEndVar());
+ break;
+ }
+
+ case dup: {
+ prl(createStartVar("tempa", "tempb"));
+ prl(createTopEStack());
+ prl(createToEStack("tempa"));
+ prl(createToEStack("tempa"));
+ prl(createEndVar());
+ break;
+ }
+ case dup2: {
+ prl(createStartVar("tempa", "tempb"));
+ prl(createTopTwoEStack());
+ prl(createToEStack("tempb"));
+ prl(createToEStack("tempa"));
+ prl(createToEStack("tempb"));
+ prl(createToEStack("tempa"));
+ prl(createEndVar());
+ break;
+ }
+
+ case pop: {
+ prl(createPopEStack());
+ break;
+ }
+
+ case jmp: {
+ prl("CALL a" + (counter + get2()) + ";");
+ break;
+ }
+
+ case jeq:
+ case jne:
+ case jlt:
+ case jle:
+ case jgt:
+ case jge: {
+ prl(createStartVar("tempa", "tempb"));
+ prl(createTopTwoEStack());
+ prl("IF tempb " + getRelationFor(op)
+ + " tempa THEN mjvm_flag_jump := 1"
+ + " ELSE mjvm_flag_jump := 0"
+ + " FI;");
+ prl(createEndVar());
+ prl("IF mjvm_flag_jump = 1 THEN CALL a"
+ + (counter + get2())
+ + " ELSE CALL a" + (counter + 1)
+ + " FI;");
- op = get();
- if (op>=0) prl("CALL a"+counter+" END");
+ break;
+ }
+
+ case call: {
+ prl("CALL a" + (counter + get2()) + ";");
+ break;
+ }
+
+ case return_: {
+ // we let the actions return
+ // there is nothing to clean up
+ prl("SKIP\n END\n b" + counter + " ==");
+ break;
+ }
+ case enter: {
+ int parameters = get();
+
+ int locals = get();
+ prl(createToMStack("mjvm_locals"));
+ prl("mjvm_locals := ARRAY(" + locals + ",0);");
+ for (int i = parameters - 1; i >= 0; i--)
+ prl(createFromEStack(createLocal(i)));
+ break;
+ }
+ case exit: {
+ prl(createFromMStack("mjvm_locals"));
+ break;
+ }
+
+ // read, print
+ case bread: {
+ // TODO make it a char for read
+ messages.message("char is read like a number", TransMessages.M_WAR);
+ prl(createComment("char is read like a number", C_SPEC));
+ }
+ case read: {
+ prl(createStartVar("tempa"));
+ prl("tempa := @String_To_Num(@Read_Line(Standard_Input_Port));");
+ prl(createToEStack("tempa"));
+ prl(createEndVar());
+ break;
+ }
+
+ // the prints
+ case bprint: {
+ prl(createStartVar("tempa", "tempb"));
+ prl(createTopTwoEStack());
+ prl("Print_MJ_CHAR(tempb,tempa);");
+ prl(createEndVar());
+ break;
+ }
+ case print: {
+ // TODO printing numbers needs different lengths of spacing
+ prl(createStartVar("tempa", "tempb"));
+
+ prl(createTopTwoEStack());
+ prl("Print_MJ(tempb,tempa);");
+ prl(createEndVar());
+ break;
+ }
+
+ case trap: {
+ prl("ERROR(\"Runtime error: trap(" + get() + ")\");");
+ break;
+ }
+
+ default:
+ prl(createComment("unknown op error: " + op, C_ERR));
+ messages.message("unknown op error: " + op, TransMessages.M_ERR);
+ break;
+ }
+
+ boolean wasJump = isJumpCode(op);
+ op = get();
+ if (op >= 0)
+ if (wasJump)
+ prl("SKIP\n END");
+ else
+ prl("CALL a" + counter + "\n END");
}
- prl("CALL Z;\nSKIP END\nENDACTIONS;\n");
- prl(getStandardEnd());
-
+ prl("SKIP\n END\nENDACTIONS;\n");
+ pr(createStandardEnd());
+ }
+
+ public void convertFile(File f) {
+ try {
+ convertStream(new FileInputStream(f));
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ public void printHelp() {
+ printVersion();
+ printUsage();
+ printHelpOutput();
+ printHelpHelp();
+ }
+
+ public void printLongHelp() {
+ printVersion();
+ printUsage();
+ System.out.println();
+ printHelpOutput();
+ System.out.println();
+ printHelpDirectives();
+ System.out.println();
+ printHelpGenerating();
+ System.out.println();
+ printHelpHelp();
+ }
+
+ public void printHelpOutput() {
+ System.out.println("Output options:");
+ System.out.println(" --screen print output to screen");
+ System.out.println(" -o --oc[+-] include original code in comments");
+ System.out.println(" -v verbose, print warning messages");
+ System.out.println(" -q quiet; don't print even the error messages");
+ System.out.println(" -d print detailed debug messages");
}
- public void convertFile(File f){
- try{
- convertStream(new FileInputStream(f));
- }catch (Exception ex){
- ex.printStackTrace();
- }
+ public void printHelpGenerating() {
+ System.out.println("Options for generating extra code for tracking code execution");
+ System.out.println(" --genEStackPrint generate print for all EStack changes");
+ System.out.println(" --genAddrPrint generate prints after every address of the original code ");
+ System.out.println(" --genAddrPause generate a pause after every address of the original code ");
+ System.out.println(" --genAddr short for --genAddrPrint and --genAddrPause");
+ System.out.println(" --genAll short for applying all code generation");
+ }
+
+ public void printHelpDirectives(){
+ System.out.println("Alternatives for code generation:");
+ System.out.println(" --genPopPush generate POP/PUSH instead of TAIL/HEAD");
+ }
+
+ public void printHelpHelp() {
+ System.out.println("Help and info options");
+ System.out.println(" -h basic help");
+ System.out.println(" --help print more detailed help");
+ System.out.println(" --version or -version print version and exit");
}
- public void printHelp(){
- System.out.println("MicroJava bytecode to WSL converter. v "+versionN+", by Doni Pracner");
- System.out.println("usage:\n\t {options} mjc2wsl filename [outfile]");
- System.out.println("options:\n\t--screen print output to screen");
- System.out.println("\t-o --oc include original code in comments");
+ public void printUsage(){
+ System.out.println("usage:\n\t mjc2wsl {options} filename [outfile]");
+ }
+
+ public void printVersion() {
+ System.out.println("MicroJava bytecode to WSL converter. v " + versionN
+ + ", by Doni Pracner");
}
public String makeDefaultOutName(String inname){
- String rez = inname;
- if (inname.endsWith(".obj"))
- rez = rez.substring(0,rez.length()-4);
- return rez+".wsl";
+ String rez = inname;
+ if (inname.endsWith(".obj"))
+ rez = rez.substring(0, rez.length() - 4);
+ return rez + ".wsl";
}
- public void run(String[] args){
- if (args.length == 0){
- printHelp();
- }else{
- int i=0;
- while (i=args.length) {System.out.println("no filename supplied");System.exit(2);}
+ if (i >= args.length) {
+ System.out.println("no filename supplied");
+ System.exit(2);
+ }
File f = new File(args[i]);
-
- if (i+1