diff options
-rw-r--r-- | support/tools/TableGen/FileParser.y | 14 | ||||
-rw-r--r-- | support/tools/TableGen/TableGen.cpp | 13 | ||||
-rw-r--r-- | utils/TableGen/FileParser.y | 14 | ||||
-rw-r--r-- | utils/TableGen/TableGen.cpp | 13 |
4 files changed, 42 insertions, 12 deletions
diff --git a/support/tools/TableGen/FileParser.y b/support/tools/TableGen/FileParser.y index 55938f47ea..b82569ab74 100644 --- a/support/tools/TableGen/FileParser.y +++ b/support/tools/TableGen/FileParser.y @@ -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; } diff --git a/support/tools/TableGen/TableGen.cpp b/support/tools/TableGen/TableGen.cpp index 17f2b2e718..70d2ef9b18 100644 --- a/support/tools/TableGen/TableGen.cpp +++ b/support/tools/TableGen/TableGen.cpp @@ -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 != "-") { diff --git a/utils/TableGen/FileParser.y b/utils/TableGen/FileParser.y index 55938f47ea..b82569ab74 100644 --- a/utils/TableGen/FileParser.y +++ b/utils/TableGen/FileParser.y @@ -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; } diff --git a/utils/TableGen/TableGen.cpp b/utils/TableGen/TableGen.cpp index 17f2b2e718..70d2ef9b18 100644 --- a/utils/TableGen/TableGen.cpp +++ b/utils/TableGen/TableGen.cpp @@ -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 != "-") { |