Commit 97a6c014 authored by Dan Elphick's avatar Dan Elphick Committed by V8 LUCI CQ

[build] Move ObjectType out of code-assembler.h

To avoid external-reference.cc having to depend on code-assembler.h,
this moves ObjectType and CheckObjectType into a separate
objects/object-type.h/.cc.

Bug: v8:11879
Change-Id: Ia086b37f72c330eefef2ce4d35cdf31d2a0ebe62
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3009220
Commit-Queue: Dan Elphick <delphick@chromium.org>
Reviewed-by: 's avatarGeorg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75599}
parent ffb08a68
......@@ -1392,6 +1392,8 @@ filegroup(
"src/objects/object-list-macros.h",
"src/objects/object-macros-undef.h",
"src/objects/object-macros.h",
"src/objects/object-type.cc",
"src/objects/object-type.h",
"src/objects/objects-body-descriptors-inl.h",
"src/objects/objects-body-descriptors.h",
"src/objects/objects-inl.h",
......
......@@ -2930,6 +2930,7 @@ v8_header_set("v8_internal_headers") {
"src/objects/object-list-macros.h",
"src/objects/object-macros-undef.h",
"src/objects/object-macros.h",
"src/objects/object-type.h",
"src/objects/objects-body-descriptors-inl.h",
"src/objects/objects-body-descriptors.h",
"src/objects/objects-inl.h",
......@@ -3945,6 +3946,7 @@ v8_source_set("v8_base_without_compiler") {
"src/objects/map-updater.cc",
"src/objects/map.cc",
"src/objects/module.cc",
"src/objects/object-type.cc",
"src/objects/objects.cc",
"src/objects/ordered-hash-table.cc",
"src/objects/osr-optimized-code-cache.cc",
......
......@@ -7,7 +7,6 @@
#include "src/api/api.h"
#include "src/base/ieee754.h"
#include "src/codegen/cpu-features.h"
#include "src/compiler/code-assembler.h"
#include "src/date/date.h"
#include "src/debug/debug.h"
#include "src/deoptimizer/deoptimizer.h"
......@@ -23,6 +22,7 @@
#include "src/numbers/hash-seed-inl.h"
#include "src/numbers/math-random.h"
#include "src/objects/elements.h"
#include "src/objects/object-type.h"
#include "src/objects/objects-inl.h"
#include "src/objects/ordered-hash-table.h"
#include "src/regexp/experimental/experimental.h"
......
......@@ -20,8 +20,10 @@
#include "src/compiler/raw-machine-assembler.h"
#include "src/compiler/schedule.h"
#include "src/execution/frames.h"
#include "src/handles/handles-inl.h"
#include "src/heap/factory-inl.h"
#include "src/interpreter/bytecodes.h"
#include "src/objects/objects-inl.h"
#include "src/numbers/conversions-inl.h"
#include "src/objects/smi.h"
#include "src/utils/memcopy.h"
#include "src/zone/zone.h"
......@@ -1745,45 +1747,5 @@ ScopedExceptionHandler::~ScopedExceptionHandler() {
} // namespace compiler
Address CheckObjectType(Address raw_value, Address raw_type,
Address raw_location) {
#ifdef DEBUG
Object value(raw_value);
Smi type(raw_type);
String location = String::cast(Object(raw_location));
const char* expected;
switch (static_cast<ObjectType>(type.value())) {
#define TYPE_CASE(Name) \
case ObjectType::k##Name: \
if (value.Is##Name()) return Smi::FromInt(0).ptr(); \
expected = #Name; \
break;
#define TYPE_STRUCT_CASE(NAME, Name, name) \
case ObjectType::k##Name: \
if (value.Is##Name()) return Smi::FromInt(0).ptr(); \
expected = #Name; \
break;
TYPE_CASE(Object)
TYPE_CASE(Smi)
TYPE_CASE(TaggedIndex)
TYPE_CASE(HeapObject)
OBJECT_TYPE_LIST(TYPE_CASE)
HEAP_OBJECT_TYPE_LIST(TYPE_CASE)
STRUCT_LIST(TYPE_STRUCT_CASE)
#undef TYPE_CASE
#undef TYPE_STRUCT_CASE
}
std::stringstream value_description;
value.Print(value_description);
FATAL(
"Type cast failed in %s\n"
" Expected %s but found %s",
location.ToAsciiArray(), expected, value_description.str().c_str());
#else
UNREACHABLE();
#endif
}
} // namespace internal
} // namespace v8
......@@ -30,6 +30,7 @@
#include "src/objects/js-proxy.h"
#include "src/objects/map.h"
#include "src/objects/maybe-object.h"
#include "src/objects/object-type.h"
#include "src/objects/objects.h"
#include "src/objects/oddball.h"
#include "src/objects/smi.h"
......@@ -86,20 +87,6 @@ TORQUE_DEFINED_CLASS_LIST(MAKE_FORWARD_DECLARATION)
template <typename T>
class Signature;
#define ENUM_ELEMENT(Name) k##Name,
#define ENUM_STRUCT_ELEMENT(NAME, Name, name) k##Name,
enum class ObjectType {
ENUM_ELEMENT(Object) //
ENUM_ELEMENT(Smi) //
ENUM_ELEMENT(TaggedIndex) //
ENUM_ELEMENT(HeapObject) //
OBJECT_TYPE_LIST(ENUM_ELEMENT) //
HEAP_OBJECT_TYPE_LIST(ENUM_ELEMENT) //
STRUCT_LIST(ENUM_STRUCT_ELEMENT) //
};
#undef ENUM_ELEMENT
#undef ENUM_STRUCT_ELEMENT
enum class CheckBounds { kAlways, kDebugOnly };
inline bool NeedsBoundsCheck(CheckBounds check_bounds) {
switch (check_bounds) {
......@@ -193,13 +180,6 @@ using AtomicUint64 = UintPtrT;
#error Unknown architecture.
#endif
// {raw_value} must be a tagged Object.
// {raw_type} must be a tagged Smi.
// {raw_location} must be a tagged String.
// Returns a tagged Smi.
Address CheckObjectType(Address raw_value, Address raw_type,
Address raw_location);
namespace compiler {
class CallDescriptor;
......
// Copyright 2021 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 "src/objects/object-type.h"
#include "src/objects/objects-inl.h"
#include "src/objects/smi.h"
#include "src/objects/string-inl.h"
namespace v8 {
namespace internal {
Address CheckObjectType(Address raw_value, Address raw_type,
Address raw_location) {
#ifdef DEBUG
Object value(raw_value);
Smi type(raw_type);
String location = String::cast(Object(raw_location));
const char* expected;
switch (static_cast<ObjectType>(type.value())) {
#define TYPE_CASE(Name) \
case ObjectType::k##Name: \
if (value.Is##Name()) return Smi::FromInt(0).ptr(); \
expected = #Name; \
break;
#define TYPE_STRUCT_CASE(NAME, Name, name) \
case ObjectType::k##Name: \
if (value.Is##Name()) return Smi::FromInt(0).ptr(); \
expected = #Name; \
break;
TYPE_CASE(Object)
TYPE_CASE(Smi)
TYPE_CASE(TaggedIndex)
TYPE_CASE(HeapObject)
OBJECT_TYPE_LIST(TYPE_CASE)
HEAP_OBJECT_TYPE_LIST(TYPE_CASE)
STRUCT_LIST(TYPE_STRUCT_CASE)
#undef TYPE_CASE
#undef TYPE_STRUCT_CASE
}
std::stringstream value_description;
value.Print(value_description);
FATAL(
"Type cast failed in %s\n"
" Expected %s but found %s",
location.ToAsciiArray(), expected, value_description.str().c_str());
#else
UNREACHABLE();
#endif
}
} // namespace internal
} // namespace v8
// Copyright 2021 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_OBJECTS_OBJECT_TYPE_H_
#define V8_OBJECTS_OBJECT_TYPE_H_
#include "src/base/macros.h"
#include "src/common/globals.h"
#include "src/objects/object-list-macros.h"
#include "src/objects/objects-definitions.h"
namespace v8 {
namespace internal {
#define ENUM_ELEMENT(Name) k##Name,
#define ENUM_STRUCT_ELEMENT(NAME, Name, name) k##Name,
enum class ObjectType {
ENUM_ELEMENT(Object) //
ENUM_ELEMENT(Smi) //
ENUM_ELEMENT(TaggedIndex) //
ENUM_ELEMENT(HeapObject) //
OBJECT_TYPE_LIST(ENUM_ELEMENT) //
HEAP_OBJECT_TYPE_LIST(ENUM_ELEMENT) //
STRUCT_LIST(ENUM_STRUCT_ELEMENT) //
};
#undef ENUM_ELEMENT
#undef ENUM_STRUCT_ELEMENT
// {raw_value} must be a tagged Object.
// {raw_type} must be a tagged Smi.
// {raw_location} must be a tagged String.
// Returns a tagged Smi.
V8_EXPORT_PRIVATE Address CheckObjectType(Address raw_value, Address raw_type,
Address raw_location);
} // namespace internal
} // namespace v8
#endif // V8_OBJECTS_OBJECT_TYPE_H_
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