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