Difficulty inserting putchar in IR

Hi,

I have written a simple code to insert putchar() function into IR.
It compiled well but when I tried to run the generated .bc file with lli, its not showing
proper output.

Function *putchar_func = cast(M->
getOrInsertFunction(“putchar”, IntegerType::getInt32Ty(Context),
IntegerType::getInt32Ty(Context), NULL));

Value *One = ConstantInt::get(Type::getInt32Ty(Context), 1);

CallInst *CallFibX1 = CallInst::Create(putchar_func, One, “fibx1”, BB);
CallFibX1->setTailCall();

Thanks and Regards,
Tarun Agrawal

Hi,

I have written a simple code to insert putchar() function into IR.
It compiled well but when I tried to run the generated .bc file with lli, its not showing
proper output.

Function *putchar_func = cast(M->
getOrInsertFunction(“putchar”, IntegerType::getInt32Ty(Context),
IntegerType::getInt32Ty(Context), NULL));

Value *One = ConstantInt::get(Type::getInt32Ty(Context), 1);

CallInst *CallFibX1 = CallInst::Create(putchar_func, One, “fibx1”, BB);
CallFibX1->setTailCall();

I’m assuming the program runs through lli but is not showing any output.

I think you’re calling putchar() with a value of 1. That may be an unprintable character (like ctrl-a). Try a value that is an ASCII character (I think ‘A’ is 65, but it’s been awhile).

– John T.