Last active
December 21, 2015 03:29
-
-
Save ghorn/6242691 to your computer and use it in GitHub Desktop.
llvm AST checker
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
{-# OPTIONS_GHC -Wall #-} | |
module Main ( main ) where | |
import LLVM.General | |
import LLVM.General.Analysis | |
import LLVM.General.Context | |
import Control.Monad.Trans.Error | |
main :: IO () | |
main = do | |
asm <- getContents | |
putStrLn "------------------ input: -------------------" | |
putStrLn asm | |
validateAsm asm | |
validateAsm :: String -> IO () | |
validateAsm llvmAsm = do | |
_ <- withContext $ \context -> do | |
runErrorT $ withModuleFromString context llvmAsm $ \mdl0 -> do | |
putStrLn "------------------ llvm's interpretation: -------------" | |
moduleString mdl0 >>= putStrLn | |
vmdl' <- runErrorT $ verify mdl0 | |
putStrLn "------------------- verifying... -----------------------" | |
case vmdl' of Left err -> do | |
putStrLn "verifier fail :(\n" | |
putStrLn err | |
Right _ -> do | |
putStrLn "verifier success!!" | |
mdlAst <- moduleAST mdl0 | |
runErrorT $ withModuleFromAST context mdlAst $ \mdl1 -> do | |
putStrLn "-------------- to, then from the AST: -----------------" | |
moduleString mdl1 >>= putStrLn | |
vmdl <- runErrorT $ verify mdl1 | |
putStrLn "------------------- verifying... -----------------------" | |
case vmdl of Left err -> do | |
putStrLn "verifier fail :(\n" | |
putStrLn err | |
Right _ -> do | |
putStrLn "verifier success!!" | |
return () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment