X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mate.git;a=blobdiff_plain;f=Mate%2FX86CodeGen.hs;fp=Mate%2FX86CodeGen.hs;h=03333ce0d35d5163a3b31da763a60eb3d20b6ad6;hp=621f0c2c6c70ed171a5f0236f06f323abe05e384;hb=3398391fa883278959063506c8051943aba9c4ee;hpb=ecec298c7b0723081b1aea7447eae6f04118df34 diff --git a/Mate/X86CodeGen.hs b/Mate/X86CodeGen.hs index 621f0c2..03333ce 100644 --- a/Mate/X86CodeGen.hs +++ b/Mate/X86CodeGen.hs @@ -45,7 +45,7 @@ type BBStarts = M.Map BlockID Int type CompileInfo = (EntryPoint, Int, TrapMap) -emitFromBB :: Class Direct -> RawMethod -> CodeGen e s (CompileInfo, [Instruction]) +emitFromBB :: Class Direct -> RawMethod -> CodeGen e JpcNpcMap (CompileInfo, [Instruction]) emitFromBB cls method = do let keys = M.keys hmap llmap <- mapM (newNamedLabel . (++) "bb_" . show) keys @@ -65,16 +65,16 @@ emitFromBB cls method = do getLabel bid [] = error $ "label " ++ show bid ++ " not found" getLabel i ((x,l):xs) = if i==x then l else getLabel i xs - efBB :: [(BlockID, Label)] -> BlockID -> CodeGen e s [(Maybe (Word32, TrapCause))] + efBB :: [(BlockID, Label)] -> BlockID -> CodeGen e JpcNpcMap [(Maybe (Word32, TrapCause))] efBB lmap bid = do defineLabel $ getLabel bid lmap - ret <- mapM emit'' $ code bb + retval <- mapM emit'' $ code bb case successor bb of FallThrough t -> do -- TODO(bernhard): le dirty hax. see java/lang/Integer.toString(int, int) jmp (getLabel t lmap) _ -> return () - return ret + return retval where bb = hmap M.! bid @@ -98,7 +98,7 @@ emitFromBB cls method = do -- like: call $0x01234567 calladdr <- emitSigIllTrap 5 let patcher reip = do - entryAddr <- liftIO $ getMethodEntry l + (entryAddr, _) <- liftIO $ getMethodEntry l call (fromIntegral (entryAddr - (reip + 5)) :: NativeWord) return reip -- discard arguments on stack @@ -137,8 +137,12 @@ emitFromBB cls method = do -- depending on the method-table-ptr return $ Just (calladdr, VirtualCall isInterface mi offset) - emit'' :: J.Instruction -> CodeGen e s (Maybe (Word32, TrapCause)) - emit'' insn = newNamedLabel ("jvm_insn: " ++ show insn) >>= defineLabel >> emit' insn + emit'' :: J.Instruction -> CodeGen e JpcNpcMap (Maybe (Word32, TrapCause)) + emit'' insn = do + ep <- (fromIntegral . ptrToIntPtr) <$> getEntryPoint + jpcrpc <- getState + setState (M.insert ep bid jpcrpc) + newNamedLabel ("jvm_insn: " ++ show insn) >>= defineLabel >> emit' insn emit' :: J.Instruction -> CodeGen e s (Maybe (Word32, TrapCause)) emit' (INVOKESPECIAL cpidx) = emitInvoke cpidx True