Safe Haskell | None |
---|---|
Language | Haskell2010 |
Data.Macaw.CFG.Core
Description
Defines data types needed to represent values, assignments, and statements from Machine code.
This is a low-level CFG representation where the entire program is a single CFG.
Synopsis
- data Stmt arch ids
- = AssignStmt !(Assignment arch ids tp)
- | WriteMem !(ArchAddrValue arch ids) !(MemRepr tp) !(Value arch ids tp)
- | CondWriteMem !(Value arch ids BoolType) !(ArchAddrValue arch ids) !(MemRepr tp) !(Value arch ids tp)
- | InstructionStart !(ArchAddrWord arch) !Text
- | Comment !Text
- | ExecArchStmt !(ArchStmt arch (Value arch ids))
- | ArchState !(ArchMemAddr arch) !(MapF (ArchReg arch) (Value arch ids))
- data Assignment arch ids (tp :: Type) = Assignment {}
- newtype AssignId ids (tp :: Type) = AssignId (Nonce ids tp)
- data Value arch ids (tp :: Type) where
- data CValue arch (tp :: Type) where
- BVCValue :: forall (n :: Natural) arch. 1 <= n => !(NatRepr n) -> !Integer -> CValue arch ('BVType n)
- BoolCValue :: forall arch. !Bool -> CValue arch 'BoolType
- RelocatableCValue :: forall arch. !(AddrWidthRepr (ArchAddrWidth arch)) -> !(MemAddr (ArchAddrWidth arch)) -> CValue arch ('BVType (ArchAddrWidth arch))
- SymbolCValue :: forall arch. !(AddrWidthRepr (ArchAddrWidth arch)) -> !SymbolIdentifier -> CValue arch ('BVType (ArchAddrWidth arch))
- pattern BoolValue :: forall tp arch ids. () => tp ~ BoolType => Bool -> Value arch ids tp
- pattern BVValue :: forall tp arch ids (n :: Nat). () => (tp ~ BVType n, 1 <= n) => NatRepr n -> Integer -> Value arch ids tp
- pattern RelocatableValue :: forall tp arch ids. () => tp ~ BVType (ArchAddrWidth arch) => AddrWidthRepr (ArchAddrWidth arch) -> MemAddr (ArchAddrWidth arch) -> Value arch ids tp
- pattern SymbolValue :: forall tp arch ids. () => tp ~ BVType (ArchAddrWidth arch) => AddrWidthRepr (ArchAddrWidth arch) -> SymbolIdentifier -> Value arch ids tp
- type BVValue arch ids (w :: Nat) = Value arch ids (BVType w)
- valueAsApp :: forall arch ids (tp :: Type). Value arch ids tp -> Maybe (App (Value arch ids) tp)
- valueAsArchFn :: forall arch ids (tp :: Type). Value arch ids tp -> Maybe (ArchFn arch (Value arch ids) tp)
- valueAsRhs :: forall arch ids (tp :: Type). Value arch ids tp -> Maybe (AssignRhs arch (Value arch ids) tp)
- valueAsMemAddr :: MemWidth (ArchAddrWidth arch) => BVValue arch ids (ArchAddrWidth arch) -> Maybe (ArchMemAddr arch)
- valueAsSegmentOff :: Memory (ArchAddrWidth arch) -> BVValue arch ids (ArchAddrWidth arch) -> Maybe (ArchSegmentOff arch)
- valueAsStaticMultiplication :: forall arch ids (w :: Nat). BVValue arch ids w -> Maybe (Natural, BVValue arch ids w)
- data StackOffsetView arch (tp :: Type) where
- StackOffsetView :: forall arch. !Integer -> StackOffsetView arch ('BVType (ArchAddrWidth arch))
- appAsStackOffset :: forall arch ids (tp :: Type). MemWidth (ArchAddrWidth arch) => (Value arch ids (BVType (ArchAddrWidth arch)) -> Maybe Integer) -> App (Value arch ids) tp -> Maybe (StackOffsetView arch tp)
- asBaseOffset :: forall arch ids (w :: Nat). Value arch ids (BVType w) -> (Value arch ids (BVType w), Integer)
- asInt64Constant :: Value arch ids (BVType 64) -> Maybe Int64
- class IPAlignment arch where
- fromIPAligned :: ArchAddrValue arch ids -> Maybe (ArchAddrValue arch ids)
- toIPAligned :: MemAddr (ArchAddrWidth arch) -> MemAddr (ArchAddrWidth arch)
- mkLit :: forall (n :: Natural) arch ids. 1 <= n => NatRepr n -> Integer -> Value arch ids (BVType n)
- bvValue :: forall (n :: Nat) arch ids. (KnownNat n, 1 <= n) => Integer -> Value arch ids (BVType n)
- ppValueAssignments :: forall arch ids (tp :: Type) ann. ArchConstraints arch => Value arch ids tp -> Doc ann
- ppValueAssignmentList :: forall arch ids (tp :: Type) ann. ArchConstraints arch => [Value arch ids tp] -> Doc ann
- data RegState (r :: k -> Type) (f :: k -> Type)
- regStateMap :: forall {v} (r :: v -> Type) (f :: v -> Type). RegState r f -> MapF r f
- getBoundValue :: forall {k} r (tp :: k) f. OrdF r => r tp -> RegState r f -> f tp
- boundValue :: forall {k} r (f :: k -> Type) (tp :: k). OrdF r => r tp -> Lens' (RegState r f) (f tp)
- cmpRegState :: forall {k} (r :: k -> Type) f g. OrdF r => (forall (u :: k). f u -> g u -> Bool) -> RegState r f -> RegState r g -> Bool
- curIP :: forall (r :: Type -> Type) (f :: Type -> Type). RegisterInfo r => Lens' (RegState r f) (f (BVType (RegAddrWidth r)))
- mkRegState :: RegisterInfo r => (forall (tp :: Type). r tp -> f tp) -> RegState r f
- mkRegStateM :: (RegisterInfo r, Applicative m) => (forall (tp :: Type). r tp -> m (f tp)) -> m (RegState r f)
- mapRegsWith :: (forall (tp :: k). r tp -> f tp -> g tp) -> RegState r f -> RegState r g
- traverseRegsWith :: forall {k} m r f g. Applicative m => (forall (tp :: k). r tp -> f tp -> m (g tp)) -> RegState r f -> m (RegState r g)
- traverseRegsWith_ :: forall {k} m r f. Applicative m => (forall (tp :: k). r tp -> f tp -> m ()) -> RegState r f -> m ()
- zipWithRegState :: forall (r :: Type -> Type) f g h. RegisterInfo r => (forall (u :: Type). f u -> g u -> h u) -> RegState r f -> RegState r g -> RegState r h
- ppRegMap :: forall (r :: Type -> Type) (v :: Type -> Type) ann. PrettyRegValue r v => MapF r v -> Doc ann
- ppAssignId :: forall ids (tp :: Type) ann. AssignId ids tp -> Doc ann
- ppValue :: forall arch ids (tp :: Type) ann. ShowF (ArchReg arch) => Prec -> Value arch ids tp -> Doc ann
- ppStmt :: ArchConstraints arch => (ArchAddrWord arch -> Doc ann) -> Stmt arch ids -> Doc ann
- class PrettyF (f :: k -> Type) where
- prettyF :: forall (tp :: k) ann. f tp -> Doc ann
- type ArchConstraints arch = (RegisterInfo (ArchReg arch), FoldableFC (ArchFn arch), IsArchFn (ArchFn arch), IsArchStmt (ArchStmt arch), FoldableF (ArchStmt arch), IsArchTermStmt (ArchTermStmt arch), IPAlignment arch)
- class PrettyRegValue (r :: Type -> Type) (f :: Type -> Type) where
- class IsArchFn (f :: (Type -> Type) -> Type -> Type) where
- ppArchFn :: forall m v ann (tp :: Type). Applicative m => (forall (u :: Type). v u -> m (Doc ann)) -> f v tp -> m (Doc ann)
- class IsArchStmt (f :: (Type -> Type) -> Type) where
- ppArchStmt :: (forall (u :: Type). v u -> Doc ann) -> f v -> Doc ann
- class IsArchTermStmt (f :: (Type -> Type) -> Type) where
- ppArchTermStmt :: (forall (u :: Type). v u -> Doc ann) -> f v -> Doc ann
- collectValueRep :: forall arch ids (tp :: Type) ann. ArchConstraints arch => Prec -> Value arch ids tp -> State (MapF (AssignId ids) (DocF ann)) (Doc ann)
- ppValueAssignments' :: State (MapF (AssignId ids) (DocF ann)) (Doc ann) -> Doc ann
- data DocF ann (a :: Type)
- addrWidthTypeRepr :: forall (w :: Natural). AddrWidthRepr w -> TypeRepr (BVType w)
- class (OrdF r, ShowF r, MemWidth (RegAddrWidth r), HasRepr r TypeRepr) => RegisterInfo (r :: Type -> Type) where
- archRegs :: [Some r]
- archRegSet :: MapF r (Const () :: Type -> Type)
- sp_reg :: r (BVType (RegAddrWidth r))
- ip_reg :: r (BVType (RegAddrWidth r))
- syscall_num_reg :: r (BVType (RegAddrWidth r))
- syscallArgumentRegs :: [r (BVType (RegAddrWidth r))]
- asStackAddrOffset :: forall arch ids (tp :: Type). RegisterInfo (ArchReg arch) => Value arch ids tp -> Maybe (BVValue arch ids (ArchAddrWidth arch))
- refsInValue :: forall arch ids (tp :: Type). Value arch ids tp -> Set (Some (AssignId ids))
- type ArchAddrValue arch ids = BVValue arch ids (ArchAddrWidth arch)
- type ArchSegmentOff arch = MemSegmentOff (ArchAddrWidth arch)
- type family ArchBlockPrecond arch
- class FoldableFC (t :: (k -> Type) -> l -> Type) where
- foldMapFC :: forall f m. Monoid m => (forall (x :: k). f x -> m) -> forall (x :: l). t f x -> m
- foldrFC :: (forall (x :: k). f x -> b -> b) -> forall (x :: l). b -> t f x -> b
- foldlFC :: forall f b. (forall (x :: k). b -> f x -> b) -> forall (x :: l). b -> t f x -> b
- foldrFC' :: (forall (x :: k). f x -> b -> b) -> forall (x :: l). b -> t f x -> b
- foldlFC' :: forall f b. (forall (x :: k). b -> f x -> b) -> forall (x :: l). b -> t f x -> b
- toListFC :: (forall (x :: k). f x -> a) -> forall (x :: l). t f x -> [a]
- module Data.Macaw.CFG.AssignRhs
- module Data.Macaw.Utils.Pretty
Stmt level declarations
A statement in our control flow graph language.
Constructors
AssignStmt !(Assignment arch ids tp) | |
WriteMem !(ArchAddrValue arch ids) !(MemRepr tp) !(Value arch ids tp) | This denotes a write to memory, and consists of an address
to write to, a |
CondWriteMem !(Value arch ids BoolType) !(ArchAddrValue arch ids) !(MemRepr tp) !(Value arch ids tp) | This denotes a write to memory that only executes if the condition is true. |
InstructionStart !(ArchAddrWord arch) !Text | The start of an instruction The information includes the offset relative to the start of the block and the disassembler output if available (or empty string if unavailable) |
Comment !Text | A user-level comment |
ExecArchStmt !(ArchStmt arch (Value arch ids)) | Execute an architecture specific statement |
ArchState !(ArchMemAddr arch) !(MapF (ArchReg arch) (Value arch ids)) | Address of an instruction and the *machine* registers that it updates (with their associated macaw values after the execution of the instruction). |
data Assignment arch ids (tp :: Type) Source #
An assignment consists of a unique location identifier and a right- hand side that returns a value.
Constructors
Assignment | |
Instances
ArchConstraints arch => Pretty (Assignment arch ids tp) Source # | |
Defined in Data.Macaw.CFG.Core |
newtype AssignId ids (tp :: Type) Source #
An AssignId
is a unique identifier used to identify assignment
statements, in a manner similar to SSA (single static assignment)
form. AssignId
s are typed, and also include a type variable ids
that intuitively denotes the set of identifiers from which they are
drawn.
Constructors
AssignId (Nonce ids tp) |
Instances
TestEquality (AssignId ids :: Type -> Type) Source # | |
Defined in Data.Macaw.CFG.Core | |
OrdF (AssignId ids :: Type -> Type) Source # | |
Defined in Data.Macaw.CFG.Core Methods compareF :: forall (x :: Type) (y :: Type). AssignId ids x -> AssignId ids y -> OrderingF x y leqF :: forall (x :: Type) (y :: Type). AssignId ids x -> AssignId ids y -> Bool ltF :: forall (x :: Type) (y :: Type). AssignId ids x -> AssignId ids y -> Bool geqF :: forall (x :: Type) (y :: Type). AssignId ids x -> AssignId ids y -> Bool gtF :: forall (x :: Type) (y :: Type). AssignId ids x -> AssignId ids y -> Bool | |
ShowF (AssignId ids :: Type -> Type) Source # | |
Show (AssignId ids tp) Source # | |
Eq (AssignId ids tp) Source # | |
Ord (AssignId ids tp) Source # | |
Defined in Data.Macaw.CFG.Core Methods compare :: AssignId ids tp -> AssignId ids tp -> Ordering # (<) :: AssignId ids tp -> AssignId ids tp -> Bool # (<=) :: AssignId ids tp -> AssignId ids tp -> Bool # (>) :: AssignId ids tp -> AssignId ids tp -> Bool # (>=) :: AssignId ids tp -> AssignId ids tp -> Bool # max :: AssignId ids tp -> AssignId ids tp -> AssignId ids tp # min :: AssignId ids tp -> AssignId ids tp -> AssignId ids tp # |
Value
data Value arch ids (tp :: Type) where Source #
A value at runtime
Values are only well-defined in the context of a particular block, and are immutable within that context (i.e. their value would not change from a memory write).
Constructors
CValue :: forall arch (tp :: Type) ids. !(CValue arch tp) -> Value arch ids tp | A constant value |
AssignedValue :: forall arch ids (tp :: Type). !(Assignment arch ids tp) -> Value arch ids tp | Value from an assignment statement. |
Initial :: forall arch (tp :: Type) ids. !(ArchReg arch tp) -> Value arch ids tp | Represents the value assigned to the register when the block started. |
Instances
OrdF (ArchReg arch) => TestEquality (Value arch ids :: Type -> Type) Source # | |
Defined in Data.Macaw.CFG.Core | |
(RegisterInfo r, r ~ ArchReg arch) => PrettyRegValue r (Value arch ids) Source # | |
OrdF (ArchReg arch) => EqF (Value arch ids :: Type -> Type) Source # | |
OrdF (ArchReg arch) => OrdF (Value arch ids :: Type -> Type) Source # | |
Defined in Data.Macaw.CFG.Core Methods compareF :: forall (x :: Type) (y :: Type). Value arch ids x -> Value arch ids y -> OrderingF x y leqF :: forall (x :: Type) (y :: Type). Value arch ids x -> Value arch ids y -> Bool ltF :: forall (x :: Type) (y :: Type). Value arch ids x -> Value arch ids y -> Bool geqF :: forall (x :: Type) (y :: Type). Value arch ids x -> Value arch ids y -> Bool gtF :: forall (x :: Type) (y :: Type). Value arch ids x -> Value arch ids y -> Bool | |
HasRepr (ArchReg arch) TypeRepr => HasRepr (Value arch ids :: Type -> Type) TypeRepr Source # | |
ShowF (ArchReg arch) => Show (Value arch ids tp) Source # | |
OrdF (ArchReg arch) => Eq (Value arch ids tp) Source # | |
OrdF (ArchReg arch) => Ord (Value arch ids tp) Source # | |
Defined in Data.Macaw.CFG.Core Methods compare :: Value arch ids tp -> Value arch ids tp -> Ordering # (<) :: Value arch ids tp -> Value arch ids tp -> Bool # (<=) :: Value arch ids tp -> Value arch ids tp -> Bool # (>) :: Value arch ids tp -> Value arch ids tp -> Bool # (>=) :: Value arch ids tp -> Value arch ids tp -> Bool # max :: Value arch ids tp -> Value arch ids tp -> Value arch ids tp # min :: Value arch ids tp -> Value arch ids tp -> Value arch ids tp # | |
ArchConstraints arch => Pretty (AssignRhs arch (Value arch ids) tp) Source # | |
Defined in Data.Macaw.CFG.Core | |
ShowF (ArchReg arch) => Pretty (Value arch ids tp) Source # | |
Defined in Data.Macaw.CFG.Core |
data CValue arch (tp :: Type) where Source #
A constant whose value does not change during execution.
Constructors
BVCValue :: forall (n :: Natural) arch. 1 <= n => !(NatRepr n) -> !Integer -> CValue arch ('BVType n) | A constant bitvector The integer should be between 0 and 2^n-1. |
BoolCValue :: forall arch. !Bool -> CValue arch 'BoolType | A constant Boolean |
RelocatableCValue :: forall arch. !(AddrWidthRepr (ArchAddrWidth arch)) -> !(MemAddr (ArchAddrWidth arch)) -> CValue arch ('BVType (ArchAddrWidth arch)) | A memory address |
SymbolCValue :: forall arch. !(AddrWidthRepr (ArchAddrWidth arch)) -> !SymbolIdentifier -> CValue arch ('BVType (ArchAddrWidth arch)) | This denotes the address of a symbol identifier in the binary. This appears when dealing with relocations. |
Instances
TestEquality (CValue arch :: Type -> Type) Source # | |
Defined in Data.Macaw.CFG.Core | |
HashableF (CValue arch :: Type -> Type) Source # | |
Defined in Data.Macaw.CFG.Core | |
OrdF (CValue arch :: Type -> Type) Source # | |
Defined in Data.Macaw.CFG.Core Methods compareF :: forall (x :: Type) (y :: Type). CValue arch x -> CValue arch y -> OrderingF x y leqF :: forall (x :: Type) (y :: Type). CValue arch x -> CValue arch y -> Bool ltF :: forall (x :: Type) (y :: Type). CValue arch x -> CValue arch y -> Bool geqF :: forall (x :: Type) (y :: Type). CValue arch x -> CValue arch y -> Bool gtF :: forall (x :: Type) (y :: Type). CValue arch x -> CValue arch y -> Bool | |
HasRepr (CValue arch :: Type -> Type) TypeRepr Source # | |
Show (CValue arch tp) Source # | |
Eq (CValue arch tp) Source # | |
Hashable (CValue arch tp) Source # | |
Defined in Data.Macaw.CFG.Core | |
Pretty (CValue arch tp) Source # | |
Defined in Data.Macaw.CFG.Core |
pattern BoolValue :: forall tp arch ids. () => tp ~ BoolType => Bool -> Value arch ids tp Source #
A constant Boolean
pattern BVValue :: forall tp arch ids (n :: Nat). () => (tp ~ BVType n, 1 <= n) => NatRepr n -> Integer -> Value arch ids tp Source #
A constant bitvector
The integer should be between 0 and 2^n-1.
pattern RelocatableValue :: forall tp arch ids. () => tp ~ BVType (ArchAddrWidth arch) => AddrWidthRepr (ArchAddrWidth arch) -> MemAddr (ArchAddrWidth arch) -> Value arch ids tp Source #
A memory address
pattern SymbolValue :: forall tp arch ids. () => tp ~ BVType (ArchAddrWidth arch) => AddrWidthRepr (ArchAddrWidth arch) -> SymbolIdentifier -> Value arch ids tp Source #
This denotes the address of a symbol identifier in the binary.
This appears when dealing with relocations.
valueAsApp :: forall arch ids (tp :: Type). Value arch ids tp -> Maybe (App (Value arch ids) tp) Source #
Return the value evaluated if this is from an App
.
valueAsArchFn :: forall arch ids (tp :: Type). Value arch ids tp -> Maybe (ArchFn arch (Value arch ids) tp) Source #
Return the architecture-specific function associated with a value.
valueAsRhs :: forall arch ids (tp :: Type). Value arch ids tp -> Maybe (AssignRhs arch (Value arch ids) tp) Source #
Return the right-hand side if this is an assignment.
valueAsMemAddr :: MemWidth (ArchAddrWidth arch) => BVValue arch ids (ArchAddrWidth arch) -> Maybe (ArchMemAddr arch) Source #
This returns a segmented address if the value can be interpreted as a literal memory address, and returns nothing otherwise.
valueAsSegmentOff :: Memory (ArchAddrWidth arch) -> BVValue arch ids (ArchAddrWidth arch) -> Maybe (ArchSegmentOff arch) Source #
Returns a segment offset associated with the value if one can be defined.
valueAsStaticMultiplication :: forall arch ids (w :: Nat). BVValue arch ids w -> Maybe (Natural, BVValue arch ids w) Source #
data StackOffsetView arch (tp :: Type) where Source #
A stack offset that can also capture the width must match the pointer width.
Constructors
StackOffsetView :: forall arch. !Integer -> StackOffsetView arch ('BVType (ArchAddrWidth arch)) |
Arguments
:: forall arch ids (tp :: Type). MemWidth (ArchAddrWidth arch) | |
=> (Value arch ids (BVType (ArchAddrWidth arch)) -> Maybe Integer) | Function for inferring if argument is a stack offset. |
-> App (Value arch ids) tp | |
-> Maybe (StackOffsetView arch tp) |
This pattern matches on an app to see if it can be used to adjust a stack offset.
asBaseOffset :: forall arch ids (w :: Nat). Value arch ids (BVType w) -> (Value arch ids (BVType w), Integer) Source #
class IPAlignment arch where Source #
During the jump-table detection phase of code discovery, we have the
following problem: we are given a value which represents the computation
done to create an address to jump to. We'd like to look at the shape of that
computation and check whether it "looks like a jump table" -- say, whether
it is the computation array_base + pointer_size * i
for some unknown index
i
.
However, some architectures have special rules about what addresses are valid jump targets, and so there is frequently a sort of "standard prelude" which converts an arbitrary address into a valid jump target. For example, on PowerPC, the instruction pointer is always a multiple of four, so any computed jump strips off the bottom two bits. We'd like the jump-table detection code to be able to ignore that standard prelude when looking for jump-table-like computations (without having to know that the right thing to look for is "ignore the bottom two bits").
The fromIPAligned
method below gives specific architectures a hook for
stripping away the prelude and leaving the underlying computed value (which
is potentially an invalid jump target!).
Of course, after stripping away the cleanup parts of the computation,
checking the unclean computation for specific patterns, and finding
particular concrete values that the unclean computation could evaluate to,
the discovery code then needs to be able to re-clean the concrete values.
The toIPAligned
method gives architectures a hook to do that direction of
translation.
Methods
fromIPAligned :: ArchAddrValue arch ids -> Maybe (ArchAddrValue arch ids) Source #
Take an aligned value and strip away the bits of the semantics that
align it, leaving behind a (potentially unaligned) value. Return Nothing
if the input value does not appear to be a valid value for the instruction
pointer.
toIPAligned :: MemAddr (ArchAddrWidth arch) -> MemAddr (ArchAddrWidth arch) Source #
Take an unaligned memory address and clean it up so that it is a valid value for the instruction pointer.
mkLit :: forall (n :: Natural) arch ids. 1 <= n => NatRepr n -> Integer -> Value arch ids (BVType n) Source #
bvValue :: forall (n :: Nat) arch ids. (KnownNat n, 1 <= n) => Integer -> Value arch ids (BVType n) Source #
ppValueAssignments :: forall arch ids (tp :: Type) ann. ArchConstraints arch => Value arch ids tp -> Doc ann Source #
This pretty prints all the history used to create a value.
ppValueAssignmentList :: forall arch ids (tp :: Type) ann. ArchConstraints arch => [Value arch ids tp] -> Doc ann Source #
RegState
data RegState (r :: k -> Type) (f :: k -> Type) Source #
This represents the state of the processor registers.
Instances
FoldableF (RegState r :: (k -> Type) -> Type) Source # | |
Defined in Data.Macaw.CFG.Core Methods foldMapF :: Monoid m => (forall (s :: k). e s -> m) -> RegState r e -> m foldrF :: (forall (s :: k). e s -> b -> b) -> b -> RegState r e -> b foldlF :: (forall (s :: k). b -> e s -> b) -> b -> RegState r e -> b foldrF' :: (forall (s :: k). e s -> b -> b) -> b -> RegState r e -> b foldlF' :: (forall (s :: k). b -> e s -> b) -> b -> RegState r e -> b toListF :: (forall (tp :: k). f tp -> a) -> RegState r f -> [a] | |
FunctorF (RegState r :: (k -> Type) -> Type) Source # | |
Defined in Data.Macaw.CFG.Core | |
TraversableF (RegState r :: (k -> Type) -> Type) Source # | |
Defined in Data.Macaw.CFG.Core Methods traverseF :: Applicative m => (forall (s :: k). e s -> m (f s)) -> RegState r e -> m (RegState r f) | |
PrettyRegValue r f => Show (RegState r f) Source # | |
(OrdF r, EqF f) => Eq (RegState r f) Source # | |
PrettyRegValue r f => Pretty (RegState r f) Source # | |
Defined in Data.Macaw.CFG.Core |
regStateMap :: forall {v} (r :: v -> Type) (f :: v -> Type). RegState r f -> MapF r f Source #
Return underlying map of register state.
getBoundValue :: forall {k} r (tp :: k) f. OrdF r => r tp -> RegState r f -> f tp Source #
boundValue :: forall {k} r (f :: k -> Type) (tp :: k). OrdF r => r tp -> Lens' (RegState r f) (f tp) Source #
Get a register out of the state.
Arguments
:: forall {k} (r :: k -> Type) f g. OrdF r | |
=> (forall (u :: k). f u -> g u -> Bool) | Function for checking if two values are equal. |
-> RegState r f | |
-> RegState r g | |
-> Bool |
Compares if two register states are equal.
curIP :: forall (r :: Type -> Type) (f :: Type -> Type). RegisterInfo r => Lens' (RegState r f) (f (BVType (RegAddrWidth r))) Source #
mkRegState :: RegisterInfo r => (forall (tp :: Type). r tp -> f tp) -> RegState r f Source #
mkRegStateM :: (RegisterInfo r, Applicative m) => (forall (tp :: Type). r tp -> m (f tp)) -> m (RegState r f) Source #
mapRegsWith :: (forall (tp :: k). r tp -> f tp -> g tp) -> RegState r f -> RegState r g Source #
Traverse the register state with the name of each register and value.
traverseRegsWith :: forall {k} m r f g. Applicative m => (forall (tp :: k). r tp -> f tp -> m (g tp)) -> RegState r f -> m (RegState r g) Source #
Traverse the register state with the name of each register and value.
traverseRegsWith_ :: forall {k} m r f. Applicative m => (forall (tp :: k). r tp -> f tp -> m ()) -> RegState r f -> m () Source #
Traverse the register state with the name of each register and value.
zipWithRegState :: forall (r :: Type -> Type) f g h. RegisterInfo r => (forall (u :: Type). f u -> g u -> h u) -> RegState r f -> RegState r g -> RegState r h Source #
ppRegMap :: forall (r :: Type -> Type) (v :: Type -> Type) ann. PrettyRegValue r v => MapF r v -> Doc ann Source #
Pretty printing
ppAssignId :: forall ids (tp :: Type) ann. AssignId ids tp -> Doc ann Source #
ppValue :: forall arch ids (tp :: Type) ann. ShowF (ArchReg arch) => Prec -> Value arch ids tp -> Doc ann Source #
Pretty print a value.
Arguments
:: ArchConstraints arch | |
=> (ArchAddrWord arch -> Doc ann) | Function for pretty printing an instruction address offset |
-> Stmt arch ids | |
-> Doc ann |
type ArchConstraints arch = (RegisterInfo (ArchReg arch), FoldableFC (ArchFn arch), IsArchFn (ArchFn arch), IsArchStmt (ArchStmt arch), FoldableF (ArchStmt arch), IsArchTermStmt (ArchTermStmt arch), IPAlignment arch) Source #
Constructs expected by architectures type classes.
class PrettyRegValue (r :: Type -> Type) (f :: Type -> Type) where Source #
This class provides a way of optionally pretty printing the contents of a register or omitting them.
Methods
ppValueEq :: forall (tp :: Type) ann. r tp -> f tp -> Maybe (Doc ann) Source #
ppValueEq should return a doc if the contents of the given register should be printed, and Nothing if the contents should be ignored.
Instances
(MemWidth w, ShowF r) => PrettyRegValue r (AbsValue w) Source # | Print a list of Docs vertically separated. |
(RegisterInfo r, r ~ ArchReg arch) => PrettyRegValue r (Value arch ids) Source # | |
class IsArchFn (f :: (Type -> Type) -> Type -> Type) where Source #
Typeclass for architecture-specific functions
class IsArchStmt (f :: (Type -> Type) -> Type) where Source #
Typeclass for architecture-specific statements
Methods
Arguments
:: (forall (u :: Type). v u -> Doc ann) | Function for pretty printing value. |
-> f v | |
-> Doc ann |
A function for pretty printing an architecture statement of a given type.
class IsArchTermStmt (f :: (Type -> Type) -> Type) where Source #
Methods
Arguments
:: (forall (u :: Type). v u -> Doc ann) | Function to pretty print contained values |
-> f v | |
-> Doc ann |
Arguments
:: forall arch ids (tp :: Type) ann. ArchConstraints arch | |
=> Prec | Outer precedence |
-> Value arch ids tp | |
-> State (MapF (AssignId ids) (DocF ann)) (Doc ann) |
This pretty prints a value's representation while saving the pretty printed repreentation of subvalues in a map.
ppValueAssignments' :: State (MapF (AssignId ids) (DocF ann)) (Doc ann) -> Doc ann Source #
This pretty prints all the history used to create a value.
data DocF ann (a :: Type) Source #
Helper type to wrap up a Doc
with a dummy type argument; used to put
Doc
s into heterogenous maps in the below
Utilities
addrWidthTypeRepr :: forall (w :: Natural). AddrWidthRepr w -> TypeRepr (BVType w) Source #
A type repr for the address width
RegisterInfo
class (OrdF r, ShowF r, MemWidth (RegAddrWidth r), HasRepr r TypeRepr) => RegisterInfo (r :: Type -> Type) where Source #
This class provides access to information about registers.
Minimal complete definition
archRegs, sp_reg, ip_reg, syscall_num_reg, syscallArgumentRegs
Methods
List of all arch registers.
archRegSet :: MapF r (Const () :: Type -> Type) Source #
Set of all arch registers (expressed as a Map
of units).
Preferable to archRegs
when building a map.
sp_reg :: r (BVType (RegAddrWidth r)) Source #
The stack pointer register
ip_reg :: r (BVType (RegAddrWidth r)) Source #
The instruction pointer register
syscall_num_reg :: r (BVType (RegAddrWidth r)) Source #
The register used to store system call numbers.
syscallArgumentRegs :: [r (BVType (RegAddrWidth r))] Source #
Registers used for passing system call arguments
asStackAddrOffset :: forall arch ids (tp :: Type). RegisterInfo (ArchReg arch) => Value arch ids tp -> Maybe (BVValue arch ids (ArchAddrWidth arch)) Source #
Returns a offset if the value is an offset of the stack.
References
refsInValue :: forall arch ids (tp :: Type). Value arch ids tp -> Set (Some (AssignId ids)) Source #
Synonyms
type ArchAddrValue arch ids = BVValue arch ids (ArchAddrWidth arch) Source #
A address value for a specific architecture
type ArchSegmentOff arch = MemSegmentOff (ArchAddrWidth arch) Source #
A pair containing a segment and valid offset within the segment.
type family ArchBlockPrecond arch Source #
This family maps architecture parameters to information needed to successfully translate machine code into Macaw CFGs.
This is currently used for registers values that are required to be known constants at translation time. For example, on X86_64, due to aliasing between the FPU and MMX registers, we require that the floating point stack value is known at translation time so that we do not need to check which register is modified when pushing or poping from the x86 stack.
If no preconditions are needed, this can just be set to the unit type.
class FoldableFC (t :: (k -> Type) -> l -> Type) where #
Methods
foldMapFC :: forall f m. Monoid m => (forall (x :: k). f x -> m) -> forall (x :: l). t f x -> m #
foldrFC :: (forall (x :: k). f x -> b -> b) -> forall (x :: l). b -> t f x -> b #
foldlFC :: forall f b. (forall (x :: k). b -> f x -> b) -> forall (x :: l). b -> t f x -> b #
foldrFC' :: (forall (x :: k). f x -> b -> b) -> forall (x :: l). b -> t f x -> b #
foldlFC' :: forall f b. (forall (x :: k). b -> f x -> b) -> forall (x :: l). b -> t f x -> b #
toListFC :: (forall (x :: k). f x -> a) -> forall (x :: l). t f x -> [a] #
Instances
FoldableFC App Source # | |
Defined in Data.Macaw.CFG.App Methods foldMapFC :: forall f m. Monoid m => (forall (x :: Type). f x -> m) -> forall (x :: Type). App f x -> m # foldrFC :: (forall (x :: Type). f x -> b -> b) -> forall (x :: Type). b -> App f x -> b # foldlFC :: forall f b. (forall (x :: Type). b -> f x -> b) -> forall (x :: Type). b -> App f x -> b # foldrFC' :: (forall (x :: Type). f x -> b -> b) -> forall (x :: Type). b -> App f x -> b # foldlFC' :: forall f b. (forall (x :: Type). b -> f x -> b) -> forall (x :: Type). b -> App f x -> b # toListFC :: (forall (x :: Type). f x -> a) -> forall (x :: Type). App f x -> [a] # | |
FoldableFC (ArchFn arch) => FoldableFC (AssignRhs arch :: (Type -> Type) -> Type -> Type) Source # | |
Defined in Data.Macaw.CFG.AssignRhs Methods foldMapFC :: forall f m. Monoid m => (forall (x :: Type). f x -> m) -> forall (x :: Type). AssignRhs arch f x -> m # foldrFC :: (forall (x :: Type). f x -> b -> b) -> forall (x :: Type). b -> AssignRhs arch f x -> b # foldlFC :: forall f b. (forall (x :: Type). b -> f x -> b) -> forall (x :: Type). b -> AssignRhs arch f x -> b # foldrFC' :: (forall (x :: Type). f x -> b -> b) -> forall (x :: Type). b -> AssignRhs arch f x -> b # foldlFC' :: forall f b. (forall (x :: Type). b -> f x -> b) -> forall (x :: Type). b -> AssignRhs arch f x -> b # toListFC :: (forall (x :: Type). f x -> a) -> forall (x :: Type). AssignRhs arch f x -> [a] # | |
FoldableFC (Assignment :: (k -> Type) -> Ctx k -> Type) | |
Defined in Data.Parameterized.Context.Safe Methods foldMapFC :: forall f m. Monoid m => (forall (x :: k). f x -> m) -> forall (x :: Ctx k). Assignment f x -> m # foldrFC :: (forall (x :: k). f x -> b -> b) -> forall (x :: Ctx k). b -> Assignment f x -> b # foldlFC :: forall f b. (forall (x :: k). b -> f x -> b) -> forall (x :: Ctx k). b -> Assignment f x -> b # foldrFC' :: (forall (x :: k). f x -> b -> b) -> forall (x :: Ctx k). b -> Assignment f x -> b # foldlFC' :: forall f b. (forall (x :: k). b -> f x -> b) -> forall (x :: Ctx k). b -> Assignment f x -> b # toListFC :: (forall (x :: k). f x -> a) -> forall (x :: Ctx k). Assignment f x -> [a] # | |
FoldableFC (Assignment :: (k -> Type) -> Ctx k -> Type) | |
Defined in Data.Parameterized.Context.Unsafe Methods foldMapFC :: forall f m. Monoid m => (forall (x :: k). f x -> m) -> forall (x :: Ctx k). Assignment f x -> m # foldrFC :: (forall (x :: k). f x -> b -> b) -> forall (x :: Ctx k). b -> Assignment f x -> b # foldlFC :: forall f b. (forall (x :: k). b -> f x -> b) -> forall (x :: Ctx k). b -> Assignment f x -> b # foldrFC' :: (forall (x :: k). f x -> b -> b) -> forall (x :: Ctx k). b -> Assignment f x -> b # foldlFC' :: forall f b. (forall (x :: k). b -> f x -> b) -> forall (x :: Ctx k). b -> Assignment f x -> b # toListFC :: (forall (x :: k). f x -> a) -> forall (x :: Ctx k). Assignment f x -> [a] # | |
FoldableFC (List :: (k -> Type) -> [k] -> Type) | |
Defined in Data.Parameterized.List Methods foldMapFC :: forall f m. Monoid m => (forall (x :: k). f x -> m) -> forall (x :: [k]). List f x -> m # foldrFC :: (forall (x :: k). f x -> b -> b) -> forall (x :: [k]). b -> List f x -> b # foldlFC :: forall f b. (forall (x :: k). b -> f x -> b) -> forall (x :: [k]). b -> List f x -> b # foldrFC' :: (forall (x :: k). f x -> b -> b) -> forall (x :: [k]). b -> List f x -> b # foldlFC' :: forall f b. (forall (x :: k). b -> f x -> b) -> forall (x :: [k]). b -> List f x -> b # toListFC :: (forall (x :: k). f x -> a) -> forall (x :: [k]). List f x -> [a] # |
module Data.Macaw.CFG.AssignRhs
module Data.Macaw.Utils.Pretty