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 "src/macro-assembler.h" | 5 #include "src/macro-assembler.h" |
6 #include "src/objects.h" | 6 #include "src/objects.h" |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/wasm/decoder.h" | 9 #include "src/wasm/decoder.h" |
10 #include "src/wasm/module-decoder.h" | 10 #include "src/wasm/module-decoder.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 module->min_mem_size_log2 = 0; | 48 module->min_mem_size_log2 = 0; |
49 module->max_mem_size_log2 = 0; | 49 module->max_mem_size_log2 = 0; |
50 module->mem_export = false; | 50 module->mem_export = false; |
51 module->mem_external = false; | 51 module->mem_external = false; |
52 module->globals = new std::vector<WasmGlobal>(); | 52 module->globals = new std::vector<WasmGlobal>(); |
53 module->signatures = new std::vector<FunctionSig*>(); | 53 module->signatures = new std::vector<FunctionSig*>(); |
54 module->functions = new std::vector<WasmFunction>(); | 54 module->functions = new std::vector<WasmFunction>(); |
55 module->data_segments = new std::vector<WasmDataSegment>(); | 55 module->data_segments = new std::vector<WasmDataSegment>(); |
56 module->function_table = new std::vector<uint16_t>(); | 56 module->function_table = new std::vector<uint16_t>(); |
57 module->import_table = new std::vector<WasmImport>(); | 57 module->import_table = new std::vector<WasmImport>(); |
| 58 module->export_table = new std::vector<WasmExport>(); |
58 | 59 |
59 bool sections[kMaxModuleSectionCode]; | 60 bool sections[kMaxModuleSectionCode]; |
60 memset(sections, 0, sizeof(sections)); | 61 memset(sections, 0, sizeof(sections)); |
61 | 62 |
62 // Decode the module sections. | 63 // Decode the module sections. |
63 while (pc_ < limit_) { | 64 while (pc_ < limit_) { |
64 TRACE("DecodeSection\n"); | 65 TRACE("DecodeSection\n"); |
65 WasmSectionDeclCode section = | 66 WasmSectionDeclCode section = |
66 static_cast<WasmSectionDeclCode>(consume_u8("section")); | 67 static_cast<WasmSectionDeclCode>(consume_u8("section")); |
67 // Each section should appear at most once. | 68 // Each section should appear at most once. |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 error(sigpos, "invalid signature index"); | 228 error(sigpos, "invalid signature index"); |
228 } else { | 229 } else { |
229 import->sig = module->signatures->at(import->sig_index); | 230 import->sig = module->signatures->at(import->sig_index); |
230 } | 231 } |
231 import->module_name_offset = consume_string("import module name"); | 232 import->module_name_offset = consume_string("import module name"); |
232 import->function_name_offset = | 233 import->function_name_offset = |
233 consume_string("import function name"); | 234 consume_string("import function name"); |
234 } | 235 } |
235 break; | 236 break; |
236 } | 237 } |
| 238 case kDeclExportTable: { |
| 239 // Declares an export table. |
| 240 CheckForPreviousSection(sections, kDeclFunctions, true); |
| 241 int length; |
| 242 uint32_t export_table_count = |
| 243 consume_u32v(&length, "export table count"); |
| 244 module->export_table->reserve(SafeReserve(export_table_count)); |
| 245 // Decode export table. |
| 246 for (uint32_t i = 0; i < export_table_count; i++) { |
| 247 if (failed()) break; |
| 248 TRACE("DecodeExportTable[%d] module+%d\n", i, |
| 249 static_cast<int>(pc_ - start_)); |
| 250 |
| 251 module->export_table->push_back({0, 0}); |
| 252 WasmExport* exp = &module->export_table->back(); |
| 253 |
| 254 const byte* sigpos = pc_; |
| 255 exp->func_index = consume_u16("function index"); |
| 256 if (exp->func_index >= module->functions->size()) { |
| 257 error(sigpos, sigpos, |
| 258 "function index %u out of bounds (%d functions)", |
| 259 exp->func_index, |
| 260 static_cast<int>(module->functions->size())); |
| 261 } |
| 262 exp->name_offset = consume_string("export name"); |
| 263 } |
| 264 break; |
| 265 } |
237 case kDeclWLL: { | 266 case kDeclWLL: { |
238 // Reserved for experimentation by the Web Low-level Language project | 267 // Reserved for experimentation by the Web Low-level Language project |
239 // which is augmenting the binary encoding with source code meta | 268 // which is augmenting the binary encoding with source code meta |
240 // information. This section does not affect the semantics of the code | 269 // information. This section does not affect the semantics of the code |
241 // and can be ignored by the runtime. https://github.com/JSStats/wll | 270 // and can be ignored by the runtime. https://github.com/JSStats/wll |
242 int length = 0; | 271 int length = 0; |
243 uint32_t section_size = consume_u32v(&length, "section size"); | 272 uint32_t section_size = consume_u32v(&length, "section size"); |
244 if (pc_ + section_size > limit_ || pc_ + section_size < pc_) { | 273 if (pc_ + section_size > limit_ || pc_ + section_size < pc_) { |
245 error(pc_ - length, "invalid section size"); | 274 error(pc_ - length, "invalid section size"); |
246 break; | 275 break; |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 if (function_start > function_end) return FunctionError("start > end"); | 636 if (function_start > function_end) return FunctionError("start > end"); |
608 if (size > kMaxFunctionSize) | 637 if (size > kMaxFunctionSize) |
609 return FunctionError("size > maximum function size"); | 638 return FunctionError("size > maximum function size"); |
610 WasmFunction* function = new WasmFunction(); | 639 WasmFunction* function = new WasmFunction(); |
611 ModuleDecoder decoder(zone, function_start, function_end, false); | 640 ModuleDecoder decoder(zone, function_start, function_end, false); |
612 return decoder.DecodeSingleFunction(module_env, function); | 641 return decoder.DecodeSingleFunction(module_env, function); |
613 } | 642 } |
614 } // namespace wasm | 643 } // namespace wasm |
615 } // namespace internal | 644 } // namespace internal |
616 } // namespace v8 | 645 } // namespace v8 |
OLD | NEW |