cgen: add support for `$if gcc {}` too
parent
fbb260159b
commit
0fb8074353
|
@ -4026,6 +4026,9 @@ fn (mut g Gen) comp_if_to_ifdef(name string, is_comptime_optional bool) string {
|
||||||
return '_VJS'
|
return '_VJS'
|
||||||
}
|
}
|
||||||
// compilers:
|
// compilers:
|
||||||
|
'gcc' {
|
||||||
|
return '__V_GCC__'
|
||||||
|
}
|
||||||
'tinyc' {
|
'tinyc' {
|
||||||
return '__TINYC__'
|
return '__TINYC__'
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,23 @@ const (
|
||||||
#define __NOINLINE __attribute__((noinline))
|
#define __NOINLINE __attribute__((noinline))
|
||||||
#define __IRQHANDLER __attribute__((interrupt))
|
#define __IRQHANDLER __attribute__((interrupt))
|
||||||
|
|
||||||
|
// Using just __GNUC__ for detecting gcc, is not reliable because other compilers define it too:
|
||||||
|
#ifdef __GNUC__
|
||||||
|
#define __V_GCC__
|
||||||
|
#endif
|
||||||
|
#ifdef __TINYC__
|
||||||
|
#undef __V_GCC__
|
||||||
|
#endif
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#undef __V_GCC__
|
||||||
|
#endif
|
||||||
|
#ifdef __clang__
|
||||||
|
#undef __V_GCC__
|
||||||
|
#endif
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#undef __V_GCC__
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __TINYC__
|
#ifdef __TINYC__
|
||||||
#undef EMPTY_STRUCT_DECLARATION
|
#undef EMPTY_STRUCT_DECLARATION
|
||||||
#undef EMPTY_STRUCT_INITIALIZATION
|
#undef EMPTY_STRUCT_INITIALIZATION
|
||||||
|
|
|
@ -225,19 +225,26 @@ fn (mut p Parser) comp_if() ast.Stmt {
|
||||||
name_pos := name_pos_start.extend(p.tok.position())
|
name_pos := name_pos_start.extend(p.tok.position())
|
||||||
//
|
//
|
||||||
mut stmts := []ast.Stmt{}
|
mut stmts := []ast.Stmt{}
|
||||||
mut skip := false
|
mut skip_os := false
|
||||||
|
mut skip_cc := false
|
||||||
if val in supported_platforms {
|
if val in supported_platforms {
|
||||||
os := os_from_string(val)
|
os := os_from_string(val)
|
||||||
if (!is_not && os != p.pref.os) || (is_not && os == p.pref.os) {
|
if (!is_not && os != p.pref.os) || (is_not && os == p.pref.os) {
|
||||||
skip = true
|
skip_os = true
|
||||||
}
|
}
|
||||||
} else if val in supported_ccompilers {
|
} else if val in supported_ccompilers {
|
||||||
cc := cc_from_string(val)
|
if p.pref.ccompiler.len == 2 && p.pref.ccompiler == 'cc' {
|
||||||
user_cc := cc_from_string(p.pref.ccompiler)
|
// we just do not know, so we can not skip:
|
||||||
if (!is_not && cc != user_cc) || (is_not && cc == user_cc) {
|
skip_cc = false
|
||||||
skip = true
|
}else {
|
||||||
|
cc := cc_from_string(val)
|
||||||
|
user_cc := cc_from_string(p.pref.ccompiler)
|
||||||
|
if (!is_not && cc != user_cc) || (is_not && cc == user_cc) {
|
||||||
|
skip_cc = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mut skip := skip_os || skip_cc
|
||||||
// `$if os {` or `$if compiler {` for a different target, skip everything inside
|
// `$if os {` or `$if compiler {` for a different target, skip everything inside
|
||||||
// to avoid compilation errors (like including <windows.h> or calling WinAPI fns
|
// to avoid compilation errors (like including <windows.h> or calling WinAPI fns
|
||||||
// on non-Windows systems)
|
// on non-Windows systems)
|
||||||
|
|
Loading…
Reference in New Issue