forked from Matway/mpl-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessorImpl.mpl
executable file
·324 lines (273 loc) · 9.97 KB
/
processorImpl.mpl
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
"processorImpl" module
"astNodeType" useModule
"variable" useModule
"codeNode" useModule
"pathUtils" useModule
"staticCall" useModule
"processSubNodes" useModule
"builtinImpl" useModule
"builtins" useModule
"debugWriter" useModule
"processor" useModule
"irWriter" useModule
{
processorResult: ProcessorResult Ref;
unitId: 0;
options: ProcessorOptions Cref;
multiParserResult: MultiParserResult Cref;
} () {convention: cdecl;} [
processorResult:;
copy unitId:;
options:;
multiParserResult:;
processor: Processor;
unitId @processor.@unitId set
multiParserResult.names @processor.@nameToId set
@options @processor.@options set
processor.nameToId.getSize @[email protected]
@processor.@nameToId [
pair:;
id: pair.value;
key: pair.key;
key id @[email protected].@name set
] each
"" findNameInfo @processor.@emptyNameInfo set
"CALL" findNameInfo @processor.@callNameInfo set
"PRE" findNameInfo @processor.@preNameInfo set
"DIE" findNameInfo @processor.@dieNameInfo set
"INIT" findNameInfo @processor.@initNameInfo set
"ASSIGN" findNameInfo @processor.@assignNameInfo set
"self" findNameInfo @processor.@selfNameInfo set
"closure" findNameInfo @processor.@closureNameInfo set
"inputs" findNameInfo @processor.@inputsNameInfo set
"outputs" findNameInfo @processor.@outputsNameInfo set
"captures" findNameInfo @processor.@capturesNameInfo set
"variadic" findNameInfo @processor.@variadicNameInfo set
"failProc" findNameInfo @processor.@failProcNameInfo set
"convention" findNameInfo @processor.@conventionNameInfo set
addCodeNode
TRUE dynamic @[email protected].@root set
@processorResult @processor initBuiltins
s1: String;
s2: String;
processor.options.pointerSize 32nx = [
"target datalayout = \"e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32\"" makeStringView addStrToProlog
"target triple = \"i386-pc-windows-msvc18.0.0\"" makeStringView addStrToProlog
] [
"target datalayout = \"e-m:w-i64:64-f80:128-n8:16:32:64-S128\"" makeStringView addStrToProlog
"target triple = \"x86_64-pc-windows\"" makeStringView addStrToProlog
] if
"" makeStringView addStrToProlog
("mainPath is \"" makeStringView processor.options.mainPath makeStringView "\"" makeStringView) addLog
processor.options.callTrace [createCallTraceData] when
addLinkerOptionsDebugInfo
processor.options.debug [
@processor [processor:; addDebugProlog @processor.@debugInfo.@unit set] call
i: 0 dynamic;
[
i processor.options.fileNames.dataSize < [
id: i processor.options.fileNames.at makeStringView addFileDebugInfo;
id @processor.@[email protected]
i 1 + @i set TRUE
] &&
] loop
] when
lastFile: 0 dynamic;
multiParserResult.nodes.dataSize 0 > [
dependedFiles: String IndexArray HashTable; # string -> array of indexes of dependent files
cachedGlobalErrorInfoSize: 0;
runFile: [
copy n:;
n @lastFile set
fileNode: n multiParserResult.nodes.at;
rootPositionInfo: CompilerPositionInfo;
1 dynamic @rootPositionInfo.@column set
1 dynamic @rootPositionInfo.@line set
0 dynamic @rootPositionInfo.@offset set
n dynamic @rootPositionInfo.@fileNumber set
processorResult.globalErrorInfo.getSize @cachedGlobalErrorInfoSize set
topNodeIndex: StringView 0 NodeCaseCode @processorResult @processor fileNode multiParserResult rootPositionInfo CFunctionSignature astNodeToCodeNode;
processorResult.findModuleFail [
# cant compile this file now, add him to queue
fr: processorResult.errorInfo.missedModule makeStringView @dependedFiles.find;
fr.success [
] [
a: IndexArray;
n @a.pushBack
@processorResult.@errorInfo.@missedModule @a move @dependedFiles.insert
] if
cachedGlobalErrorInfoSize clearProcessorResult
] [
("compiled file " n processor.options.fileNames.at) addLog
# call files which depends from this module
moduleName: topNodeIndex processor.nodes.at.get.moduleName;
moduleName.getTextSize 0 > [
fr: moduleName @dependedFiles.find;
fr.success [
i: 0 dynamic;
[
i fr.value.dataSize < [
numberOfDependent: fr.value.dataSize 1 - i - fr.value.at;
numberOfDependent @unfinishedFiles.pushBack
i 1 + @i set TRUE
] &&
] loop
] when
] when
] if
];
unfinishedFiles: IndexArray;
n: 0 dynamic;
[
n multiParserResult.nodes.dataSize < [
multiParserResult.nodes.dataSize 1 - n - @unfinishedFiles.pushBack
n 1 + @n set TRUE
] &&
] loop
[
0 unfinishedFiles.dataSize < [
n: unfinishedFiles.last copy;
@unfinishedFiles.popBack
n runFile
processorResult.success copy
] &&
] loop
processorResult.success not [
@processorResult.@errorInfo move @[email protected]
] when
processorResult.globalErrorInfo.getSize 0 > [
FALSE @processorResult.@success set
] when
processorResult.success [
processor.options.debug [
lastFile correctUnitInfo
] when
0 clearProcessorResult
dependedFiles.getSize 0 > [
hasError: FALSE dynamic;
hasErrorMessage: FALSE dynamic;
dependedFiles [
# queue is empty, but has uncompiled files
pair:;
pair.value.dataSize 0 > [
fr: pair.key processor.modules.find;
fr.success not [
("missed module: " @pair.@key "; used in file: " pair.value.last processor.options.fileNames.at LF) assembleString @processorResult.@errorInfo.@message set
TRUE @hasErrorMessage set
] when
TRUE @hasError set
FALSE @processorResult.@success set
] when
] each
hasError [hasErrorMessage not] && [
String @processorResult.@errorInfo.@message set
"problem with finding modules" @processorResult.@[email protected]
LF @processorResult.@[email protected]
dependedFiles [
# queue is empty, but has uncompiled files
pair:;
pair.value.dataSize 0 > [
("need module: " @pair.@key "; used in file: " pair.value.last processor.options.fileNames.at LF) assembleString @processorResult.@[email protected]
] when
] each
] when
processorResult.success not [
@processorResult.@errorInfo move @[email protected]
] when
] when
] when
] when
("all nodes generated" makeStringView) addLog
[compilable not [processor.recursiveNodesStack.getSize 0 =] ||] "Recursive stack is not empty!" assert
processorResult.success [
("nameCount=" processor.nameInfos.dataSize
"; irNameCount=" processor.nameBuffer.dataSize) addLog
("max depth of recursion=" processor.maxDepthOfRecursion) addLog
processor.usedFloatBuiltins [createFloatBuiltins] when
processor.options.callTrace processor.options.threadModel 1 = and createCtors
createDtors
clearUnusedDebugInfo
addAliasesForUsedNodes
i: 0 dynamic;
[
i processor.prolog.dataSize < [
i 1 + @i set TRUE
] &&
] loop
i: 1 dynamic; # 0th node is root fake node
[
i processor.nodes.dataSize < [
currentNode: i @[email protected];
currentNode nodeHasCode [
LF makeStringView @[email protected]
currentNode.header makeStringView @[email protected]
currentNode.nodeCase NodeCaseDeclaration = [currentNode.nodeCase NodeCaseDllDeclaration =] || [
# no body
] [
" {" @[email protected]
currentNode.program [
curInstruction: .value;
curInstruction.enabled [
curInstruction.code makeStringView @[email protected]
] [
] if
] each
"}" @[email protected]
] if
] when
i 1 + @i set TRUE
] &&
] loop
processor.debugInfo.strings [
s: .value;
s.getTextSize 0 = not [
] when
] each
] when
] "process" exportFunction
{
signature: CFunctionSignature Cref;
compilerPositionInfo: CompilerPositionInfo Cref;
multiParserResult: MultiParserResult Cref;
processor: Processor Ref;
processorResult: ProcessorResult Ref;
refToVar: RefToVar Cref;
} () {convention: cdecl;} [
forcedSignature:;
compilerPositionInfo:;
multiParserResult:;
processor:;
processorResult:;
refToVar:;
addCodeNode
codeNode: @[email protected];
indexOfCodeNode: processor.nodes.dataSize 1 -;
currentNode: @codeNode;
indexOfNode: indexOfCodeNode copy;
failProc: @failProcForProcessor;
NodeCaseDtor @codeNode.@nodeCase set
0 dynamic @codeNode.@parent set
@compilerPositionInfo @codeNode.@position set
processor.options.debug [
addDebugReserve @codeNode.@funcDbgIndex set
] when
begin: RefToVar;
end: RefToVar;
refToVar @begin @end ShadowReasonCapture makeShadows
VarStruct refToVar getVar .data.get.get .unableToDie
VarStruct end [email protected].@unableToDie set # fake becouse it is fake shadow
end killStruct
dtorName: ("dtor." refToVar getVar.globalId) assembleString;
dtorNameStringView: dtorName makeStringView;
dtorNameStringView finalizeCodeNode
] "createDtorForGlobalVar" exportFunction