[llvm] ee9b49e - Tablegen: Remove the error for duplicate include files.
Mehdi Amini via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 20 18:25:21 PST 2019
Author: River Riddle
Date: 2019-11-20T18:24:10-08:00
New Revision: ee9b49eef04518123ec04372b7b4bfc337c39dc9
URL: https://github.com/llvm/llvm-project/commit/ee9b49eef04518123ec04372b7b4bfc337c39dc9
DIFF: https://github.com/llvm/llvm-project/commit/ee9b49eef04518123ec04372b7b4bfc337c39dc9.diff
LOG: 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
Added:
llvm/test/TableGen/duplicate-include.inc
llvm/test/TableGen/duplicate-include.td
Modified:
llvm/lib/TableGen/Main.cpp
llvm/lib/TableGen/TGLexer.cpp
llvm/lib/TableGen/TGLexer.h
llvm/lib/TableGen/TGParser.h
Removed:
################################################################################
diff --git a/llvm/lib/TableGen/Main.cpp b/llvm/lib/TableGen/Main.cpp
index 48ded6c45a46..427bd6778577 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 da2286e41fe5..425952338c6d 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 266a9cd5d973..11a9bd303f53 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 @@ class TGLexer {
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 840cd2181f26..cbe0b545d0fb 100644
--- a/llvm/lib/TableGen/TGParser.h
+++ b/llvm/lib/TableGen/TGParser.h
@@ -129,7 +129,7 @@ class TGParser {
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 000000000000..eefbf5ffc2ef
--- /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 000000000000..6c132499d851
--- /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"
+
More information about the llvm-commits
mailing list