Remove unneeded Luau branch gadgets
Fixiee
This commit is contained in:
parent
49bc994353
commit
cdefb2f06a
@ -1,29 +0,0 @@
|
|||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use wasm_ast::{
|
|
||||||
node::{BrTable, FuncData},
|
|
||||||
visit::{Driver, Visitor},
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Visit {
|
|
||||||
id_map: HashMap<usize, usize>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Visitor for Visit {
|
|
||||||
fn visit_br_table(&mut self, table: &BrTable) {
|
|
||||||
let id = table as *const _ as usize;
|
|
||||||
let len = self.id_map.len() + 1;
|
|
||||||
|
|
||||||
self.id_map.insert(id, len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn visit(ast: &FuncData) -> HashMap<usize, usize> {
|
|
||||||
let mut visit = Visit {
|
|
||||||
id_map: HashMap::new(),
|
|
||||||
};
|
|
||||||
|
|
||||||
ast.accept(&mut visit);
|
|
||||||
|
|
||||||
visit.id_map
|
|
||||||
}
|
|
40
codegen/luau/src/analyzer/br_target.rs
Normal file
40
codegen/luau/src/analyzer/br_target.rs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use wasm_ast::{
|
||||||
|
node::{Br, BrIf, BrTable, FuncData},
|
||||||
|
visit::{Driver, Visitor},
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Visit {
|
||||||
|
br_map: HashMap<usize, usize>,
|
||||||
|
has_branch: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Visitor for Visit {
|
||||||
|
fn visit_br(&mut self, _: &Br) {
|
||||||
|
self.has_branch = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_br_if(&mut self, _: &BrIf) {
|
||||||
|
self.has_branch = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visit_br_table(&mut self, table: &BrTable) {
|
||||||
|
let id = table as *const _ as usize;
|
||||||
|
let len = self.br_map.len() + 1;
|
||||||
|
|
||||||
|
self.has_branch = true;
|
||||||
|
self.br_map.insert(id, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn visit(ast: &FuncData) -> (HashMap<usize, usize>, bool) {
|
||||||
|
let mut visit = Visit {
|
||||||
|
br_map: HashMap::new(),
|
||||||
|
has_branch: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
ast.accept(&mut visit);
|
||||||
|
|
||||||
|
(visit.br_map, visit.has_branch)
|
||||||
|
}
|
@ -1,3 +1,3 @@
|
|||||||
pub mod as_symbol;
|
pub mod as_symbol;
|
||||||
pub mod br_table;
|
pub mod br_target;
|
||||||
pub mod localize;
|
pub mod localize;
|
||||||
|
@ -9,7 +9,7 @@ use wasm_ast::node::{
|
|||||||
};
|
};
|
||||||
use wasmparser::ValType;
|
use wasmparser::ValType;
|
||||||
|
|
||||||
use crate::analyzer::br_table;
|
use crate::analyzer::br_target;
|
||||||
|
|
||||||
use super::manager::{
|
use super::manager::{
|
||||||
write_ascending, write_condition, write_separated, write_variable, Driver, Manager,
|
write_ascending, write_condition, write_separated, write_variable, Driver, Manager,
|
||||||
@ -130,7 +130,7 @@ fn write_br_gadget(
|
|||||||
label: usize,
|
label: usize,
|
||||||
w: &mut dyn Write,
|
w: &mut dyn Write,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if label_list.len() == 1 {
|
if label_list.len() == 1 || label_list.iter().all(Option::is_none) {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,17 +340,20 @@ fn write_variable_list(ast: &FuncData, w: &mut dyn Write) -> Result<()> {
|
|||||||
|
|
||||||
impl Driver for FuncData {
|
impl Driver for FuncData {
|
||||||
fn write(&self, mng: &mut Manager, w: &mut dyn Write) -> Result<()> {
|
fn write(&self, mng: &mut Manager, w: &mut dyn Write) -> Result<()> {
|
||||||
let br_map = br_table::visit(self);
|
let br_data = br_target::visit(self);
|
||||||
|
|
||||||
write_parameter_list(self, w)?;
|
write_parameter_list(self, w)?;
|
||||||
write_variable_list(self, w)?;
|
write_variable_list(self, w)?;
|
||||||
write!(w, "local desired ")?;
|
|
||||||
|
|
||||||
if !br_map.is_empty() {
|
if br_data.1 {
|
||||||
|
write!(w, "local desired ")?;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !br_data.0.is_empty() {
|
||||||
write!(w, "local br_map = {{}} ")?;
|
write!(w, "local br_map = {{}} ")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
mng.set_table_map(br_map);
|
mng.set_table_map(br_data.0);
|
||||||
mng.set_num_param(self.num_param());
|
mng.set_num_param(self.num_param());
|
||||||
self.code().write(mng, w)?;
|
self.code().write(mng, w)?;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user