Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/opcodes/cgen-dis.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* CGEN generic disassembler support code.
    22
    3    Copyright 1996, 1997, 1998, 1999, 2000, 2001
     3   Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002
    44   Free Software Foundation, Inc.
    55
     
    2828#include "opcode/cgen.h"
    2929
     30static CGEN_INSN_LIST *  hash_insn_array      PARAMS ((CGEN_CPU_DESC, const CGEN_INSN *, int, int, CGEN_INSN_LIST **, CGEN_INSN_LIST *));
     31static CGEN_INSN_LIST *  hash_insn_list       PARAMS ((CGEN_CPU_DESC, const CGEN_INSN_LIST *, CGEN_INSN_LIST **, CGEN_INSN_LIST *));
     32static void              build_dis_hash_table PARAMS ((CGEN_CPU_DESC));
     33static int               count_decodable_bits PARAMS ((const CGEN_INSN *));
     34static void              add_insn_to_hash_chain PARAMS ((CGEN_INSN_LIST *,
     35                                                         const CGEN_INSN *,
     36                                                         CGEN_INSN_LIST **,
     37                                                         unsigned int));
     38
     39/* Return the number of decodable bits in this insn.  */
     40static int
     41count_decodable_bits (insn)
     42  const CGEN_INSN *insn;
     43{
     44  unsigned mask = CGEN_INSN_BASE_MASK (insn);
     45  int bits = 0;
     46  int m;
     47  for (m = 1; m != 0; m <<= 1)
     48    {
     49      if (mask & m)
     50        ++bits;
     51    }
     52  return bits;
     53}
     54
     55/* Add an instruction to the hash chain.  */     
     56static void
     57add_insn_to_hash_chain (hentbuf, insn, htable, hash)
     58     CGEN_INSN_LIST *hentbuf;
     59     const CGEN_INSN *insn;
     60     CGEN_INSN_LIST **htable;
     61     unsigned int hash;
     62{
     63  CGEN_INSN_LIST *current_buf;
     64  CGEN_INSN_LIST *previous_buf;
     65  int insn_decodable_bits;
     66
     67  /* Add insns sorted by the number of decodable bits, in decreasing order.
     68     This ensures that any insn which is a special case of another will be
     69     checked first.  */
     70  insn_decodable_bits = count_decodable_bits (insn);
     71  previous_buf = NULL;
     72  for (current_buf = htable[hash]; current_buf != NULL;
     73       current_buf = current_buf->next)
     74    {
     75      int current_decodable_bits = count_decodable_bits (current_buf->insn);
     76      if (insn_decodable_bits >= current_decodable_bits)
     77        break;
     78      previous_buf = current_buf;
     79    }
     80
     81  /* Now insert the new insn.  */
     82  hentbuf->insn = insn;
     83  hentbuf->next = current_buf;
     84  if (previous_buf == NULL)
     85    htable[hash] = hentbuf;
     86  else
     87    previous_buf->next = hentbuf;
     88}
     89
    3090/* Subroutine of build_dis_hash_table to add INSNS to the hash table.
    3191
     
    71131                    big_p);
    72132      hash = (* cd->dis_hash) (buf, value);
    73       hentbuf->next = htable[hash];
    74       hentbuf->insn = insn;
    75       htable[hash] = hentbuf;
     133      add_insn_to_hash_chain (hentbuf, insn, htable, hash);
    76134    }
    77135
     
    111169                   big_p);
    112170      hash = (* cd->dis_hash) (buf, value);
    113       hentbuf->next = htable [hash];
    114       hentbuf->insn = ilist->insn;
    115       htable [hash] = hentbuf;
     171      add_insn_to_hash_chain (hentbuf, ilist->insn, htable, hash);
    116172    }
    117173
Note: See TracChangeset for help on using the changeset viewer.