From: sandeep Date: Wed, 30 Jan 2002 04:09:40 +0000 (+0000) Subject: added function returnAtEnd - to determine if a basic block terminates with X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=aac4af49be9af5dbbdf36f81aa8e38f369f67456;p=fw%2Fsdcc added function returnAtEnd - to determine if a basic block terminates with a RETURN iCode git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1861 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCCcflow.c b/src/SDCCcflow.c index 2dc53135..4db70948 100644 --- a/src/SDCCcflow.c +++ b/src/SDCCcflow.c @@ -425,3 +425,35 @@ computeControlFlow (eBBlock ** ebbs, int count, int reSort) qsort (ebbs, saveCount, sizeof (eBBlock *), dfNumCompare); } + +/*-----------------------------------------------------------------*/ +/* returnAtEnd - returns 1 if Basic Block has a return at the end */ +/* of it */ +/*-----------------------------------------------------------------*/ +int returnAtEnd (eBBlock *ebp) +{ + /* case 1. + This basic block ends in a return statment + */ + if (ebp->ech && ebp->ech->op == RETURN) return 1; + + /* case 2. + This basic block has only one successor and that + successor has only one return statement + */ + if (elementsInSet(ebp->succList) == 1) { + eBBlock *succ = setFirstItem(ebp->succList); + /* could happen for dummy blocks */ + if (!succ->sch || !succ->ech) return 0; + + /* first iCode is a return */ + if (succ->sch->op == RETURN) return 2; + + /* or first iCode is a label & the next & + last icode is a return */ + if (succ->sch->op == LABEL && succ->sch->next == succ->ech && + succ->ech->op == RETURN ) return 2; + } + + return 0; +} diff --git a/src/SDCCcflow.h b/src/SDCCcflow.h index 949c9b5c..4d6af9f5 100644 --- a/src/SDCCcflow.h +++ b/src/SDCCcflow.h @@ -40,5 +40,5 @@ void computeControlFlow (eBBlock **, int, int); int dfNumCompare (const void *, const void *); int bbNumCompare (const void *, const void *); void disconBBlock (eBBlock *, eBBlock **, int); - +int returnAtEnd (eBBlock *) ; #endif