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 | f460165a4c1bf4bc762f9b3f12b9ed284b89cc99 (patch) | |
tree | 682aa3de3d166b50c3025180826f14903bbd5e1e /utils/TableGen/TableGen.cpp | |
parent | ed4a2f168873527e1737deaa7a0c6c045a2cff7d (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44274 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/TableGen.cpp')
-rw-r--r-- | utils/TableGen/TableGen.cpp | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/utils/TableGen/TableGen.cpp b/utils/TableGen/TableGen.cpp index d3d241e6c7..f4ece12897 100644 --- a/utils/TableGen/TableGen.cpp +++ b/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 != "-") { |