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

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

Issue 2594993002: [wasm] Rename wasm::LocalType to wasm::ValueType and kAst* to kWasm* (Closed)
Patch Set: Fix inspector tests Created 4 years 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') | src/wasm/wasm-opcodes.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/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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 body_.push_back(*p); 69 body_.push_back(*p);
70 } 70 }
71 } 71 }
72 72
73 void WasmFunctionBuilder::SetSignature(FunctionSig* sig) { 73 void WasmFunctionBuilder::SetSignature(FunctionSig* sig) {
74 DCHECK(!locals_.has_sig()); 74 DCHECK(!locals_.has_sig());
75 locals_.set_sig(sig); 75 locals_.set_sig(sig);
76 signature_index_ = builder_->AddSignature(sig); 76 signature_index_ = builder_->AddSignature(sig);
77 } 77 }
78 78
79 uint32_t WasmFunctionBuilder::AddLocal(LocalType type) { 79 uint32_t WasmFunctionBuilder::AddLocal(ValueType type) {
80 DCHECK(locals_.has_sig()); 80 DCHECK(locals_.has_sig());
81 return locals_.AddLocals(1, type); 81 return locals_.AddLocals(1, type);
82 } 82 }
83 83
84 void WasmFunctionBuilder::EmitGetLocal(uint32_t local_index) { 84 void WasmFunctionBuilder::EmitGetLocal(uint32_t local_index) {
85 EmitWithVarInt(kExprGetLocal, local_index); 85 EmitWithVarInt(kExprGetLocal, local_index);
86 } 86 }
87 87
88 void WasmFunctionBuilder::EmitSetLocal(uint32_t local_index) { 88 void WasmFunctionBuilder::EmitSetLocal(uint32_t local_index) {
89 EmitWithVarInt(kExprSetLocal, local_index); 89 EmitWithVarInt(kExprSetLocal, local_index);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 uint32_t WasmModuleBuilder::AddImport(const char* name, int name_length, 282 uint32_t WasmModuleBuilder::AddImport(const char* name, int name_length,
283 FunctionSig* sig) { 283 FunctionSig* sig) {
284 imports_.push_back({AddSignature(sig), name, name_length}); 284 imports_.push_back({AddSignature(sig), name, name_length});
285 return static_cast<uint32_t>(imports_.size() - 1); 285 return static_cast<uint32_t>(imports_.size() - 1);
286 } 286 }
287 287
288 void WasmModuleBuilder::MarkStartFunction(WasmFunctionBuilder* function) { 288 void WasmModuleBuilder::MarkStartFunction(WasmFunctionBuilder* function) {
289 start_function_index_ = function->func_index(); 289 start_function_index_ = function->func_index();
290 } 290 }
291 291
292 uint32_t WasmModuleBuilder::AddGlobal(LocalType type, bool exported, 292 uint32_t WasmModuleBuilder::AddGlobal(ValueType type, bool exported,
293 bool mutability, 293 bool mutability,
294 const WasmInitExpr& init) { 294 const WasmInitExpr& init) {
295 globals_.push_back({type, exported, mutability, init}); 295 globals_.push_back({type, exported, mutability, init});
296 return static_cast<uint32_t>(globals_.size() - 1); 296 return static_cast<uint32_t>(globals_.size() - 1);
297 } 297 }
298 298
299 void WasmModuleBuilder::WriteTo(ZoneBuffer& buffer) const { 299 void WasmModuleBuilder::WriteTo(ZoneBuffer& buffer) const {
300 uint32_t exports = 0; 300 uint32_t exports = 0;
301 301
302 // == Emit magic ============================================================= 302 // == Emit magic =============================================================
303 TRACE("emit magic\n"); 303 TRACE("emit magic\n");
304 buffer.write_u32(kWasmMagic); 304 buffer.write_u32(kWasmMagic);
305 buffer.write_u32(kWasmVersion); 305 buffer.write_u32(kWasmVersion);
306 306
307 // == Emit signatures ======================================================== 307 // == Emit signatures ========================================================
308 if (signatures_.size() > 0) { 308 if (signatures_.size() > 0) {
309 size_t start = EmitSection(kTypeSectionCode, buffer); 309 size_t start = EmitSection(kTypeSectionCode, buffer);
310 buffer.write_size(signatures_.size()); 310 buffer.write_size(signatures_.size());
311 311
312 for (FunctionSig* sig : signatures_) { 312 for (FunctionSig* sig : signatures_) {
313 buffer.write_u8(kWasmFunctionTypeForm); 313 buffer.write_u8(kWasmFunctionTypeForm);
314 buffer.write_size(sig->parameter_count()); 314 buffer.write_size(sig->parameter_count());
315 for (size_t j = 0; j < sig->parameter_count(); j++) { 315 for (size_t j = 0; j < sig->parameter_count(); j++) {
316 buffer.write_u8(WasmOpcodes::LocalTypeCodeFor(sig->GetParam(j))); 316 buffer.write_u8(WasmOpcodes::ValueTypeCodeFor(sig->GetParam(j)));
317 } 317 }
318 buffer.write_size(sig->return_count()); 318 buffer.write_size(sig->return_count());
319 for (size_t j = 0; j < sig->return_count(); j++) { 319 for (size_t j = 0; j < sig->return_count(); j++) {
320 buffer.write_u8(WasmOpcodes::LocalTypeCodeFor(sig->GetReturn(j))); 320 buffer.write_u8(WasmOpcodes::ValueTypeCodeFor(sig->GetReturn(j)));
321 } 321 }
322 } 322 }
323 FixupSection(buffer, start); 323 FixupSection(buffer, start);
324 } 324 }
325 325
326 // == Emit imports =========================================================== 326 // == Emit imports ===========================================================
327 if (imports_.size() > 0) { 327 if (imports_.size() > 0) {
328 size_t start = EmitSection(kImportSectionCode, buffer); 328 size_t start = EmitSection(kImportSectionCode, buffer);
329 buffer.write_size(imports_.size()); 329 buffer.write_size(imports_.size());
330 for (auto import : imports_) { 330 for (auto import : imports_) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 buffer.write_u32v(32); // max memory size 371 buffer.write_u32v(32); // max memory size
372 FixupSection(buffer, start); 372 FixupSection(buffer, start);
373 } 373 }
374 374
375 // == Emit globals =========================================================== 375 // == Emit globals ===========================================================
376 if (globals_.size() > 0) { 376 if (globals_.size() > 0) {
377 size_t start = EmitSection(kGlobalSectionCode, buffer); 377 size_t start = EmitSection(kGlobalSectionCode, buffer);
378 buffer.write_size(globals_.size()); 378 buffer.write_size(globals_.size());
379 379
380 for (auto global : globals_) { 380 for (auto global : globals_) {
381 buffer.write_u8(WasmOpcodes::LocalTypeCodeFor(global.type)); 381 buffer.write_u8(WasmOpcodes::ValueTypeCodeFor(global.type));
382 buffer.write_u8(global.mutability ? 1 : 0); 382 buffer.write_u8(global.mutability ? 1 : 0);
383 switch (global.init.kind) { 383 switch (global.init.kind) {
384 case WasmInitExpr::kI32Const: { 384 case WasmInitExpr::kI32Const: {
385 DCHECK_EQ(kAstI32, global.type); 385 DCHECK_EQ(kWasmI32, global.type);
386 const byte code[] = {WASM_I32V_5(global.init.val.i32_const)}; 386 const byte code[] = {WASM_I32V_5(global.init.val.i32_const)};
387 buffer.write(code, sizeof(code)); 387 buffer.write(code, sizeof(code));
388 break; 388 break;
389 } 389 }
390 case WasmInitExpr::kI64Const: { 390 case WasmInitExpr::kI64Const: {
391 DCHECK_EQ(kAstI64, global.type); 391 DCHECK_EQ(kWasmI64, global.type);
392 const byte code[] = {WASM_I64V_10(global.init.val.i64_const)}; 392 const byte code[] = {WASM_I64V_10(global.init.val.i64_const)};
393 buffer.write(code, sizeof(code)); 393 buffer.write(code, sizeof(code));
394 break; 394 break;
395 } 395 }
396 case WasmInitExpr::kF32Const: { 396 case WasmInitExpr::kF32Const: {
397 DCHECK_EQ(kAstF32, global.type); 397 DCHECK_EQ(kWasmF32, global.type);
398 const byte code[] = {WASM_F32(global.init.val.f32_const)}; 398 const byte code[] = {WASM_F32(global.init.val.f32_const)};
399 buffer.write(code, sizeof(code)); 399 buffer.write(code, sizeof(code));
400 break; 400 break;
401 } 401 }
402 case WasmInitExpr::kF64Const: { 402 case WasmInitExpr::kF64Const: {
403 DCHECK_EQ(kAstF64, global.type); 403 DCHECK_EQ(kWasmF64, global.type);
404 const byte code[] = {WASM_F64(global.init.val.f64_const)}; 404 const byte code[] = {WASM_F64(global.init.val.f64_const)};
405 buffer.write(code, sizeof(code)); 405 buffer.write(code, sizeof(code));
406 break; 406 break;
407 } 407 }
408 case WasmInitExpr::kGlobalIndex: { 408 case WasmInitExpr::kGlobalIndex: {
409 const byte code[] = {kExprGetGlobal, 409 const byte code[] = {kExprGetGlobal,
410 U32V_5(global.init.val.global_index)}; 410 U32V_5(global.init.val.global_index)};
411 buffer.write(code, sizeof(code)); 411 buffer.write(code, sizeof(code));
412 break; 412 break;
413 } 413 }
414 default: { 414 default: {
415 // No initializer, emit a default value. 415 // No initializer, emit a default value.
416 switch (global.type) { 416 switch (global.type) {
417 case kAstI32: { 417 case kWasmI32: {
418 const byte code[] = {WASM_I32V_1(0)}; 418 const byte code[] = {WASM_I32V_1(0)};
419 buffer.write(code, sizeof(code)); 419 buffer.write(code, sizeof(code));
420 break; 420 break;
421 } 421 }
422 case kAstI64: { 422 case kWasmI64: {
423 const byte code[] = {WASM_I64V_1(0)}; 423 const byte code[] = {WASM_I64V_1(0)};
424 buffer.write(code, sizeof(code)); 424 buffer.write(code, sizeof(code));
425 break; 425 break;
426 } 426 }
427 case kAstF32: { 427 case kWasmF32: {
428 const byte code[] = {WASM_F32(0.0)}; 428 const byte code[] = {WASM_F32(0.0)};
429 buffer.write(code, sizeof(code)); 429 buffer.write(code, sizeof(code));
430 break; 430 break;
431 } 431 }
432 case kAstF64: { 432 case kWasmF64: {
433 const byte code[] = {WASM_F64(0.0)}; 433 const byte code[] = {WASM_F64(0.0)};
434 buffer.write(code, sizeof(code)); 434 buffer.write(code, sizeof(code));
435 break; 435 break;
436 } 436 }
437 default: 437 default:
438 UNREACHABLE(); 438 UNREACHABLE();
439 } 439 }
440 } 440 }
441 } 441 }
442 buffer.write_u8(kExprEnd); 442 buffer.write_u8(kExprEnd);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 // Emit the offset table per function. 535 // Emit the offset table per function.
536 for (auto function : functions_) { 536 for (auto function : functions_) {
537 function->WriteAsmWasmOffsetTable(buffer); 537 function->WriteAsmWasmOffsetTable(buffer);
538 } 538 }
539 // Append a 0 to indicate that this is an encoded table. 539 // Append a 0 to indicate that this is an encoded table.
540 buffer.write_u8(0); 540 buffer.write_u8(0);
541 } 541 }
542 } // namespace wasm 542 } // namespace wasm
543 } // namespace internal 543 } // namespace internal
544 } // namespace v8 544 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-module-builder.h ('k') | src/wasm/wasm-opcodes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698