Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1787)

Unified Diff: src/wasm/encoder.h

Issue 2017853003: [wasm] Remove redundant intermediate data structures in encoder.cc. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/wasm/asm-wasm-builder.cc ('k') | src/wasm/encoder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/encoder.h
diff --git a/src/wasm/encoder.h b/src/wasm/encoder.h
index 5d2e6c8faea1b7843ed3adb79c71fa51558f1e7e..14248b01c89b62583db14634c724dbc1e5c0fab0 100644
--- a/src/wasm/encoder.h
+++ b/src/wasm/encoder.h
@@ -112,27 +112,9 @@ class ZoneBuffer : public ZoneObject {
class WasmModuleBuilder;
-class WasmFunctionEncoder : public ZoneObject {
- public:
- void WriteSignature(ZoneBuffer& buffer) const;
- void WriteExport(ZoneBuffer& buffer, uint32_t func_index) const;
- void WriteBody(ZoneBuffer& buffer) const;
- bool exported() const { return exported_; }
-
- private:
- WasmFunctionEncoder(Zone* zone, LocalDeclEncoder locals, bool exported);
- friend class WasmFunctionBuilder;
- uint32_t signature_index_;
- LocalDeclEncoder locals_;
- bool exported_;
- ZoneVector<uint8_t> body_;
- ZoneVector<char> name_;
-
- bool HasName() const { return exported_ && name_.size() > 0; }
-};
-
class WasmFunctionBuilder : public ZoneObject {
public:
+ // Building methods.
void SetSignature(FunctionSig* sig);
uint32_t AddLocal(LocalType type);
void EmitVarInt(uint32_t val);
@@ -144,20 +126,27 @@ class WasmFunctionBuilder : public ZoneObject {
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 Exported(uint8_t flag);
+ void SetExported();
void SetName(const char* name, int name_length);
- WasmFunctionEncoder* Build(Zone* zone, WasmModuleBuilder* mb) const;
+ bool exported() { return exported_; }
+
+ // Writing methods.
+ void WriteSignature(ZoneBuffer& buffer) const;
+ void WriteExport(ZoneBuffer& buffer, uint32_t func_index) const;
+ void WriteBody(ZoneBuffer& buffer) const;
private:
- explicit WasmFunctionBuilder(Zone* zone);
+ explicit WasmFunctionBuilder(WasmModuleBuilder* builder);
friend class WasmModuleBuilder;
+ WasmModuleBuilder* builder_;
LocalDeclEncoder locals_;
- uint8_t exported_;
+ uint32_t signature_index_;
+ bool exported_;
ZoneVector<uint8_t> body_;
ZoneVector<char> name_;
- void IndexVars(WasmFunctionEncoder* e, uint32_t* var_index) const;
};
+// TODO(titzer): kill!
class WasmDataSegmentEncoder : public ZoneObject {
public:
WasmDataSegmentEncoder(Zone* zone, const byte* data, uint32_t size,
@@ -175,25 +164,11 @@ struct WasmFunctionImport {
int name_length;
};
-class WasmModuleWriter : public ZoneObject {
- public:
- void WriteTo(ZoneBuffer& buffer) const;
-
- private:
- friend class WasmModuleBuilder;
- explicit WasmModuleWriter(Zone* zone);
- ZoneVector<WasmFunctionImport> imports_;
- ZoneVector<WasmFunctionEncoder*> functions_;
- ZoneVector<WasmDataSegmentEncoder*> data_segments_;
- ZoneVector<FunctionSig*> signatures_;
- ZoneVector<uint32_t> indirect_functions_;
- ZoneVector<std::pair<MachineType, bool>> globals_;
- int start_function_index_;
-};
-
class WasmModuleBuilder : public ZoneObject {
public:
explicit WasmModuleBuilder(Zone* zone);
+
+ // Building methods.
uint32_t AddFunction();
uint32_t AddGlobal(MachineType type, bool exported);
WasmFunctionBuilder* FunctionAt(size_t index);
@@ -202,13 +177,17 @@ class WasmModuleBuilder : public ZoneObject {
void AddIndirectFunction(uint32_t index);
void MarkStartFunction(uint32_t index);
uint32_t AddImport(const char* name, int name_length, FunctionSig* sig);
- WasmModuleWriter* Build(Zone* zone);
+
+ // Writing methods.
+ void WriteTo(ZoneBuffer& buffer) const;
struct CompareFunctionSigs {
bool operator()(FunctionSig* a, FunctionSig* b) const;
};
typedef ZoneMap<FunctionSig*, uint32_t, CompareFunctionSigs> SignatureMap;
+ Zone* zone() { return zone_; }
+
private:
Zone* zone_;
ZoneVector<FunctionSig*> signatures_;
« no previous file with comments | « src/wasm/asm-wasm-builder.cc ('k') | src/wasm/encoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698