X-Git-Url: http://svarog.pmf.uns.ac.rs/gitweb/?p=mjc2wsl.git;a=blobdiff_plain;f=src%2Fmjc2wsl.java;h=886cd7d3ba0588bb4f413d5362e8e378c1b045e3;hp=76d225b5c73c5f4b3d08b0bc47e966586b13813f;hb=ec3c740bef0052321dad7949b470f3bdc6d6bc03;hpb=9fe5956ccf526188287b4e9939b4b73ba22920ba diff --git a/src/mjc2wsl.java b/src/mjc2wsl.java index 76d225b..886cd7d 100644 --- a/src/mjc2wsl.java +++ b/src/mjc2wsl.java @@ -33,7 +33,8 @@ public class mjc2wsl{ } private boolean addPauseAfterEachAddress=false, - addPrintForEachAddress = false; + addPrintForEachAddress = false, + genPrintEStackOnChange = false; /** Constant used for marking a regular comment from the original file */ public static final char C_REG = ' '; @@ -114,7 +115,7 @@ public class mjc2wsl{ ret.append("VAR < tempa := 0, tempb := 0, tempres :=0,\n\t"); for (int i = 0; i <= 3; i++) - ret.append("mjvm_loc" + i + " := 0, "); + ret.append(loc(i) + " := 0, "); ret.append("\n mjvm_estack := < >, mjvm_mstack := < >, "); ret.append("\n mjvm_fp := 0, mjvm_sp := 0,"); ret.append("\n t_e_m_p := 0 > :"); @@ -226,15 +227,21 @@ public class mjc2wsl{ //Expression stack private String cmdToEStack(int i) { - return "mjvm_estack := <" + i + " > ++ mjvm_estack;"; + String res = "mjvm_estack := <" + i + " > ++ mjvm_estack;"; + if (genPrintEStackOnChange) res +="PRINT(\"eStack\",mjvm_estack);"; + return res; } private String cmdToEStack(String i) { - return "mjvm_estack := <" + i + " > ++ mjvm_estack;"; + String res = "mjvm_estack := <" + i + " > ++ mjvm_estack;"; + if (genPrintEStackOnChange) res +="PRINT(\"eStack\",mjvm_estack);"; + return res; } private String cmdFromEStack(String st) { - return st + " := HEAD(mjvm_estack); mjvm_estack := TAIL(mjvm_estack);"; + String res = st + " := HEAD(mjvm_estack); mjvm_estack := TAIL(mjvm_estack);"; + if (genPrintEStackOnChange) res +="PRINT(\"eStack\",mjvm_estack);"; + return res; } private String getTopTwo(){ @@ -270,6 +277,10 @@ public class mjc2wsl{ } 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; @@ -389,6 +400,7 @@ public class mjc2wsl{ prl(getTopTwo()); prl("IF tempb "+ getRelationFor(op) +" tempa THEN CALL a" + (counter + get2()) + +" ELSE CALL a" + (counter+1) + " FI;"); break; } @@ -410,8 +422,11 @@ public class mjc2wsl{ case enter: { prl(createComment("enter not fully procesed yet")); message("enter not fully procesed yet", M_WAR); + int parameters = get(); + get(); - get(); + for (int i = parameters-1; i >= 0; i--) + prl(cmdFromEStack(loc(i))); break; } case exit: { @@ -441,10 +456,7 @@ public class mjc2wsl{ } case trap: { - // TODO finish trap - prl(createComment("trap not fully procesed yet")); - message("trap not fully procesed yet", M_WAR); - get(); + prl("ERROR(\"Runtime error: trap("+get()+")\");"); break; } @@ -455,9 +467,13 @@ public class mjc2wsl{ break; } + boolean wasJump = isJumpCode(op); op = get(); if (op >= 0) - prl("CALL a" + counter + " END"); + if (wasJump) + prl("SKIP END"); + else + prl("CALL a" + counter + " END"); } prl("CALL Z;\nSKIP END\nENDACTIONS;\n"); prl(getStandardEnd()); @@ -507,16 +523,21 @@ public class mjc2wsl{ originalInComments = args[i].charAt(4) == '+'; else originalInComments = true; - } else if (args[i].startsWith("--screen")) { + } else if (args[i].compareTo("--screen") == 0) { out = new PrintWriter(System.out); } else if (args[i].compareTo("-d") == 0) { printLevel = M_DEB;//print debug info } else if (args[i].compareTo("-v") == 0) { printLevel = M_WAR;//print warnings } else if (args[i].compareTo("-q") == 0) { - printLevel = M_ERR+1;//no printing - } - i++; + printLevel = M_ERR+1;//no printing + } else if (args[i].compareToIgnoreCase("--genEStackPrint") == 0) { + genPrintEStackOnChange = true; + } else if (args[i].compareToIgnoreCase("--genAll") == 0) { + genPrintEStackOnChange = true; + addPrintForEachAddress = true; + addPauseAfterEachAddress = true; + }i++; } if (i >= args.length) {