// Copyright 2014 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_TYPES_INL_H_ #define V8_TYPES_INL_H_ #include "types.h" #include "factory.h" #include "handles-inl.h" namespace v8 { namespace internal { // static Type* ZoneTypeConfig::handle(Type* type) { return type; } // static bool ZoneTypeConfig::is_bitset(Type* type) { return reinterpret_cast(type) & 1; } // static bool ZoneTypeConfig::is_struct(Type* type) { return !is_bitset(type); } // static bool ZoneTypeConfig::is_class(Type* type) { return is_struct(type) && struct_tag(as_struct(type)) == Type::kClassTag; } // static bool ZoneTypeConfig::is_constant(Type* type) { return is_struct(type) && struct_tag(as_struct(type)) == Type::kConstantTag; } // static int ZoneTypeConfig::as_bitset(Type* type) { ASSERT(is_bitset(type)); return static_cast(reinterpret_cast(type) >> 1); } // static ZoneTypeConfig::Struct* ZoneTypeConfig::as_struct(Type* type) { ASSERT(is_struct(type)); return reinterpret_cast(type); } // static i::Handle ZoneTypeConfig::as_class(Type* type) { ASSERT(is_class(type)); return i::Handle(static_cast(as_struct(type)[3])); } // static i::Handle ZoneTypeConfig::as_constant(Type* type) { ASSERT(is_constant(type)); return i::Handle( static_cast(as_struct(type)[3])); } // static ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset) { return reinterpret_cast((bitset << 1) | 1); } // static ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset, Zone* Zone) { return from_bitset(bitset); } // static ZoneTypeConfig::Type* ZoneTypeConfig::from_struct(Struct* structured) { return reinterpret_cast(structured); } // static ZoneTypeConfig::Type* ZoneTypeConfig::from_class( i::Handle map, int lub, Zone* zone) { Struct* structured = struct_create(Type::kClassTag, 2, zone); structured[2] = from_bitset(lub); structured[3] = map.location(); return from_struct(structured); } // static ZoneTypeConfig::Type* ZoneTypeConfig::from_constant( i::Handle value, int lub, Zone* zone) { Struct* structured = struct_create(Type::kConstantTag, 2, zone); structured[2] = from_bitset(lub); structured[3] = value.location(); return from_struct(structured); } // static ZoneTypeConfig::Struct* ZoneTypeConfig::struct_create( int tag, int length, Zone* zone) { Struct* structured = reinterpret_cast( zone->New(sizeof(void*) * (length + 2))); // NOLINT structured[0] = reinterpret_cast(tag); structured[1] = reinterpret_cast(length); return structured; } // static void ZoneTypeConfig::struct_shrink(Struct* structured, int length) { ASSERT(0 <= length && length <= struct_length(structured)); structured[1] = reinterpret_cast(length); } // static int ZoneTypeConfig::struct_tag(Struct* structured) { return static_cast(reinterpret_cast(structured[0])); } // static int ZoneTypeConfig::struct_length(Struct* structured) { return static_cast(reinterpret_cast(structured[1])); } // static Type* ZoneTypeConfig::struct_get(Struct* structured, int i) { ASSERT(0 <= i && i <= struct_length(structured)); return static_cast(structured[2 + i]); } // static void ZoneTypeConfig::struct_set(Struct* structured, int i, Type* type) { ASSERT(0 <= i && i <= struct_length(structured)); structured[2 + i] = type; } // static int ZoneTypeConfig::lub_bitset(Type* type) { ASSERT(is_class(type) || is_constant(type)); return as_bitset(struct_get(as_struct(type), 0)); } // -------------------------------------------------------------------------- // // static i::Handle HeapTypeConfig::handle(Type* type) { return i::handle(type, i::HeapObject::cast(type)->GetIsolate()); } // static bool HeapTypeConfig::is_bitset(Type* type) { return type->IsSmi(); } // static bool HeapTypeConfig::is_class(Type* type) { return type->IsMap(); } // static bool HeapTypeConfig::is_constant(Type* type) { return type->IsBox(); } // static bool HeapTypeConfig::is_struct(Type* type) { return type->IsFixedArray(); } // static int HeapTypeConfig::as_bitset(Type* type) { return Smi::cast(type)->value(); } // static i::Handle HeapTypeConfig::as_class(Type* type) { return i::handle(i::Map::cast(type)); } // static i::Handle HeapTypeConfig::as_constant(Type* type) { i::Box* box = i::Box::cast(type); return i::handle(box->value(), box->GetIsolate()); } // static i::Handle HeapTypeConfig::as_struct(Type* type) { return i::handle(Struct::cast(type)); } // static HeapTypeConfig::Type* HeapTypeConfig::from_bitset(int bitset) { return Type::cast(i::Smi::FromInt(bitset)); } // static i::Handle HeapTypeConfig::from_bitset( int bitset, Isolate* isolate) { return i::handle(from_bitset(bitset), isolate); } // static i::Handle HeapTypeConfig::from_class( i::Handle map, int lub, Isolate* isolate) { return i::Handle::cast(i::Handle::cast(map)); } // static i::Handle HeapTypeConfig::from_constant( i::Handle value, int lub, Isolate* isolate) { i::Handle box = isolate->factory()->NewBox(value); return i::Handle::cast(i::Handle::cast(box)); } // static i::Handle HeapTypeConfig::from_struct( i::Handle structured) { return i::Handle::cast(i::Handle::cast(structured)); } // static i::Handle HeapTypeConfig::struct_create( int tag, int length, Isolate* isolate) { i::Handle structured = isolate->factory()->NewFixedArray(length + 1); structured->set(0, i::Smi::FromInt(tag)); return structured; } // static void HeapTypeConfig::struct_shrink(i::Handle structured, int length) { structured->Shrink(length + 1); } // static int HeapTypeConfig::struct_tag(i::Handle structured) { return static_cast(structured->get(0))->value(); } // static int HeapTypeConfig::struct_length(i::Handle structured) { return structured->length() - 1; } // static i::Handle HeapTypeConfig::struct_get( i::Handle structured, int i) { Type* type = static_cast(structured->get(i + 1)); return i::handle(type, structured->GetIsolate()); } // static void HeapTypeConfig::struct_set( i::Handle structured, int i, i::Handle type) { structured->set(i + 1, *type); } // static int HeapTypeConfig::lub_bitset(Type* type) { return 0; // kNone, which causes recomputation. } } } // namespace v8::internal #endif // V8_TYPES_INL_H_