(
wasm_import_module: &str,
wasm_import_name: &str,
rust_name: &str,
params: &[WasmType],
results: &[WasmType],
)
| 1779 | } |
| 1780 | |
| 1781 | fn declare_import( |
| 1782 | wasm_import_module: &str, |
| 1783 | wasm_import_name: &str, |
| 1784 | rust_name: &str, |
| 1785 | params: &[WasmType], |
| 1786 | results: &[WasmType], |
| 1787 | ) -> String { |
| 1788 | let mut sig = "(".to_owned(); |
| 1789 | for param in params.iter() { |
| 1790 | sig.push_str("_: "); |
| 1791 | sig.push_str(wasm_type(*param)); |
| 1792 | sig.push_str(", "); |
| 1793 | } |
| 1794 | sig.push(')'); |
| 1795 | assert!(results.len() < 2); |
| 1796 | for result in results.iter() { |
| 1797 | sig.push_str(" -> "); |
| 1798 | sig.push_str(wasm_type(*result)); |
| 1799 | } |
| 1800 | format!( |
| 1801 | " |
| 1802 | #[cfg(target_arch = \"wasm32\")] |
| 1803 | #[link(wasm_import_module = \"{wasm_import_module}\")] |
| 1804 | unsafe extern \"C\" {{ |
| 1805 | #[link_name = \"{wasm_import_name}\"] |
| 1806 | fn {rust_name}{sig}; |
| 1807 | }} |
| 1808 | |
| 1809 | #[cfg(not(target_arch = \"wasm32\"))] |
| 1810 | unsafe extern \"C\" fn {rust_name}{sig} {{ unreachable!() }} |
| 1811 | " |
| 1812 | ) |
| 1813 | } |
| 1814 | |
| 1815 | fn int_repr(repr: Int) -> &'static str { |
| 1816 | match repr { |
no test coverage detected