1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

MCAssembler: Add assorted dump() methods.

llvm-svn: 96089
This commit is contained in:
Daniel Dunbar 2010-02-13 09:28:03 +00:00
parent 1581cae46f
commit a699e834fb
2 changed files with 193 additions and 31 deletions

View File

@ -46,7 +46,7 @@ struct MCAsmFixup {
uint64_t FixedValue;
public:
MCAsmFixup(uint64_t _Offset, const MCExpr &_Value, unsigned _Size)
MCAsmFixup(uint64_t _Offset, const MCExpr &_Value, unsigned _Size)
: Offset(_Offset), Value(&_Value), Size(_Size), FixedValue(0) {}
};
@ -151,7 +151,7 @@ public:
uint64_t getAddress() const;
uint64_t getFileSize() const {
uint64_t getFileSize() const {
assert(FileSize != ~UINT64_C(0) && "File size not set!");
return FileSize;
}
@ -169,6 +169,8 @@ public:
/// @}
static bool classof(const MCFragment *O) { return true; }
virtual void dump();
};
class MCDataFragment : public MCFragment {
@ -189,10 +191,12 @@ public:
/// @}
static bool classof(const MCFragment *F) {
return F->getKind() == MCFragment::FT_Data;
static bool classof(const MCFragment *F) {
return F->getKind() == MCFragment::FT_Data;
}
static bool classof(const MCDataFragment *) { return true; }
virtual void dump();
};
class MCAlignFragment : public MCFragment {
@ -224,7 +228,7 @@ public:
}
unsigned getAlignment() const { return Alignment; }
int64_t getValue() const { return Value; }
unsigned getValueSize() const { return ValueSize; }
@ -233,10 +237,12 @@ public:
/// @}
static bool classof(const MCFragment *F) {
return F->getKind() == MCFragment::FT_Align;
static bool classof(const MCFragment *F) {
return F->getKind() == MCFragment::FT_Align;
}
static bool classof(const MCAlignFragment *) { return true; }
virtual void dump();
};
class MCFillFragment : public MCFragment {
@ -251,7 +257,7 @@ class MCFillFragment : public MCFragment {
public:
MCFillFragment(const MCExpr &_Value, unsigned _ValueSize, uint64_t _Count,
MCSectionData *SD = 0)
MCSectionData *SD = 0)
: MCFragment(FT_Fill, SD),
Value(&_Value), ValueSize(_ValueSize), Count(_Count) {}
@ -263,24 +269,26 @@ public:
}
const MCExpr &getValue() const { return *Value; }
unsigned getValueSize() const { return ValueSize; }
uint64_t getCount() const { return Count; }
/// @}
static bool classof(const MCFragment *F) {
return F->getKind() == MCFragment::FT_Fill;
static bool classof(const MCFragment *F) {
return F->getKind() == MCFragment::FT_Fill;
}
static bool classof(const MCFillFragment *) { return true; }
virtual void dump();
};
class MCOrgFragment : public MCFragment {
/// Offset - The offset this fragment should start at.
const MCExpr *Offset;
/// Value - Value to use for filling bytes.
/// Value - Value to use for filling bytes.
int8_t Value;
public:
@ -297,15 +305,17 @@ public:
}
const MCExpr &getOffset() const { return *Offset; }
uint8_t getValue() const { return Value; }
/// @}
static bool classof(const MCFragment *F) {
return F->getKind() == MCFragment::FT_Org;
static bool classof(const MCFragment *F) {
return F->getKind() == MCFragment::FT_Org;
}
static bool classof(const MCOrgFragment *) { return true; }
virtual void dump();
};
/// MCZeroFillFragment - Represent data which has a fixed size and alignment,
@ -331,15 +341,17 @@ public:
}
uint64_t getSize() const { return Size; }
unsigned getAlignment() const { return Alignment; }
/// @}
static bool classof(const MCFragment *F) {
return F->getKind() == MCFragment::FT_ZeroFill;
static bool classof(const MCFragment *F) {
return F->getKind() == MCFragment::FT_ZeroFill;
}
static bool classof(const MCZeroFillFragment *) { return true; }
virtual void dump();
};
// FIXME: Should this be a separate class, or just merged into MCSection? Since
@ -387,7 +399,7 @@ private:
/// @}
public:
public:
// Only for use as sentinel.
MCSectionData();
MCSectionData(const MCSection &Section, MCAssembler *A = 0);
@ -425,28 +437,30 @@ public:
//
// FIXME: This could all be kept private to the assembler implementation.
uint64_t getAddress() const {
uint64_t getAddress() const {
assert(Address != ~UINT64_C(0) && "Address not set!");
return Address;
}
void setAddress(uint64_t Value) { Address = Value; }
uint64_t getSize() const {
uint64_t getSize() const {
assert(Size != ~UINT64_C(0) && "File size not set!");
return Size;
}
void setSize(uint64_t Value) { Size = Value; }
uint64_t getFileSize() const {
uint64_t getFileSize() const {
assert(FileSize != ~UINT64_C(0) && "File size not set!");
return FileSize;
}
void setFileSize(uint64_t Value) { FileSize = Value; }
void setFileSize(uint64_t Value) { FileSize = Value; }
bool hasInstructions() const { return HasInstructions; }
void setHasInstructions(bool Value) { HasInstructions = Value; }
/// @}
void dump();
};
// FIXME: Same concerns as with SectionData.
@ -460,7 +474,7 @@ public:
/// Offset - The offset to apply to the fragment address to form this symbol's
/// value.
uint64_t Offset;
/// IsExternal - True if this symbol is visible outside this translation
/// unit.
unsigned IsExternal : 1;
@ -506,10 +520,10 @@ public:
/// @}
/// @name Symbol Attributes
/// @{
bool isExternal() const { return IsExternal; }
void setExternal(bool Value) { IsExternal = Value; }
bool isPrivateExtern() const { return IsPrivateExtern; }
void setPrivateExtern(bool Value) { IsPrivateExtern = Value; }
@ -542,14 +556,16 @@ public:
/// setFlags - Set the (implementation defined) symbol flags.
void setFlags(uint32_t Value) { Flags = Value; }
/// getIndex - Get the (implementation defined) index.
uint64_t getIndex() const { return Index; }
/// setIndex - Set the (implementation defined) index.
void setIndex(uint64_t Value) { Index = Value; }
/// @}
/// @}
void dump();
};
// FIXME: This really doesn't belong here. See comments below.
@ -578,7 +594,7 @@ private:
MCContext &Context;
raw_ostream &OS;
iplist<MCSectionData> Sections;
iplist<MCSymbolData> Symbols;
@ -622,7 +638,7 @@ public:
/// @{
const SectionDataListType &getSectionList() const { return Sections; }
SectionDataListType &getSectionList() { return Sections; }
SectionDataListType &getSectionList() { return Sections; }
iterator begin() { return Sections.begin(); }
const_iterator begin() const { return Sections.begin(); }
@ -669,6 +685,8 @@ public:
size_t indirect_symbol_size() const { return IndirectSymbols.size(); }
/// @}
void dump();
};
} // end namespace llvm

View File

@ -16,11 +16,13 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MachO.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/Debug.h"
#include <vector>
using namespace llvm;
@ -1148,6 +1150,10 @@ static void WriteFileData(raw_ostream &OS, const MCSectionData &SD,
}
void MCAssembler::Finish() {
DEBUG_WITH_TYPE("mc-dump", {
llvm::errs() << "assembler backend - pre-layout\n--\n";
dump(); });
// Layout the concrete sections and fragments.
uint64_t Address = 0;
MCSectionData *Prev = 0;
@ -1186,9 +1192,147 @@ void MCAssembler::Finish() {
Address += SD.getSize();
}
DEBUG_WITH_TYPE("mc-dump", {
llvm::errs() << "assembler backend - post-layout\n--\n";
dump(); });
// Write the object file.
MachObjectWriter MOW(OS);
MOW.WriteObject(*this);
OS.flush();
}
// Debugging methods
namespace llvm {
raw_ostream &operator<<(raw_ostream &OS, const MCAsmFixup &AF) {
OS << "<MCAsmFixup" << " Offset:" << AF.Offset << " Value:" << AF.Value
<< " Size:" << AF.Size << ">";
return OS;
}
}
void MCFragment::dump() {
raw_ostream &OS = llvm::errs();
OS << "<MCFragment " << (void*) this << " Offset:" << Offset
<< " FileSize:" << FileSize;
if (!Fixups.empty()) {
OS << "\n";
OS << " Fixups:[";
for (fixup_iterator it = fixup_begin(), ie = fixup_end(); it != ie; ++it) {
if (it != fixup_begin()) OS << ",\n ";
OS << *it;
}
OS << "]";
}
OS << ">";
}
void MCAlignFragment::dump() {
raw_ostream &OS = llvm::errs();
OS << "<MCAlignFragment ";
this->MCFragment::dump();
OS << "\n ";
OS << " Alignment:" << getAlignment()
<< " Value:" << getValue() << " ValueSize:" << getValueSize()
<< " MaxBytesToEmit:" << getMaxBytesToEmit() << ">";
}
void MCDataFragment::dump() {
raw_ostream &OS = llvm::errs();
OS << "<MCDataFragment ";
this->MCFragment::dump();
OS << "\n ";
OS << " Contents:[";
for (unsigned i = 0, e = getContents().size(); i != e; ++i) {
if (i) OS << ",";
OS << hexdigit((Contents[i] >> 4) & 0xF) << hexdigit(Contents[i] & 0xF);
}
OS << "]>";
}
void MCFillFragment::dump() {
raw_ostream &OS = llvm::errs();
OS << "<MCFillFragment ";
this->MCFragment::dump();
OS << "\n ";
OS << " Value:" << getValue() << " ValueSize:" << getValueSize()
<< " Count:" << getCount() << ">";
}
void MCOrgFragment::dump() {
raw_ostream &OS = llvm::errs();
OS << "<MCOrgFragment ";
this->MCFragment::dump();
OS << "\n ";
OS << " Offset:" << getOffset() << " Value:" << getValue() << ">";
}
void MCZeroFillFragment::dump() {
raw_ostream &OS = llvm::errs();
OS << "<MCZeroFillFragment ";
this->MCFragment::dump();
OS << "\n ";
OS << " Size:" << getSize() << " Alignment:" << getAlignment() << ">";
}
void MCSectionData::dump() {
raw_ostream &OS = llvm::errs();
OS << "<MCSectionData";
OS << " Alignment:" << getAlignment() << " Address:" << Address
<< " Size:" << Size << " FileSize:" << FileSize
<< " Fragments:[";
for (iterator it = begin(), ie = end(); it != ie; ++it) {
if (it != begin()) OS << ",\n ";
it->dump();
}
OS << "]>";
}
void MCSymbolData::dump() {
raw_ostream &OS = llvm::errs();
OS << "<MCSymbolData Symbol:" << getSymbol()
<< " Fragment:" << getFragment() << " Offset:" << getOffset()
<< " Flags:" << getFlags() << " Index:" << getIndex();
if (isCommon())
OS << " (common, size:" << getCommonSize()
<< " align: " << getCommonAlignment() << ")";
if (isExternal())
OS << " (external)";
if (isPrivateExtern())
OS << " (private extern)";
OS << ">";
}
void MCAssembler::dump() {
raw_ostream &OS = llvm::errs();
OS << "<MCAssembler\n";
OS << " Sections:[";
for (iterator it = begin(), ie = end(); it != ie; ++it) {
if (it != begin()) OS << ",\n ";
it->dump();
}
OS << "],\n";
OS << " Symbols:[";
for (symbol_iterator it = symbol_begin(), ie = symbol_end(); it != ie; ++it) {
if (it != symbol_begin()) OS << ",\n ";
it->dump();
}
OS << "]>\n";
}