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

Side by Side Diff: test/cctest/wasm/wasm-run-utils.h

Issue 2230063002: [wasm] Experimental: Add support for multiple non-homogeneous tables Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 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/test-signatures.h ('k') | test/unittests/wasm/ast-decoder-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 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 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 #ifndef WASM_RUN_UTILS_H 5 #ifndef WASM_RUN_UTILS_H
6 #define WASM_RUN_UTILS_H 6 #define WASM_RUN_UTILS_H
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // exception. 45 // exception.
46 #define CHECK_TRAP32(x) \ 46 #define CHECK_TRAP32(x) \
47 CHECK_EQ(0xdeadbeef, (bit_cast<uint32_t>(x)) & 0xFFFFFFFF) 47 CHECK_EQ(0xdeadbeef, (bit_cast<uint32_t>(x)) & 0xFFFFFFFF)
48 #define CHECK_TRAP64(x) \ 48 #define CHECK_TRAP64(x) \
49 CHECK_EQ(0xdeadbeefdeadbeef, (bit_cast<uint64_t>(x)) & 0xFFFFFFFFFFFFFFFF) 49 CHECK_EQ(0xdeadbeefdeadbeef, (bit_cast<uint64_t>(x)) & 0xFFFFFFFFFFFFFFFF)
50 #define CHECK_TRAP(x) CHECK_TRAP32(x) 50 #define CHECK_TRAP(x) CHECK_TRAP32(x)
51 51
52 #define WASM_RUNNER_MAX_NUM_PARAMETERS 4 52 #define WASM_RUNNER_MAX_NUM_PARAMETERS 4
53 #define WASM_WRAPPER_RETURN_VALUE 8754 53 #define WASM_WRAPPER_RETURN_VALUE 8754
54 54
55 #define BUILD(r, ...) \ 55 #define BUILD(r, ...) \
56 do { \ 56 do { \
57 byte code[] = {__VA_ARGS__}; \ 57 byte code[] = {__VA_ARGS__}; \
58 r.Build(code, code + arraysize(code)); \ 58 r.Build(code, code + arraysize(code), false); \
59 } while (false)
60
61 #define BUILD_FAIL(r, ...) \
62 do { \
63 byte code[] = {__VA_ARGS__}; \
64 r.Build(code, code + arraysize(code), true); \
59 } while (false) 65 } while (false)
60 66
61 namespace { 67 namespace {
62 using namespace v8::base; 68 using namespace v8::base;
63 using namespace v8::internal; 69 using namespace v8::internal;
64 using namespace v8::internal::compiler; 70 using namespace v8::internal::compiler;
65 using namespace v8::internal::wasm; 71 using namespace v8::internal::wasm;
66 72
67 const uint32_t kMaxGlobalsSize = 128; 73 const uint32_t kMaxGlobalsSize = 128;
68 74
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 isolate_, ret_code, name, 227 isolate_, ret_code, name,
222 static_cast<int>(this->module->functions[index].sig->parameter_count()), 228 static_cast<int>(this->module->functions[index].sig->parameter_count()),
223 exportedSig, module_object); 229 exportedSig, module_object);
224 return ret; 230 return ret;
225 } 231 }
226 232
227 void SetFunctionCode(uint32_t index, Handle<Code> code) { 233 void SetFunctionCode(uint32_t index, Handle<Code> code) {
228 instance->function_code[index] = code; 234 instance->function_code[index] = code;
229 } 235 }
230 236
231 void AddIndirectFunctionTable(uint16_t* functions, uint32_t table_size) { 237 void AddIndirectFunctionTable(FunctionSig* sig, uint32_t table,
232 module_.function_tables.push_back( 238 uint16_t* functions, uint32_t table_size) {
233 {table_size, table_size, std::vector<uint16_t>()}); 239 module_.function_tables.push_back({!module_.function_tables.size(), sig,
240 table, table_size, table_size,
241 std::vector<uint16_t>()});
234 for (uint32_t i = 0; i < table_size; ++i) { 242 for (uint32_t i = 0; i < table_size; ++i) {
235 module_.function_tables.back().values.push_back(functions[i]); 243 module_.function_tables.back().values.push_back(functions[i]);
236 } 244 }
237 245
238 Handle<FixedArray> values = BuildFunctionTable( 246 Handle<FixedArray> values = BuildFunctionTable(
239 isolate_, static_cast<int>(module_.function_tables.size() - 1), 247 isolate_, static_cast<int>(module_.function_tables.size() - 1),
240 &module_); 248 &module_);
241 instance->function_tables.push_back(values); 249 instance->function_tables.push_back(values);
242 } 250 }
243 251
(...skipping 27 matching lines...) Expand all
271 global_offset += size; 279 global_offset += size;
272 // limit number of globals. 280 // limit number of globals.
273 CHECK_LT(global_offset, kMaxGlobalsSize); 281 CHECK_LT(global_offset, kMaxGlobalsSize);
274 return &module->globals.back(); 282 return &module->globals.back();
275 } 283 }
276 }; 284 };
277 285
278 inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module, 286 inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module,
279 FunctionSig* sig, 287 FunctionSig* sig,
280 SourcePositionTable* source_position_table, 288 SourcePositionTable* source_position_table,
281 const byte* start, const byte* end) { 289 const byte* start, const byte* end, bool fail) {
282 compiler::WasmGraphBuilder builder(zone, jsgraph, sig, source_position_table); 290 compiler::WasmGraphBuilder builder(zone, jsgraph, sig, source_position_table);
283 DecodeResult result = 291 DecodeResult result =
284 BuildTFGraph(zone->allocator(), &builder, module, sig, start, end); 292 BuildTFGraph(zone->allocator(), &builder, module, sig, start, end);
285 if (result.failed()) { 293 if ((result.failed() && !fail) || (!result.failed() && fail)) {
286 ptrdiff_t pc = result.error_pc - result.start; 294 ptrdiff_t pc = result.error_pc - result.start;
287 ptrdiff_t pt = result.error_pt - result.start; 295 ptrdiff_t pt = result.error_pt - result.start;
288 std::ostringstream str; 296 std::ostringstream str;
289 str << "Verification failed: " << result.error_code << " pc = +" << pc; 297 str << "Verification failed: " << result.error_code << " pc = +" << pc;
290 if (result.error_pt) str << ", pt = +" << pt; 298 if (result.error_pt) str << ", pt = +" << pt;
291 str << ", msg = " << result.error_msg.get(); 299 str << ", msg = " << result.error_msg.get();
292 FATAL(str.str().c_str()); 300 FATAL(str.str().c_str());
293 } 301 }
302 if (result.failed()) return;
294 builder.Int64LoweringForTesting(); 303 builder.Int64LoweringForTesting();
295 if (FLAG_trace_turbo_graph) { 304 if (FLAG_trace_turbo_graph) {
296 OFStream os(stdout); 305 OFStream os(stdout);
297 os << AsRPO(*jsgraph->graph()); 306 os << AsRPO(*jsgraph->graph());
298 } 307 }
299 } 308 }
300 309
301 template <typename ReturnType> 310 template <typename ReturnType>
302 class WasmFunctionWrapper : public HandleAndZoneScope, 311 class WasmFunctionWrapper : public HandleAndZoneScope,
303 private GraphAndBuilders { 312 private GraphAndBuilders {
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 CommonOperatorBuilder* common() { return &main_common_; } 523 CommonOperatorBuilder* common() { return &main_common_; }
515 MachineOperatorBuilder* machine() { return &main_machine_; } 524 MachineOperatorBuilder* machine() { return &main_machine_; }
516 void InitializeDescriptor() { 525 void InitializeDescriptor() {
517 if (descriptor_ == nullptr) { 526 if (descriptor_ == nullptr) {
518 descriptor_ = testing_module_->GetWasmCallDescriptor(main_zone(), sig); 527 descriptor_ = testing_module_->GetWasmCallDescriptor(main_zone(), sig);
519 } 528 }
520 } 529 }
521 CallDescriptor* descriptor() { return descriptor_; } 530 CallDescriptor* descriptor() { return descriptor_; }
522 uint32_t function_index() { return function_->func_index; } 531 uint32_t function_index() { return function_->func_index; }
523 532
524 void Build(const byte* start, const byte* end) { 533 void Build(const byte* start, const byte* end, bool fail) {
525 // Build the TurboFan graph. 534 // Build the TurboFan graph.
526 local_decls.Prepend(main_zone(), &start, &end); 535 local_decls.Prepend(main_zone(), &start, &end);
527 TestBuildingGraph(main_zone(), &jsgraph, testing_module_, sig, 536 TestBuildingGraph(main_zone(), &jsgraph, testing_module_, sig,
528 &source_position_table_, start, end); 537 &source_position_table_, start, end, fail);
529 if (interpreter_) { 538 if (!fail && interpreter_) {
530 // Add the code to the interpreter. 539 // Add the code to the interpreter.
531 CHECK(interpreter_->SetFunctionCodeForTesting(function_, start, end)); 540 CHECK(interpreter_->SetFunctionCodeForTesting(function_, start, end));
532 } 541 }
533 } 542 }
534 543
535 byte AllocateLocal(LocalType type) { 544 byte AllocateLocal(LocalType type) {
536 uint32_t index = local_decls.AddLocals(1, type); 545 uint32_t index = local_decls.AddLocals(1, type);
537 byte result = static_cast<byte>(index); 546 byte result = static_cast<byte>(index);
538 DCHECK_EQ(index, result); 547 DCHECK_EQ(index, result);
539 return result; 548 return result;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 if (p3 != MachineType::None()) 650 if (p3 != MachineType::None())
642 storage_[index++] = WasmOpcodes::LocalTypeFor(p3); 651 storage_[index++] = WasmOpcodes::LocalTypeFor(p3);
643 652
644 compiler_.InitializeDescriptor(); 653 compiler_.InitializeDescriptor();
645 wrapper_.Init(compiler_.descriptor(), p0, p1, p2, p3); 654 wrapper_.Init(compiler_.descriptor(), p0, p1, p2, p3);
646 } 655 }
647 656
648 // Builds a graph from the given Wasm code and generates the machine 657 // Builds a graph from the given Wasm code and generates the machine
649 // code and call wrapper for that graph. This method must not be called 658 // code and call wrapper for that graph. This method must not be called
650 // more than once. 659 // more than once.
651 void Build(const byte* start, const byte* end) { 660 void Build(const byte* start, const byte* end, bool fail) {
652 CHECK(!compiled_); 661 CHECK(!compiled_);
653 compiled_ = true; 662 compiled_ = true;
654 compiler_.Build(start, end); 663 compiler_.Build(start, end, fail);
655 664
656 if (!interpret()) { 665 if (!interpret() && !fail) {
657 // Compile machine code and install it into the module. 666 // Compile machine code and install it into the module.
658 Handle<Code> code = compiler_.Compile(); 667 Handle<Code> code = compiler_.Compile();
659 668
660 if (compiler_.testing_module_) { 669 if (compiler_.testing_module_) {
661 // Update the table of function code in the module. 670 // Update the table of function code in the module.
662 compiler_.testing_module_->SetFunctionCode( 671 compiler_.testing_module_->SetFunctionCode(
663 compiler_.function_->func_index, code); 672 compiler_.function_->func_index, code);
664 } 673 }
665 674
666 wrapper_.SetInnerCode(code); 675 wrapper_.SetInnerCode(code);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 // interpreter. 783 // interpreter.
775 #define WASM_EXEC_TEST(name) \ 784 #define WASM_EXEC_TEST(name) \
776 void RunWasm_##name(WasmExecutionMode execution_mode); \ 785 void RunWasm_##name(WasmExecutionMode execution_mode); \
777 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ 786 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \
778 TEST(RunWasmInterpreted_##name) { RunWasm_##name(kExecuteInterpreted); } \ 787 TEST(RunWasmInterpreted_##name) { RunWasm_##name(kExecuteInterpreted); } \
779 void RunWasm_##name(WasmExecutionMode execution_mode) 788 void RunWasm_##name(WasmExecutionMode execution_mode)
780 789
781 } // namespace 790 } // namespace
782 791
783 #endif 792 #endif
OLDNEW
« no previous file with comments | « test/cctest/wasm/test-signatures.h ('k') | test/unittests/wasm/ast-decoder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698