-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This implements an experimental `mir_load_module` command, the first SAW command dedicated to MIR (Rust) code. I have added a basic test case to kick the tires and ensure that everything works as you would expect. You can't do much with the resulting MIR module yet (besides printing it in the SAW REPL), but more functionality for verifying the MIR code will come in future patches. Note that in order to produce a MIR JSON file suitable for SAW's needs, you must build your Rust code with one of the two `mir-json` tools added in GaloisInc/mir-json#41. This checks off one box in #1859.
- Loading branch information
1 parent
5df5615
commit 6583923
Showing
18 changed files
with
268 additions
and
11 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
all: test.json | ||
|
||
test.linked-mir.json: test.rs | ||
saw-rustc $< | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f test.linked-mir.json |
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 @@ | ||
{"fns":[{"abi":{"kind":"Rust"},"args":[],"body":{"blocks":[{"block":{"data":[{"kind":"Assign","lhs":{"data":[],"var":{"is_zst":false,"mut":{"kind":"Mut"},"name":"_0","ty":"ty::i32"}},"pos":"test.rs:1:23: 1:25","rhs":{"kind":"Use","usevar":{"data":{"rendered":{"kind":"int","size":4,"val":"42"},"ty":"ty::i32"},"kind":"Constant"}}}],"terminator":{"kind":"Return","pos":"test.rs:1:27: 1:27"}},"blockid":"bb0"}],"vars":[{"is_zst":false,"mut":{"kind":"Mut"},"name":"_0","ty":"ty::i32"}]},"name":"test/3a1fbbbh::foo[0]","return_ty":"ty::i32","spread_arg":null}],"adts":[],"statics":[],"vtables":[],"traits":[],"intrinsics":[{"inst":{"def_id":"test/3a1fbbbh::foo[0]","kind":"Item","substs":[]},"name":"test/3a1fbbbh::foo[0]"}],"tys":[{"name":"ty::i32","ty":{"intkind":{"kind":"I32"},"kind":"Int"}}],"roots":["test/3a1fbbbh::foo[0]"]} |
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 @@ | ||
pub fn foo() -> i32 { 42 } |
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 @@ | ||
enable_experimental; | ||
|
||
m <- mir_load_module "test.linked-mir.json"; | ||
print m; |
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,3 @@ | ||
set -e | ||
|
||
$SAW test.saw |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{-# LANGUAGE MultiParamTypeClasses #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
-- | Support for interfacing with MIR-related commands in SAW. | ||
module SAWServer.MIRCrucibleSetup | ||
( mirLoadModule | ||
, mirLoadModuleDescr | ||
) where | ||
|
||
import Control.Lens ( view ) | ||
import Data.Aeson ( FromJSON(..), withObject, (.:) ) | ||
|
||
import SAWScript.Crucible.MIR.Builtins ( mir_load_module ) | ||
|
||
import qualified Argo | ||
import qualified Argo.Doc as Doc | ||
import SAWServer as Server | ||
( ServerName(..), | ||
SAWState, | ||
sawTask, | ||
setServerVal ) | ||
import SAWServer.Exceptions ( notAtTopLevel ) | ||
import SAWServer.OK ( OK, ok ) | ||
import SAWServer.TopLevel ( tl ) | ||
import SAWServer.TrackFile ( trackFile ) | ||
|
||
data MIRLoadModuleParams | ||
= MIRLoadModuleParams ServerName FilePath | ||
|
||
instance FromJSON MIRLoadModuleParams where | ||
parseJSON = | ||
withObject "params for \"SAW/MIR/load module\"" $ \o -> | ||
MIRLoadModuleParams <$> o .: "name" <*> o .: "module name" | ||
|
||
instance Doc.DescribedMethod MIRLoadModuleParams OK where | ||
parameterFieldDescription = | ||
[ ("name", | ||
Doc.Paragraph [Doc.Text "The name to refer to the loaded module by later."]) | ||
, ("module name", | ||
Doc.Paragraph [Doc.Text "The file containing the MIR JSON file to load."]) | ||
] | ||
resultFieldDescription = [] | ||
|
||
mirLoadModuleDescr :: Doc.Block | ||
mirLoadModuleDescr = | ||
Doc.Paragraph [Doc.Text "Load the specified MIR module."] | ||
|
||
-- | The implementation of the @SAW/MIR/load module@ command. | ||
mirLoadModule :: MIRLoadModuleParams -> Argo.Command SAWState OK | ||
mirLoadModule (MIRLoadModuleParams serverName fileName) = | ||
do tasks <- view sawTask <$> Argo.getState | ||
case tasks of | ||
(_:_) -> Argo.raise $ notAtTopLevel $ map fst tasks | ||
[] -> | ||
do mirMod <- tl $ mir_load_module fileName | ||
setServerVal serverName mirMod | ||
trackFile fileName | ||
ok |
Oops, something went wrong.