static void ResolveTypeDependencies(this IComponentDescriptor component, DesignDescriptor design)
        {
            foreach (var child in component.GetChildComponents())
            {
                ResolveTypeDependencies(child, design);
            }
            var processes = component.GetProcesses().ToArray();
            var str       = new StmtTypeResolver(design, component);

            foreach (var process in processes)
            {
                ResolveTypeDependencies(process, str);
            }
            foreach (var port in component.GetPorts())
            {
                str.RequireType(port.ElementType, design);
            }
            foreach (var signal in component.GetSignals())
            {
                str.RequireType(signal.ElementType, design);
            }
            foreach (var field in component.GetFields())
            {
                str.RequireType(field.Type, design);
            }
        }
Пример #2
0
        private void DeclareComponentInstance(IComponentDescriptor cd, IndentedTextWriter tw)
        {
            string name = GetComponentName(cd);
            string rname = GetComponentName(((ComponentDescriptor)cd).Instance.Representant.Descriptor);
            if (_curComponent != null && // may happen if called prior to actual VHDL generation in OnSynthesis() method of a component
                GetLibrary(_curComponent) != GetLibrary(cd))
                rname = "entity " + GetLibrary(cd) + "." + rname;
            tw.WriteLine("inst_" + name + ": " + rname);
            tw.Indent++;
            tw.WriteLine("port map(");
            tw.Indent++;
            IComponentDescriptor owner = (IComponentDescriptor)cd.Owner;
            bool first = true;
            var xsim = _sim.Fork();
            xsim.PushScope();
            foreach (IPortDescriptor pd in cd.GetPorts())
            {
                if (first)
                    first = false;
                else
                    tw.WriteLine(",");

                var ownerRef = pd
                    .BoundSignal
                    .AsSignalRef(SignalRef.EReferencedProperty.Cur);
                if (ownerRef == null)
                    throw new InvalidOperationException("Bound signal unknown to instantiating component");

                var litstr = new LiteralStringifier(this, LiteralReference.EMode.Direct);
                var temp = _curComponent;
                _curComponent = owner;
                litstr.VisitSignalRef(ownerRef);
                var rhs = litstr.Result;
                _curComponent = temp;
                
                string pid = MakeIDName(pd.Name, pd.BoundSignal.RemoveIndex(), xsim);
                /*string sigExpr = MakeIDName(spd.Name, pd.BoundSignal.RemoveIndex());
                if (pd.BoundSignal is InstanceDescriptor &&
                    ((InstanceDescriptor)pd.BoundSignal).Index != null)
                    sigExpr += ((InstanceDescriptor)pd.BoundSignal).Index.ToString();
                tw.Write(pid + " => " + sigExpr);*/
                tw.Write(pid + " => " + rhs);
            }
            tw.WriteLine(");");
            tw.Indent--;
            tw.Indent--;
        }
Пример #3
0
        private void DeclarePortList(IComponentDescriptor cd, IndentedTextWriter tw, bool extScope)
        {
            if (cd.GetPorts().Count() == 0)
                return;
            tw.WriteLine("port (");
            tw.Indent++;
            bool first = true;
            ScopedIdentifierManager xsim = _sim;
            if (extScope)
            {
                xsim = _sim.Fork();
                xsim.PushScope();
            }
            foreach (IPortDescriptor pd in cd.GetPorts())
            {
                if (first)
                    first = false;
                else
                    tw.WriteLine(";");

                string pid = MakeIDName(pd.Name, pd.BoundSignal, xsim);

                tw.Write(pid + ": " + PortDirectionToString(pd.Direction) + " " +
                    GetTypeDescriptorCompletedName(pd.ElementType));
                if (pd.Direction != EFlowDirection.In &&
                    pd.InitialValue != null)
                {
                    tw.Write(" := ");
                    tw.Write(GetValueID(pd.InitialValue));
                }
            }
            tw.WriteLine(");");
        }
Пример #4
0
        //      ADDED
        private void GenerateCtor(IComponentDescriptor cd, IndentedTextWriter tw)
        {
            string name = GetComponentName(cd);
            bool first = true;
            tw.Write("SC_CTOR(" + name + ")");
            tw.Indent++;

            //      Initialization List
            foreach (ISignalDescriptor signal in cd.GetSignals())
            {
                if (signal.ElementType.CILType.IsArray)
                {
                    if (first)
                    {
                        first = false;
                        tw.Write(": ");
                    }
                    else
                        tw.Write(", ");

                    DeclareSignalVecInstance(signal, tw);
                }
            }

            if (cd.GetPorts() != null)
            {
                var xsim = _sim.Fork();
                xsim.PushScope();
                foreach (IPortDescriptor pd in cd.GetPorts())
                {
                    if (pd.ElementType.CILType.IsArray)
                    {
                        if (first)
                        {
                            first = false;
                            tw.Write(": ");
                        }
                        else
                            tw.Write(", ");


                        string pname = MakeIDName(pd.Name, pd.BoundSignal.RemoveIndex(), xsim);
                        tw.Write(pname + "(" + "\"" + pname + "\", " + pd.ElementType.TypeParams[0] + ")");
                    }

                }

            }

            var components = cd.GetChildComponents();
                //.Cast<ComponentDescriptor>()
                //.Select(c => c.Instance.Representant)
                //.Distinct()
                //.Select(c => c.Descriptor);

            foreach (IComponentDescriptor scd in components)
            {
                if (first)
                {
                    first = false;
                    tw.Write(": ");
                }
                else
                    tw.Write(", ");
                DeclareComponentInstance(scd, tw);
            }

            tw.WriteLine();
            tw.Indent--;
            tw.WriteLine("{");
            tw.Indent++;

            // Initialize Ports
            if (cd.GetPorts() != null)
            {
                var xsim = _sim.Fork();
                xsim.PushScope();
                foreach (IPortDescriptor pd in cd.GetPorts())
                {
                    if ((pd.Direction == EFlowDirection.Out) && (pd.InitialValue != null) && !pd.ElementType.CILType.IsArray)
                    {
                        string pname = MakeIDName(pd.Name, pd.BoundSignal.RemoveIndex(), xsim);
                        tw.WriteLine(pname + ".initialize(" + SystemCifyConstant(pd.InitialValue) + ");");
                    }
                }
            }

            tw.WriteLine();

            //      Process Registration and Sensitivity List
            foreach (ProcessDescriptor pd in cd.GetProcesses())
            {
                InitializeProcess(pd, tw);
            }
            if (cd.GetProcesses().Count() > 0)
                tw.WriteLine();

            //      Module Variable/Constant Initialization
            foreach (FieldDescriptor field in cd.GetVariables())
            {
                InitializeField(field, tw);
            }
            if (cd.GetVariables().Count() > 0)
                tw.WriteLine();

            foreach (FieldDescriptor field in cd.GetConstants())
            {
                InitializeField(field, tw);
            }
            if (cd.GetVariables().Count() > 0)
                tw.WriteLine();

            // Signals Initialization
            foreach (ISignalDescriptor signal in cd.GetSignals())
            {
                InitializeSignal(signal, tw);
            }
            if (cd.GetSignals().Count() > 0)
                tw.WriteLine();

            //      Port Binding
            foreach (IComponentDescriptor scd in cd.GetChildComponents())
            {
                PortBinding(scd, tw);
            }

            tw.Indent--;
            tw.WriteLine("}");
        }
Пример #5
0
        //      ADDED
        private void PortBinding(IComponentDescriptor cd, IndentedTextWriter tw)
        {
            //string rname = GetComponentName(((ComponentDescriptor)cd).Instance.Representant.Descriptor);
            string rname = MakeIDName(GetComponentName(cd), cd) + "_";
            // Alternative 1
            if (cd.GetPorts() != null)
            {

                IComponentDescriptor owner = (IComponentDescriptor)cd.Owner;
                //bool first = true;
                var xsim = _sim.Fork();
                xsim.PushScope();
                foreach (IPortDescriptor pd in cd.GetPorts())
                {
                    tw.Write(rname + ".");
                    var ownerRef = pd
                        .BoundSignal
                        .AsSignalRef(SignalRef.EReferencedProperty.Instance);
                    if (ownerRef == null)
                        throw new InvalidOperationException("Bound signal unknown to instantiating component");

                    var litstr = new LiteralStringifier(this, LiteralReference.EMode.Direct);
                    var temp = _curComponent;
                    _curComponent = owner;
                    litstr.VisitSignalRef(ownerRef);
                    var rhs = litstr.Result;
                    _curComponent = temp;
                    string pid = MakeIDName(pd.Name, pd.BoundSignal.RemoveIndex(), xsim);
                    tw.WriteLine(pid + ".bind(" + rhs + ");");


                }
                tw.WriteLine();
            }

            //// Alternative 2 
            //if (cd.GetPorts() != null)
            //{
            //    tw.Write(rname + "(");
            //    IComponentDescriptor owner = (IComponentDescriptor)cd.Owner;
            //    bool first = true;
            //    var xsim = _sim.Fork();
            //    xsim.PushScope();
            //    foreach (IPortDescriptor pd in cd.GetPorts())
            //    {
            //        if (first)
            //            first = false;
            //        else
            //            tw.Write(",");

            //        var ownerRef = pd
            //            .BoundSignal
            //            .AsSignalRef(SignalRef.EReferencedProperty.Instance);
            //        if (ownerRef == null)
            //            throw new InvalidOperationException("Bound signal unknown to instantiating component");

            //        var litstr = new LiteralStringifier(this, LiteralReference.EMode.Direct);
            //        var temp = _curComponent;
            //        _curComponent = owner;
            //        litstr.VisitSignalRef(ownerRef);
            //        var rhs = litstr.Result;
            //        _curComponent = temp;
            //        string pid = MakeIDName(pd.Name, pd.BoundSignal.RemoveIndex(), xsim);
            //        tw.Write(rhs);
            //    }
            //    tw.WriteLine(");");
            //}
        }
Пример #6
0
        //      ALTERADA
        private void DeclarePortList(IComponentDescriptor cd, IndentedTextWriter tw, bool extScope)
        {
            if (cd.GetPorts().Count() == 0)
                return;
            ScopedIdentifierManager xsim = _sim;
            if (extScope)
            {
                xsim = _sim.Fork();
                xsim.PushScope();
            }
            foreach (IPortDescriptor pd in cd.GetPorts())
            {
                string pid = MakeIDName(pd.Name, pd.BoundSignal, xsim);

                if (!pd.ElementType.CILType.IsArray)
                {
                    tw.WriteLine("sc_" + PortDirectionToString(pd.Direction) + "<" +
                          GetTypeDescriptorCompletedName(pd.ElementType) + "> " + pid + ";");
                }
                else
                {
                    tw.WriteLine("sc_vector< sc_" + PortDirectionToString(pd.Direction) + "<" +
                        GetTypeDescriptorCompletedName(pd.ElementType.Element0Type) + "> > " + pid +
                        ";");
                }
            }


        }