Initial cut at an asm writer emitter.  So far, this only handles emission of
instructions, and only instructions that take no operands at that!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15386 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/utils/TableGen/AsmWriterEmitter.cpp b/utils/TableGen/AsmWriterEmitter.cpp
new file mode 100644
index 0000000..b2cf107
--- /dev/null
+++ b/utils/TableGen/AsmWriterEmitter.cpp
@@ -0,0 +1,48 @@
+//===- AsmWriterEmitter.cpp - Generate an assembly writer -----------------===//
+// 
+//                     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 tablegen backend is emits an assembly printer for the current target.
+// Note that this is currently fairly skeletal, but will grow over time.
+//
+//===----------------------------------------------------------------------===//
+
+#include "AsmWriterEmitter.h"
+#include "CodeGenTarget.h"
+#include <ostream>
+using namespace llvm;
+
+void AsmWriterEmitter::run(std::ostream &O) {
+  EmitSourceFileHeader("Assembly Writer Source Fragment", O);
+
+  CodeGenTarget Target;
+  O <<
+  "/// printInstruction - This method is automatically generated by tablegen\n"
+  "/// from the instruction set description.  This method returns true if the\n"
+  "/// machine instruction was sufficiently described to print it, otherwise\n"
+  "/// it returns false.\n"
+    "bool " << Target.getName()
+            << "AsmPrinter::printInstruction(const MachineInstr *MI) {\n";
+  O << "  switch (MI->getOpcode()) {\n"
+       "  default: return false;\n";
+
+  std::string Namespace = Target.inst_begin()->second.Namespace;
+
+  for (CodeGenTarget::inst_iterator I = Target.inst_begin(),
+         E = Target.inst_end(); I != E; ++I)
+    if (!I->second.AsmString.empty()) {
+      const std::string &AsmString = I->second.AsmString;
+      O << "  case " << Namespace << "::" << I->first << ": O << \""
+        << AsmString << "\" << '\\n'; break;\n";
+    }
+
+  O << "  }\n"
+       "  return true;\n"
+       "}\n";
+  EmitSourceFileTail(O);
+}