[WASM] Compile C Code into WebAssembly
code INTO compile WebAssembly Wasm
2023-09-14 08:59:18 时间
We use the C language instead of pure WAST to create a square root function using WASM Fiddle (https://wasdk.github.io/WasmFiddle//). We show how to run the WebAssembly in WASM Fiddle, then download and run it in the browser using a helper function to load the WebAssembly.
WASM Fiddle: https://wasdk.github.io/WasmFiddle/?t96rp
Demo Repo: https://github.com/guybedford/wasm-intro
// C #include <math.h> float getSqrt (float num) { return sqrt(num); }
Compile to WASM:
(module (type $FUNCSIG$ff (func (param f32) (result f32))) (table 0 anyfunc) (memory $0 1) (export "memory" (memory $0)) (export "getSqrt" (func $getSqrt)) (func $getSqrt (param $0 f32) (result f32) (f32.sqrt (get_local $0) ) ) )
index.html:
<!doctype> <html> <header> <title> WASM </title> <script> function fetchAndInstantiateWasm(url, imports) { return fetch(url) .then((res) => { if (res.ok) { return res.arrayBuffer(); } throw new Error('Unable to fetch WASM') }) .then((bytes) => { return WebAssembly.compile(bytes); }) .then(module => { return WebAssembly.instantiate(module, imports || {}); }) .then(instance => instance.exports); } fetchAndInstantiateWasm('./program.wasm') .then(m => { window.getSqrt = m.getSqrt; }); </script> </header> </html>
相关文章
- 一文吃透 VS Code+Git 操作(vs code中git的相关配置与使用)
- Visual Studio Code Macv1.71.0中文版
- 某车联网App 通讯协议加密分析(四) Trace Code
- 想在 Visual Studio Code 里进行 ABAP 开发,需要安装的扩展列表
- vs code如何运行_vs如何代码提示
- npm ERR! code E404 npm ERR! 404 Not Found – GET https://registry.npmjs.com/@mlamp%2fuser-info-dropdo
- Good-code-books 前端经典常用好书分享
- 【Laravel】在企业级项目中使用Laravel框架中的工厂状态下的页面方法 Code Verifier以及错误处理
- WordPress 所有的 Dashicons 和其 CSS Class 以及 CODE
- ORA-00600: internal error code, arguments: [string], [string], [string], [string], [string], [string], [string], [string], [string], [string], [string], [string] ORACLE 报错 故障修复 远程处理
- ORA-00606: Internal error code ORACLE 报错 故障修复 远程处理
- ORA-30176: invalid format code used in the format string ORACLE 报错 故障修复 远程处理
- ORA-46095: Invalid error code supplied ORACLE 报错 故障修复 远程处理
- ORA-04086: trigger description too long, move comments into triggering code ORACLE 报错 故障修复 远程处理
- Android漏洞扫描工具Code Arbiter
- 深入掌握MySQL中的INTO用法,快速提升数据插入操作效率(mysql中into用法)
- 学习MySQL了解INTO语句的用法(mysql 中into)
- 布比Code Review百万赏金计划&BUMO全球大使计划同步启动,本月17日在车库咖啡召开宣讲会