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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH: use hashtab for pseudo op table


This patch is a first step toward eliminating the use of gas/hash.c in favour of
libiberty's hashtab.  Tested with an all-targets `make check' in the gas directory.

Okay for mainline?

2005-04-29  Ben Elliston  <bje@au.ibm.com>

	* read.c (po_hash): Change type to htab_t.
	(pop_override_ok): Remove unneeded global variable.
	(pop_insert): Use htab functions for insertion.
	(pobegin): Use htab_create_alloc. Remove uses of pop_override_ok.
	(hash_pseudo): New static function.
	(pseudo_equal_p): Likewise.
	(read_print_statistics): Remove.
	(read_a_source_file): Use htab_find.
	(s_macro): Likewise.
	* as.c (dump_statistics): Don't call read_print_statistics ().

Index: as.c
===================================================================
RCS file: /home/bje/src-cvs/src/gas/as.c,v
retrieving revision 1.61
diff -u -p -r1.61 as.c
--- as.c	29 Apr 2005 00:22:26 -0000	1.61
+++ as.c	29 Apr 2005 07:54:18 -0000
@@ -926,7 +926,6 @@ dump_statistics (void)
   subsegs_print_statistics (stderr);
   write_print_statistics (stderr);
   symbol_print_statistics (stderr);
-  read_print_statistics (stderr);

 #ifdef tc_print_statistics
   tc_print_statistics (stderr);
Index: read.c
===================================================================
RCS file: /home/bje/src-cvs/src/gas/read.c,v
retrieving revision 1.100
diff -u -p -r1.100 read.c
--- read.c	29 Apr 2005 00:22:26 -0000	1.100
+++ read.c	29 Apr 2005 07:54:18 -0000
@@ -41,6 +41,7 @@ Software Foundation, 59 Temple Place - S
 #include "listing.h"
 #include "ecoff.h"
 #include "dw2gencfi.h"
+#include "hashtab.h"

 #ifndef TC_START_LABEL
 #define TC_START_LABEL(x,y) (x == ':')
@@ -264,7 +265,7 @@ address_bytes (void)

 /* Set up pseudo-op tables.  */

-static struct hash_control *po_hash;
+static htab_t po_hash;

 static const pseudo_typeS potable[] = {
   {"abort", s_abort, 0},
@@ -460,20 +461,27 @@ get_absolute_expression (void)
   return get_absolute_expr (&exp);
 }

-static int pop_override_ok = 0;
 static const char *pop_table_name;

 void
 pop_insert (const pseudo_typeS *table)
 {
-  const char *errtxt;
+  void **slot;
   const pseudo_typeS *pop;
+  pseudo_typeS *found;
+
   for (pop = table; pop->poc_name; pop++)
     {
-      errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop);
-      if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists")))
-	as_fatal (_("error constructing %s pseudo-op table: %s"), pop_table_name,
-		  errtxt);
+      found = htab_find (po_hash, (const void *) pop);
+      if (found)
+	continue;
+
+      slot = htab_find_slot (po_hash, (const void *) pop, INSERT);
+      if (!slot)
+	as_fatal (_("error allocating %s in %s pseudo-op table"),
+		  pop->poc_name, pop_table_name);
+
+      *(const pseudo_typeS **) slot = pop;
     }
 }

@@ -489,10 +497,28 @@ pop_insert (const pseudo_typeS *table)
 #define cfi_pop_insert()	pop_insert(cfi_pseudo_table)
 #endif

+
+static hashval_t
+hash_pseudo (const PTR p)
+{
+  return htab_hash_string (((pseudo_typeS *) p)->poc_name);
+}
+
+/* Returns non-zero if P1 and P2 are equal.  */
+
+static int
+pseudo_equal_p (const PTR p1, const PTR p2)
+{
+  pseudo_typeS *pt1 = (pseudo_typeS *) p1;
+  pseudo_typeS *pt2 = (pseudo_typeS *) p2;
+  return (strcmp (pt1->poc_name, pt2->poc_name) == 0);
+}
+
 static void
 pobegin (void)
 {
-  po_hash = hash_new ();
+  po_hash = htab_create_alloc (50, hash_pseudo, pseudo_equal_p,
+			       NULL, calloc, free);

   /* Do the target-specific pseudo ops.  */
   pop_table_name = "md";
@@ -500,7 +526,6 @@ pobegin (void)

   /* Now object specific.  Skip any that were in the target table.  */
   pop_table_name = "obj";
-  pop_override_ok = 1;
   obj_pop_insert ();

   /* Now portable ones.  Skip any that we've seen already.  */
@@ -509,7 +534,6 @@ pobegin (void)

 #ifdef TARGET_USE_CFIPOP
   pop_table_name = "cfi";
-  pop_override_ok = 1;
   cfi_pop_insert ();
 #endif
 }
@@ -822,7 +846,9 @@ read_a_source_file (char *name)
 		    {
 		      /* The MRI assembler and the m88k use pseudo-ops
 			 without a period.  */
-		      pop = (pseudo_typeS *) hash_find (po_hash, s);
+		      pseudo_typeS ptype;
+		      ptype.poc_name = s;
+		      pop = (pseudo_typeS *) htab_find (po_hash, &ptype);
 		      if (pop != NULL && pop->poc_handler == NULL)
 			pop = NULL;
 		    }
@@ -836,8 +862,11 @@ read_a_source_file (char *name)
 			 We lookup the pseudo-op table with s+1 because we
 			 already know that the pseudo-op begins with a '.'.  */

+		      pseudo_typeS ptype;
+		      ptype.poc_name = s + 1;
+
 		      if (pop == NULL)
-			pop = (pseudo_typeS *) hash_find (po_hash, s + 1);
+			pop = (pseudo_typeS *) htab_find (po_hash, &ptype);
 		      if (pop && !pop->poc_handler)
 			pop = NULL;

@@ -2365,6 +2394,10 @@ s_macro (int ignore ATTRIBUTE_UNUSED)
     as_bad_where (file, line, err, name);
   else
     {
+      pseudo_typeS ptype, ptype1;
+      ptype.poc_name = name;
+      ptype1.poc_name = name + 1;
+
       if (line_label != NULL)
 	{
 	  S_SET_SEGMENT (line_label, absolute_section);
@@ -2373,10 +2406,10 @@ s_macro (int ignore ATTRIBUTE_UNUSED)
 	}

       if (((NO_PSEUDO_DOT || flag_m68k_mri)
-	   && hash_find (po_hash, name) != NULL)
+	   && htab_find (po_hash, &ptype) != NULL)
 	  || (!flag_m68k_mri
 	      && *name == '.'
-	      && hash_find (po_hash, name + 1) != NULL))
+	      && htab_find (po_hash, &ptype1) != NULL))
 	as_warn_where (file,
 		 line,
 		 _("attempt to redefine pseudo-op `%s' ignored"),
@@ -5296,12 +5329,6 @@ s_ignore (int arg ATTRIBUTE_UNUSED)
       ++input_line_pointer;
     }
   ++input_line_pointer;
-}
-
-void
-read_print_statistics (FILE *file)
-{
-  hash_print_statistics (file, "pseudo-op table", po_hash);
 }

 /* Inserts the given line into the input stream.

Attachment: signature.asc
Description: OpenPGP digital signature


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