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"); }