Home | History | Annotate | Download | only in CodeGen
      1 //===- MCLinker.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 // MCLinker is a base class inherited by target specific linker.
     11 // This class primarily handles common functionality used by all linkers.
     12 //
     13 //===----------------------------------------------------------------------===//
     14 #ifndef MCLD_CODEGEN_MCLINKER_H
     15 #define MCLD_CODEGEN_MCLINKER_H
     16 #ifdef ENABLE_UNITTEST
     17 #include <gtest.h>
     18 #endif
     19 #include <llvm/CodeGen/MachineFunctionPass.h>
     20 
     21 namespace llvm {
     22 
     23 class Module;
     24 class MachineFunction;
     25 
     26 } // namespace of llvm
     27 
     28 namespace mcld {
     29 
     30 class Module;
     31 class MemoryArea;
     32 class IRBuilder;
     33 class LinkerConfig;
     34 class Linker;
     35 
     36 /** \class MCLinker
     37 *  \brief MCLinker provides a linking pass for standard compilation flow
     38 *
     39 *  MCLinker is responded for
     40 *  - provide an interface for target-specific linker
     41 *  - set up environment for ObjectLinker
     42 *  - perform linking
     43 *
     44 *  @see MachineFunctionPass ObjectLinker
     45 */
     46 class MCLinker : public llvm::MachineFunctionPass
     47 {
     48 protected:
     49   // Constructor. Although MCLinker has only two arguments,
     50   // TargetMCLinker should handle
     51   // - enabled attributes
     52   // - the default attribute
     53   // - the default link script
     54   // - the standard symbols
     55   MCLinker(LinkerConfig& pConfig,
     56            mcld::Module& pModule,
     57            MemoryArea& pOutput);
     58 
     59 public:
     60   virtual ~MCLinker();
     61 
     62   virtual bool doInitialization(llvm::Module &pM);
     63 
     64   virtual bool doFinalization(llvm::Module &pM);
     65 
     66   virtual bool runOnMachineFunction(llvm::MachineFunction& pMFn);
     67 
     68 protected:
     69   void initializeInputTree(IRBuilder& pBuilder);
     70 
     71 protected:
     72   LinkerConfig& m_Config;
     73   mcld::Module& m_Module;
     74   MemoryArea& m_Output;
     75   IRBuilder* m_pBuilder;
     76   Linker* m_pLinker;
     77 
     78 private:
     79   static char m_ID;
     80 };
     81 
     82 } // namespace of MC Linker
     83 
     84 #endif
     85 
     86