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