llvm.org GIT mirror llvm / 862ea57
[LLVM-C] [bindings/go] Add C and Golang bindings for COMDAT Patch by Ben Clayton Differential Revision: https://reviews.llvm.org/D44086 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327551 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 1 year, 6 months ago
5 changed file(s) with 186 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
1414
1515 /*
1616 #include "llvm-c/Core.h"
17 #include "llvm-c/Comdat.h"
1718 #include "IRBindings.h"
1819 #include
1920 */
3637 Value struct {
3738 C C.LLVMValueRef
3839 }
40 Comdat struct {
41 C C.LLVMComdatRef
42 }
3943 BasicBlock struct {
4044 C C.LLVMBasicBlockRef
4145 }
6064 Attribute struct {
6165 C C.LLVMAttributeRef
6266 }
63 Opcode C.LLVMOpcode
64 TypeKind C.LLVMTypeKind
65 Linkage C.LLVMLinkage
66 Visibility C.LLVMVisibility
67 CallConv C.LLVMCallConv
68 IntPredicate C.LLVMIntPredicate
69 FloatPredicate C.LLVMRealPredicate
70 LandingPadClause C.LLVMLandingPadClauseTy
67 Opcode C.LLVMOpcode
68 TypeKind C.LLVMTypeKind
69 Linkage C.LLVMLinkage
70 Visibility C.LLVMVisibility
71 CallConv C.LLVMCallConv
72 ComdatSelectionKind C.LLVMComdatSelectionKind
73 IntPredicate C.LLVMIntPredicate
74 FloatPredicate C.LLVMRealPredicate
75 LandingPadClause C.LLVMLandingPadClauseTy
7176 )
7277
7378 func (c Context) IsNil() bool { return c.C == nil }
245250 ColdCallConv CallConv = C.LLVMColdCallConv
246251 X86StdcallCallConv CallConv = C.LLVMX86StdcallCallConv
247252 X86FastcallCallConv CallConv = C.LLVMX86FastcallCallConv
253 )
254
255 //-------------------------------------------------------------------------
256 // llvm.ComdatSelectionKind
257 //-------------------------------------------------------------------------
258
259 const (
260 AnyComdatSelectionKind ComdatSelectionKind = C.LLVMAnyComdatSelectionKind
261 ExactMatchComdatSelectionKind ComdatSelectionKind = C.LLVMExactMatchComdatSelectionKind
262 LargestComdatSelectionKind ComdatSelectionKind = C.LLVMLargestComdatSelectionKind
263 NoDuplicatesComdatSelectionKind ComdatSelectionKind = C.LLVMNoDuplicatesComdatSelectionKind
264 SameSizeComdatSelectionKind ComdatSelectionKind = C.LLVMSameSizeComdatSelectionKind
248265 )
249266
250267 //-------------------------------------------------------------------------
10281045 return
10291046 }
10301047
1048 // Operations on comdat
1049 func (m Module) Comdat(name string) (c Comdat) {
1050 cname := C.CString(name)
1051 defer C.free(unsafe.Pointer(cname))
1052 c.C = C.LLVMGetOrInsertComdat(m.C, cname)
1053 return
1054 }
1055
1056 func (v Value) Comdat() (c Comdat) { c.C = C.LLVMGetComdat(v.C); return }
1057 func (v Value) SetComdat(c Comdat) { C.LLVMSetComdat(v.C, c.C) }
1058
1059 func (c Comdat) SelectionKind() ComdatSelectionKind {
1060 return ComdatSelectionKind(C.LLVMGetComdatSelectionKind(c.C))
1061 }
1062
1063 func (c Comdat) SetSelectionKind(k ComdatSelectionKind) {
1064 C.LLVMSetComdatSelectionKind(c.C, (C.LLVMComdatSelectionKind)(k))
1065 }
1066
10311067 // Operations on functions
10321068 func AddFunction(m Module, name string, ft Type) (v Value) {
10331069 cname := C.CString(name)
1414
1515 #ifndef LLVM_IR_COMDAT_H
1616 #define LLVM_IR_COMDAT_H
17
18 #include "llvm-c/Types.h"
19 #include "llvm/Support/CBindingWrapping.h"
1720
1821 namespace llvm {
1922
5457 SelectionKind SK = Any;
5558 };
5659
60 // Create wrappers for C Binding types (see CBindingWrapping.h).
61 DEFINE_SIMPLE_CONVERSION_FUNCTIONS(Comdat, LLVMComdatRef)
62
5763 inline raw_ostream &operator<<(raw_ostream &OS, const Comdat &C) {
5864 C.print(OS);
5965 return OS;
0 /*===-- llvm-c/Comdat.h - Module Comdat C Interface -------------*- C++ -*-===*\
1 |* *|
2 |* The LLVM Compiler Infrastructure *|
3 |* *|
4 |* This file is distributed under the University of Illinois Open Source *|
5 |* License. See LICENSE.TXT for details. *|
6 |* *|
7 |*===----------------------------------------------------------------------===*|
8 |* *|
9 |* This file defines the C interface to COMDAT. *|
10 |* *|
11 \*===----------------------------------------------------------------------===*/
12
13 #ifndef LLVM_C_COMDAT_H
14 #define LLVM_C_COMDAT_H
15
16 #include "llvm-c/Types.h"
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 typedef enum {
23 LLVMAnyComdatSelectionKind, ///< The linker may choose any COMDAT.
24 LLVMExactMatchComdatSelectionKind, ///< The data referenced by the COMDAT must
25 ///< be the same.
26 LLVMLargestComdatSelectionKind, ///< The linker will choose the largest
27 ///< COMDAT.
28 LLVMNoDuplicatesComdatSelectionKind, ///< No other Module may specify this
29 ///< COMDAT.
30 LLVMSameSizeComdatSelectionKind ///< The data referenced by the COMDAT must be
31 ///< the same size.
32 } LLVMComdatSelectionKind;
33
34 /**
35 * Return the Comdat in the module with the specified name. It is created
36 * if it didn't already exist.
37 *
38 * @see llvm::Module::getOrInsertComdat()
39 */
40 LLVMComdatRef LLVMGetOrInsertComdat(LLVMModuleRef M, const char *Name);
41
42 /**
43 * Get the Comdat assigned to the given global object.
44 *
45 * @see llvm::GlobalObject::getComdat()
46 */
47 LLVMComdatRef LLVMGetComdat(LLVMValueRef V);
48
49 /**
50 * Assign the Comdat to the given global object.
51 *
52 * @see llvm::GlobalObject::setComdat()
53 */
54 void LLVMSetComdat(LLVMValueRef V, LLVMComdatRef C);
55
56 /*
57 * Get the conflict resolution selection kind for the Comdat.
58 *
59 * @see llvm::Comdat::getSelectionKind()
60 */
61 LLVMComdatSelectionKind LLVMGetComdatSelectionKind(LLVMComdatRef C);
62
63 /*
64 * Set the conflict resolution selection kind for the Comdat.
65 *
66 * @see llvm::Comdat::setSelectionKind()
67 */
68 void LLVMSetComdatSelectionKind(LLVMComdatRef C, LLVMComdatSelectionKind Kind);
69
70 #ifdef __cplusplus
71 }
72 #endif
73
74 #endif
134134 typedef struct LLVMOpaqueDiagnosticInfo *LLVMDiagnosticInfoRef;
135135
136136 /**
137 * @see llvm::Comdat
138 */
139 typedef struct LLVMComdat *LLVMComdatRef;
140
141 /**
137142 * @}
138143 */
139144
66 //
77 //===----------------------------------------------------------------------===//
88 //
9 // This file implements the Comdat class.
9 // This file implements the Comdat class (including the C bindings).
1010 //
1111 //===----------------------------------------------------------------------===//
1212
13 #include "llvm/IR/Comdat.h"
13 #include "llvm-c/Comdat.h"
1414 #include "llvm/ADT/StringMap.h"
1515 #include "llvm/ADT/StringRef.h"
16 #include "llvm/IR/Comdat.h"
17 #include "llvm/IR/GlobalObject.h"
18 #include "llvm/IR/Module.h"
1619
1720 using namespace llvm;
1821
2124 Comdat::Comdat() = default;
2225
2326 StringRef Comdat::getName() const { return Name->first(); }
27
28 LLVMComdatRef LLVMGetOrInsertComdat(LLVMModuleRef M, const char *Name) {
29 return wrap(unwrap(M)->getOrInsertComdat(Name));
30 }
31
32 LLVMComdatRef LLVMGetComdat(LLVMValueRef V) {
33 GlobalObject *G = unwrap(V);
34 return wrap(G->getComdat());
35 }
36
37 void LLVMSetComdat(LLVMValueRef V, LLVMComdatRef C) {
38 GlobalObject *G = unwrap(V);
39 G->setComdat(unwrap(C));
40 }
41
42 LLVMComdatSelectionKind LLVMGetComdatSelectionKind(LLVMComdatRef C) {
43 switch (unwrap(C)->getSelectionKind()) {
44 case Comdat::Any:
45 return LLVMAnyComdatSelectionKind;
46 case Comdat::ExactMatch:
47 return LLVMExactMatchComdatSelectionKind;
48 case Comdat::Largest:
49 return LLVMLargestComdatSelectionKind;
50 case Comdat::NoDuplicates:
51 return LLVMNoDuplicatesComdatSelectionKind;
52 case Comdat::SameSize:
53 return LLVMSameSizeComdatSelectionKind;
54 }
55 llvm_unreachable("Invalid Comdat SelectionKind!");
56 }
57
58 void LLVMSetComdatSelectionKind(LLVMComdatRef C, LLVMComdatSelectionKind kind) {
59 Comdat *Cd = unwrap(C);
60 switch (kind) {
61 case LLVMAnyComdatSelectionKind:
62 Cd->setSelectionKind(Comdat::Any);
63 break;
64 case LLVMExactMatchComdatSelectionKind:
65 Cd->setSelectionKind(Comdat::ExactMatch);
66 break;
67 case LLVMLargestComdatSelectionKind:
68 Cd->setSelectionKind(Comdat::Largest);
69 break;
70 case LLVMNoDuplicatesComdatSelectionKind:
71 Cd->setSelectionKind(Comdat::NoDuplicates);
72 break;
73 case LLVMSameSizeComdatSelectionKind:
74 Cd->setSelectionKind(Comdat::SameSize);
75 break;
76 }
77 }