|
View:
New views
15 Messages
—
Rating Filter:
Alert me
|
|
|
adding PLUGIN_REGISTER_PRAGMA [& PLUGIN_PARSED_UNIT?]Hello All,
See the http://gcc.gnu.org/ml/gcc/2009-10/msg00547.html thread for motivation about PLUGIN_REGISTER_PRAGMA and Ian Taylor's reply on http://gcc.gnu.org/ml/gcc/2009-10/msg00552.html By the way, the name PLUGIN_REGISTER_PRAGMA might be not very well chosed, since it does not register anything [like PLUGIN_REGISTER_GGC_ROOTS does], but allow plugin to do pragma registrations. Maybe we should change it to PLUGIN_PRAGMA_REGISTRATION? Not being a native english speaker, I won't decide that alone. What do other people think? I am also adding the PLUGIN_PARSED_UNIT event in the same patch. Maybe I should remove that. My fuzzy motivation is to allow plugin to do something when all the compilation unit has been parsed, but not much else has been done. Imagine a company policy requiring that every *.c has a static const copyright[] = "...." string. Won't that be the easiest place to check such a crazy requirement inside a plugin? Also, perhaps G.Marpons coding rule checking would fit best at that place (but I am not sure, not knowing well the implementation of his work) See http://ols.fedoraproject.org/GCC/Reprints-2008/marpons-reprint.pdf gcc/ChangeLog is attached, with the patch to trunk r153600. Comments are welcome. I am bootstrapping that patch. The stage1 did build its xgcc. Stage2 is running right now. Regards. -- Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359 8, rue de la Faiencerie, 92340 Bourg La Reine, France *** opinions {are only mines, sont seulement les miennes} *** Index: gcc/doc/plugins.texi =================================================================== --- gcc/doc/plugins.texi (revision 153603) +++ gcc/doc/plugins.texi (working copy) @@ -136,6 +136,9 @@ enum plugin_event PLUGIN_REGISTER_GGC_CACHES, /* Register an extra GGC cache table. */ PLUGIN_ATTRIBUTES, /* Called during attribute registration */ PLUGIN_START_UNIT, /* Called before processing a translation unit. */ + PLUGIN_PARSED_UNIT, /* Called after a translation unit has + been parsed. */ + PLUGIN_REGISTER_PRAGMA, /* Called to allow pragma registration. */ PLUGIN_EVENT_LAST /* Dummy event used for indexing callback array. */ @}; @@ -156,6 +159,11 @@ For the PLUGIN_PASS_MANAGER_SETUP, PLUGIN_INFO, PL and PLUGIN_REGISTER_GGC_CACHES pseudo-events the @code{callback} should be null, and the @code{user_data} is specific. +When the PLUGIN_REGISTER_PRAGMA event is triggered (with a null +pointer as data from GCC), plugins may register their own pragmas +using functions like @code{c_register_pragma} or +@code{c_register_pragma_with_expansion}. + @section Interacting with the pass manager There needs to be a way to add/reorder/remove passes dynamically. This Index: gcc/cgraphunit.c =================================================================== --- gcc/cgraphunit.c (revision 153603) +++ gcc/cgraphunit.c (working copy) @@ -135,6 +135,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-dump.h" #include "output.h" #include "coverage.h" +#include "plugin.h" static void cgraph_expand_all_functions (void); static void cgraph_mark_functions_to_output (void); @@ -1052,6 +1053,9 @@ cgraph_finalize_compilation_unit (void) { timevar_push (TV_CGRAPH); + /* Invoke registered plugin callbacks. */ + invoke_plugin_callbacks (PLUGIN_PARSED_UNIT, NULL); + /* Do not skip analyzing the functions if there were errors, we miss diagnostics for following functions otherwise. */ Index: gcc/c-pragma.c =================================================================== --- gcc/c-pragma.c (revision 153603) +++ gcc/c-pragma.c (working copy) @@ -37,6 +37,7 @@ along with GCC; see the file COPYING3. If not see #include "target.h" #include "diagnostic.h" #include "opts.h" +#include "plugin.h" #define GCC_BAD(gmsgid) \ do { warning (OPT_Wpragmas, gmsgid); return; } while (0) @@ -1444,6 +1445,9 @@ init_pragma (void) #ifdef REGISTER_TARGET_PRAGMAS REGISTER_TARGET_PRAGMAS (); #endif + + /* Allow plugins to register their pragmas. */ + invoke_plugin_callbacks (PLUGIN_REGISTER_PRAGMA, NULL); } #include "gt-c-pragma.h" Index: gcc/gcc-plugin.h =================================================================== --- gcc/gcc-plugin.h (revision 153603) +++ gcc/gcc-plugin.h (working copy) @@ -43,6 +43,9 @@ enum plugin_event PLUGIN_REGISTER_GGC_CACHES, /* Register an extra GGC cache table. */ PLUGIN_ATTRIBUTES, /* Called during attribute registration. */ PLUGIN_START_UNIT, /* Called before processing a translation unit. */ + PLUGIN_PARSED_UNIT, /* Called after a translation unit has + been parsed. */ + PLUGIN_REGISTER_PRAGMA, /* Called to allow pragma registration. */ PLUGIN_EVENT_LAST /* Dummy event used for indexing callback array. */ }; Index: gcc/plugin.c =================================================================== --- gcc/plugin.c (revision 153603) +++ gcc/plugin.c (working copy) @@ -58,7 +58,9 @@ const char *plugin_event_name[] = "PLUGIN_GGC_END", "PLUGIN_REGISTER_GGC_ROOTS", "PLUGIN_REGISTER_GGC_CACHES", - "PLUGIN_START_UNIT", + "PLUGIN_START_UNIT", + "PLUGIN_PARSED_UNIT", + "PLUGIN_REGISTER_PRAGMA", "PLUGIN_EVENT_LAST" }; @@ -365,6 +367,7 @@ invoke_plugin_callbacks (enum plugin_event event, { case PLUGIN_FINISH_TYPE: case PLUGIN_START_UNIT: + case PLUGIN_PARSED_UNIT: case PLUGIN_FINISH_UNIT: case PLUGIN_CXX_CP_PRE_GENERICIZE: case PLUGIN_ATTRIBUTES: @@ -372,6 +375,7 @@ invoke_plugin_callbacks (enum plugin_event event, case PLUGIN_GGC_START: case PLUGIN_GGC_MARKING: case PLUGIN_GGC_END: + case PLUGIN_REGISTER_PRAGMA: { /* Iterate over every callback registered with this event and call it. */ Index: gcc/Makefile.in =================================================================== --- gcc/Makefile.in (revision 153603) +++ gcc/Makefile.in (working copy) @@ -1982,7 +1982,7 @@ c-convert.o : c-convert.c $(CONFIG_H) $(SYSTEM_H) c-pragma.o: c-pragma.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \ $(TREE_H) $(FUNCTION_H) $(C_PRAGMA_H) $(TOPLEV_H) output.h $(GGC_H) $(TM_P_H) \ $(C_COMMON_H) $(TARGET_H) gt-c-pragma.h $(CPPLIB_H) $(FLAGS_H) $(DIAGNOSTIC_H) \ - opts.h + opts.h $(PLUGINS_H) graph.o: graph.c $(SYSTEM_H) coretypes.h $(TM_H) $(TOPLEV_H) $(FLAGS_H) output.h \ $(RTL_H) $(FUNCTION_H) hard-reg-set.h $(BASIC_BLOCK_H) graph.h $(OBSTACK_H) \ $(CONFIG_H) @@ -2855,7 +2855,7 @@ cgraphunit.o : cgraphunit.c $(CONFIG_H) $(SYSTEM_H $(TARGET_H) $(CGRAPH_H) intl.h pointer-set.h $(FUNCTION_H) $(GIMPLE_H) \ $(TREE_FLOW_H) $(TREE_PASS_H) debug.h $(DIAGNOSTIC_H) \ $(FIBHEAP_H) output.h $(PARAMS_H) $(RTL_H) $(TIMEVAR_H) $(IPA_PROP_H) \ - gt-cgraphunit.h tree-iterator.h $(COVERAGE_H) $(TREE_DUMP_H) + gt-cgraphunit.h tree-iterator.h $(COVERAGE_H) $(TREE_DUMP_H) $(PLUGIN_H) cgraphbuild.o : cgraphbuild.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ $(TREE_H) langhooks.h $(CGRAPH_H) intl.h pointer-set.h $(GIMPLE_H) \ $(TREE_FLOW_H) $(TREE_PASS_H) @@ -4524,7 +4524,7 @@ install-collect2: collect2 installdirs # Install lto-wrapper. install-lto-wrapper: lto-wrapper$(exeext) $(INSTALL_PROGRAM) lto-wrapper$(exeext) $(DESTDIR)$(libexecsubdir)/lto-wrapper$(exeext) - + # Cancel installation by deleting the installed files. uninstall: lang.uninstall -rm -rf $(DESTDIR)$(libsubdir) 2009-10-27 Basile Starynkevitch <basile@...> * doc/plugins.texi (Plugin callbacks): Documented PLUGIN_PARSED_UNIT & PLUGIN_REGISTER_PRAGMA. * cgraphunit.c: Added "plugin.h" inclusion. (cgraph_finalize_compilation_unit) Added stuff for PLUGIN_PARSED_UNIT. * c-pragma.c: Added "plugin.h" inclusion. (init_pragma): Run the PLUGIN_REGISTER_PRAGMA plugin stuff. * gcc-plugin.h (enum plugin_event): Added PLUGIN_PARSED_UNIT & PLUGIN_REGISTER_PRAGMA. * gcc-plugin.c (plugin_event_name): Likewise. * Makefile.in (c-pragma.o): added plugin.h dependency. (cgraphunit.o): likewise. Removed tab-only line before uninstall. Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359 8, rue de la Faiencerie, 92340 Bourg La Reine, France *** opinions {are only mines, sont seulement les miennes} *** |
|
|
Re: adding PLUGIN_REGISTER_PRAGMA [& PLUGIN_PARSED_UNIT?]> I am also adding the PLUGIN_PARSED_UNIT event in the same patch. Maybe I
> should remove that. My fuzzy motivation is to allow plugin to do something > when all the compilation unit has been parsed, but not much else has been > done. Imagine a company policy requiring that every *.c has a static const > copyright[] = "...." string. Won't that be the easiest place to check such a > crazy requirement inside a plugin? Also, perhaps G.Marpons coding rule > checking would fit best at that place (but I am not sure, not knowing well > the implementation of his work) See > http://ols.fedoraproject.org/GCC/Reprints-2008/marpons-reprint.pdf Sorry for taking so long, was very busy. Would you mind splitting the patch in 2? One for pargma one for parsed_unit. This part about pragmas is very similar to what we have for attributes. Maybe it should use the same style? Something like PLUGIN_PRAGMAS, /* Called during pragma registration. */ Can you add a small testcase.? > Regards. > > -- > Basile STARYNKEVITCH http://starynkevitch.net/Basile/ > email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359 > 8, rue de la Faiencerie, 92340 Bourg La Reine, France > *** opinions {are only mines, sont seulement les miennes} *** Cheers, -- Rafael Ávila de Espíndola |
|
|
PLUGIN_PRAGMAS eventHello All
The attached patch to trunk rev 152931 adds a PLUGIN_PRAGMAS event. See http://gcc.gnu.org/ml/gcc-patches/2009-11/msg00197.html Rafael Espindola wrote: > > Would you mind splitting the patch in 2? One for pargma one for parsed_unit. > > This part about pragmas is very similar to what we have for > attributes. Maybe it should use the same style? Something like > > PLUGIN_PRAGMAS, /* Called during pragma registration. */ > > Can you add a small testcase.? I did add a small testcase, but since I am running the make bootstrap I did not run the testcase yet. Is it enough or not? Assuming the attached patch bootstraps & the test runs ok, can I commit it [this evening or tomorrow]. Otherwise comments are welcome. #### gcc/ChangeLog 2009-11-05 Basile Starynkevitch <basile@...> * doc/plugins.texi (Plugin callbacks): added PLUGIN_PRAGMAS. * testsuite/g++.dg/plugin/pragma_plugin-test-1.C: new testcase for PLUGIN_PRAGMAS. * testsuite/g++.dg/plugin/pragma_plugin.c: new test plugin for PLUGIN_PRAGMAS. * c-pragma.c: Include "plugin.h". (init_pragma): Invoke PLUGIN_PRAGMAS. * gcc-plugin.h: Added PLUGIN_PRAGMAS. * plugin.c: Added PLUGIN_PRAGMAS. * Makefile.in (c-pragma.o): Added dependency upon plugin.h. (PLUGIN_HEADERS): added plugin.h. #### I am bootstrapping it (x86_64-unknown-linux; Debian/Sid/AMD64; with C & C++) and I did not yet run the added test. Regards -- Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359 8, rue de la Faiencerie, 92340 Bourg La Reine, France *** opinions {are only mines, sont seulement les miennes} *** Index: gcc/doc/plugins.texi =================================================================== --- gcc/doc/plugins.texi (revision 153931) +++ gcc/doc/plugins.texi (working copy) @@ -136,6 +136,7 @@ enum plugin_event PLUGIN_REGISTER_GGC_CACHES, /* Register an extra GGC cache table. */ PLUGIN_ATTRIBUTES, /* Called during attribute registration */ PLUGIN_START_UNIT, /* Called before processing a translation unit. */ + PLUGIN_PRAGMAS, /* Called during pragma registration. */ PLUGIN_EVENT_LAST /* Dummy event used for indexing callback array. */ @}; @@ -156,6 +157,11 @@ For the PLUGIN_PASS_MANAGER_SETUP, PLUGIN_INFO, PL and PLUGIN_REGISTER_GGC_CACHES pseudo-events the @code{callback} should be null, and the @code{user_data} is specific. +When the PLUGIN_PRAGMAS event is triggered (with a null +pointer as data from GCC), plugins may register their own pragmas +using functions like @code{c_register_pragma} or +@code{c_register_pragma_with_expansion}. + @section Interacting with the pass manager There needs to be a way to add/reorder/remove passes dynamically. This Index: gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C =================================================================== --- gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C (revision 0) +++ gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C (revision 0) @@ -0,0 +1,21 @@ +// { dg-warning "Callback to register pragmas" "" { target *-*-* } 0 } + +void some_func (int c); + +#pragma GCCPLUGIN sayhello "here" + +// { dg-warning "pragma GCCPLUGIN sayhello outside of function: here" } + +void some_func (const char* s) +{ +#pragma GCCPLUGIN sayhello "at start" +// { dg-warning "pragma GCCPLUGIN sayhello from function 'some_func': at start" } +#define DO_PRAGMA(x) _Pragma(#x) + if (!s) + { + DO_PRAGMA(GCCPLUGIN sayhello "in block"); +// { dg-warning "pragma GCCPLUGIN sayhello from function 'some_func': in block" } + abort (); + } +} + Index: gcc/testsuite/g++.dg/plugin/pragma_plugin.c =================================================================== --- gcc/testsuite/g++.dg/plugin/pragma_plugin.c (revision 0) +++ gcc/testsuite/g++.dg/plugin/pragma_plugin.c (revision 0) @@ -0,0 +1,55 @@ +/* Demonstrates how to add custom pragmas */ + +#include "gcc-plugin.h" +#include <stdlib.h> +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tree.h" +#include "tree-pass.h" +#include "intl.h" + +int plugin_is_GPL_compatible; + + +/* handler of #pragma GCCPLUGIN sayhello "message" is quite similar to + handler of #pragma GCC message...*/ + +static void +handle_pragma_sayhello (cpp_reader *dummy) +{ + tree message = 0; + if (pragma_lex (&message) != CPP_STRING) + { + GCC_BAD ("%<#pragma GCCPLUGIN sayhello%> is not a string"); + return; + } + if (TREE_STRING_LENGTH (message) > 1) + if (cfun) + inform (input_location, + "#pragma GCCPLUGIN sayhello from function %qE: %s", + cfun->decl, TREE_STRING_POINTER (message)); + else + inform (input_location, + "#pragma GCCPLUGIN sayhello outside of function: %s", + TREE_STRING_POINTER (message)); +} + +/* Plugin callback called during pragma registration */ + +static void +pragma_attributes (void *event_data, void *data) +{ + warning (0, G_("Callback to register pragmas")); + c_register_pragma ("GCCPLUGIN", "sayhello", handle_pragma_sayhello); +} + +int +plugin_init (struct plugin_name_args *plugin_info, + struct plugin_gcc_version *version) +{ + const char *plugin_name = plugin_info->base_name; + + register_callback (plugin_name, PLUGIN_PRAGMAS, register_pragmas, NULL); + return 0; +} Index: gcc/testsuite/g++.dg/plugin/plugin.exp =================================================================== --- gcc/testsuite/g++.dg/plugin/plugin.exp (revision 153931) +++ gcc/testsuite/g++.dg/plugin/plugin.exp (working copy) @@ -48,6 +48,7 @@ load_lib plugin-support.exp # plugin_test_list={ {plugin1 test1 test2 ...} {plugin2 test1 ...} ... } set plugin_test_list [list \ { attribute_plugin.c attribute_plugin-test-1.C } \ + { pragma_plugin.c pragma_plugin-test-1.C } \ { selfassign.c self-assign-test-1.C self-assign-test-2.C self-assign-test-3.C } \ { dumb_plugin.c dumb-plugin-test-1.C } \ { header_plugin.c header-plugin-test.C } ] Index: gcc/c-pragma.c =================================================================== --- gcc/c-pragma.c (revision 153931) +++ gcc/c-pragma.c (working copy) @@ -37,6 +37,7 @@ along with GCC; see the file COPYING3. If not see #include "target.h" #include "diagnostic.h" #include "opts.h" +#include "plugin.h" #define GCC_BAD(gmsgid) \ do { warning (OPT_Wpragmas, gmsgid); return; } while (0) @@ -1450,6 +1451,9 @@ init_pragma (void) #ifdef REGISTER_TARGET_PRAGMAS REGISTER_TARGET_PRAGMAS (); #endif + + /* Allow plugins to register their own pragmas. */ + invoke_plugin_callbacks (PLUGIN_PRAGMAS, NULL); } #include "gt-c-pragma.h" Index: gcc/gcc-plugin.h =================================================================== --- gcc/gcc-plugin.h (revision 153931) +++ gcc/gcc-plugin.h (working copy) @@ -43,6 +43,7 @@ enum plugin_event PLUGIN_REGISTER_GGC_CACHES, /* Register an extra GGC cache table. */ PLUGIN_ATTRIBUTES, /* Called during attribute registration. */ PLUGIN_START_UNIT, /* Called before processing a translation unit. */ + PLUGIN_PRAGMAS, /* Called during pragma registration. */ PLUGIN_EVENT_LAST /* Dummy event used for indexing callback array. */ }; Index: gcc/plugin.c =================================================================== --- gcc/plugin.c (revision 153931) +++ gcc/plugin.c (working copy) @@ -58,7 +58,9 @@ const char *plugin_event_name[] = "PLUGIN_GGC_END", "PLUGIN_REGISTER_GGC_ROOTS", "PLUGIN_REGISTER_GGC_CACHES", - "PLUGIN_START_UNIT", + "PLUGIN_ATTRIBUTES", + "PLUGIN_START_UNIT", + "PLUGIN_PRAGMAS", "PLUGIN_EVENT_LAST" }; @@ -372,6 +374,7 @@ invoke_plugin_callbacks (enum plugin_event event, case PLUGIN_GGC_START: case PLUGIN_GGC_MARKING: case PLUGIN_GGC_END: + case PLUGIN_PRAGMAS: { /* Iterate over every callback registered with this event and call it. */ Index: gcc/Makefile.in =================================================================== --- gcc/Makefile.in (revision 153931) +++ gcc/Makefile.in (working copy) @@ -1982,7 +1982,7 @@ c-convert.o : c-convert.c $(CONFIG_H) $(SYSTEM_H) c-pragma.o: c-pragma.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \ $(TREE_H) $(FUNCTION_H) $(C_PRAGMA_H) $(TOPLEV_H) output.h $(GGC_H) $(TM_P_H) \ $(C_COMMON_H) $(TARGET_H) gt-c-pragma.h $(CPPLIB_H) $(FLAGS_H) $(DIAGNOSTIC_H) \ - opts.h + opts.h $(PLUGINS_H) graph.o: graph.c $(SYSTEM_H) coretypes.h $(TM_H) $(TOPLEV_H) $(FLAGS_H) output.h \ $(RTL_H) $(FUNCTION_H) hard-reg-set.h $(BASIC_BLOCK_H) graph.h $(OBSTACK_H) \ $(CONFIG_H) @@ -4260,7 +4260,7 @@ PLUGIN_HEADERS = $(TREE_H) $(CONFIG_H) $(SYSTEM_H) $(host_xm_file_list) $(host_xm_include_list) $(xm_include_list) \ intl.h $(PLUGIN_VERSION_H) $(DIAGNOSTIC_H) $(C_COMMON_H) $(C_PRETTY_PRINT_H) \ tree-iterator.h $(PLUGIN_H) $(TREE_FLOW_H) langhooks.h incpath.h \ - tree-ssa-sccvn.h real.h output.h $(IPA_UTILS_H) + tree-ssa-sccvn.h real.h output.h $(IPA_UTILS_H) $(C_PRAGMA_H) # Install the headers needed to build a plugin. install-plugin: installdirs lang.install-plugin @@ -4524,7 +4524,7 @@ install-collect2: collect2 installdirs # Install lto-wrapper. install-lto-wrapper: lto-wrapper$(exeext) $(INSTALL_PROGRAM) lto-wrapper$(exeext) $(DESTDIR)$(libexecsubdir)/lto-wrapper$(exeext) - + # Cancel installation by deleting the installed files. uninstall: lang.uninstall -rm -rf $(DESTDIR)$(libsubdir) Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359 8, rue de la Faiencerie, 92340 Bourg La Reine, France *** opinions {are only mines, sont seulement les miennes} *** |
|
|
Re: PLUGIN_PRAGMAS eventBasile STARYNKEVITCH wrote:
> Hello All > > > The attached patch to trunk rev 152931 adds a PLUGIN_PRAGMAS event. > > See http://gcc.gnu.org/ml/gcc-patches/2009-11/msg00197.html > I did add a small testcase, but since I am running the make bootstrap I > did not run the testcase yet. Is it enough or not? > > I am bootstrapping it (x86_64-unknown-linux; Debian/Sid/AMD64; with C & > C++) and I did not yet run the added test. The test was buggy, pragma_plugin.c did not compile & the patch was buggy. #### gcc/ChangeLog 2009-11-05 Basile Starynkevitch <basile@...> * doc/plugins.texi (Plugin callbacks): added PLUGIN_PRAGMAS. * testsuite/g++.dg/plugin/pragma_plugin-test-1.C: new testcase for PLUGIN_PRAGMAS. * testsuite/g++.dg/plugin/pragma_plugin.c: new test plugin for PLUGIN_PRAGMAS. * c-pragma.c: Include "plugin.h". (init_pragma): Invoke PLUGIN_PRAGMAS. * gcc-plugin.h: Added PLUGIN_PRAGMAS. * plugin.c (plugin_event_names, register_callbacks): Added PLUGIN_PRAGMAS. * Makefile.in (c-pragma.o): Added dependency upon plugin.h. (PLUGIN_HEADERS): added c-pragma.h & function.h #### The attached improved patch is still imperfect, because I don't understand the syntax for getting notes in testsuite. However, the test does run as expected, handling appropriately my new pragma GCCPLUGIN sayhello - which is very similar to the existing pragma GCC message... Could someone help me with the dejagnu comments in the test please? Regards. -- Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359 8, rue de la Faiencerie, 92340 Bourg La Reine, France *** opinions {are only mines, sont seulement les miennes} *** Index: gcc/doc/plugins.texi =================================================================== --- gcc/doc/plugins.texi (revision 153931) +++ gcc/doc/plugins.texi (working copy) @@ -136,6 +136,7 @@ enum plugin_event PLUGIN_REGISTER_GGC_CACHES, /* Register an extra GGC cache table. */ PLUGIN_ATTRIBUTES, /* Called during attribute registration */ PLUGIN_START_UNIT, /* Called before processing a translation unit. */ + PLUGIN_PRAGMAS, /* Called during pragma registration. */ PLUGIN_EVENT_LAST /* Dummy event used for indexing callback array. */ @}; @@ -156,6 +157,11 @@ For the PLUGIN_PASS_MANAGER_SETUP, PLUGIN_INFO, PL and PLUGIN_REGISTER_GGC_CACHES pseudo-events the @code{callback} should be null, and the @code{user_data} is specific. +When the PLUGIN_PRAGMAS event is triggered (with a null +pointer as data from GCC), plugins may register their own pragmas +using functions like @code{c_register_pragma} or +@code{c_register_pragma_with_expansion}. + @section Interacting with the pass manager There needs to be a way to add/reorder/remove passes dynamically. This Index: gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C =================================================================== --- gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C (revision 0) +++ gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C (revision 0) @@ -0,0 +1,21 @@ +// { dg-warning "Callback to register pragmas" "" { target *-*-* } 0 } + +void some_func (int c); + +#pragma GCCPLUGIN sayhello "here" + +// { dg-warning "pragma GCCPLUGIN sayhello outside of function: here" } + +void some_func (const char* s) +{ +#pragma GCCPLUGIN sayhello "at start" +// { dg-warning "pragma GCCPLUGIN sayhello from function 'some_func': at start" } +#define DO_PRAGMA(x) _Pragma(#x) + if (!s) + { + DO_PRAGMA(GCCPLUGIN sayhello "in block"); +// { dg-warning "pragma GCCPLUGIN sayhello from function 'some_func': in block" } + abort (); + } +} + Index: gcc/testsuite/g++.dg/plugin/pragma_plugin.c =================================================================== --- gcc/testsuite/g++.dg/plugin/pragma_plugin.c (revision 0) +++ gcc/testsuite/g++.dg/plugin/pragma_plugin.c (revision 0) @@ -0,0 +1,60 @@ +/* Demonstrates how to add custom pragmas */ + +#include "gcc-plugin.h" +#include <stdlib.h> +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tm.h" +#include "rtl.h" +#include "tree.h" +#include "function.h" +#include "c-pragma.h" +#include "cpplib.h" +#include "tree-pass.h" +#include "intl.h" + +int plugin_is_GPL_compatible; + + +/* handler of #pragma GCCPLUGIN sayhello "message" is quite similar to + handler of #pragma GCC message...*/ + +static void +handle_pragma_sayhello (cpp_reader *dummy) +{ + tree message = 0; + if (pragma_lex (&message) != CPP_STRING) + { + warning (OPT_Wpragmas, "%<#pragma GCCPLUGIN sayhello%> is not a string"); + return; + } + if (TREE_STRING_LENGTH (message) > 1) + if (cfun) + inform (input_location, + "#pragma GCCPLUGIN sayhello from function %qE: %s", + cfun->decl, TREE_STRING_POINTER (message)); + else + inform (input_location, + "#pragma GCCPLUGIN sayhello outside of function: %s", + TREE_STRING_POINTER (message)); +} + +/* Plugin callback called during pragma registration */ + +static void +register_my_pragma (void *event_data, void *data) +{ + warning (0, G_("Callback to register pragmas")); + c_register_pragma ("GCCPLUGIN", "sayhello", handle_pragma_sayhello); +} + +int +plugin_init (struct plugin_name_args *plugin_info, + struct plugin_gcc_version *version) +{ + const char *plugin_name = plugin_info->base_name; + + register_callback (plugin_name, PLUGIN_PRAGMAS, register_my_pragma, NULL); + return 0; +} Index: gcc/testsuite/g++.dg/plugin/plugin.exp =================================================================== --- gcc/testsuite/g++.dg/plugin/plugin.exp (revision 153931) +++ gcc/testsuite/g++.dg/plugin/plugin.exp (working copy) @@ -48,6 +48,7 @@ load_lib plugin-support.exp # plugin_test_list={ {plugin1 test1 test2 ...} {plugin2 test1 ...} ... } set plugin_test_list [list \ { attribute_plugin.c attribute_plugin-test-1.C } \ + { pragma_plugin.c pragma_plugin-test-1.C } \ { selfassign.c self-assign-test-1.C self-assign-test-2.C self-assign-test-3.C } \ { dumb_plugin.c dumb-plugin-test-1.C } \ { header_plugin.c header-plugin-test.C } ] Index: gcc/c-pragma.c =================================================================== --- gcc/c-pragma.c (revision 153931) +++ gcc/c-pragma.c (working copy) @@ -37,6 +37,7 @@ along with GCC; see the file COPYING3. If not see #include "target.h" #include "diagnostic.h" #include "opts.h" +#include "plugin.h" #define GCC_BAD(gmsgid) \ do { warning (OPT_Wpragmas, gmsgid); return; } while (0) @@ -1450,6 +1451,9 @@ init_pragma (void) #ifdef REGISTER_TARGET_PRAGMAS REGISTER_TARGET_PRAGMAS (); #endif + + /* Allow plugins to register their own pragmas. */ + invoke_plugin_callbacks (PLUGIN_PRAGMAS, NULL); } #include "gt-c-pragma.h" Index: gcc/gcc-plugin.h =================================================================== --- gcc/gcc-plugin.h (revision 153931) +++ gcc/gcc-plugin.h (working copy) @@ -43,6 +43,7 @@ enum plugin_event PLUGIN_REGISTER_GGC_CACHES, /* Register an extra GGC cache table. */ PLUGIN_ATTRIBUTES, /* Called during attribute registration. */ PLUGIN_START_UNIT, /* Called before processing a translation unit. */ + PLUGIN_PRAGMAS, /* Called during pragma registration. */ PLUGIN_EVENT_LAST /* Dummy event used for indexing callback array. */ }; Index: gcc/plugin.c =================================================================== --- gcc/plugin.c (revision 153931) +++ gcc/plugin.c (working copy) @@ -58,7 +58,9 @@ const char *plugin_event_name[] = "PLUGIN_GGC_END", "PLUGIN_REGISTER_GGC_ROOTS", "PLUGIN_REGISTER_GGC_CACHES", - "PLUGIN_START_UNIT", + "PLUGIN_ATTRIBUTES", + "PLUGIN_START_UNIT", + "PLUGIN_PRAGMAS", "PLUGIN_EVENT_LAST" }; @@ -325,6 +327,7 @@ register_callback (const char *plugin_name, case PLUGIN_GGC_MARKING: case PLUGIN_GGC_END: case PLUGIN_ATTRIBUTES: + case PLUGIN_PRAGMAS: case PLUGIN_FINISH: { struct callback_info *new_callback; @@ -372,6 +375,7 @@ invoke_plugin_callbacks (enum plugin_event event, case PLUGIN_GGC_START: case PLUGIN_GGC_MARKING: case PLUGIN_GGC_END: + case PLUGIN_PRAGMAS: { /* Iterate over every callback registered with this event and call it. */ Index: gcc/Makefile.in =================================================================== --- gcc/Makefile.in (revision 153931) +++ gcc/Makefile.in (working copy) @@ -1982,7 +1982,7 @@ c-convert.o : c-convert.c $(CONFIG_H) $(SYSTEM_H) c-pragma.o: c-pragma.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \ $(TREE_H) $(FUNCTION_H) $(C_PRAGMA_H) $(TOPLEV_H) output.h $(GGC_H) $(TM_P_H) \ $(C_COMMON_H) $(TARGET_H) gt-c-pragma.h $(CPPLIB_H) $(FLAGS_H) $(DIAGNOSTIC_H) \ - opts.h + opts.h $(PLUGINS_H) graph.o: graph.c $(SYSTEM_H) coretypes.h $(TM_H) $(TOPLEV_H) $(FLAGS_H) output.h \ $(RTL_H) $(FUNCTION_H) hard-reg-set.h $(BASIC_BLOCK_H) graph.h $(OBSTACK_H) \ $(CONFIG_H) @@ -4260,7 +4260,8 @@ PLUGIN_HEADERS = $(TREE_H) $(CONFIG_H) $(SYSTEM_H) $(host_xm_file_list) $(host_xm_include_list) $(xm_include_list) \ intl.h $(PLUGIN_VERSION_H) $(DIAGNOSTIC_H) $(C_COMMON_H) $(C_PRETTY_PRINT_H) \ tree-iterator.h $(PLUGIN_H) $(TREE_FLOW_H) langhooks.h incpath.h \ - tree-ssa-sccvn.h real.h output.h $(IPA_UTILS_H) + tree-ssa-sccvn.h real.h output.h $(IPA_UTILS_H) \ + $(C_PRAGMA_H) $(CPPLIB_H) $(FUNCTION_H) # Install the headers needed to build a plugin. install-plugin: installdirs lang.install-plugin @@ -4524,7 +4525,7 @@ install-collect2: collect2 installdirs # Install lto-wrapper. install-lto-wrapper: lto-wrapper$(exeext) $(INSTALL_PROGRAM) lto-wrapper$(exeext) $(DESTDIR)$(libexecsubdir)/lto-wrapper$(exeext) - + # Cancel installation by deleting the installed files. uninstall: lang.uninstall -rm -rf $(DESTDIR)$(libsubdir) Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359 8, rue de la Faiencerie, 92340 Bourg La Reine, France *** opinions {are only mines, sont seulement les miennes} *** |
|
|
Re: PLUGIN_PRAGMAS event> The attached improved patch is still imperfect, because I don't understand
> the syntax for getting notes in testsuite. > > However, the test does run as expected, handling appropriately my new pragma > GCCPLUGIN sayhello - which is very similar to the existing pragma GCC > message... > > Could someone help me with the dejagnu comments in the test please? The patch still has PLUGIN_START_UNIT in plugin.c The test fails with: error: 'abort' was not declared in this scope Diego, can you review the rest of the test? > Regards. > -- > Basile STARYNKEVITCH http://starynkevitch.net/Basile/ > email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359 > 8, rue de la Faiencerie, 92340 Bourg La Reine, France > *** opinions {are only mines, sont seulement les miennes} *** > Cheers, -- Rafael Ávila de Espíndola |
|
|
Re: PLUGIN_PRAGMAS eventHello All
A big thanks to Rafael & Diego for their help. Rafael Espindola wrote: > > The patch still has PLUGIN_START_UNIT in plugin.c PLUGIN_START_UNIT seems to already be in the trunk rev 153950. I believe it was added by somebody else, and I strongly believe it should not be removed (that is, all plugin events should be kept). And the string "PLUGIN_ATTRIBUTES" seems to be missing in its plugin.c; I am correcting that also in the submitted patch here. I tend to believe that we should have a plugin-events.def file containing the list of events like PLUGIN_EVENT(PLUGIN_PASS_MANAGER_SETUP) PLUGIN_EVENT(PLUGIN_FINISH_TYPE) PLUGIN_EVENT(PLUGIN_FINISH_UNIT) and include it with various #define of PLUGIN_EVENT both in gcc-plugin.h & plugin.c. We could even generate some part of plugins.texi but I won't propose such a patch if people are not interested. Perhaps we should sort alphabetically the list of events there. There is also a typo in the error message when the callback event is unknown. Back to PLUGIN_PRAGMAS. > > The test fails with: > error: 'abort' was not declared in this scope I removed the use of abort. I tried to reproduce the dg comments from other tests, but which the plugin_pragma.c does work as expected, the comments in gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C are not making dejagnu happy. Unfortunately I never understood dejagnu. But when the pragma_plugin.so is loaded, it works as I expect: /usr/src/Lang/gcc-trunk-bstarynk/gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C:5:28: warning: 'pragma GCCPLUGIN sayhello' outside of function: here /usr/src/Lang/gcc-trunk-bstarynk/gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C: In function 'int some_func(const char*)': /usr/src/Lang/gcc-trunk-bstarynk/gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C:11:28: warning: 'pragma GCCPLUGIN sayhello' from function 'some_func': at start /usr/src/Lang/gcc-trunk-bstarynk/gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C:16:20: warning: 'pragma GCCPLUGIN sayhello' from function 'some_func': in block What are the comments needed in pragma_plugin-test-1.C to make dejagnu happy? I am attaching a patch to rev 153950 of trunk The gcc/ChangeLog is #### 2009-11-05 Basile Starynkevitch <basile@...> * doc/plugins.texi (Plugin callbacks): added PLUGIN_PRAGMAS. * testsuite/g++.dg/plugin/pragma_plugin-test-1.C: new testcase for PLUGIN_PRAGMAS. * testsuite/g++.dg/plugin/pragma_plugin.c: new test plugin for PLUGIN_PRAGMAS. * c-pragma.c: Include "plugin.h". (init_pragma): Invoke PLUGIN_PRAGMAS. * gcc-plugin.h: Added PLUGIN_PRAGMAS. * plugin.c (plugin_event_name): Added PLUGIN_PRAGMAS & the missing PLUGIN_ATTRIBUTES. (register_callback): Added PLUGIN_PRAGMAS. Fixed typo in message error for unknown callback event. (invoke_plugin_callbacks): Added PLUGIN_PRAGMAS. * Makefile.in (c-pragma.o): Added dependency upon plugin.h. (PLUGIN_HEADERS): added plugin.h. #### Comments, and most importantly, corrections to the dejagnu comments in pragma_plugin-test-1.C are expected. Respectful regards. -- Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359 8, rue de la Faiencerie, 92340 Bourg La Reine, France *** opinions {are only mines, sont seulement les miennes} *** Index: gcc/doc/plugins.texi =================================================================== --- gcc/doc/plugins.texi (revision 153950) +++ gcc/doc/plugins.texi (working copy) @@ -136,6 +136,7 @@ enum plugin_event PLUGIN_REGISTER_GGC_CACHES, /* Register an extra GGC cache table. */ PLUGIN_ATTRIBUTES, /* Called during attribute registration */ PLUGIN_START_UNIT, /* Called before processing a translation unit. */ + PLUGIN_PRAGMAS, /* Called during pragma registration. */ PLUGIN_EVENT_LAST /* Dummy event used for indexing callback array. */ @}; @@ -156,6 +157,11 @@ For the PLUGIN_PASS_MANAGER_SETUP, PLUGIN_INFO, PL and PLUGIN_REGISTER_GGC_CACHES pseudo-events the @code{callback} should be null, and the @code{user_data} is specific. +When the PLUGIN_PRAGMAS event is triggered (with a null +pointer as data from GCC), plugins may register their own pragmas +using functions like @code{c_register_pragma} or +@code{c_register_pragma_with_expansion}. + @section Interacting with the pass manager There needs to be a way to add/reorder/remove passes dynamically. This Index: gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C =================================================================== --- gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C (revision 0) +++ gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C (revision 0) @@ -0,0 +1,22 @@ +// { dg-warning "Callback to register pragmas" "" { target *-*-* } 0 } + +int some_func (int c); + +#pragma GCCPLUGIN sayhello "here" + +// { dg-warning "pragma GCCPLUGIN sayhello outside of function: here" } + +int some_func (const char* s) +{ +#pragma GCCPLUGIN sayhello "at start" +// { dg-warning "pragma GCCPLUGIN sayhello from function 'some_func': at start" } +#define DO_PRAGMA(x) _Pragma(#x) + if (!s) + { + DO_PRAGMA(GCCPLUGIN sayhello "in block"); +// { dg-warning "pragma GCCPLUGIN sayhello from function 'some_func': in block" } + return 0; + } + return 1; +} + Index: gcc/testsuite/g++.dg/plugin/pragma_plugin.c =================================================================== --- gcc/testsuite/g++.dg/plugin/pragma_plugin.c (revision 0) +++ gcc/testsuite/g++.dg/plugin/pragma_plugin.c (revision 0) @@ -0,0 +1,60 @@ +/* Demonstrates how to add custom pragmas */ + +#include "gcc-plugin.h" +#include <stdlib.h> +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tm.h" +#include "rtl.h" +#include "tree.h" +#include "function.h" +#include "c-pragma.h" +#include "cpplib.h" +#include "tree-pass.h" +#include "intl.h" + +int plugin_is_GPL_compatible; + + +/* handler of #pragma GCCPLUGIN sayhello "message" is quite similar to + handler of #pragma GCC message...*/ + +static void +handle_pragma_sayhello (cpp_reader *dummy) +{ + tree message = 0; + if (pragma_lex (&message) != CPP_STRING) + { + warning (OPT_Wpragmas, "%<#pragma GCCPLUGIN sayhello%> is not a string"); + return; + } + if (TREE_STRING_LENGTH (message) > 1) + if (cfun) + warning (OPT_Wpragmas, + "%<pragma GCCPLUGIN sayhello%> from function %qE: %s", + cfun->decl, TREE_STRING_POINTER (message)); + else + warning (OPT_Wpragmas, + "%<pragma GCCPLUGIN sayhello%> outside of function: %s", + TREE_STRING_POINTER (message)); +} + +/* Plugin callback called during pragma registration */ + +static void +register_my_pragma (void *event_data, void *data) +{ + warning (0, G_("Callback to register pragmas")); + c_register_pragma ("GCCPLUGIN", "sayhello", handle_pragma_sayhello); +} + +int +plugin_init (struct plugin_name_args *plugin_info, + struct plugin_gcc_version *version) +{ + const char *plugin_name = plugin_info->base_name; + + register_callback (plugin_name, PLUGIN_PRAGMAS, register_my_pragma, NULL); + return 0; +} Index: gcc/testsuite/g++.dg/plugin/plugin.exp =================================================================== --- gcc/testsuite/g++.dg/plugin/plugin.exp (revision 153950) +++ gcc/testsuite/g++.dg/plugin/plugin.exp (working copy) @@ -48,6 +48,7 @@ load_lib plugin-support.exp # plugin_test_list={ {plugin1 test1 test2 ...} {plugin2 test1 ...} ... } set plugin_test_list [list \ { attribute_plugin.c attribute_plugin-test-1.C } \ + { pragma_plugin.c pragma_plugin-test-1.C } \ { selfassign.c self-assign-test-1.C self-assign-test-2.C self-assign-test-3.C } \ { dumb_plugin.c dumb-plugin-test-1.C } \ { header_plugin.c header-plugin-test.C } ] Index: gcc/c-pragma.c =================================================================== --- gcc/c-pragma.c (revision 153950) +++ gcc/c-pragma.c (working copy) @@ -37,6 +37,7 @@ along with GCC; see the file COPYING3. If not see #include "target.h" #include "diagnostic.h" #include "opts.h" +#include "plugin.h" #define GCC_BAD(gmsgid) \ do { warning (OPT_Wpragmas, gmsgid); return; } while (0) @@ -1450,6 +1451,9 @@ init_pragma (void) #ifdef REGISTER_TARGET_PRAGMAS REGISTER_TARGET_PRAGMAS (); #endif + + /* Allow plugins to register their own pragmas. */ + invoke_plugin_callbacks (PLUGIN_PRAGMAS, NULL); } #include "gt-c-pragma.h" Index: gcc/gcc-plugin.h =================================================================== --- gcc/gcc-plugin.h (revision 153950) +++ gcc/gcc-plugin.h (working copy) @@ -43,6 +43,7 @@ enum plugin_event PLUGIN_REGISTER_GGC_CACHES, /* Register an extra GGC cache table. */ PLUGIN_ATTRIBUTES, /* Called during attribute registration. */ PLUGIN_START_UNIT, /* Called before processing a translation unit. */ + PLUGIN_PRAGMAS, /* Called during pragma registration. */ PLUGIN_EVENT_LAST /* Dummy event used for indexing callback array. */ }; Index: gcc/plugin.c =================================================================== --- gcc/plugin.c (revision 153950) +++ gcc/plugin.c (working copy) @@ -58,7 +58,9 @@ const char *plugin_event_name[] = "PLUGIN_GGC_END", "PLUGIN_REGISTER_GGC_ROOTS", "PLUGIN_REGISTER_GGC_CACHES", - "PLUGIN_START_UNIT", + "PLUGIN_ATTRIBUTES", + "PLUGIN_START_UNIT", + "PLUGIN_PRAGMAS", "PLUGIN_EVENT_LAST" }; @@ -325,6 +327,7 @@ register_callback (const char *plugin_name, case PLUGIN_GGC_MARKING: case PLUGIN_GGC_END: case PLUGIN_ATTRIBUTES: + case PLUGIN_PRAGMAS: case PLUGIN_FINISH: { struct callback_info *new_callback; @@ -344,7 +347,7 @@ register_callback (const char *plugin_name, break; case PLUGIN_EVENT_LAST: default: - error ("Unkown callback event registered by plugin %s", + error ("Unknown callback event registered by plugin %s", plugin_name); } } @@ -368,6 +371,7 @@ invoke_plugin_callbacks (enum plugin_event event, case PLUGIN_FINISH_UNIT: case PLUGIN_CXX_CP_PRE_GENERICIZE: case PLUGIN_ATTRIBUTES: + case PLUGIN_PRAGMAS: case PLUGIN_FINISH: case PLUGIN_GGC_START: case PLUGIN_GGC_MARKING: Index: gcc/Makefile.in =================================================================== --- gcc/Makefile.in (revision 153950) +++ gcc/Makefile.in (working copy) @@ -1982,7 +1982,7 @@ c-convert.o : c-convert.c $(CONFIG_H) $(SYSTEM_H) c-pragma.o: c-pragma.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \ $(TREE_H) $(FUNCTION_H) $(C_PRAGMA_H) $(TOPLEV_H) output.h $(GGC_H) $(TM_P_H) \ $(C_COMMON_H) $(TARGET_H) gt-c-pragma.h $(CPPLIB_H) $(FLAGS_H) $(DIAGNOSTIC_H) \ - opts.h + opts.h $(PLUGINS_H) graph.o: graph.c $(SYSTEM_H) coretypes.h $(TM_H) $(TOPLEV_H) $(FLAGS_H) output.h \ $(RTL_H) $(FUNCTION_H) hard-reg-set.h $(BASIC_BLOCK_H) graph.h $(OBSTACK_H) \ $(CONFIG_H) @@ -4260,7 +4260,8 @@ PLUGIN_HEADERS = $(TREE_H) $(CONFIG_H) $(SYSTEM_H) $(host_xm_file_list) $(host_xm_include_list) $(xm_include_list) \ intl.h $(PLUGIN_VERSION_H) $(DIAGNOSTIC_H) $(C_COMMON_H) $(C_PRETTY_PRINT_H) \ tree-iterator.h $(PLUGIN_H) $(TREE_FLOW_H) langhooks.h incpath.h \ - tree-ssa-sccvn.h real.h output.h $(IPA_UTILS_H) + tree-ssa-sccvn.h real.h output.h $(IPA_UTILS_H) \ + $(C_PRAGMA_H) $(CPPLIB_H) $(FUNCTION_H) # Install the headers needed to build a plugin. install-plugin: installdirs lang.install-plugin @@ -4524,7 +4525,7 @@ install-collect2: collect2 installdirs # Install lto-wrapper. install-lto-wrapper: lto-wrapper$(exeext) $(INSTALL_PROGRAM) lto-wrapper$(exeext) $(DESTDIR)$(libexecsubdir)/lto-wrapper$(exeext) - + # Cancel installation by deleting the installed files. uninstall: lang.uninstall -rm -rf $(DESTDIR)$(libsubdir) Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359 8, rue de la Faiencerie, 92340 Bourg La Reine, France *** opinions {are only mines, sont seulement les miennes} *** |
|
|
Re: PLUGIN_PRAGMAS event>>
>> The patch still has PLUGIN_START_UNIT in plugin.c > > PLUGIN_START_UNIT seems to already be in the trunk rev 153950. I believe it > was added by somebody else, and I strongly believe it should not be removed > (that is, all plugin events should be kept). > And the string "PLUGIN_ATTRIBUTES" seems to be missing in its plugin.c; I am > correcting that also in the submitted patch here. That is correct. I misread the first patch. Thanks. > I tend to believe that we should have a plugin-events.def file containing > the list of events like > > PLUGIN_EVENT(PLUGIN_PASS_MANAGER_SETUP) > PLUGIN_EVENT(PLUGIN_FINISH_TYPE) > PLUGIN_EVENT(PLUGIN_FINISH_UNIT) > > and include it with various #define of PLUGIN_EVENT both in gcc-plugin.h & > plugin.c. We could even generate some part of plugins.texi but I won't > propose such a patch if people are not interested. > Perhaps we should sort alphabetically the list of events there. > There is also a typo in the error message when the callback event is > unknown. Thanks for fixing. > Back to PLUGIN_PRAGMAS. > >> >> The test fails with: >> error: 'abort' was not declared in this scope > > I removed the use of abort. I tried to reproduce the dg comments from other > tests, but which the plugin_pragma.c does work as expected, the comments in > gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C > are not making dejagnu happy. Unfortunately I never understood dejagnu. But > when the pragma_plugin.so is loaded, it works as I expect: > > /usr/src/Lang/gcc-trunk-bstarynk/gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C:5:28: > warning: 'pragma GCCPLUGIN sayhello' outside of function: here > /usr/src/Lang/gcc-trunk-bstarynk/gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C: > In function 'int some_func(const char*)': > /usr/src/Lang/gcc-trunk-bstarynk/gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C:11:28: > warning: 'pragma GCCPLUGIN sayhello' from function 'some_func': at start > /usr/src/Lang/gcc-trunk-bstarynk/gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C:16:20: > warning: 'pragma GCCPLUGIN sayhello' from function 'some_func': in block > > What are the comments needed in pragma_plugin-test-1.C to make dejagnu > happy? line as the pragmas and that some single quotes were missing. I have attached a fix. I think the patch is OK. Richard, Diego, the impact is probably low, OK during stage3? > Respectful regards. > > -- > Basile STARYNKEVITCH http://starynkevitch.net/Basile/ > email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359 > 8, rue de la Faiencerie, 92340 Bourg La Reine, France > *** opinions {are only mines, sont seulement les miennes} *** > Cheers, -- Rafael Ávila de Espíndola [pragmas.patch] diff --git a/gcc/Makefile.in b/gcc/Makefile.in index 5dd47e5..f66f9ef 100644 --- a/gcc/Makefile.in +++ b/gcc/Makefile.in @@ -1982,7 +1982,7 @@ c-convert.o : c-convert.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ c-pragma.o: c-pragma.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(RTL_H) \ $(TREE_H) $(FUNCTION_H) $(C_PRAGMA_H) $(TOPLEV_H) output.h $(GGC_H) $(TM_P_H) \ $(C_COMMON_H) $(TARGET_H) gt-c-pragma.h $(CPPLIB_H) $(FLAGS_H) $(DIAGNOSTIC_H) \ - opts.h + opts.h $(PLUGINS_H) graph.o: graph.c $(SYSTEM_H) coretypes.h $(TM_H) $(TOPLEV_H) $(FLAGS_H) output.h \ $(RTL_H) $(FUNCTION_H) hard-reg-set.h $(BASIC_BLOCK_H) graph.h $(OBSTACK_H) \ $(CONFIG_H) @@ -4260,7 +4260,8 @@ PLUGIN_HEADERS = $(TREE_H) $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ $(host_xm_file_list) $(host_xm_include_list) $(xm_include_list) \ intl.h $(PLUGIN_VERSION_H) $(DIAGNOSTIC_H) $(C_COMMON_H) $(C_PRETTY_PRINT_H) \ tree-iterator.h $(PLUGIN_H) $(TREE_FLOW_H) langhooks.h incpath.h \ - tree-ssa-sccvn.h real.h output.h $(IPA_UTILS_H) + tree-ssa-sccvn.h real.h output.h $(IPA_UTILS_H) \ + $(C_PRAGMA_H) $(CPPLIB_H) $(FUNCTION_H) # Install the headers needed to build a plugin. install-plugin: installdirs lang.install-plugin @@ -4524,7 +4525,7 @@ install-collect2: collect2 installdirs # Install lto-wrapper. install-lto-wrapper: lto-wrapper$(exeext) $(INSTALL_PROGRAM) lto-wrapper$(exeext) $(DESTDIR)$(libexecsubdir)/lto-wrapper$(exeext) - + # Cancel installation by deleting the installed files. uninstall: lang.uninstall -rm -rf $(DESTDIR)$(libsubdir) diff --git a/gcc/c-pragma.c b/gcc/c-pragma.c index f281644..f71399f 100644 --- a/gcc/c-pragma.c +++ b/gcc/c-pragma.c @@ -37,6 +37,7 @@ along with GCC; see the file COPYING3. If not see #include "target.h" #include "diagnostic.h" #include "opts.h" +#include "plugin.h" #define GCC_BAD(gmsgid) \ do { warning (OPT_Wpragmas, gmsgid); return; } while (0) @@ -1450,6 +1451,9 @@ init_pragma (void) #ifdef REGISTER_TARGET_PRAGMAS REGISTER_TARGET_PRAGMAS (); #endif + + /* Allow plugins to register their own pragmas. */ + invoke_plugin_callbacks (PLUGIN_PRAGMAS, NULL); } #include "gt-c-pragma.h" diff --git a/gcc/doc/plugins.texi b/gcc/doc/plugins.texi index f784953..123f670 100644 --- a/gcc/doc/plugins.texi +++ b/gcc/doc/plugins.texi @@ -136,6 +136,7 @@ enum plugin_event PLUGIN_REGISTER_GGC_CACHES, /* Register an extra GGC cache table. */ PLUGIN_ATTRIBUTES, /* Called during attribute registration */ PLUGIN_START_UNIT, /* Called before processing a translation unit. */ + PLUGIN_PRAGMAS, /* Called during pragma registration. */ PLUGIN_EVENT_LAST /* Dummy event used for indexing callback array. */ @}; @@ -156,6 +157,11 @@ For the PLUGIN_PASS_MANAGER_SETUP, PLUGIN_INFO, PLUGIN_REGISTER_GGC_ROOTS and PLUGIN_REGISTER_GGC_CACHES pseudo-events the @code{callback} should be null, and the @code{user_data} is specific. +When the PLUGIN_PRAGMAS event is triggered (with a null +pointer as data from GCC), plugins may register their own pragmas +using functions like @code{c_register_pragma} or +@code{c_register_pragma_with_expansion}. + @section Interacting with the pass manager There needs to be a way to add/reorder/remove passes dynamically. This diff --git a/gcc/gcc-plugin.h b/gcc/gcc-plugin.h index 1792c03..2e36f48 100644 --- a/gcc/gcc-plugin.h +++ b/gcc/gcc-plugin.h @@ -43,6 +43,7 @@ enum plugin_event PLUGIN_REGISTER_GGC_CACHES, /* Register an extra GGC cache table. */ PLUGIN_ATTRIBUTES, /* Called during attribute registration. */ PLUGIN_START_UNIT, /* Called before processing a translation unit. */ + PLUGIN_PRAGMAS, /* Called during pragma registration. */ PLUGIN_EVENT_LAST /* Dummy event used for indexing callback array. */ }; diff --git a/gcc/plugin.c b/gcc/plugin.c index 18b7c8a..2d64422 100644 --- a/gcc/plugin.c +++ b/gcc/plugin.c @@ -58,7 +58,9 @@ const char *plugin_event_name[] = "PLUGIN_GGC_END", "PLUGIN_REGISTER_GGC_ROOTS", "PLUGIN_REGISTER_GGC_CACHES", - "PLUGIN_START_UNIT", + "PLUGIN_ATTRIBUTES", + "PLUGIN_START_UNIT", + "PLUGIN_PRAGMAS", "PLUGIN_EVENT_LAST" }; @@ -325,6 +327,7 @@ register_callback (const char *plugin_name, case PLUGIN_GGC_MARKING: case PLUGIN_GGC_END: case PLUGIN_ATTRIBUTES: + case PLUGIN_PRAGMAS: case PLUGIN_FINISH: { struct callback_info *new_callback; @@ -344,7 +347,7 @@ register_callback (const char *plugin_name, break; case PLUGIN_EVENT_LAST: default: - error ("Unkown callback event registered by plugin %s", + error ("Unknown callback event registered by plugin %s", plugin_name); } } @@ -368,6 +371,7 @@ invoke_plugin_callbacks (enum plugin_event event, void *gcc_data) case PLUGIN_FINISH_UNIT: case PLUGIN_CXX_CP_PRE_GENERICIZE: case PLUGIN_ATTRIBUTES: + case PLUGIN_PRAGMAS: case PLUGIN_FINISH: case PLUGIN_GGC_START: case PLUGIN_GGC_MARKING: diff --git a/gcc/testsuite/g++.dg/plugin/plugin.exp b/gcc/testsuite/g++.dg/plugin/plugin.exp index 4ba73e5..72de92d 100644 --- a/gcc/testsuite/g++.dg/plugin/plugin.exp +++ b/gcc/testsuite/g++.dg/plugin/plugin.exp @@ -48,6 +48,7 @@ load_lib plugin-support.exp # plugin_test_list={ {plugin1 test1 test2 ...} {plugin2 test1 ...} ... } set plugin_test_list [list \ { attribute_plugin.c attribute_plugin-test-1.C } \ + { pragma_plugin.c pragma_plugin-test-1.C } \ { selfassign.c self-assign-test-1.C self-assign-test-2.C self-assign-test-3.C } \ { dumb_plugin.c dumb-plugin-test-1.C } \ { header_plugin.c header-plugin-test.C } ] diff --git a/gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C b/gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C new file mode 100644 index 0000000..3c08420 --- /dev/null +++ b/gcc/testsuite/g++.dg/plugin/pragma_plugin-test-1.C @@ -0,0 +1,18 @@ +// { dg-warning "Callback to register pragmas" "" { target *-*-* } 0 } + +int some_func (int c); + +#pragma GCCPLUGIN sayhello "here" // { dg-warning "'pragma GCCPLUGIN sayhello' outside of function: here" } + +int some_func (const char* s) +{ +#pragma GCCPLUGIN sayhello "at start" // { dg-warning "'pragma GCCPLUGIN sayhello' from function 'some_func': at start" } + +#define DO_PRAGMA(x) _Pragma(#x) + if (!s) + { + DO_PRAGMA(GCCPLUGIN sayhello "in block"); // { dg-warning "'pragma GCCPLUGIN sayhello' from function 'some_func': in block" } + return 0; + } + return 1; +} diff --git a/gcc/testsuite/g++.dg/plugin/pragma_plugin.c b/gcc/testsuite/g++.dg/plugin/pragma_plugin.c new file mode 100644 index 0000000..237fcdd --- /dev/null +++ b/gcc/testsuite/g++.dg/plugin/pragma_plugin.c @@ -0,0 +1,60 @@ +/* Demonstrates how to add custom pragmas */ + +#include "gcc-plugin.h" +#include <stdlib.h> +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tm.h" +#include "rtl.h" +#include "tree.h" +#include "function.h" +#include "c-pragma.h" +#include "cpplib.h" +#include "tree-pass.h" +#include "intl.h" + +int plugin_is_GPL_compatible; + + +/* handler of #pragma GCCPLUGIN sayhello "message" is quite similar to + handler of #pragma GCC message...*/ + +static void +handle_pragma_sayhello (cpp_reader *dummy) +{ + tree message = 0; + if (pragma_lex (&message) != CPP_STRING) + { + warning (OPT_Wpragmas, "%<#pragma GCCPLUGIN sayhello%> is not a string"); + return; + } + if (TREE_STRING_LENGTH (message) > 1) + if (cfun) + warning (OPT_Wpragmas, + "%<pragma GCCPLUGIN sayhello%> from function %qE: %s", + cfun->decl, TREE_STRING_POINTER (message)); + else + warning (OPT_Wpragmas, + "%<pragma GCCPLUGIN sayhello%> outside of function: %s", + TREE_STRING_POINTER (message)); +} + +/* Plugin callback called during pragma registration */ + +static void +register_my_pragma (void *event_data, void *data) +{ + warning (0, G_("Callback to register pragmas")); + c_register_pragma ("GCCPLUGIN", "sayhello", handle_pragma_sayhello); +} + +int +plugin_init (struct plugin_name_args *plugin_info, + struct plugin_gcc_version *version) +{ + const char *plugin_name = plugin_info->base_name; + + register_callback (plugin_name, PLUGIN_PRAGMAS, register_my_pragma, NULL); + return 0; +} |
|
|
Re: PLUGIN_PRAGMAS eventOn Fri, Nov 6, 2009 at 10:24, Rafael Espindola <espindola@...> wrote:
> I think the patch is OK. Richard, Diego, the impact is probably low, > OK during stage3? I also need to add a few events, mostly preprocessor and 1 for the parser (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41757). Adding new events seems very low impact to me, but let's hear from the release managers first. If adding new events is not possible now, this would not be a big patch to carry around until the next stage 1. Diego. |
|
|
Re: PLUGIN_PRAGMAS eventOn Fri, Nov 6, 2009 at 5:00 PM, Diego Novillo <dnovillo@...> wrote:
> On Fri, Nov 6, 2009 at 10:24, Rafael Espindola <espindola@...> wrote: > >> I think the patch is OK. Richard, Diego, the impact is probably low, >> OK during stage3? > > I also need to add a few events, mostly preprocessor and 1 for the > parser (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41757). > > Adding new events seems very low impact to me, but let's hear from the > release managers first. If adding new events is not possible now, > this would not be a big patch to carry around until the next stage 1. If there is a current need for new hooks then it is ok to add them during stage3. Current as opposed to theoretical. Thanks, Richard. |
|
|
Re: PLUGIN_PRAGMAS eventOn Fri, Nov 6, 2009 at 11:18, Richard Guenther
<richard.guenther@...> wrote: > If there is a current need for new hooks then it is ok to add them > during stage3. Current as opposed to theoretical. Great, thanks! Diego. |
|
|
Re: PLUGIN_PRAGMAS eventDiego Novillo wrote:
> On Fri, Nov 6, 2009 at 11:18,> > >> I think the patch is OK. Richard, Diego, the impact is probably low, > >> OK during stage3? If Rafael could apply the improved patch that is ok for me. Otherwise I can apply Rafael's improvement to the trunk (if there is an ok, which I understood). I prefer Rafael to make the svn commit (because I am a bit scared of git generated patches; I am not sure to understand how to apply them automatically, and I am afraid of making mistakes if applying them manually.). Richard Guenther > <richard.guenther@...> wrote: > >> If there is a current need for new hooks then it is ok to add them >> during stage3. Current as opposed to theoretical. Should I guess that the Google team have both a private branch of the trunk (with the added PLUGIN_* event) and a private plugin using that new plugin event? Or is the branch public (perhaps the lto branch?)... I am very confused. Otherwise, I am not sure to understand what is theoretical. I really need an explanation (remember that I am not a native English speaker, so it is probably a human language issue - "theoritical" is translated into "théorique" in Franch according to all my dictionnaries, but might have slightly different meanings in French and in English). I would never bother calling any PLUGIN_* event a theoretical stuff (usually theory related to software is in greek letters and typeset using the math mode of LaTeX, at least that is what I learned in France.).[Note *] Why are some events more theoretical than others? What is the criteria for adding them or for rejecting them as theoretical? I still believe that adding PLUGIN events which are rarely used in a invoke_plugin_callbacks (for example, which are called only once like PLUGIN_PRAGMAS or are called a thousand times, not a million times) should be accepted easily now. I believe that an explanation of how a not-yet-coded plugin could use them is enough. We can't expect people to code in a week or two a useful plugin demonstrating the interest of an extra PLUGIN_* event. That would be a crazy expectation! In particular, if the ICI guys want a few events invoked a few times, I believe these events should be accepted (even in the current stage 3 of trunk = future 4.5). And they might want a few events inside the pass manager (but of course, I don't understand their exact needs in details). I leave up to them to propose the PLUGIN_* event they need [but they should propose them quickly]! I hope that the PLUGIN_PRAGMAS will make into 4.5 and I hope that Diego (or some other good guys) would be able to push CPP related PLUGIN_* events into 4.5. Why cannot we accept any (I really mean any, not some) PLUGIN_* event provided that 1. its invoke_plugin_callbacks is not called very often [so does not impact performance of compilations without plugins] 2. it has a story - just a written description in English, not real code - which explains how it will be used in the near future - ie before end of 2012? 3. it has a small patch with a few sentences of documentation in plugins.texi and a small testcase? And I don't believe that the plugin API is carved in stone. It will evolve, and plugins won't be able to run both on e.g. 4.5 & 4.6 without special care in their source code (this is not related to plugins. I believe that a pass written in a dead branch merged with 4.4 or 4.3 cannot be merged without any changes into 4.5). It is really not an issue to add several dozens of additional PLUGIN_* events [Note **]! And we could remove some of them later (in GCC 4.6 or 4.7 or 5.0) when we find out that they are not needed. Regards. Note [*]: An example of interesting theoretical stuff (written in North America by an American) is for example "Types and Programming Languages" by Benjamin C. Pierce at http://www.cis.upenn.edu/~bcpierce/tapl/index.html - the theory is typeset in LaTeX (mathematical formulas, greek letters, quantifiers... everything that GCC don't have - and has nothing in common with plugins). Note [**]: in particular, the numerical value of some PLUGIN_* event (that is, its position in the enum plugin_event of gcc-plugin.h) is completely irrelevant, even for a minor 4.5.2 -> 4.5.3 change. We definitely should not expect a plugin binary to run on a gcc different of the one for which it has been compiled (even for a minor release change). We might want to write that more clearly! I would even wish that PLUGIN_PRAGMAS is written just after PLUGIN_ATTRIBUTES in the enum plugin_event because it is conceptually near. Likewise, I believe that PLUGIN_START_UNIT should be just before PLUGIN_FINISH_UNIT. The current order of PLUGIN_* events in the enum plugin_event is chronological and that is not pretty. -- Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359 8, rue de la Faiencerie, 92340 Bourg La Reine, France *** opinions {are only mines, sont seulement les miennes} *** Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359 8, rue de la Faiencerie, 92340 Bourg La Reine, France *** opinions {are only mines, sont seulement les miennes} *** |
|
|
Re: PLUGIN_PRAGMAS eventOn Fri, Nov 6, 2009 at 12:56, Basile STARYNKEVITCH
<basile@...> wrote: > What is the criteria for adding them or for rejecting them as theoretical? That you have a specific plugin making concrete use of them. A theoretical event would be one that is only added just in case a future plugin may have a use for it. I don't have an internal plugin branch. I am working off of a 4.4 compiler with backported plugin support. The events I need to add are all for dehydra's use. I need to add an event for when the parser finishes recognizing a DECL (the PR I pointed to earlier) and also I need some pre-processor events for allowing dehydra to expose things like #define and #include to user javascript code. Diego. |
|
|
Re: PLUGIN_PRAGMAS event> If Rafael could apply the improved patch that is ok for me.
Done. Thanks. > > -- > Basile STARYNKEVITCH http://starynkevitch.net/Basile/ > email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359 > 8, rue de la Faiencerie, 92340 Bourg La Reine, France > *** opinions {are only mines, sont seulement les miennes} *** > Cheers, -- Rafael Ávila de Espíndola |
|
|
Re: PLUGIN_PRAGMAS eventRafael Espindola wrote:
>> If Rafael could apply the improved patch that is ok for me. > Done. Thanks. I am just curious. What is the way of applying a git patch when using only svn (for GCC patches).? What is the magical command to apply automagically a git patch to an Svn tree? is it patch -p2? Regards. -- Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359 8, rue de la Faiencerie, 92340 Bourg La Reine, France *** opinions {are only mines, sont seulement les miennes} *** Basile STARYNKEVITCH http://starynkevitch.net/Basile/ email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359 8, rue de la Faiencerie, 92340 Bourg La Reine, France *** opinions {are only mines, sont seulement les miennes} *** |
|
|
Re: PLUGIN_PRAGMAS event> I am just curious. What is the way of applying a git patch when using only
> svn (for GCC patches).? I use the old patch utility :-) svn up patch -p1 < <the patch> svn commit > What is the magical command to apply automagically a git patch to an Svn > tree? is it patch -p2? -p1 > Regards. > > -- > Basile STARYNKEVITCH http://starynkevitch.net/Basile/ > email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359 > 8, rue de la Faiencerie, 92340 Bourg La Reine, France > *** opinions {are only mines, sont seulement les miennes} *** > Cheers, -- Rafael Ávila de Espíndola |
| Free embeddable forum powered by Nabble | Forum Help |