cgen: move comp_if_to_ifdef to comptime.v (#8668)
parent
de287c0add
commit
f371803a32
|
@ -5585,134 +5585,6 @@ fn op_to_fn_name(name string) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut g Gen) comp_if_to_ifdef(name string, is_comptime_optional bool) ?string {
|
|
||||||
match name {
|
|
||||||
// platforms/os-es:
|
|
||||||
'windows' {
|
|
||||||
return '_WIN32'
|
|
||||||
}
|
|
||||||
'ios' {
|
|
||||||
return '__TARGET_IOS__'
|
|
||||||
}
|
|
||||||
'macos' {
|
|
||||||
return '__APPLE__'
|
|
||||||
}
|
|
||||||
'mach' {
|
|
||||||
return '__MACH__'
|
|
||||||
}
|
|
||||||
'darwin' {
|
|
||||||
return '__DARWIN__'
|
|
||||||
}
|
|
||||||
'hpux' {
|
|
||||||
return '__HPUX__'
|
|
||||||
}
|
|
||||||
'gnu' {
|
|
||||||
return '__GNU__'
|
|
||||||
}
|
|
||||||
'qnx' {
|
|
||||||
return '__QNX__'
|
|
||||||
}
|
|
||||||
'linux' {
|
|
||||||
return '__linux__'
|
|
||||||
}
|
|
||||||
'freebsd' {
|
|
||||||
return '__FreeBSD__'
|
|
||||||
}
|
|
||||||
'openbsd' {
|
|
||||||
return '__OpenBSD__'
|
|
||||||
}
|
|
||||||
'netbsd' {
|
|
||||||
return '__NetBSD__'
|
|
||||||
}
|
|
||||||
'bsd' {
|
|
||||||
return '__BSD__'
|
|
||||||
}
|
|
||||||
'dragonfly' {
|
|
||||||
return '__DragonFly__'
|
|
||||||
}
|
|
||||||
'android' {
|
|
||||||
return '__ANDROID__'
|
|
||||||
}
|
|
||||||
'solaris' {
|
|
||||||
return '__sun'
|
|
||||||
}
|
|
||||||
'haiku' {
|
|
||||||
return '__haiku__'
|
|
||||||
}
|
|
||||||
'linux_or_macos' {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
//
|
|
||||||
'js' {
|
|
||||||
return '_VJS'
|
|
||||||
}
|
|
||||||
// compilers:
|
|
||||||
'gcc' {
|
|
||||||
return '__V_GCC__'
|
|
||||||
}
|
|
||||||
'tinyc' {
|
|
||||||
return '__TINYC__'
|
|
||||||
}
|
|
||||||
'clang' {
|
|
||||||
return '__clang__'
|
|
||||||
}
|
|
||||||
'mingw' {
|
|
||||||
return '__MINGW32__'
|
|
||||||
}
|
|
||||||
'msvc' {
|
|
||||||
return '_MSC_VER'
|
|
||||||
}
|
|
||||||
'cplusplus' {
|
|
||||||
return '__cplusplus'
|
|
||||||
}
|
|
||||||
// other:
|
|
||||||
'debug' {
|
|
||||||
return '_VDEBUG'
|
|
||||||
}
|
|
||||||
'test' {
|
|
||||||
return '_VTEST'
|
|
||||||
}
|
|
||||||
'glibc' {
|
|
||||||
return '__GLIBC__'
|
|
||||||
}
|
|
||||||
'prealloc' {
|
|
||||||
return '_VPREALLOC'
|
|
||||||
}
|
|
||||||
'no_bounds_checking' {
|
|
||||||
return 'CUSTOM_DEFINE_no_bounds_checking'
|
|
||||||
}
|
|
||||||
// architectures:
|
|
||||||
'amd64' {
|
|
||||||
return '__V_amd64'
|
|
||||||
}
|
|
||||||
'aarch64' {
|
|
||||||
return '__V_aarch64'
|
|
||||||
}
|
|
||||||
// bitness:
|
|
||||||
'x64' {
|
|
||||||
return 'TARGET_IS_64BIT'
|
|
||||||
}
|
|
||||||
'x32' {
|
|
||||||
return 'TARGET_IS_32BIT'
|
|
||||||
}
|
|
||||||
// endianness:
|
|
||||||
'little_endian' {
|
|
||||||
return 'TARGET_ORDER_IS_LITTLE'
|
|
||||||
}
|
|
||||||
'big_endian' {
|
|
||||||
return 'TARGET_ORDER_IS_BIG'
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if is_comptime_optional
|
|
||||||
|| (g.pref.compile_defines_all.len > 0 && name in g.pref.compile_defines_all) {
|
|
||||||
return 'CUSTOM_DEFINE_$name'
|
|
||||||
}
|
|
||||||
return error('bad os ifdef name "$name"') // should never happen, caught in the checker
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return none
|
|
||||||
}
|
|
||||||
|
|
||||||
[inline]
|
[inline]
|
||||||
fn c_name(name_ string) string {
|
fn c_name(name_ string) string {
|
||||||
name := util.no_dots(name_)
|
name := util.no_dots(name_)
|
||||||
|
|
|
@ -411,3 +411,131 @@ fn (mut g Gen) comp_for(node ast.CompFor) {
|
||||||
}
|
}
|
||||||
g.writeln('} // } comptime for')
|
g.writeln('} // } comptime for')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn (mut g Gen) comp_if_to_ifdef(name string, is_comptime_optional bool) ?string {
|
||||||
|
match name {
|
||||||
|
// platforms/os-es:
|
||||||
|
'windows' {
|
||||||
|
return '_WIN32'
|
||||||
|
}
|
||||||
|
'ios' {
|
||||||
|
return '__TARGET_IOS__'
|
||||||
|
}
|
||||||
|
'macos' {
|
||||||
|
return '__APPLE__'
|
||||||
|
}
|
||||||
|
'mach' {
|
||||||
|
return '__MACH__'
|
||||||
|
}
|
||||||
|
'darwin' {
|
||||||
|
return '__DARWIN__'
|
||||||
|
}
|
||||||
|
'hpux' {
|
||||||
|
return '__HPUX__'
|
||||||
|
}
|
||||||
|
'gnu' {
|
||||||
|
return '__GNU__'
|
||||||
|
}
|
||||||
|
'qnx' {
|
||||||
|
return '__QNX__'
|
||||||
|
}
|
||||||
|
'linux' {
|
||||||
|
return '__linux__'
|
||||||
|
}
|
||||||
|
'freebsd' {
|
||||||
|
return '__FreeBSD__'
|
||||||
|
}
|
||||||
|
'openbsd' {
|
||||||
|
return '__OpenBSD__'
|
||||||
|
}
|
||||||
|
'netbsd' {
|
||||||
|
return '__NetBSD__'
|
||||||
|
}
|
||||||
|
'bsd' {
|
||||||
|
return '__BSD__'
|
||||||
|
}
|
||||||
|
'dragonfly' {
|
||||||
|
return '__DragonFly__'
|
||||||
|
}
|
||||||
|
'android' {
|
||||||
|
return '__ANDROID__'
|
||||||
|
}
|
||||||
|
'solaris' {
|
||||||
|
return '__sun'
|
||||||
|
}
|
||||||
|
'haiku' {
|
||||||
|
return '__haiku__'
|
||||||
|
}
|
||||||
|
'linux_or_macos' {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
//
|
||||||
|
'js' {
|
||||||
|
return '_VJS'
|
||||||
|
}
|
||||||
|
// compilers:
|
||||||
|
'gcc' {
|
||||||
|
return '__V_GCC__'
|
||||||
|
}
|
||||||
|
'tinyc' {
|
||||||
|
return '__TINYC__'
|
||||||
|
}
|
||||||
|
'clang' {
|
||||||
|
return '__clang__'
|
||||||
|
}
|
||||||
|
'mingw' {
|
||||||
|
return '__MINGW32__'
|
||||||
|
}
|
||||||
|
'msvc' {
|
||||||
|
return '_MSC_VER'
|
||||||
|
}
|
||||||
|
'cplusplus' {
|
||||||
|
return '__cplusplus'
|
||||||
|
}
|
||||||
|
// other:
|
||||||
|
'debug' {
|
||||||
|
return '_VDEBUG'
|
||||||
|
}
|
||||||
|
'test' {
|
||||||
|
return '_VTEST'
|
||||||
|
}
|
||||||
|
'glibc' {
|
||||||
|
return '__GLIBC__'
|
||||||
|
}
|
||||||
|
'prealloc' {
|
||||||
|
return '_VPREALLOC'
|
||||||
|
}
|
||||||
|
'no_bounds_checking' {
|
||||||
|
return 'CUSTOM_DEFINE_no_bounds_checking'
|
||||||
|
}
|
||||||
|
// architectures:
|
||||||
|
'amd64' {
|
||||||
|
return '__V_amd64'
|
||||||
|
}
|
||||||
|
'aarch64' {
|
||||||
|
return '__V_aarch64'
|
||||||
|
}
|
||||||
|
// bitness:
|
||||||
|
'x64' {
|
||||||
|
return 'TARGET_IS_64BIT'
|
||||||
|
}
|
||||||
|
'x32' {
|
||||||
|
return 'TARGET_IS_32BIT'
|
||||||
|
}
|
||||||
|
// endianness:
|
||||||
|
'little_endian' {
|
||||||
|
return 'TARGET_ORDER_IS_LITTLE'
|
||||||
|
}
|
||||||
|
'big_endian' {
|
||||||
|
return 'TARGET_ORDER_IS_BIG'
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if is_comptime_optional
|
||||||
|
|| (g.pref.compile_defines_all.len > 0 && name in g.pref.compile_defines_all) {
|
||||||
|
return 'CUSTOM_DEFINE_$name'
|
||||||
|
}
|
||||||
|
return error('bad os ifdef name "$name"') // should never happen, caught in the checker
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return none
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue