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 @nogc:
25 nothrow:
26 @safe:
27 
28 alias symlist_t = LIST*;
29 
30 public import dmd.backend.dcgcv : cv_init, cv_typidx, cv_outsym, cv_func, cv_term, cv4_struct,
31     cv_stringbytes, cv4_numericbytes, cv4_storenumeric, cv4_signednumericbytes,
32     cv4_storesignednumeric, cv_debtyp, cv_namestring, cv4_typidx, cv4_arglist, cv4_callconv,
33     cv_numdebtypes, debtyp_alloc;
34 
35 public import dmd.backend.dwarfdbginf : dwarf_outsym;
36 
37 /* =================== Added for MARS compiler ========================= */
38 
39 alias idx_t = uint;        // type of type index
40 
41 /* Data structure for a type record     */
42 
43 struct debtyp_t
44 {
45   align(1):
46     uint prev;          // previous debtyp_t with same hash
47     ushort length;      // length of following array
48     ubyte[2] data;      // variable size array
49 }
50 
51 struct Cgcv
52 {
53     uint signature;
54     symlist_t list;     // deferred list of symbols to output
55     idx_t deb_offset;   // offset added to type index
56     uint sz_idx;        // size of stored type index
57     int LCFDoffset;
58     int LCFDpointer;
59     int FD_code;        // frame for references to code
60 }
61 
62 __gshared Cgcv cgcv;
63 
64 @trusted
65 void TOWORD(ubyte* a, uint b)
66 {
67     *cast(ushort*)a = cast(ushort)b;
68 }
69 
70 @trusted
71 void TOLONG(ubyte* a, uint b)
72 {
73     *cast(uint*)a = b;
74 }
75 
76 @trusted
77 void TOIDX(ubyte* a, uint b)
78 {
79     if (cgcv.sz_idx == 4)
80         TOLONG(a,b);
81     else
82         TOWORD(a,b);
83 }
84 
85 enum DEBSYM = 5;               // segment of symbol info
86 enum DEBTYP = 6;               // segment of type info
87 
88 /* ======================== Added for Codeview 8 =========================== */
89 
90 public import dmd.backend.cv8;