1 //===- Binary.cpp - A generic binary file -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the Binary class.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Object/Binary.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/Support/MemoryBuffer.h"
17 #include "llvm/Support/Path.h"
20 using namespace object;
26 Binary::Binary(unsigned int Type, MemoryBuffer *Source)
30 StringRef Binary::getData() const {
31 return Data->getBuffer();
34 StringRef Binary::getFileName() const {
35 return Data->getBufferIdentifier();
38 error_code object::createBinary(MemoryBuffer *Source,
39 OwningPtr<Binary> &Result) {
40 // We don't support any at the moment.
42 return object_error::invalid_file_type;
45 error_code object::createBinary(StringRef Path, OwningPtr<Binary> &Result) {
46 OwningPtr<MemoryBuffer> File;
47 if (error_code ec = MemoryBuffer::getFile(Path, File))
49 return createBinary(File.take(), Result);