Preserve global wasm module offset in SourceLoc.

This commit is contained in:
Yury Delendik
2019-01-22 16:48:31 -06:00
committed by Benjamin Bouvier
parent 2a519092a0
commit 27b0933a4a
4 changed files with 25 additions and 13 deletions

View File

@@ -54,10 +54,15 @@ impl FuncTranslator {
pub fn translate<FE: FuncEnvironment + ?Sized>(
&mut self,
code: &[u8],
code_offset: usize,
func: &mut ir::Function,
environ: &mut FE,
) -> WasmResult<()> {
self.translate_from_reader(BinaryReader::new(code), func, environ)
self.translate_from_reader(
BinaryReader::new_with_offset(code, code_offset),
func,
environ,
)
}
/// Translate a binary WebAssembly function from a `BinaryReader`.
@@ -222,11 +227,9 @@ fn parse_function_body<FE: FuncEnvironment + ?Sized>(
/// Get the current source location from a reader.
fn cur_srcloc(reader: &BinaryReader) -> ir::SourceLoc {
// We record source locations as byte code offsets relative to the beginning of the function.
// This will wrap around of a single function's byte code is larger than 4 GB, but a) the
// WebAssembly format doesn't allow for that, and b) that would hit other Cranelift
// implementation limits anyway.
ir::SourceLoc::new(reader.current_position() as u32)
// We record source locations as byte code offsets relative to the beginning of the file.
// This will wrap around if byte code is larger than 4 GB.
ir::SourceLoc::new(reader.original_position() as u32)
}
#[cfg(test)]
@@ -270,7 +273,7 @@ mod tests {
ctx.func.signature.returns.push(ir::AbiParam::new(I32));
trans
.translate(&BODY, &mut ctx.func, &mut runtime.func_env())
.translate(&BODY, 0, &mut ctx.func, &mut runtime.func_env())
.unwrap();
debug!("{}", ctx.func.display(None));
ctx.verify(&flags).unwrap();
@@ -308,7 +311,7 @@ mod tests {
ctx.func.signature.returns.push(ir::AbiParam::new(I32));
trans
.translate(&BODY, &mut ctx.func, &mut runtime.func_env())
.translate(&BODY, 0, &mut ctx.func, &mut runtime.func_env())
.unwrap();
debug!("{}", ctx.func.display(None));
ctx.verify(&flags).unwrap();
@@ -354,7 +357,7 @@ mod tests {
ctx.func.signature.returns.push(ir::AbiParam::new(I32));
trans
.translate(&BODY, &mut ctx.func, &mut runtime.func_env())
.translate(&BODY, 0, &mut ctx.func, &mut runtime.func_env())
.unwrap();
debug!("{}", ctx.func.display(None));
ctx.verify(&flags).unwrap();