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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 const std::vector<uint8_t> result = UnsignedLEB128From(input); | 45 const std::vector<uint8_t> result = UnsignedLEB128From(input); |
46 CHECK_EQ(result.size(), length); | 46 CHECK_EQ(result.size(), length); |
47 for (int i = 0; i < length; i++) { | 47 for (int i = 0; i < length; i++) { |
48 CHECK_EQ(result.at(i), vals[i]); | 48 CHECK_EQ(result.at(i), vals[i]); |
49 } | 49 } |
50 } | 50 } |
51 }; | 51 }; |
52 | 52 |
53 | 53 |
54 TEST_F(EncoderTest, Function_Builder_Variable_Indexing) { | 54 TEST_F(EncoderTest, Function_Builder_Variable_Indexing) { |
55 Zone zone; | 55 base::AccountingAllocator allocator; |
| 56 Zone zone(&allocator); |
56 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 57 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
57 uint16_t f_index = builder->AddFunction(); | 58 uint16_t f_index = builder->AddFunction(); |
58 WasmFunctionBuilder* function = builder->FunctionAt(f_index); | 59 WasmFunctionBuilder* function = builder->FunctionAt(f_index); |
59 uint16_t local_f32 = function->AddLocal(kAstF32); | 60 uint16_t local_f32 = function->AddLocal(kAstF32); |
60 uint16_t param_float32 = function->AddParam(kAstF32); | 61 uint16_t param_float32 = function->AddParam(kAstF32); |
61 uint16_t local_i32 = function->AddLocal(kAstI32); | 62 uint16_t local_i32 = function->AddLocal(kAstI32); |
62 uint16_t local_f64 = function->AddLocal(kAstF64); | 63 uint16_t local_f64 = function->AddLocal(kAstF64); |
63 uint16_t local_i64 = function->AddLocal(kAstI64); | 64 uint16_t local_i64 = function->AddLocal(kAstI64); |
64 uint16_t param_int32 = function->AddParam(kAstI32); | 65 uint16_t param_int32 = function->AddParam(kAstI32); |
65 uint16_t local_i32_2 = function->AddLocal(kAstI32); | 66 uint16_t local_i32_2 = function->AddLocal(kAstI32); |
(...skipping 17 matching lines...) Expand all Loading... |
83 WasmFunctionEncoder* f = function->Build(&zone, builder); | 84 WasmFunctionEncoder* f = function->Build(&zone, builder); |
84 ZoneVector<uint8_t> buffer_vector(f->HeaderSize() + f->BodySize(), &zone); | 85 ZoneVector<uint8_t> buffer_vector(f->HeaderSize() + f->BodySize(), &zone); |
85 byte* buffer = &buffer_vector[0]; | 86 byte* buffer = &buffer_vector[0]; |
86 byte* header = buffer; | 87 byte* header = buffer; |
87 byte* body = buffer + f->HeaderSize(); | 88 byte* body = buffer + f->HeaderSize(); |
88 f->Serialize(buffer, &header, &body); | 89 f->Serialize(buffer, &header, &body); |
89 } | 90 } |
90 | 91 |
91 | 92 |
92 TEST_F(EncoderTest, Function_Builder_Indexing_Variable_Width) { | 93 TEST_F(EncoderTest, Function_Builder_Indexing_Variable_Width) { |
93 Zone zone; | 94 base::AccountingAllocator allocator; |
| 95 Zone zone(&allocator); |
94 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 96 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
95 uint16_t f_index = builder->AddFunction(); | 97 uint16_t f_index = builder->AddFunction(); |
96 WasmFunctionBuilder* function = builder->FunctionAt(f_index); | 98 WasmFunctionBuilder* function = builder->FunctionAt(f_index); |
97 for (size_t i = 0; i < 128; i++) { | 99 for (size_t i = 0; i < 128; i++) { |
98 AddLocal(function, kAstF32); | 100 AddLocal(function, kAstF32); |
99 } | 101 } |
100 AddLocal(function, kAstI32); | 102 AddLocal(function, kAstI32); |
101 | 103 |
102 WasmFunctionEncoder* f = function->Build(&zone, builder); | 104 WasmFunctionEncoder* f = function->Build(&zone, builder); |
103 ZoneVector<uint8_t> buffer_vector(f->HeaderSize() + f->BodySize(), &zone); | 105 ZoneVector<uint8_t> buffer_vector(f->HeaderSize() + f->BodySize(), &zone); |
104 byte* buffer = &buffer_vector[0]; | 106 byte* buffer = &buffer_vector[0]; |
105 byte* header = buffer; | 107 byte* header = buffer; |
106 byte* body = buffer + f->HeaderSize(); | 108 byte* body = buffer + f->HeaderSize(); |
107 f->Serialize(buffer, &header, &body); | 109 f->Serialize(buffer, &header, &body); |
108 body = buffer + f->HeaderSize(); | 110 body = buffer + f->HeaderSize(); |
109 } | 111 } |
110 | 112 |
111 TEST_F(EncoderTest, Function_Builder_Block_Variable_Width) { | 113 TEST_F(EncoderTest, Function_Builder_Block_Variable_Width) { |
112 Zone zone; | 114 base::AccountingAllocator allocator; |
| 115 Zone zone(&allocator); |
113 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 116 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
114 uint16_t f_index = builder->AddFunction(); | 117 uint16_t f_index = builder->AddFunction(); |
115 WasmFunctionBuilder* function = builder->FunctionAt(f_index); | 118 WasmFunctionBuilder* function = builder->FunctionAt(f_index); |
116 function->EmitWithVarInt(kExprBlock, 200); | 119 function->EmitWithVarInt(kExprBlock, 200); |
117 for (int i = 0; i < 200; ++i) { | 120 for (int i = 0; i < 200; ++i) { |
118 function->Emit(kExprNop); | 121 function->Emit(kExprNop); |
119 } | 122 } |
120 | 123 |
121 WasmFunctionEncoder* f = function->Build(&zone, builder); | 124 WasmFunctionEncoder* f = function->Build(&zone, builder); |
122 CHECK_EQ(f->BodySize(), 204); | 125 CHECK_EQ(f->BodySize(), 204); |
123 } | 126 } |
124 | 127 |
125 TEST_F(EncoderTest, Function_Builder_EmitEditableVarIntImmediate) { | 128 TEST_F(EncoderTest, Function_Builder_EmitEditableVarIntImmediate) { |
126 Zone zone; | 129 base::AccountingAllocator allocator; |
| 130 Zone zone(&allocator); |
127 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 131 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
128 uint16_t f_index = builder->AddFunction(); | 132 uint16_t f_index = builder->AddFunction(); |
129 WasmFunctionBuilder* function = builder->FunctionAt(f_index); | 133 WasmFunctionBuilder* function = builder->FunctionAt(f_index); |
130 function->Emit(kExprLoop); | 134 function->Emit(kExprLoop); |
131 uint32_t offset = function->EmitEditableVarIntImmediate(); | 135 uint32_t offset = function->EmitEditableVarIntImmediate(); |
132 for (int i = 0; i < 200; ++i) { | 136 for (int i = 0; i < 200; ++i) { |
133 function->Emit(kExprNop); | 137 function->Emit(kExprNop); |
134 } | 138 } |
135 function->EditVarIntImmediate(offset, 200); | 139 function->EditVarIntImmediate(offset, 200); |
136 | 140 |
137 WasmFunctionEncoder* f = function->Build(&zone, builder); | 141 WasmFunctionEncoder* f = function->Build(&zone, builder); |
138 CHECK_EQ(f->BodySize(), 204); | 142 CHECK_EQ(f->BodySize(), 204); |
139 } | 143 } |
140 | 144 |
141 TEST_F(EncoderTest, Function_Builder_EmitEditableVarIntImmediate_Locals) { | 145 TEST_F(EncoderTest, Function_Builder_EmitEditableVarIntImmediate_Locals) { |
142 Zone zone; | 146 base::AccountingAllocator allocator; |
| 147 Zone zone(&allocator); |
143 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 148 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
144 uint16_t f_index = builder->AddFunction(); | 149 uint16_t f_index = builder->AddFunction(); |
145 WasmFunctionBuilder* function = builder->FunctionAt(f_index); | 150 WasmFunctionBuilder* function = builder->FunctionAt(f_index); |
146 function->Emit(kExprBlock); | 151 function->Emit(kExprBlock); |
147 uint32_t offset = function->EmitEditableVarIntImmediate(); | 152 uint32_t offset = function->EmitEditableVarIntImmediate(); |
148 for (int i = 0; i < 200; ++i) { | 153 for (int i = 0; i < 200; ++i) { |
149 AddLocal(function, kAstI32); | 154 AddLocal(function, kAstI32); |
150 } | 155 } |
151 function->EditVarIntImmediate(offset, 200); | 156 function->EditVarIntImmediate(offset, 200); |
152 | 157 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 leb_value[0] = 0x80; | 209 leb_value[0] = 0x80; |
205 leb_value[1] = 0x80; | 210 leb_value[1] = 0x80; |
206 leb_value[2] = 0x80; | 211 leb_value[2] = 0x80; |
207 leb_value[3] = 0x80; | 212 leb_value[3] = 0x80; |
208 leb_value[4] = 0x80; | 213 leb_value[4] = 0x80; |
209 CheckReadValue(leb_value, -1, -1, kInvalidLEB128); | 214 CheckReadValue(leb_value, -1, -1, kInvalidLEB128); |
210 } | 215 } |
211 } // namespace wasm | 216 } // namespace wasm |
212 } // namespace internal | 217 } // namespace internal |
213 } // namespace v8 | 218 } // namespace v8 |
OLD | NEW |