c78cf584feb4f07f9100ed5f8902a046f1027e01
4 * BabelTrace - Float Type Converter
6 * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
19 #include <babeltrace/compiler.h>
20 #include <babeltrace/format.h>
23 struct type_float
*_float_type_new(struct type_class
*type_class
,
24 struct declaration_scope
*parent_scope
);
26 void _float_type_free(struct type
*type
);
28 void float_copy(struct stream_pos
*destp
,
29 const struct format
*fdest
,
30 struct stream_pos
*srcp
,
31 const struct format
*fsrc
,
34 struct type_float
*_float
= container_of(type
, struct type_float
, p
);
35 struct type_class_float
*float_class
= _float
->_class
;
37 if (fsrc
->float_copy
== fdest
->float_copy
) {
38 fsrc
->float_copy(destp
, srcp
, float_class
);
42 v
= fsrc
->double_read(srcp
, float_class
);
43 fdest
->double_write(destp
, float_class
, v
);
48 void _float_type_class_free(struct type_class
*type_class
)
50 struct type_class_float
*float_class
=
51 container_of(type_class
, struct type_class_float
, p
);
53 type_class_unref(&float_class
->exp
->p
);
54 type_class_unref(&float_class
->mantissa
->p
);
55 type_class_unref(&float_class
->sign
->p
);
59 struct type_class_float
*
60 float_type_class_new(const char *name
, size_t mantissa_len
,
61 size_t exp_len
, int byte_order
, size_t alignment
)
63 struct type_class_float
*float_class
;
64 struct type_class
*type_class
;
67 float_class
= g_new(struct type_class_float
, 1);
68 type_class
= &float_class
->p
;
69 type_class
->name
= g_quark_from_string(name
);
70 type_class
->alignment
= alignment
;
71 type_class
->copy
= float_copy
;
72 type_class
->class_free
= _float_type_class_free
;
73 type_class
->type_new
= _float_type_new
;
74 type_class
->type_free
= _float_type_free
;
76 float_class
->byte_order
= byte_order
;
78 float_class
->sign
= integer_type_new(NULL
, 1,
79 byte_order
, false, 1);
80 if (!float_class
->mantissa
)
82 float_class
->mantissa
= integer_type_new(NULL
, mantissa_len
- 1,
83 byte_order
, false, 1);
84 if (!float_class
->mantissa
)
86 float_class
->exp
= integer_type_new(NULL
, exp_len
,
88 if (!float_class
->exp
)
91 if (float_class
->p
.name
) {
92 ret
= register_type(&float_class
->p
);
99 type_class_unref(&float_class
->exp
->p
);
101 type_class_unref(&float_class
->mantissa
->p
);
103 type_class_unref(&float_class
->sign
->p
);
110 struct type_float
*_float_type_new(struct type_class
*type_class
,
111 struct declaration_scope
*parent_scope
)
113 struct type_class_float
*float_class
=
114 container_of(type_class
, struct type_class_float
, p
);
115 struct type_float
*_float
;
117 _float
= g_new(struct type_float
, 1);
118 type_class_ref(&_float_class
->p
);
119 _float
->p
._class
= _float_class
;
126 void _float_type_free(struct type
*type
)
128 struct type_float
*_float
= container_of(type
, struct type_float
, p
);
130 type_class_unref(_float
->p
._class
);
This page took 0.035647 seconds and 4 git commands to generate.