summaryrefslogtreecommitdiff
path: root/utils/TableGen/AsmWriterEmitter.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-08-01 05:59:33 +0000
committerChris Lattner <sabre@nondot.org>2004-08-01 05:59:33 +0000
commit2e1f51b8a583649d74cb666ca5e4cf680cc1ced9 (patch)
tree9d3918655c2d43639de8e63e519beb837528ba00 /utils/TableGen/AsmWriterEmitter.cpp
parentec3524064c57fbc2c5976ca301bbaadc94006d07 (diff)
downloadllvm-2e1f51b8a583649d74cb666ca5e4cf680cc1ced9.tar.gz
llvm-2e1f51b8a583649d74cb666ca5e4cf680cc1ced9.tar.bz2
llvm-2e1f51b8a583649d74cb666ca5e4cf680cc1ced9.tar.xz
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
Diffstat (limited to 'utils/TableGen/AsmWriterEmitter.cpp')
-rw-r--r--utils/TableGen/AsmWriterEmitter.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/utils/TableGen/AsmWriterEmitter.cpp b/utils/TableGen/AsmWriterEmitter.cpp
new file mode 100644
index 0000000000..b2cf1072b9
--- /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);
+}