[LLVMdev] Complex constant expressions?

Talin viridia at gmail.com
Tue Jan 22 21:36:40 PST 2008


Neil Booth wrote:
> Talin wrote:-
>   
>> On the other hand, writing an interpreter means duplicating a lot of
>> the functionality that's already in LLVM. For example, consider just
>> the problem of float to int conversions:
>>
>>    char B[ (int)3.0 ];
>>
>> Generating code for this is relatively simple; Converting
>> arbitrary-sized APFloats to arbitrary-sized APInts isn't quite as
>> easy.
>>     
>
> APFloat::convertToInteger does just this.  Why can't you use it? 
>   
Well, I may be using it wrong. But looking at APFloat.h, I see four 
functions that purport to convert to integer:

    opStatus convertToInteger(integerPart *, unsigned int, bool,
                  roundingMode) const;
    opStatus convertFromSignExtendedInteger(const integerPart *, 
unsigned int,
                                            bool, roundingMode);
    opStatus convertFromZeroExtendedInteger(const integerPart *, 
unsigned int,
                                            bool, roundingMode);
    APInt convertToAPInt() const;

The first three convert to an array of integer parts, which (as far as I 
can tell) is not easily convertible into an APInt via any public methods 
I have been able to discover so far.

The last function doesn't appear to convert the APFloat into the nearest 
integer equivalent, since my experiments with it returned completely 
unexpected values; I'm assuming that what is returned is an APInt 
containing the bitwise representation of the floating-point value?

-- Talin




More information about the llvm-dev mailing list