예제 #1
0
            protected override void DeclareAlgorithm()
            {
                var        srClk = SignalRef.Create(_taSite._clk, SignalRef.EReferencedProperty.RisingEdge);
                var        lrClk = new LiteralReference(srClk);
                var        srEn  = SignalRef.Create(_taSite._en, SignalRef.EReferencedProperty.Cur);
                var        lrEn  = new LiteralReference(srEn);
                var        lr1   = LiteralReference.CreateConstant(StdLogic._1);
                var        cond  = lrClk & (Expression.Equal(lrEn, lr1));
                var        srSLV = SignalRef.Create(_taSite._slvSignal, SignalRef.EReferencedProperty.Cur);
                var        lrSLV = new LiteralReference(srSLV);
                Expression conv;

                if (_taSite._port.InitialValue.GetType().Equals(typeof(StdLogicVector)))
                {
                    conv = lrSLV;
                }
                else
                {
                    conv = IntrinsicFunctions.Cast(
                        lrSLV,
                        typeof(StdLogicVector),
                        TypeDescriptor.GetTypeOf(_taSite._port.InitialValue));
                }
                var srNext = SignalRef.Create(_taSite._port, SignalRef.EReferencedProperty.Next);

                If(cond);
                {
                    Store(srNext, conv);
                }
                EndIf();
            }
예제 #2
0
        private Expression MakeIntegerResult(Expression ex)
        {
            var arg = ex.Accept(this);

            if (arg.ResultType.CILType.Equals(typeof(int)))
            {
                return(arg);
            }
            else
            {
                var iarg = IntrinsicFunctions.Cast(ex, arg.ResultType.CILType, typeof(int));
                return(iarg);
            }
        }
예제 #3
0
        private void MakeStringArray(Expression[] elements)
        {
            TypeDescriptor stype = (TypeDescriptor)typeof(string);

            for (int i = 0; i < elements.Length; i++)
            {
                TypeDescriptor rtype = elements[i].ResultType;
                if (!rtype.Equals(stype))
                {
                    elements[i] = IntrinsicFunctions.Cast(
                        elements[i],
                        rtype.CILType, typeof(string));
                }
            }
        }
예제 #4
0
            public override bool Rewrite(CodeDescriptor decompilee, System.Reflection.MethodBase callee, Analysis.StackElement[] args, Analysis.IDecompiler stack, IFunctionBuilder builder)
            {
                Array arr = (Array)args[0].Sample;

                if (arr == null)
                {
                    throw new InvalidOperationException("Unable to deduce array length");
                }

                int  numElems = arr.Length;
                Type tTE      = arr.GetType().GetElementType();
                Type tTA;

                callee.IsFunction(out tTA);
                FunctionCall      newCall = IntrinsicFunctions.NewArray(tTE, LiteralReference.CreateConstant(numElems), arr);
                FunctionSpec      fspec   = (FunctionSpec)newCall.Callee;
                IntrinsicFunction ifun    = fspec.IntrinsicRep;
                ArrayParams       aparams = (ArrayParams)ifun.Parameter;

                for (int i = 0; i < numElems; i++)
                {
                    aparams.Elements[i] = IntrinsicFunctions.GetArrayElement(
                        args[0].Expr,
                        LiteralReference.CreateConstant(i));
                }

                object sample = null;

                try
                {
                    sample = callee.Invoke(arr);
                }
                catch (Exception)
                {
                }

                Expression conv = IntrinsicFunctions.Cast(newCall, arr.GetType(), tTA);

                stack.Push(conv, sample);
                return(true);
            }
예제 #5
0
            protected override void DeclareAlgorithm()
            {
                var srCur = SignalRef.Create(_taSite._portSignal, SignalRef.EReferencedProperty.Cur);
                var lrCur = new LiteralReference(srCur);

                if (_taSite._portSignal.ElementType.CILType.Equals(typeof(StdLogic)))
                {
                    var index = new IndexSpec((DimSpec)0);
                    var srSLV = new SignalRef(
                        _taSite._slvSignal,
                        SignalRef.EReferencedProperty.Next,
                        index.AsExpressions(),
                        index, true);
                    Store(srSLV, lrCur);
                }
                else
                {
                    var convFn = IntrinsicFunctions.Cast(lrCur,
                                                         _taSite._portSignal.ElementType.CILType,
                                                         _taSite._slvSignal.ElementType);
                    var srSLV = SignalRef.Create(_taSite._slvSignal, SignalRef.EReferencedProperty.Next);
                    Store(srSLV, convFn);
                }
            }
예제 #6
0
                protected override void DeclareAlgorithm()
                {
                    var srClk      = SignalRef.Create(_taSite._clk, SignalRef.EReferencedProperty.RisingEdge);
                    var lrClk      = new LiteralReference(srClk);
                    var srWrEn     = _taSite.NeedWriteAccess ? SignalRef.Create(_taSite._wrEn, SignalRef.EReferencedProperty.Cur) : null;
                    var lrWrEn     = _taSite.NeedWriteAccess ? new LiteralReference(srWrEn) : null;
                    var srAddr     = SignalRef.Create(_taSite._addr, SignalRef.EReferencedProperty.Cur);
                    var lrAddr     = new LiteralReference(srAddr);
                    var srDataIn   = _taSite.NeedWriteAccess ? SignalRef.Create(_taSite._dataIn, SignalRef.EReferencedProperty.Cur) : null;
                    var lrDataIn   = _taSite.NeedWriteAccess ? new LiteralReference(srDataIn) : null;
                    var srDataOut  = SignalRef.Create(_taSite._dataOut, SignalRef.EReferencedProperty.Next);
                    var hi         = LiteralReference.CreateConstant(StdLogic._1);
                    var addrUType  = TypeDescriptor.GetTypeOf(((StdLogicVector)_taSite._addr.InitialValue).UnsignedValue);
                    var uAddr      = IntrinsicFunctions.Cast(lrAddr, typeof(StdLogicVector), addrUType);
                    var iAddr      = IntrinsicFunctions.Cast(uAddr, addrUType.CILType, typeof(int));
                    var array      = _taSite._array;
                    var lrArray    = new LiteralReference(array.ArrayLit);
                    var elemType   = array.ElementType;
                    var aref       = new ArrayRef(lrArray, elemType, iAddr);
                    var convDataIn = _taSite.NeedWriteAccess ? IntrinsicFunctions.Cast(lrDataIn, typeof(StdLogicVector), elemType) : null;
                    var convAref   = IntrinsicFunctions.Cast(aref, elemType.CILType, _taSite._dataOut.ElementType);

                    If(lrClk);
                    {
                        Store(srDataOut, convAref);
                        if (_taSite.NeedWriteAccess)
                        {
                            If(Expression.Equal(lrWrEn, hi));
                            {
                                Store(aref, convDataIn);
                            }
                            EndIf();
                        }
                    }
                    EndIf();
                }
예제 #7
0
                public void AddAccessor(InlineFieldMapperTransactionSite taSite, bool needRead, bool needWrite)
                {
                    var  srWrEn     = needWrite ? SignalRef.Create(taSite._wrEn, SignalRef.EReferencedProperty.Cur) : null;
                    var  lrWrEn     = needWrite ? new LiteralReference(srWrEn) : null;
                    var  srDataIn   = needWrite ? SignalRef.Create(taSite._dataIn, SignalRef.EReferencedProperty.Cur) : null;
                    var  lrDataIn   = needWrite ? new LiteralReference(srDataIn) : null;
                    var  srDataOut  = needRead ? SignalRef.Create(taSite._dataOut, SignalRef.EReferencedProperty.Next) : null;
                    var  hi         = LiteralReference.CreateConstant(StdLogic._1);
                    var  elemType   = taSite._literal.Type;
                    var  lrVar      = new LiteralReference((Literal)taSite._literal);
                    var  convDataIn = needWrite ? IntrinsicFunctions.Cast(lrDataIn, typeof(StdLogicVector), elemType) : null;
                    var  convVar    = needRead ? IntrinsicFunctions.Cast(lrVar, elemType.CILType, taSite._dataOut.ElementType) : null;
                    bool isBool     = taSite._literal.Type.CILType.Equals(typeof(bool));
                    var  lr1        = LiteralReference.CreateConstant((StdLogicVector)"1");
                    var  lr0        = LiteralReference.CreateConstant((StdLogicVector)"0");

                    if (needWrite)
                    {
                        BodyBuilder.If(Expression.Equal(lrWrEn, hi));
                        {
                            if (isBool)
                            {
                                BodyBuilder.Store(taSite._literal, Expression.Equal(lrDataIn, lr1));
                            }
                            else
                            {
                                BodyBuilder.Store(taSite._literal, convDataIn);
                            }

                            var diagOut = taSite.Host as ISupportsDiagnosticOutput;
                            if (diagOut != null && diagOut.EnableDiagnostics)
                            {
                                Expression vref  = new LiteralReference(taSite.Literal);
                                var        fref  = taSite.Literal as FieldRef;
                                var        field = fref != null ? fref.FieldDesc : null;
                                if (field != null && field.HasAttribute <ActualTypeAttribute>())
                                {
                                    var atype = field.QueryAttribute <ActualTypeAttribute>();
                                    vref = IntrinsicFunctions.Cast(vref, vref.ResultType.CILType, atype.ActualType, true);
                                }
                                BodyBuilder.ReportLine(taSite.Literal.Name + " changed to ", vref);
                            }
                        }
                        BodyBuilder.EndIf();
                    }
                    if (needRead)
                    {
                        if (isBool)
                        {
                            BodyBuilder.If(lrVar);
                            {
                                BodyBuilder.If(lrVar);
                                BodyBuilder.Store(srDataOut, lr1);
                            }
                            BodyBuilder.Else();
                            {
                                BodyBuilder.Store(srDataOut, lr0);
                            }
                            BodyBuilder.EndIf();
                        }
                        else
                        {
                            BodyBuilder.Store(srDataOut, convVar);
                        }
                    }
                }