Home | History | Annotate | Download | only in alone
      1 //===- Linker.h -----------------------------------------------------------===//
      2 //
      3 //                     The MCLinker Project
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #ifndef ALONE_LINKER_H
     11 #define ALONE_LINKER_H
     12 
     13 #include <string>
     14 
     15 namespace mcld {
     16 
     17 class Module;
     18 class IRBuilder;
     19 class LinkerConfig;
     20 class Linker;
     21 class Input;
     22 class MemoryArea;
     23 
     24 namespace sys { namespace fs {
     25 
     26 class Path;
     27 
     28 } } // end namespace sys::fs
     29 
     30 } // end namespace mcld
     31 
     32 namespace alone {
     33 
     34 class LinkerConfig;
     35 
     36 class Linker {
     37 public:
     38   enum ErrorCode {
     39     kSuccess,
     40     kDoubleConfig,
     41     kDelegateLDInfo,
     42     kFindNameSpec,
     43     kOpenObjectFile,
     44     kOpenMemory,
     45     kNotConfig,
     46     kNotSetUpOutput,
     47     kOpenOutput,
     48     kReadSections,
     49     kReadSymbols,
     50     kAddAdditionalSymbols,
     51     kMaxErrorCode
     52   };
     53 
     54   static const char *GetErrorString(enum ErrorCode pErrCode);
     55 
     56 private:
     57   const mcld::LinkerConfig *mLDConfig;
     58   mcld::Module *mModule;
     59   mcld::Linker *mLinker;
     60   mcld::IRBuilder *mBuilder;
     61   std::string mSOName;
     62   std::string mOutputPath;
     63   int mOutputHandler;
     64 
     65 public:
     66   Linker();
     67 
     68   Linker(const LinkerConfig& pConfig);
     69 
     70   ~Linker();
     71 
     72   enum ErrorCode config(const LinkerConfig& pConfig);
     73 
     74   enum ErrorCode addNameSpec(const std::string &pNameSpec);
     75 
     76   enum ErrorCode addObject(const std::string &pObjectPath);
     77 
     78   enum ErrorCode addObject(void* pMemory, size_t pSize);
     79 
     80   enum ErrorCode addCode(void* pMemory, size_t pSize);
     81 
     82   enum ErrorCode setOutput(const std::string &pPath);
     83 
     84   enum ErrorCode setOutput(int pFileHandler);
     85 
     86   enum ErrorCode link();
     87 
     88 private:
     89   enum ErrorCode extractFiles(const LinkerConfig& pConfig);
     90 };
     91 
     92 } // end namespace alone
     93 
     94 #endif // ALONE_LINKER_H
     95