blob: ab595ca9fbc59e1e1d2295c5685e9ab9e32d1ad3 [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//
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.
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"
Jeff Cohen615ed992005-01-22 18:50:10 +000018#include <algorithm>
Chris Lattner2e1f51b2004-08-01 05:59:33 +000019#include <ostream>
20using namespace llvm;
21
Chris Lattner076efa72004-08-01 07:43:02 +000022static bool isIdentChar(char C) {
23 return (C >= 'a' && C <= 'z') ||
24 (C >= 'A' && C <= 'Z') ||
25 (C >= '0' && C <= '9') ||
26 C == '_';
27}
28
Chris Lattnerb0b55e72005-01-22 17:32:42 +000029namespace {
30 struct AsmWriterOperand {
31 enum { isLiteralTextOperand, isMachineInstrOperand } OperandType;
32
33 /// Str - For isLiteralTextOperand, this IS the literal text. For
34 /// isMachineInstrOperand, this is the PrinterMethodName for the operand.
35 std::string Str;
36
37 /// MiOpNo - For isMachineInstrOperand, this is the operand number of the
38 /// machine instruction.
39 unsigned MIOpNo;
Chris Lattner04cadb32006-02-06 23:40:48 +000040
41 /// MiModifier - For isMachineInstrOperand, this is the modifier string for
42 /// an operand, specified with syntax like ${opname:modifier}.
43 std::string MiModifier;
Chris Lattnerb0b55e72005-01-22 17:32:42 +000044
Chris Lattnerb0b55e72005-01-22 17:32:42 +000045 AsmWriterOperand(const std::string &LitStr)
Nate Begeman391c5d22005-11-30 18:54:35 +000046 : OperandType(isLiteralTextOperand), Str(LitStr) {}
Chris Lattnerb0b55e72005-01-22 17:32:42 +000047
Chris Lattner04cadb32006-02-06 23:40:48 +000048 AsmWriterOperand(const std::string &Printer, unsigned OpNo,
49 const std::string &Modifier)
50 : OperandType(isMachineInstrOperand), Str(Printer), MIOpNo(OpNo),
51 MiModifier(Modifier) {}
Chris Lattnerb0b55e72005-01-22 17:32:42 +000052
Chris Lattner870c0162005-01-22 18:38:13 +000053 bool operator!=(const AsmWriterOperand &Other) const {
54 if (OperandType != Other.OperandType || Str != Other.Str) return true;
55 if (OperandType == isMachineInstrOperand)
Chris Lattner04cadb32006-02-06 23:40:48 +000056 return MIOpNo != Other.MIOpNo || MiModifier != Other.MiModifier;
Chris Lattner870c0162005-01-22 18:38:13 +000057 return false;
58 }
Chris Lattner38c07512005-01-22 20:31:17 +000059 bool operator==(const AsmWriterOperand &Other) const {
60 return !operator!=(Other);
61 }
Chris Lattnerb0b55e72005-01-22 17:32:42 +000062 void EmitCode(std::ostream &OS) const;
63 };
64
65 struct AsmWriterInst {
66 std::vector<AsmWriterOperand> Operands;
Chris Lattner5765dba2005-01-22 17:40:38 +000067 const CodeGenInstruction *CGI;
Misha Brukman3da94ae2005-04-22 00:00:37 +000068
Chris Lattner5765dba2005-01-22 17:40:38 +000069 AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant);
Chris Lattner870c0162005-01-22 18:38:13 +000070
Chris Lattnerf8766682005-01-22 19:22:23 +000071 /// MatchesAllButOneOp - If this instruction is exactly identical to the
72 /// specified instruction except for one differing operand, return the
73 /// differing operand number. Otherwise return ~0.
74 unsigned MatchesAllButOneOp(const AsmWriterInst &Other) const;
Chris Lattner870c0162005-01-22 18:38:13 +000075
Chris Lattnerb0b55e72005-01-22 17:32:42 +000076 private:
77 void AddLiteralString(const std::string &Str) {
78 // If the last operand was already a literal text string, append this to
79 // it, otherwise add a new operand.
80 if (!Operands.empty() &&
81 Operands.back().OperandType == AsmWriterOperand::isLiteralTextOperand)
82 Operands.back().Str.append(Str);
83 else
84 Operands.push_back(AsmWriterOperand(Str));
85 }
86 };
87}
88
89
90void AsmWriterOperand::EmitCode(std::ostream &OS) const {
91 if (OperandType == isLiteralTextOperand)
92 OS << "O << \"" << Str << "\"; ";
Chris Lattner04cadb32006-02-06 23:40:48 +000093 else {
94 OS << Str << "(MI, " << MIOpNo;
95 if (!MiModifier.empty())
96 OS << ", \"" << MiModifier << '"';
97 OS << "); ";
98 }
Chris Lattnerb0b55e72005-01-22 17:32:42 +000099}
100
101
102/// ParseAsmString - Parse the specified Instruction's AsmString into this
103/// AsmWriterInst.
104///
Chris Lattner5765dba2005-01-22 17:40:38 +0000105AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant) {
106 this->CGI = &CGI;
Chris Lattnerb03b0802006-02-06 22:43:28 +0000107 unsigned CurVariant = ~0U; // ~0 if we are outside a {.|.|.} region, other #.
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000108
Chris Lattner1cf9d962006-02-01 19:12:23 +0000109 // NOTE: Any extensions to this code need to be mirrored in the
110 // AsmPrinter::printInlineAsm code that executes as compile time (assuming
111 // that inline asm strings should also get the new feature)!
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000112 const std::string &AsmString = CGI.AsmString;
113 std::string::size_type LastEmitted = 0;
114 while (LastEmitted != AsmString.size()) {
115 std::string::size_type DollarPos =
116 AsmString.find_first_of("${|}", LastEmitted);
117 if (DollarPos == std::string::npos) DollarPos = AsmString.size();
118
119 // Emit a constant string fragment.
120 if (DollarPos != LastEmitted) {
121 // TODO: this should eventually handle escaping.
Chris Lattnerb03b0802006-02-06 22:43:28 +0000122 if (CurVariant == Variant || CurVariant == ~0U)
123 AddLiteralString(std::string(AsmString.begin()+LastEmitted,
124 AsmString.begin()+DollarPos));
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000125 LastEmitted = DollarPos;
126 } else if (AsmString[DollarPos] == '{') {
Chris Lattnerb03b0802006-02-06 22:43:28 +0000127 if (CurVariant != ~0U)
Jeff Cohen00b168892005-07-27 06:12:32 +0000128 throw "Nested variants found for instruction '" +
Chris Lattner3e3def92005-07-15 22:43:04 +0000129 CGI.TheDef->getName() + "'!";
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000130 LastEmitted = DollarPos+1;
Chris Lattnerb03b0802006-02-06 22:43:28 +0000131 CurVariant = 0; // We are now inside of the variant!
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000132 } else if (AsmString[DollarPos] == '|') {
Chris Lattnerb03b0802006-02-06 22:43:28 +0000133 if (CurVariant == ~0U)
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000134 throw "'|' character found outside of a variant in instruction '"
Chris Lattner3e3def92005-07-15 22:43:04 +0000135 + CGI.TheDef->getName() + "'!";
Chris Lattnerb03b0802006-02-06 22:43:28 +0000136 ++CurVariant;
137 ++LastEmitted;
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000138 } else if (AsmString[DollarPos] == '}') {
Chris Lattnerb03b0802006-02-06 22:43:28 +0000139 if (CurVariant == ~0U)
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000140 throw "'}' character found outside of a variant in instruction '"
Chris Lattner3e3def92005-07-15 22:43:04 +0000141 + CGI.TheDef->getName() + "'!";
Chris Lattnerb03b0802006-02-06 22:43:28 +0000142 ++LastEmitted;
143 CurVariant = ~0U;
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000144 } else if (DollarPos+1 != AsmString.size() &&
145 AsmString[DollarPos+1] == '$') {
Chris Lattnerb03b0802006-02-06 22:43:28 +0000146 if (CurVariant == Variant || CurVariant == ~0U)
147 AddLiteralString("$"); // "$$" -> $
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000148 LastEmitted = DollarPos+2;
149 } else {
150 // Get the name of the variable.
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000151 std::string::size_type VarEnd = DollarPos+1;
Nate Begemanafc54562005-07-14 22:50:30 +0000152
153 // handle ${foo}bar as $foo by detecting whether the character following
154 // the dollar sign is a curly brace. If so, advance VarEnd and DollarPos
155 // so the variable name does not contain the leading curly brace.
156 bool hasCurlyBraces = false;
157 if (VarEnd < AsmString.size() && '{' == AsmString[VarEnd]) {
158 hasCurlyBraces = true;
159 ++DollarPos;
160 ++VarEnd;
161 }
162
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000163 while (VarEnd < AsmString.size() && isIdentChar(AsmString[VarEnd]))
164 ++VarEnd;
165 std::string VarName(AsmString.begin()+DollarPos+1,
166 AsmString.begin()+VarEnd);
Nate Begemanafc54562005-07-14 22:50:30 +0000167
Chris Lattner04cadb32006-02-06 23:40:48 +0000168 // Modifier - Support ${foo:modifier} syntax, where "modifier" is passed
169 // into printOperand.
170 std::string Modifier;
171
Nate Begemanafc54562005-07-14 22:50:30 +0000172 // In order to avoid starting the next string at the terminating curly
173 // brace, advance the end position past it if we found an opening curly
174 // brace.
175 if (hasCurlyBraces) {
176 if (VarEnd >= AsmString.size())
177 throw "Reached end of string before terminating curly brace in '"
Chris Lattner3e3def92005-07-15 22:43:04 +0000178 + CGI.TheDef->getName() + "'";
Chris Lattner04cadb32006-02-06 23:40:48 +0000179
180 // Look for a modifier string.
181 if (AsmString[VarEnd] == ':') {
182 ++VarEnd;
183 if (VarEnd >= AsmString.size())
184 throw "Reached end of string before terminating curly brace in '"
185 + CGI.TheDef->getName() + "'";
186
187 unsigned ModifierStart = VarEnd;
188 while (VarEnd < AsmString.size() && isIdentChar(AsmString[VarEnd]))
189 ++VarEnd;
190 Modifier = std::string(AsmString.begin()+ModifierStart,
191 AsmString.begin()+VarEnd);
192 if (Modifier.empty())
193 throw "Bad operand modifier name in '"+ CGI.TheDef->getName() + "'";
194 }
195
Nate Begemanafc54562005-07-14 22:50:30 +0000196 if (AsmString[VarEnd] != '}')
Chris Lattnerb03b0802006-02-06 22:43:28 +0000197 throw "Variable name beginning with '{' did not end with '}' in '"
Chris Lattner3e3def92005-07-15 22:43:04 +0000198 + CGI.TheDef->getName() + "'";
Nate Begemanafc54562005-07-14 22:50:30 +0000199 ++VarEnd;
200 }
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000201 if (VarName.empty())
Jeff Cohen00b168892005-07-27 06:12:32 +0000202 throw "Stray '$' in '" + CGI.TheDef->getName() +
Chris Lattner3e3def92005-07-15 22:43:04 +0000203 "' asm string, maybe you want $$?";
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000204
205 unsigned OpNo = CGI.getOperandNamed(VarName);
Chris Lattner5765dba2005-01-22 17:40:38 +0000206 CodeGenInstruction::OperandInfo OpInfo = CGI.OperandList[OpNo];
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000207
208 // If this is a two-address instruction and we are not accessing the
209 // 0th operand, remove an operand.
Chris Lattner5765dba2005-01-22 17:40:38 +0000210 unsigned MIOp = OpInfo.MIOperandNo;
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000211 if (CGI.isTwoAddress && MIOp != 0) {
212 if (MIOp == 1)
213 throw "Should refer to operand #0 instead of #1 for two-address"
Chris Lattner3e3def92005-07-15 22:43:04 +0000214 " instruction '" + CGI.TheDef->getName() + "'!";
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000215 --MIOp;
216 }
217
Chris Lattnerb03b0802006-02-06 22:43:28 +0000218 if (CurVariant == Variant || CurVariant == ~0U)
Chris Lattner04cadb32006-02-06 23:40:48 +0000219 Operands.push_back(AsmWriterOperand(OpInfo.PrinterMethodName, MIOp,
220 Modifier));
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000221 LastEmitted = VarEnd;
222 }
223 }
224
225 AddLiteralString("\\n");
226}
227
Chris Lattnerf8766682005-01-22 19:22:23 +0000228/// MatchesAllButOneOp - If this instruction is exactly identical to the
229/// specified instruction except for one differing operand, return the differing
230/// operand number. If more than one operand mismatches, return ~1, otherwise
231/// if the instructions are identical return ~0.
232unsigned AsmWriterInst::MatchesAllButOneOp(const AsmWriterInst &Other)const{
233 if (Operands.size() != Other.Operands.size()) return ~1;
Chris Lattner870c0162005-01-22 18:38:13 +0000234
235 unsigned MismatchOperand = ~0U;
236 for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
Chris Lattner870c0162005-01-22 18:38:13 +0000237 if (Operands[i] != Other.Operands[i])
Chris Lattnerf8766682005-01-22 19:22:23 +0000238 if (MismatchOperand != ~0U) // Already have one mismatch?
239 return ~1U;
Misha Brukman3da94ae2005-04-22 00:00:37 +0000240 else
Chris Lattner870c0162005-01-22 18:38:13 +0000241 MismatchOperand = i;
242 }
243 return MismatchOperand;
244}
245
Chris Lattner38c07512005-01-22 20:31:17 +0000246static void PrintCases(std::vector<std::pair<std::string,
247 AsmWriterOperand> > &OpsToPrint, std::ostream &O) {
248 O << " case " << OpsToPrint.back().first << ": ";
249 AsmWriterOperand TheOp = OpsToPrint.back().second;
250 OpsToPrint.pop_back();
251
252 // Check to see if any other operands are identical in this list, and if so,
253 // emit a case label for them.
254 for (unsigned i = OpsToPrint.size(); i != 0; --i)
255 if (OpsToPrint[i-1].second == TheOp) {
256 O << "\n case " << OpsToPrint[i-1].first << ": ";
257 OpsToPrint.erase(OpsToPrint.begin()+i-1);
258 }
259
260 // Finally, emit the code.
261 TheOp.EmitCode(O);
262 O << "break;\n";
263}
264
Chris Lattner870c0162005-01-22 18:38:13 +0000265
266/// EmitInstructions - Emit the last instruction in the vector and any other
267/// instructions that are suitably similar to it.
268static void EmitInstructions(std::vector<AsmWriterInst> &Insts,
269 std::ostream &O) {
270 AsmWriterInst FirstInst = Insts.back();
271 Insts.pop_back();
272
273 std::vector<AsmWriterInst> SimilarInsts;
274 unsigned DifferingOperand = ~0;
275 for (unsigned i = Insts.size(); i != 0; --i) {
Chris Lattnerf8766682005-01-22 19:22:23 +0000276 unsigned DiffOp = Insts[i-1].MatchesAllButOneOp(FirstInst);
277 if (DiffOp != ~1U) {
Chris Lattner870c0162005-01-22 18:38:13 +0000278 if (DifferingOperand == ~0U) // First match!
279 DifferingOperand = DiffOp;
280
281 // If this differs in the same operand as the rest of the instructions in
282 // this class, move it to the SimilarInsts list.
Chris Lattnerf8766682005-01-22 19:22:23 +0000283 if (DifferingOperand == DiffOp || DiffOp == ~0U) {
Chris Lattner870c0162005-01-22 18:38:13 +0000284 SimilarInsts.push_back(Insts[i-1]);
285 Insts.erase(Insts.begin()+i-1);
286 }
287 }
288 }
289
Chris Lattnera1e8a802006-05-01 17:01:17 +0000290 O << " case " << FirstInst.CGI->Namespace << "::"
Chris Lattner870c0162005-01-22 18:38:13 +0000291 << FirstInst.CGI->TheDef->getName() << ":\n";
292 for (unsigned i = 0, e = SimilarInsts.size(); i != e; ++i)
Chris Lattnera1e8a802006-05-01 17:01:17 +0000293 O << " case " << SimilarInsts[i].CGI->Namespace << "::"
Chris Lattner870c0162005-01-22 18:38:13 +0000294 << SimilarInsts[i].CGI->TheDef->getName() << ":\n";
295 for (unsigned i = 0, e = FirstInst.Operands.size(); i != e; ++i) {
296 if (i != DifferingOperand) {
297 // If the operand is the same for all instructions, just print it.
298 O << " ";
299 FirstInst.Operands[i].EmitCode(O);
300 } else {
301 // If this is the operand that varies between all of the instructions,
302 // emit a switch for just this operand now.
303 O << " switch (MI->getOpcode()) {\n";
Chris Lattner38c07512005-01-22 20:31:17 +0000304 std::vector<std::pair<std::string, AsmWriterOperand> > OpsToPrint;
Chris Lattnera1e8a802006-05-01 17:01:17 +0000305 OpsToPrint.push_back(std::make_pair(FirstInst.CGI->Namespace + "::" +
Chris Lattner38c07512005-01-22 20:31:17 +0000306 FirstInst.CGI->TheDef->getName(),
307 FirstInst.Operands[i]));
Misha Brukman3da94ae2005-04-22 00:00:37 +0000308
Chris Lattner870c0162005-01-22 18:38:13 +0000309 for (unsigned si = 0, e = SimilarInsts.size(); si != e; ++si) {
Chris Lattner38c07512005-01-22 20:31:17 +0000310 AsmWriterInst &AWI = SimilarInsts[si];
Chris Lattnera1e8a802006-05-01 17:01:17 +0000311 OpsToPrint.push_back(std::make_pair(AWI.CGI->Namespace+"::"+
Chris Lattner38c07512005-01-22 20:31:17 +0000312 AWI.CGI->TheDef->getName(),
313 AWI.Operands[i]));
Chris Lattner870c0162005-01-22 18:38:13 +0000314 }
Chris Lattner38c07512005-01-22 20:31:17 +0000315 std::reverse(OpsToPrint.begin(), OpsToPrint.end());
316 while (!OpsToPrint.empty())
317 PrintCases(OpsToPrint, O);
Chris Lattner870c0162005-01-22 18:38:13 +0000318 O << " }";
319 }
320 O << "\n";
321 }
322
323 O << " break;\n";
324}
Chris Lattnerb0b55e72005-01-22 17:32:42 +0000325
Chris Lattner2e1f51b2004-08-01 05:59:33 +0000326void AsmWriterEmitter::run(std::ostream &O) {
327 EmitSourceFileHeader("Assembly Writer Source Fragment", O);
328
329 CodeGenTarget Target;
Chris Lattner175580c2004-08-14 22:50:53 +0000330 Record *AsmWriter = Target.getAsmWriter();
Chris Lattner953c6fe2004-10-03 20:19:02 +0000331 std::string ClassName = AsmWriter->getValueAsString("AsmWriterClassName");
332 unsigned Variant = AsmWriter->getValueAsInt("Variant");
Chris Lattner175580c2004-08-14 22:50:53 +0000333
Chris Lattner2e1f51b2004-08-01 05:59:33 +0000334 O <<
335 "/// printInstruction - This method is automatically generated by tablegen\n"
336 "/// from the instruction set description. This method returns true if the\n"
337 "/// machine instruction was sufficiently described to print it, otherwise\n"
338 "/// it returns false.\n"
Chris Lattner953c6fe2004-10-03 20:19:02 +0000339 "bool " << Target.getName() << ClassName
Chris Lattner175580c2004-08-14 22:50:53 +0000340 << "::printInstruction(const MachineInstr *MI) {\n";
Chris Lattner2e1f51b2004-08-01 05:59:33 +0000341
Chris Lattner5765dba2005-01-22 17:40:38 +0000342 std::vector<AsmWriterInst> Instructions;
343
Chris Lattner2e1f51b2004-08-01 05:59:33 +0000344 for (CodeGenTarget::inst_iterator I = Target.inst_begin(),
345 E = Target.inst_end(); I != E; ++I)
Chris Lattner5765dba2005-01-22 17:40:38 +0000346 if (!I->second.AsmString.empty())
347 Instructions.push_back(AsmWriterInst(I->second, Variant));
Chris Lattner076efa72004-08-01 07:43:02 +0000348
Chris Lattnerf8766682005-01-22 19:22:23 +0000349 // If all of the instructions start with a constant string (a very very common
350 // occurance), emit all of the constant strings as a big table lookup instead
Misha Brukman3da94ae2005-04-22 00:00:37 +0000351 // of requiring a switch for them.
Chris Lattnerf8766682005-01-22 19:22:23 +0000352 bool AllStartWithString = true;
353
354 for (unsigned i = 0, e = Instructions.size(); i != e; ++i)
355 if (Instructions[i].Operands.empty() ||
356 Instructions[i].Operands[0].OperandType !=
357 AsmWriterOperand::isLiteralTextOperand) {
358 AllStartWithString = false;
359 break;
360 }
Misha Brukman3da94ae2005-04-22 00:00:37 +0000361
Chris Lattner0cfcc1e2006-01-27 02:10:50 +0000362 std::vector<const CodeGenInstruction*> NumberedInstructions;
363 Target.getInstructionsByEnumValue(NumberedInstructions);
364
Chris Lattnerf8766682005-01-22 19:22:23 +0000365 if (AllStartWithString) {
366 // Compute the CodeGenInstruction -> AsmWriterInst mapping. Note that not
367 // all machine instructions are necessarily being printed, so there may be
368 // target instructions not in this map.
369 std::map<const CodeGenInstruction*, AsmWriterInst*> CGIAWIMap;
370 for (unsigned i = 0, e = Instructions.size(); i != e; ++i)
371 CGIAWIMap.insert(std::make_pair(Instructions[i].CGI, &Instructions[i]));
372
373 // Emit a table of constant strings.
Chris Lattnerf8766682005-01-22 19:22:23 +0000374 O << " static const char * const OpStrs[] = {\n";
375 for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
376 AsmWriterInst *AWI = CGIAWIMap[NumberedInstructions[i]];
377 if (AWI == 0) {
378 // Something not handled by the asmwriter printer.
379 O << " 0,\t// ";
380 } else {
381 O << " \"" << AWI->Operands[0].Str << "\",\t// ";
382 // Nuke the string from the operand list. It is now handled!
383 AWI->Operands.erase(AWI->Operands.begin());
384 }
385 O << NumberedInstructions[i]->TheDef->getName() << "\n";
386 }
387 O << " };\n\n"
388 << " // Emit the opcode for the instruction.\n"
389 << " if (const char *AsmStr = OpStrs[MI->getOpcode()])\n"
390 << " O << AsmStr;\n\n";
391 }
392
Chris Lattner870c0162005-01-22 18:38:13 +0000393 // Because this is a vector we want to emit from the end. Reverse all of the
394 // elements in the vector.
395 std::reverse(Instructions.begin(), Instructions.end());
Chris Lattnerf8766682005-01-22 19:22:23 +0000396
Chris Lattner0cfcc1e2006-01-27 02:10:50 +0000397 // Find the opcode # of inline asm
Chris Lattnerf8766682005-01-22 19:22:23 +0000398 O << " switch (MI->getOpcode()) {\n"
Chris Lattner0cfcc1e2006-01-27 02:10:50 +0000399 " default: return false;\n"
400 " case " << NumberedInstructions.back()->Namespace
401 << "::INLINEASM: printInlineAsm(MI); break;\n";
Misha Brukman3da94ae2005-04-22 00:00:37 +0000402
Chris Lattner870c0162005-01-22 18:38:13 +0000403 while (!Instructions.empty())
404 EmitInstructions(Instructions, O);
405
Chris Lattner2e1f51b2004-08-01 05:59:33 +0000406 O << " }\n"
407 " return true;\n"
408 "}\n";
Chris Lattner2e1f51b2004-08-01 05:59:33 +0000409}