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

Unified Diff: src/wasm/encoder.cc

Issue 1763433002: [wasm] Rework encoding of local declarations. (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
Index: src/wasm/encoder.cc
diff --git a/src/wasm/encoder.cc b/src/wasm/encoder.cc
index 70d739ec67277e4606aae5f574e8d505ef5c7996..c7febe1e9f27f9a4caf5e999edc12680ce4a4910 100644
--- a/src/wasm/encoder.cc
+++ b/src/wasm/encoder.cc
@@ -195,6 +195,7 @@ WasmFunctionEncoder* WasmFunctionBuilder::Build(Zone* zone,
void WasmFunctionBuilder::IndexVars(WasmFunctionEncoder* e,
uint16_t* var_index) const {
+ // TODO(titzer): all of this is unnecessary now.
uint16_t param = 0;
uint16_t i32 = 0;
uint16_t i64 = 0;
@@ -213,10 +214,10 @@ void WasmFunctionBuilder::IndexVars(WasmFunctionEncoder* e,
f64++;
}
}
- e->local_i32_count_ = i32;
- e->local_i64_count_ = i64;
- e->local_f32_count_ = f32;
- e->local_f64_count_ = f64;
+ e->local_decls_.AddLocals(i32, kAstI32);
+ e->local_decls_.AddLocals(i64, kAstI64);
+ e->local_decls_.AddLocals(f32, kAstF32);
+ e->local_decls_.AddLocals(f64, kAstF64);
f64 = param + i32 + i64 + f32;
f32 = param + i32 + i64;
i64 = param + i32;
@@ -250,7 +251,6 @@ WasmFunctionEncoder::WasmFunctionEncoder(Zone* zone, LocalType return_type,
uint32_t WasmFunctionEncoder::HeaderSize() const {
uint32_t size = 3;
- if (HasLocals()) size += 8;
if (!external_) size += 2;
if (HasName()) size += 4;
return size;
@@ -258,7 +258,8 @@ uint32_t WasmFunctionEncoder::HeaderSize() const {
uint32_t WasmFunctionEncoder::BodySize(void) const {
- return external_ ? 0 : static_cast<uint32_t>(body_.size());
+ return external_ ? 0
+ : static_cast<uint32_t>(local_decls_.Size() + body_.size());
}
@@ -271,7 +272,6 @@ void WasmFunctionEncoder::Serialize(byte* buffer, byte** header,
byte** body) const {
uint8_t decl_bits = (exported_ ? kDeclFunctionExport : 0) |
(external_ ? kDeclFunctionImport : 0) |
- (HasLocals() ? kDeclFunctionLocals : 0) |
(HasName() ? kDeclFunctionName : 0);
EmitUint8(header, decl_bits);
@@ -284,15 +284,10 @@ void WasmFunctionEncoder::Serialize(byte* buffer, byte** header,
(*body) += name_.size();
}
- if (HasLocals()) {
- EmitUint16(header, local_i32_count_);
- EmitUint16(header, local_i64_count_);
- EmitUint16(header, local_f32_count_);
- EmitUint16(header, local_f64_count_);
- }
-
if (!external_) {
- EmitUint16(header, static_cast<uint16_t>(body_.size()));
+ size_t size = body_.size() + local_decls_.Size();
+ EmitUint16(header, static_cast<uint16_t>(size));
bradnelson 2016/03/02 21:51:15 I assume this will change to a leb in a later chan
titzer 2016/03/02 22:43:41 Yeah, we'll just update everything to be LEB in on
+ (*header) += local_decls_.Emit(*header);
if (body_.size() > 0) {
std::memcpy(*header, &body_[0], body_.size());
(*header) += body_.size();

Powered by Google App Engine
This is Rietveld 408576698