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

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

Issue 2406133003: [wasm] Decouple function name and exported name in WasmFunctionBuilder (Closed)
Patch Set: Change interface to Vector<const char>; avoids size_t/int confusion 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
« no previous file with comments | « src/wasm/wasm-module-builder.h ('k') | test/cctest/wasm/test-run-wasm-module.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 } 47 }
48 48
49 WasmFunctionBuilder::WasmFunctionBuilder(WasmModuleBuilder* builder) 49 WasmFunctionBuilder::WasmFunctionBuilder(WasmModuleBuilder* builder)
50 : builder_(builder), 50 : builder_(builder),
51 locals_(builder->zone()), 51 locals_(builder->zone()),
52 signature_index_(0), 52 signature_index_(0),
53 exported_(0), 53 exported_(0),
54 func_index_(static_cast<uint32_t>(builder->functions_.size())), 54 func_index_(static_cast<uint32_t>(builder->functions_.size())),
55 body_(builder->zone()), 55 body_(builder->zone()),
56 name_(builder->zone()), 56 name_(builder->zone()),
57 exported_name_(builder->zone()),
57 i32_temps_(builder->zone()), 58 i32_temps_(builder->zone()),
58 i64_temps_(builder->zone()), 59 i64_temps_(builder->zone()),
59 f32_temps_(builder->zone()), 60 f32_temps_(builder->zone()),
60 f64_temps_(builder->zone()), 61 f64_temps_(builder->zone()),
61 direct_calls_(builder->zone()) {} 62 direct_calls_(builder->zone()) {}
62 63
63 void WasmFunctionBuilder::EmitVarInt(uint32_t val) { 64 void WasmFunctionBuilder::EmitVarInt(uint32_t val) {
64 byte buffer[8]; 65 byte buffer[8];
65 byte* ptr = buffer; 66 byte* ptr = buffer;
66 LEBHelper::write_u32v(&ptr, val); 67 LEBHelper::write_u32v(&ptr, val);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 133
133 void WasmFunctionBuilder::EmitDirectCallIndex(uint32_t index) { 134 void WasmFunctionBuilder::EmitDirectCallIndex(uint32_t index) {
134 DirectCallIndex call; 135 DirectCallIndex call;
135 call.offset = body_.size(); 136 call.offset = body_.size();
136 call.direct_index = index; 137 call.direct_index = index;
137 direct_calls_.push_back(call); 138 direct_calls_.push_back(call);
138 byte code[] = {U32V_5(0)}; 139 byte code[] = {U32V_5(0)};
139 EmitCode(code, sizeof(code)); 140 EmitCode(code, sizeof(code));
140 } 141 }
141 142
142 void WasmFunctionBuilder::SetExported() { exported_ = true; } 143 void WasmFunctionBuilder::Export() { exported_ = true; }
143 144
144 void WasmFunctionBuilder::SetName(const char* name, int name_length) { 145 void WasmFunctionBuilder::ExportAs(Vector<const char> name) {
145 name_.clear(); 146 exported_ = true;
146 if (name_length > 0) { 147 exported_name_.resize(name.length());
147 for (int i = 0; i < name_length; ++i) { 148 memcpy(exported_name_.data(), name.start(), name.length());
148 name_.push_back(*(name + i)); 149 }
149 } 150
150 } 151 void WasmFunctionBuilder::SetName(Vector<const char> name) {
152 name_.resize(name.length());
153 memcpy(name_.data(), name.start(), name.length());
151 } 154 }
152 155
153 void WasmFunctionBuilder::WriteSignature(ZoneBuffer& buffer) const { 156 void WasmFunctionBuilder::WriteSignature(ZoneBuffer& buffer) const {
154 buffer.write_u32v(signature_index_); 157 buffer.write_u32v(signature_index_);
155 } 158 }
156 159
157 void WasmFunctionBuilder::WriteExport(ZoneBuffer& buffer) const { 160 void WasmFunctionBuilder::WriteExport(ZoneBuffer& buffer) const {
158 if (exported_) { 161 if (exported_) {
159 buffer.write_size(name_.size()); 162 const ZoneVector<char>* exported_name =
160 if (name_.size() > 0) { 163 exported_name_.size() == 0 ? &name_ : &exported_name_;
161 buffer.write(reinterpret_cast<const byte*>(&name_[0]), name_.size()); 164 buffer.write_size(exported_name->size());
162 } 165 buffer.write(reinterpret_cast<const byte*>(exported_name->data()),
166 exported_name->size());
163 buffer.write_u8(kExternalFunction); 167 buffer.write_u8(kExternalFunction);
164 buffer.write_u32v(func_index_ + 168 buffer.write_u32v(func_index_ +
165 static_cast<uint32_t>(builder_->imports_.size())); 169 static_cast<uint32_t>(builder_->imports_.size()));
166 } 170 }
167 } 171 }
168 172
169 void WasmFunctionBuilder::WriteBody(ZoneBuffer& buffer) const { 173 void WasmFunctionBuilder::WriteBody(ZoneBuffer& buffer) const {
170 size_t locals_size = locals_.Size(); 174 size_t locals_size = locals_.Size();
171 buffer.write_size(locals_size + body_.size()); 175 buffer.write_size(locals_size + body_.size());
172 buffer.EnsureSpace(locals_size); 176 buffer.EnsureSpace(locals_size);
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 function->name_.size()); 490 function->name_.size());
487 } 491 }
488 buffer.write_u8(0); 492 buffer.write_u8(0);
489 } 493 }
490 FixupSection(buffer, start); 494 FixupSection(buffer, start);
491 } 495 }
492 } 496 }
493 } // namespace wasm 497 } // namespace wasm
494 } // namespace internal 498 } // namespace internal
495 } // namespace v8 499 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-module-builder.h ('k') | test/cctest/wasm/test-run-wasm-module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698