Added the files for intermeadiat code gen #t51

This commit is contained in:
Meyer Simon
2025-03-28 10:25:11 -04:00
3 changed files with 50 additions and 1 deletions

13
src/intermediate_code.c Normal file
View File

@ -0,0 +1,13 @@
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;
}

37
src/intermediate_code.h Normal file
View File

@ -0,0 +1,37 @@
// 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;
} Instruction;
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

View File

@ -562,7 +562,6 @@ TableNode *look_up(SymbolTable *table, char *x) {
}
void print_symbol_table(SymbolTable *table, FILE *file_ptr) {
return;
if (table->Parent_Scope == NULL) {
fprintf(file_ptr, "%-17s: %-6s : %-6s : %-21s: %-28s\n", "NAME",