Пример #1
0
        public int visit(IrMove s)
        {
            int rVal = s.src.accept(this);
            int lVal;

            if (s.dst is IrTemp) {

                lVal = getLValue((IrTemp) s.dst);
                temps[lVal] = rVal;

            } else if (s.dst is IrMem) {

                lVal = GetMemAddress((IrMem) s.dst);
                heap[lVal] = rVal;

            } else if (s.dst is IrField) {

                lVal = GetFieldAddress((IrField) s.dst);
                heap[lVal] = rVal;

            } else if (s.dst is IrParam) {

                lVal = GetParamAddress((IrParam) s.dst);
                stack[lVal] = rVal;
            } else if (s.dst is IrVar) {

                lVal = GetVarAddress((IrVar) s.dst);
                stack[lVal] = rVal;
            }
            return STATUS_DEFAULT;
        }
Пример #2
0
 public IrStmt visit(IrMove t)
 {
     IrExp dst = t.dst.accept(this);
     IrExp src = t.src.accept(this);
     IrStmt s = mergeStmts(getStmt(dst), getStmt(src));
     if (s != null)
         return mergeStmts(s, new IrMove(getExp(dst), getExp(src)));
     return t;
 }
Пример #3
0
        /* 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;
        }
Пример #4
0
 public IrExp visit(IrCall t)
 {
     IrExp args = t.args.accept(this);
     IrStmt s = getStmt(args);
     if (t.func.id != "malloc")
     {
         IrTemp tmp = new IrTemp();
         IrStmt s1 = new IrMove(tmp, new IrCall(t.func, (IrExpList)getExp(args)));
         return new IrEseq(mergeStmts(s, s1), tmp);
     }
     else if (s != null)
     {
         return new IrEseq(s, new IrCall(t.func, (IrExpList)getExp(args)));
     }
     else
     {
         return t;
     }
 }