1 #ifndef lint
2 static char *sccsid ="bldds.c	(CWI)	1.1	85/03/01";
3 #endif
4 /* BuiLD Data Structures */
5 
6 #include "ideal.h"
7 #include "y.tab.h"
8 
9 NOADPTR rbuildnoadtree (corrputnode)
10 PUTPTR corrputnode;
11 {
12 	NOADPTR nuroot, putsons, boxsons;
13 	dprintf "building noad tree for %s\n", idprint (corrputnode->name));
14 	nuroot = noadgen (
15 			corrputnode,
16 			buildvarlist (corrputnode->parm->stmtlist),
17 			buildvarlist ((findbox (corrputnode->parm->name,FALSE))->stmtlist)
18 		);
19 	putsons = walkputlist (corrputnode->parm->stmtlist, nuroot);
20 	boxsons = walkputlist ((findbox (corrputnode->parm->name,FALSE))->stmtlist, nuroot);
21 	if (putsons == NULL) {
22 		nuroot->son = boxsons;
23 	} else {
24 		NOADPTR temp;
25 		for (temp = putsons;
26 			temp->brother != NULL;
27 			temp = temp->brother)
28 			;
29 		temp->brother = boxsons;
30 		nuroot->son = putsons;
31 	}
32 	return (nuroot);
33 }
34 
35 NOADPTR buildnoadtree (corrputnode)
36 PUTPTR corrputnode;
37 {
38 	NOADPTR retval;
39 	if (when_bug & 02) bug_on;
40 	retval = rbuildnoadtree (corrputnode);
41 	bug_off;
42 	return (retval);
43 }
44 
45 VARPTR buildvarlist (stmtlist)
46 STMTPTR stmtlist;
47 {
48 	VARPTR curlist;
49 	NAMEPTR namewalk;
50 	curlist = NULL;
51 	stmtlist = nextstmt (VAR, stmtlist);
52 	while (stmtlist) {
53 		/* make room for each local variable, and
54 		/* make each independent (x = 1*x) */
55 		for (namewalk = ((NAMEPTR) stmtlist->stmt);
56 			namewalk;
57 			namewalk = namewalk->next) {
58 			VARPTR newre, newim;
59 			newre = vargen (namewalk->name, TRUE, (DEPPTR) NULL);
60 			newre->deplist = depgen (newre, 1.0);
61 			newim = vargen (namewalk->name, FALSE, (DEPPTR) NULL);
62 			newim->deplist = depgen (newim, 1.0);
63 			newre->next = newim;
64 			newim->next = curlist;
65 			curlist = newre;
66 		}
67 		stmtlist = nextstmt (VAR, stmtlist->next);
68 	}
69 	return (curlist);
70 }
71 
72 NOADPTR walkputlist (stmtlist, parent)
73 STMTPTR stmtlist;
74 NOADPTR parent;
75 {
76 	NOADPTR headnoad, curnoad, prevnoad;
77 	stmtlist = nextstmt (PUT, stmtlist);
78 	if (!stmtlist)
79 		return (NULL);
80 	headnoad = prevnoad = rbuildnoadtree ((PUTPTR) stmtlist->stmt);
81 	prevnoad->father = parent;
82 	stmtlist = nextstmt (PUT, stmtlist->next);
83 	while (stmtlist) {
84 		curnoad = rbuildnoadtree ((PUTPTR) stmtlist->stmt);
85 		curnoad->father = parent;
86 		prevnoad->brother = curnoad;
87 		prevnoad = curnoad;
88 		stmtlist = nextstmt (PUT, stmtlist->next);
89 	}
90 	return (headnoad);
91 }
92