Add support for archives and object file caching under MCJIT.
[oota-llvm.git] / lib / ExecutionEngine / RuntimeDyld / ObjectImageCommon.h
1 //===-- ObjectImageCommon.h - Format independent executuable object image -===//
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 a file format independent ObjectImage class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_RUNTIMEDYLD_OBJECTIMAGECOMMON_H
15 #define LLVM_RUNTIMEDYLD_OBJECTIMAGECOMMON_H
16
17 #include "llvm/ExecutionEngine/ObjectBuffer.h"
18 #include "llvm/ExecutionEngine/ObjectImage.h"
19 #include "llvm/Object/ObjectFile.h"
20
21 namespace llvm {
22
23 namespace object {
24   class ObjectFile;
25 }
26
27 class ObjectImageCommon : public ObjectImage {
28   ObjectImageCommon(); // = delete
29   ObjectImageCommon(const ObjectImageCommon &other); // = delete
30   virtual void anchor();
31
32 protected:
33   object::ObjectFile *ObjFile;
34
35   // This form of the constructor allows subclasses to use
36   // format-specific subclasses of ObjectFile directly
37   ObjectImageCommon(ObjectBuffer *Input, object::ObjectFile *Obj)
38   : ObjectImage(Input), // saves Input as Buffer and takes ownership
39     ObjFile(Obj)
40   {
41   }
42
43 public:
44   ObjectImageCommon(ObjectBuffer* Input)
45   : ObjectImage(Input) // saves Input as Buffer and takes ownership
46   {
47     ObjFile = object::ObjectFile::createObjectFile(Buffer->getMemBuffer());
48   }
49   ObjectImageCommon(object::ObjectFile* Input)
50   : ObjectImage(NULL), ObjFile(Input)  {}
51   virtual ~ObjectImageCommon() { delete ObjFile; }
52
53   virtual object::symbol_iterator begin_symbols() const
54               { return ObjFile->begin_symbols(); }
55   virtual object::symbol_iterator end_symbols() const
56               { return ObjFile->end_symbols(); }
57
58   virtual object::section_iterator begin_sections() const
59               { return ObjFile->begin_sections(); }
60   virtual object::section_iterator end_sections() const
61               { return ObjFile->end_sections(); }
62
63   virtual /* Triple::ArchType */ unsigned getArch() const
64               { return ObjFile->getArch(); }
65
66   virtual StringRef getData() const { return ObjFile->getData(); }
67
68   virtual object::ObjectFile* getObjectFile() const { return ObjFile; }
69
70   // Subclasses can override these methods to update the image with loaded
71   // addresses for sections and common symbols
72   virtual void updateSectionAddress(const object::SectionRef &Sec,
73                                     uint64_t Addr) {}
74   virtual void updateSymbolAddress(const object::SymbolRef &Sym, uint64_t Addr)
75               {}
76
77   // Subclasses can override these methods to provide JIT debugging support
78   virtual void registerWithDebugger() {}
79   virtual void deregisterWithDebugger() {}
80 };
81
82 } // end namespace llvm
83
84 #endif // LLVM_RUNTIMEDYLD_OBJECT_IMAGE_H
85