Right, here is the new version of the patch (with the correct files).
I added, a function register_pre_genericize_hook in
melt/warmelt-base.melt to be called when we want to register a MELT
function to handle the callback, so we don't manually set
sysdata_pre_genericize field.
Pierre Vittet
On 15/07/2011 18:41, Romain Geissler wrote:
Le 15 juil. 2011 à 18:17, Pierre Vittet a écrit :
Hello,
The following patch add support for PLUGIN_PRE_GENERICIZE callback.
The add_sysdata_pre_genericize patch add a field (sysdata_pre_genericize) in
initial system data, allowing to register a closure to be called on
PLUGIN_PRE_GENERICIZE event. This patch must be first applied and a make
warmelt-upgrade must be run in order to regenerate generated melt files.
The add_pre_genericize_hook patch add a function (in melt-runtime.c) to be
called on PLUGIN_PRE_GENERICIZE, which call the closure sysdata_pre_genericize
defined by the users.
Thanks
Pierre Vittet
<add_sysdata_pre_genericize-176032.ChangeLog><add_sysdata_pre_genericize-176032.diff><add_pre_genericize_hook-176032.ChangeLog><add_pre_genericize_hook-176032.ChangeLog~>
Great !
You forgot to attach the patch for melt-runtime.c (there is only the changelog)
I know your performing some simple static analysis, mostly based on matching
some c source code patterns (check that there is a if (fopen_result) just after
a fopen.
Is there a particular reason to do that as a pass (so at the gimple level)
rather that doing it just after the function has been parsed (eg upon
PLUGIN_PRE_GENERICIZE) ?
2011-07-15 Pierre Vittet <pier...@pvittet.com>
* melt-runtime.h (enum FSYDAT*): Add a FSYSDAT_PRE_GENERICIZE field.
* melt/warmelt-first.melt (class_system_data): add a
sysdata_pre_genericize field.
Index: gcc/melt/warmelt-first.melt
===================================================================
--- gcc/melt/warmelt-first.melt (revision 176032)
+++ gcc/melt/warmelt-first.melt (working copy)
@@ -441,6 +441,8 @@ don't instanciate this class!}#
sysdata_stdout ;raw file for stdout
sysdata_stderr ;raw file for stderr
sysdata_dumpfile ;raw file for dump_file
+ sysdata_pre_genericize ;closure to be called for
PLUGIN_PRE_GENERICIZE:
+ ;look at gcc/c-decl.c.
sysdata_unit_starter ;closure to be called at
;compilation unit start
sysdata_unit_finisher ;closure to be called at
Index: gcc/melt-runtime.h
===================================================================
--- gcc/melt-runtime.h (revision 176032)
+++ gcc/melt-runtime.h (working copy)
@@ -2324,6 +2324,7 @@ enum
FSYSDAT_STDOUT, /* raw boxed file for stdout */
FSYSDAT_STDERR, /* raw boxed file for stderr */
FSYSDAT_DUMPFILE, /* raw boxed file for dump_file */
+ FSYSDAT_PRE_GENERICIZE, /* closure for PLUGIN_PRE_GENERICIZE */
FSYSDAT_UNIT_STARTER, /* closure for start of compilation
unit */
FSYSDAT_UNIT_FINISHER, /* closure for start of compilation unit */
FSYSDAT_OPTION_SET, /* closure to set options */
2011-07-15 Pierre Vittet <pier...@pvittet.com>
* melt-runtime.c (melt_really_initialize): Register a new Callback to
PLUGIN_PRE_GENERICIZE.
(melt_pre_genericize_callback): New function, use field
sysdata_pre_genericize to transmit the callbacks.
* melt/warmelt-base.melt (register_pre_genericize_hook): New function.
Index: gcc/melt-runtime.c
===================================================================
--- gcc/melt-runtime.c (revision 176032)
+++ gcc/melt-runtime.c (working copy)
@@ -9044,6 +9044,35 @@ melt_pragma_callback (void *gcc_data ATTRIBUTE_UNU
#endif /*GCC >4.6 for handling pragma support*/
+
+/* This function is used when PLUGIN_PRE_GENERICIZE callback is invoked. It
+ calls the closure registered in field sydata_pre_genericize of
+ initial_system_data. The first argument is the tree containing the function
+ declaration (as given in file gcc/c-decl.c). */
+static void
+melt_pre_genericize_callback (void *ptr_fndecl,
+ void *user_data ATTRIBUTE_UNUSED)
+{
+ MELT_ENTERFRAME (2, NULL);
+#define pregenclosv meltfram__.mcfr_varptr[0]
+#define fndeclv meltfram__.mcfr_varptr[1]
+ fndeclv = meltgc_new_tree ((meltobject_ptr_t) MELT_PREDEF (DISCR_TREE),
+ ((tree) ptr_fndecl));
+ pregenclosv = melt_get_inisysdata (FSYSDAT_PRE_GENERICIZE);
+ if (melt_magic_discr ((melt_ptr_t) pregenclosv) == MELTOBMAG_CLOSURE)
+ {
+ MELT_LOCATION_HERE
+ ("melt_pre_genericize befire applying pre_genericize closure");
+ (void) melt_apply ((meltclosure_ptr_t) pregenclosv, (melt_ptr_t) fndeclv,
+ "", NULL, "", NULL);
+ }
+ MELT_EXITFRAME ();
+#undef fndeclv
+#undef pregenclosv
+}
+
+
+
/* the plugin callback when starting a compilation unit */
static void
melt_startunit_callback(void *gcc_data ATTRIBUTE_UNUSED,
@@ -9302,6 +9331,8 @@ melt_really_initialize (const char* pluginame, con
NULL);
register_callback (melt_plugin_name, PLUGIN_PRAGMAS, melt_pragma_callback,
NULL);
+ register_callback (melt_plugin_name, PLUGIN_PRE_GENERICIZE,
+ melt_pre_genericize_callback, NULL);
register_callback (melt_plugin_name, PLUGIN_START_UNIT,
melt_startunit_callback,
NULL);
Index: gcc/melt/warmelt-base.melt
===================================================================
--- gcc/melt/warmelt-base.melt (revision 176032)
+++ gcc/melt/warmelt-base.melt (working copy)
@@ -1192,6 +1192,17 @@ registered with $REGISTER_PASS_EXECUTION_HOOK.}#
))
)
+;;register a new closure at PLUGIN_PRE_GENERCIZE callback. If a closure was
+;;already attributed, we replace it with $clo.
+(defun register_pre_genericize_hook (clo)
+ (if (is_closure clo)
+ (put_fields initial_system_data :sysdata_pre_genericize clo)
+ (errormsg_strv
+ "Impossible to register pre_genericize_hook, argument should be a closure"
+ clo)
+ )
+)
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; the descriptions of values which are not ctype related.
(defclass class_value_descriptor
@@ -2421,6 +2432,7 @@ polyhedron values.}#
read_file
register_pass_execution_hook
register_pragma_handler
+ register_pre_genericize_hook
retrieve_value_descriptor_list
some_integer_greater_than
some_integer_multiple