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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 void EmitVarInt(uint32_t val); | 119 void EmitVarInt(uint32_t val); |
120 void EmitCode(const byte* code, uint32_t code_size); | 120 void EmitCode(const byte* code, uint32_t code_size); |
121 void Emit(WasmOpcode opcode); | 121 void Emit(WasmOpcode opcode); |
122 void EmitGetLocal(uint32_t index); | 122 void EmitGetLocal(uint32_t index); |
123 void EmitSetLocal(uint32_t index); | 123 void EmitSetLocal(uint32_t index); |
124 void EmitTeeLocal(uint32_t index); | 124 void EmitTeeLocal(uint32_t index); |
125 void EmitI32Const(int32_t val); | 125 void EmitI32Const(int32_t val); |
126 void EmitWithU8(WasmOpcode opcode, const byte immediate); | 126 void EmitWithU8(WasmOpcode opcode, const byte immediate); |
127 void EmitWithU8U8(WasmOpcode opcode, const byte imm1, const byte imm2); | 127 void EmitWithU8U8(WasmOpcode opcode, const byte imm1, const byte imm2); |
128 void EmitWithVarInt(WasmOpcode opcode, uint32_t immediate); | 128 void EmitWithVarInt(WasmOpcode opcode, uint32_t immediate); |
| 129 void EmitDirectCallIndex(uint32_t index); |
129 void SetExported(); | 130 void SetExported(); |
130 void SetName(const char* name, int name_length); | 131 void SetName(const char* name, int name_length); |
131 | 132 |
132 void WriteSignature(ZoneBuffer& buffer) const; | 133 void WriteSignature(ZoneBuffer& buffer) const; |
133 void WriteExport(ZoneBuffer& buffer) const; | 134 void WriteExport(ZoneBuffer& buffer) const; |
134 void WriteBody(ZoneBuffer& buffer) const; | 135 void WriteBody(ZoneBuffer& buffer) const; |
135 | 136 |
136 bool exported() { return exported_; } | 137 bool exported() { return exported_; } |
137 uint32_t func_index() { return func_index_; } | 138 uint32_t func_index() { return func_index_; } |
138 FunctionSig* signature(); | 139 FunctionSig* signature(); |
139 | 140 |
140 private: | 141 private: |
141 explicit WasmFunctionBuilder(WasmModuleBuilder* builder); | 142 explicit WasmFunctionBuilder(WasmModuleBuilder* builder); |
142 friend class WasmModuleBuilder; | 143 friend class WasmModuleBuilder; |
143 friend class WasmTemporary; | 144 friend class WasmTemporary; |
| 145 |
| 146 struct DirectCallIndex { |
| 147 size_t offset; |
| 148 uint32_t direct_index; |
| 149 }; |
| 150 |
144 WasmModuleBuilder* builder_; | 151 WasmModuleBuilder* builder_; |
145 LocalDeclEncoder locals_; | 152 LocalDeclEncoder locals_; |
146 uint32_t signature_index_; | 153 uint32_t signature_index_; |
147 bool exported_; | 154 bool exported_; |
148 uint32_t func_index_; | 155 uint32_t func_index_; |
149 ZoneVector<uint8_t> body_; | 156 ZoneVector<uint8_t> body_; |
150 ZoneVector<char> name_; | 157 ZoneVector<char> name_; |
151 ZoneVector<uint32_t> i32_temps_; | 158 ZoneVector<uint32_t> i32_temps_; |
152 ZoneVector<uint32_t> i64_temps_; | 159 ZoneVector<uint32_t> i64_temps_; |
153 ZoneVector<uint32_t> f32_temps_; | 160 ZoneVector<uint32_t> f32_temps_; |
154 ZoneVector<uint32_t> f64_temps_; | 161 ZoneVector<uint32_t> f64_temps_; |
| 162 ZoneVector<DirectCallIndex> direct_calls_; |
155 }; | 163 }; |
156 | 164 |
157 class WasmTemporary { | 165 class WasmTemporary { |
158 public: | 166 public: |
159 WasmTemporary(WasmFunctionBuilder* builder, LocalType type) { | 167 WasmTemporary(WasmFunctionBuilder* builder, LocalType type) { |
160 switch (type) { | 168 switch (type) { |
161 case kAstI32: | 169 case kAstI32: |
162 temporary_ = &builder->i32_temps_; | 170 temporary_ = &builder->i32_temps_; |
163 break; | 171 break; |
164 case kAstI64: | 172 case kAstI64: |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 262 |
255 inline FunctionSig* WasmFunctionBuilder::signature() { | 263 inline FunctionSig* WasmFunctionBuilder::signature() { |
256 return builder_->signatures_[signature_index_]; | 264 return builder_->signatures_[signature_index_]; |
257 } | 265 } |
258 | 266 |
259 } // namespace wasm | 267 } // namespace wasm |
260 } // namespace internal | 268 } // namespace internal |
261 } // namespace v8 | 269 } // namespace v8 |
262 | 270 |
263 #endif // V8_WASM_WASM_MODULE_BUILDER_H_ | 271 #endif // V8_WASM_WASM_MODULE_BUILDER_H_ |
OLD | NEW |