-
Notifications
You must be signed in to change notification settings - Fork 0
/
L7.hs
36 lines (32 loc) · 818 Bytes
/
L7.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 LLVM.General.AST
import qualified LLVM.General.AST as AST
import LLVM.General.Context
import LLVM.General.Module
import Control.Monad.Error
import LLVM.General.AST.Global
initModule :: AST.Module
initModule = defaultModule {
moduleName = "top"
, moduleDefinitions = [func]
}
retTy :: Type
retTy = IntegerType 32
func = GlobalDefinition $ functionDefaults {
name = Name "main"
, returnType = retTy
}
-- withContext :: (Context -> IO a) -> IO a
{-
withModuleFromAST
:: Context
-> AST.Module
-> (LLVM.General.Module.Module -> IO a)
-> Control.Monad.Trans.Error.ErrorT String IO a
-}
main :: IO ()
main = do
s <- withContext $ \context ->
runErrorT $ withModuleFromAST context initModule $ \m -> moduleLLVMAssembly m
case s of
Left err -> print err
Right ll -> putStrLn ll