-
-
Notifications
You must be signed in to change notification settings - Fork 606
/
dmsc.d
186 lines (163 loc) · 4.89 KB
/
dmsc.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
/**
* Compiler implementation of the
* $(LINK2 http://www.dlang.org, D programming language).
*
* Copyright: Copyright (C) 1999-2020 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/dmsc.d, _dmsc.d)
* Documentation: https://dlang.org/phobos/dmd_dmsc.html
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/dmsc.d
*/
module dmd.dmsc;
import core.stdc.stdio;
import core.stdc.string;
import core.stdc.stddef;
extern (C++):
import dmd.globals;
import dmd.dclass;
import dmd.dmodule;
import dmd.mtype;
import dmd.root.filename;
import dmd.backend.cc;
import dmd.backend.cdef;
import dmd.backend.global;
import dmd.backend.ty;
import dmd.backend.type;
extern (C) void out_config_init(
int model, // 32: 32 bit code
// 64: 64 bit code
// Windows: bit 0 set to generate MS-COFF instead of OMF
bool exe, // true: exe file
// false: dll or shared library (generate PIC code)
bool trace, // add profiling code
bool nofloat, // do not pull in floating point code
bool verbose, // verbose compile
bool optimize, // optimize code
int symdebug, // add symbolic debug information
// 1: D
// 2: fake it with C symbolic debug info
bool alwaysframe, // always create standard function frame
bool stackstomp, // add stack stomping code
ubyte avx, // use AVX instruction set (0, 1, 2)
PIC pic, // kind of position independent code
bool useModuleInfo, // implement ModuleInfo
bool useTypeInfo, // implement TypeInfo
bool useExceptions, // implement exception handling
string _version // Compiler version
);
void out_config_debug(
bool debugb,
bool debugc,
bool debugf,
bool debugr,
bool debugw,
bool debugx,
bool debugy
);
/**************************************
* Initialize config variables.
*/
void backend_init()
{
//printf("out_config_init()\n");
Param *params = &global.params;
bool exe;
if (params.dll || params.pic != PIC.fixed)
{
}
else if (params.run)
exe = true; // EXE file only optimizations
else if (params.link && !params.deffile)
exe = true; // EXE file only optimizations
else if (params.exefile.length &&
params.exefile.length >= 4 &&
FileName.equals(FileName.ext(params.exefile), "exe"))
exe = true; // if writing out EXE file
out_config_init(
(params.is64bit ? 64 : 32) | (params.mscoff ? 1 : 0),
exe,
false, //params.trace,
params.nofloat,
params.verbose,
params.optimize,
params.symdebug,
params.alwaysframe,
params.stackstomp,
params.cpu >= CPU.avx2 ? 2 : params.cpu >= CPU.avx ? 1 : 0,
params.pic,
params.useModuleInfo && Module.moduleinfo,
params.useTypeInfo && Type.dtypeinfo,
params.useExceptions && ClassDeclaration.throwable,
global._version
);
debug
{
out_config_debug(
params.debugb,
params.debugc,
params.debugf,
params.debugr,
false,
params.debugx,
params.debugy
);
}
}
/***********************************
* Return aligned 'offset' if it is of size 'size'.
*/
targ_size_t _align(targ_size_t size, targ_size_t offset)
{
switch (size)
{
case 1:
break;
case 2:
case 4:
case 8:
case 16:
case 32:
case 64:
offset = (offset + size - 1) & ~(size - 1);
break;
default:
if (size >= 16)
offset = (offset + 15) & ~15;
else
offset = (offset + _tysize[TYnptr] - 1) & ~(_tysize[TYnptr] - 1);
break;
}
return offset;
}
/*******************************
* Get size of ty
*/
targ_size_t size(tym_t ty)
{
int sz = (tybasic(ty) == TYvoid) ? 1 : tysize(ty);
debug
{
if (sz == -1)
WRTYxx(ty);
}
assert(sz!= -1);
return sz;
}
/****************************
* Generate symbol of type ty at DATA:offset
*/
Symbol *symboldata(targ_size_t offset,tym_t ty)
{
Symbol *s = symbol_generate(SClocstat, type_fake(ty));
s.Sfl = FLdata;
s.Soffset = offset;
s.Stype.Tmangle = mTYman_sys; // writes symbol unmodified in Obj::mangle
symbol_keep(s); // keep around
return s;
}
/**************************************
*/
void backend_term()
{
}