11673e404SJohn Birrell /*
21673e404SJohn Birrell * CDDL HEADER START
31673e404SJohn Birrell *
41673e404SJohn Birrell * The contents of this file are subject to the terms of the
51673e404SJohn Birrell * Common Development and Distribution License (the "License").
61673e404SJohn Birrell * You may not use this file except in compliance with the License.
71673e404SJohn Birrell *
81673e404SJohn Birrell * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91673e404SJohn Birrell * or http://www.opensolaris.org/os/licensing.
101673e404SJohn Birrell * See the License for the specific language governing permissions
111673e404SJohn Birrell * and limitations under the License.
121673e404SJohn Birrell *
131673e404SJohn Birrell * When distributing Covered Code, include this CDDL HEADER in each
141673e404SJohn Birrell * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151673e404SJohn Birrell * If applicable, add the following below this CDDL HEADER, with the
161673e404SJohn Birrell * fields enclosed by brackets "[]" replaced with your own identifying
171673e404SJohn Birrell * information: Portions Copyright [yyyy] [name of copyright owner]
181673e404SJohn Birrell *
191673e404SJohn Birrell * CDDL HEADER END
201673e404SJohn Birrell */
211673e404SJohn Birrell /*
221670a1c2SRui Paulo * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
231673e404SJohn Birrell * Use is subject to license terms.
241673e404SJohn Birrell */
251673e404SJohn Birrell
261673e404SJohn Birrell /*
271673e404SJohn Birrell * Routines for manipulating tdesc and tdata structures
281673e404SJohn Birrell */
291673e404SJohn Birrell
301673e404SJohn Birrell #include <stdio.h>
311673e404SJohn Birrell #include <stdlib.h>
321673e404SJohn Birrell #include <strings.h>
331673e404SJohn Birrell #include <pthread.h>
341673e404SJohn Birrell
351673e404SJohn Birrell #include "ctftools.h"
361673e404SJohn Birrell #include "memory.h"
371673e404SJohn Birrell #include "traverse.h"
381673e404SJohn Birrell
391673e404SJohn Birrell /*
401673e404SJohn Birrell * The layout hash is used during the equivalency checking. We have a node in
411673e404SJohn Birrell * the child graph that may be equivalent to a node in the parent graph. To
421673e404SJohn Birrell * find the corresponding node (if any) in the parent, we need a quick way to
431673e404SJohn Birrell * get to all nodes in the parent that look like the node in the child. Since a
441673e404SJohn Birrell * large number of nodes don't have names, we need to incorporate the layout of
451673e404SJohn Birrell * the node into the hash. If we don't, we'll end up with the vast majority of
461673e404SJohn Birrell * nodes in bucket zero, with one or two nodes in each of the remaining buckets.
471673e404SJohn Birrell *
481673e404SJohn Birrell * There are a couple of constraints, both of which concern forward
491673e404SJohn Birrell * declarations. Recall that a forward declaration tdesc is equivalent to a
501673e404SJohn Birrell * tdesc that actually defines the structure or union. As such, we cannot
511673e404SJohn Birrell * incorporate anything into the hash for a named struct or union node that
521673e404SJohn Birrell * couldn't be found by looking at the forward, and vice versa.
531673e404SJohn Birrell */
541673e404SJohn Birrell int
tdesc_layouthash(int nbuckets,void * node)551673e404SJohn Birrell tdesc_layouthash(int nbuckets, void *node)
561673e404SJohn Birrell {
571673e404SJohn Birrell tdesc_t *tdp = node;
581673e404SJohn Birrell char *name = NULL;
591673e404SJohn Birrell ulong_t h = 0;
601673e404SJohn Birrell
611673e404SJohn Birrell if (tdp->t_name)
621673e404SJohn Birrell name = tdp->t_name;
631673e404SJohn Birrell else {
641673e404SJohn Birrell switch (tdp->t_type) {
651673e404SJohn Birrell case POINTER:
661673e404SJohn Birrell case TYPEDEF:
671673e404SJohn Birrell case VOLATILE:
681673e404SJohn Birrell case CONST:
691673e404SJohn Birrell case RESTRICT:
701673e404SJohn Birrell name = tdp->t_tdesc->t_name;
711673e404SJohn Birrell break;
721673e404SJohn Birrell case FUNCTION:
731673e404SJohn Birrell h = tdp->t_fndef->fn_nargs +
741673e404SJohn Birrell tdp->t_fndef->fn_vargs;
751673e404SJohn Birrell name = tdp->t_fndef->fn_ret->t_name;
761673e404SJohn Birrell break;
771673e404SJohn Birrell case ARRAY:
781673e404SJohn Birrell h = tdp->t_ardef->ad_nelems;
791673e404SJohn Birrell name = tdp->t_ardef->ad_contents->t_name;
801673e404SJohn Birrell break;
811673e404SJohn Birrell case STRUCT:
821673e404SJohn Birrell case UNION:
831673e404SJohn Birrell /*
841673e404SJohn Birrell * Unnamed structures, which cannot have forward
851673e404SJohn Birrell * declarations pointing to them. We can therefore
861673e404SJohn Birrell * incorporate the name of the first member into
871670a1c2SRui Paulo * the hash value, assuming there are any.
881673e404SJohn Birrell */
891670a1c2SRui Paulo if (tdp->t_members != NULL)
901673e404SJohn Birrell name = tdp->t_members->ml_name;
911673e404SJohn Birrell break;
921673e404SJohn Birrell case ENUM:
931673e404SJohn Birrell /* Use the first element in the hash value */
941673e404SJohn Birrell name = tdp->t_emem->el_name;
951673e404SJohn Birrell break;
961673e404SJohn Birrell default:
971673e404SJohn Birrell /*
981673e404SJohn Birrell * Intrinsics, forwards, and typedefs all have
991673e404SJohn Birrell * names.
1001673e404SJohn Birrell */
1011673e404SJohn Birrell warning("Unexpected unnamed %d tdesc (ID %d)\n",
1021673e404SJohn Birrell tdp->t_type, tdp->t_id);
1031673e404SJohn Birrell }
1041673e404SJohn Birrell }
1051673e404SJohn Birrell
1061673e404SJohn Birrell if (name)
1071673e404SJohn Birrell return (hash_name(nbuckets, name));
1081673e404SJohn Birrell
1091673e404SJohn Birrell return (h % nbuckets);
1101673e404SJohn Birrell }
1111673e404SJohn Birrell
1121673e404SJohn Birrell int
tdesc_layoutcmp(void * arg1,void * arg2)1131673e404SJohn Birrell tdesc_layoutcmp(void *arg1, void *arg2)
1141673e404SJohn Birrell {
1151673e404SJohn Birrell tdesc_t *tdp1 = arg1, *tdp2 = arg2;
1161673e404SJohn Birrell
1171673e404SJohn Birrell if (tdp1->t_name == NULL) {
1181673e404SJohn Birrell if (tdp2->t_name == NULL)
1191673e404SJohn Birrell return (0);
1201673e404SJohn Birrell else
1211673e404SJohn Birrell return (-1);
1221673e404SJohn Birrell } else if (tdp2->t_name == NULL)
1231673e404SJohn Birrell return (1);
1241673e404SJohn Birrell else
1251673e404SJohn Birrell return (strcmp(tdp1->t_name, tdp2->t_name));
1261673e404SJohn Birrell }
1271673e404SJohn Birrell
1281673e404SJohn Birrell int
tdesc_idhash(int nbuckets,void * data)1291673e404SJohn Birrell tdesc_idhash(int nbuckets, void *data)
1301673e404SJohn Birrell {
1311673e404SJohn Birrell tdesc_t *tdp = data;
1321673e404SJohn Birrell
1331673e404SJohn Birrell return (tdp->t_id % nbuckets);
1341673e404SJohn Birrell }
1351673e404SJohn Birrell
1361673e404SJohn Birrell int
tdesc_idcmp(void * arg1,void * arg2)1371673e404SJohn Birrell tdesc_idcmp(void *arg1, void *arg2)
1381673e404SJohn Birrell {
1391673e404SJohn Birrell tdesc_t *tdp1 = arg1, *tdp2 = arg2;
1401673e404SJohn Birrell
1411673e404SJohn Birrell if (tdp1->t_id == tdp2->t_id)
1421673e404SJohn Birrell return (0);
1431673e404SJohn Birrell else
1441673e404SJohn Birrell return (tdp1->t_id > tdp2->t_id ? 1 : -1);
1451673e404SJohn Birrell }
1461673e404SJohn Birrell
1471673e404SJohn Birrell int
tdesc_namehash(int nbuckets,void * data)1481673e404SJohn Birrell tdesc_namehash(int nbuckets, void *data)
1491673e404SJohn Birrell {
1501673e404SJohn Birrell tdesc_t *tdp = data;
1511673e404SJohn Birrell ulong_t h, g;
1521673e404SJohn Birrell char *c;
1531673e404SJohn Birrell
1541673e404SJohn Birrell if (tdp->t_name == NULL)
1551673e404SJohn Birrell return (0);
1561673e404SJohn Birrell
1571673e404SJohn Birrell for (h = 0, c = tdp->t_name; *c; c++) {
1581673e404SJohn Birrell h = (h << 4) + *c;
1591673e404SJohn Birrell if ((g = (h & 0xf0000000)) != 0) {
1601673e404SJohn Birrell h ^= (g >> 24);
1611673e404SJohn Birrell h ^= g;
1621673e404SJohn Birrell }
1631673e404SJohn Birrell }
1641673e404SJohn Birrell
1651673e404SJohn Birrell return (h % nbuckets);
1661673e404SJohn Birrell }
1671673e404SJohn Birrell
1681673e404SJohn Birrell int
tdesc_namecmp(void * arg1,void * arg2)1691673e404SJohn Birrell tdesc_namecmp(void *arg1, void *arg2)
1701673e404SJohn Birrell {
1711673e404SJohn Birrell tdesc_t *tdp1 = arg1, *tdp2 = arg2;
1721673e404SJohn Birrell
1731673e404SJohn Birrell return (!streq(tdp1->t_name, tdp2->t_name));
1741673e404SJohn Birrell }
1751673e404SJohn Birrell
176*bc96366cSSteven Hartland #ifdef illumos
1771673e404SJohn Birrell /*ARGSUSED1*/
1784cc75139SJohn Birrell static int
tdesc_print(void * data,void * private __unused)1794cc75139SJohn Birrell tdesc_print(void *data, void *private __unused)
1801673e404SJohn Birrell {
1811673e404SJohn Birrell tdesc_t *tdp = data;
1821673e404SJohn Birrell
1831673e404SJohn Birrell printf("%7d %s\n", tdp->t_id, tdesc_name(tdp));
1841673e404SJohn Birrell
1851673e404SJohn Birrell return (1);
1861673e404SJohn Birrell }
1874cc75139SJohn Birrell #endif
1881673e404SJohn Birrell
1891673e404SJohn Birrell static void
free_intr(tdesc_t * tdp)1901673e404SJohn Birrell free_intr(tdesc_t *tdp)
1911673e404SJohn Birrell {
1921673e404SJohn Birrell free(tdp->t_intr);
1931673e404SJohn Birrell }
1941673e404SJohn Birrell
1951673e404SJohn Birrell static void
free_ardef(tdesc_t * tdp)1961673e404SJohn Birrell free_ardef(tdesc_t *tdp)
1971673e404SJohn Birrell {
1981673e404SJohn Birrell free(tdp->t_ardef);
1991673e404SJohn Birrell }
2001673e404SJohn Birrell
2011673e404SJohn Birrell static void
free_mlist(tdesc_t * tdp)2021673e404SJohn Birrell free_mlist(tdesc_t *tdp)
2031673e404SJohn Birrell {
2041673e404SJohn Birrell mlist_t *ml = tdp->t_members;
2051673e404SJohn Birrell mlist_t *oml;
2061673e404SJohn Birrell
2071673e404SJohn Birrell while (ml) {
2081673e404SJohn Birrell oml = ml;
2091673e404SJohn Birrell ml = ml->ml_next;
2101673e404SJohn Birrell
2111673e404SJohn Birrell if (oml->ml_name)
2121673e404SJohn Birrell free(oml->ml_name);
2131673e404SJohn Birrell free(oml);
2141673e404SJohn Birrell }
2151673e404SJohn Birrell }
2161673e404SJohn Birrell
2171673e404SJohn Birrell static void
free_elist(tdesc_t * tdp)2181673e404SJohn Birrell free_elist(tdesc_t *tdp)
2191673e404SJohn Birrell {
2201673e404SJohn Birrell elist_t *el = tdp->t_emem;
2211673e404SJohn Birrell elist_t *oel;
2221673e404SJohn Birrell
2231673e404SJohn Birrell while (el) {
2241673e404SJohn Birrell oel = el;
2251673e404SJohn Birrell el = el->el_next;
2261673e404SJohn Birrell
2271673e404SJohn Birrell if (oel->el_name)
2281673e404SJohn Birrell free(oel->el_name);
2291673e404SJohn Birrell free(oel);
2301673e404SJohn Birrell }
2311673e404SJohn Birrell }
2321673e404SJohn Birrell
2331673e404SJohn Birrell static void (*free_cbs[])(tdesc_t *) = {
2341673e404SJohn Birrell NULL,
2351673e404SJohn Birrell free_intr,
2361673e404SJohn Birrell NULL,
2371673e404SJohn Birrell free_ardef,
2381673e404SJohn Birrell NULL,
2391673e404SJohn Birrell free_mlist,
2401673e404SJohn Birrell free_mlist,
2411673e404SJohn Birrell free_elist,
2421673e404SJohn Birrell NULL,
2431673e404SJohn Birrell NULL,
2441673e404SJohn Birrell NULL,
2451673e404SJohn Birrell NULL,
2461673e404SJohn Birrell NULL,
2471673e404SJohn Birrell NULL
2481673e404SJohn Birrell };
2491673e404SJohn Birrell
2501673e404SJohn Birrell /*ARGSUSED1*/
2514cc75139SJohn Birrell static void
tdesc_free_cb(void * arg,void * private __unused)2524cc75139SJohn Birrell tdesc_free_cb(void *arg, void *private __unused)
2531673e404SJohn Birrell {
2544cc75139SJohn Birrell tdesc_t *tdp = arg;
2551673e404SJohn Birrell if (tdp->t_name)
2561673e404SJohn Birrell free(tdp->t_name);
2571673e404SJohn Birrell if (free_cbs[tdp->t_type])
2581673e404SJohn Birrell free_cbs[tdp->t_type](tdp);
2591673e404SJohn Birrell free(tdp);
2601673e404SJohn Birrell
2614cc75139SJohn Birrell return;
2621673e404SJohn Birrell }
2631673e404SJohn Birrell
2641673e404SJohn Birrell void
tdesc_free(tdesc_t * tdp)2651673e404SJohn Birrell tdesc_free(tdesc_t *tdp)
2661673e404SJohn Birrell {
2674cc75139SJohn Birrell tdesc_free_cb(tdp, NULL);
2681673e404SJohn Birrell }
2691673e404SJohn Birrell
2701673e404SJohn Birrell static int
tdata_label_cmp(void * arg1,void * arg2)2714cc75139SJohn Birrell tdata_label_cmp(void *arg1, void *arg2)
2721673e404SJohn Birrell {
2734cc75139SJohn Birrell labelent_t *le1 = arg1;
2744cc75139SJohn Birrell labelent_t *le2 = arg2;
2751673e404SJohn Birrell return (le1->le_idx - le2->le_idx);
2761673e404SJohn Birrell }
2771673e404SJohn Birrell
2781673e404SJohn Birrell void
tdata_label_add(tdata_t * td,const char * label,int idx)2794cc75139SJohn Birrell tdata_label_add(tdata_t *td, const char *label, int idx)
2801673e404SJohn Birrell {
2811673e404SJohn Birrell labelent_t *le = xmalloc(sizeof (*le));
2821673e404SJohn Birrell
2831673e404SJohn Birrell le->le_name = xstrdup(label);
2841673e404SJohn Birrell le->le_idx = (idx == -1 ? td->td_nextid - 1 : idx);
2851673e404SJohn Birrell
2864cc75139SJohn Birrell slist_add(&td->td_labels, le, tdata_label_cmp);
2871673e404SJohn Birrell }
2881673e404SJohn Birrell
2891673e404SJohn Birrell static int
tdata_label_top_cb(void * data,void * arg)2901673e404SJohn Birrell tdata_label_top_cb(void *data, void *arg)
2911673e404SJohn Birrell {
2921673e404SJohn Birrell labelent_t *le = data;
2931673e404SJohn Birrell labelent_t **topp = arg;
2941673e404SJohn Birrell
2951673e404SJohn Birrell *topp = le;
2961673e404SJohn Birrell
2971673e404SJohn Birrell return (1);
2981673e404SJohn Birrell }
2991673e404SJohn Birrell
3001673e404SJohn Birrell labelent_t *
tdata_label_top(tdata_t * td)3011673e404SJohn Birrell tdata_label_top(tdata_t *td)
3021673e404SJohn Birrell {
3031673e404SJohn Birrell labelent_t *top = NULL;
3041673e404SJohn Birrell
3051673e404SJohn Birrell (void) list_iter(td->td_labels, tdata_label_top_cb, &top);
3061673e404SJohn Birrell
3071673e404SJohn Birrell return (top);
3081673e404SJohn Birrell }
3091673e404SJohn Birrell
3101673e404SJohn Birrell static int
tdata_label_find_cb(void * arg1,void * arg2)3114cc75139SJohn Birrell tdata_label_find_cb(void *arg1, void *arg2)
3121673e404SJohn Birrell {
3134cc75139SJohn Birrell labelent_t *le = arg1;
3144cc75139SJohn Birrell labelent_t *tmpl = arg2;
3151673e404SJohn Birrell return (streq(le->le_name, tmpl->le_name));
3161673e404SJohn Birrell }
3171673e404SJohn Birrell
3181673e404SJohn Birrell int
tdata_label_find(tdata_t * td,char * label)3191673e404SJohn Birrell tdata_label_find(tdata_t *td, char *label)
3201673e404SJohn Birrell {
3211673e404SJohn Birrell labelent_t let;
3221673e404SJohn Birrell labelent_t *ret;
3231673e404SJohn Birrell
3241673e404SJohn Birrell if (streq(label, "BASE")) {
3251673e404SJohn Birrell ret = (labelent_t *)list_first(td->td_labels);
3261673e404SJohn Birrell return (ret ? ret->le_idx : -1);
3271673e404SJohn Birrell }
3281673e404SJohn Birrell
3291673e404SJohn Birrell let.le_name = label;
3301673e404SJohn Birrell
3311673e404SJohn Birrell if (!(ret = (labelent_t *)list_find(td->td_labels, &let,
3324cc75139SJohn Birrell tdata_label_find_cb)))
3331673e404SJohn Birrell return (-1);
3341673e404SJohn Birrell
3351673e404SJohn Birrell return (ret->le_idx);
3361673e404SJohn Birrell }
3371673e404SJohn Birrell
3381673e404SJohn Birrell static int
tdata_label_newmax_cb(void * data,void * arg)3391673e404SJohn Birrell tdata_label_newmax_cb(void *data, void *arg)
3401673e404SJohn Birrell {
3411673e404SJohn Birrell labelent_t *le = data;
3421673e404SJohn Birrell int *newmaxp = arg;
3431673e404SJohn Birrell
3441673e404SJohn Birrell if (le->le_idx > *newmaxp) {
3451673e404SJohn Birrell le->le_idx = *newmaxp;
3461673e404SJohn Birrell return (1);
3471673e404SJohn Birrell }
3481673e404SJohn Birrell
3491673e404SJohn Birrell return (0);
3501673e404SJohn Birrell }
3511673e404SJohn Birrell
3521673e404SJohn Birrell void
tdata_label_newmax(tdata_t * td,int newmax)3531673e404SJohn Birrell tdata_label_newmax(tdata_t *td, int newmax)
3541673e404SJohn Birrell {
3551673e404SJohn Birrell (void) list_iter(td->td_labels, tdata_label_newmax_cb, &newmax);
3561673e404SJohn Birrell }
3571673e404SJohn Birrell
3581673e404SJohn Birrell /*ARGSUSED1*/
3591673e404SJohn Birrell static void
tdata_label_free_cb(void * arg,void * private __unused)3604cc75139SJohn Birrell tdata_label_free_cb(void *arg, void *private __unused)
3611673e404SJohn Birrell {
3624cc75139SJohn Birrell labelent_t *le = arg;
3631673e404SJohn Birrell if (le->le_name)
3641673e404SJohn Birrell free(le->le_name);
3651673e404SJohn Birrell free(le);
3661673e404SJohn Birrell }
3671673e404SJohn Birrell
3681673e404SJohn Birrell void
tdata_label_free(tdata_t * td)3691673e404SJohn Birrell tdata_label_free(tdata_t *td)
3701673e404SJohn Birrell {
3714cc75139SJohn Birrell list_free(td->td_labels, tdata_label_free_cb, NULL);
3721673e404SJohn Birrell td->td_labels = NULL;
3731673e404SJohn Birrell }
3741673e404SJohn Birrell
3751673e404SJohn Birrell tdata_t *
tdata_new(void)3761673e404SJohn Birrell tdata_new(void)
3771673e404SJohn Birrell {
3781673e404SJohn Birrell tdata_t *new = xcalloc(sizeof (tdata_t));
3791673e404SJohn Birrell
3801673e404SJohn Birrell new->td_layouthash = hash_new(TDATA_LAYOUT_HASH_SIZE, tdesc_layouthash,
3811673e404SJohn Birrell tdesc_layoutcmp);
3821673e404SJohn Birrell new->td_idhash = hash_new(TDATA_ID_HASH_SIZE, tdesc_idhash,
3831673e404SJohn Birrell tdesc_idcmp);
3841673e404SJohn Birrell /*
3851673e404SJohn Birrell * This is also traversed as a list, but amortized O(1)
3861673e404SJohn Birrell * lookup massively impacts part of the merge phase, so
3871673e404SJohn Birrell * we store the iidescs as a hash.
3881673e404SJohn Birrell */
3891673e404SJohn Birrell new->td_iihash = hash_new(IIDESC_HASH_SIZE, iidesc_hash, NULL);
3901673e404SJohn Birrell new->td_nextid = 1;
3911673e404SJohn Birrell new->td_curvgen = 1;
3921673e404SJohn Birrell
3931673e404SJohn Birrell pthread_mutex_init(&new->td_mergelock, NULL);
3941673e404SJohn Birrell
3951673e404SJohn Birrell return (new);
3961673e404SJohn Birrell }
3971673e404SJohn Birrell
3981673e404SJohn Birrell void
tdata_free(tdata_t * td)3991673e404SJohn Birrell tdata_free(tdata_t *td)
4001673e404SJohn Birrell {
4014cc75139SJohn Birrell hash_free(td->td_iihash, iidesc_free, NULL);
4024cc75139SJohn Birrell hash_free(td->td_layouthash, tdesc_free_cb, NULL);
4031673e404SJohn Birrell hash_free(td->td_idhash, NULL, NULL);
4041673e404SJohn Birrell list_free(td->td_fwdlist, NULL, NULL);
4051673e404SJohn Birrell
4061673e404SJohn Birrell tdata_label_free(td);
4071673e404SJohn Birrell
4081673e404SJohn Birrell free(td->td_parlabel);
4091673e404SJohn Birrell free(td->td_parname);
4101673e404SJohn Birrell
4111673e404SJohn Birrell pthread_mutex_destroy(&td->td_mergelock);
4121673e404SJohn Birrell
4131673e404SJohn Birrell free(td);
4141673e404SJohn Birrell }
4151673e404SJohn Birrell
4161673e404SJohn Birrell /*ARGSUSED1*/
4171673e404SJohn Birrell static int
build_hashes(tdesc_t * ctdp,tdesc_t ** ctdpp __unused,void * private)4184cc75139SJohn Birrell build_hashes(tdesc_t *ctdp, tdesc_t **ctdpp __unused, void *private)
4191673e404SJohn Birrell {
4201673e404SJohn Birrell tdata_t *td = private;
4211673e404SJohn Birrell
4221673e404SJohn Birrell hash_add(td->td_idhash, ctdp);
4231673e404SJohn Birrell hash_add(td->td_layouthash, ctdp);
4241673e404SJohn Birrell
4251673e404SJohn Birrell return (1);
4261673e404SJohn Birrell }
4271673e404SJohn Birrell
4281673e404SJohn Birrell static tdtrav_cb_f build_hashes_cbs[] = {
4291673e404SJohn Birrell NULL,
4301673e404SJohn Birrell build_hashes, /* intrinsic */
4311673e404SJohn Birrell build_hashes, /* pointer */
4321673e404SJohn Birrell build_hashes, /* array */
4331673e404SJohn Birrell build_hashes, /* function */
4341673e404SJohn Birrell build_hashes, /* struct */
4351673e404SJohn Birrell build_hashes, /* union */
4361673e404SJohn Birrell build_hashes, /* enum */
4371673e404SJohn Birrell build_hashes, /* forward */
4381673e404SJohn Birrell build_hashes, /* typedef */
4391673e404SJohn Birrell tdtrav_assert, /* typedef_unres */
4401673e404SJohn Birrell build_hashes, /* volatile */
4411673e404SJohn Birrell build_hashes, /* const */
4421673e404SJohn Birrell build_hashes /* restrict */
4431673e404SJohn Birrell };
4441673e404SJohn Birrell
4451673e404SJohn Birrell static void
tdata_build_hashes_common(tdata_t * td,hash_t * hash)4461673e404SJohn Birrell tdata_build_hashes_common(tdata_t *td, hash_t *hash)
4471673e404SJohn Birrell {
4481673e404SJohn Birrell (void) iitraverse_hash(hash, &td->td_curvgen, NULL, NULL,
4491673e404SJohn Birrell build_hashes_cbs, td);
4501673e404SJohn Birrell }
4511673e404SJohn Birrell
4521673e404SJohn Birrell void
tdata_build_hashes(tdata_t * td)4531673e404SJohn Birrell tdata_build_hashes(tdata_t *td)
4541673e404SJohn Birrell {
4551673e404SJohn Birrell tdata_build_hashes_common(td, td->td_iihash);
4561673e404SJohn Birrell }
4571673e404SJohn Birrell
4581673e404SJohn Birrell /* Merge td2 into td1. td2 is destroyed by the merge */
4591673e404SJohn Birrell void
tdata_merge(tdata_t * td1,tdata_t * td2)4601673e404SJohn Birrell tdata_merge(tdata_t *td1, tdata_t *td2)
4611673e404SJohn Birrell {
4621673e404SJohn Birrell td1->td_curemark = MAX(td1->td_curemark, td2->td_curemark);
4631673e404SJohn Birrell td1->td_curvgen = MAX(td1->td_curvgen, td2->td_curvgen);
4641673e404SJohn Birrell td1->td_nextid = MAX(td1->td_nextid, td2->td_nextid);
4651673e404SJohn Birrell
4661673e404SJohn Birrell hash_merge(td1->td_iihash, td2->td_iihash);
4671673e404SJohn Birrell
4681673e404SJohn Birrell /* Add td2's type tree to the hashes */
4691673e404SJohn Birrell tdata_build_hashes_common(td1, td2->td_iihash);
4701673e404SJohn Birrell
4711673e404SJohn Birrell list_concat(&td1->td_fwdlist, td2->td_fwdlist);
4721673e404SJohn Birrell td2->td_fwdlist = NULL;
4731673e404SJohn Birrell
4741673e404SJohn Birrell slist_merge(&td1->td_labels, td2->td_labels,
4754cc75139SJohn Birrell tdata_label_cmp);
4761673e404SJohn Birrell td2->td_labels = NULL;
4771673e404SJohn Birrell
4781673e404SJohn Birrell /* free the td2 hashes (data is now part of td1) */
4791673e404SJohn Birrell
4801673e404SJohn Birrell hash_free(td2->td_layouthash, NULL, NULL);
4811673e404SJohn Birrell td2->td_layouthash = NULL;
4821673e404SJohn Birrell
4831673e404SJohn Birrell hash_free(td2->td_iihash, NULL, NULL);
4841673e404SJohn Birrell td2->td_iihash = NULL;
4851673e404SJohn Birrell
4861673e404SJohn Birrell tdata_free(td2);
4871673e404SJohn Birrell }
488