Hello every, I am new to LLVM, using it to create a system
Now I have a problem
code below:
int main(int argc, char **argv)
{
symbolic(2);//symbolic(int a)
sleep(1,2);//sleep(int a, int b)
}
two definations of sleep
int sleep(int a, int b)
{
return a+b;
}
int sleep(int a, int b)
{
return a-b;
}
can I choose different sleep() by the result of symbolic(),
if symbolic(5) calling the first sleep
if symbolic(2) calling the second sleep
how to make it by using PASS, how to complete it by writing symbolic()
Do you have any ideas,
Thank you very much
Hi 赵夏,
Hello every, I am new to LLVM, using it to create a system
Now I have a problem
code below:
int main(int argc, char **argv)
{
symbolic(2);//symbolic(int a)
sleep(1,2);//sleep(int a, int b)
}
two definations of sleep
int sleep(int a, int b)
{
return a+b;
}
int sleep(int a, int b)
{
return a-b;
}
can I choose different sleep() by the result of symbolic(),
if symbolic(5) calling the first sleep
if symbolic(2) calling the second sleep
I'm not sure exactly what you are asking. If symbolic returns a boolean
value, and you want to call different sleep functions depending on the
result, then:
(1) make sure the different sleep functions have different names, say sleep1
and sleep2.
(2) create a CallInst (call this CI) which calls symbolic.
(3) create a conditional Branch instruction which uses CI as the condition,
and branches either to basic block B1 or B2 depending on the condition.
You will need to create B1 and B2 and insert them into your function.
(4) in B1, create a call to sleep1; in B2, create a call to sleep2.
(5) at the ends of B1 and B2, create unconditional branches to a basic block
B3. You will need to create B3 and insert it in your function.
(6) the return statement goes in B3.
One way to understand how to do things is to write an example in C, and
paste it into http://llvm.org/demo/ That will output LLVM IR that implements
the C you pasted, showing one way of implementing it in LLVM IR.
Ciao, Duncan.