Implemented the 2 operation functions #t51
This commit is contained in:
@ -1,3 +1,7 @@
|
|||||||
|
#include "intermediate_code.h"
|
||||||
|
|
||||||
|
|
||||||
|
start = current = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -7,10 +11,37 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
void emit_binary_op(char* result, char* op, char* arg1, char* arg2){
|
void emit_binary_op(char* result, Op op, char* arg1, char* arg2){
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
void emit_unary_op(char* result, char* op, char* arg){
|
void emit_unary_op(char* result, Oo op, char* arg){
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
void emit_assignment(char* target, char* source){
|
void emit_assignment(char* target, char* source){
|
||||||
|
@ -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);
|
||||||
|
Reference in New Issue
Block a user