added function returnAtEnd - to determine if a basic block terminates with
authorsandeep <sandeep@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 30 Jan 2002 04:09:40 +0000 (04:09 +0000)
committersandeep <sandeep@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 30 Jan 2002 04:09:40 +0000 (04:09 +0000)
a RETURN iCode

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1861 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCcflow.c
src/SDCCcflow.h

index 2dc5313511da4c1957ea4329bcaff58817075de8..4db709480e6cbae2c7c2653555a5e1bde0a9d2c7 100644 (file)
@@ -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;
+}
index 949c9b5c3d3044cccfc342d8b473a3cfa3454c2f..4d6af9f5e68d61c3249ae2a23b2bc2e1b27c378d 100644 (file)
@@ -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