working roundtrip for simple module
This commit is contained in:
parent
4585ec48be
commit
63aa7e4cb6
|
@ -169,6 +169,11 @@ pub fn produce_func_wasm<FT: FuncTypeSink>(
|
|||
for operator in &body.operators {
|
||||
ctx.translate(operator, locations);
|
||||
}
|
||||
|
||||
// Fixup: add unreachable just before last `end`; there must be an explicit return.
|
||||
// assert!(matches!(wasm.operators.pop(), Some(wasm_encoder::Instruction::End)));
|
||||
// wasm.operators.push(wasm_encoder::Instruction::Unreachable);
|
||||
// wasm.operators.push(wasm_encoder::Instruction::End);
|
||||
|
||||
wasm
|
||||
}
|
||||
|
|
|
@ -288,6 +288,8 @@ impl<'a> SerializedBodyContext<'a> {
|
|||
self.operators.extend(rev_ops);
|
||||
self.operators
|
||||
.push(SerializedOperator::BrTable { targets, default });
|
||||
self.operators
|
||||
.push(SerializedOperator::Operator(Operator::Unreachable));
|
||||
}
|
||||
&Terminator::Return { ref values, .. } => {
|
||||
let mut rev_ops = vec![];
|
||||
|
|
|
@ -345,13 +345,17 @@ impl BlockOrder {
|
|||
target_stack.push(target);
|
||||
}
|
||||
let params = f.blocks[header].params.clone();
|
||||
let results = match fallthrough {
|
||||
Some(fallthrough) => f.blocks[fallthrough]
|
||||
.params
|
||||
.iter()
|
||||
.map(|(ty, _)| *ty)
|
||||
.collect(),
|
||||
None => vec![],
|
||||
let results = if header == 0 {
|
||||
f.rets.clone()
|
||||
} else {
|
||||
match fallthrough {
|
||||
Some(fallthrough) => f.blocks[fallthrough]
|
||||
.params
|
||||
.iter()
|
||||
.map(|(ty, _)| *ty)
|
||||
.collect(),
|
||||
None => vec![],
|
||||
}
|
||||
};
|
||||
if is_loop {
|
||||
entries.push(BlockOrderEntry::StartLoop(header, params, results));
|
||||
|
|
13
src/bin/roundtrip.rs
Normal file
13
src/bin/roundtrip.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
//! Roundtrip utility.
|
||||
|
||||
use std::io::{Read, Write};
|
||||
use waffle::Module;
|
||||
|
||||
fn main() {
|
||||
let _ = env_logger::try_init();
|
||||
let mut bytes = vec![];
|
||||
std::io::stdin().read_to_end(&mut bytes).unwrap();
|
||||
let module = Module::from_wasm_bytes(&bytes).unwrap();
|
||||
let new_bytes = module.to_wasm_bytes();
|
||||
std::io::stdout().write(&new_bytes[..]).unwrap();
|
||||
}
|
|
@ -109,6 +109,9 @@ fn parse_body<'a>(
|
|||
for ¶m in &module.signatures[my_sig].params[..] {
|
||||
ret.locals.push(param);
|
||||
}
|
||||
for &r in &module.signatures[my_sig].returns[..] {
|
||||
ret.rets.push(r);
|
||||
}
|
||||
|
||||
let mut locals = body.get_locals_reader()?;
|
||||
for _ in 0..locals.get_count() {
|
||||
|
|
Loading…
Reference in a new issue