LLVM API Documentation

ObjectImage.h
Go to the documentation of this file.
00001 //===---- ObjectImage.h - Format independent executuable object image -----===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file declares a file format independent ObjectImage class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_EXECUTIONENGINE_OBJECTIMAGE_H
00015 #define LLVM_EXECUTIONENGINE_OBJECTIMAGE_H
00016 
00017 #include "llvm/ExecutionEngine/ObjectBuffer.h"
00018 #include "llvm/Object/ObjectFile.h"
00019 
00020 namespace llvm {
00021 
00022 
00023 /// ObjectImage - A container class that represents an ObjectFile that has been
00024 /// or is in the process of being loaded into memory for execution.
00025 class ObjectImage {
00026   ObjectImage() LLVM_DELETED_FUNCTION;
00027   ObjectImage(const ObjectImage &other) LLVM_DELETED_FUNCTION;
00028   virtual void anchor();
00029 
00030 protected:
00031   std::unique_ptr<ObjectBuffer> Buffer;
00032 
00033 public:
00034   ObjectImage(std::unique_ptr<ObjectBuffer> Input) : Buffer(std::move(Input)) {}
00035   virtual ~ObjectImage() {}
00036 
00037   virtual object::symbol_iterator begin_symbols() const = 0;
00038   virtual object::symbol_iterator end_symbols() const = 0;
00039   iterator_range<object::symbol_iterator> symbols() const {
00040     return iterator_range<object::symbol_iterator>(begin_symbols(),
00041                                                    end_symbols());
00042   }
00043 
00044   virtual object::section_iterator begin_sections() const = 0;
00045   virtual object::section_iterator end_sections() const  = 0;
00046   iterator_range<object::section_iterator> sections() const {
00047     return iterator_range<object::section_iterator>(begin_sections(),
00048                                                     end_sections());
00049   }
00050 
00051   virtual /* Triple::ArchType */ unsigned getArch() const = 0;
00052 
00053   // Return the name associated with this ObjectImage.
00054   // This is usually the name of the file or MemoryBuffer that the the
00055   // ObjectBuffer was constructed from.
00056   StringRef getImageName() const { return Buffer->getBufferIdentifier(); }
00057 
00058   // Subclasses can override these methods to update the image with loaded
00059   // addresses for sections and common symbols
00060   virtual void updateSectionAddress(const object::SectionRef &Sec,
00061                                     uint64_t Addr) = 0;
00062   virtual void updateSymbolAddress(const object::SymbolRef &Sym,
00063                                    uint64_t Addr) = 0;
00064 
00065   virtual StringRef getData() const = 0;
00066 
00067   virtual object::ObjectFile* getObjectFile() const = 0;
00068 
00069   // Subclasses can override these methods to provide JIT debugging support
00070   virtual void registerWithDebugger() = 0;
00071   virtual void deregisterWithDebugger() = 0;
00072 };
00073 
00074 } // end namespace llvm
00075 
00076 #endif // LLVM_EXECUTIONENGINE_OBJECTIMAGE_H