-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split out crucible-mir from crux-mir
For the most part, most code was moved wholesale from `crux-mir` with only minor changes (I removed redundant imports to more easily determine which library dependencies could be dropped in `crucible-mir`). The most unusual change was creating a new `Mir.ParseTranslate` module in `crucible-mir`, which contains the `parseMIR` and `translateMIR` functions previously defined in `Mir.Generate` (now a `crux-mir` module that only exports `generateMIR`). Fixes #1065.
- Loading branch information
1 parent
a946dc9
commit 57caee6
Showing
25 changed files
with
234 additions
and
184 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# 0.1 | ||
|
||
* TODO: Describe API changes here |
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,30 @@ | ||
Copyright (c) 2017-2023 Galois, Inc. | ||
|
||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
|
||
* Neither the name of the authors nor the names of other | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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,6 @@ | ||
# crucible-mir | ||
|
||
This package implements a MIR frontend for Crucible. This exports all of the | ||
code that is useful across multiple projects that make use of MIR, such as | ||
[`crux-mir`](https://github.com/GaloisInc/crucible/blob/master/crux-mir) and | ||
[`crux-mir-comp`](https://github.com/GaloisInc/saw-script/blob/master/crux-mir-comp). |
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,56 @@ | ||
name: crucible-mir | ||
version: 0.1 | ||
-- synopsis: | ||
-- description: | ||
homepage: https://github.com/GaloisInc/crucible/blob/master/crucible-mir/README.md | ||
license: BSD3 | ||
license-file: LICENSE | ||
author: Joshua Gancher, | ||
Rob Dockins, | ||
Andrey Chudnov, | ||
Stephanie Weirich, | ||
Stuart Pernsteiner | ||
maintainer: spernsteiner@galois.com | ||
copyright: 2017-2023 Galois, Inc. | ||
category: Web | ||
build-type: Simple | ||
cabal-version: 2.0 | ||
extra-source-files: README.md | ||
|
||
library | ||
default-language: Haskell2010 | ||
build-depends: base >= 4.11 && < 5, | ||
aeson < 2.1, | ||
bv-sized, | ||
bytestring, | ||
prettyprinter >= 1.7.0, | ||
text, | ||
unordered-containers, | ||
crucible, | ||
parameterized-utils >= 1.0.8, | ||
containers, | ||
lens, | ||
vector, | ||
mtl, | ||
regex-compat, | ||
regex-base, | ||
transformers, | ||
what4, | ||
scientific >= 0.3, | ||
template-haskell | ||
|
||
hs-source-dirs: src | ||
exposed-modules: Mir.JSON | ||
Mir.Generator | ||
Mir.Mir | ||
Mir.GenericOps | ||
Mir.ParseTranslate | ||
Mir.Pass | ||
Mir.Pass.AllocateEnum | ||
Mir.PP | ||
Mir.DefId | ||
Mir.FancyMuxTree | ||
Mir.Intrinsics | ||
Mir.TransTy | ||
Mir.Trans | ||
Mir.TransCustom |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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
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,76 @@ | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE ImplicitParams #-} | ||
----------------------------------------------------------------------- | ||
-- | | ||
-- Module : Mir.ParseTranslate | ||
-- Description : Produce MIR AST and translate to Crucible | ||
-- Copyright : (c) Galois, Inc 2018 | ||
-- License : BSD3 | ||
-- Stability : provisional | ||
-- | ||
-- Entry points for parsing and translating the MIR AST into Crucible. | ||
----------------------------------------------------------------------- | ||
|
||
|
||
module Mir.ParseTranslate (parseMIR, translateMIR) where | ||
|
||
import Control.Lens hiding((<.>)) | ||
import Control.Monad (when) | ||
|
||
import qualified Data.Aeson as J | ||
import qualified Data.ByteString.Lazy as B | ||
import qualified Data.Map as M | ||
|
||
import GHC.Stack | ||
|
||
import Prettyprinter (Pretty(..)) | ||
|
||
import qualified Lang.Crucible.FunctionHandle as C | ||
|
||
|
||
import Mir.Mir (Collection(..), namedTys) | ||
import Mir.JSON () | ||
import Mir.GenericOps (uninternTys) | ||
import Mir.Pass(rewriteCollection) | ||
import Mir.Generator(RustModule(..),CollectionState(..), collection) | ||
import Mir.Trans(transCollection) | ||
import qualified Mir.TransCustom as Mir (customOps) | ||
|
||
import Debug.Trace | ||
|
||
|
||
parseMIR :: (HasCallStack, ?debug::Int) => | ||
FilePath | ||
-> B.ByteString | ||
-> IO Collection | ||
parseMIR path f = do | ||
let c = (J.eitherDecode f) :: Either String Collection | ||
case c of | ||
Left msg -> fail $ "JSON Decoding of " ++ path ++ " failed: " ++ msg | ||
Right col -> do | ||
when (?debug > 5) $ do | ||
traceM "--------------------------------------------------------------" | ||
traceM $ "Loaded module: " ++ path | ||
traceM $ show (pretty col) | ||
traceM "--------------------------------------------------------------" | ||
return $ uninternMir col | ||
|
||
uninternMir :: Collection -> Collection | ||
uninternMir col = uninternTys unintern (col { _namedTys = mempty }) | ||
where | ||
-- NB: knot-tying is happening here. Some values in `tyMap` depend on | ||
-- other values. This should be okay: the original `rustc::ty::Ty`s are | ||
-- acyclic, so the entries in `tyMap` should be too. | ||
tyMap = fmap (uninternTys unintern) (col^.namedTys) | ||
unintern name = case M.lookup name tyMap of | ||
Nothing -> error $ "missing " ++ show name ++ " in type map" | ||
Just ty -> ty | ||
|
||
|
||
-- | Translate a MIR collection to Crucible | ||
translateMIR :: (HasCallStack, ?debug::Int, ?assertFalseOnError::Bool, ?printCrucible::Bool) | ||
=> CollectionState -> Collection -> C.HandleAllocator -> IO RustModule | ||
translateMIR lib col halloc = | ||
let ?customOps = Mir.customOps in | ||
let col0 = let ?mirLib = lib^.collection in rewriteCollection col | ||
in let ?libCS = lib in transCollection col0 halloc |
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
File renamed without changes.
Oops, something went wrong.