Skip to content

Commit

Permalink
remove dependency on list_t
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Feb 3, 2013
1 parent a6bcdab commit 066cc00
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 52 deletions.
5 changes: 5 additions & 0 deletions src/backend/cc.h
Expand Up @@ -557,6 +557,11 @@ typedef struct block
#define Btryoff _BLU._UD.Btryoff
} _UD;
} _BLU;

void appendSucc(block *b) { list_append(&this->Bsucc, b); }
void prependSucc(block *b) { list_prepend(&this->Bsucc, b); }
int numSucc() { return list_nitems(this->Bsucc); }
block *nthSucc(int n) { return (block *)list_ptr(list_nth(Bsucc, n)); }
} block;

#define list_block(l) ((block *) list_ptr(l))
Expand Down
12 changes: 6 additions & 6 deletions src/eh.c
Expand Up @@ -185,7 +185,7 @@ void except_fillInEHTable(symbol *s)
}
i = b->Bscope_index + 1;

int nsucc = list_nitems(b->Bsucc);
int nsucc = b->numSucc();

if (OUREH)
{
Expand Down Expand Up @@ -221,10 +221,10 @@ void except_fillInEHTable(symbol *s)
{
assert(nsucc == 2);
pdt = dtdword(pdt,0); // no catch offset
block *bhandler = list_block(list_next(b->Bsucc));
block *bhandler = b->nthSucc(1);
assert(bhandler->BC == BC_finally);
// To successor of BC_finally block
bhandler = list_block(bhandler->Bsucc);
bhandler = bhandler->nthSucc(0);
// finally handler address
if (OUREH)
{
Expand Down Expand Up @@ -344,13 +344,13 @@ void except_fillInEHTable(symbol *s)
{
if (b->BC == BC_try && b->jcatchvar) // if try-catch
{
int nsucc = list_nitems(b->Bsucc);
int nsucc = b->numSucc();
pdt = dtsize_t(pdt,nsucc - 1); // # of catch blocks
sz += NPTRSIZE;

for (list_t bl = list_next(b->Bsucc); bl; bl = list_next(bl))
for (int i = 1; i < nsucc; ++i)
{
block *bcatch = list_block(bl);
block *bcatch = b->nthSucc(i);

pdt = dtxoff(pdt,bcatch->Bcatchtype,0,TYjhandle);

Expand Down
92 changes: 46 additions & 46 deletions src/s2ir.c
@@ -1,6 +1,6 @@

// Compiler implementation of the D programming language
// Copyright (c) 2000-2012 by Digital Mars
// Copyright (c) 2000-2013 by Digital Mars
// All Rights Reserved
// Written by Walter Bright
// http://www.digitalmars.com
Expand Down Expand Up @@ -162,20 +162,20 @@ void IfStatement::toIR(IRState *irs)
block *bcond = blx->curblock;
block_next(blx, BCiftrue, NULL);

list_append(&bcond->Bsucc, blx->curblock);
bcond->appendSucc(blx->curblock);
if (ifbody)
ifbody->toIR(&mystate);
list_append(&blx->curblock->Bsucc, bexit);
blx->curblock->appendSucc(bexit);

if (elsebody)
{
block_next(blx, BCgoto, NULL);
list_append(&bcond->Bsucc, blx->curblock);
bcond->appendSucc(blx->curblock);
elsebody->toIR(&mystate);
list_append(&blx->curblock->Bsucc, bexit);
blx->curblock->appendSucc(bexit);
}
else
list_append(&bcond->Bsucc, bexit);
bcond->appendSucc(bexit);

block_next(blx, BCgoto, bexit);

Expand Down Expand Up @@ -224,14 +224,14 @@ void DoStatement::toIR(IRState *irs)

block *bpre = blx->curblock;
block_next(blx, BCgoto, NULL);
list_append(&bpre->Bsucc, blx->curblock);
bpre->appendSucc(blx->curblock);

list_append(&mystate.contBlock->Bsucc, blx->curblock);
list_append(&mystate.contBlock->Bsucc, mystate.breakBlock);
mystate.contBlock->appendSucc(blx->curblock);
mystate.contBlock->appendSucc(mystate.breakBlock);

if (body)
body->toIR(&mystate);
list_append(&blx->curblock->Bsucc, mystate.contBlock);
blx->curblock->appendSucc(mystate.contBlock);

block_next(blx, BCgoto, mystate.contBlock);
incUsage(irs, condition->loc);
Expand All @@ -256,28 +256,28 @@ void ForStatement::toIR(IRState *irs)
block *bpre = blx->curblock;
block_next(blx,BCgoto,NULL);
block *bcond = blx->curblock;
list_append(&bpre->Bsucc, bcond);
list_append(&mystate.contBlock->Bsucc, bcond);
bpre->appendSucc(bcond);
mystate.contBlock->appendSucc(bcond);
if (condition)
{
incUsage(irs, condition->loc);
block_appendexp(bcond, condition->toElemDtor(&mystate));
block_next(blx,BCiftrue,NULL);
list_append(&bcond->Bsucc, blx->curblock);
list_append(&bcond->Bsucc, mystate.breakBlock);
bcond->appendSucc(blx->curblock);
bcond->appendSucc(mystate.breakBlock);
}
else
{ /* No conditional, it's a straight goto
*/
block_next(blx,BCgoto,NULL);
list_append(&bcond->Bsucc, blx->curblock);
bcond->appendSucc(blx->curblock);
}

if (body)
body->toIR(&mystate);
/* End of the body goes to the continue block
*/
list_append(&blx->curblock->Bsucc, mystate.contBlock);
blx->curblock->appendSucc(mystate.contBlock);
block_next(blx, BCgoto, mystate.contBlock);

if (increment)
Expand Down Expand Up @@ -335,7 +335,7 @@ void BreakStatement::toIR(IRState *irs)

/* Nothing more than a 'goto' to the current break destination
*/
list_append(&b->Bsucc, bbreak);
b->appendSucc(bbreak);
block_next(blx, BCgoto, NULL);
}

Expand All @@ -362,7 +362,7 @@ void ContinueStatement::toIR(IRState *irs)

/* Nothing more than a 'goto' to the current continue destination
*/
list_append(&b->Bsucc, bcont);
b->appendSucc(bcont);
block_next(blx, BCgoto, NULL);
}

Expand Down Expand Up @@ -444,7 +444,7 @@ void GotoStatement::toIR(IRState *irs)
}
}

list_append(&b->Bsucc,bdest);
b->appendSucc(bdest);
block_next(blx,BCgoto,NULL);
}

Expand Down Expand Up @@ -490,7 +490,7 @@ void LabelStatement::toIR(IRState *irs)
else
lblock = block_calloc(blx);
block_next(blx,BCgoto,lblock);
list_append(&bc->Bsucc,blx->curblock);
bc->appendSucc(blx->curblock);
if (statement)
statement->toIR(&mystate);
}
Expand Down Expand Up @@ -547,15 +547,15 @@ void SwitchStatement::toIR(IRState *irs)
block *bcase = block_calloc(blx);
cs->cblock = bcase;
block_next(blx, BCiftrue, NULL);
list_append(&b->Bsucc, bcase);
list_append(&b->Bsucc, blx->curblock);
b->appendSucc(bcase);
b->appendSucc(blx->curblock);
}

/* The final 'else' clause goes to the default
*/
block *b = blx->curblock;
block_next(blx, BCgoto, NULL);
list_append(&b->Bsucc, mystate.defaultBlock);
b->appendSucc(mystate.defaultBlock);

body->toIR(&mystate);

Expand Down Expand Up @@ -638,7 +638,7 @@ void SwitchStatement::toIR(IRState *irs)
/* First pair is the number of cases, and the default block
*/
*pu++ = numcases;
list_append(&mystate.switchBlock->Bsucc, mystate.defaultBlock);
mystate.switchBlock->appendSucc(mystate.defaultBlock);

/* Fill in the first entry in each pair, which is the case value.
* CaseStatement::toIR() will fill in
Expand Down Expand Up @@ -674,8 +674,8 @@ void CaseStatement::toIR(IRState *irs)
block_next(blx,BCgoto,cblock);
block *bsw = irs->getSwitchBlock();
if (bsw->BC == BCswitch)
list_append(&bsw->Bsucc,cblock); // second entry in pair
list_append(&bcase->Bsucc,cblock);
bsw->appendSucc(cblock); // second entry in pair
bcase->appendSucc(cblock);
if (blx->tryblock != bsw->Btry)
error("case cannot be in different try block level from switch");
incUsage(irs, loc);
Expand All @@ -689,7 +689,7 @@ void DefaultStatement::toIR(IRState *irs)
block *bcase = blx->curblock;
block *bdefault = irs->getDefaultBlock();
block_next(blx,BCgoto,bdefault);
list_append(&bcase->Bsucc,blx->curblock);
bcase->appendSucc(blx->curblock);
if (blx->tryblock != irs->getSwitchBlock()->Btry)
error("default cannot be in different try block level from switch");
incUsage(irs, loc);
Expand Down Expand Up @@ -724,7 +724,7 @@ void GotoDefaultStatement::toIR(IRState *irs)
//setScopeIndex(blx, b, bdest->Btry ? bdest->Btry->Bscope_index : -1);
}

list_append(&b->Bsucc,bdest);
b->appendSucc(bdest);
incUsage(irs, loc);
block_next(blx,BCgoto,NULL);
}
Expand Down Expand Up @@ -762,7 +762,7 @@ void GotoCaseStatement::toIR(IRState *irs)
//setScopeIndex(blx, b, bdest->Btry ? bdest->Btry->Bscope_index : -1);
}

list_append(&b->Bsucc,bdest);
b->appendSucc(bdest);
incUsage(irs, loc);
block_next(blx,BCgoto,NULL);
}
Expand Down Expand Up @@ -885,11 +885,11 @@ void ReturnStatement::toIR(IRState *irs)
if (btry)
{
// A finally block is a successor to a return block inside a try-finally
if (list_nitems(btry->Bsucc) == 2) // try-finally
if (btry->numSucc() == 2) // try-finally
{
block *bfinally = list_block(list_next(btry->Bsucc));
block *bfinally = btry->nthSucc(1);
assert(bfinally->BC == BC_finally);
list_append(&blx->curblock->Bsucc, bfinally);
blx->curblock->appendSucc(bfinally);
}
}
block_next(blx, bc, NULL);
Expand Down Expand Up @@ -963,7 +963,7 @@ void UnrolledLoopStatement::toIR(IRState *irs)
block_next(blx, BCgoto, NULL);

block *bdo = blx->curblock;
list_append(&bpre->Bsucc, bdo);
bpre->appendSucc(bdo);

block *bdox;

Expand All @@ -979,13 +979,13 @@ void UnrolledLoopStatement::toIR(IRState *irs)

bdox = blx->curblock;
block_next(blx, BCgoto, mystate.contBlock);
list_append(&bdox->Bsucc, mystate.contBlock);
bdox->appendSucc(mystate.contBlock);
}
}

bdox = blx->curblock;
block_next(blx, BCgoto, mystate.breakBlock);
list_append(&bdox->Bsucc, mystate.breakBlock);
bdox->appendSucc(mystate.breakBlock);
}


Expand Down Expand Up @@ -1111,7 +1111,7 @@ void TryCatchStatement::toIR(IRState *irs)
// create new break block that follows all the catches
breakblock = block_calloc(blx);

list_append(&blx->curblock->Bsucc, breakblock);
blx->curblock->appendSucc(breakblock);
block_next(blx,BCgoto,NULL);

assert(catches);
Expand All @@ -1123,14 +1123,14 @@ void TryCatchStatement::toIR(IRState *irs)
block *bcatch = blx->curblock;
if (cs->type)
bcatch->Bcatchtype = cs->type->toBasetype()->toSymbol();
list_append(&tryblock->Bsucc,bcatch);
tryblock->appendSucc(bcatch);
block_goto(blx,BCjcatch,NULL);
if (cs->handler != NULL)
{
IRState catchState(irs, this);
cs->handler->toIR(&catchState);
}
list_append(&blx->curblock->Bsucc, breakblock);
blx->curblock->appendSucc(breakblock);
block_next(blx, BCgoto, NULL);
}

Expand Down Expand Up @@ -1174,7 +1174,7 @@ void TryFinallyStatement::toIR(IRState *irs)
IRState bodyirs(irs, this);
block *breakblock = block_calloc(blx);
block *contblock = block_calloc(blx);
list_append(&tryblock->Bsucc,contblock);
tryblock->appendSucc(contblock);
contblock->BC = BC_finally;

if (body)
Expand Down Expand Up @@ -1203,8 +1203,8 @@ void TryFinallyStatement::toIR(IRState *irs)
block *retblock = blx->curblock;
block_next(blx,BC_ret,NULL);

list_append(&finallyblock->Bsucc, blx->curblock);
list_append(&retblock->Bsucc, blx->curblock);
finallyblock->appendSucc(blx->curblock);
retblock->appendSucc(blx->curblock);
}

/****************************************
Expand All @@ -1231,7 +1231,7 @@ void AsmStatement::toIR(IRState *irs)
bpre = blx->curblock;
block_next(blx,BCgoto,NULL);
basm = blx->curblock;
list_append(&bpre->Bsucc, basm);
bpre->appendSucc(basm);
basm->Bcode = asmcode;
basm->Balign = asmalign;
#if 0
Expand All @@ -1241,7 +1241,7 @@ void AsmStatement::toIR(IRState *irs)
b = labelToBlock(loc, blx, label);
printf("AsmStatement::toIR() %p\n", b);
if (b)
list_append(&basm->Bsucc, b);
basm->appendSucc(b);
}
#endif
// Loop through each instruction, fixing Dsymbols into Symbol's
Expand All @@ -1256,7 +1256,7 @@ void AsmStatement::toIR(IRState *irs)
// FLblock and FLblockoff have LabelDsymbol's - convert to blocks
label = c->IEVlsym1;
b = labelToBlock(loc, blx, label);
list_append(&basm->Bsucc, b);
basm->appendSucc(b);
c->IEV1.Vblock = b;
break;

Expand All @@ -1278,7 +1278,7 @@ void AsmStatement::toIR(IRState *irs)
case FLblock:
label = c->IEVlsym2;
b = labelToBlock(loc, blx, label);
list_append(&basm->Bsucc, b);
basm->appendSucc(b);
c->IEV2.Vblock = b;
break;

Expand All @@ -1302,7 +1302,7 @@ void AsmStatement::toIR(IRState *irs)
basm->usIasmregs = regs; // registers modified

block_next(blx,BCasm, NULL);
list_prepend(&basm->Bsucc, blx->curblock);
basm->prependSucc(blx->curblock);

if (naked)
{
Expand Down

0 comments on commit 066cc00

Please sign in to comment.