]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - bindings/go/llvm/IRBindings.cpp
Vendor import of llvm trunk r290819:
[FreeBSD/FreeBSD.git] / bindings / go / llvm / IRBindings.cpp
1 //===- IRBindings.cpp - Additional bindings for ir ------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines additional C bindings for the ir component.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "IRBindings.h"
15 #include "llvm/IR/Attributes.h"
16 #include "llvm/IR/DebugLoc.h"
17 #include "llvm/IR/Function.h"
18 #include "llvm/IR/IRBuilder.h"
19 #include "llvm/IR/LLVMContext.h"
20 #include "llvm/IR/Module.h"
21
22 using namespace llvm;
23
24 LLVMMetadataRef LLVMConstantAsMetadata(LLVMValueRef C) {
25   return wrap(ConstantAsMetadata::get(unwrap<Constant>(C)));
26 }
27
28 LLVMMetadataRef LLVMMDString2(LLVMContextRef C, const char *Str, unsigned SLen) {
29   return wrap(MDString::get(*unwrap(C), StringRef(Str, SLen)));
30 }
31
32 LLVMMetadataRef LLVMMDNode2(LLVMContextRef C, LLVMMetadataRef *MDs,
33                             unsigned Count) {
34   return wrap(
35       MDNode::get(*unwrap(C), ArrayRef<Metadata *>(unwrap(MDs), Count)));
36 }
37
38 LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef C, LLVMMetadataRef *MDs,
39                                     unsigned Count) {
40   return wrap(MDTuple::getTemporary(*unwrap(C),
41                                     ArrayRef<Metadata *>(unwrap(MDs), Count))
42                   .release());
43 }
44
45 void LLVMAddNamedMetadataOperand2(LLVMModuleRef M, const char *name,
46                                   LLVMMetadataRef Val) {
47   NamedMDNode *N = unwrap(M)->getOrInsertNamedMetadata(name);
48   if (!N)
49     return;
50   if (!Val)
51     return;
52   N->addOperand(unwrap<MDNode>(Val));
53 }
54
55 void LLVMSetMetadata2(LLVMValueRef Inst, unsigned KindID, LLVMMetadataRef MD) {
56   MDNode *N = MD ? unwrap<MDNode>(MD) : nullptr;
57   unwrap<Instruction>(Inst)->setMetadata(KindID, N);
58 }
59
60 void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef MD, LLVMMetadataRef New) {
61   auto *Node = unwrap<MDNode>(MD);
62   Node->replaceAllUsesWith(unwrap<Metadata>(New));
63   MDNode::deleteTemporary(Node);
64 }
65
66 void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Bref, unsigned Line,
67                                   unsigned Col, LLVMMetadataRef Scope,
68                                   LLVMMetadataRef InlinedAt) {
69   unwrap(Bref)->SetCurrentDebugLocation(
70       DebugLoc::get(Line, Col, Scope ? unwrap<MDNode>(Scope) : nullptr,
71                     InlinedAt ? unwrap<MDNode>(InlinedAt) : nullptr));
72 }
73
74 void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP) {
75   unwrap<Function>(Func)->setSubprogram(unwrap<DISubprogram>(SP));
76 }