2 /*--------------------------------------------------------------------*/
3 /*--- Representation of source level types. priv_tytypes.h ---*/
4 /*--------------------------------------------------------------------*/
7 This file is part of Valgrind, a dynamic binary instrumentation
10 Copyright (C) 2008-2017 OpenWorks LLP
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <http://www.gnu.org/licenses/>.
26 The GNU General Public License is contained in the file COPYING.
28 Neither the names of the U.S. Department of Energy nor the
29 University of California nor the names of its contributors may be
30 used to endorse or promote products derived from this software
31 without prior written permission.
34 #ifndef __PRIV_TYTYPES_H
35 #define __PRIV_TYTYPES_H
37 #include "pub_core_basics.h" // UWord
38 #include "pub_core_xarray.h" // XArray
39 #include "priv_misc.h" // MaybeULong
43 Te_EMPTY
=10, /* empty (contains no info) */
44 Te_INDIR
, /* indirection to some other TyEnt */
45 Te_UNKNOWN
, /* denotes a unknown type/field/whatever */
46 Te_Atom
, /* name & 64-bit const, iow, enumeration member */
47 Te_Field
, /* struct/class field defn */
48 Te_Bound
, /* array bounds indication, for one dimension */
49 Te_TyBase
, /* base type */
50 Te_TyPtr
, /* pointer type */
51 Te_TyRef
, /* reference type */
52 Te_TyPtrMbr
, /* pointer to member type */
53 Te_TyRvalRef
,/* rvalue reference type */
54 Te_TyTyDef
, /* a renaming of some other type */
55 Te_TyStOrUn
, /* structure or union type */
56 Te_TyEnum
, /* an enum type */
57 Te_TyArray
, /* an array type */
58 Te_TyFn
, /* function type */
59 Te_TyQual
, /* qualified type */
60 Te_TyVoid
/* void type */
64 /* Fields ending in "R" are references to other TyEnts. Fields ending
65 in "Rs" are XArray*s of references to other TyEnts. */
79 HChar
* name
; /* in mallocville */
80 Bool valueKnown
; /* atoms w/ unknown value are possible */
84 HChar
* name
; /* in mallocville */
85 UWord typeR
; /* should be Te_TyXXXX */
87 UChar
* loc
; /* location expr, in mallocville */
88 Word offset
; /* or offset from the beginning of containing
91 Word nLoc
; /* number of bytes in .pos.loc if >= 0, or -1
92 if .pos.offset should be used instead */
102 HChar
* name
; /* in mallocville */
104 UChar enc
; /* S:signed U:unsigned F:floating C:complex float */
111 HChar
* name
; /* in mallocville */
112 UWord typeR
; /* MAY BE D3_INVALID_CUOFF, denoting unknown */
115 HChar
* name
; /* in mallocville */
118 XArray
* /* of UWord */ fieldRs
;
123 HChar
* name
; /* in mallocville */
125 XArray
* /* of UWord */ atomRs
;
129 XArray
* /* of UWord */ boundRs
;
134 UChar qual
; /* C:const V:volatile R:restrict */
138 Bool isFake
; /* True == introduced by the reader */
144 /* Does this TyEnt denote a type, as opposed to some other kind of
146 Bool
ML_(TyEnt__is_type
)( const TyEnt
* );
148 /* Print a TyEnt, debug-style. */
149 void ML_(pp_TyEnt
)( const TyEnt
* );
151 /* Print a whole XArray of TyEnts, debug-style */
152 void ML_(pp_TyEnts
)( const XArray
* tyents
, const HChar
* who
);
154 /* Print a TyEnt, C style, chasing stuff as necessary. */
155 void ML_(pp_TyEnt_C_ishly
)( const XArray
* /* of TyEnt */ tyents
,
158 /* Generates a total ordering on TyEnts based only on their .cuOff
160 Word
ML_(TyEnt__cmp_by_cuOff_only
) ( const TyEnt
* te1
, const TyEnt
* te2
);
162 /* Generates a total ordering on TyEnts based on everything except
163 their .cuOff fields. */
164 Word
ML_(TyEnt__cmp_by_all_except_cuOff
) ( const TyEnt
* te1
, const TyEnt
* te2
);
166 /* Free up all directly or indirectly heap-allocated stuff attached to
167 this TyEnt, and set its tag to Te_EMPTY. The .cuOff field is
169 void ML_(TyEnt__make_EMPTY
) ( TyEnt
* te
);
171 /* How big is this type? If .b in the returned struct is False, the
174 MaybeULong
ML_(sizeOfType
)( const XArray
* /* of TyEnt */ tyents
,
177 /* Describe where in the type 'offset' falls. Caller must
178 deallocate the resulting XArray. */
179 XArray
* /*UChar*/ ML_(describe_type
)( /*OUT*/PtrdiffT
* residual_offset
,
180 const XArray
* /* of TyEnt */ tyents
,
185 /* A fast-lookup cache for ML_(TyEnts__index_by_cuOff). Nothing
186 particularly surprising here; it's 2 way set associative, with some
187 number of ways, doesn't particularly have to be a power of 2. In
188 order to have a way to indicate an invalid entry, we set the second
189 value of the pair to NULL, and keep checking for it, since
190 unfortunately there's no obvious cuOff number that we could put in
191 the first word of the pair that could indicate an invalid entry.
193 4096 arrived at as the best value for an E6600 loading Qt-4.4.1
194 Designer and all associated libraries, compiled by gcc-4.3.1,
195 -g -O, 64-bit, which is at least a moderately good stress test,
196 with the largest library being about 150MB.*/
198 #define N_TYENT_INDEX_CACHE 4096
202 struct { UWord cuOff0
; TyEnt
* ent0
;
203 UWord cuOff1
; TyEnt
* ent1
; }
204 ce
[N_TYENT_INDEX_CACHE
];
208 void ML_(TyEntIndexCache__invalidate
) ( TyEntIndexCache
* cache
);
210 /* 'ents' is an XArray of TyEnts, sorted by their .cuOff fields. Find
211 the entry which has .cuOff field as specified. Returns NULL if not
212 found. Asserts if more than one entry has the specified .cuOff
214 TyEnt
* ML_(TyEnts__index_by_cuOff
) ( const XArray
* /* of TyEnt */ ents
,
215 TyEntIndexCache
* cache
,
216 UWord cuOff_to_find
);
218 #endif /* ndef __PRIV_TYTYPES_H */
220 /*--------------------------------------------------------------------*/
221 /*--- end priv_tytypes.h ---*/
222 /*--------------------------------------------------------------------*/