diff --git a/valuescript_compiler/src/optimization/mod.rs b/valuescript_compiler/src/optimization/mod.rs index 6b0b028d..4ee8c234 100644 --- a/valuescript_compiler/src/optimization/mod.rs +++ b/valuescript_compiler/src/optimization/mod.rs @@ -1,6 +1,7 @@ mod collapse_pointers_of_pointers; mod extract_constants; mod optimize; +mod remove_meta_lines; mod shake_tree; mod simplify; pub mod try_to_val; diff --git a/valuescript_compiler/src/optimization/optimize.rs b/valuescript_compiler/src/optimization/optimize.rs index bc728568..b440a2e2 100644 --- a/valuescript_compiler/src/optimization/optimize.rs +++ b/valuescript_compiler/src/optimization/optimize.rs @@ -3,6 +3,7 @@ use crate::name_allocator::NameAllocator; use super::collapse_pointers_of_pointers::collapse_pointers_of_pointers; use super::extract_constants::extract_constants; +use super::remove_meta_lines::remove_meta_lines; use super::shake_tree::shake_tree; use super::simplify::simplify; @@ -11,4 +12,5 @@ pub fn optimize(module: &mut Module, pointer_allocator: &mut NameAllocator) { extract_constants(module, pointer_allocator); shake_tree(module); simplify(module); + remove_meta_lines(module); } diff --git a/valuescript_compiler/src/optimization/remove_meta_lines.rs b/valuescript_compiler/src/optimization/remove_meta_lines.rs new file mode 100644 index 00000000..ce401b7c --- /dev/null +++ b/valuescript_compiler/src/optimization/remove_meta_lines.rs @@ -0,0 +1,16 @@ +use std::mem::take; + +use crate::asm::{DefinitionContent, FnLine, Module}; + +pub fn remove_meta_lines(module: &mut Module) { + for defn in &mut module.definitions { + if let DefinitionContent::Function(fn_) = &mut defn.content { + for line in take(&mut fn_.body) { + match &line { + FnLine::Instruction(_) | FnLine::Label(_) | FnLine::Empty => fn_.body.push(line), + FnLine::Comment(_) | FnLine::Release(_) => continue, + } + } + } + } +}