Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Flags: --expose-wasm --allow-natives-syntax | |
| 6 | |
| 7 load("test/mjsunit/wasm/wasm-constants.js"); | |
| 8 load("test/mjsunit/wasm/wasm-module-builder.js"); | |
| 9 | |
| 10 var expect_elison = 0; | |
| 11 var expect_no_elison = 1; | |
| 12 // function calls stack: first_export -> first_func -> first_import -> | |
| 13 // second_export -> second_import | |
| 14 // In this case, first_import and second_export have same signature, | |
| 15 // So that wrappers will be removed | |
| 16 (function TestWasmWrapperElision() { | |
| 17 var imported = function (a) { | |
| 18 return a; | |
| 19 }; | |
| 20 | |
| 21 var second_module = new WasmModuleBuilder(); | |
| 22 var sig_index = second_module.addType(kSig_i_i); | |
| 23 second_module.addImportWithModule("import_module_2", "import_name_2", sig_in dex); | |
|
Mircea Trofin
2016/08/04 18:21:08
check 80 char limit
Chen
2016/08/04 20:05:07
Done.
| |
| 24 second_module.addFunction("second_export", sig_index) | |
| 25 .addBody([ | |
| 26 kExprGetLocal, 0, | |
| 27 kExprCallImport, kArity1, 0, | |
| 28 kExprReturn, kArity1 | |
| 29 ]) | |
| 30 .exportFunc(); | |
| 31 | |
| 32 var first_module = new WasmModuleBuilder(); | |
| 33 var sig_index = first_module.addType(kSig_i_i); | |
| 34 first_module.addImportWithModule("import_module_1", "import_name_1", sig_ind ex); | |
| 35 first_module.addFunction("first_export", sig_index) | |
| 36 .addBody([ | |
| 37 kExprGetLocal, 0, | |
| 38 kExprCallFunction, kArity1, 1, | |
| 39 kExprReturn, kArity1 | |
| 40 ]) | |
| 41 .exportFunc(); | |
| 42 first_module.addFunction("first_func", sig_index) | |
| 43 .addBody([ | |
| 44 kExprI32Const, 1, | |
| 45 kExprGetLocal, 0, | |
| 46 kExprI32Add, | |
| 47 kExprCallImport, kArity1, 0, | |
| 48 kExprReturn, kArity1 | |
| 49 ]); | |
| 50 | |
| 51 var f = second_module.instantiate({import_module_2: {import_name_2: imported }}) | |
| 52 .exports.second_export; | |
| 53 var the_export = first_module.instantiate({import_module_1: {import_name_1: f}}) | |
| 54 .exports.first_export; | |
| 55 assertEquals(the_export(2), 3); | |
| 56 assertEquals(the_export(-1), 0); | |
| 57 assertEquals(the_export(0), 1); | |
| 58 assertEquals(the_export(5.5), 6); | |
| 59 assertEquals(%CheckWasmWrapperElision(the_export, expect_elison), true); | |
| 60 })(); | |
| 61 | |
| 62 // function calls stack: first_export -> first_func -> first_import -> | |
| 63 // second_export -> second_import | |
| 64 // In this case, second_export has less params than first_import, | |
| 65 // So that wrappers will not be removed | |
| 66 (function TestWasmWrapperNoElisionLessParams() { | |
| 67 var imported = function (a) { | |
| 68 return a; | |
| 69 }; | |
| 70 | |
| 71 var second_module = new WasmModuleBuilder(); | |
| 72 var sig_index_1 = second_module.addType(kSig_i_i); | |
| 73 second_module.addImportWithModule("import_module_2", "import_name_2", sig_in dex_1); | |
| 74 second_module.addFunction("second_export", sig_index_1) | |
| 75 .addBody([ | |
| 76 kExprGetLocal, 0, | |
| 77 kExprCallImport, kArity1, 0, | |
| 78 kExprReturn, kArity1 | |
| 79 ]) | |
| 80 .exportFunc(); | |
| 81 | |
| 82 var first_module = new WasmModuleBuilder(); | |
| 83 var sig_index_2 = first_module.addType(kSig_i_ii); | |
| 84 first_module.addImportWithModule("import_module_1", "import_name_1", sig_ind ex_2); | |
| 85 first_module.addFunction("first_export", sig_index_2) | |
| 86 .addBody([ | |
| 87 kExprGetLocal, 0, | |
| 88 kExprGetLocal, 1, | |
| 89 kExprCallFunction, kArity2, 1, | |
| 90 kExprReturn, kArity1 | |
| 91 ]) | |
| 92 .exportFunc(); | |
| 93 first_module.addFunction("first_func", sig_index_2) | |
| 94 .addBody([ | |
| 95 kExprGetLocal, 0, | |
| 96 kExprGetLocal, 1, | |
| 97 kExprCallImport, kArity2, 0, | |
| 98 kExprReturn, kArity1 | |
| 99 ]); | |
| 100 | |
| 101 var f = second_module.instantiate({import_module_2: {import_name_2: imported }}) | |
| 102 .exports.second_export; | |
| 103 var the_export = first_module.instantiate({import_module_1: {import_name_1: f}}) | |
| 104 .exports.first_export; | |
| 105 assertEquals(the_export(4, 5), 4); | |
| 106 assertEquals(the_export(-1, 4), -1); | |
| 107 assertEquals(the_export(0, 2), 0); | |
| 108 assertEquals(the_export(9.9, 4.3), 9); | |
| 109 assertEquals(%CheckWasmWrapperElision(the_export, expect_no_elison), true); | |
| 110 })(); | |
| 111 | |
| 112 // function calls stack: first_export -> first_func -> first_import -> | |
| 113 // second_export -> second_import | |
| 114 // In this case, second_export has more params than first_import, | |
| 115 // So that wrappers will not be removed | |
| 116 (function TestWasmWrapperNoElisionMoreParams() { | |
| 117 var imported = function (a, b, c) { | |
| 118 return a+b+c; | |
| 119 }; | |
| 120 | |
| 121 var second_module = new WasmModuleBuilder(); | |
| 122 var sig_index_3 = second_module.addType(kSig_i_iii); | |
| 123 second_module.addImportWithModule("import_module_2", "import_name_2", sig_in dex_3); | |
| 124 second_module.addFunction("second_export", sig_index_3) | |
| 125 .addBody([ | |
| 126 kExprGetLocal, 0, | |
| 127 kExprGetLocal, 1, | |
| 128 kExprGetLocal, 2, | |
| 129 kExprCallImport, kArity3, 0, | |
| 130 kExprReturn, kArity1 | |
| 131 ]) | |
| 132 .exportFunc(); | |
| 133 | |
| 134 var first_module = new WasmModuleBuilder(); | |
| 135 var sig_index_2 = first_module.addType(kSig_i_ii); | |
| 136 first_module.addImportWithModule("import_module_1", "import_name_1", sig_ind ex_2); | |
| 137 first_module.addFunction("first_export", sig_index_2) | |
| 138 .addBody([ | |
| 139 kExprGetLocal, 0, | |
| 140 kExprGetLocal, 1, | |
| 141 kExprCallFunction, kArity2, 1, | |
| 142 kExprReturn, kArity1 | |
| 143 ]) | |
| 144 .exportFunc(); | |
| 145 first_module.addFunction("first_func", sig_index_2) | |
| 146 .addBody([ | |
| 147 kExprGetLocal, 0, | |
| 148 kExprGetLocal, 1, | |
| 149 kExprCallImport, kArity2, 0, | |
| 150 kExprReturn, kArity1 | |
| 151 ]); | |
| 152 | |
| 153 var f = second_module.instantiate({import_module_2: {import_name_2: imported }}) | |
| 154 .exports.second_export; | |
| 155 var the_export = first_module.instantiate({import_module_1: {import_name_1: f}}) | |
| 156 .exports.first_export; | |
| 157 assertEquals(the_export(5, 6), 11); | |
| 158 assertEquals(the_export(-1, -4), -5); | |
| 159 assertEquals(the_export(0, 0), 0); | |
| 160 assertEquals(the_export(1.1, 2.7), 3); | |
| 161 assertEquals(%CheckWasmWrapperElision(the_export, expect_no_elison), true); | |
| 162 })(); | |
| 163 | |
| 164 // function calls stack: first_export -> first_func -> first_import -> | |
| 165 // second_export -> second_import | |
| 166 // In this case, second_export has different params type with first_import, | |
| 167 // So that wrappers will not be removed | |
| 168 (function TestWasmWrapperNoElisionTypeMismatch() { | |
| 169 var imported = function (a, b) { | |
| 170 return a+b; | |
| 171 }; | |
| 172 | |
| 173 var second_module = new WasmModuleBuilder(); | |
| 174 var sig_index_2 = second_module.addType(kSig_d_dd); | |
| 175 second_module.addImportWithModule("import_module_2", "import_name_2", sig_in dex_2); | |
| 176 second_module.addFunction("second_export", sig_index_2) | |
| 177 .addBody([ | |
| 178 kExprGetLocal, 0, | |
| 179 kExprGetLocal, 1, | |
| 180 kExprCallImport, kArity2, 0, | |
| 181 kExprReturn, kArity1 | |
| 182 ]) | |
| 183 .exportFunc(); | |
| 184 | |
| 185 var first_module = new WasmModuleBuilder(); | |
| 186 var sig_index_2 = first_module.addType(kSig_i_ii); | |
| 187 first_module.addImportWithModule("import_module_1", "import_name_1", sig_ind ex_2); | |
| 188 first_module.addFunction("first_export", sig_index_2) | |
| 189 .addBody([ | |
| 190 kExprGetLocal, 0, | |
| 191 kExprGetLocal, 1, | |
| 192 kExprCallFunction, kArity2, 1, | |
| 193 kExprReturn, kArity1 | |
| 194 ]) | |
| 195 .exportFunc(); | |
| 196 first_module.addFunction("first_func", sig_index_2) | |
| 197 .addBody([ | |
| 198 kExprGetLocal, 0, | |
| 199 kExprGetLocal, 1, | |
| 200 kExprCallImport, kArity2, 0, | |
| 201 kExprReturn, kArity1 | |
| 202 ]); | |
| 203 | |
| 204 var f = second_module.instantiate({import_module_2: {import_name_2: imported }}) | |
| 205 .exports.second_export; | |
| 206 var the_export = first_module.instantiate({import_module_1: {import_name_1: f}}) | |
| 207 .exports.first_export; | |
| 208 assertEquals(the_export(2.8, 9.1), 11); | |
| 209 assertEquals(the_export(-1.7, -2.5), -3); | |
| 210 assertEquals(the_export(0.0, 0.0), 0); | |
| 211 assertEquals(the_export(2, -2), 0); | |
| 212 assertEquals(%CheckWasmWrapperElision(the_export, expect_no_elison), true); | |
| 213 })(); | |
| OLD | NEW |