forked from OSchip/llvm-project
[llvm-c] Improve TargetMachine bindings
Original patch by Chris Wailes llvm-svn: 194143
This commit is contained in:
parent
671fe2ee58
commit
7b61b75c21
|
@ -62,6 +62,16 @@ LLVMTargetRef LLVMGetFirstTarget(void);
|
||||||
LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T);
|
LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T);
|
||||||
|
|
||||||
/*===-- Target ------------------------------------------------------------===*/
|
/*===-- Target ------------------------------------------------------------===*/
|
||||||
|
/** Finds the target corresponding to the given name and stores it in \p T.
|
||||||
|
Returns 0 on success. */
|
||||||
|
LLVMBool LLVMGetTargetFromName(const char *Name, LLVMTargetRef *T);
|
||||||
|
|
||||||
|
/** Finds the target corresponding to the given triple and stores it in \p T.
|
||||||
|
Returns 0 on success. Optionally returns any error in ErrorMessage.
|
||||||
|
Use LLVMDisposeMessage to dispose the message. */
|
||||||
|
LLVMBool LLVMGetTargetFromTriple(const char* Triple, LLVMTargetRef *T,
|
||||||
|
char **ErrorMessage);
|
||||||
|
|
||||||
/** Returns the name of a target. See llvm::Target::getName */
|
/** Returns the name of a target. See llvm::Target::getName */
|
||||||
const char *LLVMGetTargetName(LLVMTargetRef T);
|
const char *LLVMGetTargetName(LLVMTargetRef T);
|
||||||
|
|
||||||
|
@ -108,6 +118,10 @@ char *LLVMGetTargetMachineFeatureString(LLVMTargetMachineRef T);
|
||||||
/** Returns the llvm::DataLayout used for this llvm:TargetMachine. */
|
/** Returns the llvm::DataLayout used for this llvm:TargetMachine. */
|
||||||
LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T);
|
LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T);
|
||||||
|
|
||||||
|
/** Set the target machine's ASM verbosity. */
|
||||||
|
void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,
|
||||||
|
LLVMBool VerboseAsm);
|
||||||
|
|
||||||
/** Emits an asm or object file for the given module to the filename. This
|
/** 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
|
wraps several c++ only classes (among them a file stream). Returns any
|
||||||
error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */
|
error in ErrorMessage. Use LLVMDisposeMessage to dispose the message. */
|
||||||
|
@ -117,6 +131,12 @@ LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
|
||||||
/** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */
|
/** Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf. */
|
||||||
LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M,
|
LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M,
|
||||||
LLVMCodeGenFileType codegen, char** ErrorMessage, LLVMMemoryBufferRef *OutMemBuf);
|
LLVMCodeGenFileType codegen, char** ErrorMessage, LLVMMemoryBufferRef *OutMemBuf);
|
||||||
|
|
||||||
|
/*===-- Triple ------------------------------------------------------------===*/
|
||||||
|
/** Get a triple for the host machine as a string. The result needs to be
|
||||||
|
disposed with LLVMDisposeMessage. */
|
||||||
|
char* LLVMGetDefaultTargetTriple(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "llvm/Support/FormattedStream.h"
|
#include "llvm/Support/FormattedStream.h"
|
||||||
#include "llvm/Support/TargetRegistry.h"
|
#include "llvm/Support/TargetRegistry.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
#include "llvm/Support/Host.h"
|
||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/Target/TargetMachine.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
@ -71,6 +72,35 @@ LLVMTargetRef LLVMGetNextTarget(LLVMTargetRef T) {
|
||||||
return wrap(unwrap(T)->getNext());
|
return wrap(unwrap(T)->getNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LLVMBool LLVMGetTargetFromName(const char *Name, LLVMTargetRef *T) {
|
||||||
|
for (TargetRegistry::iterator IT = TargetRegistry::begin(),
|
||||||
|
IE = TargetRegistry::end(); IT != IE; ++IT) {
|
||||||
|
if (IT->getName() == Name) {
|
||||||
|
*T = wrap(&*IT);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
LLVMBool LLVMGetTargetFromTriple(const char* TripleStr, LLVMTargetRef *T,
|
||||||
|
char **ErrorMessage) {
|
||||||
|
std::string Error;
|
||||||
|
|
||||||
|
*T = wrap(TargetRegistry::lookupTarget(TripleStr, Error));
|
||||||
|
|
||||||
|
if (!*T) {
|
||||||
|
if (ErrorMessage)
|
||||||
|
*ErrorMessage = strdup(Error.c_str());
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const char * LLVMGetTargetName(LLVMTargetRef T) {
|
const char * LLVMGetTargetName(LLVMTargetRef T) {
|
||||||
return unwrap(T)->getName();
|
return unwrap(T)->getName();
|
||||||
}
|
}
|
||||||
|
@ -162,6 +192,11 @@ LLVMTargetDataRef LLVMGetTargetMachineData(LLVMTargetMachineRef T) {
|
||||||
return wrap(unwrap(T)->getDataLayout());
|
return wrap(unwrap(T)->getDataLayout());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LLVMSetTargetMachineAsmVerbosity(LLVMTargetMachineRef T,
|
||||||
|
LLVMBool VerboseAsm) {
|
||||||
|
unwrap(T)->setAsmVerbosityDefault(VerboseAsm);
|
||||||
|
}
|
||||||
|
|
||||||
static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M,
|
static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M,
|
||||||
formatted_raw_ostream &OS, LLVMCodeGenFileType codegen, char **ErrorMessage) {
|
formatted_raw_ostream &OS, LLVMCodeGenFileType codegen, char **ErrorMessage) {
|
||||||
TargetMachine* TM = unwrap(T);
|
TargetMachine* TM = unwrap(T);
|
||||||
|
@ -229,3 +264,7 @@ LLVMBool LLVMTargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T,
|
||||||
Data.length(), "");
|
Data.length(), "");
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *LLVMGetDefaultTargetTriple(void) {
|
||||||
|
return strdup(sys::getDefaultTargetTriple().c_str());
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue