From: Brendan Hansen Date: Fri, 18 Mar 2022 03:52:20 +0000 (-0500) Subject: added architecture compile time variable X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=0b28aa24011e9552e6b5e6ffd94353355f97f9f8;p=onyx.git added architecture compile time variable --- diff --git a/core/runtime/build_opts.onyx b/core/runtime/build_opts.onyx index 1016bdb9..ad0feca2 100644 --- a/core/runtime/build_opts.onyx +++ b/core/runtime/build_opts.onyx @@ -12,4 +12,12 @@ Runtime :: enum { OS :: enum { Linux :: 1; Windows :: 2; +} + +// arch: Arch This is set by the compiler. +Arch :: enum { + Unknown :: 0; + X86_64 :: 1; + X86_32 :: 2; + AARCH64 :: 3; } \ No newline at end of file diff --git a/src/builtins.c b/src/builtins.c index 98dacf4d..94d412ed 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -511,5 +511,25 @@ void introduce_build_options(bh_allocator a) { os_type->type_node = OS_Type; add_entities_for_node(NULL, (AstNode *) os_type, NULL, NULL); symbol_builtin_introduce(p->scope, "compiler_os", (AstNode *) os_type); + + i32 arch = 0; + #if defined(__x86_64__) || defined(_M_X64) + arch = 1; // X86_64; + #elif defined(i386) || defined(__i386__) || defined(__i386) || defined(_M_IX86) + arch = 2; // X86_32; + #elif defined(__aarch64__) || defined(_M_ARM64) + arch = 3; // AARCH64; + #endif + + AstType* Arch_Type = (AstType *) symbol_raw_resolve(p->scope, "Arch"); + if (Arch_Type == NULL) { + onyx_report_error((OnyxFilePos) {0}, Error_Critical, "'Arch' type not found in package runtime."); + return; + } + + AstNumLit* arch_type = make_int_literal(a, arch); + arch_type->type_node = Arch_Type; + add_entities_for_node(NULL, (AstNode *) arch_type, NULL, NULL); + symbol_builtin_introduce(p->scope, "arch", (AstNode *) arch_type); }