-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathucomp.hs
36 lines (35 loc) · 1.22 KB
/
ucomp.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import Data.List
import System.Environment
import System.IO
import System.Process
import UModuleLoader
import ULambdaExpression
import UCompile
import qualified Data.Set as Set
main = do
args <- getArgs
if null args then
putStrLn "ucomp: ifname.u"
else do
let ifname = head args
if not$isSuffixOf ".u" ifname then do
putStrLn "filename must end with .u"
else do
let basename = take (length ifname - 2) ifname
loadc <- loadMainModule ifname defaultLoadContext
case loadc of
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"
| 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
rawSystem "llc" [llname,"-o",sname,"-O2"]
rawSystem "clang" ["simpleruntime.ll",sname,"-o",basename,"-O2","-lm"]
return ()