+#endif //0
+
+
+/*****************************************************************************
+ *Function name
+ * get_alignment : Get the alignment needed for a field.
+ *Input params
+ * field : field
+ *
+ * returns : The size on which it must be aligned.
+ *
+ ****************************************************************************/
+#if 0
+off_t get_alignment(LttField *field)
+{
+ LttType *type = &field->field_type;
+
+ switch(type->type_class) {
+ case LTT_INT_FIXED:
+ case LTT_UINT_FIXED:
+ case LTT_POINTER:
+ case LTT_CHAR:
+ case LTT_UCHAR:
+ case LTT_SHORT:
+ case LTT_USHORT:
+ case LTT_INT:
+ case LTT_UINT:
+ case LTT_LONG:
+ case LTT_ULONG:
+ case LTT_SIZE_T:
+ case LTT_SSIZE_T:
+ case LTT_OFF_T:
+ case LTT_FLOAT:
+ case LTT_ENUM:
+ /* Align offset on type size */
+ g_assert(field->field_size != 0);
+ return field->field_size;
+ break;
+ case LTT_STRING:
+ return 1;
+ break;
+ case LTT_ARRAY:
+ g_assert(type->fields->len == 1);
+ {
+ LttField *child = &g_array_index(type->fields, LttField, 0);
+ return get_alignment(child);
+ }
+ break;
+ case LTT_SEQUENCE:
+ g_assert(type->fields->len == 2);
+ {
+ off_t localign = 1;
+ LttField *child = &g_array_index(type->fields, LttField, 0);
+
+ localign = max(localign, get_alignment(child));
+
+ child = &g_array_index(type->fields, LttField, 1);
+ localign = max(localign, get_alignment(child));
+
+ return localign;
+ }
+ break;
+ case LTT_STRUCT:
+ case LTT_UNION:
+ {
+ guint i;
+ off_t localign = 1;
+
+ for(i=0; i<type->fields->len; i++) {
+ LttField *child = &g_array_index(type->fields, LttField, i);
+ localign = max(localign, get_alignment(child));
+ }
+ return localign;
+ }
+ break;
+ case LTT_NONE:
+ default:
+ g_error("get_alignment : unknown type");
+ return -1;
+ }
+}
+
+#endif //0
+
+/*****************************************************************************
+ *Function name
+ * field_compute_static_size : Determine the size of fields known by their
+ * sole definition. Unions, arrays and struct sizes might be known, but
+ * the parser does not give that information.
+ *Input params
+ * tf : tracefile
+ * field : field
+ *
+ ****************************************************************************/
+#if 0
+void field_compute_static_size(LttFacility *fac, LttField *field)
+{
+ LttType *type = &field->field_type;
+
+ switch(type->type_class) {
+ case LTT_INT_FIXED:
+ case LTT_UINT_FIXED:
+ case LTT_POINTER:
+ case LTT_CHAR:
+ case LTT_UCHAR:
+ case LTT_SHORT:
+ case LTT_USHORT:
+ case LTT_INT:
+ case LTT_UINT:
+ case LTT_LONG:
+ case LTT_ULONG:
+ case LTT_SIZE_T:
+ case LTT_SSIZE_T:
+ case LTT_OFF_T:
+ case LTT_FLOAT:
+ case LTT_ENUM:
+ case LTT_STRING:
+ /* nothing to do */
+ break;
+ case LTT_ARRAY:
+ /* note this : array type size is the number of elements in the array,
+ * while array field size of the length of the array in bytes */
+ g_assert(type->fields->len == 1);
+ {
+ LttField *child = &g_array_index(type->fields, LttField, 0);
+ field_compute_static_size(fac, child);
+
+ if(child->field_size != 0) {
+ field->field_size = type->size * child->field_size;
+ field->dynamic_offsets = g_array_sized_new(FALSE, TRUE,
+ sizeof(off_t), type->size);
+ } else {
+ field->field_size = 0;
+ }
+ }
+ break;
+ case LTT_SEQUENCE:
+ g_assert(type->fields->len == 2);
+ {
+ off_t local_offset = 0;
+ LttField *child = &g_array_index(type->fields, LttField, 1);
+ field_compute_static_size(fac, child);
+ field->field_size = 0;
+ type->size = 0;
+ if(child->field_size != 0) {
+ field->dynamic_offsets = g_array_sized_new(FALSE, TRUE,
+ sizeof(off_t), SEQUENCE_AVG_ELEMENTS);
+ }
+ }
+ break;
+ case LTT_STRUCT:
+ case LTT_UNION:
+ {
+ guint i;
+ for(i=0;i<type->fields->len;i++) {
+ LttField *child = &g_array_index(type->fields, LttField, i);
+ field_compute_static_size(fac, child);
+ if(child->field_size != 0) {
+ type->size += ltt_align(type->size, get_alignment(child),
+ fac->alignment);
+ type->size += child->field_size;
+ } else {
+ /* As soon as we find a child with variable size, we have
+ * a variable size */
+ type->size = 0;
+ break;
+ }
+ }
+ field->field_size = type->size;
+ }
+ break;
+ default:
+ g_error("field_static_size : unknown type");
+ }
+
+}
+#endif //0
+
+
+/*****************************************************************************
+ *Function name
+ * precompute_fields_offsets : set the precomputable offset of the fields
+ *Input params
+ * fac : facility
+ * field : the field
+ * offset : pointer to the current offset, must be incremented
+ *
+ * return : 1 : found a variable length field, stop the processing.
+ * 0 otherwise.
+ ****************************************************************************/
+
+#if 0
+gint precompute_fields_offsets(LttFacility *fac, LttField *field, off_t *offset, gint is_compact)
+{
+ LttType *type = &field->field_type;
+
+ if(unlikely(is_compact)) {
+ g_assert(field->field_size != 0);
+ /* FIXME THIS IS A HUUUUUGE hack :
+ * offset is between the compact_data field in struct LttEvent
+ * and the address of the field root in the memory map.
+ * ark. Both will stay at the same addresses while the event
+ * is readable, so it's ok.
+ */
+ field->offset_root = 0;
+ field->fixed_root = FIELD_FIXED;
+ return 0;
+ }
+
+ switch(type->type_class) {
+ case LTT_INT_FIXED:
+ case LTT_UINT_FIXED:
+ case LTT_POINTER:
+ case LTT_CHAR:
+ case LTT_UCHAR:
+ case LTT_SHORT:
+ case LTT_USHORT:
+ case LTT_INT:
+ case LTT_UINT:
+ case LTT_LONG:
+ case LTT_ULONG:
+ case LTT_SIZE_T:
+ case LTT_SSIZE_T:
+ case LTT_OFF_T:
+ case LTT_FLOAT:
+ case LTT_ENUM:
+ g_assert(field->field_size != 0);
+ /* Align offset on type size */
+ *offset += ltt_align(*offset, get_alignment(field),
+ fac->alignment);
+ /* remember offset */
+ field->offset_root = *offset;
+ field->fixed_root = FIELD_FIXED;
+ /* Increment offset */
+ *offset += field->field_size;
+ return 0;
+ break;
+ case LTT_STRING:
+ field->offset_root = *offset;
+ field->fixed_root = FIELD_FIXED;
+ return 1;
+ break;
+ case LTT_ARRAY:
+ g_assert(type->fields->len == 1);
+ {
+ LttField *child = &g_array_index(type->fields, LttField, 0);
+
+ *offset += ltt_align(*offset, get_alignment(field),
+ fac->alignment);
+
+ /* remember offset */
+ field->offset_root = *offset;
+ field->array_offset = *offset;
+ field->fixed_root = FIELD_FIXED;
+
+ /* Let the child be variable */
+ //precompute_fields_offsets(tf, child, offset);
+
+ if(field->field_size != 0) {
+ /* Increment offset */
+ /* field_size is the array size in bytes */
+ *offset += field->field_size;
+ return 0;
+ } else {
+ return 1;
+ }
+ }
+ break;
+ case LTT_SEQUENCE:
+ g_assert(type->fields->len == 2);
+ {
+ LttField *child;
+ guint ret;
+
+ *offset += ltt_align(*offset, get_alignment(field),
+ fac->alignment);
+
+ /* remember offset */
+ field->offset_root = *offset;
+ field->fixed_root = FIELD_FIXED;
+
+ child = &g_array_index(type->fields, LttField, 0);
+ ret = precompute_fields_offsets(fac, child, offset, is_compact);
+ g_assert(ret == 0); /* Seq len cannot have variable len */
+
+ child = &g_array_index(type->fields, LttField, 1);
+ *offset += ltt_align(*offset, get_alignment(child),
+ fac->alignment);
+ field->array_offset = *offset;
+ /* Let the child be variable. */
+ //ret = precompute_fields_offsets(fac, child, offset);
+
+ /* Cannot precompute fields offsets of sequence members, and has
+ * variable length. */
+ return 1;
+ }
+ break;
+ case LTT_STRUCT:
+ {
+ LttField *child;
+ guint i;
+ gint ret=0;
+
+ *offset += ltt_align(*offset, get_alignment(field),
+ fac->alignment);
+ /* remember offset */
+ field->offset_root = *offset;
+ field->fixed_root = FIELD_FIXED;
+
+ for(i=0; i< type->fields->len; i++) {
+ child = &g_array_index(type->fields, LttField, i);
+ ret = precompute_fields_offsets(fac, child, offset, is_compact);
+
+ if(ret) break;
+ }
+ return ret;
+ }
+ break;
+ case LTT_UNION:
+ {
+ LttField *child;
+ guint i;
+ gint ret=0;
+
+ *offset += ltt_align(*offset, get_alignment(field),
+ fac->alignment);
+ /* remember offset */
+ field->offset_root = *offset;
+ field->fixed_root = FIELD_FIXED;
+
+ for(i=0; i< type->fields->len; i++) {
+ *offset = field->offset_root;
+ child = &g_array_index(type->fields, LttField, i);
+ ret = precompute_fields_offsets(fac, child, offset, is_compact);
+
+ if(ret) break;
+ }
+ *offset = field->offset_root + field->field_size;
+ return ret;
+ }
+
+ break;
+ case LTT_NONE:
+ default:
+ g_error("precompute_fields_offsets : unknown type");
+ return 1;
+ }
+
+}
+
+#endif //0
+
+#if 0
+/*****************************************************************************
+ *Function name
+ * precompute_offsets : set the precomputable offset of an event type
+ *Input params
+ * tf : tracefile
+ * event : event type
+ *
+ ****************************************************************************/
+void precompute_offsets(LttFacility *fac, LttEventType *event)
+{
+ guint i;
+ off_t offset = 0;
+ gint ret;
+
+ /* First, compute the size of fixed size fields. Will determine size for
+ * arrays, struct and unions, which is not done by the parser */
+ for(i=0; i<event->fields->len; i++) {
+ LttField *field = &g_array_index(event->fields, LttField, i);
+ field_compute_static_size(fac, field);
+ }
+
+ /* Precompute all known offsets */
+ for(i=0; i<event->fields->len; i++) {
+ LttField *field = &g_array_index(event->fields, LttField, i);
+ if(event->has_compact_data && i == 0)
+ ret = precompute_fields_offsets(fac, field, &offset, 1);
+ else
+ ret = precompute_fields_offsets(fac, field, &offset, 0);
+ if(ret) break;
+ }
+}
+#endif //0
+