From 8e80091da43bd1c1107bc58e0a12930f2a942db5 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 22 Apr 2020 13:50:00 +0200 Subject: [PATCH] Create CI --- .github/workflows/main.yml | 21 +++++++++++++++++++++ CMakeLists.txt | 2 +- src/compiler/ast.c | 1 + src/compiler/bigint.c | 2 +- src/compiler/compiler_internal.h | 2 +- src/compiler/llvm_codegen.c | 5 +++++ src/compiler/llvm_codegen_expr.c | 1 + src/compiler/llvm_codegen_stmt.c | 2 +- src/compiler/number.c | 4 ++-- src/compiler/parse_stmt.c | 1 + src/compiler/sema_expr.c | 11 +++++++---- src/compiler/sema_stmts.c | 1 + src/compiler/sema_types.c | 2 +- src/compiler/types.c | 1 + src/utils/errors.h | 5 +++++ src/utils/malloc.c | 8 ++++---- 16 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..347bcfc91 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,21 @@ + +name: CI + +on: + push: + branches: [ master, dev ] + pull_request: + branches: [ master ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: (Linux) Download LLVM + run: sudo apt-get install llvm + - name: Build + run: | + mkdir build && cd build + cmake -DLLVM_DIR=/usr/lib/llvm/cmake -DCMAKE_BUILD_TYPE=Debug .. + cmake --build . diff --git a/CMakeLists.txt b/CMakeLists.txt index 791a8226d..021627fd0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,6 @@ add_executable(c3c src/utils/toml.c src/build/project.c src/compiler/sema_name_resolution.c src/target_info/target_info.c src/compiler/parse_expr.c src/compiler/parser_internal.h src/compiler/parse_stmt.c src/compiler/sema_passes.c src/compiler/sema_internal.h src/compiler/sema_decls.c src/compiler/sema_types.c src/compiler/sema_stmts.c src/compiler/number.c) -target_compile_options(c3c PRIVATE -Wimplicit-int -Werror -Wall -Wextra -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter) +target_compile_options(c3c PRIVATE -Wimplicit-int -Werror -Wall -Wno-unknown-pragmas -Wextra -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter) target_link_libraries(c3c m ${llvm_libs}) \ No newline at end of file diff --git a/src/compiler/ast.c b/src/compiler/ast.c index 8ef766360..f59a129af 100644 --- a/src/compiler/ast.c +++ b/src/compiler/ast.c @@ -345,6 +345,7 @@ void fprint_type_recursive(FILE *file, Type *type, int indent) fprintf_indented(file, indent, "(meta-type"); fprint_type_recursive(file, type->child, indent + 1); fprint_endparen(file, indent); + return; case TYPE_FUNC: fprintf_indented(file, indent, "(type-func %s)\n", type->func.signature->mangled_signature); return; diff --git a/src/compiler/bigint.c b/src/compiler/bigint.c index 846060e70..c4f34c68b 100644 --- a/src/compiler/bigint.c +++ b/src/compiler/bigint.c @@ -2148,7 +2148,7 @@ long double bigint_as_float(const BigInt *bigint) { if (bigint_fits_in_bits(bigint, 64, bigint->is_negative)) { - return bigint->is_negative ? bigint_as_signed(bigint) : bigint_as_unsigned(bigint); + return bigint->is_negative ? (long double)bigint_as_signed(bigint) : (long double)bigint_as_unsigned(bigint); } BigInt div; uint64_t mult = 0x100000000000ULL; diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index 66ba84f89..3b8d3ea86 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -1223,7 +1223,7 @@ static inline Type *type_reduced(Type *type) static inline bool type_is_structlike(Type *type) { - assert(type->canonical = type); + assert(type->canonical == type); switch (type->type_kind) { case TYPE_UNION: diff --git a/src/compiler/llvm_codegen.c b/src/compiler/llvm_codegen.c index f51171415..100a7b147 100644 --- a/src/compiler/llvm_codegen.c +++ b/src/compiler/llvm_codegen.c @@ -69,6 +69,7 @@ static LLVMValueRef gencontext_emit_initializer(GenContext *context, Expr *expr) { TODO } + static void gencontext_emit_global_variable_definition(GenContext *context, Decl *decl, bool is_tentative) { assert(decl->var.kind == VARDECL_GLOBAL); @@ -86,9 +87,13 @@ static void gencontext_emit_global_variable_definition(GenContext *context, Decl init = gencontext_emit_initializer(context, decl->var.init_expr); } + + assert(!init); + // TODO fix name decl->var.backend_ref = LLVMAddGlobal(context->module, llvm_type(decl->type), decl->name); + // If read only: LLVMSetGlobalConstant(decl->var.backend_ref, 1); switch (decl->visibility) diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index b45272ddb..845e39d5d 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -265,6 +265,7 @@ LLVMValueRef gencontext_emit_cast(GenContext *context, CastKind cast_kind, LLVMV case CAST_ENUMSI: TODO } + UNREACHABLE } static inline LLVMValueRef gencontext_emit_cast_expr(GenContext *context, Expr *expr) { diff --git a/src/compiler/llvm_codegen_stmt.c b/src/compiler/llvm_codegen_stmt.c index 0b3ff5367..8d0579c4a 100644 --- a/src/compiler/llvm_codegen_stmt.c +++ b/src/compiler/llvm_codegen_stmt.c @@ -384,7 +384,7 @@ void gencontext_emit_do_stmt(GenContext *context, Ast *ast) // A loop must either have a body or an inc. // This type do-while for loop is forbidden: // do { } while (1); - assert(cond_block || body_block && "Do has no body and no cond."); + assert((cond_block || body_block) && "Do has no body and no cond."); // Break is simple it always jumps out. // For continue: if there is no condition, jump to the body. diff --git a/src/compiler/number.c b/src/compiler/number.c index 97b758edf..4a0a98434 100644 --- a/src/compiler/number.c +++ b/src/compiler/number.c @@ -192,8 +192,8 @@ bool expr_const_compare(const ExprConst *left, const ExprConst *right, BinaryOp default: UNREACHABLE } - assert(op == BINARYOP_EQ || op == BINARYOP_NE); - return op == BINARYOP_EQ == is_eq; + assert((op == BINARYOP_EQ) || (op == BINARYOP_NE)); + return (op == BINARYOP_EQ) && is_eq; } bool expr_const_int_overflowed(const ExprConst *expr) diff --git a/src/compiler/parse_stmt.c b/src/compiler/parse_stmt.c index 596af08eb..46891319d 100644 --- a/src/compiler/parse_stmt.c +++ b/src/compiler/parse_stmt.c @@ -826,6 +826,7 @@ Ast *parse_stmt(Context *context) sema_error_at(context->tok.span.loc - 1, "Reached the end of the file when expecting a statement."); return poisoned_ast; } + UNREACHABLE } diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index f0e83a8c2..a0671c38f 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -390,7 +390,7 @@ static inline bool sema_expr_analyse_subscript_after_parent_resolution(Context * bigint_to_error_string(&index->const_expr.i, 10), type->array.len - 1); return false; } - // fallthrough + FALLTHROUGH; } case TYPE_VARARRAY: case TYPE_SUBARRAY: @@ -648,7 +648,7 @@ static bool expr_check_index_in_range(Type *type, Expr *index) bigint_to_error_string(&index->const_expr.i, 10), type->array.len - 1); return false; } - // fallthrough + FALLTHROUGH; } case TYPE_VARARRAY: case TYPE_SUBARRAY: @@ -1931,7 +1931,7 @@ static bool sema_expr_analyse_neg(Context *context, Type *to, Expr *expr, Expr * case ALL_INTS: if (is_negmod) { - if (inner->expr_kind != TYPE_IXX) + if (canonical->type_kind != TYPE_IXX) { SEMA_ERROR(expr, "Cannot use –% on compile time integers, you need to first cast it to an integer type e.g. -%cast(-128, char)."); @@ -2175,6 +2175,7 @@ static inline bool sema_expr_analyse_unary(Context *context, Type *to, Expr *exp case UNARYOP_ERROR: return false; } + UNREACHABLE } static inline bool sema_expr_analyse_post_unary(Context *context, Type *to, Expr *expr) @@ -2254,6 +2255,7 @@ static TypeInfo *type_info_copy_from_macro(Context *context, Expr *macro, TypeIn copy->pointer = type_info_copy_from_macro(context, macro, source->pointer); return copy; } + UNREACHABLE } @@ -2357,6 +2359,7 @@ static Expr *expr_copy_from_macro(Context *context, Expr *macro, Expr *source_ex return expr; } #undef EXPR_COPY + UNREACHABLE } static Expr **expr_copy_expr_list_from_macro(Context *context, Expr *macro, Expr **expr_list) @@ -2521,7 +2524,7 @@ static Ast *ast_copy_from_macro(Context *context, Expr *macro, Ast *source) AST_COPY(ast->scoped_stmt.stmt); return ast; } - + UNREACHABLE; #undef EXPR_COPY #undef AST_COPY } diff --git a/src/compiler/sema_stmts.c b/src/compiler/sema_stmts.c index 00b0b5a9a..536922b32 100644 --- a/src/compiler/sema_stmts.c +++ b/src/compiler/sema_stmts.c @@ -854,6 +854,7 @@ static inline bool sema_analyse_statement_inner(Context *context, Ast *statement case AST_GENERIC_DEFAULT_STMT: TODO } + UNREACHABLE } bool sema_analyse_statement(Context *context, Ast *statement) diff --git a/src/compiler/sema_types.c b/src/compiler/sema_types.c index 127469761..71ceb7d14 100644 --- a/src/compiler/sema_types.c +++ b/src/compiler/sema_types.c @@ -151,5 +151,5 @@ bool sema_resolve_type_shallow(Context *context, TypeInfo *type_info) case TYPE_INFO_POINTER: return sema_resolve_ptr_type(context, type_info); } - + UNREACHABLE } \ No newline at end of file diff --git a/src/compiler/types.c b/src/compiler/types.c index 50967f679..fbf1e87b7 100644 --- a/src/compiler/types.c +++ b/src/compiler/types.c @@ -692,6 +692,7 @@ Type *type_find_max_type(Type *type, Type *other) case TYPE_U32: case TYPE_U64: if (other->type_kind == TYPE_ENUM) return type_find_max_type(type, other->decl->enums.type_info->type->canonical); + FALLTHROUGH; case TYPE_F32: case TYPE_F64: case TYPE_FXX: diff --git a/src/utils/errors.h b/src/utils/errors.h index e9264f53f..8f6d102b6 100644 --- a/src/utils/errors.h +++ b/src/utils/errors.h @@ -17,6 +17,11 @@ void error_exit(const char *format, ...) __attribute__((noreturn)); #define UNREACHABLE FATAL_ERROR("Cannot reach %s:%d", __func__, __LINE__); +#if defined(__GNUC__) && __GNUC__ >= 7 +#define FALLTHROUGH __attribute__ ((fallthrough)) +#else +#define FALLTHROUGH ((void)0) +#endif #define TODO FATAL_ERROR("TODO reached", __func__, __LINE__); #define TEST_ASSERT(_condition, _string, ...) while (!(_condition)) { FATAL_ERROR(_string, ##__VA_ARGS__); } diff --git a/src/utils/malloc.c b/src/utils/malloc.c index 88be1feeb..372c53ddc 100644 --- a/src/utils/malloc.c +++ b/src/utils/malloc.c @@ -4,11 +4,11 @@ #include "common.h" -static const size_t KB = 1024ul; +#define KB 1024ul // Use 1MB at a time. -static const size_t MB = KB * 1024ul; -static const size_t BUCKET_SIZE = MB; -static const size_t STARTING_ARENA_BUCKETS = 16; +#define MB (KB * 1024ul) +#define BUCKET_SIZE MB +#define STARTING_ARENA_BUCKETS 16 static uint8_t **arena_buckets; static size_t arena_buckets_used;