From 80adcf724041ab52a9dcea93f395440332901634 Mon Sep 17 00:00:00 2001 From: Doni Pracner Date: Mon, 23 Dec 2013 15:38:47 +0100 Subject: [PATCH] mjc2wsl, load the string names of the opcodes when displaying original code in comments --- src/mjc2wsl.java | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/mjc2wsl.java b/src/mjc2wsl.java index b7edf0b..ee36c51 100644 --- a/src/mjc2wsl.java +++ b/src/mjc2wsl.java @@ -125,6 +125,38 @@ public class mjc2wsl{ private boolean originalInComments = false; + private HashMap opMap = null; + + private String opCodeFile = "mj-bytecodes.properties"; + + private HashMap getOpMap() { + if (opMap==null) { + opMap = new HashMap (60, 0.98f); + try{ + BufferedReader in = new BufferedReader( + new InputStreamReader(getClass().getResourceAsStream(opCodeFile))); + String str = in.readLine(); + while (str != null) { + String[] ss = str.split("="); + opMap.put(Integer.parseInt(ss[0]),ss[1]); + str = in.readLine(); + } + in.close(); + }catch (Exception ex) { + ex.printStackTrace(); + } + } + return opMap; + } + + public String getOpString(int op) { + return getOpMap().get(op); + } + + public String describeOpCode(int op) { + return op + " (" + getOpString(op) + ")"; + } + private InputStream mainIn; private PrintWriter out = null; private int counter = -1; @@ -247,7 +279,7 @@ public class mjc2wsl{ int op = get(); while (op >= 0) { if (originalInComments) - prl(createComment("" + op, C_OC)); + prl(createComment(describeOpCode(op), C_OC)); prl("a" + counter + " == "); switch (op) { case load: { -- 2.25.1