Dwarf requires variable entries to be in the source order. Right now, since we are...
[oota-llvm.git] / utils / TableGen / TableGen.cpp
index d3d241e6c701b0bc6bdb3658340e60e34d89e261..b174ff89031a65677c8791db3f9a80079286bc77 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
 //===----------------------------------------------------------------------===//
 
 #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"
 #include "InstrInfoEmitter.h"
+#include "InstrEnumEmitter.h"
 #include "AsmWriterEmitter.h"
 #include "DAGISelEmitter.h"
 #include "SubtargetEmitter.h"
@@ -93,16 +96,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 != "-") {
@@ -137,7 +159,7 @@ int main(int argc, char **argv) {
       break;
 
     case GenInstrEnums:
-      InstrInfoEmitter(Records).runEnums(*Out);
+      InstrEnumEmitter(Records).run(*Out);
       break;
     case GenInstrs:
       InstrInfoEmitter(Records).run(*Out);