.int_read = ctf_int_read,
.uint_write = ctf_uint_write,
.int_write = ctf_int_write,
- .bitfield_unsigned_read = ctf_bitfield_unsigned_read,
- .bitfield_signed_read = ctf_bitfield_signed_read,
- .bitfield_unsigned_write = ctf_bitfield_unsigned_write,
- .bitfield_signed_write = ctf_bitfield_signed_write,
.double_read = ctf_double_read,
.double_write = ctf_double_write,
.float_copy = ctf_float_copy,
+++ /dev/null
-/*
- * Common Trace Format
- *
- * Bitfields read/write functions.
- *
- * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <ctf/bitfield.h>
-#include <endian.h>
-
-uint64_t ctf_bitfield_unsigned_read(struct stream_pos *pos,
- const struct type_class_bitfield *bitfield_class)
-{
- uint64_t v;
-
- align_pos(pos, bitfield_class->p.p.alignment);
- if (bitfield_class->p.byte_order == LITTLE_ENDIAN)
- ctf_bitfield_read_le(pos->base, pos->offset,
- bitfield_class->p.len, &v);
- else
- ctf_bitfield_read_be(pos->base, pos->offset,
- bitfield_class->p.len, &v);
- move_pos(pos, bitfield_class->p.len);
- return v;
-}
-
-int64_t ctf_bitfield_signed_read(struct stream_pos *pos,
- const struct type_class_bitfield *bitfield_class)
-{
- int64_t v;
-
- align_pos(pos, bitfield_class->p.p.alignment);
-
- if (bitfield_class->p.byte_order == LITTLE_ENDIAN)
- ctf_bitfield_read_le(pos->base, pos->offset,
- bitfield_class->p.len, &v);
- else
- ctf_bitfield_read_be(pos->base, pos->offset,
- bitfield_class->p.len, &v);
- move_pos(pos, bitfield_class->p.len);
- return v;
-}
-
-void ctf_bitfield_unsigned_write(struct stream_pos *pos,
- const struct type_class_bitfield *bitfield_class,
- uint64_t v)
-{
- align_pos(pos, bitfield_class->p.p.alignment);
- if (pos->dummy)
- goto end;
- if (bitfield_class->p.byte_order == LITTLE_ENDIAN)
- ctf_bitfield_write_le(pos->base, pos->offset,
- bitfield_class->p.len, v);
- else
- ctf_bitfield_write_be(pos->base, pos->offset,
- bitfield_class->p.len,, v);
-end:
- move_pos(pos, bitfield_class->p.len);
-}
-
-void ctf_bitfield_signed_write(struct stream_pos *pos,
- const struct type_class_bitfield *bitfield_class,
- int64_t v)
-{
- align_pos(pos, bitfield_class->p.p.alignment);
- if (pos->dummy)
- goto end;
- if (bitfield_class->p.byte_order == LITTLE_ENDIAN)
- ctf_bitfield_write_le(pos->base, pos->offset,
- bitfield_class->p.len, v);
- else
- ctf_bitfield_write_be(pos->base, pos->offset,
- bitfield_class->p.len, v);
-end:
- move_pos(pos, bitfield_class->p.len);
-}
GQuark ctf_enum_read(struct stream_pos *pos,
const struct type_class_enum *src)
{
- struct type_class_bitfield *bitfield_class = &src->p;
- struct type_class_integer *int_class = &bitfield_class->p;
+ struct type_class_integer *int_class = &src->p;
if (!int_class->signedness) {
uint64_t v;
- v = ctf_bitfield_unsigned_read(pos, bitfield_class);
+ v = ctf_uint_read(pos, int_class);
return enum_uint_to_quark(src, v);
} else {
int64_t v;
- v = fsrc->bitfield_signed_read(pos, bitfield_class);
+ v = fsrc->ctf_int_read(pos, int_class);
return enum_int_to_quark(src, v);
}
}
const struct type_class_enum *dest,
GQuark q)
{
- struct type_class_bitfield *bitfield_class = &dest->p;
- struct type_class_integer *int_class = &bitfield_class->p;
+ struct type_class_integer *int_class = &dest->p;
if (!int_class->signedness) {
uint64_t v;
v = enum_quark_to_uint(dest, q);
- return ctf_bitfield_unsigned_write(pos, bitfield_class, v);
+ return ctf_uint_write(pos, int_class, v);
} else {
int64_t v;
v = enum_quark_to_int(dest, q);
- return ctf_bitfield_signed_write(pos, bitfield_class, v);
+ return ctf_int_write(pos, int_class, v);
}
}
/* Read */
if (src->byte_order == LITTLE_ENDIAN) {
- mantissa = ctf_bitfield_unsigned_read(srcp,
- src_class->mantissa);
- exp = ctf_bitfield_signed_read(srcp, src_class->exp);
- sign = ctf_bitfield_unsigned_read(srcp, src_class->sign);
+ mantissa = ctf_uint_read(srcp, src_class->mantissa);
+ exp = ctf_int_read(srcp, src_class->exp);
+ sign = ctf_uint_read(srcp, src_class->sign);
} else {
- sign = ctf_bitfield_unsigned_read(srcp, src_class->sign);
- exp = ctf_bitfield_signed_read(srcp, src_class->exp);
- mantissa = ctf_bitfield_unsigned_read(srcp,
- src_class->mantissa);
+ sign = ctf_uint_read(srcp, src_class->sign);
+ exp = ctf_int_read(srcp, src_class->exp);
+ mantissa = ctf_uint_read(srcp, src_class->mantissa);
}
/* Write */
if (dest->byte_order == LITTLE_ENDIAN) {
- ctf_bitfield_unsigned_write(destp, dest_class->mantissa,
- mantissa);
- ctf_bitfield_signed_write(destp, dest_class->exp, exp);
- ctf_bitfield_unsigned_write(destp, dest_class->sign, sign);
+ ctf_uint_write(destp, dest_class->mantissa, mantissa);
+ ctf_int_write(destp, dest_class->exp, exp);
+ ctf_uint_write(destp, dest_class->sign, sign);
} else {
- ctf_bitfield_unsigned_write(destp, dest_class->sign, sign);
- ctf_bitfield_signed_write(destp, dest_class->exp, exp);
- ctf_bitfield_unsigned_write(destp, dest_class->mantissa,
- mantissa);
+ ctf_uint_write(destp, dest_class->sign, sign);
+ ctf_int_write(destp, dest_class->exp, exp);
+ ctf_uint_write(destp, dest_class->mantissa, mantissa);
}
}
*/
#include <ctf/ctf-types.h>
+#include <ctf/bitfield.h>
#include <stdint.h>
#include <glib.h>
#include <endian.h>
-uint64_t ctf_uint_read(struct stream_pos *pos,
+static
+uint64_t _aligned_uint_read(struct stream_pos *pos,
const struct type_class_integer *int_class)
{
int rbo = (int_class->byte_order != BYTE_ORDER); /* reverse byte order */
}
}
-int64_t ctf_int_read(struct stream_pos *pos,
+static
+int64_t _aligned_int_read(struct stream_pos *pos,
const struct type_class_integer *int_class)
{
int rbo = (int_class->byte_order != BYTE_ORDER); /* reverse byte order */
}
}
-void ctf_uint_write(struct stream_pos *pos,
+static
+void _aligned_uint_write(struct stream_pos *pos,
const struct type_class_integer *int_class,
uint64_t v)
{
move_pos(pos, int_class->len);
}
-void ctf_int_write(struct stream_pos *pos,
+static
+void _aligned_int_write(struct stream_pos *pos,
const struct type_class_integer *int_class,
int64_t v)
{
move_pos(pos, int_class->len);
return;
}
+
+uint64_t ctf_uint_read(struct stream_pos *pos,
+ const struct type_class_bitfield *int_class)
+{
+ uint64_t v;
+
+ align_pos(pos, int_class->p.alignment);
+ if (int_class->byte_order == LITTLE_ENDIAN)
+ ctf_bitfield_read_le(pos->base, pos->offset,
+ int_class->len, &v);
+ else
+ ctf_bitfield_read_be(pos->base, pos->offset,
+ int_class->len, &v);
+ move_pos(pos, int_class->len);
+ return v;
+}
+
+int64_t ctf_int_read(struct stream_pos *pos,
+ const struct type_class_bitfield *int_class)
+{
+ int64_t v;
+
+ align_pos(pos, int_class->p.alignment);
+ if (int_class->byte_order == LITTLE_ENDIAN)
+ ctf_bitfield_read_le(pos->base, pos->offset,
+ int_class->len, &v);
+ else
+ ctf_bitfield_read_be(pos->base, pos->offset,
+ int_class->len, &v);
+ move_pos(pos, int_class->len);
+ return v;
+}
+
+void ctf_uint_write(struct stream_pos *pos,
+ const struct type_class_bitfield *int_class,
+ uint64_t v)
+{
+ align_pos(pos, int_class->p.alignment);
+ if (pos->dummy)
+ goto end;
+ if (int_class->byte_order == LITTLE_ENDIAN)
+ ctf_bitfield_write_le(pos->base, pos->offset,
+ int_class->len, v);
+ else
+ ctf_bitfield_write_be(pos->base, pos->offset,
+ int_class->len,, v);
+end:
+ move_pos(pos, int_class->len);
+}
+
+void ctf_int_write(struct stream_pos *pos,
+ const struct type_class_bitfield *int_class,
+ int64_t v)
+{
+ align_pos(pos, int_class->p.alignment);
+ if (pos->dummy)
+ goto end;
+ if (int_class->byte_order == LITTLE_ENDIAN)
+ ctf_bitfield_write_le(pos->base, pos->offset,
+ int_class->len, v);
+ else
+ ctf_bitfield_write_be(pos->base, pos->offset,
+ int_class->len, v);
+end:
+ move_pos(pos, int_class->len);
+}
const struct type_class_integer *int_class,
int64_t v);
-uint64_t ctf_bitfield_unsigned_read(struct stream_pos *pos,
- const struct type_class_bitfield *bitfield_class);
-int64_t ctf_bitfield_signed_read(struct stream_pos *pos,
- const struct type_class_bitfield *bitfield_class);
-void ctf_bitfield_unsigned_write(struct stream_pos *pos,
- const struct type_class_bitfield *bitfield_class,
- uint64_t v);
-void ctf_bitfield_signed_write(struct stream_pos *pos,
- const struct type_class_bitfield *bitfield_class,
- int64_t v);
-
double ctf_double_read(struct stream_pos *pos,
const struct type_class_float *src);
void ctf_double_write(struct stream_pos *pos,
const struct type_class_integer *int_class,
int64_t v);
- uint64_t (*bitfield_unsigned_read)(struct stream_pos *pos,
- const struct type_class_bitfield *bitfield_class);
- int64_t (*bitfield_signed_read)(struct stream_pos *pos,
- const struct type_class_bitfield *bitfield_class);
- void (*bitfield_unsigned_write)(struct stream_pos *pos,
- const struct type_class_bitfield *bitfield_class,
- uint64_t v);
- void (*bitfield_signed_write)(struct stream_pos *pos,
- const struct type_class_bitfield *bitfield_class,
- int64_t v);
-
void (*float_copy)(struct stream_pos *dest,
struct stream_pos *src,
const struct type_class_float *src);
void (*free)(struct type_class *type_class);
};
-struct type_class_integer {
- struct type_class p;
- size_t len; /* length, in bits. */
- int byte_order; /* byte order */
- int signedness;
-};
-
/*
* Because we address in bits, bitfields end up being exactly the same as
* integers, except that their read/write functions must be able to deal with
* read/write non aligned on CHAR_BIT.
*/
-struct type_class_bitfield {
- struct type_class_integer p;
+struct type_class_integer {
+ struct type_class p;
+ size_t len; /* length, in bits. */
+ int byte_order; /* byte order */
+ int signedness;
};
struct type_class_float {
struct type_class p;
- struct bitfield_class *sign;
- struct bitfield_class *mantissa;
- struct bitfield_class *exp;
+ struct int_class *sign;
+ struct int_class *mantissa;
+ struct int_class *exp;
int byte_order;
/* TODO: we might want to express more info about NaN, +inf and -inf */
};
};
struct type_class_enum {
- struct type_class_bitfield p; /* inherit from bitfield */
+ struct type_class_int p; /* inherit from integer */
struct enum_table table;
};
size_t alignment);
void integer_type_free(struct type_class_integer *int_class);
-struct type_class_bitfield *bitfield_type_new(const char *name,
- size_t len, int byte_order,
- int signedness,
- size_t alignment);
-void bitfield_type_free(struct type_class_bitfield *bitfield_class);
-
/*
* mantissa_len is the length of the number of bytes represented by the mantissa
* (e.g. result of DBL_MANT_DIG). It includes the leading 1.
+++ /dev/null
-/*
- * BabelTrace - Bitfield Type Converter
- *
- * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <babeltrace/compiler.h>
-#include <babeltrace/types.h>
-#include <stdint.h>
-
-size_t bitfield_copy(struct stream_pos *dest, const struct format *fdest,
- struct stream_pos *src, const struct format *fsrc,
- const struct type_class *type_class)
-{
- struct type_class_bitfield *bitfield_class =
- container_of(type_class, struct type_class_bitfield, p);
- struct type_class_integer *int_class = &bitfield_class->p;
-
- if (!int_class->signedness) {
- uint64_t v;
-
- v = fsrc->bitfield_unsigned_read(src, bitfield_class);
- return fdest->bitfield_unsigned_write(dest, bitfield_class, v);
- } else {
- int64_t v;
-
- v = fsrc->bitfield_signed_read(src, bitfield_class);
- return fdest->bitfield_signed_write(dest, bitfield_class, v);
- }
-}
-
-void bitfield_type_free(struct type_class_bitfield *bitfield_class)
-{
- g_free(bitfield_class);
-}
-
-static void _bitfield_type_free(struct type_class *type_class)
-{
- struct type_class_bitfield *bitfield_class =
- container_of(type_class, struct type_class_bitfield, p);
- bitfield_type_free(bitfield_class);
-}
-
-struct type_class_bitfield *bitfield_type_new(const char *name,
- size_t len, int byte_order,
- int signedness,
- size_t alignment)
-{
- struct type_class_bitfield *bitfield_class;
- struct type_class_integer *int_class;
- int ret;
-
- bitfield_class = g_new(struct type_class_bitfield, 1);
- int_class = &bitfield_class->p;
- int_class->p.name = g_quark_from_string(name);
- int_class->p.alignment = alignment;
- int_class->p.copy = bitfield_copy;
- int_class->p.free = _bitfield_type_free;
- int_class->len = len;
- int_class->byte_order = byte_order;
- int_class->signedness = signedness;
- if (int_class->p.name) {
- ret = ctf_register_type(&int_class->p);
- if (ret) {
- g_free(bitfield_class);
- return NULL;
- }
- }
- return bitfield_class;
-}
{
struct type_class_enum *enum_class =
container_of(type_class, struct type_class_enum, p);
- struct type_class_bitfield *bitfield_class = &enum_class->p;
- struct type_class_integer *int_class = &bitfield_class->p;
+ struct type_class_integer *int_class = &enum_class->p;
GQuark v;
v = fsrc->enum_read(src, enum_class)
int signedness,
size_t alignment)
{
- struct type_class_bitfield *bitfield_class;
struct type_class_integer *int_class;
int ret;
- enum_class = g_new(struct type_class_bitfield, 1);
+ enum_class = g_new(struct type_class_enum, 1);
enum_class->table.value_to_quark = g_hash_table(enum_val_hash,
enum_val_equal);
enum_class->table.quark_to_value = g_hash_table_new_full(g_direct_hash,
g_direct_equal,
NULL, enum_val_free);
- bitfield_class = &enum_class->p;
- int_class = &bitfield_class->p;
+ int_class = &enum_class->p;
int_class->p.name = g_quark_from_string(name);
int_class->p.alignment = alignment;
int_class->p.copy = enum_copy;
size_t alignment)
{
struct type_class_float *float_class;
- struct type_class_bitfield *bitfield_class;
struct type_class_integer *int_class;
struct type_class *type_class;
int ret;
type_class->free = _float_type_free;
float_class->byte_order = byte_order;
- float_class->sign = bitfield_type_new(NULL, 1,
- byte_order, false, 1);
+ float_class->sign = integer_type_new(NULL, 1,
+ byte_order, false, 1);
if (!float_class->mantissa)
goto error_sign;
- float_class->mantissa = bitfield_type_new(NULL, mantissa_len - 1,
- byte_order, false, 1);
+ float_class->mantissa = integer_type_new(NULL, mantissa_len - 1,
+ byte_order, false, 1);
if (!float_class->mantissa)
goto error_mantissa;
- float_class->exp = bitfield_type_new(NULL, exp_len,
- byte_order, true, 1);
+ float_class->exp = integer_type_new(NULL, exp_len,
+ byte_order, true, 1);
if (!float_class->exp)
goto error_exp;
return float_class;
error_register:
- bitfield_type_free(float_class->exp);
+ integer_type_free(float_class->exp);
error_exp:
- bitfield_type_free(float_class->mantissa);
+ integer_type_free(float_class->mantissa);
error_mantissa:
- bitfield_type_free(float_class->sign);
+ integer_type_free(float_class->sign);
error_sign:
g_free(float_class);
return NULL;