From fbd2a5f852ab4f94c0a0c20f7a572c99e75f9daf Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Tue, 12 Jun 2012 22:08:36 +0200 Subject: [PATCH] codegen: some more tests --- Mate/X86CodeGen.hs | 1 + tests/If1.java | 19 +++++++++++++++++++ tests/WhileArray1.java | 31 +++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 tests/If1.java create mode 100644 tests/WhileArray1.java diff --git a/Mate/X86CodeGen.hs b/Mate/X86CodeGen.hs index 53ac641..2b820b6 100644 --- a/Mate/X86CodeGen.hs +++ b/Mate/X86CodeGen.hs @@ -173,6 +173,7 @@ emitFromBB method sig cls hmap = do emit POP = add esp (4 :: Word32) -- drop value emit DUP = push (Disp 0, esp) emit DUP_X1 = do pop eax; pop ebx; push eax; push ebx; push eax + emit DUP_X2 = do pop eax; pop ebx; pop ecx; push eax; push ecx; push ebx; push eax emit AASTORE = emit IASTORE emit IASTORE = do pop eax -- value diff --git a/tests/If1.java b/tests/If1.java new file mode 100644 index 0000000..1eff764 --- /dev/null +++ b/tests/If1.java @@ -0,0 +1,19 @@ +package tests; + +public class If1 { + public static void main(String []args) { + boolean a = true; + boolean b = true; + boolean c = true; + boolean d = true; + + if (a) + System.out.printf("a\n"); + if (b) + System.out.printf("b\n"); + if (c) + System.out.printf("c\n"); + if (d) + System.out.printf("d\n"); + } +} diff --git a/tests/WhileArray1.java b/tests/WhileArray1.java new file mode 100644 index 0000000..912d043 --- /dev/null +++ b/tests/WhileArray1.java @@ -0,0 +1,31 @@ +package tests; + +public class WhileArray1 { + public static void main(String args[]) { + char a[] = new char[10]; + char b[] = new char[10]; + for (int i = 0; i < 10; i++) { + a[i] = b[i] = (char) i; + } + System.out.printf("success? %d\n", equal(a, b, 5) ? 1 : 0); + + for (int i = 0; i < 10; i++) { + b[i] = (char) i; + a[i] = (char) (b[i] + 2); + } + System.out.printf("success? %d\n", equal(a, b, 5) ? 1 : 0); + } + + public static boolean equal(char[] a, char[] 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++]) { + return false; + } + } + return true; + } +} -- 2.25.1