gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
mjc2wsl - added optional PRINTs of addresses as the WSL code is executed, plus option...
[mjc2wsl.git] / src / mjc2wsl.java
index 0adf8f9..76d225b 100644 (file)
@@ -32,6 +32,9 @@ public class mjc2wsl{
                        out.println("total errors:"+messageCounters[M_ERR]+" warnings:"+messageCounters[M_WAR]);
        }
        
+       private boolean addPauseAfterEachAddress=false, 
+               addPrintForEachAddress = false;
+       
        /** Constant used for marking a regular comment from the original file */
        public static final char C_REG = ' ';
        /**
@@ -270,17 +273,27 @@ public class mjc2wsl{
 
        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("SKIP;\n ACTIONS A_S_start:\n A_S_start == CALL a"+(14+mainAdr)+" END");
                int op = get();
                while (op >= 0) {
                        if (originalInComments)
                                prl(createComment(describeOpCode(op), C_OC));
                        prl("a" + counter + " == ");
+                       if (addPrintForEachAddress) {
+                                       prl("PRINT(\"a"+counter+"\");");
+                                       if (addPauseAfterEachAddress)
+                                                       prl("debug_disposable_string := @Read_Line(Standard_Input_Port);");
+                       }
                        switch (op) {
                        case load: {
                                prl(cmdToEStack(loc(get())));
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner