aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/TableGen
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/TableGen')
-rw-r--r--llvm/lib/TableGen/DetailedRecordsBackend.cpp1
-rw-r--r--llvm/lib/TableGen/Main.cpp75
-rw-r--r--llvm/lib/TableGen/Record.cpp4
-rw-r--r--llvm/lib/TableGen/StringToOffsetTable.cpp3
-rw-r--r--llvm/lib/TableGen/TGLexer.cpp6
-rw-r--r--llvm/lib/TableGen/TGLexer.h1
-rw-r--r--llvm/lib/TableGen/TableGenBackend.cpp19
7 files changed, 71 insertions, 38 deletions
diff --git a/llvm/lib/TableGen/DetailedRecordsBackend.cpp b/llvm/lib/TableGen/DetailedRecordsBackend.cpp
index 1ed6435..b1152bf 100644
--- a/llvm/lib/TableGen/DetailedRecordsBackend.cpp
+++ b/llvm/lib/TableGen/DetailedRecordsBackend.cpp
@@ -22,7 +22,6 @@
#include "llvm/TableGen/Error.h"
#include "llvm/TableGen/Record.h"
#include <string>
-#include <utility>
using namespace llvm;
diff --git a/llvm/lib/TableGen/Main.cpp b/llvm/lib/TableGen/Main.cpp
index b1024a8..939e9c6 100644
--- a/llvm/lib/TableGen/Main.cpp
+++ b/llvm/lib/TableGen/Main.cpp
@@ -23,6 +23,7 @@
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
#include "llvm/Support/SMLoc.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/ToolOutputFile.h"
@@ -104,8 +105,29 @@ static int createDependencyFile(const TGParser &Parser, const char *argv0) {
return 0;
}
-int llvm::TableGenMain(const char *argv0,
- std::function<TableGenMainFn> MainFn) {
+static int WriteOutput(const TGParser &Parser, const char *argv0,
+ StringRef Filename, StringRef Content) {
+ if (WriteIfChanged) {
+ // Only updates the real output file if there are any differences.
+ // This prevents recompilation of all the files depending on it if there
+ // aren't any.
+ if (auto ExistingOrErr = MemoryBuffer::getFile(Filename, /*IsText=*/true))
+ if (std::move(ExistingOrErr.get())->getBuffer() == Content)
+ return 0;
+ }
+ std::error_code EC;
+ ToolOutputFile OutFile(Filename, EC, sys::fs::OF_Text);
+ if (EC)
+ return reportError(argv0, "error opening " + Filename + ": " +
+ EC.message() + "\n");
+ OutFile.os() << Content;
+ if (ErrorsPrinted == 0)
+ OutFile.keep();
+
+ return 0;
+}
+
+int llvm::TableGenMain(const char *argv0, MultiFileTableGenMainFn MainFn) {
RecordKeeper Records;
TGTimer &Timer = Records.getTimer();
@@ -144,13 +166,13 @@ int llvm::TableGenMain(const char *argv0,
// Write output to memory.
Timer.startBackendTimer("Backend overall");
- std::string OutString;
- raw_string_ostream Out(OutString);
+ TableGenOutputFiles OutFiles;
unsigned status = 0;
// ApplyCallback will return true if it did not apply any callback. In that
// case, attempt to apply the MainFn.
- if (TableGen::Emitter::ApplyCallback(Records, Out))
- status = MainFn ? MainFn(Out, Records) : 1;
+ StringRef FilenamePrefix(sys::path::stem(OutputFilename));
+ if (TableGen::Emitter::ApplyCallback(Records, OutFiles, FilenamePrefix))
+ status = MainFn ? MainFn(OutFiles, Records) : 1;
Timer.stopBackendTimer();
if (status)
return 1;
@@ -165,25 +187,17 @@ int llvm::TableGenMain(const char *argv0,
}
Timer.startTimer("Write output");
- bool WriteFile = true;
- if (WriteIfChanged) {
- // Only updates the real output file if there are any differences.
- // This prevents recompilation of all the files depending on it if there
- // aren't any.
- if (auto ExistingOrErr =
- MemoryBuffer::getFile(OutputFilename, /*IsText=*/true))
- if (std::move(ExistingOrErr.get())->getBuffer() == OutString)
- WriteFile = false;
- }
- if (WriteFile) {
- std::error_code EC;
- ToolOutputFile OutFile(OutputFilename, EC, sys::fs::OF_Text);
- if (EC)
- return reportError(argv0, "error opening " + OutputFilename + ": " +
- EC.message() + "\n");
- OutFile.os() << OutString;
- if (ErrorsPrinted == 0)
- OutFile.keep();
+ if (int Ret = WriteOutput(Parser, argv0, OutputFilename, OutFiles.MainFile))
+ return Ret;
+ for (auto [Suffix, Content] : OutFiles.AdditionalFiles) {
+ SmallString<128> Filename(OutputFilename);
+ // TODO: Format using the split-file convention when writing to stdout?
+ if (Filename != "-") {
+ sys::path::replace_extension(Filename, "");
+ Filename.append(Suffix);
+ }
+ if (int Ret = WriteOutput(Parser, argv0, Filename, Content))
+ return Ret;
}
Timer.stopTimer();
@@ -193,3 +207,14 @@ int llvm::TableGenMain(const char *argv0,
return reportError(argv0, Twine(ErrorsPrinted) + " errors.\n");
return 0;
}
+
+int llvm::TableGenMain(const char *argv0, TableGenMainFn MainFn) {
+ return TableGenMain(argv0, [&MainFn](TableGenOutputFiles &OutFiles,
+ const RecordKeeper &Records) {
+ std::string S;
+ raw_string_ostream OS(S);
+ int Res = MainFn(OS, Records);
+ OutFiles = {S, {}};
+ return Res;
+ });
+}
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index afce803..8ad20b4 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -46,12 +46,11 @@ using namespace llvm;
// Context
//===----------------------------------------------------------------------===//
-namespace llvm::detail {
/// This class represents the internal implementation of the RecordKeeper.
/// It contains all of the contextual static state of the Record classes. It is
/// kept out-of-line to simplify dependencies, and also make it easier for
/// internal classes to access the uniquer state of the keeper.
-struct RecordKeeperImpl {
+struct detail::RecordKeeperImpl {
RecordKeeperImpl(RecordKeeper &RK)
: SharedBitRecTy(RK), SharedIntRecTy(RK), SharedStringRecTy(RK),
SharedDagRecTy(RK), AnyRecord(RK, {}), TheUnsetInit(RK),
@@ -99,7 +98,6 @@ struct RecordKeeperImpl {
void dumpAllocationStats(raw_ostream &OS) const;
};
-} // namespace llvm::detail
void detail::RecordKeeperImpl::dumpAllocationStats(raw_ostream &OS) const {
// Dump memory allocation related stats.
diff --git a/llvm/lib/TableGen/StringToOffsetTable.cpp b/llvm/lib/TableGen/StringToOffsetTable.cpp
index 41f82ca..06d8240 100644
--- a/llvm/lib/TableGen/StringToOffsetTable.cpp
+++ b/llvm/lib/TableGen/StringToOffsetTable.cpp
@@ -39,7 +39,8 @@ void StringToOffsetTable::EmitStringTableDef(raw_ostream &OS,
#pragma GCC diagnostic ignored "-Woverlength-strings"
#endif
{} constexpr char {}{}Storage[] =)",
- ClassPrefix.empty() ? "static" : "", ClassPrefix, Name);
+ ClassPrefix.empty() ? "static" : "",
+ UsePrefixForStorageMember ? ClassPrefix : "", Name);
// MSVC silently miscompiles string literals longer than 64k in some
// circumstances. The build system sets EmitLongStrLiterals to false when it
diff --git a/llvm/lib/TableGen/TGLexer.cpp b/llvm/lib/TableGen/TGLexer.cpp
index 30eae6e..e8e6469 100644
--- a/llvm/lib/TableGen/TGLexer.cpp
+++ b/llvm/lib/TableGen/TGLexer.cpp
@@ -682,8 +682,10 @@ tgtok::TokKind TGLexer::LexExclaim() {
.Case("instances", tgtok::XInstances)
.Case("substr", tgtok::XSubstr)
.Case("find", tgtok::XFind)
- .Cases("setdagop", "setop", tgtok::XSetDagOp) // !setop is deprecated.
- .Cases("getdagop", "getop", tgtok::XGetDagOp) // !getop is deprecated.
+ .Cases({"setdagop", "setop"},
+ tgtok::XSetDagOp) // !setop is deprecated.
+ .Cases({"getdagop", "getop"},
+ tgtok::XGetDagOp) // !getop is deprecated.
.Case("setdagopname", tgtok::XSetDagOpName)
.Case("getdagopname", tgtok::XGetDagOpName)
.Case("getdagarg", tgtok::XGetDagArg)
diff --git a/llvm/lib/TableGen/TGLexer.h b/llvm/lib/TableGen/TGLexer.h
index 753470d..a0ade64 100644
--- a/llvm/lib/TableGen/TGLexer.h
+++ b/llvm/lib/TableGen/TGLexer.h
@@ -19,7 +19,6 @@
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/SMLoc.h"
#include <cassert>
-#include <memory>
#include <set>
#include <string>
diff --git a/llvm/lib/TableGen/TableGenBackend.cpp b/llvm/lib/TableGen/TableGenBackend.cpp
index 153ca39..116c3fc 100644
--- a/llvm/lib/TableGen/TableGenBackend.cpp
+++ b/llvm/lib/TableGen/TableGenBackend.cpp
@@ -61,12 +61,21 @@ Opt::Opt(StringRef Name, FnT CB, StringRef Desc, bool ByDefault) {
/// Apply callback specified on the command line. Returns true if no callback
/// was applied.
bool llvm::TableGen::Emitter::ApplyCallback(const RecordKeeper &Records,
- raw_ostream &OS) {
+ TableGenOutputFiles &OutFiles,
+ StringRef FilenamePrefix) {
FnT Fn = CallbackFunction->getValue();
- if (!Fn)
- return true;
- Fn(Records, OS);
- return false;
+ if (Fn.SingleFileGenerator) {
+ std::string S;
+ raw_string_ostream OS(S);
+ Fn.SingleFileGenerator(Records, OS);
+ OutFiles = {S, {}};
+ return false;
+ }
+ if (Fn.MultiFileGenerator) {
+ OutFiles = Fn.MultiFileGenerator(FilenamePrefix, Records);
+ return false;
+ }
+ return true;
}
static void printLine(raw_ostream &OS, const Twine &Prefix, char Fill,