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

Side by Side Diff: src/wasm/wasm-module-builder.cc

Issue 2406133003: [wasm] Decouple function name and exported name in WasmFunctionBuilder (Closed)
Patch Set: Created 4 years, 2 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/signature.h" 5 #include "src/signature.h"
6 6
7 #include "src/handles.h" 7 #include "src/handles.h"
8 #include "src/v8.h" 8 #include "src/v8.h"
9 #include "src/zone/zone-containers.h" 9 #include "src/zone/zone-containers.h"
10 10
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 48 }
49 49
50 WasmFunctionBuilder::WasmFunctionBuilder(WasmModuleBuilder* builder) 50 WasmFunctionBuilder::WasmFunctionBuilder(WasmModuleBuilder* builder)
51 : builder_(builder), 51 : builder_(builder),
52 locals_(builder->zone()), 52 locals_(builder->zone()),
53 signature_index_(0), 53 signature_index_(0),
54 exported_(0), 54 exported_(0),
55 func_index_(static_cast<uint32_t>(builder->functions_.size())), 55 func_index_(static_cast<uint32_t>(builder->functions_.size())),
56 body_(builder->zone()), 56 body_(builder->zone()),
57 name_(builder->zone()), 57 name_(builder->zone()),
58 exported_name_(builder->zone()),
58 i32_temps_(builder->zone()), 59 i32_temps_(builder->zone()),
59 i64_temps_(builder->zone()), 60 i64_temps_(builder->zone()),
60 f32_temps_(builder->zone()), 61 f32_temps_(builder->zone()),
61 f64_temps_(builder->zone()), 62 f64_temps_(builder->zone()),
62 direct_calls_(builder->zone()) {} 63 direct_calls_(builder->zone()) {}
63 64
64 void WasmFunctionBuilder::EmitVarInt(uint32_t val) { 65 void WasmFunctionBuilder::EmitVarInt(uint32_t val) {
65 byte buffer[8]; 66 byte buffer[8];
66 byte* ptr = buffer; 67 byte* ptr = buffer;
67 LEBHelper::write_u32v(&ptr, val); 68 LEBHelper::write_u32v(&ptr, val);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 DirectCallIndex call; 136 DirectCallIndex call;
136 call.offset = body_.size(); 137 call.offset = body_.size();
137 call.direct_index = index; 138 call.direct_index = index;
138 direct_calls_.push_back(call); 139 direct_calls_.push_back(call);
139 byte code[] = {U32V_5(0)}; 140 byte code[] = {U32V_5(0)};
140 EmitCode(code, sizeof(code)); 141 EmitCode(code, sizeof(code));
141 } 142 }
142 143
143 void WasmFunctionBuilder::SetExported() { exported_ = true; } 144 void WasmFunctionBuilder::SetExported() { exported_ = true; }
144 145
146 void WasmFunctionBuilder::SetExportedWithName(const char* name,
147 int name_length) {
148 exported_ = true;
149 exported_name_.resize(name_length);
150 memcpy(exported_name_.data(), name, name_length);
151 }
152
145 void WasmFunctionBuilder::SetName(const char* name, int name_length) { 153 void WasmFunctionBuilder::SetName(const char* name, int name_length) {
146 name_.clear(); 154 name_.resize(name_length);
147 if (name_length > 0) { 155 memcpy(name_.data(), name, name_length);
148 for (int i = 0; i < name_length; ++i) {
149 name_.push_back(*(name + i));
150 }
151 }
152 } 156 }
153 157
154 void WasmFunctionBuilder::WriteSignature(ZoneBuffer& buffer) const { 158 void WasmFunctionBuilder::WriteSignature(ZoneBuffer& buffer) const {
155 buffer.write_u32v(signature_index_); 159 buffer.write_u32v(signature_index_);
156 } 160 }
157 161
158 void WasmFunctionBuilder::WriteExport(ZoneBuffer& buffer) const { 162 void WasmFunctionBuilder::WriteExport(ZoneBuffer& buffer) const {
159 if (exported_) { 163 if (exported_) {
160 buffer.write_size(name_.size()); 164 const ZoneVector<char>* exported_name =
161 if (name_.size() > 0) { 165 exported_name_.size() == 0 ? &name_ : &exported_name_;
162 buffer.write(reinterpret_cast<const byte*>(&name_[0]), name_.size()); 166 buffer.write_size(exported_name->size());
163 } 167 buffer.write(reinterpret_cast<const byte*>(exported_name->data()),
168 exported_name->size());
164 buffer.write_u8(kExternalFunction); 169 buffer.write_u8(kExternalFunction);
165 buffer.write_u32v(func_index_ + 170 buffer.write_u32v(func_index_ +
166 static_cast<uint32_t>(builder_->imports_.size())); 171 static_cast<uint32_t>(builder_->imports_.size()));
167 } 172 }
168 } 173 }
169 174
170 void WasmFunctionBuilder::WriteBody(ZoneBuffer& buffer) const { 175 void WasmFunctionBuilder::WriteBody(ZoneBuffer& buffer) const {
171 size_t locals_size = locals_.Size(); 176 size_t locals_size = locals_.Size();
172 buffer.write_size(locals_size + body_.size()); 177 buffer.write_size(locals_size + body_.size());
173 buffer.EnsureSpace(locals_size); 178 buffer.EnsureSpace(locals_size);
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 function->name_.size()); 493 function->name_.size());
489 } 494 }
490 buffer.write_u8(0); 495 buffer.write_u8(0);
491 } 496 }
492 FixupSection(buffer, start, payload_offset); 497 FixupSection(buffer, start, payload_offset);
493 } 498 }
494 } 499 }
495 } // namespace wasm 500 } // namespace wasm
496 } // namespace internal 501 } // namespace internal
497 } // namespace v8 502 } // namespace v8
OLDNEW
« src/asmjs/asm-wasm-builder.cc ('K') | « src/wasm/wasm-module-builder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698