| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 rng.NextBytes(raw, end - raw); | 174 rng.NextBytes(raw, end - raw); |
| 175 } | 175 } |
| 176 | 176 |
| 177 uint32_t AddFunction(FunctionSig* sig, Handle<Code> code) { | 177 uint32_t AddFunction(FunctionSig* sig, Handle<Code> code) { |
| 178 if (module->functions.size() == 0) { | 178 if (module->functions.size() == 0) { |
| 179 // TODO(titzer): Reserving space here to avoid the underlying WasmFunction | 179 // TODO(titzer): Reserving space here to avoid the underlying WasmFunction |
| 180 // structs from moving. | 180 // structs from moving. |
| 181 module_.functions.reserve(kMaxFunctions); | 181 module_.functions.reserve(kMaxFunctions); |
| 182 } | 182 } |
| 183 uint32_t index = static_cast<uint32_t>(module->functions.size()); | 183 uint32_t index = static_cast<uint32_t>(module->functions.size()); |
| 184 module_.functions.push_back({sig, index, 0, 0, 0, 0, 0}); | 184 module_.functions.push_back({sig, index, 0, 0, 0, 0, 0, false, false}); |
| 185 instance->function_code.push_back(code); | 185 instance->function_code.push_back(code); |
| 186 if (interpreter_) { | 186 if (interpreter_) { |
| 187 const WasmFunction* function = &module->functions.back(); | 187 const WasmFunction* function = &module->functions.back(); |
| 188 int interpreter_index = interpreter_->AddFunctionForTesting(function); | 188 int interpreter_index = interpreter_->AddFunctionForTesting(function); |
| 189 CHECK_EQ(index, static_cast<uint32_t>(interpreter_index)); | 189 CHECK_EQ(index, static_cast<uint32_t>(interpreter_index)); |
| 190 } | 190 } |
| 191 DCHECK_LT(index, kMaxFunctions); // limited for testing. | 191 DCHECK_LT(index, kMaxFunctions); // limited for testing. |
| 192 return index; | 192 return index; |
| 193 } | 193 } |
| 194 | 194 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 224 exportedSig, module_object); | 224 exportedSig, module_object); |
| 225 return ret; | 225 return ret; |
| 226 } | 226 } |
| 227 | 227 |
| 228 void SetFunctionCode(uint32_t index, Handle<Code> code) { | 228 void SetFunctionCode(uint32_t index, Handle<Code> code) { |
| 229 instance->function_code[index] = code; | 229 instance->function_code[index] = code; |
| 230 } | 230 } |
| 231 | 231 |
| 232 void AddIndirectFunctionTable(uint16_t* functions, uint32_t table_size) { | 232 void AddIndirectFunctionTable(uint16_t* functions, uint32_t table_size) { |
| 233 module_.function_tables.push_back( | 233 module_.function_tables.push_back( |
| 234 {table_size, table_size, std::vector<uint16_t>()}); | 234 {table_size, table_size, std::vector<int32_t>(), false, false}); |
| 235 for (uint32_t i = 0; i < table_size; ++i) { | 235 for (uint32_t i = 0; i < table_size; ++i) { |
| 236 module_.function_tables.back().values.push_back(functions[i]); | 236 module_.function_tables.back().values.push_back(functions[i]); |
| 237 } | 237 } |
| 238 | 238 |
| 239 Handle<FixedArray> values = BuildFunctionTable( | 239 Handle<FixedArray> values = BuildFunctionTable( |
| 240 isolate_, static_cast<int>(module_.function_tables.size() - 1), | 240 isolate_, static_cast<int>(module_.function_tables.size() - 1), |
| 241 &module_); | 241 &module_); |
| 242 instance->function_tables.push_back(values); | 242 instance->function_tables.push_back(values); |
| 243 } | 243 } |
| 244 | 244 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 261 WasmModuleInstance instance_; | 261 WasmModuleInstance instance_; |
| 262 Isolate* isolate_; | 262 Isolate* isolate_; |
| 263 v8::base::AccountingAllocator allocator_; | 263 v8::base::AccountingAllocator allocator_; |
| 264 uint32_t global_offset; | 264 uint32_t global_offset; |
| 265 V8_ALIGNED(8) byte global_data[kMaxGlobalsSize]; // preallocated global data. | 265 V8_ALIGNED(8) byte global_data[kMaxGlobalsSize]; // preallocated global data. |
| 266 WasmInterpreter* interpreter_; | 266 WasmInterpreter* interpreter_; |
| 267 | 267 |
| 268 const WasmGlobal* AddGlobal(LocalType type) { | 268 const WasmGlobal* AddGlobal(LocalType type) { |
| 269 byte size = WasmOpcodes::MemSize(WasmOpcodes::MachineTypeFor(type)); | 269 byte size = WasmOpcodes::MemSize(WasmOpcodes::MachineTypeFor(type)); |
| 270 global_offset = (global_offset + size - 1) & ~(size - 1); // align | 270 global_offset = (global_offset + size - 1) & ~(size - 1); // align |
| 271 module_.globals.push_back({0, 0, type, global_offset, false}); | 271 module_.globals.push_back( |
| 272 {type, true, NO_INIT, global_offset, false, false}); |
| 272 global_offset += size; | 273 global_offset += size; |
| 273 // limit number of globals. | 274 // limit number of globals. |
| 274 CHECK_LT(global_offset, kMaxGlobalsSize); | 275 CHECK_LT(global_offset, kMaxGlobalsSize); |
| 275 return &module->globals.back(); | 276 return &module->globals.back(); |
| 276 } | 277 } |
| 277 }; | 278 }; |
| 278 | 279 |
| 279 inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module, | 280 inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module, |
| 280 FunctionSig* sig, | 281 FunctionSig* sig, |
| 281 SourcePositionTable* source_position_table, | 282 SourcePositionTable* source_position_table, |
| 282 const byte* start, const byte* end) { | 283 const byte* start, const byte* end) { |
| 283 compiler::WasmGraphBuilder builder(zone, jsgraph, sig, source_position_table); | 284 compiler::WasmGraphBuilder builder(zone, jsgraph, sig, source_position_table); |
| 284 DecodeResult result = | 285 DecodeResult result = |
| 285 BuildTFGraph(zone->allocator(), &builder, module, sig, start, end); | 286 BuildTFGraph(zone->allocator(), &builder, module, sig, start, end); |
| 286 if (result.failed()) { | 287 if (result.failed()) { |
| 288 if (!FLAG_trace_wasm_decoder) { |
| 289 // Retry the compilation with the tracing flag on, to help in debugging. |
| 290 FLAG_trace_wasm_decoder = true; |
| 291 result = |
| 292 BuildTFGraph(zone->allocator(), &builder, module, sig, start, end); |
| 293 } |
| 294 |
| 287 ptrdiff_t pc = result.error_pc - result.start; | 295 ptrdiff_t pc = result.error_pc - result.start; |
| 288 ptrdiff_t pt = result.error_pt - result.start; | 296 ptrdiff_t pt = result.error_pt - result.start; |
| 289 std::ostringstream str; | 297 std::ostringstream str; |
| 290 str << "Verification failed: " << result.error_code << " pc = +" << pc; | 298 str << "Verification failed: " << result.error_code << " pc = +" << pc; |
| 291 if (result.error_pt) str << ", pt = +" << pt; | 299 if (result.error_pt) str << ", pt = +" << pt; |
| 292 str << ", msg = " << result.error_msg.get(); | 300 str << ", msg = " << result.error_msg.get(); |
| 293 FATAL(str.str().c_str()); | 301 FATAL(str.str().c_str()); |
| 294 } | 302 } |
| 295 builder.Int64LoweringForTesting(); | 303 builder.Int64LoweringForTesting(); |
| 296 if (FLAG_trace_turbo_graph) { | 304 if (FLAG_trace_turbo_graph) { |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 // interpreter. | 784 // interpreter. |
| 777 #define WASM_EXEC_TEST(name) \ | 785 #define WASM_EXEC_TEST(name) \ |
| 778 void RunWasm_##name(WasmExecutionMode execution_mode); \ | 786 void RunWasm_##name(WasmExecutionMode execution_mode); \ |
| 779 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ | 787 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ |
| 780 TEST(RunWasmInterpreted_##name) { RunWasm_##name(kExecuteInterpreted); } \ | 788 TEST(RunWasmInterpreted_##name) { RunWasm_##name(kExecuteInterpreted); } \ |
| 781 void RunWasm_##name(WasmExecutionMode execution_mode) | 789 void RunWasm_##name(WasmExecutionMode execution_mode) |
| 782 | 790 |
| 783 } // namespace | 791 } // namespace |
| 784 | 792 |
| 785 #endif | 793 #endif |
| OLD | NEW |