Skip to content

Commit

Permalink
modify ucomp
Browse files Browse the repository at this point in the history
  • Loading branch information
Haoqiang Fan committed Jan 7, 2017
1 parent 1865673 commit ac17529
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 10 additions & 1 deletion UCompile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ import qualified Data.Map as Map

compileToC :: LExpr -> [Char]
compileToC l = header++compileToCS l (Map.fromList []) 0 footer where
header="void main_program(){\nexecuteVExp("
header="typedef struct VExp VExp;\n\
\VExp * makeBuiltin(const char* func_name);\n\
\VExp * makeInt(int a);\n\
\VExp * makeDouble(double a);\n\
\VExp * makeAbs(VExp* abs_val);\n\
\VExp * makeRef(int ref_val);\n\
\VExp * makeApply(VExp * f,VExp * x);\n\
\int executeVExp(VExp * exp);\n\
\int main(){\n\
\return executeVExp("
footer=");\n}"
compileToCS :: LExpr -> Map.Map [Char] Int -> Int -> ShowS
compileToCS l names curlevel = case l of
Expand Down
8 changes: 5 additions & 3 deletions ucomp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ main = do
putStrLn "ucomp: ifname.u"
else do
let ifname = head args
let outputc = "-c" `elem` (tail args)
if not$isSuffixOf ".u" ifname then do
putStrLn "filename must end with .u"
else do
Expand All @@ -22,12 +23,13 @@ main = do
MFail msg modname pos -> putStrLn ("error loading "++modname++" at "++(show pos)++": "++msg)
MSucc (MLoadContext loaded curchain)
| (not (Set.member "main.main" loaded)) -> putStrLn "main.main not defined"
| outputc -> do
fout <- openFile (basename++".c") WriteMode
hPutStrLn fout$compileToC$assembleChainLExpr curchain (LRef "main.main")
hClose fout
| otherwise -> do
let llname = (basename ++ ".ll")
let sname = (basename ++ ".s")
-- fout <- openFile (ifname++"c") WriteMode
-- hPutStrLn fout$compileToC$assembleChainLExpr curchain (LRef "main.main")
-- hClose fout
fout <- openFile llname WriteMode
hPutStrLn fout$compileToLLVM$assembleChainLExpr curchain (LRef "main.main")
hClose fout
Expand Down

0 comments on commit ac17529

Please sign in to comment.