Пример #1
0
        public string Visit(CIL_AST_Root node)
        {
            string solve = ".data\n";
            // data
            var data = node.Data.Visit(this);

            // set types
            var types = Utils.SetMemoryInCIL(Semtype, node.Types);

            // offset_types
            node.Types.Visit(this);


            string code = ".text\n\n" + node.Functions.Visit(this) + @"
        li $v0, 10
        syscall

        exception:
            li $v0, 4
            syscall
            li $v0, 10
            syscall
";

            return(solve + data + types + code);
        }
Пример #2
0
        public string Visit(CIL_AST_Root node)
        {
            Utils.SetMemory(mem, semtype, node.Types);
            allnode = new List <CIL_AST_Node>(CIL_AST_Node.GetAllNode(node));
            int main = -1;

            for (int i = 0; i < allnode.Count; i++)
            {
                if (allnode[i] is CIL_Label)
                {
                    resolvaddr[((CIL_Label)allnode[i]).Label] = i;
                }
                else if (allnode[i] is CIL_FunctionDef)
                {
                    resolvaddr[((CIL_FunctionDef)allnode[i]).Name] = i;
                    if (main == -1)
                    {
                        main = i;
                    }
                    //mem.SetValue(mem.GetDirMethod(((CIL_ClassMethod)allnode[i]).Idres), i);
                }
            }

            foreach (var item in semtype)
            {
                if (item.Key == "SELF_TYPE")
                {
                    continue;
                }
                int idx = mem.GetDirType(item.Key);
                idx += 2;
                foreach (var item2 in item.Value.GetAllMethods())
                {
                    if (resolvaddr.ContainsKey(item2.Label()))
                    {
                        mem.SetValue(idx++, resolvaddr[item2.Label()]);
                    }
                    else
                    {
                        Console.WriteLine($"Method {item2.Label()} not found in CIL");
                        idx++;
                    }
                }
                //Console.Write($"{item.Key} :");
                //PrintObject(mem.GetDirType(item.Key));
            }



            // Build DataElement
            node.Data.Visit(this);

            // Debug DataElement
            foreach (var d in dataaddr)
            {
                //PrintObject(d.Value);
            }

            // Build OffSetAttr
            node.Types.Visit(this);

            // Init Simulator
            variableaddr.Push(new Dictionary <string, int>());

            allnode[resolvaddr["entry"]].Visit(this);

            return(io.get_all_text());
        }
Пример #3
0
 public static string Execute(CIL_AST_Root root, Dictionary <string, SemanticType> semtype)
 {
     return(new CIL_Execute(new CIL_Memory(), semtype).Visit(root));
 }