Compare commits

...

2 Commits

Author SHA1 Message Date
Christoffer Lerno
058d637407 Additional codegen. 2024-12-28 16:46:12 +01:00
Christoffer Lerno
01335f6862 Additional codegen. 2024-12-28 16:23:25 +01:00
10 changed files with 1106 additions and 8 deletions

View File

@@ -371,6 +371,7 @@ endif()
if(C3_WITH_LLVM) if(C3_WITH_LLVM)
target_sources(c3c PRIVATE target_sources(c3c PRIVATE
src/compiler/c_codegen.c
src/compiler/llvm_codegen.c src/compiler/llvm_codegen.c
src/compiler/llvm_codegen_debug_info.c src/compiler/llvm_codegen_debug_info.c
src/compiler/llvm_codegen_expr.c src/compiler/llvm_codegen_expr.c

View File

@@ -17,8 +17,9 @@
typedef enum typedef enum
{ {
BACKEND_LLVM = 1, BACKEND_LLVM = 0,
BACKEND_TB = 2 BACKEND_TB = 1,
BACKEND_C = 2,
} CompilerBackend; } CompilerBackend;
typedef enum typedef enum

View File

@@ -88,6 +88,12 @@ static const char *optlevels[4] = {
[OPTIMIZATION_AGGRESSIVE] = "max", [OPTIMIZATION_AGGRESSIVE] = "max",
}; };
static const char *backends[3] = {
[BACKEND_LLVM] = "llvm",
[BACKEND_TB] = "tb",
[BACKEND_C] = "c",
};
static const char *backtrace_levels[2] = { static const char *backtrace_levels[2] = {
[SHOW_BACKTRACE_OFF] = "off", [SHOW_BACKTRACE_OFF] = "off",
[SHOW_BACKTRACE_ON] = "on", [SHOW_BACKTRACE_ON] = "on",

View File

@@ -654,6 +654,11 @@ static void parse_option(BuildOptions *options)
print_version(); print_version();
exit_compiler(COMPILER_SUCCESS_EXIT); exit_compiler(COMPILER_SUCCESS_EXIT);
} }
if ((argopt = match_argopt("backend")))
{
options->backend = (CompilerBackend)parse_multi_option(argopt, 3, backends);
return;
}
if (match_longopt("run-once")) if (match_longopt("run-once"))
{ {
options->run_once = true; options->run_once = true;

1078
src/compiler/c_codegen.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1 @@
#include "codegen_internal.h"

View File

@@ -468,6 +468,9 @@ void compiler_compile(void)
switch (compiler.build.backend) switch (compiler.build.backend)
{ {
case BACKEND_C:
gen_contexts = c_gen(modules, module_count);
error_exit("Unfinished C backend!");
case BACKEND_LLVM: case BACKEND_LLVM:
#if LLVM_AVAILABLE #if LLVM_AVAILABLE
gen_contexts = llvm_gen(modules, module_count); gen_contexts = llvm_gen(modules, module_count);

View File

@@ -439,6 +439,7 @@ typedef struct VarDecl_
{ {
// Variable // Variable
void *optional_ref; void *optional_ref;
int optional_id;
int tb_optional_reg; int tb_optional_reg;
}; };
}; };
@@ -613,6 +614,7 @@ typedef struct Decl_
union union
{ {
void *backend_ref; void *backend_ref;
int backend_id;
int tb_register; int tb_register;
void *backend_value; void *backend_value;
void *tb_symbol; void *tb_symbol;
@@ -2120,6 +2122,7 @@ CastKind cast_to_bool_kind(Type *type);
const char *llvm_codegen(void *context); const char *llvm_codegen(void *context);
const char *tilde_codegen(void *context); const char *tilde_codegen(void *context);
void **c_gen(Module** modules, unsigned module_count);
void **llvm_gen(Module** modules, unsigned module_count); void **llvm_gen(Module** modules, unsigned module_count);
void **tilde_gen(Module** modules, unsigned module_count); void **tilde_gen(Module** modules, unsigned module_count);

View File

@@ -347,7 +347,6 @@ static bool sema_analyse_union_members(SemaContext *context, Decl *decl)
} }
AlignSize member_alignment; AlignSize member_alignment;
if (!sema_set_abi_alignment(context, member->type, &member_alignment)) return false; if (!sema_set_abi_alignment(context, member->type, &member_alignment)) return false;
if (!sema_check_struct_holes(context, decl, member)) return false; if (!sema_check_struct_holes(context, decl, member)) return false;
ByteSize member_size = type_size(member->type); ByteSize member_size = type_size(member->type);

View File

@@ -208,15 +208,16 @@ static void register_generic_decls(CompilationUnit *unit, Decl **decls)
decl->unit = unit; decl->unit = unit;
switch (decl->decl_kind) switch (decl->decl_kind)
{ {
case DECL_POISONED:
case DECL_ENUM_CONSTANT: case DECL_ENUM_CONSTANT:
case DECL_FAULTVALUE: case DECL_FAULTVALUE:
case DECL_IMPORT:
case DECL_LABEL:
case DECL_CT_ASSERT:
case DECL_CT_ECHO:
case DECL_DECLARRAY: case DECL_DECLARRAY:
case DECL_ERASED: case DECL_ERASED:
case DECL_LABEL:
UNREACHABLE
case DECL_POISONED:
case DECL_IMPORT:
case DECL_CT_ASSERT:
case DECL_CT_ECHO:
case DECL_FNTYPE: case DECL_FNTYPE:
case DECL_CT_INCLUDE: case DECL_CT_INCLUDE:
case DECL_CT_EXEC: case DECL_CT_EXEC: