Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize lazy memory model using HasMacawLazySimulatorState #358

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions symbolic/src/Data/Macaw/Symbolic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ module Data.Macaw.Symbolic
, MO.MacawSimulatorState(..)
, MO.MacawLazySimulatorState(..)
, MO.emptyMacawLazySimulatorState
, MO.HasMacawLazySimulatorState(..)
, MO.populatedMemChunks
, MkGlobalPointerValidityAssertion
, MemModelConfig(..)
Expand Down
25 changes: 21 additions & 4 deletions symbolic/src/Data/Macaw/Symbolic/MemOps.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
{-# LANGUAGE ConstraintKinds #-}
{-# Language DataKinds #-}
{-# Language FlexibleContexts #-}
{-# Language FlexibleInstances #-}
{-# Language FunctionalDependencies #-}
{-# Language TypeOperators #-}
{-# Language TypeFamilies #-}
{-# Language ImplicitParams #-}
Expand Down Expand Up @@ -37,6 +39,7 @@ module Data.Macaw.Symbolic.MemOps
, MacawSimulatorState(..)
, MacawLazySimulatorState(..)
, emptyMacawLazySimulatorState
, HasMacawLazySimulatorState(..)
, populatedMemChunks
, LookupFunctionHandle(..)
, LookupSyscallHandle(..)
Expand Down Expand Up @@ -379,11 +382,25 @@ emptyMacawLazySimulatorState = MacawLazySimulatorState
{ _populatedMemChunks = IS.empty
}

-- | A class for Crucible personality types @p@ which contain a
-- 'MacawLazySimulatorState'. The lazy memory model in
-- "Data.Macaw.Symbolic.Memory" is polymorphic over 'HasMacawLazySimulatorState'
-- instances so that downstream @macaw-symbolic@ users can supply their own
-- personality types that extend 'MacawLazySimulatorState' further.
-- See @Note [Lazy memory model]@ in "Data.Macaw.Symbolic.Memory.Lazy".
class HasMacawLazySimulatorState p sym w | p -> sym w where
macawLazySimulatorState :: Lens' p (MacawLazySimulatorState sym w)
instance HasMacawLazySimulatorState (MacawLazySimulatorState sym w) sym w where
macawLazySimulatorState = id

-- | A `Lens'` for '_populatedMemChunks'.
populatedMemChunks :: Lens' (MacawLazySimulatorState sym w)
(IS.IntervalSet (IMI.Interval (M.MemWord w)))
populatedMemChunks = lens _populatedMemChunks
(\s v -> s { _populatedMemChunks = v })
populatedMemChunks ::
HasMacawLazySimulatorState p sym w
=> Lens' p (IS.IntervalSet (IMI.Interval (M.MemWord w)))
populatedMemChunks =
macawLazySimulatorState
. lens _populatedMemChunks
(\s v -> s { _populatedMemChunks = v })

type Regs sym arch = Ctx.Assignment (C.RegValue' sym)
(MacawCrucibleRegTypes arch)
Expand Down
9 changes: 5 additions & 4 deletions symbolic/src/Data/Macaw/Symbolic/Memory/Lazy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ import qualified Data.Macaw.Symbolic.Memory.Common as MSMC
-- Note some key differences between this function and the @memModelConfig@
-- function in "Data.Macaw.Symbolic.Memory":
--
-- * This function requires the personality type to be
-- 'MS.MacawLazySimulatorState', as it must track which sections of global
-- * This function requires the personality type to be an instance of
-- 'MS.HasMacawLazySimulatorState', as it must track which sections of global
-- memory have already been populated in the simulator state.
--
-- * This function requires an 'CBO.OnlineBackend' to make use of an online
Expand All @@ -112,6 +112,7 @@ memModelConfig ::
, sym ~ WE.ExprBuilder scope st fs
, bak ~ CBO.OnlineBackend solver scope st fs
, WPO.OnlineSolver solver
, MS.HasMacawLazySimulatorState p sym w
, MC.MemWidth w
, 1 <= w
, 16 <= w
Expand All @@ -120,7 +121,7 @@ memModelConfig ::
)
=> bak
-> MemPtrTable sym w
-> MS.MemModelConfig (MS.MacawLazySimulatorState sym w) sym arch CL.Mem
-> MS.MemModelConfig p sym arch CL.Mem
memModelConfig bak mpt =
MS.MemModelConfig
{ MS.globalMemMap = mapRegionPointers mpt
Expand Down Expand Up @@ -660,7 +661,7 @@ lazilyPopulateGlobalMemArr ::
forall sym bak w t st fs p ext.
( CB.IsSymBackend sym bak
, sym ~ WEB.ExprBuilder t st fs
, p ~ MS.MacawLazySimulatorState sym w
, MS.HasMacawLazySimulatorState p sym w
, MC.MemWidth w
) =>
bak ->
Expand Down
Loading