From dd4a6268bba13afdda7ccd40d82a5955ef56eb7d Mon Sep 17 00:00:00 2001 From: Doni Pracner Date: Tue, 26 Nov 2013 20:47:20 +0100 Subject: [PATCH 1/1] mjc2wsl - proper processing of the cond jumps --- src/mjc2wsl.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/mjc2wsl.java b/src/mjc2wsl.java index 4a30186..521be05 100644 --- a/src/mjc2wsl.java +++ b/src/mjc2wsl.java @@ -185,8 +185,20 @@ public class mjc2wsl{ private String getTop() { return cmdFromEStack("tempa"); } + + private String getRelationFor(int opcode) throws Exception { + switch (opcode) { + case jeq: return "="; + case jne: return "#"; + case jlt: return "<"; + case jle: return "<="; + case jgt: return ">"; + case jge: return ">="; + } + throw new Exception("Wrong opcode for a relation"); + } - public void convertStream(InputStream ins){ + public void convertStream(InputStream ins) throws Exception{ mainIn = ins; //skip start TODO make better for (int i = 0; i < 14; i++) @@ -249,7 +261,8 @@ public class mjc2wsl{ case jgt: case jge: { prl(getTopTwo()); - prl("IF tempb >= tempa THEN CALL a" + (counter + get2()) + prl("IF tempb "+ getRelationFor(op) + +" tempa THEN CALL a" + (counter + get2()) + " FI;"); break; } -- 2.17.1