charon_lib/transform/
remove_nops.rs1use crate::ast::*;
3use crate::transform::TransformCtx;
4
5use super::ctx::TransformPass;
6
7pub struct Transform;
8impl TransformPass for Transform {
9 fn transform_ctx(&self, ctx: &mut TransformCtx) {
10 ctx.for_each_fun_decl(|_ctx, fun| {
11 if let Ok(body) = &mut fun.body {
12 match body {
13 Body::Unstructured(body) => {
14 for blk in &mut body.body {
15 if blk.statements.iter().any(|st| st.content.is_nop()) {
16 blk.statements.retain(|st| !st.content.is_nop())
17 }
18 }
19 }
20 Body::Structured(body) => {
21 body.body.visit_blocks_bwd(|blk: &mut llbc_ast::Block| {
22 if blk.statements.iter().any(|st| st.content.is_nop()) {
24 blk.statements.retain(|st| !st.content.is_nop())
25 }
26 });
27 }
28 }
29 }
30 });
31 }
32}