codegen: implement IF_ACMP
authorBernhard Urban <lewurm@gmail.com>
Thu, 26 Apr 2012 09:37:45 +0000 (11:37 +0200)
committerBernhard Urban <lewurm@gmail.com>
Thu, 26 Apr 2012 09:42:01 +0000 (11:42 +0200)
it's just IF_ICMP actually

Makefile
Mate/BasicBlocks.hs
Mate/X86CodeGen.hs
tests/Strings1.java [new file with mode: 0644]

index 57f77e22d94bfed98ea4d0633fc7522559283fc2..3bd63d44968acf5b880a854708854791f8731996 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -60,8 +60,10 @@ test: mate $(CLASS_FILES)
        @printf "should be:  0x%08x 0x%08x\n" 0x1337 0x1337
        ./$< tests/Native2 | grep "printstream"
        @printf "should be:   0x%08x\n" 0x1337
-       ./$< tests/Native2 | grep "Hello World"
-       @printf "should be: %s" "Hello World"
+       ./$< tests/Native3 | egrep -e "^Hello World"
+       @printf "should be: %s\n" "Hello World"
+       ./$< tests/Strings1 | egrep -c -e "^okay :-\)"
+       @printf "should be: %d\n" 3
 
 %.class: %.java
        $(JAVAC) $<
index c5d974330e42129f7f11fc9d2901365590e99915..bde2697d67634e4a896813633097dde1a276eb7d 100644 (file)
@@ -169,6 +169,7 @@ calculateInstructionOffset = cio' (0, Nothing)
   cio' (off,_) (x:xs) = case x of
       IF _ w16 -> twotargets w16
       IF_ICMP _ w16 -> twotargets w16
+      IF_ACMP _ w16 -> twotargets w16
       GOTO w16 -> onetarget w16
       IRETURN -> notarget
       ARETURN -> notarget
index 15616f59007fbadab8693327488b13dcb16c5092..9fc57567fd963ced2185cee14d289f0ce6853472 100644 (file)
@@ -294,6 +294,7 @@ emitFromBB method cls hmap =  do
     emit (IINC x imm) = do
         add (Disp (cArgs x), ebp) (s8_w32 imm)
 
+    emit (IF_ACMP cond x) = emit (IF_ICMP cond x)
     emit (IF_ICMP cond _) = do
         pop eax -- value2
         pop ebx -- value1
diff --git a/tests/Strings1.java b/tests/Strings1.java
new file mode 100644 (file)
index 0000000..9a6a9ba
--- /dev/null
@@ -0,0 +1,27 @@
+package tests;
+
+public class Strings1 {
+       public static void main(String []args) {
+               String a = "abc";
+               String b = "abc";
+               String c = "wtf";
+
+               if (a == b) {
+                       System.out.println("okay :-)");
+               } else {
+                       System.out.println("bad :-(");
+               }
+
+               if (a != c) {
+                       System.out.println("okay :-)");
+               } else {
+                       System.out.println("bad :-(");
+               }
+
+               if (a == c) {
+                       System.out.println("bad :-(");
+               } else {
+                       System.out.println("okay :-)");
+               }
+       }
+}