General cleanup, more native platform detection.

This commit is contained in:
Christoffer Lerno
2022-02-17 20:49:57 +01:00
committed by Christoffer Lerno
parent 73351e0aa9
commit bf5683b41c
27 changed files with 167 additions and 304 deletions

View File

@@ -75,6 +75,9 @@ set(LLVM_LINK_COMPONENTS
WindowsManifest 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}) 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_MINGW NAMES lldMinGW.a liblldMinGW.a PATHS ${LLVM_LIBRARY_DIRS})
find_library(LLD_WASM NAMES lldWasm.a liblldWasm.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_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_DRIVER NAMES lldDriver.a liblldDriver.a PATHS ${LLVM_LIBRARY_DIRS})
find_library(LLD_READER_WRITER NAMES lldReaderWriter.a liblldReaderWriter.a PATHS ${LLVM_LIBRARY_DIRS}) find_library(LLD_READER_WRITER NAMES lldReaderWriter.a liblldReaderWriter.a PATHS ${LLVM_LIBRARY_DIRS})

View File

@@ -25,6 +25,7 @@ extern const char* llvm_target;
char *arch_os_target[ARCH_OS_TARGET_LAST + 1] = { char *arch_os_target[ARCH_OS_TARGET_LAST + 1] = {
[X86_FREEBSD] = "x86-freebsd", [X86_FREEBSD] = "x86-freebsd",
[X86_OPENBSD] = "x86-openbsd", [X86_OPENBSD] = "x86-openbsd",
[X86_NETBSD] = "x86-netbsd",
[X86_MCU] = "x86-mcu", [X86_MCU] = "x86-mcu",
[X86_ELF] = "x86-elf", [X86_ELF] = "x86-elf",
[X86_WINDOWS] = "x86-windows", [X86_WINDOWS] = "x86-windows",
@@ -33,12 +34,17 @@ char *arch_os_target[ARCH_OS_TARGET_LAST + 1] = {
[X64_LINUX] = "x64-linux", [X64_LINUX] = "x64-linux",
[X64_WINDOWS] = "x64-windows", [X64_WINDOWS] = "x64-windows",
[X64_WINDOWS_GNU] = "x64-mingw", [X64_WINDOWS_GNU] = "x64-mingw",
[X64_FREEBSD] = "x64-freebsd",
[X64_OPENBSD] = "x64-openbsd",
[X64_NETBSD] = "x64-netbsd", [X64_NETBSD] = "x64-netbsd",
[X64_ELF] = "x64-elf", [X64_ELF] = "x64-elf",
[AARCH64_LINUX] = "aarch64-linux", [AARCH64_LINUX] = "aarch64-linux",
[AARCH64_DARWIN] = "aarch64-darwin", [AARCH64_DARWIN] = "aarch64-darwin",
[AARCH64_ELF] = "aarch64-elf",
[RISCV32_LINUX] = "riscv32-linux", [RISCV32_LINUX] = "riscv32-linux",
[RISCV32_ELF] = "riscv32-elf",
[RISCV64_LINUX] = "riscv64-linux", [RISCV64_LINUX] = "riscv64-linux",
[RISCV64_ELF] = "riscv64-elf",
[WASM32] = "wasm32", [WASM32] = "wasm32",
[WASM64] = "wasm64", [WASM64] = "wasm64",
}; };
@@ -70,7 +76,7 @@ static void usage(void)
OUTPUT(" --stdlib <dir> - Use this directory as the C3 standard library path."); OUTPUT(" --stdlib <dir> - Use this directory as the C3 standard library path.");
OUTPUT(" --lib <dir> - Use this directory as the C3 library path."); OUTPUT(" --lib <dir> - Use this directory as the C3 library path.");
OUTPUT(" --path <dir> - Use this as the base directory for the current command."); OUTPUT(" --path <dir> - Use this as the base directory for the current command.");
OUTPUT(" --template <template> - Use a different template: \"lib\", \"staticlib\" or a path."); OUTPUT(" --template <template> - Use a different template: \"lib\", \"static-lib\" or a path.");
OUTPUT(" --about - Prints a short description of C3."); OUTPUT(" --about - Prints a short description of C3.");
OUTPUT(" --symtab <value> - Sets the preferred symtab size."); OUTPUT(" --symtab <value> - Sets the preferred symtab size.");
OUTPUT(" -V --version - Print version information."); OUTPUT(" -V --version - Print version information.");

View File

@@ -112,24 +112,6 @@ typedef enum
SIZE_OPTIMIZATION_TINY = 2, // -Oz SIZE_OPTIMIZATION_TINY = 2, // -Oz
} SizeOptimizationLevel; } 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 typedef enum
{ {
SOFT_FLOAT_DEFAULT = -1, SOFT_FLOAT_DEFAULT = -1,
@@ -193,6 +175,7 @@ typedef enum
ARCH_OS_TARGET_DEFAULT = 0, ARCH_OS_TARGET_DEFAULT = 0,
X86_FREEBSD, X86_FREEBSD,
X86_OPENBSD, X86_OPENBSD,
X86_NETBSD,
X86_LINUX, X86_LINUX,
X86_WINDOWS, X86_WINDOWS,
X86_MCU, X86_MCU,
@@ -200,13 +183,18 @@ typedef enum
X64_DARWIN, X64_DARWIN,
X64_LINUX, X64_LINUX,
X64_NETBSD, X64_NETBSD,
X64_FREEBSD,
X64_OPENBSD,
X64_WINDOWS, X64_WINDOWS,
X64_WINDOWS_GNU, X64_WINDOWS_GNU,
X64_ELF, X64_ELF,
AARCH64_LINUX, AARCH64_LINUX,
AARCH64_DARWIN, AARCH64_DARWIN,
AARCH64_ELF,
RISCV32_LINUX, RISCV32_LINUX,
RISCV32_ELF,
RISCV64_LINUX, RISCV64_LINUX,
RISCV64_ELF,
WASM32, WASM32,
WASM64, WASM64,
ARCH_OS_TARGET_LAST = WASM64 ARCH_OS_TARGET_LAST = WASM64

View File

@@ -13,6 +13,63 @@
void load_library_files(void) {} void load_library_files(void) {}
void load_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) 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; 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; if (options->reloc_model != RELOC_DEFAULT) target->reloc_model = options->reloc_model;
for (int i = 0; i < options->linker_arg_count; i++) for (int i = 0; i < options->linker_arg_count; i++)

View File

@@ -217,7 +217,6 @@ static void project_add_targets(Project *project, JSONObject *project_data)
{ {
error_exit("'targets' did not contain map of targets."); error_exit("'targets' did not contain map of targets.");
} }
JSONObject *targets_find = NULL;
for (unsigned i = 0; i < targets_json->member_len; i++) for (unsigned i = 0; i < targets_json->member_len; i++)
{ {
JSONObject *object = targets_json->members[i]; JSONObject *object = targets_json->members[i];

View File

@@ -106,7 +106,7 @@ const char *decl_to_name(Decl *decl)
case VARDECL_PARAM_REF: case VARDECL_PARAM_REF:
return "ref parameter"; return "ref parameter";
case VARDECL_PARAM_EXPR: case VARDECL_PARAM_EXPR:
return "extpression parameter"; return "expression parameter";
case VARDECL_LOCAL_CT: case VARDECL_LOCAL_CT:
return "compile time variable"; return "compile time variable";
case VARDECL_LOCAL_CT_TYPE: case VARDECL_LOCAL_CT_TYPE:

View File

@@ -6,23 +6,23 @@
#include <inttypes.h> #include <inttypes.h>
#include <math.h> #include <math.h>
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; 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; 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; 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) if (digit <= 9)
{ {
@@ -93,7 +93,7 @@ Int128 i128_from_str(const char *str)
return x; 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; char c;
Int128 x = { 0, 0 }; Int128 x = { 0, 0 };
@@ -105,7 +105,7 @@ Int128 i128_from_strl(const char *str, const char *end)
return x; 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; char c;
Int128 x = { 0, 0 }; 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 // Check all zero
if (!op2 && !op1.high && !op1.low) return CMP_EQ; 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; 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.high) return CMP_GT;
if (op1.low == op2) return CMP_EQ; if (op1.low == op2) return CMP_EQ;
return op1.low > op2 ? CMP_GT : CMP_LT; 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_GT;
if (op1.high < op2.high) return CMP_LT; 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 }; 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); assert(bit < 128 && bit >= 0);
if (bit > 63) if (bit > 63)
@@ -322,6 +322,7 @@ Int128 i128_lshr(Int128 op1, Int128 op2)
Int128 i128_ashr64(Int128 op1, uint64_t amount) Int128 i128_ashr64(Int128 op1, uint64_t amount)
{ {
if (amount == 0) return op1;
if (!ISNEG(op1.high)) return i128_lshr64(op1, amount); if (!ISNEG(op1.high)) return i128_lshr64(op1, amount);
if (amount > 127) return (Int128){ UINT64_MAX, UINT64_MAX }; if (amount > 127) return (Int128){ UINT64_MAX, UINT64_MAX };
if (amount == 64) return (Int128){ UINT64_MAX, op1.high }; 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; 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); return popcnt64(i.high) + popcnt64(i.low);
} }
@@ -725,7 +726,6 @@ unsigned int_bits_needed(Int op)
{ {
TypeKind kind = op.type; TypeKind kind = op.type;
Int128 i = op.i; Int128 i = op.i;
int bits_used;
if (type_kind_is_signed(kind)) if (type_kind_is_signed(kind))
{ {
if (i128_is_neg(i)) if (i128_is_neg(i))

View File

@@ -36,7 +36,7 @@ bool abi_type_is_integer(AbiType type);
bool abi_type_is_float(AbiType type); bool abi_type_is_float(AbiType type);
static inline void abi_type_set_type(AbiType *abi_type, Type *type); static inline void abi_type_set_type(AbiType *abi_type, Type *type);
static inline AbiType abi_type_get(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); TypeSize abi_type_size(AbiType type);
typedef struct typedef struct
@@ -81,9 +81,3 @@ static inline void abi_type_set_type(AbiType *abi_type, Type *type)
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;
}

View File

@@ -103,39 +103,19 @@ typedef struct CompileData_
Task task; Task task;
} CompileData; } 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); 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); 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) static const char *active_target_name(void)
{ {
if (active_target.name) return active_target.name; if (active_target.name) return active_target.name;
@@ -260,7 +240,6 @@ void compiler_compile(void)
for (int i = 0; i < cfiles; i++) for (int i = 0; i < cfiles; i++)
{ {
char *filename = NULL; char *filename = NULL;
char *dir = NULL;
bool split_worked = filenamesplit(active_target.csources[i], &filename, NULL); bool split_worked = filenamesplit(active_target.csources[i], &filename, NULL);
assert(split_worked); assert(split_worked);
size_t len = strlen(filename); size_t len = strlen(filename);
@@ -297,7 +276,7 @@ void compiler_compile(void)
if (create_exe) if (create_exe)
{ {
const char *output_name = active_target_name(); 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); platform_linker(output_name, obj_files, output_file_count);
} }

View File

@@ -563,7 +563,6 @@ typedef struct Decl_
Visibility visibility : 3; Visibility visibility : 3;
ResolveStatus resolve_status : 3; ResolveStatus resolve_status : 3;
bool is_packed : 1; bool is_packed : 1;
bool needs_additional_pad : 1;
bool is_substruct : 1; bool is_substruct : 1;
bool has_variable_array : 1; bool has_variable_array : 1;
bool no_scope : 1; bool no_scope : 1;
@@ -1748,13 +1747,13 @@ Real i128_to_float_signed(Int128 op);
bool i128_is_zero(Int128 op); bool i128_is_zero(Int128 op);
uint32_t i128_clz(const Int128 *op); uint32_t i128_clz(const Int128 *op);
uint32_t i128_ctz(const Int128 *op); uint32_t i128_ctz(const Int128 *op);
int i128_lsb(const Int128 *op); UNUSED int i128_lsb(const Int128 *op);
int i128_msb(const Int128 *op); UNUSED int i128_msb(const Int128 *op);
Int128 i128_from_float_signed(Real d); Int128 i128_from_float_signed(Real d);
Int128 i128_from_float_unsigned(Real d); Int128 i128_from_float_unsigned(Real d);
Int128 i128_from_signed(int64_t i); Int128 i128_from_signed(int64_t i);
Int128 i128_from_unsigned(uint64_t i); UNUSED Int128 i128_from_unsigned(uint64_t i);
bool i128_get_bit(const Int128 *op, int bit); UNUSED bool i128_get_bit(const Int128 *op, int bit);
static inline bool type_may_negate(Type *type) 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_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_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); 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; 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_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 bool decl_is_user_defined_type(Decl *decl);
static inline DeclKind decl_from_token(TokenType type); 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) static inline Decl *decl_flatten(Decl *decl)
{ {
if (decl->decl_kind == DECL_DEFINE && decl->define_decl.define_kind != DEFINE_TYPE_GENERIC) 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_compare(const ExprConst *left, const ExprConst *right, BinaryOp op);
bool expr_const_will_overflow(const ExprConst *expr, TypeKind kind); 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); Expr *expr_generate_decl(Decl *decl, Expr *assign);
void expr_insert_addr(Expr *original); void expr_insert_addr(Expr *original);
@@ -1946,7 +1920,6 @@ const char *module_create_object_file_name(Module *module);
bool parse_file(File *file); bool parse_file(File *file);
Path *path_create_from_string(const char *string, uint32_t len, SourceSpan span); 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_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__) #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_set(STable *table, const char *key, void *value);
void *stable_get(STable *table, const char *key); 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); void decltable_init(DeclTable *table, uint32_t initial_size);
Decl *decltable_get(DeclTable *table, const char *name); 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_len(const char *string, size_t len);
void scratch_buffer_append_char(char c); void scratch_buffer_append_char(char c);
void scratch_buffer_append_signed_int(int64_t i); 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); char *scratch_buffer_to_string(void);
const char *scratch_buffer_interned(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_type(TokenType type);
bool token_is_any_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); const char *token_type_to_string(TokenType type);
static inline TokenType advance_token(TokenId *token) 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_largest_union_element(Type *type);
Type *type_find_max_type(Type *type, Type *other); Type *type_find_max_type(Type *type, Type *other);
Type *type_abi_find_single_struct_element(Type *type); Type *type_abi_find_single_struct_element(Type *type);
const char *type_generate_qname(Type *type);
bool type_is_valid_for_vector(Type *type); bool type_is_valid_for_vector(Type *type);
Type *type_get_array(Type *arr_type, ArraySize len); Type *type_get_array(Type *arr_type, ArraySize len);
Type *type_get_indexed_type(Type *type); 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); 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) static inline bool decl_is_user_defined_type(Decl *decl)
{ {
DeclKind kind = decl->decl_kind; DeclKind kind = decl->decl_kind;
@@ -2568,4 +2531,5 @@ static inline Ast *ast_next(AstId *current_ptr)
Ast *ast = astptr(*current_ptr); Ast *ast = astptr(*current_ptr);
*current_ptr = ast->next; *current_ptr = ast->next;
return ast; return ast;
} }
extern ArchOsTarget default_target;

View File

@@ -591,7 +591,6 @@ typedef enum
UNARYOP_INC, UNARYOP_INC,
UNARYOP_DEC, UNARYOP_DEC,
UNARYOP_TADDR, UNARYOP_TADDR,
UNARYOP_LAST = UNARYOP_DEC
} UnaryOp; } UnaryOp;
typedef enum typedef enum

View File

@@ -3,7 +3,7 @@
#include <math.h> #include <math.h>
#include <errno.h> #include <errno.h>
static int precision_bits(TypeKind kind) UNUSED static int precision_bits(TypeKind kind)
{ {
switch (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) 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) switch (kind)
{ {

View File

@@ -69,31 +69,21 @@ static void prepare_msys2_linker_flags(const char ***args, const char **files_to
#undef add_arg #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) switch (reloc)
{ {
case RELOC_DEFAULT: case RELOC_DEFAULT:
UNREACHABLE UNREACHABLE
case RELOC_NONE: case RELOC_NONE:
vec_add(*args_ref, "-no-pic"); vec_add(*args_ref, "-no_pie");
vec_add(*args_ref, "-no-pie");
vec_add(*args_ref, "-no-PIC");
vec_add(*args_ref, "-no-PIE");
break; break;
case RELOC_SMALL_PIC: case RELOC_SMALL_PIC:
vec_add(*args_ref, "-pic");
break;
case RELOC_BIG_PIC: case RELOC_BIG_PIC:
vec_add(*args_ref, "-PIC");
break; break;
case RELOC_SMALL_PIE: case RELOC_SMALL_PIE:
vec_add(*args_ref, "-pie");
vec_add(*args_ref, "-pic");
break;
case RELOC_BIG_PIE: case RELOC_BIG_PIE:
vec_add(*args_ref, "-PIE"); vec_add(*args_ref, "-pie");
vec_add(*args_ref, "-PIC");
break; 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, "-lm");
vec_add(args, "-syslibroot"); vec_add(args, "-syslibroot");
vec_add(args, "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"); 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) if (platform_target.reloc_model == RELOC_SMALL_PIE || platform_target.reloc_model == RELOC_BIG_PIE)
{ {
vec_add(args, "-macosx_version_min"); 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: case ARCH_TYPE_X86_64:
vec_add(args, "elf_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)) if (is_pie_pic(platform_target.reloc_model))
{ {
vec_add(args, "--eh-frame-hdr"); 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; break;
default: default:
add_files(&args, files_to_link, file_count); 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; return false;
} }

View File

@@ -23,40 +23,37 @@ ABIArgInfo *win64_classify(Regs *regs, Type *type, bool is_return, bool is_vecto
Type *base = NULL; Type *base = NULL;
unsigned elements = 0; 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 regs->float_regs -= elements;
if (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(); return abi_arg_new_direct();
} }
// HVAs are handled later. return abi_arg_new_expand();
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.
} }
// 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); ByteSize size = type_size(type);
if (type_is_abi_aggregate(type)) if (type_is_abi_aggregate(type))

View File

@@ -207,7 +207,6 @@ ABIArgInfo *x86_classify_return(CallABI call, Regs *regs, Type *type)
// Check if we can return it in a register. // Check if we can return it in a register.
if (x86_should_return_type_in_reg(type)) 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) // Special case is floats and pointers in single field structs (except for MSVC)
Type *single_element = type_abi_find_single_struct_element(type); Type *single_element = type_abi_find_single_struct_element(type);
if (single_element) if (single_element)

View File

@@ -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), ""); LLVMValueRef call_value = LLVMBuildCall2(c->builder, func_type, func, values, vec_size(values), "");
if (prototype->call_abi) 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) if (expr->call_expr.force_noinline)
{ {

View File

@@ -615,7 +615,7 @@ void llvm_emit_function_decl(GenContext *c, Decl *decl)
LLVMSetDLLStorageClass(function, LLVMDLLImportStorageClass); 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) switch (decl->visibility)
{ {

View File

@@ -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) switch (abi)
{ {

View File

@@ -265,20 +265,5 @@ void expr_const_set_float(ExprConst *expr, Real d, TypeKind kind)
expr->const_kind = CONST_FLOAT; 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
}
}

View File

@@ -770,8 +770,6 @@ static Decl *parse_const_declaration(ParseContext *context, Visibility visibilit
{ {
advance_and_verify(context, TOKEN_CONST); advance_and_verify(context, TOKEN_CONST);
SourceSpan span = { .loc = context->prev_tok, .end_loc = context->tok.id };
TypeInfo *type_info = NULL; TypeInfo *type_info = NULL;
if (parse_next_is_decl(context)) if (parse_next_is_decl(context))
@@ -792,42 +790,6 @@ static Decl *parse_const_declaration(ParseContext *context, Visibility visibilit
return decl; 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(&current);
if (tok != TOKEN_SCOPE) break;
tok = advance_token(&current);
}
if (tok != TOKEN_TYPE_IDENT) return false;
tok = advance_token(&current);
if (tok != TOKEN_DOT) return false;
tok = advance_token(&current);
if (tok != TOKEN_IDENT) return false;
tok = advance_token(&current);
return tok == TOKEN_LPAREN;
}
Decl *parse_var_decl(ParseContext *context) Decl *parse_var_decl(ParseContext *context)
{ {
TokenId start = context->tok.id; TokenId start = context->tok.id;
@@ -1501,19 +1463,6 @@ static inline TypeInfo **parse_generic_parameters(ParseContext *context)
return types; 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?) ';' * 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)) while (!try_consume(context, TOKEN_RPAREN))
{ {
if (!parse_param_decl(context, parent_visibility, parameters_ref, true)) return false; if (!parse_param_decl(context, parent_visibility, parameters_ref, true)) return false;
assert(VECLAST(*parameters_ref));
if (VECLAST(*parameters_ref)->var.vararg) if (VECLAST(*parameters_ref)->var.vararg)
{ {
SEMA_TOKID_ERROR(context->prev_tok, "Vararg parameters are not allowed as enum parameters."); SEMA_TOKID_ERROR(context->prev_tok, "Vararg parameters are not allowed as enum parameters.");

View File

@@ -353,8 +353,6 @@ static inline bool parse_foreach_var(ParseContext *context, Ast *foreach)
{ {
TypeInfo *type = NULL; TypeInfo *type = NULL;
bool failable = false;
// If we don't get foreach (foo ... or foreach (*foo ... then a type is expected. // If we don't get foreach (foo ... or foreach (*foo ... then a type is expected.
if (!TOKEN_IS(TOKEN_IDENT) && !TOKEN_IS(TOKEN_AMP)) 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); ASSIGN_EXPR_ELSE(Expr *expr, parse_expr(context), poisoned_ast);
Ast *ast = ast_calloc(); Ast *ast = ast_calloc();
ast->span = expr->span; ast->span = expr->span;
bool failable = false;
// We might be parsing "int!" // We might be parsing "int!"
// If so we need to unwrap this. // If so we need to unwrap this.
if (expr->expr_kind == EXPR_FAILABLE && expr->inner_expr->expr_kind == EXPR_TYPEINFO) if (expr->expr_kind == EXPR_FAILABLE && expr->inner_expr->expr_kind == EXPR_TYPEINFO)

View File

@@ -141,7 +141,7 @@ bool bool_to_float(Expr *expr, Type *canonical, Type *type)
/** /**
* Cast bool to float. * 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 *inner = expr_copy(expr);
expr->expr_kind = EXPR_CATCH; 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); 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) static inline bool subarray_to_bool(Expr *expr)
{ {
if (expr->expr_kind == EXPR_CONST && expr->const_expr.const_kind == CONST_LIST) 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 // Special case *! => error
if (to == type_anyerr || to->type_kind == TYPE_ERRTYPE) 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)) if (type_is_failable_any(from_type))

View File

@@ -30,10 +30,10 @@ int target_alloca_addr_space()
static void type_dump(LLVMTargetDataRef llvm_target_data, LLVMTypeRef type) static void type_dump(LLVMTargetDataRef llvm_target_data, LLVMTypeRef type)
{ {
unsigned long long size = LLVMSizeOfTypeInBits(llvm_target_data, type); unsigned long long size = LLVMSizeOfTypeInBits(llvm_target_data, type);
unsigned abialign = LLVMABIAlignmentOfType(llvm_target_data, type) * 8; unsigned abi_align = LLVMABIAlignmentOfType(llvm_target_data, type) * 8;
unsigned prefalign = LLVMPreferredAlignmentOfType(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) static inline void target_setup_x64_abi(BuildTarget *target)
{ {
platform_target.abi = ABI_X64; platform_target.abi = ABI_X64;
X86VectorCapability vector_capability; X86VectorCapability capability;
platform_target.x64.is_win64 = platform_target.os == OS_TYPE_WIN32; platform_target.x64.is_win64 = platform_target.os == OS_TYPE_WIN32;
if (target->feature.x86_vector_capability != X86VECTOR_DEFAULT) if (target->feature.x86_vector_capability != X86VECTOR_DEFAULT)
{ {
vector_capability = target->feature.x86_vector_capability; capability = target->feature.x86_vector_capability;
} }
else 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 (target->feature.soft_float == SOFT_FLOAT_YES) platform_target.x64.soft_float = true;
if (platform_target.environment_type == ENV_TYPE_GNU) 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; platform_target.x64.pass_int128_vector_in_mem = true;
} }
switch (vector_capability) switch (capability)
{ {
case X86VECTOR_AVX: case X86VECTOR_AVX:
platform_target.x64.native_vector_size_avx = 32; 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] = { static char *arch_to_target_triple[ARCH_OS_TARGET_LAST + 1] = {
[X86_FREEBSD] = "i386-unknown-freebsd", [X86_FREEBSD] = "i386-unknown-freebsd",
[X86_OPENBSD] = "i386-unknown-openbsd", [X86_OPENBSD] = "i386-unknown-openbsd",
[X86_NETBSD] = "i386-unknown-netbsd",
[X86_MCU] = "i386-pc-elfiamcu", [X86_MCU] = "i386-pc-elfiamcu",
[X86_WINDOWS] = "i386-pc-win32", [X86_WINDOWS] = "i386-pc-win32",
[X86_LINUX] = "i386-unknown-linux", [X86_LINUX] = "i386-unknown-linux",
[X86_ELF] = "i386-unknown-elf", [X86_ELF] = "i386-unknown-elf",
[X64_DARWIN] = "x86_64-apple-darwin-1", [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] = "x86_64-pc-windows-msvc",
[X64_WINDOWS_GNU] = "x86_64-pc-windows-gnu", [X64_WINDOWS_GNU] = "x86_64-w64-windows-gnu",
[X64_NETBSD] = "x86_64-unknown-netbsd", [X64_NETBSD] = "x86_64-pc-netbsd",
[X64_FREEBSD] = "x86_64-pc-freebsd",
[X64_OPENBSD] = "x86_64-pc-openbsd",
[X64_ELF] = "x86_64-unknown-elf", [X64_ELF] = "x86_64-unknown-elf",
[AARCH64_LINUX] = "aarch64-unknown-linux-gnu", [AARCH64_LINUX] = "aarch64-unknown-linux-gnu",
[AARCH64_DARWIN] = "aarch64-apple-darwin", [AARCH64_DARWIN] = "aarch64-apple-darwin",
[AARCH64_ELF] = "aarch64-unknown-elf",
[RISCV32_LINUX] = "riscv32-unknown-linux", [RISCV32_LINUX] = "riscv32-unknown-linux",
[RISCV32_ELF] = "riscv32-unknown-elf",
[RISCV64_LINUX] = "riscv64-unknown-linux", [RISCV64_LINUX] = "riscv64-unknown-linux",
[RISCV64_ELF] = "riscv64-unknown-elf",
[WASM32] = "wasm32-unknown-unknown", [WASM32] = "wasm32-unknown-unknown",
[WASM64] = "wasm64-unknown-unknown", [WASM64] = "wasm64-unknown-unknown",
}; };
@@ -1223,6 +1229,9 @@ void target_setup(BuildTarget *target)
INITIALIZE_TARGET(X86); INITIALIZE_TARGET(X86);
// To support more targets, add them above. // 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) if (target->arch_os_target == ARCH_OS_TARGET_DEFAULT)
{ {
platform_target.target_triple = LLVM_DEFAULT_TARGET_TRIPLE; platform_target.target_triple = LLVM_DEFAULT_TARGET_TRIPLE;
@@ -1262,6 +1271,7 @@ void target_setup(BuildTarget *target)
platform_target.llvm_opt_level = (int)level; platform_target.llvm_opt_level = (int)level;
DEBUG_LOG("Triple picked was %s.", platform_target.target_triple); 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(); LLVMTargetMachineRef machine = llvm_target_machine_create();
char *target_triple = LLVMGetTargetMachineTriple(machine); char *target_triple = LLVMGetTargetMachineTriple(machine);

View File

@@ -392,19 +392,6 @@ const char *token_type_to_string(TokenType type)
UNREACHABLE 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) bool token_is_type(TokenType type)
{ {
return type >= TOKEN_VOID && type <= TOKEN_TYPEID; 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; 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;
}

View File

@@ -330,12 +330,6 @@ RETRY:
UNREACHABLE 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) bool type_is_float_or_float_vector(Type *type)
{ {

View File

@@ -26,10 +26,12 @@
#define UNREACHABLE FATAL_ERROR("Should be unreachable"); #define UNREACHABLE FATAL_ERROR("Should be unreachable");
#if defined(__GNUC__) && __GNUC__ >= 7 #if (defined(__GNUC__) && __GNUC__ >= 7) || defined(__clang__)
#define FALLTHROUGH __attribute__ ((fallthrough)) #define FALLTHROUGH __attribute__ ((fallthrough))
#define UNUSED __attribute__((unused))
#else #else
#define FALLTHROUGH ((void)0) #define FALLTHROUGH ((void)0)
#define UNUSED
#endif #endif

View File

@@ -15,7 +15,6 @@
#ifndef _MSC_VER #ifndef _MSC_VER
#include <libgen.h>
#include <unistd.h> #include <unistd.h>
#include <dirent.h> #include <dirent.h>
#include <limits.h> #include <limits.h>