type BBStarts = M.Map BlockID Int
-type CompileInfo = (EntryPoint, BBStarts, Int, TMap)
+type CompileInfo = (EntryPoint, BBStarts, Int, TrapMap)
emitFromBB :: B.ByteString -> Class Resolved -> MapBB -> CodeGen e s (CompileInfo, [Instruction])
getLabel _ [] = error "label not found!"
getLabel i ((x,l):xs) = if i==x then l else getLabel i xs
- efBB :: (BlockID, BasicBlock) -> TMap -> BBStarts -> [(BlockID, Label)] -> CodeGen e s (TMap, BBStarts)
+ efBB :: (BlockID, BasicBlock) -> TrapMap -> BBStarts -> [(BlockID, Label)] -> CodeGen e s (TrapMap, BBStarts)
efBB (bid, bb) calls bbstarts lmap =
if M.member bid bbstarts then
return (calls, bbstarts)
emit' insn = emit insn >> return Nothing
emit :: J.Instruction -> CodeGen e s ()
- emit POP = do -- print dropped value
- calladdr <- getCurrentOffset
- -- '5' is the size of the `call' instruction ( + immediate)
- let w32_calladdr = 5 + calladdr
- let trapaddr = (fromIntegral getaddr :: Word32)
- call (trapaddr - w32_calladdr)
+ emit POP = do -- dropp value
add esp (4 :: Word32)
emit DUP = push (Disp 0, esp)
+ emit AASTORE = emit IASTORE
emit IASTORE = do
pop eax -- value
pop ebx -- offset
add ebx (1 :: Word32)
pop ecx -- aref
mov (ecx, ebx, S4) eax
+ emit AALOAD = emit IALOAD
emit IALOAD = do
pop ebx -- offset
add ebx (1 :: Word32)
emit ARRAYLENGTH = do
pop eax
push (Disp 0, eax)
+ emit (ANEWARRAY _) = emit (NEWARRAY 10) -- 10 == T_INT
emit (NEWARRAY typ) = do
let tsize = case decodeS (0 :: Integer) (B.pack [typ]) of
T_INT -> 4
push eax -- push ref again
emit (NEW objidx) = do
let objname = buildClassID cls objidx
- amount <- liftIO $ getMethodSize objname
+ amount <- liftIO $ getObjectSize objname
push (amount :: Word32)
callMalloc
-- TODO(bernhard): save reference somewhere for GC
emit (ICONST_0) = push (0 :: Word32)
emit (ICONST_1) = push (1 :: Word32)
emit (ICONST_2) = push (2 :: Word32)
+ emit (ICONST_3) = push (3 :: Word32)
emit (ICONST_4) = push (4 :: Word32)
emit (ICONST_5) = push (5 :: Word32)
emit (ALOAD_ x) = emit (ILOAD_ x)