diff options
author | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2012-03-30 21:12:52 +0000 |
---|---|---|
committer | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2012-03-30 21:12:52 +0000 |
commit | c19f72bd83e8cb2cc31257008ee9d7797dbf3dbb (patch) | |
tree | c7bd20bf0c99fc1aadc1932225299b1ccaebae9f | |
parent | 0d4e2ea00eac5d51a74a54dd504a8f34580041d7 (diff) | |
download | external_llvm-c19f72bd83e8cb2cc31257008ee9d7797dbf3dbb.zip external_llvm-c19f72bd83e8cb2cc31257008ee9d7797dbf3dbb.tar.gz external_llvm-c19f72bd83e8cb2cc31257008ee9d7797dbf3dbb.tar.bz2 |
Use SequenceToOffsetTable in emitRegisterNameString.
This allows suffix sharing in register names. (AX is a suffix of EAX).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153777 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | utils/TableGen/AsmWriterEmitter.cpp | 22 | ||||
-rw-r--r-- | utils/TableGen/SequenceToOffsetTable.h | 14 |
2 files changed, 28 insertions, 8 deletions
diff --git a/utils/TableGen/AsmWriterEmitter.cpp b/utils/TableGen/AsmWriterEmitter.cpp index c4812dc..f840709 100644 --- a/utils/TableGen/AsmWriterEmitter.cpp +++ b/utils/TableGen/AsmWriterEmitter.cpp @@ -16,6 +16,7 @@ #include "AsmWriterInst.h" #include "CodeGenTarget.h" #include "StringToOffsetTable.h" +#include "SequenceToOffsetTable.h" #include "llvm/ADT/Twine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/MathExtras.h" @@ -462,12 +463,12 @@ void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) { static void emitRegisterNameString(raw_ostream &O, StringRef AltName, const std::vector<CodeGenRegister*> &Registers) { - StringToOffsetTable StringTable; - O << " static const unsigned RegAsmOffset" << AltName << "[] = {\n "; + SequenceToOffsetTable<std::string> StringTable; + SmallVector<std::string, 4> AsmNames(Registers.size()); for (unsigned i = 0, e = Registers.size(); i != e; ++i) { const CodeGenRegister &Reg = *Registers[i]; + std::string &AsmName = AsmNames[i]; - std::string AsmName; // "NoRegAltName" is special. We don't need to do a lookup for that, // as it's just a reference to the default register name. if (AltName == "" || AltName == "NoRegAltName") { @@ -495,8 +496,17 @@ emitRegisterNameString(raw_ostream &O, StringRef AltName, AsmName = AltNames[Idx]; } } + StringTable.add(AsmName); + } + + StringTable.layout(); + O << " static const char AsmStrs" << AltName << "[] = {\n"; + StringTable.emit(O, printChar); + O << " };\n\n"; - O << StringTable.GetOrAddStringOffset(AsmName); + O << " static const unsigned RegAsmOffset" << AltName << "[] = {\n "; + for (unsigned i = 0, e = Registers.size(); i != e; ++i) { + O << StringTable.get(AsmNames[i]); if (((i + 1) % 14) == 0) O << ",\n "; else @@ -506,10 +516,6 @@ emitRegisterNameString(raw_ostream &O, StringRef AltName, O << "0\n" << " };\n" << "\n"; - - O << " const char *AsmStrs" << AltName << " =\n"; - StringTable.EmitString(O); - O << ";\n"; } void AsmWriterEmitter::EmitGetRegisterName(raw_ostream &O) { diff --git a/utils/TableGen/SequenceToOffsetTable.h b/utils/TableGen/SequenceToOffsetTable.h index 09dccbb..97c764e 100644 --- a/utils/TableGen/SequenceToOffsetTable.h +++ b/utils/TableGen/SequenceToOffsetTable.h @@ -21,6 +21,7 @@ #include <algorithm> #include <vector> #include <cassert> +#include <cctype> namespace llvm { @@ -120,6 +121,19 @@ public: } }; +// Helper function for SequenceToOffsetTable<string>. +static inline void printChar(raw_ostream &OS, char C) { + unsigned char UC(C); + if (isalnum(UC) || ispunct(UC)) { + OS << '\''; + if (C == '\\' || C == '\'') + OS << '\\'; + OS << C << '\''; + } else { + OS << unsigned(UC); + } +} + } // end namespace llvm #endif |