예제 #1
0
파일: IrCJump.cs 프로젝트: robin5/DemiTasse
 public IrCJump(AstRelop.OP o, IrExp l, IrExp r, IrName t)
 {
     left = l; right = r; target = t;
     switch (o)
     {
         case AstRelop.OP.EQ: op = OP.EQ; break;
         case AstRelop.OP.NE: op = OP.NE; break;
         case AstRelop.OP.LT: op = OP.LT; break;
         case AstRelop.OP.LE: op = OP.LE; break;
         case AstRelop.OP.GT: op = OP.GT; break;
         case AstRelop.OP.GE: op = OP.GE; break;
         default: Debug.Assert(false, "Encountered unknown binary operator: value = " + o.ToString()); break;
     }
 }
예제 #2
0
 public string opName(AstRelop.OP op)
 {
     switch (op)
     {
         case AstRelop.OP.EQ: return "== ";
         case AstRelop.OP.NE: return "!= ";
         case AstRelop.OP.LT: return "< ";
         case AstRelop.OP.LE: return "<= ";
         case AstRelop.OP.GT: return "> ";
         case AstRelop.OP.GE: return ">= ";
         default: return "?? ";
     }
 }
예제 #3
0
 // Relop ---
 // int op;
 // Exp e1, e2;
 public IrExp visit(AstRelop n)
 {
     IrExp l = n.e1.accept(this);
     IrExp r = n.e2.accept(this);
     IrStmtList sl = new IrStmtList();
     IrTemp tmp = new IrTemp();
     IrName done = new IrName();
     sl.add(new IrMove(tmp, cOne));
     sl.add(new IrCJump(n.op, l, r, done));
     sl.add(new IrMove(tmp, cZero));
     sl.add(new IrLabel(done));
     return new IrEseq(sl, tmp);
 }
예제 #4
0
        /* throws ParseException */
        /* final */
        public static AstExp astExp()
        {
            AstType t;
            AstToken n;
            AstRelop.OP relop;
            AstBinop.OP binop;
            AstUnop.OP unop;
            AstExp e, e1, e2;
            AstExpList el;

            jj_consume_token(AstRegExpId.kw56);
            switch ((jj_ntk == AstRegExpId.UNDEFINED)?jj_ntk_fn():jj_ntk) {
            case AstRegExpId.kwArrayElm:
              jj_consume_token(AstRegExpId.kwArrayElm);
              e1 = astExp();
              e2 = astExp();
                                  e = new AstArrayElm(e1,e2);
              break;
            case AstRegExpId.kwArrayLen:
              jj_consume_token(AstRegExpId.kwArrayLen);
              e1 = astExp();
                                  e = new AstArrayLen(e1);
              break;
            case AstRegExpId.kwBinop:
              jj_consume_token(AstRegExpId.kwBinop);
              binop = binOp();
              e1 = astExp();
              e2 = astExp();
                                  e = new AstBinop(binop,e1,e2);
              break;
            case AstRegExpId.kwBoolVal:
              jj_consume_token(AstRegExpId.kwBoolVal);
              switch ((jj_ntk == AstRegExpId.UNDEFINED)?jj_ntk_fn():jj_ntk) {
              case AstRegExpId.kwTrue:
            jj_consume_token(AstRegExpId.kwTrue);
                                  e = new AstBoolVal(true);
            break;
              case AstRegExpId.kwFalse:
            jj_consume_token(AstRegExpId.kwFalse);
                                  e = new AstBoolVal(false);
            break;
              default:
            jj_la1[12] = jj_gen;
            jj_consume_token(AstRegExpId.UNDEFINED);
            throw new AstParseException();
              }
              break;
            case AstRegExpId.kwCall:
              jj_consume_token(AstRegExpId.kwCall);
              e1 = astExp();
              e2 = astExp();
              el = astExpList();
                                  e = new AstCall(e1,(AstId)e2,el);
              break;
            case AstRegExpId.kwId:
              jj_consume_token(AstRegExpId.kwId);
              n = jj_consume_token(AstRegExpId.ID);
                                  e = new AstId(n.image);
              break;
            case AstRegExpId.kwIntVal:
              jj_consume_token(AstRegExpId.kwIntVal);
              n = jj_consume_token(AstRegExpId.INTVAL);
                                  e = new AstIntVal(int.Parse(n.image));
              break;
            case AstRegExpId.kwField:
              jj_consume_token(AstRegExpId.kwField);
              e1 = astExp();
              e2 = astExp();
                                  e = new AstField(e1,(AstId)e2);
              break;
            case AstRegExpId.kwNewArray:
              jj_consume_token(AstRegExpId.kwNewArray);
              t = astType();
              n = jj_consume_token(AstRegExpId.INTVAL);
              e = new AstNewArray((AstType)t, int.Parse(n.image));
              break;
            case AstRegExpId.kwNewObj:
              jj_consume_token(AstRegExpId.kwNewObj);
              e1 = astExp();
              el = astExpList();
                                  e = new AstNewObj((AstId)e1,el);
              break;
            case AstRegExpId.kwRelop:
              jj_consume_token(AstRegExpId.kwRelop);
              relop = relOp();
              e1 = astExp();
              e2 = astExp();
              e = new AstRelop(relop, e1, e2);
              break;
            case AstRegExpId.kwStrVal:
              jj_consume_token(AstRegExpId.kwStrVal);
              n = jj_consume_token(AstRegExpId.STRVAL);
                                  String s = n.image;
                                  e = new AstStrVal(s.Substring(1, s.Length-2));
              break;
            case AstRegExpId.kwThis:
              jj_consume_token(AstRegExpId.kwThis);
                                  e = new AstThis();
              break;
            case AstRegExpId.kwUnop:
              jj_consume_token(AstRegExpId.kwUnop);
              unop = unOp();
              e1 = astExp();
                                   e = new AstUnop(unop,e1);
              break;
            case AstRegExpId.kwNullExp:
              jj_consume_token(AstRegExpId.kwNullExp);
                                  e = null;
              break;

            default:
              jj_la1[13] = jj_gen;
              jj_consume_token(AstRegExpId.UNDEFINED);
              throw new AstParseException();
            }
            jj_consume_token(AstRegExpId.kw57);
            {if (true) return e;}
            throw new Error("Missing return statement in function");
        }
예제 #5
0
 public AstType visit(AstRelop n)
 {
     return null;
 }
예제 #6
0
        /* throws Exception */
        // Relop ---
        // int op;
        // Exp e1, e2;
        public AstType visit(AstRelop n)
        {
            AstType t1 = n.e1.accept(this);
            AstType t2 = n.e2.accept(this);

            if (n.op == AstRelop.OP.EQ || n.op == AstRelop.OP.NE)
            {
                if (compatible(t1,t2) || compatible(t2,t1))
                    return BoolType;
            }
            else if (isIntType(t1) && isIntType(t2))
            {
                return BoolType;
            }

            throw new TypeException("Incorrect operand types in Relop: " + t1 + n.opName(n.op) + t2);
        }