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_ENCODER_H_ | 5 #ifndef V8_WASM_ENCODER_H_ |
6 #define V8_WASM_ENCODER_H_ | 6 #define V8_WASM_ENCODER_H_ |
7 | 7 |
8 #include "src/signature.h" | 8 #include "src/signature.h" |
9 #include "src/zone-containers.h" | 9 #include "src/zone-containers.h" |
10 | 10 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 bool exported() { return exported_; } | 129 bool exported() { return exported_; } |
130 | 130 |
131 // Writing methods. | 131 // Writing methods. |
132 void WriteSignature(ZoneBuffer& buffer) const; | 132 void WriteSignature(ZoneBuffer& buffer) const; |
133 void WriteExport(ZoneBuffer& buffer, uint32_t func_index) const; | 133 void WriteExport(ZoneBuffer& buffer, uint32_t func_index) const; |
134 void WriteBody(ZoneBuffer& buffer) const; | 134 void WriteBody(ZoneBuffer& buffer) const; |
135 | 135 |
136 private: | 136 private: |
137 explicit WasmFunctionBuilder(WasmModuleBuilder* builder); | 137 explicit WasmFunctionBuilder(WasmModuleBuilder* builder); |
138 friend class WasmModuleBuilder; | 138 friend class WasmModuleBuilder; |
139 friend class WasmTemporary; | |
139 WasmModuleBuilder* builder_; | 140 WasmModuleBuilder* builder_; |
140 LocalDeclEncoder locals_; | 141 LocalDeclEncoder locals_; |
141 uint32_t signature_index_; | 142 uint32_t signature_index_; |
142 bool exported_; | 143 bool exported_; |
143 ZoneVector<uint8_t> body_; | 144 ZoneVector<uint8_t> body_; |
144 ZoneVector<char> name_; | 145 ZoneVector<char> name_; |
146 ZoneVector<uint32_t> i32_temps_; | |
147 ZoneVector<uint32_t> i64_temps_; | |
148 ZoneVector<uint32_t> f32_temps_; | |
149 ZoneVector<uint32_t> f64_temps_; | |
150 }; | |
151 | |
152 class WasmTemporary { | |
153 public: | |
154 WasmTemporary(WasmFunctionBuilder* builder, LocalType type) { | |
155 switch (type) { | |
156 case kAstI32: | |
157 vector_ = &builder->i32_temps_; | |
158 break; | |
159 case kAstI64: | |
160 vector_ = &builder->i64_temps_; | |
161 break; | |
162 case kAstF32: | |
163 vector_ = &builder->f32_temps_; | |
164 break; | |
165 case kAstF64: | |
166 vector_ = &builder->f64_temps_; | |
167 break; | |
168 default: | |
169 UNREACHABLE(); | |
170 vector_ = nullptr; | |
171 } | |
172 if (vector_->size() == 0) { | |
173 // Allocate a new temporary. | |
174 index_ = builder->AddLocal(type); | |
175 } else { | |
176 // Reuse a previous temporary. | |
177 index_ = vector_->back(); | |
178 vector_->pop_back(); | |
179 } | |
180 } | |
181 ~WasmTemporary() { | |
182 vector_->push_back(index_); // return the temporary to the list. | |
183 } | |
184 uint32_t index() { return index_; } | |
185 | |
186 private: | |
187 ZoneVector<uint32_t>* vector_; | |
bradnelson
2016/08/29 16:04:24
temporary_?
| |
188 uint32_t index_; | |
145 }; | 189 }; |
146 | 190 |
147 // TODO(titzer): kill! | 191 // TODO(titzer): kill! |
148 class WasmDataSegmentEncoder : public ZoneObject { | 192 class WasmDataSegmentEncoder : public ZoneObject { |
149 public: | 193 public: |
150 WasmDataSegmentEncoder(Zone* zone, const byte* data, uint32_t size, | 194 WasmDataSegmentEncoder(Zone* zone, const byte* data, uint32_t size, |
151 uint32_t dest); | 195 uint32_t dest); |
152 void Write(ZoneBuffer& buffer) const; | 196 void Write(ZoneBuffer& buffer) const; |
153 | 197 |
154 private: | 198 private: |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
196 ZoneVector<std::pair<LocalType, bool>> globals_; | 240 ZoneVector<std::pair<LocalType, bool>> globals_; |
197 SignatureMap signature_map_; | 241 SignatureMap signature_map_; |
198 int start_function_index_; | 242 int start_function_index_; |
199 }; | 243 }; |
200 | 244 |
201 } // namespace wasm | 245 } // namespace wasm |
202 } // namespace internal | 246 } // namespace internal |
203 } // namespace v8 | 247 } // namespace v8 |
204 | 248 |
205 #endif // V8_WASM_ENCODER_H_ | 249 #endif // V8_WASM_ENCODER_H_ |
OLD | NEW |