1 /* Assembler interface for targets using CGEN. -*- C -*-
2 CGEN: Cpu tools GENerator
4 THIS FILE IS MACHINE GENERATED WITH CGEN.
5 - the resultant file is machine generated, cgen-asm.in isn't
7 Copyright 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
9 This file is part of the GNU Binutils and GDB, the GNU debugger.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2, or (at your option)
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software Foundation, Inc.,
23 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 /* ??? Eventually more and more of this stuff can go to cpu-independent files.
37 #include "libiberty.h"
38 #include "safe-ctype.h"
41 #define min(a,b) ((a) < (b) ? (a) : (b))
43 #define max(a,b) ((a) > (b) ? (a) : (b))
45 static const char * parse_insn_normal
46 PARAMS ((CGEN_CPU_DESC
, const CGEN_INSN
*, const char **, CGEN_FIELDS
*));
48 /* -- assembler routines inserted here. */
51 static const char * parse_ulo16
52 PARAMS ((CGEN_CPU_DESC
, const char **, int, unsigned long *));
53 static const char * parse_uslo16
54 PARAMS ((CGEN_CPU_DESC
, const char **, int, unsigned long *));
55 static const char * parse_uhi16
56 PARAMS ((CGEN_CPU_DESC
, const char **, int, unsigned long *));
57 static long parse_register_number
58 PARAMS ((const char **));
59 static const char * parse_spr
60 PARAMS ((CGEN_CPU_DESC
, const char **, CGEN_KEYWORD
*, long *));
61 static const char * parse_d12
62 PARAMS ((CGEN_CPU_DESC
, const char **, int, long *));
63 static const char * parse_s12
64 PARAMS ((CGEN_CPU_DESC
, const char **, int, long *));
65 static const char * parse_u12
66 PARAMS ((CGEN_CPU_DESC
, const char **, int, long *));
69 parse_ulo16 (cd
, strp
, opindex
, valuep
)
73 unsigned long *valuep
;
76 enum cgen_parse_operand_result result_type
;
79 if (**strp
== '#' || **strp
== '%')
81 if (strncasecmp (*strp
+ 1, "lo(", 3) == 0)
84 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_LO16
,
85 &result_type
, &value
);
90 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
95 if (strncasecmp (*strp
+ 1, "gprello(", 8) == 0)
98 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_GPRELLO
,
99 &result_type
, &value
);
101 return "missing ')'";
104 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
110 return cgen_parse_signed_integer (cd
, strp
, opindex
, valuep
);
114 parse_uslo16 (cd
, strp
, opindex
, valuep
)
118 unsigned long *valuep
;
121 enum cgen_parse_operand_result result_type
;
124 if (**strp
== '#' || **strp
== '%')
126 if (strncasecmp (*strp
+ 1, "lo(", 3) == 0)
129 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_LO16
,
130 &result_type
, &value
);
132 return "missing `)'";
135 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
140 else if (strncasecmp (*strp
+ 1, "gprello(", 8) == 0)
143 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_GPRELLO
,
144 &result_type
, &value
);
146 return "missing ')'";
149 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
155 return cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
159 parse_uhi16 (cd
, strp
, opindex
, valuep
)
163 unsigned long *valuep
;
166 enum cgen_parse_operand_result result_type
;
169 if (**strp
== '#' || **strp
== '%')
171 if (strncasecmp (*strp
+ 1, "hi(", 3) == 0)
174 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_HI16
,
175 &result_type
, &value
);
177 return "missing `)'";
180 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
185 else if (strncasecmp (*strp
+ 1, "gprelhi(", 8) == 0)
188 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_GPRELHI
,
189 &result_type
, &value
);
191 return "missing ')'";
194 && result_type
== CGEN_PARSE_OPERAND_RESULT_NUMBER
)
200 return cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
204 parse_register_number (strp
)
208 if (**strp
< '0' || **strp
> '9')
209 return -1; /* error */
211 regno
= **strp
- '0';
212 for (++*strp
; **strp
>= '0' && **strp
<= '9'; ++*strp
)
213 regno
= regno
* 10 + (**strp
- '0');
219 parse_spr (cd
, strp
, table
, valuep
)
222 CGEN_KEYWORD
* table
;
225 const char *save_strp
;
228 /* Check for spr index notation. */
229 if (strncasecmp (*strp
, "spr[", 4) == 0)
232 regno
= parse_register_number (strp
);
234 return "missing `]'";
236 if (! spr_valid (regno
))
237 return "Special purpose register number is out of range";
243 regno
= parse_register_number (strp
);
246 if (! spr_valid (regno
))
247 return "Special purpose register number is out of range";
253 return cgen_parse_keyword (cd
, strp
, table
, valuep
);
257 parse_d12 (cd
, strp
, opindex
, valuep
)
264 enum cgen_parse_operand_result result_type
;
267 /* Check for small data reference. */
268 if (**strp
== '#' || **strp
== '%')
270 if (strncasecmp (*strp
+ 1, "gprel12(", 8) == 0)
273 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_GPREL12
,
274 &result_type
, &value
);
276 return "missing `)'";
282 return cgen_parse_signed_integer (cd
, strp
, opindex
, valuep
);
286 parse_s12 (cd
, strp
, opindex
, valuep
)
293 enum cgen_parse_operand_result result_type
;
296 /* Check for small data reference. */
297 if ((**strp
== '#' || **strp
== '%')
298 && strncasecmp (*strp
+ 1, "gprel12(", 8) == 0)
301 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_GPREL12
,
302 &result_type
, &value
);
304 return "missing `)'";
313 return cgen_parse_signed_integer (cd
, strp
, opindex
, valuep
);
318 parse_u12 (cd
, strp
, opindex
, valuep
)
325 enum cgen_parse_operand_result result_type
;
328 /* Check for small data reference. */
329 if ((**strp
== '#' || **strp
== '%')
330 && strncasecmp (*strp
+ 1, "gprel12(", 8) == 0)
333 errmsg
= cgen_parse_address (cd
, strp
, opindex
, BFD_RELOC_FRV_GPRELU12
,
334 &result_type
, &value
);
336 return "missing `)'";
345 return cgen_parse_signed_integer (cd
, strp
, opindex
, valuep
);
351 const char * frv_cgen_parse_operand
352 PARAMS ((CGEN_CPU_DESC
, int, const char **, CGEN_FIELDS
*));
354 /* Main entry point for operand parsing.
356 This function is basically just a big switch statement. Earlier versions
357 used tables to look up the function to use, but
358 - if the table contains both assembler and disassembler functions then
359 the disassembler contains much of the assembler and vice-versa,
360 - there's a lot of inlining possibilities as things grow,
361 - using a switch statement avoids the function call overhead.
363 This function could be moved into `parse_insn_normal', but keeping it
364 separate makes clear the interface between `parse_insn_normal' and each of
368 frv_cgen_parse_operand (cd
, opindex
, strp
, fields
)
372 CGEN_FIELDS
* fields
;
374 const char * errmsg
= NULL
;
375 /* Used by scalar operands that still need to be parsed. */
376 long junk ATTRIBUTE_UNUSED
;
381 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_A
, &fields
->f_A
);
383 case FRV_OPERAND_ACC40SI
:
384 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_acc_names
, & fields
->f_ACC40Si
);
386 case FRV_OPERAND_ACC40SK
:
387 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_acc_names
, & fields
->f_ACC40Sk
);
389 case FRV_OPERAND_ACC40UI
:
390 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_acc_names
, & fields
->f_ACC40Ui
);
392 case FRV_OPERAND_ACC40UK
:
393 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_acc_names
, & fields
->f_ACC40Uk
);
395 case FRV_OPERAND_ACCGI
:
396 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_accg_names
, & fields
->f_ACCGi
);
398 case FRV_OPERAND_ACCGK
:
399 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_accg_names
, & fields
->f_ACCGk
);
401 case FRV_OPERAND_CCI
:
402 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_cccr_names
, & fields
->f_CCi
);
404 case FRV_OPERAND_CPRDOUBLEK
:
405 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_cpr_names
, & fields
->f_CPRk
);
407 case FRV_OPERAND_CPRI
:
408 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_cpr_names
, & fields
->f_CPRi
);
410 case FRV_OPERAND_CPRJ
:
411 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_cpr_names
, & fields
->f_CPRj
);
413 case FRV_OPERAND_CPRK
:
414 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_cpr_names
, & fields
->f_CPRk
);
416 case FRV_OPERAND_CRI
:
417 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_cccr_names
, & fields
->f_CRi
);
419 case FRV_OPERAND_CRJ
:
420 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_cccr_names
, & fields
->f_CRj
);
422 case FRV_OPERAND_CRJ_FLOAT
:
423 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_cccr_names
, & fields
->f_CRj_float
);
425 case FRV_OPERAND_CRJ_INT
:
426 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_cccr_names
, & fields
->f_CRj_int
);
428 case FRV_OPERAND_CRK
:
429 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_cccr_names
, & fields
->f_CRk
);
431 case FRV_OPERAND_FCCI_1
:
432 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fccr_names
, & fields
->f_FCCi_1
);
434 case FRV_OPERAND_FCCI_2
:
435 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fccr_names
, & fields
->f_FCCi_2
);
437 case FRV_OPERAND_FCCI_3
:
438 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fccr_names
, & fields
->f_FCCi_3
);
440 case FRV_OPERAND_FCCK
:
441 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fccr_names
, & fields
->f_FCCk
);
443 case FRV_OPERAND_FRDOUBLEI
:
444 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRi
);
446 case FRV_OPERAND_FRDOUBLEJ
:
447 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRj
);
449 case FRV_OPERAND_FRDOUBLEK
:
450 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRk
);
452 case FRV_OPERAND_FRI
:
453 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRi
);
455 case FRV_OPERAND_FRINTI
:
456 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRi
);
458 case FRV_OPERAND_FRINTJ
:
459 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRj
);
461 case FRV_OPERAND_FRINTK
:
462 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRk
);
464 case FRV_OPERAND_FRJ
:
465 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRj
);
467 case FRV_OPERAND_FRK
:
468 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRk
);
470 case FRV_OPERAND_FRKHI
:
471 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRk
);
473 case FRV_OPERAND_FRKLO
:
474 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_fr_names
, & fields
->f_FRk
);
476 case FRV_OPERAND_GRDOUBLEK
:
477 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_gr_names
, & fields
->f_GRk
);
479 case FRV_OPERAND_GRI
:
480 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_gr_names
, & fields
->f_GRi
);
482 case FRV_OPERAND_GRJ
:
483 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_gr_names
, & fields
->f_GRj
);
485 case FRV_OPERAND_GRK
:
486 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_gr_names
, & fields
->f_GRk
);
488 case FRV_OPERAND_GRKHI
:
489 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_gr_names
, & fields
->f_GRk
);
491 case FRV_OPERAND_GRKLO
:
492 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_gr_names
, & fields
->f_GRk
);
494 case FRV_OPERAND_ICCI_1
:
495 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_iccr_names
, & fields
->f_ICCi_1
);
497 case FRV_OPERAND_ICCI_2
:
498 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_iccr_names
, & fields
->f_ICCi_2
);
500 case FRV_OPERAND_ICCI_3
:
501 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_iccr_names
, & fields
->f_ICCi_3
);
503 case FRV_OPERAND_LI
:
504 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_LI
, &fields
->f_LI
);
506 case FRV_OPERAND_AE
:
507 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_AE
, &fields
->f_ae
);
509 case FRV_OPERAND_CCOND
:
510 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_CCOND
, &fields
->f_ccond
);
512 case FRV_OPERAND_COND
:
513 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_COND
, &fields
->f_cond
);
515 case FRV_OPERAND_D12
:
516 errmsg
= parse_d12 (cd
, strp
, FRV_OPERAND_D12
, &fields
->f_d12
);
518 case FRV_OPERAND_DEBUG
:
519 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_DEBUG
, &fields
->f_debug
);
521 case FRV_OPERAND_EIR
:
522 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_EIR
, &fields
->f_eir
);
524 case FRV_OPERAND_HINT
:
525 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_HINT
, &fields
->f_hint
);
527 case FRV_OPERAND_HINT_NOT_TAKEN
:
528 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_h_hint_not_taken
, & fields
->f_hint
);
530 case FRV_OPERAND_HINT_TAKEN
:
531 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_h_hint_taken
, & fields
->f_hint
);
533 case FRV_OPERAND_LABEL16
:
536 errmsg
= cgen_parse_address (cd
, strp
, FRV_OPERAND_LABEL16
, 0, NULL
, & value
);
537 fields
->f_label16
= value
;
540 case FRV_OPERAND_LABEL24
:
543 errmsg
= cgen_parse_address (cd
, strp
, FRV_OPERAND_LABEL24
, 0, NULL
, & value
);
544 fields
->f_label24
= value
;
547 case FRV_OPERAND_LOCK
:
548 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_LOCK
, &fields
->f_lock
);
550 case FRV_OPERAND_PACK
:
551 errmsg
= cgen_parse_keyword (cd
, strp
, & frv_cgen_opval_h_pack
, & fields
->f_pack
);
553 case FRV_OPERAND_S10
:
554 errmsg
= cgen_parse_signed_integer (cd
, strp
, FRV_OPERAND_S10
, &fields
->f_s10
);
556 case FRV_OPERAND_S12
:
557 errmsg
= parse_s12 (cd
, strp
, FRV_OPERAND_S12
, &fields
->f_d12
);
559 case FRV_OPERAND_S16
:
560 errmsg
= cgen_parse_signed_integer (cd
, strp
, FRV_OPERAND_S16
, &fields
->f_s16
);
562 case FRV_OPERAND_S5
:
563 errmsg
= cgen_parse_signed_integer (cd
, strp
, FRV_OPERAND_S5
, &fields
->f_s5
);
565 case FRV_OPERAND_S6
:
566 errmsg
= cgen_parse_signed_integer (cd
, strp
, FRV_OPERAND_S6
, &fields
->f_s6
);
568 case FRV_OPERAND_S6_1
:
569 errmsg
= cgen_parse_signed_integer (cd
, strp
, FRV_OPERAND_S6_1
, &fields
->f_s6_1
);
571 case FRV_OPERAND_SLO16
:
572 errmsg
= parse_uslo16 (cd
, strp
, FRV_OPERAND_SLO16
, &fields
->f_s16
);
574 case FRV_OPERAND_SPR
:
575 errmsg
= parse_spr (cd
, strp
, & frv_cgen_opval_spr_names
, & fields
->f_spr
);
577 case FRV_OPERAND_U12
:
578 errmsg
= parse_u12 (cd
, strp
, FRV_OPERAND_U12
, &fields
->f_u12
);
580 case FRV_OPERAND_U16
:
581 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_U16
, &fields
->f_u16
);
583 case FRV_OPERAND_U6
:
584 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, FRV_OPERAND_U6
, &fields
->f_u6
);
586 case FRV_OPERAND_UHI16
:
587 errmsg
= parse_uhi16 (cd
, strp
, FRV_OPERAND_UHI16
, &fields
->f_u16
);
589 case FRV_OPERAND_ULO16
:
590 errmsg
= parse_ulo16 (cd
, strp
, FRV_OPERAND_ULO16
, &fields
->f_u16
);
594 /* xgettext:c-format */
595 fprintf (stderr
, _("Unrecognized field %d while parsing.\n"), opindex
);
602 cgen_parse_fn
* const frv_cgen_parse_handlers
[] =
608 frv_cgen_init_asm (cd
)
611 frv_cgen_init_opcode_table (cd
);
612 frv_cgen_init_ibld_table (cd
);
613 cd
->parse_handlers
= & frv_cgen_parse_handlers
[0];
614 cd
->parse_operand
= frv_cgen_parse_operand
;
619 /* Regex construction routine.
621 This translates an opcode syntax string into a regex string,
622 by replacing any non-character syntax element (such as an
623 opcode) with the pattern '.*'
625 It then compiles the regex and stores it in the opcode, for
626 later use by frv_cgen_assemble_insn
628 Returns NULL for success, an error message for failure. */
631 frv_cgen_build_insn_regex (insn
)
634 CGEN_OPCODE
*opc
= (CGEN_OPCODE
*) CGEN_INSN_OPCODE (insn
);
635 const char *mnem
= CGEN_INSN_MNEMONIC (insn
);
636 char rxbuf
[CGEN_MAX_RX_ELEMENTS
];
638 const CGEN_SYNTAX_CHAR_TYPE
*syn
;
641 syn
= CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc
));
643 /* Mnemonics come first in the syntax string. */
644 if (! CGEN_SYNTAX_MNEMONIC_P (* syn
))
645 return _("missing mnemonic in syntax string");
648 /* Generate a case sensitive regular expression that emulates case
649 insensitive matching in the "C" locale. We cannot generate a case
650 insensitive regular expression because in Turkish locales, 'i' and 'I'
651 are not equal modulo case conversion. */
653 /* Copy the literal mnemonic out of the insn. */
654 for (; *mnem
; mnem
++)
669 /* Copy any remaining literals from the syntax string into the rx. */
670 for(; * syn
!= 0 && rx
<= rxbuf
+ (CGEN_MAX_RX_ELEMENTS
- 7 - 4); ++syn
)
672 if (CGEN_SYNTAX_CHAR_P (* syn
))
674 char c
= CGEN_SYNTAX_CHAR (* syn
);
678 /* Escape any regex metacharacters in the syntax. */
679 case '.': case '[': case '\\':
680 case '*': case '^': case '$':
682 #ifdef CGEN_ESCAPE_EXTENDED_REGEX
683 case '?': case '{': case '}':
684 case '(': case ')': case '*':
685 case '|': case '+': case ']':
706 /* Replace non-syntax fields with globs. */
712 /* Trailing whitespace ok. */
719 /* But anchor it after that. */
723 CGEN_INSN_RX (insn
) = xmalloc (sizeof (regex_t
));
724 reg_err
= regcomp ((regex_t
*) CGEN_INSN_RX (insn
), rxbuf
, REG_NOSUB
);
732 regerror (reg_err
, (regex_t
*) CGEN_INSN_RX (insn
), msg
, 80);
733 regfree ((regex_t
*) CGEN_INSN_RX (insn
));
734 free (CGEN_INSN_RX (insn
));
735 (CGEN_INSN_RX (insn
)) = NULL
;
741 /* Default insn parser.
743 The syntax string is scanned and operands are parsed and stored in FIELDS.
744 Relocs are queued as we go via other callbacks.
746 ??? Note that this is currently an all-or-nothing parser. If we fail to
747 parse the instruction, we return 0 and the caller will start over from
748 the beginning. Backtracking will be necessary in parsing subexpressions,
749 but that can be handled there. Not handling backtracking here may get
750 expensive in the case of the m68k. Deal with later.
752 Returns NULL for success, an error message for failure. */
755 parse_insn_normal (cd
, insn
, strp
, fields
)
757 const CGEN_INSN
*insn
;
761 /* ??? Runtime added insns not handled yet. */
762 const CGEN_SYNTAX
*syntax
= CGEN_INSN_SYNTAX (insn
);
763 const char *str
= *strp
;
766 const CGEN_SYNTAX_CHAR_TYPE
* syn
;
767 #ifdef CGEN_MNEMONIC_OPERANDS
772 /* For now we assume the mnemonic is first (there are no leading operands).
773 We can parse it without needing to set up operand parsing.
774 GAS's input scrubber will ensure mnemonics are lowercase, but we may
775 not be called from GAS. */
776 p
= CGEN_INSN_MNEMONIC (insn
);
777 while (*p
&& TOLOWER (*p
) == TOLOWER (*str
))
781 return _("unrecognized instruction");
783 #ifndef CGEN_MNEMONIC_OPERANDS
784 if (* str
&& ! ISSPACE (* str
))
785 return _("unrecognized instruction");
788 CGEN_INIT_PARSE (cd
);
789 cgen_init_parse_operand (cd
);
790 #ifdef CGEN_MNEMONIC_OPERANDS
794 /* We don't check for (*str != '\0') here because we want to parse
795 any trailing fake arguments in the syntax string. */
796 syn
= CGEN_SYNTAX_STRING (syntax
);
798 /* Mnemonics come first for now, ensure valid string. */
799 if (! CGEN_SYNTAX_MNEMONIC_P (* syn
))
806 /* Non operand chars must match exactly. */
807 if (CGEN_SYNTAX_CHAR_P (* syn
))
809 /* FIXME: While we allow for non-GAS callers above, we assume the
810 first char after the mnemonic part is a space. */
811 /* FIXME: We also take inappropriate advantage of the fact that
812 GAS's input scrubber will remove extraneous blanks. */
813 if (TOLOWER (*str
) == TOLOWER (CGEN_SYNTAX_CHAR (* syn
)))
815 #ifdef CGEN_MNEMONIC_OPERANDS
816 if (CGEN_SYNTAX_CHAR(* syn
) == ' ')
824 /* Syntax char didn't match. Can't be this insn. */
825 static char msg
[80];
827 /* xgettext:c-format */
828 sprintf (msg
, _("syntax error (expected char `%c', found `%c')"),
829 CGEN_SYNTAX_CHAR(*syn
), *str
);
834 /* Ran out of input. */
835 static char msg
[80];
837 /* xgettext:c-format */
838 sprintf (msg
, _("syntax error (expected char `%c', found end of instruction)"),
839 CGEN_SYNTAX_CHAR(*syn
));
845 /* We have an operand of some sort. */
846 errmsg
= cd
->parse_operand (cd
, CGEN_SYNTAX_FIELD (*syn
),
851 /* Done with this operand, continue with next one. */
855 /* If we're at the end of the syntax string, we're done. */
858 /* FIXME: For the moment we assume a valid `str' can only contain
859 blanks now. IE: We needn't try again with a longer version of
860 the insn and it is assumed that longer versions of insns appear
861 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
862 while (ISSPACE (* str
))
866 return _("junk at end of line"); /* FIXME: would like to include `str' */
871 /* We couldn't parse it. */
872 return _("unrecognized instruction");
876 This routine is called for each instruction to be assembled.
877 STR points to the insn to be assembled.
878 We assume all necessary tables have been initialized.
879 The assembled instruction, less any fixups, is stored in BUF.
880 Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
881 still needs to be converted to target byte order, otherwise BUF is an array
882 of bytes in target byte order.
883 The result is a pointer to the insn's entry in the opcode table,
884 or NULL if an error occured (an error message will have already been
887 Note that when processing (non-alias) macro-insns,
888 this function recurses.
890 ??? It's possible to make this cpu-independent.
891 One would have to deal with a few minor things.
892 At this point in time doing so would be more of a curiosity than useful
893 [for example this file isn't _that_ big], but keeping the possibility in
894 mind helps keep the design clean. */
897 frv_cgen_assemble_insn (cd
, str
, fields
, buf
, errmsg
)
901 CGEN_INSN_BYTES_PTR buf
;
905 CGEN_INSN_LIST
*ilist
;
906 const char *parse_errmsg
= NULL
;
907 const char *insert_errmsg
= NULL
;
908 int recognized_mnemonic
= 0;
910 /* Skip leading white space. */
911 while (ISSPACE (* str
))
914 /* The instructions are stored in hashed lists.
915 Get the first in the list. */
916 ilist
= CGEN_ASM_LOOKUP_INSN (cd
, str
);
918 /* Keep looking until we find a match. */
920 for ( ; ilist
!= NULL
; ilist
= CGEN_ASM_NEXT_INSN (ilist
))
922 const CGEN_INSN
*insn
= ilist
->insn
;
923 recognized_mnemonic
= 1;
925 #ifdef CGEN_VALIDATE_INSN_SUPPORTED
926 /* Not usually needed as unsupported opcodes
927 shouldn't be in the hash lists. */
928 /* Is this insn supported by the selected cpu? */
929 if (! frv_cgen_insn_supported (cd
, insn
))
932 /* If the RELAX attribute is set, this is an insn that shouldn't be
933 chosen immediately. Instead, it is used during assembler/linker
934 relaxation if possible. */
935 if (CGEN_INSN_ATTR_VALUE (insn
, CGEN_INSN_RELAX
) != 0)
940 /* Skip this insn if str doesn't look right lexically. */
941 if (CGEN_INSN_RX (insn
) != NULL
&&
942 regexec ((regex_t
*) CGEN_INSN_RX (insn
), str
, 0, NULL
, 0) == REG_NOMATCH
)
945 /* Allow parse/insert handlers to obtain length of insn. */
946 CGEN_FIELDS_BITSIZE (fields
) = CGEN_INSN_BITSIZE (insn
);
948 parse_errmsg
= CGEN_PARSE_FN (cd
, insn
) (cd
, insn
, & str
, fields
);
949 if (parse_errmsg
!= NULL
)
952 /* ??? 0 is passed for `pc'. */
953 insert_errmsg
= CGEN_INSERT_FN (cd
, insn
) (cd
, insn
, fields
, buf
,
955 if (insert_errmsg
!= NULL
)
958 /* It is up to the caller to actually output the insn and any
964 static char errbuf
[150];
965 #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
966 const char *tmp_errmsg
;
968 /* If requesting verbose error messages, use insert_errmsg.
969 Failing that, use parse_errmsg. */
970 tmp_errmsg
= (insert_errmsg
? insert_errmsg
:
971 parse_errmsg
? parse_errmsg
:
972 recognized_mnemonic
?
973 _("unrecognized form of instruction") :
974 _("unrecognized instruction"));
976 if (strlen (start
) > 50)
977 /* xgettext:c-format */
978 sprintf (errbuf
, "%s `%.50s...'", tmp_errmsg
, start
);
980 /* xgettext:c-format */
981 sprintf (errbuf
, "%s `%.50s'", tmp_errmsg
, start
);
983 if (strlen (start
) > 50)
984 /* xgettext:c-format */
985 sprintf (errbuf
, _("bad instruction `%.50s...'"), start
);
987 /* xgettext:c-format */
988 sprintf (errbuf
, _("bad instruction `%.50s'"), start
);
996 #if 0 /* This calls back to GAS which we can't do without care. */
998 /* Record each member of OPVALS in the assembler's symbol table.
999 This lets GAS parse registers for us.
1000 ??? Interesting idea but not currently used. */
1002 /* Record each member of OPVALS in the assembler's symbol table.
1003 FIXME: Not currently used. */
1006 frv_cgen_asm_hash_keywords (cd
, opvals
)
1008 CGEN_KEYWORD
*opvals
;
1010 CGEN_KEYWORD_SEARCH search
= cgen_keyword_search_init (opvals
, NULL
);
1011 const CGEN_KEYWORD_ENTRY
* ke
;
1013 while ((ke
= cgen_keyword_search_next (& search
)) != NULL
)
1015 #if 0 /* Unnecessary, should be done in the search routine. */
1016 if (! frv_cgen_opval_supported (ke
))
1019 cgen_asm_record_register (cd
, ke
->name
, ke
->value
);