4 * BabelTrace - Float Type Converter
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.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 #include <babeltrace/compiler.h>
30 #include <babeltrace/format.h>
31 #include <babeltrace/types.h>
32 #include <babeltrace/endian.h>
35 struct definition
*_float_definition_new(struct declaration
*declaration
,
36 struct definition_scope
*parent_scope
,
37 GQuark field_name
, int index
,
38 const char *root_name
);
40 void _float_definition_free(struct definition
*definition
);
43 void _float_declaration_free(struct declaration
*declaration
)
45 struct declaration_float
*float_declaration
=
46 container_of(declaration
, struct declaration_float
, p
);
48 bt_declaration_unref(&float_declaration
->exp
->p
);
49 bt_declaration_unref(&float_declaration
->mantissa
->p
);
50 bt_declaration_unref(&float_declaration
->sign
->p
);
51 g_free(float_declaration
);
54 struct declaration_float
*
55 float_declaration_new(size_t mantissa_len
,
56 size_t exp_len
, int byte_order
, size_t alignment
)
58 struct declaration_float
*float_declaration
;
59 struct declaration
*declaration
;
61 float_declaration
= g_new(struct declaration_float
, 1);
62 declaration
= &float_declaration
->p
;
63 declaration
->id
= CTF_TYPE_FLOAT
;
64 declaration
->alignment
= alignment
;
65 declaration
->declaration_free
= _float_declaration_free
;
66 declaration
->definition_new
= _float_definition_new
;
67 declaration
->definition_free
= _float_definition_free
;
69 float_declaration
->byte_order
= byte_order
;
71 float_declaration
->sign
= integer_declaration_new(1,
72 byte_order
, false, 1, 2,
73 CTF_STRING_NONE
, NULL
);
74 float_declaration
->mantissa
= integer_declaration_new(mantissa_len
- 1,
75 byte_order
, false, 1, 10,
76 CTF_STRING_NONE
, NULL
);
77 float_declaration
->exp
= integer_declaration_new(exp_len
,
78 byte_order
, true, 1, 10,
79 CTF_STRING_NONE
, NULL
);
80 return float_declaration
;
85 _float_definition_new(struct declaration
*declaration
,
86 struct definition_scope
*parent_scope
,
87 GQuark field_name
, int index
,
88 const char *root_name
)
90 struct declaration_float
*float_declaration
=
91 container_of(declaration
, struct declaration_float
, p
);
92 struct definition_float
*_float
;
93 struct definition
*tmp
;
95 _float
= g_new(struct definition_float
, 1);
96 bt_declaration_ref(&float_declaration
->p
);
97 _float
->p
.declaration
= declaration
;
98 _float
->declaration
= float_declaration
;
99 _float
->p
.scope
= new_definition_scope(parent_scope
, field_name
, root_name
);
100 _float
->p
.path
= new_definition_path(parent_scope
, field_name
, root_name
);
101 if (float_declaration
->byte_order
== LITTLE_ENDIAN
) {
102 tmp
= float_declaration
->mantissa
->p
.definition_new(&float_declaration
->mantissa
->p
,
103 _float
->p
.scope
, g_quark_from_static_string("mantissa"), 0, NULL
);
104 _float
->mantissa
= container_of(tmp
, struct definition_integer
, p
);
105 tmp
= float_declaration
->exp
->p
.definition_new(&float_declaration
->exp
->p
,
106 _float
->p
.scope
, g_quark_from_static_string("exp"), 1, NULL
);
107 _float
->exp
= container_of(tmp
, struct definition_integer
, p
);
108 tmp
= float_declaration
->sign
->p
.definition_new(&float_declaration
->sign
->p
,
109 _float
->p
.scope
, g_quark_from_static_string("sign"), 2, NULL
);
110 _float
->sign
= container_of(tmp
, struct definition_integer
, p
);
112 tmp
= float_declaration
->sign
->p
.definition_new(&float_declaration
->sign
->p
,
113 _float
->p
.scope
, g_quark_from_static_string("sign"), 0, NULL
);
114 _float
->sign
= container_of(tmp
, struct definition_integer
, p
);
115 tmp
= float_declaration
->exp
->p
.definition_new(&float_declaration
->exp
->p
,
116 _float
->p
.scope
, g_quark_from_static_string("exp"), 1, NULL
);
117 _float
->exp
= container_of(tmp
, struct definition_integer
, p
);
118 tmp
= float_declaration
->mantissa
->p
.definition_new(&float_declaration
->mantissa
->p
,
119 _float
->p
.scope
, g_quark_from_static_string("mantissa"), 2, NULL
);
120 _float
->mantissa
= container_of(tmp
, struct definition_integer
, p
);
124 * Use INT_MAX order to ensure that all fields of the parent
125 * scope are seen as being prior to this scope.
127 _float
->p
.index
= root_name
? INT_MAX
: index
;
128 _float
->p
.name
= field_name
;
133 ret
= register_field_definition(field_name
, &_float
->p
,
141 void _float_definition_free(struct definition
*definition
)
143 struct definition_float
*_float
=
144 container_of(definition
, struct definition_float
, p
);
146 bt_definition_unref(&_float
->sign
->p
);
147 bt_definition_unref(&_float
->exp
->p
);
148 bt_definition_unref(&_float
->mantissa
->p
);
149 free_definition_scope(_float
->p
.scope
);
150 bt_declaration_unref(_float
->p
.declaration
);
This page took 0.031618 seconds and 4 git commands to generate.