From ac274d08df99de9ec43e8672b094afdc88e9a61f Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Tue, 8 Sep 2020 12:37:28 -0400 Subject: [PATCH] bitfield.h.j2: keep a single version for the target byte order Because all bit array fields use the target byte order since 4c91e76 ("config.py: remove bit array field type's byte order property"), we don't need both little-endian and big-endian versions of the `bitfield.h` macros. Signed-off-by: Philippe Proulx --- barectf/templates/c/bitfield.h.j2 | 24 +++++++++---------- .../c/serialize-write-bit-array-statements.j2 | 5 ++-- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/barectf/templates/c/bitfield.h.j2 b/barectf/templates/c/bitfield.h.j2 index 0ec0784..05d507b 100644 --- a/barectf/templates/c/bitfield.h.j2 +++ b/barectf/templates/c/bitfield.h.j2 @@ -27,6 +27,8 @@ #ifndef _{{ ucprefix }}BITFIELD_H #define _{{ ucprefix }}BITFIELD_H +#include + /* * BabelTrace * @@ -96,6 +98,9 @@ do { \ * Also, consecutive bitfields are placed from higher to lower bits. */ +{% if cfg.target_byte_order == barectf_config.ByteOrder.LITTLE_ENDIAN %} +/* Target byte order: little-endian */ + #define _bt_bitfield_write_le(_ptr, type, _start, _length, _vtype, _v) \ do { \ _vtype __v = (_v); \ @@ -155,6 +160,11 @@ do { \ __ptr[this_unit] = (type) __v; \ } while (0) +#define bt_bitfield_write_le(ptr, _start, _length, _vtype, _v) \ + _bt_bitfield_write_le(ptr, uint8_t, _start, _length, _vtype, _v) +{% else %} +/* Target byte order: big-endian */ + #define _bt_bitfield_write_be(_ptr, type, _start, _length, _vtype, _v) \ do { \ _vtype __v = (_v); \ @@ -214,18 +224,8 @@ do { \ __ptr[this_unit] = (type) __v; \ } while (0) -{% if cfg.target_byte_order == barectf_config.ByteOrder.LITTLE_ENDIAN %} -/* Target byte order: little-endian */ -#define bt_bitfield_write_le(ptr, type, _start, _length, _vtype, _v) \ - _bt_bitfield_write_le(ptr, type, _start, _length, _vtype, _v) -#define bt_bitfield_write_be(ptr, type, _start, _length, _vtype, _v) \ - _bt_bitfield_write_be(ptr, unsigned char, _start, _length, _vtype, _v) -{% else %} -/* Target byte order: big-endian */ -#define bt_bitfield_write_le(ptr, type, _start, _length, _vtype, _v) \ - _bt_bitfield_write_le(ptr, unsigned char, _start, _length, _vtype, _v) -#define bt_bitfield_write_be(ptr, type, _start, _length, _vtype, _v) \ - _bt_bitfield_write_be(ptr, type, _start, _length, _vtype, _v) +#define bt_bitfield_write_be(ptr, _start, _length, _vtype, _v) \ + _bt_bitfield_write_be(ptr, uint8_t, _start, _length, _vtype, _v) {% endif %} #endif /* _{{ ucprefix }}BITFIELD_H */ diff --git a/barectf/templates/c/serialize-write-bit-array-statements.j2 b/barectf/templates/c/serialize-write-bit-array-statements.j2 index a822c28..091d7f7 100644 --- a/barectf/templates/c/serialize-write-bit-array-statements.j2 +++ b/barectf/templates/c/serialize-write-bit-array-statements.j2 @@ -25,7 +25,6 @@ {% import 'common.j2' as common %} {% set bo = 'le' if cfg.target_byte_order == barectf_config.ByteOrder.LITTLE_ENDIAN else 'be' %} {% set c_type_non_const = c_type | replace('const ', '') %} -bt_bitfield_write_{{ bo }}(&ctx->buf[_BITS_TO_BYTES(ctx->at)], - uint8_t, {{ op.offset_in_byte }}, {{ op.ft.size }}, {{ c_type_non_const }}, - ({{ c_type_non_const }}) {{ src }}); +bt_bitfield_write_{{ bo }}(&ctx->buf[_BITS_TO_BYTES(ctx->at)], {{ op.offset_in_byte }}, {{ op.ft.size }}, + {{ c_type_non_const }}, ({{ c_type_non_const }}) {{ src }}); ctx->at += {{ op.ft.size }}; -- 2.34.1