Example #1
0
static void
build_asm_hash_table ()
{
  int i;
  unsigned int hash;
  int count = cgen_insn_count ();
  CGEN_OPCODE_DATA *data = cgen_current_opcode_data;
  CGEN_INSN_TABLE *insn_table = data->insn_table;
  unsigned int entry_size = insn_table->entry_size;
  unsigned int hash_size = insn_table->asm_hash_table_size;
  const CGEN_INSN *insn;
  CGEN_INSN_LIST *insn_lists,*new_insns;

  /* The space allocated for the hash table consists of two parts:
     the hash table and the hash lists.  */

  asm_hash_table = (CGEN_INSN_LIST **)
    xmalloc (hash_size * sizeof (CGEN_INSN_LIST *)
	     + count * sizeof (CGEN_INSN_LIST));
  memset (asm_hash_table, 0,
	  hash_size * sizeof (CGEN_INSN_LIST *)
	  + count * sizeof (CGEN_INSN_LIST));
  insn_lists = (CGEN_INSN_LIST *) (asm_hash_table + hash_size);

  /* Add compiled in insns.
     The table is scanned backwards as later additions are inserted in
     front of earlier ones and we want earlier ones to be prefered.
     We stop at the first one as it is a reserved entry.
     This is a bit tricky as the attribute member of CGEN_INSN is variable
     among architectures.  This code could be moved to cgen-asm.in, but
     I prefer to keep it here for now.  */

  for (insn = (CGEN_INSN *)
       ((char *) insn_table->init_entries
	+ entry_size * (insn_table->num_init_entries - 1));
       insn > insn_table->init_entries;
       insn = (CGEN_INSN *) ((char *) insn - entry_size), ++insn_lists)
    {
      hash = (*insn_table->asm_hash) CGEN_INSN_MNEMONIC (insn);
      insn_lists->next = asm_hash_table[hash];
      insn_lists->insn = insn;
      asm_hash_table[hash] = insn_lists;
    }

  /* Add runtime added insns.
     ??? Currently later added insns will be prefered over earlier ones.
     Not sure this is a bug or not.  */
  for (new_insns = insn_table->new_entries;
       new_insns != NULL;
       new_insns = new_insns->next, ++insn_lists)
    {
      hash = (*insn_table->asm_hash) CGEN_INSN_MNEMONIC (new_insns->insn);
      insn_lists->next = asm_hash_table[hash];
      insn_lists->insn = new_insns->insn;
      asm_hash_table[hash] = insn_lists;
    }
}
Example #2
0
static void
build_dis_hash_table (CGEN_CPU_DESC cd)
{
  int count = cgen_insn_count (cd) + cgen_macro_insn_count (cd);
  CGEN_INSN_TABLE *insn_table = & cd->insn_table;
  CGEN_INSN_TABLE *macro_insn_table = & cd->macro_insn_table;
  unsigned int hash_size = cd->dis_hash_size;
  CGEN_INSN_LIST *hash_entry_buf;
  CGEN_INSN_LIST **dis_hash_table;
  CGEN_INSN_LIST *dis_hash_table_entries;

  /* The space allocated for the hash table consists of two parts:
     the hash table and the hash lists.  */

  dis_hash_table = (CGEN_INSN_LIST **)
    xmalloc (hash_size * sizeof (CGEN_INSN_LIST *));
  memset (dis_hash_table, 0, hash_size * sizeof (CGEN_INSN_LIST *));
  dis_hash_table_entries = hash_entry_buf = (CGEN_INSN_LIST *)
    xmalloc (count * sizeof (CGEN_INSN_LIST));

  /* Add compiled in insns.
     Don't include the first one as it is a reserved entry.  */
  /* ??? It was the end of all hash chains, and also the special
     "invalid insn" marker.  May be able to do it differently now.  */

  hash_entry_buf = hash_insn_array (cd,
				    insn_table->init_entries + 1,
				    insn_table->num_init_entries - 1,
				    insn_table->entry_size,
				    dis_hash_table, hash_entry_buf);

  /* Add compiled in macro-insns.  */

  hash_entry_buf = hash_insn_array (cd, macro_insn_table->init_entries,
				    macro_insn_table->num_init_entries,
				    macro_insn_table->entry_size,
				    dis_hash_table, hash_entry_buf);

  /* Add runtime added insns.
     Later added insns will be prefered over earlier ones.  */

  hash_entry_buf = hash_insn_list (cd, insn_table->new_entries,
				   dis_hash_table, hash_entry_buf);

  /* Add runtime added macro-insns.  */

  hash_insn_list (cd, macro_insn_table->new_entries,
		  dis_hash_table, hash_entry_buf);

  cd->dis_hash_table = dis_hash_table;
  cd->dis_hash_table_entries = dis_hash_table_entries;
}