From f371803a325f7a1796424d3551881891e3478b90 Mon Sep 17 00:00:00 2001 From: zakuro Date: Thu, 11 Feb 2021 09:22:49 +0900 Subject: [PATCH] cgen: move comp_if_to_ifdef to comptime.v (#8668) --- vlib/v/gen/c/cgen.v | 128 ---------------------------------------- vlib/v/gen/c/comptime.v | 128 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 128 insertions(+), 128 deletions(-) diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 645a3ea879..ddd8029c02 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -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] fn c_name(name_ string) string { name := util.no_dots(name_) diff --git a/vlib/v/gen/c/comptime.v b/vlib/v/gen/c/comptime.v index f4d3820f3d..567960adb2 100644 --- a/vlib/v/gen/c/comptime.v +++ b/vlib/v/gen/c/comptime.v @@ -411,3 +411,131 @@ fn (mut g Gen) comp_for(node ast.CompFor) { } 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 +}