mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
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
This commit is contained in:
parent
bb9dbb7d6b
commit
d3c9d9447e
@ -25,14 +25,14 @@ namespace llvm {
|
|||||||
///
|
///
|
||||||
class MCInstrInfo {
|
class MCInstrInfo {
|
||||||
const MCInstrDesc *Desc; // Raw array to allow static init'n
|
const MCInstrDesc *Desc; // Raw array to allow static init'n
|
||||||
const unsigned *InstrNameIndices; // Array for name indices in InstrNameData
|
const uint16_t *InstrNameIndices; // Array for name indices in InstrNameData
|
||||||
const char *InstrNameData; // Instruction name string pool
|
const char *InstrNameData; // Instruction name string pool
|
||||||
unsigned NumOpcodes; // Number of entries in the desc array
|
unsigned NumOpcodes; // Number of entries in the desc array
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// InitMCInstrInfo - Initialize MCInstrInfo, called by TableGen
|
/// InitMCInstrInfo - Initialize MCInstrInfo, called by TableGen
|
||||||
/// auto-generated routines. *DO NOT USE*.
|
/// auto-generated routines. *DO NOT USE*.
|
||||||
void InitMCInstrInfo(const MCInstrDesc *D, const unsigned *NI, const char *ND,
|
void InitMCInstrInfo(const MCInstrDesc *D, const uint16_t *NI, const char *ND,
|
||||||
unsigned NO) {
|
unsigned NO) {
|
||||||
Desc = D;
|
Desc = D;
|
||||||
InstrNameIndices = NI;
|
InstrNameIndices = NI;
|
||||||
|
@ -2023,7 +2023,7 @@ static void EmitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target,
|
|||||||
// Emit the static custom operand parsing table;
|
// Emit the static custom operand parsing table;
|
||||||
OS << "namespace {\n";
|
OS << "namespace {\n";
|
||||||
OS << " struct OperandMatchEntry {\n";
|
OS << " struct OperandMatchEntry {\n";
|
||||||
OS << " static const char *MnemonicTable;\n";
|
OS << " static const char *const MnemonicTable;\n";
|
||||||
OS << " unsigned OperandMask;\n";
|
OS << " unsigned OperandMask;\n";
|
||||||
OS << " uint16_t Mnemonic;\n";
|
OS << " uint16_t Mnemonic;\n";
|
||||||
OS << " " << getMinimalTypeForRange(Info.Classes.size())
|
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.
|
// Store a pascal-style length byte in the mnemonic.
|
||||||
std::string LenMnemonic = char(II.Mnemonic.size()) + II.Mnemonic.str();
|
std::string LenMnemonic = char(II.Mnemonic.size()) + II.Mnemonic.str();
|
||||||
OS << ", " << StringTable.GetOrAddStringOffset(LenMnemonic, false)
|
unsigned Idx = StringTable.GetOrAddStringOffset(LenMnemonic, false);
|
||||||
<< " /* " << II.Mnemonic << " */";
|
assert(Idx <= 0xffff && "String offset too large to fit in table");
|
||||||
|
OS << ", " << Idx << " /* " << II.Mnemonic << " */";
|
||||||
|
|
||||||
OS << ", " << OMI.CI->Name
|
OS << ", " << OMI.CI->Name
|
||||||
<< ", ";
|
<< ", ";
|
||||||
@ -2097,7 +2098,7 @@ static void EmitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target,
|
|||||||
}
|
}
|
||||||
OS << "};\n\n";
|
OS << "};\n\n";
|
||||||
|
|
||||||
OS << "const char *OperandMatchEntry::MnemonicTable =\n";
|
OS << "const char *const OperandMatchEntry::MnemonicTable =\n";
|
||||||
StringTable.EmitString(OS);
|
StringTable.EmitString(OS);
|
||||||
OS << ";\n\n";
|
OS << ";\n\n";
|
||||||
|
|
||||||
@ -2320,7 +2321,7 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
|
|||||||
// following the mnemonic.
|
// following the mnemonic.
|
||||||
OS << "namespace {\n";
|
OS << "namespace {\n";
|
||||||
OS << " struct MatchEntry {\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 Opcode;\n";
|
||||||
OS << " uint16_t Mnemonic;\n";
|
OS << " uint16_t Mnemonic;\n";
|
||||||
OS << " " << getMinimalTypeForRange(Info.Matchables.size())
|
OS << " " << getMinimalTypeForRange(Info.Matchables.size())
|
||||||
@ -2363,10 +2364,11 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
|
|||||||
|
|
||||||
// Store a pascal-style length byte in the mnemonic.
|
// Store a pascal-style length byte in the mnemonic.
|
||||||
std::string LenMnemonic = char(II.Mnemonic.size()) + II.Mnemonic.str();
|
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() << "::"
|
OS << " { " << Target.getName() << "::"
|
||||||
<< II.getResultInst()->TheDef->getName() << ", "
|
<< II.getResultInst()->TheDef->getName() << ", "
|
||||||
<< StringTable.GetOrAddStringOffset(LenMnemonic, false)
|
<< Idx << " /* " << II.Mnemonic << " */"
|
||||||
<< " /* " << II.Mnemonic << " */"
|
|
||||||
<< ", " << II.ConversionFnKind << ", { ";
|
<< ", " << II.ConversionFnKind << ", { ";
|
||||||
for (unsigned i = 0, e = II.AsmOperands.size(); i != e; ++i) {
|
for (unsigned i = 0, e = II.AsmOperands.size(); i != e; ++i) {
|
||||||
MatchableInfo::AsmOperand &Op = II.AsmOperands[i];
|
MatchableInfo::AsmOperand &Op = II.AsmOperands[i];
|
||||||
@ -2390,7 +2392,7 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
|
|||||||
|
|
||||||
OS << "};\n\n";
|
OS << "};\n\n";
|
||||||
|
|
||||||
OS << "const char *MatchEntry::MnemonicTable =\n";
|
OS << "const char *const MatchEntry::MnemonicTable =\n";
|
||||||
StringTable.EmitString(OS);
|
StringTable.EmitString(OS);
|
||||||
OS << ";\n\n";
|
OS << ";\n\n";
|
||||||
|
|
||||||
|
@ -306,6 +306,7 @@ void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Bias offset by one since we want 0 as a sentinel.
|
// Bias offset by one since we want 0 as a sentinel.
|
||||||
|
assert((Idx+1) <= 0xffff && "String offset too large to fit in table");
|
||||||
OpcodeInfo.push_back(Idx+1);
|
OpcodeInfo.push_back(Idx+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,7 +374,7 @@ void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) {
|
|||||||
O << " };\n\n";
|
O << " };\n\n";
|
||||||
|
|
||||||
// Emit the string itself.
|
// Emit the string itself.
|
||||||
O << " const char *AsmStrs = \n";
|
O << " const char *const AsmStrs = \n";
|
||||||
StringTable.EmitString(O);
|
StringTable.EmitString(O);
|
||||||
O << ";\n\n";
|
O << ";\n\n";
|
||||||
|
|
||||||
@ -496,7 +497,9 @@ emitRegisterNameString(raw_ostream &O, StringRef AltName,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
O << StringTable.GetOrAddStringOffset(AsmName);
|
unsigned Idx = StringTable.GetOrAddStringOffset(AsmName);
|
||||||
|
assert(Idx <= 0xffff && "String offset too large to fit in table");
|
||||||
|
O << Idx;
|
||||||
if (((i + 1) % 14) == 0)
|
if (((i + 1) % 14) == 0)
|
||||||
O << ",\n ";
|
O << ",\n ";
|
||||||
else
|
else
|
||||||
@ -591,7 +594,9 @@ void AsmWriterEmitter::EmitGetInstructionName(raw_ostream &O) {
|
|||||||
if ((i % 14) == 0)
|
if ((i % 14) == 0)
|
||||||
O << "\n ";
|
O << "\n ";
|
||||||
|
|
||||||
O << StringTable.GetOrAddStringOffset(AsmName) << ", ";
|
unsigned Idx = StringTable.GetOrAddStringOffset(AsmName);
|
||||||
|
assert(Idx <= 0xffff && "String offset too large to fit in table");
|
||||||
|
O << Idx << ", ";
|
||||||
}
|
}
|
||||||
O << "0\n"
|
O << "0\n"
|
||||||
<< " };\n"
|
<< " };\n"
|
||||||
|
@ -213,18 +213,20 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
|
|||||||
OperandInfoIDs, OS);
|
OperandInfoIDs, OS);
|
||||||
OS << "};\n\n";
|
OS << "};\n\n";
|
||||||
|
|
||||||
OS << "extern const unsigned " << TargetName <<"InstrNameIndices[] = {\n ";
|
OS << "extern const uint16_t " << TargetName <<"InstrNameIndices[] = {\n ";
|
||||||
StringToOffsetTable StringTable;
|
StringToOffsetTable StringTable;
|
||||||
for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
|
for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
|
||||||
const CodeGenInstruction *Instr = NumberedInstructions[i];
|
const CodeGenInstruction *Instr = NumberedInstructions[i];
|
||||||
OS << StringTable.GetOrAddStringOffset(Instr->TheDef->getName()) << "U, ";
|
unsigned Idx = StringTable.GetOrAddStringOffset(Instr->TheDef->getName());
|
||||||
|
assert(Idx <= 0xffff && "String offset too large to fit in table");
|
||||||
|
OS << Idx << "U, ";
|
||||||
if (i % 8 == 0)
|
if (i % 8 == 0)
|
||||||
OS << "\n ";
|
OS << "\n ";
|
||||||
}
|
}
|
||||||
|
|
||||||
OS << "\n};\n\n";
|
OS << "\n};\n\n";
|
||||||
|
|
||||||
OS << "const char *" << TargetName << "InstrNameData =\n";
|
OS << "extern const char *const " << TargetName << "InstrNameData =\n";
|
||||||
StringTable.EmitString(OS);
|
StringTable.EmitString(OS);
|
||||||
OS << ";\n\n";
|
OS << ";\n\n";
|
||||||
|
|
||||||
@ -257,7 +259,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
|
|||||||
|
|
||||||
OS << "namespace llvm {\n";
|
OS << "namespace llvm {\n";
|
||||||
OS << "extern const MCInstrDesc " << TargetName << "Insts[];\n";
|
OS << "extern const MCInstrDesc " << TargetName << "Insts[];\n";
|
||||||
OS << "extern const unsigned " << TargetName << "InstrNameIndices[];\n";
|
OS << "extern const uint16_t " << TargetName << "InstrNameIndices[];\n";
|
||||||
OS << "extern const char *" << TargetName << "InstrNameData;\n";
|
OS << "extern const char *" << TargetName << "InstrNameData;\n";
|
||||||
OS << ClassName << "::" << ClassName << "(int SO, int DO)\n"
|
OS << ClassName << "::" << ClassName << "(int SO, int DO)\n"
|
||||||
<< " : TargetInstrInfoImpl(SO, DO) {\n"
|
<< " : TargetInstrInfoImpl(SO, DO) {\n"
|
||||||
|
@ -40,6 +40,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EmitString(raw_ostream &O) {
|
void EmitString(raw_ostream &O) {
|
||||||
|
assert(AggregateString.size() <= 65536 &&
|
||||||
|
"Aggregate string too large to be portable");
|
||||||
|
|
||||||
// Escape the string.
|
// Escape the string.
|
||||||
SmallString<256> Str;
|
SmallString<256> Str;
|
||||||
raw_svector_ostream(Str).write_escaped(AggregateString);
|
raw_svector_ostream(Str).write_escaped(AggregateString);
|
||||||
|
Loading…
Reference in New Issue
Block a user