From 632c14358ddeee497f769cf98f31345f19fad03d Mon Sep 17 00:00:00 2001 From: Doni Pracner Date: Wed, 23 Apr 2014 00:45:41 +0200 Subject: [PATCH] Alternative to make Push and Pop instead of TAIL and HEAD for stack manipulation; default off, has problems with the current transformations --- src/mjc2wsl.java | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/mjc2wsl.java b/src/mjc2wsl.java index 8717711..52c7542 100644 --- a/src/mjc2wsl.java +++ b/src/mjc2wsl.java @@ -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++; } -- 2.25.1