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

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/algol60/src/tools/tnc/alignment.c – Rev 7

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
/*
7 7u83 2
 * Copyright (c) 2002-2005 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) 1997
7 7u83 33
 
2 7u83 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:-
7 7u83 42
 
2 7u83 43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
7 7u83 45
 
2 7u83 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;
7 7u83 49
 
2 7u83 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;
7 7u83 53
 
2 7u83 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
 
61
#include "config.h"
62
#include "types.h"
7 7u83 63
#include "alignment.h"
2 7u83 64
#include "check.h"
65
#include "node.h"
66
#include "shape.h"
67
#include "table.h"
68
#include "tdf.h"
69
#include "utility.h"
70
 
71
 
72
/*
73
    BASIC ALIGNMENTS
74
 
75
    These are the basic alignments from the TDF specification.
76
*/
77
 
7 7u83 78
node *al_code = null;
79
node *al_frame =  null;
80
node *al_alloca = null;
81
node *al_var_param = null;
82
node *al_top =  null;
83
static node *al_offset = null;
84
static node *al_pointer = null;
85
static node *al_proc = null;
2 7u83 86
 
87
 
88
/*
89
    FIND THE ALIGNMENT OF A SHAPE
90
 
91
    For the node p, representing a shape or an alignment, this returns
92
    the alignment of p.
93
*/
94
 
7 7u83 95
node *
96
al_shape(node *p)
2 7u83 97
{
7 7u83 98
    node *q;
99
    sortname s;
100
    if (p == null) return(null);
101
    s = p->cons->sortnum;
102
    if (s == SORT_alignment) {
103
	switch (p->cons->encoding) {
104
	    case ENC_alignment: {
105
		return(al_shape(p->son));
2 7u83 106
	    }
7 7u83 107
	    case ENC_alignment_apply_token: {
108
		return(al_shape(expand_tok(p)));
2 7u83 109
	    }
110
	}
7 7u83 111
	return(copy_node(p));
2 7u83 112
    }
7 7u83 113
    if (s == SORT_shape) {
114
	switch (p->cons->encoding) {
115
	    case ENC_bottom: {
116
		is_fatal = 0;
117
		input_error("Can't have alignment of bottom in %s",
118
			      checking);
119
		return(null);
2 7u83 120
	    }
7 7u83 121
	    case ENC_offset: return(copy_node(al_offset));
122
	    case ENC_pointer: return(copy_node(al_pointer));
123
	    case ENC_proc: return(copy_node(al_proc));
124
	    case ENC_top: return(copy_node(al_top));
125
	    case ENC_nof: return(al_shape(p->son->bro));
126
	    case ENC_shape_apply_token: {
127
		return(al_shape(expand_tok(p)));
2 7u83 128
	    }
129
	}
130
    }
7 7u83 131
    q = new_node();
132
    q->cons = cons_no(SORT_alignment, ENC_alignment);
133
    q->son = copy_node(p);
134
    return(null);
2 7u83 135
}
136
 
137
 
138
/*
139
    FIND WHAT A POINTER POINTS TO
140
 
141
    For the node p of the form ( pointer a ) this routine returns a.
142
*/
143
 
7 7u83 144
node *
145
ptr_to(node *p)
2 7u83 146
{
7 7u83 147
    p = expand_tok(p);
148
    if (p && p->cons == cons_no(SORT_shape, ENC_pointer)) {
149
	return(p->son);
2 7u83 150
    }
7 7u83 151
    return(null);
2 7u83 152
}
153
 
154
 
155
/*
156
    FIND THE FIRST COMPONENT OF AN OFFSET
157
 
158
    For the node p of the form ( offset a b ) this routine returns a.
159
*/
160
 
7 7u83 161
node *
162
offset_from(node *p)
2 7u83 163
{
7 7u83 164
    p = expand_tok(p);
165
    if (p && p->cons == cons_no(SORT_shape, ENC_offset)) {
166
	return(p->son);
2 7u83 167
    }
7 7u83 168
    return(null);
2 7u83 169
}
170
 
171
 
172
/*
173
    FIND THE SECOND COMPONENT OF AN OFFSET
174
 
175
    For the node p of the form ( offset a b ) this routine returns b.
176
*/
177
 
7 7u83 178
node *
179
offset_to(node *p)
2 7u83 180
{
7 7u83 181
    p = expand_tok(p);
182
    if (p && p->cons == cons_no(SORT_shape, ENC_offset)) {
183
	return(p->son->bro);
2 7u83 184
    }
7 7u83 185
    return(null);
2 7u83 186
}
187
 
188
 
189
/*
190
    CHECK THAT TWO ALIGNMENTS ARE EQUAL
191
 
192
    This routine is not yet implemented.
193
*/
194
 
7 7u83 195
void
196
al_equals(node *p, node *q)
2 7u83 197
{
7 7u83 198
    UNUSED(p);
199
    UNUSED(q);
200
    return;
2 7u83 201
}
202
 
203
 
204
/*
205
    CHECK THAT ONE ALIGNMENT CONTAINS ANOTHER
206
 
207
    This routine is not yet implemented.
208
*/
209
 
7 7u83 210
void
211
al_includes(node *p, node *q)
2 7u83 212
{
7 7u83 213
    UNUSED(p);
214
    UNUSED(q);
215
    return;
2 7u83 216
}
217
 
218
 
219
/*
220
    FIND THE UNIONS OF TWO ALIGNMENTS
221
 
222
    The value of ( unite_alignments p q ) is returned.
223
*/
224
 
7 7u83 225
node *
226
al_union(node *p, node *q)
2 7u83 227
{
7 7u83 228
    if (p == null || p->cons->sortnum != SORT_alignment) return(null);
229
    if (q == null || q->cons->sortnum != SORT_alignment) return(null);
230
    if (p->cons->encoding == ENC_alignment &&
231
	 p->son->cons == cons_no(SORT_shape, ENC_top)) return(q);
232
    if (q->cons->encoding == ENC_alignment &&
233
	 q->son->cons == cons_no(SORT_shape, ENC_top)) return(p);
234
    return(null);
2 7u83 235
}
236
 
237
 
238
/*
239
    INITIALIZE BASIC ALIGNMENTS
240
 
241
    The basic alignments, al_top, al_offset, al_pointer and al_proc, are
242
    initialized.
243
*/
244
 
7 7u83 245
void
246
init_alignments(void)
2 7u83 247
{
248
    /* Set up al_top */
7 7u83 249
    al_top =  new_node();
250
    al_top->cons = cons_no(SORT_alignment, ENC_alignment);
251
    al_top->son = copy_node(sh_top);
2 7u83 252
 
253
    /* Set up al_offset */
7 7u83 254
    al_offset =  new_node();
255
    al_offset->cons = cons_no(SORT_alignment, ENC_alignment);
256
    al_offset->son = sh_offset(al_top, al_top);
2 7u83 257
 
258
    /* Set up al_pointer */
7 7u83 259
    al_pointer =  new_node();
260
    al_pointer->cons = cons_no(SORT_alignment, ENC_alignment);
261
    al_pointer->son = sh_pointer(al_top);
2 7u83 262
 
263
    /* Set up al_proc */
7 7u83 264
    al_proc =  new_node();
265
    al_proc->cons = cons_no(SORT_alignment, ENC_alignment);
266
    al_proc->son = copy_node(sh_proc);
267
    return;
2 7u83 268
}