Make tablegen take an input filename to parse if one is specified, otherwise
authorChris Lattner <sabre@nondot.org>
Wed, 30 Jul 2003 19:48:02 +0000 (19:48 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 30 Jul 2003 19:48:02 +0000 (19:48 +0000)
use stdin.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7431 91177308-0d34-0410-b5e6-96231b3b80d8

support/tools/TableGen/FileParser.y
support/tools/TableGen/TableGen.cpp
utils/TableGen/FileParser.y
utils/TableGen/TableGen.cpp

index 55938f47ea7e4be7a322132b50fc475ae43326e1..b82569ab74207b87a1f1e22845b3f156d91c81c0 100644 (file)
@@ -24,12 +24,24 @@ typedef std::pair<Record*, std::vector<Init*>*> SubClassRefTy;
 static std::vector<std::pair<std::pair<std::string, std::vector<unsigned>*>,
                              Init*> > SetStack;
 
-void ParseFile() {
+void ParseFile(const std::string &Filename) {
   FILE *F = stdin;
+  if (Filename != "-") {
+    F = fopen(Filename.c_str(), "r");
+
+    if (F == 0) {
+      std::cerr << "Could not open input file '" + Filename + "'!\n";
+      abort();
+    }
+  }
+
 
   Filein = F;
   Filelineno = 1;
   Fileparse();
+
+  if (F != stdin)
+    fclose(F);
   Filein = stdin;
 }
 
index 17f2b2e7181600667299149ec0f71017dcd94bbc..70d2ef9b1808c47a99181d3e6d37e725447e0cb8 100644 (file)
@@ -29,13 +29,16 @@ namespace {
   Class("class", cl::desc("Print Enum list for this class"),
         cl::value_desc("class name"));
 
- cl::opt<std::string>
- OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"),
-                cl::init("-"));
+  cl::opt<std::string>
+  OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"),
+                 cl::init("-"));
+
+  cl::opt<std::string>
+  InputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-"));
 }
 
 
-void ParseFile();
+void ParseFile(const std::string &Filename);
 
 RecordKeeper Records;
 
@@ -379,7 +382,7 @@ static void ParseMachineCode() {
 
 int main(int argc, char **argv) {
   cl::ParseCommandLineOptions(argc, argv);
-  ParseFile();
+  ParseFile(InputFilename);
 
   std::ostream *Out = &std::cout;
   if (OutputFilename != "-") {
index 55938f47ea7e4be7a322132b50fc475ae43326e1..b82569ab74207b87a1f1e22845b3f156d91c81c0 100644 (file)
@@ -24,12 +24,24 @@ typedef std::pair<Record*, std::vector<Init*>*> SubClassRefTy;
 static std::vector<std::pair<std::pair<std::string, std::vector<unsigned>*>,
                              Init*> > SetStack;
 
-void ParseFile() {
+void ParseFile(const std::string &Filename) {
   FILE *F = stdin;
+  if (Filename != "-") {
+    F = fopen(Filename.c_str(), "r");
+
+    if (F == 0) {
+      std::cerr << "Could not open input file '" + Filename + "'!\n";
+      abort();
+    }
+  }
+
 
   Filein = F;
   Filelineno = 1;
   Fileparse();
+
+  if (F != stdin)
+    fclose(F);
   Filein = stdin;
 }
 
index 17f2b2e7181600667299149ec0f71017dcd94bbc..70d2ef9b1808c47a99181d3e6d37e725447e0cb8 100644 (file)
@@ -29,13 +29,16 @@ namespace {
   Class("class", cl::desc("Print Enum list for this class"),
         cl::value_desc("class name"));
 
- cl::opt<std::string>
- OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"),
-                cl::init("-"));
+  cl::opt<std::string>
+  OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"),
+                 cl::init("-"));
+
+  cl::opt<std::string>
+  InputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-"));
 }
 
 
-void ParseFile();
+void ParseFile(const std::string &Filename);
 
 RecordKeeper Records;
 
@@ -379,7 +382,7 @@ static void ParseMachineCode() {
 
 int main(int argc, char **argv) {
   cl::ParseCommandLineOptions(argc, argv);
-  ParseFile();
+  ParseFile(InputFilename);
 
   std::ostream *Out = &std::cout;
   if (OutputFilename != "-") {