summaryrefslogtreecommitdiff
path: root/src/format/mangling/itanium/component.h
blob: cc00d4786dfed18ee2619d5db5addd1234754339 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213

/* Chrysalide - Outil d'analyse de fichiers binaires
 * component.h - prototypes pour la représentation des composants extraits de l'ABI C++ Itanium
 *
 * Copyright (C) 2013-2017 Cyrille Bagard
 *
 *  This file is part of Chrysalide.
 *
 *  Chrysalide is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Chrysalide is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */


#ifndef _FORMAT_MANGLING_ITANIUM_COMPONENT_H
#define _FORMAT_MANGLING_ITANIUM_COMPONENT_H


#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <sys/types.h>


#include "context.h"
#include "../../../analysis/type.h"
#include "../../../common/fnv1a.h"



/* Type de composants */
typedef enum _ItaniumComponentType
{
    /**
     * Représentation d'une règle vide.
     */
    ICT_EMPTY,

    /**
     * Chaîne de caractère, terminée par un octet nul.
     */
    ICT_NAME,
    ICT_STD_SUBST,

    /**
     * Noms imbriqués, en deux parties : 'binary'.
     */
    ICT_NESTED_NAME,
    ICT_TEMPLATE_NAME_ARGS,

    /**
     * Deux types de préfixes : un ou deux éléments.
     *  -> 'unary' ou 'binary'
     */
    ICT_PREFIX_UNARY,
    ICT_PREFIX_BINARY,
    ICT_TPREFIX_UNARY,
    ICT_TPREFIX_BINARY,

    /**
     * Encodage d'un nom d'opérateur, consigné dans 'operator'.
     */
    ICT_OPERATOR_NAME,


    /**
     * Fonctions virtuelles.
     *  -> décallage : 'offset'.
     *  -> fonctions simples : 'binary'.
     *  -> fonctions complexes : 'ternary'.
     */
    ICT_NON_VIRTUAL_OFFSET,
    ICT_VIRTUAL_OFFSET,
    ICT_FUNCTION_THUNK,
    ICT_FUNCTION_COVARIANT_THUNK,

    /**
     * Constructeur ou destructeur, sans plus de détail.
     */
    ICT_CONSTRUCTOR,
    ICT_DESSTRUCTOR,

    /**
     * Type instanciable dans le programme.
     */
    ICT_TYPE,

    /**
     * Différentes références vers un sous-type.
     * Le champ impacté est 'unary'.
     */
    ICT_POINTER_TO,
    ICT_REFERENCE_TO,
    ICT_RVALUE_REFERENCE_TO,
    ICT_COMPLEX_PAIR,
    ICT_IMAGINARY,

    /**
     * Fonction (nom + retour/paramètres), sous forme binaire :
     *  -> left = function name
     *  -> right = bare-function-type
     */
    ICT_FUNCTION_ENCODING,

    /**
     * Liste d'arguments pour templates, à encadrer par des chevrons.
     * 'unary' pointe vers la liste des éléments.
     */
    ICT_TEMPLATE_ARGS,

    /**
     * Liste de types, sous forme binaire :
     *  -> left = élément de la liste de types.
     *  -> right = reste de la liste de types.
     */
    ICT_TYPES_LIST,

    ICT_COUNT

} ItaniumComponentType;


/* Catégories d'opérateurs */
typedef enum _ItaniumOperatorType
{
    IOT_SIMPLE,                             /* Présent dans la liste       */
    IOT_CAST,                               /* Conversion forcée           */
    IOT_VENDOR                              /* Défini par un vendeur       */

} ItaniumOperatorType;


/* Enregistrement des opérateurs */
typedef struct _itanium_operator_info
{
    const char *code;                       /* Nom encodé                  */
    const char *name;                       /* Désignation humaine         */
    size_t name_len;                        /* Taille du nom humain        */
    int args;                               /* Nombre d'arguments          */

} itanium_operator_info;


/* Composant extrait de l'encodage */
typedef struct _itanium_component itanium_component;



/* Incrémente le nombre d'utilisation du composant. */
void itd_ref_comp(itanium_component *);

/* Décrémente le nombre d'utilisation du composant. */
void itd_unref_comp(itanium_component *);

/* Détermine ou fournit l'empreinte d'un composant. */
fnv64_t itd_hash_comp(itanium_component *);



/* Marque un composant comme étant disponible pour un usage. */
void itd_free_comp(GItaniumDContext *, itanium_component *);

/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_empty(GItaniumDContext *);

/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_name(GItaniumDContext *, const char *, size_t);


/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_operator(GItaniumDContext *, const itanium_operator_info *);


/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_offset(GItaniumDContext *, ItaniumComponentType, ssize_t);


/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_type(GItaniumDContext *, GDataType *);

/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_binary(GItaniumDContext *, ItaniumComponentType, itanium_component *, itanium_component *);

/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_append_right_to_binary(GItaniumDContext *, ItaniumComponentType, itanium_component *, itanium_component *);

/* Construit un composant dans un contexte Itanium. */
itanium_component *itd_make_unary(GItaniumDContext *, ItaniumComponentType, itanium_component *);



/* Modifie légèrement le type d'un composant donné. */
void itd_set_type(itanium_component *, ItaniumComponentType);

/* Fournit le type d'un composant issu d'un contexte Itanium. */
ItaniumComponentType itd_get_component_type(const itanium_component *);

/* Traduit les composants de contexte Itanium. */
char *itd_translate_component(GItaniumDContext *, const itanium_component *, char *);



#endif  /* _FORMAT_MANGLING_ITANIUM_COMPONENT_H */