1 /* Demonstrates how to add custom pragmas */
3 #include "gcc-plugin.h"
12 #include "c-family/c-pragma.h"
14 #include "tree-pass.h"
17 #include "diagnostic.h"
19 int plugin_is_GPL_compatible
;
22 /* handler of #pragma GCCPLUGIN sayhello "message" is quite similar to
23 handler of #pragma GCC message...*/
26 handle_pragma_sayhello (cpp_reader
*dummy
)
29 if (pragma_lex (&message
) != CPP_STRING
)
31 warning (OPT_Wpragmas
, "%<#pragma GCCPLUGIN sayhello%> is not a string");
34 if (TREE_STRING_LENGTH (message
) > 1)
36 warning (OPT_Wpragmas
,
37 "%<pragma GCCPLUGIN sayhello%> from function %qE: %s",
38 cfun
->decl
, TREE_STRING_POINTER (message
));
40 warning (OPT_Wpragmas
,
41 "%<pragma GCCPLUGIN sayhello%> outside of function: %s",
42 TREE_STRING_POINTER (message
));
45 /* Plugin callback called during pragma registration */
48 register_my_pragma (void *event_data
, void *data
)
50 warning (0, G_("Callback to register pragmas"));
51 c_register_pragma ("GCCPLUGIN", "sayhello", handle_pragma_sayhello
);
55 plugin_init (struct plugin_name_args
*plugin_info
,
56 struct plugin_gcc_version
*version
)
58 const char *plugin_name
= plugin_info
->base_name
;
60 register_callback (plugin_name
, PLUGIN_PRAGMAS
, register_my_pragma
, NULL
);