1 /**
2  * Interface for CodeView symbol debug info generation
3  *
4  * Compiler implementation of the
5  * $(LINK2 https://www.dlang.org, D programming language).
6  *
7  * Copyright:   Copyright (C) 1985-1998 by Symantec
8  *              Copyright (C) 2000-2023 by The D Language Foundation, All Rights Reserved
9  * Authors:     $(LINK2 https://www.digitalmars.com, Walter Bright)
10  * License:     $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
11  * Source:      $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/backend/cgcv.c, backend/cgcv.c)
12  */
13 
14 /* Header for cgcv.c    */
15 
16 module dmd.backend.cgcv;
17 
18 // Online documentation: https://dlang.org/phobos/dmd_backend_cgcv.html
19 
20 import dmd.backend.cc : Classsym, Symbol;
21 import dmd.backend.dlist;
22 import dmd.backend.type;
23 
24 extern (C++):
25 @nogc:
26 nothrow:
27 @safe:
28 
29 alias symlist_t = LIST*;
30 
31 extern __gshared char* ftdbname;
32 
33 void cv_init();
34 uint cv_typidx(type* t);
35 void cv_outsym(Symbol* s);
36 void cv_func(Symbol* s);
37 void cv_term();
38 
39 void dwarf_outsym(Symbol* s);
40 
41 uint cv4_struct(Classsym*, int);
42 
43 
44 /* =================== Added for MARS compiler ========================= */
45 
46 alias idx_t = uint;        // type of type index
47 
48 /* Data structure for a type record     */
49 
50 struct debtyp_t
51 {
52   align(1):
53     uint prev;          // previous debtyp_t with same hash
54     ushort length;      // length of following array
55     ubyte[2] data;      // variable size array
56 }
57 
58 struct Cgcv
59 {
60     uint signature;
61     symlist_t list;     // deferred list of symbols to output
62     idx_t deb_offset;   // offset added to type index
63     uint sz_idx;        // size of stored type index
64     int LCFDoffset;
65     int LCFDpointer;
66     int FD_code;        // frame for references to code
67 }
68 
69 __gshared Cgcv cgcv;
70 
71 debtyp_t* debtyp_alloc(uint length);
72 int cv_stringbytes(const(char)* name);
73 uint cv4_numericbytes(uint value);
74 void cv4_storenumeric(ubyte* p, uint value);
75 uint cv4_signednumericbytes(int value);
76 void cv4_storesignednumeric(ubyte* p, int value);
77 idx_t cv_debtyp(debtyp_t* d);
78 int cv_namestring(ubyte* p, const(char)* name, int length = -1);
79 uint cv4_typidx(type* t);
80 idx_t cv4_arglist(type* t, uint* pnparam);
81 ubyte cv4_callconv(type* t);
82 idx_t cv_numdebtypes();
83 
84 @trusted
85 void TOWORD(ubyte* a, uint b)
86 {
87     *cast(ushort*)a = cast(ushort)b;
88 }
89 
90 @trusted
91 void TOLONG(ubyte* a, uint b)
92 {
93     *cast(uint*)a = b;
94 }
95 
96 @trusted
97 void TOIDX(ubyte* a, uint b)
98 {
99     if (cgcv.sz_idx == 4)
100         TOLONG(a,b);
101     else
102         TOWORD(a,b);
103 }
104 
105 enum DEBSYM = 5;               // segment of symbol info
106 enum DEBTYP = 6;               // segment of type info
107 
108 /* ======================== Added for Codeview 8 =========================== */
109 
110 void cv8_initfile(const(char)* filename);
111 void cv8_termfile(const(char)* objfilename);
112 void cv8_initmodule(const(char)* filename, const(char)* modulename);
113 void cv8_termmodule();
114 void cv8_func_start(Symbol* sfunc);
115 void cv8_func_term(Symbol* sfunc);
116 //void cv8_linnum(Srcpos srcpos, uint offset);  // Srcpos isn't available yet
117 void cv8_outsym(Symbol* s);
118 void cv8_udt(const(char)* id, idx_t typidx);
119 int cv8_regnum(Symbol* s);
120 idx_t cv8_fwdref(Symbol* s);
121 idx_t cv8_darray(type* tnext, idx_t etypidx);
122 idx_t cv8_ddelegate(type* t, idx_t functypidx);
123 idx_t cv8_daarray(type* t, idx_t keyidx, idx_t validx);