works?
This commit is contained in:
@ -190,7 +190,8 @@ void emit_binary_op(
|
||||
Op op,
|
||||
TableNode *result,
|
||||
TNodeOrConst *arg1,
|
||||
TNodeOrConst *arg2) {
|
||||
TNodeOrConst *arg2
|
||||
) {
|
||||
emit_helper();
|
||||
current->opcode = op;
|
||||
// TODO: create temp and remove result from param list
|
||||
@ -315,6 +316,9 @@ void emit_return(TNodeOrConst *value) {
|
||||
void emit_reserve(TableNode *result, TNodeOrConst *size) {
|
||||
// this needs to change
|
||||
// we need to take a int
|
||||
/*
|
||||
emit_binary_op(E_MUL, result,
|
||||
*/
|
||||
emit_parameter(size);
|
||||
emit_function_call(result, 1, tn_or_const(NODE, look_up(cur, "reserve")));
|
||||
}
|
||||
@ -345,8 +349,12 @@ void emit_address_of(TableNode *x, TNodeOrConst *y) {
|
||||
current->operand1 = y;
|
||||
}
|
||||
|
||||
void emit_field_access(char *result, char *record, char *field) {
|
||||
void emit_field_access(TableNode *result, TNodeOrConst *record, int offset){
|
||||
emit_helper();
|
||||
current->opcode = E_DEREF_RIGHT;
|
||||
current->result = result;
|
||||
current->operand1 = record;
|
||||
current->operand2 = tn_or_const(INTEGER, &offset);
|
||||
}
|
||||
|
||||
void emit_array_access(Op op, TableNode *result, TNodeOrConst *array, TNodeOrConst *index) {
|
||||
@ -587,19 +595,22 @@ void emit_as_file(FILE *out_file, Instruction *i) {
|
||||
getName(i->result),
|
||||
get_string(i->operand1));
|
||||
break;
|
||||
|
||||
case E_DEREF_RIGHT:
|
||||
fprintf(out_file,
|
||||
"%4.d: %s = *%s\n",
|
||||
"%4.d: %s = *((char * )%s + %s)\n",
|
||||
i->index,
|
||||
getName(i->result),
|
||||
get_string(i->operand1));
|
||||
get_string(i->operand1),
|
||||
get_string(i->operand2)
|
||||
);
|
||||
break;
|
||||
case E_DEREF_LEFT:
|
||||
fprintf(out_file,
|
||||
"%4.d: *%s = %s\n",
|
||||
i->index,
|
||||
getName(i->result),
|
||||
get_string(i->operand1));
|
||||
break;
|
||||
}
|
||||
|
||||
emit_as_file(out_file, i->next);
|
||||
@ -615,6 +626,12 @@ TableNode *getTN(TNodeOrConst *tnc) {
|
||||
int getConst(TNodeOrConst *tnc) {
|
||||
if (tnc->d == INTEGER) {
|
||||
return tnc->tnc_union->integer;
|
||||
} else if (tnc->d == CHARACTER) {
|
||||
return tnc->tnc_union->character;
|
||||
} else if (tnc->d == BOOLEAN) {
|
||||
return tnc->tnc_union->Boolean;
|
||||
} else if (tnc->d == ADDRESS) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user