Index: bindings/go/llvm/ir.go =================================================================== --- bindings/go/llvm/ir.go +++ bindings/go/llvm/ir.go @@ -58,7 +58,6 @@ Metadata struct { C C.LLVMMetadataRef } - Attribute uint64 Opcode C.LLVMOpcode TypeKind C.LLVMTypeKind Linkage C.LLVMLinkage @@ -115,56 +114,6 @@ } //------------------------------------------------------------------------- -// llvm.Attribute -//------------------------------------------------------------------------- - -const ( - NoneAttribute Attribute = 0 - ZExtAttribute Attribute = C.LLVMZExtAttribute - SExtAttribute Attribute = C.LLVMSExtAttribute - NoReturnAttribute Attribute = C.LLVMNoReturnAttribute - InRegAttribute Attribute = C.LLVMInRegAttribute - StructRetAttribute Attribute = C.LLVMStructRetAttribute - NoUnwindAttribute Attribute = C.LLVMNoUnwindAttribute - NoAliasAttribute Attribute = C.LLVMNoAliasAttribute - ByValAttribute Attribute = C.LLVMByValAttribute - NestAttribute Attribute = C.LLVMNestAttribute - ReadNoneAttribute Attribute = C.LLVMReadNoneAttribute - ReadOnlyAttribute Attribute = C.LLVMReadOnlyAttribute - NoInlineAttribute Attribute = C.LLVMNoInlineAttribute - AlwaysInlineAttribute Attribute = C.LLVMAlwaysInlineAttribute - OptimizeForSizeAttribute Attribute = C.LLVMOptimizeForSizeAttribute - StackProtectAttribute Attribute = C.LLVMStackProtectAttribute - StackProtectReqAttribute Attribute = C.LLVMStackProtectReqAttribute - Alignment Attribute = C.LLVMAlignment - NoCaptureAttribute Attribute = C.LLVMNoCaptureAttribute - NoRedZoneAttribute Attribute = C.LLVMNoRedZoneAttribute - NoImplicitFloatAttribute Attribute = C.LLVMNoImplicitFloatAttribute - NakedAttribute Attribute = C.LLVMNakedAttribute - InlineHintAttribute Attribute = C.LLVMInlineHintAttribute - StackAlignment Attribute = C.LLVMStackAlignment - ReturnsTwiceAttribute Attribute = C.LLVMReturnsTwice - UWTableAttribute Attribute = C.LLVMUWTable - NonLazyBindAttribute Attribute = 1 << 31 - SanitizeAddressAttribute Attribute = 1 << 32 - MinSizeAttribute Attribute = 1 << 33 - NoDuplicateAttribute Attribute = 1 << 34 - StackProtectStrongAttribute Attribute = 1 << 35 - SanitizeThreadAttribute Attribute = 1 << 36 - SanitizeMemoryAttribute Attribute = 1 << 37 - NoBuiltinAttribute Attribute = 1 << 38 - ReturnedAttribute Attribute = 1 << 39 - ColdAttribute Attribute = 1 << 40 - BuiltinAttribute Attribute = 1 << 41 - OptimizeNoneAttribute Attribute = 1 << 42 - InAllocaAttribute Attribute = 1 << 43 - NonNullAttribute Attribute = 1 << 44 - JumpTableAttribute Attribute = 1 << 45 - ConvergentAttribute Attribute = 1 << 46 - SafeStackAttribute Attribute = 1 << 47 -) - -//------------------------------------------------------------------------- // llvm.Opcode //------------------------------------------------------------------------- @@ -1044,9 +993,6 @@ defer C.free(unsafe.Pointer(cname)) C.LLVMSetGC(v.C, cname) } -func (v Value) AddFunctionAttr(a Attribute) { C.LLVMAddFunctionAttr2(v.C, C.uint64_t(a)) } -func (v Value) FunctionAttr() Attribute { return Attribute(C.LLVMGetFunctionAttr2(v.C)) } -func (v Value) RemoveFunctionAttr(a Attribute) { C.LLVMRemoveFunctionAttr2(v.C, C.uint64_t(a)) } func (v Value) AddTargetDependentFunctionAttr(attr, value string) { cattr := C.CString(attr) defer C.free(unsafe.Pointer(cattr)) @@ -1070,25 +1016,12 @@ } return out } -func (v Value) Param(i int) (rv Value) { rv.C = C.LLVMGetParam(v.C, C.unsigned(i)); return } -func (v Value) ParamParent() (rv Value) { rv.C = C.LLVMGetParamParent(v.C); return } -func (v Value) FirstParam() (rv Value) { rv.C = C.LLVMGetFirstParam(v.C); return } -func (v Value) LastParam() (rv Value) { rv.C = C.LLVMGetLastParam(v.C); return } -func NextParam(v Value) (rv Value) { rv.C = C.LLVMGetNextParam(v.C); return } -func PrevParam(v Value) (rv Value) { rv.C = C.LLVMGetPreviousParam(v.C); return } -func (v Value) AddAttribute(a Attribute) { - if a >= 1<<32 { - panic("attribute value currently unsupported") - } - C.LLVMAddAttribute(v.C, C.LLVMAttribute(a)) -} -func (v Value) RemoveAttribute(a Attribute) { - if a >= 1<<32 { - panic("attribute value currently unsupported") - } - C.LLVMRemoveAttribute(v.C, C.LLVMAttribute(a)) -} -func (v Value) Attribute() Attribute { return Attribute(C.LLVMGetAttribute(v.C)) } +func (v Value) Param(i int) (rv Value) { rv.C = C.LLVMGetParam(v.C, C.unsigned(i)); return } +func (v Value) ParamParent() (rv Value) { rv.C = C.LLVMGetParamParent(v.C); return } +func (v Value) FirstParam() (rv Value) { rv.C = C.LLVMGetFirstParam(v.C); return } +func (v Value) LastParam() (rv Value) { rv.C = C.LLVMGetLastParam(v.C); return } +func NextParam(v Value) (rv Value) { rv.C = C.LLVMGetNextParam(v.C); return } +func PrevParam(v Value) (rv Value) { rv.C = C.LLVMGetPreviousParam(v.C); return } func (v Value) SetParamAlignment(align int) { C.LLVMSetParamAlignment(v.C, C.unsigned(align)) } // Operations on basic blocks @@ -1149,18 +1082,6 @@ func (v Value) InstructionCallConv() CallConv { return CallConv(C.LLVMCallConv(C.LLVMGetInstructionCallConv(v.C))) } -func (v Value) AddInstrAttribute(i int, a Attribute) { - if a >= 1<<32 { - panic("attribute value currently unsupported") - } - C.LLVMAddInstrAttribute(v.C, C.unsigned(i), C.LLVMAttribute(a)) -} -func (v Value) RemoveInstrAttribute(i int, a Attribute) { - if a >= 1<<32 { - panic("attribute value currently unsupported") - } - C.LLVMRemoveInstrAttribute(v.C, C.unsigned(i), C.LLVMAttribute(a)) -} func (v Value) SetInstrParamAlignment(i int, align int) { C.LLVMSetInstrParamAlignment(v.C, C.unsigned(i), C.unsigned(align)) } Index: bindings/go/llvm/ir_test.go =================================================================== --- bindings/go/llvm/ir_test.go +++ /dev/null @@ -1,97 +0,0 @@ -//===- ir_test.go - Tests for ir ------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file tests bindings for the ir component. -// -//===----------------------------------------------------------------------===// - -package llvm - -import ( - "strings" - "testing" -) - -func testAttribute(t *testing.T, attr Attribute, name string) { - mod := NewModule("") - defer mod.Dispose() - - ftyp := FunctionType(VoidType(), nil, false) - fn := AddFunction(mod, "foo", ftyp) - - fn.AddFunctionAttr(attr) - newattr := fn.FunctionAttr() - if attr != newattr { - t.Errorf("got attribute mask %d, want %d", newattr, attr) - } - - text := mod.String() - if !strings.Contains(text, " "+name+" ") { - t.Errorf("expected attribute '%s', got:\n%s", name, text) - } - - fn.RemoveFunctionAttr(attr) - newattr = fn.FunctionAttr() - if newattr != 0 { - t.Errorf("got attribute mask %d, want 0", newattr) - } -} - -func TestAttributes(t *testing.T) { - // Tests that our attribute constants haven't drifted from LLVM's. - attrTests := []struct { - attr Attribute - name string - }{ - {SanitizeAddressAttribute, "sanitize_address"}, - {AlwaysInlineAttribute, "alwaysinline"}, - {BuiltinAttribute, "builtin"}, - {ByValAttribute, "byval"}, - {ConvergentAttribute, "convergent"}, - {InAllocaAttribute, "inalloca"}, - {InlineHintAttribute, "inlinehint"}, - {InRegAttribute, "inreg"}, - {JumpTableAttribute, "jumptable"}, - {MinSizeAttribute, "minsize"}, - {NakedAttribute, "naked"}, - {NestAttribute, "nest"}, - {NoAliasAttribute, "noalias"}, - {NoBuiltinAttribute, "nobuiltin"}, - {NoCaptureAttribute, "nocapture"}, - {NoDuplicateAttribute, "noduplicate"}, - {NoImplicitFloatAttribute, "noimplicitfloat"}, - {NoInlineAttribute, "noinline"}, - {NonLazyBindAttribute, "nonlazybind"}, - {NonNullAttribute, "nonnull"}, - {NoRedZoneAttribute, "noredzone"}, - {NoReturnAttribute, "noreturn"}, - {NoUnwindAttribute, "nounwind"}, - {OptimizeNoneAttribute, "optnone"}, - {OptimizeForSizeAttribute, "optsize"}, - {ReadNoneAttribute, "readnone"}, - {ReadOnlyAttribute, "readonly"}, - {ReturnedAttribute, "returned"}, - {ReturnsTwiceAttribute, "returns_twice"}, - {SExtAttribute, "signext"}, - {SafeStackAttribute, "safestack"}, - {StackProtectAttribute, "ssp"}, - {StackProtectReqAttribute, "sspreq"}, - {StackProtectStrongAttribute, "sspstrong"}, - {StructRetAttribute, "sret"}, - {SanitizeThreadAttribute, "sanitize_thread"}, - {SanitizeMemoryAttribute, "sanitize_memory"}, - {UWTableAttribute, "uwtable"}, - {ZExtAttribute, "zeroext"}, - {ColdAttribute, "cold"}, - } - - for _, a := range attrTests { - testAttribute(t, a.attr, a.name) - } -}