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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 byte* pos_; | 113 byte* pos_; |
114 byte* end_; | 114 byte* end_; |
115 }; | 115 }; |
116 | 116 |
117 class WasmModuleBuilder; | 117 class WasmModuleBuilder; |
118 | 118 |
119 class V8_EXPORT_PRIVATE WasmFunctionBuilder : public ZoneObject { | 119 class V8_EXPORT_PRIVATE WasmFunctionBuilder : public ZoneObject { |
120 public: | 120 public: |
121 // Building methods. | 121 // Building methods. |
122 void SetSignature(FunctionSig* sig); | 122 void SetSignature(FunctionSig* sig); |
123 uint32_t AddLocal(LocalType type); | 123 uint32_t AddLocal(ValueType type); |
124 void EmitVarInt(uint32_t val); | 124 void EmitVarInt(uint32_t val); |
125 void EmitCode(const byte* code, uint32_t code_size); | 125 void EmitCode(const byte* code, uint32_t code_size); |
126 void Emit(WasmOpcode opcode); | 126 void Emit(WasmOpcode opcode); |
127 void EmitGetLocal(uint32_t index); | 127 void EmitGetLocal(uint32_t index); |
128 void EmitSetLocal(uint32_t index); | 128 void EmitSetLocal(uint32_t index); |
129 void EmitTeeLocal(uint32_t index); | 129 void EmitTeeLocal(uint32_t index); |
130 void EmitI32Const(int32_t val); | 130 void EmitI32Const(int32_t val); |
131 void EmitWithU8(WasmOpcode opcode, const byte immediate); | 131 void EmitWithU8(WasmOpcode opcode, const byte immediate); |
132 void EmitWithU8U8(WasmOpcode opcode, const byte imm1, const byte imm2); | 132 void EmitWithU8U8(WasmOpcode opcode, const byte imm1, const byte imm2); |
133 void EmitWithVarInt(WasmOpcode opcode, uint32_t immediate); | 133 void EmitWithVarInt(WasmOpcode opcode, uint32_t immediate); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 ZoneVector<DirectCallIndex> direct_calls_; | 168 ZoneVector<DirectCallIndex> direct_calls_; |
169 | 169 |
170 // Delta-encoded mapping from wasm bytes to asm.js source positions. | 170 // Delta-encoded mapping from wasm bytes to asm.js source positions. |
171 ZoneBuffer asm_offsets_; | 171 ZoneBuffer asm_offsets_; |
172 uint32_t last_asm_byte_offset_ = 0; | 172 uint32_t last_asm_byte_offset_ = 0; |
173 uint32_t last_asm_source_position_ = 0; | 173 uint32_t last_asm_source_position_ = 0; |
174 }; | 174 }; |
175 | 175 |
176 class WasmTemporary { | 176 class WasmTemporary { |
177 public: | 177 public: |
178 WasmTemporary(WasmFunctionBuilder* builder, LocalType type) { | 178 WasmTemporary(WasmFunctionBuilder* builder, ValueType type) { |
179 switch (type) { | 179 switch (type) { |
180 case kAstI32: | 180 case kWasmI32: |
181 temporary_ = &builder->i32_temps_; | 181 temporary_ = &builder->i32_temps_; |
182 break; | 182 break; |
183 case kAstI64: | 183 case kWasmI64: |
184 temporary_ = &builder->i64_temps_; | 184 temporary_ = &builder->i64_temps_; |
185 break; | 185 break; |
186 case kAstF32: | 186 case kWasmF32: |
187 temporary_ = &builder->f32_temps_; | 187 temporary_ = &builder->f32_temps_; |
188 break; | 188 break; |
189 case kAstF64: | 189 case kWasmF64: |
190 temporary_ = &builder->f64_temps_; | 190 temporary_ = &builder->f64_temps_; |
191 break; | 191 break; |
192 default: | 192 default: |
193 UNREACHABLE(); | 193 UNREACHABLE(); |
194 temporary_ = nullptr; | 194 temporary_ = nullptr; |
195 } | 195 } |
196 if (temporary_->size() == 0) { | 196 if (temporary_->size() == 0) { |
197 // Allocate a new temporary. | 197 // Allocate a new temporary. |
198 index_ = builder->AddLocal(type); | 198 index_ = builder->AddLocal(type); |
199 } else { | 199 } else { |
(...skipping 16 matching lines...) Expand all Loading... |
216 public: | 216 public: |
217 explicit WasmModuleBuilder(Zone* zone); | 217 explicit WasmModuleBuilder(Zone* zone); |
218 | 218 |
219 // Building methods. | 219 // Building methods. |
220 uint32_t AddImport(const char* name, int name_length, FunctionSig* sig); | 220 uint32_t AddImport(const char* name, int name_length, FunctionSig* sig); |
221 void SetImportName(uint32_t index, const char* name, int name_length) { | 221 void SetImportName(uint32_t index, const char* name, int name_length) { |
222 imports_[index].name = name; | 222 imports_[index].name = name; |
223 imports_[index].name_length = name_length; | 223 imports_[index].name_length = name_length; |
224 } | 224 } |
225 WasmFunctionBuilder* AddFunction(FunctionSig* sig = nullptr); | 225 WasmFunctionBuilder* AddFunction(FunctionSig* sig = nullptr); |
226 uint32_t AddGlobal(LocalType type, bool exported, bool mutability = true, | 226 uint32_t AddGlobal(ValueType type, bool exported, bool mutability = true, |
227 const WasmInitExpr& init = WasmInitExpr()); | 227 const WasmInitExpr& init = WasmInitExpr()); |
228 void AddDataSegment(const byte* data, uint32_t size, uint32_t dest); | 228 void AddDataSegment(const byte* data, uint32_t size, uint32_t dest); |
229 uint32_t AddSignature(FunctionSig* sig); | 229 uint32_t AddSignature(FunctionSig* sig); |
230 uint32_t AllocateIndirectFunctions(uint32_t count); | 230 uint32_t AllocateIndirectFunctions(uint32_t count); |
231 void SetIndirectFunction(uint32_t indirect, uint32_t direct); | 231 void SetIndirectFunction(uint32_t indirect, uint32_t direct); |
232 void MarkStartFunction(WasmFunctionBuilder* builder); | 232 void MarkStartFunction(WasmFunctionBuilder* builder); |
233 | 233 |
234 // Writing methods. | 234 // Writing methods. |
235 void WriteTo(ZoneBuffer& buffer) const; | 235 void WriteTo(ZoneBuffer& buffer) const; |
236 void WriteAsmJsOffsetTable(ZoneBuffer& buffer) const; | 236 void WriteAsmJsOffsetTable(ZoneBuffer& buffer) const; |
(...skipping 10 matching lines...) Expand all Loading... |
247 FunctionSig* GetSignature(uint32_t index) { return signatures_[index]; } | 247 FunctionSig* GetSignature(uint32_t index) { return signatures_[index]; } |
248 | 248 |
249 private: | 249 private: |
250 struct WasmFunctionImport { | 250 struct WasmFunctionImport { |
251 uint32_t sig_index; | 251 uint32_t sig_index; |
252 const char* name; | 252 const char* name; |
253 int name_length; | 253 int name_length; |
254 }; | 254 }; |
255 | 255 |
256 struct WasmGlobal { | 256 struct WasmGlobal { |
257 LocalType type; | 257 ValueType type; |
258 bool exported; | 258 bool exported; |
259 bool mutability; | 259 bool mutability; |
260 WasmInitExpr init; | 260 WasmInitExpr init; |
261 }; | 261 }; |
262 | 262 |
263 struct WasmDataSegment { | 263 struct WasmDataSegment { |
264 ZoneVector<byte> data; | 264 ZoneVector<byte> data; |
265 uint32_t dest; | 265 uint32_t dest; |
266 }; | 266 }; |
267 | 267 |
(...skipping 11 matching lines...) Expand all Loading... |
279 | 279 |
280 inline FunctionSig* WasmFunctionBuilder::signature() { | 280 inline FunctionSig* WasmFunctionBuilder::signature() { |
281 return builder_->signatures_[signature_index_]; | 281 return builder_->signatures_[signature_index_]; |
282 } | 282 } |
283 | 283 |
284 } // namespace wasm | 284 } // namespace wasm |
285 } // namespace internal | 285 } // namespace internal |
286 } // namespace v8 | 286 } // namespace v8 |
287 | 287 |
288 #endif // V8_WASM_WASM_MODULE_BUILDER_H_ | 288 #endif // V8_WASM_WASM_MODULE_BUILDER_H_ |
OLD | NEW |