aboutsummaryrefslogtreecommitdiff
path: root/src/unreachable.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-04-02 15:15:04 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-04-02 15:15:04 +0300
commita7cb592efa9ec72c4c5e9d3c1e7469203a4b47e2 (patch)
tree5c43cfbde7cad7f1f46366d9b9fedd9c81953f91 /src/unreachable.c
parent59148d666a78d671198d56caabe7fe4d7fb3fee1 (diff)
downloadqbt-a7cb592efa9ec72c4c5e9d3c1e7469203a4b47e2.tar.gz
qbt-a7cb592efa9ec72c4c5e9d3c1e7469203a4b47e2.zip
add simple unreachability
Diffstat (limited to 'src/unreachable.c')
-rw-r--r--src/unreachable.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/unreachable.c b/src/unreachable.c
new file mode 100644
index 0000000..90a65bd
--- /dev/null
+++ b/src/unreachable.c
@@ -0,0 +1,38 @@
+#include <qbt/unreachable.h>
+
+void build_reachable_vec(struct vec *reachable, struct blk *cur)
+{
+ if (cur->reachable)
+ return;
+
+ cur->reachable = true;
+ vec_append(reachable, &cur);
+
+ if (cur->btype == RET)
+ return;
+
+ if (cur->btype == J)
+ cur->s1 = cur->s2;
+
+ if (cur->s1)
+ build_reachable_vec(reachable, cur->s1);
+
+ if (cur->s2)
+ build_reachable_vec(reachable, cur->s2);
+}
+
+void unreachable(struct fn *f)
+{
+ struct vec reachable = vec_create(sizeof(struct blk *));
+ struct blk *b = blk_at(f->blks, 0);
+ build_reachable_vec(&reachable, b);
+ foreach_blk(bi, f->blks) {
+ struct blk *b = blk_at(f->blks, bi);
+ if (!b->reachable)
+ destroy_block(b);
+
+ }
+
+ vec_destroy(&f->blks);
+ f->blks = reachable;
+}