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
/*** tdf-write.c --- TDF writer ADT.
32
 *
33
 ** Author: Steve Folkes <smf@hermes.mod.uk>
34
 *
35
 *** Commentary:
36
 *
37
 * This file implements the TDF writer routines used by the TDF linker.
38
 *
39
 *** Change Log:
40
 * $Log: tdf-write.c,v $
41
 * Revision 1.1.1.1  1998/01/17  15:57:20  release
42
 * First version to be checked into rolling release.
43
 *
44
 * Revision 1.3  1995/09/22  08:39:40  smf
45
 * Fixed problems with incomplete structures (to shut "tcc" up).
46
 * Fixed some problems in "name-key.c" (no real problems, but rewritten to
47
 * reduce the warnings that were output by "tcc" and "gcc").
48
 * Fixed bug CR95_354.tld-common-id-problem (library capsules could be loaded
49
 * more than once).
50
 *
51
 * Revision 1.2  1994/12/12  11:46:58  smf
52
 * Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
53
 * OSSG C Coding Standards.
54
 *
55
 * Revision 1.1.1.1  1994/07/25  16:03:39  smf
56
 * Initial import of TDF linker 3.5 non shared files.
57
 *
58
**/
59
 
60
/****************************************************************************/
61
 
62
#include "tdf-write.h"
63
#include "gen-errors.h"
64
#include "ostream.h"
65
 
66
#include "solve-cycles.h"
67
 
68
/*--------------------------------------------------------------------------*/
69
 
70
static void
71
tdf_write_nibble PROTO_N ((writer, nibble))
72
		 PROTO_T (TDFWriterP writer X
73
			  unsigned   nibble)
74
{
75
    if (writer->new_byte) {
76
	writer->new_byte = FALSE;
77
	writer->byte     = (ByteT) ((nibble & 0x0F) << 4);
78
    } else {
79
	writer->new_byte = TRUE;
80
	writer->byte    |= (ByteT) (nibble & 0x0F);
81
	bostream_write_byte (&(writer->bostream), writer->byte);
82
    }
83
}
84
 
85
/*--------------------------------------------------------------------------*/
86
 
87
BoolT
88
tdf_writer_open PROTO_N ((writer, name))
89
		PROTO_T (TDFWriterP writer X
90
			 CStringP   name)
91
{
92
    writer->new_byte = TRUE;
93
    if (!bostream_open (&(writer->bostream), name)) {
94
	return (FALSE);
95
    }
96
    return (TRUE);
97
}
98
 
99
CStringP
100
tdf_writer_name PROTO_N ((writer))
101
		PROTO_T (TDFWriterP writer)
102
{
103
    return (bostream_name (&(writer->bostream)));
104
}
105
 
106
void
107
tdf_write_int PROTO_N ((writer, value))
108
	      PROTO_T (TDFWriterP writer X
109
		       unsigned   value)
110
{
111
    unsigned shift = 0;
112
    unsigned tmp   = value;
113
    unsigned mask  = (~(unsigned) 0x07);
114
 
115
    while (tmp & mask) {
116
	tmp >>= 3;
117
	shift ++;
118
    }
119
    while (shift) {
120
	tmp = ((value >> (3 * shift)) & 0x07);
121
	shift --;
122
	tdf_write_nibble (writer, tmp);
123
    }
124
    tmp = ((value & 0x07) | 0x08);
125
    tdf_write_nibble (writer, tmp);
126
}
127
 
128
void
129
tdf_write_align PROTO_N ((writer))
130
		PROTO_T (TDFWriterP writer)
131
{
132
    if (!(writer->new_byte)) {
133
	bostream_write_byte (&(writer->bostream), writer->byte);
134
	writer->new_byte = TRUE;
135
    }
136
}
137
 
138
void
139
tdf_write_bytes PROTO_N ((writer, nstring))
140
		PROTO_T (TDFWriterP writer X
141
			 NStringP   nstring)
142
{
143
    unsigned length   = nstring_length (nstring);
144
    CStringP contents = nstring_contents (nstring);
145
 
146
    tdf_write_align (writer);
147
    bostream_write_chars (&(writer->bostream), length, contents);
148
}
149
 
150
void
151
tdf_write_string PROTO_N ((writer, nstring))
152
		 PROTO_T (TDFWriterP writer X
153
			  NStringP   nstring)
154
{
155
    unsigned length = nstring_length (nstring);
156
 
157
    tdf_write_int (writer, (unsigned) 8);
158
    tdf_write_int (writer, length);
159
    tdf_write_bytes (writer, nstring);
160
}
161
 
162
void
163
tdf_write_name PROTO_N ((writer, name))
164
	       PROTO_T (TDFWriterP writer X
165
			NameKeyP   name)
166
{
167
    unsigned  type;
168
    unsigned  components;
169
    unsigned  i;
170
    NStringP  nstring;
171
 
172
    switch (name_key_type (name)) EXHAUSTIVE {
173
      case KT_STRING:
174
	type = (unsigned) (0x1 << 2);
175
	tdf_write_nibble (writer, type);
176
	tdf_write_align (writer);
177
	tdf_write_string (writer, name_key_string (name));
178
	break;
179
      case KT_UNIQUE:
180
	type = (unsigned) (0x2 << 2);
181
	tdf_write_nibble (writer, type);
182
	tdf_write_align (writer);
183
	components = name_key_components (name);
184
	tdf_write_int (writer, components);
185
	for (i = 0; i < components; i ++) {
186
	    nstring = name_key_get_component (name, i);
187
	    tdf_write_string (writer, nstring);
188
	}
189
	break;
190
    }
191
}
192
 
193
void
194
tdf_writer_close PROTO_N ((writer))
195
		 PROTO_T (TDFWriterP writer)
196
{
197
    tdf_write_align (writer);
198
    bostream_close (&(writer->bostream));
199
}
200
 
201
/*
202
 * Local variables(smf):
203
 * eval: (include::add-path-entry "../os-interface" "../library")
204
 * eval: (include::add-path-entry "../generated")
205
 * end:
206
**/