本文整理汇总了C#中ILExpression类的典型用法代码示例。如果您正苦于以下问题:C# ILExpression类的具体用法?C# ILExpression怎么用?C# ILExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ILExpression类属于命名空间,在下文中一共展示了ILExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Match
public virtual bool Match(PatternMatcher pm, ILExpression e)
{
if (e.Arguments.Count != this.Arguments.Length || e.Prefixes != null) return false;
for (int i = 0; i < this.Arguments.Length; i++)
if (!this.Arguments[i].Match(pm, e.Arguments[i])) return false;
return true;
}
开发者ID:GreenDamTan,项目名称:dnSpy,代码行数:7,代码来源:LiftedOperators.cs
示例2: HandleDecimalConstants
static ILExpression HandleDecimalConstants(ILExpression expr)
{
if (expr.Code == ILCode.Newobj) {
MethodReference r = (MethodReference)expr.Operand;
if (r.DeclaringType.Name == "Decimal" && r.DeclaringType.Namespace == "System") {
if (expr.Arguments.Count == 1) {
int? val = GetI4Constant(expr.Arguments[0]);
if (val != null) {
expr.Arguments.Clear();
expr.Code = ILCode.Ldc_Decimal;
expr.Operand = new decimal(val.Value);
expr.InferredType = r.DeclaringType;
}
} else if (expr.Arguments.Count == 5) {
int? lo = GetI4Constant(expr.Arguments[0]);
int? mid = GetI4Constant(expr.Arguments[1]);
int? hi = GetI4Constant(expr.Arguments[2]);
int? isNegative = GetI4Constant(expr.Arguments[3]);
int? scale = GetI4Constant(expr.Arguments[4]);
if (lo != null && mid != null && hi != null && isNegative != null && scale != null) {
expr.Arguments.Clear();
expr.Code = ILCode.Ldc_Decimal;
expr.Operand = new decimal(lo.Value, mid.Value, hi.Value, isNegative.Value != 0, (byte)scale);
expr.InferredType = r.DeclaringType;
}
}
}
}
return expr;
}
开发者ID:hlesesne,项目名称:ILSpy,代码行数:30,代码来源:PeepholeTransform.cs
示例3: VisitExpression
protected override ILExpression VisitExpression(ILExpression expression)
{
if (expression.Code == ILCode.Stloc)
{
var variable = (ILVariable)expression.Operand;
if (variable.Type.HasInterface("System.IDisposable"))
{
var key = Tuple.Create(variable, currentScope);
if (starts.Keys.Any(k => k.Item1 == variable && k.Item2 != currentScope))
{
LogTo.Warning("Method {0}: Using cannot be added because reassigning a variable in a condition is not supported.", method);
}
else
{
if (starts.ContainsKey(key))
{
UsingRanges.Add(new ILRange { From = starts[key], To = expression.FirstILOffset() });
starts.Remove(key);
}
if (!currentTrys.Contains(expression.LastILOffset()))
starts.Add(key, expression.LastILOffset());
}
}
}
if (expression.Code == ILCode.Ret && currentScope > 1)
{
EarlyReturns.Add(expression.FirstILOffset());
}
return base.VisitExpression(expression);
}
开发者ID:ropean,项目名称:Usable,代码行数:34,代码来源:UsableVisitor.cs
示例4: TransformDecimalCtorToConstant
static bool TransformDecimalCtorToConstant(ILExpression expr)
{
IMethod r;
List<ILExpression> args;
if (expr.Match(ILCode.Newobj, out r, out args) &&
r.DeclaringType.Namespace == "System" &&
r.DeclaringType.Name == "Decimal")
{
if (args.Count == 1) {
int val;
if (args[0].Match(ILCode.Ldc_I4, out val)) {
expr.Code = ILCode.Ldc_Decimal;
expr.Operand = new decimal(val);
expr.InferredType = r.DeclaringType.ToTypeSig();
expr.Arguments.Clear();
return true;
}
} else if (args.Count == 5) {
int lo, mid, hi, isNegative, scale;
if (expr.Arguments[0].Match(ILCode.Ldc_I4, out lo) &&
expr.Arguments[1].Match(ILCode.Ldc_I4, out mid) &&
expr.Arguments[2].Match(ILCode.Ldc_I4, out hi) &&
expr.Arguments[3].Match(ILCode.Ldc_I4, out isNegative) &&
expr.Arguments[4].Match(ILCode.Ldc_I4, out scale))
{
expr.Code = ILCode.Ldc_Decimal;
expr.Operand = new decimal(lo, mid, hi, isNegative != 0, (byte)scale);
expr.InferredType = r.DeclaringType.ToTypeSig();
expr.Arguments.Clear();
return true;
}
}
}
return false;
}
开发者ID:modulexcite,项目名称:ICSharpCode.Decompiler-retired,代码行数:35,代码来源:PeepholeTransform.cs
示例5: EliminateDups
static ILExpression EliminateDups(ILExpression expr)
{
if (expr.Code == ILCode.Dup)
return expr.Arguments.Single();
else
return expr;
}
开发者ID:hlesesne,项目名称:ILSpy,代码行数:7,代码来源:PeepholeTransform.cs
示例6: TransformArrayInitializers
bool TransformArrayInitializers(List<ILNode> body, ILExpression expr, int pos)
{
ILVariable v, v3;
ILExpression newarrExpr;
TypeReference elementType;
ILExpression lengthExpr;
int arrayLength;
if (expr.Match(ILCode.Stloc, out v, out newarrExpr) &&
newarrExpr.Match(ILCode.Newarr, out elementType, out lengthExpr) &&
lengthExpr.Match(ILCode.Ldc_I4, out arrayLength) &&
arrayLength > 0) {
ILExpression[] newArr;
int initArrayPos;
if (ForwardScanInitializeArrayRuntimeHelper(body, pos + 1, v, elementType, arrayLength, out newArr, out initArrayPos)) {
var arrayType = new ArrayType(
elementType,
new[] { new ArrayDimension(0, arrayLength) });
body[pos] = new ILExpression(ILCode.Stloc, v, new ILExpression(ILCode.InitArray, arrayType, newArr));
body.RemoveAt(initArrayPos);
}
// Put in a limit so that we don't consume too much memory if the code allocates a huge array
// and populates it extremely sparsly. However, 255 "null" elements in a row actually occur in the Mono C# compiler!
const int maxConsecutiveDefaultValueExpressions = 300;
List<ILExpression> operands = new List<ILExpression>();
int numberOfInstructionsToRemove = 0;
for (int j = pos + 1; j < body.Count; j++) {
ILExpression nextExpr = body[j] as ILExpression;
int arrayPos;
if (nextExpr != null &&
nextExpr.Code.IsStoreToArray() &&
nextExpr.Arguments[0].Match(ILCode.Ldloc, out v3) &&
v == v3 &&
nextExpr.Arguments[1].Match(ILCode.Ldc_I4, out arrayPos) &&
arrayPos >= operands.Count &&
arrayPos <= operands.Count + maxConsecutiveDefaultValueExpressions) {
while (operands.Count < arrayPos)
operands.Add(new ILExpression(ILCode.DefaultValue, elementType));
operands.Add(nextExpr.Arguments[2]);
numberOfInstructionsToRemove++;
} else {
break;
}
}
if (operands.Count == arrayLength) {
var arrayType = new ArrayType(
elementType,
new[] { new ArrayDimension(0, arrayLength) });
expr.Arguments[0] = new ILExpression(ILCode.InitArray, arrayType, operands);
body.RemoveRange(pos + 1, numberOfInstructionsToRemove);
new ILInlining(method).InlineIfPossible(body, ref pos);
return true;
}
}
return false;
}
开发者ID:BGCX261,项目名称:zoom-decompiler-hg-to-git,代码行数:60,代码来源:InitializerPeepholeTransforms.cs
示例7: CreateLabeledExpression
protected ILExpression CreateLabeledExpression(GMCode code)
{
int absolute = GMCodeUtil.getBranchOffset(CurrentRaw) + CurrentPC;
ILExpression e = new ILExpression(code, GetLabel(absolute));
e.Extra = (int)(CurrentRaw & 0xFFFF);
e.ILRanges.Add(new ILRange(CurrentPC, CurrentPC));
return e;
}
开发者ID:WarlockD,项目名称:GMdsam,代码行数:8,代码来源:IBuildAst.cs
示例8: SimplifyLiftedOperators
public bool SimplifyLiftedOperators(ILExpression expr)
{
if (Simplify(expr)) return true;
bool modified = false;
foreach (var a in expr.Arguments)
modified |= SimplifyLiftedOperators(a);
return modified;
}
开发者ID:GreenDamTan,项目名称:dnSpy,代码行数:9,代码来源:LiftedOperators.cs
示例9: AnalyzeInstructions
/// <summary>
/// Finds individual instructions within the block that represent higher level concepts related to dynamic call sites.
/// This enables FindDynamicCallSites to locate and transform call sites in a single pass.
/// </summary>
public bool AnalyzeInstructions(List<ILNode> body, ILExpression expr, int pos) {
bool result = false;
var newInstruction = AnalyzeInstruction(expr, ref result);
if (newInstruction != expr)
body[pos] = newInstruction;
return result;
}
开发者ID:sq,项目名称:ILSpy-JSIL,代码行数:13,代码来源:DynamicCallSites.cs
示例10: SimplifyLiftedOperators
bool SimplifyLiftedOperators(List<ILNode> body, ILExpression expr, int pos)
{
if (!new PatternMatcher(typeSystem).SimplifyLiftedOperators(expr)) return false;
var inlining = new ILInlining(method);
while (--pos >= 0 && inlining.InlineIfPossible(body, ref pos)) ;
return true;
}
开发者ID:ropean,项目名称:Usable,代码行数:9,代码来源:LiftedOperators.cs
示例11: Match
public override bool Match(ILNode other)
{
ILExpression expr = other as ILExpression;
if (expr != null && expr.Code == ILCode.Stloc && (!MustBeGenerated || ((ILVariable)expr.Operand).IsGenerated) && Match(this.Arguments, expr.Arguments)) {
this.LastMatch = expr;
return true;
} else {
return false;
}
}
开发者ID:hlesesne,项目名称:ILSpy,代码行数:10,代码来源:Pattern.cs
示例12: TypeConversionSimplifications
static bool TypeConversionSimplifications(List<ILNode> body, ILExpression expr, int pos)
{
bool modified = false;
modified |= TransformDecimalCtorToConstant(expr);
modified |= SimplifyLdcI4ConvI8(expr);
modified |= RemoveConvIFromArrayCreation(expr);
foreach(ILExpression arg in expr.Arguments) {
modified |= TypeConversionSimplifications(null, arg, -1);
}
return modified;
}
开发者ID:modulexcite,项目名称:ICSharpCode.Decompiler-retired,代码行数:11,代码来源:PeepholeTransform.cs
示例13: SimplifyLdcI4ConvI8
static bool SimplifyLdcI4ConvI8(ILExpression expr)
{
ILExpression ldc;
int val;
if (expr.Match(ILCode.Conv_I8, out ldc) && ldc.Match(ILCode.Ldc_I4, out val)) {
expr.Code = ILCode.Ldc_I8;
expr.Operand = (long)val;
expr.Arguments.Clear();
return true;
}
return false;
}
开发者ID:modulexcite,项目名称:ICSharpCode.Decompiler-retired,代码行数:12,代码来源:PeepholeTransform.cs
示例14: SimplifyLdObjAndStObj
static bool SimplifyLdObjAndStObj(List<ILNode> body, ILExpression expr, int pos)
{
bool modified = false;
expr = SimplifyLdObjAndStObj(expr, ref modified);
if (modified && body != null)
body[pos] = expr;
for (int i = 0; i < expr.Arguments.Count; i++) {
expr.Arguments[i] = SimplifyLdObjAndStObj(expr.Arguments[i], ref modified);
modified |= SimplifyLdObjAndStObj(null, expr.Arguments[i], -1);
}
return modified;
}
开发者ID:BGCX261,项目名称:zoom-decompiler-hg-to-git,代码行数:12,代码来源:PeepholeTransform.cs
示例15: ParameterDeclarationAnnotation
public ParameterDeclarationAnnotation(ILExpression expr)
{
Debug.Assert(expr.Code == ILCode.ExpressionTreeParameterDeclarations);
for (int i = 0; i < expr.Arguments.Count - 1; i++) {
ILExpression p = expr.Arguments[i];
// p looks like this:
// stloc(v, call(Expression::Parameter, call(Type::GetTypeFromHandle, ldtoken(...)), ldstr(...)))
ILVariable v = (ILVariable)p.Operand;
TypeReference typeRef = (TypeReference)p.Arguments[0].Arguments[0].Arguments[0].Operand;
string name = (string)p.Arguments[0].Arguments[1].Operand;
Parameters.Add(new ParameterDeclaration(AstBuilder.ConvertType(typeRef), name).WithAnnotation(v));
}
}
开发者ID:ropean,项目名称:Usable,代码行数:13,代码来源:Annotations.cs
示例16: SimplifyLdcI4ConvI8
static bool SimplifyLdcI4ConvI8(ILExpression expr)
{
ILExpression ldc;
int val;
if (expr.Match(ILCode.Conv_I8, out ldc) && ldc.Match(ILCode.Ldc_I4, out val)) {
expr.Code = ILCode.Ldc_I8;
expr.Operand = (long)val;
foreach (var arg in expr.Arguments)
expr.ILRanges.AddRange(arg.GetSelfAndChildrenRecursiveILRanges());
expr.Arguments.Clear();
return true;
}
return false;
}
开发者ID:lovebanyi,项目名称:dnSpy,代码行数:14,代码来源:PeepholeTransform.cs
示例17: InlineIfPossible
/// <summary>
/// Inlines 'expr' into 'next', if possible.
/// </summary>
public static bool InlineIfPossible(ILExpression expr, ILNode next, ILBlock method)
{
if (expr.Code != ILCode.Stloc)
throw new ArgumentException("expr must be stloc");
// ensure the variable is accessed only a single time
if (method.GetSelfAndChildrenRecursive<ILExpression>().Count(e => e != expr && e.Operand == expr.Operand) != 1)
return false;
ILExpression parent;
int pos;
if (FindLoadInNext(next as ILExpression, (ILVariable)expr.Operand, out parent, out pos) == true) {
parent.Arguments[pos] = expr.Arguments[0];
return true;
}
return false;
}
开发者ID:hlesesne,项目名称:ILSpy,代码行数:18,代码来源:ILInlining.cs
示例18: SimplifyLdcI4ConvI8
bool SimplifyLdcI4ConvI8(ILExpression expr)
{
ILExpression ldc;
int val;
if (expr.Match(ILCode.Conv_I8, out ldc) && ldc.Match(ILCode.Ldc_I4, out val)) {
expr.Code = ILCode.Ldc_I8;
expr.Operand = (long)val;
if (context.CalculateILRanges) {
foreach (var arg in expr.Arguments)
arg.AddSelfAndChildrenRecursiveILRanges(expr.ILRanges);
}
expr.Arguments.Clear();
return true;
}
return false;
}
开发者ID:GreenDamTan,项目名称:dnSpy,代码行数:16,代码来源:PeepholeTransform.cs
示例19: CanBeRepresentedAsCompoundAssignment
static bool CanBeRepresentedAsCompoundAssignment(ILExpression expr)
{
switch (expr.Code) {
case ILCode.Add:
case ILCode.Add_Ovf:
case ILCode.Add_Ovf_Un:
case ILCode.Sub:
case ILCode.Sub_Ovf:
case ILCode.Sub_Ovf_Un:
case ILCode.Mul:
case ILCode.Mul_Ovf:
case ILCode.Mul_Ovf_Un:
case ILCode.Div:
case ILCode.Div_Un:
case ILCode.Rem:
case ILCode.Rem_Un:
case ILCode.And:
case ILCode.Or:
case ILCode.Xor:
case ILCode.Shl:
case ILCode.Shr:
case ILCode.Shr_Un:
return true;
case ILCode.Call:
var m = expr.Operand as IMethod;
if (m == null || m.MethodSig == null || m.MethodSig.HasThis || expr.Arguments.Count != 2) return false;
switch (m.Name) {
case "op_Addition":
case "op_Subtraction":
case "op_Multiply":
case "op_Division":
case "op_Modulus":
case "op_BitwiseAnd":
case "op_BitwiseOr":
case "op_ExclusiveOr":
case "op_LeftShift":
case "op_RightShift":
return true;
default:
return false;
}
default:
return false;
}
}
开发者ID:n017,项目名称:dnSpy,代码行数:45,代码来源:PeepholeTransform.cs
示例20: FindLoadInNext
/// <summary>
/// Finds the position to inline to.
/// </summary>
/// <returns>true = found; false = cannot continue search; null = not found</returns>
static bool? FindLoadInNext(ILExpression expr, ILVariable v, out ILExpression parent, out int pos)
{
parent = null;
pos = 0;
if (expr == null)
return false;
for (int i = 0; i < expr.Arguments.Count; i++) {
ILExpression arg = expr.Arguments[i];
if (arg.Code == ILCode.Ldloc && arg.Operand == v) {
parent = expr;
pos = i;
return true;
}
bool? r = FindLoadInNext(arg, v, out parent, out pos);
if (r != null)
return r;
}
return IsWithoutSideEffects(expr.Code) ? (bool?)null : false;
}
开发者ID:hlesesne,项目名称:ILSpy,代码行数:23,代码来源:ILInlining.cs
注:本文中的ILExpression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论