public static StmExpList Reorder(Tree.ExpList exps) { if (exps == null) { return(NopNull); } else { Tree.Expr a = exps.Head; if (a is Tree.CALL) { Temp.Temp t = new Temp.Temp(); Tree.Expr e = new Tree.ESEQ(new Tree.MOVE(new Tree.TEMP(t), a), new Tree.TEMP(t)); return(Reorder(new Tree.ExpList(e, exps.Tail))); } else { Tree.ESEQ aa = DoExp(a); StmExpList bb = Reorder(exps.Tail); if (Commute(bb.Stm, aa.Exp)) { return(new StmExpList(Seq(aa.Stm, bb.Stm), new Tree.ExpList(aa.Exp, bb.Exps))); } else { Temp.Temp t = new Temp.Temp(); return(new StmExpList( Seq(aa.Stm, Seq(new Tree.MOVE(new Tree.TEMP(t), aa.Exp), bb.Stm)), new Tree.ExpList(new Tree.TEMP(t), bb.Exps))); } } } }
public static Tree.ESEQ ReorderExp(Tree.Expr e) { StmExpList x = Reorder(e.Kids()); return(new Tree.ESEQ(x.Stm, e.Build(x.Exps))); }
static Tree.Stm ReorderStm(Tree.Stm s) { StmExpList x = Reorder(s.Kids()); return(Seq(x.Stm, s.Build(x.Exps))); }