Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(462)

Side by Side Diff: test/mjsunit/wasm/indirect-calls.js

Issue 2403093002: [wasm] Canonicalize function signature indices for matching in indirect calls. (Closed)
Patch Set: Address review comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/wasm/wasm-run-utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 load("test/mjsunit/wasm/wasm-constants.js"); 7 load("test/mjsunit/wasm/wasm-constants.js");
8 load("test/mjsunit/wasm/wasm-module-builder.js"); 8 load("test/mjsunit/wasm/wasm-module-builder.js");
9 9
10 var module = (function () { 10 var module = (function () {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 assertTraps(kTrapFuncSigMismatch, "module.exports.main(2, 12, 33)"); 48 assertTraps(kTrapFuncSigMismatch, "module.exports.main(2, 12, 33)");
49 assertTraps(kTrapFuncInvalid, "module.exports.main(3, 12, 33)"); 49 assertTraps(kTrapFuncInvalid, "module.exports.main(3, 12, 33)");
50 50
51 51
52 module = (function () { 52 module = (function () {
53 var builder = new WasmModuleBuilder(); 53 var builder = new WasmModuleBuilder();
54 54
55 var sig_i_ii = builder.addType(kSig_i_ii); 55 var sig_i_ii = builder.addType(kSig_i_ii);
56 var sig_i_i = builder.addType(kSig_i_i); 56 var sig_i_i = builder.addType(kSig_i_i);
57 builder.addImport("mul", sig_i_ii); 57 var mul = builder.addImport("mul", sig_i_ii);
58 builder.addFunction("add", sig_i_ii) 58 var add = builder.addFunction("add", sig_i_ii)
59 .addBody([ 59 .addBody([
60 kExprGetLocal, 0, // -- 60 kExprGetLocal, 0, // --
61 kExprGetLocal, 1, // -- 61 kExprGetLocal, 1, // --
62 kExprI32Add // -- 62 kExprI32Add // --
63 ]); 63 ]);
64 builder.addFunction("popcnt", sig_i_i) 64 var popcnt = builder.addFunction("popcnt", sig_i_i)
65 .addBody([ 65 .addBody([
66 kExprGetLocal, 0, // -- 66 kExprGetLocal, 0, // --
67 kExprI32Popcnt // -- 67 kExprI32Popcnt // --
68 ]); 68 ]);
69 builder.addFunction("main", kSig_i_iii) 69 var main = builder.addFunction("main", kSig_i_iii)
70 .addBody([ 70 .addBody([
71 kExprGetLocal, 1, 71 kExprGetLocal, 1,
72 kExprGetLocal, 2, 72 kExprGetLocal, 2,
73 kExprGetLocal, 0, 73 kExprGetLocal, 0,
74 kExprCallIndirect, sig_i_ii 74 kExprCallIndirect, sig_i_ii
75 ]) 75 ])
76 .exportFunc() 76 .exportFunc()
77 builder.appendToTable([0, 1, 2, 3]); 77 builder.appendToTable([mul.index, add.index, popcnt.index, main.index]);
78 78
79 return builder.instantiate({mul: function(a, b) { return a * b | 0; }}); 79 return builder.instantiate({mul: function(a, b) { return a * b | 0; }});
80 })(); 80 })();
81 81
82 assertEquals(-6, module.exports.main(0, -2, 3)); 82 assertEquals(-6, module.exports.main(0, -2, 3));
83 assertEquals(99, module.exports.main(1, 22, 77)); 83 assertEquals(99, module.exports.main(1, 22, 77));
84 assertTraps(kTrapFuncSigMismatch, "module.exports.main(2, 12, 33)"); 84 assertTraps(kTrapFuncSigMismatch, "module.exports.main(2, 12, 33)");
85 assertTraps(kTrapFuncSigMismatch, "module.exports.main(3, 12, 33)"); 85 assertTraps(kTrapFuncSigMismatch, "module.exports.main(3, 12, 33)");
86 assertTraps(kTrapFuncInvalid, "module.exports.main(4, 12, 33)"); 86 assertTraps(kTrapFuncInvalid, "module.exports.main(4, 12, 33)");
87
88
89 module = (function () {
90 var builder = new WasmModuleBuilder();
91
92 var mul = builder.addFunction("mul", kSig_i_ii)
93 .addBody([
94 kExprGetLocal, 0, // --
95 kExprGetLocal, 1, // --
96 kExprI32Mul // --
97 ]);
98 var add = builder.addFunction("add", kSig_i_ii)
99 .addBody([
100 kExprGetLocal, 0, // --
101 kExprGetLocal, 1, // --
102 kExprI32Add // --
103 ]);
104 var sub = builder.addFunction("sub", kSig_i_ii)
105 .addBody([
106 kExprGetLocal, 0, // --
107 kExprGetLocal, 1, // --
108 kExprI32Sub // --
109 ]);
110 builder.addFunction("main", kSig_i_ii)
111 .addBody([
112 kExprI32Const, 33, // --
113 kExprGetLocal, 0, // --
114 kExprGetLocal, 1, // --
115 kExprCallIndirect, 0]) // --
116 .exportAs("main");
117
118 builder.appendToTable([mul.index, add.index, sub.index]);
119
120 return builder.instantiate();
121 })();
122
123 assertEquals(33, module.exports.main(1, 0));
124 assertEquals(66, module.exports.main(2, 0));
125 assertEquals(34, module.exports.main(1, 1));
126 assertEquals(35, module.exports.main(2, 1));
127 assertEquals(32, module.exports.main(1, 2));
128 assertEquals(31, module.exports.main(2, 2));
129 assertTraps(kTrapFuncInvalid, "module.exports.main(12, 3)");
OLDNEW
« no previous file with comments | « test/cctest/wasm/wasm-run-utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698