Home | History | Annotate | Download | only in Support
      1 /*
      2  * Copyright 2012, The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include "bcc/Support/Initialization.h"
     18 
     19 #include <cstdlib>
     20 
     21 #include <llvm/Support/ErrorHandling.h>
     22 #include <llvm/Support/TargetSelect.h>
     23 
     24 #include <mcld/Support/TargetSelect.h>
     25 #include <mcld/Support/TargetRegistry.h>
     26 
     27 #include "bcc/Config/Config.h"
     28 #include "bcc/Support/Log.h"
     29 
     30 namespace {
     31 
     32 void llvm_error_handler(void *pUserData, const std::string &pMessage) {
     33   ALOGE("%s", pMessage.c_str());
     34   ::exit(1);
     35 }
     36 
     37 } // end anonymous namespace
     38 
     39 void bcc::init::Initialize() {
     40   static bool is_initialized = false;
     41 
     42   if (is_initialized) {
     43     return;
     44   }
     45 
     46   // Setup error handler for LLVM.
     47   llvm::remove_fatal_error_handler();
     48   llvm::install_fatal_error_handler(llvm_error_handler, NULL);
     49 
     50 #if defined(PROVIDE_ARM_CODEGEN)
     51   LLVMInitializeARMAsmPrinter();
     52 # if USE_DISASSEMBLER
     53   LLVMInitializeARMDisassembler();
     54 # endif
     55   LLVMInitializeARMTargetMC();
     56   LLVMInitializeARMTargetInfo();
     57   LLVMInitializeARMTarget();
     58   LLVMInitializeARMLDTargetInfo();
     59   LLVMInitializeARMLDTarget();
     60   LLVMInitializeARMLDBackend();
     61   LLVMInitializeARMDiagnosticLineInfo();
     62 #endif
     63 
     64 #if defined(PROVIDE_MIPS_CODEGEN)
     65   LLVMInitializeMipsAsmPrinter();
     66 # if USE_DISASSEMBLER
     67   LLVMInitializeMipsDisassembler();
     68 # endif
     69   LLVMInitializeMipsTargetMC();
     70   LLVMInitializeMipsTargetInfo();
     71   LLVMInitializeMipsTarget();
     72   LLVMInitializeMipsLDTargetInfo();
     73   LLVMInitializeMipsLDTarget();
     74   LLVMInitializeMipsLDBackend();
     75   LLVMInitializeMipsDiagnosticLineInfo();
     76 #endif
     77 
     78 #if defined(PROVIDE_X86_CODEGEN)
     79   LLVMInitializeX86AsmPrinter();
     80 # if USE_DISASSEMBLER
     81   LLVMInitializeX86Disassembler();
     82 # endif
     83   LLVMInitializeX86TargetMC();
     84   LLVMInitializeX86TargetInfo();
     85   LLVMInitializeX86Target();
     86   LLVMInitializeX86LDTargetInfo();
     87   LLVMInitializeX86LDTarget();
     88   LLVMInitializeX86LDBackend();
     89   LLVMInitializeX86DiagnosticLineInfo();
     90 #endif
     91 
     92   is_initialized = true;
     93 
     94   return;
     95 }
     96