bitfield.h.j2: keep a single version for the target byte order
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 8 Sep 2020 16:37:28 +0000 (12:37 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 8 Sep 2020 16:37:28 +0000 (12:37 -0400)
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 <eeppeliteloop@gmail.com>
barectf/templates/c/bitfield.h.j2
barectf/templates/c/serialize-write-bit-array-statements.j2

index 0ec078405852346a526c6275e0c927697267a7ee..05d507ba3bb140a3b373b0a4599e53e2a484ac7f 100644 (file)
@@ -27,6 +27,8 @@
 #ifndef _{{ ucprefix }}BITFIELD_H
 #define _{{ ucprefix }}BITFIELD_H
 
+#include <stdint.h>
+
 /*
  * 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 */
index a822c28ad2903832df799cc4c7ea8aa984fcb229..091d7f737810f5a6f90c23141c01f51e06006a28 100644 (file)
@@ -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 }};
This page took 0.024031 seconds and 4 git commands to generate.