Home | History | Annotate | Download | only in Support
      1 //===- Initialization.cpp -------------------------------------------------===//
      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 #include "alone/Support/Initialization.h"
     11 
     12 #include <cstdlib>
     13 
     14 #include <llvm/Support/ErrorHandling.h>
     15 #include <llvm/Support/TargetSelect.h>
     16 
     17 #include <mcld/Support/TargetSelect.h>
     18 #include <mcld/Support/TargetRegistry.h>
     19 
     20 #include "alone/Config/Config.h"
     21 #include "alone/Support/Log.h"
     22 
     23 namespace {
     24 
     25 void llvm_error_handler(void *pUserData, const std::string &pMessage) {
     26   ALOGE("%s", pMessage.c_str());
     27   ::exit(1);
     28 }
     29 
     30 } // end anonymous namespace
     31 
     32 void alone::init::Initialize() {
     33   static bool is_initialized = false;
     34 
     35   if (is_initialized) {
     36     return;
     37   }
     38 
     39   // Setup error handler for LLVM.
     40   llvm::remove_fatal_error_handler();
     41   llvm::install_fatal_error_handler(llvm_error_handler, NULL);
     42 
     43 #if defined(PROVIDE_ARM_CODEGEN)
     44   LLVMInitializeARMAsmPrinter();
     45 # if USE_DISASSEMBLER
     46   LLVMInitializeARMDisassembler();
     47 # endif
     48   LLVMInitializeARMTargetMC();
     49   LLVMInitializeARMTargetInfo();
     50   LLVMInitializeARMTarget();
     51   MCLDInitializeARMLDTargetInfo();
     52   MCLDInitializeARMLDTarget();
     53   MCLDInitializeARMLDBackend();
     54   MCLDInitializeARMDiagnosticLineInfo();
     55 #endif
     56 
     57 #if defined(PROVIDE_MIPS_CODEGEN)
     58   LLVMInitializeMipsAsmPrinter();
     59 # if USE_DISASSEMBLER
     60   LLVMInitializeMipsDisassembler();
     61 # endif
     62   LLVMInitializeMipsTargetMC();
     63   LLVMInitializeMipsTargetInfo();
     64   LLVMInitializeMipsTarget();
     65   MCLDInitializeMipsLDTargetInfo();
     66   MCLDInitializeMipsLDTarget();
     67   MCLDInitializeMipsLDBackend();
     68   MCLDInitializeMipsDiagnosticLineInfo();
     69 #endif
     70 
     71 #if defined(PROVIDE_X86_CODEGEN)
     72   LLVMInitializeX86AsmPrinter();
     73 # if USE_DISASSEMBLER
     74   LLVMInitializeX86Disassembler();
     75 # endif
     76   LLVMInitializeX86TargetMC();
     77   LLVMInitializeX86TargetInfo();
     78   LLVMInitializeX86Target();
     79   MCLDInitializeX86LDTargetInfo();
     80   MCLDInitializeX86LDTarget();
     81   MCLDInitializeX86LDBackend();
     82   MCLDInitializeX86DiagnosticLineInfo();
     83 #endif
     84 
     85   is_initialized = true;
     86 
     87   return;
     88 }
     89