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>
24 struct definition
*_float_definition_new(struct declaration
*declaration
,
25 struct definition_scope
*parent_scope
,
26 GQuark field_name
, int index
);
28 void _float_definition_free(struct definition
*definition
);
31 void _float_declaration_free(struct declaration
*declaration
)
33 struct declaration_float
*float_declaration
=
34 container_of(declaration
, struct declaration_float
, p
);
36 declaration_unref(&float_declaration
->exp
->p
);
37 declaration_unref(&float_declaration
->mantissa
->p
);
38 declaration_unref(&float_declaration
->sign
->p
);
39 g_free(float_declaration
);
42 struct declaration_float
*
43 float_declaration_new(size_t mantissa_len
,
44 size_t exp_len
, int byte_order
, size_t alignment
)
46 struct declaration_float
*float_declaration
;
47 struct declaration
*declaration
;
49 float_declaration
= g_new(struct declaration_float
, 1);
50 declaration
= &float_declaration
->p
;
51 declaration
->id
= CTF_TYPE_FLOAT
;
52 declaration
->alignment
= alignment
;
53 declaration
->declaration_free
= _float_declaration_free
;
54 declaration
->definition_new
= _float_definition_new
;
55 declaration
->definition_free
= _float_definition_free
;
57 float_declaration
->byte_order
= byte_order
;
59 float_declaration
->sign
= integer_declaration_new(1,
60 byte_order
, false, 1);
61 float_declaration
->mantissa
= integer_declaration_new(mantissa_len
- 1,
62 byte_order
, false, 1);
63 float_declaration
->exp
= integer_declaration_new(exp_len
,
65 return float_declaration
;
70 _float_definition_new(struct declaration
*declaration
,
71 struct definition_scope
*parent_scope
,
72 GQuark field_name
, int index
)
74 struct declaration_float
*float_declaration
=
75 container_of(declaration
, struct declaration_float
, p
);
76 struct definition_float
*_float
;
77 struct definition
*tmp
;
79 _float
= g_new(struct definition_float
, 1);
80 declaration_ref(&float_declaration
->p
);
81 _float
->p
.declaration
= declaration
;
82 _float
->declaration
= float_declaration
;
83 if (float_declaration
->byte_order
== LITTLE_ENDIAN
) {
84 tmp
= float_declaration
->mantissa
->p
.definition_new(&float_declaration
->mantissa
->p
,
85 parent_scope
, g_quark_from_static_string("mantissa"), 0);
86 _float
->mantissa
= container_of(tmp
, struct definition_integer
, p
);
87 tmp
= float_declaration
->exp
->p
.definition_new(&float_declaration
->exp
->p
,
88 parent_scope
, g_quark_from_static_string("exp"), 1);
89 _float
->exp
= container_of(tmp
, struct definition_integer
, p
);
90 tmp
= float_declaration
->sign
->p
.definition_new(&float_declaration
->sign
->p
,
91 parent_scope
, g_quark_from_static_string("sign"), 2);
92 _float
->sign
= container_of(tmp
, struct definition_integer
, p
);
94 tmp
= float_declaration
->sign
->p
.definition_new(&float_declaration
->sign
->p
,
95 parent_scope
, g_quark_from_static_string("sign"), 0);
96 _float
->sign
= container_of(tmp
, struct definition_integer
, p
);
97 tmp
= float_declaration
->exp
->p
.definition_new(&float_declaration
->exp
->p
,
98 parent_scope
, g_quark_from_static_string("exp"), 1);
99 _float
->exp
= container_of(tmp
, struct definition_integer
, p
);
100 tmp
= float_declaration
->mantissa
->p
.definition_new(&float_declaration
->mantissa
->p
,
101 parent_scope
, g_quark_from_static_string("mantissa"), 2);
102 _float
->mantissa
= container_of(tmp
, struct definition_integer
, p
);
105 _float
->p
.index
= index
;
106 _float
->p
.name
= field_name
;
107 _float
->p
.path
= new_definition_path(parent_scope
, field_name
);
113 void _float_definition_free(struct definition
*definition
)
115 struct definition_float
*_float
=
116 container_of(definition
, struct definition_float
, p
);
118 definition_unref(&_float
->sign
->p
);
119 definition_unref(&_float
->exp
->p
);
120 definition_unref(&_float
->mantissa
->p
);
121 declaration_unref(_float
->p
.declaration
);
This page took 0.031647 seconds and 4 git commands to generate.