]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - opcodes/mep-asm.c
New Romanian translation for ld
[thirdparty/binutils-gdb.git] / opcodes / mep-asm.c
CommitLineData
4162bb66 1/* DO NOT EDIT! -*- buffer-read-only: t -*- vi:set ro: */
bd2f2e55
DB
2/* Assembler interface for targets using CGEN. -*- C -*-
3 CGEN: Cpu tools GENerator
4
5 THIS FILE IS MACHINE GENERATED WITH CGEN.
6 - the resultant file is machine generated, cgen-asm.in isn't
7
d87bef3a 8 Copyright (C) 1996-2023 Free Software Foundation, Inc.
bd2f2e55 9
9b201bb5 10 This file is part of libopcodes.
bd2f2e55 11
9b201bb5 12 This library is free software; you can redistribute it and/or modify
bd2f2e55 13 it under the terms of the GNU General Public License as published by
9b201bb5 14 the Free Software Foundation; either version 3, or (at your option)
bd2f2e55
DB
15 any later version.
16
9b201bb5
NC
17 It is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
20 License for more details.
bd2f2e55
DB
21
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. */
25
9b201bb5 26
bd2f2e55
DB
27/* ??? Eventually more and more of this stuff can go to cpu-independent files.
28 Keep that in mind. */
29
30#include "sysdep.h"
31#include <stdio.h>
32#include "ansidecl.h"
33#include "bfd.h"
34#include "symcat.h"
35#include "mep-desc.h"
36#include "mep-opc.h"
37#include "opintl.h"
38#include "xregex.h"
39#include "libiberty.h"
40#include "safe-ctype.h"
41
42#undef min
43#define min(a,b) ((a) < (b) ? (a) : (b))
44#undef max
45#define max(a,b) ((a) > (b) ? (a) : (b))
46
47static const char * parse_insn_normal
48 (CGEN_CPU_DESC, const CGEN_INSN *, const char **, CGEN_FIELDS *);
49\f
50/* -- assembler routines inserted here. */
51
52/* -- asm.c */
53
40493983
DD
54#include "elf/mep.h"
55
bd2f2e55 56#define CGEN_VALIDATE_INSN_SUPPORTED
378a0c07 57#define mep_cgen_insn_supported mep_cgen_insn_supported_asm
bd2f2e55
DB
58
59 const char * parse_csrn (CGEN_CPU_DESC, const char **, CGEN_KEYWORD *, long *);
60 const char * parse_tpreg (CGEN_CPU_DESC, const char **, CGEN_KEYWORD *, long *);
61 const char * parse_spreg (CGEN_CPU_DESC, const char **, CGEN_KEYWORD *, long *);
62 const char * parse_mep_align (CGEN_CPU_DESC, const char **, enum cgen_operand_type, long *);
63 const char * parse_mep_alignu (CGEN_CPU_DESC, const char **, enum cgen_operand_type, unsigned long *);
64static const char * parse_signed16 (CGEN_CPU_DESC, const char **, int, long *);
05316052 65static const char * parse_signed16_range (CGEN_CPU_DESC, const char **, int, long *) ATTRIBUTE_UNUSED;
bd2f2e55 66static const char * parse_unsigned16 (CGEN_CPU_DESC, const char **, int, unsigned long *);
05316052 67static const char * parse_unsigned16_range (CGEN_CPU_DESC, const char **, int, unsigned long *) ATTRIBUTE_UNUSED;
bd2f2e55
DB
68static const char * parse_lo16 (CGEN_CPU_DESC, const char **, int, long *, long);
69static const char * parse_unsigned7 (CGEN_CPU_DESC, const char **, enum cgen_operand_type, unsigned long *);
70static const char * parse_zero (CGEN_CPU_DESC, const char **, int, long *);
71
72const char *
73parse_csrn (CGEN_CPU_DESC cd, const char **strp,
74 CGEN_KEYWORD *keyword_table, long *field)
75{
76 const char *err;
77 unsigned long value;
78
79 err = cgen_parse_keyword (cd, strp, keyword_table, field);
80 if (!err)
81 return NULL;
82
83 err = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_CSRN_IDX, & value);
84 if (err)
85 return err;
86 *field = value;
87 return NULL;
88}
89
90/* begin-cop-ip-parse-handlers */
3526b680
DD
91static const char *
92parse_ivc2_cr (CGEN_CPU_DESC,
93 const char **,
94 CGEN_KEYWORD *,
95 long *) ATTRIBUTE_UNUSED;
96static const char *
97parse_ivc2_cr (CGEN_CPU_DESC cd,
98 const char **strp,
99 CGEN_KEYWORD *keyword_table ATTRIBUTE_UNUSED,
100 long *field)
101{
102 return cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr_ivc2, field);
103}
104static const char *
105parse_ivc2_ccr (CGEN_CPU_DESC,
106 const char **,
107 CGEN_KEYWORD *,
108 long *) ATTRIBUTE_UNUSED;
109static const char *
110parse_ivc2_ccr (CGEN_CPU_DESC cd,
111 const char **strp,
112 CGEN_KEYWORD *keyword_table ATTRIBUTE_UNUSED,
113 long *field)
114{
115 return cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, field);
116}
bd2f2e55
DB
117/* end-cop-ip-parse-handlers */
118
119const char *
120parse_tpreg (CGEN_CPU_DESC cd, const char ** strp,
121 CGEN_KEYWORD *keyword_table, long *field)
122{
123 const char *err;
124
125 err = cgen_parse_keyword (cd, strp, keyword_table, field);
126 if (err)
127 return err;
128 if (*field != 13)
129 return _("Only $tp or $13 allowed for this opcode");
130 return NULL;
131}
132
133const char *
134parse_spreg (CGEN_CPU_DESC cd, const char ** strp,
135 CGEN_KEYWORD *keyword_table, long *field)
136{
137 const char *err;
138
139 err = cgen_parse_keyword (cd, strp, keyword_table, field);
140 if (err)
141 return err;
142 if (*field != 15)
143 return _("Only $sp or $15 allowed for this opcode");
144 return NULL;
145}
146
147const char *
148parse_mep_align (CGEN_CPU_DESC cd, const char ** strp,
149 enum cgen_operand_type type, long *field)
150{
151 long lsbs = 0;
152 const char *err;
153
154 switch (type)
155 {
156 case MEP_OPERAND_PCREL8A2:
157 case MEP_OPERAND_PCREL12A2:
158 case MEP_OPERAND_PCREL17A2:
159 case MEP_OPERAND_PCREL24A2:
bd2f2e55
DB
160 err = cgen_parse_signed_integer (cd, strp, type, field);
161 break;
162 case MEP_OPERAND_PCABS24A2:
163 case MEP_OPERAND_UDISP7:
164 case MEP_OPERAND_UDISP7A2:
165 case MEP_OPERAND_UDISP7A4:
166 case MEP_OPERAND_UIMM7A4:
167 case MEP_OPERAND_ADDR24A4:
168 err = cgen_parse_unsigned_integer (cd, strp, type, (unsigned long *) field);
169 break;
170 default:
171 abort();
172 }
173 if (err)
174 return err;
175 switch (type)
176 {
177 case MEP_OPERAND_UDISP7:
178 lsbs = 0;
179 break;
180 case MEP_OPERAND_PCREL8A2:
181 case MEP_OPERAND_PCREL12A2:
182 case MEP_OPERAND_PCREL17A2:
183 case MEP_OPERAND_PCREL24A2:
184 case MEP_OPERAND_PCABS24A2:
185 case MEP_OPERAND_UDISP7A2:
bd2f2e55
DB
186 lsbs = *field & 1;
187 break;
188 case MEP_OPERAND_UDISP7A4:
189 case MEP_OPERAND_UIMM7A4:
190 case MEP_OPERAND_ADDR24A4:
bd2f2e55
DB
191 lsbs = *field & 3;
192 break;
bd2f2e55
DB
193 lsbs = *field & 7;
194 break;
195 default:
196 /* Safe assumption? */
197 abort ();
198 }
199 if (lsbs)
200 return "Value is not aligned enough";
201 return NULL;
202}
203
204const char *
205parse_mep_alignu (CGEN_CPU_DESC cd, const char ** strp,
206 enum cgen_operand_type type, unsigned long *field)
207{
208 return parse_mep_align (cd, strp, type, (long *) field);
209}
210
211
212/* Handle %lo(), %tpoff(), %sdaoff(), %hi(), and other signed
213 constants in a signed context. */
214
215static const char *
216parse_signed16 (CGEN_CPU_DESC cd,
217 const char **strp,
218 int opindex,
219 long *valuep)
220{
221 return parse_lo16 (cd, strp, opindex, valuep, 1);
222}
223
224static const char *
225parse_lo16 (CGEN_CPU_DESC cd,
226 const char **strp,
227 int opindex,
228 long *valuep,
229 long signedp)
230{
231 const char *errmsg;
232 enum cgen_parse_operand_result result_type;
233 bfd_vma value;
234
235 if (strncasecmp (*strp, "%lo(", 4) == 0)
236 {
237 *strp += 4;
238 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_LOW16,
239 & result_type, & value);
240 if (**strp != ')')
241 return _("missing `)'");
242 ++*strp;
243 if (errmsg == NULL
244 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
245 value &= 0xffff;
246 if (signedp)
247 *valuep = (long)(short) value;
248 else
249 *valuep = value;
250 return errmsg;
251 }
252
253 if (strncasecmp (*strp, "%hi(", 4) == 0)
254 {
255 *strp += 4;
256 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_HI16S,
257 & result_type, & value);
258 if (**strp != ')')
259 return _("missing `)'");
260 ++*strp;
261 if (errmsg == NULL
262 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
263 value = (value + 0x8000) >> 16;
264 *valuep = value;
265 return errmsg;
266 }
267
268 if (strncasecmp (*strp, "%uhi(", 5) == 0)
269 {
270 *strp += 5;
271 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_HI16U,
272 & result_type, & value);
273 if (**strp != ')')
274 return _("missing `)'");
275 ++*strp;
276 if (errmsg == NULL
277 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
278 value = value >> 16;
279 *valuep = value;
280 return errmsg;
281 }
282
283 if (strncasecmp (*strp, "%sdaoff(", 8) == 0)
284 {
285 *strp += 8;
286 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_GPREL,
287 NULL, & value);
288 if (**strp != ')')
289 return _("missing `)'");
290 ++*strp;
291 *valuep = value;
292 return errmsg;
293 }
294
295 if (strncasecmp (*strp, "%tpoff(", 7) == 0)
296 {
297 *strp += 7;
298 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_TPREL,
299 NULL, & value);
300 if (**strp != ')')
301 return _("missing `)'");
302 ++*strp;
303 *valuep = value;
304 return errmsg;
305 }
306
307 if (**strp == '%')
308 return _("invalid %function() here");
309
310 return cgen_parse_signed_integer (cd, strp, opindex, valuep);
311}
312
313static const char *
314parse_unsigned16 (CGEN_CPU_DESC cd,
315 const char **strp,
316 int opindex,
317 unsigned long *valuep)
318{
319 return parse_lo16 (cd, strp, opindex, (long *) valuep, 0);
320}
321
d285268e
DD
322static const char *
323parse_signed16_range (CGEN_CPU_DESC cd,
324 const char **strp,
325 int opindex,
326 signed long *valuep)
327{
328 const char *errmsg = 0;
329 signed long value;
330
331 errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value);
332 if (errmsg)
333 return errmsg;
334
335 if (value < -32768 || value > 32767)
336 return _("Immediate is out of range -32768 to 32767");
337
338 *valuep = value;
339 return 0;
340}
341
342static const char *
343parse_unsigned16_range (CGEN_CPU_DESC cd,
344 const char **strp,
345 int opindex,
346 unsigned long *valuep)
347{
348 const char *errmsg = 0;
349 unsigned long value;
350
351 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, & value);
352 if (errmsg)
353 return errmsg;
354
355 if (value > 65535)
356 return _("Immediate is out of range 0 to 65535");
357
358 *valuep = value;
359 return 0;
360}
361
bd2f2e55
DB
362/* A special case of parse_signed16 which accepts only the value zero. */
363
364static const char *
365parse_zero (CGEN_CPU_DESC cd, const char **strp, int opindex, long *valuep)
366{
367 const char *errmsg;
368 enum cgen_parse_operand_result result_type;
369 bfd_vma value;
370
371 /*fprintf(stderr, "dj: signed parse opindex `%s'\n", *strp);*/
372
373 /* Prevent ($ry) from being attempted as an expression on 'sw $rx,($ry)'.
374 It will fail and cause ry to be listed as an undefined symbol in the
375 listing. */
376 if (strncmp (*strp, "($", 2) == 0)
377 return "not zero"; /* any string will do -- will never be seen. */
378
379 if (strncasecmp (*strp, "%lo(", 4) == 0)
380 {
381 *strp += 4;
382 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_LOW16,
383 &result_type, &value);
384 if (**strp != ')')
385 return "missing `)'";
386 ++*strp;
387 if (errmsg == NULL
388 && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
389 return "not zero"; /* any string will do -- will never be seen. */
390 *valuep = value;
391 return errmsg;
392 }
393
394 if (strncasecmp (*strp, "%hi(", 4) == 0)
395 {
396 *strp += 4;
397 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_HI16S,
398 &result_type, &value);
399 if (**strp != ')')
400 return "missing `)'";
401 ++*strp;
402 if (errmsg == NULL
403 && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
404 return "not zero"; /* any string will do -- will never be seen. */
405 *valuep = value;
406 return errmsg;
407 }
408
409 if (strncasecmp (*strp, "%uhi(", 5) == 0)
410 {
411 *strp += 5;
412 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_HI16U,
413 &result_type, &value);
414 if (**strp != ')')
415 return "missing `)'";
416 ++*strp;
417 if (errmsg == NULL
418 && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
419 return "not zero"; /* any string will do -- will never be seen. */
420 *valuep = value;
421 return errmsg;
422 }
423
424 if (strncasecmp (*strp, "%sdaoff(", 8) == 0)
425 {
426 *strp += 8;
427 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_GPREL,
428 &result_type, &value);
429 if (**strp != ')')
430 return "missing `)'";
431 ++*strp;
432 if (errmsg == NULL
433 && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
434 return "not zero"; /* any string will do -- will never be seen. */
435 *valuep = value;
436 return errmsg;
437 }
438
439 if (strncasecmp (*strp, "%tpoff(", 7) == 0)
440 {
441 *strp += 7;
442 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_TPREL,
443 &result_type, &value);
444 if (**strp != ')')
445 return "missing `)'";
446 ++*strp;
447 if (errmsg == NULL
448 && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
449 return "not zero"; /* any string will do -- will never be seen. */
450 *valuep = value;
451 return errmsg;
452 }
453
454 if (**strp == '%')
455 return "invalid %function() here";
456
457 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_NONE,
458 &result_type, &value);
459 if (errmsg == NULL
460 && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
461 return "not zero"; /* any string will do -- will never be seen. */
462
463 return errmsg;
464}
465
466static const char *
467parse_unsigned7 (CGEN_CPU_DESC cd, const char **strp,
468 enum cgen_operand_type opindex, unsigned long *valuep)
469{
470 const char *errmsg;
471 bfd_vma value;
472
473 /* fprintf(stderr, "dj: unsigned7 parse `%s'\n", *strp); */
474
475 if (strncasecmp (*strp, "%tpoff(", 7) == 0)
476 {
477 int reloc;
478 *strp += 7;
479 switch (opindex)
480 {
481 case MEP_OPERAND_UDISP7:
482 reloc = BFD_RELOC_MEP_TPREL7;
483 break;
484 case MEP_OPERAND_UDISP7A2:
485 reloc = BFD_RELOC_MEP_TPREL7A2;
486 break;
487 case MEP_OPERAND_UDISP7A4:
488 reloc = BFD_RELOC_MEP_TPREL7A4;
489 break;
490 default:
491 /* Safe assumption? */
43e65147 492 abort ();
bd2f2e55
DB
493 }
494 errmsg = cgen_parse_address (cd, strp, opindex, reloc,
495 NULL, &value);
496 if (**strp != ')')
497 return "missing `)'";
498 ++*strp;
499 *valuep = value;
500 return errmsg;
501 }
502
503 if (**strp == '%')
504 return _("invalid %function() here");
505
506 return parse_mep_alignu (cd, strp, opindex, valuep);
507}
508
40493983
DD
509static ATTRIBUTE_UNUSED const char *
510parse_cdisp10 (CGEN_CPU_DESC cd,
511 const char **strp,
512 int opindex,
513 long *valuep)
514{
515 const char *errmsg = 0;
516 signed long value;
517 long have_zero = 0;
518 int wide = 0;
519 int alignment;
520
521 switch (opindex)
522 {
523 case MEP_OPERAND_CDISP10A4:
524 alignment = 2;
525 break;
526 case MEP_OPERAND_CDISP10A2:
527 alignment = 1;
528 break;
529 case MEP_OPERAND_CDISP10:
530 default:
531 alignment = 0;
532 break;
533 }
534
eb956800 535 if ((MEP_CPU & EF_MEP_CPU_MASK) == EF_MEP_CPU_C5)
40493983
DD
536 wide = 1;
537
43e65147 538 if (strncmp (*strp, "0x0", 3) == 0
40493983
DD
539 || (**strp == '0' && *(*strp + 1) != 'x'))
540 have_zero = 1;
541
542 errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value);
543 if (errmsg)
544 return errmsg;
545
546 if (wide)
547 {
548 if (value < -512 || value > 511)
549 return _("Immediate is out of range -512 to 511");
550 }
551 else
552 {
553 if (value < -128 || value > 127)
554 return _("Immediate is out of range -128 to 127");
555 }
556
557 if (value & ((1<<alignment)-1))
558 return _("Value is not aligned enough");
559
560 /* If this field may require a relocation then use larger dsp16. */
561 if (! have_zero && value == 0)
562 return (wide ? _("Immediate is out of range -512 to 511")
563 : _("Immediate is out of range -128 to 127"));
564
565 *valuep = value;
566 return 0;
567}
568
bd2f2e55
DB
569/* BEGIN LIGHTWEIGHT MACRO PROCESSOR. */
570
571#define MAXARGS 9
572
573typedef struct
574{
575 char *name;
576 char *expansion;
577} macro;
578
579typedef struct
580{
581 const char *start;
582 int len;
583} arg;
584
f375d32b 585static macro const macros[] =
bd2f2e55
DB
586{
587 { "sizeof", "(`1.end + (- `1))"},
588 { "startof", "(`1 | 0)" },
589 { "align4", "(`1&(~3))"},
590/*{ "hi", "(((`1+0x8000)>>16) & 0xffff)" }, */
591/*{ "lo", "(`1 & 0xffff)" }, */
592/*{ "sdaoff", "((`1-__sdabase) & 0x7f)"}, */
593/*{ "tpoff", "((`1-__tpbase) & 0x7f)"}, */
594 { 0,0 }
595};
596
597static char * expand_string (const char *, int);
598
599static const char *
600mep_cgen_expand_macros_and_parse_operand
601 (CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *);
602
603static char *
604str_append (char *dest, const char *input, int len)
43e65147 605{
bd2f2e55
DB
606 char *new_dest;
607 int oldlen;
608
609 if (len == 0)
610 return dest;
611 /* printf("str_append: <<%s>>, <<%s>>, %d\n", dest, input, len); */
612 oldlen = (dest ? strlen(dest) : 0);
613 new_dest = realloc (dest, oldlen + len + 1);
614 memset (new_dest + oldlen, 0, len + 1);
615 return strncat (new_dest, input, len);
616}
617
f375d32b 618static const macro *
bd2f2e55
DB
619lookup_macro (const char *name)
620{
f375d32b 621 const macro *m;
bd2f2e55
DB
622
623 for (m = macros; m->name; ++m)
624 if (strncmp (m->name, name, strlen(m->name)) == 0)
625 return m;
626
627 return 0;
628}
629
630static char *
f375d32b 631expand_macro (arg *args, int narg, const macro *mac)
bd2f2e55
DB
632{
633 char *result = 0, *rescanned_result = 0;
634 char *e = mac->expansion;
635 char *mark = e;
91d6fa6a 636 int mac_arg = 0;
bd2f2e55
DB
637
638 /* printf("expanding macro %s with %d args\n", mac->name, narg + 1); */
639 while (*e)
640 {
3e8b13bf
AM
641 if (*e == '`'
642 && (*e+1)
643 && ((*(e + 1) - '1') <= MAXARGS)
644 && ((*(e + 1) - '1') <= narg))
bd2f2e55
DB
645 {
646 result = str_append (result, mark, e - mark);
91d6fa6a
NC
647 mac_arg = (*(e + 1) - '1');
648 /* printf("replacing `%d with %s\n", mac_arg+1, args[mac_arg].start); */
649 result = str_append (result, args[mac_arg].start, args[mac_arg].len);
bd2f2e55
DB
650 ++e;
651 mark = e+1;
652 }
653 ++e;
654 }
655
656 if (mark != e)
657 result = str_append (result, mark, e - mark);
658
659 if (result)
660 {
661 rescanned_result = expand_string (result, 0);
662 free (result);
663 return rescanned_result;
664 }
43e65147 665 else
bd2f2e55
DB
666 return result;
667}
668
669#define IN_TEXT 0
670#define IN_ARGS 1
671
672static char *
673expand_string (const char *in, int first_only)
674{
675 int num_expansions = 0;
676 int depth = 0;
677 int narg = -1;
678 arg args[MAXARGS];
679 int state = IN_TEXT;
680 const char *mark = in;
f375d32b 681 const macro *pmacro = NULL;
bd2f2e55
DB
682 char *expansion = 0;
683 char *result = 0;
684
685 while (*in)
686 {
687 switch (state)
688 {
689 case IN_TEXT:
43e65147
L
690 if (*in == '%' && *(in + 1) && (!first_only || num_expansions == 0))
691 {
91d6fa6a
NC
692 pmacro = lookup_macro (in + 1);
693 if (pmacro)
bd2f2e55
DB
694 {
695 /* printf("entering state %d at '%s'...\n", state, in); */
696 result = str_append (result, mark, in - mark);
697 mark = in;
91d6fa6a 698 in += 1 + strlen (pmacro->name);
bd2f2e55
DB
699 while (*in == ' ') ++in;
700 if (*in != '(')
701 {
43e65147 702 state = IN_TEXT;
91d6fa6a 703 pmacro = NULL;
bd2f2e55
DB
704 }
705 else
706 {
707 state = IN_ARGS;
708 narg = 0;
709 args[narg].start = in + 1;
710 args[narg].len = 0;
43e65147 711 mark = in + 1;
bd2f2e55
DB
712 }
713 }
714 }
715 break;
716 case IN_ARGS:
717 if (depth == 0)
718 {
719 switch (*in)
720 {
721 case ',':
722 narg++;
723 args[narg].start = (in + 1);
724 args[narg].len = 0;
725 break;
726 case ')':
727 state = IN_TEXT;
728 /* printf("entering state %d at '%s'...\n", state, in); */
91d6fa6a 729 if (pmacro)
bd2f2e55
DB
730 {
731 expansion = 0;
91d6fa6a 732 expansion = expand_macro (args, narg, pmacro);
bd2f2e55
DB
733 num_expansions++;
734 if (expansion)
735 {
736 result = str_append (result, expansion, strlen (expansion));
737 free (expansion);
738 }
739 }
740 else
741 {
742 result = str_append (result, mark, in - mark);
743 }
91d6fa6a 744 pmacro = NULL;
bd2f2e55
DB
745 mark = in + 1;
746 break;
747 case '(':
748 depth++;
1a0670f3 749 /* Fall through. */
bd2f2e55
DB
750 default:
751 args[narg].len++;
43e65147 752 break;
bd2f2e55 753 }
43e65147 754 }
bd2f2e55
DB
755 else
756 {
757 if (*in == ')')
758 depth--;
759 if (narg > -1)
760 args[narg].len++;
761 }
bd2f2e55
DB
762 }
763 ++in;
764 }
43e65147 765
bd2f2e55
DB
766 if (mark != in)
767 result = str_append (result, mark, in - mark);
43e65147 768
bd2f2e55
DB
769 return result;
770}
771
772#undef IN_ARGS
773#undef IN_TEXT
774#undef MAXARGS
775
776
777/* END LIGHTWEIGHT MACRO PROCESSOR. */
778
779const char * mep_cgen_parse_operand
780 (CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *);
781
782const char *
783mep_cgen_expand_macros_and_parse_operand (CGEN_CPU_DESC cd, int opindex,
784 const char ** strp_in, CGEN_FIELDS * fields)
785{
786 const char * errmsg = NULL;
787 char *str = 0, *hold = 0;
788 const char **strp = 0;
789
790 /* Set up a new pointer to macro-expanded string. */
791 str = expand_string (*strp_in, 1);
792 /* fprintf (stderr, " expanded <<%s>> to <<%s>>\n", *strp_in, str); */
793
794 hold = str;
795 strp = (const char **)(&str);
796
797 errmsg = mep_cgen_parse_operand (cd, opindex, strp, fields);
798
799 /* Now work out the advance. */
800 if (strlen (str) == 0)
801 *strp_in += strlen (*strp_in);
802
803 else
804 {
805 if (strstr (*strp_in, str))
806 /* A macro-expansion was pulled off the front. */
43e65147 807 *strp_in = strstr (*strp_in, str);
bd2f2e55
DB
808 else
809 /* A non-macro-expansion was pulled off the front. */
43e65147 810 *strp_in += (str - hold);
bd2f2e55
DB
811 }
812
d96bf37b 813 free (hold);
bd2f2e55
DB
814
815 return errmsg;
816}
817
43e65147 818#define CGEN_ASM_INIT_HOOK (cd->parse_operand = mep_cgen_expand_macros_and_parse_operand);
bd2f2e55
DB
819
820/* -- dis.c */
821
822const char * mep_cgen_parse_operand
823 (CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *);
824
825/* Main entry point for operand parsing.
826
827 This function is basically just a big switch statement. Earlier versions
828 used tables to look up the function to use, but
829 - if the table contains both assembler and disassembler functions then
830 the disassembler contains much of the assembler and vice-versa,
831 - there's a lot of inlining possibilities as things grow,
832 - using a switch statement avoids the function call overhead.
833
834 This function could be moved into `parse_insn_normal', but keeping it
835 separate makes clear the interface between `parse_insn_normal' and each of
836 the handlers. */
837
838const char *
839mep_cgen_parse_operand (CGEN_CPU_DESC cd,
840 int opindex,
841 const char ** strp,
842 CGEN_FIELDS * fields)
843{
844 const char * errmsg = NULL;
845 /* Used by scalar operands that still need to be parsed. */
846 long junk ATTRIBUTE_UNUSED;
847
848 switch (opindex)
849 {
850 case MEP_OPERAND_ADDR24A4 :
851 errmsg = parse_mep_alignu (cd, strp, MEP_OPERAND_ADDR24A4, (unsigned long *) (& fields->f_24u8a4n));
852 break;
40493983
DD
853 case MEP_OPERAND_C5RMUIMM20 :
854 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_C5RMUIMM20, (unsigned long *) (& fields->f_c5_rmuimm20));
855 break;
856 case MEP_OPERAND_C5RNMUIMM24 :
857 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_C5RNMUIMM24, (unsigned long *) (& fields->f_c5_rnmuimm24));
858 break;
bd2f2e55
DB
859 case MEP_OPERAND_CALLNUM :
860 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_CALLNUM, (unsigned long *) (& fields->f_callnum));
861 break;
862 case MEP_OPERAND_CCCC :
863 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_CCCC, (unsigned long *) (& fields->f_rm));
864 break;
865 case MEP_OPERAND_CCRN :
866 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr, & fields->f_ccrn);
867 break;
40493983
DD
868 case MEP_OPERAND_CDISP10 :
869 errmsg = parse_cdisp10 (cd, strp, MEP_OPERAND_CDISP10, (long *) (& fields->f_cdisp10));
870 break;
871 case MEP_OPERAND_CDISP10A2 :
872 errmsg = parse_cdisp10 (cd, strp, MEP_OPERAND_CDISP10A2, (long *) (& fields->f_cdisp10));
bd2f2e55 873 break;
40493983
DD
874 case MEP_OPERAND_CDISP10A4 :
875 errmsg = parse_cdisp10 (cd, strp, MEP_OPERAND_CDISP10A4, (long *) (& fields->f_cdisp10));
bd2f2e55 876 break;
40493983
DD
877 case MEP_OPERAND_CDISP10A8 :
878 errmsg = parse_cdisp10 (cd, strp, MEP_OPERAND_CDISP10A8, (long *) (& fields->f_cdisp10));
bd2f2e55 879 break;
40493983
DD
880 case MEP_OPERAND_CDISP12 :
881 errmsg = cgen_parse_signed_integer (cd, strp, MEP_OPERAND_CDISP12, (long *) (& fields->f_12s20));
bd2f2e55
DB
882 break;
883 case MEP_OPERAND_CIMM4 :
884 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_CIMM4, (unsigned long *) (& fields->f_rn));
885 break;
886 case MEP_OPERAND_CIMM5 :
887 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_CIMM5, (unsigned long *) (& fields->f_5u24));
888 break;
889 case MEP_OPERAND_CODE16 :
890 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_CODE16, (unsigned long *) (& fields->f_16u16));
891 break;
892 case MEP_OPERAND_CODE24 :
893 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_CODE24, (unsigned long *) (& fields->f_24u4n));
894 break;
895 case MEP_OPERAND_CP_FLAG :
896 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr, & junk);
897 break;
898 case MEP_OPERAND_CRN :
899 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr, & fields->f_crn);
900 break;
901 case MEP_OPERAND_CRN64 :
902 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr64, & fields->f_crn);
903 break;
904 case MEP_OPERAND_CRNX :
905 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr, & fields->f_crnx);
906 break;
907 case MEP_OPERAND_CRNX64 :
908 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr64, & fields->f_crnx);
909 break;
3526b680
DD
910 case MEP_OPERAND_CROC :
911 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr64, & fields->f_ivc2_5u7);
912 break;
913 case MEP_OPERAND_CROP :
914 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr64, & fields->f_ivc2_5u23);
915 break;
916 case MEP_OPERAND_CRPC :
917 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr64, & fields->f_ivc2_5u26);
918 break;
919 case MEP_OPERAND_CRPP :
920 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr64, & fields->f_ivc2_5u18);
921 break;
922 case MEP_OPERAND_CRQC :
923 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr64, & fields->f_ivc2_5u21);
924 break;
925 case MEP_OPERAND_CRQP :
926 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr64, & fields->f_ivc2_5u13);
927 break;
bd2f2e55
DB
928 case MEP_OPERAND_CSRN :
929 errmsg = parse_csrn (cd, strp, & mep_cgen_opval_h_csr, & fields->f_csrn);
930 break;
931 case MEP_OPERAND_CSRN_IDX :
932 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_CSRN_IDX, (unsigned long *) (& fields->f_csrn));
933 break;
934 case MEP_OPERAND_DBG :
935 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
936 break;
937 case MEP_OPERAND_DEPC :
938 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
939 break;
940 case MEP_OPERAND_EPC :
941 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
942 break;
943 case MEP_OPERAND_EXC :
944 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
945 break;
bd2f2e55
DB
946 case MEP_OPERAND_HI :
947 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
948 break;
3526b680 949 case MEP_OPERAND_IMM16P0 :
d285268e 950 errmsg = parse_unsigned16_range (cd, strp, MEP_OPERAND_IMM16P0, (unsigned long *) (& fields->f_ivc2_imm16p0));
3526b680
DD
951 break;
952 case MEP_OPERAND_IMM3P12 :
953 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM3P12, (unsigned long *) (& fields->f_ivc2_3u12));
954 break;
955 case MEP_OPERAND_IMM3P25 :
956 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM3P25, (unsigned long *) (& fields->f_ivc2_3u25));
957 break;
958 case MEP_OPERAND_IMM3P4 :
959 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM3P4, (unsigned long *) (& fields->f_ivc2_3u4));
960 break;
961 case MEP_OPERAND_IMM3P5 :
962 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM3P5, (unsigned long *) (& fields->f_ivc2_3u5));
963 break;
964 case MEP_OPERAND_IMM3P9 :
965 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM3P9, (unsigned long *) (& fields->f_ivc2_3u9));
966 break;
967 case MEP_OPERAND_IMM4P10 :
968 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM4P10, (unsigned long *) (& fields->f_ivc2_4u10));
969 break;
970 case MEP_OPERAND_IMM4P4 :
971 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM4P4, (unsigned long *) (& fields->f_ivc2_4u4));
972 break;
973 case MEP_OPERAND_IMM4P8 :
974 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM4P8, (unsigned long *) (& fields->f_ivc2_4u8));
975 break;
976 case MEP_OPERAND_IMM5P23 :
977 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM5P23, (unsigned long *) (& fields->f_ivc2_5u23));
978 break;
979 case MEP_OPERAND_IMM5P3 :
980 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM5P3, (unsigned long *) (& fields->f_ivc2_5u3));
981 break;
982 case MEP_OPERAND_IMM5P7 :
983 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM5P7, (unsigned long *) (& fields->f_ivc2_5u7));
984 break;
985 case MEP_OPERAND_IMM5P8 :
986 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM5P8, (unsigned long *) (& fields->f_ivc2_5u8));
987 break;
988 case MEP_OPERAND_IMM6P2 :
989 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM6P2, (unsigned long *) (& fields->f_ivc2_6u2));
990 break;
991 case MEP_OPERAND_IMM6P6 :
992 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM6P6, (unsigned long *) (& fields->f_ivc2_6u6));
993 break;
994 case MEP_OPERAND_IMM8P0 :
995 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM8P0, (unsigned long *) (& fields->f_ivc2_8u0));
996 break;
997 case MEP_OPERAND_IMM8P20 :
998 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM8P20, (unsigned long *) (& fields->f_ivc2_8u20));
999 break;
1000 case MEP_OPERAND_IMM8P4 :
1001 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM8P4, (unsigned long *) (& fields->f_ivc2_8u4));
1002 break;
1003 case MEP_OPERAND_IVC_X_0_2 :
1004 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IVC_X_0_2, (unsigned long *) (& fields->f_ivc2_2u0));
1005 break;
1006 case MEP_OPERAND_IVC_X_0_3 :
1007 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IVC_X_0_3, (unsigned long *) (& fields->f_ivc2_3u0));
1008 break;
1009 case MEP_OPERAND_IVC_X_0_4 :
1010 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IVC_X_0_4, (unsigned long *) (& fields->f_ivc2_4u0));
1011 break;
1012 case MEP_OPERAND_IVC_X_0_5 :
1013 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IVC_X_0_5, (unsigned long *) (& fields->f_ivc2_5u0));
1014 break;
1015 case MEP_OPERAND_IVC_X_6_1 :
1016 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IVC_X_6_1, (unsigned long *) (& fields->f_ivc2_1u6));
1017 break;
1018 case MEP_OPERAND_IVC_X_6_2 :
1019 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IVC_X_6_2, (unsigned long *) (& fields->f_ivc2_2u6));
1020 break;
1021 case MEP_OPERAND_IVC_X_6_3 :
1022 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IVC_X_6_3, (unsigned long *) (& fields->f_ivc2_3u6));
1023 break;
dab97f24
DD
1024 case MEP_OPERAND_IVC2_ACC0_0 :
1025 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1026 break;
1027 case MEP_OPERAND_IVC2_ACC0_1 :
1028 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1029 break;
1030 case MEP_OPERAND_IVC2_ACC0_2 :
1031 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1032 break;
1033 case MEP_OPERAND_IVC2_ACC0_3 :
1034 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1035 break;
1036 case MEP_OPERAND_IVC2_ACC0_4 :
1037 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1038 break;
1039 case MEP_OPERAND_IVC2_ACC0_5 :
1040 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1041 break;
1042 case MEP_OPERAND_IVC2_ACC0_6 :
1043 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1044 break;
1045 case MEP_OPERAND_IVC2_ACC0_7 :
1046 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1047 break;
1048 case MEP_OPERAND_IVC2_ACC1_0 :
1049 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1050 break;
1051 case MEP_OPERAND_IVC2_ACC1_1 :
1052 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1053 break;
1054 case MEP_OPERAND_IVC2_ACC1_2 :
1055 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1056 break;
1057 case MEP_OPERAND_IVC2_ACC1_3 :
1058 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1059 break;
1060 case MEP_OPERAND_IVC2_ACC1_4 :
1061 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1062 break;
1063 case MEP_OPERAND_IVC2_ACC1_5 :
1064 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1065 break;
1066 case MEP_OPERAND_IVC2_ACC1_6 :
1067 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1068 break;
1069 case MEP_OPERAND_IVC2_ACC1_7 :
1070 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1071 break;
1072 case MEP_OPERAND_IVC2_CC :
1073 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1074 break;
1075 case MEP_OPERAND_IVC2_COFA0 :
1076 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1077 break;
1078 case MEP_OPERAND_IVC2_COFA1 :
1079 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1080 break;
1081 case MEP_OPERAND_IVC2_COFR0 :
1082 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1083 break;
1084 case MEP_OPERAND_IVC2_COFR1 :
1085 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1086 break;
1087 case MEP_OPERAND_IVC2_CSAR0 :
1088 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1089 break;
1090 case MEP_OPERAND_IVC2_CSAR1 :
1091 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1092 break;
1d74713b 1093 case MEP_OPERAND_IVC2C3CCRN :
2f3565a3 1094 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & fields->f_ivc2_ccrn_c3);
1d74713b 1095 break;
3526b680 1096 case MEP_OPERAND_IVC2CCRN :
1d74713b 1097 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & fields->f_ivc2_ccrn);
3526b680
DD
1098 break;
1099 case MEP_OPERAND_IVC2CRN :
1100 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr64, & fields->f_ivc2_crnx);
1101 break;
1102 case MEP_OPERAND_IVC2RM :
1103 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_ivc2_crm);
1104 break;
bd2f2e55
DB
1105 case MEP_OPERAND_LO :
1106 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
1107 break;
1108 case MEP_OPERAND_LP :
1109 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
1110 break;
1111 case MEP_OPERAND_MB0 :
1112 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
1113 break;
1114 case MEP_OPERAND_MB1 :
1115 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
1116 break;
1117 case MEP_OPERAND_ME0 :
1118 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
1119 break;
1120 case MEP_OPERAND_ME1 :
1121 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
1122 break;
1123 case MEP_OPERAND_NPC :
1124 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
1125 break;
1126 case MEP_OPERAND_OPT :
1127 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
1128 break;
1129 case MEP_OPERAND_PCABS24A2 :
1130 errmsg = parse_mep_alignu (cd, strp, MEP_OPERAND_PCABS24A2, (unsigned long *) (& fields->f_24u5a2n));
1131 break;
1132 case MEP_OPERAND_PCREL12A2 :
1133 errmsg = parse_mep_align (cd, strp, MEP_OPERAND_PCREL12A2, (long *) (& fields->f_12s4a2));
1134 break;
1135 case MEP_OPERAND_PCREL17A2 :
1136 errmsg = parse_mep_align (cd, strp, MEP_OPERAND_PCREL17A2, (long *) (& fields->f_17s16a2));
1137 break;
1138 case MEP_OPERAND_PCREL24A2 :
1139 errmsg = parse_mep_align (cd, strp, MEP_OPERAND_PCREL24A2, (long *) (& fields->f_24s5a2n));
1140 break;
1141 case MEP_OPERAND_PCREL8A2 :
1142 errmsg = parse_mep_align (cd, strp, MEP_OPERAND_PCREL8A2, (long *) (& fields->f_8s8a2));
1143 break;
1144 case MEP_OPERAND_PSW :
1145 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
1146 break;
1147 case MEP_OPERAND_R0 :
1148 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & junk);
1149 break;
1150 case MEP_OPERAND_R1 :
1151 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & junk);
1152 break;
1153 case MEP_OPERAND_RL :
1154 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rl);
1155 break;
40493983
DD
1156 case MEP_OPERAND_RL5 :
1157 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rl5);
1158 break;
bd2f2e55
DB
1159 case MEP_OPERAND_RM :
1160 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rm);
1161 break;
1162 case MEP_OPERAND_RMA :
1163 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rm);
1164 break;
1165 case MEP_OPERAND_RN :
1166 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn);
1167 break;
1168 case MEP_OPERAND_RN3 :
1169 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn3);
1170 break;
1171 case MEP_OPERAND_RN3C :
1172 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn3);
1173 break;
1174 case MEP_OPERAND_RN3L :
1175 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn3);
1176 break;
1177 case MEP_OPERAND_RN3S :
1178 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn3);
1179 break;
1180 case MEP_OPERAND_RN3UC :
1181 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn3);
1182 break;
1183 case MEP_OPERAND_RN3UL :
1184 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn3);
1185 break;
1186 case MEP_OPERAND_RN3US :
1187 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn3);
1188 break;
1189 case MEP_OPERAND_RNC :
1190 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn);
1191 break;
1192 case MEP_OPERAND_RNL :
1193 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn);
1194 break;
1195 case MEP_OPERAND_RNS :
1196 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn);
1197 break;
1198 case MEP_OPERAND_RNUC :
1199 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn);
1200 break;
1201 case MEP_OPERAND_RNUL :
1202 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn);
1203 break;
1204 case MEP_OPERAND_RNUS :
1205 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn);
1206 break;
1207 case MEP_OPERAND_SAR :
1208 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
1209 break;
1210 case MEP_OPERAND_SDISP16 :
1211 errmsg = parse_signed16 (cd, strp, MEP_OPERAND_SDISP16, (long *) (& fields->f_16s16));
1212 break;
1213 case MEP_OPERAND_SIMM16 :
1214 errmsg = parse_signed16 (cd, strp, MEP_OPERAND_SIMM16, (long *) (& fields->f_16s16));
1215 break;
3526b680 1216 case MEP_OPERAND_SIMM16P0 :
d285268e 1217 errmsg = parse_signed16_range (cd, strp, MEP_OPERAND_SIMM16P0, (long *) (& fields->f_ivc2_simm16p0));
3526b680 1218 break;
bd2f2e55
DB
1219 case MEP_OPERAND_SIMM6 :
1220 errmsg = cgen_parse_signed_integer (cd, strp, MEP_OPERAND_SIMM6, (long *) (& fields->f_6s8));
1221 break;
1222 case MEP_OPERAND_SIMM8 :
1223 errmsg = cgen_parse_signed_integer (cd, strp, MEP_OPERAND_SIMM8, (long *) (& fields->f_8s8));
1224 break;
3526b680
DD
1225 case MEP_OPERAND_SIMM8P0 :
1226 errmsg = cgen_parse_signed_integer (cd, strp, MEP_OPERAND_SIMM8P0, (long *) (& fields->f_ivc2_8s0));
1227 break;
1d74713b
DD
1228 case MEP_OPERAND_SIMM8P20 :
1229 errmsg = cgen_parse_signed_integer (cd, strp, MEP_OPERAND_SIMM8P20, (long *) (& fields->f_ivc2_8s20));
1230 break;
3526b680
DD
1231 case MEP_OPERAND_SIMM8P4 :
1232 errmsg = cgen_parse_signed_integer (cd, strp, MEP_OPERAND_SIMM8P4, (long *) (& fields->f_ivc2_8s4));
1233 break;
bd2f2e55
DB
1234 case MEP_OPERAND_SP :
1235 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & junk);
1236 break;
1237 case MEP_OPERAND_SPR :
1238 errmsg = parse_spreg (cd, strp, & mep_cgen_opval_h_gpr, & junk);
1239 break;
1240 case MEP_OPERAND_TP :
1241 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & junk);
1242 break;
1243 case MEP_OPERAND_TPR :
1244 errmsg = parse_tpreg (cd, strp, & mep_cgen_opval_h_gpr, & junk);
1245 break;
1246 case MEP_OPERAND_UDISP2 :
1247 errmsg = cgen_parse_signed_integer (cd, strp, MEP_OPERAND_UDISP2, (long *) (& fields->f_2u6));
1248 break;
1249 case MEP_OPERAND_UDISP7 :
1250 errmsg = parse_unsigned7 (cd, strp, MEP_OPERAND_UDISP7, (unsigned long *) (& fields->f_7u9));
1251 break;
1252 case MEP_OPERAND_UDISP7A2 :
1253 errmsg = parse_unsigned7 (cd, strp, MEP_OPERAND_UDISP7A2, (unsigned long *) (& fields->f_7u9a2));
1254 break;
1255 case MEP_OPERAND_UDISP7A4 :
1256 errmsg = parse_unsigned7 (cd, strp, MEP_OPERAND_UDISP7A4, (unsigned long *) (& fields->f_7u9a4));
1257 break;
1258 case MEP_OPERAND_UIMM16 :
1259 errmsg = parse_unsigned16 (cd, strp, MEP_OPERAND_UIMM16, (unsigned long *) (& fields->f_16u16));
1260 break;
1261 case MEP_OPERAND_UIMM2 :
1262 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_UIMM2, (unsigned long *) (& fields->f_2u10));
1263 break;
1264 case MEP_OPERAND_UIMM24 :
1265 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_UIMM24, (unsigned long *) (& fields->f_24u8n));
1266 break;
1267 case MEP_OPERAND_UIMM3 :
1268 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_UIMM3, (unsigned long *) (& fields->f_3u5));
1269 break;
1270 case MEP_OPERAND_UIMM4 :
1271 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_UIMM4, (unsigned long *) (& fields->f_4u8));
1272 break;
1273 case MEP_OPERAND_UIMM5 :
1274 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_UIMM5, (unsigned long *) (& fields->f_5u8));
1275 break;
1276 case MEP_OPERAND_UIMM7A4 :
1277 errmsg = parse_mep_alignu (cd, strp, MEP_OPERAND_UIMM7A4, (unsigned long *) (& fields->f_7u9a4));
1278 break;
1279 case MEP_OPERAND_ZERO :
1280 errmsg = parse_zero (cd, strp, MEP_OPERAND_ZERO, (long *) (& junk));
1281 break;
1282
1283 default :
1284 /* xgettext:c-format */
a6743a54
AM
1285 opcodes_error_handler
1286 (_("internal error: unrecognized field %d while parsing"),
1287 opindex);
bd2f2e55
DB
1288 abort ();
1289 }
1290
1291 return errmsg;
1292}
1293
43e65147 1294cgen_parse_fn * const mep_cgen_parse_handlers[] =
bd2f2e55
DB
1295{
1296 parse_insn_normal,
1297};
1298
1299void
1300mep_cgen_init_asm (CGEN_CPU_DESC cd)
1301{
1302 mep_cgen_init_opcode_table (cd);
1303 mep_cgen_init_ibld_table (cd);
1304 cd->parse_handlers = & mep_cgen_parse_handlers[0];
1305 cd->parse_operand = mep_cgen_parse_operand;
1306#ifdef CGEN_ASM_INIT_HOOK
1307CGEN_ASM_INIT_HOOK
1308#endif
1309}
1310
1311\f
1312
1313/* Regex construction routine.
1314
1315 This translates an opcode syntax string into a regex string,
1316 by replacing any non-character syntax element (such as an
1317 opcode) with the pattern '.*'
1318
1319 It then compiles the regex and stores it in the opcode, for
1320 later use by mep_cgen_assemble_insn
1321
1322 Returns NULL for success, an error message for failure. */
1323
43e65147 1324char *
bd2f2e55 1325mep_cgen_build_insn_regex (CGEN_INSN *insn)
43e65147 1326{
bd2f2e55
DB
1327 CGEN_OPCODE *opc = (CGEN_OPCODE *) CGEN_INSN_OPCODE (insn);
1328 const char *mnem = CGEN_INSN_MNEMONIC (insn);
1329 char rxbuf[CGEN_MAX_RX_ELEMENTS];
1330 char *rx = rxbuf;
1331 const CGEN_SYNTAX_CHAR_TYPE *syn;
1332 int reg_err;
1333
1334 syn = CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc));
1335
1336 /* Mnemonics come first in the syntax string. */
1337 if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
1338 return _("missing mnemonic in syntax string");
1339 ++syn;
1340
1341 /* Generate a case sensitive regular expression that emulates case
1342 insensitive matching in the "C" locale. We cannot generate a case
1343 insensitive regular expression because in Turkish locales, 'i' and 'I'
1344 are not equal modulo case conversion. */
1345
1346 /* Copy the literal mnemonic out of the insn. */
1347 for (; *mnem; mnem++)
1348 {
1349 char c = *mnem;
1350
1351 if (ISALPHA (c))
1352 {
1353 *rx++ = '[';
1354 *rx++ = TOLOWER (c);
1355 *rx++ = TOUPPER (c);
1356 *rx++ = ']';
1357 }
1358 else
1359 *rx++ = c;
1360 }
1361
1362 /* Copy any remaining literals from the syntax string into the rx. */
1363 for(; * syn != 0 && rx <= rxbuf + (CGEN_MAX_RX_ELEMENTS - 7 - 4); ++syn)
1364 {
43e65147 1365 if (CGEN_SYNTAX_CHAR_P (* syn))
bd2f2e55
DB
1366 {
1367 char c = CGEN_SYNTAX_CHAR (* syn);
1368
43e65147 1369 switch (c)
bd2f2e55
DB
1370 {
1371 /* Escape any regex metacharacters in the syntax. */
43e65147
L
1372 case '.': case '[': case '\\':
1373 case '*': case '^': case '$':
bd2f2e55
DB
1374
1375#ifdef CGEN_ESCAPE_EXTENDED_REGEX
43e65147 1376 case '?': case '{': case '}':
bd2f2e55
DB
1377 case '(': case ')': case '*':
1378 case '|': case '+': case ']':
1379#endif
1380 *rx++ = '\\';
1381 *rx++ = c;
1382 break;
1383
1384 default:
1385 if (ISALPHA (c))
1386 {
1387 *rx++ = '[';
1388 *rx++ = TOLOWER (c);
1389 *rx++ = TOUPPER (c);
1390 *rx++ = ']';
1391 }
1392 else
1393 *rx++ = c;
1394 break;
1395 }
1396 }
1397 else
1398 {
1399 /* Replace non-syntax fields with globs. */
1400 *rx++ = '.';
1401 *rx++ = '*';
1402 }
1403 }
1404
1405 /* Trailing whitespace ok. */
43e65147
L
1406 * rx++ = '[';
1407 * rx++ = ' ';
1408 * rx++ = '\t';
1409 * rx++ = ']';
1410 * rx++ = '*';
bd2f2e55
DB
1411
1412 /* But anchor it after that. */
43e65147 1413 * rx++ = '$';
bd2f2e55
DB
1414 * rx = '\0';
1415
1416 CGEN_INSN_RX (insn) = xmalloc (sizeof (regex_t));
1417 reg_err = regcomp ((regex_t *) CGEN_INSN_RX (insn), rxbuf, REG_NOSUB);
1418
43e65147 1419 if (reg_err == 0)
bd2f2e55
DB
1420 return NULL;
1421 else
1422 {
1423 static char msg[80];
1424
1425 regerror (reg_err, (regex_t *) CGEN_INSN_RX (insn), msg, 80);
1426 regfree ((regex_t *) CGEN_INSN_RX (insn));
1427 free (CGEN_INSN_RX (insn));
1428 (CGEN_INSN_RX (insn)) = NULL;
1429 return msg;
1430 }
1431}
1432
1433\f
1434/* Default insn parser.
1435
1436 The syntax string is scanned and operands are parsed and stored in FIELDS.
1437 Relocs are queued as we go via other callbacks.
1438
1439 ??? Note that this is currently an all-or-nothing parser. If we fail to
1440 parse the instruction, we return 0 and the caller will start over from
1441 the beginning. Backtracking will be necessary in parsing subexpressions,
1442 but that can be handled there. Not handling backtracking here may get
1443 expensive in the case of the m68k. Deal with later.
1444
1445 Returns NULL for success, an error message for failure. */
1446
1447static const char *
1448parse_insn_normal (CGEN_CPU_DESC cd,
1449 const CGEN_INSN *insn,
1450 const char **strp,
1451 CGEN_FIELDS *fields)
1452{
1453 /* ??? Runtime added insns not handled yet. */
1454 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
1455 const char *str = *strp;
1456 const char *errmsg;
1457 const char *p;
1458 const CGEN_SYNTAX_CHAR_TYPE * syn;
1459#ifdef CGEN_MNEMONIC_OPERANDS
1460 /* FIXME: wip */
1461 int past_opcode_p;
1462#endif
1463
1464 /* For now we assume the mnemonic is first (there are no leading operands).
1465 We can parse it without needing to set up operand parsing.
1466 GAS's input scrubber will ensure mnemonics are lowercase, but we may
1467 not be called from GAS. */
1468 p = CGEN_INSN_MNEMONIC (insn);
1469 while (*p && TOLOWER (*p) == TOLOWER (*str))
1470 ++p, ++str;
1471
1472 if (* p)
1473 return _("unrecognized instruction");
1474
1475#ifndef CGEN_MNEMONIC_OPERANDS
1476 if (* str && ! ISSPACE (* str))
1477 return _("unrecognized instruction");
1478#endif
1479
1480 CGEN_INIT_PARSE (cd);
1481 cgen_init_parse_operand (cd);
1482#ifdef CGEN_MNEMONIC_OPERANDS
1483 past_opcode_p = 0;
1484#endif
1485
1486 /* We don't check for (*str != '\0') here because we want to parse
1487 any trailing fake arguments in the syntax string. */
1488 syn = CGEN_SYNTAX_STRING (syntax);
1489
1490 /* Mnemonics come first for now, ensure valid string. */
1491 if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
1492 abort ();
1493
1494 ++syn;
1495
1496 while (* syn != 0)
1497 {
1498 /* Non operand chars must match exactly. */
1499 if (CGEN_SYNTAX_CHAR_P (* syn))
1500 {
1501 /* FIXME: While we allow for non-GAS callers above, we assume the
1502 first char after the mnemonic part is a space. */
1503 /* FIXME: We also take inappropriate advantage of the fact that
1504 GAS's input scrubber will remove extraneous blanks. */
1505 if (TOLOWER (*str) == TOLOWER (CGEN_SYNTAX_CHAR (* syn)))
1506 {
1507#ifdef CGEN_MNEMONIC_OPERANDS
1508 if (CGEN_SYNTAX_CHAR(* syn) == ' ')
1509 past_opcode_p = 1;
1510#endif
1511 ++ syn;
1512 ++ str;
1513 }
1514 else if (*str)
1515 {
1516 /* Syntax char didn't match. Can't be this insn. */
1517 static char msg [80];
1518
1519 /* xgettext:c-format */
1520 sprintf (msg, _("syntax error (expected char `%c', found `%c')"),
1521 CGEN_SYNTAX_CHAR(*syn), *str);
1522 return msg;
1523 }
1524 else
1525 {
1526 /* Ran out of input. */
1527 static char msg [80];
1528
1529 /* xgettext:c-format */
1530 sprintf (msg, _("syntax error (expected char `%c', found end of instruction)"),
1531 CGEN_SYNTAX_CHAR(*syn));
1532 return msg;
1533 }
1534 continue;
1535 }
1536
c7e2358a
AM
1537#ifdef CGEN_MNEMONIC_OPERANDS
1538 (void) past_opcode_p;
1539#endif
bd2f2e55 1540 /* We have an operand of some sort. */
c7e2358a 1541 errmsg = cd->parse_operand (cd, CGEN_SYNTAX_FIELD (*syn), &str, fields);
bd2f2e55
DB
1542 if (errmsg)
1543 return errmsg;
1544
1545 /* Done with this operand, continue with next one. */
1546 ++ syn;
1547 }
1548
1549 /* If we're at the end of the syntax string, we're done. */
1550 if (* syn == 0)
1551 {
1552 /* FIXME: For the moment we assume a valid `str' can only contain
1553 blanks now. IE: We needn't try again with a longer version of
1554 the insn and it is assumed that longer versions of insns appear
1555 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
1556 while (ISSPACE (* str))
1557 ++ str;
1558
1559 if (* str != '\0')
1560 return _("junk at end of line"); /* FIXME: would like to include `str' */
1561
1562 return NULL;
1563 }
1564
1565 /* We couldn't parse it. */
1566 return _("unrecognized instruction");
1567}
1568\f
1569/* Main entry point.
1570 This routine is called for each instruction to be assembled.
1571 STR points to the insn to be assembled.
1572 We assume all necessary tables have been initialized.
1573 The assembled instruction, less any fixups, is stored in BUF.
1574 Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
1575 still needs to be converted to target byte order, otherwise BUF is an array
1576 of bytes in target byte order.
1577 The result is a pointer to the insn's entry in the opcode table,
1578 or NULL if an error occured (an error message will have already been
1579 printed).
1580
1581 Note that when processing (non-alias) macro-insns,
1582 this function recurses.
1583
1584 ??? It's possible to make this cpu-independent.
1585 One would have to deal with a few minor things.
1586 At this point in time doing so would be more of a curiosity than useful
1587 [for example this file isn't _that_ big], but keeping the possibility in
1588 mind helps keep the design clean. */
1589
1590const CGEN_INSN *
1591mep_cgen_assemble_insn (CGEN_CPU_DESC cd,
1592 const char *str,
1593 CGEN_FIELDS *fields,
1594 CGEN_INSN_BYTES_PTR buf,
1595 char **errmsg)
1596{
1597 const char *start;
1598 CGEN_INSN_LIST *ilist;
1599 const char *parse_errmsg = NULL;
1600 const char *insert_errmsg = NULL;
1601 int recognized_mnemonic = 0;
1602
1603 /* Skip leading white space. */
1604 while (ISSPACE (* str))
1605 ++ str;
1606
1607 /* The instructions are stored in hashed lists.
1608 Get the first in the list. */
1609 ilist = CGEN_ASM_LOOKUP_INSN (cd, str);
1610
1611 /* Keep looking until we find a match. */
1612 start = str;
1613 for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist))
1614 {
1615 const CGEN_INSN *insn = ilist->insn;
1616 recognized_mnemonic = 1;
1617
43e65147 1618#ifdef CGEN_VALIDATE_INSN_SUPPORTED
bd2f2e55
DB
1619 /* Not usually needed as unsupported opcodes
1620 shouldn't be in the hash lists. */
1621 /* Is this insn supported by the selected cpu? */
1622 if (! mep_cgen_insn_supported (cd, insn))
1623 continue;
1624#endif
1625 /* If the RELAXED attribute is set, this is an insn that shouldn't be
1626 chosen immediately. Instead, it is used during assembler/linker
1627 relaxation if possible. */
1628 if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXED) != 0)
1629 continue;
1630
1631 str = start;
1632
1633 /* Skip this insn if str doesn't look right lexically. */
1634 if (CGEN_INSN_RX (insn) != NULL &&
1635 regexec ((regex_t *) CGEN_INSN_RX (insn), str, 0, NULL, 0) == REG_NOMATCH)
1636 continue;
1637
1638 /* Allow parse/insert handlers to obtain length of insn. */
1639 CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
1640
1641 parse_errmsg = CGEN_PARSE_FN (cd, insn) (cd, insn, & str, fields);
1642 if (parse_errmsg != NULL)
1643 continue;
1644
1645 /* ??? 0 is passed for `pc'. */
1646 insert_errmsg = CGEN_INSERT_FN (cd, insn) (cd, insn, fields, buf,
1647 (bfd_vma) 0);
1648 if (insert_errmsg != NULL)
1649 continue;
1650
1651 /* It is up to the caller to actually output the insn and any
1652 queued relocs. */
1653 return insn;
1654 }
1655
1656 {
1657 static char errbuf[150];
bd2f2e55 1658 const char *tmp_errmsg;
c7e2358a
AM
1659#ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
1660#define be_verbose 1
bd2f2e55 1661#else
c7e2358a 1662#define be_verbose 0
bd2f2e55 1663#endif
c7e2358a
AM
1664
1665 if (be_verbose)
1666 {
1667 /* If requesting verbose error messages, use insert_errmsg.
1668 Failing that, use parse_errmsg. */
1669 tmp_errmsg = (insert_errmsg ? insert_errmsg :
1670 parse_errmsg ? parse_errmsg :
1671 recognized_mnemonic ?
1672 _("unrecognized form of instruction") :
1673 _("unrecognized instruction"));
1674
1675 if (strlen (start) > 50)
1676 /* xgettext:c-format */
1677 sprintf (errbuf, "%s `%.50s...'", tmp_errmsg, start);
43e65147 1678 else
c7e2358a
AM
1679 /* xgettext:c-format */
1680 sprintf (errbuf, "%s `%.50s'", tmp_errmsg, start);
1681 }
1682 else
1683 {
1684 if (strlen (start) > 50)
1685 /* xgettext:c-format */
1686 sprintf (errbuf, _("bad instruction `%.50s...'"), start);
43e65147 1687 else
c7e2358a
AM
1688 /* xgettext:c-format */
1689 sprintf (errbuf, _("bad instruction `%.50s'"), start);
1690 }
43e65147 1691
bd2f2e55
DB
1692 *errmsg = errbuf;
1693 return NULL;
1694 }
1695}