Back to index

cell-binutils  2.17cvs20070401
Classes | Defines | Functions | Variables
z8kgen.c File Reference
#include <stdio.h>
#include "sysdep.h"
#include "libiberty.h"

Go to the source code of this file.

Classes

struct  op
struct  tok_struct

Defines

#define BYTE_INFO_LEN   10
#define iswhite(x)   ((x) == ' ' || (x) == '\t')

Functions

static int count (void)
static int func (struct op *a, struct op *b)
static char * translate (struct tok_struct *table, char *x, int *length)
static void chewbits (char *bits, int *length)
static int chewname (char **name)
static void sub (char *x, char c)
static void print_type (struct op *n)
static void internal (void)
static void gas (void)
int main (int ac, char **av)

Variables

static struct op []
static struct tok_struct []

Class Documentation

struct op

Definition at line 28 of file z8kgen.c.

Class Members
char * bits
int cycles
char * flags
char * flavor
char * name
char type
struct tok_struct

Definition at line 582 of file z8kgen.c.

Class Members
int length
char * match
char * token

Define Documentation

#define BYTE_INFO_LEN   10

Definition at line 26 of file z8kgen.c.

#define iswhite (   x)    ((x) == ' ' || (x) == '\t')

Definition at line 38 of file z8kgen.c.


Function Documentation

static void chewbits ( char *  bits,
int length 
) [static]

Definition at line 758 of file z8kgen.c.

{
  int n = 0;

  *length = 0;
  printf ("{");
  while (*bits)
    {
      while (*bits == ' ')
       {
         bits++;
       }
      bits = translate (toks, bits, length);
      n++;
      printf (",");

    }
  while (n < BYTE_INFO_LEN - 1)
    {
      printf ("0,");
      n++;
    }
  printf ("}");
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int chewname ( char **  name) [static]

Definition at line 784 of file z8kgen.c.

{
  char *n;
  int nargs = 0;

  n = *name;
  while (*n && !iswhite (*n))
    n++;

  if (*n)
    {
      size_t len = n - *name;
      char *newname = xmalloc (len + 1);
      memcpy (newname, *name, len);
      newname[len] = 0;
      *name = newname;
    }

  printf ("\"%s\",OPC_%s,0,{", *name, *name);

  /* Scan the operands and make entries for them.
     Remember indirect things.  */
  while (*n)
    {
      int d;

      while (*n == ',' || iswhite (*n))
       n++;
      nargs++;
      n = translate (args, n, &d);
      printf (",");
    }
  if (nargs == 0)
    {
      printf ("0");
    }
  printf ("},");
  return nargs;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int count ( void  ) [static]

Definition at line 555 of file z8kgen.c.

{
  struct op *p = opt;
  int r = 0;

  while (p->name)
    {
      r++;
      p++;
    }
  return r;

}

Here is the call graph for this function:

static int func ( struct op a,
struct op b 
) [static]

Definition at line 570 of file z8kgen.c.

{
  return strcmp ((a)->name, (b)->name);
}

Here is the call graph for this function:

static void gas ( void  ) [static]

Definition at line 957 of file z8kgen.c.

{
  int c = count ();
  struct op *p = opt;
  int idx = -1;
  char *oldname = "";
  struct op *new = xmalloc (sizeof (struct op) * c);

  memcpy (new, p, c * sizeof (struct op));

  /* Sort all names in table alphabetically.  */
  qsort (new, c, sizeof (struct op), (int (*)(const void *, const void *)) func);

  printf ("/* DO NOT EDIT!  -*- buffer-read-only: t -*-\n");
  printf ("   This file is automatically generated by z8kgen.  */\n\n");

  printf ("#define ARG_MASK         0x0f\n");

  printf ("#define ARG_SRC          0x01\n");
  printf ("#define ARG_DST          0x02\n");

  printf ("#define ARG_RS           0x01\n");
  printf ("#define ARG_RD           0x02\n");
  printf ("#define ARG_RA           0x03\n");
  printf ("#define ARG_RB           0x04\n");
  printf ("#define ARG_RR           0x05\n");
  printf ("#define ARG_RX           0x06\n");

  printf ("#define ARG_IMM4         0x01\n");
  printf ("#define ARG_IMM8         0x02\n");
  printf ("#define ARG_IMM16        0x03\n");
  printf ("#define ARG_IMM32        0x04\n");
  printf ("#define ARG_IMMN         0x05\n");
  printf ("#define ARG_IMMNMINUS1   0x05\n");
  printf ("#define ARG_IMM_1        0x06\n");
  printf ("#define ARG_IMM_2        0x07\n");
  printf ("#define ARG_DISP16       0x08\n");
  printf ("#define ARG_NIM8         0x09\n");
  printf ("#define ARG_IMM2         0x0a\n");
  printf ("#define ARG_IMM1OR2      0x0b\n");

  printf ("#define ARG_DISP12       0x0b\n");
  printf ("#define ARG_NIM4         0x0c\n");
  printf ("#define ARG_DISP8        0x0c\n");
  printf ("#define ARG_IMM4M1       0x0d\n");

  printf ("#define CLASS_X          0x10\n");
  printf ("#define CLASS_BA         0x20\n");
  printf ("#define CLASS_DA         0x30\n");
  printf ("#define CLASS_BX         0x40\n");
  printf ("#define CLASS_DISP       0x50\n");
  printf ("#define CLASS_IMM        0x60\n");
  printf ("#define CLASS_CC         0x70\n");
  printf ("#define CLASS_CTRL       0x80\n");
  printf ("#define CLASS_IGNORE     0x90\n");
  printf ("#define CLASS_ADDRESS    0xd0\n");
  printf ("#define CLASS_0CCC       0xe0\n");
  printf ("#define CLASS_1CCC       0xf0\n");
  printf ("#define CLASS_0DISP7    0x100\n");
  printf ("#define CLASS_1DISP7    0x200\n");
  printf ("#define CLASS_01II      0x300\n");
  printf ("#define CLASS_00II      0x400\n");
  printf ("#define CLASS_BIT       0x500\n");
  printf ("#define CLASS_FLAGS     0x600\n");
  printf ("#define CLASS_IR        0x700\n");
  printf ("#define CLASS_IRO       0x800\n");
  printf ("#define CLASS_DISP8     0x900\n");

  printf ("#define CLASS_BIT_1OR2  0xa00\n");
  printf ("#define CLASS_REG       0x7000\n");
  printf ("#define CLASS_REG_BYTE  0x2000\n");
  printf ("#define CLASS_REG_WORD  0x3000\n");
  printf ("#define CLASS_REG_QUAD  0x4000\n");
  printf ("#define CLASS_REG_LONG  0x5000\n");
  printf ("#define CLASS_REGN0     0x8000\n");
  printf ("#define CLASS_PR       0x10000\n");
  printf ("#define CLASS_MASK     0x1fff0\n");

  printf ("#define OPC_adc      0\n");
  printf ("#define OPC_adcb     1\n");
  printf ("#define OPC_add      2\n");
  printf ("#define OPC_addb     3\n");
  printf ("#define OPC_addl     4\n");
  printf ("#define OPC_and      5\n");
  printf ("#define OPC_andb     6\n");
  printf ("#define OPC_bit      7\n");
  printf ("#define OPC_bitb     8\n");
  printf ("#define OPC_call     9\n");
  printf ("#define OPC_calr    10\n");
  printf ("#define OPC_clr     11\n");
  printf ("#define OPC_clrb    12\n");
  printf ("#define OPC_com     13\n");
  printf ("#define OPC_comb    14\n");
  printf ("#define OPC_comflg  15\n");
  printf ("#define OPC_cp      16\n");
  printf ("#define OPC_cpb     17\n");
  printf ("#define OPC_cpd     18\n");
  printf ("#define OPC_cpdb    19\n");
  printf ("#define OPC_cpdr    20\n");
  printf ("#define OPC_cpdrb   21\n");
  printf ("#define OPC_cpi     22\n");
  printf ("#define OPC_cpib    23\n");
  printf ("#define OPC_cpir    24\n");
  printf ("#define OPC_cpirb   25\n");
  printf ("#define OPC_cpl     26\n");
  printf ("#define OPC_cpsd    27\n");
  printf ("#define OPC_cpsdb   28\n");
  printf ("#define OPC_cpsdr   29\n");
  printf ("#define OPC_cpsdrb  30\n");
  printf ("#define OPC_cpsi    31\n");
  printf ("#define OPC_cpsib   32\n");
  printf ("#define OPC_cpsir   33\n");
  printf ("#define OPC_cpsirb  34\n");
  printf ("#define OPC_dab     35\n");
  printf ("#define OPC_dbjnz   36\n");
  printf ("#define OPC_dec     37\n");
  printf ("#define OPC_decb    38\n");
  printf ("#define OPC_di      39\n");
  printf ("#define OPC_div     40\n");
  printf ("#define OPC_divl    41\n");
  printf ("#define OPC_djnz    42\n");
  printf ("#define OPC_ei      43\n");
  printf ("#define OPC_ex      44\n");
  printf ("#define OPC_exb     45\n");
  printf ("#define OPC_exts    46\n");
  printf ("#define OPC_extsb   47\n");
  printf ("#define OPC_extsl   48\n");
  printf ("#define OPC_halt    49\n");
  printf ("#define OPC_in      50\n");
  printf ("#define OPC_inb     51\n");
  printf ("#define OPC_inc     52\n");
  printf ("#define OPC_incb    53\n");
  printf ("#define OPC_ind     54\n");
  printf ("#define OPC_indb    55\n");
  printf ("#define OPC_indr    56\n");
  printf ("#define OPC_indrb   57\n");
  printf ("#define OPC_ini     58\n");
  printf ("#define OPC_inib    59\n");
  printf ("#define OPC_inir    60\n");
  printf ("#define OPC_inirb   61\n");
  printf ("#define OPC_iret    62\n");
  printf ("#define OPC_jp      63\n");
  printf ("#define OPC_jr      64\n");
  printf ("#define OPC_ld      65\n");
  printf ("#define OPC_lda     66\n");
  printf ("#define OPC_ldar    67\n");
  printf ("#define OPC_ldb     68\n");
  printf ("#define OPC_ldctl   69\n");
  printf ("#define OPC_ldir    70\n");
  printf ("#define OPC_ldirb   71\n");
  printf ("#define OPC_ldk     72\n");
  printf ("#define OPC_ldl     73\n");
  printf ("#define OPC_ldm     74\n");
  printf ("#define OPC_ldps    75\n");
  printf ("#define OPC_ldr     76\n");
  printf ("#define OPC_ldrb    77\n");
  printf ("#define OPC_ldrl    78\n");
  printf ("#define OPC_mbit    79\n");
  printf ("#define OPC_mreq    80\n");
  printf ("#define OPC_mres    81\n");
  printf ("#define OPC_mset    82\n");
  printf ("#define OPC_mult    83\n");
  printf ("#define OPC_multl   84\n");
  printf ("#define OPC_neg     85\n");
  printf ("#define OPC_negb    86\n");
  printf ("#define OPC_nop     87\n");
  printf ("#define OPC_or      88\n");
  printf ("#define OPC_orb     89\n");
  printf ("#define OPC_otdr    90\n");
  printf ("#define OPC_otdrb   91\n");
  printf ("#define OPC_otir    92\n");
  printf ("#define OPC_otirb   93\n");
  printf ("#define OPC_out     94\n");
  printf ("#define OPC_outb    95\n");
  printf ("#define OPC_outd    96\n");
  printf ("#define OPC_outdb   97\n");
  printf ("#define OPC_outi    98\n");
  printf ("#define OPC_outib   99\n");
  printf ("#define OPC_pop    100\n");
  printf ("#define OPC_popl   101\n");
  printf ("#define OPC_push   102\n");
  printf ("#define OPC_pushl  103\n");
  printf ("#define OPC_res    104\n");
  printf ("#define OPC_resb   105\n");
  printf ("#define OPC_resflg 106\n");
  printf ("#define OPC_ret    107\n");
  printf ("#define OPC_rl     108\n");
  printf ("#define OPC_rlb    109\n");
  printf ("#define OPC_rlc    110\n");
  printf ("#define OPC_rlcb   111\n");
  printf ("#define OPC_rldb   112\n");
  printf ("#define OPC_rr     113\n");
  printf ("#define OPC_rrb    114\n");
  printf ("#define OPC_rrc    115\n");
  printf ("#define OPC_rrcb   116\n");
  printf ("#define OPC_rrdb   117\n");
  printf ("#define OPC_sbc    118\n");
  printf ("#define OPC_sbcb   119\n");
  printf ("#define OPC_sda    120\n");
  printf ("#define OPC_sdab   121\n");
  printf ("#define OPC_sdal   122\n");
  printf ("#define OPC_sdl    123\n");
  printf ("#define OPC_sdlb   124\n");
  printf ("#define OPC_sdll   125\n");
  printf ("#define OPC_set    126\n");
  printf ("#define OPC_setb   127\n");
  printf ("#define OPC_setflg 128\n");
  printf ("#define OPC_sin    129\n");
  printf ("#define OPC_sinb   130\n");
  printf ("#define OPC_sind   131\n");
  printf ("#define OPC_sindb  132\n");
  printf ("#define OPC_sindr  133\n");
  printf ("#define OPC_sindrb 134\n");
  printf ("#define OPC_sini   135\n");
  printf ("#define OPC_sinib  136\n");
  printf ("#define OPC_sinir  137\n");
  printf ("#define OPC_sinirb 138\n");
  printf ("#define OPC_sla    139\n");
  printf ("#define OPC_slab   140\n");
  printf ("#define OPC_slal   141\n");
  printf ("#define OPC_sll    142\n");
  printf ("#define OPC_sllb   143\n");
  printf ("#define OPC_slll   144\n");
  printf ("#define OPC_sotdr  145\n");
  printf ("#define OPC_sotdrb 146\n");
  printf ("#define OPC_sotir  147\n");
  printf ("#define OPC_sotirb 148\n");
  printf ("#define OPC_sout   149\n");
  printf ("#define OPC_soutb  150\n");
  printf ("#define OPC_soutd  151\n");
  printf ("#define OPC_soutdb 152\n");
  printf ("#define OPC_souti  153\n");
  printf ("#define OPC_soutib 154\n");
  printf ("#define OPC_sra    155\n");
  printf ("#define OPC_srab   156\n");
  printf ("#define OPC_sral   157\n");
  printf ("#define OPC_srl    158\n");
  printf ("#define OPC_srlb   159\n");
  printf ("#define OPC_srll   160\n");
  printf ("#define OPC_sub    161\n");
  printf ("#define OPC_subb   162\n");
  printf ("#define OPC_subl   163\n");
  printf ("#define OPC_tcc    164\n");
  printf ("#define OPC_tccb   165\n");
  printf ("#define OPC_test   166\n");
  printf ("#define OPC_testb  167\n");
  printf ("#define OPC_testl  168\n");
  printf ("#define OPC_trdb   169\n");
  printf ("#define OPC_trdrb  170\n");
  printf ("#define OPC_trib   171\n");
  printf ("#define OPC_trirb  172\n");
  printf ("#define OPC_trtdrb 173\n");
  printf ("#define OPC_trtib  174\n");
  printf ("#define OPC_trtirb 175\n");
  printf ("#define OPC_trtrb  176\n");
  printf ("#define OPC_tset   177\n");
  printf ("#define OPC_tsetb  178\n");
  printf ("#define OPC_xor    179\n");
  printf ("#define OPC_xorb   180\n");

  printf ("#define OPC_ldd    181\n");
  printf ("#define OPC_lddb   182\n");
  printf ("#define OPC_lddr   183\n");
  printf ("#define OPC_lddrb  184\n");
  printf ("#define OPC_ldi    185\n");
  printf ("#define OPC_ldib   186\n");
  printf ("#define OPC_sc     187\n");
  printf ("#define OPC_bpt    188\n");
  printf ("#define OPC_ext0e  188\n");
  printf ("#define OPC_ext0f  188\n");
  printf ("#define OPC_ext8e  188\n");
  printf ("#define OPC_ext8f  188\n");
  printf ("#define OPC_rsvd36 188\n");
  printf ("#define OPC_rsvd38 188\n");
  printf ("#define OPC_rsvd78 188\n");
  printf ("#define OPC_rsvd7e 188\n");
  printf ("#define OPC_rsvd9d 188\n");
  printf ("#define OPC_rsvd9f 188\n");
  printf ("#define OPC_rsvdb9 188\n");
  printf ("#define OPC_rsvdbf 188\n");
  printf ("#define OPC_ldctlb 189\n");
  printf ("#define OPC_trtdb  190\n");
  printf ("#define OPC_brk    191\n");
#if 0
  for (i = 0; toks[i].token; i++)
    printf ("#define %s\t0x%x\n", toks[i].token, i * 16);
#endif
  printf ("\ntypedef struct {\n");

  printf ("#ifdef NICENAMES\n");
  printf ("  const char *nicename;\n");
  printf ("  int type;\n");
  printf ("  int cycles;\n");
  printf ("  int flags;\n");
  printf ("#endif\n");
  printf ("  const char *name;\n");
  printf ("  unsigned char opcode;\n");
  printf ("  void (*func) (void);\n");
  printf ("  unsigned int arg_info[4];\n");
  printf ("  unsigned int byte_info[%d];\n", BYTE_INFO_LEN);
  printf ("  int noperands;\n");
  printf ("  int length;\n");
  printf ("  int idx;\n");
  printf ("} opcode_entry_type;\n\n");
  printf ("#ifdef DEFINE_TABLE\n");
  printf ("const opcode_entry_type z8k_table[] = {\n");

  while (new->flags && new->flags[0])
    {
      int nargs;
      int length;

      printf ("\n/* %s *** %s */\n", new->bits, new->name);
      printf ("{\n");

      printf ("#ifdef NICENAMES\n");
      printf ("\"%s\",%d,%d,", new->name, new->type, new->cycles);
      {
       int answer = 0;
       char *p = new->flags;

       while (*p)
         {
           answer <<= 1;

           if (*p != '-')
             answer |= 1;
           p++;
         }
       printf ("0x%02x,\n", answer);
      }

      printf ("#endif\n");

      nargs = chewname (&new->name);

      printf ("\n\t");
      chewbits (new->bits, &length);
      length /= 2;
      if (length & 1)
       abort();

      if (strcmp (oldname, new->name) != 0)
       idx++;
      printf (",%d,%d,%d", nargs, length, idx);
      oldname = new->name;
      printf ("},\n");
      new++;
    }
  printf ("\n/* end marker */\n");
  printf ("{\n#ifdef NICENAMES\nNULL,0,0,\n0,\n#endif\n");
  printf ("NULL,0,0,{0,0,0,0},{0,0,0,0,0,0,0,0,0,0},0,0,0}\n};\n");
  printf ("#endif\n");
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void internal ( void  ) [static]

Definition at line 904 of file z8kgen.c.

{
  int c = count ();
  struct op *new = xmalloc (sizeof (struct op) * c);
  struct op *p = opt;
  memcpy (new, p, c * sizeof (struct op));

  /* Sort all names in table alphabetically.  */
  qsort (new, c, sizeof (struct op), (int (*)(const void *, const void *))func);

  p = new;
  while (p->flags && p->flags[0] != '*')
  {
    /* If there are any @rs, sub the ssss into a ssn0, (rs), (ssn0).  */
    int loop = 1;

    printf ("\"%s\",%2d, ", p->flags, p->cycles);
    while (loop)
    {
      char *s = p->name;

      loop = 0;
      while (*s)
      {
       if (s[0] == '@')
       {
         char c;

         /* Skip the r and sub the string.  */
         s++;
         c = s[1];
         sub (p->bits, c);
       }
       if (s[0] == '(' && s[3] == ')')
       {
         sub (p->bits, s[2]);
       }
       if (s[0] == '(')
       {
         sub (p->bits, s[-1]);
       }

       s++;
      }

    }
    print_type (p);
    printf ("\"%s\",\"%s\",0,\n", p->bits, p->name);
    p++;
  }
}

Here is the call graph for this function:

int main ( int  ac,
char **  av 
)

Definition at line 1313 of file z8kgen.c.

{
  struct op *p = opt;

  if (ac == 2 && strcmp (av[1], "-t") == 0)
    {
      internal ();
    }
  else if (ac == 2 && strcmp (av[1], "-h") == 0)
    {
      while (p->name)
       {
         printf ("%-25s\t%s\n", p->name, p->bits);
         p++;
       }
    }

  else if (ac == 2 && strcmp (av[1], "-a") == 0)
    {
      gas ();
    }
  else
    {
      printf ("Usage: %s -t\n", av[0]);
      printf ("-t : generate new internal table\n");
      printf ("-a : generate new table for gas\n");
      printf ("-h : generate new table for humans\n");
    }
  return 0;
}

Here is the call graph for this function:

static void print_type ( struct op n) [static]

Definition at line 878 of file z8kgen.c.

{
#ifdef WORK_TYPE
  while (*s && !iswhite (*s))
    {
      l = *s;
      s++;
    }
  switch (l)
    {
    case 'l':
      printf ("32,");
      break;
    case 'b':
      printf ("8,");
      break;
    default:
      printf ("16,");
      break;
    }
#else
  printf ("%2d,", n->type);
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void sub ( char *  x,
char  c 
) [static]

Definition at line 825 of file z8kgen.c.

{
  while (*x)
    {
      if (x[0] == c && x[1] == c &&
         x[2] == c && x[3] == c)
       {
         x[2] = 'N';
         x[3] = '0';
       }
      x++;
    }
}
static char* translate ( struct tok_struct table,
char *  x,
int length 
) [static]

Definition at line 730 of file z8kgen.c.

{

  int found;

  found = 0;
  while (table->match)
    {
      int l = strlen (table->match);

      if (strncmp (table->match, x, l) == 0)
       {
         /* Got a hit */
         printf ("%s", table->token);
         *length += table->length;
         return x + l;
       }

      table++;
    }
  fprintf (stderr, "Can't find %s\n", x);
  printf ("**** Can't find %s\n", x);
  while (*x)
    x++;
  return x;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

struct op[] [static]

Definition at line 39 of file z8kgen.c.

static struct tok_struct [static]

Definition at line 589 of file z8kgen.c.