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.
34 #include "xc16x-desc.h"
35 #include "xc16x-opc.h"
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 /* Handle '#' prefixes (i.e. skip over them). */
55 parse_hash (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
57 int opindex ATTRIBUTE_UNUSED
,
58 long *valuep ATTRIBUTE_UNUSED
)
65 return _("Missing '#' prefix");
68 /* Handle '.' prefixes (i.e. skip over them). */
71 parse_dot (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
73 int opindex ATTRIBUTE_UNUSED
,
74 long *valuep ATTRIBUTE_UNUSED
)
81 return _("Missing '.' prefix");
84 /* Handle 'pof:' prefixes (i.e. skip over them). */
87 parse_pof (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
89 int opindex ATTRIBUTE_UNUSED
,
90 long *valuep ATTRIBUTE_UNUSED
)
92 if (strncasecmp (*strp
, "pof:", 4) == 0)
97 return _("Missing 'pof:' prefix");
100 /* Handle 'pag:' prefixes (i.e. skip over them). */
103 parse_pag (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
105 int opindex ATTRIBUTE_UNUSED
,
106 long *valuep ATTRIBUTE_UNUSED
)
108 if (strncasecmp (*strp
, "pag:", 4) == 0)
113 return _("Missing 'pag:' prefix");
116 /* Handle 'sof' prefixes (i.e. skip over them). */
119 parse_sof (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
121 int opindex ATTRIBUTE_UNUSED
,
122 long *valuep ATTRIBUTE_UNUSED
)
124 if (strncasecmp (*strp
, "sof:", 4) == 0)
129 return _("Missing 'sof:' prefix");
132 /* Handle 'seg' prefixes (i.e. skip over them). */
135 parse_seg (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED
,
137 int opindex ATTRIBUTE_UNUSED
,
138 long *valuep ATTRIBUTE_UNUSED
)
140 if (strncasecmp (*strp
, "seg:", 4) == 0)
145 return _("Missing 'seg:' prefix");
149 const char * xc16x_cgen_parse_operand
150 (CGEN_CPU_DESC
, int, const char **, CGEN_FIELDS
*);
152 /* Main entry point for operand parsing.
154 This function is basically just a big switch statement. Earlier versions
155 used tables to look up the function to use, but
156 - if the table contains both assembler and disassembler functions then
157 the disassembler contains much of the assembler and vice-versa,
158 - there's a lot of inlining possibilities as things grow,
159 - using a switch statement avoids the function call overhead.
161 This function could be moved into `parse_insn_normal', but keeping it
162 separate makes clear the interface between `parse_insn_normal' and each of
166 xc16x_cgen_parse_operand (CGEN_CPU_DESC cd
,
169 CGEN_FIELDS
* fields
)
171 const char * errmsg
= NULL
;
172 /* Used by scalar operands that still need to be parsed. */
173 long junk ATTRIBUTE_UNUSED
;
177 case XC16X_OPERAND_REGNAM
:
178 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_psw_names
, & fields
->f_reg8
);
180 case XC16X_OPERAND_BIT01
:
181 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_BIT01
, (unsigned long *) (& fields
->f_op_1bit
));
183 case XC16X_OPERAND_BIT1
:
184 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_BIT1
, (unsigned long *) (& fields
->f_op_bit1
));
186 case XC16X_OPERAND_BIT2
:
187 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_BIT2
, (unsigned long *) (& fields
->f_op_bit2
));
189 case XC16X_OPERAND_BIT4
:
190 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_BIT4
, (unsigned long *) (& fields
->f_op_bit4
));
192 case XC16X_OPERAND_BIT8
:
193 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_BIT8
, (unsigned long *) (& fields
->f_op_bit8
));
195 case XC16X_OPERAND_BITONE
:
196 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_BITONE
, (unsigned long *) (& fields
->f_op_onebit
));
198 case XC16X_OPERAND_CADDR
:
201 errmsg
= cgen_parse_address (cd
, strp
, XC16X_OPERAND_CADDR
, 0, NULL
, & value
);
202 fields
->f_offset16
= value
;
205 case XC16X_OPERAND_COND
:
206 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_conditioncode_names
, & fields
->f_condcode
);
208 case XC16X_OPERAND_DATA8
:
209 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_DATA8
, (unsigned long *) (& fields
->f_data8
));
211 case XC16X_OPERAND_DATAHI8
:
212 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_DATAHI8
, (unsigned long *) (& fields
->f_datahi8
));
214 case XC16X_OPERAND_DOT
:
215 errmsg
= parse_dot (cd
, strp
, XC16X_OPERAND_DOT
, (long *) (& junk
));
217 case XC16X_OPERAND_DR
:
218 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_gr_names
, & fields
->f_r1
);
220 case XC16X_OPERAND_DRB
:
221 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_grb_names
, & fields
->f_r1
);
223 case XC16X_OPERAND_DRI
:
224 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_gr_names
, & fields
->f_r4
);
226 case XC16X_OPERAND_EXTCOND
:
227 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_extconditioncode_names
, & fields
->f_extccode
);
229 case XC16X_OPERAND_GENREG
:
230 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_r8_names
, & fields
->f_regb8
);
232 case XC16X_OPERAND_HASH
:
233 errmsg
= parse_hash (cd
, strp
, XC16X_OPERAND_HASH
, (long *) (& junk
));
235 case XC16X_OPERAND_ICOND
:
236 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_conditioncode_names
, & fields
->f_icondcode
);
238 case XC16X_OPERAND_LBIT2
:
239 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_LBIT2
, (unsigned long *) (& fields
->f_op_lbit2
));
241 case XC16X_OPERAND_LBIT4
:
242 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_LBIT4
, (unsigned long *) (& fields
->f_op_lbit4
));
244 case XC16X_OPERAND_MASK8
:
245 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_MASK8
, (unsigned long *) (& fields
->f_mask8
));
247 case XC16X_OPERAND_MASKLO8
:
248 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_MASKLO8
, (unsigned long *) (& fields
->f_datahi8
));
250 case XC16X_OPERAND_MEMGR8
:
251 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_memgr8_names
, & fields
->f_memgr8
);
253 case XC16X_OPERAND_MEMORY
:
256 errmsg
= cgen_parse_address (cd
, strp
, XC16X_OPERAND_MEMORY
, 0, NULL
, & value
);
257 fields
->f_memory
= value
;
260 case XC16X_OPERAND_PAG
:
261 errmsg
= parse_pag (cd
, strp
, XC16X_OPERAND_PAG
, (long *) (& junk
));
263 case XC16X_OPERAND_PAGENUM
:
264 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_PAGENUM
, (unsigned long *) (& fields
->f_pagenum
));
266 case XC16X_OPERAND_POF
:
267 errmsg
= parse_pof (cd
, strp
, XC16X_OPERAND_POF
, (long *) (& junk
));
269 case XC16X_OPERAND_QBIT
:
270 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_QBIT
, (unsigned long *) (& fields
->f_qbit
));
272 case XC16X_OPERAND_QHIBIT
:
273 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_QHIBIT
, (unsigned long *) (& fields
->f_qhibit
));
275 case XC16X_OPERAND_QLOBIT
:
276 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_QLOBIT
, (unsigned long *) (& fields
->f_qlobit
));
278 case XC16X_OPERAND_REG8
:
279 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_r8_names
, & fields
->f_reg8
);
281 case XC16X_OPERAND_REGB8
:
282 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_grb8_names
, & fields
->f_regb8
);
284 case XC16X_OPERAND_REGBMEM8
:
285 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_regbmem8_names
, & fields
->f_regmem8
);
287 case XC16X_OPERAND_REGHI8
:
288 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_r8_names
, & fields
->f_reghi8
);
290 case XC16X_OPERAND_REGMEM8
:
291 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_regmem8_names
, & fields
->f_regmem8
);
293 case XC16X_OPERAND_REGOFF8
:
294 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_r8_names
, & fields
->f_regoff8
);
296 case XC16X_OPERAND_REL
:
297 errmsg
= cgen_parse_signed_integer (cd
, strp
, XC16X_OPERAND_REL
, (long *) (& fields
->f_rel8
));
299 case XC16X_OPERAND_RELHI
:
300 errmsg
= cgen_parse_signed_integer (cd
, strp
, XC16X_OPERAND_RELHI
, (long *) (& fields
->f_relhi8
));
302 case XC16X_OPERAND_SEG
:
303 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_SEG
, (unsigned long *) (& fields
->f_seg8
));
305 case XC16X_OPERAND_SEGHI8
:
306 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_SEGHI8
, (unsigned long *) (& fields
->f_segnum8
));
308 case XC16X_OPERAND_SEGM
:
309 errmsg
= parse_seg (cd
, strp
, XC16X_OPERAND_SEGM
, (long *) (& junk
));
311 case XC16X_OPERAND_SOF
:
312 errmsg
= parse_sof (cd
, strp
, XC16X_OPERAND_SOF
, (long *) (& junk
));
314 case XC16X_OPERAND_SR
:
315 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_gr_names
, & fields
->f_r2
);
317 case XC16X_OPERAND_SR2
:
318 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_gr_names
, & fields
->f_r0
);
320 case XC16X_OPERAND_SRB
:
321 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_grb_names
, & fields
->f_r2
);
323 case XC16X_OPERAND_SRC1
:
324 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_gr_names
, & fields
->f_r1
);
326 case XC16X_OPERAND_SRC2
:
327 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_gr_names
, & fields
->f_r2
);
329 case XC16X_OPERAND_SRDIV
:
330 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_regdiv8_names
, & fields
->f_reg8
);
332 case XC16X_OPERAND_U4
:
333 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_reg0_name
, & fields
->f_uimm4
);
335 case XC16X_OPERAND_UIMM16
:
336 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_UIMM16
, (unsigned long *) (& fields
->f_uimm16
));
338 case XC16X_OPERAND_UIMM2
:
339 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_ext_names
, & fields
->f_uimm2
);
341 case XC16X_OPERAND_UIMM3
:
342 errmsg
= cgen_parse_keyword (cd
, strp
, & xc16x_cgen_opval_reg0_name1
, & fields
->f_uimm3
);
344 case XC16X_OPERAND_UIMM4
:
345 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_UIMM4
, (unsigned long *) (& fields
->f_uimm4
));
347 case XC16X_OPERAND_UIMM7
:
348 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_UIMM7
, (unsigned long *) (& fields
->f_uimm7
));
350 case XC16X_OPERAND_UIMM8
:
351 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_UIMM8
, (unsigned long *) (& fields
->f_uimm8
));
353 case XC16X_OPERAND_UPAG16
:
354 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_UPAG16
, (unsigned long *) (& fields
->f_uimm16
));
356 case XC16X_OPERAND_UPOF16
:
359 errmsg
= cgen_parse_address (cd
, strp
, XC16X_OPERAND_UPOF16
, 0, NULL
, & value
);
360 fields
->f_memory
= value
;
363 case XC16X_OPERAND_USEG16
:
364 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_USEG16
, (unsigned long *) (& fields
->f_offset16
));
366 case XC16X_OPERAND_USEG8
:
367 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_USEG8
, (unsigned long *) (& fields
->f_seg8
));
369 case XC16X_OPERAND_USOF16
:
370 errmsg
= cgen_parse_unsigned_integer (cd
, strp
, XC16X_OPERAND_USOF16
, (unsigned long *) (& fields
->f_offset16
));
374 /* xgettext:c-format */
375 fprintf (stderr
, _("Unrecognized field %d while parsing.\n"), opindex
);
382 cgen_parse_fn
* const xc16x_cgen_parse_handlers
[] =
388 xc16x_cgen_init_asm (CGEN_CPU_DESC cd
)
390 xc16x_cgen_init_opcode_table (cd
);
391 xc16x_cgen_init_ibld_table (cd
);
392 cd
->parse_handlers
= & xc16x_cgen_parse_handlers
[0];
393 cd
->parse_operand
= xc16x_cgen_parse_operand
;
398 /* Regex construction routine.
400 This translates an opcode syntax string into a regex string,
401 by replacing any non-character syntax element (such as an
402 opcode) with the pattern '.*'
404 It then compiles the regex and stores it in the opcode, for
405 later use by xc16x_cgen_assemble_insn
407 Returns NULL for success, an error message for failure. */
410 xc16x_cgen_build_insn_regex (CGEN_INSN
*insn
)
412 CGEN_OPCODE
*opc
= (CGEN_OPCODE
*) CGEN_INSN_OPCODE (insn
);
413 const char *mnem
= CGEN_INSN_MNEMONIC (insn
);
414 char rxbuf
[CGEN_MAX_RX_ELEMENTS
];
416 const CGEN_SYNTAX_CHAR_TYPE
*syn
;
419 syn
= CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc
));
421 /* Mnemonics come first in the syntax string. */
422 if (! CGEN_SYNTAX_MNEMONIC_P (* syn
))
423 return _("missing mnemonic in syntax string");
426 /* Generate a case sensitive regular expression that emulates case
427 insensitive matching in the "C" locale. We cannot generate a case
428 insensitive regular expression because in Turkish locales, 'i' and 'I'
429 are not equal modulo case conversion. */
431 /* Copy the literal mnemonic out of the insn. */
432 for (; *mnem
; mnem
++)
447 /* Copy any remaining literals from the syntax string into the rx. */
448 for(; * syn
!= 0 && rx
<= rxbuf
+ (CGEN_MAX_RX_ELEMENTS
- 7 - 4); ++syn
)
450 if (CGEN_SYNTAX_CHAR_P (* syn
))
452 char c
= CGEN_SYNTAX_CHAR (* syn
);
456 /* Escape any regex metacharacters in the syntax. */
457 case '.': case '[': case '\\':
458 case '*': case '^': case '$':
460 #ifdef CGEN_ESCAPE_EXTENDED_REGEX
461 case '?': case '{': case '}':
462 case '(': case ')': case '*':
463 case '|': case '+': case ']':
484 /* Replace non-syntax fields with globs. */
490 /* Trailing whitespace ok. */
497 /* But anchor it after that. */
501 CGEN_INSN_RX (insn
) = xmalloc (sizeof (regex_t
));
502 reg_err
= regcomp ((regex_t
*) CGEN_INSN_RX (insn
), rxbuf
, REG_NOSUB
);
510 regerror (reg_err
, (regex_t
*) CGEN_INSN_RX (insn
), msg
, 80);
511 regfree ((regex_t
*) CGEN_INSN_RX (insn
));
512 free (CGEN_INSN_RX (insn
));
513 (CGEN_INSN_RX (insn
)) = NULL
;
519 /* Default insn parser.
521 The syntax string is scanned and operands are parsed and stored in FIELDS.
522 Relocs are queued as we go via other callbacks.
524 ??? Note that this is currently an all-or-nothing parser. If we fail to
525 parse the instruction, we return 0 and the caller will start over from
526 the beginning. Backtracking will be necessary in parsing subexpressions,
527 but that can be handled there. Not handling backtracking here may get
528 expensive in the case of the m68k. Deal with later.
530 Returns NULL for success, an error message for failure. */
533 parse_insn_normal (CGEN_CPU_DESC cd
,
534 const CGEN_INSN
*insn
,
538 /* ??? Runtime added insns not handled yet. */
539 const CGEN_SYNTAX
*syntax
= CGEN_INSN_SYNTAX (insn
);
540 const char *str
= *strp
;
543 const CGEN_SYNTAX_CHAR_TYPE
* syn
;
544 #ifdef CGEN_MNEMONIC_OPERANDS
549 /* For now we assume the mnemonic is first (there are no leading operands).
550 We can parse it without needing to set up operand parsing.
551 GAS's input scrubber will ensure mnemonics are lowercase, but we may
552 not be called from GAS. */
553 p
= CGEN_INSN_MNEMONIC (insn
);
554 while (*p
&& TOLOWER (*p
) == TOLOWER (*str
))
558 return _("unrecognized instruction");
560 #ifndef CGEN_MNEMONIC_OPERANDS
561 if (* str
&& ! ISSPACE (* str
))
562 return _("unrecognized instruction");
565 CGEN_INIT_PARSE (cd
);
566 cgen_init_parse_operand (cd
);
567 #ifdef CGEN_MNEMONIC_OPERANDS
571 /* We don't check for (*str != '\0') here because we want to parse
572 any trailing fake arguments in the syntax string. */
573 syn
= CGEN_SYNTAX_STRING (syntax
);
575 /* Mnemonics come first for now, ensure valid string. */
576 if (! CGEN_SYNTAX_MNEMONIC_P (* syn
))
583 /* Non operand chars must match exactly. */
584 if (CGEN_SYNTAX_CHAR_P (* syn
))
586 /* FIXME: While we allow for non-GAS callers above, we assume the
587 first char after the mnemonic part is a space. */
588 /* FIXME: We also take inappropriate advantage of the fact that
589 GAS's input scrubber will remove extraneous blanks. */
590 if (TOLOWER (*str
) == TOLOWER (CGEN_SYNTAX_CHAR (* syn
)))
592 #ifdef CGEN_MNEMONIC_OPERANDS
593 if (CGEN_SYNTAX_CHAR(* syn
) == ' ')
601 /* Syntax char didn't match. Can't be this insn. */
602 static char msg
[80];
604 /* xgettext:c-format */
605 sprintf (msg
, _("syntax error (expected char `%c', found `%c')"),
606 CGEN_SYNTAX_CHAR(*syn
), *str
);
611 /* Ran out of input. */
612 static char msg
[80];
614 /* xgettext:c-format */
615 sprintf (msg
, _("syntax error (expected char `%c', found end of instruction)"),
616 CGEN_SYNTAX_CHAR(*syn
));
622 /* We have an operand of some sort. */
623 errmsg
= cd
->parse_operand (cd
, CGEN_SYNTAX_FIELD (*syn
),
628 /* Done with this operand, continue with next one. */
632 /* If we're at the end of the syntax string, we're done. */
635 /* FIXME: For the moment we assume a valid `str' can only contain
636 blanks now. IE: We needn't try again with a longer version of
637 the insn and it is assumed that longer versions of insns appear
638 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
639 while (ISSPACE (* str
))
643 return _("junk at end of line"); /* FIXME: would like to include `str' */
648 /* We couldn't parse it. */
649 return _("unrecognized instruction");
653 This routine is called for each instruction to be assembled.
654 STR points to the insn to be assembled.
655 We assume all necessary tables have been initialized.
656 The assembled instruction, less any fixups, is stored in BUF.
657 Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
658 still needs to be converted to target byte order, otherwise BUF is an array
659 of bytes in target byte order.
660 The result is a pointer to the insn's entry in the opcode table,
661 or NULL if an error occured (an error message will have already been
664 Note that when processing (non-alias) macro-insns,
665 this function recurses.
667 ??? It's possible to make this cpu-independent.
668 One would have to deal with a few minor things.
669 At this point in time doing so would be more of a curiosity than useful
670 [for example this file isn't _that_ big], but keeping the possibility in
671 mind helps keep the design clean. */
674 xc16x_cgen_assemble_insn (CGEN_CPU_DESC cd
,
677 CGEN_INSN_BYTES_PTR buf
,
681 CGEN_INSN_LIST
*ilist
;
682 const char *parse_errmsg
= NULL
;
683 const char *insert_errmsg
= NULL
;
684 int recognized_mnemonic
= 0;
686 /* Skip leading white space. */
687 while (ISSPACE (* str
))
690 /* The instructions are stored in hashed lists.
691 Get the first in the list. */
692 ilist
= CGEN_ASM_LOOKUP_INSN (cd
, str
);
694 /* Keep looking until we find a match. */
696 for ( ; ilist
!= NULL
; ilist
= CGEN_ASM_NEXT_INSN (ilist
))
698 const CGEN_INSN
*insn
= ilist
->insn
;
699 recognized_mnemonic
= 1;
701 #ifdef CGEN_VALIDATE_INSN_SUPPORTED
702 /* Not usually needed as unsupported opcodes
703 shouldn't be in the hash lists. */
704 /* Is this insn supported by the selected cpu? */
705 if (! xc16x_cgen_insn_supported (cd
, insn
))
708 /* If the RELAXED attribute is set, this is an insn that shouldn't be
709 chosen immediately. Instead, it is used during assembler/linker
710 relaxation if possible. */
711 if (CGEN_INSN_ATTR_VALUE (insn
, CGEN_INSN_RELAXED
) != 0)
716 /* Skip this insn if str doesn't look right lexically. */
717 if (CGEN_INSN_RX (insn
) != NULL
&&
718 regexec ((regex_t
*) CGEN_INSN_RX (insn
), str
, 0, NULL
, 0) == REG_NOMATCH
)
721 /* Allow parse/insert handlers to obtain length of insn. */
722 CGEN_FIELDS_BITSIZE (fields
) = CGEN_INSN_BITSIZE (insn
);
724 parse_errmsg
= CGEN_PARSE_FN (cd
, insn
) (cd
, insn
, & str
, fields
);
725 if (parse_errmsg
!= NULL
)
728 /* ??? 0 is passed for `pc'. */
729 insert_errmsg
= CGEN_INSERT_FN (cd
, insn
) (cd
, insn
, fields
, buf
,
731 if (insert_errmsg
!= NULL
)
734 /* It is up to the caller to actually output the insn and any
740 static char errbuf
[150];
741 #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
742 const char *tmp_errmsg
;
744 /* If requesting verbose error messages, use insert_errmsg.
745 Failing that, use parse_errmsg. */
746 tmp_errmsg
= (insert_errmsg
? insert_errmsg
:
747 parse_errmsg
? parse_errmsg
:
748 recognized_mnemonic
?
749 _("unrecognized form of instruction") :
750 _("unrecognized instruction"));
752 if (strlen (start
) > 50)
753 /* xgettext:c-format */
754 sprintf (errbuf
, "%s `%.50s...'", tmp_errmsg
, start
);
756 /* xgettext:c-format */
757 sprintf (errbuf
, "%s `%.50s'", tmp_errmsg
, start
);
759 if (strlen (start
) > 50)
760 /* xgettext:c-format */
761 sprintf (errbuf
, _("bad instruction `%.50s...'"), start
);
763 /* xgettext:c-format */
764 sprintf (errbuf
, _("bad instruction `%.50s'"), start
);