llvm.org GIT mirror llvm / 96b4bed
Added an option to TableGen that allows users to specify a directory in which to find include files. TableGen will load include files from this directory if it cannot find them in the current directory. This feature was needed for building code inside the object tree (a la autoconf style). TODO: Allow for multiple -I options to specify a list of directories to search. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8159 91177308-0d34-0410-b5e6-96231b3b80d8 John Criswell 16 years ago
4 changed file(s) with 90 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
2020
2121 %{
2222 #include "Record.h"
23 #include "Support/CommandLine.h"
2324 typedef std::pair*> SubClassRefTy;
2425 #include "FileParser.h"
26
27 // Global variable recording the location of the include directory
28 std::string IncludeDirectory;
2529
2630 // ParseInt - This has to handle the special case of binary numbers 0b0101
2731 static int ParseInt(const char *Str) {
6064
6165 int Fileparse();
6266
63 void ParseFile(const std::string &Filename) {
67 //
68 // Function: ParseFile()
69 //
70 // Description:
71 // This function begins the parsing of the specified tablegen file.
72 //
73 // Inputs:
74 // Filename - A string containing the name of the file to parse.
75 // IncludeDir - A string containing the directory from which include
76 // files can be found.
77 //
78 void ParseFile(const std::string &Filename, const std::string & IncludeDir) {
6479 FILE *F = stdin;
6580 if (Filename != "-") {
6681 F = fopen(Filename.c_str(), "r");
7489 IncludeStack.push_back(IncludeRec("", stdin));
7590 }
7691
92 //
93 // Record the location of the include directory so that the lexer can find
94 // it later.
95 //
96 IncludeDirectory = IncludeDir;
97
7798 Filein = F;
7899 Filelineno = 1;
79100 Fileparse();
102123 // Open the new input file...
103124 yyin = fopen(Filename.c_str(), "r");
104125 if (yyin == 0) {
105 err() << "Could not find include file '" << Filename << "'!\n";
106 abort();
126 //
127 // If we couldn't find the file in the current directory, look for it in
128 // the include directories.
129 //
130 // NOTE:
131 // Right now, there is only one directory. We need to eventually add
132 // support for more.
133 //
134 Filename = IncludeDirectory + "/" + Filename;
135 yyin = fopen(Filename.c_str(), "r");
136 if (yyin == 0) {
137 err() << "Could not find include file '" << Filename << "'!\n";
138 abort();
139 }
107140 }
108141
109142 // Add the file to our include stack...
6363
6464 cl::opt
6565 InputFilename(cl::Positional, cl::desc(""), cl::init("-"));
66 }
67
68
69 void ParseFile(const std::string &Filename);
66
67 cl::opt
68 IncludeDir("I", cl::desc("Directory of include files"),
69 cl::value_desc("directory"), cl::init(""));
70 }
71
72
73 void ParseFile(const std::string &Filename, const std::string & IncludeDir);
7074
7175 RecordKeeper Records;
7276
397401
398402 int main(int argc, char **argv) {
399403 cl::ParseCommandLineOptions(argc, argv);
400 ParseFile(InputFilename);
404 ParseFile(InputFilename, IncludeDir);
401405
402406 std::ostream *Out = &std::cout;
403407 if (OutputFilename != "-") {
2020
2121 %{
2222 #include "Record.h"
23 #include "Support/CommandLine.h"
2324 typedef std::pair*> SubClassRefTy;
2425 #include "FileParser.h"
26
27 // Global variable recording the location of the include directory
28 std::string IncludeDirectory;
2529
2630 // ParseInt - This has to handle the special case of binary numbers 0b0101
2731 static int ParseInt(const char *Str) {
6064
6165 int Fileparse();
6266
63 void ParseFile(const std::string &Filename) {
67 //
68 // Function: ParseFile()
69 //
70 // Description:
71 // This function begins the parsing of the specified tablegen file.
72 //
73 // Inputs:
74 // Filename - A string containing the name of the file to parse.
75 // IncludeDir - A string containing the directory from which include
76 // files can be found.
77 //
78 void ParseFile(const std::string &Filename, const std::string & IncludeDir) {
6479 FILE *F = stdin;
6580 if (Filename != "-") {
6681 F = fopen(Filename.c_str(), "r");
7489 IncludeStack.push_back(IncludeRec("", stdin));
7590 }
7691
92 //
93 // Record the location of the include directory so that the lexer can find
94 // it later.
95 //
96 IncludeDirectory = IncludeDir;
97
7798 Filein = F;
7899 Filelineno = 1;
79100 Fileparse();
102123 // Open the new input file...
103124 yyin = fopen(Filename.c_str(), "r");
104125 if (yyin == 0) {
105 err() << "Could not find include file '" << Filename << "'!\n";
106 abort();
126 //
127 // If we couldn't find the file in the current directory, look for it in
128 // the include directories.
129 //
130 // NOTE:
131 // Right now, there is only one directory. We need to eventually add
132 // support for more.
133 //
134 Filename = IncludeDirectory + "/" + Filename;
135 yyin = fopen(Filename.c_str(), "r");
136 if (yyin == 0) {
137 err() << "Could not find include file '" << Filename << "'!\n";
138 abort();
139 }
107140 }
108141
109142 // Add the file to our include stack...
6363
6464 cl::opt
6565 InputFilename(cl::Positional, cl::desc(""), cl::init("-"));
66 }
67
68
69 void ParseFile(const std::string &Filename);
66
67 cl::opt
68 IncludeDir("I", cl::desc("Directory of include files"),
69 cl::value_desc("directory"), cl::init(""));
70 }
71
72
73 void ParseFile(const std::string &Filename, const std::string & IncludeDir);
7074
7175 RecordKeeper Records;
7276
397401
398402 int main(int argc, char **argv) {
399403 cl::ParseCommandLineOptions(argc, argv);
400 ParseFile(InputFilename);
404 ParseFile(InputFilename, IncludeDir);
401405
402406 std::ostream *Out = &std::cout;
403407 if (OutputFilename != "-") {