The following example uses a rule set written in XTRAN's rules language ("meta-code") that finds and suppresses every statement that is "dead" (cannot execute). The rules comprise 147 non-comment lines of meta-code.
NOTE that these rules are language-independent; they are exactly the same rules used for similar examples for other languages.
Strategy:
void func(void)
{
int i;
if (i == 0 || i == 1)
goto lbl2;
i = 1;
goto lbl3;
/*
* The following code is dead and should therefore be eliminated:
*/
if (i > 1)
goto lbl1;
i = 2;
lbl1: i = 3;
goto lbl3;
/*
* The following statement is dead and should therefore be eliminated:
*/
i = 5;
lbl2: i = 6;
lbl3: i = 7;
}
void func(void)
{
int i;
if (i == 0 || i == 1)
goto lbl2;
i = 1;
goto lbl3;
lbl2:
i = 6;
lbl3:
i = 7;
}
COPYRIGHT 2008; reproduction prohibited without permission. Revised 2006-11-27
XTRAN is a trademark of Pennington Systems Incorporated.
Pennington Systems Incorporated
8655 East
Via de Ventura, Suite G200
Scottsdale, Arizona 85258-3321
Phone: +1(480)626-5503
Fax: +1(480)626-7618
Email: Info@Pennington.com
Web: http://WWW.Pennington.com