Ejemplo n.º 1
0
static void dump_fields(region r, const char *prefix, field_declaration fields)
{
  while (fields)
    {
      if (fields->name) /* skip anon fields */
	{
	  type t = fields->type;

	  printf("  %s%s ", prefix, fields->name);
	  while (type_array(t))
	    {
	      type base = type_array_of(t);
	      expression size = type_array_size(t);

	      printf("[%lu]", (unsigned long)constant_uint_value(size->cst));
	      t = base;
	    }
	  dump_type(t);

	  assert(cval_isinteger(fields->offset));
	  printf(" %lu %lu\n", (unsigned long)cval_uint_value(fields->offset),
		 (unsigned long)
		 (!cval_istop(fields->bitwidth) ?
		  cval_uint_value(fields->bitwidth) :
		  BITSPERBYTE * cval_uint_value(type_size(t))));

	  if (type_aggregate(t))
	    {
	      tag_declaration tdecl = type_tag(t);
	      char *newprefix = rarrayalloc(r, strlen(prefix) + strlen(fields->name) + 2, char);

	      sprintf(newprefix, "%s%s.", prefix, fields->name);
	      dump_fields(r, newprefix, tdecl->fieldlist);
	      printf("  %s%s AX\n", prefix, fields->name);
	    }
	}
      fields = fields->next;
    }
Ejemplo n.º 2
0
void xml_attr_cval(const char *name, cval val)
{
    bool unknown = FALSE;

    xprintf(" %s=\"", name);

    if (cval_isunsigned(val))
        xprintf("I:%llu", cval_uint_value(val));
    else if (cval_isinteger(val))
        xprintf("I:%lld", cval_sint_value(val));
    else if (cval_isunknown(val))
        unknown = TRUE;
    else if (cval_isfloating(val))
        /* XXX: hacky version */
        xprintf("F:%.20Le", cval_float_value(val));
    else if (cval_isaddress(val))
    {
        data_declaration ddecl = cval_ddecl(val);

        /* XXX: We don't (yet) support strings with an offset */
        if (ddecl && ddecl->kind == decl_magic_string && cval_knownbool(val))
        {
            /* Wide strings are printed as their byte-by-byte rep. FIXME */
            xputs("S:");
            xqputcs(ddecl->schars);
        }
        else
            unknown = TRUE;
    }
    else if (cval_istop(val))
        xputs("V:");
    else
        unknown = TRUE;

    if (unknown)
        xputs("U:");
    xputc('"');
}