Upstream version 11.40.271.0
[platform/framework/web/crosswalk.git] / src / v8 / src / hydrogen-types.cc
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/hydrogen-types.h"
6
7 #include "src/ostreams.h"
8 #include "src/property-details.h"
9 #include "src/types-inl.h"
10
11
12 namespace v8 {
13 namespace internal {
14
15 // static
16 template <class T>
17 HType HType::FromType(typename T::TypeHandle type) {
18   if (T::Any()->Is(type)) return HType::Any();
19   if (type->Is(T::None())) return HType::None();
20   if (type->Is(T::SignedSmall())) return HType::Smi();
21   if (type->Is(T::Number())) return HType::TaggedNumber();
22   if (type->Is(T::Null())) return HType::Null();
23   if (type->Is(T::String())) return HType::String();
24   if (type->Is(T::Boolean())) return HType::Boolean();
25   if (type->Is(T::Undefined())) return HType::Undefined();
26   if (type->Is(T::Array())) return HType::JSArray();
27   if (type->Is(T::Object())) return HType::JSObject();
28   return HType::Tagged();
29 }
30
31
32 // static
33 template
34 HType HType::FromType<Type>(Type* type);
35
36
37 // static
38 template
39 HType HType::FromType<HeapType>(Handle<HeapType> type);
40
41
42 // static
43 HType HType::FromValue(Handle<Object> value) {
44   if (value->IsSmi()) return HType::Smi();
45   if (value->IsNull()) return HType::Null();
46   if (value->IsHeapNumber()) {
47     double n = Handle<v8::internal::HeapNumber>::cast(value)->value();
48     return IsSmiDouble(n) ? HType::Smi() : HType::HeapNumber();
49   }
50   if (value->IsFloat32x4()) return HType::Float32x4();
51   if (value->IsFloat64x2()) return HType::Float64x2();
52   if (value->IsInt32x4()) return HType::Int32x4();
53   if (value->IsString()) return HType::String();
54   if (value->IsBoolean()) return HType::Boolean();
55   if (value->IsUndefined()) return HType::Undefined();
56   if (value->IsJSArray()) return HType::JSArray();
57   if (value->IsJSObject()) return HType::JSObject();
58   DCHECK(value->IsHeapObject());
59   return HType::HeapObject();
60 }
61
62
63 // static
64 HType HType::FromRepresentation(Representation representation) {
65   HType result = HType::Tagged();
66   if (representation.IsSmi()) {
67     result = HType::Smi();
68   } else if (representation.IsDouble()) {
69     result = HType::HeapNumber();
70   } else if (representation.IsFloat32x4()) {
71     result = HType::Float32x4();
72   } else if (representation.IsFloat64x2()) {
73     result = HType::Float64x2();
74   } else if (representation.IsInt32x4()) {
75     result = HType::Int32x4();
76   }
77   return result;
78 }
79
80
81 std::ostream& operator<<(std::ostream& os, const HType& t) {
82   // Note: The c1visualizer syntax for locals allows only a sequence of the
83   // following characters: A-Za-z0-9_-|:
84   switch (t.kind_) {
85 #define DEFINE_CASE(Name, mask) \
86   case HType::k##Name:          \
87     return os << #Name;
88     HTYPE_LIST(DEFINE_CASE)
89 #undef DEFINE_CASE
90   }
91   UNREACHABLE();
92   return os;
93 }
94
95 } }  // namespace v8::internal