gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
Alternative to make Push and Pop instead of TAIL and HEAD for stack manipulation...
authorDoni Pracner <quinnuendo@gmail.com>
Tue, 22 Apr 2014 22:45:41 +0000 (00:45 +0200)
committerDoni Pracner <quinnuendo@gmail.com>
Tue, 22 Apr 2014 22:45:41 +0000 (00:45 +0200)
src/mjc2wsl.java

index 87177112908a7923d7a282be0825afdec10b0659..52c75422b7b7a6bd6ecc6a044830c69da686dbce 100644 (file)
@@ -35,6 +35,8 @@ public class mjc2wsl{
        private boolean genPauseAfterEachAddress=false, 
                genPrintForEachAddress = false,
                genPrintEStackOnChange = false;
+               
+       private boolean genPopPush=false;
        
        /** Constant used for marking a regular comment from the original file */
        public static final char C_REG = ' ';
@@ -275,10 +277,16 @@ public class mjc2wsl{
        // generalised stack operations
        
        private String createToStack(String stack, String var){
-                       return stack + " := <" + var + " > ++ " + stack +";";
+               if (genPopPush)
+                               return  "PUSH("+stack+"," + var + ");";
+               else
+                               return stack + " := <" + var + " > ++ " + stack +";";
        }
 
        private String createFromStack(String stack, String var){
+               if (genPopPush)
+                       return "POP("+ var + ", "+stack+");";
+               else
                        return var + ":= HEAD("+stack+"); "+stack+" := TAIL("+stack+");";
        }
 //Expression stack
@@ -378,7 +386,10 @@ public class mjc2wsl{
                        case load_1:
                        case load_2:
                        case load_3: {
-                               prl(createToEStack(createLocal(op - load_0)));
+                               prl(createStartVar("tempa"));
+                               prl("tempa :="+createLocal(op - load_0)+";");
+                               prl(createToEStack("tempa"));
+                               prl(createEndVar());
                                break;
                        }
                        case store: {
@@ -389,7 +400,10 @@ public class mjc2wsl{
                        case store_1:
                        case store_2:
                        case store_3: {
-                               prl(createFromEStack(createLocal(op - store_0)));
+                               prl(createStartVar("tempa"));
+                               prl(createFromEStack("tempa"));
+                               prl(createLocal(op - store_0)+" := tempa;");
+                               prl(createEndVar());
                                break;
                        }
 
@@ -689,6 +703,8 @@ public class mjc2wsl{
                System.out.println();
                printHelpOutput();
                System.out.println();
+               printHelpDirectives();
+               System.out.println();
                printHelpGenerating();
                System.out.println();
                printHelpHelp();
@@ -712,6 +728,11 @@ public class mjc2wsl{
                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");
@@ -780,6 +801,8 @@ public class mjc2wsl{
                                        genPrintEStackOnChange = true;
                                        genPrintForEachAddress = true;
                                        genPauseAfterEachAddress = true;
+                               } else if (args[i].compareToIgnoreCase("--genPopPush") == 0) {
+                                       genPopPush = true;
                                }
                                i++;
                        }
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner