<div>Hi John,</div><div><br></div>Thanks John. I tried using SequentialType::getElementType() function and it worked. <div><br></div><div>I have one more question how can we do function permutation at intermediate representation byte code level?<div>
<br></div><div>If I have lets say C program having three functions and its corresponding IR bytecode. </div><div><div><div><br></div><div>void findLen(char a[10])</div><div>{</div><div> int tmp = strlen(a);</div><div> printf("Len is : %d\n", tmp);</div>
<div>}</div></div><div>void muladd(int a, int b, int c)</div><div>{</div><div> int tmp = a + b;</div><div> int tmp1 = tmp * c;</div><div> printf("Addition is : %d Multiplication is : %d\n", tmp, tmp1);</div>
<div> char d[10] = "abhd";</div><div> findLen(d);</div><div>}</div><div>void main()</div><div>{</div><div> int x = 8, y = 5, z = 3;</div><div> muladd(x, y, z);</div><div>}</div></div><div><br></div><div>
In its corresponding .s / .ll IR bytecode file function sequence will be same first findLen() then muladd() and then main(). Suppose I want to change this sequence i.e. swap findLen() and muladd() function's positions. I am expecting to have IR bytecode of first muladd() then findLen() and then main() in the output file. </div>
<div><br></div><div>Can you please tell me how can I achieve it ? </div><div><br></div><div>Thanks,</div><div>Teja<br><br><div class="gmail_quote">On Mon, Feb 25, 2013 at 11:54 AM, John Criswell <span dir="ltr"><<a href="mailto:criswell@illinois.edu" target="_blank">criswell@illinois.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"><div class="im">
<div>On 2/25/13 1:44 PM, teja tamboli wrote:<br>
</div>
<blockquote type="cite">
<div style="color:rgb(34,34,34);font-size:12.727272033691406px;font-family:arial,sans-serif">Hi
all,</div>
<div style="color:rgb(34,34,34);font-size:12.727272033691406px;font-family:arial,sans-serif"><br>
</div>
<div style="color:rgb(34,34,34);font-size:12.727272033691406px;font-family:arial,sans-serif">I
am working on my Master's project in security and I am trying to
iterate over the argument list of the function. Basically I need
to do following things :</div>
</blockquote>
<br></div>
Interesting. Just out of curiosity, can you tell us what your
project is about?<div class="im"><br>
<br>
<blockquote type="cite">
<div style="color:rgb(34,34,34);font-size:12.727272033691406px;font-family:arial,sans-serif"><br>
</div>
<div style="color:rgb(34,34,34);font-size:12.727272033691406px;font-family:arial,sans-serif">1.
Check data type of each argument of the argument list of the
function.<br>
2. Based on its data type like character array or integer array,
pointer, int, char, take different action. <br>
3. I have added following code to check its data type. <br>
</div>
</blockquote>
<br></div>
There is one caveat when working with LLVM types: the type indicates
what the function *expects* to get as an argument; it does not
represent what the type of the actual memory object passed into the
function will be. A caller can cast a pointer of one structure type
to a different structure type and pass that into a function.<div class="im"><br>
<br>
<blockquote type="cite">
<div style="color:rgb(34,34,34);font-size:12.727272033691406px;font-family:arial,sans-serif"><br>
// F is any function basically of type function *<br>
FunctionType *FTy = F->getFunctionType();<br>
unsigned int numArgs = FTy->getNumParams();<br>
<br>
//Currently just checking data type of the 0th argument.
Eventually will be running it in the loop from 0 to numArgs.<br>
</div>
<div>
errs() << "\n1 Argument type int 32 : " <<
FTy->getParamType(0)->isIntegerTy(32);<br>
errs() << "\n2 Argument type char : " <<
FTy->getParamType(0)->isIntegerTy(8);<br>
errs() << "\n4 Argument type pointer : " <<
FTy->getParamType(0)->isPointerTy();<br>
errs() << "\n5 Argument type array : " <<
FTy->getParamType(0)->isArrayTy();<br>
errs() << "\n6 Argument type structure : " <<
FTy->getParamType(0)->isStructTy(); <br>
</div>
<br>
I can just find these many data types for integer and characters.
This just tells me that parameter is of type pointer or array or
structure. <br>
<br>
My question is if function's parameter type is pointer / array,
how can I figure it out whether its character pointer or integer
pointer? <br>
</blockquote>
<br></div>
You need to use dyn_cast<SequentialType> to convert the Type *
into a SequentialType *. With that, you can use
SequentialType::getElementType() to see what type of pointer
type/array type it is.<br>
<br>
You can also use dyn_cast<> to cast to an ArrayType to get the
declared size of the array, or to a StructType so that you can
examine the structure type's fields.<br>
<br>
You should be familiar with how to use dyn_cast<>(), and you
should be familiar with the LLVM type classes. The former is
documented in the LLVM Programmer's Manual, and the latter can be
found within the doxygen documentation.<br>
<br>
-- John T.<br>
<br>
<blockquote type="cite"><div class="im">Also if it is a array then how can I find size of the
array? <br>
In case of structure how to check exact structure definition I
mean exactly it is instance of which structure? <br>
<br>
Please let me know. <br>
<br>
Thanks, <br>
--Teja
<br>
<fieldset></fieldset>
<br>
</div><pre>_______________________________________________
LLVM Developers mailing list
<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>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
</blockquote>
</div></blockquote></div><br></div></div>