From aa84286cc240b418601d8b5b49cc332a9d5e0c37 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 1 Dec 2014 21:48:01 +0100 Subject: mds-kbdc: dead code-elimination: walk tree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/mds-kbdc/eliminate-dead-code.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'src/mds-kbdc') 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); @@ -164,6 +164,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 * @@ -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; } -- cgit v1.2.3-70-g09d2