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 = 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); }
void make_operand(expr* e,struct vmarg* arg){ /*if(!e) { arg->type = nil_a; return; }*/ // printf("name:%s and type:%d\n",e->name); switch(e->type){ case var_e:{ arg->val = e->sym->offset; newvar(e->sym->offset,e->sym->name); switch(e->sym->space){ case programvar: arg->type = global_a; break; case functionlocal: arg->type = local_a; break; case formalarg: arg->type = formal_a; break; default: assert(0); } break; /*n from case newtable_e */ } case tableitem_e:{ arg->val = e->sym->offset; switch(e->sym->space){ case programvar: arg->type = global_a; break; case functionlocal: arg->type = local_a; break; case formalarg: arg->type = formal_a; break; default: assert(0); } break; /*n from case newtable_e */ } case boolexpr_e:{ arg->val = e->sym->offset; newvar(e->sym->offset,e->sym->name); switch(e->sym->space){ case programvar: arg->type = global_a; break; case functionlocal: arg->type = local_a; break; case formalarg: arg->type = formal_a; break; default: assert(0); } break; /*n from case newtable_e */ } case assignexpr_e:{ arg->val = e->sym->offset; newvar(e->sym->offset,e->sym->name); switch(e->sym->space){ case programvar: arg->type = global_a; break; case functionlocal: arg->type = local_a; break; case formalarg: arg->type = formal_a; break; default: assert(0); } break; /*n from case newtable_e */ } case newtable_e:{ arg->val = e->sym->offset; switch(e->sym->space){ case programvar: arg->type = global_a; break; case functionlocal: arg->type = local_a; break; case formalarg: arg->type = formal_a; break; default: assert(0); } break; /*n from case newtable_e */ } /* Constants */ case constbool_e:{ unsigned int temp = (unsigned int)e->boolConst; arg->val =e->boolConst; arg->type = bool_a; break; } case conststring_e:{ arg->val = consts_newstring(e->strConst); arg->type = string_a; break; } case constnum_e:{ arg->val = consts_newnumber(e->numConst); arg->type = number_a; break; } case nil_e: arg->type = nil_a; break; /* Functions */ case programfunc_e:{ // printf("in tcode address is:%d\n",e->sym->taddress); arg->val = userfuncs_newfunc(e->sym); arg->type = userfunc_a; break; } case libraryfunc_e:{ arg->type = libfunc_a; arg->val = libfuncs_newused(e->sym->name); break; } default: assert(0); } }
void make_operand(expr1 *e, vmarg *arg) { if(e==NULL) return; switch(e->type) { case var_e: case assignexpr_e: case tableitem_e: case arithmexpr_e: case booleanexpr_e: case newtable_e: { assert(e->sym); //arg->val = e->sym->offset; arg->val = uservars_newvar(e->sym); switch(e->sym->space) { case programVar: arg->type = global_a; break; case functionLocal: arg->type = local_a; break; case formalArg: arg->type = formal_a; break; default : assert(0); } break; } case constbool_e: { arg->val = e->boolConst; arg->type = bool_a; break; } case constchar_e: { arg->val = consts_newstring(e->strConst); arg->type = string_a; break; } case constnum_e: { arg->val = consts_newnumber(e->numConst); arg->type = number_a; break; } case nil_e: { arg->type = nil_a; break; } case programfunc_e: { arg->type = userfunc_a; //arg->val = e->sym->iaddress; arg->val = userfuncs_newfunc(e->sym); break; } case libraryfunc_e: { arg->type = libfunc_a; arg->val = libfuncs_newused(e->sym->value.funcVal->name); break; } default : assert(0); } }