Chromium Code Reviews| Index: src/wasm/encoder.h |
| diff --git a/src/wasm/encoder.h b/src/wasm/encoder.h |
| index eb8aa64abde2f82bc7e39dfa2e37436dc05fb34d..2a25ea60a0d811665428d1897ae352265e9156cf 100644 |
| --- a/src/wasm/encoder.h |
| +++ b/src/wasm/encoder.h |
| @@ -136,12 +136,56 @@ class WasmFunctionBuilder : public ZoneObject { |
| private: |
| explicit WasmFunctionBuilder(WasmModuleBuilder* builder); |
| friend class WasmModuleBuilder; |
| + friend class WasmTemporary; |
| WasmModuleBuilder* builder_; |
| LocalDeclEncoder locals_; |
| uint32_t signature_index_; |
| bool exported_; |
| ZoneVector<uint8_t> body_; |
| ZoneVector<char> name_; |
| + ZoneVector<uint32_t> i32_temps_; |
| + ZoneVector<uint32_t> i64_temps_; |
| + ZoneVector<uint32_t> f32_temps_; |
| + ZoneVector<uint32_t> f64_temps_; |
| +}; |
| + |
| +class WasmTemporary { |
| + public: |
| + WasmTemporary(WasmFunctionBuilder* builder, LocalType type) { |
| + switch (type) { |
| + case kAstI32: |
| + vector_ = &builder->i32_temps_; |
| + break; |
| + case kAstI64: |
| + vector_ = &builder->i64_temps_; |
| + break; |
| + case kAstF32: |
| + vector_ = &builder->f32_temps_; |
| + break; |
| + case kAstF64: |
| + vector_ = &builder->f64_temps_; |
| + break; |
| + default: |
| + UNREACHABLE(); |
| + vector_ = nullptr; |
| + } |
| + if (vector_->size() == 0) { |
| + // Allocate a new temporary. |
| + index_ = builder->AddLocal(type); |
| + } else { |
| + // Reuse a previous temporary. |
| + index_ = vector_->back(); |
| + vector_->pop_back(); |
| + } |
| + } |
| + ~WasmTemporary() { |
| + vector_->push_back(index_); // return the temporary to the list. |
| + } |
| + uint32_t index() { return index_; } |
| + |
| + private: |
| + ZoneVector<uint32_t>* vector_; |
|
bradnelson
2016/08/29 16:04:24
temporary_?
|
| + uint32_t index_; |
| }; |
| // TODO(titzer): kill! |