Added an option to TableGen that allows users to specify a directory in which
authorJohn Criswell <criswell@uiuc.edu>
Wed, 27 Aug 2003 13:41:57 +0000 (13:41 +0000)
committerJohn Criswell <criswell@uiuc.edu>
Wed, 27 Aug 2003 13:41:57 +0000 (13:41 +0000)
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

support/tools/TableGen/FileLexer.l
support/tools/TableGen/TableGen.cpp
utils/TableGen/FileLexer.l
utils/TableGen/TableGen.cpp

index 98370a7fef5d55b860954f027e2902b38ac75e77..f3cd32522aa751fc9e1c6fa733f2bd1b5c0e68fa 100644 (file)
 
 %{
 #include "Record.h"
+#include "Support/CommandLine.h"
 typedef std::pair<Record*, std::vector<Init*>*> SubClassRefTy;
 #include "FileParser.h"
 
+// Global variable recording the location of the include directory
+std::string IncludeDirectory;
+
 // ParseInt - This has to handle the special case of binary numbers 0b0101
 static int ParseInt(const char *Str) {
   if (Str[0] == '0' && Str[1] == 'b')
@@ -61,7 +65,18 @@ std::ostream &err() {
 
 int Fileparse();
 
-void ParseFile(const std::string &Filename) {
+//
+// Function: ParseFile()
+//
+// Description:
+//     This function begins the parsing of the specified tablegen file.
+//
+// Inputs:
+//     Filename - A string containing the name of the file to parse.
+//     IncludeDir - A string containing the directory from which include
+//                  files can be found.
+//
+void ParseFile(const std::string &Filename, const std::string & IncludeDir) {
   FILE *F = stdin;
   if (Filename != "-") {
     F = fopen(Filename.c_str(), "r");
@@ -75,6 +90,12 @@ void ParseFile(const std::string &Filename) {
     IncludeStack.push_back(IncludeRec("<stdin>", stdin));
   }
 
+  //
+  // Record the location of the include directory so that the lexer can find
+  // it later.
+  //
+  IncludeDirectory = IncludeDir;
   Filein = F;
   Filelineno = 1;
   Fileparse();
@@ -103,8 +124,20 @@ static void HandleInclude(const char *Buffer) {
   // Open the new input file...
   yyin = fopen(Filename.c_str(), "r");
   if (yyin == 0) {
-    err() << "Could not find include file '" << Filename << "'!\n";
-    abort();
+    //
+    // 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.
+    //
+    Filename = IncludeDirectory + "/" + Filename;
+    yyin = fopen(Filename.c_str(), "r");
+    if (yyin == 0) {
+      err() << "Could not find include file '" << Filename << "'!\n";
+      abort();
+    }
   }
 
   // Add the file to our include stack...
index 85a63ceaf6a16782d535ef9bc2f0c8535a9aa01f..67efdb46c857c59d31f1f220915506a352a8ad93 100644 (file)
@@ -64,10 +64,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(""));
 }
 
 
-void ParseFile(const std::string &Filename);
+void ParseFile(const std::string &Filename, const std::string & IncludeDir);
 
 RecordKeeper Records;
 
@@ -398,7 +402,7 @@ static void ParseMachineCode() {
 
 int main(int argc, char **argv) {
   cl::ParseCommandLineOptions(argc, argv);
-  ParseFile(InputFilename);
+  ParseFile(InputFilename, IncludeDir);
 
   std::ostream *Out = &std::cout;
   if (OutputFilename != "-") {
index 98370a7fef5d55b860954f027e2902b38ac75e77..f3cd32522aa751fc9e1c6fa733f2bd1b5c0e68fa 100644 (file)
 
 %{
 #include "Record.h"
+#include "Support/CommandLine.h"
 typedef std::pair<Record*, std::vector<Init*>*> SubClassRefTy;
 #include "FileParser.h"
 
+// Global variable recording the location of the include directory
+std::string IncludeDirectory;
+
 // ParseInt - This has to handle the special case of binary numbers 0b0101
 static int ParseInt(const char *Str) {
   if (Str[0] == '0' && Str[1] == 'b')
@@ -61,7 +65,18 @@ std::ostream &err() {
 
 int Fileparse();
 
-void ParseFile(const std::string &Filename) {
+//
+// Function: ParseFile()
+//
+// Description:
+//     This function begins the parsing of the specified tablegen file.
+//
+// Inputs:
+//     Filename - A string containing the name of the file to parse.
+//     IncludeDir - A string containing the directory from which include
+//                  files can be found.
+//
+void ParseFile(const std::string &Filename, const std::string & IncludeDir) {
   FILE *F = stdin;
   if (Filename != "-") {
     F = fopen(Filename.c_str(), "r");
@@ -75,6 +90,12 @@ void ParseFile(const std::string &Filename) {
     IncludeStack.push_back(IncludeRec("<stdin>", stdin));
   }
 
+  //
+  // Record the location of the include directory so that the lexer can find
+  // it later.
+  //
+  IncludeDirectory = IncludeDir;
   Filein = F;
   Filelineno = 1;
   Fileparse();
@@ -103,8 +124,20 @@ static void HandleInclude(const char *Buffer) {
   // Open the new input file...
   yyin = fopen(Filename.c_str(), "r");
   if (yyin == 0) {
-    err() << "Could not find include file '" << Filename << "'!\n";
-    abort();
+    //
+    // 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.
+    //
+    Filename = IncludeDirectory + "/" + Filename;
+    yyin = fopen(Filename.c_str(), "r");
+    if (yyin == 0) {
+      err() << "Could not find include file '" << Filename << "'!\n";
+      abort();
+    }
   }
 
   // Add the file to our include stack...
index 85a63ceaf6a16782d535ef9bc2f0c8535a9aa01f..67efdb46c857c59d31f1f220915506a352a8ad93 100644 (file)
@@ -64,10 +64,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(""));
 }
 
 
-void ParseFile(const std::string &Filename);
+void ParseFile(const std::string &Filename, const std::string & IncludeDir);
 
 RecordKeeper Records;
 
@@ -398,7 +402,7 @@ static void ParseMachineCode() {
 
 int main(int argc, char **argv) {
   cl::ParseCommandLineOptions(argc, argv);
-  ParseFile(InputFilename);
+  ParseFile(InputFilename, IncludeDir);
 
   std::ostream *Out = &std::cout;
   if (OutputFilename != "-") {