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, 2005
8 Free Software Foundation, Inc.
10 This file is part of the GNU Binutils and GDB, the GNU debugger.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2, or (at your option)
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software Foundation, Inc.,
24 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
26 /* ??? Eventually more and more of this stuff can go to cpu-independent files.
38 #include "libiberty.h"
39 #include "safe-ctype.h"
42 #define min(a,b) ((a) < (b) ? (a) : (b))
44 #define max(a,b) ((a) > (b) ? (a) : (b))
46 static const char * parse_insn_normal
47 (CGEN_CPU_DESC
, const CGEN_INSN
*, const char **, CGEN_FIELDS
*);
49 /* -- assembler routines inserted here. */
52 static int signed_out_of_bounds (long);
53 static const char * parse_imm16 (CGEN_CPU_DESC
, const char **, int, long *);
54 static const char * parse_dup (CGEN_CPU_DESC
, const char **, int, long *);
55 static const char * parse_ball (CGEN_CPU_DESC
, const char **, int, long *);
56 static const char * parse_xmode (CGEN_CPU_DESC
, const char **, int, long *);
57 static const char * parse_rc (CGEN_CPU_DESC
, const char **, int, long *);
58 static const char * parse_cbrb (CGEN_CPU_DESC
, const char **, int, long *);
59 static const char * parse_rbbc (CGEN_CPU_DESC
, const char **, int, long *);
60 static const char * parse_type (CGEN_CPU_DESC
, const char **, int, long *);
62 /* Range checking for signed numbers. Returns 0 if acceptable
63 and 1 if the value is out of bounds for a signed quantity. */
66 signed_out_of_bounds (long val
)
68 if ((val
< -32768) || (val
> 32767))
74 parse_imm16 (CGEN_CPU_DESC cd
,
80 enum cgen_parse_operand_result result_type
;
81 bfd_reloc_code_real_type code
= BFD_RELOC_NONE
;
84 /* Is it a control transfer instructions? */
85 if (opindex
== (CGEN_OPERAND_TYPE
) MS1_OPERAND_IMM16O
)
87 code
= BFD_RELOC_16_PCREL
;
88 errmsg
= cgen_parse_address (cd
, strp
, opindex
, code
,
89 & result_type
, & value
);
92 if (signed_out_of_bounds (value
))
93 errmsg
= _("Operand out of range. Must be between -32768 and 32767.");
99 /* If it's not a control transfer instruction, then
100 we have to check for %OP relocating operators. */
101 if (strncmp (*strp
, "%hi16", 5) == 0)
104 code
= BFD_RELOC_HI16
;
106 else if (strncmp (*strp
, "%lo16", 5) == 0)
109 code
= BFD_RELOC_LO16
;
112 /* If we found a %OP relocating operator, then parse it as an address.
113 If not, we need to parse it as an integer, either signed or unsigned
114 depending on which operand type we have. */
115 if (code
!= BFD_RELOC_NONE
)
117 /* %OP relocating operator found. */
118 errmsg
= cgen_parse_address (cd
, strp
, opindex
, code
,
119 & result_type
, & value
);
124 case (CGEN_PARSE_OPERAND_RESULT_NUMBER
):
125 if (code
== BFD_RELOC_HI16
)
126 value
= (value
>> 16) & 0xFFFF;
127 else if (code
== BFD_RELOC_LO16
)
128 value
= value
& 0xFFFF;
130 errmsg
= _("Biiiig Trouble in parse_imm16!");
133 case (CGEN_PARSE_OPERAND_RESULT_QUEUED
):
134 /* No special processing for this case. */
138 errmsg
= _("%operator operand is not a symbol");
146 /* Parse hex values like 0xffff as unsigned, and sign extend
148 int parse_signed
= (opindex
== (CGEN_OPERAND_TYPE
)MS1_OPERAND_IMM16
);
150 if ((*strp
)[0] == '0'
151 && ((*strp
)[1] == 'x' || (*strp
)[1] == 'X'))
154 /* No relocating operator. Parse as an number. */
157 /* Parse as as signed integer. */
159 errmsg
= cgen_parse_signed_integer (cd
, strp
, opindex
, valuep
);
164 /* Manual range checking is needed for the signed case. */
165 if (*valuep
& 0x8000)
166 value
= 0xffff0000 | *valuep
;
170 if (signed_out_of_bounds (value
))
171 errmsg
= _("Operand out of range. Must be between -32768 and 32767.");
172 /* Truncate to 16 bits. This is necessary
173 because cgen will have sign extended *valuep. */
180 /* MS1_OPERAND_IMM16Z. Parse as an unsigned integer. */
181 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
183 if (opindex
== (CGEN_OPERAND_TYPE
)MS1_OPERAND_IMM16
185 && *valuep
<= 0xffff)
195 parse_dup (CGEN_CPU_DESC cd
,
200 const char *errmsg
= NULL
;
202 if (strncmp (*strp
, "dup", 3) == 0 || strncmp (*strp
, "DUP", 3) == 0)
207 else if (strncmp (*strp
, "xx", 2) == 0 || strncmp (*strp
, "XX", 2) == 0)
213 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
220 parse_ball (CGEN_CPU_DESC cd
,
225 const char *errmsg
= NULL
;
227 if (strncmp (*strp
, "all", 3) == 0 || strncmp (*strp
, "ALL", 3) == 0)
232 else if (strncmp (*strp
, "one", 3) == 0 || strncmp (*strp
, "ONE", 3) == 0)
238 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
244 parse_xmode (CGEN_CPU_DESC cd
,
249 const char *errmsg
= NULL
;
251 if (strncmp (*strp
, "pm", 2) == 0 || strncmp (*strp
, "PM", 2) == 0)
256 else if (strncmp (*strp
, "xm", 2) == 0 || strncmp (*strp
, "XM", 2) == 0)
262 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
268 parse_rc (CGEN_CPU_DESC cd
,
273 const char *errmsg
= NULL
;
275 if (strncmp (*strp
, "r", 1) == 0 || strncmp (*strp
, "R", 1) == 0)
280 else if (strncmp (*strp
, "c", 1) == 0 || strncmp (*strp
, "C", 1) == 0)
286 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
292 parse_cbrb (CGEN_CPU_DESC cd
,
297 const char *errmsg
= NULL
;
299 if (strncmp (*strp
, "rb", 2) == 0 || strncmp (*strp
, "RB", 2) == 0)
304 else if (strncmp (*strp
, "cb", 2) == 0 || strncmp (*strp
, "CB", 2) == 0)
310 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
316 parse_rbbc (CGEN_CPU_DESC cd
,
321 const char *errmsg
= NULL
;
323 if (strncmp (*strp
, "rt", 2) == 0 || strncmp (*strp
, "RT", 2) == 0)
328 else if (strncmp (*strp
, "br1", 3) == 0 || strncmp (*strp
, "BR1", 3) == 0)
333 else if (strncmp (*strp
, "br2", 3) == 0 || strncmp (*strp
, "BR2", 3) == 0)
338 else if (strncmp (*strp
, "cs", 2) == 0 || strncmp (*strp
, "CS", 2) == 0)
344 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
350 parse_type (CGEN_CPU_DESC cd
,
355 const char *errmsg
= NULL
;
357 if (strncmp (*strp
, "odd", 3) == 0 || strncmp (*strp
, "ODD", 3) == 0)
362 else if (strncmp (*strp
, "even", 4) == 0 || strncmp (*strp
, "EVEN", 4) == 0)
367 else if (strncmp (*strp
, "oe", 2) == 0 || strncmp (*strp
, "OE", 2) == 0)
373 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
375 if ((errmsg
== NULL
) && (*valuep
== 3))
376 errmsg
= _("invalid operand. type may have values 0,1,2 only.");
383 const char * ms1_cgen_parse_operand
384 (CGEN_CPU_DESC
, int, const char **, CGEN_FIELDS
*);
386 /* Main entry point for operand parsing.
388 This function is basically just a big switch statement. Earlier versions
389 used tables to look up the function to use, but
390 - if the table contains both assembler and disassembler functions then
391 the disassembler contains much of the assembler and vice-versa,
392 - there's a lot of inlining possibilities as things grow,
393 - using a switch statement avoids the function call overhead.
395 This function could be moved into `parse_insn_normal', but keeping it
396 separate makes clear the interface between `parse_insn_normal' and each of
400 ms1_cgen_parse_operand (CGEN_CPU_DESC cd
,
403 CGEN_FIELDS
* fields
)
405 const char * errmsg
= NULL
;
406 /* Used by scalar operands that still need to be parsed. */
407 long junk ATTRIBUTE_UNUSED
;
411 case MS1_OPERAND_A23
:
412 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_A23
, (unsigned long *) (& fields
->f_a23
));
414 case MS1_OPERAND_BALL
:
415 errmsg
= parse_ball (cd
, strp
, MS1_OPERAND_BALL
, (unsigned long *) (& fields
->f_ball
));
417 case MS1_OPERAND_BALL2
:
418 errmsg
= parse_ball (cd
, strp
, MS1_OPERAND_BALL2
, (unsigned long *) (& fields
->f_ball2
));
420 case MS1_OPERAND_BANKADDR
:
421 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_BANKADDR
, (unsigned long *) (& fields
->f_bankaddr
));
423 case MS1_OPERAND_BRC
:
424 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_BRC
, (unsigned long *) (& fields
->f_brc
));
426 case MS1_OPERAND_BRC2
:
427 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_BRC2
, (unsigned long *) (& fields
->f_brc2
));
429 case MS1_OPERAND_CBRB
:
430 errmsg
= parse_cbrb (cd
, strp
, MS1_OPERAND_CBRB
, (unsigned long *) (& fields
->f_cbrb
));
432 case MS1_OPERAND_CBS
:
433 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CBS
, (unsigned long *) (& fields
->f_cbs
));
435 case MS1_OPERAND_CBX
:
436 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CBX
, (unsigned long *) (& fields
->f_cbx
));
438 case MS1_OPERAND_CCB
:
439 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CCB
, (unsigned long *) (& fields
->f_ccb
));
441 case MS1_OPERAND_CDB
:
442 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CDB
, (unsigned long *) (& fields
->f_cdb
));
444 case MS1_OPERAND_CELL
:
445 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CELL
, (unsigned long *) (& fields
->f_cell
));
447 case MS1_OPERAND_COLNUM
:
448 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_COLNUM
, (unsigned long *) (& fields
->f_colnum
));
450 case MS1_OPERAND_CONTNUM
:
451 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CONTNUM
, (unsigned long *) (& fields
->f_contnum
));
453 case MS1_OPERAND_CR
:
454 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CR
, (unsigned long *) (& fields
->f_cr
));
456 case MS1_OPERAND_CTXDISP
:
457 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CTXDISP
, (unsigned long *) (& fields
->f_ctxdisp
));
459 case MS1_OPERAND_DUP
:
460 errmsg
= parse_dup (cd
, strp
, MS1_OPERAND_DUP
, (unsigned long *) (& fields
->f_dup
));
462 case MS1_OPERAND_FBDISP
:
463 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_FBDISP
, (unsigned long *) (& fields
->f_fbdisp
));
465 case MS1_OPERAND_FBINCR
:
466 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_FBINCR
, (unsigned long *) (& fields
->f_fbincr
));
468 case MS1_OPERAND_FRDR
:
469 errmsg
= cgen_parse_keyword (cd
, strp
, & ms1_cgen_opval_h_spr
, & fields
->f_dr
);
471 case MS1_OPERAND_FRDRRR
:
472 errmsg
= cgen_parse_keyword (cd
, strp
, & ms1_cgen_opval_h_spr
, & fields
->f_drrr
);
474 case MS1_OPERAND_FRSR1
:
475 errmsg
= cgen_parse_keyword (cd
, strp
, & ms1_cgen_opval_h_spr
, & fields
->f_sr1
);
477 case MS1_OPERAND_FRSR2
:
478 errmsg
= cgen_parse_keyword (cd
, strp
, & ms1_cgen_opval_h_spr
, & fields
->f_sr2
);
480 case MS1_OPERAND_ID
:
481 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_ID
, (unsigned long *) (& fields
->f_id
));
483 case MS1_OPERAND_IMM16
:
484 errmsg
= parse_imm16 (cd
, strp
, MS1_OPERAND_IMM16
, (long *) (& fields
->f_imm16s
));
486 case MS1_OPERAND_IMM16O
:
487 errmsg
= parse_imm16 (cd
, strp
, MS1_OPERAND_IMM16O
, (unsigned long *) (& fields
->f_imm16s
));
489 case MS1_OPERAND_IMM16Z
:
490 errmsg
= parse_imm16 (cd
, strp
, MS1_OPERAND_IMM16Z
, (unsigned long *) (& fields
->f_imm16u
));
492 case MS1_OPERAND_INCAMT
:
493 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_INCAMT
, (unsigned long *) (& fields
->f_incamt
));
495 case MS1_OPERAND_INCR
:
496 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_INCR
, (unsigned long *) (& fields
->f_incr
));
498 case MS1_OPERAND_LENGTH
:
499 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_LENGTH
, (unsigned long *) (& fields
->f_length
));
501 case MS1_OPERAND_MASK
:
502 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_MASK
, (unsigned long *) (& fields
->f_mask
));
504 case MS1_OPERAND_MASK1
:
505 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_MASK1
, (unsigned long *) (& fields
->f_mask1
));
507 case MS1_OPERAND_MODE
:
508 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_MODE
, (unsigned long *) (& fields
->f_mode
));
510 case MS1_OPERAND_PERM
:
511 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_PERM
, (unsigned long *) (& fields
->f_perm
));
513 case MS1_OPERAND_RBBC
:
514 errmsg
= parse_rbbc (cd
, strp
, MS1_OPERAND_RBBC
, (unsigned long *) (& fields
->f_rbbc
));
516 case MS1_OPERAND_RC
:
517 errmsg
= parse_rc (cd
, strp
, MS1_OPERAND_RC
, (unsigned long *) (& fields
->f_rc
));
519 case MS1_OPERAND_RC1
:
520 errmsg
= parse_rc (cd
, strp
, MS1_OPERAND_RC1
, (unsigned long *) (& fields
->f_rc1
));
522 case MS1_OPERAND_RC2
:
523 errmsg
= parse_rc (cd
, strp
, MS1_OPERAND_RC2
, (unsigned long *) (& fields
->f_rc2
));
525 case MS1_OPERAND_RCNUM
:
526 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_RCNUM
, (unsigned long *) (& fields
->f_rcnum
));
528 case MS1_OPERAND_RDA
:
529 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_RDA
, (unsigned long *) (& fields
->f_rda
));
531 case MS1_OPERAND_ROWNUM
:
532 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_ROWNUM
, (unsigned long *) (& fields
->f_rownum
));
534 case MS1_OPERAND_ROWNUM1
:
535 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_ROWNUM1
, (unsigned long *) (& fields
->f_rownum1
));
537 case MS1_OPERAND_ROWNUM2
:
538 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_ROWNUM2
, (unsigned long *) (& fields
->f_rownum2
));
540 case MS1_OPERAND_SIZE
:
541 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_SIZE
, (unsigned long *) (& fields
->f_size
));
543 case MS1_OPERAND_TYPE
:
544 errmsg
= parse_type (cd
, strp
, MS1_OPERAND_TYPE
, (unsigned long *) (& fields
->f_type
));
546 case MS1_OPERAND_WR
:
547 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_WR
, (unsigned long *) (& fields
->f_wr
));
549 case MS1_OPERAND_XMODE
:
550 errmsg
= parse_xmode (cd
, strp
, MS1_OPERAND_XMODE
, (unsigned long *) (& fields
->f_xmode
));
554 /* xgettext:c-format */
555 fprintf (stderr
, _("Unrecognized field %d while parsing.\n"), opindex
);
562 cgen_parse_fn
* const ms1_cgen_parse_handlers
[] =
568 ms1_cgen_init_asm (CGEN_CPU_DESC cd
)
570 ms1_cgen_init_opcode_table (cd
);
571 ms1_cgen_init_ibld_table (cd
);
572 cd
->parse_handlers
= & ms1_cgen_parse_handlers
[0];
573 cd
->parse_operand
= ms1_cgen_parse_operand
;
578 /* Regex construction routine.
580 This translates an opcode syntax string into a regex string,
581 by replacing any non-character syntax element (such as an
582 opcode) with the pattern '.*'
584 It then compiles the regex and stores it in the opcode, for
585 later use by ms1_cgen_assemble_insn
587 Returns NULL for success, an error message for failure. */
590 ms1_cgen_build_insn_regex (CGEN_INSN
*insn
)
592 CGEN_OPCODE
*opc
= (CGEN_OPCODE
*) CGEN_INSN_OPCODE (insn
);
593 const char *mnem
= CGEN_INSN_MNEMONIC (insn
);
594 char rxbuf
[CGEN_MAX_RX_ELEMENTS
];
596 const CGEN_SYNTAX_CHAR_TYPE
*syn
;
599 syn
= CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc
));
601 /* Mnemonics come first in the syntax string. */
602 if (! CGEN_SYNTAX_MNEMONIC_P (* syn
))
603 return _("missing mnemonic in syntax string");
606 /* Generate a case sensitive regular expression that emulates case
607 insensitive matching in the "C" locale. We cannot generate a case
608 insensitive regular expression because in Turkish locales, 'i' and 'I'
609 are not equal modulo case conversion. */
611 /* Copy the literal mnemonic out of the insn. */
612 for (; *mnem
; mnem
++)
627 /* Copy any remaining literals from the syntax string into the rx. */
628 for(; * syn
!= 0 && rx
<= rxbuf
+ (CGEN_MAX_RX_ELEMENTS
- 7 - 4); ++syn
)
630 if (CGEN_SYNTAX_CHAR_P (* syn
))
632 char c
= CGEN_SYNTAX_CHAR (* syn
);
636 /* Escape any regex metacharacters in the syntax. */
637 case '.': case '[': case '\\':
638 case '*': case '^': case '$':
640 #ifdef CGEN_ESCAPE_EXTENDED_REGEX
641 case '?': case '{': case '}':
642 case '(': case ')': case '*':
643 case '|': case '+': case ']':
664 /* Replace non-syntax fields with globs. */
670 /* Trailing whitespace ok. */
677 /* But anchor it after that. */
681 CGEN_INSN_RX (insn
) = xmalloc (sizeof (regex_t
));
682 reg_err
= regcomp ((regex_t
*) CGEN_INSN_RX (insn
), rxbuf
, REG_NOSUB
);
690 regerror (reg_err
, (regex_t
*) CGEN_INSN_RX (insn
), msg
, 80);
691 regfree ((regex_t
*) CGEN_INSN_RX (insn
));
692 free (CGEN_INSN_RX (insn
));
693 (CGEN_INSN_RX (insn
)) = NULL
;
699 /* Default insn parser.
701 The syntax string is scanned and operands are parsed and stored in FIELDS.
702 Relocs are queued as we go via other callbacks.
704 ??? Note that this is currently an all-or-nothing parser. If we fail to
705 parse the instruction, we return 0 and the caller will start over from
706 the beginning. Backtracking will be necessary in parsing subexpressions,
707 but that can be handled there. Not handling backtracking here may get
708 expensive in the case of the m68k. Deal with later.
710 Returns NULL for success, an error message for failure. */
713 parse_insn_normal (CGEN_CPU_DESC cd
,
714 const CGEN_INSN
*insn
,
718 /* ??? Runtime added insns not handled yet. */
719 const CGEN_SYNTAX
*syntax
= CGEN_INSN_SYNTAX (insn
);
720 const char *str
= *strp
;
723 const CGEN_SYNTAX_CHAR_TYPE
* syn
;
724 #ifdef CGEN_MNEMONIC_OPERANDS
729 /* For now we assume the mnemonic is first (there are no leading operands).
730 We can parse it without needing to set up operand parsing.
731 GAS's input scrubber will ensure mnemonics are lowercase, but we may
732 not be called from GAS. */
733 p
= CGEN_INSN_MNEMONIC (insn
);
734 while (*p
&& TOLOWER (*p
) == TOLOWER (*str
))
738 return _("unrecognized instruction");
740 #ifndef CGEN_MNEMONIC_OPERANDS
741 if (* str
&& ! ISSPACE (* str
))
742 return _("unrecognized instruction");
745 CGEN_INIT_PARSE (cd
);
746 cgen_init_parse_operand (cd
);
747 #ifdef CGEN_MNEMONIC_OPERANDS
751 /* We don't check for (*str != '\0') here because we want to parse
752 any trailing fake arguments in the syntax string. */
753 syn
= CGEN_SYNTAX_STRING (syntax
);
755 /* Mnemonics come first for now, ensure valid string. */
756 if (! CGEN_SYNTAX_MNEMONIC_P (* syn
))
763 /* Non operand chars must match exactly. */
764 if (CGEN_SYNTAX_CHAR_P (* syn
))
766 /* FIXME: While we allow for non-GAS callers above, we assume the
767 first char after the mnemonic part is a space. */
768 /* FIXME: We also take inappropriate advantage of the fact that
769 GAS's input scrubber will remove extraneous blanks. */
770 if (TOLOWER (*str
) == TOLOWER (CGEN_SYNTAX_CHAR (* syn
)))
772 #ifdef CGEN_MNEMONIC_OPERANDS
773 if (CGEN_SYNTAX_CHAR(* syn
) == ' ')
781 /* Syntax char didn't match. Can't be this insn. */
782 static char msg
[80];
784 /* xgettext:c-format */
785 sprintf (msg
, _("syntax error (expected char `%c', found `%c')"),
786 CGEN_SYNTAX_CHAR(*syn
), *str
);
791 /* Ran out of input. */
792 static char msg
[80];
794 /* xgettext:c-format */
795 sprintf (msg
, _("syntax error (expected char `%c', found end of instruction)"),
796 CGEN_SYNTAX_CHAR(*syn
));
802 /* We have an operand of some sort. */
803 errmsg
= cd
->parse_operand (cd
, CGEN_SYNTAX_FIELD (*syn
),
808 /* Done with this operand, continue with next one. */
812 /* If we're at the end of the syntax string, we're done. */
815 /* FIXME: For the moment we assume a valid `str' can only contain
816 blanks now. IE: We needn't try again with a longer version of
817 the insn and it is assumed that longer versions of insns appear
818 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
819 while (ISSPACE (* str
))
823 return _("junk at end of line"); /* FIXME: would like to include `str' */
828 /* We couldn't parse it. */
829 return _("unrecognized instruction");
833 This routine is called for each instruction to be assembled.
834 STR points to the insn to be assembled.
835 We assume all necessary tables have been initialized.
836 The assembled instruction, less any fixups, is stored in BUF.
837 Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
838 still needs to be converted to target byte order, otherwise BUF is an array
839 of bytes in target byte order.
840 The result is a pointer to the insn's entry in the opcode table,
841 or NULL if an error occured (an error message will have already been
844 Note that when processing (non-alias) macro-insns,
845 this function recurses.
847 ??? It's possible to make this cpu-independent.
848 One would have to deal with a few minor things.
849 At this point in time doing so would be more of a curiosity than useful
850 [for example this file isn't _that_ big], but keeping the possibility in
851 mind helps keep the design clean. */
854 ms1_cgen_assemble_insn (CGEN_CPU_DESC cd
,
857 CGEN_INSN_BYTES_PTR buf
,
861 CGEN_INSN_LIST
*ilist
;
862 const char *parse_errmsg
= NULL
;
863 const char *insert_errmsg
= NULL
;
864 int recognized_mnemonic
= 0;
866 /* Skip leading white space. */
867 while (ISSPACE (* str
))
870 /* The instructions are stored in hashed lists.
871 Get the first in the list. */
872 ilist
= CGEN_ASM_LOOKUP_INSN (cd
, str
);
874 /* Keep looking until we find a match. */
876 for ( ; ilist
!= NULL
; ilist
= CGEN_ASM_NEXT_INSN (ilist
))
878 const CGEN_INSN
*insn
= ilist
->insn
;
879 recognized_mnemonic
= 1;
881 #ifdef CGEN_VALIDATE_INSN_SUPPORTED
882 /* Not usually needed as unsupported opcodes
883 shouldn't be in the hash lists. */
884 /* Is this insn supported by the selected cpu? */
885 if (! ms1_cgen_insn_supported (cd
, insn
))
888 /* If the RELAXED attribute is set, this is an insn that shouldn't be
889 chosen immediately. Instead, it is used during assembler/linker
890 relaxation if possible. */
891 if (CGEN_INSN_ATTR_VALUE (insn
, CGEN_INSN_RELAXED
) != 0)
896 /* Skip this insn if str doesn't look right lexically. */
897 if (CGEN_INSN_RX (insn
) != NULL
&&
898 regexec ((regex_t
*) CGEN_INSN_RX (insn
), str
, 0, NULL
, 0) == REG_NOMATCH
)
901 /* Allow parse/insert handlers to obtain length of insn. */
902 CGEN_FIELDS_BITSIZE (fields
) = CGEN_INSN_BITSIZE (insn
);
904 parse_errmsg
= CGEN_PARSE_FN (cd
, insn
) (cd
, insn
, & str
, fields
);
905 if (parse_errmsg
!= NULL
)
908 /* ??? 0 is passed for `pc'. */
909 insert_errmsg
= CGEN_INSERT_FN (cd
, insn
) (cd
, insn
, fields
, buf
,
911 if (insert_errmsg
!= NULL
)
914 /* It is up to the caller to actually output the insn and any
920 static char errbuf
[150];
921 #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
922 const char *tmp_errmsg
;
924 /* If requesting verbose error messages, use insert_errmsg.
925 Failing that, use parse_errmsg. */
926 tmp_errmsg
= (insert_errmsg
? insert_errmsg
:
927 parse_errmsg
? parse_errmsg
:
928 recognized_mnemonic
?
929 _("unrecognized form of instruction") :
930 _("unrecognized instruction"));
932 if (strlen (start
) > 50)
933 /* xgettext:c-format */
934 sprintf (errbuf
, "%s `%.50s...'", tmp_errmsg
, start
);
936 /* xgettext:c-format */
937 sprintf (errbuf
, "%s `%.50s'", tmp_errmsg
, start
);
939 if (strlen (start
) > 50)
940 /* xgettext:c-format */
941 sprintf (errbuf
, _("bad instruction `%.50s...'"), start
);
943 /* xgettext:c-format */
944 sprintf (errbuf
, _("bad instruction `%.50s'"), start
);