tmpl = templates._FUNC_SERIALIZE_EVENT_PROTO_END
self._cg.add_lines(tmpl)
- def _generate_bitfield_write(self, var, ctx, t):
+ def _generate_bitfield_write(self, ctype, var, ctx, t):
ptr = '&{ctx}->buf[_BITS_TO_BYTES({ctx}->at)]'.format(ctx=ctx)
start = self._sasa.byte_offset
suffix = 'le' if t.byte_order is metadata.ByteOrder.LE else 'be'
func = '{}bt_bitfield_write_{}'.format(self._cfg.prefix, suffix)
- call = '{}({}, uint8_t, {}, {}, {});'.format(func, ptr, start, t.size,
- var)
+ call_fmt = '{func}({ptr}, uint8_t, {start}, {size}, {ctype}, ({ctype}) {var});'
+ call = call_fmt.format(func=func, ptr=ptr, start=start, size=t.size,
+ ctype=ctype, var=var)
self._cg.add_line(call)
def _generate_serialize_int(self, var, ctx, t):
- self._generate_bitfield_write(var, ctx, t)
+ ctype = self._get_int_ctype(t)
+ self._generate_bitfield_write(ctype, var, ctx, t)
self._generate_incr_pos('{}->at'.format(ctx), t.size)
def _generate_serialize_float(self, var, ctx, t):
gen_union_var = True
union_name = 'f2u'
+ int_ctype = 'uint32_t'
elif ctype == 'double':
if not self._ud_written:
self._ud_written = True
gen_union_var = True
union_name = 'd2u'
+ int_ctype = 'uint64_t'
if gen_union_var:
# union for reading the bytes of the floating point number
-
self._cg.add_line('union {name} {name};'.format(name=union_name))
self._cg.add_empty_line()
bf_var = '{}.u'.format(union_name)
else:
bf_var = '({}) {}'.format(ctype, var)
+ int_ctype = ctype
- self._generate_bitfield_write(bf_var, ctx, t)
+ self._generate_bitfield_write(int_ctype, bf_var, ctx, t)
self._generate_incr_pos('{}->at'.format(ctx), t.size)
def _generate_serialize_enum(self, var, ctx, t):
#define $PREFIX$BYTE_ORDER $ENDIAN_DEF$
/* We can't shift a int from 32 bit, >> 32 and << 32 on int is undefined */
-#define _$prefix$bt_piecewise_rshift(_v, _shift) \\
-__extension__ ({ \\
- __typeof__(_v) ___v = (_v); \\
- __typeof__(_shift) ___shift = (_shift); \\
- unsigned long sb = (___shift) / (sizeof(___v) * CHAR_BIT - 1); \\
- unsigned long final = (___shift) % (sizeof(___v) * CHAR_BIT - 1); \\
- \\
- for (; sb; sb--) \\
- ___v >>= sizeof(___v) * CHAR_BIT - 1; \\
- ___v >>= final; \\
-})
-
-#define _$prefix$bt_piecewise_lshift(_v, _shift) \\
-__extension__ ({ \\
- __typeof__(_v) ___v = (_v); \\
- __typeof__(_shift) ___shift = (_shift); \\
- unsigned long sb = (___shift) / (sizeof(___v) * CHAR_BIT - 1); \\
- unsigned long final = (___shift) % (sizeof(___v) * CHAR_BIT - 1); \\
+#define _$prefix$bt_piecewise_rshift(_vtype, _v, _shift) \\
+do { \\
+ unsigned long ___shift = (_shift); \\
+ unsigned long sb = (___shift) / (sizeof(_v) * CHAR_BIT - 1); \\
+ unsigned long final = (___shift) % (sizeof(_v) * CHAR_BIT - 1); \\
\\
for (; sb; sb--) \\
- ___v <<= sizeof(___v) * CHAR_BIT - 1; \\
- ___v <<= final; \\
-})
+ _v >>= sizeof(_v) * CHAR_BIT - 1; \\
+ _v >>= final; \\
+} while (0)
#define _$prefix$bt_is_signed_type(type) ((type) -1 < (type) 0)
* Also, consecutive bitfields are placed from higher to lower bits.
*/
-#define _$prefix$bt_bitfield_write_le(_ptr, type, _start, _length, _v) \\
+#define _$prefix$bt_bitfield_write_le(_ptr, type, _start, _length, _vtype, _v) \\
do { \\
- __typeof__(_v) __v = (_v); \\
+ _vtype __v = (_v); \\
type *__ptr = CAST_PTR(type *, _ptr); \\
unsigned long __start = (_start), __length = (_length); \\
type mask, cmask; \\
\\
/* Trim v high bits */ \\
if (__length < sizeof(__v) * CHAR_BIT) \\
- __v &= ~((~(__typeof__(__v)) 0) << __length); \\
+ __v &= ~((~(_vtype) 0) << __length); \\
\\
/* We can now append v with a simple "or", shift it piece-wise */ \\
this_unit = start_unit; \\
cmask &= ~mask; \\
__ptr[this_unit] &= mask; \\
__ptr[this_unit] |= cmask; \\
- __v = _$prefix$bt_piecewise_rshift(__v, ts - cshift); \\
+ _$prefix$bt_piecewise_rshift(_vtype, __v, ts - cshift); \\
__start += ts - cshift; \\
this_unit++; \\
} \\
for (; this_unit < end_unit - 1; this_unit++) { \\
__ptr[this_unit] = (type) __v; \\
- __v = _$prefix$bt_piecewise_rshift(__v, ts); \\
+ _$prefix$bt_piecewise_rshift(_vtype, __v, ts); \\
__start += ts; \\
} \\
if (end % ts) { \\
__ptr[this_unit] = (type) __v; \\
} while (0)
-#define _$prefix$bt_bitfield_write_be(_ptr, type, _start, _length, _v) \\
+#define _$prefix$bt_bitfield_write_be(_ptr, type, _start, _length, _vtype, _v) \\
do { \\
- __typeof__(_v) __v = (_v); \\
+ _vtype __v = (_v); \\
type *__ptr = CAST_PTR(type *, _ptr); \\
unsigned long __start = (_start), __length = (_length); \\
type mask, cmask; \\
\\
/* Trim v high bits */ \\
if (__length < sizeof(__v) * CHAR_BIT) \\
- __v &= ~((~(__typeof__(__v)) 0) << __length); \\
+ __v &= ~((~(_vtype) 0) << __length); \\
\\
/* We can now append v with a simple "or", shift it piece-wise */ \\
this_unit = end_unit - 1; \\
cmask &= ~mask; \\
__ptr[this_unit] &= mask; \\
__ptr[this_unit] |= cmask; \\
- __v = _$prefix$bt_piecewise_rshift(__v, cshift); \\
+ _$prefix$bt_piecewise_rshift(__v, cshift); \\
end -= cshift; \\
this_unit--; \\
} \\
for (; (long) this_unit >= (long) start_unit + 1; this_unit--) { \\
__ptr[this_unit] = (type) __v; \\
- __v = _$prefix$bt_piecewise_rshift(__v, ts); \\
+ _$prefix$bt_piecewise_rshift(__v, ts); \\
end -= ts; \\
} \\
if (__start % ts) { \\
#if ($PREFIX$BYTE_ORDER == LITTLE_ENDIAN)
-#define $prefix$bt_bitfield_write_le(ptr, type, _start, _length, _v) \\
- _$prefix$bt_bitfield_write_le(ptr, type, _start, _length, _v)
+#define $prefix$bt_bitfield_write_le(ptr, type, _start, _length, _vtype, _v) \\
+ _$prefix$bt_bitfield_write_le(ptr, type, _start, _length, _vtype, _v)
-#define $prefix$bt_bitfield_write_be(ptr, type, _start, _length, _v) \\
- _$prefix$bt_bitfield_write_be(ptr, unsigned char, _start, _length, _v)
+#define $prefix$bt_bitfield_write_be(ptr, type, _start, _length, _vtype, _v) \\
+ _$prefix$bt_bitfield_write_be(ptr, unsigned char, _start, _length, _vtype, _v)
#elif ($PREFIX$BYTE_ORDER == BIG_ENDIAN)
-#define $prefix$bt_bitfield_write_le(ptr, type, _start, _length, _v) \\
- _$prefix$bt_bitfield_write_le(ptr, unsigned char, _start, _length, _v)
+#define $prefix$bt_bitfield_write_le(ptr, type, _start, _length, _vtype, _v) \\
+ _$prefix$bt_bitfield_write_le(ptr, unsigned char, _start, _length, _vtype, _v)
-#define $prefix$bt_bitfield_write_be(ptr, type, _start, _length, _v) \\
- _$prefix$bt_bitfield_write_be(ptr, type, _start, _length, _v)
+#define $prefix$bt_bitfield_write_be(ptr, type, _start, _length, _vtype, _v) \\
+ _$prefix$bt_bitfield_write_be(ptr, type, _start, _length, _vtype, _v)
#else /* ($PREFIX$BYTE_ORDER == PDP_ENDIAN) */