suggested fixes 1
This commit is contained in:
parent
ff4d2aba3c
commit
b5a61d053f
|
@ -31,13 +31,9 @@ pub enum WasmBlock<'a> {
|
|||
header: Block,
|
||||
},
|
||||
/// A leaf node: one CFG block.
|
||||
Leaf {
|
||||
block: Block,
|
||||
},
|
||||
Leaf { block: Block },
|
||||
/// A translated unconditional branch.
|
||||
Br {
|
||||
target: WasmLabel,
|
||||
},
|
||||
Br { target: WasmLabel },
|
||||
/// A translated conditional.
|
||||
If {
|
||||
cond: Value,
|
||||
|
@ -56,13 +52,10 @@ pub enum WasmBlock<'a> {
|
|||
to: &'a [(Type, Value)],
|
||||
},
|
||||
/// A function return instruction.
|
||||
Return {
|
||||
values: &'a [Value],
|
||||
},
|
||||
ReturnCall {
|
||||
func: Func,
|
||||
values: &'a [Value],
|
||||
},
|
||||
Return { values: &'a [Value] },
|
||||
/// A function tail call instruction
|
||||
ReturnCall { func: Func, values: &'a [Value] },
|
||||
/// A function indirect tail call instruction
|
||||
ReturnCallIndirect {
|
||||
sig: Signature,
|
||||
table: Table,
|
||||
|
|
|
@ -1249,7 +1249,6 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
|
|||
type_index,
|
||||
table_index,
|
||||
} => {
|
||||
// let sig = self.module.funcs[Func::new(*function_index as usize)].sig();
|
||||
let retvals = self.pop_n(
|
||||
self.module.signatures[Signature::new(*type_index as usize)]
|
||||
.params
|
||||
|
@ -1687,7 +1686,6 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
|
|||
t
|
||||
);
|
||||
if self.reachable {
|
||||
// let values = values.to_vec();
|
||||
self.body.set_terminator(self.cur_block, t);
|
||||
self.reachable = false;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ pub struct Module<'a> {
|
|||
pub start_func: Option<Func>,
|
||||
pub debug: Debug,
|
||||
pub debug_map: DebugMap,
|
||||
pub custom_sections: IndexMap<String,Vec<u8>>
|
||||
pub custom_sections: IndexMap<String, Vec<u8>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
|
|
|
@ -5,7 +5,6 @@ pub mod dom_pass;
|
|||
pub mod empty_blocks;
|
||||
pub mod maxssa;
|
||||
pub mod remove_phis;
|
||||
pub mod reorder_funs;
|
||||
pub mod resolve_aliases;
|
||||
pub mod ssa;
|
||||
pub mod trace;
|
||||
|
|
|
@ -1,78 +0,0 @@
|
|||
use std::collections::BTreeMap;
|
||||
|
||||
use crate::{
|
||||
entity::EntityRef, ExportKind, Func, FuncDecl, FunctionBody, ImportKind, Module, Operator,
|
||||
Terminator, ValueDef,
|
||||
};
|
||||
|
||||
pub fn reorder_funcs_in_body(b: &mut FunctionBody, f: &BTreeMap<Func, Func>) {
|
||||
for v in b.values.values_mut() {
|
||||
if let ValueDef::Operator(a, _, _) = v {
|
||||
if let Operator::Call { function_index } = a {
|
||||
*function_index = *f.get(&*function_index).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
for k in b.blocks.values_mut() {
|
||||
if let Terminator::ReturnCall { func, args } = &mut k.terminator {
|
||||
*func = *f.get(&*func).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn reorder_funcs(m: &mut Module, fs: &BTreeMap<Func, Func>) {
|
||||
let mut n = m.funcs.clone();
|
||||
for (f, b) in m.funcs.entries() {
|
||||
let mut b = b.clone();
|
||||
if let Some(b) = b.body_mut() {
|
||||
reorder_funcs_in_body(b, fs);
|
||||
}
|
||||
n[*fs.get(&f).unwrap()] = b;
|
||||
}
|
||||
m.funcs = n;
|
||||
for t in m.tables.values_mut() {
|
||||
if let Some(e) = t.func_elements.as_mut() {
|
||||
for e in e.iter_mut() {
|
||||
let Some(f) = fs.get(&*e) else{
|
||||
let f = *e;
|
||||
panic!("invalid func: {f}; {}",m.funcs[f].name())
|
||||
};
|
||||
*e = *f;
|
||||
}
|
||||
}
|
||||
}
|
||||
for i in m.imports.iter_mut() {
|
||||
if let ImportKind::Func(f) = &mut i.kind {
|
||||
*f = *fs.get(&*f).unwrap();
|
||||
}
|
||||
}
|
||||
for i in m.exports.iter_mut() {
|
||||
if let ExportKind::Func(f) = &mut i.kind {
|
||||
*f = *fs.get(&*f).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn fixup_orders(m: &mut Module) {
|
||||
let mut fs = BTreeMap::new();
|
||||
let mut a = vec![];
|
||||
let mut b = vec![];
|
||||
for (f, d) in m.funcs.entries() {
|
||||
if let FuncDecl::Import(_, _) = d {
|
||||
a.push(f)
|
||||
} else {
|
||||
b.push(f)
|
||||
}
|
||||
}
|
||||
let mut i = 0;
|
||||
for v in a {
|
||||
fs.insert(v, Func::new(i));
|
||||
i += 1;
|
||||
}
|
||||
for v in b {
|
||||
fs.insert(v, Func::new(i));
|
||||
i += 1;
|
||||
}
|
||||
assert_eq!(fs.len(),m.funcs.len());
|
||||
fs.insert(Func::invalid(),Func::invalid());
|
||||
reorder_funcs(m, &fs);
|
||||
return;
|
||||
}
|
Loading…
Reference in a new issue