/* throws ParseException */ public static IrStmt STMT() { IrToken t; IrCJump.OP n; IrStmt s; IrExp e1 = null, e2, e3; IrExpList el=new IrExpList(); jj_consume_token(RegExpId.kw44); switch ((jj_ntk == RegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk) { case RegExpId.kwMOVE: jj_consume_token(RegExpId.kwMOVE); e1 = EXP(); e2 = EXP(); s = new IrMove(e1,e2); break; case RegExpId.kwJUMP: jj_consume_token(RegExpId.kwJUMP); e1 = EXP(); s = new IrJump((IrName)e1); break; case RegExpId.kwCJUMP: jj_consume_token(RegExpId.kwCJUMP); n = relopCode(); e1 = EXP(); e2 = EXP(); e3 = EXP(); s = new IrCJump(n,e1,e2,(IrName)e3); break; case RegExpId.kwLABEL: jj_consume_token(RegExpId.kwLABEL); t = jj_consume_token(RegExpId.ID); s = new IrLabel(t.image); break; case RegExpId.kwCALLST: jj_consume_token(RegExpId.kwCALLST); e1 = EXP(); jj_consume_token(RegExpId.kw32); RegExpId tmp2; //label_3: while (true) { tmp2 = (jj_ntk == RegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk; switch (tmp2) { case RegExpId.kw32: break; default: jj_la1[3] = jj_gen; goto label_3a; // break label_3; } e2 = EXP(); el.add(e2); } label_3a: jj_consume_token(RegExpId.kw35); s = new IrCallst((IrName)e1,el); break; case RegExpId.kwRETURN: jj_consume_token(RegExpId.kwRETURN); switch ((jj_ntk == RegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk) { case RegExpId.kw32: e1 = EXP(); break; default: jj_la1[4] = jj_gen; break; } s = new IrReturn(e1); break; default: jj_la1[5] = jj_gen; jj_consume_token(RegExpId.UNDEFINED); throw new IrParseException(); } jj_consume_token(RegExpId.kw45); return s; //throw new Error("Missing return statement in function"); //return s; }
public int visit(IrCJump s) { bool cond; int left = s.left.accept(this); int right = s.right.accept(this); switch (s.op) { case IrCJump.OP.EQ: cond = (left == right); break; case IrCJump.OP.NE: cond = (left != right); break; case IrCJump.OP.LT: cond = (left < right); break; case IrCJump.OP.LE: cond = (left <= right); break; case IrCJump.OP.GT: cond = (left > right); break; case IrCJump.OP.GE: cond = (left >= right); break; default: throw new Exception("Encountered invalid CJUMP op value"); } if (cond) return findStmtIdx(s.target); else return STATUS_DEFAULT; }
public IrStmt visit(IrCJump t) { IrExp left = t.left.accept(this); IrExp right = t.right.accept(this); IrStmt s = mergeStmts(getStmt(left), getStmt(right)); if (s != null) return mergeStmts(s, new IrCJump(t.op, getExp(left), getExp(right), t.target)); return t; }