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 <stdlib.h> | 5 #include <stdlib.h> |
6 #include <string.h> | 6 #include <string.h> |
7 | 7 |
8 #include "src/wasm/encoder.h" | 8 #include "src/wasm/encoder.h" |
9 #include "src/wasm/wasm-js.h" | 9 #include "src/wasm/wasm-js.h" |
10 #include "src/wasm/wasm-macro-gen.h" | 10 #include "src/wasm/wasm-macro-gen.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 Zone zone; | 134 Zone zone; |
135 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 135 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
136 uint16_t f_index = builder->AddFunction(); | 136 uint16_t f_index = builder->AddFunction(); |
137 WasmFunctionBuilder* f = builder->FunctionAt(f_index); | 137 WasmFunctionBuilder* f = builder->FunctionAt(f_index); |
138 f->ReturnType(kAstI32); | 138 f->ReturnType(kAstI32); |
139 uint16_t localIndex = f->AddLocal(kAstI32); | 139 uint16_t localIndex = f->AddLocal(kAstI32); |
140 f->Exported(1); | 140 f->Exported(1); |
141 byte code[] = {WASM_BLOCK( | 141 byte code[] = {WASM_BLOCK( |
142 2, | 142 2, |
143 WASM_WHILE( | 143 WASM_WHILE( |
144 WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32V_3(kCheckSize)), | 144 WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32(kCheckSize)), |
145 WASM_IF_ELSE( | 145 WASM_IF_ELSE( |
146 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(localIndex)), | 146 WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(localIndex)), |
147 WASM_BRV(2, WASM_I8(-1)), WASM_INC_LOCAL_BY(localIndex, 4))), | 147 WASM_BRV(2, WASM_I8(-1)), WASM_INC_LOCAL_BY(localIndex, 4))), |
148 WASM_I8(11))}; | 148 WASM_I8(11))}; |
149 uint32_t local_indices[] = {7, 18, 24, 27}; | 149 uint32_t local_indices[] = {7, 19, 25, 28}; |
150 f->EmitCode(code, sizeof(code), local_indices, sizeof(local_indices) / 4); | 150 f->EmitCode(code, sizeof(code), local_indices, sizeof(local_indices) / 4); |
151 WasmModuleWriter* writer = builder->Build(&zone); | 151 WasmModuleWriter* writer = builder->Build(&zone); |
152 TestModule(writer->WriteTo(&zone), 11); | 152 TestModule(writer->WriteTo(&zone), 11); |
153 } | 153 } |
154 #endif | 154 #endif |
155 | 155 |
156 | 156 |
157 #if !defined(V8_WITH_ASAN) | 157 #if !defined(V8_WITH_ASAN) |
158 // TODO(bradnelson): Figure out why this crashes under asan. | 158 // TODO(bradnelson): Figure out why this crashes under asan. |
159 TEST(Run_WasmModule_CallMain_recursive) { | 159 TEST(Run_WasmModule_CallMain_recursive) { |
(...skipping 30 matching lines...) Expand all Loading... |
190 uint16_t f1_index = builder->AddFunction(); | 190 uint16_t f1_index = builder->AddFunction(); |
191 WasmFunctionBuilder* f = builder->FunctionAt(f1_index); | 191 WasmFunctionBuilder* f = builder->FunctionAt(f1_index); |
192 f->ReturnType(kAstI32); | 192 f->ReturnType(kAstI32); |
193 byte code1[] = { | 193 byte code1[] = { |
194 WASM_I32_ADD(WASM_LOAD_GLOBAL(global1), WASM_LOAD_GLOBAL(global2))}; | 194 WASM_I32_ADD(WASM_LOAD_GLOBAL(global1), WASM_LOAD_GLOBAL(global2))}; |
195 f->EmitCode(code1, sizeof(code1)); | 195 f->EmitCode(code1, sizeof(code1)); |
196 uint16_t f2_index = builder->AddFunction(); | 196 uint16_t f2_index = builder->AddFunction(); |
197 f = builder->FunctionAt(f2_index); | 197 f = builder->FunctionAt(f2_index); |
198 f->ReturnType(kAstI32); | 198 f->ReturnType(kAstI32); |
199 f->Exported(1); | 199 f->Exported(1); |
200 byte code2[] = {WASM_STORE_GLOBAL(global1, WASM_I32V_1(56)), | 200 byte code2[] = {WASM_STORE_GLOBAL(global1, WASM_I32(56)), |
201 WASM_STORE_GLOBAL(global2, WASM_I32V_1(41)), | 201 WASM_STORE_GLOBAL(global2, WASM_I32(41)), |
202 WASM_RETURN(WASM_CALL_FUNCTION0(f1_index))}; | 202 WASM_RETURN(WASM_CALL_FUNCTION0(f1_index))}; |
203 f->EmitCode(code2, sizeof(code2)); | 203 f->EmitCode(code2, sizeof(code2)); |
204 WasmModuleWriter* writer = builder->Build(&zone); | 204 WasmModuleWriter* writer = builder->Build(&zone); |
205 TestModule(writer->WriteTo(&zone), 97); | 205 TestModule(writer->WriteTo(&zone), 97); |
206 } | 206 } |
207 #endif | 207 #endif |
208 | 208 |
209 #endif // !V8_TARGET_ARCH_ARM64 | 209 #endif // !V8_TARGET_ARCH_ARM64 |
OLD | NEW |