commit d22fc2f43cb7b92f5ac1823620b51c1c19d752e4 Author: David Malcolm dmalcolm@redhat.com Date: Thu Mar 29 23:27:48 2012 -0400
introduce GccFunctionI
Makefile | 1 + gcc-python-closure.c | 4 +- gcc-python-function.c | 13 ++-- gcc-python-pass.c | 5 +- gcc-python.h | 2 +- generate-function-c.py | 13 ++-- generate-tree-c.py | 2 +- proposed-plugin-api/gcc-function.c | 90 +++++++++++++++++++++++++++ proposed-plugin-api/gcc-function.h | 49 +++++++++++++++ proposed-plugin-api/gcc-public-types.h | 3 + proposed-plugin-api/gcc-semiprivate-types.h | 8 +++ 11 files changed, 173 insertions(+), 17 deletions(-) --- diff --git a/Makefile b/Makefile index d0d6e8b..eb58f86 100644 --- a/Makefile +++ b/Makefile @@ -19,6 +19,7 @@
PLUGIN_SOURCE_FILES= \ proposed-plugin-api/gcc-cfg.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 \ diff --git a/gcc-python-closure.c b/gcc-python-closure.c index f238914..a8b7dc2 100644 --- a/gcc-python-closure.c +++ b/gcc-python-closure.c @@ -24,6 +24,8 @@ #include "gcc-python.h" #include "function.h"
+#include "proposed-plugin-api/gcc-function.h" + struct callback_closure * gcc_python_closure_new_generic(PyObject *callback, PyObject *extraargs, PyObject *kwargs) { @@ -102,7 +104,7 @@ gcc_python_closure_make_args(struct callback_closure * closure, int add_cfun, Py }
if (add_cfun) { - cfun_obj = gcc_python_make_wrapper_function(cfun); + cfun_obj = gcc_python_make_wrapper_function(Gcc_GetCurrentFunction()); if (!cfun_obj) { goto error; } diff --git a/gcc-python-function.c b/gcc-python-function.c index a4997d6..0ce3676 100644 --- a/gcc-python-function.c +++ b/gcc-python-function.c @@ -29,6 +29,7 @@ */
#include "function.h" +#include "proposed-plugin-api/gcc-function.h"
PyObject * gcc_Function_repr(struct PyGccFunction * self) @@ -37,8 +38,8 @@ gcc_Function_repr(struct PyGccFunction * self) PyObject *result = NULL; tree decl;
- assert(self->fun); - decl = self->fun->decl; + assert(self->fun.inner); + decl = self->fun.inner->decl; if (DECL_NAME(decl)) { name = IDENTIFIER_POINTER (DECL_NAME(decl)); } else { @@ -58,11 +59,11 @@ error: }
PyObject * -gcc_python_make_wrapper_function(struct function *fun) +gcc_python_make_wrapper_function(GccFunctionI func) { struct PyGccFunction *obj;
- if (!fun) { + if (!func.inner) { Py_RETURN_NONE; }
@@ -117,7 +118,7 @@ gcc_python_make_wrapper_function(struct function *fun) goto error; }
- obj->fun = fun; + obj->fun = func;
return (PyObject*)obj;
@@ -129,7 +130,7 @@ void wrtp_mark_for_PyGccFunction(PyGccFunction *wrapper) { /* Mark the underlying object (recursing into its fields): */ - gt_ggc_mx_function(wrapper->fun); + GccFunctionI_MarkInUse(wrapper->fun); }
diff --git a/gcc-python-pass.c b/gcc-python-pass.c index 8471222..c3eb401 100644 --- a/gcc-python-pass.c +++ b/gcc-python-pass.c @@ -21,6 +21,7 @@ #include "gcc-python.h" #include "gcc-python-wrappers.h" #include "diagnostic.h" +#include "proposed-plugin-api/gcc-function.h" #include "proposed-plugin-api/gcc-location.h"
/* @@ -59,7 +60,7 @@ static bool impl_gate(void) if (cfun) { /* Temporarily override input_location to the top of the function: */ Gcc_SetInputLocation(GccPrivate_make_LocationI(cfun->function_start_locus)); - cfun_obj = gcc_python_make_wrapper_function(cfun); + cfun_obj = gcc_python_make_wrapper_function(Gcc_GetCurrentFunction()); if (!cfun_obj) { gcc_python_print_exception("Unhandled Python exception raised calling 'gate' method"); Py_DECREF(pass_obj); @@ -101,7 +102,7 @@ static unsigned int impl_execute(void) if (cfun) { /* Temporarily override input_location to the top of the function: */ Gcc_SetInputLocation(GccPrivate_make_LocationI(cfun->function_start_locus)); - cfun_obj = gcc_python_make_wrapper_function(cfun); + cfun_obj = gcc_python_make_wrapper_function(Gcc_GetCurrentFunction()); if (!cfun_obj) { gcc_python_print_exception("Unhandled Python exception raised calling 'execute' method"); Py_DECREF(pass_obj); diff --git a/gcc-python.h b/gcc-python.h index a4f004e..11b215b 100644 --- a/gcc-python.h +++ b/gcc-python.h @@ -197,7 +197,7 @@ DECLARE_SIMPLE_WRAPPER(PyGccCfg, DECLARE_SIMPLE_WRAPPER(PyGccFunction, gcc_FunctionType, function, - struct function *, fun) + GccFunctionI, fun)
DECLARE_SIMPLE_WRAPPER(PyGccOption, gcc_OptionType, diff --git a/generate-function-c.py b/generate-function-c.py index 67b007f..cce7238 100644 --- a/generate-function-c.py +++ b/generate-function-c.py @@ -23,6 +23,7 @@ cu.add_include('gcc-python.h') 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")
modinit_preinit = '' modinit_postinit = '' @@ -37,7 +38,7 @@ def generate_function(): "static PyObject *\n" "gcc_Function_get_cfg(struct PyGccFunction *self, void *closure)\n" "{\n" - " return gcc_python_make_wrapper_cfg(GccPrivate_make_CfgI(self->fun->cfg));\n" + " return gcc_python_make_wrapper_cfg(GccFunctionI_GetCfg(self->fun));\n" "}\n" "\n") getsettable = PyGetSetDefTable('gcc_Function_getset_table', @@ -48,23 +49,23 @@ def generate_function(): typename='PyGccFunction') getsettable.add_simple_getter(cu, 'decl', - 'gcc_python_make_wrapper_tree(self->fun->decl)', + 'gcc_python_make_wrapper_tree(self->fun.inner->decl)', 'The declaration of this function, as a gcc.FunctionDecl instance') getsettable.add_simple_getter(cu, 'local_decls', - 'VEC_tree_as_PyList(self->fun->local_decls)', + 'VEC_tree_as_PyList(self->fun.inner->local_decls)', "List of gcc.VarDecl for the function's local variables") getsettable.add_simple_getter(cu, 'funcdef_no', - 'gcc_python_int_from_long(self->fun->funcdef_no)', + 'gcc_python_int_from_long(GccFunctionI_GetIndex(self->fun))', 'Function sequence number for profiling, debugging, etc.') getsettable.add_simple_getter(cu, 'start', - 'gcc_python_make_wrapper_location(GccPrivate_make_LocationI(self->fun->function_start_locus))', + 'gcc_python_make_wrapper_location(GccFunctionI_GetStart(self->fun))', 'Location of the start of the function') getsettable.add_simple_getter(cu, 'end', - 'gcc_python_make_wrapper_location(GccPrivate_make_LocationI(self->fun->function_end_locus))', + 'gcc_python_make_wrapper_location(GccFunctionI_GetEnd(self->fun))', 'Location of the end of the function') cu.add_defn(getsettable.c_defn())
diff --git a/generate-tree-c.py b/generate-tree-c.py index ef63e2d..737ff90 100644 --- a/generate-tree-c.py +++ b/generate-tree-c.py @@ -504,7 +504,7 @@ def generate_tree_code_classes(): None, 'C++ only: the full name of this function declaration') add_simple_getter('function', - 'gcc_python_make_wrapper_function(DECL_STRUCT_FUNCTION(self->t))', + 'gcc_python_make_wrapper_function(GccPrivate_make_FunctionI(DECL_STRUCT_FUNCTION(self->t)))', 'The gcc.Function (or None) for this declaration') add_simple_getter('arguments', 'gcc_tree_list_from_chain(DECL_ARGUMENTS(self->t))', diff --git a/proposed-plugin-api/gcc-function.c b/proposed-plugin-api/gcc-function.c new file mode 100644 index 0000000..891330e --- /dev/null +++ b/proposed-plugin-api/gcc-function.c @@ -0,0 +1,90 @@ +/* + Copyright 2012 David Malcolm dmalcolm@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" + +/* TODO: rationalize these headers */ +#include "tree.h" +#include "gimple.h" +#include "params.h" +#include "cp/name-lookup.h" /* for global_namespace */ +#include "tree.h" +#include "function.h" +#include "diagnostic.h" +#include "cgraph.h" +#include "opts.h" +#include "c-family/c-pragma.h" /* for parse_in */ +#include "basic-block.h" +#include "rtl.h" + +/* Declarations: functions */ + +/* GccFunctionI */ +GCC_IMPLEMENT_PUBLIC_API(void) +GccFunctionI_MarkInUse(GccFunctionI func) +{ + gt_ggc_mx_function(func.inner); +} + +GCC_IMPLEMENT_PRIVATE_API(struct GccFunctionI) +GccPrivate_make_FunctionI(struct function *inner) +{ + struct GccFunctionI result; + result.inner = inner; + return result; +} + +GCC_IMPLEMENT_PUBLIC_API(GccCfgI) +GccFunctionI_GetCfg(GccFunctionI func) +{ + return GccPrivate_make_CfgI(func.inner->cfg); +} + +GCC_IMPLEMENT_PUBLIC_API(int) +GccFunctionI_GetIndex(GccFunctionI func) +{ + return func.inner->funcdef_no; +} + +GCC_IMPLEMENT_PUBLIC_API(GccLocationI) +GccFunctionI_GetStart(GccFunctionI func) +{ + return GccPrivate_make_LocationI(func.inner->function_start_locus); +} + +GCC_IMPLEMENT_PUBLIC_API(GccLocationI) +GccFunctionI_GetEnd(GccFunctionI func) +{ + return GccPrivate_make_LocationI(func.inner->function_end_locus); +} + +GCC_IMPLEMENT_PUBLIC_API(GccFunctionI) +Gcc_GetCurrentFunction(void) +{ + return GccPrivate_make_FunctionI(cfun); +} + + +/* + PEP-7 +Local variables: +c-basic-offset: 4 +indent-tabs-mode: nil +End: +*/ diff --git a/proposed-plugin-api/gcc-function.h b/proposed-plugin-api/gcc-function.h new file mode 100644 index 0000000..606b535 --- /dev/null +++ b/proposed-plugin-api/gcc-function.h @@ -0,0 +1,49 @@ +/* + Copyright 2012 David Malcolm dmalcolm@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" + +/* Declarations: functions */ + +/* GccFunctionI */ +GCC_PUBLIC_API(void) +GccFunctionI_MarkInUse(GccFunctionI func); + +GCC_PUBLIC_API(GccCfgI) +GccFunctionI_GetCfg(GccFunctionI func); + +GCC_PUBLIC_API(int) +GccFunctionI_GetIndex(GccFunctionI func); + +GCC_PUBLIC_API(GccLocationI) +GccFunctionI_GetStart(GccFunctionI func); + +GCC_PUBLIC_API(GccLocationI) +GccFunctionI_GetEnd(GccFunctionI func); + +GCC_PUBLIC_API(GccFunctionI) +Gcc_GetCurrentFunction(void); + +/* + PEP-7 +Local variables: +c-basic-offset: 4 +indent-tabs-mode: nil +End: +*/ diff --git a/proposed-plugin-api/gcc-public-types.h b/proposed-plugin-api/gcc-public-types.h index 007c123..6a40489 100644 --- a/proposed-plugin-api/gcc-public-types.h +++ b/proposed-plugin-api/gcc-public-types.h @@ -40,4 +40,7 @@ typedef struct GccPrinterI GccPrinterI; /* Opaque types: locations */ typedef struct GccLocationI GccLocationI;
+/* Opaque types: functions */ +typedef struct GccFunctionI GccFunctionI; + #endif /* INCLUDED__GCC_PUBLIC_TYPES_H */ diff --git a/proposed-plugin-api/gcc-semiprivate-types.h b/proposed-plugin-api/gcc-semiprivate-types.h index c94e86c..d59e4a4 100644 --- a/proposed-plugin-api/gcc-semiprivate-types.h +++ b/proposed-plugin-api/gcc-semiprivate-types.h @@ -89,5 +89,13 @@ struct GccLocationI { GCC_PRIVATE_API(struct GccLocationI) GccPrivate_make_LocationI(location_t inner);
+/* Semiprivate types: functions */ +struct GccFunctionI { + struct function *inner; +}; + +GCC_PRIVATE_API(struct GccFunctionI) +GccPrivate_make_FunctionI(struct function *inner); +
#endif /* INCLUDED__GCC_SEMIPRIVATE_TYPES_H */
gcc-python-plugin-commits@lists.stg.fedorahosted.org