blob: 75f5a58ac08328d35c5a0bf8331329c2d60bca23 [file] [log] [blame]
Michael J. Spencerc44c9152011-06-25 17:54:29 +00001//===- Binary.cpp - A generic binary file -----------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the Binary class.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/Object/Binary.h"
15#include "llvm/ADT/StringRef.h"
16#include "llvm/Support/MemoryBuffer.h"
17#include "llvm/Support/Path.h"
18
19using namespace llvm;
20using namespace object;
21
22Binary::~Binary() {
23 delete Data;
24}
25
26Binary::Binary(unsigned int Type, MemoryBuffer *Source)
27 : TypeID(Type)
28 , Data(Source) {}
29
30StringRef Binary::getData() const {
31 return Data->getBuffer();
32}
33
34StringRef Binary::getFileName() const {
35 return Data->getBufferIdentifier();
36}
37
38error_code object::createBinary(MemoryBuffer *Source,
39 OwningPtr<Binary> &Result) {
40 // We don't support any at the moment.
41 delete Source;
42 return object_error::invalid_file_type;
43}
44
45error_code object::createBinary(StringRef Path, OwningPtr<Binary> &Result) {
46 OwningPtr<MemoryBuffer> File;
47 if (error_code ec = MemoryBuffer::getFile(Path, File))
48 return ec;
49 return createBinary(File.take(), Result);
50}