本文整理汇总了C#中IRMethod类的典型用法代码示例。如果您正苦于以下问题:C# IRMethod类的具体用法?C# IRMethod怎么用?C# IRMethod使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IRMethod类属于命名空间,在下文中一共展示了IRMethod类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Transform
public override void Transform(IRMethod pMethod)
{
KnownLocalType[] locals = new KnownLocalType[pMethod.Locals.Count];
for (int i = 0; i < pMethod.Instructions.Count; i++)
{
var curInstr = pMethod.Instructions[i];
if (curInstr.Opcode == IROpcode.NewObject && curInstr.Destination.Type == IRLinearizedLocationType.Local)
{
locals[curInstr.Destination.Local.LocalIndex].Known = true;
locals[curInstr.Destination.Local.LocalIndex].Type = ((IRNewObjectInstruction)curInstr).Constructor.ParentType;
}
}
for (int i = 0; i < pMethod.Instructions.Count; i++)
{
var curInstr = pMethod.Instructions[i];
if (curInstr.Opcode == IROpcode.Call)
{
var callInstr = (IRCallInstruction)curInstr;
if (callInstr.Virtual)
{
if (!callInstr.Target.IsVirtual || callInstr.Target.IsFinal || callInstr.Target.ParentType.IsSealed || callInstr.Sources[0].GetTypeOfLocation().IsSealed)
{
callInstr.Virtual = false;
}
else if (callInstr.Sources[0].Type == IRLinearizedLocationType.Local && locals[callInstr.Sources[0].Local.LocalIndex].Known)
{
callInstr.Target = locals[callInstr.Sources[0].Local.LocalIndex].Type.VirtualMethodTree[callInstr.Target.VirtualMethodIndex];
callInstr.Virtual = false;
}
}
}
}
}
示例2: IsSimpleAccessor
private static bool IsSimpleAccessor(IRMethod m, out int retInstrIdx)
{
// TODO: Allow for statics here as well.
return
(retInstrIdx = -1) == -1 &&
m.ReturnType != null &&
m.Parameters.Count == 1 &&
m.Parameters[0].Type == m.ParentType &&
(
(
m.Instructions.Count == 1 &&
m.Instructions[0].Opcode == IROpcode.Return &&
IsSimpleSource(m.Instructions[0].Sources[0]) &&
(retInstrIdx = 0) == 0
) ||
(
m.Instructions.Count == 2 &&
m.Instructions[0].Opcode == IROpcode.Nop &&
m.Instructions[1].Opcode == IROpcode.Return &&
IsSimpleSource(m.Instructions[1].Sources[0]) &&
(retInstrIdx = 1) == 1
)
)
;
}
示例3: IsEmptyConstructor
private static bool IsEmptyConstructor(IRMethod m)
{
return
(
m.Instructions.Count == 3 &&
m.Instructions[0].Opcode == IROpcode.Call &&
IsBaseCallInstruction(m, m.Instructions[0]) &&
IsEmptyConstructor(((IRCallInstruction)m.Instructions[0]).Target) &&
m.Instructions[1].Opcode == IROpcode.Nop &&
m.Instructions[2].Opcode == IROpcode.Return
) ||
(
m.Instructions.Count == 2 &&
(
m.Instructions[0].Opcode == IROpcode.Nop ||
(
m.Instructions[0].Opcode == IROpcode.Call &&
IsBaseCallInstruction(m, m.Instructions[0]) &&
IsEmptyConstructor(((IRCallInstruction)m.Instructions[0]).Target)
)
) &&
m.Instructions[1].Opcode == IROpcode.Return
) ||
(
m.Instructions.Count == 1 &&
m.Instructions[0].Opcode == IROpcode.Return
)
;
}
示例4: Transform
public override void Transform(IRType type)
{
if (!type.IsAbstract && (type.IsGeneric || type.NestedInsideOfType != null || type.IsArrayType || type.IsManagedPointerType || type.IsUnmanagedPointerType))
{
if (type.VirtualMethodTree[3].ParentType != type)
{
// It doesn't already implement ToString() itself.
IRMethod ts = new IRMethod(type.Assembly);
ts.ParentType = type;
ts.ReturnType = type.Assembly.AppDomain.System_String;
ts.Parameters.Add(new IRParameter(type.Assembly) { ParentMethod = ts, Type = type });
ts.VirtualMethodIndex = 3;
var r = new IRReturnInstruction();
r.ParentMethod = ts;
r.Linearized = true;
var loc = new IRLinearizedLocation(r, IRLinearizedLocationType.String);
loc.String.Value = type.ToString();
r.Sources.Add(loc);
ts.Instructions.Add(r);
ts.ParentTypeMethodIndex = type.Methods.Count;
type.Methods.Add(ts);
type.VirtualMethodTree[3] = ts;
if (!ts.Resolved) // This adds it to the Domain's Methods list.
throw new Exception();
}
}
}
示例5: IRLoadRuntimeHandleInstruction
public IRLoadRuntimeHandleInstruction(IRType pTargetType, IRMethod pTargetMethod, IRField pTargetField)
: base(IROpcode.LoadRuntimeHandle)
{
TargetType = pTargetType;
TargetMethod = pTargetMethod;
TargetField = pTargetField;
}
示例6: Transform
public override void Transform(IRMethod method)
{
method.Instructions.ImmediateRetargetModifiedInstructions = false;
for (int i = 0; i < method.Instructions.Count; i++)
{
var curInstr = method.Instructions[i];
switch (curInstr.Opcode)
{
case IROpcode.Unbox:
{
var curUBx = (Instructions.IRUnboxInstruction)curInstr;
if (curUBx.GetValue && !curUBx.Type.IsValueType)
{
var c = new Instructions.IRCastInstruction(curUBx.Type, true);
c.Sources.AddRange(curUBx.Sources);
c.Sources.ForEach(s => s.SetParentInstruction(c));
c.Destination = curUBx.Destination;
c.Destination.SetParentInstruction(c);
method.Instructions[i] = c;
}
break;
}
default:
break;
}
}
method.Instructions.FixModifiedTargetInstructions();
method.Instructions.ImmediateRetargetModifiedInstructions = false;
}
示例7: Run
public override void Run(IRMethod pMethod)
{
bool prevWasKeptNop = false;
pMethod.Instructions.DelayedReIndexOnRemove = true;
for (int i = 0; i < pMethod.Instructions.Count; i++)
{
var curInstr = pMethod.Instructions[i];
if (curInstr.Opcode == IROpcode.Nop)
{
var nop = (IRNopInstruction)curInstr;
if (!nop.ForceEmit || prevWasKeptNop)
{
pMethod.Instructions.Remove(nop);
i--;
}
else
{
prevWasKeptNop = true;
}
}
else
{
prevWasKeptNop = false;
}
}
pMethod.Instructions.FixRemovedTargetInstructions();
pMethod.Instructions.DelayedReIndexOnRemove = false;
}
示例8: Transform
public override void Transform(IRMethod method)
{
foreach (var instr in method.Instructions)
{
instr.Sources.ForEach(s => TransformLocation(s));
if (instr.Destination != null)
TransformLocation(instr.Destination);
}
}
示例9: ResolveSimpleReturn
private static IRType ResolveSimpleReturn(IRType tp, IRMethod target)
{
if (tp.IsTemporaryVar)
return target.ParentType.GenericParameters[tp.TemporaryVarOrMVarIndex];
else if (tp.IsTemporaryMVar)
return target.GenericParameters[tp.TemporaryVarOrMVarIndex];
else if (tp.IsArrayType)
return target.Assembly.AppDomain.GetArrayType(ResolveSimpleReturn(tp.ArrayElementType, target));
else
return tp;
}
示例10: IsBaseCallInstruction
private static bool IsBaseCallInstruction(IRMethod pMethod, IRInstruction instr)
{
if (((IRCallInstruction)instr).Target.ParentType != pMethod.ParentType.BaseType)
{
int i43 = 0;
i43++;
}
return
instr.Sources.Count == 1 &&
instr.Sources[0].Type == IRLinearizedLocationType.Parameter &&
instr.Sources[0].Parameter.ParameterIndex == 0 &&
((IRCallInstruction)instr).Target.ParentType == pMethod.ParentType.BaseType
;
}
示例11: Run
public override void Run(IRMethod pMethod)
{
pMethod.Instructions.ImmediateRetargetModifiedInstructions = false;
for (int i = 0; i < pMethod.Instructions.Count; i++)
{
var curInstr = pMethod.Instructions[i];
if (curInstr.Opcode == IROpcode.Call)
{
var curCall = (IRCallInstruction)curInstr;
int retIdx;
if (!curCall.Virtual && IsSimpleAccessor(curCall.Target, out retIdx))
{
if (curCall.Target.IsStatic)
{
var newMove = new IRMoveInstruction()
{
ParentMethod = pMethod,
};
newMove.Destination = curCall.Destination.Clone(newMove);
var retSrc = curCall.Target.Instructions[retIdx].Sources[0];
newMove.Sources.Add(retSrc.Clone(newMove));
pMethod.Instructions[i] = newMove;
}
else
{
var newMove = new IRMoveInstruction()
{
ParentMethod = pMethod,
};
newMove.Destination = curCall.Destination.Clone(newMove);
var curSrc = curCall.Sources[0];
var retSrc = curCall.Target.Instructions[retIdx].Sources[0];
var paramSrc = new IRLinearizedLocation(newMove, IRLinearizedLocationType.Parameter)
{
Parameter = new IRLinearizedLocation.ParameterLocationData()
{
ParameterIndex = 0,
},
};
var nSrc = retSrc.Clone(newMove);
nSrc.RetargetSource(ref nSrc, paramSrc, curSrc);
newMove.Sources.Add(nSrc);
pMethod.Instructions[i] = newMove;
}
}
}
}
pMethod.Instructions.FixModifiedTargetInstructions();
pMethod.Instructions.ImmediateRetargetModifiedInstructions = true;
}
示例12: Transform
public override void Transform(IRMethod method)
{
if (method.IsInternalCall)
{
IRInstruction added = null;
switch (method.ToString())
{
case "object object::Internal_PointerToReference(void*)":
case "void* object.Internal_ReferenceToPointer(object)":
method.Instructions.Add(
added = new IRReturnInstruction()
{
Sources = new List<IRLinearizedLocation>()
{
new IRLinearizedLocation(null, IRLinearizedLocationType.Parameter)
{
Parameter = new IRLinearizedLocation.ParameterLocationData()
{
ParameterIndex = 0
}
}
}
}
);
added.Sources[0].SetParentInstruction(added);
added.ParentMethod = method;
break;
case "(null) object::Internal_FastCopy(void*, void*, int)":
break;
case "(null) object::Internal_FastZero(void*, int)":
break;
case "(null) string..ctor(string, char[])":
break;
case "(null) string..ctor(string, char, int)":
break;
default:
throw new Exception("Unknown internal call '" + method.ToString() + "'!");
}
}
}
示例13: Run
public override void Run(IRMethod pMethod)
{
if (
pMethod.Name == ".ctor" &&
pMethod.Instructions.Count >= 3 &&
pMethod.ParentType.BaseType != null
)
{
int c = pMethod.Instructions.Count;
int cIdx = -1;
pMethod.Instructions.ImmediateRetargetModifiedInstructions = false;
if (
(
pMethod.Instructions[c - 3].Opcode == IROpcode.Call &&
IsBaseCallInstruction(pMethod, pMethod.Instructions[c - 3]) &&
(cIdx = c - 3) >= 0
) ||
(
pMethod.Instructions[0].Opcode == IROpcode.Call &&
IsBaseCallInstruction(pMethod, pMethod.Instructions[0]) &&
(cIdx = 0) >= 0
) ||
(
pMethod.Instructions[c - 2].Opcode == IROpcode.Call &&
IsBaseCallInstruction(pMethod, pMethod.Instructions[c - 2]) &&
(cIdx = c - 2) >= 0
)
)
{
if (IsEmptyConstructor(((IRCallInstruction)pMethod.Instructions[cIdx]).Target))
{
pMethod.Instructions[cIdx] = new IRNopInstruction();
}
}
pMethod.Instructions.FixModifiedTargetInstructions();
pMethod.Instructions.ImmediateRetargetModifiedInstructions = true;
}
}
示例14: Run
public override void Run(IRMethod pMethod)
{
pMethod.Instructions.ImmediateRetargetModifiedInstructions = false;
for (int i = 0; i < pMethod.Instructions.Count - 1; i++)
{
var curInstr = pMethod.Instructions[i];
if (curInstr.Opcode == IROpcode.Branch)
{
var curBranchInstr = (IRBranchInstruction)curInstr;
if (curBranchInstr.BranchCondition == IRBranchCondition.Always)
{
if (curBranchInstr.TargetIRInstruction.IRIndex == curBranchInstr.IRIndex + 1)
{
pMethod.Instructions[i] = new IRNopInstruction();
}
else if (curBranchInstr.TargetIRInstruction.Opcode == IROpcode.Return)
{
pMethod.Instructions[i] = curBranchInstr.TargetIRInstruction.Clone(pMethod);
}
else if (pMethod.ReturnType != null &&
curBranchInstr.TargetIRInstruction.Opcode == IROpcode.Move &&
curBranchInstr.TargetIRInstruction.Sources[0].Type == IRLinearizedLocationType.Local &&
pMethod.Instructions[curBranchInstr.TargetIRInstruction.IRIndex + 1].Opcode == IROpcode.Return
)
{
var r = pMethod.Instructions[curBranchInstr.TargetIRInstruction.IRIndex + 1].Clone(pMethod);
r.Sources[0] = curBranchInstr.TargetIRInstruction.Sources[0].Clone(r);
pMethod.Instructions[i] = r;
}
}
}
}
pMethod.Instructions.FixModifiedTargetInstructions();
pMethod.Instructions.ImmediateRetargetModifiedInstructions = true;
IRAppDomain.RemoveDeadCode(pMethod);
}
示例15: Clone
public override IRInstruction Clone(IRMethod pNewMethod)
{
IRInstruction[] newTargetIRInstructions = (IRInstruction[])TargetIRInstructions.Clone();
return CopyTo(new IRSwitchInstruction(TargetILOffsets) { TargetIRInstructions = newTargetIRInstructions }, pNewMethod);
}