codegen: some more tests
authorBernhard Urban <lewurm@gmail.com>
Tue, 12 Jun 2012 20:08:36 +0000 (22:08 +0200)
committerBernhard Urban <lewurm@gmail.com>
Wed, 13 Jun 2012 22:09:37 +0000 (00:09 +0200)
Mate/X86CodeGen.hs
tests/If1.java [new file with mode: 0644]
tests/WhileArray1.java [new file with mode: 0644]

index 53ac64197098d88cdaa50f8345a550364f60e2e4..2b820b6379274638ebf5f6c8a93042e3144c0dcd 100644 (file)
@@ -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 (file)
index 0000000..1eff764
--- /dev/null
@@ -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 (file)
index 0000000..912d043
--- /dev/null
@@ -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;
+       }
+}