I work on a large codebase of code written in C for embedded processors. There are many conditionally compiled statements in the code that makes it difficult to read. I would like to know if there exists a perl script that will execute like a C pre-processor to strip away code which is not relavant based on a set of macros. The output from the script would then be used just for reading the code.
I want to use PERL because I want to be able to easily modify the script. For example, in the code snippet below, I would want to include the code unmodified if the macro BCS_GFSK_TRACKING_HW_FIX if defined. I would not want to replace BCS_LINKTYPE_ACL_MDR with an actual number because I want to maintain the readability of the code.
#ifdef BCS_GFSK_TRACKING_HW_FIX
// The following is HWWA for BR freq tracking
switch ( logicalConnInfo )
{
case BCS_LINKTYPE_ACL_MDR:
case BCS_LINKTYPE_ESCO_MDR:
{
REG32(dcOffEstCtrl5_adr) &= ~(((UINT32)1) << TRACK_GFSK_FR
+EQ_MASK_OFFSET);
break;
}
default:
{
REG32(dcOffEstCtrl5_adr) |= (((UINT32)1) << TRACK_GFSK_FRE
+Q_MASK_OFFSET);
break;
}
}
#endif
I found a script at the location below, but it does not appear to handle complex statements such as:
#if (defined(BCM20702) || defined(BCM20733)) && !defined(FPGA_BD_2
+045)
http://software.hixie.ch/utilities/unix/preprocessor/
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.