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

Side by Side Diff: src/wasm/encoder.cc

Issue 1583603002: Add __init__ function to all modules created in asm-to-wasm (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@refactor
Patch Set: Created 4 years, 11 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/encoder.h ('k') | test/mjsunit/wasm/asm-wasm.js » ('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-containers.h" 9 #include "src/zone-containers.h"
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 } 56 }
57 } // namespace 57 } // namespace
58 58
59 59
60 struct WasmFunctionBuilder::Type { 60 struct WasmFunctionBuilder::Type {
61 bool param_; 61 bool param_;
62 LocalType type_; 62 LocalType type_;
63 }; 63 };
64 64
65 65
66 WasmFunctionBuilder::WasmFunctionBuilder(Zone* zone, const unsigned char* name, 66 WasmFunctionBuilder::WasmFunctionBuilder(Zone* zone)
67 int name_length)
68 : return_type_(kAstI32), 67 : return_type_(kAstI32),
69 locals_(zone), 68 locals_(zone),
70 exported_(0), 69 exported_(0),
71 external_(0), 70 external_(0),
72 body_(zone), 71 body_(zone),
73 local_indices_(zone), 72 local_indices_(zone),
74 name_(zone) { 73 name_(zone) {}
75 if (name_length > 0) {
76 for (int i = 0; i < name_length; i++) {
77 name_.push_back(*(name + i));
78 }
79 name_.push_back('\0');
80 }
81 }
82 74
83 75
84 uint16_t WasmFunctionBuilder::AddParam(LocalType type) { 76 uint16_t WasmFunctionBuilder::AddParam(LocalType type) {
85 return AddVar(type, true); 77 return AddVar(type, true);
86 } 78 }
87 79
88 80
89 uint16_t WasmFunctionBuilder::AddLocal(LocalType type) { 81 uint16_t WasmFunctionBuilder::AddLocal(LocalType type) {
90 return AddVar(type, false); 82 return AddVar(type, false);
91 } 83 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 DCHECK(offset < body_.size()); 137 DCHECK(offset < body_.size());
146 body_[offset] = immediate; 138 body_[offset] = immediate;
147 } 139 }
148 140
149 141
150 void WasmFunctionBuilder::Exported(uint8_t flag) { exported_ = flag; } 142 void WasmFunctionBuilder::Exported(uint8_t flag) { exported_ = flag; }
151 143
152 144
153 void WasmFunctionBuilder::External(uint8_t flag) { external_ = flag; } 145 void WasmFunctionBuilder::External(uint8_t flag) { external_ = flag; }
154 146
147 void WasmFunctionBuilder::SetName(const unsigned char* name, int name_length) {
148 name_.clear();
149 if (name_length > 0) {
150 for (int i = 0; i < name_length; i++) {
151 name_.push_back(*(name + i));
152 }
153 name_.push_back('\0');
154 }
155 }
156
155 157
156 WasmFunctionEncoder* WasmFunctionBuilder::Build(Zone* zone, 158 WasmFunctionEncoder* WasmFunctionBuilder::Build(Zone* zone,
157 WasmModuleBuilder* mb) const { 159 WasmModuleBuilder* mb) const {
158 WasmFunctionEncoder* e = 160 WasmFunctionEncoder* e =
159 new (zone) WasmFunctionEncoder(zone, return_type_, exported_, external_); 161 new (zone) WasmFunctionEncoder(zone, return_type_, exported_, external_);
160 uint16_t* var_index = zone->NewArray<uint16_t>(locals_.size()); 162 uint16_t* var_index = zone->NewArray<uint16_t>(locals_.size());
161 IndexVars(e, var_index); 163 IndexVars(e, var_index);
162 if (body_.size() > 0) { 164 if (body_.size() > 0) {
163 // TODO(titzer): iterate over local indexes, not the bytes. 165 // TODO(titzer): iterate over local indexes, not the bytes.
164 const byte* start = &body_[0]; 166 const byte* start = &body_[0];
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 WasmModuleBuilder::WasmModuleBuilder(Zone* zone) 343 WasmModuleBuilder::WasmModuleBuilder(Zone* zone)
342 : zone_(zone), 344 : zone_(zone),
343 signatures_(zone), 345 signatures_(zone),
344 functions_(zone), 346 functions_(zone),
345 data_segments_(zone), 347 data_segments_(zone),
346 indirect_functions_(zone), 348 indirect_functions_(zone),
347 globals_(zone), 349 globals_(zone),
348 signature_map_(zone) {} 350 signature_map_(zone) {}
349 351
350 352
351 uint16_t WasmModuleBuilder::AddFunction(const unsigned char* name, 353 uint16_t WasmModuleBuilder::AddFunction() {
352 int name_length) { 354 functions_.push_back(new (zone_) WasmFunctionBuilder(zone_));
353 functions_.push_back(new (zone_)
354 WasmFunctionBuilder(zone_, name, name_length));
355 return static_cast<uint16_t>(functions_.size() - 1); 355 return static_cast<uint16_t>(functions_.size() - 1);
356 } 356 }
357 357
358 358
359 WasmFunctionBuilder* WasmModuleBuilder::FunctionAt(size_t index) { 359 WasmFunctionBuilder* WasmModuleBuilder::FunctionAt(size_t index) {
360 if (functions_.size() > index) { 360 if (functions_.size() > index) {
361 return functions_.at(index); 361 return functions_.at(index);
362 } else { 362 } else {
363 return nullptr; 363 return nullptr;
364 } 364 }
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 next = next | 0x80; 583 next = next | 0x80;
584 } 584 }
585 output.push_back(next); 585 output.push_back(next);
586 shift += 7; 586 shift += 7;
587 } while ((next & 0x80) != 0); 587 } while ((next & 0x80) != 0);
588 return output; 588 return output;
589 } 589 }
590 } // namespace wasm 590 } // namespace wasm
591 } // namespace internal 591 } // namespace internal
592 } // namespace v8 592 } // namespace v8
OLDNEW
« 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