diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-09-19 17:56:04 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-09-19 17:56:04 +0000 |
commit | 0b8b771e9f2f251460a6f200c45efe9d55640d60 (patch) | |
tree | 1dd175cf9df13a7ecc88fc7d4a1aa6294b97e17e /tools/llvm-objdump/MCFunction.h | |
parent | a182be9b6cab86b3d52371efea1681161820cf1c (diff) |
Add a MachO-specific "mode" to llvm-objdump, that, if enabled, gathers additional information that are only available on MachO.
- It can take FunctionStarts from a binary to find entry points more accurately.
- Symbol offsets in executables are correct now.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@140028 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-objdump/MCFunction.h')
-rw-r--r-- | tools/llvm-objdump/MCFunction.h | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/tools/llvm-objdump/MCFunction.h b/tools/llvm-objdump/MCFunction.h index 023ca39183..4677d91bb7 100644 --- a/tools/llvm-objdump/MCFunction.h +++ b/tools/llvm-objdump/MCFunction.h @@ -12,8 +12,11 @@ // //===----------------------------------------------------------------------===// +#ifndef LLVM_OBJECTDUMP_MCFUNCTION_H +#define LLVM_OBJECTDUMP_MCFUNCTION_H + #include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/SmallPtrSet.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/MC/MCInst.h" #include <map> @@ -31,15 +34,20 @@ struct MCDecodedInst { uint64_t Size; MCInst Inst; + MCDecodedInst() {} MCDecodedInst(uint64_t Address, uint64_t Size, MCInst Inst) : Address(Address), Size(Size), Inst(Inst) {} + + bool operator<(const MCDecodedInst &RHS) const { + return Address < RHS.Address; + } }; /// MCBasicBlock - Consists of multiple MCDecodedInsts and a list of successing /// MCBasicBlocks. class MCBasicBlock { - SmallVector<MCDecodedInst, 8> Insts; - typedef SmallPtrSet<MCBasicBlock*, 8> SetTy; + std::vector<MCDecodedInst> Insts; + typedef DenseSet<uint64_t> SetTy; SetTy Succs; public: ArrayRef<MCDecodedInst> getInsts() const { return Insts; } @@ -48,10 +56,14 @@ public: succ_iterator succ_begin() const { return Succs.begin(); } succ_iterator succ_end() const { return Succs.end(); } - bool contains(MCBasicBlock *BB) const { return Succs.count(BB); } + bool contains(uint64_t Addr) const { return Succs.count(Addr); } void addInst(const MCDecodedInst &Inst) { Insts.push_back(Inst); } - void addSucc(MCBasicBlock *BB) { Succs.insert(BB); } + void addSucc(uint64_t Addr) { Succs.insert(Addr); } + + bool operator<(const MCBasicBlock &RHS) const { + return Insts.size() < RHS.Insts.size(); + } }; /// MCFunction - Represents a named function in machine code, containing @@ -59,7 +71,7 @@ public: class MCFunction { const StringRef Name; // Keep BBs sorted by address. - typedef std::map<uint64_t, MCBasicBlock> MapTy; + typedef std::vector<std::pair<uint64_t, MCBasicBlock> > MapTy; MapTy Blocks; public: MCFunction(StringRef Name) : Name(Name) {} @@ -68,7 +80,8 @@ public: static MCFunction createFunctionFromMC(StringRef Name, const MCDisassembler *DisAsm, const MemoryObject &Region, uint64_t Start, uint64_t End, - const MCInstrAnalysis *Ana, raw_ostream &DebugOut); + const MCInstrAnalysis *Ana, raw_ostream &DebugOut, + SmallVectorImpl<uint64_t> &Calls); typedef MapTy::iterator iterator; iterator begin() { return Blocks.begin(); } @@ -77,14 +90,11 @@ public: StringRef getName() const { return Name; } MCBasicBlock &addBlock(uint64_t Address, const MCBasicBlock &BB) { - assert(!Blocks.count(Address) && "Already a BB at address."); - return Blocks[Address] = BB; - } - - MCBasicBlock &getBlockAtAddress(uint64_t Address) { - assert(Blocks.count(Address) && "No BB at address."); - return Blocks[Address]; + Blocks.push_back(std::make_pair(Address, BB)); + return Blocks.back().second; } }; } + +#endif |