4 * Integers read/write functions.
6 * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
8 * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
21 #include <babeltrace/ctf-text/types.h>
25 #include <babeltrace/bitfield.h>
27 int ctf_text_integer_write(struct stream_pos
*ppos
, struct definition
*definition
)
29 struct definition_integer
*integer_definition
=
30 container_of(definition
, struct definition_integer
, p
);
31 const struct declaration_integer
*integer_declaration
=
32 integer_definition
->declaration
;
33 struct ctf_text_stream_pos
*pos
= ctf_text_pos(ppos
);
35 if (!print_field(definition
))
41 if (pos
->field_nr
++ != 0)
42 fprintf(pos
->fp
, ",");
43 fprintf(pos
->fp
, " ");
45 fprintf(pos
->fp
, "%s = ",
46 g_quark_to_string(definition
->name
));
49 && (integer_declaration
->encoding
== CTF_STRING_ASCII
50 || integer_declaration
->encoding
== CTF_STRING_UTF8
)) {
52 if (!integer_declaration
->signedness
) {
53 g_string_append_c(pos
->string
,
54 (int) integer_definition
->value
._unsigned
);
56 g_string_append_c(pos
->string
,
57 (int) integer_definition
->value
._signed
);
62 switch (integer_declaration
->base
) {
65 if (!integer_declaration
->signedness
) {
66 fprintf(pos
->fp
, "%" PRIu64
,
67 integer_definition
->value
._unsigned
);
69 fprintf(pos
->fp
, "%" PRId64
,
70 integer_definition
->value
._signed
);
78 if (!integer_declaration
->signedness
)
79 v
= integer_definition
->value
._unsigned
;
81 v
= (uint64_t) integer_definition
->value
._signed
;
83 fprintf(pos
->fp
, "0b");
84 v
= _bt_piecewise_lshift(v
, 64 - integer_declaration
->len
);
85 for (bitnr
= 0; bitnr
< integer_declaration
->len
; bitnr
++) {
86 fprintf(pos
->fp
, "%u", (v
& (1ULL << 63)) ? 1 : 0);
87 v
= _bt_piecewise_lshift(v
, 1);
95 if (!integer_declaration
->signedness
)
96 v
= integer_definition
->value
._unsigned
;
98 v
= (uint64_t) integer_definition
->value
._signed
;
100 fprintf(pos
->fp
, "0%" PRIo64
,
101 integer_definition
->value
._unsigned
);
108 if (!integer_declaration
->signedness
)
109 v
= integer_definition
->value
._unsigned
;
111 v
= (uint64_t) integer_definition
->value
._signed
;
113 fprintf(pos
->fp
, "0x%" PRIX64
,
114 integer_definition
->value
._unsigned
);
This page took 0.03223 seconds and 4 git commands to generate.