本文整理汇总了C#中Context.AppendInstruction方法的典型用法代码示例。如果您正苦于以下问题:C# Context.AppendInstruction方法的具体用法?C# Context.AppendInstruction怎么用?C# Context.AppendInstruction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Context
的用法示例。
在下文中一共展示了Context.AppendInstruction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
protected override void Run()
{
triggered = false;
// The method declaring type must be a valuetype
if (!MethodCompiler.Type.IsValueType)
return;
// If the method is static, non-virtual or is a constructor then don't process
if (MethodCompiler.Method.IsStatic || !MethodCompiler.Method.IsVirtual || MethodCompiler.Method.Name.Equals(".ctor"))
return;
// If the method does not belong to an interface then don't process
if (!(IsInterfaceMethod() || OverridesMethod()))
return;
// If the method is empty then don't process
if (BasicBlocks.PrologueBlock.NextBlocks.Count == 0 || BasicBlocks.PrologueBlock.NextBlocks[0] == BasicBlocks.EpilogueBlock)
return;
triggered = true;
// Get the this pointer
var thisPtr = MethodCompiler.Parameters[0];
//todo: move this to the end of prologue
var context = new Context(BasicBlocks.PrologueBlock.NextBlocks[0].First);
// Now push the this pointer by two native pointer sizes
var v1 = AllocateVirtualRegister(TypeSystem.BuiltIn.TypedRef);
context.AppendInstruction(IRInstruction.LoadInteger, NativeInstructionSize, v1, StackFrame, thisPtr);
context.AppendInstruction(IRInstruction.AddSigned, NativeInstructionSize, v1, v1, Operand.CreateConstant(TypeSystem.BuiltIn.I4, NativePointerSize * 2));
context.AppendInstruction(IRInstruction.StoreInteger, NativeInstructionSize, null, StackFrame, thisPtr, v1);
}
示例2: TypeInitializerSchedulerStage
/// <summary>
/// Initializes a new instance of the <see cref="TypeInitializerSchedulerStage"/> class.
/// </summary>
public TypeInitializerSchedulerStage()
{
basicBlocks = new BasicBlocks();
// Create the blocks
var prologueBlock = basicBlocks.CreateBlock(BasicBlock.PrologueLabel);
var startBlock = basicBlocks.CreateBlock(BasicBlock.StartLabel);
var epilogueBlock = basicBlocks.CreateBlock(BasicBlock.EpilogueLabel);
// Create the prologue instructions
basicBlocks.AddHeadBlock(prologueBlock);
var prologue = new Context(prologueBlock);
prologue.AppendInstruction(IRInstruction.Prologue);
prologue.Label = -1;
prologue.AppendInstruction(IRInstruction.Jmp, startBlock);
// Create the epilogue instruction
var epilogue = new Context(epilogueBlock);
epilogue.AppendInstruction(IRInstruction.Epilogue);
// create start instructions
start = new Context(startBlock);
start.AppendInstruction(IRInstruction.Jmp, epilogueBlock);
start.GotoPrevious();
}
示例3: InsertBlockProtectInstructions
private void InsertBlockProtectInstructions()
{
foreach (var handler in MethodCompiler.Method.ExceptionHandlers)
{
var tryBlock = BasicBlocks.GetByLabel(handler.TryStart);
var tryHandler = BasicBlocks.GetByLabel(handler.HandlerStart);
var context = new Context(InstructionSet, tryBlock);
while (context.IsEmpty || context.Instruction == IRInstruction.TryStart)
{
context.GotoNext();
}
context.AppendInstruction(IRInstruction.TryStart, tryHandler);
context = new Context(InstructionSet, tryHandler);
if (handler.HandlerType == ExceptionHandlerType.Exception)
{
var exceptionObject = MethodCompiler.CreateVirtualRegister(handler.Type);
context.AppendInstruction(IRInstruction.ExceptionStart, exceptionObject);
}
else if (handler.HandlerType == ExceptionHandlerType.Finally)
{
context.AppendInstruction(IRInstruction.FinallyStart);
}
}
}
示例4: Run
protected override void Run()
{
// The method declaring type must be a valuetype
if (!MethodCompiler.Type.IsValueType)
return;
// The method and method declaring type must not have generic parameters
//if (MethodCompiler.Method.HasOpenGenericParams || MethodCompiler.Method.DeclaringType.HasOpenGenericParams)
// return;
// If the method is static, non-virtual or is a constructor then don't process
if (MethodCompiler.Method.IsStatic || !MethodCompiler.Method.IsVirtual || MethodCompiler.Method.Name.Equals(".ctor"))
return;
// If the method does not belong to an interface then don't process
if (!(IsInterfaceMethod() || OverridesMethod()))
return;
// If the method is empty then don't process
if (BasicBlocks.PrologueBlock.NextBlocks.Count == 0 || BasicBlocks.PrologueBlock.NextBlocks[0] == BasicBlocks.EpilogueBlock)
return;
// Get the this pointer
var thisPtr = MethodCompiler.StackLayout.GetStackParameter(0);
var context = new Context(BasicBlocks.PrologueBlock.NextBlocks[0].First);
// Now push the this pointer by two native pointer sizes
context.AppendInstruction(IRInstruction.AddSigned, thisPtr, thisPtr, Operand.CreateConstant(TypeSystem, NativePointerSize * 2));
}
示例5: Run
protected override void Run()
{
triggered = false;
// The method declaring type must be a valuetype
if (!MethodCompiler.Type.IsValueType)
return;
// If the method is static, non-virtual or is a constructor then don't process
if (MethodCompiler.Method.IsStatic || !MethodCompiler.Method.IsVirtual || MethodCompiler.Method.Name.Equals(".ctor"))
return;
// If the method does not belong to an interface then don't process
if (!(IsInterfaceMethod() || OverridesMethod()))
return;
// If the method is empty then don't process
if (BasicBlocks.PrologueBlock.NextBlocks.Count == 0 || BasicBlocks.PrologueBlock.NextBlocks[0] == BasicBlocks.EpilogueBlock)
return;
triggered = true;
//System.Diagnostics.Debug.WriteLine(this.MethodCompiler.Method.FullName); //temp - remove me
// Get the this pointer
var thisPtr = MethodCompiler.StackLayout.Parameters[0];
var context = new Context(BasicBlocks.PrologueBlock.NextBlocks[0].First);
// Now push the this pointer by two native pointer sizes
context.AppendInstruction(IRInstruction.AddSigned, thisPtr, thisPtr, Operand.CreateConstant(TypeSystem, NativePointerSize * 2));
}
示例6: InsertBlockProtectInstructions
private void InsertBlockProtectInstructions()
{
foreach (var handler in MethodCompiler.Method.ExceptionHandlers)
{
var tryBlock = BasicBlocks.GetByLabel(handler.TryStart);
var tryHandler = BasicBlocks.GetByLabel(handler.HandlerStart);
var context = new Context(tryBlock);
while (context.IsEmpty || context.Instruction == IRInstruction.TryStart)
{
context.GotoNext();
}
context.AppendInstruction(IRInstruction.TryStart, tryHandler);
context = new Context(tryHandler);
if (handler.ExceptionHandlerType == ExceptionHandlerType.Finally)
{
var exceptionObject = AllocateVirtualRegister(exceptionType);
var finallyOperand = AllocateVirtualRegister(TypeSystem.BuiltIn.I4);
context.AppendInstruction2(IRInstruction.FinallyStart, exceptionObject, finallyOperand);
}
}
}
示例7: CollectLocalVariablesFromIL
/// <summary>
/// Runs the specified method compiler.
/// </summary>
void IMethodCompilerStage.Run()
{
if (methodCompiler.PlugSystem != null)
if (methodCompiler.PlugSystem.GetPlugMethod(methodCompiler.Method) != null)
return;
List<StackOperand> locals = CollectLocalVariablesFromIL();
// Iterate and collect locals from all blocks
foreach (BasicBlock block in basicBlocks)
{
CollectLocalVariables(locals, block);
}
// Sort all found locals
OrderVariables(locals, callingConvention);
// Now we assign increasing stack offsets to each variable
localsSize = LayoutVariables(locals, callingConvention, callingConvention.OffsetOfFirstLocal, 1);
// Layout parameters
LayoutParameters(methodCompiler);
// Create a prologue instruction
Context prologueCtx = new Context(instructionSet, basicBlocks.PrologueBlock).InsertBefore();
prologueCtx.SetInstruction(IRInstruction.Prologue);
prologueCtx.Label = -1;
// Create an epilogue instruction
Context epilogueCtx = new Context(instructionSet, basicBlocks.EpilogueBlock);
epilogueCtx.AppendInstruction(IRInstruction.Epilogue);
epilogueCtx.Label = Int32.MaxValue;
}
示例8: TypeInitializerSchedulerStage
/// <summary>
/// Initializes a new instance of the <see cref="TypeInitializerSchedulerStage"/> class.
/// </summary>
public TypeInitializerSchedulerStage()
{
basicBlocks = new BasicBlocks();
instructionSet = new InstructionSet(25);
context = instructionSet.CreateNewBlock(basicBlocks);
basicBlocks.AddHeaderBlock(context.BasicBlock);
context.AppendInstruction(IRInstruction.Prologue);
}
示例9: CreateEmptyBlockContext
/// <summary>
/// Create an empty block.
/// </summary>
/// <param name="label">The label.</param>
/// <returns></returns>
protected Context CreateEmptyBlockContext(int label)
{
Context ctx = new Context(instructionSet);
BasicBlock block = basicBlocks.CreateBlock();
ctx.BasicBlock = block;
// Need a dummy instruction at the start of each block to establish a starting point of the block
ctx.AppendInstruction(null);
ctx.Label = label;
block.Index = ctx.Index;
return ctx;
}
示例10: InsertExceptionStartInstructions
private void InsertExceptionStartInstructions()
{
foreach (var clause in MethodCompiler.Method.ExceptionHandlers)
{
if (clause.HandlerType == ExceptionHandlerType.Exception)
{
var tryHandler = BasicBlocks.GetByLabel(clause.HandlerStart);
var context = new Context(tryHandler);
var exceptionObject = MethodCompiler.CreateVirtualRegister(clause.Type);
context.AppendInstruction(IRInstruction.ExceptionStart, exceptionObject);
}
}
}
示例11: Context
/// <summary>
/// Performs stage specific processing on the compiler context.
/// </summary>
void IMethodCompilerStage.Run()
{
if (methodCompiler.Compiler.PlugSystem.GetPlugMethod(methodCompiler.Method) != null)
return;
if (!methodCompiler.Method.HasCode)
return;
// Create the prologue block
Context context = new Context(instructionSet);
// Add a jump instruction to the first block from the prologue
context.AppendInstruction(IRInstruction.Jmp);
context.SetBranch(0);
context.Label = BasicBlock.PrologueLabel;
prologue = basicBlocks.CreateBlock(BasicBlock.PrologueLabel, context.Index);
basicBlocks.AddHeaderBlock(prologue);
SplitIntoBlocks(0);
// Create the epilogue block
context = new Context(instructionSet);
// Add null instruction, necessary to generate a block index
context.AppendInstruction(null);
context.Label = BasicBlock.EpilogueLabel;
epilogue = basicBlocks.CreateBlock(BasicBlock.EpilogueLabel, context.Index);
// Link all the blocks together
BuildBlockLinks(prologue);
foreach (ExceptionHandlingClause exceptionClause in methodCompiler.ExceptionClauseHeader.Clauses)
{
if (exceptionClause.HandlerOffset != 0)
{
BasicBlock basicBlock = basicBlocks.GetByLabel(exceptionClause.HandlerOffset);
BuildBlockLinks(basicBlock);
basicBlocks.AddHeaderBlock(basicBlock);
}
if (exceptionClause.FilterOffset != 0)
{
BasicBlock basicBlock = basicBlocks.GetByLabel(exceptionClause.FilterOffset);
BuildBlockLinks(basicBlock);
basicBlocks.AddHeaderBlock(basicBlock);
}
}
}
示例12: InsertExceptionStartInstructions
private void InsertExceptionStartInstructions()
{
var objectType = TypeSystem.GetTypeByName("System", "Object");
foreach (var clause in MethodCompiler.Method.ExceptionHandlers)
{
if (clause.ExceptionHandlerType == ExceptionHandlerType.Exception)
{
var handler = BasicBlocks.GetByLabel(clause.HandlerStart);
var exceptionObject = MethodCompiler.CreateVirtualRegister(clause.Type);
var context = new Context(handler);
context.AppendInstruction(IRInstruction.ExceptionStart, exceptionObject);
}
if (clause.ExceptionHandlerType == ExceptionHandlerType.Filter)
{
{
var handler = BasicBlocks.GetByLabel(clause.HandlerStart);
var exceptionObject = MethodCompiler.CreateVirtualRegister(objectType);
var context = new Context(handler);
context.AppendInstruction(IRInstruction.ExceptionStart, exceptionObject);
}
{
var handler = BasicBlocks.GetByLabel(clause.FilterStart.Value);
var exceptionObject = MethodCompiler.CreateVirtualRegister(objectType);
var context = new Context(handler);
context.AppendInstruction(IRInstruction.FilterStart, exceptionObject);
}
}
}
}
示例13: LayoutStackVariables
/// <summary>
/// Runs the specified method compiler.
/// </summary>
void IMethodCompilerStage.Run()
{
if (methodCompiler.Compiler.PlugSystem.GetPlugMethod(methodCompiler.Method) != null)
return;
// Layout stack variables
LayoutStackVariables();
// Layout parameters
LayoutParameters(methodCompiler);
// Create a prologue instruction
Context prologueCtx = new Context(instructionSet, basicBlocks.PrologueBlock).InsertBefore();
prologueCtx.SetInstruction(IRInstruction.Prologue);
prologueCtx.Label = -1;
// Create an epilogue instruction
Context epilogueCtx = new Context(instructionSet, basicBlocks.EpilogueBlock);
epilogueCtx.AppendInstruction(IRInstruction.Epilogue);
epilogueCtx.Label = Int32.MaxValue;
}
示例14: SplitEdge
private void SplitEdge(BasicBlock a, BasicBlock b)
{
// Create new block z
var z = basicBlocks.CreateBlock();
Context ctx = new Context(instructionSet);
ctx.AppendInstruction(IR.IRInstruction.Jmp, a);
ctx.Label = -1;
z.Index = ctx.Index;
// Unlink blocks
a.NextBlocks.Remove(b);
b.PreviousBlocks.Remove(a);
// Link a to z
a.NextBlocks.Add(z);
z.PreviousBlocks.Add(a);
// Link z to b
b.PreviousBlocks.Add(z);
z.NextBlocks.Add(b);
// Insert jump in z to b
ctx.SetInstruction(IRInstruction.Jmp, b);
// Replace any jump/branch target in block a with z
ctx = new Context(instructionSet, a);
ctx.GotoLast();
// Find branch or jump to b and replace it with z
while (ctx.BranchTargets != null)
{
int[] targets = ctx.BranchTargets;
for (int index = 0; index < targets.Length; index++)
{
if (targets[index] == b.Label)
targets[index] = z.Label;
}
ctx.GotoPrevious();
}
}
示例15: Run
protected override void Run()
{
// No stack setup if this is a linker generated method
if (MethodCompiler.Method.DeclaringType.IsLinkerGenerated)
return;
if (IsPlugged)
return;
// Create a prologue instruction
var prologue = new Context(BasicBlocks.PrologueBlock);
prologue.AppendInstruction(IRInstruction.Prologue);
prologue.Label = -1;
if (BasicBlocks.EpilogueBlock != null)
{
// Create an epilogue instruction
var epilogueCtx = new Context(BasicBlocks.EpilogueBlock);
epilogueCtx.AppendInstruction(IRInstruction.Epilogue);
epilogueCtx.Label = BasicBlock.EpilogueLabel;
}
}