Created
January 19, 2013 05:32
-
-
Save wavewave/4570925 to your computer and use it in GitHub Desktop.
reading llvm bitcode in haskell and execute. llvm created from clang-llvm. (SFMT: mersenne twister)
This file contains hidden or 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.Int | |
| import Data.Word | |
| import LLVM.Core | |
| import LLVM.ExecutionEngine | |
| import Foreign.C.Types | |
| main = do | |
| initializeNativeTarget | |
| m <- readBitcodeFromFile "SFMT.bc" | |
| funcs <- getModuleValues m | |
| mapM_ (print . fst) funcs | |
| let fio_get_initialized :: Function ( IO Int32 ) | |
| Just fio_get_initialized = lookup "get_initialized" funcs >>= castModuleValue | |
| fio_init_gen_rand :: Function (Int32 -> IO ()) | |
| Just fio_init_gen_rand = lookup "init_gen_rand" funcs >>= castModuleValue | |
| fio_gen_rand32 :: Function ( IO Word32) | |
| Just fio_gen_rand32 = lookup "gen_rand32" funcs >>= castModuleValue | |
| io_get_initialized <- runEngineAccess (generateFunction fio_get_initialized) | |
| io_init_gen_rand <- runEngineAccess (generateFunction fio_init_gen_rand) | |
| io_gen_rand32 <- runEngineAccess (generateFunction fio_gen_rand32) | |
| io_get_initialized | |
| io_init_gen_rand 30 | |
| replicateM_ 50 $ do | |
| x <- io_gen_rand32 | |
| print x | |
| return () | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment