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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Zone zone; |
56 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 56 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
57 uint16_t f_index = builder->AddFunction(); | 57 uint16_t f_index = builder->AddFunction(); |
58 WasmFunctionBuilder* function = builder->FunctionAt(f_index); | 58 WasmFunctionBuilder* function = builder->FunctionAt(f_index); |
59 uint16_t local_float32 = function->AddLocal(kAstF32); | 59 uint16_t local_f32 = function->AddLocal(kAstF32); |
60 uint16_t param_float32 = function->AddParam(kAstF32); | 60 uint16_t param_float32 = function->AddParam(kAstF32); |
61 uint16_t local_int32 = function->AddLocal(kAstI32); | 61 uint16_t local_i32 = function->AddLocal(kAstI32); |
62 uint16_t local_float64 = function->AddLocal(kAstF64); | 62 uint16_t local_f64 = function->AddLocal(kAstF64); |
63 uint16_t local_int64 = function->AddLocal(kAstI64); | 63 uint16_t local_i64 = function->AddLocal(kAstI64); |
64 uint16_t param_int32 = function->AddParam(kAstI32); | 64 uint16_t param_int32 = function->AddParam(kAstI32); |
65 uint16_t local_int32_2 = function->AddLocal(kAstI32); | 65 uint16_t local_i32_2 = function->AddLocal(kAstI32); |
66 | 66 |
67 byte code[] = {kExprGetLocal, static_cast<uint8_t>(param_float32)}; | 67 byte code[] = {kExprGetLocal, static_cast<uint8_t>(param_float32)}; |
68 uint32_t local_indices[] = {1}; | 68 uint32_t local_indices[] = {1}; |
69 function->EmitCode(code, sizeof(code), local_indices, 1); | 69 function->EmitCode(code, sizeof(code), local_indices, 1); |
70 code[1] = static_cast<uint8_t>(param_int32); | 70 code[1] = static_cast<uint8_t>(param_int32); |
71 function->EmitCode(code, sizeof(code), local_indices, 1); | 71 function->EmitCode(code, sizeof(code), local_indices, 1); |
72 code[1] = static_cast<uint8_t>(local_int32); | 72 code[1] = static_cast<uint8_t>(local_i32); |
73 function->EmitCode(code, sizeof(code), local_indices, 1); | 73 function->EmitCode(code, sizeof(code), local_indices, 1); |
74 code[1] = static_cast<uint8_t>(local_int32_2); | 74 code[1] = static_cast<uint8_t>(local_i32_2); |
75 function->EmitCode(code, sizeof(code), local_indices, 1); | 75 function->EmitCode(code, sizeof(code), local_indices, 1); |
76 code[1] = static_cast<uint8_t>(local_int64); | 76 code[1] = static_cast<uint8_t>(local_i64); |
77 function->EmitCode(code, sizeof(code), local_indices, 1); | 77 function->EmitCode(code, sizeof(code), local_indices, 1); |
78 code[1] = static_cast<uint8_t>(local_float32); | 78 code[1] = static_cast<uint8_t>(local_f32); |
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_float64); | 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++) { | 89 for (size_t i = 0; i < 7; i++) { |
90 CHECK_EQ(i, static_cast<size_t>(*(buffer + 2 * i + f->HeaderSize() + 1))); | 90 CHECK_EQ(i, static_cast<size_t>(*(buffer + 2 * i + f->HeaderSize() + 1))); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 leb_value[0] = 0x80; | 142 leb_value[0] = 0x80; |
143 leb_value[1] = 0x80; | 143 leb_value[1] = 0x80; |
144 leb_value[2] = 0x80; | 144 leb_value[2] = 0x80; |
145 leb_value[3] = 0x80; | 145 leb_value[3] = 0x80; |
146 leb_value[4] = 0x80; | 146 leb_value[4] = 0x80; |
147 CheckReadValue(leb_value, -1, -1, kInvalidLEB128); | 147 CheckReadValue(leb_value, -1, -1, kInvalidLEB128); |
148 } | 148 } |
149 } // namespace wasm | 149 } // namespace wasm |
150 } // namespace internal | 150 } // namespace internal |
151 } // namespace v8 | 151 } // namespace v8 |
OLD | NEW |