* config/tc-mips.c (mips_cpreturn_offset): New variable.
[deliverable/binutils-gdb.git] / opcodes / fr30-asm.c
... / ...
CommitLineData
1/* Assembler interface for targets using CGEN. -*- C -*-
2 CGEN: Cpu tools GENerator
3
4THIS FILE IS MACHINE GENERATED WITH CGEN.
5- the resultant file is machine generated, cgen-asm.in isn't
6
7Copyright 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
8
9This file is part of the GNU Binutils and GDB, the GNU debugger.
10
11This program is free software; you can redistribute it and/or modify
12it under the terms of the GNU General Public License as published by
13the Free Software Foundation; either version 2, or (at your option)
14any later version.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License
22along with this program; if not, write to the Free Software Foundation, Inc.,
2359 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24
25/* ??? Eventually more and more of this stuff can go to cpu-independent files.
26 Keep that in mind. */
27
28#include "sysdep.h"
29#include <ctype.h>
30#include <stdio.h>
31#include "ansidecl.h"
32#include "bfd.h"
33#include "symcat.h"
34#include "fr30-desc.h"
35#include "fr30-opc.h"
36#include "opintl.h"
37#include "xregex.h"
38#include "libiberty.h"
39
40#undef min
41#define min(a,b) ((a) < (b) ? (a) : (b))
42#undef max
43#define max(a,b) ((a) > (b) ? (a) : (b))
44
45static const char * parse_insn_normal
46 PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *, const char **, CGEN_FIELDS *));
47\f
48/* -- assembler routines inserted here */
49
50/* -- asm.c */
51/* Handle register lists for LDMx and STMx. */
52
53static int parse_register_number
54 PARAMS ((const char **));
55static const char * parse_register_list
56 PARAMS ((CGEN_CPU_DESC, const char **, int, unsigned long *, int, int));
57static const char * parse_low_register_list_ld
58 PARAMS ((CGEN_CPU_DESC, const char **, int, unsigned long *));
59static const char * parse_hi_register_list_ld
60 PARAMS ((CGEN_CPU_DESC, const char **, int, unsigned long *));
61static const char * parse_low_register_list_st
62 PARAMS ((CGEN_CPU_DESC, const char **, int, unsigned long *));
63static const char * parse_hi_register_list_st
64 PARAMS ((CGEN_CPU_DESC, const char **, int, unsigned long *));
65
66static int
67parse_register_number (strp)
68 const char **strp;
69{
70 int regno;
71 if (**strp < '0' || **strp > '9')
72 return -1; /* error. */
73 regno = **strp - '0';
74 ++*strp;
75
76 if (**strp >= '0' && **strp <= '9')
77 {
78 regno = regno * 10 + (**strp - '0');
79 ++*strp;
80 }
81
82 return regno;
83}
84
85static const char *
86parse_register_list (cd, strp, opindex, valuep, high_low, load_store)
87 CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
88 const char **strp;
89 int opindex ATTRIBUTE_UNUSED;
90 unsigned long *valuep;
91 int high_low; /* 0 == high, 1 == low */
92 int load_store; /* 0 == load, 1 == store */
93{
94 int regno;
95
96 *valuep = 0;
97 while (**strp && **strp != ')')
98 {
99 if (**strp != 'R' && **strp != 'r')
100 break;
101 ++*strp;
102
103 regno = parse_register_number (strp);
104 if (regno == -1)
105 return "Register number is not valid";
106 if (regno > 7 && !high_low)
107 return "Register must be between r0 and r7";
108 if (regno < 8 && high_low)
109 return "Register must be between r8 and r15";
110
111 if (high_low)
112 regno -= 8;
113
114 if (load_store) /* Mask is reversed for store. */
115 *valuep |= 0x80 >> regno;
116 else
117 *valuep |= 1 << regno;
118
119 if (**strp == ',')
120 {
121 if (*(*strp + 1) == ')')
122 break;
123 ++*strp;
124 }
125 }
126
127 if (!*strp || **strp != ')')
128 return "Register list is not valid";
129
130 return NULL;
131}
132
133static const char *
134parse_low_register_list_ld (cd, strp, opindex, valuep)
135 CGEN_CPU_DESC cd;
136 const char **strp;
137 int opindex;
138 unsigned long *valuep;
139{
140 return parse_register_list (cd, strp, opindex, valuep, 0/*low*/, 0/*load*/);
141}
142
143static const char *
144parse_hi_register_list_ld (cd, strp, opindex, valuep)
145 CGEN_CPU_DESC cd;
146 const char **strp;
147 int opindex;
148 unsigned long *valuep;
149{
150 return parse_register_list (cd, strp, opindex, valuep, 1/*high*/, 0/*load*/);
151}
152
153static const char *
154parse_low_register_list_st (cd, strp, opindex, valuep)
155 CGEN_CPU_DESC cd;
156 const char **strp;
157 int opindex;
158 unsigned long *valuep;
159{
160 return parse_register_list (cd, strp, opindex, valuep, 0/*low*/, 1/*store*/);
161}
162
163static const char *
164parse_hi_register_list_st (cd, strp, opindex, valuep)
165 CGEN_CPU_DESC cd;
166 const char **strp;
167 int opindex;
168 unsigned long *valuep;
169{
170 return parse_register_list (cd, strp, opindex, valuep, 1/*high*/, 1/*store*/);
171}
172
173/* -- */
174
175const char * fr30_cgen_parse_operand
176 PARAMS ((CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *));
177
178/* Main entry point for operand parsing.
179
180 This function is basically just a big switch statement. Earlier versions
181 used tables to look up the function to use, but
182 - if the table contains both assembler and disassembler functions then
183 the disassembler contains much of the assembler and vice-versa,
184 - there's a lot of inlining possibilities as things grow,
185 - using a switch statement avoids the function call overhead.
186
187 This function could be moved into `parse_insn_normal', but keeping it
188 separate makes clear the interface between `parse_insn_normal' and each of
189 the handlers.
190*/
191
192const char *
193fr30_cgen_parse_operand (cd, opindex, strp, fields)
194 CGEN_CPU_DESC cd;
195 int opindex;
196 const char ** strp;
197 CGEN_FIELDS * fields;
198{
199 const char * errmsg = NULL;
200 /* Used by scalar operands that still need to be parsed. */
201 long junk ATTRIBUTE_UNUSED;
202
203 switch (opindex)
204 {
205 case FR30_OPERAND_CRI :
206 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_cr_names, & fields->f_CRi);
207 break;
208 case FR30_OPERAND_CRJ :
209 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_cr_names, & fields->f_CRj);
210 break;
211 case FR30_OPERAND_R13 :
212 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_h_r13, & junk);
213 break;
214 case FR30_OPERAND_R14 :
215 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_h_r14, & junk);
216 break;
217 case FR30_OPERAND_R15 :
218 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_h_r15, & junk);
219 break;
220 case FR30_OPERAND_RI :
221 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_gr_names, & fields->f_Ri);
222 break;
223 case FR30_OPERAND_RIC :
224 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_gr_names, & fields->f_Ric);
225 break;
226 case FR30_OPERAND_RJ :
227 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_gr_names, & fields->f_Rj);
228 break;
229 case FR30_OPERAND_RJC :
230 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_gr_names, & fields->f_Rjc);
231 break;
232 case FR30_OPERAND_RS1 :
233 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_dr_names, & fields->f_Rs1);
234 break;
235 case FR30_OPERAND_RS2 :
236 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_dr_names, & fields->f_Rs2);
237 break;
238 case FR30_OPERAND_CC :
239 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_CC, &fields->f_cc);
240 break;
241 case FR30_OPERAND_CCC :
242 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_CCC, &fields->f_ccc);
243 break;
244 case FR30_OPERAND_DIR10 :
245 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_DIR10, &fields->f_dir10);
246 break;
247 case FR30_OPERAND_DIR8 :
248 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_DIR8, &fields->f_dir8);
249 break;
250 case FR30_OPERAND_DIR9 :
251 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_DIR9, &fields->f_dir9);
252 break;
253 case FR30_OPERAND_DISP10 :
254 errmsg = cgen_parse_signed_integer (cd, strp, FR30_OPERAND_DISP10, &fields->f_disp10);
255 break;
256 case FR30_OPERAND_DISP8 :
257 errmsg = cgen_parse_signed_integer (cd, strp, FR30_OPERAND_DISP8, &fields->f_disp8);
258 break;
259 case FR30_OPERAND_DISP9 :
260 errmsg = cgen_parse_signed_integer (cd, strp, FR30_OPERAND_DISP9, &fields->f_disp9);
261 break;
262 case FR30_OPERAND_I20 :
263 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_I20, &fields->f_i20);
264 break;
265 case FR30_OPERAND_I32 :
266 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_I32, &fields->f_i32);
267 break;
268 case FR30_OPERAND_I8 :
269 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_I8, &fields->f_i8);
270 break;
271 case FR30_OPERAND_LABEL12 :
272 {
273 bfd_vma value;
274 errmsg = cgen_parse_address (cd, strp, FR30_OPERAND_LABEL12, 0, NULL, & value);
275 fields->f_rel12 = value;
276 }
277 break;
278 case FR30_OPERAND_LABEL9 :
279 {
280 bfd_vma value;
281 errmsg = cgen_parse_address (cd, strp, FR30_OPERAND_LABEL9, 0, NULL, & value);
282 fields->f_rel9 = value;
283 }
284 break;
285 case FR30_OPERAND_M4 :
286 errmsg = cgen_parse_signed_integer (cd, strp, FR30_OPERAND_M4, &fields->f_m4);
287 break;
288 case FR30_OPERAND_PS :
289 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_h_ps, & junk);
290 break;
291 case FR30_OPERAND_REGLIST_HI_LD :
292 errmsg = parse_hi_register_list_ld (cd, strp, FR30_OPERAND_REGLIST_HI_LD, &fields->f_reglist_hi_ld);
293 break;
294 case FR30_OPERAND_REGLIST_HI_ST :
295 errmsg = parse_hi_register_list_st (cd, strp, FR30_OPERAND_REGLIST_HI_ST, &fields->f_reglist_hi_st);
296 break;
297 case FR30_OPERAND_REGLIST_LOW_LD :
298 errmsg = parse_low_register_list_ld (cd, strp, FR30_OPERAND_REGLIST_LOW_LD, &fields->f_reglist_low_ld);
299 break;
300 case FR30_OPERAND_REGLIST_LOW_ST :
301 errmsg = parse_low_register_list_st (cd, strp, FR30_OPERAND_REGLIST_LOW_ST, &fields->f_reglist_low_st);
302 break;
303 case FR30_OPERAND_S10 :
304 errmsg = cgen_parse_signed_integer (cd, strp, FR30_OPERAND_S10, &fields->f_s10);
305 break;
306 case FR30_OPERAND_U10 :
307 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_U10, &fields->f_u10);
308 break;
309 case FR30_OPERAND_U4 :
310 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_U4, &fields->f_u4);
311 break;
312 case FR30_OPERAND_U4C :
313 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_U4C, &fields->f_u4c);
314 break;
315 case FR30_OPERAND_U8 :
316 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_U8, &fields->f_u8);
317 break;
318 case FR30_OPERAND_UDISP6 :
319 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_UDISP6, &fields->f_udisp6);
320 break;
321
322 default :
323 /* xgettext:c-format */
324 fprintf (stderr, _("Unrecognized field %d while parsing.\n"), opindex);
325 abort ();
326 }
327
328 return errmsg;
329}
330
331cgen_parse_fn * const fr30_cgen_parse_handlers[] =
332{
333 parse_insn_normal,
334};
335
336void
337fr30_cgen_init_asm (cd)
338 CGEN_CPU_DESC cd;
339{
340 fr30_cgen_init_opcode_table (cd);
341 fr30_cgen_init_ibld_table (cd);
342 cd->parse_handlers = & fr30_cgen_parse_handlers[0];
343 cd->parse_operand = fr30_cgen_parse_operand;
344}
345
346\f
347
348/*
349 Regex construction routine.
350
351 This translates an opcode syntax string into a regex string,
352 by replacing any non-character syntax element (such as an
353 opcode) with the pattern '.*'
354
355 It then compiles the regex and stores it in the opcode, for
356 later use by fr30_cgen_assemble_insn
357
358 Returns NULL for success, an error message for failure. */
359
360char *
361fr30_cgen_build_insn_regex (insn)
362 CGEN_INSN *insn;
363{
364 CGEN_OPCODE *opc = (CGEN_OPCODE *) CGEN_INSN_OPCODE (insn);
365 const char *mnem = CGEN_INSN_MNEMONIC (insn);
366 int mnem_len;
367 char rxbuf[CGEN_MAX_RX_ELEMENTS];
368 char *rx = rxbuf;
369 const CGEN_SYNTAX_CHAR_TYPE *syn;
370 int reg_err;
371
372 syn = CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc));
373
374 /* Mnemonics come first in the syntax string */
375 if (! CGEN_SYNTAX_MNEMONIC_P (* syn)) return "missing mnemonic in syntax string";
376 ++syn;
377
378 /* copy the literal mnemonic out of the insn */
379 memset (rx, 0, CGEN_MAX_RX_ELEMENTS);
380 mnem_len = strlen(mnem);
381 memcpy (rx, mnem, mnem_len);
382 rx += mnem_len;
383
384 /* copy any remaining literals from the syntax string into the rx */
385 for(; * syn != 0 && rx < rxbuf + (CGEN_MAX_RX_ELEMENTS - 9); ++syn, ++rx)
386 {
387 if (CGEN_SYNTAX_CHAR_P (* syn))
388 {
389 char tmp = CGEN_SYNTAX_CHAR (* syn);
390 switch (tmp)
391 {
392 /* escape any regex metacharacters in the syntax */
393 case '.': case '[': case '\\':
394 case '*': case '^': case '$':
395
396#ifdef CGEN_ESCAPE_EXTENDED_REGEX
397 case '?': case '{': case '}':
398 case '(': case ')': case '*':
399 case '|': case '+': case ']':
400#endif
401
402 * rx++ = '\\';
403 break;
404 }
405 /* insert syntax char into rx */
406 * rx = tmp;
407 }
408 else
409 {
410 /* replace non-syntax fields with globs */
411 * rx = '.';
412 * ++rx = '*';
413 }
414 }
415
416 /* trailing whitespace ok */
417 * rx++ = '[';
418 * rx++ = ' ';
419 * rx++ = '\t';
420 * rx++ = ']';
421 * rx++ = '*';
422
423 /* but anchor it after that */
424 * rx++ = '$';
425 * rx = '\0';
426
427 CGEN_INSN_RX (insn) = xmalloc (sizeof (regex_t));
428 reg_err = regcomp ((regex_t *) CGEN_INSN_RX (insn), rxbuf, REG_NOSUB|REG_ICASE);
429
430 if (reg_err == 0)
431 return NULL;
432 else
433 {
434 static char msg[80];
435 regerror (reg_err, (regex_t *) CGEN_INSN_RX (insn), msg, 80);
436 regfree ((regex_t *) CGEN_INSN_RX (insn));
437 free (CGEN_INSN_RX (insn));
438 (CGEN_INSN_RX (insn)) = NULL;
439 return msg;
440 }
441}
442
443\f
444/* Default insn parser.
445
446 The syntax string is scanned and operands are parsed and stored in FIELDS.
447 Relocs are queued as we go via other callbacks.
448
449 ??? Note that this is currently an all-or-nothing parser. If we fail to
450 parse the instruction, we return 0 and the caller will start over from
451 the beginning. Backtracking will be necessary in parsing subexpressions,
452 but that can be handled there. Not handling backtracking here may get
453 expensive in the case of the m68k. Deal with later.
454
455 Returns NULL for success, an error message for failure.
456*/
457
458static const char *
459parse_insn_normal (cd, insn, strp, fields)
460 CGEN_CPU_DESC cd;
461 const CGEN_INSN *insn;
462 const char **strp;
463 CGEN_FIELDS *fields;
464{
465 /* ??? Runtime added insns not handled yet. */
466 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
467 const char *str = *strp;
468 const char *errmsg;
469 const char *p;
470 const CGEN_SYNTAX_CHAR_TYPE * syn;
471#ifdef CGEN_MNEMONIC_OPERANDS
472 /* FIXME: wip */
473 int past_opcode_p;
474#endif
475
476 /* For now we assume the mnemonic is first (there are no leading operands).
477 We can parse it without needing to set up operand parsing.
478 GAS's input scrubber will ensure mnemonics are lowercase, but we may
479 not be called from GAS. */
480 p = CGEN_INSN_MNEMONIC (insn);
481 while (*p && tolower (*p) == tolower (*str))
482 ++p, ++str;
483
484 if (* p)
485 return _("unrecognized instruction");
486
487#ifndef CGEN_MNEMONIC_OPERANDS
488 if (* str && !isspace (* str))
489 return _("unrecognized instruction");
490#endif
491
492 CGEN_INIT_PARSE (cd);
493 cgen_init_parse_operand (cd);
494#ifdef CGEN_MNEMONIC_OPERANDS
495 past_opcode_p = 0;
496#endif
497
498 /* We don't check for (*str != '\0') here because we want to parse
499 any trailing fake arguments in the syntax string. */
500 syn = CGEN_SYNTAX_STRING (syntax);
501
502 /* Mnemonics come first for now, ensure valid string. */
503 if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
504 abort ();
505
506 ++syn;
507
508 while (* syn != 0)
509 {
510 /* Non operand chars must match exactly. */
511 if (CGEN_SYNTAX_CHAR_P (* syn))
512 {
513 /* FIXME: While we allow for non-GAS callers above, we assume the
514 first char after the mnemonic part is a space. */
515 /* FIXME: We also take inappropriate advantage of the fact that
516 GAS's input scrubber will remove extraneous blanks. */
517 if (tolower (*str) == tolower (CGEN_SYNTAX_CHAR (* syn)))
518 {
519#ifdef CGEN_MNEMONIC_OPERANDS
520 if (CGEN_SYNTAX_CHAR(* syn) == ' ')
521 past_opcode_p = 1;
522#endif
523 ++ syn;
524 ++ str;
525 }
526 else if (*str)
527 {
528 /* Syntax char didn't match. Can't be this insn. */
529 static char msg [80];
530 /* xgettext:c-format */
531 sprintf (msg, _("syntax error (expected char `%c', found `%c')"),
532 CGEN_SYNTAX_CHAR(*syn), *str);
533 return msg;
534 }
535 else
536 {
537 /* Ran out of input. */
538 static char msg [80];
539 /* xgettext:c-format */
540 sprintf (msg, _("syntax error (expected char `%c', found end of instruction)"),
541 CGEN_SYNTAX_CHAR(*syn));
542 return msg;
543 }
544 continue;
545 }
546
547 /* We have an operand of some sort. */
548 errmsg = fr30_cgen_parse_operand (cd, CGEN_SYNTAX_FIELD (*syn),
549 &str, fields);
550 if (errmsg)
551 return errmsg;
552
553 /* Done with this operand, continue with next one. */
554 ++ syn;
555 }
556
557 /* If we're at the end of the syntax string, we're done. */
558 if (* syn == 0)
559 {
560 /* FIXME: For the moment we assume a valid `str' can only contain
561 blanks now. IE: We needn't try again with a longer version of
562 the insn and it is assumed that longer versions of insns appear
563 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
564 while (isspace (* str))
565 ++ str;
566
567 if (* str != '\0')
568 return _("junk at end of line"); /* FIXME: would like to include `str' */
569
570 return NULL;
571 }
572
573 /* We couldn't parse it. */
574 return _("unrecognized instruction");
575}
576\f
577/* Main entry point.
578 This routine is called for each instruction to be assembled.
579 STR points to the insn to be assembled.
580 We assume all necessary tables have been initialized.
581 The assembled instruction, less any fixups, is stored in BUF.
582 Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
583 still needs to be converted to target byte order, otherwise BUF is an array
584 of bytes in target byte order.
585 The result is a pointer to the insn's entry in the opcode table,
586 or NULL if an error occured (an error message will have already been
587 printed).
588
589 Note that when processing (non-alias) macro-insns,
590 this function recurses.
591
592 ??? It's possible to make this cpu-independent.
593 One would have to deal with a few minor things.
594 At this point in time doing so would be more of a curiosity than useful
595 [for example this file isn't _that_ big], but keeping the possibility in
596 mind helps keep the design clean. */
597
598const CGEN_INSN *
599fr30_cgen_assemble_insn (cd, str, fields, buf, errmsg)
600 CGEN_CPU_DESC cd;
601 const char *str;
602 CGEN_FIELDS *fields;
603 CGEN_INSN_BYTES_PTR buf;
604 char **errmsg;
605{
606 const char *start;
607 CGEN_INSN_LIST *ilist;
608 const char *parse_errmsg = NULL;
609 const char *insert_errmsg = NULL;
610 int recognized_mnemonic = 0;
611
612 /* Skip leading white space. */
613 while (isspace (* str))
614 ++ str;
615
616 /* The instructions are stored in hashed lists.
617 Get the first in the list. */
618 ilist = CGEN_ASM_LOOKUP_INSN (cd, str);
619
620 /* Keep looking until we find a match. */
621
622 start = str;
623 for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist))
624 {
625 const CGEN_INSN *insn = ilist->insn;
626 recognized_mnemonic = 1;
627
628#ifdef CGEN_VALIDATE_INSN_SUPPORTED
629 /* not usually needed as unsupported opcodes shouldn't be in the hash lists */
630 /* Is this insn supported by the selected cpu? */
631 if (! fr30_cgen_insn_supported (cd, insn))
632 continue;
633#endif
634
635 /* If the RELAX attribute is set, this is an insn that shouldn't be
636 chosen immediately. Instead, it is used during assembler/linker
637 relaxation if possible. */
638 if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAX) != 0)
639 continue;
640
641 str = start;
642
643 /* skip this insn if str doesn't look right lexically */
644 if (CGEN_INSN_RX (insn) != NULL &&
645 regexec ((regex_t *) CGEN_INSN_RX (insn), str, 0, NULL, 0) == REG_NOMATCH)
646 continue;
647
648 /* Allow parse/insert handlers to obtain length of insn. */
649 CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
650
651 parse_errmsg = CGEN_PARSE_FN (cd, insn) (cd, insn, & str, fields);
652 if (parse_errmsg != NULL)
653 continue;
654
655 /* ??? 0 is passed for `pc' */
656 insert_errmsg = CGEN_INSERT_FN (cd, insn) (cd, insn, fields, buf,
657 (bfd_vma) 0);
658 if (insert_errmsg != NULL)
659 continue;
660
661 /* It is up to the caller to actually output the insn and any
662 queued relocs. */
663 return insn;
664 }
665
666 {
667 static char errbuf[150];
668#ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
669 const char *tmp_errmsg;
670
671 /* If requesting verbose error messages, use insert_errmsg.
672 Failing that, use parse_errmsg */
673 tmp_errmsg = (insert_errmsg ? insert_errmsg :
674 parse_errmsg ? parse_errmsg :
675 recognized_mnemonic ? _("unrecognized form of instruction") :
676 _("unrecognized instruction"));
677
678 if (strlen (start) > 50)
679 /* xgettext:c-format */
680 sprintf (errbuf, "%s `%.50s...'", tmp_errmsg, start);
681 else
682 /* xgettext:c-format */
683 sprintf (errbuf, "%s `%.50s'", tmp_errmsg, start);
684#else
685 if (strlen (start) > 50)
686 /* xgettext:c-format */
687 sprintf (errbuf, _("bad instruction `%.50s...'"), start);
688 else
689 /* xgettext:c-format */
690 sprintf (errbuf, _("bad instruction `%.50s'"), start);
691#endif
692
693 *errmsg = errbuf;
694 return NULL;
695 }
696}
697\f
698#if 0 /* This calls back to GAS which we can't do without care. */
699
700/* Record each member of OPVALS in the assembler's symbol table.
701 This lets GAS parse registers for us.
702 ??? Interesting idea but not currently used. */
703
704/* Record each member of OPVALS in the assembler's symbol table.
705 FIXME: Not currently used. */
706
707void
708fr30_cgen_asm_hash_keywords (cd, opvals)
709 CGEN_CPU_DESC cd;
710 CGEN_KEYWORD *opvals;
711{
712 CGEN_KEYWORD_SEARCH search = cgen_keyword_search_init (opvals, NULL);
713 const CGEN_KEYWORD_ENTRY * ke;
714
715 while ((ke = cgen_keyword_search_next (& search)) != NULL)
716 {
717#if 0 /* Unnecessary, should be done in the search routine. */
718 if (! fr30_cgen_opval_supported (ke))
719 continue;
720#endif
721 cgen_asm_record_register (cd, ke->name, ke->value);
722 }
723}
724
725#endif /* 0 */
This page took 0.024919 seconds and 4 git commands to generate.