1 // Copyright 2014 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "src/crankshaft/hydrogen-types.h" 6 7 #include "src/field-type.h" 8 #include "src/handles-inl.h" 9 #include "src/ostreams.h" 10 11 namespace v8 { 12 namespace internal { 13 14 // static FromType(AstType * type)15HType HType::FromType(AstType* type) { 16 if (AstType::Any()->Is(type)) return HType::Any(); 17 if (!type->IsInhabited()) return HType::None(); 18 if (type->Is(AstType::SignedSmall())) return HType::Smi(); 19 if (type->Is(AstType::Number())) return HType::TaggedNumber(); 20 if (type->Is(AstType::Null())) return HType::Null(); 21 if (type->Is(AstType::String())) return HType::String(); 22 if (type->Is(AstType::Boolean())) return HType::Boolean(); 23 if (type->Is(AstType::Undefined())) return HType::Undefined(); 24 if (type->Is(AstType::Object())) return HType::JSObject(); 25 if (type->Is(AstType::DetectableReceiver())) return HType::JSReceiver(); 26 return HType::Tagged(); 27 } 28 29 30 // static FromFieldType(Handle<FieldType> type,Zone * temp_zone)31HType HType::FromFieldType(Handle<FieldType> type, Zone* temp_zone) { 32 return FromType(type->Convert(temp_zone)); 33 } 34 35 // static FromValue(Handle<Object> value)36HType HType::FromValue(Handle<Object> value) { 37 Object* raw_value = *value; 38 if (raw_value->IsSmi()) return HType::Smi(); 39 DCHECK(raw_value->IsHeapObject()); 40 Isolate* isolate = HeapObject::cast(*value)->GetIsolate(); 41 if (raw_value->IsNull(isolate)) return HType::Null(); 42 if (raw_value->IsHeapNumber()) { 43 double n = Handle<v8::internal::HeapNumber>::cast(value)->value(); 44 return IsSmiDouble(n) ? HType::Smi() : HType::HeapNumber(); 45 } 46 if (raw_value->IsString()) return HType::String(); 47 if (raw_value->IsBoolean()) return HType::Boolean(); 48 if (raw_value->IsUndefined(isolate)) return HType::Undefined(); 49 if (raw_value->IsJSArray()) { 50 DCHECK(!raw_value->IsUndetectable()); 51 return HType::JSArray(); 52 } 53 if (raw_value->IsJSObject() && !raw_value->IsUndetectable()) { 54 return HType::JSObject(); 55 } 56 return HType::HeapObject(); 57 } 58 59 operator <<(std::ostream & os,const HType & t)60std::ostream& operator<<(std::ostream& os, const HType& t) { 61 // Note: The c1visualizer syntax for locals allows only a sequence of the 62 // following characters: A-Za-z0-9_-|: 63 switch (t.kind_) { 64 #define DEFINE_CASE(Name, mask) \ 65 case HType::k##Name: \ 66 return os << #Name; 67 HTYPE_LIST(DEFINE_CASE) 68 #undef DEFINE_CASE 69 } 70 UNREACHABLE(); 71 return os; 72 } 73 74 } // namespace internal 75 } // namespace v8 76