Mark LLVMAttribute as a bitfield, add some missing functions, note URLs for upstreame...
[cl-llvm.git] / src / llvm-extras.cpp
blobb9643cee685162e327819a94a678b84a7f0416b0
1 #include <llvm-c/Target.h>
2 #include <llvm/Target/TargetData.h>
3 #include <llvm/ModuleProvider.h>
4 #include <llvm/Support/SourceMgr.h>
5 #include <llvm/Support/raw_ostream.h>
6 #include <llvm/Assembly/Parser.h>
8 extern "C" {
9 // Declare here so the inline definition gets into the lib. Why is
10 // there an inline function in a binding header anyways. :(
11 int CLLLVM_LLVMInitializeNativeTarget() {
12 LLVMInitializeNativeTarget();
15 // Functions missing in the LLVM C API
19 LLVMModuleRef CLLLVM_LLVMModuleProviderGetModule(LLVMModuleProviderRef modprovider) {
20 return llvm::wrap(llvm::unwrap(modprovider)->getModule());
23 LLVMModuleRef CLLLVM_LLVMParseAssemblyString(const char *AsmString,
24 LLVMModuleRef M,
25 LLVMContextRef Context) {
26 class llvm::SMDiagnostic Error;
27 LLVMModuleRef res =
28 llvm::wrap(llvm::ParseAssemblyString(AsmString, llvm::unwrap(M), Error, *llvm::unwrap(Context)));
29 Error.Print("sbcl", llvm::errs());
32 LLVMTypeRef CLLLVM_LLVMIntPtrTypeInContext(LLVMContextRef Context, LLVMTargetDataRef TD) {
33 return llvm::wrap(llvm::unwrap(TD)->getIntPtrType(*llvm::unwrap(Context)));
36 char *CLLLVM_LLVMDumpModuleToString(LLVMModuleRef module)
38 std::string s;
39 llvm::raw_string_ostream buf(s);
40 llvm::unwrap(module)->print(buf, NULL);
41 return strdup(buf.str().c_str());
44 char *CLLLVM_LLVMDumpTypeToString(LLVMTypeRef type)
46 std::string s;
47 llvm::raw_string_ostream buf(s);
48 llvm::unwrap(type)->print(buf);
49 return strdup(buf.str().c_str());
52 char *CLLLVM_LLVMDumpValueToString(LLVMValueRef value)
54 std::string s;
55 llvm::raw_string_ostream buf(s);
56 llvm::unwrap(value)->print(buf);
57 return strdup(buf.str().c_str());