latest version still not working #t51
This commit is contained in:
@ -4,13 +4,16 @@
|
||||
|
||||
Instruction * begin;
|
||||
Instruction * current;
|
||||
char * temp = NULL;
|
||||
|
||||
|
||||
// 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){
|
||||
TNodeOrConst * tn_or_const(Op op, RegConstUnion r);
|
||||
|
||||
static void emit_helper(void){
|
||||
Instruction * inst = calloc(1, sizeof(*inst));
|
||||
if(begin == NULL){
|
||||
begin = current = inst;
|
||||
@ -23,7 +26,7 @@ void emit_helper(void){
|
||||
}
|
||||
}
|
||||
|
||||
void emit_binary_op(TableNode * result, Op op, TableNode * arg1, TableNode * arg2){
|
||||
void emit_binary_op(Op op, TableNode * result, TNodeOrConst * arg1, TableNode * arg2){
|
||||
emit_helper();
|
||||
current->opcode = op;
|
||||
current->result = result;
|
||||
@ -32,7 +35,7 @@ void emit_helper(void){
|
||||
return;
|
||||
}
|
||||
|
||||
void emit_unary_op(TableNode * result, Op op, TableNode * arg){
|
||||
void emit_unary_op(Op op, TableNode * result, TNodeOrConst * arg){
|
||||
emit_helper();
|
||||
current->opcode = op;
|
||||
current->result = result;
|
||||
@ -40,11 +43,11 @@ void emit_helper(void){
|
||||
return;
|
||||
}
|
||||
|
||||
void emit_assignment(char* target, char* source){
|
||||
void emit_assignment(TableNode * target, TNodeOrConst * source){
|
||||
emit_helper();
|
||||
current->opcode = ADD; // TODO: replace with move
|
||||
current->result = look_up(cur, target);
|
||||
current->operand1 = look_up(cur, source);
|
||||
current->opcode = E_ASSIGN; // TODO: replace with move
|
||||
current->result = target;
|
||||
current->operand1 = source;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -60,48 +63,77 @@ void emit_as_file(FILE * out_file, Instruction * instr_arr){
|
||||
|
||||
void emit_label(char* label){
|
||||
emit_helper();
|
||||
current->opcode = LABEL;
|
||||
current->opcode = E_LABEL;
|
||||
current->label = label;
|
||||
return;
|
||||
}
|
||||
void emit_jump(char* label){
|
||||
emit_helper();
|
||||
current->opcode = GOTO;
|
||||
current->opcode = E_GOTO;
|
||||
current->label = label;
|
||||
return;
|
||||
}
|
||||
void emit_conditional_jump(char* condition, char* label){
|
||||
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
|
||||
emit_helper();
|
||||
current->opcode = CGOTO; // I am positive this needs to be 2 instructions
|
||||
va_list argptr;
|
||||
va_start(argptr, count);
|
||||
Op condition = va_arg(argptr, Op);
|
||||
char * label = va_arg(argptr, char *);
|
||||
current->opcode = condition;
|
||||
current->label = label;
|
||||
TNodeOrConst * n1;
|
||||
TableNode * n2;
|
||||
switch (condition) {
|
||||
case E_IF_X_TRUE: case E_IF_X_FALSE:
|
||||
n1 = va_arg(argptr, TNodeOrConst *);
|
||||
current->operand1 = n1;
|
||||
break;
|
||||
case E_LESSTHEN: case E_EQUALTO:
|
||||
n1 = va_arg(argptr, TNodeOrConst *);
|
||||
n2 = va_arg(argptr, TableNode *);
|
||||
current->operand1 = n1;
|
||||
current->operand2 = n2;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void emit_function_start(char* name){
|
||||
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;
|
||||
current->opcode = E_LABEL; // I think this is right TODO: ask
|
||||
current->label = name; // wait what is a function start
|
||||
// this is probabaly a func decleration
|
||||
return;
|
||||
}
|
||||
void emit_parameter(char* param){
|
||||
void emit_parameter(TNodeOrConst * param){
|
||||
emit_helper();
|
||||
current->opcode = PARAM;
|
||||
current->operand1 = look_up(cur, param);
|
||||
current->opcode = E_PARAM;
|
||||
current->operand1 = param;
|
||||
return;
|
||||
}
|
||||
void emit_function_call(char* result, char* name){
|
||||
|
||||
void emit_function_call(TableNode * result, int param_count, TableNode * name){
|
||||
emit_helper();
|
||||
current->opcode = CALL;
|
||||
current->operand1 = look_up(cur, name);
|
||||
current->result = look_up(cur, result);
|
||||
current->opcode = E_CALL;
|
||||
TNodeOrConst * count = calloc(1, sizeof(*count));
|
||||
count->d = INTEGER;
|
||||
count->rc_union->integer = param_count;
|
||||
current->operand1 = count;
|
||||
current->operand2 = name;
|
||||
current->result = result;
|
||||
return;
|
||||
}
|
||||
void emit_return(char* value){
|
||||
void emit_return(TNodeOrConst * value){
|
||||
emit_helper();
|
||||
current->opcode = RETURN;
|
||||
current->operand1 = look_up(cur, name);
|
||||
current->opcode = E_RETURN;
|
||||
current->operand1 = value;
|
||||
return;
|
||||
}
|
||||
void emit_reserve(char* result, char* type_name, int size){
|
||||
@ -115,11 +147,30 @@ void emit_release(char* pointer){
|
||||
|
||||
|
||||
void emit_field_access(char* result, char* record, char* field){
|
||||
emit_helper();
|
||||
return;
|
||||
}
|
||||
void emit_array_access(char* result, char* array, char* index, char* dimension){
|
||||
emit_helper();
|
||||
return;
|
||||
}
|
||||
void emit_bounds_check(char* index, char* size, char* error_label){
|
||||
emit_helper();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// * Implement temp variable generator function that produces unique names (t1, t2, etc.)
|
||||
char * temp_var_gen(){
|
||||
char * ret = calloc(9, sizeof(*ret));
|
||||
sprintf(ret, "$t%d", temp_count);
|
||||
temp_count++;
|
||||
return ret;
|
||||
}
|
||||
|
||||
char * lable_gen(){
|
||||
char * ret = calloc( 9, sizeof(*ret));
|
||||
sprintf(ret, "L_%d", label_count);
|
||||
label_count++;
|
||||
return ret;
|
||||
}
|
||||
|
Reference in New Issue
Block a user