Skip to content

Commit 1b44a06

Browse files
author
Kevin Pyle
committed
Enable cross-version compiling
Rename GCC_VERSION to TARGET_GCC_VERSION in source files. Add a command line preprocessor definition setting TARGET_GCC_VERSION to the value of the file autogenerated-gcc-version, which contains the effective GCC_VERSION of TARGET_GCC.
1 parent ff96a71 commit 1b44a06

17 files changed

+51
-51
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ $(PLUGIN_DSO): $(PLUGIN_OBJECT_FILES) $(LIBGCC_C_API_SO)
169169
)
170170

171171
.PHONY: gcc-c-api/phony-stamp-gcc-api
172-
gcc-c-api/phony-stamp-gcc-api: autogenerated-EXTRA_CFLAGS.txt
172+
gcc-c-api/phony-stamp-gcc-api: autogenerated-EXTRA_CFLAGS.txt autogenerated-gcc-version
173173
$(MAKE) -C gcc-c-api libgcc-c-api.so CC="$(CC)" CXX="$(CXX)" TARGET_GCC="$(TARGET_GCC)"
174174

175175
$(LIBGCC_C_API_SO): gcc-c-api/phony-stamp-gcc-api
@@ -178,8 +178,8 @@ $(PLUGIN_OBJECT_GENERATED_FILES): CPPFLAGS+= $(if $(srcdir),-I$(srcdir))
178178

179179
# This is the standard .c->.o recipe, but it needs to be stated
180180
# explicitly to support the case that $(srcdir) is not blank.
181-
$(PLUGIN_OBJECT_SOURCE_FILES) $(PLUGIN_OBJECT_GENERATED_FILES): %.o: $(srcdir)%.c autogenerated-config.h $(srcdir)gcc-python.h $(LIBGCC_C_API_SO) autogenerated-EXTRA_CFLAGS.txt
182-
$(call run-cc,$< $(OUTPUT_OPTION),$(COMPILE.c),$(COMPILE.cpp))
181+
$(PLUGIN_OBJECT_SOURCE_FILES) $(PLUGIN_OBJECT_GENERATED_FILES): %.o: $(srcdir)%.c autogenerated-config.h $(srcdir)gcc-python.h $(LIBGCC_C_API_SO) autogenerated-EXTRA_CFLAGS.txt autogenerated-gcc-version
182+
read gcc_version < autogenerated-gcc-version || exit 1; $(call run-cc,-DTARGET_GCC_VERSION="$$gcc_version" $< $(OUTPUT_OPTION),$(COMPILE.c),$(COMPILE.cpp))
183183

184184
# Use a long variable name to avoid unwanted matches. Add an explicit
185185
# -x c since gcc requires a language specifier when processing stdin.

gcc-c-api/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ $(LIBGCC_C_API_SO): $(OBJECT_FILES)
104104

105105
# This is the standard .c->.o recipe, but it needs to be stated
106106
# explicitly to support the case that $(srcdir) is not blank.
107-
$(OBJECT_FILES): %.o: $(srcdir)%.c $(GENERATED_HEADERS) ../autogenerated-EXTRA_CFLAGS.txt
108-
$(call run-cc,$< $(OUTPUT_OPTION),$(COMPILE.c),$(COMPILE.cpp))
107+
$(OBJECT_FILES): %.o: $(srcdir)%.c $(GENERATED_HEADERS) ../autogenerated-EXTRA_CFLAGS.txt ../autogenerated-gcc-version
108+
read gcc_version < ../autogenerated-gcc-version || exit 1; $(call run-cc,-DTARGET_GCC_VERSION="$$gcc_version" $< $(OUTPUT_OPTION),$(COMPILE.c),$(COMPILE.cpp))
109109

110110
autogenerated-casts.c: $(SOURCE_XML) xmltypes.py generate-casts-c.py
111111
$(PYTHON) generate-casts-c.py $@

gcc-c-api/gcc-callgraph.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ GCC_PUBLIC_API (void) gcc_cgraph_node_mark_in_use (gcc_cgraph_node node)
3838
/* As of gcc 4.9, a cgraph_node inherits from symtab node and uses that
3939
struct's marking routine.
4040
*/
41-
#if (GCC_VERSION >= 4009)
41+
#if (TARGET_GCC_VERSION >= 4009)
4242
gt_ggc_mx_symtab_node (node.inner);
4343
#else
4444
gt_ggc_mx_cgraph_node (node.inner);
@@ -58,11 +58,11 @@ gcc_cgraph_node_get_decl (gcc_cgraph_node node)
5858
*/
5959
tree decl;
6060

61-
#if (GCC_VERSION >= 4009)
61+
#if (TARGET_GCC_VERSION >= 4009)
6262
/* Access decl field of parent class, symtab_node */
6363
decl = node.inner->decl;
6464
#else
65-
# if (GCC_VERSION >= 4008)
65+
# if (TARGET_GCC_VERSION >= 4008)
6666
decl = node.inner->symbol.decl;
6767
# else
6868
decl = node.inner->decl;
@@ -153,7 +153,7 @@ gcc_for_each_cgraph_node (bool (*cb) (gcc_cgraph_node node, void *user_data),
153153
gcc 4.8 eliminated: extern GTY(()) struct cgraph_node *cgraph_nodes;
154154
FIXME: does this only visit *defined* functions then?
155155
*/
156-
#if (GCC_VERSION >= 4008)
156+
#if (TARGET_GCC_VERSION >= 4008)
157157
FOR_EACH_DEFINED_FUNCTION(node)
158158
#else
159159
for (node = cgraph_nodes; node; node = node->next)

gcc-c-api/gcc-cfg.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "function.h"
2424
#include "basic-block.h"
2525

26-
#if (GCC_VERSION >= 4009)
26+
#if (TARGET_GCC_VERSION >= 4009)
2727
#include "tree-ssa-alias.h" /* needed by gimple.h in 4.9 */
2828
#include "internal-fn.h" /* needed by gimple.h in 4.9 */
2929
#include "is-a.h" /* needed by gimple.h in 4.9 */
@@ -33,7 +33,7 @@
3333
#include "gimple.h"
3434

3535
/* gcc 4.9 moved gimple_stmt_iterator into this header */
36-
#if (GCC_VERSION >= 4009)
36+
#if (TARGET_GCC_VERSION >= 4009)
3737
#include "gimple-iterator.h"
3838
#endif
3939

@@ -118,7 +118,7 @@ gcc_cfg_block_get_index (gcc_cfg_block block)
118118

119119
static bool
120120
for_each_edge (
121-
#if (GCC_VERSION >= 4008)
121+
#if (TARGET_GCC_VERSION >= 4008)
122122
vec<edge, va_gc> *vec_edges,
123123
#else
124124
VEC (edge, gc) * vec_edges,
@@ -174,7 +174,7 @@ checked_get_gimple_info(gcc_cfg_block block)
174174
return NULL;
175175
}
176176

177-
#if (GCC_VERSION >= 4008)
177+
#if (TARGET_GCC_VERSION >= 4008)
178178
return &block.inner->il.gimple;
179179
#else
180180
return block.inner->il.gimple;

gcc-c-api/gcc-gimple.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "tree.h"
2525
#include "function.h"
2626
#include "basic-block.h"
27-
#if (GCC_VERSION >= 4009)
27+
#if (TARGET_GCC_VERSION >= 4009)
2828
//#include "alias.h" /* needed by tree-ssa-alias.h in 4.9 */
2929
#include "tree-ssa-alias.h" /* needed by gimple.h in 4.9 */
3030
#include "internal-fn.h" /* needed by gimple.h in 4.9 */
@@ -52,7 +52,7 @@ GCC_IMPLEMENT_PUBLIC_API (void) gcc_gimple_mark_in_use (gcc_gimple stmt)
5252
/* Mark the underlying object (recursing into its fields): */
5353

5454
/* GCC 4.9 converted gimple to a class hierarchy */
55-
#if (GCC_VERSION >= 4009)
55+
#if (TARGET_GCC_VERSION >= 4009)
5656
gt_ggc_mx_gimple_statement_base (stmt.inner);
5757
#else
5858
gt_ggc_mx_gimple_statement_d (stmt.inner);

gcc-c-api/gcc-private-compat.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*************************************************************************/
2828

2929
/* Getting the length of a vector, returning 0 if it is NULL: */
30-
#if (GCC_VERSION >= 4008)
30+
#if (TARGET_GCC_VERSION >= 4008)
3131
#define GCC_COMPAT_VEC_LENGTH(KIND, V) \
3232
( (V) ? ( (V)->length() ) : 0 )
3333
#else
@@ -36,7 +36,7 @@
3636
#endif
3737

3838
/* Looking up an element by index: */
39-
#if (GCC_VERSION >= 4008)
39+
#if (TARGET_GCC_VERSION >= 4008)
4040
#define GCC_COMPAT_VEC_INDEX(KIND, V, IDX) \
4141
( (*(V))[IDX] )
4242
#else
@@ -46,7 +46,7 @@
4646

4747
/* Iterating over every element in a vector, or not at all if it is
4848
NULL: */
49-
#if (GCC_VERSION >= 4008)
49+
#if (TARGET_GCC_VERSION >= 4008)
5050
#define GCC_COMPAT_FOR_EACH_VEC_ELT(KIND, V, IDX_VAR, ITEM_VAR) \
5151
if ( (V) != NULL ) \
5252
FOR_EACH_VEC_ELT ( (*V), (IDX_VAR), (ITEM_VAR) )

gcc-c-api/gcc-variable.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ GCC_IMPLEMENT_PUBLIC_API (void) gcc_variable_mark_in_use (gcc_variable var)
4040
/* In GCC 4.8, struct varpool_node became part of union symtab_node_def, and
4141
In GCC 4.9, union symtab_node_def became class symtab_node.
4242
*/
43-
#if (GCC_VERSION >= 4009)
43+
#if (TARGET_GCC_VERSION >= 4009)
4444
gt_ggc_mx_symtab_node (var.inner);
4545
#else
46-
# if (GCC_VERSION >= 4008)
46+
# if (TARGET_GCC_VERSION >= 4008)
4747
gt_ggc_mx_symtab_node_def (var.inner);
4848
# else
4949
gt_ggc_mx_varpool_node (var.inner);
@@ -63,11 +63,11 @@ GCC_IMPLEMENT_PUBLIC_API (gcc_tree) gcc_variable_get_decl (gcc_variable var)
6363
*/
6464
tree decl;
6565

66-
#if (GCC_VERSION >= 4009)
66+
#if (TARGET_GCC_VERSION >= 4009)
6767
/* Get from base class */
6868
decl = var.inner->decl;
6969
#else
70-
# if (GCC_VERSION >= 4008)
70+
# if (TARGET_GCC_VERSION >= 4008)
7171
decl = var.inner->symbol.decl;
7272
# else
7373
decl = var.inner->decl;

gcc-python-attribute.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include "diagnostic.h"
2626
#include "plugin.h"
2727

28-
#if (GCC_VERSION >= 4009)
28+
#if (TARGET_GCC_VERSION >= 4009)
2929
/* GCC 4.9 moved debug_tree here: */
3030
#include "print-tree.h"
3131
#endif

gcc-python-cfg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ PyGccCfg_get_block_for_label(PyObject *s, PyObject *args)
432432
if (uid < 0 ||
433433
(
434434
(
435-
#if (GCC_VERSION >= 4008)
435+
#if (TARGET_GCC_VERSION >= 4008)
436436
vec_safe_length(self->cfg.inner->x_label_to_block_map)
437437
#else
438438
VEC_length (basic_block, self->cfg.inner->x_label_to_block_map)

gcc-python-gimple.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
/* gimple_phi_arg_def etc were in tree-flow-inline.h prior to 4.9, when they
2828
moved to gimple.h */
29-
#if (GCC_VERSION < 4009)
29+
#if (TARGET_GCC_VERSION < 4009)
3030
#include "tree-flow.h"
3131
#include "tree-flow-inline.h"
3232
#endif
@@ -35,15 +35,15 @@
3535
Needed for pp_gimple_stmt_1 for gcc 4.8+;
3636
this header didn't exist in gcc 4.6:
3737
*/
38-
#if (GCC_VERSION >= 4008)
38+
#if (TARGET_GCC_VERSION >= 4008)
3939
#include "gimple-pretty-print.h"
4040
#endif
4141

4242
#include "gcc-c-api/gcc-gimple.h"
4343

4444
/* GCC 4.9 moved struct walk_stmt_info into the new header gimple-walk.h,
4545
which in turn needs the new header gimple-iterator.h: */
46-
#if (GCC_VERSION >= 4009)
46+
#if (TARGET_GCC_VERSION >= 4009)
4747
#include "gimple-iterator.h"
4848
#include "gimple-walk.h"
4949
#endif
@@ -109,7 +109,7 @@ do_pretty_print(struct PyGccGimple * self, int spc, int flags)
109109
gcc 4.8 renamed "dump_gimple_stmt" to "pp_gimple_stmt_1"
110110
(in r191884). Declaration is in gimple-pretty-print.h
111111
*/
112-
#if (GCC_VERSION >= 4008)
112+
#if (TARGET_GCC_VERSION >= 4008)
113113
pp_gimple_stmt_1(PyGccPrettyPrinter_as_pp(ppobj),
114114
self->stmt.inner,
115115
spc, flags);

gcc-python-option.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ PyGccOption_repr(PyGccOption * self)
8686
#define warn_format global_options.x_warn_format
8787
*/
8888

89-
#if (GCC_VERSION < 4008)
89+
#if (TARGET_GCC_VERSION < 4008)
9090
/*
9191
Weakly import warn_format; it's not available in lto1
9292
(during link-time optimization)
@@ -135,7 +135,7 @@ int PyGcc_option_is_enabled(enum opt_code opt_code)
135135
/* We don't know: */
136136
return -1;
137137

138-
#if (GCC_VERSION >= 4008)
138+
#if (TARGET_GCC_VERSION >= 4008)
139139
case OPT_Wformat_:
140140
#else
141141
case OPT_Wformat:

gcc-python-pass.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "diagnostic.h"
2424
#include "gcc-c-api/gcc-function.h"
2525
#include "gcc-c-api/gcc-location.h"
26-
#if (GCC_VERSION >= 4009)
26+
#if (TARGET_GCC_VERSION >= 4009)
2727
#include "context.h"
2828
#include "pass_manager.h"
2929
#endif
@@ -177,7 +177,7 @@ static unsigned int impl_execute(void)
177177
return 0;
178178
}
179179

180-
#if (GCC_VERSION >= 4009)
180+
#if (TARGET_GCC_VERSION >= 4009)
181181
/*
182182
GCC 4.9 converted passes to a C++ class hierarchy, with methods for gate
183183
and execute.
@@ -243,7 +243,7 @@ class PyGccSimpleIpaPass : public simple_ipa_opt_pass
243243
opt_pass *clone() {return this; }
244244
};
245245

246-
#endif /* #if (GCC_VERSION >= 4009) */
246+
#endif /* #if (TARGET_GCC_VERSION >= 4009) */
247247

248248
static int
249249
do_pass_init(PyObject *s, PyObject *args, PyObject *kwargs,
@@ -267,7 +267,7 @@ do_pass_init(PyObject *s, PyObject *args, PyObject *kwargs,
267267
return -1;
268268
}
269269

270-
#if (GCC_VERSION >= 4009)
270+
#if (TARGET_GCC_VERSION >= 4009)
271271
pass_data pass_data;
272272
memset(&pass_data, 0, sizeof(pass_data));
273273
pass_data.type = pass_type;
@@ -364,7 +364,7 @@ PyGccPass_repr(struct PyGccPass *self)
364364
self->pass->name);
365365
}
366366

367-
#if (GCC_VERSION >= 4009)
367+
#if (TARGET_GCC_VERSION >= 4009)
368368
static struct dump_file_info *
369369
get_dump_file_info(int phase)
370370
{
@@ -383,7 +383,7 @@ get_dump_file_info(int phase)
383383
static bool
384384
is_dump_enabled(struct opt_pass *pass)
385385
{
386-
#if (GCC_VERSION >= 4008)
386+
#if (TARGET_GCC_VERSION >= 4008)
387387
struct dump_file_info *dfi = get_dump_file_info(pass->static_pass_number);
388388
return dfi->pstate || dfi->alt_state;
389389
#else
@@ -398,7 +398,7 @@ PyGccPass_get_dump_enabled(struct PyGccPass *self, void *closure)
398398
}
399399

400400
/* In GCC 4.8, this field became "pstate" */
401-
#if (GCC_VERSION >= 4008)
401+
#if (TARGET_GCC_VERSION >= 4008)
402402
#define DFI_STATE(dfi) (dfi)->pstate
403403
#else
404404
#define DFI_STATE(dfi) (dfi)->state
@@ -454,7 +454,7 @@ PyGccPass_set_dump_enabled(struct PyGccPass *self, PyObject *value, void *closur
454454

455455
/* In GCC 4.9, passes moved from being globals to fields of the
456456
pass_manager. */
457-
#if (GCC_VERSION >= 4009)
457+
#if (TARGET_GCC_VERSION >= 4009)
458458
#define GET_PASS_LIST(PASS_NAME) (g->get_passes()->PASS_NAME)
459459
#else
460460
#define GET_PASS_LIST(PASS_NAME) (PASS_NAME)
@@ -486,7 +486,7 @@ PyGccPass_get_roots(PyObject *cls, PyObject *noargs)
486486
SET_PASS(2, all_regular_ipa_passes);
487487
/* all_late_ipa_passes appeared in r175336 */
488488
/* r204984 eliminated all_lto_gen_passes */
489-
#if (GCC_VERSION >= 4009)
489+
#if (TARGET_GCC_VERSION >= 4009)
490490
SET_PASS(3, all_late_ipa_passes);
491491
#else
492492
SET_PASS(3, all_lto_gen_passes);
@@ -552,7 +552,7 @@ PyGccPass_get_by_name(PyObject *cls, PyObject *args, PyObject *kwargs)
552552
SEARCH_WITHIN_LIST(all_regular_ipa_passes);
553553
/* all_late_ipa_passes appeared in r175336 */
554554
/* r204984 eliminated all_lto_gen_passes */
555-
#if (GCC_VERSION >= 4009)
555+
#if (TARGET_GCC_VERSION >= 4009)
556556
SEARCH_WITHIN_LIST(all_late_ipa_passes);
557557
#else
558558
SEARCH_WITHIN_LIST(all_lto_gen_passes);

gcc-python-pretty-printer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include <Python.h>
2121
#include "gcc-python.h"
2222
#include "gcc-python-wrappers.h"
23-
#if (GCC_VERSION >= 4009)
23+
#if (TARGET_GCC_VERSION >= 4009)
2424
/* Needed for placement new */
2525
#include <new>
2626
#endif
@@ -41,7 +41,7 @@ PyGccPrettyPrinter_New(void)
4141
obj->buf[0] = '\0';
4242
obj->file_ptr = fmemopen(obj->buf, sizeof(obj->buf), "w");
4343

44-
#if (GCC_VERSION >= 4009)
44+
#if (TARGET_GCC_VERSION >= 4009)
4545
/* GCC 4.9 eliminated pp_construct in favor of a C++ ctor.
4646
Use placement new to run it on obj->pp. */
4747
new ((void*)&obj->pp) pretty_printer(NULL, 0);

gcc-python-rtl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ PyObject *
2828
PyGccRtl_get_location(struct PyGccRtl *self, void *closure)
2929
{
3030
/* In gcc 4.8, INSN_LOCATOR was replaced by INSN_LOCATION (in r191494) */
31-
#if (GCC_VERSION >= 4008)
31+
#if (TARGET_GCC_VERSION >= 4008)
3232
return PyGccLocation_New(gcc_private_make_location(INSN_LOCATION(self->insn.inner)));
3333
#else
3434
int locator = INSN_LOCATOR (self->insn.inner);

gcc-python-tree.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828

2929
/* for op_symbol_code */
3030
/* Moved to tree-pretty-print.h in gcc 4.9: */
31-
#if (GCC_VERSION >= 4009)
31+
#if (TARGET_GCC_VERSION >= 4009)
3232
#include "tree-pretty-print.h"
3333
#else
3434
#include "tree-flow.h"
3535
#endif
3636

3737
/* "maybe_get_identifier" was moved from tree.h to stringpool.h in 4.9 */
38-
#if (GCC_VERSION >= 4009)
38+
#if (TARGET_GCC_VERSION >= 4009)
3939
#include "stringpool.h" /* for maybe_get_identifier */
4040
#endif
4141

@@ -1152,7 +1152,7 @@ gcc_tree_list_of_pairs_from_tree_list_chain(tree t)
11521152

11531153
PyObject *
11541154
VEC_tree_as_PyList(
1155-
#if (GCC_VERSION >= 4008)
1155+
#if (TARGET_GCC_VERSION >= 4008)
11561156
vec<tree, va_gc> *vec_nodes
11571157
#else
11581158
VEC(tree,gc) *vec_nodes

0 commit comments

Comments
 (0)