refactor: better names for TrapInfo^WTrapCause
authorBernhard Urban <lewurm@gmail.com>
Tue, 12 Jun 2012 10:43:22 +0000 (12:43 +0200)
committerBernhard Urban <lewurm@gmail.com>
Tue, 12 Jun 2012 19:50:20 +0000 (21:50 +0200)
Mate/ClassPool.hs
Mate/MethodPool.hs
Mate/Types.hs
Mate/X86CodeGen.hs
Mate/X86TrapHandling.hs

index cb38b28fbd22d89b4237c0735e9d395089e7e85e..8d88ad325e31f02e5835aa6923d91888f9b71b23 100644 (file)
@@ -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
index 44e0545cf599980a17c72779009b6bdc068e301c..7a0cda170964a761e50affbfe0a3c31d43e940d0 100644 (file)
@@ -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
index 71b08571e0bd578769deec226a7d0a628885a6c1..59ebd6a568afb97487f6993b1c015fd68850e46f 100644 (file)
@@ -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,
index 56b48f7061883b44402bcf99ea6b663dab9c18ef..de370bea9c5aef3d40047861a8cb11877676f998 100644 (file)
@@ -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 ()
index f383c2d3635afdec98079b70931d7101cf929374..882a541f1eefb7b5fe89eed22285d7a2d4cf524e 100644 (file)
@@ -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