本文整理汇总了C#中Mono.Cecil.Cil.Instruction类的典型用法代码示例。如果您正苦于以下问题:C# Instruction类的具体用法?C# Instruction怎么用?C# Instruction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Instruction类属于Mono.Cecil.Cil命名空间,在下文中一共展示了Instruction类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ReadOperand
public object ReadOperand(Instruction instruction)
{
while (instruction.Operand is Instruction)
instruction = (Instruction)instruction.Operand;
return instruction.Operand;
}
开发者ID:pluraldj,项目名称:SharpDevelop,代码行数:7,代码来源:ILAnalyzer.cs
示例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;
}
开发者ID:Galigator,项目名称:db4o,代码行数:7,代码来源:StackAnalyzerTestCase.Helper.cs
示例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);
}
开发者ID:stschake,项目名称:obfuscatus,代码行数:7,代码来源:Extensions.cs
示例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;
}
开发者ID:rfcclub,项目名称:dot42,代码行数:34,代码来源:Instructions.cs
示例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;
}
开发者ID:Galigator,项目名称:db4o,代码行数:7,代码来源:StackAnalyzerTestCase.Helper.cs
示例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);
}
}
开发者ID:OliverHallam,项目名称:Illustrious,代码行数:40,代码来源:InlineFunctionCall.cs
示例7: CompiledString
public CompiledString(MethodDefinition method, Instruction instruction)
{
Method = method;
Instruction = instruction;
OriginalValue = Value;
}
开发者ID:Xcelled,项目名称:net-string-editor,代码行数:7,代码来源:CompiledString.cs
示例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;
}
}
开发者ID:Jonesey13,项目名称:TF-8-Player,代码行数:7,代码来源:VersusRoundResults.cs
示例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;
}
开发者ID:cessationoftime,项目名称:nroles,代码行数:7,代码来源:RoleComposer.Initialization.cs
示例10: StackAnalysisResult
public StackAnalysisResult(Instruction consumer, int offset, bool match, int stackHeight)
{
_consumer = consumer;
_offset = offset;
_match = match;
_stackHeight = stackHeight;
}
开发者ID:superyfwy,项目名称:db4o,代码行数:7,代码来源:StackAnalysisResult.cs
示例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));
}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:8,代码来源:Pattern.cs
示例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;
}
开发者ID:Robby777,项目名称:ambientsmell,代码行数:7,代码来源:InstructionInfo.cs
示例14: _Pops
protected override int _Pops(Instruction i, int stackSize)
{
// Check i.Operand?
if (stackSize == 1)
return 1;
return 0;
}
开发者ID:Robby777,项目名称:ambientsmell,代码行数:7,代码来源:InstructionInfo.cs
示例15: IsFloatingPointArguments
static bool IsFloatingPointArguments (Instruction ins, MethodDefinition method)
{
TypeReference tr = ins.GetOperandType (method);
if (tr == null)
return false;
return tr.IsFloatingPoint ();
}
开发者ID:FreeBSD-DotNet,项目名称:mono-tools,代码行数:7,代码来源:ReviewCastOnIntegerMultiplicationRule.cs
示例16: ReplaceTransfer
/// <summary>
/// Replaces instruction references (ie if, try) to a new instruction target.
/// This is useful if you are injecting new code before a section of code that is already
/// the receiver of a try/if block.
/// </summary>
/// <param name="current">The original instruction</param>
/// <param name="newTarget">The new instruction that will receive the transfer</param>
/// <param name="originalMethod">The original method that is used to search for transfers</param>
public static void ReplaceTransfer(this Instruction current, Instruction newTarget, MethodDefinition originalMethod)
{
//If a method has a body then check the instruction targets & exceptions
if (originalMethod.HasBody)
{
//Replaces instruction references from the old instruction to the new instruction
foreach (var ins in originalMethod.Body.Instructions.Where(x => x.Operand == current))
ins.Operand = newTarget;
//If there are exception handlers, it's possible that they will also need to be switched over
if (originalMethod.Body.HasExceptionHandlers)
{
foreach (var handler in originalMethod.Body.ExceptionHandlers)
{
if (handler.FilterStart == current) handler.FilterStart = newTarget;
if (handler.HandlerEnd == current) handler.HandlerEnd = newTarget;
if (handler.HandlerStart == current) handler.HandlerStart = newTarget;
if (handler.TryEnd == current) handler.TryEnd = newTarget;
if (handler.TryStart == current) handler.TryStart = newTarget;
}
}
//Update the new target to take the old targets place
newTarget.Offset = current.Offset;
newTarget.SequencePoint = current.SequencePoint;
newTarget.Offset++; //TODO: spend some time to figure out why this is incrementing
}
}
开发者ID:DeathCradle,项目名称:Open-Terraria-API,代码行数:36,代码来源:Wrapping.cs
示例17: NextInstructions
private static IEnumerable<Instruction> NextInstructions(Instruction v)
{
var fc = v.OpCode.FlowControl;
switch (fc)
{
case FlowControl.Next:
case FlowControl.Call: // stay within the method
yield return v.Next;
break;
case FlowControl.Return:
yield break;
case FlowControl.Cond_Branch:
yield return v.Next;
if (v.Operand is Instruction[])
{
// switch statement
foreach (var i in (Instruction[])v.Operand)
yield return i;
}
else
yield return (Instruction)v.Operand;
break;
case FlowControl.Branch:
yield return (Instruction)v.Operand;
break;
default:
throw new NotImplementedException(fc.ToString());
}
}
开发者ID:provegard,项目名称:testness,代码行数:33,代码来源:InstructionGraph.cs
示例18: SwitchRunnable
public SwitchRunnable(BlockDecomposer block, IList<int> cyclomaticComplexity, Instruction defaultCase, params Instruction[] cases)
{
this.block = block;
this.cyclomaticComplexity = cyclomaticComplexity;
this.defaultCase = defaultCase;
this.cases = cases;
}
开发者ID:dbremner,项目名称:dotnet-testability-explorer,代码行数:7,代码来源:SwitchRunnable.cs
示例19: Append
public void Append(Instruction instruction)
{
if (instruction == null)
throw new ArgumentNullException ("instruction");
instructions.Add (instruction);
}
开发者ID:n017,项目名称:Confuser,代码行数:7,代码来源:ILProcessor.cs
示例20: Dispatch
public static void Dispatch (Instruction instruction, IInstructionVisitor visitor)
{
switch (instruction.OpCode.Code) {
<%
for instr in Instructions:
for opcode in instr.OpCodes:
%> case Code.${opcode}:
开发者ID:transformersprimeabcxyz,项目名称:cecil-old,代码行数:7,代码来源:InstructionDispatcher.cs
注:本文中的Mono.Cecil.Cil.Instruction类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论