2019-07-26 05:36:37 +08:00
|
|
|
//===- LLDBPropertyDefEmitter.cpp -----------------------------------------===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// These tablegen backends emits LLDB's PropertyDefinition values.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "LLDBTableGenBackends.h"
|
2019-07-31 08:47:00 +08:00
|
|
|
#include "LLDBTableGenUtils.h"
|
2019-07-26 05:36:37 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
|
|
|
#include "llvm/TableGen/Record.h"
|
|
|
|
#include "llvm/TableGen/StringMatcher.h"
|
|
|
|
#include "llvm/TableGen/TableGenBackend.h"
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace llvm;
|
2019-07-31 06:50:37 +08:00
|
|
|
using namespace lldb_private;
|
2019-07-26 05:36:37 +08:00
|
|
|
|
|
|
|
static void emitPropertyEnum(Record *Property, raw_ostream &OS) {
|
|
|
|
OS << "eProperty";
|
|
|
|
OS << Property->getName();
|
|
|
|
OS << ",\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
static void emitProperty(Record *Property, raw_ostream &OS) {
|
|
|
|
OS << " {";
|
|
|
|
|
|
|
|
// Emit the property name.
|
|
|
|
OS << "\"" << Property->getValueAsString("Name") << "\"";
|
|
|
|
OS << ", ";
|
|
|
|
|
|
|
|
// Emit the property type.
|
2020-03-21 09:34:50 +08:00
|
|
|
llvm::StringRef type = Property->getValueAsString("Type");
|
2019-07-26 05:36:37 +08:00
|
|
|
OS << "OptionValue::eType";
|
2020-03-21 09:34:50 +08:00
|
|
|
OS << type;
|
2019-07-26 05:36:37 +08:00
|
|
|
OS << ", ";
|
|
|
|
|
|
|
|
// Emit the property's global value.
|
|
|
|
OS << (Property->getValue("Global") ? "true" : "false");
|
|
|
|
OS << ", ";
|
|
|
|
|
|
|
|
bool hasDefaultUnsignedValue = Property->getValue("HasDefaultUnsignedValue");
|
|
|
|
bool hasDefaultEnumValue = Property->getValue("HasDefaultEnumValue");
|
|
|
|
bool hasDefaultStringValue = Property->getValue("HasDefaultStringValue");
|
2020-03-21 09:34:50 +08:00
|
|
|
bool hasElementType = Property->getValue("HasElementType");
|
2019-07-26 05:36:37 +08:00
|
|
|
|
|
|
|
// Guarantee that every property has a default value.
|
|
|
|
assert((hasDefaultUnsignedValue || hasDefaultEnumValue ||
|
2020-03-21 09:34:50 +08:00
|
|
|
hasDefaultStringValue || hasElementType) &&
|
|
|
|
"Property must have a default value or an element type");
|
2019-07-26 05:36:37 +08:00
|
|
|
|
|
|
|
// Guarantee that no property has both a default unsigned value and a default
|
|
|
|
// enum value, since they're bothed stored in the same field.
|
|
|
|
assert(!(hasDefaultUnsignedValue && hasDefaultEnumValue) &&
|
|
|
|
"Property cannot have both a unsigned and enum default value.");
|
|
|
|
|
2019-10-26 01:17:09 +08:00
|
|
|
// Guarantee that every boolean property has a boolean default value.
|
|
|
|
assert(!(Property->getValueAsString("Type") == "Boolean" &&
|
2019-10-26 06:46:24 +08:00
|
|
|
!Property->getValue("HasDefaultBooleanValue")) &&
|
2019-10-26 01:17:09 +08:00
|
|
|
"Boolean property must have a boolean default value.");
|
|
|
|
|
|
|
|
// Guarantee that every string property has a string default value.
|
|
|
|
assert(!(Property->getValueAsString("Type") == "String" &&
|
|
|
|
!hasDefaultStringValue) &&
|
|
|
|
"String property must have a string default value.");
|
|
|
|
|
|
|
|
// Guarantee that every enum property has an enum default value.
|
|
|
|
assert(
|
|
|
|
!(Property->getValueAsString("Type") == "Enum" && !hasDefaultEnumValue) &&
|
|
|
|
"Enum property must have a enum default value.");
|
|
|
|
|
2020-03-21 09:34:50 +08:00
|
|
|
// Guarantee that only arrays and dictionaries have an element type;
|
|
|
|
assert(((type != "Array" && type != "Dictionary") || hasElementType) &&
|
|
|
|
"Only dictionaries and arrays can have an element type.");
|
|
|
|
|
2019-07-26 05:36:37 +08:00
|
|
|
// Emit the default uint value.
|
|
|
|
if (hasDefaultUnsignedValue) {
|
|
|
|
OS << std::to_string(Property->getValueAsInt("DefaultUnsignedValue"));
|
|
|
|
} else if (hasDefaultEnumValue) {
|
|
|
|
OS << Property->getValueAsString("DefaultEnumValue");
|
2020-03-21 09:34:50 +08:00
|
|
|
} else if (hasElementType) {
|
|
|
|
OS << "OptionValue::eType";
|
|
|
|
OS << Property->getValueAsString("ElementType");
|
2019-07-26 05:36:37 +08:00
|
|
|
} else {
|
|
|
|
OS << "0";
|
|
|
|
}
|
|
|
|
OS << ", ";
|
|
|
|
|
|
|
|
// Emit the default string value.
|
|
|
|
if (hasDefaultStringValue) {
|
|
|
|
if (auto D = Property->getValue("DefaultStringValue")) {
|
|
|
|
OS << "\"";
|
2019-07-26 06:17:08 +08:00
|
|
|
OS << D->getValue()->getAsUnquotedString();
|
2019-07-26 05:36:37 +08:00
|
|
|
OS << "\"";
|
|
|
|
} else {
|
|
|
|
OS << "\"\"";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
OS << "nullptr";
|
|
|
|
}
|
|
|
|
OS << ", ";
|
|
|
|
|
|
|
|
// Emit the enum values value.
|
|
|
|
if (Property->getValue("EnumValues"))
|
|
|
|
OS << Property->getValueAsString("EnumValues");
|
|
|
|
else
|
|
|
|
OS << "{}";
|
|
|
|
OS << ", ";
|
|
|
|
|
|
|
|
// Emit the property description.
|
|
|
|
if (auto D = Property->getValue("Description")) {
|
|
|
|
OS << "\"";
|
2019-07-26 06:17:08 +08:00
|
|
|
OS << D->getValue()->getAsUnquotedString();
|
2019-07-26 05:36:37 +08:00
|
|
|
OS << "\"";
|
|
|
|
} else {
|
|
|
|
OS << "\"\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << "},\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Emits all property initializers to the raw_ostream.
|
|
|
|
static void emityProperties(std::string PropertyName,
|
|
|
|
std::vector<Record *> PropertyRecords,
|
|
|
|
raw_ostream &OS) {
|
|
|
|
// Generate the macro that the user needs to define before including the
|
|
|
|
// *.inc file.
|
|
|
|
std::string NeededMacro = "LLDB_PROPERTIES_" + PropertyName;
|
|
|
|
std::replace(NeededMacro.begin(), NeededMacro.end(), ' ', '_');
|
|
|
|
|
|
|
|
// All options are in one file, so we need put them behind macros and ask the
|
|
|
|
// user to define the macro for the options that are needed.
|
|
|
|
OS << "// Property definitions for " << PropertyName << "\n";
|
|
|
|
OS << "#ifdef " << NeededMacro << "\n";
|
2019-07-30 00:41:30 +08:00
|
|
|
OS << "static constexpr PropertyDefinition g_" << PropertyName
|
|
|
|
<< "_properties[] = {\n";
|
2019-07-26 05:36:37 +08:00
|
|
|
for (Record *R : PropertyRecords)
|
|
|
|
emitProperty(R, OS);
|
2019-07-30 00:41:30 +08:00
|
|
|
OS << "};\n";
|
2019-07-26 05:36:37 +08:00
|
|
|
// We undefine the macro for the user like Clang's include files are doing it.
|
|
|
|
OS << "#undef " << NeededMacro << "\n";
|
|
|
|
OS << "#endif // " << PropertyName << " Property\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Emits all property initializers to the raw_ostream.
|
|
|
|
static void emitPropertyEnum(std::string PropertyName,
|
|
|
|
std::vector<Record *> PropertyRecords,
|
|
|
|
raw_ostream &OS) {
|
|
|
|
// Generate the macro that the user needs to define before including the
|
|
|
|
// *.inc file.
|
|
|
|
std::string NeededMacro = "LLDB_PROPERTIES_" + PropertyName;
|
|
|
|
std::replace(NeededMacro.begin(), NeededMacro.end(), ' ', '_');
|
|
|
|
|
|
|
|
// All options are in one file, so we need put them behind macros and ask the
|
|
|
|
// user to define the macro for the options that are needed.
|
|
|
|
OS << "// Property enum cases for " << PropertyName << "\n";
|
|
|
|
OS << "#ifdef " << NeededMacro << "\n";
|
|
|
|
for (Record *R : PropertyRecords)
|
|
|
|
emitPropertyEnum(R, OS);
|
|
|
|
// We undefine the macro for the user like Clang's include files are doing it.
|
|
|
|
OS << "#undef " << NeededMacro << "\n";
|
|
|
|
OS << "#endif // " << PropertyName << " Property\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void lldb_private::EmitPropertyDefs(RecordKeeper &Records, raw_ostream &OS) {
|
|
|
|
emitSourceFileHeader("Property definitions for LLDB.", OS);
|
|
|
|
|
|
|
|
std::vector<Record *> Properties =
|
|
|
|
Records.getAllDerivedDefinitions("Property");
|
2019-07-31 08:47:00 +08:00
|
|
|
for (auto &PropertyRecordPair : getRecordsByName(Properties, "Definition")) {
|
2019-07-26 05:36:37 +08:00
|
|
|
emityProperties(PropertyRecordPair.first, PropertyRecordPair.second, OS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void lldb_private::EmitPropertyEnumDefs(RecordKeeper &Records,
|
|
|
|
raw_ostream &OS) {
|
|
|
|
emitSourceFileHeader("Property definition enum for LLDB.", OS);
|
|
|
|
|
|
|
|
std::vector<Record *> Properties =
|
|
|
|
Records.getAllDerivedDefinitions("Property");
|
2019-07-31 08:47:00 +08:00
|
|
|
for (auto &PropertyRecordPair : getRecordsByName(Properties, "Definition")) {
|
2019-07-26 05:36:37 +08:00
|
|
|
emitPropertyEnum(PropertyRecordPair.first, PropertyRecordPair.second, OS);
|
|
|
|
}
|
|
|
|
}
|