X86: Move the function that prints memory args into the inst base class.

This commit is contained in:
Gabe Black 2009-01-06 22:46:28 -08:00
parent 9e24d8c599
commit 8cab1805f9
3 changed files with 43 additions and 27 deletions

View file

@ -64,7 +64,6 @@ namespace X86ISA
const SymbolTable *symtab) const const SymbolTable *symtab) const
{ {
std::stringstream response; std::stringstream response;
bool someAddr = false;
printMnemonic(response, instMnem, mnemonic); printMnemonic(response, instMnem, mnemonic);
if(flags[IsLoad]) if(flags[IsLoad])
@ -72,32 +71,8 @@ namespace X86ISA
else else
printSrcReg(response, 2, dataSize); printSrcReg(response, 2, dataSize);
response << ", "; response << ", ";
printSegment(response, segment); printMem(response, segment, scale, index, base, disp,
response << ":["; addressSize, false);
if(scale != 0 && _srcRegIdx[0] != ZeroReg)
{
if(scale != 1)
ccprintf(response, "%d*", scale);
printSrcReg(response, 0, addressSize);
someAddr = true;
}
if(_srcRegIdx[1] != ZeroReg)
{
if(someAddr)
response << " + ";
printSrcReg(response, 1, addressSize);
someAddr = true;
}
if(disp != 0)
{
if(someAddr)
response << " + ";
ccprintf(response, "%#x", disp);
someAddr = true;
}
if(!someAddr)
response << "0";
response << "]";
return response.str(); return response.str();
} }
} }

View file

@ -240,6 +240,44 @@ namespace X86ISA
} }
} }
void X86StaticInst::printMem(std::ostream &os, uint8_t segment,
uint8_t scale, RegIndex index, RegIndex base,
uint64_t disp, uint8_t addressSize, bool rip) const
{
bool someAddr = false;
printSegment(os, segment);
os << ":[";
if (rip) {
os << "rip";
someAddr = true;
} else {
if (scale != 0 && index != ZeroReg)
{
if(scale != 1)
ccprintf(os, "%d*", scale);
printReg(os, index, addressSize);
someAddr = true;
}
if (base != ZeroReg)
{
if(someAddr)
os << " + ";
printReg(os, base, addressSize);
someAddr = true;
}
}
if (disp != 0)
{
if(someAddr)
os << " + ";
ccprintf(os, "%#x", disp);
someAddr = true;
}
if (!someAddr)
os << "0";
os << "]";
}
std::string X86StaticInst::generateDisassembly(Addr pc, std::string X86StaticInst::generateDisassembly(Addr pc,
const SymbolTable *symtab) const const SymbolTable *symtab) const
{ {

View file

@ -89,6 +89,9 @@ namespace X86ISA
void printReg(std::ostream &os, int reg, int size) const; void printReg(std::ostream &os, int reg, int size) const;
void printSrcReg(std::ostream &os, int reg, int size) const; void printSrcReg(std::ostream &os, int reg, int size) const;
void printDestReg(std::ostream &os, int reg, int size) const; void printDestReg(std::ostream &os, int reg, int size) const;
void printMem(std::ostream &os, uint8_t segment,
uint8_t scale, RegIndex index, RegIndex base,
uint64_t disp, uint8_t addressSize, bool rip) const;
inline uint64_t merge(uint64_t into, uint64_t val, int size) const inline uint64_t merge(uint64_t into, uint64_t val, int size) const
{ {