-
-
Notifications
You must be signed in to change notification settings - Fork 594
/
dcgcv.d
3161 lines (2810 loc) · 85.9 KB
/
dcgcv.d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Compiler implementation of the
* $(LINK2 http://www.dlang.org, D programming language).
*
* Copyright: Copyright (C) 1984-1995 by Symantec
* Copyright (C) 2000-2019 by The D Language Foundation, All Rights Reserved
* Authors: $(LINK2 http://www.digitalmars.com, Walter Bright)
* License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/backend/dcgcv.d, backend/dcgcv.d)
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/backend/dcgcv.d
*/
module dmd.backend.dcgcv;
version (Windows)
{
version (SCPP)
version = COMPILE;
version (MARS)
version = COMPILE;
}
version (COMPILE)
{
import core.stdc.stdio;
import core.stdc.stdlib;
import core.stdc.string;
import dmd.backend.cc;
import dmd.backend.cdef;
import dmd.backend.cgcv;
import dmd.backend.code;
import dmd.backend.code_x86;
import dmd.backend.cv4;
import dmd.backend.dlist;
import dmd.backend.dvec;
import dmd.backend.el;
import dmd.backend.global;
import dmd.backend.mem;
import dmd.backend.obj;
import dmd.backend.outbuf;
import dmd.backend.ty;
import dmd.backend.type;
import dmd.backend.barray;
version (SCPP)
{
import cpp;
import msgs2;
import parser;
}
version (MARS)
{
import dmd.backend.varstats;
}
extern (C++):
enum SYMDEB_TDB = false;
extern (C) void TOOFFSET(void* p, targ_size_t value)
{
switch (_tysize[TYnptr])
{
case 2: *cast(ushort*)p = cast(ushort)value; break;
case 4: *cast(uint*) p = cast(uint) value; break;
case 8: *cast(ulong*) p = cast(ulong) value; break;
default:
assert(0);
}
}
extern __gshared char* ftdbname;
// Convert from SFL protections to CV4 protections
uint SFLtoATTR(uint sfl) { return 4 - ((sfl & SFLpmask) >> 5); }
__gshared
{
/* Dynamic array of debtyp_t's */
private Barray!(debtyp_t*) debtyp;
private vec_t debtypvec; // vector of used entries
enum DEBTYPVECDIM = 16001; //8009 //3001 // dimension of debtypvec (should be prime)
enum DEBTYPHASHDIM = 1009;
private uint[DEBTYPHASHDIM] debtyphash;
private Outbuffer *reset_symbuf; // Keep pointers to reset symbols
idx_t DEB_NULL() { return cgcv.deb_offset; } // index of null debug type record
/* This limitation is because of 4K page sizes
* in optlink/cv/cvhashes.asm
*/
enum CVIDMAX = (0xFF0-20); // the -20 is picked by trial and error
enum LOCATsegrel = 0xC000;
/* Unfortunately, the fixup stuff is different for EASY OMF and Microsoft */
enum EASY_LCFDoffset = (LOCATsegrel | 0x1404);
enum EASY_LCFDpointer = (LOCATsegrel | 0x1800);
enum LCFD32offset = (LOCATsegrel | 0x2404);
enum LCFD32pointer = (LOCATsegrel | 0x2C00);
enum LCFD16pointer = (LOCATsegrel | 0x0C00);
version (MARS)
extern Cgcv cgcv; // already declared in cgcv.d
else
Cgcv cgcv;
}
version (MARS)
enum MARS = true;
else
enum MARS = false;
/******************************************
* Return number of bytes consumed in OBJ file by a name.
*/
int cv_stringbytes(const(char)* name)
{
int len = cast(int)strlen(name);
if (config.fulltypes == CV8)
return len + 1;
if (len > CVIDMAX)
len = CVIDMAX;
return len + ((len > 255) ? 4 : 1);
}
/******************************************
* Stuff a namestring into p.
* Returns:
* number of bytes consumed
*/
int cv_namestring(ubyte *p, const(char)* name, int length = -1)
{
size_t len = (length >= 0) ? length : strlen(name);
if (config.fulltypes == CV8)
{
size_t numBytesWritten = len + ((length < 0) ? 1 : 0);
memcpy(p, name, numBytesWritten);
if(config.flags2 & CFG2gms)
{
for(int i = 0; i < len; i++)
{
if(p[i] == '.')
p[i] = '@';
}
}
return cast(int)numBytesWritten;
}
if (len > 255)
{ p[0] = 0xFF;
p[1] = 0;
if (len > CVIDMAX)
len = CVIDMAX;
TOWORD(p + 2,cast(uint)len);
memcpy(p + 4,name,len);
len += 4;
}
else
{ p[0] = cast(ubyte)len;
memcpy(p + 1,name,len);
len++;
}
return cast(int)len;
}
/***********************************
* Compute debug register number for symbol s.
* Returns:
* 0..7 byte registers
* 8..15 word registers
* 16..23 dword registers
*/
private int cv_regnum(Symbol *s)
{
uint reg = s.Sreglsw;
if (s.Sclass == SCpseudo)
{
version (SCPP)
reg = pseudoreg[reg];
}
else
{
assert(reg < 8);
assert(s.Sfl == FLreg);
switch (type_size(s.Stype))
{
case LONGSIZE:
case 3: reg += 8;
goto case;
case SHORTSIZE: reg += 8;
goto case;
case CHARSIZE: break;
case LLONGSIZE:
reg += (s.Sregmsw << 8) + (16 << 8) + 16;
if (config.fulltypes == CV4)
reg += (1 << 8);
break;
default:
static if (0)
{
symbol_print(s);
type_print(s.Stype);
printf("size = %d\n",type_size(s.Stype));
}
assert(0);
}
}
if (config.fulltypes == CV4)
reg++;
return reg;
}
/***********************************
* Allocate a debtyp_t.
*/
debtyp_t * debtyp_alloc(uint length)
{
debtyp_t *d;
uint pad = 0;
//printf("len = %u, x%x\n", length, length);
if (config.fulltypes == CV8)
{ // length+2 must lie on 4 byte boundary
pad = ((length + 2 + 3) & ~3) - (length + 2);
length += pad;
}
debug
{
const len = debtyp_t.sizeof - (d.data).sizeof + length;
assert(len < 4 * 4096 - 100);
d = cast(debtyp_t *) mem_malloc(len /*+ 1*/);
memset(d, 0xAA, len);
// (cast(char*)d)[len] = 0x2E;
}
else
{
assert(length < 0x10000);
d = cast(debtyp_t *) malloc(debtyp_t.sizeof - (d.data).sizeof + length);
}
d.length = cast(ushort)length;
if (pad)
{
__gshared const ubyte[3] padx = [0xF3, 0xF2, 0xF1];
memcpy(d.data.ptr + length - pad, padx.ptr + 3 - pad, pad);
}
//printf("debtyp_alloc(%d) = %p\n", length, d);
return d;
}
/***********************************
* Free a debtyp_t.
*/
private void debtyp_free(debtyp_t *d)
{
//printf("debtyp_free(length = %d, %p)\n", d.length, d);
//fflush(stdout);
debug
{
uint len = debtyp_t.sizeof - (d.data).sizeof + d.length;
assert(len < 4 * 4096 - 100);
// assert((cast(char*)d)[len] == 0x2E);
memset(d, 0x55, len);
mem_free(d);
}
else
{
free(d);
}
}
static if (0)
{
void debtyp_check(debtyp_t *d,int linnum)
{ int i;
__gshared char c;
//printf("linnum = %d\n",linnum);
//printf(" length = %d\n",d.length);
for (i = 0; i < d.length; i++)
c = d.data.ptr[i];
}
void debtyp_check(debtyp_t* d) { debtyp_check(d,__LINE__); }
}
else
{
void debtyp_check(debtyp_t* d) { }
}
/***********************************
* Search for debtyp_t in debtyp[]. If it is there, return the index
* of it, and free d. Otherwise, add it.
* Returns:
* index in debtyp[]
*/
idx_t cv_debtyp(debtyp_t *d)
{
ushort length;
uint hashi;
assert(d);
length = d.length;
//printf("length = %3d\n",length);
static if (SYMDEB_TDB)
{
if (config.fulltypes == CVTDB)
{
idx_t result;
static if (1)
{
assert(length);
debtyp_check(d);
result = tdb_typidx(&d.length);
}
else
{
ubyte *buf;
// Allocate buffer
buf = malloc(6 + length);
if (!buf)
err_nomem(); // out of memory
// Fill the buffer
TOLONG(buf,cgcv.signature);
memcpy(buf + 4,cast(char *)d + uint.sizeof,2 + length);
static if (0)
{
{int i;
for (i=0;i<length;i++)
printf("%02x ",buf[6+i]);
printf("\n");
}
}
result = tdb_typidx(buf,6 + length);
}
//printf("result = x%x\n",result);
debtyp_free(d);
return result;
}
}
if (length)
{ uint hash;
hash = length;
if (length >= uint.sizeof)
{
// Hash consists of the sum of the first 4 bytes with the last 4 bytes
union U { ubyte* cp; uint* up; }
U un = void;
un.cp = d.data.ptr;
hash += *un.up;
un.cp += length - uint.sizeof;
hash += *un.up;
}
hashi = hash % DEBTYPHASHDIM;
hash %= DEBTYPVECDIM;
//printf(" hashi = %d", hashi);
if (vec_testbit(hash,debtypvec))
{
//printf(" test");
// Threaded list is much faster
for (uint u = debtyphash[hashi]; u; u = debtyp[u].prev)
//for (uint u = debtyp.length; u--; )
{
if (length == debtyp[u].length &&
memcmp(d.data.ptr,debtyp[u].data.ptr,length) == 0)
{ debtyp_free(d);
//printf(" match %d\n",u);
return u + cgcv.deb_offset;
}
}
}
else
vec_setbit(hash,debtypvec);
}
else
hashi = 1;
//printf(" add %d\n",debtyp.length);
d.prev = debtyphash[hashi];
debtyphash[hashi] = cast(uint)debtyp.length;
/* It's not already in the array, so add it */
L1:
debtyp.push(d);
version (SCPP)
{
if (debtyp.length >= 0xE000)
err_fatal(EM_2manytypes,0xE000); // too many types
}
return cast(uint)debtyp.length - 1 + cgcv.deb_offset;
}
idx_t cv_numdebtypes()
{
return cast(idx_t)debtyp.length;
}
/****************************
* Store a null record at DEB_NULL.
*/
void cv_init()
{ debtyp_t *d;
//printf("cv_init()\n");
// Initialize statics
debtyp.setLength(0);
if (!ftdbname)
ftdbname = cast(char *)"symc.tdb".ptr;
memset(&cgcv,0,cgcv.sizeof);
cgcv.sz_idx = 2;
cgcv.LCFDoffset = LCFD32offset;
cgcv.LCFDpointer = LCFD16pointer;
debtypvec = vec_calloc(DEBTYPVECDIM);
memset(debtyphash.ptr,0,debtyphash.sizeof);
if (reset_symbuf)
{
Symbol **p = cast(Symbol **)reset_symbuf.buf;
const size_t n = reset_symbuf.size() / (Symbol *).sizeof;
for (size_t i = 0; i < n; ++i)
symbol_reset(p[i]);
reset_symbuf.setsize(0);
}
else
{
reset_symbuf = cast(Outbuffer*) calloc(1, Outbuffer.sizeof);
assert(reset_symbuf);
reset_symbuf.enlarge(10 * (Symbol *).sizeof);
}
/* Reset for different OBJ file formats */
if (I32 || I64)
{
// Adjust values in old CV tables for 32 bit ints
dttab[TYenum] = dttab[TYlong];
dttab[TYint] = dttab[TYlong];
dttab[TYuint] = dttab[TYulong];
// Adjust Codeview 4 values for 32 bit ints and 32 bit pointer offsets
dttab4[TYenum] = 0x74;
dttab4[TYint] = 0x74;
dttab4[TYuint] = 0x75;
if (I64)
{
dttab4[TYptr] = 0x600;
dttab4[TYnptr] = 0x600;
}
else
{
dttab4[TYptr] = 0x400;
dttab4[TYnptr] = 0x400;
}
dttab4[TYsptr] = 0x400;
dttab4[TYcptr] = 0x400;
dttab4[TYfptr] = 0x500;
if (config.flags & CFGeasyomf)
{ cgcv.LCFDoffset = EASY_LCFDoffset;
cgcv.LCFDpointer = EASY_LCFDpointer;
assert(config.fulltypes == CVOLD);
}
else
cgcv.LCFDpointer = LCFD32pointer;
if (config.exe & EX_flat)
cgcv.FD_code = 0x10;
}
if (config.fulltypes >= CV4)
{ int flags;
__gshared ushort[5] memmodel = [0,0x100,0x20,0x120,0x120];
char[1 + (VERSION).sizeof] version_;
ubyte[8 + (version_).sizeof] debsym;
// Put out signature indicating CV4 format
switch (config.fulltypes)
{
case CV4:
cgcv.signature = 1;
break;
case CV8:
cgcv.signature = 4;
break;
default:
{ const(char)* x = "1MYS";
cgcv.signature = *cast(int *) x;
break;
}
}
cgcv.deb_offset = 0x1000;
if (config.fulltypes == CV8)
{ cgcv.sz_idx = 4;
return; // figure out rest later
}
if (config.fulltypes >= CVSYM)
{ cgcv.sz_idx = 4;
if (!(config.flags2 & CFG2phgen))
cgcv.deb_offset = 0x80000000;
}
objmod.write_bytes(SegData[DEBSYM],4,&cgcv.signature);
// Allocate an LF_ARGLIST with no arguments
if (config.fulltypes == CV4)
{ d = debtyp_alloc(4);
TOWORD(d.data.ptr,LF_ARGLIST);
TOWORD(d.data.ptr + 2,0);
}
else
{ d = debtyp_alloc(6);
TOWORD(d.data.ptr,LF_ARGLIST);
TOLONG(d.data.ptr + 2,0);
}
// Put out S_COMPILE record
TOWORD(debsym.ptr + 2,S_COMPILE);
switch (config.target_cpu)
{
case TARGET_8086: debsym[4] = 0; break;
case TARGET_80286: debsym[4] = 2; break;
case TARGET_80386: debsym[4] = 3; break;
case TARGET_80486: debsym[4] = 4; break;
case TARGET_Pentium:
case TARGET_PentiumMMX:
debsym[4] = 5; break;
case TARGET_PentiumPro:
case TARGET_PentiumII:
debsym[4] = 6; break;
default: assert(0);
}
debsym[5] = (CPP != 0); // 0==C, 1==C++
flags = (config.inline8087) ? (0<<3) : (1<<3);
if (I32)
flags |= 0x80; // 32 bit addresses
flags |= memmodel[config.memmodel];
TOWORD(debsym.ptr + 6,flags);
version_[0] = 'Z';
strcpy(version_.ptr + 1,VERSION);
cv_namestring(debsym.ptr + 8,version_.ptr);
TOWORD(debsym.ptr,6 + (version_).sizeof);
objmod.write_bytes(SegData[DEBSYM],8 + (version_).sizeof,debsym.ptr);
static if (SYMDEB_TDB)
{
// Put out S_TDBNAME record
if (config.fulltypes == CVTDB)
{
ubyte[50] buf = void;
pstate.STtdbtimestamp = tdb_gettimestamp();
size_t len = cv_stringbytes(ftdbname);
ubyte *ds = (8 + len <= buf.sizeof) ? buf : cast(ubyte *) malloc(8 + len);
assert(ds);
TOWORD(ds,6 + len);
TOWORD(ds + 2,S_TDBNAME);
TOLONG(ds + 4,pstate.STtdbtimestamp);
cv_namestring(ds + 8,ftdbname);
objmod.write_bytes(SegData[DEBSYM],8 + len,ds);
if (ds != buf)
free(ds);
}
}
}
else
{
assert(0);
}
if (config.fulltypes == CVTDB)
cgcv.deb_offset = cv_debtyp(d);
else
cv_debtyp(d);
}
/////////////////////////// CodeView 4 ///////////////////////////////
/***********************************
* Return number of bytes required to store a numeric leaf.
*/
uint cv4_numericbytes(uint value)
{ uint u;
if (value < 0x8000)
u = 2;
else if (value < 0x10000)
u = 4;
else
u = 6;
return u;
}
/********************************
* Store numeric leaf.
* Must use exact same number of bytes as cv4_numericbytes().
*/
void cv4_storenumeric(ubyte *p, uint value)
{
if (value < 0x8000)
TOWORD(p,value);
else if (value < 0x10000)
{ TOWORD(p,LF_USHORT);
p += 2;
TOWORD(p,value);
}
else
{ TOWORD(p,LF_ULONG);
*cast(targ_ulong *)(p + 2) = cast(uint) value;
}
}
/***********************************
* Return number of bytes required to store a signed numeric leaf.
* Params:
* value = value to store
* Returns:
* number of bytes required for storing value
*/
uint cv4_signednumericbytes(int value)
{
uint u;
if (value >= 0 && value < 0x8000)
u = 2;
else if (value == cast(short)value)
u = 4;
else
u = 6;
return u;
}
/********************************
* Store signed numeric leaf.
* Must use exact same number of bytes as cv4_signednumericbytes().
* Params:
* p = address where to store value
* value = value to store
*/
void cv4_storesignednumeric(ubyte *p, int value)
{
if (value >= 0 && value < 0x8000)
TOWORD(p, value);
else if (value == cast(short)value)
{
TOWORD(p, LF_SHORT);
TOWORD(p + 2, value);
}
else
{
TOWORD(p,LF_LONG);
TOLONG(p + 2, value);
}
}
/*********************************
* Generate a type index for a parameter list.
*/
idx_t cv4_arglist(type *t,uint *pnparam)
{ uint u;
uint nparam;
idx_t paramidx;
debtyp_t *d;
param_t *p;
// Compute nparam, number of parameters
nparam = 0;
for (p = t.Tparamtypes; p; p = p.Pnext)
nparam++;
*pnparam = nparam;
// Construct an LF_ARGLIST of those parameters
if (nparam == 0)
{
if (config.fulltypes == CV8)
{
d = debtyp_alloc(2 + 4 + 4);
TOWORD(d.data.ptr,LF_ARGLIST_V2);
TOLONG(d.data.ptr + 2,1);
TOLONG(d.data.ptr + 6,0);
paramidx = cv_debtyp(d);
}
else
paramidx = DEB_NULL;
}
else
{
switch (config.fulltypes)
{
case CV8:
d = debtyp_alloc(2 + 4 + nparam * 4);
TOWORD(d.data.ptr,LF_ARGLIST_V2);
TOLONG(d.data.ptr + 2,nparam);
p = t.Tparamtypes;
for (u = 0; u < nparam; u++)
{ TOLONG(d.data.ptr + 6 + u * 4,cv4_typidx(p.Ptype));
p = p.Pnext;
}
break;
case CV4:
d = debtyp_alloc(2 + 2 + nparam * 2);
TOWORD(d.data.ptr,LF_ARGLIST);
TOWORD(d.data.ptr + 2,nparam);
p = t.Tparamtypes;
for (u = 0; u < nparam; u++)
{ TOWORD(d.data.ptr + 4 + u * 2,cv4_typidx(p.Ptype));
p = p.Pnext;
}
break;
default:
d = debtyp_alloc(2 + 4 + nparam * 4);
TOWORD(d.data.ptr,LF_ARGLIST);
TOLONG(d.data.ptr + 2,nparam);
p = t.Tparamtypes;
for (u = 0; u < nparam; u++)
{ TOLONG(d.data.ptr + 6 + u * 4,cv4_typidx(p.Ptype));
p = p.Pnext;
}
break;
}
paramidx = cv_debtyp(d);
}
return paramidx;
}
/*****************************
* Build LF_METHODLIST for overloaded member function.
* Output:
* *pcount # of entries in method list
* Returns:
* type index of method list
* 0 don't do this one
*/
version (SCPP)
{
private int cv4_methodlist(Symbol *sf,int *pcount)
{ int count;
int mlen;
Symbol *s;
debtyp_t *d;
ubyte *p;
ushort attribute;
symbol_debug(sf);
// First, compute how big the method list is
count = 0;
mlen = 2;
for (s = sf; s; s = s.Sfunc.Foversym)
{
if (s.Sclass == SCtypedef || s.Sclass == SCfunctempl)
continue;
if (s.Sfunc.Fflags & Fnodebug)
continue;
if (s.Sfunc.Fflags & Fintro)
mlen += 4;
mlen += cgcv.sz_idx * 2;
count++;
}
if (!count)
return 0;
// Allocate and fill it in
d = debtyp_alloc(mlen);
p = d.data.ptr;
TOWORD(p,LF_METHODLIST);
p += 2;
for (s = sf; s; s = s.Sfunc.Foversym)
{
if (s.Sclass == SCtypedef || s.Sclass == SCfunctempl)
continue;
if (s.Sfunc.Fflags & Fnodebug)
continue;
attribute = cast(ushort)SFLtoATTR(s.Sflags);
// Make sure no overlapping bits
assert((Fvirtual | Fpure | Fintro | Fstatic) == (Fvirtual ^ Fpure ^ Fintro ^ Fstatic));
switch ((s.Sfunc.Fflags & (Fvirtual | Fstatic)) |
(s.Sfunc.Fflags & (Fpure | Fintro)))
{
// BUG: should we have 0x0C, friend functions?
case Fstatic: attribute |= 0x08; break;
case Fvirtual: attribute |= 0x04; break;
case Fvirtual | Fintro: attribute |= 0x10; break;
case Fvirtual | Fpure: attribute |= 0x14; break;
case Fvirtual | Fintro | Fpure: attribute |= 0x18; break;
case 0:
break;
default:
symbol_print(s);
assert(0);
}
TOIDX(p,attribute);
p += cgcv.sz_idx;
TOIDX(p,cv4_symtypidx(s));
p += cgcv.sz_idx;
if (s.Sfunc.Fflags & Fintro)
{ TOLONG(p,cpp_vtbloffset(cast(Classsym *)s.Sscope,s));
p += 4;
}
}
assert(p - d.data.ptr == mlen);
*pcount = count;
return cv_debtyp(d);
}
}
/**********************************
* Pretty-print indentifier for CV4 types.
*/
version (SCPP)
{
private const(char)* cv4_prettyident(Symbol *s)
{ Symbol *stmp;
stmp = s.Sscope;
s.Sscope = null; // trick cpp_prettyident into leaving off ::
const p = cpp_prettyident(s);
s.Sscope = cast(Classsym *)stmp;
return p;
}
}
/****************************
* Return type index of struct.
* Input:
* s struct tag symbol
* flags
* 0 generate a reference to s
* 1 just saw the definition of s
* 2 saw key function for class s
* 3 no longer have a key function for class s
*/
idx_t cv4_struct(Classsym *s,int flags)
{ targ_size_t size;
debtyp_t* d,dt;
uint len;
uint nfields,fnamelen;
idx_t typidx;
type *t;
struct_t *st;
const(char)* id;
version (SCPP)
{
baseclass_t *b;
}
uint numidx;
uint leaf;
uint property;
uint attribute;
ubyte *p;
int refonly;
int i;
int count; // COUNT field in LF_CLASS
symbol_debug(s);
assert(config.fulltypes >= CV4);
st = s.Sstruct;
if (st.Sflags & STRanonymous) // if anonymous class/union
return 0;
//printf("cv4_struct(%s,%d)\n",s.Sident.ptr,flags);
t = s.Stype;
//printf("t = %p, Tflags = x%x\n", t, t.Tflags);
type_debug(t);
// Determine if we should do a reference or a definition
refonly = 1; // assume reference only
if (MARS || t.Tflags & TFsizeunknown || st.Sflags & STRoutdef)
{
//printf("ref only\n");
}
else
{
// We have a definition that we have not put out yet
switch (flags)
{
case 0: // reference to s
version (SCPP)
{
if (!CPP ||
config.flags2 & (CFG2fulltypes | CFG2hdrdebug) ||
!(st.Sflags & STRvtblext))
refonly = 0;
}
else
{
refonly = 0;
}
break;
case 1: // saw def of s
if (!s.Stypidx) // if not forward referenced
return 0;
version (SCPP)
{
if (!CPP ||
config.flags2 & CFG2fulltypes ||
!(st.Sflags & STRvtblext))
refonly = 0;
}
break;
version (SCPP)
{
case 2: // saw key func for s
if (config.flags2 & CFG2fulltypes)
return 0;
refonly = 0;
break;
case 3: // no longer have key func for s
if (!s.Stypidx || config.flags2 & CFG2fulltypes)
return 0;
refonly = 0;
break;
}
default:
assert(0);
}
}
if (MARS || refonly)
{
if (s.Stypidx) // if reference already generated
{ //assert(s.Stypidx - cgcv.deb_offset < debtyp.length);
return s.Stypidx; // use already existing reference
}
size = 0;
property = 0x80; // class is forward referenced
}
else
{ size = type_size(t);
st.Sflags |= STRoutdef;
property = 0;
}
version (SCPP)
{
if (CPP)
{
if (s.Sscope) // if class is nested
property |= 8;
if (st.Sctor || st.Sdtor)
property |= 2; // class has ctors and/or dtors
if (st.Sopoverload)
property |= 4; // class has overloaded operators
if (st.Scastoverload)
property |= 0x40; // class has casting methods
if (st.Sopeq && !(st.Sopeq.Sfunc.Fflags & Fnodebug))