This is the mail archive of the
cgen@sources.redhat.com
mailing list for the CGEN project.
Switch to using safe-ctype.h
- To: cgen at sources dot redhat dot com
- Subject: Switch to using safe-ctype.h
- From: Nick Clifton <nickc at cambridge dot redhat dot com>
- Date: 13 Oct 2001 10:33:42 +0100
Hi Guys,
Bruno Haible's recent patch to fix the case insenstivity of the cgen
instruction parser introduced the use of the safe-ctype.h header to
cgen generated files. Unfortunately some cgen files use ctype.h and
this is incompatable. The patch below fixes this problem by
changing them to use safe-ctype.h.
The patch also fixes a bug in Bruno's patch which would duplicate
all of the literals in the syntax regular expression, preventing
them from matching real instructions!
Applied as an obvious fix.
Cheers
Nick
cgen
2001-10-13 Nick Clifton <nickc@cambridge.redhat.com>
* desc-cpu.scm: Do not include ctype.h in generated desc
files. They will inherit safe-ctype.h instead.
opcodes
2001-10-13 Nick Clifton <nickc@cambridge.redhat.com>
* cgen-ibld.in: Include safe-ctype.h in preference to
ctype.h.
* cgen-asm.in: Include safe-ctype.h in preference to
ctype.h. Fix formatting. Use ISSPACE instead of isspace and
TOLOWER instead of tolower.
(@arch@_cgen_build_insn_regex): Remove duplication of syntax
string elements in constructed regular expression.
* fr30-asm.c: Regenerate.
* fr30-desc.c: Regenerate.
* fr30-ibld.c: Regenerate.
* m32r-asm.c: Regenerate.
* m32r-desc.c: Regenerate.
* m32r-ibld.c: Regenerate.
* openrisc-asm.c: Regenerate.
* openrisc-desc.c: Regenerate.
* openrisc-ibld.c: Regenerate.
* po/opcodes.pot: Regenerate.
Index: cgen/desc-cpu.scm
===================================================================
RCS file: /cvs/src/src/cgen/desc-cpu.scm,v
retrieving revision 1.9
diff -p -r1.9 desc-cpu.scm
*** desc-cpu.scm 2001/10/09 08:24:22 1.9
--- desc-cpu.scm 2001/10/13 09:20:20
*************** init_tables ()
*** 946,952 ****
CURRENT-COPYRIGHT CURRENT-PACKAGE)
"\
#include \"sysdep.h\"
- #include <ctype.h>
#include <stdio.h>
#include <stdarg.h>
#include \"ansidecl.h\"
--- 946,951 ----
Index: opcodes/cgen-ibld.in
===================================================================
RCS file: /cvs/src/src/opcodes/cgen-ibld.in,v
retrieving revision 1.12
diff -p -r1.12 cgen-ibld.in
*** cgen-ibld.in 2001/10/09 08:54:57 1.12
--- cgen-ibld.in 2001/10/13 09:28:43
*************** along with this program; if not, write t
*** 25,31 ****
Keep that in mind. */
#include "sysdep.h"
- #include <ctype.h>
#include <stdio.h>
#include "ansidecl.h"
#include "dis-asm.h"
--- 25,30 ----
*************** along with this program; if not, write t
*** 34,39 ****
--- 33,39 ----
#include "@prefix@-desc.h"
#include "@prefix@-opc.h"
#include "opintl.h"
+ #include "safe-ctype.h"
#undef min
#define min(a,b) ((a) < (b) ? (a) : (b))
Index: opcodes/cgen-asm.in
===================================================================
RCS file: /cvs/src/src/opcodes/cgen-asm.in,v
retrieving revision 1.9
diff -p -r1.9 cgen-asm.in
*** cgen-asm.in 2001/10/10 09:13:05 1.9
--- cgen-asm.in 2001/10/13 09:28:28
*************** along with this program; if not, write t
*** 26,32 ****
Keep that in mind. */
#include "sysdep.h"
- #include <ctype.h>
#include <stdio.h>
#include "ansidecl.h"
#include "bfd.h"
--- 26,31 ----
*************** along with this program; if not, write t
*** 36,64 ****
#include "opintl.h"
#include "xregex.h"
#include "libiberty.h"
! #undef min
#define min(a,b) ((a) < (b) ? (a) : (b))
! #undef max
#define max(a,b) ((a) > (b) ? (a) : (b))
static const char * parse_insn_normal
PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *, const char **, CGEN_FIELDS *));
! /* -- assembler routines inserted here */
! /*
! Regex construction routine.
! This translates an opcode syntax string into a regex string,
! by replacing any non-character syntax element (such as an
! opcode) with the pattern '.*'
! It then compiles the regex and stores it in the opcode, for
! later use by @arch@_cgen_assemble_insn
! Returns NULL for success, an error message for failure. */
char *
@arch@_cgen_build_insn_regex (insn)
--- 35,63 ----
#include "opintl.h"
#include "xregex.h"
#include "libiberty.h"
+ #include "safe-ctype.h"
! #undef min
#define min(a,b) ((a) < (b) ? (a) : (b))
! #undef max
#define max(a,b) ((a) > (b) ? (a) : (b))
static const char * parse_insn_normal
PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *, const char **, CGEN_FIELDS *));
! /* -- assembler routines inserted here. */
! /* Regex construction routine.
! This translates an opcode syntax string into a regex string,
! by replacing any non-character syntax element (such as an
! opcode) with the pattern '.*'
! It then compiles the regex and stores it in the opcode, for
! later use by @arch@_cgen_assemble_insn
! Returns NULL for success, an error message for failure. */
char *
@arch@_cgen_build_insn_regex (insn)
*************** char *
*** 66,72 ****
{
CGEN_OPCODE *opc = (CGEN_OPCODE *) CGEN_INSN_OPCODE (insn);
const char *mnem = CGEN_INSN_MNEMONIC (insn);
- int mnem_len;
char rxbuf[CGEN_MAX_RX_ELEMENTS];
char *rx = rxbuf;
const CGEN_SYNTAX_CHAR_TYPE *syn;
--- 65,70 ----
*************** char *
*** 134,142 ****
*rx++ = c;
break;
}
-
- /* Insert syntax char into rx. */
- *rx++ = c;
}
else
{
--- 132,137 ----
*************** char *
*** 170,176 ****
regfree ((regex_t *) CGEN_INSN_RX (insn));
free (CGEN_INSN_RX (insn));
(CGEN_INSN_RX (insn)) = NULL;
! return msg;
}
}
--- 165,171 ----
regfree ((regex_t *) CGEN_INSN_RX (insn));
free (CGEN_INSN_RX (insn));
(CGEN_INSN_RX (insn)) = NULL;
! return msg;
}
}
*************** parse_insn_normal (cd, insn, strp, field
*** 211,224 ****
GAS's input scrubber will ensure mnemonics are lowercase, but we may
not be called from GAS. */
p = CGEN_INSN_MNEMONIC (insn);
! while (*p && tolower (*p) == tolower (*str))
++p, ++str;
if (* p)
return _("unrecognized instruction");
#ifndef CGEN_MNEMONIC_OPERANDS
! if (* str && !isspace (* str))
return _("unrecognized instruction");
#endif
--- 206,219 ----
GAS's input scrubber will ensure mnemonics are lowercase, but we may
not be called from GAS. */
p = CGEN_INSN_MNEMONIC (insn);
! while (*p && TOLOWER (*p) == TOLOWER (*str))
++p, ++str;
if (* p)
return _("unrecognized instruction");
#ifndef CGEN_MNEMONIC_OPERANDS
! if (* str && ! ISSPACE (* str))
return _("unrecognized instruction");
#endif
*************** parse_insn_normal (cd, insn, strp, field
*** 247,253 ****
first char after the mnemonic part is a space. */
/* FIXME: We also take inappropriate advantage of the fact that
GAS's input scrubber will remove extraneous blanks. */
! if (tolower (*str) == tolower (CGEN_SYNTAX_CHAR (* syn)))
{
#ifdef CGEN_MNEMONIC_OPERANDS
if (CGEN_SYNTAX_CHAR(* syn) == ' ')
--- 242,248 ----
first char after the mnemonic part is a space. */
/* FIXME: We also take inappropriate advantage of the fact that
GAS's input scrubber will remove extraneous blanks. */
! if (TOLOWER (*str) == TOLOWER (CGEN_SYNTAX_CHAR (* syn)))
{
#ifdef CGEN_MNEMONIC_OPERANDS
if (CGEN_SYNTAX_CHAR(* syn) == ' ')
*************** parse_insn_normal (cd, insn, strp, field
*** 296,302 ****
blanks now. IE: We needn't try again with a longer version of
the insn and it is assumed that longer versions of insns appear
before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
! while (isspace (* str))
++ str;
if (* str != '\0')
--- 291,297 ----
blanks now. IE: We needn't try again with a longer version of
the insn and it is assumed that longer versions of insns appear
before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
! while (ISSPACE (* str))
++ str;
if (* str != '\0')
*************** const CGEN_INSN *
*** 345,351 ****
int recognized_mnemonic = 0;
/* Skip leading white space. */
! while (isspace (* str))
++ str;
/* The instructions are stored in hashed lists.
--- 340,346 ----
int recognized_mnemonic = 0;
/* Skip leading white space. */
! while (ISSPACE (* str))
++ str;
/* The instructions are stored in hashed lists.