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 /* Range checking for signed numbers. Returns 0 if acceptable
53 and 1 if the value is out of bounds for a signed quantity. */
56 signed_out_of_bounds (long val
)
58 if ((val
< -32768) || (val
> 32767))
64 parse_imm16 (CGEN_CPU_DESC cd
,
69 signed long * valuep
= (signed long *) arg
;
71 enum cgen_parse_operand_result result_type
;
72 bfd_reloc_code_real_type code
= BFD_RELOC_NONE
;
75 /* Is it a control transfer instructions? */
76 if (opindex
== (CGEN_OPERAND_TYPE
) MS1_OPERAND_IMM16O
)
78 code
= BFD_RELOC_16_PCREL
;
79 errmsg
= cgen_parse_address (cd
, strp
, opindex
, code
,
80 & result_type
, & value
);
83 if (signed_out_of_bounds (value
))
84 errmsg
= _("Operand out of range. Must be between -32768 and 32767.");
90 /* If it's not a control transfer instruction, then
91 we have to check for %OP relocating operators. */
92 if (strncmp (*strp
, "%hi16", 5) == 0)
95 code
= BFD_RELOC_HI16
;
97 else if (strncmp (*strp
, "%lo16", 5) == 0)
100 code
= BFD_RELOC_LO16
;
103 /* If we found a %OP relocating operator, then parse it as an address.
104 If not, we need to parse it as an integer, either signed or unsigned
105 depending on which operand type we have. */
106 if (code
!= BFD_RELOC_NONE
)
108 /* %OP relocating operator found. */
109 errmsg
= cgen_parse_address (cd
, strp
, opindex
, code
,
110 & result_type
, & value
);
115 case (CGEN_PARSE_OPERAND_RESULT_NUMBER
):
116 if (code
== BFD_RELOC_HI16
)
117 value
= (value
>> 16) & 0xFFFF;
118 else if (code
== BFD_RELOC_LO16
)
119 value
= value
& 0xFFFF;
121 errmsg
= _("Biiiig Trouble in parse_imm16!");
124 case (CGEN_PARSE_OPERAND_RESULT_QUEUED
):
125 /* No special processing for this case. */
129 errmsg
= _("%operator operand is not a symbol");
137 /* Parse hex values like 0xffff as unsigned, and sign extend
139 int parse_signed
= (opindex
== (CGEN_OPERAND_TYPE
)MS1_OPERAND_IMM16
);
141 if ((*strp
)[0] == '0'
142 && ((*strp
)[1] == 'x' || (*strp
)[1] == 'X'))
145 /* No relocating operator. Parse as an number. */
148 /* Parse as as signed integer. */
150 errmsg
= cgen_parse_signed_integer (cd
, strp
, opindex
, valuep
);
155 /* Manual range checking is needed for the signed case. */
156 if (*valuep
& 0x8000)
157 value
= 0xffff0000 | *valuep
;
161 if (signed_out_of_bounds (value
))
162 errmsg
= _("Operand out of range. Must be between -32768 and 32767.");
163 /* Truncate to 16 bits. This is necessary
164 because cgen will have sign extended *valuep. */
171 /* MS1_OPERAND_IMM16Z. Parse as an unsigned integer. */
172 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, (unsigned long *) valuep
);
174 if (opindex
== (CGEN_OPERAND_TYPE
) MS1_OPERAND_IMM16
176 && *valuep
<= 0xffff)
186 parse_dup (CGEN_CPU_DESC cd
,
189 unsigned long *valuep
)
191 const char *errmsg
= NULL
;
193 if (strncmp (*strp
, "dup", 3) == 0 || strncmp (*strp
, "DUP", 3) == 0)
198 else if (strncmp (*strp
, "xx", 2) == 0 || strncmp (*strp
, "XX", 2) == 0)
204 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
211 parse_ball (CGEN_CPU_DESC cd
,
214 unsigned long *valuep
)
216 const char *errmsg
= NULL
;
218 if (strncmp (*strp
, "all", 3) == 0 || strncmp (*strp
, "ALL", 3) == 0)
223 else if (strncmp (*strp
, "one", 3) == 0 || strncmp (*strp
, "ONE", 3) == 0)
229 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
235 parse_xmode (CGEN_CPU_DESC cd
,
238 unsigned long *valuep
)
240 const char *errmsg
= NULL
;
242 if (strncmp (*strp
, "pm", 2) == 0 || strncmp (*strp
, "PM", 2) == 0)
247 else if (strncmp (*strp
, "xm", 2) == 0 || strncmp (*strp
, "XM", 2) == 0)
253 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
259 parse_rc (CGEN_CPU_DESC cd
,
262 unsigned long *valuep
)
264 const char *errmsg
= NULL
;
266 if (strncmp (*strp
, "r", 1) == 0 || strncmp (*strp
, "R", 1) == 0)
271 else if (strncmp (*strp
, "c", 1) == 0 || strncmp (*strp
, "C", 1) == 0)
277 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
283 parse_cbrb (CGEN_CPU_DESC cd
,
286 unsigned long *valuep
)
288 const char *errmsg
= NULL
;
290 if (strncmp (*strp
, "rb", 2) == 0 || strncmp (*strp
, "RB", 2) == 0)
295 else if (strncmp (*strp
, "cb", 2) == 0 || strncmp (*strp
, "CB", 2) == 0)
301 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
307 parse_rbbc (CGEN_CPU_DESC cd
,
310 unsigned long *valuep
)
312 const char *errmsg
= NULL
;
314 if (strncmp (*strp
, "rt", 2) == 0 || strncmp (*strp
, "RT", 2) == 0)
319 else if (strncmp (*strp
, "br1", 3) == 0 || strncmp (*strp
, "BR1", 3) == 0)
324 else if (strncmp (*strp
, "br2", 3) == 0 || strncmp (*strp
, "BR2", 3) == 0)
329 else if (strncmp (*strp
, "cs", 2) == 0 || strncmp (*strp
, "CS", 2) == 0)
335 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
341 parse_type (CGEN_CPU_DESC cd
,
344 unsigned long *valuep
)
346 const char *errmsg
= NULL
;
348 if (strncmp (*strp
, "odd", 3) == 0 || strncmp (*strp
, "ODD", 3) == 0)
353 else if (strncmp (*strp
, "even", 4) == 0 || strncmp (*strp
, "EVEN", 4) == 0)
358 else if (strncmp (*strp
, "oe", 2) == 0 || strncmp (*strp
, "OE", 2) == 0)
364 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, opindex
, valuep
);
366 if ((errmsg
== NULL
) && (*valuep
== 3))
367 errmsg
= _("invalid operand. type may have values 0,1,2 only.");
374 const char * ms1_cgen_parse_operand
375 (CGEN_CPU_DESC
, int, const char **, CGEN_FIELDS
*);
377 /* Main entry point for operand parsing.
379 This function is basically just a big switch statement. Earlier versions
380 used tables to look up the function to use, but
381 - if the table contains both assembler and disassembler functions then
382 the disassembler contains much of the assembler and vice-versa,
383 - there's a lot of inlining possibilities as things grow,
384 - using a switch statement avoids the function call overhead.
386 This function could be moved into `parse_insn_normal', but keeping it
387 separate makes clear the interface between `parse_insn_normal' and each of
391 ms1_cgen_parse_operand (CGEN_CPU_DESC cd
,
394 CGEN_FIELDS
* fields
)
396 const char * errmsg
= NULL
;
397 /* Used by scalar operands that still need to be parsed. */
398 long junk ATTRIBUTE_UNUSED
;
402 case MS1_OPERAND_A23
:
403 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_A23
, (unsigned long *) (& fields
->f_a23
));
405 case MS1_OPERAND_BALL
:
406 errmsg
= parse_ball (cd
, strp
, MS1_OPERAND_BALL
, (unsigned long *) (& fields
->f_ball
));
408 case MS1_OPERAND_BALL2
:
409 errmsg
= parse_ball (cd
, strp
, MS1_OPERAND_BALL2
, (unsigned long *) (& fields
->f_ball2
));
411 case MS1_OPERAND_BANKADDR
:
412 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_BANKADDR
, (unsigned long *) (& fields
->f_bankaddr
));
414 case MS1_OPERAND_BRC
:
415 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_BRC
, (unsigned long *) (& fields
->f_brc
));
417 case MS1_OPERAND_BRC2
:
418 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_BRC2
, (unsigned long *) (& fields
->f_brc2
));
420 case MS1_OPERAND_CBRB
:
421 errmsg
= parse_cbrb (cd
, strp
, MS1_OPERAND_CBRB
, (unsigned long *) (& fields
->f_cbrb
));
423 case MS1_OPERAND_CBS
:
424 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CBS
, (unsigned long *) (& fields
->f_cbs
));
426 case MS1_OPERAND_CBX
:
427 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CBX
, (unsigned long *) (& fields
->f_cbx
));
429 case MS1_OPERAND_CCB
:
430 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CCB
, (unsigned long *) (& fields
->f_ccb
));
432 case MS1_OPERAND_CDB
:
433 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CDB
, (unsigned long *) (& fields
->f_cdb
));
435 case MS1_OPERAND_CELL
:
436 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CELL
, (unsigned long *) (& fields
->f_cell
));
438 case MS1_OPERAND_COLNUM
:
439 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_COLNUM
, (unsigned long *) (& fields
->f_colnum
));
441 case MS1_OPERAND_CONTNUM
:
442 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CONTNUM
, (unsigned long *) (& fields
->f_contnum
));
444 case MS1_OPERAND_CR
:
445 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CR
, (unsigned long *) (& fields
->f_cr
));
447 case MS1_OPERAND_CTXDISP
:
448 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_CTXDISP
, (unsigned long *) (& fields
->f_ctxdisp
));
450 case MS1_OPERAND_DUP
:
451 errmsg
= parse_dup (cd
, strp
, MS1_OPERAND_DUP
, (unsigned long *) (& fields
->f_dup
));
453 case MS1_OPERAND_FBDISP
:
454 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_FBDISP
, (unsigned long *) (& fields
->f_fbdisp
));
456 case MS1_OPERAND_FBINCR
:
457 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_FBINCR
, (unsigned long *) (& fields
->f_fbincr
));
459 case MS1_OPERAND_FRDR
:
460 errmsg
= cgen_parse_keyword (cd
, strp
, & ms1_cgen_opval_h_spr
, & fields
->f_dr
);
462 case MS1_OPERAND_FRDRRR
:
463 errmsg
= cgen_parse_keyword (cd
, strp
, & ms1_cgen_opval_h_spr
, & fields
->f_drrr
);
465 case MS1_OPERAND_FRSR1
:
466 errmsg
= cgen_parse_keyword (cd
, strp
, & ms1_cgen_opval_h_spr
, & fields
->f_sr1
);
468 case MS1_OPERAND_FRSR2
:
469 errmsg
= cgen_parse_keyword (cd
, strp
, & ms1_cgen_opval_h_spr
, & fields
->f_sr2
);
471 case MS1_OPERAND_ID
:
472 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_ID
, (unsigned long *) (& fields
->f_id
));
474 case MS1_OPERAND_IMM16
:
475 errmsg
= parse_imm16 (cd
, strp
, MS1_OPERAND_IMM16
, (long *) (& fields
->f_imm16s
));
477 case MS1_OPERAND_IMM16O
:
478 errmsg
= parse_imm16 (cd
, strp
, MS1_OPERAND_IMM16O
, (unsigned long *) (& fields
->f_imm16s
));
480 case MS1_OPERAND_IMM16Z
:
481 errmsg
= parse_imm16 (cd
, strp
, MS1_OPERAND_IMM16Z
, (unsigned long *) (& fields
->f_imm16u
));
483 case MS1_OPERAND_INCAMT
:
484 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_INCAMT
, (unsigned long *) (& fields
->f_incamt
));
486 case MS1_OPERAND_INCR
:
487 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_INCR
, (unsigned long *) (& fields
->f_incr
));
489 case MS1_OPERAND_LENGTH
:
490 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_LENGTH
, (unsigned long *) (& fields
->f_length
));
492 case MS1_OPERAND_MASK
:
493 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_MASK
, (unsigned long *) (& fields
->f_mask
));
495 case MS1_OPERAND_MASK1
:
496 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_MASK1
, (unsigned long *) (& fields
->f_mask1
));
498 case MS1_OPERAND_MODE
:
499 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_MODE
, (unsigned long *) (& fields
->f_mode
));
501 case MS1_OPERAND_PERM
:
502 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_PERM
, (unsigned long *) (& fields
->f_perm
));
504 case MS1_OPERAND_RBBC
:
505 errmsg
= parse_rbbc (cd
, strp
, MS1_OPERAND_RBBC
, (unsigned long *) (& fields
->f_rbbc
));
507 case MS1_OPERAND_RC
:
508 errmsg
= parse_rc (cd
, strp
, MS1_OPERAND_RC
, (unsigned long *) (& fields
->f_rc
));
510 case MS1_OPERAND_RC1
:
511 errmsg
= parse_rc (cd
, strp
, MS1_OPERAND_RC1
, (unsigned long *) (& fields
->f_rc1
));
513 case MS1_OPERAND_RC2
:
514 errmsg
= parse_rc (cd
, strp
, MS1_OPERAND_RC2
, (unsigned long *) (& fields
->f_rc2
));
516 case MS1_OPERAND_RCNUM
:
517 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_RCNUM
, (unsigned long *) (& fields
->f_rcnum
));
519 case MS1_OPERAND_RDA
:
520 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_RDA
, (unsigned long *) (& fields
->f_rda
));
522 case MS1_OPERAND_ROWNUM
:
523 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_ROWNUM
, (unsigned long *) (& fields
->f_rownum
));
525 case MS1_OPERAND_ROWNUM1
:
526 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_ROWNUM1
, (unsigned long *) (& fields
->f_rownum1
));
528 case MS1_OPERAND_ROWNUM2
:
529 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_ROWNUM2
, (unsigned long *) (& fields
->f_rownum2
));
531 case MS1_OPERAND_SIZE
:
532 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_SIZE
, (unsigned long *) (& fields
->f_size
));
534 case MS1_OPERAND_TYPE
:
535 errmsg
= parse_type (cd
, strp
, MS1_OPERAND_TYPE
, (unsigned long *) (& fields
->f_type
));
537 case MS1_OPERAND_WR
:
538 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, MS1_OPERAND_WR
, (unsigned long *) (& fields
->f_wr
));
540 case MS1_OPERAND_XMODE
:
541 errmsg
= parse_xmode (cd
, strp
, MS1_OPERAND_XMODE
, (unsigned long *) (& fields
->f_xmode
));
545 /* xgettext:c-format */
546 fprintf (stderr
, _("Unrecognized field %d while parsing.\n"), opindex
);
553 cgen_parse_fn
* const ms1_cgen_parse_handlers
[] =
559 ms1_cgen_init_asm (CGEN_CPU_DESC cd
)
561 ms1_cgen_init_opcode_table (cd
);
562 ms1_cgen_init_ibld_table (cd
);
563 cd
->parse_handlers
= & ms1_cgen_parse_handlers
[0];
564 cd
->parse_operand
= ms1_cgen_parse_operand
;
569 /* Regex construction routine.
571 This translates an opcode syntax string into a regex string,
572 by replacing any non-character syntax element (such as an
573 opcode) with the pattern '.*'
575 It then compiles the regex and stores it in the opcode, for
576 later use by ms1_cgen_assemble_insn
578 Returns NULL for success, an error message for failure. */
581 ms1_cgen_build_insn_regex (CGEN_INSN
*insn
)
583 CGEN_OPCODE
*opc
= (CGEN_OPCODE
*) CGEN_INSN_OPCODE (insn
);
584 const char *mnem
= CGEN_INSN_MNEMONIC (insn
);
585 char rxbuf
[CGEN_MAX_RX_ELEMENTS
];
587 const CGEN_SYNTAX_CHAR_TYPE
*syn
;
590 syn
= CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc
));
592 /* Mnemonics come first in the syntax string. */
593 if (! CGEN_SYNTAX_MNEMONIC_P (* syn
))
594 return _("missing mnemonic in syntax string");
597 /* Generate a case sensitive regular expression that emulates case
598 insensitive matching in the "C" locale. We cannot generate a case
599 insensitive regular expression because in Turkish locales, 'i' and 'I'
600 are not equal modulo case conversion. */
602 /* Copy the literal mnemonic out of the insn. */
603 for (; *mnem
; mnem
++)
618 /* Copy any remaining literals from the syntax string into the rx. */
619 for(; * syn
!= 0 && rx
<= rxbuf
+ (CGEN_MAX_RX_ELEMENTS
- 7 - 4); ++syn
)
621 if (CGEN_SYNTAX_CHAR_P (* syn
))
623 char c
= CGEN_SYNTAX_CHAR (* syn
);
627 /* Escape any regex metacharacters in the syntax. */
628 case '.': case '[': case '\\':
629 case '*': case '^': case '$':
631 #ifdef CGEN_ESCAPE_EXTENDED_REGEX
632 case '?': case '{': case '}':
633 case '(': case ')': case '*':
634 case '|': case '+': case ']':
655 /* Replace non-syntax fields with globs. */
661 /* Trailing whitespace ok. */
668 /* But anchor it after that. */
672 CGEN_INSN_RX (insn
) = xmalloc (sizeof (regex_t
));
673 reg_err
= regcomp ((regex_t
*) CGEN_INSN_RX (insn
), rxbuf
, REG_NOSUB
);
681 regerror (reg_err
, (regex_t
*) CGEN_INSN_RX (insn
), msg
, 80);
682 regfree ((regex_t
*) CGEN_INSN_RX (insn
));
683 free (CGEN_INSN_RX (insn
));
684 (CGEN_INSN_RX (insn
)) = NULL
;
690 /* Default insn parser.
692 The syntax string is scanned and operands are parsed and stored in FIELDS.
693 Relocs are queued as we go via other callbacks.
695 ??? Note that this is currently an all-or-nothing parser. If we fail to
696 parse the instruction, we return 0 and the caller will start over from
697 the beginning. Backtracking will be necessary in parsing subexpressions,
698 but that can be handled there. Not handling backtracking here may get
699 expensive in the case of the m68k. Deal with later.
701 Returns NULL for success, an error message for failure. */
704 parse_insn_normal (CGEN_CPU_DESC cd
,
705 const CGEN_INSN
*insn
,
709 /* ??? Runtime added insns not handled yet. */
710 const CGEN_SYNTAX
*syntax
= CGEN_INSN_SYNTAX (insn
);
711 const char *str
= *strp
;
714 const CGEN_SYNTAX_CHAR_TYPE
* syn
;
715 #ifdef CGEN_MNEMONIC_OPERANDS
720 /* For now we assume the mnemonic is first (there are no leading operands).
721 We can parse it without needing to set up operand parsing.
722 GAS's input scrubber will ensure mnemonics are lowercase, but we may
723 not be called from GAS. */
724 p
= CGEN_INSN_MNEMONIC (insn
);
725 while (*p
&& TOLOWER (*p
) == TOLOWER (*str
))
729 return _("unrecognized instruction");
731 #ifndef CGEN_MNEMONIC_OPERANDS
732 if (* str
&& ! ISSPACE (* str
))
733 return _("unrecognized instruction");
736 CGEN_INIT_PARSE (cd
);
737 cgen_init_parse_operand (cd
);
738 #ifdef CGEN_MNEMONIC_OPERANDS
742 /* We don't check for (*str != '\0') here because we want to parse
743 any trailing fake arguments in the syntax string. */
744 syn
= CGEN_SYNTAX_STRING (syntax
);
746 /* Mnemonics come first for now, ensure valid string. */
747 if (! CGEN_SYNTAX_MNEMONIC_P (* syn
))
754 /* Non operand chars must match exactly. */
755 if (CGEN_SYNTAX_CHAR_P (* syn
))
757 /* FIXME: While we allow for non-GAS callers above, we assume the
758 first char after the mnemonic part is a space. */
759 /* FIXME: We also take inappropriate advantage of the fact that
760 GAS's input scrubber will remove extraneous blanks. */
761 if (TOLOWER (*str
) == TOLOWER (CGEN_SYNTAX_CHAR (* syn
)))
763 #ifdef CGEN_MNEMONIC_OPERANDS
764 if (CGEN_SYNTAX_CHAR(* syn
) == ' ')
772 /* Syntax char didn't match. Can't be this insn. */
773 static char msg
[80];
775 /* xgettext:c-format */
776 sprintf (msg
, _("syntax error (expected char `%c', found `%c')"),
777 CGEN_SYNTAX_CHAR(*syn
), *str
);
782 /* Ran out of input. */
783 static char msg
[80];
785 /* xgettext:c-format */
786 sprintf (msg
, _("syntax error (expected char `%c', found end of instruction)"),
787 CGEN_SYNTAX_CHAR(*syn
));
793 /* We have an operand of some sort. */
794 errmsg
= cd
->parse_operand (cd
, CGEN_SYNTAX_FIELD (*syn
),
799 /* Done with this operand, continue with next one. */
803 /* If we're at the end of the syntax string, we're done. */
806 /* FIXME: For the moment we assume a valid `str' can only contain
807 blanks now. IE: We needn't try again with a longer version of
808 the insn and it is assumed that longer versions of insns appear
809 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
810 while (ISSPACE (* str
))
814 return _("junk at end of line"); /* FIXME: would like to include `str' */
819 /* We couldn't parse it. */
820 return _("unrecognized instruction");
824 This routine is called for each instruction to be assembled.
825 STR points to the insn to be assembled.
826 We assume all necessary tables have been initialized.
827 The assembled instruction, less any fixups, is stored in BUF.
828 Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
829 still needs to be converted to target byte order, otherwise BUF is an array
830 of bytes in target byte order.
831 The result is a pointer to the insn's entry in the opcode table,
832 or NULL if an error occured (an error message will have already been
835 Note that when processing (non-alias) macro-insns,
836 this function recurses.
838 ??? It's possible to make this cpu-independent.
839 One would have to deal with a few minor things.
840 At this point in time doing so would be more of a curiosity than useful
841 [for example this file isn't _that_ big], but keeping the possibility in
842 mind helps keep the design clean. */
845 ms1_cgen_assemble_insn (CGEN_CPU_DESC cd
,
848 CGEN_INSN_BYTES_PTR buf
,
852 CGEN_INSN_LIST
*ilist
;
853 const char *parse_errmsg
= NULL
;
854 const char *insert_errmsg
= NULL
;
855 int recognized_mnemonic
= 0;
857 /* Skip leading white space. */
858 while (ISSPACE (* str
))
861 /* The instructions are stored in hashed lists.
862 Get the first in the list. */
863 ilist
= CGEN_ASM_LOOKUP_INSN (cd
, str
);
865 /* Keep looking until we find a match. */
867 for ( ; ilist
!= NULL
; ilist
= CGEN_ASM_NEXT_INSN (ilist
))
869 const CGEN_INSN
*insn
= ilist
->insn
;
870 recognized_mnemonic
= 1;
872 #ifdef CGEN_VALIDATE_INSN_SUPPORTED
873 /* Not usually needed as unsupported opcodes
874 shouldn't be in the hash lists. */
875 /* Is this insn supported by the selected cpu? */
876 if (! ms1_cgen_insn_supported (cd
, insn
))
879 /* If the RELAXED attribute is set, this is an insn that shouldn't be
880 chosen immediately. Instead, it is used during assembler/linker
881 relaxation if possible. */
882 if (CGEN_INSN_ATTR_VALUE (insn
, CGEN_INSN_RELAXED
) != 0)
887 /* Skip this insn if str doesn't look right lexically. */
888 if (CGEN_INSN_RX (insn
) != NULL
&&
889 regexec ((regex_t
*) CGEN_INSN_RX (insn
), str
, 0, NULL
, 0) == REG_NOMATCH
)
892 /* Allow parse/insert handlers to obtain length of insn. */
893 CGEN_FIELDS_BITSIZE (fields
) = CGEN_INSN_BITSIZE (insn
);
895 parse_errmsg
= CGEN_PARSE_FN (cd
, insn
) (cd
, insn
, & str
, fields
);
896 if (parse_errmsg
!= NULL
)
899 /* ??? 0 is passed for `pc'. */
900 insert_errmsg
= CGEN_INSERT_FN (cd
, insn
) (cd
, insn
, fields
, buf
,
902 if (insert_errmsg
!= NULL
)
905 /* It is up to the caller to actually output the insn and any
911 static char errbuf
[150];
912 #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
913 const char *tmp_errmsg
;
915 /* If requesting verbose error messages, use insert_errmsg.
916 Failing that, use parse_errmsg. */
917 tmp_errmsg
= (insert_errmsg
? insert_errmsg
:
918 parse_errmsg
? parse_errmsg
:
919 recognized_mnemonic
?
920 _("unrecognized form of instruction") :
921 _("unrecognized instruction"));
923 if (strlen (start
) > 50)
924 /* xgettext:c-format */
925 sprintf (errbuf
, "%s `%.50s...'", tmp_errmsg
, start
);
927 /* xgettext:c-format */
928 sprintf (errbuf
, "%s `%.50s'", tmp_errmsg
, start
);
930 if (strlen (start
) > 50)
931 /* xgettext:c-format */
932 sprintf (errbuf
, _("bad instruction `%.50s...'"), start
);
934 /* xgettext:c-format */
935 sprintf (errbuf
, _("bad instruction `%.50s'"), start
);