/* Assembler interface for targets using CGEN. -*- C -*-
CGEN: Cpu tools GENerator
-This file is used to generate @arch@-asm.c.
+THIS FILE IS USED TO GENERATE @prefix@-asm.c.
Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+along with this program; if not, write to the Free Software Foundation, Inc.,
+59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "sysdep.h"
#include <ctype.h>
#include "ansidecl.h"
#include "bfd.h"
#include "symcat.h"
-#include "@arch@-opc.h"
+#include "@prefix@-opc.h"
+#include "opintl.h"
/* ??? The layout of this stuff is still work in progress.
For speed in assembly/disassembly, we use inline functions. That of course
compiled with GCC), or switch to macros, or use something else.
*/
+static const char * insert_normal
+ PARAMS ((long, unsigned int, int, int, int, char *));
static const char * parse_insn_normal
PARAMS ((const CGEN_INSN *, const char **, CGEN_FIELDS *));
static const char * insert_insn_normal
- PARAMS ((const CGEN_INSN *, CGEN_FIELDS *, cgen_insn_t *));
+ PARAMS ((const CGEN_INSN *, CGEN_FIELDS *, cgen_insn_t *, bfd_vma));
+\f
+/* -- assembler routines inserted here */
\f
/* Default insertion routine.
store insn in `field' struct and add registers, etc. while parsing? */
static const char *
-insert_normal (value, attrs, start, length, shift, total_length, buffer)
+insert_normal (value, attrs, start, length, total_length, buffer)
long value;
unsigned int attrs;
int start;
int length;
- int shift;
int total_length;
char * buffer;
{
bfd_vma x;
static char buf[100];
+ /* Written this way to avoid undefined behaviour.
+ Yes, `long' will be bfd_vma but not yet. */
+ long mask = (((1L << (length - 1)) - 1) << 1) | 1;
- if (shift < 0)
- value <<= -shift;
- else
- value >>= shift;
+ /* If LENGTH is zero, this operand doesn't contribute to the value. */
+ if (length == 0)
+ return NULL;
/* Ensure VALUE will fit. */
- if ((attrs & (1 << CGEN_OPERAND_UNSIGNED)) != 0)
+ if ((attrs & CGEN_ATTR_MASK (CGEN_OPERAND_UNSIGNED)) != 0)
{
- unsigned long max = (1 << length) - 1;
+ unsigned long max = mask;
if ((unsigned long) value > max)
{
- const char *err = "operand out of range (%lu not between 0 and %lu)";
-
- sprintf (buf, err, value, max);
+ /* xgettext:c-format */
+ sprintf (buf, _("operand out of range (%lu not between 0 and %lu)"),
+ value, max);
return buf;
}
}
else
{
- long min = - (1 << (length - 1));
- long max = (1 << (length - 1)) - 1;
+ long min = - (1L << (length - 1));
+ long max = (1L << (length - 1)) - 1;
if (value < min || value > max)
{
- const char *err = "operand out of range (%ld not between %ld and %ld)";
-
- sprintf (buf, err, value, min, max);
+ sprintf
+ /* xgettext:c-format */
+ (buf, _("operand out of range (%ld not between %ld and %ld)"),
+ value, min, max);
return buf;
}
}
#if 0 /*def CGEN_INT_INSN*/
- *buffer |= ((value & ((1 << length) - 1))
- << (total_length - (start + length)));
+ *buffer |= (value & mask) << (total_length - (start + length));
#else
switch (total_length)
{
abort ();
}
- x |= ((value & ((1 << length) - 1))
- << (total_length - (start + length)));
+ x |= (value & mask) << (total_length - (start + length));
switch (total_length)
{
return NULL;
}
\f
-/* -- assembler routines inserted here */
-\f
/* Default insn parser.
The syntax string is scanned and operands are parsed and stored in FIELDS.
const char * p;
const unsigned char * syn;
#ifdef CGEN_MNEMONIC_OPERANDS
+ /* FIXME: wip */
int past_opcode_p;
#endif
p = CGEN_INSN_MNEMONIC (insn);
while (* p && * p == * str)
++ p, ++ str;
+
if (* p || (* str && !isspace (* str)))
- return "unrecognized instruction";
+ return _("unrecognized instruction");
CGEN_INIT_PARSE ();
cgen_init_parse_operand ();
while (* syn != 0)
{
/* Non operand chars must match exactly. */
- /* FIXME: Need to better handle whitespace. */
if (CGEN_SYNTAX_CHAR_P (* syn))
{
if (*str == CGEN_SYNTAX_CHAR (* syn))
/* Syntax char didn't match. Can't be this insn. */
/* FIXME: would like to return something like
"expected char `c'" */
- return "syntax error";
+ return _("syntax error");
}
continue;
}
++ str;
if (* str != '\0')
- return "junk at end of line"; /* FIXME: would like to include `str' */
+ return _("junk at end of line"); /* FIXME: would like to include `str' */
return NULL;
}
/* FIXME: change buffer to char *? */
static const char *
-insert_insn_normal (insn, fields, buffer)
+insert_insn_normal (insn, fields, buffer, pc)
const CGEN_INSN * insn;
CGEN_FIELDS * fields;
cgen_insn_t * buffer;
+ bfd_vma pc;
{
const CGEN_SYNTAX * syntax = CGEN_INSN_SYNTAX (insn);
bfd_vma value;
continue;
errmsg = @arch@_cgen_insert_operand (CGEN_SYNTAX_FIELD (*syn), fields,
- (char *) buffer);
+ (char *) buffer, pc);
if (errmsg)
return errmsg;
}
This routine is called for each instruction to be assembled.
STR points to the insn to be assembled.
We assume all necessary tables have been initialized.
+ The assembled instruction, less any fixups, is stored in buf.
+ [??? What byte order?]
The result is a pointer to the insn's entry in the opcode table,
or NULL if an error occured (an error message will have already been
- printed). */
+ printed).
+
+ Note that when processing (non-alias) macro-insns,
+ this function recurses. */
const CGEN_INSN *
@arch@_cgen_assemble_insn (str, fields, buf, errmsg)
continue;
#endif
-#if 1 /* FIXME: wip */
/* If the RELAX attribute is set, this is an insn that shouldn't be
chosen immediately. Instead, it is used during assembler/linker
relaxation if possible. */
if (CGEN_INSN_ATTR (insn, CGEN_INSN_RELAX) != 0)
continue;
-#endif
str = start;
if (! CGEN_PARSE_FN (insn) (insn, & str, fields))
{
- if (CGEN_INSERT_FN (insn) (insn, fields, buf) != NULL)
+ /* ??? 0 is passed for `pc' */
+ if (CGEN_INSERT_FN (insn) (insn, fields, buf, (bfd_vma) 0) != NULL)
continue;
/* It is up to the caller to actually output the insn and any
queued relocs. */
Need to track why it failed and pick the right one. */
{
static char errbuf[100];
- sprintf (errbuf, "bad instruction `%.50s%s'",
- start, strlen (start) > 50 ? "..." : "");
+ if (strlen (start) > 50)
+ /* xgettext:c-format */
+ sprintf (errbuf, _("bad instruction `%.50s...'"), start);
+ else
+ /* xgettext:c-format */
+ sprintf (errbuf, _("bad instruction `%.50s'"), start);
+
*errmsg = errbuf;
return NULL;
}