This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PLUGIN_PRAGMAS event
Basile 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@starynkevitch.net>
* 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)