Skip to content

Commit 41ff177

Browse files
committed
Add getting strings from string constants
1 parent 8e7ec80 commit 41ff177

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

ir.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ package llvm
1919
#include <stdlib.h>
2020
*/
2121
import "C"
22-
import "unsafe"
23-
import "errors"
22+
import (
23+
"errors"
24+
"unsafe"
25+
)
2426

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

915+
// IsConstantString checks if the constant is an array of i8.
916+
func (v Value) IsConstantString() bool {
917+
return C.LLVMIsConstantString(v.C) != 0
918+
}
919+
920+
// ConstGetAsString will return the string contained in a constant.
921+
func (v Value) ConstGetAsString() string {
922+
length := C.ulong(0)
923+
cstr := C.LLVMGetAsString(v.C, &length)
924+
return C.GoStringN(cstr, C.int(length))
925+
}
926+
913927
// Constant expressions
914928
func (v Value) Opcode() Opcode { return Opcode(C.LLVMGetConstOpcode(v.C)) }
915929
func (v Value) InstructionOpcode() Opcode { return Opcode(C.LLVMGetInstructionOpcode(v.C)) }

0 commit comments

Comments
 (0)