Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions ir.go
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,40 @@ func (v Value) AddTargetDependentFunctionAttr(attr, value string) {
func (v Value) SetPersonality(p Value) {
C.LLVMSetPersonalityFn(v.C, p.C)
}
func IntrinsicID(name string) (id uint) {
cname := C.CString(name)
defer C.free(unsafe.Pointer(cname))
id = uint(C.LLVMLookupIntrinsicID(cname, C.size_t(len(name))))
return
}
func IsIntrinsicOverloaded(id uint) bool {
return C.LLVMIntrinsicIsOverloaded(C.unsigned(id)) != 0
}
func IntrinsicName(id uint) string {
length := C.size_t(0)
cname := C.LLVMIntrinsicGetName(C.unsigned(id), &length)
return C.GoStringN(cname, C.int(length))
}
func (c Context) IntrinsicType(id uint, paramTypes []Type) (t Type) {
t.C = C.LLVMIntrinsicGetType(c.C, C.unsigned(id), llvmTypeRefPtr(&paramTypes[0]), C.size_t(len(paramTypes)))
return
}
func (c Module) InsertIntrinsic(id uint, paramTypes []Type) (v Value) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest GetIntrinsic to match the C name and because it really is a kind of getter.

var pt *C.LLVMTypeRef
if paramTypes == nil {
pt = nil
} else {
pt = llvmTypeRefPtr(&paramTypes[0])
}
v.C = C.LLVMGetIntrinsicDeclaration(c.C, C.unsigned(id), pt, C.size_t(len(paramTypes)))
return
}
func (c Module) CopyOverloadedName(id uint, paramTypes []Type) string {
lenght := C.size_t(0)
cname := C.LLVMIntrinsicCopyOverloadedName2(c.C, C.unsigned(id), llvmTypeRefPtr(&paramTypes[0]), C.size_t(len(paramTypes)), &lenght)
defer C.free(unsafe.Pointer(cname))
return C.GoStringN(cname, C.int(lenght))
}

// Operations on parameters
func (v Value) ParamsCount() int { return int(C.LLVMCountParams(v.C)) }
Expand Down