Index: src/wasm/encoder.cc |
diff --git a/src/wasm/encoder.cc b/src/wasm/encoder.cc |
index a6b2f43983e9d1952f0274a7aa5f55e6d244f435..99227c70b0a1b87c3c98cfb784bbbaa0d5c8e613 100644 |
--- a/src/wasm/encoder.cc |
+++ b/src/wasm/encoder.cc |
@@ -333,7 +333,6 @@ void WasmDataSegmentEncoder::Serialize(byte* buffer, byte** header, |
(*body) += data_.size(); |
} |
- |
WasmModuleBuilder::WasmModuleBuilder(Zone* zone) |
: zone_(zone), |
signatures_(zone), |
@@ -341,8 +340,9 @@ WasmModuleBuilder::WasmModuleBuilder(Zone* zone) |
data_segments_(zone), |
indirect_functions_(zone), |
globals_(zone), |
- signature_map_(zone) {} |
- |
+ signature_map_(zone), |
+ has_start_function_(false), |
+ start_function_index_(0) {} |
uint16_t WasmModuleBuilder::AddFunction() { |
functions_.push_back(new (zone_) WasmFunctionBuilder(zone_)); |
@@ -399,6 +399,10 @@ void WasmModuleBuilder::AddIndirectFunction(uint16_t index) { |
indirect_functions_.push_back(index); |
} |
+void WasmModuleBuilder::MarkStartFunction(uint16_t index) { |
+ has_start_function_ = true; |
+ start_function_index_ = index; |
+} |
WasmModuleWriter* WasmModuleBuilder::Build(Zone* zone) { |
WasmModuleWriter* writer = new (zone) WasmModuleWriter(zone); |
@@ -417,6 +421,8 @@ WasmModuleWriter* WasmModuleBuilder::Build(Zone* zone) { |
for (auto global : globals_) { |
writer->globals_.push_back(global); |
} |
+ writer->has_start_function_ = has_start_function_; |
+ writer->start_function_index_ = start_function_index_; |
return writer; |
} |
@@ -482,6 +488,15 @@ WasmModuleIndex* WasmModuleWriter::WriteTo(Zone* zone) const { |
function->NameSize()); |
} |
+ if (has_start_function_) { |
+ sizes.Add(1, 0); |
+ uint16_t size = start_function_index_; |
+ do { |
titzer
2016/03/01 02:09:33
Let's lift out this varint encoding into a helper
aseemgarg
2016/03/01 02:37:34
This is enclosed in AddSection for other. Just for
titzer
2016/03/01 02:43:58
At least lift it out to a helper that computes the
aseemgarg
2016/03/01 03:00:24
Done.
|
+ sizes.Add(1, 0); |
+ size = size >> 7; |
+ } while (size > 0); |
+ } |
+ |
sizes.AddSection(data_segments_.size()); |
for (auto segment : data_segments_) { |
sizes.Add(segment->HeaderSize(), segment->BodySize()); |
@@ -547,6 +562,12 @@ WasmModuleIndex* WasmModuleWriter::WriteTo(Zone* zone) const { |
} |
} |
+ // -- emit start function index ---------------------------------------------- |
+ if (has_start_function_) { |
+ EmitUint8(&header, kDeclStartFunction); |
+ EmitVarInt(&header, start_function_index_); |
+ } |
+ |
// -- emit data segments ----------------------------------------------------- |
if (data_segments_.size() > 0) { |
EmitUint8(&header, kDeclDataSegments); |