Skip to content

Commit 8932c21

Browse files
authored
json-from-wast: Fix generation of DWARF (#2296)
This fixes an accidental bug from #2247 where DWARF was not actually generated in the individual wasm modules for an input `*.wast` when requested. This was due to the fact that it was inserted in the wrong location after the file was originally created, only affecting `module quote ...` for example.
1 parent 4c16e95 commit 8932c21

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

crates/json-from-wast/src/build.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,20 @@ impl<'a> JsonBuilder<'a, '_> {
233233
malformed: bool,
234234
) -> Result<(Option<&'a str>, crate::WasmFile<'static>)> {
235235
let name = module.name().map(|i| i.name());
236-
let (contents, module_type, ext) = match module.to_test()? {
237-
QuoteWatTest::Text(s) => (s, WasmFileType::Text, "wat"),
238-
QuoteWatTest::Binary(s) => (s, WasmFileType::Binary, "wasm"),
236+
let (contents, module_type, ext) = match &mut module {
237+
QuoteWat::Wat(wat) => {
238+
let mut opts = EncodeOptions::new();
239+
if self.opts.dwarf {
240+
let filename: &str = &self.ret.source_filename;
241+
opts.dwarf(filename.as_ref(), self.contents, GenerateDwarf::Lines);
242+
}
243+
let contents = opts.encode_wat(wat)?;
244+
(contents, WasmFileType::Binary, "wasm")
245+
}
246+
other => match other.to_test()? {
247+
QuoteWatTest::Text(s) => (s, WasmFileType::Text, "wat"),
248+
QuoteWatTest::Binary(s) => (s, WasmFileType::Binary, "wasm"),
249+
},
239250
};
240251
let filename: &str = &self.ret.source_filename;
241252
let stem = Path::new(filename).file_stem().unwrap().to_str().unwrap();
@@ -250,18 +261,7 @@ impl<'a> JsonBuilder<'a, '_> {
250261
binary_filename: None,
251262
};
252263
if module_type == WasmFileType::Text && !malformed {
253-
let bytes = match &mut module {
254-
QuoteWat::Wat(wat) => {
255-
let mut opts = EncodeOptions::new();
256-
if self.opts.dwarf {
257-
let filename: &str = &self.ret.source_filename;
258-
opts.dwarf(filename.as_ref(), self.contents, GenerateDwarf::Lines);
259-
}
260-
opts.encode_wat(wat)
261-
}
262-
_ => module.encode(),
263-
};
264-
if let Ok(bytes) = bytes {
264+
if let Ok(bytes) = module.encode() {
265265
self.ret.wasms.push((binary_filename.clone(), bytes));
266266
ret.binary_filename = Some(binary_filename.into());
267267
}

0 commit comments

Comments
 (0)