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);
            }
        }
        //      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("}");
        }
Exemple #3
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;");
        }
        //      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");
        }