Skip to content

Commit b6cb6bb

Browse files
Frederik Harwathdavidmalcolm
Frederik Harwath
authored andcommitted
Don't include "params.h" if building with GCC 10
The params.h header has been removed from GCC 10. To allow building the plugin for GCC 10, the header should be included conditionally for older GCC versions only.
1 parent 3a4b484 commit b6cb6bb

8 files changed

+60
-0
lines changed

gcc-c-api/gcc-cfg.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@
3737
#include "gimple-iterator.h"
3838
#endif
3939

40+
/* gcc 10 removed this header */
41+
#if (GCC_VERSION < 10000)
4042
#include "params.h"
43+
#endif
44+
4145
#include "tree.h"
4246
#include "diagnostic.h"
4347
#include "cgraph.h"

gcc-c-api/gcc-function.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@
2222

2323
/* TODO: rationalize these headers */
2424
#include "tree.h"
25+
26+
/* gcc 10 removed this header */
27+
#if (GCC_VERSION < 10000)
2528
#include "params.h"
29+
#endif
30+
2631
#include "tree.h"
2732
#include "function.h"
2833
#include "diagnostic.h"

gcc-c-api/gcc-gimple.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@
3535
#include "gimple.h"
3636

3737
#if 0
38+
39+
/* gcc 10 removed this header */
40+
#if (GCC_VERSION < 10000)
3841
#include "params.h"
42+
#endif
43+
3944
#include "cp/name-lookup.h" /* for global_namespace */
4045
#include "tree.h"
4146
#include "diagnostic.h"

gcc-python-option.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@ int PyGcc_option_is_enabled(enum opt_code opt_code)
9898
{
9999
/* Returns 1 if option OPT_IDX is enabled in OPTS, 0 if it is disabled,
100100
or -1 if it isn't a simple on-off switch. */
101+
#if (GCC_VERSION < 10000)
101102
int i = option_enabled (opt_code, global_dc->option_state);
103+
#else
104+
/* Starting with GCC 10, options can be distinguished by language. */
105+
/* TODO Expose the lang_mask to the user. */
106+
int i = option_enabled (opt_code, CL_LANG_ALL, global_dc->option_state);
107+
#endif
108+
102109
if (i == 1) {
103110
return 1;
104111
}

gcc-python-parameter.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@
1717
<http://www.gnu.org/licenses/>.
1818
*/
1919

20+
21+
2022
#include <Python.h>
2123
#include "gcc-python.h"
2224
#include "gcc-python-wrappers.h"
2325

26+
/* gcc 10 removed params.h */
27+
#if (GCC_VERSION < 10000)
28+
2429
/*
2530
Wrapper for GCC's params.h.
2631
We specifically wrap "compiler_param" (a typedef to an enum)
@@ -50,6 +55,8 @@ PyGcc_WrtpMarkForPyGccParameter(PyGccParameter *wrapper)
5055
/* empty */
5156
}
5257

58+
#endif
59+
5360
/*
5461
PEP-7
5562
Local variables:

gcc-python.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ PyGcc_get_option_dict(PyObject *self, PyObject *args)
225225
return dict;
226226
}
227227

228+
/* Function has been removed from GCC 10. */
229+
#if (GCC_VERSION < 10000)
228230
static PyObject *
229231
PyGcc_get_parameters(PyObject *self, PyObject *args)
230232
{
@@ -256,6 +258,7 @@ PyGcc_get_parameters(PyObject *self, PyObject *args)
256258
Py_XDECREF(dict);
257259
return NULL;
258260
}
261+
#endif
259262

260263
IMPL_APPENDER(add_var_to_list,
261264
gcc_variable,
@@ -452,9 +455,12 @@ static PyMethodDef GccMethods[] = {
452455
("Get all command-line options, as a dict from command-line text strings "
453456
"to gcc.Option instances")},
454457

458+
/* Function has been removed from GCC 10. */
459+
#if (GCC_VERSION < 10000)
455460
{"get_parameters", PyGcc_get_parameters, METH_NOARGS,
456461
"Get all tunable GCC parameters. Returns a dictionary, mapping from"
457462
"option name -> gcc.Parameter instance"},
463+
#endif
458464

459465
{"get_variables", PyGcc_get_variables, METH_NOARGS,
460466
"Get all variables in this compilation unit as a list of gcc.Variable"},
@@ -811,7 +817,9 @@ plugin_init (struct plugin_name_args *plugin_info,
811817
autogenerated_gimple_init_types(); /* FIXME: error checking! */
812818
autogenerated_location_init_types(); /* FIXME: error checking! */
813819
autogenerated_option_init_types(); /* FIXME: error checking! */
820+
#if (GCC_VERSION < 10000)
814821
autogenerated_parameter_init_types(); /* FIXME: error checking! */
822+
#endif
815823
autogenerated_pass_init_types(); /* FIXME: error checking! */
816824
autogenerated_pretty_printer_init_types(); /* FIXME: error checking! */
817825
autogenerated_rtl_init_types(); /* FIXME: error checking! */
@@ -826,7 +834,9 @@ plugin_init (struct plugin_name_args *plugin_info,
826834
autogenerated_gimple_add_types(PyGcc_globals.module);
827835
autogenerated_location_add_types(PyGcc_globals.module);
828836
autogenerated_option_add_types(PyGcc_globals.module);
837+
#if (GCC_VERSION < 10000)
829838
autogenerated_parameter_add_types(PyGcc_globals.module);
839+
#endif
830840
autogenerated_pass_add_types(PyGcc_globals.module);
831841
autogenerated_pretty_printer_add_types(PyGcc_globals.module);
832842
autogenerated_rtl_add_types(PyGcc_globals.module);

gcc-python.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@
3636
#endif
3737
#include "gimple.h"
3838

39+
40+
/* gcc 10 removed this header */
41+
#if (GCC_VERSION < 10000)
3942
#include "params.h"
43+
#endif
44+
4045
#endif
4146
#include "gcc-c-api/gcc-cfg.h"
4247

@@ -226,10 +231,13 @@ DECLARE_SIMPLE_WRAPPER(PyGccOption,
226231
option,
227232
gcc_option, opt)
228233

234+
/* gcc 10 removed params.h */
235+
#if (GCC_VERSION < 10000)
229236
DECLARE_SIMPLE_WRAPPER(PyGccParameter,
230237
PyGccParameter_TypeObj,
231238
param_num,
232239
compiler_param, param_num)
240+
#endif
233241

234242
DECLARE_SIMPLE_WRAPPER(PyGccRtl,
235243
PyGccRtl_TypeObj,
@@ -276,9 +284,12 @@ void autogenerated_location_add_types(PyObject *m);
276284
int autogenerated_option_init_types(void);
277285
void autogenerated_option_add_types(PyObject *m);
278286

287+
/* GCC 10 removed params.h */
288+
#if (GCC_VERSION < 10000)
279289
/* autogenerated-parameter.c */
280290
int autogenerated_parameter_init_types(void);
281291
void autogenerated_parameter_add_types(PyObject *m);
292+
#endif
282293

283294
/* autogenerated-pass.c */
284295
int autogenerated_pass_init_types(void);

generate-parameter-c.py

100644100755
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717

1818
from cpybuilder import *
1919
from wrapperbuilder import PyGccWrapperTypeObject
20+
import os, subprocess, sys
21+
22+
if not os.path.exists("./print-gcc-version"):
23+
sys.stderr.write("Build make target 'print-gcc-version' before running this script.")
24+
sys.exit(1)
25+
26+
gcc_version = int(subprocess.check_output("./print-gcc-version"))
27+
28+
if gcc_version >= 10000:
29+
print("/* GCC10 has removed params.h; no need for this wrapper. */")
30+
sys.exit(0)
2031

2132
cu = CompilationUnit()
2233
cu.add_include('gcc-python.h')

0 commit comments

Comments
 (0)