1*3d8817e4Smiod /* Assembler interface for targets using CGEN. -*- C -*-
2*3d8817e4Smiod CGEN: Cpu tools GENerator
3*3d8817e4Smiod
4*3d8817e4Smiod THIS FILE IS MACHINE GENERATED WITH CGEN.
5*3d8817e4Smiod - the resultant file is machine generated, cgen-asm.in isn't
6*3d8817e4Smiod
7*3d8817e4Smiod Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2005
8*3d8817e4Smiod Free Software Foundation, Inc.
9*3d8817e4Smiod
10*3d8817e4Smiod This file is part of the GNU Binutils and GDB, the GNU debugger.
11*3d8817e4Smiod
12*3d8817e4Smiod This program is free software; you can redistribute it and/or modify
13*3d8817e4Smiod it under the terms of the GNU General Public License as published by
14*3d8817e4Smiod the Free Software Foundation; either version 2, or (at your option)
15*3d8817e4Smiod any later version.
16*3d8817e4Smiod
17*3d8817e4Smiod This program is distributed in the hope that it will be useful,
18*3d8817e4Smiod but WITHOUT ANY WARRANTY; without even the implied warranty of
19*3d8817e4Smiod MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20*3d8817e4Smiod GNU General Public License for more details.
21*3d8817e4Smiod
22*3d8817e4Smiod You should have received a copy of the GNU General Public License
23*3d8817e4Smiod along with this program; if not, write to the Free Software Foundation, Inc.,
24*3d8817e4Smiod 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
25*3d8817e4Smiod
26*3d8817e4Smiod /* ??? Eventually more and more of this stuff can go to cpu-independent files.
27*3d8817e4Smiod Keep that in mind. */
28*3d8817e4Smiod
29*3d8817e4Smiod #include "sysdep.h"
30*3d8817e4Smiod #include <stdio.h>
31*3d8817e4Smiod #include "ansidecl.h"
32*3d8817e4Smiod #include "bfd.h"
33*3d8817e4Smiod #include "symcat.h"
34*3d8817e4Smiod #include "xc16x-desc.h"
35*3d8817e4Smiod #include "xc16x-opc.h"
36*3d8817e4Smiod #include "opintl.h"
37*3d8817e4Smiod #include "xregex.h"
38*3d8817e4Smiod #include "libiberty.h"
39*3d8817e4Smiod #include "safe-ctype.h"
40*3d8817e4Smiod
41*3d8817e4Smiod #undef min
42*3d8817e4Smiod #define min(a,b) ((a) < (b) ? (a) : (b))
43*3d8817e4Smiod #undef max
44*3d8817e4Smiod #define max(a,b) ((a) > (b) ? (a) : (b))
45*3d8817e4Smiod
46*3d8817e4Smiod static const char * parse_insn_normal
47*3d8817e4Smiod (CGEN_CPU_DESC, const CGEN_INSN *, const char **, CGEN_FIELDS *);
48*3d8817e4Smiod
49*3d8817e4Smiod /* -- assembler routines inserted here. */
50*3d8817e4Smiod
51*3d8817e4Smiod /* -- asm.c */
52*3d8817e4Smiod /* Handle '#' prefixes (i.e. skip over them). */
53*3d8817e4Smiod
54*3d8817e4Smiod static const char *
parse_hash(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,const char ** strp,int opindex ATTRIBUTE_UNUSED,long * valuep ATTRIBUTE_UNUSED)55*3d8817e4Smiod parse_hash (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
56*3d8817e4Smiod const char **strp,
57*3d8817e4Smiod int opindex ATTRIBUTE_UNUSED,
58*3d8817e4Smiod long *valuep ATTRIBUTE_UNUSED)
59*3d8817e4Smiod {
60*3d8817e4Smiod if (**strp == '#')
61*3d8817e4Smiod {
62*3d8817e4Smiod ++*strp;
63*3d8817e4Smiod return NULL;
64*3d8817e4Smiod }
65*3d8817e4Smiod return _("Missing '#' prefix");
66*3d8817e4Smiod }
67*3d8817e4Smiod
68*3d8817e4Smiod /* Handle '.' prefixes (i.e. skip over them). */
69*3d8817e4Smiod
70*3d8817e4Smiod static const char *
parse_dot(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,const char ** strp,int opindex ATTRIBUTE_UNUSED,long * valuep ATTRIBUTE_UNUSED)71*3d8817e4Smiod parse_dot (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
72*3d8817e4Smiod const char **strp,
73*3d8817e4Smiod int opindex ATTRIBUTE_UNUSED,
74*3d8817e4Smiod long *valuep ATTRIBUTE_UNUSED)
75*3d8817e4Smiod {
76*3d8817e4Smiod if (**strp == '.')
77*3d8817e4Smiod {
78*3d8817e4Smiod ++*strp;
79*3d8817e4Smiod return NULL;
80*3d8817e4Smiod }
81*3d8817e4Smiod return _("Missing '.' prefix");
82*3d8817e4Smiod }
83*3d8817e4Smiod
84*3d8817e4Smiod /* Handle 'pof:' prefixes (i.e. skip over them). */
85*3d8817e4Smiod
86*3d8817e4Smiod static const char *
parse_pof(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,const char ** strp,int opindex ATTRIBUTE_UNUSED,long * valuep ATTRIBUTE_UNUSED)87*3d8817e4Smiod parse_pof (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
88*3d8817e4Smiod const char **strp,
89*3d8817e4Smiod int opindex ATTRIBUTE_UNUSED,
90*3d8817e4Smiod long *valuep ATTRIBUTE_UNUSED)
91*3d8817e4Smiod {
92*3d8817e4Smiod if (strncasecmp (*strp, "pof:", 4) == 0)
93*3d8817e4Smiod {
94*3d8817e4Smiod *strp += 4;
95*3d8817e4Smiod return NULL;
96*3d8817e4Smiod }
97*3d8817e4Smiod return _("Missing 'pof:' prefix");
98*3d8817e4Smiod }
99*3d8817e4Smiod
100*3d8817e4Smiod /* Handle 'pag:' prefixes (i.e. skip over them). */
101*3d8817e4Smiod
102*3d8817e4Smiod static const char *
parse_pag(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,const char ** strp,int opindex ATTRIBUTE_UNUSED,long * valuep ATTRIBUTE_UNUSED)103*3d8817e4Smiod parse_pag (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
104*3d8817e4Smiod const char **strp,
105*3d8817e4Smiod int opindex ATTRIBUTE_UNUSED,
106*3d8817e4Smiod long *valuep ATTRIBUTE_UNUSED)
107*3d8817e4Smiod {
108*3d8817e4Smiod if (strncasecmp (*strp, "pag:", 4) == 0)
109*3d8817e4Smiod {
110*3d8817e4Smiod *strp += 4;
111*3d8817e4Smiod return NULL;
112*3d8817e4Smiod }
113*3d8817e4Smiod return _("Missing 'pag:' prefix");
114*3d8817e4Smiod }
115*3d8817e4Smiod
116*3d8817e4Smiod /* Handle 'sof' prefixes (i.e. skip over them). */
117*3d8817e4Smiod
118*3d8817e4Smiod static const char *
parse_sof(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,const char ** strp,int opindex ATTRIBUTE_UNUSED,long * valuep ATTRIBUTE_UNUSED)119*3d8817e4Smiod parse_sof (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
120*3d8817e4Smiod const char **strp,
121*3d8817e4Smiod int opindex ATTRIBUTE_UNUSED,
122*3d8817e4Smiod long *valuep ATTRIBUTE_UNUSED)
123*3d8817e4Smiod {
124*3d8817e4Smiod if (strncasecmp (*strp, "sof:", 4) == 0)
125*3d8817e4Smiod {
126*3d8817e4Smiod *strp += 4;
127*3d8817e4Smiod return NULL;
128*3d8817e4Smiod }
129*3d8817e4Smiod return _("Missing 'sof:' prefix");
130*3d8817e4Smiod }
131*3d8817e4Smiod
132*3d8817e4Smiod /* Handle 'seg' prefixes (i.e. skip over them). */
133*3d8817e4Smiod
134*3d8817e4Smiod static const char *
parse_seg(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,const char ** strp,int opindex ATTRIBUTE_UNUSED,long * valuep ATTRIBUTE_UNUSED)135*3d8817e4Smiod parse_seg (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
136*3d8817e4Smiod const char **strp,
137*3d8817e4Smiod int opindex ATTRIBUTE_UNUSED,
138*3d8817e4Smiod long *valuep ATTRIBUTE_UNUSED)
139*3d8817e4Smiod {
140*3d8817e4Smiod if (strncasecmp (*strp, "seg:", 4) == 0)
141*3d8817e4Smiod {
142*3d8817e4Smiod *strp += 4;
143*3d8817e4Smiod return NULL;
144*3d8817e4Smiod }
145*3d8817e4Smiod return _("Missing 'seg:' prefix");
146*3d8817e4Smiod }
147*3d8817e4Smiod /* -- */
148*3d8817e4Smiod
149*3d8817e4Smiod const char * xc16x_cgen_parse_operand
150*3d8817e4Smiod (CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *);
151*3d8817e4Smiod
152*3d8817e4Smiod /* Main entry point for operand parsing.
153*3d8817e4Smiod
154*3d8817e4Smiod This function is basically just a big switch statement. Earlier versions
155*3d8817e4Smiod used tables to look up the function to use, but
156*3d8817e4Smiod - if the table contains both assembler and disassembler functions then
157*3d8817e4Smiod the disassembler contains much of the assembler and vice-versa,
158*3d8817e4Smiod - there's a lot of inlining possibilities as things grow,
159*3d8817e4Smiod - using a switch statement avoids the function call overhead.
160*3d8817e4Smiod
161*3d8817e4Smiod This function could be moved into `parse_insn_normal', but keeping it
162*3d8817e4Smiod separate makes clear the interface between `parse_insn_normal' and each of
163*3d8817e4Smiod the handlers. */
164*3d8817e4Smiod
165*3d8817e4Smiod const char *
xc16x_cgen_parse_operand(CGEN_CPU_DESC cd,int opindex,const char ** strp,CGEN_FIELDS * fields)166*3d8817e4Smiod xc16x_cgen_parse_operand (CGEN_CPU_DESC cd,
167*3d8817e4Smiod int opindex,
168*3d8817e4Smiod const char ** strp,
169*3d8817e4Smiod CGEN_FIELDS * fields)
170*3d8817e4Smiod {
171*3d8817e4Smiod const char * errmsg = NULL;
172*3d8817e4Smiod /* Used by scalar operands that still need to be parsed. */
173*3d8817e4Smiod long junk ATTRIBUTE_UNUSED;
174*3d8817e4Smiod
175*3d8817e4Smiod switch (opindex)
176*3d8817e4Smiod {
177*3d8817e4Smiod case XC16X_OPERAND_REGNAM :
178*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_psw_names, & fields->f_reg8);
179*3d8817e4Smiod break;
180*3d8817e4Smiod case XC16X_OPERAND_BIT01 :
181*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_BIT01, (unsigned long *) (& fields->f_op_1bit));
182*3d8817e4Smiod break;
183*3d8817e4Smiod case XC16X_OPERAND_BIT1 :
184*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_BIT1, (unsigned long *) (& fields->f_op_bit1));
185*3d8817e4Smiod break;
186*3d8817e4Smiod case XC16X_OPERAND_BIT2 :
187*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_BIT2, (unsigned long *) (& fields->f_op_bit2));
188*3d8817e4Smiod break;
189*3d8817e4Smiod case XC16X_OPERAND_BIT4 :
190*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_BIT4, (unsigned long *) (& fields->f_op_bit4));
191*3d8817e4Smiod break;
192*3d8817e4Smiod case XC16X_OPERAND_BIT8 :
193*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_BIT8, (unsigned long *) (& fields->f_op_bit8));
194*3d8817e4Smiod break;
195*3d8817e4Smiod case XC16X_OPERAND_BITONE :
196*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_BITONE, (unsigned long *) (& fields->f_op_onebit));
197*3d8817e4Smiod break;
198*3d8817e4Smiod case XC16X_OPERAND_CADDR :
199*3d8817e4Smiod {
200*3d8817e4Smiod bfd_vma value = 0;
201*3d8817e4Smiod errmsg = cgen_parse_address (cd, strp, XC16X_OPERAND_CADDR, 0, NULL, & value);
202*3d8817e4Smiod fields->f_offset16 = value;
203*3d8817e4Smiod }
204*3d8817e4Smiod break;
205*3d8817e4Smiod case XC16X_OPERAND_COND :
206*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_conditioncode_names, & fields->f_condcode);
207*3d8817e4Smiod break;
208*3d8817e4Smiod case XC16X_OPERAND_DATA8 :
209*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_DATA8, (unsigned long *) (& fields->f_data8));
210*3d8817e4Smiod break;
211*3d8817e4Smiod case XC16X_OPERAND_DATAHI8 :
212*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_DATAHI8, (unsigned long *) (& fields->f_datahi8));
213*3d8817e4Smiod break;
214*3d8817e4Smiod case XC16X_OPERAND_DOT :
215*3d8817e4Smiod errmsg = parse_dot (cd, strp, XC16X_OPERAND_DOT, (long *) (& junk));
216*3d8817e4Smiod break;
217*3d8817e4Smiod case XC16X_OPERAND_DR :
218*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_gr_names, & fields->f_r1);
219*3d8817e4Smiod break;
220*3d8817e4Smiod case XC16X_OPERAND_DRB :
221*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_grb_names, & fields->f_r1);
222*3d8817e4Smiod break;
223*3d8817e4Smiod case XC16X_OPERAND_DRI :
224*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_gr_names, & fields->f_r4);
225*3d8817e4Smiod break;
226*3d8817e4Smiod case XC16X_OPERAND_EXTCOND :
227*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_extconditioncode_names, & fields->f_extccode);
228*3d8817e4Smiod break;
229*3d8817e4Smiod case XC16X_OPERAND_GENREG :
230*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_r8_names, & fields->f_regb8);
231*3d8817e4Smiod break;
232*3d8817e4Smiod case XC16X_OPERAND_HASH :
233*3d8817e4Smiod errmsg = parse_hash (cd, strp, XC16X_OPERAND_HASH, (long *) (& junk));
234*3d8817e4Smiod break;
235*3d8817e4Smiod case XC16X_OPERAND_ICOND :
236*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_conditioncode_names, & fields->f_icondcode);
237*3d8817e4Smiod break;
238*3d8817e4Smiod case XC16X_OPERAND_LBIT2 :
239*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_LBIT2, (unsigned long *) (& fields->f_op_lbit2));
240*3d8817e4Smiod break;
241*3d8817e4Smiod case XC16X_OPERAND_LBIT4 :
242*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_LBIT4, (unsigned long *) (& fields->f_op_lbit4));
243*3d8817e4Smiod break;
244*3d8817e4Smiod case XC16X_OPERAND_MASK8 :
245*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_MASK8, (unsigned long *) (& fields->f_mask8));
246*3d8817e4Smiod break;
247*3d8817e4Smiod case XC16X_OPERAND_MASKLO8 :
248*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_MASKLO8, (unsigned long *) (& fields->f_datahi8));
249*3d8817e4Smiod break;
250*3d8817e4Smiod case XC16X_OPERAND_MEMGR8 :
251*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_memgr8_names, & fields->f_memgr8);
252*3d8817e4Smiod break;
253*3d8817e4Smiod case XC16X_OPERAND_MEMORY :
254*3d8817e4Smiod {
255*3d8817e4Smiod bfd_vma value = 0;
256*3d8817e4Smiod errmsg = cgen_parse_address (cd, strp, XC16X_OPERAND_MEMORY, 0, NULL, & value);
257*3d8817e4Smiod fields->f_memory = value;
258*3d8817e4Smiod }
259*3d8817e4Smiod break;
260*3d8817e4Smiod case XC16X_OPERAND_PAG :
261*3d8817e4Smiod errmsg = parse_pag (cd, strp, XC16X_OPERAND_PAG, (long *) (& junk));
262*3d8817e4Smiod break;
263*3d8817e4Smiod case XC16X_OPERAND_PAGENUM :
264*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_PAGENUM, (unsigned long *) (& fields->f_pagenum));
265*3d8817e4Smiod break;
266*3d8817e4Smiod case XC16X_OPERAND_POF :
267*3d8817e4Smiod errmsg = parse_pof (cd, strp, XC16X_OPERAND_POF, (long *) (& junk));
268*3d8817e4Smiod break;
269*3d8817e4Smiod case XC16X_OPERAND_QBIT :
270*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_QBIT, (unsigned long *) (& fields->f_qbit));
271*3d8817e4Smiod break;
272*3d8817e4Smiod case XC16X_OPERAND_QHIBIT :
273*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_QHIBIT, (unsigned long *) (& fields->f_qhibit));
274*3d8817e4Smiod break;
275*3d8817e4Smiod case XC16X_OPERAND_QLOBIT :
276*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_QLOBIT, (unsigned long *) (& fields->f_qlobit));
277*3d8817e4Smiod break;
278*3d8817e4Smiod case XC16X_OPERAND_REG8 :
279*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_r8_names, & fields->f_reg8);
280*3d8817e4Smiod break;
281*3d8817e4Smiod case XC16X_OPERAND_REGB8 :
282*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_grb8_names, & fields->f_regb8);
283*3d8817e4Smiod break;
284*3d8817e4Smiod case XC16X_OPERAND_REGBMEM8 :
285*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_regbmem8_names, & fields->f_regmem8);
286*3d8817e4Smiod break;
287*3d8817e4Smiod case XC16X_OPERAND_REGHI8 :
288*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_r8_names, & fields->f_reghi8);
289*3d8817e4Smiod break;
290*3d8817e4Smiod case XC16X_OPERAND_REGMEM8 :
291*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_regmem8_names, & fields->f_regmem8);
292*3d8817e4Smiod break;
293*3d8817e4Smiod case XC16X_OPERAND_REGOFF8 :
294*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_r8_names, & fields->f_regoff8);
295*3d8817e4Smiod break;
296*3d8817e4Smiod case XC16X_OPERAND_REL :
297*3d8817e4Smiod errmsg = cgen_parse_signed_integer (cd, strp, XC16X_OPERAND_REL, (long *) (& fields->f_rel8));
298*3d8817e4Smiod break;
299*3d8817e4Smiod case XC16X_OPERAND_RELHI :
300*3d8817e4Smiod errmsg = cgen_parse_signed_integer (cd, strp, XC16X_OPERAND_RELHI, (long *) (& fields->f_relhi8));
301*3d8817e4Smiod break;
302*3d8817e4Smiod case XC16X_OPERAND_SEG :
303*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_SEG, (unsigned long *) (& fields->f_seg8));
304*3d8817e4Smiod break;
305*3d8817e4Smiod case XC16X_OPERAND_SEGHI8 :
306*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_SEGHI8, (unsigned long *) (& fields->f_segnum8));
307*3d8817e4Smiod break;
308*3d8817e4Smiod case XC16X_OPERAND_SEGM :
309*3d8817e4Smiod errmsg = parse_seg (cd, strp, XC16X_OPERAND_SEGM, (long *) (& junk));
310*3d8817e4Smiod break;
311*3d8817e4Smiod case XC16X_OPERAND_SOF :
312*3d8817e4Smiod errmsg = parse_sof (cd, strp, XC16X_OPERAND_SOF, (long *) (& junk));
313*3d8817e4Smiod break;
314*3d8817e4Smiod case XC16X_OPERAND_SR :
315*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_gr_names, & fields->f_r2);
316*3d8817e4Smiod break;
317*3d8817e4Smiod case XC16X_OPERAND_SR2 :
318*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_gr_names, & fields->f_r0);
319*3d8817e4Smiod break;
320*3d8817e4Smiod case XC16X_OPERAND_SRB :
321*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_grb_names, & fields->f_r2);
322*3d8817e4Smiod break;
323*3d8817e4Smiod case XC16X_OPERAND_SRC1 :
324*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_gr_names, & fields->f_r1);
325*3d8817e4Smiod break;
326*3d8817e4Smiod case XC16X_OPERAND_SRC2 :
327*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_gr_names, & fields->f_r2);
328*3d8817e4Smiod break;
329*3d8817e4Smiod case XC16X_OPERAND_SRDIV :
330*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_regdiv8_names, & fields->f_reg8);
331*3d8817e4Smiod break;
332*3d8817e4Smiod case XC16X_OPERAND_U4 :
333*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_reg0_name, & fields->f_uimm4);
334*3d8817e4Smiod break;
335*3d8817e4Smiod case XC16X_OPERAND_UIMM16 :
336*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_UIMM16, (unsigned long *) (& fields->f_uimm16));
337*3d8817e4Smiod break;
338*3d8817e4Smiod case XC16X_OPERAND_UIMM2 :
339*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_ext_names, & fields->f_uimm2);
340*3d8817e4Smiod break;
341*3d8817e4Smiod case XC16X_OPERAND_UIMM3 :
342*3d8817e4Smiod errmsg = cgen_parse_keyword (cd, strp, & xc16x_cgen_opval_reg0_name1, & fields->f_uimm3);
343*3d8817e4Smiod break;
344*3d8817e4Smiod case XC16X_OPERAND_UIMM4 :
345*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_UIMM4, (unsigned long *) (& fields->f_uimm4));
346*3d8817e4Smiod break;
347*3d8817e4Smiod case XC16X_OPERAND_UIMM7 :
348*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_UIMM7, (unsigned long *) (& fields->f_uimm7));
349*3d8817e4Smiod break;
350*3d8817e4Smiod case XC16X_OPERAND_UIMM8 :
351*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_UIMM8, (unsigned long *) (& fields->f_uimm8));
352*3d8817e4Smiod break;
353*3d8817e4Smiod case XC16X_OPERAND_UPAG16 :
354*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_UPAG16, (unsigned long *) (& fields->f_uimm16));
355*3d8817e4Smiod break;
356*3d8817e4Smiod case XC16X_OPERAND_UPOF16 :
357*3d8817e4Smiod {
358*3d8817e4Smiod bfd_vma value = 0;
359*3d8817e4Smiod errmsg = cgen_parse_address (cd, strp, XC16X_OPERAND_UPOF16, 0, NULL, & value);
360*3d8817e4Smiod fields->f_memory = value;
361*3d8817e4Smiod }
362*3d8817e4Smiod break;
363*3d8817e4Smiod case XC16X_OPERAND_USEG16 :
364*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_USEG16, (unsigned long *) (& fields->f_offset16));
365*3d8817e4Smiod break;
366*3d8817e4Smiod case XC16X_OPERAND_USEG8 :
367*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_USEG8, (unsigned long *) (& fields->f_seg8));
368*3d8817e4Smiod break;
369*3d8817e4Smiod case XC16X_OPERAND_USOF16 :
370*3d8817e4Smiod errmsg = cgen_parse_unsigned_integer (cd, strp, XC16X_OPERAND_USOF16, (unsigned long *) (& fields->f_offset16));
371*3d8817e4Smiod break;
372*3d8817e4Smiod
373*3d8817e4Smiod default :
374*3d8817e4Smiod /* xgettext:c-format */
375*3d8817e4Smiod fprintf (stderr, _("Unrecognized field %d while parsing.\n"), opindex);
376*3d8817e4Smiod abort ();
377*3d8817e4Smiod }
378*3d8817e4Smiod
379*3d8817e4Smiod return errmsg;
380*3d8817e4Smiod }
381*3d8817e4Smiod
382*3d8817e4Smiod cgen_parse_fn * const xc16x_cgen_parse_handlers[] =
383*3d8817e4Smiod {
384*3d8817e4Smiod parse_insn_normal,
385*3d8817e4Smiod };
386*3d8817e4Smiod
387*3d8817e4Smiod void
xc16x_cgen_init_asm(CGEN_CPU_DESC cd)388*3d8817e4Smiod xc16x_cgen_init_asm (CGEN_CPU_DESC cd)
389*3d8817e4Smiod {
390*3d8817e4Smiod xc16x_cgen_init_opcode_table (cd);
391*3d8817e4Smiod xc16x_cgen_init_ibld_table (cd);
392*3d8817e4Smiod cd->parse_handlers = & xc16x_cgen_parse_handlers[0];
393*3d8817e4Smiod cd->parse_operand = xc16x_cgen_parse_operand;
394*3d8817e4Smiod }
395*3d8817e4Smiod
396*3d8817e4Smiod
397*3d8817e4Smiod
398*3d8817e4Smiod /* Regex construction routine.
399*3d8817e4Smiod
400*3d8817e4Smiod This translates an opcode syntax string into a regex string,
401*3d8817e4Smiod by replacing any non-character syntax element (such as an
402*3d8817e4Smiod opcode) with the pattern '.*'
403*3d8817e4Smiod
404*3d8817e4Smiod It then compiles the regex and stores it in the opcode, for
405*3d8817e4Smiod later use by xc16x_cgen_assemble_insn
406*3d8817e4Smiod
407*3d8817e4Smiod Returns NULL for success, an error message for failure. */
408*3d8817e4Smiod
409*3d8817e4Smiod char *
xc16x_cgen_build_insn_regex(CGEN_INSN * insn)410*3d8817e4Smiod xc16x_cgen_build_insn_regex (CGEN_INSN *insn)
411*3d8817e4Smiod {
412*3d8817e4Smiod CGEN_OPCODE *opc = (CGEN_OPCODE *) CGEN_INSN_OPCODE (insn);
413*3d8817e4Smiod const char *mnem = CGEN_INSN_MNEMONIC (insn);
414*3d8817e4Smiod char rxbuf[CGEN_MAX_RX_ELEMENTS];
415*3d8817e4Smiod char *rx = rxbuf;
416*3d8817e4Smiod const CGEN_SYNTAX_CHAR_TYPE *syn;
417*3d8817e4Smiod int reg_err;
418*3d8817e4Smiod
419*3d8817e4Smiod syn = CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc));
420*3d8817e4Smiod
421*3d8817e4Smiod /* Mnemonics come first in the syntax string. */
422*3d8817e4Smiod if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
423*3d8817e4Smiod return _("missing mnemonic in syntax string");
424*3d8817e4Smiod ++syn;
425*3d8817e4Smiod
426*3d8817e4Smiod /* Generate a case sensitive regular expression that emulates case
427*3d8817e4Smiod insensitive matching in the "C" locale. We cannot generate a case
428*3d8817e4Smiod insensitive regular expression because in Turkish locales, 'i' and 'I'
429*3d8817e4Smiod are not equal modulo case conversion. */
430*3d8817e4Smiod
431*3d8817e4Smiod /* Copy the literal mnemonic out of the insn. */
432*3d8817e4Smiod for (; *mnem; mnem++)
433*3d8817e4Smiod {
434*3d8817e4Smiod char c = *mnem;
435*3d8817e4Smiod
436*3d8817e4Smiod if (ISALPHA (c))
437*3d8817e4Smiod {
438*3d8817e4Smiod *rx++ = '[';
439*3d8817e4Smiod *rx++ = TOLOWER (c);
440*3d8817e4Smiod *rx++ = TOUPPER (c);
441*3d8817e4Smiod *rx++ = ']';
442*3d8817e4Smiod }
443*3d8817e4Smiod else
444*3d8817e4Smiod *rx++ = c;
445*3d8817e4Smiod }
446*3d8817e4Smiod
447*3d8817e4Smiod /* Copy any remaining literals from the syntax string into the rx. */
448*3d8817e4Smiod for(; * syn != 0 && rx <= rxbuf + (CGEN_MAX_RX_ELEMENTS - 7 - 4); ++syn)
449*3d8817e4Smiod {
450*3d8817e4Smiod if (CGEN_SYNTAX_CHAR_P (* syn))
451*3d8817e4Smiod {
452*3d8817e4Smiod char c = CGEN_SYNTAX_CHAR (* syn);
453*3d8817e4Smiod
454*3d8817e4Smiod switch (c)
455*3d8817e4Smiod {
456*3d8817e4Smiod /* Escape any regex metacharacters in the syntax. */
457*3d8817e4Smiod case '.': case '[': case '\\':
458*3d8817e4Smiod case '*': case '^': case '$':
459*3d8817e4Smiod
460*3d8817e4Smiod #ifdef CGEN_ESCAPE_EXTENDED_REGEX
461*3d8817e4Smiod case '?': case '{': case '}':
462*3d8817e4Smiod case '(': case ')': case '*':
463*3d8817e4Smiod case '|': case '+': case ']':
464*3d8817e4Smiod #endif
465*3d8817e4Smiod *rx++ = '\\';
466*3d8817e4Smiod *rx++ = c;
467*3d8817e4Smiod break;
468*3d8817e4Smiod
469*3d8817e4Smiod default:
470*3d8817e4Smiod if (ISALPHA (c))
471*3d8817e4Smiod {
472*3d8817e4Smiod *rx++ = '[';
473*3d8817e4Smiod *rx++ = TOLOWER (c);
474*3d8817e4Smiod *rx++ = TOUPPER (c);
475*3d8817e4Smiod *rx++ = ']';
476*3d8817e4Smiod }
477*3d8817e4Smiod else
478*3d8817e4Smiod *rx++ = c;
479*3d8817e4Smiod break;
480*3d8817e4Smiod }
481*3d8817e4Smiod }
482*3d8817e4Smiod else
483*3d8817e4Smiod {
484*3d8817e4Smiod /* Replace non-syntax fields with globs. */
485*3d8817e4Smiod *rx++ = '.';
486*3d8817e4Smiod *rx++ = '*';
487*3d8817e4Smiod }
488*3d8817e4Smiod }
489*3d8817e4Smiod
490*3d8817e4Smiod /* Trailing whitespace ok. */
491*3d8817e4Smiod * rx++ = '[';
492*3d8817e4Smiod * rx++ = ' ';
493*3d8817e4Smiod * rx++ = '\t';
494*3d8817e4Smiod * rx++ = ']';
495*3d8817e4Smiod * rx++ = '*';
496*3d8817e4Smiod
497*3d8817e4Smiod /* But anchor it after that. */
498*3d8817e4Smiod * rx++ = '$';
499*3d8817e4Smiod * rx = '\0';
500*3d8817e4Smiod
501*3d8817e4Smiod CGEN_INSN_RX (insn) = xmalloc (sizeof (regex_t));
502*3d8817e4Smiod reg_err = regcomp ((regex_t *) CGEN_INSN_RX (insn), rxbuf, REG_NOSUB);
503*3d8817e4Smiod
504*3d8817e4Smiod if (reg_err == 0)
505*3d8817e4Smiod return NULL;
506*3d8817e4Smiod else
507*3d8817e4Smiod {
508*3d8817e4Smiod static char msg[80];
509*3d8817e4Smiod
510*3d8817e4Smiod regerror (reg_err, (regex_t *) CGEN_INSN_RX (insn), msg, 80);
511*3d8817e4Smiod regfree ((regex_t *) CGEN_INSN_RX (insn));
512*3d8817e4Smiod free (CGEN_INSN_RX (insn));
513*3d8817e4Smiod (CGEN_INSN_RX (insn)) = NULL;
514*3d8817e4Smiod return msg;
515*3d8817e4Smiod }
516*3d8817e4Smiod }
517*3d8817e4Smiod
518*3d8817e4Smiod
519*3d8817e4Smiod /* Default insn parser.
520*3d8817e4Smiod
521*3d8817e4Smiod The syntax string is scanned and operands are parsed and stored in FIELDS.
522*3d8817e4Smiod Relocs are queued as we go via other callbacks.
523*3d8817e4Smiod
524*3d8817e4Smiod ??? Note that this is currently an all-or-nothing parser. If we fail to
525*3d8817e4Smiod parse the instruction, we return 0 and the caller will start over from
526*3d8817e4Smiod the beginning. Backtracking will be necessary in parsing subexpressions,
527*3d8817e4Smiod but that can be handled there. Not handling backtracking here may get
528*3d8817e4Smiod expensive in the case of the m68k. Deal with later.
529*3d8817e4Smiod
530*3d8817e4Smiod Returns NULL for success, an error message for failure. */
531*3d8817e4Smiod
532*3d8817e4Smiod static const char *
parse_insn_normal(CGEN_CPU_DESC cd,const CGEN_INSN * insn,const char ** strp,CGEN_FIELDS * fields)533*3d8817e4Smiod parse_insn_normal (CGEN_CPU_DESC cd,
534*3d8817e4Smiod const CGEN_INSN *insn,
535*3d8817e4Smiod const char **strp,
536*3d8817e4Smiod CGEN_FIELDS *fields)
537*3d8817e4Smiod {
538*3d8817e4Smiod /* ??? Runtime added insns not handled yet. */
539*3d8817e4Smiod const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
540*3d8817e4Smiod const char *str = *strp;
541*3d8817e4Smiod const char *errmsg;
542*3d8817e4Smiod const char *p;
543*3d8817e4Smiod const CGEN_SYNTAX_CHAR_TYPE * syn;
544*3d8817e4Smiod #ifdef CGEN_MNEMONIC_OPERANDS
545*3d8817e4Smiod /* FIXME: wip */
546*3d8817e4Smiod int past_opcode_p;
547*3d8817e4Smiod #endif
548*3d8817e4Smiod
549*3d8817e4Smiod /* For now we assume the mnemonic is first (there are no leading operands).
550*3d8817e4Smiod We can parse it without needing to set up operand parsing.
551*3d8817e4Smiod GAS's input scrubber will ensure mnemonics are lowercase, but we may
552*3d8817e4Smiod not be called from GAS. */
553*3d8817e4Smiod p = CGEN_INSN_MNEMONIC (insn);
554*3d8817e4Smiod while (*p && TOLOWER (*p) == TOLOWER (*str))
555*3d8817e4Smiod ++p, ++str;
556*3d8817e4Smiod
557*3d8817e4Smiod if (* p)
558*3d8817e4Smiod return _("unrecognized instruction");
559*3d8817e4Smiod
560*3d8817e4Smiod #ifndef CGEN_MNEMONIC_OPERANDS
561*3d8817e4Smiod if (* str && ! ISSPACE (* str))
562*3d8817e4Smiod return _("unrecognized instruction");
563*3d8817e4Smiod #endif
564*3d8817e4Smiod
565*3d8817e4Smiod CGEN_INIT_PARSE (cd);
566*3d8817e4Smiod cgen_init_parse_operand (cd);
567*3d8817e4Smiod #ifdef CGEN_MNEMONIC_OPERANDS
568*3d8817e4Smiod past_opcode_p = 0;
569*3d8817e4Smiod #endif
570*3d8817e4Smiod
571*3d8817e4Smiod /* We don't check for (*str != '\0') here because we want to parse
572*3d8817e4Smiod any trailing fake arguments in the syntax string. */
573*3d8817e4Smiod syn = CGEN_SYNTAX_STRING (syntax);
574*3d8817e4Smiod
575*3d8817e4Smiod /* Mnemonics come first for now, ensure valid string. */
576*3d8817e4Smiod if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
577*3d8817e4Smiod abort ();
578*3d8817e4Smiod
579*3d8817e4Smiod ++syn;
580*3d8817e4Smiod
581*3d8817e4Smiod while (* syn != 0)
582*3d8817e4Smiod {
583*3d8817e4Smiod /* Non operand chars must match exactly. */
584*3d8817e4Smiod if (CGEN_SYNTAX_CHAR_P (* syn))
585*3d8817e4Smiod {
586*3d8817e4Smiod /* FIXME: While we allow for non-GAS callers above, we assume the
587*3d8817e4Smiod first char after the mnemonic part is a space. */
588*3d8817e4Smiod /* FIXME: We also take inappropriate advantage of the fact that
589*3d8817e4Smiod GAS's input scrubber will remove extraneous blanks. */
590*3d8817e4Smiod if (TOLOWER (*str) == TOLOWER (CGEN_SYNTAX_CHAR (* syn)))
591*3d8817e4Smiod {
592*3d8817e4Smiod #ifdef CGEN_MNEMONIC_OPERANDS
593*3d8817e4Smiod if (CGEN_SYNTAX_CHAR(* syn) == ' ')
594*3d8817e4Smiod past_opcode_p = 1;
595*3d8817e4Smiod #endif
596*3d8817e4Smiod ++ syn;
597*3d8817e4Smiod ++ str;
598*3d8817e4Smiod }
599*3d8817e4Smiod else if (*str)
600*3d8817e4Smiod {
601*3d8817e4Smiod /* Syntax char didn't match. Can't be this insn. */
602*3d8817e4Smiod static char msg [80];
603*3d8817e4Smiod
604*3d8817e4Smiod /* xgettext:c-format */
605*3d8817e4Smiod sprintf (msg, _("syntax error (expected char `%c', found `%c')"),
606*3d8817e4Smiod CGEN_SYNTAX_CHAR(*syn), *str);
607*3d8817e4Smiod return msg;
608*3d8817e4Smiod }
609*3d8817e4Smiod else
610*3d8817e4Smiod {
611*3d8817e4Smiod /* Ran out of input. */
612*3d8817e4Smiod static char msg [80];
613*3d8817e4Smiod
614*3d8817e4Smiod /* xgettext:c-format */
615*3d8817e4Smiod sprintf (msg, _("syntax error (expected char `%c', found end of instruction)"),
616*3d8817e4Smiod CGEN_SYNTAX_CHAR(*syn));
617*3d8817e4Smiod return msg;
618*3d8817e4Smiod }
619*3d8817e4Smiod continue;
620*3d8817e4Smiod }
621*3d8817e4Smiod
622*3d8817e4Smiod /* We have an operand of some sort. */
623*3d8817e4Smiod errmsg = cd->parse_operand (cd, CGEN_SYNTAX_FIELD (*syn),
624*3d8817e4Smiod &str, fields);
625*3d8817e4Smiod if (errmsg)
626*3d8817e4Smiod return errmsg;
627*3d8817e4Smiod
628*3d8817e4Smiod /* Done with this operand, continue with next one. */
629*3d8817e4Smiod ++ syn;
630*3d8817e4Smiod }
631*3d8817e4Smiod
632*3d8817e4Smiod /* If we're at the end of the syntax string, we're done. */
633*3d8817e4Smiod if (* syn == 0)
634*3d8817e4Smiod {
635*3d8817e4Smiod /* FIXME: For the moment we assume a valid `str' can only contain
636*3d8817e4Smiod blanks now. IE: We needn't try again with a longer version of
637*3d8817e4Smiod the insn and it is assumed that longer versions of insns appear
638*3d8817e4Smiod before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
639*3d8817e4Smiod while (ISSPACE (* str))
640*3d8817e4Smiod ++ str;
641*3d8817e4Smiod
642*3d8817e4Smiod if (* str != '\0')
643*3d8817e4Smiod return _("junk at end of line"); /* FIXME: would like to include `str' */
644*3d8817e4Smiod
645*3d8817e4Smiod return NULL;
646*3d8817e4Smiod }
647*3d8817e4Smiod
648*3d8817e4Smiod /* We couldn't parse it. */
649*3d8817e4Smiod return _("unrecognized instruction");
650*3d8817e4Smiod }
651*3d8817e4Smiod
652*3d8817e4Smiod /* Main entry point.
653*3d8817e4Smiod This routine is called for each instruction to be assembled.
654*3d8817e4Smiod STR points to the insn to be assembled.
655*3d8817e4Smiod We assume all necessary tables have been initialized.
656*3d8817e4Smiod The assembled instruction, less any fixups, is stored in BUF.
657*3d8817e4Smiod Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
658*3d8817e4Smiod still needs to be converted to target byte order, otherwise BUF is an array
659*3d8817e4Smiod of bytes in target byte order.
660*3d8817e4Smiod The result is a pointer to the insn's entry in the opcode table,
661*3d8817e4Smiod or NULL if an error occured (an error message will have already been
662*3d8817e4Smiod printed).
663*3d8817e4Smiod
664*3d8817e4Smiod Note that when processing (non-alias) macro-insns,
665*3d8817e4Smiod this function recurses.
666*3d8817e4Smiod
667*3d8817e4Smiod ??? It's possible to make this cpu-independent.
668*3d8817e4Smiod One would have to deal with a few minor things.
669*3d8817e4Smiod At this point in time doing so would be more of a curiosity than useful
670*3d8817e4Smiod [for example this file isn't _that_ big], but keeping the possibility in
671*3d8817e4Smiod mind helps keep the design clean. */
672*3d8817e4Smiod
673*3d8817e4Smiod const CGEN_INSN *
xc16x_cgen_assemble_insn(CGEN_CPU_DESC cd,const char * str,CGEN_FIELDS * fields,CGEN_INSN_BYTES_PTR buf,char ** errmsg)674*3d8817e4Smiod xc16x_cgen_assemble_insn (CGEN_CPU_DESC cd,
675*3d8817e4Smiod const char *str,
676*3d8817e4Smiod CGEN_FIELDS *fields,
677*3d8817e4Smiod CGEN_INSN_BYTES_PTR buf,
678*3d8817e4Smiod char **errmsg)
679*3d8817e4Smiod {
680*3d8817e4Smiod const char *start;
681*3d8817e4Smiod CGEN_INSN_LIST *ilist;
682*3d8817e4Smiod const char *parse_errmsg = NULL;
683*3d8817e4Smiod const char *insert_errmsg = NULL;
684*3d8817e4Smiod int recognized_mnemonic = 0;
685*3d8817e4Smiod
686*3d8817e4Smiod /* Skip leading white space. */
687*3d8817e4Smiod while (ISSPACE (* str))
688*3d8817e4Smiod ++ str;
689*3d8817e4Smiod
690*3d8817e4Smiod /* The instructions are stored in hashed lists.
691*3d8817e4Smiod Get the first in the list. */
692*3d8817e4Smiod ilist = CGEN_ASM_LOOKUP_INSN (cd, str);
693*3d8817e4Smiod
694*3d8817e4Smiod /* Keep looking until we find a match. */
695*3d8817e4Smiod start = str;
696*3d8817e4Smiod for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist))
697*3d8817e4Smiod {
698*3d8817e4Smiod const CGEN_INSN *insn = ilist->insn;
699*3d8817e4Smiod recognized_mnemonic = 1;
700*3d8817e4Smiod
701*3d8817e4Smiod #ifdef CGEN_VALIDATE_INSN_SUPPORTED
702*3d8817e4Smiod /* Not usually needed as unsupported opcodes
703*3d8817e4Smiod shouldn't be in the hash lists. */
704*3d8817e4Smiod /* Is this insn supported by the selected cpu? */
705*3d8817e4Smiod if (! xc16x_cgen_insn_supported (cd, insn))
706*3d8817e4Smiod continue;
707*3d8817e4Smiod #endif
708*3d8817e4Smiod /* If the RELAXED attribute is set, this is an insn that shouldn't be
709*3d8817e4Smiod chosen immediately. Instead, it is used during assembler/linker
710*3d8817e4Smiod relaxation if possible. */
711*3d8817e4Smiod if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXED) != 0)
712*3d8817e4Smiod continue;
713*3d8817e4Smiod
714*3d8817e4Smiod str = start;
715*3d8817e4Smiod
716*3d8817e4Smiod /* Skip this insn if str doesn't look right lexically. */
717*3d8817e4Smiod if (CGEN_INSN_RX (insn) != NULL &&
718*3d8817e4Smiod regexec ((regex_t *) CGEN_INSN_RX (insn), str, 0, NULL, 0) == REG_NOMATCH)
719*3d8817e4Smiod continue;
720*3d8817e4Smiod
721*3d8817e4Smiod /* Allow parse/insert handlers to obtain length of insn. */
722*3d8817e4Smiod CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
723*3d8817e4Smiod
724*3d8817e4Smiod parse_errmsg = CGEN_PARSE_FN (cd, insn) (cd, insn, & str, fields);
725*3d8817e4Smiod if (parse_errmsg != NULL)
726*3d8817e4Smiod continue;
727*3d8817e4Smiod
728*3d8817e4Smiod /* ??? 0 is passed for `pc'. */
729*3d8817e4Smiod insert_errmsg = CGEN_INSERT_FN (cd, insn) (cd, insn, fields, buf,
730*3d8817e4Smiod (bfd_vma) 0);
731*3d8817e4Smiod if (insert_errmsg != NULL)
732*3d8817e4Smiod continue;
733*3d8817e4Smiod
734*3d8817e4Smiod /* It is up to the caller to actually output the insn and any
735*3d8817e4Smiod queued relocs. */
736*3d8817e4Smiod return insn;
737*3d8817e4Smiod }
738*3d8817e4Smiod
739*3d8817e4Smiod {
740*3d8817e4Smiod static char errbuf[150];
741*3d8817e4Smiod #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
742*3d8817e4Smiod const char *tmp_errmsg;
743*3d8817e4Smiod
744*3d8817e4Smiod /* If requesting verbose error messages, use insert_errmsg.
745*3d8817e4Smiod Failing that, use parse_errmsg. */
746*3d8817e4Smiod tmp_errmsg = (insert_errmsg ? insert_errmsg :
747*3d8817e4Smiod parse_errmsg ? parse_errmsg :
748*3d8817e4Smiod recognized_mnemonic ?
749*3d8817e4Smiod _("unrecognized form of instruction") :
750*3d8817e4Smiod _("unrecognized instruction"));
751*3d8817e4Smiod
752*3d8817e4Smiod if (strlen (start) > 50)
753*3d8817e4Smiod /* xgettext:c-format */
754*3d8817e4Smiod sprintf (errbuf, "%s `%.50s...'", tmp_errmsg, start);
755*3d8817e4Smiod else
756*3d8817e4Smiod /* xgettext:c-format */
757*3d8817e4Smiod sprintf (errbuf, "%s `%.50s'", tmp_errmsg, start);
758*3d8817e4Smiod #else
759*3d8817e4Smiod if (strlen (start) > 50)
760*3d8817e4Smiod /* xgettext:c-format */
761*3d8817e4Smiod sprintf (errbuf, _("bad instruction `%.50s...'"), start);
762*3d8817e4Smiod else
763*3d8817e4Smiod /* xgettext:c-format */
764*3d8817e4Smiod sprintf (errbuf, _("bad instruction `%.50s'"), start);
765*3d8817e4Smiod #endif
766*3d8817e4Smiod
767*3d8817e4Smiod *errmsg = errbuf;
768*3d8817e4Smiod return NULL;
769*3d8817e4Smiod }
770*3d8817e4Smiod }
771