Skip to content

Commit

Permalink
Make DT a D enum (#20651)
Browse files Browse the repository at this point in the history
Co-authored-by: Dennis Korpel <[email protected]>
  • Loading branch information
dkorpel and Dennis Korpel authored Jan 7, 2025
1 parent 1bdea38 commit 0ee880f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 61 deletions.
18 changes: 9 additions & 9 deletions compiler/src/dmd/backend/cc.d
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,7 @@ struct Declar
struct dt_t
{
dt_t *DTnext; // next in list
char dt; // type (DTxxxx)
DT dt; // Tagged union tag, see above
ubyte Dty; // pointer type
ubyte DTn; // DTibytes: number of bytes
ubyte DTalign; // DTabytes: alignment (as power of 2) of pointed-to data
Expand All @@ -1488,13 +1488,13 @@ struct dt_t
}
}

enum
enum DT : ubyte
{
DT_abytes = 0,
DT_azeros = 1,
DT_xoff = 2,
DT_nbytes = 3,
DT_common = 4,
DT_coff = 5,
DT_ibytes = 6,
abytes = 0,
azeros = 1,
xoff = 2,
nbytes = 3,
common = 4,
coff = 5,
ibytes = 6,
}
30 changes: 15 additions & 15 deletions compiler/src/dmd/backend/dout.d
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void outdata(Symbol *s)
{
//printf("\tdt = %p, dt = %d\n",dt,dt.dt);
switch (dt.dt)
{ case DT_abytes:
{ case DT.abytes:
{ // Put out the data for the string, and
// reserve a spot for a pointer to that string
datasize += size(dt.Dty); // reserve spot for pointer to string
Expand All @@ -120,19 +120,19 @@ void outdata(Symbol *s)
break;
}

case DT_ibytes:
case DT.ibytes:
datasize += dt.DTn;
break;

case DT_nbytes:
//printf("DT_nbytes %d\n", dt.DTnbytes);
case DT.nbytes:
//printf("DT.nbytes %d\n", dt.DTnbytes);
datasize += dt.DTnbytes;
break;

case DT_azeros:
case DT.azeros:
/* A block of zeros
*/
//printf("DT_azeros %d\n", dt.DTazeros);
//printf("DT.azeros %d\n", dt.DTazeros);
datasize += dt.DTazeros;
if (dt == dtstart && !dt.DTnext && s.Sclass != SC.comdat &&
(s.Sseg == UNKNOWN || s.Sseg <= UDATA))
Expand Down Expand Up @@ -185,12 +185,12 @@ void outdata(Symbol *s)
}
break;

case DT_common:
case DT.common:
assert(!dt.DTnext);
outcommon(s,dt.DTazeros);
goto Lret;

case DT_xoff:
case DT.xoff:
{ Symbol *sb = dt.DTsym;

if (tyfunc(sb.ty()))
Expand All @@ -202,7 +202,7 @@ void outdata(Symbol *s)
}
}
goto case;
case DT_coff:
case DT.coff:
datasize += size(dt.Dty);
break;
default:
Expand Down Expand Up @@ -335,7 +335,7 @@ void dt_writeToObj(Obj objmod, dt_t *dt, int seg, ref targ_size_t offset)
{
switch (dt.dt)
{
case DT_abytes:
case DT.abytes:
{
int flags;
if (tyreg(dt.Dty))
Expand Down Expand Up @@ -369,24 +369,24 @@ else
break;
}

case DT_ibytes:
case DT.ibytes:
objmod.bytes(seg,offset,dt.DTn,dt.DTdata.ptr);
offset += dt.DTn;
break;

case DT_nbytes:
case DT.nbytes:
objmod.bytes(seg,offset,dt.DTnbytes,dt.DTpbytes);
offset += dt.DTnbytes;
break;

case DT_azeros:
case DT.azeros:
//printf("objmod.lidata(seg = %d, offset = %d, azeros = %d)\n", seg, offset, dt.DTazeros);
SegData[seg].SDoffset = offset;
objmod.lidata(seg,offset,dt.DTazeros);
offset = SegData[seg].SDoffset;
break;

case DT_xoff:
case DT.xoff:
{
Symbol *sb = dt.DTsym; // get external symbol pointer
targ_size_t a = dt.DToffset; // offset from it
Expand All @@ -401,7 +401,7 @@ else
break;
}

case DT_coff:
case DT.coff:
objmod.reftocodeseg(seg,offset,dt.DToffset);
offset += _tysize[TYint];
break;
Expand Down
74 changes: 37 additions & 37 deletions compiler/src/dmd/backend/dt.d
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ void dt_free(dt_t *dt)
{
switch (dtn.dt)
{
case DT_abytes:
case DT_nbytes:
case DT.abytes:
case DT.nbytes:
mem_free(dtn.DTpbytes);
break;

Expand Down Expand Up @@ -105,7 +105,7 @@ void init_common(Symbol *s)
uint size = cast(uint)type_size(s.Stype);
if (size)
{
dt_t *dt = dt_calloc(DT_common);
dt_t *dt = dt_calloc(DT.common);
dt.DTazeros = size;
s.Sdt = dt;
}
Expand All @@ -121,22 +121,22 @@ uint dt_size(const(dt_t)* dtstart)
{
switch (dt.dt)
{
case DT_abytes:
case DT.abytes:
datasize += size(dt.Dty);
break;
case DT_ibytes:
case DT.ibytes:
datasize += dt.DTn;
break;
case DT_nbytes:
case DT.nbytes:
datasize += dt.DTnbytes;
break;
case DT_azeros:
case DT.azeros:
datasize += dt.DTazeros;
break;
case DT_common:
case DT.common:
break;
case DT_xoff:
case DT_coff:
case DT.xoff:
case DT.coff:
datasize += size(dt.Dty);
break;
default:
Expand All @@ -153,7 +153,7 @@ uint dt_size(const(dt_t)* dtstart)

bool dtallzeros(const(dt_t)* dt)
{
return dt && dt.dt == DT_azeros && !dt.DTnext;
return dt && dt.dt == DT.azeros && !dt.DTnext;
}

/************************************
Expand All @@ -166,9 +166,9 @@ bool dtpointers(const(dt_t)* dtstart)
{
switch (dt.dt)
{
case DT_abytes:
case DT_xoff:
case DT_coff:
case DT.abytes:
case DT.xoff:
case DT.coff:
return true;

default:
Expand All @@ -179,13 +179,13 @@ bool dtpointers(const(dt_t)* dtstart)
}

/***********************************
* Turn DT_azeros into DTcommon
* Turn DT.azeros into DTcommon
*/

void dt2common(dt_t **pdt)
{
assert((*pdt).dt == DT_azeros);
(*pdt).dt = DT_common;
assert((*pdt).dt == DT.azeros);
(*pdt).dt = DT.common;
}

/**********************************************************/
Expand Down Expand Up @@ -230,12 +230,12 @@ nothrow:
/* Merge all the 0s at the start of the list
* so we can later check for dtallzeros()
*/
if (head && head.dt == DT_azeros)
if (head && head.dt == DT.azeros)
{
while (1)
{
dt_t *dtn = head.DTnext;
if (!(dtn && dtn.dt == DT_azeros))
if (!(dtn && dtn.dt == DT.azeros))
break;

// combine head and dtn
Expand Down Expand Up @@ -273,13 +273,13 @@ nothrow:
dt_t *dt;

if (size < dt_t.DTibytesMax)
{ dt = dt_calloc(DT_ibytes);
{ dt = dt_calloc(DT.ibytes);
dt.DTn = cast(ubyte)size;
memcpy(dt.DTdata.ptr,ptr,size);
}
else
{
dt = dt_calloc(DT_nbytes);
dt = dt_calloc(DT.nbytes);
dt.DTnbytes = size;
dt.DTpbytes = cast(byte *) mem_malloc(size);
memcpy(dt.DTpbytes,ptr,size);
Expand All @@ -304,7 +304,7 @@ nothrow:
@trusted
void abytes(tym_t ty, uint offset, uint size, const(char)* ptr, uint nzeros, ubyte _align)
{
dt_t *dt = dt_calloc(DT_abytes);
dt_t *dt = dt_calloc(DT.abytes);
const n = size + nzeros;
assert(n >= size); // overflow check
dt.DTnbytes = n;
Expand Down Expand Up @@ -339,7 +339,7 @@ nothrow:
return;
}

dt_t *dt = dt_calloc(DT_ibytes);
dt_t *dt = dt_calloc(DT.ibytes);
dt.DTn = 4;

union U { char* cp; int* lp; }
Expand All @@ -364,7 +364,7 @@ nothrow:
nzeros(_tysize[TYnptr]);
return;
}
dt_t *dt = dt_calloc(DT_ibytes);
dt_t *dt = dt_calloc(DT.ibytes);
dt.DTn = _tysize[TYnptr];

union U { char* cp; int* lp; }
Expand All @@ -389,7 +389,7 @@ nothrow:
return;
assert(cast(int) size > 0);

dt_t *dt = dt_calloc(DT_azeros);
dt_t *dt = dt_calloc(DT.azeros);
dt.DTazeros = size;

assert(!*pTail);
Expand All @@ -404,7 +404,7 @@ nothrow:
@trusted
void xoff(Symbol *s, uint offset, tym_t ty)
{
dt_t *dt = dt_calloc(DT_xoff);
dt_t *dt = dt_calloc(DT.xoff);
dt.DTsym = s;
dt.DToffset = offset;
dt.Dty = cast(ubyte)ty;
Expand All @@ -429,7 +429,7 @@ nothrow:
@trusted
dt_t *xoffpatch(Symbol *s, uint offset, tym_t ty)
{
dt_t *dt = dt_calloc(DT_xoff);
dt_t *dt = dt_calloc(DT.xoff);
dt.DTsym = s;
dt.DToffset = offset;
dt.Dty = cast(ubyte)ty;
Expand Down Expand Up @@ -470,7 +470,7 @@ nothrow:
@trusted
void coff(uint offset)
{
dt_t *dt = dt_calloc(DT_coff);
dt_t *dt = dt_calloc(DT.coff);

if (config.exe & EX_segmented)
dt.Dty = TYcptr;
Expand Down Expand Up @@ -548,8 +548,8 @@ nothrow:
dtx.DTnext = null;
switch (dtx.dt)
{
case DT_abytes:
case DT_nbytes:
case DT.abytes:
case DT.nbytes:
dtx.DTpbytes = cast(byte *) mem_malloc(dtx.DTnbytes);
memcpy(dtx.DTpbytes, dtn.DTpbytes, dtx.DTnbytes);
break;
Expand Down Expand Up @@ -578,15 +578,15 @@ nothrow:
{
switch (dtn.dt)
{
case DT_nbytes:
case DT.nbytes:
memcpy(p + offset, dtn.DTpbytes, dtn.DTnbytes);
offset += dtn.DTnbytes;
break;
case DT_ibytes:
case DT.ibytes:
memcpy(p + offset, dtn.DTdata.ptr, dtn.DTn);
offset += dtn.DTn;
break;
case DT_azeros:
case DT.azeros:
memset(p + offset, 0, cast(uint)dtn.DTazeros);
offset += dtn.DTazeros;
break;
Expand All @@ -603,7 +603,7 @@ nothrow:
offset += size;
}

dt_t *dtx = dt_calloc(DT_nbytes);
dt_t *dtx = dt_calloc(DT.nbytes);
dtx.DTnbytes = cast(uint)(size * count);
dtx.DTpbytes = cast(byte*)p;

Expand Down Expand Up @@ -638,7 +638,7 @@ private __gshared dt_t *dt_freelist;
*/

@trusted
private dt_t *dt_calloc(int dtx)
private dt_t *dt_calloc(DT dtx)
{
dt_t *dt = dt_freelist;
if (!dt)
Expand All @@ -657,7 +657,7 @@ private dt_t *dt_calloc(int dtx)
dt_freelist = dt.DTnext;
debug memset(dt, 0xBE, (*dt).sizeof);
dt.DTnext = null;
dt.dt = cast(char)dtx;
dt.dt = dtx;
return dt;
}

Expand All @@ -668,7 +668,7 @@ private dt_t *dt_calloc(int dtx)

dt_t* dt_get_nzeros(uint n)
{
dt_t *dt = dt_calloc(DT_azeros);
dt_t *dt = dt_calloc(DT.azeros);
dt.DTazeros = n;
return dt;
}

0 comments on commit 0ee880f

Please sign in to comment.