gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
transf-min does not need to explicitly Simplify, it's called anyway
[mjc2wsl.git] / src / mjc2wsl.java
index e23b10e..a552b08 100644 (file)
@@ -1,3 +1,21 @@
+/*
+   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 <http://www.gnu.org/licenses/>.
+*/
 import java.io.*;
 import java.util.*;
 
@@ -10,7 +28,7 @@ import java.util.*;
  * @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();
 
@@ -483,13 +501,8 @@ public class mjc2wsl{
                        }
                        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;
                        }
 
@@ -604,7 +617,7 @@ public class mjc2wsl{
                                else
                                        prl("CALL a" + counter + " END");
                }
-               prl("CALL Z;\nSKIP END\nENDACTIONS;\n");
+               prl("\nSKIP END\nENDACTIONS;\n");
                prl(createStandardEnd());
        }
 
@@ -617,14 +630,55 @@ public class mjc2wsl{
        }
        
        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("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){
@@ -643,6 +697,13 @@ public class mjc2wsl{
                                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)
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner