Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DT a D enum #20651

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
{
//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 @@
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 @@
}
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 @@
}
}
goto case;
case DT_coff:
case DT.coff:
datasize += size(dt.Dty);
break;
default:
Expand Down Expand Up @@ -335,7 +335,7 @@
{
switch (dt.dt)
{
case DT_abytes:
case DT.abytes:
{
int flags;
if (tyreg(dt.Dty))
Expand Down Expand Up @@ -369,24 +369,24 @@
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 @@
break;
}

case DT_coff:
case DT.coff:

Check warning on line 404 in compiler/src/dmd/backend/dout.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/dout.d#L404

Added line #L404 was not covered by tests
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 @@
{
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 @@
uint size = cast(uint)type_size(s.Stype);
if (size)
{
dt_t *dt = dt_calloc(DT_common);
dt_t *dt = dt_calloc(DT.common);

Check warning on line 108 in compiler/src/dmd/backend/dt.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/dt.d#L108

Added line #L108 was not covered by tests
dt.DTazeros = size;
s.Sdt = dt;
}
Expand All @@ -121,22 +121,22 @@
{
switch (dt.dt)
{
case DT_abytes:
case DT.abytes:

Check warning on line 124 in compiler/src/dmd/backend/dt.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/dt.d#L124

Added line #L124 was not covered by tests
datasize += size(dt.Dty);
break;
case DT_ibytes:
case DT.ibytes:
datasize += dt.DTn;
break;
case DT_nbytes:
case DT.nbytes:

Check warning on line 130 in compiler/src/dmd/backend/dt.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/dt.d#L130

Added line #L130 was not covered by tests
datasize += dt.DTnbytes;
break;
case DT_azeros:
case DT.azeros:
datasize += dt.DTazeros;
break;
case DT_common:
case DT.common:

Check warning on line 136 in compiler/src/dmd/backend/dt.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/dt.d#L136

Added line #L136 was not covered by tests
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 @@

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 @@
{
switch (dt.dt)
{
case DT_abytes:
case DT_xoff:
case DT_coff:
case DT.abytes:

Check warning on line 169 in compiler/src/dmd/backend/dt.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/dt.d#L169

Added line #L169 was not covered by tests
case DT.xoff:
case DT.coff:
return true;

default:
Expand All @@ -179,13 +179,13 @@
}

/***********************************
* 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 @@
/* 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 @@
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 @@
@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 @@
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 @@
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 @@
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 @@
@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 @@
@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 @@
@trusted
void coff(uint offset)
{
dt_t *dt = dt_calloc(DT_coff);
dt_t *dt = dt_calloc(DT.coff);

Check warning on line 473 in compiler/src/dmd/backend/dt.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/dt.d#L473

Added line #L473 was not covered by tests

if (config.exe & EX_segmented)
dt.Dty = TYcptr;
Expand Down Expand Up @@ -548,8 +548,8 @@
dtx.DTnext = null;
switch (dtx.dt)
{
case DT_abytes:
case DT_nbytes:
case DT.abytes:
case DT.nbytes:

Check warning on line 552 in compiler/src/dmd/backend/dt.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/dt.d#L551-L552

Added lines #L551 - L552 were not covered by tests
dtx.DTpbytes = cast(byte *) mem_malloc(dtx.DTnbytes);
memcpy(dtx.DTpbytes, dtn.DTpbytes, dtx.DTnbytes);
break;
Expand Down Expand Up @@ -578,15 +578,15 @@
{
switch (dtn.dt)
{
case DT_nbytes:
case DT.nbytes:

Check warning on line 581 in compiler/src/dmd/backend/dt.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/dt.d#L581

Added line #L581 was not covered by tests
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 @@
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 @@
*/

@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 @@
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 @@

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

Check warning on line 671 in compiler/src/dmd/backend/dt.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/backend/dt.d#L671

Added line #L671 was not covered by tests
dt.DTazeros = n;
return dt;
}
Loading