From 939b6ea9339ab801f166e8ed4160541da20a564f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Cabrera?= Date: Mon, 6 Feb 2023 17:02:38 -0500 Subject: [PATCH] winch: Fix retrieving function signature for compilation (#5725) This commit fixes an incorrect usage of `func_type_at` to retrieve a defined function signature and instead uses `function_at` to retrieve the signature. Additionally it enhances `winch-tools` `compile` and `test` commands to handle modules with multiple functions correctly. --- winch/filetests/src/lib.rs | 6 +++--- winch/src/compile.rs | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/winch/filetests/src/lib.rs b/winch/filetests/src/lib.rs index 225445a2a6..4400bf0652 100644 --- a/winch/filetests/src/lib.rs +++ b/winch/filetests/src/lib.rs @@ -112,9 +112,9 @@ mod test { let binding = body_inputs .into_iter() - .flat_map(|func| compile(&*isa, module, types, func)) + .map(|func| compile(&*isa, module, types, func).join("\n")) .collect::>() - .join("\n"); + .join("\n\n"); let actual = binding.as_str(); if std::env::var("WINCH_TEST_BLESS").unwrap_or_default() == "1" { @@ -151,7 +151,7 @@ mod test { ) -> Vec { let index = module.func_index(f.0); let sig = types - .func_type_at(index.as_u32()) + .function_at(index.as_u32()) .expect(&format!("function type at index {:?}", index.as_u32())); let FunctionBodyData { body, validator } = f.1; let validator = validator.into_validator(Default::default()); diff --git a/winch/src/compile.rs b/winch/src/compile.rs index 0f1c49239d..6573801044 100644 --- a/winch/src/compile.rs +++ b/winch/src/compile.rs @@ -56,7 +56,7 @@ fn compile( ) -> Result<()> { let index = module.func_index(f.0); let sig = types - .func_type_at(index.as_u32()) + .function_at(index.as_u32()) .expect(&format!("function type at index {:?}", index.as_u32())); let FunctionBodyData { body, validator } = f.1; let validator = validator.into_validator(Default::default()); @@ -64,6 +64,7 @@ fn compile( .compile_function(&sig, &body, validator) .expect("Couldn't compile function"); + println!("Disassembly for function: {}", index.as_u32()); disasm(buffer.data(), isa)? .iter() .for_each(|s| println!("{}", s));