//===- MachOObjectFile.cpp - Mach-O object file binding ---------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file defines the MachOObjectFile class, which binds the MachOObject
// class to the generic ObjectFile wrapper.
//
//===----------------------------------------------------------------------===//
#include "llvm/Object/MachO.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Object/MachOFormat.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/MemoryBuffer.h"
#include <cctype>
#include <cstring>
#include <limits>
using namespace llvm;
using namespace object;
namespace llvm {
namespace object {
MachOObjectFile::MachOObjectFile(MemoryBuffer *Object, MachOObject *MOO,
error_code &ec)
: ObjectFile(Binary::ID_MachO, Object),
MachOObj(MOO) {
DataRefImpl DRI;
moveToNextSection(DRI);
uint32_t LoadCommandCount = MachOObj->getHeader().NumLoadCommands;
while (DRI.d.a < LoadCommandCount) {
Sections.push_back(DRI);
DRI.d.b++;
moveToNextSection(DRI);
}
}
bool MachOObjectFile::is64Bit() const {
return MachOObj->is64Bit();
}
const LoadCommandInfo &
MachOObjectFile::getLoadCommandInfo(unsigned Index) const {
return MachOObj->getLoadCommandInfo(Index);
}
void MachOObjectFile::ReadULEB128s(uint64_t Index,
SmallVectorImpl<uint64_t> &Out) const {
return MachOObj->ReadULEB128s(Index, Out);
}
const macho::Header &MachOObjectFile::getHeader() const {
return MachOObj->getHeader();
}
ObjectFile *ObjectFile::createMachOObjectFile(MemoryBuffer *Buffer) {
error_code ec;
std::string Err;
MachOObject *MachOObj = MachOObject::LoadFromBuffer(Buffer, &Err);
if (!MachOObj)
return NULL;
// MachOObject takes ownership of the Buffer we passed to it, and
// MachOObjectFile does, too, so we need to make sure they don't get the
<