diff --git a/packages/helper-wasm-bytecode/src/index.js b/packages/helper-wasm-bytecode/src/index.js index 76536f6ec..6d91ee69a 100644 --- a/packages/helper-wasm-bytecode/src/index.js +++ b/packages/helper-wasm-bytecode/src/index.js @@ -348,6 +348,17 @@ const symbolsByByte = { 0xfc_10: createSymbol("table.size", 1), 0xfc_11: createSymbol("table.fill", 1), + // https://webassembly.github.io/spec/core/binary/instructions.html#numeric-instructions + // saturating truncation instructions + 0xfc_00: createSymbol("i32.trunc_sat_f32_s"), + 0xfc_01: createSymbol("i32.trunc_sat_f32_u"), + 0xfc_02: createSymbol("i32.trunc_sat_f64_s"), + 0xfc_03: createSymbol("i32.trunc_sat_f64_u"), + 0xfc_04: createSymbol("i64.trunc_sat_f32_s"), + 0xfc_05: createSymbol("i64.trunc_sat_f32_u"), + 0xfc_06: createSymbol("i64.trunc_sat_f64_s"), + 0xfc_07: createSymbol("i64.trunc_sat_f64_u"), + // Atomic Memory Instructions 0xfe00: createSymbol("memory.atomic.notify", 1), 0xfe01: createSymbol("memory.atomic.wait32", 1), diff --git a/packages/wasm-parser/test/fixtures/conversions/actual.wasm b/packages/wasm-parser/test/fixtures/conversions/actual.wasm new file mode 100644 index 000000000..dd697c3ba Binary files /dev/null and b/packages/wasm-parser/test/fixtures/conversions/actual.wasm differ diff --git a/packages/wasm-parser/test/fixtures/conversions/expected b/packages/wasm-parser/test/fixtures/conversions/expected new file mode 100644 index 000000000..4d15c7412 --- /dev/null +++ b/packages/wasm-parser/test/fixtures/conversions/expected @@ -0,0 +1,487 @@ +0x0: 0x0 0x61 0x73 0x6d ; wasm magic header +0x4: 0x1 0x0 0x0 0x0 ; wasm version +; section Type +0xa: 0x1 ; section code +0xa: 0x3d ; section size +0xb: 0xc ; num types +; type 0 +0xc: 0x60 ; func +0xd: 0x1 ; number +0xe: 0x7f ; i32 +0xf: 0x1 ; number +0x10: 0x7e ; i64 +; type 1 +0x11: 0x60 ; func +0x12: 0x1 ; number +0x13: 0x7e ; i64 +0x14: 0x1 ; number +0x15: 0x7f ; i32 +; type 2 +0x16: 0x60 ; func +0x17: 0x1 ; number +0x18: 0x7d ; f32 +0x19: 0x1 ; number +0x1a: 0x7f ; i32 +; type 3 +0x1b: 0x60 ; func +0x1c: 0x1 ; number +0x1d: 0x7c ; f64 +0x1e: 0x1 ; number +0x1f: 0x7f ; i32 +; type 4 +0x20: 0x60 ; func +0x21: 0x1 ; number +0x22: 0x7d ; f32 +0x23: 0x1 ; number +0x24: 0x7e ; i64 +; type 5 +0x25: 0x60 ; func +0x26: 0x1 ; number +0x27: 0x7c ; f64 +0x28: 0x1 ; number +0x29: 0x7e ; i64 +; type 6 +0x2a: 0x60 ; func +0x2b: 0x1 ; number +0x2c: 0x7f ; i32 +0x2d: 0x1 ; number +0x2e: 0x7d ; f32 +; type 7 +0x2f: 0x60 ; func +0x30: 0x1 ; number +0x31: 0x7e ; i64 +0x32: 0x1 ; number +0x33: 0x7d ; f32 +; type 8 +0x34: 0x60 ; func +0x35: 0x1 ; number +0x36: 0x7f ; i32 +0x37: 0x1 ; number +0x38: 0x7c ; f64 +; type 9 +0x39: 0x60 ; func +0x3a: 0x1 ; number +0x3b: 0x7e ; i64 +0x3c: 0x1 ; number +0x3d: 0x7c ; f64 +; type 10 +0x3e: 0x60 ; func +0x3f: 0x1 ; number +0x40: 0x7d ; f32 +0x41: 0x1 ; number +0x42: 0x7c ; f64 +; type 11 +0x43: 0x60 ; func +0x44: 0x1 ; number +0x45: 0x7c ; f64 +0x46: 0x1 ; number +0x47: 0x7d ; f32 +; section Function +0x49: 0x3 ; section code +0x49: 0x22 ; section size +0x4a: 0x21 ; num funcs +0x4b: 0x0 ; type index +0x4c: 0x0 ; type index +0x4d: 0x1 ; type index +0x4e: 0x2 ; type index +0x4f: 0x2 ; type index +0x50: 0x3 ; type index +0x51: 0x3 ; type index +0x52: 0x4 ; type index +0x53: 0x4 ; type index +0x54: 0x5 ; type index +0x55: 0x5 ; type index +0x56: 0x2 ; type index +0x57: 0x2 ; type index +0x58: 0x3 ; type index +0x59: 0x3 ; type index +0x5a: 0x4 ; type index +0x5b: 0x4 ; type index +0x5c: 0x5 ; type index +0x5d: 0x5 ; type index +0x5e: 0x6 ; type index +0x5f: 0x7 ; type index +0x60: 0x8 ; type index +0x61: 0x9 ; type index +0x62: 0x6 ; type index +0x63: 0x7 ; type index +0x64: 0x8 ; type index +0x65: 0x9 ; type index +0x66: 0xa ; type index +0x67: 0xb ; type index +0x68: 0x6 ; type index +0x69: 0x9 ; type index +0x6a: 0x2 ; type index +0x6b: 0x5 ; type index +; section Export +0x6e: 0x7 ; section code +0x6e: 0x291 ; section size +0x6f: 0x21 ; num exports +0x6f: 0x10 ; string length +0x80: ; export name (i64.extend_i32_s) +0x81: 0x0 ; export kind +0x82: 0x0 ; export index +0x82: 0x10 ; string length +0x93: ; export name (i64.extend_i32_u) +0x94: 0x0 ; export kind +0x95: 0x1 ; export index +0x95: 0xc ; string length +0xa2: ; export name (i32.wrap_i64) +0xa3: 0x0 ; export kind +0xa4: 0x2 ; export index +0xa4: 0xf ; string length +0xb4: ; export name (i32.trunc_f32_s) +0xb5: 0x0 ; export kind +0xb6: 0x3 ; export index +0xb6: 0xf ; string length +0xc6: ; export name (i32.trunc_f32_u) +0xc7: 0x0 ; export kind +0xc8: 0x4 ; export index +0xc8: 0xf ; string length +0xd8: ; export name (i32.trunc_f64_s) +0xd9: 0x0 ; export kind +0xda: 0x5 ; export index +0xda: 0xf ; string length +0xea: ; export name (i32.trunc_f64_u) +0xeb: 0x0 ; export kind +0xec: 0x6 ; export index +0xec: 0xf ; string length +0xfc: ; export name (i64.trunc_f32_s) +0xfd: 0x0 ; export kind +0xfe: 0x7 ; export index +0xfe: 0xf ; string length +0x10e: ; export name (i64.trunc_f32_u) +0x10f: 0x0 ; export kind +0x110: 0x8 ; export index +0x110: 0xf ; string length +0x120: ; export name (i64.trunc_f64_s) +0x121: 0x0 ; export kind +0x122: 0x9 ; export index +0x122: 0xf ; string length +0x132: ; export name (i64.trunc_f64_u) +0x133: 0x0 ; export kind +0x134: 0xa ; export index +0x134: 0x13 ; string length +0x148: ; export name (i32.trunc_sat_f32_s) +0x149: 0x0 ; export kind +0x14a: 0xb ; export index +0x14a: 0x13 ; string length +0x15e: ; export name (i32.trunc_sat_f32_u) +0x15f: 0x0 ; export kind +0x160: 0xc ; export index +0x160: 0x13 ; string length +0x174: ; export name (i32.trunc_sat_f64_s) +0x175: 0x0 ; export kind +0x176: 0xd ; export index +0x176: 0x13 ; string length +0x18a: ; export name (i32.trunc_sat_f64_u) +0x18b: 0x0 ; export kind +0x18c: 0xe ; export index +0x18c: 0x13 ; string length +0x1a0: ; export name (i64.trunc_sat_f32_s) +0x1a1: 0x0 ; export kind +0x1a2: 0xf ; export index +0x1a2: 0x13 ; string length +0x1b6: ; export name (i64.trunc_sat_f32_u) +0x1b7: 0x0 ; export kind +0x1b8: 0x10 ; export index +0x1b8: 0x13 ; string length +0x1cc: ; export name (i64.trunc_sat_f64_s) +0x1cd: 0x0 ; export kind +0x1ce: 0x11 ; export index +0x1ce: 0x13 ; string length +0x1e2: ; export name (i64.trunc_sat_f64_u) +0x1e3: 0x0 ; export kind +0x1e4: 0x12 ; export index +0x1e4: 0x11 ; string length +0x1f6: ; export name (f32.convert_i32_s) +0x1f7: 0x0 ; export kind +0x1f8: 0x13 ; export index +0x1f8: 0x11 ; string length +0x20a: ; export name (f32.convert_i64_s) +0x20b: 0x0 ; export kind +0x20c: 0x14 ; export index +0x20c: 0x11 ; string length +0x21e: ; export name (f64.convert_i32_s) +0x21f: 0x0 ; export kind +0x220: 0x15 ; export index +0x220: 0x11 ; string length +0x232: ; export name (f64.convert_i64_s) +0x233: 0x0 ; export kind +0x234: 0x16 ; export index +0x234: 0x11 ; string length +0x246: ; export name (f32.convert_i32_u) +0x247: 0x0 ; export kind +0x248: 0x17 ; export index +0x248: 0x11 ; string length +0x25a: ; export name (f32.convert_i64_u) +0x25b: 0x0 ; export kind +0x25c: 0x18 ; export index +0x25c: 0x11 ; string length +0x26e: ; export name (f64.convert_i32_u) +0x26f: 0x0 ; export kind +0x270: 0x19 ; export index +0x270: 0x11 ; string length +0x282: ; export name (f64.convert_i64_u) +0x283: 0x0 ; export kind +0x284: 0x1a ; export index +0x284: 0xf ; string length +0x294: ; export name (f64.promote_f32) +0x295: 0x0 ; export kind +0x296: 0x1b ; export index +0x296: 0xe ; string length +0x2a5: ; export name (f32.demote_f64) +0x2a6: 0x0 ; export kind +0x2a7: 0x1c ; export index +0x2a7: 0x13 ; string length +0x2bb: ; export name (f32.reinterpret_i32) +0x2bc: 0x0 ; export kind +0x2bd: 0x1d ; export index +0x2bd: 0x13 ; string length +0x2d1: ; export name (f64.reinterpret_i64) +0x2d2: 0x0 ; export kind +0x2d3: 0x1e ; export index +0x2d3: 0x13 ; string length +0x2e7: ; export name (i32.reinterpret_f32) +0x2e8: 0x0 ; export kind +0x2e9: 0x1f ; export index +0x2e9: 0x13 ; string length +0x2fd: ; export name (i64.reinterpret_f64) +0x2fe: 0x0 ; export kind +0x2ff: 0x20 ; export index +; section Code +0x302: 0xa ; section code +0x302: 0xcf ; section size +0x303: 0x21 ; number functions +; function body 0 +0x304: 0x5 ; function body size +0x305: 0x0 ; num locals +0x306: 0x20 ; get_local +0x307: 0x0 ; argument 0 +0x308: 0xac ; i64.extend_s/i32 +0x309: 0xb ; end +; function body 1 +0x30a: 0x5 ; function body size +0x30b: 0x0 ; num locals +0x30c: 0x20 ; get_local +0x30d: 0x0 ; argument 0 +0x30e: 0xad ; i64.extend_u/i32 +0x30f: 0xb ; end +; function body 2 +0x310: 0x5 ; function body size +0x311: 0x0 ; num locals +0x312: 0x20 ; get_local +0x313: 0x0 ; argument 0 +0x314: 0xa7 ; i32.wrap/i64 +0x315: 0xb ; end +; function body 3 +0x316: 0x5 ; function body size +0x317: 0x0 ; num locals +0x318: 0x20 ; get_local +0x319: 0x0 ; argument 0 +0x31a: 0xa8 ; i32.trunc_s/f32 +0x31b: 0xb ; end +; function body 4 +0x31c: 0x5 ; function body size +0x31d: 0x0 ; num locals +0x31e: 0x20 ; get_local +0x31f: 0x0 ; argument 0 +0x320: 0xa9 ; i32.trunc_u/f32 +0x321: 0xb ; end +; function body 5 +0x322: 0x5 ; function body size +0x323: 0x0 ; num locals +0x324: 0x20 ; get_local +0x325: 0x0 ; argument 0 +0x326: 0xaa ; i32.trunc_s/f64 +0x327: 0xb ; end +; function body 6 +0x328: 0x5 ; function body size +0x329: 0x0 ; num locals +0x32a: 0x20 ; get_local +0x32b: 0x0 ; argument 0 +0x32c: 0xab ; i32.trunc_u/f64 +0x32d: 0xb ; end +; function body 7 +0x32e: 0x5 ; function body size +0x32f: 0x0 ; num locals +0x330: 0x20 ; get_local +0x331: 0x0 ; argument 0 +0x332: 0xae ; i64.trunc_s/f32 +0x333: 0xb ; end +; function body 8 +0x334: 0x5 ; function body size +0x335: 0x0 ; num locals +0x336: 0x20 ; get_local +0x337: 0x0 ; argument 0 +0x338: 0xaf ; i64.trunc_u/f32 +0x339: 0xb ; end +; function body 9 +0x33a: 0x5 ; function body size +0x33b: 0x0 ; num locals +0x33c: 0x20 ; get_local +0x33d: 0x0 ; argument 0 +0x33e: 0xb0 ; i64.trunc_s/f64 +0x33f: 0xb ; end +; function body 10 +0x340: 0x5 ; function body size +0x341: 0x0 ; num locals +0x342: 0x20 ; get_local +0x343: 0x0 ; argument 0 +0x344: 0xb1 ; i64.trunc_u/f64 +0x345: 0xb ; end +; function body 11 +0x346: 0x6 ; function body size +0x347: 0x0 ; num locals +0x348: 0x20 ; get_local +0x349: 0x0 ; argument 0 +0x34b: 0xfc00 ; i32.trunc_sat_f32_s +0x34c: 0xb ; end +; function body 12 +0x34d: 0x6 ; function body size +0x34e: 0x0 ; num locals +0x34f: 0x20 ; get_local +0x350: 0x0 ; argument 0 +0x352: 0xfc01 ; i32.trunc_sat_f32_u +0x353: 0xb ; end +; function body 13 +0x354: 0x6 ; function body size +0x355: 0x0 ; num locals +0x356: 0x20 ; get_local +0x357: 0x0 ; argument 0 +0x359: 0xfc02 ; i32.trunc_sat_f64_s +0x35a: 0xb ; end +; function body 14 +0x35b: 0x6 ; function body size +0x35c: 0x0 ; num locals +0x35d: 0x20 ; get_local +0x35e: 0x0 ; argument 0 +0x360: 0xfc03 ; i32.trunc_sat_f64_u +0x361: 0xb ; end +; function body 15 +0x362: 0x6 ; function body size +0x363: 0x0 ; num locals +0x364: 0x20 ; get_local +0x365: 0x0 ; argument 0 +0x367: 0xfc04 ; i64.trunc_sat_f32_s +0x368: 0xb ; end +; function body 16 +0x369: 0x6 ; function body size +0x36a: 0x0 ; num locals +0x36b: 0x20 ; get_local +0x36c: 0x0 ; argument 0 +0x36e: 0xfc05 ; i64.trunc_sat_f32_u +0x36f: 0xb ; end +; function body 17 +0x370: 0x6 ; function body size +0x371: 0x0 ; num locals +0x372: 0x20 ; get_local +0x373: 0x0 ; argument 0 +0x375: 0xfc06 ; i64.trunc_sat_f64_s +0x376: 0xb ; end +; function body 18 +0x377: 0x6 ; function body size +0x378: 0x0 ; num locals +0x379: 0x20 ; get_local +0x37a: 0x0 ; argument 0 +0x37c: 0xfc07 ; i64.trunc_sat_f64_u +0x37d: 0xb ; end +; function body 19 +0x37e: 0x5 ; function body size +0x37f: 0x0 ; num locals +0x380: 0x20 ; get_local +0x381: 0x0 ; argument 0 +0x382: 0xb2 ; f32.convert_s/i32 +0x383: 0xb ; end +; function body 20 +0x384: 0x5 ; function body size +0x385: 0x0 ; num locals +0x386: 0x20 ; get_local +0x387: 0x0 ; argument 0 +0x388: 0xb4 ; f32.convert_s/i64 +0x389: 0xb ; end +; function body 21 +0x38a: 0x5 ; function body size +0x38b: 0x0 ; num locals +0x38c: 0x20 ; get_local +0x38d: 0x0 ; argument 0 +0x38e: 0xb7 ; f64.convert_s/i32 +0x38f: 0xb ; end +; function body 22 +0x390: 0x5 ; function body size +0x391: 0x0 ; num locals +0x392: 0x20 ; get_local +0x393: 0x0 ; argument 0 +0x394: 0xb9 ; f64.convert_s/i64 +0x395: 0xb ; end +; function body 23 +0x396: 0x5 ; function body size +0x397: 0x0 ; num locals +0x398: 0x20 ; get_local +0x399: 0x0 ; argument 0 +0x39a: 0xb3 ; f32.convert_u/i32 +0x39b: 0xb ; end +; function body 24 +0x39c: 0x5 ; function body size +0x39d: 0x0 ; num locals +0x39e: 0x20 ; get_local +0x39f: 0x0 ; argument 0 +0x3a0: 0xb5 ; f32.convert_u/i64 +0x3a1: 0xb ; end +; function body 25 +0x3a2: 0x5 ; function body size +0x3a3: 0x0 ; num locals +0x3a4: 0x20 ; get_local +0x3a5: 0x0 ; argument 0 +0x3a6: 0xb8 ; f64.convert_u/i32 +0x3a7: 0xb ; end +; function body 26 +0x3a8: 0x5 ; function body size +0x3a9: 0x0 ; num locals +0x3aa: 0x20 ; get_local +0x3ab: 0x0 ; argument 0 +0x3ac: 0xba ; f64.convert_u/i64 +0x3ad: 0xb ; end +; function body 27 +0x3ae: 0x5 ; function body size +0x3af: 0x0 ; num locals +0x3b0: 0x20 ; get_local +0x3b1: 0x0 ; argument 0 +0x3b2: 0xbb ; f64.promote/f32 +0x3b3: 0xb ; end +; function body 28 +0x3b4: 0x5 ; function body size +0x3b5: 0x0 ; num locals +0x3b6: 0x20 ; get_local +0x3b7: 0x0 ; argument 0 +0x3b8: 0xb6 ; f32.demote/f64 +0x3b9: 0xb ; end +; function body 29 +0x3ba: 0x5 ; function body size +0x3bb: 0x0 ; num locals +0x3bc: 0x20 ; get_local +0x3bd: 0x0 ; argument 0 +0x3be: 0xbe ; f32.reinterpret/i32 +0x3bf: 0xb ; end +; function body 30 +0x3c0: 0x5 ; function body size +0x3c1: 0x0 ; num locals +0x3c2: 0x20 ; get_local +0x3c3: 0x0 ; argument 0 +0x3c4: 0xbf ; f64.reinterpret/i64 +0x3c5: 0xb ; end +; function body 31 +0x3c6: 0x5 ; function body size +0x3c7: 0x0 ; num locals +0x3c8: 0x20 ; get_local +0x3c9: 0x0 ; argument 0 +0x3ca: 0xbc ; i32.reinterpret/f32 +0x3cb: 0xb ; end +; function body 32 +0x3cc: 0x5 ; function body size +0x3cd: 0x0 ; num locals +0x3ce: 0x20 ; get_local +0x3cf: 0x0 ; argument 0 +0x3d0: 0xbd ; i64.reinterpret/f64 +0x3d1: 0xb ; end +; end of program