Chromium Code Reviews| Index: src/wasm/encoder.h | 
| diff --git a/src/wasm/encoder.h b/src/wasm/encoder.h | 
| index 50ec6e5eaf61d32ec1141aa3dc342d8d519f5205..ae3b074bef2d109d2de6ee67d6021f72006a97c7 100644 | 
| --- a/src/wasm/encoder.h | 
| +++ b/src/wasm/encoder.h | 
| @@ -120,19 +120,22 @@ class 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_; } | 
| 
 
Mircea Trofin
2016/09/19 16:16:25
const? also for exported() above.
worth checking
 
titzer
2016/09/21 08:58:44
I don't think const annotations on builder classes
 
Mircea Trofin
2016/09/21 16:38:23
See my previous point about the value of const for
 
titzer
2016/09/21 18:49:28
I prefer a very light and judicial application of
 
 | 
| + FunctionSig* signature(); | 
| + | 
| private: | 
| explicit WasmFunctionBuilder(WasmModuleBuilder* builder); | 
| friend class WasmModuleBuilder; | 
| @@ -141,6 +144,7 @@ class 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_; | 
| @@ -211,14 +215,17 @@ class 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; | 
| @@ -230,18 +237,25 @@ class 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_; | 
| 
 
Mircea Trofin
2016/09/19 16:16:25
For readability (like, what's this second and thir
 
 | 
| SignatureMap signature_map_; | 
| int start_function_index_; | 
| }; | 
| +inline FunctionSig* WasmFunctionBuilder::signature() { | 
| + return builder_->signatures_[signature_index_]; | 
| +} | 
| + | 
| } // namespace wasm | 
| } // namespace internal | 
| } // namespace v8 |