aboutsummaryrefslogtreecommitdiff
path: root/CodeGen.hs
diff options
context:
space:
mode:
Diffstat (limited to 'CodeGen.hs')
-rw-r--r--CodeGen.hs13
1 files changed, 13 insertions, 0 deletions
diff --git a/CodeGen.hs b/CodeGen.hs
index 9a46af7..8eee371 100644
--- a/CodeGen.hs
+++ b/CodeGen.hs
@@ -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)