From 4f8eac54ade38ddb60f47ba28221353aeb1a0e35 Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Tue, 12 Jun 2012 12:43:22 +0200 Subject: [PATCH] refactor: better names for TrapInfo^WTrapCause --- Mate/ClassPool.hs | 4 ++-- Mate/MethodPool.hs | 11 +++++------ Mate/Types.hs | 12 ++++++------ Mate/X86CodeGen.hs | 14 +++++++------- Mate/X86TrapHandling.hs | 12 ++++++------ 5 files changed, 26 insertions(+), 27 deletions(-) diff --git a/Mate/ClassPool.hs b/Mate/ClassPool.hs index cb38b28..8d88ad3 100644 --- a/Mate/ClassPool.hs +++ b/Mate/ClassPool.hs @@ -98,8 +98,8 @@ getStaticFieldAddr from = do let sfi = trapmap M.! w32_from setTrapMap $ M.delete w32_from trapmap case sfi of - (SFI (StaticFieldInfo cls field)) -> getStaticFieldOffset cls field - _ -> error "getFieldAddr: no trapInfo. abort" + (StaticField (StaticFieldInfo cls field)) -> getStaticFieldOffset cls field + _ -> error "getFieldAddr: no TrapCause found. abort" -- interface + method + signature plz! getInterfaceMethodOffset :: B.ByteString -> B.ByteString -> B.ByteString -> IO Word32 diff --git a/Mate/MethodPool.hs b/Mate/MethodPool.hs index 44e0545..7a0cda1 100644 --- a/Mate/MethodPool.hs +++ b/Mate/MethodPool.hs @@ -45,12 +45,11 @@ getMethodEntry signal_from methodtable = do let mi = tmap M.! w32_from let mi'@(MethodInfo method cm sig) = case mi of - (MI x) -> x - (VI _(MethodInfo methname _ msig)) -> - MethodInfo methname (vmap M.! fromIntegral methodtable) msig - (II _ (MethodInfo methname _ msig)) -> - MethodInfo methname (vmap M.! fromIntegral methodtable) msig - _ -> error "getMethodEntry: no trapInfo. abort." + (StaticMethod x) -> x + (VirtualMethod _ (MethodInfo methname _ msig)) -> newMi methname msig + (InterfaceMethod _ (MethodInfo methname _ msig)) -> newMi methname msig + _ -> error "getMethodEntry: no TrapCause found. abort." + where newMi mn = MethodInfo mn (vmap M.! fromIntegral methodtable) setTrapMap $ M.delete w32_from tmap case M.lookup mi' mmap of Nothing -> do diff --git a/Mate/Types.hs b/Mate/Types.hs index 71b0857..59ebd6a 100644 --- a/Mate/Types.hs +++ b/Mate/Types.hs @@ -28,13 +28,13 @@ type MapBB = M.Map BlockID BasicBlock -- Word32 = point of method call in generated code -- MethodInfo = relevant information about callee -type TrapMap = M.Map Word32 TrapInfo +type TrapMap = M.Map Word32 TrapCause -data TrapInfo = - MI MethodInfo | -- for static calls - VI Bool MethodInfo | -- for virtual calls - II Bool MethodInfo | -- for interface calls - SFI StaticFieldInfo deriving Show +data TrapCause = + StaticMethod MethodInfo | -- for static calls + VirtualMethod Bool MethodInfo | -- for virtual calls + InterfaceMethod Bool MethodInfo | -- for interface calls + StaticField StaticFieldInfo deriving Show data StaticFieldInfo = StaticFieldInfo { sfiClassName :: B.ByteString, diff --git a/Mate/X86CodeGen.hs b/Mate/X86CodeGen.hs index 56b48f7..de370be 100644 --- a/Mate/X86CodeGen.hs +++ b/Mate/X86CodeGen.hs @@ -94,7 +94,7 @@ emitFromBB method sig cls hmap = do offset <- getCodeOffset return $ w32_ep + fromIntegral offset - emitInvoke :: Word16 -> Bool -> CodeGen e s (Maybe (Word32, TrapInfo)) + emitInvoke :: Word16 -> Bool -> CodeGen e s (Maybe (Word32, TrapCause)) emitInvoke cpidx hasThis = do let l = buildMethodID cls cpidx calladdr <- getCurrentOffset @@ -108,9 +108,9 @@ emitFromBB method sig cls hmap = do -- push result on stack if method has a return value when (methodHaveReturnValue cls cpidx) (push eax) -- +2 is for correcting eip in trap context - return $ Just (calladdr + 2, MI l) + return $ Just (calladdr + 2, StaticMethod l) - emit' :: J.Instruction -> CodeGen e s (Maybe (Word32, TrapInfo)) + emit' :: J.Instruction -> CodeGen e s (Maybe (Word32, TrapCause)) emit' (INVOKESPECIAL cpidx) = emitInvoke cpidx True emit' (INVOKESTATIC cpidx) = emitInvoke cpidx False emit' (INVOKEINTERFACE cpidx _) = do @@ -137,7 +137,7 @@ emitFromBB method sig cls hmap = do -- we figure that out at run-time, in the methodpool, -- depending on the method-table-ptr let imm8 = is8BitOffset offset - return $ Just (calladdr + (if imm8 then 3 else 6), II imm8 mi) + return $ Just (calladdr + (if imm8 then 3 else 6), InterfaceMethod imm8 mi) emit' (INVOKEVIRTUAL cpidx) = do -- get methodInfo entry let mi@(MethodInfo methodname objname msig@(MethodSignature args _)) = buildMethodID cls cpidx @@ -161,17 +161,17 @@ emitFromBB method sig cls hmap = do -- we figure that out at run-time, in the methodpool, -- depending on the method-table-ptr let imm8 = is8BitOffset offset - return $ Just (calladdr + (if imm8 then 3 else 6), VI imm8 mi) + return $ Just (calladdr + (if imm8 then 3 else 6), VirtualMethod imm8 mi) emit' (PUTSTATIC cpidx) = do pop eax trapaddr <- getCurrentOffset mov (Addr 0x00000000) eax -- it's a trap - return $ Just (trapaddr, SFI $ buildStaticFieldID cls cpidx) + return $ Just (trapaddr, StaticField $ buildStaticFieldID cls cpidx) emit' (GETSTATIC cpidx) = do trapaddr <- getCurrentOffset mov eax (Addr 0x00000000) -- it's a trap push eax - return $ Just (trapaddr, SFI $ buildStaticFieldID cls cpidx) + return $ Just (trapaddr, StaticField $ buildStaticFieldID cls cpidx) emit' insn = emit insn >> return Nothing emit :: J.Instruction -> CodeGen e s () diff --git a/Mate/X86TrapHandling.hs b/Mate/X86TrapHandling.hs index f383c2d..882a541 100644 --- a/Mate/X86TrapHandling.hs +++ b/Mate/X86TrapHandling.hs @@ -21,15 +21,15 @@ getTrapType :: CUInt -> CUInt -> IO CUInt getTrapType signal_from from2 = do tmap <- getTrapMap case M.lookup (fromIntegral signal_from) tmap of - (Just (MI _)) -> return 0 - (Just (SFI _)) -> return 2 + (Just (StaticMethod _)) -> return 0 + (Just (StaticField _)) -> return 2 (Just _) -> error "getTrapMap: doesn't happen" -- maybe we've a hit on the second `from' value Nothing -> case M.lookup (fromIntegral from2) tmap of - (Just (VI True _)) -> return 1 - (Just (VI False _)) -> return 5 - (Just (II True _)) -> return 4 - (Just (II False _)) -> return 8 + (Just (VirtualMethod True _)) -> return 1 + (Just (VirtualMethod False _)) -> return 5 + (Just (InterfaceMethod True _)) -> return 4 + (Just (InterfaceMethod False _)) -> return 8 (Just _) -> error "getTrapType: abort #1 :-(" Nothing -> error $ "getTrapType: abort #2 :-(" ++ show signal_from ++ ", " ++ show from2 ++ ", " ++ show tmap -- 2.25.1