Skip to content

Instantly share code, notes, and snippets.

@23Skidoo
Forked from robstewart57/hello-world-llvm.hs
Last active December 26, 2015 18:39
Show Gist options
  • Save 23Skidoo/7195530 to your computer and use it in GitHub Desktop.
Save 23Skidoo/7195530 to your computer and use it in GitHub Desktop.
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