Skip to content

Commit 87a06cb

Browse files
authored
pass through debugprint.d to just make it nicer (dlang#23000)
1 parent 179d809 commit 87a06cb

1 file changed

Lines changed: 141 additions & 130 deletions

File tree

compiler/src/dmd/backend/debugprint.d

Lines changed: 141 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ nothrow:
4141
void ferr(const(char)* p) { printf("%s", p); }
4242

4343
/*******************************
44-
* Params: storage class SC members
45-
* Returns: storage class string
44+
* Params:
45+
* c = storage class SC members
46+
* Returns:
47+
* storage class string
4648
*/
4749

4850
@trusted
@@ -177,12 +179,12 @@ const(char)* bc_str(uint bc)
177179
}
178180

179181
private immutable char[8][BC.max + 1] bcs =
180-
["unde ","goto_ ","true ","ret ","retexp",
181-
"exit ","asm_ ","switch_","ifthen","jmptab",
182-
"try_ ","catch_ ","jump ",
183-
"_try ","_filter","_final ","_ret ","_excep",
184-
"jcatch","_lpad ",
185-
];
182+
[
183+
"unde ", "goto_ ", "true ", "ret ", "retexp ",
184+
"exit ", "asm_ ", "switch_", "ifthen", "jmptab ",
185+
"try_ ", "catch_ ", "jump ", "_try ", "_filter",
186+
"_final ", "_ret ", "_excep ", "jcatch", "_lpad ",
187+
];
186188

187189

188190
/************************
@@ -191,21 +193,26 @@ private immutable char[8][BC.max + 1] bcs =
191193

192194
@trusted
193195
void WRarglst(list_t a)
194-
{ int n = 1;
195-
196-
if (!a) printf("0 args\n");
197-
while (a)
198-
{ const(char)* c = cast(const(char)*)list_ptr(a);
199-
printf("arg %d: '%s'\n", n, c ? c : "NULL");
200-
a = a.next;
201-
n++;
202-
}
196+
{
197+
if (a)
198+
{
199+
int n = 1;
200+
do
201+
{
202+
const(char)* c = cast(const(char)*)list_ptr(a);
203+
printf("arg %d: '%s'\n", n, c ? c : "NULL");
204+
a = a.next;
205+
n++;
206+
} while (a);
207+
}
208+
else
209+
printf("0 args\n");
203210
}
204211

205212
/***************************
206213
* Write out equation elem.
207214
* Params:
208-
* e = equation to print
215+
* e = equation to print
209216
*/
210217

211218
@trusted
@@ -215,99 +222,99 @@ void WReqn(elem* e)
215222

216223
nothrow void eqn(elem* e)
217224
{
218-
nothrow void nestEqn(elem* e)
219-
{
220-
++nest;
221-
ferr("(");
222-
eqn(e);
223-
ferr(")");
224-
--nest;
225-
}
226-
227-
if (!e)
228-
return;
229-
if (OTunary(e.Eoper))
230-
{
231-
ferr(oper_str(e.Eoper));
232-
ferr(" ");
233-
if (OTbinary(e.E1.Eoper))
234-
nestEqn(e.E1);
235-
else
236-
eqn(e.E1);
237-
}
238-
else if (e.Eoper == OPcomma && !nest)
239-
{
240-
eqn(e.E1);
241-
printf(";\n\t");
242-
eqn(e.E2);
243-
}
244-
else if (OTbinary(e.Eoper))
245-
{
246-
if (OTbinary(e.E1.Eoper))
247-
nestEqn(e.E1);
248-
else
249-
eqn(e.E1);
250-
ferr(" ");
251-
ferr(oper_str(e.Eoper));
252-
ferr(" ");
253-
if (e.Eoper == OPstreq)
254-
printf("%d", cast(int)type_size(e.ET));
255-
ferr(" ");
256-
if (OTbinary(e.E2.Eoper))
257-
nestEqn(e.E2);
258-
else
259-
eqn(e.E2);
260-
}
261-
else
262-
{
263-
switch (e.Eoper)
264-
{
265-
case OPconst:
266-
elem_print_const(e);
267-
break;
268-
269-
case OPrelconst:
270-
ferr("#");
271-
goto case OPvar;
272-
273-
case OPvar:
274-
printf("%s",e.Vsym.Sident.ptr);
275-
if (e.Vsym.Ssymnum != SYMIDX.max)
276-
printf("(%d)", cast(int) e.Vsym.Ssymnum);
277-
if (e.Voffset != 0)
278-
{
279-
if (e.Voffset.sizeof == 8)
280-
printf(".x%llx", cast(ulong)e.Voffset);
281-
else
282-
printf(".%d",cast(int)e.Voffset);
283-
}
284-
break;
285-
286-
case OPasm:
287-
case OPstring:
288-
printf("\"%s\"",e.Vstring);
289-
if (e.Voffset)
290-
printf("+%lld",cast(long)e.Voffset);
291-
break;
292-
293-
case OPmark:
294-
case OPgot:
295-
case OPframeptr:
296-
case OPhalt:
297-
case OPdctor:
298-
case OPddtor:
299-
ferr(oper_str(e.Eoper));
300-
ferr(" ");
301-
break;
302-
303-
case OPstrthis:
304-
break;
305-
306-
default:
307-
ferr(oper_str(e.Eoper));
308-
assert(0);
309-
}
310-
}
225+
nothrow void nestEqn(elem* e)
226+
{
227+
++nest;
228+
ferr("(");
229+
eqn(e);
230+
ferr(")");
231+
--nest;
232+
}
233+
234+
if (!e)
235+
return;
236+
if (OTunary(e.Eoper))
237+
{
238+
ferr(oper_str(e.Eoper));
239+
ferr(" ");
240+
if (OTbinary(e.E1.Eoper))
241+
nestEqn(e.E1);
242+
else
243+
eqn(e.E1);
244+
}
245+
else if (e.Eoper == OPcomma && !nest)
246+
{
247+
eqn(e.E1);
248+
printf(";\n\t");
249+
eqn(e.E2);
250+
}
251+
else if (OTbinary(e.Eoper))
252+
{
253+
if (OTbinary(e.E1.Eoper))
254+
nestEqn(e.E1);
255+
else
256+
eqn(e.E1);
257+
ferr(" ");
258+
ferr(oper_str(e.Eoper));
259+
ferr(" ");
260+
if (e.Eoper == OPstreq)
261+
printf("%d", cast(int)type_size(e.ET));
262+
ferr(" ");
263+
if (OTbinary(e.E2.Eoper))
264+
nestEqn(e.E2);
265+
else
266+
eqn(e.E2);
267+
}
268+
else
269+
{
270+
switch (e.Eoper)
271+
{
272+
case OPconst:
273+
elem_print_const(e);
274+
break;
275+
276+
case OPrelconst:
277+
ferr("#");
278+
goto case OPvar;
279+
280+
case OPvar:
281+
printf("%s",e.Vsym.Sident.ptr);
282+
if (e.Vsym.Ssymnum != SYMIDX.max)
283+
printf("(%d)", cast(int) e.Vsym.Ssymnum);
284+
if (e.Voffset != 0)
285+
{
286+
if (e.Voffset.sizeof == 8)
287+
printf(".x%llx", cast(ulong)e.Voffset);
288+
else
289+
printf(".%d",cast(int)e.Voffset);
290+
}
291+
break;
292+
293+
case OPasm:
294+
case OPstring:
295+
printf("\"%s\"",e.Vstring);
296+
if (e.Voffset)
297+
printf("+%lld",cast(long)e.Voffset);
298+
break;
299+
300+
case OPmark:
301+
case OPgot:
302+
case OPframeptr:
303+
case OPhalt:
304+
case OPdctor:
305+
case OPddtor:
306+
ferr(oper_str(e.Eoper));
307+
ferr(" ");
308+
break;
309+
310+
case OPstrthis:
311+
break;
312+
313+
default:
314+
ferr(oper_str(e.Eoper));
315+
assert(0);
316+
}
317+
}
311318
}
312319

313320
eqn(e);
@@ -330,19 +337,20 @@ void WRblocklist(list_t bl)
330337

331338
@trusted
332339
void WRdefnod(ref GlobalOptimizer go)
333-
{ int i;
334-
335-
for (i = 0; i < go.defnod.length; i++)
336-
{ printf("defnod[%d] in B%d = (", go.defnod[i].DNblock.Bdfoidx, i);
340+
{
341+
foreach (i; 0 .. go.defnod.length)
342+
{
343+
printf("defnod[%d] in B%zu = (", go.defnod[i].DNblock.Bdfoidx, i);
337344
WReqn(go.defnod[i].DNelem);
338345
printf(");\n");
339-
}
346+
}
340347
}
341348

342349
const(char)* fl_str(FL fl)
343350
{
344351
immutable char*[FL.max + 1] fls =
345-
[ "FL.unde",
352+
[
353+
"FL.unde",
346354
"FL.const_",
347355
"FL.oper",
348356
"FL.func",
@@ -393,12 +401,13 @@ void WRblock(block* b)
393401
if (OPTIMIZER)
394402
{
395403
if (b && b.Bweight)
396-
printf("B%d: (%p), weight=%d",b.Bdfoidx,b,b.Bweight);
404+
printf("B%d: (%p), weight=%d",b.Bdfoidx,b,b.Bweight);
397405
else
398-
printf("block %p",b);
406+
printf("block %p",b);
399407
if (!b)
400-
{ ferr("\n");
401-
return;
408+
{
409+
ferr("\n");
410+
return;
402411
}
403412
printf(" flags=x%x weight=%d",b.Bflags,b.Bweight);
404413
//printf("\tfile %p, line %d",b.Bfilptr,b.Blinnum);
@@ -409,13 +418,15 @@ void WRblock(block* b)
409418
printf("\tBpred: "); WRblocklist(b.Bpred);
410419
printf("\tBsucc: "); WRblocklist(b.Bsucc);
411420
if (b.Belem)
412-
{ if (debugf) /* if full output */
413-
elem_print(b.Belem);
414-
else
415-
{ ferr("\t");
416-
WReqn(b.Belem);
417-
printf(";\n");
418-
}
421+
{
422+
if (debugf) /* if full output */
423+
elem_print(b.Belem);
424+
else
425+
{
426+
ferr("\t");
427+
WReqn(b.Belem);
428+
printf(";\n");
429+
}
419430
}
420431
if (b.Bcode)
421432
b.Bcode.print();
@@ -505,9 +516,9 @@ void WRblock(block* b)
505516
*/
506517
void numberBlocks(block* startblock)
507518
{
508-
uint number = 0;
519+
uint n = 0;
509520
for (block* b = startblock; b; b = b.Bnext)
510-
b.Bnumber = ++number;
521+
b.Bnumber = ++n;
511522
}
512523

513524
/**************************************

0 commit comments

Comments
 (0)