comparison gcc/plugin.c @ 63:b7f97abdc517 gcc-4.6-20100522

update gcc from gcc-4.5.0 to gcc-4.6
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Mon, 24 May 2010 12:47:05 +0900
parents 77e2b8dfacca
children f6334be47118
comparison
equal deleted inserted replaced
56:3c8a44c06a95 63:b7f97abdc517
1 /* Support for GCC plugin mechanism. 1 /* Support for GCC plugin mechanism.
2 Copyright (C) 2009 Free Software Foundation, Inc. 2 Copyright (C) 2009, 2010 Free Software Foundation, Inc.
3 3
4 This file is part of GCC. 4 This file is part of GCC.
5 5
6 GCC is free software; you can redistribute it and/or modify 6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU General Public License as published by
84 84
85 /* An array of lists of 'callback_info' objects indexed by the event id. */ 85 /* An array of lists of 'callback_info' objects indexed by the event id. */
86 static struct callback_info *plugin_callbacks_init[PLUGIN_EVENT_FIRST_DYNAMIC]; 86 static struct callback_info *plugin_callbacks_init[PLUGIN_EVENT_FIRST_DYNAMIC];
87 static struct callback_info **plugin_callbacks = plugin_callbacks_init; 87 static struct callback_info **plugin_callbacks = plugin_callbacks_init;
88 88
89 /* For invoke_plugin_callbacks(), see plugin.h. */
90 bool flag_plugin_added = false;
89 91
90 #ifdef ENABLE_PLUGIN 92 #ifdef ENABLE_PLUGIN
91 /* Each plugin should define an initialization function with exactly 93 /* Each plugin should define an initialization function with exactly
92 this name. */ 94 this name. */
93 static const char *str_plugin_init_func_name = "plugin_init"; 95 static const char *str_plugin_init_func_name = "plugin_init";
122 124
123 return base_name; 125 return base_name;
124 } 126 }
125 127
126 128
127 /* Create a plugin_name_args object for the give plugin and insert it to 129 /* Create a plugin_name_args object for the given plugin and insert it
128 the hash table. This function is called when -fplugin=/path/to/NAME.so 130 to the hash table. This function is called when
129 option is processed. */ 131 -fplugin=/path/to/NAME.so or -fplugin=NAME option is processed. */
130 132
131 void 133 void
132 add_new_plugin (const char* plugin_name) 134 add_new_plugin (const char* plugin_name)
133 { 135 {
134 struct plugin_name_args *plugin; 136 struct plugin_name_args *plugin;
135 void **slot; 137 void **slot;
136 char *base_name = get_plugin_base_name (plugin_name); 138 char *base_name;
139 bool name_is_short;
140 const char *pc;
141
142 flag_plugin_added = true;
143
144 /* Replace short names by their full path when relevant. */
145 name_is_short = !IS_ABSOLUTE_PATH (plugin_name);
146 for (pc = plugin_name; name_is_short && *pc; pc++)
147 if (*pc == '.' || IS_DIR_SEPARATOR (*pc))
148 name_is_short = false;
149
150 if (name_is_short)
151 {
152 base_name = CONST_CAST (char*, plugin_name);
153 /* FIXME: the ".so" suffix is currently builtin, since plugins
154 only work on ELF host systems like e.g. Linux or Solaris.
155 When plugins shall be available on non ELF systems such as
156 Windows or MacOS, this code has to be greatly improved. */
157 plugin_name = concat (default_plugin_dir_name (), "/",
158 plugin_name, ".so", NULL);
159 if (access (plugin_name, R_OK))
160 fatal_error
161 ("inacessible plugin file %s expanded from short plugin name %s: %m",
162 plugin_name, base_name);
163 }
164 else
165 base_name = get_plugin_base_name (plugin_name);
137 166
138 /* If this is the first -fplugin= option we encounter, create 167 /* If this is the first -fplugin= option we encounter, create
139 'plugin_name_args_tab' hash table. */ 168 'plugin_name_args_tab' hash table. */
140 if (!plugin_name_args_tab) 169 if (!plugin_name_args_tab)
141 plugin_name_args_tab = htab_create (10, htab_hash_string, htab_str_eq, 170 plugin_name_args_tab = htab_create (10, htab_hash_string, htab_str_eq,
456 return PLUGEVT_SUCCESS; 485 return PLUGEVT_SUCCESS;
457 } 486 }
458 return PLUGEVT_NO_CALLBACK; 487 return PLUGEVT_NO_CALLBACK;
459 } 488 }
460 489
461 /* Called from inside GCC. Invoke all plug-in callbacks registered with 490 /* Invoke all plugin callbacks registered with the specified event,
462 the specified event. 491 called from invoke_plugin_callbacks(). */
463 Return PLUGEVT_SUCCESS if at least one callback was called,
464 PLUGEVT_NO_CALLBACK if there was no callback.
465
466 EVENT - the event identifier
467 GCC_DATA - event-specific data provided by the compiler */
468 492
469 int 493 int
470 invoke_plugin_callbacks (int event, void *gcc_data) 494 invoke_plugin_callbacks_full (int event, void *gcc_data)
471 { 495 {
472 int retval = PLUGEVT_SUCCESS; 496 int retval = PLUGEVT_SUCCESS;
473 497
474 timevar_push (TV_PLUGIN_RUN); 498 timevar_push (TV_PLUGIN_RUN);
475 499
807 plugin_version->configuration_arguments)) 831 plugin_version->configuration_arguments))
808 return false; 832 return false;
809 return true; 833 return true;
810 } 834 }
811 835
836
812 /* Return the current value of event_last, so that plugins which provide 837 /* Return the current value of event_last, so that plugins which provide
813 additional functionality for events for the benefit of high-level plugins 838 additional functionality for events for the benefit of high-level plugins
814 know how many valid entries plugin_event_name holds. */ 839 know how many valid entries plugin_event_name holds. */
815 840
816 int 841 int
817 get_event_last (void) 842 get_event_last (void)
818 { 843 {
819 return event_last; 844 return event_last;
820 } 845 }
846
847
848 /* Retrieve the default plugin directory. The gcc driver should have passed
849 it as -iplugindir <dir> to the cc1 program, and it is queriable thru the
850 -print-file-name=plugin option to gcc. */
851 const char*
852 default_plugin_dir_name (void)
853 {
854 if (!plugindir_string)
855 fatal_error ("-iplugindir <dir> option not passed from the gcc driver");
856 return plugindir_string;
857 }