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

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

Issue 1765673002: [wasm] Update {i32,i64}.const to use signed leb128 (Closed) Base URL: http://chromium.googlesource.com/v8/v8.git@master
Patch Set: nits, WASM_I64V fixes 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 | « no previous file | src/wasm/ast-decoder.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/v8.h" 5 #include "src/v8.h"
6 6
7 // Required to get M_E etc. in MSVC. 7 // Required to get M_E etc. in MSVC.
8 #if defined(_WIN32) 8 #if defined(_WIN32)
9 #define _USE_MATH_DEFINES 9 #define _USE_MATH_DEFINES
10 #endif 10 #endif
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 if (!in_function_) { 230 if (!in_function_) {
231 marking_exported = false; 231 marking_exported = false;
232 } 232 }
233 } 233 }
234 234
235 void VisitWithStatement(WithStatement* stmt) { UNREACHABLE(); } 235 void VisitWithStatement(WithStatement* stmt) { UNREACHABLE(); }
236 236
237 void SetLocalTo(uint16_t index, int value) { 237 void SetLocalTo(uint16_t index, int value) {
238 current_function_builder_->Emit(kExprSetLocal); 238 current_function_builder_->Emit(kExprSetLocal);
239 AddLeb128(index, true); 239 AddLeb128(index, true);
240 byte code[] = {WASM_I32(value)}; 240 // TODO(bradnelson): variable size
241 byte code[] = {WASM_I32V(value)};
241 current_function_builder_->EmitCode(code, sizeof(code)); 242 current_function_builder_->EmitCode(code, sizeof(code));
242 block_size_++; 243 block_size_++;
243 } 244 }
244 245
245 void CompileCase(CaseClause* clause, uint16_t fall_through, 246 void CompileCase(CaseClause* clause, uint16_t fall_through,
246 VariableProxy* tag) { 247 VariableProxy* tag) {
247 Literal* label = clause->label()->AsLiteral(); 248 Literal* label = clause->label()->AsLiteral();
248 DCHECK_NOT_NULL(label); 249 DCHECK_NOT_NULL(label);
249 block_size_++; 250 block_size_++;
250 current_function_builder_->Emit(kExprIf); 251 current_function_builder_->Emit(kExprIf);
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 } 459 }
459 } 460 }
460 461
461 void VisitLiteral(Literal* expr) { 462 void VisitLiteral(Literal* expr) {
462 if (in_function_) { 463 if (in_function_) {
463 if (expr->raw_value()->IsNumber()) { 464 if (expr->raw_value()->IsNumber()) {
464 LocalType type = TypeOf(expr); 465 LocalType type = TypeOf(expr);
465 switch (type) { 466 switch (type) {
466 case kAstI32: { 467 case kAstI32: {
467 int val = static_cast<int>(expr->raw_value()->AsNumber()); 468 int val = static_cast<int>(expr->raw_value()->AsNumber());
468 byte code[] = {WASM_I32(val)}; 469 // TODO(bradnelson): variable size
470 byte code[] = {WASM_I32V(val)};
469 current_function_builder_->EmitCode(code, sizeof(code)); 471 current_function_builder_->EmitCode(code, sizeof(code));
470 break; 472 break;
471 } 473 }
472 case kAstF32: { 474 case kAstF32: {
473 float val = static_cast<float>(expr->raw_value()->AsNumber()); 475 float val = static_cast<float>(expr->raw_value()->AsNumber());
474 byte code[] = {WASM_F32(val)}; 476 byte code[] = {WASM_F32(val)};
475 current_function_builder_->EmitCode(code, sizeof(code)); 477 current_function_builder_->EmitCode(code, sizeof(code));
476 break; 478 break;
477 } 479 }
478 case kAstF64: { 480 case kAstF64: {
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 return; 737 return;
736 } 738 }
737 } 739 }
738 } else { 740 } else {
739 MaybeHandle<Object> maybe_nvalue = 741 MaybeHandle<Object> maybe_nvalue =
740 i::Object::ToInt32(isolate_, value); 742 i::Object::ToInt32(isolate_, value);
741 if (!maybe_nvalue.is_null()) { 743 if (!maybe_nvalue.is_null()) {
742 Handle<Object> nvalue = maybe_nvalue.ToHandleChecked(); 744 Handle<Object> nvalue = maybe_nvalue.ToHandleChecked();
743 if (nvalue->IsNumber()) { 745 if (nvalue->IsNumber()) {
744 int32_t val = static_cast<int32_t>(nvalue->Number()); 746 int32_t val = static_cast<int32_t>(nvalue->Number());
745 byte code[] = {WASM_I32(val)}; 747 // TODO(bradnelson): variable size
748 byte code[] = {WASM_I32V(val)};
746 current_function_builder_->EmitCode(code, sizeof(code)); 749 current_function_builder_->EmitCode(code, sizeof(code));
747 return; 750 return;
748 } 751 }
749 } 752 }
750 } 753 }
751 } 754 }
752 } 755 }
753 if (is_float) { 756 if (is_float) {
754 byte code[] = {WASM_F64(std::numeric_limits<double>::quiet_NaN())}; 757 byte code[] = {WASM_F64(std::numeric_limits<double>::quiet_NaN())};
755 current_function_builder_->EmitCode(code, sizeof(code)); 758 current_function_builder_->EmitCode(code, sizeof(code));
756 } else { 759 } else {
757 byte code[] = {WASM_I32(0)}; 760 byte code[] = {WASM_I32V_1(0)};
758 current_function_builder_->EmitCode(code, sizeof(code)); 761 current_function_builder_->EmitCode(code, sizeof(code));
759 } 762 }
760 } 763 }
761 764
762 void VisitProperty(Property* expr) { 765 void VisitProperty(Property* expr) {
763 Expression* obj = expr->obj(); 766 Expression* obj = expr->obj();
764 DCHECK_EQ(obj->bounds().lower, obj->bounds().upper); 767 DCHECK_EQ(obj->bounds().lower, obj->bounds().upper);
765 Type* type = obj->bounds().lower; 768 Type* type = obj->bounds().lower;
766 MachineType mtype; 769 MachineType mtype;
767 int size; 770 int size;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 // Early versions of Emscripten emit HEAP8[HEAP32[..]|0] in 808 // Early versions of Emscripten emit HEAP8[HEAP32[..]|0] in
806 // places that strictly should be HEAP8[HEAP32[..]>>0]. 809 // places that strictly should be HEAP8[HEAP32[..]>>0].
807 RECURSE(Visit(expr->key())); 810 RECURSE(Visit(expr->key()));
808 return; 811 return;
809 } else { 812 } else {
810 Literal* value = expr->key()->AsLiteral(); 813 Literal* value = expr->key()->AsLiteral();
811 if (value) { 814 if (value) {
812 DCHECK(value->raw_value()->IsNumber()); 815 DCHECK(value->raw_value()->IsNumber());
813 DCHECK_EQ(kAstI32, TypeOf(value)); 816 DCHECK_EQ(kAstI32, TypeOf(value));
814 int val = static_cast<int>(value->raw_value()->AsNumber()); 817 int val = static_cast<int>(value->raw_value()->AsNumber());
815 byte code[] = {WASM_I32(val * size)}; 818 // TODO(bradnelson): variable size
819 byte code[] = {WASM_I32V(val * size)};
816 current_function_builder_->EmitCode(code, sizeof(code)); 820 current_function_builder_->EmitCode(code, sizeof(code));
817 return; 821 return;
818 } 822 }
819 BinaryOperation* binop = expr->key()->AsBinaryOperation(); 823 BinaryOperation* binop = expr->key()->AsBinaryOperation();
820 if (binop) { 824 if (binop) {
821 DCHECK_EQ(Token::SAR, binop->op()); 825 DCHECK_EQ(Token::SAR, binop->op());
822 DCHECK(binop->right()->AsLiteral()->raw_value()->IsNumber()); 826 DCHECK(binop->right()->AsLiteral()->raw_value()->IsNumber());
823 DCHECK(kAstI32 == TypeOf(binop->right()->AsLiteral())); 827 DCHECK(kAstI32 == TypeOf(binop->right()->AsLiteral()));
824 DCHECK_EQ(size, 828 DCHECK_EQ(size,
825 1 << static_cast<int>( 829 1 << static_cast<int>(
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1050 case Call::KEYED_PROPERTY_CALL: { 1054 case Call::KEYED_PROPERTY_CALL: {
1051 DCHECK(in_function_); 1055 DCHECK(in_function_);
1052 Property* p = expr->expression()->AsProperty(); 1056 Property* p = expr->expression()->AsProperty();
1053 DCHECK_NOT_NULL(p); 1057 DCHECK_NOT_NULL(p);
1054 VariableProxy* var = p->obj()->AsVariableProxy(); 1058 VariableProxy* var = p->obj()->AsVariableProxy();
1055 DCHECK_NOT_NULL(var); 1059 DCHECK_NOT_NULL(var);
1056 FunctionTableIndices* indices = LookupFunctionTable(var->var()); 1060 FunctionTableIndices* indices = LookupFunctionTable(var->var());
1057 current_function_builder_->EmitWithU8(kExprCallIndirect, 1061 current_function_builder_->EmitWithU8(kExprCallIndirect,
1058 indices->signature_index); 1062 indices->signature_index);
1059 current_function_builder_->Emit(kExprI32Add); 1063 current_function_builder_->Emit(kExprI32Add);
1060 byte code[] = {WASM_I32(indices->start_index)}; 1064 // TODO(bradnelson): variable size
1065 byte code[] = {WASM_I32V(indices->start_index)};
1061 current_function_builder_->EmitCode(code, sizeof(code)); 1066 current_function_builder_->EmitCode(code, sizeof(code));
1062 RECURSE(Visit(p->key())); 1067 RECURSE(Visit(p->key()));
1063 break; 1068 break;
1064 } 1069 }
1065 default: 1070 default:
1066 UNREACHABLE(); 1071 UNREACHABLE();
1067 } 1072 }
1068 VisitCallArgs(expr); 1073 VisitCallArgs(expr);
1069 } 1074 }
1070 1075
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
1512 // that zone in constructor may be thrown away once wasm module is written. 1517 // that zone in constructor may be thrown away once wasm module is written.
1513 WasmModuleIndex* AsmWasmBuilder::Run() { 1518 WasmModuleIndex* AsmWasmBuilder::Run() {
1514 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_, typer_); 1519 AsmWasmBuilderImpl impl(isolate_, zone_, literal_, foreign_, typer_);
1515 impl.Compile(); 1520 impl.Compile();
1516 WasmModuleWriter* writer = impl.builder_->Build(zone_); 1521 WasmModuleWriter* writer = impl.builder_->Build(zone_);
1517 return writer->WriteTo(zone_); 1522 return writer->WriteTo(zone_);
1518 } 1523 }
1519 } // namespace wasm 1524 } // namespace wasm
1520 } // namespace internal 1525 } // namespace internal
1521 } // namespace v8 1526 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/wasm/ast-decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698