1 /* Assembler interface for targets using CGEN. -*- C -*-
2 CGEN: Cpu tools GENerator
4 THIS FILE IS MACHINE GENERATED WITH CGEN.
5 - the resultant file is machine generated, cgen-asm.in isn't
7 Copyright (C) 1996-2016 Free Software Foundation, Inc.
9 This file is part of libopcodes.
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)
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.
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. */
26 /* ??? Eventually more and more of this stuff can go to cpu-independent files.
38 #include "libiberty.h"
39 #include "safe-ctype.h"
42 #define min(a,b) ((a) < (b) ? (a) : (b))
44 #define max(a,b) ((a) > (b) ? (a) : (b))
46 static const char * parse_insn_normal
47 (CGEN_CPU_DESC, const CGEN_INSN *, const char **, CGEN_FIELDS *);
49 /* -- assembler routines inserted here. */
55 #define CGEN_VALIDATE_INSN_SUPPORTED
56 #define mep_cgen_insn_supported mep_cgen_insn_supported_asm
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 *);
72 parse_csrn (CGEN_CPU_DESC cd, const char **strp,
73 CGEN_KEYWORD *keyword_table, long *field)
78 err = cgen_parse_keyword (cd, strp, keyword_table, field);
82 err = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_CSRN_IDX, & value);
89 /* begin-cop-ip-parse-handlers */
91 parse_ivc2_cr (CGEN_CPU_DESC,
94 long *) ATTRIBUTE_UNUSED;
96 parse_ivc2_cr (CGEN_CPU_DESC cd,
98 CGEN_KEYWORD *keyword_table ATTRIBUTE_UNUSED,
101 return cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr_ivc2, field);
104 parse_ivc2_ccr (CGEN_CPU_DESC,
107 long *) ATTRIBUTE_UNUSED;
109 parse_ivc2_ccr (CGEN_CPU_DESC cd,
111 CGEN_KEYWORD *keyword_table ATTRIBUTE_UNUSED,
114 return cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, field);
116 /* end-cop-ip-parse-handlers */
119 parse_tpreg (CGEN_CPU_DESC cd, const char ** strp,
120 CGEN_KEYWORD *keyword_table, long *field)
124 err = cgen_parse_keyword (cd, strp, keyword_table, field);
128 return _("Only $tp or $13 allowed for this opcode");
133 parse_spreg (CGEN_CPU_DESC cd, const char ** strp,
134 CGEN_KEYWORD *keyword_table, long *field)
138 err = cgen_parse_keyword (cd, strp, keyword_table, field);
142 return _("Only $sp or $15 allowed for this opcode");
147 parse_mep_align (CGEN_CPU_DESC cd, const char ** strp,
148 enum cgen_operand_type type, long *field)
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);
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);
176 case MEP_OPERAND_UDISP7:
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:
187 case MEP_OPERAND_UDISP7A4:
188 case MEP_OPERAND_UIMM7A4:
189 case MEP_OPERAND_ADDR24A4:
195 /* Safe assumption? */
199 return "Value is not aligned enough";
204 parse_mep_alignu (CGEN_CPU_DESC cd, const char ** strp,
205 enum cgen_operand_type type, unsigned long *field)
207 return parse_mep_align (cd, strp, type, (long *) field);
211 /* Handle %lo(), %tpoff(), %sdaoff(), %hi(), and other signed
212 constants in a signed context. */
215 parse_signed16 (CGEN_CPU_DESC cd,
220 return parse_lo16 (cd, strp, opindex, valuep, 1);
224 parse_lo16 (CGEN_CPU_DESC cd,
231 enum cgen_parse_operand_result result_type;
234 if (strncasecmp (*strp, "%lo(", 4) == 0)
237 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_LOW16,
238 & result_type, & value);
240 return _("missing `)'");
243 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
246 *valuep = (long)(short) value;
252 if (strncasecmp (*strp, "%hi(", 4) == 0)
255 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_HI16S,
256 & result_type, & value);
258 return _("missing `)'");
261 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
262 value = (value + 0x8000) >> 16;
267 if (strncasecmp (*strp, "%uhi(", 5) == 0)
270 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_HI16U,
271 & result_type, & value);
273 return _("missing `)'");
276 && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
282 if (strncasecmp (*strp, "%sdaoff(", 8) == 0)
285 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_GPREL,
288 return _("missing `)'");
294 if (strncasecmp (*strp, "%tpoff(", 7) == 0)
297 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_TPREL,
300 return _("missing `)'");
307 return _("invalid %function() here");
309 return cgen_parse_signed_integer (cd, strp, opindex, valuep);
313 parse_unsigned16 (CGEN_CPU_DESC cd,
316 unsigned long *valuep)
318 return parse_lo16 (cd, strp, opindex, (long *) valuep, 0);
322 parse_signed16_range (CGEN_CPU_DESC cd,
327 const char *errmsg = 0;
330 errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value);
334 if (value < -32768 || value > 32767)
335 return _("Immediate is out of range -32768 to 32767");
342 parse_unsigned16_range (CGEN_CPU_DESC cd,
345 unsigned long *valuep)
347 const char *errmsg = 0;
350 errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, & value);
355 return _("Immediate is out of range 0 to 65535");
361 /* A special case of parse_signed16 which accepts only the value zero. */
364 parse_zero (CGEN_CPU_DESC cd, const char **strp, int opindex, long *valuep)
367 enum cgen_parse_operand_result result_type;
370 /*fprintf(stderr, "dj: signed parse opindex `%s'\n", *strp);*/
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
375 if (strncmp (*strp, "($", 2) == 0)
376 return "not zero"; /* any string will do -- will never be seen. */
378 if (strncasecmp (*strp, "%lo(", 4) == 0)
381 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_LOW16,
382 &result_type, &value);
384 return "missing `)'";
387 && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
388 return "not zero"; /* any string will do -- will never be seen. */
393 if (strncasecmp (*strp, "%hi(", 4) == 0)
396 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_HI16S,
397 &result_type, &value);
399 return "missing `)'";
402 && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
403 return "not zero"; /* any string will do -- will never be seen. */
408 if (strncasecmp (*strp, "%uhi(", 5) == 0)
411 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_HI16U,
412 &result_type, &value);
414 return "missing `)'";
417 && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
418 return "not zero"; /* any string will do -- will never be seen. */
423 if (strncasecmp (*strp, "%sdaoff(", 8) == 0)
426 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_GPREL,
427 &result_type, &value);
429 return "missing `)'";
432 && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
433 return "not zero"; /* any string will do -- will never be seen. */
438 if (strncasecmp (*strp, "%tpoff(", 7) == 0)
441 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_MEP_TPREL,
442 &result_type, &value);
444 return "missing `)'";
447 && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
448 return "not zero"; /* any string will do -- will never be seen. */
454 return "invalid %function() here";
456 errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_NONE,
457 &result_type, &value);
459 && (result_type != CGEN_PARSE_OPERAND_RESULT_NUMBER || value != 0))
460 return "not zero"; /* any string will do -- will never be seen. */
466 parse_unsigned7 (CGEN_CPU_DESC cd, const char **strp,
467 enum cgen_operand_type opindex, unsigned long *valuep)
472 /* fprintf(stderr, "dj: unsigned7 parse `%s'\n", *strp); */
474 if (strncasecmp (*strp, "%tpoff(", 7) == 0)
480 case MEP_OPERAND_UDISP7:
481 reloc = BFD_RELOC_MEP_TPREL7;
483 case MEP_OPERAND_UDISP7A2:
484 reloc = BFD_RELOC_MEP_TPREL7A2;
486 case MEP_OPERAND_UDISP7A4:
487 reloc = BFD_RELOC_MEP_TPREL7A4;
490 /* Safe assumption? */
493 errmsg = cgen_parse_address (cd, strp, opindex, reloc,
496 return "missing `)'";
503 return _("invalid %function() here");
505 return parse_mep_alignu (cd, strp, opindex, valuep);
508 static ATTRIBUTE_UNUSED const char *
509 parse_cdisp10 (CGEN_CPU_DESC cd,
514 const char *errmsg = 0;
522 case MEP_OPERAND_CDISP10A4:
525 case MEP_OPERAND_CDISP10A2:
528 case MEP_OPERAND_CDISP10:
534 if ((MEP_CPU & EF_MEP_CPU_MASK) == EF_MEP_CPU_C5)
537 if (strncmp (*strp, "0x0", 3) == 0
538 || (**strp == '0' && *(*strp + 1) != 'x'))
541 errmsg = cgen_parse_signed_integer (cd, strp, opindex, & value);
547 if (value < -512 || value > 511)
548 return _("Immediate is out of range -512 to 511");
552 if (value < -128 || value > 127)
553 return _("Immediate is out of range -128 to 127");
556 if (value & ((1<<alignment)-1))
557 return _("Value is not aligned enough");
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"));
568 /* BEGIN LIGHTWEIGHT MACRO PROCESSOR. */
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)"}, */
596 static char * expand_string (const char *, int);
599 mep_cgen_expand_macros_and_parse_operand
600 (CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *);
603 str_append (char *dest, const char *input, int len)
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);
618 lookup_macro (const char *name)
622 for (m = macros; m->name; ++m)
623 if (strncmp (m->name, name, strlen(m->name)) == 0)
630 expand_macro (arg *args, int narg, macro *mac)
632 char *result = 0, *rescanned_result = 0;
633 char *e = mac->expansion;
637 /* printf("expanding macro %s with %d args\n", mac->name, narg + 1); */
642 ((*(e + 1) - '1') <= MAXARGS) &&
643 ((*(e + 1) - '1') <= narg))
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);
656 result = str_append (result, mark, e - mark);
660 rescanned_result = expand_string (result, 0);
662 return rescanned_result;
672 expand_string (const char *in, int first_only)
674 int num_expansions = 0;
679 const char *mark = in;
680 macro *pmacro = NULL;
689 if (*in == '%' && *(in + 1) && (!first_only || num_expansions == 0))
691 pmacro = lookup_macro (in + 1);
694 /* printf("entering state %d at '%s'...\n", state, in); */
695 result = str_append (result, mark, in - mark);
697 in += 1 + strlen (pmacro->name);
698 while (*in == ' ') ++in;
708 args[narg].start = in + 1;
722 args[narg].start = (in + 1);
727 /* printf("entering state %d at '%s'...\n", state, in); */
731 expansion = expand_macro (args, narg, pmacro);
735 result = str_append (result, expansion, strlen (expansion));
741 result = str_append (result, mark, in - mark);
767 result = str_append (result, mark, in - mark);
777 /* END LIGHTWEIGHT MACRO PROCESSOR. */
779 const char * mep_cgen_parse_operand
780 (CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *);
783 mep_cgen_expand_macros_and_parse_operand (CGEN_CPU_DESC cd, int opindex,
784 const char ** strp_in, CGEN_FIELDS * fields)
786 const char * errmsg = NULL;
787 char *str = 0, *hold = 0;
788 const char **strp = 0;
790 /* Set up a new pointer to macro-expanded string. */
791 str = expand_string (*strp_in, 1);
792 /* fprintf (stderr, " expanded <<%s>> to <<%s>>\n", *strp_in, str); */
795 strp = (const char **)(&str);
797 errmsg = mep_cgen_parse_operand (cd, opindex, strp, fields);
799 /* Now work out the advance. */
800 if (strlen (str) == 0)
801 *strp_in += strlen (*strp_in);
805 if (strstr (*strp_in, str))
806 /* A macro-expansion was pulled off the front. */
807 *strp_in = strstr (*strp_in, str);
809 /* A non-macro-expansion was pulled off the front. */
810 *strp_in += (str - hold);
819 #define CGEN_ASM_INIT_HOOK (cd->parse_operand = mep_cgen_expand_macros_and_parse_operand);
823 const char * mep_cgen_parse_operand
824 (CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *);
826 /* Main entry point for operand parsing.
828 This function is basically just a big switch statement. Earlier versions
829 used tables to look up the function to use, but
830 - if the table contains both assembler and disassembler functions then
831 the disassembler contains much of the assembler and vice-versa,
832 - there's a lot of inlining possibilities as things grow,
833 - using a switch statement avoids the function call overhead.
835 This function could be moved into `parse_insn_normal', but keeping it
836 separate makes clear the interface between `parse_insn_normal' and each of
840 mep_cgen_parse_operand (CGEN_CPU_DESC cd,
843 CGEN_FIELDS * fields)
845 const char * errmsg = NULL;
846 /* Used by scalar operands that still need to be parsed. */
847 long junk ATTRIBUTE_UNUSED;
851 case MEP_OPERAND_ADDR24A4 :
852 errmsg = parse_mep_alignu (cd, strp, MEP_OPERAND_ADDR24A4, (unsigned long *) (& fields->f_24u8a4n));
854 case MEP_OPERAND_C5RMUIMM20 :
855 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_C5RMUIMM20, (unsigned long *) (& fields->f_c5_rmuimm20));
857 case MEP_OPERAND_C5RNMUIMM24 :
858 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_C5RNMUIMM24, (unsigned long *) (& fields->f_c5_rnmuimm24));
860 case MEP_OPERAND_CALLNUM :
861 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_CALLNUM, (unsigned long *) (& fields->f_callnum));
863 case MEP_OPERAND_CCCC :
864 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_CCCC, (unsigned long *) (& fields->f_rm));
866 case MEP_OPERAND_CCRN :
867 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr, & fields->f_ccrn);
869 case MEP_OPERAND_CDISP10 :
870 errmsg = parse_cdisp10 (cd, strp, MEP_OPERAND_CDISP10, (long *) (& fields->f_cdisp10));
872 case MEP_OPERAND_CDISP10A2 :
873 errmsg = parse_cdisp10 (cd, strp, MEP_OPERAND_CDISP10A2, (long *) (& fields->f_cdisp10));
875 case MEP_OPERAND_CDISP10A4 :
876 errmsg = parse_cdisp10 (cd, strp, MEP_OPERAND_CDISP10A4, (long *) (& fields->f_cdisp10));
878 case MEP_OPERAND_CDISP10A8 :
879 errmsg = parse_cdisp10 (cd, strp, MEP_OPERAND_CDISP10A8, (long *) (& fields->f_cdisp10));
881 case MEP_OPERAND_CDISP12 :
882 errmsg = cgen_parse_signed_integer (cd, strp, MEP_OPERAND_CDISP12, (long *) (& fields->f_12s20));
884 case MEP_OPERAND_CIMM4 :
885 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_CIMM4, (unsigned long *) (& fields->f_rn));
887 case MEP_OPERAND_CIMM5 :
888 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_CIMM5, (unsigned long *) (& fields->f_5u24));
890 case MEP_OPERAND_CODE16 :
891 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_CODE16, (unsigned long *) (& fields->f_16u16));
893 case MEP_OPERAND_CODE24 :
894 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_CODE24, (unsigned long *) (& fields->f_24u4n));
896 case MEP_OPERAND_CP_FLAG :
897 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr, & junk);
899 case MEP_OPERAND_CRN :
900 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr, & fields->f_crn);
902 case MEP_OPERAND_CRN64 :
903 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr64, & fields->f_crn);
905 case MEP_OPERAND_CRNX :
906 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr, & fields->f_crnx);
908 case MEP_OPERAND_CRNX64 :
909 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr64, & fields->f_crnx);
911 case MEP_OPERAND_CROC :
912 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr64, & fields->f_ivc2_5u7);
914 case MEP_OPERAND_CROP :
915 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr64, & fields->f_ivc2_5u23);
917 case MEP_OPERAND_CRPC :
918 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr64, & fields->f_ivc2_5u26);
920 case MEP_OPERAND_CRPP :
921 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr64, & fields->f_ivc2_5u18);
923 case MEP_OPERAND_CRQC :
924 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr64, & fields->f_ivc2_5u21);
926 case MEP_OPERAND_CRQP :
927 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr64, & fields->f_ivc2_5u13);
929 case MEP_OPERAND_CSRN :
930 errmsg = parse_csrn (cd, strp, & mep_cgen_opval_h_csr, & fields->f_csrn);
932 case MEP_OPERAND_CSRN_IDX :
933 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_CSRN_IDX, (unsigned long *) (& fields->f_csrn));
935 case MEP_OPERAND_DBG :
936 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
938 case MEP_OPERAND_DEPC :
939 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
941 case MEP_OPERAND_EPC :
942 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
944 case MEP_OPERAND_EXC :
945 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
947 case MEP_OPERAND_HI :
948 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
950 case MEP_OPERAND_IMM16P0 :
951 errmsg = parse_unsigned16_range (cd, strp, MEP_OPERAND_IMM16P0, (unsigned long *) (& fields->f_ivc2_imm16p0));
953 case MEP_OPERAND_IMM3P12 :
954 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM3P12, (unsigned long *) (& fields->f_ivc2_3u12));
956 case MEP_OPERAND_IMM3P25 :
957 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM3P25, (unsigned long *) (& fields->f_ivc2_3u25));
959 case MEP_OPERAND_IMM3P4 :
960 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM3P4, (unsigned long *) (& fields->f_ivc2_3u4));
962 case MEP_OPERAND_IMM3P5 :
963 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM3P5, (unsigned long *) (& fields->f_ivc2_3u5));
965 case MEP_OPERAND_IMM3P9 :
966 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM3P9, (unsigned long *) (& fields->f_ivc2_3u9));
968 case MEP_OPERAND_IMM4P10 :
969 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM4P10, (unsigned long *) (& fields->f_ivc2_4u10));
971 case MEP_OPERAND_IMM4P4 :
972 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM4P4, (unsigned long *) (& fields->f_ivc2_4u4));
974 case MEP_OPERAND_IMM4P8 :
975 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM4P8, (unsigned long *) (& fields->f_ivc2_4u8));
977 case MEP_OPERAND_IMM5P23 :
978 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM5P23, (unsigned long *) (& fields->f_ivc2_5u23));
980 case MEP_OPERAND_IMM5P3 :
981 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM5P3, (unsigned long *) (& fields->f_ivc2_5u3));
983 case MEP_OPERAND_IMM5P7 :
984 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM5P7, (unsigned long *) (& fields->f_ivc2_5u7));
986 case MEP_OPERAND_IMM5P8 :
987 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM5P8, (unsigned long *) (& fields->f_ivc2_5u8));
989 case MEP_OPERAND_IMM6P2 :
990 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM6P2, (unsigned long *) (& fields->f_ivc2_6u2));
992 case MEP_OPERAND_IMM6P6 :
993 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM6P6, (unsigned long *) (& fields->f_ivc2_6u6));
995 case MEP_OPERAND_IMM8P0 :
996 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM8P0, (unsigned long *) (& fields->f_ivc2_8u0));
998 case MEP_OPERAND_IMM8P20 :
999 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM8P20, (unsigned long *) (& fields->f_ivc2_8u20));
1001 case MEP_OPERAND_IMM8P4 :
1002 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IMM8P4, (unsigned long *) (& fields->f_ivc2_8u4));
1004 case MEP_OPERAND_IVC_X_0_2 :
1005 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IVC_X_0_2, (unsigned long *) (& fields->f_ivc2_2u0));
1007 case MEP_OPERAND_IVC_X_0_3 :
1008 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IVC_X_0_3, (unsigned long *) (& fields->f_ivc2_3u0));
1010 case MEP_OPERAND_IVC_X_0_4 :
1011 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IVC_X_0_4, (unsigned long *) (& fields->f_ivc2_4u0));
1013 case MEP_OPERAND_IVC_X_0_5 :
1014 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IVC_X_0_5, (unsigned long *) (& fields->f_ivc2_5u0));
1016 case MEP_OPERAND_IVC_X_6_1 :
1017 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IVC_X_6_1, (unsigned long *) (& fields->f_ivc2_1u6));
1019 case MEP_OPERAND_IVC_X_6_2 :
1020 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IVC_X_6_2, (unsigned long *) (& fields->f_ivc2_2u6));
1022 case MEP_OPERAND_IVC_X_6_3 :
1023 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_IVC_X_6_3, (unsigned long *) (& fields->f_ivc2_3u6));
1025 case MEP_OPERAND_IVC2_ACC0_0 :
1026 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1028 case MEP_OPERAND_IVC2_ACC0_1 :
1029 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1031 case MEP_OPERAND_IVC2_ACC0_2 :
1032 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1034 case MEP_OPERAND_IVC2_ACC0_3 :
1035 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1037 case MEP_OPERAND_IVC2_ACC0_4 :
1038 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1040 case MEP_OPERAND_IVC2_ACC0_5 :
1041 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1043 case MEP_OPERAND_IVC2_ACC0_6 :
1044 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1046 case MEP_OPERAND_IVC2_ACC0_7 :
1047 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1049 case MEP_OPERAND_IVC2_ACC1_0 :
1050 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1052 case MEP_OPERAND_IVC2_ACC1_1 :
1053 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1055 case MEP_OPERAND_IVC2_ACC1_2 :
1056 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1058 case MEP_OPERAND_IVC2_ACC1_3 :
1059 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1061 case MEP_OPERAND_IVC2_ACC1_4 :
1062 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1064 case MEP_OPERAND_IVC2_ACC1_5 :
1065 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1067 case MEP_OPERAND_IVC2_ACC1_6 :
1068 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1070 case MEP_OPERAND_IVC2_ACC1_7 :
1071 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1073 case MEP_OPERAND_IVC2_CC :
1074 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1076 case MEP_OPERAND_IVC2_COFA0 :
1077 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1079 case MEP_OPERAND_IVC2_COFA1 :
1080 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1082 case MEP_OPERAND_IVC2_COFR0 :
1083 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1085 case MEP_OPERAND_IVC2_COFR1 :
1086 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1088 case MEP_OPERAND_IVC2_CSAR0 :
1089 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1091 case MEP_OPERAND_IVC2_CSAR1 :
1092 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & junk);
1094 case MEP_OPERAND_IVC2C3CCRN :
1095 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & fields->f_ivc2_ccrn_c3);
1097 case MEP_OPERAND_IVC2CCRN :
1098 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_ccr_ivc2, & fields->f_ivc2_ccrn);
1100 case MEP_OPERAND_IVC2CRN :
1101 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_cr64, & fields->f_ivc2_crnx);
1103 case MEP_OPERAND_IVC2RM :
1104 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_ivc2_crm);
1106 case MEP_OPERAND_LO :
1107 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
1109 case MEP_OPERAND_LP :
1110 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
1112 case MEP_OPERAND_MB0 :
1113 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
1115 case MEP_OPERAND_MB1 :
1116 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
1118 case MEP_OPERAND_ME0 :
1119 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
1121 case MEP_OPERAND_ME1 :
1122 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
1124 case MEP_OPERAND_NPC :
1125 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
1127 case MEP_OPERAND_OPT :
1128 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
1130 case MEP_OPERAND_PCABS24A2 :
1131 errmsg = parse_mep_alignu (cd, strp, MEP_OPERAND_PCABS24A2, (unsigned long *) (& fields->f_24u5a2n));
1133 case MEP_OPERAND_PCREL12A2 :
1134 errmsg = parse_mep_align (cd, strp, MEP_OPERAND_PCREL12A2, (long *) (& fields->f_12s4a2));
1136 case MEP_OPERAND_PCREL17A2 :
1137 errmsg = parse_mep_align (cd, strp, MEP_OPERAND_PCREL17A2, (long *) (& fields->f_17s16a2));
1139 case MEP_OPERAND_PCREL24A2 :
1140 errmsg = parse_mep_align (cd, strp, MEP_OPERAND_PCREL24A2, (long *) (& fields->f_24s5a2n));
1142 case MEP_OPERAND_PCREL8A2 :
1143 errmsg = parse_mep_align (cd, strp, MEP_OPERAND_PCREL8A2, (long *) (& fields->f_8s8a2));
1145 case MEP_OPERAND_PSW :
1146 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
1148 case MEP_OPERAND_R0 :
1149 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & junk);
1151 case MEP_OPERAND_R1 :
1152 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & junk);
1154 case MEP_OPERAND_RL :
1155 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rl);
1157 case MEP_OPERAND_RL5 :
1158 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rl5);
1160 case MEP_OPERAND_RM :
1161 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rm);
1163 case MEP_OPERAND_RMA :
1164 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rm);
1166 case MEP_OPERAND_RN :
1167 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn);
1169 case MEP_OPERAND_RN3 :
1170 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn3);
1172 case MEP_OPERAND_RN3C :
1173 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn3);
1175 case MEP_OPERAND_RN3L :
1176 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn3);
1178 case MEP_OPERAND_RN3S :
1179 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn3);
1181 case MEP_OPERAND_RN3UC :
1182 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn3);
1184 case MEP_OPERAND_RN3UL :
1185 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn3);
1187 case MEP_OPERAND_RN3US :
1188 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn3);
1190 case MEP_OPERAND_RNC :
1191 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn);
1193 case MEP_OPERAND_RNL :
1194 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn);
1196 case MEP_OPERAND_RNS :
1197 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn);
1199 case MEP_OPERAND_RNUC :
1200 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn);
1202 case MEP_OPERAND_RNUL :
1203 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn);
1205 case MEP_OPERAND_RNUS :
1206 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & fields->f_rn);
1208 case MEP_OPERAND_SAR :
1209 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_csr, & junk);
1211 case MEP_OPERAND_SDISP16 :
1212 errmsg = parse_signed16 (cd, strp, MEP_OPERAND_SDISP16, (long *) (& fields->f_16s16));
1214 case MEP_OPERAND_SIMM16 :
1215 errmsg = parse_signed16 (cd, strp, MEP_OPERAND_SIMM16, (long *) (& fields->f_16s16));
1217 case MEP_OPERAND_SIMM16P0 :
1218 errmsg = parse_signed16_range (cd, strp, MEP_OPERAND_SIMM16P0, (long *) (& fields->f_ivc2_simm16p0));
1220 case MEP_OPERAND_SIMM6 :
1221 errmsg = cgen_parse_signed_integer (cd, strp, MEP_OPERAND_SIMM6, (long *) (& fields->f_6s8));
1223 case MEP_OPERAND_SIMM8 :
1224 errmsg = cgen_parse_signed_integer (cd, strp, MEP_OPERAND_SIMM8, (long *) (& fields->f_8s8));
1226 case MEP_OPERAND_SIMM8P0 :
1227 errmsg = cgen_parse_signed_integer (cd, strp, MEP_OPERAND_SIMM8P0, (long *) (& fields->f_ivc2_8s0));
1229 case MEP_OPERAND_SIMM8P20 :
1230 errmsg = cgen_parse_signed_integer (cd, strp, MEP_OPERAND_SIMM8P20, (long *) (& fields->f_ivc2_8s20));
1232 case MEP_OPERAND_SIMM8P4 :
1233 errmsg = cgen_parse_signed_integer (cd, strp, MEP_OPERAND_SIMM8P4, (long *) (& fields->f_ivc2_8s4));
1235 case MEP_OPERAND_SP :
1236 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & junk);
1238 case MEP_OPERAND_SPR :
1239 errmsg = parse_spreg (cd, strp, & mep_cgen_opval_h_gpr, & junk);
1241 case MEP_OPERAND_TP :
1242 errmsg = cgen_parse_keyword (cd, strp, & mep_cgen_opval_h_gpr, & junk);
1244 case MEP_OPERAND_TPR :
1245 errmsg = parse_tpreg (cd, strp, & mep_cgen_opval_h_gpr, & junk);
1247 case MEP_OPERAND_UDISP2 :
1248 errmsg = cgen_parse_signed_integer (cd, strp, MEP_OPERAND_UDISP2, (long *) (& fields->f_2u6));
1250 case MEP_OPERAND_UDISP7 :
1251 errmsg = parse_unsigned7 (cd, strp, MEP_OPERAND_UDISP7, (unsigned long *) (& fields->f_7u9));
1253 case MEP_OPERAND_UDISP7A2 :
1254 errmsg = parse_unsigned7 (cd, strp, MEP_OPERAND_UDISP7A2, (unsigned long *) (& fields->f_7u9a2));
1256 case MEP_OPERAND_UDISP7A4 :
1257 errmsg = parse_unsigned7 (cd, strp, MEP_OPERAND_UDISP7A4, (unsigned long *) (& fields->f_7u9a4));
1259 case MEP_OPERAND_UIMM16 :
1260 errmsg = parse_unsigned16 (cd, strp, MEP_OPERAND_UIMM16, (unsigned long *) (& fields->f_16u16));
1262 case MEP_OPERAND_UIMM2 :
1263 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_UIMM2, (unsigned long *) (& fields->f_2u10));
1265 case MEP_OPERAND_UIMM24 :
1266 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_UIMM24, (unsigned long *) (& fields->f_24u8n));
1268 case MEP_OPERAND_UIMM3 :
1269 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_UIMM3, (unsigned long *) (& fields->f_3u5));
1271 case MEP_OPERAND_UIMM4 :
1272 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_UIMM4, (unsigned long *) (& fields->f_4u8));
1274 case MEP_OPERAND_UIMM5 :
1275 errmsg = cgen_parse_unsigned_integer (cd, strp, MEP_OPERAND_UIMM5, (unsigned long *) (& fields->f_5u8));
1277 case MEP_OPERAND_UIMM7A4 :
1278 errmsg = parse_mep_alignu (cd, strp, MEP_OPERAND_UIMM7A4, (unsigned long *) (& fields->f_7u9a4));
1280 case MEP_OPERAND_ZERO :
1281 errmsg = parse_zero (cd, strp, MEP_OPERAND_ZERO, (long *) (& junk));
1285 /* xgettext:c-format */
1286 fprintf (stderr, _("Unrecognized field %d while parsing.\n"), opindex);
1293 cgen_parse_fn * const mep_cgen_parse_handlers[] =
1299 mep_cgen_init_asm (CGEN_CPU_DESC cd)
1301 mep_cgen_init_opcode_table (cd);
1302 mep_cgen_init_ibld_table (cd);
1303 cd->parse_handlers = & mep_cgen_parse_handlers[0];
1304 cd->parse_operand = mep_cgen_parse_operand;
1305 #ifdef CGEN_ASM_INIT_HOOK
1312 /* Regex construction routine.
1314 This translates an opcode syntax string into a regex string,
1315 by replacing any non-character syntax element (such as an
1316 opcode) with the pattern '.*'
1318 It then compiles the regex and stores it in the opcode, for
1319 later use by mep_cgen_assemble_insn
1321 Returns NULL for success, an error message for failure. */
1324 mep_cgen_build_insn_regex (CGEN_INSN *insn)
1326 CGEN_OPCODE *opc = (CGEN_OPCODE *) CGEN_INSN_OPCODE (insn);
1327 const char *mnem = CGEN_INSN_MNEMONIC (insn);
1328 char rxbuf[CGEN_MAX_RX_ELEMENTS];
1330 const CGEN_SYNTAX_CHAR_TYPE *syn;
1333 syn = CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc));
1335 /* Mnemonics come first in the syntax string. */
1336 if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
1337 return _("missing mnemonic in syntax string");
1340 /* Generate a case sensitive regular expression that emulates case
1341 insensitive matching in the "C" locale. We cannot generate a case
1342 insensitive regular expression because in Turkish locales, 'i' and 'I'
1343 are not equal modulo case conversion. */
1345 /* Copy the literal mnemonic out of the insn. */
1346 for (; *mnem; mnem++)
1353 *rx++ = TOLOWER (c);
1354 *rx++ = TOUPPER (c);
1361 /* Copy any remaining literals from the syntax string into the rx. */
1362 for(; * syn != 0 && rx <= rxbuf + (CGEN_MAX_RX_ELEMENTS - 7 - 4); ++syn)
1364 if (CGEN_SYNTAX_CHAR_P (* syn))
1366 char c = CGEN_SYNTAX_CHAR (* syn);
1370 /* Escape any regex metacharacters in the syntax. */
1371 case '.': case '[': case '\\':
1372 case '*': case '^': case '$':
1374 #ifdef CGEN_ESCAPE_EXTENDED_REGEX
1375 case '?': case '{': case '}':
1376 case '(': case ')': case '*':
1377 case '|': case '+': case ']':
1387 *rx++ = TOLOWER (c);
1388 *rx++ = TOUPPER (c);
1398 /* Replace non-syntax fields with globs. */
1404 /* Trailing whitespace ok. */
1411 /* But anchor it after that. */
1415 CGEN_INSN_RX (insn) = xmalloc (sizeof (regex_t));
1416 reg_err = regcomp ((regex_t *) CGEN_INSN_RX (insn), rxbuf, REG_NOSUB);
1422 static char msg[80];
1424 regerror (reg_err, (regex_t *) CGEN_INSN_RX (insn), msg, 80);
1425 regfree ((regex_t *) CGEN_INSN_RX (insn));
1426 free (CGEN_INSN_RX (insn));
1427 (CGEN_INSN_RX (insn)) = NULL;
1433 /* Default insn parser.
1435 The syntax string is scanned and operands are parsed and stored in FIELDS.
1436 Relocs are queued as we go via other callbacks.
1438 ??? Note that this is currently an all-or-nothing parser. If we fail to
1439 parse the instruction, we return 0 and the caller will start over from
1440 the beginning. Backtracking will be necessary in parsing subexpressions,
1441 but that can be handled there. Not handling backtracking here may get
1442 expensive in the case of the m68k. Deal with later.
1444 Returns NULL for success, an error message for failure. */
1447 parse_insn_normal (CGEN_CPU_DESC cd,
1448 const CGEN_INSN *insn,
1450 CGEN_FIELDS *fields)
1452 /* ??? Runtime added insns not handled yet. */
1453 const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
1454 const char *str = *strp;
1457 const CGEN_SYNTAX_CHAR_TYPE * syn;
1458 #ifdef CGEN_MNEMONIC_OPERANDS
1463 /* For now we assume the mnemonic is first (there are no leading operands).
1464 We can parse it without needing to set up operand parsing.
1465 GAS's input scrubber will ensure mnemonics are lowercase, but we may
1466 not be called from GAS. */
1467 p = CGEN_INSN_MNEMONIC (insn);
1468 while (*p && TOLOWER (*p) == TOLOWER (*str))
1472 return _("unrecognized instruction");
1474 #ifndef CGEN_MNEMONIC_OPERANDS
1475 if (* str && ! ISSPACE (* str))
1476 return _("unrecognized instruction");
1479 CGEN_INIT_PARSE (cd);
1480 cgen_init_parse_operand (cd);
1481 #ifdef CGEN_MNEMONIC_OPERANDS
1485 /* We don't check for (*str != '\0') here because we want to parse
1486 any trailing fake arguments in the syntax string. */
1487 syn = CGEN_SYNTAX_STRING (syntax);
1489 /* Mnemonics come first for now, ensure valid string. */
1490 if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
1497 /* Non operand chars must match exactly. */
1498 if (CGEN_SYNTAX_CHAR_P (* syn))
1500 /* FIXME: While we allow for non-GAS callers above, we assume the
1501 first char after the mnemonic part is a space. */
1502 /* FIXME: We also take inappropriate advantage of the fact that
1503 GAS's input scrubber will remove extraneous blanks. */
1504 if (TOLOWER (*str) == TOLOWER (CGEN_SYNTAX_CHAR (* syn)))
1506 #ifdef CGEN_MNEMONIC_OPERANDS
1507 if (CGEN_SYNTAX_CHAR(* syn) == ' ')
1515 /* Syntax char didn't match. Can't be this insn. */
1516 static char msg [80];
1518 /* xgettext:c-format */
1519 sprintf (msg, _("syntax error (expected char `%c', found `%c')"),
1520 CGEN_SYNTAX_CHAR(*syn), *str);
1525 /* Ran out of input. */
1526 static char msg [80];
1528 /* xgettext:c-format */
1529 sprintf (msg, _("syntax error (expected char `%c', found end of instruction)"),
1530 CGEN_SYNTAX_CHAR(*syn));
1536 #ifdef CGEN_MNEMONIC_OPERANDS
1537 (void) past_opcode_p;
1539 /* We have an operand of some sort. */
1540 errmsg = cd->parse_operand (cd, CGEN_SYNTAX_FIELD (*syn), &str, fields);
1544 /* Done with this operand, continue with next one. */
1548 /* If we're at the end of the syntax string, we're done. */
1551 /* FIXME: For the moment we assume a valid `str' can only contain
1552 blanks now. IE: We needn't try again with a longer version of
1553 the insn and it is assumed that longer versions of insns appear
1554 before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
1555 while (ISSPACE (* str))
1559 return _("junk at end of line"); /* FIXME: would like to include `str' */
1564 /* We couldn't parse it. */
1565 return _("unrecognized instruction");
1568 /* Main entry point.
1569 This routine is called for each instruction to be assembled.
1570 STR points to the insn to be assembled.
1571 We assume all necessary tables have been initialized.
1572 The assembled instruction, less any fixups, is stored in BUF.
1573 Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
1574 still needs to be converted to target byte order, otherwise BUF is an array
1575 of bytes in target byte order.
1576 The result is a pointer to the insn's entry in the opcode table,
1577 or NULL if an error occured (an error message will have already been
1580 Note that when processing (non-alias) macro-insns,
1581 this function recurses.
1583 ??? It's possible to make this cpu-independent.
1584 One would have to deal with a few minor things.
1585 At this point in time doing so would be more of a curiosity than useful
1586 [for example this file isn't _that_ big], but keeping the possibility in
1587 mind helps keep the design clean. */
1590 mep_cgen_assemble_insn (CGEN_CPU_DESC cd,
1592 CGEN_FIELDS *fields,
1593 CGEN_INSN_BYTES_PTR buf,
1597 CGEN_INSN_LIST *ilist;
1598 const char *parse_errmsg = NULL;
1599 const char *insert_errmsg = NULL;
1600 int recognized_mnemonic = 0;
1602 /* Skip leading white space. */
1603 while (ISSPACE (* str))
1606 /* The instructions are stored in hashed lists.
1607 Get the first in the list. */
1608 ilist = CGEN_ASM_LOOKUP_INSN (cd, str);
1610 /* Keep looking until we find a match. */
1612 for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist))
1614 const CGEN_INSN *insn = ilist->insn;
1615 recognized_mnemonic = 1;
1617 #ifdef CGEN_VALIDATE_INSN_SUPPORTED
1618 /* Not usually needed as unsupported opcodes
1619 shouldn't be in the hash lists. */
1620 /* Is this insn supported by the selected cpu? */
1621 if (! mep_cgen_insn_supported (cd, insn))
1624 /* If the RELAXED attribute is set, this is an insn that shouldn't be
1625 chosen immediately. Instead, it is used during assembler/linker
1626 relaxation if possible. */
1627 if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXED) != 0)
1632 /* Skip this insn if str doesn't look right lexically. */
1633 if (CGEN_INSN_RX (insn) != NULL &&
1634 regexec ((regex_t *) CGEN_INSN_RX (insn), str, 0, NULL, 0) == REG_NOMATCH)
1637 /* Allow parse/insert handlers to obtain length of insn. */
1638 CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
1640 parse_errmsg = CGEN_PARSE_FN (cd, insn) (cd, insn, & str, fields);
1641 if (parse_errmsg != NULL)
1644 /* ??? 0 is passed for `pc'. */
1645 insert_errmsg = CGEN_INSERT_FN (cd, insn) (cd, insn, fields, buf,
1647 if (insert_errmsg != NULL)
1650 /* It is up to the caller to actually output the insn and any
1656 static char errbuf[150];
1657 const char *tmp_errmsg;
1658 #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
1659 #define be_verbose 1
1661 #define be_verbose 0
1666 /* If requesting verbose error messages, use insert_errmsg.
1667 Failing that, use parse_errmsg. */
1668 tmp_errmsg = (insert_errmsg ? insert_errmsg :
1669 parse_errmsg ? parse_errmsg :
1670 recognized_mnemonic ?
1671 _("unrecognized form of instruction") :
1672 _("unrecognized instruction"));
1674 if (strlen (start) > 50)
1675 /* xgettext:c-format */
1676 sprintf (errbuf, "%s `%.50s...'", tmp_errmsg, start);
1678 /* xgettext:c-format */
1679 sprintf (errbuf, "%s `%.50s'", tmp_errmsg, start);
1683 if (strlen (start) > 50)
1684 /* xgettext:c-format */
1685 sprintf (errbuf, _("bad instruction `%.50s...'"), start);
1687 /* xgettext:c-format */
1688 sprintf (errbuf, _("bad instruction `%.50s'"), start);