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]

CGEN patch: null keywords and very long lines



This patch changes the way cgen_parse_keywords handles very long
lines.  The problem occured with an instruction of the form:

        call<optional suffix> <address>

and a source line:

        call <a very long name>

where the very long name was a C++ mangled effort with more than 256
characters.

After matching "call", the parser uses cgen_parse_keyword to check
whether the suffix is used.  The absence of a suffix is indicated by a
null keyword.

In the case above, cgen_parse_keyword is passed the string:

        " <a very long name>"

The function lets a keyword start with any character, including a space,
so in this case it treats the rest of the line as a single keyword.  It
also has a 256-character internal buffer for storing the null-terminated
string that it's trying to match.  The problem is that the function
returns an error message when the keyword is too big for the buffer, so
it never tries to match the null keyword.

Two possible fixes are: (1) don't let a keyword start with a whitespace
character or (2) if the keyword is too long, try to match the null
keyword instead.  I've gone for the second, on the principle that it
makes the handling of long lines match the current handling of shorter
lines.  It also gets rid of a cut-and-pasted error message.

Patch tested on the internal port that showed up the problem and on fr30
(which has no null keywords, but still).  OK to apply?

	* cgen-asm.c (cgen_parse_keyword): If the keyword is too big to
	fit in the buffer, try to match the empty keyword.

Index: cgen-asm.c
===================================================================
RCS file: /cvs/src/src/opcodes/cgen-asm.c,v
retrieving revision 1.7
diff -c -p -d -r1.7 cgen-asm.c
*** cgen-asm.c	2001/09/19 17:40:28	1.7
--- cgen-asm.c	2001/11/09 11:03:35
*************** cgen_parse_keyword (cd, strp, keyword_ta
*** 229,238 ****
      ++p;
  
    if (p - start >= (int) sizeof (buf))
!     return _("unrecognized keyword/register name");
! 
!   memcpy (buf, start, p - start);
!   buf[p - start] = 0;
  
    ke = cgen_keyword_lookup_name (keyword_table, buf);
  
--- 229,244 ----
      ++p;
  
    if (p - start >= (int) sizeof (buf))
!     {
!       /* All non-empty CGEN keywords can fit into BUF.  The only thing
! 	 we can match here is the empty keyword.  */
!       buf[0] = 0;
!     }
!   else
!     {
!       memcpy (buf, start, p - start);
!       buf[p - start] = 0;
!     }
  
    ke = cgen_keyword_lookup_name (keyword_table, buf);
  


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