blob: b2cf1072b9ad826af15e6b57deb779b676efef43 [file] [log] [blame]
Chris Lattner2e1f51b2004-08-01 05:59:33 +00001//===- AsmWriterEmitter.cpp - Generate an assembly writer -----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This tablegen backend is emits an assembly printer for the current target.
11// Note that this is currently fairly skeletal, but will grow over time.
12//
13//===----------------------------------------------------------------------===//
14
15#include "AsmWriterEmitter.h"
16#include "CodeGenTarget.h"
17#include <ostream>
18using namespace llvm;
19
20void AsmWriterEmitter::run(std::ostream &O) {
21 EmitSourceFileHeader("Assembly Writer Source Fragment", O);
22
23 CodeGenTarget Target;
24 O <<
25 "/// printInstruction - This method is automatically generated by tablegen\n"
26 "/// from the instruction set description. This method returns true if the\n"
27 "/// machine instruction was sufficiently described to print it, otherwise\n"
28 "/// it returns false.\n"
29 "bool " << Target.getName()
30 << "AsmPrinter::printInstruction(const MachineInstr *MI) {\n";
31 O << " switch (MI->getOpcode()) {\n"
32 " default: return false;\n";
33
34 std::string Namespace = Target.inst_begin()->second.Namespace;
35
36 for (CodeGenTarget::inst_iterator I = Target.inst_begin(),
37 E = Target.inst_end(); I != E; ++I)
38 if (!I->second.AsmString.empty()) {
39 const std::string &AsmString = I->second.AsmString;
40 O << " case " << Namespace << "::" << I->first << ": O << \""
41 << AsmString << "\" << '\\n'; break;\n";
42 }
43
44 O << " }\n"
45 " return true;\n"
46 "}\n";
47 EmitSourceFileTail(O);
48}