Ejemplo n.º 1
0
static unsigned int
type_bitwidth(ir_unit_t *iu, int index)
{
  ir_type_t *it = type_get(iu, index);
  switch(it->it_code) {
  case IR_TYPE_VOID:
    return 0;
  case IR_TYPE_INT1:
    return 1;
  case IR_TYPE_INT8:
    return 8;
  case IR_TYPE_INT16:
    return 16;
  case IR_TYPE_INT32:
    return 32;
  case IR_TYPE_INT64:
    return 64;
  case IR_TYPE_INTx:
    return it->it_bits;

  default:
    parser_error(iu, "Unable to compute bitwidth of type %s\n",
                 type_str(iu, it));
  }
}
Ejemplo n.º 2
0
int main()
{
	object_t *o;
	char *s;
	const char *string_type = "STRING";
	type_t *type;

	plan(9);
	
	type = type_get(string_type);
	type_set_callback(type, "free", free);

	s = calloc(20, sizeof(char));
	strcpy(s, "Hello, object world");

	o = object_new(string_type, s);
	ok(o != NULL, "object is not NULL");
	ok(object_isset(o), "object is set");
	ok(object_isa(o, string_type), "object isa '%s'", string_type);
	str_eq(object_type(o), string_type);
	ok(object_type(o) == string_type, "object_type() returns direct pointer to type string");
	str_eq(object_value(o), s);
	ok(object_value(o) == s, "object_value() returns direct pointer to value");

	object_set(o, "Goodbye");
	str_eq(object_value(o), "Goodbye");
	object_set(o, s);

	object_free(o);
	ok(object_isset(NULL) == 0, "NULL is considered as an unset object");

	types_finalize();

	return 0;
}
Ejemplo n.º 3
0
static unsigned int
type_get_pointee(ir_unit_t *iu, unsigned int id)
{
  ir_type_t *it = type_get(iu, id);
  if(it->it_code != IR_TYPE_POINTER)
    parser_error(iu, "Type (%s) (index:%d) is not a pointer",
                 type_str_index(iu, id), id);
  if(it->it_pointer.pointee == -1)
    parser_error(iu, "Attempting to dereference void pointer");
  return it->it_pointer.pointee;
}
Ejemplo n.º 4
0
static unsigned int
type_sizeof(ir_unit_t *iu, int index)
{
  ir_type_t *it = type_get(iu, index);
  switch(it->it_code) {
  case IR_TYPE_VOID:
    return 0;
  case IR_TYPE_INT1:
  case IR_TYPE_INT8:
    return 1;
  case IR_TYPE_INT16:
    return 2;
  case IR_TYPE_INT32:
  case IR_TYPE_FLOAT:
    return 4;
  case IR_TYPE_INT64:
  case IR_TYPE_DOUBLE:
    return 8;

  case IR_TYPE_INTx:
    if(it->it_bits <= 32)
      return 4;
    if(it->it_bits <= 64) {
      return 8;
    }
    goto bad;

  case IR_TYPE_POINTER:
    return 4;
  case IR_TYPE_STRUCT:
    return it->it_struct.size;

  case IR_TYPE_ARRAY:

    return type_sizeof(iu, it->it_array.element_type) *
      it->it_array.num_elements;

  default:
  bad:
    parser_error(iu, "Unable to compute size of type %s\n",
                 type_str(iu, it));
  }
}