I made the IR compile
This commit is contained in:
@ -17,7 +17,7 @@ void S_Free(Stack *s){
|
||||
|
||||
void S_Push(Stack * s, void *v) {
|
||||
__Node * n = calloc(1, sizeof(*n));
|
||||
n->v = v
|
||||
n->v = v;
|
||||
n->next = s->n;
|
||||
s->n = n;
|
||||
s->size = s->size + 1;
|
||||
@ -55,8 +55,6 @@ int S_Size(Stack *s){
|
||||
}
|
||||
//_______________________________________________________________________
|
||||
|
||||
Instruction * begin;
|
||||
Instruction * current;
|
||||
char * temp = NULL;
|
||||
|
||||
|
||||
@ -287,7 +285,7 @@ void emit_address_of(TableNode * x, TNodeOrConst * y){
|
||||
emit_helper();
|
||||
current->opcode = E_ADDRESS_OF;
|
||||
current->result = x;
|
||||
current->opernad1 = y;
|
||||
current->operand1 = y;
|
||||
}
|
||||
|
||||
void emit_field_access(char* result, char* record, char* field){
|
||||
@ -340,18 +338,10 @@ void emit_bounds_check(TNodeOrConst * index, TNodeOrConst * arr){
|
||||
}
|
||||
|
||||
// * Implement temp variable generator function that produces unique names (t1, t2, etc.)
|
||||
char * temp_var_gen(){
|
||||
char * ret = calloc(9, sizeof(*ret));
|
||||
sprintf(ret, "$t%d", temp_count);
|
||||
temp_count++;
|
||||
return ret;
|
||||
}
|
||||
|
||||
char * label_gen(){
|
||||
char * ret = calloc( 9, sizeof(*ret));
|
||||
sprintf(ret, "L_%d", label_count);
|
||||
int label_gen(){
|
||||
label_count++;
|
||||
return ret;
|
||||
return label_count;
|
||||
}
|
||||
|
||||
void emit_as_file(FILE * out_file, Instruction * i){
|
||||
@ -569,4 +559,20 @@ void emit_as_file(FILE * out_file, Instruction * i){
|
||||
}
|
||||
|
||||
emit_as_file(out_file, i->next);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
TableNode* getTN(TNodeOrConst* tnc) {
|
||||
if (tnc->d == NODE) {
|
||||
return tnc->tnc_union->node;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int getConst(TNodeOrConst* tnc) {
|
||||
if (tnc->d == INTEGER) {
|
||||
return tnc->tnc_union->integer;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user