Skip to main content

BaseRef

Struct BaseRef 

Source
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: Id

Implementations§

Source§

impl<'str, H: QCodeMut<'str>> BaseRef<H, BlockId>

Source

pub fn is_terminated(&self) -> bool

Whether this block currently ends in a terminator instruction.

Source

pub fn set_comment(&mut self, comment: Option<String>)

Sets (or clears) this block’s comment. Own-block edit, host-routed.

Source

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.

Source

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.

Source

pub fn push_insn(&mut self, id: InstructionId)

Pushes an instruction to the end of this block.

Source

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.

Source

pub fn delete(&mut self)

Removes this block from its function, including its payload. Delegates to the backing’s delete_block verb.

Source

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>

Source

pub fn num_params(&self) -> usize

Source

pub fn instruction_ids(&self) -> Vec<InstructionId>

Source

pub fn instructions(&self) -> impl Iterator<Item = InstructionRef<'str, '_>>

Source

pub fn address(&self) -> Option<u64>

Source

pub fn successors(&self) -> impl Iterator<Item = (EdgeId, BlockId)>

Source

pub fn with_address(self, addr: u64) -> Self

Builder-style address assignment. Panics if addr is already mapped. Use set_address for fallible assignment.

Source

pub fn with_address_indexed( self, addresses: &mut AddressIndex, addr: u64, ) -> Self

Indexed construction variant of with_address.

Source

pub fn in_function(self, fun_id: FunctionId) -> Self

Source

pub fn with_id(&mut self, id: BlockId) -> &mut Self

Source

pub fn reborrow(&mut self) -> BlockMutRef<'str, '_>

Reborrows this BlockMutRef, shortening the lifetime.

Source

pub fn parent_mut(&mut self) -> Option<FunctionMutRef<'str, '_>>

Source

pub fn as_ref(&self) -> BlockRef<'str, '_>

Source

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.

Source

pub fn push_existing_param(&mut self, id: BlockParamId)

Appends an already-created block parameter to the parameters list

Source

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.

Source

pub fn retain_insns(&mut self, f: impl FnMut(&InstructionId) -> bool)

Retains only the instructions for which f returns true, deleting the removed instructions.

Source

pub fn pop_insn(&mut self)

Removes the last instruction from this block.

Source

pub fn extend_insns(&mut self, insns: &[InstructionId])

Appends a slice of instruction ids to this block.

Source

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.

Source

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>

Source

pub fn set_origin(&mut self, origin: ValueId)

Record the source value this param promotes (see BlockParam::origin).

Source

pub fn constrain_size(&mut self, size: usize)

Source

pub fn as_ref(&self) -> BlockParamRef<'str, '_>

Source§

impl<'str, H: QCodeMut<'str>> BaseRef<H, BlockParamId>

Source

pub fn set_size(&mut self, size: usize)

Resize this parameter: mint an int type in shared storage and retype the param in its owning function’s arena.

Source

pub fn rename_local(&mut self, name: Cow<'str, str>) -> Result<()>

Renames this parameter in its owning function’s local name table (own-param edit, host-routed). Errors only on a duplicate name.

Source§

impl<'s, 'ctx: 's, 'str: 'ctx, Ctx> BaseRef<Ctx, BytesId>
where Self: WithShared<'s, 'ctx, 'str>,

Source

pub fn data(&'s self) -> &'ctx [u8]

The raw bytes in target memory order.

Source

pub fn type_id(&'s self) -> TypeId

Returns the TypeId of this blob.

Source§

impl<'str, 'ctx> BaseRef<&'ctx mut Context<'str>, FunctionId>

Source

pub fn as_ref(&self) -> FunctionRef<'str, '_>

Source

pub fn name(&self) -> &str

Source

pub fn blocks(&self) -> impl Iterator<Item = BlockRef<'str, '_>>

Source

pub fn root(&self) -> Option<BlockRef<'str, '_>>

Source

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.

Source

pub fn make_root(&mut self) -> BlockRef<'str, '_>

Source

pub fn ensure_root(&mut self, id: BlockId) -> Result<()>

Source

pub fn set_external(&mut self, is_external: bool)

Source

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.

Source

pub fn set_kind(&mut self, kind: FunctionKind)

Source

pub fn set_signature(&mut self, sig: FunctionSignature)

Source

pub fn set_param_attrs(&mut self, attrs: Vec<ParamAttrs>)

Records the inferred per-parameter pointer attributes on this function. See FunctionSignature::param_attrs.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn add_instruction_addr(&mut self, addr: u64)

Records the address of a machine instruction lifted into this function.

Source

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>

Source

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

pub fn rename_local(&mut self, name: Cow<'str, str>) -> Result<()>

Renames this instruction in its owning function’s local name table (own-instruction edit, host-routed). Errors only on a duplicate name.

Source§

impl<'str, 'ctx> BaseRef<&'ctx mut Context<'str>, InstructionId>

Source

pub fn as_ref(&self) -> InstructionRef<'str, '_>

Source

pub fn inner_mut(&mut self) -> &mut Instruction<'str>

Source

pub fn mnemonic_mut(&mut self) -> &mut Mnemonic

Source

pub fn set_mnemonic(&mut self, mnemonic: Mnemonic)

Replace this instruction’s mnemonic while keeping the reverse use-def map in sync.

Source

pub fn address_mut(&mut self) -> &mut Option<u64>

Source

pub fn set_address(&mut self, address: u64)

Source

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).

Source

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.

Source

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>,

Source

pub fn mask(&'s self) -> u64

Source

pub fn value(&'s self) -> u64

Source

pub fn type_id(&'s self) -> TypeId

Returns the TypeId of this literal.

Source§

impl<'s, 'ctx: 's, 'str: 'ctx, Ctx> BaseRef<Ctx, PoisonId>
where Self: WithShared<'s, 'ctx, 'str>,

Source

pub fn type_id(&'s self) -> TypeId

Returns the TypeId of this poison value.

Source§

impl<Ctx, Id: Copy> BaseRef<Ctx, Id>

Source

pub fn new(ctx: Ctx, id: Id) -> Self

Source§

impl<Ctx, Id: Copy + Into<ValueId>> BaseRef<Ctx, Id>

Source

pub fn id(&self) -> ValueId

Source§

impl<'str, 'ctx, Id: Copy> BaseRef<&'ctx Context<'str>, Id>

Source

pub fn from_id(ctx: &'ctx Context<'str>, id: Id) -> Self

Source§

impl<'a, 'str, Id: Copy> BaseRef<&'a Shared<'str>, Id>

Construct a shared-leaf wrapper ref (literal, bytes, varnode) over the module’s Shared IR state, taking either a &Context or a &Shared (via AsShared) so module- and pass-scope callers share one spelling (context-split stage 5b-ii item #1).

Source

pub fn from_id(src: impl AsShared<'a, 'str>, id: Id) -> Self

Source§

impl<'str, 'ctx, Id: Copy> BaseRef<&'ctx mut Context<'str>, Id>

Source

pub fn from_id(ctx: &'ctx mut Context<'str>, id: Id) -> Self

Source§

impl<'s, 'ctx: 's, 'str: 'ctx, Ctx> BaseRef<Ctx, VarnodeId>
where Self: WithShared<'s, 'ctx, 'str>,

Source

pub fn space(&'s self) -> SpaceRef<'ctx>

The space this varnode belongs to.

Source

pub fn address(&'s self) -> i64

The address at which this varnode begins

Source

pub fn size(&'s self) -> usize

The number of bytes in this varnode’s range

Source

pub fn name(&'s self) -> Option<&'ctx str>

An optional name for this varnode, used for debugging and display purposes. The name of a varnode is guaranteed to be unique within the context, and renaming a varnode will update the context’s name registry to maintain this invariant.

Source

pub fn label(&'s self) -> Option<u32>

The integer label of a generated temporary, if any. Temporaries derive their display name (v{label}) from this without an allocation.

Source§

impl<'str, 'ctx> BaseRef<&'ctx mut Context<'str>, VarnodeId>

Source

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§

impl<'str, 'ctx, R> From<BaseRef<&'ctx Shared<'str>, BytesId>> for ValueRef<'str, 'ctx, R>

Source§

fn from(bytes_ref: BytesRef<'str, 'ctx>) -> Self

Converts to this type from the input type.
Source§

impl<'str, 'ctx, R> From<BaseRef<&'ctx Shared<'str>, LiteralId>> for ValueRef<'str, 'ctx, R>

Source§

fn from(lit_ref: LiteralRef<'str, 'ctx>) -> Self

Converts to this type from the input type.
Source§

impl<'str, 'ctx, R> From<BaseRef<&'ctx Shared<'str>, PoisonId>> for ValueRef<'str, 'ctx, R>

Source§

fn from(poison_ref: PoisonRef<'str, 'ctx>) -> Self

Converts to this type from the input type.
Source§

impl<'str, 'ctx, R> From<BaseRef<&'ctx Shared<'str>, VarnodeId>> for ValueRef<'str, 'ctx, R>

Source§

fn from(var_ref: VarnodeRef<'str, 'ctx>) -> Self

Converts to this type from the input type.
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.

Source§

fn from(r: BaseRef<&'ctx mut Context<'str>, Id>) -> Self

Converts to this type from the input type.
Source§

impl<'a, 'str> Named for BaseRef<BodyMut<'a, 'str>, BlockId>

Source§

fn name(&self) -> Option<&str>

Source§

impl<'str, 'ctx, H: QCodeMut<'str>> Renameable<'str, 'ctx> for BaseRef<H, BlockId>
where Self: Named,

Source§

fn rename(&mut self, name: Cow<'str, str>) -> Result<()>

Source§

fn with_name(self, name: Cow<'str, str>) -> Result<Self>
where Self: Sized,

Source§

impl<'str, 'ctx, H: QCodeMut<'str>> Renameable<'str, 'ctx> for BaseRef<H, BlockParamId>
where Self: Named,

Source§

fn rename(&mut self, name: Cow<'str, str>) -> Result<()>

Source§

fn with_name(self, name: Cow<'str, str>) -> Result<Self>
where Self: Sized,

Source§

impl<'str, 'ctx, H: QCodeMut<'str>> Renameable<'str, 'ctx> for BaseRef<H, InstructionId>
where Self: Named,

Source§

fn rename(&mut self, name: Cow<'str, str>) -> Result<()>

Source§

fn with_name(self, name: Cow<'str, str>) -> Result<Self>
where Self: Sized,

Source§

impl<'s, 'str> WithCtx<'s, 's, 'str> for BaseRef<&mut Context<'str>, BlockId>
where 'str: 's,

Source§

fn ctx(&'s self) -> &'s Context<'str>

Auto Trait Implementations§

§

impl<Ctx, Id> Freeze for BaseRef<Ctx, Id>
where Id: Freeze, Ctx: Freeze,

§

impl<Ctx, Id> RefUnwindSafe for BaseRef<Ctx, Id>
where Id: RefUnwindSafe, Ctx: RefUnwindSafe,

§

impl<Ctx, Id> Send for BaseRef<Ctx, Id>
where Id: Send, Ctx: Send,

§

impl<Ctx, Id> Sync for BaseRef<Ctx, Id>
where Id: Sync, Ctx: Sync,

§

impl<Ctx, Id> Unpin for BaseRef<Ctx, Id>
where Id: Unpin, Ctx: Unpin,

§

impl<Ctx, Id> UnsafeUnpin for BaseRef<Ctx, Id>
where Id: UnsafeUnpin, Ctx: UnsafeUnpin,

§

impl<Ctx, Id> UnwindSafe for BaseRef<Ctx, Id>
where Id: UnwindSafe, Ctx: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.