Example #1
0
File: node.c Project: yipf/C-lisp
char* new_string(char* string,unsigned n){
	char *str;
	str=calloc(n+1,sizeof(char));
	memcpy(str,string,n);
	string=unique_string(str);
	if(string!=str){ free(str); }
	return string;
}
Example #2
0
File: node.c Project: yipf/C-lisp
node_t quote_node(node_t node,int quote){
	value_t value;
	while(quote--){
		value=alloc_value(SYMBOL,0);
		value->string=unique_string("quote");
		node=alloc_node(value,node);
		node=alloc_node(alloc_value(LIST,node),0);
 	}
	return node;
}
Example #3
0
main()
{
    char input_string[16];

    printf("Enter the string\n");
    scanf("%s", input_string);
    printf("%s\n", input_string);

    unique_string(input_string);
}
Example #4
0
/* This function computes information about all unexpanded operands, placing
 * information needed to extract them into op.  It also determines appropriate
 * byte ordering information and modifies v's code to swap bytes when
 * appropriate.  Returns the number of words of operands.
 */
int
compute_operand_info (OperandInfo *op, const ParsedOpcodeInfo *p,
		      const CCVariant *v)
{
  PatternRange range;
  ExprInfo field_info[16];
  char decls[2048];
  int words_in = p->operand_words_to_skip;
  int i;

  /* Zero out everything by default. */
  memset (op, 0, sizeof *op);

  /* Start out with the endianness/size of all operands unknown. */
  memset (field_info, 0, sizeof field_info);

  /* Figure out whatever we can about various fields. */
  for (i = 1; pattern_range (p->opcode_bits, i, &range); i++)
    {
      /* Was this field expanded? */
      if (field_expanded (i, p->opcode_bits, v->bits_to_expand))
	{
	  /* Yep; it's going to expand to a constant number,
	   * so specify the byte order as NATIVE.
	   */
	  field_info[i].order = BO_NATIVE;
	  break;
	}
    }

  /* Loop through unexpanded fields and nail down their size + signedness. */
  for (i = 1; pattern_range (p->opcode_bits, i, &range); i++)
    {
      Token *dollartok;
  
      /* If this field was expanded, no need to save it as an operand. */
      if (field_expanded (i, p->opcode_bits, v->bits_to_expand))
	continue;

      /* See if this field was actually used as a numeric constant. */
      if ((dollartok = has_tok_dollar (v->code, TOK_DOLLAR_NUMBER, i)) != NULL)
	{
	  field_info[i].sgnd = dollartok->u.dollarinfo.sgnd;
	  field_info[i].size = dollartok->u.dollarinfo.size;
	}
      else if (has_tok_dollar_reg (v->code, i))
	{
	  /* Make register numbers be 32 bit uints, since this seems to
	   * make most compilers the happiest when doing array references.
	   */
	  field_info[i].sgnd  = FALSE;
	  field_info[i].size  = BS_LONG;
	  field_info[i].order = BO_NATIVE;
	}
    }

  /* Recursively set/determine the endianness of all expressions and
   * add in swap's where appropriate.
   */
  endianness (v->code, BO_UNKNOWN, BO_NATIVE, FALSE, field_info);

  /* For all of the fields that weren't expanded, create bitfield
   * information for them and create a declaration.
   */
  for (i = 1; pattern_range (p->opcode_bits, i, &range); i++)
    {
      BitfieldInfo *b;

      /* If this field was expanded, no need to save it as an operand. */
      if (field_expanded (i, p->opcode_bits, v->bits_to_expand))
	continue;

      /* See if this field was actually used as a numeric constant,
       * or as a register number...
       */
      if (has_tok_dollar (v->code, TOK_DOLLAR_NUMBER, i) == NULL
	  && !has_tok_dollar_reg (v->code, i))
	continue;

      /* If we just don't care about byte order for a numeric constant,
       * make it default to BO_NATIVE.
       */
      if (field_info[i].order == BO_UNKNOWN
	  && has_tok_dollar (v->code, TOK_DOLLAR_NUMBER, i) != NULL)
	field_info[i].order = BO_NATIVE;

      /* It wasn't expanded, so create a bitfield for it. */
      if (field_info[i].order == BO_UNKNOWN
	  || field_info[i].size == BS_UNKNOWN)
	{
	  parse_error (v->code, "Error: Unable to determine best byte order "
		       "or size of operand field %d.  "
		       "(order == %d, size == %d)\n", i, field_info[i].order,
		       field_info[i].size);
	  print_list (stderr, v->code);
	  putc ('\n', stderr);
	}
      else
	{
	  b = &op->bitfield[op->num_bitfields++];
	  b->rev_amode = (has_tok_dollar (v->code, TOK_DOLLAR_REVERSED_AMODE,i)
			  != NULL);
	  b->index = range.index;
	  b->length = range.length - 1;
	  b->sign_extend = field_info[i].sgnd;
	  b->make_native_endian = (field_info[i].order == BO_NATIVE
				   || field_info[i].size == BS_BYTE);

#if 0
	  /* We prefer to translate 16 bit operands to the synthetic
	   * instruction stream as 16 bit operands.  However, if the operand
	   * is to be sign- or zero-extended to 32 bits, and it is not to be
	   * native endian, we extend it at translation time.  The logic
	   * behind this is that extending a 16 bit number is a free
	   * operation on the 386 (movesx/movezx) and a cheap operation on
	   * other CPU's, but this will only work for operands in native
	   * format.  Also, since 32 bit operands force operand alignment for
	   * QUADALIGN machines, using 16 bit operands can avoid alignment
	   * NOPs.
	   */
	  if (b->make_native_endian && range.length <= 16)
	    b->words = 1 - 1;  /* 1 word. */
	  else
	    b->words = ((field_info[i].size == BS_LONG) ? 2 : 1) - 1;
#else
	  /* We now prefer to use BS_LONG operands.  These are generally
	   * faster on RISC chips, and on the Pentium movswl, etc. are
	   * apparently not pairable.
	   */
	  if (b->make_native_endian)
	    field_info[i].size = BS_LONG;
	  b->words = ((field_info[i].size == BS_LONG) ? 2 : 1) - 1;
#endif

	  if (b->index == MAGIC_END_INDEX && b->length == MAGIC_END_LENGTH)
	    fatal_error ("Illegal bitfield index/length (%d/%d).  This "
			 "combination is used as a magic value and shouldn't "
			 "show up in real code!", MAGIC_END_INDEX,
			 MAGIC_END_LENGTH);
	}
    }

  if (op->num_bitfields > MAX_BITFIELDS)
    fatal_error ("Too many operand bitfields (%d) for OpcodeMappingInfo "
		 "struct.\n", op->num_bitfields);

#if defined (SORT_OPERANDS)
  /* Sort operands by size and then by field number. */
  {
#ifdef GENERATE_NATIVE_CODE
    BitfieldInfo *save;
    int size = op->num_bitfields * sizeof op->bitfield[0];
    save = (BitfieldInfo *) alloca (size);
    memcpy (save, op->bitfield, size);
#endif
    qsort (op->bitfield, op->num_bitfields, sizeof op->bitfield[0],
	   compare_bitfields);
#ifdef GENERATE_NATIVE_CODE
    if (v->native_code_info != NULL && memcmp (save, op->bitfield, size))
      parse_error (v->code, "byteorder.c insists on reordering your operands!"
		   "  This is incompatible with native code generation.");
#endif
  }
#endif /* defined (SORT_OPERANDS) */

  /* Create decls string. */
  decls[0] = '\0';
  for (i = 0; i < op->num_bitfields; i++)
    {
      int field = field_with_index (p->opcode_bits, op->bitfield[i].index);

      /* Output declaration. */
#if	1 || !defined(TEMPS_AT_TOP)
      sprintf (decls + strlen (decls), "        %sint%d operand_%d = ",
	       op->bitfield[i].sign_extend ? "" : "u",
	       field_info[field].size * 8, field);
#else	/* defined(TEMPS_AT_TOP) */
      sprintf (decls + strlen (decls), "        operand_%s%d_%d = ",
	       op->bitfield[i].sign_extend ? "" : "u",
	       field_info[field].size * 8, field);
#endif	/* defined(TEMPS_AT_TOP) */

      /* Fetch initial value. */
      if (op->bitfield[i].words == 1 - 1  /* One 16 bit word. */ )
	{
	  if (op->bitfield[i].sign_extend)
	    strcat (decls, "(int16) ");
	  sprintf (decls + strlen (decls), "code[%d];", words_in);
	  /* We leave a gap here.  We used to pack all the 16 bit
	   * operands together, but they have largely been abandoned
	   * in favor of 32 bit operands.  They only crop up occasionally
	   * when we're doing byte swapping of immediate constants.
	   * We leave a gap here so everything stays aligned.
	   */
	  words_in += 2;
	}
      else  /* Two 16 bit words. */
	{
	  strcat (decls, "*((");
	  if (!op->bitfield[i].sign_extend)
	    strcat (decls, "u");
	  if (words_in != 0)
	    sprintf (decls + strlen (decls), "int32 *) (code + %d));",
		     words_in);
	  else
	    sprintf (decls + strlen (decls), "int32 *) code);");
	  words_in += 2;
	}

      /* Add comment indicating swappedness. */
      if (op->bitfield[i].make_native_endian)
	strcat (decls, "   /* Native endian */\n");
      else
	strcat (decls, "   /* Big endian */\n");
    }

  op->operand_decls = unique_string (decls);
  return words_in;
}
int main(int argc, char *argv[]){
    char* str = argv[1];
    bool uniq = unique_string(str);
    fputs( uniq ? "true \n" : "false \n", stdout);
}