Index: src/typing-asm.cc |
diff --git a/src/typing-asm.cc b/src/typing-asm.cc |
index da752418a63ba63e53b3c9e781c86817be7d60f0..a146258ab482a88e2e5f343067c375d958cde872 100644 |
--- a/src/typing-asm.cc |
+++ b/src/typing-asm.cc |
@@ -41,12 +41,17 @@ AsmTyper::AsmTyper(Isolate* isolate, Zone* zone, Script* script, |
script_(script), |
root_(root), |
valid_(true), |
+ allow_simd_(false), |
stdlib_types_(zone), |
stdlib_heap_types_(zone), |
stdlib_math_types_(zone), |
- global_variable_type_(HashMap::PointersMatch, |
- ZoneHashMap::kDefaultHashMapCapacity, |
- ZoneAllocationPolicy(zone)), |
+#define V(NAME, Name, name, lane_count, lane_type) \ |
+ stdlib_simd_##name##_types_(zone), |
+ SIMD128_TYPES(V) |
+#undef V |
+ global_variable_type_(HashMap::PointersMatch, |
+ ZoneHashMap::kDefaultHashMapCapacity, |
+ ZoneAllocationPolicy(zone)), |
local_variable_type_(HashMap::PointersMatch, |
ZoneHashMap::kDefaultHashMapCapacity, |
ZoneAllocationPolicy(zone)), |
@@ -688,35 +693,94 @@ void AsmTyper::VisitHeapAccess(Property* expr) { |
} |
+bool AsmTyper::IsStdlibObject(Expression* expr) { |
+ VariableProxy* proxy = expr->AsVariableProxy(); |
+ if (proxy == NULL) { |
+ return false; |
+ } |
+ Variable* var = proxy->var(); |
+ if (var->location() != VariableLocation::PARAMETER || var->index() != 0) { |
+ return false; |
+ } |
+ return true; |
+} |
+ |
+ |
+bool AsmTyper::IsMathObject(Expression* expr) { |
+ Property* property = expr->AsProperty(); |
+ if (property == NULL) { |
+ return false; |
+ } |
+ if (!IsStdlibObject(property->obj())) { |
+ return false; |
+ } |
+ Literal* key = property->key()->AsLiteral(); |
+ if (key == NULL || !key->IsPropertyName() || |
titzer
2015/11/24 19:38:02
Maybe we can factor out the Literal+IsPropertyName
bradn
2015/11/25 04:05:40
Done.
|
+ !key->AsPropertyName()->IsUtf8EqualTo(CStrVector("Math"))) { |
+ return false; |
+ } |
+ return true; |
+} |
+ |
+ |
+bool AsmTyper::IsSIMDObject(Expression* expr) { |
+ Property* property = expr->AsProperty(); |
+ if (property == NULL) { |
+ return false; |
+ } |
+ if (!IsStdlibObject(property->obj())) { |
+ return false; |
+ } |
+ Literal* key = property->key()->AsLiteral(); |
+ if (key == NULL || !key->IsPropertyName() || |
+ !key->AsPropertyName()->IsUtf8EqualTo(CStrVector("SIMD"))) { |
+ return false; |
+ } |
+ return true; |
+} |
+ |
+ |
+bool AsmTyper::IsSIMDTypeObject(Expression* expr, const char* name) { |
+ Property* property = expr->AsProperty(); |
+ if (property == NULL) { |
+ return false; |
+ } |
+ if (!IsSIMDObject(property->obj())) { |
+ return false; |
+ } |
+ Literal* key = property->key()->AsLiteral(); |
+ if (key == NULL || !key->IsPropertyName() || |
+ !key->AsPropertyName()->IsUtf8EqualTo(CStrVector(name))) { |
+ return false; |
+ } |
+ return true; |
+} |
+ |
+ |
void AsmTyper::VisitProperty(Property* expr) { |
- // stdlib.Math.x |
- Property* inner_prop = expr->obj()->AsProperty(); |
- if (inner_prop != NULL) { |
- // Get property name. |
+ if (IsMathObject(expr->obj())) { |
Literal* key = expr->key()->AsLiteral(); |
if (key == NULL || !key->IsPropertyName()) |
- FAIL(expr, "invalid type annotation on property 2"); |
+ FAIL(expr, "invalid key used on Math object"); |
Handle<String> name = key->AsPropertyName(); |
- |
- // Check that inner property name is "Math". |
- Literal* math_key = inner_prop->key()->AsLiteral(); |
- if (math_key == NULL || !math_key->IsPropertyName() || |
- !math_key->AsPropertyName()->IsUtf8EqualTo(CStrVector("Math"))) |
- FAIL(expr, "invalid type annotation on stdlib (a1)"); |
- |
- // Check that object is stdlib. |
- VariableProxy* proxy = inner_prop->obj()->AsVariableProxy(); |
- if (proxy == NULL) FAIL(expr, "invalid type annotation on stdlib (a2)"); |
- Variable* var = proxy->var(); |
- if (var->location() != VariableLocation::PARAMETER || var->index() != 0) |
- FAIL(expr, "invalid type annotation on stdlib (a3)"); |
- |
- // Look up library type. |
Type* type = LibType(stdlib_math_types_, name); |
- if (type == NULL) FAIL(expr, "unknown standard function 3 "); |
+ if (type == NULL) FAIL(expr, "unknown Math function"); |
SetResult(expr, type); |
return; |
} |
+#define V(NAME, Name, name, lane_count, lane_type) \ |
+ if (IsSIMDTypeObject(expr->obj(), #name)) { \ |
+ Literal* key = expr->key()->AsLiteral(); \ |
+ if (key == NULL || !key->IsPropertyName()) \ |
+ FAIL(expr, "invalid key used on SIMD type object"); \ |
+ Handle<String> kname = key->AsPropertyName(); \ |
+ Type* type = LibType(stdlib_simd_##name##_types_, kname); \ |
+ if (type == NULL) FAIL(expr, "unknown Math function"); \ |
+ SetResult(expr, type); \ |
+ return; \ |
+ } |
+ SIMD128_TYPES(V) |
+#undef V |
// Only recurse at this point so that we avoid needing |
// stdlib.Math to have a real type. |