forked from OSchip/llvm-project
[TableGen] Move helpers into LLDBTableGenUtils.
Instead of polluting the LLDBTableGenBackends header with helpers used by both emitters, move them into a separate files. llvm-svn: 367377
This commit is contained in:
parent
5f52d49f1d
commit
be019c7a1f
|
@ -10,6 +10,7 @@ else()
|
|||
LLDBOptionDefEmitter.cpp
|
||||
LLDBPropertyDefEmitter.cpp
|
||||
LLDBTableGen.cpp
|
||||
LLDBTableGenUtils.cpp
|
||||
)
|
||||
set_target_properties(lldb-tblgen PROPERTIES FOLDER "LLDB tablegenning")
|
||||
endif()
|
||||
|
|
|
@ -12,24 +12,16 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "LLDBTableGenBackends.h"
|
||||
#include "LLDBTableGenUtils.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/TableGen/Record.h"
|
||||
#include "llvm/TableGen/StringMatcher.h"
|
||||
#include "llvm/TableGen/TableGenBackend.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
using namespace llvm;
|
||||
using namespace lldb_private;
|
||||
|
||||
/// Groups all records by their command.
|
||||
static RecordsByName getCommandList(std::vector<Record *> Options) {
|
||||
RecordsByName result;
|
||||
for (Record *Option : Options)
|
||||
result[Option->getValueAsString("Command").str()].push_back(Option);
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace {
|
||||
struct CommandOption {
|
||||
std::vector<std::string> GroupsArg;
|
||||
|
@ -187,7 +179,7 @@ void lldb_private::EmitOptionDefs(RecordKeeper &Records, raw_ostream &OS) {
|
|||
emitSourceFileHeader("Options for LLDB command line commands.", OS);
|
||||
|
||||
std::vector<Record *> Options = Records.getAllDerivedDefinitions("Option");
|
||||
for (auto &CommandRecordPair : getCommandList(Options)) {
|
||||
for (auto &CommandRecordPair : getRecordsByName(Options, "Command")) {
|
||||
emitOptions(CommandRecordPair.first, CommandRecordPair.second, OS);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,24 +11,16 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "LLDBTableGenBackends.h"
|
||||
#include "LLDBTableGenUtils.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/TableGen/Record.h"
|
||||
#include "llvm/TableGen/StringMatcher.h"
|
||||
#include "llvm/TableGen/TableGenBackend.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
using namespace llvm;
|
||||
using namespace lldb_private;
|
||||
|
||||
/// Groups all properties by their definition.
|
||||
static RecordsByName getPropertyList(std::vector<Record *> Properties) {
|
||||
RecordsByName result;
|
||||
for (Record *Property : Properties)
|
||||
result[Property->getValueAsString("Definition").str()].push_back(Property);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void emitPropertyEnum(Record *Property, raw_ostream &OS) {
|
||||
OS << "eProperty";
|
||||
OS << Property->getName();
|
||||
|
@ -156,7 +148,7 @@ void lldb_private::EmitPropertyDefs(RecordKeeper &Records, raw_ostream &OS) {
|
|||
|
||||
std::vector<Record *> Properties =
|
||||
Records.getAllDerivedDefinitions("Property");
|
||||
for (auto &PropertyRecordPair : getPropertyList(Properties)) {
|
||||
for (auto &PropertyRecordPair : getRecordsByName(Properties, "Definition")) {
|
||||
emityProperties(PropertyRecordPair.first, PropertyRecordPair.second, OS);
|
||||
}
|
||||
}
|
||||
|
@ -167,7 +159,7 @@ void lldb_private::EmitPropertyEnumDefs(RecordKeeper &Records,
|
|||
|
||||
std::vector<Record *> Properties =
|
||||
Records.getAllDerivedDefinitions("Property");
|
||||
for (auto &PropertyRecordPair : getPropertyList(Properties)) {
|
||||
for (auto &PropertyRecordPair : getRecordsByName(Properties, "Definition")) {
|
||||
emitPropertyEnum(PropertyRecordPair.first, PropertyRecordPair.second, OS);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,7 @@
|
|||
#ifndef LLVM_LLDB_UTILS_TABLEGEN_TABLEGENBACKENDS_H
|
||||
#define LLVM_LLDB_UTILS_TABLEGEN_TABLEGENBACKENDS_H
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
|
||||
namespace llvm {
|
||||
class raw_ostream;
|
||||
|
@ -31,10 +29,6 @@ using llvm::RecordKeeper;
|
|||
|
||||
namespace lldb_private {
|
||||
|
||||
/// Map of names to their associated records. This map also ensures that our
|
||||
/// records are sorted in a deterministic way.
|
||||
typedef std::map<std::string, std::vector<llvm::Record *>> RecordsByName;
|
||||
|
||||
void EmitOptionDefs(RecordKeeper &RK, raw_ostream &OS);
|
||||
void EmitPropertyDefs(RecordKeeper &RK, raw_ostream &OS);
|
||||
void EmitPropertyEnumDefs(RecordKeeper &RK, raw_ostream &OS);
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
//===- LLDBTableGenUtils.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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "LLDBTableGenUtils.h"
|
||||
#include "llvm/TableGen/Record.h"
|
||||
|
||||
using namespace llvm;
|
||||
using namespace lldb_private;
|
||||
|
||||
RecordsByName lldb_private::getRecordsByName(std::vector<Record *> Records,
|
||||
StringRef Name) {
|
||||
RecordsByName Result;
|
||||
for (Record *R : Records)
|
||||
Result[R->getValueAsString(Name).str()].push_back(R);
|
||||
return Result;
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
//===- LLDBTableGenUtils.h --------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_LLDB_UTILS_TABLEGEN_TABLEGENUTILS_H
|
||||
#define LLVM_LLDB_UTILS_TABLEGEN_TABLEGENUTILS_H
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace llvm {
|
||||
class RecordKeeper;
|
||||
class Record;
|
||||
} // namespace llvm
|
||||
|
||||
namespace lldb_private {
|
||||
|
||||
/// Map of names to their associated records. This map also ensures that our
|
||||
/// records are sorted in a deterministic way.
|
||||
typedef std::map<std::string, std::vector<llvm::Record *>> RecordsByName;
|
||||
|
||||
/// Return records grouped by name.
|
||||
RecordsByName getRecordsByName(std::vector<llvm::Record *> Records,
|
||||
llvm::StringRef);
|
||||
|
||||
} // namespace lldb_private
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue