Tidy up. Move for loop index declarations into for statements. Use unsigned instead of uint16_t for loop indices. Use unsigned instead of uint32_t for arguments to raw_ostream.indent.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@161033 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Craig Topper
2012-07-31 06:02:05 +00:00
parent e08789f5e2
commit de9e333e18

View File

@@ -170,7 +170,7 @@ static inline const char* stringForOperandEncoding(OperandEncoding encoding) {
} }
} }
void DisassemblerTables::emitOneID(raw_ostream &o, uint32_t &i, InstrUID id, void DisassemblerTables::emitOneID(raw_ostream &o, unsigned &i, InstrUID id,
bool addComma) const { bool addComma) const {
if (id) if (id)
o.indent(i * 2) << format("0x%hx", id); o.indent(i * 2) << format("0x%hx", id);
@@ -195,7 +195,7 @@ void DisassemblerTables::emitOneID(raw_ostream &o, uint32_t &i, InstrUID id,
/// ///
/// @param o - The output stream on which to emit the table. /// @param o - The output stream on which to emit the table.
/// @param i - The indentation level for that output stream. /// @param i - The indentation level for that output stream.
static void emitEmptyTable(raw_ostream &o, uint32_t &i) { static void emitEmptyTable(raw_ostream &o, unsigned &i) {
o.indent(i * 2) << "0x0, /* EmptyTable */\n"; o.indent(i * 2) << "0x0, /* EmptyTable */\n";
} }
@@ -209,9 +209,7 @@ static ModRMDecisionType getDecisionType(ModRMDecision &decision) {
bool satisfiesSplitRM = true; bool satisfiesSplitRM = true;
bool satisfiesSplitReg = true; bool satisfiesSplitReg = true;
uint16_t index; for (unsigned index = 0; index < 256; ++index) {
for (index = 0; index < 256; ++index) {
if (decision.instructionIDs[index] != decision.instructionIDs[0]) if (decision.instructionIDs[index] != decision.instructionIDs[0])
satisfiesOneEntry = false; satisfiesOneEntry = false;
@@ -295,12 +293,11 @@ DisassemblerTables::~DisassemblerTables() {
} }
void DisassemblerTables::emitModRMDecision(raw_ostream &o1, raw_ostream &o2, void DisassemblerTables::emitModRMDecision(raw_ostream &o1, raw_ostream &o2,
uint32_t &i1, uint32_t &i2, unsigned &i1, unsigned &i2,
ModRMDecision &decision) const { ModRMDecision &decision) const {
static uint64_t sTableNumber = 0; static uint32_t sTableNumber = 0;
static uint64_t sEntryNumber = 1; static uint32_t sEntryNumber = 1;
ModRMDecisionType dt = getDecisionType(decision); ModRMDecisionType dt = getDecisionType(decision);
uint16_t index;
if (dt == MODRM_ONEENTRY && decision.instructionIDs[0] == 0) if (dt == MODRM_ONEENTRY && decision.instructionIDs[0] == 0)
{ {
@@ -329,13 +326,13 @@ void DisassemblerTables::emitModRMDecision(raw_ostream &o1, raw_ostream &o2,
emitOneID(o1, i1, decision.instructionIDs[0xc0], true); // mod = 0b11 emitOneID(o1, i1, decision.instructionIDs[0xc0], true); // mod = 0b11
break; break;
case MODRM_SPLITREG: case MODRM_SPLITREG:
for (index = 0; index < 64; index += 8) for (unsigned index = 0; index < 64; index += 8)
emitOneID(o1, i1, decision.instructionIDs[index], true); emitOneID(o1, i1, decision.instructionIDs[index], true);
for (index = 0xc0; index < 256; index += 8) for (unsigned index = 0xc0; index < 256; index += 8)
emitOneID(o1, i1, decision.instructionIDs[index], true); emitOneID(o1, i1, decision.instructionIDs[index], true);
break; break;
case MODRM_FULL: case MODRM_FULL:
for (index = 0; index < 256; ++index) for (unsigned index = 0; index < 256; ++index)
emitOneID(o1, i1, decision.instructionIDs[index], true); emitOneID(o1, i1, decision.instructionIDs[index], true);
break; break;
} }
@@ -372,16 +369,14 @@ void DisassemblerTables::emitModRMDecision(raw_ostream &o1, raw_ostream &o2,
} }
void DisassemblerTables::emitOpcodeDecision(raw_ostream &o1, raw_ostream &o2, void DisassemblerTables::emitOpcodeDecision(raw_ostream &o1, raw_ostream &o2,
uint32_t &i1, uint32_t &i2, unsigned &i1, unsigned &i2,
OpcodeDecision &decision) const { OpcodeDecision &decision) const {
uint16_t index;
o2.indent(i2) << "{ /* struct OpcodeDecision */" << "\n"; o2.indent(i2) << "{ /* struct OpcodeDecision */" << "\n";
i2++; i2++;
o2.indent(i2) << "{" << "\n"; o2.indent(i2) << "{" << "\n";
i2++; i2++;
for (index = 0; index < 256; ++index) { for (unsigned index = 0; index < 256; ++index) {
o2.indent(i2); o2.indent(i2);
o2 << "/* 0x" << format("%02hhx", index) << " */" << "\n"; o2 << "/* 0x" << format("%02hhx", index) << " */" << "\n";
@@ -401,7 +396,7 @@ void DisassemblerTables::emitOpcodeDecision(raw_ostream &o1, raw_ostream &o2,
} }
void DisassemblerTables::emitContextDecision(raw_ostream &o1, raw_ostream &o2, void DisassemblerTables::emitContextDecision(raw_ostream &o1, raw_ostream &o2,
uint32_t &i1, uint32_t &i2, unsigned &i1, unsigned &i2,
ContextDecision &decision, ContextDecision &decision,
const char* name) const { const char* name) const {
o2.indent(i2) << "static const struct ContextDecision " << name << " = {\n"; o2.indent(i2) << "static const struct ContextDecision " << name << " = {\n";
@@ -409,9 +404,7 @@ void DisassemblerTables::emitContextDecision(raw_ostream &o1, raw_ostream &o2,
o2.indent(i2) << "{ /* opcodeDecisions */" << "\n"; o2.indent(i2) << "{ /* opcodeDecisions */" << "\n";
i2++; i2++;
unsigned index; for (unsigned index = 0; index < IC_max; ++index) {
for (index = 0; index < IC_max; ++index) {
o2.indent(i2) << "/* "; o2.indent(i2) << "/* ";
o2 << stringForContext((InstructionContext)index); o2 << stringForContext((InstructionContext)index);
o2 << " */"; o2 << " */";
@@ -429,17 +422,16 @@ void DisassemblerTables::emitContextDecision(raw_ostream &o1, raw_ostream &o2,
o2.indent(i2) << "};" << "\n"; o2.indent(i2) << "};" << "\n";
} }
void DisassemblerTables::emitInstructionInfo(raw_ostream &o, uint32_t &i) void DisassemblerTables::emitInstructionInfo(raw_ostream &o,
const { unsigned &i) const {
o.indent(i * 2) << "static const struct InstructionSpecifier "; o.indent(i * 2) << "static const struct InstructionSpecifier ";
o << INSTRUCTIONS_STR "[" << InstructionSpecifiers.size() << "] = {\n"; o << INSTRUCTIONS_STR "[" << InstructionSpecifiers.size() << "] = {\n";
i++; i++;
uint16_t numInstructions = InstructionSpecifiers.size(); unsigned numInstructions = InstructionSpecifiers.size();
uint16_t index, operandIndex;
for (index = 0; index < numInstructions; ++index) { for (unsigned index = 0; index < numInstructions; ++index) {
o.indent(i * 2) << "{ /* " << index << " */" << "\n"; o.indent(i * 2) << "{ /* " << index << " */" << "\n";
i++; i++;
@@ -454,7 +446,8 @@ void DisassemblerTables::emitInstructionInfo(raw_ostream &o, uint32_t &i)
o.indent(i * 2) << "{" << "\n"; o.indent(i * 2) << "{" << "\n";
i++; i++;
for (operandIndex = 0; operandIndex < X86_MAX_OPERANDS; ++operandIndex) { for (unsigned operandIndex = 0; operandIndex < X86_MAX_OPERANDS;
++operandIndex) {
o.indent(i * 2) << "{ "; o.indent(i * 2) << "{ ";
o <<stringForOperandEncoding((OperandEncoding)InstructionSpecifiers[index] o <<stringForOperandEncoding((OperandEncoding)InstructionSpecifiers[index]
.operands[operandIndex] .operands[operandIndex]
@@ -490,14 +483,12 @@ void DisassemblerTables::emitInstructionInfo(raw_ostream &o, uint32_t &i)
o.indent(i * 2) << "};" << "\n"; o.indent(i * 2) << "};" << "\n";
} }
void DisassemblerTables::emitContextTable(raw_ostream &o, uint32_t &i) const { void DisassemblerTables::emitContextTable(raw_ostream &o, unsigned &i) const {
uint16_t index;
o.indent(i * 2) << "static const InstructionContext " CONTEXTS_STR o.indent(i * 2) << "static const InstructionContext " CONTEXTS_STR
"[256] = {\n"; "[256] = {\n";
i++; i++;
for (index = 0; index < 256; ++index) { for (unsigned index = 0; index < 256; ++index) {
o.indent(i * 2); o.indent(i * 2);
if ((index & ATTR_VEXL) && (index & ATTR_REXW) && (index & ATTR_OPSIZE)) if ((index & ATTR_VEXL) && (index & ATTR_REXW) && (index & ATTR_OPSIZE))
@@ -579,7 +570,7 @@ void DisassemblerTables::emitContextTable(raw_ostream &o, uint32_t &i) const {
} }
void DisassemblerTables::emitContextDecisions(raw_ostream &o1, raw_ostream &o2, void DisassemblerTables::emitContextDecisions(raw_ostream &o1, raw_ostream &o2,
uint32_t &i1, uint32_t &i2) const { unsigned &i1, unsigned &i2) const {
emitContextDecision(o1, o2, i1, i2, *Tables[0], ONEBYTE_STR); emitContextDecision(o1, o2, i1, i2, *Tables[0], ONEBYTE_STR);
emitContextDecision(o1, o2, i1, i2, *Tables[1], TWOBYTE_STR); emitContextDecision(o1, o2, i1, i2, *Tables[1], TWOBYTE_STR);
emitContextDecision(o1, o2, i1, i2, *Tables[2], THREEBYTE38_STR); emitContextDecision(o1, o2, i1, i2, *Tables[2], THREEBYTE38_STR);
@@ -589,8 +580,8 @@ void DisassemblerTables::emitContextDecisions(raw_ostream &o1, raw_ostream &o2,
} }
void DisassemblerTables::emit(raw_ostream &o) const { void DisassemblerTables::emit(raw_ostream &o) const {
uint32_t i1 = 0; unsigned i1 = 0;
uint32_t i2 = 0; unsigned i2 = 0;
std::string s1; std::string s1;
std::string s2; std::string s2;
@@ -623,9 +614,7 @@ void DisassemblerTables::setTableFields(ModRMDecision &decision,
const ModRMFilter &filter, const ModRMFilter &filter,
InstrUID uid, InstrUID uid,
uint8_t opcode) { uint8_t opcode) {
unsigned index; for (unsigned index = 0; index < 256; ++index) {
for (index = 0; index < 256; ++index) {
if (filter.accepts(index)) { if (filter.accepts(index)) {
if (decision.instructionIDs[index] == uid) if (decision.instructionIDs[index] == uid)
continue; continue;
@@ -672,11 +661,9 @@ void DisassemblerTables::setTableFields(OpcodeType type,
InstrUID uid, InstrUID uid,
bool is32bit, bool is32bit,
bool ignoresVEX_L) { bool ignoresVEX_L) {
unsigned index;
ContextDecision &decision = *Tables[type]; ContextDecision &decision = *Tables[type];
for (index = 0; index < IC_max; ++index) { for (unsigned index = 0; index < IC_max; ++index) {
if (is32bit && inheritsFrom((InstructionContext)index, IC_64BIT)) if (is32bit && inheritsFrom((InstructionContext)index, IC_64BIT))
continue; continue;