OLD | NEW |
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 #include "src/typing-asm.h" | 7 #include "src/typing-asm.h" |
8 | 8 |
9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
10 #include "src/ast/scopes.h" | 10 #include "src/ast/scopes.h" |
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 | 769 |
770 | 770 |
771 bool AsmTyper::IsStdlibObject(Expression* expr) { | 771 bool AsmTyper::IsStdlibObject(Expression* expr) { |
772 VariableProxy* proxy = expr->AsVariableProxy(); | 772 VariableProxy* proxy = expr->AsVariableProxy(); |
773 if (proxy == NULL) { | 773 if (proxy == NULL) { |
774 return false; | 774 return false; |
775 } | 775 } |
776 Variable* var = proxy->var(); | 776 Variable* var = proxy->var(); |
777 VariableInfo* info = GetVariableInfo(var, false); | 777 VariableInfo* info = GetVariableInfo(var, false); |
778 if (info) { | 778 if (info) { |
779 if (info->is_stdlib_object) return info->is_stdlib_object; | 779 if (info->standard_object == kStdlib) return true; |
780 } | 780 } |
781 if (var->location() != VariableLocation::PARAMETER || var->index() != 0) { | 781 if (var->location() != VariableLocation::PARAMETER || var->index() != 0) { |
782 return false; | 782 return false; |
783 } | 783 } |
784 info = GetVariableInfo(var, true); | 784 info = GetVariableInfo(var, true); |
785 info->type = Type::Object(); | 785 info->type = Type::Object(); |
786 info->is_stdlib_object = true; | 786 info->standard_object = kStdlib; |
787 return true; | 787 return true; |
788 } | 788 } |
789 | 789 |
790 | 790 |
791 Expression* AsmTyper::GetReceiverOfPropertyAccess(Expression* expr, | 791 Expression* AsmTyper::GetReceiverOfPropertyAccess(Expression* expr, |
792 const char* name) { | 792 const char* name) { |
793 Property* property = expr->AsProperty(); | 793 Property* property = expr->AsProperty(); |
794 if (property == NULL) { | 794 if (property == NULL) { |
795 return NULL; | 795 return NULL; |
796 } | 796 } |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 | 1227 |
1228 Type* fround_type = Type::Function(cache_.kAsmFloat, number_type, zone()); | 1228 Type* fround_type = Type::Function(cache_.kAsmFloat, number_type, zone()); |
1229 Type* imul_type = | 1229 Type* imul_type = |
1230 Type::Function(cache_.kAsmSigned, cache_.kAsmInt, cache_.kAsmInt, zone()); | 1230 Type::Function(cache_.kAsmSigned, cache_.kAsmInt, cache_.kAsmInt, zone()); |
1231 // TODO(bradnelson): currently only approximating the proper intersection type | 1231 // TODO(bradnelson): currently only approximating the proper intersection type |
1232 // (which we cannot currently represent). | 1232 // (which we cannot currently represent). |
1233 Type* abs_type = Type::Function(number_type, number_type, zone()); | 1233 Type* abs_type = Type::Function(number_type, number_type, zone()); |
1234 | 1234 |
1235 struct Assignment { | 1235 struct Assignment { |
1236 const char* name; | 1236 const char* name; |
| 1237 StandardObject standard_object; |
1237 Type* type; | 1238 Type* type; |
1238 }; | 1239 }; |
1239 | 1240 |
1240 const Assignment math[] = { | 1241 const Assignment math[] = {{"PI", kMathPI, double_type}, |
1241 {"PI", double_type}, {"E", double_type}, | 1242 {"E", kMathE, double_type}, |
1242 {"LN2", double_type}, {"LN10", double_type}, | 1243 {"LN2", kMathLN2, double_type}, |
1243 {"LOG2E", double_type}, {"LOG10E", double_type}, | 1244 {"LN10", kMathLN10, double_type}, |
1244 {"SQRT2", double_type}, {"SQRT1_2", double_type}, | 1245 {"LOG2E", kMathLOG2E, double_type}, |
1245 {"imul", imul_type}, {"abs", abs_type}, | 1246 {"LOG10E", kMathLOG10E, double_type}, |
1246 {"ceil", double_fn1_type}, {"floor", double_fn1_type}, | 1247 {"SQRT2", kMathSQRT2, double_type}, |
1247 {"fround", fround_type}, {"pow", double_fn2_type}, | 1248 {"SQRT1_2", kMathSQRT1_2, double_type}, |
1248 {"exp", double_fn1_type}, {"log", double_fn1_type}, | 1249 {"imul", kMathImul, imul_type}, |
1249 {"min", double_fn2_type}, {"max", double_fn2_type}, | 1250 {"abs", kMathAbs, abs_type}, |
1250 {"sqrt", double_fn1_type}, {"cos", double_fn1_type}, | 1251 {"ceil", kMathCeil, double_fn1_type}, |
1251 {"sin", double_fn1_type}, {"tan", double_fn1_type}, | 1252 {"floor", kMathFloor, double_fn1_type}, |
1252 {"acos", double_fn1_type}, {"asin", double_fn1_type}, | 1253 {"fround", kMathFround, fround_type}, |
1253 {"atan", double_fn1_type}, {"atan2", double_fn2_type}}; | 1254 {"pow", kMathPow, double_fn2_type}, |
| 1255 {"exp", kMathExp, double_fn1_type}, |
| 1256 {"log", kMathLog, double_fn1_type}, |
| 1257 {"min", kMathMin, double_fn2_type}, |
| 1258 {"max", kMathMax, double_fn2_type}, |
| 1259 {"sqrt", kMathSqrt, double_fn1_type}, |
| 1260 {"cos", kMathCos, double_fn1_type}, |
| 1261 {"sin", kMathSin, double_fn1_type}, |
| 1262 {"tan", kMathTan, double_fn1_type}, |
| 1263 {"acos", kMathAcos, double_fn1_type}, |
| 1264 {"asin", kMathAsin, double_fn1_type}, |
| 1265 {"atan", kMathAtan, double_fn1_type}, |
| 1266 {"atan2", kMathAtan2, double_fn2_type}}; |
1254 for (unsigned i = 0; i < arraysize(math); ++i) { | 1267 for (unsigned i = 0; i < arraysize(math); ++i) { |
1255 stdlib_math_types_[math[i].name] = new (zone()) VariableInfo(math[i].type); | 1268 stdlib_math_types_[math[i].name] = new (zone()) VariableInfo(math[i].type); |
| 1269 stdlib_math_types_[math[i].name]->standard_object = math[i].standard_object; |
1256 } | 1270 } |
1257 stdlib_math_types_["fround"]->is_check_function = true; | 1271 stdlib_math_types_["fround"]->is_check_function = true; |
1258 | 1272 |
1259 stdlib_types_["Infinity"] = new (zone()) VariableInfo(double_type); | 1273 stdlib_types_["Infinity"] = new (zone()) VariableInfo(double_type); |
| 1274 stdlib_types_["Infinity"]->standard_object = kInfinity; |
1260 stdlib_types_["NaN"] = new (zone()) VariableInfo(double_type); | 1275 stdlib_types_["NaN"] = new (zone()) VariableInfo(double_type); |
| 1276 stdlib_types_["NaN"]->standard_object = kNaN; |
1261 Type* buffer_type = Type::Any(zone()); | 1277 Type* buffer_type = Type::Any(zone()); |
1262 #define TYPED_ARRAY(TypeName, type_name, TYPE_NAME, ctype, size) \ | 1278 #define TYPED_ARRAY(TypeName, type_name, TYPE_NAME, ctype, size) \ |
1263 stdlib_types_[#TypeName "Array"] = new (zone()) VariableInfo( \ | 1279 stdlib_types_[#TypeName "Array"] = new (zone()) VariableInfo( \ |
1264 Type::Function(cache_.k##TypeName##Array, buffer_type, zone())); | 1280 Type::Function(cache_.k##TypeName##Array, buffer_type, zone())); |
1265 TYPED_ARRAYS(TYPED_ARRAY) | 1281 TYPED_ARRAYS(TYPED_ARRAY) |
1266 #undef TYPED_ARRAY | 1282 #undef TYPED_ARRAY |
1267 | 1283 |
1268 #define TYPED_ARRAY(TypeName, type_name, TYPE_NAME, ctype, size) \ | 1284 #define TYPED_ARRAY(TypeName, type_name, TYPE_NAME, ctype, size) \ |
1269 stdlib_heap_types_[#TypeName "Array"] = new (zone()) VariableInfo( \ | 1285 stdlib_heap_types_[#TypeName "Array"] = new (zone()) VariableInfo( \ |
1270 Type::Function(cache_.k##TypeName##Array, buffer_type, zone())); | 1286 Type::Function(cache_.k##TypeName##Array, buffer_type, zone())); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 if (!setting) return NULL; | 1349 if (!setting) return NULL; |
1334 entry->value = new (zone()) VariableInfo; | 1350 entry->value = new (zone()) VariableInfo; |
1335 } | 1351 } |
1336 return reinterpret_cast<VariableInfo*>(entry->value); | 1352 return reinterpret_cast<VariableInfo*>(entry->value); |
1337 } | 1353 } |
1338 | 1354 |
1339 | 1355 |
1340 void AsmTyper::SetVariableInfo(Variable* variable, const VariableInfo* info) { | 1356 void AsmTyper::SetVariableInfo(Variable* variable, const VariableInfo* info) { |
1341 VariableInfo* dest = GetVariableInfo(variable, true); | 1357 VariableInfo* dest = GetVariableInfo(variable, true); |
1342 dest->type = info->type; | 1358 dest->type = info->type; |
1343 dest->is_stdlib_object = info->is_stdlib_object; | |
1344 dest->is_check_function = info->is_check_function; | 1359 dest->is_check_function = info->is_check_function; |
1345 dest->is_constructor_function = info->is_constructor_function; | 1360 dest->is_constructor_function = info->is_constructor_function; |
| 1361 dest->standard_object = info->standard_object; |
1346 } | 1362 } |
1347 | 1363 |
1348 | 1364 |
| 1365 AsmTyper::StandardObject AsmTyper::VariableAsStandardObject( |
| 1366 Variable* variable) { |
| 1367 VariableInfo* info = GetVariableInfo(variable, false); |
| 1368 if (!info) return kNone; |
| 1369 return info->standard_object; |
| 1370 } |
| 1371 |
| 1372 |
1349 void AsmTyper::SetResult(Expression* expr, Type* type) { | 1373 void AsmTyper::SetResult(Expression* expr, Type* type) { |
1350 computed_type_ = type; | 1374 computed_type_ = type; |
1351 expr->set_bounds(Bounds(computed_type_)); | 1375 expr->set_bounds(Bounds(computed_type_)); |
1352 } | 1376 } |
1353 | 1377 |
1354 | 1378 |
1355 void AsmTyper::IntersectResult(Expression* expr, Type* type) { | 1379 void AsmTyper::IntersectResult(Expression* expr, Type* type) { |
1356 computed_type_ = type; | 1380 computed_type_ = type; |
1357 Type* bounded_type = Type::Intersect(computed_type_, expected_type_, zone()); | 1381 Type* bounded_type = Type::Intersect(computed_type_, expected_type_, zone()); |
1358 expr->set_bounds(Bounds(bounded_type)); | 1382 expr->set_bounds(Bounds(bounded_type)); |
(...skipping 20 matching lines...) Expand all Loading... |
1379 | 1403 |
1380 | 1404 |
1381 void AsmTyper::VisitRewritableAssignmentExpression( | 1405 void AsmTyper::VisitRewritableAssignmentExpression( |
1382 RewritableAssignmentExpression* expr) { | 1406 RewritableAssignmentExpression* expr) { |
1383 RECURSE(Visit(expr->expression())); | 1407 RECURSE(Visit(expr->expression())); |
1384 } | 1408 } |
1385 | 1409 |
1386 | 1410 |
1387 } // namespace internal | 1411 } // namespace internal |
1388 } // namespace v8 | 1412 } // namespace v8 |
OLD | NEW |