1 //===- IRBindings.cpp - Additional bindings for ir ------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines additional C bindings for the ir component.
12 //===----------------------------------------------------------------------===//
14 #include "IRBindings.h"
16 #include "llvm/IR/Attributes.h"
17 #include "llvm/IR/DebugLoc.h"
18 #include "llvm/IR/Function.h"
19 #include "llvm/IR/IRBuilder.h"
20 #include "llvm/IR/LLVMContext.h"
21 #include "llvm/IR/Module.h"
25 void LLVMAddFunctionAttr2(LLVMValueRef Fn, uint64_t PA) {
26 Function *Func = unwrap<Function>(Fn);
27 const AttributeSet PAL = Func->getAttributes();
29 const AttributeSet PALnew =
30 PAL.addAttributes(Func->getContext(), AttributeSet::FunctionIndex,
31 AttributeSet::get(Func->getContext(),
32 AttributeSet::FunctionIndex, B));
33 Func->setAttributes(PALnew);
36 uint64_t LLVMGetFunctionAttr2(LLVMValueRef Fn) {
37 Function *Func = unwrap<Function>(Fn);
38 const AttributeSet PAL = Func->getAttributes();
39 return PAL.Raw(AttributeSet::FunctionIndex);
42 void LLVMRemoveFunctionAttr2(LLVMValueRef Fn, uint64_t PA) {
43 Function *Func = unwrap<Function>(Fn);
44 const AttributeSet PAL = Func->getAttributes();
46 const AttributeSet PALnew =
47 PAL.removeAttributes(Func->getContext(), AttributeSet::FunctionIndex,
48 AttributeSet::get(Func->getContext(),
49 AttributeSet::FunctionIndex, B));
50 Func->setAttributes(PALnew);
53 LLVMMetadataRef LLVMMDString2(LLVMContextRef C, const char *Str, unsigned SLen) {
54 return wrap(MDString::get(*unwrap(C), StringRef(Str, SLen)));
57 LLVMMetadataRef LLVMMDNode2(LLVMContextRef C, LLVMMetadataRef *MDs,
60 MDNode::get(*unwrap(C), ArrayRef<Metadata *>(unwrap(MDs), Count)));
63 void LLVMAddNamedMetadataOperand2(LLVMModuleRef M, const char *name,
64 LLVMMetadataRef Val) {
65 NamedMDNode *N = unwrap(M)->getOrInsertNamedMetadata(name);
70 N->addOperand(unwrap<MDNode>(Val));
73 void LLVMSetMetadata2(LLVMValueRef Inst, unsigned KindID, LLVMMetadataRef MD) {
74 MDNode *N = MD ? unwrap<MDNode>(MD) : nullptr;
75 unwrap<Instruction>(Inst)->setMetadata(KindID, N);
78 void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Bref, unsigned Line,
79 unsigned Col, LLVMMetadataRef Scope,
80 LLVMMetadataRef InlinedAt) {
81 unwrap(Bref)->SetCurrentDebugLocation(
82 DebugLoc::get(Line, Col, Scope ? unwrap<MDNode>(Scope) : nullptr,
83 InlinedAt ? unwrap<MDNode>(InlinedAt) : nullptr));