1 /* Assembler interface for targets using CGEN. -*- C -*-
2 CGEN: Cpu tools GENerator
3
4 THIS FILE IS MACHINE GENERATED WITH CGEN.
5 - the resultant file is machine generated, cgen-asm.in isn't
6
7 Copyright (C) 1996-2016 Free Software Foundation, Inc.
8
9 This file is part of libopcodes.
10
11 This library is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3, or (at your option)
14 any later version.
15
16 It is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
19 License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
24
25
26 /* ??? Eventually more and more of this stuff can go to cpu-independent files.
27 Keep that in mind. */
28
29 #include "sysdep.h"
30 #include <stdio.h>
31 #include "ansidecl.h"
32 #include "bfd.h"
33 #include "symcat.h"
34 #include "mep-desc.h"
35 #include "mep-opc.h"
36 #include "opintl.h"
37 #include "xregex.h"
38 #include "libiberty.h"
39 #include "safe-ctype.h"
40
41 #undef min
42 #define min(a,b) ((a) < (b) ? (a) : (b))
43 #undef max
44 #define max(a,b) ((a) > (b) ? (a) : (b))
45
46 static const char * parse_insn_normal
47 (CGEN_CPU_DESC, const CGEN_INSN *, const char **, CGEN_FIELDS *);
48
49 /* -- assembler routines inserted here. */
50
51 /* -- asm.c */
52
53 #include "elf/mep.h"
54
55 #define CGEN_VALIDATE_INSN_SUPPORTED
56 #define mep_cgen_insn_supported mep_cgen_insn_supported_asm
57
58 const char * parse_csrn (CGEN_CPU_DESC, const char **, CGEN_KEYWORD *, long *);
59 const char * parse_tpreg (CGEN_CPU_DESC, const char **, CGEN_KEYWORD *, long *);
60 const char * parse_spreg (CGEN_CPU_DESC, const char **, CGEN_KEYWORD *, long *);
61 const char * parse_mep_align (CGEN_CPU_DESC, const char **, enum cgen_operand_type, long *);
62 const char * parse_mep_alignu (CGEN_CPU_DESC, const char **, enum cgen_operand_type, unsigned long *);
63 static const char * parse_signed16 (CGEN_CPU_DESC, const char **, int, long *);
64 static const char * parse_signed16_range (CGEN_CPU_DESC, const char **, int, long *) ATTRIBUTE_UNUSED;
65 static const char * parse_unsigned16 (CGEN_CPU_DESC, const char **, int, unsigned long *);
66 static const char * parse_unsigned16_range (CGEN_CPU_DESC, const char **, int, unsigned long *) ATTRIBUTE_UNUSED;
67 static const char * parse_lo16 (CGEN_CPU_DESC, const char **, int, long *, long);
68 static const char * parse_unsigned7 (CGEN_CPU_DESC, const char **, enum cgen_operand_type, unsigned long *);
69 static const char * parse_zero (CGEN_CPU_DESC, const char **, int, long *);
70
71 const char *
parse_csrn(CGEN_CPU_DESC cd,const char ** strp,CGEN_KEYWORD * keyword_table,long * field)72 parse_csrn (CGEN_CPU_DESC cd, const char **strp,
73 CGEN_KEYWORD *keyword_table, long *field)
74 {
75 const char *err;
76 unsigned long value;
77
78 err = cgen_parse_keyword (cd, strp, keyword_table, field);
79 if (!err)
80 return NULL;
81
82 err = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_CSRN_IDX, & value);
83 if (err)
84 return err;
85 *field = value;
86 return NULL;
87 }
88
89 /* begin-cop-ip-parse-handlers */
90 static const char *
91 parse_ivc2_cr (CGEN_CPU_DESC,
92 const char **,
93 CGEN_KEYWORD *,
94 long *) ATTRIBUTE_UNUSED;
95 static const char *
parse_ivc2_cr(CGEN_CPU_DESC cd,const char ** strp,CGEN_KEYWORD * keyword_table ATTRIBUTE_UNUSED,long * field)96 parse_ivc2_cr (CGEN_CPU_DESC cd,
97 const char **strp,
98 CGEN_KEYWORD *keyword_table ATTRIBUTE_UNUSED,
99 long *field)
100 {
101 return cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr_ivc2, field);
102 }
103 static const char *
104 parse_ivc2_ccr (CGEN_CPU_DESC,
105 const char **,
106 CGEN_KEYWORD *,
107 long *) ATTRIBUTE_UNUSED;
108 static const char *
parse_ivc2_ccr(CGEN_CPU_DESC cd,const char ** strp,CGEN_KEYWORD * keyword_table ATTRIBUTE_UNUSED,long * field)109 parse_ivc2_ccr (CGEN_CPU_DESC cd,
110 const char **strp,
111 CGEN_KEYWORD *keyword_table ATTRIBUTE_UNUSED,
112 long *field)
113 {
114 return cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, field);
115 }
116 /* end-cop-ip-parse-handlers */
117
118 const char *
parse_tpreg(CGEN_CPU_DESC cd,const char ** strp,CGEN_KEYWORD * keyword_table,long * field)119 parse_tpreg (CGEN_CPU_DESC cd, const char ** strp,
120 CGEN_KEYWORD *keyword_table, long *field)
121 {
122 const char *err;
123
124 err = cgen_parse_keyword (cd, strp, keyword_table, field);
125 if (err)
126 return err;
127 if (*field != 13)
128 return _("Only $tp or $13 allowed for this opcode");
129 return NULL;
130 }
131
132 const char *
parse_spreg(CGEN_CPU_DESC cd,const char ** strp,CGEN_KEYWORD * keyword_table,long * field)133 parse_spreg (CGEN_CPU_DESC cd, const char ** strp,
134 CGEN_KEYWORD *keyword_table, long *field)
135 {
136 const char *err;
137
138 err = cgen_parse_keyword (cd, strp, keyword_table, field);
139 if (err)
140 return err;
141 if (*field != 15)
142 return _("Only $sp or $15 allowed for this opcode");
143 return NULL;
144 }
145
146 const char *
parse_mep_align(CGEN_CPU_DESC cd,const char ** strp,enum cgen_operand_type type,long * field)147 parse_mep_align (CGEN_CPU_DESC cd, const char ** strp,
148 enum cgen_operand_type type, long *field)
149 {
150 long lsbs = 0;
151 const char *err;
152
153 switch (type)
154 {
155 case MEP_OPERAND_PCREL8A2:
156 case MEP_OPERAND_PCREL12A2:
157 case MEP_OPERAND_PCREL17A2:
158 case MEP_OPERAND_PCREL24A2:
159 err = cgen_parse_signed_integer (cd, strp, type, field);
160 break;
161 case MEP_OPERAND_PCABS24A2:
162 case MEP_OPERAND_UDISP7:
163 case MEP_OPERAND_UDISP7A2:
164 case MEP_OPERAND_UDISP7A4:
165 case MEP_OPERAND_UIMM7A4:
166 case MEP_OPERAND_ADDR24A4:
167 err = cgen_parse_unsigned_integer (cd, strp, type, (unsigned long *) field);
168 break;
169 default:
170 abort();
171 }
172 if (err)
173 return err;
174 switch (type)
175 {
176 case MEP_OPERAND_UDISP7:
177 lsbs = 0;
178 break;
179 case MEP_OPERAND_PCREL8A2:
180 case MEP_OPERAND_PCREL12A2:
181 case MEP_OPERAND_PCREL17A2:
182 case MEP_OPERAND_PCREL24A2:
183 case MEP_OPERAND_PCABS24A2:
184 case MEP_OPERAND_UDISP7A2:
185 lsbs = *field & 1;
186 break;
187 case MEP_OPERAND_UDISP7A4:
188 case MEP_OPERAND_UIMM7A4:
189 case MEP_OPERAND_ADDR24A4:
190 lsbs = *field & 3;
191 break;
192 lsbs = *field & 7;
193 break;
194 default:
195 /* Safe assumption? */
196 abort ();
197 }
198 if (lsbs)
199 return "Value is not aligned enough";
200 return NULL;
201 }
202
203 const char *
parse_mep_alignu(CGEN_CPU_DESC cd,const char ** strp,enum cgen_operand_type type,unsigned long * field)204 parse_mep_alignu (CGEN_CPU_DESC cd, const char ** strp,
205 enum cgen_operand_type type, unsigned long *field)
206 {
207 return parse_mep_align (cd, strp, type, (long *) field);
208 }
209
210
211 /* Handle %lo(), %tpoff(), %sdaoff(), %hi(), and other signed
212 constants in a signed context. */
213
214 static const char *
parse_signed16(CGEN_CPU_DESC cd,const char ** strp,int opindex,long * valuep)215 parse_signed16 (CGEN_CPU_DESC cd,
216 const char **strp,
217 int opindex,
218 long *valuep)
219 {
220 return parse_lo16 (cd, strp, opindex, valuep, 1);
221 }
222
223 static const char *
parse_lo16(CGEN_CPU_DESC cd,const char ** strp,int opindex,long * valuep,long signedp)224 parse_lo16 (CGEN_CPU_DESC cd,
225 const char **strp,
226 int opindex,
227 long *valuep,
228 long signedp)
229 {
230 const char *errmsg;
231 enum cgen_parse_operand_result result_type;
232 bfd_vma value;
233
234 if (strncasecmp (*strp, "%lo(", 4) == 0)
235 {
236 *strp += 4;
237 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_LOW16,
238 & result_type, & value);
239 if (**strp != ')')
240 return _("missing `)'");
241 ++*strp;
242 if (errmsg == NULL
243 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
244 value &= 0xffff;
245 if (signedp)
246 *valuep = (long)(short) value;
247 else
248 *valuep = value;
249 return errmsg;
250 }
251
252 if (strncasecmp (*strp, "%hi(", 4) == 0)
253 {
254 *strp += 4;
255 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_HI16S,
256 & result_type, & value);
257 if (**strp != ')')
258 return _("missing `)'");
259 ++*strp;
260 if (errmsg == NULL
261 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
262 value = (value + 0x8000) >> 16;
263 *valuep = value;
264 return errmsg;
265 }
266
267 if (strncasecmp (*strp, "%uhi(", 5) == 0)
268 {
269 *strp += 5;
270 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_HI16U,
271 & result_type, & value);
272 if (**strp != ')')
273 return _("missing `)'");
274 ++*strp;
275 if (errmsg == NULL
276 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
277 value = value >> 16;
278 *valuep = value;
279 return errmsg;
280 }
281
282 if (strncasecmp (*strp, "%sdaoff(", 8) == 0)
283 {
284 *strp += 8;
285 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_GPREL,
286 NULL, & value);
287 if (**strp != ')')
288 return _("missing `)'");
289 ++*strp;
290 *valuep = value;
291 return errmsg;
292 }
293
294 if (strncasecmp (*strp, "%tpoff(", 7) == 0)
295 {
296 *strp += 7;
297 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_TPREL,
298 NULL, & value);
299 if (**strp != ')')
300 return _("missing `)'");
301 ++*strp;
302 *valuep = value;
303 return errmsg;
304 }
305
306 if (**strp == '%')
307 return _("invalid %function() here");
308
309 return cgen_parse_signed_integer (cd, strp, opindex, valuep);
310 }
311
312 static const char *
parse_unsigned16(CGEN_CPU_DESC cd,const char ** strp,int opindex,unsigned long * valuep)313 parse_unsigned16 (CGEN_CPU_DESC cd,
314 const char **strp,
315 int opindex,
316 unsigned long *valuep)
317 {
318 return parse_lo16 (cd, strp, opindex, (long *) valuep, 0);
319 }
320
321 static const char *
parse_signed16_range(CGEN_CPU_DESC cd,const char ** strp,int opindex,signed long * valuep)322 parse_signed16_range (CGEN_CPU_DESC cd,
323 const char **strp,
324 int opindex,
325 signed long *valuep)
326 {
327 const char *errmsg = 0;
328 signed long value;
329
330 errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value);
331 if (errmsg)
332 return errmsg;
333
334 if (value < -32768 || value > 32767)
335 return _("Immediate is out of range -32768 to 32767");
336
337 *valuep = value;
338 return 0;
339 }
340
341 static const char *
parse_unsigned16_range(CGEN_CPU_DESC cd,const char ** strp,int opindex,unsigned long * valuep)342 parse_unsigned16_range (CGEN_CPU_DESC cd,
343 const char **strp,
344 int opindex,
345 unsigned long *valuep)
346 {
347 const char *errmsg = 0;
348 unsigned long value;
349
350 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, & value);
351 if (errmsg)
352 return errmsg;
353
354 if (value > 65535)
355 return _("Immediate is out of range 0 to 65535");
356
357 *valuep = value;
358 return 0;
359 }
360
361 /* A special case of parse_signed16 which accepts only the value zero. */
362
363 static const char *
parse_zero(CGEN_CPU_DESC cd,const char ** strp,int opindex,long * valuep)364 parse_zero (CGEN_CPU_DESC cd, const char **strp, int opindex, long *valuep)
365 {
366 const char *errmsg;
367 enum cgen_parse_operand_result result_type;
368 bfd_vma value;
369
370 /*fprintf(stderr, "dj: signed parse opindex `%s'\n", *strp);*/
371
372 /* Prevent ($ry) from being attempted as an expression on 'sw $rx,($ry)'.
373 It will fail and cause ry to be listed as an undefined symbol in the
374 listing. */
375 if (strncmp (*strp, "($", 2) == 0)
376 return "not zero"; /* any string will do -- will never be seen. */
377
378 if (strncasecmp (*strp, "%lo(", 4) == 0)
379 {
380 *strp += 4;
381 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_LOW16,
382 &result_type, &value);
383 if (**strp != ')')
384 return "missing `)'";
385 ++*strp;
386 if (errmsg == NULL
387 && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
388 return "not zero"; /* any string will do -- will never be seen. */
389 *valuep = value;
390 return errmsg;
391 }
392
393 if (strncasecmp (*strp, "%hi(", 4) == 0)
394 {
395 *strp += 4;
396 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_HI16S,
397 &result_type, &value);
398 if (**strp != ')')
399 return "missing `)'";
400 ++*strp;
401 if (errmsg == NULL
402 && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
403 return "not zero"; /* any string will do -- will never be seen. */
404 *valuep = value;
405 return errmsg;
406 }
407
408 if (strncasecmp (*strp, "%uhi(", 5) == 0)
409 {
410 *strp += 5;
411 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_HI16U,
412 &result_type, &value);
413 if (**strp != ')')
414 return "missing `)'";
415 ++*strp;
416 if (errmsg == NULL
417 && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
418 return "not zero"; /* any string will do -- will never be seen. */
419 *valuep = value;
420 return errmsg;
421 }
422
423 if (strncasecmp (*strp, "%sdaoff(", 8) == 0)
424 {
425 *strp += 8;
426 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_GPREL,
427 &result_type, &value);
428 if (**strp != ')')
429 return "missing `)'";
430 ++*strp;
431 if (errmsg == NULL
432 && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
433 return "not zero"; /* any string will do -- will never be seen. */
434 *valuep = value;
435 return errmsg;
436 }
437
438 if (strncasecmp (*strp, "%tpoff(", 7) == 0)
439 {
440 *strp += 7;
441 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_TPREL,
442 &result_type, &value);
443 if (**strp != ')')
444 return "missing `)'";
445 ++*strp;
446 if (errmsg == NULL
447 && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
448 return "not zero"; /* any string will do -- will never be seen. */
449 *valuep = value;
450 return errmsg;
451 }
452
453 if (**strp == '%')
454 return "invalid %function() here";
455
456 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_NONE,
457 &result_type, &value);
458 if (errmsg == NULL
459 && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
460 return "not zero"; /* any string will do -- will never be seen. */
461
462 return errmsg;
463 }
464
465 static const char *
parse_unsigned7(CGEN_CPU_DESC cd,const char ** strp,enum cgen_operand_type opindex,unsigned long * valuep)466 parse_unsigned7 (CGEN_CPU_DESC cd, const char **strp,
467 enum cgen_operand_type opindex, unsigned long *valuep)
468 {
469 const char *errmsg;
470 bfd_vma value;
471
472 /* fprintf(stderr, "dj: unsigned7 parse `%s'\n", *strp); */
473
474 if (strncasecmp (*strp, "%tpoff(", 7) == 0)
475 {
476 int reloc;
477 *strp += 7;
478 switch (opindex)
479 {
480 case MEP_OPERAND_UDISP7:
481 reloc = BFD_RELOC_MEP_TPREL7;
482 break;
483 case MEP_OPERAND_UDISP7A2:
484 reloc = BFD_RELOC_MEP_TPREL7A2;
485 break;
486 case MEP_OPERAND_UDISP7A4:
487 reloc = BFD_RELOC_MEP_TPREL7A4;
488 break;
489 default:
490 /* Safe assumption? */
491 abort ();
492 }
493 errmsg = cgen_parse_address (cd, strp, opindex, reloc,
494 NULL, &value);
495 if (**strp != ')')
496 return "missing `)'";
497 ++*strp;
498 *valuep = value;
499 return errmsg;
500 }
501
502 if (**strp == '%')
503 return _("invalid %function() here");
504
505 return parse_mep_alignu (cd, strp, opindex, valuep);
506 }
507
508 static ATTRIBUTE_UNUSED const char *
parse_cdisp10(CGEN_CPU_DESC cd,const char ** strp,int opindex,long * valuep)509 parse_cdisp10 (CGEN_CPU_DESC cd,
510 const char **strp,
511 int opindex,
512 long *valuep)
513 {
514 const char *errmsg = 0;
515 signed long value;
516 long have_zero = 0;
517 int wide = 0;
518 int alignment;
519
520 switch (opindex)
521 {
522 case MEP_OPERAND_CDISP10A4:
523 alignment = 2;
524 break;
525 case MEP_OPERAND_CDISP10A2:
526 alignment = 1;
527 break;
528 case MEP_OPERAND_CDISP10:
529 default:
530 alignment = 0;
531 break;
532 }
533
534 if ((MEP_CPU & EF_MEP_CPU_MASK) == EF_MEP_CPU_C5)
535 wide = 1;
536
537 if (strncmp (*strp, "0x0", 3) == 0
538 || (**strp == '0' && *(*strp + 1) != 'x'))
539 have_zero = 1;
540
541 errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value);
542 if (errmsg)
543 return errmsg;
544
545 if (wide)
546 {
547 if (value < -512 || value > 511)
548 return _("Immediate is out of range -512 to 511");
549 }
550 else
551 {
552 if (value < -128 || value > 127)
553 return _("Immediate is out of range -128 to 127");
554 }
555
556 if (value & ((1<<alignment)-1))
557 return _("Value is not aligned enough");
558
559 /* If this field may require a relocation then use larger dsp16. */
560 if (! have_zero && value == 0)
561 return (wide ? _("Immediate is out of range -512 to 511")
562 : _("Immediate is out of range -128 to 127"));
563
564 *valuep = value;
565 return 0;
566 }
567
568 /* BEGIN LIGHTWEIGHT MACRO PROCESSOR. */
569
570 #define MAXARGS 9
571
572 typedef struct
573 {
574 char *name;
575 char *expansion;
576 } macro;
577
578 typedef struct
579 {
580 const char *start;
581 int len;
582 } arg;
583
584 macro macros[] =
585 {
586 { "sizeof", "(`1.end + (- `1))"},
587 { "startof", "(`1 | 0)" },
588 { "align4", "(`1&(~3))"},
589 /*{ "hi", "(((`1+0x8000)>>16) & 0xffff)" }, */
590 /*{ "lo", "(`1 & 0xffff)" }, */
591 /*{ "sdaoff", "((`1-__sdabase) & 0x7f)"}, */
592 /*{ "tpoff", "((`1-__tpbase) & 0x7f)"}, */
593 { 0,0 }
594 };
595
596 static char * expand_string (const char *, int);
597
598 static const char *
599 mep_cgen_expand_macros_and_parse_operand
600 (CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *);
601
602 static char *
str_append(char * dest,const char * input,int len)603 str_append (char *dest, const char *input, int len)
604 {
605 char *new_dest;
606 int oldlen;
607
608 if (len == 0)
609 return dest;
610 /* printf("str_append: <<%s>>, <<%s>>, %d\n", dest, input, len); */
611 oldlen = (dest ? strlen(dest) : 0);
612 new_dest = realloc (dest, oldlen + len + 1);
613 memset (new_dest + oldlen, 0, len + 1);
614 return strncat (new_dest, input, len);
615 }
616
617 static macro *
lookup_macro(const char * name)618 lookup_macro (const char *name)
619 {
620 macro *m;
621
622 for (m = macros; m->name; ++m)
623 if (strncmp (m->name, name, strlen(m->name)) == 0)
624 return m;
625
626 return 0;
627 }
628
629 static char *
expand_macro(arg * args,int narg,macro * mac)630 expand_macro (arg *args, int narg, macro *mac)
631 {
632 char *result = 0, *rescanned_result = 0;
633 char *e = mac->expansion;
634 char *mark = e;
635 int mac_arg = 0;
636
637 /* printf("expanding macro %s with %d args\n", mac->name, narg + 1); */
638 while (*e)
639 {
640 if (*e == '`' &&
641 (*e+1) &&
642 ((*(e + 1) - '1') <= MAXARGS) &&
643 ((*(e + 1) - '1') <= narg))
644 {
645 result = str_append (result, mark, e - mark);
646 mac_arg = (*(e + 1) - '1');
647 /* printf("replacing `%d with %s\n", mac_arg+1, args[mac_arg].start); */
648 result = str_append (result, args[mac_arg].start, args[mac_arg].len);
649 ++e;
650 mark = e+1;
651 }
652 ++e;
653 }
654
655 if (mark != e)
656 result = str_append (result, mark, e - mark);
657
658 if (result)
659 {
660 rescanned_result = expand_string (result, 0);
661 free (result);
662 return rescanned_result;
663 }
664 else
665 return result;
666 }
667
668 #define IN_TEXT 0
669 #define IN_ARGS 1
670
671 static char *
expand_string(const char * in,int first_only)672 expand_string (const char *in, int first_only)
673 {
674 int num_expansions = 0;
675 int depth = 0;
676 int narg = -1;
677 arg args[MAXARGS];
678 int state = IN_TEXT;
679 const char *mark = in;
680 macro *pmacro = NULL;
681 char *expansion = 0;
682 char *result = 0;
683
684 while (*in)
685 {
686 switch (state)
687 {
688 case IN_TEXT:
689 if (*in == '%' && *(in + 1) && (!first_only || num_expansions == 0))
690 {
691 pmacro = lookup_macro (in + 1);
692 if (pmacro)
693 {
694 /* printf("entering state %d at '%s'...\n", state, in); */
695 result = str_append (result, mark, in - mark);
696 mark = in;
697 in += 1 + strlen (pmacro->name);
698 while (*in == ' ') ++in;
699 if (*in != '(')
700 {
701 state = IN_TEXT;
702 pmacro = NULL;
703 }
704 else
705 {
706 state = IN_ARGS;
707 narg = 0;
708 args[narg].start = in + 1;
709 args[narg].len = 0;
710 mark = in + 1;
711 }
712 }
713 }
714 break;
715 case IN_ARGS:
716 if (depth == 0)
717 {
718 switch (*in)
719 {
720 case ',':
721 narg++;
722 args[narg].start = (in + 1);
723 args[narg].len = 0;
724 break;
725 case ')':
726 state = IN_TEXT;
727 /* printf("entering state %d at '%s'...\n", state, in); */
728 if (pmacro)
729 {
730 expansion = 0;
731 expansion = expand_macro (args, narg, pmacro);
732 num_expansions++;
733 if (expansion)
734 {
735 result = str_append (result, expansion, strlen (expansion));
736 free (expansion);
737 }
738 }
739 else
740 {
741 result = str_append (result, mark, in - mark);
742 }
743 pmacro = NULL;
744 mark = in + 1;
745 break;
746 case '(':
747 depth++;
748 default:
749 args[narg].len++;
750 break;
751 }
752 }
753 else
754 {
755 if (*in == ')')
756 depth--;
757 if (narg > -1)
758 args[narg].len++;
759 }
760
761 }
762 ++in;
763 }
764
765 if (mark != in)
766 result = str_append (result, mark, in - mark);
767
768 return result;
769 }
770
771 #undef IN_ARGS
772 #undef IN_TEXT
773 #undef MAXARGS
774
775
776 /* END LIGHTWEIGHT MACRO PROCESSOR. */
777
778 const char * mep_cgen_parse_operand
779 (CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *);
780
781 const char *
mep_cgen_expand_macros_and_parse_operand(CGEN_CPU_DESC cd,int opindex,const char ** strp_in,CGEN_FIELDS * fields)782 mep_cgen_expand_macros_and_parse_operand (CGEN_CPU_DESC cd, int opindex,
783 const char ** strp_in, CGEN_FIELDS * fields)
784 {
785 const char * errmsg = NULL;
786 char *str = 0, *hold = 0;
787 const char **strp = 0;
788
789 /* Set up a new pointer to macro-expanded string. */
790 str = expand_string (*strp_in, 1);
791 /* fprintf (stderr, " expanded <<%s>> to <<%s>>\n", *strp_in, str); */
792
793 hold = str;
794 strp = (const char **)(&str);
795
796 errmsg = mep_cgen_parse_operand (cd, opindex, strp, fields);
797
798 /* Now work out the advance. */
799 if (strlen (str) == 0)
800 *strp_in += strlen (*strp_in);
801
802 else
803 {
804 if (strstr (*strp_in, str))
805 /* A macro-expansion was pulled off the front. */
806 *strp_in = strstr (*strp_in, str);
807 else
808 /* A non-macro-expansion was pulled off the front. */
809 *strp_in += (str - hold);
810 }
811
812 if (hold)
813 free (hold);
814
815 return errmsg;
816 }
817
818 #define CGEN_ASM_INIT_HOOK (cd->parse_operand = mep_cgen_expand_macros_and_parse_operand);
819
820 /* -- dis.c */
821
822 const 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
838 const char *
mep_cgen_parse_operand(CGEN_CPU_DESC cd,int opindex,const char ** strp,CGEN_FIELDS * fields)839 mep_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;
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;
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;
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));
873 break;
874 case MEP_OPERAND_CDISP10A4 :
875 errmsg = parse_cdisp10 (cd, strp, MEP_OPERAND_CDISP10A4, (long *) (& fields->f_cdisp10));
876 break;
877 case MEP_OPERAND_CDISP10A8 :
878 errmsg = parse_cdisp10 (cd, strp, MEP_OPERAND_CDISP10A8, (long *) (& fields->f_cdisp10));
879 break;
880 case MEP_OPERAND_CDISP12 :
881 errmsg = cgen_parse_signed_integer (cd, strp, MEP_OPERAND_CDISP12, (long *) (& fields->f_12s20));
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;
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;
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;
946 case MEP_OPERAND_HI :
947 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
948 break;
949 case MEP_OPERAND_IMM16P0 :
950 errmsg = parse_unsigned16_range (cd, strp, MEP_OPERAND_IMM16P0, (unsigned long *) (& fields->f_ivc2_imm16p0));
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;
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;
1093 case MEP_OPERAND_IVC2C3CCRN :
1094 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & fields->f_ivc2_ccrn_c3);
1095 break;
1096 case MEP_OPERAND_IVC2CCRN :
1097 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & fields->f_ivc2_ccrn);
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;
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;
1156 case MEP_OPERAND_RL5 :
1157 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rl5);
1158 break;
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;
1216 case MEP_OPERAND_SIMM16P0 :
1217 errmsg = parse_signed16_range (cd, strp, MEP_OPERAND_SIMM16P0, (long *) (& fields->f_ivc2_simm16p0));
1218 break;
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;
1225 case MEP_OPERAND_SIMM8P0 :
1226 errmsg = cgen_parse_signed_integer (cd, strp, MEP_OPERAND_SIMM8P0, (long *) (& fields->f_ivc2_8s0));
1227 break;
1228 case MEP_OPERAND_SIMM8P20 :
1229 errmsg = cgen_parse_signed_integer (cd, strp, MEP_OPERAND_SIMM8P20, (long *) (& fields->f_ivc2_8s20));
1230 break;
1231 case MEP_OPERAND_SIMM8P4 :
1232 errmsg = cgen_parse_signed_integer (cd, strp, MEP_OPERAND_SIMM8P4, (long *) (& fields->f_ivc2_8s4));
1233 break;
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 */
1285 fprintf (stderr, _("Unrecognized field %d while parsing.\n"), opindex);
1286 abort ();
1287 }
1288
1289 return errmsg;
1290 }
1291
1292 cgen_parse_fn * const mep_cgen_parse_handlers[] =
1293 {
1294 parse_insn_normal,
1295 };
1296
1297 void
mep_cgen_init_asm(CGEN_CPU_DESC cd)1298 mep_cgen_init_asm (CGEN_CPU_DESC cd)
1299 {
1300 mep_cgen_init_opcode_table (cd);
1301 mep_cgen_init_ibld_table (cd);
1302 cd->parse_handlers = & mep_cgen_parse_handlers[0];
1303 cd->parse_operand = mep_cgen_parse_operand;
1304 #ifdef CGEN_ASM_INIT_HOOK
1305 CGEN_ASM_INIT_HOOK
1306 #endif
1307 }
1308
1309
1310
1311 /* Regex construction routine.
1312
1313 This translates an opcode syntax string into a regex string,
1314 by replacing any non-character syntax element (such as an
1315 opcode) with the pattern '.*'
1316
1317 It then compiles the regex and stores it in the opcode, for
1318 later use by mep_cgen_assemble_insn
1319
1320 Returns NULL for success, an error message for failure. */
1321
1322 char *
mep_cgen_build_insn_regex(CGEN_INSN * insn)1323 mep_cgen_build_insn_regex (CGEN_INSN *insn)
1324 {
1325 CGEN_OPCODE *opc = (CGEN_OPCODE *) CGEN_INSN_OPCODE (insn);
1326 const char *mnem = CGEN_INSN_MNEMONIC (insn);
1327 char rxbuf[CGEN_MAX_RX_ELEMENTS];
1328 char *rx = rxbuf;
1329 const CGEN_SYNTAX_CHAR_TYPE *syn;
1330 int reg_err;
1331
1332 syn = CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc));
1333
1334 /* Mnemonics come first in the syntax string. */
1335 if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
1336 return _("missing mnemonic in syntax string");
1337 ++syn;
1338
1339 /* Generate a case sensitive regular expression that emulates case
1340 insensitive matching in the "C" locale. We cannot generate a case
1341 insensitive regular expression because in Turkish locales, 'i' and 'I'
1342 are not equal modulo case conversion. */
1343
1344 /* Copy the literal mnemonic out of the insn. */
1345 for (; *mnem; mnem++)
1346 {
1347 char c = *mnem;
1348
1349 if (ISALPHA (c))
1350 {
1351 *rx++ = '[';
1352 *rx++ = TOLOWER (c);
1353 *rx++ = TOUPPER (c);
1354 *rx++ = ']';
1355 }
1356 else
1357 *rx++ = c;
1358 }
1359
1360 /* Copy any remaining literals from the syntax string into the rx. */
1361 for(; * syn != 0 && rx <= rxbuf + (CGEN_MAX_RX_ELEMENTS - 7 - 4); ++syn)
1362 {
1363 if (CGEN_SYNTAX_CHAR_P (* syn))
1364 {
1365 char c = CGEN_SYNTAX_CHAR (* syn);
1366
1367 switch (c)
1368 {
1369 /* Escape any regex metacharacters in the syntax. */
1370 case '.': case '[': case '\\':
1371 case '*': case '^': case '$':
1372
1373 #ifdef CGEN_ESCAPE_EXTENDED_REGEX
1374 case '?': case '{': case '}':
1375 case '(': case ')': case '*':
1376 case '|': case '+': case ']':
1377 #endif
1378 *rx++ = '\\';
1379 *rx++ = c;
1380 break;
1381
1382 default:
1383 if (ISALPHA (c))
1384 {
1385 *rx++ = '[';
1386 *rx++ = TOLOWER (c);
1387 *rx++ = TOUPPER (c);
1388 *rx++ = ']';
1389 }
1390 else
1391 *rx++ = c;
1392 break;
1393 }
1394 }
1395 else
1396 {
1397 /* Replace non-syntax fields with globs. */
1398 *rx++ = '.';
1399 *rx++ = '*';
1400 }
1401 }
1402
1403 /* Trailing whitespace ok. */
1404 * rx++ = '[';
1405 * rx++ = ' ';
1406 * rx++ = '\t';
1407 * rx++ = ']';
1408 * rx++ = '*';
1409
1410 /* But anchor it after that. */
1411 * rx++ = '$';
1412 * rx = '\0';
1413
1414 CGEN_INSN_RX (insn) = xmalloc (sizeof (regex_t));
1415 reg_err = regcomp ((regex_t *) CGEN_INSN_RX (insn), rxbuf, REG_NOSUB);
1416
1417 if (reg_err == 0)
1418 return NULL;
1419 else
1420 {
1421 static char msg[80];
1422
1423 regerror (reg_err, (regex_t *) CGEN_INSN_RX (insn), msg, 80);
1424 regfree ((regex_t *) CGEN_INSN_RX (insn));
1425 free (CGEN_INSN_RX (insn));
1426 (CGEN_INSN_RX (insn)) = NULL;
1427 return msg;
1428 }
1429 }
1430
1431
1432 /* Default insn parser.
1433
1434 The syntax string is scanned and operands are parsed and stored in FIELDS.
1435 Relocs are queued as we go via other callbacks.
1436
1437 ??? Note that this is currently an all-or-nothing parser. If we fail to
1438 parse the instruction, we return 0 and the caller will start over from
1439 the beginning. Backtracking will be necessary in parsing subexpressions,
1440 but that can be handled there. Not handling backtracking here may get
1441 expensive in the case of the m68k. Deal with later.
1442
1443 Returns NULL for success, an error message for failure. */
1444
1445 static const char *
parse_insn_normal(CGEN_CPU_DESC cd,const CGEN_INSN * insn,const char ** strp,CGEN_FIELDS * fields)1446 parse_insn_normal (CGEN_CPU_DESC cd,
1447 const CGEN_INSN *insn,
1448 const char **strp,
1449 CGEN_FIELDS *fields)
1450 {
1451 /* ??? Runtime added insns not handled yet. */
1452 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
1453 const char *str = *strp;
1454 const char *errmsg;
1455 const char *p;
1456 const CGEN_SYNTAX_CHAR_TYPE * syn;
1457 #ifdef CGEN_MNEMONIC_OPERANDS
1458 /* FIXME: wip */
1459 int past_opcode_p;
1460 #endif
1461
1462 /* For now we assume the mnemonic is first (there are no leading operands).
1463 We can parse it without needing to set up operand parsing.
1464 GAS's input scrubber will ensure mnemonics are lowercase, but we may
1465 not be called from GAS. */
1466 p = CGEN_INSN_MNEMONIC (insn);
1467 while (*p && TOLOWER (*p) == TOLOWER (*str))
1468 ++p, ++str;
1469
1470 if (* p)
1471 return _("unrecognized instruction");
1472
1473 #ifndef CGEN_MNEMONIC_OPERANDS
1474 if (* str && ! ISSPACE (* str))
1475 return _("unrecognized instruction");
1476 #endif
1477
1478 CGEN_INIT_PARSE (cd);
1479 cgen_init_parse_operand (cd);
1480 #ifdef CGEN_MNEMONIC_OPERANDS
1481 past_opcode_p = 0;
1482 #endif
1483
1484 /* We don't check for (*str != '\0') here because we want to parse
1485 any trailing fake arguments in the syntax string. */
1486 syn = CGEN_SYNTAX_STRING (syntax);
1487
1488 /* Mnemonics come first for now, ensure valid string. */
1489 if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
1490 abort ();
1491
1492 ++syn;
1493
1494 while (* syn != 0)
1495 {
1496 /* Non operand chars must match exactly. */
1497 if (CGEN_SYNTAX_CHAR_P (* syn))
1498 {
1499 /* FIXME: While we allow for non-GAS callers above, we assume the
1500 first char after the mnemonic part is a space. */
1501 /* FIXME: We also take inappropriate advantage of the fact that
1502 GAS's input scrubber will remove extraneous blanks. */
1503 if (TOLOWER (*str) == TOLOWER (CGEN_SYNTAX_CHAR (* syn)))
1504 {
1505 #ifdef CGEN_MNEMONIC_OPERANDS
1506 if (CGEN_SYNTAX_CHAR(* syn) == ' ')
1507 past_opcode_p = 1;
1508 #endif
1509 ++ syn;
1510 ++ str;
1511 }
1512 else if (*str)
1513 {
1514 /* Syntax char didn't match. Can't be this insn. */
1515 static char msg [80];
1516
1517 /* xgettext:c-format */
1518 sprintf (msg, _("syntax error (expected char `%c', found `%c')"),
1519 CGEN_SYNTAX_CHAR(*syn), *str);
1520 return msg;
1521 }
1522 else
1523 {
1524 /* Ran out of input. */
1525 static char msg [80];
1526
1527 /* xgettext:c-format */
1528 sprintf (msg, _("syntax error (expected char `%c', found end of instruction)"),
1529 CGEN_SYNTAX_CHAR(*syn));
1530 return msg;
1531 }
1532 continue;
1533 }
1534
1535 #ifdef CGEN_MNEMONIC_OPERANDS
1536 (void) past_opcode_p;
1537 #endif
1538 /* We have an operand of some sort. */
1539 errmsg = cd->parse_operand (cd, CGEN_SYNTAX_FIELD (*syn), &str, fields);
1540 if (errmsg)
1541 return errmsg;
1542
1543 /* Done with this operand, continue with next one. */
1544 ++ syn;
1545 }
1546
1547 /* If we're at the end of the syntax string, we're done. */
1548 if (* syn == 0)
1549 {
1550 /* FIXME: For the moment we assume a valid `str' can only contain
1551 blanks now. IE: We needn't try again with a longer version of
1552 the insn and it is assumed that longer versions of insns appear
1553 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
1554 while (ISSPACE (* str))
1555 ++ str;
1556
1557 if (* str != '\0')
1558 return _("junk at end of line"); /* FIXME: would like to include `str' */
1559
1560 return NULL;
1561 }
1562
1563 /* We couldn't parse it. */
1564 return _("unrecognized instruction");
1565 }
1566
1567 /* Main entry point.
1568 This routine is called for each instruction to be assembled.
1569 STR points to the insn to be assembled.
1570 We assume all necessary tables have been initialized.
1571 The assembled instruction, less any fixups, is stored in BUF.
1572 Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
1573 still needs to be converted to target byte order, otherwise BUF is an array
1574 of bytes in target byte order.
1575 The result is a pointer to the insn's entry in the opcode table,
1576 or NULL if an error occured (an error message will have already been
1577 printed).
1578
1579 Note that when processing (non-alias) macro-insns,
1580 this function recurses.
1581
1582 ??? It's possible to make this cpu-independent.
1583 One would have to deal with a few minor things.
1584 At this point in time doing so would be more of a curiosity than useful
1585 [for example this file isn't _that_ big], but keeping the possibility in
1586 mind helps keep the design clean. */
1587
1588 const CGEN_INSN *
mep_cgen_assemble_insn(CGEN_CPU_DESC cd,const char * str,CGEN_FIELDS * fields,CGEN_INSN_BYTES_PTR buf,char ** errmsg)1589 mep_cgen_assemble_insn (CGEN_CPU_DESC cd,
1590 const char *str,
1591 CGEN_FIELDS *fields,
1592 CGEN_INSN_BYTES_PTR buf,
1593 char **errmsg)
1594 {
1595 const char *start;
1596 CGEN_INSN_LIST *ilist;
1597 const char *parse_errmsg = NULL;
1598 const char *insert_errmsg = NULL;
1599 int recognized_mnemonic = 0;
1600
1601 /* Skip leading white space. */
1602 while (ISSPACE (* str))
1603 ++ str;
1604
1605 /* The instructions are stored in hashed lists.
1606 Get the first in the list. */
1607 ilist = CGEN_ASM_LOOKUP_INSN (cd, str);
1608
1609 /* Keep looking until we find a match. */
1610 start = str;
1611 for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist))
1612 {
1613 const CGEN_INSN *insn = ilist->insn;
1614 recognized_mnemonic = 1;
1615
1616 #ifdef CGEN_VALIDATE_INSN_SUPPORTED
1617 /* Not usually needed as unsupported opcodes
1618 shouldn't be in the hash lists. */
1619 /* Is this insn supported by the selected cpu? */
1620 if (! mep_cgen_insn_supported (cd, insn))
1621 continue;
1622 #endif
1623 /* If the RELAXED attribute is set, this is an insn that shouldn't be
1624 chosen immediately. Instead, it is used during assembler/linker
1625 relaxation if possible. */
1626 if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXED) != 0)
1627 continue;
1628
1629 str = start;
1630
1631 /* Skip this insn if str doesn't look right lexically. */
1632 if (CGEN_INSN_RX (insn) != NULL &&
1633 regexec ((regex_t *) CGEN_INSN_RX (insn), str, 0, NULL, 0) == REG_NOMATCH)
1634 continue;
1635
1636 /* Allow parse/insert handlers to obtain length of insn. */
1637 CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
1638
1639 parse_errmsg = CGEN_PARSE_FN (cd, insn) (cd, insn, & str, fields);
1640 if (parse_errmsg != NULL)
1641 continue;
1642
1643 /* ??? 0 is passed for `pc'. */
1644 insert_errmsg = CGEN_INSERT_FN (cd, insn) (cd, insn, fields, buf,
1645 (bfd_vma) 0);
1646 if (insert_errmsg != NULL)
1647 continue;
1648
1649 /* It is up to the caller to actually output the insn and any
1650 queued relocs. */
1651 return insn;
1652 }
1653
1654 {
1655 static char errbuf[150];
1656 const char *tmp_errmsg;
1657 #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
1658 #define be_verbose 1
1659 #else
1660 #define be_verbose 0
1661 #endif
1662
1663 if (be_verbose)
1664 {
1665 /* If requesting verbose error messages, use insert_errmsg.
1666 Failing that, use parse_errmsg. */
1667 tmp_errmsg = (insert_errmsg ? insert_errmsg :
1668 parse_errmsg ? parse_errmsg :
1669 recognized_mnemonic ?
1670 _("unrecognized form of instruction") :
1671 _("unrecognized instruction"));
1672
1673 if (strlen (start) > 50)
1674 /* xgettext:c-format */
1675 sprintf (errbuf, "%s `%.50s...'", tmp_errmsg, start);
1676 else
1677 /* xgettext:c-format */
1678 sprintf (errbuf, "%s `%.50s'", tmp_errmsg, start);
1679 }
1680 else
1681 {
1682 if (strlen (start) > 50)
1683 /* xgettext:c-format */
1684 sprintf (errbuf, _("bad instruction `%.50s...'"), start);
1685 else
1686 /* xgettext:c-format */
1687 sprintf (errbuf, _("bad instruction `%.50s'"), start);
1688 }
1689
1690 *errmsg = errbuf;
1691 return NULL;
1692 }
1693 }
1694