Integer base update
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 14 May 2011 00:29:35 +0000 (20:29 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 14 May 2011 00:29:35 +0000 (20:29 -0400)
- Test and fix base2 binary formatting.
- Use base16 (hex) printout for pointers if the integer does not specify
  any specific base.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf-text/types/integer.c
formats/ctf/metadata/ctf-visitor-generate-io-struct.c
tests/ctf-traces/fail/fail1/metadata

index a01284583f6ecdd64e83cc2a9d34c31b00bc0a8f..34a899ddd0e901dab98141133f71c1c2526e92c2 100644 (file)
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <inttypes.h>
 #include <stdint.h>
+#include <babeltrace/bitfield.h>
 
 int ctf_text_integer_write(struct stream_pos *ppos, struct definition *definition)
 {
@@ -40,37 +41,60 @@ int ctf_text_integer_write(struct stream_pos *ppos, struct definition *definitio
                        g_quark_to_string(definition->name));
 
        switch (integer_declaration->base) {
+       case 0: /* default */
+       case 10:
+               if (!integer_declaration->signedness) {
+                       fprintf(pos->fp, "%" PRIu64,
+                               integer_definition->value._unsigned);
+               } else {
+                       fprintf(pos->fp, "%" PRId64,
+                               integer_definition->value._signed);
+               }
+               break;
        case 2:
        {
                int bitnr;
-               uint64_t v = integer_definition->value._unsigned;
+               uint64_t v;
+
+               if (!integer_declaration->signedness)
+                       v = integer_definition->value._unsigned;
+               else
+                       v = (uint64_t) integer_definition->value._signed;
 
                fprintf(pos->fp, "b");
-               for (bitnr = 0; bitnr < integer_declaration->len; bitnr++)
-                       v <<= 1;
-               for (; bitnr < sizeof(v) * CHAR_BIT; bitnr++) {
-                       fprintf(pos->fp, "%u", ((v & 1ULL) << 63) ? 1 : 0);
-                       v <<= 1;
+               v = _bt_piecewise_lshift(v, 64 - integer_declaration->len);
+               for (bitnr = 0; bitnr < integer_declaration->len; bitnr++) {
+                       fprintf(pos->fp, "%u", (v & (1ULL << 63)) ? 1 : 0);
+                       v = _bt_piecewise_lshift(v, 1);
                }
                break;
        }
        case 8:
+       {
+               uint64_t v;
+
+               if (!integer_declaration->signedness)
+                       v = integer_definition->value._unsigned;
+               else
+                       v = (uint64_t) integer_definition->value._signed;
+
                fprintf(pos->fp, "0%" PRIo64,
                        integer_definition->value._unsigned);
                break;
-       case 10:
-               if (!integer_declaration->signedness) {
-                       fprintf(pos->fp, "%" PRIu64,
-                               integer_definition->value._unsigned);
-               } else {
-                       fprintf(pos->fp, "%" PRId64,
-                               integer_definition->value._signed);
-               }
-               break;
+       }
        case 16:
+       {
+               uint64_t v;
+
+               if (!integer_declaration->signedness)
+                       v = integer_definition->value._unsigned;
+               else
+                       v = (uint64_t) integer_definition->value._signed;
+
                fprintf(pos->fp, "0x%" PRIX64,
                        integer_definition->value._unsigned);
                break;
+       }
        default:
                return -EINVAL;
        }
index de760ca019f1e863f9f26e49989fd172c4e8bc47..7688f5f1f3cd27470420770139b58b7c9d0fdc3f 100644 (file)
@@ -313,6 +313,13 @@ struct declaration *ctf_type_declarator_visit(FILE *fd, int depth,
                                fprintf(fd, "[error] %s: cannot find typealias \"%s\".\n", __func__, g_quark_to_string(alias_q));
                                return NULL;
                        }
+                       if (nested_declaration->id == CTF_TYPE_INTEGER) {
+                               struct declaration_integer *integer_declaration =
+                                       container_of(nested_declaration, struct declaration_integer, p);
+                               /* For base to 16 for pointers (expected pretty-print) */
+                               if (!integer_declaration->base)
+                                       integer_declaration->base = 16;
+                       }
                } else {
                        nested_declaration = ctf_type_specifier_list_visit(fd, depth,
                                type_specifier_list, declaration_scope, trace);
@@ -1069,7 +1076,7 @@ struct declaration *ctf_declaration_integer_visit(FILE *fd, int depth,
        int byte_order = trace->byte_order;
        int signedness = 0;
        int has_alignment = 0, has_size = 0;
-       int base = 10;
+       int base = 0;
        struct declaration_integer *integer_declaration;
 
        cds_list_for_each_entry(expression, expressions, siblings) {
index ffdf52c5e9f757d3fde1f2e27feb74d949c98169..8cd8e416c37b33a94ac2fd7b52faedbe54b49be3 100644 (file)
@@ -5,7 +5,7 @@ typealias integer { size = 8; align = 8; signed = false; } := uint8_t;
 typealias integer { size = 63; align = 1; signed = false; } := timestamp_t;
 
 typealias integer { size = 32; align = 32; signed = false; base = 10; } := uint32_t;
-typealias integer { size = 32; align = 32; signed = false; base = hex; } := void *;
+typealias integer { size = 32; align = 32; signed = false; } := void *;
 
 
 trace {
This page took 0.037249 seconds and 4 git commands to generate.