| 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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 } else { | 201 } else { |
| 202 TRACE("= %u\n", result); | 202 TRACE("= %u\n", result); |
| 203 } | 203 } |
| 204 return result; | 204 return result; |
| 205 } | 205 } |
| 206 return traceOffEnd<uint32_t>(); | 206 return traceOffEnd<uint32_t>(); |
| 207 } | 207 } |
| 208 | 208 |
| 209 // Consume {size} bytes and send them to the bit bucket, advancing {pc_}. | 209 // Consume {size} bytes and send them to the bit bucket, advancing {pc_}. |
| 210 void consume_bytes(int size) { | 210 void consume_bytes(int size) { |
| 211 TRACE(" +%d %-20s: %d bytes\n", static_cast<int>(pc_ - start_), "skip", | |
| 212 size); | |
| 213 if (checkAvailable(size)) { | 211 if (checkAvailable(size)) { |
| 214 pc_ += size; | 212 pc_ += size; |
| 215 } else { | 213 } else { |
| 216 pc_ = limit_; | |
| 217 } | |
| 218 } | |
| 219 | |
| 220 // Consume {size} bytes and send them to the bit bucket, advancing {pc_}. | |
| 221 void consume_bytes(uint32_t size, const char* name = "skip") { | |
| 222 TRACE(" +%d %-20s: %d bytes\n", static_cast<int>(pc_ - start_), name, | |
| 223 size); | |
| 224 if (checkAvailable(size)) { | |
| 225 pc_ += size; | |
| 226 } else { | |
| 227 pc_ = limit_; | 214 pc_ = limit_; |
| 228 } | 215 } |
| 229 } | 216 } |
| 230 | 217 |
| 231 // Check that at least {size} bytes exist between {pc_} and {limit_}. | 218 // Check that at least {size} bytes exist between {pc_} and {limit_}. |
| 232 bool checkAvailable(int size) { | 219 bool checkAvailable(int size) { |
| 233 intptr_t pc_overflow_value = std::numeric_limits<intptr_t>::max() - size; | 220 intptr_t pc_overflow_value = std::numeric_limits<intptr_t>::max() - size; |
| 234 if (size < 0 || (intptr_t)pc_ > pc_overflow_value) { | 221 if (size < 0 || (intptr_t)pc_ > pc_overflow_value) { |
| 235 error(pc_, nullptr, "reading %d bytes would underflow/overflow", size); | 222 error(pc_, nullptr, "reading %d bytes would underflow/overflow", size); |
| 236 return false; | 223 return false; |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 return result; | 371 return result; |
| 385 } | 372 } |
| 386 }; | 373 }; |
| 387 | 374 |
| 388 #undef TRACE | 375 #undef TRACE |
| 389 } // namespace wasm | 376 } // namespace wasm |
| 390 } // namespace internal | 377 } // namespace internal |
| 391 } // namespace v8 | 378 } // namespace v8 |
| 392 | 379 |
| 393 #endif // V8_WASM_DECODER_H_ | 380 #endif // V8_WASM_DECODER_H_ |
| OLD | NEW |