diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-08-27 20:34:57 +0200 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-08-27 20:34:57 +0200 |
commit | c129641b18156b463cd12318ba956c85a9017e39 (patch) | |
tree | 1b17cfa6b009db854380c983b7ea9a00507b9513 /CodeGen.hs | |
parent | aa049227c17f15ad22092f1fcab4410bbf3521ba (diff) |
Tenth
Diffstat (limited to 'CodeGen.hs')
-rw-r--r-- | CodeGen.hs | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -5,6 +5,7 @@ module CodeGen(codegen) where import Control.Monad import Control.Monad.Except import Control.Monad.State.Strict +import Data.Char import Data.List import Data.Maybe import Data.Map.Strict ((!)) @@ -73,6 +74,10 @@ codegen (IRProgram vars funcs) = do codegenVar :: DVar -> Error String codegenVar (DVar TInt n (ELit (LInt i) (Just TInt))) = Right $ n ++ ": dq " ++ show i +codegenVar (DVar (TArr TChar _) n (ELit (LStr s) _)) = Right $ + n ++ ":\n" ++ + "\tdq " ++ show (length s + 1) ++ "\n" ++ + "\tdb " ++ (intercalate ", " $ map show $ map ord s ++ [0]) codegenVar _ = Left "Unsupported global variable declaration" @@ -196,6 +201,13 @@ codegenIns m (IMov d s) | otherwise = addIns $ mkmov dm sm where dm = mkxref d m sm = mkxref s m +codegenIns m (ILea d n) + | X64.isXMem dm = do + addIns $ LEA (xref $ XReg (fromIntegral $ refSize d) RAX) (xref sm) + addIns $ mkmov dm (XReg (fromIntegral $ refSize d) RAX) + | otherwise = addIns $ LEA (xref dm) (xref sm) + where dm = mkxref d m + sm = mkxref (Global 8 n) m codegenIns m (IStore d s) = do sourcexref <- if X64.isXMem sm then do @@ -394,6 +406,7 @@ collectTempRefs bbs = where listRefsIns :: IRIns -> [[LA.Access Ref]] listRefsIns (IMov a b) = [[LA.Read b], [LA.Write a]] + listRefsIns (ILea a _) = [[LA.Write a]] listRefsIns (IStore a b) = [[LA.Read a, LA.Read b]] listRefsIns (ILoad a b) = [[LA.Read b], [LA.Write a]] listRefsIns (IAri at a b c) |