[llvm-dev] Newbie question on codeine for SmallString

ecwdw 23e3e23e via llvm-dev llvm-dev at lists.llvm.org
Tue Mar 27 17:04:11 PDT 2018


Let me explain a bit better. Suppose in a custom language we want to support strings implemented as llvm::SmallString. You can imagine code like this,

——————
String s(“Hello world);
s.append(“ and hello llvm-dev”);
————————

The objective is to emit the code for this. Now as the tutorial explains, I’d have to do some work here. That’s fine. 

So would the general approach be to write each desired supported code block — here declaration, initialization, and append — write the equivalent as in C++ and copy-and-paste the IR clang produces with —emit-llvm into my generator? Or is there a smarter way?   

> On Mar 27, 2018, at 7:48 PM, ecwdw 23e3e23e <efdwefwfwerf at gmail.com> wrote:
> 
> The LLVM Tutorial,
> 
>   https://llvm.org/docs/tutorial/LangImpl01.html
> 
> provides an excellent introduction to language definition and code generation.
> 
> I am looking for a similar example that demonstrates how to use SmallString. Even a small test program,
> 
> ————
> #include <llvm/ADT/SmallString.h>
> 
> int main(int argc, char **argv)
> {
>    llvm::SmallString<32> str("hello world\n");
>    printf("%s\n", str.c_str());
>    return 0;
> }
> ————
> 
> produces  81 lines of IR. In the same way the tutorials generate code over doubles, I’m looking for a way to generate IR code for SmallStrings over typical blocks: declare variable of type SmallString, assign to it, concat to it, and so on.
> 
> Thanks



More information about the llvm-dev mailing list