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> | 8 #include <memory> |
9 | 9 |
10 #include "src/base/compiler-specific.h" | 10 #include "src/base/compiler-specific.h" |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 } | 246 } |
247 TRACE("<end>\n"); | 247 TRACE("<end>\n"); |
248 pc_ = limit_; | 248 pc_ = limit_; |
249 return t; | 249 return t; |
250 } | 250 } |
251 | 251 |
252 // Converts the given value to a {Result}, copying the error if necessary. | 252 // Converts the given value to a {Result}, copying the error if necessary. |
253 template <typename T> | 253 template <typename T> |
254 Result<T> toResult(T val) { | 254 Result<T> toResult(T val) { |
255 Result<T> result; | 255 Result<T> result; |
256 if (error_pc_) { | 256 if (failed()) { |
257 TRACE("Result error: %s\n", error_msg_.get()); | 257 TRACE("Result error: %s\n", error_msg_.get()); |
258 result.error_code = kError; | 258 result.error_code = kError; |
259 result.start = start_; | 259 result.start = start_; |
260 result.error_pc = error_pc_; | 260 result.error_pc = error_pc_; |
261 result.error_pt = error_pt_; | 261 result.error_pt = error_pt_; |
262 // transfer ownership of the error to the result. | 262 // transfer ownership of the error to the result. |
263 result.error_msg.reset(error_msg_.release()); | 263 result.error_msg.reset(error_msg_.release()); |
264 } else { | 264 } else { |
265 result.error_code = kSuccess; | 265 result.error_code = kSuccess; |
266 } | 266 } |
267 result.val = std::move(val); | 267 result.val = std::move(val); |
268 return result; | 268 return result; |
269 } | 269 } |
270 | 270 |
271 // Resets the boundaries of this decoder. | 271 // Resets the boundaries of this decoder. |
272 void Reset(const byte* start, const byte* end) { | 272 void Reset(const byte* start, const byte* end) { |
273 start_ = start; | 273 start_ = start; |
274 pc_ = start; | 274 pc_ = start; |
275 limit_ = end; | 275 limit_ = end; |
276 end_ = end; | 276 end_ = end; |
277 error_pc_ = nullptr; | 277 error_pc_ = nullptr; |
278 error_pt_ = nullptr; | 278 error_pt_ = nullptr; |
279 error_msg_.reset(); | 279 error_msg_.reset(); |
280 } | 280 } |
281 | 281 |
282 bool ok() const { return error_pc_ == nullptr; } | 282 bool ok() const { return error_msg_ == nullptr; } |
283 bool failed() const { return !!error_msg_; } | 283 bool failed() const { return !ok(); } |
284 bool more() const { return pc_ < limit_; } | 284 bool more() const { return pc_ < limit_; } |
285 | 285 |
286 const byte* start() { return start_; } | 286 const byte* start() { return start_; } |
287 const byte* pc() { return pc_; } | 287 const byte* pc() { return pc_; } |
288 uint32_t pc_offset() { return static_cast<uint32_t>(pc_ - start_); } | 288 uint32_t pc_offset() { return static_cast<uint32_t>(pc_ - start_); } |
289 | 289 |
290 protected: | 290 protected: |
291 const byte* start_; | 291 const byte* start_; |
292 const byte* pc_; | 292 const byte* pc_; |
293 const byte* limit_; | 293 const byte* limit_; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 return traceOffEnd<uint32_t>(); | 391 return traceOffEnd<uint32_t>(); |
392 } | 392 } |
393 }; | 393 }; |
394 | 394 |
395 #undef TRACE | 395 #undef TRACE |
396 } // namespace wasm | 396 } // namespace wasm |
397 } // namespace internal | 397 } // namespace internal |
398 } // namespace v8 | 398 } // namespace v8 |
399 | 399 |
400 #endif // V8_WASM_DECODER_H_ | 400 #endif // V8_WASM_DECODER_H_ |
OLD | NEW |