aboutsummaryrefslogtreecommitdiffstats
path: root/utils/TableGen
diff options
context:
space:
mode:
authorTim Northover <Tim.Northover@arm.com>2013-01-10 15:17:36 +0000
committerTim Northover <Tim.Northover@arm.com>2013-01-10 15:17:36 +0000
commit88abcde3b47dcd9b64e8b0cd6558481d692609eb (patch)
treec6701ba770a23990a10c6df1181b7594a103351d /utils/TableGen
parent2b8f6ae6b791099ceff8ad87bcca7f165655c5c7 (diff)
downloadexternal_llvm-88abcde3b47dcd9b64e8b0cd6558481d692609eb.zip
external_llvm-88abcde3b47dcd9b64e8b0cd6558481d692609eb.tar.gz
external_llvm-88abcde3b47dcd9b64e8b0cd6558481d692609eb.tar.bz2
Make TableGen mangle operand method names before putting in enum.
The purpose of this patch is to allow PredicateMethods to be set to something like "isUImm<8>", calling a C++ template method to reduce code duplication. For this to work, the PredicateMethod must be mangled into a valid C++ identifier for insertion into an enum. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172073 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen')
-rw-r--r--utils/TableGen/AsmMatcherEmitter.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/utils/TableGen/AsmMatcherEmitter.cpp b/utils/TableGen/AsmMatcherEmitter.cpp
index bc0cf43..f0fb970 100644
--- a/utils/TableGen/AsmMatcherEmitter.cpp
+++ b/utils/TableGen/AsmMatcherEmitter.cpp
@@ -1658,6 +1658,16 @@ void MatchableInfo::buildAliasResultOperands() {
}
}
+// Modify a string so that it is suitable for use as an enum tag.
+static std::string mangle(const std::string &Name) {
+ std::string MangledName = Name;
+ for (unsigned i = 0; i < MangledName.size(); ++i) {
+ if (!isalnum(MangledName[i]) && MangledName[i] != '_')
+ MangledName[i] = '_';
+ }
+ return MangledName;
+}
+
static unsigned getConverterOperandID(const std::string &Name,
SetVector<std::string> &Table,
bool &IsNew) {
@@ -1754,7 +1764,7 @@ static void emitConvertFuncs(CodeGenTarget &Target, StringRef ClassName,
// Remember this converter for the kind enum.
unsigned KindID = OperandConversionKinds.size();
- OperandConversionKinds.insert("CVT_" + AsmMatchConverter);
+ OperandConversionKinds.insert("CVT_" + mangle(AsmMatchConverter));
// Add the converter row for this instruction.
ConversionTable.push_back(std::vector<uint8_t>());
@@ -1762,7 +1772,7 @@ static void emitConvertFuncs(CodeGenTarget &Target, StringRef ClassName,
ConversionTable.back().push_back(CVT_Done);
// Add the handler to the conversion driver function.
- CvtOS << " case CVT_" << AsmMatchConverter << ":\n"
+ CvtOS << " case CVT_" << mangle(AsmMatchConverter) << ":\n"
<< " " << AsmMatchConverter << "(Inst, Operands);\n"
<< " break;\n";
@@ -1800,6 +1810,7 @@ static void emitConvertFuncs(CodeGenTarget &Target, StringRef ClassName,
// the index of its entry in the vector).
std::string Name = "CVT_" + (Op.Class->isRegisterClass() ? "Reg" :
Op.Class->RenderMethod);
+ Name = mangle(Name);
bool IsNewConverter = false;
unsigned ID = getConverterOperandID(Name, OperandConversionKinds,