mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
C backend work.
This commit is contained in:
@@ -342,6 +342,7 @@ add_executable(c3c
|
|||||||
src/utils/whereami.c
|
src/utils/whereami.c
|
||||||
src/utils/cpus.c
|
src/utils/cpus.c
|
||||||
src/utils/unzipper.c
|
src/utils/unzipper.c
|
||||||
|
src/compiler/c_codegen.c
|
||||||
src/compiler/decltable.c
|
src/compiler/decltable.c
|
||||||
src/compiler/mac_support.c
|
src/compiler/mac_support.c
|
||||||
src/compiler/windows_support.c
|
src/compiler/windows_support.c
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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",
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
1079
src/compiler/c_codegen.c
Normal file
1079
src/compiler/c_codegen.c
Normal file
File diff suppressed because it is too large
Load Diff
1
src/compiler/c_codegen_internal.h
Normal file
1
src/compiler/c_codegen_internal.h
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "codegen_internal.h"
|
||||||
@@ -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);
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
Reference in New Issue
Block a user