OLD | NEW |
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 <setjmp.h> | 8 #include <setjmp.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <stdlib.h> | 10 #include <stdlib.h> |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 MachineOperatorBuilder* machine() { return &main_machine_; } | 502 MachineOperatorBuilder* machine() { return &main_machine_; } |
503 CallDescriptor* descriptor() { | 503 CallDescriptor* descriptor() { |
504 if (descriptor_ == nullptr) { | 504 if (descriptor_ == nullptr) { |
505 descriptor_ = testing_module_->GetWasmCallDescriptor(zone(), sig); | 505 descriptor_ = testing_module_->GetWasmCallDescriptor(zone(), sig); |
506 } | 506 } |
507 return descriptor_; | 507 return descriptor_; |
508 } | 508 } |
509 uint32_t function_index() { return function_->func_index; } | 509 uint32_t function_index() { return function_->func_index; } |
510 | 510 |
511 void Build(const byte* start, const byte* end) { | 511 void Build(const byte* start, const byte* end) { |
512 size_t locals_size = local_decls.Size(); | 512 local_decls.Prepend(zone(), &start, &end); |
513 size_t total_size = end - start + locals_size + 1; | |
514 byte* buffer = static_cast<byte*>(zone()->New(total_size)); | |
515 // Prepend the local decls to the code. | |
516 local_decls.Emit(buffer); | |
517 // Emit the code. | |
518 memcpy(buffer + locals_size, start, end - start); | |
519 // Append an extra end opcode. | |
520 buffer[total_size - 1] = kExprEnd; | |
521 | |
522 start = buffer; | |
523 end = buffer + total_size; | |
524 | 513 |
525 CHECK_GE(kMaxInt, end - start); | 514 CHECK_GE(kMaxInt, end - start); |
526 int len = static_cast<int>(end - start); | 515 int len = static_cast<int>(end - start); |
527 function_->code_start_offset = | 516 function_->code_start_offset = |
528 testing_module_->AddBytes(Vector<const byte>(start, len)); | 517 testing_module_->AddBytes(Vector<const byte>(start, len)); |
529 function_->code_end_offset = function_->code_start_offset + len; | 518 function_->code_end_offset = function_->code_start_offset + len; |
530 | 519 |
531 if (interpreter_) { | 520 if (interpreter_) { |
532 // Add the code to the interpreter. | 521 // Add the code to the interpreter. |
533 CHECK(interpreter_->SetFunctionCodeForTesting(function_, start, end)); | 522 CHECK(interpreter_->SetFunctionCodeForTesting(function_, start, end)); |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
811 void RunWasm_##name(WasmExecutionMode execution_mode) | 800 void RunWasm_##name(WasmExecutionMode execution_mode) |
812 | 801 |
813 #define WASM_EXEC_COMPILED_TEST(name) \ | 802 #define WASM_EXEC_COMPILED_TEST(name) \ |
814 void RunWasm_##name(WasmExecutionMode execution_mode); \ | 803 void RunWasm_##name(WasmExecutionMode execution_mode); \ |
815 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ | 804 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ |
816 void RunWasm_##name(WasmExecutionMode execution_mode) | 805 void RunWasm_##name(WasmExecutionMode execution_mode) |
817 | 806 |
818 } // namespace | 807 } // namespace |
819 | 808 |
820 #endif | 809 #endif |
OLD | NEW |