Skip to content

Commit

Permalink
remove_meta_lines
Browse files Browse the repository at this point in the history
  • Loading branch information
voltrevo committed Jun 30, 2023
1 parent 6ee5951 commit 25ba1d9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions valuescript_compiler/src/optimization/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 2 additions & 0 deletions valuescript_compiler/src/optimization/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}
16 changes: 16 additions & 0 deletions valuescript_compiler/src/optimization/remove_meta_lines.rs
Original file line number Diff line number Diff line change
@@ -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,
}
}
}
}
}

0 comments on commit 25ba1d9

Please sign in to comment.