Skip to content

Commit

Permalink
crucible-llvm: Don't pass around the symbolic backend explicitly
Browse files Browse the repository at this point in the history
`Lang.Crucible.Simulator.OverrideSim.{getSymInterface,ovrWithBackend}`
can replace the explicit passing of `bak`. This should simplify some
type signatures.
  • Loading branch information
langston-barrett committed Mar 21, 2024
1 parent af9c127 commit dd52913
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion crucible-llvm/src/Lang/Crucible/LLVM/Intrinsics/LLVM.hs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ llvmBSwapOverride widthRepr =
-- From the LLVM docs:
-- declare i16 @llvm.bswap.i16(i16 <id>)
[llvmOvr| #width8 $nm( #width8 ) |]
(\_ bak args -> Ctx.uncurryAssignment (Libc.callBSwap bak widthRepr) args)
(\_ _bak args -> Ctx.uncurryAssignment (Libc.callBSwap widthRepr) args)
}}}

llvmAbsOverride ::
Expand Down
23 changes: 11 additions & 12 deletions crucible-llvm/src/Lang/Crucible/LLVM/Intrinsics/Libc.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,7 @@ llvmHtonlOverride ::
(BVType 32)
llvmHtonlOverride =
[llvmOvr| i32 @htonl( i32 ) |]
(\_ bak args -> Ctx.uncurryAssignment (callBSwapIfLittleEndian bak (knownNat @4)) args)
(\_ bak args -> Ctx.uncurryAssignment (callBSwapIfLittleEndian (knownNat @4)) args)

llvmHtonsOverride ::
(IsSymInterface sym, ?lc :: TypeContext) =>
Expand All @@ -1538,7 +1538,7 @@ llvmHtonsOverride ::
(BVType 16)
llvmHtonsOverride =
[llvmOvr| i16 @htons( i16 ) |]
(\_ bak args -> Ctx.uncurryAssignment (callBSwapIfLittleEndian bak (knownNat @2)) args)
(\_ bak args -> Ctx.uncurryAssignment (callBSwapIfLittleEndian (knownNat @2)) args)

llvmNtohlOverride ::
(IsSymInterface sym, ?lc :: TypeContext) =>
Expand All @@ -1547,7 +1547,7 @@ llvmNtohlOverride ::
(BVType 32)
llvmNtohlOverride =
[llvmOvr| i32 @ntohl( i32 ) |]
(\_ bak args -> Ctx.uncurryAssignment (callBSwapIfLittleEndian bak (knownNat @4)) args)
(\_ bak args -> Ctx.uncurryAssignment (callBSwapIfLittleEndian (knownNat @4)) args)

llvmNtohsOverride ::
(IsSymInterface sym, ?lc :: TypeContext) =>
Expand All @@ -1556,7 +1556,7 @@ llvmNtohsOverride ::
(BVType 16)
llvmNtohsOverride =
[llvmOvr| i16 @ntohs( i16 ) |]
(\_ bak args -> Ctx.uncurryAssignment (callBSwapIfLittleEndian bak (knownNat @2)) args)
(\_ bak args -> Ctx.uncurryAssignment (callBSwapIfLittleEndian (knownNat @2)) args)

llvmAbsOverride ::
(IsSymInterface sym, HasLLVMAnn sym) =>
Expand Down Expand Up @@ -1606,13 +1606,13 @@ llvmLLAbsOverride =
Ctx.uncurryAssignment (callLibcAbs bak callStack (knownNat @64)) args)

callBSwap ::
(1 <= width, IsSymBackend sym bak) =>
bak ->
(1 <= width, IsSymInterface sym) =>
NatRepr width ->
RegEntry sym (BVType (width * 8)) ->
OverrideSim p sym ext r args ret (RegValue sym (BVType (width * 8)))
callBSwap bak widthRepr (regValue -> vec) =
liftIO $ bvSwap (backendGetSym bak) widthRepr vec
callBSwap widthRepr (regValue -> vec) = do
sym <- getSymInterface
liftIO $ bvSwap sym widthRepr vec

-- | This determines under what circumstances @callAbs@ should check if its
-- argument is equal to the smallest signed integer of a particular size
Expand Down Expand Up @@ -1699,15 +1699,14 @@ callLLVMAbs bak callStack widthRepr src (regValue -> isIntMinPoison) = do
-- Otherwise, return the input unchanged. This is the workhorse for the
-- @hton{s,l}@ and @ntoh{s,l}@ overrides.
callBSwapIfLittleEndian ::
(1 <= width, IsSymBackend sym bak, ?lc :: TypeContext) =>
bak ->
(1 <= width, IsSymInterface sym, ?lc :: TypeContext) =>
NatRepr width ->
RegEntry sym (BVType (width * 8)) ->
OverrideSim p sym ext r args ret (RegValue sym (BVType (width * 8)))
callBSwapIfLittleEndian bak widthRepr vec =
callBSwapIfLittleEndian widthRepr vec =
case (llvmDataLayout ?lc)^.intLayout of
BigEndian -> pure (regValue vec)
LittleEndian -> callBSwap bak widthRepr vec
LittleEndian -> callBSwap widthRepr vec

----------------------------------------------------------------------------
-- atexit stuff
Expand Down

0 comments on commit dd52913

Please sign in to comment.