diff options
author | Craig Topper <craig.topper@gmail.com> | 2012-03-07 05:17:23 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@gmail.com> | 2012-03-07 05:17:23 +0000 |
commit | d3c9d9447ed7b5b8d3800b871ff162ae2df9fd5b (patch) | |
tree | d08e8a5fda30f7bc303ffa5fab41037e447e9228 /utils/TableGen/AsmMatcherEmitter.cpp | |
parent | bb9dbb7d6b4f39b74b755795e31b219a5518dd77 (diff) | |
download | llvm-d3c9d9447ed7b5b8d3800b871ff162ae2df9fd5b.tar.gz llvm-d3c9d9447ed7b5b8d3800b871ff162ae2df9fd5b.tar.bz2 llvm-d3c9d9447ed7b5b8d3800b871ff162ae2df9fd5b.tar.xz |
Use uint16_t to store InstrNameIndices in MCInstrInfo. Add asserts to protect all 16-bit string table offsets. Also make sure the string to offset table string is not larger than 65536 characters since larger string literals aren't portable.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152202 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/AsmMatcherEmitter.cpp')
-rw-r--r-- | utils/TableGen/AsmMatcherEmitter.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/utils/TableGen/AsmMatcherEmitter.cpp b/utils/TableGen/AsmMatcherEmitter.cpp index cdcc496e7d..4afee21523 100644 --- a/utils/TableGen/AsmMatcherEmitter.cpp +++ b/utils/TableGen/AsmMatcherEmitter.cpp @@ -2023,7 +2023,7 @@ static void EmitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target, // Emit the static custom operand parsing table; OS << "namespace {\n"; OS << " struct OperandMatchEntry {\n"; - OS << " static const char *MnemonicTable;\n"; + OS << " static const char *const MnemonicTable;\n"; OS << " unsigned OperandMask;\n"; OS << " uint16_t Mnemonic;\n"; OS << " " << getMinimalTypeForRange(Info.Classes.size()) @@ -2079,8 +2079,9 @@ static void EmitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target, // Store a pascal-style length byte in the mnemonic. std::string LenMnemonic = char(II.Mnemonic.size()) + II.Mnemonic.str(); - OS << ", " << StringTable.GetOrAddStringOffset(LenMnemonic, false) - << " /* " << II.Mnemonic << " */"; + unsigned Idx = StringTable.GetOrAddStringOffset(LenMnemonic, false); + assert(Idx <= 0xffff && "String offset too large to fit in table"); + OS << ", " << Idx << " /* " << II.Mnemonic << " */"; OS << ", " << OMI.CI->Name << ", "; @@ -2097,7 +2098,7 @@ static void EmitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target, } OS << "};\n\n"; - OS << "const char *OperandMatchEntry::MnemonicTable =\n"; + OS << "const char *const OperandMatchEntry::MnemonicTable =\n"; StringTable.EmitString(OS); OS << ";\n\n"; @@ -2320,7 +2321,7 @@ void AsmMatcherEmitter::run(raw_ostream &OS) { // following the mnemonic. OS << "namespace {\n"; OS << " struct MatchEntry {\n"; - OS << " static const char *MnemonicTable;\n"; + OS << " static const char *const MnemonicTable;\n"; OS << " uint16_t Opcode;\n"; OS << " uint16_t Mnemonic;\n"; OS << " " << getMinimalTypeForRange(Info.Matchables.size()) @@ -2363,10 +2364,11 @@ void AsmMatcherEmitter::run(raw_ostream &OS) { // Store a pascal-style length byte in the mnemonic. std::string LenMnemonic = char(II.Mnemonic.size()) + II.Mnemonic.str(); + unsigned Idx = StringTable.GetOrAddStringOffset(LenMnemonic, false); + assert(Idx <= 0xffff && "String offset too large to fit in table"); OS << " { " << Target.getName() << "::" << II.getResultInst()->TheDef->getName() << ", " - << StringTable.GetOrAddStringOffset(LenMnemonic, false) - << " /* " << II.Mnemonic << " */" + << Idx << " /* " << II.Mnemonic << " */" << ", " << II.ConversionFnKind << ", { "; for (unsigned i = 0, e = II.AsmOperands.size(); i != e; ++i) { MatchableInfo::AsmOperand &Op = II.AsmOperands[i]; @@ -2390,7 +2392,7 @@ void AsmMatcherEmitter::run(raw_ostream &OS) { OS << "};\n\n"; - OS << "const char *MatchEntry::MnemonicTable =\n"; + OS << "const char *const MatchEntry::MnemonicTable =\n"; StringTable.EmitString(OS); OS << ";\n\n"; |