Exemplo n.º 1
0
  // Ast0.Block ---
  // Ast0.Stmt[] stmts;
  //
  // AG:
  //   code: {stmt.c}
  //
  static List<IR0.Inst> gen(Ast0.Block n) throws Exception {
    List<IR0.Inst> code = new ArrayList<IR0.Inst>();

    // ... need code ...
    for (Ast0.Stmt s : n.stmts) code.addAll(gen(s));
    return code;
  }
Exemplo n.º 2
0
  // Ast0.Assign ---
  // Ast0.Id lhs;
  // Ast0.Exp rhs;
  //
  // AG:
  //   code: rhs.c + "lhs.s = rhs.v"
  //
  static List<IR0.Inst> gen(Ast0.Assign n) throws Exception {
    List<IR0.Inst> code = new ArrayList<IR0.Inst>();

    // ... need code ...
    CodePack rhs = gen(n.rhs);
    code.addAll(rhs.code);
    code.add(new IR0.Move(new IR0.Id(n.lhs.nm), rhs.src));
    return code;
  }
Exemplo n.º 3
0
  // Ast0.Print ---
  // Ast0.Exp arg;
  //
  // AG:
  //   code: arg.c + "print (arg.v)"
  //
  static List<IR0.Inst> gen(Ast0.Print n) throws Exception {
    List<IR0.Inst> code = new ArrayList<IR0.Inst>();

    // ... need code ...
    CodePack arg = gen(n.arg);
    code.addAll(arg.code);
    code.add(new IR0.Print(arg.src));
    return code;
  }
Exemplo n.º 4
0
  // Ast0.Unop ---
  // Ast0.UOP op;
  // Ast0.Exp e;
  //
  // AG:
  //   newTemp: t
  //   code: e.c + "t = op e.v"
  //
  static CodePack gen(Ast0.Unop n) throws Exception {
    List<IR0.Inst> code = new ArrayList<IR0.Inst>();

    // ... need code ...
    IR0.Temp temp = new IR0.Temp();
    CodePack e = gen(n.e);
    code.addAll(e.code);
    IR0.UOP op = gen(n.op);
    code.add(new IR0.Unop(op, temp, e.src));
    return new CodePack(temp, code);
  }
Exemplo n.º 5
0
  // This is a helper used by both the Function and Script cases
  private void instrumentStmtList(List<Stmt> stmts) {
    // insert the counter initialization statement as the first statement,
    // and the counter display as the last statement
    stmts.insertChild(init(), 0);
    stmts.addChild(display());

    // recurse on children
    caseASTNode(stmts);

    skip.clear();
  }
Exemplo n.º 6
0
  // Ast0.Binop ---
  // Ast0.BOP op;
  // Ast0.Exp e1,e2;
  //
  // AG:
  //   newTemp: t
  //   code: e1.c + e2.c
  //         + "t = e1.v op e2.v"
  //
  static CodePack gen(Ast0.Binop n) throws Exception {
    List<IR0.Inst> code = new ArrayList<IR0.Inst>();

    // ... need code ...
    IR0.Temp temp = new IR0.Temp();
    CodePack e1 = gen(n.e1);
    CodePack e2 = gen(n.e2);
    code.addAll(e1.code);
    code.addAll(e2.code);
    IR0.BOP op = gen(n.op);
    code.add(new IR0.Binop(op, temp, e1.src, e2.src));
    return new CodePack(temp, code);
  }
Exemplo n.º 7
0
  // Ast0.If ---
  // Ast0.Exp cond;
  // Ast0.Stmt s1, s2;
  //
  // AG:
  //   newLabel: L1[,L2]
  //   code: cond.c
  //         + "if cond.v == false goto L1"
  //         + s1.c
  //         [+ "goto L2"]
  //         + "L1:"
  //         [+ s2.c]
  //         [+ "L2:"]
  //
  static List<IR0.Inst> gen(Ast0.If n) throws Exception {
    List<IR0.Inst> code = new ArrayList<IR0.Inst>();

    // ... need code ...
    IR0.Label L1 = new IR0.Label();
    IR0.Label L2 = new IR0.Label();
    CodePack cond = gen(n.cond);
    code.add(new IR0.LabelDec(L1));
    code.addAll(cond.code);
    code.add(new IR0.CJump(IR0.ROP.EQ, cond.src, IR0.FALSE, L1));
    for (IR0.Inst s : gen(n.s1)) code.add(s);
    if (n.s2 != null) code.add(new IR0.Jump(L2));
    code.add(new IR0.LabelDec(L1));
    if (n.s2 != null) {
      for (IR0.Inst s : gen(n.s2)) code.add(s);
      code.add(new IR0.LabelDec(L2));
    }

    return code;
  }
 public List<Expr> genList(Expr... elements) {
   List<Expr> list = new List<Expr>();
   for (Expr element : elements) list.add(element);
   return list;
 }
 public <T extends ASTNode> List<T> genList(T... elements) {
   List<T> list = new List<T>();
   for (T element : elements) list.add(element);
   return list;
 }
 /**
  * generate list of {@link Expr} for params
  *
  * @param params
  * @return
  */
 public List<Expr> generateArgs(List<ParameterDeclaration> params) {
   List<Expr> args = new List<Expr>();
   for (int y = 0; y < params.getNumChild(); y++)
     args.add(new VarAccess(params.getChild(y).getID()));
   return args;
 }
Exemplo n.º 11
0
 // Ast0.Program ---
 // Ast0.Stmt[] stmts;
 //
 // AG:
 //   code: stmts.c  -- append all individual stmt.c
 //
 public static IR0.Program gen(Ast0.Program n) throws Exception {
   List<IR0.Inst> code = new ArrayList<IR0.Inst>();
   for (Ast0.Stmt s : n.stmts) code.addAll(gen(s));
   return new IR0.Program(code);
 }
Exemplo n.º 12
0
 private java.util.List<ParseName> getSubjects(List<Access> subjectTypes) {
   java.util.List<ParseName> types = new ArrayList();
   for (int i = 0; i < subjectTypes.getNumChildNoTransform(); i++)
     types.add((ParseName) subjectTypes.getChildNoTransform(i));
   return types;
 }