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