1ede78133Schristos /* DO NOT EDIT! -*- buffer-read-only: t -*- vi:set ro: */
275fd0b74Schristos /* Assembler interface for targets using CGEN. -*- C -*-
375fd0b74Schristos CGEN: Cpu tools GENerator
475fd0b74Schristos
575fd0b74Schristos THIS FILE IS MACHINE GENERATED WITH CGEN.
675fd0b74Schristos - the resultant file is machine generated, cgen-asm.in isn't
775fd0b74Schristos
8*e992f068Schristos Copyright (C) 1996-2022 Free Software Foundation, Inc.
975fd0b74Schristos
1075fd0b74Schristos This file is part of libopcodes.
1175fd0b74Schristos
1275fd0b74Schristos This library is free software; you can redistribute it and/or modify
1375fd0b74Schristos it under the terms of the GNU General Public License as published by
1475fd0b74Schristos the Free Software Foundation; either version 3, or (at your option)
1575fd0b74Schristos any later version.
1675fd0b74Schristos
1775fd0b74Schristos It is distributed in the hope that it will be useful, but WITHOUT
1875fd0b74Schristos ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
1975fd0b74Schristos or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
2075fd0b74Schristos License for more details.
2175fd0b74Schristos
2275fd0b74Schristos You should have received a copy of the GNU General Public License
2375fd0b74Schristos along with this program; if not, write to the Free Software Foundation, Inc.,
2475fd0b74Schristos 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
2575fd0b74Schristos
2675fd0b74Schristos
2775fd0b74Schristos /* ??? Eventually more and more of this stuff can go to cpu-independent files.
2875fd0b74Schristos Keep that in mind. */
2975fd0b74Schristos
3075fd0b74Schristos #include "sysdep.h"
3175fd0b74Schristos #include <stdio.h>
3275fd0b74Schristos #include "ansidecl.h"
3375fd0b74Schristos #include "bfd.h"
3475fd0b74Schristos #include "symcat.h"
3575fd0b74Schristos #include "epiphany-desc.h"
3675fd0b74Schristos #include "epiphany-opc.h"
3775fd0b74Schristos #include "opintl.h"
3875fd0b74Schristos #include "xregex.h"
3975fd0b74Schristos #include "libiberty.h"
4075fd0b74Schristos #include "safe-ctype.h"
4175fd0b74Schristos
4275fd0b74Schristos #undef min
4375fd0b74Schristos #define min(a,b) ((a) < (b) ? (a) : (b))
4475fd0b74Schristos #undef max
4575fd0b74Schristos #define max(a,b) ((a) > (b) ? (a) : (b))
4675fd0b74Schristos
4775fd0b74Schristos static const char * parse_insn_normal
4875fd0b74Schristos (CGEN_CPU_DESC, const CGEN_INSN *, const char **, CGEN_FIELDS *);
4975fd0b74Schristos
5075fd0b74Schristos /* -- assembler routines inserted here. */
5175fd0b74Schristos
5275fd0b74Schristos /* -- asm.c */
5375fd0b74Schristos const char *
parse_shortregs(CGEN_CPU_DESC cd,const char ** strp,CGEN_KEYWORD * keywords,long * regno)5475fd0b74Schristos parse_shortregs (CGEN_CPU_DESC cd,
5575fd0b74Schristos const char ** strp,
5675fd0b74Schristos CGEN_KEYWORD * keywords,
5775fd0b74Schristos long * regno)
5875fd0b74Schristos {
5975fd0b74Schristos const char * errmsg;
6075fd0b74Schristos
6175fd0b74Schristos /* Parse register. */
6275fd0b74Schristos errmsg = cgen_parse_keyword (cd, strp, keywords, regno);
6375fd0b74Schristos
6475fd0b74Schristos if (errmsg)
6575fd0b74Schristos return errmsg;
6675fd0b74Schristos
6775fd0b74Schristos if (*regno > 7)
6875fd0b74Schristos errmsg = _("register unavailable for short instructions");
6975fd0b74Schristos
7075fd0b74Schristos return errmsg;
7175fd0b74Schristos }
7275fd0b74Schristos
7375fd0b74Schristos static const char * parse_simm_not_reg (CGEN_CPU_DESC, const char **, int,
7475fd0b74Schristos long *);
7575fd0b74Schristos
7675fd0b74Schristos static const char *
parse_uimm_not_reg(CGEN_CPU_DESC cd,const char ** strp,int opindex,unsigned long * valuep)7775fd0b74Schristos parse_uimm_not_reg (CGEN_CPU_DESC cd,
7875fd0b74Schristos const char ** strp,
7975fd0b74Schristos int opindex,
8075fd0b74Schristos unsigned long * valuep)
8175fd0b74Schristos {
8275fd0b74Schristos long * svalp = (void *) valuep;
8375fd0b74Schristos return parse_simm_not_reg (cd, strp, opindex, svalp);
8475fd0b74Schristos }
8575fd0b74Schristos
8675fd0b74Schristos /* Handle simm3/simm11/imm3/imm12. */
8775fd0b74Schristos
8875fd0b74Schristos static const char *
parse_simm_not_reg(CGEN_CPU_DESC cd,const char ** strp,int opindex,long * valuep)8975fd0b74Schristos parse_simm_not_reg (CGEN_CPU_DESC cd,
9075fd0b74Schristos const char ** strp,
9175fd0b74Schristos int opindex,
9275fd0b74Schristos long * valuep)
9375fd0b74Schristos {
9475fd0b74Schristos const char * errmsg;
9575fd0b74Schristos
9675fd0b74Schristos int sign = 0;
9775fd0b74Schristos int bits = 0;
9875fd0b74Schristos
9975fd0b74Schristos switch (opindex)
10075fd0b74Schristos {
10175fd0b74Schristos case EPIPHANY_OPERAND_SIMM3:
10275fd0b74Schristos sign = 1; bits = 3; break;
10375fd0b74Schristos case EPIPHANY_OPERAND_SIMM11:
10475fd0b74Schristos sign = 1; bits = 11; break;
10575fd0b74Schristos case EPIPHANY_OPERAND_DISP3:
10675fd0b74Schristos sign = 0; bits = 3; break;
10775fd0b74Schristos case EPIPHANY_OPERAND_DISP11:
10875fd0b74Schristos /* Load/store displacement is a sign-magnitude 12 bit value. */
10975fd0b74Schristos sign = 0; bits = 11; break;
11075fd0b74Schristos }
11175fd0b74Schristos
11275fd0b74Schristos /* First try to parse as a register name and reject the operand. */
11375fd0b74Schristos errmsg = cgen_parse_keyword (cd, strp, & epiphany_cgen_opval_gr_names,valuep);
11475fd0b74Schristos if (!errmsg)
11575fd0b74Schristos return _("register name used as immediate value");
11675fd0b74Schristos
11775fd0b74Schristos errmsg = (sign ? cgen_parse_signed_integer (cd, strp, opindex, valuep)
11875fd0b74Schristos : cgen_parse_unsigned_integer (cd, strp, opindex,
11975fd0b74Schristos (unsigned long *) valuep));
12075fd0b74Schristos if (errmsg)
12175fd0b74Schristos return errmsg;
12275fd0b74Schristos
12375fd0b74Schristos if (sign)
12475fd0b74Schristos errmsg = cgen_validate_signed_integer (*valuep,
12575fd0b74Schristos -((1L << bits) - 1), (1 << (bits - 1)) - 1);
12675fd0b74Schristos else
12775fd0b74Schristos errmsg = cgen_validate_unsigned_integer (*valuep, 0, (1L << bits) - 1);
12875fd0b74Schristos
12975fd0b74Schristos return errmsg;
13075fd0b74Schristos }
13175fd0b74Schristos
13275fd0b74Schristos static const char *
parse_postindex(CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,const char ** strp,int opindex ATTRIBUTE_UNUSED,unsigned long * valuep)13375fd0b74Schristos parse_postindex (CGEN_CPU_DESC cd ATTRIBUTE_UNUSED,
13475fd0b74Schristos const char ** strp,
13575fd0b74Schristos int opindex ATTRIBUTE_UNUSED,
13675fd0b74Schristos unsigned long *valuep)
13775fd0b74Schristos {
13875fd0b74Schristos if (**strp == '#')
13975fd0b74Schristos ++*strp; /* Skip leading hashes. */
14075fd0b74Schristos
14175fd0b74Schristos if (**strp == '-')
14275fd0b74Schristos {
14375fd0b74Schristos *valuep = 1;
14475fd0b74Schristos ++*strp;
14575fd0b74Schristos }
14675fd0b74Schristos else if (**strp == '+')
14775fd0b74Schristos {
14875fd0b74Schristos *valuep = 0;
14975fd0b74Schristos ++*strp;
15075fd0b74Schristos }
15175fd0b74Schristos else
15275fd0b74Schristos *valuep = 0;
15375fd0b74Schristos
15475fd0b74Schristos return NULL;
15575fd0b74Schristos }
15675fd0b74Schristos
15775fd0b74Schristos static const char *
parse_imm8(CGEN_CPU_DESC cd,const char ** strp,int opindex,bfd_reloc_code_real_type code,enum cgen_parse_operand_result * result_type,bfd_vma * valuep)15875fd0b74Schristos parse_imm8 (CGEN_CPU_DESC cd,
15975fd0b74Schristos const char ** strp,
16075fd0b74Schristos int opindex,
16175fd0b74Schristos bfd_reloc_code_real_type code,
16275fd0b74Schristos enum cgen_parse_operand_result * result_type,
16375fd0b74Schristos bfd_vma * valuep)
16475fd0b74Schristos {
16575fd0b74Schristos const char * errmsg;
16675fd0b74Schristos enum cgen_parse_operand_result rt;
16775fd0b74Schristos long dummyval;
16875fd0b74Schristos
16975fd0b74Schristos if (!result_type)
17075fd0b74Schristos result_type = &rt;
17175fd0b74Schristos
17275fd0b74Schristos code = BFD_RELOC_NONE;
17375fd0b74Schristos
17475fd0b74Schristos if (!cgen_parse_keyword (cd, strp, &epiphany_cgen_opval_gr_names, &dummyval)
17575fd0b74Schristos || !cgen_parse_keyword (cd, strp, &epiphany_cgen_opval_cr_names,
17675fd0b74Schristos &dummyval))
17775fd0b74Schristos /* Don't treat "mov ip,ip" as a move-immediate. */
17875fd0b74Schristos return _("register source in immediate move");
17975fd0b74Schristos
18075fd0b74Schristos errmsg = cgen_parse_address (cd, strp, opindex, code, result_type, valuep);
18175fd0b74Schristos if (errmsg)
18275fd0b74Schristos return errmsg;
18375fd0b74Schristos
18475fd0b74Schristos if (*result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
18575fd0b74Schristos errmsg = cgen_validate_unsigned_integer (*valuep, 0, 0xff);
18675fd0b74Schristos else
18775fd0b74Schristos errmsg = _("byte relocation unsupported");
18875fd0b74Schristos
18975fd0b74Schristos *valuep &= 0xff;
19075fd0b74Schristos return errmsg;
19175fd0b74Schristos }
19275fd0b74Schristos
19375fd0b74Schristos static const char * MISSING_CLOSE_PARENTHESIS = N_("missing `)'");
19475fd0b74Schristos
19575fd0b74Schristos static const char *
parse_imm16(CGEN_CPU_DESC cd,const char ** strp,int opindex,bfd_reloc_code_real_type code ATTRIBUTE_UNUSED,enum cgen_parse_operand_result * result_type,bfd_vma * valuep)19675fd0b74Schristos parse_imm16 (CGEN_CPU_DESC cd,
19775fd0b74Schristos const char ** strp,
19875fd0b74Schristos int opindex,
19975fd0b74Schristos bfd_reloc_code_real_type code ATTRIBUTE_UNUSED,
20075fd0b74Schristos enum cgen_parse_operand_result * result_type,
20175fd0b74Schristos bfd_vma * valuep)
20275fd0b74Schristos {
20375fd0b74Schristos const char * errmsg;
20475fd0b74Schristos enum cgen_parse_operand_result rt;
20575fd0b74Schristos long dummyval;
20675fd0b74Schristos
20775fd0b74Schristos if (!result_type)
20875fd0b74Schristos result_type = &rt;
20975fd0b74Schristos
21075fd0b74Schristos if (strncasecmp (*strp, "%high(", 6) == 0)
21175fd0b74Schristos {
21275fd0b74Schristos *strp += 6;
21375fd0b74Schristos errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_EPIPHANY_HIGH,
21475fd0b74Schristos result_type, valuep);
21575fd0b74Schristos if (**strp != ')')
21675fd0b74Schristos return MISSING_CLOSE_PARENTHESIS;
21775fd0b74Schristos ++*strp;
21875fd0b74Schristos *valuep >>= 16;
21975fd0b74Schristos }
22075fd0b74Schristos else if (strncasecmp (*strp, "%low(", 5) == 0)
22175fd0b74Schristos {
22275fd0b74Schristos *strp += 5;
22375fd0b74Schristos errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_EPIPHANY_LOW,
22475fd0b74Schristos result_type, valuep);
22575fd0b74Schristos if (**strp != ')')
22675fd0b74Schristos return MISSING_CLOSE_PARENTHESIS;
22775fd0b74Schristos ++*strp;
22875fd0b74Schristos }
22975fd0b74Schristos else if (!cgen_parse_keyword (cd, strp, &epiphany_cgen_opval_gr_names,
23075fd0b74Schristos &dummyval)
23175fd0b74Schristos || !cgen_parse_keyword (cd, strp, &epiphany_cgen_opval_cr_names,
23275fd0b74Schristos &dummyval))
23375fd0b74Schristos /* Don't treat "mov ip,ip" as a move-immediate. */
23475fd0b74Schristos return _("register source in immediate move");
23575fd0b74Schristos else
23675fd0b74Schristos errmsg = cgen_parse_address (cd, strp, opindex, BFD_RELOC_16,
23775fd0b74Schristos result_type, valuep);
23875fd0b74Schristos
23975fd0b74Schristos if (!errmsg && result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
24075fd0b74Schristos errmsg = cgen_validate_unsigned_integer (*valuep, 0, 0xffff);
24175fd0b74Schristos
24275fd0b74Schristos *valuep &= 0xffff;
24375fd0b74Schristos return errmsg;
24475fd0b74Schristos }
24575fd0b74Schristos
24675fd0b74Schristos const char *
parse_branch_addr(CGEN_CPU_DESC cd,const char ** strp,int opindex,int opinfo ATTRIBUTE_UNUSED,enum cgen_parse_operand_result * resultp ATTRIBUTE_UNUSED,bfd_vma * valuep ATTRIBUTE_UNUSED)24775fd0b74Schristos parse_branch_addr (CGEN_CPU_DESC cd,
24875fd0b74Schristos const char ** strp,
24975fd0b74Schristos int opindex,
25075fd0b74Schristos int opinfo ATTRIBUTE_UNUSED,
25175fd0b74Schristos enum cgen_parse_operand_result * resultp ATTRIBUTE_UNUSED,
25275fd0b74Schristos bfd_vma *valuep ATTRIBUTE_UNUSED)
25375fd0b74Schristos {
25475fd0b74Schristos const char * errmsg;
25575fd0b74Schristos enum cgen_parse_operand_result result_type;
25675fd0b74Schristos bfd_reloc_code_real_type code = BFD_RELOC_NONE;
25775fd0b74Schristos bfd_vma value;
25875fd0b74Schristos
25975fd0b74Schristos switch (opindex)
26075fd0b74Schristos {
26175fd0b74Schristos case EPIPHANY_OPERAND_SIMM24:
26275fd0b74Schristos code = BFD_RELOC_EPIPHANY_SIMM24;
26375fd0b74Schristos break;
26475fd0b74Schristos
26575fd0b74Schristos case EPIPHANY_OPERAND_SIMM8:
26675fd0b74Schristos code = BFD_RELOC_EPIPHANY_SIMM8;
26775fd0b74Schristos break;
26875fd0b74Schristos
26975fd0b74Schristos default:
27075fd0b74Schristos errmsg = _("ABORT: unknown operand");
27175fd0b74Schristos return errmsg;
27275fd0b74Schristos }
27375fd0b74Schristos
27475fd0b74Schristos errmsg = cgen_parse_address (cd, strp, opindex, code,
27575fd0b74Schristos &result_type, &value);
27675fd0b74Schristos if (errmsg == NULL)
27775fd0b74Schristos {
27875fd0b74Schristos if (result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
27975fd0b74Schristos {
28075fd0b74Schristos /* Act as if we had done a PC-relative branch, ala .+num. */
28175fd0b74Schristos char buf[20];
28275fd0b74Schristos const char * bufp = (const char *) buf;
28375fd0b74Schristos
28475fd0b74Schristos sprintf (buf, ".+%ld", (long) value);
28575fd0b74Schristos errmsg = cgen_parse_address (cd, &bufp, opindex, code, &result_type,
28675fd0b74Schristos &value);
28775fd0b74Schristos }
28875fd0b74Schristos
28975fd0b74Schristos if (result_type == CGEN_PARSE_OPERAND_RESULT_QUEUED)
29075fd0b74Schristos {
29175fd0b74Schristos /* This will happen for things like (s2-s1) where s2 and s1
29275fd0b74Schristos are labels. */
29375fd0b74Schristos /* Nothing further to be done. */
29475fd0b74Schristos }
29575fd0b74Schristos else
29675fd0b74Schristos errmsg = _("Not a pc-relative address.");
29775fd0b74Schristos }
29875fd0b74Schristos return errmsg;
29975fd0b74Schristos }
30075fd0b74Schristos
30175fd0b74Schristos /* -- dis.c */
30275fd0b74Schristos
30375fd0b74Schristos const char * epiphany_cgen_parse_operand
30475fd0b74Schristos (CGEN_CPU_DESC, int, const char **, CGEN_FIELDS *);
30575fd0b74Schristos
30675fd0b74Schristos /* Main entry point for operand parsing.
30775fd0b74Schristos
30875fd0b74Schristos This function is basically just a big switch statement. Earlier versions
30975fd0b74Schristos used tables to look up the function to use, but
31075fd0b74Schristos - if the table contains both assembler and disassembler functions then
31175fd0b74Schristos the disassembler contains much of the assembler and vice-versa,
31275fd0b74Schristos - there's a lot of inlining possibilities as things grow,
31375fd0b74Schristos - using a switch statement avoids the function call overhead.
31475fd0b74Schristos
31575fd0b74Schristos This function could be moved into `parse_insn_normal', but keeping it
31675fd0b74Schristos separate makes clear the interface between `parse_insn_normal' and each of
31775fd0b74Schristos the handlers. */
31875fd0b74Schristos
31975fd0b74Schristos const char *
epiphany_cgen_parse_operand(CGEN_CPU_DESC cd,int opindex,const char ** strp,CGEN_FIELDS * fields)32075fd0b74Schristos epiphany_cgen_parse_operand (CGEN_CPU_DESC cd,
32175fd0b74Schristos int opindex,
32275fd0b74Schristos const char ** strp,
32375fd0b74Schristos CGEN_FIELDS * fields)
32475fd0b74Schristos {
32575fd0b74Schristos const char * errmsg = NULL;
32675fd0b74Schristos /* Used by scalar operands that still need to be parsed. */
32775fd0b74Schristos long junk ATTRIBUTE_UNUSED;
32875fd0b74Schristos
32975fd0b74Schristos switch (opindex)
33075fd0b74Schristos {
33175fd0b74Schristos case EPIPHANY_OPERAND_DIRECTION :
33275fd0b74Schristos errmsg = parse_postindex (cd, strp, EPIPHANY_OPERAND_DIRECTION, (unsigned long *) (& fields->f_addsubx));
33375fd0b74Schristos break;
33475fd0b74Schristos case EPIPHANY_OPERAND_DISP11 :
33575fd0b74Schristos errmsg = parse_uimm_not_reg (cd, strp, EPIPHANY_OPERAND_DISP11, (unsigned long *) (& fields->f_disp11));
33675fd0b74Schristos break;
33775fd0b74Schristos case EPIPHANY_OPERAND_DISP3 :
33875fd0b74Schristos errmsg = cgen_parse_unsigned_integer (cd, strp, EPIPHANY_OPERAND_DISP3, (unsigned long *) (& fields->f_disp3));
33975fd0b74Schristos break;
34075fd0b74Schristos case EPIPHANY_OPERAND_DPMI :
34175fd0b74Schristos errmsg = parse_postindex (cd, strp, EPIPHANY_OPERAND_DPMI, (unsigned long *) (& fields->f_subd));
34275fd0b74Schristos break;
34375fd0b74Schristos case EPIPHANY_OPERAND_FRD :
34475fd0b74Schristos errmsg = parse_shortregs (cd, strp, & epiphany_cgen_opval_gr_names, & fields->f_rd);
34575fd0b74Schristos break;
34675fd0b74Schristos case EPIPHANY_OPERAND_FRD6 :
34775fd0b74Schristos errmsg = cgen_parse_keyword (cd, strp, & epiphany_cgen_opval_gr_names, & fields->f_rd6);
34875fd0b74Schristos break;
34975fd0b74Schristos case EPIPHANY_OPERAND_FRM :
35075fd0b74Schristos errmsg = parse_shortregs (cd, strp, & epiphany_cgen_opval_gr_names, & fields->f_rm);
35175fd0b74Schristos break;
35275fd0b74Schristos case EPIPHANY_OPERAND_FRM6 :
35375fd0b74Schristos errmsg = cgen_parse_keyword (cd, strp, & epiphany_cgen_opval_gr_names, & fields->f_rm6);
35475fd0b74Schristos break;
35575fd0b74Schristos case EPIPHANY_OPERAND_FRN :
35675fd0b74Schristos errmsg = parse_shortregs (cd, strp, & epiphany_cgen_opval_gr_names, & fields->f_rn);
35775fd0b74Schristos break;
35875fd0b74Schristos case EPIPHANY_OPERAND_FRN6 :
35975fd0b74Schristos errmsg = cgen_parse_keyword (cd, strp, & epiphany_cgen_opval_gr_names, & fields->f_rn6);
36075fd0b74Schristos break;
36175fd0b74Schristos case EPIPHANY_OPERAND_IMM16 :
36275fd0b74Schristos {
36375fd0b74Schristos bfd_vma value = 0;
36475fd0b74Schristos errmsg = parse_imm16 (cd, strp, EPIPHANY_OPERAND_IMM16, 0, NULL, & value);
36575fd0b74Schristos fields->f_imm16 = value;
36675fd0b74Schristos }
36775fd0b74Schristos break;
36875fd0b74Schristos case EPIPHANY_OPERAND_IMM8 :
36975fd0b74Schristos {
37075fd0b74Schristos bfd_vma value = 0;
37175fd0b74Schristos errmsg = parse_imm8 (cd, strp, EPIPHANY_OPERAND_IMM8, 0, NULL, & value);
37275fd0b74Schristos fields->f_imm8 = value;
37375fd0b74Schristos }
37475fd0b74Schristos break;
37575fd0b74Schristos case EPIPHANY_OPERAND_RD :
37675fd0b74Schristos errmsg = parse_shortregs (cd, strp, & epiphany_cgen_opval_gr_names, & fields->f_rd);
37775fd0b74Schristos break;
37875fd0b74Schristos case EPIPHANY_OPERAND_RD6 :
37975fd0b74Schristos errmsg = cgen_parse_keyword (cd, strp, & epiphany_cgen_opval_gr_names, & fields->f_rd6);
38075fd0b74Schristos break;
38175fd0b74Schristos case EPIPHANY_OPERAND_RM :
38275fd0b74Schristos errmsg = parse_shortregs (cd, strp, & epiphany_cgen_opval_gr_names, & fields->f_rm);
38375fd0b74Schristos break;
38475fd0b74Schristos case EPIPHANY_OPERAND_RM6 :
38575fd0b74Schristos errmsg = cgen_parse_keyword (cd, strp, & epiphany_cgen_opval_gr_names, & fields->f_rm6);
38675fd0b74Schristos break;
38775fd0b74Schristos case EPIPHANY_OPERAND_RN :
38875fd0b74Schristos errmsg = parse_shortregs (cd, strp, & epiphany_cgen_opval_gr_names, & fields->f_rn);
38975fd0b74Schristos break;
39075fd0b74Schristos case EPIPHANY_OPERAND_RN6 :
39175fd0b74Schristos errmsg = cgen_parse_keyword (cd, strp, & epiphany_cgen_opval_gr_names, & fields->f_rn6);
39275fd0b74Schristos break;
39375fd0b74Schristos case EPIPHANY_OPERAND_SD :
39475fd0b74Schristos errmsg = parse_shortregs (cd, strp, & epiphany_cgen_opval_cr_names, & fields->f_sd);
39575fd0b74Schristos break;
39675fd0b74Schristos case EPIPHANY_OPERAND_SD6 :
39775fd0b74Schristos errmsg = cgen_parse_keyword (cd, strp, & epiphany_cgen_opval_cr_names, & fields->f_sd6);
39875fd0b74Schristos break;
39975fd0b74Schristos case EPIPHANY_OPERAND_SDDMA :
40075fd0b74Schristos errmsg = cgen_parse_keyword (cd, strp, & epiphany_cgen_opval_crdma_names, & fields->f_sd6);
40175fd0b74Schristos break;
40275fd0b74Schristos case EPIPHANY_OPERAND_SDMEM :
40375fd0b74Schristos errmsg = cgen_parse_keyword (cd, strp, & epiphany_cgen_opval_crmem_names, & fields->f_sd6);
40475fd0b74Schristos break;
40575fd0b74Schristos case EPIPHANY_OPERAND_SDMESH :
40675fd0b74Schristos errmsg = cgen_parse_keyword (cd, strp, & epiphany_cgen_opval_crmesh_names, & fields->f_sd6);
40775fd0b74Schristos break;
40875fd0b74Schristos case EPIPHANY_OPERAND_SHIFT :
40975fd0b74Schristos errmsg = cgen_parse_unsigned_integer (cd, strp, EPIPHANY_OPERAND_SHIFT, (unsigned long *) (& fields->f_shift));
41075fd0b74Schristos break;
41175fd0b74Schristos case EPIPHANY_OPERAND_SIMM11 :
41275fd0b74Schristos errmsg = parse_simm_not_reg (cd, strp, EPIPHANY_OPERAND_SIMM11, (long *) (& fields->f_sdisp11));
41375fd0b74Schristos break;
41475fd0b74Schristos case EPIPHANY_OPERAND_SIMM24 :
41575fd0b74Schristos {
41675fd0b74Schristos bfd_vma value = 0;
41775fd0b74Schristos errmsg = parse_branch_addr (cd, strp, EPIPHANY_OPERAND_SIMM24, 0, NULL, & value);
41875fd0b74Schristos fields->f_simm24 = value;
41975fd0b74Schristos }
42075fd0b74Schristos break;
42175fd0b74Schristos case EPIPHANY_OPERAND_SIMM3 :
42275fd0b74Schristos errmsg = parse_simm_not_reg (cd, strp, EPIPHANY_OPERAND_SIMM3, (long *) (& fields->f_sdisp3));
42375fd0b74Schristos break;
42475fd0b74Schristos case EPIPHANY_OPERAND_SIMM8 :
42575fd0b74Schristos {
42675fd0b74Schristos bfd_vma value = 0;
42775fd0b74Schristos errmsg = parse_branch_addr (cd, strp, EPIPHANY_OPERAND_SIMM8, 0, NULL, & value);
42875fd0b74Schristos fields->f_simm8 = value;
42975fd0b74Schristos }
43075fd0b74Schristos break;
43175fd0b74Schristos case EPIPHANY_OPERAND_SN :
43275fd0b74Schristos errmsg = parse_shortregs (cd, strp, & epiphany_cgen_opval_cr_names, & fields->f_sn);
43375fd0b74Schristos break;
43475fd0b74Schristos case EPIPHANY_OPERAND_SN6 :
43575fd0b74Schristos errmsg = cgen_parse_keyword (cd, strp, & epiphany_cgen_opval_cr_names, & fields->f_sn6);
43675fd0b74Schristos break;
43775fd0b74Schristos case EPIPHANY_OPERAND_SNDMA :
43875fd0b74Schristos errmsg = cgen_parse_keyword (cd, strp, & epiphany_cgen_opval_crdma_names, & fields->f_sn6);
43975fd0b74Schristos break;
44075fd0b74Schristos case EPIPHANY_OPERAND_SNMEM :
44175fd0b74Schristos errmsg = cgen_parse_keyword (cd, strp, & epiphany_cgen_opval_crmem_names, & fields->f_sn6);
44275fd0b74Schristos break;
44375fd0b74Schristos case EPIPHANY_OPERAND_SNMESH :
44475fd0b74Schristos errmsg = cgen_parse_keyword (cd, strp, & epiphany_cgen_opval_crmesh_names, & fields->f_sn6);
44575fd0b74Schristos break;
44675fd0b74Schristos case EPIPHANY_OPERAND_SWI_NUM :
44775fd0b74Schristos errmsg = parse_uimm_not_reg (cd, strp, EPIPHANY_OPERAND_SWI_NUM, (unsigned long *) (& fields->f_trap_num));
44875fd0b74Schristos break;
44975fd0b74Schristos case EPIPHANY_OPERAND_TRAPNUM6 :
45075fd0b74Schristos errmsg = cgen_parse_unsigned_integer (cd, strp, EPIPHANY_OPERAND_TRAPNUM6, (unsigned long *) (& fields->f_trap_num));
45175fd0b74Schristos break;
45275fd0b74Schristos
45375fd0b74Schristos default :
45475fd0b74Schristos /* xgettext:c-format */
455ede78133Schristos opcodes_error_handler
456ede78133Schristos (_("internal error: unrecognized field %d while parsing"),
457ede78133Schristos opindex);
45875fd0b74Schristos abort ();
45975fd0b74Schristos }
46075fd0b74Schristos
46175fd0b74Schristos return errmsg;
46275fd0b74Schristos }
46375fd0b74Schristos
46475fd0b74Schristos cgen_parse_fn * const epiphany_cgen_parse_handlers[] =
46575fd0b74Schristos {
46675fd0b74Schristos parse_insn_normal,
46775fd0b74Schristos };
46875fd0b74Schristos
46975fd0b74Schristos void
epiphany_cgen_init_asm(CGEN_CPU_DESC cd)47075fd0b74Schristos epiphany_cgen_init_asm (CGEN_CPU_DESC cd)
47175fd0b74Schristos {
47275fd0b74Schristos epiphany_cgen_init_opcode_table (cd);
47375fd0b74Schristos epiphany_cgen_init_ibld_table (cd);
47475fd0b74Schristos cd->parse_handlers = & epiphany_cgen_parse_handlers[0];
47575fd0b74Schristos cd->parse_operand = epiphany_cgen_parse_operand;
47675fd0b74Schristos #ifdef CGEN_ASM_INIT_HOOK
47775fd0b74Schristos CGEN_ASM_INIT_HOOK
47875fd0b74Schristos #endif
47975fd0b74Schristos }
48075fd0b74Schristos
48175fd0b74Schristos
48275fd0b74Schristos
48375fd0b74Schristos /* Regex construction routine.
48475fd0b74Schristos
48575fd0b74Schristos This translates an opcode syntax string into a regex string,
48675fd0b74Schristos by replacing any non-character syntax element (such as an
48775fd0b74Schristos opcode) with the pattern '.*'
48875fd0b74Schristos
48975fd0b74Schristos It then compiles the regex and stores it in the opcode, for
49075fd0b74Schristos later use by epiphany_cgen_assemble_insn
49175fd0b74Schristos
49275fd0b74Schristos Returns NULL for success, an error message for failure. */
49375fd0b74Schristos
49475fd0b74Schristos char *
epiphany_cgen_build_insn_regex(CGEN_INSN * insn)49575fd0b74Schristos epiphany_cgen_build_insn_regex (CGEN_INSN *insn)
49675fd0b74Schristos {
49775fd0b74Schristos CGEN_OPCODE *opc = (CGEN_OPCODE *) CGEN_INSN_OPCODE (insn);
49875fd0b74Schristos const char *mnem = CGEN_INSN_MNEMONIC (insn);
49975fd0b74Schristos char rxbuf[CGEN_MAX_RX_ELEMENTS];
50075fd0b74Schristos char *rx = rxbuf;
50175fd0b74Schristos const CGEN_SYNTAX_CHAR_TYPE *syn;
50275fd0b74Schristos int reg_err;
50375fd0b74Schristos
50475fd0b74Schristos syn = CGEN_SYNTAX_STRING (CGEN_OPCODE_SYNTAX (opc));
50575fd0b74Schristos
50675fd0b74Schristos /* Mnemonics come first in the syntax string. */
50775fd0b74Schristos if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
50875fd0b74Schristos return _("missing mnemonic in syntax string");
50975fd0b74Schristos ++syn;
51075fd0b74Schristos
51175fd0b74Schristos /* Generate a case sensitive regular expression that emulates case
51275fd0b74Schristos insensitive matching in the "C" locale. We cannot generate a case
51375fd0b74Schristos insensitive regular expression because in Turkish locales, 'i' and 'I'
51475fd0b74Schristos are not equal modulo case conversion. */
51575fd0b74Schristos
51675fd0b74Schristos /* Copy the literal mnemonic out of the insn. */
51775fd0b74Schristos for (; *mnem; mnem++)
51875fd0b74Schristos {
51975fd0b74Schristos char c = *mnem;
52075fd0b74Schristos
52175fd0b74Schristos if (ISALPHA (c))
52275fd0b74Schristos {
52375fd0b74Schristos *rx++ = '[';
52475fd0b74Schristos *rx++ = TOLOWER (c);
52575fd0b74Schristos *rx++ = TOUPPER (c);
52675fd0b74Schristos *rx++ = ']';
52775fd0b74Schristos }
52875fd0b74Schristos else
52975fd0b74Schristos *rx++ = c;
53075fd0b74Schristos }
53175fd0b74Schristos
53275fd0b74Schristos /* Copy any remaining literals from the syntax string into the rx. */
53375fd0b74Schristos for(; * syn != 0 && rx <= rxbuf + (CGEN_MAX_RX_ELEMENTS - 7 - 4); ++syn)
53475fd0b74Schristos {
53575fd0b74Schristos if (CGEN_SYNTAX_CHAR_P (* syn))
53675fd0b74Schristos {
53775fd0b74Schristos char c = CGEN_SYNTAX_CHAR (* syn);
53875fd0b74Schristos
53975fd0b74Schristos switch (c)
54075fd0b74Schristos {
54175fd0b74Schristos /* Escape any regex metacharacters in the syntax. */
54275fd0b74Schristos case '.': case '[': case '\\':
54375fd0b74Schristos case '*': case '^': case '$':
54475fd0b74Schristos
54575fd0b74Schristos #ifdef CGEN_ESCAPE_EXTENDED_REGEX
54675fd0b74Schristos case '?': case '{': case '}':
54775fd0b74Schristos case '(': case ')': case '*':
54875fd0b74Schristos case '|': case '+': case ']':
54975fd0b74Schristos #endif
55075fd0b74Schristos *rx++ = '\\';
55175fd0b74Schristos *rx++ = c;
55275fd0b74Schristos break;
55375fd0b74Schristos
55475fd0b74Schristos default:
55575fd0b74Schristos if (ISALPHA (c))
55675fd0b74Schristos {
55775fd0b74Schristos *rx++ = '[';
55875fd0b74Schristos *rx++ = TOLOWER (c);
55975fd0b74Schristos *rx++ = TOUPPER (c);
56075fd0b74Schristos *rx++ = ']';
56175fd0b74Schristos }
56275fd0b74Schristos else
56375fd0b74Schristos *rx++ = c;
56475fd0b74Schristos break;
56575fd0b74Schristos }
56675fd0b74Schristos }
56775fd0b74Schristos else
56875fd0b74Schristos {
56975fd0b74Schristos /* Replace non-syntax fields with globs. */
57075fd0b74Schristos *rx++ = '.';
57175fd0b74Schristos *rx++ = '*';
57275fd0b74Schristos }
57375fd0b74Schristos }
57475fd0b74Schristos
57575fd0b74Schristos /* Trailing whitespace ok. */
57675fd0b74Schristos * rx++ = '[';
57775fd0b74Schristos * rx++ = ' ';
57875fd0b74Schristos * rx++ = '\t';
57975fd0b74Schristos * rx++ = ']';
58075fd0b74Schristos * rx++ = '*';
58175fd0b74Schristos
58275fd0b74Schristos /* But anchor it after that. */
58375fd0b74Schristos * rx++ = '$';
58475fd0b74Schristos * rx = '\0';
58575fd0b74Schristos
58675fd0b74Schristos CGEN_INSN_RX (insn) = xmalloc (sizeof (regex_t));
58775fd0b74Schristos reg_err = regcomp ((regex_t *) CGEN_INSN_RX (insn), rxbuf, REG_NOSUB);
58875fd0b74Schristos
58975fd0b74Schristos if (reg_err == 0)
59075fd0b74Schristos return NULL;
59175fd0b74Schristos else
59275fd0b74Schristos {
59375fd0b74Schristos static char msg[80];
59475fd0b74Schristos
59575fd0b74Schristos regerror (reg_err, (regex_t *) CGEN_INSN_RX (insn), msg, 80);
59675fd0b74Schristos regfree ((regex_t *) CGEN_INSN_RX (insn));
59775fd0b74Schristos free (CGEN_INSN_RX (insn));
59875fd0b74Schristos (CGEN_INSN_RX (insn)) = NULL;
59975fd0b74Schristos return msg;
60075fd0b74Schristos }
60175fd0b74Schristos }
60275fd0b74Schristos
60375fd0b74Schristos
60475fd0b74Schristos /* Default insn parser.
60575fd0b74Schristos
60675fd0b74Schristos The syntax string is scanned and operands are parsed and stored in FIELDS.
60775fd0b74Schristos Relocs are queued as we go via other callbacks.
60875fd0b74Schristos
60975fd0b74Schristos ??? Note that this is currently an all-or-nothing parser. If we fail to
61075fd0b74Schristos parse the instruction, we return 0 and the caller will start over from
61175fd0b74Schristos the beginning. Backtracking will be necessary in parsing subexpressions,
61275fd0b74Schristos but that can be handled there. Not handling backtracking here may get
61375fd0b74Schristos expensive in the case of the m68k. Deal with later.
61475fd0b74Schristos
61575fd0b74Schristos Returns NULL for success, an error message for failure. */
61675fd0b74Schristos
61775fd0b74Schristos static const char *
parse_insn_normal(CGEN_CPU_DESC cd,const CGEN_INSN * insn,const char ** strp,CGEN_FIELDS * fields)61875fd0b74Schristos parse_insn_normal (CGEN_CPU_DESC cd,
61975fd0b74Schristos const CGEN_INSN *insn,
62075fd0b74Schristos const char **strp,
62175fd0b74Schristos CGEN_FIELDS *fields)
62275fd0b74Schristos {
62375fd0b74Schristos /* ??? Runtime added insns not handled yet. */
62475fd0b74Schristos const CGEN_SYNTAX *syntax = CGEN_INSN_SYNTAX (insn);
62575fd0b74Schristos const char *str = *strp;
62675fd0b74Schristos const char *errmsg;
62775fd0b74Schristos const char *p;
62875fd0b74Schristos const CGEN_SYNTAX_CHAR_TYPE * syn;
62975fd0b74Schristos #ifdef CGEN_MNEMONIC_OPERANDS
63075fd0b74Schristos /* FIXME: wip */
63175fd0b74Schristos int past_opcode_p;
63275fd0b74Schristos #endif
63375fd0b74Schristos
63475fd0b74Schristos /* For now we assume the mnemonic is first (there are no leading operands).
63575fd0b74Schristos We can parse it without needing to set up operand parsing.
63675fd0b74Schristos GAS's input scrubber will ensure mnemonics are lowercase, but we may
63775fd0b74Schristos not be called from GAS. */
63875fd0b74Schristos p = CGEN_INSN_MNEMONIC (insn);
63975fd0b74Schristos while (*p && TOLOWER (*p) == TOLOWER (*str))
64075fd0b74Schristos ++p, ++str;
64175fd0b74Schristos
64275fd0b74Schristos if (* p)
64375fd0b74Schristos return _("unrecognized instruction");
64475fd0b74Schristos
64575fd0b74Schristos #ifndef CGEN_MNEMONIC_OPERANDS
64675fd0b74Schristos if (* str && ! ISSPACE (* str))
64775fd0b74Schristos return _("unrecognized instruction");
64875fd0b74Schristos #endif
64975fd0b74Schristos
65075fd0b74Schristos CGEN_INIT_PARSE (cd);
65175fd0b74Schristos cgen_init_parse_operand (cd);
65275fd0b74Schristos #ifdef CGEN_MNEMONIC_OPERANDS
65375fd0b74Schristos past_opcode_p = 0;
65475fd0b74Schristos #endif
65575fd0b74Schristos
65675fd0b74Schristos /* We don't check for (*str != '\0') here because we want to parse
65775fd0b74Schristos any trailing fake arguments in the syntax string. */
65875fd0b74Schristos syn = CGEN_SYNTAX_STRING (syntax);
65975fd0b74Schristos
66075fd0b74Schristos /* Mnemonics come first for now, ensure valid string. */
66175fd0b74Schristos if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
66275fd0b74Schristos abort ();
66375fd0b74Schristos
66475fd0b74Schristos ++syn;
66575fd0b74Schristos
66675fd0b74Schristos while (* syn != 0)
66775fd0b74Schristos {
66875fd0b74Schristos /* Non operand chars must match exactly. */
66975fd0b74Schristos if (CGEN_SYNTAX_CHAR_P (* syn))
67075fd0b74Schristos {
67175fd0b74Schristos /* FIXME: While we allow for non-GAS callers above, we assume the
67275fd0b74Schristos first char after the mnemonic part is a space. */
67375fd0b74Schristos /* FIXME: We also take inappropriate advantage of the fact that
67475fd0b74Schristos GAS's input scrubber will remove extraneous blanks. */
67575fd0b74Schristos if (TOLOWER (*str) == TOLOWER (CGEN_SYNTAX_CHAR (* syn)))
67675fd0b74Schristos {
67775fd0b74Schristos #ifdef CGEN_MNEMONIC_OPERANDS
67875fd0b74Schristos if (CGEN_SYNTAX_CHAR(* syn) == ' ')
67975fd0b74Schristos past_opcode_p = 1;
68075fd0b74Schristos #endif
68175fd0b74Schristos ++ syn;
68275fd0b74Schristos ++ str;
68375fd0b74Schristos }
68475fd0b74Schristos else if (*str)
68575fd0b74Schristos {
68675fd0b74Schristos /* Syntax char didn't match. Can't be this insn. */
68775fd0b74Schristos static char msg [80];
68875fd0b74Schristos
68975fd0b74Schristos /* xgettext:c-format */
69075fd0b74Schristos sprintf (msg, _("syntax error (expected char `%c', found `%c')"),
69175fd0b74Schristos CGEN_SYNTAX_CHAR(*syn), *str);
69275fd0b74Schristos return msg;
69375fd0b74Schristos }
69475fd0b74Schristos else
69575fd0b74Schristos {
69675fd0b74Schristos /* Ran out of input. */
69775fd0b74Schristos static char msg [80];
69875fd0b74Schristos
69975fd0b74Schristos /* xgettext:c-format */
70075fd0b74Schristos sprintf (msg, _("syntax error (expected char `%c', found end of instruction)"),
70175fd0b74Schristos CGEN_SYNTAX_CHAR(*syn));
70275fd0b74Schristos return msg;
70375fd0b74Schristos }
70475fd0b74Schristos continue;
70575fd0b74Schristos }
70675fd0b74Schristos
70775fd0b74Schristos #ifdef CGEN_MNEMONIC_OPERANDS
70875fd0b74Schristos (void) past_opcode_p;
70975fd0b74Schristos #endif
71075fd0b74Schristos /* We have an operand of some sort. */
71175fd0b74Schristos errmsg = cd->parse_operand (cd, CGEN_SYNTAX_FIELD (*syn), &str, fields);
71275fd0b74Schristos if (errmsg)
71375fd0b74Schristos return errmsg;
71475fd0b74Schristos
71575fd0b74Schristos /* Done with this operand, continue with next one. */
71675fd0b74Schristos ++ syn;
71775fd0b74Schristos }
71875fd0b74Schristos
71975fd0b74Schristos /* If we're at the end of the syntax string, we're done. */
72075fd0b74Schristos if (* syn == 0)
72175fd0b74Schristos {
72275fd0b74Schristos /* FIXME: For the moment we assume a valid `str' can only contain
72375fd0b74Schristos blanks now. IE: We needn't try again with a longer version of
72475fd0b74Schristos the insn and it is assumed that longer versions of insns appear
72575fd0b74Schristos before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
72675fd0b74Schristos while (ISSPACE (* str))
72775fd0b74Schristos ++ str;
72875fd0b74Schristos
72975fd0b74Schristos if (* str != '\0')
73075fd0b74Schristos return _("junk at end of line"); /* FIXME: would like to include `str' */
73175fd0b74Schristos
73275fd0b74Schristos return NULL;
73375fd0b74Schristos }
73475fd0b74Schristos
73575fd0b74Schristos /* We couldn't parse it. */
73675fd0b74Schristos return _("unrecognized instruction");
73775fd0b74Schristos }
73875fd0b74Schristos
73975fd0b74Schristos /* Main entry point.
74075fd0b74Schristos This routine is called for each instruction to be assembled.
74175fd0b74Schristos STR points to the insn to be assembled.
74275fd0b74Schristos We assume all necessary tables have been initialized.
74375fd0b74Schristos The assembled instruction, less any fixups, is stored in BUF.
74475fd0b74Schristos Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
74575fd0b74Schristos still needs to be converted to target byte order, otherwise BUF is an array
74675fd0b74Schristos of bytes in target byte order.
74775fd0b74Schristos The result is a pointer to the insn's entry in the opcode table,
74875fd0b74Schristos or NULL if an error occured (an error message will have already been
74975fd0b74Schristos printed).
75075fd0b74Schristos
75175fd0b74Schristos Note that when processing (non-alias) macro-insns,
75275fd0b74Schristos this function recurses.
75375fd0b74Schristos
75475fd0b74Schristos ??? It's possible to make this cpu-independent.
75575fd0b74Schristos One would have to deal with a few minor things.
75675fd0b74Schristos At this point in time doing so would be more of a curiosity than useful
75775fd0b74Schristos [for example this file isn't _that_ big], but keeping the possibility in
75875fd0b74Schristos mind helps keep the design clean. */
75975fd0b74Schristos
76075fd0b74Schristos const CGEN_INSN *
epiphany_cgen_assemble_insn(CGEN_CPU_DESC cd,const char * str,CGEN_FIELDS * fields,CGEN_INSN_BYTES_PTR buf,char ** errmsg)76175fd0b74Schristos epiphany_cgen_assemble_insn (CGEN_CPU_DESC cd,
76275fd0b74Schristos const char *str,
76375fd0b74Schristos CGEN_FIELDS *fields,
76475fd0b74Schristos CGEN_INSN_BYTES_PTR buf,
76575fd0b74Schristos char **errmsg)
76675fd0b74Schristos {
76775fd0b74Schristos const char *start;
76875fd0b74Schristos CGEN_INSN_LIST *ilist;
76975fd0b74Schristos const char *parse_errmsg = NULL;
77075fd0b74Schristos const char *insert_errmsg = NULL;
77175fd0b74Schristos int recognized_mnemonic = 0;
77275fd0b74Schristos
77375fd0b74Schristos /* Skip leading white space. */
77475fd0b74Schristos while (ISSPACE (* str))
77575fd0b74Schristos ++ str;
77675fd0b74Schristos
77775fd0b74Schristos /* The instructions are stored in hashed lists.
77875fd0b74Schristos Get the first in the list. */
77975fd0b74Schristos ilist = CGEN_ASM_LOOKUP_INSN (cd, str);
78075fd0b74Schristos
78175fd0b74Schristos /* Keep looking until we find a match. */
78275fd0b74Schristos start = str;
78375fd0b74Schristos for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist))
78475fd0b74Schristos {
78575fd0b74Schristos const CGEN_INSN *insn = ilist->insn;
78675fd0b74Schristos recognized_mnemonic = 1;
78775fd0b74Schristos
78875fd0b74Schristos #ifdef CGEN_VALIDATE_INSN_SUPPORTED
78975fd0b74Schristos /* Not usually needed as unsupported opcodes
79075fd0b74Schristos shouldn't be in the hash lists. */
79175fd0b74Schristos /* Is this insn supported by the selected cpu? */
79275fd0b74Schristos if (! epiphany_cgen_insn_supported (cd, insn))
79375fd0b74Schristos continue;
79475fd0b74Schristos #endif
79575fd0b74Schristos /* If the RELAXED attribute is set, this is an insn that shouldn't be
79675fd0b74Schristos chosen immediately. Instead, it is used during assembler/linker
79775fd0b74Schristos relaxation if possible. */
79875fd0b74Schristos if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXED) != 0)
79975fd0b74Schristos continue;
80075fd0b74Schristos
80175fd0b74Schristos str = start;
80275fd0b74Schristos
80375fd0b74Schristos /* Skip this insn if str doesn't look right lexically. */
80475fd0b74Schristos if (CGEN_INSN_RX (insn) != NULL &&
80575fd0b74Schristos regexec ((regex_t *) CGEN_INSN_RX (insn), str, 0, NULL, 0) == REG_NOMATCH)
80675fd0b74Schristos continue;
80775fd0b74Schristos
80875fd0b74Schristos /* Allow parse/insert handlers to obtain length of insn. */
80975fd0b74Schristos CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
81075fd0b74Schristos
81175fd0b74Schristos parse_errmsg = CGEN_PARSE_FN (cd, insn) (cd, insn, & str, fields);
81275fd0b74Schristos if (parse_errmsg != NULL)
81375fd0b74Schristos continue;
81475fd0b74Schristos
81575fd0b74Schristos /* ??? 0 is passed for `pc'. */
81675fd0b74Schristos insert_errmsg = CGEN_INSERT_FN (cd, insn) (cd, insn, fields, buf,
81775fd0b74Schristos (bfd_vma) 0);
81875fd0b74Schristos if (insert_errmsg != NULL)
81975fd0b74Schristos continue;
82075fd0b74Schristos
82175fd0b74Schristos /* It is up to the caller to actually output the insn and any
82275fd0b74Schristos queued relocs. */
82375fd0b74Schristos return insn;
82475fd0b74Schristos }
82575fd0b74Schristos
82675fd0b74Schristos {
82775fd0b74Schristos static char errbuf[150];
82875fd0b74Schristos const char *tmp_errmsg;
82975fd0b74Schristos #ifdef CGEN_VERBOSE_ASSEMBLER_ERRORS
83075fd0b74Schristos #define be_verbose 1
83175fd0b74Schristos #else
83275fd0b74Schristos #define be_verbose 0
83375fd0b74Schristos #endif
83475fd0b74Schristos
83575fd0b74Schristos if (be_verbose)
83675fd0b74Schristos {
83775fd0b74Schristos /* If requesting verbose error messages, use insert_errmsg.
83875fd0b74Schristos Failing that, use parse_errmsg. */
83975fd0b74Schristos tmp_errmsg = (insert_errmsg ? insert_errmsg :
84075fd0b74Schristos parse_errmsg ? parse_errmsg :
84175fd0b74Schristos recognized_mnemonic ?
84275fd0b74Schristos _("unrecognized form of instruction") :
84375fd0b74Schristos _("unrecognized instruction"));
84475fd0b74Schristos
84575fd0b74Schristos if (strlen (start) > 50)
84675fd0b74Schristos /* xgettext:c-format */
84775fd0b74Schristos sprintf (errbuf, "%s `%.50s...'", tmp_errmsg, start);
84875fd0b74Schristos else
84975fd0b74Schristos /* xgettext:c-format */
85075fd0b74Schristos sprintf (errbuf, "%s `%.50s'", tmp_errmsg, start);
85175fd0b74Schristos }
85275fd0b74Schristos else
85375fd0b74Schristos {
85475fd0b74Schristos if (strlen (start) > 50)
85575fd0b74Schristos /* xgettext:c-format */
85675fd0b74Schristos sprintf (errbuf, _("bad instruction `%.50s...'"), start);
85775fd0b74Schristos else
85875fd0b74Schristos /* xgettext:c-format */
85975fd0b74Schristos sprintf (errbuf, _("bad instruction `%.50s'"), start);
86075fd0b74Schristos }
86175fd0b74Schristos
86275fd0b74Schristos *errmsg = errbuf;
86375fd0b74Schristos return NULL;
86475fd0b74Schristos }
86575fd0b74Schristos }
866