Skip to content
BitVecTryFromIntegerAlloc

BitVecTryFromIntegerAlloc

Description

Build a bitvector from an integer using an explicit allocator.

Parameters

Name Direction Description
out out Destination bitvector.
value in Integer value to convert.
bits in Number of bits to emit.
alloc in Allocator to bind to the destination bitvector.

Success

Returns true and initializes out.

Failure

Returns false if allocation fails.

Usage example (Cross-references)

Usage examples (Cross-references)
        }
    
        if (!BitVecTryFromIntegerAlloc(&out->bits, value, bits, alloc)) {
            IntDeinit(out);
            *out = IntInit(alloc);
        }
    
        if (!BitVecTryFromIntegerAlloc(INT_BITS(out), value, bits, alloc)) {
            IntDeinit(out);
            *out = IntInit(alloc);
    }
    
    bool BitVecTryFromIntegerAlloc(BitVec *out, u64 value, u64 bits, Allocator alloc) {
        if (!out) {
            LOG_FATAL("out is NULL");
        BitVec result;
    
        if (!BitVecTryFromIntegerAlloc(&result, value, bits, alloc)) {
            result = BitVecInit(alloc);
        }
    #define BitVecTryFromInteger(...)                                                                                      \
        CONCAT(BitVecTryFromInteger_, BITVEC_TRY_FROM_INTEGER_HAS_ARGS(__VA_ARGS__))(__VA_ARGS__)
    #define BitVecTryFromInteger_3(out, value, bits)        BitVecTryFromIntegerAlloc((out), (value), (bits), DefaultAllocator())
    #define BitVecTryFromInteger_4(out, value, bits, alloc) BitVecTryFromIntegerAlloc((out), (value), (bits), (alloc))
        CONCAT(BitVecTryFromInteger_, BITVEC_TRY_FROM_INTEGER_HAS_ARGS(__VA_ARGS__))(__VA_ARGS__)
    #define BitVecTryFromInteger_3(out, value, bits)        BitVecTryFromIntegerAlloc((out), (value), (bits), DefaultAllocator())
    #define BitVecTryFromInteger_4(out, value, bits, alloc) BitVecTryFromIntegerAlloc((out), (value), (bits), (alloc))
    
    ///
Last updated on