This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

macros in .md files


I am sick of not being able to use macros in .md files, so I though I might
as well hack an implementation.  I don't want to spend too much time on
such a meta-tool, so I kept it simple.  It only processes simple macros
without arguments, e.g.

(#define FOO_REG 42)

Tue Oct 17 22:21:50 2000  J"orn Rennecke <amylaar@redhat.co.uk>

	* rtl.c (all_defines): New variable.
	(read_name): Expand defines.
	(read_rtx): Accept (#define .. ..) expressions.

Index: rtl.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gcc/rtl.c,v
retrieving revision 1.81
diff -p -r1.81 rtl.c
*** rtl.c	2000/09/18 21:44:56	1.81
--- rtl.c	2000/10/17 21:21:44
*************** const char * const reg_note_name[] =
*** 301,306 ****
--- 301,308 ----
    "REG_EH_RETHROW", "REG_SAVE_NOTE", "REG_MAYBE_DEAD", "REG_NORETURN"
  };
  
+ static struct define { char *name, *value; struct define *next; } *all_defines;
+ 
  static void fatal_with_file_and_line PARAMS ((FILE *, const char *, ...))
    ATTRIBUTE_PRINTF_2 ATTRIBUTE_NORETURN;
  static void fatal_expected_char PARAMS ((FILE *, int, int)) ATTRIBUTE_NORETURN;
*************** read_name (str, infile)
*** 844,849 ****
--- 846,852 ----
  {
    register char *p;
    register int c;
+   struct define *def;
  
    c = read_skip_spaces(infile);
  
*************** read_name (str, infile)
*** 867,872 ****
--- 870,889 ----
      read_rtx_lineno++;
  
    *p = 0;
+ 
+   /* Do macro expansion.  */
+   p = str;
+   do
+     {
+       for (def = all_defines; def; def = def->next)
+ 	if (! strcmp (p, def->name))
+ 	  {
+ 	    p = def->value;
+ 	    break;
+ 	  }
+     } while (def);
+   if (p != str)
+     strcpy (str, p);
  }
  
  /* Provide a version of a function to read a long long if the system does
*************** read_rtx (infile)
*** 934,939 ****
--- 951,957 ----
        rtx value;		/* Value of this node.  */
      };
  
+ again:
    c = read_skip_spaces (infile); /* Should be open paren.  */
    if (c != '(')
      fatal_expected_char (infile, '(', c);
*************** read_rtx (infile)
*** 942,947 ****
--- 960,985 ----
  
    tmp_code = UNKNOWN;
  
+   if (! strcmp (tmp_char, "#define"))
+     {
+       struct define *def;
+ 
+       def = xmalloc (sizeof (struct define));
+       c = read_skip_spaces (infile);
+       ungetc (c, infile);
+       read_name (tmp_char, infile);
+       def->name = xstrdup (tmp_char);
+       c = read_skip_spaces (infile);
+       ungetc (c, infile);
+       read_name (tmp_char, infile);
+       def->value = xstrdup (tmp_char);
+       def->next = all_defines;
+       all_defines = def;
+       c = read_skip_spaces (infile);
+       if (c != ')')
+ 	fatal_expected_char (infile, ')', c);
+       goto again;
+     }
    for (i = 0; i < NUM_RTX_CODE; i++)
      if (! strcmp (tmp_char, GET_RTX_NAME (i)))
        {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]