123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- /* GCC plugin APIs.
- This program 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 2 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 "gml4gtk-plugin.h"
- /* plugin license check */
- int plugin_is_GPL_compatible;
- /* */
- static void
- help (void)
- {
- printf (
- "Usage: gcc -fplugin=/path/to/gml4gtk_plugin.so -fplugin-arg-gml4gtk_plugin-<option> ...\n" \
- "Options:\n" \
- " cgraph dump the call graph before IPA passes.\n" \
- " cgraph-callee dump the callee graph for each function.\n" \
- " cgraph-caller dump the caller graph for each function.\n" \
- " gimple-hierarchy dump the gimple hierarchy graph.\n" \
- " help show this help.\n" \
- " passes dump the passes graph.\n" \
- " pass-lists dump the pass lists graph.\n" \
- " tree-hierarchy dump the tree hierarchy graph.\n" \
- " viewer=name set the viewer, default is gml4gtk\n" \
- " \n" \
- "%s %s \n",
- dot_plugin_common.plugin_name, dot_plugin_common.version);
- exit (0);
- }
- /* Version check. */
- static bool
- version_check (struct plugin_gcc_version *gcc_version,
- struct plugin_gcc_version *plugin_version)
- {
- if (!gcc_version || !plugin_version)
- return false;
- if (strcmp (gcc_version->basever, plugin_version->basever))
- return false;
- return true;
- }
- /* Plugin initialization. */
- int
- plugin_init (struct plugin_name_args *plugin_info,
- struct plugin_gcc_version *version)
- {
- int i;
- int argc = plugin_info->argc;
- struct plugin_argument *argv = plugin_info->argv;
- if (!version_check (version, &gcc_version))
- {
- dot_plugin_common.error ("version check failed. plugin compiled by gcc %s and used by %s.",
- version->basever, gcc_version.basever);
- return 1;
- }
- dot_plugin_common.gcc_basever = (char *) version->basever;
- dot_plugin_common.info = concat ("GCC: (GNU) ", version->basever,
- " ", version->datestamp, " ",
- "(", version->devphase, ")\n", NULL);
- /* Initialize the dot plugin */
- for (i = 0; i < argc; i++)
- {
- /* Get the viewer tool, default is "mooigrap". */
- if (strcmp (argv[i].key, "viewer") == 0)
- {
- dot_plugin_common.dot_viewer = argv[i].value;
- }
- /* Dump call graph. */
- if (strcmp (argv[i].key, "cgraph") == 0)
- {
- register_callback (plugin_info->base_name,
- PLUGIN_ALL_IPA_PASSES_START,
- (plugin_callback_func) dot_plugin_callback_cgraph,
- NULL);
- }
- /* Dump callee graph. */
- if (strcmp (argv[i].key, "cgraph-callee") == 0)
- {
- register_callback (plugin_info->base_name,
- PLUGIN_ALL_IPA_PASSES_START,
- (plugin_callback_func) dot_plugin_callback_callee,
- NULL);
- }
- /* Dump caller graph. */
- if (strcmp (argv[i].key, "cgraph-caller") == 0)
- {
- register_callback (plugin_info->base_name,
- PLUGIN_ALL_IPA_PASSES_START,
- (plugin_callback_func) dot_plugin_callback_caller,
- NULL);
- }
- /* Dump passes. */
- if (strcmp (argv[i].key, "passes") == 0)
- {
- register_callback (plugin_info->base_name,
- PLUGIN_START_UNIT,
- (plugin_callback_func) dot_plugin_callback_passes_start,
- NULL);
- register_callback (plugin_info->base_name,
- PLUGIN_OVERRIDE_GATE,
- (plugin_callback_func) dot_plugin_callback_pass,
- NULL);
- register_callback (plugin_info->base_name,
- PLUGIN_FINISH_UNIT,
- (plugin_callback_func) dot_plugin_callback_passes_finish,
- NULL);
- }
- /* Dump gcc pass lists. */
- if (strcmp (argv[i].key, "pass-lists") == 0)
- {
- register_callback (plugin_info->base_name,
- PLUGIN_FINISH,
- (plugin_callback_func) dot_plugin_callback_pass_lists,
- NULL);
- }
- /* Dump gimple hierarchy graph. */
- if (strcmp (argv[i].key, "gimple-hierarchy") == 0)
- {
- register_callback (plugin_info->base_name,
- PLUGIN_FINISH,
- (plugin_callback_func) dot_plugin_callback_gimple_hierarchy,
- NULL);
- }
- /* Dump tree hierarchy graph. */
- if (strcmp (argv[i].key, "tree-hierarchy") == 0)
- {
- register_callback (plugin_info->base_name,
- PLUGIN_FINISH,
- (plugin_callback_func) dot_plugin_callback_tree_hierarchy,
- NULL);
- }
- if (strcmp (argv[i].key, "help") == 0)
- {
- help ();
- }
- }
- return 0;
- }
- /* end */
|