Merge branch 'Dev' into Sprint3-Table_Restructure_Part2-FE-t#NoTask
This commit is contained in:
64
src/intermediate_code.c
Normal file
64
src/intermediate_code.c
Normal file
@ -0,0 +1,64 @@
|
||||
|
||||
|
||||
|
||||
// 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_binary_op(char* result, char* op, char* arg1, char* arg2){
|
||||
return;
|
||||
}
|
||||
void emit_unary_op(char* result, char* op, char* arg){
|
||||
return;
|
||||
}
|
||||
void emit_assignment(char* target, char* source){
|
||||
return;
|
||||
}
|
||||
void emit_as_file(FILE * out_file, Instruction * instr_arr){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void emit_label(char* label){
|
||||
return;
|
||||
}
|
||||
void emit_jump(char* label){
|
||||
return;
|
||||
}
|
||||
void emit_conditional_jump(char* condition, char* label){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void emit_function_start(char* name){
|
||||
return;
|
||||
}
|
||||
void emit_parameter(char* param){
|
||||
return;
|
||||
}
|
||||
void emit_function_call(char* result, char* name){
|
||||
return;
|
||||
}
|
||||
void emit_return(char* value){
|
||||
return;
|
||||
}
|
||||
void emit_reserve(char* result, char* type_name, int size){
|
||||
return;
|
||||
}
|
||||
void emit_release(char* pointer){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void emit_field_access(char* result, char* record, char* field){
|
||||
return;
|
||||
}
|
||||
void emit_array_access(char* result, char* array, char* index, char* dimension){
|
||||
return;
|
||||
}
|
||||
void emit_bounds_check(char* index, char* size, char* error_label){
|
||||
return;
|
||||
}
|
59
src/intermediate_code.h
Normal file
59
src/intermediate_code.h
Normal file
@ -0,0 +1,59 @@
|
||||
// Track 1: Core Infrastructure & Basic Expressions
|
||||
// * Create intermediate_code.h/.c defining the instruction structure:
|
||||
// - Struct with fields for: opcode, result, operand1, operand2, label
|
||||
// - Enum for all operation types (ADD, SUB, MUL, DIV, etc.)
|
||||
// * Implement temp variable generator function that produces unique names (t1, t2, etc.)
|
||||
// * Create specific code emission functions:
|
||||
// - emit_binary_op(char* result, char* op, char* arg1, char* arg2)
|
||||
// - emit_unary_op(char* result, char* op, char* arg)
|
||||
// - emit_assignment(char* target, char* source)
|
||||
// * Add Bison actions for arithmetic expressions:
|
||||
// - Addition: $$ = new_temp(); emit_binary_op($$, "ADD", $1, $3);
|
||||
// - Subtraction, multiplication, division, modulo
|
||||
#include "symbol_table.h"
|
||||
|
||||
typedef enum {ADD, SUB, MUL, DIV} Op; // TODO: add all the instructions
|
||||
typedef struct {
|
||||
Op opcode;
|
||||
TableNode * result;
|
||||
TableNode * operand1;
|
||||
TableNode * operand2;
|
||||
int label;
|
||||
int instruction;
|
||||
Instruction * prev;
|
||||
Instruction * next;
|
||||
} Instruction;
|
||||
|
||||
Instruction * start = NULL;
|
||||
Instruction * current = NULL;
|
||||
|
||||
void emit_binary_op(char* result, char* op, char* arg1, char* arg2);
|
||||
void emit_unary_op(char* result, char* op, char* arg);
|
||||
void emit_assignment(char* target, char* source);
|
||||
// TODO: Find out what these are suposed to do. Guess is create an entry in
|
||||
// the list of instructions. Guess is that its suposed to ret a struct ptr
|
||||
|
||||
|
||||
// * Implement integer/boolean/character specific operation handling
|
||||
// TODO: Find out what this means.
|
||||
|
||||
// * Create output function to write instructions to file with line formatting
|
||||
void emit_as_file(FILE * out_file, Instruction * instr_arr);
|
||||
|
||||
// * Implement instruction array storage for backpatching
|
||||
|
||||
void emit_label(char* label);
|
||||
void emit_jump(char* label);
|
||||
void emit_conditional_jump(char* condition, char* label);
|
||||
|
||||
void emit_function_start(char* name);
|
||||
void emit_parameter(char* param);
|
||||
void emit_function_call(char* result, char* name);
|
||||
void emit_return(char* value);
|
||||
void emit_reserve(char* result, char* type_name, int size);
|
||||
void emit_release(char* pointer);
|
||||
|
||||
|
||||
void emit_field_access(char* result, char* record, char* field);
|
||||
void emit_array_access(char* result, char* array, char* index, char* dimension);
|
||||
void emit_bounds_check(char* index, char* size, char* error_label);
|
Reference in New Issue
Block a user