Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – /branches/tendra5/src/installers/mips/common/extern_adds.c – Rev 2

Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
/**********************************************************************
32
$Author: release $
33
$Date: 1998/01/17 15:56:05 $
34
$Revision: 1.1.1.1 $
35
$Log: extern_adds.c,v $
36
 * Revision 1.1.1.1  1998/01/17  15:56:05  release
37
 * First version to be checked into rolling release.
38
 *
39
 * Revision 1.2  1995/09/12  10:59:19  currie
40
 * gcc pedanttry
41
 *
42
 * Revision 1.1  1995/04/13  09:08:06  currie
43
 * Initial revision
44
 *
45
***********************************************************************/
46
#include "config.h"
47
#include "extern_adds.h"
48
#include "common_types.h"
49
#include "procrectypes.h"
50
#include "tags.h"
51
#include "exp.h"
52
#include "expmacs.h"
53
#include "shapemacs.h"
54
#include "externs.h"
55
#include "basicread.h"
56
#include "needs_scan.h"
57
 
58
 
59
/* replaces uses of extern in procs by local identification of address;
60
 
61
   initially replace usage chain by
62
     name:0; pt: usage chain in proc P; son: P; props: !=0 if in loop
63
	no: no of usages in proc; bro: last in usage chain;
64
    in usages[no of procs]
65
    Use this to determine if and where to identify global to a proc local
66
 
67
*/
68
 
69
exp * usages;
70
 
71
static bool enter_parents
72
    PROTO_N ( (e) )
73
    PROTO_T ( exp e )
74
{
75
	exp dad =e;
76
	bool inloop = 0;
77
	Assert(name(e)==name_tag);
78
	for(;;) {
79
	  	dad = father(dad);
80
		if (name(dad)==rep_tag) {
81
		  	inloop=1;
82
		}
83
		else
84
		if (name(dad)==proc_tag) {
85
			exp nu = usages[no(dad)];
86
			if (nu == nilexp) {
87
			  nu = getexp(sh(e), e, 1, dad, nilexp, 0,
88
			  		0, 0);
89
			  usages[no(dad)] = nu;
90
		        }
91
			props(nu) |= inloop;
92
			pt(e) = pt(nu);
93
				/* remember pt(e) before entry */
94
			pt(nu) = e;
95
			no(nu)++;
96
			return 1;
97
		}
98
		else
99
		if (name(dad)== ident_tag && isglob(dad)) {
100
			return 0;
101
		}
102
		else
103
		if (name(dad) == 102) {
104
			/* could be leftover from exp token expansion
105
				with no pars */
106
			return 0;
107
		}
108
	}
109
}
110
 
111
 
112
 
113
void global_usages
114
    PROTO_N ( (id, nop) )
115
    PROTO_T ( exp id X int nop )
116
{
117
	exp plist, nextpl;
118
	int i;
119
	Assert(name(id)==ident_tag && isglob(id) && son(id)==nilexp);
120
	if (no(id)==0) return;
121
 
122
	for(i=0; i<nop; i++) {
123
		usages[i] = nilexp;
124
	}
125
	plist = pt(id);
126
	nextpl = pt(plist);
127
	pt(id) = nilexp;
128
	no(id) = 0;
129
	for(;;) {
130
		if (!enter_parents(plist)) {
131
			pt(plist) = pt(id);
132
			pt(id) = plist;
133
			no(id)++;
134
		}
135
		if ((plist = nextpl) == nilexp) break;
136
		nextpl = pt(plist);
137
	}
138
 
139
	for(i=0; i<nop; i++) {
140
	  exp ui = usages[i];
141
	  if (ui != nilexp) {
142
 
143
	     if (props(ui) != 0  ) {
144
	     	/* id is used enough in proc i - so identify it locally */
145
		exp * pi;
146
		shape sname = f_pointer(f_alignment(sh(id)));
147
		for(pi= &son(son(ui));;) {
148
		  if (name(*pi)== ident_tag && isparam(*pi)) {
149
		  	pi = &bro(son(*pi));
150
		  }
151
		  else
152
		  if (name(*pi) == diagnose_tag || name(*pi) == prof_tag) {
153
			pi = &son(*pi);
154
		  }
155
		  else {
156
		  	/* invent new def to identify global ... */
157
			exp nl = getexp(sname,
158
				   *pi, 0, id, pt(id), 0, 0, name_tag);
159
			exp ndef = getexp(sh(*pi), bro(*pi),last(*pi),
160
					 nl, nilexp, 0x10 /*don't defer */,
161
					0, ident_tag);
162
			exp lu = pt(ui);
163
			setlast(*pi); bro(*pi) = ndef;
164
			pt(id) = nl; no(id)++;
165
			*pi = ndef;
166
			/*... and replace uses of global by ndef */
167
			while(lu != nilexp) {
168
			  exp nlu = pt(lu);
169
			  if (no(lu)!=0) {
170
				exp * plu = ptr_position(lu);
171
				exp nrf = getexp(sh(lu), bro(lu), last(lu),
172
						lu, nilexp, 0, no(lu), reff_tag);
173
				sh(lu) = sname;
174
				no(lu) = 0;
175
				bro(lu) = nrf; setlast(lu);
176
				*plu = nrf;
177
			  }
178
			  son(lu) = ndef;
179
			  pt(lu) = pt(ndef);
180
		          pt(ndef)= lu; no(ndef)++;
181
			  lu = nlu;
182
			}
183
			break;
184
		  }
185
		}
186
	      }
187
	      else {
188
	      	/* restore normal usage chain */
189
		pt(bro(ui)) = pt(id);
190
		pt(id) = pt(ui);
191
		no(id)+= no(ui);
192
	      }
193
	      retcell(ui);
194
	   }
195
	}
196
}