示例#1
0
 public string Visit(CIL_SectionTypes node)
 {
     foreach (var item in node.ListNode)
     {
         item.Visit(this);
     }
     return("");
 }
示例#2
0
        public static string SetMemoryInCIL(Dictionary <string, SemanticType> types, CIL_SectionTypes secttype)
        {
            Queue <string>           Zeros = new Queue <string>();
            var                      graph = BuildGraph(types);
            Dictionary <string, int> ind   = new Dictionary <string, int>();

            foreach (var item in graph)
            {
                ind.Add(item.Key, 0);
            }
            foreach (var item in graph)
            {
                foreach (var w in item.Value)
                {
                    ind[w]++;
                }
            }
            foreach (var item in ind)
            {
                if (item.Value == 0)
                {
                    Zeros.Enqueue(item.Key);
                }
            }

            // Section Type
            Dictionary <string, CIL_ClassDef> mapped = new Dictionary <string, CIL_ClassDef>();

            foreach (var item in secttype.ListNode)
            {
                mapped.Add(item.Id, item);
            }

            string solve = "";

            while (Zeros.Count > 0)
            {
                string k = Zeros.Dequeue();

                foreach (var item in graph[k])
                {
                    ind[item]--;
                    if (ind[item] == 0)
                    {
                        Zeros.Enqueue(item);
                    }
                }

                if (!mapped.ContainsKey(k))
                {
                    continue;
                }

                var classdef = mapped[k];
                var semt     = types[k];

                solve += string.Format("\t {0}: .word ", k);

                // Len Del Type
                solve += (classdef.Methods.ListNode.Count + 4);

                // Len del Objeto
                solve += ", " + (4 * (classdef.Attrs.ListNode.Count + 2));

                // Father
                solve += ", " + ((semt.Father == null) ? "0" : semt.Father.Name);

                // Type Name
                solve += string.Format(", type_{0}", k);

                for (int i = 0; i < classdef.Methods.ListNode.Count; i++)
                {
                    var s = classdef.Methods.ListNode[i];
                    solve += ", " + s.Idres;
                }
                solve += "\n";
            }

            return(solve);
        }
示例#3
0
        public static void SetMemory(ICIL_Memory mem, Dictionary <string, SemanticType> types, CIL_SectionTypes secttype)
        {
            Queue <string>           Zeros = new Queue <string>();
            var                      graph = BuildGraph(types);
            Dictionary <string, int> ind   = new Dictionary <string, int>();

            foreach (var item in graph)
            {
                ind.Add(item.Key, 0);
            }
            foreach (var item in graph)
            {
                foreach (var w in item.Value)
                {
                    ind[w]++;
                }
            }
            foreach (var item in ind)
            {
                if (item.Value == 0)
                {
                    Zeros.Enqueue(item.Key);
                }
            }

            // Section Type
            Dictionary <string, CIL_ClassDef> mapped = new Dictionary <string, CIL_ClassDef>();

            foreach (var item in secttype.ListNode)
            {
                mapped.Add(item.Id, item);
            }

            while (Zeros.Count > 0)
            {
                string k = Zeros.Dequeue();

                foreach (var item in graph[k])
                {
                    ind[item]--;
                    if (ind[item] == 0)
                    {
                        Zeros.Enqueue(item);
                    }
                }

                if (!mapped.ContainsKey(k))
                {
                    continue;
                }

                var classdef = mapped[k];

                int idx = mem.Allocate(classdef.Methods.ListNode.Count + 2);

                mem.SetDirType(k, idx);

                mem.SetValue(idx++, classdef.Methods.ListNode.Count + 1);

                var sem = types[k];

                if (sem.Father != null)
                {
                    mem.SetValue(idx, mem.GetDirType(sem.Father.Name));
                }

                idx++;

                foreach (var item in classdef.Methods.ListNode)
                {
                    mem.SetDirmethod(item.Idres, idx++);
                }
            }
        }