Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getting strings from string constants #52

Merged
merged 1 commit into from
Sep 10, 2023
Merged
Changes from all commits
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
18 changes: 16 additions & 2 deletions ir.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ package llvm
#include <stdlib.h>
*/
import "C"
import "unsafe"
import "errors"
import (
"errors"
"unsafe"
)

type (
// We use these weird structs here because *Ref types are pointers and
Expand Down Expand Up @@ -910,6 +912,18 @@ func ConstVector(scalarConstVals []Value, packed bool) (v Value) {
return
}

// IsConstantString checks if the constant is an array of i8.
func (v Value) IsConstantString() bool {
return C.LLVMIsConstantString(v.C) != 0
}

// ConstGetAsString will return the string contained in a constant.
func (v Value) ConstGetAsString() string {
length := C.ulong(0)
cstr := C.LLVMGetAsString(v.C, &length)
return C.GoStringN(cstr, C.int(length))
}

// Constant expressions
func (v Value) Opcode() Opcode { return Opcode(C.LLVMGetConstOpcode(v.C)) }
func (v Value) InstructionOpcode() Opcode { return Opcode(C.LLVMGetInstructionOpcode(v.C)) }
Expand Down
Loading