Copyright | (c) Galois Inc 2017-2019 |
---|---|
Maintainer | jhendrix@galois.com |
Safe Haskell | None |
Language | Haskell2010 |
Data.Macaw.CFG.Rewriter
Contents
Description
This provides a rewriter for simplifying blocks by rewriting value computations and performing other rearrangement and adjustments.
The main entry point is calling runRewriter
with a constructed
RewriteContext
to control the rewrite operation and a Rewriter monad
computation that rewrites the statements for a particular block.
Note that while the common case is a single block, the Branch TermStmt that can be part of a block may refer to other Blocks (by ID) and therefore the rewriting operation may need to actually modify multiple blocks or even add new blocks for new Branch TermStmt targets.
Synopsis
- data RewriteContext arch s src tgt
- mkRewriteContext :: RegisterInfo (ArchReg arch) => NonceGenerator (ST s) tgt -> (forall (tp :: Type). ArchFn arch (Value arch src) tp -> Rewriter arch s src tgt (Value arch tgt tp)) -> (ArchStmt arch (Value arch src) -> Rewriter arch s src tgt ()) -> (TermStmt arch tgt -> Rewriter arch s src tgt (TermStmt arch tgt)) -> Map SectionIndex (ArchSegmentOff arch) -> ST s (RewriteContext arch s src tgt)
- data Rewriter arch s src tgt a
- runRewriter :: RewriteContext arch s src tgt -> Rewriter arch s src tgt (TermStmt arch tgt) -> ST s (RewriteContext arch s src tgt, [Stmt arch tgt], TermStmt arch tgt)
- rewriteStmt :: Stmt arch src -> Rewriter arch s src tgt ()
- rewriteValue :: forall arch src (tp :: Type) s tgt. Value arch src tp -> Rewriter arch s src tgt (Value arch tgt tp)
- rewriteApp :: forall arch tgt (tp :: Type) s src. App (Value arch tgt) tp -> Rewriter arch s src tgt (Value arch tgt tp)
- evalRewrittenArchFn :: forall arch tgt (tp :: Type) s src. HasRepr (ArchFn arch (Value arch tgt)) TypeRepr => ArchFn arch (Value arch tgt) tp -> Rewriter arch s src tgt (Value arch tgt tp)
- appendRewrittenArchStmt :: ArchStmt arch (Value arch tgt) -> Rewriter arch s src tgt ()
Basic types
data RewriteContext arch s src tgt Source #
Information needed for rewriting.
Arguments
:: RegisterInfo (ArchReg arch) | |
=> NonceGenerator (ST s) tgt | |
-> (forall (tp :: Type). ArchFn arch (Value arch src) tp -> Rewriter arch s src tgt (Value arch tgt tp)) | |
-> (ArchStmt arch (Value arch src) -> Rewriter arch s src tgt ()) | |
-> (TermStmt arch tgt -> Rewriter arch s src tgt (TermStmt arch tgt)) | Optional internal terminal statement rewriter; e.g. use is for block jump targets discovered outside normal pattern-matching in Discovery.hs. |
-> Map SectionIndex (ArchSegmentOff arch) | Map from loaded section indices to their address. |
-> ST s (RewriteContext arch s src tgt) |
data Rewriter arch s src tgt a Source #
Monad for constant propagation within a block.
Instances
Applicative (Rewriter arch s src tgt) Source # | |
Defined in Data.Macaw.CFG.Rewriter Methods pure :: a -> Rewriter arch s src tgt a # (<*>) :: Rewriter arch s src tgt (a -> b) -> Rewriter arch s src tgt a -> Rewriter arch s src tgt b # liftA2 :: (a -> b -> c) -> Rewriter arch s src tgt a -> Rewriter arch s src tgt b -> Rewriter arch s src tgt c # (*>) :: Rewriter arch s src tgt a -> Rewriter arch s src tgt b -> Rewriter arch s src tgt b # (<*) :: Rewriter arch s src tgt a -> Rewriter arch s src tgt b -> Rewriter arch s src tgt a # | |
Functor (Rewriter arch s src tgt) Source # | |
Monad (Rewriter arch s src tgt) Source # | |
runRewriter :: RewriteContext arch s src tgt -> Rewriter arch s src tgt (TermStmt arch tgt) -> ST s (RewriteContext arch s src tgt, [Stmt arch tgt], TermStmt arch tgt) Source #
Run the rewriter with the given context and collect the statements.
rewriteStmt :: Stmt arch src -> Rewriter arch s src tgt () Source #
Apply optimizations to a statement.
Since statements may be introduced/deleted during optimization, this should add new statements to the list of target statements rather than return the optimized statement.
rewriteValue :: forall arch src (tp :: Type) s tgt. Value arch src tp -> Rewriter arch s src tgt (Value arch tgt tp) Source #
rewriteApp :: forall arch tgt (tp :: Type) s src. App (Value arch tgt) tp -> Rewriter arch s src tgt (Value arch tgt tp) Source #