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++) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 if ((typeof val) == "string") val = val.charCodeAt(0); | 45 if ((typeof val) == "string") val = val.charCodeAt(0); |
46 view[kHeaderSize + i] = val | 0; | 46 view[kHeaderSize + i] = val | 0; |
47 } | 47 } |
48 return buffer; | 48 return buffer; |
49 } | 49 } |
50 | 50 |
51 var kDeclNoLocals = 0; | 51 var kDeclNoLocals = 0; |
52 | 52 |
53 // Section declaration constants | 53 // Section declaration constants |
54 var kDeclMemory = 0x00; | 54 var kDeclMemory = 0x00; |
55 var kDeclSignatures = 0x01; | 55 var kDeclTypes = 0x01; |
56 var kDeclFunctions = 0x02; | 56 var kDeclFunctions = 0x02; |
57 var kDeclGlobals = 0x03; | 57 var kDeclGlobals = 0x03; |
58 var kDeclDataSegments = 0x04; | 58 var kDeclData = 0x04; |
59 var kDeclFunctionTable = 0x05; | 59 var kDeclTable = 0x05; |
60 var kDeclEnd = 0x06; | 60 var kDeclEnd = 0x06; |
61 var kDeclStartFunction = 0x07; | 61 var kDeclStart = 0x07; |
62 var kDeclImportTable = 0x08; | 62 var kDeclImports = 0x08; |
63 var kDeclExportTable = 0x09; | 63 var kDeclExports = 0x09; |
64 var kDeclFunctionSignatures = 0x0a; | 64 var kDeclFunctions = 0x0a; |
65 var kDeclFunctionBodies = 0x0b; | 65 var kDeclCode = 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 var kWasmFunctionTypeForm = 0x40; |
73 | 73 |
74 var section_names = [ | 74 var section_names = [ |
75 "memory", "type", "old_function", "global", "data", | 75 "memory", "type", "old_function", "global", "data", |
76 "table", "end", "start", "import", "export", | 76 "table", "end", "start", "import", "export", |
77 "function", "code", "name"]; | 77 "function", "code", "name"]; |
78 | 78 |
79 // Function declaration flags | 79 // Function declaration flags |
80 var kDeclFunctionName = 0x01; | 80 var kDeclFunctionName = 0x01; |
81 var kDeclFunctionImport = 0x02; | 81 var kDeclFunctionImport = 0x02; |
82 var kDeclFunctionLocals = 0x04; | 82 var kDeclFunctionLocals = 0x04; |
83 var kDeclFunctionExport = 0x08; | 83 var kDeclFunctionExport = 0x08; |
84 | 84 |
85 // Local types | 85 // Local types |
86 var kAstStmt = 0; | 86 var kAstStmt = 0; |
87 var kAstI32 = 1; | 87 var kAstI32 = 1; |
88 var kAstI64 = 2; | 88 var kAstI64 = 2; |
89 var kAstF32 = 3; | 89 var kAstF32 = 3; |
90 var kAstF64 = 4; | 90 var kAstF64 = 4; |
91 | 91 |
92 // Useful signatures | 92 // Useful signatures |
93 var kSig_i = [0, 1, kAstI32]; | 93 var kSig_i = makeSig([], [kAstI32]); |
94 var kSig_d = [0, 1, kAstF64]; | 94 var kSig_d = makeSig([], [kAstF64]); |
95 var kSig_i_i = [1, kAstI32, 1, kAstI32]; | 95 var kSig_i_i = makeSig([kAstI32], [kAstI32]); |
96 var kSig_i_ii = [2, kAstI32, kAstI32, 1, kAstI32]; | 96 var kSig_i_ii = makeSig([kAstI32, kAstI32], [kAstI32]); |
97 var kSig_i_iii = [3, kAstI32, kAstI32, kAstI32, 1, kAstI32]; | 97 var kSig_i_iii = makeSig([kAstI32, kAstI32, kAstI32], [kAstI32]); |
98 var kSig_d_dd = [2, kAstF64, kAstF64, 1, kAstF64]; | 98 var kSig_d_dd = makeSig([kAstF64, kAstF64], [kAstF64]); |
99 var kSig_l_ll = [2, kAstI64, kAstI64, 1, kAstI64]; | 99 var kSig_l_ll = makeSig([kAstI64, kAstI64], [kAstI64]); |
100 var kSig_i_dd = [2, kAstF64, kAstF64, 1, kAstI32]; | 100 var kSig_i_dd = makeSig([kAstF64, kAstF64], [kAstI32]); |
101 var kSig_v_v = [0, 0]; | 101 var kSig_v_v = makeSig([], []); |
102 var kSig_i_v = [0, 1, kAstI32]; | 102 var kSig_i_v = makeSig([], [kAstI32]); |
103 | 103 |
104 function makeSig_v_xx(x) { | 104 function makeSig(params, results) { |
105 return [2, x, x, 0]; | 105 return {params: params, results: results}; |
106 } | 106 } |
107 | 107 |
108 function makeSig_v_x(x) { | 108 function makeSig_v_x(x) { |
109 return [1, x, 0]; | 109 return makeSig([x], []); |
| 110 } |
| 111 |
| 112 function makeSig_v_xx(x) { |
| 113 return makeSig([x, x], []); |
| 114 } |
| 115 |
| 116 function makeSig_r_v(r) { |
| 117 return makeSig([], [r]); |
| 118 } |
| 119 |
| 120 function makeSig_r_x(r, x) { |
| 121 return makeSig([x], [r]); |
110 } | 122 } |
111 | 123 |
112 function makeSig_r_xx(r, x) { | 124 function makeSig_r_xx(r, x) { |
113 return [2, x, x, 1, r]; | 125 return makeSig([x, x], [r]); |
114 } | |
115 | |
116 function makeSig_r_x(r, x) { | |
117 return [1, x, 1, r]; | |
118 } | 126 } |
119 | 127 |
120 // Opcodes | 128 // Opcodes |
121 var kExprNop = 0x00; | 129 var kExprNop = 0x00; |
122 var kExprBlock = 0x01; | 130 var kExprBlock = 0x01; |
123 var kExprLoop = 0x02; | 131 var kExprLoop = 0x02; |
124 var kExprIf = 0x03; | 132 var kExprIf = 0x03; |
125 var kExprElse = 0x04; | 133 var kExprElse = 0x04; |
126 var kExprSelect = 0x05; | 134 var kExprSelect = 0x05; |
127 var kExprBr = 0x06; | 135 var kExprBr = 0x06; |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 } | 333 } |
326 threwException = false; | 334 threwException = false; |
327 } catch (e) { | 335 } catch (e) { |
328 assertEquals("object", typeof e); | 336 assertEquals("object", typeof e); |
329 assertEquals(kTrapMsgs[trap], e.message); | 337 assertEquals(kTrapMsgs[trap], e.message); |
330 // Success. | 338 // Success. |
331 return; | 339 return; |
332 } | 340 } |
333 throw new MjsUnitAssertionError("Did not trap, expected: " + kTrapMsgs[trap]
); | 341 throw new MjsUnitAssertionError("Did not trap, expected: " + kTrapMsgs[trap]
); |
334 } | 342 } |
OLD | NEW |