Index: src/wasm/encoder.h |
diff --git a/src/wasm/encoder.h b/src/wasm/encoder.h |
index 87fcc35f7446470c38921339a288d6b4565b21bb..4fdcc950ef6086ada773fc7abfb5e910ee492cc5 100644 |
--- a/src/wasm/encoder.h |
+++ b/src/wasm/encoder.h |
@@ -121,19 +121,22 @@ class V8_EXPORT_PRIVATE WasmFunctionBuilder : public ZoneObject { |
void Emit(WasmOpcode opcode); |
void EmitGetLocal(uint32_t index); |
void EmitSetLocal(uint32_t index); |
+ void EmitTeeLocal(uint32_t index); |
void EmitI32Const(int32_t val); |
void EmitWithU8(WasmOpcode opcode, const byte immediate); |
void EmitWithU8U8(WasmOpcode opcode, const byte imm1, const byte imm2); |
void EmitWithVarInt(WasmOpcode opcode, uint32_t immediate); |
void SetExported(); |
void SetName(const char* name, int name_length); |
- bool exported() { return exported_; } |
- // Writing methods. |
void WriteSignature(ZoneBuffer& buffer) const; |
- void WriteExport(ZoneBuffer& buffer, uint32_t func_index) const; |
+ void WriteExport(ZoneBuffer& buffer) const; |
void WriteBody(ZoneBuffer& buffer) const; |
+ bool exported() { return exported_; } |
+ uint32_t func_index() { return func_index_; } |
+ FunctionSig* signature(); |
+ |
private: |
explicit WasmFunctionBuilder(WasmModuleBuilder* builder); |
friend class WasmModuleBuilder; |
@@ -142,6 +145,7 @@ class V8_EXPORT_PRIVATE WasmFunctionBuilder : public ZoneObject { |
LocalDeclEncoder locals_; |
uint32_t signature_index_; |
bool exported_; |
+ uint32_t func_index_; |
ZoneVector<uint8_t> body_; |
ZoneVector<char> name_; |
ZoneVector<uint32_t> i32_temps_; |
@@ -212,14 +216,17 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject { |
explicit WasmModuleBuilder(Zone* zone); |
// Building methods. |
- uint32_t AddFunction(); |
- uint32_t AddGlobal(LocalType type, bool exported); |
- WasmFunctionBuilder* FunctionAt(size_t index); |
+ uint32_t AddImport(const char* name, int name_length, FunctionSig* sig); |
+ void SetImportName(uint32_t index, const char* name, int name_length) { |
+ imports_[index].name = name; |
+ imports_[index].name_length = name_length; |
+ } |
+ WasmFunctionBuilder* AddFunction(FunctionSig* sig = nullptr); |
+ uint32_t AddGlobal(LocalType type, bool exported, bool mutability = true); |
void AddDataSegment(WasmDataSegmentEncoder* data); |
uint32_t AddSignature(FunctionSig* sig); |
void AddIndirectFunction(uint32_t index); |
- void MarkStartFunction(uint32_t index); |
- uint32_t AddImport(const char* name, int name_length, FunctionSig* sig); |
+ void MarkStartFunction(WasmFunctionBuilder* builder); |
// Writing methods. |
void WriteTo(ZoneBuffer& buffer) const; |
@@ -231,18 +238,25 @@ class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject { |
Zone* zone() { return zone_; } |
+ FunctionSig* GetSignature(uint32_t index) { return signatures_[index]; } |
+ |
private: |
+ friend class WasmFunctionBuilder; |
Zone* zone_; |
ZoneVector<FunctionSig*> signatures_; |
ZoneVector<WasmFunctionImport> imports_; |
ZoneVector<WasmFunctionBuilder*> functions_; |
ZoneVector<WasmDataSegmentEncoder*> data_segments_; |
ZoneVector<uint32_t> indirect_functions_; |
- ZoneVector<std::pair<LocalType, bool>> globals_; |
+ ZoneVector<std::tuple<LocalType, bool, bool>> globals_; |
SignatureMap signature_map_; |
int start_function_index_; |
}; |
+inline FunctionSig* WasmFunctionBuilder::signature() { |
+ return builder_->signatures_[signature_index_]; |
+} |
+ |
} // namespace wasm |
} // namespace internal |
} // namespace v8 |