Initialization.cpp revision c72c4ddfcd79c74f70713da91a69569451b5c19e
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/DebugHelper.h" 26 27namespace { 28 29void llvm_error_handler(void *pUserData, const std::string &pMessage) { 30 ALOGE("%s", pMessage.c_str()); 31 ::exit(1); 32} 33 34} // end anonymous namespace 35 36void bcc::init::Initialize() { 37 static bool is_initialized = false; 38 39 if (is_initialized) { 40 return; 41 } 42 43 // Setup error handler for LLVM. 44 llvm::remove_fatal_error_handler(); 45 llvm::install_fatal_error_handler(llvm_error_handler, NULL); 46 47#if defined(PROVIDE_ARM_CODEGEN) 48 LLVMInitializeARMAsmPrinter(); 49 LLVMInitializeARMTargetMC(); 50 LLVMInitializeARMTargetInfo(); 51 LLVMInitializeARMTarget(); 52#endif 53 54#if defined(PROVIDE_MIPS_CODEGEN) 55 LLVMInitializeMipsAsmPrinter(); 56 LLVMInitializeMipsTargetMC(); 57 LLVMInitializeMipsTargetInfo(); 58 LLVMInitializeMipsTarget(); 59#endif 60 61#if defined(PROVIDE_X86_CODEGEN) 62 LLVMInitializeX86AsmPrinter(); 63 LLVMInitializeX86TargetMC(); 64 LLVMInitializeX86TargetInfo(); 65 LLVMInitializeX86Target(); 66#endif 67 68#if USE_DISASSEMBLER 69 InitializeDisassembler(); 70#endif 71 72 is_initialized = true; 73 74 return; 75} 76