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/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

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/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

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() {
// 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)
}

View File

@ -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 {

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)
}
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

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
fn test_native() {
$if !amd64 {
return
}
$if aarch64 {
$if arm64 {
return
}
// 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() {
if p.arch == ._auto {
p.arch = get_host_arch()
}
p.expand_lookup_paths()
rpath := os.real_path(p.path)
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 {
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.')