OLD | NEW |
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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 } | 160 } |
161 | 161 |
162 int AddFunction(FunctionSig* sig, Handle<Code> code) { | 162 int AddFunction(FunctionSig* sig, Handle<Code> code) { |
163 if (module->functions.size() == 0) { | 163 if (module->functions.size() == 0) { |
164 // TODO(titzer): Reserving space here to avoid the underlying WasmFunction | 164 // TODO(titzer): Reserving space here to avoid the underlying WasmFunction |
165 // structs from moving. | 165 // structs from moving. |
166 module->functions.reserve(kMaxFunctions); | 166 module->functions.reserve(kMaxFunctions); |
167 } | 167 } |
168 uint32_t index = static_cast<uint32_t>(module->functions.size()); | 168 uint32_t index = static_cast<uint32_t>(module->functions.size()); |
169 module->functions.push_back( | 169 module->functions.push_back( |
170 {sig, index, 0, 0, 0, 0, 0, 0, 0, false, false}); | 170 {sig, index, 0, 0, 0, 0, 0, 0, 0, 0, 0, false, false}); |
171 instance->function_code.push_back(code); | 171 instance->function_code.push_back(code); |
172 DCHECK_LT(index, kMaxFunctions); // limited for testing. | 172 DCHECK_LT(index, kMaxFunctions); // limited for testing. |
173 return index; | 173 return index; |
174 } | 174 } |
175 | 175 |
176 void SetFunctionCode(uint32_t index, Handle<Code> code) { | 176 void SetFunctionCode(uint32_t index, Handle<Code> code) { |
177 instance->function_code[index] = code; | 177 instance->function_code[index] = code; |
178 } | 178 } |
179 | 179 |
180 void AddIndirectFunctionTable(int* functions, int table_size) { | 180 void AddIndirectFunctionTable(int* functions, int table_size) { |
(...skipping 21 matching lines...) Expand all Loading... |
202 | 202 |
203 private: | 203 private: |
204 WasmModule module_; | 204 WasmModule module_; |
205 WasmModuleInstance instance_; | 205 WasmModuleInstance instance_; |
206 uint32_t global_offset; | 206 uint32_t global_offset; |
207 V8_ALIGNED(8) byte global_data[kMaxGlobalsSize]; // preallocated global data. | 207 V8_ALIGNED(8) byte global_data[kMaxGlobalsSize]; // preallocated global data. |
208 | 208 |
209 WasmGlobal* AddGlobal(MachineType mem_type) { | 209 WasmGlobal* AddGlobal(MachineType mem_type) { |
210 byte size = WasmOpcodes::MemSize(mem_type); | 210 byte size = WasmOpcodes::MemSize(mem_type); |
211 global_offset = (global_offset + size - 1) & ~(size - 1); // align | 211 global_offset = (global_offset + size - 1) & ~(size - 1); // align |
212 module->globals.push_back({0, mem_type, global_offset, false}); | 212 module->globals.push_back({0, 0, mem_type, global_offset, false}); |
213 global_offset += size; | 213 global_offset += size; |
214 // limit number of globals. | 214 // limit number of globals. |
215 CHECK_LT(global_offset, kMaxGlobalsSize); | 215 CHECK_LT(global_offset, kMaxGlobalsSize); |
216 return &module->globals.back(); | 216 return &module->globals.back(); |
217 } | 217 } |
218 }; | 218 }; |
219 | 219 |
220 inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module, | 220 inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module, |
221 FunctionSig* sig, const byte* start, | 221 FunctionSig* sig, const byte* start, |
222 const byte* end) { | 222 const byte* end) { |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 if (p1 == MachineType::None()) return 1; | 592 if (p1 == MachineType::None()) return 1; |
593 if (p2 == MachineType::None()) return 2; | 593 if (p2 == MachineType::None()) return 2; |
594 if (p3 == MachineType::None()) return 3; | 594 if (p3 == MachineType::None()) return 3; |
595 return 4; | 595 return 4; |
596 } | 596 } |
597 }; | 597 }; |
598 | 598 |
599 } // namespace | 599 } // namespace |
600 | 600 |
601 #endif | 601 #endif |
OLD | NEW |