public RegisterAllocate(MipsFrame frame, List <BasicBlock> blocks, Temp.Temp[] precolored) { Frame = frame; Blocks = blocks; for (int i = 0; i < precolored.Length; ++i) { Precolored.Add(GetNodeByTemp(precolored[i])); GetNodeByTemp(precolored[i]).Color = i; GetNodeByTemp(precolored[i]).Degree = Infinity; } foreach (BasicBlock b in blocks) { foreach (TExp i in b.List) { LivenessNode n = new LivenessNode(i); foreach (Temp.Temp t in n.Def) { if (!TempToNode.ContainsKey(t)) { Initial.Add(GetNodeByTemp(t)); } } foreach (Temp.Temp t in n.Use) { if (!TempToNode.ContainsKey(t)) { Initial.Add(GetNodeByTemp(t)); } } } } }
public override Frame.Frame NewFrame(Temp.Label name, BoolList formals) { MipsFrame ret = new MipsFrame(); ret.Name = name; AccessList ptr = null; int count = 0; for (BoolList f = formals; f != null; f = f.Tail) { Access a; if (count < 4 && !f.Head) { a = ret.AllocLocal(false); } else { a = ret.AllocLocal(true); } if (ret.Formals == null) { ptr = ret.Formals = new AccessList(a, null); } else { ptr = ptr.Tail = new AccessList(a, null); } } AllFrames.Add(ret); return(ret); }
Temp.Temp TranslateExpr(CALL expr) { Call c = new Call(); c.Name = new Label((expr.Func as NAME).Label); TempList args = null, ptr = null; for (ExpList exp = expr.Args; exp != null; exp = exp.Tail) { Temp.Temp arg = TranslateExpr(exp.Head); if (args == null) { ptr = args = new TempList(arg, null); } else { ptr = ptr.Tail = new TempList(arg, null); } } c.Param = args; MipsFrame t = null; foreach (MipsFrame f in MipsFrame.AllFrames) { if (c.Name.Lab == f.Name) { t = f; break; } } if (t == null) { int count = 0; for (ptr = c.Param; ptr != null; ptr = ptr.Tail) { InstrList.Add(new Move(Frame.A(count), ptr.Head)); ++count; } } else { int count = 0; ptr = c.Param; for (AccessList al = t.Formals; al != null; al = al.Tail, ptr = ptr.Tail) { if (al.Head is InReg) { InstrList.Add(new Move(t.A(count), ptr.Head)); ++count; } else { InstrList.Add(new Store(t.SP(), (al.Head as InFrame).Offset, ptr.Head)); } } } InstrList.Add(c); return(Frame.RV()); }
public Quadruple(MipsFrame frame) { Frame = frame; }
public CodeGen(List <TExp> instrList, Dictionary <Temp.Temp, Node> temp2Node, MipsFrame frame) { this.InstrList = instrList; this.TempToNode = temp2Node; this.Frame = frame; }
public InFrame(MipsFrame frame, int offset) { Frame = frame; Offset = offset; }