Initialization.cpp revision d793ca93d75fe8f1d29ceab8f9bf0432f0f63565
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 30namespace { 31 32void 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 39void 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 LLVMInitializeARMAsmParser(); 53# if USE_DISASSEMBLER 54 LLVMInitializeARMDisassembler(); 55# endif 56 LLVMInitializeARMTargetMC(); 57 LLVMInitializeARMTargetInfo(); 58 LLVMInitializeARMTarget(); 59 MCLDInitializeARMLDTargetInfo(); 60 MCLDInitializeARMLDTarget(); 61 MCLDInitializeARMLDBackend(); 62 MCLDInitializeARMDiagnosticLineInfo(); 63#endif 64 65#if defined(PROVIDE_MIPS_CODEGEN) 66 LLVMInitializeMipsAsmPrinter(); 67 LLVMInitializeMipsAsmParser(); 68# if USE_DISASSEMBLER 69 LLVMInitializeMipsDisassembler(); 70# endif 71 LLVMInitializeMipsTargetMC(); 72 LLVMInitializeMipsTargetInfo(); 73 LLVMInitializeMipsTarget(); 74 MCLDInitializeMipsLDTargetInfo(); 75 MCLDInitializeMipsLDTarget(); 76 MCLDInitializeMipsLDBackend(); 77 MCLDInitializeMipsDiagnosticLineInfo(); 78#endif 79 80#if defined(PROVIDE_X86_CODEGEN) 81 LLVMInitializeX86AsmPrinter(); 82 LLVMInitializeX86AsmParser(); 83# if USE_DISASSEMBLER 84 LLVMInitializeX86Disassembler(); 85# endif 86 LLVMInitializeX86TargetMC(); 87 LLVMInitializeX86TargetInfo(); 88 LLVMInitializeX86Target(); 89 MCLDInitializeX86LDTargetInfo(); 90 MCLDInitializeX86LDTarget(); 91 MCLDInitializeX86LDBackend(); 92 MCLDInitializeX86DiagnosticLineInfo(); 93#endif 94 95 is_initialized = true; 96 97 return; 98} 99