From 95836e98a21bbca2a2fad57f7747f155910205a6 Mon Sep 17 00:00:00 2001 From: pitust <41321673+pitust@users.noreply.github.com> Date: Mon, 16 Aug 2021 18:38:56 +0200 Subject: [PATCH] Create {x86,x64}-elf targets, and make all targets more consistent (#273) * Add triples for x86 and x64 targets --- src/build/build_options.c | 24 ++++++++++--------- src/build/build_options.h | 2 ++ src/compiler/target.c | 8 +++++++ src/compiler/target.h | 1 + test/test_suite/abi/literal_load.c3t | 2 +- test/test_suite/abi/literal_load_aarch64.c3t | 2 +- test/test_suite/abi/literal_load_mingw.c3t | 2 +- test/test_suite/abi/pass_large_aarch.c3t | 2 +- test/test_suite/abi/test_sret.c3t | 2 +- test/test_suite/abi/union_x64.c3t | 2 +- test/test_suite/abi/vec2_aarch64.c3t | 2 +- test/test_suite/abi/vec2_x64.c3t | 2 +- test/test_suite/arrays/array_literal.c3t | 2 +- test/test_suite/arrays/array_struct.c3t | 2 +- .../test_suite/arrays/complex_array_const.c3t | 2 +- test/test_suite/assert/assert_variants.c3t | 2 +- .../compile_time_introspection/alignof.c3t | 2 +- .../compile_time_introspection/offsetof.c3t | 2 +- test/test_suite/errors/else_checks.c3t | 2 +- test/test_suite/errors/rethrow.c3t | 2 +- test/test_suite/errors/rethrow_mingw.c3t | 2 +- .../errors/simple_static_failable.c3t | 2 +- test/test_suite/errors/try_assign.c3t | 2 +- .../errors/try_with_chained_unwrap.c3t | 2 +- test/test_suite/functions/splat.c3t | 2 +- test/test_suite/functions/splat_aarch64.c3t | 2 +- test/test_suite/functions/splat_mingw.c3t | 2 +- test/test_suite/functions/test_regression.c3t | 2 +- .../functions/test_regression_mingw.c3t | 2 +- .../methods/enum_distinct_err_methods.c3t | 2 +- test/test_suite/pointers/const_pointer.c3t | 2 +- test/test_suite/statements/foreach_custom.c3t | 2 +- test/test_suite/struct/struct_as_value.c3t | 2 +- .../struct/struct_as_value_aarch64.c3t | 2 +- 34 files changed, 54 insertions(+), 41 deletions(-) diff --git a/src/build/build_options.c b/src/build/build_options.c index 5f36e04a7..e69ffbeee 100644 --- a/src/build/build_options.c +++ b/src/build/build_options.c @@ -21,18 +21,20 @@ extern const char* llvm_version; extern const char* llvm_target; char *arch_os_target[ARCH_OS_TARGET_LAST + 1] = { - [X86_FREEBSD] = "x86_freebsd", - [X86_OPENBSD] = "x86_openbsd", - [X86_MCU] = "x86_mcu", + [X86_FREEBSD] = "x86-freebsd", + [X86_OPENBSD] = "x86-openbsd", + [X86_MCU] = "x86-mcu", + [X86_ELF] = "x86-elf", [X86_WINDOWS] = "x86-windows", - [X86_LINUX] = "x86_linux", - [X64_DARWIN] = "x64_darwin", - [X64_LINUX] = "x64_linux", - [X64_WINDOWS] = "x64_windows", - [X64_WINDOWS_GNU] = "x64_mingw", - [X64_NETBSD] = "x64_netbsd", - [AARCH64_LINUX] = "aarch64_linux", - [AARCH64_DARWIN] = "aarch64_darwin", + [X86_LINUX] = "x86-linux", + [X64_DARWIN] = "x64-darwin", + [X64_LINUX] = "x64-linux", + [X64_WINDOWS] = "x64-windows", + [X64_WINDOWS_GNU] = "x64-mingw", + [X64_NETBSD] = "x64-netbsd", + [X64_ELF] = "x64-elf", + [AARCH64_LINUX] = "aarch64-linux", + [AARCH64_DARWIN] = "aarch64-darwin", [RISCV32_LINUX] = "riscv32-linux", [RISCV64_LINUX] = "riscv64-linux", [WASM32] = "wasm32", diff --git a/src/build/build_options.h b/src/build/build_options.h index 19d8a1c09..b6c626ace 100644 --- a/src/build/build_options.h +++ b/src/build/build_options.h @@ -151,11 +151,13 @@ typedef enum X86_LINUX, X86_WINDOWS, X86_MCU, + X86_ELF, X64_DARWIN, X64_LINUX, X64_NETBSD, X64_WINDOWS, X64_WINDOWS_GNU, + X64_ELF, AARCH64_LINUX, AARCH64_DARWIN, RISCV32_LINUX, diff --git a/src/compiler/target.c b/src/compiler/target.c index ec6116d74..1ff795ca0 100644 --- a/src/compiler/target.c +++ b/src/compiler/target.c @@ -406,11 +406,13 @@ static char *arch_to_target_triple[ARCH_OS_TARGET_LAST + 1] = { [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_WINDOWS] = "x86_64-pc-windows-msvc", [X64_WINDOWS_GNU] = "x86_64-pc-windows-gnu", [X64_NETBSD] = "x86_64-unknown-netbsd", + [X64_ELF] = "x86_64-unknown-elf", [AARCH64_LINUX] = "aarch64-unknown-linux-gnu", [AARCH64_DARWIN] = "aarch64-apple-darwin", [RISCV32_LINUX] = "riscv32-unknown-linux", @@ -614,6 +616,7 @@ static OsType os_from_llvm_string(StringSlice os_string) STRCASE("hurd", OS_TYPE_HURD) STRCASE("wasi", OS_TYPE_WASI) STRCASE("emscripten", OS_TYPE_EMSCRIPTEN) + STRCASE("elf", OS_TYPE_NONE) return OS_TYPE_UNKNOWN; #undef STRCASE } @@ -735,6 +738,7 @@ static ObjectFormatType object_format_from_os(OsType os) return OBJ_FORMAT_UNSUPPORTED; case OS_TYPE_LINUX: case OS_TYPE_UNKNOWN: + case OS_TYPE_NONE: case OS_TYPE_NETBSD: case OS_TYPE_OPENBSD: case OS_TYPE_FREE_BSD: @@ -789,6 +793,7 @@ static unsigned os_target_c_type_bits(OsType os, ArchType arch, CType type) break; case OS_TYPE_MACOSX: case OS_TYPE_LINUX: + case OS_TYPE_NONE: case OS_TYPE_FREE_BSD: case OS_TYPE_NETBSD: case OS_TYPE_OPENBSD: @@ -1005,6 +1010,7 @@ static PicGeneration arch_os_pic_default(ArchType arch, OsType os) case OS_TYPE_WASI: return PIC_NONE; case OS_TYPE_UNKNOWN: + case OS_TYPE_NONE: case OS_TYPE_FREE_BSD: case OS_TYPE_LINUX: case OS_TYPE_NETBSD: @@ -1029,6 +1035,7 @@ static bool arch_os_pic_default_forced(ArchType arch, OsType os) return arch == ARCH_TYPE_AARCH64 || arch == ARCH_TYPE_X86_64; case OS_TYPE_WASI: case OS_TYPE_UNKNOWN: + case OS_TYPE_NONE: case OS_TYPE_FREE_BSD: case OS_TYPE_LINUX: case OS_TYPE_NETBSD: @@ -1045,6 +1052,7 @@ static PieGeneration arch_os_pie_default(ArchType arch, OsType os, EnvironmentTy switch (os) { case OS_TYPE_UNKNOWN: + case OS_TYPE_NONE: return PIE_NONE; case OS_TYPE_OPENBSD: return PIE_SMALL; diff --git a/src/compiler/target.h b/src/compiler/target.h index dd3de8850..4b0eb04a9 100644 --- a/src/compiler/target.h +++ b/src/compiler/target.h @@ -83,6 +83,7 @@ typedef enum typedef enum { OS_TYPE_UNKNOWN, + OS_TYPE_NONE, OS_TYPE_ANANAS, OS_TYPE_CLOUD_ABI, OS_TYPE_DRAGON_FLY, diff --git a/test/test_suite/abi/literal_load.c3t b/test/test_suite/abi/literal_load.c3t index b06591eef..d30696ad9 100644 --- a/test/test_suite/abi/literal_load.c3t +++ b/test/test_suite/abi/literal_load.c3t @@ -1,4 +1,4 @@ -// #target: x64_darwin +// #target: x64-darwin struct Test { diff --git a/test/test_suite/abi/literal_load_aarch64.c3t b/test/test_suite/abi/literal_load_aarch64.c3t index 390e32a2e..2c0a0ffaf 100644 --- a/test/test_suite/abi/literal_load_aarch64.c3t +++ b/test/test_suite/abi/literal_load_aarch64.c3t @@ -1,4 +1,4 @@ -// #target: aarch64_linux +// #target: aarch64-linux module literal_load; struct Test diff --git a/test/test_suite/abi/literal_load_mingw.c3t b/test/test_suite/abi/literal_load_mingw.c3t index 3f5900bdd..6ce442ab3 100644 --- a/test/test_suite/abi/literal_load_mingw.c3t +++ b/test/test_suite/abi/literal_load_mingw.c3t @@ -1,4 +1,4 @@ -// #target: x64_mingw +// #target: x64-mingw module literal_load; struct Test diff --git a/test/test_suite/abi/pass_large_aarch.c3t b/test/test_suite/abi/pass_large_aarch.c3t index 06c3e8095..75fbf237a 100644 --- a/test/test_suite/abi/pass_large_aarch.c3t +++ b/test/test_suite/abi/pass_large_aarch.c3t @@ -1,4 +1,4 @@ -// #target: aarch64_linux +// #target: aarch64-linux module pass_large; diff --git a/test/test_suite/abi/test_sret.c3t b/test/test_suite/abi/test_sret.c3t index c7c2e99f4..d6a2440f2 100644 --- a/test/test_suite/abi/test_sret.c3t +++ b/test/test_suite/abi/test_sret.c3t @@ -1,4 +1,4 @@ -// #target: x64_darwin +// #target: x64-darwin struct Abc { long a; diff --git a/test/test_suite/abi/union_x64.c3t b/test/test_suite/abi/union_x64.c3t index e0620fd23..8899e4b9e 100644 --- a/test/test_suite/abi/union_x64.c3t +++ b/test/test_suite/abi/union_x64.c3t @@ -1,4 +1,4 @@ -// #target: x64_darwin +// #target: x64-darwin module unionx64; diff --git a/test/test_suite/abi/vec2_aarch64.c3t b/test/test_suite/abi/vec2_aarch64.c3t index f400cf69d..c90a16d38 100644 --- a/test/test_suite/abi/vec2_aarch64.c3t +++ b/test/test_suite/abi/vec2_aarch64.c3t @@ -1,4 +1,4 @@ -// #target: aarch64_linux +// #target: aarch64-linux module abi; struct Vector2 { diff --git a/test/test_suite/abi/vec2_x64.c3t b/test/test_suite/abi/vec2_x64.c3t index b528747e0..976aac014 100644 --- a/test/test_suite/abi/vec2_x64.c3t +++ b/test/test_suite/abi/vec2_x64.c3t @@ -1,4 +1,4 @@ -// #target: x64_darwin +// #target: x64-darwin module abi; struct Vector2 { diff --git a/test/test_suite/arrays/array_literal.c3t b/test/test_suite/arrays/array_literal.c3t index 27348361e..38381c637 100644 --- a/test/test_suite/arrays/array_literal.c3t +++ b/test/test_suite/arrays/array_literal.c3t @@ -1,4 +1,4 @@ -// #target: x64_darwin +// #target: x64-darwin module array_literal; func double test(uint x) diff --git a/test/test_suite/arrays/array_struct.c3t b/test/test_suite/arrays/array_struct.c3t index 9564cafb7..304ec68ea 100644 --- a/test/test_suite/arrays/array_struct.c3t +++ b/test/test_suite/arrays/array_struct.c3t @@ -1,4 +1,4 @@ -// #target: x64_darwin +// #target: x64-darwin module test; struct Foo diff --git a/test/test_suite/arrays/complex_array_const.c3t b/test/test_suite/arrays/complex_array_const.c3t index e13d6079c..c5a387497 100644 --- a/test/test_suite/arrays/complex_array_const.c3t +++ b/test/test_suite/arrays/complex_array_const.c3t @@ -1,4 +1,4 @@ -// #target: x64_darwin +// #target: x64-darwin module test; struct Connection diff --git a/test/test_suite/assert/assert_variants.c3t b/test/test_suite/assert/assert_variants.c3t index 9ec560afe..029aa0959 100644 --- a/test/test_suite/assert/assert_variants.c3t +++ b/test/test_suite/assert/assert_variants.c3t @@ -1,4 +1,4 @@ -// #target: x64_windows +// #target: x64-windows func int foo() { diff --git a/test/test_suite/compile_time_introspection/alignof.c3t b/test/test_suite/compile_time_introspection/alignof.c3t index 3d4502263..65c633c97 100644 --- a/test/test_suite/compile_time_introspection/alignof.c3t +++ b/test/test_suite/compile_time_introspection/alignof.c3t @@ -1,4 +1,4 @@ -// #target: x64_darwin +// #target: x64-darwin module foo; int[100] zfe; diff --git a/test/test_suite/compile_time_introspection/offsetof.c3t b/test/test_suite/compile_time_introspection/offsetof.c3t index 2249e8664..21bc63548 100644 --- a/test/test_suite/compile_time_introspection/offsetof.c3t +++ b/test/test_suite/compile_time_introspection/offsetof.c3t @@ -1,4 +1,4 @@ -// #target: x64_darwin +// #target: x64-darwin module foo; int[100] zfe; diff --git a/test/test_suite/errors/else_checks.c3t b/test/test_suite/errors/else_checks.c3t index 710170636..ae802856d 100644 --- a/test/test_suite/errors/else_checks.c3t +++ b/test/test_suite/errors/else_checks.c3t @@ -1,4 +1,4 @@ -// #target: x64_darwin +// #target: x64-darwin extern func int! testError(); diff --git a/test/test_suite/errors/rethrow.c3t b/test/test_suite/errors/rethrow.c3t index aa9059162..750ca4af6 100644 --- a/test/test_suite/errors/rethrow.c3t +++ b/test/test_suite/errors/rethrow.c3t @@ -1,4 +1,4 @@ -// #target: x64_darwin +// #target: x64-darwin func void! test() { diff --git a/test/test_suite/errors/rethrow_mingw.c3t b/test/test_suite/errors/rethrow_mingw.c3t index e6d5def6a..53b3bb6ee 100644 --- a/test/test_suite/errors/rethrow_mingw.c3t +++ b/test/test_suite/errors/rethrow_mingw.c3t @@ -1,4 +1,4 @@ -// #target: x64_mingw +// #target: x64-mingw module rethrow; diff --git a/test/test_suite/errors/simple_static_failable.c3t b/test/test_suite/errors/simple_static_failable.c3t index 06b19fd4b..bb0ff8510 100644 --- a/test/test_suite/errors/simple_static_failable.c3t +++ b/test/test_suite/errors/simple_static_failable.c3t @@ -1,4 +1,4 @@ -// #target: x64_darwin +// #target: x64-darwin module foo; diff --git a/test/test_suite/errors/try_assign.c3t b/test/test_suite/errors/try_assign.c3t index 28e280be6..a14c9fbc5 100644 --- a/test/test_suite/errors/try_assign.c3t +++ b/test/test_suite/errors/try_assign.c3t @@ -1,4 +1,4 @@ -// #target: x64_darwin +// #target: x64-darwin extern func int! err(); errtype FooErr { int x; } diff --git a/test/test_suite/errors/try_with_chained_unwrap.c3t b/test/test_suite/errors/try_with_chained_unwrap.c3t index dec5d361c..d37814a3b 100644 --- a/test/test_suite/errors/try_with_chained_unwrap.c3t +++ b/test/test_suite/errors/try_with_chained_unwrap.c3t @@ -1,4 +1,4 @@ -// #target: x64_darwin +// #target: x64-darwin extern func char*! readLine(); extern func int! atoi(char*); diff --git a/test/test_suite/functions/splat.c3t b/test/test_suite/functions/splat.c3t index 84d5b75a3..39477675b 100644 --- a/test/test_suite/functions/splat.c3t +++ b/test/test_suite/functions/splat.c3t @@ -1,4 +1,4 @@ -// #target: x64_darwin +// #target: x64-darwin module splat; extern func int sum_us(int... x); diff --git a/test/test_suite/functions/splat_aarch64.c3t b/test/test_suite/functions/splat_aarch64.c3t index 41177c633..9d35e17ef 100644 --- a/test/test_suite/functions/splat_aarch64.c3t +++ b/test/test_suite/functions/splat_aarch64.c3t @@ -1,4 +1,4 @@ -// #target: aarch64_linux +// #target: aarch64-linux module splat; extern func int sum_us(int... x); diff --git a/test/test_suite/functions/splat_mingw.c3t b/test/test_suite/functions/splat_mingw.c3t index 68b59dd36..7f2edc88a 100644 --- a/test/test_suite/functions/splat_mingw.c3t +++ b/test/test_suite/functions/splat_mingw.c3t @@ -1,4 +1,4 @@ -// #target: x64_mingw +// #target: x64-mingw module splat; extern func int sum_us(int... x); diff --git a/test/test_suite/functions/test_regression.c3t b/test/test_suite/functions/test_regression.c3t index f6554dfd0..c3253b21b 100644 --- a/test/test_suite/functions/test_regression.c3t +++ b/test/test_suite/functions/test_regression.c3t @@ -1,4 +1,4 @@ -// #target: x64_darwin +// #target: x64-darwin module test; import test2; diff --git a/test/test_suite/functions/test_regression_mingw.c3t b/test/test_suite/functions/test_regression_mingw.c3t index b93e18d65..e833b2a99 100644 --- a/test/test_suite/functions/test_regression_mingw.c3t +++ b/test/test_suite/functions/test_regression_mingw.c3t @@ -1,4 +1,4 @@ -// #target: x64_mingw +// #target: x64-mingw module test; import test2; diff --git a/test/test_suite/methods/enum_distinct_err_methods.c3t b/test/test_suite/methods/enum_distinct_err_methods.c3t index b1138d1d0..f448cf570 100644 --- a/test/test_suite/methods/enum_distinct_err_methods.c3t +++ b/test/test_suite/methods/enum_distinct_err_methods.c3t @@ -1,4 +1,4 @@ -// #target: x64_darwin +// #target: x64-darwin module foo; import std::io; diff --git a/test/test_suite/pointers/const_pointer.c3t b/test/test_suite/pointers/const_pointer.c3t index 2f1824a4d..1b24c70c8 100644 --- a/test/test_suite/pointers/const_pointer.c3t +++ b/test/test_suite/pointers/const_pointer.c3t @@ -1,4 +1,4 @@ -// #target: x64_darwin +// #target: x64-darwin module const_pointer; diff --git a/test/test_suite/statements/foreach_custom.c3t b/test/test_suite/statements/foreach_custom.c3t index 428bd5a37..7feecc8ad 100644 --- a/test/test_suite/statements/foreach_custom.c3t +++ b/test/test_suite/statements/foreach_custom.c3t @@ -1,4 +1,4 @@ -// #target: x64_darwin +// #target: x64-darwin module foo; struct Foo diff --git a/test/test_suite/struct/struct_as_value.c3t b/test/test_suite/struct/struct_as_value.c3t index 0ea6840bc..643138407 100644 --- a/test/test_suite/struct/struct_as_value.c3t +++ b/test/test_suite/struct/struct_as_value.c3t @@ -1,4 +1,4 @@ -// #target: x64_darwin +// #target: x64-darwin module test; struct Event diff --git a/test/test_suite/struct/struct_as_value_aarch64.c3t b/test/test_suite/struct/struct_as_value_aarch64.c3t index 6126f1ba5..bccfd2542 100644 --- a/test/test_suite/struct/struct_as_value_aarch64.c3t +++ b/test/test_suite/struct/struct_as_value_aarch64.c3t @@ -1,4 +1,4 @@ -// #target: aarch64_linux +// #target: aarch64-linux module test; struct Event