89cd24bfb97d9d29ded4ab7ba282b61fdbfb45e4
[oota-llvm.git] / include / llvm / Object / Binary.h
1 //===- Binary.h - 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 declares the Binary class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_OBJECT_BINARY_H
15 #define LLVM_OBJECT_BINARY_H
16
17 #include "llvm/ADT/OwningPtr.h"
18 #include "llvm/Object/Error.h"
19
20 namespace llvm {
21
22 class MemoryBuffer;
23 class StringRef;
24
25 namespace object {
26
27 class Binary {
28 private:
29   Binary(); // = delete
30   Binary(const Binary &other); // = delete
31
32   unsigned int TypeID;
33
34 protected:
35   MemoryBuffer *Data;
36
37   Binary(unsigned int Type, MemoryBuffer *Source);
38
39   enum {
40     isArchive,
41     isCOFF,
42     isELF,
43     isMachO,
44     isObject
45   };
46
47 public:
48   virtual ~Binary();
49
50   StringRef getData() const;
51   StringRef getFileName() const;
52
53   // Cast methods.
54   unsigned int getType() const { return TypeID; }
55   static inline bool classof(Binary const *v) { return true; }
56 };
57
58 error_code createBinary(MemoryBuffer *Source, OwningPtr<Binary> &Result);
59 error_code createBinary(StringRef Path, OwningPtr<Binary> &Result);
60
61 }
62 }
63
64 #endif