From 2ff0f628663d6681cd5c90c0a20234685ef1dfc1 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 13 Jun 2021 00:45:17 +0300 Subject: [PATCH] v: fix passing `-arch arm64` to `$if arm64{}` --- vlib/sync/atomic2/atomic.v | 2 +- vlib/sync/channels.v | 2 +- vlib/v/builder/native.v | 3 -- vlib/v/checker/checker.v | 45 +++++++++++++++++---------- vlib/v/gen/native/gen.v | 6 ++-- vlib/v/gen/native/tests/native_test.v | 5 +-- vlib/v/pref/default.v | 3 ++ vlib/v/pref/pref.v | 1 + 8 files changed, 38 insertions(+), 29 deletions(-) diff --git a/vlib/sync/atomic2/atomic.v b/vlib/sync/atomic2/atomic.v index e57bade962..2ff64f2a21 100644 --- a/vlib/sync/atomic2/atomic.v +++ b/vlib/sync/atomic2/atomic.v @@ -29,7 +29,7 @@ $if linux { #flag -L/usr/lib/gcc/x86_64-linux-gnu/10 #flag -L/usr/lib/gcc/x86_64-linux-gnu/11 #flag -L/usr/lib/gcc/x86_64-linux-gnu/12 - } $else $if aarch64 { + } $else $if arm64 { #flag -L/usr/lib/gcc/aarch64-linux-gnu/6 #flag -L/usr/lib/gcc/aarch64-linux-gnu/7 #flag -L/usr/lib/gcc/aarch64-linux-gnu/8 diff --git a/vlib/sync/channels.v b/vlib/sync/channels.v index 559acb7c89..7fc11b5d5d 100644 --- a/vlib/sync/channels.v +++ b/vlib/sync/channels.v @@ -20,7 +20,7 @@ $if linux { #flag -L/usr/lib/gcc/x86_64-linux-gnu/10 #flag -L/usr/lib/gcc/x86_64-linux-gnu/11 #flag -L/usr/lib/gcc/x86_64-linux-gnu/12 - } $else $if aarch64 { + } $else $if arm64 { #flag -L/usr/lib/gcc/aarch64-linux-gnu/6 #flag -L/usr/lib/gcc/aarch64-linux-gnu/7 #flag -L/usr/lib/gcc/aarch64-linux-gnu/8 diff --git a/vlib/v/builder/native.v b/vlib/v/builder/native.v index d7d23d705c..c2176bee3c 100644 --- a/vlib/v/builder/native.v +++ b/vlib/v/builder/native.v @@ -17,9 +17,6 @@ pub fn (mut b Builder) build_native(v_files []string, out_file string) { pub fn (mut b Builder) compile_native() { // v.files << v.v_files_from_dir(os.join_path(v.pref.vlib_path,'builtin','bare')) files := [b.pref.path] - if b.pref.arch == ._auto { - b.pref.arch = pref.get_host_arch() - } b.set_module_lookup_paths() b.build_native(files, b.pref.out_name) } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 85b728d0b9..d2b46412c7 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -24,9 +24,8 @@ const ( 'haiku', ] valid_comp_if_compilers = ['gcc', 'tinyc', 'clang', 'mingw', 'msvc', 'cplusplus'] - valid_comp_if_platforms = ['amd64', 'aarch64', 'arm64', 'x64', 'x32', 'little_endian', - 'big_endian', - ] + valid_comp_if_platforms = ['amd64', 'i386', 'aarch64', 'arm64', 'arm32', 'rv64', 'rv32'] + valid_comp_if_cpu_features = ['x64', 'x32', 'little_endian', 'big_endian'] valid_comp_if_other = ['js', 'debug', 'prod', 'test', 'glibc', 'prealloc', 'no_bounds_checking', 'freestanding', 'threads'] array_builtin_methods = ['filter', 'clone', 'repeat', 'reverse', 'map', 'slice', 'sort', @@ -6201,15 +6200,29 @@ fn (mut c Checker) comp_if_branch(cond ast.Expr, pos token.Position) bool { } } ast.Ident { - if cond.name in checker.valid_comp_if_os { - return cond.name != c.pref.os.str().to_lower() // TODO hack - } else if cond.name in checker.valid_comp_if_compilers { - return pref.cc_from_string(cond.name) != c.pref.ccompiler_type - } else if cond.name in checker.valid_comp_if_platforms { - return false // TODO - } else if cond.name in checker.valid_comp_if_other { - // TODO: This should probably be moved - match cond.name { + cname := cond.name + if cname in checker.valid_comp_if_os { + return cname != c.pref.os.str().to_lower() + } else if cname in checker.valid_comp_if_compilers { + return pref.cc_from_string(cname) != c.pref.ccompiler_type + } else if cname in checker.valid_comp_if_platforms { + if cname == 'aarch64' { + c.note('use `arm64` instead of `aarch64`', pos) + } + match cname { + 'amd64' { return c.pref.arch != .amd64 } + 'i386' { return c.pref.arch != .i386 } + 'aarch64' { return c.pref.arch != .arm64 } + 'arm64' { return c.pref.arch != .arm64 } + 'arm32' { return c.pref.arch != .arm32 } + 'rv64' { return c.pref.arch != .rv64 } + 'rv32' { return c.pref.arch != .rv32 } + else { return false } + } + } else if cname in checker.valid_comp_if_cpu_features { + return false + } else if cname in checker.valid_comp_if_other { + match cname { 'js' { return c.pref.backend != .js } 'debug' { return !c.pref.is_debug } 'prod' { return !c.pref.is_prod } @@ -6217,12 +6230,12 @@ fn (mut c Checker) comp_if_branch(cond ast.Expr, pos token.Position) bool { 'glibc' { return false } // TODO 'threads' { return c.table.gostmts == 0 } 'prealloc' { return !c.pref.prealloc } - 'no_bounds_checking' { return cond.name !in c.pref.compile_defines_all } + 'no_bounds_checking' { return cname !in c.pref.compile_defines_all } 'freestanding' { return !c.pref.is_bare || c.pref.output_cross_c } else { return false } } - } else if cond.name !in c.pref.compile_defines_all { - if cond.name == 'linux_or_macos' { + } else if cname !in c.pref.compile_defines_all { + if cname == 'linux_or_macos' { c.error('linux_or_macos is deprecated, use `\$if linux || macos {` instead', cond.pos) return false @@ -6231,7 +6244,7 @@ fn (mut c Checker) comp_if_branch(cond ast.Expr, pos token.Position) bool { typ := c.expr(cond) if cond.obj !is ast.Var && cond.obj !is ast.ConstField && cond.obj !is ast.GlobalField { - c.error('unknown var: `$cond.name`', pos) + c.error('unknown var: `$cname`', pos) return false } expr := c.find_obj_definition(cond.obj) or { diff --git a/vlib/v/gen/native/gen.v b/vlib/v/gen/native/gen.v index e280c33f05..d8e75f863e 100644 --- a/vlib/v/gen/native/gen.v +++ b/vlib/v/gen/native/gen.v @@ -244,6 +244,7 @@ pub fn (mut g Gen) gen_print_from_expr(expr ast.Expr, newline bool) { g.gen_print_reg(.rax, 3) } else { + dump(typeof(expr).name) dump(expr) verror('expected string as argument for print') } @@ -336,10 +337,7 @@ fn (mut g Gen) stmt(node ast.Stmt) { g.write8(b) } } - ast.Module { - eprintln('module') - dump(node) - } + ast.Module {} ast.Return { // dump(node.exprs[0]) // if in main diff --git a/vlib/v/gen/native/tests/native_test.v b/vlib/v/gen/native/tests/native_test.v index a1f67efd22..d4e938b997 100644 --- a/vlib/v/gen/native/tests/native_test.v +++ b/vlib/v/gen/native/tests/native_test.v @@ -6,10 +6,7 @@ const is_verbose = os.getenv('VTEST_SHOW_CMD') != '' // TODO some logic copy pasted from valgrind_test.v and compiler_test.v, move to a module fn test_native() { - $if !amd64 { - return - } - $if aarch64 { + $if arm64 { return } // some tests are running fine in macos diff --git a/vlib/v/pref/default.v b/vlib/v/pref/default.v index 024914af97..2862c574bd 100644 --- a/vlib/v/pref/default.v +++ b/vlib/v/pref/default.v @@ -37,6 +37,9 @@ fn (mut p Preferences) expand_lookup_paths() { } pub fn (mut p Preferences) fill_with_defaults() { + if p.arch == ._auto { + p.arch = get_host_arch() + } p.expand_lookup_paths() rpath := os.real_path(p.path) if p.out_name == '' { diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 1ce329a4f3..f73c1479fa 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -590,6 +590,7 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences if res.is_debug { parse_define(mut res, 'debug') } + // res.use_cache = true if command != 'doc' && res.out_name.ends_with('.v') { eprintln('Cannot save output binary in a .v file.')