Skip to content
Concord

Class CodeInstruction

Namespace
Concord
Assembly
Concord.Emit.dll

One IL instruction in an author-facing transpiler stream. Member names are lowercase to match Harmony so migrating transpiler bodies compile unchanged; do not rename them to house style.

public sealed class CodeInstruction
Inheritance
CodeInstruction
Inherited Members

Constructors

CodeInstruction(CodeInstruction)

Creates a copy of another instruction, including its labels and blocks.

public CodeInstruction(CodeInstruction other)

Parameters

other CodeInstruction

The instruction to copy.

CodeInstruction(OpCode, object?)

Creates an instruction.

public CodeInstruction(OpCode opcode, object? operand = null)

Parameters

opcode OpCode

The opcode.

operand object

The operand, or null when the opcode takes none.

Properties

blocks

The exception-handling boundaries that open or close at this instruction.

public List<ExceptionBlock> blocks { get; }

Property Value

List<ExceptionBlock>

labels

The labels attached to this instruction as a branch target.

public List<Label> labels { get; }

Property Value

List<Label>

opcode

The opcode.

public OpCode opcode { get; set; }

Property Value

OpCode

operand

The operand, or null when the opcode takes none.

public object? operand { get; set; }

Property Value

object

Methods

Calls(MethodInfo)

Tests whether this instruction calls the given method.

public bool Calls(MethodInfo method)

Parameters

method MethodInfo

The method to match.

Returns

bool

true when the instruction calls it.

Remarks

Matches both Call and Callvirt, as Harmony does, so a migrated transpiler body selects the same call sites it selected before.

Exceptions

ArgumentNullException

Thrown when method is null.

Is(OpCode, object?)

Tests whether this instruction has the given opcode and operand.

public bool Is(OpCode match, object? matchOperand)

Parameters

match OpCode

The opcode to match.

matchOperand object

The operand to match, or null to match any operand.

Returns

bool

true when the instruction matches.

Remarks

Numeric operands compare by value across box types, so matching 4 finds an operand boxed as byte, int, or long alike. Short-form opcodes carry a byte operand, and requiring authors to know that is a silent -false trap. Integral and floating-point operands never cross-match.

IsLdarg(int?)

Tests whether this instruction loads an argument, optionally a specific slot.

public bool IsLdarg(int? n = null)

Parameters

n int?

The argument slot to match, or null to match any.

Returns

bool

true when the instruction loads the requested argument.

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

WithLabels(params Label[])

Attaches branch-target labels to this instruction.

public CodeInstruction WithLabels(params Label[] add)

Parameters

add Label[]

The labels to attach.

Returns

CodeInstruction

This instruction, so the call can be chained onto a constructor.

WithLabels(IEnumerable<Label>)

Attaches branch-target labels to this instruction.

public CodeInstruction WithLabels(IEnumerable<Label> add)

Parameters

add IEnumerable<Label>

The labels to attach.

Returns

CodeInstruction

This instruction, so the call can be chained onto a constructor.