OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Flags: --expose-wasm | 5 // Flags: --expose-wasm |
6 | 6 |
7 function bytes() { | 7 function bytes() { |
8 var buffer = new ArrayBuffer(arguments.length); | 8 var buffer = new ArrayBuffer(arguments.length); |
9 var view = new Uint8Array(buffer); | 9 var view = new Uint8Array(buffer); |
10 for (var i = 0; i < arguments.length; i++) { | 10 for (var i = 0; i < arguments.length; i++) { |
11 var val = arguments[i]; | 11 var val = arguments[i]; |
12 if ((typeof val) == "string") val = val.charCodeAt(0); | 12 if ((typeof val) == "string") val = val.charCodeAt(0); |
13 view[i] = val | 0; | 13 view[i] = val | 0; |
14 } | 14 } |
15 return buffer; | 15 return buffer; |
16 } | 16 } |
17 | 17 |
18 // Header declaration constants | 18 // Header declaration constants |
19 var kWasmH0 = 0; | 19 var kWasmH0 = 0; |
20 var kWasmH1 = 0x61; | 20 var kWasmH1 = 0x61; |
21 var kWasmH2 = 0x73; | 21 var kWasmH2 = 0x73; |
22 var kWasmH3 = 0x6d; | 22 var kWasmH3 = 0x6d; |
23 | 23 |
24 var kWasmV0 = 10; | 24 var kWasmV0 = 11; |
25 var kWasmV1 = 0; | 25 var kWasmV1 = 0; |
26 var kWasmV2 = 0; | 26 var kWasmV2 = 0; |
27 var kWasmV3 = 0; | 27 var kWasmV3 = 0; |
28 | 28 |
29 var kHeaderSize = 8; | 29 var kHeaderSize = 8; |
30 var kPageSize = 65536; | 30 var kPageSize = 65536; |
31 | 31 |
32 function bytesWithHeader() { | 32 function bytesWithHeader() { |
33 var buffer = new ArrayBuffer(kHeaderSize + arguments.length); | 33 var buffer = new ArrayBuffer(kHeaderSize + arguments.length); |
34 var view = new Uint8Array(buffer); | 34 var view = new Uint8Array(buffer); |
(...skipping 27 matching lines...) Expand all Loading... |
62 var kDeclImportTable = 0x08; | 62 var kDeclImportTable = 0x08; |
63 var kDeclExportTable = 0x09; | 63 var kDeclExportTable = 0x09; |
64 var kDeclFunctionSignatures = 0x0a; | 64 var kDeclFunctionSignatures = 0x0a; |
65 var kDeclFunctionBodies = 0x0b; | 65 var kDeclFunctionBodies = 0x0b; |
66 var kDeclNames = 0x0c; | 66 var kDeclNames = 0x0c; |
67 | 67 |
68 var kArity0 = 0; | 68 var kArity0 = 0; |
69 var kArity1 = 1; | 69 var kArity1 = 1; |
70 var kArity2 = 2; | 70 var kArity2 = 2; |
71 var kArity3 = 3; | 71 var kArity3 = 3; |
| 72 var kWasmFunctionTypeForm = 0x40; |
72 | 73 |
73 var section_names = [ | 74 var section_names = [ |
74 "memory", "signatures", "functions", "globals", "data_segments", | 75 "memory", "type", "old_function", "global", "data", |
75 "function_table", "end", "start_function", "import_table", "export_table", | 76 "table", "end", "start", "import", "export", |
76 "function_signatures", "function_bodies", "names"]; | 77 "function", "code", "name"]; |
77 | 78 |
78 // Function declaration flags | 79 // Function declaration flags |
79 var kDeclFunctionName = 0x01; | 80 var kDeclFunctionName = 0x01; |
80 var kDeclFunctionImport = 0x02; | 81 var kDeclFunctionImport = 0x02; |
81 var kDeclFunctionLocals = 0x04; | 82 var kDeclFunctionLocals = 0x04; |
82 var kDeclFunctionExport = 0x08; | 83 var kDeclFunctionExport = 0x08; |
83 | 84 |
84 // Local types | 85 // Local types |
85 var kAstStmt = 0; | 86 var kAstStmt = 0; |
86 var kAstI32 = 1; | 87 var kAstI32 = 1; |
87 var kAstI64 = 2; | 88 var kAstI64 = 2; |
88 var kAstF32 = 3; | 89 var kAstF32 = 3; |
89 var kAstF64 = 4; | 90 var kAstF64 = 4; |
90 | 91 |
| 92 // Useful signatures |
| 93 var kSig_i = [0, 1, kAstI32]; |
| 94 var kSig_d = [0, 1, kAstF64]; |
| 95 var kSig_i_i = [1, kAstI32, 1, kAstI32]; |
| 96 var kSig_i_ii = [2, kAstI32, kAstI32, 1, kAstI32]; |
| 97 var kSig_i_iii = [3, kAstI32, kAstI32, kAstI32, 1, kAstI32]; |
| 98 var kSig_d_dd = [2, kAstF64, kAstF64, 1, kAstF64]; |
| 99 var kSig_l_ll = [2, kAstI64, kAstI64, 1, kAstI64]; |
| 100 var kSig_i_dd = [2, kAstF64, kAstF64, 1, kAstI32]; |
| 101 var kSig_v_v = [0, 0]; |
| 102 |
| 103 function makeSig_v_xx(x) { |
| 104 return [2, x, x, 0]; |
| 105 } |
| 106 |
| 107 function makeSig_v_x(x) { |
| 108 return [1, x, 0]; |
| 109 } |
| 110 |
| 111 function makeSig_r_xx(r, x) { |
| 112 return [2, x, x, 1, r]; |
| 113 } |
| 114 |
| 115 function makeSig_r_x(r, x) { |
| 116 return [1, x, 1, r]; |
| 117 } |
| 118 |
91 // Opcodes | 119 // Opcodes |
92 var kExprNop = 0x00; | 120 var kExprNop = 0x00; |
93 var kExprBlock = 0x01; | 121 var kExprBlock = 0x01; |
94 var kExprLoop = 0x02; | 122 var kExprLoop = 0x02; |
95 var kExprIf = 0x03; | 123 var kExprIf = 0x03; |
96 var kExprElse = 0x04; | 124 var kExprElse = 0x04; |
97 var kExprSelect = 0x05; | 125 var kExprSelect = 0x05; |
98 var kExprBr = 0x06; | 126 var kExprBr = 0x06; |
99 var kExprBrIf = 0x07; | 127 var kExprBrIf = 0x07; |
100 var kExprBrTable = 0x08; | 128 var kExprBrTable = 0x08; |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 } | 324 } |
297 threwException = false; | 325 threwException = false; |
298 } catch (e) { | 326 } catch (e) { |
299 assertEquals("object", typeof e); | 327 assertEquals("object", typeof e); |
300 assertEquals(kTrapMsgs[trap], e.message); | 328 assertEquals(kTrapMsgs[trap], e.message); |
301 // Success. | 329 // Success. |
302 return; | 330 return; |
303 } | 331 } |
304 throw new MjsUnitAssertionError("Did not trap, expected: " + kTrapMsgs[trap]
); | 332 throw new MjsUnitAssertionError("Did not trap, expected: " + kTrapMsgs[trap]
); |
305 } | 333 } |
OLD | NEW |