Commit 7c38cdb2 authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

Make it possible to use HeapType inside objects-inl.h.

R=rossberg@chromium.org

Review URL: https://codereview.chromium.org/220193007

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20390 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 3cbb49f2
// 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 "factory.h"
#include "handles-inl.h"
#include "types.h"
namespace v8 {
namespace internal {
// static
ZoneTypeConfig::Tagged* ZoneTypeConfig::tagged_create(
Tag tag, int size, Zone* zone) {
Tagged* tagged = new(zone) Tagged(size + 1, zone);
tagged->Add(reinterpret_cast<void*>(tag), zone);
tagged->AddBlock(NULL, size, zone);
return tagged;
}
// static
void ZoneTypeConfig::tagged_shrink(Tagged* tagged, int size) {
tagged->Rewind(size + 1);
}
// static
ZoneTypeConfig::Tag ZoneTypeConfig::tagged_tag(Tagged* tagged) {
return static_cast<Tag>(reinterpret_cast<intptr_t>(tagged->at(0)));
}
// static
template<class T>
T ZoneTypeConfig::tagged_get(Tagged* tagged, int i) {
return reinterpret_cast<T>(tagged->at(i + 1));
}
// static
template<class T>
void ZoneTypeConfig::tagged_set(Tagged* tagged, int i, T value) {
tagged->at(i + 1) = reinterpret_cast<void*>(value);
}
// static
int ZoneTypeConfig::tagged_length(Tagged* tagged) {
return tagged->length() - 1;
}
// static
Type* ZoneTypeConfig::handle(Type* type) {
return type;
}
// static
bool ZoneTypeConfig::is(Type* type, Tag tag) {
return is_tagged(type) && tagged_tag(as_tagged(type)) == tag;
}
// static
bool ZoneTypeConfig::is_bitset(Type* type) {
return reinterpret_cast<intptr_t>(type) & 1;
}
// static
bool ZoneTypeConfig::is_tagged(Type* type) {
return !is_bitset(type);
}
// static
bool ZoneTypeConfig::is_class(Type* type) {
return is(type, kClassTag);
}
// static
bool ZoneTypeConfig::is_constant(Type* type) {
return is(type, kConstantTag);
}
// static
bool ZoneTypeConfig::is_union(Type* type) {
return is(type, kUnionTag);
}
// static
bool ZoneTypeConfig::tagged_is_union(Tagged* tagged) {
return is(from_tagged(tagged), kUnionTag);
}
// static
int ZoneTypeConfig::as_bitset(Type* type) {
ASSERT(is_bitset(type));
return static_cast<int>(reinterpret_cast<intptr_t>(type) >> 1);
}
// static
ZoneTypeConfig::Tagged* ZoneTypeConfig::as_tagged(Type* type) {
ASSERT(is_tagged(type));
return reinterpret_cast<Tagged*>(type);
}
// static
i::Handle<i::Map> ZoneTypeConfig::as_class(Type* type) {
ASSERT(is_class(type));
return i::Handle<i::Map>(tagged_get<i::Map**>(as_tagged(type), 1));
}
// static
i::Handle<i::Object> ZoneTypeConfig::as_constant(Type* type) {
ASSERT(is_constant(type));
return i::Handle<i::Object>(tagged_get<i::Object**>(as_tagged(type), 1));
}
// static
ZoneTypeConfig::Unioned* ZoneTypeConfig::as_union(Type* type) {
ASSERT(is_union(type));
return tagged_as_union(as_tagged(type));
}
// static
ZoneTypeConfig::Unioned* ZoneTypeConfig::tagged_as_union(Tagged* tagged) {
ASSERT(tagged_is_union(tagged));
return reinterpret_cast<Unioned*>(tagged);
}
// static
ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset) {
return reinterpret_cast<Type*>((bitset << 1) | 1);
}
// static
ZoneTypeConfig::Type* ZoneTypeConfig::from_bitset(int bitset, Zone* Zone) {
return from_bitset(bitset);
}
// static
ZoneTypeConfig::Type* ZoneTypeConfig::from_tagged(Tagged* tagged) {
return reinterpret_cast<Type*>(tagged);
}
// static
ZoneTypeConfig::Type* ZoneTypeConfig::from_class(
i::Handle<i::Map> map, int lub, Zone* zone) {
Tagged* tagged = tagged_create(kClassTag, 2, zone);
tagged_set(tagged, 0, lub);
tagged_set(tagged, 1, map.location());
return from_tagged(tagged);
}
// static
ZoneTypeConfig::Type* ZoneTypeConfig::from_constant(
i::Handle<i::Object> value, int lub, Zone* zone) {
Tagged* tagged = tagged_create(kConstantTag, 2, zone);
tagged_set(tagged, 0, lub);
tagged_set(tagged, 1, value.location());
return from_tagged(tagged);
}
// static
ZoneTypeConfig::Type* ZoneTypeConfig::from_union(Unioned* unioned) {
return from_tagged(tagged_from_union(unioned));
}
// static
ZoneTypeConfig::Tagged* ZoneTypeConfig::tagged_from_union(Unioned* unioned) {
return reinterpret_cast<Tagged*>(unioned);
}
// static
ZoneTypeConfig::Unioned* ZoneTypeConfig::union_create(int size, Zone* zone) {
return tagged_as_union(tagged_create(kUnionTag, size, zone));
}
// static
void ZoneTypeConfig::union_shrink(Unioned* unioned, int size) {
tagged_shrink(tagged_from_union(unioned), size);
}
// static
ZoneTypeConfig::Type* ZoneTypeConfig::union_get(Unioned* unioned, int i) {
Type* type = tagged_get<Type*>(tagged_from_union(unioned), i);
ASSERT(!is_union(type));
return type;
}
// static
void ZoneTypeConfig::union_set(Unioned* unioned, int i, Type* type) {
ASSERT(!is_union(type));
tagged_set(tagged_from_union(unioned), i, type);
}
// static
int ZoneTypeConfig::union_length(Unioned* unioned) {
return tagged_length(tagged_from_union(unioned));
}
// static
int ZoneTypeConfig::lub_bitset(Type* type) {
ASSERT(is_class(type) || is_constant(type));
return static_cast<int>(tagged_get<intptr_t>(as_tagged(type), 0));
}
// static
i::Handle<HeapTypeConfig::Type> 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_union(Type* type) {
return type->IsFixedArray();
}
// static
int HeapTypeConfig::as_bitset(Type* type) {
return Smi::cast(type)->value();
}
// static
i::Handle<i::Map> HeapTypeConfig::as_class(Type* type) {
return i::handle(i::Map::cast(type));
}
// static
i::Handle<i::Object> HeapTypeConfig::as_constant(Type* type) {
i::Box* box = i::Box::cast(type);
return i::handle(box->value(), box->GetIsolate());
}
// static
i::Handle<HeapTypeConfig::Unioned> HeapTypeConfig::as_union(Type* type) {
return i::handle(i::FixedArray::cast(type));
}
// static
HeapTypeConfig::Type* HeapTypeConfig::from_bitset(int bitset) {
return Type::cast(i::Smi::FromInt(bitset));
}
// static
i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_bitset(
int bitset, Isolate* isolate) {
return i::handle(from_bitset(bitset), isolate);
}
// static
i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_class(
i::Handle<i::Map> map, int lub, Isolate* isolate) {
return i::Handle<Type>::cast(i::Handle<Object>::cast(map));
}
// static
i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_constant(
i::Handle<i::Object> value, int lub, Isolate* isolate) {
i::Handle<Box> box = isolate->factory()->NewBox(value);
return i::Handle<Type>::cast(i::Handle<Object>::cast(box));
}
// static
i::Handle<HeapTypeConfig::Type> HeapTypeConfig::from_union(
i::Handle<Unioned> unioned) {
return i::Handle<Type>::cast(i::Handle<Object>::cast(unioned));
}
// static
i::Handle<HeapTypeConfig::Unioned> HeapTypeConfig::union_create(
int size, Isolate* isolate) {
return isolate->factory()->NewFixedArray(size);
}
// static
void HeapTypeConfig::union_shrink(i::Handle<Unioned> unioned, int size) {
unioned->Shrink(size);
}
// static
i::Handle<HeapTypeConfig::Type> HeapTypeConfig::union_get(
i::Handle<Unioned> unioned, int i) {
Type* type = static_cast<Type*>(unioned->get(i));
ASSERT(!is_union(type));
return i::handle(type, unioned->GetIsolate());
}
// static
void HeapTypeConfig::union_set(
i::Handle<Unioned> unioned, int i, i::Handle<Type> type) {
ASSERT(!is_union(*type));
unioned->set(i, *type);
}
// static
int HeapTypeConfig::union_length(i::Handle<Unioned> unioned) {
return unioned->length();
}
// static
int HeapTypeConfig::lub_bitset(Type* type) {
return 0; // kNone, which causes recomputation.
}
} } // namespace v8::internal
#endif // V8_TYPES_INL_H_
// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// 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.
#include "types.h"
#include "string-stream.h"
#include "types-inl.h"
namespace v8 {
namespace internal {
......@@ -690,5 +669,4 @@ template TypeImpl<HeapTypeConfig>::TypeHandle
TypeImpl<HeapTypeConfig>::Convert<Type>(
TypeImpl<ZoneTypeConfig>::TypeHandle, TypeImpl<HeapTypeConfig>::Region*);
} } // namespace v8::internal
This diff is collapsed.
......@@ -66,6 +66,7 @@
#include "mark-compact-inl.h"
#include "log-inl.h"
#include "handles-inl.h"
#include "types-inl.h"
#include "zone-inl.h"
namespace v8 {
......@@ -135,6 +136,4 @@ enum NilValue { kNullValue, kUndefinedValue };
} } // namespace v8::internal
namespace i = v8::internal;
#endif // V8_V8_H_
......@@ -565,4 +565,6 @@ enum MinusZeroMode {
} } // namespace v8::internal
namespace i = v8::internal;
#endif // V8_V8GLOBALS_H_
......@@ -569,6 +569,7 @@
'../../src/transitions.h',
'../../src/type-info.cc',
'../../src/type-info.h',
'../../src/types-inl.h',
'../../src/types.cc',
'../../src/types.h',
'../../src/typing.cc',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment