aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-07-30 19:48:02 +0000
committerChris Lattner <sabre@nondot.org>2003-07-30 19:48:02 +0000
commit90523906fa31c8f4e156dc7ef4a433a50d4b706d (patch)
tree87e30faa14fcfd36792a0c53aff7a0de5ddd7ab4 /utils
parent35c7444e52efaeae5d9cc1024350edb25dae5447 (diff)
downloadexternal_llvm-90523906fa31c8f4e156dc7ef4a433a50d4b706d.zip
external_llvm-90523906fa31c8f4e156dc7ef4a433a50d4b706d.tar.gz
external_llvm-90523906fa31c8f4e156dc7ef4a433a50d4b706d.tar.bz2
Make tablegen take an input filename to parse if one is specified, otherwise
use stdin. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7431 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r--utils/TableGen/FileParser.y14
-rw-r--r--utils/TableGen/TableGen.cpp13
2 files changed, 21 insertions, 6 deletions
diff --git a/utils/TableGen/FileParser.y b/utils/TableGen/FileParser.y
index 55938f4..b82569a 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 17f2b2e..70d2ef9 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 != "-") {