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>
13 // Declare here so the inline definition gets into the lib. Why is
14 // there an inline function in a binding header anyways. :(
15 int CLLLVM_LLVMInitializeNativeTarget() {
16 LLVMInitializeNativeTarget();
19 // Functions missing in the LLVM C API
23 LLVMModuleRef
CLLLVM_LLVMModuleProviderGetModule(LLVMModuleProviderRef modprovider
) {
24 return wrap(unwrap(modprovider
)->getModule());
27 LLVMModuleRef
CLLLVM_LLVMParseAssemblyString(const char *AsmString
,
29 LLVMContextRef Context
) {
30 class SMDiagnostic Error
;
32 wrap(ParseAssemblyString(AsmString
, unwrap(M
), Error
, *unwrap(Context
)));
33 Error
.Print("sbcl", errs());
36 LLVMTypeRef
CLLLVM_LLVMIntPtrTypeInContext(LLVMContextRef Context
, LLVMTargetDataRef TD
) {
37 return wrap(unwrap(TD
)->getIntPtrType(*unwrap(Context
)));
40 char *CLLLVM_LLVMDumpModuleToString(LLVMModuleRef module
)
43 raw_string_ostream
buf(s
);
44 unwrap(module
)->print(buf
, NULL
);
45 return strdup(buf
.str().c_str());
48 char *CLLLVM_LLVMDumpTypeToString(LLVMTypeRef type
)
51 raw_string_ostream
buf(s
);
52 unwrap(type
)->print(buf
);
53 return strdup(buf
.str().c_str());
56 char *CLLLVM_LLVMDumpValueToString(LLVMValueRef value
)
59 raw_string_ostream
buf(s
);
60 unwrap(value
)->print(buf
);
61 return strdup(buf
.str().c_str());
64 // These are buggy in LLVM: they affect the return value attributes,
65 // not the fn attributes.
66 void CLLLVM_LLVMAddFunctionAttr(LLVMValueRef Fn
, LLVMAttribute PA
) {
67 Function
*Func
= unwrap
<Function
>(Fn
);
68 const AttrListPtr PAL
= Func
->getAttributes();
69 const AttrListPtr PALnew
= PAL
.addAttr(~0, PA
);
70 Func
->setAttributes(PALnew
);
73 void CLLLVM_LLVMRemoveFunctionAttr(LLVMValueRef Fn
, LLVMAttribute PA
) {
74 Function
*Func
= unwrap
<Function
>(Fn
);
75 const AttrListPtr PAL
= Func
->getAttributes();
76 const AttrListPtr PALnew
= PAL
.removeAttr(~0, PA
);
77 Func
->setAttributes(PALnew
);
80 void CLLLVM_LLVMAddRetAttr(LLVMValueRef Fn
, LLVMAttribute PA
) {
81 Function
*Func
= unwrap
<Function
>(Fn
);
82 const AttrListPtr PAL
= Func
->getAttributes();
83 const AttrListPtr PALnew
= PAL
.addAttr(0, PA
);
84 Func
->setAttributes(PALnew
);
87 void CLLLVM_LLVMRemoveRetAttr(LLVMValueRef Fn
, LLVMAttribute PA
) {
88 Function
*Func
= unwrap
<Function
>(Fn
);
89 const AttrListPtr PAL
= Func
->getAttributes();
90 const AttrListPtr PALnew
= PAL
.removeAttr(0, PA
);
91 Func
->setAttributes(PALnew
);
94 LLVMAttribute
CLLLVM_LLVMGetRetAttr(LLVMValueRef Fn
) {
95 Function
*Func
= unwrap
<Function
>(Fn
);
96 const AttrListPtr PAL
= Func
->getAttributes();
97 Attributes attr
= PAL
.getRetAttributes();
98 return (LLVMAttribute
)attr
;