Fix typo in error message.
[oota-llvm.git] / utils / TableGen / TableGen.cpp
index d3d241e6c701b0bc6bdb3658340e60e34d89e261..c6692f805bacef30d16b40199e8092542db3c09b 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 "FastISelEmitter.h"
 #include "SubtargetEmitter.h"
 #include "IntrinsicEmitter.h"
+#include "LLVMCConfigurationEmitter.h"
 #include <algorithm>
 #include <cstdio>
 #include <fstream>
@@ -38,11 +43,13 @@ enum ActionType {
   PrintRecords,
   GenEmitter,
   GenRegisterEnums, GenRegister, GenRegisterHeader,
-  GenInstrEnums, GenInstrs, GenAsmWriter, 
+  GenInstrEnums, GenInstrs, GenAsmWriter,
   GenCallingConv,
   GenDAGISel,
+  GenFastISel,
   GenSubtarget,
   GenIntrinsic,
+  GenLLVMCConf,
   PrintEnums
 };
 
@@ -69,10 +76,14 @@ namespace {
                                "Generate assembly writer"),
                     clEnumValN(GenDAGISel, "gen-dag-isel",
                                "Generate a DAG instruction selector"),
+                    clEnumValN(GenFastISel, "gen-fast-isel",
+                               "Generate a \"fast\" instruction selector"),
                     clEnumValN(GenSubtarget, "gen-subtarget",
                                "Generate subtarget enumerations"),
                     clEnumValN(GenIntrinsic, "gen-intrinsic",
                                "Generate intrinsic information"),
+                    clEnumValN(GenLLVMCConf, "gen-llvmc",
+                               "Generate LLVMC configuration library"),
                     clEnumValN(PrintEnums, "print-enums",
                                "Print enum values for a class"),
                     clEnumValEnd));
@@ -93,16 +104,34 @@ 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.c_str(), &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 +166,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);
@@ -152,12 +181,18 @@ int main(int argc, char **argv) {
     case GenDAGISel:
       DAGISelEmitter(Records).run(*Out);
       break;
+    case GenFastISel:
+      FastISelEmitter(Records).run(*Out);
+      break;
     case GenSubtarget:
       SubtargetEmitter(Records).run(*Out);
       break;
     case GenIntrinsic:
       IntrinsicEmitter(Records).run(*Out);
       break;
+    case GenLLVMCConf:
+      LLVMCConfigurationEmitter(Records).run(*Out);
+      break;
     case PrintEnums:
     {
       std::vector<Record*> Recs = Records.getAllDerivedDefinitions(Class);
@@ -177,6 +212,13 @@ int main(int argc, char **argv) {
       std::remove(OutputFilename.c_str());    // Remove the file, it's broken
     }
     return 1;
+  } catch (const char *Error) {
+    cerr << argv[0] << ": " << Error << "\n";
+    if (Out != cout.stream()) {
+      delete Out;                             // Close the file
+      std::remove(OutputFilename.c_str());    // Remove the file, it's broken
+    }
+    return 1;
   } catch (...) {
     cerr << argv[0] << ": Unknown unexpected exception occurred.\n";
     if (Out != cout.stream()) {