Some fixes to wasm-to-IR step.
This commit is contained in:
parent
45a66fa3b8
commit
d8a4340743
|
@ -12,6 +12,7 @@ cargo-fuzz = true
|
||||||
[dependencies]
|
[dependencies]
|
||||||
libfuzzer-sys = "0.4"
|
libfuzzer-sys = "0.4"
|
||||||
wasm-smith = "0.8"
|
wasm-smith = "0.8"
|
||||||
|
env_logger = "0.9"
|
||||||
|
|
||||||
[dependencies.waffle]
|
[dependencies.waffle]
|
||||||
path = ".."
|
path = ".."
|
||||||
|
|
|
@ -5,5 +5,6 @@ use waffle::frontend::wasm_to_ir;
|
||||||
use wasm_smith::Module;
|
use wasm_smith::Module;
|
||||||
|
|
||||||
fuzz_target!(|module: Module| {
|
fuzz_target!(|module: Module| {
|
||||||
|
let _ = env_logger::try_init();
|
||||||
let _parsed_module = wasm_to_ir(&module.to_bytes()[..]).unwrap();
|
let _parsed_module = wasm_to_ir(&module.to_bytes()[..]).unwrap();
|
||||||
});
|
});
|
||||||
|
|
|
@ -108,6 +108,12 @@ fn parse_body<'a, 'b>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trace!(
|
||||||
|
"Parsing function body: locals = {:?} sig = {:?}",
|
||||||
|
ret.locals,
|
||||||
|
module.signatures[my_sig]
|
||||||
|
);
|
||||||
|
|
||||||
let mut builder = FunctionBodyBuilder::new(module, my_sig, &mut ret);
|
let mut builder = FunctionBodyBuilder::new(module, my_sig, &mut ret);
|
||||||
let ops = body.get_operators_reader()?;
|
let ops = body.get_operators_reader()?;
|
||||||
for op in ops.into_iter() {
|
for op in ops.into_iter() {
|
||||||
|
@ -115,6 +121,12 @@ fn parse_body<'a, 'b>(
|
||||||
builder.handle_op(op)?;
|
builder.handle_op(op)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if builder.cur_block.is_some() {
|
||||||
|
builder.handle_op(Operator::Return)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
trace!("Final function body:{:?}", ret);
|
||||||
|
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,14 +202,26 @@ impl Frame {
|
||||||
impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
|
impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
|
||||||
fn new(module: &'b Module<'a>, my_sig: SignatureId, body: &'b mut FunctionBody<'a>) -> Self {
|
fn new(module: &'b Module<'a>, my_sig: SignatureId, body: &'b mut FunctionBody<'a>) -> Self {
|
||||||
body.blocks.push(Block::default());
|
body.blocks.push(Block::default());
|
||||||
Self {
|
let mut ret = Self {
|
||||||
module,
|
module,
|
||||||
my_sig,
|
my_sig,
|
||||||
body,
|
body,
|
||||||
ctrl_stack: vec![],
|
ctrl_stack: vec![],
|
||||||
op_stack: vec![],
|
op_stack: vec![],
|
||||||
cur_block: Some(0),
|
cur_block: Some(0),
|
||||||
}
|
};
|
||||||
|
|
||||||
|
// Push initial implicit Block.
|
||||||
|
let params = module.signatures[my_sig].params.to_vec();
|
||||||
|
let results = module.signatures[my_sig].params.to_vec();
|
||||||
|
let out = ret.create_block();
|
||||||
|
ret.ctrl_stack.push(Frame::Block {
|
||||||
|
start_depth: 0,
|
||||||
|
out,
|
||||||
|
params,
|
||||||
|
results,
|
||||||
|
});
|
||||||
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_block_params(&mut self, block: BlockId, tys: &[Type]) {
|
fn add_block_params(&mut self, block: BlockId, tys: &[Type]) {
|
||||||
|
@ -217,6 +241,7 @@ impl<'a, 'b> FunctionBodyBuilder<'a, 'b> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_op(&mut self, op: Operator<'a>) -> Result<()> {
|
fn handle_op(&mut self, op: Operator<'a>) -> Result<()> {
|
||||||
|
trace!("handle_op: {:?}", op);
|
||||||
match &op {
|
match &op {
|
||||||
Operator::Unreachable
|
Operator::Unreachable
|
||||||
| Operator::LocalGet { .. }
|
| Operator::LocalGet { .. }
|
||||||
|
|
Loading…
Reference in a new issue