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);
            }
        }
            private void ComponentDFS(IComponentDescriptor component)
            {
                IDependencyOrdered ordered = component as IDependencyOrdered;

                if (ordered.DependencyOrder >= 0)
                {
                    return;
                }

                foreach (IComponentDescriptor child in component.GetChildComponents())
                {
                    ComponentDFS(child);
                }

                ordered.DependencyOrder = _curOrder++;
            }
            private void ComponentDFS(IComponentDescriptor component)
            {
                IDependencyOrdered ordered = component as IDependencyOrdered;
                if (ordered.DependencyOrder >= 0)
                    return;

                foreach (IComponentDescriptor child in component.GetChildComponents())
                    ComponentDFS(child);

                ordered.DependencyOrder = _curOrder++;
            }
예제 #4
0
        private void GenerateArchitecture(IComponentDescriptor cd, IndentedTextWriter tw)
        {
            string name = GetComponentName(cd);
            tw.WriteLine("architecture behavioral of " + name + " is");
            tw.Indent++;

            foreach (TypeDescriptor td in cd.GetTypes())
            {
                GenerateTypeDecl(td, tw);
            }
            if (cd.GetTypes().Count() > 0)
                tw.WriteLine();

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

            foreach (ComponentDescriptor scd in components)
            {
                DeclareComponent(scd, tw);
                tw.WriteLine();
            }

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

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

            foreach (ISignalOrPortDescriptor sd in cd.GetSignals())
            {
                object initVal = sd.InitialValue;
                string initSuffix = "";
                if (initVal != null)
                    initSuffix = " := " + GetValueID(initVal);
                string sname = MakeIDName(sd.Name, sd);
                tw.WriteLine("signal " + sname + ": " +
                    GetTypeDescriptorCompletedName(sd.ElementType) + initSuffix + ";");
            }
            if (cd.GetSignals().Count() > 0)
                tw.WriteLine();

            foreach (MethodDescriptor md in cd.GetActiveMethods())
            {
                GenerateMethodImpl(md, tw);
                tw.WriteLine();
            }
            if (cd.GetActiveMethods().Count() > 0)
                tw.WriteLine();

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

            foreach (IComponentDescriptor scd in cd.GetChildComponents())
            {
                DeclareComponentInstance(scd, tw);
                tw.WriteLine();
            }

            foreach (ProcessDescriptor pd in cd.GetProcesses())
            {
                DeclareProcess(pd, tw);
                tw.WriteLine();
            }

            tw.Indent--;
            tw.WriteLine("end behavioral;");
        }
예제 #5
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("}");
        }
예제 #6
0
        private void GenerateDependencies(IComponentDescriptor desc, IndentedTextWriter tw, string top)
        {

            // Due to their compile-time overhead, fixed-point data types are omitted from the 
            // default SystemC include file. To enable fixed-point data types, SC_INCLUDE_FX
            // must be defined prior to including the SystemC header file
        
            tw.WriteLine("#define SC_INCLUDE_FX");
            

            foreach (SysCLib lib in _stdLibraries)
            {
                if (lib.Name != "#define SC_INCLUDE_FX")
                    tw.WriteLine("#include " + "\"" + lib.Name + "\"");
            }
            IPackageOrComponentDescriptor aux = (IPackageOrComponentDescriptor)desc;
            if (aux != null)
            {
                var pds = aux.Dependencies
                .Where(pd => pd != aux && !pd.IsEmpty)
                .GroupBy(pd => GetLibrary(pd));

                foreach (var grp in pds)
                {
                    //tw.WriteLine("library {0};", grp.Key);

                    foreach (var pd in grp)
                    {
                        tw.WriteLine("#include \"" + MakeIDName(pd.PackageName, pd) + ".h\"");
                    }
                }

                //foreach (PackageDescriptor pack in ((DescriptorBase)desc).GetDesign().GetPackages())
                //{
                //    tw.WriteLine("// " + pack.PackageName);
                //}

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

                foreach (ComponentDescriptor scd in components)
                {
                    tw.WriteLine("#include " + "\"" + GetComponentName(scd) + ".h" + "\"");
                }
            }
            else
            {
                tw.WriteLine("#include " + "\"" + top + ".h" + "\"");
            }

            tw.WriteLine("#include <iostream>");
            tw.WriteLine("#include \"sc_lv_add_ons.h\"");
            tw.WriteLine("#include \"sc_logic_add_ons.h\"");
            tw.WriteLine("using namespace sc_core;");
            tw.WriteLine("using namespace sc_dt;");
            tw.WriteLine("using namespace std;");
            tw.WriteLine();

        }
예제 #7
0
        //      ALTERADA - equivalent to "DeclareEntity()" and "GenerateArchitecture()" in VHDLGen.cs
        private void DeclareAndGenerateModule(IComponentDescriptor cd, IndentedTextWriter tw)
        {
            string name = GetComponentName(cd);

            //      Module Declaration
            tw.WriteLine("SC_MODULE(" + name + ")");
            tw.WriteLine("{");
            tw.Indent++;

            tw.WriteLine();
            tw.WriteLine("// Port List" );
            //      Port Declarations
            DeclarePortList(cd, tw, false);
            tw.WriteLine();

            tw.WriteLine("// Sub-Components");
            //      Sub-Components Declaration
            var components = cd.GetChildComponents();
            //    .Cast<ComponentDescriptor>()
            //    .Select(c => c.Instance.Representant)
            //    .Distinct()
            //    .Select(c => c.Descriptor);

            foreach (IComponentDescriptor scd in components)
            {
                DeclareComponent(scd, tw);
            }
            if (cd.GetChildComponents().Count() > 0)
                tw.WriteLine();

            tw.WriteLine("// Local Channels");
            //      Local Channel Declaration
            foreach (ISignalOrPortDescriptor sd in cd.GetSignals())
            {
                //object initVal = sd.InitialValue;
                //string initSuffix = "";
                //if (initVal != null)
                //    initSuffix = ".write( " + GetValueID(initVal);
                string sname = MakeIDName(sd.Name, sd);

                if (sd.ElementType.CILType.IsEnum)
                {
                    tw.WriteLine("sc_signal<int> " + sname + ";");
                }
                else if (sd.ElementType.CILType.IsArray)
                {
                    tw.WriteLine("sc_vector< sc_signal<" + GetTypeDescriptorCompletedName(sd.ElementType.Element0Type)
                        + "> > " + sname + ";");
                }
                else
                {
                    tw.WriteLine("sc_signal<" + GetTypeDescriptorCompletedName(sd.ElementType) + "> " + sname + ";");

                }

            }
            if (cd.GetSignals().Count() > 0)
                tw.WriteLine();

            tw.WriteLine("// Constants");
            //      Constant Declarations
            foreach (FieldDescriptor field in cd.GetConstants())
            {
                DeclareField(field, tw);
            }
            if (cd.GetConstants().Count() > 0)
                tw.WriteLine();

            tw.WriteLine("// Variables");
            //      Variables Declaration
            foreach (FieldDescriptor field in cd.GetVariables())
            {

                DeclareField(field, tw);
            }
            if (cd.GetVariables().Count() > 0)
                tw.WriteLine();

            tw.WriteLine("// Processes");
            //      Process Declaration
            foreach (ProcessDescriptor pd in cd.GetProcesses())
            {
                DeclareProcess(pd, tw);
                tw.WriteLine();
            }

            //      Other Methods Declaration
            //tw.WriteLine("// Funcoes/Procedimentos: ");
            //foreach (MethodDescriptor md in cd.GetMethods())
            //{
            //    GenerateMethodImpl(md, tw);
            //    tw.WriteLine();
            //}
            //if (cd.GetMethods().Count() > 0)
            //    tw.WriteLine();

            tw.WriteLine("// Active functions/methods ");
            foreach (MethodDescriptor md in cd.GetActiveMethods())
            {
                GenerateMethodImpl(md, tw);
                tw.WriteLine();
            }
            if (cd.GetMethods().Count() > 0)
                tw.WriteLine();           


            //      Constructors
            tw.WriteLine("// Constructor");
            GenerateCtor(cd, tw);

            tw.Indent--;
            tw.WriteLine("};");
            tw.WriteLine("#endif");
        }