Browse files

Trying Jens Mueller LLVM binding.

  • Loading branch information...
1 parent a8a07dc commit 8e3b53a1040db672c16fd0685bd0e6fd7d075b48 @mlarouche committed Jul 21, 2012
View
10 Makefile
@@ -2,13 +2,7 @@ FILES=\
main.d
LLVM_LIBS=`llvm-config --libs | sed 's/-l/-L-l/g'`
-LLVM_OBJ=llvmExt.o llvmTarget.o
+LLVM_OBJ=
-main: llvmExt.o llvmTarget.o $(FILES)
+main: $(FILES)
dmd -ofmain -L-L/usr/local/lib -L-ldl -L-lstdc++ $(FLAGS) -fPIC $(FILES) $(LLVM_LIBS) $(LLVM_OBJ)
-
-llvmExt.o:
- g++ llvm/Ext.cpp -c -I$LLVM_DIR/include -o llvmExt.o -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS
-
-llvmTarget.o:
- g++ llvm/Target.cpp -c -I$LLVM_DIR/include -o llvmTarget.o -D_GNU_SOURCE -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS
View
185 llvm/Ext.cpp
@@ -1,185 +0,0 @@
-#include "llvm/ADT/Triple.h"
-#include "llvm/LLVMContext.h"
-#include "llvm/Support/Host.h"
-#include "llvm/Support/Signals.h"
-#include "llvm/PassManager.h"
-#include "llvm/Transforms/IPO.h"
-#include "llvm/Transforms/Scalar.h"
-
-#include "llvm-c/Core.h"
-#include "llvm-c/Target.h"
-#include "llvm-c/Transforms/IPO.h"
-
-// extensions to the LLVM C interface, we'll be needing more eventually ...
-
-using namespace llvm;
-
-extern "C" {
-
-LLVMTypeRef LLVMMetadataType()
-{
- return wrap(Type::getMetadataTy(*unwrap(LLVMGetGlobalContext())));
-}
-LLVMValueRef LLVMMetadataOperand(LLVMValueRef md, unsigned i)
-{
- return wrap(unwrap<MDNode>(md)->getOperand(i));
-}
-
-// load/store alignment
-
-void LLVMSetLoadAlign(LLVMValueRef store, unsigned align)
-{
- cast<LoadInst>(unwrap(store))->setAlignment(align);
-}
-unsigned LLVMGetLoadAlign(LLVMValueRef store)
-{
- return cast<LoadInst>(unwrap(store))->getAlignment();
-}
-
-void LLVMSetStoreAlign(LLVMValueRef store, unsigned align)
-{
- cast<StoreInst>(unwrap(store))->setAlignment(align);
-}
-unsigned LLVMGetStoreAlign(LLVMValueRef store)
-{
- return cast<StoreInst>(unwrap(store))->getAlignment();
-}
-
-void LLVMSetAllocaAlign(LLVMValueRef alloc, unsigned align)
-{
- cast<AllocaInst>(unwrap(alloc))->setAlignment(align);
-}
-unsigned LLVMGetAllocaAlign(LLVMValueRef alloc)
-{
- return cast<AllocaInst>(unwrap(alloc))->getAlignment();
-}
-int LLVMIsAllocaInst(LLVMValueRef V)
-{
- return isa<AllocaInst>(unwrap(V)) ? 1 : 0;
-}
-
-// is terminator
-int LLVMIsTerminator(LLVMValueRef inst)
-{
- if (dyn_cast<TerminatorInst>(unwrap(inst)) != NULL)
- return 1;
- return 0;
-}
-
-// dump type
-void LLVMDumpType(LLVMTypeRef type)
-{
- unwrap(type)->dump();
-}
-
-// erase instruction
-void LLVMEraseInstructionFromParent(LLVMValueRef V)
-{
- cast<Instruction>(unwrap(V))->eraseFromParent();
-}
-
-LLVMTypeRef LLVMGetStructElementType(LLVMTypeRef ST, unsigned elem_index)
-{
- return wrap(
- cast<StructType>(unwrap(ST))->getElementType(elem_index)
- );
-}
-
-// llvm/ADT/Triple.h binding
-
-// disabled for now
-
-#if 0
-
-typedef Triple* LLVMTripleRef;
-
-LLVMTripleRef LLVMCreateTriple(const char* str)
-{
- return new Triple(str);
-}
-
-void LLVMDisposeTriple(LLVMTripleRef triple)
-{
- delete triple;
-}
-
-Triple::ArchType LLVMTripleGetArch(LLVMTripleRef triple)
-{
- return triple->getArch();
-}
-
-Triple::VendorType LLVMTripleGetVendor(LLVMTripleRef triple)
-{
- return triple->getVendor();
-}
-
-Triple::OSType LLVMTripleGetOS(LLVMTripleRef triple)
-{
- return triple->getOS();
-}
-
-#endif
-
-const char* LLVMGetHostTriple()
-{
- static std::string str; // OK ?
- if (str.empty())
- str = sys::getHostTriple();
- return str.c_str();
-}
-
-// internalize
-
-//ModulePass *createInternalizePass(const std::vector<const char *> &exportList);
-
-void LLVMAddInternalizePassWithExportList(LLVMPassManagerRef PM, const char* exp[], unsigned nexps) {
- std::vector<const char *> exportList(nexps, NULL);
- for (unsigned i = 0; i < nexps; ++i)
- exportList[i] = exp[i];
- unwrap(PM)->add(createInternalizePass(exportList));
-}
-
-// other optimizations
-/*
-void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM)
-{
- unwrap(PM)->add(createCorrelatedValuePropagationPass());
-}*/
-
-/*
-void LLVMAddTailDuplicationPass(LLVMPassManagerRef PM)
-{
- unwrap(PM)->add(createTailDuplicationPass());
-}*/
-
-// system stuff
-
-void LLVMPrintStackTraceOnErrorSignal()
-{
- sys::PrintStackTraceOnErrorSignal();
-}
-
-// const long double
-
-LLVMValueRef LLVMConstRealFromBits(LLVMTypeRef T, unsigned bits, uint64_t* data, unsigned nbitwords)
-{
- return wrap(ConstantFP::get(getGlobalContext(), APFloat(APInt(bits, nbitwords, data))));
-}
-
-// get alias
-
-LLVMValueRef LLVMGetNamedAlias(LLVMModuleRef M, const char *Name)
-{
- return wrap(unwrap(M)->getNamedAlias(Name));
-}
-
-// add attribute to return value
-
-void LLVMAddRetAttr(LLVMValueRef Fn, LLVMAttribute PA) {
- Function *Func = unwrap<Function>(Fn);
- const AttrListPtr PAL = Func->getAttributes();
- const AttrListPtr PALnew = PAL.addAttr(0, PA);
- Func->setAttributes(PALnew);
-}
-
-}
View
186 llvm/Ext.d
@@ -1,186 +0,0 @@
-module llvm.Ext;
-
-import llvm.c.Core;
-import llvm.c.Target;
-
-extern(C):
-
-LLVMTypeRef LLVMMetadataType();
-LLVMValueRef LLVMMetadataOperand(LLVMValueRef, uint);
-
-void LLVMSetStoreAlign(LLVMValueRef store, uint alignment);
-uint LLVMGetStoreAlign(LLVMValueRef store);
-
-void LLVMSetLoadAlign(LLVMValueRef store, uint alignment);
-uint LLVMGetLoadAlign(LLVMValueRef store);
-
-void LLVMSetAllocaAlign(LLVMValueRef alloc, uint alignment);
-uint LLVMGetAllocaAlign(LLVMValueRef alloc);
-int LLVMIsAllocaInst(LLVMValueRef V);
-
-int LLVMIsTerminator(LLVMValueRef inst);
-
-void LLVMDumpType(LLVMTypeRef type);
-
-void LLVMEraseInstructionFromParent(LLVMValueRef V);
-
-LLVMTypeRef LLVMGetStructElementType(LLVMTypeRef ST, uint elem_index);
-
-LLVMValueRef LLVMConstRealFromBits(LLVMTypeRef T, uint bits, ulong* data, uint nbitwords);
-
-LLVMValueRef LLVMGetNamedAlias(LLVMModuleRef M, /*const*/ char *Name);
-
-void LLVMAddRetAttr(LLVMValueRef Fn, LLVMAttribute PA);
-
-// target triple binding
-
-// returns the running host triple
-char* LLVMGetHostTriple();
-
-version(none) // disable for now, since this enum is too unstable in llvm
-{
-struct LLVM_OpaqueTriple {}
-alias LLVM_OpaqueTriple* LLVMTripleRef;
-
-enum LLVMArchType {
- UnknownArch,
-
- alpha, // Alpha: alpha
- arm, // ARM; arm, armv.*, xscale
- bfin, // Blackfin: bfin
- cellspu, // CellSPU: spu, cellspu
- mips, // MIPS: mips, mipsallegrex
- mipsel, // MIPSEL: mipsel, mipsallegrexel, psp
- msp430, // MSP430: msp430
- pic16, // PIC16: pic16
- ppc, // PPC: powerpc
- ppc64, // PPC64: powerpc64
- sparc, // Sparc: sparc
- systemz, // SystemZ: s390x
- tce, // TCE (http://tce.cs.tut.fi/): tce
- thumb, // Thumb: thumb, thumbv.*
- x86, // X86: i[3-9]86
- x86_64, // X86-64: amd64, x86_64
- xcore, // XCore: xcore
-
- InvalidArch
-};
-
-enum LLVMVendorType {
- UnknownVendor,
-
- Apple,
- PC
-};
-
-enum LLVMOSType {
- UnknownOS,
-
- AuroraUX,
- Cygwin,
- Darwin,
- DragonFly,
- FreeBSD,
- Linux,
- MinGW32,
- MinGW64,
- NetBSD,
- OpenBSD,
- Solaris,
- Win32
-};
-
-LLVMTripleRef LLVMCreateTriple(char* str);
-void LLVMDisposeTriple(LLVMTripleRef triple);
-
-LLVMArchType LLVMTripleGetArch(LLVMTripleRef triple);
-LLVMVendorType LLVMTripleGetVendor(LLVMTripleRef triple);
-LLVMOSType LLVMTripleGetOS(LLVMTripleRef triple);
-}
-
-// TargetMachine binding
-
-struct LLVM_OpaqueTargetMachine {}
-alias LLVM_OpaqueTargetMachine* LLVMTargetMachineRef;
-
-LLVMTargetMachineRef LLVMCreateTargetMachine(char* cpu, char* triple, char** feats, size_t nfeats, int pic);
-void LLVMDisposeTargetMachine(LLVMTargetMachineRef machine);
-LLVMTargetDataRef LLVMTargetMachineData(LLVMTargetMachineRef TM);
-
-// Targets
-
-void LLVMInitializeX86TargetMC();
-void LLVMInitializeX86TargetInfo();
-void LLVMInitializeX86Target();
-void LLVMInitializeX86AsmPrinter();
-void LLVMInitializeX86AsmParser();
-
-void LLVMInitializePPCTargetMC();
-void LLVMInitializePPCTargetInfo();
-void LLVMInitializePPCTarget();
-void LLVMInitializePPCAsmPrinter();
-void LLVMInitializePPCAsmParser();
-
-void LLVMInitializeARMTargetMC();
-void LLVMInitializeARMTargetInfo();
-void LLVMInitializeARMTarget();
-void LLVMInitializeARMAsmPrinter();
-void LLVMInitializeARMAsmParser();
-
-void LLVMInitializeSparcTargetMC();
-void LLVMInitializeSparcTargetInfo();
-void LLVMInitializeSparcTarget();
-void LLVMInitializeSparcAsmPrinter();
-void LLVMInitializeSparcAsmParser();
-
-LLVMBool LLVMInitializeNativeTarget() {
- // If we have a native target, initialize it to ensure it is linked in.
- version(X86) {
- LLVMInitializeX86TargetMC();
- LLVMInitializeX86TargetInfo();
- LLVMInitializeX86Target();
- } else version(X86_64) {
- LLVMInitializeX86TargetMC();
- LLVMInitializeX86TargetInfo();
- LLVMInitializeX86Target();
- } else version(PPC) {
- LLVMInitializePPCTargetMC();
- LLVMInitializePPCTargetInfo();
- LLVMInitializePPCTarget();
- } else version(PPC64) {
- LLVMInitializePPCTargetMC();
- LLVMInitializePPCTargetInfo();
- LLVMInitializePPCTarget();
- } else version(ARM) {
- LLVMInitializeARMTargetMC();
- LLVMInitializeARMTargetInfo();
- LLVMInitializeARMTarget();
- } else version(SPARC) {
- LLVMInitializeSparcTargetMC();
- LLVMInitializeSparcTargetInfo();
- LLVMInitializeSparcTarget();
- } else version(SPARC64) {
- LLVMInitializeSparcTargetMC();
- LLVMInitializeSparcTargetInfo();
- LLVMInitializeSparcTarget();
- } else {
- return 1;
- }
- return 0;
-}
-
-// TODO add the rest
-
-// Extra output functions
-int LLVMWriteAsmToFile(LLVMModuleRef M, char* path, char** errstr);
-int LLVMWriteNativeAsmToFile(LLVMTargetMachineRef TM, LLVMModuleRef M, char* path, int opt /*, int pic*/);
-
-// More optimization
-
-void LLVMAddInternalizePassWithExportList(LLVMPassManagerRef PM, char** exp, uint nexps);
-//void LLVMAddTailDuplicationPass(LLVMPassManagerRef PM);
-void LLVMAddCorrelatedValuePropagationPass(LLVMPassManagerRef PM);
-
-// system utils
-
-void LLVMPrintStackTraceOnErrorSignal();
View
69 llvm/LICENSE.TXT
@@ -1,69 +0,0 @@
-==============================================================================
-LLVM Release License
-==============================================================================
-University of Illinois/NCSA
-Open Source License
-
-Copyright (c) 2003-2010 University of Illinois at Urbana-Champaign.
-All rights reserved.
-
-Developed by:
-
- LLVM Team
-
- University of Illinois at Urbana-Champaign
-
- http://llvm.org
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal with
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-of the Software, and to permit persons to whom the Software is furnished to do
-so, subject to the following conditions:
-
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimers.
-
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimers in the
- documentation and/or other materials provided with the distribution.
-
- * Neither the names of the LLVM Team, University of Illinois at
- Urbana-Champaign, nor the names of its contributors may be used to
- endorse or promote products derived from this Software without specific
- prior written permission.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
-SOFTWARE.
-
-==============================================================================
-Copyrights and Licenses for Third Party Software Distributed with LLVM:
-==============================================================================
-The LLVM software contains code written by third parties. Such software will
-have its own individual LICENSE.TXT file in the directory in which it appears.
-This file will describe the copyrights, license, and restrictions which apply
-to that code.
-
-The disclaimer of warranty in the University of Illinois Open Source License
-applies to all code in the LLVM Distribution, and nothing in any of the
-other licenses gives permission to use the names of the LLVM Team or the
-University of Illinois to endorse or promote products derived from this
-Software.
-
-The following pieces of software have additional or alternate copyrights,
-licenses, and/or restrictions:
-
-Program Directory
-------- ---------
-Autoconf llvm/autoconf
- llvm/projects/ModuleMaker/autoconf
- llvm/projects/sample/autoconf
-CellSPU backend llvm/lib/Target/CellSPU/README.txt
-Google Test llvm/utils/unittest/googletest
-OpenBSD regex llvm/lib/Support/{reg*, COPYRIGHT.regex}
View
158 llvm/Target.cpp
@@ -1,158 +0,0 @@
-#include "llvm-c/Core.h"
-#include "llvm-c/Target.h"
-#include "llvm/Module.h"
-#include "llvm/CodeGen/MachineCodeEmitter.h"
-#include "llvm/GlobalValue.h"
-#include "llvm/PassManager.h"
-#include "llvm/ADT/Triple.h"
-#include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/FormattedStream.h"
-#include "llvm/MC/SubtargetFeature.h"
-#include "llvm/Target/TargetData.h"
-#include "llvm/Target/TargetMachine.h"
-#include "llvm/Support/TargetRegistry.h"
-#include "llvm/Support/TargetSelect.h"
-
-#include <cstdio>
-
-using namespace llvm;
-
-typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef;
-
-namespace llvm
-{
- class TargetMachine;
-
- inline TargetMachine *unwrap(LLVMTargetMachineRef P) {
- return reinterpret_cast<TargetMachine*>(P);
- }
-
- inline LLVMTargetMachineRef wrap(const TargetMachine *P) {
- return reinterpret_cast<LLVMTargetMachineRef>(const_cast<TargetMachine*>(P));
- }
-}
-
-extern "C" {
-
-LLVMTargetMachineRef LLVMCreateTargetMachine(const char* cpu, const char* triple, const char** feats, size_t nfeats, int pic)
-{
- // based on LDC code
-
- // find target from the given triple and cpu
- const Target* target = NULL;
- for (TargetRegistry::iterator it = TargetRegistry::begin(),
- ie = TargetRegistry::end(); it != ie; ++it)
- {
-#if 0
- printf("cpu: %s target: %s\n", cpu, it->getName());
-#endif
- if (strcmp(cpu, it->getName()) == 0)
- {
- target = &*it;
- break;
- }
- }
- assert(target != NULL);
-
- // add any features the user might have provided
- Twine twine;
-
- SubtargetFeatures features;
- //features.setCPU(cpu);
-
- for (size_t i = 0; i < nfeats; ++i)
- {
- features.AddFeature(feats[i]);
- twine = twine.concat(features.getString());
- }
-
- // create machine
- TargetMachine* targetMachine = target->createTargetMachine(triple, cpu, twine.str(), pic ? Reloc::PIC_ : Reloc::Default, CodeModel::Default);
- if (!targetMachine)
- return NULL;
-
- return wrap(targetMachine);
-}
-
-void LLVMDisposeTargetMachine(LLVMTargetMachineRef machine)
-{
- delete unwrap(machine);
-}
-
-LLVMTargetDataRef LLVMTargetMachineData(LLVMTargetMachineRef TM)
-{
- return wrap(unwrap(TM)->getTargetData());
-}
-
-// LLVM to native asm
-
-// stolen from LDC and modified
-// based on llc (from LLVM) code, University of Illinois Open Source License
-int LLVMWriteNativeAsmToFile(LLVMTargetMachineRef TMRef, LLVMModuleRef MRef, const char* filename, int opt) //, int pic)
-{
- TargetMachine* TM = unwrap(TMRef);
- Module* M = unwrap(MRef);
-
- //TargetMachine::setRelocationModel(pic ? Reloc::PIC_ : Reloc::Default);
-
-#if 0
- printf("trying to write native asm for target: %s\n", TM->getTarget().getName());
-#endif
-
- std::string Err;
-
- // Build up all of the passes that we want to do to the module.
- FunctionPassManager Passes(M);
-
- // Add TargetData
- if (const TargetData *TD = TM->getTargetData())
- Passes.add(new TargetData(*TD));
- else
- assert(0); // Passes.add(new TargetData(M));
-
- // debug info doesn't work properly with OptLevel != None!
- CodeGenOpt::Level OLvl = CodeGenOpt::Default;
- if (opt)
- OLvl = CodeGenOpt::Aggressive;
- else
- OLvl = CodeGenOpt::None;
-
- // open output file
- raw_fd_ostream out(filename, Err, raw_fd_ostream::F_Binary);
- assert(Err.empty());
-
- // add codegen passes
- formatted_raw_ostream fout(out);
- bool error = TM->addPassesToEmitFile(Passes, fout, TargetMachine::CGFT_AssemblyFile, OLvl);
- assert(error == false); // Target does not support generation of this file type!
-
- Passes.doInitialization();
-
- // Run our queue of passes all at once now, efficiently.
- for (llvm::Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
- if (!I->isDeclaration())
- Passes.run(*I);
-
- Passes.doFinalization();
-
- fout.flush();
-
- return 1;
-}
-
-// write llvm asm to file instead of stdout
-int LLVMWriteAsmToFile(LLVMModuleRef M, const char* path, const char** errstr)
-{
- std::string errs;
- raw_fd_ostream out(path, errs, raw_fd_ostream::F_Binary);
- if (!errs.empty())
- {
- if (errstr)
- *errstr = strdup(errs.c_str());
- return 0;
- }
- unwrap(M)->print(out, NULL);
- return 1;
-}
-
-}
View
29 llvm/c/Analysis.d 100755 → 100644
@@ -1,4 +1,4 @@
-/*===-- llvm-c/Analysis.h - Analysis Library C Interface --------*- D -*-===*\
+/*===-- llvm-c/Analysis.h - Analysis Library C Interface --------*- C++ -*-===*\
|* *|
|* The LLVM Compiler Infrastructure *|
|* *|
@@ -15,23 +15,32 @@
|* tools written in such languages. *|
|* *|
\*===----------------------------------------------------------------------===*/
-module llvm.c.Analysis;
-import llvm.c.Core;
+module llvm.c.analysis;
-extern(C):
+import llvm.c.core;
+
+extern(C) nothrow:
+
+/**
+ * @defgroup LLVMCAnalysis Analysis
+ * @ingroup LLVMC
+ *
+ * @{
+ */
enum LLVMVerifierFailureAction {
- AbortProcess, /* verifier will print to stderr and abort() */
- PrintMessage, /* verifier will print to stderr and return 1 */
- ReturnStatus /* verifier will just return 1 */
+ LLVMAbortProcessAction, /* verifier will print to stderr and abort() */
+ LLVMPrintMessageAction, /* verifier will print to stderr and return 1 */
+ LLVMReturnStatusAction /* verifier will just return 1 */
}
+
/* Verifies that a module is valid, taking the specified action if not.
Optionally returns a human-readable description of any invalid constructs.
OutMessage must be disposed with LLVMDisposeMessage. */
LLVMBool LLVMVerifyModule(LLVMModuleRef M, LLVMVerifierFailureAction Action,
- char** OutMessage);
+ char **OutMessage);
/* Verifies that a single function is valid, taking the specified action. Useful
for debugging. */
@@ -41,3 +50,7 @@ LLVMBool LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action);
Useful for debugging. */
void LLVMViewFunctionCFG(LLVMValueRef Fn);
void LLVMViewFunctionCFGOnly(LLVMValueRef Fn);
+
+/**
+ * @}
+ */
View
43 llvm/c/BitReader.d 100755 → 100644
@@ -1,4 +1,4 @@
-/*===-- llvm-c/BitReader.h - BitReader Library C Interface ------*- D -*-===*\
+/*===-- llvm-c/BitReader.h - BitReader Library C Interface ------*- C++ -*-===*\
|* *|
|* The LLVM Compiler Infrastructure *|
|* *|
@@ -15,42 +15,53 @@
|* tools written in such languages. *|
|* *|
\*===----------------------------------------------------------------------===*/
-module llvm.c.BitReader;
-import llvm.c.Core;
+module llvm.c.bitreader;
-extern(C):
+import llvm.c.core;
+extern(C) nothrow:
+
+/**
+ * @defgroup LLVMCBitReader Bit Reader
+ * @ingroup LLVMC
+ *
+ * @{
+ */
/* Builds a module from the bitcode in the specified memory buffer, returning a
reference to the module via the OutModule parameter. Returns 0 on success.
- Optionally returns a human-readable error message via OutMessage. */
+ Optionally returns a human-readable error message via OutMessage. */
LLVMBool LLVMParseBitcode(LLVMMemoryBufferRef MemBuf,
- LLVMModuleRef* OutModule, char** OutMessage);
+ LLVMModuleRef *OutModule, char **OutMessage);
LLVMBool LLVMParseBitcodeInContext(LLVMContextRef ContextRef,
LLVMMemoryBufferRef MemBuf,
- LLVMModuleRef* OutModule, char** OutMessage);
+ LLVMModuleRef *OutModule, char **OutMessage);
/** Reads a module from the specified path, returning via the OutMP parameter
a module provider which performs lazy deserialization. Returns 0 on success.
- Optionally returns a human-readable error message via OutMessage. */
+ Optionally returns a human-readable error message via OutMessage. */
LLVMBool LLVMGetBitcodeModuleInContext(LLVMContextRef ContextRef,
LLVMMemoryBufferRef MemBuf,
- LLVMModuleRef* OutM,
- char** OutMessage);
+ LLVMModuleRef *OutM,
+ char **OutMessage);
-LLVMBool LLVMGetBitcodeModule(LLVMMemoryBufferRef MemBuf, LLVMModuleRef* OutM,
- char** OutMessage);
+LLVMBool LLVMGetBitcodeModule(LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM,
+ char **OutMessage);
/** Deprecated: Use LLVMGetBitcodeModuleInContext instead. */
LLVMBool LLVMGetBitcodeModuleProviderInContext(LLVMContextRef ContextRef,
LLVMMemoryBufferRef MemBuf,
- LLVMModuleProviderRef* OutMP,
- char** OutMessage);
+ LLVMModuleProviderRef *OutMP,
+ char **OutMessage);
/** Deprecated: Use LLVMGetBitcodeModule instead. */
LLVMBool LLVMGetBitcodeModuleProvider(LLVMMemoryBufferRef MemBuf,
- LLVMModuleProviderRef* OutMP,
- char** OutMessage);
+ LLVMModuleProviderRef *OutMP,
+ char **OutMessage);
+
+/**
+ * @}
+ */
View
26 llvm/c/BitWriter.d 100755 → 100644
@@ -1,4 +1,4 @@
-/*===-- llvm-c/BitWriter.h - BitWriter Library C Interface ------*- D -*-===*\
+/*===-- llvm-c/BitWriter.h - BitWriter Library C Interface ------*- C++ -*-===*\
|* *|
|* The LLVM Compiler Infrastructure *|
|* *|
@@ -15,21 +15,33 @@
|* tools written in such languages. *|
|* *|
\*===----------------------------------------------------------------------===*/
-module llvm.c.BitWriter;
-import llvm.c.Core;
+module llvm.c.bitwriter;
-extern(C):
+import llvm.c.core;
+
+extern(C) nothrow:
+
+/**
+ * @defgroup LLVMCBitWriter Bit Writer
+ * @ingroup LLVMC
+ *
+ * @{
+ */
/*===-- Operations on modules ---------------------------------------------===*/
-/** Writes a module to the specified path. Returns 0 on success. */
-int LLVMWriteBitcodeToFile(LLVMModuleRef M, /*const*/ char* Path);
+/** Writes a module to the specified path. Returns 0 on success. */
+int LLVMWriteBitcodeToFile(LLVMModuleRef M, const(char) *Path);
/** Writes a module to an open file descriptor. Returns 0 on success. */
int LLVMWriteBitcodeToFD(LLVMModuleRef M, int FD, int ShouldClose,
int Unbuffered);
/** Deprecated for LLVMWriteBitcodeToFD. Writes a module to an open file
- descriptor. Returns 0 on success. Closes the Handle. */
+ descriptor. Returns 0 on success. Closes the Handle. */
int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int Handle);
+
+/**
+ * @}
+ */
View
2,517 llvm/c/Core.d 100755 → 100644
@@ -1,4 +1,4 @@
-/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- D -*-===*\
+/*===-- llvm-c/Core.h - Core Library C Interface ------------------*- C -*-===*\
|* *|
|* The LLVM Compiler Infrastructure *|
|* *|
@@ -10,184 +10,242 @@
|* This header declares the C interface to libLLVMCore.a, which implements *|
|* the LLVM intermediate representation. *|
|* *|
-|* LLVM uses a polymorphic type hierarchy which C cannot represent, therefore *|
-|* parameters must be passed as base types. Despite the declared types, most *|
-|* of the functions provided operate only on branches of the type hierarchy. *|
-|* The declared parameter names are descriptive and specify which type is *|
-|* required. Additionally, each type hierarchy is documented along with the *|
-|* functions that operate upon it. For more detail, refer to LLVM's C++ code. *|
-|* If in doubt, refer to Core.cpp, which performs paramter downcasts in the *|
-|* form unwrap<RequiredType>(Param). *|
-|* *|
-|* Many exotic languages can interoperate with C code but have a harder time *|
-|* with C++ due to name mangling. So in addition to C, this interface enables *|
-|* tools written in such languages. *|
-|* *|
-|* When included into a C++ source file, also declares 'wrap' and 'unwrap' *|
-|* helpers to perform opaque reference<-->pointer conversions. These helpers *|
-|* are shorter and more tightly typed than writing the casts by hand when *|
-|* authoring bindings. In assert builds, they will do runtime type checking. *|
-|* *|
\*===----------------------------------------------------------------------===*/
-module llvm.c.Core;
+module llvm.c.core;
+
+import core.stdc.stdint : uint8_t, uint64_t;
+
+extern(C) nothrow:
+
+/**
+ * @defgroup LLVMC LLVM-C: C interface to LLVM
+ *
+ * This module exposes parts of the LLVM library as a C API.
+ *
+ * @{
+ */
+
+/**
+ * @defgroup LLVMCTransforms Transforms
+ */
-extern(C):
+/**
+ * @defgroup LLVMCCore Core
+ *
+ * This modules provide an interface to libLLVMCore, which implements
+ * the LLVM intermediate representation as well as other related types
+ * and utilities.
+ *
+ * LLVM uses a polymorphic type hierarchy which C cannot represent, therefore
+ * parameters must be passed as base types. Despite the declared types, most
+ * of the functions provided operate only on branches of the type hierarchy.
+ * The declared parameter names are descriptive and specify which type is
+ * required. Additionally, each type hierarchy is documented along with the
+ * functions that operate upon it. For more detail, refer to LLVM's C++ code.
+ * If in doubt, refer to Core.cpp, which performs paramter downcasts in the
+ * form unwrap<RequiredType>(Param).
+ *
+ * Many exotic languages can interoperate with C code but have a harder time
+ * with C++ due to name mangling. So in addition to C, this interface enables
+ * tools written in such languages.
+ *
+ * When included into a C++ source file, also declares 'wrap' and 'unwrap'
+ * helpers to perform opaque reference<-->pointer conversions. These helpers
+ * are shorter and more tightly typed than writing the casts by hand when
+ * authoring bindings. In assert builds, they will do runtime type checking.
+ *
+ * @{
+ */
+/**
+ * @defgroup LLVMCCoreTypes Types and Enumerations
+ *
+ * @{
+ */
alias int LLVMBool;
/* Opaque types. */
/**
- * The top-level container for all LLVM global data. See the LLVMContext class.
+ * The top-level container for all LLVM global data. See the LLVMContext class.
*/
-struct __LLVMOpaqueContext {}
-alias __LLVMOpaqueContext* LLVMContextRef;
+struct __LLVMOpaqueContext {};
+alias __LLVMOpaqueContext *LLVMContextRef;
/**
* The top-level container for all other LLVM Intermediate Representation (IR)
- * objects. See the llvm::Module class.
+ * objects.
+ *
+ * @see llvm::Module
*/
-struct __LLVMOpaqueModule {}
-alias __LLVMOpaqueModule* LLVMModuleRef;
+struct __LLVMOpaqueModule {};
+alias __LLVMOpaqueModule *LLVMModuleRef;
/**
- * Each value in the LLVM IR has a type, an LLVMTypeRef. See the llvm::Type
- * class.
+ * Each value in the LLVM IR has a type, an LLVMTypeRef.
+ *
+ * @see llvm::Type
*/
-struct __LLVMOpaqueType {}
-alias __LLVMOpaqueType* /*int**/ LLVMTypeRef;
+struct __LLVMOpaqueType {};
+alias __LLVMOpaqueType *LLVMTypeRef;
-struct __LLVMOpaqueValue {}
-alias __LLVMOpaqueValue* /*int**/ LLVMValueRef;
+/**
+ * Represents an individual value in LLVM IR.
+ *
+ * This models llvm::Value.
+ */
+struct __LLVMOpaqueValue {};
+alias __LLVMOpaqueValue *LLVMValueRef;
-//struct __LLVMOpaqueBasicBlock {}
-alias /*__LLVMOpaqueBasicBlock*/ int* LLVMBasicBlockRef;
+/**
+ * Represents a basic block of instruction in LLVM IR.
+ *
+ * This models llvm::BasicBlock.
+ */
+struct __LLVMOpaqueBasicBlock {};
+alias __LLVMOpaqueBasicBlock *LLVMBasicBlockRef;
-struct __LLVMOpaqueBuilder {}
-alias __LLVMOpaqueBuilder* LLVMBuilderRef;
+/**
+ * Represents an LLVM basic block builder.
+ *
+ * This models llvm::IRBuilder.
+ */
+struct __LLVMOpaqueBuilder {};
+alias __LLVMOpaqueBuilder *LLVMBuilderRef;
-/* Interface used to provide a module to JIT or interpreter. This is now just a
- * synonym for llvm::Module, but we have to keep using the different type to
- * keep binary compatibility.
+/**
+ * Interface used to provide a module to JIT or interpreter.
+ * This is now just a synonym for llvm::Module, but we have to keep using the
+ * different type to keep binary compatibility.
*/
-struct __LLVMOpaqueModuleProvider {}
-alias __LLVMOpaqueModuleProvider* LLVMModuleProviderRef;
+struct __LLVMOpaqueModuleProvider {};
+alias __LLVMOpaqueModuleProvider *LLVMModuleProviderRef;
-/* Used to provide a module to JIT or interpreter.
- * See the llvm::MemoryBuffer class.
+/**
+ * Used to provide a module to JIT or interpreter.
+ *
+ * @see llvm::MemoryBuffer
*/
-struct __LLVMOpaqueMemoryBuffer {}
-alias __LLVMOpaqueMemoryBuffer* LLVMMemoryBufferRef;
+struct __LLVMOpaqueMemoryBuffer {};
+alias __LLVMOpaqueMemoryBuffer *LLVMMemoryBufferRef;
-/** See the llvm::PassManagerBase class. */
-struct __LLVMOpaquePassManager {}
-alias __LLVMOpaquePassManager* LLVMPassManagerRef;
+/** @see llvm::PassManagerBase */
+struct __LLVMOpaquePassManager {};
+alias __LLVMOpaquePassManager *LLVMPassManagerRef;
-/** See the llvm::PassRegistry class. */
-struct __LLVMOpaquePassRegistry {}
-alias __LLVMOpaquePassRegistry* LLVMPassRegistryRef;
+/** @see llvm::PassRegistry */
+struct __LLVMOpaquePassRegistry {};
+alias __LLVMOpaquePassRegistry *LLVMPassRegistryRef;
-/** Used to get the users and usees of a Value. See the llvm::Use class. */
-struct __LLVMOpaqueUse {}
-alias __LLVMOpaqueUse* LLVMUseRef;
+/**
+ * Used to get the users and usees of a Value.
+ *
+ * @see llvm::Use */
+struct __LLVMOpaqueUse {};
+alias __LLVMOpaqueUse *LLVMUseRef;
enum LLVMAttribute {
- ZExt = 1<<0,
- SExt = 1<<1,
- NoReturn = 1<<2,
- InReg = 1<<3,
- StructRet = 1<<4,
- NoUnwind = 1<<5,
- NoAlias = 1<<6,
- ByVal = 1<<7,
- Nest = 1<<8,
- ReadNone = 1<<9,
- ReadOnly = 1<<10,
- NoInline = 1<<11,
- AlwaysInline = 1<<12,
- OptimizeForSize = 1<<13,
- StackProtect = 1<<14,
- StackProtectReq = 1<<15,
- Alignment = 31<<16,
- NoCapture = 1<<21,
- NoRedZone = 1<<22,
- NoImplicitFloat = 1<<23,
- Naked = 1<<24,
- InlineHint = 1<<25,
- StackAlignment = 7<<26,
- ReturnsTwice = 1 << 29,
- UWTable = 1 << 30,
- NonLazyBind = 1 << 31
+ LLVMZExtAttribute = 1<<0,
+ LLVMSExtAttribute = 1<<1,
+ LLVMNoReturnAttribute = 1<<2,
+ LLVMInRegAttribute = 1<<3,
+ LLVMStructRetAttribute = 1<<4,
+ LLVMNoUnwindAttribute = 1<<5,
+ LLVMNoAliasAttribute = 1<<6,
+ LLVMByValAttribute = 1<<7,
+ LLVMNestAttribute = 1<<8,
+ LLVMReadNoneAttribute = 1<<9,
+ LLVMReadOnlyAttribute = 1<<10,
+ LLVMNoInlineAttribute = 1<<11,
+ LLVMAlwaysInlineAttribute = 1<<12,
+ LLVMOptimizeForSizeAttribute = 1<<13,
+ LLVMStackProtectAttribute = 1<<14,
+ LLVMStackProtectReqAttribute = 1<<15,
+ LLVMAlignment = 31<<16,
+ LLVMNoCaptureAttribute = 1<<21,
+ LLVMNoRedZoneAttribute = 1<<22,
+ LLVMNoImplicitFloatAttribute = 1<<23,
+ LLVMNakedAttribute = 1<<24,
+ LLVMInlineHintAttribute = 1<<25,
+ LLVMStackAlignment = 7<<26,
+ LLVMReturnsTwice = 1 << 29,
+ LLVMUWTable = 1 << 30,
+ LLVMNonLazyBind = 1 << 31
+
+ // FIXME: This attribute is currently not included in the C API as
+ // a temporary measure until the API/ABI impact to the C API is understood
+ // and the path forward agreed upon.
+ //LLVMAddressSafety = 1ULL << 32
}
enum LLVMOpcode {
/* Terminator Instructions */
- Ret = 1,
- Br = 2,
- Switch = 3,
- IndirectBr = 4,
- Invoke = 5,
+ LLVMRet = 1,
+ LLVMBr = 2,
+ LLVMSwitch = 3,
+ LLVMIndirectBr = 4,
+ LLVMInvoke = 5,
/* removed 6 due to API changes */
- Unreachable = 7,
+ LLVMUnreachable = 7,
/* Standard Binary Operators */
- Add = 8,
- FAdd = 9,
- Sub = 10,
- FSub = 11,
- Mul = 12,
- FMul = 13,
- UDiv = 14,
- SDiv = 15,
- FDiv = 16,
- URem = 17,
- SRem = 18,
- FRem = 19,
+ LLVMAdd = 8,
+ LLVMFAdd = 9,
+ LLVMSub = 10,
+ LLVMFSub = 11,
+ LLVMMul = 12,
+ LLVMFMul = 13,
+ LLVMUDiv = 14,
+ LLVMSDiv = 15,
+ LLVMFDiv = 16,
+ LLVMURem = 17,
+ LLVMSRem = 18,
+ LLVMFRem = 19,
/* Logical Operators */
- Shl = 20,
- LShr = 21,
- AShr = 22,
- And = 23,
- Or = 24,
- Xor = 25,
+ LLVMShl = 20,
+ LLVMLShr = 21,
+ LLVMAShr = 22,
+ LLVMAnd = 23,
+ LLVMOr = 24,
+ LLVMXor = 25,
/* Memory Operators */
- Alloca = 26,
- Load = 27,
- Store = 28,
- GetElementPtr = 29,
+ LLVMAlloca = 26,
+ LLVMLoad = 27,
+ LLVMStore = 28,
+ LLVMGetElementPtr = 29,
/* Cast Operators */
- Trunc = 30,
- ZExt = 31,
- SExt = 32,
- FPToUI = 33,
- FPToSI = 34,
- UIToFP = 35,
- SIToFP = 36,
- FPTrunc = 37,
- FPExt = 38,
- PtrToInt = 39,
- IntToPtr = 40,
- BitCast = 41,
+ LLVMTrunc = 30,
+ LLVMZExt = 31,
+ LLVMSExt = 32,
+ LLVMFPToUI = 33,
+ LLVMFPToSI = 34,
+ LLVMUIToFP = 35,
+ LLVMSIToFP = 36,
+ LLVMFPTrunc = 37,
+ LLVMFPExt = 38,
+ LLVMPtrToInt = 39,
+ LLVMIntToPtr = 40,
+ LLVMBitCast = 41,
/* Other Operators */
- ICmp = 42,
- FCmp = 43,
- PHI = 44,
- Call = 45,
- Select = 46,
- UserOp1 = 47,
- UserOp2 = 48,
- VAArg = 49,
- ExtractElement = 50,
- InsertElement = 51,
- ShuffleVector = 52,
- ExtractValue = 53,
- InsertValue = 54,
+ LLVMICmp = 42,
+ LLVMFCmp = 43,
+ LLVMPHI = 44,
+ LLVMCall = 45,
+ LLVMSelect = 46,
+ LLVMUserOp1 = 47,
+ LLVMUserOp2 = 48,
+ LLVMVAArg = 49,
+ LLVMExtractElement = 50,
+ LLVMInsertElement = 51,
+ LLVMShuffleVector = 52,
+ LLVMExtractValue = 53,
+ LLVMInsertValue = 54,
/* Atomic operators */
LLVMFence = 55,
@@ -196,149 +254,342 @@ enum LLVMOpcode {
/* Exception Handling Operators */
LLVMResume = 58,
- LLVMLandingPad = 59,
- LLVMUnwind = 60
+ LLVMLandingPad = 59
+
}
enum LLVMTypeKind {
- Void, /**< type with no size */
- Float, /**< 32 bit floating point type */
- Double, /**< 64 bit floating point type */
- X86_FP80, /**< 80 bit floating point type (X87) */
- FP128, /**< 128 bit floating point type (112-bit mantissa) */
- PPC_FP128, /**< 128 bit floating point type (two 64-bits) */
- Label, /**< Labels */
- Integer, /**< Arbitrary bit width integers */
- Function, /**< Functions */
- Struct, /**< Structures */
- Array, /**< Arrays */
- Pointer, /**< Pointers */
- Vector, /**< SIMD 'packed' format, or other vector type */
- Metadata, /**< Metadata */
- X86_MMX /**< X86 MMX */
+ LLVMVoidTypeKind, /**< type with no size */
+ LLVMHalfTypeKind, /**< 16 bit floating point type */
+ LLVMFloatTypeKind, /**< 32 bit floating point type */
+ LLVMDoubleTypeKind, /**< 64 bit floating point type */
+ LLVMX86_FP80TypeKind, /**< 80 bit floating point type (X87) */
+ LLVMFP128TypeKind, /**< 128 bit floating point type (112-bit mantissa)*/
+ LLVMPPC_FP128TypeKind, /**< 128 bit floating point type (two 64-bits) */
+ LLVMLabelTypeKind, /**< Labels */
+ LLVMIntegerTypeKind, /**< Arbitrary bit width integers */
+ LLVMFunctionTypeKind, /**< Functions */
+ LLVMStructTypeKind, /**< Structures */
+ LLVMArrayTypeKind, /**< Arrays */
+ LLVMPointerTypeKind, /**< Pointers */
+ LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
+ LLVMMetadataTypeKind, /**< Metadata */
+ LLVMX86_MMXTypeKind /**< X86 MMX */
}
enum LLVMLinkage {
- External, /**< Externally visible function */
- AvailableExternally,
- LinkOnceAny, /**< Keep one copy of function when linking (inline) */
- LinkOnceODR, /**< Same, but only replaced by something equivalent. */
- WeakAny, /**< Keep one copy of function when linking (weak) */
- WeakODR, /**< Same, but only replaced by something equivalent. */
- Appending, /**< Special purpose, only applies to global arrays */
- Internal, /**< Rename collisions when linking (static functions) */
- Private, /**< Like Internal, but omit from symbol table */
- DLLImport, /**< Function to be imported from DLL */
- DLLExport, /**< Function to be accessible from DLL */
- ExternalWeak, /**< ExternalWeak linkage description */
- Ghost, /**< Obsolete */
- Common, /**< Tentative definitions */
- LinkerPrivate, /**< Like Private, but linker removes. */
- LinkerPrivateWeak, /**< Like LinkerPrivate, but is weak. */
- LinkerPrivateWeakDefAuto /**< Like LinkerPrivateWeak, but possibly hidden. */
+ LLVMExternalLinkage, /**< Externally visible function */
+ LLVMAvailableExternallyLinkage,
+ LLVMLinkOnceAnyLinkage, /**< Keep one copy of function when linking (inline)*/
+ LLVMLinkOnceODRLinkage, /**< Same, but only replaced by something
+ equivalent. */
+ LLVMWeakAnyLinkage, /**< Keep one copy of function when linking (weak) */
+ LLVMWeakODRLinkage, /**< Same, but only replaced by something
+ equivalent. */
+ LLVMAppendingLinkage, /**< Special purpose, only applies to global arrays */
+ LLVMInternalLinkage, /**< Rename collisions when linking (static
+ functions) */
+ LLVMPrivateLinkage, /**< Like Internal, but omit from symbol table */
+ LLVMDLLImportLinkage, /**< Function to be imported from DLL */
+ LLVMDLLExportLinkage, /**< Function to be accessible from DLL */
+ LLVMExternalWeakLinkage,/**< ExternalWeak linkage description */
+ LLVMGhostLinkage, /**< Obsolete */
+ LLVMCommonLinkage, /**< Tentative definitions */
+ LLVMLinkerPrivateLinkage, /**< Like Private, but linker removes. */
+ LLVMLinkerPrivateWeakLinkage, /**< Like LinkerPrivate, but is weak. */
+ LLVMLinkerPrivateWeakDefAutoLinkage /**< Like LinkerPrivateWeak, but possibly
+ hidden. */
}
enum LLVMVisibility {
- Default, /**< The GV is visible */
- Hidden, /**< The GV is hidden */
- Protected /**< The GV is protected */
+ LLVMDefaultVisibility, /**< The GV is visible */
+ LLVMHiddenVisibility, /**< The GV is hidden */
+ LLVMProtectedVisibility /**< The GV is protected */
}
enum LLVMCallConv {
- C = 0,
- Fast = 8,
- Cold = 9,
- X86Stdcall = 64,
- X86Fastcall = 65
+ LLVMCCallConv = 0,
+ LLVMFastCallConv = 8,
+ LLVMColdCallConv = 9,
+ LLVMX86StdcallCallConv = 64,
+ LLVMX86FastcallCallConv = 65
}
enum LLVMIntPredicate {
- EQ = 32, /**< equal */
- NE, /**< not equal */
- UGT, /**< unsigned greater than */
- UGE, /**< unsigned greater or equal */
- ULT, /**< unsigned less than */
- ULE, /**< unsigned less or equal */
- SGT, /**< signed greater than */
- SGE, /**< signed greater or equal */
- SLT, /**< signed less than */
- SLE /**< signed less or equal */
+ LLVMIntEQ = 32, /**< equal */
+ LLVMIntNE, /**< not equal */
+ LLVMIntUGT, /**< unsigned greater than */
+ LLVMIntUGE, /**< unsigned greater or equal */
+ LLVMIntULT, /**< unsigned less than */
+ LLVMIntULE, /**< unsigned less or equal */
+ LLVMIntSGT, /**< signed greater than */
+ LLVMIntSGE, /**< signed greater or equal */
+ LLVMIntSLT, /**< signed less than */
+ LLVMIntSLE /**< signed less or equal */
}
enum LLVMRealPredicate {
- False, /**< Always false (always folded) */
- OEQ, /**< True if ordered and equal */
- OGT, /**< True if ordered and greater than */
- OGE, /**< True if ordered and greater than or equal */
- OLT, /**< True if ordered and less than */
- OLE, /**< True if ordered and less than or equal */
- ONE, /**< True if ordered and operands are unequal */
- ORD, /**< True if ordered (no nans) */
- UNO, /**< True if unordered: isnan(X) | isnan(Y) */
- UEQ, /**< True if unordered or equal */
- UGT, /**< True if unordered or greater than */
- UGE, /**< True if unordered, greater than, or equal */
- ULT, /**< True if unordered or less than */
- ULE, /**< True if unordered, less than, or equal */
- UNE, /**< True if unordered or not equal */
- True /**< Always true (always folded) */
+ LLVMRealPredicateFalse, /**< Always false (always folded) */
+ LLVMRealOEQ, /**< True if ordered and equal */
+ LLVMRealOGT, /**< True if ordered and greater than */
+ LLVMRealOGE, /**< True if ordered and greater than or equal */
+ LLVMRealOLT, /**< True if ordered and less than */
+ LLVMRealOLE, /**< True if ordered and less than or equal */
+ LLVMRealONE, /**< True if ordered and operands are unequal */
+ LLVMRealORD, /**< True if ordered (no nans) */
+ LLVMRealUNO, /**< True if unordered: isnan(X) | isnan(Y) */
+ LLVMRealUEQ, /**< True if unordered or equal */
+ LLVMRealUGT, /**< True if unordered or greater than */
+ LLVMRealUGE, /**< True if unordered, greater than, or equal */
+ LLVMRealULT, /**< True if unordered or less than */
+ LLVMRealULE, /**< True if unordered, less than, or equal */
+ LLVMRealUNE, /**< True if unordered or not equal */
+ LLVMRealPredicateTrue /**< Always true (always folded) */
}
enum LLVMLandingPadClauseTy {
- Catch, /**< A catch clause */
- Filter /**< A filter clause */
+ LLVMLandingPadCatch, /**< A catch clause */
+ LLVMLandingPadFilter /**< A filter clause */
}
+/**
+ * @}
+ */
+
void LLVMInitializeCore(LLVMPassRegistryRef R);
/*===-- Error handling ----------------------------------------------------===*/
-void LLVMDisposeMessage(char* Message);
+void LLVMDisposeMessage(char *Message);
-/*===-- Contexts ----------------------------------------------------------===*/
+/**
+ * @defgroup LLVMCCoreContext Contexts
+ *
+ * Contexts are execution states for the core LLVM IR system.
+ *
+ * Most types are tied to a context instance. Multiple contexts can
+ * exist simultaneously. A single context is not thread safe. However,
+ * different contexts can execute on different threads simultaneously.
+ *
+ * @{
+ */
-/* Create and destroy contexts. */
+/**
+ * Create a new context.
+ *
+ * Every call to this function should be paired with a call to
+ * LLVMContextDispose() or the context will leak memory.
+ */
LLVMContextRef LLVMContextCreate();
+
+/**
+ * Obtain the global context instance.
+ */
LLVMContextRef LLVMGetGlobalContext();
+
+/**
+ * Destroy a context instance.
+ *
+ * This should be called for every call to LLVMContextCreate() or memory
+ * will be leaked.
+ */
void LLVMContextDispose(LLVMContextRef C);
-uint LLVMGetMDKindIDInContext(LLVMContextRef C, /*const*/ const(char)* Name,
- uint SLen);
-uint LLVMGetMDKindID(/*const*/ const(char)* Name, uint SLen);
+uint LLVMGetMDKindIDInContext(LLVMContextRef C, const(char)* Name,
+ uint SLen);
+uint LLVMGetMDKindID(const(char)* Name, uint SLen);
+
+/**
+ * @}
+ */
+
+/**
+ * @defgroup LLVMCCoreModule Modules
+ *
+ * Modules represent the top-level structure in a LLVM program. An LLVM
+ * module is effectively a translation unit or a collection of
+ * translation units merged together.
+ *
+ * @{
+ */
-/*===-- Modules -----------------------------------------------------------===*/
+/**
+ * Create a new, empty module in the global context.
+ *
+ * This is equivalent to calling LLVMModuleCreateWithNameInContext with
+ * LLVMGetGlobalContext() as the context parameter.
+ *
+ * Every invocation should be paired with LLVMDisposeModule() or memory
+ * will be leaked.
+ */
+LLVMModuleRef LLVMModuleCreateWithName(const(char) *ModuleID);
-/* Create and destroy modules. */
-/** See llvm::Module::Module. */
-LLVMModuleRef LLVMModuleCreateWithName(/*const*/ const(char)* ModuleID);
-LLVMModuleRef LLVMModuleCreateWithNameInContext(/*const*/ const(char)* ModuleID,
+/**
+ * Create a new, empty module in a specific context.
+ *
+ * Every invocation should be paired with LLVMDisposeModule() or memory
+ * will be leaked.
+ */
+LLVMModuleRef LLVMModuleCreateWithNameInContext(const(char) *ModuleID,
LLVMContextRef C);
-/** See llvm::Module::~Module. */
+/**
+ * Destroy a module instance.
+ *
+ * This must be called for every created module or memory will be
+ * leaked.
+ */
void LLVMDisposeModule(LLVMModuleRef M);
-/** Data layout. See Module::getDataLayout. */
-/*const*/ const(char)* LLVMGetDataLayout(LLVMModuleRef M);
-void LLVMSetDataLayout(LLVMModuleRef M, /*const*/ const(char)* Triple);
+/**
+ * Obtain the data layout for a module.
+ *
+ * @see Module::getDataLayout()
+ */
+const(char) *LLVMGetDataLayout(LLVMModuleRef M);
+
+/**
+ * Set the data layout for a module.
+ *
+ * @see Module::setDataLayout()
+ */
+void LLVMSetDataLayout(LLVMModuleRef M, const(char) *Triple);
+
+/**
+ * Obtain the target triple for a module.
+ *
+ * @see Module::getTargetTriple()
+ */
+const(char) *LLVMGetTarget(LLVMModuleRef M);
-/** Target triple. See Module::getTargetTriple. */
-/*const*/ const(char)* LLVMGetTarget(LLVMModuleRef M);
-void LLVMSetTarget(LLVMModuleRef M, /*const*/ const(char)* Triple);
+/**
+ * Set the target triple for a module.
+ *
+ * @see Module::setTargetTriple()
+ */
+void LLVMSetTarget(LLVMModuleRef M, const(char) *Triple);
-/** See Module::dump. */
+/**
+ * Dump a representation of a module to stderr.
+ *
+ * @see Module::dump()
+ */
void LLVMDumpModule(LLVMModuleRef M);
-/** See Module::setModuleInlineAsm. */
-void LLVMSetModuleInlineAsm(LLVMModuleRef M, /*const*/ const(char)* Asm);
+/**
+ * Set inline assembly for a module.
+ *
+ * @see Module::setModuleInlineAsm()
+ */
+void LLVMSetModuleInlineAsm(LLVMModuleRef M, const(char) *Asm);
-/** See Module::getContext. */
+/**
+ * Obtain the context to which this module is associated.
+ *
+ * @see Module::getContext()
+ */
LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
-/*===-- Types -------------------------------------------------------------===*/
+/**
+ * Obtain a Type from a module by its registered name.
+ */
+LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const(char) *Name);
+
+/**
+ * Obtain the number of operands for named metadata in a module.
+ *
+ * @see llvm::Module::getNamedMetadata()
+ */
+uint LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const(char)* name);
+
+/**
+ * Obtain the named metadata operands for a module.
+ *
+ * The passed LLVMValueRef pointer should refer to an array of
+ * LLVMValueRef at least LLVMGetNamedMetadataNumOperands long. This
+ * array will be populated with the LLVMValueRef instances. Each
+ * instance corresponds to a llvm::MDNode.
+ *
+ * @see llvm::Module::getNamedMetadata()
+ * @see llvm::MDNode::getOperand()
+ */
+void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const(char)* name, LLVMValueRef *Dest);
+
+/**
+ * Add an operand to named metadata.
+ *
+ * @see llvm::Module::getNamedMetadata()
+ * @see llvm::MDNode::addOperand()
+ */
+void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const(char)* name,
+ LLVMValueRef Val);
+
+/**
+ * Add a function to a module under a specified name.
+ *
+ * @see llvm::Function::Create()
+ */
+LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const(char) *Name,
+ LLVMTypeRef FunctionTy);
+
+/**
+ * Obtain a Function value from a Module by its name.
+ *
+ * The returned value corresponds to a llvm::Function value.
+ *
+ * @see llvm::Module::getFunction()
+ */
+LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const(char) *Name);
+
+/**
+ * Obtain an iterator to the first Function in a Module.
+ *
+ * @see llvm::Module::begin()
+ */
+LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M);
+
+/**
+ * Obtain an iterator to the last Function in a Module.
+ *
+ * @see llvm::Module::end()
+ */
+LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M);
+
+/**
+ * Advance a Function iterator to the next Function.
+ *
+ * Returns NULL if the iterator was already at the end and there are no more
+ * functions.
+ */
+LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn);
+
+/**
+ * Decrement a Function iterator to the previous Function.
+ *
+ * Returns NULL if the iterator was already at the beginning and there are
+ * no previous functions.
+ */
+LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn);
+
+/**
+ * @}
+ */
-/* LLVM types conform to the following hierarchy:
+/**
+ * @defgroup LLVMCCoreType Types
+ *
+ * Types represent the type of a value.
+ *
+ * Types are associated with a context instance. The context internally
+ * deduplicates types so there is only 1 instance of a specific type
+ * alive at a time. In other words, a unique type is shared among all
+ * consumers within a context.
+ *
+ * A Type in the C API corresponds to llvm::Type.
+ *
+ * Types have the following hierarchy:
*
* types:
* integer type
@@ -351,23 +602,55 @@ LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M);
* void type
* label type
* opaque type
+ *
+ * @{
*/
-/** See llvm::LLVMTypeKind::getTypeID. */
+/**
+ * Obtain the enumerated type of a Type instance.
+ *
+ * @see llvm::Type:getTypeID()
+ */
LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty);
+
+/**
+ * Whether the type has a known size.
+ *
+ * Things that don't have a size are abstract types, labels, and void.a
+ *
+ * @see llvm::Type::isSized()
+ */
LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty);
-/** See llvm::LLVMType::getContext. */
+/**
+ * Obtain the context to which this type instance is associated.
+ *
+ * @see llvm::Type::getContext()
+ */
LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty);
-/* Operations on integer types */
+/**
+ * @defgroup LLVMCCoreTypeInt Integer Types
+ *
+ * Functions in this section operate on integer types.
+ *
+ * @{
+ */
+
+/**
+ * Obtain an integer type from a context with specified bit width.
+ */
LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C);
LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C);
LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C);
LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C);
LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C);
LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, uint NumBits);
+/**
+ * Obtain an integer type from the global context with a specified bit
+ * width.
+ */
LLVMTypeRef LLVMInt1Type();
LLVMTypeRef LLVMInt8Type();
LLVMTypeRef LLVMInt16Type();
@@ -376,160 +659,811 @@ LLVMTypeRef LLVMInt64Type();
LLVMTypeRef LLVMIntType(uint NumBits);
uint LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy);
-/* Operations on real types */
+/**
+ * @}
+ */
+
+/**
+ * @defgroup LLVMCCoreTypeFloat Floating Point Types
+ *
+ * @{
+ */
+
+/**
+ * Obtain a 16-bit floating point type from a context.
+ */
+LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C);
+
+/**
+ * Obtain a 32-bit floating point type from a context.
+ */
LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C);
+
+/**
+ * Obtain a 64-bit floating point type from a context.
+ */
LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C);
+
+/**
+ * Obtain a 80-bit floating point type (X87) from a context.
+ */
LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C);
+
+/**
+ * Obtain a 128-bit floating point type (112-bit mantissa) from a
+ * context.
+ */
LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C);
+
+/**
+ * Obtain a 128-bit floating point type (two 64-bits) from a context.
+ */
LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C);
+/**
+ * Obtain a floating point type from the global context.
+ *
+ * These map to the functions in this group of the same name.
+ */
+LLVMTypeRef LLVMHalfType();
LLVMTypeRef LLVMFloatType();
LLVMTypeRef LLVMDoubleType();
LLVMTypeRef LLVMX86FP80Type();
LLVMTypeRef LLVMFP128Type();
LLVMTypeRef LLVMPPCFP128Type();
-/* Operations on function types */
+/**
+ * @}
+ */
+
+/**
+ * @defgroup LLVMCCoreTypeFunction Function Types
+ *
+ * @{
+ */
+
+/**
+ * Obtain a function type consisting of a specified signature.
+ *
+ * The function is defined as a tuple of a return Type, a list of
+ * parameter types, and whether the function is variadic.
+ */
LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
- LLVMTypeRef* ParamTypes, uint ParamCount,
+ LLVMTypeRef *ParamTypes, uint ParamCount,
LLVMBool IsVarArg);
+
+/**
+ * Returns whether a function type is variadic.
+ */
LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy);
+
+/**
+ * Obtain the Type this function Type returns.
+ */
LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy);
-uint LLVMCountParamTypes(LLVMTypeRef FunctionTy);
-void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef* Dest);
-/* Operations on struct types */
-LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef* ElementTypes,
- uint ElementCount, LLVMBool Packed);
-LLVMTypeRef LLVMStructType(LLVMTypeRef* ElementTypes, uint ElementCount,
- LLVMBool Packed);
-LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, /*const*/ char* Name);
-/*const*/ char* LLVMGetStructName(LLVMTypeRef Ty);
-void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef* ElementTypes,
- uint ElementCount, LLVMBool Packed);
+/**
+ * Obtain the number of parameters this function accepts.
+ */
+uint LLVMCountParamTypes(LLVMTypeRef FunctionTy);
-uint LLVMCountStructElementTypes(LLVMTypeRef StructTy);
-void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef* Dest);
-LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
-LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
+/**
+ * Obtain the types of a function's parameters.
+ *
+ * The Dest parameter should point to a pre-allocated array of
+ * LLVMTypeRef at least LLVMCountParamTypes() large. On return, the
+ * first LLVMCountParamTypes() entries in the array will be populated
+ * with LLVMTypeRef instances.
+ *
+ * @param FunctionTy The function type to operate on.
+ * @param Dest Memory address of an array to be filled with result.
+ */
+void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest);
-LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, /*const*/ char* Name);
+/**
+ * @}
+ */
-/* Operations on array, pointer, and vector types (sequence types) */
-LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, uint ElementCount);
-LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, uint AddressSpace);
-LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, uint ElementCount);
+/**
+ * @defgroup LLVMCCoreTypeStruct Structure Types
+ *
+ * These functions relate to LLVMTypeRef instances.
+ *
+ * @see llvm::StructType
+ *
+ * @{
+ */
-LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
-uint LLVMGetArrayLength(LLVMTypeRef ArrayTy);
-uint LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
-uint LLVMGetVectorSize(LLVMTypeRef VectorTy);
+/**
+ * Create a new structure type in a context.
+ *
+ * A structure is specified by a list of inner elements/types and
+ * whether these can be packed together.
+ *
+ * @see llvm::StructType::create()
+ */
+LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
+ uint ElementCount, LLVMBool Packed);
-/* Operations on other types */
-LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
-LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
-LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
+/**
+ * Create a new structure type in the global context.
+ *
+ * @see llvm::StructType::create()
+ */
+LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes, uint ElementCount,
+ LLVMBool Packed);
+/**
+ * Create an empty structure in a context having a specified name.
+ *
+ * @see llvm::StructType::create()
+ */
+LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const(char) *Name);
+
+/**
+ * Obtain the name of a structure.
+ *
+ * @see llvm::StructType::getName()
+ */
+const(char) *LLVMGetStructName(LLVMTypeRef Ty);
+
+/**
+ * Set the contents of a structure type.
+ *
+ * @see llvm::StructType::setBody()
+ */
+void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
+ uint ElementCount, LLVMBool Packed);
+
+/**
+ * Get the number of elements defined inside the structure.
+ *
+ * @see llvm::StructType::getNumElements()
+ */
+uint LLVMCountStructElementTypes(LLVMTypeRef StructTy);
+
+/**
+ * Get the elements within a structure.
+ *
+ * The function is passed the address of a pre-allocated array of
+ * LLVMTypeRef at least LLVMCountStructElementTypes() long. After
+ * invocation, this array will be populated with the structure's
+ * elements. The objects in the destination array will have a lifetime
+ * of the structure type itself, which is the lifetime of the context it
+ * is contained in.
+ */
+void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest);
+
+/**
+ * Determine whether a structure is packed.
+ *
+ * @see llvm::StructType::isPacked()
+ */
+LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy);
+
+/**
+ * Determine whether a structure is opaque.
+ *
+ * @see llvm::StructType::isOpaque()
+ */
+LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy);
+
+/**
+ * @}
+ */
+
+
+/**
+ * @defgroup LLVMCCoreTypeSequential Sequential Types
+ *
+ * Sequential types represents "arrays" of types. This is a super class
+ * for array, vector, and pointer types.
+ *
+ * @{
+ */
+
+/**
+ * Obtain the type of elements within a sequential type.
+ *
+ * This works on array, vector, and pointer types.
+ *
+ * @see llvm::SequentialType::getElementType()
+ */
+LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty);
+
+/**
+ * Create a fixed size array type that refers to a specific type.
+ *
+ * The created type will exist in the context that its element type
+ * exists in.
+ *
+ * @see llvm::ArrayType::get()
+ */
+LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, uint ElementCount);
+
+/**
+ * Obtain the length of an array type.
+ *
+ * This only works on types that represent arrays.
+ *
+ * @see llvm::ArrayType::getNumElements()
+ */
+uint LLVMGetArrayLength(LLVMTypeRef ArrayTy);
+
+/**
+ * Create a pointer type that points to a defined type.
+ *
+ * The created type will exist in the context that its pointee type
+ * exists in.
+ *
+ * @see llvm::PointerType::get()
+ */
+LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, uint AddressSpace);
+
+/**
+ * Obtain the address space of a pointer type.
+ *
+ * This only works on types that represent pointers.
+ *
+ * @see llvm::PointerType::getAddressSpace()
+ */
+uint LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy);
+
+/**
+ * Create a vector type that contains a defined type and has a specific
+ * number of elements.
+ *
+ * The created type will exist in the context thats its element type
+ * exists in.
+ *
+ * @see llvm::VectorType::get()
+ */
+LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, uint ElementCount);
+
+/**
+ * Obtain the number of elements in a vector type.
+ *
+ * This only works on types that represent vectors.
+ *
+ * @see llvm::VectorType::getNumElements()
+ */
+uint LLVMGetVectorSize(LLVMTypeRef VectorTy);
+
+/**
+ * @}
+ */
+
+/**
+ * @defgroup LLVMCCoreTypeOther Other Types
+ *
+ * @{
+ */
+
+/**
+ * Create a void type in a context.
+ */
+LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C);
+
+/**
+ * Create a label type in a context.
+ */
+LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C);
+
+/**
+ * Create a X86 MMX type in a context.
+ */
+LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C);
+
+/**
+ * These are similar to the above functions except they operate on the
+ * global context.
+ */
LLVMTypeRef LLVMVoidType();
LLVMTypeRef LLVMLabelType();
LLVMTypeRef LLVMX86MMXType();
+/**
+ * @}
+ */
-/*===-- Values ------------------------------------------------------------===*/
+/**
+ * @}
+ */
-/* The bulk of LLVM's object model consists of values, which comprise a very
+/**
+ * @defgroup LLVMCCoreValues Values
+ *
+ * The bulk of LLVM's object model consists of values, which comprise a very
* rich type hierarchy.
+ *
+ * LLVMValueRef essentially represents llvm::Value. There is a rich
+ * hierarchy of classes within this type. Depending on the instance
+ * obtain, not all APIs are available.
+ *
+ * Callers can determine the type of a LLVMValueRef by calling the
+ * LLVMIsA* family of functions (e.g. LLVMIsAArgument()). These
+ * functions are defined by a macro, so it isn't obvious which are
+ * available by looking at the Doxygen source code. Instead, look at the
+ * source definition of LLVM_FOR_EACH_VALUE_SUBCLASS and note the list
+ * of value names given. These value names also correspond to classes in
+ * the llvm::Value hierarchy.
+ *
+ * @{
*/
-// macros were removed for these bindings
-/* Operations on all values */
+extern(D) string LLVM_FOR_EACH_VALUE_SUBCLASS(string delegate(string) nothrow fun)
+{
+ string ret;
+ foreach (str; [
+ "Argument",
+ "BasicBlock",
+ "InlineAsm",
+ "MDNode",
+ "MDString",
+ "User",
+ "Constant",
+ "BlockAddress",
+ "ConstantAggregateZero",
+ "ConstantArray",
+ "ConstantExpr",
+ "ConstantFP",
+ "ConstantInt",
+ "ConstantPointerNull",
+ "ConstantStruct",
+ "ConstantVector",
+ "GlobalValue",
+ "Function",
+ "GlobalAlias",
+ "GlobalVariable",
+ "UndefValue",
+ "Instruction",
+ "BinaryOperator",
+ "CallInst",
+ "IntrinsicInst",
+ "DbgInfoIntrinsic",
+ "DbgDeclareInst",
+ "MemIntrinsic",
+ "MemCpyInst",
+ "MemMoveInst",
+ "MemSetInst",
+ "CmpInst",
+ "FCmpInst",
+ "ICmpInst",
+ "ExtractElementInst",
+ "GetElementPtrInst",
+ "InsertElementInst",
+ "InsertValueInst",
+ "LandingPadInst",
+ "PHINode",
+ "SelectInst",
+ "ShuffleVectorInst",
+ "StoreInst",
+ "TerminatorInst",
+ "BranchInst",
+ "IndirectBrInst",
+ "InvokeInst",
+ "ReturnInst",
+ "SwitchInst",
+ "UnreachableInst",
+ "ResumeInst",
+ "UnaryInstruction",
+ "AllocaInst",
+ "CastInst",
+ "BitCastInst",
+ "FPExtInst",
+ "FPToSIInst",
+ "FPToUIInst",
+ "FPTruncInst"
+ "IntToPtrInst",
+ "PtrToIntInst",
+ "SExtInst",
+ "SIToFPInst",
+ "TruncInst",
+ "UIToFPInst"
+ "ZExtInst",
+ "ExtractValueInst",
+ "LoadInst",
+ "VAArgInst"
+ ])
+ {
+ ret ~= fun(str) ~ "\n";
+ }
+ return ret;
+}
+
+/**
+ * @defgroup LLVMCCoreValueGeneral General APIs
+ *
+ * Functions in this section work on all LLVMValueRef instances,
+ * regardless of their sub-type. They correspond to functions available
+ * on llvm::Value.
+ *
+ * @{
+ */
+
+/**
+ * Obtain the type of a value.
+ *
+ * @see llvm::Value::getType()
+ */
LLVMTypeRef LLVMTypeOf(LLVMValueRef Val);
-/*const*/ const(char)* LLVMGetValueName(LLVMValueRef Val);
-void LLVMSetValueName(LLVMValueRef Val, /*const*/ const(char)* Name);
+
+/**
+ * Obtain the string name of a value.
+ *
+ * @see llvm::Value::getName()
+ */
+const(char) *LLVMGetValueName(LLVMValueRef Val);
+
+/**
+ * Set the string name of a value.
+ *
+ * @see llvm::Value::setName()
+ */
+void LLVMSetValueName(LLVMValueRef Val, const(char) *Name);
+
+/**
+ * Dump a representation of a value to stderr.
+ *
+ * @see llvm::Value::dump()
+ */
void LLVMDumpValue(LLVMValueRef Val);
+
+/**
+ * Replace all uses of a value with another one.
+ *
+ * @see llvm::Value::replaceAllUsesWith()
+ */
void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal);
-int LLVMHasMetadata(LLVMValueRef Val);
-LLVMValueRef LLVMGetMetadata(LLVMValueRef Val, uint KindID);
-void LLVMSetMetadata(LLVMValueRef Val, uint KindID, LLVMValueRef Node);
-/* Conversion functions. Return the input value if it is an instance of the
- specified class, otherwise NULL. See llvm::dyn_cast_or_null<>. */
-/*
-#define LLVM_DECLARE_VALUE_CAST(name) \
- LLVMValueRef LLVMIsA##name(LLVMValueRef Val);
-LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DECLARE_VALUE_CAST)
-*/
+/**
+ * Determine whether the specified constant instance is constant.
+ */
+LLVMBool LLVMIsConstant(LLVMValueRef Val);
+
+/**
+ * Determine whether a value instance is undefined.
+ */
+LLVMBool LLVMIsUndef(LLVMValueRef Val);
+
+/**
+ * Convert value instances between types.
+ *
+ * Internally, a LLVMValueRef is "pinned" to a specific type. This
+ * series of functions allows you to cast an instance to a specific
+ * type.
+ *
+ * If the cast is not valid for the specified type, NULL is returned.
+ *
+ * @see llvm::dyn_cast_or_null<>
+ */
+extern(D) mixin(LLVM_FOR_EACH_VALUE_SUBCLASS(delegate string(string name) {
+ return "extern(C) LLVMValueRef LLVMIsA" ~ name ~ "(LLVMValueRef Val);";
+}));
+
+/**
+ * @}
+ */
-/* Operations on Uses */
+/**
+ * @defgroup LLVMCCoreValueUses Usage
+ *
+ * This module defines functions that allow you to inspect the uses of a
+ * LLVMValueRef.
+ *
+ * It is possible to obtain a LLVMUseRef for any LLVMValueRef instance.
+ * Each LLVMUseRef (which corresponds to a llvm::Use instance) holds a
+ * llvm::User and llvm::Value.
+ *
+ * @{
+ */
+
+/**
+ * Obtain the first use of a value.
+ *
+ * Uses are obtained in an iterator fashion. First, call this function
+ * to obtain a reference to the first use. Then, call LLVMGetNextUse()
+ * on that instance and all subsequently obtained instances untl
+ * LLVMGetNextUse() returns NULL.
+ *
+ * @see llvm::Value::use_begin()
+ */
LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val);
+
+/**
+ * Obtain the next use of a value.
+ *
+ * This effectively advances the iterator. It returns NULL if you are on
+ * the final use and no more are available.
+ */
LLVMUseRef LLVMGetNextUse(LLVMUseRef U);
+
+/**
+ * Obtain the user value for a user.
+ *
+ * The returned value corresponds to a llvm::User type.
+ *
+ * @see llvm::Use::getUser()
+ */
LLVMValueRef LLVMGetUser(LLVMUseRef U);
+
+/**
+ * Obtain the value this use corresponds to.
+ *
+ * @see llvm::Use::get().
+ */
LLVMValueRef LLVMGetUsedValue(LLVMUseRef U);
-/* Operations on Users */
+/**
+ * @}
+ */
+
+/**
+ * @defgroup LLVMCCoreValueUser User value
+ *
+ * Function in this group pertain to LLVMValueRef instances that descent
+ * from llvm::User. This includes constants, instructions, and
+ * operators.
+ *
+ * @{
+ */
+
+/**
+ * Obtain an operand at a specific index in a llvm::User value.
+ *
+ * @see llvm::User::getOperand()
+ */
LLVMValueRef LLVMGetOperand(LLVMValueRef Val, uint Index);
+
+/**
+ * Set an operand at a specific index in a llvm::User value.
+ *
+ * @see llvm::User::setOperand()
+ */
void LLVMSetOperand(LLVMValueRef User, uint Index, LLVMValueRef Val);
+
+/**
+ * Obtain the number of operands in a llvm::User value.
+ *
+ * @see llvm::User::getNumOperands()
+ */
int LLVMGetNumOperands(LLVMValueRef Val);
-/* Operations on constants of any type */
+/**
+ * @}
+ */
+
+/**
+ * @defgroup LLVMCCoreValueConstant Constants
+ *
+ * This section contains APIs for interacting with LLVMValueRef that
+ * correspond to llvm::Constant instances.
+ *
+ * These functions will work for any LLVMValueRef in the llvm::Constant
+ * class hierarchy.
+ *
+ * @{
+ */
+
+/**
+ * Obtain a constant value referring to the null instance of a type.
+ *
+ * @see llvm::Constant::getNullValue()
+ */
LLVMValueRef LLVMConstNull(LLVMTypeRef Ty); /* all zeroes */
-LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty); /* only for int/vector */
+
+/**
+ * Obtain a constant value referring to the instance of a type
+ * consisting of all ones.
+ *
+ * This is only valid for integer types.
+ *
+ * @see llvm::Constant::getAllOnesValue()
+ */
+LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty);
+
+/**
+ * Obtain a constant value referring to an undefined value of a type.
+ *
+ * @see llvm::UndefValue::get()
+ */
LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty);
-LLVMBool LLVMIsConstant(LLVMValueRef Val);
+
+/**
+ * Determine whether a value instance is null.
+ *
+ * @see llvm::Constant::isNullValue()
+ */
LLVMBool LLVMIsNull(LLVMValueRef Val);
-LLVMBool LLVMIsUndef(LLVMValueRef Val);
+
+/**
+ * Obtain a constant that is a constant pointer pointing to NULL for a
+ * specified type.
+ */
LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty);
-/* Operations on metadata */
-LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, /*const*/ const(char)* Str,
- uint SLen);
-LLVMValueRef LLVMMDString(/*const*/ const(char)* Str, uint SLen);
-LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef* Vals,
- uint Count);
-LLVMValueRef LLVMMDNode(LLVMValueRef* Vals, uint Count);
-/*const*/ char* LLVMGetMDString(LLVMValueRef V, uint* Len);
-int LLVMGetMDNodeNumOperands(LLVMValueRef V);
-LLVMValueRef *LLVMGetMDNodeOperand(LLVMValueRef V, uint i);
-uint LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, /*const*/ char* name);
-void LLVMGetNamedMetadataOperands(LLVMModuleRef M, /*const*/ char* name, LLVMValueRef *Dest);
-
-/* Operations on scalar constants */
+/**
+ * @defgroup LLVMCCoreValueConstantScalar Scalar constants
+ *
+ * Functions in this group model LLVMValueRef instances that correspond
+ * to constants referring to scalar types.
+ *
+ * For integer types, the LLVMTypeRef parameter should correspond to a
+ * llvm::IntegerType instance and the returned LLVMValueRef will
+ * correspond to a llvm::ConstantInt.
+ *
+ * For floating point types, the LLVMTypeRef returned corresponds to a
+ * llvm::ConstantFP.
+ *
+ * @{
+ */
+
+/**
+ * Obtain a constant value for an integer type.
+ *
+ * The returned value corresponds to a llvm::ConstantInt.
+ *
+ * @see llvm::ConstantInt::get()
+ *
+ * @param IntTy Integer type to obtain value of.
+ * @param N The value the returned instance should refer to.
+ * @param SignExtend Whether to sign extend the produced value.
+ */
LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, ulong N,
LLVMBool SignExtend);
+
+/**
+ * Obtain a constant value for an integer of arbitrary precision.
+ *
+ * @see llvm::ConstantInt::get()
+ */
LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
uint NumWords,
- /*const*/ ulong* Words);
-LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, /*const*/ const(char)* Text,
- ubyte Radix);
-LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, /*const*/ const(char)* Text,
- uint SLen, ubyte Radix);
+ const uint64_t Words[]);
+
+/**
+ * Obtain a constant value for an integer parsed from a string.
+ *
+ * A similar API, LLVMConstIntOfStringAndSize is also available. If the
+ * string's length is available, it is preferred to call that function
+ * instead.
+ *
+ * @see llvm::ConstantInt::get()
+ */
+LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const(char) *Text,
+ uint8_t Radix);
+
+/**
+ * Obtain a constant value for an integer parsed from a string with
+ * specified length.
+ *
+ * @see llvm::ConstantInt::get()
+ */
+LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const(char) *Text,
+ uint SLen, uint8_t Radix);
+
+/**
+ * Obtain a constant value referring to a double floating point value.
+ */
LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N);
-LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, /*const*/ const(char)* Text);
-LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, /*const*/ const(char)* Text,
+
+/**
+ * Obtain a constant for a floating point value parsed from a string.
+ *
+ * A similar API, LLVMConstRealOfStringAndSize is also available. It
+ * should be used if the input string's length is known.
+ */
+LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const(char) *Text);
+
+/**
+ * Obtain a constant for a floating point value parsed from a string.
+ */
+LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const(char) *Text,
uint SLen);
+
+/**
+ * Obtain the zero extended value for an integer constant value.