From 587075176908d44a9a524e788e7daa86a736a132 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 12 Jun 2021 22:15:08 +0300 Subject: [PATCH] v.gen.c: use the __V_architecture macro in v.pref.get_host_arch() --- vlib/v/ast/types.v | 2 +- vlib/v/pref/pref.v | 23 ++++++++++------------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/vlib/v/ast/types.v b/vlib/v/ast/types.v index 159cde105e..53b7826e3b 100644 --- a/vlib/v/ast/types.v +++ b/vlib/v/ast/types.v @@ -51,7 +51,7 @@ pub fn pref_arch_to_table_language(pref_arch pref.Arch) Language { .i386 { Language.i386 } - ._auto { + ._auto, ._max { Language.v } } diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 1a9f0fd3c4..1ce329a4f3 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -67,6 +67,7 @@ pub enum Arch { rv64 // 64-bit risc-v rv32 // 32-bit risc-v i386 + _max } const ( @@ -754,20 +755,16 @@ pub fn cc_from_string(cc_str string) CompilerType { } pub fn get_host_arch() Arch { - $if amd64 { - return .amd64 + // NB: we can not use `$if arch` here, because V skips cgen for the non + // current comptime branches by default, so there is a bootstrapping + // problem => the __V_architecture macro is used to resolve it. + // TODO: think about how to solve it for non C backends, perhaps we + // need a comptime `$if native {` too, and/or a mechanism to always + // generate all branches for specific functions? + if C.__V_architecture <= int(Arch._auto) || C.__V_architecture >= int(Arch._max) { + panic('unknown host CPU architecture') } - // $if i386 { - // return .amd64 - // } - // $if arm64 { // requires new vc - $if aarch64 { - return .arm64 - } - // $if arm32 { - // return .arm32 - // } - panic('unknown host OS') + return Arch(C.__V_architecture) } fn parse_define(mut prefs Preferences, define string) {