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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 module->module_end = limit_; | 47 module->module_end = limit_; |
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 | 58 |
58 bool sections[kMaxModuleSectionCode]; | 59 bool sections[kMaxModuleSectionCode]; |
59 memset(sections, 0, sizeof(sections)); | 60 memset(sections, 0, sizeof(sections)); |
60 | 61 |
61 // Decode the module sections. | 62 // Decode the module sections. |
62 while (pc_ < limit_) { | 63 while (pc_ < limit_) { |
63 TRACE("DecodeSection\n"); | 64 TRACE("DecodeSection\n"); |
64 WasmSectionDeclCode section = | 65 WasmSectionDeclCode section = |
65 static_cast<WasmSectionDeclCode>(consume_u8("section")); | 66 static_cast<WasmSectionDeclCode>(consume_u8("section")); |
66 // Each section should appear at most once. | 67 // Each section should appear at most once. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 } | 197 } |
197 module->start_function_index = static_cast<int>(index); | 198 module->start_function_index = static_cast<int>(index); |
198 FunctionSig* sig = | 199 FunctionSig* sig = |
199 module->signatures->at(module->functions->at(index).sig_index); | 200 module->signatures->at(module->functions->at(index).sig_index); |
200 if (sig->parameter_count() > 0) { | 201 if (sig->parameter_count() > 0) { |
201 error(before, "invalid start function: non-zero parameter count"); | 202 error(before, "invalid start function: non-zero parameter count"); |
202 break; | 203 break; |
203 } | 204 } |
204 break; | 205 break; |
205 } | 206 } |
| 207 case kDeclImportTable: { |
| 208 // Declares an import table. |
| 209 CheckForPreviousSection(sections, kDeclSignatures, true); |
| 210 int length; |
| 211 uint32_t import_table_count = |
| 212 consume_u32v(&length, "import table count"); |
| 213 module->import_table->reserve(SafeReserve(import_table_count)); |
| 214 // Decode import table. |
| 215 for (uint32_t i = 0; i < import_table_count; i++) { |
| 216 if (failed()) break; |
| 217 TRACE("DecodeImportTable[%d] module+%d\n", i, |
| 218 static_cast<int>(pc_ - start_)); |
| 219 |
| 220 module->import_table->push_back({nullptr, 0, 0}); |
| 221 WasmImport* import = &module->import_table->back(); |
| 222 |
| 223 const byte* sigpos = pc_; |
| 224 import->sig_index = consume_u16("signature index"); |
| 225 |
| 226 if (import->sig_index >= module->signatures->size()) { |
| 227 error(sigpos, "invalid signature index"); |
| 228 } else { |
| 229 import->sig = module->signatures->at(import->sig_index); |
| 230 } |
| 231 import->module_name_offset = consume_string("import module name"); |
| 232 import->function_name_offset = |
| 233 consume_string("import function name"); |
| 234 } |
| 235 break; |
| 236 } |
206 case kDeclWLL: { | 237 case kDeclWLL: { |
207 // Reserved for experimentation by the Web Low-level Language project | 238 // Reserved for experimentation by the Web Low-level Language project |
208 // which is augmenting the binary encoding with source code meta | 239 // which is augmenting the binary encoding with source code meta |
209 // information. This section does not affect the semantics of the code | 240 // information. This section does not affect the semantics of the code |
210 // and can be ignored by the runtime. https://github.com/JSStats/wll | 241 // and can be ignored by the runtime. https://github.com/JSStats/wll |
211 int length = 0; | 242 int length = 0; |
212 uint32_t section_size = consume_u32v(&length, "section size"); | 243 uint32_t section_size = consume_u32v(&length, "section size"); |
213 if (pc_ + section_size > limit_ || pc_ + section_size < pc_) { | 244 if (pc_ + section_size > limit_ || pc_ + section_size < pc_) { |
214 error(pc_ - length, "invalid section size"); | 245 error(pc_ - length, "invalid section size"); |
215 break; | 246 break; |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 if (function_start > function_end) return FunctionError("start > end"); | 607 if (function_start > function_end) return FunctionError("start > end"); |
577 if (size > kMaxFunctionSize) | 608 if (size > kMaxFunctionSize) |
578 return FunctionError("size > maximum function size"); | 609 return FunctionError("size > maximum function size"); |
579 WasmFunction* function = new WasmFunction(); | 610 WasmFunction* function = new WasmFunction(); |
580 ModuleDecoder decoder(zone, function_start, function_end, false); | 611 ModuleDecoder decoder(zone, function_start, function_end, false); |
581 return decoder.DecodeSingleFunction(module_env, function); | 612 return decoder.DecodeSingleFunction(module_env, function); |
582 } | 613 } |
583 } // namespace wasm | 614 } // namespace wasm |
584 } // namespace internal | 615 } // namespace internal |
585 } // namespace v8 | 616 } // namespace v8 |
OLD | NEW |