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/wasm/module-decoder.h" | 5 #include "src/wasm/module-decoder.h" |
6 | 6 |
7 #include "src/base/functional.h" | 7 #include "src/base/functional.h" |
8 #include "src/base/platform/platform.h" | 8 #include "src/base/platform/platform.h" |
9 #include "src/macro-assembler.h" | 9 #include "src/macro-assembler.h" |
10 #include "src/objects.h" | 10 #include "src/objects.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 uint32_t functions_count = consume_u32v(&length, "functions count"); | 165 uint32_t functions_count = consume_u32v(&length, "functions count"); |
166 module->functions.reserve(SafeReserve(functions_count)); | 166 module->functions.reserve(SafeReserve(functions_count)); |
167 for (uint32_t i = 0; i < functions_count; i++) { | 167 for (uint32_t i = 0; i < functions_count; i++) { |
168 module->functions.push_back({nullptr, // sig | 168 module->functions.push_back({nullptr, // sig |
169 i, // func_index | 169 i, // func_index |
170 0, // sig_index | 170 0, // sig_index |
171 0, // name_offset | 171 0, // name_offset |
172 0, // name_length | 172 0, // name_length |
173 0, // code_start_offset | 173 0, // code_start_offset |
174 0, // code_end_offset | 174 0, // code_end_offset |
175 0, // local_i32_count | |
176 0, // local_i64_count | |
177 0, // local_f32_count | |
178 0, // local_f64_count | |
179 false}); // exported | 175 false}); // exported |
180 WasmFunction* function = &module->functions.back(); | 176 WasmFunction* function = &module->functions.back(); |
181 function->sig_index = consume_sig_index(module, &function->sig); | 177 function->sig_index = consume_sig_index(module, &function->sig); |
182 } | 178 } |
183 break; | 179 break; |
184 } | 180 } |
185 case WasmSection::Code::FunctionBodies: { | 181 case WasmSection::Code::FunctionBodies: { |
186 int length; | 182 int length; |
187 const byte* pos = pc_; | 183 const byte* pos = pc_; |
188 uint32_t functions_count = consume_u32v(&length, "functions count"); | 184 uint32_t functions_count = consume_u32v(&length, "functions count"); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 TRACE("DecodeFunction[%d] module+%d\n", i, | 219 TRACE("DecodeFunction[%d] module+%d\n", i, |
224 static_cast<int>(pc_ - start_)); | 220 static_cast<int>(pc_ - start_)); |
225 | 221 |
226 module->functions.push_back({nullptr, // sig | 222 module->functions.push_back({nullptr, // sig |
227 i, // func_index | 223 i, // func_index |
228 0, // sig_index | 224 0, // sig_index |
229 0, // name_offset | 225 0, // name_offset |
230 0, // name_length | 226 0, // name_length |
231 0, // code_start_offset | 227 0, // code_start_offset |
232 0, // code_end_offset | 228 0, // code_end_offset |
233 0, // local_i32_count | |
234 0, // local_i64_count | |
235 0, // local_f32_count | |
236 0, // local_f64_count | |
237 false}); // exported | 229 false}); // exported |
238 WasmFunction* function = &module->functions.back(); | 230 WasmFunction* function = &module->functions.back(); |
239 DecodeFunctionInModule(module, function, false); | 231 DecodeFunctionInModule(module, function, false); |
240 } | 232 } |
241 if (ok() && verify_functions) { | 233 if (ok() && verify_functions) { |
242 for (uint32_t i = 0; i < functions_count; i++) { | 234 for (uint32_t i = 0; i < functions_count; i++) { |
243 if (failed()) break; | 235 if (failed()) break; |
244 WasmFunction* function = &module->functions[i]; | 236 WasmFunction* function = &module->functions[i]; |
245 VerifyFunctionBody(i, &menv, function); | 237 VerifyFunctionBody(i, &menv, function); |
246 if (result_.failed()) { | 238 if (result_.failed()) { |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 | 504 |
513 const byte* sigpos = pc_; | 505 const byte* sigpos = pc_; |
514 function->sig_index = consume_u16("signature index"); | 506 function->sig_index = consume_u16("signature index"); |
515 | 507 |
516 if (function->sig_index >= module->signatures.size()) { | 508 if (function->sig_index >= module->signatures.size()) { |
517 return error(sigpos, "invalid signature index"); | 509 return error(sigpos, "invalid signature index"); |
518 } else { | 510 } else { |
519 function->sig = module->signatures[function->sig_index]; | 511 function->sig = module->signatures[function->sig_index]; |
520 } | 512 } |
521 | 513 |
522 TRACE(" +%d <function attributes:%s%s%s>\n", | 514 TRACE(" +%d <function attributes:%s%s>\n", static_cast<int>(pc_ - start_), |
523 static_cast<int>(pc_ - start_), | |
524 decl_bits & kDeclFunctionName ? " name" : "", | 515 decl_bits & kDeclFunctionName ? " name" : "", |
525 decl_bits & kDeclFunctionLocals ? " locals" : "", | |
526 decl_bits & kDeclFunctionExport ? " exported" : ""); | 516 decl_bits & kDeclFunctionExport ? " exported" : ""); |
527 | 517 |
528 function->exported = decl_bits & kDeclFunctionExport; | 518 function->exported = decl_bits & kDeclFunctionExport; |
529 | 519 |
530 if (decl_bits & kDeclFunctionName) { | 520 if (decl_bits & kDeclFunctionName) { |
531 function->name_offset = | 521 function->name_offset = |
532 consume_string(&function->name_length, function->exported); | 522 consume_string(&function->name_length, function->exported); |
533 } | 523 } |
534 | 524 |
535 if (decl_bits & kDeclFunctionLocals) { | |
536 function->local_i32_count = consume_u16("i32 count"); | |
537 function->local_i64_count = consume_u16("i64 count"); | |
538 function->local_f32_count = consume_u16("f32 count"); | |
539 function->local_f64_count = consume_u16("f64 count"); | |
540 } | |
541 | |
542 uint16_t size = consume_u16("body size"); | 525 uint16_t size = consume_u16("body size"); |
543 if (ok()) { | 526 if (ok()) { |
544 if ((pc_ + size) > limit_) { | 527 if ((pc_ + size) > limit_) { |
545 return error(pc_, limit_, | 528 return error(pc_, limit_, |
546 "expected %d bytes for function body, fell off end", size); | 529 "expected %d bytes for function body, fell off end", size); |
547 } | 530 } |
548 function->code_start_offset = static_cast<uint32_t>(pc_ - start_); | 531 function->code_start_offset = static_cast<uint32_t>(pc_ - start_); |
549 function->code_end_offset = function->code_start_offset + size; | 532 function->code_end_offset = function->code_start_offset + size; |
550 TRACE(" +%d %-20s: (%d bytes)\n", static_cast<int>(pc_ - start_), | 533 TRACE(" +%d %-20s: (%d bytes)\n", static_cast<int>(pc_ - start_), |
551 "function body", size); | 534 "function body", size); |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 return FunctionError("size > maximum function size"); | 814 return FunctionError("size > maximum function size"); |
832 isolate->counters()->wasm_function_size_bytes()->AddSample( | 815 isolate->counters()->wasm_function_size_bytes()->AddSample( |
833 static_cast<int>(size)); | 816 static_cast<int>(size)); |
834 WasmFunction* function = new WasmFunction(); | 817 WasmFunction* function = new WasmFunction(); |
835 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); | 818 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); |
836 return decoder.DecodeSingleFunction(module_env, function); | 819 return decoder.DecodeSingleFunction(module_env, function); |
837 } | 820 } |
838 } // namespace wasm | 821 } // namespace wasm |
839 } // namespace internal | 822 } // namespace internal |
840 } // namespace v8 | 823 } // namespace v8 |
OLD | NEW |