1 module Mate.Types where
5 import qualified Data.Map as M
6 import qualified Data.ByteString.Lazy as B
7 import Codec.Binary.UTF8.String hiding (encode,decode)
14 -- Represents a CFG node
15 data BasicBlock = BasicBlock {
16 code :: [Instruction],
19 -- describes (leaving) edges of a CFG node
20 data BBEnd = Return | FallThrough BlockID | OneTarget BlockID | TwoTarget BlockID BlockID deriving Show
22 type MapBB = M.Map BlockID BasicBlock
25 -- Word32 = point of method call in generated code
26 -- MethodInfo = relevant information about callee
27 type CMap = M.Map Word32 MethodInfo
29 -- B.ByteString = name of method
30 -- Word32 = entrypoint of method
31 type MMap = M.Map MethodInfo Word32
35 data MethodInfo = MethodInfo {
36 methName :: B.ByteString,
37 cName :: B.ByteString,
38 mSignature :: MethodSignature}
40 instance Eq MethodInfo where
41 (MethodInfo m_a c_a s_a) == (MethodInfo m_b c_b s_b) =
42 (m_a == m_b) && (c_a == c_b) && (s_a == s_b)
44 -- TODO(bernhard): not really efficient. also, outsource that to hs-java
45 instance Ord MethodSignature where
46 compare (MethodSignature args_a ret_a) (MethodSignature args_b ret_b)
47 | cmp_args /= EQ = cmp_args
48 | otherwise = (show ret_a) `compare` (show ret_b)
50 cmp_args = (show args_a) `compare` (show args_b)
52 instance Ord MethodInfo where
53 compare (MethodInfo m_a c_a s_a) (MethodInfo m_b c_b s_b)
56 | otherwise = s_a `compare` s_b
58 cmp_m = m_a `compare` m_b
59 cmp_c = c_a `compare` c_b
61 instance Show MethodInfo where
62 show (MethodInfo method c sig) =
63 (toString c) ++ "." ++ (toString method) ++ "." ++ (show sig)
66 toString :: B.ByteString -> String
67 toString bstr = decodeString $ map (chr . fromIntegral) $ B.unpack bstr