Revert the last two commits in the series. r132911, r132912.
[oota-llvm.git] / lib / Object / Binary.cpp
1 //===- 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
19 using namespace llvm;
20 using namespace object;
21
22 Binary::~Binary() {
23   delete Data;
24 }
25
26 Binary::Binary(unsigned int Type, MemoryBuffer *Source)
27   : TypeID(Type)
28   , Data(Source) {}
29
30 StringRef Binary::getData() const {
31   return Data->getBuffer();
32 }
33
34 StringRef Binary::getFileName() const {
35   return Data->getBufferIdentifier();
36 }
37
38 error_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
45 error_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 }