[gcc-python-plugin/proposed-plugin-api] use gcc_integer_type_get_{max|min}_value
by David Hugh Malcolm
commit e62f95838a98b05cae8b0f4a67460ac96fc9c669
Author: David Malcolm <dmalcolm(a)redhat.com>
Date: Tue May 8 15:54:10 2012 -0400
use gcc_integer_type_get_{max|min}_value
generate-tree-c.py | 4 ++--
proposed-plugin-api/type.xml | 2 ++
2 files changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/generate-tree-c.py b/generate-tree-c.py
index 89d12c4..a16bc84 100644
--- a/generate-tree-c.py
+++ b/generate-tree-c.py
@@ -389,10 +389,10 @@ def generate_tree_code_classes():
'gcc_python_make_wrapper_tree(gcc_private_make_tree(c_common_unsigned_type(self->t.inner)))',
'The gcc.IntegerType for the unsigned version of this type')
add_simple_getter('max_value',
- 'gcc_python_make_wrapper_tree(gcc_private_make_tree(TYPE_MAX_VALUE(self->t.inner)))',
+ 'gcc_python_make_wrapper_tree(gcc_integer_constant_as_gcc_tree(gcc_integer_type_get_max_value(gcc_tree_as_gcc_integer_type(self->t))))',
'The maximum possible value for this type, as a gcc.IntegerCst')
add_simple_getter('min_value',
- 'gcc_python_make_wrapper_tree(gcc_private_make_tree(TYPE_MIN_VALUE(self->t.inner)))',
+ 'gcc_python_make_wrapper_tree(gcc_integer_constant_as_gcc_tree(gcc_integer_type_get_min_value(gcc_tree_as_gcc_integer_type(self->t))))',
'The minimum possible value for this type, as a gcc.IntegerCst')
if tree_type.SYM in ('INTEGER_TYPE', 'REAL_TYPE', 'FIXED_POINT_TYPE'):
diff --git a/proposed-plugin-api/type.xml b/proposed-plugin-api/type.xml
index 1b99320..7c34d37 100644
--- a/proposed-plugin-api/type.xml
+++ b/proposed-plugin-api/type.xml
@@ -61,6 +61,8 @@
</type>
<type name="integer_type" base="type">
+ <attribute name="max_value" kind="integer_constant"/>
+ <attribute name="min_value" kind="integer_constant"/>
</type>
<type name="lang_type" base="type">
12 years
[gcc-python-plugin/proposed-plugin-api] simplify casting
by David Hugh Malcolm
commit 40992b88e4af71d671b2faa3a9c0e16cd0c5e29e
Author: David Malcolm <dmalcolm(a)redhat.com>
Date: Tue May 8 15:53:33 2012 -0400
simplify casting
Makefile | 2 +
gcc-python-cfg.c | 2 +-
gcc-python.c | 2 +-
generate-callgraph-c.py | 4 +-
generate-function-c.py | 2 +-
generate-tree-c.py | 6 ++-
proposed-plugin-api/gcc-constant.c | 37 +++++++++++++++++++++
proposed-plugin-api/gcc-declaration.c | 29 ++--------------
proposed-plugin-api/gcc-gimple.c | 14 ++------
proposed-plugin-api/gcc-internal.h | 14 +-------
proposed-plugin-api/gcc-tree.c | 38 +++++++---------------
proposed-plugin-api/gcc-type.c | 57 +++++++++++++++++++++++++++++++++
proposed-plugin-api/xml-to-h.py | 11 +++---
proposed-plugin-api/xmltypes.py | 13 +++++++-
14 files changed, 144 insertions(+), 87 deletions(-)
---
diff --git a/Makefile b/Makefile
index c64ebf8..6b37c85 100644
--- a/Makefile
+++ b/Makefile
@@ -20,12 +20,14 @@
PLUGIN_SOURCE_FILES= \
proposed-plugin-api/gcc-callgraph.c \
proposed-plugin-api/gcc-cfg.c \
+ proposed-plugin-api/gcc-constant.c \
proposed-plugin-api/gcc-declaration.c \
proposed-plugin-api/gcc-function.c \
proposed-plugin-api/gcc-gimple.c \
proposed-plugin-api/gcc-location.c \
proposed-plugin-api/gcc-rtl.c \
proposed-plugin-api/gcc-tree.c \
+ proposed-plugin-api/gcc-type.c \
proposed-plugin-api/gcc-variable.c \
gcc-python.c \
gcc-python-attribute.c \
diff --git a/gcc-python-cfg.c b/gcc-python-cfg.c
index 5ef2507..7fafd0b 100644
--- a/gcc-python-cfg.c
+++ b/gcc-python-cfg.c
@@ -105,7 +105,7 @@ gcc_BasicBlock_get_gimple(PyGccBasicBlock *self, void *closure)
static PyObject*
gcc_python_make_wrapper_gimple_phi(gcc_gimple_phi phi)
{
- return gcc_python_make_wrapper_gimple(gcc_gimple_phi_upcast(phi));
+ return gcc_python_make_wrapper_gimple(gcc_gimple_phi_as_gcc_gimple(phi));
}
IMPL_APPENDER(append_gimple_phi_to_list,
diff --git a/gcc-python.c b/gcc-python.c
index b83e09a..711f6d3 100644
--- a/gcc-python.c
+++ b/gcc-python.c
@@ -256,7 +256,7 @@ gcc_python_maybe_get_identifier(PyObject *self, PyObject *args)
static PyObject *gcc_python_make_translation_unit_decl(gcc_translation_unit_decl decl)
{
- gcc_tree tree = gcc_decl_upcast(gcc_translation_unit_decl_upcast(decl));
+ gcc_tree tree = gcc_translation_unit_decl_as_gcc_tree(decl);
return gcc_python_make_wrapper_tree(tree);
}
diff --git a/generate-callgraph-c.py b/generate-callgraph-c.py
index 34631d7..41eb640 100644
--- a/generate-callgraph-c.py
+++ b/generate-callgraph-c.py
@@ -50,7 +50,7 @@ def generate_callgraph_edge():
'The function that is called here, as a gcc.CallgraphNode')
getsettable.add_simple_getter(cu,
'call_stmt',
- 'gcc_python_make_wrapper_gimple(gcc_gimple_call_upcast(gcc_cgraph_edge_get_call_stmt(self->edge)))',
+ 'gcc_python_make_wrapper_gimple(gcc_gimple_call_as_gcc_gimple(gcc_cgraph_edge_get_call_stmt(self->edge)))',
'The gcc.GimpleCall statememt for the function call')
cu.add_defn(getsettable.c_defn())
@@ -83,7 +83,7 @@ def generate_callgraph_node():
# FIXME: add getters
getsettable.add_simple_getter(cu,
'decl',
- 'gcc_python_make_wrapper_tree(gcc_decl_upcast(gcc_function_decl_upcast(gcc_cgraph_node_get_decl(self->node))))',
+ 'gcc_python_make_wrapper_tree(gcc_function_decl_as_gcc_tree(gcc_cgraph_node_get_decl(self->node)))',
'The gcc.FunctionDecl for this node')
getsettable.add_gsdef('callees',
'gcc_CallgraphNode_get_callees',
diff --git a/generate-function-c.py b/generate-function-c.py
index a1e700b..62b66af 100644
--- a/generate-function-c.py
+++ b/generate-function-c.py
@@ -51,7 +51,7 @@ def generate_function():
typename='PyGccFunction')
getsettable.add_simple_getter(cu,
'decl',
- 'gcc_python_make_wrapper_tree(gcc_decl_upcast(gcc_function_decl_upcast(gcc_function_get_decl(self->fun))))',
+ 'gcc_python_make_wrapper_tree(gcc_function_decl_as_gcc_tree(gcc_function_get_decl(self->fun)))',
'The declaration of this function, as a gcc.FunctionDecl instance')
getsettable.add_simple_getter(cu,
'local_decls',
diff --git a/generate-tree-c.py b/generate-tree-c.py
index eef673b..89d12c4 100644
--- a/generate-tree-c.py
+++ b/generate-tree-c.py
@@ -33,7 +33,9 @@ cu.add_include("function.h")
cu.add_include("basic-block.h")
cu.add_include("c-family/c-common.h")
cu.add_include("proposed-plugin-api/gcc-tree.h")
+cu.add_include("proposed-plugin-api/gcc-constant.h")
cu.add_include("proposed-plugin-api/gcc-declaration.h")
+cu.add_include("proposed-plugin-api/gcc-type.h")
modinit_preinit = ''
modinit_postinit = ''
@@ -465,10 +467,10 @@ def generate_tree_code_classes():
if tree_type.SYM == 'TRANSLATION_UNIT_DECL':
add_simple_getter('block',
- 'gcc_python_make_wrapper_tree(gcc_block_upcast(gcc_translation_unit_decl_get_block(gcc_decl_as_gcc_translation_unit_decl(gcc_tree_as_gcc_decl(self->t)))))',
+ 'gcc_python_make_wrapper_tree(gcc_block_as_gcc_tree(gcc_translation_unit_decl_get_block(gcc_tree_as_gcc_translation_unit_decl(self->t))))',
"The gcc.Block for this namespace")
add_simple_getter('language',
- 'gcc_python_string_from_string(gcc_translation_unit_decl_get_language(gcc_decl_as_gcc_translation_unit_decl(gcc_tree_as_gcc_decl(self->t))))',
+ 'gcc_python_string_from_string(gcc_translation_unit_decl_get_language(gcc_tree_as_gcc_translation_unit_decl(self->t)))',
"The source language of this translation unit, as a string")
if tree_type.SYM == 'BLOCK':
diff --git a/proposed-plugin-api/gcc-constant.c b/proposed-plugin-api/gcc-constant.c
new file mode 100644
index 0000000..870b803
--- /dev/null
+++ b/proposed-plugin-api/gcc-constant.c
@@ -0,0 +1,37 @@
+/*
+ Copyright 2012 David Malcolm <dmalcolm(a)redhat.com>
+ Copyright 2012 Red Hat, Inc.
+
+ This is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include "proposed-plugin-api/gcc-common.h"
+#include "proposed-plugin-api/gcc-constant.h"
+#include "proposed-plugin-api/gcc-internal.h"
+
+/* gcc_constant */
+IMPLEMENT_CAST(gcc_constant, gcc_tree)
+
+/* gcc_integer_constant */
+IMPLEMENT_CAST(gcc_integer_constant, gcc_constant)
+
+
+/*
+ PEP-7
+Local variables:
+c-basic-offset: 4
+indent-tabs-mode: nil
+End:
+*/
diff --git a/proposed-plugin-api/gcc-declaration.c b/proposed-plugin-api/gcc-declaration.c
index 489ddc9..874a32c 100644
--- a/proposed-plugin-api/gcc-declaration.c
+++ b/proposed-plugin-api/gcc-declaration.c
@@ -45,31 +45,10 @@ gcc_decl_get_location(gcc_decl decl)
return gcc_private_make_location(DECL_SOURCE_LOCATION(decl.inner));
}
-GCC_IMPLEMENT_PUBLIC_API(gcc_tree)
-gcc_decl_upcast(gcc_decl decl)
-{
- gcc_tree tree;
- tree.inner = decl.inner;
- return tree;
-}
-
-GCC_IMPLEMENT_PUBLIC_API(gcc_decl)
-gcc_function_decl_upcast(gcc_function_decl fndecl)
-{
- gcc_decl decl;
- decl.inner = fndecl.inner;
- return decl;
-}
-
-GCC_IMPLEMENT_PUBLIC_API(gcc_decl)
-gcc_translation_unit_decl_upcast(gcc_translation_unit_decl fndecl)
-{
- gcc_decl decl;
- decl.inner = fndecl.inner;
- return decl;
-}
-
-IMPLEMENT_DOWNCAST(gcc_decl, gcc_translation_unit_decl)
+IMPLEMENT_CAST(gcc_decl, gcc_tree)
+IMPLEMENT_CAST(gcc_function_decl, gcc_decl)
+IMPLEMENT_CAST(gcc_translation_unit_decl, gcc_decl)
+IMPLEMENT_CAST(gcc_decl, gcc_translation_unit_decl)
GCC_IMPLEMENT_PUBLIC_API(gcc_block)
gcc_translation_unit_decl_get_block(gcc_translation_unit_decl node)
diff --git a/proposed-plugin-api/gcc-gimple.c b/proposed-plugin-api/gcc-gimple.c
index f21fefd..352a94b 100644
--- a/proposed-plugin-api/gcc-gimple.c
+++ b/proposed-plugin-api/gcc-gimple.c
@@ -18,6 +18,7 @@
*/
#include "proposed-plugin-api/gcc-gimple.h"
+#include "proposed-plugin-api/gcc-internal.h"
//#include "tree.h"
#include "gimple.h"
@@ -76,17 +77,8 @@ gcc_gimple_get_location(gcc_gimple stmt)
return gcc_private_make_location(gimple_location(stmt.inner));
}
-GCC_IMPLEMENT_PUBLIC_API(gcc_gimple)
-gcc_gimple_phi_upcast(gcc_gimple_phi phi)
-{
- return gcc_private_make_gimple(phi.inner);
-}
-
-GCC_IMPLEMENT_PUBLIC_API(gcc_gimple)
-gcc_gimple_call_upcast(gcc_gimple_call call)
-{
- return gcc_private_make_gimple(call.inner);
-}
+IMPLEMENT_CAST(gcc_gimple_phi, gcc_gimple)
+IMPLEMENT_CAST(gcc_gimple_call, gcc_gimple)
/*
PEP-7
diff --git a/proposed-plugin-api/gcc-internal.h b/proposed-plugin-api/gcc-internal.h
index b55a2ab..63265fc 100644
--- a/proposed-plugin-api/gcc-internal.h
+++ b/proposed-plugin-api/gcc-internal.h
@@ -17,21 +17,11 @@
<http://www.gnu.org/licenses/>.
*/
-#define IMPLEMENT_DOWNCAST(T_INPUT, T_OUTPUT) \
+#define IMPLEMENT_CAST(T_INPUT, T_OUTPUT) \
GCC_IMPLEMENT_PUBLIC_API(T_OUTPUT) \
- T_INPUT ## _as_ ## T_OUTPUT(T_INPUT input) \
+ T_INPUT ## _as_ ## T_OUTPUT(T_INPUT input) \
{ \
T_OUTPUT output; \
output.inner = input.inner; \
return output; \
}
-
-#define IMPLEMENT_UPCAST(T_INPUT, T_OUTPUT) \
- GCC_IMPLEMENT_PUBLIC_API(T_OUTPUT) \
- T_INPUT ## _upcast(T_INPUT input) \
- { \
- T_OUTPUT output; \
- output.inner = input.inner; \
- return output; \
- }
-
diff --git a/proposed-plugin-api/gcc-tree.c b/proposed-plugin-api/gcc-tree.c
index bc8355e..c154c28 100644
--- a/proposed-plugin-api/gcc-tree.c
+++ b/proposed-plugin-api/gcc-tree.c
@@ -53,19 +53,22 @@ gcc_private_make_block(tree inner)
return result;
}
-IMPLEMENT_DOWNCAST(gcc_tree, gcc_constant)
-IMPLEMENT_DOWNCAST(gcc_tree, gcc_decl)
-IMPLEMENT_DOWNCAST(gcc_tree, gcc_binary)
-IMPLEMENT_DOWNCAST(gcc_tree, gcc_block)
-IMPLEMENT_DOWNCAST(gcc_tree, gcc_statement)
-IMPLEMENT_DOWNCAST(gcc_tree, gcc_type)
+IMPLEMENT_CAST(gcc_tree, gcc_constant)
+IMPLEMENT_CAST(gcc_tree, gcc_decl)
+IMPLEMENT_CAST(gcc_tree, gcc_binary)
+IMPLEMENT_CAST(gcc_tree, gcc_block)
+IMPLEMENT_CAST(gcc_tree, gcc_statement)
+IMPLEMENT_CAST(gcc_tree, gcc_type)
+IMPLEMENT_CAST(gcc_tree, gcc_integer_type)
+IMPLEMENT_CAST(gcc_tree, gcc_translation_unit_decl)
+IMPLEMENT_CAST(gcc_translation_unit_decl, gcc_tree)
+IMPLEMENT_CAST(gcc_integer_constant, gcc_tree)
+IMPLEMENT_CAST(gcc_function_decl, gcc_tree)
/* gcc_binary */
GCC_IMPLEMENT_PUBLIC_API(void)
gcc_binary_mark_in_use(gcc_binary node);
-GCC_IMPLEMENT_PUBLIC_API(gcc_tree)
-gcc_binary_upcast(gcc_binary node);
GCC_IMPLEMENT_PUBLIC_API(gcc_bitwise_and_expr)
gcc_binary_as_gcc_bitwise_and_expr(gcc_binary node);
@@ -80,39 +83,25 @@ gcc_binary_as_gcc_bitwise_xor_expr(gcc_binary node);
GCC_IMPLEMENT_PUBLIC_API(void)
gcc_bitwise_and_expr_mark_in_use(gcc_bitwise_and_expr node);
-GCC_IMPLEMENT_PUBLIC_API(gcc_binary)
-gcc_bitwise_and_expr_upcast(gcc_bitwise_and_expr node);
-
/* gcc_bitwise_ior_expr */
GCC_IMPLEMENT_PUBLIC_API(void)
gcc_bitwise_ior_expr_mark_in_use(gcc_bitwise_ior_expr node);
-GCC_IMPLEMENT_PUBLIC_API(gcc_binary)
-gcc_bitwise_ior_expr_upcast(gcc_bitwise_ior_expr node);
-
/* gcc_bitwise_xor_expr */
GCC_IMPLEMENT_PUBLIC_API(void)
gcc_bitwise_xor_expr_mark_in_use(gcc_bitwise_xor_expr node);
-GCC_IMPLEMENT_PUBLIC_API(gcc_binary)
-gcc_bitwise_xor_expr_upcast(gcc_bitwise_xor_expr node);
-
/* gcc_block */
GCC_IMPLEMENT_PUBLIC_API(void)
gcc_block_mark_in_use(gcc_block node);
-GCC_IMPLEMENT_PUBLIC_API(gcc_tree)
-gcc_block_upcast(gcc_block node);
-
-IMPLEMENT_UPCAST(gcc_block, gcc_tree)
+IMPLEMENT_CAST(gcc_block, gcc_tree)
/* gcc_statement */
GCC_IMPLEMENT_PUBLIC_API(void)
gcc_statement_mark_in_use(gcc_statement node);
-GCC_IMPLEMENT_PUBLIC_API(gcc_tree)
-gcc_statement_upcast(gcc_statement node);
GCC_IMPLEMENT_PUBLIC_API(gcc_case_label_expr)
gcc_statement_as_gcc_case_label_expr(gcc_statement node);
@@ -121,9 +110,6 @@ gcc_statement_as_gcc_case_label_expr(gcc_statement node);
GCC_IMPLEMENT_PUBLIC_API(void)
gcc_case_label_expr_mark_in_use(gcc_case_label_expr node);
-GCC_IMPLEMENT_PUBLIC_API(gcc_statement)
-gcc_case_label_expr_upcast(gcc_case_label_expr node);
-
/*
PEP-7
Local variables:
diff --git a/proposed-plugin-api/gcc-type.c b/proposed-plugin-api/gcc-type.c
new file mode 100644
index 0000000..d9a74f4
--- /dev/null
+++ b/proposed-plugin-api/gcc-type.c
@@ -0,0 +1,57 @@
+/*
+ Copyright 2012 David Malcolm <dmalcolm(a)redhat.com>
+ Copyright 2012 Red Hat, Inc.
+
+ This is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#include "proposed-plugin-api/gcc-common.h"
+#include "proposed-plugin-api/gcc-type.h"
+#include "proposed-plugin-api/gcc-constant.h"
+#include "proposed-plugin-api/gcc-tree.h"
+#include "tree.h"
+
+/*
+ Types
+*/
+
+/* gcc_integer_type */
+GCC_IMPLEMENT_PRIVATE_API(gcc_integer_constant)
+gcc_private_make_integer_constant(tree inner)
+{
+ gcc_integer_constant result;
+ result.inner = INTEGER_CST_CHECK(inner);
+ return result;
+}
+
+GCC_IMPLEMENT_PUBLIC_API(gcc_integer_constant)
+gcc_integer_type_get_max_value(gcc_integer_type node)
+{
+ return gcc_private_make_integer_constant(TYPE_MAX_VALUE(node.inner));
+}
+
+GCC_IMPLEMENT_PUBLIC_API(gcc_integer_constant)
+gcc_integer_type_get_min_value(gcc_integer_type node)
+{
+ return gcc_private_make_integer_constant(TYPE_MIN_VALUE(node.inner));
+}
+
+/*
+ PEP-7
+Local variables:
+c-basic-offset: 4
+indent-tabs-mode: nil
+End:
+*/
diff --git a/proposed-plugin-api/xml-to-h.py b/proposed-plugin-api/xml-to-h.py
index dad202e..e142585 100644
--- a/proposed-plugin-api/xml-to-h.py
+++ b/proposed-plugin-api/xml-to-h.py
@@ -125,17 +125,18 @@ def write_api(api, out):
itertype.get_varname()))
out.write('\n')
- # add upcast
- if type_.get_base():
+ # add upcasts
+ for base in type_.get_bases():
out.write('GCC_PUBLIC_API(%s)\n'
- '%s_upcast(%s %s);\n'
- % (type_.get_base().get_c_name(),
+ '%s_as_%s(%s %s);\n'
+ % (base.get_c_name(),
type_.get_c_prefix(),
+ base.get_c_name(),
type_.get_c_name(),
type_.get_varname()))
# add downcasts
- for subclass in type_.get_subclasses():
+ for subclass in type_.get_subclasses(recursive=True):
out.write('GCC_PUBLIC_API(%s)\n'
'%s_as_%s(%s %s);\n\n'
% (subclass.get_c_name(),
diff --git a/proposed-plugin-api/xmltypes.py b/proposed-plugin-api/xmltypes.py
index e06852c..e01e934 100644
--- a/proposed-plugin-api/xmltypes.py
+++ b/proposed-plugin-api/xmltypes.py
@@ -61,12 +61,23 @@ class Type(XmlWrapper, HasDocsMixin):
if basename:
return self.api.registry.lookup_type(basename)
- def get_subclasses(self):
+ def get_bases(self):
+ basename = self.node.get('base')
+ if basename:
+ base = self.api.registry.lookup_type(basename)
+ yield base
+ for base in base.get_bases():
+ yield base
+
+ def get_subclasses(self, recursive=False):
# brute force linear search for now:
for type_ in self.api.registry.iter_types():
base = type_.get_base()
if base == self:
yield type_
+ if recursive:
+ for type_ in type_.get_subclasses(recursive):
+ yield type_
def get_varname(self):
varname = self.node.get('varname')
12 years
[gcc-python-plugin/proposed-plugin-api] add some type-checking to gcc_private_make_ implementations
by David Hugh Malcolm
commit 69d72592c20b740107fb3d114c8141e124e05e5c
Author: David Malcolm <dmalcolm(a)redhat.com>
Date: Tue May 8 12:28:34 2012 -0400
add some type-checking to gcc_private_make_ implementations
proposed-plugin-api/gcc-declaration.c | 6 +++---
proposed-plugin-api/gcc-gimple.c | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/proposed-plugin-api/gcc-declaration.c b/proposed-plugin-api/gcc-declaration.c
index 93a5240..489ddc9 100644
--- a/proposed-plugin-api/gcc-declaration.c
+++ b/proposed-plugin-api/gcc-declaration.c
@@ -26,15 +26,15 @@ GCC_IMPLEMENT_PRIVATE_API(struct gcc_function_decl)
gcc_private_make_function_decl(tree inner)
{
struct gcc_function_decl result;
- result.inner = inner;
+ result.inner = FUNCTION_DECL_CHECK(inner);
return result;
}
-GCC_PRIVATE_API(struct gcc_translation_unit_decl)
+GCC_IMPLEMENT_PRIVATE_API(struct gcc_translation_unit_decl)
gcc_private_make_translation_unit_decl(tree inner)
{
struct gcc_translation_unit_decl result;
- result.inner = inner;
+ result.inner = TRANSLATION_UNIT_DECL_CHECK(inner);
return result;
}
diff --git a/proposed-plugin-api/gcc-gimple.c b/proposed-plugin-api/gcc-gimple.c
index 40e2af3..f21fefd 100644
--- a/proposed-plugin-api/gcc-gimple.c
+++ b/proposed-plugin-api/gcc-gimple.c
@@ -47,7 +47,7 @@ GCC_IMPLEMENT_PRIVATE_API(struct gcc_gimple_phi)
gcc_private_make_gimple_phi(gimple inner)
{
struct gcc_gimple_phi result;
- /* FIXME: type-checking */
+ GIMPLE_CHECK (inner, GIMPLE_PHI);
result.inner = inner;
return result;
}
@@ -56,7 +56,7 @@ GCC_IMPLEMENT_PRIVATE_API(struct gcc_gimple_call)
gcc_private_make_gimple_call(gimple inner)
{
struct gcc_gimple_call result;
- /* FIXME: type-checking */
+ GIMPLE_CHECK (inner, GIMPLE_CALL);
result.inner = inner;
return result;
}
12 years
[gcc-python-plugin/proposed-plugin-api] add gcc-internal.h
by David Hugh Malcolm
commit 5d346a466468b53503412049935469e42e6b4cd9
Author: David Malcolm <dmalcolm(a)redhat.com>
Date: Tue May 8 12:19:10 2012 -0400
add gcc-internal.h
generate-tree-c.py | 4 +-
proposed-plugin-api/gcc-declaration.c | 16 ++++++++++++++
proposed-plugin-api/gcc-internal.h | 37 +++++++++++++++++++++++++++++++++
proposed-plugin-api/gcc-tree.c | 21 +++++++++++-------
4 files changed, 68 insertions(+), 10 deletions(-)
---
diff --git a/generate-tree-c.py b/generate-tree-c.py
index 40e702b..eef673b 100644
--- a/generate-tree-c.py
+++ b/generate-tree-c.py
@@ -465,10 +465,10 @@ def generate_tree_code_classes():
if tree_type.SYM == 'TRANSLATION_UNIT_DECL':
add_simple_getter('block',
- 'gcc_python_make_wrapper_tree(gcc_private_make_tree(DECL_INITIAL(self->t.inner)))',
+ 'gcc_python_make_wrapper_tree(gcc_block_upcast(gcc_translation_unit_decl_get_block(gcc_decl_as_gcc_translation_unit_decl(gcc_tree_as_gcc_decl(self->t)))))',
"The gcc.Block for this namespace")
add_simple_getter('language',
- 'gcc_python_string_from_string(TRANSLATION_UNIT_LANGUAGE(self->t.inner))',
+ 'gcc_python_string_from_string(gcc_translation_unit_decl_get_language(gcc_decl_as_gcc_translation_unit_decl(gcc_tree_as_gcc_decl(self->t))))',
"The source language of this translation unit, as a string")
if tree_type.SYM == 'BLOCK':
diff --git a/proposed-plugin-api/gcc-declaration.c b/proposed-plugin-api/gcc-declaration.c
index fbebd73..93a5240 100644
--- a/proposed-plugin-api/gcc-declaration.c
+++ b/proposed-plugin-api/gcc-declaration.c
@@ -20,6 +20,7 @@
#include "proposed-plugin-api/gcc-common.h"
#include "proposed-plugin-api/gcc-semiprivate-types.h"
#include "tree.h"
+#include "gcc-internal.h"
GCC_IMPLEMENT_PRIVATE_API(struct gcc_function_decl)
gcc_private_make_function_decl(tree inner)
@@ -68,6 +69,21 @@ gcc_translation_unit_decl_upcast(gcc_translation_unit_decl fndecl)
return decl;
}
+IMPLEMENT_DOWNCAST(gcc_decl, gcc_translation_unit_decl)
+
+GCC_IMPLEMENT_PUBLIC_API(gcc_block)
+gcc_translation_unit_decl_get_block(gcc_translation_unit_decl node)
+{
+ return gcc_private_make_block(DECL_INITIAL(node.inner));
+}
+
+GCC_IMPLEMENT_PUBLIC_API(const char*)
+gcc_translation_unit_decl_get_language(gcc_translation_unit_decl node)
+{
+ return TRANSLATION_UNIT_LANGUAGE(node.inner);
+}
+
+
GCC_IMPLEMENT_PUBLIC_API(bool)
gcc_for_each_translation_unit_decl(
bool (*cb)(gcc_translation_unit_decl node, void *user_data),
diff --git a/proposed-plugin-api/gcc-internal.h b/proposed-plugin-api/gcc-internal.h
new file mode 100644
index 0000000..b55a2ab
--- /dev/null
+++ b/proposed-plugin-api/gcc-internal.h
@@ -0,0 +1,37 @@
+/*
+ Copyright 2012 David Malcolm <dmalcolm(a)redhat.com>
+ Copyright 2012 Red Hat, Inc.
+
+ This is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+#define IMPLEMENT_DOWNCAST(T_INPUT, T_OUTPUT) \
+ GCC_IMPLEMENT_PUBLIC_API(T_OUTPUT) \
+ T_INPUT ## _as_ ## T_OUTPUT(T_INPUT input) \
+ { \
+ T_OUTPUT output; \
+ output.inner = input.inner; \
+ return output; \
+ }
+
+#define IMPLEMENT_UPCAST(T_INPUT, T_OUTPUT) \
+ GCC_IMPLEMENT_PUBLIC_API(T_OUTPUT) \
+ T_INPUT ## _upcast(T_INPUT input) \
+ { \
+ T_OUTPUT output; \
+ output.inner = input.inner; \
+ return output; \
+ }
+
diff --git a/proposed-plugin-api/gcc-tree.c b/proposed-plugin-api/gcc-tree.c
index ffbfeaf..bc8355e 100644
--- a/proposed-plugin-api/gcc-tree.c
+++ b/proposed-plugin-api/gcc-tree.c
@@ -20,6 +20,9 @@
#include "proposed-plugin-api/gcc-common.h"
#include "proposed-plugin-api/gcc-tree.h"
#include "ggc.h"
+#include "gcc-internal.h"
+#include <assert.h>
+#include "tree.h"
/*
Trees
@@ -42,14 +45,13 @@ gcc_private_make_tree(tree inner)
return result;
}
-#define IMPLEMENT_DOWNCAST(T_INPUT, T_OUTPUT) \
- GCC_IMPLEMENT_PUBLIC_API(T_OUTPUT) \
- T_INPUT ## _as_ ## T_OUTPUT(T_INPUT input) \
- { \
- T_OUTPUT output; \
- output.inner = input.inner; \
- return output; \
- }
+GCC_IMPLEMENT_PRIVATE_API(struct gcc_block)
+gcc_private_make_block(tree inner)
+{
+ struct gcc_block result;
+ result.inner = BLOCK_CHECK(inner);
+ return result;
+}
IMPLEMENT_DOWNCAST(gcc_tree, gcc_constant)
IMPLEMENT_DOWNCAST(gcc_tree, gcc_decl)
@@ -102,6 +104,9 @@ gcc_block_mark_in_use(gcc_block node);
GCC_IMPLEMENT_PUBLIC_API(gcc_tree)
gcc_block_upcast(gcc_block node);
+IMPLEMENT_UPCAST(gcc_block, gcc_tree)
+
+
/* gcc_statement */
GCC_IMPLEMENT_PUBLIC_API(void)
gcc_statement_mark_in_use(gcc_statement node);
12 years
[gcc-python-plugin/proposed-plugin-api] add gcc_for_each_translation_unit_decl
by David Hugh Malcolm
commit 203e86a5890206597b9dc77b1f5250f7faf63547
Author: David Malcolm <dmalcolm(a)redhat.com>
Date: Mon May 7 19:45:16 2012 -0400
add gcc_for_each_translation_unit_decl
gcc-python.c | 19 +++++++++++-----
proposed-plugin-api/declaration.xml | 4 +++
proposed-plugin-api/gcc-declaration.c | 39 +++++++++++++++++++++++++++++++++
3 files changed, 56 insertions(+), 6 deletions(-)
---
diff --git a/gcc-python.c b/gcc-python.c
index 4627770..b83e09a 100644
--- a/gcc-python.c
+++ b/gcc-python.c
@@ -25,6 +25,7 @@
#include "proposed-plugin-api/gcc-location.h"
#include "proposed-plugin-api/gcc-variable.h"
+#include "proposed-plugin-api/gcc-declaration.h"
int plugin_is_GPL_compatible;
@@ -253,15 +254,21 @@ gcc_python_maybe_get_identifier(PyObject *self, PyObject *args)
return gcc_python_make_wrapper_tree(gcc_private_make_tree(t));
}
-/*
- get_translation_units was made globally visible in gcc revision 164331:
- http://gcc.gnu.org/ml/gcc-cvs/2010-09/msg00625.html
- http://gcc.gnu.org/viewcvs?view=revision&revision=164331
-*/
+static PyObject *gcc_python_make_translation_unit_decl(gcc_translation_unit_decl decl)
+{
+ gcc_tree tree = gcc_decl_upcast(gcc_translation_unit_decl_upcast(decl));
+ return gcc_python_make_wrapper_tree(tree);
+}
+
+IMPL_APPENDER(add_translation_unit_decl_to_list,
+ gcc_translation_unit_decl,
+ gcc_python_make_translation_unit_decl)
+
static PyObject *
gcc_python_get_translation_units(PyObject *self, PyObject *args)
{
- return VEC_tree_as_PyList(all_translation_units);
+ IMPL_GLOBAL_LIST_MAKER(gcc_for_each_translation_unit_decl,
+ add_translation_unit_decl_to_list)
}
/* Weakly import global_namespace; it will be non-NULL for the C++ frontend: */
diff --git a/proposed-plugin-api/declaration.xml b/proposed-plugin-api/declaration.xml
index 3a91065..62ebdaf 100644
--- a/proposed-plugin-api/declaration.xml
+++ b/proposed-plugin-api/declaration.xml
@@ -68,6 +68,8 @@
</type>
<type name="translation_unit_decl" base="decl">
+ <attribute name="block" kind="block"/>
+ <attribute name="language" kind="string"/>
</type>
<type name="type_decl" base="decl">
@@ -79,4 +81,6 @@
<type name="var_decl" base="decl">
</type>
+ <iterator name="translation_unit_decl" kind="translation_unit_decl"/>
+
</api>
\ No newline at end of file
diff --git a/proposed-plugin-api/gcc-declaration.c b/proposed-plugin-api/gcc-declaration.c
index 0e124c7..fbebd73 100644
--- a/proposed-plugin-api/gcc-declaration.c
+++ b/proposed-plugin-api/gcc-declaration.c
@@ -29,6 +29,15 @@ gcc_private_make_function_decl(tree inner)
return result;
}
+GCC_PRIVATE_API(struct gcc_translation_unit_decl)
+gcc_private_make_translation_unit_decl(tree inner)
+{
+ struct gcc_translation_unit_decl result;
+ result.inner = inner;
+ return result;
+}
+
+
GCC_IMPLEMENT_PUBLIC_API(gcc_location)
gcc_decl_get_location(gcc_decl decl)
{
@@ -51,6 +60,36 @@ gcc_function_decl_upcast(gcc_function_decl fndecl)
return decl;
}
+GCC_IMPLEMENT_PUBLIC_API(gcc_decl)
+gcc_translation_unit_decl_upcast(gcc_translation_unit_decl fndecl)
+{
+ gcc_decl decl;
+ decl.inner = fndecl.inner;
+ return decl;
+}
+
+GCC_IMPLEMENT_PUBLIC_API(bool)
+gcc_for_each_translation_unit_decl(
+ bool (*cb)(gcc_translation_unit_decl node, void *user_data),
+ void *user_data)
+{
+ int i;
+ tree t;
+
+ /*
+ all_translation_units was made globally visible in gcc revision 164331:
+ http://gcc.gnu.org/ml/gcc-cvs/2010-09/msg00625.html
+ http://gcc.gnu.org/viewcvs?view=revision&revision=164331
+ */
+ FOR_EACH_VEC_ELT(tree, all_translation_units, i, t) {
+ if (cb(gcc_private_make_translation_unit_decl(t),
+ user_data)) {
+ return true;
+ }
+ }
+ return false;
+}
+
/*
PEP-7
12 years
[gcc-python-plugin/proposed-plugin-api] add macros IMPL_APPENDER, IMPL_LIST_MAKER, IMPL_GLOBAL_LIST_MAKER
by David Hugh Malcolm
commit 9ce10d2e0b368b1770df82eea0dba6185837d91b
Author: David Malcolm <dmalcolm(a)redhat.com>
Date: Mon May 7 19:41:34 2012 -0400
add macros IMPL_APPENDER, IMPL_LIST_MAKER, IMPL_GLOBAL_LIST_MAKER
gcc-python-callgraph.c | 94 +++-----------------
gcc-python-cfg.c | 223 ++++++++----------------------------------------
gcc-python-wrappers.h | 55 ++++++++++++
gcc-python.c | 34 +------
4 files changed, 111 insertions(+), 295 deletions(-)
---
diff --git a/gcc-python-callgraph.c b/gcc-python-callgraph.c
index 84bfe24..6a6749e 100644
--- a/gcc-python-callgraph.c
+++ b/gcc-python-callgraph.c
@@ -56,64 +56,24 @@ gcc_CallgraphNode_str(struct PyGccCallgraphNode * self)
Py_TYPE(self)->tp_name);
}
-static bool add_cgraph_edge_to_list(gcc_cgraph_edge edge, void *user_data)
-{
- PyObject *result = (PyObject*)user_data;
- PyObject *item;
-
- item = gcc_python_make_wrapper_cgraph_edge(edge);
- if (!item) {
- return true;
- }
-
- if (-1 == PyList_Append(result, item)) {
- Py_DECREF(item);
- return true;
- }
-
- /* Success: */
- Py_DECREF(item);
- return false;
-}
+IMPL_APPENDER(add_cgraph_edge_to_list,
+ gcc_cgraph_edge,
+ gcc_python_make_wrapper_cgraph_edge)
PyObject *
gcc_CallgraphNode_get_callees(struct PyGccCallgraphNode * self)
{
- PyObject *result;
-
- result = PyList_New(0);
- if (!result) {
- return NULL;
- }
-
- if (gcc_cgraph_node_for_each_callee(self->node,
- add_cgraph_edge_to_list,
- result)) {
- Py_DECREF(result);
- return NULL;
- }
-
- return result;
+ IMPL_LIST_MAKER(gcc_cgraph_node_for_each_callee,
+ self->node,
+ add_cgraph_edge_to_list)
}
PyObject *
gcc_CallgraphNode_get_callers(struct PyGccCallgraphNode * self)
{
- PyObject *result;
-
- result = PyList_New(0);
- if (!result) {
- return NULL;
- }
-
- if (gcc_cgraph_node_for_each_caller(self->node,
- add_cgraph_edge_to_list,
- result)) {
- Py_DECREF(result);
- return NULL;
- }
-
- return result;
+ IMPL_LIST_MAKER(gcc_cgraph_node_for_each_caller,
+ self->node,
+ add_cgraph_edge_to_list)
}
PyObject *
@@ -185,31 +145,13 @@ gcc_python_make_wrapper_cgraph_node(gcc_cgraph_node node)
real_make_cgraph_node_wrapper);
}
-static bool add_cgraph_node_to_list(gcc_cgraph_node node, void *user_data)
-{
- PyObject *result = (PyObject*)user_data;
- PyObject *item;
-
- item = gcc_python_make_wrapper_cgraph_node(node);
- if (!item) {
- return true;
- }
-
- if (-1 == PyList_Append(result, item)) {
- Py_DECREF(item);
- return true;
- }
-
- /* Success: */
- Py_DECREF(item);
- return false;
-}
+IMPL_APPENDER(add_cgraph_node_to_list,
+ gcc_cgraph_node,
+ gcc_python_make_wrapper_cgraph_node)
PyObject *
gcc_python_get_callgraph_nodes(PyObject *self, PyObject *args)
{
- PyObject *result;
-
/* For debugging, see GCC's dump of things: */
if (0) {
fprintf(stderr, "----------------BEGIN----------------\n");
@@ -217,16 +159,8 @@ gcc_python_get_callgraph_nodes(PyObject *self, PyObject *args)
fprintf(stderr, "---------------- END ----------------\n");
}
- result = PyList_New(0);
- if (!result) {
- return NULL;
- }
-
- if (gcc_for_each_cgraph_node(add_cgraph_node_to_list, result)) {
- Py_DECREF(result);
- return NULL;
- }
- return result;
+ IMPL_GLOBAL_LIST_MAKER(gcc_for_each_cgraph_node,
+ add_cgraph_node_to_list)
}
/*
diff --git a/gcc-python-cfg.c b/gcc-python-cfg.c
index 98411ac..5ef2507 100644
--- a/gcc-python-cfg.c
+++ b/gcc-python-cfg.c
@@ -67,196 +67,75 @@ wrtp_mark_for_PyGccEdge(PyGccEdge *wrapper)
gcc_cfg_edge_mark_in_use(wrapper->e);
}
-static bool add_edge_to_list(gcc_cfg_edge edge, void *user_data)
-{
- PyObject *result = (PyObject*)user_data;
- PyObject *item;
-
- item = gcc_python_make_wrapper_edge(edge);
- if (!item) {
- return true;
- }
-
- if (-1 == PyList_Append(result, item)) {
- Py_DECREF(item);
- return true;
- }
-
- /* Success: */
- Py_DECREF(item);
- return false;
-}
+IMPL_APPENDER(add_edge_to_list,
+ gcc_cfg_edge,
+ gcc_python_make_wrapper_edge)
PyObject *
gcc_BasicBlock_get_preds(PyGccBasicBlock *self, void *closure)
{
- PyObject *result;
-
- result = PyList_New(0);
- if (!result) {
- return NULL;
- }
-
- if (gcc_cfg_block_for_each_pred_edge(self->bb,
- add_edge_to_list,
- result)) {
- Py_DECREF(result);
- return NULL;
- }
-
- return result;
+ IMPL_LIST_MAKER(gcc_cfg_block_for_each_pred_edge,
+ self->bb,
+ add_edge_to_list)
}
PyObject *
gcc_BasicBlock_get_succs(PyGccBasicBlock *self, void *closure)
{
- PyObject *result;
-
- result = PyList_New(0);
- if (!result) {
- return NULL;
- }
-
- if (gcc_cfg_block_for_each_succ_edge(self->bb,
- add_edge_to_list,
- result)) {
- Py_DECREF(result);
- return NULL;
- }
-
- return result;
+ IMPL_LIST_MAKER(gcc_cfg_block_for_each_succ_edge,
+ self->bb,
+ add_edge_to_list)
}
-static bool
-append_gimple_to_list(gcc_gimple stmt, void *user_data)
-{
- PyObject *result = (PyObject *)user_data;
- PyObject *obj_stmt;
-
- obj_stmt = gcc_python_make_wrapper_gimple(stmt);
- if (!obj_stmt) {
- return true;
- }
-
- if (PyList_Append(result, obj_stmt)) {
- Py_DECREF(obj_stmt);
- return true;
- }
-
- /* Success: */
- Py_DECREF(obj_stmt);
- return false;
-}
+IMPL_APPENDER(append_gimple_to_list,
+ gcc_gimple,
+ gcc_python_make_wrapper_gimple)
PyObject *
gcc_BasicBlock_get_gimple(PyGccBasicBlock *self, void *closure)
{
- PyObject *result = NULL;
-
assert(self);
assert(self->bb.inner);
- result = PyList_New(0);
- if (!result) {
- return NULL;
- }
-
- if (gcc_cfg_block_for_each_gimple(self->bb,
- append_gimple_to_list,
- result)) {
- Py_DECREF(result);
- return NULL;
- }
-
- return result;
+ IMPL_LIST_MAKER(gcc_cfg_block_for_each_gimple,
+ self->bb,
+ append_gimple_to_list)
}
-static bool
-append_gimple_phi_to_list(gcc_gimple_phi stmt, void *user_data)
+static PyObject*
+gcc_python_make_wrapper_gimple_phi(gcc_gimple_phi phi)
{
- PyObject *result = (PyObject *)user_data;
- PyObject *obj_stmt;
-
- obj_stmt = gcc_python_make_wrapper_gimple(gcc_gimple_phi_upcast(stmt));
- if (!obj_stmt) {
- return true;
- }
-
- if (PyList_Append(result, obj_stmt)) {
- Py_DECREF(obj_stmt);
- return true;
- }
-
- /* Success: */
- Py_DECREF(obj_stmt);
- return false;
+ return gcc_python_make_wrapper_gimple(gcc_gimple_phi_upcast(phi));
}
+IMPL_APPENDER(append_gimple_phi_to_list,
+ gcc_gimple_phi,
+ gcc_python_make_wrapper_gimple_phi)
+
PyObject *
gcc_BasicBlock_get_phi_nodes(PyGccBasicBlock *self, void *closure)
{
- PyObject *result = NULL;
-
assert(self);
assert(self->bb.inner);
- result = PyList_New(0);
- if (!result) {
- return NULL;
- }
-
- if (gcc_cfg_block_for_each_gimple_phi(self->bb,
- append_gimple_phi_to_list,
- result)) {
- Py_DECREF(result);
- return NULL;
- }
-
- return result;
+ IMPL_LIST_MAKER(gcc_cfg_block_for_each_gimple_phi,
+ self->bb,
+ append_gimple_phi_to_list)
}
-static bool
-append_rtl_to_list(gcc_rtl_insn insn, void *user_data)
-{
- PyObject *result = (PyObject *)user_data;
- PyObject *obj;
-
- obj = gcc_python_make_wrapper_rtl(insn);
- if (!obj) {
- return true;
- }
-
- if (PyList_Append(result, obj)) {
- Py_DECREF(obj);
- return true;
- }
-
- /* Success: */
- Py_DECREF(obj);
- return false;
-}
+IMPL_APPENDER(append_rtl_to_list,
+ gcc_rtl_insn,
+ gcc_python_make_wrapper_rtl)
PyObject *
gcc_BasicBlock_get_rtl(PyGccBasicBlock *self, void *closure)
{
- PyObject *result = NULL;
-
assert(self);
assert(self->bb.inner);
- result = PyList_New(0);
- if (!result) {
- return NULL;
- }
-
- if (gcc_cfg_block_for_each_rtl_insn(self->bb,
- append_rtl_to_list,
- result)) {
- Py_DECREF(result);
- return NULL;
- }
-
- return result;
+ IMPL_LIST_MAKER(gcc_cfg_block_for_each_rtl_insn,
+ self->bb,
+ append_rtl_to_list)
}
@@ -461,44 +340,16 @@ gcc_python_make_wrapper_basic_block(gcc_cfg_block bb)
real_make_basic_block_wrapper);
}
-static bool add_block_to_list(gcc_cfg_block block, void *user_data)
-{
- PyObject *result = (PyObject*)user_data;
- PyObject *item;
-
- item = gcc_python_make_wrapper_basic_block(block);
- if (!item) {
- return true;
- }
-
- if (-1 == PyList_Append(result, item)) {
- Py_DECREF(item);
- return true;
- }
-
- /* Success: */
- Py_DECREF(item);
- return false;
-}
+IMPL_APPENDER(add_block_to_list,
+ gcc_cfg_block,
+ gcc_python_make_wrapper_basic_block)
PyObject *
gcc_Cfg_get_basic_blocks(PyGccCfg *self, void *closure)
{
- PyObject *result;
-
- result = PyList_New(0);
- if (!result) {
- return NULL;
- }
-
- if (gcc_cfg_for_each_block(self->cfg,
- add_block_to_list,
- result)) {
- Py_DECREF(result);
- return NULL;
- }
-
- return result;
+ IMPL_LIST_MAKER(gcc_cfg_for_each_block,
+ self->cfg,
+ add_block_to_list)
}
extern PyTypeObject gcc_LabelDeclType;
diff --git a/gcc-python-wrappers.h b/gcc-python-wrappers.h
index fb70fb4..7657948 100644
--- a/gcc-python-wrappers.h
+++ b/gcc-python-wrappers.h
@@ -25,6 +25,61 @@
#include "opts.h"
#include "cgraph.h"
+/*
+ Create a callback for use in a gcc for_each iterator to make wrapper
+ objects for the underlying gcc objects being iterated, and append the
+ wrapper objects to a Python list
+*/
+#define IMPL_APPENDER(FNNAME, KIND, MAKE_WRAPPER) \
+ static bool FNNAME(KIND var, void *user_data) \
+ { \
+ PyObject *result = (PyObject*)user_data; \
+ PyObject *obj_var; \
+ obj_var = MAKE_WRAPPER(var); \
+ if (!obj_var) { \
+ return true; \
+ } \
+ if (-1 == PyList_Append(result, obj_var)) { \
+ Py_DECREF(obj_var); \
+ return true; \
+ } \
+ /* Success: */ \
+ Py_DECREF(obj_var); \
+ return false; \
+ }
+
+/*
+ Create the body of a function that builds a list by calling a for_each
+ ITERATOR, passing in the APPENDER callback to convert the iterated items
+ into Python wrapper objects
+ */
+#define IMPL_LIST_MAKER(ITERATOR, ARG, APPENDER) \
+ PyObject *result; \
+ result = PyList_New(0); \
+ if (!result) { \
+ return NULL; \
+ } \
+ if (ITERATOR((ARG), APPENDER, result)) { \
+ Py_DECREF(result); \
+ return NULL; \
+ } \
+ return result;
+
+/*
+As per IMPL_LIST_MAKER, but for a global iterator that takes no ARG
+ */
+#define IMPL_GLOBAL_LIST_MAKER(ITERATOR, APPENDER) \
+ PyObject *result; \
+ result = PyList_New(0); \
+ if (!result) { \
+ return NULL; \
+ } \
+ if (ITERATOR(APPENDER, result)) { \
+ Py_DECREF(result); \
+ return NULL; \
+ } \
+ return result;
+
PyMODINIT_FUNC initoptpass(void);
/* gcc-python-attribute.c: */
diff --git a/gcc-python.c b/gcc-python.c
index 462bf4d..4627770 100644
--- a/gcc-python.c
+++ b/gcc-python.c
@@ -226,39 +226,15 @@ gcc_python_get_parameters(PyObject *self, PyObject *args)
return NULL;
}
-static bool add_var_to_list(gcc_variable var, void *user_data)
-{
- PyObject *result = (PyObject*)user_data;
- PyObject *obj_var;
-
- obj_var = gcc_python_make_wrapper_variable(var);
- if (!obj_var) {
- return true;
- }
- if (-1 == PyList_Append(result, obj_var)) {
- Py_DECREF(obj_var);
- return true;
- }
- /* Success: */
- Py_DECREF(obj_var);
- return false;
-}
+IMPL_APPENDER(add_var_to_list,
+ gcc_variable,
+ gcc_python_make_wrapper_variable)
static PyObject *
gcc_python_get_variables(PyObject *self, PyObject *args)
{
- PyObject *result;
-
- result = PyList_New(0);
- if (!result) {
- return NULL;
- }
-
- if (gcc_for_each_variable(add_var_to_list, result)) {
- Py_DECREF(result);
- return NULL;
- }
- return result;
+ IMPL_GLOBAL_LIST_MAKER(gcc_for_each_variable,
+ add_var_to_list)
}
static PyObject *
12 years
[gcc-python-plugin/proposed-plugin-api] add gcc_gimple_get_location
by David Hugh Malcolm
commit 24310b8f25de335e89cdbe74362550aefb60a7ca
Author: David Malcolm <dmalcolm(a)redhat.com>
Date: Mon May 7 16:49:35 2012 -0400
add gcc_gimple_get_location
generate-gimple-c.py | 3 ++-
proposed-plugin-api/gcc-gimple.c | 6 ++++++
2 files changed, 8 insertions(+), 1 deletions(-)
---
diff --git a/generate-gimple-c.py b/generate-gimple-c.py
index 6b99112..f34136c 100644
--- a/generate-gimple-c.py
+++ b/generate-gimple-c.py
@@ -25,6 +25,7 @@ cu.add_include('gcc-python.h')
cu.add_include('gcc-python-wrappers.h')
cu.add_include('gcc-plugin.h')
cu.add_include("gimple.h")
+cu.add_include("proposed-plugin-api/gcc-gimple.h")
modinit_preinit = ''
modinit_postinit = ''
@@ -192,7 +193,7 @@ def generate_gimple():
static PyObject *
gcc_Gimple_get_location(struct PyGccGimple *self, void *closure)
{
- return gcc_python_make_wrapper_location(gcc_private_make_location(gimple_location(self->stmt.inner)));
+ return gcc_python_make_wrapper_location(gcc_gimple_get_location(self->stmt));
}
static PyObject *
diff --git a/proposed-plugin-api/gcc-gimple.c b/proposed-plugin-api/gcc-gimple.c
index bd980b2..40e2af3 100644
--- a/proposed-plugin-api/gcc-gimple.c
+++ b/proposed-plugin-api/gcc-gimple.c
@@ -70,6 +70,12 @@ gcc_private_make_gimple(gimple inner)
return result;
}
+GCC_IMPLEMENT_PUBLIC_API(gcc_location)
+gcc_gimple_get_location(gcc_gimple stmt)
+{
+ return gcc_private_make_location(gimple_location(stmt.inner));
+}
+
GCC_IMPLEMENT_PUBLIC_API(gcc_gimple)
gcc_gimple_phi_upcast(gcc_gimple_phi phi)
{
12 years
[gcc-python-plugin/proposed-plugin-api] add gcc_function_get_decl
by David Hugh Malcolm
commit 67e5b50611441e611504896b2aac02eb77bff53a
Author: David Malcolm <dmalcolm(a)redhat.com>
Date: Mon May 7 16:46:03 2012 -0400
add gcc_function_get_decl
generate-function-c.py | 4 +++-
proposed-plugin-api/function.xml | 1 +
proposed-plugin-api/gcc-function.c | 6 ++++++
3 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/generate-function-c.py b/generate-function-c.py
index 65905f9..a1e700b 100644
--- a/generate-function-c.py
+++ b/generate-function-c.py
@@ -24,6 +24,8 @@ cu.add_include('gcc-python-wrappers.h')
cu.add_include('gcc-plugin.h')
cu.add_include("function.h")
cu.add_include("proposed-plugin-api/gcc-function.h")
+cu.add_include("proposed-plugin-api/gcc-declaration.h")
+cu.add_include("proposed-plugin-api/gcc-tree.h")
modinit_preinit = ''
modinit_postinit = ''
@@ -49,7 +51,7 @@ def generate_function():
typename='PyGccFunction')
getsettable.add_simple_getter(cu,
'decl',
- 'gcc_python_make_wrapper_tree(gcc_private_make_tree(self->fun.inner->decl))',
+ 'gcc_python_make_wrapper_tree(gcc_decl_upcast(gcc_function_decl_upcast(gcc_function_get_decl(self->fun))))',
'The declaration of this function, as a gcc.FunctionDecl instance')
getsettable.add_simple_getter(cu,
'local_decls',
diff --git a/proposed-plugin-api/function.xml b/proposed-plugin-api/function.xml
index 55a5b93..e774e9e 100644
--- a/proposed-plugin-api/function.xml
+++ b/proposed-plugin-api/function.xml
@@ -26,6 +26,7 @@
<doc>The control flow graph for this function (can be NULL in early
passes)</doc>
</attribute>
+ <attribute name="decl" kind="function_decl"/>
<attribute name="index" kind="int"/>
<attribute name="start" kind="location"/>
<attribute name="end" kind="location"/>
diff --git a/proposed-plugin-api/gcc-function.c b/proposed-plugin-api/gcc-function.c
index cf8ee2f..84c3753 100644
--- a/proposed-plugin-api/gcc-function.c
+++ b/proposed-plugin-api/gcc-function.c
@@ -56,6 +56,12 @@ gcc_function_get_cfg(gcc_function func)
return gcc_private_make_cfg(func.inner->cfg);
}
+GCC_IMPLEMENT_PUBLIC_API(gcc_function_decl)
+gcc_function_get_decl(gcc_function func)
+{
+ return gcc_private_make_function_decl(func.inner->decl);
+}
+
GCC_IMPLEMENT_PUBLIC_API(int)
gcc_function_get_index(gcc_function func)
{
12 years
[gcc-python-plugin/proposed-plugin-api] add gcc_decl_get_location
by David Hugh Malcolm
commit ab5d2204495189845cfe4eb36d2e6b5f036034e4
Author: David Malcolm <dmalcolm(a)redhat.com>
Date: Fri May 4 14:50:27 2012 -0400
add gcc_decl_get_location
generate-tree-c.py | 4 +++-
proposed-plugin-api/declaration.xml | 1 +
proposed-plugin-api/gcc-declaration.c | 7 +++++++
3 files changed, 11 insertions(+), 1 deletions(-)
---
diff --git a/generate-tree-c.py b/generate-tree-c.py
index 9dcc0f6..40e702b 100644
--- a/generate-tree-c.py
+++ b/generate-tree-c.py
@@ -32,6 +32,8 @@ cu.add_include("tree.h")
cu.add_include("function.h")
cu.add_include("basic-block.h")
cu.add_include("c-family/c-common.h")
+cu.add_include("proposed-plugin-api/gcc-tree.h")
+cu.add_include("proposed-plugin-api/gcc-declaration.h")
modinit_preinit = ''
modinit_postinit = ''
@@ -163,7 +165,7 @@ gcc_Declaration_get_name(struct PyGccTree *self, void *closure)
static PyObject *
gcc_Declaration_get_location(struct PyGccTree *self, void *closure)
{
- return gcc_python_make_wrapper_location(gcc_private_make_location(DECL_SOURCE_LOCATION(self->t.inner)));
+ return gcc_python_make_wrapper_location(gcc_decl_get_location(gcc_tree_as_gcc_decl(self->t)));
}
""")
diff --git a/proposed-plugin-api/declaration.xml b/proposed-plugin-api/declaration.xml
index 73e812e..3a91065 100644
--- a/proposed-plugin-api/declaration.xml
+++ b/proposed-plugin-api/declaration.xml
@@ -22,6 +22,7 @@
<doc>Declarations</doc>
<type name="decl" base="tree">
+ <attribute name="location" kind="location"/>
</type>
<type name="class_method_decl" base="decl">
diff --git a/proposed-plugin-api/gcc-declaration.c b/proposed-plugin-api/gcc-declaration.c
index 34a2276..0e124c7 100644
--- a/proposed-plugin-api/gcc-declaration.c
+++ b/proposed-plugin-api/gcc-declaration.c
@@ -19,6 +19,7 @@
#include "proposed-plugin-api/gcc-common.h"
#include "proposed-plugin-api/gcc-semiprivate-types.h"
+#include "tree.h"
GCC_IMPLEMENT_PRIVATE_API(struct gcc_function_decl)
gcc_private_make_function_decl(tree inner)
@@ -28,6 +29,12 @@ gcc_private_make_function_decl(tree inner)
return result;
}
+GCC_IMPLEMENT_PUBLIC_API(gcc_location)
+gcc_decl_get_location(gcc_decl decl)
+{
+ return gcc_private_make_location(DECL_SOURCE_LOCATION(decl.inner));
+}
+
GCC_IMPLEMENT_PUBLIC_API(gcc_tree)
gcc_decl_upcast(gcc_decl decl)
{
12 years
[gcc-python-plugin/proposed-plugin-api] add IMPLEMENT_DOWNCAST
by David Hugh Malcolm
commit 853c1eea453f7aa6dca9fbbb33097ee232b8d795
Author: David Malcolm <dmalcolm(a)redhat.com>
Date: Fri May 4 14:49:52 2012 -0400
add IMPLEMENT_DOWNCAST
proposed-plugin-api/gcc-tree.c | 33 +++++++++++++++------------------
1 files changed, 15 insertions(+), 18 deletions(-)
---
diff --git a/proposed-plugin-api/gcc-tree.c b/proposed-plugin-api/gcc-tree.c
index 285900d..ffbfeaf 100644
--- a/proposed-plugin-api/gcc-tree.c
+++ b/proposed-plugin-api/gcc-tree.c
@@ -42,24 +42,21 @@ gcc_private_make_tree(tree inner)
return result;
}
-GCC_IMPLEMENT_PUBLIC_API(gcc_constant)
-gcc_tree_as_gcc_constant(gcc_tree node);
-
-GCC_IMPLEMENT_PUBLIC_API(gcc_decl)
-gcc_tree_as_gcc_decl(gcc_tree node);
-
-GCC_IMPLEMENT_PUBLIC_API(gcc_binary)
-gcc_tree_as_gcc_binary(gcc_tree node);
-
-GCC_IMPLEMENT_PUBLIC_API(gcc_block)
-gcc_tree_as_gcc_block(gcc_tree node);
-
-GCC_IMPLEMENT_PUBLIC_API(gcc_statement)
-gcc_tree_as_gcc_statement(gcc_tree node);
-
-GCC_IMPLEMENT_PUBLIC_API(gcc_type)
-gcc_tree_as_gcc_type(gcc_tree node);
-
+#define IMPLEMENT_DOWNCAST(T_INPUT, T_OUTPUT) \
+ GCC_IMPLEMENT_PUBLIC_API(T_OUTPUT) \
+ T_INPUT ## _as_ ## T_OUTPUT(T_INPUT input) \
+ { \
+ T_OUTPUT output; \
+ output.inner = input.inner; \
+ return output; \
+ }
+
+IMPLEMENT_DOWNCAST(gcc_tree, gcc_constant)
+IMPLEMENT_DOWNCAST(gcc_tree, gcc_decl)
+IMPLEMENT_DOWNCAST(gcc_tree, gcc_binary)
+IMPLEMENT_DOWNCAST(gcc_tree, gcc_block)
+IMPLEMENT_DOWNCAST(gcc_tree, gcc_statement)
+IMPLEMENT_DOWNCAST(gcc_tree, gcc_type)
/* gcc_binary */
GCC_IMPLEMENT_PUBLIC_API(void)
12 years