summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRiver Riddle <riddleriver@gmail.com>2019-11-20 18:21:50 -0800
committerMehdi Amini <aminim@google.com>2019-11-20 18:24:10 -0800
commitee9b49eef04518123ec04372b7b4bfc337c39dc9 (patch)
treee910fd198eb9d0d3f89165a00c88d1558c74d298
parent8e896b19ddd940254c42cfbb11ba541b22177152 (diff)
downloadbcm5719-llvm-ee9b49eef04518123ec04372b7b4bfc337c39dc9.tar.gz
bcm5719-llvm-ee9b49eef04518123ec04372b7b4bfc337c39dc9.zip
Tablegen: Remove the error for duplicate include files.
This error was originally added a while(7 years) ago when including multiple files was basically always an error. Tablegen now has preprocessor support, which allows for building nice c/c++ style include guards. With the current error being reported, we unfortunately need to double guard when including files: * In user of MyFile.td #ifndef MYFILE_TD include MyFile.td #endif * In MyFile.td #ifndef MYFILE_TD #define MYFILE_TD ... #endif Differential Revision: https://reviews.llvm.org/D70410
-rw-r--r--llvm/lib/TableGen/Main.cpp2
-rw-r--r--llvm/lib/TableGen/TGLexer.cpp10
-rw-r--r--llvm/lib/TableGen/TGLexer.h9
-rw-r--r--llvm/lib/TableGen/TGParser.h2
-rw-r--r--llvm/test/TableGen/duplicate-include.inc7
-rw-r--r--llvm/test/TableGen/duplicate-include.td7
6 files changed, 22 insertions, 15 deletions
diff --git a/llvm/lib/TableGen/Main.cpp b/llvm/lib/TableGen/Main.cpp
index 48ded6c45a4..427bd677857 100644
--- a/llvm/lib/TableGen/Main.cpp
+++ b/llvm/lib/TableGen/Main.cpp
@@ -73,7 +73,7 @@ static int createDependencyFile(const TGParser &Parser, const char *argv0) {
EC.message() + "\n");
DepOut.os() << OutputFilename << ":";
for (const auto &Dep : Parser.getDependencies()) {
- DepOut.os() << ' ' << Dep.first;
+ DepOut.os() << ' ' << Dep;
}
DepOut.os() << "\n";
DepOut.keep();
diff --git a/llvm/lib/TableGen/TGLexer.cpp b/llvm/lib/TableGen/TGLexer.cpp
index da2286e41fe..425952338c6 100644
--- a/llvm/lib/TableGen/TGLexer.cpp
+++ b/llvm/lib/TableGen/TGLexer.cpp
@@ -379,15 +379,7 @@ bool TGLexer::LexInclude() {
return true;
}
- DependenciesMapTy::const_iterator Found = Dependencies.find(IncludedFile);
- if (Found != Dependencies.end()) {
- PrintError(getLoc(),
- "File '" + IncludedFile + "' has already been included.");
- SrcMgr.PrintMessage(Found->second, SourceMgr::DK_Note,
- "previously included here");
- return true;
- }
- Dependencies.insert(std::make_pair(IncludedFile, getLoc()));
+ Dependencies.insert(IncludedFile);
// Save the line number and lex buffer of the includer.
CurBuf = SrcMgr.getMemoryBuffer(CurBuffer)->getBuffer();
CurPtr = CurBuf.begin();
diff --git a/llvm/lib/TableGen/TGLexer.h b/llvm/lib/TableGen/TGLexer.h
index 266a9cd5d97..11a9bd303f5 100644
--- a/llvm/lib/TableGen/TGLexer.h
+++ b/llvm/lib/TableGen/TGLexer.h
@@ -19,8 +19,8 @@
#include "llvm/Support/DataTypes.h"
#include "llvm/Support/SMLoc.h"
#include <cassert>
-#include <map>
#include <memory>
+#include <set>
#include <string>
namespace llvm {
@@ -87,10 +87,11 @@ class TGLexer {
unsigned CurBuffer = 0;
public:
- typedef std::map<std::string, SMLoc> DependenciesMapTy;
+ typedef std::set<std::string> DependenciesSetTy;
+
private:
/// Dependencies - This is the list of all included files.
- DependenciesMapTy Dependencies;
+ DependenciesSetTy Dependencies;
public:
TGLexer(SourceMgr &SrcMgr, ArrayRef<std::string> Macros);
@@ -99,7 +100,7 @@ public:
return CurCode = LexToken(CurPtr == CurBuf.begin());
}
- const DependenciesMapTy &getDependencies() const {
+ const DependenciesSetTy &getDependencies() const {
return Dependencies;
}
diff --git a/llvm/lib/TableGen/TGParser.h b/llvm/lib/TableGen/TGParser.h
index 840cd2181f2..cbe0b545d0f 100644
--- a/llvm/lib/TableGen/TGParser.h
+++ b/llvm/lib/TableGen/TGParser.h
@@ -129,7 +129,7 @@ public:
bool TokError(const Twine &Msg) const {
return Error(Lex.getLoc(), Msg);
}
- const TGLexer::DependenciesMapTy &getDependencies() const {
+ const TGLexer::DependenciesSetTy &getDependencies() const {
return Lex.getDependencies();
}
diff --git a/llvm/test/TableGen/duplicate-include.inc b/llvm/test/TableGen/duplicate-include.inc
new file mode 100644
index 00000000000..eefbf5ffc2e
--- /dev/null
+++ b/llvm/test/TableGen/duplicate-include.inc
@@ -0,0 +1,7 @@
+#ifndef DUPLICATE_INCLUDE
+#define DUPLICATE_INCLUDE
+
+// This is used by the duplicate-include.td test
+def InInclude;
+
+#endif
diff --git a/llvm/test/TableGen/duplicate-include.td b/llvm/test/TableGen/duplicate-include.td
new file mode 100644
index 00000000000..6c132499d85
--- /dev/null
+++ b/llvm/test/TableGen/duplicate-include.td
@@ -0,0 +1,7 @@
+// RUN: llvm-tblgen -I %p %s | FileCheck %s
+
+// CHECK: def InInclude
+
+include "duplicate-include.inc"
+include "duplicate-include.inc"
+
OpenPOWER on IntegriCloud