c++: CWG 2789 and reversed operator candidates
[official-gcc.git] / gcc / config / bpf / bpf-c.cc
blobf12f0627103606b130c73ba72bc0c546059205bb
1 /* BPF-specific code for C family languages.
2 Copyright (C) 2024 Free Software Foundation, Inc.
3 Contributed by Oracle Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #define IN_TARGET_CODE 1
23 #include "config.h"
24 #include "system.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "c-family/c-common.h"
28 #include "cpplib.h"
30 /* Define target-specific CPP macros. This function in used in the
31 definition of TARGET_CPU_CPP_BUILTINS in bpf.h */
33 #define builtin_define(TXT) cpp_define (pfile, TXT)
35 void
36 bpf_target_macros (cpp_reader *pfile)
38 builtin_define ("__BPF__");
39 builtin_define ("__bpf__");
41 if (TARGET_BIG_ENDIAN)
42 builtin_define ("__BPF_BIG_ENDIAN__");
43 else
44 builtin_define ("__BPF_LITTLE_ENDIAN__");
46 switch (bpf_isa)
48 case ISA_V1:
49 builtin_define_with_int_value ("__BPF_CPU_VERSION__", 1);
50 break;
51 case ISA_V2:
52 builtin_define_with_int_value ("__BPF_CPU_VERSION__", 2);
53 break;
54 case ISA_V3:
55 builtin_define_with_int_value ("__BPF_CPU_VERSION__", 3);
56 break;
57 case ISA_V4:
58 builtin_define_with_int_value ("__BPF_CPU_VERSION__", 4);
59 break;
60 default:
61 gcc_unreachable ();
62 break;
65 /* Different BPF CPU versions support different features. Some of
66 them can be enabled/disabled explicitly. */
67 if (bpf_has_alu32)
68 builtin_define ("__BPF_FEATURE_ALU32");
69 if (bpf_has_jmp32)
70 builtin_define ("__BPF_FEATURE_JMP32");
71 if (bpf_has_jmpext)
72 builtin_define ("__BPF_FEATURE_JMP_EXT");
73 if (bpf_has_bswap)
74 builtin_define ("__BPF_FEATURE_BSWAP");
75 if (bpf_has_sdiv)
76 builtin_define ("__BPF_FEATURE_SDIV_SMOD");
77 if (bpf_has_smov)
78 builtin_define ("__BPF_FEATURE_MOVSX");
80 /* Other CPU features can only be enabled/disabled generically by
81 selecting the corresponding CPU version. */
82 if (bpf_isa >= ISA_V4)
84 builtin_define ("__BPF_FEATURE_LDSX");
85 builtin_define ("__BPF_FEATURE_GOTOL");
86 builtin_define ("__BPF_FEATURE_ST");