Implemented the 2 operation functions #t51

This commit is contained in:
Meyer Simon
2025-04-02 11:28:23 -04:00
parent 05b641a32e
commit 1c7cdbb4da
2 changed files with 39 additions and 7 deletions

View File

@ -1,3 +1,7 @@
#include "intermediate_code.h"
start = current = NULL;
@ -7,11 +11,38 @@
void emit_binary_op(char* result, char* op, char* arg1, char* arg2){ void emit_binary_op(char* result, Op op, char* arg1, char* arg2){
return; Instruction * inst = calloc(1, sizeof(*inst));
if(start == NULL){
start = current = inst;
current->index = 1;
} else {
current->next = inst;
inst->prev = current;
inst->index = current->index++;
current = inst;
}
current->opcode = op;
current->result = look_up(result);
current->operand1 = look_up(arg1);
current->operand2 = look_up(arg2);
return;
} }
void emit_unary_op(char* result, char* op, char* arg){ void emit_unary_op(char* result, Oo op, char* arg){
return; Instruction * inst = calloc(1, sizeof(*inst));
if(start == NULL){
start = current = inst;
current->index = 1;
} else {
current->next = inst;
inst->prev = current;
inst->index = current->index++;
current = inst;
}
current->opcode = op;
current->result = look_up(result);
current->operand1 = look_up(arg);
return;
} }
void emit_assignment(char* target, char* source){ void emit_assignment(char* target, char* source){
return; return;

View File

@ -19,13 +19,14 @@ typedef struct {
TableNode * operand1; TableNode * operand1;
TableNode * operand2; TableNode * operand2;
int label; int label;
int instruction; int index;
Instruction * prev; Instruction * prev;
Instruction * next; Instruction * next;
} Instruction; } Instruction;
Instruction * start = NULL; Instruction * start;
Instruction * current = NULL; Instruction * current;
void emit_binary_op(char* result, char* op, char* arg1, char* arg2); void emit_binary_op(char* result, char* op, char* arg1, char* arg2);
void emit_unary_op(char* result, char* op, char* arg); void emit_unary_op(char* result, char* op, char* arg);