diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-12-01 21:48:01 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-12-01 21:48:01 +0100 |
commit | aa84286cc240b418601d8b5b49cc332a9d5e0c37 (patch) | |
tree | b0ba552301c5c15a3efbac339e168a2dba391b2d /src/mds-kbdc | |
parent | mds-kbdc: m (diff) | |
download | mds-aa84286cc240b418601d8b5b49cc332a9d5e0c37.tar.gz mds-aa84286cc240b418601d8b5b49cc332a9d5e0c37.tar.bz2 mds-aa84286cc240b418601d8b5b49cc332a9d5e0c37.tar.xz |
mds-kbdc: dead code-elimination: walk tree
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src/mds-kbdc')
-rw-r--r-- | src/mds-kbdc/eliminate-dead-code.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/mds-kbdc/eliminate-dead-code.c b/src/mds-kbdc/eliminate-dead-code.c index 586faa7..5f16bc3 100644 --- a/src/mds-kbdc/eliminate-dead-code.c +++ b/src/mds-kbdc/eliminate-dead-code.c @@ -104,9 +104,9 @@ static size_t includes_ptr = 0; /** - * Validate that a part of the structure of the compilation unit + * Eliminate dead code in a subtree * - * @param tree The tree to validate + * @param tree The tree to reduce * @return Zero on success, -1 on error */ static int eliminate_subtree(mds_kbdc_tree_t* restrict tree); @@ -165,6 +165,31 @@ static int eliminate_include(mds_kbdc_tree_include_t* restrict tree) /** + * Eliminate dead code in a for-loop + * + * @param tree The tree to reduce + * @return Zero on success, -1 on error + */ +static int eliminate_for(mds_kbdc_tree_for_t* restrict tree) +{ + return eliminate_subtree(tree->inner); +} + + +/** + * Eliminate dead code in an if-statement + * + * @param tree The tree to reduce + * @return Zero on success, -1 on error + */ +static int eliminate_if(mds_kbdc_tree_if_t* restrict tree) +{ + return -(eliminate_subtree(tree->inner) || + eliminate_subtree(tree->otherwise)); +} + + +/** * Eliminate dead code in a subtree * * @param tree The tree to reduce @@ -181,7 +206,16 @@ static int eliminate_subtree(mds_kbdc_tree_t* restrict tree) switch (tree->type) { + case C(INFORMATION): + case C(FUNCTION): + case C(MACRO): + case C(ASSUMPTION): + if ((r = eliminate_subtree(tree->information.inner))) + return r; + break; case C(INCLUDE): e(include); break; + case C(FOR): E(for); break; + case C(IF): E(if); break; default: break; } |