示例#1
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;");
        }