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

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

Issue 1775873002: [Wasm] Convert many of the fixed-size values to LEB128. (Closed) Base URL: http://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix windows Created 4 years, 9 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.cc ('k') | src/wasm/wasm-macro-gen.h » ('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/macro-assembler.h" 5 #include "src/macro-assembler.h"
6 #include "src/objects.h" 6 #include "src/objects.h"
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/wasm/decoder.h" 9 #include "src/wasm/decoder.h"
10 #include "src/wasm/module-decoder.h" 10 #include "src/wasm/module-decoder.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 CheckForPreviousSection(sections, kDeclFunctions, true); 188 CheckForPreviousSection(sections, kDeclFunctions, true);
189 int length; 189 int length;
190 uint32_t function_table_count = 190 uint32_t function_table_count =
191 consume_u32v(&length, "function table count"); 191 consume_u32v(&length, "function table count");
192 module->function_table.reserve(SafeReserve(function_table_count)); 192 module->function_table.reserve(SafeReserve(function_table_count));
193 // Decode function table. 193 // Decode function table.
194 for (uint32_t i = 0; i < function_table_count; i++) { 194 for (uint32_t i = 0; i < function_table_count; i++) {
195 if (failed()) break; 195 if (failed()) break;
196 TRACE("DecodeFunctionTable[%d] module+%d\n", i, 196 TRACE("DecodeFunctionTable[%d] module+%d\n", i,
197 static_cast<int>(pc_ - start_)); 197 static_cast<int>(pc_ - start_));
198 uint16_t index = consume_u16(); 198 uint16_t index = consume_u32v(&length);
199 if (index >= module->functions.size()) { 199 if (index >= module->functions.size()) {
200 error(pc_ - 2, "invalid function index"); 200 error(pc_ - 2, "invalid function index");
201 break; 201 break;
202 } 202 }
203 module->function_table.push_back(index); 203 module->function_table.push_back(index);
204 } 204 }
205 break; 205 break;
206 } 206 }
207 case kDeclStartFunction: { 207 case kDeclStartFunction: {
208 // Declares a start function for a module. 208 // Declares a start function for a module.
(...skipping 28 matching lines...) Expand all
237 // Decode import table. 237 // Decode import table.
238 for (uint32_t i = 0; i < import_table_count; i++) { 238 for (uint32_t i = 0; i < import_table_count; i++) {
239 if (failed()) break; 239 if (failed()) break;
240 TRACE("DecodeImportTable[%d] module+%d\n", i, 240 TRACE("DecodeImportTable[%d] module+%d\n", i,
241 static_cast<int>(pc_ - start_)); 241 static_cast<int>(pc_ - start_));
242 242
243 module->import_table.push_back({nullptr, 0, 0}); 243 module->import_table.push_back({nullptr, 0, 0});
244 WasmImport* import = &module->import_table.back(); 244 WasmImport* import = &module->import_table.back();
245 245
246 const byte* sigpos = pc_; 246 const byte* sigpos = pc_;
247 import->sig_index = consume_u16("signature index"); 247 import->sig_index = consume_u32v(&length, "signature index");
248 248
249 if (import->sig_index >= module->signatures.size()) { 249 if (import->sig_index >= module->signatures.size()) {
250 error(sigpos, "invalid signature index"); 250 error(sigpos, "invalid signature index");
251 } else { 251 } else {
252 import->sig = module->signatures[import->sig_index]; 252 import->sig = module->signatures[import->sig_index];
253 } 253 }
254 const byte* pos = pc_; 254 const byte* pos = pc_;
255 import->module_name_offset = consume_string("import module name"); 255 import->module_name_offset = consume_string("import module name");
256 if (import->module_name_offset == 0) { 256 if (import->module_name_offset == 0) {
257 error(pos, "import module name cannot be NULL"); 257 error(pos, "import module name cannot be NULL");
(...skipping 13 matching lines...) Expand all
271 // Decode export table. 271 // Decode export table.
272 for (uint32_t i = 0; i < export_table_count; i++) { 272 for (uint32_t i = 0; i < export_table_count; i++) {
273 if (failed()) break; 273 if (failed()) break;
274 TRACE("DecodeExportTable[%d] module+%d\n", i, 274 TRACE("DecodeExportTable[%d] module+%d\n", i,
275 static_cast<int>(pc_ - start_)); 275 static_cast<int>(pc_ - start_));
276 276
277 module->export_table.push_back({0, 0}); 277 module->export_table.push_back({0, 0});
278 WasmExport* exp = &module->export_table.back(); 278 WasmExport* exp = &module->export_table.back();
279 279
280 const byte* sigpos = pc_; 280 const byte* sigpos = pc_;
281 exp->func_index = consume_u16("function index"); 281 exp->func_index = consume_u32v(&length, "function index");
282 if (exp->func_index >= module->functions.size()) { 282 if (exp->func_index >= module->functions.size()) {
283 error(sigpos, sigpos, 283 error(sigpos, sigpos,
284 "function index %u out of bounds (%d functions)", 284 "function index %u out of bounds (%d functions)",
285 exp->func_index, 285 exp->func_index,
286 static_cast<int>(module->functions.size())); 286 static_cast<int>(module->functions.size()));
287 } 287 }
288 exp->name_offset = consume_string("export name"); 288 exp->name_offset = consume_string("export name");
289 } 289 }
290 break; 290 break;
291 } 291 }
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 case kMemF64: 559 case kMemF64:
560 return MachineType::Float64(); 560 return MachineType::Float64();
561 default: 561 default:
562 error(pc_ - 1, "invalid memory type"); 562 error(pc_ - 1, "invalid memory type");
563 return MachineType::None(); 563 return MachineType::None();
564 } 564 }
565 } 565 }
566 566
567 // Parses an inline function signature. 567 // Parses an inline function signature.
568 FunctionSig* consume_sig() { 568 FunctionSig* consume_sig() {
569 byte count = consume_u8("param count"); 569 int length;
570 byte count = consume_u32v(&length, "param count");
570 LocalType ret = consume_local_type(); 571 LocalType ret = consume_local_type();
571 FunctionSig::Builder builder(module_zone, ret == kAstStmt ? 0 : 1, count); 572 FunctionSig::Builder builder(module_zone, ret == kAstStmt ? 0 : 1, count);
572 if (ret != kAstStmt) builder.AddReturn(ret); 573 if (ret != kAstStmt) builder.AddReturn(ret);
573 574
574 for (int i = 0; i < count; i++) { 575 for (int i = 0; i < count; i++) {
575 LocalType param = consume_local_type(); 576 LocalType param = consume_local_type();
576 if (param == kAstStmt) error(pc_ - 1, "invalid void parameter type"); 577 if (param == kAstStmt) error(pc_ - 1, "invalid void parameter type");
577 builder.AddParam(param); 578 builder.AddParam(param);
578 } 579 }
579 return builder.Build(); 580 return builder.Build();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 if (function_start > function_end) return FunctionError("start > end"); 636 if (function_start > function_end) return FunctionError("start > end");
636 if (size > kMaxFunctionSize) 637 if (size > kMaxFunctionSize)
637 return FunctionError("size > maximum function size"); 638 return FunctionError("size > maximum function size");
638 WasmFunction* function = new WasmFunction(); 639 WasmFunction* function = new WasmFunction();
639 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin); 640 ModuleDecoder decoder(zone, function_start, function_end, kWasmOrigin);
640 return decoder.DecodeSingleFunction(module_env, function); 641 return decoder.DecodeSingleFunction(module_env, function);
641 } 642 }
642 } // namespace wasm 643 } // namespace wasm
643 } // namespace internal 644 } // namespace internal
644 } // namespace v8 645 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/encoder.cc ('k') | src/wasm/wasm-macro-gen.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698