[torque] Generate bitfield definitions as macros

The list of forward declarations required in the generated file
bit-fields-tq.h is already somewhat unwieldy and will run into serious
problems when we attempt to use enums that are defined within classes,
such as JSDateTimeFormat::DateTimeStyle. After a brief discussion today,
the cleanest solution we arrived at is to generate macros instead.

Change-Id: I654e10efbab5a1a0a340fa565c51ff1da34badaa
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2050830
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Nico Hartmann <nicohartmann@chromium.org>
Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#66240}
This commit is contained in:
Seth Brenith 2020-02-11 11:47:12 -08:00 committed by Commit Bot
parent 137bfe47c9
commit 4ef429f7cd
7 changed files with 33 additions and 30 deletions

View File

@ -24,10 +24,10 @@ class BytecodeArray;
// The DebugInfo class holds additional information for a function being
// debugged.
class DebugInfo : public TorqueGeneratedDebugInfo<DebugInfo, Struct>,
public TorqueGeneratedDebugInfoFlagsFields {
class DebugInfo : public TorqueGeneratedDebugInfo<DebugInfo, Struct> {
public:
NEVER_READ_ONLY_SPACE
DEFINE_TORQUE_GENERATED_DEBUG_INFO_FLAGS()
using Flags = base::Flags<Flag>;
// A bitfield that lists uses of the current instance.

View File

@ -253,7 +253,9 @@ class Map : public HeapObject {
DECL_PRIMITIVE_ACCESSORS(relaxed_bit_field, byte)
// Bit positions for |bit_field|.
using Bits1 = TorqueGeneratedMapBitFields1Fields;
struct Bits1 {
DEFINE_TORQUE_GENERATED_MAP_BIT_FIELDS1()
};
//
// Bit field 2.
@ -261,7 +263,9 @@ class Map : public HeapObject {
DECL_PRIMITIVE_ACCESSORS(bit_field2, byte)
// Bit positions for |bit_field2|.
using Bits2 = TorqueGeneratedMapBitFields2Fields;
struct Bits2 {
DEFINE_TORQUE_GENERATED_MAP_BIT_FIELDS2()
};
//
// Bit field 3.
@ -273,7 +277,9 @@ class Map : public HeapObject {
V8_INLINE void clear_padding();
// Bit positions for |bit_field3|.
using Bits3 = TorqueGeneratedMapBitFields3Fields;
struct Bits3 {
DEFINE_TORQUE_GENERATED_MAP_BIT_FIELDS3()
};
// Ensure that Torque-defined bit widths for |bit_field3| are as expected.
STATIC_ASSERT(Bits3::EnumLengthBits::kSize == kDescriptorIndexBitCount);

View File

@ -139,9 +139,10 @@ class Name : public TorqueGeneratedName<Name, PrimitiveHeapObject> {
};
// ES6 symbols.
class Symbol : public TorqueGeneratedSymbol<Symbol, Name>,
public TorqueGeneratedSymbolFlagsFields {
class Symbol : public TorqueGeneratedSymbol<Symbol, Name> {
public:
DEFINE_TORQUE_GENERATED_SYMBOL_FLAGS()
// [is_private]: Whether this is a private symbol. Private symbols can only
// be used to designate own properties of objects.
DECL_BOOLEAN_ACCESSORS(is_private)

View File

@ -37,8 +37,10 @@ class Zone;
// This object provides quick access to scope info details for runtime
// routines.
class ScopeInfo : public FixedArray, public TorqueGeneratedScopeFlagsFields {
class ScopeInfo : public FixedArray {
public:
DEFINE_TORQUE_GENERATED_SCOPE_FLAGS()
DECL_CAST(ScopeInfo)
DECL_PRINTER(ScopeInfo)

View File

@ -167,10 +167,10 @@ class InterpreterData : public Struct {
// SharedFunctionInfo describes the JSFunction information that can be
// shared by multiple instances of the function.
class SharedFunctionInfo : public HeapObject,
public TorqueGeneratedSharedFunctionInfoFlagsFields {
class SharedFunctionInfo : public HeapObject {
public:
NEVER_READ_ONLY_SPACE
DEFINE_TORQUE_GENERATED_SHARED_FUNCTION_INFO_FLAGS()
// This initializes the SharedFunctionInfo after allocation. It must
// initialize all fields, and leave the SharedFunctionInfo in a state where

View File

@ -858,9 +858,12 @@ void CSAGenerator::EmitInstruction(const StoreReferenceInstruction& instruction,
namespace {
std::string GetBitFieldSpecialization(const BitFieldStructType* container,
const BitField& field) {
std::string suffix = field.num_bits == 1 ? "Bit" : "Bits";
return "TorqueGenerated" + container->name() +
"Fields::" + CamelifyString(field.name_and_type.name) + suffix;
std::stringstream stream;
stream << "base::BitField<"
<< field.name_and_type.type->GetConstexprGeneratedTypeName() << ", "
<< field.offset << ", " << field.num_bits << ", "
<< container->GetConstexprGeneratedTypeName() << ">";
return stream.str();
}
} // namespace

View File

@ -3250,20 +3250,11 @@ void ImplementationVisitor::GenerateBitFields(
header << "#include \"src/base/bit-field.h\"\n\n";
NamespaceScope namespaces(header, {"v8", "internal"});
// TODO(v8:7793): Once we can define enums in Torque, we should be able to
// do something nicer than hard-coding these predeclarations. Until then,
// any enum used as a bitfield must be included in this list.
header << R"(
enum class FunctionSyntaxKind : uint8_t;
enum class BailoutReason : uint8_t;
enum FunctionKind : uint8_t;
)";
for (const auto& type : TypeOracle::GetBitFieldStructTypes()) {
bool all_single_bits = true; // Track whether every field is one bit.
header << "struct TorqueGenerated" << type->name() << "Fields {\n";
header << "#define DEFINE_TORQUE_GENERATED_"
<< CapifyStringWithUnderscores(type->name()) << "() \\\n";
std::string type_name = type->GetConstexprGeneratedTypeName();
for (const auto& field : type->fields()) {
const char* suffix = field.num_bits == 1 ? "Bit" : "Bits";
@ -3273,21 +3264,21 @@ enum FunctionKind : uint8_t;
header << " using " << CamelifyString(field.name_and_type.name)
<< suffix << " = base::BitField<" << field_type_name << ", "
<< field.offset << ", " << field.num_bits << ", " << type_name
<< ">;\n";
<< ">; \\\n";
}
// If every field is one bit, we can also generate a convenient enum.
if (all_single_bits) {
header << " enum Flag {\n";
header << " kNone = 0,\n";
header << " enum Flag { \\\n";
header << " kNone = 0, \\\n";
for (const auto& field : type->fields()) {
header << " k" << CamelifyString(field.name_and_type.name)
<< " = 1 << " << field.offset << ",\n";
<< " = 1 << " << field.offset << ", \\\n";
}
header << " };\n";
header << " }; \\\n";
}
header << "};\n\n";
header << "\n";
}
}
const std::string output_header_path = output_directory + "/" + file_name;