Author: jdevlieghere Date: Tue Jul 30 17:47:00 2019 New Revision: 367377 URL: http://llvm.org/viewvc/llvm-project?rev=367377&view=rev Log: [TableGen] Move helpers into LLDBTableGenUtils.
Instead of polluting the LLDBTableGenBackends header with helpers used by both emitters, move them into a separate files. Added: lldb/trunk/utils/TableGen/LLDBTableGenUtils.cpp lldb/trunk/utils/TableGen/LLDBTableGenUtils.h Modified: lldb/trunk/utils/TableGen/CMakeLists.txt lldb/trunk/utils/TableGen/LLDBOptionDefEmitter.cpp lldb/trunk/utils/TableGen/LLDBPropertyDefEmitter.cpp lldb/trunk/utils/TableGen/LLDBTableGenBackends.h Modified: lldb/trunk/utils/TableGen/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/utils/TableGen/CMakeLists.txt?rev=367377&r1=367376&r2=367377&view=diff ============================================================================== --- lldb/trunk/utils/TableGen/CMakeLists.txt (original) +++ lldb/trunk/utils/TableGen/CMakeLists.txt Tue Jul 30 17:47:00 2019 @@ -10,6 +10,7 @@ else() LLDBOptionDefEmitter.cpp LLDBPropertyDefEmitter.cpp LLDBTableGen.cpp + LLDBTableGenUtils.cpp ) set_target_properties(lldb-tblgen PROPERTIES FOLDER "LLDB tablegenning") endif() Modified: lldb/trunk/utils/TableGen/LLDBOptionDefEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/utils/TableGen/LLDBOptionDefEmitter.cpp?rev=367377&r1=367376&r2=367377&view=diff ============================================================================== --- lldb/trunk/utils/TableGen/LLDBOptionDefEmitter.cpp (original) +++ lldb/trunk/utils/TableGen/LLDBOptionDefEmitter.cpp Tue Jul 30 17:47:00 2019 @@ -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(Record 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); } } Modified: lldb/trunk/utils/TableGen/LLDBPropertyDefEmitter.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/utils/TableGen/LLDBPropertyDefEmitter.cpp?rev=367377&r1=367376&r2=367377&view=diff ============================================================================== --- lldb/trunk/utils/TableGen/LLDBPropertyDefEmitter.cpp (original) +++ lldb/trunk/utils/TableGen/LLDBPropertyDefEmitter.cpp Tue Jul 30 17:47:00 2019 @@ -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(Reco 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( std::vector<Record *> Properties = Records.getAllDerivedDefinitions("Property"); - for (auto &PropertyRecordPair : getPropertyList(Properties)) { + for (auto &PropertyRecordPair : getRecordsByName(Properties, "Definition")) { emitPropertyEnum(PropertyRecordPair.first, PropertyRecordPair.second, OS); } } Modified: lldb/trunk/utils/TableGen/LLDBTableGenBackends.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/utils/TableGen/LLDBTableGenBackends.h?rev=367377&r1=367376&r2=367377&view=diff ============================================================================== --- lldb/trunk/utils/TableGen/LLDBTableGenBackends.h (original) +++ lldb/trunk/utils/TableGen/LLDBTableGenBackends.h Tue Jul 30 17:47:00 2019 @@ -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); Added: lldb/trunk/utils/TableGen/LLDBTableGenUtils.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/utils/TableGen/LLDBTableGenUtils.cpp?rev=367377&view=auto ============================================================================== --- lldb/trunk/utils/TableGen/LLDBTableGenUtils.cpp (added) +++ lldb/trunk/utils/TableGen/LLDBTableGenUtils.cpp Tue Jul 30 17:47:00 2019 @@ -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; +} Added: lldb/trunk/utils/TableGen/LLDBTableGenUtils.h URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/utils/TableGen/LLDBTableGenUtils.h?rev=367377&view=auto ============================================================================== --- lldb/trunk/utils/TableGen/LLDBTableGenUtils.h (added) +++ lldb/trunk/utils/TableGen/LLDBTableGenUtils.h Tue Jul 30 17:47:00 2019 @@ -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 _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits