From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4697 invoked by alias); 29 Apr 2005 07:56:54 -0000 Mailing-List: contact binutils-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sources.redhat.com Received: (qmail 4444 invoked from network); 29 Apr 2005 07:56:35 -0000 Received: from unknown (HELO ausmtp02.au.ibm.com) (202.81.18.187) by sourceware.org with SMTP; 29 Apr 2005 07:56:35 -0000 Received: from sd0112e0.au.ibm.com (d23rh903.au.ibm.com [202.81.18.201]) by ausmtp02.au.ibm.com (8.12.10/8.12.10) with ESMTP id j3T7qXbP167796 for ; Fri, 29 Apr 2005 17:52:33 +1000 Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.250.242]) by sd0112e0.au.ibm.com (8.12.10/NCO/VER6.6) with ESMTP id j3T7x0dw132916 for ; Fri, 29 Apr 2005 17:59:01 +1000 Received: from d23av01.au.ibm.com (loopback [127.0.0.1]) by d23av01.au.ibm.com (8.12.11/8.13.3) with ESMTP id j3T7uFmh001201 for ; Fri, 29 Apr 2005 17:56:15 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.190.163.12]) by d23av01.au.ibm.com (8.12.11/8.12.11) with ESMTP id j3T7uFkp001189 for ; Fri, 29 Apr 2005 17:56:15 +1000 Received: from [10.61.2.237] (haven.au.ibm.com [9.190.164.82]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.au.ibm.com (Postfix) with ESMTP id 105D27354D for ; Fri, 29 Apr 2005 17:56:26 +1000 (EST) Message-ID: <4271E891.5090202@au.ibm.com> Date: Fri, 29 Apr 2005 08:21:00 -0000 From: Ben Elliston User-Agent: Debian Thunderbird 1.0.2 (X11/20050331) MIME-Version: 1.0 To: binutils@sources.redhat.com Subject: PATCH: use hashtab for pseudo op table Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigFB977C42F85785222A898858" X-SW-Source: 2005-04/txt/msg00875.txt.bz2 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigFB977C42F85785222A898858 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-length: 5728 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 * 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. --------------enigFB977C42F85785222A898858 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" Content-length: 256 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCceibMGpskFPkywkRAiZ0AKC/Mo5WUQIz3Kwucu+zKZOWCySORACePiKU nSJKgxAFhCn83b/+N++wl+I= =8/3V -----END PGP SIGNATURE----- --------------enigFB977C42F85785222A898858--