| 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 #ifndef V8_WASM_DECODER_H_ |    5 #ifndef V8_WASM_DECODER_H_ | 
|    6 #define V8_WASM_DECODER_H_ |    6 #define V8_WASM_DECODER_H_ | 
|    7  |    7  | 
 |    8 #include <memory> | 
 |    9  | 
|    8 #include "src/base/compiler-specific.h" |   10 #include "src/base/compiler-specific.h" | 
|    9 #include "src/base/smart-pointers.h" |   11 #include "src/base/smart-pointers.h" | 
|   10 #include "src/flags.h" |   12 #include "src/flags.h" | 
|   11 #include "src/signature.h" |   13 #include "src/signature.h" | 
|   12 #include "src/utils.h" |   14 #include "src/utils.h" | 
|   13 #include "src/wasm/wasm-result.h" |   15 #include "src/wasm/wasm-result.h" | 
|   14 #include "src/zone-containers.h" |   16 #include "src/zone-containers.h" | 
|   15  |   17  | 
|   16 namespace v8 { |   18 namespace v8 { | 
|   17 namespace internal { |   19 namespace internal { | 
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  240       if (FLAG_wasm_break_on_decoder_error) { |  242       if (FLAG_wasm_break_on_decoder_error) { | 
|  241         base::OS::DebugBreak(); |  243         base::OS::DebugBreak(); | 
|  242       } |  244       } | 
|  243 #endif |  245 #endif | 
|  244       const int kMaxErrorMsg = 256; |  246       const int kMaxErrorMsg = 256; | 
|  245       char* buffer = new char[kMaxErrorMsg]; |  247       char* buffer = new char[kMaxErrorMsg]; | 
|  246       va_list arguments; |  248       va_list arguments; | 
|  247       va_start(arguments, format); |  249       va_start(arguments, format); | 
|  248       base::OS::VSNPrintF(buffer, kMaxErrorMsg - 1, format, arguments); |  250       base::OS::VSNPrintF(buffer, kMaxErrorMsg - 1, format, arguments); | 
|  249       va_end(arguments); |  251       va_end(arguments); | 
|  250       error_msg_.Reset(buffer); |  252       error_msg_.reset(buffer); | 
|  251       error_pc_ = pc; |  253       error_pc_ = pc; | 
|  252       error_pt_ = pt; |  254       error_pt_ = pt; | 
|  253       onFirstError(); |  255       onFirstError(); | 
|  254     } |  256     } | 
|  255   } |  257   } | 
|  256  |  258  | 
|  257   // Behavior triggered on first error, overridden in subclasses. |  259   // Behavior triggered on first error, overridden in subclasses. | 
|  258   virtual void onFirstError() {} |  260   virtual void onFirstError() {} | 
|  259  |  261  | 
|  260   // Debugging helper to print bytes up to the end. |  262   // Debugging helper to print bytes up to the end. | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
|  273   template <typename T> |  275   template <typename T> | 
|  274   Result<T> toResult(T val) { |  276   Result<T> toResult(T val) { | 
|  275     Result<T> result; |  277     Result<T> result; | 
|  276     if (error_pc_) { |  278     if (error_pc_) { | 
|  277       TRACE("Result error: %s\n", error_msg_.get()); |  279       TRACE("Result error: %s\n", error_msg_.get()); | 
|  278       result.error_code = kError; |  280       result.error_code = kError; | 
|  279       result.start = start_; |  281       result.start = start_; | 
|  280       result.error_pc = error_pc_; |  282       result.error_pc = error_pc_; | 
|  281       result.error_pt = error_pt_; |  283       result.error_pt = error_pt_; | 
|  282       // transfer ownership of the error to the result. |  284       // transfer ownership of the error to the result. | 
|  283       result.error_msg.Reset(error_msg_.Detach()); |  285       result.error_msg.reset(error_msg_.release()); | 
|  284     } else { |  286     } else { | 
|  285       result.error_code = kSuccess; |  287       result.error_code = kSuccess; | 
|  286     } |  288     } | 
|  287     result.val = std::move(val); |  289     result.val = std::move(val); | 
|  288     return result; |  290     return result; | 
|  289   } |  291   } | 
|  290  |  292  | 
|  291   // Resets the boundaries of this decoder. |  293   // Resets the boundaries of this decoder. | 
|  292   void Reset(const byte* start, const byte* end) { |  294   void Reset(const byte* start, const byte* end) { | 
|  293     start_ = start; |  295     start_ = start; | 
|  294     pc_ = start; |  296     pc_ = start; | 
|  295     limit_ = end; |  297     limit_ = end; | 
|  296     end_ = end; |  298     end_ = end; | 
|  297     error_pc_ = nullptr; |  299     error_pc_ = nullptr; | 
|  298     error_pt_ = nullptr; |  300     error_pt_ = nullptr; | 
|  299     error_msg_.Reset(nullptr); |  301     error_msg_.reset(); | 
|  300   } |  302   } | 
|  301  |  303  | 
|  302   bool ok() const { return error_pc_ == nullptr; } |  304   bool ok() const { return error_pc_ == nullptr; } | 
|  303   bool failed() const { return !error_msg_.is_empty(); } |  305   bool failed() const { return !!error_msg_; } | 
|  304   bool more() const { return pc_ < limit_; } |  306   bool more() const { return pc_ < limit_; } | 
|  305  |  307  | 
|  306   const byte* start() { return start_; } |  308   const byte* start() { return start_; } | 
|  307   const byte* pc() { return pc_; } |  309   const byte* pc() { return pc_; } | 
|  308   uint32_t pc_offset() { return static_cast<uint32_t>(pc_ - start_); } |  310   uint32_t pc_offset() { return static_cast<uint32_t>(pc_ - start_); } | 
|  309  |  311  | 
|  310  protected: |  312  protected: | 
|  311   const byte* start_; |  313   const byte* start_; | 
|  312   const byte* pc_; |  314   const byte* pc_; | 
|  313   const byte* limit_; |  315   const byte* limit_; | 
|  314   const byte* end_; |  316   const byte* end_; | 
|  315   const byte* error_pc_; |  317   const byte* error_pc_; | 
|  316   const byte* error_pt_; |  318   const byte* error_pt_; | 
|  317   base::SmartArrayPointer<char> error_msg_; |  319   std::unique_ptr<char[]> error_msg_; | 
|  318  |  320  | 
|  319  private: |  321  private: | 
|  320   template <typename IntType, bool is_signed> |  322   template <typename IntType, bool is_signed> | 
|  321   IntType checked_read_leb(const byte* base, unsigned offset, unsigned* length, |  323   IntType checked_read_leb(const byte* base, unsigned offset, unsigned* length, | 
|  322                            const char* msg) { |  324                            const char* msg) { | 
|  323     if (!check(base, offset, 1, msg)) { |  325     if (!check(base, offset, 1, msg)) { | 
|  324       *length = 0; |  326       *length = 0; | 
|  325       return 0; |  327       return 0; | 
|  326     } |  328     } | 
|  327  |  329  | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  370     return result; |  372     return result; | 
|  371   } |  373   } | 
|  372 }; |  374 }; | 
|  373  |  375  | 
|  374 #undef TRACE |  376 #undef TRACE | 
|  375 }  // namespace wasm |  377 }  // namespace wasm | 
|  376 }  // namespace internal |  378 }  // namespace internal | 
|  377 }  // namespace v8 |  379 }  // namespace v8 | 
|  378  |  380  | 
|  379 #endif  // V8_WASM_DECODER_H_ |  381 #endif  // V8_WASM_DECODER_H_ | 
| OLD | NEW |