llvm.org GIT mirror llvm / d9f5d90
add support for multiple include directories git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26485 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
2 changed file(s) with 16 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
3535 namespace llvm {
3636
3737 // Global variable recording the location of the include directory
38 std::string IncludeDirectory;
38 std::vector IncludeDirectories;
3939
4040 /// ParseInt - This has to handle the special case of binary numbers 0b0101
4141 ///
7373
7474 /// ParseFile - this function begins the parsing of the specified tablegen file.
7575 ///
76 void ParseFile(const std::string &Filename, const std::string & IncludeDir) {
76 void ParseFile(const std::string &Filename,
77 const std::vector &IncludeDirs) {
7778 FILE *F = stdin;
7879 if (Filename != "-") {
7980 F = fopen(Filename.c_str(), "r");
8990
9091 // Record the location of the include directory so that the lexer can find
9192 // it later.
92 IncludeDirectory = IncludeDir;
93 IncludeDirectories = IncludeDirs;
9394
9495 Filein = F;
9596 Filelineno = 1;
123124 // If we couldn't find the file in the current directory, look for it in
124125 // the include directories.
125126 //
126 // NOTE: Right now, there is only one directory. We need to eventually add
127 // support for more.
128 std::string NextFilename = IncludeDirectory + "/" + Filename;
129 yyin = fopen(NextFilename.c_str(), "r");
127 std::string NextFilename;
128 for (unsigned i = 0, e = IncludeDirectories.size(); i != e; ++i) {
129 NextFilename = IncludeDirectories[i] + "/" + Filename;
130 if (yyin = fopen(NextFilename.c_str(), "r"))
131 break;
132 }
133
130134 if (yyin == 0) {
131135 err() << "Could not find include file '" << Filename << "'!\n";
132136 exit(1);
8181 cl::opt
8282 InputFilename(cl::Positional, cl::desc(""), cl::init("-"));
8383
84 cl::opt
85 IncludeDir("I", cl::desc("Directory of include files"),
86 cl::value_desc("directory"), cl::init(""));
84 cl::list
85 IncludeDirs("I", cl::desc("Directory of include files"),
86 cl::value_desc("directory"));
8787 }
8888
8989 namespace llvm {
9090 void ParseFile(const std::string &Filename,
91 const std::string &IncludeDir);
91 const std::vector &IncludeDirs);
9292 }
9393
9494 RecordKeeper llvm::Records;
419419
420420 int main(int argc, char **argv) {
421421 cl::ParseCommandLineOptions(argc, argv);
422 ParseFile(InputFilename, IncludeDir);
422 ParseFile(InputFilename, IncludeDirs);
423423
424424 std::ostream *Out = &std::cout;
425425 if (OutputFilename != "-") {