1848b8605Smrg/************************************************************************** 2848b8605Smrg * 3848b8605Smrg * Copyright 2010 VMware, Inc. 4848b8605Smrg * All Rights Reserved. 5848b8605Smrg * 6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a 7848b8605Smrg * copy of this software and associated documentation files (the 8848b8605Smrg * "Software"), to deal in the Software without restriction, including 9848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish, 10848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to 11848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to 12848b8605Smrg * the following conditions: 13848b8605Smrg * 14848b8605Smrg * The above copyright notice and this permission notice (including the 15848b8605Smrg * next paragraph) shall be included in all copies or substantial portions 16848b8605Smrg * of the Software. 17848b8605Smrg * 18848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20848b8605Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21848b8605Smrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22848b8605Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23848b8605Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24848b8605Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25848b8605Smrg * 26848b8605Smrg **************************************************************************/ 27848b8605Smrg 28848b8605Smrg/** 29848b8605Smrg * @file 30848b8605Smrg * Wrapper for LLVM header file #includes. 31848b8605Smrg */ 32848b8605Smrg 33848b8605Smrg 34848b8605Smrg#ifndef LP_BLD_H 35848b8605Smrg#define LP_BLD_H 36848b8605Smrg 37848b8605Smrg 38848b8605Smrg/** 39848b8605Smrg * @file 40848b8605Smrg * LLVM IR building helpers interfaces. 41848b8605Smrg * 42848b8605Smrg * We use LLVM-C bindings for now. They are not documented, but follow the C++ 43848b8605Smrg * interfaces very closely, and appear to be complete enough for code 44848b8605Smrg * genration. See 45848b8605Smrg * http://npcontemplation.blogspot.com/2008/06/secret-of-llvm-c-bindings.html 46848b8605Smrg * for a standalone example. 47848b8605Smrg */ 48848b8605Smrg 49848b8605Smrg#include <llvm-c/Core.h> 50848b8605Smrg 51848b8605Smrg 52848b8605Smrg/** Ensure HAVE_LLVM is set to avoid #ifdef HAVE_LLVM everywhere */ 53848b8605Smrg#ifndef HAVE_LLVM 54848b8605Smrg#error "HAVE_LLVM should be set with LLVM's version number, e.g. (0x0207 for 2.7)" 55848b8605Smrg#endif 56b8e80941Smrg#if HAVE_LLVM < 0x303 57b8e80941Smrg#error "LLVM 3.3 or newer required" 58b8e80941Smrg#endif 59b8e80941Smrg 60b8e80941Smrg 61b8e80941Smrg#if HAVE_LLVM <= 0x0303 62b8e80941Smrg/* We won't actually use LLVMMCJITMemoryManagerRef, just create a dummy 63b8e80941Smrg * typedef to simplify things elsewhere. 64b8e80941Smrg */ 65b8e80941Smrgtypedef void *LLVMMCJITMemoryManagerRef; 66848b8605Smrg#endif 67848b8605Smrg 68848b8605Smrg 69848b8605Smrg/** 70848b8605Smrg * Redefine these LLVM entrypoints as invalid macros to make sure we 71848b8605Smrg * don't accidentally use them. We need to use the functions which 72848b8605Smrg * take an explicit LLVMContextRef parameter. 73848b8605Smrg */ 74848b8605Smrg#define LLVMInt1Type ILLEGAL_LLVM_FUNCTION 75848b8605Smrg#define LLVMInt8Type ILLEGAL_LLVM_FUNCTION 76848b8605Smrg#define LLVMInt16Type ILLEGAL_LLVM_FUNCTION 77848b8605Smrg#define LLVMInt32Type ILLEGAL_LLVM_FUNCTION 78848b8605Smrg#define LLVMInt64Type ILLEGAL_LLVM_FUNCTION 79848b8605Smrg#define LLVMIntType ILLEGAL_LLVM_FUNCTION 80848b8605Smrg#define LLVMFloatType ILLEGAL_LLVM_FUNCTION 81848b8605Smrg#define LLVMDoubleType ILLEGAL_LLVM_FUNCTION 82848b8605Smrg#define LLVMX86FP80Type ILLEGAL_LLVM_FUNCTION 83848b8605Smrg#define LLVMFP128Type ILLEGAL_LLVM_FUNCTION 84848b8605Smrg#define LLVMPPCFP128Type ILLEGAL_LLVM_FUNCTION 85848b8605Smrg#define LLVMStructType ILLEGAL_LLVM_FUNCTION 86848b8605Smrg#define LLVMVoidType ILLEGAL_LLVM_FUNCTION 87848b8605Smrg#define LLVMLabelType ILLEGAL_LLVM_FUNCTION 88848b8605Smrg#define LLVMOpaqueType ILLEGAL_LLVM_FUNCTION 89848b8605Smrg#define LLVMUnionType ILLEGAL_LLVM_FUNCTION 90848b8605Smrg#define LLVMMDString ILLEGAL_LLVM_FUNCTION 91848b8605Smrg#define LLVMMDNode ILLEGAL_LLVM_FUNCTION 92848b8605Smrg#define LLVMConstString ILLEGAL_LLVM_FUNCTION 93848b8605Smrg#define LLVMConstStruct ILLEGAL_LLVM_FUNCTION 94848b8605Smrg#define LLVMAppendBasicBlock ILLEGAL_LLVM_FUNCTION 95848b8605Smrg#define LLVMInsertBasicBlock ILLEGAL_LLVM_FUNCTION 96848b8605Smrg#define LLVMCreateBuilder ILLEGAL_LLVM_FUNCTION 97848b8605Smrg 98b8e80941Smrg 99b8e80941Smrg/* 100b8e80941Smrg * Before LLVM 3.4 LLVMSetAlignment only supported GlobalValue, not 101b8e80941Smrg * LoadInst/StoreInst as we need. 102b8e80941Smrg */ 103b8e80941Smrg#if HAVE_LLVM < 0x0304 104b8e80941Smrg# ifdef __cplusplus 105b8e80941Smrg extern "C" 106b8e80941Smrg# endif 107b8e80941Smrg void LLVMSetAlignmentBackport(LLVMValueRef V, unsigned Bytes); 108b8e80941Smrg# define LLVMSetAlignment LLVMSetAlignmentBackport 109b8e80941Smrg#endif 110b8e80941Smrg 111b8e80941Smrg 112848b8605Smrg#endif /* LP_BLD_H */ 113