Example #1
0
void generate(void){
		unsigned int i;
		for(i=0;i<nextquadlabel();i++){
			(*generators[quads[i].op])(quads+i);

		}
		patch_incomplete_jumps(nextquadlabel(), currInstruction);
}
Example #2
0
expr* logical_expr(listNode* truelist, listNode* falselist, expr* result){

    result = newexpr(boolexpr_e);
    result -> sym = newtemp();

    patchlabel(-1, nextquadlabel(), truelist);
    patchlabel(-1, nextquadlabel()+2, falselist);
    emit(ASSIGN, newexpr_constbool(1), NULL, result, 0, yylineno);
    emit(JUMP, NULL, NULL, NULL, nextquadlabel()+2, yylineno);
    emit(ASSIGN, newexpr_constbool(0), NULL, result, 0, yylineno);

    return result;
}
Example #3
0
expr* equal_op(iopcode op, expr* expr1, expr* expr2, expr* result){
    if(expr1->type == expr2->type){
        if (expr1 -> type == constnum_e){
            result = newexpr(boolexpr_e);
            result -> sym = newtemp();
            if(op == IF_EQ){
                result -> boolConst = expr1 -> numConst == expr2 -> numConst;
            }else{
                result -> boolConst = expr1 -> numConst != expr2 -> numConst;
            }
            emit(ASSIGN, newexpr_constbool(result -> boolConst), NULL, result, 0, yylineno);
        }else{
            result = newexpr(boolexpr_e);
            result -> sym = newtemp();
            emit(op, expr1, expr2, NULL, nextquadlabel()+3, yylineno);
            emit(ASSIGN, newexpr_constbool(0), NULL, result, 0, yylineno);
            emit(JUMP, NULL, NULL, NULL, nextquadlabel()+2, yylineno);
            emit(ASSIGN, newexpr_constbool(1), NULL, result, 0, yylineno);
        }
        return result;
    }else if((expr1 -> type == newtable_e && expr2 -> type == nil_e) ||
                (expr1 -> type == nil_e && expr2 -> type == newtable_e)){
        if(op == IF_EQ){
            result = newexpr(boolexpr_e);
            result -> sym = newtemp();
            // emit(op, expr1, expr2, NULL, nextquadlabel()+3, yylineno);
            emit(ASSIGN, newexpr_constbool(0), NULL, result, 0, yylineno);
            // emit(JUMP, NULL, NULL, NULL, nextquadlabel()+2, yylineno);
            // emit(ASSIGN, newexpr_constbool(1), NULL, result, 0, yylineno);
        }else{
            result = newexpr(boolexpr_e);
            result -> sym = newtemp();
            // emit(op, expr1, expr2, NULL, nextquadlabel()+3, yylineno);
            // emit(ASSIGN, newexpr_constbool(0), NULL, result, 0, yylineno);
            // emit(JUMP, NULL, NULL, NULL, nextquadlabel()+2, yylineno);
            emit(ASSIGN, newexpr_constbool(1), NULL, result, 0, yylineno);
        }
        return result;
    }
    return NULL;
}
Example #4
0
void patchIncJump(){
    incJump *tmp = malloc( sizeof( incJump ) );
    tmp = incJumpH;

    while( tmp != NULL ){
        if( tmp->instrAddress == nextquadlabel() ){
            VmargsTable[ tmp->instrNo ].result->val = nextInstructionLabel();
        }
        else{
            VmargsTable[ tmp->instrNo ].result->val = quads[ tmp->instrAddress].taddress;
        }
        tmp = tmp->next;
    }

    return;
} 
Example #5
0
void patch_incomplete_jumps()
{
	if(ij_head==NULL)
		return;
	
	incomplete_jump *tmpHead = ij_head;
	
	while(tmpHead!=NULL)
	{
		if (tmpHead->iaddress == nextquadlabel() )
		{
			instructions[tmpHead->instrNo].result->type = label_a;
			instructions[tmpHead->instrNo].result->val = currproccessedquad()+1;
		}
		else
		{
			instructions[tmpHead->instrNo].result->type = label_a;
			instructions[tmpHead->instrNo].result->val = quads[tmpHead->iaddress].taddress;
		}
		tmpHead = tmpHead->next;
	}
}
Example #6
0
void relation_expr(listNode* truelist, listNode* falselist){
    patchlabel(-1, nextquadlabel(), truelist);
    patchlabel(-1, nextquadlabel()+2, falselist);
}