Back to index

cell-binutils  2.17cvs20070401
Classes | Defines | Typedefs | Functions | Variables
test-gen.c File Reference
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  insn_data
struct  func_arg
struct  func
struct  group_t

Defines

#define TEST_GEN_C   1
#define SIMPLIFY_OUTPUT   0
#define DISASSEMBLER_TEST   1
#define INSN_REPEAT   5
#define OUTPUT_RANDOMIZATION_COUNTER   0
#define define_insn(insname, funcs...)   func i_ ## insname[] = { funcs, { 0 } }
#define insn(insname)   (i_ ## insname)
#define comma   literal_q (", ", ", ?")
#define space   literal (" ")
#define tab   literal ("\t")
#define plus   literal_q ("+", "\\+")
#define lsqbkt   literal_q ("[", "\\[")
#define rsqbkt   literal_q ("]", "\\]")
#define lparen   literal_q ("(", "\\(")
#define rparen   literal_q (")", "\\)")
#define nothing   { nothing }
#define literal(s)   { literal, { p1: (s) } }
#define literal_q(s, q)   { literal_q, { p1: (s), p2: (q) } }
#define insn_bits(name, bits)   { insn_bits, { p1: # name, w: bits } }
#define insn_size_bits(name, size, bits)   { insn_size_bits, { p1: # name, i1: size, w: bits } }
#define tick_random   { tick_random }
#define get_bits_from_size(V, S)   ((V)[randomization_counter ++ % (S)])
#define _get_bits_var(N)   (random_order_ ## N)
#define _get_bits_size(V)   (sizeof (V) / sizeof * (V))
#define mk_get_bits(N)   p2: _get_bits_var (N), i3: _get_bits_size (_get_bits_var (N))
#define get_bits_from(V)   get_bits_from_size ((V),_get_bits_size ((V)))
#define get_bits(N)   get_bits_from (_get_bits_var (N))
#define signed_constant(bits, shift, revert)
#define unsigned_constant(bits, shift, revert)
#define absolute_address
#define reg_p(prefix, shift, gen)   { reg_p, { i1: (shift), p1: (prefix), gen } }
#define reg_r(names, shift, mask, gen)   { reg_r, { i1: (shift), i2: (mask), p1: (names), gen } }

Typedefs

typedef unsigned long long word

Functions

int nothing (func_arg *arg, insn_data *data)
int literal (func_arg *arg, insn_data *data)
int literal_q (func_arg *arg, insn_data *data)
int skip_insn (char *name)
int insn_bits (func_arg *arg, insn_data *data)
int insn_size_bits (func_arg *arg, insn_data *data)
int tick_random (func_arg *arg, insn_data *data)
unsigned long ulen (unsigned long i, unsigned base)
int signed_constant (func_arg *arg, insn_data *data)
int unsigned_constant (func_arg *arg, insn_data *data)
int absolute_address (func_arg *arg, insn_data *data)
int reg_p (func_arg *arg, insn_data *data)
int reg_r (func_arg *arg, insn_data *data)
void output_insns (func **insn, FILE *as_in, FILE *dis_out)
void output_groups (group_t group[], FILE *as_in, FILE *dis_out)

Variables

int insn_size = 4
int current_offset = 0
int last_label_offset = 0
const char * last_label_name = 0
char ** skip_list = 0
unsigned randomization_counter = 0
unsigned random_order_2u []
unsigned random_order_3u []
unsigned random_order_4u []
unsigned random_order_5u []
int random_order_7s []
int random_order_8s []
int random_order_9s []
int random_order_16s []
int random_order_24s []
int random_order_32s []

Class Documentation

struct insn_data

Definition at line 105 of file test-gen.c.

Class Members
char * as_in
word bits
char * dis_out
struct func_arg

Definition at line 117 of file test-gen.c.

Class Members
int i1
int i2
int i3
void * p1
void * p2
word w
struct group_t

Definition at line 139 of file test-gen.c.

Collaboration diagram for group_t:
Class Members
func ** insns
const char * name

Define Documentation

#define _get_bits_size (   V)    (sizeof (V) / sizeof * (V))

Definition at line 293 of file test-gen.c.

#define _get_bits_var (   N)    (random_order_ ## N)

Definition at line 292 of file test-gen.c.

Value:
(bits, shift, revert) \
  { absolute_address, { i1: shift, i2: bits * (revert ? -1 : 1), \
                     mk_get_bits (bits ## s) } }
#define comma   literal_q (", ", ", ?")

Definition at line 179 of file test-gen.c.

#define define_insn (   insname,
  funcs... 
)    func i_ ## insname[] = { funcs, { 0 } }

Definition at line 172 of file test-gen.c.

#define DISASSEMBLER_TEST   1

Definition at line 72 of file test-gen.c.

#define get_bits (   N)    get_bits_from (_get_bits_var (N))

Definition at line 303 of file test-gen.c.

#define get_bits_from (   V)    get_bits_from_size ((V),_get_bits_size ((V)))

Definition at line 302 of file test-gen.c.

#define get_bits_from_size (   V,
  S 
)    ((V)[randomization_counter ++ % (S)])

Definition at line 286 of file test-gen.c.

#define insn (   insname)    (i_ ## insname)

Definition at line 174 of file test-gen.c.

#define insn_bits (   name,
  bits 
)    { insn_bits, { p1: # name, w: bits } }
#define INSN_REPEAT   5

Definition at line 78 of file test-gen.c.

#define insn_size_bits (   name,
  size,
  bits 
)    { insn_size_bits, { p1: # name, i1: size, w: bits } }
#define literal (   s)    { literal, { p1: (s) } }
#define literal_q (   s,
 
)    { literal_q, { p1: (s), p2: (q) } }
#define lparen   literal_q ("(", "\\(")

Definition at line 185 of file test-gen.c.

#define lsqbkt   literal_q ("[", "\\[")

Definition at line 183 of file test-gen.c.

#define mk_get_bits (   N)    p2: _get_bits_var (N), i3: _get_bits_size (_get_bits_var (N))

Definition at line 297 of file test-gen.c.

#define nothing   { nothing }

Definition at line 84 of file test-gen.c.

#define plus   literal_q ("+", "\\+")

Definition at line 182 of file test-gen.c.

#define reg_p (   prefix,
  shift,
  gen 
)    { reg_p, { i1: (shift), p1: (prefix), gen } }
#define reg_r (   names,
  shift,
  mask,
  gen 
)    { reg_r, { i1: (shift), i2: (mask), p1: (names), gen } }
#define rparen   literal_q (")", "\\)")

Definition at line 186 of file test-gen.c.

#define rsqbkt   literal_q ("]", "\\]")

Definition at line 184 of file test-gen.c.

#define signed_constant (   bits,
  shift,
  revert 
)
Value:
{ signed_constant, { i1: shift, i2: bits * (revert ? -1 : 1), \
                     mk_get_bits (bits ## s) } }
#define SIMPLIFY_OUTPUT   0

Definition at line 67 of file test-gen.c.

#define space   literal (" ")

Definition at line 180 of file test-gen.c.

#define tab   literal ("\t")

Definition at line 181 of file test-gen.c.

#define TEST_GEN_C   1

Definition at line 2 of file test-gen.c.

#define tick_random   { tick_random }
#define unsigned_constant (   bits,
  shift,
  revert 
)
Value:
{ unsigned_constant, { i1: shift, i2: bits * (revert ? -1 : 1), \
                      mk_get_bits (bits ## s) } }

Typedef Documentation

Definition at line 97 of file test-gen.c.


Function Documentation

int absolute_address ( func_arg arg,
insn_data data 
)

Definition at line 540 of file test-gen.c.

  { absolute_address, { i1: shift, i2: bits * (revert ? -1 : 1), \
                     mk_get_bits (bits ## s) } }
{
  int nbits = (arg->i2 >= 0 ? arg->i2 : -arg->i2);
  unsigned long val =
    get_bits_from_size ((unsigned *) arg->p2, arg->i3)
    & (((((word) 1) << (nbits - 1)) << 1) - 1);
  word bits = val;

  data->as_in = malloc (ulen (val, 10) + 1);
  sprintf (data->as_in, "%lu", val);
  data->dis_out = malloc (nbits / 4 + 11);
  sprintf (data->dis_out, "0*%0*lx <[^>]*>", nbits / 4, val);
  if (arg->i2 < 0)
    {
      word rbits = 0;

      do
       {
         rbits <<= 8;
         rbits |= bits & 0xff;
         bits >>= 8;
         nbits -= 8;
       }
      while (nbits > 0);

      bits = rbits;
    }
  data->bits = bits << arg->i1;

  return 0;
}

Here is the call graph for this function:

int insn_bits ( func_arg arg,
insn_data data 
)

Definition at line 245 of file test-gen.c.

  { insn_bits, { p1: # name, w: bits } }
{
  if (skip_insn ((char *) arg->p1))
    return 1;
  data->as_in = data->dis_out = strdup ((char *) arg->p1);
  data->bits = arg->w;
  return 0;
}

Here is the call graph for this function:

int insn_size_bits ( func_arg arg,
insn_data data 
)

Definition at line 259 of file test-gen.c.

  { insn_size_bits, { p1: # name, i1: size, w: bits } }
{
  if (skip_insn ((char *) arg->p1))
    return 1;
  data->as_in = data->dis_out = strdup ((char *) arg->p1);
  data->bits = arg->w;
  insn_size = arg->i1;
  return 0;
}

Here is the call graph for this function:

int literal ( func_arg arg,
insn_data data 
)

Definition at line 202 of file test-gen.c.

                   { literal, { p1: (s) } }
{
  data->as_in = data->dis_out = strdup ((char *) arg->p1);
  return 0;
}

Here is the call graph for this function:

int literal_q ( func_arg arg,
insn_data data 
)

Definition at line 216 of file test-gen.c.

                       { literal_q, { p1: (s), p2: (q) } }
{
  data->as_in = strdup ((char *) arg->p1);
  data->dis_out = strdup ((char *) arg->p2);
  return 0;
}

Here is the call graph for this function:

int nothing ( func_arg arg,
insn_data data 
)

Definition at line 191 of file test-gen.c.

                { nothing }
{
  return 0;
}
void output_groups ( group_t  group[],
FILE *  as_in,
FILE *  dis_out 
)

Definition at line 732 of file test-gen.c.

{
  for (; group->name; ++group)
    {
      fprintf (as_in, "%s:\n", group->name);
      fprintf (dis_out, "# %s:\n", group->name);
      last_label_offset = current_offset;
      last_label_name = group->name;
      output_insns (group->insns, as_in, dis_out);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void output_insns ( func **  insn,
FILE *  as_in,
FILE *  dis_out 
)

Definition at line 622 of file test-gen.c.

{
  for (; *insn; ++insn)
    {
      insn_data *data;
      func *parts = *insn;
      int part_count = 0, r;

      /* Figure out how many funcs have to be called.  */
      while (parts[part_count].func)
       ++part_count;

      /* Allocate storage for the output area of each func.  */
      data = (insn_data*) malloc (part_count * sizeof (insn_data));

#if SIMPLIFY_OUTPUT
      randomization_counter = 0;
#else
      /* Repeat each insn several times.  */
      for (r = 0; r < INSN_REPEAT; ++r)
#endif
       {
         unsigned saved_rc = randomization_counter;
         int part;
         word bits = 0;

         for (part = 0; part < part_count; ++part)
           {
             /* Zero-initialize the storage.  */
             data[part].as_in = data[part].dis_out = 0;
             data[part].bits = 0;
             /* If a func returns non-zero, skip this line.  */
             if (parts[part].func (&parts[part].arg, &data[part]))
              goto skip;
             /* Otherwise, get its output bit pattern into the total
                bit pattern.  */
             bits |= data[part].bits;
           }
         
         if (as_in)
           {
             /* Output the whole assembly line.  */
             fputc ('\t', as_in);
             for (part = 0; part < part_count; ++part)
              if (data[part].as_in)
                fputs (data[part].as_in, as_in);
             fputc ('\n', as_in);
           }

         if (dis_out)
           {
             /* Output the disassembler expected output line,
                starting with the offset and the insn binary pattern,
                just like objdump outputs.  Because objdump sometimes
                inserts spaces between each byte in the insn binary
                pattern, make the space optional.  */
             fprintf (dis_out, "0*%x <", current_offset);
             if (last_label_name)
              if (current_offset == last_label_offset)
                fputs (last_label_name, dis_out);
              else
                fprintf (dis_out, "%s\\+0x%x", last_label_name,
                        current_offset - last_label_offset);
             else
              fputs ("[^>]*", dis_out);
             fputs ("> ", dis_out);
             for (part = insn_size; part-- > 0; )
              fprintf (dis_out, "%02x ?", (int)(bits >> (part * 8)) & 0xff);
             fputs (" *\t", dis_out);
             
#if DISASSEMBLER_TEST
             for (part = 0; part < part_count; ++part)
              if (data[part].dis_out)
                fputs (data[part].dis_out, dis_out);
#else
             /* If we're not testing the DISASSEMBLER, just match
                anything.  */
             fputs (".*", dis_out);
#endif
             fputc ('\n', dis_out);
#if OUTPUT_RANDOMIZATION_COUNTER
             fprintf (dis_out, "# %i\n", randomization_counter);
#endif
           }

         /* Account for the insn_size bytes we've just output.  */
         current_offset += insn_size;

         /* Release the memory that each func may have allocated.  */
         for (; part-- > 0;)
           {
           skip:
             if (data[part].as_in)
              free (data[part].as_in);
             if (data[part].dis_out
                && data[part].dis_out != data[part].as_in)
              free (data[part].dis_out);
           }

         /* There's nothing random here, don't repeat this insn.  */
         if (randomization_counter == saved_rc)
           break;
       }

      free (data);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int reg_p ( func_arg arg,
insn_data data 
)

Definition at line 580 of file test-gen.c.

  { reg_p, { i1: (shift), p1: (prefix), gen } }
{
  unsigned reg = get_bits_from_size ((unsigned *) arg->p2, arg->i3);
  char *regname = (char *) arg->p1;

  data->as_in = data->dis_out = malloc (strlen (regname) + ulen (reg, 10) + 1);
  sprintf (data->as_in, "%s%u", regname, reg);
  data->bits = reg;
  data->bits <<= arg->i1;
  return 0;
}

Here is the call graph for this function:

int reg_r ( func_arg arg,
insn_data data 
)

Definition at line 604 of file test-gen.c.

  { reg_r, { i1: (shift), i2: (mask), p1: (names), gen } }
{
  unsigned reg = get_bits_from_size ((unsigned *) arg->p2, arg->i3);
  
  data->as_in = strdup (((const char **) arg->p1)[reg]);
  reg &= arg->i2;
  data->dis_out = strdup (((const char **) arg->p1)[reg]);
  data->bits = reg;
  data->bits <<= arg->i1;
  return 0;
}

Here is the call graph for this function:

int signed_constant ( func_arg arg,
insn_data data 
)

Definition at line 468 of file test-gen.c.

  { signed_constant, { i1: shift, i2: bits * (revert ? -1 : 1), \
                     mk_get_bits (bits ## s) } }
{
  long val = get_bits_from_size ((unsigned *) arg->p2, arg->i3);
  int len = (val >= 0 ? ulen (val, 10) : (1 + ulen (-val, 10)));
  int nbits = (arg->i2 >= 0 ? arg->i2 : -arg->i2);
  word bits = ((word) val) & (((((word) 1) << (nbits - 1)) << 1) - 1);

  data->as_in = data->dis_out = malloc (len + 1);
  sprintf (data->as_in, "%ld", val);
  if (arg->i2 < 0)
    {
      word rbits = 0;

      do
       {
         rbits <<= 8;
         rbits |= bits & 0xff;
         bits >>= 8;
         nbits -= 8;
       }
      while (nbits > 0);

      bits = rbits;
    }
  data->bits = bits << arg->i1;

  return 0;
}

Here is the call graph for this function:

int skip_insn ( char *  name)

Definition at line 228 of file test-gen.c.

{
  char **test;

  if (! skip_list)
    return 0;

  for (test = skip_list; * test; ++ test)
    if (strcmp (name, * test) == 0)
      return 0;

  return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int tick_random ( func_arg arg,
insn_data data 
)

Definition at line 277 of file test-gen.c.

                    { tick_random }
{
  ++ randomization_counter;
  return 0;
}
unsigned long ulen ( unsigned long  i,
unsigned  base 
)

Definition at line 454 of file test-gen.c.

{
  int count = 0;

  if (i == 0)
    return 1;
  for (; i > 0; ++ count)
    i /= base;
  return count;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int unsigned_constant ( func_arg arg,
insn_data data 
)

Definition at line 503 of file test-gen.c.

  { unsigned_constant, { i1: shift, i2: bits * (revert ? -1 : 1), \
                      mk_get_bits (bits ## s) } }
{
  int nbits = (arg->i2 >= 0 ? arg->i2 : -arg->i2);
  unsigned long val =
    get_bits_from_size ((unsigned *) arg->p2, arg->i3)
    & (((((word) 1) << (nbits - 1)) << 1) - 1);
  int len = ulen (val, 10);
  word bits = val;

  data->as_in = data->dis_out = malloc (len + 1);
  sprintf (data->as_in, "%lu", val);
  if (arg->i2 < 0)
    {
      word rbits = 0;

      do
       {
         rbits <<= 8;
         rbits |= bits & 0xff;
         bits >>= 8;
         nbits -= 8;
       }
      while (nbits > 0);

      bits = rbits;
    }
  data->bits = bits << arg->i1;

  return 0;
}

Here is the call graph for this function:


Variable Documentation

Definition at line 151 of file test-gen.c.

Definition at line 147 of file test-gen.c.

Definition at line 155 of file test-gen.c.

Definition at line 154 of file test-gen.c.

Initial value:
  {
    
    -32768,
    32767,
    (-1 << 15) | (64 << 8) | 32,
    (64 << 8) | 32,
    0x1234,
    (-1 << 15) | 0x8765,
    0x0180,
    (-1 << 15) | 0x8001
}

Definition at line 399 of file test-gen.c.

Initial value:
  {
    
    -1 << 23,
    1 << 23 -1,
    (-1 << 23) | (((64 << 8) | 32) << 8) | 16,
    (((64 << 8) | 32) << 8) | 16,
    0x123456,
    (-1 << 23) | 0x876543,
    0x01ff80,
    (-1 << 23) | 0x80ff01
}

Definition at line 417 of file test-gen.c.

Initial value:
  {
    
    0, 1, 3, 2,
    2, 0, 1, 3,
    1, 3, 2, 0,
    3, 2, 0, 1
  }

Definition at line 308 of file test-gen.c.

Initial value:
  {
    
    -1 << 31,
    1 << 31 - 1,
    (-1 << 31) | (((((64 << 8) | 32) << 8) | 16) << 8) | 8,
    (((((64 << 8) | 32) << 8) | 16) << 8) | 8,
    0x12345678,
    (-1 << 31) | 0x87654321,
    0x01ffff80,
    (-1 << 31) | 0x80ffff01
  }

Definition at line 435 of file test-gen.c.

Initial value:
  {
    
    0, 6, 3, 1, 4, 2, 7, 5,
    
    0, 2, 5, 7, 4, 6, 1, 3,
  }

Definition at line 320 of file test-gen.c.

Initial value:
  {
    
    0,  5, 15, 10, 9,  4, 14,  3,
    8, 13,  7,  2, 1, 12,  6, 11,
    
    0,  7,  5, 14,  3, 12, 10, 1,
    8, 15, 13,  6, 11,  4,  2, 9,
  }

Definition at line 334 of file test-gen.c.

Initial value:
  {
    
    0, 26, 13,  7, 20, 14,  1, 27,
    8, 2,  21, 15, 28, 22,  9,  3,
    16, 10, 29, 23,  4, 30, 17, 11,
    24,  18, 5, 31, 12, 6,  25, 19
  }

Definition at line 350 of file test-gen.c.

Initial value:
  {
    
    0, -1, -64, 63, -32, 32, 24, -20,
    9, -27, -31, 33, 40, -2, -5, 1
  }

Definition at line 363 of file test-gen.c.

Initial value:
  {
    
    0, -1, -128, 127, -32, 32, 24, -20,
    73, -27, -95, 33, 104, -2, -69, 1
  }

Definition at line 375 of file test-gen.c.

Initial value:
  {
    
    0, -1, -256, 255, -64, 64, 72, -40,
    73, -137, -158, 37, 104, -240, -69, 1
  }

Definition at line 387 of file test-gen.c.

Definition at line 168 of file test-gen.c.

char** skip_list = 0

Definition at line 163 of file test-gen.c.