1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v.gen.c: use the __V_architecture macro in v.pref.get_host_arch()

This commit is contained in:
Delyan Angelov 2021-06-12 22:15:08 +03:00
parent 6e9218c088
commit 5452ba4653
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 11 additions and 14 deletions

View File

@ -51,7 +51,7 @@ pub fn pref_arch_to_table_language(pref_arch pref.Arch) Language {
.i386 { .i386 {
Language.i386 Language.i386
} }
._auto { ._auto, ._max {
Language.v Language.v
} }
} }

View File

@ -67,6 +67,7 @@ pub enum Arch {
rv64 // 64-bit risc-v rv64 // 64-bit risc-v
rv32 // 32-bit risc-v rv32 // 32-bit risc-v
i386 i386
_max
} }
const ( const (
@ -754,20 +755,16 @@ pub fn cc_from_string(cc_str string) CompilerType {
} }
pub fn get_host_arch() Arch { pub fn get_host_arch() Arch {
$if amd64 { // NB: we can not use `$if arch` here, because V skips cgen for the non
return .amd64 // 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 Arch(C.__V_architecture)
// return .amd64
// }
// $if arm64 { // requires new vc
$if aarch64 {
return .arm64
}
// $if arm32 {
// return .arm32
// }
panic('unknown host OS')
} }
fn parse_define(mut prefs Preferences, define string) { fn parse_define(mut prefs Preferences, define string) {