void generate_NOT( quad *quad ){ quad->taddress = nextInstructionLabel(); instruction *t = InitInstruction(); instruction *t1 = InitInstruction(); instruction *t2 = InitInstruction(); instruction *t3 = InitInstruction(); t->opcode = jeq_v; make_operand( quad->arg1, t->arg1 ); make_booloperand( t->arg2, 1 ); t->result->type = label_a; t->result->val = nextInstructionLabel()+3; emitVmarg( t ); t1->opcode = assign_v; make_booloperand( t1->arg1, 1 ); //reset_operand( t->arg2 ); make_operand( quad->result, t1->result ); emitVmarg( t1 ); t2->opcode = jump_v; //reset_operand( t1->arg1 ); //reset_operand( t1->arg2 ); t2->result->type = label_a; t2->result->val = nextInstructionLabel()+2; emitVmarg( t2 ); t2->opcode = assign_v; make_booloperand( t2->arg1, 0 ); reset_operand( t2->arg2 ); make_operand( quad->result, t2->result ); emitVmarg( t2 ); }
void generate_OR (quad* quad) { quad->taddress = nextinstructionlabel(); struct instruction t; t.opcode = jeq_v; make_operand(quad->arg1, &t.arg1); make_booloperand(&t.arg2, '1'); t.result.type = label_a; t.result.val = nextinstructionlabel()+4; emit_instruction(&t); make_operand(quad->arg2, &t.arg1); t.result.val = nextinstructionlabel()+3; emit_instruction(&t); t.opcode = assign_v; make_booloperand(&t.arg1, '0'); reset_operand(&t.arg2); make_operand(quad->result, &t.result); emit_instruction(&t); t.opcode = jump_v; reset_operand (&t.arg1); reset_operand(&t.arg2); t.result.type = label_a; t.result.val = nextinstructionlabel()+2; emit_instruction(&t); t.opcode = assign_v; make_booloperand(&t.arg1, '1'); reset_operand(&t.arg2); make_operand(quad->result, &t.result); emit_instruction(&t); }
void generate_relational(vmopcode op,quad *quad){ instruction *t = (instruction *)malloc(sizeof(instruction)); t->arg1 = malloc(sizeof(vmarg)); t->arg2 = malloc(sizeof(vmarg)); vmarg *result = make_vmarg(); t->opcode = op; if (quad->arg1) make_operand(quad->arg1,t->arg1); if (quad->arg2) make_operand(quad->arg2,t->arg2); result->type = label_a; t->srcLine = quad->line; if(quad->label < currProcessedQuad()){ result->val = (quads+quad->label)->taddress; } else{ addIncJump(quad->label,nextInstructionLabel()); } t->result = result; quad->taddress = nextInstructionLabel(); t->srcLine = quad->line; emitVmarg(t); }
void generate_relational(iopcode op, quad *q) { instruction t; init_instruction(&t); t.opcode = op; // # WARNING t.srcLine = q->line; make_operand(q->arg1, t.arg1); make_operand(q->arg2, t.arg2); t.result->type = label_a; if(q->label < currproccessedquad()) { t.result->val = quads[q->label].taddress; } else { add_incomplete_jump(nextinstructionlabel(), q->label); } q->taddress = nextinstructionlabel(); emit_icode(t); }
void generate (vmopcode op, quad *q){ instruction *t = (instruction *) malloc (sizeof(instruction)); q->taddress = NEXTINSTRUCTIONLABEL; t->srcLine= q->line; t->opcode = op; if(q->arg1) make_operand(q->arg1, &(t->arg1)); if(q->arg2) make_operand(q->arg2, &(t->arg2)); if(q->result) make_operand(q->result, &(t->result)); emit_t(t); }
void generate_instr(enum vmopcode op,quad* quad){ struct instruction t; t.opcode = op; if(op==23){ printf("element:%lf,type:%d\n",quad->arg1->numConst,quad->arg1->type ); } make_operand(quad->arg1, &(t.arg1)); make_operand(quad->arg2, &(t.arg2)); make_operand(quad->result, &(t.result)); quad->taddress = nextinstructionlabel(); emit_instruction(&t); }
void generate_UMINUS(quad *quad){ quad->taddress = nextInstructionLabel(); instruction *t = (instruction *)malloc(sizeof(instruction)); t->arg1 = malloc(sizeof(vmarg)); t->result = malloc(sizeof(vmarg)); t->opcode = mul_v; make_operand(quad->arg1, t->arg1); t->arg2 = make_integeroperand(-1); make_operand(quad->result, t->result); t->srcLine = quad->line; emitVmarg(t); }
void generate_AND(quad *q) { q->taddress = nextinstructionlabel(); instruction t1, t2, t3, t4, t5; init_instruction(&t1); init_instruction(&t2); init_instruction(&t3); init_instruction(&t4); init_instruction(&t5); t1.srcLine = q->line; t1.opcode = ieq_v; make_operand(q->arg1, t1.arg1); make_booloperand(t1.arg2, 0); t1.result->type = label_a; t1.result->val = nextinstructionlabel()+4; emit_icode(t1); t2.opcode = ieq_v; t2.srcLine = q->line; make_booloperand(t2.arg2, 0); make_operand(q->arg2, t2.arg1); t2.result->type = label_a; t2.result->val = nextinstructionlabel()+3; emit_icode(t2); t3.opcode = assign_v; t3.srcLine = q->line; make_booloperand(t3.arg1, 1); make_operand(q->result, t3.result); emit_icode(t3); t4.opcode = jump_v; t4.srcLine = q->line; t4.result->type = label_a; t4.result->val = nextinstructionlabel()+2; emit_icode(t4); t5.opcode = assign_v; t5.srcLine = q->line; make_booloperand(t5.arg1, 0); make_operand(q->result, t5.result); emit_icode(t5); }
void generate_AND( quad *quad ){ instruction *t = InitInstruction(); instruction *t1 = InitInstruction(); instruction *t2 = InitInstruction(); instruction *t3 = InitInstruction(); instruction *t4 = InitInstruction(); quad->taddress = nextInstructionLabel(); t->opcode = jeq_v; make_operand( quad->arg1, t->arg1 ); make_booloperand( t->arg2, 0); t->result->type = label_a; t->result->val = nextInstructionLabel()+4; emitVmarg( t ); t1->opcode = jeq_v; make_operand(quad->arg2,t1->arg1); make_booloperand(t1->arg2,0); t1->result = make_vmarg(); (t1->result)->val = nextInstructionLabel()+3; (t1->result)->type = label_a; emitVmarg( t1 ); t2->opcode = assign_v; make_booloperand(t2->arg1,1); t2->arg2 = reset_operand(); make_operand(quad->result,t2->result); t2->srcLine = quad->line; emitVmarg(t2); t3->opcode = jump_v; t3->arg1 = reset_operand(); t3->arg2 = reset_operand(); t3->result = make_vmarg(); (t3->result)->type = label_a; (t3->result)->val = nextInstructionLabel()+2; t3->srcLine = quad->line; emitVmarg(t3); t4->opcode = assign_v; make_booloperand(t4->arg1,0); t4->arg2 = reset_operand(); make_operand(quad->result,t4->result); t4->srcLine = quad->line; emitVmarg(t4); return; }
void generate_relational (int op,quad* quad) { struct instruction t; t.opcode = op; // printf("arg1:%d,arg2:%d\n", quad->arg1->boolConst,quad->arg2->boolConst); make_operand(quad->arg1, &t.arg1); make_operand(quad->arg2, &t.arg2); t.result.type = label_a; if (quad->label < currprocessedquad()) t.result.val = (quads+quad->label)->taddress; else add_incomplete_jump(nextinstructionlabel(), quad->label); quad->taddress = nextinstructionlabel(); emit_instruction(&t); }
void generate_relational (vmopcode op, quad *q){ instruction *t = (instruction *) malloc (sizeof(instruction)); q->taddress = NEXTINSTRUCTIONLABEL; t->srcLine= q->line; t->opcode = op; if(q->arg1) make_operand(q->arg1, &(t->arg1)); if(q->arg2) make_operand(q->arg2, &(t->arg2)); t->result.type = label_a; if(q->label < CURRPROCESSEDQUAD){ t->result.val = Quads[q->label].taddress; } else { LIST_INSERT(ij_head, INCJMPSTATEMENT(NEXTINSTRUCTIONLABEL, q->label), incomplete_jump, ADD_2_FRONT); } emit_t(t); }
void generate(iopcode op, quad *q) { instruction t; init_instruction(&t); t.opcode = op; // # WARNING t.srcLine = q->line; make_operand(q->arg1, t.arg1); make_operand(q->arg2, t.arg2); make_operand(q->result, t.result); q->taddress = nextinstructionlabel(); emit_icode(t); }
void generate_FUNCSTART( quad* quad ){ Symbol *funSymbol = malloc( sizeof( Symbol ) ); funSymbol = createS( quad->result->sym->name, 0, 0, quad->result->sym->name, 0, 0, "func", 0, 0, 0); instruction *t = malloc( sizeof( instruction ) ); t->opcode = jump_v; reset_operand(t->arg1); reset_operand(t->arg2); t->result = make_vmarg(); (t->result)->type = label_a; (t->result)->val = nextInstructionLabel(); t->srcLine = quad->line; emitVmarg( t ); funSymbol = (quad->result)->sym; funSymbol->taddress = nextInstructionLabel(); quad->taddress = nextInstructionLabel(); funSymbol->line = 0; AddFunctionUserElem(funSymbol); pushSym(funSymbol); instruction *t1 = (instruction *)malloc(sizeof(instruction)); t1->result = (vmarg *)malloc(sizeof(vmarg)); t1->opcode = funcenter_v; make_operand(quad->result, t1->result); reset_operand(t1->arg1); reset_operand(t1->arg2); t1->srcLine = quad->line; emitVmarg(t1); }
void generate_FUNCSTART(quad* quad){ struct instruction t0; t0.arg1.type = nil_a; t0.arg2.type = nil_a; t0.result.type= label_a; t0.result.val = 0; t0.opcode = jump_v; add_func_jump(nextinstructionlabel()); emit_instruction(&t0); struct userfunc* f; f = (struct userfunc*)malloc(sizeof(struct userfunc)); f->id=quad->result->sym->name; f->address = nextinstructionlabel(); quad->taddress = nextinstructionlabel(); userfuncs_newfunc(quad->result->sym); //added 6/5 ore (userFuncs+totalUserFuncs)->address = f->address; (userFuncs+totalUserFuncs)->id = f->id; (userFuncs+totalUserFuncs)->localSize = quad->result->sym->totallocals; f->index = totalUserFuncs-1; funcpush(f); struct instruction t; totalUserFuncs++; t.arg1.type = nil_a; t.arg2.type = nil_a; t.opcode = funcenter_v; make_operand(quad->result, &t.result); t.result.val = totalUserFuncs-1; //EDW emit_instruction(&t); }
void generate_FUNCSTART(quad *q){ SymbolTableEntry *f; instruction * t; if (funcStack == NULL) funcStack = newStack_func(); if(q->result) f = q->result->sym; f->taddress = NEXTINSTRUCTIONLABEL; LIST_INSERT(f->returnList, LABELSTATEMENT(NEXTINSTRUCTIONLABEL), returnElem, ADD_2_BACK); q->taddress = NEXTINSTRUCTIONLABEL; LIST_INSERT(userFuncs, FUNCTIONSTATEMENT(f->taddress+1, f->totallocals, f->value.funcVal->name), userfunc, ADD_2_BACK); push_func(funcStack, f); totalUserFuncs++; t = (instruction *) malloc (sizeof(instruction)); t->opcode = jump_v; RESET_OPERAND(&(t->arg1)); RESET_OPERAND(&(t->arg2)); t->result.type = label_a; emit_t(t); t = (instruction *) malloc (sizeof(instruction)); t->srcLine= q->line; t->opcode = funcenter_v; if(q->result) make_operand(q->result, &(t->result)); emit_t(t); }
void generate_RETURN(quad *quad){ quad->taddress = nextInstructionLabel(); instruction *t = (instruction *)malloc(sizeof(instruction)); instruction *t1 = (instruction *)malloc(sizeof(instruction)); t->arg1 = malloc(sizeof(vmarg)); t->result = malloc(sizeof(vmarg)); t1->result = malloc(sizeof(vmarg)); funcs *fun; if(quad->result!=NULL){ t->opcode = assign_v; make_retvaloperand(t->result); make_operand(quad->result, t->arg1); reset_operand(t->arg2); t->srcLine = quad->line; emitVmarg(t); } fun = topSym(); fun->nodeR = appendR(fun->nodeR,nextInstructionLabel()); t1->opcode = jump_v; reset_operand(t1->arg1); reset_operand(t1->arg2); t->arg1 = malloc(sizeof(vmarg)); make_retvaloperand(t1->result); (t1->result)->type = label_a; t1->srcLine = quad->line; emitVmarg(t1); }
void generate_GETRETVAL(quad* quad) { quad->taddress = nextinstructionlabel(); struct instruction t; t.opcode = assign_v; make_operand(quad->result, &t.result); make_retvaloperand(&t.arg1); emit_instruction(&t); }
void generate_CALL(quad *q){ instruction * t = (instruction *) malloc (sizeof(instruction)); q->taddress = NEXTINSTRUCTIONLABEL; t->srcLine= q->line; t->opcode = call_v; if(q->result) make_operand(q->result,&(t->result)); emit_t(t); }
void generate_GETRETVAL(quad *q){ instruction * t = (instruction *) malloc (sizeof(instruction)); q->taddress = NEXTINSTRUCTIONLABEL; t->srcLine= q->line; t->opcode = assign_v; if(q->result) make_operand(q->result,&(t->result)); make_retvaloperand(&(t->arg1)); emit_t(t); }
void generate_CALL(quad* quad) { quad->taddress = nextinstructionlabel(); struct instruction t; t.opcode = call_v; t.arg1.type = nil_a; t.arg2.type = nil_a; make_operand(quad->result, &t.result); emit_instruction(&t); }
void generate(vmopcode op ,quad * quad ){ instruction *t = malloc(sizeof(instruction)); t->arg1 = malloc(sizeof(vmarg)); t->arg2 = malloc(sizeof(vmarg)); t->result = malloc(sizeof(vmarg)); t->opcode = op; if (quad->arg1 && t->arg1){ make_operand( quad->arg1, t->arg1 ); } if (quad->arg2 && t->arg2){ make_operand( quad->arg2, t->arg2 ); } if (quad->result && t->result){ make_operand( quad->result, t->result ); } //printf("VAR SCOPE NAME2:%d\n",t->result->val); t->srcLine = quad->line ; quad->taddress = nextInstructionLabel(); emitVmarg( t ); }
void generate_PARAM(quad *quad){ quad->taddress = nextInstructionLabel(); instruction *t = (instruction *)malloc(sizeof(instruction)); t->result = malloc(sizeof(vmarg)); t->opcode = pusharg_v; make_operand(quad->result, t->result); reset_operand(t->arg1); reset_operand(t->arg2); t->srcLine = quad->line; emitVmarg(t); }
void generate_GETRETVAL(quad *q) { q->taddress = nextinstructionlabel(); instruction t; init_instruction(&t); t.srcLine = q->line; t.opcode = assign_v; make_operand(q->arg1, t.arg1); make_retvaloperand(t.result); emit_icode(t); }
void generate_CALL(quad *q) { q->taddress = nextinstructionlabel(); instruction t; init_instruction(&t); t.srcLine = q->line; t.opcode = call_v; make_operand(q->arg1, t.arg1); emit_icode(t); }
void generate_FUNCEND(quad *q){ SymbolTableEntry *f; instruction * t = (instruction *) malloc (sizeof(instruction)); f = pop_func(funcStack); backpatchReturn(f->returnList, NEXTINSTRUCTIONLABEL); q->taddress = NEXTINSTRUCTIONLABEL; t->srcLine= q->line; t->opcode = funcexit_v; if(q->result) make_operand(q->result, &(t->result)); emit_t(t); }
void generate_FUNCEND(quad* quad){ struct userfunc* f; f=funcpop(funcstack); patch_returns(f->returnList, nextinstructionlabel()); quad->taddress = nextinstructionlabel(); struct instruction t; t.opcode = funcexit_v; t.arg1.type = nil_a; t.arg2.type = nil_a; make_operand(quad->result, &t.result); t.result.val = f->index; patch_func_jump(quad->taddress); emit_instruction(&t); }
void generate_CALL( quad* quad ){ quad->taddress = nextInstructionLabel(); ///print///printf("QUAD FUNC NUM: %d",quad->line ); instruction *t = malloc( sizeof( instruction ) ); t->result = malloc(sizeof(vmarg)); t->opcode = call_v; make_operand( quad->result, t->result ); reset_operand(t->arg1); reset_operand(t->arg2); t->srcLine = quad->line; t->result->val = FindFunctionUser((quad->result->sym)->name,deepestFunctionScope); if (t->result->val == -1){ if(isLibFunction((quad->result->sym)->name)){ int check = FindLibFunction((quad->result->sym)->name); if (check == -1){ instruction *t1 =(instruction *) InitInstruction(); expr * e = malloc(sizeof(expr)); e->type = libraryfunc_e; e->sym =createS( (quad->result->sym)->name, 0, 0, (quad->result->sym)->name, 0, 0, "lib_func", 1,currscopespace(),currscopeoffset()); make_operand(e,t1->arg1); } t->result->val = FindLibFunction((quad->result->sym)->name); t->result->type = libfunc_a; emitVmarg( t ); } } else { emitVmarg( t ); } return; }
void generate_FUNCEND(quad *q) { SymbolTableEntry *f = pop_func(funcstack); backpatch_returnList(f->returnList, nextinstructionlabel()); q->taddress = nextinstructionlabel(); instruction t; init_instruction(&t); t.srcLine = q->line; t.opcode = funcexit_v; make_operand(q->arg1, t.arg1); emit_icode(t); }
void generate_GETRETVAL( quad* quad ){ quad->taddress = nextInstructionLabel(); instruction *t = malloc( sizeof( instruction ) ); t->result = malloc(sizeof(vmarg)); t->opcode = getretval_v; make_operand( quad->result ,t->result); reset_operand(t->arg1);/////////Vervelak XXX reset_operand(t->arg2); t->srcLine = quad->line; emitVmarg( t ); return; }
void generate_FUNCSTART(quad *q) { SymbolTableEntry *f = q->arg1->sym; f->iaddress = nextinstructionlabel(); q->taddress = nextinstructionlabel(); userfuncs_newfunc(f); push_func(funcstack, f); instruction t; init_instruction(&t); t.srcLine = q->line; t.opcode = funcenter_v; make_operand(q->arg1, t.arg1); emit_icode(t); }