1/************************************************************************** 2 * 3 * Copyright 2010 VMware, Inc. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28/** 29 * @file 30 * Wrapper for LLVM header file #includes. 31 */ 32 33 34#ifndef LP_BLD_H 35#define LP_BLD_H 36 37 38/** 39 * @file 40 * LLVM IR building helpers interfaces. 41 * 42 * We use LLVM-C bindings for now. They are not documented, but follow the C++ 43 * interfaces very closely, and appear to be complete enough for code 44 * genration. See 45 * http://npcontemplation.blogspot.com/2008/06/secret-of-llvm-c-bindings.html 46 * for a standalone example. 47 */ 48 49#include <llvm-c/Core.h> 50 51 52/** Ensure HAVE_LLVM is set to avoid #ifdef HAVE_LLVM everywhere */ 53#ifndef HAVE_LLVM 54#error "HAVE_LLVM should be set with LLVM's version number, e.g. (0x0207 for 2.7)" 55#endif 56#if HAVE_LLVM < 0x303 57#error "LLVM 3.3 or newer required" 58#endif 59 60 61#if HAVE_LLVM <= 0x0303 62/* We won't actually use LLVMMCJITMemoryManagerRef, just create a dummy 63 * typedef to simplify things elsewhere. 64 */ 65typedef void *LLVMMCJITMemoryManagerRef; 66#endif 67 68 69/** 70 * Redefine these LLVM entrypoints as invalid macros to make sure we 71 * don't accidentally use them. We need to use the functions which 72 * take an explicit LLVMContextRef parameter. 73 */ 74#define LLVMInt1Type ILLEGAL_LLVM_FUNCTION 75#define LLVMInt8Type ILLEGAL_LLVM_FUNCTION 76#define LLVMInt16Type ILLEGAL_LLVM_FUNCTION 77#define LLVMInt32Type ILLEGAL_LLVM_FUNCTION 78#define LLVMInt64Type ILLEGAL_LLVM_FUNCTION 79#define LLVMIntType ILLEGAL_LLVM_FUNCTION 80#define LLVMFloatType ILLEGAL_LLVM_FUNCTION 81#define LLVMDoubleType ILLEGAL_LLVM_FUNCTION 82#define LLVMX86FP80Type ILLEGAL_LLVM_FUNCTION 83#define LLVMFP128Type ILLEGAL_LLVM_FUNCTION 84#define LLVMPPCFP128Type ILLEGAL_LLVM_FUNCTION 85#define LLVMStructType ILLEGAL_LLVM_FUNCTION 86#define LLVMVoidType ILLEGAL_LLVM_FUNCTION 87#define LLVMLabelType ILLEGAL_LLVM_FUNCTION 88#define LLVMOpaqueType ILLEGAL_LLVM_FUNCTION 89#define LLVMUnionType ILLEGAL_LLVM_FUNCTION 90#define LLVMMDString ILLEGAL_LLVM_FUNCTION 91#define LLVMMDNode ILLEGAL_LLVM_FUNCTION 92#define LLVMConstString ILLEGAL_LLVM_FUNCTION 93#define LLVMConstStruct ILLEGAL_LLVM_FUNCTION 94#define LLVMAppendBasicBlock ILLEGAL_LLVM_FUNCTION 95#define LLVMInsertBasicBlock ILLEGAL_LLVM_FUNCTION 96#define LLVMCreateBuilder ILLEGAL_LLVM_FUNCTION 97 98 99/* 100 * Before LLVM 3.4 LLVMSetAlignment only supported GlobalValue, not 101 * LoadInst/StoreInst as we need. 102 */ 103#if HAVE_LLVM < 0x0304 104# ifdef __cplusplus 105 extern "C" 106# endif 107 void LLVMSetAlignmentBackport(LLVMValueRef V, unsigned Bytes); 108# define LLVMSetAlignment LLVMSetAlignmentBackport 109#endif 110 111 112#endif /* LP_BLD_H */ 113