| OLD | NEW |
| 1 // Copyright 2017 the V8 project authors. All rights reserved. | 1 // Copyright 2017 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 index = 0; | 50 index = 0; |
| 51 } | 51 } |
| 52 return split(index); | 52 return split(index); |
| 53 } | 53 } |
| 54 | 54 |
| 55 template <typename T> | 55 template <typename T> |
| 56 T get() { | 56 T get() { |
| 57 if (size() == 0) { | 57 if (size() == 0) { |
| 58 return T(); | 58 return T(); |
| 59 } else { | 59 } else { |
| 60 // We want to support the case where we have less than sizeof(T) bytes |
| 61 // remaining in the slice. For example, if we emit an i32 constant, it's |
| 62 // okay if we don't have a full four bytes available, we'll just use what |
| 63 // we have. We aren't concerned about endianness because we are generating |
| 64 // arbitrary expressions. |
| 60 const size_t num_bytes = std::min(sizeof(T), size()); | 65 const size_t num_bytes = std::min(sizeof(T), size()); |
| 61 T result; | 66 T result = T(); |
| 62 memcpy(&result, data_, num_bytes); | 67 memcpy(&result, data_, num_bytes); |
| 63 data_ += num_bytes; | 68 data_ += num_bytes; |
| 64 size_ -= num_bytes; | 69 size_ -= num_bytes; |
| 65 return result; | 70 return result; |
| 66 } | 71 } |
| 67 } | 72 } |
| 68 }; | 73 }; |
| 69 | 74 |
| 70 class WasmGenerator { | 75 class WasmGenerator { |
| 71 template <WasmOpcode Op, ValueType... Args> | 76 template <WasmOpcode Op, ValueType... Args> |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 if (!possible_nondeterminism && (result_interpreted != result_compiled)) { | 438 if (!possible_nondeterminism && (result_interpreted != result_compiled)) { |
| 434 printf("\nInterpreter returned 0x%x but compiled code returned 0x%x\n", | 439 printf("\nInterpreter returned 0x%x but compiled code returned 0x%x\n", |
| 435 result_interpreted, result_compiled); | 440 result_interpreted, result_compiled); |
| 436 V8_Fatal(__FILE__, __LINE__, "WasmCodeFuzzerHash=%x", | 441 V8_Fatal(__FILE__, __LINE__, "WasmCodeFuzzerHash=%x", |
| 437 v8::internal::StringHasher::HashSequentialString( | 442 v8::internal::StringHasher::HashSequentialString( |
| 438 data, static_cast<int>(size), WASM_CODE_FUZZER_HASH_SEED)); | 443 data, static_cast<int>(size), WASM_CODE_FUZZER_HASH_SEED)); |
| 439 } | 444 } |
| 440 } | 445 } |
| 441 return 0; | 446 return 0; |
| 442 } | 447 } |
| OLD | NEW |