It seems that I had for gotten to fix one of the signatures
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
#include <stdio.h>
|
||||
#include "intermediate_code.h"
|
||||
#include "symbol_table.h"
|
||||
|
||||
Instruction * begin;
|
||||
Instruction * current;
|
||||
@ -11,7 +10,31 @@ char * temp = NULL;
|
||||
// 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.
|
||||
|
||||
TNodeOrConst * tn_or_const(Op op, RegConstUnion r);
|
||||
TNodeOrConst * tn_or_const(Op op, void * tnc) {
|
||||
TNodeOrConst * count = calloc(1, sizeof(*count));
|
||||
count->d = op;
|
||||
switch (op) {
|
||||
case NODE:
|
||||
count->tnc_union->node = tnc;
|
||||
break;
|
||||
case ADDRESS:
|
||||
count->tnc_union->address = tnc;
|
||||
break;
|
||||
case STRING:
|
||||
count->tnc_union->string = tnc;
|
||||
break;
|
||||
case INTEGER:
|
||||
count->tnc_union->integer = *(int*)tnc;
|
||||
break;
|
||||
case CHARACTER:
|
||||
count->tnc_union->character = *(char*)tnc;
|
||||
break;
|
||||
case BOOLEAN:
|
||||
count->tnc_union->Boolean = *(bool*)tnc;
|
||||
break;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static void emit_helper(void){
|
||||
Instruction * inst = calloc(1, sizeof(*inst));
|
||||
@ -26,7 +49,7 @@ static void emit_helper(void){
|
||||
}
|
||||
}
|
||||
|
||||
void emit_binary_op(Op op, TableNode * result, TNodeOrConst * arg1, TableNode * arg2){
|
||||
void emit_binary_op(Op op, TableNode * result, TNodeOrConst * arg1, TNodeOrConst * arg2){
|
||||
emit_helper();
|
||||
current->opcode = op;
|
||||
current->result = result;
|
||||
@ -61,35 +84,29 @@ void emit_as_file(FILE * out_file, Instruction * instr_arr){
|
||||
}
|
||||
|
||||
|
||||
void emit_label(char* label){
|
||||
void emit_label(int label){
|
||||
emit_helper();
|
||||
current->opcode = E_LABEL;
|
||||
current->label = label;
|
||||
return;
|
||||
}
|
||||
void emit_jump(char* label){
|
||||
void emit_jump(int label){
|
||||
emit_helper();
|
||||
current->opcode = E_GOTO;
|
||||
current->label = label;
|
||||
return;
|
||||
}
|
||||
void emit_conditional_jump(int count, ...){
|
||||
// it apears that I cant do what I want So we will have to deal with
|
||||
// the limitations presented.
|
||||
// arg_count is the number of args passed to the function
|
||||
// from there the sequence is Op, char * , TableNode * , and an optional
|
||||
// extra TableNode *.
|
||||
// when this instruction is a conditional jump then ... is 1
|
||||
// when the inst is a cond with a Relational op then ... is 2
|
||||
|
||||
void emit_conditional_jump(Op condition, int label, ...){
|
||||
// when this instruction is a conditional jump then the imput looks like (Op, int, TNodeOrConst *).
|
||||
// when the inst is a cond with a Relational operation then the input looks like (Op, int, TNodeOrConst *, TNodeOrConst *)
|
||||
emit_helper();
|
||||
va_list argptr;
|
||||
va_start(argptr, count);
|
||||
Op condition = va_arg(argptr, Op);
|
||||
char * label = va_arg(argptr, char *);
|
||||
va_start(argptr, label);
|
||||
current->opcode = condition;
|
||||
current->label = label;
|
||||
TNodeOrConst * n1;
|
||||
TableNode * n2;
|
||||
TNodeOrConst * n2;
|
||||
switch (condition) {
|
||||
case E_IF_X_TRUE: case E_IF_X_FALSE:
|
||||
n1 = va_arg(argptr, TNodeOrConst *);
|
||||
@ -97,21 +114,23 @@ void emit_conditional_jump(int count, ...){
|
||||
break;
|
||||
case E_LESSTHEN: case E_EQUALTO:
|
||||
n1 = va_arg(argptr, TNodeOrConst *);
|
||||
n2 = va_arg(argptr, TableNode *);
|
||||
n2 = va_arg(argptr, TNodeOrConst *);
|
||||
current->operand1 = n1;
|
||||
current->operand2 = n2;
|
||||
break;
|
||||
}
|
||||
va_end(argptr);
|
||||
return;
|
||||
}
|
||||
|
||||
void emit_function_start(char * name){
|
||||
emit_helper(); // actualy what is this?
|
||||
void emit_function_start(int name){
|
||||
emit_helper();
|
||||
current->opcode = E_LABEL; // I think this is right TODO: ask
|
||||
current->label = name; // wait what is a function start
|
||||
current->label = name;
|
||||
// this is probabaly a func decleration
|
||||
return;
|
||||
}
|
||||
|
||||
void emit_parameter(TNodeOrConst * param){
|
||||
emit_helper();
|
||||
current->opcode = E_PARAM;
|
||||
@ -119,13 +138,10 @@ void emit_parameter(TNodeOrConst * param){
|
||||
return;
|
||||
}
|
||||
|
||||
void emit_function_call(TableNode * result, int param_count, TableNode * name){
|
||||
void emit_function_call(TableNode * result, int param_count, TNodeOrConst * name){
|
||||
emit_helper();
|
||||
current->opcode = E_CALL;
|
||||
TNodeOrConst * count = calloc(1, sizeof(*count));
|
||||
count->d = INTEGER;
|
||||
count->rc_union->integer = param_count;
|
||||
current->operand1 = count;
|
||||
current->operand1 = tn_or_const(INTEGER, ¶m_count);
|
||||
current->operand2 = name;
|
||||
current->result = result;
|
||||
return;
|
||||
@ -168,7 +184,7 @@ char * temp_var_gen(){
|
||||
return ret;
|
||||
}
|
||||
|
||||
char * lable_gen(){
|
||||
char * label_gen(){
|
||||
char * ret = calloc( 9, sizeof(*ret));
|
||||
sprintf(ret, "L_%d", label_count);
|
||||
label_count++;
|
||||
|
Reference in New Issue
Block a user