├── out ├── fib-wasi.wasm ├── hello-emcc.wasm ├── hello-wasi.wasm ├── fib-emcc.wasm ├── fib-emcc.wat ├── fib-wasi.wat ├── hello-emcc.js └── hello-emcc.wat ├── hello.c ├── fib.c ├── .gitignore ├── test-hello.js ├── test-fib.js ├── package.json ├── loader.js └── README.md /out/fib-wasi.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hanks10100/cpp2wasm/HEAD/out/fib-wasi.wasm -------------------------------------------------------------------------------- /out/hello-emcc.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hanks10100/cpp2wasm/HEAD/out/hello-emcc.wasm -------------------------------------------------------------------------------- /out/hello-wasi.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hanks10100/cpp2wasm/HEAD/out/hello-wasi.wasm -------------------------------------------------------------------------------- /out/fib-emcc.wasm: -------------------------------------------------------------------------------- 1 | asm`_fib 2 | )' AH@A AHA A~j Ajj -------------------------------------------------------------------------------- /hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | printf("Hello World!\n"); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /fib.c: -------------------------------------------------------------------------------- 1 | int fib (int n) { 2 | if (n <= 0) return 0; 3 | if (n <= 2) return 1; 4 | return fib(n - 2) + fib(n - 1); 5 | } 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea 3 | .project 4 | .pub 5 | .vscode 6 | .npm 7 | .eslintcache 8 | .yarn-integrity 9 | Thumbs.db 10 | node_modules 11 | package-lock.json 12 | -------------------------------------------------------------------------------- /test-hello.js: -------------------------------------------------------------------------------- 1 | const { loadWebAssembly } = require('./loader') 2 | 3 | // 自执行 4 | require('./out/hello-emcc.js') 5 | 6 | loadWebAssembly('./out/hello-wasi.wasm').then(apis => { 7 | apis._start() 8 | }) 9 | -------------------------------------------------------------------------------- /test-fib.js: -------------------------------------------------------------------------------- 1 | const { loadWebAssembly } = require('./loader') 2 | 3 | // 读取 Node.js 传递的命令参数 (node fib.js N) 4 | const args = process.argv.slice(2) 5 | const N = args.length ? parseInt(args[0], 10) : 3 6 | 7 | loadWebAssembly('./out/fib-emcc.wasm').then(apis => { 8 | console.log(`[emcc] fib(${N}) = ${apis._fib(N)}`) 9 | }) 10 | 11 | loadWebAssembly('./out/fib-wasi.wasm').then(apis => { 12 | console.log(`[wasi] fib(${N}) = ${apis.fib(N)}`) 13 | }) 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cpp2wasm", 3 | "version": "1.0.0", 4 | "description": "compile simple cpp into wasm", 5 | "main": "hello-emcc.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [ 10 | "cpp", 11 | "wasm", 12 | "wasi", 13 | "emscripten" 14 | ], 15 | "author": "Hanks ", 16 | "license": "MIT", 17 | "dependencies": { 18 | "wasi": "0.0.6" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /out/fib-emcc.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type (;0;) (func (param i32) (result i32))) 3 | (func (;0;) (type 0) (param i32) (result i32) 4 | local.get 0 5 | i32.const 1 6 | i32.lt_s 7 | if ;; label = @1 8 | i32.const 0 9 | return 10 | end 11 | local.get 0 12 | i32.const 3 13 | i32.lt_s 14 | if (result i32) ;; label = @1 15 | i32.const 1 16 | else 17 | local.get 0 18 | i32.const -2 19 | i32.add 20 | call 0 21 | local.get 0 22 | i32.const -1 23 | i32.add 24 | call 0 25 | i32.add 26 | end) 27 | (export "_fib" (func 0))) 28 | -------------------------------------------------------------------------------- /out/fib-wasi.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type (;0;) (func (param i32) (result i32))) 3 | (func $fib (type 0) (param i32) (result i32) 4 | (local i32) 5 | i32.const 1 6 | local.set 1 7 | block ;; label = @1 8 | block ;; label = @2 9 | local.get 0 10 | i32.const 1 11 | i32.ge_s 12 | br_if 0 (;@2;) 13 | i32.const 0 14 | local.set 1 15 | br 1 (;@1;) 16 | end 17 | local.get 0 18 | i32.const 3 19 | i32.lt_s 20 | br_if 0 (;@1;) 21 | local.get 0 22 | i32.const -2 23 | i32.add 24 | call $fib 25 | local.get 0 26 | i32.const -1 27 | i32.add 28 | call $fib 29 | i32.add 30 | return 31 | end 32 | local.get 1) 33 | (table (;0;) 1 1 funcref) 34 | (memory (;0;) 2) 35 | (global (;0;) (mut i32) (i32.const 66560)) 36 | (export "memory" (memory 0)) 37 | (export "fib" (func $fib))) 38 | -------------------------------------------------------------------------------- /loader.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | const path = require('path') 3 | const WASI = require('wasi') 4 | 5 | // 编译并实例化 wasm 模块,返回导出的接口 6 | async function loadWebAssembly (filename, env) { 7 | const wasi = new WASI({}) 8 | const filePath = path.resolve(__dirname, filename) 9 | 10 | // 读入 wasm 文件的二进制代码 11 | const buffer = fs.readFileSync(filePath) 12 | 13 | // 将 wasm 包实例化并传入外部接口,因为没有外部依赖,不传 env 也可以的 14 | const result = await WebAssembly.instantiate(buffer, { 15 | env: Object.assign({ 16 | '__memory_base': 0, 17 | '__table_base': 0, 18 | memory: new WebAssembly.Memory({ initial: 256, maximum: 256 }), 19 | table: new WebAssembly.Table({ initial: 0, maximum: 128, element: 'anyfunc' }) 20 | }, env), 21 | wasi_unstable: wasi.exports 22 | }) 23 | 24 | // 返回实例化好之后的接口 25 | if (result && result.instance && result.instance.exports) { 26 | wasi.setMemory(result.instance.exports.memory) 27 | return result.instance.exports 28 | } 29 | } 30 | 31 | module.exports = { 32 | loadWebAssembly 33 | } 34 | 35 | // loadWebAssembly('./hello-wasi.wasm').then(apis => { 36 | // console.log(Object.keys(apis)) 37 | // console.log(apis._start()) 38 | // }) 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 把 C/C++ 编译成 WebAssembly 2 | 3 | 参考文章:[《从零开始把 C/C++ 编译成 WebAssembly》](https://mp.weixin.qq.com/s/XrOHuoJB4vwkozBDI4t1yA) 4 | 5 | ## 源代码 6 | 7 | ``` 8 | ./ 9 | ├── fib.c # 斐波那契函数 10 | └── hello.c # 输出 Hello World! 11 | ``` 12 | 13 | ## 编译代码 14 | 15 | 首先安装依赖: 16 | 17 | 1. [Emscripten](https://emscripten.org/docs/getting_started/downloads.html) 18 | 2. [wasi-sdk](https://github.com/CraneStation/wasi-sdk) 19 | 3. [WABT (WebAssembly Binary Toolkit)](https://github.com/WebAssembly/wabt) 20 | 21 | 然后执行下方命令即可编译所有代码,具体每行命令的含义,参考文件内的注释。 22 | 23 | ```bash 24 | ./build.sh 25 | ``` 26 | 27 | ## 测试代码 28 | 29 | 首先安装 Node.js ,然后在当前目录下执行 `npm install`,然后就可以执行如下测试: 30 | 31 | ### 1. 测试 hello.c 32 | 33 | ```bash 34 | node test-hello.js 35 | ``` 36 | 37 | 将会得到两行输出,分别由 Emscripten 和 wasi-sdk 编译而来: 38 | 39 | ``` 40 | Hello World! 41 | Hello World! 42 | ``` 43 | 44 | ### 2. 测试 fib.c 45 | 46 | ```bash 47 | node test-fib.js 48 | ``` 49 | 50 | 将会得到两行输出: 51 | 52 | ``` 53 | [emcc] fib(3) = 2 54 | [wasi] fib(3) = 2 55 | ``` 56 | 57 | 可以在命令后指定要计算的数字: 58 | 59 | ```bash 60 | node test-fib.js 17 61 | ``` 62 | 63 | 输出: 64 | 65 | ``` 66 | [wasi] fib(17) = 1597 67 | [emcc] fib(17) = 1597 68 | ``` 69 | 70 | ## 使用独立运行时 71 | 72 | 可以使用独立的 WebAssembly 运行时执行编译出来的代码,以 [Wasmtime]() 为例: 73 | 74 | ```bash 75 | # 输出 Hello World! 76 | wasmtime out/hello-wasi.wasm 77 | ``` 78 | 79 | ```bash 80 | # 调用 wasi-sdk 编译出来的 fib 函数 81 | wasmtime out/fib-wasi.wasm --invoke fib 8 82 | ``` 83 | 84 | ```bash 85 | # 调用 Emscripten 编译出来的 fib 函数 86 | wasmtime out/fib-emcc.wasm --invoke _fib 11 87 | ``` 88 | -------------------------------------------------------------------------------- /out/hello-emcc.js: -------------------------------------------------------------------------------- 1 | var Module=typeof Module!=="undefined"?Module:{};var moduleOverrides={};var key;for(key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}Module["arguments"]=[];Module["thisProgram"]="./this.program";Module["quit"]=function(status,toThrow){throw toThrow};Module["preRun"]=[];Module["postRun"]=[];var ENVIRONMENT_IS_WEB=false;var ENVIRONMENT_IS_WORKER=false;var ENVIRONMENT_IS_NODE=false;var ENVIRONMENT_IS_SHELL=false;ENVIRONMENT_IS_WEB=typeof window==="object";ENVIRONMENT_IS_WORKER=typeof importScripts==="function";ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof require==="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}else{return scriptDirectory+path}}if(ENVIRONMENT_IS_NODE){scriptDirectory=__dirname+"/";var nodeFS;var nodePath;Module["read"]=function shell_read(filename,binary){var ret;if(!nodeFS)nodeFS=require("fs");if(!nodePath)nodePath=require("path");filename=nodePath["normalize"](filename);ret=nodeFS["readFileSync"](filename);return binary?ret:ret.toString()};Module["readBinary"]=function readBinary(filename){var ret=Module["read"](filename,true);if(!ret.buffer){ret=new Uint8Array(ret)}assert(ret.buffer);return ret};if(process["argv"].length>1){Module["thisProgram"]=process["argv"][1].replace(/\\/g,"/")}Module["arguments"]=process["argv"].slice(2);if(typeof module!=="undefined"){module["exports"]=Module}process["on"]("uncaughtException",function(ex){if(!(ex instanceof ExitStatus)){throw ex}});process["on"]("unhandledRejection",abort);Module["quit"]=function(status){process["exit"](status)};Module["inspect"]=function(){return"[Emscripten Module object]"}}else if(ENVIRONMENT_IS_SHELL){if(typeof read!="undefined"){Module["read"]=function shell_read(f){return read(f)}}Module["readBinary"]=function readBinary(f){var data;if(typeof readbuffer==="function"){return new Uint8Array(readbuffer(f))}data=read(f,"binary");assert(typeof data==="object");return data};if(typeof scriptArgs!="undefined"){Module["arguments"]=scriptArgs}else if(typeof arguments!="undefined"){Module["arguments"]=arguments}if(typeof quit==="function"){Module["quit"]=function(status){quit(status)}}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WORKER){scriptDirectory=self.location.href}else if(document.currentScript){scriptDirectory=document.currentScript.src}if(scriptDirectory.indexOf("blob:")!==0){scriptDirectory=scriptDirectory.substr(0,scriptDirectory.lastIndexOf("/")+1)}else{scriptDirectory=""}Module["read"]=function shell_read(url){var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.send(null);return xhr.responseText};if(ENVIRONMENT_IS_WORKER){Module["readBinary"]=function readBinary(url){var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}Module["readAsync"]=function readAsync(url,onload,onerror){var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=function xhr_onload(){if(xhr.status==200||xhr.status==0&&xhr.response){onload(xhr.response);return}onerror()};xhr.onerror=onerror;xhr.send(null)};Module["setWindowTitle"]=function(title){document.title=title}}else{}var out=Module["print"]||(typeof console!=="undefined"?console.log.bind(console):typeof print!=="undefined"?print:null);var err=Module["printErr"]||(typeof printErr!=="undefined"?printErr:typeof console!=="undefined"&&console.warn.bind(console)||out);for(key in moduleOverrides){if(moduleOverrides.hasOwnProperty(key)){Module[key]=moduleOverrides[key]}}moduleOverrides=undefined;var asm2wasmImports={"f64-rem":function(x,y){return x%y},"debugger":function(){debugger}};var functionPointers=new Array(0);if(typeof WebAssembly!=="object"){err("no native wasm support detected")}var wasmMemory;var wasmTable;var ABORT=false;var EXITSTATUS=0;function assert(condition,text){if(!condition){abort("Assertion failed: "+text)}}var UTF8Decoder=typeof TextDecoder!=="undefined"?new TextDecoder("utf8"):undefined;function UTF8ArrayToString(u8Array,idx,maxBytesToRead){var endIdx=idx+maxBytesToRead;var endPtr=idx;while(u8Array[endPtr]&&!(endPtr>=endIdx))++endPtr;if(endPtr-idx>16&&u8Array.subarray&&UTF8Decoder){return UTF8Decoder.decode(u8Array.subarray(idx,endPtr))}else{var str="";while(idx>10,56320|ch&1023)}}}return str}function UTF8ToString(ptr,maxBytesToRead){return ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead):""}function stringToUTF8Array(str,outU8Array,outIdx,maxBytesToWrite){if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i=55296&&u<=57343){var u1=str.charCodeAt(++i);u=65536+((u&1023)<<10)|u1&1023}if(u<=127){if(outIdx>=endIdx)break;outU8Array[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;outU8Array[outIdx++]=192|u>>6;outU8Array[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;outU8Array[outIdx++]=224|u>>12;outU8Array[outIdx++]=128|u>>6&63;outU8Array[outIdx++]=128|u&63}else{if(outIdx+3>=endIdx)break;outU8Array[outIdx++]=240|u>>18;outU8Array[outIdx++]=128|u>>12&63;outU8Array[outIdx++]=128|u>>6&63;outU8Array[outIdx++]=128|u&63}}outU8Array[outIdx]=0;return outIdx-startIdx}function lengthBytesUTF8(str){var len=0;for(var i=0;i=55296&&u<=57343)u=65536+((u&1023)<<10)|str.charCodeAt(++i)&1023;if(u<=127)++len;else if(u<=2047)len+=2;else if(u<=65535)len+=3;else len+=4}return len}var UTF16Decoder=typeof TextDecoder!=="undefined"?new TextDecoder("utf-16le"):undefined;function allocateUTF8OnStack(str){var size=lengthBytesUTF8(str)+1;var ret=stackAlloc(size);stringToUTF8Array(str,HEAP8,ret,size);return ret}var WASM_PAGE_SIZE=65536;var buffer,HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;function updateGlobalBufferViews(){Module["HEAP8"]=HEAP8=new Int8Array(buffer);Module["HEAP16"]=HEAP16=new Int16Array(buffer);Module["HEAP32"]=HEAP32=new Int32Array(buffer);Module["HEAPU8"]=HEAPU8=new Uint8Array(buffer);Module["HEAPU16"]=HEAPU16=new Uint16Array(buffer);Module["HEAPU32"]=HEAPU32=new Uint32Array(buffer);Module["HEAPF32"]=HEAPF32=new Float32Array(buffer);Module["HEAPF64"]=HEAPF64=new Float64Array(buffer)}var DYNAMIC_BASE=5246880,DYNAMICTOP_PTR=3744;var TOTAL_STACK=5242880;var INITIAL_TOTAL_MEMORY=Module["TOTAL_MEMORY"]||16777216;if(INITIAL_TOTAL_MEMORY>2]=DYNAMIC_BASE;function callRuntimeCallbacks(callbacks){while(callbacks.length>0){var callback=callbacks.shift();if(typeof callback=="function"){callback();continue}var func=callback.func;if(typeof func==="number"){if(callback.arg===undefined){Module["dynCall_v"](func)}else{Module["dynCall_vi"](func,callback.arg)}}else{func(callback.arg===undefined?null:callback.arg)}}}var __ATPRERUN__=[];var __ATINIT__=[];var __ATMAIN__=[];var __ATPOSTRUN__=[];var runtimeInitialized=false;var runtimeExited=false;function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(__ATPRERUN__)}function ensureInitRuntime(){if(runtimeInitialized)return;runtimeInitialized=true;callRuntimeCallbacks(__ATINIT__)}function preMain(){callRuntimeCallbacks(__ATMAIN__)}function exitRuntime(){runtimeExited=true}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(__ATPOSTRUN__)}function addOnPreRun(cb){__ATPRERUN__.unshift(cb)}function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb)}var runDependencies=0;var runDependencyWatcher=null;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}}function removeRunDependency(id){runDependencies--;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}if(runDependencies==0){if(runDependencyWatcher!==null){clearInterval(runDependencyWatcher);runDependencyWatcher=null}if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}Module["preloadedImages"]={};Module["preloadedAudios"]={};var dataURIPrefix="data:application/octet-stream;base64,";function isDataURI(filename){return String.prototype.startsWith?filename.startsWith(dataURIPrefix):filename.indexOf(dataURIPrefix)===0}var wasmBinaryFile="hello-emcc.wasm";if(!isDataURI(wasmBinaryFile)){wasmBinaryFile=locateFile(wasmBinaryFile)}function getBinary(){try{if(Module["wasmBinary"]){return new Uint8Array(Module["wasmBinary"])}if(Module["readBinary"]){return Module["readBinary"](wasmBinaryFile)}else{throw"both async and sync fetching of the wasm failed"}}catch(err){abort(err)}}function getBinaryPromise(){if(!Module["wasmBinary"]&&(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER)&&typeof fetch==="function"){return fetch(wasmBinaryFile,{credentials:"same-origin"}).then(function(response){if(!response["ok"]){throw"failed to load wasm binary file at '"+wasmBinaryFile+"'"}return response["arrayBuffer"]()}).catch(function(){return getBinary()})}return new Promise(function(resolve,reject){resolve(getBinary())})}function createWasm(env){var info={"env":env,"global":{"NaN":NaN,Infinity:Infinity},"global.Math":Math,"asm2wasm":asm2wasmImports};function receiveInstance(instance,module){var exports=instance.exports;Module["asm"]=exports;removeRunDependency("wasm-instantiate")}addRunDependency("wasm-instantiate");if(Module["instantiateWasm"]){try{return Module["instantiateWasm"](info,receiveInstance)}catch(e){err("Module.instantiateWasm callback failed with error: "+e);return false}}function receiveInstantiatedSource(output){receiveInstance(output["instance"])}function instantiateArrayBuffer(receiver){getBinaryPromise().then(function(binary){return WebAssembly.instantiate(binary,info)}).then(receiver,function(reason){err("failed to asynchronously prepare wasm: "+reason);abort(reason)})}if(!Module["wasmBinary"]&&typeof WebAssembly.instantiateStreaming==="function"&&!isDataURI(wasmBinaryFile)&&typeof fetch==="function"){WebAssembly.instantiateStreaming(fetch(wasmBinaryFile,{credentials:"same-origin"}),info).then(receiveInstantiatedSource,function(reason){err("wasm streaming compile failed: "+reason);err("falling back to ArrayBuffer instantiation");instantiateArrayBuffer(receiveInstantiatedSource)})}else{instantiateArrayBuffer(receiveInstantiatedSource)}return{}}Module["asm"]=function(global,env,providedBuffer){env["memory"]=wasmMemory;env["table"]=wasmTable=new WebAssembly.Table({"initial":6,"maximum":6,"element":"anyfunc"});env["__memory_base"]=1024;env["__table_base"]=0;var exports=createWasm(env);return exports};var SYSCALLS={buffers:[null,[],[]],printChar:function(stream,curr){var buffer=SYSCALLS.buffers[stream];if(curr===0||curr===10){(stream===1?out:err)(UTF8ArrayToString(buffer,0));buffer.length=0}else{buffer.push(curr)}},varargs:0,get:function(varargs){SYSCALLS.varargs+=4;var ret=HEAP32[SYSCALLS.varargs-4>>2];return ret},getStr:function(){var ret=UTF8ToString(SYSCALLS.get());return ret},get64:function(){var low=SYSCALLS.get(),high=SYSCALLS.get();return low},getZero:function(){SYSCALLS.get()}};function ___syscall140(which,varargs){SYSCALLS.varargs=varargs;try{var stream=SYSCALLS.getStreamFromFD(),offset_high=SYSCALLS.get(),offset_low=SYSCALLS.get(),result=SYSCALLS.get(),whence=SYSCALLS.get();var offset=offset_low;FS.llseek(stream,offset,whence);HEAP32[result>>2]=stream.position;if(stream.getdents&&offset===0&&whence===0)stream.getdents=null;return 0}catch(e){if(typeof FS==="undefined"||!(e instanceof FS.ErrnoError))abort(e);return-e.errno}}function ___syscall146(which,varargs){SYSCALLS.varargs=varargs;try{var stream=SYSCALLS.get(),iov=SYSCALLS.get(),iovcnt=SYSCALLS.get();var ret=0;for(var i=0;i>2];var len=HEAP32[iov+(i*8+4)>>2];for(var j=0;j>2]=allocateUTF8OnStack(Module["thisProgram"]);for(var i=1;i>2)+i]=allocateUTF8OnStack(args[i-1])}HEAP32[(argv>>2)+argc]=0;try{var ret=Module["_main"](argc,argv,0);exit(ret,true)}catch(e){if(e instanceof ExitStatus){return}else if(e=="SimulateInfiniteLoop"){Module["noExitRuntime"]=true;return}else{var toLog=e;if(e&&typeof e==="object"&&e.stack){toLog=[e,e.stack]}err("exception thrown: "+toLog);Module["quit"](1,e)}}finally{calledMain=true}};function run(args){args=args||Module["arguments"];if(runDependencies>0){return}preRun();if(runDependencies>0)return;if(Module["calledRun"])return;function doRun(){if(Module["calledRun"])return;Module["calledRun"]=true;if(ABORT)return;ensureInitRuntime();preMain();if(Module["onRuntimeInitialized"])Module["onRuntimeInitialized"]();if(Module["_main"]&&shouldRunNow)Module["callMain"](args);postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(function(){setTimeout(function(){Module["setStatus"]("")},1);doRun()},1)}else{doRun()}}Module["run"]=run;function exit(status,implicit){if(implicit&&Module["noExitRuntime"]&&status===0){return}if(Module["noExitRuntime"]){}else{ABORT=true;EXITSTATUS=status;exitRuntime();if(Module["onExit"])Module["onExit"](status)}Module["quit"](status,new ExitStatus(status))}function abort(what){if(Module["onAbort"]){Module["onAbort"](what)}if(what!==undefined){out(what);err(what);what=JSON.stringify(what)}else{what=""}ABORT=true;EXITSTATUS=1;throw"abort("+what+"). Build with -s ASSERTIONS=1 for more info."}Module["abort"]=abort;if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}var shouldRunNow=true;if(Module["noInitialRun"]){shouldRunNow=false}Module["noExitRuntime"]=true;run(); 2 | -------------------------------------------------------------------------------- /out/hello-emcc.wat: -------------------------------------------------------------------------------- 1 | (module 2 | (type (;0;) (func (param i32 i32 i32) (result i32))) 3 | (type (;1;) (func (param i32) (result i32))) 4 | (type (;2;) (func (param i32))) 5 | (type (;3;) (func (param i32 i32) (result i32))) 6 | (type (;4;) (func (result i32))) 7 | (type (;5;) (func)) 8 | (import "env" "a" (func (;0;) (type 3))) 9 | (import "env" "b" (func (;1;) (type 2))) 10 | (import "env" "c" (func (;2;) (type 0))) 11 | (import "env" "d" (func (;3;) (type 3))) 12 | (import "env" "e" (func (;4;) (type 3))) 13 | (import "env" "f" (func (;5;) (type 3))) 14 | (import "env" "__table_base" (global (;0;) i32)) 15 | (import "env" "memory" (memory (;0;) 256 256)) 16 | (import "env" "table" (table (;0;) 6 6 funcref)) 17 | (func (;6;) (type 0) (param i32 i32 i32) (result i32) 18 | (local i32 i32 i32 i32 i32 i32 i32 i32) 19 | global.get 1 20 | local.set 7 21 | global.get 1 22 | i32.const 48 23 | i32.add 24 | global.set 1 25 | local.get 7 26 | i32.const 32 27 | i32.add 28 | local.set 6 29 | local.get 7 30 | local.tee 3 31 | local.get 0 32 | i32.load offset=28 33 | local.tee 5 34 | i32.store 35 | local.get 3 36 | local.get 0 37 | i32.load offset=20 38 | local.get 5 39 | i32.sub 40 | local.tee 5 41 | i32.store offset=4 42 | local.get 3 43 | local.get 1 44 | i32.store offset=8 45 | local.get 3 46 | local.get 2 47 | i32.store offset=12 48 | local.get 3 49 | i32.const 16 50 | i32.add 51 | local.tee 1 52 | local.get 0 53 | i32.load offset=60 54 | i32.store 55 | local.get 1 56 | local.get 3 57 | i32.store offset=4 58 | local.get 1 59 | i32.const 2 60 | i32.store offset=8 61 | i32.const 146 62 | local.get 1 63 | call 0 64 | local.tee 4 65 | i32.const -4096 66 | i32.gt_u 67 | if ;; label = @1 68 | i32.const 2704 69 | i32.const 0 70 | local.get 4 71 | i32.sub 72 | i32.store 73 | i32.const -1 74 | local.set 4 75 | end 76 | block ;; label = @1 77 | block ;; label = @2 78 | local.get 4 79 | local.get 2 80 | local.get 5 81 | i32.add 82 | local.tee 5 83 | i32.eq 84 | br_if 0 (;@2;) 85 | i32.const 2 86 | local.set 8 87 | local.get 3 88 | local.set 1 89 | local.get 4 90 | local.set 3 91 | loop ;; label = @3 92 | local.get 3 93 | i32.const 0 94 | i32.ge_s 95 | if ;; label = @4 96 | local.get 1 97 | i32.const 8 98 | i32.add 99 | local.get 1 100 | local.get 3 101 | local.get 1 102 | i32.load offset=4 103 | local.tee 9 104 | i32.gt_u 105 | local.tee 4 106 | select 107 | local.tee 1 108 | local.get 3 109 | local.get 9 110 | i32.const 0 111 | local.get 4 112 | select 113 | i32.sub 114 | local.tee 9 115 | local.get 1 116 | i32.load 117 | i32.add 118 | i32.store 119 | local.get 1 120 | local.get 1 121 | i32.load offset=4 122 | local.get 9 123 | i32.sub 124 | i32.store offset=4 125 | local.get 6 126 | local.get 0 127 | i32.load offset=60 128 | i32.store 129 | local.get 6 130 | local.get 1 131 | i32.store offset=4 132 | local.get 6 133 | local.get 8 134 | local.get 4 135 | i32.const 31 136 | i32.shl 137 | i32.const 31 138 | i32.shr_s 139 | i32.add 140 | local.tee 8 141 | i32.store offset=8 142 | block (result i32) ;; label = @5 143 | local.get 5 144 | local.get 3 145 | i32.sub 146 | local.tee 5 147 | local.set 10 148 | i32.const 146 149 | local.get 6 150 | call 0 151 | local.tee 3 152 | i32.const -4096 153 | i32.gt_u 154 | if ;; label = @6 155 | i32.const 2704 156 | i32.const 0 157 | local.get 3 158 | i32.sub 159 | i32.store 160 | i32.const -1 161 | local.set 3 162 | end 163 | local.get 10 164 | end 165 | local.get 3 166 | i32.eq 167 | br_if 2 (;@2;) 168 | br 1 (;@3;) 169 | end 170 | end 171 | local.get 0 172 | i32.const 0 173 | i32.store offset=16 174 | local.get 0 175 | i32.const 0 176 | i32.store offset=28 177 | local.get 0 178 | i32.const 0 179 | i32.store offset=20 180 | local.get 0 181 | local.get 0 182 | i32.load 183 | i32.const 32 184 | i32.or 185 | i32.store 186 | local.get 8 187 | i32.const 2 188 | i32.eq 189 | if (result i32) ;; label = @3 190 | i32.const 0 191 | else 192 | local.get 2 193 | local.get 1 194 | i32.load offset=4 195 | i32.sub 196 | end 197 | local.set 2 198 | br 1 (;@1;) 199 | end 200 | local.get 0 201 | local.get 0 202 | i32.load offset=44 203 | local.tee 1 204 | local.get 0 205 | i32.load offset=48 206 | i32.add 207 | i32.store offset=16 208 | local.get 0 209 | local.get 1 210 | i32.store offset=28 211 | local.get 0 212 | local.get 1 213 | i32.store offset=20 214 | end 215 | local.get 7 216 | global.set 1 217 | local.get 2) 218 | (func (;7;) (type 1) (param i32) (result i32) 219 | (local i32) 220 | local.get 0 221 | local.get 0 222 | i32.load8_s offset=74 223 | local.tee 1 224 | local.get 1 225 | i32.const 255 226 | i32.add 227 | i32.or 228 | i32.store8 offset=74 229 | local.get 0 230 | i32.load 231 | local.tee 1 232 | i32.const 8 233 | i32.and 234 | if (result i32) ;; label = @1 235 | local.get 0 236 | local.get 1 237 | i32.const 32 238 | i32.or 239 | i32.store 240 | i32.const -1 241 | else 242 | local.get 0 243 | i32.const 0 244 | i32.store offset=8 245 | local.get 0 246 | i32.const 0 247 | i32.store offset=4 248 | local.get 0 249 | local.get 0 250 | i32.load offset=44 251 | local.tee 1 252 | i32.store offset=28 253 | local.get 0 254 | local.get 1 255 | i32.store offset=20 256 | local.get 0 257 | local.get 1 258 | local.get 0 259 | i32.load offset=48 260 | i32.add 261 | i32.store offset=16 262 | i32.const 0 263 | end) 264 | (func (;8;) (type 0) (param i32 i32 i32) (result i32) 265 | (local i32 i32) 266 | global.get 1 267 | local.set 3 268 | global.get 1 269 | i32.const 32 270 | i32.add 271 | global.set 1 272 | local.get 3 273 | local.get 0 274 | i32.load offset=60 275 | i32.store 276 | local.get 3 277 | i32.const 0 278 | i32.store offset=4 279 | local.get 3 280 | local.get 1 281 | i32.store offset=8 282 | local.get 3 283 | local.get 3 284 | i32.const 20 285 | i32.add 286 | i32.store offset=12 287 | local.get 3 288 | local.get 2 289 | i32.store offset=16 290 | i32.const 140 291 | local.get 3 292 | call 5 293 | local.tee 0 294 | i32.const -4096 295 | i32.gt_u 296 | if (result i32) ;; label = @1 297 | i32.const 2704 298 | i32.const 0 299 | local.get 0 300 | i32.sub 301 | i32.store 302 | i32.const -1 303 | else 304 | local.get 0 305 | end 306 | i32.const 0 307 | i32.lt_s 308 | if (result i32) ;; label = @1 309 | local.get 3 310 | i32.const -1 311 | i32.store offset=20 312 | i32.const -1 313 | else 314 | local.get 3 315 | i32.load offset=20 316 | end 317 | local.set 4 318 | local.get 3 319 | global.set 1 320 | local.get 4) 321 | (func (;9;) (type 1) (param i32) (result i32) 322 | (local i32) 323 | global.get 1 324 | local.set 1 325 | global.get 1 326 | i32.const 16 327 | i32.add 328 | global.set 1 329 | local.get 1 330 | local.get 0 331 | i32.load offset=60 332 | i32.store 333 | i32.const 6 334 | local.get 1 335 | call 3 336 | local.tee 0 337 | i32.const -4096 338 | i32.gt_u 339 | if ;; label = @1 340 | i32.const 2704 341 | i32.const 0 342 | local.get 0 343 | i32.sub 344 | i32.store 345 | i32.const -1 346 | local.set 0 347 | end 348 | local.get 1 349 | global.set 1 350 | local.get 0) 351 | (func (;10;) (type 4) (result i32) 352 | call 14 353 | i32.const 0) 354 | (func (;11;) (type 0) (param i32 i32 i32) (result i32) 355 | i32.const 1 356 | call 1 357 | i32.const 0) 358 | (func (;12;) (type 1) (param i32) (result i32) 359 | i32.const 0 360 | call 1 361 | i32.const 0) 362 | (func (;13;) (type 0) (param i32 i32 i32) (result i32) 363 | (local i32 i32 i32) 364 | local.get 2 365 | i32.const 8192 366 | i32.ge_s 367 | if ;; label = @1 368 | local.get 0 369 | local.get 1 370 | local.get 2 371 | call 2 372 | drop 373 | local.get 0 374 | return 375 | end 376 | local.get 0 377 | local.set 4 378 | local.get 0 379 | local.get 2 380 | i32.add 381 | local.set 3 382 | local.get 0 383 | i32.const 3 384 | i32.and 385 | local.get 1 386 | i32.const 3 387 | i32.and 388 | i32.eq 389 | if ;; label = @1 390 | loop ;; label = @2 391 | local.get 0 392 | i32.const 3 393 | i32.and 394 | if ;; label = @3 395 | local.get 2 396 | i32.eqz 397 | if ;; label = @4 398 | local.get 4 399 | return 400 | end 401 | local.get 0 402 | local.get 1 403 | i32.load8_s 404 | i32.store8 405 | local.get 0 406 | i32.const 1 407 | i32.add 408 | local.set 0 409 | local.get 1 410 | i32.const 1 411 | i32.add 412 | local.set 1 413 | local.get 2 414 | i32.const 1 415 | i32.sub 416 | local.set 2 417 | br 1 (;@2;) 418 | end 419 | end 420 | local.get 3 421 | i32.const -4 422 | i32.and 423 | local.tee 2 424 | i32.const -64 425 | i32.add 426 | local.set 5 427 | loop ;; label = @2 428 | local.get 0 429 | local.get 5 430 | i32.le_s 431 | if ;; label = @3 432 | local.get 0 433 | local.get 1 434 | i32.load 435 | i32.store 436 | local.get 0 437 | local.get 1 438 | i32.load offset=4 439 | i32.store offset=4 440 | local.get 0 441 | local.get 1 442 | i32.load offset=8 443 | i32.store offset=8 444 | local.get 0 445 | local.get 1 446 | i32.load offset=12 447 | i32.store offset=12 448 | local.get 0 449 | local.get 1 450 | i32.load offset=16 451 | i32.store offset=16 452 | local.get 0 453 | local.get 1 454 | i32.load offset=20 455 | i32.store offset=20 456 | local.get 0 457 | local.get 1 458 | i32.load offset=24 459 | i32.store offset=24 460 | local.get 0 461 | local.get 1 462 | i32.load offset=28 463 | i32.store offset=28 464 | local.get 0 465 | local.get 1 466 | i32.load offset=32 467 | i32.store offset=32 468 | local.get 0 469 | local.get 1 470 | i32.load offset=36 471 | i32.store offset=36 472 | local.get 0 473 | local.get 1 474 | i32.load offset=40 475 | i32.store offset=40 476 | local.get 0 477 | local.get 1 478 | i32.load offset=44 479 | i32.store offset=44 480 | local.get 0 481 | local.get 1 482 | i32.load offset=48 483 | i32.store offset=48 484 | local.get 0 485 | local.get 1 486 | i32.load offset=52 487 | i32.store offset=52 488 | local.get 0 489 | local.get 1 490 | i32.load offset=56 491 | i32.store offset=56 492 | local.get 0 493 | local.get 1 494 | i32.load offset=60 495 | i32.store offset=60 496 | local.get 0 497 | i32.const -64 498 | i32.sub 499 | local.set 0 500 | local.get 1 501 | i32.const -64 502 | i32.sub 503 | local.set 1 504 | br 1 (;@2;) 505 | end 506 | end 507 | loop ;; label = @2 508 | local.get 0 509 | local.get 2 510 | i32.lt_s 511 | if ;; label = @3 512 | local.get 0 513 | local.get 1 514 | i32.load 515 | i32.store 516 | local.get 0 517 | i32.const 4 518 | i32.add 519 | local.set 0 520 | local.get 1 521 | i32.const 4 522 | i32.add 523 | local.set 1 524 | br 1 (;@2;) 525 | end 526 | end 527 | else 528 | local.get 3 529 | i32.const 4 530 | i32.sub 531 | local.set 2 532 | loop ;; label = @2 533 | local.get 0 534 | local.get 2 535 | i32.lt_s 536 | if ;; label = @3 537 | local.get 0 538 | local.get 1 539 | i32.load8_s 540 | i32.store8 541 | local.get 0 542 | local.get 1 543 | i32.load8_s offset=1 544 | i32.store8 offset=1 545 | local.get 0 546 | local.get 1 547 | i32.load8_s offset=2 548 | i32.store8 offset=2 549 | local.get 0 550 | local.get 1 551 | i32.load8_s offset=3 552 | i32.store8 offset=3 553 | local.get 0 554 | i32.const 4 555 | i32.add 556 | local.set 0 557 | local.get 1 558 | i32.const 4 559 | i32.add 560 | local.set 1 561 | br 1 (;@2;) 562 | end 563 | end 564 | end 565 | loop ;; label = @1 566 | local.get 0 567 | local.get 3 568 | i32.lt_s 569 | if ;; label = @2 570 | local.get 0 571 | local.get 1 572 | i32.load8_s 573 | i32.store8 574 | local.get 0 575 | i32.const 1 576 | i32.add 577 | local.set 0 578 | local.get 1 579 | i32.const 1 580 | i32.add 581 | local.set 1 582 | br 1 (;@1;) 583 | end 584 | end 585 | local.get 4) 586 | (func (;14;) (type 5) 587 | (local i32 i32 i32 i32) 588 | i32.const 1024 589 | i32.load 590 | local.tee 0 591 | i32.load offset=76 592 | i32.const -1 593 | i32.gt_s 594 | if (result i32) ;; label = @1 595 | i32.const 1 596 | else 597 | i32.const 0 598 | end 599 | drop 600 | block (result i32) ;; label = @1 601 | call 17 602 | local.tee 1 603 | local.set 3 604 | local.get 0 605 | i32.load offset=76 606 | drop 607 | local.get 3 608 | end 609 | local.get 1 610 | local.get 0 611 | call 15 612 | local.tee 2 613 | local.get 1 614 | local.get 1 615 | local.get 2 616 | i32.ne 617 | select 618 | i32.ne 619 | i32.const 31 620 | i32.shl 621 | i32.const 31 622 | i32.shr_s 623 | i32.const 0 624 | i32.lt_s 625 | if (result i32) ;; label = @1 626 | i32.const -1 627 | else 628 | block (result i32) ;; label = @2 629 | local.get 0 630 | i32.load8_s offset=75 631 | i32.const 10 632 | i32.ne 633 | if ;; label = @3 634 | local.get 0 635 | i32.load offset=20 636 | local.tee 1 637 | local.get 0 638 | i32.load offset=16 639 | i32.lt_u 640 | if ;; label = @4 641 | local.get 0 642 | local.get 1 643 | i32.const 1 644 | i32.add 645 | i32.store offset=20 646 | local.get 1 647 | i32.const 10 648 | i32.store8 649 | i32.const 0 650 | br 2 (;@2;) 651 | end 652 | end 653 | local.get 0 654 | call 16 655 | end 656 | end 657 | drop) 658 | (func (;15;) (type 3) (param i32 i32) (result i32) 659 | (local i32 i32 i32 i32) 660 | i32.const 1152 661 | local.set 4 662 | block ;; label = @1 663 | block ;; label = @2 664 | local.get 1 665 | i32.load offset=16 666 | local.tee 2 667 | br_if 0 (;@2;) 668 | local.get 1 669 | call 7 670 | if (result i32) ;; label = @3 671 | i32.const 0 672 | else 673 | local.get 1 674 | i32.load offset=16 675 | local.set 2 676 | br 1 (;@2;) 677 | end 678 | local.set 3 679 | br 1 (;@1;) 680 | end 681 | local.get 2 682 | local.get 1 683 | i32.load offset=20 684 | local.tee 3 685 | i32.sub 686 | local.get 0 687 | i32.lt_u 688 | if ;; label = @2 689 | local.get 1 690 | i32.const 1152 691 | local.get 0 692 | local.get 1 693 | i32.load offset=36 694 | i32.const 3 695 | i32.and 696 | i32.const 2 697 | i32.add 698 | call_indirect (type 0) 699 | local.set 3 700 | br 1 (;@1;) 701 | end 702 | local.get 0 703 | i32.eqz 704 | local.get 1 705 | i32.load8_s offset=75 706 | i32.const 0 707 | i32.lt_s 708 | i32.or 709 | if ;; label = @2 710 | i32.const 0 711 | local.set 2 712 | else 713 | block ;; label = @3 714 | local.get 0 715 | local.set 2 716 | loop ;; label = @4 717 | local.get 2 718 | i32.const -1 719 | i32.add 720 | local.tee 5 721 | i32.const 1152 722 | i32.add 723 | i32.load8_s 724 | i32.const 10 725 | i32.ne 726 | if ;; label = @5 727 | local.get 5 728 | if ;; label = @6 729 | local.get 5 730 | local.set 2 731 | br 2 (;@4;) 732 | else 733 | i32.const 0 734 | local.set 2 735 | br 3 (;@3;) 736 | end 737 | unreachable 738 | end 739 | end 740 | local.get 1 741 | i32.const 1152 742 | local.get 2 743 | local.get 1 744 | i32.load offset=36 745 | i32.const 3 746 | i32.and 747 | i32.const 2 748 | i32.add 749 | call_indirect (type 0) 750 | local.tee 3 751 | local.get 2 752 | i32.lt_u 753 | br_if 2 (;@1;) 754 | local.get 2 755 | i32.const 1152 756 | i32.add 757 | local.set 4 758 | local.get 0 759 | local.get 2 760 | i32.sub 761 | local.set 0 762 | local.get 1 763 | i32.load offset=20 764 | local.set 3 765 | end 766 | end 767 | local.get 3 768 | local.get 4 769 | local.get 0 770 | call 13 771 | drop 772 | local.get 1 773 | local.get 0 774 | local.get 1 775 | i32.load offset=20 776 | i32.add 777 | i32.store offset=20 778 | local.get 0 779 | local.get 2 780 | i32.add 781 | local.set 3 782 | end 783 | local.get 3) 784 | (func (;16;) (type 1) (param i32) (result i32) 785 | (local i32 i32 i32) 786 | global.get 1 787 | local.set 2 788 | global.get 1 789 | i32.const 16 790 | i32.add 791 | global.set 1 792 | local.get 2 793 | i32.const 10 794 | i32.store8 795 | block ;; label = @1 796 | block ;; label = @2 797 | local.get 0 798 | i32.load offset=16 799 | local.tee 1 800 | br_if 0 (;@2;) 801 | local.get 0 802 | call 7 803 | if (result i32) ;; label = @3 804 | i32.const -1 805 | else 806 | local.get 0 807 | i32.load offset=16 808 | local.set 1 809 | br 1 (;@2;) 810 | end 811 | local.set 1 812 | br 1 (;@1;) 813 | end 814 | local.get 0 815 | i32.load offset=20 816 | local.tee 3 817 | local.get 1 818 | i32.lt_u 819 | if ;; label = @2 820 | i32.const 10 821 | local.tee 1 822 | local.get 0 823 | i32.load8_s offset=75 824 | i32.ne 825 | if ;; label = @3 826 | local.get 0 827 | local.get 3 828 | i32.const 1 829 | i32.add 830 | i32.store offset=20 831 | local.get 3 832 | i32.const 10 833 | i32.store8 834 | br 2 (;@1;) 835 | end 836 | end 837 | local.get 0 838 | local.get 2 839 | i32.const 1 840 | local.get 0 841 | i32.load offset=36 842 | i32.const 3 843 | i32.and 844 | i32.const 2 845 | i32.add 846 | call_indirect (type 0) 847 | i32.const 1 848 | i32.eq 849 | if (result i32) ;; label = @2 850 | local.get 2 851 | i32.load8_u 852 | else 853 | i32.const -1 854 | end 855 | local.set 1 856 | end 857 | local.get 2 858 | global.set 1 859 | local.get 1) 860 | (func (;17;) (type 4) (result i32) 861 | (local i32 i32 i32) 862 | i32.const 1152 863 | local.set 0 864 | loop ;; label = @1 865 | local.get 0 866 | i32.const 4 867 | i32.add 868 | local.set 1 869 | local.get 0 870 | i32.load 871 | local.tee 2 872 | i32.const -16843009 873 | i32.add 874 | local.get 2 875 | i32.const -2139062144 876 | i32.and 877 | i32.const -2139062144 878 | i32.xor 879 | i32.and 880 | i32.eqz 881 | if ;; label = @2 882 | local.get 1 883 | local.set 0 884 | br 1 (;@1;) 885 | end 886 | end 887 | local.get 2 888 | i32.const 255 889 | i32.and 890 | if ;; label = @1 891 | loop ;; label = @2 892 | local.get 0 893 | i32.const 1 894 | i32.add 895 | local.tee 0 896 | i32.load8_s 897 | br_if 0 (;@2;) 898 | end 899 | end 900 | local.get 0 901 | i32.const 1152 902 | i32.sub) 903 | (func (;18;) (type 0) (param i32 i32 i32) (result i32) 904 | (local i32 i32 i32) 905 | global.get 1 906 | local.set 3 907 | global.get 1 908 | i32.const 32 909 | i32.add 910 | global.set 1 911 | local.get 3 912 | i32.const 16 913 | i32.add 914 | local.set 4 915 | local.get 0 916 | i32.const 3 917 | i32.store offset=36 918 | local.get 0 919 | i32.load 920 | i32.const 64 921 | i32.and 922 | i32.eqz 923 | if ;; label = @1 924 | local.get 3 925 | local.get 0 926 | i32.load offset=60 927 | i32.store 928 | local.get 3 929 | i32.const 21523 930 | i32.store offset=4 931 | local.get 3 932 | local.get 4 933 | i32.store offset=8 934 | i32.const 54 935 | local.get 3 936 | call 4 937 | if ;; label = @2 938 | local.get 0 939 | i32.const -1 940 | i32.store8 offset=75 941 | end 942 | end 943 | local.get 0 944 | local.get 1 945 | local.get 2 946 | call 6 947 | local.set 5 948 | local.get 3 949 | global.set 1 950 | local.get 5) 951 | (func (;19;) (type 1) (param i32) (result i32) 952 | (local i32 i32) 953 | global.get 1 954 | local.set 2 955 | local.get 0 956 | global.get 1 957 | i32.add 958 | global.set 1 959 | global.get 1 960 | i32.const 15 961 | i32.add 962 | i32.const -16 963 | i32.and 964 | global.set 1 965 | local.get 2) 966 | (global (;1;) (mut i32) (i32.const 4000)) 967 | (export "g" (func 10)) 968 | (export "h" (func 19)) 969 | (elem (;0;) (global.get 0) func 12 9 11 18 8 6) 970 | (data (;0;) (i32.const 1024) "\04\04\00\00\05") 971 | (data (;1;) (i32.const 1040) "\01") 972 | (data (;2;) (i32.const 1064) "\01\00\00\00\02\00\00\00\98\04\00\00\00\04") 973 | (data (;3;) (i32.const 1088) "\01") 974 | (data (;4;) (i32.const 1103) "\0a\ff\ff\ff\ff") 975 | (data (;5;) (i32.const 1152) "Hello World!")) 976 | --------------------------------------------------------------------------------