Back to index

cell-binutils  2.17cvs20070401
Defines | Functions
cgen-opc.c File Reference
#include "sysdep.h"
#include <stdio.h>
#include "ansidecl.h"
#include "libiberty.h"
#include "safe-ctype.h"
#include "bfd.h"
#include "symcat.h"
#include "opcode/cgen.h"

Go to the source code of this file.

Defines

#define KEYWORD_HASH_SIZE(n)   ((n) <= 31 ? 17 : 31)

Functions

static unsigned int hash_keyword_name (const CGEN_KEYWORD *, const char *, int)
static unsigned int hash_keyword_value (const CGEN_KEYWORD *, unsigned int)
static void build_keyword_hash_tables (CGEN_KEYWORD *)
const CGEN_KEYWORD_ENTRYcgen_keyword_lookup_name (CGEN_KEYWORD *kt, const char *name)
const CGEN_KEYWORD_ENTRYcgen_keyword_lookup_value (CGEN_KEYWORD *kt, int value)
void cgen_keyword_add (CGEN_KEYWORD *kt, CGEN_KEYWORD_ENTRY *ke)
CGEN_KEYWORD_SEARCH cgen_keyword_search_init (CGEN_KEYWORD *kt, const char *spec)
const CGEN_KEYWORD_ENTRYcgen_keyword_search_next (CGEN_KEYWORD_SEARCH *search)
const CGEN_HW_ENTRYcgen_hw_lookup_by_name (CGEN_CPU_DESC cd, const char *name)
const CGEN_HW_ENTRYcgen_hw_lookup_by_num (CGEN_CPU_DESC cd, unsigned int hwnum)
const CGEN_OPERANDcgen_operand_lookup_by_name (CGEN_CPU_DESC cd, const char *name)
const CGEN_OPERANDcgen_operand_lookup_by_num (CGEN_CPU_DESC cd, int opnum)
int cgen_insn_count (CGEN_CPU_DESC cd)
int cgen_macro_insn_count (CGEN_CPU_DESC cd)
CGEN_INSN_INT cgen_get_insn_value (CGEN_CPU_DESC cd, unsigned char *buf, int length)
void cgen_put_insn_value (CGEN_CPU_DESC cd, unsigned char *buf, int length, CGEN_INSN_INT value)
const CGEN_INSN * cgen_lookup_insn (CGEN_CPU_DESC cd, const CGEN_INSN *insn, CGEN_INSN_INT insn_int_value, unsigned char *insn_bytes_value, int length, CGEN_FIELDS *fields, int alias_p)
void cgen_get_insn_operands (CGEN_CPU_DESC cd, const CGEN_INSN *insn, const CGEN_FIELDS *fields, int *indices)
const CGEN_INSN * cgen_lookup_get_insn_operands (CGEN_CPU_DESC cd, const CGEN_INSN *insn, CGEN_INSN_INT insn_int_value, unsigned char *insn_bytes_value, int length, int *indices, CGEN_FIELDS *fields)
void cgen_set_signed_overflow_ok (CGEN_CPU_DESC cd)
void cgen_clear_signed_overflow_ok (CGEN_CPU_DESC cd)
unsigned int cgen_signed_overflow_ok_p (CGEN_CPU_DESC cd)

Define Documentation

#define KEYWORD_HASH_SIZE (   n)    ((n) <= 31 ? 17 : 31)

Definition at line 43 of file cgen-opc.c.


Function Documentation

static void build_keyword_hash_tables ( CGEN_KEYWORD kt) [static]

Definition at line 240 of file cgen-opc.c.

{
  int i;
  /* Use the number of compiled in entries as an estimate for the
     typical sized table [not too many added at runtime].  */
  unsigned int size = KEYWORD_HASH_SIZE (kt->num_init_entries);

  kt->hash_table_size = size;
  kt->name_hash_table = (CGEN_KEYWORD_ENTRY **)
    xmalloc (size * sizeof (CGEN_KEYWORD_ENTRY *));
  memset (kt->name_hash_table, 0, size * sizeof (CGEN_KEYWORD_ENTRY *));
  kt->value_hash_table = (CGEN_KEYWORD_ENTRY **)
    xmalloc (size * sizeof (CGEN_KEYWORD_ENTRY *));
  memset (kt->value_hash_table, 0, size * sizeof (CGEN_KEYWORD_ENTRY *));

  /* The table is scanned backwards as we want keywords appearing earlier to
     be prefered over later ones.  */
  for (i = kt->num_init_entries - 1; i >= 0; --i)
    cgen_keyword_add (kt, &kt->init_entries[i]);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 605 of file cgen-opc.c.

{
  cd->signed_overflow_ok_p = 0;
}

Here is the caller graph for this function:

void cgen_get_insn_operands ( CGEN_CPU_DESC  cd,
const CGEN_INSN *  insn,
const CGEN_FIELDS *  fields,
int indices 
)

Definition at line 545 of file cgen-opc.c.

{
  const CGEN_OPINST *opinst;
  int i;

  if (insn->opinst == NULL)
    abort ();
  for (i = 0, opinst = insn->opinst; opinst->type != CGEN_OPINST_END; ++i, ++opinst)
    {
      enum cgen_operand_type op_type = opinst->op_type;
      if (op_type == CGEN_OPERAND_NIL)
       indices[i] = opinst->index;
      else
       indices[i] = (*cd->get_int_operand) (cd, op_type, fields);
    }
}

Here is the caller graph for this function:

CGEN_INSN_INT cgen_get_insn_value ( CGEN_CPU_DESC  cd,
unsigned char *  buf,
int  length 
)

Definition at line 364 of file cgen-opc.c.

{
  int big_p = (cd->insn_endian == CGEN_ENDIAN_BIG);
  int insn_chunk_bitsize = cd->insn_chunk_bitsize;
  CGEN_INSN_INT value = 0;

  if (insn_chunk_bitsize != 0 && insn_chunk_bitsize < length)
    {
      /* We need to divide up the incoming value into insn_chunk_bitsize-length
        segments, and endian-convert them, one at a time. */
      int i;

      /* Enforce divisibility. */ 
      if ((length % insn_chunk_bitsize) != 0)
       abort ();

      for (i = 0; i < length; i += insn_chunk_bitsize) /* NB: i == bits */
       {
         int index;
         bfd_vma this_value;
         index = i; /* NB: not dependent on endianness; opposite of cgen_put_insn_value! */
         this_value = bfd_get_bits (& buf[index / 8], insn_chunk_bitsize, big_p);
         value = (value << insn_chunk_bitsize) | this_value;
       }
    }
  else
    {
      value = bfd_get_bits (buf, length, cd->insn_endian == CGEN_ENDIAN_BIG);
    }

  return value;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 268 of file cgen-opc.c.

{
  unsigned int i;
  const CGEN_HW_ENTRY **hw = cd->hw_table.entries;

  for (i = 0; i < cd->hw_table.num_entries; ++i)
    if (hw[i] && strcmp (name, hw[i]->name) == 0)
      return hw[i];

  return NULL;
}

Here is the call graph for this function:

Definition at line 286 of file cgen-opc.c.

{
  unsigned int i;
  const CGEN_HW_ENTRY **hw = cd->hw_table.entries;

  /* ??? This can be speeded up.  */
  for (i = 0; i < cd->hw_table.num_entries; ++i)
    if (hw[i] && hwnum == hw[i]->type)
      return hw[i];

  return NULL;
}

Definition at line 335 of file cgen-opc.c.

{
  int count = cd->insn_table.num_init_entries;
  CGEN_INSN_LIST *rt_insns = cd->insn_table.new_entries;

  for ( ; rt_insns != NULL; rt_insns = rt_insns->next)
    ++count;

  return count;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 110 of file cgen-opc.c.

{
  unsigned int hash;
  size_t i;

  if (kt->name_hash_table == NULL)
    build_keyword_hash_tables (kt);

  hash = hash_keyword_name (kt, ke->name, 0);
  ke->next_name = kt->name_hash_table[hash];
  kt->name_hash_table[hash] = ke;

  hash = hash_keyword_value (kt, ke->value);
  ke->next_value = kt->value_hash_table[hash];
  kt->value_hash_table[hash] = ke;

  if (ke->name[0] == 0)
    kt->null_entry = ke;

  for (i = 1; i < strlen (ke->name); i++)
    if (! ISALNUM (ke->name[i])
       && ! strchr (kt->nonalpha_chars, ke->name[i]))
      {
       size_t idx = strlen (kt->nonalpha_chars);
       
       /* If you hit this limit, please don't just
          increase the size of the field, instead
          look for a better algorithm.  */
       if (idx >= sizeof (kt->nonalpha_chars) - 1)
         abort ();
       kt->nonalpha_chars[idx] = ke->name[i];
       kt->nonalpha_chars[idx+1] = 0;
      }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 49 of file cgen-opc.c.

{
  const CGEN_KEYWORD_ENTRY *ke;
  const char *p,*n;

  if (kt->name_hash_table == NULL)
    build_keyword_hash_tables (kt);

  ke = kt->name_hash_table[hash_keyword_name (kt, name, 0)];

  /* We do case insensitive comparisons.
     If that ever becomes a problem, add an attribute that denotes
     "do case sensitive comparisons".  */

  while (ke != NULL)
    {
      n = name;
      p = ke->name;

      while (*p
            && (*p == *n
               || (ISALPHA (*p) && (TOLOWER (*p) == TOLOWER (*n)))))
       ++n, ++p;

      if (!*p && !*n)
       return ke;

      ke = ke->next_name;
    }

  if (kt->null_entry)
    return kt->null_entry;
  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 88 of file cgen-opc.c.

{
  const CGEN_KEYWORD_ENTRY *ke;

  if (kt->name_hash_table == NULL)
    build_keyword_hash_tables (kt);

  ke = kt->value_hash_table[hash_keyword_value (kt, value)];

  while (ke != NULL)
    {
      if (value == ke->value)
       return ke;
      ke = ke->next_value;
    }

  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 156 of file cgen-opc.c.

{
  CGEN_KEYWORD_SEARCH search;

  /* FIXME: Need to specify format of params.  */
  if (spec != NULL)
    abort ();

  if (kt->name_hash_table == NULL)
    build_keyword_hash_tables (kt);

  search.table = kt;
  search.spec = spec;
  search.current_hash = 0;
  search.current_entry = NULL;
  return search;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 178 of file cgen-opc.c.

{
  /* Has search finished?  */
  if (search->current_hash == search->table->hash_table_size)
    return NULL;

  /* Search in progress?  */
  if (search->current_entry != NULL
      /* Anything left on this hash chain?  */
      && search->current_entry->next_name != NULL)
    {
      search->current_entry = search->current_entry->next_name;
      return search->current_entry;
    }

  /* Move to next hash chain [unless we haven't started yet].  */
  if (search->current_entry != NULL)
    ++search->current_hash;

  while (search->current_hash < search->table->hash_table_size)
    {
      search->current_entry = search->table->name_hash_table[search->current_hash];
      if (search->current_entry != NULL)
       return search->current_entry;
      ++search->current_hash;
    }

  return NULL;
}
const CGEN_INSN* cgen_lookup_get_insn_operands ( CGEN_CPU_DESC  cd,
const CGEN_INSN *  insn,
CGEN_INSN_INT  insn_int_value,
unsigned char *  insn_bytes_value,
int  length,
int indices,
CGEN_FIELDS *  fields 
)

Definition at line 576 of file cgen-opc.c.

{
  /* Pass non-zero for ALIAS_P only if INSN != NULL.
     If INSN == NULL, we want a real insn.  */
  insn = cgen_lookup_insn (cd, insn, insn_int_value, insn_bytes_value,
                        length, fields, insn != NULL);
  if (! insn)
    return NULL;

  cgen_get_insn_operands (cd, insn, fields, indices);
  return insn;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const CGEN_INSN* cgen_lookup_insn ( CGEN_CPU_DESC  cd,
const CGEN_INSN *  insn,
CGEN_INSN_INT  insn_int_value,
unsigned char *  insn_bytes_value,
int  length,
CGEN_FIELDS *  fields,
int  alias_p 
)

Definition at line 448 of file cgen-opc.c.

{
  unsigned char *buf;
  CGEN_INSN_INT base_insn;
  CGEN_EXTRACT_INFO ex_info;
  CGEN_EXTRACT_INFO *info;

  if (cd->int_insn_p)
    {
      info = NULL;
      buf = (unsigned char *) alloca (cd->max_insn_bitsize / 8);
      cgen_put_insn_value (cd, buf, length, insn_int_value);
      base_insn = insn_int_value;
    }
  else
    {
      info = &ex_info;
      ex_info.dis_info = NULL;
      ex_info.insn_bytes = insn_bytes_value;
      ex_info.valid = -1;
      buf = insn_bytes_value;
      base_insn = cgen_get_insn_value (cd, buf, length);
    }

  if (!insn)
    {
      const CGEN_INSN_LIST *insn_list;

      /* The instructions are stored in hash lists.
        Pick the first one and keep trying until we find the right one.  */

      insn_list = cgen_dis_lookup_insn (cd, (char *) buf, base_insn);
      while (insn_list != NULL)
       {
         insn = insn_list->insn;

         if (alias_p
             /* FIXME: Ensure ALIAS attribute always has same index.  */
             || ! CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_ALIAS))
           {
             /* Basic bit mask must be correct.  */
             /* ??? May wish to allow target to defer this check until the
               extract handler.  */
             if ((base_insn & CGEN_INSN_BASE_MASK (insn))
                == CGEN_INSN_BASE_VALUE (insn))
              {
                /* ??? 0 is passed for `pc' */
                int elength = CGEN_EXTRACT_FN (cd, insn)
                  (cd, insn, info, base_insn, fields, (bfd_vma) 0);
                if (elength > 0)
                  {
                    /* sanity check */
                    if (length != 0 && length != elength)
                     abort ();
                    return insn;
                  }
              }
           }

         insn_list = insn_list->next;
       }
    }
  else
    {
      /* Sanity check: can't pass an alias insn if ! alias_p.  */
      if (! alias_p
         && CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_ALIAS))
       abort ();
      /* Sanity check: length must be correct.  */
      if (length != CGEN_INSN_BITSIZE (insn))
       abort ();

      /* ??? 0 is passed for `pc' */
      length = CGEN_EXTRACT_FN (cd, insn)
       (cd, insn, info, base_insn, fields, (bfd_vma) 0);
      /* Sanity check: must succeed.
        Could relax this later if it ever proves useful.  */
      if (length == 0)
       abort ();
      return insn;
    }

  return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 350 of file cgen-opc.c.

{
  int count = cd->macro_insn_table.num_init_entries;
  CGEN_INSN_LIST *rt_insns = cd->macro_insn_table.new_entries;

  for ( ; rt_insns != NULL; rt_insns = rt_insns->next)
    ++count;

  return count;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 306 of file cgen-opc.c.

{
  unsigned int i;
  const CGEN_OPERAND **op = cd->operand_table.entries;

  for (i = 0; i < cd->operand_table.num_entries; ++i)
    if (op[i] && strcmp (name, op[i]->name) == 0)
      return op[i];

  return NULL;
}

Here is the call graph for this function:

Definition at line 325 of file cgen-opc.c.

{
  return cd->operand_table.entries[opnum];
}

Here is the caller graph for this function:

void cgen_put_insn_value ( CGEN_CPU_DESC  cd,
unsigned char *  buf,
int  length,
CGEN_INSN_INT  value 
)

Definition at line 400 of file cgen-opc.c.

{
  int big_p = (cd->insn_endian == CGEN_ENDIAN_BIG);
  int insn_chunk_bitsize = cd->insn_chunk_bitsize;

  if (insn_chunk_bitsize != 0 && insn_chunk_bitsize < length)
    {
      /* We need to divide up the incoming value into insn_chunk_bitsize-length
        segments, and endian-convert them, one at a time. */
      int i;

      /* Enforce divisibility. */ 
      if ((length % insn_chunk_bitsize) != 0)
       abort ();

      for (i = 0; i < length; i += insn_chunk_bitsize) /* NB: i == bits */
       {
         int index;
         index = (length - insn_chunk_bitsize - i); /* NB: not dependent on endianness! */
         bfd_put_bits ((bfd_vma) value, & buf[index / 8], insn_chunk_bitsize, big_p);
         value >>= insn_chunk_bitsize;
       }
    }
  else
    {
      bfd_put_bits ((bfd_vma) value, buf, length, big_p);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 598 of file cgen-opc.c.

{
  cd->signed_overflow_ok_p = 1;
}

Here is the caller graph for this function:

Definition at line 612 of file cgen-opc.c.

{
  return cd->signed_overflow_ok_p;
}

Here is the caller graph for this function:

static unsigned int hash_keyword_name ( const CGEN_KEYWORD kt,
const char *  name,
int  case_sensitive_p 
) [static]

Definition at line 212 of file cgen-opc.c.

{
  unsigned int hash;

  if (case_sensitive_p)
    for (hash = 0; *name; ++name)
      hash = (hash * 97) + (unsigned char) *name;
  else
    for (hash = 0; *name; ++name)
      hash = (hash * 97) + (unsigned char) TOLOWER (*name);
  return hash % kt->hash_table_size;
}

Here is the caller graph for this function:

static unsigned int hash_keyword_value ( const CGEN_KEYWORD kt,
unsigned int  value 
) [static]

Definition at line 230 of file cgen-opc.c.

{
  return value % kt->hash_table_size;
}

Here is the caller graph for this function: