<div dir="ltr"><div><div><div><div><div>Hi Alex, I'll try to answer your questions to the best of my knowledge:<br><br></div>1) You can use the IRBuilder::CreateGlobalStringPtr function, which returns a value with the "i8*" type.<br>
<br></div>2) You can define a structure type using llvm::StructType::get or create function. When you want to store a string in the structure, you can add a field which has the "i8*" type, which stores a pointer to a null-terminated i8(character) array, or you can also add a field which has a structure type that stores both the pointer and the length of the string. <br>
<br></div>3) I'm not quite sure what exactly do you mean, but I'm guessing that you want to add new fields to this structure based on the run-time behavior of the program. You can do this by storing a dynamic array in your structure, and inserting pointers into this dynamic array.<br>
<br></div>I hope that was helpful,<br></div>Alex<br><div class="gmail_extra"><br><br><div class="gmail_quote">2013/12/3 Alexander Popolitov <span dir="ltr"><<a href="mailto:popolit@gmail.com" target="_blank">popolit@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
<br>
<div>For some reason the mail didn't
got through the first time, so sending it again.<div><div><br>
<br>
-------- Original Message --------
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<th nowrap valign="BASELINE" align="RIGHT">Subject:
</th>
<td>code-generating constant strings</td>
</tr>
<tr>
<th nowrap valign="BASELINE" align="RIGHT">Date: </th>
<td>Tue, 03 Dec 2013 01:56:11 +0100</td>
</tr>
<tr>
<th nowrap valign="BASELINE" align="RIGHT">From: </th>
<td>Alexander Popolitov <a href="mailto:popolit@gmail.com" target="_blank"><popolit@gmail.com></a></td>
</tr>
<tr>
<th nowrap valign="BASELINE" align="RIGHT">To: </th>
<td><a href="mailto:llvmdev@cs.uiuc.edu" target="_blank">llvmdev@cs.uiuc.edu</a>.</td>
</tr>
</tbody>
</table>
<br>
<br>
<pre>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
</pre>
<br>
</div></div></div>
<br>
</div>
<br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div></div>