本文整理汇总了C#中Mono.Cecil.Cil.Instruction类的典型用法代码示例。如果您正苦于以下问题:C# Instruction类的具体用法?C# Instruction怎么用?C# Instruction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Instruction类属于Mono.Cecil.Cil命名空间,在下文中一共展示了Instruction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadOperand
public object ReadOperand(Instruction instruction)
{
while (instruction.Operand is Instruction)
instruction = (Instruction)instruction.Operand;
return instruction.Operand;
}
示例2: IsCastTo
private static bool IsCastTo(TypeDefinition castTarget, Instruction instruction)
{
if (instruction.OpCode != OpCodes.Castclass) return false;
TypeReference typeReference = (TypeReference)instruction.Operand;
return typeReference.Resolve() == castTarget;
}
示例3: InsertFront
public static void InsertFront(this ILProcessor processor, Instruction instr)
{
if (processor.Body.Instructions.Count <= 0)
processor.Append(instr);
else
processor.InsertBefore(processor.Body.Instructions[0], instr);
}
示例4: GetCallArguments
/// <summary>
/// Gets the instructions that generate the arguments for the call in the given instructions.
/// </summary>
public static Instruction[] GetCallArguments(this Instruction call, ILSequence sequence, bool includeThis)
{
var method = (MethodReference)call.Operand;
var count = method.Parameters.Count;
if (includeThis && method.HasThis)
{
count++;
}
var result = new Instruction[count];
var current = call;
var height = count;
for (int i = count - 1; i >= 0; i--)
{
// Look for the starting instruction where stack height is i
while (result[i] == null)
{
var prevIndex = sequence.IndexOf(current);
var prev = (prevIndex >= 1) ? sequence[prevIndex - 1] : null;
if (prev == null)
throw new ArgumentException(string.Format("Cannot find arguments for call to {0}", method));
height -= prev.GetPushDelta();
if (height == i)
result[i] = prev;
height += prev.GetPopDelta(0, true);
current = prev;
}
}
return result;
}
示例5: IsMethodCallOnList
private static bool IsMethodCallOnList(Instruction candidate)
{
if (candidate.OpCode != OpCodes.Call && candidate.OpCode != OpCodes.Callvirt) return false;
MethodDefinition callee = ((MethodReference)candidate.Operand).Resolve();
return callee.DeclaringType.Resolve().FullName == callee.DeclaringType.Module.Import(typeof(List<>)).FullName;
}
示例6: OptimizeInstruction
/// <summary>
/// Performs the optimization starting at the current instruction.
/// </summary>
/// <param name="instruction">The instruction to target.</param>
/// <param name="worker">The worker for optimization actions.</param>
public override void OptimizeInstruction(Instruction instruction, OptimizationWorker worker)
{
// TODO: allow arguments
// TODO: allow return values
// TODO: allow generic methods
// TODO: allow non-static methods
var opCode = instruction.OpCode;
if (opCode.FlowControl != FlowControl.Call)
{
return;
}
var methodRef = (MethodReference) instruction.Operand;
var typeRef = methodRef.DeclaringType;
var module = typeRef.Module;
var type = module.Types[typeRef.FullName];
if (type == null)
{
return;
}
var method = type.Methods.GetMethod(methodRef.Name, methodRef.Parameters);
bool shouldInlineMethod;
if (!this.shouldInline.TryGetValue(method, out shouldInlineMethod))
{
shouldInlineMethod = this.configuration.ShouldInline(method);
this.shouldInline[method] = shouldInlineMethod;
}
if (shouldInlineMethod)
{
InlineMethod(instruction, worker, method);
}
}
示例7: CompiledString
public CompiledString(MethodDefinition method, Instruction instruction)
{
Method = method;
Instruction = instruction;
OriginalValue = Value;
}
示例8: ChangeThreeToSeven
public static void ChangeThreeToSeven(Instruction i)
{
if (i.OpCode.Code == Code.Ldc_I4_3 && i.Previous.OpCode == OpCodes.Stloc_S && i.Next.OpCode == OpCodes.Stloc_S)
{
i.OpCode = OpCodes.Ldc_I4_7;
}
}
示例9: EmitCodeInit
private Instruction EmitCodeInit(TypeReference role, Instruction instructionBeforeInit, ILProcessor il)
{
var current = instructionBeforeInit;
current = InsertAfter(il, current, il.Create(OpCodes.Ldarg_0));
current = InsertAfter(il, current, il.Create(OpCodes.Call, ResolveInitReference(role)));
return current;
}
示例10: StackAnalysisResult
public StackAnalysisResult(Instruction consumer, int offset, bool match, int stackHeight)
{
_consumer = consumer;
_offset = offset;
_match = match;
_stackHeight = stackHeight;
}
示例11: IsCallVirt
// look for a virtual call to a specific method
static bool IsCallVirt (Instruction ins, string typeName, string methodName)
{
if (ins.OpCode.Code != Code.Callvirt)
return false;
MethodReference mr = (ins.Operand as MethodReference);
return ((mr != null) && (mr.Name == methodName) && (mr.DeclaringType.FullName == typeName));
}
示例12: CountElementsInTheStack
private static int CountElementsInTheStack (MethodDefinition method, Instruction start, Instruction end)
{
Instruction current = start;
int counter = 0;
bool newarrDetected = false;
while (end != current) {
if (newarrDetected) {
//Count only the stelem instructions if
//there are a newarr instruction.
if (current.OpCode == OpCodes.Stelem_Ref)
counter++;
}
else {
//Count with the stack
counter += current.GetPushCount ();
counter -= current.GetPopCount (method);
}
//If there are a newarr we need an special
//behaviour
if (current.OpCode == OpCodes.Newarr) {
newarrDetected = true;
counter = 0;
}
current = current.Next;
}
return counter;
}
开发者ID:TheRealDuckboy,项目名称:mono-soc-2008,代码行数:27,代码来源:ProvideCorrectArgumentsToFormattingMethodsRule.cs
示例13: _Pushes
protected override int _Pushes(Instruction i)
{
MethodReference method = (MethodReference)i.Operand;
if (method.ReturnType == null)
return 0;
return 1;
}
示例14: _Pops
protected override int _Pops(Instruction i, int stackSize)
{
// Check i.Operand?
if (stackSize == 1)
return 1;
return 0;
}
示例15: IsFloatingPointArguments
static bool IsFloatingPointArguments (Instruction ins, MethodDefinition method)
{
TypeReference tr = ins.GetOperandType (method);
if (tr == null)
return false;
return tr.IsFloatingPoint ();
}