v: fix passing `-arch arm64` to `$if arm64{}`

pull/10444/head
Delyan Angelov 2021-06-13 00:45:17 +03:00
parent 5870751769
commit 2ff0f62866
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
8 changed files with 38 additions and 29 deletions

View File

@ -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/10
#flag -L/usr/lib/gcc/x86_64-linux-gnu/11 #flag -L/usr/lib/gcc/x86_64-linux-gnu/11
#flag -L/usr/lib/gcc/x86_64-linux-gnu/12 #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/6
#flag -L/usr/lib/gcc/aarch64-linux-gnu/7 #flag -L/usr/lib/gcc/aarch64-linux-gnu/7
#flag -L/usr/lib/gcc/aarch64-linux-gnu/8 #flag -L/usr/lib/gcc/aarch64-linux-gnu/8

View File

@ -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/10
#flag -L/usr/lib/gcc/x86_64-linux-gnu/11 #flag -L/usr/lib/gcc/x86_64-linux-gnu/11
#flag -L/usr/lib/gcc/x86_64-linux-gnu/12 #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/6
#flag -L/usr/lib/gcc/aarch64-linux-gnu/7 #flag -L/usr/lib/gcc/aarch64-linux-gnu/7
#flag -L/usr/lib/gcc/aarch64-linux-gnu/8 #flag -L/usr/lib/gcc/aarch64-linux-gnu/8

View File

@ -17,9 +17,6 @@ pub fn (mut b Builder) build_native(v_files []string, out_file string) {
pub fn (mut b Builder) compile_native() { pub fn (mut b Builder) compile_native() {
// v.files << v.v_files_from_dir(os.join_path(v.pref.vlib_path,'builtin','bare')) // v.files << v.v_files_from_dir(os.join_path(v.pref.vlib_path,'builtin','bare'))
files := [b.pref.path] files := [b.pref.path]
if b.pref.arch == ._auto {
b.pref.arch = pref.get_host_arch()
}
b.set_module_lookup_paths() b.set_module_lookup_paths()
b.build_native(files, b.pref.out_name) b.build_native(files, b.pref.out_name)
} }

View File

@ -24,9 +24,8 @@ const (
'haiku', 'haiku',
] ]
valid_comp_if_compilers = ['gcc', 'tinyc', 'clang', 'mingw', 'msvc', 'cplusplus'] valid_comp_if_compilers = ['gcc', 'tinyc', 'clang', 'mingw', 'msvc', 'cplusplus']
valid_comp_if_platforms = ['amd64', 'aarch64', 'arm64', 'x64', 'x32', 'little_endian', valid_comp_if_platforms = ['amd64', 'i386', 'aarch64', 'arm64', 'arm32', 'rv64', 'rv32']
'big_endian', valid_comp_if_cpu_features = ['x64', 'x32', 'little_endian', 'big_endian']
]
valid_comp_if_other = ['js', 'debug', 'prod', 'test', 'glibc', 'prealloc', valid_comp_if_other = ['js', 'debug', 'prod', 'test', 'glibc', 'prealloc',
'no_bounds_checking', 'freestanding', 'threads'] 'no_bounds_checking', 'freestanding', 'threads']
array_builtin_methods = ['filter', 'clone', 'repeat', 'reverse', 'map', 'slice', 'sort', 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 { ast.Ident {
if cond.name in checker.valid_comp_if_os { cname := cond.name
return cond.name != c.pref.os.str().to_lower() // TODO hack if cname in checker.valid_comp_if_os {
} else if cond.name in checker.valid_comp_if_compilers { return cname != c.pref.os.str().to_lower()
return pref.cc_from_string(cond.name) != c.pref.ccompiler_type } else if cname in checker.valid_comp_if_compilers {
} else if cond.name in checker.valid_comp_if_platforms { return pref.cc_from_string(cname) != c.pref.ccompiler_type
return false // TODO } else if cname in checker.valid_comp_if_platforms {
} else if cond.name in checker.valid_comp_if_other { if cname == 'aarch64' {
// TODO: This should probably be moved c.note('use `arm64` instead of `aarch64`', pos)
match cond.name { }
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 } 'js' { return c.pref.backend != .js }
'debug' { return !c.pref.is_debug } 'debug' { return !c.pref.is_debug }
'prod' { return !c.pref.is_prod } '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 'glibc' { return false } // TODO
'threads' { return c.table.gostmts == 0 } 'threads' { return c.table.gostmts == 0 }
'prealloc' { return !c.pref.prealloc } '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 } 'freestanding' { return !c.pref.is_bare || c.pref.output_cross_c }
else { return false } else { return false }
} }
} else if cond.name !in c.pref.compile_defines_all { } else if cname !in c.pref.compile_defines_all {
if cond.name == 'linux_or_macos' { if cname == 'linux_or_macos' {
c.error('linux_or_macos is deprecated, use `\$if linux || macos {` instead', c.error('linux_or_macos is deprecated, use `\$if linux || macos {` instead',
cond.pos) cond.pos)
return false return false
@ -6231,7 +6244,7 @@ fn (mut c Checker) comp_if_branch(cond ast.Expr, pos token.Position) bool {
typ := c.expr(cond) typ := c.expr(cond)
if cond.obj !is ast.Var && cond.obj !is ast.ConstField if cond.obj !is ast.Var && cond.obj !is ast.ConstField
&& cond.obj !is ast.GlobalField { && cond.obj !is ast.GlobalField {
c.error('unknown var: `$cond.name`', pos) c.error('unknown var: `$cname`', pos)
return false return false
} }
expr := c.find_obj_definition(cond.obj) or { expr := c.find_obj_definition(cond.obj) or {

View File

@ -244,6 +244,7 @@ pub fn (mut g Gen) gen_print_from_expr(expr ast.Expr, newline bool) {
g.gen_print_reg(.rax, 3) g.gen_print_reg(.rax, 3)
} }
else { else {
dump(typeof(expr).name)
dump(expr) dump(expr)
verror('expected string as argument for print') verror('expected string as argument for print')
} }
@ -336,10 +337,7 @@ fn (mut g Gen) stmt(node ast.Stmt) {
g.write8(b) g.write8(b)
} }
} }
ast.Module { ast.Module {}
eprintln('module')
dump(node)
}
ast.Return { ast.Return {
// dump(node.exprs[0]) // dump(node.exprs[0])
// if in main // if in main

View File

@ -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 // TODO some logic copy pasted from valgrind_test.v and compiler_test.v, move to a module
fn test_native() { fn test_native() {
$if !amd64 { $if arm64 {
return
}
$if aarch64 {
return return
} }
// some tests are running fine in macos // some tests are running fine in macos

View File

@ -37,6 +37,9 @@ fn (mut p Preferences) expand_lookup_paths() {
} }
pub fn (mut p Preferences) fill_with_defaults() { pub fn (mut p Preferences) fill_with_defaults() {
if p.arch == ._auto {
p.arch = get_host_arch()
}
p.expand_lookup_paths() p.expand_lookup_paths()
rpath := os.real_path(p.path) rpath := os.real_path(p.path)
if p.out_name == '' { if p.out_name == '' {

View File

@ -590,6 +590,7 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences
if res.is_debug { if res.is_debug {
parse_define(mut res, 'debug') parse_define(mut res, 'debug')
} }
// res.use_cache = true // res.use_cache = true
if command != 'doc' && res.out_name.ends_with('.v') { if command != 'doc' && res.out_name.ends_with('.v') {
eprintln('Cannot save output binary in a .v file.') eprintln('Cannot save output binary in a .v file.')