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