llvm.org GIT mirror llvm / cb096f0
Also delete the go side of the bindings deleted in r286085/r286086. Also delete a comment I forgot to delete. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286087 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Jasper 3 years ago
3 changed file(s) with 0 addition(s) and 180 deletion(s). Raw diff Collapse all Expand all
2626 #endif
2727
2828 typedef struct LLVMOpaqueMetadata *LLVMMetadataRef;
29
30 // These functions duplicate the LLVM*FunctionAttr functions in the stable C
31 // API. We cannot use the existing functions because they take 32-bit attribute
32 // values, and the Go bindings expose all of the LLVM attributes, some of which
33 // have values >= 1<<32.
3429
3530 LLVMMetadataRef LLVMConstantAsMetadata(LLVMValueRef Val);
3631
112112 }
113113 return pt, ptlen
114114 }
115
116 //-------------------------------------------------------------------------
117 // llvm.Attribute
118 //-------------------------------------------------------------------------
119
120 const (
121 NoneAttribute Attribute = 0
122 ZExtAttribute Attribute = C.LLVMZExtAttribute
123 SExtAttribute Attribute = C.LLVMSExtAttribute
124 NoReturnAttribute Attribute = C.LLVMNoReturnAttribute
125 InRegAttribute Attribute = C.LLVMInRegAttribute
126 StructRetAttribute Attribute = C.LLVMStructRetAttribute
127 NoUnwindAttribute Attribute = C.LLVMNoUnwindAttribute
128 NoAliasAttribute Attribute = C.LLVMNoAliasAttribute
129 ByValAttribute Attribute = C.LLVMByValAttribute
130 NestAttribute Attribute = C.LLVMNestAttribute
131 ReadNoneAttribute Attribute = C.LLVMReadNoneAttribute
132 ReadOnlyAttribute Attribute = C.LLVMReadOnlyAttribute
133 NoInlineAttribute Attribute = C.LLVMNoInlineAttribute
134 AlwaysInlineAttribute Attribute = C.LLVMAlwaysInlineAttribute
135 OptimizeForSizeAttribute Attribute = C.LLVMOptimizeForSizeAttribute
136 StackProtectAttribute Attribute = C.LLVMStackProtectAttribute
137 StackProtectReqAttribute Attribute = C.LLVMStackProtectReqAttribute
138 Alignment Attribute = C.LLVMAlignment
139 NoCaptureAttribute Attribute = C.LLVMNoCaptureAttribute
140 NoRedZoneAttribute Attribute = C.LLVMNoRedZoneAttribute
141 NoImplicitFloatAttribute Attribute = C.LLVMNoImplicitFloatAttribute
142 NakedAttribute Attribute = C.LLVMNakedAttribute
143 InlineHintAttribute Attribute = C.LLVMInlineHintAttribute
144 StackAlignment Attribute = C.LLVMStackAlignment
145 ReturnsTwiceAttribute Attribute = C.LLVMReturnsTwice
146 UWTableAttribute Attribute = C.LLVMUWTable
147 NonLazyBindAttribute Attribute = 1 << 31
148 SanitizeAddressAttribute Attribute = 1 << 32
149 MinSizeAttribute Attribute = 1 << 33
150 NoDuplicateAttribute Attribute = 1 << 34
151 StackProtectStrongAttribute Attribute = 1 << 35
152 SanitizeThreadAttribute Attribute = 1 << 36
153 SanitizeMemoryAttribute Attribute = 1 << 37
154 NoBuiltinAttribute Attribute = 1 << 38
155 ReturnedAttribute Attribute = 1 << 39
156 ColdAttribute Attribute = 1 << 40
157 BuiltinAttribute Attribute = 1 << 41
158 OptimizeNoneAttribute Attribute = 1 << 42
159 InAllocaAttribute Attribute = 1 << 43
160 NonNullAttribute Attribute = 1 << 44
161 JumpTableAttribute Attribute = 1 << 45
162 ConvergentAttribute Attribute = 1 << 46
163 SafeStackAttribute Attribute = 1 << 47
164 )
165115
166116 //-------------------------------------------------------------------------
167117 // llvm.Opcode
1043993 defer C.free(unsafe.Pointer(cname))
1044994 C.LLVMSetGC(v.C, cname)
1045995 }
1046 func (v Value) AddFunctionAttr(a Attribute) { C.LLVMAddFunctionAttr2(v.C, C.uint64_t(a)) }
1047 func (v Value) FunctionAttr() Attribute { return Attribute(C.LLVMGetFunctionAttr2(v.C)) }
1048 func (v Value) RemoveFunctionAttr(a Attribute) { C.LLVMRemoveFunctionAttr2(v.C, C.uint64_t(a)) }
1049996 func (v Value) AddTargetDependentFunctionAttr(attr, value string) {
1050997 cattr := C.CString(attr)
1051998 defer C.free(unsafe.Pointer(cattr))
10751022 func (v Value) LastParam() (rv Value) { rv.C = C.LLVMGetLastParam(v.C); return }
10761023 func NextParam(v Value) (rv Value) { rv.C = C.LLVMGetNextParam(v.C); return }
10771024 func PrevParam(v Value) (rv Value) { rv.C = C.LLVMGetPreviousParam(v.C); return }
1078 func (v Value) AddAttribute(a Attribute) {
1079 if a >= 1<<32 {
1080 panic("attribute value currently unsupported")
1081 }
1082 C.LLVMAddAttribute(v.C, C.LLVMAttribute(a))
1083 }
1084 func (v Value) RemoveAttribute(a Attribute) {
1085 if a >= 1<<32 {
1086 panic("attribute value currently unsupported")
1087 }
1088 C.LLVMRemoveAttribute(v.C, C.LLVMAttribute(a))
1089 }
1090 func (v Value) Attribute() Attribute { return Attribute(C.LLVMGetAttribute(v.C)) }
10911025 func (v Value) SetParamAlignment(align int) { C.LLVMSetParamAlignment(v.C, C.unsigned(align)) }
10921026
10931027 // Operations on basic blocks
11481082 func (v Value) InstructionCallConv() CallConv {
11491083 return CallConv(C.LLVMCallConv(C.LLVMGetInstructionCallConv(v.C)))
11501084 }
1151 func (v Value) AddInstrAttribute(i int, a Attribute) {
1152 if a >= 1<<32 {
1153 panic("attribute value currently unsupported")
1154 }
1155 C.LLVMAddInstrAttribute(v.C, C.unsigned(i), C.LLVMAttribute(a))
1156 }
1157 func (v Value) RemoveInstrAttribute(i int, a Attribute) {
1158 if a >= 1<<32 {
1159 panic("attribute value currently unsupported")
1160 }
1161 C.LLVMRemoveInstrAttribute(v.C, C.unsigned(i), C.LLVMAttribute(a))
1162 }
11631085 func (v Value) SetInstrParamAlignment(i int, align int) {
11641086 C.LLVMSetInstrParamAlignment(v.C, C.unsigned(i), C.unsigned(align))
11651087 }
+0
-97
bindings/go/llvm/ir_test.go less more
None //===- ir_test.go - Tests for ir ------------------------------------------===//
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 tests bindings for the ir component.
10 //
11 //===----------------------------------------------------------------------===//
12
13 package llvm
14
15 import (
16 "strings"
17 "testing"
18 )
19
20 func testAttribute(t *testing.T, attr Attribute, name string) {
21 mod := NewModule("")
22 defer mod.Dispose()
23
24 ftyp := FunctionType(VoidType(), nil, false)
25 fn := AddFunction(mod, "foo", ftyp)
26
27 fn.AddFunctionAttr(attr)
28 newattr := fn.FunctionAttr()
29 if attr != newattr {
30 t.Errorf("got attribute mask %d, want %d", newattr, attr)
31 }
32
33 text := mod.String()
34 if !strings.Contains(text, " "+name+" ") {
35 t.Errorf("expected attribute '%s', got:\n%s", name, text)
36 }
37
38 fn.RemoveFunctionAttr(attr)
39 newattr = fn.FunctionAttr()
40 if newattr != 0 {
41 t.Errorf("got attribute mask %d, want 0", newattr)
42 }
43 }
44
45 func TestAttributes(t *testing.T) {
46 // Tests that our attribute constants haven't drifted from LLVM's.
47 attrTests := []struct {
48 attr Attribute
49 name string
50 }{
51 {SanitizeAddressAttribute, "sanitize_address"},
52 {AlwaysInlineAttribute, "alwaysinline"},
53 {BuiltinAttribute, "builtin"},
54 {ByValAttribute, "byval"},
55 {ConvergentAttribute, "convergent"},
56 {InAllocaAttribute, "inalloca"},
57 {InlineHintAttribute, "inlinehint"},
58 {InRegAttribute, "inreg"},
59 {JumpTableAttribute, "jumptable"},
60 {MinSizeAttribute, "minsize"},
61 {NakedAttribute, "naked"},
62 {NestAttribute, "nest"},
63 {NoAliasAttribute, "noalias"},
64 {NoBuiltinAttribute, "nobuiltin"},
65 {NoCaptureAttribute, "nocapture"},
66 {NoDuplicateAttribute, "noduplicate"},
67 {NoImplicitFloatAttribute, "noimplicitfloat"},
68 {NoInlineAttribute, "noinline"},
69 {NonLazyBindAttribute, "nonlazybind"},
70 {NonNullAttribute, "nonnull"},
71 {NoRedZoneAttribute, "noredzone"},
72 {NoReturnAttribute, "noreturn"},
73 {NoUnwindAttribute, "nounwind"},
74 {OptimizeNoneAttribute, "optnone"},
75 {OptimizeForSizeAttribute, "optsize"},
76 {ReadNoneAttribute, "readnone"},
77 {ReadOnlyAttribute, "readonly"},
78 {ReturnedAttribute, "returned"},
79 {ReturnsTwiceAttribute, "returns_twice"},
80 {SExtAttribute, "signext"},
81 {SafeStackAttribute, "safestack"},
82 {StackProtectAttribute, "ssp"},
83 {StackProtectReqAttribute, "sspreq"},
84 {StackProtectStrongAttribute, "sspstrong"},
85 {StructRetAttribute, "sret"},
86 {SanitizeThreadAttribute, "sanitize_thread"},
87 {SanitizeMemoryAttribute, "sanitize_memory"},
88 {UWTableAttribute, "uwtable"},
89 {ZExtAttribute, "zeroext"},
90 {ColdAttribute, "cold"},
91 }
92
93 for _, a := range attrTests {
94 testAttribute(t, a.attr, a.name)
95 }
96 }