[LLVMdev] Fwd: code-generating constant strings

Alexander Popolitov popolit at gmail.com
Tue Dec 3 12:23:02 PST 2013


For some reason the mail didn't got through the first time, so sending 
it again.

-------- Original Message --------
Subject: 	code-generating constant strings
Date: 	Tue, 03 Dec 2013 01:56:11 +0100
From: 	Alexander Popolitov <popolit at gmail.com>
To: 	llvmdev at cs.uiuc.edu.



Hi, everyone!

I have maybe very naive question, but nontheless.
I'm experimenting with Kaleidoscope tutorial and I want to morph it into
something similar to McCarthy's initial Lisp.
For that, I need to implement symbols, which I thought I should
implement as pointers to structures, and those
structures would contain at least one field, which would be symbol's name.
So, here's a question: how do I generate a code, that represents a
literal string on LLVM side using LLVM's C++ API
I'm asking, because to simply generate constant floating-point value C++
API uses
an incantation 'ConstantFP::get(getGlobalContext(), APFloat(Val));' so I
guess string generation is also not obvious.

In the textual LLVM, what I want to generate is something like
'@.foo_sym = private unnamed_addr constant {[13 x i8] c"hello world\0A\00"}'

I just modified the example of a constant string from LLVM reference
manual, adding curly braces.
So, what I really want is for any newly encountered symbol to generate
code, that declares variable, which is structure, which contains
that symbol name, and a way to access the address of that structure,
substituting all occurencies of that symbol in a code I'm generating
by the pointer to that structure.
So, how would I (using C++ API):
   1. generate code that defines constant string
   2. generate code, that defines structure, that contains a string
   3. when generating further code, be able to insert a pointer to this
structure?


Yours sincerely,
Alex



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131203/8e79a314/attachment.html>


More information about the llvm-dev mailing list