public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Patch for gas (mri mode).
@ 1999-09-20 10:43 Vladimir Makarov
  1999-09-20 10:59 ` Richard Henderson
  1999-09-20 11:06 ` Ian Lance Taylor
  0 siblings, 2 replies; 6+ messages in thread
From: Vladimir Makarov @ 1999-09-20 10:43 UTC (permalink / raw)
  To: rth; +Cc: binutils

Hi, Richard

The following patch is relative to net binutils repository.  Please,
approve it or not.  Without the patch, the assembler code likes the
following results in assembler crash because in MRI mode the assembler
does not define NARG, but in non-MRI mode the assembler expects that
NARG is defined.

.mri 0
.macro listing_off
.nolist
.endm
.macro listing_on
list
.endm
listing_off
.mri 1
listing_on


Vlad


1999-09-20  Vladimir Makarov  <vmakarov@tootie.to.cygnus.com>

	* macro.c (macro_entry): Add new member macro_mri.
        (define_macro): Assign value to macro->macro_mri.
        (do_formals): Use macro->macro_mri instead of macro_mri to decide
        define formal NARG or not.
        (macro_expand): Use m->macro_mri instead of macro_mri to decide
        make expansion of NARG or not.

Index: macro.c
===================================================================
RCS file: /cvs/binutils/binutils/gas/macro.c,v
retrieving revision 1.2
diff -p -c -r1.2 macro.c
*** macro.c	1999/06/03 00:23:27	1.2
--- macro.c	1999/09/20 17:09:25
*************** formal_entry;
*** 100,105 ****
--- 100,111 ----
  typedef struct macro_struct
    {
      sb sub;			/* substitution text. */
+     /* The following member value is MACRO_MRI when macro definition
+        is started.  It is needed for complex cases when macro is
+        defined in mri mode and used in non-mri mode or vise versa.
+        For example, if a macro is defined in non-mri mode and expanded
+        in mri mode, we should not expand NARG formal. */
+     int macro_mri;
      int formal_count;		/* number of formal args. */
      formal_entry *formals;	/* pointer to list of formal_structs */
      struct hash_control *formal_hash; /* hash table of formals. */
*************** do_formals (macro, idx, in)
*** 502,508 ****
        *p = NULL;
      }
  
!   if (macro_mri)
      {
        formal_entry *formal;
        const char *name;
--- 508,514 ----
        *p = NULL;
      }
  
!   if (macro->macro_mri)
      {
        formal_entry *formal;
        const char *name;
*************** define_macro (idx, in, label, get_line, 
*** 556,561 ****
--- 562,568 ----
    sb_new (&name);
  
    macro->formal_count = 0;
+   macro->macro_mri = macro_mri;
    macro->formals = 0;
  
    idx = sb_skip_white (idx, in);
*************** macro_expand (idx, in, m, out, comment_c
*** 1056,1062 ****
  	}
      }
  
!   if (macro_mri)
      {
        char buffer[20];
  
--- 1063,1069 ----
  	}
      }
  
!   if (m->macro_mri)
      {
        char buffer[20];
  

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

* Re: Patch for gas (mri mode).
  1999-09-20 10:43 Patch for gas (mri mode) Vladimir Makarov
@ 1999-09-20 10:59 ` Richard Henderson
  1999-09-20 11:03   ` Vladimir Makarov
  1999-09-20 11:06 ` Ian Lance Taylor
  1 sibling, 1 reply; 6+ messages in thread
From: Richard Henderson @ 1999-09-20 10:59 UTC (permalink / raw)
  To: Vladimir Makarov; +Cc: binutils

On Mon, Sep 20, 1999 at 01:41:55PM -0400, Vladimir Makarov wrote:
> 1999-09-20  Vladimir Makarov  <vmakarov@tootie.to.cygnus.com>
> 
> 	* macro.c (macro_entry): Add new member macro_mri.
>         (define_macro): Assign value to macro->macro_mri.
>         (do_formals): Use macro->macro_mri instead of macro_mri to decide
>         define formal NARG or not.
>         (macro_expand): Use m->macro_mri instead of macro_mri to decide
>         make expansion of NARG or not.

This is ok.  Can you check it in?


r~

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

* Re: Patch for gas (mri mode).
  1999-09-20 10:59 ` Richard Henderson
@ 1999-09-20 11:03   ` Vladimir Makarov
  0 siblings, 0 replies; 6+ messages in thread
From: Vladimir Makarov @ 1999-09-20 11:03 UTC (permalink / raw)
  To: Richard Henderson; +Cc: binutils

Richard Henderson wrote:

> On Mon, Sep 20, 1999 at 01:41:55PM -0400, Vladimir Makarov wrote:
> > 1999-09-20  Vladimir Makarov  <vmakarov@tootie.to.cygnus.com>
> >
> >       * macro.c (macro_entry): Add new member macro_mri.
> >         (define_macro): Assign value to macro->macro_mri.
> >         (do_formals): Use macro->macro_mri instead of macro_mri to decide
> >         define formal NARG or not.
> >         (macro_expand): Use m->macro_mri instead of macro_mri to decide
> >         make expansion of NARG or not.
>
> This is ok.  Can you check it in?
>

Richard, I am afraid I can't because I have no write permission to the
repository.

Vlad


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

* Re: Patch for gas (mri mode).
  1999-09-20 10:43 Patch for gas (mri mode) Vladimir Makarov
  1999-09-20 10:59 ` Richard Henderson
@ 1999-09-20 11:06 ` Ian Lance Taylor
  1999-09-20 13:05   ` Vladimir Makarov
  1 sibling, 1 reply; 6+ messages in thread
From: Ian Lance Taylor @ 1999-09-20 11:06 UTC (permalink / raw)
  To: vmakarov; +Cc: rth, binutils

   Date: Mon, 20 Sep 1999 13:41:55 -0400
   From: Vladimir Makarov <vmakarov@tootie.to.cygnus.com>

   The following patch is relative to net binutils repository.  Please,
   approve it or not.  Without the patch, the assembler code likes the
   following results in assembler crash because in MRI mode the assembler
   does not define NARG, but in non-MRI mode the assembler expects that
   NARG is defined.

That's backward: NARG is defined and expected to exist in MRI mode.

If we think that a macro defined in MRI mode should operate as an
MRI-style macro, then quite a few more instances of macro_mri need to
change.  In fact, we probably need to push and pop the global variable
flag_mri during the macro expansion.

If we just want to fix the particular problem at hand, I think it
would be clearer to simply check the result of hash_find for NULL,
rather than consider a macro to be in MRI mode or not.

Ian

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

* Re: Patch for gas (mri mode).
  1999-09-20 11:06 ` Ian Lance Taylor
@ 1999-09-20 13:05   ` Vladimir Makarov
  1999-09-20 13:51     ` Ian Lance Taylor
  0 siblings, 1 reply; 6+ messages in thread
From: Vladimir Makarov @ 1999-09-20 13:05 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: rth, binutils

Ian Lance Taylor wrote:

>    Date: Mon, 20 Sep 1999 13:41:55 -0400
>    From: Vladimir Makarov <vmakarov@tootie.to.cygnus.com>
>
>    The following patch is relative to net binutils repository.  Please,
>    approve it or not.  Without the patch, the assembler code likes the
>    following results in assembler crash because in MRI mode the assembler
>    does not define NARG, but in non-MRI mode the assembler expects that
>    NARG is defined.
>
> That's backward: NARG is defined and expected to exist in MRI mode.
>
> If we think that a macro defined in MRI mode should operate as an
> MRI-style macro, then quite a few more instances of macro_mri need to
> change.  In fact, we probably need to push and pop the global variable
> flag_mri during the macro expansion.
>
> If we just want to fix the particular problem at hand, I think it
> would be clearer to simply check the result of hash_find for NULL,
> rather than consider a macro to be in MRI mode or not.
>

Ian, I thought about this solution.  I've chosen the previous solution.  I
believed that it is clearer because it says clearly about the situation of
usage of macro defined in mri mode and used in non-macro mode (and vise
versa).  It could be useful for anyone who will add code (e.g. new implicit
args) in order to miss the situation because he/she will see new member in
the struct macro.  It could be safer because if something is wrong with the
code with implicit definition of NARG, we will miss the bug because we 'll
think that is defined in mri mode.  Now I see that there are many awkward
situations with .mri usage (e.g. treatment of usage of .mri in macros
themselves).

So, now I'd prefer the simple solution.  Here the new patch is.  Please,
approve it or not.


1999-09-20  Vladimir Makarov  <vmakarov@tootie.to.cygnus.com>

        * macro.c (macro_expand): Expand NARG only if it is defined.

Index: macro.c
===================================================================
RCS file: /cvs/binutils/binutils/gas/macro.c,v
retrieving revision 1.2
diff -c -p -r1.2 macro.c
*** macro.c     1999/06/03 00:23:27     1.2
--- macro.c     1999/09/20 19:37:52
*************** macro_expand (idx, in, m, out, comment_c
*** 1063,1071 ****
        sb_reset (&t);
        sb_add_string (&t, macro_strip_at ? "$NARG" : "NARG");
        ptr = (formal_entry *) hash_find (m->formal_hash, sb_terminate
(&t));
!       sb_reset (&ptr->actual);
!       sprintf (buffer, "%d", narg);
!       sb_add_string (&ptr->actual, buffer);
      }

    err = macro_expand_body (&m->sub, out, m->formals, m->formal_hash,
--- 1063,1075 ----
        sb_reset (&t);
        sb_add_string (&t, macro_strip_at ? "$NARG" : "NARG");
        ptr = (formal_entry *) hash_find (m->formal_hash, sb_terminate
(&t));
!       /* ptr == NULL means that macro is defined not in mri mode. */
!       if (ptr != NULL)
!       {
!         sb_reset (&ptr->actual);
!         sprintf (buffer, "%d", narg);
!         sb_add_string (&ptr->actual, buffer);
!       }
      }

    err = macro_expand_body (&m->sub, out, m->formals, m->formal_hash,


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

* Re: Patch for gas (mri mode).
  1999-09-20 13:05   ` Vladimir Makarov
@ 1999-09-20 13:51     ` Ian Lance Taylor
  0 siblings, 0 replies; 6+ messages in thread
From: Ian Lance Taylor @ 1999-09-20 13:51 UTC (permalink / raw)
  To: vmakarov; +Cc: rth, binutils

   Date: Mon, 20 Sep 1999 16:04:05 -0400
   From: Vladimir Makarov <vmakarov@cygnus.com>

   So, now I'd prefer the simple solution.  Here the new patch is.  Please,
   approve it or not.


   1999-09-20  Vladimir Makarov  <vmakarov@tootie.to.cygnus.com>

	   * macro.c (macro_expand): Expand NARG only if it is defined.

This is OK with me.

Ian

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

end of thread, other threads:[~1999-09-20 13:51 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-09-20 10:43 Patch for gas (mri mode) Vladimir Makarov
1999-09-20 10:59 ` Richard Henderson
1999-09-20 11:03   ` Vladimir Makarov
1999-09-20 11:06 ` Ian Lance Taylor
1999-09-20 13:05   ` Vladimir Makarov
1999-09-20 13:51     ` Ian Lance Taylor

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).