annotate dmd/Library.d @ 178:e3afd1303184

Many small bugs fixed Made all classes derive from TObject to detect memory leaks (functionality is disabled for now) Began work on overriding backend memory allocations (to avoid memory leaks)
author korDen
date Sun, 17 Oct 2010 07:42:00 +0400
parents e7769d53e750
children 190ba98276b3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.Library;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 14
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.File;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.StringTable;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.ObjModule;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.String;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.File;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.FileName;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.StringValue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.String;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import core.stdc.string;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import core.stdc.stdlib;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import std.string;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21
4
d706d958e4e8 Step 2 of restoring GC functionality.
korDen
parents: 2
diff changeset
22 import core.memory;
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
23
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 align(1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 struct LibHeader
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 ubyte recTyp; // 0xF0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 ushort pagesize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 int lSymSeek;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 ushort ndicpages;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 ubyte flags;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 align(1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 struct Libheader
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 ubyte recTyp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 ushort recLen;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 int trailerPosn;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 ushort ndicpages;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 ubyte flags;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 char[6] filler;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 struct ObjSymbol
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 string name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 ObjModule* om;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 /**************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 * Record types:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 enum HASHMOD = 0x25;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 enum BUCKETPAGE = 512;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 enum BUCKETSIZE = (BUCKETPAGE - HASHMOD - 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 /+
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 #define RHEADR 0x6E
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 #define REGINT 0x70
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 #define REDATA 0x72
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 #define RIDATA 0x74
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 #define OVLDEF 0x76
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 #define ENDREC 0x78
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 #define BLKDEF 0x7A
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 #define BLKEND 0x7C
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 #define DEBSYM 0x7E
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 +/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 enum THEADR = 0x80;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 enum LHEADR = 0x82;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 /+#define PEDATA 0x84
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 #define PIDATA 0x86
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 +/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 enum COMENT = 0x88;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 enum MODEND = 0x8A;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 enum M386END = 0x8B; /* 32 bit module end record */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 /+
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 #define EXTDEF 0x8C
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 #define TYPDEF 0x8E
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 +/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 enum PUBDEF = 0x90;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 enum PUB386 = 0x91;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 /+
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 #define LOCSYM 0x92
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 #define LINNUM 0x94
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 +/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 enum LNAMES = 0x96;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 /+
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 #define SEGDEF 0x98
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 #define GRPDEF 0x9A
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 #define FIXUPP 0x9C
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 /*#define (none) 0x9E */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 #define LEDATA 0xA0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 #define LIDATA 0xA2
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 #define LIBHED 0xA4
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 #define LIBNAM 0xA6
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 #define LIBLOC 0xA8
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 #define LIBDIC 0xAA
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 #define COMDEF 0xB0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 #define LEXTDEF 0xB4
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 #define LPUBDEF 0xB6
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 #define LCOMDEF 0xB8
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 #define CEXTDEF 0xBC
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 +/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 enum COMDAT = 0xC2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 /+#define LINSYM 0xC4
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 +/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 enum ALIAS = 0xC6;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 enum LLNAMES = 0xCA;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 enum LIBIDMAX = (512 - 0x25 - 3 - 4); // max size that will fit in dictionary
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 extern (C) extern char* strdup(const(char)* ptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 static uint parseName(ubyte** pp, char* name)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 ubyte* p = *pp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 uint len = *p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 if (len == 0xFF && *p == 0) // if long name
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 len = p[1] & 0xFF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 len |= cast(uint)p[2] << 8;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 p += 3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 assert(len <= LIBIDMAX);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 memcpy(name, p, len);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 name[len] = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 *pp = p + len;
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
133
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 return len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 static ushort parseIdx(ubyte** pp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 ubyte* p = *pp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 ubyte c = *p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 ushort idx = cast(ushort)((0x80 & c) ? ((0x7F & c) << 8) + *p++ : c);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 *pp = p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 return idx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 extern (C) int D_NameCompare(const(void*) a, const(void*) b)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 ObjSymbol** p1 = cast(ObjSymbol**)a;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 ObjSymbol** p2 = cast(ObjSymbol**)b;
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
151
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 return cmp((*p1).name, (*p2).name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 }
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
154 version (Windows)
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
155 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 * Write a single entry into dictionary.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 * 0 failure
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 */
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
161
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 extern (C) extern uint _rotl(uint value, int shift);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 extern (C) extern uint _rotr(uint value, int shift);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 static int EnterDict(ubyte* bucketsP, ushort ndicpages, ubyte* entry, uint entrylen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 ushort uStartIndex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 ushort uStep;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 ushort uStartPage;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 ushort uPageStep;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 ushort uIndex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 ushort uPage;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 ushort n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 uint u;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 uint nbytes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 ubyte* aP;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 ubyte* zP;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 aP = entry;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 zP = aP + entrylen; // point at last char in identifier
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 uStartPage = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 uPageStep = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 uStartIndex = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 uStep = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187 u = entrylen;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 while ( u-- )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 uStartPage = cast(ushort)_rotl( uStartPage, 2 ) ^ ( *aP | 0x20 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 uStep = cast(ushort)_rotr( uStep, 2 ) ^ ( *aP++ | 0x20 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 uStartIndex = cast(ushort)_rotr( uStartIndex, 2 ) ^ ( *zP | 0x20 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 uPageStep = cast(ushort)_rotl( uPageStep, 2 ) ^ ( *zP-- | 0x20 );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 uStartPage %= ndicpages;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 uPageStep %= ndicpages;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 if ( uPageStep == 0 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 uPageStep++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 uStartIndex %= HASHMOD;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 uStep %= HASHMOD;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 if ( uStep == 0 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 uStep++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 uPage = uStartPage;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 uIndex = uStartIndex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 // number of bytes in entry
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 nbytes = 1 + entrylen + 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 if (entrylen > 255)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 nbytes += 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 aP = &bucketsP[uPage * BUCKETPAGE];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 uStartIndex = uIndex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 if ( 0 == aP[ uIndex ] )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 // n = next available position in this page
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 n = aP[ HASHMOD ] << 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 assert(n > HASHMOD);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 // if off end of this page
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 if (n + nbytes > BUCKETPAGE )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 { aP[ HASHMOD ] = 0xFF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 break; // next page
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
231 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 aP[ uIndex ] = cast(ubyte)(n >> 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 memcpy( (aP + n), entry, nbytes );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 aP[ HASHMOD ] += (nbytes + 1) >> 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235 if (aP[HASHMOD] == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
236 aP[HASHMOD] = 0xFF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 uIndex += uStep;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241 uIndex %= 0x25;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 /*if (uIndex > 0x25)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 uIndex -= 0x25;*/
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 if( uIndex == uStartIndex )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 uPage += uPageStep;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 if (uPage >= ndicpages)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 uPage -= ndicpages;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 if( uPage == uStartPage )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
256
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
257 import dmd.TObject;
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
258
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
259 class Library : TObject
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
260 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
261 File libfile;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
262 Array objmodules; // ObjModule[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
263 Array objsymbols; // ObjSymbol[]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
264
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
265 StringTable tab;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
266
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
267 this()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
268 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
269 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
270 libfile = null;
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
271
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
272 objmodules = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
273 objsymbols = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
274 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
275
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
276 /***********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
277 * Set the library file name based on the output directory
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
278 * and the filename.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
279 * Add default library file name extension.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
280 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
281 void setFilename(string dir, string filename)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
282 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
283 string arg = filename;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
284 if (arg.length == 0)
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
285 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
286 // Generate lib file name from first obj name
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
287 string n = (cast(String)global.params.objfiles.data[0]).str;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
288
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
289 n = FileName.name(n);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
290 FileName fn = FileName.forceExt(n, global.lib_ext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
291 arg = fn.toChars();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
292 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
293 if (!FileName.absolute(arg))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
294 arg = FileName.combine(dir, arg);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
295
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
296 FileName libfilename = FileName.defaultExt(arg, global.lib_ext);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
297 libfile = new File(libfilename);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
298 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
299
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
300 /***************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
301 * Add object module or library to the library.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
302 * Examine the buffer to see which it is.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
303 * If the buffer is null, use module_name as the file name
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
304 * and load the file.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
305 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
306 void addObject(string module_name, void *buf, size_t buflen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
307 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
308 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
309 printf("Library.addObject(%s)\n", module_name ? module_name : "");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
310 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
311 if (!buf)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313 assert(module_name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
314 scope FileName f = new FileName(module_name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 scope File file = new File(f);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
316 file.readv();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
317 buf = file.buffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
318 buflen = file.len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
319 file.ref_ = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
320 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
321
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
322 uint g_page_size;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
323 ubyte* pstart = cast(ubyte*)buf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
324 int islibrary = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
325
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
326 /* See if it's an OMF library.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
327 * Don't go by file extension.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
328 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
329
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
330 /* Determine if it is an OMF library, an OMF object module,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
331 * or something else.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
332 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
333 if (buflen < LibHeader.sizeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
334 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 Lcorrupt:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336 error("corrupt object module");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
337 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 LibHeader* lh = cast(LibHeader*)buf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 if (lh.recTyp == 0xF0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 { /* OMF library
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 * The modules are all at buf[g_page_size .. lh.lSymSeek]
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 islibrary = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 g_page_size = lh.pagesize + 3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 buf = cast(void*)(pstart + g_page_size);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 if (lh.lSymSeek > buflen ||
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 g_page_size > buflen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 goto Lcorrupt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 buflen = lh.lSymSeek - g_page_size;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 else if (lh.recTyp == '!' && memcmp(lh, "!<arch>\n".ptr, 8) == 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 error("COFF libraries not supported");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
355 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 else
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
357 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 // Not a library, assume OMF object module
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359 g_page_size = 16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362 /* Split up the buffer buf[0..buflen] into multiple object modules,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 * each aligned on a g_page_size boundary.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 ObjModule* om = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 int first_module = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 ubyte* p = cast(ubyte*)buf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 ubyte* pend = p + buflen;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 ubyte* pnext;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 for (; p < pend; p = pnext) // for each OMF record
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 if (p + 3 >= pend)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 goto Lcorrupt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376 ubyte recTyp = *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 ushort recLen = *cast(ushort*)(p + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 pnext = p + 3 + recLen;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 if (pnext > pend)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380 goto Lcorrupt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 recLen--; /* forget the checksum */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383 switch (recTyp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 case LHEADR :
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 case THEADR :
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 if (!om)
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
388 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 char name[LIBIDMAX + 1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 om = new ObjModule();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 om.flags = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 om.base = p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 p += 3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 parseName(&p, name.ptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395 if (first_module && module_name && !islibrary)
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
396 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 // Remove path and extension
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 string fname = FileName.name(module_name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399 string ext = FileName.ext(fname);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 if (ext.length != 0) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 fname = fname[0..$-ext.length-1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 om.name = fname;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 else
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
407 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 /* Use THEADR name as module name,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 * removing path and extension.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 string fname = FileName.name(fromStringz(name.ptr));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 string ext = FileName.ext(fname);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 if (ext.length != 0) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 fname = fname[0..$-ext.length-1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 }
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
416
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 om.name = fname;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418 om.flags |= MFtheadr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 if (strcmp(name.ptr, "C".ptr) == 0) // old C compilers did this
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
421 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 om.flags |= MFgentheadr; // generate our own THEADR
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 om.base = pnext; // skip past THEADR
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 objmodules.push(cast(void*)om);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426 first_module = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 case MODEND :
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 case M386END:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 if (om)
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
433 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 om.page = cast(ushort)((om.base - pstart) / g_page_size);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435 om.length = pnext - om.base;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 om = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 // Round up to next page
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 uint t = pnext - pstart;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 t = (t + g_page_size - 1) & ~cast(uint)(g_page_size - 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 pnext = pstart + t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 break;
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
443
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 default:
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
445 // ignore
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 if (om)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 goto Lcorrupt; // missing MODEND record
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 void addLibrary(void *buf, size_t buflen)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 void write()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 if (global.params.verbose)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 writef("library %s\n", libfile.name.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 scope OutBuffer libbuf = new OutBuffer();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465 WriteLibToBuffer(libbuf);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 // Transfer image to file
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 libfile.setbuffer(libbuf.data, libbuf.offset);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469 libbuf.extractData();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 string p = FileName.path(libfile.name.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 FileName.ensurePathExists(p);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 libfile.writev();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477 private:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 void addSymbol(ObjModule* om, string name, int pickAny = 0)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 printf("Library.addSymbol(%s, %s, %d)\n", om.name, name, pickAny);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 }
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
483 Object* s = tab.insert(name);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 if (!s)
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
485 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 // already in table
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 if (!pickAny)
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
488 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 s = tab.lookup(name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 assert(s);
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
491 ObjSymbol* os = *cast(ObjSymbol**)s;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 error("multiple definition of %s: %s and %s: %s",
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 om.name, name, os.om.name, os.name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
496 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
497 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 ObjSymbol* os = new ObjSymbol();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 os.name = name;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 os.om = om;
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
501 *s = cast(Object)cast(void*)os; /// !!!!
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503 objsymbols.push(os);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 }
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
506
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 void scanObjModule(ObjModule* om)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 int easyomf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 uint u;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 ubyte result = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 char name[LIBIDMAX + 1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 scope Array names = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 names.push(null); // don't use index 0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 assert(om);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 easyomf = 0; // assume not EASY-OMF
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 ubyte* pend = om.base + om.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 ubyte* pnext;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522 for (ubyte* p = om.base; 1; p = pnext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 assert(p < pend);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 ubyte recTyp = *p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 ushort recLen = *cast(ushort*)p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 p += 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
528 pnext = p + recLen;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
529 recLen--; // forget the checksum
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
530
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
531 switch (recTyp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
532 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
533 case LNAMES:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
534 case LLNAMES:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
535 while (p + 1 < pnext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
536 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
537 uint len = parseName(&p, name.ptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
538 names.push(cast(void*)new String(name[0..len].idup));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
539 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
540 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
541
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
542 case PUBDEF:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
543 if (easyomf)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
544 recTyp = PUB386; // convert to MS format
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
545 case PUB386:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
546 if (!(parseIdx(&p) | parseIdx(&p)))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
547 p += 2; // skip seg, grp, frame
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
548 while (p + 1 < pnext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
549 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
550 uint len = parseName(&p, name.ptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
551 p += (recTyp == PUBDEF) ? 2 : 4; // skip offset
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
552 parseIdx(&p); // skip type index
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
553 addSymbol(om, name[0..len].idup);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
554 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
555 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
556
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
557 case COMDAT:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
558 if (easyomf)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
559 recTyp = COMDAT+1; // convert to MS format
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
560 case COMDAT+1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
561 int pickAny = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
562
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
563 if (*p++ & 5) // if continuation or local comdat
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
564 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
565
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
566 ubyte attr = *p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
567 if (attr & 0xF0) // attr: if multiple instances allowed
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
568 pickAny = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
569 p++; // align
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
570
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
571 p += 2; // enum data offset
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
572 if (recTyp == COMDAT+1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
573 p += 2; // enum data offset
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
574
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
575 parseIdx(&p); // type index
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
576
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
577 if ((attr & 0x0F) == 0) // if explicit allocation
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
578 { parseIdx(&p); // base group
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
579 parseIdx(&p); // base segment
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
580 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
581
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
582 uint idx = parseIdx(&p); // public name index
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
583 if( idx == 0 || idx >= names.dim)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
584 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
585 //debug(printf("[s] name idx=%d, uCntNames=%d\n", idx, uCntNames));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
586 error("corrupt COMDAT");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
587 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
588 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
589
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
590 //printf("[s] name='%s'\n",name);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
591 addSymbol(om, (cast(String)names.data[idx]).str, pickAny);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
592 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
593
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
594 case ALIAS:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
595 while (p + 1 < pnext)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
596 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
597 uint len = parseName(&p, name.ptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
598 addSymbol(om, name[0..len].idup);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
599 parseName(&p, name.ptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
600 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
601 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
602
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
603 case MODEND:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
604 case M386END:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
605 result = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
606 goto Ret;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
607
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
608 case COMENT:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
609 // Recognize Phar Lap EASY-OMF format
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
610 {
169
e7769d53e750 Moves static variables from Module to Global
korDen
parents: 114
diff changeset
611 enum ubyte[7] omfstr = [0x80,0xAA,'8','0','3','8','6'];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
612
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
613 if (recLen == omfstr.sizeof)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
614 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
615 for (uint i = 0; i < omfstr.sizeof; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
616 if (*p++ != omfstr[i])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
617 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
618 easyomf = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
619 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
620 L1: ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
621 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
622 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
623 // Recognize .IMPDEF Import Definition Records
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
624 {
169
e7769d53e750 Moves static variables from Module to Global
korDen
parents: 114
diff changeset
625 enum ubyte[3] omfstr = [0, 0xA0, 1];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
626
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
627 if (recLen >= 7)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
628 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
629 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
630 for (uint i = 1; i < omfstr.sizeof; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
631 if (*p++ != omfstr[i])
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
632 goto L2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
633 p++; // skip OrdFlag field
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
634 uint len = parseName(&p, name.ptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
635 addSymbol(om, name[0..len].idup);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
636 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
637 L2: ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
638 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
639 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
640 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
641
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
642 default:
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
643 // ignore
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
644 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
645 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
646 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
647
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
648 Ret:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
649 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
650 ///for (u = 1; u < names.dim; u++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
651 /// free(names.data[u]);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
652 }
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
653
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
654 /***********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
655 * Calculates number of pages needed for dictionary
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
656 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
657 * number of pages
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
658 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
659 ushort numDictPages(uint padding)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
660 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
661 ushort ndicpages;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
662 ushort bucksForHash;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
663 ushort bucksForSize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
664 uint symSize = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
665
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
666 for (int i = 0; i < objsymbols.dim; i++)
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
667 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
668 ObjSymbol* s = cast(ObjSymbol*)objsymbols.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
669 symSize += ( s.name.length + 4 ) & ~1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
670 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
671
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
672 for (int i = 0; i < objmodules.dim; i++)
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
673 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
674 ObjModule* om = cast(ObjModule*)objmodules.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
675
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
676 size_t len = om.name.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
677 if (len > 0xFF)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
678 len += 2; // Digital Mars long name extension
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
679 symSize += ( len + 4 + 1 ) & ~1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
680 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
681
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
682 bucksForHash = cast(ushort)((objsymbols.dim + objmodules.dim + HASHMOD - 3) / (HASHMOD - 2));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
683 bucksForSize = cast(ushort)((symSize + BUCKETSIZE - padding - padding - 1) / (BUCKETSIZE - padding));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
684
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
685 ndicpages = (bucksForHash > bucksForSize ) ? bucksForHash : bucksForSize;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
686 //printf("ndicpages = %u\n",ndicpages);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
687
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
688 // Find prime number greater than ndicpages
169
e7769d53e750 Moves static variables from Module to Global
korDen
parents: 114
diff changeset
689 enum uint[] primes =
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
690 [ 1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
691 47,53,59,61,67,71,73,79,83,89,97,101,103,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
692 107,109,113,127,131,137,139,149,151,157,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
693 163,167,173,179,181,191,193,197,199,211,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
694 223,227,229,233,239,241,251,257,263,269,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
695 271,277,281,283,293,307,311,313,317,331,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
696 337,347,349,353,359,367,373,379,383,389,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
697 397,401,409,419,421,431,433,439,443,449,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
698 457,461,463,467,479,487,491,499,503,509,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
699 //521,523,541,547,
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
700 0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
701 ];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
702
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
703 for (int i = 0; 1; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
704 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
705 if ( primes[i] == 0 )
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
706 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
707 // Quick and easy way is out.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
708 // Now try and find first prime number > ndicpages
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
709 uint prime;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
710
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
711 for (prime = (ndicpages + 1) | 1; 1; prime += 2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
712 { // Determine if prime is prime
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
713 for (uint u = 3; u < prime / 2; u += 2)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
714 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
715 if ((prime / u) * u == prime)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
716 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
717 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
718 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
719
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
720 L1: ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
721 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
722 ndicpages = cast(ushort)prime;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
723 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
724 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
725
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
726 if (primes[i] > ndicpages)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
727 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
728 ndicpages = cast(ushort)primes[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
729 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
730 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
731 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
732
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
733 return ndicpages;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
734 }
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
735
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
736 /*******************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
737 * Write the module and symbol names to the dictionary.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
738 * Returns:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
739 * 0 failure
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
740 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
741 int FillDict(ubyte* bucketsP, ushort ndicpages)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
742 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
743 ubyte entry[4 + LIBIDMAX + 2 + 1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
744
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
745 //printf("FillDict()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
746
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
747 // Add each of the module names
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
748 for (int i = 0; i < objmodules.dim; i++)
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
749 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
750 ObjModule* om = cast(ObjModule*)objmodules.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
751
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
752 ushort n = cast(ushort)om.name.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
753 if (n > 255)
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
754 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
755 entry[0] = 0xFF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
756 entry[1] = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
757 *cast(ushort*)(entry.ptr + 2) = cast(ushort)(n + 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
758 memcpy(entry.ptr + 4, om.name.ptr, n);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
759 n += 3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
760 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
761 else
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
762 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
763 entry[ 0 ] = cast(ubyte)(1 + n);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
764 memcpy(entry.ptr + 1, om.name.ptr, n );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
765 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
766 entry[ n + 1 ] = '!';
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
767 *(cast(ushort*)( n + 2 + entry.ptr )) = om.page;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
768 if ( n & 1 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
769 entry[ n + 2 + 2 ] = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
770 if ( !EnterDict( bucketsP, ndicpages, entry.ptr, n + 1 ) )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
771 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
772 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
773
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
774 // Sort the symbols
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
775 qsort( objsymbols.data, objsymbols.dim, 4, /*(cmpfunc_t)*/&D_NameCompare );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
776
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
777 // Add each of the symbols
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
778 for (int i = 0; i < objsymbols.dim; i++)
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
779 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
780 ObjSymbol* os = cast(ObjSymbol*)objsymbols.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
781
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
782 ushort n = cast(ushort)os.name.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
783 if (n > 255)
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
784 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
785 entry[0] = 0xFF;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
786 entry[1] = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
787 *cast(ushort*)(entry.ptr + 2) = n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
788 memcpy(entry.ptr + 4, os.name.ptr, n);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
789 n += 3;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
790 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
791 else
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
792 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
793 entry[ 0 ] = cast(ubyte)n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
794 memcpy( entry.ptr + 1, os.name.ptr, n );
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
795 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
796 *(cast(ushort*)( n + 1 + entry.ptr )) = os.om.page;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
797 if ( (n & 1) == 0 )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
798 entry[ n + 3] = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
799 if ( !EnterDict( bucketsP, ndicpages, entry.ptr, n ) )
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
800 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
801 return 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
802 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
803 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
804
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
805 return 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
806 }
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
807
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
808 /**********************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
809 * Create and write library to libbuf.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
810 * The library consists of:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
811 * library header
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
812 * object modules...
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
813 * dictionary header
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
814 * dictionary pages...
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
815 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
816 void WriteLibToBuffer(OutBuffer libbuf)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
817 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
818 /* Scan each of the object modules for symbols
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
819 * to go into the dictionary
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
820 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
821 for (int i = 0; i < objmodules.dim; i++)
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
822 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
823 ObjModule* om = cast(ObjModule*)objmodules.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
824 scanObjModule(om);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
825 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
826
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
827 uint g_page_size = 16;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
828
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
829 /* Calculate page size so that the number of pages
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
830 * fits in 16 bits. This is because object modules
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
831 * are indexed by page number, stored as an unsigned short.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
832 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
833 while (1)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
834 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
835 Lagain:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
836 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
837 printf("g_page_size = %d\n", g_page_size);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
838 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
839 uint offset = g_page_size;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
840
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
841 for (int i = 0; i < objmodules.dim; i++)
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
842 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
843 ObjModule* om = cast(ObjModule*)objmodules.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
844
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
845 uint page = offset / g_page_size;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
846 if (page > 0xFFFF)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
847 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
848 // Page size is too small, double it and try again
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
849 g_page_size *= 2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
850 goto Lagain;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
851 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
852
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
853 // Write out the object module m
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
854 if (om.flags & MFgentheadr) // if generate THEADR record
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
855 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
856 size_t size = om.name.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
857 assert(size <= LIBIDMAX);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
858
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
859 offset += size + 5;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
860 //offset += om.length - (size + 5);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
861 offset += om.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
862 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
863 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
864 offset += om.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
865
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
866 // Round the size of the file up to the next page size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
867 // by filling with 0s
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
868 uint n = (g_page_size - 1) & offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
869 if (n)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
870 offset += g_page_size - n;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
871 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
872 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
873 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
874
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
875
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
876 /* Leave one page of 0s at start as a dummy library header.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
877 * Fill it in later with the real data.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
878 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
879 libbuf.fill0(g_page_size);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
880
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
881 /* Write each object module into the library
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
882 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
883 for (int i = 0; i < objmodules.dim; i++)
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
884 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
885 ObjModule* om = cast(ObjModule*)objmodules.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
886
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
887 uint page = libbuf.offset / g_page_size;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
888 assert(page <= 0xFFFF);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
889 om.page = cast(ushort)page;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
890
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
891 // Write out the object module om
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
892 if (om.flags & MFgentheadr) // if generate THEADR record
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
893 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
894 uint size = om.name.length;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
895 ubyte header[4 + LIBIDMAX + 1];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
896
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
897 header [0] = THEADR;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
898 header [1] = cast(ubyte)(2 + size);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
899 header [2] = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
900 header [3] = cast(ubyte)size;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
901 assert(size <= 0xFF - 2);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
902
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
903 memcpy(4 + header.ptr, om.name.ptr, size);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
904
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
905 // Compute and store record checksum
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
906 uint n = size + 4;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
907 ubyte checksum = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
908 ubyte* p = header.ptr;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
909 while (n--)
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
910 {
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
911 checksum -= *p;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
912 p++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
913 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
914 *p = checksum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
915
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
916 libbuf.write(header.ptr, size + 5);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
917 //libbuf.write(om.base, om.length - (size + 5));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
918 libbuf.write(om.base, om.length);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
919 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
920 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
921 libbuf.write(om.base, om.length);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
922
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
923 // Round the size of the file up to the next page size
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
924 // by filling with 0s
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
925 uint n = (g_page_size - 1) & libbuf.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
926 if (n)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
927 libbuf.fill0(g_page_size - n);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
928 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
929
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
930 // File offset of start of dictionary
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
931 uint offset = libbuf.offset;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
932
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
933 // Write dictionary header, then round it to a BUCKETPAGE boundary
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
934 ushort size = (BUCKETPAGE - (cast(short)offset + 3)) & (BUCKETPAGE - 1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
935 libbuf.writeByte(0xF1);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
936 libbuf.writeword(size);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
937 libbuf.fill0(size);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
938
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
939 // Create dictionary
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
940 ubyte* bucketsP = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
941 ushort ndicpages;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
942 ushort padding = 32;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
943 for (;;)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
944 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
945 ndicpages = numDictPages(padding);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
946
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
947 version (LOG) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
948 printf("ndicpages = %d\n", ndicpages);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
949 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
950 // Allocate dictionary
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
951 if (bucketsP)
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
952 bucketsP = cast(ubyte*)GC.realloc(bucketsP, ndicpages * BUCKETPAGE);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
953 else
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
954 bucketsP = cast(ubyte*)GC.malloc(ndicpages * BUCKETPAGE);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
955 assert(bucketsP);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
956 memset(bucketsP, 0, ndicpages * BUCKETPAGE);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
957 for (uint u = 0; u < ndicpages; u++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
958 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
959 // 'next available' slot
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
960 bucketsP[u * BUCKETPAGE + HASHMOD] = (HASHMOD + 1) >> 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
961 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
962
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
963 if (FillDict(bucketsP, ndicpages))
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
964 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
965 padding += 16; // try again with more margins
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
966 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
967
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
968 // Write dictionary
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
969 libbuf.write(bucketsP, ndicpages * BUCKETPAGE);
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
970 ///if (bucketsP)
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
971 /// free(bucketsP);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
972
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
973 // Create library header
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
974 Libheader libHeader;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
975 memset(&libHeader, 0, Libheader.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
976 libHeader.recTyp = 0xF0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
977 libHeader.recLen = 0x0D;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
978 libHeader.trailerPosn = offset + (3 + size);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
979 libHeader.recLen = cast(ushort)(g_page_size - 3);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
980 libHeader.ndicpages = ndicpages;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
981 libHeader.flags = 1; // always case sensitive
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
982
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
983 // Write library header at start of buffer
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
984 memcpy(libbuf.data, &libHeader, libHeader.sizeof);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
985 }
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
986 }
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
987 } // version (Windows)
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
988 else version(TARGET_LINUX)
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
989 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
990
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
991 import dmd.TObject;
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
992
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
993 class Library : TObject
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
994 {
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
995 void setFilename(string dir, string filename)
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
996 {
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
997 assert(0);
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
998 }
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
999
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1000 void addObject(string module_name, void *buf, size_t buflen)
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1001 {
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1002 assert(0);
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1003 }
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
1004
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1005 void write()
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1006 {
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1007 assert(0);
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1008 }
178
e3afd1303184 Many small bugs fixed
korDen
parents: 169
diff changeset
1009
14
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1010 }
2cc604139636 Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents: 4
diff changeset
1011 }