callconv: once again, fail...
authorBernhard Urban <lewurm@gmail.com>
Wed, 25 Apr 2012 15:13:49 +0000 (17:13 +0200)
committerBernhard Urban <lewurm@gmail.com>
Wed, 25 Apr 2012 21:52:47 +0000 (23:52 +0200)
the arguments were in the wrong order, which wasn't covered by the test cases,
because I use addition everywhere... *d'oh*

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

index 3c004ec808a9f4e9ecdacd7b0094ffc42a6b42e3..4a5863d35d0f0a83cd2d2e782883aec1871ac07b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -48,6 +48,8 @@ test: mate $(CLASS_FILES)
        @printf "should be:  0x%08x\n" 0x1337
        ./$< tests/CallConv2 | grep mainresult
        @printf "should be:  0x%08x\n" 0x1337
+       ./$< tests/CallConv3 | grep mainresult
+       @printf "should be:  0x%08x 0x%08x 0x%08x 0x%08x\n" 0x1000 0x300 0x30 0x7
        ./$< tests/Instance1 | grep mainresult
        @printf "should be:  0x%08x 0x%08x\n" 0x55 0x11
        ./$< tests/Instance2 | grep mainresult
index 57ffdff6ef9f77dc5d807efa186b53120603ae1b..70ee0136e60c0cc0bdd482e823f252b9ad195707 100644 (file)
@@ -294,7 +294,7 @@ emitFromBB method cls hmap =  do
   cArgs x = if (x' >= thisMethodArgCnt)
       -- TODO(bernhard): maybe s/(-4)/(-8)/
       then fromIntegral $ (-4) * (x' - thisMethodArgCnt + 1)
-      else 8 + (4 * x')
+      else 4 + (thisMethodArgCnt * 4) - (4 * x')
     where x' = fromIntegral x
 
   cArgs_ :: IMM -> Word32
diff --git a/tests/CallConv3.java b/tests/CallConv3.java
new file mode 100644 (file)
index 0000000..d5fa6da
--- /dev/null
@@ -0,0 +1,23 @@
+package tests;
+
+public class CallConv3 {
+       public static void main(String []args) {
+               manyVars_A(0x1000, 0x300, 0x30, 0x7);
+               manyVars_B(0x1000, 0x300, 0x30, 0x7);
+               manyVars_C(0x1000, 0x300, 0x30, 0x7);
+               manyVars_D(0x1000, 0x300, 0x30, 0x7);
+       }
+
+       public static int manyVars_A(int a, int b, int c, int d) {
+               return a;
+       }
+       public static int manyVars_B(int a, int b, int c, int d) {
+               return b;
+       }
+       public static int manyVars_C(int a, int b, int c, int d) {
+               return c;
+       }
+       public static int manyVars_D(int a, int b, int c, int d) {
+               return d;
+       }
+}