Created
October 28, 2013 09:51
-
-
Save robstewart57/7194104 to your computer and use it in GitHub Desktop.
generating hello world LLVM function from Haskell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad | |
import Data.Word | |
import LLVM.Core | |
import LLVM.Util.File | |
-- prints out "hello world" | |
bldGreet :: CodeGenModule (Function (IO ())) | |
bldGreet = do | |
puts <- newNamedFunction ExternalLinkage "puts" :: TFunction (Ptr Word8 -> IO Word32) | |
func <- withStringNul "Hello, World!" $ \greetz -> | |
createFunction ExternalLinkage $ do | |
tmp <- getElementPtr greetz (0::Word32, (0::Word32, ())) | |
void $ call puts tmp | |
ret () | |
return func | |
main :: IO () | |
main = writeCodeGenModule "hello.bc" (_main =<< bldGreet) | |
where | |
_main :: (Function (IO ())) -> CodeGenModule (Function (IO ())) | |
_main func = createNamedFunction ExternalLinkage "main" $ do | |
call func | |
ret () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment