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 #include <stdlib.h> | 5 #include <stdlib.h> |
6 #include <string.h> | 6 #include <string.h> |
7 | 7 |
8 #include "src/wasm/encoder.h" | 8 #include "src/wasm/encoder.h" |
9 #include "src/wasm/module-decoder.h" | 9 #include "src/wasm/module-decoder.h" |
10 #include "src/wasm/wasm-js.h" | |
11 #include "src/wasm/wasm-macro-gen.h" | 10 #include "src/wasm/wasm-macro-gen.h" |
12 #include "src/wasm/wasm-module.h" | 11 #include "src/wasm/wasm-module.h" |
13 #include "src/wasm/wasm-opcodes.h" | 12 #include "src/wasm/wasm-opcodes.h" |
14 | 13 |
15 #include "test/cctest/cctest.h" | 14 #include "test/cctest/cctest.h" |
16 #include "test/cctest/wasm/test-signatures.h" | 15 #include "test/cctest/wasm/test-signatures.h" |
17 #include "test/common/wasm/wasm-module-runner.h" | 16 #include "test/common/wasm/wasm-module-runner.h" |
18 | 17 |
19 using namespace v8::base; | 18 using namespace v8::base; |
20 using namespace v8::internal; | 19 using namespace v8::internal; |
21 using namespace v8::internal::compiler; | 20 using namespace v8::internal::compiler; |
22 using namespace v8::internal::wasm; | 21 using namespace v8::internal::wasm; |
23 | 22 |
24 namespace { | 23 namespace { |
25 void TestModule(Zone* zone, WasmModuleBuilder* builder, | 24 void TestModule(Zone* zone, WasmModuleBuilder* builder, |
26 int32_t expected_result) { | 25 int32_t expected_result) { |
27 ZoneBuffer buffer(zone); | 26 ZoneBuffer buffer(zone); |
28 builder->WriteTo(buffer); | 27 builder->WriteTo(buffer); |
29 | 28 |
30 Isolate* isolate = CcTest::InitIsolateOnce(); | 29 Isolate* isolate = CcTest::InitIsolateOnce(); |
31 HandleScope scope(isolate); | 30 HandleScope scope(isolate); |
32 WasmJs::SetupIsolateForWasm(isolate); | 31 testing::SetupIsolateForWasmModule(isolate); |
33 int32_t result = testing::CompileAndRunWasmModule( | 32 int32_t result = testing::CompileAndRunWasmModule( |
34 isolate, buffer.begin(), buffer.end(), ModuleOrigin::kWasmOrigin); | 33 isolate, buffer.begin(), buffer.end(), ModuleOrigin::kWasmOrigin); |
35 CHECK_EQ(expected_result, result); | 34 CHECK_EQ(expected_result, result); |
36 } | 35 } |
37 | 36 |
38 void ExportAs(WasmFunctionBuilder* f, const char* name) { | 37 void ExportAs(WasmFunctionBuilder* f, const char* name) { |
39 f->SetExported(); | 38 f->SetExported(); |
40 f->SetName(name, static_cast<int>(strlen(name))); | 39 f->SetName(name, static_cast<int>(strlen(name))); |
41 } | 40 } |
42 | 41 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 ExportAs(f, kFunctionName); | 197 ExportAs(f, kFunctionName); |
199 | 198 |
200 ZoneBuffer buffer(&zone); | 199 ZoneBuffer buffer(&zone); |
201 builder->WriteTo(buffer); | 200 builder->WriteTo(buffer); |
202 | 201 |
203 Isolate* isolate = CcTest::InitIsolateOnce(); | 202 Isolate* isolate = CcTest::InitIsolateOnce(); |
204 ErrorThrower thrower(isolate, ""); | 203 ErrorThrower thrower(isolate, ""); |
205 v8::WasmCompiledModule::SerializedModule data; | 204 v8::WasmCompiledModule::SerializedModule data; |
206 { | 205 { |
207 HandleScope scope(isolate); | 206 HandleScope scope(isolate); |
208 WasmJs::SetupIsolateForWasm(isolate); | 207 testing::SetupIsolateForWasmModule(isolate); |
209 | 208 |
210 ModuleResult decoding_result = DecodeWasmModule( | 209 ModuleResult decoding_result = DecodeWasmModule( |
211 isolate, &zone, buffer.begin(), buffer.end(), false, kWasmOrigin); | 210 isolate, &zone, buffer.begin(), buffer.end(), false, kWasmOrigin); |
212 std::unique_ptr<const WasmModule> module(decoding_result.val); | 211 std::unique_ptr<const WasmModule> module(decoding_result.val); |
213 CHECK(!decoding_result.failed()); | 212 CHECK(!decoding_result.failed()); |
214 | 213 |
215 MaybeHandle<FixedArray> compiled_module = | 214 MaybeHandle<FixedArray> compiled_module = |
216 module->CompileFunctions(isolate, &thrower); | 215 module->CompileFunctions(isolate, &thrower); |
217 CHECK(!compiled_module.is_null()); | 216 CHECK(!compiled_module.is_null()); |
218 Handle<JSObject> module_obj = CreateCompiledModuleObject( | 217 Handle<JSObject> module_obj = CreateCompiledModuleObject( |
(...skipping 10 matching lines...) Expand all Loading... |
229 create_params.array_buffer_allocator = | 228 create_params.array_buffer_allocator = |
230 CcTest::InitIsolateOnce()->array_buffer_allocator(); | 229 CcTest::InitIsolateOnce()->array_buffer_allocator(); |
231 | 230 |
232 v8::Isolate* v8_isolate = v8::Isolate::New(create_params); | 231 v8::Isolate* v8_isolate = v8::Isolate::New(create_params); |
233 { | 232 { |
234 v8::Isolate::Scope isolate_scope(v8_isolate); | 233 v8::Isolate::Scope isolate_scope(v8_isolate); |
235 v8::HandleScope new_scope(v8_isolate); | 234 v8::HandleScope new_scope(v8_isolate); |
236 v8::Local<v8::Context> new_ctx = v8::Context::New(v8_isolate); | 235 v8::Local<v8::Context> new_ctx = v8::Context::New(v8_isolate); |
237 new_ctx->Enter(); | 236 new_ctx->Enter(); |
238 isolate = reinterpret_cast<Isolate*>(v8_isolate); | 237 isolate = reinterpret_cast<Isolate*>(v8_isolate); |
239 WasmJs::SetupIsolateForWasm(isolate); | 238 testing::SetupIsolateForWasmModule(isolate); |
240 | 239 |
241 v8::MaybeLocal<v8::WasmCompiledModule> deserialized = | 240 v8::MaybeLocal<v8::WasmCompiledModule> deserialized = |
242 v8::WasmCompiledModule::Deserialize(v8_isolate, data); | 241 v8::WasmCompiledModule::Deserialize(v8_isolate, data); |
243 v8::Local<v8::WasmCompiledModule> compiled_module; | 242 v8::Local<v8::WasmCompiledModule> compiled_module; |
244 CHECK(deserialized.ToLocal(&compiled_module)); | 243 CHECK(deserialized.ToLocal(&compiled_module)); |
245 Handle<JSObject> module_object = | 244 Handle<JSObject> module_object = |
246 Handle<JSObject>::cast(v8::Utils::OpenHandle(*compiled_module)); | 245 Handle<JSObject>::cast(v8::Utils::OpenHandle(*compiled_module)); |
247 Handle<JSObject> instance = | 246 Handle<JSObject> instance = |
248 WasmModule::Instantiate(isolate, module_object, | 247 WasmModule::Instantiate(isolate, module_object, |
249 Handle<JSReceiver>::null(), | 248 Handle<JSReceiver>::null(), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 282 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
284 uint16_t f_index = builder->AddFunction(); | 283 uint16_t f_index = builder->AddFunction(); |
285 WasmFunctionBuilder* f = builder->FunctionAt(f_index); | 284 WasmFunctionBuilder* f = builder->FunctionAt(f_index); |
286 f->SetSignature(sigs.i_v()); | 285 f->SetSignature(sigs.i_v()); |
287 ExportAsMain(f); | 286 ExportAsMain(f); |
288 byte code[] = {WASM_IF_ELSE(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)), | 287 byte code[] = {WASM_IF_ELSE(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)), |
289 WASM_I32V(12))}; | 288 WASM_I32V(12))}; |
290 f->EmitCode(code, sizeof(code)); | 289 f->EmitCode(code, sizeof(code)); |
291 TestModule(&zone, builder, 12); | 290 TestModule(&zone, builder, 12); |
292 } | 291 } |
OLD | NEW |