Skip to content

Commit f223e95

Browse files
committed
add _Alignof support
2 parents b096bcc + 6b9798e commit f223e95

6 files changed

Lines changed: 66 additions & 360 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ http://www.digitalmars.com
66

77
https://digitalmars.com/ctg/sc.html
88

9-
## Building the compiler:
9+
## Building the compiler (Win32 only):
1010

1111
1. Download and install Digital Mars C++ compiler from https://www.digitalmars.com/download/freecompiler.html
1212
2. Download and install DMD 2.074.1 from http://downloads.dlang.org/releases/2017/
@@ -20,3 +20,5 @@ https://digitalmars.com/ctg/sc.html
2020
`make clean`
2121
`make scppn`
2222
You might need to edit the `makefile` to set the path to your DMD installation.
23+
24+
Note that DMC targets Win32, and hasn't been ported to other platforms.

dm/src/dmc/cgelem.d

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,6 +2140,8 @@ private elem * elcom(elem *e, goal_t goal)
21402140
@trusted
21412141
private elem * elcond(elem *e, goal_t goal)
21422142
{
2143+
//printf("elcond() goal = %d\n", goal);
2144+
//elem_print(e);
21432145
elem *e1 = e.EV.E1;
21442146
switch (e1.Eoper)
21452147
{
@@ -2388,12 +2390,60 @@ private elem * elcond(elem *e, goal_t goal)
23882390
e.EV.E1.EV.E1 = e1;
23892391
}
23902392

2393+
/* Replace:
2394+
* *p op e ? p : false
2395+
* with:
2396+
* bool
2397+
*/
2398+
else if (goal == GOALflags &&
2399+
ec2.Eoper == OPconst && !boolres(ec2) &&
2400+
typtr(ec1.Ety) &&
2401+
ec1.Eoper == OPvar &&
2402+
OTbinary(e1.Eoper) &&
2403+
!OTsideff(e1.Eoper) &&
2404+
e1.EV.E1.Eoper == OPind &&
2405+
el_match(findPointer(e1.EV.E1.EV.E1), ec1) &&
2406+
!el_sideeffect(e))
2407+
{
2408+
/* NOTE: should optimize other cases of this
2409+
*/
2410+
el_free(e.EV.E2);
2411+
e.EV.E2 = null;
2412+
e.Eoper = OPbool;
2413+
e.Ety = TYint;
2414+
}
23912415
break;
23922416
}
23932417
}
23942418
return e;
23952419
}
23962420

2421+
/******************************
2422+
* Given an elem that is the operand to OPind,
2423+
* find the expression representing the pointer.
2424+
* Params:
2425+
* e = operand to OPind
2426+
* Returns:
2427+
* expression that represents the pointer
2428+
*/
2429+
@trusted
2430+
private elem* findPointer(elem* e)
2431+
{
2432+
if (e.Eoper == OPvar)
2433+
return e;
2434+
if (OTleaf(e.Eoper) || !(e.Eoper == OPadd || e.Eoper == OPmin))
2435+
return null;
2436+
2437+
if (typtr(e.EV.E1.Ety))
2438+
return findPointer(e.EV.E1);
2439+
if (OTbinary(e.Eoper))
2440+
{
2441+
if (typtr(e.EV.E2.Ety))
2442+
return findPointer(e.EV.E2);
2443+
}
2444+
return null;
2445+
}
2446+
23972447

23982448
/****************************
23992449
* Comma operator.

dm/src/dmc/dt.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ uint dt_size(const(dt_t)* dtstart)
156156

157157
bool dtallzeros(const(dt_t)* dt)
158158
{
159-
return dt.dt == DT_azeros && !dt.DTnext;
159+
return dt && dt.dt == DT_azeros && !dt.DTnext;
160160
}
161161

162162
/************************************

dm/src/dmc/gflow.d

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ private void initDNunambigVectors(DefNode[] defnod)
334334
if (vec_t v = defnod[i].DNunambig)
335335
{
336336
elem *e = defnod[i].DNelem;
337+
vec_setbit(cast(uint) i, v); // of course it modifies itself
337338
fillInDNunambig(v, e, i, defnod[]);
338339
}
339340
}
@@ -400,13 +401,16 @@ private void fillInDNunambig(vec_t v, elem *e, size_t start, DefNode[] defnod)
400401
if (d != tn1.EV.Vsym)
401402
continue;
402403

403-
// If t completely overlaps tn1
404404
tn1size = (tn.Eoper == OPstreq)
405405
? type_size(tn.ET) : tysize(tn1.Ety);
406-
if (toff <= tn1.EV.Voffset &&
407-
tn1.EV.Voffset + tn1size <= ttop)
406+
// If t completely overlaps tn1
407+
if (toff <= tn1.EV.Voffset && tn1.EV.Voffset + tn1size <= ttop)
408408
{
409409
vec_setbit(cast(uint)i, v);
410+
}
411+
// if tn1 completely overlaps t
412+
if (tn1.EV.Voffset <= toff && ttop <= tn1.EV.Voffset + tn1size)
413+
{
410414
vec_setbit(cast(uint)start, v2);
411415
}
412416
}

dm/src/dmc/makefile

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@
1313

1414
DMCDIR=\dm
1515

16-
#DMDDIR=e:\dmd2.074
17-
#DMDDIR79=e:\dmd2.079
18-
DMDDIR=e:\dmd2.079
19-
DMDDIR74=e:\dmd2.074
20-
DMDDIR79=e:\dmd2.079
21-
DMDDIR92=e:\dmd2.092
22-
2316
CBX=.
2417
NTDLLSHELL=ntdllshell
2518
TK=tk
@@ -70,16 +63,7 @@ LFLAGS=/map/e/f/packcode/noe;
7063
##### Tools
7164

7265
# D compiler
73-
DMD=$(DMDDIR)\windows\bin\dmd
74-
DMD74=$(DMDDIR74)\windows\bin\dmd
75-
DMD79=$(DMDDIR79)\windows\bin\dmd
76-
DMDXX=$(DMDDIR74)\windows\bin\dmd
77-
78-
DMD=$(DMDDIR92)\windows\bin\dmd
79-
DMD74=$(DMDDIR92)\windows\bin\dmd
80-
DMD79=$(DMDDIR92)\windows\bin\dmd
81-
DMDXX=$(DMDDIR92)\windows\bin\dmd
82-
66+
DMD=dmd
8367
# C++ compiler
8468
CC=dmc
8569
# Make program
@@ -431,7 +415,7 @@ barray.obj : barray.d
431415
$(DMD) -c $(DFLAGS) barray.d
432416

433417
bcomplex.obj : bcomplex.d
434-
$(DMD79) -c $(DFLAGS) bcomplex.d
418+
$(DMD) -c $(DFLAGS) bcomplex.d
435419

436420
blockopt.obj : blockopt.d
437421
$(DMD) -c $(DFLAGS) blockopt.d
@@ -548,7 +532,7 @@ dnwc.obj : dnwc.d
548532
$(DMD) -c $(DFLAGS) dnwc.d
549533

550534
dph.obj : dph.d page.di
551-
$(DMD79) -c $(DFLAGS) dph.d
535+
$(DMD) -c $(DFLAGS) dph.d
552536

553537
dpragma.obj : dpragma.d
554538
$(DMD) -c $(DFLAGS) dpragma.d
@@ -560,10 +544,10 @@ dspeller.obj : dspeller.d
560544
$(DMD) -c $(DFLAGS) dspeller.d
561545

562546
dtemplate.obj : dtemplate.d
563-
$(DMD79) -c $(DFLAGS) dtemplate.d
547+
$(DMD) -c $(DFLAGS) dtemplate.d
564548

565549
dtype.obj : dtype.d
566-
$(DMD79) -c $(DFLAGS) dtype.d
550+
$(DMD) -c $(DFLAGS) dtype.d
567551

568552
dwarfeh.obj : dwarfeh.d
569553
$(DMD) -c $(DFLAGS) dwarfeh.d

0 commit comments

Comments
 (0)