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 #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 Loading... |
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()); | |
217 void AddDataSegment(const byte* data, uint32_t size, uint32_t dest); | 216 void AddDataSegment(const byte* data, uint32_t size, uint32_t dest); |
218 uint32_t AddSignature(FunctionSig* sig); | 217 uint32_t AddSignature(FunctionSig* sig); |
219 void AddIndirectFunction(uint32_t index); | 218 void AddIndirectFunction(uint32_t index); |
220 void MarkStartFunction(WasmFunctionBuilder* builder); | 219 void MarkStartFunction(WasmFunctionBuilder* builder); |
221 | 220 |
222 // Writing methods. | 221 // Writing methods. |
223 void WriteTo(ZoneBuffer& buffer) const; | 222 void WriteTo(ZoneBuffer& buffer) const; |
224 | 223 |
225 struct CompareFunctionSigs { | 224 struct CompareFunctionSigs { |
226 bool operator()(FunctionSig* a, FunctionSig* b) const; | 225 bool operator()(FunctionSig* a, FunctionSig* b) const; |
227 }; | 226 }; |
228 typedef ZoneMap<FunctionSig*, uint32_t, CompareFunctionSigs> SignatureMap; | 227 typedef ZoneMap<FunctionSig*, uint32_t, CompareFunctionSigs> SignatureMap; |
229 | 228 |
230 Zone* zone() { return zone_; } | 229 Zone* zone() { return zone_; } |
231 | 230 |
232 FunctionSig* GetSignature(uint32_t index) { return signatures_[index]; } | 231 FunctionSig* GetSignature(uint32_t index) { return signatures_[index]; } |
233 | 232 |
234 private: | 233 private: |
235 struct WasmFunctionImport { | 234 struct WasmFunctionImport { |
236 uint32_t sig_index; | 235 uint32_t sig_index; |
237 const char* name; | 236 const char* name; |
238 int name_length; | 237 int name_length; |
239 }; | 238 }; |
240 | 239 |
241 struct WasmGlobal { | 240 struct WasmGlobal { |
242 LocalType type; | 241 LocalType type; |
243 bool exported; | 242 bool exported; |
244 bool mutability; | 243 bool mutability; |
245 WasmInitExpr init; | |
246 }; | 244 }; |
247 | 245 |
248 struct WasmDataSegment { | 246 struct WasmDataSegment { |
249 ZoneVector<byte> data; | 247 ZoneVector<byte> data; |
250 uint32_t dest; | 248 uint32_t dest; |
251 }; | 249 }; |
252 | 250 |
253 friend class WasmFunctionBuilder; | 251 friend class WasmFunctionBuilder; |
254 Zone* zone_; | 252 Zone* zone_; |
255 ZoneVector<FunctionSig*> signatures_; | 253 ZoneVector<FunctionSig*> signatures_; |
256 ZoneVector<WasmFunctionImport> imports_; | 254 ZoneVector<WasmFunctionImport> imports_; |
257 ZoneVector<WasmFunctionBuilder*> functions_; | 255 ZoneVector<WasmFunctionBuilder*> functions_; |
258 ZoneVector<WasmDataSegment> data_segments_; | 256 ZoneVector<WasmDataSegment> data_segments_; |
259 ZoneVector<uint32_t> indirect_functions_; | 257 ZoneVector<uint32_t> indirect_functions_; |
260 ZoneVector<WasmGlobal> globals_; | 258 ZoneVector<WasmGlobal> globals_; |
261 SignatureMap signature_map_; | 259 SignatureMap signature_map_; |
262 int start_function_index_; | 260 int start_function_index_; |
263 }; | 261 }; |
264 | 262 |
265 inline FunctionSig* WasmFunctionBuilder::signature() { | 263 inline FunctionSig* WasmFunctionBuilder::signature() { |
266 return builder_->signatures_[signature_index_]; | 264 return builder_->signatures_[signature_index_]; |
267 } | 265 } |
268 | 266 |
269 } // namespace wasm | 267 } // namespace wasm |
270 } // namespace internal | 268 } // namespace internal |
271 } // namespace v8 | 269 } // namespace v8 |
272 | 270 |
273 #endif // V8_WASM_WASM_MODULE_BUILDER_H_ | 271 #endif // V8_WASM_WASM_MODULE_BUILDER_H_ |
OLD | NEW |