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

Side by Side Diff: src/wasm/wasm-module-builder.h

Issue 2390113003: [wasm] Refactor import handling for 0xC. (Closed)
Patch Set: Fix gc stress failure Created 4 years, 2 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 | « src/wasm/wasm-module.cc ('k') | src/wasm/wasm-module-builder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef V8_WASM_WASM_MODULE_BUILDER_H_ 5 #ifndef V8_WASM_WASM_MODULE_BUILDER_H_
6 #define V8_WASM_WASM_MODULE_BUILDER_H_ 6 #define V8_WASM_WASM_MODULE_BUILDER_H_
7 7
8 #include "src/signature.h" 8 #include "src/signature.h"
9 #include "src/zone/zone-containers.h" 9 #include "src/zone/zone-containers.h"
10 10
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 public: 205 public:
206 explicit WasmModuleBuilder(Zone* zone); 206 explicit WasmModuleBuilder(Zone* zone);
207 207
208 // Building methods. 208 // Building methods.
209 uint32_t AddImport(const char* name, int name_length, FunctionSig* sig); 209 uint32_t AddImport(const char* name, int name_length, FunctionSig* sig);
210 void SetImportName(uint32_t index, const char* name, int name_length) { 210 void SetImportName(uint32_t index, const char* name, int name_length) {
211 imports_[index].name = name; 211 imports_[index].name = name;
212 imports_[index].name_length = name_length; 212 imports_[index].name_length = name_length;
213 } 213 }
214 WasmFunctionBuilder* AddFunction(FunctionSig* sig = nullptr); 214 WasmFunctionBuilder* AddFunction(FunctionSig* sig = nullptr);
215 uint32_t AddGlobal(LocalType type, bool exported, bool mutability = true); 215 uint32_t AddGlobal(LocalType type, bool exported, bool mutability = true,
216 const WasmInitExpr& init = WasmInitExpr());
216 void AddDataSegment(const byte* data, uint32_t size, uint32_t dest); 217 void AddDataSegment(const byte* data, uint32_t size, uint32_t dest);
217 uint32_t AddSignature(FunctionSig* sig); 218 uint32_t AddSignature(FunctionSig* sig);
218 void AddIndirectFunction(uint32_t index); 219 void AddIndirectFunction(uint32_t index);
219 void MarkStartFunction(WasmFunctionBuilder* builder); 220 void MarkStartFunction(WasmFunctionBuilder* builder);
220 221
221 // Writing methods. 222 // Writing methods.
222 void WriteTo(ZoneBuffer& buffer) const; 223 void WriteTo(ZoneBuffer& buffer) const;
223 224
224 struct CompareFunctionSigs { 225 struct CompareFunctionSigs {
225 bool operator()(FunctionSig* a, FunctionSig* b) const; 226 bool operator()(FunctionSig* a, FunctionSig* b) const;
226 }; 227 };
227 typedef ZoneMap<FunctionSig*, uint32_t, CompareFunctionSigs> SignatureMap; 228 typedef ZoneMap<FunctionSig*, uint32_t, CompareFunctionSigs> SignatureMap;
228 229
229 Zone* zone() { return zone_; } 230 Zone* zone() { return zone_; }
230 231
231 FunctionSig* GetSignature(uint32_t index) { return signatures_[index]; } 232 FunctionSig* GetSignature(uint32_t index) { return signatures_[index]; }
232 233
233 private: 234 private:
234 struct WasmFunctionImport { 235 struct WasmFunctionImport {
235 uint32_t sig_index; 236 uint32_t sig_index;
236 const char* name; 237 const char* name;
237 int name_length; 238 int name_length;
238 }; 239 };
239 240
240 struct WasmGlobal { 241 struct WasmGlobal {
241 LocalType type; 242 LocalType type;
242 bool exported; 243 bool exported;
243 bool mutability; 244 bool mutability;
245 WasmInitExpr init;
244 }; 246 };
245 247
246 struct WasmDataSegment { 248 struct WasmDataSegment {
247 ZoneVector<byte> data; 249 ZoneVector<byte> data;
248 uint32_t dest; 250 uint32_t dest;
249 }; 251 };
250 252
251 friend class WasmFunctionBuilder; 253 friend class WasmFunctionBuilder;
252 Zone* zone_; 254 Zone* zone_;
253 ZoneVector<FunctionSig*> signatures_; 255 ZoneVector<FunctionSig*> signatures_;
254 ZoneVector<WasmFunctionImport> imports_; 256 ZoneVector<WasmFunctionImport> imports_;
255 ZoneVector<WasmFunctionBuilder*> functions_; 257 ZoneVector<WasmFunctionBuilder*> functions_;
256 ZoneVector<WasmDataSegment> data_segments_; 258 ZoneVector<WasmDataSegment> data_segments_;
257 ZoneVector<uint32_t> indirect_functions_; 259 ZoneVector<uint32_t> indirect_functions_;
258 ZoneVector<WasmGlobal> globals_; 260 ZoneVector<WasmGlobal> globals_;
259 SignatureMap signature_map_; 261 SignatureMap signature_map_;
260 int start_function_index_; 262 int start_function_index_;
261 }; 263 };
262 264
263 inline FunctionSig* WasmFunctionBuilder::signature() { 265 inline FunctionSig* WasmFunctionBuilder::signature() {
264 return builder_->signatures_[signature_index_]; 266 return builder_->signatures_[signature_index_];
265 } 267 }
266 268
267 } // namespace wasm 269 } // namespace wasm
268 } // namespace internal 270 } // namespace internal
269 } // namespace v8 271 } // namespace v8
270 272
271 #endif // V8_WASM_WASM_MODULE_BUILDER_H_ 273 #endif // V8_WASM_WASM_MODULE_BUILDER_H_
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | src/wasm/wasm-module-builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698