fields: don't multiple the offset with 4
[mate.git] / Mate / X86CodeGen.hs
index c71494e74ecdad5ea6bee96746adbf80b9cb5a5a..59ccb420d4a6cd929c8bb31f7780740c2d519275 100644 (file)
@@ -11,7 +11,7 @@ import qualified Data.Set as S
 import qualified Data.ByteString.Lazy as B
 import Control.Monad
 
-import Foreign
+import Foreign hiding (xor)
 import Foreign.C.Types
 
 import Text.Printf
@@ -234,6 +234,17 @@ emitFromBB method cls hmap =  do
         call (trapaddr - w32_calladdr)
         add esp (4 :: Word32)
     emit DUP = push (Disp 0, esp)
+    emit IASTORE = do
+        pop eax -- value
+        pop ebx -- offset
+        add ebx (1 :: Word32)
+        pop ecx -- aref
+        mov (ecx, ebx, S4) eax
+    emit IALOAD = do
+        pop ebx -- offset
+        add ebx (1 :: Word32)
+        pop ecx -- aref
+        push (ecx, ebx, S4)
     emit ARRAYLENGTH = do
         pop eax
         push (Disp 0, eax)
@@ -296,17 +307,18 @@ emitFromBB method cls hmap =  do
         pop eax -- this pointer
         let (cname, fname) = buildFieldOffset cls x
         offset <- liftIO $ getFieldOffset cname fname
-        push (Disp (fromIntegral $ offset * 4), eax) -- get field
+        push (Disp (fromIntegral $ offset), eax) -- get field
     emit (PUTFIELD x) = do
         pop ebx -- value to write
         pop eax -- this pointer
         let (cname, fname) = buildFieldOffset cls x
         offset <- liftIO $ getFieldOffset cname fname
-        mov (Disp (fromIntegral $ offset * 4), eax) ebx -- set field
+        mov (Disp (fromIntegral $ offset), eax) ebx -- set field
 
     emit IADD = do pop ebx; pop eax; add eax ebx; push eax
     emit ISUB = do pop ebx; pop eax; sub eax ebx; push eax
     emit IMUL = do pop ebx; pop eax; mul ebx; push eax
+    emit IXOR = do pop ebx; pop eax; xor eax ebx; push eax
     emit (IINC x imm) = do
         add (Disp (cArgs x), ebp) (s8_w32 imm)