From 67a5f82a835bf83c2725f09378a739dd9f5c19e7 Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Wed, 13 Jun 2012 16:37:56 +0200 Subject: [PATCH] codegen: print every jvm instruction as label in disasm output --- Mate/X86CodeGen.hs | 5 ++++- tests/WhileArray1.java | 20 +++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Mate/X86CodeGen.hs b/Mate/X86CodeGen.hs index 2b820b6..d895d63 100644 --- a/Mate/X86CodeGen.hs +++ b/Mate/X86CodeGen.hs @@ -74,7 +74,7 @@ emitFromBB method sig cls hmap = do bb_offset <- getCodeOffset let bbstarts' = M.insert bid bb_offset bbstarts defineLabel $ getLabel bid lmap - cs <- mapM emit' $ code bb + cs <- mapM emit'' $ code bb let calls' = calls `M.union` M.fromList (catMaybes cs) case successor bb of Return -> return (calls', bbstarts') @@ -123,6 +123,9 @@ emitFromBB method sig cls hmap = do let imm8 = is8BitOffset offset return $ Just (calladdr + (if imm8 then 3 else 6), trapcause imm8) + emit'' :: J.Instruction -> CodeGen e s (Maybe (Word32, TrapCause)) + emit'' insn = newNamedLabel ("jvm_insn: " ++ show insn) >>= defineLabel >> emit' insn + emit' :: J.Instruction -> CodeGen e s (Maybe (Word32, TrapCause)) emit' (INVOKESPECIAL cpidx) = emitInvoke cpidx True emit' (INVOKESTATIC cpidx) = emitInvoke cpidx False diff --git a/tests/WhileArray1.java b/tests/WhileArray1.java index 912d043..f652a5c 100644 --- a/tests/WhileArray1.java +++ b/tests/WhileArray1.java @@ -1,28 +1,30 @@ package tests; public class WhileArray1 { + public char arr[] = new char[10]; + public static void main(String args[]) { - char a[] = new char[10]; - char b[] = new char[10]; + WhileArray1 a = new WhileArray1(); + WhileArray1 b = new WhileArray1(); for (int i = 0; i < 10; i++) { - a[i] = b[i] = (char) i; + a.arr[i] = b.arr[i] = (char) i; } - System.out.printf("success? %d\n", equal(a, b, 5) ? 1 : 0); + System.out.printf("success? %d\n", equal(a, b, 10) ? 1 : 0); for (int i = 0; i < 10; i++) { - b[i] = (char) i; - a[i] = (char) (b[i] + 2); + b.arr[i] = (char) i; + a.arr[i] = (char) (b.arr[i] + 2); } - System.out.printf("success? %d\n", equal(a, b, 5) ? 1 : 0); + System.out.printf("success? %d\n", equal(a, b, 10) ? 1 : 0); } - public static boolean equal(char[] a, char[] b, int len) { + public static boolean equal(WhileArray1 a, WhileArray1 b, int len) { /* stolen from the equals implementation of java.lang.String of * GNU Classpath */ int x = 0, y = 0; while (--len >= 0) { System.out.printf("idx: x: %d, y: %d\n", x, y); - if (a[x++] != b[y++]) { + if (a.arr[x++] != b.arr[y++]) { return false; } } -- 2.25.1