Skip to content

Instantly share code, notes, and snippets.

@ghorn
Last active December 21, 2015 03:29
Show Gist options
  • Save ghorn/6242691 to your computer and use it in GitHub Desktop.
Save ghorn/6242691 to your computer and use it in GitHub Desktop.
llvm AST checker
{-# 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