Skip to content

Commit

Permalink
CreateGlobalStringPtr
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Apr 29, 2024
1 parent d083ead commit aca6320
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 aca6320

Please sign in to comment.