diff options
author | Chris Lattner <sabre@nondot.org> | 2007-11-22 20:49:04 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-11-22 20:49:04 +0000 |
commit | f4127dd48e11297ed3c545bb6ee6a70bf91388c7 (patch) | |
tree | 673ba0b198b7f69a66e800762e449eb28d4740d8 /llvm/utils/TableGen/TableGen.cpp | |
parent | a89a113a2047a4c355b1ed65665afd3b592b2d18 (diff) | |
download | bcm5719-llvm-f4127dd48e11297ed3c545bb6ee6a70bf91388c7.tar.gz bcm5719-llvm-f4127dd48e11297ed3c545bb6ee6a70bf91388c7.zip |
Rewrite the tblgen parser in a recursive descent style, eliminating the bison parser.
This makes the parser much easier to understand, eliminates a ton of global variables,
and gives tblgen nice caret diagnostics. It is also faster, but tblgen probably doesn't
care about performance.
There are a couple of FIXMEs which I will take care of next.
llvm-svn: 44274
Diffstat (limited to 'llvm/utils/TableGen/TableGen.cpp')
-rw-r--r-- | llvm/utils/TableGen/TableGen.cpp | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/llvm/utils/TableGen/TableGen.cpp b/llvm/utils/TableGen/TableGen.cpp index d3d241e6c70..f4ece12897e 100644 --- a/llvm/utils/TableGen/TableGen.cpp +++ b/llvm/utils/TableGen/TableGen.cpp @@ -16,10 +16,12 @@ //===----------------------------------------------------------------------===// #include "Record.h" +#include "TGParser.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Streams.h" #include "llvm/System/Signals.h" #include "llvm/Support/FileUtilities.h" +#include "llvm/Support/MemoryBuffer.h" #include "CallingConvEmitter.h" #include "CodeEmitterGen.h" #include "RegisterInfoEmitter.h" @@ -93,16 +95,35 @@ namespace { cl::value_desc("directory"), cl::Prefix); } -namespace llvm { - void ParseFile(const std::string &Filename, - const std::vector<std::string> &IncludeDirs); -} - RecordKeeper llvm::Records; +/// ParseFile - this function begins the parsing of the specified tablegen +/// file. +static bool ParseFile(const std::string &Filename, + const std::vector<std::string> &IncludeDirs) { + std::string ErrorStr; + MemoryBuffer *F = MemoryBuffer::getFileOrSTDIN(&Filename[0], Filename.size(), + &ErrorStr); + if (F == 0) { + cerr << "Could not open input file '" + Filename + "': " << ErrorStr <<"\n"; + return true; + } + + TGParser Parser(F); + + // Record the location of the include directory so that the lexer can find + // it later. + Parser.setIncludeDirs(IncludeDirs); + + return Parser.ParseFile(); +} + int main(int argc, char **argv) { cl::ParseCommandLineOptions(argc, argv); - ParseFile(InputFilename, IncludeDirs); + + // Parse the input file. + if (ParseFile(InputFilename, IncludeDirs)) + return 1; std::ostream *Out = cout.stream(); if (OutputFilename != "-") { |