-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathastgen.cpp
8339 lines (7000 loc) · 369 KB
/
astgen.cpp
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
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2021 Andrew Kelley
*
* This file is part of zig, which is MIT licensed.
* See http://opensource.org/licenses/MIT
*/
#include "astgen.hpp"
#include "analyze.hpp"
#include "util.hpp"
#include "os.hpp"
#include "parser.hpp"
struct Stage1AstGen {
CodeGen *codegen;
Stage1Zir *exec;
Stage1ZirBasicBlock *current_basic_block;
AstNode *main_block_node;
size_t next_debug_id;
ZigFn *fn;
bool in_c_import_scope;
};
static Stage1ZirInst *astgen_node(Stage1AstGen *ag, AstNode *node, Scope *scope);
static Stage1ZirInst *astgen_node_extra(Stage1AstGen *ag, AstNode *node, Scope *scope, LVal lval,
ResultLoc *result_loc);
static Stage1ZirInst *ir_lval_wrap(Stage1AstGen *ag, Scope *scope, Stage1ZirInst *value, LVal lval,
ResultLoc *result_loc);
static Stage1ZirInst *ir_expr_wrap(Stage1AstGen *ag, Scope *scope, Stage1ZirInst *inst,
ResultLoc *result_loc);
static Stage1ZirInst *astgen_union_init_expr(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
Stage1ZirInst *union_type, Stage1ZirInst *field_name, AstNode *expr_node,
LVal lval, ResultLoc *parent_result_loc);
static ResultLocCast *ir_build_cast_result_loc(Stage1AstGen *ag, Stage1ZirInst *dest_type,
ResultLoc *parent_result_loc);
static ZigVar *ir_create_var(Stage1AstGen *ag, AstNode *node, Scope *scope, Buf *name,
bool src_is_const, bool gen_is_const, bool is_shadowable, Stage1ZirInst *is_comptime);
static void build_decl_var_and_init(Stage1AstGen *ag, Scope *scope, AstNode *source_node,
ZigVar *var, Stage1ZirInst *init, const char *name_hint, Stage1ZirInst *is_comptime);
static void ir_assert_impl(bool ok, Stage1ZirInst *source_instruction, char const *file, unsigned int line) {
if (ok) return;
src_assert_impl(ok, source_instruction->source_node, file, line);
}
static ErrorMsg *exec_add_error_node(CodeGen *codegen, Stage1Zir *exec, AstNode *source_node, Buf *msg) {
ErrorMsg *err_msg = add_node_error(codegen, source_node, msg);
invalidate_exec(exec, err_msg);
return err_msg;
}
#define ir_assert(OK, SOURCE_INSTRUCTION) ir_assert_impl((OK), (SOURCE_INSTRUCTION), __FILE__, __LINE__)
static bool instr_is_unreachable(Stage1ZirInst *instruction) {
switch (instruction->id) {
case Stage1ZirInstIdCondBr:
case Stage1ZirInstIdReturn:
case Stage1ZirInstIdBr:
case Stage1ZirInstIdUnreachable:
case Stage1ZirInstIdSwitchBr:
case Stage1ZirInstIdPanic:
return true;
default:
return false;
}
}
void destroy_instruction_src(Stage1ZirInst *inst) {
switch (inst->id) {
case Stage1ZirInstIdInvalid:
zig_unreachable();
case Stage1ZirInstIdReturn:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstReturn *>(inst));
case Stage1ZirInstIdConst:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstConst *>(inst));
case Stage1ZirInstIdBinOp:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstBinOp *>(inst));
case Stage1ZirInstIdMergeErrSets:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstMergeErrSets *>(inst));
case Stage1ZirInstIdDeclVar:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstDeclVar *>(inst));
case Stage1ZirInstIdCall:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstCall *>(inst));
case Stage1ZirInstIdCallExtra:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstCallExtra *>(inst));
case Stage1ZirInstIdAsyncCallExtra:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstAsyncCallExtra *>(inst));
case Stage1ZirInstIdUnOp:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstUnOp *>(inst));
case Stage1ZirInstIdCondBr:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstCondBr *>(inst));
case Stage1ZirInstIdBr:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstBr *>(inst));
case Stage1ZirInstIdPhi:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstPhi *>(inst));
case Stage1ZirInstIdContainerInitList:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstContainerInitList *>(inst));
case Stage1ZirInstIdContainerInitFields:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstContainerInitFields *>(inst));
case Stage1ZirInstIdUnreachable:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstUnreachable *>(inst));
case Stage1ZirInstIdElemPtr:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstElemPtr *>(inst));
case Stage1ZirInstIdVarPtr:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstVarPtr *>(inst));
case Stage1ZirInstIdLoadPtr:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstLoadPtr *>(inst));
case Stage1ZirInstIdStorePtr:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstStorePtr *>(inst));
case Stage1ZirInstIdTypeOf:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstTypeOf *>(inst));
case Stage1ZirInstIdFieldPtr:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstFieldPtr *>(inst));
case Stage1ZirInstIdSetCold:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstSetCold *>(inst));
case Stage1ZirInstIdSetRuntimeSafety:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstSetRuntimeSafety *>(inst));
case Stage1ZirInstIdSetFloatMode:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstSetFloatMode *>(inst));
case Stage1ZirInstIdArrayType:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstArrayType *>(inst));
case Stage1ZirInstIdSliceType:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstSliceType *>(inst));
case Stage1ZirInstIdAnyFrameType:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstAnyFrameType *>(inst));
case Stage1ZirInstIdAsm:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstAsm *>(inst));
case Stage1ZirInstIdSizeOf:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstSizeOf *>(inst));
case Stage1ZirInstIdTestNonNull:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstTestNonNull *>(inst));
case Stage1ZirInstIdOptionalUnwrapPtr:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstOptionalUnwrapPtr *>(inst));
case Stage1ZirInstIdPopCount:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstPopCount *>(inst));
case Stage1ZirInstIdClz:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstClz *>(inst));
case Stage1ZirInstIdCtz:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstCtz *>(inst));
case Stage1ZirInstIdBswap:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstBswap *>(inst));
case Stage1ZirInstIdBitReverse:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstBitReverse *>(inst));
case Stage1ZirInstIdSwitchBr:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstSwitchBr *>(inst));
case Stage1ZirInstIdSwitchVar:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstSwitchVar *>(inst));
case Stage1ZirInstIdSwitchElseVar:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstSwitchElseVar *>(inst));
case Stage1ZirInstIdSwitchTarget:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstSwitchTarget *>(inst));
case Stage1ZirInstIdImport:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstImport *>(inst));
case Stage1ZirInstIdRef:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstRef *>(inst));
case Stage1ZirInstIdCompileErr:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstCompileErr *>(inst));
case Stage1ZirInstIdCompileLog:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstCompileLog *>(inst));
case Stage1ZirInstIdErrName:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstErrName *>(inst));
case Stage1ZirInstIdCImport:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstCImport *>(inst));
case Stage1ZirInstIdCInclude:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstCInclude *>(inst));
case Stage1ZirInstIdCDefine:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstCDefine *>(inst));
case Stage1ZirInstIdCUndef:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstCUndef *>(inst));
case Stage1ZirInstIdEmbedFile:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstEmbedFile *>(inst));
case Stage1ZirInstIdCmpxchg:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstCmpxchg *>(inst));
case Stage1ZirInstIdFence:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstFence *>(inst));
case Stage1ZirInstIdReduce:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstReduce *>(inst));
case Stage1ZirInstIdTruncate:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstTruncate *>(inst));
case Stage1ZirInstIdIntCast:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstIntCast *>(inst));
case Stage1ZirInstIdFloatCast:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstFloatCast *>(inst));
case Stage1ZirInstIdErrSetCast:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstErrSetCast *>(inst));
case Stage1ZirInstIdIntToFloat:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstIntToFloat *>(inst));
case Stage1ZirInstIdFloatToInt:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstFloatToInt *>(inst));
case Stage1ZirInstIdBoolToInt:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstBoolToInt *>(inst));
case Stage1ZirInstIdVectorType:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstVectorType *>(inst));
case Stage1ZirInstIdShuffleVector:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstShuffleVector *>(inst));
case Stage1ZirInstIdSelect:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstSelect *>(inst));
case Stage1ZirInstIdSplat:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstSplat *>(inst));
case Stage1ZirInstIdBoolNot:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstBoolNot *>(inst));
case Stage1ZirInstIdMemset:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstMemset *>(inst));
case Stage1ZirInstIdMemcpy:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstMemcpy *>(inst));
case Stage1ZirInstIdSlice:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstSlice *>(inst));
case Stage1ZirInstIdBreakpoint:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstBreakpoint *>(inst));
case Stage1ZirInstIdReturnAddress:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstReturnAddress *>(inst));
case Stage1ZirInstIdFrameAddress:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstFrameAddress *>(inst));
case Stage1ZirInstIdFrameHandle:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstFrameHandle *>(inst));
case Stage1ZirInstIdFrameType:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstFrameType *>(inst));
case Stage1ZirInstIdFrameSize:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstFrameSize *>(inst));
case Stage1ZirInstIdAlignOf:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstAlignOf *>(inst));
case Stage1ZirInstIdOverflowOp:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstOverflowOp *>(inst));
case Stage1ZirInstIdTestErr:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstTestErr *>(inst));
case Stage1ZirInstIdUnwrapErrCode:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstUnwrapErrCode *>(inst));
case Stage1ZirInstIdUnwrapErrPayload:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstUnwrapErrPayload *>(inst));
case Stage1ZirInstIdFnProto:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstFnProto *>(inst));
case Stage1ZirInstIdTestComptime:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstTestComptime *>(inst));
case Stage1ZirInstIdPtrCast:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstPtrCast *>(inst));
case Stage1ZirInstIdBitCast:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstBitCast *>(inst));
case Stage1ZirInstIdPtrToInt:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstPtrToInt *>(inst));
case Stage1ZirInstIdIntToPtr:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstIntToPtr *>(inst));
case Stage1ZirInstIdIntToEnum:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstIntToEnum *>(inst));
case Stage1ZirInstIdIntToErr:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstIntToErr *>(inst));
case Stage1ZirInstIdErrToInt:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstErrToInt *>(inst));
case Stage1ZirInstIdCheckSwitchProngsUnderNo:
case Stage1ZirInstIdCheckSwitchProngsUnderYes:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstCheckSwitchProngs *>(inst));
case Stage1ZirInstIdCheckStatementIsVoid:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstCheckStatementIsVoid *>(inst));
case Stage1ZirInstIdTypeName:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstTypeName *>(inst));
case Stage1ZirInstIdTagName:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstTagName *>(inst));
case Stage1ZirInstIdPtrType:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstPtrType *>(inst));
case Stage1ZirInstIdPtrTypeSimple:
case Stage1ZirInstIdPtrTypeSimpleConst:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstPtrTypeSimple *>(inst));
case Stage1ZirInstIdDeclRef:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstDeclRef *>(inst));
case Stage1ZirInstIdPanic:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstPanic *>(inst));
case Stage1ZirInstIdFieldParentPtr:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstFieldParentPtr *>(inst));
case Stage1ZirInstIdOffsetOf:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstOffsetOf *>(inst));
case Stage1ZirInstIdBitOffsetOf:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstBitOffsetOf *>(inst));
case Stage1ZirInstIdTypeInfo:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstTypeInfo *>(inst));
case Stage1ZirInstIdType:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstType *>(inst));
case Stage1ZirInstIdHasField:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstHasField *>(inst));
case Stage1ZirInstIdSetEvalBranchQuota:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstSetEvalBranchQuota *>(inst));
case Stage1ZirInstIdAlignCast:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstAlignCast *>(inst));
case Stage1ZirInstIdImplicitCast:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstImplicitCast *>(inst));
case Stage1ZirInstIdResolveResult:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstResolveResult *>(inst));
case Stage1ZirInstIdResetResult:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstResetResult *>(inst));
case Stage1ZirInstIdSetAlignStack:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstSetAlignStack *>(inst));
case Stage1ZirInstIdArgTypeAllowVarFalse:
case Stage1ZirInstIdArgTypeAllowVarTrue:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstArgType *>(inst));
case Stage1ZirInstIdExport:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstExport *>(inst));
case Stage1ZirInstIdExtern:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstExtern *>(inst));
case Stage1ZirInstIdErrorReturnTrace:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstErrorReturnTrace *>(inst));
case Stage1ZirInstIdErrorUnion:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstErrorUnion *>(inst));
case Stage1ZirInstIdAtomicRmw:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstAtomicRmw *>(inst));
case Stage1ZirInstIdSaveErrRetAddr:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstSaveErrRetAddr *>(inst));
case Stage1ZirInstIdAddImplicitReturnType:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstAddImplicitReturnType *>(inst));
case Stage1ZirInstIdFloatOp:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstFloatOp *>(inst));
case Stage1ZirInstIdMulAdd:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstMulAdd *>(inst));
case Stage1ZirInstIdAtomicLoad:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstAtomicLoad *>(inst));
case Stage1ZirInstIdAtomicStore:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstAtomicStore *>(inst));
case Stage1ZirInstIdEnumToInt:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstEnumToInt *>(inst));
case Stage1ZirInstIdCheckRuntimeScope:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstCheckRuntimeScope *>(inst));
case Stage1ZirInstIdHasDecl:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstHasDecl *>(inst));
case Stage1ZirInstIdUndeclaredIdent:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstUndeclaredIdent *>(inst));
case Stage1ZirInstIdAlloca:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstAlloca *>(inst));
case Stage1ZirInstIdEndExpr:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstEndExpr *>(inst));
case Stage1ZirInstIdUnionInitNamedField:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstUnionInitNamedField *>(inst));
case Stage1ZirInstIdSuspendBegin:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstSuspendBegin *>(inst));
case Stage1ZirInstIdSuspendFinish:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstSuspendFinish *>(inst));
case Stage1ZirInstIdResume:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstResume *>(inst));
case Stage1ZirInstIdAwait:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstAwait *>(inst));
case Stage1ZirInstIdSpillBegin:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstSpillBegin *>(inst));
case Stage1ZirInstIdSpillEnd:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstSpillEnd *>(inst));
case Stage1ZirInstIdCallArgs:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstCallArgs *>(inst));
case Stage1ZirInstIdWasmMemorySize:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstWasmMemorySize *>(inst));
case Stage1ZirInstIdWasmMemoryGrow:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstWasmMemoryGrow *>(inst));
case Stage1ZirInstIdSrc:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstSrc *>(inst));
case Stage1ZirInstIdPrefetch:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstPrefetch *>(inst));
case Stage1ZirInstIdAddrSpaceCast:
return heap::c_allocator.destroy(reinterpret_cast<Stage1ZirInstAddrSpaceCast *>(inst));
}
zig_unreachable();
}
bool ir_should_inline(Stage1Zir *exec, Scope *scope) {
if (exec->is_inline)
return true;
while (scope != nullptr) {
if (scope->id == ScopeIdCompTime)
return true;
if (scope->id == ScopeIdTypeOf)
return false;
if (scope->id == ScopeIdFnDef)
break;
scope = scope->parent;
}
return false;
}
static void ir_instruction_append(Stage1ZirBasicBlock *basic_block, Stage1ZirInst *instruction) {
assert(basic_block);
assert(instruction);
basic_block->instruction_list.append(instruction);
}
static size_t irb_next_debug_id(Stage1AstGen *ag) {
size_t result = ag->next_debug_id;
ag->next_debug_id += 1;
return result;
}
static void ir_ref_bb(Stage1ZirBasicBlock *bb) {
bb->ref_count += 1;
}
static void ir_ref_instruction(Stage1ZirInst *instruction, Stage1ZirBasicBlock *cur_bb) {
assert(instruction->id != Stage1ZirInstIdInvalid);
instruction->ref_count += 1;
if (instruction->owner_bb != cur_bb && !instr_is_unreachable(instruction)
&& instruction->id != Stage1ZirInstIdConst)
{
ir_ref_bb(instruction->owner_bb);
}
}
static Stage1ZirBasicBlock *ir_create_basic_block(Stage1AstGen *ag, Scope *scope, const char *name_hint) {
Stage1ZirBasicBlock *result = heap::c_allocator.create<Stage1ZirBasicBlock>();
result->scope = scope;
result->name_hint = name_hint;
result->debug_id = irb_next_debug_id(ag);
result->index = UINT32_MAX; // set later
return result;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstDeclVar *) {
return Stage1ZirInstIdDeclVar;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstBr *) {
return Stage1ZirInstIdBr;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstCondBr *) {
return Stage1ZirInstIdCondBr;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstSwitchBr *) {
return Stage1ZirInstIdSwitchBr;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstSwitchVar *) {
return Stage1ZirInstIdSwitchVar;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstSwitchElseVar *) {
return Stage1ZirInstIdSwitchElseVar;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstSwitchTarget *) {
return Stage1ZirInstIdSwitchTarget;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstPhi *) {
return Stage1ZirInstIdPhi;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstUnOp *) {
return Stage1ZirInstIdUnOp;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstBinOp *) {
return Stage1ZirInstIdBinOp;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstMergeErrSets *) {
return Stage1ZirInstIdMergeErrSets;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstLoadPtr *) {
return Stage1ZirInstIdLoadPtr;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstStorePtr *) {
return Stage1ZirInstIdStorePtr;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstFieldPtr *) {
return Stage1ZirInstIdFieldPtr;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstElemPtr *) {
return Stage1ZirInstIdElemPtr;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstVarPtr *) {
return Stage1ZirInstIdVarPtr;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstCall *) {
return Stage1ZirInstIdCall;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstCallArgs *) {
return Stage1ZirInstIdCallArgs;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstCallExtra *) {
return Stage1ZirInstIdCallExtra;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstAsyncCallExtra *) {
return Stage1ZirInstIdAsyncCallExtra;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstConst *) {
return Stage1ZirInstIdConst;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstReturn *) {
return Stage1ZirInstIdReturn;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstContainerInitList *) {
return Stage1ZirInstIdContainerInitList;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstContainerInitFields *) {
return Stage1ZirInstIdContainerInitFields;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstUnreachable *) {
return Stage1ZirInstIdUnreachable;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstTypeOf *) {
return Stage1ZirInstIdTypeOf;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstSetCold *) {
return Stage1ZirInstIdSetCold;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstSetRuntimeSafety *) {
return Stage1ZirInstIdSetRuntimeSafety;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstSetFloatMode *) {
return Stage1ZirInstIdSetFloatMode;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstArrayType *) {
return Stage1ZirInstIdArrayType;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstAnyFrameType *) {
return Stage1ZirInstIdAnyFrameType;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstSliceType *) {
return Stage1ZirInstIdSliceType;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstAsm *) {
return Stage1ZirInstIdAsm;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstSizeOf *) {
return Stage1ZirInstIdSizeOf;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstTestNonNull *) {
return Stage1ZirInstIdTestNonNull;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstOptionalUnwrapPtr *) {
return Stage1ZirInstIdOptionalUnwrapPtr;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstClz *) {
return Stage1ZirInstIdClz;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstCtz *) {
return Stage1ZirInstIdCtz;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstPopCount *) {
return Stage1ZirInstIdPopCount;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstBswap *) {
return Stage1ZirInstIdBswap;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstBitReverse *) {
return Stage1ZirInstIdBitReverse;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstImport *) {
return Stage1ZirInstIdImport;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstCImport *) {
return Stage1ZirInstIdCImport;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstCInclude *) {
return Stage1ZirInstIdCInclude;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstCDefine *) {
return Stage1ZirInstIdCDefine;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstCUndef *) {
return Stage1ZirInstIdCUndef;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstRef *) {
return Stage1ZirInstIdRef;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstCompileErr *) {
return Stage1ZirInstIdCompileErr;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstCompileLog *) {
return Stage1ZirInstIdCompileLog;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstErrName *) {
return Stage1ZirInstIdErrName;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstEmbedFile *) {
return Stage1ZirInstIdEmbedFile;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstCmpxchg *) {
return Stage1ZirInstIdCmpxchg;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstFence *) {
return Stage1ZirInstIdFence;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstReduce *) {
return Stage1ZirInstIdReduce;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstTruncate *) {
return Stage1ZirInstIdTruncate;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstIntCast *) {
return Stage1ZirInstIdIntCast;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstFloatCast *) {
return Stage1ZirInstIdFloatCast;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstIntToFloat *) {
return Stage1ZirInstIdIntToFloat;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstFloatToInt *) {
return Stage1ZirInstIdFloatToInt;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstBoolToInt *) {
return Stage1ZirInstIdBoolToInt;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstVectorType *) {
return Stage1ZirInstIdVectorType;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstShuffleVector *) {
return Stage1ZirInstIdShuffleVector;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstSelect *) {
return Stage1ZirInstIdSelect;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstSplat *) {
return Stage1ZirInstIdSplat;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstBoolNot *) {
return Stage1ZirInstIdBoolNot;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstMemset *) {
return Stage1ZirInstIdMemset;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstMemcpy *) {
return Stage1ZirInstIdMemcpy;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstSlice *) {
return Stage1ZirInstIdSlice;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstBreakpoint *) {
return Stage1ZirInstIdBreakpoint;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstReturnAddress *) {
return Stage1ZirInstIdReturnAddress;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstFrameAddress *) {
return Stage1ZirInstIdFrameAddress;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstFrameHandle *) {
return Stage1ZirInstIdFrameHandle;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstFrameType *) {
return Stage1ZirInstIdFrameType;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstFrameSize *) {
return Stage1ZirInstIdFrameSize;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstAlignOf *) {
return Stage1ZirInstIdAlignOf;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstOverflowOp *) {
return Stage1ZirInstIdOverflowOp;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstTestErr *) {
return Stage1ZirInstIdTestErr;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstMulAdd *) {
return Stage1ZirInstIdMulAdd;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstFloatOp *) {
return Stage1ZirInstIdFloatOp;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstUnwrapErrCode *) {
return Stage1ZirInstIdUnwrapErrCode;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstUnwrapErrPayload *) {
return Stage1ZirInstIdUnwrapErrPayload;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstFnProto *) {
return Stage1ZirInstIdFnProto;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstTestComptime *) {
return Stage1ZirInstIdTestComptime;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstPtrCast *) {
return Stage1ZirInstIdPtrCast;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstBitCast *) {
return Stage1ZirInstIdBitCast;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstIntToPtr *) {
return Stage1ZirInstIdIntToPtr;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstPtrToInt *) {
return Stage1ZirInstIdPtrToInt;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstIntToEnum *) {
return Stage1ZirInstIdIntToEnum;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstEnumToInt *) {
return Stage1ZirInstIdEnumToInt;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstIntToErr *) {
return Stage1ZirInstIdIntToErr;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstErrToInt *) {
return Stage1ZirInstIdErrToInt;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstCheckStatementIsVoid *) {
return Stage1ZirInstIdCheckStatementIsVoid;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstTypeName *) {
return Stage1ZirInstIdTypeName;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstDeclRef *) {
return Stage1ZirInstIdDeclRef;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstPanic *) {
return Stage1ZirInstIdPanic;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstTagName *) {
return Stage1ZirInstIdTagName;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstFieldParentPtr *) {
return Stage1ZirInstIdFieldParentPtr;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstOffsetOf *) {
return Stage1ZirInstIdOffsetOf;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstBitOffsetOf *) {
return Stage1ZirInstIdBitOffsetOf;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstTypeInfo *) {
return Stage1ZirInstIdTypeInfo;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstType *) {
return Stage1ZirInstIdType;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstHasField *) {
return Stage1ZirInstIdHasField;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstSetEvalBranchQuota *) {
return Stage1ZirInstIdSetEvalBranchQuota;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstPtrType *) {
return Stage1ZirInstIdPtrType;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstAlignCast *) {
return Stage1ZirInstIdAlignCast;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstImplicitCast *) {
return Stage1ZirInstIdImplicitCast;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstResolveResult *) {
return Stage1ZirInstIdResolveResult;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstResetResult *) {
return Stage1ZirInstIdResetResult;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstSetAlignStack *) {
return Stage1ZirInstIdSetAlignStack;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstExport *) {
return Stage1ZirInstIdExport;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstExtern *) {
return Stage1ZirInstIdExtern;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstErrorReturnTrace *) {
return Stage1ZirInstIdErrorReturnTrace;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstErrorUnion *) {
return Stage1ZirInstIdErrorUnion;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstAtomicRmw *) {
return Stage1ZirInstIdAtomicRmw;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstAtomicLoad *) {
return Stage1ZirInstIdAtomicLoad;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstAtomicStore *) {
return Stage1ZirInstIdAtomicStore;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstSaveErrRetAddr *) {
return Stage1ZirInstIdSaveErrRetAddr;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstAddImplicitReturnType *) {
return Stage1ZirInstIdAddImplicitReturnType;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstErrSetCast *) {
return Stage1ZirInstIdErrSetCast;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstCheckRuntimeScope *) {
return Stage1ZirInstIdCheckRuntimeScope;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstHasDecl *) {
return Stage1ZirInstIdHasDecl;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstUndeclaredIdent *) {
return Stage1ZirInstIdUndeclaredIdent;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstAlloca *) {
return Stage1ZirInstIdAlloca;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstEndExpr *) {
return Stage1ZirInstIdEndExpr;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstUnionInitNamedField *) {
return Stage1ZirInstIdUnionInitNamedField;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstSuspendBegin *) {
return Stage1ZirInstIdSuspendBegin;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstSuspendFinish *) {
return Stage1ZirInstIdSuspendFinish;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstAwait *) {
return Stage1ZirInstIdAwait;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstResume *) {
return Stage1ZirInstIdResume;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstSpillBegin *) {
return Stage1ZirInstIdSpillBegin;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstSpillEnd *) {
return Stage1ZirInstIdSpillEnd;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstWasmMemorySize *) {
return Stage1ZirInstIdWasmMemorySize;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstWasmMemoryGrow *) {
return Stage1ZirInstIdWasmMemoryGrow;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstSrc *) {
return Stage1ZirInstIdSrc;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstPrefetch *) {
return Stage1ZirInstIdPrefetch;
}
static constexpr Stage1ZirInstId ir_inst_id(Stage1ZirInstAddrSpaceCast *) {
return Stage1ZirInstIdAddrSpaceCast;
}
template<typename T>
static T *ir_create_instruction(Stage1AstGen *ag, Scope *scope, AstNode *source_node) {
T *special_instruction = heap::c_allocator.create<T>();
special_instruction->base.id = ir_inst_id(special_instruction);
special_instruction->base.scope = scope;
special_instruction->base.source_node = source_node;
special_instruction->base.debug_id = irb_next_debug_id(ag);
special_instruction->base.owner_bb = ag->current_basic_block;
return special_instruction;
}
template<typename T>
static T *ir_build_instruction(Stage1AstGen *ag, Scope *scope, AstNode *source_node) {
T *special_instruction = ir_create_instruction<T>(ag, scope, source_node);
ir_instruction_append(ag->current_basic_block, &special_instruction->base);
return special_instruction;
}
static Stage1ZirInst *ir_build_cond_br(Stage1AstGen *ag, Scope *scope, AstNode *source_node, Stage1ZirInst *condition,
Stage1ZirBasicBlock *then_block, Stage1ZirBasicBlock *else_block, Stage1ZirInst *is_comptime)
{
Stage1ZirInstCondBr *inst = ir_build_instruction<Stage1ZirInstCondBr>(ag, scope, source_node);
inst->condition = condition;
inst->then_block = then_block;
inst->else_block = else_block;
inst->is_comptime = is_comptime;
ir_ref_instruction(condition, ag->current_basic_block);
ir_ref_bb(then_block);
ir_ref_bb(else_block);
if (is_comptime != nullptr) ir_ref_instruction(is_comptime, ag->current_basic_block);
return &inst->base;
}
static Stage1ZirInst *ir_build_return_src(Stage1AstGen *ag, Scope *scope, AstNode *source_node, Stage1ZirInst *operand) {
Stage1ZirInstReturn *inst = ir_build_instruction<Stage1ZirInstReturn>(ag, scope, source_node);
inst->operand = operand;
if (operand != nullptr) ir_ref_instruction(operand, ag->current_basic_block);
return &inst->base;
}
static Stage1ZirInst *ir_build_const_void(Stage1AstGen *ag, Scope *scope, AstNode *source_node) {