OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 <cstring> | 5 #include <cstring> |
6 #include <functional> | 6 #include <functional> |
7 #include <iostream> | 7 #include <iostream> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "src/asmjs/asm-typer.h" | 10 #include "src/asmjs/asm-typer.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 VariableName& operator=(const VariableName&) = default; | 93 VariableName& operator=(const VariableName&) = default; |
94 | 94 |
95 const char* name_; | 95 const char* name_; |
96 const VariableMode mode_; | 96 const VariableMode mode_; |
97 }; | 97 }; |
98 | 98 |
99 AsmTyperHarnessBuilder* WithLocal(VariableName var_name, AsmType* type) { | 99 AsmTyperHarnessBuilder* WithLocal(VariableName var_name, AsmType* type) { |
100 CHECK(validation_type_ == ValidateStatement || | 100 CHECK(validation_type_ == ValidateStatement || |
101 validation_type_ == ValidateExpression); | 101 validation_type_ == ValidateExpression); |
102 auto* var = DeclareVariable(var_name); | 102 auto* var = DeclareVariable(var_name); |
| 103 if (var->IsUnallocated()) { |
| 104 var->AllocateTo(VariableLocation::LOCAL, -1); |
| 105 } |
103 auto* var_info = new (zone_) AsmTyper::VariableInfo(type); | 106 auto* var_info = new (zone_) AsmTyper::VariableInfo(type); |
104 var_info->set_mutability(AsmTyper::VariableInfo::kLocal); | 107 var_info->set_mutability(AsmTyper::VariableInfo::kLocal); |
105 CHECK(typer_->AddLocal(var, var_info)); | 108 CHECK(typer_->AddLocal(var, var_info)); |
106 return this; | 109 return this; |
107 } | 110 } |
108 | 111 |
109 AsmTyperHarnessBuilder* WithGlobal(VariableName var_name, AsmType* type) { | 112 AsmTyperHarnessBuilder* WithGlobal(VariableName var_name, AsmType* type) { |
110 auto* var = DeclareVariable(var_name); | 113 auto* var = DeclareVariable(var_name); |
111 auto* var_info = new (zone_) AsmTyper::VariableInfo(type); | 114 if (var->IsUnallocated()) { |
112 var_info->set_mutability(AsmTyper::VariableInfo::kMutableGlobal); | 115 var->AllocateTo(VariableLocation::MODULE, -1); |
113 CHECK(typer_->AddGlobal(var, var_info)); | 116 } |
| 117 if (type != nullptr) { |
| 118 auto* var_info = new (zone_) AsmTyper::VariableInfo(type); |
| 119 var_info->set_mutability(AsmTyper::VariableInfo::kMutableGlobal); |
| 120 CHECK(typer_->AddGlobal(var, var_info)); |
| 121 } |
114 return this; | 122 return this; |
115 } | 123 } |
116 | 124 |
117 AsmTyperHarnessBuilder* WithGlobal( | 125 AsmTyperHarnessBuilder* WithGlobal( |
118 VariableName var_name, std::function<AsmType*(Zone*)> type_creator) { | 126 VariableName var_name, std::function<AsmType*(Zone*)> type_creator) { |
119 return WithGlobal(var_name, type_creator(zone_)); | 127 return WithGlobal(var_name, type_creator(zone_)); |
120 } | 128 } |
121 | 129 |
122 AsmTyperHarnessBuilder* WithUndefinedGlobal( | 130 AsmTyperHarnessBuilder* WithUndefinedGlobal( |
123 VariableName var_name, std::function<AsmType*(Zone*)> type_creator) { | 131 VariableName var_name, std::function<AsmType*(Zone*)> type_creator) { |
124 auto* type = type_creator(zone_); | 132 auto* type = type_creator(zone_); |
125 CHECK(type->AsFunctionType() != nullptr || | 133 CHECK(type->AsFunctionType() != nullptr || |
126 type->AsFunctionTableType() != nullptr); | 134 type->AsFunctionTableType() != nullptr); |
127 WithGlobal(var_name, type); | 135 WithGlobal(var_name, type); |
128 auto* var_info = typer_->Lookup(DeclareVariable(var_name)); | 136 auto* var_info = typer_->Lookup(DeclareVariable(var_name)); |
129 CHECK(var_info); | 137 CHECK(var_info); |
130 MessageLocation location; | 138 MessageLocation location; |
131 var_info->SetFirstForwardUse(location); | 139 var_info->SetFirstForwardUse(location); |
132 return this; | 140 return this; |
133 } | 141 } |
134 | 142 |
135 AsmTyperHarnessBuilder* WithImport(VariableName var_name, | 143 AsmTyperHarnessBuilder* WithImport(VariableName var_name, |
136 AsmTyper::StandardMember standard_member) { | 144 AsmTyper::StandardMember standard_member) { |
137 auto* var = DeclareVariable(var_name); | 145 auto* var = DeclareVariable(var_name); |
| 146 if (var->IsUnallocated()) { |
| 147 var->AllocateTo(VariableLocation::LOCAL, -1); |
| 148 } |
138 AsmTyper::VariableInfo* var_info = nullptr; | 149 AsmTyper::VariableInfo* var_info = nullptr; |
139 auto* stdlib_map = &typer_->stdlib_math_types_; | 150 auto* stdlib_map = &typer_->stdlib_math_types_; |
140 switch (standard_member) { | 151 switch (standard_member) { |
141 case AsmTyper::kHeap: | 152 case AsmTyper::kHeap: |
142 case AsmTyper::kStdlib: | 153 case AsmTyper::kStdlib: |
143 case AsmTyper::kModule: | 154 case AsmTyper::kModule: |
144 case AsmTyper::kNone: | 155 case AsmTyper::kNone: |
145 CHECK(false); | 156 CHECK(false); |
146 case AsmTyper::kFFI: | 157 case AsmTyper::kFFI: |
147 stdlib_map = nullptr; | 158 stdlib_map = nullptr; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 | 223 |
213 if (validation_type_ == ValidateStatement) { | 224 if (validation_type_ == ValidateStatement) { |
214 CHECK(typer_->return_type_ != AsmType::None()); | 225 CHECK(typer_->return_type_ != AsmType::None()); |
215 if (ValidateAllStatements(fun_decl_)) { | 226 if (ValidateAllStatements(fun_decl_)) { |
216 return true; | 227 return true; |
217 } | 228 } |
218 } else if (typer_->Validate()) { | 229 } else if (typer_->Validate()) { |
219 return true; | 230 return true; |
220 } | 231 } |
221 | 232 |
222 std::cerr << "Asm validation failed: " << typer_->error_message() << "\n"; | 233 std::unique_ptr<char[]> msg = i::MessageHandler::GetLocalizedMessage( |
| 234 isolate_, typer_->error_message()); |
| 235 std::cerr << "Asm validation failed: " << msg.get() << "\n"; |
223 return false; | 236 return false; |
224 } | 237 } |
225 | 238 |
226 bool SucceedsWithExactType(AsmType* type) { | 239 bool SucceedsWithExactType(AsmType* type) { |
227 CHECK(validation_type_ == ValidateExpression); | 240 CHECK(validation_type_ == ValidateExpression); |
228 auto* validated_as = ValidateExpressionStatment(fun_decl_); | 241 auto* validated_as = ValidateExpressionStatment(fun_decl_); |
229 if (validated_as == AsmType::None()) { | 242 if (validated_as == AsmType::None()) { |
230 std::cerr << "Validation failure: " << typer_->error_message() << "\n"; | 243 std::unique_ptr<char[]> msg = i::MessageHandler::GetLocalizedMessage( |
| 244 isolate_, typer_->error_message()); |
| 245 std::cerr << "Validation failure: " << msg.get() << "\n"; |
231 return false; | 246 return false; |
232 } else if (validated_as != type) { | 247 } else if (validated_as != type) { |
233 std::cerr << "Validation succeeded with wrong type " | 248 std::cerr << "Validation succeeded with wrong type " |
234 << validated_as->Name() << " (vs. " << type->Name() << ").\n"; | 249 << validated_as->Name() << " (vs. " << type->Name() << ").\n"; |
235 return false; | 250 return false; |
236 } | 251 } |
237 | 252 |
238 return true; | 253 return true; |
239 } | 254 } |
240 | 255 |
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 {"return f();", "Unrecognized expression in asm.js module export"}, | 683 {"return f();", "Unrecognized expression in asm.js module export"}, |
669 {"return d2s_tbl;", "cannot export function tables"}, | 684 {"return d2s_tbl;", "cannot export function tables"}, |
670 {"return min;", "cannot export standard library functions"}, | 685 {"return min;", "cannot export standard library functions"}, |
671 {"return ffi;", "cannot export foreign functions"}, | 686 {"return ffi;", "cannot export foreign functions"}, |
672 {"return I;", "is not an asm.js function"}, | 687 {"return I;", "is not an asm.js function"}, |
673 {"return {'a': d2s_tbl}", "cannot export function tables"}, | 688 {"return {'a': d2s_tbl}", "cannot export function tables"}, |
674 {"return {'a': min}", "cannot export standard library functions"}, | 689 {"return {'a': min}", "cannot export standard library functions"}, |
675 {"return {'a': ffi}", "cannot export foreign functions"}, | 690 {"return {'a': ffi}", "cannot export foreign functions"}, |
676 {"return {'a': f()}", "must be an asm.js function name"}, | 691 {"return {'a': f()}", "must be an asm.js function name"}, |
677 {"return {'a': f}", "Undefined identifier in asm.js module export"}, | 692 {"return {'a': f}", "Undefined identifier in asm.js module export"}, |
678 {"function v() { a(); } return {b: d2s}", "Missing definition for forw"}, | 693 {"function v() { a(); } return {b: d2s}", |
| 694 "Invalid call of existing global function"}, |
679 {"function v() {} return {b: v, 'a': d2s_tbl}", | 695 {"function v() {} return {b: v, 'a': d2s_tbl}", |
680 "cannot export function tables"}, | 696 "cannot export function tables"}, |
681 {"function v() {} return {b: v, 'a': min}", | 697 {"function v() {} return {b: v, 'a': min}", |
682 "cannot export standard library"}, | 698 "cannot export standard library"}, |
683 {"function v() {} return {b: v, 'a': ffi}", | 699 {"function v() {} return {b: v, 'a': ffi}", |
684 "cannot export foreign functions"}, | 700 "cannot export foreign functions"}, |
685 {"function v() {} return {b: v, 'a': f()}", | 701 {"function v() {} return {b: v, 'a': f()}", |
686 "must be an asm.js function name"}, | 702 "must be an asm.js function name"}, |
687 {"function v() {} return {b: v, 'a': f}", | 703 {"function v() {} return {b: v, 'a': f}", |
688 "Undefined identifier in asm.js module"}, | 704 "Undefined identifier in asm.js module"}, |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 "Case label must be a 32-bit signed"}, | 921 "Case label must be a 32-bit signed"}, |
906 }; | 922 }; |
907 | 923 |
908 for (size_t ii = 0; ii < arraysize(kTests); ++ii) { | 924 for (size_t ii = 0; ii < arraysize(kTests); ++ii) { |
909 const auto* test = kTests + ii; | 925 const auto* test = kTests + ii; |
910 if (!ValidationOf(Statement(test->statement)) | 926 if (!ValidationOf(Statement(test->statement)) |
911 ->WithReturnType(iw::AsmType::Signed()) | 927 ->WithReturnType(iw::AsmType::Signed()) |
912 ->WithImport(DynamicGlobal("fround"), iw::AsmTyper::kMathFround) | 928 ->WithImport(DynamicGlobal("fround"), iw::AsmTyper::kMathFround) |
913 ->WithLocal(DynamicGlobal("flocal"), iw::AsmType::Float()) | 929 ->WithLocal(DynamicGlobal("flocal"), iw::AsmType::Float()) |
914 ->WithLocal(DynamicGlobal("slocal"), iw::AsmType::Signed()) | 930 ->WithLocal(DynamicGlobal("slocal"), iw::AsmType::Signed()) |
| 931 ->WithGlobal(DynamicGlobal("d"), nullptr) |
915 ->FailsWithMessage(test->error_message)) { | 932 ->FailsWithMessage(test->error_message)) { |
916 std::cerr << "Test:\n" << test->statement; | 933 std::cerr << "Test:\n" << test->statement; |
917 CHECK(false); | 934 CHECK(false); |
918 } | 935 } |
919 } | 936 } |
920 } | 937 } |
921 | 938 |
922 TEST(ErrorsInExpression) { | 939 TEST(ErrorsInExpression) { |
923 auto d2d = [](Zone* zone) -> iw::AsmType* { | 940 auto d2d = [](Zone* zone) -> iw::AsmType* { |
924 auto* ret = iw::AsmType::Function(zone, iw::AsmType::Double()); | 941 auto* ret = iw::AsmType::Function(zone, iw::AsmType::Double()); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 ->WithLocal(DynamicGlobal("ilocal"), iw::AsmType::Int()) | 1052 ->WithLocal(DynamicGlobal("ilocal"), iw::AsmType::Int()) |
1036 ->WithLocal(DynamicGlobal("dlocal"), iw::AsmType::Double()) | 1053 ->WithLocal(DynamicGlobal("dlocal"), iw::AsmType::Double()) |
1037 ->WithLocal(DynamicGlobal("dlocal2"), iw::AsmType::Double()) | 1054 ->WithLocal(DynamicGlobal("dlocal2"), iw::AsmType::Double()) |
1038 ->WithLocal(DynamicGlobal("not_a_function"), iw::AsmType::Int()) | 1055 ->WithLocal(DynamicGlobal("not_a_function"), iw::AsmType::Int()) |
1039 ->WithImport(DynamicGlobal("fround"), iw::AsmTyper::kMathFround) | 1056 ->WithImport(DynamicGlobal("fround"), iw::AsmTyper::kMathFround) |
1040 ->WithImport(DynamicGlobal("FFI"), iw::AsmTyper::kFFI) | 1057 ->WithImport(DynamicGlobal("FFI"), iw::AsmTyper::kFFI) |
1041 ->WithGlobal(DynamicGlobal("d2d"), d2d) | 1058 ->WithGlobal(DynamicGlobal("d2d"), d2d) |
1042 ->WithGlobal(DynamicGlobal("d2s_tbl"), d2s_tbl) | 1059 ->WithGlobal(DynamicGlobal("d2s_tbl"), d2s_tbl) |
1043 ->WithGlobal(DynamicGlobal("HEAP32"), iw::AsmType::Int32Array()) | 1060 ->WithGlobal(DynamicGlobal("HEAP32"), iw::AsmType::Int32Array()) |
1044 ->WithGlobal(DynamicGlobal("HEAP8"), iw::AsmType::Int8Array()) | 1061 ->WithGlobal(DynamicGlobal("HEAP8"), iw::AsmType::Int8Array()) |
| 1062 ->WithGlobal(DynamicGlobal("a"), nullptr) |
1045 ->FailsWithMessage(test->error_message)) { | 1063 ->FailsWithMessage(test->error_message)) { |
1046 std::cerr << "Test:\n" << test->expression; | 1064 std::cerr << "Test:\n" << test->expression; |
1047 CHECK(false); | 1065 CHECK(false); |
1048 } | 1066 } |
1049 } | 1067 } |
1050 } | 1068 } |
1051 | 1069 |
1052 TEST(ValidateNumericLiteral) { | 1070 TEST(ValidateNumericLiteral) { |
1053 const struct { | 1071 const struct { |
1054 const char* expression; | 1072 const char* expression; |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1362 ->WithLocal(DynamicGlobal("dlocal"), iw::AsmType::Double()) | 1380 ->WithLocal(DynamicGlobal("dlocal"), iw::AsmType::Double()) |
1363 ->WithLocal(DynamicGlobal("flocal"), iw::AsmType::Float()) | 1381 ->WithLocal(DynamicGlobal("flocal"), iw::AsmType::Float()) |
1364 ->WithGlobal(DynamicGlobal("I8"), iw::AsmType::Int8Array()) | 1382 ->WithGlobal(DynamicGlobal("I8"), iw::AsmType::Int8Array()) |
1365 ->WithGlobal(DynamicGlobal("U8"), iw::AsmType::Uint8Array()) | 1383 ->WithGlobal(DynamicGlobal("U8"), iw::AsmType::Uint8Array()) |
1366 ->WithGlobal(DynamicGlobal("I16"), iw::AsmType::Int16Array()) | 1384 ->WithGlobal(DynamicGlobal("I16"), iw::AsmType::Int16Array()) |
1367 ->WithGlobal(DynamicGlobal("U16"), iw::AsmType::Uint16Array()) | 1385 ->WithGlobal(DynamicGlobal("U16"), iw::AsmType::Uint16Array()) |
1368 ->WithGlobal(DynamicGlobal("I32"), iw::AsmType::Int32Array()) | 1386 ->WithGlobal(DynamicGlobal("I32"), iw::AsmType::Int32Array()) |
1369 ->WithGlobal(DynamicGlobal("U32"), iw::AsmType::Uint32Array()) | 1387 ->WithGlobal(DynamicGlobal("U32"), iw::AsmType::Uint32Array()) |
1370 ->WithGlobal(DynamicGlobal("F32"), iw::AsmType::Float32Array()) | 1388 ->WithGlobal(DynamicGlobal("F32"), iw::AsmType::Float32Array()) |
1371 ->WithGlobal(DynamicGlobal("F64"), iw::AsmType::Float64Array()) | 1389 ->WithGlobal(DynamicGlobal("F64"), iw::AsmType::Float64Array()) |
| 1390 ->WithGlobal(DynamicGlobal("make_float"), nullptr) |
| 1391 ->WithGlobal(DynamicGlobal("make_double"), nullptr) |
1372 ->SucceedsWithExactType(test->load_type)) { | 1392 ->SucceedsWithExactType(test->load_type)) { |
1373 std::cerr << "Test:\n" << test->expression; | 1393 std::cerr << "Test:\n" << test->expression; |
1374 CHECK(false); | 1394 CHECK(false); |
1375 } | 1395 } |
1376 } | 1396 } |
1377 } | 1397 } |
1378 | 1398 |
1379 TEST(ValidateUnaryExpression) { | 1399 TEST(ValidateUnaryExpression) { |
1380 auto v2d = [](Zone* zone) -> iw::AsmType* { | 1400 auto v2d = [](Zone* zone) -> iw::AsmType* { |
1381 auto* ret = iw::AsmType::Function(zone, iw::AsmType::Double()); | 1401 auto* ret = iw::AsmType::Function(zone, iw::AsmType::Double()); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1417 for (size_t ii = 0; ii < arraysize(kTests); ++ii) { | 1437 for (size_t ii = 0; ii < arraysize(kTests); ++ii) { |
1418 const auto* test = kTests + ii; | 1438 const auto* test = kTests + ii; |
1419 if (!ValidationOf(Expression(test->expression)) | 1439 if (!ValidationOf(Expression(test->expression)) |
1420 ->WithLocal(DynamicGlobal("fq"), iw::AsmType::FloatQ()) | 1440 ->WithLocal(DynamicGlobal("fq"), iw::AsmType::FloatQ()) |
1421 ->WithLocal(DynamicGlobal("dq"), iw::AsmType::DoubleQ()) | 1441 ->WithLocal(DynamicGlobal("dq"), iw::AsmType::DoubleQ()) |
1422 ->WithLocal(DynamicGlobal("iish"), iw::AsmType::Intish()) | 1442 ->WithLocal(DynamicGlobal("iish"), iw::AsmType::Intish()) |
1423 ->WithLocal(DynamicGlobal("slocal"), iw::AsmType::Signed()) | 1443 ->WithLocal(DynamicGlobal("slocal"), iw::AsmType::Signed()) |
1424 ->WithLocal(DynamicGlobal("ulocal"), iw::AsmType::Unsigned()) | 1444 ->WithLocal(DynamicGlobal("ulocal"), iw::AsmType::Unsigned()) |
1425 ->WithLocal(DynamicGlobal("ilocal"), iw::AsmType::Int()) | 1445 ->WithLocal(DynamicGlobal("ilocal"), iw::AsmType::Int()) |
1426 ->WithGlobal(DynamicGlobal("dglobal"), iw::AsmType::Double()) | 1446 ->WithGlobal(DynamicGlobal("dglobal"), iw::AsmType::Double()) |
| 1447 ->WithGlobal(DynamicGlobal("make_double"), nullptr) |
1427 ->WithGlobal(DynamicGlobal("dbl"), v2d) | 1448 ->WithGlobal(DynamicGlobal("dbl"), v2d) |
1428 ->SucceedsWithExactType(test->load_type)) { | 1449 ->SucceedsWithExactType(test->load_type)) { |
1429 std::cerr << "Test:\n" << test->expression; | 1450 std::cerr << "Test:\n" << test->expression; |
1430 CHECK(false); | 1451 CHECK(false); |
1431 } | 1452 } |
1432 } | 1453 } |
1433 } | 1454 } |
1434 | 1455 |
1435 TEST(ValidateMultiplicativeExpression) { | 1456 TEST(ValidateMultiplicativeExpression) { |
1436 const struct { | 1457 const struct { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1666 {"make_signed()|0", iw::AsmType::Signed()}, | 1687 {"make_signed()|0", iw::AsmType::Signed()}, |
1667 {"signed()|0", iw::AsmType::Signed()}, | 1688 {"signed()|0", iw::AsmType::Signed()}, |
1668 }; | 1689 }; |
1669 | 1690 |
1670 for (size_t ii = 0; ii < arraysize(kTests); ++ii) { | 1691 for (size_t ii = 0; ii < arraysize(kTests); ++ii) { |
1671 const auto* test = kTests + ii; | 1692 const auto* test = kTests + ii; |
1672 if (!ValidationOf(Expression(test->expression)) | 1693 if (!ValidationOf(Expression(test->expression)) |
1673 ->WithLocal(DynamicGlobal("iish1"), iw::AsmType::Intish()) | 1694 ->WithLocal(DynamicGlobal("iish1"), iw::AsmType::Intish()) |
1674 ->WithLocal(DynamicGlobal("iish0"), iw::AsmType::Intish()) | 1695 ->WithLocal(DynamicGlobal("iish0"), iw::AsmType::Intish()) |
1675 ->WithGlobal(DynamicGlobal("signed"), v2s) | 1696 ->WithGlobal(DynamicGlobal("signed"), v2s) |
| 1697 ->WithGlobal(DynamicGlobal("make_signed"), nullptr) |
1676 ->SucceedsWithExactType(test->load_type)) { | 1698 ->SucceedsWithExactType(test->load_type)) { |
1677 std::cerr << "Test:\n" << test->expression; | 1699 std::cerr << "Test:\n" << test->expression; |
1678 CHECK(false); | 1700 CHECK(false); |
1679 } | 1701 } |
1680 } | 1702 } |
1681 } | 1703 } |
1682 | 1704 |
1683 TEST(ValidateConditionalExpression) { | 1705 TEST(ValidateConditionalExpression) { |
1684 const struct { | 1706 const struct { |
1685 const char* expression; | 1707 const char* expression; |
(...skipping 27 matching lines...) Expand all Loading... |
1713 return ret; | 1735 return ret; |
1714 }; | 1736 }; |
1715 | 1737 |
1716 // ifd2_ is a helper function that returns a lambda for creating a function | 1738 // ifd2_ is a helper function that returns a lambda for creating a function |
1717 // type that accepts an int, a float, and a double. ret_type_factory is a | 1739 // type that accepts an int, a float, and a double. ret_type_factory is a |
1718 // pointer to an AsmType*() function, and (*ret_type_factory)() returns the | 1740 // pointer to an AsmType*() function, and (*ret_type_factory)() returns the |
1719 // desired return type. For example, | 1741 // desired return type. For example, |
1720 // | 1742 // |
1721 // ifd2_(&iw::AsmType::Float) | 1743 // ifd2_(&iw::AsmType::Float) |
1722 // | 1744 // |
1723 // returns an AsmType representing an asm.j function with the following | 1745 // returns an AsmType representing an asm.js function with the following |
1724 // signature: | 1746 // signature: |
1725 // | 1747 // |
1726 // float(int, float, double) | 1748 // float(int, float, double) |
1727 auto ifd2_ = [](iw::AsmType* ( | 1749 auto ifd2_ = [](iw::AsmType* ( |
1728 *ret_type_factory)()) -> std::function<iw::AsmType*(Zone*)> { | 1750 *ret_type_factory)()) -> std::function<iw::AsmType*(Zone*)> { |
1729 return [ret_type_factory](Zone* zone) -> iw::AsmType* { | 1751 return [ret_type_factory](Zone* zone) -> iw::AsmType* { |
1730 auto* ret = iw::AsmType::Function(zone, (*ret_type_factory)()); | 1752 auto* ret = iw::AsmType::Function(zone, (*ret_type_factory)()); |
1731 ret->AsFunctionType()->AddArgument(iw::AsmType::Int()); | 1753 ret->AsFunctionType()->AddArgument(iw::AsmType::Int()); |
1732 ret->AsFunctionType()->AddArgument(iw::AsmType::Float()); | 1754 ret->AsFunctionType()->AddArgument(iw::AsmType::Float()); |
1733 ret->AsFunctionType()->AddArgument(iw::AsmType::Double()); | 1755 ret->AsFunctionType()->AddArgument(iw::AsmType::Double()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1790 const auto* test = kTests + ii; | 1812 const auto* test = kTests + ii; |
1791 if (!ValidationOf(Expression(test->expression)) | 1813 if (!ValidationOf(Expression(test->expression)) |
1792 ->WithImport(DynamicGlobal("fround"), iw::AsmTyper::kMathFround) | 1814 ->WithImport(DynamicGlobal("fround"), iw::AsmTyper::kMathFround) |
1793 ->WithImport(DynamicGlobal("ffi"), iw::AsmTyper::kFFI) | 1815 ->WithImport(DynamicGlobal("ffi"), iw::AsmTyper::kFFI) |
1794 ->WithLocal(DynamicGlobal("fish"), iw::AsmType::Floatish()) | 1816 ->WithLocal(DynamicGlobal("fish"), iw::AsmType::Floatish()) |
1795 ->WithLocal(DynamicGlobal("dq"), iw::AsmType::DoubleQ()) | 1817 ->WithLocal(DynamicGlobal("dq"), iw::AsmType::DoubleQ()) |
1796 ->WithLocal(DynamicGlobal("s"), iw::AsmType::Signed()) | 1818 ->WithLocal(DynamicGlobal("s"), iw::AsmType::Signed()) |
1797 ->WithLocal(DynamicGlobal("u"), iw::AsmType::Unsigned()) | 1819 ->WithLocal(DynamicGlobal("u"), iw::AsmType::Unsigned()) |
1798 ->WithLocal(DynamicGlobal("iish"), iw::AsmType::Intish()) | 1820 ->WithLocal(DynamicGlobal("iish"), iw::AsmType::Intish()) |
1799 ->WithGlobal(DynamicGlobal("v2f"), v2f) | 1821 ->WithGlobal(DynamicGlobal("v2f"), v2f) |
| 1822 ->WithGlobal(DynamicGlobal("ifd2f"), nullptr) |
| 1823 ->WithGlobal(DynamicGlobal("ifd2d"), nullptr) |
| 1824 ->WithGlobal(DynamicGlobal("ifd2i"), nullptr) |
1800 ->WithGlobal(DynamicGlobal("ifd2f_tbl"), ifd2f_tbl) | 1825 ->WithGlobal(DynamicGlobal("ifd2f_tbl"), ifd2f_tbl) |
1801 ->WithGlobal(DynamicGlobal("ifd2d_tbl"), ifd2d_tbl) | 1826 ->WithGlobal(DynamicGlobal("ifd2d_tbl"), ifd2d_tbl) |
1802 ->WithGlobal(DynamicGlobal("ifd2i_tbl"), ifd2i_tbl) | 1827 ->WithGlobal(DynamicGlobal("ifd2i_tbl"), ifd2i_tbl) |
1803 ->SucceedsWithExactType(test->load_type)) { | 1828 ->SucceedsWithExactType(test->load_type)) { |
1804 std::cerr << "Test:\n" << test->expression; | 1829 std::cerr << "Test:\n" << test->expression; |
1805 CHECK(false); | 1830 CHECK(false); |
1806 } | 1831 } |
1807 } | 1832 } |
1808 } | 1833 } |
1809 | 1834 |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2051 if (!ValidationOf(Module(kTests[ii])) | 2076 if (!ValidationOf(Module(kTests[ii])) |
2052 ->FailsWithMessage( | 2077 ->FailsWithMessage( |
2053 "Constant in return must be signed, float, or double.")) { | 2078 "Constant in return must be signed, float, or double.")) { |
2054 std::cerr << "Test:\n" << kTests[ii]; | 2079 std::cerr << "Test:\n" << kTests[ii]; |
2055 CHECK(false); | 2080 CHECK(false); |
2056 } | 2081 } |
2057 } | 2082 } |
2058 } | 2083 } |
2059 | 2084 |
2060 } // namespace | 2085 } // namespace |
OLD | NEW |