Exemple #1
0
 public MipsCompiler(CIL_AST_Node root, Dictionary <string, SemanticType> semtype)
 {
     Semtype = semtype;
 }
Exemple #2
0
 public string Visit(CIL_AST_Node node)
 {
     throw new NotImplementedException();
 }
Exemple #3
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());
        }