[TableGen] Move helpers into LLDBTableGenUtils.
authorJonas Devlieghere <jonas@devlieghere.com>
Wed, 31 Jul 2019 00:47:00 +0000 (00:47 +0000)
committerJonas Devlieghere <jonas@devlieghere.com>
Wed, 31 Jul 2019 00:47:00 +0000 (00:47 +0000)
Instead of polluting the LLDBTableGenBackends header with helpers used
by both emitters, move them into a separate files.

llvm-svn: 367377

lldb/utils/TableGen/CMakeLists.txt
lldb/utils/TableGen/LLDBOptionDefEmitter.cpp
lldb/utils/TableGen/LLDBPropertyDefEmitter.cpp
lldb/utils/TableGen/LLDBTableGenBackends.h
lldb/utils/TableGen/LLDBTableGenUtils.cpp [new file with mode: 0644]
lldb/utils/TableGen/LLDBTableGenUtils.h [new file with mode: 0644]

index 2f365d2..2e8aec1 100644 (file)
@@ -10,6 +10,7 @@ else()
     LLDBOptionDefEmitter.cpp
     LLDBPropertyDefEmitter.cpp
     LLDBTableGen.cpp
+    LLDBTableGenUtils.cpp
     )
   set_target_properties(lldb-tblgen PROPERTIES FOLDER "LLDB tablegenning")
 endif()
index 01eacba..6e73d0c 100644 (file)
 //===----------------------------------------------------------------------===//
 
 #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);
   }
 }
index 9e46218..f49c05c 100644 (file)
 //===----------------------------------------------------------------------===//
 
 #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);
   }
 }
index d9b4e8f..b424abf 100644 (file)
@@ -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 (file)
index 0000000..8b4c758
--- /dev/null
@@ -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 (file)
index 0000000..5553cec
--- /dev/null
@@ -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