gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
README - added notes about the additional documentation about MJ
[mjc2wsl.git] / src / mjc2wsl.java
index ab8899a..858cae3 100644 (file)
@@ -28,7 +28,7 @@ import java.util.*;
  * @author Doni Pracner, http://perun.dmi.rs/pracner http://quemaster.com
  */
 public class mjc2wsl{
  * @author Doni Pracner, http://perun.dmi.rs/pracner http://quemaster.com
  */
 public class mjc2wsl{
-       public static String versionN = "0.1.4";
+       public static String versionN = "0.1.5";
 
        private TransMessages messages = new TransMessages();
 
 
        private TransMessages messages = new TransMessages();
 
@@ -192,20 +192,31 @@ public class mjc2wsl{
                        "C:\" This file automatically converted from microjava bytecode\";\n"
                        +"C:\" with mjc2wsl v "+versionN+"\";\n");
        
                        "C:\" This file automatically converted from microjava bytecode\";\n"
                        +"C:\" with mjc2wsl v "+versionN+"\";\n");
        
+               ret.append("BEGIN ");
                ret.append("VAR < tempa := 0, tempb := 0, tempres :=0,\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_objects := < >, ");
                ret.append("VAR < tempa := 0, tempb := 0, tempres :=0,\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_objects := < >, ");
-               ret.append("\n  mjvm_estack := < >, mjvm_mstack := < >, "); 
-               ret.append("\n  mjvm_fp := 0, mjvm_sp := 0,");
-               ret.append("\n  t_e_m_p := 0 > :");
+               ret.append("\n  mjvm_estack := < >, mjvm_mstack := < > > : "); 
        
                return ret.toString();
        }
 
        public String createStandardEnd(){
        
                return ret.toString();
        }
 
        public String createStandardEnd(){
-               return "SKIP\nENDVAR";
+               StringBuilder ret = new StringBuilder("SKIP\nENDVAR");
+               ret.append("\nWHERE\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("\nEND\n");
+               
+               return ret.toString();
        }
 
        private String createLocal(int i) {
        }
 
        private String createLocal(int i) {
@@ -328,13 +339,12 @@ public class mjc2wsl{
                int mainAdr = get4();
                
                prl(createStandardStart(numberOfWords));
                int mainAdr = get4();
                
                prl(createStandardStart(numberOfWords));
-               prl("SKIP;\n ACTIONS A_S_start:\n A_S_start == CALL a" + (14 + mainAdr)
-                               + " END");
+               prl("SKIP;\n ACTIONS a" + (14 + mainAdr) + " :");
                int op = get();
                while (op >= 0) {
                        if (originalInComments)
                                prl(createComment(describeOpCode(op), C_OC));
                int op = get();
                while (op >= 0) {
                        if (originalInComments)
                                prl(createComment(describeOpCode(op), C_OC));
-                       prl("a" + counter + " == ");
+                       prl(" a" + counter + " == ");
                        if (genPrintForEachAddress) {
                                prl("PRINT(\"a" + counter + "\");");
                                if (genPauseAfterEachAddress)
                        if (genPrintForEachAddress) {
                                prl("PRINT(\"a" + counter + "\");");
                                if (genPauseAfterEachAddress)
@@ -501,13 +511,8 @@ public class mjc2wsl{
                        }
                        case arraylength: {
                                prl(createTopEStack());
                        }
                        case arraylength: {
                                prl(createTopEStack());
-                               // TODO make an array length function of some sort!
-                               prl(createComment(
-                                               "array length not known - LENGTH not aplicable to arrays",
-                                               C_ERR));
-                               messages.message("array length not known - LENGTH not aplicable to arrays", TransMessages.M_ERR);
-                               prl(createComment("put 1 on the stack for consistency", C_SPEC));
-                               prl(createToEStack(1));
+                               prl("tempb := LENGTH("+ createArray("tempa") + ");");
+                               prl(createToEStack("tempb"));
                                break;
                        }
 
                                break;
                        }
 
@@ -557,7 +562,7 @@ public class mjc2wsl{
                        case return_: {
                                // we let the actions return
                                // there is nothing to clean up
                        case return_: {
                                // we let the actions return
                                // there is nothing to clean up
-                               prl("SKIP END b" + counter + " ==");
+                               prl("SKIP\n END\n b" + counter + " ==");
                                break;
                        }
                        case enter: {
                                break;
                        }
                        case enter: {
@@ -597,9 +602,7 @@ public class mjc2wsl{
                        case print: {
                                // TODO printing numbers needs different lengths of spacing
                                prl(createTopTwoEStack());
                        case print: {
                                // TODO printing numbers needs different lengths of spacing
                                prl(createTopTwoEStack());
-                               pr(createComment("print spacing", C_SPEC));
-                               prl("IF tempa>1 THEN FOR i:=2 TO tempa STEP 1 DO PRINFLUSH(\" \") OD FI;");
-                               prl("PRINFLUSH(tempb);");
+                               prl("Print_MJ(tempb,tempa);");
                                break;
                        }
 
                                break;
                        }
 
@@ -618,11 +621,11 @@ public class mjc2wsl{
                        op = get();
                        if (op >= 0)
                                if (wasJump)
                        op = get();
                        if (op >= 0)
                                if (wasJump)
-                                       prl("SKIP END");
+                                       prl("SKIP\n END");
                                else
                                else
-                                       prl("CALL a" + counter + " END");
+                                       prl("CALL a" + counter + "\n END");
                }
                }
-               prl("CALL Z;\nSKIP END\nENDACTIONS;\n");
+               prl("SKIP\n END\nENDACTIONS;\n");
                prl(createStandardEnd());
        }
 
                prl(createStandardEnd());
        }
 
@@ -635,14 +638,55 @@ public class mjc2wsl{
        }
        
        public void printHelp() {
        }
        
        public void printHelp() {
+               printVersion();
+               printUsage();
+               printHelpOutput();
+               printHelpHelp();
+       }
+       
+       public void printLongHelp() {
+               printVersion();
+               printUsage();
+               System.out.println();
+               printHelpOutput();
+               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 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 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 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");
                System.out.println("MicroJava bytecode to WSL converter. v " + versionN
                                + ", by Doni Pracner");
-               System.out.println("usage:\n\t mjc2wsl {options} filename [outfile]");
-               System.out.println("options:\n\t--screen print output to screen");
-               System.out.println("\t-o --oc[+-] include original code in comments");
-               System.out.println("\t-v verbose, print warning messages");
-               System.out.println("\t-q don't print even the error messages");
-               System.out.println("\t-d print detailed debug messages");
        }
        
        public String makeDefaultOutName(String inname){
        }
        
        public String makeDefaultOutName(String inname){
@@ -661,6 +705,13 @@ public class mjc2wsl{
                                if (args[i].compareTo("-h") == 0) {
                                        printHelp();
                                        return;
                                if (args[i].compareTo("-h") == 0) {
                                        printHelp();
                                        return;
+                               } else if (args[i].compareTo("--help") == 0) {
+                                       printLongHelp();
+                                       return;
+                               } else if (args[i].compareTo("--version") == 0 
+                                               || args[i].compareTo("-version") == 0) {
+                                       printVersion();
+                                       return;
                                } else if (args[i].compareTo("-o") == 0
                                                || args[i].startsWith("--oc")) {
                                        if (args[i].length() == 2)
                                } else if (args[i].compareTo("-o") == 0
                                                || args[i].startsWith("--oc")) {
                                        if (args[i].length() == 2)
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner