public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, MELT] new function register_data_handler
@ 2011-07-07 10:14 Pierre Vittet
  2011-07-07 10:35 ` Basile Starynkevitch
  0 siblings, 1 reply; 2+ messages in thread
From: Pierre Vittet @ 2011-07-07 10:14 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 741 bytes --]

Hi, this patch add a new function allowing to add a pragma handler more 
easily. In the past, we were directly modifying the :sysdata_meltpragmas 
field of initial_system_data.

The pragma handler take a list of new pragma handler that we want to 
add. The reason is that the field :sysdata_meltpragmas is a tuple (fixed 
size, this is a mandatory because we uses index to recognize the handler 
later). Each time we call register_data_handler, we recreate the tuple, 
so we try to give a list of handler to call it not to often.

This function should works with a GCC 4.6 but should be used with care, 
as we can only register a single pragma named "melt" (maybe we could use 
another function specially for 4.6 ?).

Thanks!

Pierre Vittet

[-- Attachment #2: defun_register_data_handler-175906.ChangeLog --]
[-- Type: text/plain, Size: 118 bytes --]

2011-07-07  Pierre Vittet  <piervit@pvittet.com>

	* melt/warmelt-base.melt (register_pragma_handler ): new function.

[-- Attachment #3: defun_register_data_handler-175906.diff --]
[-- Type: text/plain, Size: 2101 bytes --]

Index: gcc/melt/warmelt-base.melt
===================================================================
--- gcc/melt/warmelt-base.melt	(revision 175906)
+++ gcc/melt/warmelt-base.melt	(working copy)
@@ -1135,6 +1135,42 @@ registered with $REGISTER_PASS_EXECUTION_HOOK.}#
 		       }#)
 )))
 
+;;register a new pragma handler.
+(defun register_pragma_handler (lsthandler)
+  :doc #{register a list of new pragma handlers.  As :sysdata_meltpragmas must
+  be a tuple (we use an index to recognize handlers), we have to recreate this
+  tuple each time we call this function.  That why $LSTHANDLER is a list of
+  handlers (class_gcc_pragma) and not a single object.  }#
+  (assert_msg "register_pragma_handler takes a list as argument." 
+    (is_list lsthandler))
+  (let ((oldtuple (get_field :sysdata_meltpragmas initial_system_data))
+        (:long oldsize 0))
+    (if notnull oldtuple)
+      (setq oldsize (multiple_length oldtuple))
+    (let ((:long newsize (+i (multiple_length oldtuple)
+                          (list_length lsthandler)))
+          (newtuple (make_multiple discr_multiple newsize))
+          (:long i 0))
+    ;;copy in oldhandlers in the newtuple
+    (foreach_in_multiple
+    (oldtuple)
+    (curhander :long iunused)
+      (multiple_put_nth newtuple i curhander)
+      (setq i (+i i 1))
+    )
+    ;;add new handler from lsthandler
+    (foreach_in_list
+    (lsthandler)
+    (curpair curhandler)
+      (assert_msg "register_pragma_handler must be a list of class_gcc_pragma."
+        (is_a curhandler class_gcc_pragma))
+      (multiple_put_nth newtuple i curhandler)
+      (setq i (+i i 1))
+    )
+    (put_fields initial_system_data :sysdata_meltpragmas newtuple)
+    ))
+)
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;; the descriptions of values which are not ctype related.
 (defclass class_value_descriptor
@@ -2361,6 +2397,7 @@ polyhedron values.}#
  ppstrbuf_mixbigint
  read_file
  register_pass_execution_hook
+ register_pragma_handler
  retrieve_value_descriptor_list
  some_integer_greater_than
  some_integer_multiple

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH, MELT] new function register_data_handler
  2011-07-07 10:14 [PATCH, MELT] new function register_data_handler Pierre Vittet
@ 2011-07-07 10:35 ` Basile Starynkevitch
  0 siblings, 0 replies; 2+ messages in thread
From: Basile Starynkevitch @ 2011-07-07 10:35 UTC (permalink / raw)
  To: Pierre Vittet; +Cc: gcc-patches

On Thu, Jul 07, 2011 at 12:10:30PM +0200, Pierre Vittet wrote:
> Hi, this patch add a new function allowing to add a pragma handler
> more easily. In the past, we were directly modifying the
> :sysdata_meltpragmas field of initial_system_data.
> 

> 2011-07-07  Pierre Vittet  <piervit@pvittet.com>
> 
> 	* melt/warmelt-base.melt (register_pragma_handler): new function.


Thanks. I committed it on the MELT branch. Committed revision 175962.


-- 
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} ***

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-07-07 10:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-07 10:14 [PATCH, MELT] new function register_data_handler Pierre Vittet
2011-07-07 10:35 ` Basile Starynkevitch

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).