Initialization.cpp revision 93c8832a6916a54d984764bf83a8a77cbae4143b
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 LLVMInitializeARMTargetMC(); 53 LLVMInitializeARMTargetInfo(); 54 LLVMInitializeARMTarget(); 55 LLVMInitializeARMLDTargetInfo(); 56 LLVMInitializeARMLDTarget(); 57 LLVMInitializeARMLDBackend(); 58 LLVMInitializeARMDiagnosticLineInfo(); 59#endif 60 61#if defined(PROVIDE_MIPS_CODEGEN) 62 LLVMInitializeMipsAsmPrinter(); 63 LLVMInitializeMipsTargetMC(); 64 LLVMInitializeMipsTargetInfo(); 65 LLVMInitializeMipsTarget(); 66 LLVMInitializeMipsLDTargetInfo(); 67 LLVMInitializeMipsLDTarget(); 68 LLVMInitializeMipsLDBackend(); 69 LLVMInitializeMipsDiagnosticLineInfo(); 70#endif 71 72#if defined(PROVIDE_X86_CODEGEN) 73 LLVMInitializeX86AsmPrinter(); 74 LLVMInitializeX86TargetMC(); 75 LLVMInitializeX86TargetInfo(); 76 LLVMInitializeX86Target(); 77 LLVMInitializeX86LDTargetInfo(); 78 LLVMInitializeX86LDTarget(); 79 LLVMInitializeX86LDBackend(); 80 LLVMInitializeX86DiagnosticLineInfo(); 81#endif 82 83#if USE_DISASSEMBLER 84 InitializeDisassembler(); 85#endif 86 87 is_initialized = true; 88 89 return; 90} 91