├── .gitignore ├── LICENSE ├── README.md ├── examples └── factorial │ └── factorial.go ├── include ├── llvm-c │ ├── Analysis.h │ ├── BitReader.h │ ├── BitWriter.h │ ├── Core.h │ ├── Disassembler.h │ ├── EnhancedDisassembly.h │ ├── ExecutionEngine.h │ ├── Initialization.h │ ├── LinkTimeOptimizer.h │ ├── Linker.h │ ├── Object.h │ ├── Target.h │ ├── TargetMachine.h │ ├── Transforms │ │ ├── IPO.h │ │ ├── PassManagerBuilder.h │ │ ├── Scalar.h │ │ └── Vectorize.h │ └── lto.h └── llvm │ ├── Config │ ├── AsmParsers.def │ ├── AsmPrinters.def │ ├── Disassemblers.def │ ├── Targets.def │ ├── config.h │ └── llvm-config.h │ └── Support │ └── DataTypes.h ├── install.sh └── llvm ├── analysis.go ├── bitreader.go ├── bitwriter.go ├── core.go ├── debug.go ├── executionengine.go ├── executionengine_test.go ├── linker.go ├── string.go ├── string_test.go ├── target.go ├── transforms_ipo.go └── transforms_scalar.go /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.[68] 3 | llvm/_cgo_export.h 4 | llvm/_obj 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2011 Andrew Wilkins 2 | 3 | Copyright (C) 2010 nsf 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | GoLLVM 2 | ------ 3 | 4 | [LLVM](http://llvm.org) bindings for [The Go Programming Language](http://golang.org). 5 | 6 | Prerequisites 7 | ------------- 8 | 9 | * LLVM 3.1+. LLVM must have been built with shared libraries enabled. 10 | * Go 1.0+. 11 | 12 | The author has only built and tested with Linux, but there is no particular reason why GoLLVM should not work with other operating systems. 13 | 14 | Installation 15 | ------------ 16 | 17 | To install, run the following (assuming you have curl and Go installed): 18 | 19 | curl https://raw.github.com/axw/gollvm/master/install.sh | sh 20 | 21 | Alternatively, you can use `go get` directly, but you must then set the 22 | CGO\_CFLAGS and CGO\_LDFLAGS environment variables: 23 | 24 | $ export CGO_CFLAGS=`llvm-config --cflags` 25 | $ export CGO_LDFLAGS="`llvm-config --ldflags` -Wl,-L`llvm-config --libdir` -lLLVM-`llvm-config --version`" 26 | $ go get github.com/axw/gollvm/llvm 27 | 28 | -------------------------------------------------------------------------------- /examples/factorial/factorial.go: -------------------------------------------------------------------------------- 1 | // Taken from: http://npcontemplation.blogspot.com/2008/06/secret-of-llvm-c-bindings.html 2 | package main 3 | 4 | import "fmt" 5 | 6 | import "github.com/axw/gollvm/llvm" 7 | 8 | func test() { 9 | llvm.LinkInJIT() 10 | llvm.InitializeNativeTarget() 11 | 12 | mod := llvm.NewModule("fac_module") 13 | 14 | // don't do that, because ExecutionEngine takes ownership over module 15 | //defer mod.Dispose() 16 | 17 | fac_args := []llvm.Type{llvm.Int32Type()} 18 | fac_type := llvm.FunctionType(llvm.Int32Type(), fac_args, false) 19 | fac := llvm.AddFunction(mod, "fac", fac_type) 20 | fac.SetFunctionCallConv(llvm.CCallConv) 21 | n := fac.Param(0) 22 | 23 | entry := llvm.AddBasicBlock(fac, "entry") 24 | iftrue := llvm.AddBasicBlock(fac, "iftrue") 25 | iffalse := llvm.AddBasicBlock(fac, "iffalse") 26 | end := llvm.AddBasicBlock(fac, "end") 27 | 28 | builder := llvm.NewBuilder() 29 | defer builder.Dispose() 30 | 31 | builder.SetInsertPointAtEnd(entry) 32 | If := builder.CreateICmp(llvm.IntEQ, n, llvm.ConstInt(llvm.Int32Type(), 0, false), "cmptmp") 33 | builder.CreateCondBr(If, iftrue, iffalse) 34 | 35 | builder.SetInsertPointAtEnd(iftrue) 36 | res_iftrue := llvm.ConstInt(llvm.Int32Type(), 1, false) 37 | builder.CreateBr(end) 38 | 39 | builder.SetInsertPointAtEnd(iffalse) 40 | n_minus := builder.CreateSub(n, llvm.ConstInt(llvm.Int32Type(), 1, false), "subtmp") 41 | call_fac_args := []llvm.Value{n_minus} 42 | call_fac := builder.CreateCall(fac, call_fac_args, "calltmp") 43 | res_iffalse := builder.CreateMul(n, call_fac, "multmp") 44 | builder.CreateBr(end) 45 | 46 | builder.SetInsertPointAtEnd(end) 47 | res := builder.CreatePHI(llvm.Int32Type(), "result") 48 | phi_vals := []llvm.Value{res_iftrue, res_iffalse} 49 | phi_blocks := []llvm.BasicBlock{iftrue, iffalse} 50 | res.AddIncoming(phi_vals, phi_blocks) 51 | builder.CreateRet(res) 52 | 53 | err := llvm.VerifyModule(mod, llvm.ReturnStatusAction) 54 | if err != nil { 55 | fmt.Println(err) 56 | return 57 | } 58 | 59 | engine, err := llvm.NewJITCompiler(mod, 2) 60 | if err != nil { 61 | fmt.Println(err) 62 | return 63 | } 64 | defer engine.Dispose() 65 | 66 | pass := llvm.NewPassManager() 67 | defer pass.Dispose() 68 | 69 | pass.Add(engine.TargetData()) 70 | pass.AddConstantPropagationPass() 71 | pass.AddInstructionCombiningPass() 72 | pass.AddPromoteMemoryToRegisterPass() 73 | pass.AddGVNPass() 74 | pass.AddCFGSimplificationPass() 75 | pass.Run(mod) 76 | 77 | mod.Dump() 78 | 79 | exec_args := []llvm.GenericValue{llvm.NewGenericValueFromInt(llvm.Int32Type(), 10, false)} 80 | exec_res := engine.RunFunction(fac, exec_args) 81 | fmt.Println("-----------------------------------------") 82 | fmt.Println("Running fac(10) with JIT...") 83 | fmt.Printf("Result: %d\n", exec_res.Int(false)) 84 | } 85 | 86 | func main() { 87 | test() 88 | fmt.Println("DONE") 89 | } 90 | -------------------------------------------------------------------------------- /include/llvm-c/Analysis.h: -------------------------------------------------------------------------------- 1 | /*===-- llvm-c/Analysis.h - Analysis Library C Interface --------*- C++ -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This header declares the C interface to libLLVMAnalysis.a, which *| 11 | |* implements various analyses of the LLVM IR. *| 12 | |* *| 13 | |* Many exotic languages can interoperate with C code but have a harder time *| 14 | |* with C++ due to name mangling. So in addition to C, this interface enables *| 15 | |* tools written in such languages. *| 16 | |* *| 17 | \*===----------------------------------------------------------------------===*/ 18 | 19 | #ifndef LLVM_C_ANALYSIS_H 20 | #define LLVM_C_ANALYSIS_H 21 | 22 | #include "llvm-c/Core.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /** 29 | * @defgroup LLVMCAnalysis Analysis 30 | * @ingroup LLVMC 31 | * 32 | * @{ 33 | */ 34 | 35 | typedef enum { 36 | LLVMAbortProcessAction, /* verifier will print to stderr and abort() */ 37 | LLVMPrintMessageAction, /* verifier will print to stderr and return 1 */ 38 | LLVMReturnStatusAction /* verifier will just return 1 */ 39 | } LLVMVerifierFailureAction; 40 | 41 | 42 | /* Verifies that a module is valid, taking the specified action if not. 43 | Optionally returns a human-readable description of any invalid constructs. 44 | OutMessage must be disposed with LLVMDisposeMessage. */ 45 | LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action, 46 | char **OutMessage); 47 | 48 | /* Verifies that a single function is valid, taking the specified action. Useful 49 | for debugging. */ 50 | LLVMBool LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action); 51 | 52 | /* Open up a ghostview window that displays the CFG of the current function. 53 | Useful for debugging. */ 54 | void LLVMViewFunctionCFG(LLVMValueRef Fn); 55 | void LLVMViewFunctionCFGOnly(LLVMValueRef Fn); 56 | 57 | /** 58 | * @} 59 | */ 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /include/llvm-c/BitReader.h: -------------------------------------------------------------------------------- 1 | /*===-- llvm-c/BitReader.h - BitReader Library C Interface ------*- C++ -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This header declares the C interface to libLLVMBitReader.a, which *| 11 | |* implements input of the LLVM bitcode format. *| 12 | |* *| 13 | |* Many exotic languages can interoperate with C code but have a harder time *| 14 | |* with C++ due to name mangling. So in addition to C, this interface enables *| 15 | |* tools written in such languages. *| 16 | |* *| 17 | \*===----------------------------------------------------------------------===*/ 18 | 19 | #ifndef LLVM_C_BITCODEREADER_H 20 | #define LLVM_C_BITCODEREADER_H 21 | 22 | #include "llvm-c/Core.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /** 29 | * @defgroup LLVMCBitReader Bit Reader 30 | * @ingroup LLVMC 31 | * 32 | * @{ 33 | */ 34 | 35 | /* Builds a module from the bitcode in the specified memory buffer, returning a 36 | reference to the module via the OutModule parameter. Returns 0 on success. 37 | Optionally returns a human-readable error message via OutMessage. */ 38 | LLVMBool LLVMParseBitcode(LLVMMemoryBufferRef MemBuf, 39 | LLVMModuleRef *OutModule, char **OutMessage); 40 | 41 | LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef, 42 | LLVMMemoryBufferRef MemBuf, 43 | LLVMModuleRef *OutModule, char **OutMessage); 44 | 45 | /** Reads a module from the specified path, returning via the OutMP parameter 46 | a module provider which performs lazy deserialization. Returns 0 on success. 47 | Optionally returns a human-readable error message via OutMessage. */ 48 | LLVMBool LLVMGetBitcodeModuleInContext(LLVMContextRef ContextRef, 49 | LLVMMemoryBufferRef MemBuf, 50 | LLVMModuleRef *OutM, 51 | char **OutMessage); 52 | 53 | LLVMBool LLVMGetBitcodeModule(LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM, 54 | char **OutMessage); 55 | 56 | 57 | /** Deprecated: Use LLVMGetBitcodeModuleInContext instead. */ 58 | LLVMBool LLVMGetBitcodeModuleProviderInContext(LLVMContextRef ContextRef, 59 | LLVMMemoryBufferRef MemBuf, 60 | LLVMModuleProviderRef *OutMP, 61 | char **OutMessage); 62 | 63 | /** Deprecated: Use LLVMGetBitcodeModule instead. */ 64 | LLVMBool LLVMGetBitcodeModuleProvider(LLVMMemoryBufferRef MemBuf, 65 | LLVMModuleProviderRef *OutMP, 66 | char **OutMessage); 67 | 68 | /** 69 | * @} 70 | */ 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /include/llvm-c/BitWriter.h: -------------------------------------------------------------------------------- 1 | /*===-- llvm-c/BitWriter.h - BitWriter Library C Interface ------*- C++ -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This header declares the C interface to libLLVMBitWriter.a, which *| 11 | |* implements output of the LLVM bitcode format. *| 12 | |* *| 13 | |* Many exotic languages can interoperate with C code but have a harder time *| 14 | |* with C++ due to name mangling. So in addition to C, this interface enables *| 15 | |* tools written in such languages. *| 16 | |* *| 17 | \*===----------------------------------------------------------------------===*/ 18 | 19 | #ifndef LLVM_C_BITCODEWRITER_H 20 | #define LLVM_C_BITCODEWRITER_H 21 | 22 | #include "llvm-c/Core.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /** 29 | * @defgroup LLVMCBitWriter Bit Writer 30 | * @ingroup LLVMC 31 | * 32 | * @{ 33 | */ 34 | 35 | /*===-- Operations on modules ---------------------------------------------===*/ 36 | 37 | /** Writes a module to the specified path. Returns 0 on success. */ 38 | int LLVMWriteBitcodeToFile(LLVMModuleRef M, const char *Path); 39 | 40 | /** Writes a module to an open file descriptor. Returns 0 on success. */ 41 | int LLVMWriteBitcodeToFD(LLVMModuleRef M, int FD, int ShouldClose, 42 | int Unbuffered); 43 | 44 | /** Deprecated for LLVMWriteBitcodeToFD. Writes a module to an open file 45 | descriptor. Returns 0 on success. Closes the Handle. */ 46 | int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int Handle); 47 | 48 | /** 49 | * @} 50 | */ 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /include/llvm-c/Disassembler.h: -------------------------------------------------------------------------------- 1 | /*===-- llvm-c/Disassembler.h - Disassembler Public C Interface ---*- C -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This header provides a public interface to a disassembler library. *| 11 | |* LLVM provides an implementation of this interface. *| 12 | |* *| 13 | \*===----------------------------------------------------------------------===*/ 14 | 15 | #ifndef LLVM_C_DISASSEMBLER_H 16 | #define LLVM_C_DISASSEMBLER_H 17 | 18 | #include "llvm/Support/DataTypes.h" 19 | #include 20 | 21 | /** 22 | * @defgroup LLVMCDisassembler Disassembler 23 | * @ingroup LLVMC 24 | * 25 | * @{ 26 | */ 27 | 28 | /** 29 | * An opaque reference to a disassembler context. 30 | */ 31 | typedef void *LLVMDisasmContextRef; 32 | 33 | /** 34 | * The type for the operand information call back function. This is called to 35 | * get the symbolic information for an operand of an instruction. Typically 36 | * this is from the relocation information, symbol table, etc. That block of 37 | * information is saved when the disassembler context is created and passed to 38 | * the call back in the DisInfo parameter. The instruction containing operand 39 | * is at the PC parameter. For some instruction sets, there can be more than 40 | * one operand with symbolic information. To determine the symbolic operand 41 | * information for each operand, the bytes for the specific operand in the 42 | * instruction are specified by the Offset parameter and its byte widith is the 43 | * size parameter. For instructions sets with fixed widths and one symbolic 44 | * operand per instruction, the Offset parameter will be zero and Size parameter 45 | * will be the instruction width. The information is returned in TagBuf and is 46 | * Triple specific with its specific information defined by the value of 47 | * TagType for that Triple. If symbolic information is returned the function 48 | * returns 1, otherwise it returns 0. 49 | */ 50 | typedef int (*LLVMOpInfoCallback)(void *DisInfo, uint64_t PC, 51 | uint64_t Offset, uint64_t Size, 52 | int TagType, void *TagBuf); 53 | 54 | /** 55 | * The initial support in LLVM MC for the most general form of a relocatable 56 | * expression is "AddSymbol - SubtractSymbol + Offset". For some Darwin targets 57 | * this full form is encoded in the relocation information so that AddSymbol and 58 | * SubtractSymbol can be link edited independent of each other. Many other 59 | * platforms only allow a relocatable expression of the form AddSymbol + Offset 60 | * to be encoded. 61 | * 62 | * The LLVMOpInfoCallback() for the TagType value of 1 uses the struct 63 | * LLVMOpInfo1. The value of the relocatable expression for the operand, 64 | * including any PC adjustment, is passed in to the call back in the Value 65 | * field. The symbolic information about the operand is returned using all 66 | * the fields of the structure with the Offset of the relocatable expression 67 | * returned in the Value field. It is possible that some symbols in the 68 | * relocatable expression were assembly temporary symbols, for example 69 | * "Ldata - LpicBase + constant", and only the Values of the symbols without 70 | * symbol names are present in the relocation information. The VariantKind 71 | * type is one of the Target specific #defines below and is used to print 72 | * operands like "_foo@GOT", ":lower16:_foo", etc. 73 | */ 74 | struct LLVMOpInfoSymbol1 { 75 | uint64_t Present; /* 1 if this symbol is present */ 76 | const char *Name; /* symbol name if not NULL */ 77 | uint64_t Value; /* symbol value if name is NULL */ 78 | }; 79 | 80 | struct LLVMOpInfo1 { 81 | struct LLVMOpInfoSymbol1 AddSymbol; 82 | struct LLVMOpInfoSymbol1 SubtractSymbol; 83 | uint64_t Value; 84 | uint64_t VariantKind; 85 | }; 86 | 87 | /** 88 | * The operand VariantKinds for symbolic disassembly. 89 | */ 90 | #define LLVMDisassembler_VariantKind_None 0 /* all targets */ 91 | 92 | /** 93 | * The ARM target VariantKinds. 94 | */ 95 | #define LLVMDisassembler_VariantKind_ARM_HI16 1 /* :upper16: */ 96 | #define LLVMDisassembler_VariantKind_ARM_LO16 2 /* :lower16: */ 97 | 98 | /** 99 | * The type for the symbol lookup function. This may be called by the 100 | * disassembler for things like adding a comment for a PC plus a constant 101 | * offset load instruction to use a symbol name instead of a load address value. 102 | * It is passed the block information is saved when the disassembler context is 103 | * created and the ReferenceValue to look up as a symbol. If no symbol is found 104 | * for the ReferenceValue NULL is returned. The ReferenceType of the 105 | * instruction is passed indirectly as is the PC of the instruction in 106 | * ReferencePC. If the output reference can be determined its type is returned 107 | * indirectly in ReferenceType along with ReferenceName if any, or that is set 108 | * to NULL. 109 | */ 110 | typedef const char *(*LLVMSymbolLookupCallback)(void *DisInfo, 111 | uint64_t ReferenceValue, 112 | uint64_t *ReferenceType, 113 | uint64_t ReferencePC, 114 | const char **ReferenceName); 115 | /** 116 | * The reference types on input and output. 117 | */ 118 | /* No input reference type or no output reference type. */ 119 | #define LLVMDisassembler_ReferenceType_InOut_None 0 120 | 121 | /* The input reference is from a branch instruction. */ 122 | #define LLVMDisassembler_ReferenceType_In_Branch 1 123 | /* The input reference is from a PC relative load instruction. */ 124 | #define LLVMDisassembler_ReferenceType_In_PCrel_Load 2 125 | 126 | /* The output reference is to as symbol stub. */ 127 | #define LLVMDisassembler_ReferenceType_Out_SymbolStub 1 128 | /* The output reference is to a symbol address in a literal pool. */ 129 | #define LLVMDisassembler_ReferenceType_Out_LitPool_SymAddr 2 130 | /* The output reference is to a cstring address in a literal pool. */ 131 | #define LLVMDisassembler_ReferenceType_Out_LitPool_CstrAddr 3 132 | 133 | #ifdef __cplusplus 134 | extern "C" { 135 | #endif /* !defined(__cplusplus) */ 136 | 137 | /** 138 | * Create a disassembler for the TripleName. Symbolic disassembly is supported 139 | * by passing a block of information in the DisInfo parameter and specifying the 140 | * TagType and callback functions as described above. These can all be passed 141 | * as NULL. If successful, this returns a disassembler context. If not, it 142 | * returns NULL. 143 | */ 144 | LLVMDisasmContextRef LLVMCreateDisasm(const char *TripleName, void *DisInfo, 145 | int TagType, LLVMOpInfoCallback GetOpInfo, 146 | LLVMSymbolLookupCallback SymbolLookUp); 147 | 148 | /** 149 | * Dispose of a disassembler context. 150 | */ 151 | void LLVMDisasmDispose(LLVMDisasmContextRef DC); 152 | 153 | /** 154 | * Disassemble a single instruction using the disassembler context specified in 155 | * the parameter DC. The bytes of the instruction are specified in the 156 | * parameter Bytes, and contains at least BytesSize number of bytes. The 157 | * instruction is at the address specified by the PC parameter. If a valid 158 | * instruction can be disassembled, its string is returned indirectly in 159 | * OutString whose size is specified in the parameter OutStringSize. This 160 | * function returns the number of bytes in the instruction or zero if there was 161 | * no valid instruction. 162 | */ 163 | size_t LLVMDisasmInstruction(LLVMDisasmContextRef DC, uint8_t *Bytes, 164 | uint64_t BytesSize, uint64_t PC, 165 | char *OutString, size_t OutStringSize); 166 | 167 | /** 168 | * @} 169 | */ 170 | 171 | #ifdef __cplusplus 172 | } 173 | #endif /* !defined(__cplusplus) */ 174 | 175 | #endif /* !defined(LLVM_C_DISASSEMBLER_H) */ 176 | -------------------------------------------------------------------------------- /include/llvm-c/EnhancedDisassembly.h: -------------------------------------------------------------------------------- 1 | /*===-- llvm-c/EnhancedDisassembly.h - Disassembler C Interface ---*- C -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This header declares the C interface to EnhancedDisassembly.so, which *| 11 | |* implements a disassembler with the ability to extract operand values and *| 12 | |* individual tokens from assembly instructions. *| 13 | |* *| 14 | |* The header declares additional interfaces if the host compiler supports *| 15 | |* the blocks API. *| 16 | |* *| 17 | \*===----------------------------------------------------------------------===*/ 18 | 19 | #ifndef LLVM_C_ENHANCEDDISASSEMBLY_H 20 | #define LLVM_C_ENHANCEDDISASSEMBLY_H 21 | 22 | #include "llvm/Support/DataTypes.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /** 29 | * @defgroup LLVMCEnhancedDisassembly Enhanced Disassembly 30 | * @ingroup LLVMC 31 | * @deprecated 32 | * 33 | * This module contains an interface to the Enhanced Disassembly (edis) 34 | * library. The edis library is deprecated and will likely disappear in 35 | * the near future. You should use the @ref LLVMCDisassembler interface 36 | * instead. 37 | * 38 | * @{ 39 | */ 40 | 41 | /*! 42 | @typedef EDByteReaderCallback 43 | Interface to memory from which instructions may be read. 44 | @param byte A pointer whose target should be filled in with the data returned. 45 | @param address The address of the byte to be read. 46 | @param arg An anonymous argument for client use. 47 | @result 0 on success; -1 otherwise. 48 | */ 49 | typedef int (*EDByteReaderCallback)(uint8_t *byte, uint64_t address, void *arg); 50 | 51 | /*! 52 | @typedef EDRegisterReaderCallback 53 | Interface to registers from which registers may be read. 54 | @param value A pointer whose target should be filled in with the value of the 55 | register. 56 | @param regID The LLVM register identifier for the register to read. 57 | @param arg An anonymous argument for client use. 58 | @result 0 if the register could be read; -1 otherwise. 59 | */ 60 | typedef int (*EDRegisterReaderCallback)(uint64_t *value, unsigned regID, 61 | void* arg); 62 | 63 | /*! 64 | @typedef EDAssemblySyntax_t 65 | An assembly syntax for use in tokenizing instructions. 66 | */ 67 | enum { 68 | /*! @constant kEDAssemblySyntaxX86Intel Intel syntax for i386 and x86_64. */ 69 | kEDAssemblySyntaxX86Intel = 0, 70 | /*! @constant kEDAssemblySyntaxX86ATT AT&T syntax for i386 and x86_64. */ 71 | kEDAssemblySyntaxX86ATT = 1, 72 | kEDAssemblySyntaxARMUAL = 2 73 | }; 74 | typedef unsigned EDAssemblySyntax_t; 75 | 76 | /*! 77 | @typedef EDDisassemblerRef 78 | Encapsulates a disassembler for a single CPU architecture. 79 | */ 80 | typedef void *EDDisassemblerRef; 81 | 82 | /*! 83 | @typedef EDInstRef 84 | Encapsulates a single disassembled instruction in one assembly syntax. 85 | */ 86 | typedef void *EDInstRef; 87 | 88 | /*! 89 | @typedef EDTokenRef 90 | Encapsulates a token from the disassembly of an instruction. 91 | */ 92 | typedef void *EDTokenRef; 93 | 94 | /*! 95 | @typedef EDOperandRef 96 | Encapsulates an operand of an instruction. 97 | */ 98 | typedef void *EDOperandRef; 99 | 100 | /*! 101 | @functiongroup Getting a disassembler 102 | */ 103 | 104 | /*! 105 | @function EDGetDisassembler 106 | Gets the disassembler for a given target. 107 | @param disassembler A pointer whose target will be filled in with the 108 | disassembler. 109 | @param triple Identifies the target. Example: "x86_64-apple-darwin10" 110 | @param syntax The assembly syntax to use when decoding instructions. 111 | @result 0 on success; -1 otherwise. 112 | */ 113 | int EDGetDisassembler(EDDisassemblerRef *disassembler, 114 | const char *triple, 115 | EDAssemblySyntax_t syntax); 116 | 117 | /*! 118 | @functiongroup Generic architectural queries 119 | */ 120 | 121 | /*! 122 | @function EDGetRegisterName 123 | Gets the human-readable name for a given register. 124 | @param regName A pointer whose target will be pointed at the name of the 125 | register. The name does not need to be deallocated and will be 126 | @param disassembler The disassembler to query for the name. 127 | @param regID The register identifier, as returned by EDRegisterTokenValue. 128 | @result 0 on success; -1 otherwise. 129 | */ 130 | int EDGetRegisterName(const char** regName, 131 | EDDisassemblerRef disassembler, 132 | unsigned regID); 133 | 134 | /*! 135 | @function EDRegisterIsStackPointer 136 | Determines if a register is one of the platform's stack-pointer registers. 137 | @param disassembler The disassembler to query. 138 | @param regID The register identifier, as returned by EDRegisterTokenValue. 139 | @result 1 if true; 0 otherwise. 140 | */ 141 | int EDRegisterIsStackPointer(EDDisassemblerRef disassembler, 142 | unsigned regID); 143 | 144 | /*! 145 | @function EDRegisterIsProgramCounter 146 | Determines if a register is one of the platform's stack-pointer registers. 147 | @param disassembler The disassembler to query. 148 | @param regID The register identifier, as returned by EDRegisterTokenValue. 149 | @result 1 if true; 0 otherwise. 150 | */ 151 | int EDRegisterIsProgramCounter(EDDisassemblerRef disassembler, 152 | unsigned regID); 153 | 154 | /*! 155 | @functiongroup Creating and querying instructions 156 | */ 157 | 158 | /*! 159 | @function EDCreateInst 160 | Gets a set of contiguous instructions from a disassembler. 161 | @param insts A pointer to an array that will be filled in with the 162 | instructions. Must have at least count entries. Entries not filled in will 163 | be set to NULL. 164 | @param count The maximum number of instructions to fill in. 165 | @param disassembler The disassembler to use when decoding the instructions. 166 | @param byteReader The function to use when reading the instruction's machine 167 | code. 168 | @param address The address of the first byte of the instruction. 169 | @param arg An anonymous argument to be passed to byteReader. 170 | @result The number of instructions read on success; 0 otherwise. 171 | */ 172 | unsigned int EDCreateInsts(EDInstRef *insts, 173 | unsigned int count, 174 | EDDisassemblerRef disassembler, 175 | EDByteReaderCallback byteReader, 176 | uint64_t address, 177 | void *arg); 178 | 179 | /*! 180 | @function EDReleaseInst 181 | Frees the memory for an instruction. The instruction can no longer be accessed 182 | after this call. 183 | @param inst The instruction to be freed. 184 | */ 185 | void EDReleaseInst(EDInstRef inst); 186 | 187 | /*! 188 | @function EDInstByteSize 189 | @param inst The instruction to be queried. 190 | @result The number of bytes in the instruction's machine-code representation. 191 | */ 192 | int EDInstByteSize(EDInstRef inst); 193 | 194 | /*! 195 | @function EDGetInstString 196 | Gets the disassembled text equivalent of the instruction. 197 | @param buf A pointer whose target will be filled in with a pointer to the 198 | string. (The string becomes invalid when the instruction is released.) 199 | @param inst The instruction to be queried. 200 | @result 0 on success; -1 otherwise. 201 | */ 202 | int EDGetInstString(const char **buf, 203 | EDInstRef inst); 204 | 205 | /*! 206 | @function EDInstID 207 | @param instID A pointer whose target will be filled in with the LLVM identifier 208 | for the instruction. 209 | @param inst The instruction to be queried. 210 | @result 0 on success; -1 otherwise. 211 | */ 212 | int EDInstID(unsigned *instID, EDInstRef inst); 213 | 214 | /*! 215 | @function EDInstIsBranch 216 | @param inst The instruction to be queried. 217 | @result 1 if the instruction is a branch instruction; 0 if it is some other 218 | type of instruction; -1 if there was an error. 219 | */ 220 | int EDInstIsBranch(EDInstRef inst); 221 | 222 | /*! 223 | @function EDInstIsMove 224 | @param inst The instruction to be queried. 225 | @result 1 if the instruction is a move instruction; 0 if it is some other 226 | type of instruction; -1 if there was an error. 227 | */ 228 | int EDInstIsMove(EDInstRef inst); 229 | 230 | /*! 231 | @function EDBranchTargetID 232 | @param inst The instruction to be queried. 233 | @result The ID of the branch target operand, suitable for use with 234 | EDCopyOperand. -1 if no such operand exists. 235 | */ 236 | int EDBranchTargetID(EDInstRef inst); 237 | 238 | /*! 239 | @function EDMoveSourceID 240 | @param inst The instruction to be queried. 241 | @result The ID of the move source operand, suitable for use with 242 | EDCopyOperand. -1 if no such operand exists. 243 | */ 244 | int EDMoveSourceID(EDInstRef inst); 245 | 246 | /*! 247 | @function EDMoveTargetID 248 | @param inst The instruction to be queried. 249 | @result The ID of the move source operand, suitable for use with 250 | EDCopyOperand. -1 if no such operand exists. 251 | */ 252 | int EDMoveTargetID(EDInstRef inst); 253 | 254 | /*! 255 | @functiongroup Creating and querying tokens 256 | */ 257 | 258 | /*! 259 | @function EDNumTokens 260 | @param inst The instruction to be queried. 261 | @result The number of tokens in the instruction, or -1 on error. 262 | */ 263 | int EDNumTokens(EDInstRef inst); 264 | 265 | /*! 266 | @function EDGetToken 267 | Retrieves a token from an instruction. The token is valid until the 268 | instruction is released. 269 | @param token A pointer to be filled in with the token. 270 | @param inst The instruction to be queried. 271 | @param index The index of the token in the instruction. 272 | @result 0 on success; -1 otherwise. 273 | */ 274 | int EDGetToken(EDTokenRef *token, 275 | EDInstRef inst, 276 | int index); 277 | 278 | /*! 279 | @function EDGetTokenString 280 | Gets the disassembled text for a token. 281 | @param buf A pointer whose target will be filled in with a pointer to the 282 | string. (The string becomes invalid when the token is released.) 283 | @param token The token to be queried. 284 | @result 0 on success; -1 otherwise. 285 | */ 286 | int EDGetTokenString(const char **buf, 287 | EDTokenRef token); 288 | 289 | /*! 290 | @function EDOperandIndexForToken 291 | Returns the index of the operand to which a token belongs. 292 | @param token The token to be queried. 293 | @result The operand index on success; -1 otherwise 294 | */ 295 | int EDOperandIndexForToken(EDTokenRef token); 296 | 297 | /*! 298 | @function EDTokenIsWhitespace 299 | @param token The token to be queried. 300 | @result 1 if the token is whitespace; 0 if not; -1 on error. 301 | */ 302 | int EDTokenIsWhitespace(EDTokenRef token); 303 | 304 | /*! 305 | @function EDTokenIsPunctuation 306 | @param token The token to be queried. 307 | @result 1 if the token is punctuation; 0 if not; -1 on error. 308 | */ 309 | int EDTokenIsPunctuation(EDTokenRef token); 310 | 311 | /*! 312 | @function EDTokenIsOpcode 313 | @param token The token to be queried. 314 | @result 1 if the token is opcode; 0 if not; -1 on error. 315 | */ 316 | int EDTokenIsOpcode(EDTokenRef token); 317 | 318 | /*! 319 | @function EDTokenIsLiteral 320 | @param token The token to be queried. 321 | @result 1 if the token is a numeric literal; 0 if not; -1 on error. 322 | */ 323 | int EDTokenIsLiteral(EDTokenRef token); 324 | 325 | /*! 326 | @function EDTokenIsRegister 327 | @param token The token to be queried. 328 | @result 1 if the token identifies a register; 0 if not; -1 on error. 329 | */ 330 | int EDTokenIsRegister(EDTokenRef token); 331 | 332 | /*! 333 | @function EDTokenIsNegativeLiteral 334 | @param token The token to be queried. 335 | @result 1 if the token is a negative signed literal; 0 if not; -1 on error. 336 | */ 337 | int EDTokenIsNegativeLiteral(EDTokenRef token); 338 | 339 | /*! 340 | @function EDLiteralTokenAbsoluteValue 341 | @param value A pointer whose target will be filled in with the absolute value 342 | of the literal. 343 | @param token The token to be queried. 344 | @result 0 on success; -1 otherwise. 345 | */ 346 | int EDLiteralTokenAbsoluteValue(uint64_t *value, 347 | EDTokenRef token); 348 | 349 | /*! 350 | @function EDRegisterTokenValue 351 | @param registerID A pointer whose target will be filled in with the LLVM 352 | register identifier for the token. 353 | @param token The token to be queried. 354 | @result 0 on success; -1 otherwise. 355 | */ 356 | int EDRegisterTokenValue(unsigned *registerID, 357 | EDTokenRef token); 358 | 359 | /*! 360 | @functiongroup Creating and querying operands 361 | */ 362 | 363 | /*! 364 | @function EDNumOperands 365 | @param inst The instruction to be queried. 366 | @result The number of operands in the instruction, or -1 on error. 367 | */ 368 | int EDNumOperands(EDInstRef inst); 369 | 370 | /*! 371 | @function EDGetOperand 372 | Retrieves an operand from an instruction. The operand is valid until the 373 | instruction is released. 374 | @param operand A pointer to be filled in with the operand. 375 | @param inst The instruction to be queried. 376 | @param index The index of the operand in the instruction. 377 | @result 0 on success; -1 otherwise. 378 | */ 379 | int EDGetOperand(EDOperandRef *operand, 380 | EDInstRef inst, 381 | int index); 382 | 383 | /*! 384 | @function EDOperandIsRegister 385 | @param operand The operand to be queried. 386 | @result 1 if the operand names a register; 0 if not; -1 on error. 387 | */ 388 | int EDOperandIsRegister(EDOperandRef operand); 389 | 390 | /*! 391 | @function EDOperandIsImmediate 392 | @param operand The operand to be queried. 393 | @result 1 if the operand specifies an immediate value; 0 if not; -1 on error. 394 | */ 395 | int EDOperandIsImmediate(EDOperandRef operand); 396 | 397 | /*! 398 | @function EDOperandIsMemory 399 | @param operand The operand to be queried. 400 | @result 1 if the operand specifies a location in memory; 0 if not; -1 on error. 401 | */ 402 | int EDOperandIsMemory(EDOperandRef operand); 403 | 404 | /*! 405 | @function EDRegisterOperandValue 406 | @param value A pointer whose target will be filled in with the LLVM register ID 407 | of the register named by the operand. 408 | @param operand The operand to be queried. 409 | @result 0 on success; -1 otherwise. 410 | */ 411 | int EDRegisterOperandValue(unsigned *value, 412 | EDOperandRef operand); 413 | 414 | /*! 415 | @function EDImmediateOperandValue 416 | @param value A pointer whose target will be filled in with the value of the 417 | immediate. 418 | @param operand The operand to be queried. 419 | @result 0 on success; -1 otherwise. 420 | */ 421 | int EDImmediateOperandValue(uint64_t *value, 422 | EDOperandRef operand); 423 | 424 | /*! 425 | @function EDEvaluateOperand 426 | Evaluates an operand using a client-supplied register state accessor. Register 427 | operands are evaluated by reading the value of the register; immediate operands 428 | are evaluated by reporting the immediate value; memory operands are evaluated 429 | by computing the target address (with only those relocations applied that were 430 | already applied to the original bytes). 431 | @param result A pointer whose target is to be filled with the result of 432 | evaluating the operand. 433 | @param operand The operand to be evaluated. 434 | @param regReader The function to use when reading registers from the register 435 | state. 436 | @param arg An anonymous argument for client use. 437 | @result 0 if the operand could be evaluated; -1 otherwise. 438 | */ 439 | int EDEvaluateOperand(uint64_t *result, 440 | EDOperandRef operand, 441 | EDRegisterReaderCallback regReader, 442 | void *arg); 443 | 444 | #ifdef __BLOCKS__ 445 | 446 | /*! 447 | @typedef EDByteBlock_t 448 | Block-based interface to memory from which instructions may be read. 449 | @param byte A pointer whose target should be filled in with the data returned. 450 | @param address The address of the byte to be read. 451 | @result 0 on success; -1 otherwise. 452 | */ 453 | typedef int (^EDByteBlock_t)(uint8_t *byte, uint64_t address); 454 | 455 | /*! 456 | @typedef EDRegisterBlock_t 457 | Block-based interface to registers from which registers may be read. 458 | @param value A pointer whose target should be filled in with the value of the 459 | register. 460 | @param regID The LLVM register identifier for the register to read. 461 | @result 0 if the register could be read; -1 otherwise. 462 | */ 463 | typedef int (^EDRegisterBlock_t)(uint64_t *value, unsigned regID); 464 | 465 | /*! 466 | @typedef EDTokenVisitor_t 467 | Block-based handler for individual tokens. 468 | @param token The current token being read. 469 | @result 0 to continue; 1 to stop normally; -1 on error. 470 | */ 471 | typedef int (^EDTokenVisitor_t)(EDTokenRef token); 472 | 473 | /*! @functiongroup Block-based interfaces */ 474 | 475 | /*! 476 | @function EDBlockCreateInsts 477 | Gets a set of contiguous instructions from a disassembler, using a block to 478 | read memory. 479 | @param insts A pointer to an array that will be filled in with the 480 | instructions. Must have at least count entries. Entries not filled in will 481 | be set to NULL. 482 | @param count The maximum number of instructions to fill in. 483 | @param disassembler The disassembler to use when decoding the instructions. 484 | @param byteBlock The block to use when reading the instruction's machine 485 | code. 486 | @param address The address of the first byte of the instruction. 487 | @result The number of instructions read on success; 0 otherwise. 488 | */ 489 | unsigned int EDBlockCreateInsts(EDInstRef *insts, 490 | int count, 491 | EDDisassemblerRef disassembler, 492 | EDByteBlock_t byteBlock, 493 | uint64_t address); 494 | 495 | /*! 496 | @function EDBlockEvaluateOperand 497 | Evaluates an operand using a block to read registers. 498 | @param result A pointer whose target is to be filled with the result of 499 | evaluating the operand. 500 | @param operand The operand to be evaluated. 501 | @param regBlock The block to use when reading registers from the register 502 | state. 503 | @result 0 if the operand could be evaluated; -1 otherwise. 504 | */ 505 | int EDBlockEvaluateOperand(uint64_t *result, 506 | EDOperandRef operand, 507 | EDRegisterBlock_t regBlock); 508 | 509 | /*! 510 | @function EDBlockVisitTokens 511 | Visits every token with a visitor. 512 | @param inst The instruction with the tokens to be visited. 513 | @param visitor The visitor. 514 | @result 0 if the visit ended normally; -1 if the visitor encountered an error 515 | or there was some other error. 516 | */ 517 | int EDBlockVisitTokens(EDInstRef inst, 518 | EDTokenVisitor_t visitor); 519 | 520 | /** 521 | * @} 522 | */ 523 | 524 | #endif 525 | 526 | #ifdef __cplusplus 527 | } 528 | #endif 529 | 530 | #endif 531 | -------------------------------------------------------------------------------- /include/llvm-c/ExecutionEngine.h: -------------------------------------------------------------------------------- 1 | /*===-- llvm-c/ExecutionEngine.h - ExecutionEngine Lib C Iface --*- C++ -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This header declares the C interface to libLLVMExecutionEngine.o, which *| 11 | |* implements various analyses of the LLVM IR. *| 12 | |* *| 13 | |* Many exotic languages can interoperate with C code but have a harder time *| 14 | |* with C++ due to name mangling. So in addition to C, this interface enables *| 15 | |* tools written in such languages. *| 16 | |* *| 17 | \*===----------------------------------------------------------------------===*/ 18 | 19 | #ifndef LLVM_C_EXECUTIONENGINE_H 20 | #define LLVM_C_EXECUTIONENGINE_H 21 | 22 | #include "llvm-c/Core.h" 23 | #include "llvm-c/Target.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /** 30 | * @defgroup LLVMCExecutionEngine Execution Engine 31 | * @ingroup LLVMC 32 | * 33 | * @{ 34 | */ 35 | 36 | void LLVMLinkInJIT(void); 37 | void LLVMLinkInInterpreter(void); 38 | 39 | typedef struct LLVMOpaqueGenericValue *LLVMGenericValueRef; 40 | typedef struct LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef; 41 | 42 | /*===-- Operations on generic values --------------------------------------===*/ 43 | 44 | LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty, 45 | unsigned long long N, 46 | LLVMBool IsSigned); 47 | 48 | LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P); 49 | 50 | LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N); 51 | 52 | unsigned LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef); 53 | 54 | unsigned long long LLVMGenericValueToInt(LLVMGenericValueRef GenVal, 55 | LLVMBool IsSigned); 56 | 57 | void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal); 58 | 59 | double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal); 60 | 61 | void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal); 62 | 63 | /*===-- Operations on execution engines -----------------------------------===*/ 64 | 65 | LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE, 66 | LLVMModuleRef M, 67 | char **OutError); 68 | 69 | LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp, 70 | LLVMModuleRef M, 71 | char **OutError); 72 | 73 | LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT, 74 | LLVMModuleRef M, 75 | unsigned OptLevel, 76 | char **OutError); 77 | 78 | /** Deprecated: Use LLVMCreateExecutionEngineForModule instead. */ 79 | LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE, 80 | LLVMModuleProviderRef MP, 81 | char **OutError); 82 | 83 | /** Deprecated: Use LLVMCreateInterpreterForModule instead. */ 84 | LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp, 85 | LLVMModuleProviderRef MP, 86 | char **OutError); 87 | 88 | /** Deprecated: Use LLVMCreateJITCompilerForModule instead. */ 89 | LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT, 90 | LLVMModuleProviderRef MP, 91 | unsigned OptLevel, 92 | char **OutError); 93 | 94 | void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE); 95 | 96 | void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE); 97 | 98 | void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE); 99 | 100 | int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F, 101 | unsigned ArgC, const char * const *ArgV, 102 | const char * const *EnvP); 103 | 104 | LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F, 105 | unsigned NumArgs, 106 | LLVMGenericValueRef *Args); 107 | 108 | void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F); 109 | 110 | void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M); 111 | 112 | /** Deprecated: Use LLVMAddModule instead. */ 113 | void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP); 114 | 115 | LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M, 116 | LLVMModuleRef *OutMod, char **OutError); 117 | 118 | /** Deprecated: Use LLVMRemoveModule instead. */ 119 | LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE, 120 | LLVMModuleProviderRef MP, 121 | LLVMModuleRef *OutMod, char **OutError); 122 | 123 | LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const char *Name, 124 | LLVMValueRef *OutFn); 125 | 126 | void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE, LLVMValueRef Fn); 127 | 128 | LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE); 129 | 130 | void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global, 131 | void* Addr); 132 | 133 | void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global); 134 | 135 | /** 136 | * @} 137 | */ 138 | 139 | #ifdef __cplusplus 140 | } 141 | 142 | namespace llvm { 143 | struct GenericValue; 144 | class ExecutionEngine; 145 | 146 | #define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref) \ 147 | inline ty *unwrap(ref P) { \ 148 | return reinterpret_cast(P); \ 149 | } \ 150 | \ 151 | inline ref wrap(const ty *P) { \ 152 | return reinterpret_cast(const_cast(P)); \ 153 | } 154 | 155 | DEFINE_SIMPLE_CONVERSION_FUNCTIONS(GenericValue, LLVMGenericValueRef ) 156 | DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ExecutionEngine, LLVMExecutionEngineRef) 157 | 158 | #undef DEFINE_SIMPLE_CONVERSION_FUNCTIONS 159 | } 160 | 161 | #endif /* defined(__cplusplus) */ 162 | 163 | #endif 164 | -------------------------------------------------------------------------------- /include/llvm-c/Initialization.h: -------------------------------------------------------------------------------- 1 | /*===-- llvm-c/Initialization.h - Initialization C Interface ------*- C -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This header declares the C interface to LLVM initialization routines, *| 11 | |* which must be called before you can use the functionality provided by *| 12 | |* the corresponding LLVM library. *| 13 | |* *| 14 | \*===----------------------------------------------------------------------===*/ 15 | 16 | #ifndef LLVM_C_INITIALIZEPASSES_H 17 | #define LLVM_C_INITIALIZEPASSES_H 18 | 19 | #include "llvm-c/Core.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | /** 26 | * @defgroup LLVMCInitialization Initialization Routines 27 | * @ingroup LLVMC 28 | * 29 | * This module contains routines used to initialize the LLVM system. 30 | * 31 | * @{ 32 | */ 33 | 34 | void LLVMInitializeCore(LLVMPassRegistryRef R); 35 | void LLVMInitializeTransformUtils(LLVMPassRegistryRef R); 36 | void LLVMInitializeScalarOpts(LLVMPassRegistryRef R); 37 | void LLVMInitializeVectorization(LLVMPassRegistryRef R); 38 | void LLVMInitializeInstCombine(LLVMPassRegistryRef R); 39 | void LLVMInitializeIPO(LLVMPassRegistryRef R); 40 | void LLVMInitializeInstrumentation(LLVMPassRegistryRef R); 41 | void LLVMInitializeAnalysis(LLVMPassRegistryRef R); 42 | void LLVMInitializeIPA(LLVMPassRegistryRef R); 43 | void LLVMInitializeCodeGen(LLVMPassRegistryRef R); 44 | void LLVMInitializeTarget(LLVMPassRegistryRef R); 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /include/llvm-c/LinkTimeOptimizer.h: -------------------------------------------------------------------------------- 1 | //===-- llvm/LinkTimeOptimizer.h - LTO Public C Interface -------*- C++ -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is distributed under the University of Illinois Open Source 6 | // License. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This header provides a C API to use the LLVM link time optimization 11 | // library. This is intended to be used by linkers which are C-only in 12 | // their implementation for performing LTO. 13 | // 14 | //===----------------------------------------------------------------------===// 15 | 16 | #ifndef __LTO_CAPI_H__ 17 | #define __LTO_CAPI_H__ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /** 24 | * @defgroup LLVMCLinkTimeOptimizer Link Time Optimization 25 | * @ingroup LLVMC 26 | * 27 | * @{ 28 | */ 29 | 30 | /// This provides a dummy type for pointers to the LTO object. 31 | typedef void* llvm_lto_t; 32 | 33 | /// This provides a C-visible enumerator to manage status codes. 34 | /// This should map exactly onto the C++ enumerator LTOStatus. 35 | typedef enum llvm_lto_status { 36 | LLVM_LTO_UNKNOWN, 37 | LLVM_LTO_OPT_SUCCESS, 38 | LLVM_LTO_READ_SUCCESS, 39 | LLVM_LTO_READ_FAILURE, 40 | LLVM_LTO_WRITE_FAILURE, 41 | LLVM_LTO_NO_TARGET, 42 | LLVM_LTO_NO_WORK, 43 | LLVM_LTO_MODULE_MERGE_FAILURE, 44 | LLVM_LTO_ASM_FAILURE, 45 | 46 | // Added C-specific error codes 47 | LLVM_LTO_NULL_OBJECT 48 | } llvm_lto_status_t; 49 | 50 | /// This provides C interface to initialize link time optimizer. This allows 51 | /// linker to use dlopen() interface to dynamically load LinkTimeOptimizer. 52 | /// extern "C" helps, because dlopen() interface uses name to find the symbol. 53 | extern llvm_lto_t llvm_create_optimizer(void); 54 | extern void llvm_destroy_optimizer(llvm_lto_t lto); 55 | 56 | extern llvm_lto_status_t llvm_read_object_file 57 | (llvm_lto_t lto, const char* input_filename); 58 | extern llvm_lto_status_t llvm_optimize_modules 59 | (llvm_lto_t lto, const char* output_filename); 60 | 61 | /** 62 | * @} 63 | */ 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /include/llvm-c/Linker.h: -------------------------------------------------------------------------------- 1 | /*===-- llvm-c/Linker.h - Module Linker C Interface -------------*- C++ -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This file defines the C interface to the module/file/archive linker. *| 11 | |* *| 12 | \*===----------------------------------------------------------------------===*/ 13 | 14 | #ifndef LLVM_C_LINKER_H 15 | #define LLVM_C_LINKER_H 16 | 17 | #include "llvm-c/Core.h" 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | 24 | typedef enum { 25 | LLVMLinkerDestroySource = 0, /* Allow source module to be destroyed. */ 26 | LLVMLinkerPreserveSource = 1 /* Preserve the source module. */ 27 | } LLVMLinkerMode; 28 | 29 | 30 | /* Links the source module into the destination module, taking ownership 31 | * of the source module away from the caller. Optionally returns a 32 | * human-readable description of any errors that occurred in linking. 33 | * OutMessage must be disposed with LLVMDisposeMessage. The return value 34 | * is true if an error occurred, false otherwise. */ 35 | LLVMBool LLVMLinkModules(LLVMModuleRef Dest, LLVMModuleRef Src, 36 | LLVMLinkerMode Mode, char **OutMessage); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /include/llvm-c/Object.h: -------------------------------------------------------------------------------- 1 | /*===-- llvm-c/Object.h - Object Lib C Iface --------------------*- C++ -*-===*/ 2 | /* */ 3 | /* The LLVM Compiler Infrastructure */ 4 | /* */ 5 | /* This file is distributed under the University of Illinois Open Source */ 6 | /* License. See LICENSE.TXT for details. */ 7 | /* */ 8 | /*===----------------------------------------------------------------------===*/ 9 | /* */ 10 | /* This header declares the C interface to libLLVMObject.a, which */ 11 | /* implements object file reading and writing. */ 12 | /* */ 13 | /* Many exotic languages can interoperate with C code but have a harder time */ 14 | /* with C++ due to name mangling. So in addition to C, this interface enables */ 15 | /* tools written in such languages. */ 16 | /* */ 17 | /*===----------------------------------------------------------------------===*/ 18 | 19 | #ifndef LLVM_C_OBJECT_H 20 | #define LLVM_C_OBJECT_H 21 | 22 | #include "llvm-c/Core.h" 23 | #include "llvm/Config/llvm-config.h" 24 | 25 | #ifdef __cplusplus 26 | #include "llvm/Object/ObjectFile.h" 27 | 28 | extern "C" { 29 | #endif 30 | 31 | /** 32 | * @defgroup LLVMCObject Object file reading and writing 33 | * @ingroup LLVMC 34 | * 35 | * @{ 36 | */ 37 | 38 | // Opaque type wrappers 39 | typedef struct LLVMOpaqueObjectFile *LLVMObjectFileRef; 40 | typedef struct LLVMOpaqueSectionIterator *LLVMSectionIteratorRef; 41 | typedef struct LLVMOpaqueSymbolIterator *LLVMSymbolIteratorRef; 42 | typedef struct LLVMOpaqueRelocationIterator *LLVMRelocationIteratorRef; 43 | 44 | // ObjectFile creation 45 | LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf); 46 | void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile); 47 | 48 | // ObjectFile Section iterators 49 | LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile); 50 | void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI); 51 | LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile, 52 | LLVMSectionIteratorRef SI); 53 | void LLVMMoveToNextSection(LLVMSectionIteratorRef SI); 54 | void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect, 55 | LLVMSymbolIteratorRef Sym); 56 | 57 | // ObjectFile Symbol iterators 58 | LLVMSymbolIteratorRef LLVMGetSymbols(LLVMObjectFileRef ObjectFile); 59 | void LLVMDisposeSymbolIterator(LLVMSymbolIteratorRef SI); 60 | LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile, 61 | LLVMSymbolIteratorRef SI); 62 | void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI); 63 | 64 | // SectionRef accessors 65 | const char *LLVMGetSectionName(LLVMSectionIteratorRef SI); 66 | uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI); 67 | const char *LLVMGetSectionContents(LLVMSectionIteratorRef SI); 68 | uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI); 69 | LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI, 70 | LLVMSymbolIteratorRef Sym); 71 | 72 | // Section Relocation iterators 73 | LLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section); 74 | void LLVMDisposeRelocationIterator(LLVMRelocationIteratorRef RI); 75 | LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section, 76 | LLVMRelocationIteratorRef RI); 77 | void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef RI); 78 | 79 | 80 | // SymbolRef accessors 81 | const char *LLVMGetSymbolName(LLVMSymbolIteratorRef SI); 82 | uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI); 83 | uint64_t LLVMGetSymbolFileOffset(LLVMSymbolIteratorRef SI); 84 | uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI); 85 | 86 | // RelocationRef accessors 87 | uint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI); 88 | uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI); 89 | LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI); 90 | uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI); 91 | // NOTE: Caller takes ownership of returned string of the two 92 | // following functions. 93 | const char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI); 94 | const char *LLVMGetRelocationValueString(LLVMRelocationIteratorRef RI); 95 | 96 | /** 97 | * @} 98 | */ 99 | 100 | #ifdef __cplusplus 101 | } 102 | 103 | namespace llvm { 104 | namespace object { 105 | inline ObjectFile *unwrap(LLVMObjectFileRef OF) { 106 | return reinterpret_cast(OF); 107 | } 108 | 109 | inline LLVMObjectFileRef wrap(const ObjectFile *OF) { 110 | return reinterpret_cast(const_cast(OF)); 111 | } 112 | 113 | inline section_iterator *unwrap(LLVMSectionIteratorRef SI) { 114 | return reinterpret_cast(SI); 115 | } 116 | 117 | inline LLVMSectionIteratorRef 118 | wrap(const section_iterator *SI) { 119 | return reinterpret_cast 120 | (const_cast(SI)); 121 | } 122 | 123 | inline symbol_iterator *unwrap(LLVMSymbolIteratorRef SI) { 124 | return reinterpret_cast(SI); 125 | } 126 | 127 | inline LLVMSymbolIteratorRef 128 | wrap(const symbol_iterator *SI) { 129 | return reinterpret_cast 130 | (const_cast(SI)); 131 | } 132 | 133 | inline relocation_iterator *unwrap(LLVMRelocationIteratorRef SI) { 134 | return reinterpret_cast(SI); 135 | } 136 | 137 | inline LLVMRelocationIteratorRef 138 | wrap(const relocation_iterator *SI) { 139 | return reinterpret_cast 140 | (const_cast(SI)); 141 | } 142 | 143 | } 144 | } 145 | 146 | #endif /* defined(__cplusplus) */ 147 | 148 | #endif 149 | 150 | -------------------------------------------------------------------------------- /include/llvm-c/Target.h: -------------------------------------------------------------------------------- 1 | /*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- C++ -*-===*/ 2 | /* */ 3 | /* The LLVM Compiler Infrastructure */ 4 | /* */ 5 | /* This file is distributed under the University of Illinois Open Source */ 6 | /* License. See LICENSE.TXT for details. */ 7 | /* */ 8 | /*===----------------------------------------------------------------------===*/ 9 | /* */ 10 | /* This header declares the C interface to libLLVMTarget.a, which */ 11 | /* implements target information. */ 12 | /* */ 13 | /* Many exotic languages can interoperate with C code but have a harder time */ 14 | /* with C++ due to name mangling. So in addition to C, this interface enables */ 15 | /* tools written in such languages. */ 16 | /* */ 17 | /*===----------------------------------------------------------------------===*/ 18 | 19 | #ifndef LLVM_C_TARGET_H 20 | #define LLVM_C_TARGET_H 21 | 22 | #include "llvm-c/Core.h" 23 | #include "llvm/Config/llvm-config.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /** 30 | * @defgroup LLVMCTarget Target information 31 | * @ingroup LLVMC 32 | * 33 | * @{ 34 | */ 35 | 36 | enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian }; 37 | 38 | typedef struct LLVMOpaqueTargetData *LLVMTargetDataRef; 39 | typedef struct LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef; 40 | typedef struct LLVMStructLayout *LLVMStructLayoutRef; 41 | 42 | /* Declare all of the target-initialization functions that are available. */ 43 | #define LLVM_TARGET(TargetName) \ 44 | void LLVMInitialize##TargetName##TargetInfo(void); 45 | #include "llvm/Config/Targets.def" 46 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ 47 | 48 | #define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target(void); 49 | #include "llvm/Config/Targets.def" 50 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ 51 | 52 | #define LLVM_TARGET(TargetName) \ 53 | void LLVMInitialize##TargetName##TargetMC(void); 54 | #include "llvm/Config/Targets.def" 55 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ 56 | 57 | /* Declare all of the available assembly printer initialization functions. */ 58 | #define LLVM_ASM_PRINTER(TargetName) \ 59 | void LLVMInitialize##TargetName##AsmPrinter(void); 60 | #include "llvm/Config/AsmPrinters.def" 61 | #undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */ 62 | 63 | /* Declare all of the available assembly parser initialization functions. */ 64 | #define LLVM_ASM_PARSER(TargetName) \ 65 | void LLVMInitialize##TargetName##AsmParser(void); 66 | #include "llvm/Config/AsmParsers.def" 67 | #undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */ 68 | 69 | /* Declare all of the available disassembler initialization functions. */ 70 | #define LLVM_DISASSEMBLER(TargetName) \ 71 | void LLVMInitialize##TargetName##Disassembler(void); 72 | #include "llvm/Config/Disassemblers.def" 73 | #undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */ 74 | 75 | /** LLVMInitializeAllTargetInfos - The main program should call this function if 76 | it wants access to all available targets that LLVM is configured to 77 | support. */ 78 | static inline void LLVMInitializeAllTargetInfos(void) { 79 | #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo(); 80 | #include "llvm/Config/Targets.def" 81 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ 82 | } 83 | 84 | /** LLVMInitializeAllTargets - The main program should call this function if it 85 | wants to link in all available targets that LLVM is configured to 86 | support. */ 87 | static inline void LLVMInitializeAllTargets(void) { 88 | #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target(); 89 | #include "llvm/Config/Targets.def" 90 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ 91 | } 92 | 93 | /** LLVMInitializeAllTargetMCs - The main program should call this function if 94 | it wants access to all available target MC that LLVM is configured to 95 | support. */ 96 | static inline void LLVMInitializeAllTargetMCs(void) { 97 | #define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetMC(); 98 | #include "llvm/Config/Targets.def" 99 | #undef LLVM_TARGET /* Explicit undef to make SWIG happier */ 100 | } 101 | 102 | /** LLVMInitializeAllAsmPrinters - The main program should call this function if 103 | it wants all asm printers that LLVM is configured to support, to make them 104 | available via the TargetRegistry. */ 105 | static inline void LLVMInitializeAllAsmPrinters(void) { 106 | #define LLVM_ASM_PRINTER(TargetName) LLVMInitialize##TargetName##AsmPrinter(); 107 | #include "llvm/Config/AsmPrinters.def" 108 | #undef LLVM_ASM_PRINTER /* Explicit undef to make SWIG happier */ 109 | } 110 | 111 | /** LLVMInitializeAllAsmParsers - The main program should call this function if 112 | it wants all asm parsers that LLVM is configured to support, to make them 113 | available via the TargetRegistry. */ 114 | static inline void LLVMInitializeAllAsmParsers(void) { 115 | #define LLVM_ASM_PARSER(TargetName) LLVMInitialize##TargetName##AsmParser(); 116 | #include "llvm/Config/AsmParsers.def" 117 | #undef LLVM_ASM_PARSER /* Explicit undef to make SWIG happier */ 118 | } 119 | 120 | /** LLVMInitializeAllDisassemblers - The main program should call this function 121 | if it wants all disassemblers that LLVM is configured to support, to make 122 | them available via the TargetRegistry. */ 123 | static inline void LLVMInitializeAllDisassemblers(void) { 124 | #define LLVM_DISASSEMBLER(TargetName) \ 125 | LLVMInitialize##TargetName##Disassembler(); 126 | #include "llvm/Config/Disassemblers.def" 127 | #undef LLVM_DISASSEMBLER /* Explicit undef to make SWIG happier */ 128 | } 129 | 130 | /** LLVMInitializeNativeTarget - The main program should call this function to 131 | initialize the native target corresponding to the host. This is useful 132 | for JIT applications to ensure that the target gets linked in correctly. */ 133 | static inline LLVMBool LLVMInitializeNativeTarget(void) { 134 | /* If we have a native target, initialize it to ensure it is linked in. */ 135 | #ifdef LLVM_NATIVE_TARGET 136 | LLVM_NATIVE_TARGETINFO(); 137 | LLVM_NATIVE_TARGET(); 138 | LLVM_NATIVE_TARGETMC(); 139 | return 0; 140 | #else 141 | return 1; 142 | #endif 143 | } 144 | 145 | /*===-- Target Data -------------------------------------------------------===*/ 146 | 147 | /** Creates target data from a target layout string. 148 | See the constructor llvm::TargetData::TargetData. */ 149 | LLVMTargetDataRef LLVMCreateTargetData(const char *StringRep); 150 | 151 | /** Adds target data information to a pass manager. This does not take ownership 152 | of the target data. 153 | See the method llvm::PassManagerBase::add. */ 154 | void LLVMAddTargetData(LLVMTargetDataRef, LLVMPassManagerRef); 155 | 156 | /** Adds target library information to a pass manager. This does not take 157 | ownership of the target library info. 158 | See the method llvm::PassManagerBase::add. */ 159 | void LLVMAddTargetLibraryInfo(LLVMTargetLibraryInfoRef, LLVMPassManagerRef); 160 | 161 | /** Converts target data to a target layout string. The string must be disposed 162 | with LLVMDisposeMessage. 163 | See the constructor llvm::TargetData::TargetData. */ 164 | char *LLVMCopyStringRepOfTargetData(LLVMTargetDataRef); 165 | 166 | /** Returns the byte order of a target, either LLVMBigEndian or 167 | LLVMLittleEndian. 168 | See the method llvm::TargetData::isLittleEndian. */ 169 | enum LLVMByteOrdering LLVMByteOrder(LLVMTargetDataRef); 170 | 171 | /** Returns the pointer size in bytes for a target. 172 | See the method llvm::TargetData::getPointerSize. */ 173 | unsigned LLVMPointerSize(LLVMTargetDataRef); 174 | 175 | /** Returns the integer type that is the same size as a pointer on a target. 176 | See the method llvm::TargetData::getIntPtrType. */ 177 | LLVMTypeRef LLVMIntPtrType(LLVMTargetDataRef); 178 | 179 | /** Computes the size of a type in bytes for a target. 180 | See the method llvm::TargetData::getTypeSizeInBits. */ 181 | unsigned long long LLVMSizeOfTypeInBits(LLVMTargetDataRef, LLVMTypeRef); 182 | 183 | /** Computes the storage size of a type in bytes for a target. 184 | See the method llvm::TargetData::getTypeStoreSize. */ 185 | unsigned long long LLVMStoreSizeOfType(LLVMTargetDataRef, LLVMTypeRef); 186 | 187 | /** Computes the ABI size of a type in bytes for a target. 188 | See the method llvm::TargetData::getTypeAllocSize. */ 189 | unsigned long long LLVMABISizeOfType(LLVMTargetDataRef, LLVMTypeRef); 190 | 191 | /** Computes the ABI alignment of a type in bytes for a target. 192 | See the method llvm::TargetData::getTypeABISize. */ 193 | unsigned LLVMABIAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef); 194 | 195 | /** Computes the call frame alignment of a type in bytes for a target. 196 | See the method llvm::TargetData::getTypeABISize. */ 197 | unsigned LLVMCallFrameAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef); 198 | 199 | /** Computes the preferred alignment of a type in bytes for a target. 200 | See the method llvm::TargetData::getTypeABISize. */ 201 | unsigned LLVMPreferredAlignmentOfType(LLVMTargetDataRef, LLVMTypeRef); 202 | 203 | /** Computes the preferred alignment of a global variable in bytes for a target. 204 | See the method llvm::TargetData::getPreferredAlignment. */ 205 | unsigned LLVMPreferredAlignmentOfGlobal(LLVMTargetDataRef, 206 | LLVMValueRef GlobalVar); 207 | 208 | /** Computes the structure element that contains the byte offset for a target. 209 | See the method llvm::StructLayout::getElementContainingOffset. */ 210 | unsigned LLVMElementAtOffset(LLVMTargetDataRef, LLVMTypeRef StructTy, 211 | unsigned long long Offset); 212 | 213 | /** Computes the byte offset of the indexed struct element for a target. 214 | See the method llvm::StructLayout::getElementContainingOffset. */ 215 | unsigned long long LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy, 216 | unsigned Element); 217 | 218 | /** Deallocates a TargetData. 219 | See the destructor llvm::TargetData::~TargetData. */ 220 | void LLVMDisposeTargetData(LLVMTargetDataRef); 221 | 222 | /** 223 | * @} 224 | */ 225 | 226 | #ifdef __cplusplus 227 | } 228 | 229 | namespace llvm { 230 | class TargetData; 231 | class TargetLibraryInfo; 232 | 233 | inline TargetData *unwrap(LLVMTargetDataRef P) { 234 | return reinterpret_cast(P); 235 | } 236 | 237 | inline LLVMTargetDataRef wrap(const TargetData *P) { 238 | return reinterpret_cast(const_cast(P)); 239 | } 240 | 241 | inline TargetLibraryInfo *unwrap(LLVMTargetLibraryInfoRef P) { 242 | return reinterpret_cast(P); 243 | } 244 | 245 | inline LLVMTargetLibraryInfoRef wrap(const TargetLibraryInfo *P) { 246 | TargetLibraryInfo *X = const_cast(P); 247 | return reinterpret_cast(X); 248 | } 249 | } 250 | 251 | #endif /* defined(__cplusplus) */ 252 | 253 | #endif 254 | -------------------------------------------------------------------------------- /include/llvm-c/TargetMachine.h: -------------------------------------------------------------------------------- 1 | /*===-- llvm-c/TargetMachine.h - Target Machine Library C Interface - C++ -*-=*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This header declares the C interface to the Target and TargetMachine *| 11 | |* classes, which can be used to generate assembly or object files. *| 12 | |* *| 13 | |* Many exotic languages can interoperate with C code but have a harder time *| 14 | |* with C++ due to name mangling. So in addition to C, this interface enables *| 15 | |* tools written in such languages. *| 16 | |* *| 17 | \*===----------------------------------------------------------------------===*/ 18 | 19 | #ifndef LLVM_C_TARGETMACHINE_H 20 | #define LLVM_C_TARGETMACHINE_H 21 | 22 | #include "llvm-c/Core.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | typedef struct LLVMTargetMachine *LLVMTargetMachineRef; 28 | typedef struct LLVMTarget *LLVMTargetRef; 29 | 30 | typedef enum { 31 | LLVMCodeGenLevelNone, 32 | LLVMCodeGenLevelLess, 33 | LLVMCodeGenLevelDefault, 34 | LLVMCodeGenLevelAggressive 35 | } LLVMCodeGenOptLevel; 36 | 37 | typedef enum { 38 | LLVMRelocDefault, 39 | LLVMRelocStatic, 40 | LLVMRelocPIC, 41 | LLVMRelocDynamicNoPic 42 | } LLVMRelocMode; 43 | 44 | typedef enum { 45 | LLVMCodeModelDefault, 46 | LLVMCodeModelJITDefault, 47 | LLVMCodeModelSmall, 48 | LLVMCodeModelKernel, 49 | LLVMCodeModelMedium, 50 | LLVMCodeModelLarge 51 | } LLVMCodeModel; 52 | 53 | typedef enum { 54 | LLVMAssemblyFile, 55 | LLVMObjectFile 56 | } LLVMCodeGenFileType; 57 | 58 | /** Returns the first llvm::Target in the registered targets list. */ 59 | LLVMTargetRef LLVMGetFirstTarget(); 60 | /** Returns the next llvm::Target given a previous one (or null if there's none) */ 61 | LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T); 62 | 63 | /*===-- Target ------------------------------------------------------------===*/ 64 | /** Returns the name of a target. See llvm::Target::getName */ 65 | const char *LLVMGetTargetName(LLVMTargetRef T); 66 | 67 | /** Returns the description of a target. See llvm::Target::getDescription */ 68 | const char *LLVMGetTargetDescription(LLVMTargetRef T); 69 | 70 | /** Returns if the target has a JIT */ 71 | LLVMBool LLVMTargetHasJIT(LLVMTargetRef T); 72 | 73 | /** Returns if the target has a TargetMachine associated */ 74 | LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T); 75 | 76 | /** Returns if the target as an ASM backend (required for emitting output) */ 77 | LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T); 78 | 79 | /*===-- Target Machine ----------------------------------------------------===*/ 80 | /** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */ 81 | LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, char *Triple, 82 | char *CPU, char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, 83 | LLVMCodeModel CodeModel); 84 | 85 | /** Dispose the LLVMTargetMachineRef instance generated by 86 | LLVMCreateTargetMachine. */ 87 | void LLVMDisposeTargetMachine(LLVMTargetMachineRef T); 88 | 89 | /** Returns the Target used in a TargetMachine */ 90 | LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T); 91 | 92 | /** Returns the triple used creating this target machine. See 93 | llvm::TargetMachine::getTriple. The result needs to be disposed with 94 | LLVMDisposeMessage. */ 95 | char *LLVMGetTargetMachineTriple(LLVMTargetMachineRef T); 96 | 97 | /** Returns the cpu used creating this target machine. See 98 | llvm::TargetMachine::getCPU. The result needs to be disposed with 99 | LLVMDisposeMessage. */ 100 | char *LLVMGetTargetMachineCPU(LLVMTargetMachineRef T); 101 | 102 | /** Returns the feature string used creating this target machine. See 103 | llvm::TargetMachine::getFeatureString. The result needs to be disposed with 104 | LLVMDisposeMessage. */ 105 | char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T); 106 | 107 | /** Returns the llvm::TargetData used for this llvm:TargetMachine. */ 108 | LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T); 109 | 110 | /** Emits an asm or object file for the given module to the filename. This 111 | wraps several c++ only classes (among them a file stream). Returns any 112 | error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */ 113 | LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M, 114 | char *Filename, LLVMCodeGenFileType codegen, char **ErrorMessage); 115 | 116 | 117 | 118 | 119 | #ifdef __cplusplus 120 | } 121 | 122 | namespace llvm { 123 | class TargetMachine; 124 | class Target; 125 | 126 | inline TargetMachine *unwrap(LLVMTargetMachineRef P) { 127 | return reinterpret_cast(P); 128 | } 129 | inline Target *unwrap(LLVMTargetRef P) { 130 | return reinterpret_cast(P); 131 | } 132 | inline LLVMTargetMachineRef wrap(const TargetMachine *P) { 133 | return reinterpret_cast( 134 | const_cast(P)); 135 | } 136 | inline LLVMTargetRef wrap(const Target * P) { 137 | return reinterpret_cast(const_cast(P)); 138 | } 139 | } 140 | #endif 141 | 142 | #endif 143 | -------------------------------------------------------------------------------- /include/llvm-c/Transforms/IPO.h: -------------------------------------------------------------------------------- 1 | /*===-- IPO.h - Interprocedural Transformations C Interface -----*- C++ -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This header declares the C interface to libLLVMIPO.a, which implements *| 11 | |* various interprocedural transformations of the LLVM IR. *| 12 | |* *| 13 | \*===----------------------------------------------------------------------===*/ 14 | 15 | #ifndef LLVM_C_TRANSFORMS_IPO_H 16 | #define LLVM_C_TRANSFORMS_IPO_H 17 | 18 | #include "llvm-c/Core.h" 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /** 25 | * @defgroup LLVMCTransformsIPO Interprocedural transformations 26 | * @ingroup LLVMCTransforms 27 | * 28 | * @{ 29 | */ 30 | 31 | /** See llvm::createArgumentPromotionPass function. */ 32 | void LLVMAddArgumentPromotionPass(LLVMPassManagerRef PM); 33 | 34 | /** See llvm::createConstantMergePass function. */ 35 | void LLVMAddConstantMergePass(LLVMPassManagerRef PM); 36 | 37 | /** See llvm::createDeadArgEliminationPass function. */ 38 | void LLVMAddDeadArgEliminationPass(LLVMPassManagerRef PM); 39 | 40 | /** See llvm::createFunctionAttrsPass function. */ 41 | void LLVMAddFunctionAttrsPass(LLVMPassManagerRef PM); 42 | 43 | /** See llvm::createFunctionInliningPass function. */ 44 | void LLVMAddFunctionInliningPass(LLVMPassManagerRef PM); 45 | 46 | /** See llvm::createAlwaysInlinerPass function. */ 47 | void LLVMAddAlwaysInlinerPass(LLVMPassManagerRef PM); 48 | 49 | /** See llvm::createGlobalDCEPass function. */ 50 | void LLVMAddGlobalDCEPass(LLVMPassManagerRef PM); 51 | 52 | /** See llvm::createGlobalOptimizerPass function. */ 53 | void LLVMAddGlobalOptimizerPass(LLVMPassManagerRef PM); 54 | 55 | /** See llvm::createIPConstantPropagationPass function. */ 56 | void LLVMAddIPConstantPropagationPass(LLVMPassManagerRef PM); 57 | 58 | /** See llvm::createPruneEHPass function. */ 59 | void LLVMAddPruneEHPass(LLVMPassManagerRef PM); 60 | 61 | /** See llvm::createIPSCCPPass function. */ 62 | void LLVMAddIPSCCPPass(LLVMPassManagerRef PM); 63 | 64 | /** See llvm::createInternalizePass function. */ 65 | void LLVMAddInternalizePass(LLVMPassManagerRef, unsigned AllButMain); 66 | 67 | /** See llvm::createStripDeadPrototypesPass function. */ 68 | void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM); 69 | 70 | /** See llvm::createStripSymbolsPass function. */ 71 | void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM); 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif /* defined(__cplusplus) */ 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /include/llvm-c/Transforms/PassManagerBuilder.h: -------------------------------------------------------------------------------- 1 | /*===-- llvm-c/Transform/PassManagerBuilder.h - PMB C Interface ---*- C -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This header declares the C interface to the PassManagerBuilder class. *| 11 | |* *| 12 | \*===----------------------------------------------------------------------===*/ 13 | 14 | #ifndef LLVM_C_PASSMANAGERBUILDER 15 | #define LLVM_C_PASSMANAGERBUILDER 16 | 17 | #include "llvm-c/Core.h" 18 | 19 | typedef struct LLVMOpaquePassManagerBuilder *LLVMPassManagerBuilderRef; 20 | 21 | #ifdef __cplusplus 22 | #include "llvm/Transforms/IPO/PassManagerBuilder.h" 23 | extern "C" { 24 | #endif 25 | 26 | /** 27 | * @defgroup LLVMCTransformsPassManagerBuilder Pass manager builder 28 | * @ingroup LLVMCTransforms 29 | * 30 | * @{ 31 | */ 32 | 33 | /** See llvm::PassManagerBuilder. */ 34 | LLVMPassManagerBuilderRef LLVMPassManagerBuilderCreate(void); 35 | void LLVMPassManagerBuilderDispose(LLVMPassManagerBuilderRef PMB); 36 | 37 | /** See llvm::PassManagerBuilder::OptLevel. */ 38 | void 39 | LLVMPassManagerBuilderSetOptLevel(LLVMPassManagerBuilderRef PMB, 40 | unsigned OptLevel); 41 | 42 | /** See llvm::PassManagerBuilder::SizeLevel. */ 43 | void 44 | LLVMPassManagerBuilderSetSizeLevel(LLVMPassManagerBuilderRef PMB, 45 | unsigned SizeLevel); 46 | 47 | /** See llvm::PassManagerBuilder::DisableUnitAtATime. */ 48 | void 49 | LLVMPassManagerBuilderSetDisableUnitAtATime(LLVMPassManagerBuilderRef PMB, 50 | LLVMBool Value); 51 | 52 | /** See llvm::PassManagerBuilder::DisableUnrollLoops. */ 53 | void 54 | LLVMPassManagerBuilderSetDisableUnrollLoops(LLVMPassManagerBuilderRef PMB, 55 | LLVMBool Value); 56 | 57 | /** See llvm::PassManagerBuilder::DisableSimplifyLibCalls */ 58 | void 59 | LLVMPassManagerBuilderSetDisableSimplifyLibCalls(LLVMPassManagerBuilderRef PMB, 60 | LLVMBool Value); 61 | 62 | /** See llvm::PassManagerBuilder::Inliner. */ 63 | void 64 | LLVMPassManagerBuilderUseInlinerWithThreshold(LLVMPassManagerBuilderRef PMB, 65 | unsigned Threshold); 66 | 67 | /** See llvm::PassManagerBuilder::populateFunctionPassManager. */ 68 | void 69 | LLVMPassManagerBuilderPopulateFunctionPassManager(LLVMPassManagerBuilderRef PMB, 70 | LLVMPassManagerRef PM); 71 | 72 | /** See llvm::PassManagerBuilder::populateModulePassManager. */ 73 | void 74 | LLVMPassManagerBuilderPopulateModulePassManager(LLVMPassManagerBuilderRef PMB, 75 | LLVMPassManagerRef PM); 76 | 77 | /** See llvm::PassManagerBuilder::populateLTOPassManager. */ 78 | void LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB, 79 | LLVMPassManagerRef PM, 80 | bool Internalize, 81 | bool RunInliner); 82 | 83 | /** 84 | * @} 85 | */ 86 | 87 | #ifdef __cplusplus 88 | } 89 | 90 | namespace llvm { 91 | inline PassManagerBuilder *unwrap(LLVMPassManagerBuilderRef P) { 92 | return reinterpret_cast(P); 93 | } 94 | 95 | inline LLVMPassManagerBuilderRef wrap(PassManagerBuilder *P) { 96 | return reinterpret_cast(P); 97 | } 98 | } 99 | #endif 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /include/llvm-c/Transforms/Scalar.h: -------------------------------------------------------------------------------- 1 | /*===-- Scalar.h - Scalar Transformation Library C Interface ----*- C++ -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This header declares the C interface to libLLVMScalarOpts.a, which *| 11 | |* implements various scalar transformations of the LLVM IR. *| 12 | |* *| 13 | |* Many exotic languages can interoperate with C code but have a harder time *| 14 | |* with C++ due to name mangling. So in addition to C, this interface enables *| 15 | |* tools written in such languages. *| 16 | |* *| 17 | \*===----------------------------------------------------------------------===*/ 18 | 19 | #ifndef LLVM_C_TRANSFORMS_SCALAR_H 20 | #define LLVM_C_TRANSFORMS_SCALAR_H 21 | 22 | #include "llvm-c/Core.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | /** 29 | * @defgroup LLVMCTransformsScalar Scalar transformations 30 | * @ingroup LLVMCTransforms 31 | * 32 | * @{ 33 | */ 34 | 35 | /** See llvm::createAggressiveDCEPass function. */ 36 | void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM); 37 | 38 | /** See llvm::createCFGSimplificationPass function. */ 39 | void LLVMAddCFGSimplificationPass(LLVMPassManagerRef PM); 40 | 41 | /** See llvm::createDeadStoreEliminationPass function. */ 42 | void LLVMAddDeadStoreEliminationPass(LLVMPassManagerRef PM); 43 | 44 | /** See llvm::createGVNPass function. */ 45 | void LLVMAddGVNPass(LLVMPassManagerRef PM); 46 | 47 | /** See llvm::createIndVarSimplifyPass function. */ 48 | void LLVMAddIndVarSimplifyPass(LLVMPassManagerRef PM); 49 | 50 | /** See llvm::createInstructionCombiningPass function. */ 51 | void LLVMAddInstructionCombiningPass(LLVMPassManagerRef PM); 52 | 53 | /** See llvm::createJumpThreadingPass function. */ 54 | void LLVMAddJumpThreadingPass(LLVMPassManagerRef PM); 55 | 56 | /** See llvm::createLICMPass function. */ 57 | void LLVMAddLICMPass(LLVMPassManagerRef PM); 58 | 59 | /** See llvm::createLoopDeletionPass function. */ 60 | void LLVMAddLoopDeletionPass(LLVMPassManagerRef PM); 61 | 62 | /** See llvm::createLoopIdiomPass function */ 63 | void LLVMAddLoopIdiomPass(LLVMPassManagerRef PM); 64 | 65 | /** See llvm::createLoopRotatePass function. */ 66 | void LLVMAddLoopRotatePass(LLVMPassManagerRef PM); 67 | 68 | /** See llvm::createLoopUnrollPass function. */ 69 | void LLVMAddLoopUnrollPass(LLVMPassManagerRef PM); 70 | 71 | /** See llvm::createLoopUnswitchPass function. */ 72 | void LLVMAddLoopUnswitchPass(LLVMPassManagerRef PM); 73 | 74 | /** See llvm::createMemCpyOptPass function. */ 75 | void LLVMAddMemCpyOptPass(LLVMPassManagerRef PM); 76 | 77 | /** See llvm::createPromoteMemoryToRegisterPass function. */ 78 | void LLVMAddPromoteMemoryToRegisterPass(LLVMPassManagerRef PM); 79 | 80 | /** See llvm::createReassociatePass function. */ 81 | void LLVMAddReassociatePass(LLVMPassManagerRef PM); 82 | 83 | /** See llvm::createSCCPPass function. */ 84 | void LLVMAddSCCPPass(LLVMPassManagerRef PM); 85 | 86 | /** See llvm::createScalarReplAggregatesPass function. */ 87 | void LLVMAddScalarReplAggregatesPass(LLVMPassManagerRef PM); 88 | 89 | /** See llvm::createScalarReplAggregatesPass function. */ 90 | void LLVMAddScalarReplAggregatesPassSSA(LLVMPassManagerRef PM); 91 | 92 | /** See llvm::createScalarReplAggregatesPass function. */ 93 | void LLVMAddScalarReplAggregatesPassWithThreshold(LLVMPassManagerRef PM, 94 | int Threshold); 95 | 96 | /** See llvm::createSimplifyLibCallsPass function. */ 97 | void LLVMAddSimplifyLibCallsPass(LLVMPassManagerRef PM); 98 | 99 | /** See llvm::createTailCallEliminationPass function. */ 100 | void LLVMAddTailCallEliminationPass(LLVMPassManagerRef PM); 101 | 102 | /** See llvm::createConstantPropagationPass function. */ 103 | void LLVMAddConstantPropagationPass(LLVMPassManagerRef PM); 104 | 105 | /** See llvm::demotePromoteMemoryToRegisterPass function. */ 106 | void LLVMAddDemoteMemoryToRegisterPass(LLVMPassManagerRef PM); 107 | 108 | /** See llvm::createVerifierPass function. */ 109 | void LLVMAddVerifierPass(LLVMPassManagerRef PM); 110 | 111 | /** See llvm::createCorrelatedValuePropagationPass function */ 112 | void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM); 113 | 114 | /** See llvm::createEarlyCSEPass function */ 115 | void LLVMAddEarlyCSEPass(LLVMPassManagerRef PM); 116 | 117 | /** See llvm::createLowerExpectIntrinsicPass function */ 118 | void LLVMAddLowerExpectIntrinsicPass(LLVMPassManagerRef PM); 119 | 120 | /** See llvm::createTypeBasedAliasAnalysisPass function */ 121 | void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM); 122 | 123 | /** See llvm::createBasicAliasAnalysisPass function */ 124 | void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM); 125 | 126 | /** 127 | * @} 128 | */ 129 | 130 | #ifdef __cplusplus 131 | } 132 | #endif /* defined(__cplusplus) */ 133 | 134 | #endif 135 | -------------------------------------------------------------------------------- /include/llvm-c/Transforms/Vectorize.h: -------------------------------------------------------------------------------- 1 | /*===---------------------------Vectorize.h --------------------- -*- C -*-===*\ 2 | |*===----------- Vectorization Transformation Library C Interface ---------===*| 3 | |* *| 4 | |* The LLVM Compiler Infrastructure *| 5 | |* *| 6 | |* This file is distributed under the University of Illinois Open Source *| 7 | |* License. See LICENSE.TXT for details. *| 8 | |* *| 9 | |*===----------------------------------------------------------------------===*| 10 | |* *| 11 | |* This header declares the C interface to libLLVMVectorize.a, which *| 12 | |* implements various vectorization transformations of the LLVM IR. *| 13 | |* *| 14 | |* Many exotic languages can interoperate with C code but have a harder time *| 15 | |* with C++ due to name mangling. So in addition to C, this interface enables *| 16 | |* tools written in such languages. *| 17 | |* *| 18 | \*===----------------------------------------------------------------------===*/ 19 | 20 | #ifndef LLVM_C_TRANSFORMS_VECTORIZE_H 21 | #define LLVM_C_TRANSFORMS_VECTORIZE_H 22 | 23 | #include "llvm-c/Core.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /** 30 | * @defgroup LLVMCTransformsVectorize Vectorization transformations 31 | * @ingroup LLVMCTransforms 32 | * 33 | * @{ 34 | */ 35 | 36 | /** See llvm::createBBVectorizePass function. */ 37 | void LLVMAddBBVectorizePass(LLVMPassManagerRef PM); 38 | 39 | /** 40 | * @} 41 | */ 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif /* defined(__cplusplus) */ 46 | 47 | #endif 48 | 49 | -------------------------------------------------------------------------------- /include/llvm-c/lto.h: -------------------------------------------------------------------------------- 1 | /*===-- llvm-c/lto.h - LTO Public C Interface ---------------------*- C -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This header provides public interface to an abstract link time optimization*| 11 | |* library. LLVM provides an implementation of this interface for use with *| 12 | |* llvm bitcode files. *| 13 | |* *| 14 | \*===----------------------------------------------------------------------===*/ 15 | 16 | #ifndef LTO_H 17 | #define LTO_H 1 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | /** 24 | * @defgroup LLVMCLTO LTO 25 | * @ingroup LLVMC 26 | * 27 | * @{ 28 | */ 29 | 30 | #define LTO_API_VERSION 4 31 | 32 | typedef enum { 33 | LTO_SYMBOL_ALIGNMENT_MASK = 0x0000001F, /* log2 of alignment */ 34 | LTO_SYMBOL_PERMISSIONS_MASK = 0x000000E0, 35 | LTO_SYMBOL_PERMISSIONS_CODE = 0x000000A0, 36 | LTO_SYMBOL_PERMISSIONS_DATA = 0x000000C0, 37 | LTO_SYMBOL_PERMISSIONS_RODATA = 0x00000080, 38 | LTO_SYMBOL_DEFINITION_MASK = 0x00000700, 39 | LTO_SYMBOL_DEFINITION_REGULAR = 0x00000100, 40 | LTO_SYMBOL_DEFINITION_TENTATIVE = 0x00000200, 41 | LTO_SYMBOL_DEFINITION_WEAK = 0x00000300, 42 | LTO_SYMBOL_DEFINITION_UNDEFINED = 0x00000400, 43 | LTO_SYMBOL_DEFINITION_WEAKUNDEF = 0x00000500, 44 | LTO_SYMBOL_SCOPE_MASK = 0x00003800, 45 | LTO_SYMBOL_SCOPE_INTERNAL = 0x00000800, 46 | LTO_SYMBOL_SCOPE_HIDDEN = 0x00001000, 47 | LTO_SYMBOL_SCOPE_PROTECTED = 0x00002000, 48 | LTO_SYMBOL_SCOPE_DEFAULT = 0x00001800, 49 | LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN = 0x00002800 50 | } lto_symbol_attributes; 51 | 52 | typedef enum { 53 | LTO_DEBUG_MODEL_NONE = 0, 54 | LTO_DEBUG_MODEL_DWARF = 1 55 | } lto_debug_model; 56 | 57 | typedef enum { 58 | LTO_CODEGEN_PIC_MODEL_STATIC = 0, 59 | LTO_CODEGEN_PIC_MODEL_DYNAMIC = 1, 60 | LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2 61 | } lto_codegen_model; 62 | 63 | 64 | /** opaque reference to a loaded object module */ 65 | typedef struct LTOModule* lto_module_t; 66 | 67 | /** opaque reference to a code generator */ 68 | typedef struct LTOCodeGenerator* lto_code_gen_t; 69 | 70 | #ifdef __cplusplus 71 | extern "C" { 72 | #endif 73 | 74 | /** 75 | * Returns a printable string. 76 | */ 77 | extern const char* 78 | lto_get_version(void); 79 | 80 | 81 | /** 82 | * Returns the last error string or NULL if last operation was successful. 83 | */ 84 | extern const char* 85 | lto_get_error_message(void); 86 | 87 | /** 88 | * Checks if a file is a loadable object file. 89 | */ 90 | extern bool 91 | lto_module_is_object_file(const char* path); 92 | 93 | 94 | /** 95 | * Checks if a file is a loadable object compiled for requested target. 96 | */ 97 | extern bool 98 | lto_module_is_object_file_for_target(const char* path, 99 | const char* target_triple_prefix); 100 | 101 | 102 | /** 103 | * Checks if a buffer is a loadable object file. 104 | */ 105 | extern bool 106 | lto_module_is_object_file_in_memory(const void* mem, size_t length); 107 | 108 | 109 | /** 110 | * Checks if a buffer is a loadable object compiled for requested target. 111 | */ 112 | extern bool 113 | lto_module_is_object_file_in_memory_for_target(const void* mem, size_t length, 114 | const char* target_triple_prefix); 115 | 116 | 117 | /** 118 | * Loads an object file from disk. 119 | * Returns NULL on error (check lto_get_error_message() for details). 120 | */ 121 | extern lto_module_t 122 | lto_module_create(const char* path); 123 | 124 | 125 | /** 126 | * Loads an object file from memory. 127 | * Returns NULL on error (check lto_get_error_message() for details). 128 | */ 129 | extern lto_module_t 130 | lto_module_create_from_memory(const void* mem, size_t length); 131 | 132 | /** 133 | * Loads an object file from disk. The seek point of fd is not preserved. 134 | * Returns NULL on error (check lto_get_error_message() for details). 135 | */ 136 | extern lto_module_t 137 | lto_module_create_from_fd(int fd, const char *path, size_t file_size); 138 | 139 | /** 140 | * Loads an object file from disk. The seek point of fd is not preserved. 141 | * Returns NULL on error (check lto_get_error_message() for details). 142 | */ 143 | extern lto_module_t 144 | lto_module_create_from_fd_at_offset(int fd, const char *path, size_t file_size, 145 | size_t map_size, off_t offset); 146 | 147 | 148 | /** 149 | * Frees all memory internally allocated by the module. 150 | * Upon return the lto_module_t is no longer valid. 151 | */ 152 | extern void 153 | lto_module_dispose(lto_module_t mod); 154 | 155 | 156 | /** 157 | * Returns triple string which the object module was compiled under. 158 | */ 159 | extern const char* 160 | lto_module_get_target_triple(lto_module_t mod); 161 | 162 | /** 163 | * Sets triple string with which the object will be codegened. 164 | */ 165 | extern void 166 | lto_module_set_target_triple(lto_module_t mod, const char *triple); 167 | 168 | 169 | /** 170 | * Returns the number of symbols in the object module. 171 | */ 172 | extern unsigned int 173 | lto_module_get_num_symbols(lto_module_t mod); 174 | 175 | 176 | /** 177 | * Returns the name of the ith symbol in the object module. 178 | */ 179 | extern const char* 180 | lto_module_get_symbol_name(lto_module_t mod, unsigned int index); 181 | 182 | 183 | /** 184 | * Returns the attributes of the ith symbol in the object module. 185 | */ 186 | extern lto_symbol_attributes 187 | lto_module_get_symbol_attribute(lto_module_t mod, unsigned int index); 188 | 189 | 190 | /** 191 | * Instantiates a code generator. 192 | * Returns NULL on error (check lto_get_error_message() for details). 193 | */ 194 | extern lto_code_gen_t 195 | lto_codegen_create(void); 196 | 197 | 198 | /** 199 | * Frees all code generator and all memory it internally allocated. 200 | * Upon return the lto_code_gen_t is no longer valid. 201 | */ 202 | extern void 203 | lto_codegen_dispose(lto_code_gen_t); 204 | 205 | 206 | 207 | /** 208 | * Add an object module to the set of modules for which code will be generated. 209 | * Returns true on error (check lto_get_error_message() for details). 210 | */ 211 | extern bool 212 | lto_codegen_add_module(lto_code_gen_t cg, lto_module_t mod); 213 | 214 | 215 | 216 | /** 217 | * Sets if debug info should be generated. 218 | * Returns true on error (check lto_get_error_message() for details). 219 | */ 220 | extern bool 221 | lto_codegen_set_debug_model(lto_code_gen_t cg, lto_debug_model); 222 | 223 | 224 | /** 225 | * Sets which PIC code model to generated. 226 | * Returns true on error (check lto_get_error_message() for details). 227 | */ 228 | extern bool 229 | lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model); 230 | 231 | 232 | /** 233 | * Sets the cpu to generate code for. 234 | */ 235 | extern void 236 | lto_codegen_set_cpu(lto_code_gen_t cg, const char *cpu); 237 | 238 | 239 | /** 240 | * Sets the location of the assembler tool to run. If not set, libLTO 241 | * will use gcc to invoke the assembler. 242 | */ 243 | extern void 244 | lto_codegen_set_assembler_path(lto_code_gen_t cg, const char* path); 245 | 246 | /** 247 | * Sets extra arguments that libLTO should pass to the assembler. 248 | */ 249 | extern void 250 | lto_codegen_set_assembler_args(lto_code_gen_t cg, const char **args, 251 | int nargs); 252 | 253 | /** 254 | * Adds to a list of all global symbols that must exist in the final 255 | * generated code. If a function is not listed, it might be 256 | * inlined into every usage and optimized away. 257 | */ 258 | extern void 259 | lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const char* symbol); 260 | 261 | /** 262 | * Writes a new object file at the specified path that contains the 263 | * merged contents of all modules added so far. 264 | * Returns true on error (check lto_get_error_message() for details). 265 | */ 266 | extern bool 267 | lto_codegen_write_merged_modules(lto_code_gen_t cg, const char* path); 268 | 269 | /** 270 | * Generates code for all added modules into one native object file. 271 | * On success returns a pointer to a generated mach-o/ELF buffer and 272 | * length set to the buffer size. The buffer is owned by the 273 | * lto_code_gen_t and will be freed when lto_codegen_dispose() 274 | * is called, or lto_codegen_compile() is called again. 275 | * On failure, returns NULL (check lto_get_error_message() for details). 276 | */ 277 | extern const void* 278 | lto_codegen_compile(lto_code_gen_t cg, size_t* length); 279 | 280 | /** 281 | * Generates code for all added modules into one native object file. 282 | * The name of the file is written to name. Returns true on error. 283 | */ 284 | extern bool 285 | lto_codegen_compile_to_file(lto_code_gen_t cg, const char** name); 286 | 287 | 288 | /** 289 | * Sets options to help debug codegen bugs. 290 | */ 291 | extern void 292 | lto_codegen_debug_options(lto_code_gen_t cg, const char *); 293 | 294 | #ifdef __cplusplus 295 | } 296 | #endif 297 | 298 | /** 299 | * @} 300 | */ 301 | 302 | #endif 303 | -------------------------------------------------------------------------------- /include/llvm/Config/AsmParsers.def: -------------------------------------------------------------------------------- 1 | /*===- llvm/Config/AsmParsers.def - LLVM Assembly Parsers -------*- C++ -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This file enumerates all of the assembly-language parsers *| 11 | |* supported by this build of LLVM. Clients of this file should define *| 12 | |* the LLVM_ASM_PARSER macro to be a function-like macro with a *| 13 | |* single parameter (the name of the target whose assembly can be *| 14 | |* generated); including this file will then enumerate all of the *| 15 | |* targets with assembly parsers. *| 16 | |* *| 17 | |* The set of targets supported by LLVM is generated at configuration *| 18 | |* time, at which point this header is generated. Do not modify this *| 19 | |* header directly. *| 20 | |* *| 21 | \*===----------------------------------------------------------------------===*/ 22 | 23 | #ifndef LLVM_ASM_PARSER 24 | # error Please define the macro LLVM_ASM_PARSER(TargetName) 25 | #endif 26 | 27 | LLVM_ASM_PARSER(MBlaze) LLVM_ASM_PARSER(Mips) LLVM_ASM_PARSER(ARM) LLVM_ASM_PARSER(X86) 28 | 29 | #undef LLVM_ASM_PARSER 30 | -------------------------------------------------------------------------------- /include/llvm/Config/AsmPrinters.def: -------------------------------------------------------------------------------- 1 | /*===- llvm/Config/AsmPrinters.def - LLVM Assembly Printers -----*- C++ -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This file enumerates all of the assembly-language printers *| 11 | |* supported by this build of LLVM. Clients of this file should define *| 12 | |* the LLVM_ASM_PRINTER macro to be a function-like macro with a *| 13 | |* single parameter (the name of the target whose assembly can be *| 14 | |* generated); including this file will then enumerate all of the *| 15 | |* targets with assembly printers. *| 16 | |* *| 17 | |* The set of targets supported by LLVM is generated at configuration *| 18 | |* time, at which point this header is generated. Do not modify this *| 19 | |* header directly. *| 20 | |* *| 21 | \*===----------------------------------------------------------------------===*/ 22 | 23 | #ifndef LLVM_ASM_PRINTER 24 | # error Please define the macro LLVM_ASM_PRINTER(TargetName) 25 | #endif 26 | 27 | LLVM_ASM_PRINTER(Hexagon) LLVM_ASM_PRINTER(NVPTX) LLVM_ASM_PRINTER(MBlaze) LLVM_ASM_PRINTER(MSP430) LLVM_ASM_PRINTER(XCore) LLVM_ASM_PRINTER(CellSPU) LLVM_ASM_PRINTER(Mips) LLVM_ASM_PRINTER(ARM) LLVM_ASM_PRINTER(PowerPC) LLVM_ASM_PRINTER(Sparc) LLVM_ASM_PRINTER(X86) 28 | 29 | #undef LLVM_ASM_PRINTER 30 | -------------------------------------------------------------------------------- /include/llvm/Config/Disassemblers.def: -------------------------------------------------------------------------------- 1 | /*===- llvm/Config/Disassemblers.def - LLVM Assembly Parsers ----*- C++ -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This file enumerates all of the assembly-language parsers *| 11 | |* supported by this build of LLVM. Clients of this file should define *| 12 | |* the LLVM_DISASSEMBLER macro to be a function-like macro with a *| 13 | |* single parameter (the name of the target whose assembly can be *| 14 | |* generated); including this file will then enumerate all of the *| 15 | |* targets with assembly parsers. *| 16 | |* *| 17 | |* The set of targets supported by LLVM is generated at configuration *| 18 | |* time, at which point this header is generated. Do not modify this *| 19 | |* header directly. *| 20 | |* *| 21 | \*===----------------------------------------------------------------------===*/ 22 | 23 | #ifndef LLVM_DISASSEMBLER 24 | # error Please define the macro LLVM_DISASSEMBLER(TargetName) 25 | #endif 26 | 27 | LLVM_DISASSEMBLER(MBlaze) LLVM_DISASSEMBLER(Mips) LLVM_DISASSEMBLER(ARM) LLVM_DISASSEMBLER(X86) 28 | 29 | #undef LLVM_DISASSEMBLER 30 | -------------------------------------------------------------------------------- /include/llvm/Config/Targets.def: -------------------------------------------------------------------------------- 1 | /*===- llvm/Config/Targets.def - LLVM Target Architectures ------*- C++ -*-===*\ 2 | |* *| 3 | |* The LLVM Compiler Infrastructure *| 4 | |* *| 5 | |* This file is distributed under the University of Illinois Open Source *| 6 | |* License. See LICENSE.TXT for details. *| 7 | |* *| 8 | |*===----------------------------------------------------------------------===*| 9 | |* *| 10 | |* This file enumerates all of the target architectures supported by *| 11 | |* this build of LLVM. Clients of this file should define the *| 12 | |* LLVM_TARGET macro to be a function-like macro with a single *| 13 | |* parameter (the name of the target); including this file will then *| 14 | |* enumerate all of the targets. *| 15 | |* *| 16 | |* The set of targets supported by LLVM is generated at configuration *| 17 | |* time, at which point this header is generated. Do not modify this *| 18 | |* header directly. *| 19 | |* *| 20 | \*===----------------------------------------------------------------------===*/ 21 | 22 | #ifndef LLVM_TARGET 23 | # error Please define the macro LLVM_TARGET(TargetName) 24 | #endif 25 | 26 | LLVM_TARGET(ARM) LLVM_TARGET(X86) 27 | 28 | #undef LLVM_TARGET 29 | -------------------------------------------------------------------------------- /include/llvm/Config/config.h: -------------------------------------------------------------------------------- 1 | /* include/llvm/Config/config.h. Generated from config.h.in by configure. */ 2 | /* include/llvm/Config/config.h.in. Generated from autoconf/configure.ac by autoheader. */ 3 | 4 | #ifndef CONFIG_H 5 | #define CONFIG_H 6 | 7 | /* Bug report URL. */ 8 | #define BUG_REPORT_URL "http://llvm.org/bugs/" 9 | 10 | /* Define if we have libxml2 */ 11 | /* #undef CLANG_HAVE_LIBXML */ 12 | 13 | /* Relative directory for resource files */ 14 | #define CLANG_RESOURCE_DIR "" 15 | 16 | /* Directories clang will search for headers */ 17 | #define C_INCLUDE_DIRS "" 18 | 19 | /* Default to all compiler invocations for --sysroot=. */ 20 | #define DEFAULT_SYSROOT "" 21 | 22 | /* Define if you want backtraces on crash */ 23 | #define ENABLE_BACKTRACES 24 | 25 | /* Define if position independent code is enabled */ 26 | #define ENABLE_PIC 1 27 | 28 | /* Define if timestamp information (e.g., __DATE__) is allowed */ 29 | #define ENABLE_TIMESTAMPS 1 30 | 31 | /* Directory where gcc is installed. */ 32 | #define GCC_INSTALL_PREFIX "" 33 | 34 | /* Define to 1 if you have the `arc4random' function. */ 35 | /* #undef HAVE_ARC4RANDOM */ 36 | 37 | /* Define to 1 if you have the `argz_append' function. */ 38 | #define HAVE_ARGZ_APPEND 1 39 | 40 | /* Define to 1 if you have the `argz_create_sep' function. */ 41 | #define HAVE_ARGZ_CREATE_SEP 1 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_ARGZ_H 1 45 | 46 | /* Define to 1 if you have the `argz_insert' function. */ 47 | #define HAVE_ARGZ_INSERT 1 48 | 49 | /* Define to 1 if you have the `argz_next' function. */ 50 | #define HAVE_ARGZ_NEXT 1 51 | 52 | /* Define to 1 if you have the `argz_stringify' function. */ 53 | #define HAVE_ARGZ_STRINGIFY 1 54 | 55 | /* Define to 1 if you have the header file. */ 56 | #define HAVE_ASSERT_H 1 57 | 58 | /* Define to 1 if you have the `backtrace' function. */ 59 | #define HAVE_BACKTRACE 1 60 | 61 | /* Define to 1 if you have the `bcopy' function. */ 62 | /* #undef HAVE_BCOPY */ 63 | 64 | /* Define to 1 if you have the `ceilf' function. */ 65 | #define HAVE_CEILF 1 66 | 67 | /* Define if the neat program is available */ 68 | /* #undef HAVE_CIRCO */ 69 | 70 | /* Define to 1 if you have the `closedir' function. */ 71 | #define HAVE_CLOSEDIR 1 72 | 73 | /* Define to 1 if you have the header file. */ 74 | /* #undef HAVE_CRASHREPORTERCLIENT_H */ 75 | 76 | /* Define if __crashreporter_info__ exists. */ 77 | #define HAVE_CRASHREPORTER_INFO 0 78 | 79 | /* Define to 1 if you have the header file. */ 80 | #define HAVE_CTYPE_H 1 81 | 82 | /* Define to 1 if you have the declaration of `strerror_s', and to 0 if you 83 | don't. */ 84 | #define HAVE_DECL_STRERROR_S 0 85 | 86 | /* Define to 1 if you have the header file, and it defines `DIR'. 87 | */ 88 | #define HAVE_DIRENT_H 1 89 | 90 | /* Define if you have the GNU dld library. */ 91 | /* #undef HAVE_DLD */ 92 | 93 | /* Define to 1 if you have the header file. */ 94 | /* #undef HAVE_DLD_H */ 95 | 96 | /* Define to 1 if you have the `dlerror' function. */ 97 | #define HAVE_DLERROR 1 98 | 99 | /* Define to 1 if you have the header file. */ 100 | #define HAVE_DLFCN_H 1 101 | 102 | /* Define if dlopen() is available on this platform. */ 103 | #define HAVE_DLOPEN 1 104 | 105 | /* Define to 1 if you have the header file. */ 106 | /* #undef HAVE_DL_H */ 107 | 108 | /* Define if the dot program is available */ 109 | /* #undef HAVE_DOT */ 110 | 111 | /* Define if the dotty program is available */ 112 | /* #undef HAVE_DOTTY */ 113 | 114 | /* Define if you have the _dyld_func_lookup function. */ 115 | /* #undef HAVE_DYLD */ 116 | 117 | /* Define to 1 if you have the header file. */ 118 | #define HAVE_ERRNO_H 1 119 | 120 | /* Define to 1 if the system has the type `error_t'. */ 121 | #define HAVE_ERROR_T 1 122 | 123 | /* Define to 1 if you have the header file. */ 124 | #define HAVE_EXECINFO_H 1 125 | 126 | /* Define to 1 if you have the header file. */ 127 | #define HAVE_FCNTL_H 1 128 | 129 | /* Define if the neat program is available */ 130 | /* #undef HAVE_FDP */ 131 | 132 | /* Define to 1 if you have the header file. */ 133 | #define HAVE_FENV_H 1 134 | 135 | /* Define if libffi is available on this platform. */ 136 | /* #undef HAVE_FFI_CALL */ 137 | 138 | /* Define to 1 if you have the header file. */ 139 | /* #undef HAVE_FFI_FFI_H */ 140 | 141 | /* Define to 1 if you have the header file. */ 142 | /* #undef HAVE_FFI_H */ 143 | 144 | /* Set to 1 if the finite function is found in */ 145 | /* #undef HAVE_FINITE_IN_IEEEFP_H */ 146 | 147 | /* Define to 1 if you have the `floorf' function. */ 148 | #define HAVE_FLOORF 1 149 | 150 | /* Define to 1 if you have the `fmodf' function. */ 151 | #define HAVE_FMODF 1 152 | 153 | /* Define to 1 if you have the `getcwd' function. */ 154 | #define HAVE_GETCWD 1 155 | 156 | /* Define to 1 if you have the `getpagesize' function. */ 157 | #define HAVE_GETPAGESIZE 1 158 | 159 | /* Define to 1 if you have the `getrlimit' function. */ 160 | #define HAVE_GETRLIMIT 1 161 | 162 | /* Define to 1 if you have the `getrusage' function. */ 163 | #define HAVE_GETRUSAGE 1 164 | 165 | /* Define to 1 if you have the `gettimeofday' function. */ 166 | #define HAVE_GETTIMEOFDAY 1 167 | 168 | /* Define if the Graphviz program is available */ 169 | /* #undef HAVE_GRAPHVIZ */ 170 | 171 | /* Define if the gv program is available */ 172 | /* #undef HAVE_GV */ 173 | 174 | /* Define to 1 if you have the `index' function. */ 175 | /* #undef HAVE_INDEX */ 176 | 177 | /* Define to 1 if the system has the type `int64_t'. */ 178 | #define HAVE_INT64_T 1 179 | 180 | /* Define to 1 if you have the header file. */ 181 | #define HAVE_INTTYPES_H 1 182 | 183 | /* Define to 1 if you have the `isatty' function. */ 184 | #define HAVE_ISATTY 1 185 | 186 | /* Set to 1 if the isinf function is found in */ 187 | #define HAVE_ISINF_IN_CMATH 1 188 | 189 | /* Set to 1 if the isinf function is found in */ 190 | #define HAVE_ISINF_IN_MATH_H 1 191 | 192 | /* Set to 1 if the isnan function is found in */ 193 | #define HAVE_ISNAN_IN_CMATH 1 194 | 195 | /* Set to 1 if the isnan function is found in */ 196 | #define HAVE_ISNAN_IN_MATH_H 1 197 | 198 | /* Define if you have the libdl library or equivalent. */ 199 | #define HAVE_LIBDL 1 200 | 201 | /* Define to 1 if you have the `imagehlp' library (-limagehlp). */ 202 | /* #undef HAVE_LIBIMAGEHLP */ 203 | 204 | /* Define to 1 if you have the `m' library (-lm). */ 205 | #define HAVE_LIBM 1 206 | 207 | /* Define to 1 if you have the `psapi' library (-lpsapi). */ 208 | /* #undef HAVE_LIBPSAPI */ 209 | 210 | /* Define to 1 if you have the `pthread' library (-lpthread). */ 211 | #define HAVE_LIBPTHREAD 1 212 | 213 | /* Define to 1 if you have the `udis86' library (-ludis86). */ 214 | /* #undef HAVE_LIBUDIS86 */ 215 | 216 | /* Define to 1 if you have the header file. */ 217 | #define HAVE_LIMITS_H 1 218 | 219 | /* Define if you can use -Wl,-export-dynamic. */ 220 | #define HAVE_LINK_EXPORT_DYNAMIC 1 221 | 222 | /* Define to 1 if you have the header file. */ 223 | #define HAVE_LINK_H 1 224 | 225 | /* Define if you can use -Wl,-R. to pass -R. to the linker, in order to add 226 | the current directory to the dynamic linker search path. */ 227 | #define HAVE_LINK_R 1 228 | 229 | /* Define to 1 if you have the `longjmp' function. */ 230 | #define HAVE_LONGJMP 1 231 | 232 | /* Define to 1 if you have the header file. */ 233 | /* #undef HAVE_MACH_MACH_H */ 234 | 235 | /* Define to 1 if you have the header file. */ 236 | /* #undef HAVE_MACH_O_DYLD_H */ 237 | 238 | /* Define if mallinfo() is available on this platform. */ 239 | #define HAVE_MALLINFO 1 240 | 241 | /* Define to 1 if you have the header file. */ 242 | #define HAVE_MALLOC_H 1 243 | 244 | /* Define to 1 if you have the header file. */ 245 | /* #undef HAVE_MALLOC_MALLOC_H */ 246 | 247 | /* Define to 1 if you have the `malloc_zone_statistics' function. */ 248 | /* #undef HAVE_MALLOC_ZONE_STATISTICS */ 249 | 250 | /* Define to 1 if you have the `memcpy' function. */ 251 | #define HAVE_MEMCPY 1 252 | 253 | /* Define to 1 if you have the `memmove' function. */ 254 | #define HAVE_MEMMOVE 1 255 | 256 | /* Define to 1 if you have the header file. */ 257 | #define HAVE_MEMORY_H 1 258 | 259 | /* Define to 1 if you have the `mkdtemp' function. */ 260 | #define HAVE_MKDTEMP 1 261 | 262 | /* Define to 1 if you have the `mkstemp' function. */ 263 | #define HAVE_MKSTEMP 1 264 | 265 | /* Define to 1 if you have the `mktemp' function. */ 266 | #define HAVE_MKTEMP 1 267 | 268 | /* Define to 1 if you have a working `mmap' system call. */ 269 | #define HAVE_MMAP 1 270 | 271 | /* Define if mmap() uses MAP_ANONYMOUS to map anonymous pages, or undefine if 272 | it uses MAP_ANON */ 273 | #define HAVE_MMAP_ANONYMOUS 1 274 | 275 | /* Define if mmap() can map files into memory */ 276 | #define HAVE_MMAP_FILE 277 | 278 | /* Define to 1 if you have the header file, and it defines `DIR'. */ 279 | /* #undef HAVE_NDIR_H */ 280 | 281 | /* Define to 1 if you have the `nearbyintf' function. */ 282 | #define HAVE_NEARBYINTF 1 283 | 284 | /* Define if the neat program is available */ 285 | /* #undef HAVE_NEATO */ 286 | 287 | /* Define to 1 if you have the `opendir' function. */ 288 | #define HAVE_OPENDIR 1 289 | 290 | /* Define to 1 if you have the `posix_spawn' function. */ 291 | #define HAVE_POSIX_SPAWN 1 292 | 293 | /* Define to 1 if you have the `powf' function. */ 294 | #define HAVE_POWF 1 295 | 296 | /* Define to 1 if you have the `pread' function. */ 297 | #define HAVE_PREAD 1 298 | 299 | /* Define if libtool can extract symbol lists from object files. */ 300 | #define HAVE_PRELOADED_SYMBOLS 1 301 | 302 | /* Define to have the %a format string */ 303 | #define HAVE_PRINTF_A 1 304 | 305 | /* Have pthread_getspecific */ 306 | #define HAVE_PTHREAD_GETSPECIFIC 1 307 | 308 | /* Define to 1 if you have the header file. */ 309 | #define HAVE_PTHREAD_H 1 310 | 311 | /* Have pthread_mutex_lock */ 312 | #define HAVE_PTHREAD_MUTEX_LOCK 1 313 | 314 | /* Have pthread_rwlock_init */ 315 | #define HAVE_PTHREAD_RWLOCK_INIT 1 316 | 317 | /* Define to 1 if srand48/lrand48/drand48 exist in */ 318 | #define HAVE_RAND48 1 319 | 320 | /* Define to 1 if you have the `readdir' function. */ 321 | #define HAVE_READDIR 1 322 | 323 | /* Define to 1 if you have the `realpath' function. */ 324 | #define HAVE_REALPATH 1 325 | 326 | /* Define to 1 if you have the `rindex' function. */ 327 | /* #undef HAVE_RINDEX */ 328 | 329 | /* Define to 1 if you have the `rintf' function. */ 330 | #define HAVE_RINTF 1 331 | 332 | /* Define to 1 if you have the `round' function. */ 333 | #define HAVE_ROUND 1 334 | 335 | /* Define to 1 if you have the `roundf' function. */ 336 | #define HAVE_ROUNDF 1 337 | 338 | /* Define to 1 if you have the `sbrk' function. */ 339 | #define HAVE_SBRK 1 340 | 341 | /* Define to 1 if you have the `setenv' function. */ 342 | #define HAVE_SETENV 1 343 | 344 | /* Define to 1 if you have the `setjmp' function. */ 345 | #define HAVE_SETJMP 1 346 | 347 | /* Define to 1 if you have the header file. */ 348 | #define HAVE_SETJMP_H 1 349 | 350 | /* Define to 1 if you have the `setrlimit' function. */ 351 | #define HAVE_SETRLIMIT 1 352 | 353 | /* Define if you have the shl_load function. */ 354 | /* #undef HAVE_SHL_LOAD */ 355 | 356 | /* Define to 1 if you have the `siglongjmp' function. */ 357 | #define HAVE_SIGLONGJMP 1 358 | 359 | /* Define to 1 if you have the header file. */ 360 | #define HAVE_SIGNAL_H 1 361 | 362 | /* Define to 1 if you have the `sigsetjmp' function. */ 363 | /* #undef HAVE_SIGSETJMP */ 364 | 365 | /* Define to 1 if you have the header file. */ 366 | #define HAVE_STDINT_H 1 367 | 368 | /* Define to 1 if you have the header file. */ 369 | #define HAVE_STDIO_H 1 370 | 371 | /* Define to 1 if you have the header file. */ 372 | #define HAVE_STDLIB_H 1 373 | 374 | /* Set to 1 if the std::isinf function is found in */ 375 | #define HAVE_STD_ISINF_IN_CMATH 1 376 | 377 | /* Set to 1 if the std::isnan function is found in */ 378 | #define HAVE_STD_ISNAN_IN_CMATH 1 379 | 380 | /* Define to 1 if you have the `strchr' function. */ 381 | #define HAVE_STRCHR 1 382 | 383 | /* Define to 1 if you have the `strcmp' function. */ 384 | #define HAVE_STRCMP 1 385 | 386 | /* Define to 1 if you have the `strdup' function. */ 387 | #define HAVE_STRDUP 1 388 | 389 | /* Define to 1 if you have the `strerror' function. */ 390 | #define HAVE_STRERROR 1 391 | 392 | /* Define to 1 if you have the `strerror_r' function. */ 393 | #define HAVE_STRERROR_R 1 394 | 395 | /* Define to 1 if you have the header file. */ 396 | #define HAVE_STRINGS_H 1 397 | 398 | /* Define to 1 if you have the header file. */ 399 | #define HAVE_STRING_H 1 400 | 401 | /* Define to 1 if you have the `strrchr' function. */ 402 | #define HAVE_STRRCHR 1 403 | 404 | /* Define to 1 if you have the `strtof' function. */ 405 | #define HAVE_STRTOF 1 406 | 407 | /* Define to 1 if you have the `strtoll' function. */ 408 | #define HAVE_STRTOLL 1 409 | 410 | /* Define to 1 if you have the `strtoq' function. */ 411 | #define HAVE_STRTOQ 1 412 | 413 | /* Define to 1 if you have the `sysconf' function. */ 414 | #define HAVE_SYSCONF 1 415 | 416 | /* Define to 1 if you have the header file, and it defines `DIR'. 417 | */ 418 | /* #undef HAVE_SYS_DIR_H */ 419 | 420 | /* Define to 1 if you have the header file. */ 421 | /* #undef HAVE_SYS_DL_H */ 422 | 423 | /* Define to 1 if you have the header file. */ 424 | #define HAVE_SYS_IOCTL_H 1 425 | 426 | /* Define to 1 if you have the header file. */ 427 | #define HAVE_SYS_MMAN_H 1 428 | 429 | /* Define to 1 if you have the header file, and it defines `DIR'. 430 | */ 431 | /* #undef HAVE_SYS_NDIR_H */ 432 | 433 | /* Define to 1 if you have the header file. */ 434 | #define HAVE_SYS_PARAM_H 1 435 | 436 | /* Define to 1 if you have the header file. */ 437 | #define HAVE_SYS_RESOURCE_H 1 438 | 439 | /* Define to 1 if you have the header file. */ 440 | #define HAVE_SYS_STAT_H 1 441 | 442 | /* Define to 1 if you have the header file. */ 443 | #define HAVE_SYS_TIME_H 1 444 | 445 | /* Define to 1 if you have the header file. */ 446 | #define HAVE_SYS_TYPES_H 1 447 | 448 | /* Define to 1 if you have the header file. */ 449 | #define HAVE_SYS_UIO_H 1 450 | 451 | /* Define to 1 if you have that is POSIX.1 compatible. */ 452 | #define HAVE_SYS_WAIT_H 1 453 | 454 | /* Define to 1 if you have the header file. */ 455 | #define HAVE_TERMIOS_H 1 456 | 457 | /* Define if the neat program is available */ 458 | /* #undef HAVE_TWOPI */ 459 | 460 | /* Define to 1 if the system has the type `uint64_t'. */ 461 | #define HAVE_UINT64_T 1 462 | 463 | /* Define to 1 if you have the header file. */ 464 | #define HAVE_UNISTD_H 1 465 | 466 | /* Define to 1 if you have the header file. */ 467 | #define HAVE_UTIME_H 1 468 | 469 | /* Define to 1 if the system has the type `u_int64_t'. */ 470 | /* #undef HAVE_U_INT64_T */ 471 | 472 | /* Define to 1 if you have the header file. */ 473 | /* #undef HAVE_VALGRIND_VALGRIND_H */ 474 | 475 | /* Define to 1 if you have the header file. */ 476 | /* #undef HAVE_WINDOWS_H */ 477 | 478 | /* Define to 1 if you have the `writev' function. */ 479 | #define HAVE_WRITEV 1 480 | 481 | /* Define if the xdot.py program is available */ 482 | /* #undef HAVE_XDOT_PY */ 483 | 484 | /* Have host's _alloca */ 485 | /* #undef HAVE__ALLOCA */ 486 | 487 | /* Have host's __alloca */ 488 | /* #undef HAVE___ALLOCA */ 489 | 490 | /* Have host's __ashldi3 */ 491 | /* #undef HAVE___ASHLDI3 */ 492 | 493 | /* Have host's __ashrdi3 */ 494 | /* #undef HAVE___ASHRDI3 */ 495 | 496 | /* Have host's __chkstk */ 497 | /* #undef HAVE___CHKSTK */ 498 | 499 | /* Have host's __cmpdi2 */ 500 | /* #undef HAVE___CMPDI2 */ 501 | 502 | /* Have host's __divdi3 */ 503 | /* #undef HAVE___DIVDI3 */ 504 | 505 | /* Define to 1 if you have the `__dso_handle' function. */ 506 | #define HAVE___DSO_HANDLE 1 507 | 508 | /* Have host's __fixdfdi */ 509 | /* #undef HAVE___FIXDFDI */ 510 | 511 | /* Have host's __fixsfdi */ 512 | /* #undef HAVE___FIXSFDI */ 513 | 514 | /* Have host's __floatdidf */ 515 | /* #undef HAVE___FLOATDIDF */ 516 | 517 | /* Have host's __lshrdi3 */ 518 | /* #undef HAVE___LSHRDI3 */ 519 | 520 | /* Have host's __main */ 521 | /* #undef HAVE___MAIN */ 522 | 523 | /* Have host's __moddi3 */ 524 | /* #undef HAVE___MODDI3 */ 525 | 526 | /* Have host's __udivdi3 */ 527 | /* #undef HAVE___UDIVDI3 */ 528 | 529 | /* Have host's __umoddi3 */ 530 | /* #undef HAVE___UMODDI3 */ 531 | 532 | /* Have host's ___chkstk */ 533 | /* #undef HAVE____CHKSTK */ 534 | 535 | /* Linker version detected at compile time. */ 536 | #define HOST_LINK_VERSION "2.22" 537 | 538 | /* Installation directory for binary executables */ 539 | #define LLVM_BINDIR "/usr/local/bin" 540 | 541 | /* Time at which LLVM was configured */ 542 | #define LLVM_CONFIGTIME "Sat Sep 22 15:55:00 WST 2012" 543 | 544 | /* Installation directory for data files */ 545 | #define LLVM_DATADIR "/usr/local/share/llvm" 546 | 547 | /* Target triple LLVM will generate code for by default */ 548 | #define LLVM_DEFAULT_TARGET_TRIPLE "x86_64-unknown-linux-gnu" 549 | 550 | /* Installation directory for documentation */ 551 | #define LLVM_DOCSDIR "/usr/local/share/doc/llvm" 552 | 553 | /* Define if threads enabled */ 554 | #define LLVM_ENABLE_THREADS 1 555 | 556 | /* Installation directory for config files */ 557 | #define LLVM_ETCDIR "/usr/local/etc/llvm" 558 | 559 | /* Has gcc/MSVC atomic intrinsics */ 560 | #define LLVM_HAS_ATOMICS 1 561 | 562 | /* Host triple LLVM will be executed on */ 563 | #define LLVM_HOSTTRIPLE "x86_64-unknown-linux-gnu" 564 | 565 | /* Installation directory for include files */ 566 | #define LLVM_INCLUDEDIR "/usr/local/include" 567 | 568 | /* Installation directory for .info files */ 569 | #define LLVM_INFODIR "/usr/local/info" 570 | 571 | /* Installation directory for libraries */ 572 | #define LLVM_LIBDIR "/usr/local/lib" 573 | 574 | /* Installation directory for man pages */ 575 | #define LLVM_MANDIR "/usr/local/man" 576 | 577 | /* LLVM architecture name for the native architecture, if available */ 578 | #define LLVM_NATIVE_ARCH X86 579 | 580 | /* LLVM name for the native AsmParser init function, if available */ 581 | #define LLVM_NATIVE_ASMPARSER LLVMInitializeX86AsmParser 582 | 583 | /* LLVM name for the native AsmPrinter init function, if available */ 584 | #define LLVM_NATIVE_ASMPRINTER LLVMInitializeX86AsmPrinter 585 | 586 | /* LLVM name for the native Disassembler init function, if available */ 587 | #define LLVM_NATIVE_DISASSEMBLER LLVMInitializeX86Disassembler 588 | 589 | /* LLVM name for the native Target init function, if available */ 590 | #define LLVM_NATIVE_TARGET LLVMInitializeX86Target 591 | 592 | /* LLVM name for the native TargetInfo init function, if available */ 593 | #define LLVM_NATIVE_TARGETINFO LLVMInitializeX86TargetInfo 594 | 595 | /* LLVM name for the native target MC init function, if available */ 596 | #define LLVM_NATIVE_TARGETMC LLVMInitializeX86TargetMC 597 | 598 | /* Define if this is Unixish platform */ 599 | #define LLVM_ON_UNIX 1 600 | 601 | /* Define if this is Win32ish platform */ 602 | /* #undef LLVM_ON_WIN32 */ 603 | 604 | /* Define to path to circo program if found or 'echo circo' otherwise */ 605 | /* #undef LLVM_PATH_CIRCO */ 606 | 607 | /* Define to path to dot program if found or 'echo dot' otherwise */ 608 | /* #undef LLVM_PATH_DOT */ 609 | 610 | /* Define to path to dotty program if found or 'echo dotty' otherwise */ 611 | /* #undef LLVM_PATH_DOTTY */ 612 | 613 | /* Define to path to fdp program if found or 'echo fdp' otherwise */ 614 | /* #undef LLVM_PATH_FDP */ 615 | 616 | /* Define to path to Graphviz program if found or 'echo Graphviz' otherwise */ 617 | /* #undef LLVM_PATH_GRAPHVIZ */ 618 | 619 | /* Define to path to gv program if found or 'echo gv' otherwise */ 620 | /* #undef LLVM_PATH_GV */ 621 | 622 | /* Define to path to neato program if found or 'echo neato' otherwise */ 623 | /* #undef LLVM_PATH_NEATO */ 624 | 625 | /* Define to path to twopi program if found or 'echo twopi' otherwise */ 626 | /* #undef LLVM_PATH_TWOPI */ 627 | 628 | /* Define to path to xdot.py program if found or 'echo xdot.py' otherwise */ 629 | /* #undef LLVM_PATH_XDOT_PY */ 630 | 631 | /* Installation prefix directory */ 632 | #define LLVM_PREFIX "/usr/local" 633 | 634 | /* Define if we have the Intel JIT API runtime support library */ 635 | #define LLVM_USE_INTEL_JITEVENTS 0 636 | 637 | /* Define if we have the oprofile JIT-support library */ 638 | #define LLVM_USE_OPROFILE 0 639 | 640 | /* Major version of the LLVM API */ 641 | #define LLVM_VERSION_MAJOR 3 642 | 643 | /* Minor version of the LLVM API */ 644 | #define LLVM_VERSION_MINOR 2 645 | 646 | /* Define if the OS needs help to load dependent libraries for dlopen(). */ 647 | /* #undef LTDL_DLOPEN_DEPLIBS */ 648 | 649 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 650 | */ 651 | #define LTDL_OBJDIR ".libs/" 652 | 653 | /* Define to the name of the environment variable that determines the dynamic 654 | library search path. */ 655 | #define LTDL_SHLIBPATH_VAR "LD_LIBRARY_PATH" 656 | 657 | /* Define to the extension used for shared libraries, say, ".so". */ 658 | #define LTDL_SHLIB_EXT ".so" 659 | 660 | /* Define to the system default library search path. */ 661 | #define LTDL_SYSSEARCHPATH "/lib:/usr/lib:/usr/local/lib:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu/mesa" 662 | 663 | /* Define if /dev/zero should be used when mapping RWX memory, or undefine if 664 | its not necessary */ 665 | /* #undef NEED_DEV_ZERO_FOR_MMAP */ 666 | 667 | /* Define if dlsym() requires a leading underscore in symbol names. */ 668 | /* #undef NEED_USCORE */ 669 | 670 | /* Define to the address where bug reports for this package should be sent. */ 671 | #define PACKAGE_BUGREPORT "http://llvm.org/bugs/" 672 | 673 | /* Define to the full name of this package. */ 674 | #define PACKAGE_NAME "LLVM" 675 | 676 | /* Define to the full name and version of this package. */ 677 | #define PACKAGE_STRING "LLVM 3.2svn" 678 | 679 | /* Define to the one symbol short name of this package. */ 680 | #define PACKAGE_TARNAME "llvm" 681 | 682 | /* Define to the version of this package. */ 683 | #define PACKAGE_VERSION "3.2svn" 684 | 685 | /* Define as the return type of signal handlers (`int' or `void'). */ 686 | #define RETSIGTYPE void 687 | 688 | /* Define to 1 if the `S_IS*' macros in do not work properly. */ 689 | /* #undef STAT_MACROS_BROKEN */ 690 | 691 | /* Define to 1 if you have the ANSI C header files. */ 692 | #define STDC_HEADERS 1 693 | 694 | /* Define to 1 if you can safely include both and . */ 695 | #define TIME_WITH_SYS_TIME 1 696 | 697 | /* Define to 1 if your declares `struct tm'. */ 698 | /* #undef TM_IN_SYS_TIME */ 699 | 700 | /* Define if use udis86 library */ 701 | #define USE_UDIS86 0 702 | 703 | /* Type of 1st arg on ELM Callback */ 704 | /* #undef WIN32_ELMCB_PCSTR */ 705 | 706 | /* Define to empty if `const' does not conform to ANSI C. */ 707 | /* #undef const */ 708 | 709 | /* Define to a type to use for `error_t' if it is not otherwise available. */ 710 | /* #undef error_t */ 711 | 712 | /* Define to `int' if does not define. */ 713 | /* #undef pid_t */ 714 | 715 | /* Define to `unsigned int' if does not define. */ 716 | /* #undef size_t */ 717 | 718 | #endif 719 | -------------------------------------------------------------------------------- /include/llvm/Config/llvm-config.h: -------------------------------------------------------------------------------- 1 | /* include/llvm/Config/llvm-config.h. Generated from llvm-config.h.in by configure. */ 2 | /*===-- llvm/config/llvm-config.h - llvm configure variable -------*- C -*-===*/ 3 | /* */ 4 | /* The LLVM Compiler Infrastructure */ 5 | /* */ 6 | /* This file is distributed under the University of Illinois Open Source */ 7 | /* License. See LICENSE.TXT for details. */ 8 | /* */ 9 | /*===----------------------------------------------------------------------===*/ 10 | 11 | /* This file enumerates all of the llvm variables from configure so that 12 | they can be in exported headers and won't override package specific 13 | directives. This is a C file so we can include it in the llvm-c headers. */ 14 | 15 | /* To avoid multiple inclusions of these variables when we include the exported 16 | headers and config.h, conditionally include these. */ 17 | /* TODO: This is a bit of a hack. */ 18 | #ifndef CONFIG_H 19 | 20 | /* Installation directory for binary executables */ 21 | #define LLVM_BINDIR "/usr/local/bin" 22 | 23 | /* Time at which LLVM was configured */ 24 | #define LLVM_CONFIGTIME "Sat Sep 22 15:55:00 WST 2012" 25 | 26 | /* Installation directory for data files */ 27 | #define LLVM_DATADIR "/usr/local/share/llvm" 28 | 29 | /* Target triple LLVM will generate code for by default */ 30 | #define LLVM_DEFAULT_TARGET_TRIPLE "x86_64-unknown-linux-gnu" 31 | 32 | /* Installation directory for documentation */ 33 | #define LLVM_DOCSDIR "/usr/local/share/doc/llvm" 34 | 35 | /* Define if threads enabled */ 36 | #define LLVM_ENABLE_THREADS 1 37 | 38 | /* Installation directory for config files */ 39 | #define LLVM_ETCDIR "/usr/local/etc/llvm" 40 | 41 | /* Has gcc/MSVC atomic intrinsics */ 42 | #define LLVM_HAS_ATOMICS 1 43 | 44 | /* Host triple LLVM will be executed on */ 45 | #define LLVM_HOSTTRIPLE "x86_64-unknown-linux-gnu" 46 | 47 | /* Installation directory for include files */ 48 | #define LLVM_INCLUDEDIR "/usr/local/include" 49 | 50 | /* Installation directory for .info files */ 51 | #define LLVM_INFODIR "/usr/local/info" 52 | 53 | /* Installation directory for libraries */ 54 | #define LLVM_LIBDIR "/usr/local/lib" 55 | 56 | /* Installation directory for man pages */ 57 | #define LLVM_MANDIR "/usr/local/man" 58 | 59 | /* LLVM architecture name for the native architecture, if available */ 60 | #define LLVM_NATIVE_ARCH X86 61 | 62 | /* LLVM name for the native AsmParser init function, if available */ 63 | #define LLVM_NATIVE_ASMPARSER LLVMInitializeX86AsmParser 64 | 65 | /* LLVM name for the native AsmPrinter init function, if available */ 66 | #define LLVM_NATIVE_ASMPRINTER LLVMInitializeX86AsmPrinter 67 | 68 | /* LLVM name for the native Disassembler init function, if available */ 69 | #define LLVM_NATIVE_DISASSEMBLER LLVMInitializeX86Disassembler 70 | 71 | /* LLVM name for the native Target init function, if available */ 72 | #define LLVM_NATIVE_TARGET LLVMInitializeX86Target 73 | 74 | /* LLVM name for the native TargetInfo init function, if available */ 75 | #define LLVM_NATIVE_TARGETINFO LLVMInitializeX86TargetInfo 76 | 77 | /* LLVM name for the native target MC init function, if available */ 78 | #define LLVM_NATIVE_TARGETMC LLVMInitializeX86TargetMC 79 | 80 | /* Define if this is Unixish platform */ 81 | #define LLVM_ON_UNIX 1 82 | 83 | /* Define if this is Win32ish platform */ 84 | /* #undef LLVM_ON_WIN32 */ 85 | 86 | /* Define to path to circo program if found or 'echo circo' otherwise */ 87 | /* #undef LLVM_PATH_CIRCO */ 88 | 89 | /* Define to path to dot program if found or 'echo dot' otherwise */ 90 | /* #undef LLVM_PATH_DOT */ 91 | 92 | /* Define to path to dotty program if found or 'echo dotty' otherwise */ 93 | /* #undef LLVM_PATH_DOTTY */ 94 | 95 | /* Define to path to fdp program if found or 'echo fdp' otherwise */ 96 | /* #undef LLVM_PATH_FDP */ 97 | 98 | /* Define to path to Graphviz program if found or 'echo Graphviz' otherwise */ 99 | /* #undef LLVM_PATH_GRAPHVIZ */ 100 | 101 | /* Define to path to gv program if found or 'echo gv' otherwise */ 102 | /* #undef LLVM_PATH_GV */ 103 | 104 | /* Define to path to neato program if found or 'echo neato' otherwise */ 105 | /* #undef LLVM_PATH_NEATO */ 106 | 107 | /* Define to path to twopi program if found or 'echo twopi' otherwise */ 108 | /* #undef LLVM_PATH_TWOPI */ 109 | 110 | /* Define to path to xdot.py program if found or 'echo xdot.py' otherwise */ 111 | /* #undef LLVM_PATH_XDOT_PY */ 112 | 113 | /* Installation prefix directory */ 114 | #define LLVM_PREFIX "/usr/local" 115 | 116 | /* Major version of the LLVM API */ 117 | #define LLVM_VERSION_MAJOR 3 118 | 119 | /* Minor version of the LLVM API */ 120 | #define LLVM_VERSION_MINOR 2 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /include/llvm/Support/DataTypes.h: -------------------------------------------------------------------------------- 1 | /* include/llvm/Support/DataTypes.h. Generated from DataTypes.h.in by configure. */ 2 | /*===-- include/Support/DataTypes.h - Define fixed size types -----*- C -*-===*\ 3 | |* *| 4 | |* The LLVM Compiler Infrastructure *| 5 | |* *| 6 | |* This file is distributed under the University of Illinois Open Source *| 7 | |* License. See LICENSE.TXT for details. *| 8 | |* *| 9 | |*===----------------------------------------------------------------------===*| 10 | |* *| 11 | |* This file contains definitions to figure out the size of _HOST_ data types.*| 12 | |* This file is important because different host OS's define different macros,*| 13 | |* which makes portability tough. This file exports the following *| 14 | |* definitions: *| 15 | |* *| 16 | |* [u]int(32|64)_t : typedefs for signed and unsigned 32/64 bit system types*| 17 | |* [U]INT(8|16|32|64)_(MIN|MAX) : Constants for the min and max values. *| 18 | |* *| 19 | |* No library is required when using these functions. *| 20 | |* *| 21 | |*===----------------------------------------------------------------------===*/ 22 | 23 | /* Please leave this file C-compatible. */ 24 | 25 | /* Please keep this file in sync with DataTypes.h.cmake */ 26 | 27 | #ifndef SUPPORT_DATATYPES_H 28 | #define SUPPORT_DATATYPES_H 29 | 30 | #define HAVE_SYS_TYPES_H 1 31 | #define HAVE_INTTYPES_H 1 32 | #define HAVE_STDINT_H 1 33 | #define HAVE_UINT64_T 1 34 | /* #undef HAVE_U_INT64_T */ 35 | 36 | #ifdef __cplusplus 37 | #include 38 | #else 39 | #include 40 | #endif 41 | 42 | #ifndef _MSC_VER 43 | 44 | /* Note that this header's correct operation depends on __STDC_LIMIT_MACROS 45 | being defined. We would define it here, but in order to prevent Bad Things 46 | happening when system headers or C++ STL headers include stdint.h before we 47 | define it here, we define it on the g++ command line (in Makefile.rules). */ 48 | #if !defined(__STDC_LIMIT_MACROS) 49 | # error "Must #define __STDC_LIMIT_MACROS before #including Support/DataTypes.h" 50 | #endif 51 | 52 | #if !defined(__STDC_CONSTANT_MACROS) 53 | # error "Must #define __STDC_CONSTANT_MACROS before " \ 54 | "#including Support/DataTypes.h" 55 | #endif 56 | 57 | /* Note that includes , if this is a C99 system. */ 58 | #ifdef HAVE_SYS_TYPES_H 59 | #include 60 | #endif 61 | 62 | #ifdef HAVE_INTTYPES_H 63 | #include 64 | #endif 65 | 66 | #ifdef HAVE_STDINT_H 67 | #include 68 | #endif 69 | 70 | #ifdef _AIX 71 | #include "llvm/Support/AIXDataTypesFix.h" 72 | #endif 73 | 74 | /* Handle incorrect definition of uint64_t as u_int64_t */ 75 | #ifndef HAVE_UINT64_T 76 | #ifdef HAVE_U_INT64_T 77 | typedef u_int64_t uint64_t; 78 | #else 79 | # error "Don't have a definition for uint64_t on this platform" 80 | #endif 81 | #endif 82 | 83 | #else /* _MSC_VER */ 84 | /* Visual C++ doesn't provide standard integer headers, but it does provide 85 | built-in data types. */ 86 | #include 87 | #include 88 | #include 89 | #ifdef __cplusplus 90 | #include 91 | #else 92 | #include 93 | #endif 94 | typedef __int64 int64_t; 95 | typedef unsigned __int64 uint64_t; 96 | typedef signed int int32_t; 97 | typedef unsigned int uint32_t; 98 | typedef short int16_t; 99 | typedef unsigned short uint16_t; 100 | typedef signed char int8_t; 101 | typedef unsigned char uint8_t; 102 | typedef signed int ssize_t; 103 | #ifndef INT8_MAX 104 | # define INT8_MAX 127 105 | #endif 106 | #ifndef INT8_MIN 107 | # define INT8_MIN -128 108 | #endif 109 | #ifndef UINT8_MAX 110 | # define UINT8_MAX 255 111 | #endif 112 | #ifndef INT16_MAX 113 | # define INT16_MAX 32767 114 | #endif 115 | #ifndef INT16_MIN 116 | # define INT16_MIN -32768 117 | #endif 118 | #ifndef UINT16_MAX 119 | # define UINT16_MAX 65535 120 | #endif 121 | #ifndef INT32_MAX 122 | # define INT32_MAX 2147483647 123 | #endif 124 | #ifndef INT32_MIN 125 | /* MSC treats -2147483648 as -(2147483648U). */ 126 | # define INT32_MIN (-INT32_MAX - 1) 127 | #endif 128 | #ifndef UINT32_MAX 129 | # define UINT32_MAX 4294967295U 130 | #endif 131 | /* Certain compatibility updates to VC++ introduce the `cstdint' 132 | * header, which defines the INT*_C macros. On default installs they 133 | * are absent. */ 134 | #ifndef INT8_C 135 | # define INT8_C(C) C##i8 136 | #endif 137 | #ifndef UINT8_C 138 | # define UINT8_C(C) C##ui8 139 | #endif 140 | #ifndef INT16_C 141 | # define INT16_C(C) C##i16 142 | #endif 143 | #ifndef UINT16_C 144 | # define UINT16_C(C) C##ui16 145 | #endif 146 | #ifndef INT32_C 147 | # define INT32_C(C) C##i32 148 | #endif 149 | #ifndef UINT32_C 150 | # define UINT32_C(C) C##ui32 151 | #endif 152 | #ifndef INT64_C 153 | # define INT64_C(C) C##i64 154 | #endif 155 | #ifndef UINT64_C 156 | # define UINT64_C(C) C##ui64 157 | #endif 158 | 159 | #ifndef PRId64 160 | # define PRId64 "I64d" 161 | #endif 162 | #ifndef PRIi64 163 | # define PRIi64 "I64i" 164 | #endif 165 | #ifndef PRIo64 166 | # define PRIo64 "I64o" 167 | #endif 168 | #ifndef PRIu64 169 | # define PRIu64 "I64u" 170 | #endif 171 | #ifndef PRIx64 172 | # define PRIx64 "I64x" 173 | #endif 174 | #ifndef PRIX64 175 | # define PRIX64 "I64X" 176 | #endif 177 | 178 | #endif /* _MSC_VER */ 179 | 180 | /* Set defaults for constants which we cannot find. */ 181 | #if !defined(INT64_MAX) 182 | # define INT64_MAX 9223372036854775807LL 183 | #endif 184 | #if !defined(INT64_MIN) 185 | # define INT64_MIN ((-INT64_MAX)-1) 186 | #endif 187 | #if !defined(UINT64_MAX) 188 | # define UINT64_MAX 0xffffffffffffffffULL 189 | #endif 190 | 191 | #if __GNUC__ > 3 192 | #define END_WITH_NULL __attribute__((sentinel)) 193 | #else 194 | #define END_WITH_NULL 195 | #endif 196 | 197 | #ifndef HUGE_VALF 198 | #define HUGE_VALF (float)HUGE_VAL 199 | #endif 200 | 201 | #endif /* SUPPORT_DATATYPES_H */ 202 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ver="`llvm-config --version`" 3 | export CGO_CFLAGS="`llvm-config --cflags` -I ../include" 4 | export CGO_LDFLAGS="`llvm-config --ldflags` -Wl,-L`llvm-config --libdir` -lLLVM-$ver" 5 | 6 | case "$ver" in 7 | *svn) 8 | tags="-tags llvmsvn" 9 | ;; 10 | *) 11 | tags="-tags llvm$ver" 12 | ;; 13 | esac 14 | 15 | go clean -i github.com/axw/gollvm/llvm 16 | go get $tags $* github.com/axw/gollvm/llvm 17 | -------------------------------------------------------------------------------- /llvm/analysis.go: -------------------------------------------------------------------------------- 1 | package llvm 2 | 3 | /* 4 | #include 5 | #include 6 | */ 7 | import "C" 8 | import "errors" 9 | 10 | type VerifierFailureAction C.LLVMVerifierFailureAction 11 | 12 | const ( 13 | // verifier will print to stderr and abort() 14 | AbortProcessAction VerifierFailureAction = C.LLVMAbortProcessAction 15 | // verifier will print to stderr and return 1 16 | PrintMessageAction VerifierFailureAction = C.LLVMPrintMessageAction 17 | // verifier will just return 1 18 | ReturnStatusAction VerifierFailureAction = C.LLVMReturnStatusAction 19 | ) 20 | 21 | // Verifies that a module is valid, taking the specified action if not. 22 | // Optionally returns a human-readable description of any invalid constructs. 23 | func VerifyModule(m Module, a VerifierFailureAction) error { 24 | var cmsg *C.char 25 | broken := C.LLVMVerifyModule(m.C, C.LLVMVerifierFailureAction(a), &cmsg) 26 | 27 | // C++'s verifyModule means isModuleBroken, so it returns false if 28 | // there are no errors 29 | if broken != 0 { 30 | err := errors.New(C.GoString(cmsg)) 31 | C.LLVMDisposeMessage(cmsg) 32 | return err 33 | } 34 | return nil 35 | } 36 | 37 | var verifyFunctionError = errors.New("Function is broken") 38 | 39 | // Verifies that a single function is valid, taking the specified action. 40 | // Useful for debugging. 41 | func VerifyFunction(f Value, a VerifierFailureAction) error { 42 | broken := C.LLVMVerifyFunction(f.C, C.LLVMVerifierFailureAction(a)) 43 | 44 | // C++'s verifyFunction means isFunctionBroken, so it returns false if 45 | // there are no errors 46 | if broken != 0 { 47 | return verifyFunctionError 48 | } 49 | return nil 50 | } 51 | 52 | // Open up a ghostview window that displays the CFG of the current function. 53 | // Useful for debugging. 54 | func ViewFunctionCFG(f Value) { C.LLVMViewFunctionCFG(f.C) } 55 | func ViewFunctionCFGOnly(f Value) { C.LLVMViewFunctionCFGOnly(f.C) } 56 | -------------------------------------------------------------------------------- /llvm/bitreader.go: -------------------------------------------------------------------------------- 1 | package llvm 2 | 3 | /* 4 | #include 5 | #include 6 | */ 7 | import "C" 8 | 9 | import ( 10 | "errors" 11 | "unsafe" 12 | ) 13 | 14 | // ParseBitcodeFile parses the LLVM IR (bitcode) in the file with the 15 | // specified name, and returns a new LLVM module. 16 | func ParseBitcodeFile(name string) (Module, error) { 17 | var buf C.LLVMMemoryBufferRef 18 | var errmsg *C.char 19 | var cfilename *C.char = C.CString(name) 20 | result := C.LLVMCreateMemoryBufferWithContentsOfFile(cfilename, &buf, &errmsg) 21 | C.free(unsafe.Pointer(cfilename)) 22 | if result != 0 { 23 | err := errors.New(C.GoString(errmsg)) 24 | C.free(unsafe.Pointer(errmsg)) 25 | return Module{}, err 26 | } 27 | defer C.LLVMDisposeMemoryBuffer(buf) 28 | 29 | var m Module 30 | if C.LLVMParseBitcode(buf, &m.C, &errmsg) == 0 { 31 | return m, nil 32 | } 33 | 34 | err := errors.New(C.GoString(errmsg)) 35 | C.free(unsafe.Pointer(errmsg)) 36 | return Module{nil}, err 37 | } 38 | -------------------------------------------------------------------------------- /llvm/bitwriter.go: -------------------------------------------------------------------------------- 1 | package llvm 2 | 3 | /* 4 | #include 5 | #include 6 | */ 7 | import "C" 8 | import "os" 9 | import "errors" 10 | 11 | var writeBitcodeToFileErr = errors.New("Failed to write bitcode to file") 12 | 13 | func WriteBitcodeToFile(m Module, file *os.File) error { 14 | fail := C.LLVMWriteBitcodeToFD(m.C, C.int(file.Fd()), C.int(0), C.int(0)) 15 | if fail != 0 { 16 | return writeBitcodeToFileErr 17 | } 18 | return nil 19 | } 20 | 21 | // TODO(nsf): Figure out way how to make it work with io.Writer 22 | -------------------------------------------------------------------------------- /llvm/debug.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011, 2012 Andrew Wilkins 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | this software and associated documentation files (the "Software"), to deal in 6 | the Software without restriction, including without limitation the rights to 7 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8 | of the Software, and to permit persons to whom the Software is furnished to do 9 | so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | */ 22 | 23 | package llvm 24 | 25 | import ( 26 | "path" 27 | "reflect" 28 | ) 29 | 30 | /////////////////////////////////////////////////////////////////////////////// 31 | // Common types and constants. 32 | 33 | const ( 34 | LLVMDebugVersion = (12 << 16) 35 | ) 36 | 37 | type DwarfTag uint32 38 | 39 | const ( 40 | DW_TAG_lexical_block DwarfTag = 0x0b 41 | DW_TAG_compile_unit DwarfTag = 0x11 42 | DW_TAG_variable DwarfTag = 0x34 43 | DW_TAG_base_type DwarfTag = 0x24 44 | DW_TAG_pointer_type DwarfTag = 0x0F 45 | DW_TAG_structure_type DwarfTag = 0x13 46 | DW_TAG_subroutine_type DwarfTag = 0x15 47 | DW_TAG_file_type DwarfTag = 0x29 48 | DW_TAG_subprogram DwarfTag = 0x2E 49 | DW_TAG_auto_variable DwarfTag = 0x100 50 | DW_TAG_arg_variable DwarfTag = 0x101 51 | ) 52 | 53 | const ( 54 | FlagPrivate = 1 << iota 55 | FlagProtected 56 | FlagFwdDecl 57 | FlagAppleBlock 58 | FlagBlockByrefStruct 59 | FlagVirtual 60 | FlagArtificial 61 | FlagExplicit 62 | FlagPrototyped 63 | FlagObjcClassComplete 64 | FlagObjectPointer 65 | FlagVector 66 | FlagStaticMember 67 | FlagIndirectVariable 68 | ) 69 | 70 | type DwarfLang uint32 71 | 72 | const ( 73 | // http://dwarfstd.org/ShowIssue.php?issue=101014.1&type=open 74 | DW_LANG_Go DwarfLang = 0x0016 75 | ) 76 | 77 | type DwarfTypeEncoding uint32 78 | 79 | const ( 80 | DW_ATE_address DwarfTypeEncoding = 0x01 81 | DW_ATE_boolean DwarfTypeEncoding = 0x02 82 | DW_ATE_complex_float DwarfTypeEncoding = 0x03 83 | DW_ATE_float DwarfTypeEncoding = 0x04 84 | DW_ATE_signed DwarfTypeEncoding = 0x05 85 | DW_ATE_signed_char DwarfTypeEncoding = 0x06 86 | DW_ATE_unsigned DwarfTypeEncoding = 0x07 87 | DW_ATE_unsigned_char DwarfTypeEncoding = 0x08 88 | DW_ATE_imaginary_float DwarfTypeEncoding = 0x09 89 | DW_ATE_packed_decimal DwarfTypeEncoding = 0x0a 90 | DW_ATE_numeric_string DwarfTypeEncoding = 0x0b 91 | DW_ATE_edited DwarfTypeEncoding = 0x0c 92 | DW_ATE_signed_fixed DwarfTypeEncoding = 0x0d 93 | DW_ATE_unsigned_fixed DwarfTypeEncoding = 0x0e 94 | DW_ATE_decimal_float DwarfTypeEncoding = 0x0f 95 | DW_ATE_UTF DwarfTypeEncoding = 0x10 96 | DW_ATE_lo_user DwarfTypeEncoding = 0x80 97 | DW_ATE_hi_user DwarfTypeEncoding = 0xff 98 | ) 99 | 100 | type DebugInfo struct { 101 | cache map[DebugDescriptor]Value 102 | } 103 | 104 | type DebugDescriptor interface { 105 | // Tag returns the DWARF tag for this descriptor. 106 | Tag() DwarfTag 107 | 108 | // mdNode creates an LLVM metadata node. 109 | mdNode(i *DebugInfo) Value 110 | } 111 | 112 | /////////////////////////////////////////////////////////////////////////////// 113 | // Utility functions. 114 | 115 | func constInt1(v bool) Value { 116 | if v { 117 | return ConstAllOnes(Int1Type()) 118 | } 119 | return ConstNull(Int1Type()) 120 | } 121 | 122 | func (info *DebugInfo) MDNode(d DebugDescriptor) Value { 123 | // A nil pointer assigned to an interface does not result in a nil 124 | // interface. Instead, we must check the innards. 125 | if d == nil || reflect.ValueOf(d).IsNil() { 126 | return Value{nil} 127 | } 128 | 129 | if info.cache == nil { 130 | info.cache = make(map[DebugDescriptor]Value) 131 | } 132 | value, exists := info.cache[d] 133 | if !exists { 134 | value = d.mdNode(info) 135 | info.cache[d] = value 136 | } 137 | return value 138 | } 139 | 140 | func (info *DebugInfo) MDNodes(d []DebugDescriptor) []Value { 141 | if n := len(d); n > 0 { 142 | v := make([]Value, n) 143 | for i := 0; i < n; i++ { 144 | v[i] = info.MDNode(d[i]) 145 | } 146 | return v 147 | } 148 | return nil 149 | } 150 | 151 | /////////////////////////////////////////////////////////////////////////////// 152 | // Basic Types 153 | 154 | type BasicTypeDescriptor struct { 155 | Context DebugDescriptor 156 | Name string 157 | File *FileDescriptor 158 | Line uint32 159 | Size uint64 // Size in bits. 160 | Alignment uint64 // Alignment in bits. 161 | Offset uint64 // Offset in bits 162 | Flags uint32 163 | TypeEncoding DwarfTypeEncoding 164 | } 165 | 166 | func (d *BasicTypeDescriptor) Tag() DwarfTag { 167 | return DW_TAG_base_type 168 | } 169 | 170 | func (d *BasicTypeDescriptor) mdNode(info *DebugInfo) Value { 171 | return MDNode([]Value{ 172 | ConstInt(Int32Type(), LLVMDebugVersion+uint64(d.Tag()), false), 173 | info.MDNode(d.File), 174 | info.MDNode(d.Context), 175 | MDString(d.Name), 176 | ConstInt(Int32Type(), uint64(d.Line), false), 177 | ConstInt(Int64Type(), d.Size, false), 178 | ConstInt(Int64Type(), d.Alignment, false), 179 | ConstInt(Int64Type(), d.Offset, false), 180 | ConstInt(Int32Type(), uint64(d.Flags), false), 181 | ConstInt(Int32Type(), uint64(d.TypeEncoding), false)}) 182 | } 183 | 184 | /////////////////////////////////////////////////////////////////////////////// 185 | // Composite Types 186 | 187 | type CompositeTypeDescriptor struct { 188 | tag DwarfTag 189 | Context DebugDescriptor 190 | Name string 191 | File *FileDescriptor 192 | Line uint32 193 | Size uint64 // Size in bits. 194 | Alignment uint64 // Alignment in bits. 195 | Offset uint64 // Offset in bits 196 | Flags uint32 197 | Members []DebugDescriptor 198 | } 199 | 200 | func (d *CompositeTypeDescriptor) Tag() DwarfTag { 201 | return d.tag 202 | } 203 | 204 | func (d *CompositeTypeDescriptor) mdNode(info *DebugInfo) Value { 205 | return MDNode([]Value{ 206 | ConstInt(Int32Type(), LLVMDebugVersion+uint64(d.Tag()), false), 207 | info.MDNode(d.File), 208 | info.MDNode(d.Context), 209 | MDString(d.Name), 210 | ConstInt(Int32Type(), uint64(d.Line), false), 211 | ConstInt(Int64Type(), d.Size, false), 212 | ConstInt(Int64Type(), d.Alignment, false), 213 | ConstInt(Int64Type(), d.Offset, false), 214 | ConstInt(Int32Type(), uint64(d.Flags), false), 215 | info.MDNode(nil), // reference type derived from 216 | MDNode(info.MDNodes(d.Members)), 217 | ConstInt(Int32Type(), uint64(0), false), // Runtime language 218 | ConstInt(Int32Type(), uint64(0), false), // Base type containing the vtable pointer for this type 219 | }) 220 | } 221 | 222 | func NewStructCompositeType( 223 | Members []DebugDescriptor) *CompositeTypeDescriptor { 224 | d := new(CompositeTypeDescriptor) 225 | d.tag = DW_TAG_structure_type 226 | d.Members = Members // XXX Take a copy? 227 | return d 228 | } 229 | 230 | func NewSubroutineCompositeType( 231 | Result DebugDescriptor, 232 | Params []DebugDescriptor) *CompositeTypeDescriptor { 233 | d := new(CompositeTypeDescriptor) 234 | d.tag = DW_TAG_subroutine_type 235 | d.Members = make([]DebugDescriptor, len(Params)+1) 236 | d.Members[0] = Result 237 | copy(d.Members[1:], Params) 238 | return d 239 | } 240 | 241 | /////////////////////////////////////////////////////////////////////////////// 242 | // Compilation Unit 243 | 244 | type CompileUnitDescriptor struct { 245 | Path FileDescriptor // Path to file being compiled. 246 | Language DwarfLang 247 | Producer string 248 | Optimized bool 249 | CompilerFlags string 250 | Runtime int32 251 | EnumTypes []DebugDescriptor 252 | RetainedTypes []DebugDescriptor 253 | Subprograms []DebugDescriptor 254 | GlobalVariables []DebugDescriptor 255 | } 256 | 257 | func (d *CompileUnitDescriptor) Tag() DwarfTag { 258 | return DW_TAG_compile_unit 259 | } 260 | 261 | func (d *CompileUnitDescriptor) mdNode(info *DebugInfo) Value { 262 | return MDNode([]Value{ 263 | ConstInt(Int32Type(), uint64(d.Tag())+LLVMDebugVersion, false), 264 | d.Path.mdNode(nil), 265 | ConstInt(Int32Type(), uint64(d.Language), false), 266 | MDString(d.Producer), 267 | constInt1(d.Optimized), 268 | MDString(d.CompilerFlags), 269 | ConstInt(Int32Type(), uint64(d.Runtime), false), 270 | MDNode(info.MDNodes(d.EnumTypes)), 271 | MDNode(info.MDNodes(d.RetainedTypes)), 272 | MDNode(info.MDNodes(d.Subprograms)), 273 | MDNode(info.MDNodes(d.GlobalVariables)), 274 | MDNode(nil), // List of imported entities 275 | MDString(""), // Split debug filename 276 | }) 277 | } 278 | 279 | /////////////////////////////////////////////////////////////////////////////// 280 | // Derived Types 281 | 282 | type DerivedTypeDescriptor struct { 283 | tag DwarfTag 284 | Context DebugDescriptor 285 | Name string 286 | File *FileDescriptor 287 | Line uint32 288 | Size uint64 // Size in bits. 289 | Alignment uint64 // Alignment in bits. 290 | Offset uint64 // Offset in bits 291 | Flags uint32 292 | Base DebugDescriptor 293 | } 294 | 295 | func (d *DerivedTypeDescriptor) Tag() DwarfTag { 296 | return d.tag 297 | } 298 | 299 | func (d *DerivedTypeDescriptor) mdNode(info *DebugInfo) Value { 300 | return MDNode([]Value{ 301 | ConstInt(Int32Type(), LLVMDebugVersion+uint64(d.Tag()), false), 302 | info.MDNode(d.File), 303 | info.MDNode(d.Context), 304 | MDString(d.Name), 305 | ConstInt(Int32Type(), uint64(d.Line), false), 306 | ConstInt(Int64Type(), d.Size, false), 307 | ConstInt(Int64Type(), d.Alignment, false), 308 | ConstInt(Int64Type(), d.Offset, false), 309 | ConstInt(Int32Type(), uint64(d.Flags), false), 310 | info.MDNode(d.Base)}) 311 | } 312 | 313 | func NewPointerDerivedType(Base DebugDescriptor) *DerivedTypeDescriptor { 314 | d := new(DerivedTypeDescriptor) 315 | d.tag = DW_TAG_pointer_type 316 | d.Base = Base 317 | return d 318 | } 319 | 320 | /////////////////////////////////////////////////////////////////////////////// 321 | // Subprograms. 322 | 323 | type SubprogramDescriptor struct { 324 | Context DebugDescriptor 325 | Name string 326 | DisplayName string 327 | Type DebugDescriptor 328 | Line uint32 329 | Function Value 330 | Path FileDescriptor 331 | ScopeLine uint32 332 | // Function declaration descriptor 333 | // Function variables 334 | } 335 | 336 | func (d *SubprogramDescriptor) Tag() DwarfTag { 337 | return DW_TAG_subprogram 338 | } 339 | 340 | func (d *SubprogramDescriptor) mdNode(info *DebugInfo) Value { 341 | return MDNode([]Value{ 342 | ConstInt(Int32Type(), LLVMDebugVersion+uint64(d.Tag()), false), 343 | d.Path.mdNode(nil), 344 | info.MDNode(d.Context), 345 | MDString(d.Name), 346 | MDString(d.DisplayName), 347 | MDString(""), // mips linkage name 348 | ConstInt(Int32Type(), uint64(d.Line), false), 349 | info.MDNode(d.Type), 350 | ConstNull(Int1Type()), // not static 351 | ConstAllOnes(Int1Type()), // locally defined (not extern) 352 | ConstNull(Int32Type()), // virtuality 353 | ConstNull(Int32Type()), // index into a virtual function 354 | info.MDNode(nil), // basetype containing the vtable pointer 355 | ConstInt(Int32Type(), FlagPrototyped, false), // flags 356 | ConstNull(Int1Type()), // not optimised 357 | d.Function, 358 | info.MDNode(nil), // Template parameters 359 | info.MDNode(nil), // function declaration descriptor 360 | MDNode(nil), // function variables 361 | ConstInt(Int32Type(), uint64(d.ScopeLine), false), // Line number where the scope of the subprogram begins 362 | }) 363 | } 364 | 365 | /////////////////////////////////////////////////////////////////////////////// 366 | // Global Variables. 367 | 368 | type GlobalVariableDescriptor struct { 369 | Context DebugDescriptor 370 | Name string 371 | DisplayName string 372 | File *FileDescriptor 373 | Line uint32 374 | Type DebugDescriptor 375 | Local bool 376 | External bool 377 | Value Value 378 | } 379 | 380 | func (d *GlobalVariableDescriptor) Tag() DwarfTag { 381 | return DW_TAG_variable 382 | } 383 | 384 | func (d *GlobalVariableDescriptor) mdNode(info *DebugInfo) Value { 385 | return MDNode([]Value{ 386 | ConstInt(Int32Type(), uint64(d.Tag())+LLVMDebugVersion, false), 387 | ConstNull(Int32Type()), 388 | info.MDNode(d.Context), 389 | MDString(d.Name), 390 | MDString(d.DisplayName), 391 | MDNode(nil), 392 | info.MDNode(d.File), 393 | ConstInt(Int32Type(), uint64(d.Line), false), 394 | info.MDNode(d.Type), 395 | constInt1(d.Local), 396 | constInt1(!d.External), 397 | d.Value}) 398 | } 399 | 400 | /////////////////////////////////////////////////////////////////////////////// 401 | // Local Variables. 402 | 403 | type LocalVariableDescriptor struct { 404 | tag DwarfTag 405 | Context DebugDescriptor 406 | Name string 407 | File DebugDescriptor 408 | Line uint32 409 | Argument uint32 410 | Type DebugDescriptor 411 | } 412 | 413 | func (d *LocalVariableDescriptor) Tag() DwarfTag { 414 | return d.tag 415 | } 416 | 417 | func (d *LocalVariableDescriptor) mdNode(info *DebugInfo) Value { 418 | return MDNode([]Value{ 419 | ConstInt(Int32Type(), uint64(d.Tag())+LLVMDebugVersion, false), 420 | info.MDNode(d.Context), 421 | MDString(d.Name), 422 | info.MDNode(d.File), 423 | ConstInt(Int32Type(), uint64(d.Line)|(uint64(d.Argument)<<24), false), 424 | info.MDNode(d.Type), 425 | ConstNull(Int32Type()), // flags 426 | ConstNull(Int32Type()), // optional reference to inline location 427 | }) 428 | } 429 | 430 | func NewLocalVariableDescriptor(tag DwarfTag) *LocalVariableDescriptor { 431 | return &LocalVariableDescriptor{tag: tag} 432 | } 433 | 434 | /////////////////////////////////////////////////////////////////////////////// 435 | // Files. 436 | 437 | type FileDescriptor string 438 | 439 | func (d *FileDescriptor) Tag() DwarfTag { 440 | return DW_TAG_file_type 441 | } 442 | 443 | func (d *FileDescriptor) mdNode(info *DebugInfo) Value { 444 | dirname, filename := path.Split(string(*d)) 445 | if l := len(dirname); l > 0 && dirname[l-1] == '/' { 446 | dirname = dirname[:l-1] 447 | } 448 | return MDNode([]Value{MDString(filename), MDString(dirname)}) 449 | } 450 | 451 | /////////////////////////////////////////////////////////////////////////////// 452 | // Line. 453 | 454 | type LineDescriptor struct { 455 | Line uint32 456 | Column uint32 457 | Context DebugDescriptor 458 | } 459 | 460 | func (d *LineDescriptor) Tag() DwarfTag { 461 | panic("LineDescriptor.Tag should never be called") 462 | } 463 | 464 | func (d *LineDescriptor) mdNode(info *DebugInfo) Value { 465 | return MDNode([]Value{ 466 | ConstInt(Int32Type(), uint64(d.Line), false), 467 | ConstInt(Int32Type(), uint64(d.Column), false), 468 | info.MDNode(d.Context), 469 | info.MDNode(nil), 470 | }) 471 | } 472 | 473 | /////////////////////////////////////////////////////////////////////////////// 474 | // Context. 475 | 476 | type ContextDescriptor struct{ FileDescriptor } 477 | 478 | func (d *ContextDescriptor) mdNode(info *DebugInfo) Value { 479 | return MDNode([]Value{ConstInt(Int32Type(), uint64(d.Tag())+LLVMDebugVersion, false), d.FileDescriptor.mdNode(info)}) 480 | } 481 | 482 | /////////////////////////////////////////////////////////////////////////////// 483 | // Block. 484 | 485 | type BlockDescriptor struct { 486 | File *FileDescriptor 487 | Context DebugDescriptor 488 | Line uint32 489 | Column uint32 490 | Id uint32 491 | } 492 | 493 | func (d *BlockDescriptor) Tag() DwarfTag { 494 | return DW_TAG_lexical_block 495 | } 496 | 497 | func (d *BlockDescriptor) mdNode(info *DebugInfo) Value { 498 | return MDNode([]Value{ 499 | ConstInt(Int32Type(), uint64(d.Tag())+LLVMDebugVersion, false), 500 | info.MDNode(d.File), 501 | info.MDNode(d.Context), 502 | ConstInt(Int32Type(), uint64(d.Line), false), 503 | ConstInt(Int32Type(), uint64(d.Column), false), 504 | ConstInt(Int32Type(), uint64(d.Id), false), 505 | }) 506 | } 507 | 508 | // vim: set ft=go : 509 | -------------------------------------------------------------------------------- /llvm/executionengine.go: -------------------------------------------------------------------------------- 1 | package llvm 2 | 3 | /* 4 | #include 5 | #include 6 | */ 7 | import "C" 8 | import "unsafe" 9 | import "errors" 10 | 11 | func LinkInJIT() { C.LLVMLinkInJIT() } 12 | func LinkInInterpreter() { C.LLVMLinkInInterpreter() } 13 | 14 | type ( 15 | GenericValue struct { 16 | C C.LLVMGenericValueRef 17 | } 18 | ExecutionEngine struct { 19 | C C.LLVMExecutionEngineRef 20 | } 21 | ) 22 | 23 | // helpers 24 | func llvmGenericValueRefPtr(t *GenericValue) *C.LLVMGenericValueRef { 25 | return (*C.LLVMGenericValueRef)(unsafe.Pointer(t)) 26 | } 27 | 28 | //------------------------------------------------------------------------- 29 | // llvm.GenericValue 30 | //------------------------------------------------------------------------- 31 | 32 | func NewGenericValueFromInt(t Type, n uint64, signed bool) (g GenericValue) { 33 | g.C = C.LLVMCreateGenericValueOfInt(t.C, C.ulonglong(n), boolToLLVMBool(signed)) 34 | return 35 | } 36 | func NewGenericValueFromPointer(p unsafe.Pointer) (g GenericValue) { 37 | g.C = C.LLVMCreateGenericValueOfPointer(p) 38 | return 39 | } 40 | func NewGenericValueFromFloat(t Type, n float64) (g GenericValue) { 41 | g.C = C.LLVMCreateGenericValueOfFloat(t.C, C.double(n)) 42 | return 43 | } 44 | func (g GenericValue) IntWidth() int { return int(C.LLVMGenericValueIntWidth(g.C)) } 45 | func (g GenericValue) Int(signed bool) uint64 { 46 | return uint64(C.LLVMGenericValueToInt(g.C, boolToLLVMBool(signed))) 47 | } 48 | func (g GenericValue) Float(t Type) float64 { 49 | return float64(C.LLVMGenericValueToFloat(t.C, g.C)) 50 | } 51 | func (g GenericValue) Pointer() unsafe.Pointer { 52 | return C.LLVMGenericValueToPointer(g.C) 53 | } 54 | func (g GenericValue) Dispose() { C.LLVMDisposeGenericValue(g.C) } 55 | 56 | //------------------------------------------------------------------------- 57 | // llvm.ExecutionEngine 58 | //------------------------------------------------------------------------- 59 | 60 | func NewExecutionEngine(m Module) (ee ExecutionEngine, err error) { 61 | var cmsg *C.char 62 | fail := C.LLVMCreateExecutionEngineForModule(&ee.C, m.C, &cmsg) 63 | if fail != 0 { 64 | ee.C = nil 65 | err = errors.New(C.GoString(cmsg)) 66 | C.LLVMDisposeMessage(cmsg) 67 | } else { 68 | err = nil 69 | } 70 | return 71 | } 72 | 73 | func NewInterpreter(m Module) (ee ExecutionEngine, err error) { 74 | var cmsg *C.char 75 | fail := C.LLVMCreateInterpreterForModule(&ee.C, m.C, &cmsg) 76 | if fail != 0 { 77 | ee.C = nil 78 | err = errors.New(C.GoString(cmsg)) 79 | C.LLVMDisposeMessage(cmsg) 80 | } else { 81 | err = nil 82 | } 83 | return 84 | } 85 | func NewJITCompiler(m Module, optLevel int) (ee ExecutionEngine, err error) { 86 | var cmsg *C.char 87 | fail := C.LLVMCreateJITCompilerForModule(&ee.C, m.C, C.unsigned(optLevel), &cmsg) 88 | if fail != 0 { 89 | ee.C = nil 90 | err = errors.New(C.GoString(cmsg)) 91 | C.LLVMDisposeMessage(cmsg) 92 | } else { 93 | err = nil 94 | } 95 | return 96 | } 97 | 98 | // XXX: Don't port deprecated 99 | // Deprecated: Use LLVMCreateExecutionEngineForModule instead. 100 | //LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE, 101 | // LLVMModuleProviderRef MP, 102 | // char **OutError); 103 | 104 | // Deprecated: Use LLVMCreateInterpreterForModule instead. 105 | //LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp, 106 | // LLVMModuleProviderRef MP, 107 | // char **OutError); 108 | 109 | // Deprecated: Use LLVMCreateJITCompilerForModule instead. 110 | //LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT, 111 | // LLVMModuleProviderRef MP, 112 | // unsigned OptLevel, 113 | // char **OutError); 114 | 115 | func (ee ExecutionEngine) Dispose() { C.LLVMDisposeExecutionEngine(ee.C) } 116 | func (ee ExecutionEngine) RunStaticConstructors() { C.LLVMRunStaticConstructors(ee.C) } 117 | func (ee ExecutionEngine) RunStaticDestructors() { C.LLVMRunStaticDestructors(ee.C) } 118 | 119 | // TODO(nsf): figure out how to convert that stuff from Go's "os.Argv" 120 | //int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F, 121 | // unsigned ArgC, const char * const *ArgV, 122 | // const char * const *EnvP); 123 | 124 | func (ee ExecutionEngine) RunFunction(f Value, args []GenericValue) (g GenericValue) { 125 | nargs := len(args) 126 | var argptr *GenericValue 127 | if nargs > 0 { 128 | argptr = &args[0] 129 | } 130 | g.C = C.LLVMRunFunction(ee.C, f.C, 131 | C.unsigned(nargs), llvmGenericValueRefPtr(argptr)) 132 | return 133 | } 134 | 135 | func (ee ExecutionEngine) FreeMachineCodeForFunction(f Value) { 136 | C.LLVMFreeMachineCodeForFunction(ee.C, f.C) 137 | } 138 | func (ee ExecutionEngine) AddModule(m Module) { C.LLVMAddModule(ee.C, m.C) } 139 | 140 | // XXX(nsf): Don't port deprecated 141 | // Deprecated: Use LLVMAddModule instead. 142 | //void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP); 143 | 144 | func (ee ExecutionEngine) RemoveModule(m Module) { 145 | var modtmp C.LLVMModuleRef 146 | C.LLVMRemoveModule(ee.C, m.C, &modtmp, nil) 147 | } 148 | 149 | // XXX(nsf): Don't port deprecated 150 | // Deprecated: Use LLVMRemoveModule instead. 151 | //LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE, 152 | // LLVMModuleProviderRef MP, 153 | // LLVMModuleRef *OutMod, char **OutError); 154 | 155 | func (ee ExecutionEngine) FindFunction(name string) (f Value) { 156 | cname := C.CString(name) 157 | C.LLVMFindFunction(ee.C, cname, &f.C) 158 | C.free(unsafe.Pointer(cname)) 159 | return 160 | } 161 | 162 | func (ee ExecutionEngine) RecompileAndRelinkFunction(f Value) unsafe.Pointer { 163 | return C.LLVMRecompileAndRelinkFunction(ee.C, f.C) 164 | } 165 | 166 | func (ee ExecutionEngine) TargetData() (td TargetData) { 167 | td.C = C.LLVMGetExecutionEngineTargetData(ee.C) 168 | return 169 | } 170 | 171 | func (ee ExecutionEngine) AddGlobalMapping(global Value, addr unsafe.Pointer) { 172 | C.LLVMAddGlobalMapping(ee.C, global.C, addr) 173 | } 174 | 175 | func (ee ExecutionEngine) PointerToGlobal(global Value) unsafe.Pointer { 176 | return C.LLVMGetPointerToGlobal(ee.C, global.C) 177 | } 178 | 179 | // vim: set ft=go: 180 | -------------------------------------------------------------------------------- /llvm/executionengine_test.go: -------------------------------------------------------------------------------- 1 | package llvm 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestFactorial(t *testing.T) { 8 | LinkInJIT() 9 | InitializeNativeTarget() 10 | 11 | mod := NewModule("fac_module") 12 | 13 | fac_args := []Type{Int32Type()} 14 | fac_type := FunctionType(Int32Type(), fac_args, false) 15 | fac := AddFunction(mod, "fac", fac_type) 16 | fac.SetFunctionCallConv(CCallConv) 17 | n := fac.Param(0) 18 | 19 | entry := AddBasicBlock(fac, "entry") 20 | iftrue := AddBasicBlock(fac, "iftrue") 21 | iffalse := AddBasicBlock(fac, "iffalse") 22 | end := AddBasicBlock(fac, "end") 23 | 24 | builder := NewBuilder() 25 | defer builder.Dispose() 26 | 27 | builder.SetInsertPointAtEnd(entry) 28 | If := builder.CreateICmp(IntEQ, n, ConstInt(Int32Type(), 0, false), "cmptmp") 29 | builder.CreateCondBr(If, iftrue, iffalse) 30 | 31 | builder.SetInsertPointAtEnd(iftrue) 32 | res_iftrue := ConstInt(Int32Type(), 1, false) 33 | builder.CreateBr(end) 34 | 35 | builder.SetInsertPointAtEnd(iffalse) 36 | n_minus := builder.CreateSub(n, ConstInt(Int32Type(), 1, false), "subtmp") 37 | call_fac_args := []Value{n_minus} 38 | call_fac := builder.CreateCall(fac, call_fac_args, "calltmp") 39 | res_iffalse := builder.CreateMul(n, call_fac, "multmp") 40 | builder.CreateBr(end) 41 | 42 | builder.SetInsertPointAtEnd(end) 43 | res := builder.CreatePHI(Int32Type(), "result") 44 | phi_vals := []Value{res_iftrue, res_iffalse} 45 | phi_blocks := []BasicBlock{iftrue, iffalse} 46 | res.AddIncoming(phi_vals, phi_blocks) 47 | builder.CreateRet(res) 48 | 49 | err := VerifyModule(mod, ReturnStatusAction) 50 | if err != nil { 51 | t.Errorf("Error verifying module: %s", err) 52 | return 53 | } 54 | 55 | engine, err := NewJITCompiler(mod, 2) 56 | if err != nil { 57 | t.Errorf("Error creating JIT: %s", err) 58 | return 59 | } 60 | defer engine.Dispose() 61 | 62 | pass := NewPassManager() 63 | defer pass.Dispose() 64 | 65 | pass.Add(engine.TargetData()) 66 | pass.AddConstantPropagationPass() 67 | pass.AddInstructionCombiningPass() 68 | pass.AddPromoteMemoryToRegisterPass() 69 | pass.AddGVNPass() 70 | pass.AddCFGSimplificationPass() 71 | pass.Run(mod) 72 | 73 | exec_args := []GenericValue{NewGenericValueFromInt(Int32Type(), 10, false)} 74 | exec_res := engine.RunFunction(fac, exec_args) 75 | var fac10 uint64 = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1 76 | if exec_res.Int(false) != fac10 { 77 | t.Errorf("Expected %d, got %d", fac10, exec_res.Int(false)) 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /llvm/linker.go: -------------------------------------------------------------------------------- 1 | // +build llvmsvn llvm3.2 llvm3.3 2 | 3 | package llvm 4 | 5 | /* 6 | #include 7 | #include 8 | */ 9 | import "C" 10 | import "errors" 11 | 12 | type LinkerMode C.LLVMLinkerMode 13 | 14 | const ( 15 | LinkerDestroySource = C.LLVMLinkerDestroySource 16 | LinkerPreserveSource = C.LLVMLinkerPreserveSource 17 | ) 18 | 19 | func LinkModules(Dest, Src Module, Mode LinkerMode) error { 20 | var cmsg *C.char 21 | failed := C.LLVMLinkModules(Dest.C, Src.C, C.LLVMLinkerMode(Mode), &cmsg) 22 | if failed != 0 { 23 | err := errors.New(C.GoString(cmsg)) 24 | C.LLVMDisposeMessage(cmsg) 25 | return err 26 | } 27 | return nil 28 | } 29 | -------------------------------------------------------------------------------- /llvm/string.go: -------------------------------------------------------------------------------- 1 | package llvm 2 | 3 | import "fmt" 4 | 5 | func (t TypeKind) String() string { 6 | switch t { 7 | case VoidTypeKind: 8 | return "VoidTypeKind" 9 | case FloatTypeKind: 10 | return "FloatTypeKind" 11 | case DoubleTypeKind: 12 | return "DoubleTypeKind" 13 | case X86_FP80TypeKind: 14 | return "X86_FP80TypeKind" 15 | case FP128TypeKind: 16 | return "FP128TypeKind" 17 | case PPC_FP128TypeKind: 18 | return "PPC_FP128TypeKind" 19 | case LabelTypeKind: 20 | return "LabelTypeKind" 21 | case IntegerTypeKind: 22 | return "IntegerTypeKind" 23 | case FunctionTypeKind: 24 | return "FunctionTypeKind" 25 | case StructTypeKind: 26 | return "StructTypeKind" 27 | case ArrayTypeKind: 28 | return "ArrayTypeKind" 29 | case PointerTypeKind: 30 | return "PointerTypeKind" 31 | case VectorTypeKind: 32 | return "VectorTypeKind" 33 | case MetadataTypeKind: 34 | return "MetadataTypeKind" 35 | } 36 | panic("unreachable") 37 | } 38 | 39 | func (t Type) String() string { 40 | ts := typeStringer{s: make(map[Type]string)} 41 | return ts.typeString(t) 42 | } 43 | 44 | type typeStringer struct { 45 | s map[Type]string 46 | } 47 | 48 | func (ts *typeStringer) typeString(t Type) string { 49 | if s, ok := ts.s[t]; ok { 50 | return s 51 | } 52 | 53 | k := t.TypeKind() 54 | s := k.String() 55 | s = s[:len(s)-len("Kind")] 56 | 57 | switch k { 58 | case ArrayTypeKind: 59 | s += fmt.Sprintf("(%v[%v])", ts.typeString(t.ElementType()), t.ArrayLength()) 60 | case PointerTypeKind: 61 | s += fmt.Sprintf("(%v)", ts.typeString(t.ElementType())) 62 | case FunctionTypeKind: 63 | params := t.ParamTypes() 64 | s += "(" 65 | if len(params) > 0 { 66 | s += fmt.Sprintf("%v", ts.typeString(params[0])) 67 | for i := 1; i < len(params); i++ { 68 | s += fmt.Sprintf(", %v", ts.typeString(params[i])) 69 | } 70 | } 71 | s += fmt.Sprintf("):%v", ts.typeString(t.ReturnType())) 72 | case StructTypeKind: 73 | if name := t.StructName(); name != "" { 74 | ts.s[t] = "%" + name 75 | s = fmt.Sprintf("%%%s: %s", name, s) 76 | } 77 | etypes := t.StructElementTypes() 78 | s += "(" 79 | if n := len(etypes); n > 0 { 80 | s += ts.typeString(etypes[0]) 81 | for i := 1; i < n; i++ { 82 | s += fmt.Sprintf(", %v", ts.typeString(etypes[i])) 83 | } 84 | } 85 | s += ")" 86 | case IntegerTypeKind: 87 | s += fmt.Sprintf("(%d bits)", t.IntTypeWidth()) 88 | } 89 | 90 | ts.s[t] = s 91 | return s 92 | } 93 | 94 | // vim: set ft=go : 95 | -------------------------------------------------------------------------------- /llvm/string_test.go: -------------------------------------------------------------------------------- 1 | package llvm_test 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/axw/gollvm/llvm" 7 | ) 8 | 9 | func TestStringRecursiveType(t *testing.T) { 10 | //mod := llvm.NewModule("fac_module") 11 | ctx := llvm.NewContext() 12 | defer ctx.Dispose() 13 | s := ctx.StructCreateNamed("recursive") 14 | s.StructSetBody([]llvm.Type{s, s}, false) 15 | if str := s.String(); str != "%recursive: StructType(%recursive, %recursive)" { 16 | t.Errorf("incorrect string result %q", str) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /llvm/target.go: -------------------------------------------------------------------------------- 1 | package llvm 2 | 3 | /* 4 | #include 5 | #include 6 | #include 7 | */ 8 | import "C" 9 | import "unsafe" 10 | import "errors" 11 | 12 | type ( 13 | TargetData struct { 14 | C C.LLVMTargetDataRef 15 | } 16 | Target struct { 17 | C C.LLVMTargetRef 18 | } 19 | TargetMachine struct { 20 | C C.LLVMTargetMachineRef 21 | } 22 | ByteOrdering C.enum_LLVMByteOrdering 23 | RelocMode C.LLVMRelocMode 24 | CodeGenOptLevel C.LLVMCodeGenOptLevel 25 | CodeGenFileType C.LLVMCodeGenFileType 26 | CodeModel C.LLVMCodeModel 27 | ) 28 | 29 | const ( 30 | DefaultTargetTriple string = C.LLVM_DEFAULT_TARGET_TRIPLE 31 | ) 32 | 33 | const ( 34 | BigEndian ByteOrdering = C.LLVMBigEndian 35 | LittleEndian ByteOrdering = C.LLVMLittleEndian 36 | ) 37 | 38 | const ( 39 | RelocDefault RelocMode = C.LLVMRelocDefault 40 | RelocStatic RelocMode = C.LLVMRelocStatic 41 | RelocPIC RelocMode = C.LLVMRelocPIC 42 | RelocDynamicNoPic RelocMode = C.LLVMRelocDynamicNoPic 43 | ) 44 | 45 | const ( 46 | CodeGenLevelNone CodeGenOptLevel = C.LLVMCodeGenLevelNone 47 | CodeGenLevelLess CodeGenOptLevel = C.LLVMCodeGenLevelLess 48 | CodeGenLevelDefault CodeGenOptLevel = C.LLVMCodeGenLevelDefault 49 | CodeGenLevelAggressive CodeGenOptLevel = C.LLVMCodeGenLevelAggressive 50 | ) 51 | 52 | const ( 53 | CodeModelDefault CodeModel = C.LLVMCodeModelDefault 54 | CodeModelJITDefault CodeModel = C.LLVMCodeModelJITDefault 55 | CodeModelSmall CodeModel = C.LLVMCodeModelSmall 56 | CodeModelKernel CodeModel = C.LLVMCodeModelKernel 57 | CodeModelMedium CodeModel = C.LLVMCodeModelMedium 58 | CodeModelLarge CodeModel = C.LLVMCodeModelLarge 59 | ) 60 | 61 | const ( 62 | AssemblyFile CodeGenFileType = C.LLVMAssemblyFile 63 | ObjectFile CodeGenFileType = C.LLVMObjectFile 64 | ) 65 | 66 | // InitializeAllTargetInfos - The main program should call this function if it 67 | // wants access to all available targets that LLVM is configured to support. 68 | func InitializeAllTargetInfos() { C.LLVMInitializeAllTargetInfos() } 69 | 70 | // InitializeAllTargets - The main program should call this function if it wants 71 | // to link in all available targets that LLVM is configured to support. 72 | func InitializeAllTargets() { C.LLVMInitializeAllTargets() } 73 | 74 | func InitializeAllTargetMCs() { C.LLVMInitializeAllTargetMCs() } 75 | 76 | var initializeNativeTargetError = errors.New("Failed to initialize native target") 77 | 78 | // InitializeNativeTarget - The main program should call this function to 79 | // initialize the native target corresponding to the host. This is useful 80 | // for JIT applications to ensure that the target gets linked in correctly. 81 | func InitializeNativeTarget() error { 82 | fail := C.LLVMInitializeNativeTarget() 83 | if fail != 0 { 84 | return initializeNativeTargetError 85 | } 86 | return nil 87 | } 88 | 89 | //------------------------------------------------------------------------- 90 | // llvm.TargetData 91 | //------------------------------------------------------------------------- 92 | 93 | // Creates target data from a target layout string. 94 | // See the constructor llvm::TargetData::TargetData. 95 | func NewTargetData(rep string) (td TargetData) { 96 | crep := C.CString(rep) 97 | td.C = C.LLVMCreateTargetData(crep) 98 | C.free(unsafe.Pointer(crep)) 99 | return 100 | } 101 | 102 | // Adds target data information to a pass manager. This does not take ownership 103 | // of the target data. 104 | // See the method llvm::PassManagerBase::add. 105 | func (pm PassManager) Add(td TargetData) { 106 | C.LLVMAddTargetData(td.C, pm.C) 107 | } 108 | 109 | // Converts target data to a target layout string. The string must be disposed 110 | // with LLVMDisposeMessage. 111 | // See the constructor llvm::TargetData::TargetData. 112 | func (td TargetData) String() (s string) { 113 | cmsg := C.LLVMCopyStringRepOfTargetData(td.C) 114 | s = C.GoString(cmsg) 115 | C.LLVMDisposeMessage(cmsg) 116 | return 117 | } 118 | 119 | // Returns the byte order of a target, either BigEndian or LittleEndian. 120 | // See the method llvm::TargetData::isLittleEndian. 121 | func (td TargetData) ByteOrder() ByteOrdering { return ByteOrdering(C.LLVMByteOrder(td.C)) } 122 | 123 | // Returns the pointer size in bytes for a target. 124 | // See the method llvm::TargetData::getPointerSize. 125 | func (td TargetData) PointerSize() int { return int(C.LLVMPointerSize(td.C)) } 126 | 127 | // Returns the integer type that is the same size as a pointer on a target. 128 | // See the method llvm::TargetData::getIntPtrType. 129 | func (td TargetData) IntPtrType() (t Type) { t.C = C.LLVMIntPtrType(td.C); return } 130 | 131 | // Computes the size of a type in bytes for a target. 132 | // See the method llvm::TargetData::getTypeSizeInBits. 133 | func (td TargetData) TypeSizeInBits(t Type) uint64 { 134 | return uint64(C.LLVMSizeOfTypeInBits(td.C, t.C)) 135 | } 136 | 137 | // Computes the storage size of a type in bytes for a target. 138 | // See the method llvm::TargetData::getTypeStoreSize. 139 | func (td TargetData) TypeStoreSize(t Type) uint64 { 140 | return uint64(C.LLVMStoreSizeOfType(td.C, t.C)) 141 | } 142 | 143 | // Computes the ABI size of a type in bytes for a target. 144 | // See the method llvm::TargetData::getTypeAllocSize. 145 | func (td TargetData) TypeAllocSize(t Type) uint64 { 146 | return uint64(C.LLVMABISizeOfType(td.C, t.C)) 147 | } 148 | 149 | // Computes the ABI alignment of a type in bytes for a target. 150 | // See the method llvm::TargetData::getABITypeAlignment. 151 | func (td TargetData) ABITypeAlignment(t Type) int { 152 | return int(C.LLVMABIAlignmentOfType(td.C, t.C)) 153 | } 154 | 155 | // Computes the call frame alignment of a type in bytes for a target. 156 | // See the method llvm::TargetData::getCallFrameTypeAlignment. 157 | func (td TargetData) CallFrameTypeAlignment(t Type) int { 158 | return int(C.LLVMCallFrameAlignmentOfType(td.C, t.C)) 159 | } 160 | 161 | // Computes the preferred alignment of a type in bytes for a target. 162 | // See the method llvm::TargetData::getPrefTypeAlignment. 163 | func (td TargetData) PrefTypeAlignment(t Type) int { 164 | return int(C.LLVMPreferredAlignmentOfType(td.C, t.C)) 165 | } 166 | 167 | // Computes the preferred alignment of a global variable in bytes for a target. 168 | // See the method llvm::TargetData::getPreferredAlignment. 169 | func (td TargetData) PreferredAlignment(g Value) int { 170 | return int(C.LLVMPreferredAlignmentOfGlobal(td.C, g.C)) 171 | } 172 | 173 | // Computes the structure element that contains the byte offset for a target. 174 | // See the method llvm::StructLayout::getElementContainingOffset. 175 | func (td TargetData) ElementContainingOffset(t Type, offset uint64) int { 176 | return int(C.LLVMElementAtOffset(td.C, t.C, C.ulonglong(offset))) 177 | } 178 | 179 | // Computes the byte offset of the indexed struct element for a target. 180 | // See the method llvm::StructLayout::getElementOffset. 181 | func (td TargetData) ElementOffset(t Type, element int) uint64 { 182 | return uint64(C.LLVMOffsetOfElement(td.C, t.C, C.unsigned(element))) 183 | } 184 | 185 | // Deallocates a TargetData. 186 | // See the destructor llvm::TargetData::~TargetData. 187 | func (td TargetData) Dispose() { C.LLVMDisposeTargetData(td.C) } 188 | 189 | /////////////////////////////////////////////////////////////////////////////// 190 | // Target 191 | 192 | func FirstTarget() Target { 193 | return Target{C.LLVMGetFirstTarget()} 194 | } 195 | 196 | func (t Target) NextTarget() Target { 197 | return Target{C.LLVMGetNextTarget(t.C)} 198 | } 199 | 200 | func (t Target) Name() string { 201 | return C.GoString(C.LLVMGetTargetName(t.C)) 202 | } 203 | 204 | func (t Target) Description() string { 205 | return C.GoString(C.LLVMGetTargetDescription(t.C)) 206 | } 207 | 208 | /////////////////////////////////////////////////////////////////////////////// 209 | // TargetMachine 210 | 211 | // CreateTargetMachine creates a new TargetMachine. 212 | func (t Target) CreateTargetMachine(Triple string, CPU string, Features string, 213 | Level CodeGenOptLevel, Reloc RelocMode, 214 | CodeModel CodeModel) (tm TargetMachine) { 215 | cTriple := C.CString(Triple) 216 | cCPU := C.CString(CPU) 217 | cFeatures := C.CString(Features) 218 | tm.C = C.LLVMCreateTargetMachine(t.C, cTriple, cCPU, cFeatures, 219 | C.LLVMCodeGenOptLevel(Level), 220 | C.LLVMRelocMode(Reloc), 221 | C.LLVMCodeModel(CodeModel)) 222 | C.free(unsafe.Pointer(cTriple)) 223 | C.free(unsafe.Pointer(cCPU)) 224 | C.free(unsafe.Pointer(cFeatures)) 225 | return 226 | } 227 | 228 | // Triple returns the triple describing the machine (arch-vendor-os). 229 | func (tm TargetMachine) Triple() string { 230 | cstr := C.LLVMGetTargetMachineTriple(tm.C) 231 | return C.GoString(cstr) 232 | } 233 | 234 | // TargetData returns the TargetData for the machine. 235 | func (tm TargetMachine) TargetData() TargetData { 236 | return TargetData{C.LLVMGetTargetMachineData(tm.C)} 237 | } 238 | 239 | // Dispose releases resources related to the TargetMachine. 240 | func (tm TargetMachine) Dispose() { 241 | C.LLVMDisposeTargetMachine(tm.C) 242 | } 243 | -------------------------------------------------------------------------------- /llvm/transforms_ipo.go: -------------------------------------------------------------------------------- 1 | package llvm 2 | 3 | /* 4 | #include 5 | */ 6 | import "C" 7 | 8 | // helpers 9 | func boolToUnsigned(b bool) C.unsigned { 10 | if b { 11 | return 1 12 | } 13 | return 0 14 | } 15 | 16 | func (pm PassManager) AddArgumentPromotionPass() { C.LLVMAddArgumentPromotionPass(pm.C) } 17 | func (pm PassManager) AddConstantMergePass() { C.LLVMAddConstantMergePass(pm.C) } 18 | func (pm PassManager) AddDeadArgEliminationPass() { C.LLVMAddDeadArgEliminationPass(pm.C) } 19 | func (pm PassManager) AddFunctionAttrsPass() { C.LLVMAddFunctionAttrsPass(pm.C) } 20 | func (pm PassManager) AddFunctionInliningPass() { C.LLVMAddFunctionInliningPass(pm.C) } 21 | func (pm PassManager) AddGlobalDCEPass() { C.LLVMAddGlobalDCEPass(pm.C) } 22 | func (pm PassManager) AddGlobalOptimizerPass() { C.LLVMAddGlobalOptimizerPass(pm.C) } 23 | func (pm PassManager) AddIPConstantPropagationPass() { C.LLVMAddIPConstantPropagationPass(pm.C) } 24 | func (pm PassManager) AddPruneEHPass() { C.LLVMAddPruneEHPass(pm.C) } 25 | func (pm PassManager) AddIPSCCPPass() { C.LLVMAddIPSCCPPass(pm.C) } 26 | func (pm PassManager) AddInternalizePass(allButMain bool) { 27 | C.LLVMAddInternalizePass(pm.C, boolToUnsigned(allButMain)) 28 | } 29 | func (pm PassManager) AddStripDeadPrototypesPass() { C.LLVMAddStripDeadPrototypesPass(pm.C) } 30 | -------------------------------------------------------------------------------- /llvm/transforms_scalar.go: -------------------------------------------------------------------------------- 1 | package llvm 2 | 3 | /* 4 | #include 5 | */ 6 | import "C" 7 | 8 | func (pm PassManager) AddAggressiveDCEPass() { C.LLVMAddAggressiveDCEPass(pm.C) } 9 | func (pm PassManager) AddCFGSimplificationPass() { C.LLVMAddCFGSimplificationPass(pm.C) } 10 | func (pm PassManager) AddDeadStoreEliminationPass() { C.LLVMAddDeadStoreEliminationPass(pm.C) } 11 | func (pm PassManager) AddGVNPass() { C.LLVMAddGVNPass(pm.C) } 12 | func (pm PassManager) AddIndVarSimplifyPass() { C.LLVMAddIndVarSimplifyPass(pm.C) } 13 | func (pm PassManager) AddInstructionCombiningPass() { C.LLVMAddInstructionCombiningPass(pm.C) } 14 | func (pm PassManager) AddJumpThreadingPass() { C.LLVMAddJumpThreadingPass(pm.C) } 15 | func (pm PassManager) AddLICMPass() { C.LLVMAddLICMPass(pm.C) } 16 | func (pm PassManager) AddLoopDeletionPass() { C.LLVMAddLoopDeletionPass(pm.C) } 17 | func (pm PassManager) AddLoopRotatePass() { C.LLVMAddLoopRotatePass(pm.C) } 18 | func (pm PassManager) AddLoopUnrollPass() { C.LLVMAddLoopUnrollPass(pm.C) } 19 | func (pm PassManager) AddLoopUnswitchPass() { C.LLVMAddLoopUnswitchPass(pm.C) } 20 | func (pm PassManager) AddMemCpyOptPass() { C.LLVMAddMemCpyOptPass(pm.C) } 21 | func (pm PassManager) AddPromoteMemoryToRegisterPass() { C.LLVMAddPromoteMemoryToRegisterPass(pm.C) } 22 | func (pm PassManager) AddReassociatePass() { C.LLVMAddReassociatePass(pm.C) } 23 | func (pm PassManager) AddSCCPPass() { C.LLVMAddSCCPPass(pm.C) } 24 | func (pm PassManager) AddScalarReplAggregatesPass() { C.LLVMAddScalarReplAggregatesPass(pm.C) } 25 | func (pm PassManager) AddScalarReplAggregatesPassWithThreshold(threshold int) { 26 | C.LLVMAddScalarReplAggregatesPassWithThreshold(pm.C, C.int(threshold)) 27 | } 28 | func (pm PassManager) AddSimplifyLibCallsPass() { C.LLVMAddSimplifyLibCallsPass(pm.C) } 29 | func (pm PassManager) AddTailCallEliminationPass() { C.LLVMAddTailCallEliminationPass(pm.C) } 30 | func (pm PassManager) AddConstantPropagationPass() { C.LLVMAddConstantPropagationPass(pm.C) } 31 | func (pm PassManager) AddDemoteMemoryToRegisterPass() { C.LLVMAddDemoteMemoryToRegisterPass(pm.C) } 32 | func (pm PassManager) AddVerifierPass() { C.LLVMAddVerifierPass(pm.C) } 33 | --------------------------------------------------------------------------------