-
Notifications
You must be signed in to change notification settings - Fork 0
/
wasm32codegen.min.js
1 lines (1 loc) · 14.3 KB
/
wasm32codegen.min.js
1
var t=function(){this._buffer=new ArrayBuffer(8),this._data=new Uint8Array(this._buffer),this._size=0};t.prototype.size=function(){return this._size},t.prototype.get=function(t){return this._data[t]},t.prototype.set=function(t,i){this._data[t]=i},t.prototype.reserve_extra=function(t){if(this._size+t>this._data.length){for(var i=new ArrayBuffer(Math.max(2*this._data.length,this._size+t)),n=new Uint8Array(i),e=0;this._size>e;++e)n[e]=this._data[e];this._buffer=i,this._data=n}},t.prototype.push=function(t){this.reserve_extra(1),this._data[this._size++]=t},t.prototype.append=function(t){this.reserve_extra(t.length);for(var i=0;t.length>i;++i)this._data[this._size++]=t[i]},t.prototype.pop=function(){return this._data[--this._size]},t.prototype.insert_arr=function(t,i){this.reserve_extra(i.length);for(var n=this._size-1;n>=t;--n)this._data[n+i.length]=this._data[n];for(var n=0;i.length>n;++n)this._data[t+n]=i[n];this._size+=i.length},t.prototype.toUint8Array=function(){for(var t=new Uint8Array(this._size),i=0;this._size>i;++i)t[i]=this._data[i];return t};var i=function(t){return(new TextEncoder).encode(t)},n={};n.encodeUInt=function(i){0>i||i!==Math.floor(i);for(var n=new t;;){var e=i%128;if(i=Math.floor(i/128),0>=i){n.push(e);break}n.push(128+e)}return n.toUint8Array()},n.encodeInt=function(i){i!==Math.floor(i);var n=new t,e=0>i;for(e&&(i=-i-1);;){var r=i%128;if(i=Math.floor(i/128),0>=i&&64>r){n.push(e?127&~r:r);break}n.push(e?255&~r:128+r)}return n.toUint8Array()};var e={i32:127,i64:126,f32:125,f64:124,anyfunc:112,func:96,none:64},r={function:0,table:1,memory:2,global:3};(function(t,i){this._param_types=t?t:[],this._result_types=i?i:[]}).prototype.toUint8Array=function(){var i=new t;i.push(e.func),i.append(n.encodeUInt(this._param_types.length));for(var r=0;this._param_types.length>r;++r)i.push(this._param_types[r]);i.append(n.encodeUInt(this._result_types.length));for(var r=0;this._result_types.length>r;++r)i.push(this._result_types[r]);return i.toUint8Array()};var o=function(t){this._type=t};o.prototype.toUint8Array=function(){var i=new t;return i.append(n.encodeUInt(this._type)),i.toUint8Array()};var s=function(i){this._localTypes=i?i:[],this._data=new t,this._functionlinks=[]};s.prototype.setName=function(t){this._functionname=t},s.prototype.setType=function(t){this._functiontype=t},s.instruction={unreachable:0,nop:1,block:2,loop:3,if:4,else:5,end:11,br:12,br_if:13,br_table:14,return:15,call:16,call_indirect:17,drop:26,select:27,get_local:32,set_local:33,tee_local:34,get_global:35,set_global:36,i32_load:40,i64_load:41,f32_load:42,f64_load:43,i32_load8_s:44,i32_load8_u:45,i32_load16_s:46,i32_load16_u:47,i64_load8_s:48,i64_load8_u:49,i64_load16_s:50,i64_load16_u:51,i64_load32_s:52,i64_load32_u:53,i32_store:54,i64_store:55,f32_store:56,f64_store:57,i32_store8:58,i32_store16:59,i64_store8:60,i64_store16:61,i64_store32:62,current_memory:63,grow_memory:64,i32_const:65,i64_const:66,f32_const:67,f64_const:68,i32_eqz:69,i32_eq:70,i32_ne:71,i32_add:106,i32_sub:107,i32_mul:108},s.prototype.writeRawBytes=function(){for(var t=0;arguments.length>t;++t)this._data.push(arguments[t])},s.prototype.writeUint8Array=function(t){this._data.append(t)},s.prototype.unreachable=function(){this.writeRawBytes(s.instruction.unreachable)},s.prototype.nop=function(){this.writeRawBytes(s.instruction.nop)},s.prototype.block=function(t){this.writeRawBytes(s.instruction.block,t)},s.prototype.loop=function(t){this.writeRawBytes(s.instruction.loop,t)},s.prototype.if=function(t){this.writeRawBytes(s.instruction.if,t)},s.prototype.else=function(){this.writeRawBytes(s.instruction.else)},s.prototype.end=function(){this.writeRawBytes(s.instruction.end)},s.prototype.br=function(t){this.writeRawBytes(s.instruction.br),this.writeUint8Array(n.encodeUInt(t))},s.prototype.br_if=function(t){this.writeRawBytes(s.instruction.br_if),this.writeUint8Array(n.encodeUInt(t))},s.prototype.return=function(){this.writeRawBytes(s.instruction.return)},s.prototype.call=function(t){"number"==typeof t?(this.writeRawBytes(s.instruction.call),this.writeUint8Array(n.encodeUInt(t))):(this.writeRawBytes(s.instruction.call),this._functionlinks.push({location:this._data.size(),name:t}))},s.prototype.drop=function(){this.writeRawBytes(s.instruction.drop)},s.prototype.select=function(){this.writeRawBytes(s.instruction.select)},s.prototype.get_local=function(t){this.writeRawBytes(s.instruction.get_local),this.writeUint8Array(n.encodeUInt(t))},s.prototype.set_local=function(t){this.writeRawBytes(s.instruction.set_local),this.writeUint8Array(n.encodeUInt(t))},s.prototype.tee_local=function(t){this.writeRawBytes(s.instruction.tee_local),this.writeUint8Array(n.encodeUInt(t))},s.prototype.i32_load=function(t,i){i=i||0,this.writeRawBytes(s.instruction.i32_load),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.i64_load=function(t,i){i=i||0,this.writeRawBytes(s.instruction.i64_load),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.f32_load=function(t,i){i=i||0,this.writeRawBytes(s.instruction.f32_load),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.f64_load=function(t,i){i=i||0,this.writeRawBytes(s.instruction.f64_load),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.i32_load8_s=function(t,i){i=i||0,this.writeRawBytes(s.instruction.i32_load8_s),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.i32_load8_u=function(t,i){i=i||0,this.writeRawBytes(s.instruction.i32_load8_u),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.i32_load16_s=function(t,i){i=i||0,this.writeRawBytes(s.instruction.i32_load16_s),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.i32_load16_u=function(t,i){i=i||0,this.writeRawBytes(s.instruction.i32_load16_u),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.i64_load8_s=function(t,i){i=i||0,this.writeRawBytes(s.instruction.i64_load8_s),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.i64_load8_u=function(t,i){i=i||0,this.writeRawBytes(s.instruction.i64_load8_u),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.i64_load16_s=function(t,i){i=i||0,this.writeRawBytes(s.instruction.i64_load16_s),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.i64_load16_u=function(t,i){i=i||0,this.writeRawBytes(s.instruction.i64_load16_u),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.i64_load32_s=function(t,i){i=i||0,this.writeRawBytes(s.instruction.i64_load32_s),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.i64_load32_u=function(t,i){i=i||0,this.writeRawBytes(s.instruction.i64_load32_u),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.i32_store=function(t,i){i=i||0,this.writeRawBytes(s.instruction.i32_store),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.i64_store=function(t,i){i=i||0,this.writeRawBytes(s.instruction.i64_store),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.f32_store=function(t,i){i=i||0,this.writeRawBytes(s.instruction.f32_store),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.f64_store=function(t,i){i=i||0,this.writeRawBytes(s.instruction.f64_store),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.i32_store8=function(t,i){i=i||0,this.writeRawBytes(s.instruction.i32_store8),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.i32_store16=function(t,i){i=i||0,this.writeRawBytes(s.instruction.i32_store16),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.i64_store8=function(t,i){i=i||0,this.writeRawBytes(s.instruction.i64_store8),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.i64_store16=function(t,i){i=i||0,this.writeRawBytes(s.instruction.i64_store16),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.i64_store32=function(t,i){i=i||0,this.writeRawBytes(s.instruction.i64_store32),this.writeUint8Array(n.encodeUInt(i)),this.writeUint8Array(n.encodeUInt(t))},s.prototype.current_memory=function(){this.writeRawBytes(s.instruction.current_memory,0)},s.prototype.grow_memory=function(){this.writeRawBytes(s.instruction.grow_memory,0)},s.prototype.i32_const=function(t){this.writeRawBytes(s.instruction.i32_const),this.writeUint8Array(n.encodeInt(t))},s.prototype.i64_const=function(t){this.writeRawBytes(s.instruction.i64_const),this.writeUint8Array(n.encodeInt(t))},s.prototype.i32_eqz=function(){this.writeRawBytes(s.instruction.i32_eqz)},s.prototype.i32_eq=function(){this.writeRawBytes(s.instruction.i32_eq)},s.prototype.i32_ne=function(){this.writeRawBytes(s.instruction.i32_ne)},s.prototype.i32_add=function(){this.writeRawBytes(s.instruction.i32_add)},s.prototype.i32_sub=function(){this.writeRawBytes(s.instruction.i32_sub)},s.prototype.i32_mul=function(){this.writeRawBytes(s.instruction.i32_mul)},s.prototype.toUint8Array=function(){var i=new t;i.append(n.encodeUInt(this._localTypes.length));for(var e=0;this._localTypes.length>e;++e)i.push(1),i.push(this._localTypes[e]);return i.append(this._data.toUint8Array()),i.insert_arr(0,n.encodeUInt(i.size())),i.toUint8Array()};var a=function(t,i,n){this._field=t,this._kind=i,this._index=n};a.prototype.setName=function(t){this._functionname=t},a.prototype.toUint8Array=function(){var e=new t,r=i(this._field);return e.append(n.encodeUInt(r.length)),e.append(r),e.push(this._kind),e.append(n.encodeUInt(this._index)),e.toUint8Array()};var c=function(t,i,n){this._module=t,this._field=i,this._kind=n};c.prototype.setName=function(t){this._functionname=t},c.prototype.setType=function(t){this._functiontype=t},c.prototype.toUint8Array=function(){var e=new t,r=i(this._module),o=i(this._field);return e.push(n.encodeUInt(r.length)),e.append(r),e.push(n.encodeUInt(o.length)),e.append(o),e.push(this._kind),e.append(n.encodeUInt(this._type)),e.toUint8Array()},function(t,i){this._initial_pages=t,i&&(this._maximum_pages=i)}.prototype.toUint8Array=function(){var i=new t;return this._maximum_pages?(i.push(1),i.append(n.encodeUInt(this._initial_pages)),i.append(n.encodeUInt(this._maximum_pages))):(i.push(0),i.append(n.encodeUInt(this._initial_pages))),i.toUint8Array()};var h=function(){this._types=[],this._imports=[],this._functions=[],this._memory=[],this._exports=[],this._codes=[]};h.sectionCode={TYPE:1,IMPORT:2,FUNCTION:3,TABLE:4,MEMORY:5,GLOBAL:6,EXPORT:7,START:8,ELEMENT:9,CODE:10,DATA:11},h.prototype.setMemory=function(t){this._memory=[t]},h.prototype.exportFunction=function(t,i){i=i||t;var n=new a(i,r.function);n.setName(t),this._exports.push(n)},h.prototype.importFunction=function(t,i,n,e){var o=new c(n,e,r.function);o.setName(t),o.setType(i),this._imports.push(o)},h.prototype.addFunction=function(t,i,n){n.setName(t),n.setType(i),this._codes.push(n)},h.prototype.generateModule=function(){var i=[],e=this._types.length,r=function(t){return function(i){if(i.length!=t.length)return!1;for(var n=0;i.length>n;++n)if(i[n]!=t[n])return!1;return!0}},s=[],a=this._functions.length;this._imports.forEach(function(t){var i=t._functionname;if(i){if(s.findIndex(function(t){return t.name===i})!==-1)throw'Repeated function "'+i+'".';s.push({name:i,funcType:t._functiontype})}}),this._codes.forEach(function(t){var i=t._functionname;if(i){if(s.findIndex(function(t){return t.name===i})!==-1)throw'Repeated function "'+i+'".';s.push({name:i,funcType:t._functiontype})}}),s.forEach(function(t){i.findIndex(r(t.funcType))===-1&&i.push(t.funcType)});var c=this;i.forEach(function(t){c._types.push(t)});var c=this;this._codes.forEach(function(t){if(t._functiontype){var n=i.findIndex(r(t._functiontype))+e;if(n===-1)throw"Weird assembler bug.";c._functions.push(new o(n))}}),this._imports.forEach(function(t){var n=t._functiontype;if(n){var o=i.findIndex(r(n))+e;if(o===-1)throw"Weird assembler bug.";t._type=o}}),this._codes.forEach(function(t){var i=t._functionlinks;i.sort(function(t,i){return i.location-t.location}),i.forEach(function(i){var e=s.findIndex(function(t){return t.name===i.name})+a;if(e===-1)throw'Undeclared function "'+i.name+'".';t._data.insert_arr(i.location,n.encodeUInt(e))})}),this._exports.forEach(function(t){var i=t._functionname;if(i){var n=s.findIndex(function(t){return t.name===i})+a;if(n===-1)throw'Undeclared function "'+functionLink.name+'".';t._index=n}}),this._exports.forEach(function(t){t._functionname&&(t._functionname=void 0)}),this._imports.forEach(function(t){t._functionname&&(t._functionname=void 0,t._functiontype=void 0)}),this._codes.forEach(function(t){t._functionname&&(t._functionname=void 0,t._functiontype=void 0)});var p=new t,_=new Uint8Array(8);if(_[0]=0,_[1]=97,_[2]=115,_[3]=109,_[4]=1,_[5]=0,_[6]=0,_[7]=0,p.append(_),this._types.length>0){p.push(h.sectionCode.TYPE);var u=p.size();p.append(n.encodeUInt(this._types.length));for(var y=0;this._types.length>y;++y)p.append(this._types[y]);p.insert_arr(u,n.encodeUInt(p.size()-u))}if(this._imports.length>0){p.push(h.sectionCode.IMPORT);var u=p.size();p.append(n.encodeUInt(this._imports.length));for(var y=0;this._imports.length>y;++y)p.append(this._imports[y].toUint8Array());p.insert_arr(u,n.encodeUInt(p.size()-u))}if(this._functions.length>0){p.push(h.sectionCode.FUNCTION);var u=p.size();p.append(n.encodeUInt(this._functions.length));for(var y=0;this._functions.length>y;++y)p.append(this._functions[y].toUint8Array());p.insert_arr(u,n.encodeUInt(p.size()-u))}if(this._memory.length>0){p.push(h.sectionCode.MEMORY);var u=p.size();p.append(n.encodeUInt(this._memory.length));for(var y=0;this._memory.length>y;++y)p.append(this._memory[y].toUint8Array());p.insert_arr(u,n.encodeUInt(p.size()-u))}if(this._exports.length>0){p.push(h.sectionCode.EXPORT);var u=p.size();p.append(n.encodeUInt(this._exports.length));for(var y=0;this._exports.length>y;++y)p.append(this._exports[y].toUint8Array());p.insert_arr(u,n.encodeUInt(p.size()-u))}if(this._codes.length>0){p.push(h.sectionCode.CODE);var u=p.size();p.append(n.encodeUInt(this._codes.length));for(var y=0;this._codes.length>y;++y)p.append(this._codes[y].toUint8Array());p.insert_arr(u,n.encodeUInt(p.size()-u))}return p.toUint8Array()};