-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1121 from GaloisInc/lb/syntax-eval
crucible{,-llvm}-syntax: Evaluating programs with syntax extensions
- Loading branch information
Showing
13 changed files
with
285 additions
and
92 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE ImplicitParams #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
module Main (main) where | ||
|
||
import Control.Monad.IO.Class (liftIO) | ||
|
||
import Data.Parameterized.NatRepr (knownNat) | ||
|
||
import Lang.Crucible.Simulator.OverrideSim (writeGlobal) | ||
import Lang.Crucible.FunctionHandle (newHandleAllocator) | ||
|
||
import Lang.Crucible.Syntax.Prog | ||
import Lang.Crucible.Syntax.Overrides (setupOverrides) | ||
|
||
import Lang.Crucible.LLVM (llvmExtensionImpl) | ||
import Lang.Crucible.LLVM.DataLayout (EndianForm(LittleEndian)) | ||
import Lang.Crucible.LLVM.MemModel (defaultMemOptions, emptyMem, mkMemVar) | ||
|
||
import Lang.Crucible.LLVM.Syntax (emptyParserHooks, llvmParserHooks) | ||
|
||
import qualified Options.Applicative as Opt | ||
import Options.Applicative ( (<**>) ) | ||
|
||
file :: String -> Opt.Parser FilePath | ||
file which = Opt.strArgument (Opt.metavar "FILE" <> Opt.help ("The " <> which <> " file")) | ||
|
||
input :: Opt.Parser FilePath | ||
input = file "input" | ||
|
||
output :: Opt.Parser FilePath | ||
output = file "output" | ||
|
||
command :: Opt.Parser Command | ||
command = | ||
Opt.subparser $ | ||
(Opt.command "check" | ||
(Opt.info (CheckCommand <$> parseCheck) | ||
(Opt.fullDesc <> Opt.progDesc "Check a file" <> Opt.header "crucibler"))) | ||
<> (Opt.command "simulate" | ||
(Opt.info (SimulateCommand <$> simFile) | ||
(Opt.fullDesc <> Opt.progDesc "Simulate a file" <> Opt.header "crucibler"))) | ||
<> (Opt.command "profile" | ||
(Opt.info (ProfileCommand <$> profFile) | ||
(Opt.fullDesc <> Opt.progDesc "Simulate a file, with profiling" <> Opt.header "crucibler"))) | ||
<> (Opt.command "repl" | ||
(Opt.info (pure ReplCommand) (Opt.fullDesc <> Opt.progDesc "Open a REPL"))) | ||
|
||
profFile :: Opt.Parser ProfCmd | ||
profFile = | ||
ProfCmd <$> input <*> output | ||
|
||
simFile :: Opt.Parser SimCmd | ||
simFile = | ||
SimCmd <$> input <*> Opt.optional output | ||
|
||
parseCheck :: Opt.Parser CheckCmd | ||
parseCheck = | ||
CheckCmd <$> input <*> Opt.optional output <*> Opt.switch (Opt.help "Pretty-print the source file") | ||
|
||
main :: IO () | ||
main = | ||
do cmd <- Opt.customExecParser prefs info | ||
ha <- newHandleAllocator | ||
mvar <- mkMemVar "llvm_memory" ha | ||
let ?ptrWidth = knownNat @64 | ||
let ?parserHooks = llvmParserHooks emptyParserHooks mvar | ||
let simulationHooks = | ||
defaultSimulateProgramHooks | ||
{ setupHook = \_sym _ha -> do | ||
mem <- liftIO (emptyMem LittleEndian) | ||
writeGlobal mvar mem | ||
, setupOverridesHook = setupOverrides | ||
} | ||
let ext _ = let ?recordLLVMAnnotation = \_ _ _ -> pure () | ||
in llvmExtensionImpl defaultMemOptions | ||
execCommand ext simulationHooks cmd | ||
where info = Opt.info (command <**> Opt.helper) (Opt.fullDesc) | ||
prefs = Opt.prefs $ Opt.showHelpOnError <> Opt.showHelpOnEmpty |
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
(defun @main () Unit | ||
(start start: | ||
(let blk0 (the Nat 0)) | ||
(let off0 (bv 64 0)) | ||
(let p0 (ptr 64 blk0 off0)) | ||
(let p (ptr-ite 64 #t p0 p0)) | ||
(let blk (ptr-block 64 p)) | ||
(let off (ptr-offset 64 p)) | ||
(assert! (equal? blk0 blk) "block numbers equal") | ||
(assert! (equal? off0 off) "offsets equal") | ||
|
||
(let sz (bv 64 1)) | ||
(let a (alloca none sz)) | ||
(let vblk0 (the Nat 0)) | ||
(let voff0 (bv 8 255)) | ||
(let v0 (ptr 8 vblk0 voff0)) | ||
(store none i8 a v0) | ||
(let v (load none i8 a)) | ||
(let vblk (ptr-block 8 v)) | ||
(let voff (ptr-offset 8 v)) | ||
(assert! (equal? vblk0 vblk) "stored block numbers equal") | ||
(assert! (equal? voff0 voff) "stored offsets equal") | ||
|
||
(return ()))) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
==== Begin Simulation ==== | ||
|
||
==== Finish Simulation ==== | ||
==== No proof obligations ==== |
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
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
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
Oops, something went wrong.