diff options
| -rw-r--r-- | lldb/utils/TableGen/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | lldb/utils/TableGen/LLDBOptionDefEmitter.cpp | 12 | ||||
| -rw-r--r-- | lldb/utils/TableGen/LLDBPropertyDefEmitter.cpp | 14 | ||||
| -rw-r--r-- | lldb/utils/TableGen/LLDBTableGenBackends.h | 8 | ||||
| -rw-r--r-- | lldb/utils/TableGen/LLDBTableGenUtils.cpp | 21 | ||||
| -rw-r--r-- | lldb/utils/TableGen/LLDBTableGenUtils.h | 34 |
6 files changed, 62 insertions, 28 deletions
diff --git a/lldb/utils/TableGen/CMakeLists.txt b/lldb/utils/TableGen/CMakeLists.txt index 2f365d25af8..2e8aec1770a 100644 --- a/lldb/utils/TableGen/CMakeLists.txt +++ b/lldb/utils/TableGen/CMakeLists.txt @@ -10,6 +10,7 @@ else() LLDBOptionDefEmitter.cpp LLDBPropertyDefEmitter.cpp LLDBTableGen.cpp + LLDBTableGenUtils.cpp ) set_target_properties(lldb-tblgen PROPERTIES FOLDER "LLDB tablegenning") endif() diff --git a/lldb/utils/TableGen/LLDBOptionDefEmitter.cpp b/lldb/utils/TableGen/LLDBOptionDefEmitter.cpp index 01eacbad771..6e73d0c53de 100644 --- a/lldb/utils/TableGen/LLDBOptionDefEmitter.cpp +++ b/lldb/utils/TableGen/LLDBOptionDefEmitter.cpp @@ -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); } } diff --git a/lldb/utils/TableGen/LLDBPropertyDefEmitter.cpp b/lldb/utils/TableGen/LLDBPropertyDefEmitter.cpp index 9e46218935b..f49c05c9a58 100644 --- a/lldb/utils/TableGen/LLDBPropertyDefEmitter.cpp +++ b/lldb/utils/TableGen/LLDBPropertyDefEmitter.cpp @@ -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); } } diff --git a/lldb/utils/TableGen/LLDBTableGenBackends.h b/lldb/utils/TableGen/LLDBTableGenBackends.h index d9b4e8fa550..b424abfce9a 100644 --- a/lldb/utils/TableGen/LLDBTableGenBackends.h +++ b/lldb/utils/TableGen/LLDBTableGenBackends.h @@ -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); diff --git a/lldb/utils/TableGen/LLDBTableGenUtils.cpp b/lldb/utils/TableGen/LLDBTableGenUtils.cpp new file mode 100644 index 00000000000..8b4c7581c98 --- /dev/null +++ b/lldb/utils/TableGen/LLDBTableGenUtils.cpp @@ -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; +} diff --git a/lldb/utils/TableGen/LLDBTableGenUtils.h b/lldb/utils/TableGen/LLDBTableGenUtils.h new file mode 100644 index 00000000000..5553cecafb1 --- /dev/null +++ b/lldb/utils/TableGen/LLDBTableGenUtils.h @@ -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 |

