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

support alignment ops when processing statements in RegisterUse #406

Merged
merged 1 commit into from
Jul 25, 2024
Merged
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
13 changes: 13 additions & 0 deletions base/src/Data/Macaw/Analysis/RegisterUse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import Control.Monad (unless, when, zipWithM_)
import Control.Monad.Except (MonadError(..), Except)
import Control.Monad.Reader (MonadReader(..), ReaderT(..), asks)
import Control.Monad.State.Strict (MonadState(..), State, StateT, execStateT, evalState, gets, modify)
import qualified Data.Bits as Bits
import qualified Data.ByteString.Char8 as BSC
import qualified Data.ByteString as BS
import Data.Foldable
Expand Down Expand Up @@ -664,20 +665,32 @@ addMemAccessInfo :: StmtIndex -> MemAccessInfo arch ids -> StartInfer arch ids (
addMemAccessInfo idx i = seq idx $ seq i $ do
modify $ \s -> s { sisMemAccessStack = (idx,i) : sisMemAccessStack s }

-- | @processApp aid app@ computes the effect of a program assignment @aid <- app@. When `app` is
-- a computation over a stack offset expression (a `FrameExpr`), we attempt to simplify it, as we
-- require a concrete stack offset when computing `postCallConstraints`.
processApp :: (OrdF (ArchReg arch), MemWidth (ArchAddrWidth arch))
=> AssignId ids tp
-> App (Value arch ids) tp
-> StartInfer arch ids ()
processApp aid app = do
ctx <- ask
am <- gets sisAssignMap
-- This inspects the `app` term to detect cases where the abstract expression can be simplified
-- down to a `FrameExpr` expression. In such cases, the simplified expression is registered as
-- the value for this assignment. Otherwise, the value for the assignment remains abstract.
-- This may not be exhaustive, so if you encounter the `CallStackHeightError` in
-- `postCallConstraints`, you may need to extend the patterns recognized here.
case fmapFC (valueToStartExpr ctx am) app of
BVAdd _ (FrameExpr o) (IVCValue (BVCValue _ c)) ->
setAssignVal aid (FrameExpr (o+fromInteger c))
BVAdd _ (IVCValue (BVCValue _ c)) (FrameExpr o) ->
setAssignVal aid (FrameExpr (o+fromInteger c))
BVSub _ (FrameExpr o) (IVCValue (BVCValue _ c)) ->
setAssignVal aid (FrameExpr (o-fromInteger c))
BVAnd _ (FrameExpr o) (IVCValue (BVCValue _ c)) ->
Ptival marked this conversation as resolved.
Show resolved Hide resolved
setAssignVal aid (FrameExpr (o Bits..&. fromInteger c))
BVAnd _ (IVCValue (BVCValue _ c)) (FrameExpr o) ->
setAssignVal aid (FrameExpr (o Bits..&. fromInteger c))
appExpr -> do
c <- gets sisAppCache
-- Check to see if we have seen an app equivalent to
Expand Down
Loading