WIP: codegen backend #4

Draft
0xilly wants to merge 3 commits from 0xilly/Erythro:codegen into master
5 changed files with 144 additions and 25 deletions

7
.editorconfig Normal file
View File

@ -0,0 +1,7 @@
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

View File

@ -1,21 +1,26 @@
cmake_minimum_required(VERSION 3.21)
project(Erythro C)
project(Erythro C CXX)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
include_directories(include)
add_executable(Erythro
include/Data.h
include/Defs.h
src/Assembler.c
src/Delegate.c
src/Dump.c
src/Lexer.c
src/Main.c
src/Parser.c
src/Pointers.c
src/Statements.c
src/Symbols.c
src/Types.c
src/Importer.c)
set(ERYTHRO_SRC
src/Assembler.c
src/Delegate.c
src/Dump.c
src/Lexer.c
src/Main.c
src/Parser.c
src/Pointers.c
src/Statements.c
src/Symbols.c
src/Types.c
src/Importer.c
)
add_executable(eryc ${ERYTHRO_SRC})

View File

@ -0,0 +1,102 @@
/*************/
/*GEMWIRE */
/* ERYTHRO*/
/*************/
#pragma once
#include <string>
#include <Defs.h>
//Note(anita): Should I make a virtal register to deal with the translation
// should I also do the samething with the instructions like I did
// with pasm?
class IGenerator {
private:
std::string buffer;
public:
virtual auto gen_deallocate_all_register() -> void = 0;
virtual auto gen_retrieve_register() -> int = 0;
virtual auto gen_primitive_size(int type) -> int = 0;
virtual auto gen_align_memory(int type, int offset, int Direction) -> int = 0;
virtual auto gen_load(int value) -> int = 0;
virtual auto gen_add(int left, int right) -> int = 0;
virtual auto gen_mul(int left, int right) -> int = 0;
virtual auto gen_sub(int left, int right) -> int = 0;
virtual auto gen_div(int left, int right) -> int = 0;
virtual auto gen_load_global_variable(SymbolTableEntry* table, int operation) -> int = 0;
virtual auto gen_load_local_variable(SymbolTableEntry* table, int operation) -> int = 0;
virtual auto gen_str_global_var(SymbolTableEntry* table, int Register) -> int = 0;
virtual auto gen_str_local_var(SymbolTableEntry* table, int Register) -> int = 0;
virtual auto gen_calculate_offset(int type) -> int = 0;
virtual auto gen_new_stackframe() -> int = 0;
virtual auto gen_dereference(int reg, int type) -> int = 0;
virtual auto gen_str_dereference(int reg_1, int reg_2) -> int = 0;
virtual auto gen_address(SymbolTableEntry* entry) -> int = 0;
virtual auto gen_global_symbol(SymbolTableEntry* entry) -> int = 0;
virtual auto gen_new_string(char* value) -> int = 0;
virtual auto gen_load_string(int id) -> int = 0;
virtual auto gen_equal(int left, int right) -> int = 0;
virtual auto gen_if_not_equal(int left, int right) -> int = 0;
virtual auto gen_less_than(int left, int right) -> int = 0;
virtual auto gen_less_equal_than(int left, int right) -> int = 0;
virtual auto gen_greater_than(int left, int right) -> int = 0;
virtual auto gen_greater_equal_than(int left, int right) -> int = 0;
virtual auto gen_bitwise_and(int left, int right) -> int = 0;
virtual auto gen_bitwise_or(int left, int right) -> int = 0;
virtual auto gen_bitwise_xor(int left, int right) -> int = 0;
virtual auto gen_negate(int reg) -> int = 0;
virtual auto gen_invert(int reg) -> int = 0;
virtual auto gen_boolean_not(int reg) -> int = 0;
virtual auto gen_shift_left(int left, int right) -> int = 0;
virtual auto gen_shift_right(int left, int right) -> int = 0;
virtual auto gen_boolean_convert(int reg, int operation, int label) -> int = 0;
virtual auto gen_compare(int operation, int reg_left, int reg_right) -> int = 0;
virtual auto gen_compare_jmp(int operation, int reg_left, int reg_right, int label) -> int = 0;
virtual auto gen_if(ASTNode* node, int loop_start_lable, int loop_end_label) -> int = 0;
virtual auto gen_new_label() -> int = 0;
virtual auto gen_jmp(int label) -> int = 0;
virtual auto gen_label(int label) -> int = 0;
//Shift left
virtual auto gen_shift_L(int reg, int val) -> int = 0;
virtual auto gen_return(SymbolTableEntry* entry, int reg) -> int = 0;
virtual auto gen_call_wrapper(ASTNode* node) -> int = 0;
virtual auto gen_copy_args(int reg, int pos) -> int = 0;
virtual auto gen_call(SymbolTableEntry* entry, int args) -> int = 0;
virtual auto gen_while(ASTNode* node) -> int = 0;
//Fixme(anita): This is a hack do a proper call to the systems libcs
virtual auto gen_hack_printf(int reg) -> int = 0;
virtual auto gen_preamble() -> int = 0;
virtual auto gen_function_preamble() -> int = 0;
virtual auto gen_function_epilogue() -> int = 0;
};

View File

@ -12,6 +12,11 @@
#include <limits.h>
#include <sys/stat.h>
#ifdef __APPLE__
#include <errno.h>
#endif
/**
* The function of the importer is to read in definitions from a file, and store
* them into the symbol tables.

0
src/codegen/Codegen.cc Normal file
View File