This is the mail archive of the cgen@sources.redhat.com mailing list for the CGEN project.


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

patch to allow any character in keyword



This patch allows a port to have any character in any position in a
keyword, and changes the GAS parser to only look for characters which
are actually in a keyword.

It was needed by a (currently confidential) port which needed '.' in
the second position of a keyword.

OK to commit?

-- 
Geoff Keating <geoffk@redhat.com>

===File ~/patches/cgen-keywordspecials.patch================
Index: devo/opcodes/ChangeLog
2001-06-13  Geoffrey Keating  <geoffk@redhat.com>

	* cgen-asm.c (cgen_parse_keyword): When looking for the
	boundaries of a keyword, allow any special characters
	that are actually in one of the allowed keyword.
	* cgen-opc.c (cgen_keyword_add): Add any special characters
	to the nonalpha_chars field.

Index: devo/cgen/ChangeLog
2001-06-13  Geoffrey Keating  <geoffk@redhat.com>

	* desc.scm (<keyword> 'gen-defn): Add extra zero into
	CGEN_KEYWORD_ENTRY initializers.

Index: devo/include/opcode/ChangeLog
2001-06-13  Geoffrey Keating  <geoffk@redhat.com>

	* cgen.h (cgen_keyword): Add nonalpha_chars field.

Index: devo/opcodes/cgen-asm.c
===================================================================
RCS file: /cvs/cvsfiles/devo/opcodes/cgen-asm.c,v
retrieving revision 1.20
diff -p -u -p -r1.20 cgen-asm.c
--- cgen-asm.c	2001/03/15 04:23:54	1.20
+++ cgen-asm.c	2001/06/14 00:56:39
@@ -207,17 +207,16 @@ cgen_parse_keyword (cd, strp, keyword_ta
   char buf[256];
   const char *p,*start;
 
-  p = start = *strp;
+  if (keyword_table->name_hash_table == NULL)
+    (void) cgen_keyword_search_init (keyword_table, NULL);
 
-  /* Allow any first character.
-     Note that this allows recognizing ",a" for the annul flag in sparc
-     even though "," is subsequently not a valid keyword char.  */
-  if (*p)
-    ++p;
+  p = start = *strp;
 
-  /* Now allow letters, digits, and _.  */
+  /* Allow letters, digits, and any special characters.  */
   while (((p - start) < (int) sizeof (buf))
-	 && (isalnum ((unsigned char) *p) || *p == '_'))
+	 && *p
+	 && (isalnum ((unsigned char) *p) 
+	     || strchr (keyword_table->nonalpha_chars, *p)))
     ++p;
 
   if (p - start >= (int) sizeof (buf))
Index: devo/opcodes/cgen-opc.c
===================================================================
RCS file: /cvs/cvsfiles/devo/opcodes/cgen-opc.c,v
retrieving revision 1.27
diff -p -u -p -r1.27 cgen-opc.c
--- cgen-opc.c	2001/03/15 04:23:54	1.27
+++ cgen-opc.c	2001/06/14 00:56:39
@@ -118,6 +118,7 @@ cgen_keyword_add (kt, ke)
      CGEN_KEYWORD_ENTRY *ke;
 {
   unsigned int hash;
+  size_t i;
 
   if (kt->name_hash_table == NULL)
     build_keyword_hash_tables (kt);
@@ -132,6 +133,21 @@ cgen_keyword_add (kt, ke)
 
   if (ke->name[0] == 0)
     kt->null_entry = ke;
+
+  for (i = 0; i < strlen (ke->name); i++)
+    if (! isalnum ((unsigned char) ke->name[i])
+	&& ! strchr (kt->nonalpha_chars, ke->name[i]))
+      {
+	size_t idx = strlen (kt->nonalpha_chars);
+	
+	/* If you hit this limit, please don't just
+	   increase the size of the field, instead
+	   look for a better algorithm.  */
+	if (idx >= sizeof (kt->nonalpha_chars) - 1)
+	  abort ();
+	kt->nonalpha_chars[idx] = ke->name[i];
+	kt->nonalpha_chars[idx+1] = 0;
+      }
 }
 
 /* FIXME: Need function to return count of keywords.  */
Index: devo/cgen/desc.scm
===================================================================
RCS file: /cvs/cvsfiles/devo/cgen/desc.scm,v
retrieving revision 1.7
diff -p -u -p -r1.7 desc.scm
--- desc.scm	2000/12/04 18:20:56	1.7
+++ desc.scm	2001/06/14 00:56:40
@@ -137,7 +137,7 @@ static const CGEN_ATTR_ENTRY bool_attr[]
     " =\n{\n"
     "  & " (gen-hw-asm-ref (elm-get self 'name)) "_entries[0],\n"
     "  " (number->string (length (elm-get self 'values))) ",\n"
-    "  0, 0, 0, 0\n"
+    "  0, 0, 0, 0, \"\"\n"
     "};\n\n"
     )
    )
Index: devo/include/opcode/cgen.h
===================================================================
RCS file: /cvs/cvsfiles/devo/include/opcode/cgen.h,v
retrieving revision 1.57
diff -p -u -p -r1.57 cgen.h
--- cgen.h	2001/05/11 15:32:20	1.57
+++ cgen.h	2001/06/14 00:56:40
@@ -520,6 +520,11 @@ typedef struct cgen_keyword
   
   /* Pointer to null keyword "" entry if present.  */
   const CGEN_KEYWORD_ENTRY *null_entry;
+
+  /* String containing non-alphanumeric characters used
+     in keywords.  
+     At present, the highest number of entries used is 1.  */
+  char nonalpha_chars[8];
 } CGEN_KEYWORD;
 
 /* Structure used for searching.  */
============================================================


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