<div dir="ltr">Hello there,<div><br></div><div>I'm trying to use a simple implementation of a queue (my own implementation of it, actually), and I'm trying to use the functions defined on my queue class inside some llvm-ir code. Unfortunately, the names of the functions are being messed up, then I created some function wrappers just to avoid having to deal with the C++ weird function renaming.</div>

<div><br></div><div>So, to easily wrapper the class, I wrote a queue_wrapper.h library, which, basically, has the following code (where Q is a reference to my queue, and the channel is not really important):</div><div><br>

</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div style><p class="" style><b><font face="courier new, monospace">extern<span class=""> </span><span class="">"C"</span><span class=""> {</span> </font></b></p>

</div><div style><p class="" style><b><font face="courier new, monospace">#ifdef INT_TYPE</font></b></p></div><div style><p class="" style><b><font face="courier new, monospace"><span class="">  </span>void<span class=""> </span>__attribute__<span class="">((noinline))</span></font></b></p>

</div><div style><p class="" style><b><font face="courier new, monospace">  <span class="">TYPED_NAME</span>(produceValue)(<span class="">int</span> channel, <span class="">TYPE</span> elem)</font></b></p></div><div style>

<p class="" style><b><font face="courier new, monospace">  {Q-><span class="">addElement</span> (channel, (<span class="">long</span>)elem);}</font></b></p></div><div style><p class="" style><b><font face="courier new, monospace"><br>

</font></b></p></div><div style><p class="" style><b><font face="courier new, monospace">  <span class="">TYPE</span> <span class="">__attribute__</span>((noinline))</font></b></p></div><div style><p class="" style><b><font face="courier new, monospace">  <span class="">TYPED_NAME</span>(consumeValue)(<span class="">int</span> channel)</font></b></p>

</div><div style><p class="" style><b><font face="courier new, monospace">  {<span class="">return</span> (<span class="">TYPE</span>) Q-><span class="">removeElement</span> (channel);}</font></b></p></div><div style>
<p class="" style>
<b><font face="courier new, monospace">#endif</font></b></p></div><div style><p class="" style><b><font face="courier new, monospace"><br></font></b></p></div><div style><p class="" style><b><font face="courier new, monospace"><span class="">  </span>void<span class=""> </span>__attribute__<span class="">((noinline))</span></font></b></p>

</div><div style><p class="" style><b><font face="courier new, monospace">  <span class="">TYPED_NAME</span>(producePtrValue)(<span class="">int</span> channel, <span class="">TYPE</span>* elem)</font></b></p></div><div style>

<p class="" style><b><font face="courier new, monospace">  {Q-><span class="">addPtrElement</span> (channel, (<span class="">void</span>*)elem);}</font></b></p></div><div style><p class="" style><b><font face="courier new, monospace"><br>

</font></b></p></div><div style><p class="" style><b><font face="courier new, monospace">  <span class="">TYPE</span>* <span class="">__attribute__</span>((noinline))</font></b></p></div><div style><p class="" style><b><font face="courier new, monospace">  <span class="">TYPED_NAME</span>(consumePtrValue)(<span class="">int</span> channel)</font></b></p>

</div><div style><p class="" style><b><font face="courier new, monospace">  {<span class="">return</span> (<span class="">TYPE</span>*) Q-><span class="">removePtrElement</span> (channel);}</font></b></p></div><div style>

<p class="" style><b><font face="courier new, monospace">  </font></b></p></div><div style><p class="" style><b><font face="courier new, monospace">#ifdef FP_TYPE</font></b></p></div><div style><p class="" style><b><font face="courier new, monospace"><span class="">  </span>void<span class=""> </span>__attribute__<span class="">((noinline))</span></font></b></p>

</div><div style><p class="" style><b><font face="courier new, monospace">  TYPED_NAME(produceFPValue)(<span class="">int</span> channel, TYPE elem)</font></b></p></div><div style><p class="" style><b><font face="courier new, monospace">  {Q->addFPElement (channel, (<span class="">double</span>)elem);}</font></b></p>

</div><div style><p class="" style><b><font face="courier new, monospace"><br></font></b></p></div><div style><p class="" style><b><font face="courier new, monospace">  TYPE <span class="">__attribute__</span>((noinline))</font></b></p>

</div><div style><p class="" style><b><font face="courier new, monospace">  TYPED_NAME(consumeFPValue)(<span class="">int</span> channel)</font></b></p></div><div style><p class="" style><b><font face="courier new, monospace">  {<span class="">return</span> (TYPE) Q->removeFPElement (channel);}</font></b></p>

</div><div style><p class="" style><b><font face="courier new, monospace">#endif</font></b></p></div><div style><p class="" style><b><font face="courier new, monospace">}</font></b></p></div></blockquote><div>


































<div><br></div><div>In order to define a set of functions for a type, I can simply insert the following lines on my original library:</div><div><br></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px">

<div style><div style><p class="" style><font face="courier new, monospace"><b>#define INT_TYPE</b></font></p></div></div><div style><div style><p class="" style><font face="courier new, monospace"><b>#define TYPE char</b></font></p>

</div></div><div style><div style><p class="" style><font face="courier new, monospace"><b>#define TYPED_NAME(x) i8_##x</b></font></p></div></div><div style><div style><p class="" style><font face="courier new, monospace"><b><span class="">#include </span>"queue_wrappers.h"</b></font></p>

</div></div><div style><div style><p class="" style><font face="courier new, monospace"><b>#undef TYPE</b></font></p></div></div><div style><div style><p class="" style><font face="courier new, monospace"><b>#undef TYPED_NAME</b></font></p>

</div></div><div style><div style><p class="" style><font face="courier new, monospace"><b>#undef INT_TYPE</b></font></p></div></div></blockquote><div><div>













<p class="" style>And, for this example, the functions i8_produceValue, i8_consumeValue, i8_producePtrValue and i8_consumePtrValue should be defined.</p><p class="" style>Well, the problem is that all those functions are being defined, indeed, but every function inside the #ifdef INT_TYPE's preprocessor flag has only a call to llvm.trap() function inside its body =/</p>

<p class="" style>And this is only happening to the functions (*)_consumeValue and (*)_produceValue: all the other functions [(*)_consumePtrValue, (*)_producePtrValue, (*)_consumeFPValue and (*)_produceFPValue] has their bodies correctly defined on the resultant bc file.</p>

<p class="" style>Since the only difference between their implementation on the queue is the type defined inside the queue (long for integer types, void* for pointers and double for floating point numbers), does anyone have any ideia why I am having this issue with integers?</p>

<p class="" style><br></p><p class="" style>PS: I tried to implement the integer type functions using C++ templates, and it was as I expected: the functions for integer types were created with their correct set of instructions inside. However, when using templates, the names of the functions are being messed up (which was the issue I was trying to avoid in the first place).</p>

<p class="" style>Thanks in advance,</p><p class="" style><br>--</p>Cristianno Martins<br>PhD Student of Computer Science<br>University of Campinas<br><a href="mailto:cmartins@ic.unicamp.br" target="_blank">cmartins@ic.unicamp.br</a><br>

<a href="mailto:cristiannomartins@hotmail.com" target="_blank"></a></div>
</div></div>