diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4f8afb2ee..1dab620d2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -75,6 +75,9 @@ set(LLVM_LINK_COMPONENTS
WindowsManifest
)
+if (${LLVM_PACKAGE_VERSION} VERSION_GREATER 14)
+ set(LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} WindowsDriver)
+endif()
llvm_map_components_to_libnames(llvm_libs ${LLVM_LINK_COMPONENTS})
@@ -91,7 +94,7 @@ if(UNIX)
find_library(LLD_MINGW NAMES lldMinGW.a liblldMinGW.a PATHS ${LLVM_LIBRARY_DIRS})
find_library(LLD_WASM NAMES lldWasm.a liblldWasm.a PATHS ${LLVM_LIBRARY_DIRS})
- if(${LLVM_PACKAGE_VERSION} VERSION_LESS 14)
+ if (${LLVM_PACKAGE_VERSION} VERSION_LESS 14)
find_library(LLD_CORE NAMES lldCore.a liblldCore.a PATHS ${LLVM_LIBRARY_DIRS})
find_library(LLD_DRIVER NAMES lldDriver.a liblldDriver.a PATHS ${LLVM_LIBRARY_DIRS})
find_library(LLD_READER_WRITER NAMES lldReaderWriter.a liblldReaderWriter.a PATHS ${LLVM_LIBRARY_DIRS})
diff --git a/src/build/build_options.c b/src/build/build_options.c
index 101225bf1..73edbcc44 100644
--- a/src/build/build_options.c
+++ b/src/build/build_options.c
@@ -25,6 +25,7 @@ extern const char* llvm_target;
char *arch_os_target[ARCH_OS_TARGET_LAST + 1] = {
[X86_FREEBSD] = "x86-freebsd",
[X86_OPENBSD] = "x86-openbsd",
+ [X86_NETBSD] = "x86-netbsd",
[X86_MCU] = "x86-mcu",
[X86_ELF] = "x86-elf",
[X86_WINDOWS] = "x86-windows",
@@ -33,12 +34,17 @@ char *arch_os_target[ARCH_OS_TARGET_LAST + 1] = {
[X64_LINUX] = "x64-linux",
[X64_WINDOWS] = "x64-windows",
[X64_WINDOWS_GNU] = "x64-mingw",
+ [X64_FREEBSD] = "x64-freebsd",
+ [X64_OPENBSD] = "x64-openbsd",
[X64_NETBSD] = "x64-netbsd",
[X64_ELF] = "x64-elf",
[AARCH64_LINUX] = "aarch64-linux",
[AARCH64_DARWIN] = "aarch64-darwin",
+ [AARCH64_ELF] = "aarch64-elf",
[RISCV32_LINUX] = "riscv32-linux",
+ [RISCV32_ELF] = "riscv32-elf",
[RISCV64_LINUX] = "riscv64-linux",
+ [RISCV64_ELF] = "riscv64-elf",
[WASM32] = "wasm32",
[WASM64] = "wasm64",
};
@@ -70,7 +76,7 @@ static void usage(void)
OUTPUT(" --stdlib
- Use this directory as the C3 standard library path.");
OUTPUT(" --lib - Use this directory as the C3 library path.");
OUTPUT(" --path - Use this as the base directory for the current command.");
- OUTPUT(" --template - Use a different template: \"lib\", \"staticlib\" or a path.");
+ OUTPUT(" --template - Use a different template: \"lib\", \"static-lib\" or a path.");
OUTPUT(" --about - Prints a short description of C3.");
OUTPUT(" --symtab - Sets the preferred symtab size.");
OUTPUT(" -V --version - Print version information.");
diff --git a/src/build/build_options.h b/src/build/build_options.h
index 7895d128b..e9a638291 100644
--- a/src/build/build_options.h
+++ b/src/build/build_options.h
@@ -112,24 +112,6 @@ typedef enum
SIZE_OPTIMIZATION_TINY = 2, // -Oz
} SizeOptimizationLevel;
-// Values correspond to LLVM values.
-typedef enum
-{
- PIC_DEFAULT = -1,
- PIC_NONE = 0,
- PIC_SMALL = 1,
- PIC_BIG = 2,
-} PicGeneration;
-
-// Values correspond to LLVM values
-typedef enum
-{
- PIE_DEFAULT = -1,
- PIE_NONE = 0,
- PIE_SMALL = 1,
- PIE_BIG = 2,
-} PieGeneration;
-
typedef enum
{
SOFT_FLOAT_DEFAULT = -1,
@@ -193,6 +175,7 @@ typedef enum
ARCH_OS_TARGET_DEFAULT = 0,
X86_FREEBSD,
X86_OPENBSD,
+ X86_NETBSD,
X86_LINUX,
X86_WINDOWS,
X86_MCU,
@@ -200,13 +183,18 @@ typedef enum
X64_DARWIN,
X64_LINUX,
X64_NETBSD,
+ X64_FREEBSD,
+ X64_OPENBSD,
X64_WINDOWS,
X64_WINDOWS_GNU,
X64_ELF,
AARCH64_LINUX,
AARCH64_DARWIN,
+ AARCH64_ELF,
RISCV32_LINUX,
+ RISCV32_ELF,
RISCV64_LINUX,
+ RISCV64_ELF,
WASM32,
WASM64,
ARCH_OS_TARGET_LAST = WASM64
diff --git a/src/build/builder.c b/src/build/builder.c
index 10f8403da..b274a62ba 100644
--- a/src/build/builder.c
+++ b/src/build/builder.c
@@ -13,6 +13,63 @@
void load_library_files(void) {}
void load_files(void) {}
+#if defined(_M_X64) || defined(_M_AMD64)
+ #if defined(__MINGW32__)
+ArchOsTarget default_target = X64_WINDOWS_GNU;
+ #else
+ArchOsTarget default_target = X64_WINDOWS;
+ #endif
+#elif defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64)
+ #if defined(__MACH__)
+ArchOsTarget default_target = X64_DARWIN;
+ #elif defined(__linux__) && __linux__
+ArchOsTarget default_target = X64_LINUX;
+ #elif defined(__NetBSD__)
+ArchOsTarget default_target = X64_NETBSD;
+ #elif defined(__FreeBSD__)
+ArchOsTarget default_target = X64_FREEBSD;
+ #elif defined(__OpenBSD__)
+ArchOsTarget default_target = X64_OPENBSD;
+ #else
+ArchOsTarget default_target = X64_ELF;
+ #endif
+#elif defined(__aarch64__) || defined(_M_ARM64)
+ #if defined(__MACH__)
+ArchOsTarget default_target = AARCH64_DARWIN;
+ #elif defined(__linux__) && __linux__
+ArchOsTarget default_target = AARCH64_LINUX;
+ #else
+ArchOsTarget default_target = AARCH64_ELF;
+ #endif
+#elif defined(i386) || defined(__i386__) || defined(__i386) || defined(_M_IX86)
+ #if defined(__linux__) && __linux__
+ArchOsTarget default_target = X86_LINUX;
+ #elif defined(__FreeBSD__)
+ArchOsTarget default_target = X86_FREEBSD;
+ #elif defined(__OpenBSD__)
+ArchOsTarget default_target = X86_OPENBSD;
+ #elif defined(__NetBSD__)
+ArchOsTarget default_target = X86_NETBSD;
+ #elif defined(_MSC_VER) && _MSC_VER
+ArchOsTarget default_target = X86_WINDOWS;
+ #else
+ArchOsTarget default_target = X86_ELF;
+ #endif
+#elif defined(__riscv32)
+ #if defined(__linux__) && __linux__
+ArchOsTarget default_target = RISCV32_LINUX;
+ #else
+ArchOsTarget default_target = RISCV32_ELF;
+ #endif
+#elif defined(__riscv64)
+ #if defined(__linux__) && __linux__
+ArchOsTarget default_target = RISCV64_LINUX;
+ #else
+ArchOsTarget default_target = RISCV64_ELF;
+ #endif
+#else
+ArchOsTarget default_target = ARCH_OS_TARGET_DEFAULT;
+#endif
static void update_build_target_from_options(BuildTarget *target, BuildOptions *options)
{
@@ -98,16 +155,6 @@ static void update_build_target_from_options(BuildTarget *target, BuildOptions *
{
target->arch_os_target = options->arch_os_target_override;
}
-#ifndef _MSC_VER
-#define _MSC_VER 0
-#endif
- else if (_MSC_VER)
- {
- // The current handling of ARCH_OS_TARGET_DEFAULT works on unix, but not on windows.
- // to deal with this, simply default to x64-windows (unless using mingw).
- // ARCH_OS_TARGET_DEFAULT could be handled in a more cross-platform manner later on.
- target->arch_os_target = X64_WINDOWS;
- }
if (options->reloc_model != RELOC_DEFAULT) target->reloc_model = options->reloc_model;
for (int i = 0; i < options->linker_arg_count; i++)
diff --git a/src/build/project.c b/src/build/project.c
index 6e1e653d4..d3d390f82 100644
--- a/src/build/project.c
+++ b/src/build/project.c
@@ -217,7 +217,6 @@ static void project_add_targets(Project *project, JSONObject *project_data)
{
error_exit("'targets' did not contain map of targets.");
}
- JSONObject *targets_find = NULL;
for (unsigned i = 0; i < targets_json->member_len; i++)
{
JSONObject *object = targets_json->members[i];
diff --git a/src/compiler/ast.c b/src/compiler/ast.c
index 3fd78042a..925543e64 100644
--- a/src/compiler/ast.c
+++ b/src/compiler/ast.c
@@ -106,7 +106,7 @@ const char *decl_to_name(Decl *decl)
case VARDECL_PARAM_REF:
return "ref parameter";
case VARDECL_PARAM_EXPR:
- return "extpression parameter";
+ return "expression parameter";
case VARDECL_LOCAL_CT:
return "compile time variable";
case VARDECL_LOCAL_CT_TYPE:
diff --git a/src/compiler/bigint.c b/src/compiler/bigint.c
index 109d415c5..3bb44eef2 100644
--- a/src/compiler/bigint.c
+++ b/src/compiler/bigint.c
@@ -6,23 +6,23 @@
#include
#include
-static inline uint32_t u32_min(uint32_t a, uint32_t b)
+UNUSED static inline uint32_t u32_min(uint32_t a, uint32_t b)
{
return a < b ? a : b;
}
-static inline size_t size_max(size_t a, size_t b)
+UNUSED static inline size_t size_max(size_t a, size_t b)
{
return a > b ? a : b;
}
-static inline unsigned unsigned_max(unsigned a, unsigned b)
+UNUSED static inline unsigned unsigned_max(unsigned a, unsigned b)
{
return a > b ? a : b;
}
-static char digit_to_char(uint8_t digit, bool upper)
+UNUSED static char digit_to_char(uint8_t digit, bool upper)
{
if (digit <= 9)
{
@@ -93,7 +93,7 @@ Int128 i128_from_str(const char *str)
return x;
}
-Int128 i128_from_strl(const char *str, const char *end)
+UNUSED Int128 i128_from_strl(const char *str, const char *end)
{
char c;
Int128 x = { 0, 0 };
@@ -105,7 +105,7 @@ Int128 i128_from_strl(const char *str, const char *end)
return x;
}
-Int128 i128_from_hexstrl(const char *str, const char *end)
+UNUSED Int128 i128_from_hexstrl(const char *str, const char *end)
{
char c;
Int128 x = { 0, 0 };
@@ -220,7 +220,7 @@ Int128 i128_mult64(Int128 op1, uint64_t op2)
}
-CmpRes int128_scomp64(Int128 op1, int64_t op2)
+UNUSED CmpRes int128_scomp64(Int128 op1, int64_t op2)
{
// Check all zero
if (!op2 && !op1.high && !op1.low) return CMP_EQ;
@@ -246,14 +246,14 @@ CmpRes int128_scomp64(Int128 op1, int64_t op2)
return op1.low > (uint64_t)op2 ? CMP_GT : CMP_LT;
}
-CmpRes int128_ucomp64(Int128 op1, uint64_t op2)
+UNUSED CmpRes int128_ucomp64(Int128 op1, uint64_t op2)
{
if (op1.high) return CMP_GT;
if (op1.low == op2) return CMP_EQ;
return op1.low > op2 ? CMP_GT : CMP_LT;
}
-CmpRes i128_ucomp(Int128 op1, Int128 op2)
+UNUSED CmpRes i128_ucomp(Int128 op1, Int128 op2)
{
if (op1.high > op2.high) return CMP_GT;
if (op1.high < op2.high) return CMP_LT;
@@ -299,7 +299,7 @@ Int128 i128_from_float_unsigned(Real d)
return (Int128){ 0, (uint64_t)d };
}
-bool i128_get_bit(const Int128 *op, int bit)
+UNUSED bool i128_get_bit(const Int128 *op, int bit)
{
assert(bit < 128 && bit >= 0);
if (bit > 63)
@@ -322,6 +322,7 @@ Int128 i128_lshr(Int128 op1, Int128 op2)
Int128 i128_ashr64(Int128 op1, uint64_t amount)
{
+ if (amount == 0) return op1;
if (!ISNEG(op1.high)) return i128_lshr64(op1, amount);
if (amount > 127) return (Int128){ UINT64_MAX, UINT64_MAX };
if (amount == 64) return (Int128){ UINT64_MAX, op1.high };
@@ -381,7 +382,7 @@ static uint32_t popcnt64(uint64_t n)
return (((n + (n >> 4)) & 0xF0F0F0F0F0F0F0F) * 0x101010101010101) >> 56;
}
-uint32_t i128_popcnt(Int128 i)
+UNUSED uint32_t i128_popcnt(Int128 i)
{
return popcnt64(i.high) + popcnt64(i.low);
}
@@ -725,7 +726,6 @@ unsigned int_bits_needed(Int op)
{
TypeKind kind = op.type;
Int128 i = op.i;
- int bits_used;
if (type_kind_is_signed(kind))
{
if (i128_is_neg(i))
diff --git a/src/compiler/c_abi_internal.h b/src/compiler/c_abi_internal.h
index b9eec5bd8..cf33cede5 100644
--- a/src/compiler/c_abi_internal.h
+++ b/src/compiler/c_abi_internal.h
@@ -36,7 +36,7 @@ bool abi_type_is_integer(AbiType type);
bool abi_type_is_float(AbiType type);
static inline void abi_type_set_type(AbiType *abi_type, Type *type);
static inline AbiType abi_type_get(Type *type);
-static inline void abi_type_set_int_bits(AbiType *abi_type, ByteSize bits);
+
TypeSize abi_type_size(AbiType type);
typedef struct
@@ -81,9 +81,3 @@ static inline void abi_type_set_type(AbiType *abi_type, Type *type)
abi_type->type = type;
}
-static inline void abi_type_set_int_bits(AbiType *abi_type, ByteSize bits)
-{
- assert(bits < UINT32_MAX);
- abi_type->int_bits_plus_1 = (uintptr_t)bits + 1;
-}
-
diff --git a/src/compiler/compiler.c b/src/compiler/compiler.c
index 2215fa17f..15978acce 100644
--- a/src/compiler/compiler.c
+++ b/src/compiler/compiler.c
@@ -103,39 +103,19 @@ typedef struct CompileData_
Task task;
} CompileData;
-void thread_compile_task_llvm(void *compiledata)
+void thread_compile_task_llvm(void *compile_data)
{
- CompileData *data = compiledata;
+ CompileData *data = compile_data;
data->object_name = llvm_codegen(data->context);
}
-void thread_compile_task_tb(void *compiledata)
+void thread_compile_task_tb(void *compile_data)
{
- CompileData *data = compiledata;
+ CompileData *data = compile_data;
data->object_name = tinybackend_codegen(data->context);
}
-
-static void add_global_define(const char *name, Expr *value)
-{
- Decl *dec = decl_calloc();
- TokenType type = TOKEN_CONST_IDENT;
- const char *unique_name = symtab_add(name, (uint32_t)strlen(name), fnv1a(name, (uint32_t)strlen(name)), &type);
- dec->name = unique_name;
- dec->module = &global_context.std_module;
- dec->visibility = VISIBLE_PUBLIC;
- dec->decl_kind = DECL_VAR;
- dec->var.kind = VARDECL_CONST;
- dec->var.constant = true;
- dec->var.type_info = NULL;
- dec->var.init_expr = value;
- dec->type = value->type;
- dec->resolve_status = RESOLVE_DONE;
- decl_set_external_name(dec);
- stable_set(&dec->module->symbols, dec->name, dec);
-}
-
static const char *active_target_name(void)
{
if (active_target.name) return active_target.name;
@@ -260,7 +240,6 @@ void compiler_compile(void)
for (int i = 0; i < cfiles; i++)
{
char *filename = NULL;
- char *dir = NULL;
bool split_worked = filenamesplit(active_target.csources[i], &filename, NULL);
assert(split_worked);
size_t len = strlen(filename);
@@ -297,7 +276,7 @@ void compiler_compile(void)
if (create_exe)
{
const char *output_name = active_target_name();
- if (active_target.arch_os_target == ARCH_OS_TARGET_DEFAULT)
+ if (active_target.arch_os_target == default_target)
{
platform_linker(output_name, obj_files, output_file_count);
}
diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h
index ac1166174..52e09e6e5 100644
--- a/src/compiler/compiler_internal.h
+++ b/src/compiler/compiler_internal.h
@@ -563,7 +563,6 @@ typedef struct Decl_
Visibility visibility : 3;
ResolveStatus resolve_status : 3;
bool is_packed : 1;
- bool needs_additional_pad : 1;
bool is_substruct : 1;
bool has_variable_array : 1;
bool no_scope : 1;
@@ -1748,13 +1747,13 @@ Real i128_to_float_signed(Int128 op);
bool i128_is_zero(Int128 op);
uint32_t i128_clz(const Int128 *op);
uint32_t i128_ctz(const Int128 *op);
-int i128_lsb(const Int128 *op);
-int i128_msb(const Int128 *op);
+UNUSED int i128_lsb(const Int128 *op);
+UNUSED int i128_msb(const Int128 *op);
Int128 i128_from_float_signed(Real d);
Int128 i128_from_float_unsigned(Real d);
Int128 i128_from_signed(int64_t i);
-Int128 i128_from_unsigned(uint64_t i);
-bool i128_get_bit(const Int128 *op, int bit);
+UNUSED Int128 i128_from_unsigned(uint64_t i);
+UNUSED bool i128_get_bit(const Int128 *op, int bit);
static inline bool type_may_negate(Type *type)
{
@@ -1788,7 +1787,6 @@ bool cast(Expr *expr, Type *to_type);
bool cast_may_implicit(Type *from_type, Type *to_type, bool is_simple_expr, bool failable_allowed);
bool cast_may_explicit(Type *from_type, Type *to_type, bool ignore_failability, bool is_const);
-bool cast_implicit_bit_width(Expr *expr, Type *to_type);
CastKind cast_to_bool_kind(Type *type);
@@ -1835,33 +1833,10 @@ static inline bool decl_poison(Decl *decl) {
decl->decl_kind = DECL_POISONED; decl->resolve_status = RESOLVE_DONE; return false;
}
static inline bool decl_is_struct_type(Decl *decl);
-static inline bool decl_is_callable_type(Decl *decl);
+
static inline bool decl_is_user_defined_type(Decl *decl);
static inline DeclKind decl_from_token(TokenType type);
-static inline bool decl_var_is_assignable(Decl *decl)
-{
- switch (decl->var.kind)
- {
- case VARDECL_GLOBAL:
- case VARDECL_LOCAL:
- case VARDECL_PARAM:
- case VARDECL_PARAM_CT:
- case VARDECL_PARAM_CT_TYPE:
- case VARDECL_PARAM_REF:
- case VARDECL_LOCAL_CT:
- case VARDECL_LOCAL_CT_TYPE:
- case VARDECL_UNWRAPPED:
- return true;
- case VARDECL_BITMEMBER:
- case VARDECL_CONST:
- case VARDECL_MEMBER:
- case VARDECL_PARAM_EXPR:
- return false;
- case VARDECL_REWRAPPED:
- case VARDECL_ERASE:
- UNREACHABLE
- }
-}
+
static inline Decl *decl_flatten(Decl *decl)
{
if (decl->decl_kind == DECL_DEFINE && decl->define_decl.define_kind != DEFINE_TYPE_GENERIC)
@@ -1897,7 +1872,6 @@ void expr_const_set_null(ExprConst *expr);
bool expr_const_compare(const ExprConst *left, const ExprConst *right, BinaryOp op);
bool expr_const_will_overflow(const ExprConst *expr, TypeKind kind);
-ArraySize expr_const_list_size(const ConstInitializer *list);
Expr *expr_generate_decl(Decl *decl, Expr *assign);
void expr_insert_addr(Expr *original);
@@ -1946,7 +1920,6 @@ const char *module_create_object_file_name(Module *module);
bool parse_file(File *file);
Path *path_create_from_string(const char *string, uint32_t len, SourceSpan span);
-Path *path_find_parent_path(Path *path);
#define SEMA_TOKEN_ERROR(_tok, ...) sema_error_range(source_span_from_token_id(_tok.id), __VA_ARGS__)
#define SEMA_TOKID_ERROR(_tok_id, ...) sema_error_range(source_span_from_token_id(_tok_id), __VA_ARGS__)
@@ -2017,7 +1990,7 @@ void stable_init(STable *table, uint32_t initial_size);
void *stable_set(STable *table, const char *key, void *value);
void *stable_get(STable *table, const char *key);
-void stable_clear(STable *table);
+UNUSED void stable_clear(STable *table);
void decltable_init(DeclTable *table, uint32_t initial_size);
Decl *decltable_get(DeclTable *table, const char *name);
@@ -2028,7 +2001,7 @@ void scratch_buffer_append(const char *string);
void scratch_buffer_append_len(const char *string, size_t len);
void scratch_buffer_append_char(char c);
void scratch_buffer_append_signed_int(int64_t i);
-void scratch_buffer_append_unsigned_int(uint64_t i);
+UNUSED void scratch_buffer_append_unsigned_int(uint64_t i);
char *scratch_buffer_to_string(void);
const char *scratch_buffer_interned(void);
@@ -2042,9 +2015,6 @@ void c_abi_func_create(FunctionPrototype *proto);
bool token_is_type(TokenType type);
bool token_is_any_type(TokenType type);
-bool token_is_symbol(TokenType type);
-bool token_is_ident_keyword(TokenType token_type);
-bool token_is_ct_ident_keyword(TokenType token_type);
const char *token_type_to_string(TokenType type);
static inline TokenType advance_token(TokenId *token)
{
@@ -2068,7 +2038,6 @@ Type *type_find_common_ancestor(Type *left, Type *right);
Type *type_find_largest_union_element(Type *type);
Type *type_find_max_type(Type *type, Type *other);
Type *type_abi_find_single_struct_element(Type *type);
-const char *type_generate_qname(Type *type);
bool type_is_valid_for_vector(Type *type);
Type *type_get_array(Type *arr_type, ArraySize len);
Type *type_get_indexed_type(Type *type);
@@ -2465,12 +2434,6 @@ static inline bool decl_is_enum_kind(Decl *decl)
return (kind == DECL_ENUM) | (kind == DECL_ERRTYPE);
}
-static inline bool decl_is_callable_type(Decl *decl)
-{
- DeclKind kind = decl->decl_kind;
- return (kind == DECL_MACRO) | (kind == DECL_FUNC) | (kind == DECL_GENERIC);
-}
-
static inline bool decl_is_user_defined_type(Decl *decl)
{
DeclKind kind = decl->decl_kind;
@@ -2568,4 +2531,5 @@ static inline Ast *ast_next(AstId *current_ptr)
Ast *ast = astptr(*current_ptr);
*current_ptr = ast->next;
return ast;
-}
\ No newline at end of file
+}
+extern ArchOsTarget default_target;
diff --git a/src/compiler/enums.h b/src/compiler/enums.h
index 49a2058b9..c7188e3c7 100644
--- a/src/compiler/enums.h
+++ b/src/compiler/enums.h
@@ -591,7 +591,6 @@ typedef enum
UNARYOP_INC,
UNARYOP_DEC,
UNARYOP_TADDR,
- UNARYOP_LAST = UNARYOP_DEC
} UnaryOp;
typedef enum
diff --git a/src/compiler/float.c b/src/compiler/float.c
index b2e1442cc..bc647dbe8 100644
--- a/src/compiler/float.c
+++ b/src/compiler/float.c
@@ -3,7 +3,7 @@
#include
#include
-static int precision_bits(TypeKind kind)
+UNUSED static int precision_bits(TypeKind kind)
{
switch (kind)
{
@@ -22,7 +22,7 @@ static int precision_bits(TypeKind kind)
}
}
-static int max_exponent(TypeKind kind)
+UNUSED static int max_exponent(TypeKind kind)
{
switch (kind)
{
@@ -41,7 +41,7 @@ static int max_exponent(TypeKind kind)
}
}
-static int min_exponent(TypeKind kind)
+UNUSED static int min_exponent(TypeKind kind)
{
switch (kind)
{
diff --git a/src/compiler/linker.c b/src/compiler/linker.c
index 93ab0cd09..32917c286 100644
--- a/src/compiler/linker.c
+++ b/src/compiler/linker.c
@@ -69,31 +69,21 @@ static void prepare_msys2_linker_flags(const char ***args, const char **files_to
#undef add_arg
}
-static void append_pie_pic_options(RelocModel reloc, const char ***args_ref)
+static void append_linker_pie_options(RelocModel reloc, const char ***args_ref)
{
switch (reloc)
{
case RELOC_DEFAULT:
UNREACHABLE
case RELOC_NONE:
- vec_add(*args_ref, "-no-pic");
- vec_add(*args_ref, "-no-pie");
- vec_add(*args_ref, "-no-PIC");
- vec_add(*args_ref, "-no-PIE");
+ vec_add(*args_ref, "-no_pie");
break;
case RELOC_SMALL_PIC:
- vec_add(*args_ref, "-pic");
- break;
case RELOC_BIG_PIC:
- vec_add(*args_ref, "-PIC");
break;
case RELOC_SMALL_PIE:
- vec_add(*args_ref, "-pie");
- vec_add(*args_ref, "-pic");
- break;
case RELOC_BIG_PIE:
- vec_add(*args_ref, "-PIE");
- vec_add(*args_ref, "-PIC");
+ vec_add(*args_ref, "-pie");
break;
}
}
@@ -199,7 +189,7 @@ static bool link_exe(const char *output_file, const char **files_to_link, unsign
vec_add(args, "-lm");
vec_add(args, "-syslibroot");
vec_add(args, "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk");
- append_pie_pic_options(platform_target.reloc_model, &args);
+ append_linker_pie_options(platform_target.reloc_model, &args);
if (platform_target.reloc_model == RELOC_SMALL_PIE || platform_target.reloc_model == RELOC_BIG_PIE)
{
vec_add(args, "-macosx_version_min");
@@ -221,7 +211,7 @@ static bool link_exe(const char *output_file, const char **files_to_link, unsign
{
case ARCH_TYPE_X86_64:
vec_add(args, "elf_x86_64");
- append_pie_pic_options(platform_target.reloc_model, &args);
+ append_linker_pie_options(platform_target.reloc_model, &args);
if (is_pie_pic(platform_target.reloc_model))
{
vec_add(args, "--eh-frame-hdr");
@@ -265,7 +255,7 @@ static bool link_exe(const char *output_file, const char **files_to_link, unsign
break;
default:
add_files(&args, files_to_link, file_count);
- append_pie_pic_options(platform_target.reloc_model, &args);
+ append_linker_pie_options(platform_target.reloc_model, &args);
return false;
}
diff --git a/src/compiler/llvm_codegen_c_abi_win64.c b/src/compiler/llvm_codegen_c_abi_win64.c
index 8e55202f0..59ebd5cfb 100644
--- a/src/compiler/llvm_codegen_c_abi_win64.c
+++ b/src/compiler/llvm_codegen_c_abi_win64.c
@@ -23,40 +23,37 @@ ABIArgInfo *win64_classify(Regs *regs, Type *type, bool is_return, bool is_vecto
Type *base = NULL;
unsigned elements = 0;
- if ((is_vector || is_reg) && type_is_homogenous_aggregate(type, &base, &elements))
+ if (is_reg && type_is_homogenous_aggregate(type, &base, &elements))
{
- if (is_reg)
+ // Enough registers? Then use direct/expand
+ if (regs->float_regs >= elements)
{
- // Enough registers? Then use direct/expand
- if (regs->float_regs >= elements)
+ regs->float_regs -= elements;
+ // Direct if return / builtin / vector
+ if (is_return || type_is_builtin(type->type_kind) || type->type_kind == TYPE_VECTOR)
{
- regs->float_regs -= elements;
- // Direct if return / builtin / vector
- if (is_return || type_is_builtin(type->type_kind) || type->type_kind == TYPE_VECTOR)
- {
- return abi_arg_new_direct();
- }
- return abi_arg_new_expand();
- }
- // Otherwise use indirect
- return abi_arg_new_indirect_not_by_val(type);
- }
- if (is_vector)
- {
- // Enough registers AND return / builtin / vector
- if (regs->float_regs >= elements &&
- (is_return || type_is_builtin(type->type_kind) || type->type_kind == TYPE_VECTOR))
- {
- regs->float_regs -= elements;
return abi_arg_new_direct();
}
- // HVAs are handled later.
- if (is_return || (!type_is_builtin(type->type_kind) && type->type_kind != TYPE_VECTOR))
- {
- return abi_arg_new_indirect_not_by_val(type);
- }
- // => to main handling.
+ return abi_arg_new_expand();
}
+ // Else use indirect
+ return abi_arg_new_indirect_not_by_val(type);
+ }
+ if (is_vector && type_is_homogenous_aggregate(type, &base, &elements))
+ {
+ // Enough registers AND return / builtin / vector
+ if (regs->float_regs >= elements &&
+ (is_return || type_is_builtin(type->type_kind) || type->type_kind == TYPE_VECTOR))
+ {
+ regs->float_regs -= elements;
+ return abi_arg_new_direct();
+ }
+ // HVAs are handled later.
+ if (is_return || (!type_is_builtin(type->type_kind) && type->type_kind != TYPE_VECTOR))
+ {
+ return abi_arg_new_indirect_not_by_val(type);
+ }
+ // => to main handling.
}
ByteSize size = type_size(type);
if (type_is_abi_aggregate(type))
diff --git a/src/compiler/llvm_codegen_c_abi_x86.c b/src/compiler/llvm_codegen_c_abi_x86.c
index 36fcdceb5..d1a0377ea 100644
--- a/src/compiler/llvm_codegen_c_abi_x86.c
+++ b/src/compiler/llvm_codegen_c_abi_x86.c
@@ -207,7 +207,6 @@ ABIArgInfo *x86_classify_return(CallABI call, Regs *regs, Type *type)
// Check if we can return it in a register.
if (x86_should_return_type_in_reg(type))
{
- ByteSize size = type_size(type);
// Special case is floats and pointers in single field structs (except for MSVC)
Type *single_element = type_abi_find_single_struct_element(type);
if (single_element)
diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c
index ce1c9bb75..f0d6065f4 100644
--- a/src/compiler/llvm_codegen_expr.c
+++ b/src/compiler/llvm_codegen_expr.c
@@ -4712,7 +4712,7 @@ void llvm_emit_call_expr(GenContext *c, BEValue *result_value, Expr *expr)
LLVMValueRef call_value = LLVMBuildCall2(c->builder, func_type, func, values, vec_size(values), "");
if (prototype->call_abi)
{
- LLVMSetInstructionCallConv(call_value, llvm_call_convention_from_call(prototype->call_abi, platform_target.arch, platform_target.os));
+ LLVMSetInstructionCallConv(call_value, llvm_call_convention_from_call(prototype->call_abi));
}
if (expr->call_expr.force_noinline)
{
diff --git a/src/compiler/llvm_codegen_function.c b/src/compiler/llvm_codegen_function.c
index 0396fa4e4..f70b4c0d3 100644
--- a/src/compiler/llvm_codegen_function.c
+++ b/src/compiler/llvm_codegen_function.c
@@ -615,7 +615,7 @@ void llvm_emit_function_decl(GenContext *c, Decl *decl)
LLVMSetDLLStorageClass(function, LLVMDLLImportStorageClass);
}
}
- LLVMSetFunctionCallConv(function, llvm_call_convention_from_call(prototype->call_abi, platform_target.arch, platform_target.os));
+ LLVMSetFunctionCallConv(function, llvm_call_convention_from_call(prototype->call_abi));
switch (decl->visibility)
{
diff --git a/src/compiler/llvm_codegen_internal.h b/src/compiler/llvm_codegen_internal.h
index f521442a6..acee87014 100644
--- a/src/compiler/llvm_codegen_internal.h
+++ b/src/compiler/llvm_codegen_internal.h
@@ -423,7 +423,7 @@ static inline bool call_supports_variadic(CallABI abi)
}
}
-static inline LLVMCallConv llvm_call_convention_from_call(CallABI abi, ArchType arch, OsType os)
+static inline LLVMCallConv llvm_call_convention_from_call(CallABI abi)
{
switch (abi)
{
diff --git a/src/compiler/number.c b/src/compiler/number.c
index e77a234e3..3f148388f 100644
--- a/src/compiler/number.c
+++ b/src/compiler/number.c
@@ -265,20 +265,5 @@ void expr_const_set_float(ExprConst *expr, Real d, TypeKind kind)
expr->const_kind = CONST_FLOAT;
}
-ArraySize expr_const_list_size(const ConstInitializer *list)
-{
- switch (list->kind)
- {
- case CONST_INIT_ZERO:
- return 0;
- case CONST_INIT_ARRAY:
- return (ArraySize)VECLAST(list->init_array.elements)->init_array_value.index + 1;
- case CONST_INIT_ARRAY_FULL:
- return vec_size(list->init_array_full);
- default:
- UNREACHABLE
- }
-}
-
diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c
index c905e1368..1e6fc90c0 100644
--- a/src/compiler/parse_global.c
+++ b/src/compiler/parse_global.c
@@ -770,8 +770,6 @@ static Decl *parse_const_declaration(ParseContext *context, Visibility visibilit
{
advance_and_verify(context, TOKEN_CONST);
- SourceSpan span = { .loc = context->prev_tok, .end_loc = context->tok.id };
-
TypeInfo *type_info = NULL;
if (parse_next_is_decl(context))
@@ -792,42 +790,6 @@ static Decl *parse_const_declaration(ParseContext *context, Visibility visibilit
return decl;
}
-/**
- * Possibilities:
- * foo(...)
- * Bar.foo(...)
- * foo::baz::bar.foo(...)
- *
- * @return true if this is a function start.
- */
-static inline bool is_function_start(ParseContext *context)
-{
- // If it's a ! then it must be function!
- if (TOKEN_IS(TOKEN_BANG)) return true;
- if (TOKEN_IS(TOKEN_IDENT))
- {
- if (context->next_tok.type == TOKEN_EQEQ || context->next_tok.type == TOKEN_EOS) return false;
- if (context->next_tok.type == TOKEN_LPAREN) return true;
- }
- TokenId current = context->tok.id;
- TokenType tok = TOKTYPE(current);
- while (1)
- {
- if (tok != TOKEN_IDENT) break;
- tok = advance_token(¤t);
- if (tok != TOKEN_SCOPE) break;
- tok = advance_token(¤t);
- }
- if (tok != TOKEN_TYPE_IDENT) return false;
- tok = advance_token(¤t);
- if (tok != TOKEN_DOT) return false;
- tok = advance_token(¤t);
- if (tok != TOKEN_IDENT) return false;
- tok = advance_token(¤t);
- return tok == TOKEN_LPAREN;
-}
-
-
Decl *parse_var_decl(ParseContext *context)
{
TokenId start = context->tok.id;
@@ -1501,19 +1463,6 @@ static inline TypeInfo **parse_generic_parameters(ParseContext *context)
return types;
}
-static inline bool parse_define_optional_path(ParseContext *context, Path **path)
-{
- if (context->tok.type != TOKEN_IDENT || context->next_tok.type != TOKEN_SCOPE)
- {
- *path = NULL;
- return true;
- }
- bool error = false;
- *path = parse_path_prefix(context, &error);
- if (error) return false;
- return true;
-}
-
/**
* define_type_body ::= TYPE_IDENT '=' 'distinct'? (func_typedef | type generic_params?) ';'
*
@@ -1901,6 +1850,7 @@ static inline bool parse_enum_spec(ParseContext *context, TypeInfo **type_ref, D
while (!try_consume(context, TOKEN_RPAREN))
{
if (!parse_param_decl(context, parent_visibility, parameters_ref, true)) return false;
+ assert(VECLAST(*parameters_ref));
if (VECLAST(*parameters_ref)->var.vararg)
{
SEMA_TOKID_ERROR(context->prev_tok, "Vararg parameters are not allowed as enum parameters.");
diff --git a/src/compiler/parse_stmt.c b/src/compiler/parse_stmt.c
index 1bc1ca888..dae1de8f6 100644
--- a/src/compiler/parse_stmt.c
+++ b/src/compiler/parse_stmt.c
@@ -353,8 +353,6 @@ static inline bool parse_foreach_var(ParseContext *context, Ast *foreach)
{
TypeInfo *type = NULL;
- bool failable = false;
-
// If we don't get foreach (foo ... or foreach (*foo ... then a type is expected.
if (!TOKEN_IS(TOKEN_IDENT) && !TOKEN_IS(TOKEN_AMP))
{
@@ -498,7 +496,6 @@ static inline Ast *parse_decl_or_expr_stmt(ParseContext *context)
ASSIGN_EXPR_ELSE(Expr *expr, parse_expr(context), poisoned_ast);
Ast *ast = ast_calloc();
ast->span = expr->span;
- bool failable = false;
// We might be parsing "int!"
// If so we need to unwrap this.
if (expr->expr_kind == EXPR_FAILABLE && expr->inner_expr->expr_kind == EXPR_TYPEINFO)
diff --git a/src/compiler/sema_casts.c b/src/compiler/sema_casts.c
index 7477924a9..dcc9e2016 100644
--- a/src/compiler/sema_casts.c
+++ b/src/compiler/sema_casts.c
@@ -141,7 +141,7 @@ bool bool_to_float(Expr *expr, Type *canonical, Type *type)
/**
* Cast bool to float.
*/
-bool voidfail_to_error(Expr *expr, Type *canonical, Type *type)
+bool voidfail_to_error(Expr *expr, Type *type)
{
Expr *inner = expr_copy(expr);
expr->expr_kind = EXPR_CATCH;
@@ -1173,27 +1173,6 @@ static bool err_to_bool(Expr *expr, Type *to_type)
return insert_cast(expr, CAST_ERBOOL, to_type);
}
-bool cast_implicit_bit_width(Expr *expr, Type *to_type)
-{
- Type *to_canonical = to_type->canonical;
- Type *from_canonical = expr->type->canonical;
- if (type_is_integer(to_canonical) && type_is_integer(from_canonical))
- {
- if (type_is_unsigned(to_canonical) != type_is_unsigned(from_canonical))
- {
- if (type_is_unsigned(from_canonical))
- {
- to_type = type_int_unsigned_by_bitsize((uint32_t)type_size(to_canonical) * 8);
- }
- else
- {
- to_type = type_int_signed_by_bitsize((uint32_t)type_size(to_canonical) * 8);
- }
- }
- }
- return cast_implicit(expr, to_type);
-}
-
static inline bool subarray_to_bool(Expr *expr)
{
if (expr->expr_kind == EXPR_CONST && expr->const_expr.const_kind == CONST_LIST)
@@ -1345,7 +1324,7 @@ bool cast(Expr *expr, Type *to_type)
// Special case *! => error
if (to == type_anyerr || to->type_kind == TYPE_ERRTYPE)
{
- if (type_is_failable(from_type)) return voidfail_to_error(expr, to, to_type);
+ if (type_is_failable(from_type)) return voidfail_to_error(expr, to_type);
}
if (type_is_failable_any(from_type))
diff --git a/src/compiler/target.c b/src/compiler/target.c
index 0b23a71a5..533cb37ef 100644
--- a/src/compiler/target.c
+++ b/src/compiler/target.c
@@ -30,10 +30,10 @@ int target_alloca_addr_space()
static void type_dump(LLVMTargetDataRef llvm_target_data, LLVMTypeRef type)
{
unsigned long long size = LLVMSizeOfTypeInBits(llvm_target_data, type);
- unsigned abialign = LLVMABIAlignmentOfType(llvm_target_data, type) * 8;
- unsigned prefalign = LLVMPreferredAlignmentOfType(llvm_target_data, type) * 8;
+ unsigned abi_align = LLVMABIAlignmentOfType(llvm_target_data, type) * 8;
+ unsigned pref_align = LLVMPreferredAlignmentOfType(llvm_target_data, type) * 8;
- printf(" | %-3llu %-3d %-3d", size, abialign, prefalign);
+ printf(" | %-3llu %-3d %-3d", size, abi_align, pref_align);
}
@@ -423,17 +423,17 @@ static inline void target_setup_x86_abi(BuildTarget *target)
static inline void target_setup_x64_abi(BuildTarget *target)
{
platform_target.abi = ABI_X64;
- X86VectorCapability vector_capability;
+ X86VectorCapability capability;
platform_target.x64.is_win64 = platform_target.os == OS_TYPE_WIN32;
if (target->feature.x86_vector_capability != X86VECTOR_DEFAULT)
{
- vector_capability = target->feature.x86_vector_capability;
+ capability = target->feature.x86_vector_capability;
}
else
{
- vector_capability = X86VECTOR_AVX;
+ capability = X86VECTOR_AVX;
}
- platform_target.x64.x86_vector_capability = vector_capability;
+ platform_target.x64.x86_vector_capability = capability;
if (target->feature.soft_float == SOFT_FLOAT_YES) platform_target.x64.soft_float = true;
if (platform_target.environment_type == ENV_TYPE_GNU)
{
@@ -443,7 +443,7 @@ static inline void target_setup_x64_abi(BuildTarget *target)
{
platform_target.x64.pass_int128_vector_in_mem = true;
}
- switch (vector_capability)
+ switch (capability)
{
case X86VECTOR_AVX:
platform_target.x64.native_vector_size_avx = 32;
@@ -463,20 +463,26 @@ static inline void target_setup_x64_abi(BuildTarget *target)
static char *arch_to_target_triple[ARCH_OS_TARGET_LAST + 1] = {
[X86_FREEBSD] = "i386-unknown-freebsd",
[X86_OPENBSD] = "i386-unknown-openbsd",
+ [X86_NETBSD] = "i386-unknown-netbsd",
[X86_MCU] = "i386-pc-elfiamcu",
[X86_WINDOWS] = "i386-pc-win32",
[X86_LINUX] = "i386-unknown-linux",
[X86_ELF] = "i386-unknown-elf",
[X64_DARWIN] = "x86_64-apple-darwin-1",
- [X64_LINUX] = "x86_64-unknown-linux-gnu",
+ [X64_LINUX] = "x86_64-pc-linux-gnu",
[X64_WINDOWS] = "x86_64-pc-windows-msvc",
- [X64_WINDOWS_GNU] = "x86_64-pc-windows-gnu",
- [X64_NETBSD] = "x86_64-unknown-netbsd",
+ [X64_WINDOWS_GNU] = "x86_64-w64-windows-gnu",
+ [X64_NETBSD] = "x86_64-pc-netbsd",
+ [X64_FREEBSD] = "x86_64-pc-freebsd",
+ [X64_OPENBSD] = "x86_64-pc-openbsd",
[X64_ELF] = "x86_64-unknown-elf",
[AARCH64_LINUX] = "aarch64-unknown-linux-gnu",
[AARCH64_DARWIN] = "aarch64-apple-darwin",
+ [AARCH64_ELF] = "aarch64-unknown-elf",
[RISCV32_LINUX] = "riscv32-unknown-linux",
+ [RISCV32_ELF] = "riscv32-unknown-elf",
[RISCV64_LINUX] = "riscv64-unknown-linux",
+ [RISCV64_ELF] = "riscv64-unknown-elf",
[WASM32] = "wasm32-unknown-unknown",
[WASM64] = "wasm64-unknown-unknown",
};
@@ -1223,6 +1229,9 @@ void target_setup(BuildTarget *target)
INITIALIZE_TARGET(X86);
// To support more targets, add them above.
+
+ if (target->arch_os_target == ARCH_OS_TARGET_DEFAULT) target->arch_os_target = default_target;
+
if (target->arch_os_target == ARCH_OS_TARGET_DEFAULT)
{
platform_target.target_triple = LLVM_DEFAULT_TARGET_TRIPLE;
@@ -1262,6 +1271,7 @@ void target_setup(BuildTarget *target)
platform_target.llvm_opt_level = (int)level;
DEBUG_LOG("Triple picked was %s.", platform_target.target_triple);
+ DEBUG_LOG("Default was %s.", LLVM_DEFAULT_TARGET_TRIPLE);
LLVMTargetMachineRef machine = llvm_target_machine_create();
char *target_triple = LLVMGetTargetMachineTriple(machine);
diff --git a/src/compiler/tokens.c b/src/compiler/tokens.c
index d8e596237..36a3e1d77 100644
--- a/src/compiler/tokens.c
+++ b/src/compiler/tokens.c
@@ -392,19 +392,6 @@ const char *token_type_to_string(TokenType type)
UNREACHABLE
}
-bool token_is_symbol(TokenType type)
-{
- switch (type)
- {
- case TOKEN_CONST:
- case TOKEN_IDENT:
- case TOKEN_TYPE_IDENT:
- return true;
- default:
- return false;
- }
-}
-
bool token_is_type(TokenType type)
{
return type >= TOKEN_VOID && type <= TOKEN_TYPEID;
@@ -415,8 +402,3 @@ bool token_is_any_type(TokenType type)
return (type >= TOKEN_VOID && type <= TOKEN_TYPEID) || type == TOKEN_CT_TYPE_IDENT || type == TOKEN_TYPE_IDENT;
}
-bool token_is_ident_keyword(TokenType type)
-{
- if (token_is_type(type)) return true;
- return type >= TOKEN_ALIAS && type <= TOKEN_WHILE;
-}
diff --git a/src/compiler/types.c b/src/compiler/types.c
index 589412384..036daecd3 100644
--- a/src/compiler/types.c
+++ b/src/compiler/types.c
@@ -330,12 +330,6 @@ RETRY:
UNREACHABLE
}
-const char *type_generate_qname(Type *type)
-{
- if (type_is_builtin(type->type_kind)) return type->name;
- return strformat("%s::%s", type->decl->module->name->module, type->name);
-}
-
bool type_is_float_or_float_vector(Type *type)
{
diff --git a/src/utils/errors.h b/src/utils/errors.h
index 80aec94fb..0546c1f20 100644
--- a/src/utils/errors.h
+++ b/src/utils/errors.h
@@ -26,10 +26,12 @@
#define UNREACHABLE FATAL_ERROR("Should be unreachable");
-#if defined(__GNUC__) && __GNUC__ >= 7
+#if (defined(__GNUC__) && __GNUC__ >= 7) || defined(__clang__)
#define FALLTHROUGH __attribute__ ((fallthrough))
+#define UNUSED __attribute__((unused))
#else
#define FALLTHROUGH ((void)0)
+#define UNUSED
#endif
diff --git a/src/utils/file_utils.c b/src/utils/file_utils.c
index d47e2d0f2..6f84ef1b4 100644
--- a/src/utils/file_utils.c
+++ b/src/utils/file_utils.c
@@ -15,7 +15,6 @@
#ifndef _MSC_VER
-#include
#include
#include
#include