diff options
author | Chris Lattner <sabre@nondot.org> | 2006-03-03 01:47:14 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2006-03-03 01:47:14 +0000 |
commit | d9f5d90af198eff5fa78e313d019bd1770db7f03 (patch) | |
tree | 1bae86600df76be6c02ad983dc547837af87032f | |
parent | 21959390c11bed0ee199756f051bf9401fc5a699 (diff) |
add support for multiple include directories
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26485 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | utils/TableGen/FileLexer.l | 18 | ||||
-rw-r--r-- | utils/TableGen/TableGen.cpp | 10 |
2 files changed, 16 insertions, 12 deletions
diff --git a/utils/TableGen/FileLexer.l b/utils/TableGen/FileLexer.l index d0457eaa3d..c561ec64c6 100644 --- a/utils/TableGen/FileLexer.l +++ b/utils/TableGen/FileLexer.l @@ -36,7 +36,7 @@ int Fileparse(); namespace llvm { // Global variable recording the location of the include directory -std::string IncludeDirectory; +std::vector<std::string> IncludeDirectories; /// ParseInt - This has to handle the special case of binary numbers 0b0101 /// @@ -74,7 +74,8 @@ std::ostream &err() { /// ParseFile - this function begins the parsing of the specified tablegen file. /// -void ParseFile(const std::string &Filename, const std::string & IncludeDir) { +void ParseFile(const std::string &Filename, + const std::vector<std::string> &IncludeDirs) { FILE *F = stdin; if (Filename != "-") { F = fopen(Filename.c_str(), "r"); @@ -90,7 +91,7 @@ void ParseFile(const std::string &Filename, const std::string & IncludeDir) { // Record the location of the include directory so that the lexer can find // it later. - IncludeDirectory = IncludeDir; + IncludeDirectories = IncludeDirs; Filein = F; Filelineno = 1; @@ -124,10 +125,13 @@ static void HandleInclude(const char *Buffer) { // If we couldn't find the file in the current directory, look for it in // the include directories. // - // NOTE: Right now, there is only one directory. We need to eventually add - // support for more. - std::string NextFilename = IncludeDirectory + "/" + Filename; - yyin = fopen(NextFilename.c_str(), "r"); + std::string NextFilename; + for (unsigned i = 0, e = IncludeDirectories.size(); i != e; ++i) { + NextFilename = IncludeDirectories[i] + "/" + Filename; + if (yyin = fopen(NextFilename.c_str(), "r")) + break; + } + if (yyin == 0) { err() << "Could not find include file '" << Filename << "'!\n"; exit(1); diff --git a/utils/TableGen/TableGen.cpp b/utils/TableGen/TableGen.cpp index 3f8547d599..1007e1baaf 100644 --- a/utils/TableGen/TableGen.cpp +++ b/utils/TableGen/TableGen.cpp @@ -82,14 +82,14 @@ namespace { cl::opt<std::string> InputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-")); - cl::opt<std::string> - IncludeDir("I", cl::desc("Directory of include files"), - cl::value_desc("directory"), cl::init("")); + cl::list<std::string> + IncludeDirs("I", cl::desc("Directory of include files"), + cl::value_desc("directory")); } namespace llvm { void ParseFile(const std::string &Filename, - const std::string &IncludeDir); + const std::vector<std::string> &IncludeDirs); } RecordKeeper llvm::Records; @@ -420,7 +420,7 @@ static void ParseMachineCode() { int main(int argc, char **argv) { cl::ParseCommandLineOptions(argc, argv); - ParseFile(InputFilename, IncludeDir); + ParseFile(InputFilename, IncludeDirs); std::ostream *Out = &std::cout; if (OutputFilename != "-") { |