pub struct BaseRef<Ctx, Id: Copy> {
pub id: Id,
/* private fields */
}Expand description
A generic wrapper struct for referencing an ID with a context.
This is the basis for all *Ref and *MutRef.
Id is any cheap Copy handle — either a Registry Identifier (varnode,
literal, function, …) or a composite IR id (InstructionId, BlockId, …).
The bound is intentionally just Copy; routing to storage is the concern of
the concrete ref impls, not this wrapper.
Fields§
§id: IdImplementations§
Source§impl<'str, H: QCodeMut<'str>> BaseRef<H, BlockId>
impl<'str, H: QCodeMut<'str>> BaseRef<H, BlockId>
Sourcepub fn is_terminated(&self) -> bool
pub fn is_terminated(&self) -> bool
Whether this block currently ends in a terminator instruction.
Sourcepub fn set_comment(&mut self, comment: Option<String>)
pub fn set_comment(&mut self, comment: Option<String>)
Sets (or clears) this block’s comment. Own-block edit, host-routed.
Sourcepub fn rename_local(&mut self, name: Cow<'str, str>) -> Result<()>
pub fn rename_local(&mut self, name: Cow<'str, str>) -> Result<()>
Sets this block’s name and registers it in the owning function’s local name
table (own-block edit, backing-routed). Works over either backing, so
a FunctionPass can name the blocks it mints. Returns an error only on a
duplicate name.
Sourcepub fn insert_insn_at_index(&mut self, index: usize, insn_id: InstructionId)
pub fn insert_insn_at_index(&mut self, index: usize, insn_id: InstructionId)
Inserts an instruction at the given index, shifting later instructions
right. Panics if index > len.
Sourcepub fn push_insn(&mut self, id: InstructionId)
pub fn push_insn(&mut self, id: InstructionId)
Pushes an instruction to the end of this block.
Sourcepub fn insert_insn_before(
&mut self,
before_id: InstructionId,
insn_id: InstructionId,
)
pub fn insert_insn_before( &mut self, before_id: InstructionId, insn_id: InstructionId, )
Inserts insn_id immediately before before_id. Panics if before_id is
not in this block. Delegates to the backing’s insert_insn_before verb.
Sourcepub fn delete(&mut self)
pub fn delete(&mut self)
Removes this block from its function, including its payload. Delegates
to the backing’s delete_block verb.
Sourcepub fn absorb_block(&mut self, other: BlockId, edge_ab: EdgeId)
pub fn absorb_block(&mut self, other: BlockId, edge_ab: EdgeId)
Absorbs other into this block. Delegates to the backing’s absorb_block verb;
edge_ab must be the direct edge from this block to other.
Source§impl<'str, 'ctx> BaseRef<&'ctx mut Context<'str>, BlockId>
impl<'str, 'ctx> BaseRef<&'ctx mut Context<'str>, BlockId>
pub fn num_params(&self) -> usize
pub fn instruction_ids(&self) -> Vec<InstructionId>
pub fn instructions(&self) -> impl Iterator<Item = InstructionRef<'str, '_>>
pub fn address(&self) -> Option<u64>
pub fn successors(&self) -> impl Iterator<Item = (EdgeId, BlockId)>
Sourcepub fn with_address(self, addr: u64) -> Self
pub fn with_address(self, addr: u64) -> Self
Builder-style address assignment. Panics if addr is already mapped.
Use set_address for fallible assignment.
Sourcepub fn with_address_indexed(
self,
addresses: &mut AddressIndex,
addr: u64,
) -> Self
pub fn with_address_indexed( self, addresses: &mut AddressIndex, addr: u64, ) -> Self
Indexed construction variant of with_address.
pub fn in_function(self, fun_id: FunctionId) -> Self
pub fn with_id(&mut self, id: BlockId) -> &mut Self
Sourcepub fn reborrow(&mut self) -> BlockMutRef<'str, '_>
pub fn reborrow(&mut self) -> BlockMutRef<'str, '_>
Reborrows this BlockMutRef, shortening the lifetime.
pub fn parent_mut(&mut self) -> Option<FunctionMutRef<'str, '_>>
pub fn as_ref(&self) -> BlockRef<'str, '_>
Sourcepub fn push_param(&mut self, size: usize) -> BlockParamMutRef<'str, '_>
pub fn push_param(&mut self, size: usize) -> BlockParamMutRef<'str, '_>
Declares a new parameter on this block with the given size in bytes.
The parameter is appended to the block’s params list and its parent
is set to this block. It does NOT appear in instructions.
Returns a mutable reference whose ValueId can be used as an operand.
Sourcepub fn push_existing_param(&mut self, id: BlockParamId)
pub fn push_existing_param(&mut self, id: BlockParamId)
Appends an already-created block parameter to the parameters list
Sourcepub fn insert_insn_after(
&mut self,
after_id: InstructionId,
insn_id: InstructionId,
)
pub fn insert_insn_after( &mut self, after_id: InstructionId, insn_id: InstructionId, )
Inserts an instruction after the instruction identified by after_id in this block.
Panics if after_id is not an instruction in this block.
Sourcepub fn retain_insns(&mut self, f: impl FnMut(&InstructionId) -> bool)
pub fn retain_insns(&mut self, f: impl FnMut(&InstructionId) -> bool)
Retains only the instructions for which f returns true, deleting the
removed instructions.
Sourcepub fn extend_insns(&mut self, insns: &[InstructionId])
pub fn extend_insns(&mut self, insns: &[InstructionId])
Appends a slice of instruction ids to this block.
Sourcepub fn set_address(&mut self, addr: u64) -> Result<()>
pub fn set_address(&mut self, addr: u64) -> Result<()>
Associates this block with addr in the context address map.
Names the block after addr if it doesn’t already have a name.
Returns Err if another value is already mapped to addr.
Sourcepub fn set_address_indexed(
&mut self,
addresses: &mut AddressIndex,
addr: u64,
) -> Result<()>
pub fn set_address_indexed( &mut self, addresses: &mut AddressIndex, addr: u64, ) -> Result<()>
Assigns an address through a caller-owned construction index.
Source§impl<'str, 'ctx> BaseRef<&'ctx mut Context<'str>, BlockParamId>
impl<'str, 'ctx> BaseRef<&'ctx mut Context<'str>, BlockParamId>
Sourcepub fn set_origin(&mut self, origin: ValueId)
pub fn set_origin(&mut self, origin: ValueId)
Record the source value this param promotes (see BlockParam::origin).
pub fn constrain_size(&mut self, size: usize)
pub fn as_ref(&self) -> BlockParamRef<'str, '_>
Source§impl<'str, H: QCodeMut<'str>> BaseRef<H, BlockParamId>
impl<'str, H: QCodeMut<'str>> BaseRef<H, BlockParamId>
Source§impl<'s, 'ctx: 's, 'str: 'ctx, Ctx> BaseRef<Ctx, BytesId>where
Self: WithShared<'s, 'ctx, 'str>,
impl<'s, 'ctx: 's, 'str: 'ctx, Ctx> BaseRef<Ctx, BytesId>where
Self: WithShared<'s, 'ctx, 'str>,
Source§impl<'str, 'ctx> BaseRef<&'ctx mut Context<'str>, FunctionId>
impl<'str, 'ctx> BaseRef<&'ctx mut Context<'str>, FunctionId>
pub fn as_ref(&self) -> FunctionRef<'str, '_>
pub fn name(&self) -> &str
pub fn blocks(&self) -> impl Iterator<Item = BlockRef<'str, '_>>
pub fn root(&self) -> Option<BlockRef<'str, '_>>
Sourcepub fn set_root(&mut self, id: BlockId) -> Result<()>
pub fn set_root(&mut self, id: BlockId) -> Result<()>
Sets a block as the root of this function. This will also add the block to the function’s block list if it’s not already present. This will also set the address of the function/block to the address of the root block/function if both addresses are unset. Panics if the function already has an address that doesn’t match the root block’s address.
pub fn make_root(&mut self) -> BlockRef<'str, '_>
pub fn ensure_root(&mut self, id: BlockId) -> Result<()>
pub fn set_external(&mut self, is_external: bool)
Sourcepub fn set_import_ordinal(&mut self, ordinal: Option<u16>)
pub fn set_import_ordinal(&mut self, ordinal: Option<u16>)
Record the ordinal a by-ordinal PE import was brought in at. Set by the
resolve_ordinals pass before it renames the stub, so the by-ordinal
origin survives the rename.
pub fn set_kind(&mut self, kind: FunctionKind)
pub fn set_signature(&mut self, sig: FunctionSignature)
Sourcepub fn set_param_attrs(&mut self, attrs: Vec<ParamAttrs>)
pub fn set_param_attrs(&mut self, attrs: Vec<ParamAttrs>)
Records the inferred per-parameter pointer attributes on this function.
See FunctionSignature::param_attrs.
Sourcepub fn clear_param_attrs(&mut self)
pub fn clear_param_attrs(&mut self)
Drops any inferred per-parameter attributes (e.g. after a signature rewrite changed the parameter list, invalidating the index alignment).
Sourcepub fn set_written_spaces(&mut self, spaces: Option<Vec<SpaceId>>)
pub fn set_written_spaces(&mut self, spaces: Option<Vec<SpaceId>>)
Records the analysis-computed set of non-register spaces this function may
write. This is always a deliberate stamp: Some(spaces) is a bounded
witnessed set, None records stamped unbounded (⊤) — never clears the
stamp back to unstamped. See FunctionSignature::written_spaces and
FunctionRef::written_spaces_state.
Sourcepub fn set_extern_interface(&mut self, iface: ExternInterface)
pub fn set_extern_interface(&mut self, iface: ExternInterface)
Records the C-prototype-derived external call interface on this function.
See FunctionSignature::extern_interface; set by external_sigs,
consumed by argpromote_external.
Sourcepub fn set_argmem(&mut self, argmem: ExternArgmem)
pub fn set_argmem(&mut self, argmem: ExternArgmem)
Records the C-prototype-derived argmem summary on this external. See
FunctionSignature::argmem; set by external_sigs, read by the RAM
effect channel’s external_leaf.
Sourcepub fn set_register_effects(&mut self, register: RegisterChannelState)
pub fn set_register_effects(&mut self, register: RegisterChannelState)
Records this function’s register-channel effect state, preserving the
memory channel (read-modify-write). See FunctionInterface::effects.
Sourcepub fn set_memory_effects(&mut self, memory: MemoryChannelState)
pub fn set_memory_effects(&mut self, memory: MemoryChannelState)
Records this function’s memory-channel effect state, preserving the
register channel (read-modify-write). See FunctionInterface::effects.
Replaces every component of the memory channel. The channel has two
independent writers — the effect solve owns coarse/precise, the RAM
channel’s rewrite owns materialized — so a caller that computes only
one writer’s components must not build a whole state and pass it here:
the other writer’s field would be silently lost. Use
set_memory_solved or
set_memory_interface instead.
Sourcepub fn set_memory_solved(
&mut self,
coarse: WrittenSpacesState,
precise: Option<Footprint>,
)
pub fn set_memory_solved( &mut self, coarse: WrittenSpacesState, precise: Option<Footprint>, )
Records the solved components of the memory channel — the coarse written-space verdict and the precise footprint the same solve derived — leaving the materialized interface untouched.
The effect solve does not compute the interface, so it must not clear it.
Sourcepub fn set_memory_interface(&mut self, materialized: Option<MemoryInterfaceMap>)
pub fn set_memory_interface(&mut self, materialized: Option<MemoryInterfaceMap>)
Records the materialized memory interface, leaving the solved components
untouched. None marks the memory channel as not materialized.
Sourcepub fn set_is_pure(&mut self, value: bool)
pub fn set_is_pure(&mut self, value: bool)
Marks this function as fully functionalized over every side-effect
channel — a deterministic pure function of its params. See
FunctionSignature::is_pure.
Sourcepub fn set_reads_unbounded_stack(&mut self, value: bool)
pub fn set_reads_unbounded_stack(&mut self, value: bool)
Records whether this function performs an unresolved/dynamic stack read.
See FunctionSignature::reads_unbounded_stack.
Sourcepub fn set_frame_escapes_to_unbounded(&mut self, value: bool)
pub fn set_frame_escapes_to_unbounded(&mut self, value: bool)
Records whether this function hands a pointer into its own frame to a
callee that may read it unboundedly. See
FunctionSignature::frame_escapes_to_unbounded.
Sourcepub fn add_instruction_addr(&mut self, addr: u64)
pub fn add_instruction_addr(&mut self, addr: u64)
Records the address of a machine instruction lifted into this function.
Sourcepub fn add_block(&mut self, id: BlockId)
pub fn add_block(&mut self, id: BlockId)
Associates block with function by setting the block’s parent field.
With per-function block arenas, membership is arena ownership: a block
lives in the arena of the function it was born into (id.func), and that
must equal self.id. Ownership is derived from the arena, so this only
ensures the roster lists the block; it no longer moves storage between
functions.
Source§impl<'str, H: QCodeMut<'str>> BaseRef<H, InstructionId>
impl<'str, H: QCodeMut<'str>> BaseRef<H, InstructionId>
Sourcepub fn set_result_type(&mut self, new_type: TypeId)
pub fn set_result_type(&mut self, new_type: TypeId)
Sets this instruction’s result type (own-instruction edit, host-routed).
Panics on an incompatible same-nonzero-size change, exactly like
InstructionMutRef::set_type.
Source§impl<'str, 'ctx> BaseRef<&'ctx mut Context<'str>, InstructionId>
impl<'str, 'ctx> BaseRef<&'ctx mut Context<'str>, InstructionId>
pub fn as_ref(&self) -> InstructionRef<'str, '_>
pub fn inner_mut(&mut self) -> &mut Instruction<'str>
pub fn mnemonic_mut(&mut self) -> &mut Mnemonic
Sourcepub fn set_mnemonic(&mut self, mnemonic: Mnemonic)
pub fn set_mnemonic(&mut self, mnemonic: Mnemonic)
Replace this instruction’s mnemonic while keeping the reverse use-def map in sync.
pub fn address_mut(&mut self) -> &mut Option<u64>
pub fn set_address(&mut self, address: u64)
Sourcepub fn set_type(&mut self, new_type: TypeId)
pub fn set_type(&mut self, new_type: TypeId)
Sets the type of this instruction’s result.
Panics if the instruction already has a type that is incompatible with
new_type (same size but different kind).
Sourcepub fn set_type_resized(&mut self, new_type: TypeId)
pub fn set_type_resized(&mut self, new_type: TypeId)
Sets the result type, allowing the byte size to change.
Unlike set_type, this does not enforce size
invariance: it exists for transforms that legitimately resize an
aggregate result, such as trimming dead fields from a returned write-set
(dead_signature). Prefer set_type for any same-size retype.
Sourcepub fn set_space(&mut self, space: SpaceId)
pub fn set_space(&mut self, space: SpaceId)
Sets the address-space provenance of this instruction’s result.
A non-register space promotes the result to a
SpaceAddress of the same byte width.
Register spaces are ignored (pointer arithmetic is not allowed in the
register space).
Source§impl<'s, 'ctx: 's, 'str: 'ctx, Ctx> BaseRef<Ctx, LiteralId>where
Self: WithShared<'s, 'ctx, 'str>,
impl<'s, 'ctx: 's, 'str: 'ctx, Ctx> BaseRef<Ctx, LiteralId>where
Self: WithShared<'s, 'ctx, 'str>,
Source§impl<'s, 'ctx: 's, 'str: 'ctx, Ctx> BaseRef<Ctx, PoisonId>where
Self: WithShared<'s, 'ctx, 'str>,
impl<'s, 'ctx: 's, 'str: 'ctx, Ctx> BaseRef<Ctx, PoisonId>where
Self: WithShared<'s, 'ctx, 'str>,
Source§impl<'s, 'ctx: 's, 'str: 'ctx, Ctx> BaseRef<Ctx, VarnodeId>where
Self: WithShared<'s, 'ctx, 'str>,
impl<'s, 'ctx: 's, 'str: 'ctx, Ctx> BaseRef<Ctx, VarnodeId>where
Self: WithShared<'s, 'ctx, 'str>,
Source§impl<'str, 'ctx> BaseRef<&'ctx mut Context<'str>, VarnodeId>
impl<'str, 'ctx> BaseRef<&'ctx mut Context<'str>, VarnodeId>
Sourcepub fn set_label(&mut self, label: u32)
pub fn set_label(&mut self, label: u32)
Sets the integer label used to derive a generated temporary’s display
name. Unlike Renameable::rename, this neither allocates nor touches
the context name map, so it stays off the per-instruction hot path.
Trait Implementations§
Source§fn from(lit_ref: LiteralRef<'str, 'ctx>) -> Self
fn from(lit_ref: LiteralRef<'str, 'ctx>) -> Self
Source§fn from(var_ref: VarnodeRef<'str, 'ctx>) -> Self
fn from(var_ref: VarnodeRef<'str, 'ctx>) -> Self
Source§impl<'str, 'ctx, Id: Copy> From<BaseRef<&'ctx mut Context<'str>, Id>> for BaseRef<&'ctx Context<'str>, Id>
Convert mutable refs to immutable refs by cloning the ID and sharing the context reference.
impl<'str, 'ctx, Id: Copy> From<BaseRef<&'ctx mut Context<'str>, Id>> for BaseRef<&'ctx Context<'str>, Id>
Convert mutable refs to immutable refs by cloning the ID and sharing the context reference.