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 "bcc/Config/Config.h"
     25 #include "bcc/Support/Log.h"
     26 
     27 namespace {
     28 
     29 void llvm_error_handler(void *pUserData, const std::string &pMessage,
     30                         bool pGenCrashDiag) {
     31   ALOGE("%s", pMessage.c_str());
     32   ::exit(1);
     33 }
     34 
     35 } // end anonymous namespace
     36 
     37 void bcc::init::Initialize() {
     38   static bool is_initialized = false;
     39 
     40   if (is_initialized) {
     41     return;
     42   }
     43 
     44   // Setup error handler for LLVM.
     45   llvm::remove_fatal_error_handler();
     46   llvm::install_fatal_error_handler(llvm_error_handler, NULL);
     47 
     48 #if defined(PROVIDE_ARM_CODEGEN)
     49   LLVMInitializeARMAsmPrinter();
     50   LLVMInitializeARMAsmParser();
     51 # if USE_DISASSEMBLER
     52   LLVMInitializeARMDisassembler();
     53 # endif
     54   LLVMInitializeARMTargetMC();
     55   LLVMInitializeARMTargetInfo();
     56   LLVMInitializeARMTarget();
     57 #endif
     58 
     59 #if defined(PROVIDE_MIPS_CODEGEN)
     60   LLVMInitializeMipsAsmPrinter();
     61   LLVMInitializeMipsAsmParser();
     62 # if USE_DISASSEMBLER
     63   LLVMInitializeMipsDisassembler();
     64 # endif
     65   LLVMInitializeMipsTargetMC();
     66   LLVMInitializeMipsTargetInfo();
     67   LLVMInitializeMipsTarget();
     68 #endif
     69 
     70 #if defined(PROVIDE_X86_CODEGEN)
     71   LLVMInitializeX86AsmPrinter();
     72   LLVMInitializeX86AsmParser();
     73 # if USE_DISASSEMBLER
     74   LLVMInitializeX86Disassembler();
     75 # endif
     76   LLVMInitializeX86TargetMC();
     77   LLVMInitializeX86TargetInfo();
     78   LLVMInitializeX86Target();
     79 #endif
     80 
     81 #if defined(PROVIDE_ARM64_CODEGEN)
     82   LLVMInitializeAArch64AsmPrinter();
     83   LLVMInitializeAArch64AsmParser();
     84 # if USE_DISASSEMBLER
     85   LLVMInitializeAArch64Disassembler();
     86 # endif
     87   LLVMInitializeAArch64TargetMC();
     88   LLVMInitializeAArch64TargetInfo();
     89   LLVMInitializeAArch64Target();
     90 #endif
     91 
     92   is_initialized = true;
     93 
     94   return;
     95 }
     96