Fix Luau output emitting dead control branches
This commit is contained in:
parent
7a49d61e0a
commit
dfb86b30f9
@ -34,6 +34,7 @@ macro_rules! line {
|
||||
#[derive(Default)]
|
||||
pub struct Manager {
|
||||
table_map: HashMap<usize, usize>,
|
||||
has_branch: bool,
|
||||
label_list: Vec<Option<LabelType>>,
|
||||
indentation: usize,
|
||||
}
|
||||
@ -45,8 +46,13 @@ impl Manager {
|
||||
self.table_map[&id]
|
||||
}
|
||||
|
||||
pub fn set_table_map(&mut self, map: HashMap<usize, usize>) {
|
||||
self.table_map = map;
|
||||
pub fn set_branch_information(&mut self, table_map: HashMap<usize, usize>, has_branch: bool) {
|
||||
self.table_map = table_map;
|
||||
self.has_branch = has_branch;
|
||||
}
|
||||
|
||||
pub const fn has_branch(&self) -> bool {
|
||||
self.has_branch
|
||||
}
|
||||
|
||||
pub fn label_list(&self) -> &[Option<LabelType>] {
|
||||
|
@ -140,7 +140,7 @@ impl Driver for Terminator {
|
||||
}
|
||||
|
||||
fn write_br_parent(mng: &mut Manager, w: &mut dyn Write) -> Result<()> {
|
||||
if mng.label_list().iter().all(Option::is_none) {
|
||||
if !mng.has_branch() || mng.label_list().iter().all(Option::is_none) {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
@ -389,22 +389,22 @@ fn write_variable_list(ast: &FuncData, mng: &mut Manager, w: &mut dyn Write) ->
|
||||
|
||||
impl Driver for FuncData {
|
||||
fn write(&self, mng: &mut Manager, w: &mut dyn Write) -> Result<()> {
|
||||
let br_data = br_target::visit(self);
|
||||
let (table_map, has_branch) = br_target::visit(self);
|
||||
|
||||
mng.indent();
|
||||
|
||||
write_parameter_list(self, w)?;
|
||||
write_variable_list(self, mng, w)?;
|
||||
|
||||
if br_data.1 {
|
||||
if has_branch {
|
||||
line!(mng, w, "local desired")?;
|
||||
}
|
||||
|
||||
if !br_data.0.is_empty() {
|
||||
if !table_map.is_empty() {
|
||||
line!(mng, w, "local br_map = {{}}")?;
|
||||
}
|
||||
|
||||
mng.set_table_map(br_data.0);
|
||||
mng.set_branch_information(table_map, has_branch);
|
||||
self.code().write(mng, w)?;
|
||||
|
||||
if self.num_result() != 0 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user