本文整理汇总了C#中InstructionBlock类的典型用法代码示例。如果您正苦于以下问题:C# InstructionBlock类的具体用法?C# InstructionBlock怎么用?C# InstructionBlock使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InstructionBlock类属于命名空间,在下文中一共展示了InstructionBlock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Weave
/// <summary>
/// Weaves the specified context.
/// </summary>
/// <param name="context">The context.</param>
/// <param name="block">The block.</param>
public void Weave(WeavingContext context, InstructionBlock block)
{
LocalVariableSymbol parameters = block.DefineLocalVariable(context.Method.Module.FindType(typeof(ParameterDictionary), BindingOptions.Default), NameGenerator.Generate("parameters"));
InstructionSequence entrySequence = context.Method.MethodBody.CreateInstructionSequence();
block.AddInstructionSequence(entrySequence, NodePosition.Before, null);
InstructionWriter writer = context.InstructionWriter;
writer.AttachInstructionSequence(entrySequence);
writer.EmitSymbolSequencePoint(SymbolSequencePoint.Hidden);
writer.EmitInstructionMethod(OpCodeNumber.Call, context.Method.Module.FindMethod(typeof(InternalHelperMethods).GetMethod("CreateParameterCollection"), BindingOptions.Default));
IMethod add = context.Method.Module.FindMethod(typeof(ParameterDictionary).GetMethod("Add", new[] { typeof(string), typeof(object) }), BindingOptions.Default);
short parameterIndex = context.Method.IsStatic ? (short)0 : (short)1;
foreach (var parameter in method.Parameters)
{
writer.EmitInstruction(OpCodeNumber.Dup);
writer.EmitInstructionString(OpCodeNumber.Ldstr, new LiteralString(parameter.Name));
writer.EmitInstructionInt16(OpCodeNumber.Ldarg, parameterIndex++);
if (parameter.ParameterType.GetSystemType(null, null).IsValueType)
{
writer.EmitInstructionType(OpCodeNumber.Box, parameter.ParameterType);
}
writer.EmitInstructionMethod(OpCodeNumber.Callvirt, add);
}
writer.EmitInstructionLocalVariable(OpCodeNumber.Stloc, parameters);
writer.DetachInstructionSequence();
}
示例2: LocaVariableSymbolCollectionTreeNode
public LocaVariableSymbolCollectionTreeNode( InstructionBlock block )
: base( TreeViewImage.Folder, null )
{
this.block = block;
this.Text = "Symbols";
this.EnableLatePopulate();
}
示例3: Weave
public void Weave(WeavingContext context, InstructionBlock block)
{
InstructionSequence nextSequence = null;
InstructionSequence sequence = null;
sequence = context.Method.MethodBody.CreateInstructionSequence();
block.AddInstructionSequence(sequence, NodePosition.Before, null);
context.InstructionWriter.AttachInstructionSequence(sequence);
context.InstructionWriter.EmitInstructionParameter(OpCodeNumber.Ldarg, this.paramDef);
context.InstructionWriter.EmitInstructionType(OpCodeNumber.Box, this.paramDef.ParameterType);
context.InstructionWriter.EmitInstruction(OpCodeNumber.Ldnull);
context.InstructionWriter.EmitInstruction(OpCodeNumber.Ceq);
nextSequence = context.Method.MethodBody.CreateInstructionSequence();
context.InstructionWriter.EmitBranchingInstruction(OpCodeNumber.Brfalse_S, nextSequence);
context.InstructionWriter.EmitInstructionString(OpCodeNumber.Ldstr, this.paramDef.Name);
context.InstructionWriter.EmitInstructionMethod(OpCodeNumber.Newobj,
context.Method.Module.FindMethod(
typeof (ArgumentNullException).GetConstructor(
new[] {typeof (string)}),
BindingOptions.Default));
context.InstructionWriter.EmitInstruction(OpCodeNumber.Throw);
context.InstructionWriter.DetachInstructionSequence();
block.AddInstructionSequence(nextSequence, NodePosition.After, sequence);
sequence = nextSequence;
context.InstructionWriter.AttachInstructionSequence(sequence);
context.InstructionWriter.DetachInstructionSequence();
}
示例4: Weave
public void Weave(WeavingContext context, InstructionBlock block)
{
InstructionSequence sequence = context.Method.MethodBody.CreateInstructionSequence();
block.AddInstructionSequence(sequence, NodePosition.After, null);
InstructionWriter writer = context.InstructionWriter;
writer.AttachInstructionSequence(sequence);
context.InstructionWriter.EmitInstructionLocalVariable(OpCodeNumber.Ldloc, context.ReturnValueVariable);
context.InstructionWriter.EmitInstructionType(OpCodeNumber.Box,
context.ReturnValueVariable.LocalVariable.Type);
context.InstructionWriter.EmitInstruction(OpCodeNumber.Ldnull);
context.InstructionWriter.EmitInstruction(OpCodeNumber.Ceq);
InstructionSequence nextSequence = context.Method.MethodBody.CreateInstructionSequence();
context.InstructionWriter.EmitBranchingInstruction(OpCodeNumber.Brfalse_S, nextSequence);
context.InstructionWriter.EmitInstructionString(OpCodeNumber.Ldstr, "return value is null");
context.InstructionWriter.EmitInstructionMethod(OpCodeNumber.Newobj,
context.Method.Module.FindMethod(
typeof (ArgumentNullException).GetConstructor(new[]
{
typeof
(
string
)
}),
BindingOptions.Default));
context.InstructionWriter.EmitInstruction(OpCodeNumber.Throw);
block.AddInstructionSequence(nextSequence, NodePosition.After, sequence);
writer.DetachInstructionSequence();
}
示例5: AddBlock
private static InstructionBlock[] AddBlock(InstructionBlock block, InstructionBlock[] blocks)
{
InstructionBlock[] destinationArray = new InstructionBlock[blocks.Length + 1];
Array.Copy(blocks, destinationArray, blocks.Length);
destinationArray[destinationArray.Length - 1] = block;
return destinationArray;
}
示例6: IsFinallyCheckBlock
/// <summary>
/// Checks whether <paramref name="theBlock"/> is a do-finally-check block.
/// </summary>
/// <remarks>
/// Pattern:
/// (nop) - sequence of nop blocks
/// ldloc* doFinallyVariable
/// brfalse* - branch to endfinally - this check varies between compilers
/// original handler:
/// ...............
/// </remarks>
/// <param name="theBlock"></param>
/// <returns></returns>
protected override bool IsFinallyCheckBlock(InstructionBlock theBlock)
{
Instruction currentInstruction = theBlock.First;
while (currentInstruction.OpCode.Code == Code.Nop)
{
if (currentInstruction == theBlock.Last)
{
return false;
}
currentInstruction = currentInstruction.Next;
}
VariableReference loadedVariable;
if (currentInstruction == theBlock.Last ||
!StateMachineUtilities.TryGetVariableFromInstruction(currentInstruction, methodVariables, out loadedVariable) ||
loadedVariable != doFinallyVariable)
{
return false;
}
currentInstruction = currentInstruction.Next;
if (currentInstruction.OpCode.Code == Code.Brfalse || currentInstruction.OpCode.Code == Code.Brfalse_S)
{
return true;
}
return IsCSharpDebugCheck(theBlock, currentInstruction) || IsVisualBasicDebugCheck(theBlock, currentInstruction);
}
示例7: ControlFlowGraph
public ControlFlowGraph(Mono.Cecil.Cil.MethodBody body, InstructionBlock[] blocks, Dictionary<int, InstructionData> instructionData, List<ExceptionHandlerData> exception_data, HashSet<int> exception_objects_offsets)
{
this.body = body;
this.blocks = blocks;
this.data = instructionData;
this.exception_data = exception_data;
this.exception_objects_offsets = exception_objects_offsets;
}
示例8: ImplementOnEntry
protected override void ImplementOnEntry(InstructionBlock block, InstructionWriter writer)
{
foreach (var implementation in GetOnEntryImplementations()) {
using (var factory = implementation.CreateExport()) {
var instance = factory.Value;
instance.Initialize(Context);
instance.ImplementOnEntry(block, writer);
}
}
}
示例9: SwitchData
public SwitchData(InstructionBlock switchBlock, InstructionBlock defaultCase, IList<InstructionBlock> orderedCases)
{
SwitchBlock = switchBlock;
DefaultCase = defaultCase;
OrderedCasesArray = new InstructionBlock[orderedCases.Count];
for (int i = 0; i < orderedCases.Count; i++)
{
OrderedCasesArray[i] = orderedCases[i];
}
}
示例10: Weave
public void Weave(WeavingContext context, InstructionBlock block)
{
InstructionSequence sequence = null;
sequence = context.Method.MethodBody.CreateInstructionSequence();
block.AddInstructionSequence(sequence, NodePosition.After, null);
context.InstructionWriter.AttachInstructionSequence(sequence);
context.InstructionWriter.EmitInstructionMethod(OpCodeNumber.Call, context.Method.Module.FindMethod(m_type.Methods.GetOneByName("get_Instance").GetReflectionWrapper(new Type[]{},new Type[]{}),BindingOptions.Default));
context.InstructionWriter.DetachInstructionSequence();
}
示例11: MarkBlocksDeadIfNeeded
public static void MarkBlocksDeadIfNeeded(InstructionBlock[] instructionBlocks)
{
if (Enumerable.Count<InstructionBlock>(instructionBlocks) != 1)
{
foreach (InstructionBlock block in instructionBlocks)
{
block.MarkIsDead();
}
instructionBlocks[0].MarkIsAliveRecursive();
}
}
示例12: InstructionBlockTreeNode
public InstructionBlockTreeNode( InstructionBlock block, string name )
: base( TreeViewImage.Namespace, block )
{
this.Text = name + " " + block.ToString();
this.block = block;
if ( this.block.HasChildrenBlocks || this.block.HasExceptionHandlers || this.block.HasLocalVariableSymbols )
{
this.EnableLatePopulate();
}
}
示例13: ControlFlowGraph
public ControlFlowGraph(
MethodBody body,
InstructionBlock[] blocks,
Dictionary<int, InstructionBlock> instructiontoBlockMapping,
Dictionary<InstructionBlock, SwitchData> switchBlocksInformation,
Dictionary<int, Instruction> offsetToInstruction)
{
this.MethodBody = body;
this.Blocks = blocks;
this.InstructionToBlockMapping = instructiontoBlockMapping;
this.SwitchBlocksInformation = switchBlocksInformation;
this.OffsetToInstruction = offsetToInstruction;
}
示例14: AddPropertyGuard
public static void AddPropertyGuard(PropertyDeclaration property, MethodBodyTransformationContext context, InstructionBlock block, InstructionWriter writer)
{
var propertyType = property.PropertyType;
var methodBody = block.MethodBody;
var sequence = block.AddInstructionSequence(null, NodePosition.After, null);
if (sequence == null) return;
var oldValueVariable =
block.DefineLocalVariable(propertyType, string.Format("old{0}Value", property.Name));
var assets = GetTransformationAssets(property.Module);
writer.AttachInstructionSequence(sequence);
var isLocationBinding = CheckIfIsLocationBinding(methodBody,assets);
if (isLocationBinding) {
writer.AssignValue_LocalVariable(oldValueVariable
, () => writer.Call_MethodOnTarget(property.GetGetter()
,
() => {
//Load the instance parameter of the SetValue method
//and convert it to the type
writer.EmitInstruction(OpCodeNumber.Ldarg_1);
//writer.EmitInstructionLoadIndirect(Assets.ObjectTypeSignature);
writer.EmitInstructionType(OpCodeNumber.Ldobj, assets.ObjectTypeSignature);
writer.EmitConvertFromObject(property.Parent);
}
)
);
//On the location binding the value parameter is at psotion 3
writer.EmitInstruction(OpCodeNumber.Ldarg_3);
} else {
writer.AssignValue_LocalVariable(oldValueVariable,
() => writer.Get_PropertyValue(property));
//For a normal property the value parameter is at position 1
writer.EmitInstruction(OpCodeNumber.Ldarg_1);
}
if (propertyType.IsStruct()) {
writer.EmitInstructionType(OpCodeNumber.Box, propertyType);
}
writer.Box_LocalVariableIfNeeded(oldValueVariable);
var isPrimitive = propertyType.IsPrimitive();
if (isPrimitive) {
writer.Compare_Primitives();
} else {
//TODO: Try and use the equality operator when present
writer.Compare_Objects(assets.ObjectEqualsMethod);
}
//writer.Leave_IfTrue(_context.LeaveBranchTarget);
writer.Leave_IfTrue(context.LeaveBranchTarget);
writer.DetachInstructionSequence();
}
开发者ID:DamianReeves,项目名称:PostEdge,代码行数:51,代码来源:EnhancePropertySetterMethodBodyWrappingImplementation.cs
示例15: Weave
public void Weave(WeavingContext context, InstructionBlock block)
{
InstructionSequence entrySequence = context.Method.MethodBody.CreateInstructionSequence();
block.AddInstructionSequence(entrySequence, NodePosition.Before, null);
InstructionWriter writer = context.InstructionWriter;
writer.AttachInstructionSequence(entrySequence);
writer.EmitSymbolSequencePoint(SymbolSequencePoint.Hidden);
Weave(context, writer);
writer.DetachInstructionSequence();
}