Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
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
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
29
 
59
 
30
 
60
 
31
#include "config.h"
61
#include "config.h"
32
#include "types.h"
62
#include "types.h"
-
 
63
#include "alignment.h"
33
#include "check.h"
64
#include "check.h"
34
#include "node.h"
65
#include "node.h"
35
#include "shape.h"
66
#include "shape.h"
36
#include "table.h"
67
#include "table.h"
37
#include "tdf.h"
68
#include "tdf.h"
Line 42... Line 73...
42
    BASIC ALIGNMENTS
73
    BASIC ALIGNMENTS
43
 
74
 
44
    These are the basic alignments from the TDF specification.
75
    These are the basic alignments from the TDF specification.
45
*/
76
*/
46
 
77
 
47
node *al_code = null ;
78
node *al_code = null;
48
node *al_frame =  null ;
79
node *al_frame =  null;
49
node *al_alloca = null ;
80
node *al_alloca = null;
50
node *al_var_param = null ;
81
node *al_var_param = null;
51
node *al_top =  null ;
82
node *al_top =  null;
52
static node *al_offset = null ;
83
static node *al_offset = null;
53
static node *al_pointer = null ;
84
static node *al_pointer = null;
54
static node *al_proc = null ;
85
static node *al_proc = null;
55
 
86
 
56
 
87
 
57
/*
88
/*
58
    FIND THE ALIGNMENT OF A SHAPE
89
    FIND THE ALIGNMENT OF A SHAPE
59
 
90
 
60
    For the node p, representing a shape or an alignment, this returns
91
    For the node p, representing a shape or an alignment, this returns
61
    the alignment of p.
92
    the alignment of p.
62
*/
93
*/
63
 
94
 
64
node *al_shape
95
node *
65
    PROTO_N ( ( p ) )
-
 
66
    PROTO_T ( node *p )
96
al_shape(node *p)
67
{
97
{
68
    node *q ;
98
    node *q;
69
    sortname s ;
99
    sortname s;
70
    if ( p == null ) return ( null ) ;
100
    if (p == null) return(null);
71
    s = p->cons->sortnum ;
101
    s = p->cons->sortnum;
72
    if ( s == SORT_alignment ) {
102
    if (s == SORT_alignment) {
73
	switch ( p->cons->encoding ) {
103
	switch (p->cons->encoding) {
74
	    case ENC_alignment : {
104
	    case ENC_alignment: {
75
		return ( al_shape ( p->son ) ) ;
105
		return(al_shape(p->son));
76
	    }
106
	    }
77
	    case ENC_alignment_apply_token : {
107
	    case ENC_alignment_apply_token: {
78
		return ( al_shape ( expand_tok ( p ) ) ) ;
108
		return(al_shape(expand_tok(p)));
79
	    }
109
	    }
80
	}
110
	}
81
	return ( copy_node ( p ) ) ;
111
	return(copy_node(p));
82
    }
112
    }
83
    if ( s == SORT_shape ) {
113
    if (s == SORT_shape) {
84
	switch ( p->cons->encoding ) {
114
	switch (p->cons->encoding) {
85
	    case ENC_bottom : {
115
	    case ENC_bottom: {
86
		is_fatal = 0 ;
116
		is_fatal = 0;
87
		input_error ( "Can't have alignment of bottom in %s",
117
		input_error("Can't have alignment of bottom in %s",
88
			      checking ) ;
118
			      checking);
89
		return ( null ) ;
119
		return(null);
90
	    }
120
	    }
91
	    case ENC_offset : return ( copy_node ( al_offset ) ) ;
121
	    case ENC_offset: return(copy_node(al_offset));
92
	    case ENC_pointer : return ( copy_node ( al_pointer ) ) ;
122
	    case ENC_pointer: return(copy_node(al_pointer));
93
	    case ENC_proc : return ( copy_node ( al_proc ) ) ;
123
	    case ENC_proc: return(copy_node(al_proc));
94
	    case ENC_top : return ( copy_node ( al_top ) ) ;
124
	    case ENC_top: return(copy_node(al_top));
95
	    case ENC_nof : return ( al_shape ( p->son->bro ) ) ;
125
	    case ENC_nof: return(al_shape(p->son->bro));
96
	    case ENC_shape_apply_token : {
126
	    case ENC_shape_apply_token: {
97
		return ( al_shape ( expand_tok ( p ) ) ) ;
127
		return(al_shape(expand_tok(p)));
98
	    }
128
	    }
99
	}
129
	}
100
    }
130
    }
101
    q = new_node () ;
131
    q = new_node();
102
    q->cons = cons_no ( SORT_alignment, ENC_alignment ) ;
132
    q->cons = cons_no(SORT_alignment, ENC_alignment);
103
    q->son = copy_node ( p ) ;
133
    q->son = copy_node(p);
104
    return ( null ) ;
134
    return(null);
105
}
135
}
106
 
136
 
107
 
137
 
108
/*
138
/*
109
    FIND WHAT A POINTER POINTS TO
139
    FIND WHAT A POINTER POINTS TO
110
 
140
 
111
    For the node p of the form ( pointer a ) this routine returns a.
141
    For the node p of the form ( pointer a ) this routine returns a.
112
*/
142
*/
113
 
143
 
114
node *ptr_to
144
node *
115
    PROTO_N ( ( p ) )
-
 
116
    PROTO_T ( node *p )
145
ptr_to(node *p)
117
{
146
{
118
    p = expand_tok ( p ) ;
147
    p = expand_tok(p);
119
    if ( p && p->cons == cons_no ( SORT_shape, ENC_pointer ) ) {
148
    if (p && p->cons == cons_no(SORT_shape, ENC_pointer)) {
120
	return ( p->son ) ;
149
	return(p->son);
121
    }
150
    }
122
    return ( null ) ;
151
    return(null);
123
}
152
}
124
 
153
 
125
 
154
 
126
/*
155
/*
127
    FIND THE FIRST COMPONENT OF AN OFFSET
156
    FIND THE FIRST COMPONENT OF AN OFFSET
128
 
157
 
129
    For the node p of the form ( offset a b ) this routine returns a.
158
    For the node p of the form ( offset a b ) this routine returns a.
130
*/
159
*/
131
 
160
 
132
node *offset_from
161
node *
133
    PROTO_N ( ( p ) )
-
 
134
    PROTO_T ( node *p )
162
offset_from(node *p)
135
{
163
{
136
    p = expand_tok ( p ) ;
164
    p = expand_tok(p);
137
    if ( p && p->cons == cons_no ( SORT_shape, ENC_offset ) ) {
165
    if (p && p->cons == cons_no(SORT_shape, ENC_offset)) {
138
	return ( p->son ) ;
166
	return(p->son);
139
    }
167
    }
140
    return ( null ) ;
168
    return(null);
141
}
169
}
142
 
170
 
143
 
171
 
144
/*
172
/*
145
    FIND THE SECOND COMPONENT OF AN OFFSET
173
    FIND THE SECOND COMPONENT OF AN OFFSET
146
 
174
 
147
    For the node p of the form ( offset a b ) this routine returns b.
175
    For the node p of the form ( offset a b ) this routine returns b.
148
*/
176
*/
149
 
177
 
150
node *offset_to
178
node *
151
    PROTO_N ( ( p ) )
-
 
152
    PROTO_T ( node *p )
179
offset_to(node *p)
153
{
180
{
154
    p = expand_tok ( p ) ;
181
    p = expand_tok(p);
155
    if ( p && p->cons == cons_no ( SORT_shape, ENC_offset ) ) {
182
    if (p && p->cons == cons_no(SORT_shape, ENC_offset)) {
156
	return ( p->son->bro ) ;
183
	return(p->son->bro);
157
    }
184
    }
158
    return ( null ) ;
185
    return(null);
159
}
186
}
160
 
187
 
161
 
188
 
162
/*
189
/*
163
    CHECK THAT TWO ALIGNMENTS ARE EQUAL
190
    CHECK THAT TWO ALIGNMENTS ARE EQUAL
164
 
191
 
165
    This routine is not yet implemented.
192
    This routine is not yet implemented.
166
*/
193
*/
167
 
194
 
168
void al_equals
195
void
169
    PROTO_N ( ( p, q ) )
-
 
170
    PROTO_T ( node *p X node *q )
196
al_equals(node *p, node *q)
171
{
197
{
172
    UNUSED ( p ) ;
198
    UNUSED(p);
173
    UNUSED ( q ) ;
199
    UNUSED(q);
174
    return ;
200
    return;
175
}
201
}
176
 
202
 
177
 
203
 
178
/*
204
/*
179
    CHECK THAT ONE ALIGNMENT CONTAINS ANOTHER
205
    CHECK THAT ONE ALIGNMENT CONTAINS ANOTHER
180
 
206
 
181
    This routine is not yet implemented.
207
    This routine is not yet implemented.
182
*/
208
*/
183
 
209
 
184
void al_includes
210
void
185
    PROTO_N ( ( p, q ) )
-
 
186
    PROTO_T ( node *p X node *q )
211
al_includes(node *p, node *q)
187
{
212
{
188
    UNUSED ( p ) ;
213
    UNUSED(p);
189
    UNUSED ( q ) ;
214
    UNUSED(q);
190
    return ;
215
    return;
191
}
216
}
192
 
217
 
193
 
218
 
194
/*
219
/*
195
    FIND THE UNIONS OF TWO ALIGNMENTS
220
    FIND THE UNIONS OF TWO ALIGNMENTS
196
 
221
 
197
    The value of ( unite_alignments p q ) is returned.
222
    The value of ( unite_alignments p q ) is returned.
198
*/
223
*/
199
 
224
 
200
node *al_union
225
node *
201
    PROTO_N ( ( p, q ) )
-
 
202
    PROTO_T ( node *p X node *q )
226
al_union(node *p, node *q)
203
{
227
{
204
    if ( p == null || p->cons->sortnum != SORT_alignment ) return ( null ) ;
228
    if (p == null || p->cons->sortnum != SORT_alignment) return(null);
205
    if ( q == null || q->cons->sortnum != SORT_alignment ) return ( null ) ;
229
    if (q == null || q->cons->sortnum != SORT_alignment) return(null);
206
    if ( p->cons->encoding == ENC_alignment &&
230
    if (p->cons->encoding == ENC_alignment &&
207
	 p->son->cons == cons_no ( SORT_shape, ENC_top ) ) return ( q ) ;
231
	 p->son->cons == cons_no(SORT_shape, ENC_top)) return(q);
208
    if ( q->cons->encoding == ENC_alignment &&
232
    if (q->cons->encoding == ENC_alignment &&
209
	 q->son->cons == cons_no ( SORT_shape, ENC_top ) ) return ( p ) ;
233
	 q->son->cons == cons_no(SORT_shape, ENC_top)) return(p);
210
    return ( null ) ;
234
    return(null);
211
}
235
}
212
 
236
 
213
 
237
 
214
/*
238
/*
215
    INITIALIZE BASIC ALIGNMENTS
239
    INITIALIZE BASIC ALIGNMENTS
216
 
240
 
217
    The basic alignments, al_top, al_offset, al_pointer and al_proc, are
241
    The basic alignments, al_top, al_offset, al_pointer and al_proc, are
218
    initialized.
242
    initialized.
219
*/
243
*/
220
 
244
 
-
 
245
void
221
void init_alignments
246
init_alignments(void)
222
    PROTO_Z ()
-
 
223
{
247
{
224
    /* Set up al_top */
248
    /* Set up al_top */
225
    al_top =  new_node () ;
249
    al_top =  new_node();
226
    al_top->cons = cons_no ( SORT_alignment, ENC_alignment ) ;
250
    al_top->cons = cons_no(SORT_alignment, ENC_alignment);
227
    al_top->son = copy_node ( sh_top ) ;
251
    al_top->son = copy_node(sh_top);
228
 
252
 
229
    /* Set up al_offset */
253
    /* Set up al_offset */
230
    al_offset =  new_node () ;
254
    al_offset =  new_node();
231
    al_offset->cons = cons_no ( SORT_alignment, ENC_alignment ) ;
255
    al_offset->cons = cons_no(SORT_alignment, ENC_alignment);
232
    al_offset->son = sh_offset ( al_top, al_top ) ;
256
    al_offset->son = sh_offset(al_top, al_top);
233
 
257
 
234
    /* Set up al_pointer */
258
    /* Set up al_pointer */
235
    al_pointer =  new_node () ;
259
    al_pointer =  new_node();
236
    al_pointer->cons = cons_no ( SORT_alignment, ENC_alignment ) ;
260
    al_pointer->cons = cons_no(SORT_alignment, ENC_alignment);
237
    al_pointer->son = sh_pointer ( al_top ) ;
261
    al_pointer->son = sh_pointer(al_top);
238
 
262
 
239
    /* Set up al_proc */
263
    /* Set up al_proc */
240
    al_proc =  new_node () ;
264
    al_proc =  new_node();
241
    al_proc->cons = cons_no ( SORT_alignment, ENC_alignment ) ;
265
    al_proc->cons = cons_no(SORT_alignment, ENC_alignment);
242
    al_proc->son = copy_node ( sh_proc ) ;
266
    al_proc->son = copy_node(sh_proc);
243
    return ;
267
    return;
244
}
268
}