Subversion Repositories tendra.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
7 7u83 2
 * Copyright (c) 2002-2006 The TenDRA Project <http://www.tendra.org/>.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 * 1. Redistributions of source code must retain the above copyright notice,
9
 *    this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
11
 *    this list of conditions and the following disclaimer in the documentation
12
 *    and/or other materials provided with the distribution.
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific, prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 *
29
 * $Id$
30
 */
31
/*
2 7u83 32
    		 Crown Copyright (c) 1996
33
 
34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
42
 
43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
45
 
46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
49
 
50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
53
 
54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
/*
60
			    VERSION INFORMATION
61
			    ===================
62
 
63
--------------------------------------------------------------------------
64
$Header: /u/g/release/CVSROOT/Source/src/installers/680x0/common/mach_ins.c,v 1.1.1.1 1998/01/17 15:55:49 release Exp $
65
--------------------------------------------------------------------------
66
$Log: mach_ins.c,v $
67
 * Revision 1.1.1.1  1998/01/17  15:55:49  release
68
 * First version to be checked into rolling release.
69
 *
70
Revision 1.4  1997/11/13 08:27:13  ma
71
All avs test passed (except add_to_ptr).
72
 
73
Revision 1.3  1997/11/10 15:38:06  ma
74
.
75
 
76
Revision 1.2  1997/11/09 14:13:58  ma
77
comment.
78
 
79
Revision 1.1.1.1  1997/10/13 12:42:55  ma
80
First version.
81
 
82
Revision 1.5  1997/10/13 08:49:35  ma
83
Made all pl_tests for general proc & exception handling pass.
84
 
85
Revision 1.4  1997/06/18 10:09:36  ma
86
Checking in before merging with Input Baseline changes.
87
 
88
Revision 1.3  1997/05/13 11:30:34  ma
89
Introduced make_comment for debug.
90
 
91
Revision 1.2  1997/04/20 11:30:31  ma
92
Introduced gcproc.c & general_proc.[ch].
93
Added cases for apply_general_proc next to apply_proc in all files.
94
 
95
Revision 1.1.1.1  1997/03/14 07:50:14  ma
96
Imported from DRA
97
 
98
 * Revision 1.1.1.1  1996/09/20  10:56:55  john
99
 *
100
 * Revision 1.2  1996/07/05  14:22:21  john
101
 * Changes for spec 3.1
102
 *
103
 * Revision 1.1.1.1  1996/03/26  15:45:14  john
104
 *
105
 * Revision 1.2  94/02/21  15:59:49  15:59:49  ra (Robert Andrews)
106
 * Add a couple of explicit casts.  Some flags which used to be bool are
107
 * now int.
108
 *
109
 * Revision 1.1  93/02/22  17:16:02  17:16:02  ra (Robert Andrews)
110
 * Initial revision
111
 *
112
--------------------------------------------------------------------------
113
*/
114
 
115
 
116
#include "config.h"
117
#include "common_types.h"
118
#include "instrs.h"
119
#include "mach.h"
120
#include "mach_ins.h"
121
#include "mach_op.h"
122
#include "codex.h"
123
#include "output.h"
124
#include "utility.h"
7 7u83 125
extern bool have_cond;
2 7u83 126
 
127
#ifdef EBUG
7 7u83 128
extern bool seek_label;
129
extern bool seek_extern;
130
extern int seek_label_no;
131
extern char *seek_extern_id;
2 7u83 132
#endif
133
 
134
 
135
/*
136
    OUTPUT FLAG
137
 
138
    If this is true, all instructions are output immediately.  This
139
    effectively switches off all peephole optimizations.
140
*/
141
 
7 7u83 142
int output_immediately = 0;
2 7u83 143
 
144
/*
145
    LIST OF ALL INSTRUCTIONS
146
 
147
    A list of all instructions in maintained.  The current instruction is
148
    given by current_ins.
149
*/
150
 
7 7u83 151
mach_ins *all_mach_ins = null;
152
mach_ins *current_ins = null;
2 7u83 153
 
154
 
155
/*
156
    RECORD OF LAST JUMP AND REGISTERS CHANGED SINCE
157
 
158
    This is used to help get a more accurate idea of which registers
159
    are known during the peephole optimizations.
160
*/
161
 
7 7u83 162
long last_jump = -1;
163
bitpattern last_jump_regs = 0;
2 7u83 164
 
165
 
166
/*
167
    LIST OF FREE INSTRUCTIONS
168
 
169
    A list of free mach_ins's, linked by their next field, is maintained.
170
*/
171
 
7 7u83 172
static mach_ins *mach_ins_list = null;
2 7u83 173
 
174
 
175
/*
176
    FREE A SINGLE INSTRUCTION AND ITS OPERANDS
177
 
178
    The operands of the instruction are freed and the instruction
179
    itself is added to the list of all free instructions.
180
*/
181
 
7 7u83 182
void
183
reclaim_ins(mach_ins *p)
2 7u83 184
{
7 7u83 185
	if (p->op1) {
186
		free_mach_op(p->op1);
187
	}
188
	if (p->op2) {
189
		free_mach_op(p->op2);
190
	}
191
	p->next = mach_ins_list;
192
	mach_ins_list = p;
193
	return;
2 7u83 194
}
195
 
196
 
197
/*
198
    FREE ALL INSTRUCTIONS AND THEIR OPERANDS
199
 
200
    All the instructions in the list of all instructions are freed and
201
    the list is reset to zero length.
202
*/
203
 
7 7u83 204
void
205
free_all_ins(void)
2 7u83 206
{
7 7u83 207
	mach_ins *p = all_mach_ins, *q = null;
208
	if (p == null) {
209
		return;
210
	}
211
	while (p != null) {
212
		if (p->op1) {
213
			free_mach_op(p->op1);
214
		}
215
		if (p->op2) {
216
			free_mach_op(p->op2);
217
		}
218
		q = p;
219
		p = p->next;
220
	}
221
	q->next = mach_ins_list;
222
	mach_ins_list = all_mach_ins;
223
	all_mach_ins = null;
224
	current_ins = null;
225
	last_jump = -1;
226
	last_jump_regs = 0;
227
	return;
2 7u83 228
}
229
 
230
 
231
/*
232
    CREATE A NEW INSTRUCTION
233
 
234
    A new instruction, with instruction number insno and operands op1 and
235
    op2 is added to the list of all instructions.  ch gives the mask of
236
    all registers changed by the instruction.  If susp is true then
237
    this instruction is never output immediately.  This only occurs in
238
    tmp_reg.
239
 
240
    This routine is usual called via the macro make_instr which has the
241
    same first four arguments, but has susp always false.
242
*/
243
 
244
#ifdef EBUG
7 7u83 245
static int next_id = 0;
2 7u83 246
#endif
247
 
7 7u83 248
void
249
make_instr_aux(int insno, mach_op *op1, mach_op *op2, bitpattern ch, int susp)
2 7u83 250
{
7 7u83 251
	mach_ins *p;
252
	if (insno != m_comment) {
253
		if (stack_change) {
254
			update_stack();
255
		}
2 7u83 256
	}
7 7u83 257
	if (mach_ins_list == null) {
258
		int i, n = 1000;
259
		mach_ins_list = alloc_nof(mach_ins, n);
260
		for (i = 0; i < n - 1; i++) {
261
			(mach_ins_list + i) ->next = mach_ins_list + (i + 1);
262
		}
263
		(mach_ins_list + (n - 1))->next = null;
264
	}
265
	p = mach_ins_list;
266
	mach_ins_list = p->next;
2 7u83 267
#ifdef EBUG
7 7u83 268
	p->id = ++next_id;
2 7u83 269
#if 1
7 7u83 270
	if (p->id == 4803) {
271
		int found = 1;
272
	}
2 7u83 273
#endif
274
#endif
7 7u83 275
	p->ins_no = insno;
276
	p->op1 = op1;
277
	p->op2 = op2;
278
	p->changed = ch;
279
	last_jump_regs |= ch;
280
	if (current_ins == null) {
281
		p->next = all_mach_ins;
282
		all_mach_ins = p;
283
	} else {
284
		p->next = current_ins->next;
285
		current_ins->next = p;
286
	}
287
	current_ins = p;
2 7u83 288
 
7 7u83 289
	if (insno != m_comment) {
290
		/* Clear the temporary register status */
291
		tmp_reg_status = 0;
292
		tmp_reg_prefer = 0;
293
	}
2 7u83 294
 
7 7u83 295
	if (output_immediately && !susp) {
296
		output_all();
297
		free_all_ins();
298
	}
299
	return;
2 7u83 300
}
301
 
302
 
303
/*
304
    CREATE A LABEL
305
 
306
    A label is added to the list of all instructions.  This has the effect
307
    of marking all registers as changed.
308
*/
309
 
7 7u83 310
void
311
make_label(long n)
2 7u83 312
{
7 7u83 313
	mach_op *p = new_mach_op();
314
	p->type = MACH_LABQ;
315
	p->def.num = n;
316
	make_instr_aux(m_label_ins, p, null,(bitpattern)0xffff, 0);
317
	have_cond = 0;
2 7u83 318
#ifdef EBUG
7 7u83 319
	if (seek_label && n == (long)seek_label_no) {
320
		warning("Label %ld used", n);
321
		breakpoint();
322
	}
2 7u83 323
#endif
7 7u83 324
	return;
2 7u83 325
}
326
 
327
#ifdef EBUG
328
 
7 7u83 329
void
330
make_comment(char* comment)
2 7u83 331
{
7 7u83 332
	mach_op *p;
2 7u83 333
 
7 7u83 334
	p = new_mach_op();
335
	p->type = MACH_COMMENT;
336
	p->def.str = comment;
337
	make_instr_aux(m_comment, p, null,(bitpattern)0x0000, 0);
2 7u83 338
 
7 7u83 339
	return;
2 7u83 340
}
341
#endif
342
 
343
/*
344
    CREATE AN EXTERNAL LABEL
345
 
346
    An external label is added to the list of all instructions.  This has
347
    the effect of marking all registers as changed.
348
*/
349
 
7 7u83 350
void
351
make_external_label(char *nm)
2 7u83 352
{
7 7u83 353
	mach_op *p = new_mach_op();
354
	p->type = MACH_EXTQ;
355
	p->def.str = nm;
356
	make_instr_aux(m_extern_ins, p, null,(bitpattern)0xffff, 0);
357
	have_cond = 0;
2 7u83 358
#ifdef EBUG
7 7u83 359
	if (seek_extern && eq(nm, seek_extern_id)) {
360
		warning("Label %s used", nm);
361
		breakpoint();
362
	}
2 7u83 363
#endif
7 7u83 364
	return;
2 7u83 365
}
366
 
367
 
368
/*
369
    CREATE A JUMP
370
 
371
    A jump, instruction number insno, to label n, is added to the list
372
    of all instructions.
373
*/
374
 
7 7u83 375
void
376
make_jump(int insno, long n)
2 7u83 377
{
7 7u83 378
	mach_op *p = new_mach_op();
379
	p->type = MACH_LABQ;
380
	p->def.num = n;
381
	make_instr_aux(insno, p, null,(bitpattern)0, 0);
382
	if (n != last_jump) {
383
		last_jump = n;
384
		last_jump_regs = 0;
385
	}
386
	return;
2 7u83 387
}
388
 
389
 
390
/*
391
    SET A SPECIAL LABEL VALUE
392
 
393
    The special label with identifier nm is set equal to the given value.
394
*/
395
 
7 7u83 396
void
397
set_special(char *nm, mach_op *op)
2 7u83 398
{
7 7u83 399
	mach_op *op1 = make_special_data(nm);
400
	make_instr_aux(m_as_assign, op1, op,(bitpattern)0, 0);
401
	return;
2 7u83 402
}
403
 
404
 
405
/*
406
    OUTPUT AN IDENTIFICATION OF TWO NAMES
407
 
408
    This is not required, since all link information is known by the
409
    time I get round to code production.
410
*/
411
 
7 7u83 412
void
413
out_rename(char *old_nm, char *nm)
2 7u83 414
{
415
#if 0
7 7u83 416
	mach_op *op1 = make_extern_data(old_nm, 0);
417
	mach_op *op2 = make_extern_data(nm, 0);
418
	make_instr_aux(m_as_assign, op1, op2, 0, 0);
2 7u83 419
#endif
7 7u83 420
	return;
2 7u83 421
}