Changeset 609 for branches/GNU/src/binutils/opcodes/cgen-asm.in
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/opcodes/cgen-asm.in
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 27 27 28 28 #include "sysdep.h" 29 #include <ctype.h>30 29 #include <stdio.h> 31 30 #include "ansidecl.h" … … 35 34 #include "@prefix@-opc.h" 36 35 #include "opintl.h" 37 38 #undef min 36 #include "xregex.h" 37 #include "libiberty.h" 38 #include "safe-ctype.h" 39 40 #undef min 39 41 #define min(a,b) ((a) < (b) ? (a) : (b)) 40 #undef max42 #undef max 41 43 #define max(a,b) ((a) > (b) ? (a) : (b)) 42 44 … … 45 47 46 48 47 /* -- assembler routines inserted here */ 49 /* -- assembler routines inserted here. */ 50 51 52 53 /* Regex construction routine. 54 55 This translates an opcode syntax string into a regex string, 56 by replacing any non-character syntax element (such as an 57 opcode) with the pattern '.*' 58 59 It then compiles the regex and stores it in the opcode, for 60 later use by @arch@_cgen_assemble_insn 61 62 Returns NULL for success, an error message for failure. */ 63 64 char * 65 @arch@_cgen_build_insn_regex (insn) 66 CGEN_INSN *insn; 67 { 68 CGEN_OPCODE *opc = (CGEN_OPCODE *) CGEN_INSN_OPCODE (insn); 69 const char *mnem = CGEN_INSN_MNEMONIC (insn); 70 char rxbuf[CGEN_MAX_RX_ELEMENTS]; 71 char *rx = rxbuf; 72 const CGEN_SYNTAX_CHAR_TYPE *syn; 73 int reg_err; 74 75 syn = CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc)); 76 77 /* Mnemonics come first in the syntax string. */ 78 if (! CGEN_SYNTAX_MNEMONIC_P (* syn)) 79 return _("missing mnemonic in syntax string"); 80 ++syn; 81 82 /* Generate a case sensitive regular expression that emulates case 83 insensitive matching in the "C" locale. We cannot generate a case 84 insensitive regular expression because in Turkish locales, 'i' and 'I' 85 are not equal modulo case conversion. */ 86 87 /* Copy the literal mnemonic out of the insn. */ 88 for (; *mnem; mnem++) 89 { 90 char c = *mnem; 91 92 if (ISALPHA (c)) 93 { 94 *rx++ = '['; 95 *rx++ = TOLOWER (c); 96 *rx++ = TOUPPER (c); 97 *rx++ = ']'; 98 } 99 else 100 *rx++ = c; 101 } 102 103 /* Copy any remaining literals from the syntax string into the rx. */ 104 for(; * syn != 0 && rx <= rxbuf + (CGEN_MAX_RX_ELEMENTS - 7 - 4); ++syn) 105 { 106 if (CGEN_SYNTAX_CHAR_P (* syn)) 107 { 108 char c = CGEN_SYNTAX_CHAR (* syn); 109 110 switch (c) 111 { 112 /* Escape any regex metacharacters in the syntax. */ 113 case '.': case '[': case '\\': 114 case '*': case '^': case '$': 115 116 #ifdef CGEN_ESCAPE_EXTENDED_REGEX 117 case '?': case '{': case '}': 118 case '(': case ')': case '*': 119 case '|': case '+': case ']': 120 #endif 121 *rx++ = '\\'; 122 *rx++ = c; 123 break; 124 125 default: 126 if (ISALPHA (c)) 127 { 128 *rx++ = '['; 129 *rx++ = TOLOWER (c); 130 *rx++ = TOUPPER (c); 131 *rx++ = ']'; 132 } 133 else 134 *rx++ = c; 135 break; 136 } 137 } 138 else 139 { 140 /* Replace non-syntax fields with globs. */ 141 *rx++ = '.'; 142 *rx++ = '*'; 143 } 144 } 145 146 /* Trailing whitespace ok. */ 147 * rx++ = '['; 148 * rx++ = ' '; 149 * rx++ = '\t'; 150 * rx++ = ']'; 151 * rx++ = '*'; 152 153 /* But anchor it after that. */ 154 * rx++ = '$'; 155 * rx = '\0'; 156 157 CGEN_INSN_RX (insn) = xmalloc (sizeof (regex_t)); 158 reg_err = regcomp ((regex_t *) CGEN_INSN_RX (insn), rxbuf, REG_NOSUB); 159 160 if (reg_err == 0) 161 return NULL; 162 else 163 { 164 static char msg[80]; 165 166 regerror (reg_err, (regex_t *) CGEN_INSN_RX (insn), msg, 80); 167 regfree ((regex_t *) CGEN_INSN_RX (insn)); 168 free (CGEN_INSN_RX (insn)); 169 (CGEN_INSN_RX (insn)) = NULL; 170 return msg; 171 } 172 } 173 48 174 49 175 … … 59 185 expensive in the case of the m68k. Deal with later. 60 186 61 Returns NULL for success, an error message for failure. 62 */ 187 Returns NULL for success, an error message for failure. */ 63 188 64 189 static const char * … … 85 210 not be called from GAS. */ 86 211 p = CGEN_INSN_MNEMONIC (insn); 87 while (*p && tolower (*p) == tolower(*str))212 while (*p && TOLOWER (*p) == TOLOWER (*str)) 88 213 ++p, ++str; 89 214 … … 92 217 93 218 #ifndef CGEN_MNEMONIC_OPERANDS 94 if (* str && ! isspace(* str))219 if (* str && ! ISSPACE (* str)) 95 220 return _("unrecognized instruction"); 96 221 #endif … … 121 246 /* FIXME: We also take inappropriate advantage of the fact that 122 247 GAS's input scrubber will remove extraneous blanks. */ 123 if ( tolower (*str) == tolower(CGEN_SYNTAX_CHAR (* syn)))248 if (TOLOWER (*str) == TOLOWER (CGEN_SYNTAX_CHAR (* syn))) 124 249 { 125 250 #ifdef CGEN_MNEMONIC_OPERANDS … … 134 259 /* Syntax char didn't match. Can't be this insn. */ 135 260 static char msg [80]; 261 136 262 /* xgettext:c-format */ 137 263 sprintf (msg, _("syntax error (expected char `%c', found `%c')"), … … 143 269 /* Ran out of input. */ 144 270 static char msg [80]; 271 145 272 /* xgettext:c-format */ 146 273 sprintf (msg, _("syntax error (expected char `%c', found end of instruction)"), … … 152 279 153 280 /* We have an operand of some sort. */ 154 errmsg = @arch@_cgen_parse_operand (cd, CGEN_SYNTAX_FIELD (*syn),281 errmsg = cd->parse_operand (cd, CGEN_SYNTAX_FIELD (*syn), 155 282 &str, fields); 156 283 if (errmsg) … … 168 295 the insn and it is assumed that longer versions of insns appear 169 296 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */ 170 while ( isspace(* str))297 while (ISSPACE (* str)) 171 298 ++ str; 172 299 … … 215 342 const char *parse_errmsg = NULL; 216 343 const char *insert_errmsg = NULL; 344 int recognized_mnemonic = 0; 217 345 218 346 /* Skip leading white space. */ 219 while ( isspace(* str))347 while (ISSPACE (* str)) 220 348 ++ str; 221 349 … … 225 353 226 354 /* Keep looking until we find a match. */ 227 228 355 start = str; 229 356 for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist)) 230 357 { 231 358 const CGEN_INSN *insn = ilist->insn; 359 recognized_mnemonic = 1; 232 360 233 361 #ifdef CGEN_VALIDATE_INSN_SUPPORTED 234 /* not usually needed as unsupported opcodes shouldn't be in the hash lists */ 362 /* Not usually needed as unsupported opcodes 363 shouldn't be in the hash lists. */ 235 364 /* Is this insn supported by the selected cpu? */ 236 365 if (! @arch@_cgen_insn_supported (cd, insn)) 237 366 continue; 238 367 #endif 239 240 368 /* If the RELAX attribute is set, this is an insn that shouldn't be 241 369 chosen immediately. Instead, it is used during assembler/linker … … 246 374 str = start; 247 375 376 /* Skip this insn if str doesn't look right lexically. */ 377 if (CGEN_INSN_RX (insn) != NULL && 378 regexec ((regex_t *) CGEN_INSN_RX (insn), str, 0, NULL, 0) == REG_NOMATCH) 379 continue; 380 248 381 /* Allow parse/insert handlers to obtain length of insn. */ 249 382 CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn); … … 253 386 continue; 254 387 255 /* ??? 0 is passed for `pc' */388 /* ??? 0 is passed for `pc'. */ 256 389 insert_errmsg = CGEN_INSERT_FN (cd, insn) (cd, insn, fields, buf, 257 390 (bfd_vma) 0); … … 266 399 { 267 400 static char errbuf[150]; 401 #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS 268 402 const char *tmp_errmsg; 269 403 270 #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS271 404 /* If requesting verbose error messages, use insert_errmsg. 272 Failing that, use parse_errmsg */405 Failing that, use parse_errmsg. */ 273 406 tmp_errmsg = (insert_errmsg ? insert_errmsg : 274 407 parse_errmsg ? parse_errmsg : 408 recognized_mnemonic ? 409 _("unrecognized form of instruction") : 275 410 _("unrecognized instruction")); 276 411 -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.