Added body of some of the functions (not compiling) #t51

This commit is contained in:
Meyer Simon
2025-04-04 04:43:36 -04:00
parent 1c7cdbb4da
commit f7d1d90856
2 changed files with 90 additions and 38 deletions

View File

@ -1,85 +1,113 @@
#include <stdio.h>
#include "intermediate_code.h"
#include "symbol_table.h"
start = current = NULL;
Instruction * begin;
Instruction * current;
// TODO: this is here to bring your attention to the comment bellow.
// check if start is NULL if it is assign it to the start globle variable
// otherwise make it next of current and set cur to your instruction.
void emit_helper(void){
Instruction * inst = calloc(1, sizeof(*inst));
if(begin == NULL){
begin = current = inst;
current->index = 1;
} else {
current->next = inst;
inst->prev = current;
inst->index = current->index++;
current = inst;
}
}
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;
}
emit_helper();
current->opcode = op;
current->result = look_up(result);
current->operand1 = look_up(arg1);
current->operand2 = look_up(arg2);
current->result = look_up(cur, result);
current->operand1 = look_up(cur, arg1);
current->operand2 = look_up(cur, arg2);
return;
}
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;
}
void emit_unary_op(char* result, Op op, char* arg){
emit_helper();
current->opcode = op;
current->result = look_up(result);
current->operand1 = look_up(arg);
current->result = look_up(cur, result);
current->operand1 = look_up(cur, arg);
return;
}
void emit_assignment(char* target, char* source){
return;
emit_helper();
current->opcode = ADD; // TODO: replace with move
current->result = look_up(cur, target);
current->operand1 = look_up(cur, source);
return;
}
void emit_as_file(FILE * out_file, Instruction * instr_arr){
if(instr_arr == NULL){
return;
}
//fprintf(out_file,
return;
}
void emit_label(char* label){
emit_helper();
current->opcode = LABEL;
current->label = label;
return;
}
void emit_jump(char* label){
emit_helper();
current->opcode = GOTO;
current->label = label;
return;
}
void emit_conditional_jump(char* condition, char* label){
emit_helper();
current->opcode = CGOTO; // I am positive this needs to be 2 instructions
current->label = label;
return;
}
void emit_function_start(char* name){
emit_helper(); // actualy what is this?
current->opcode = LABLE; // I think this is right TODO: ask
current->label = name;
return;
}
void emit_parameter(char* param){
emit_helper();
current->opcode = PARAM;
current->operand1 = look_up(cur, param);
return;
}
void emit_function_call(char* result, char* name){
emit_helper();
current->opcode = CALL;
current->operand1 = look_up(cur, name);
current->result = look_up(cur, result);
return;
}
void emit_return(char* value){
emit_helper();
return;
}
void emit_reserve(char* result, char* type_name, int size){
emit_helper();
return;
}
void emit_release(char* pointer){
emit_helper();
return;
}