| //===- 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); |
| } |