AsmWriterEmitter.cpp revision b0b55e74a090454711b1bb17e4f872d62d6e6b65
1907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org//===- AsmWriterEmitter.cpp - Generate an assembly writer -----------------===//
2907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org//
3907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org//                     The LLVM Compiler Infrastructure
4907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org//
5907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org// This file was developed by the LLVM research group and is distributed under
6907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org// the University of Illinois Open Source License. See LICENSE.TXT for details.
7907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org//
8907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org//===----------------------------------------------------------------------===//
9907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org//
10907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org// This tablegen backend is emits an assembly printer for the current target.
11907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org// Note that this is currently fairly skeletal, but will grow over time.
12b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt//
13907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org//===----------------------------------------------------------------------===//
1430ba436f04e61d4505fb854d5fc56079636e0788joshualitt
15907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org#include "AsmWriterEmitter.h"
16907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org#include "CodeGenTarget.h"
17907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org#include "Record.h"
18907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org#include <ostream>
19907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.orgusing namespace llvm;
20907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org
21907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.orgstatic bool isIdentChar(char C) {
22907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org  return (C >= 'a' && C <= 'z') ||
23907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org         (C >= 'A' && C <= 'Z') ||
24907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org         (C >= '0' && C <= '9') ||
25907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org         C == '_';
26907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org}
275ae5fc59b27a48711e514b3ede548b228e393e9bjoshualitt
285ae5fc59b27a48711e514b3ede548b228e393e9bjoshualittnamespace {
295ae5fc59b27a48711e514b3ede548b228e393e9bjoshualitt  struct AsmWriterOperand {
305ae5fc59b27a48711e514b3ede548b228e393e9bjoshualitt    enum { isLiteralTextOperand, isMachineInstrOperand } OperandType;
315ae5fc59b27a48711e514b3ede548b228e393e9bjoshualitt
325ae5fc59b27a48711e514b3ede548b228e393e9bjoshualitt    /// Str - For isLiteralTextOperand, this IS the literal text.  For
335ae5fc59b27a48711e514b3ede548b228e393e9bjoshualitt    /// isMachineInstrOperand, this is the PrinterMethodName for the operand.
345ae5fc59b27a48711e514b3ede548b228e393e9bjoshualitt    std::string Str;
355ae5fc59b27a48711e514b3ede548b228e393e9bjoshualitt
365ae5fc59b27a48711e514b3ede548b228e393e9bjoshualitt    /// MiOpNo - For isMachineInstrOperand, this is the operand number of the
37907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    /// machine instruction.
385ae5fc59b27a48711e514b3ede548b228e393e9bjoshualitt    unsigned MIOpNo;
39907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org
40907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    /// OpVT - For isMachineInstrOperand, this is the value type for the
41907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    /// operand.
427d7f31433b627e62f518e9186d3f2d9bd44662e0commit-bot@chromium.org    MVT::ValueType OpVT;
437d7f31433b627e62f518e9186d3f2d9bd44662e0commit-bot@chromium.org
447d7f31433b627e62f518e9186d3f2d9bd44662e0commit-bot@chromium.org    AsmWriterOperand(const std::string &LitStr)
457d7f31433b627e62f518e9186d3f2d9bd44662e0commit-bot@chromium.org      : OperandType(isLiteralTextOperand),  Str(LitStr) {}
467d7f31433b627e62f518e9186d3f2d9bd44662e0commit-bot@chromium.org
477d7f31433b627e62f518e9186d3f2d9bd44662e0commit-bot@chromium.org    AsmWriterOperand(const std::string &Printer, unsigned OpNo,
48907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org                     MVT::ValueType VT) : OperandType(isMachineInstrOperand),
49907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org                                          Str(Printer), MIOpNo(OpNo), OpVT(VT){}
50907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org
51907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    void EmitCode(std::ostream &OS) const;
52907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org  };
53907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org
54907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org  struct AsmWriterInst {
55907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    std::vector<AsmWriterOperand> Operands;
56907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org
57907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    void ParseAsmString(const CodeGenInstruction &CGI, unsigned Variant);
58907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    void EmitCode(std::ostream &OS) const {
59907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      for (unsigned i = 0, e = Operands.size(); i != e; ++i)
60907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org        Operands[i].EmitCode(OS);
61907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    }
62907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org  private:
63907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    void AddLiteralString(const std::string &Str) {
64907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      // If the last operand was already a literal text string, append this to
65907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      // it, otherwise add a new operand.
66907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      if (!Operands.empty() &&
67907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org          Operands.back().OperandType == AsmWriterOperand::isLiteralTextOperand)
68907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org        Operands.back().Str.append(Str);
69907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      else
70907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org        Operands.push_back(AsmWriterOperand(Str));
71907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    }
7201a492f959e886f89995c6d1bbcd9f7bb7639726egdaniel  };
73907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org}
74907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org
75907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org
76b0a8a377f832c59cee939ad721e1f87d378b7142joshualittvoid AsmWriterOperand::EmitCode(std::ostream &OS) const {
77907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org  if (OperandType == isLiteralTextOperand)
78907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    OS << "O << \"" << Str << "\"; ";
79907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org  else
80907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    OS << Str << "(MI, " << MIOpNo << ", MVT::" << getName(OpVT) << "); ";
81907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org}
82907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org
83907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org
84907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org/// ParseAsmString - Parse the specified Instruction's AsmString into this
85907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org/// AsmWriterInst.
86907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org///
87907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.orgvoid AsmWriterInst::ParseAsmString(const CodeGenInstruction &CGI,
88907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org                                   unsigned Variant) {
89b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt  bool inVariant = false;  // True if we are inside a {.|.|.} region.
90b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt
91907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org  const std::string &AsmString = CGI.AsmString;
92907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org  std::string::size_type LastEmitted = 0;
93907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org  while (LastEmitted != AsmString.size()) {
94907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    std::string::size_type DollarPos =
95907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      AsmString.find_first_of("${|}", LastEmitted);
96907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    if (DollarPos == std::string::npos) DollarPos = AsmString.size();
97907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org
98907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    // Emit a constant string fragment.
99907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    if (DollarPos != LastEmitted) {
100907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      // TODO: this should eventually handle escaping.
101907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      AddLiteralString(std::string(AsmString.begin()+LastEmitted,
102b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt                                   AsmString.begin()+DollarPos));
103907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      LastEmitted = DollarPos;
104907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    } else if (AsmString[DollarPos] == '{') {
105907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      if (inVariant)
106b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt        throw "Nested variants found for instruction '" + CGI.Name + "'!";
107b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt      LastEmitted = DollarPos+1;
108907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      inVariant = true;   // We are now inside of the variant!
1097510b224e52b9518a8ddf7418db0e9c258f79539kkinnunen      for (unsigned i = 0; i != Variant; ++i) {
110907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org        // Skip over all of the text for an irrelevant variant here.  The
111907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org        // next variant starts at |, or there may not be text for this
112907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org        // variant if we see a }.
113907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org        std::string::size_type NP =
114907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org          AsmString.find_first_of("|}", LastEmitted);
115907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org        if (NP == std::string::npos)
116907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org          throw "Incomplete variant for instruction '" + CGI.Name + "'!";
117b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt        LastEmitted = NP+1;
118b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt        if (AsmString[NP] == '}') {
119907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org          inVariant = false;        // No text for this variant.
12063e99f7a03b2ac90ae7a00232674fd39c0bdcc68bsalomon          break;
121907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org        }
122907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      }
123907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    } else if (AsmString[DollarPos] == '|') {
124907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      if (!inVariant)
125907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org        throw "'|' character found outside of a variant in instruction '"
1267510b224e52b9518a8ddf7418db0e9c258f79539kkinnunen          + CGI.Name + "'!";
1277510b224e52b9518a8ddf7418db0e9c258f79539kkinnunen      // Move to the end of variant list.
1287510b224e52b9518a8ddf7418db0e9c258f79539kkinnunen      std::string::size_type NP = AsmString.find('}', LastEmitted);
1297510b224e52b9518a8ddf7418db0e9c258f79539kkinnunen      if (NP == std::string::npos)
130907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org        throw "Incomplete variant for instruction '" + CGI.Name + "'!";
131907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      LastEmitted = NP+1;
132907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      inVariant = false;
133907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    } else if (AsmString[DollarPos] == '}') {
134907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      if (!inVariant)
135907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org        throw "'}' character found outside of a variant in instruction '"
136907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org          + CGI.Name + "'!";
137907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      LastEmitted = DollarPos+1;
138907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      inVariant = false;
139907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    } else if (DollarPos+1 != AsmString.size() &&
140907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org               AsmString[DollarPos+1] == '$') {
141907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      AddLiteralString("$");  // "$$" -> $
142907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      LastEmitted = DollarPos+2;
143907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    } else {
144907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      // Get the name of the variable.
145907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      // TODO: should eventually handle ${foo}bar as $foo
146907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      std::string::size_type VarEnd = DollarPos+1;
147907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      while (VarEnd < AsmString.size() && isIdentChar(AsmString[VarEnd]))
148b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt        ++VarEnd;
149b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt      std::string VarName(AsmString.begin()+DollarPos+1,
150b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt                          AsmString.begin()+VarEnd);
151b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt      if (VarName.empty())
152b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt        throw "Stray '$' in '" + CGI.Name + "' asm string, maybe you want $$?";
153b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt
154907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      unsigned OpNo = CGI.getOperandNamed(VarName);
155907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org
156907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      // If this is a two-address instruction and we are not accessing the
157907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      // 0th operand, remove an operand.
158907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      unsigned MIOp = CGI.OperandList[OpNo].MIOperandNo;
159b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt      if (CGI.isTwoAddress && MIOp != 0) {
160907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org        if (MIOp == 1)
161b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt          throw "Should refer to operand #0 instead of #1 for two-address"
162907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org            " instruction '" + CGI.Name + "'!";
163907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org        --MIOp;
164907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      }
165907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org
166907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      Operands.push_back(AsmWriterOperand(CGI.OperandList[OpNo].PrinterMethodName,
167907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org                                          MIOp, CGI.OperandList[OpNo].Ty));
168907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org      LastEmitted = VarEnd;
169907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org    }
170907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org  }
171907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org
172907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org  AddLiteralString("\\n");
173907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org}
174907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org
175907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org
176907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.orgvoid AsmWriterEmitter::run(std::ostream &O) {
177b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt  EmitSourceFileHeader("Assembly Writer Source Fragment", O);
178907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org
179b0a8a377f832c59cee939ad721e1f87d378b7142joshualitt  CodeGenTarget Target;
180907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org  Record *AsmWriter = Target.getAsmWriter();
181907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org  std::string ClassName = AsmWriter->getValueAsString("AsmWriterClassName");
182907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org  unsigned Variant = AsmWriter->getValueAsInt("Variant");
183907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org
184907fbd53c5e5dd4cbde7b72f9242b51febd7ef95commit-bot@chromium.org  O <<
185  "/// printInstruction - This method is automatically generated by tablegen\n"
186  "/// from the instruction set description.  This method returns true if the\n"
187  "/// machine instruction was sufficiently described to print it, otherwise\n"
188  "/// it returns false.\n"
189    "bool " << Target.getName() << ClassName
190            << "::printInstruction(const MachineInstr *MI) {\n";
191  O << "  switch (MI->getOpcode()) {\n"
192       "  default: return false;\n";
193
194  std::string Namespace = Target.inst_begin()->second.Namespace;
195
196  for (CodeGenTarget::inst_iterator I = Target.inst_begin(),
197         E = Target.inst_end(); I != E; ++I)
198    if (!I->second.AsmString.empty()) {
199      O << "  case " << Namespace << "::" << I->first << ": ";
200
201      AsmWriterInst AWI;
202      AWI.ParseAsmString(I->second, Variant);
203      AWI.EmitCode(O);
204      O << " break;\n";
205    }
206
207  O << "  }\n"
208       "  return true;\n"
209       "}\n";
210}
211