@@ -91,12 +91,16 @@ import Text.PrettyPrint.ANSI.Leijen hiding ((<$>), (<>))
91
91
import qualified Text.PrettyPrint.ANSI.Leijen as PP
92
92
import qualified Control.Monad.Trans.Maybe as MaybeT
93
93
94
+ -- parameterized-utils
94
95
import Data.Parameterized.Classes
95
-
96
96
import Data.Parameterized.NatRepr
97
97
import Data.Parameterized.Nonce
98
98
import Data.Parameterized.Some
99
99
100
+ -- cryptol
101
+ import qualified Cryptol.TypeCheck.Type as Cryptol
102
+
103
+ -- what4
100
104
import qualified What4.Concrete as W4
101
105
import qualified What4.Config as W4
102
106
import qualified What4.FunctionName as W4
@@ -105,6 +109,7 @@ import qualified What4.ProgramLoc as W4
105
109
import qualified What4.Interface as W4
106
110
import qualified What4.Expr.Builder as W4
107
111
112
+ -- crucible
108
113
import qualified Lang.Crucible.Backend as Crucible
109
114
import qualified Lang.Crucible.Backend.SAWCore as CrucibleSAW
110
115
import qualified Lang.Crucible.CFG.Core as Crucible
@@ -117,6 +122,7 @@ import qualified Lang.Crucible.Simulator.GlobalState as Crucible
117
122
import qualified Lang.Crucible.Simulator.PathSatisfiability as Crucible
118
123
import qualified Lang.Crucible.Simulator.SimError as Crucible
119
124
125
+ -- crucible-llvm
120
126
import qualified Lang.Crucible.LLVM.ArraySizeProfile as Crucible
121
127
import qualified Lang.Crucible.LLVM.DataLayout as Crucible
122
128
import Lang.Crucible.LLVM.Extension (LLVM )
@@ -125,16 +131,18 @@ import qualified Lang.Crucible.LLVM.Translation as Crucible
125
131
126
132
import qualified SAWScript.Crucible.LLVM.CrucibleLLVM as Crucible
127
133
134
+ -- parameterized-utils
128
135
import qualified Data.Parameterized.TraversableFC as Ctx
129
136
import qualified Data.Parameterized.Context as Ctx
130
137
138
+ -- saw-core
131
139
import Verifier.SAW.FiniteValue (ppFirstOrderValue )
132
- import Verifier.SAW.Prelude
133
140
import Verifier.SAW.SharedTerm
134
141
import Verifier.SAW.TypedAST
135
142
import Verifier.SAW.Recognizer
136
143
import Verifier.SAW.TypedTerm
137
144
145
+ -- saw-script
138
146
import SAWScript.Proof
139
147
import SAWScript.Prover.SolverStats
140
148
import SAWScript.Prover.Versions
@@ -1287,37 +1295,28 @@ crucible_execute_func bic opts args =
1287
1295
getLLVMCrucibleContext :: CrucibleSetup (LLVM arch ) (LLVMCrucibleContext arch )
1288
1296
getLLVMCrucibleContext = view Setup. csCrucibleContext <$> get
1289
1297
1290
- -- | Returns logical type of actual type if it is an array or primitive
1298
+ -- | Returns Cryptol type of actual type if it is an array or primitive
1291
1299
-- type, or an appropriately-sized bit vector for pointer types.
1292
- logicTypeOfActual :: Crucible. DataLayout -> SharedContext -> Crucible. MemType
1293
- -> IO (Maybe Term )
1294
- logicTypeOfActual _ sc (Crucible. IntType w) = Just <$> logicTypeForInt sc w
1295
- logicTypeOfActual _ sc Crucible. FloatType = Just <$> scApplyPrelude_Float sc
1296
- logicTypeOfActual _ sc Crucible. DoubleType = Just <$> scApplyPrelude_Double sc
1297
- logicTypeOfActual dl sc (Crucible. ArrayType n ty) = do
1298
- melTyp <- logicTypeOfActual dl sc ty
1299
- case melTyp of
1300
- Just elTyp -> do
1301
- lTm <- scNat sc (fromIntegral n)
1302
- Just <$> scVecType sc lTm elTyp
1303
- Nothing -> return Nothing
1304
- logicTypeOfActual dl sc (Crucible. PtrType _) = do
1305
- bType <- scBoolType sc
1306
- lTm <- scNat sc (fromIntegral (Crucible. ptrBitwidth dl))
1307
- Just <$> scVecType sc lTm bType
1308
- logicTypeOfActual dl sc (Crucible. StructType si) = do
1309
- let memtypes = V. toList (Crucible. siFieldTypes si)
1310
- melTyps <- traverse (logicTypeOfActual dl sc) memtypes
1311
- case sequence melTyps of
1312
- Just elTyps -> Just <$> scTupleType sc elTyps
1313
- Nothing -> return Nothing
1314
- logicTypeOfActual _ _ t = fail (show t) -- return Nothing
1315
-
1316
- logicTypeForInt :: SharedContext -> Natural -> IO Term
1317
- logicTypeForInt sc w =
1318
- do bType <- scBoolType sc
1319
- lTm <- scNat sc (fromIntegral w)
1320
- scVecType sc lTm bType
1300
+ cryptolTypeOfActual :: Crucible. DataLayout -> Crucible. MemType -> Maybe Cryptol. Type
1301
+ cryptolTypeOfActual dl mt =
1302
+ case mt of
1303
+ Crucible. IntType w ->
1304
+ return $ Cryptol. tWord (Cryptol. tNum w)
1305
+ Crucible. FloatType ->
1306
+ Nothing -- FIXME: update when Cryptol gets float types
1307
+ Crucible. DoubleType ->
1308
+ Nothing -- FIXME: update when Cryptol gets float types
1309
+ Crucible. ArrayType n ty ->
1310
+ do cty <- cryptolTypeOfActual dl ty
1311
+ return $ Cryptol. tSeq (Cryptol. tNum n) cty
1312
+ Crucible. PtrType _ ->
1313
+ return $ Cryptol. tWord (Cryptol. tNum (Crucible. ptrBitwidth dl))
1314
+ Crucible. StructType si ->
1315
+ do let memtypes = V. toList (Crucible. siFieldTypes si)
1316
+ ctys <- traverse (cryptolTypeOfActual dl) memtypes
1317
+ return $ Cryptol. tTuple ctys
1318
+ _ ->
1319
+ Nothing
1321
1320
1322
1321
-- | Generate a fresh variable term. The name will be used when
1323
1322
-- pretty-printing the variable in debug output.
@@ -1327,16 +1326,16 @@ crucible_fresh_var ::
1327
1326
String {- ^ variable name -} ->
1328
1327
L. Type {- ^ variable type -} ->
1329
1328
LLVMCrucibleSetupM TypedTerm {- ^ fresh typed term -}
1330
- crucible_fresh_var bic _opts name lty = LLVMCrucibleSetupM $ do
1331
- cctx <- getLLVMCrucibleContext
1332
- let ? lc = cctx ^. ccTypeCtx
1333
- lty' <- memTypeForLLVMType bic lty
1334
- let sc = biSharedContext bic
1335
- let dl = Crucible. llvmDataLayout (cctx ^. ccTypeCtx)
1336
- mty <- liftIO $ logicTypeOfActual dl sc lty'
1337
- case mty of
1338
- Nothing -> fail $ " Unsupported type in crucible_fresh_var: " ++ show (L. ppType lty)
1339
- Just ty -> Setup. freshVariable sc name ty
1329
+ crucible_fresh_var bic _opts name lty =
1330
+ LLVMCrucibleSetupM $
1331
+ do cctx <- getLLVMCrucibleContext
1332
+ let ? lc = cctx ^. ccTypeCtx
1333
+ lty' <- memTypeForLLVMType bic lty
1334
+ let sc = biSharedContext bic
1335
+ let dl = Crucible. llvmDataLayout (cctx ^. ccTypeCtx)
1336
+ case cryptolTypeOfActual dl lty' of
1337
+ Nothing -> fail $ " Unsupported type in crucible_fresh_var: " ++ show (L. ppType lty)
1338
+ Just cty -> Setup. freshVariable sc name cty
1340
1339
1341
1340
-- | Use the given LLVM type to compute a setup value that
1342
1341
-- covers expands all of the struct, array, and pointer
@@ -1370,8 +1369,8 @@ constructExpandedSetupValue ::
1370
1369
constructExpandedSetupValue cc sc loc t = do
1371
1370
case t of
1372
1371
Crucible. IntType w ->
1373
- do ty <- liftIO (logicTypeForInt sc w)
1374
- fv <- Setup. freshVariable sc " " ty
1372
+ do let cty = Cryptol. tWord ( Cryptol. tNum w)
1373
+ fv <- Setup. freshVariable sc " " cty
1375
1374
pure $ mkAllLLVM (SetupTerm fv)
1376
1375
1377
1376
Crucible. StructType si -> do
@@ -1515,8 +1514,7 @@ crucible_alloc_global ::
1515
1514
String ->
1516
1515
LLVMCrucibleSetupM ()
1517
1516
crucible_alloc_global _bic _opts name = LLVMCrucibleSetupM $
1518
- do cc <- getLLVMCrucibleContext
1519
- loc <- getW4Position " crucible_alloc_global"
1517
+ do loc <- getW4Position " crucible_alloc_global"
1520
1518
Setup. addAllocGlobal . LLVMAllocGlobal loc $ L. Symbol name
1521
1519
1522
1520
crucible_fresh_pointer ::
0 commit comments