Back to Harmony

Class CodeInstruction

docs/api/HarmonyLib.CodeInstruction.html

2.4.2.018.6 KB
Original Source

Class CodeInstruction

An abstract wrapper around OpCode and their operands. Used by transpilers

Inheritance

System.Object

CodeInstruction

CodeMatch

Namespace : HarmonyLib
Assembly : 0Harmony.dll
Syntax
public class CodeInstruction

Constructors

CodeInstruction(CodeInstruction)

Create a full copy (including labels and exception blocks) of a CodeInstruction

Declaration
public CodeInstruction(CodeInstruction instruction)
Parameters
TypeNameDescription
CodeInstructioninstruction

The CodeInstruction to copy

|

CodeInstruction(OpCode, Object)

Creates a new CodeInstruction with a given opcode and optional operand

Declaration
public CodeInstruction(OpCode opcode, object operand = null)
Parameters
TypeNameDescription
System.Reflection.Emit.OpCodeopcode

The opcode

| | System.Object | operand |

The operand

|

Fields

blocks

All exception block boundaries defined on this instruction

Declaration
public List<ExceptionBlock> blocks
Field Value
TypeDescription
System.Collections.Generic.List<ExceptionBlock>

labels

All labels defined on this instruction

Declaration
public List<Label> labels
Field Value
TypeDescription
System.Collections.Generic.List\

opcode

The opcode

Declaration
public OpCode opcode
Field Value
TypeDescription
System.Reflection.Emit.OpCode

operand

The operand

Declaration
public object operand
Field Value
TypeDescription
System.Object

Methods

Call(Expression<Action>)

Creates a CodeInstruction calling a method (CALL)

Declaration
public static CodeInstruction Call(Expression<Action> expression)
Parameters
TypeNameDescription
System.Linq.Expressions.Expression\expression

The lambda expression using the method

|

Returns
TypeDescription
CodeInstruction

A new Codeinstruction

|

Call(LambdaExpression)

Creates a CodeInstruction calling a method (CALL)

Declaration
public static CodeInstruction Call(LambdaExpression expression)
Parameters
TypeNameDescription
System.Linq.Expressions.LambdaExpressionexpression

The lambda expression using the method

|

Returns
TypeDescription
CodeInstruction

A new Codeinstruction

|

Call(String, Type[], Type[])

Creates a CodeInstruction calling a method (CALL)

Declaration
public static CodeInstruction Call(string typeColonMethodname, Type[] parameters = null, Type[] generics = null)
Parameters
TypeNameDescription
System.StringtypeColonMethodname

The target method in the form TypeFullName:MethodName, where the type name matches a form recognized by Type.GetType like Some.Namespace.Type.

| | System.Type[] | parameters |

Optional parameters to target a specific overload of the method

| | System.Type[] | generics |

Optional list of types that define the generic version of the method

|

Returns
TypeDescription
CodeInstruction

A code instruction that calls the method matching the arguments

|

Call(Type, String, Type[], Type[])

Creates a CodeInstruction calling a method (CALL)

Declaration
public static CodeInstruction Call(Type type, string name, Type[] parameters = null, Type[] generics = null)
Parameters
TypeNameDescription
System.Typetype

The class/type where the method is declared

| | System.String | name |

The name of the method (case sensitive)

| | System.Type[] | parameters |

Optional parameters to target a specific overload of the method

| | System.Type[] | generics |

Optional list of types that define the generic version of the method

|

Returns
TypeDescription
CodeInstruction

A code instruction that calls the method matching the arguments

|

Call<T>(Expression<Action<T>>)

Creates a CodeInstruction calling a method (CALL)

Declaration
public static CodeInstruction Call<T>(Expression<Action<T>> expression)
Parameters
TypeNameDescription
System.Linq.Expressions.Expression\>expression

The lambda expression using the method

|

Returns
TypeDescription
CodeInstruction

A new Codeinstruction

|

Type Parameters
NameDescription
T

Call<T, TResult>(Expression<Func<T, TResult>>)

Creates a CodeInstruction calling a method (CALL)

Declaration
public static CodeInstruction Call<T, TResult>(Expression<Func<T, TResult>> expression)
Parameters
TypeNameDescription
System.Linq.Expressions.Expression\>expression

The lambda expression using the method

|

Returns
TypeDescription
CodeInstruction

A new Codeinstruction

|

Type Parameters
NameDescription
T
TResult

CallClosure<T>(T)

Returns an instruction to call the specified closure

Declaration
public static CodeInstruction CallClosure<T>(T closure)
    where T : Delegate
Parameters
TypeNameDescription
Tclosure

The closure that defines the method to call

|

Returns
TypeDescription
CodeInstruction

A CodeInstruction that calls the closure as a method

|

Type Parameters
NameDescription
T

The delegate type to emit

|

Clone()

Clones a CodeInstruction and resets its labels and exception blocks

Declaration
public CodeInstruction Clone()
Returns
TypeDescription
CodeInstruction

A lightweight copy of this code instruction

|

Clone(Object)

Clones a CodeInstruction, resets labels and exception blocks and sets its operand

Declaration
public CodeInstruction Clone(object operand)
Parameters
TypeNameDescription
System.Objectoperand

The operand

|

Returns
TypeDescription
CodeInstruction

A copy of this CodeInstruction with a new operand

|

Clone(OpCode)

Clones a CodeInstruction, resets labels and exception blocks and sets its opcode

Declaration
public CodeInstruction Clone(OpCode opcode)
Parameters
TypeNameDescription
System.Reflection.Emit.OpCodeopcode

The opcode

|

Returns
TypeDescription
CodeInstruction

A copy of this CodeInstruction with a new opcode

|

HasBlock(ExceptionBlockType)

Checks if a CodeInstruction contains a given exception block type

Declaration
public bool HasBlock(ExceptionBlockType type)
Parameters
TypeNameDescription
ExceptionBlockTypetype

Type of the exception block to check for

|

Returns
TypeDescription
System.Boolean

True if the instruction contains the exception block type, false otherwise

|

LoadArgument(Int32, Boolean)

Creates a CodeInstruction loading an argument with the given index, using the shorter forms when possible

Declaration
public static CodeInstruction LoadArgument(int index, bool useAddress = false)
Parameters
TypeNameDescription
System.Int32index

The index of the argument

| | System.Boolean | useAddress |

Use address of argument

|

Returns
TypeDescription
CodeInstruction

A new Codeinstruction

|

See Also

ArgumentIndex(CodeInstruction)

LoadField(Type, String, Boolean)

Creates a CodeInstruction loading a field (LD[S]FLD[A])

Declaration
public static CodeInstruction LoadField(Type type, string name, bool useAddress = false)
Parameters
TypeNameDescription
System.Typetype

The class/type where the field is defined

| | System.String | name |

The name of the field (case sensitive)

| | System.Boolean | useAddress |

Use address of field

|

Returns
TypeDescription
CodeInstruction

A new Codeinstruction

|

LoadLocal(Int32, Boolean)

Creates a CodeInstruction loading a local with the given index, using the shorter forms when possible

Declaration
public static CodeInstruction LoadLocal(int index, bool useAddress = false)
Parameters
TypeNameDescription
System.Int32index

The index where the local is stored

| | System.Boolean | useAddress |

Use address of local

|

Returns
TypeDescription
CodeInstruction

A new Codeinstruction

|

See Also

LocalIndex(CodeInstruction)

StoreArgument(Int32)

Creates a CodeInstruction storing to an argument with the given index, using the shorter forms when possible

Declaration
public static CodeInstruction StoreArgument(int index)
Parameters
TypeNameDescription
System.Int32index

The index of the argument

|

Returns
TypeDescription
CodeInstruction

A new Codeinstruction

|

See Also

ArgumentIndex(CodeInstruction)

StoreField(Type, String)

Creates a CodeInstruction storing to a field (ST[S]FLD)

Declaration
public static CodeInstruction StoreField(Type type, string name)
Parameters
TypeNameDescription
System.Typetype

The class/type where the field is defined

| | System.String | name |

The name of the field (case sensitive)

|

Returns
TypeDescription
CodeInstruction

A new Codeinstruction

|

StoreLocal(Int32)

Creates a CodeInstruction storing to a local with the given index, using the shorter forms when possible

Declaration
public static CodeInstruction StoreLocal(int index)
Parameters
TypeNameDescription
System.Int32index

The index where the local is stored

|

Returns
TypeDescription
CodeInstruction

A new Codeinstruction

|

See Also

LocalIndex(CodeInstruction)

ToString()

Returns a string representation of the code instruction

Declaration
public override string ToString()
Returns
TypeDescription
System.String

A string representation of the code instruction

|

Overrides

System.Object.ToString()

Extension Methods

CodeInstructionExtensions.OperandIs(CodeInstruction, Object)

CodeInstructionExtensions.OperandIs(CodeInstruction, MemberInfo)

CodeInstructionExtensions.Is(CodeInstruction, OpCode, Object)

CodeInstructionExtensions.Is(CodeInstruction, OpCode, MemberInfo)

CodeInstructionExtensions.IsLdarg(CodeInstruction, Nullable<Int32>)

CodeInstructionExtensions.IsLdarga(CodeInstruction, Nullable<Int32>)

CodeInstructionExtensions.IsStarg(CodeInstruction, Nullable<Int32>)

CodeInstructionExtensions.IsLdloc(CodeInstruction, LocalBuilder)

CodeInstructionExtensions.IsStloc(CodeInstruction, LocalBuilder)

CodeInstructionExtensions.Branches(CodeInstruction, out Nullable<Label>)

CodeInstructionExtensions.Calls(CodeInstruction, MethodInfo)

CodeInstructionExtensions.LoadsConstant(CodeInstruction)

CodeInstructionExtensions.LoadsConstant(CodeInstruction, Int64)

CodeInstructionExtensions.LoadsConstant(CodeInstruction, Double)

CodeInstructionExtensions.LoadsConstant(CodeInstruction, Enum)

CodeInstructionExtensions.LoadsConstant(CodeInstruction, String)

CodeInstructionExtensions.LoadsField(CodeInstruction, FieldInfo, Boolean)

CodeInstructionExtensions.StoresField(CodeInstruction, FieldInfo)

CodeInstructionExtensions.LocalIndex(CodeInstruction)

CodeInstructionExtensions.ArgumentIndex(CodeInstruction)

CodeInstructionExtensions.WithLabels(CodeInstruction, Label[])

CodeInstructionExtensions.WithLabels(CodeInstruction, IEnumerable<Label>)

CodeInstructionExtensions.ExtractLabels(CodeInstruction)

CodeInstructionExtensions.MoveLabelsTo(CodeInstruction, CodeInstruction)

CodeInstructionExtensions.MoveLabelsFrom(CodeInstruction, CodeInstruction)

CodeInstructionExtensions.WithBlocks(CodeInstruction, ExceptionBlock[])

CodeInstructionExtensions.WithBlocks(CodeInstruction, IEnumerable<ExceptionBlock>)

CodeInstructionExtensions.ExtractBlocks(CodeInstruction)

CodeInstructionExtensions.MoveBlocksTo(CodeInstruction, CodeInstruction)

CodeInstructionExtensions.MoveBlocksFrom(CodeInstruction, CodeInstruction)