*** empty log message ***
[deliverable/binutils-gdb.git] / opcodes / fr30-asm.c
CommitLineData
252b5132
RH
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
060d22b0 7Copyright 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
252b5132
RH
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"
252b5132
RH
29#include <stdio.h>
30#include "ansidecl.h"
31#include "bfd.h"
32#include "symcat.h"
33#include "fr30-desc.h"
34#include "fr30-opc.h"
35#include "opintl.h"
fc7bc883 36#include "xregex.h"
d5b2f4d6 37#include "libiberty.h"
37111cc7 38#include "safe-ctype.h"
252b5132 39
37111cc7 40#undef min
252b5132 41#define min(a,b) ((a) < (b) ? (a) : (b))
37111cc7 42#undef max
252b5132
RH
43#define max(a,b) ((a) > (b) ? (a) : (b))
44
0e2ee3ca
NC
45static const char * parse_insn_normal
46 PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *, const char **, CGEN_FIELDS *));
252b5132 47\f
37111cc7 48/* -- assembler routines inserted here. */
252b5132
RH
49
50/* -- asm.c */
0e2ee3ca
NC
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 *));
252b5132
RH
65
66static int
67parse_register_number (strp)
68 const char **strp;
69{
70 int regno;
71 if (**strp < '0' || **strp > '9')
0e2ee3ca 72 return -1; /* error. */
252b5132
RH
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)
d5b2f4d6 87 CGEN_CPU_DESC cd ATTRIBUTE_UNUSED;
252b5132 88 const char **strp;
d5b2f4d6 89 int opindex ATTRIBUTE_UNUSED;
252b5132
RH
90 unsigned long *valuep;
91 int high_low; /* 0 == high, 1 == low */
92 int load_store; /* 0 == load, 1 == store */
93{
94 int regno;
0e2ee3ca 95
252b5132
RH
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
0e2ee3ca 114 if (load_store) /* Mask is reversed for store. */
252b5132
RH
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
0e2ee3ca
NC
175const char * fr30_cgen_parse_operand
176 PARAMS ((CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *));
177
252b5132
RH
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
9a2e995d 189 the handlers. */
252b5132
RH
190
191const char *
192fr30_cgen_parse_operand (cd, opindex, strp, fields)
193 CGEN_CPU_DESC cd;
194 int opindex;
195 const char ** strp;
196 CGEN_FIELDS * fields;
197{
eb1b03df
DE
198 const char * errmsg = NULL;
199 /* Used by scalar operands that still need to be parsed. */
0e2ee3ca 200 long junk ATTRIBUTE_UNUSED;
252b5132
RH
201
202 switch (opindex)
203 {
204 case FR30_OPERAND_CRI :
205 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_cr_names, & fields->f_CRi);
206 break;
207 case FR30_OPERAND_CRJ :
208 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_cr_names, & fields->f_CRj);
209 break;
210 case FR30_OPERAND_R13 :
eb1b03df 211 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_h_r13, & junk);
252b5132
RH
212 break;
213 case FR30_OPERAND_R14 :
eb1b03df 214 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_h_r14, & junk);
252b5132
RH
215 break;
216 case FR30_OPERAND_R15 :
eb1b03df 217 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_h_r15, & junk);
252b5132
RH
218 break;
219 case FR30_OPERAND_RI :
220 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_gr_names, & fields->f_Ri);
221 break;
222 case FR30_OPERAND_RIC :
223 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_gr_names, & fields->f_Ric);
224 break;
225 case FR30_OPERAND_RJ :
226 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_gr_names, & fields->f_Rj);
227 break;
228 case FR30_OPERAND_RJC :
229 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_gr_names, & fields->f_Rjc);
230 break;
231 case FR30_OPERAND_RS1 :
232 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_dr_names, & fields->f_Rs1);
233 break;
234 case FR30_OPERAND_RS2 :
235 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_dr_names, & fields->f_Rs2);
236 break;
237 case FR30_OPERAND_CC :
238 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_CC, &fields->f_cc);
239 break;
240 case FR30_OPERAND_CCC :
241 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_CCC, &fields->f_ccc);
242 break;
243 case FR30_OPERAND_DIR10 :
244 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_DIR10, &fields->f_dir10);
245 break;
246 case FR30_OPERAND_DIR8 :
247 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_DIR8, &fields->f_dir8);
248 break;
249 case FR30_OPERAND_DIR9 :
250 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_DIR9, &fields->f_dir9);
251 break;
252 case FR30_OPERAND_DISP10 :
253 errmsg = cgen_parse_signed_integer (cd, strp, FR30_OPERAND_DISP10, &fields->f_disp10);
254 break;
255 case FR30_OPERAND_DISP8 :
256 errmsg = cgen_parse_signed_integer (cd, strp, FR30_OPERAND_DISP8, &fields->f_disp8);
257 break;
258 case FR30_OPERAND_DISP9 :
259 errmsg = cgen_parse_signed_integer (cd, strp, FR30_OPERAND_DISP9, &fields->f_disp9);
260 break;
261 case FR30_OPERAND_I20 :
262 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_I20, &fields->f_i20);
263 break;
264 case FR30_OPERAND_I32 :
265 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_I32, &fields->f_i32);
266 break;
267 case FR30_OPERAND_I8 :
268 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_I8, &fields->f_i8);
269 break;
270 case FR30_OPERAND_LABEL12 :
271 {
272 bfd_vma value;
273 errmsg = cgen_parse_address (cd, strp, FR30_OPERAND_LABEL12, 0, NULL, & value);
274 fields->f_rel12 = value;
275 }
276 break;
277 case FR30_OPERAND_LABEL9 :
278 {
279 bfd_vma value;
280 errmsg = cgen_parse_address (cd, strp, FR30_OPERAND_LABEL9, 0, NULL, & value);
281 fields->f_rel9 = value;
282 }
283 break;
284 case FR30_OPERAND_M4 :
285 errmsg = cgen_parse_signed_integer (cd, strp, FR30_OPERAND_M4, &fields->f_m4);
286 break;
287 case FR30_OPERAND_PS :
eb1b03df 288 errmsg = cgen_parse_keyword (cd, strp, & fr30_cgen_opval_h_ps, & junk);
252b5132
RH
289 break;
290 case FR30_OPERAND_REGLIST_HI_LD :
291 errmsg = parse_hi_register_list_ld (cd, strp, FR30_OPERAND_REGLIST_HI_LD, &fields->f_reglist_hi_ld);
292 break;
293 case FR30_OPERAND_REGLIST_HI_ST :
294 errmsg = parse_hi_register_list_st (cd, strp, FR30_OPERAND_REGLIST_HI_ST, &fields->f_reglist_hi_st);
295 break;
296 case FR30_OPERAND_REGLIST_LOW_LD :
297 errmsg = parse_low_register_list_ld (cd, strp, FR30_OPERAND_REGLIST_LOW_LD, &fields->f_reglist_low_ld);
298 break;
299 case FR30_OPERAND_REGLIST_LOW_ST :
300 errmsg = parse_low_register_list_st (cd, strp, FR30_OPERAND_REGLIST_LOW_ST, &fields->f_reglist_low_st);
301 break;
302 case FR30_OPERAND_S10 :
303 errmsg = cgen_parse_signed_integer (cd, strp, FR30_OPERAND_S10, &fields->f_s10);
304 break;
305 case FR30_OPERAND_U10 :
306 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_U10, &fields->f_u10);
307 break;
308 case FR30_OPERAND_U4 :
309 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_U4, &fields->f_u4);
310 break;
311 case FR30_OPERAND_U4C :
312 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_U4C, &fields->f_u4c);
313 break;
314 case FR30_OPERAND_U8 :
315 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_U8, &fields->f_u8);
316 break;
317 case FR30_OPERAND_UDISP6 :
318 errmsg = cgen_parse_unsigned_integer (cd, strp, FR30_OPERAND_UDISP6, &fields->f_udisp6);
319 break;
320
321 default :
322 /* xgettext:c-format */
323 fprintf (stderr, _("Unrecognized field %d while parsing.\n"), opindex);
324 abort ();
325 }
326
327 return errmsg;
328}
329
330cgen_parse_fn * const fr30_cgen_parse_handlers[] =
331{
332 parse_insn_normal,
333};
334
335void
336fr30_cgen_init_asm (cd)
337 CGEN_CPU_DESC cd;
338{
339 fr30_cgen_init_opcode_table (cd);
340 fr30_cgen_init_ibld_table (cd);
341 cd->parse_handlers = & fr30_cgen_parse_handlers[0];
342 cd->parse_operand = fr30_cgen_parse_operand;
343}
344
fc7bc883
RH
345\f
346
37111cc7 347/* Regex construction routine.
fc7bc883 348
37111cc7
NC
349 This translates an opcode syntax string into a regex string,
350 by replacing any non-character syntax element (such as an
351 opcode) with the pattern '.*'
fc7bc883 352
37111cc7
NC
353 It then compiles the regex and stores it in the opcode, for
354 later use by fr30_cgen_assemble_insn
fc7bc883 355
37111cc7 356 Returns NULL for success, an error message for failure. */
fc7bc883
RH
357
358char *
359fr30_cgen_build_insn_regex (insn)
360 CGEN_INSN *insn;
361{
d5b2f4d6 362 CGEN_OPCODE *opc = (CGEN_OPCODE *) CGEN_INSN_OPCODE (insn);
fc7bc883 363 const char *mnem = CGEN_INSN_MNEMONIC (insn);
fc7bc883
RH
364 char rxbuf[CGEN_MAX_RX_ELEMENTS];
365 char *rx = rxbuf;
366 const CGEN_SYNTAX_CHAR_TYPE *syn;
367 int reg_err;
368
369 syn = CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc));
370
f3a55c17
NC
371 /* Mnemonics come first in the syntax string. */
372 if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
373 return _("missing mnemonic in syntax string");
fc7bc883
RH
374 ++syn;
375
f3a55c17
NC
376 /* Generate a case sensitive regular expression that emulates case
377 insensitive matching in the "C" locale. We cannot generate a case
378 insensitive regular expression because in Turkish locales, 'i' and 'I'
379 are not equal modulo case conversion. */
fc7bc883 380
f3a55c17
NC
381 /* Copy the literal mnemonic out of the insn. */
382 for (; *mnem; mnem++)
383 {
384 char c = *mnem;
385
386 if (ISALPHA (c))
387 {
388 *rx++ = '[';
389 *rx++ = TOLOWER (c);
390 *rx++ = TOUPPER (c);
391 *rx++ = ']';
392 }
393 else
394 *rx++ = c;
395 }
396
397 /* Copy any remaining literals from the syntax string into the rx. */
398 for(; * syn != 0 && rx <= rxbuf + (CGEN_MAX_RX_ELEMENTS - 7 - 4); ++syn)
fc7bc883
RH
399 {
400 if (CGEN_SYNTAX_CHAR_P (* syn))
401 {
f3a55c17
NC
402 char c = CGEN_SYNTAX_CHAR (* syn);
403
404 switch (c)
405 {
406 /* Escape any regex metacharacters in the syntax. */
407 case '.': case '[': case '\\':
408 case '*': case '^': case '$':
fc7bc883
RH
409
410#ifdef CGEN_ESCAPE_EXTENDED_REGEX
f3a55c17
NC
411 case '?': case '{': case '}':
412 case '(': case ')': case '*':
413 case '|': case '+': case ']':
fc7bc883 414#endif
f3a55c17
NC
415 *rx++ = '\\';
416 *rx++ = c;
417 break;
418
419 default:
420 if (ISALPHA (c))
421 {
422 *rx++ = '[';
423 *rx++ = TOLOWER (c);
424 *rx++ = TOUPPER (c);
425 *rx++ = ']';
426 }
427 else
428 *rx++ = c;
429 break;
430 }
fc7bc883
RH
431 }
432 else
433 {
f3a55c17
NC
434 /* Replace non-syntax fields with globs. */
435 *rx++ = '.';
436 *rx++ = '*';
fc7bc883
RH
437 }
438 }
439
f3a55c17 440 /* Trailing whitespace ok. */
fc7bc883
RH
441 * rx++ = '[';
442 * rx++ = ' ';
443 * rx++ = '\t';
444 * rx++ = ']';
445 * rx++ = '*';
446
f3a55c17 447 /* But anchor it after that. */
fc7bc883
RH
448 * rx++ = '$';
449 * rx = '\0';
450
451 CGEN_INSN_RX (insn) = xmalloc (sizeof (regex_t));
f3a55c17 452 reg_err = regcomp ((regex_t *) CGEN_INSN_RX (insn), rxbuf, REG_NOSUB);
fc7bc883
RH
453
454 if (reg_err == 0)
455 return NULL;
456 else
457 {
458 static char msg[80];
f3a55c17 459
fc7bc883
RH
460 regerror (reg_err, (regex_t *) CGEN_INSN_RX (insn), msg, 80);
461 regfree ((regex_t *) CGEN_INSN_RX (insn));
462 free (CGEN_INSN_RX (insn));
463 (CGEN_INSN_RX (insn)) = NULL;
37111cc7 464 return msg;
fc7bc883
RH
465 }
466}
467
252b5132
RH
468\f
469/* Default insn parser.
470
471 The syntax string is scanned and operands are parsed and stored in FIELDS.
472 Relocs are queued as we go via other callbacks.
473
474 ??? Note that this is currently an all-or-nothing parser. If we fail to
475 parse the instruction, we return 0 and the caller will start over from
476 the beginning. Backtracking will be necessary in parsing subexpressions,
477 but that can be handled there. Not handling backtracking here may get
478 expensive in the case of the m68k. Deal with later.
479
f3a55c17 480 Returns NULL for success, an error message for failure. */
252b5132
RH
481
482static const char *
483parse_insn_normal (cd, insn, strp, fields)
484 CGEN_CPU_DESC cd;
485 const CGEN_INSN *insn;
486 const char **strp;
487 CGEN_FIELDS *fields;
488{
489 /* ??? Runtime added insns not handled yet. */
490 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
491 const char *str = *strp;
492 const char *errmsg;
493 const char *p;
b3466c39 494 const CGEN_SYNTAX_CHAR_TYPE * syn;
252b5132
RH
495#ifdef CGEN_MNEMONIC_OPERANDS
496 /* FIXME: wip */
497 int past_opcode_p;
498#endif
499
500 /* For now we assume the mnemonic is first (there are no leading operands).
501 We can parse it without needing to set up operand parsing.
502 GAS's input scrubber will ensure mnemonics are lowercase, but we may
503 not be called from GAS. */
504 p = CGEN_INSN_MNEMONIC (insn);
37111cc7 505 while (*p && TOLOWER (*p) == TOLOWER (*str))
252b5132 506 ++p, ++str;
1fa60b5d
DE
507
508 if (* p)
509 return _("unrecognized instruction");
510
511#ifndef CGEN_MNEMONIC_OPERANDS
37111cc7 512 if (* str && ! ISSPACE (* str))
252b5132 513 return _("unrecognized instruction");
1fa60b5d 514#endif
252b5132
RH
515
516 CGEN_INIT_PARSE (cd);
517 cgen_init_parse_operand (cd);
518#ifdef CGEN_MNEMONIC_OPERANDS
519 past_opcode_p = 0;
520#endif
521
522 /* We don't check for (*str != '\0') here because we want to parse
523 any trailing fake arguments in the syntax string. */
524 syn = CGEN_SYNTAX_STRING (syntax);
525
526 /* Mnemonics come first for now, ensure valid string. */
527 if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
528 abort ();
529
530 ++syn;
531
532 while (* syn != 0)
533 {
534 /* Non operand chars must match exactly. */
535 if (CGEN_SYNTAX_CHAR_P (* syn))
536 {
1fa60b5d
DE
537 /* FIXME: While we allow for non-GAS callers above, we assume the
538 first char after the mnemonic part is a space. */
539 /* FIXME: We also take inappropriate advantage of the fact that
540 GAS's input scrubber will remove extraneous blanks. */
37111cc7 541 if (TOLOWER (*str) == TOLOWER (CGEN_SYNTAX_CHAR (* syn)))
252b5132
RH
542 {
543#ifdef CGEN_MNEMONIC_OPERANDS
b3466c39 544 if (CGEN_SYNTAX_CHAR(* syn) == ' ')
252b5132
RH
545 past_opcode_p = 1;
546#endif
547 ++ syn;
548 ++ str;
549 }
b3466c39 550 else if (*str)
252b5132
RH
551 {
552 /* Syntax char didn't match. Can't be this insn. */
6bb95a0f 553 static char msg [80];
f3a55c17 554
6bb95a0f
DB
555 /* xgettext:c-format */
556 sprintf (msg, _("syntax error (expected char `%c', found `%c')"),
b3466c39
DB
557 CGEN_SYNTAX_CHAR(*syn), *str);
558 return msg;
559 }
560 else
561 {
562 /* Ran out of input. */
563 static char msg [80];
f3a55c17 564
b3466c39
DB
565 /* xgettext:c-format */
566 sprintf (msg, _("syntax error (expected char `%c', found end of instruction)"),
567 CGEN_SYNTAX_CHAR(*syn));
6bb95a0f 568 return msg;
252b5132
RH
569 }
570 continue;
571 }
572
573 /* We have an operand of some sort. */
a978a3e5 574 errmsg = cd->parse_operand (cd, CGEN_SYNTAX_FIELD (*syn),
252b5132
RH
575 &str, fields);
576 if (errmsg)
577 return errmsg;
578
579 /* Done with this operand, continue with next one. */
580 ++ syn;
581 }
582
583 /* If we're at the end of the syntax string, we're done. */
b3466c39 584 if (* syn == 0)
252b5132
RH
585 {
586 /* FIXME: For the moment we assume a valid `str' can only contain
587 blanks now. IE: We needn't try again with a longer version of
588 the insn and it is assumed that longer versions of insns appear
589 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
37111cc7 590 while (ISSPACE (* str))
252b5132
RH
591 ++ str;
592
593 if (* str != '\0')
594 return _("junk at end of line"); /* FIXME: would like to include `str' */
595
596 return NULL;
597 }
598
599 /* We couldn't parse it. */
600 return _("unrecognized instruction");
601}
602\f
603/* Main entry point.
604 This routine is called for each instruction to be assembled.
605 STR points to the insn to be assembled.
606 We assume all necessary tables have been initialized.
607 The assembled instruction, less any fixups, is stored in BUF.
608 Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
609 still needs to be converted to target byte order, otherwise BUF is an array
610 of bytes in target byte order.
611 The result is a pointer to the insn's entry in the opcode table,
612 or NULL if an error occured (an error message will have already been
613 printed).
614
615 Note that when processing (non-alias) macro-insns,
616 this function recurses.
617
618 ??? It's possible to make this cpu-independent.
619 One would have to deal with a few minor things.
620 At this point in time doing so would be more of a curiosity than useful
621 [for example this file isn't _that_ big], but keeping the possibility in
622 mind helps keep the design clean. */
623
624const CGEN_INSN *
625fr30_cgen_assemble_insn (cd, str, fields, buf, errmsg)
626 CGEN_CPU_DESC cd;
627 const char *str;
628 CGEN_FIELDS *fields;
629 CGEN_INSN_BYTES_PTR buf;
630 char **errmsg;
631{
632 const char *start;
633 CGEN_INSN_LIST *ilist;
b3466c39
DB
634 const char *parse_errmsg = NULL;
635 const char *insert_errmsg = NULL;
fc7bc883 636 int recognized_mnemonic = 0;
252b5132
RH
637
638 /* Skip leading white space. */
37111cc7 639 while (ISSPACE (* str))
252b5132
RH
640 ++ str;
641
642 /* The instructions are stored in hashed lists.
643 Get the first in the list. */
644 ilist = CGEN_ASM_LOOKUP_INSN (cd, str);
645
646 /* Keep looking until we find a match. */
252b5132
RH
647 start = str;
648 for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist))
649 {
650 const CGEN_INSN *insn = ilist->insn;
fc7bc883 651 recognized_mnemonic = 1;
252b5132 652
6bb95a0f 653#ifdef CGEN_VALIDATE_INSN_SUPPORTED
f3a55c17
NC
654 /* Not usually needed as unsupported opcodes
655 shouldn't be in the hash lists. */
252b5132
RH
656 /* Is this insn supported by the selected cpu? */
657 if (! fr30_cgen_insn_supported (cd, insn))
658 continue;
659#endif
b11dcf4e 660 /* If the RELAXED attribute is set, this is an insn that shouldn't be
252b5132
RH
661 chosen immediately. Instead, it is used during assembler/linker
662 relaxation if possible. */
b11dcf4e 663 if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXED) != 0)
252b5132
RH
664 continue;
665
666 str = start;
667
f3a55c17 668 /* Skip this insn if str doesn't look right lexically. */
fc7bc883
RH
669 if (CGEN_INSN_RX (insn) != NULL &&
670 regexec ((regex_t *) CGEN_INSN_RX (insn), str, 0, NULL, 0) == REG_NOMATCH)
671 continue;
672
252b5132
RH
673 /* Allow parse/insert handlers to obtain length of insn. */
674 CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
675
b3466c39
DB
676 parse_errmsg = CGEN_PARSE_FN (cd, insn) (cd, insn, & str, fields);
677 if (parse_errmsg != NULL)
6bb95a0f 678 continue;
252b5132 679
f3a55c17 680 /* ??? 0 is passed for `pc'. */
b3466c39
DB
681 insert_errmsg = CGEN_INSERT_FN (cd, insn) (cd, insn, fields, buf,
682 (bfd_vma) 0);
683 if (insert_errmsg != NULL)
6bb95a0f
DB
684 continue;
685
686 /* It is up to the caller to actually output the insn and any
687 queued relocs. */
688 return insn;
252b5132
RH
689 }
690
252b5132 691 {
6bb95a0f 692 static char errbuf[150];
fc7bc883 693#ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
b3466c39 694 const char *tmp_errmsg;
6bb95a0f 695
b3466c39 696 /* If requesting verbose error messages, use insert_errmsg.
f3a55c17 697 Failing that, use parse_errmsg. */
b3466c39
DB
698 tmp_errmsg = (insert_errmsg ? insert_errmsg :
699 parse_errmsg ? parse_errmsg :
f3a55c17
NC
700 recognized_mnemonic ?
701 _("unrecognized form of instruction") :
b3466c39
DB
702 _("unrecognized instruction"));
703
6bb95a0f
DB
704 if (strlen (start) > 50)
705 /* xgettext:c-format */
706 sprintf (errbuf, "%s `%.50s...'", tmp_errmsg, start);
707 else
708 /* xgettext:c-format */
709 sprintf (errbuf, "%s `%.50s'", tmp_errmsg, start);
710#else
252b5132
RH
711 if (strlen (start) > 50)
712 /* xgettext:c-format */
713 sprintf (errbuf, _("bad instruction `%.50s...'"), start);
714 else
715 /* xgettext:c-format */
716 sprintf (errbuf, _("bad instruction `%.50s'"), start);
6bb95a0f 717#endif
252b5132
RH
718
719 *errmsg = errbuf;
720 return NULL;
721 }
722}
723\f
724#if 0 /* This calls back to GAS which we can't do without care. */
725
726/* Record each member of OPVALS in the assembler's symbol table.
727 This lets GAS parse registers for us.
728 ??? Interesting idea but not currently used. */
729
730/* Record each member of OPVALS in the assembler's symbol table.
731 FIXME: Not currently used. */
732
733void
734fr30_cgen_asm_hash_keywords (cd, opvals)
735 CGEN_CPU_DESC cd;
736 CGEN_KEYWORD *opvals;
737{
738 CGEN_KEYWORD_SEARCH search = cgen_keyword_search_init (opvals, NULL);
739 const CGEN_KEYWORD_ENTRY * ke;
740
741 while ((ke = cgen_keyword_search_next (& search)) != NULL)
742 {
743#if 0 /* Unnecessary, should be done in the search routine. */
744 if (! fr30_cgen_opval_supported (ke))
745 continue;
746#endif
747 cgen_asm_record_register (cd, ke->name, ke->value);
748 }
749}
750
751#endif /* 0 */
This page took 0.204619 seconds and 4 git commands to generate.