blob: d1cb7022d06d070acec843bca13334ef697013f1 [file] [log] [blame]
Chris Lattner2e1f51b2004-08-01 05:59:33 +00001//===- AsmWriterEmitter.cpp - Generate an assembly writer -----------------===//
Misha Brukman3da94ae2005-04-22 00:00:37 +00002//
Chris Lattner2e1f51b2004-08-01 05:59:33 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner30609102007-12-29 20:37:13 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman3da94ae2005-04-22 00:00:37 +00007//
Chris Lattner2e1f51b2004-08-01 05:59:33 +00008//===----------------------------------------------------------------------===//
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"
Chris Lattner175580c2004-08-14 22:50:53 +000017#include "Record.h"
Chris Lattner6af022f2006-07-14 22:59:11 +000018#include "llvm/ADT/StringExtras.h"
Chris Lattnerbdff5f92006-07-18 17:18:03 +000019#include "llvm/Support/Debug.h"
20#include "llvm/Support/MathExtras.h"
Jeff Cohen615ed992005-01-22 18:50:10 +000021#include <algorithm>
Daniel Dunbar1a551802009-07-03 00:10:29 +000022#include <iostream>
Chris Lattner2e1f51b2004-08-01 05:59:33 +000023using namespace llvm;
24
Chris Lattner076efa72004-08-01 07:43:02 +000025static bool isIdentChar(char C) {
26 return (C >= 'a' && C <= 'z') ||
27 (C >= 'A' && C <= 'Z') ||
28 (C >= '0' && C <= '9') ||
29 C == '_';
30}
31
Chris Lattnerad8c5312007-07-18 04:51:57 +000032// This should be an anon namespace, this works around a GCC warning.
33namespace llvm {
Chris Lattnerb0b55e72005-01-22 17:32:42 +000034 struct AsmWriterOperand {
Evan Cheng3837b642009-07-18 01:43:53 +000035 enum { isLiteralTextOperand, isMachineInstrOperand } OperandType;
Chris Lattnerb0b55e72005-01-22 17:32:42 +000036
37 /// Str - For isLiteralTextOperand, this IS the literal text. For
38 /// isMachineInstrOperand, this is the PrinterMethodName for the operand.
39 std::string Str;
40
41 /// MiOpNo - For isMachineInstrOperand, this is the operand number of the
42 /// machine instruction.
43 unsigned MIOpNo;
Chris Lattner04cadb32006-02-06 23:40:48 +000044
45 /// MiModifier - For isMachineInstrOperand, this is the modifier string for
46 /// an operand, specified with syntax like ${opname:modifier}.
47 std::string MiModifier;
Chris Lattnerb0b55e72005-01-22 17:32:42 +000048
Cedric Venet7caa2d02008-10-27 19:21:35 +000049 // To make VS STL happy
Evan Cheng3837b642009-07-18 01:43:53 +000050 AsmWriterOperand():OperandType(isLiteralTextOperand) {}
Cedric Venet3bff2df2008-10-26 15:40:44 +000051
Evan Cheng3837b642009-07-18 01:43:53 +000052 explicit AsmWriterOperand(const std::string &LitStr)
53 : OperandType(isLiteralTextOperand), Str(LitStr) {}
Chris Lattnerb0b55e72005-01-22 17:32:42 +000054
Chris Lattner04cadb32006-02-06 23:40:48 +000055 AsmWriterOperand(const std::string &Printer, unsigned OpNo,
Evan Cheng3837b642009-07-18 01:43:53 +000056 const std::string &Modifier)
57 : OperandType(isMachineInstrOperand), Str(Printer), MIOpNo(OpNo),
Chris Lattner04cadb32006-02-06 23:40:48 +000058 MiModifier(Modifier) {}
Chris Lattnerb0b55e72005-01-22 17:32:42 +000059
Chris Lattner870c0162005-01-22 18:38:13 +000060 bool operator!=(const AsmWriterOperand &Other) const {
61 if (OperandType != Other.OperandType || Str != Other.Str) return true;
62 if (OperandType == isMachineInstrOperand)
Chris Lattner04cadb32006-02-06 23:40:48 +000063 return MIOpNo != Other.MIOpNo || MiModifier != Other.MiModifier;
Chris Lattner870c0162005-01-22 18:38:13 +000064 return false;
65 }
Chris Lattner38c07512005-01-22 20:31:17 +000066 bool operator==(const AsmWriterOperand &Other) const {
67 return !operator!=(Other);
68 }
Chris Lattnerbdff5f92006-07-18 17:18:03 +000069
70 /// getCode - Return the code that prints this operand.
71 std::string getCode() const;
Chris Lattnerb0b55e72005-01-22 17:32:42 +000072 };
Chris Lattnerbdff5f92006-07-18 17:18:03 +000073}
Chris Lattnerb0b55e72005-01-22 17:32:42 +000074
Chris Lattnerbdff5f92006-07-18 17:18:03 +000075namespace llvm {
Jeff Cohend41b30d2006-11-05 19:31:28 +000076 class AsmWriterInst {
77 public:
Chris Lattnerb0b55e72005-01-22 17:32:42 +000078 std::vector<AsmWriterOperand> Operands;
Chris Lattner5765dba2005-01-22 17:40:38 +000079 const CodeGenInstruction *CGI;
Misha Brukman3da94ae2005-04-22 00:00:37 +000080
Chris Lattner5765dba2005-01-22 17:40:38 +000081 AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant);
Chris Lattner870c0162005-01-22 18:38:13 +000082
Chris Lattnerf8766682005-01-22 19:22:23 +000083 /// MatchesAllButOneOp - If this instruction is exactly identical to the
84 /// specified instruction except for one differing operand, return the
85 /// differing operand number. Otherwise return ~0.
86 unsigned MatchesAllButOneOp(const AsmWriterInst &Other) const;
Chris Lattner870c0162005-01-22 18:38:13 +000087
Chris Lattnerb0b55e72005-01-22 17:32:42 +000088 private:
89 void AddLiteralString(const std::string &Str) {
90 // If the last operand was already a literal text string, append this to
91 // it, otherwise add a new operand.
92 if (!Operands.empty() &&
93 Operands.back().OperandType == AsmWriterOperand::isLiteralTextOperand)
94 Operands.back().Str.append(Str);
95 else
96 Operands.push_back(AsmWriterOperand(Str));
97 }
98 };
99}
100
101
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000102std::string AsmWriterOperand::getCode() const {
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000103 if (OperandType == isLiteralTextOperand)
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000104 return "O << \"" + Str + "\"; ";
105
Chris Lattner1bf63612006-09-26 23:45:08 +0000106 std::string Result = Str + "(MI";
107 if (MIOpNo != ~0U)
108 Result += ", " + utostr(MIOpNo);
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000109 if (!MiModifier.empty())
110 Result += ", \"" + MiModifier + '"';
111 return Result + "); ";
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000112}
113
114
115/// ParseAsmString - Parse the specified Instruction's AsmString into this
116/// AsmWriterInst.
117///
Evan Cheng3837b642009-07-18 01:43:53 +0000118AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant) {
Chris Lattner5765dba2005-01-22 17:40:38 +0000119 this->CGI = &CGI;
Chris Lattnerb03b0802006-02-06 22:43:28 +0000120 unsigned CurVariant = ~0U; // ~0 if we are outside a {.|.|.} region, other #.
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000121
Chris Lattner1cf9d962006-02-01 19:12:23 +0000122 // NOTE: Any extensions to this code need to be mirrored in the
123 // AsmPrinter::printInlineAsm code that executes as compile time (assuming
124 // that inline asm strings should also get the new feature)!
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000125 const std::string &AsmString = CGI.AsmString;
126 std::string::size_type LastEmitted = 0;
127 while (LastEmitted != AsmString.size()) {
128 std::string::size_type DollarPos =
Nate Begeman817affc2008-03-17 07:26:14 +0000129 AsmString.find_first_of("${|}\\", LastEmitted);
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000130 if (DollarPos == std::string::npos) DollarPos = AsmString.size();
131
132 // Emit a constant string fragment.
133 if (DollarPos != LastEmitted) {
Chris Lattner7f3b28a2009-03-13 21:33:17 +0000134 if (CurVariant == Variant || CurVariant == ~0U) {
135 for (; LastEmitted != DollarPos; ++LastEmitted)
136 switch (AsmString[LastEmitted]) {
137 case '\n': AddLiteralString("\\n"); break;
138 case '\t': AddLiteralString("\\t"); break;
139 case '"': AddLiteralString("\\\""); break;
140 case '\\': AddLiteralString("\\\\"); break;
141 default:
142 AddLiteralString(std::string(1, AsmString[LastEmitted]));
143 break;
144 }
145 } else {
146 LastEmitted = DollarPos;
147 }
Nate Begeman817affc2008-03-17 07:26:14 +0000148 } else if (AsmString[DollarPos] == '\\') {
149 if (DollarPos+1 != AsmString.size() &&
150 (CurVariant == Variant || CurVariant == ~0U)) {
151 if (AsmString[DollarPos+1] == 'n') {
152 AddLiteralString("\\n");
153 } else if (AsmString[DollarPos+1] == 't') {
154 AddLiteralString("\\t");
155 } else if (std::string("${|}\\").find(AsmString[DollarPos+1])
156 != std::string::npos) {
157 AddLiteralString(std::string(1, AsmString[DollarPos+1]));
158 } else {
159 throw "Non-supported escaped character found in instruction '" +
160 CGI.TheDef->getName() + "'!";
161 }
162 LastEmitted = DollarPos+2;
163 continue;
164 }
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000165 } else if (AsmString[DollarPos] == '{') {
Chris Lattnerb03b0802006-02-06 22:43:28 +0000166 if (CurVariant != ~0U)
Jeff Cohen00b168892005-07-27 06:12:32 +0000167 throw "Nested variants found for instruction '" +
Chris Lattner3e3def92005-07-15 22:43:04 +0000168 CGI.TheDef->getName() + "'!";
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000169 LastEmitted = DollarPos+1;
Chris Lattnerb03b0802006-02-06 22:43:28 +0000170 CurVariant = 0; // We are now inside of the variant!
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000171 } else if (AsmString[DollarPos] == '|') {
Chris Lattnerb03b0802006-02-06 22:43:28 +0000172 if (CurVariant == ~0U)
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000173 throw "'|' character found outside of a variant in instruction '"
Chris Lattner3e3def92005-07-15 22:43:04 +0000174 + CGI.TheDef->getName() + "'!";
Chris Lattnerb03b0802006-02-06 22:43:28 +0000175 ++CurVariant;
176 ++LastEmitted;
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000177 } else if (AsmString[DollarPos] == '}') {
Chris Lattnerb03b0802006-02-06 22:43:28 +0000178 if (CurVariant == ~0U)
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000179 throw "'}' character found outside of a variant in instruction '"
Chris Lattner3e3def92005-07-15 22:43:04 +0000180 + CGI.TheDef->getName() + "'!";
Chris Lattnerb03b0802006-02-06 22:43:28 +0000181 ++LastEmitted;
182 CurVariant = ~0U;
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000183 } else if (DollarPos+1 != AsmString.size() &&
184 AsmString[DollarPos+1] == '$') {
Chris Lattnerb03b0802006-02-06 22:43:28 +0000185 if (CurVariant == Variant || CurVariant == ~0U)
186 AddLiteralString("$"); // "$$" -> $
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000187 LastEmitted = DollarPos+2;
188 } else {
189 // Get the name of the variable.
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000190 std::string::size_type VarEnd = DollarPos+1;
Nate Begemanafc54562005-07-14 22:50:30 +0000191
192 // handle ${foo}bar as $foo by detecting whether the character following
193 // the dollar sign is a curly brace. If so, advance VarEnd and DollarPos
194 // so the variable name does not contain the leading curly brace.
195 bool hasCurlyBraces = false;
196 if (VarEnd < AsmString.size() && '{' == AsmString[VarEnd]) {
197 hasCurlyBraces = true;
198 ++DollarPos;
199 ++VarEnd;
200 }
201
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000202 while (VarEnd < AsmString.size() && isIdentChar(AsmString[VarEnd]))
203 ++VarEnd;
204 std::string VarName(AsmString.begin()+DollarPos+1,
205 AsmString.begin()+VarEnd);
Nate Begemanafc54562005-07-14 22:50:30 +0000206
Chris Lattner04cadb32006-02-06 23:40:48 +0000207 // Modifier - Support ${foo:modifier} syntax, where "modifier" is passed
Chris Lattner1bf63612006-09-26 23:45:08 +0000208 // into printOperand. Also support ${:feature}, which is passed into
Chris Lattner16f046a2006-09-26 23:47:10 +0000209 // PrintSpecial.
Chris Lattner04cadb32006-02-06 23:40:48 +0000210 std::string Modifier;
211
Nate Begemanafc54562005-07-14 22:50:30 +0000212 // In order to avoid starting the next string at the terminating curly
213 // brace, advance the end position past it if we found an opening curly
214 // brace.
215 if (hasCurlyBraces) {
216 if (VarEnd >= AsmString.size())
217 throw "Reached end of string before terminating curly brace in '"
Chris Lattner3e3def92005-07-15 22:43:04 +0000218 + CGI.TheDef->getName() + "'";
Chris Lattner04cadb32006-02-06 23:40:48 +0000219
220 // Look for a modifier string.
221 if (AsmString[VarEnd] == ':') {
222 ++VarEnd;
223 if (VarEnd >= AsmString.size())
224 throw "Reached end of string before terminating curly brace in '"
225 + CGI.TheDef->getName() + "'";
226
227 unsigned ModifierStart = VarEnd;
228 while (VarEnd < AsmString.size() && isIdentChar(AsmString[VarEnd]))
229 ++VarEnd;
230 Modifier = std::string(AsmString.begin()+ModifierStart,
231 AsmString.begin()+VarEnd);
232 if (Modifier.empty())
233 throw "Bad operand modifier name in '"+ CGI.TheDef->getName() + "'";
234 }
235
Nate Begemanafc54562005-07-14 22:50:30 +0000236 if (AsmString[VarEnd] != '}')
Chris Lattnerb03b0802006-02-06 22:43:28 +0000237 throw "Variable name beginning with '{' did not end with '}' in '"
Chris Lattner3e3def92005-07-15 22:43:04 +0000238 + CGI.TheDef->getName() + "'";
Nate Begemanafc54562005-07-14 22:50:30 +0000239 ++VarEnd;
240 }
Chris Lattner1bf63612006-09-26 23:45:08 +0000241 if (VarName.empty() && Modifier.empty())
Jeff Cohen00b168892005-07-27 06:12:32 +0000242 throw "Stray '$' in '" + CGI.TheDef->getName() +
Chris Lattner3e3def92005-07-15 22:43:04 +0000243 "' asm string, maybe you want $$?";
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000244
Chris Lattner1bf63612006-09-26 23:45:08 +0000245 if (VarName.empty()) {
Chris Lattner16f046a2006-09-26 23:47:10 +0000246 // Just a modifier, pass this into PrintSpecial.
247 Operands.push_back(AsmWriterOperand("PrintSpecial", ~0U, Modifier));
Chris Lattner1bf63612006-09-26 23:45:08 +0000248 } else {
249 // Otherwise, normal operand.
250 unsigned OpNo = CGI.getOperandNamed(VarName);
251 CodeGenInstruction::OperandInfo OpInfo = CGI.OperandList[OpNo];
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000252
Chris Lattnerf64f9a42006-11-15 23:23:02 +0000253 if (CurVariant == Variant || CurVariant == ~0U) {
254 unsigned MIOp = OpInfo.MIOperandNo;
Chris Lattner1bf63612006-09-26 23:45:08 +0000255 Operands.push_back(AsmWriterOperand(OpInfo.PrinterMethodName, MIOp,
256 Modifier));
Chris Lattnerf64f9a42006-11-15 23:23:02 +0000257 }
Chris Lattner1bf63612006-09-26 23:45:08 +0000258 }
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000259 LastEmitted = VarEnd;
260 }
261 }
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000262}
263
Chris Lattnerf8766682005-01-22 19:22:23 +0000264/// MatchesAllButOneOp - If this instruction is exactly identical to the
265/// specified instruction except for one differing operand, return the differing
266/// operand number. If more than one operand mismatches, return ~1, otherwise
267/// if the instructions are identical return ~0.
268unsigned AsmWriterInst::MatchesAllButOneOp(const AsmWriterInst &Other)const{
269 if (Operands.size() != Other.Operands.size()) return ~1;
Chris Lattner870c0162005-01-22 18:38:13 +0000270
271 unsigned MismatchOperand = ~0U;
272 for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
Anton Korobeynikovae9f3a32008-02-20 11:08:44 +0000273 if (Operands[i] != Other.Operands[i]) {
Chris Lattnerf8766682005-01-22 19:22:23 +0000274 if (MismatchOperand != ~0U) // Already have one mismatch?
275 return ~1U;
Misha Brukman3da94ae2005-04-22 00:00:37 +0000276 else
Chris Lattner870c0162005-01-22 18:38:13 +0000277 MismatchOperand = i;
Anton Korobeynikovae9f3a32008-02-20 11:08:44 +0000278 }
Chris Lattner870c0162005-01-22 18:38:13 +0000279 }
280 return MismatchOperand;
281}
282
Chris Lattner38c07512005-01-22 20:31:17 +0000283static void PrintCases(std::vector<std::pair<std::string,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000284 AsmWriterOperand> > &OpsToPrint, raw_ostream &O) {
Chris Lattner38c07512005-01-22 20:31:17 +0000285 O << " case " << OpsToPrint.back().first << ": ";
286 AsmWriterOperand TheOp = OpsToPrint.back().second;
287 OpsToPrint.pop_back();
288
289 // Check to see if any other operands are identical in this list, and if so,
290 // emit a case label for them.
291 for (unsigned i = OpsToPrint.size(); i != 0; --i)
292 if (OpsToPrint[i-1].second == TheOp) {
293 O << "\n case " << OpsToPrint[i-1].first << ": ";
294 OpsToPrint.erase(OpsToPrint.begin()+i-1);
295 }
296
297 // Finally, emit the code.
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000298 O << TheOp.getCode();
Chris Lattner38c07512005-01-22 20:31:17 +0000299 O << "break;\n";
300}
301
Chris Lattner870c0162005-01-22 18:38:13 +0000302
303/// EmitInstructions - Emit the last instruction in the vector and any other
304/// instructions that are suitably similar to it.
305static void EmitInstructions(std::vector<AsmWriterInst> &Insts,
Daniel Dunbar1a551802009-07-03 00:10:29 +0000306 raw_ostream &O) {
Chris Lattner870c0162005-01-22 18:38:13 +0000307 AsmWriterInst FirstInst = Insts.back();
308 Insts.pop_back();
309
310 std::vector<AsmWriterInst> SimilarInsts;
311 unsigned DifferingOperand = ~0;
312 for (unsigned i = Insts.size(); i != 0; --i) {
Chris Lattnerf8766682005-01-22 19:22:23 +0000313 unsigned DiffOp = Insts[i-1].MatchesAllButOneOp(FirstInst);
314 if (DiffOp != ~1U) {
Chris Lattner870c0162005-01-22 18:38:13 +0000315 if (DifferingOperand == ~0U) // First match!
316 DifferingOperand = DiffOp;
317
318 // If this differs in the same operand as the rest of the instructions in
319 // this class, move it to the SimilarInsts list.
Chris Lattnerf8766682005-01-22 19:22:23 +0000320 if (DifferingOperand == DiffOp || DiffOp == ~0U) {
Chris Lattner870c0162005-01-22 18:38:13 +0000321 SimilarInsts.push_back(Insts[i-1]);
322 Insts.erase(Insts.begin()+i-1);
323 }
324 }
325 }
326
Chris Lattnera1e8a802006-05-01 17:01:17 +0000327 O << " case " << FirstInst.CGI->Namespace << "::"
Chris Lattner870c0162005-01-22 18:38:13 +0000328 << FirstInst.CGI->TheDef->getName() << ":\n";
329 for (unsigned i = 0, e = SimilarInsts.size(); i != e; ++i)
Chris Lattnera1e8a802006-05-01 17:01:17 +0000330 O << " case " << SimilarInsts[i].CGI->Namespace << "::"
Chris Lattner870c0162005-01-22 18:38:13 +0000331 << SimilarInsts[i].CGI->TheDef->getName() << ":\n";
332 for (unsigned i = 0, e = FirstInst.Operands.size(); i != e; ++i) {
333 if (i != DifferingOperand) {
334 // If the operand is the same for all instructions, just print it.
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000335 O << " " << FirstInst.Operands[i].getCode();
Chris Lattner870c0162005-01-22 18:38:13 +0000336 } else {
337 // If this is the operand that varies between all of the instructions,
338 // emit a switch for just this operand now.
339 O << " switch (MI->getOpcode()) {\n";
Chris Lattner38c07512005-01-22 20:31:17 +0000340 std::vector<std::pair<std::string, AsmWriterOperand> > OpsToPrint;
Chris Lattnera1e8a802006-05-01 17:01:17 +0000341 OpsToPrint.push_back(std::make_pair(FirstInst.CGI->Namespace + "::" +
Chris Lattner38c07512005-01-22 20:31:17 +0000342 FirstInst.CGI->TheDef->getName(),
343 FirstInst.Operands[i]));
Misha Brukman3da94ae2005-04-22 00:00:37 +0000344
Chris Lattner870c0162005-01-22 18:38:13 +0000345 for (unsigned si = 0, e = SimilarInsts.size(); si != e; ++si) {
Chris Lattner38c07512005-01-22 20:31:17 +0000346 AsmWriterInst &AWI = SimilarInsts[si];
Chris Lattnera1e8a802006-05-01 17:01:17 +0000347 OpsToPrint.push_back(std::make_pair(AWI.CGI->Namespace+"::"+
Chris Lattner38c07512005-01-22 20:31:17 +0000348 AWI.CGI->TheDef->getName(),
349 AWI.Operands[i]));
Chris Lattner870c0162005-01-22 18:38:13 +0000350 }
Chris Lattner38c07512005-01-22 20:31:17 +0000351 std::reverse(OpsToPrint.begin(), OpsToPrint.end());
352 while (!OpsToPrint.empty())
353 PrintCases(OpsToPrint, O);
Chris Lattner870c0162005-01-22 18:38:13 +0000354 O << " }";
355 }
356 O << "\n";
357 }
Chris Lattner870c0162005-01-22 18:38:13 +0000358 O << " break;\n";
359}
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000360
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000361void AsmWriterEmitter::
362FindUniqueOperandCommands(std::vector<std::string> &UniqueOperandCommands,
Chris Lattner96c1ade2006-07-18 18:28:27 +0000363 std::vector<unsigned> &InstIdxs,
364 std::vector<unsigned> &InstOpsUsed) const {
Chris Lattner195bb4a2006-07-18 19:27:30 +0000365 InstIdxs.assign(NumberedInstructions.size(), ~0U);
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000366
367 // This vector parallels UniqueOperandCommands, keeping track of which
368 // instructions each case are used for. It is a comma separated string of
369 // enums.
370 std::vector<std::string> InstrsForCase;
371 InstrsForCase.resize(UniqueOperandCommands.size());
Chris Lattner96c1ade2006-07-18 18:28:27 +0000372 InstOpsUsed.assign(UniqueOperandCommands.size(), 0);
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000373
374 for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
375 const AsmWriterInst *Inst = getAsmWriterInstByID(i);
Dan Gohman44066042008-07-01 00:05:16 +0000376 if (Inst == 0) continue; // PHI, INLINEASM, DBG_LABEL, etc.
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000377
378 std::string Command;
Chris Lattnerb8462862006-07-18 17:56:07 +0000379 if (Inst->Operands.empty())
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000380 continue; // Instruction already done.
Chris Lattner191dd1f2006-07-18 17:50:22 +0000381
Chris Lattnerb8462862006-07-18 17:56:07 +0000382 Command = " " + Inst->Operands[0].getCode() + "\n";
Chris Lattner191dd1f2006-07-18 17:50:22 +0000383
384 // If this is the last operand, emit a return.
David Greene014700c2009-07-13 20:25:48 +0000385 if (Inst->Operands.size() == 1) {
David Greenefe7b16f2009-07-15 18:24:03 +0000386 Command += " EmitComments(*MI);\n";
David Greene014700c2009-07-13 20:25:48 +0000387 // Print the final newline
388 Command += " O << \"\\n\";\n";
Chris Lattner191dd1f2006-07-18 17:50:22 +0000389 Command += " return true;\n";
David Greene014700c2009-07-13 20:25:48 +0000390 }
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000391
392 // Check to see if we already have 'Command' in UniqueOperandCommands.
393 // If not, add it.
394 bool FoundIt = false;
395 for (unsigned idx = 0, e = UniqueOperandCommands.size(); idx != e; ++idx)
396 if (UniqueOperandCommands[idx] == Command) {
397 InstIdxs[i] = idx;
398 InstrsForCase[idx] += ", ";
399 InstrsForCase[idx] += Inst->CGI->TheDef->getName();
400 FoundIt = true;
401 break;
402 }
403 if (!FoundIt) {
404 InstIdxs[i] = UniqueOperandCommands.size();
405 UniqueOperandCommands.push_back(Command);
406 InstrsForCase.push_back(Inst->CGI->TheDef->getName());
Chris Lattner96c1ade2006-07-18 18:28:27 +0000407
408 // This command matches one operand so far.
409 InstOpsUsed.push_back(1);
410 }
411 }
412
413 // For each entry of UniqueOperandCommands, there is a set of instructions
414 // that uses it. If the next command of all instructions in the set are
415 // identical, fold it into the command.
416 for (unsigned CommandIdx = 0, e = UniqueOperandCommands.size();
417 CommandIdx != e; ++CommandIdx) {
418
419 for (unsigned Op = 1; ; ++Op) {
420 // Scan for the first instruction in the set.
421 std::vector<unsigned>::iterator NIT =
422 std::find(InstIdxs.begin(), InstIdxs.end(), CommandIdx);
423 if (NIT == InstIdxs.end()) break; // No commonality.
424
425 // If this instruction has no more operands, we isn't anything to merge
426 // into this command.
427 const AsmWriterInst *FirstInst =
428 getAsmWriterInstByID(NIT-InstIdxs.begin());
429 if (!FirstInst || FirstInst->Operands.size() == Op)
430 break;
431
432 // Otherwise, scan to see if all of the other instructions in this command
433 // set share the operand.
434 bool AllSame = true;
435
Chris Lattner96c1ade2006-07-18 18:28:27 +0000436 for (NIT = std::find(NIT+1, InstIdxs.end(), CommandIdx);
437 NIT != InstIdxs.end();
438 NIT = std::find(NIT+1, InstIdxs.end(), CommandIdx)) {
439 // Okay, found another instruction in this command set. If the operand
440 // matches, we're ok, otherwise bail out.
441 const AsmWriterInst *OtherInst =
442 getAsmWriterInstByID(NIT-InstIdxs.begin());
443 if (!OtherInst || OtherInst->Operands.size() == Op ||
444 OtherInst->Operands[Op] != FirstInst->Operands[Op]) {
445 AllSame = false;
446 break;
447 }
448 }
449 if (!AllSame) break;
450
451 // Okay, everything in this command set has the same next operand. Add it
452 // to UniqueOperandCommands and remember that it was consumed.
453 std::string Command = " " + FirstInst->Operands[Op].getCode() + "\n";
454
455 // If this is the last operand, emit a return after the code.
David Greene014700c2009-07-13 20:25:48 +0000456 if (FirstInst->Operands.size() == Op+1) {
David Greenefe7b16f2009-07-15 18:24:03 +0000457 Command += " EmitComments(*MI);\n";
David Greene014700c2009-07-13 20:25:48 +0000458 // Print the final newline
459 Command += " O << \"\\n\";\n";
Chris Lattner96c1ade2006-07-18 18:28:27 +0000460 Command += " return true;\n";
David Greene014700c2009-07-13 20:25:48 +0000461 }
Chris Lattner96c1ade2006-07-18 18:28:27 +0000462
463 UniqueOperandCommands[CommandIdx] += Command;
464 InstOpsUsed[CommandIdx]++;
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000465 }
466 }
467
468 // Prepend some of the instructions each case is used for onto the case val.
469 for (unsigned i = 0, e = InstrsForCase.size(); i != e; ++i) {
470 std::string Instrs = InstrsForCase[i];
471 if (Instrs.size() > 70) {
472 Instrs.erase(Instrs.begin()+70, Instrs.end());
473 Instrs += "...";
474 }
475
476 if (!Instrs.empty())
477 UniqueOperandCommands[i] = " // " + Instrs + "\n" +
478 UniqueOperandCommands[i];
479 }
480}
481
482
483
Daniel Dunbar1a551802009-07-03 00:10:29 +0000484void AsmWriterEmitter::run(raw_ostream &O) {
Chris Lattner2e1f51b2004-08-01 05:59:33 +0000485 EmitSourceFileHeader("Assembly Writer Source Fragment", O);
486
487 CodeGenTarget Target;
Chris Lattner175580c2004-08-14 22:50:53 +0000488 Record *AsmWriter = Target.getAsmWriter();
Chris Lattner953c6fe2004-10-03 20:19:02 +0000489 std::string ClassName = AsmWriter->getValueAsString("AsmWriterClassName");
490 unsigned Variant = AsmWriter->getValueAsInt("Variant");
Chris Lattner175580c2004-08-14 22:50:53 +0000491
Chris Lattner2e1f51b2004-08-01 05:59:33 +0000492 O <<
493 "/// printInstruction - This method is automatically generated by tablegen\n"
494 "/// from the instruction set description. This method returns true if the\n"
495 "/// machine instruction was sufficiently described to print it, otherwise\n"
496 "/// it returns false.\n"
Chris Lattner953c6fe2004-10-03 20:19:02 +0000497 "bool " << Target.getName() << ClassName
Chris Lattner175580c2004-08-14 22:50:53 +0000498 << "::printInstruction(const MachineInstr *MI) {\n";
Chris Lattner2e1f51b2004-08-01 05:59:33 +0000499
Chris Lattner5765dba2005-01-22 17:40:38 +0000500 std::vector<AsmWriterInst> Instructions;
501
Chris Lattner2e1f51b2004-08-01 05:59:33 +0000502 for (CodeGenTarget::inst_iterator I = Target.inst_begin(),
503 E = Target.inst_end(); I != E; ++I)
Chris Lattner5765dba2005-01-22 17:40:38 +0000504 if (!I->second.AsmString.empty())
505 Instructions.push_back(AsmWriterInst(I->second, Variant));
Chris Lattner076efa72004-08-01 07:43:02 +0000506
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000507 // Get the instruction numbering.
Chris Lattner0cfcc1e2006-01-27 02:10:50 +0000508 Target.getInstructionsByEnumValue(NumberedInstructions);
509
Chris Lattner6af022f2006-07-14 22:59:11 +0000510 // Compute the CodeGenInstruction -> AsmWriterInst mapping. Note that not
511 // all machine instructions are necessarily being printed, so there may be
512 // target instructions not in this map.
Chris Lattner6af022f2006-07-14 22:59:11 +0000513 for (unsigned i = 0, e = Instructions.size(); i != e; ++i)
514 CGIAWIMap.insert(std::make_pair(Instructions[i].CGI, &Instructions[i]));
Chris Lattnerf8766682005-01-22 19:22:23 +0000515
Chris Lattner6af022f2006-07-14 22:59:11 +0000516 // Build an aggregate string, and build a table of offsets into it.
517 std::map<std::string, unsigned> StringOffset;
518 std::string AggregateString;
Chris Lattner259bda42006-09-27 16:44:09 +0000519 AggregateString.push_back(0); // "\0"
520 AggregateString.push_back(0); // "\0"
Chris Lattner6af022f2006-07-14 22:59:11 +0000521
Chris Lattner259bda42006-09-27 16:44:09 +0000522 /// OpcodeInfo - This encodes the index of the string to use for the first
Chris Lattner55616402006-07-18 17:32:27 +0000523 /// chunk of the output as well as indices used for operand printing.
524 std::vector<unsigned> OpcodeInfo;
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000525
Chris Lattner55616402006-07-18 17:32:27 +0000526 unsigned MaxStringIdx = 0;
Chris Lattner6af022f2006-07-14 22:59:11 +0000527 for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
528 AsmWriterInst *AWI = CGIAWIMap[NumberedInstructions[i]];
529 unsigned Idx;
Chris Lattnera6dc9fb2006-07-19 01:39:06 +0000530 if (AWI == 0) {
Chris Lattner6af022f2006-07-14 22:59:11 +0000531 // Something not handled by the asmwriter printer.
532 Idx = 0;
Chris Lattnera6dc9fb2006-07-19 01:39:06 +0000533 } else if (AWI->Operands[0].OperandType !=
534 AsmWriterOperand::isLiteralTextOperand ||
535 AWI->Operands[0].Str.empty()) {
536 // Something handled by the asmwriter printer, but with no leading string.
537 Idx = 1;
Chris Lattner6af022f2006-07-14 22:59:11 +0000538 } else {
539 unsigned &Entry = StringOffset[AWI->Operands[0].Str];
540 if (Entry == 0) {
541 // Add the string to the aggregate if this is the first time found.
Chris Lattner55616402006-07-18 17:32:27 +0000542 MaxStringIdx = Entry = AggregateString.size();
Chris Lattner6af022f2006-07-14 22:59:11 +0000543 std::string Str = AWI->Operands[0].Str;
544 UnescapeString(Str);
545 AggregateString += Str;
546 AggregateString += '\0';
Chris Lattnerf8766682005-01-22 19:22:23 +0000547 }
Chris Lattner6af022f2006-07-14 22:59:11 +0000548 Idx = Entry;
Chris Lattner6af022f2006-07-14 22:59:11 +0000549
550 // Nuke the string from the operand list. It is now handled!
551 AWI->Operands.erase(AWI->Operands.begin());
Chris Lattnerf8766682005-01-22 19:22:23 +0000552 }
Chris Lattner55616402006-07-18 17:32:27 +0000553 OpcodeInfo.push_back(Idx);
Chris Lattnerf8766682005-01-22 19:22:23 +0000554 }
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000555
Chris Lattner55616402006-07-18 17:32:27 +0000556 // Figure out how many bits we used for the string index.
Nate Begeman59d28132008-04-09 16:24:11 +0000557 unsigned AsmStrBits = Log2_32_Ceil(MaxStringIdx+1);
Chris Lattner55616402006-07-18 17:32:27 +0000558
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000559 // To reduce code size, we compactify common instructions into a few bits
560 // in the opcode-indexed table.
Chris Lattnerb51ecd42006-07-18 17:38:46 +0000561 unsigned BitsLeft = 32-AsmStrBits;
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000562
563 std::vector<std::vector<std::string> > TableDrivenOperandPrinters;
564
Chris Lattnerb8462862006-07-18 17:56:07 +0000565 bool isFirst = true;
566 while (1) {
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000567 std::vector<std::string> UniqueOperandCommands;
568
Chris Lattnera6dc9fb2006-07-19 01:39:06 +0000569 // For the first operand check, add a default value for instructions with
570 // just opcode strings to use.
Chris Lattnerb8462862006-07-18 17:56:07 +0000571 if (isFirst) {
David Greene014700c2009-07-13 20:25:48 +0000572 // Do the post instruction processing and print the final newline
David Greenefe7b16f2009-07-15 18:24:03 +0000573 UniqueOperandCommands.push_back(" EmitComments(*MI);\n O << \"\\n\";\n return true;\n");
Chris Lattnerb8462862006-07-18 17:56:07 +0000574 isFirst = false;
575 }
David Greene014700c2009-07-13 20:25:48 +0000576
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000577 std::vector<unsigned> InstIdxs;
Chris Lattner96c1ade2006-07-18 18:28:27 +0000578 std::vector<unsigned> NumInstOpsHandled;
579 FindUniqueOperandCommands(UniqueOperandCommands, InstIdxs,
580 NumInstOpsHandled);
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000581
582 // If we ran out of operands to print, we're done.
583 if (UniqueOperandCommands.empty()) break;
584
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000585 // Compute the number of bits we need to represent these cases, this is
586 // ceil(log2(numentries)).
587 unsigned NumBits = Log2_32_Ceil(UniqueOperandCommands.size());
588
589 // If we don't have enough bits for this operand, don't include it.
590 if (NumBits > BitsLeft) {
Bill Wendlingf5da1332006-12-07 22:21:48 +0000591 DOUT << "Not enough bits to densely encode " << NumBits
592 << " more bits\n";
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000593 break;
594 }
595
596 // Otherwise, we can include this in the initial lookup table. Add it in.
597 BitsLeft -= NumBits;
598 for (unsigned i = 0, e = InstIdxs.size(); i != e; ++i)
Chris Lattner195bb4a2006-07-18 19:27:30 +0000599 if (InstIdxs[i] != ~0U)
600 OpcodeInfo[i] |= InstIdxs[i] << (BitsLeft+AsmStrBits);
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000601
Chris Lattnerb8462862006-07-18 17:56:07 +0000602 // Remove the info about this operand.
603 for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
604 if (AsmWriterInst *Inst = getAsmWriterInstByID(i))
Chris Lattner96c1ade2006-07-18 18:28:27 +0000605 if (!Inst->Operands.empty()) {
606 unsigned NumOps = NumInstOpsHandled[InstIdxs[i]];
Chris Lattner0a012122006-07-18 19:06:01 +0000607 assert(NumOps <= Inst->Operands.size() &&
608 "Can't remove this many ops!");
Chris Lattner96c1ade2006-07-18 18:28:27 +0000609 Inst->Operands.erase(Inst->Operands.begin(),
610 Inst->Operands.begin()+NumOps);
611 }
Chris Lattnerb8462862006-07-18 17:56:07 +0000612 }
613
614 // Remember the handlers for this set of operands.
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000615 TableDrivenOperandPrinters.push_back(UniqueOperandCommands);
616 }
617
618
619
Chris Lattner55616402006-07-18 17:32:27 +0000620 O<<" static const unsigned OpInfo[] = {\n";
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000621 for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
Chris Lattnerb51ecd42006-07-18 17:38:46 +0000622 O << " " << OpcodeInfo[i] << "U,\t// "
Chris Lattner55616402006-07-18 17:32:27 +0000623 << NumberedInstructions[i]->TheDef->getName() << "\n";
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000624 }
625 // Add a dummy entry so the array init doesn't end with a comma.
Chris Lattner55616402006-07-18 17:32:27 +0000626 O << " 0U\n";
Chris Lattner6af022f2006-07-14 22:59:11 +0000627 O << " };\n\n";
628
629 // Emit the string itself.
630 O << " const char *AsmStrs = \n \"";
631 unsigned CharsPrinted = 0;
632 EscapeString(AggregateString);
633 for (unsigned i = 0, e = AggregateString.size(); i != e; ++i) {
634 if (CharsPrinted > 70) {
635 O << "\"\n \"";
636 CharsPrinted = 0;
637 }
638 O << AggregateString[i];
639 ++CharsPrinted;
640
641 // Print escape sequences all together.
642 if (AggregateString[i] == '\\') {
643 assert(i+1 < AggregateString.size() && "Incomplete escape sequence!");
644 if (isdigit(AggregateString[i+1])) {
645 assert(isdigit(AggregateString[i+2]) && isdigit(AggregateString[i+3]) &&
646 "Expected 3 digit octal escape!");
647 O << AggregateString[++i];
648 O << AggregateString[++i];
649 O << AggregateString[++i];
650 CharsPrinted += 3;
651 } else {
652 O << AggregateString[++i];
653 ++CharsPrinted;
654 }
655 }
656 }
657 O << "\";\n\n";
658
Argyrios Kyrtzidiscd762402009-05-07 13:55:51 +0000659 O << " processDebugLoc(MI->getDebugLoc());\n\n";
Bill Wendlingcb819f12009-02-18 23:12:06 +0000660
Chris Lattner5b842c32009-06-19 23:57:53 +0000661 O << "\n#ifndef NO_ASM_WRITER_BOILERPLATE\n";
662
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000663 O << " if (MI->getOpcode() == TargetInstrInfo::INLINEASM) {\n"
Evan Cheng4eecdeb2008-02-02 08:39:46 +0000664 << " O << \"\\t\";\n"
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000665 << " printInlineAsm(MI);\n"
666 << " return true;\n"
Dan Gohman44066042008-07-01 00:05:16 +0000667 << " } else if (MI->isLabel()) {\n"
Jim Laskeya683f9b2007-01-26 17:29:20 +0000668 << " printLabel(MI);\n"
669 << " return true;\n"
Evan Chenga844bde2008-02-02 04:07:54 +0000670 << " } else if (MI->getOpcode() == TargetInstrInfo::DECLARE) {\n"
671 << " printDeclare(MI);\n"
672 << " return true;\n"
Evan Chengda47e6e2008-03-15 00:03:38 +0000673 << " } else if (MI->getOpcode() == TargetInstrInfo::IMPLICIT_DEF) {\n"
674 << " printImplicitDef(MI);\n"
675 << " return true;\n"
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000676 << " }\n\n";
Chris Lattner5b842c32009-06-19 23:57:53 +0000677
678 O << "\n#endif\n";
679
Evan Cheng4eecdeb2008-02-02 08:39:46 +0000680 O << " O << \"\\t\";\n\n";
681
Chris Lattner6af022f2006-07-14 22:59:11 +0000682 O << " // Emit the opcode for the instruction.\n"
Chris Lattner55616402006-07-18 17:32:27 +0000683 << " unsigned Bits = OpInfo[MI->getOpcode()];\n"
Evan Cheng3837b642009-07-18 01:43:53 +0000684 << " if (Bits == 0) return false;\n"
685 << " O << AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << ");\n\n";
Chris Lattnerf8766682005-01-22 19:22:23 +0000686
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000687 // Output the table driven operand information.
Chris Lattnerb51ecd42006-07-18 17:38:46 +0000688 BitsLeft = 32-AsmStrBits;
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000689 for (unsigned i = 0, e = TableDrivenOperandPrinters.size(); i != e; ++i) {
690 std::vector<std::string> &Commands = TableDrivenOperandPrinters[i];
691
692 // Compute the number of bits we need to represent these cases, this is
693 // ceil(log2(numentries)).
694 unsigned NumBits = Log2_32_Ceil(Commands.size());
695 assert(NumBits <= BitsLeft && "consistency error");
696
697 // Emit code to extract this field from Bits.
698 BitsLeft -= NumBits;
699
700 O << "\n // Fragment " << i << " encoded into " << NumBits
Chris Lattnere7a589d2006-07-18 17:43:54 +0000701 << " bits for " << Commands.size() << " unique commands.\n";
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000702
Chris Lattner96c1ade2006-07-18 18:28:27 +0000703 if (Commands.size() == 2) {
Chris Lattnere7a589d2006-07-18 17:43:54 +0000704 // Emit two possibilitys with if/else.
705 O << " if ((Bits >> " << (BitsLeft+AsmStrBits) << ") & "
706 << ((1 << NumBits)-1) << ") {\n"
707 << Commands[1]
708 << " } else {\n"
709 << Commands[0]
710 << " }\n\n";
711 } else {
712 O << " switch ((Bits >> " << (BitsLeft+AsmStrBits) << ") & "
713 << ((1 << NumBits)-1) << ") {\n"
714 << " default: // unreachable.\n";
715
716 // Print out all the cases.
717 for (unsigned i = 0, e = Commands.size(); i != e; ++i) {
718 O << " case " << i << ":\n";
719 O << Commands[i];
720 O << " break;\n";
721 }
722 O << " }\n\n";
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000723 }
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000724 }
725
Chris Lattnerb8462862006-07-18 17:56:07 +0000726 // Okay, delete instructions with no operand info left.
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000727 for (unsigned i = 0, e = Instructions.size(); i != e; ++i) {
728 // Entire instruction has been emitted?
729 AsmWriterInst &Inst = Instructions[i];
Chris Lattnerb8462862006-07-18 17:56:07 +0000730 if (Inst.Operands.empty()) {
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000731 Instructions.erase(Instructions.begin()+i);
Chris Lattnerb8462862006-07-18 17:56:07 +0000732 --i; --e;
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000733 }
734 }
735
736
737 // Because this is a vector, we want to emit from the end. Reverse all of the
Chris Lattner870c0162005-01-22 18:38:13 +0000738 // elements in the vector.
739 std::reverse(Instructions.begin(), Instructions.end());
Chris Lattnerbdff5f92006-07-18 17:18:03 +0000740
Chris Lattnerb51ecd42006-07-18 17:38:46 +0000741 if (!Instructions.empty()) {
742 // Find the opcode # of inline asm.
743 O << " switch (MI->getOpcode()) {\n";
744 while (!Instructions.empty())
745 EmitInstructions(Instructions, O);
Chris Lattner870c0162005-01-22 18:38:13 +0000746
Chris Lattnerb51ecd42006-07-18 17:38:46 +0000747 O << " }\n";
David Greenefe7b16f2009-07-15 18:24:03 +0000748 O << " EmitComments(*MI);\n";
Evan Cheng3837b642009-07-18 01:43:53 +0000749 // Print the final newline
750 O << " O << \"\\n\";\n";
751 O << " return true;\n";
Chris Lattnerb51ecd42006-07-18 17:38:46 +0000752 }
753
Chris Lattner0a012122006-07-18 19:06:01 +0000754 O << "}\n";
Chris Lattner2e1f51b2004-08-01 05:59:33 +0000755}