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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 CheckForPreviousSection(sections, kDeclFunctions, true); | 188 CheckForPreviousSection(sections, kDeclFunctions, true); |
189 int length; | 189 int length; |
190 uint32_t function_table_count = | 190 uint32_t function_table_count = |
191 consume_u32v(&length, "function table count"); | 191 consume_u32v(&length, "function table count"); |
192 module->function_table.reserve(SafeReserve(function_table_count)); | 192 module->function_table.reserve(SafeReserve(function_table_count)); |
193 // Decode function table. | 193 // Decode function table. |
194 for (uint32_t i = 0; i < function_table_count; i++) { | 194 for (uint32_t i = 0; i < function_table_count; i++) { |
195 if (failed()) break; | 195 if (failed()) break; |
196 TRACE("DecodeFunctionTable[%d] module+%d\n", i, | 196 TRACE("DecodeFunctionTable[%d] module+%d\n", i, |
197 static_cast<int>(pc_ - start_)); | 197 static_cast<int>(pc_ - start_)); |
198 uint16_t index = consume_u16(); | 198 uint16_t index = consume_u32v(&length); |
199 if (index >= module->functions.size()) { | 199 if (index >= module->functions.size()) { |
200 error(pc_ - 2, "invalid function index"); | 200 error(pc_ - 2, "invalid function index"); |
201 break; | 201 break; |
202 } | 202 } |
203 module->function_table.push_back(index); | 203 module->function_table.push_back(index); |
204 } | 204 } |
205 break; | 205 break; |
206 } | 206 } |
207 case kDeclStartFunction: { | 207 case kDeclStartFunction: { |
208 // Declares a start function for a module. | 208 // Declares a start function for a module. |
(...skipping 28 matching lines...) Expand all Loading... |
237 // Decode import table. | 237 // Decode import table. |
238 for (uint32_t i = 0; i < import_table_count; i++) { | 238 for (uint32_t i = 0; i < import_table_count; i++) { |
239 if (failed()) break; | 239 if (failed()) break; |
240 TRACE("DecodeImportTable[%d] module+%d\n", i, | 240 TRACE("DecodeImportTable[%d] module+%d\n", i, |
241 static_cast<int>(pc_ - start_)); | 241 static_cast<int>(pc_ - start_)); |
242 | 242 |
243 module->import_table.push_back({nullptr, 0, 0}); | 243 module->import_table.push_back({nullptr, 0, 0}); |
244 WasmImport* import = &module->import_table.back(); | 244 WasmImport* import = &module->import_table.back(); |
245 | 245 |
246 const byte* sigpos = pc_; | 246 const byte* sigpos = pc_; |
247 import->sig_index = consume_u16("signature index"); | 247 import->sig_index = consume_u32v(&length, "signature index"); |
248 | 248 |
249 if (import->sig_index >= module->signatures.size()) { | 249 if (import->sig_index >= module->signatures.size()) { |
250 error(sigpos, "invalid signature index"); | 250 error(sigpos, "invalid signature index"); |
251 } else { | 251 } else { |
252 import->sig = module->signatures[import->sig_index]; | 252 import->sig = module->signatures[import->sig_index]; |
253 } | 253 } |
254 import->module_name_offset = consume_string("import module name"); | 254 import->module_name_offset = consume_string("import module name"); |
255 import->function_name_offset = | 255 import->function_name_offset = |
256 consume_string("import function name"); | 256 consume_string("import function name"); |
257 } | 257 } |
258 break; | 258 break; |
259 } | 259 } |
260 case kDeclExportTable: { | 260 case kDeclExportTable: { |
261 // Declares an export table. | 261 // Declares an export table. |
262 CheckForPreviousSection(sections, kDeclFunctions, true); | 262 CheckForPreviousSection(sections, kDeclFunctions, true); |
263 int length; | 263 int length; |
264 uint32_t export_table_count = | 264 uint32_t export_table_count = |
265 consume_u32v(&length, "export table count"); | 265 consume_u32v(&length, "export table count"); |
266 module->export_table.reserve(SafeReserve(export_table_count)); | 266 module->export_table.reserve(SafeReserve(export_table_count)); |
267 // Decode export table. | 267 // Decode export table. |
268 for (uint32_t i = 0; i < export_table_count; i++) { | 268 for (uint32_t i = 0; i < export_table_count; i++) { |
269 if (failed()) break; | 269 if (failed()) break; |
270 TRACE("DecodeExportTable[%d] module+%d\n", i, | 270 TRACE("DecodeExportTable[%d] module+%d\n", i, |
271 static_cast<int>(pc_ - start_)); | 271 static_cast<int>(pc_ - start_)); |
272 | 272 |
273 module->export_table.push_back({0, 0}); | 273 module->export_table.push_back({0, 0}); |
274 WasmExport* exp = &module->export_table.back(); | 274 WasmExport* exp = &module->export_table.back(); |
275 | 275 |
276 const byte* sigpos = pc_; | 276 const byte* sigpos = pc_; |
277 exp->func_index = consume_u16("function index"); | 277 exp->func_index = consume_u32v(&length, "function index"); |
278 if (exp->func_index >= module->functions.size()) { | 278 if (exp->func_index >= module->functions.size()) { |
279 error(sigpos, sigpos, | 279 error(sigpos, sigpos, |
280 "function index %u out of bounds (%d functions)", | 280 "function index %u out of bounds (%d functions)", |
281 exp->func_index, | 281 exp->func_index, |
282 static_cast<int>(module->functions.size())); | 282 static_cast<int>(module->functions.size())); |
283 } | 283 } |
284 exp->name_offset = consume_string("export name"); | 284 exp->name_offset = consume_string("export name"); |
285 } | 285 } |
286 break; | 286 break; |
287 } | 287 } |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 case kMemF64: | 555 case kMemF64: |
556 return MachineType::Float64(); | 556 return MachineType::Float64(); |
557 default: | 557 default: |
558 error(pc_ - 1, "invalid memory type"); | 558 error(pc_ - 1, "invalid memory type"); |
559 return MachineType::None(); | 559 return MachineType::None(); |
560 } | 560 } |
561 } | 561 } |
562 | 562 |
563 // Parses an inline function signature. | 563 // Parses an inline function signature. |
564 FunctionSig* consume_sig() { | 564 FunctionSig* consume_sig() { |
565 byte count = consume_u8("param count"); | 565 int length; |
| 566 byte count = consume_u32v(&length, "param count"); |
566 LocalType ret = consume_local_type(); | 567 LocalType ret = consume_local_type(); |
567 FunctionSig::Builder builder(module_zone, ret == kAstStmt ? 0 : 1, count); | 568 FunctionSig::Builder builder(module_zone, ret == kAstStmt ? 0 : 1, count); |
568 if (ret != kAstStmt) builder.AddReturn(ret); | 569 if (ret != kAstStmt) builder.AddReturn(ret); |
569 | 570 |
570 for (int i = 0; i < count; i++) { | 571 for (int i = 0; i < count; i++) { |
571 LocalType param = consume_local_type(); | 572 LocalType param = consume_local_type(); |
572 if (param == kAstStmt) error(pc_ - 1, "invalid void parameter type"); | 573 if (param == kAstStmt) error(pc_ - 1, "invalid void parameter type"); |
573 builder.AddParam(param); | 574 builder.AddParam(param); |
574 } | 575 } |
575 return builder.Build(); | 576 return builder.Build(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 if (function_start > function_end) return FunctionError("start > end"); | 632 if (function_start > function_end) return FunctionError("start > end"); |
632 if (size > kMaxFunctionSize) | 633 if (size > kMaxFunctionSize) |
633 return FunctionError("size > maximum function size"); | 634 return FunctionError("size > maximum function size"); |
634 WasmFunction* function = new WasmFunction(); | 635 WasmFunction* function = new WasmFunction(); |
635 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); | 636 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); |
636 return decoder.DecodeSingleFunction(module_env, function); | 637 return decoder.DecodeSingleFunction(module_env, function); |
637 } | 638 } |
638 } // namespace wasm | 639 } // namespace wasm |
639 } // namespace internal | 640 } // namespace internal |
640 } // namespace v8 | 641 } // namespace v8 |
OLD | NEW |