Ejemplo n.º 1
0
 public IrgenVisitor(SymbolTable symTable_, TypeVisitor tv_)
 {
     cOne = new IrConst(1);
     cZero = new IrConst(0);
     cWordSize = new IrName("wSZ");
     symTable = symTable_;
     tv = tv_;
     currClass = null;
     currMethod = null;
 }
Ejemplo n.º 2
0
 // NewArray ---
 // int size;
 public IrExp visit(AstNewArray n)
 {
     IrExp size = new IrConst(n.size);
     IrStmtList sl = new IrStmtList();
     IrName top = new IrName();
     IrTemp array = new IrTemp();
     IrTemp cnt = new IrTemp();
     IrExp bound = new IrBinop(IrBinop.OP.MUL, new IrConst(n.size + 1), cWordSize);
     sl.add(new IrMove(array, new IrCall(new IrName("malloc"), new IrExpList(bound))));
     sl.add(new IrMove(new IrMem(array), size));
     sl.add(new IrMove(cnt, new IrBinop(IrBinop.OP.ADD, array,
                    new IrBinop(IrBinop.OP.MUL, size, cWordSize))));
     sl.add(new IrLabel(top));
     sl.add(new IrMove(new IrMem(cnt), cZero));
     sl.add(new IrMove(cnt, new IrBinop(IrBinop.OP.SUB, cnt, cWordSize)));
     sl.add(new IrCJump(IrCJump.OP.GT, cnt, array, top));
     return new IrEseq(sl, array);
 }
Ejemplo n.º 3
0
        /* throws ParseException */
        public static IrExp EXP()
        {
            IrToken t;
            int n;
            String str;
            IrStmt s;
            IrExp e, e2;
            IrExpList el = new IrExpList();
            jj_consume_token(RegExpId.kw32);

            switch ((jj_ntk == RegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
            {
                case RegExpId.kwESEQ:

                    jj_consume_token(RegExpId.kwESEQ);
                    s = STMT();
                    e = EXP();
                    e = new IrEseq(s,e);
                    break;

                case RegExpId.kwMEM:

                    jj_consume_token(RegExpId.kwMEM);
                    e = EXP();
                    e = new IrMem(e);
                    break;

                case RegExpId.kwBINOP:

                    jj_consume_token(RegExpId.kwBINOP);
                    IrBinop.OP op = binopCode();
                    e = EXP();
                    e2 = EXP();
                    e = new IrBinop(op,e,e2);
                    break;

                case RegExpId.kwCALL:

                    jj_consume_token(RegExpId.kwCALL);
                    e = EXP();
                    jj_consume_token(RegExpId.kw32);
                    // label_4:
                    while (true)
                    {
                        switch ((jj_ntk == RegExpId.UNDEFINED) ? jj_ntk_fn() : jj_ntk)
                        {
                            case RegExpId.kw32:
                                break;

                            default:
                                jj_la1[7] = jj_gen;
                                goto label_4a; // break label_4;
                        }
                        e2 = EXP();
                        el.add(e2);
                    }
                    label_4a:

                    jj_consume_token(RegExpId.kw35);
                    e = new IrCall((IrName)e,el);
                    break;

                case RegExpId.kwTEMP:

                    jj_consume_token(RegExpId.kwTEMP);
                    n = INT();
                    e = new IrTemp(n);
                    break;

                case RegExpId.kwNAME:

                    jj_consume_token(RegExpId.kwNAME);
                    t = jj_consume_token(RegExpId.ID);
                    e = new IrName(t.image);
                    break;

                case RegExpId.kwFIELD:

                    jj_consume_token(RegExpId.kwFIELD);
                    e = EXP();
                    n = INT();
                    e = new IrField(e,n);
                    break;

                case RegExpId.kwPARAM:

                    jj_consume_token(RegExpId.kwPARAM);
                    n = INT();
                    e = new IrParam(n);
                    break;

                case RegExpId.kwVAR:

                    jj_consume_token(RegExpId.kwVAR);
                    n = INT();
                    e = new IrVar(n);
                    break;

                case RegExpId.kwCONST:

                    jj_consume_token(RegExpId.kwCONST);
                    n = INT();
                    e = new IrConst(n);
                    break;

                case RegExpId.kwSTRING:

                    jj_consume_token(RegExpId.kwSTRING);
                    str = STR();
                    e = new IrString(str);
                    break;

                default:

                    jj_la1[8] = jj_gen;
                    jj_consume_token(RegExpId.UNDEFINED);
                    throw new IrParseException();
            }

            jj_consume_token(RegExpId.kw35);
            {if (true) return e;}
            throw new Error("Missing return statement in function");
        }
Ejemplo n.º 4
0
 public int visit(IrConst t)
 {
     return t.val;
 }
Ejemplo n.º 5
0
 public IrExp visit(IrConst t)
 {
     return t;
 }