I added some packpatching

This commit is contained in:
Meyer Simon
2025-04-30 08:20:11 -04:00
parent 0189c2d937
commit cd4393d052
6 changed files with 138 additions and 110 deletions

View File

@ -69,6 +69,13 @@ void emit_detach(){
current->next = NULL;
}
void backpatch(Stack *s, int l){
while (!S_IsEmpty(s)){
Instruction * i = S_Pop(s);
set_label(i, l);
}
}
TNodeOrConst * getOperand1(Instruction * i){
return i->operand1;
}
@ -480,21 +487,21 @@ void emit_as_file(FILE * out_file, Instruction * i){
case E_LESS_THAN:
// this feels wrong I need to TODO: this
fprintf(out_file,
"%4.d: %s = %s < %s\n",
"%4.d: if ( %s < %s ) GOTO %d\n",
i->index,
getName(i->result),
get_string(i->operand1),
get_string(i->operand2)
get_string(i->operand2),
i->label
);
break;
case E_EQUAL_TO:
// this feels wrong I need to TODO: this
fprintf(out_file,
"%4.d: %s = %s == %s\n",
"%4.d: if ( %s = %s ) GOTO %d\n",
i->index,
getName(i->result),
get_string(i->operand1),
get_string(i->operand2)
get_string(i->operand2),
i->label
);
break;
case E_CALL: