diff options
-rw-r--r-- | codegen.hs | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -64,12 +64,12 @@ runCGMonad m = let (e, s) = runState (runExceptT (unMon m)) initialGenState getUniqueId :: CGMonad Integer getUniqueId = state $ \s -> (nextId s, s {nextId = nextId s + 1}) -getNewName :: String -> CGMonad String +getNewName :: String -> CGMonad LLName getNewName base = fmap ((base++) . show) getUniqueId newBlock :: CGMonad LLName newBlock = do - name <- getNewName "bb" + name <- getNewName ".bb" state $ \s -> (name, s { currentBlock = Just name, allBlocks = Map.insert name (A.BasicBlock (A.Name name) [] undefined) $ allBlocks s @@ -96,7 +96,7 @@ addInstr :: A.Instruction -> CGMonad LLName addInstr instr | instrReturnsVoid instr = addNamedInstr $ A.Do instr | otherwise = do - name <- getNewName "t" + name <- getNewName ".t" addNamedInstr $ A.Name name A.:= instr addNamedInstr :: A.Named A.Instruction -> CGMonad LLName @@ -150,7 +150,7 @@ lookupGlobalFunction name = liftM (fromJust . Map.lookup name . globalFunctions) addStringLiteral :: String -> CGMonad (A.Type, LLName) addStringLiteral str = do - name <- getNewName "str" + name <- getNewName ".str" state $ \s -> ((A.ptr $ A.ArrayType (fromIntegral (length str + 1)) A.i8, name), s {stringLiterals = (name, str) : stringLiterals s}) @@ -229,7 +229,7 @@ genGlobalVars (Program decs) = liftM (mapMaybe id) $ mapM gen decs return Nothing gen (DecExtern t@(TypeFunc rt ats) n) = do setGlobalFunction n n t - argnames <- sequence $ replicate (length ats) (getNewName "arg") + argnames <- sequence $ replicate (length ats) (getNewName ".arg") return $ Just $ A.GlobalDefinition $ A.functionDefaults { A.G.returnType = toLLVMType rt, @@ -277,7 +277,7 @@ genFunctions (Program decs) = liftM (mapMaybe id) $ mapM gen decs return $ Just $ A.GlobalDefinition $ A.functionDefaults { A.G.returnType = toLLVMType rettype, A.G.name = A.Name name, - A.G.parameters = ([A.Parameter (toLLVMType t) (A.Name ("farg_"++n)) [] | (t,n) <- args], False), + A.G.parameters = ([A.Parameter (toLLVMType t) (A.Name (".farg_"++n)) [] | (t,n) <- args], False), A.G.basicBlocks = bbs } gen _ = return Nothing @@ -291,7 +291,7 @@ genFunctionBlock bl (rettype, fname) args = do prepArg (t,n) = do label <- addInstr $ A.Alloca (toLLVMType t) Nothing 0 [] void $ addInstr $ A.Store False (A.LocalReference (A.ptr (toLLVMType t)) (A.Name label)) - (A.LocalReference (toLLVMType t) (A.Name ("farg_"++n))) + (A.LocalReference (toLLVMType t) (A.Name (".farg_"++n))) Nothing 0 [] setVar n label t sequence_ $ map prepArg args |