Skip to content

Commit

Permalink
Merge pull request #10 from xushiwei/q
Browse files Browse the repository at this point in the history
CreateGlobalStringPtr
  • Loading branch information
xushiwei authored Apr 29, 2024
2 parents 3476221 + aca6320 commit 4d6268b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions z_llvmext.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ package llvm

/*
#include "llvm-c/Core.h"
#include <stdlib.h>
*/
import "C"
import (
"runtime"
"unsafe"
)

func (c Context) Finalize() {
Expand Down Expand Up @@ -118,3 +120,10 @@ func CreateCall(b Builder, t Type, fn Value, args []Value) (v Value) {
v.C = C.LLVMBuildCall2(b.C, t.C, fn.C, ptr, nvals, &emptyCStr[0])
return
}

func CreateGlobalStringPtr(b Builder, str string) (v Value) {
cstr := C.CString(str)
defer C.free(unsafe.Pointer(cstr))
v.C = C.LLVMBuildGlobalStringPtr(b.C, cstr, &emptyCStr[0])
return
}

0 comments on commit 4d6268b

Please sign in to comment.