| 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" |
| 11 | 11 |
| 12 namespace v8 { | 12 namespace v8 { |
| 13 namespace internal { | 13 namespace internal { |
| 14 namespace wasm { | 14 namespace wasm { |
| 15 | 15 |
| 16 #if DEBUG | |
| 17 #define TRACE(...) \ | 16 #define TRACE(...) \ |
| 18 do { \ | 17 do { \ |
| 19 if (FLAG_trace_wasm_decoder) PrintF(__VA_ARGS__); \ | 18 if (FLAG_trace_wasm_decoder) PrintF(__VA_ARGS__); \ |
| 20 } while (false) | 19 } while (false) |
| 21 #else | |
| 22 #define TRACE(...) | |
| 23 #endif | |
| 24 | 20 |
| 25 | 21 |
| 26 // The main logic for decoding the bytes of a module. | 22 // The main logic for decoding the bytes of a module. |
| 27 class ModuleDecoder : public Decoder { | 23 class ModuleDecoder : public Decoder { |
| 28 public: | 24 public: |
| 29 ModuleDecoder(Zone* zone, const byte* module_start, const byte* module_end, | 25 ModuleDecoder(Zone* zone, const byte* module_start, const byte* module_end, |
| 30 bool asm_js) | 26 bool asm_js) |
| 31 : Decoder(module_start, module_end), module_zone(zone), asm_js_(asm_js) { | 27 : Decoder(module_start, module_end), module_zone(zone), asm_js_(asm_js) { |
| 32 result_.start = start_; | 28 result_.start = start_; |
| 33 if (limit_ < start_) { | 29 if (limit_ < start_) { |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 return; | 319 return; |
| 324 } | 320 } |
| 325 | 321 |
| 326 if (decl_bits & kDeclFunctionLocals) { | 322 if (decl_bits & kDeclFunctionLocals) { |
| 327 function->local_i32_count = consume_u16("i32 count"); | 323 function->local_i32_count = consume_u16("i32 count"); |
| 328 function->local_i64_count = consume_u16("i64 count"); | 324 function->local_i64_count = consume_u16("i64 count"); |
| 329 function->local_f32_count = consume_u16("f32 count"); | 325 function->local_f32_count = consume_u16("f32 count"); |
| 330 function->local_f64_count = consume_u16("f64 count"); | 326 function->local_f64_count = consume_u16("f64 count"); |
| 331 } | 327 } |
| 332 | 328 |
| 333 uint16_t size = consume_u16("body size"); | 329 uint32_t size = consume_u32("body size"); |
| 334 if (ok()) { | 330 if (ok()) { |
| 335 if ((pc_ + size) > limit_) { | 331 if ((pc_ + size) > limit_) { |
| 336 return error(pc_, limit_, | 332 return error(pc_, limit_, |
| 337 "expected %d bytes for function body, fell off end", size); | 333 "expected %d bytes for function body, fell off end", size); |
| 338 } | 334 } |
| 339 function->code_start_offset = static_cast<uint32_t>(pc_ - start_); | 335 function->code_start_offset = static_cast<uint32_t>(pc_ - start_); |
| 340 function->code_end_offset = function->code_start_offset + size; | 336 function->code_end_offset = function->code_start_offset + size; |
| 341 TRACE(" +%d %-20s: (%d bytes)\n", static_cast<int>(pc_ - start_), | 337 TRACE(" +%d %-20s: (%d bytes)\n", static_cast<int>(pc_ - start_), |
| 342 "function body", size); | 338 "function body", size); |
| 343 pc_ += size; | 339 pc_ += size; |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 if (function_start > function_end) return FunctionError("start > end"); | 553 if (function_start > function_end) return FunctionError("start > end"); |
| 558 if (size > kMaxFunctionSize) | 554 if (size > kMaxFunctionSize) |
| 559 return FunctionError("size > maximum function size"); | 555 return FunctionError("size > maximum function size"); |
| 560 WasmFunction* function = new WasmFunction(); | 556 WasmFunction* function = new WasmFunction(); |
| 561 ModuleDecoder decoder(zone, function_start, function_end, false); | 557 ModuleDecoder decoder(zone, function_start, function_end, false); |
| 562 return decoder.DecodeSingleFunction(module_env, function); | 558 return decoder.DecodeSingleFunction(module_env, function); |
| 563 } | 559 } |
| 564 } // namespace wasm | 560 } // namespace wasm |
| 565 } // namespace internal | 561 } // namespace internal |
| 566 } // namespace v8 | 562 } // namespace v8 |
| OLD | NEW |