From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28963 invoked by alias); 2 Dec 2010 19:21:35 -0000 Received: (qmail 28944 invoked by uid 22791); 2 Dec 2010 19:21:34 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,TW_CP,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 02 Dec 2010 19:21:27 +0000 Received: (qmail 24725 invoked from network); 2 Dec 2010 19:21:25 -0000 Received: from unknown (HELO tp.orcam.me.uk) (macro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 2 Dec 2010 19:21:25 -0000 Date: Thu, 02 Dec 2010 19:21:00 -0000 From: "Maciej W. Rozycki" To: Richard Sandiford cc: Catherine Moore , binutils@sourceware.org Subject: [PATCH 13/20] MIPS/GAS: Improve instruction's mnemonic processing Message-ID: User-Agent: Alpine 1.10 (DEB 962 2008-03-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2010-12/txt/msg00107.txt.bz2 Hi Richard, Following your earlier comment addressing microMIPS code: On Sun, 23 May 2010, Richard Sandiford wrote: > Message-ID: <87y6fa9u3t.fsf@firetop.home> > You could use alloca to create an opcode without the "16" or "32", > which would make the error-reporting code simpler. It's best not > to change the user's source line if we can help it. I have made a complementing adjustment to original code currently present in mips_ip(), making the whole piece much simpler and less fragile. 2010-12-02 Maciej W. Rozycki gas/ * config/tc-mips.c (mips_ip): Make a copy of the instruction's mnemonic and use it for further processing. OK to apply? Maciej binutils-gas-mips-ip-insn-copy.diff Index: binutils-fsf-trunk-quilt/gas/config/tc-mips.c =================================================================== --- binutils-fsf-trunk-quilt.orig/gas/config/tc-mips.c 2010-12-02 01:48:16.000000000 +0000 +++ binutils-fsf-trunk-quilt/gas/config/tc-mips.c 2010-12-02 01:49:28.000000000 +0000 @@ -8642,67 +8642,54 @@ mips_ip (char *str, struct mips_cl_insn unsigned int lastpos = 0; unsigned int limlo, limhi; char *s_reset; - char save_c = 0; offsetT min_range, max_range; + char *name; int argnum; unsigned int rtype; + char *dot; + long end; insn_error = NULL; + insn = NULL; + /* If the instruction contains a '.', we first try to match an instruction including the '.'. Then we try again without the '.'. */ - insn = NULL; - for (s = str; *s != '\0' && !ISSPACE (*s); ++s) + for (end = 0; str[end] != '\0' && !ISSPACE (str[end]); end++) continue; - /* If we stopped on whitespace, then replace the whitespace with null for - the call to hash_find. Save the character we replaced just in case we - have to re-parse the instruction. */ - if (ISSPACE (*s)) + /* Make a copy of the instruction so that we can fiddle with it. */ + name = alloca (end + 1); + memcpy (name, str, end); + name[end] = '\0'; + + for (;;) { - save_c = *s; - *s++ = '\0'; - } + insn = (struct mips_opcode *) hash_find (op_hash, name); - insn = (struct mips_opcode *) hash_find (op_hash, str); + if (insn != NULL) + break; - /* If we didn't find the instruction in the opcode table, try again, but - this time with just the instruction up to, but not including the - first '.'. */ + /* If we didn't find the instruction in the opcode table, try again, + but this time with just the instruction up to, but not including + the first '.'. */ + dot = strchr (name, '.'); + if (dot == NULL) + break; + *dot = '\0'; + } if (insn == NULL) { - /* Restore the character we overwrite above (if any). */ - if (save_c) - *(--s) = save_c; - - /* Scan up to the first '.' or whitespace. */ - for (s = str; - *s != '\0' && *s != '.' && !ISSPACE (*s); - ++s) - continue; - - /* If we did not find a '.', then we can quit now. */ - if (*s != '.') - { - insn_error = _("Unrecognized opcode"); - return; - } - - /* Lookup the instruction in the hash table. */ - *s++ = '\0'; - if ((insn = (struct mips_opcode *) hash_find (op_hash, str)) == NULL) - { - insn_error = _("Unrecognized opcode"); - return; - } + insn_error = _("Unrecognized opcode"); + return; } - argsStart = s; + argsStart = s = str + end; for (;;) { bfd_boolean ok; - gas_assert (strcmp (insn->name, str) == 0); + gas_assert (strcmp (insn->name, name) == 0); ok = is_opcode_valid (insn); if (! ok) @@ -8724,8 +8711,6 @@ mips_ip (char *str, struct mips_cl_insn mips_cpu_info_from_isa (mips_opts.isa)->name); insn_error = buf; } - if (save_c) - *(--s) = save_c; return; } } @@ -10114,8 +10099,6 @@ mips_ip (char *str, struct mips_cl_insn insn_error = _("Illegal operands"); continue; } - if (save_c) - *(--argsStart) = save_c; insn_error = _("Illegal operands"); return; }