Closed dannypsnl closed 2 years ago
Since LLVM IR is front end language agnostic, we cannot assume that the strings are NULL-terminated or length-prefixed. Thus, there may exist more than one reasonable implementation of a "get string" method.
For this reason, it belong well in an irutil
library. Perhaps we could include two standard versions, one for NULL-terminated strings, and one for length-prefixed strings.
Cheers, Robin
sounds good
I would create two API
ok...maybe the problem is should we add Len
for CharArray
?
ok...maybe the problem is should we add Len for CharArray?
CharArray
is modelled from the character array of LLVM. It handles any kind of string, not just length-prefixed strings, so I think using irutil
for Pascal strings is the way to go.
To get the length of a CharArray
, simply use len
:
c := constant.NewCharArrayFromString("foo")
n := len(c.X)
A common string using is like
but that's quite annoying that we have to use GEP since in most cases we just want a pointer to the zero address of the string and the type of string is always the same.
Thus, I want to introduce API for this
I think the second one make more sense, since this pattern only useful for string literal