|
1 | 1 | {-# LANGUAGE GADTs #-}
|
| 2 | +{-# LANGUAGE RankNTypes #-} |
2 | 3 | {-# LANGUAGE StandaloneDeriving #-}
|
3 | 4 | module Data.Macaw.AArch32.Symbolic.Functions (
|
4 | 5 | SymFuns
|
@@ -82,33 +83,33 @@ funcSemantics :: (CB.IsSymInterface sym, MS.ToCrucibleType mt ~ t)
|
82 | 83 | -> IO (CS.RegValue sym t, S sym rtp bs r ctx)
|
83 | 84 | funcSemantics sfns fn st0 =
|
84 | 85 | case fn of
|
85 |
| - MAA.SDiv _rep lhs rhs -> withSym st0 $ \sym -> do |
86 |
| - lhs' <- toValBV sym lhs |
87 |
| - rhs' <- toValBV sym rhs |
| 86 | + MAA.SDiv _rep lhs rhs -> withBackend st0 $ \sym bak -> do |
| 87 | + lhs' <- toValBV bak lhs |
| 88 | + rhs' <- toValBV bak rhs |
88 | 89 | -- NOTE: We are applying division directly here without checking the divisor for zero.
|
89 | 90 | --
|
90 | 91 | -- The ARM semantics explicitly check this and have different behaviors
|
91 | 92 | -- depending on what CPU flags are set; this operation is never called
|
92 | 93 | -- with a divisor of zero. We could add an assertion to that effect here,
|
93 | 94 | -- but it might be difficult to prove.
|
94 | 95 | LL.llvmPointer_bv sym =<< WI.bvSdiv sym lhs' rhs'
|
95 |
| - MAA.UDiv _rep lhs rhs -> withSym st0 $ \sym -> do |
96 |
| - lhs' <- toValBV sym lhs |
97 |
| - rhs' <- toValBV sym rhs |
| 96 | + MAA.UDiv _rep lhs rhs -> withBackend st0 $ \sym bak -> do |
| 97 | + lhs' <- toValBV bak lhs |
| 98 | + rhs' <- toValBV bak rhs |
98 | 99 | -- NOTE: See the note in SDiv
|
99 | 100 | LL.llvmPointer_bv sym =<< WI.bvUdiv sym lhs' rhs'
|
100 |
| - MAA.URem _rep lhs rhs -> withSym st0 $ \sym -> do |
101 |
| - lhs' <- toValBV sym lhs |
102 |
| - rhs' <- toValBV sym rhs |
| 101 | + MAA.URem _rep lhs rhs -> withBackend st0 $ \sym bak -> do |
| 102 | + lhs' <- toValBV bak lhs |
| 103 | + rhs' <- toValBV bak rhs |
103 | 104 | -- NOTE: See the note in SDiv
|
104 | 105 | LL.llvmPointer_bv sym =<< WI.bvUrem sym lhs' rhs'
|
105 |
| - MAA.SRem _rep lhs rhs -> withSym st0 $ \sym -> do |
106 |
| - lhs' <- toValBV sym lhs |
107 |
| - rhs' <- toValBV sym rhs |
| 106 | + MAA.SRem _rep lhs rhs -> withBackend st0 $ \sym bak -> do |
| 107 | + lhs' <- toValBV bak lhs |
| 108 | + rhs' <- toValBV bak rhs |
108 | 109 | -- NOTE: See the note in SDiv
|
109 | 110 | LL.llvmPointer_bv sym =<< WI.bvSrem sym lhs' rhs'
|
110 |
| - MAA.UnsignedRSqrtEstimate _rep v -> withSym st0 $ \sym -> do |
111 |
| - v' <- toValBV sym v |
| 111 | + MAA.UnsignedRSqrtEstimate _rep v -> withBackend st0 $ \sym bak -> do |
| 112 | + v' <- toValBV bak v |
112 | 113 | let args = Ctx.empty Ctx.:> v'
|
113 | 114 | res <- lookupApplySymFun sym sfns "unsignedRSqrtEstimate" CT.knownRepr args CT.knownRepr
|
114 | 115 | LL.llvmPointer_bv sym res
|
@@ -139,22 +140,21 @@ funcSemantics sfns fn st0 =
|
139 | 140 | MAA.ARMSyscall {} ->
|
140 | 141 | AP.panic AP.AArch32 "funcSemantics" ["The ARM syscall primitive should be eliminated and replaced by a handle lookup"]
|
141 | 142 |
|
142 |
| -withSym :: (CB.IsSymInterface sym) |
143 |
| - => S sym rtp bs r ctx |
144 |
| - -> (sym -> IO a) |
145 |
| - -> IO (a, S sym rtp bs r ctx) |
146 |
| -withSym s action = do |
147 |
| - let sym = s ^. CSET.stateSymInterface |
148 |
| - val <- action sym |
149 |
| - return (val, s) |
150 |
| - |
| 143 | +withBackend :: |
| 144 | + S sym rtp bs r ctx -> |
| 145 | + (forall bak. CB.IsSymBackend sym bak => sym -> bak -> IO a) -> |
| 146 | + IO (a, S sym rtp bs r ctx) |
| 147 | +withBackend s action = do |
| 148 | + CSET.withBackend (s^.CSET.stateContext) $ \bak -> |
| 149 | + do val <- action (CB.backendGetSym bak) bak |
| 150 | + return (val, s) |
151 | 151 |
|
152 | 152 | -- | Assert that the wrapped value is a bitvector
|
153 |
| -toValBV :: (CB.IsSymInterface sym) |
154 |
| - => sym |
| 153 | +toValBV :: (CB.IsSymBackend sym bak) |
| 154 | + => bak |
155 | 155 | -> AA.AtomWrapper (CS.RegEntry sym) (MT.BVType w)
|
156 | 156 | -> IO (CS.RegValue sym (CT.BVType w))
|
157 |
| -toValBV sym (AA.AtomWrapper x) = LL.projectLLVM_bv sym (CS.regValue x) |
| 157 | +toValBV bak (AA.AtomWrapper x) = LL.projectLLVM_bv bak (CS.regValue x) |
158 | 158 |
|
159 | 159 | -- | Apply an uninterpreted function to the provided arguments
|
160 | 160 | --
|
|
0 commit comments