Skip to content

Commit 979759a

Browse files
committed
add a "label" attribute to gcc.GimpleLabel
Commit f695cea updated gcc.GimpleLabel.__repr__ to lookup the object's "label" attribute, but this didn't actually exist, causing repr() of a gcc.GimpleLabel to raise an exception. Implement the missing attribute
1 parent 844618c commit 979759a

File tree

6 files changed

+49
-10
lines changed

6 files changed

+49
-10
lines changed

docs/gimple.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
.. Copyright 2011, 2012 David Malcolm <[email protected]>
2-
Copyright 2011, 2012 Red Hat, Inc.
1+
.. Copyright 2011, 2012, 2013 David Malcolm <[email protected]>
2+
Copyright 2011, 2012, 2013 Red Hat, Inc.
33
44
This is free software: you can redistribute it and/or modify it
55
under the terms of the GNU General Public License as published by
@@ -346,9 +346,10 @@ Subclass Meaning
346346

347347
Subclass of :py:class:`gcc.Gimple`, representing a "label" statement::
348348

349-
LABEL:
349+
.. py:attribute:: labels
350350

351-
.. FIXME: Label is a gcc.LabelDecl representing a jump target.
351+
The underlying :py:class:`gcc.LabelDecl` node representing this jump
352+
target
352353

353354
.. py:class:: gcc.GimpleAssign
354355

gcc-c-api/gcc-gimple.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
Copyright 2012 David Malcolm <[email protected]>
3-
Copyright 2012 Red Hat, Inc.
2+
Copyright 2012, 2013 David Malcolm <[email protected]>
3+
Copyright 2012, 2013 Red Hat, Inc.
44
55
This is free software: you can redistribute it and/or modify it
66
under the terms of the GNU General Public License as published by
@@ -18,6 +18,7 @@
1818
*/
1919

2020
#include "gcc-gimple.h"
21+
#include "gcc-tree.h"
2122
#include "gcc-internal.h"
2223

2324
//#include "tree.h"
@@ -252,6 +253,15 @@ gcc_gimple_switch_for_each_label (gcc_gimple_switch stmt,
252253
return false;
253254
}
254255

256+
/***************************************************************************
257+
gcc_gimple_label
258+
**************************************************************************/
259+
GCC_IMPLEMENT_PUBLIC_API(gcc_label_decl)
260+
gcc_gimple_label_get_label(gcc_gimple_label stmt)
261+
{
262+
return gcc_tree_as_gcc_label_decl (gcc_private_make_tree (gimple_label_label (stmt.inner)));
263+
}
264+
255265
/*
256266
Local variables:
257267
c-basic-offset: 2

gcc-c-api/gimple.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,11 @@
103103
<doc>The labels of the switch statement. The initial label in the list is always the default.</doc>
104104
</iterator>
105105
</type>
106+
107+
<type name="gimple_label" base="gimple">
108+
<attribute name="label" kind="label_decl">
109+
<doc>The underlying label_decl for this statement</doc>
110+
</attribute>
111+
</type>
106112

107113
</api>

gcc-python-gimple.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ PyGccGimple_as_gcc_gimple_switch(struct PyGccGimple *self)
7070
return gcc_gimple_as_gcc_gimple_switch(self->stmt);
7171
}
7272

73+
gcc_gimple_label
74+
PyGccGimple_as_gcc_gimple_label(struct PyGccGimple *self)
75+
{
76+
return gcc_gimple_as_gcc_gimple_label(self->stmt);
77+
}
78+
7379
static PyObject *
7480
do_pretty_print(struct PyGccGimple * self, int spc, int flags)
7581
{

gcc-python-wrappers.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
2-
Copyright 2011, 2012 David Malcolm <[email protected]>
3-
Copyright 2011, 2012 Red Hat, Inc.
2+
Copyright 2011, 2012, 2013 David Malcolm <[email protected]>
3+
Copyright 2011, 2012, 2013 Red Hat, Inc.
44
55
This is free software: you can redistribute it and/or modify it
66
under the terms of the GNU General Public License as published by
@@ -333,6 +333,9 @@ PyGccGimple_as_gcc_gimple_phi(struct PyGccGimple *self);
333333
extern gcc_gimple_switch
334334
PyGccGimple_as_gcc_gimple_switch(struct PyGccGimple *self);
335335

336+
extern gcc_gimple_label
337+
PyGccGimple_as_gcc_gimple_label(struct PyGccGimple *self);
338+
336339
PyObject *
337340
PyGccGimple_repr(struct PyGccGimple * self);
338341

generate-gimple-c.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Copyright 2011, 2012 David Malcolm <[email protected]>
2-
# Copyright 2011, 2012 Red Hat, Inc.
1+
# Copyright 2011, 2012, 2013 David Malcolm <[email protected]>
2+
# Copyright 2011, 2012, 2013 Red Hat, Inc.
33
#
44
# This is free software: you can redistribute it and/or modify it
55
# under the terms of the GNU General Public License as published by
@@ -26,6 +26,7 @@
2626
cu.add_include('gcc-plugin.h')
2727
cu.add_include("gimple.h")
2828
cu.add_include("gcc-c-api/gcc-gimple.h")
29+
cu.add_include("gcc-c-api/gcc-declaration.h")
2930

3031
modinit_preinit = ''
3132
modinit_postinit = ''
@@ -383,6 +384,17 @@ def make_getset_Switch():
383384
'Get a list of labels, as a list of gcc.CaseLabelExpr The initial label in the list is always the default.')
384385
return getsettable
385386

387+
def make_getset_Label():
388+
getsettable = PyGetSetDefTable('gcc_%s_getset_table' % cc,
389+
[exprcode_getter],
390+
'PyGccGimpleLabel',
391+
'PyGccGimple')
392+
getsettable.add_simple_getter(cu,
393+
'label',
394+
'PyGccTree_New(gcc_label_decl_as_gcc_tree(gcc_gimple_label_get_label(PyGccGimple_as_gcc_gimple_label(self))))',
395+
'Get the underlying gcc.LabelDecl for this statement')
396+
return getsettable
397+
386398
for gt in gimple_types:
387399
cc = gt.camel_cased_string()
388400

@@ -403,6 +415,7 @@ def make_getset_Switch():
403415
elif cc == 'GimpleSwitch':
404416
getsettable = make_getset_Switch()
405417
elif cc == 'GimpleLabel':
418+
getsettable = make_getset_Label()
406419
tp_repr = '(reprfunc)PyGccGimpleLabel_repr'
407420

408421
if getsettable:

0 commit comments

Comments
 (0)