69 changes: 0 additions & 69 deletions llvm/LICENSE.TXT

This file was deleted.

158 changes: 0 additions & 158 deletions llvm/Target.cpp

This file was deleted.

29 changes: 21 additions & 8 deletions llvm/c/Analysis.d
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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 *|
|* *|
Expand All @@ -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. */
Expand All @@ -41,3 +50,7 @@ LLVMBool LLVMVerifyFunction(LLVMValueRef Fn, LLVMVerifierFailureAction Action);
Useful for debugging. */
void LLVMViewFunctionCFG(LLVMValueRef Fn);
void LLVMViewFunctionCFGOnly(LLVMValueRef Fn);

/**
* @}
*/
43 changes: 27 additions & 16 deletions llvm/c/BitReader.d
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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 *|
|* *|
Expand All @@ -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);

/**
* @}
*/
26 changes: 19 additions & 7 deletions llvm/c/BitWriter.d
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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 *|
|* *|
Expand All @@ -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);

/**
* @}
*/
2,517 changes: 2,041 additions & 476 deletions llvm/c/Core.d
100755 → 100644

Large diffs are not rendered by default.

70 changes: 35 additions & 35 deletions llvm/c/Disassembler.d
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@
|* LLVM provides an implementation of this interface. *|
|* *|
\*===----------------------------------------------------------------------===*/
module llvm.c.Disassembler;

import llvm.c.Core;
module llvm.c.disassembler;

extern(C):
import core.stdc.stdint : uint8_t, uint64_t;
import core.stdc.stddef;

//#include "llvm/Support/DataTypes.h"
//#include <stddef.h>
extern(C) nothrow:

/**
* @defgroup LLVMCDisassembler Disassembler
* @ingroup LLVMC
*
* @{
*/

/**
* An opaque reference to a disassembler context.
Expand All @@ -42,9 +48,9 @@ alias void *LLVMDisasmContextRef;
* TagType for that Triple. If symbolic information is returned the function
* returns 1, otherwise it returns 0.
*/
alias int (*LLVMOpInfoCallback)(void *DisInfo, uint64_t PC,
uint64_t Offset, uint64_t Size,
int TagType, void *TagBuf);
alias int function(void *DisInfo, uint64_t PC,
uint64_t Offset, uint64_t Size,
int TagType, void *TagBuf) LLVMOpInfoCallback;

/**
* The initial support in LLVM MC for the most general form of a relocatable
Expand All @@ -68,27 +74,27 @@ alias int (*LLVMOpInfoCallback)(void *DisInfo, uint64_t PC,
*/
struct LLVMOpInfoSymbol1 {
uint64_t Present; /* 1 if this symbol is present */
const char *Name; /* symbol name if not NULL */
const(char) *Name; /* symbol name if not NULL */
uint64_t Value; /* symbol value if name is NULL */
};

struct LLVMOpInfo1 {
struct LLVMOpInfoSymbol1 AddSymbol;
struct LLVMOpInfoSymbol1 SubtractSymbol;
LLVMOpInfoSymbol1 AddSymbol;
LLVMOpInfoSymbol1 SubtractSymbol;
uint64_t Value;
uint64_t VariantKind;
};

/**
* The operand VariantKinds for symbolic disassembly.
*/
#define LLVMDisassembler_VariantKind_None 0 /* all targets */
enum LLVMDisassembler_VariantKind_None = 0; /* all targets */

/**
* The ARM target VariantKinds.
*/
#define LLVMDisassembler_VariantKind_ARM_HI16 1 /* :upper16: */
#define LLVMDisassembler_VariantKind_ARM_LO16 2 /* :lower16: */
enum LLVMDisassembler_VariantKind_ARM_HI16 = 1; /* :upper16: */
enum LLVMDisassembler_VariantKind_ARM_LO16 = 2; /* :lower16: */

/**
* The type for the symbol lookup function. This may be called by the
Expand All @@ -102,32 +108,28 @@ struct LLVMOpInfo1 {
* indirectly in ReferenceType along with ReferenceName if any, or that is set
* to NULL.
*/
typedef const char *(*LLVMSymbolLookupCallback)(void *DisInfo,
uint64_t ReferenceValue,
uint64_t *ReferenceType,
uint64_t ReferencePC,
const char **ReferenceName);
alias const(char) *function(void *DisInfo,
uint64_t ReferenceValue,
uint64_t *ReferenceType,
uint64_t ReferencePC,
const(char) **ReferenceName) LLVMSymbolLookupCallback;
/**
* The reference types on input and output.
*/
/* No input reference type or no output reference type. */
#define LLVMDisassembler_ReferenceType_InOut_None 0
enum LLVMDisassembler_ReferenceType_InOut_None = 0;

/* The input reference is from a branch instruction. */
#define LLVMDisassembler_ReferenceType_In_Branch 1
enum LLVMDisassembler_ReferenceType_In_Branch = 1;
/* The input reference is from a PC relative load instruction. */
#define LLVMDisassembler_ReferenceType_In_PCrel_Load 2
enum LLVMDisassembler_ReferenceType_In_PCrel_Load = 2;

/* The output reference is to as symbol stub. */
#define LLVMDisassembler_ReferenceType_Out_SymbolStub 1
enum LLVMDisassembler_ReferenceType_Out_SymbolStub = 1;
/* The output reference is to a symbol address in a literal pool. */
#define LLVMDisassembler_ReferenceType_Out_LitPool_SymAddr 2
enum LLVMDisassembler_ReferenceType_Out_LitPool_SymAddr = 2;
/* The output reference is to a cstring address in a literal pool. */
#define LLVMDisassembler_ReferenceType_Out_LitPool_CstrAddr 3

#ifdef __cplusplus
extern "C" {
#endif /* !defined(__cplusplus) */
enum LLVMDisassembler_ReferenceType_Out_LitPool_CstrAddr = 3;

/**
* Create a disassembler for the TripleName. Symbolic disassembly is supported
Expand All @@ -136,7 +138,7 @@ extern "C" {
* as NULL. If successful, this returns a disassembler context. If not, it
* returns NULL.
*/
LLVMDisasmContextRef LLVMCreateDisasm(const char *TripleName, void *DisInfo,
LLVMDisasmContextRef LLVMCreateDisasm(const(char) *TripleName, void *DisInfo,
int TagType, LLVMOpInfoCallback GetOpInfo,
LLVMSymbolLookupCallback SymbolLookUp);

Expand All @@ -159,8 +161,6 @@ size_t LLVMDisasmInstruction(LLVMDisasmContextRef DC, uint8_t *Bytes,
uint64_t BytesSize, uint64_t PC,
char *OutString, size_t OutStringSize);

#ifdef __cplusplus
}
#endif /* !defined(__cplusplus) */

#endif /* !defined(LLVM_C_DISASSEMBLER_H) */
/**
* @}
*/
141 changes: 82 additions & 59 deletions llvm/c/EnhancedDisassembly.d
100755 → 100644

Large diffs are not rendered by default.

69 changes: 41 additions & 28 deletions llvm/c/ExecutionEngine.d
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*===-- llvm-c/ExecutionEngine.h - ExecutionEngine Lib C Iface --*- D -*-===*\
/*===-- llvm-c/ExecutionEngine.h - ExecutionEngine Lib C Iface --*- C++ -*-===*\
|* *|
|* The LLVM Compiler Infrastructure *|
|* *|
Expand All @@ -15,27 +15,36 @@
|* tools written in such languages. *|
|* *|
\*===----------------------------------------------------------------------===*/
module llvm.c.ExecutionEngine;

import llvm.c.Core;
import llvm.c.Target;
module llvm.c.enhanceddisassembly;

extern(C):
import llvm.c.core;
import llvm.c.target;

extern(C) nothrow:

/**
* @defgroup LLVMCExecutionEngine Execution Engine
* @ingroup LLVMC
*
* @{
*/

void LLVMLinkInJIT();
void LLVMLinkInInterpreter();

alias /*struct LLVMOpaqueGenericValue*/ void* LLVMGenericValueRef;
alias /* struct LLVMOpaqueExecutionEngine*/ void* LLVMExecutionEngineRef;
struct __LLVMOpaqueGenericValue {};
alias __LLVMOpaqueGenericValue *LLVMGenericValueRef;
struct __LLVMOpaqueExecutionEngine {};
alias __LLVMOpaqueExecutionEngine *LLVMExecutionEngineRef;

/*===-- Operations on generic values --------------------------------------===*/

LLVMGenericValueRef LLVMCreateGenericValueOfInt(LLVMTypeRef Ty,
ulong N,
LLVMBool IsSigned);

LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void* P);
LLVMGenericValueRef LLVMCreateGenericValueOfPointer(void *P);

LLVMGenericValueRef LLVMCreateGenericValueOfFloat(LLVMTypeRef Ty, double N);

Expand All @@ -44,42 +53,42 @@ uint LLVMGenericValueIntWidth(LLVMGenericValueRef GenValRef);
ulong LLVMGenericValueToInt(LLVMGenericValueRef GenVal,
LLVMBool IsSigned);

void* LLVMGenericValueToPointer(LLVMGenericValueRef GenVal);
void *LLVMGenericValueToPointer(LLVMGenericValueRef GenVal);

double LLVMGenericValueToFloat(LLVMTypeRef TyRef, LLVMGenericValueRef GenVal);

void LLVMDisposeGenericValue(LLVMGenericValueRef GenVal);

/*===-- Operations on execution engines -----------------------------------===*/

LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef* OutEE,
LLVMBool LLVMCreateExecutionEngineForModule(LLVMExecutionEngineRef *OutEE,
LLVMModuleRef M,
char** OutError);
char **OutError);

LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef* OutInterp,
LLVMBool LLVMCreateInterpreterForModule(LLVMExecutionEngineRef *OutInterp,
LLVMModuleRef M,
char** OutError);
char **OutError);

LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef* OutJIT,
LLVMBool LLVMCreateJITCompilerForModule(LLVMExecutionEngineRef *OutJIT,
LLVMModuleRef M,
uint OptLevel,
char** OutError);
char **OutError);

/** Deprecated: Use LLVMCreateExecutionEngineForModule instead. */
LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef* OutEE,
LLVMBool LLVMCreateExecutionEngine(LLVMExecutionEngineRef *OutEE,
LLVMModuleProviderRef MP,
char** OutError);
char **OutError);

/** Deprecated: Use LLVMCreateInterpreterForModule instead. */
LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef* OutInterp,
LLVMBool LLVMCreateInterpreter(LLVMExecutionEngineRef *OutInterp,
LLVMModuleProviderRef MP,
char** OutError);
char **OutError);

/** Deprecated: Use LLVMCreateJITCompilerForModule instead. */
LLVMBool LLVMCreateJITCompiler(LLVMExecutionEngineRef *OutJIT,
LLVMModuleProviderRef MP,
uint OptLevel,
char** OutError);
char **OutError);

void LLVMDisposeExecutionEngine(LLVMExecutionEngineRef EE);

Expand All @@ -88,12 +97,12 @@ void LLVMRunStaticConstructors(LLVMExecutionEngineRef EE);
void LLVMRunStaticDestructors(LLVMExecutionEngineRef EE);

int LLVMRunFunctionAsMain(LLVMExecutionEngineRef EE, LLVMValueRef F,
uint ArgC, /*const*/ char* /*const*/* ArgV,
/*const*/ char* /*const*/* EnvP);
uint ArgC, const(char*) *ArgV,
const(char*) *EnvP);

LLVMGenericValueRef LLVMRunFunction(LLVMExecutionEngineRef EE, LLVMValueRef F,
uint NumArgs,
LLVMGenericValueRef* Args);
LLVMGenericValueRef *Args);

void LLVMFreeMachineCodeForFunction(LLVMExecutionEngineRef EE, LLVMValueRef F);

Expand All @@ -103,15 +112,15 @@ void LLVMAddModule(LLVMExecutionEngineRef EE, LLVMModuleRef M);
void LLVMAddModuleProvider(LLVMExecutionEngineRef EE, LLVMModuleProviderRef MP);

LLVMBool LLVMRemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M,
LLVMModuleRef* OutMod, char** OutError);
LLVMModuleRef *OutMod, char **OutError);

/** Deprecated: Use LLVMRemoveModule instead. */
LLVMBool LLVMRemoveModuleProvider(LLVMExecutionEngineRef EE,
LLVMModuleProviderRef MP,
LLVMModuleRef* OutMod, char** OutError);
LLVMModuleRef *OutMod, char **OutError);

LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, /*const*/ char* Name,
LLVMValueRef* OutFn);
LLVMBool LLVMFindFunction(LLVMExecutionEngineRef EE, const(char) *Name,
LLVMValueRef *OutFn);

void *LLVMRecompileAndRelinkFunction(LLVMExecutionEngineRef EE, LLVMValueRef Fn);

Expand All @@ -120,4 +129,8 @@ LLVMTargetDataRef LLVMGetExecutionEngineTargetData(LLVMExecutionEngineRef EE);
void LLVMAddGlobalMapping(LLVMExecutionEngineRef EE, LLVMValueRef Global,
void* Addr);

void* LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);
void *LLVMGetPointerToGlobal(LLVMExecutionEngineRef EE, LLVMValueRef Global);

/**
* @}
*/
22 changes: 18 additions & 4 deletions llvm/c/Initialization.d
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*===-- llvm-c/Initialization.h - Initialization C Interface ------*- D -*-===*\
/*===-- llvm-c/Initialization.h - Initialization C Interface ------*- C -*-===*\
|* *|
|* The LLVM Compiler Infrastructure *|
|* *|
Expand All @@ -12,20 +12,34 @@
|* the corresponding LLVM library. *|
|* *|
\*===----------------------------------------------------------------------===*/
module llvm.c.Initialization;

import llvm.c.Core;
module llvm.c.initialization;

extern(C):
import llvm.c.core;

extern(C) nothrow:

/**
* @defgroup LLVMCInitialization Initialization Routines
* @ingroup LLVMC
*
* This module contains routines used to initialize the LLVM system.
*
* @{
*/

void LLVMInitializeCore(LLVMPassRegistryRef R);
void LLVMInitializeTransformUtils(LLVMPassRegistryRef R);
void LLVMInitializeScalarOpts(LLVMPassRegistryRef R);
void LLVMInitializeVectorization(LLVMPassRegistryRef R);
void LLVMInitializeInstCombine(LLVMPassRegistryRef R);
void LLVMInitializeIPO(LLVMPassRegistryRef R);
void LLVMInitializeInstrumentation(LLVMPassRegistryRef R);
void LLVMInitializeAnalysis(LLVMPassRegistryRef R);
void LLVMInitializeIPA(LLVMPassRegistryRef R);
void LLVMInitializeCodeGen(LLVMPassRegistryRef R);
void LLVMInitializeTarget(LLVMPassRegistryRef R);

/**
* @}
*/
29 changes: 22 additions & 7 deletions llvm/c/LinkTimeOptimizer.d
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//===-- llvm/LinkTimeOptimizer.h - LTO Public C Interface -------*- D -*-===//
//===-- llvm/LinkTimeOptimizer.h - LTO Public C Interface -------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
Expand All @@ -12,18 +12,26 @@
// their implementation for performing LTO.
//
//===----------------------------------------------------------------------===//
module llvm.c.LinkTimeOptimizer;

module llvm.c.linktimeoptimizer;

extern(C):
import llvm.c.core;

extern(C) nothrow:

/**
* @defgroup LLVMCLinkTimeOptimizer Link Time Optimization
* @ingroup LLVMC
*
* @{
*/

/// This provides a dummy type for pointers to the LTO object.
alias void* llvm_lto_t;
alias void* llvm_lto_t;

/// This provides a C-visible enumerator to manage status codes.
/// This should map exactly onto the C++ enumerator LTOStatus.
enum llvm_lto_status {
enum llvm_lto_status {
LLVM_LTO_UNKNOWN,
LLVM_LTO_OPT_SUCCESS,
LLVM_LTO_READ_SUCCESS,
Expand All @@ -37,12 +45,19 @@ enum llvm_lto_status {
// Added C-specific error codes
LLVM_LTO_NULL_OBJECT
}
alias llvm_lto_status llvm_lto_status_t;

/// This provides C interface to initialize link time optimizer. This allows
/// linker to use dlopen() interface to dynamically load LinkTimeOptimizer.
/// extern "C" helps, because dlopen() interface uses name to find the symbol.
extern llvm_lto_t llvm_create_optimizer();
extern void llvm_destroy_optimizer(llvm_lto_t lto);

extern llvm_lto_status llvm_read_object_file(llvm_lto_t lto, /*const*/ char* input_filename);
extern llvm_lto_status llvm_optimize_modules(llvm_lto_t lto, /*const*/ char* output_filename);
extern llvm_lto_status_t llvm_read_object_file
(llvm_lto_t lto, const(char)* input_filename);
extern llvm_lto_status_t llvm_optimize_modules
(llvm_lto_t lto, const(char)* output_filename);

/**
* @}
*/
77 changes: 67 additions & 10 deletions llvm/c/Object.d
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,83 @@
/* tools written in such languages. */
/* */
/*===----------------------------------------------------------------------===*/
module llvm.c.Object;

import llvm.c.Core;
module llvm.c.object;

extern(C):
import core.stdc.stdint : uint64_t;
import llvm.c.core;

struct __LLVMOpaqueObjectFile {}
alias __LLVMOpaqueObjectFile* LLVMObjectFileRef;
extern(C) nothrow:

struct __LLVMOpaqueSectionIterator {}
alias __LLVMOpaqueSectionIterator* LLVMSectionIteratorRef;
/**
* @defgroup LLVMCObject Object file reading and writing
* @ingroup LLVMC
*
* @{
*/

// Opaque type wrappers
struct __LLVMOpaqueObjectFile {};
alias __LLVMOpaqueObjectFile *LLVMObjectFileRef;
struct __LLVMOpaqueSectionIterator {};
alias __LLVMOpaqueSectionIterator *LLVMSectionIteratorRef;
struct __LLVMOpaqueSymbolIterator {};
alias __LLVMOpaqueSymbolIterator *LLVMSymbolIteratorRef;
struct __LLVMOpaqueRelocationIterator {};
alias __LLVMOpaqueRelocationIterator *LLVMRelocationIteratorRef;

// ObjectFile creation
LLVMObjectFileRef LLVMCreateObjectFile(LLVMMemoryBufferRef MemBuf);
void LLVMDisposeObjectFile(LLVMObjectFileRef ObjectFile);

// ObjectFile Section iterators
LLVMSectionIteratorRef LLVMGetSections(LLVMObjectFileRef ObjectFile);
void LLVMDisposeSectionIterator(LLVMSectionIteratorRef SI);
LLVMBool LLVMIsSectionIteratorAtEnd(LLVMObjectFileRef ObjectFile,
LLVMSectionIteratorRef SI);
void LLVMMoveToNextSection(LLVMSectionIteratorRef SI);
/*const*/ char* LLVMGetSectionName(LLVMSectionIteratorRef SI);
ulong LLVMGetSectionSize(LLVMSectionIteratorRef SI);
/*const*/ char* LLVMGetSectionContents(LLVMSectionIteratorRef SI);
void LLVMMoveToContainingSection(LLVMSectionIteratorRef Sect,
LLVMSymbolIteratorRef Sym);

// ObjectFile Symbol iterators
LLVMSymbolIteratorRef LLVMGetSymbols(LLVMObjectFileRef ObjectFile);
void LLVMDisposeSymbolIterator(LLVMSymbolIteratorRef SI);
LLVMBool LLVMIsSymbolIteratorAtEnd(LLVMObjectFileRef ObjectFile,
LLVMSymbolIteratorRef SI);
void LLVMMoveToNextSymbol(LLVMSymbolIteratorRef SI);

// SectionRef accessors
const(char) *LLVMGetSectionName(LLVMSectionIteratorRef SI);
uint64_t LLVMGetSectionSize(LLVMSectionIteratorRef SI);
const(char) *LLVMGetSectionContents(LLVMSectionIteratorRef SI);
uint64_t LLVMGetSectionAddress(LLVMSectionIteratorRef SI);
LLVMBool LLVMGetSectionContainsSymbol(LLVMSectionIteratorRef SI,
LLVMSymbolIteratorRef Sym);

// Section Relocation iterators
LLVMRelocationIteratorRef LLVMGetRelocations(LLVMSectionIteratorRef Section);
void LLVMDisposeRelocationIterator(LLVMRelocationIteratorRef RI);
LLVMBool LLVMIsRelocationIteratorAtEnd(LLVMSectionIteratorRef Section,
LLVMRelocationIteratorRef RI);
void LLVMMoveToNextRelocation(LLVMRelocationIteratorRef RI);


// SymbolRef accessors
const(char) *LLVMGetSymbolName(LLVMSymbolIteratorRef SI);
uint64_t LLVMGetSymbolAddress(LLVMSymbolIteratorRef SI);
uint64_t LLVMGetSymbolFileOffset(LLVMSymbolIteratorRef SI);
uint64_t LLVMGetSymbolSize(LLVMSymbolIteratorRef SI);

// RelocationRef accessors
uint64_t LLVMGetRelocationAddress(LLVMRelocationIteratorRef RI);
uint64_t LLVMGetRelocationOffset(LLVMRelocationIteratorRef RI);
LLVMSymbolIteratorRef LLVMGetRelocationSymbol(LLVMRelocationIteratorRef RI);
uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI);
// NOTE: Caller takes ownership of returned string of the two
// following functions.
const(char) *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI);
const(char) *LLVMGetRelocationValueString(LLVMRelocationIteratorRef RI);

/**
* @}
*/
227 changes: 174 additions & 53 deletions llvm/c/Target.d
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- D -*-===*/
/*===-- llvm-c/Target.h - Target Lib C Iface --------------------*- C++ -*-===*/
/* */
/* The LLVM Compiler Infrastructure */
/* */
Expand All @@ -15,83 +15,200 @@
/* tools written in such languages. */
/* */
/*===----------------------------------------------------------------------===*/
module llvm.c.Target;

import llvm.c.Core;
module llvm.c.target;

extern(C):
import llvm.c.core;

extern(C) nothrow:

enum LLVMByteOrdering { BigEndian, LittleEndian };
/**
* @defgroup LLVMCTarget Target information
* @ingroup LLVMC
*
* @{
*/

struct __LLVMOpaqueTargetData {}
alias __LLVMOpaqueTargetData* LLVMTargetDataRef;
struct __LLVMOpaqueTargetLibraryInfotData {}
alias __LLVMOpaqueTargetLibraryInfotData* LLVMTargetLibraryInfoRef;
struct __LLVMStructLayout {}
alias __LLVMStructLayout* LLVMStructLayoutRef;
enum LLVMByteOrdering { LLVMBigEndian, LLVMLittleEndian };

struct __LLVMOpaqueTargetData {};
alias __LLVMOpaqueTargetData *LLVMTargetDataRef;
struct __LLVMOpaqueTargetLibraryInfotData {};
alias __LLVMOpaqueTargetLibraryInfotData *LLVMTargetLibraryInfoRef;
struct __LLVMStructLayout {};
alias __LLVMStructLayout *LLVMStructLayoutRef;

extern(D) string LLVM_TARGET(string delegate(string) nothrow fun)
{
string ret;
foreach (str; [
"ARM",
"CellSPU",
"CppBackend",
"Hexagon",
"Mips",
"MBlaze",
"MSP430",
"PowerPC",
"PTX",
"Sparc",
"X86",
"XCore",
])
{
ret ~= fun(str) ~ "\n";
}
return ret;
}

/* Declare all of the target-initialization functions that are available. */
/*
#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##TargetInfo();
#include "llvm/Config/Targets.def"
#undef LLVM_TARGET // Explicit undef to make SWIG happier
#define LLVM_TARGET(TargetName) void LLVMInitialize##TargetName##Target();
#include "llvm/Config/Targets.def"
#undef LLVM_TARGET // Explicit undef to make SWIG happier
*/

/*
#define LLVM_TARGET(TargetName) \
void LLVMInitialize##TargetName##TargetMC(void);
#include "llvm/Config/Targets.def"
#undef LLVM_TARGET // Explicit undef to make SWIG happier
*/
extern(D) mixin(LLVM_TARGET(delegate string(string name) {
return "extern(C) void LLVMInitialize" ~ name ~ "TargetInfo();";
}));

extern(D) mixin(LLVM_TARGET(delegate string(string name) {
return "extern(C) void LLVMInitialize" ~ name ~ "Target();";
}));

extern(D) mixin(LLVM_TARGET(delegate string(string name) {
return "extern(C) void LLVMInitialize" ~ name ~ "TargetMC();";
}));


extern(D) string LLVM_ASM_PRINTER(string delegate(string) nothrow fun)
{
string ret;
foreach (str; [
"ARM",
"CellSPU",
"Hexagon",
"Mips",
"MBlaze",
"MSP430",
"PowerPC",
"PTX",
"Sparc",
"X86",
"XCore",
])
{
ret ~= fun(str) ~ "\n";
}
return ret;
}

/* Declare all of the available assembly printer initialization functions. */
extern(D) mixin(LLVM_ASM_PRINTER(delegate string(string name) {
return "extern(C) void LLVMInitialize" ~ name ~ "AsmPrinter();";
}));

extern(D) string LLVM_ASM_PARSER(string delegate(string) nothrow fun)
{
string ret;
foreach (str; [
"ARM",
"Mips",
"MBlaze",
"X86",
])
{
ret ~= fun(str) ~ "\n";
}
return ret;
}

/* Declare all of the available assembly parser initialization functions. */
extern(D) mixin(LLVM_ASM_PARSER(delegate string(string name) {
return "extern(C) void LLVMInitialize" ~ name ~ "AsmParser();";
}));

extern(D) string LLVM_ASM_DISASSEMBLER(string delegate(string) nothrow fun)
{
string ret;
foreach (str; [
"ARM",
"Mips",
"MBlaze",
"X86",
])
{
ret ~= fun(str) ~ "\n";
}
return ret;
}

/* Declare all of the available disassembler initialization functions. */
extern(D) mixin(LLVM_ASM_PARSER(delegate string(string name) {
return "extern(C) void LLVMInitialize" ~ name ~ "Disassembler();";
}));

/** LLVMInitializeAllTargetInfos - The main program should call this function if
it wants access to all available targets that LLVM is configured to
support. */
/*
static inline void LLVMInitializeAllTargetInfos() {
#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##TargetInfo();
#include "llvm/Config/Targets.def"
#undef LLVM_TARGET // Explicit undef to make SWIG happier
static void LLVMInitializeAllTargetInfos() {
mixin(LLVM_TARGET(delegate string(string name) {
return "LLVMInitialize" ~ name ~ "TargetInfo();";
}));
}
*/

/** LLVMInitializeAllTargets - The main program should call this function if it
wants to link in all available targets that LLVM is configured to
support. */
/*
static inline void LLVMInitializeAllTargets() {
#define LLVM_TARGET(TargetName) LLVMInitialize##TargetName##Target();
#include "llvm/Config/Targets.def"
#undef LLVM_TARGET // Explicit undef to make SWIG happier
}*/
static void LLVMInitializeAllTargets() {
mixin(LLVM_TARGET(delegate string(string name) {
return "LLVMInitialize" ~ name ~ "Target();";
}));
}

/** LLVMInitializeAllTargetMCs - The main program should call this function if
it wants access to all available target MC that LLVM is configured to
support. */
static void LLVMInitializeAllTargetMCs() {
mixin(LLVM_TARGET(delegate string(string name) {
return "LLVMInitialize" ~ name ~ "TargetMV();";
}));
}

/** LLVMInitializeAllAsmPrinters - The main program should call this function if
it wants all asm printers that LLVM is configured to support, to make them
available via the TargetRegistry. */
static void LLVMInitializeAllAsmPrinters() {
mixin(LLVM_ASM_PRINTER(delegate string(string name) {
return "LLVMInitialize" ~ name ~ "AsmPrinter();";
}));
}

/** LLVMInitializeAllAsmParsers - The main program should call this function if
it wants all asm parsers that LLVM is configured to support, to make them
available via the TargetRegistry. */
static void LLVMInitializeAllAsmParsers() {
mixin(LLVM_ASM_PARSER(delegate string(string name) {
return "LLVMInitialize" ~ name ~ "AsmParser();";
}));
}

/** LLVMInitializeAllDisassemblers - The main program should call this function
if it wants all disassemblers that LLVM is configured to support, to make
them available via the TargetRegistry. */
static void LLVMInitializeAllDisassemblers() {
mixin(LLVM_ASM_DISASSEMBLER(delegate string(string name) {
return "LLVMInitialize" ~ name ~ "Disassembler();";
}));
}

/** LLVMInitializeNativeTarget - The main program should call this function to
initialize the native target corresponding to the host. This is useful
initialize the native target corresponding to the host. This is useful
for JIT applications to ensure that the target gets linked in correctly. */
/*
static inline LLVMBool LLVMInitializeNativeTarget() {
// If we have a native target, initialize it to ensure it is linked in.
#ifdef LLVM_NATIVE_TARGET
LLVM_NATIVE_TARGETINFO();
LLVM_NATIVE_TARGET();
LLVM_NATIVE_TARGETMC();
return 0;
#else
static LLVMBool LLVMInitializeNativeTarget() {
/* If we have a native target, initialize it to ensure it is linked in. */
return 1;
#endif
}
*/
}

/*===-- Target Data -------------------------------------------------------===*/

/** Creates target data from a target layout string.
See the constructor llvm::TargetData::TargetData. */
LLVMTargetDataRef LLVMCreateTargetData(/*const*/ char* StringRep);
LLVMTargetDataRef LLVMCreateTargetData(const(char) *StringRep);

/** Adds target data information to a pass manager. This does not take ownership
of the target data.
Expand Down Expand Up @@ -163,3 +280,7 @@ ulong LLVMOffsetOfElement(LLVMTargetDataRef, LLVMTypeRef StructTy,
/** Deallocates a TargetData.
See the destructor llvm::TargetData::~TargetData. */
void LLVMDisposeTargetData(LLVMTargetDataRef);

/**
* @}
*/
126 changes: 71 additions & 55 deletions llvm/c/lto.d
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*===-- llvm-c/lto.h - LTO Public C Interface ---------------------*- D -*-===*\
/*===-- llvm-c/lto.h - LTO Public C Interface ---------------------*- C -*-===*\
|* *|
|* The LLVM Compiler Infrastructure *|
|* *|
Expand All @@ -12,124 +12,137 @@
|* llvm bitcode files. *|
|* *|
\*===----------------------------------------------------------------------===*/

module llvm.c.lto;

private alias long off_t; //assumes __USE_LARGEFILE64 = 1
import core.stdc.stddef;
import core.sys.posix.unistd;

extern(C) nothrow:

const LTO_API_VERSION = 4;
/**
* @defgroup LLVMCLTO LTO
* @ingroup LLVMC
*
* @{
*/

enum LTO_API_VERSION = 4;

enum lto_symbol_attributes {
ALIGNMENT_MASK = 0x0000001F, /* log2 of alignment */
PERMISSIONS_MASK = 0x000000E0,
PERMISSIONS_CODE = 0x000000A0,
PERMISSIONS_DATA = 0x000000C0,
PERMISSIONS_RODATA = 0x00000080,
DEFINITION_MASK = 0x00000700,
DEFINITION_REGULAR = 0x00000100,
DEFINITION_TENTATIVE = 0x00000200,
DEFINITION_WEAK = 0x00000300,
DEFINITION_UNDEFINED = 0x00000400,
DEFINITION_WEAKUNDEF = 0x00000500,
SCOPE_MASK = 0x00003800,
SCOPE_INTERNAL = 0x00000800,
SCOPE_HIDDEN = 0x00001000,
SCOPE_PROTECTED = 0x00002000,
SCOPE_DEFAULT = 0x00001800,
SCOPE_DEFAULT_CAN_BE_HIDDEN = 0x00002800
LTO_SYMBOL_ALIGNMENT_MASK = 0x0000001F, /* log2 of alignment */
LTO_SYMBOL_PERMISSIONS_MASK = 0x000000E0,
LTO_SYMBOL_PERMISSIONS_CODE = 0x000000A0,
LTO_SYMBOL_PERMISSIONS_DATA = 0x000000C0,
LTO_SYMBOL_PERMISSIONS_RODATA = 0x00000080,
LTO_SYMBOL_DEFINITION_MASK = 0x00000700,
LTO_SYMBOL_DEFINITION_REGULAR = 0x00000100,
LTO_SYMBOL_DEFINITION_TENTATIVE = 0x00000200,
LTO_SYMBOL_DEFINITION_WEAK = 0x00000300,
LTO_SYMBOL_DEFINITION_UNDEFINED = 0x00000400,
LTO_SYMBOL_DEFINITION_WEAKUNDEF = 0x00000500,
LTO_SYMBOL_SCOPE_MASK = 0x00003800,
LTO_SYMBOL_SCOPE_INTERNAL = 0x00000800,
LTO_SYMBOL_SCOPE_HIDDEN = 0x00001000,
LTO_SYMBOL_SCOPE_PROTECTED = 0x00002000,
LTO_SYMBOL_SCOPE_DEFAULT = 0x00001800,
LTO_SYMBOL_SCOPE_DEFAULT_CAN_BE_HIDDEN = 0x00002800
}

enum lto_debug_model {
MODEL_NONE = 0,
MODEL_DWARF = 1
LTO_DEBUG_MODEL_NONE = 0,
LTO_DEBUG_MODEL_DWARF = 1
}

enum lto_codegen_model{
STATIC = 0,
DYNAMIC = 1,
DYNAMIC_NO_PIC = 2
enum lto_codegen_model {
LTO_CODEGEN_PIC_MODEL_STATIC = 0,
LTO_CODEGEN_PIC_MODEL_DYNAMIC = 1,
LTO_CODEGEN_PIC_MODEL_DYNAMIC_NO_PIC = 2
}


/** opaque reference to a loaded object module */
alias /*struct LTOModule*/ void* lto_module_t;
struct __LTOModule {};
alias __LTOModule* lto_module_t;

/** opaque reference to a code generator */
alias /*struct LTOCodeGenerator*/ void* lto_code_gen_t;

extern(C):
struct __LTOCodeGenerator {};
alias __LTOCodeGenerator* lto_code_gen_t;

/**
* Returns a printable string.
*/
extern /*const*/ char*
extern const(char)*
lto_get_version();


/**
* Returns the last error string or NULL if last operation was successful.
*/
extern /*const*/ char*
extern const(char)*
lto_get_error_message();

/**
* Checks if a file is a loadable object file.
*/
extern bool
lto_module_is_object_file(/*const*/ char* path);
lto_module_is_object_file(const(char)* path);


/**
* Checks if a file is a loadable object compiled for requested target.
*/
extern bool
lto_module_is_object_file_for_target(/*const*/ char* path,
/*const*/ char* target_triple_prefix);
lto_module_is_object_file_for_target(const(char)* path,
const(char)* target_triple_prefix);


/**
* Checks if a buffer is a loadable object file.
*/
extern bool
lto_module_is_object_file_in_memory(/*const*/ void* mem, size_t length);
lto_module_is_object_file_in_memory(const(void)* mem, size_t length);


/**
* Checks if a buffer is a loadable object compiled for requested target.
*/
extern bool
lto_module_is_object_file_in_memory_for_target(/*const*/ void* mem, size_t length, /*const*/ char* target_triple_prefix);
lto_module_is_object_file_in_memory_for_target(const(void)* mem, size_t length,
const(char)* target_triple_prefix);


/**
* Loads an object file from disk.
* Returns NULL on error (check lto_get_error_message() for details).
*/
extern lto_module_t
lto_module_create(/*const*/ char* path);
lto_module_create(const(char)* path);


/**
* Loads an object file from memory.
* Returns NULL on error (check lto_get_error_message() for details).
*/
extern lto_module_t
lto_module_create_from_memory(/*const*/ void* mem, size_t length);
lto_module_create_from_memory(const(void)* mem, size_t length);

/**
* Loads an object file from disk. The seek point of fd is not preserved.
* Returns NULL on error (check lto_get_error_message() for details).
*/
extern lto_module_t
lto_module_create_from_fd(int fd, /*const*/ char* path, size_t size);
lto_module_create_from_fd(int fd, const(char) *path, size_t file_size);

/**
* Loads an object file from disk. The seek point of fd is not preserved.
* Returns NULL on error (check lto_get_error_message() for details).
*/
extern lto_module_t
lto_module_create_from_fd_at_offset(int fd, /*const*/ char* path, size_t file_size,
lto_module_create_from_fd_at_offset(int fd, const(char) *path, size_t file_size,
size_t map_size, off_t offset);


/**
* Frees all memory internally allocated by the module.
* Upon return the lto_module_t is no longer valid.
Expand All @@ -141,14 +154,14 @@ lto_module_dispose(lto_module_t mod);
/**
* Returns triple string which the object module was compiled under.
*/
extern /*const*/ char*
extern const(char)*
lto_module_get_target_triple(lto_module_t mod);

/**
* Sets triple string with which the object will be codegened.
*/
extern void
lto_module_set_target_triple(lto_module_t mod, /*const*/ char* triple);
lto_module_set_target_triple(lto_module_t mod, const(char) *triple);


/**
Expand All @@ -161,7 +174,7 @@ lto_module_get_num_symbols(lto_module_t mod);
/**
* Returns the name of the ith symbol in the object module.
*/
extern /*const*/ char*
extern const(char)*
lto_module_get_symbol_name(lto_module_t mod, uint index);


Expand Down Expand Up @@ -218,20 +231,21 @@ lto_codegen_set_pic_model(lto_code_gen_t cg, lto_codegen_model);
* Sets the cpu to generate code for.
*/
extern void
lto_codegen_set_cpu(lto_code_gen_t cg, /*const*/ char* cpu);
lto_codegen_set_cpu(lto_code_gen_t cg, const(char) *cpu);


/**
* Sets the location of the assembler tool to run. If not set, libLTO
* will use gcc to invoke the assembler.
*/
extern void
lto_codegen_set_assembler_path(lto_code_gen_t cg, /*const*/ char* path);
lto_codegen_set_assembler_path(lto_code_gen_t cg, const(char)* path);

/**
* Sets extra arguments that libLTO should pass to the assembler.
*/
extern void
lto_codegen_set_assembler_args(lto_code_gen_t cg, /*const*/ char** args,
lto_codegen_set_assembler_args(lto_code_gen_t cg, const(char) **args,
int nargs);

/**
Expand All @@ -240,39 +254,41 @@ lto_codegen_set_assembler_args(lto_code_gen_t cg, /*const*/ char** args,
* inlined into every usage and optimized away.
*/
extern void
lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, /*const*/ char* symbol);

lto_codegen_add_must_preserve_symbol(lto_code_gen_t cg, const(char)* symbol);

/**
* Writes a new object file at the specified path that contains the
* merged contents of all modules added so far.
* Returns true on error (check lto_get_error_message() for details).
*/
extern bool
lto_codegen_write_merged_modules(lto_code_gen_t cg, /*const*/ char* path);

lto_codegen_write_merged_modules(lto_code_gen_t cg, const(char)* path);

/**
* Generates code for all added modules into one native object file.
* On success returns a pointer to a generated mach-o/ELF buffer and
* length set to the buffer size. The buffer is owned by the
* length set to the buffer size. The buffer is owned by the
* lto_code_gen_t and will be freed when lto_codegen_dispose()
* is called, or lto_codegen_compile() is called again.
* On failure, returns NULL (check lto_get_error_message() for details).
*/
extern /*const*/ void*
extern const(void)*
lto_codegen_compile(lto_code_gen_t cg, size_t* length);

/**
* Generates code for all added modules into one native object file.
* The name of the file is written to name. Returns true on error.
*/
extern bool
lto_codegen_compile_to_file(lto_code_gen_t cg, /*const*/ char** name);
lto_codegen_compile_to_file(lto_code_gen_t cg, const(char)** name);


/**
* Sets options to help debug codegen bugs.
*/
extern void
lto_codegen_debug_options(lto_code_gen_t cg, /*const*/ char *);
lto_codegen_debug_options(lto_code_gen_t cg, const(char) *);

/**
* @}
*/
115 changes: 115 additions & 0 deletions llvm/c/targetmachine.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*===-- llvm-c/TargetMachine.h - Target Machine Library C Interface - C++ -*-=*\
|* *|
|* The LLVM Compiler Infrastructure *|
|* *|
|* This file is distributed under the University of Illinois Open Source *|
|* License. See LICENSE.TXT for details. *|
|* *|
|*===----------------------------------------------------------------------===*|
|* *|
|* This header declares the C interface to the Target and TargetMachine *|
|* classes, which can be used to generate assembly or object files. *|
|* *|
|* 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. *|
|* *|
\*===----------------------------------------------------------------------===*/

module llvm.c.targetmachine;

import llvm.c.core;
import llvm.c.target : LLVMTargetDataRef;

extern(C) nothrow:

struct __LLVMTargetMachine {};
alias __LLVMTargetMachine *LLVMTargetMachineRef;
struct __LLVMTarget {};
alias __LLVMTarget *LLVMTargetRef;

enum LLVMCodeGenOptLevel {
LLVMCodeGenLevelNone,
LLVMCodeGenLevelLess,
LLVMCodeGenLevelDefault,
LLVMCodeGenLevelAggressive
}

enum LLVMRelocMode {
LLVMRelocDefault,
LLVMRelocStatic,
LLVMRelocPIC,
LLVMRelocDynamicNoPic
}

enum LLVMCodeModel {
LLVMCodeModelDefault,
LLVMCodeModelJITDefault,
LLVMCodeModelSmall,
LLVMCodeModelKernel,
LLVMCodeModelMedium,
LLVMCodeModelLarge
}

enum LLVMCodeGenFileType {
LLVMAssemblyFile,
LLVMObjectFile
}

/** Returns the first llvm::Target in the registered targets list. */
LLVMTargetRef LLVMGetFirstTarget();
/** Returns the next llvm::Target given a previous one (or null if there's none) */
LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T);

/*===-- Target ------------------------------------------------------------===*/
/** Returns the name of a target. See llvm::Target::getName */
const(char) *LLVMGetTargetName(LLVMTargetRef T);

/** Returns the description of a target. See llvm::Target::getDescription */
const(char) *LLVMGetTargetDescription(LLVMTargetRef T);

/** Returns if the target has a JIT */
LLVMBool LLVMTargetHasJIT(LLVMTargetRef T);

/** Returns if the target has a TargetMachine associated */
LLVMBool LLVMTargetHasTargetMachine(LLVMTargetRef T);

/** Returns if the target as an ASM backend (required for emitting output) */
LLVMBool LLVMTargetHasAsmBackend(LLVMTargetRef T);

/*===-- Target Machine ----------------------------------------------------===*/
/** Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine */
LLVMTargetMachineRef LLVMCreateTargetMachine(LLVMTargetRef T, char *Triple,
char *CPU, char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc,
LLVMCodeModel CodeModel);

/** Dispose the LLVMTargetMachineRef instance generated by
LLVMCreateTargetMachine. */
void LLVMDisposeTargetMachine(LLVMTargetMachineRef T);

/** Returns the Target used in a TargetMachine */
LLVMTargetRef LLVMGetTargetMachineTarget(LLVMTargetMachineRef T);

/** Returns the triple used creating this target machine. See
llvm::TargetMachine::getTriple. The result needs to be disposed with
LLVMDisposeMessage. */
char *LLVMGetTargetMachineTriple(LLVMTargetMachineRef T);

/** Returns the cpu used creating this target machine. See
llvm::TargetMachine::getCPU. The result needs to be disposed with
LLVMDisposeMessage. */
char *LLVMGetTargetMachineCPU(LLVMTargetMachineRef T);

/** Returns the feature string used creating this target machine. See
llvm::TargetMachine::getFeatureString. The result needs to be disposed with
LLVMDisposeMessage. */
char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T);

/** Returns the llvm::TargetData used for this llvm:TargetMachine. */
LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T);

/** Emits an asm or object file for the given module to the filename. This
wraps several c++ only classes (among them a file stream). Returns any
error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */
LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
char *Filename, LLVMCodeGenFileType codegen, char **ErrorMessage);
20 changes: 16 additions & 4 deletions llvm/c/transforms/IPO.d
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*===-- IPO.h - Interprocedural Transformations C Interface -----*- D -*-===*\
/*===-- IPO.h - Interprocedural Transformations C Interface -----*- C++ -*-===*\
|* *|
|* The LLVM Compiler Infrastructure *|
|* *|
Expand All @@ -11,11 +11,19 @@
|* various interprocedural transformations of the LLVM IR. *|
|* *|
\*===----------------------------------------------------------------------===*/
module llvm.c.transforms.IPO;

import llvm.c.Core;
module llvm.c.transforms.ipo;

extern(C):
import llvm.c.core;

extern(C) nothrow:

/**
* @defgroup LLVMCTransformsIPO Interprocedural transformations
* @ingroup LLVMCTransforms
*
* @{
*/

/** See llvm::createArgumentPromotionPass function. */
void LLVMAddArgumentPromotionPass(LLVMPassManagerRef PM);
Expand Down Expand Up @@ -58,3 +66,7 @@ void LLVMAddStripDeadPrototypesPass(LLVMPassManagerRef PM);

/** See llvm::createStripSymbolsPass function. */
void LLVMAddStripSymbolsPass(LLVMPassManagerRef PM);

/**
* @}
*/
21 changes: 16 additions & 5 deletions llvm/c/transforms/PassManagerBuilder.d
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@
|* This header declares the C interface to the PassManagerBuilder class. *|
|* *|
\*===----------------------------------------------------------------------===*/
module llvm.c.transforms.PassManagerBuilder;

import llvm.c.Core;
module llvm.c.transforms.passmanagerbuilder;

extern(C):
import llvm.c.core;

struct __LLVMOpaquePassManagerBuilder {}
alias __LLVMOpaquePassManagerBuilder* LLVMPassManagerBuilderRef;
extern(C) nothrow:

struct __LLVMOpaquePassManagerBuilder {};
alias __LLVMOpaquePassManagerBuilder *LLVMPassManagerBuilderRef;

/**
* @defgroup LLVMCTransformsPassManagerBuilder Pass manager builder
* @ingroup LLVMCTransforms
*
* @{
*/

/** See llvm::PassManagerBuilder. */
LLVMPassManagerBuilderRef LLVMPassManagerBuilderCreate();
Expand Down Expand Up @@ -69,3 +76,7 @@ void LLVMPassManagerBuilderPopulateLTOPassManager(LLVMPassManagerBuilderRef PMB,
LLVMPassManagerRef PM,
bool Internalize,
bool RunInliner);

/**
* @}
*/
19 changes: 15 additions & 4 deletions llvm/c/transforms/Scalar.d
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*===-- Scalar.h - Scalar Transformation Library C Interface ----*- D -*-===*\
/*===-- Scalar.h - Scalar Transformation Library C Interface ----*- C++ -*-===*\
|* *|
|* The LLVM Compiler Infrastructure *|
|* *|
Expand All @@ -15,12 +15,19 @@
|* tools written in such languages. *|
|* *|
\*===----------------------------------------------------------------------===*/
module llvm.c.transforms.Scalar;

import llvm.c.Core;
module llvm.c.transforms.scalar;

extern(C):
import llvm.c.core;

extern(C) nothrow:

/**
* @defgroup LLVMCTransformsScalar Scalar transformations
* @ingroup LLVMCTransforms
*
* @{
*/

/** See llvm::createAggressiveDCEPass function. */
void LLVMAddAggressiveDCEPass(LLVMPassManagerRef PM);
Expand Down Expand Up @@ -112,3 +119,7 @@ void LLVMAddTypeBasedAliasAnalysisPass(LLVMPassManagerRef PM);

/** See llvm::createBasicAliasAnalysisPass function */
void LLVMAddBasicAliasAnalysisPass(LLVMPassManagerRef PM);

/**
* @}
*/
38 changes: 38 additions & 0 deletions llvm/c/transforms/vectorize.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*===---------------------------Vectorize.h --------------------- -*- C -*-===*\
|*===----------- Vectorization Transformation Library C Interface ---------===*|
|* *|
|* The LLVM Compiler Infrastructure *|
|* *|
|* This file is distributed under the University of Illinois Open Source *|
|* License. See LICENSE.TXT for details. *|
|* *|
|*===----------------------------------------------------------------------===*|
|* *|
|* This header declares the C interface to libLLVMVectorize.a, which *|
|* implements various vectorization transformations of the LLVM IR. *|
|* *|
|* 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. *|
|* *|
\*===----------------------------------------------------------------------===*/

module llvm.c.transforms.vectorize;

import llvm.c.core;

extern(C) nothrow:

/**
* @defgroup LLVMCTransformsVectorize Vectorization transformations
* @ingroup LLVMCTransforms
*
* @{
*/

/** See llvm::createBBVectorizePass function. */
void LLVMAddBBVectorizePass(LLVMPassManagerRef PM);

/**
* @}
*/
20 changes: 10 additions & 10 deletions main.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
/// Converted by Michaël Larouche <michael.larouche@gmail.com>
module test.llvmKaleidoscope;

import llvm.c.Analysis;
import llvm.c.Core;
import llvm.c.ExecutionEngine;
import llvm.c.Initialization;
import llvm.c.transforms.Scalar;
import llvm.c.Target;
import llvm.c.analysis;
import llvm.c.core;
import llvm.c.executionengine;
import llvm.c.initialization;
import llvm.c.transforms.scalar;
import llvm.c.target;
import std.ascii;
import std.conv;
import std.stdio;
Expand Down Expand Up @@ -278,7 +278,7 @@ public:
case '/':
return LLVMBuildFDiv(Builder, l, r, "divtmp");
case '<':
l = LLVMBuildFCmp(Builder, LLVMRealPredicate.ULT, l, r, "cmp");
l = LLVMBuildFCmp(Builder, LLVMRealPredicate.LLVMRealULT, l, r, "cmp");
// Convert bool 0/1 to double 0.0 or 1.0
return LLVMBuildUIToFP(Builder, l, LLVMDoubleType(), "booltmp");

Expand Down Expand Up @@ -493,7 +493,7 @@ public:
LLVMBuildRet(Builder, returnValue);

// Valide the generated code, checking for consistency.
LLVMVerifyFunction(theFunction, LLVMVerifierFailureAction.PrintMessage);
LLVMVerifyFunction(theFunction, LLVMVerifierFailureAction.LLVMPrintMessageAction);

// Optimize the function.
LLVMRunFunctionPassManager(TheFPM, theFunction);
Expand Down Expand Up @@ -538,7 +538,7 @@ public:
}

// Convert condition to a bool by comparing equal to 0.0.
condV = LLVMBuildFCmp(Builder, LLVMRealPredicate.ONE, condV, LLVMConstReal(LLVMDoubleType(), 0.0), "ifcond");
condV = LLVMBuildFCmp(Builder, LLVMRealPredicate.LLVMRealONE, condV, LLVMConstReal(LLVMDoubleType(), 0.0), "ifcond");

auto theFunction = LLVMGetBasicBlockParent(LLVMGetInsertBlock(Builder));

Expand Down Expand Up @@ -706,7 +706,7 @@ public:
LLVMBuildStore(Builder, nextVar, alloca);

// Convert condition to a bool by comparing equal to 0.0.
endCond = LLVMBuildFCmp(Builder, LLVMRealPredicate.ONE, endCond, LLVMConstReal(LLVMDoubleType(), 0.0), "loopcond");
endCond = LLVMBuildFCmp(Builder, LLVMRealPredicate.LLVMRealONE, endCond, LLVMConstReal(LLVMDoubleType(), 0.0), "loopcond");

// Create the "after loop" block and insert it.
auto afterBB = LLVMAppendBasicBlock(theFunction, "afterloop");
Expand Down