⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test-gen.c

📁 GNU binutils是GNU交叉工具链中的一个源码包
💻 C
📖 第 1 页 / 共 2 页
字号:
   ``interesting'' constants from -128 to +127.  */int random_order_8s[] =  {    /* Sequence generated by hand, to explore limit values and a few       intermediate values selected by chance.  Keep the number of       intermediate values low, to ensure that the limit values are       generated often enough.  */    0, -1, -128, 127, -32, 32, 24, -20,    73, -27, -95, 33, 104, -2, -69, 1  };/* Use `9s' to generate 9-bit signed values.  Good for selecting   ``interesting'' constants from -256 to +255.  */int random_order_9s[] =  {    /* Sequence generated by hand, to explore limit values and a few       intermediate values selected by chance.  Keep the number of       intermediate values low, to ensure that the limit values are       generated often enough.  */    0, -1, -256, 255, -64, 64, 72, -40,    73, -137, -158, 37, 104, -240, -69, 1  };/* Use `16s' to generate 16-bit signed values.  Good for selecting   ``interesting'' constants from -32768 to +32767.  */int random_order_16s[] =  {    /* Sequence generated by hand, to explore limit values and a few       intermediate values selected by chance.  Keep the number of       intermediate values low, to ensure that the limit values are       generated often enough.  */    -32768,    32767,    (-1 << 15) | (64 << 8) | 32,    (64 << 8) | 32,    0x1234,    (-1 << 15) | 0x8765,    0x0180,    (-1 << 15) | 0x8001};/* Use `24s' to generate 24-bit signed values.  Good for selecting   ``interesting'' constants from -2^23 to 2^23-1.  */int random_order_24s[] =  {    /* Sequence generated by hand, to explore limit values and a few       intermediate values selected by chance.  Keep the number of       intermediate values low, to ensure that the limit values are       generated often enough.  */    -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};/* Use `32s' to generate 32-bit signed values.  Good for selecting   ``interesting'' constants from -2^31 to 2^31-1.  */int random_order_32s[] =  {    /* Sequence generated by hand, to explore limit values and a few       intermediate values selected by chance.  Keep the number of       intermediate values low, to ensure that the limit values are       generated often enough.  */    -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  };/* This function computes the number of digits needed to represent a   given number.  */unsigned longulen (unsigned long i, unsigned base){  int count = 0;  if (i == 0)    return 1;  for (; i > 0; ++ count)    i /= base;  return count;}/* Use this to generate a signed constant of the given size, shifted   by the given amount, with the specified endianness.  */intsigned_constant (func_arg * arg, insn_data * data)#define signed_constant(bits, shift, revert) \  { 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;}/* Use this to generate a unsigned constant of the given size, shifted   by the given amount, with the specified endianness.  */intunsigned_constant (func_arg * arg, insn_data * data)#define unsigned_constant(bits, shift, revert) \  { 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;}/* Use this to generate an absolute address of the given size, shifted   by the given amount, with the specified endianness.  */intabsolute_address (func_arg *arg, insn_data *data)#define absolute_address (bits, shift, revert) \  { 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;}/* Use this to generate a register name that starts with a given   prefix, and is followed by a number generated by `gen' (see   mk_get_bits below).  The register number is shifted `shift' bits   left before being stored in the binary insn.  */intreg_p (func_arg *arg, insn_data *data)#define reg_p(prefix,shift,gen) \  { 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;}/* Use this to generate a register name taken from an array.  The   index into the array `names' is to be produced by `gen', but `mask'   may be used to filter out some of the bits before choosing the   disassembler output and the bits for the binary insn, shifted left   by `shift'.  For example, if registers have canonical names, but   can also be referred to by aliases, the array can be n times larger   than the actual number of registers, and the mask is then used to   pick the canonical name for the disassembler output, and to   eliminate the extra bits from the binary output.  */intreg_r (func_arg *arg, insn_data *data)#define reg_r(names,shift,mask,gen) \  { 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;}/* Given a NULL-terminated array of insns-definitions (pointers to   arrays of funcs), output test code for the insns to as_in (assembly   input) and dis_out (expected disassembler output).  */voidoutput_insns (func **insn, FILE *as_in, FILE *dis_out){  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);    }}/* For each group, output an asm label and the insns of the group.  */voidoutput_groups (group_t group[], FILE *as_in, FILE *dis_out){  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);    }}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -