added architecture compile time variable
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 18 Mar 2022 03:52:20 +0000 (22:52 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 18 Mar 2022 03:52:20 +0000 (22:52 -0500)
core/runtime/build_opts.onyx
src/builtins.c

index 1016bdb95b7d9915f5effc6e592a82e54a55489d..ad0feca2d49b7fb760975902c211d2eca459af46 100644 (file)
@@ -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
index 98dacf4d1649c1dd4e5df44af4e3a95456883b03..94d412edef282adf846b2c6d63db055e11baba15 100644 (file)
@@ -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);
 }