a945fd290e73308f2f093819ab44c9b485b7a4d9
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 declaration
*_float_declaration_new(struct type
*type
,
24 struct declaration_scope
*parent_scope
);
26 void _float_declaration_free(struct declaration
*declaration
);
28 void float_copy(struct stream_pos
*destp
,
29 const struct format
*fdest
,
30 struct stream_pos
*srcp
,
31 const struct format
*fsrc
,
32 struct declaration
*declaration
)
34 struct declaration_float
*_float
=
35 container_of(declaration
, struct declaration_float
, p
);
36 struct type_float
*float_type
= _float
->type
;
38 if (fsrc
->float_copy
== fdest
->float_copy
) {
39 fsrc
->float_copy(destp
, srcp
, float_type
);
43 v
= fsrc
->double_read(srcp
, float_type
);
44 fdest
->double_write(destp
, float_type
, v
);
49 void _float_type_free(struct type
*type
)
51 struct type_float
*float_type
=
52 container_of(type
, struct type_float
, p
);
54 type_unref(&float_type
->exp
->p
);
55 type_unref(&float_type
->mantissa
->p
);
56 type_unref(&float_type
->sign
->p
);
61 float_type_new(const char *name
, size_t mantissa_len
,
62 size_t exp_len
, int byte_order
, size_t alignment
)
64 struct type_float
*float_type
;
68 float_type
= g_new(struct type_float
, 1);
69 type
= &float_type
->p
;
70 type
->name
= g_quark_from_string(name
);
71 type
->alignment
= alignment
;
72 type
->copy
= float_copy
;
73 type
->type_free
= _float_type_free
;
74 type
->declaration_new
= _float_declaration_new
;
75 type
->declaration_free
= _float_declaration_free
;
77 float_type
->byte_order
= byte_order
;
79 float_type
->sign
= integer_type_new(NULL
, 1,
80 byte_order
, false, 1);
81 if (!float_type
->mantissa
)
83 float_type
->mantissa
= integer_type_new(NULL
, mantissa_len
- 1,
84 byte_order
, false, 1);
85 if (!float_type
->mantissa
)
87 float_type
->exp
= integer_type_new(NULL
, exp_len
,
92 if (float_type
->p
.name
) {
93 ret
= register_type(&float_type
->p
);
100 type_unref(&float_type
->exp
->p
);
102 type_unref(&float_type
->mantissa
->p
);
104 type_unref(&float_type
->sign
->p
);
112 _float_declaration_new(struct type
*type
,
113 struct declaration_scope
*parent_scope
)
115 struct type_float
*float_type
=
116 container_of(type
, struct type_float
, p
);
117 struct declaration_float
*_float
;
119 _float
= g_new(struct declaration_float
, 1);
120 type_ref(&_float_type
->p
);
121 _float
->p
.type
= _float_type
;
128 void _float_declaration_free(struct declaration
*declaration
)
130 struct declaration_float
*_float
=
131 container_of(declaration
, struct declaration_float
, p
);
133 type_unref(_float
->p
.type
);
This page took 0.031793 seconds and 3 git commands to generate.