[LLVMdev] conversion from 'const llvm::Value*' to 'llvm::Constant*'
Duncan Sands
baldrick at free.fr
Sun Feb 13 09:09:56 PST 2011
Hi Anton,
> Oh, I thought that after "codegening" cos(0) would get me double 1.0
> (assigment is working for anything like: global a = 1/3 + 2 /3 for
> example) What would be the best way to make assigments involving
> functions, like global a = cos(0);
> without getting the assertion arising from InitVal =
> cast<Constant>(Init->Codegen()); ?
the problem is that you are performing a function call (to "cos"). A function
call is simply not a constant in the sense of LLVM (even if it is a constant in
the sense of mathematics): it needs to be executed to work out what the return
value is, and something that needs to be executed is not a Constant.
Probably you should have a constructor call "cos" and assign the return value
to your global. To work out how to do this I suggest you write the C code
corresponding to assigning cos(0) to a and stick it in http://llvm.org/demo to
see how it is handled.
Ciao, Duncan.
More information about the llvm-dev
mailing list