Exemple #1
0
        public string Visit(CIL_DataElement node)
        {
            int idx = mem.Allocate(node.Data.Length + 1 + 2);

            dataaddr.Add(node.Id, idx);

            mem.SetValue(idx++, node.Data.Length + 2);

            mem.SetValue(idx++, mem.GetDirType("String"));

            foreach (var item in node.Data)
            {
                mem.SetValue(idx++, item);
            }

            return("");
        }
Exemple #2
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++);
                }
            }
        }