1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

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
This commit is contained in:
River Riddle 2019-11-20 18:21:50 -08:00 committed by Mehdi Amini
parent 2aa858aa23
commit b76b006b31
6 changed files with 22 additions and 15 deletions

View File

@ -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();

View File

@ -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();

View File

@ -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;
}

View File

@ -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();
}

View File

@ -0,0 +1,7 @@
#ifndef DUPLICATE_INCLUDE
#define DUPLICATE_INCLUDE
// This is used by the duplicate-include.td test
def InInclude;
#endif

View File

@ -0,0 +1,7 @@
// RUN: llvm-tblgen -I %p %s | FileCheck %s
// CHECK: def InInclude
include "duplicate-include.inc"
include "duplicate-include.inc"