Subversion Repositories tendra.SVN

Rev

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