diff options
Diffstat (limited to 'X64.hs')
-rw-r--r-- | X64.hs | 29 |
1 files changed, 17 insertions, 12 deletions
@@ -184,26 +184,31 @@ instance Stringifiable XRef where stringify (XMem _ _ (mult, _) _ _) | not (mult `elem` [0,1,2,4,8]) = error $ "Register multiplier has invalid value " ++ show mult ++ " in XMem" - stringify (XMem sz mr pair lab off) = - let res = intercalate "+" (catMaybes [goR1 mr, goPair pair, goLab lab]) ++ goOff off - in szword sz ++ " " ++ if null res then "[0]" else "[" ++ res ++ "]" + stringify x@(XMem sz _ _ _ _) = szword sz ++ " " ++ stringify_only_xmem_brackets x where szword 1 = "byte" szword 2 = "word" szword 4 = "dword" szword 8 = "qword" szword _ = undefined - goR1 Nothing = Nothing - goR1 (Just r) = Just $ stringify (XReg 8 r) - goPair (0, _) = Nothing - goPair (mult, r) = Just $ show mult ++ "*" ++ stringify (XReg 8 r) - goLab = id - goOff o | o > 0 = '+' : show o - | o < 0 = show o - | otherwise = "" stringify (XImm imm) = show imm +stringify_only_xmem_brackets :: XRef -> String +stringify_only_xmem_brackets (XMem _ mr pair lab off) = + let res = intercalate "+" (catMaybes [goR1 mr, goPair pair, goLab lab]) ++ goOff off + in if null res then "[0]" else "[" ++ res ++ "]" + where + goR1 Nothing = Nothing + goR1 (Just r) = Just $ stringify (XReg 8 r) + goPair (0, _) = Nothing + goPair (mult, r) = Just $ show mult ++ "*" ++ stringify (XReg 8 r) + goLab = id + goOff o | o > 0 = '+' : show o + | o < 0 = show o + | otherwise = "" +stringify_only_xmem_brackets _ = undefined + instance Stringifiable Reg where stringify (Reg x) = stringify x instance Stringifiable Mem where stringify (Mem x) = stringify x instance Stringifiable Imm where stringify (Imm x) = stringify x @@ -235,7 +240,7 @@ instance Stringifiable CondCode where instance Stringifiable Ins where stringify (MOV a b) = "mov " ++ stringify a ++ ", " ++ stringify b stringify (MOVi a b) = "mov " ++ stringify a ++ ", " ++ stringify b - stringify (LEA a b) = "lea " ++ stringify a ++ ", " ++ stringify b + stringify (LEA a (Mem b)) = "lea " ++ stringify a ++ ", " ++ stringify_only_xmem_brackets b stringify (MOVSX a b@(RegMem bx)) = case compare (xrefGetSize bx) 4 of EQ -> "movsxd " ++ stringify a ++ ", " ++ stringify b LT -> "movsx " ++ stringify a ++ ", " ++ stringify b |