本文整理汇总了C#中ILExpression类的典型用法代码示例。如果您正苦于以下问题:C# ILExpression类的具体用法?C# ILExpression怎么用?C# ILExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ILExpression类属于命名空间,在下文中一共展示了ILExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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);
}
示例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;
}
示例5: EliminateDups
static ILExpression EliminateDups(ILExpression expr)
{
if (expr.Code == ILCode.Dup)
return expr.Arguments.Single();
else
return expr;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
}