Generates CLIF for all the wasm functions in this test.
(&mut self)
| 191 | |
| 192 | /// Generates CLIF for all the wasm functions in this test. |
| 193 | fn compile(&mut self) -> Result<CompileOutput> { |
| 194 | // Use wasmtime::Config with its `emit_clif` option to get Wasmtime's |
| 195 | // code generator to jettison CLIF out the back. |
| 196 | let tempdir = TempDir::new().context("failed to make a tempdir")?; |
| 197 | let mut config = self.opts.config(None)?; |
| 198 | config.target(&self.config.target)?; |
| 199 | match self.config.test { |
| 200 | TestKind::Clif => { |
| 201 | config.emit_clif(tempdir.path()); |
| 202 | config.cranelift_opt_level(OptLevel::None); |
| 203 | } |
| 204 | TestKind::Optimize => { |
| 205 | config.emit_clif(tempdir.path()); |
| 206 | } |
| 207 | TestKind::Compile => {} |
| 208 | TestKind::Winch => { |
| 209 | config.strategy(Strategy::Winch); |
| 210 | } |
| 211 | } |
| 212 | let engine = Engine::new(&config).context("failed to create engine")?; |
| 213 | |
| 214 | let mut builder = CodeBuilder::new(&engine); |
| 215 | builder.wasm_binary_or_text_file(&self.path)?; |
| 216 | if let Some(name) = self.config.unsafe_intrinsics.as_deref() { |
| 217 | unsafe { |
| 218 | builder.expose_unsafe_intrinsics(name); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | let elf = match builder.hint() { |
| 223 | Some(CodeHint::Component) => builder |
| 224 | .compile_component_serialized() |
| 225 | .context("failed to compile component")?, |
| 226 | Some(CodeHint::Module) => builder |
| 227 | .compile_module_serialized() |
| 228 | .context("failed to compile module")?, |
| 229 | None => bail!( |
| 230 | "contents of `{}` do not look like a Wasm component or module", |
| 231 | self.path.display() |
| 232 | ), |
| 233 | }; |
| 234 | |
| 235 | match self.config.test { |
| 236 | TestKind::Clif | TestKind::Optimize => { |
| 237 | // Read all `*.clif` files from the clif directory that the |
| 238 | // compilation process just emitted. |
| 239 | let mut clifs = Vec::new(); |
| 240 | |
| 241 | // Sort entries for determinism; multiple wasm modules can |
| 242 | // generate clif functions with the same names, so sorting the |
| 243 | // resulting clif functions alone isn't good enough. |
| 244 | let mut entries = tempdir |
| 245 | .path() |
| 246 | .read_dir() |
| 247 | .context("failed to read tempdir")? |
| 248 | .map(|e| Ok(e.context("failed to iterate over tempdir")?.path())) |
| 249 | .collect::<Result<Vec<_>>>()?; |
| 250 | entries.sort(); |
no test coverage detected