Skip to content

Commit

Permalink
cv8 structs should work now
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Nov 2, 2012
1 parent 25899f0 commit 3042b67
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 18 deletions.
14 changes: 11 additions & 3 deletions src/backend/cgcv.c
Expand Up @@ -2097,9 +2097,17 @@ unsigned cv4_typidx(type *t)
}

case TYstruct:
{ int foo = t->Ttag->Stypidx;
typidx = cv4_struct(t->Ttag,0);
//printf("struct '%s' %x %x\n", t->Ttag->Sident, foo, typidx);
{
#if MARS
if (config.fulltypes == CV8)
typidx = cv8_fwdref(t->Ttag);
else
#endif
{
int foo = t->Ttag->Stypidx;
typidx = cv4_struct(t->Ttag,0);
//printf("struct '%s' %x %x\n", t->Ttag->Sident, foo, typidx);
}
break;
}

Expand Down
1 change: 1 addition & 0 deletions src/backend/cgcv.h
Expand Up @@ -83,6 +83,7 @@ void cv8_linnum(Srcpos srcpos, targ_size_t offset);
void cv8_outsym(Symbol *s);
void cv8_udt(const char *id, idx_t typidx);
int cv8_regnum(Symbol *s);
idx_t cv8_fwdref(Symbol *s);

#endif

45 changes: 45 additions & 0 deletions src/backend/cv8.c
Expand Up @@ -650,6 +650,51 @@ int cv8_regnum(Symbol *s)
return reg;
}

/***************************************
* Put out a forward ref for structs, unions, and classes.
* Only put out the real definitions with toDebug().
*/
idx_t cv8_fwdref(Symbol *s)
{
assert(config.fulltypes == CV8);
// if (s->Stypidx && !global.params.multiobj)
// return s->Stypidx;
struct_t *st = s->Sstruct;
unsigned leaf;
unsigned numidx;
if (st->Sflags & STRunion)
{
leaf = LF_UNION_V3;
numidx = 10;
}
else if (st->Sflags & STRclass)
{
leaf = LF_CLASS_V3;
numidx = 18;
}
else
{
leaf = LF_STRUCTURE_V3;
numidx = 18;
}
unsigned len = numidx + cv4_numericbytes(0);
debtyp_t *d = debtyp_alloc(len + cv_stringbytes(s->Sident));
TOWORD(d->data, leaf);
TOWORD(d->data + 2, 0); // number of fields
TOWORD(d->data + 4, 0x80); // property
TOLONG(d->data + 6, 0); // field list
if (leaf == LF_CLASS_V3 || leaf == LF_STRUCTURE_V3)
{
TOLONG(d->data + 10, 0); // dList
TOLONG(d->data + 14, 0); // vshape
}
cv4_storenumeric(d->data + numidx, 0);
cv_namestring(d->data + len, s->Sident);
idx_t typidx = cv_debtyp(d);
s->Stypidx = typidx;
return typidx;
}


#endif
#endif
Expand Down
79 changes: 64 additions & 15 deletions src/tocvdebug.c
Expand Up @@ -196,9 +196,10 @@ unsigned cv4_Denum(EnumDeclaration *e)
default:
assert(0);
}
unsigned length_save = d->length;
d->length = 0; // so cv_debtyp() will allocate new
idx_t typidx = cv_debtyp(d);
d->length = len; // restore length
d->length = length_save; // restore length

TOWORD(d->data + 2,nfields);

Expand Down Expand Up @@ -250,6 +251,30 @@ unsigned cv4_Denum(EnumDeclaration *e)
return typidx;
}

/*************************************
* Align and pad.
* Returns:
* aligned count
*/
unsigned cv_align(unsigned char *p, unsigned n)
{
if (config.fulltypes == CV8)
{
if (p)
{
unsigned npad = -n & 3;
while (npad)
{
*p = 0xF0 + npad;
++p;
--npad;
}
}
n = (n + 3) & ~3;
}
return n;
}

/* ==================================================================== */

/****************************
Expand Down Expand Up @@ -418,9 +443,10 @@ void StructDeclaration::toDebug()

// Assign a number to prevent infinite recursion if a struct member
// references the same struct.
unsigned length_save = d->length;
d->length = 0; // so cv_debtyp() will allocate new
typidx = cv_debtyp(d);
d->length = len; // restore length
d->length = length_save; // restore length

if (!members) // if reference only
{
Expand Down Expand Up @@ -555,10 +581,10 @@ void ClassDeclaration::toDebug()
{
size_t n = vtbl.dim; // number of virtual functions
if (n)
{
{ // 4 bits per descriptor
debtyp_t *vshape = debtyp_alloc(4 + (n + 1) / 2);
TOWORD(vshape->data,LF_VTSHAPE);
TOWORD(vshape->data + 2,1);
TOWORD(vshape->data + 2,n);

n = 0;
unsigned char descriptor = 0;
Expand Down Expand Up @@ -588,9 +614,10 @@ void ClassDeclaration::toDebug()

// Assign a number to prevent infinite recursion if a struct member
// references the same struct.
unsigned length_save = d->length;
d->length = 0; // so cv_debtyp() will allocate new
typidx = cv_debtyp(d);
d->length = len; // restore length
d->length = length_save; // restore length

if (!members) // if reference only
{
Expand All @@ -613,13 +640,23 @@ void ClassDeclaration::toDebug()
CvMemberCount mc;
mc.nfields = 0;
mc.fnamelen = 2;

/* Adding in the base classes causes VS debugger to refuse to display any
* of the fields. I have not been able to determine why.
* (Could it be because the base class is "forward referenced"?)
*/
#if 0
// Add in base classes
for (size_t i = 0; i < baseclasses->dim; i++)
{ BaseClass *bc = (*baseclasses)[i];

mc.nfields++;
mc.fnamelen += 4 + cgcv.sz_idx + cv4_numericbytes(bc->offset);
unsigned elementlen = 4 + cgcv.sz_idx + cv4_numericbytes(bc->offset);
elementlen = cv_align(NULL, elementlen);
mc.fnamelen += elementlen;
}
#endif

for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (*members)[i];
s->apply(&cv_mem_count, &mc);
Expand All @@ -638,33 +675,38 @@ void ClassDeclaration::toDebug()
TOWORD(p,config.fulltypes == CV8 ? LF_FIELDLIST_V2 : LF_FIELDLIST);
p += 2;

#if 0
// Add in base classes
for (size_t i = 0; i < baseclasses->dim; i++)
{ BaseClass *bc = (*baseclasses)[i];

idx_t typidx = cv4_typidx(bc->base->type->toCtype()->Tnext);
unsigned attribute = PROTtoATTR(bc->protection);

unsigned elementlen;
switch (config.fulltypes)
{
case CV8:
TOWORD(p, LF_BCLASS_V2);
TOWORD(p + 2,attribute);
TOLONG(p + 4,typidx);
p += 8;
elementlen = 8;
break;

case CV4:
TOWORD(p, LF_BCLASS);
TOWORD(p + 2,typidx);
TOWORD(p + 4,attribute);
p += 6;
elementlen = 6;
break;
}

cv4_storenumeric(p, bc->offset);
p += cv4_numericbytes(bc->offset);
cv4_storenumeric(p + elementlen, bc->offset);
elementlen += cv4_numericbytes(bc->offset);
elementlen = cv_align(p + elementlen, elementlen);
p += elementlen;
}
#endif

for (size_t i = 0; i < members->dim; i++)
{ Dsymbol *s = (*members)[i];
Expand Down Expand Up @@ -736,13 +778,15 @@ int cvMember(unsigned char *p, char *id, idx_t typidx)
if (!p)
{
nwritten += 8;
nwritten = cv_align(NULL, nwritten);
}
else
{
TOWORD(p,LF_NESTTYPE_V3);
TOWORD(p + 2,0);
TOLONG(p + 4,typidx);
nwritten = 8 + cv_namestring(p + 8, id);
nwritten = cv_align(p + nwritten, nwritten);
}
break;

Expand Down Expand Up @@ -798,7 +842,9 @@ int FuncDeclaration::cvMember(unsigned char *p)

if (!p)
{
return 2 + 2 + cgcv.sz_idx + cv_stringbytes(id);
nwritten = 2 + 2 + cgcv.sz_idx + cv_stringbytes(id);
nwritten = cv_align(NULL, nwritten);
return nwritten;
}
else
{
Expand Down Expand Up @@ -885,6 +931,7 @@ int FuncDeclaration::cvMember(unsigned char *p)
assert(0);
}
}
nwritten = cv_align(p + nwritten, nwritten);
#ifdef DEBUG
assert(nwritten == cvMember(NULL));
#endif
Expand Down Expand Up @@ -918,6 +965,7 @@ int VarDeclaration::cvMember(unsigned char *p)
nwritten += 2;
nwritten += 6 + cv_stringbytes(id);
}
nwritten = cv_align(NULL, nwritten);
}
else
{
Expand All @@ -930,17 +978,17 @@ int VarDeclaration::cvMember(unsigned char *p)
if (storage_class & STCfield)
{
TOWORD(p,LF_MEMBER_V3);
TOWORD(p + 2,typidx);
TOLONG(p + 4,attribute);
TOWORD(p + 2,attribute);
TOLONG(p + 4,typidx);
cv4_storenumeric(p + 8, offset);
nwritten = 8 + cv4_numericbytes( offset);
nwritten += cv_namestring(p + nwritten, id);
}
else if (isStatic())
{
TOWORD(p,LF_STMEMBER_V3);
TOWORD(p + 2,typidx);
TOLONG(p + 4,attribute);
TOWORD(p + 2,attribute);
TOLONG(p + 4,typidx);
nwritten = 8;
nwritten += cv_namestring(p + nwritten, id);
}
Expand Down Expand Up @@ -970,6 +1018,7 @@ int VarDeclaration::cvMember(unsigned char *p)
assert(0);
}

nwritten = cv_align(p + nwritten, nwritten);
#ifdef DEBUG
assert(nwritten == cvMember(NULL));
#endif
Expand Down

0 comments on commit 3042b67

Please sign in to comment.