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

Unified Diff: src/wasm/encoder.cc

Issue 1750153002: Replace __init__ function in asm-wasm-builder with the start function section (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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/encoder.h ('k') | test/mjsunit/wasm/asm-wasm.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/encoder.cc
diff --git a/src/wasm/encoder.cc b/src/wasm/encoder.cc
index a6b2f43983e9d1952f0274a7aa5f55e6d244f435..70d739ec67277e4606aae5f574e8d505ef5c7996 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,8 @@ WasmModuleBuilder::WasmModuleBuilder(Zone* zone)
data_segments_(zone),
indirect_functions_(zone),
globals_(zone),
- signature_map_(zone) {}
-
+ signature_map_(zone),
+ start_function_index_(-1) {}
uint16_t WasmModuleBuilder::AddFunction() {
functions_.push_back(new (zone_) WasmFunctionBuilder(zone_));
@@ -399,6 +398,9 @@ void WasmModuleBuilder::AddIndirectFunction(uint16_t index) {
indirect_functions_.push_back(index);
}
+void WasmModuleBuilder::MarkStartFunction(uint16_t index) {
+ start_function_index_ = index;
+}
WasmModuleWriter* WasmModuleBuilder::Build(Zone* zone) {
WasmModuleWriter* writer = new (zone) WasmModuleWriter(zone);
@@ -417,6 +419,7 @@ WasmModuleWriter* WasmModuleBuilder::Build(Zone* zone) {
for (auto global : globals_) {
writer->globals_.push_back(global);
}
+ writer->start_function_index_ = start_function_index_;
return writer;
}
@@ -434,6 +437,14 @@ WasmModuleWriter::WasmModuleWriter(Zone* zone)
indirect_functions_(zone),
globals_(zone) {}
+size_t SizeOfVarInt(size_t value) {
+ size_t size = 0;
+ do {
+ size++;
+ value = value >> 7;
+ } while (value > 0);
+ return size;
+}
struct Sizes {
size_t header_size;
@@ -449,10 +460,7 @@ struct Sizes {
void AddSection(size_t size) {
if (size > 0) {
Add(1, 0);
- while (size > 0) {
- Add(1, 0);
- size = size >> 7;
- }
+ Add(SizeOfVarInt(size), 0);
}
}
};
@@ -482,6 +490,11 @@ WasmModuleIndex* WasmModuleWriter::WriteTo(Zone* zone) const {
function->NameSize());
}
+ if (start_function_index_ >= 0) {
+ sizes.Add(1, 0);
+ sizes.Add(SizeOfVarInt(start_function_index_), 0);
+ }
+
sizes.AddSection(data_segments_.size());
for (auto segment : data_segments_) {
sizes.Add(segment->HeaderSize(), segment->BodySize());
@@ -547,6 +560,12 @@ WasmModuleIndex* WasmModuleWriter::WriteTo(Zone* zone) const {
}
}
+ // -- emit start function index ----------------------------------------------
+ if (start_function_index_ >= 0) {
+ EmitUint8(&header, kDeclStartFunction);
+ EmitVarInt(&header, start_function_index_);
+ }
+
// -- emit data segments -----------------------------------------------------
if (data_segments_.size() > 0) {
EmitUint8(&header, kDeclDataSegments);
« no previous file with comments | « src/wasm/encoder.h ('k') | test/mjsunit/wasm/asm-wasm.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698