1 // Copyright 2017 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_WASM_LOCAL_DECL_ENCODER_H_ 6 #define V8_WASM_LOCAL_DECL_ENCODER_H_ 7 8 #include "src/globals.h" 9 #include "src/wasm/wasm-opcodes.h" 10 #include "src/zone/zone-containers.h" 11 #include "src/zone/zone.h" 12 13 namespace v8 { 14 namespace internal { 15 namespace wasm { 16 17 // A helper for encoding local declarations prepended to the body of a 18 // function. 19 class V8_EXPORT_PRIVATE LocalDeclEncoder { 20 public: 21 explicit LocalDeclEncoder(Zone* zone, FunctionSig* s = nullptr) sig(s)22 : sig(s), local_decls(zone), total(0) {} 23 24 // Prepend local declarations by creating a new buffer and copying data 25 // over. The new buffer must be delete[]'d by the caller. 26 void Prepend(Zone* zone, const byte** start, const byte** end) const; 27 28 size_t Emit(byte* buffer) const; 29 30 // Add locals declarations to this helper. Return the index of the newly added 31 // local(s), with an optional adjustment for the parameters. 32 uint32_t AddLocals(uint32_t count, ValueType type); 33 34 size_t Size() const; 35 has_sig()36 bool has_sig() const { return sig != nullptr; } get_sig()37 FunctionSig* get_sig() const { return sig; } set_sig(FunctionSig * s)38 void set_sig(FunctionSig* s) { sig = s; } 39 40 private: 41 FunctionSig* sig; 42 ZoneVector<std::pair<uint32_t, ValueType>> local_decls; 43 size_t total; 44 }; 45 46 } // namespace wasm 47 } // namespace internal 48 } // namespace v8 49 50 #endif // V8_WASM_LOCAL_DECL_ENCODER_H_ 51