| 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 "test/unittests/test-utils.h" | 5 #include "test/unittests/test-utils.h" |
| 6 | 6 |
| 7 #include "src/v8.h" | 7 #include "src/v8.h" |
| 8 | 8 |
| 9 #include "src/wasm/ast-decoder.h" | 9 #include "src/wasm/ast-decoder.h" |
| 10 #include "src/wasm/encoder.h" | 10 #include "src/wasm/encoder.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 function->EmitCode(code, sizeof(code), local_indices, 1); | 79 function->EmitCode(code, sizeof(code), local_indices, 1); |
| 80 code[1] = static_cast<uint8_t>(local_f64); | 80 code[1] = static_cast<uint8_t>(local_f64); |
| 81 function->EmitCode(code, sizeof(code), local_indices, 1); | 81 function->EmitCode(code, sizeof(code), local_indices, 1); |
| 82 | 82 |
| 83 WasmFunctionEncoder* f = function->Build(&zone, builder); | 83 WasmFunctionEncoder* f = function->Build(&zone, builder); |
| 84 ZoneVector<uint8_t> buffer_vector(f->HeaderSize() + f->BodySize(), &zone); | 84 ZoneVector<uint8_t> buffer_vector(f->HeaderSize() + f->BodySize(), &zone); |
| 85 byte* buffer = &buffer_vector[0]; | 85 byte* buffer = &buffer_vector[0]; |
| 86 byte* header = buffer; | 86 byte* header = buffer; |
| 87 byte* body = buffer + f->HeaderSize(); | 87 byte* body = buffer + f->HeaderSize(); |
| 88 f->Serialize(buffer, &header, &body); | 88 f->Serialize(buffer, &header, &body); |
| 89 for (size_t i = 0; i < 7; i++) { | |
| 90 CHECK_EQ(i, static_cast<size_t>(*(buffer + 2 * i + f->HeaderSize() + 1))); | |
| 91 } | |
| 92 } | 89 } |
| 93 | 90 |
| 94 | 91 |
| 95 TEST_F(EncoderTest, Function_Builder_Indexing_Variable_Width) { | 92 TEST_F(EncoderTest, Function_Builder_Indexing_Variable_Width) { |
| 96 Zone zone; | 93 Zone zone; |
| 97 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 94 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 98 uint16_t f_index = builder->AddFunction(); | 95 uint16_t f_index = builder->AddFunction(); |
| 99 WasmFunctionBuilder* function = builder->FunctionAt(f_index); | 96 WasmFunctionBuilder* function = builder->FunctionAt(f_index); |
| 100 for (size_t i = 0; i < 128; i++) { | 97 for (size_t i = 0; i < 128; i++) { |
| 101 AddLocal(function, kAstF32); | 98 AddLocal(function, kAstF32); |
| 102 } | 99 } |
| 103 AddLocal(function, kAstI32); | 100 AddLocal(function, kAstI32); |
| 104 | 101 |
| 105 WasmFunctionEncoder* f = function->Build(&zone, builder); | 102 WasmFunctionEncoder* f = function->Build(&zone, builder); |
| 106 ZoneVector<uint8_t> buffer_vector(f->HeaderSize() + f->BodySize(), &zone); | 103 ZoneVector<uint8_t> buffer_vector(f->HeaderSize() + f->BodySize(), &zone); |
| 107 byte* buffer = &buffer_vector[0]; | 104 byte* buffer = &buffer_vector[0]; |
| 108 byte* header = buffer; | 105 byte* header = buffer; |
| 109 byte* body = buffer + f->HeaderSize(); | 106 byte* body = buffer + f->HeaderSize(); |
| 110 f->Serialize(buffer, &header, &body); | 107 f->Serialize(buffer, &header, &body); |
| 111 body = buffer + f->HeaderSize(); | 108 body = buffer + f->HeaderSize(); |
| 112 for (size_t i = 0; i < 127; i++) { | |
| 113 CHECK_EQ(kExprGetLocal, static_cast<size_t>(*(body + 2 * i))); | |
| 114 CHECK_EQ(i + 1, static_cast<size_t>(*(body + 2 * i + 1))); | |
| 115 } | |
| 116 CHECK_EQ(kExprGetLocal, static_cast<size_t>(*(body + 2 * 127))); | |
| 117 CHECK_EQ(0x80, static_cast<size_t>(*(body + 2 * 127 + 1))); | |
| 118 CHECK_EQ(0x01, static_cast<size_t>(*(body + 2 * 127 + 2))); | |
| 119 CHECK_EQ(kExprGetLocal, static_cast<size_t>(*(body + 2 * 127 + 3))); | |
| 120 CHECK_EQ(0x00, static_cast<size_t>(*(body + 2 * 127 + 4))); | |
| 121 } | 109 } |
| 122 | 110 |
| 123 | 111 |
| 124 TEST_F(EncoderTest, LEB_Functions) { | 112 TEST_F(EncoderTest, LEB_Functions) { |
| 125 byte leb_value[5] = {0, 0, 0, 0, 0}; | 113 byte leb_value[5] = {0, 0, 0, 0, 0}; |
| 126 CheckReadValue(leb_value, 0, 1, kNoError); | 114 CheckReadValue(leb_value, 0, 1, kNoError); |
| 127 CheckWriteValue(0, 1, leb_value); | 115 CheckWriteValue(0, 1, leb_value); |
| 128 leb_value[0] = 23; | 116 leb_value[0] = 23; |
| 129 CheckReadValue(leb_value, 23, 1, kNoError); | 117 CheckReadValue(leb_value, 23, 1, kNoError); |
| 130 CheckWriteValue(23, 1, leb_value); | 118 CheckWriteValue(23, 1, leb_value); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 142 leb_value[0] = 0x80; | 130 leb_value[0] = 0x80; |
| 143 leb_value[1] = 0x80; | 131 leb_value[1] = 0x80; |
| 144 leb_value[2] = 0x80; | 132 leb_value[2] = 0x80; |
| 145 leb_value[3] = 0x80; | 133 leb_value[3] = 0x80; |
| 146 leb_value[4] = 0x80; | 134 leb_value[4] = 0x80; |
| 147 CheckReadValue(leb_value, -1, -1, kInvalidLEB128); | 135 CheckReadValue(leb_value, -1, -1, kInvalidLEB128); |
| 148 } | 136 } |
| 149 } // namespace wasm | 137 } // namespace wasm |
| 150 } // namespace internal | 138 } // namespace internal |
| 151 } // namespace v8 | 139 } // namespace v8 |
| OLD | NEW |