From 8c7bcad6b1761875dc1d5bc9e5b827273a9ebc62 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Thu, 20 Aug 2020 15:28:31 +0300 Subject: [PATCH] cgen: support for `$if amd64 {}` and `$if aarch64 {}` --- vlib/v/gen/cgen.v | 9 +++++++++ vlib/v/gen/cheaders.v | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index f3b59fe7ae..647b35b16d 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -4355,12 +4355,21 @@ fn (mut g Gen) comp_if_to_ifdef(name string, is_comptime_optional bool) string { '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' } diff --git a/vlib/v/gen/cheaders.v b/vlib/v/gen/cheaders.v index 2fc0735947..ec31f8433b 100644 --- a/vlib/v/gen/cheaders.v +++ b/vlib/v/gen/cheaders.v @@ -28,6 +28,13 @@ const ( #define __NOINLINE __attribute__((noinline)) #define __IRQHANDLER __attribute__((interrupt)) +#if defined(__x86_64__) +#define __V_amd64 1 +#endif +#if defined(__aarch64__) || defined(__arm64__) +#define __V_aarch64 1 +#endif + // Using just __GNUC__ for detecting gcc, is not reliable because other compilers define it too: #ifdef __GNUC__ #define __V_GCC__