MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / declarations

Method declarations

crates/test-util/src/component_fuzz.rs:1776–1831  ·  view source on GitHub ↗

Generate a `Declarations` for this `TestCase` which may be used to build a component to execute the case.

(&self)

Source from the content-addressed store, hash-verified

1774
1775 /// Generate a `Declarations` for this `TestCase` which may be used to build a component to execute the case.
1776 pub fn declarations(&self) -> Declarations {
1777 let mut builder = TypesBuilder::default();
1778
1779 let mut params = String::new();
1780 for (i, ty) in self.params.iter().enumerate() {
1781 params.push_str(&format!(" (param \"p{i}\" "));
1782 builder.write_ref(ty, &mut params);
1783 params.push_str(")");
1784 }
1785
1786 let mut results = String::new();
1787 if let Some(ty) = self.result {
1788 results.push_str(&format!(" (result "));
1789 builder.write_ref(ty, &mut results);
1790 results.push_str(")");
1791 }
1792
1793 let caller_module = make_import_and_export(
1794 &self.params,
1795 self.result,
1796 self.options.caller_lift_abi,
1797 self.options.caller_lower_abi,
1798 );
1799 let callee_module = make_import_and_export(
1800 &self.params,
1801 self.result,
1802 self.options.callee_lift_abi,
1803 self.options.callee_lower_abi,
1804 );
1805
1806 let mut type_decls = Vec::new();
1807 let mut type_instantiation_args = String::new();
1808 while let Some((idx, ty)) = builder.worklist.pop() {
1809 type_decls.push(builder.write_decl(idx, ty));
1810 uwriteln!(type_instantiation_args, "(with \"t{idx}\" (type $t{idx}))");
1811 }
1812
1813 // Note that types are printed here in reverse order since they were
1814 // pushed onto `type_decls` as they were referenced meaning the last one
1815 // is the "base" one.
1816 let mut types = String::new();
1817 for decl in type_decls.into_iter().rev() {
1818 types.push_str(&decl);
1819 types.push_str("\n");
1820 }
1821
1822 Declarations {
1823 types: types.into(),
1824 type_instantiation_args: type_instantiation_args.into(),
1825 params: params.into(),
1826 results: results.into(),
1827 caller_module: caller_module.into(),
1828 callee_module: callee_module.into(),
1829 options: self.options,
1830 }
1831 }
1832}
1833

Callers 5

arbtestFunction · 0.45
targetFunction · 0.45
static_api_smoke_testFunction · 0.45
write_static_api_testsFunction · 0.45

Calls 9

make_import_and_exportFunction · 0.85
write_refMethod · 0.80
write_declMethod · 0.80
newFunction · 0.50
iterMethod · 0.45
push_strMethod · 0.45
popMethod · 0.45
pushMethod · 0.45
into_iterMethod · 0.45

Tested by 2

arbtestFunction · 0.36
static_api_smoke_testFunction · 0.36