-
-
Save 23Skidoo/7195530 to your computer and use it in GitHub Desktop.
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 :: String -> CodeGenModule (Function (IO ())) | |
bldGreet userName = do | |
puts <- newNamedFunction ExternalLinkage "puts" :: TFunction (Ptr Word8 -> IO Word32) | |
func <- withStringNul ("Hello, " ++ userName ++ "!") $ \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 "Joe") | |
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