Class InstructionSpec

Namespace
AsmLocator
Assembly
AsmLocator.dll

Describes constraints for a CIL instruction. An empty specification matches every instruction and can be used as a one-instruction wildcard inside a pattern.

public sealed record InstructionSpec : IEquatable<InstructionSpec>
Inheritance
InstructionSpec
Implements
Inherited Members

Constructors

InstructionSpec()

public InstructionSpec()

Properties

AnyInstruction

A specification that matches any single instruction, useful as a pattern wildcard.

public static InstructionSpec AnyInstruction { get; }

Property Value

InstructionSpec

Code

The exact CIL opcode code.

public CilCode? Code { get; init; }

Property Value

CilCode?

Mnemonic

The instruction mnemonic matcher, for example call, ldstr, or ldc.i4*.

public StringMatcher? Mnemonic { get; init; }

Property Value

StringMatcher

Offset

The instruction offset to match. Offsets can be stale after edits until offsets are recalculated.

public int? Offset { get; init; }

Property Value

int?

Operand

The operand matcher. Operand values are converted to text by DescribeOperand(CilInstruction). For example, use Console::WriteLine to match a method descriptor.

public StringMatcher? Operand { get; init; }

Property Value

StringMatcher

Where

An optional custom predicate applied after the built-in constraints.

public Func<CilInstruction, bool>? Where { get; init; }

Property Value

Func<CilInstruction, bool>

Methods

Call(StringMatcher)

Matches call and callvirt instructions, but not calli.

public static InstructionSpec Call(StringMatcher method)

Parameters

method StringMatcher

A matcher for the called method's full name.

Returns

InstructionSpec

An instruction specification for direct and virtual method calls.

DescribeOperand(CilInstruction)

Converts common operand types to the textual representation used by Operand matching: member and type descriptors use FullName; strings use their literal value; locals use V_n; parameters use their names; labels use IL_XXXX; switch labels are comma-separated; other values use invariant conversion.

public static string? DescribeOperand(CilInstruction instruction)

Parameters

instruction CilInstruction

The candidate CIL instruction.

Returns

string

The textual operand representation, or null when the instruction has no operand.

Equals(InstructionSpec?)

public bool Equals(InstructionSpec? other)

Parameters

other InstructionSpec

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

GetHashCode()

public override int GetHashCode()

Returns

int

LdStr(StringMatcher)

Matches ldstr instructions whose string operand matches the supplied matcher.

public static InstructionSpec LdStr(StringMatcher text)

Parameters

text StringMatcher

A matcher for the string literal.

Returns

InstructionSpec

The instruction specification.

Matches(CilInstruction)

Returns whether the supplied candidate satisfies all constraints configured in this specification.

public bool Matches(CilInstruction instruction)

Parameters

instruction CilInstruction

The candidate CIL instruction.

Returns

bool

true if every configured constraint is satisfied; otherwise false.

NewObj(StringMatcher)

Matches newobj instructions whose constructor operand matches the supplied matcher.

public static InstructionSpec NewObj(StringMatcher ctor)

Parameters

ctor StringMatcher

A matcher for the constructor descriptor.

Returns

InstructionSpec

The instruction specification.

Op(CilOpCode, StringMatcher?)

Creates an instruction specification for an exact opcode and optional operand matcher.

public static InstructionSpec Op(CilOpCode opCode, StringMatcher? operand = null)

Parameters

opCode CilOpCode

The CIL opcode to match.

operand StringMatcher

An optional matcher for the instruction operand.

Returns

InstructionSpec

A new specification with the described constraints.

ToString()

Returns a readable representation of this object.

public override string ToString()

Returns

string

A readable description.

WithMnemonic(StringMatcher, StringMatcher?)

Creates an instruction specification for a mnemonic and optional operand matcher.

public static InstructionSpec WithMnemonic(StringMatcher mnemonic, StringMatcher? operand = null)

Parameters

mnemonic StringMatcher

The instruction mnemonic matcher.

operand StringMatcher

An optional matcher for the instruction operand.

Returns

InstructionSpec

A new specification with the described constraints.

Operators

operator ==(InstructionSpec?, InstructionSpec?)

public static bool operator ==(InstructionSpec? left, InstructionSpec? right)

Parameters

left InstructionSpec
right InstructionSpec

Returns

bool

operator !=(InstructionSpec?, InstructionSpec?)

public static bool operator !=(InstructionSpec? left, InstructionSpec? right)

Parameters

left InstructionSpec
right InstructionSpec

Returns

bool