Skip to content

Commit

Permalink
Move Pointer' type family to SAWScript.Crucible.Common.Setup.Value
Browse files Browse the repository at this point in the history
This is purely a refactor. This will become useful in a subsequent commit in
order to avoid import cycles.
  • Loading branch information
RyanGlScott committed Sep 1, 2023
1 parent 9218ec1 commit 5cbea4e
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 13 deletions.
10 changes: 4 additions & 6 deletions src/SAWScript/Crucible/Common/Override.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Stability : provisional

module SAWScript.Crucible.Common.Override
( Pointer
, Pointer'
, MS.Pointer'
, OverrideState
, OverrideState'(..)
, osAsserts
Expand Down Expand Up @@ -68,7 +68,6 @@ import qualified Control.Monad.Fail as Fail
import Control.Monad.Trans.Except
import Control.Monad.Trans.Class
import Control.Monad.IO.Class
import Data.Kind (Type)
import qualified Data.Map as Map
import Data.Map (Map)
import Data.Set (Set)
Expand Down Expand Up @@ -96,6 +95,7 @@ import qualified What4.ProgramLoc as W4
import SAWScript.Exceptions
import SAWScript.Crucible.Common (Sym)
import SAWScript.Crucible.Common.MethodSpec as MS
import SAWScript.Crucible.Common.Setup.Value as MS

-- TODO, not sure this is the best place for this definition
type MetadataMap =
Expand All @@ -106,13 +106,11 @@ type MetadataMap =

type LabeledPred sym = W4.LabeledPred (W4.Pred sym) Crucible.SimError

type family Pointer' ext sym :: Type

type Pointer ext = Pointer' ext Sym
type Pointer ext = MS.Pointer' ext Sym

data OverrideState' sym ext = OverrideState
{ -- | Substitution for memory allocations
_setupValueSub :: Map AllocIndex (Pointer' ext sym)
_setupValueSub :: Map AllocIndex (MS.Pointer' ext sym)

-- | Substitution for SAW Core external constants
, _termSub :: Map VarIndex Term
Expand Down
7 changes: 7 additions & 0 deletions src/SAWScript/Crucible/Common/Setup/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ module SAWScript.Crucible.Common.Setup.Value

, MethodId
, Codebase

, Pointer'
) where

import Data.Constraint (Constraint)
Expand Down Expand Up @@ -200,3 +202,8 @@ type family MethodId ext :: Type
--
-- Examples: An 'LLVMModule', a Java 'Codebase'
type family Codebase ext :: Type

--------------------------------------------------------------------------------
-- *** Pointers

type family Pointer' ext sym :: Type
2 changes: 1 addition & 1 deletion src/SAWScript/Crucible/JVM/Override.hs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ import qualified SAWScript.Crucible.Common.Override as Ov (getSymInterface)
import qualified SAWScript.Crucible.Common.MethodSpec as MS
import SAWScript.Crucible.JVM.MethodSpecIR
import SAWScript.Crucible.JVM.ResolveSetupValue
import SAWScript.Crucible.JVM.Setup.Value ()
import SAWScript.Options
import SAWScript.Panic
import SAWScript.Utils (handleException)
Expand All @@ -121,7 +122,6 @@ type SetupValue = MS.SetupValue CJ.JVM
type CrucibleMethodSpecIR = MS.CrucibleMethodSpecIR CJ.JVM
type StateSpec = MS.StateSpec CJ.JVM
type SetupCondition = MS.SetupCondition CJ.JVM
type instance Pointer' CJ.JVM Sym = JVMRefVal

-- TODO: Improve?
ppJVMVal :: JVMVal -> PP.Doc ann
Expand Down
3 changes: 1 addition & 2 deletions src/SAWScript/Crucible/JVM/ResolveSetupValue.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import SAWScript.Crucible.Common.MethodSpec (AllocIndex(..))

import SAWScript.Panic
import SAWScript.Crucible.JVM.MethodSpecIR
import SAWScript.Crucible.JVM.Setup.Value (JVMRefVal)
import qualified SAWScript.Crucible.Common.MethodSpec as MS
import SAWScript.Crucible.Common.ResolveSetupValue (resolveBoolTerm)

Expand All @@ -82,8 +83,6 @@ instance Show JVMVal where
show (IVal _) = "IVal"
show (LVal _) = "LVal"

type JVMRefVal = Crucible.RegValue Sym CJ.JVMRefType

type SetupValue = MS.SetupValue CJ.JVM

data JVMTypeOfError
Expand Down
13 changes: 12 additions & 1 deletion src/SAWScript/Crucible/JVM/Setup/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module, plus additional functionality) instead.
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ViewPatterns #-}

module SAWScript.Crucible.JVM.Setup.Value
Expand All @@ -47,6 +48,8 @@ module SAWScript.Crucible.JVM.Setup.Value
, jccJVMContext
, jccBackend
, jccHandleAllocator

, JVMRefVal
) where

import Control.Lens
Expand All @@ -55,6 +58,7 @@ import qualified Prettyprinter as PPL
import qualified Lang.Crucible.FunctionHandle as Crucible (HandleAllocator)

-- crucible-jvm
import qualified Lang.Crucible.Simulator as CS
import qualified Lang.Crucible.JVM as CJ
import qualified Lang.JVM.Codebase as CB

Expand All @@ -65,7 +69,7 @@ import qualified Language.JVM.Parser as J
import Verifier.SAW.TypedTerm (TypedTerm)

import SAWScript.Crucible.Common
import qualified SAWScript.Crucible.Common.MethodSpec as MS
import qualified SAWScript.Crucible.Common.Setup.Value as MS

--------------------------------------------------------------------------------
-- ** Language features
Expand Down Expand Up @@ -148,3 +152,10 @@ data JVMCrucibleContext =
makeLenses ''JVMCrucibleContext

type instance MS.CrucibleContext CJ.JVM = JVMCrucibleContext

--------------------------------------------------------------------------------
-- *** Pointers

type instance MS.Pointer' CJ.JVM Sym = JVMRefVal

type JVMRefVal = CS.RegValue Sym CJ.JVMRefType
3 changes: 1 addition & 2 deletions src/SAWScript/Crucible/LLVM/Override.hs
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,13 @@ import SAWScript.Crucible.Common.Override hiding (getSymInterface)
import qualified SAWScript.Crucible.Common.Override as Ov (getSymInterface)
import SAWScript.Crucible.LLVM.MethodSpecIR
import SAWScript.Crucible.LLVM.ResolveSetupValue
import SAWScript.Crucible.LLVM.Setup.Value ()
import SAWScript.Options
import SAWScript.Panic
import SAWScript.Utils (bullets, handleException)

type LabeledPred sym = W4.LabeledPred (W4.Pred sym) Crucible.SimError

type instance Pointer' (LLVM arch) Sym = LLVMPtr (Crucible.ArchWidth arch)

-- | An override packaged together with its preconditions, labeled with some
-- human-readable info about each condition.
data OverrideWithPreconditions arch =
Expand Down
2 changes: 1 addition & 1 deletion src/SAWScript/Crucible/LLVM/ResolveSetupValue.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ import SAWScript.Crucible.Common (Sym, sawCoreState, HasSymInterface(.
import SAWScript.Crucible.Common.MethodSpec (AllocIndex(..), SetupValue(..), ppTypedTermType)

import SAWScript.Crucible.LLVM.MethodSpecIR
import SAWScript.Crucible.LLVM.Setup.Value (LLVMPtr)
import qualified SAWScript.Proof as SP


type LLVMVal = Crucible.LLVMVal Sym
type LLVMPtr wptr = Crucible.LLVMPtr Sym wptr



Expand Down
10 changes: 10 additions & 0 deletions src/SAWScript/Crucible/LLVM/Setup/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module, plus additional functionality) instead.
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE ViewPatterns #-}

module SAWScript.Crucible.LLVM.Setup.Value
Expand Down Expand Up @@ -75,6 +76,8 @@ module SAWScript.Crucible.LLVM.Setup.Value
, emptyResolvedState
, rsAllocs
, rsGlobals
-- * @LLVMPtr@
, LLVMPtr
) where

import Control.Lens
Expand Down Expand Up @@ -338,3 +341,10 @@ emptyResolvedState :: LLVMResolvedState
emptyResolvedState = ResolvedState Map.empty Map.empty

makeLenses ''LLVMResolvedState

--------------------------------------------------------------------------------
-- *** Pointers

type instance Setup.Pointer' (LLVM arch) Sym = LLVMPtr (CL.ArchWidth arch)

type LLVMPtr wptr = CL.LLVMPtr Sym wptr

0 comments on commit 5cbea4e

Please sign in to comment.