diff --git a/ir.go b/ir.go index 28595b1..4b62c31 100644 --- a/ir.go +++ b/ir.go @@ -19,8 +19,10 @@ package llvm #include */ import "C" -import "unsafe" -import "errors" +import ( + "errors" + "unsafe" +) type ( // We use these weird structs here because *Ref types are pointers and @@ -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)) }