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
diff --git a/utils/TableGen/TableGen.cpp b/utils/TableGen/TableGen.cpp
index d3d241e..f4ece12 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 @@
               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 != "-") {