Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(403)

Side by Side Diff: test/cctest/wasm/wasm-run-utils.h

Issue 1616973004: [wasm] Add utilities to print out WASM ast directly from the bytes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix arm64, use AddIndirectFunctionTable() more. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/wasm/test-signatures.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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 #ifndef WASM_RUN_UTILS_H 5 #ifndef WASM_RUN_UTILS_H
6 #define WASM_RUN_UTILS_H 6 #define WASM_RUN_UTILS_H
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <stdlib.h> 9 #include <stdlib.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 AllocModule(); 161 AllocModule();
162 if (module->functions == nullptr) { 162 if (module->functions == nullptr) {
163 module->functions = new std::vector<WasmFunction>(); 163 module->functions = new std::vector<WasmFunction>();
164 function_code = new std::vector<Handle<Code>>(); 164 function_code = new std::vector<Handle<Code>>();
165 } 165 }
166 module->functions->push_back({sig, 0, 0, 0, 0, 0, 0, 0, false, false}); 166 module->functions->push_back({sig, 0, 0, 0, 0, 0, 0, 0, false, false});
167 function_code->push_back(code); 167 function_code->push_back(code);
168 return &module->functions->back(); 168 return &module->functions->back();
169 } 169 }
170 170
171 void AddIndirectFunctionTable(int* functions, int table_size) {
172 AllocModule();
173 Isolate* isolate = module->shared_isolate;
174 Handle<FixedArray> fixed =
175 isolate->factory()->NewFixedArray(2 * table_size);
176 function_table = fixed;
177 module->function_table = new std::vector<uint16_t>();
178 for (int i = 0; i < table_size; i++) {
179 module->function_table->push_back(functions[i]);
180 }
181 }
182
183 void PopulateIndirectFunctionTable() {
184 if (function_table.is_null()) return;
185 int table_size = static_cast<int>(module->function_table->size());
186 for (int i = 0; i < table_size; i++) {
187 int function_index = module->function_table->at(i);
188 WasmFunction* function = &module->functions->at(function_index);
189 function_table->set(i, Smi::FromInt(function->sig_index));
190 function_table->set(i + table_size, *function_code->at(function_index));
191 }
192 }
193
194
171 private: 195 private:
172 size_t mem_size; 196 size_t mem_size;
173 uint32_t global_offset; 197 uint32_t global_offset;
174 byte global_data[kMaxGlobalsSize]; 198 byte global_data[kMaxGlobalsSize];
175 199
176 WasmGlobal* AddGlobal(MachineType mem_type) { 200 WasmGlobal* AddGlobal(MachineType mem_type) {
177 AllocModule(); 201 AllocModule();
178 if (globals_area == 0) { 202 if (globals_area == 0) {
179 globals_area = reinterpret_cast<uintptr_t>(global_data); 203 globals_area = reinterpret_cast<uintptr_t>(global_data);
180 module->globals = new std::vector<WasmGlobal>(); 204 module->globals = new std::vector<WasmGlobal>();
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 #ifdef ENABLE_DISASSEMBLER 288 #ifdef ENABLE_DISASSEMBLER
265 if (!result.is_null() && FLAG_print_opt_code) { 289 if (!result.is_null() && FLAG_print_opt_code) {
266 OFStream os(stdout); 290 OFStream os(stdout);
267 result->Disassemble("wasm code", os); 291 result->Disassemble("wasm code", os);
268 } 292 }
269 #endif 293 #endif
270 294
271 return result; 295 return result;
272 } 296 }
273 297
274 uint32_t CompileAndAdd(TestingModule* module) { 298 uint32_t CompileAndAdd(TestingModule* module, int sig_index = 0) {
275 uint32_t index = 0; 299 uint32_t index = 0;
276 if (module->module && module->module->functions) { 300 if (module->module && module->module->functions) {
277 index = static_cast<uint32_t>(module->module->functions->size()); 301 index = static_cast<uint32_t>(module->module->functions->size());
278 } 302 }
279 module->AddFunction(env.sig, Compile(module)); 303 WasmFunction* function = module->AddFunction(env.sig, Compile(module));
304 function->sig_index = sig_index;
280 return index; 305 return index;
281 } 306 }
282 }; 307 };
283 308
284 309
285 // A helper class to build graphs from Wasm bytecode, generate machine 310 // A helper class to build graphs from Wasm bytecode, generate machine
286 // code, and run that code. 311 // code, and run that code.
287 template <typename ReturnType> 312 template <typename ReturnType>
288 class WasmRunner { 313 class WasmRunner {
289 public: 314 public:
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 if (p1 == MachineType::None()) return 1; 407 if (p1 == MachineType::None()) return 1;
383 if (p2 == MachineType::None()) return 2; 408 if (p2 == MachineType::None()) return 2;
384 if (p3 == MachineType::None()) return 3; 409 if (p3 == MachineType::None()) return 3;
385 return 4; 410 return 4;
386 } 411 }
387 }; 412 };
388 413
389 } // namespace 414 } // namespace
390 415
391 #endif 416 #endif
OLDNEW
« no previous file with comments | « test/cctest/wasm/test-signatures.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698