C# Class PERWAPI.CILInstructions

The IL instructions for a method
Datei anzeigen Open project: xored/f4 Class Usage Examples

Public Properties

Property Type Description
blockStack System.Collections.Stack

Public Methods

Method Description
AddTryBlock ( TryBlock tryBlock ) : void
BindConstant ( string name, object value, Type type ) : ConstantBinding

Bind a constant to the CIL instructions.

BindLocal ( Local local ) : LocalBinding

Bind a local to the CIL instructions.

BindLocal ( string name, int index ) : LocalBinding

Bind a local to the CIL instructions.

Branch ( BranchOp inst, CILLabel lab ) : void

Add a branch instruction

CloseScope ( ) : void

Close the current scope.

CodeLabel ( CILLabel lab ) : void

Add a label to the CIL instructions

EndCatchBlock ( Class exceptType, TryBlock tryBlock ) : void

Mark this position as the end of the last started block and make it a catch block. This catch block is associated with the specified try block.

EndFaultBlock ( TryBlock tryBlock ) : void

Mark this position as the end of the last started block and make it a fault block. This fault block is associated with the specified try block.

EndFilterBlock ( CILLabel filterLab, TryBlock tryBlock ) : void

Mark this position as the end of the last started block and make it a filter block. This filter block is associated with the specified try block. The format is: filterLab: ... ... filterHandler : ... ...

EndFinallyBlock ( TryBlock tryBlock ) : void

Mark this position as the end of the last started block and make it a finally block. This finally block is associated with the specified try block.

EndInsert ( ) : void

Stop inserting instructions into the buffer. Any instructions added after this call will go at the end of the instruction buffer. To be used with StartInsert(). This method cannot be called if not in "insert" mode.

EndInstCounter ( ) : void

Reset the counter for GetNextInstuction to the first instruction. This method cannot be called when in "insert" mode.

EndTryBlock ( ) : TryBlock

Mark this position as the end of the last started block and make it a try block. This try block is added to the current instructions (ie do not need to call AddTryBlock)

FieldInst ( FieldOp inst, Field f ) : void

Add an instruction with a field parameter

GetInstructions ( ) : PERWAPI.CILInstruction[]

Get all the IL instructions. This method cannot be called when in "insert" mode.

GetMaxStackDepthRequired ( ) : int

Returns the maximum stack depth required by these CIL instructions.

GetNextInstruction ( ) : CILInstruction

Get the next instruction in the instruction buffer in sequence. An internal index is kept to keep track of which instruction was the last retrieved by this method. On the first call, the first instruction in the buffer is retrieved. The instruction index may be zeroed using ResetInstCounter(). This method cannot be called when in "insert" mode.

GetPrevInstruction ( ) : CILInstruction

Get the previous instruction in the instruction buffer in sequence. An internal index is kept to keep track of which instruction was the last retrieved by this method. This method cannot be called when in "insert" mode.

InInsertMode ( ) : bool

Check if the buffer is ready for insertion of extra instructions. The buffer only needs to be in insert mode when instructions need to be added to existing instructions, not for addition of instructions to the end of the buffer.

Inst ( Op inst ) : void

Add a simple IL instruction

IntInst ( IntOp inst, int val ) : void

Add an IL instruction with an integer parameter

IntLine ( int num ) : void
IntLine ( int sLin, int sCol, int eLin, int eCol ) : void

CLS compliant version of Line()

Line ( uint num, uint startCol ) : void

Create a new line instruction.

Line ( uint num, uint startCol, uint endCol ) : void

Create a new line instruction.

Line ( uint startNum, uint startCol, uint endNum, uint endCol ) : void

Create a new line instruction.

Line ( uint startNum, uint startCol, uint endNum, uint endCol, SourceFile sFile ) : void

Create a new line instruction.

LoadArg ( int argNo ) : void

Add the instruction to load an argument on TOS. This method selects the correct instruction based on the value of argNo

LoadArgAdr ( int argNo ) : void

Add the instruction to load the address of an argument on TOS. This method selects the correct instruction based on the value of argNo.

LoadLocal ( int locNo ) : void

Add the instruction to load a local on TOS. This method selects the correct instruction based on the value of locNo.

LoadLocalAdr ( int locNo ) : void

Add the instruction to load the address of a local on TOS. This method selects the correct instruction based on the value of locNo.

MethInst ( MethodOp inst, Method m ) : void

Add an instruction with a method parameter

NewCodedLabel ( ) : CILLabel

Create a new label at this position in the code buffer

NewLabel ( ) : CILLabel

Create a new CIL label. To place the label in the CIL instruction stream use CodeLabel.

NumInstructions ( ) : int

The number of instructions currently in the buffer.

OpenScope ( ) : void

Open a new scope.

PushFalse ( ) : void

Add an instruction to push the boolean value false on TOS

PushInt ( int i ) : void

Add an instruction which puts an integer on TOS. This method selects the correct instruction based on the value of the integer.

PushLong ( long l ) : void

Add the instruction to load a long on TOS

PushTrue ( ) : void

Add an instruction to push the boolean value true on TOS

RemoveInstruction ( int pos ) : void

Remove the instruction at a specified position from the buffer. If you remove the "current" instruction (from GetNext or GetPrev) then the "current" instruction becomes the instruction before that in the buffer.

RemoveInstructions ( int startRange, int endRange ) : void

Remove the instructions from position "startRange" to (and including) position "endRange" from the buffer. If the range removed contains the "current" instruction (from GetNext or GetPrev) then the "current" instruction becomes the instruction before startRange in the buffer.

ReplaceInstruction ( int pos ) : void

Replace a single IL instruction at position pos in the buffer with some new instruction(s). This removes the instruction and puts the instruction buffer into "insert" mode at the position of the removed instruction. EndInsert must be called to insert the new instructions. This method cannot be called when in "insert" mode.

ReplaceInstruction ( int from, int to ) : void

Replace a number of IL instructions beginning at position pos in the buffer with some new instruction(s). This removes the instructions and puts the instruction buffer into "insert" mode at the position of the removed instructions. EndInsert must be called to insert the new instructions. The instructions from index "from" up to and including index "to" will be replaced by the new instructions entered. This method cannot be called when in "insert" mode.

ResetInstCounter ( ) : void

Reset the counter for GetNextInstuction to the first instruction. This method cannot be called when in "insert" mode.

SetInstructions ( CILInstruction insts ) : void

Set the instruction to be the new array of instructions, this will replace any existing instructions. This method cannot be called when in "insert" mode.

StartBlock ( ) : void

Mark this position as the start of a new block (try, catch, filter, finally or fault)

StartInsert ( ) : void

This method should only be used to insert instructions into a buffer which already contains some instructions. Start inserting instructions into the instruction buffer ie. set the buffer to "insert" mode. The position of the insertion will be directly after the "current instruction" as used be GetNextInstruction(). The instructions to be inserted are any calls to the instruction specific methods - Inst, TypeInst, MethodInst, etc. This method cannot be called if already in "insert" mode.

StoreArg ( int argNo ) : void

Add the instruction to store to an argument. This method selects the correct instruction based on the value of argNo.

StoreLocal ( int locNo ) : void

Add the instruction to store to a local. This method selects the correct instruction based on the value of locNo.

Switch ( CILLabel labs ) : void

Add a switch instruction

TypeInst ( TypeOp inst, Type aType ) : void

Add an instruction with a type parameter

calli ( CalliSig sig ) : void

Add the calli instruction

emitbyte ( byte bVal ) : void

Add a byte to the CIL instructions (.emitbyte)

ldc_i8 ( long cVal ) : void

Add the load long instruction

ldc_r4 ( float cVal ) : void

Add the load float32 instruction

ldc_r8 ( double cVal ) : void

Add the load float64 instruction

ldstr ( string str ) : void

Add the load string instruction

Private Methods

Method Description
AddEHClause ( EHClause ehc ) : void
AddToBuffer ( CILInstruction inst ) : void
AddToLines ( Line line ) : void
BuildCILInfo ( CILWriter output ) : void
BuildTables ( MetaDataOut md ) : void
CILInstructions ( MethodDef meth ) : System
ChangeRefsToDefs ( ClassDef newType, ClassDef oldTypes ) : void
CheckCode ( uint locSigIx, bool initLocals, int maxStack, MetaDataOut metaData ) : void
GetCodeSize ( ) : uint
GetLabel ( ArrayList labs, uint targetOffset ) : CILLabel
InsertInstructions ( int ix, CILInstruction newInsts, int numNew ) : void
IsEmpty ( ) : bool
IsTerminatingInstruction ( CILInstruction cilInstr ) : bool
SetAndResolveInstructions ( CILInstruction insts ) : void
TraverseMaxDepth ( CodeBlock entryBlock ) : int
UpdateIndexesFrom ( int ix ) : void
Write ( CILWriter output ) : void
Write ( PEWriter output ) : void

Method Details

AddTryBlock() public method

public AddTryBlock ( TryBlock tryBlock ) : void
tryBlock TryBlock
return void

BindConstant() public method

Bind a constant to the CIL instructions.
public BindConstant ( string name, object value, Type type ) : ConstantBinding
name string The name of the constant.
value object The value of the constant.
type Type The type of the constant.
return ConstantBinding

BindLocal() public method

Bind a local to the CIL instructions.
public BindLocal ( Local local ) : LocalBinding
local Local The local variable to load.
return LocalBinding

BindLocal() public method

Bind a local to the CIL instructions.
public BindLocal ( string name, int index ) : LocalBinding
name string The name of the local variable..
index int The index of the local variable.
return LocalBinding

Branch() public method

Add a branch instruction
public Branch ( BranchOp inst, CILLabel lab ) : void
inst BranchOp the branch instruction
lab CILLabel the label that is the target of the branch
return void

CloseScope() public method

Close the current scope.
public CloseScope ( ) : void
return void

CodeLabel() public method

Add a label to the CIL instructions
public CodeLabel ( CILLabel lab ) : void
lab CILLabel the label to be added
return void

EndCatchBlock() public method

Mark this position as the end of the last started block and make it a catch block. This catch block is associated with the specified try block.
public EndCatchBlock ( Class exceptType, TryBlock tryBlock ) : void
exceptType Class the exception type to be caught
tryBlock TryBlock the try block associated with this catch block
return void

EndFaultBlock() public method

Mark this position as the end of the last started block and make it a fault block. This fault block is associated with the specified try block.
public EndFaultBlock ( TryBlock tryBlock ) : void
tryBlock TryBlock the try block associated with this fault block
return void

EndFilterBlock() public method

Mark this position as the end of the last started block and make it a filter block. This filter block is associated with the specified try block. The format is: filterLab: ... ... filterHandler : ... ...
public EndFilterBlock ( CILLabel filterLab, TryBlock tryBlock ) : void
filterLab CILLabel the label where the filter code is
tryBlock TryBlock the try block associated with this filter block
return void

EndFinallyBlock() public method

Mark this position as the end of the last started block and make it a finally block. This finally block is associated with the specified try block.
public EndFinallyBlock ( TryBlock tryBlock ) : void
tryBlock TryBlock the try block associated with this finally block
return void

EndInsert() public method

Stop inserting instructions into the buffer. Any instructions added after this call will go at the end of the instruction buffer. To be used with StartInsert(). This method cannot be called if not in "insert" mode.
public EndInsert ( ) : void
return void

EndInstCounter() public method

Reset the counter for GetNextInstuction to the first instruction. This method cannot be called when in "insert" mode.
public EndInstCounter ( ) : void
return void

EndTryBlock() public method

Mark this position as the end of the last started block and make it a try block. This try block is added to the current instructions (ie do not need to call AddTryBlock)
public EndTryBlock ( ) : TryBlock
return TryBlock

FieldInst() public method

Add an instruction with a field parameter
public FieldInst ( FieldOp inst, Field f ) : void
inst FieldOp the CIL instruction
f Field the field parameter
return void

GetInstructions() public method

Get all the IL instructions. This method cannot be called when in "insert" mode.
public GetInstructions ( ) : PERWAPI.CILInstruction[]
return PERWAPI.CILInstruction[]

GetMaxStackDepthRequired() public method

Returns the maximum stack depth required by these CIL instructions.
public GetMaxStackDepthRequired ( ) : int
return int

GetNextInstruction() public method

Get the next instruction in the instruction buffer in sequence. An internal index is kept to keep track of which instruction was the last retrieved by this method. On the first call, the first instruction in the buffer is retrieved. The instruction index may be zeroed using ResetInstCounter(). This method cannot be called when in "insert" mode.
public GetNextInstruction ( ) : CILInstruction
return CILInstruction

GetPrevInstruction() public method

Get the previous instruction in the instruction buffer in sequence. An internal index is kept to keep track of which instruction was the last retrieved by this method. This method cannot be called when in "insert" mode.
public GetPrevInstruction ( ) : CILInstruction
return CILInstruction

InInsertMode() public method

Check if the buffer is ready for insertion of extra instructions. The buffer only needs to be in insert mode when instructions need to be added to existing instructions, not for addition of instructions to the end of the buffer.
public InInsertMode ( ) : bool
return bool

Inst() public method

Add a simple IL instruction
public Inst ( Op inst ) : void
inst Op the IL instruction
return void

IntInst() public method

Add an IL instruction with an integer parameter
public IntInst ( IntOp inst, int val ) : void
inst IntOp the IL instruction
val int the integer parameter value
return void

IntLine() public method

public IntLine ( int num ) : void
num int
return void

IntLine() public method

CLS compliant version of Line()
public IntLine ( int sLin, int sCol, int eLin, int eCol ) : void
sLin int The start line
sCol int The start column
eLin int The end line
eCol int The end column
return void

Line() public method

Create a new line instruction.
public Line ( uint num, uint startCol ) : void
num uint The line for the given code segment.
startCol uint The starting column for the code segment.
return void

Line() public method

Create a new line instruction.
public Line ( uint num, uint startCol, uint endCol ) : void
num uint The line for the given code segment.
startCol uint The starting column for the code segment.
endCol uint The ending column for the code segment.
return void

Line() public method

Create a new line instruction.
public Line ( uint startNum, uint startCol, uint endNum, uint endCol ) : void
startNum uint The starting line for the code segment.
startCol uint The starting column for the code segment.
endNum uint The ending line for the code segment.
endCol uint The ending column for the code segment.
return void

Line() public method

Create a new line instruction.
public Line ( uint startNum, uint startCol, uint endNum, uint endCol, SourceFile sFile ) : void
startNum uint The starting line for the code segment.
startCol uint The starting column for the code segment.
endNum uint The ending line for the code segment.
endCol uint The ending column for the code segment.
sFile SourceFile The source file for the given code segment.
return void

LoadArg() public method

Add the instruction to load an argument on TOS. This method selects the correct instruction based on the value of argNo
public LoadArg ( int argNo ) : void
argNo int the number of the argument
return void

LoadArgAdr() public method

Add the instruction to load the address of an argument on TOS. This method selects the correct instruction based on the value of argNo.
public LoadArgAdr ( int argNo ) : void
argNo int the number of the argument
return void

LoadLocal() public method

Add the instruction to load a local on TOS. This method selects the correct instruction based on the value of locNo.
public LoadLocal ( int locNo ) : void
locNo int the number of the local to load
return void

LoadLocalAdr() public method

Add the instruction to load the address of a local on TOS. This method selects the correct instruction based on the value of locNo.
public LoadLocalAdr ( int locNo ) : void
locNo int the number of the local
return void

MethInst() public method

Add an instruction with a method parameter
public MethInst ( MethodOp inst, Method m ) : void
inst MethodOp the CIL instruction
m Method the method parameter
return void

NewCodedLabel() public method

Create a new label at this position in the code buffer
public NewCodedLabel ( ) : CILLabel
return CILLabel

NewLabel() public method

Create a new CIL label. To place the label in the CIL instruction stream use CodeLabel.
public NewLabel ( ) : CILLabel
return CILLabel

NumInstructions() public method

The number of instructions currently in the buffer.
public NumInstructions ( ) : int
return int

OpenScope() public method

Open a new scope.
public OpenScope ( ) : void
return void

PushFalse() public method

Add an instruction to push the boolean value false on TOS
public PushFalse ( ) : void
return void

PushInt() public method

Add an instruction which puts an integer on TOS. This method selects the correct instruction based on the value of the integer.
public PushInt ( int i ) : void
i int the integer value
return void

PushLong() public method

Add the instruction to load a long on TOS
public PushLong ( long l ) : void
l long the long value
return void

PushTrue() public method

Add an instruction to push the boolean value true on TOS
public PushTrue ( ) : void
return void

RemoveInstruction() public method

Remove the instruction at a specified position from the buffer. If you remove the "current" instruction (from GetNext or GetPrev) then the "current" instruction becomes the instruction before that in the buffer.
public RemoveInstruction ( int pos ) : void
pos int position of the instruction to be removed
return void

RemoveInstructions() public method

Remove the instructions from position "startRange" to (and including) position "endRange" from the buffer. If the range removed contains the "current" instruction (from GetNext or GetPrev) then the "current" instruction becomes the instruction before startRange in the buffer.
public RemoveInstructions ( int startRange, int endRange ) : void
startRange int
endRange int
return void

ReplaceInstruction() public method

Replace a single IL instruction at position pos in the buffer with some new instruction(s). This removes the instruction and puts the instruction buffer into "insert" mode at the position of the removed instruction. EndInsert must be called to insert the new instructions. This method cannot be called when in "insert" mode.
public ReplaceInstruction ( int pos ) : void
pos int position of the instruction to be replaced
return void

ReplaceInstruction() public method

Replace a number of IL instructions beginning at position pos in the buffer with some new instruction(s). This removes the instructions and puts the instruction buffer into "insert" mode at the position of the removed instructions. EndInsert must be called to insert the new instructions. The instructions from index "from" up to and including index "to" will be replaced by the new instructions entered. This method cannot be called when in "insert" mode.
public ReplaceInstruction ( int from, int to ) : void
from int the index to start replacing instruction from
to int the last index of the instructions to be replaced
return void

ResetInstCounter() public method

Reset the counter for GetNextInstuction to the first instruction. This method cannot be called when in "insert" mode.
public ResetInstCounter ( ) : void
return void

SetInstructions() public method

Set the instruction to be the new array of instructions, this will replace any existing instructions. This method cannot be called when in "insert" mode.
public SetInstructions ( CILInstruction insts ) : void
insts CILInstruction The new instructions
return void

StartBlock() public method

Mark this position as the start of a new block (try, catch, filter, finally or fault)
public StartBlock ( ) : void
return void

StartInsert() public method

This method should only be used to insert instructions into a buffer which already contains some instructions. Start inserting instructions into the instruction buffer ie. set the buffer to "insert" mode. The position of the insertion will be directly after the "current instruction" as used be GetNextInstruction(). The instructions to be inserted are any calls to the instruction specific methods - Inst, TypeInst, MethodInst, etc. This method cannot be called if already in "insert" mode.
public StartInsert ( ) : void
return void

StoreArg() public method

Add the instruction to store to an argument. This method selects the correct instruction based on the value of argNo.
public StoreArg ( int argNo ) : void
argNo int the argument to be stored to
return void

StoreLocal() public method

Add the instruction to store to a local. This method selects the correct instruction based on the value of locNo.
public StoreLocal ( int locNo ) : void
locNo int the local to be stored to
return void

Switch() public method

Add a switch instruction
public Switch ( CILLabel labs ) : void
labs CILLabel the target labels for the switch
return void

TypeInst() public method

Add an instruction with a type parameter
public TypeInst ( TypeOp inst, Type aType ) : void
inst TypeOp the CIL instruction
aType Type the type argument for the CIL instruction
return void

calli() public method

Add the calli instruction
public calli ( CalliSig sig ) : void
sig CalliSig the signature for the calli
return void

emitbyte() public method

Add a byte to the CIL instructions (.emitbyte)
public emitbyte ( byte bVal ) : void
bVal byte
return void

ldc_i8() public method

Add the load long instruction
public ldc_i8 ( long cVal ) : void
cVal long the long value
return void

ldc_r4() public method

Add the load float32 instruction
public ldc_r4 ( float cVal ) : void
cVal float the float value
return void

ldc_r8() public method

Add the load float64 instruction
public ldc_r8 ( double cVal ) : void
cVal double the float value
return void

ldstr() public method

Add the load string instruction
public ldstr ( string str ) : void
str string the string value
return void

Property Details

blockStack public_oe property

public Stack,System.Collections blockStack
return System.Collections.Stack