Home | History | Annotate | Download | only in mcld
      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 #ifndef MCLD_LINKER_H
     10 #define MCLD_LINKER_H
     11 
     12 #include <string>
     13 
     14 namespace mcld {
     15 
     16 class Module;
     17 class LinkerConfig;
     18 class LinkerScript;
     19 
     20 class Target;
     21 class TargetLDBackend;
     22 
     23 class IRBuilder;
     24 class ObjectLinker;
     25 
     26 class FileHandle;
     27 class FileOutputBuffer;
     28 
     29 /** \class Linker
     30 *  \brief Linker is a modular linker.
     31 */
     32 class Linker
     33 {
     34 public:
     35   Linker();
     36 
     37   ~Linker();
     38 
     39   /// emulate - To set up target-dependent options and default linker script.
     40   bool emulate(LinkerScript& pScript, LinkerConfig& pConfig);
     41 
     42   /// normalize - To normalize the command line language into mcld::Module.
     43   bool normalize(Module& pModule, IRBuilder& pBuilder);
     44 
     45   /// resolve - To build up the topology of mcld::Module.
     46   bool resolve(Module& pModule);
     47 
     48   /// layout - To serialize the final result of the output mcld::Module.
     49   bool layout();
     50 
     51   /// link - A convenient way to resolve and to layout the output mcld::Module.
     52   bool link(Module& pModule, IRBuilder& pBuilder);
     53 
     54   /// emit - To emit output mcld::Module to a FileOutputBuffer.
     55   bool emit(FileOutputBuffer& pOutput);
     56 
     57   /// emit - To open a file for output in pPath and to emit output mcld::Module
     58   /// to the file.
     59   bool emit(const Module& pModule, const std::string& pPath);
     60 
     61   /// emit - To emit output mcld::Module in the pFileDescriptor.
     62   bool emit(const Module& pModule, int pFileDescriptor);
     63 
     64   bool reset();
     65 
     66 private:
     67   bool initTarget();
     68 
     69   bool initBackend();
     70 
     71   bool initOStream();
     72 
     73   bool initEmulator(LinkerScript& pScript);
     74 
     75 private:
     76   LinkerConfig* m_pConfig;
     77   IRBuilder* m_pIRBuilder;
     78 
     79   const Target* m_pTarget;
     80   TargetLDBackend* m_pBackend;
     81   ObjectLinker* m_pObjLinker;
     82 };
     83 
     84 } // namespace of MC Linker
     85 
     86 #endif
     87 
     88