forked from Matway/mpl-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
irWriter.mpl
executable file
·752 lines (621 loc) · 27.9 KB
/
irWriter.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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
"irWriter" module
"control" includeModule
"defaultImpl" includeModule
IRArgument: [{
irTypeId: 0;
irNameId: 0;
byRef: TRUE;
}];
createDerefTo: [
derefNameId:;
refToVar:;
(" " @derefNameId getNameById " = load " refToVar getIrType ", " refToVar getIrType "* " refToVar getIrName) assembleString makeInstruction @[email protected]
];
createDerefToRegister: [
derefName: generateRegisterIRName;
derefName createDerefTo
derefName
];
createAllocIR: [
refToVar:;
var: refToVar getVar;
currentNode.parent 0 = [
(refToVar getIrName " = local_unnamed_addr global " refToVar getIrType " zeroinitializer") assembleString @[email protected]
processor.prolog.dataSize 1 - @var.@globalDeclarationInstructionIndex set
] [
(" " refToVar getIrName " = alloca " refToVar getIrType) assembleString makeInstruction @[email protected]
TRUE @[email protected].@alloca set
currentNode.program.dataSize 1 - @var.@allocationInstructionIndex set
] if
refToVar copy
];
createStaticInitIR: [
refToVar:;
var: refToVar getVar;
[currentNode.parent 0 =] "Can be used only with global vars!" assert
(refToVar getIrName " = local_unnamed_addr global " refToVar getStaticStructIR) assembleString @[email protected]
processor.prolog.dataSize 1 - @var.@globalDeclarationInstructionIndex set
refToVar copy
];
createVarImportIR: [
refToVar:;
var: refToVar getVar;
(refToVar getIrName " = external global " refToVar getIrType) assembleString @[email protected]
processor.prolog.dataSize 1 - @var.@globalDeclarationInstructionIndex set
refToVar copy
];
createVarExportIR: [
refToVar:;
var: refToVar getVar;
(refToVar getIrName " = dllexport global " refToVar getIrType " zeroinitializer") assembleString @[email protected]
processor.prolog.dataSize 1 - @var.@globalDeclarationInstructionIndex set
refToVar copy
];
createAliasIR: [
aliaseeType:;
aliasee:;
alias:;
(" " alias getNameById " = alias " aliaseeType getNameById ", " aliaseeType getNameById "* " aliasee getNameById) assembleString makeInstruction @[email protected]
];
createGlobalAliasIR: [
aliaseeType:;
aliasee:;
alias:;
(alias getNameById " = alias " aliaseeType getNameById ", " aliaseeType getNameById "* " aliasee getNameById) assembleString @[email protected]
];
createFuncAliasIR: [
aliaseeType:;
aliasee:;
alias:;
(alias " = ifunc " aliaseeType ", " aliaseeType "* " aliasee) assembleString
];
createStoreConstant: [
refToDst:;
refWithValue:;
s: refWithValue getPlainConstantIR;
(" store " refToDst getIrType " " s ", " refToDst getIrType "* " refToDst getIrName) assembleString makeInstruction @[email protected]
];
createPlainIR: [
refToVar:;
[refToVar isPlain] "Var is not plain" assert
refToVar refToVar createAllocIR createStoreConstant
refToVar copy
];
getStringImplementation: [
stringView: makeStringView;
[
result: String;
i: 0 dynamic;
[
i stringView.dataSize < [
codeRef: stringView.dataBegin storageAddress i Natx cast + Nat8 addressToReference;
code: codeRef copy;
code 32n8 < not [code 127n8 <] && [code 34n8 = not] && [code 92n8 = not] && [ # exclude " and \
code 0n32 cast @result.catSymbolCode
] [
"\\" @result.cat
code 16n8 < ["0" @result.cat] when
code @result.catHex
] if
i 1 + @i set TRUE
] &&
] loop
result
] call
];
createStringTypeByStringName: [
stringName: makeStringView;
stringNameNoFirst: stringName.getTextSize 1 - stringName.dataBegin storageAddress 1nx + Nat8 addressToReference makeStringViewRaw;
("%type." stringNameNoFirst) assembleString
];
createStringIR: [
refToVar:;
string:;
stringId: processor.lastStringId copy;
stringName: ("@string." processor.lastStringId) assembleString;
stringType: stringName createStringTypeByStringName;
processor.lastStringId 1 + @processor.@lastStringId set
var: refToVar getVar;
@stringName findNameInfo @var.@mplNameId set
("getelementptr inbounds (" stringType ", " stringType "* " stringName ", i32 0, i32 2, i32 0)") assembleString makeStringId @var.@irNameId set
valueImplementation: string makeStringView getStringImplementation;
stringSizeWithZero: string.chars.getSize 0 = [1][string.chars.getSize 0 cast] if;
stringSize: stringSizeWithZero 1 -;
stringSizeCheck: stringSize Nat32 cast 0xDEADBEEFn32 xor;
(stringType " = type {i32, i32, [" stringSizeWithZero " x i8]}"
) assembleString @[email protected]
(stringName " = private unnamed_addr constant " stringType " {i32 " stringSizeCheck ", i32 " stringSize ", [" stringSizeWithZero " x i8] c\"" valueImplementation "\\00\"}"
) assembleString @[email protected]
];
createGetTextSizeIR: [
refToDst:;
refToName:;
int32PtrRegister: generateRegisterIRName;
ptrRegister: generateRegisterIRName;
int32SizeRegister: generateRegisterIRName;
int64SizeRegister: generateRegisterIRName;
(" " int32PtrRegister getNameById " = bitcast i8* " refToName getIrName " to i32*") assembleString makeInstruction @[email protected]
(" " ptrRegister getNameById " = getelementptr i32, i32* " int32PtrRegister getNameById ", i32 -1") assembleString makeInstruction @[email protected]
(" " int32SizeRegister getNameById " = load i32, i32* " ptrRegister getNameById) assembleString makeInstruction @[email protected]
processor.options.pointerSize 64nx = [
(" " int64SizeRegister getNameById " = zext i32 " int32SizeRegister getNameById " to i64") assembleString makeInstruction @[email protected]
int64SizeRegister refToDst createStoreFromRegister
] [
int32SizeRegister refToDst createStoreFromRegister
] if
processor.options.debug [
checkPtrRegister: generateRegisterIRName;
checkInt32SizeRegister: generateRegisterIRName;
xorRegister: generateRegisterIRName;
checkRegister: generateRegisterIRName;
(" " checkPtrRegister getNameById " = getelementptr i32, i32* " int32PtrRegister getNameById ", i32 -2") assembleString makeInstruction @[email protected]
(" " checkInt32SizeRegister getNameById " = load i32, i32* " checkPtrRegister getNameById) assembleString makeInstruction @[email protected]
(" " xorRegister getNameById " = xor i32 " checkInt32SizeRegister getNameById ", " int32SizeRegister getNameById) assembleString makeInstruction @[email protected]
(" " checkRegister getNameById " = icmp eq i32 " xorRegister getNameById ", " 0xDEADBEEFn32) assembleString makeInstruction @[email protected]
(" br i1 " checkRegister getNameById ", label %label" currentNode.lastBrLabelName 1 + ", label %label" currentNode.lastBrLabelName) assembleString makeInstruction @[email protected]
createLabel
"Pointer is not a builtin Text!" createFailWithMessage
1 createJump
createLabel
] when
];
createTypeDeclaration: [
irType:;
alias:;
(@alias " = type " @irType) assembleString @[email protected]
];
createStaticGEP: [
structRefToVar:;
struct: structRefToVar getVar;
copy index:;
resultRefToVar:;
realIndex: index VarStruct struct.data.get.get.realFieldIndexes.at;
(" " resultRefToVar getIrName " = getelementptr " structRefToVar getIrType ", " structRefToVar getIrType "* " structRefToVar getIrName ", i32 0, i32 " realIndex
) assembleString makeInstruction @[email protected]
];
createFailWithMessage: [
message:;
gnr: processor.failProcNameInfo getName;
cnr: gnr captureName;
failProcRefToVar: cnr.refToVar copy;
message toString makeVarString push
failProcRefToVar getVar.data.getTag VarBuiltin = [
#no overload
defaultFailProc
] [
failProcRefToVar derefAndPush
defaultCall
] if
];
createDynamicGEP: [
structRefToVar:;
struct: structRefToVar getVar;
indexRefToVar:;
resultRefToVar:;
indexRegister: indexRefToVar createDerefToRegister;
processor.options.arrayChecks [
structSize: VarStruct struct.data.get.get.fields.getSize; #in homogenius struct it is = realFieldIndex
checkRegister: generateRegisterIRName;
(" " checkRegister getNameById " = icmp ult i32 " indexRegister getNameById ", " structSize) assembleString makeInstruction @[email protected]
(" br i1 " checkRegister getNameById ", label %label" currentNode.lastBrLabelName 1 + ", label %label" currentNode.lastBrLabelName) assembleString makeInstruction @[email protected]
createLabel
"Index is out of bounds!" createFailWithMessage
1 createJump
createLabel
] when
(" " resultRefToVar getIrName " = getelementptr " structRefToVar getIrType ", " structRefToVar getIrType "* " structRefToVar getIrName ", i32 0, i32 " indexRegister getNameById
) assembleString makeInstruction @[email protected]
];
createGEPInsteadOfAlloc: [
struct:;
copy index:;
dstRef:;
dstVar: dstRef getVar;
# create GEP instruction
dstRef index struct createStaticGEP
# change allocation instruction
[dstVar.allocationInstructionIndex currentNode.program.dataSize <] "Var is not allocated!" assert
instruction: dstVar.allocationInstructionIndex @[email protected];
currentNode.program.last @instruction set
FALSE @[email protected].@enabled set
dstVar.allocationInstructionIndex @dstVar.@getInstructionIndex set
-1 @dstVar.@allocationInstructionIndex set
];
createStoreFromRegister: [
destRefToVar:;
regName:;
resultVar: destRefToVar getVar;
(" store " destRefToVar getIrType " " @regName getNameById ", " destRefToVar getIrType "* " destRefToVar getIrName) assembleString makeInstruction @[email protected]
];
createBinaryOperation: [
opName:;
var1p: arg1 createDerefToRegister;
var2p: arg2 createDerefToRegister;
resultReg: generateRegisterIRName;
(" " resultReg getNameById " = " @opName " " arg1 getIrType " " var1p getNameById ", " var2p getNameById) assembleString makeInstruction @[email protected]
resultReg result createStoreFromRegister
];
createBinaryOperationDiffTypes: [
opName:;
var1p: arg1 createDerefToRegister;
var2p: arg2 createDerefToRegister;
castedReg: generateRegisterIRName;
castName: arg1 getStorageSize arg2 getStorageSize > [
arg1 isNat ["zext" makeStringView]["sext" makeStringView] if
] [
"trunc" makeStringView
] if;
(" " castedReg getNameById " = " castName " " arg2 getIrType " " var2p getNameById " to " arg1 getIrType) assembleString makeInstruction @[email protected]
resultReg: generateRegisterIRName;
(" " resultReg getNameById " = " opName " " arg1 getIrType " " var1p getNameById ", " castedReg getNameById) assembleString makeInstruction @[email protected]
resultReg result createStoreFromRegister
];
createDirectBinaryOperation: [
opName:;
result:;
arg2:;
arg1:;
resultReg: generateRegisterIRName;
(" " resultReg getNameById " = " opName " " arg1 getIrType "* " arg1 getIrName ", " arg2 getIrName) assembleString makeInstruction @[email protected]
resultReg result createStoreFromRegister
];
createUnaryOperation: [
mopName:;
opName:;
varp: arg createDerefToRegister;
resultReg: generateRegisterIRName;
(" " resultReg getNameById " = " opName " " arg getIrType " " mopName varp getNameById) assembleString makeInstruction @[email protected]
resultReg result createStoreFromRegister
];
createMemset: [
dstRef:;
srcRef:;
srcRef dstRef setVar
srcRef isVirtual not [
loadReg: srcRef createDerefToRegister;
loadReg dstRef createStoreFromRegister
] when
];
createCheckedCopyToNewWith: [
copy doDie:;
copy dstRef:;
srcRef:;
srcRef isAutoStruct [
srcRef getVar.temporary [
loadReg: srcRef createDerefToRegister;
loadReg dstRef createStoreFromRegister
srcRef markAsUnableToDie
] [
srcRef isForgotten [
srcRef.mutable [
loadReg: srcRef createDerefToRegister;
loadReg dstRef createStoreFromRegister
srcRef callInit
srcRef fullUntemporize
] [
"movable variable is not mutable" makeStringView compilerError
] if
] [
prevMut: dstRef.mutable copy;
TRUE @dstRef.@mutable set
dstRef callInit
srcRef dstRef callAssign
prevMut @dstRef.@mutable set
] if
] if
doDie [dstRef @[email protected]] when
] [
loadReg: srcRef createDerefToRegister;
loadReg dstRef createStoreFromRegister
] if
];
createCheckedCopyToNew: [TRUE dynamic createCheckedCopyToNewWith];
createCheckedCopyToNewNoDie: [FALSE dynamic createCheckedCopyToNewWith];
createCopyToNew: [
newRefToVar:;
newRefToVar isVirtual [
oldRefToVar:;
"unable to copy virtual autostruct" compilerError
] [
newRefToVar createAllocIR createCheckedCopyToNew
] if
];
createCastCopyToNew: [
castName:;
dstRef: createAllocIR;
srcRef:;
loadReg: srcRef createDerefToRegister;
castedReg: generateRegisterIRName;
(" " castedReg getNameById " = " @castName " " srcRef getIrType " " loadReg getNameById " to " dstRef getIrType) assembleString makeInstruction @[email protected]
castedReg dstRef createStoreFromRegister
];
createCastCopyPtrToNew: [
castName:;
dstRef: createAllocIR;
srcRef:;
castedReg: generateRegisterIRName;
(" " castedReg getNameById " = " @castName " " srcRef getIrType "* " srcRef getIrName " to " dstRef getIrType) assembleString makeInstruction @[email protected]
castedReg dstRef createStoreFromRegister
];
createCopyToExists: [
dstRef:;
srcRef:;
srcRef isAutoStruct [
srcRef getVar.temporary [
# die-bytemove is faster than assign-die, I think
processor.options.verboseIR ["set from temporary" createComent] when
dstRef callDie
srcRef dstRef createMemset
srcRef markAsUnableToDie
] [
srcRef isForgotten [
processor.options.verboseIR ["set from moved" createComent] when
dstRef callDie
srcRef dstRef createMemset
srcRef callInit
srcRef fullUntemporize
] [
processor.options.verboseIR ["set; call ASSIGN" createComent] when
srcRef isVirtual [
"unable to copy virtual autostruct" compilerError
] [
srcRef dstRef callAssign
] if
] if
] if
] [
srcRef dstRef createMemset
] if
];
createRefOperation: [
dstRef: createAllocIR;
srcRef:;
srcRef getVar.irNameId dstRef createStoreFromRegister
];
createRetValue: [
refToVar:;
getReg: refToVar createDerefToRegister;
(" ret " refToVar getIrType " " getReg getNameById) assembleString makeInstruction @[email protected]
];
createCallIR: [
funcName:;
conventionName:;
argList:;
refToRet:;
haveRet: refToRet.varId 0 < not;
operation: String;
retName: 0;
processor.options.callTrace [createCallTraceProlog] when
haveRet [
generateRegisterIRName @retName set
(" " @retName getNameById " = call " conventionName refToRet getIrType " ") @operation.catMany
] [
(" call " conventionName "void ") @operation.catMany
] if
@funcName @operation.cat
"(" @operation.cat
i: 0 dynamic;
[
i argList.dataSize < [
currentArg: i argList.at;
i 0 > [", " @operation.cat] when
currentArg.irTypeId getNameById @operation.cat
currentArg.byRef ["*" @operation.cat] when
" " @operation.cat
currentArg.irNameId getNameById @operation.cat
i 1 + @i set TRUE
] &&
] loop
")" @operation.cat
operation makeInstruction @[email protected]
addDebugLocationForLastInstruction
processor.options.callTrace [createCallTraceEpilog] when
retName
];
createLabel: [
("label" currentNode.lastBrLabelName ":") assembleString makeInstruction @[email protected]
currentNode.lastBrLabelName 1 + @currentNode.@lastBrLabelName set
];
createBranch: [
refToCond:;
copy timeShift:;
condReg: refToCond createDerefToRegister;
(" br i1 " condReg getNameById ", label %label" currentNode.lastBrLabelName timeShift - ", label %label" currentNode.lastBrLabelName timeShift - 1 +
) assembleString makeInstruction @[email protected]
];
createJump: [
copy timeShift:;
(" br label %label" currentNode.lastBrLabelName timeShift - 1 +) assembleString makeInstruction @[email protected]
];
createPhiNode: [
copy shift:;
elseName:;
thenName:;
varName:;
varType:;
(" " @varName " = phi " @varType " [ " @thenName ", %label" currentNode.lastBrLabelName 3 - shift + " ], [ " @elseName ", %label" currentNode.lastBrLabelName 2 - shift + " ]"
) assembleString makeInstruction @[email protected]
];
createComent: [
coment: makeStringView;
[
compileOnce
(" ;" coment) assembleString makeInstruction @[email protected]
] call
];
addStrToProlog: [
toString @[email protected]
];
createFloatBuiltins: [
"declare float @llvm.sin.f32(float)" addStrToProlog
"declare double @llvm.sin.f64(double)" addStrToProlog
"declare float @llvm.cos.f32(float)" addStrToProlog
"declare double @llvm.cos.f64(double)" addStrToProlog
"declare float @llvm.floor.f32(float)" addStrToProlog
"declare double @llvm.floor.f64(double)" addStrToProlog
"declare float @llvm.ceil.f32(float)" addStrToProlog
"declare double @llvm.ceil.f64(double)" addStrToProlog
"declare float @llvm.sqrt.f32(float)" addStrToProlog
"declare double @llvm.sqrt.f64(double)" addStrToProlog
"declare float @llvm.log.f32(float)" addStrToProlog
"declare double @llvm.log.f64(double)" addStrToProlog
"declare float @llvm.log10.f32(float)" addStrToProlog
"declare double @llvm.log10.f64(double)" addStrToProlog
"declare float @llvm.pow.f32(float, float)" addStrToProlog
"declare double @llvm.pow.f64(double, double)" addStrToProlog
];
createCtors: [
copy createTlsInit:;
"" addStrToProlog
"@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @global.ctors, i8* null }]" addStrToProlog
"" addStrToProlog
"define internal void @global.ctors() {" addStrToProlog
createTlsInit [
" call void @__tls_init()" toString addStrToProlog
] when
processor.moduleFunctions [
cur: .value processor.nodes.at.get.irName copy;
(" call void " cur "()") assembleString addStrToProlog
] each
" ret void" addStrToProlog
"}" addStrToProlog
];
createDtors: [
"" addStrToProlog
"@llvm.global_dtors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @global.dtors, i8* null }]" addStrToProlog
"" addStrToProlog
"define internal void @global.dtors() {" addStrToProlog
processor.dtorFunctions [
cur: .value processor.nodes.at.get.irName copy;
(" call void " cur "()") assembleString addStrToProlog
] each
" ret void" addStrToProlog
"}" addStrToProlog
];
sortInstructions: [
allocs: Instruction Array;
fakePointersAllocs: Instruction Array;
fakePointers: Instruction Array;
noallocs: Instruction Array;
@currentNode.@program [
pair:;
pair.index 0 = [pair.value.alloca copy] || [
pair.value.fakePointer [
@pair.@value move @fakePointersAllocs.pushBack
] [
@pair.@value move @allocs.pushBack
] if
] [
pair.value.fakePointer [
@pair.@value move @fakePointers.pushBack
] [
@pair.@value move @noallocs.pushBack
] if
] if
] each
@allocs [.@value move @[email protected]] each
@fakePointersAllocs [.@value move @[email protected]] each
@fakePointers [.@value move @[email protected]] each
@noallocs [.@value move @[email protected]] each
];
addAliasesForUsedNodes: [
String @[email protected]
"; Func aliases" toString @[email protected]
@processor.@nodes [
currentNode: [email protected];
currentNode nodeHasCode [
@currentNode.@aliases [.@value move @[email protected]] each
] when
] each
];
createCallTraceData: [
tlPrefix: processor.options.threadModel 1 = ["thread_local "] [""] if;
callTraceDataType: "[65536 x %type.callTraceInfo]" toString;
"%type.callTraceInfo = type {%type.callTraceInfo*, %type.callTraceInfo*, i8*, i32, i32}" toString @[email protected]
("@debug.callTrace = " tlPrefix "unnamed_addr global " callTraceDataType " zeroinitializer") assembleString @[email protected]
("@debug.callTracePtr = " tlPrefix "unnamed_addr global %type.callTraceInfo* getelementptr inbounds (" callTraceDataType ", " callTraceDataType "* @debug.callTrace, i32 0, i32 0)") assembleString @[email protected]
processor.options.threadModel 1 = [
String @[email protected]
"@\"__tls_init$initializer$\" = internal constant void ()* @__tls_init, section \".CRT$XDU\"" toString @[email protected]
"@llvm.used = appending global [1 x i8*] [i8* bitcast (void ()** @\"__tls_init$initializer$\" to i8*)], section \"llvm.metadata\"" toString @[email protected]
String @[email protected]
"define internal void @__tls_init() {" toString @[email protected]
(" store %type.callTraceInfo* getelementptr inbounds (" callTraceDataType ", " callTraceDataType "* @debug.callTrace, i32 0, i32 0), %type.callTraceInfo** @debug.callTracePtr") assembleString @[email protected]
" ret void" toString @[email protected]
"}" toString @[email protected]
String @[email protected]
processor.options.pointerSize 64nx = [
"/include:__dyn_tls_init" toString @processor.@[email protected]
] [
"/include:___dyn_tls_init@12" toString @processor.@[email protected]
] if
] when
];
createCallTraceProlog: [
ptr: generateRegisterIRName;
ptrNext: generateRegisterIRName;
(" " ptr getNameById " = load %type.callTraceInfo*, %type.callTraceInfo** @debug.callTracePtr") assembleString makeInstruction @[email protected]
(" " ptrNext getNameById " = getelementptr inbounds %type.callTraceInfo, %type.callTraceInfo* " ptr getNameById ", i32 1") assembleString makeInstruction @[email protected]
(" store %type.callTraceInfo* " ptrNext getNameById ", %type.callTraceInfo** @debug.callTracePtr") assembleString makeInstruction @[email protected]
currentNode.hasNestedCall not [
#ptr->next = ptrNext
ptrDotNext: generateRegisterIRName;
(" " ptrDotNext getNameById " = getelementptr inbounds %type.callTraceInfo, %type.callTraceInfo* " ptr getNameById ", i32 0, i32 1") assembleString makeInstruction @[email protected]
(" store %type.callTraceInfo* " ptrNext getNameById ", %type.callTraceInfo** " ptrDotNext getNameById) assembleString makeInstruction @[email protected]
#ptrNext->prev = ptr
ptrNextDotPrev: generateRegisterIRName;
(" " ptrNextDotPrev getNameById " = getelementptr inbounds %type.callTraceInfo, %type.callTraceInfo* " ptrNext getNameById ", i32 0, i32 0") assembleString makeInstruction @[email protected]
(" store %type.callTraceInfo* " ptr getNameById ", %type.callTraceInfo** " ptrNextDotPrev getNameById) assembleString makeInstruction @[email protected]
#ptrNext->fileName = fileName
fileNameVar: currentNode.position.fileNumber processor.options.fileNames.at makeVarString;
ptrNextDotName: generateRegisterIRName;
(" " ptrNextDotName getNameById " = getelementptr inbounds %type.callTraceInfo, %type.callTraceInfo* " ptrNext getNameById ", i32 0, i32 2") assembleString makeInstruction @[email protected]
(" store i8* " fileNameVar getIrName ", i8** " ptrNextDotName getNameById) assembleString makeInstruction @[email protected]
TRUE @currentNode.@hasNestedCall set
] when
#ptrNext->line = line
ptrNextDotLine: generateRegisterIRName;
(" " ptrNextDotLine getNameById " = getelementptr inbounds %type.callTraceInfo, %type.callTraceInfo* " ptrNext getNameById ", i32 0, i32 3") assembleString makeInstruction @[email protected]
(" store i32 " currentNode.position.line ", i32* " ptrNextDotLine getNameById) assembleString makeInstruction @[email protected]
#ptrNext->column = column
ptrNextDotColumn: generateRegisterIRName;
(" " ptrNextDotColumn getNameById " = getelementptr inbounds %type.callTraceInfo, %type.callTraceInfo* " ptrNext getNameById ", i32 0, i32 4") assembleString makeInstruction @[email protected]
(" store i32 " currentNode.position.column ", i32* " ptrNextDotColumn getNameById) assembleString makeInstruction @[email protected]
];
createCallTraceEpilog: [
ptr: generateRegisterIRName;
ptrPrev: generateRegisterIRName;
(" " ptr getNameById " = load %type.callTraceInfo*, %type.callTraceInfo** @debug.callTracePtr") assembleString makeInstruction @[email protected]
(" " ptrPrev getNameById " = getelementptr inbounds %type.callTraceInfo, %type.callTraceInfo* " ptr getNameById ", i32 -1") assembleString makeInstruction @[email protected]
(" store %type.callTraceInfo* " ptrPrev getNameById ", %type.callTraceInfo** @debug.callTracePtr") assembleString makeInstruction @[email protected]
];
createGetCallTrace: [
variable:;
copy variableIrType:;
copy infoIrType:;
processor.options.callTrace [
callTraceDataType: "[65536 x %type.callTraceInfo]" toString;
ptrFirstSrc: generateRegisterIRName;
ptrFirstCast: generateRegisterIRName;
ptrFirstDst: generateRegisterIRName;
(" " ptrFirstSrc getNameById " = getelementptr inbounds " callTraceDataType ", " callTraceDataType "* @debug.callTrace, i32 0, i32 0") assembleString makeInstruction @[email protected]
(" " ptrFirstDst getNameById " = getelementptr inbounds " variableIrType ", " variableIrType "* " variable getIrName ", i32 0, i32 0") assembleString makeInstruction @[email protected]
(" " ptrFirstCast getNameById " = bitcast %type.callTraceInfo* " ptrFirstSrc getNameById " to " infoIrType "*") assembleString makeInstruction @[email protected]
(" store " infoIrType "* " ptrFirstCast getNameById ", " infoIrType "** " ptrFirstDst getNameById) assembleString makeInstruction @[email protected]
ptrLastSrc: generateRegisterIRName;
ptrLastCast: generateRegisterIRName;
ptrLastDst: generateRegisterIRName;
(" " ptrLastSrc getNameById " = load %type.callTraceInfo*, %type.callTraceInfo** @debug.callTracePtr") assembleString makeInstruction @[email protected]
(" " ptrLastDst getNameById " = getelementptr inbounds " variableIrType ", " variableIrType "* " variable getIrName ", i32 0, i32 1") assembleString makeInstruction @[email protected]
(" " ptrLastCast getNameById " = bitcast %type.callTraceInfo* " ptrLastSrc getNameById " to " infoIrType "*") assembleString makeInstruction @[email protected]
(" store " infoIrType "* " ptrLastCast getNameById ", " infoIrType "** " ptrLastDst getNameById) assembleString makeInstruction @[email protected]
] [
ptrFirstDst: generateRegisterIRName;
(" " ptrFirstDst getNameById " = getelementptr inbounds " variableIrType ", " variableIrType "* " variable getIrName ", i32 0, i32 0") assembleString makeInstruction @[email protected]
(" store " infoIrType "* null, " infoIrType "** " ptrFirstDst getNameById) assembleString makeInstruction @[email protected]
ptrLastDst: generateRegisterIRName;
(" " ptrLastDst getNameById " = getelementptr inbounds " variableIrType ", " variableIrType "* " variable getIrName ", i32 0, i32 1") assembleString makeInstruction @[email protected]
(" store " infoIrType "* null, " infoIrType "** " ptrLastDst getNameById) assembleString makeInstruction @[email protected]
] if
];