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 "src/asmjs/asm-typer.h" | 5 #include "src/asmjs/asm-typer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 AsmType* AsmTyper::ValidateModule(FunctionLiteral* fun) { | 560 AsmType* AsmTyper::ValidateModule(FunctionLiteral* fun) { |
561 SourceLayoutTracker source_layout; | 561 SourceLayoutTracker source_layout; |
562 | 562 |
563 DeclarationScope* scope = fun->scope(); | 563 DeclarationScope* scope = fun->scope(); |
564 if (!scope->is_function_scope()) FAIL(fun, "Not at function scope."); | 564 if (!scope->is_function_scope()) FAIL(fun, "Not at function scope."); |
565 if (!ValidAsmIdentifier(fun->name())) | 565 if (!ValidAsmIdentifier(fun->name())) |
566 FAIL(fun, "Invalid asm.js identifier in module name."); | 566 FAIL(fun, "Invalid asm.js identifier in module name."); |
567 module_name_ = fun->name(); | 567 module_name_ = fun->name(); |
568 | 568 |
569 // Allowed parameters: Stdlib, FFI, Mem | 569 // Allowed parameters: Stdlib, FFI, Mem |
570 static const uint32_t MaxModuleParameters = 3; | 570 static const int MaxModuleParameters = 3; |
571 if (scope->num_parameters() > MaxModuleParameters) { | 571 if (scope->num_parameters() > MaxModuleParameters) { |
572 FAIL(fun, "asm.js modules may not have more than three parameters."); | 572 FAIL(fun, "asm.js modules may not have more than three parameters."); |
573 } | 573 } |
574 | 574 |
575 struct { | 575 struct { |
576 StandardMember standard_member; | 576 StandardMember standard_member; |
577 } kModuleParamInfo[3] = { | 577 } kModuleParamInfo[3] = { |
578 {kStdlib}, {kFFI}, {kHeap}, | 578 {kStdlib}, {kFFI}, {kHeap}, |
579 }; | 579 }; |
580 | 580 |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 | 1010 |
1011 auto* target_info_table = target_info->type()->AsFunctionTableType(); | 1011 auto* target_info_table = target_info->type()->AsFunctionTableType(); |
1012 if (target_info_table == nullptr) { | 1012 if (target_info_table == nullptr) { |
1013 FAIL(assign, "Identifier redefined as function pointer table."); | 1013 FAIL(assign, "Identifier redefined as function pointer table."); |
1014 } | 1014 } |
1015 | 1015 |
1016 if (!target_info->missing_definition()) { | 1016 if (!target_info->missing_definition()) { |
1017 FAIL(assign, "Identifier redefined (function table name)."); | 1017 FAIL(assign, "Identifier redefined (function table name)."); |
1018 } | 1018 } |
1019 | 1019 |
1020 if (target_info_table->length() != pointers->length()) { | 1020 if (static_cast<int>(target_info_table->length()) != pointers->length()) { |
1021 FAIL(assign, "Function table size mismatch."); | 1021 FAIL(assign, "Function table size mismatch."); |
1022 } | 1022 } |
1023 | 1023 |
1024 DCHECK(target_info_table->signature()->AsFunctionType()); | 1024 DCHECK(target_info_table->signature()->AsFunctionType()); |
1025 if (!table_element_type->IsA(target_info_table->signature())) { | 1025 if (!table_element_type->IsA(target_info_table->signature())) { |
1026 FAIL(assign, "Function table initializer does not match previous type."); | 1026 FAIL(assign, "Function table initializer does not match previous type."); |
1027 } | 1027 } |
1028 | 1028 |
1029 target_info->MarkDefined(); | 1029 target_info->MarkDefined(); |
1030 DCHECK(target_info->type() != AsmType::None()); | 1030 DCHECK(target_info->type() != AsmType::None()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1064 // Done with parameters. | 1064 // Done with parameters. |
1065 break; | 1065 break; |
1066 } | 1066 } |
1067 auto* proxy = expr->target()->AsVariableProxy(); | 1067 auto* proxy = expr->target()->AsVariableProxy(); |
1068 if (proxy == nullptr) { | 1068 if (proxy == nullptr) { |
1069 // Done with parameters. | 1069 // Done with parameters. |
1070 break; | 1070 break; |
1071 } | 1071 } |
1072 auto* param = proxy->var(); | 1072 auto* param = proxy->var(); |
1073 if (param->location() != VariableLocation::PARAMETER || | 1073 if (param->location() != VariableLocation::PARAMETER || |
1074 param->index() != annotated_parameters) { | 1074 param->index() != static_cast<int>(annotated_parameters)) { |
1075 // Done with parameters. | 1075 // Done with parameters. |
1076 break; | 1076 break; |
1077 } | 1077 } |
1078 | 1078 |
1079 AsmType* type; | 1079 AsmType* type; |
1080 RECURSE(type = ParameterTypeAnnotations(param, expr->value())); | 1080 RECURSE(type = ParameterTypeAnnotations(param, expr->value())); |
1081 DCHECK(type->IsParameterType()); | 1081 DCHECK(type->IsParameterType()); |
1082 auto* param_info = new (zone_) VariableInfo(type); | 1082 auto* param_info = new (zone_) VariableInfo(type); |
1083 param_info->set_mutability(VariableInfo::kLocal); | 1083 param_info->set_mutability(VariableInfo::kLocal); |
1084 if (!ValidAsmIdentifier(proxy->name())) { | 1084 if (!ValidAsmIdentifier(proxy->name())) { |
1085 FAIL(proxy, "Invalid asm.js identifier in parameter name."); | 1085 FAIL(proxy, "Invalid asm.js identifier in parameter name."); |
1086 } | 1086 } |
1087 | 1087 |
1088 if (!AddLocal(param, param_info)) { | 1088 if (!AddLocal(param, param_info)) { |
1089 FAIL(proxy, "Redeclared parameter."); | 1089 FAIL(proxy, "Redeclared parameter."); |
1090 } | 1090 } |
1091 parameter_types.push_back(type); | 1091 parameter_types.push_back(type); |
1092 SetTypeOf(proxy, type); | 1092 SetTypeOf(proxy, type); |
1093 SetTypeOf(expr, type); | 1093 SetTypeOf(expr, type); |
1094 } | 1094 } |
1095 | 1095 |
1096 if (annotated_parameters != fun->parameter_count()) { | 1096 if (static_cast<int>(annotated_parameters) != fun->parameter_count()) { |
1097 FAIL(fun_decl, "Incorrect parameter type annotations."); | 1097 FAIL(fun_decl, "Incorrect parameter type annotations."); |
1098 } | 1098 } |
1099 | 1099 |
1100 // 5.3 Function type annotations | 1100 // 5.3 Function type annotations |
1101 // * locals | 1101 // * locals |
1102 for (; current; current = iter.Next()) { | 1102 for (; current; current = iter.Next()) { |
1103 auto* initializer = ExtractInitializerExpression(current); | 1103 auto* initializer = ExtractInitializerExpression(current); |
1104 if (initializer == nullptr) { | 1104 if (initializer == nullptr) { |
1105 // Done with locals. | 1105 // Done with locals. |
1106 break; | 1106 break; |
(...skipping 1750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2857 return true; | 2857 return true; |
2858 } | 2858 } |
2859 | 2859 |
2860 *error_message = typer.error_message(); | 2860 *error_message = typer.error_message(); |
2861 return false; | 2861 return false; |
2862 } | 2862 } |
2863 | 2863 |
2864 } // namespace wasm | 2864 } // namespace wasm |
2865 } // namespace internal | 2865 } // namespace internal |
2866 } // namespace v8 | 2866 } // namespace v8 |
OLD | NEW |