diff options
Diffstat (limited to 'llvm/utils/TableGen')
| -rw-r--r-- | llvm/utils/TableGen/AsmWriterEmitter.cpp | 135 | 
1 files changed, 12 insertions, 123 deletions
diff --git a/llvm/utils/TableGen/AsmWriterEmitter.cpp b/llvm/utils/TableGen/AsmWriterEmitter.cpp index 933f9210f82..d1cb7022d06 100644 --- a/llvm/utils/TableGen/AsmWriterEmitter.cpp +++ b/llvm/utils/TableGen/AsmWriterEmitter.cpp @@ -19,7 +19,6 @@  #include "llvm/Support/Debug.h"  #include "llvm/Support/MathExtras.h"  #include <algorithm> -#include <sstream>  #include <iostream>  using namespace llvm; @@ -33,11 +32,7 @@ static bool isIdentChar(char C) {  // This should be an anon namespace, this works around a GCC warning.  namespace llvm {      struct AsmWriterOperand { -    enum OpType {  -      isLiteralTextOperand,  -      isMachineInstrOperand, -      isLiteralStatementOperand -    } OperandType; +    enum { isLiteralTextOperand, isMachineInstrOperand } OperandType;      /// Str - For isLiteralTextOperand, this IS the literal text.  For      /// isMachineInstrOperand, this is the PrinterMethodName for the operand. @@ -52,16 +47,14 @@ namespace llvm {      std::string MiModifier;      // To make VS STL happy -    AsmWriterOperand(OpType op = isLiteralTextOperand):OperandType(op) {} +    AsmWriterOperand():OperandType(isLiteralTextOperand) {} -    AsmWriterOperand(const std::string &LitStr, -                     OpType op = isLiteralTextOperand) -      : OperandType(op), Str(LitStr) {} +    explicit AsmWriterOperand(const std::string &LitStr) +      : OperandType(isLiteralTextOperand), Str(LitStr) {}      AsmWriterOperand(const std::string &Printer, unsigned OpNo,  -                     const std::string &Modifier, -                     OpType op = isMachineInstrOperand)  -      : OperandType(op), Str(Printer), MIOpNo(OpNo), +                     const std::string &Modifier)  +      : OperandType(isMachineInstrOperand), Str(Printer), MIOpNo(OpNo),        MiModifier(Modifier) {}      bool operator!=(const AsmWriterOperand &Other) const { @@ -85,22 +78,6 @@ namespace llvm {      std::vector<AsmWriterOperand> Operands;      const CodeGenInstruction *CGI; -    /// MAX_GROUP_NESTING_LEVEL - The maximum number of group nesting -    /// levels we ever expect to see in an asm operand. -    static const int MAX_GROUP_NESTING_LEVEL = 10; - -    /// GroupLevel - The level of nesting of the current operand -    /// group, such as [reg + (reg + offset)].  -1 means we are not in -    /// a group. -    int GroupLevel; - -    /// GroupDelim - Remember the delimeter for a group operand. -    char GroupDelim[MAX_GROUP_NESTING_LEVEL]; - -    /// InGroup - Determine whether we are in the middle of an -    /// operand group. -    bool InGroup() const { return GroupLevel != -1; } -      AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant);      /// MatchesAllButOneOp - If this instruction is exactly identical to the @@ -112,70 +89,6 @@ namespace llvm {      void AddLiteralString(const std::string &Str) {        // If the last operand was already a literal text string, append this to        // it, otherwise add a new operand. - -      std::string::size_type SearchStart = 0; -      std::string::size_type SpaceStartPos = std::string::npos; -      do { -        // Search for whitespace and replace with calls to set the -        // output column. -        SpaceStartPos = Str.find_first_of(" \t", SearchStart); -        // Assume grouped text is one operand. -        std::string::size_type StartDelimPos = Str.find_first_of("[{(", SearchStart); - -        SearchStart = std::string::npos; - -        if (StartDelimPos != std::string::npos) { -          ++GroupLevel; -          assert(GroupLevel < MAX_GROUP_NESTING_LEVEL -                 && "Exceeded maximum operand group nesting level"); -          GroupDelim[GroupLevel] = Str[StartDelimPos]; -          if (SpaceStartPos != std::string::npos && -              SpaceStartPos > StartDelimPos) { -            // This space doesn't count. -            SpaceStartPos = std::string::npos; -          } -        } - -        if (InGroup()) { -          // Find the end delimiter. -          char EndDelim = (GroupDelim[GroupLevel] == '{' ? '}' :  -                           (GroupDelim[GroupLevel] == '(' ? ')' : ']')); -          std::string::size_type EndDelimSearchStart = -            StartDelimPos == std::string::npos ? 0 : StartDelimPos+1; -          std::string::size_type EndDelimPos = Str.find(EndDelim, -                                                        EndDelimSearchStart); -          SearchStart = EndDelimPos; -          if (EndDelimPos != std::string::npos) { -            // Iterate. -            SearchStart = EndDelimPos + 1; -            --GroupLevel; -            assert(GroupLevel > -2 && "Too many end delimeters!"); -          } -          if (InGroup()) -            SpaceStartPos = std::string::npos; -        } -      } while (SearchStart != std::string::npos); - - -      if (SpaceStartPos != std::string::npos) { -        std::string::size_type SpaceEndPos =  -          Str.find_first_not_of(" \t", SpaceStartPos+1); -        if (SpaceStartPos != 0) { -          // Emit the first part of the string. -          AddLiteralString(Str.substr(0, SpaceStartPos)); -        } -        Operands.push_back( -          AsmWriterOperand( -            "O.PadToColumn(TAI->getOperandColumn(OperandColumn++), 1);\n", -            AsmWriterOperand::isLiteralStatementOperand)); -        if (SpaceEndPos != std::string::npos) { -          // Emit the last part of the string. -          AddLiteralString(Str.substr(SpaceEndPos)); -        } -        // We've emitted the whole string. -        return; -      } -              if (!Operands.empty() &&            Operands.back().OperandType == AsmWriterOperand::isLiteralTextOperand)          Operands.back().Str.append(Str); @@ -190,18 +103,6 @@ std::string AsmWriterOperand::getCode() const {    if (OperandType == isLiteralTextOperand)      return "O << \"" + Str + "\"; "; -  if (OperandType == isLiteralStatementOperand) { -    return Str; -  } - -  if (OperandType == isLiteralStatementOperand) { -    return Str; -  } - -  if (OperandType == isLiteralStatementOperand) { -    return Str; -  } -    std::string Result = Str + "(MI";    if (MIOpNo != ~0U)      Result += ", " + utostr(MIOpNo); @@ -214,8 +115,7 @@ std::string AsmWriterOperand::getCode() const {  /// ParseAsmString - Parse the specified Instruction's AsmString into this  /// AsmWriterInst.  /// -AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant) -    : GroupLevel(-1) { +AsmWriterInst::AsmWriterInst(const CodeGenInstruction &CGI, unsigned Variant) {    this->CGI = &CGI;    unsigned CurVariant = ~0U;  // ~0 if we are outside a {.|.|.} region, other #. @@ -455,9 +355,6 @@ static void EmitInstructions(std::vector<AsmWriterInst> &Insts,      }      O << "\n";    } -  O << "    EmitComments(*MI);\n"; -  // Print the final newline -  O << "    O << \"\\n\";\n";    O << "    break;\n";  } @@ -784,16 +681,8 @@ void AsmWriterEmitter::run(raw_ostream &O) {    O << "  // Emit the opcode for the instruction.\n"      << "  unsigned Bits = OpInfo[MI->getOpcode()];\n" -    << "  if (Bits == 0) return false;\n\n"; - -  O << "  std::string OpStr(AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << "));\n" -    << "  unsigned OperandColumn = 1;\n" -    << "  O << OpStr;\n\n"; - -  O << "  if (OpStr.find_last_of(\" \\t\") == OpStr.size()-1) {\n" -    << "    O.PadToColumn(TAI->getOperandColumn(1));\n" -    << "    OperandColumn = 2;\n" -    << "  }\n\n"; +    << "  if (Bits == 0) return false;\n" +    << "  O << AsmStrs+(Bits & " << (1 << AsmStrBits)-1 << ");\n\n";    // Output the table driven operand information.    BitsLeft = 32-AsmStrBits; @@ -857,10 +746,10 @@ void AsmWriterEmitter::run(raw_ostream &O) {      O << "  }\n";      O << "  EmitComments(*MI);\n"; +    // Print the final newline +    O << "  O << \"\\n\";\n"; +    O << "  return true;\n";    } -  // Print the final newline -  O << "  O << \"\\n\";\n"; -  O << "  return true;\n";    O << "}\n";  }  | 

