private void ProcessLd0(XILSInstr i)
        {
            var targetConst = TypeConversions.ConvertValue(0, i.ResultTypes[0]);

            Emit(new XILSInstr(DefaultInstructionSet.Instance.LdConst(targetConst),
                               RemapPreds(i.Preds),
                               i.OperandTypes, i.ResultTypes));
        }
 private static bool IsMOne(Expression e)
 {
     return(e.IsConst() &&
            object.Equals(
                TypeConversions.ConvertValue(
                    e.Eval(DefaultEvaluator.DefaultConstEvaluator),
                    typeof(double)), -1.0));
 }
        private void ProcessLoadConstant(XILSInstr i)
        {
            var rTypes = i.ResultTypes;

            var constant       = i.StaticOperand;
            var targetConstant = TypeConversions.ConvertValue(constant, rTypes[0]);

            var inew = new XILSInstr(
                DefaultInstructionSet.Instance.LdConst(targetConstant),
                RemapPreds(i.Preds),
                new TypeDescriptor[0],
                rTypes);

            Emit(inew);
        }
Beispiel #4
0
        protected override void ProcessInstruction(XILSInstr i)
        {
            var       otypes = i.OperandTypes.Select(t => t.Equals(GenuineType) ? ReplacementType : t).ToArray();
            var       rtypes = i.ResultTypes.Select(t => t.Equals(GenuineType) ? ReplacementType : t).ToArray();
            XILSInstr inew;

            if (i.Name == InstructionCodes.LdConst &&
                i.StaticOperand != null &&
                i.StaticOperand.GetType().Equals(GenuineType.CILType))
            {
                var cnew = DefaultInstructionSet.Instance.LdConst(TypeConversions.ConvertValue(i.StaticOperand, ReplacementType.CILType));
                inew = cnew.CreateStk(i.Preds, otypes, rtypes);
            }
            else
            {
                inew = i.Command.CreateStk(i.Preds, otypes, rtypes);
            }
            base.ProcessInstruction(inew);
        }
Beispiel #5
0
        public override bool Rewrite(CodeDescriptor decompilee, Expression waitObject, IDecompiler stack, IFunctionBuilder builder)
        {
            if (stack.HasAttribute <Analysis.M2M.HLS>())
            {
                return(true);
            }

            var       curps = DesignContext.Instance.CurrentProcess;
            SLSignal  clk   = (SLSignal)curps.Sensitivity[0].Owner;
            SignalRef srEdge;

            if (curps.Predicate.Equals((Func <bool>)clk.RisingEdge))
            {
                srEdge = SignalRef.Create(clk.Descriptor, SignalRef.EReferencedProperty.RisingEdge);
            }
            else
            {
                srEdge = SignalRef.Create(clk.Descriptor, SignalRef.EReferencedProperty.FallingEdge);
            }
            var lrEdge = new LiteralReference(srEdge);

            int  nwait      = 0;
            var  nwaitEx    = waitObject.Children[0];
            bool nwaitConst = nwaitEx.IsConst();

            if (nwaitConst)
            {
                nwait = (int)TypeConversions.ConvertValue(
                    nwaitEx.Eval(DefaultEvaluator.DefaultConstEvaluator),
                    typeof(int));
            }

            var fspec = new FunctionSpec(typeof(void))
            {
                IntrinsicRep = IntrinsicFunctions.Wait(WaitParams.EWaitKind.WaitUntil)
            };

            Variable         v   = null;
            LiteralReference lrV = null;

            if (!nwaitConst || nwait > 3)
            {
                v = new Variable(typeof(int))
                {
                    Name = "_wait_i" + (ictr++)
                };
                builder.DeclareLocal(v);
                lrV = new LiteralReference(v);
                builder.Store(v, LiteralReference.CreateConstant((int)0));
                var loop = builder.Loop();
                builder.If(Expression.Equal(lrV, nwaitEx));
                {
                    builder.Break(loop);
                }
                builder.EndIf();
            }
            int ncalls = 1;

            if (nwaitConst && nwait <= 3)
            {
                ncalls = nwait;
            }
            for (int i = 0; i < ncalls; i++)
            {
                builder.Call(fspec, lrEdge);
            }
            if (!nwaitConst || nwait > 3)
            {
                builder.Store(v, lrV + LiteralReference.CreateConstant((int)1));
                builder.EndLoop();
            }
            return(true);
        }