numam-dpdk/scripts/cocci/mtod-offset.cocci
Cyril Chemparathy 3790a7fcf0 mbuf: add script to convert code to offset macro
This patch adds a coccinelle (see http://coccinelle.lip6.fr/)
transform to use the newly added rte_pktmbuf_mtod_offset() helper.  In
addition, we add a simple script to apply all available transforms to
a codebase.

Signed-off-by: Cyril Chemparathy <cchemparathy@ezchip.com>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
2015-06-24 12:01:14 +02:00

77 lines
1.8 KiB
Plaintext

//
// Replace explicit packet offset computations with rte_pktmbuf_mtod_offset().
//
@disable paren@
typedef uint8_t;
expression M, O;
@@
(
- rte_pktmbuf_mtod(M, char *) + O
+ rte_pktmbuf_mtod_offset(M, char *, O)
|
- rte_pktmbuf_mtod(M, char *) - O
+ rte_pktmbuf_mtod_offset(M, char *, -O)
|
- rte_pktmbuf_mtod(M, unsigned char *) + O
+ rte_pktmbuf_mtod_offset(M, unsigned char *, O)
|
- rte_pktmbuf_mtod(M, unsigned char *) - O
+ rte_pktmbuf_mtod_offset(M, unsigned char *, -O)
|
- rte_pktmbuf_mtod(M, uint8_t *) + O
+ rte_pktmbuf_mtod_offset(M, uint8_t *, O)
|
- rte_pktmbuf_mtod(M, uint8_t *) - O
+ rte_pktmbuf_mtod_offset(M, uint8_t *, -O)
)
//
// Fold subsequent offset terms into pre-existing offset used in
// rte_pktmbuf_mtod_offset().
//
@disable paren@
expression M, O1, O2;
@@
(
- rte_pktmbuf_mtod_offset(M, char *, O1) + O2
+ rte_pktmbuf_mtod_offset(M, char *, O1 + O2)
|
- rte_pktmbuf_mtod_offset(M, char *, O1) - O2
+ rte_pktmbuf_mtod_offset(M, char *, O1 - O2)
|
- rte_pktmbuf_mtod_offset(M, unsigned char *, O1) + O2
+ rte_pktmbuf_mtod_offset(M, unsigned char *, O1 + O2)
|
- rte_pktmbuf_mtod_offset(M, unsigned char *, O1) - O2
+ rte_pktmbuf_mtod_offset(M, unsigned char *, O1 - O2)
|
- rte_pktmbuf_mtod_offset(M, uint8_t *, O1) + O2
+ rte_pktmbuf_mtod_offset(M, uint8_t *, O1 + O2)
|
- rte_pktmbuf_mtod_offset(M, uint8_t *, O1) - O2
+ rte_pktmbuf_mtod_offset(M, uint8_t *, O1 - O2)
)
//
// Cleanup rules. Fold in double casts, remove unnecessary paranthesis, etc.
//
@disable paren@
expression M, O;
type C, T;
@@
(
- (C)rte_pktmbuf_mtod_offset(M, T, O)
+ rte_pktmbuf_mtod_offset(M, C, O)
|
- (rte_pktmbuf_mtod_offset(M, T, O))
+ rte_pktmbuf_mtod_offset(M, T, O)
|
- (C)rte_pktmbuf_mtod(M, T)
+ rte_pktmbuf_mtod(M, C)
|
- (rte_pktmbuf_mtod(M, T))
+ rte_pktmbuf_mtod(M, T)
)