public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder) { var amd = stack.QueryAttribute <AsyncMethodDecompiler>(); if (amd != null && amd.ImplStyle == EAsyncImplStyle.FSM) { return(false); } object[] outArgs; object result; stack.TryGetReturnValueSample((MethodInfo)callee, args, out outArgs, out result); var fspec = new FunctionSpec(typeof(Task)) { CILRep = callee }; var fcall = new FunctionCall() { Callee = fspec, Arguments = args.Select(a => a.Expr).ToArray(), ResultType = TypeDescriptor.GetTypeOf(result) }; stack.Push(fcall, result); return(true); }
public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder) { var ufixSample = (UFix)args[0].Sample; var ufixType = args[0].Expr.ResultType; var slvuType = TypeDescriptor.GetTypeOf(ufixSample.SLVValue); object[] outArgs; object rsample; stack.TryGetReturnValueSample((MethodInfo)callee, args, out outArgs, out rsample); if (rsample == null) throw new ArgumentException("Unable to infer result sample"); var sfixSample = (SFix)rsample; var sfixType = TypeDescriptor.GetTypeOf(sfixSample); var slvsType = TypeDescriptor.GetTypeOf(sfixSample.SLVValue); var zlit = LiteralReference.CreateConstant(StdLogic._0); var eargs = args.Select(arg => arg.Expr).ToArray(); var cast1 = IntrinsicFunctions.Cast(eargs, ufixType.CILType, slvuType, true); var cast2 = Expression.Concat(zlit, cast1); var cast3 = IntrinsicFunctions.Cast(new Expression[] { cast2 }, slvsType.CILType, sfixType, true); stack.Push(cast3, rsample); return true; }
public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder) { var amd = stack.QueryAttribute<AsyncMethodDecompiler>(); if (amd != null && amd.ImplStyle == EAsyncImplStyle.FSM) { return false; } object[] outArgs; object result; stack.TryGetReturnValueSample((MethodInfo)callee, args, out outArgs, out result); var fspec = new FunctionSpec(typeof(Task)) { CILRep = callee }; var fcall = new FunctionCall() { Callee = fspec, Arguments = args.Select(a => a.Expr).ToArray(), ResultType = TypeDescriptor.GetTypeOf(result) }; stack.Push(fcall, result); return true; }
public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder) { object[] outArgs; object rsample = null; if (callee is MethodInfo && !callee.HasCustomOrInjectedAttribute<IDoNotCallOnDecompilation>()) { stack.TryGetReturnValueSample((MethodInfo)callee, args, out outArgs, out rsample); } Type returnType; callee.IsFunctionOrCtor(out returnType); TypeDescriptor rtype; if (rsample != null) rtype = TypeDescriptor.GetTypeOf(rsample); else rtype = returnType; IntrinsicFunction ifun; FunctionCall fcall; if (args[1].Variability == EVariability.Constant && args[2].Variability == EVariability.Constant) { // constant arguments case int first = (int)TypeConversions.ConvertValue(args[1].Sample, typeof(int)); int second = (int)TypeConversions.ConvertValue(args[2].Sample, typeof(int)); var range = new Range(first, second, EDimDirection.Downto); ifun = new IntrinsicFunction(IntrinsicFunction.EAction.Slice, range) { MethodModel = callee }; var fspec = new FunctionSpec(rtype) { CILRep = callee, IntrinsicRep = ifun }; fcall = new FunctionCall() { Callee = fspec, Arguments = new Expression[] { args[0].Expr }, ResultType = rtype, SetResultTypeClass = EResultTypeClass.ObjectReference }; } else { ifun = new IntrinsicFunction(IntrinsicFunction.EAction.Slice) { MethodModel = callee }; var fspec = new FunctionSpec(rtype) { CILRep = callee, IntrinsicRep = ifun }; fcall = new FunctionCall() { Callee = fspec, Arguments = args.Select(arg => arg.Expr).ToArray(), ResultType = rtype, SetResultTypeClass = EResultTypeClass.ObjectReference }; } stack.Push(fcall, rsample); return true; }
public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder) { IntrinsicFunction ifun = new IntrinsicFunction(Kind, Parameter) { MethodModel = callee }; int skip = SkipFirstArg ? 1 : 0; Expression[] eargs = args.Skip(skip).Select(arg => arg.Expr).ToArray(); Type returnType; if (!callee.IsFunctionOrCtor(out returnType)) { FunctionSpec fspec = new FunctionSpec(typeof(void)) { CILRep = callee, IntrinsicRep = ifun }; builder.Call(fspec, eargs); } else { object[] outArgs; object rsample = null; if (callee is MethodInfo && !callee.HasCustomOrInjectedAttribute<IDoNotCallOnDecompilation>()) { stack.TryGetReturnValueSample((MethodInfo)callee, args, out outArgs, out rsample); } TypeDescriptor rtype; if (rsample != null) rtype = TypeDescriptor.GetTypeOf(rsample); else rtype = returnType; FunctionSpec fspec = new FunctionSpec(rtype) { CILRep = callee, IntrinsicRep = ifun }; FunctionCall fcall = new FunctionCall() { Callee = fspec, Arguments = eargs, ResultType = rtype, SetResultTypeClass = EResultTypeClass.ObjectReference }; stack.Push(fcall, rsample); } return true; }
public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder) { Type returnType; bool flag = callee.IsFunction(out returnType); Debug.Assert(flag); var atype = args[0].Expr.ResultType.CILType; if (atype.IsPointer) atype = atype.GetElementType(); Debug.Assert(atype.Equals(SourceType)); object[] outArgs; object rsample; stack.TryGetReturnValueSample((MethodInfo)callee, args, out outArgs, out rsample); TypeDescriptor rtype; if (rsample != null) rtype = TypeDescriptor.GetTypeOf(rsample); else rtype = returnType; Debug.Assert(rtype.CILType.Equals(DestType)); Expression[] eargs = args.Select(arg => arg.Expr).ToArray(); var fcall = IntrinsicFunctions.Cast(eargs, SourceType, rtype, Reinterpret); stack.Push(fcall, rsample); return true; }