Branch data Line data Source code
1 : : /*
2 : : * Copyright (c) 2016 Andrew Kelley
3 : : *
4 : : * This file is part of zig, which is MIT licensed.
5 : : * See http://opensource.org/licenses/MIT
6 : : */
7 : :
8 : : #include "analyze.hpp"
9 : : #include "ir.hpp"
10 : : #include "ir_print.hpp"
11 : : #include "os.hpp"
12 : :
13 : 0 : static uint32_t hash_instruction_ptr(IrInstruction* instruction) {
14 : 0 : return (uint32_t)(uintptr_t)instruction;
15 : : }
16 : :
17 : 0 : static bool instruction_ptr_equal(IrInstruction* a, IrInstruction* b) {
18 : 0 : return a == b;
19 : : }
20 : :
21 : : using InstructionSet = HashMap<IrInstruction*, uint8_t, hash_instruction_ptr, instruction_ptr_equal>;
22 : : using InstructionList = ZigList<IrInstruction*>;
23 : :
24 : : struct IrPrint {
25 : : IrPass pass;
26 : : CodeGen *codegen;
27 : : FILE *f;
28 : : int indent;
29 : : int indent_size;
30 : :
31 : : // When printing pass 2 instructions referenced var instructions are not
32 : : // present in the instruction list. Thus we track which instructions
33 : : // are printed (per executable) and after each pass 2 instruction those
34 : : // var instructions are rendered in a trailing fashion.
35 : : InstructionSet printed;
36 : : InstructionList pending;
37 : : };
38 : :
39 : : static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction);
40 : :
41 : 0 : static const char* ir_instruction_type_str(IrInstruction* instruction) {
42 [ # # # # : 0 : switch (instruction->id) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
43 : 0 : case IrInstructionIdInvalid:
44 : 0 : return "Invalid";
45 : 0 : case IrInstructionIdDeclVarSrc:
46 : 0 : return "DeclVarSrc";
47 : 0 : case IrInstructionIdDeclVarGen:
48 : 0 : return "DeclVarGen";
49 : 0 : case IrInstructionIdBr:
50 : 0 : return "Br";
51 : 0 : case IrInstructionIdCondBr:
52 : 0 : return "CondBr";
53 : 0 : case IrInstructionIdSwitchBr:
54 : 0 : return "SwitchBr";
55 : 0 : case IrInstructionIdSwitchVar:
56 : 0 : return "SwitchVar";
57 : 0 : case IrInstructionIdSwitchElseVar:
58 : 0 : return "SwitchElseVar";
59 : 0 : case IrInstructionIdSwitchTarget:
60 : 0 : return "SwitchTarget";
61 : 0 : case IrInstructionIdPhi:
62 : 0 : return "Phi";
63 : 0 : case IrInstructionIdUnOp:
64 : 0 : return "UnOp";
65 : 0 : case IrInstructionIdBinOp:
66 : 0 : return "BinOp";
67 : 0 : case IrInstructionIdLoadPtr:
68 : 0 : return "LoadPtr";
69 : 0 : case IrInstructionIdLoadPtrGen:
70 : 0 : return "LoadPtrGen";
71 : 0 : case IrInstructionIdStorePtr:
72 : 0 : return "StorePtr";
73 : 0 : case IrInstructionIdFieldPtr:
74 : 0 : return "FieldPtr";
75 : 0 : case IrInstructionIdStructFieldPtr:
76 : 0 : return "StructFieldPtr";
77 : 0 : case IrInstructionIdUnionFieldPtr:
78 : 0 : return "UnionFieldPtr";
79 : 0 : case IrInstructionIdElemPtr:
80 : 0 : return "ElemPtr";
81 : 0 : case IrInstructionIdVarPtr:
82 : 0 : return "VarPtr";
83 : 0 : case IrInstructionIdReturnPtr:
84 : 0 : return "ReturnPtr";
85 : 0 : case IrInstructionIdCallSrc:
86 : 0 : return "CallSrc";
87 : 0 : case IrInstructionIdCallGen:
88 : 0 : return "CallGen";
89 : 0 : case IrInstructionIdConst:
90 : 0 : return "Const";
91 : 0 : case IrInstructionIdReturn:
92 : 0 : return "Return";
93 : 0 : case IrInstructionIdCast:
94 : 0 : return "Cast";
95 : 0 : case IrInstructionIdResizeSlice:
96 : 0 : return "ResizeSlice";
97 : 0 : case IrInstructionIdContainerInitList:
98 : 0 : return "ContainerInitList";
99 : 0 : case IrInstructionIdContainerInitFields:
100 : 0 : return "ContainerInitFields";
101 : 0 : case IrInstructionIdUnreachable:
102 : 0 : return "Unreachable";
103 : 0 : case IrInstructionIdTypeOf:
104 : 0 : return "TypeOf";
105 : 0 : case IrInstructionIdSetCold:
106 : 0 : return "SetCold";
107 : 0 : case IrInstructionIdSetRuntimeSafety:
108 : 0 : return "SetRuntimeSafety";
109 : 0 : case IrInstructionIdSetFloatMode:
110 : 0 : return "SetFloatMode";
111 : 0 : case IrInstructionIdArrayType:
112 : 0 : return "ArrayType";
113 : 0 : case IrInstructionIdAnyFrameType:
114 : 0 : return "AnyFrameType";
115 : 0 : case IrInstructionIdSliceType:
116 : 0 : return "SliceType";
117 : 0 : case IrInstructionIdGlobalAsm:
118 : 0 : return "GlobalAsm";
119 : 0 : case IrInstructionIdAsm:
120 : 0 : return "Asm";
121 : 0 : case IrInstructionIdSizeOf:
122 : 0 : return "SizeOf";
123 : 0 : case IrInstructionIdTestNonNull:
124 : 0 : return "TestNonNull";
125 : 0 : case IrInstructionIdOptionalUnwrapPtr:
126 : 0 : return "OptionalUnwrapPtr";
127 : 0 : case IrInstructionIdOptionalWrap:
128 : 0 : return "OptionalWrap";
129 : 0 : case IrInstructionIdUnionTag:
130 : 0 : return "UnionTag";
131 : 0 : case IrInstructionIdClz:
132 : 0 : return "Clz";
133 : 0 : case IrInstructionIdCtz:
134 : 0 : return "Ctz";
135 : 0 : case IrInstructionIdPopCount:
136 : 0 : return "PopCount";
137 : 0 : case IrInstructionIdBswap:
138 : 0 : return "Bswap";
139 : 0 : case IrInstructionIdBitReverse:
140 : 0 : return "BitReverse";
141 : 0 : case IrInstructionIdImport:
142 : 0 : return "Import";
143 : 0 : case IrInstructionIdCImport:
144 : 0 : return "CImport";
145 : 0 : case IrInstructionIdCInclude:
146 : 0 : return "CInclude";
147 : 0 : case IrInstructionIdCDefine:
148 : 0 : return "CDefine";
149 : 0 : case IrInstructionIdCUndef:
150 : 0 : return "CUndef";
151 : 0 : case IrInstructionIdRef:
152 : 0 : return "Ref";
153 : 0 : case IrInstructionIdRefGen:
154 : 0 : return "RefGen";
155 : 0 : case IrInstructionIdCompileErr:
156 : 0 : return "CompileErr";
157 : 0 : case IrInstructionIdCompileLog:
158 : 0 : return "CompileLog";
159 : 0 : case IrInstructionIdErrName:
160 : 0 : return "ErrName";
161 : 0 : case IrInstructionIdEmbedFile:
162 : 0 : return "EmbedFile";
163 : 0 : case IrInstructionIdCmpxchgSrc:
164 : 0 : return "CmpxchgSrc";
165 : 0 : case IrInstructionIdCmpxchgGen:
166 : 0 : return "CmpxchgGen";
167 : 0 : case IrInstructionIdFence:
168 : 0 : return "Fence";
169 : 0 : case IrInstructionIdTruncate:
170 : 0 : return "Truncate";
171 : 0 : case IrInstructionIdIntCast:
172 : 0 : return "IntCast";
173 : 0 : case IrInstructionIdFloatCast:
174 : 0 : return "FloatCast";
175 : 0 : case IrInstructionIdIntToFloat:
176 : 0 : return "IntToFloat";
177 : 0 : case IrInstructionIdFloatToInt:
178 : 0 : return "FloatToInt";
179 : 0 : case IrInstructionIdBoolToInt:
180 : 0 : return "BoolToInt";
181 : 0 : case IrInstructionIdIntType:
182 : 0 : return "IntType";
183 : 0 : case IrInstructionIdVectorType:
184 : 0 : return "VectorType";
185 : 0 : case IrInstructionIdBoolNot:
186 : 0 : return "BoolNot";
187 : 0 : case IrInstructionIdMemset:
188 : 0 : return "Memset";
189 : 0 : case IrInstructionIdMemcpy:
190 : 0 : return "Memcpy";
191 : 0 : case IrInstructionIdSliceSrc:
192 : 0 : return "SliceSrc";
193 : 0 : case IrInstructionIdSliceGen:
194 : 0 : return "SliceGen";
195 : 0 : case IrInstructionIdMemberCount:
196 : 0 : return "MemberCount";
197 : 0 : case IrInstructionIdMemberType:
198 : 0 : return "MemberType";
199 : 0 : case IrInstructionIdMemberName:
200 : 0 : return "MemberName";
201 : 0 : case IrInstructionIdBreakpoint:
202 : 0 : return "Breakpoint";
203 : 0 : case IrInstructionIdReturnAddress:
204 : 0 : return "ReturnAddress";
205 : 0 : case IrInstructionIdFrameAddress:
206 : 0 : return "FrameAddress";
207 : 0 : case IrInstructionIdFrameHandle:
208 : 0 : return "FrameHandle";
209 : 0 : case IrInstructionIdFrameType:
210 : 0 : return "FrameType";
211 : 0 : case IrInstructionIdFrameSizeSrc:
212 : 0 : return "FrameSizeSrc";
213 : 0 : case IrInstructionIdFrameSizeGen:
214 : 0 : return "FrameSizeGen";
215 : 0 : case IrInstructionIdAlignOf:
216 : 0 : return "AlignOf";
217 : 0 : case IrInstructionIdOverflowOp:
218 : 0 : return "OverflowOp";
219 : 0 : case IrInstructionIdTestErrSrc:
220 : 0 : return "TestErrSrc";
221 : 0 : case IrInstructionIdTestErrGen:
222 : 0 : return "TestErrGen";
223 : 0 : case IrInstructionIdMulAdd:
224 : 0 : return "MulAdd";
225 : 0 : case IrInstructionIdFloatOp:
226 : 0 : return "FloatOp";
227 : 0 : case IrInstructionIdUnwrapErrCode:
228 : 0 : return "UnwrapErrCode";
229 : 0 : case IrInstructionIdUnwrapErrPayload:
230 : 0 : return "UnwrapErrPayload";
231 : 0 : case IrInstructionIdErrWrapCode:
232 : 0 : return "ErrWrapCode";
233 : 0 : case IrInstructionIdErrWrapPayload:
234 : 0 : return "ErrWrapPayload";
235 : 0 : case IrInstructionIdFnProto:
236 : 0 : return "FnProto";
237 : 0 : case IrInstructionIdTestComptime:
238 : 0 : return "TestComptime";
239 : 0 : case IrInstructionIdPtrCastSrc:
240 : 0 : return "PtrCastSrc";
241 : 0 : case IrInstructionIdPtrCastGen:
242 : 0 : return "PtrCastGen";
243 : 0 : case IrInstructionIdBitCastSrc:
244 : 0 : return "BitCastSrc";
245 : 0 : case IrInstructionIdBitCastGen:
246 : 0 : return "BitCastGen";
247 : 0 : case IrInstructionIdWidenOrShorten:
248 : 0 : return "WidenOrShorten";
249 : 0 : case IrInstructionIdIntToPtr:
250 : 0 : return "IntToPtr";
251 : 0 : case IrInstructionIdPtrToInt:
252 : 0 : return "PtrToInt";
253 : 0 : case IrInstructionIdIntToEnum:
254 : 0 : return "IntToEnum";
255 : 0 : case IrInstructionIdEnumToInt:
256 : 0 : return "EnumToInt";
257 : 0 : case IrInstructionIdIntToErr:
258 : 0 : return "IntToErr";
259 : 0 : case IrInstructionIdErrToInt:
260 : 0 : return "ErrToInt";
261 : 0 : case IrInstructionIdCheckSwitchProngs:
262 : 0 : return "CheckSwitchProngs";
263 : 0 : case IrInstructionIdCheckStatementIsVoid:
264 : 0 : return "CheckStatementIsVoid";
265 : 0 : case IrInstructionIdTypeName:
266 : 0 : return "TypeName";
267 : 0 : case IrInstructionIdDeclRef:
268 : 0 : return "DeclRef";
269 : 0 : case IrInstructionIdPanic:
270 : 0 : return "Panic";
271 : 0 : case IrInstructionIdTagName:
272 : 0 : return "TagName";
273 : 0 : case IrInstructionIdTagType:
274 : 0 : return "TagType";
275 : 0 : case IrInstructionIdFieldParentPtr:
276 : 0 : return "FieldParentPtr";
277 : 0 : case IrInstructionIdByteOffsetOf:
278 : 0 : return "ByteOffsetOf";
279 : 0 : case IrInstructionIdBitOffsetOf:
280 : 0 : return "BitOffsetOf";
281 : 0 : case IrInstructionIdTypeInfo:
282 : 0 : return "TypeInfo";
283 : 0 : case IrInstructionIdType:
284 : 0 : return "Type";
285 : 0 : case IrInstructionIdHasField:
286 : 0 : return "HasField";
287 : 0 : case IrInstructionIdTypeId:
288 : 0 : return "TypeId";
289 : 0 : case IrInstructionIdSetEvalBranchQuota:
290 : 0 : return "SetEvalBranchQuota";
291 : 0 : case IrInstructionIdPtrType:
292 : 0 : return "PtrType";
293 : 0 : case IrInstructionIdAlignCast:
294 : 0 : return "AlignCast";
295 : 0 : case IrInstructionIdImplicitCast:
296 : 0 : return "ImplicitCast";
297 : 0 : case IrInstructionIdResolveResult:
298 : 0 : return "ResolveResult";
299 : 0 : case IrInstructionIdResetResult:
300 : 0 : return "ResetResult";
301 : 0 : case IrInstructionIdOpaqueType:
302 : 0 : return "OpaqueType";
303 : 0 : case IrInstructionIdSetAlignStack:
304 : 0 : return "SetAlignStack";
305 : 0 : case IrInstructionIdArgType:
306 : 0 : return "ArgType";
307 : 0 : case IrInstructionIdExport:
308 : 0 : return "Export";
309 : 0 : case IrInstructionIdErrorReturnTrace:
310 : 0 : return "ErrorReturnTrace";
311 : 0 : case IrInstructionIdErrorUnion:
312 : 0 : return "ErrorUnion";
313 : 0 : case IrInstructionIdAtomicRmw:
314 : 0 : return "AtomicRmw";
315 : 0 : case IrInstructionIdAtomicLoad:
316 : 0 : return "AtomicLoad";
317 : 0 : case IrInstructionIdSaveErrRetAddr:
318 : 0 : return "SaveErrRetAddr";
319 : 0 : case IrInstructionIdAddImplicitReturnType:
320 : 0 : return "AddImplicitReturnType";
321 : 0 : case IrInstructionIdErrSetCast:
322 : 0 : return "ErrSetCast";
323 : 0 : case IrInstructionIdToBytes:
324 : 0 : return "ToBytes";
325 : 0 : case IrInstructionIdFromBytes:
326 : 0 : return "FromBytes";
327 : 0 : case IrInstructionIdCheckRuntimeScope:
328 : 0 : return "CheckRuntimeScope";
329 : 0 : case IrInstructionIdVectorToArray:
330 : 0 : return "VectorToArray";
331 : 0 : case IrInstructionIdArrayToVector:
332 : 0 : return "ArrayToVector";
333 : 0 : case IrInstructionIdAssertZero:
334 : 0 : return "AssertZero";
335 : 0 : case IrInstructionIdAssertNonNull:
336 : 0 : return "AssertNonNull";
337 : 0 : case IrInstructionIdHasDecl:
338 : 0 : return "HasDecl";
339 : 0 : case IrInstructionIdUndeclaredIdent:
340 : 0 : return "UndeclaredIdent";
341 : 0 : case IrInstructionIdAllocaSrc:
342 : 0 : return "AllocaSrc";
343 : 0 : case IrInstructionIdAllocaGen:
344 : 0 : return "AllocaGen";
345 : 0 : case IrInstructionIdEndExpr:
346 : 0 : return "EndExpr";
347 : 0 : case IrInstructionIdPtrOfArrayToSlice:
348 : 0 : return "PtrOfArrayToSlice";
349 : 0 : case IrInstructionIdUnionInitNamedField:
350 : 0 : return "UnionInitNamedField";
351 : 0 : case IrInstructionIdSuspendBegin:
352 : 0 : return "SuspendBegin";
353 : 0 : case IrInstructionIdSuspendFinish:
354 : 0 : return "SuspendFinish";
355 : 0 : case IrInstructionIdAwaitSrc:
356 : 0 : return "AwaitSrc";
357 : 0 : case IrInstructionIdAwaitGen:
358 : 0 : return "AwaitGen";
359 : 0 : case IrInstructionIdResume:
360 : 0 : return "Resume";
361 : 0 : case IrInstructionIdSpillBegin:
362 : 0 : return "SpillBegin";
363 : 0 : case IrInstructionIdSpillEnd:
364 : 0 : return "SpillEnd";
365 : : }
366 : 0 : zig_unreachable();
367 : : }
368 : :
369 : 0 : static void ir_print_indent(IrPrint *irp) {
370 [ # # ]: 0 : for (int i = 0; i < irp->indent; i += 1) {
371 : 0 : fprintf(irp->f, " ");
372 : : }
373 : 0 : }
374 : :
375 : 0 : static void ir_print_prefix(IrPrint *irp, IrInstruction *instruction, bool trailing) {
376 : 0 : ir_print_indent(irp);
377 [ # # ]: 0 : const char mark = trailing ? ':' : '#';
378 [ # # ]: 0 : const char *type_name = instruction->value.type ? buf_ptr(&instruction->value.type->name) : "(unknown)";
379 [ # # ]: 0 : const char *ref_count = ir_has_side_effects(instruction) ?
380 : 0 : "-" : buf_ptr(buf_sprintf("%" ZIG_PRI_usize "", instruction->ref_count));
381 : 0 : fprintf(irp->f, "%c%-3zu| %-22s| %-12s| %-2s| ", mark, instruction->debug_id,
382 : : ir_instruction_type_str(instruction), type_name, ref_count);
383 : 0 : }
384 : :
385 : 0 : static void ir_print_const_value(IrPrint *irp, ConstExprValue *const_val) {
386 : 0 : Buf buf = BUF_INIT;
387 : 0 : buf_resize(&buf, 0);
388 : 0 : render_const_value(irp->codegen, &buf, const_val);
389 : 0 : fprintf(irp->f, "%s", buf_ptr(&buf));
390 : 0 : }
391 : :
392 : 0 : static void ir_print_var_instruction(IrPrint *irp, IrInstruction *instruction) {
393 : 0 : fprintf(irp->f, "#%" ZIG_PRI_usize "", instruction->debug_id);
394 [ # # ][ # # ]: 0 : if (irp->pass != IrPassSrc && irp->printed.maybe_get(instruction) == nullptr) {
[ # # ]
395 : 0 : irp->printed.put(instruction, 0);
396 : 0 : irp->pending.append(instruction);
397 : : }
398 : 0 : }
399 : :
400 : 0 : static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction) {
401 [ # # ]: 0 : if (instruction == nullptr) {
402 : 0 : fprintf(irp->f, "(null)");
403 : 0 : return;
404 : : }
405 : :
406 [ # # ]: 0 : if (instruction->value.special != ConstValSpecialRuntime) {
407 : 0 : ir_print_const_value(irp, &instruction->value);
408 : : } else {
409 : 0 : ir_print_var_instruction(irp, instruction);
410 : : }
411 : : }
412 : :
413 : 0 : static void ir_print_other_block(IrPrint *irp, IrBasicBlock *bb) {
414 [ # # ]: 0 : if (bb == nullptr) {
415 : 0 : fprintf(irp->f, "(null block)");
416 : : } else {
417 : 0 : fprintf(irp->f, "$%s_%" ZIG_PRI_usize "", bb->name_hint, bb->debug_id);
418 : : }
419 : 0 : }
420 : :
421 : 0 : static void ir_print_return(IrPrint *irp, IrInstructionReturn *instruction) {
422 : 0 : fprintf(irp->f, "return ");
423 : 0 : ir_print_other_instruction(irp, instruction->operand);
424 : 0 : }
425 : :
426 : 0 : static void ir_print_const(IrPrint *irp, IrInstructionConst *const_instruction) {
427 : 0 : ir_print_const_value(irp, &const_instruction->base.value);
428 : 0 : }
429 : :
430 : 0 : static const char *ir_bin_op_id_str(IrBinOp op_id) {
431 [ # # # # : 0 : switch (op_id) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
432 : 0 : case IrBinOpInvalid:
433 : 0 : zig_unreachable();
434 : 0 : case IrBinOpBoolOr:
435 : 0 : return "BoolOr";
436 : 0 : case IrBinOpBoolAnd:
437 : 0 : return "BoolAnd";
438 : 0 : case IrBinOpCmpEq:
439 : 0 : return "==";
440 : 0 : case IrBinOpCmpNotEq:
441 : 0 : return "!=";
442 : 0 : case IrBinOpCmpLessThan:
443 : 0 : return "<";
444 : 0 : case IrBinOpCmpGreaterThan:
445 : 0 : return ">";
446 : 0 : case IrBinOpCmpLessOrEq:
447 : 0 : return "<=";
448 : 0 : case IrBinOpCmpGreaterOrEq:
449 : 0 : return ">=";
450 : 0 : case IrBinOpBinOr:
451 : 0 : return "|";
452 : 0 : case IrBinOpBinXor:
453 : 0 : return "^";
454 : 0 : case IrBinOpBinAnd:
455 : 0 : return "&";
456 : 0 : case IrBinOpBitShiftLeftLossy:
457 : 0 : return "<<";
458 : 0 : case IrBinOpBitShiftLeftExact:
459 : 0 : return "@shlExact";
460 : 0 : case IrBinOpBitShiftRightLossy:
461 : 0 : return ">>";
462 : 0 : case IrBinOpBitShiftRightExact:
463 : 0 : return "@shrExact";
464 : 0 : case IrBinOpAdd:
465 : 0 : return "+";
466 : 0 : case IrBinOpAddWrap:
467 : 0 : return "+%";
468 : 0 : case IrBinOpSub:
469 : 0 : return "-";
470 : 0 : case IrBinOpSubWrap:
471 : 0 : return "-%";
472 : 0 : case IrBinOpMult:
473 : 0 : return "*";
474 : 0 : case IrBinOpMultWrap:
475 : 0 : return "*%";
476 : 0 : case IrBinOpDivUnspecified:
477 : 0 : return "/";
478 : 0 : case IrBinOpDivTrunc:
479 : 0 : return "@divTrunc";
480 : 0 : case IrBinOpDivFloor:
481 : 0 : return "@divFloor";
482 : 0 : case IrBinOpDivExact:
483 : 0 : return "@divExact";
484 : 0 : case IrBinOpRemUnspecified:
485 : 0 : return "%";
486 : 0 : case IrBinOpRemRem:
487 : 0 : return "@rem";
488 : 0 : case IrBinOpRemMod:
489 : 0 : return "@mod";
490 : 0 : case IrBinOpArrayCat:
491 : 0 : return "++";
492 : 0 : case IrBinOpArrayMult:
493 : 0 : return "**";
494 : 0 : case IrBinOpMergeErrorSets:
495 : 0 : return "||";
496 : : }
497 : 0 : zig_unreachable();
498 : : }
499 : :
500 : 0 : static const char *ir_un_op_id_str(IrUnOp op_id) {
501 [ # # # # : 0 : switch (op_id) {
# # # ]
502 : 0 : case IrUnOpInvalid:
503 : 0 : zig_unreachable();
504 : 0 : case IrUnOpBinNot:
505 : 0 : return "~";
506 : 0 : case IrUnOpNegation:
507 : 0 : return "-";
508 : 0 : case IrUnOpNegationWrap:
509 : 0 : return "-%";
510 : 0 : case IrUnOpDereference:
511 : 0 : return "*";
512 : 0 : case IrUnOpOptional:
513 : 0 : return "?";
514 : : }
515 : 0 : zig_unreachable();
516 : : }
517 : :
518 : 0 : static void ir_print_un_op(IrPrint *irp, IrInstructionUnOp *un_op_instruction) {
519 : 0 : fprintf(irp->f, "%s ", ir_un_op_id_str(un_op_instruction->op_id));
520 : 0 : ir_print_other_instruction(irp, un_op_instruction->value);
521 : 0 : }
522 : :
523 : 0 : static void ir_print_bin_op(IrPrint *irp, IrInstructionBinOp *bin_op_instruction) {
524 : 0 : ir_print_other_instruction(irp, bin_op_instruction->op1);
525 : 0 : fprintf(irp->f, " %s ", ir_bin_op_id_str(bin_op_instruction->op_id));
526 : 0 : ir_print_other_instruction(irp, bin_op_instruction->op2);
527 [ # # ]: 0 : if (!bin_op_instruction->safety_check_on) {
528 : 0 : fprintf(irp->f, " // no safety");
529 : : }
530 : 0 : }
531 : :
532 : 0 : static void ir_print_decl_var_src(IrPrint *irp, IrInstructionDeclVarSrc *decl_var_instruction) {
533 [ # # ]: 0 : const char *var_or_const = decl_var_instruction->var->gen_is_const ? "const" : "var";
534 : 0 : const char *name = buf_ptr(&decl_var_instruction->var->name);
535 [ # # ]: 0 : if (decl_var_instruction->var_type) {
536 : 0 : fprintf(irp->f, "%s %s: ", var_or_const, name);
537 : 0 : ir_print_other_instruction(irp, decl_var_instruction->var_type);
538 : 0 : fprintf(irp->f, " ");
539 : : } else {
540 : 0 : fprintf(irp->f, "%s %s ", var_or_const, name);
541 : : }
542 [ # # ]: 0 : if (decl_var_instruction->align_value) {
543 : 0 : fprintf(irp->f, "align ");
544 : 0 : ir_print_other_instruction(irp, decl_var_instruction->align_value);
545 : 0 : fprintf(irp->f, " ");
546 : : }
547 : 0 : fprintf(irp->f, "= ");
548 : 0 : ir_print_other_instruction(irp, decl_var_instruction->ptr);
549 [ # # ]: 0 : if (decl_var_instruction->var->is_comptime != nullptr) {
550 : 0 : fprintf(irp->f, " // comptime = ");
551 : 0 : ir_print_other_instruction(irp, decl_var_instruction->var->is_comptime);
552 : : }
553 : 0 : }
554 : :
555 : 0 : static void ir_print_cast(IrPrint *irp, IrInstructionCast *cast_instruction) {
556 : 0 : fprintf(irp->f, "cast ");
557 : 0 : ir_print_other_instruction(irp, cast_instruction->value);
558 : 0 : fprintf(irp->f, " to %s", buf_ptr(&cast_instruction->dest_type->name));
559 : 0 : }
560 : :
561 : 0 : static void ir_print_result_loc_var(IrPrint *irp, ResultLocVar *result_loc_var) {
562 : 0 : fprintf(irp->f, "var(");
563 : 0 : ir_print_other_instruction(irp, result_loc_var->base.source_instruction);
564 : 0 : fprintf(irp->f, ")");
565 : 0 : }
566 : :
567 : 0 : static void ir_print_result_loc_instruction(IrPrint *irp, ResultLocInstruction *result_loc_inst) {
568 : 0 : fprintf(irp->f, "inst(");
569 : 0 : ir_print_other_instruction(irp, result_loc_inst->base.source_instruction);
570 : 0 : fprintf(irp->f, ")");
571 : 0 : }
572 : :
573 : 0 : static void ir_print_result_loc_peer(IrPrint *irp, ResultLocPeer *result_loc_peer) {
574 : 0 : fprintf(irp->f, "peer(next=");
575 : 0 : ir_print_other_block(irp, result_loc_peer->next_bb);
576 : 0 : fprintf(irp->f, ")");
577 : 0 : }
578 : :
579 : 0 : static void ir_print_result_loc_bit_cast(IrPrint *irp, ResultLocBitCast *result_loc_bit_cast) {
580 : 0 : fprintf(irp->f, "bitcast(ty=");
581 : 0 : ir_print_other_instruction(irp, result_loc_bit_cast->base.source_instruction);
582 : 0 : fprintf(irp->f, ")");
583 : 0 : }
584 : :
585 : 0 : static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {
586 [ # # # # : 0 : switch (result_loc->id) {
# # # #
# ]
587 : 0 : case ResultLocIdInvalid:
588 : 0 : zig_unreachable();
589 : 0 : case ResultLocIdNone:
590 : 0 : fprintf(irp->f, "none");
591 : 0 : return;
592 : 0 : case ResultLocIdReturn:
593 : 0 : fprintf(irp->f, "return");
594 : 0 : return;
595 : 0 : case ResultLocIdVar:
596 : 0 : return ir_print_result_loc_var(irp, (ResultLocVar *)result_loc);
597 : 0 : case ResultLocIdInstruction:
598 : 0 : return ir_print_result_loc_instruction(irp, (ResultLocInstruction *)result_loc);
599 : 0 : case ResultLocIdPeer:
600 : 0 : return ir_print_result_loc_peer(irp, (ResultLocPeer *)result_loc);
601 : 0 : case ResultLocIdBitCast:
602 : 0 : return ir_print_result_loc_bit_cast(irp, (ResultLocBitCast *)result_loc);
603 : 0 : case ResultLocIdPeerParent:
604 : 0 : fprintf(irp->f, "peer_parent");
605 : 0 : return;
606 : : }
607 : 0 : zig_unreachable();
608 : : }
609 : :
610 : 0 : static void ir_print_call_src(IrPrint *irp, IrInstructionCallSrc *call_instruction) {
611 [ # # ]: 0 : if (call_instruction->is_async) {
612 : 0 : fprintf(irp->f, "async ");
613 : : }
614 [ # # ]: 0 : if (call_instruction->fn_entry) {
615 : 0 : fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));
616 : : } else {
617 : 0 : assert(call_instruction->fn_ref);
618 : 0 : ir_print_other_instruction(irp, call_instruction->fn_ref);
619 : : }
620 : 0 : fprintf(irp->f, "(");
621 [ # # ]: 0 : for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
622 : 0 : IrInstruction *arg = call_instruction->args[i];
623 [ # # ]: 0 : if (i != 0)
624 : 0 : fprintf(irp->f, ", ");
625 : 0 : ir_print_other_instruction(irp, arg);
626 : : }
627 : 0 : fprintf(irp->f, ")result=");
628 : 0 : ir_print_result_loc(irp, call_instruction->result_loc);
629 : 0 : }
630 : :
631 : 0 : static void ir_print_call_gen(IrPrint *irp, IrInstructionCallGen *call_instruction) {
632 [ # # ]: 0 : if (call_instruction->is_async) {
633 : 0 : fprintf(irp->f, "async ");
634 : : }
635 [ # # ]: 0 : if (call_instruction->fn_entry) {
636 : 0 : fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));
637 : : } else {
638 : 0 : assert(call_instruction->fn_ref);
639 : 0 : ir_print_other_instruction(irp, call_instruction->fn_ref);
640 : : }
641 : 0 : fprintf(irp->f, "(");
642 [ # # ]: 0 : for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
643 : 0 : IrInstruction *arg = call_instruction->args[i];
644 [ # # ]: 0 : if (i != 0)
645 : 0 : fprintf(irp->f, ", ");
646 : 0 : ir_print_other_instruction(irp, arg);
647 : : }
648 : 0 : fprintf(irp->f, ")result=");
649 : 0 : ir_print_other_instruction(irp, call_instruction->result_loc);
650 : 0 : }
651 : :
652 : 0 : static void ir_print_cond_br(IrPrint *irp, IrInstructionCondBr *cond_br_instruction) {
653 : 0 : fprintf(irp->f, "if (");
654 : 0 : ir_print_other_instruction(irp, cond_br_instruction->condition);
655 : 0 : fprintf(irp->f, ") ");
656 : 0 : ir_print_other_block(irp, cond_br_instruction->then_block);
657 : 0 : fprintf(irp->f, " else ");
658 : 0 : ir_print_other_block(irp, cond_br_instruction->else_block);
659 [ # # ]: 0 : if (cond_br_instruction->is_comptime != nullptr) {
660 : 0 : fprintf(irp->f, " // comptime = ");
661 : 0 : ir_print_other_instruction(irp, cond_br_instruction->is_comptime);
662 : : }
663 : 0 : }
664 : :
665 : 0 : static void ir_print_br(IrPrint *irp, IrInstructionBr *br_instruction) {
666 : 0 : fprintf(irp->f, "goto ");
667 : 0 : ir_print_other_block(irp, br_instruction->dest_block);
668 [ # # ]: 0 : if (br_instruction->is_comptime != nullptr) {
669 : 0 : fprintf(irp->f, " // comptime = ");
670 : 0 : ir_print_other_instruction(irp, br_instruction->is_comptime);
671 : : }
672 : 0 : }
673 : :
674 : 0 : static void ir_print_phi(IrPrint *irp, IrInstructionPhi *phi_instruction) {
675 : 0 : assert(phi_instruction->incoming_count != 0);
676 : 0 : assert(phi_instruction->incoming_count != SIZE_MAX);
677 [ # # ]: 0 : for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {
678 : 0 : IrBasicBlock *incoming_block = phi_instruction->incoming_blocks[i];
679 : 0 : IrInstruction *incoming_value = phi_instruction->incoming_values[i];
680 [ # # ]: 0 : if (i != 0)
681 : 0 : fprintf(irp->f, " ");
682 : 0 : ir_print_other_block(irp, incoming_block);
683 : 0 : fprintf(irp->f, ":");
684 : 0 : ir_print_other_instruction(irp, incoming_value);
685 : : }
686 : 0 : }
687 : :
688 : 0 : static void ir_print_container_init_list(IrPrint *irp, IrInstructionContainerInitList *instruction) {
689 : 0 : ir_print_other_instruction(irp, instruction->container_type);
690 : 0 : fprintf(irp->f, "{");
691 [ # # ]: 0 : if (instruction->item_count > 50) {
692 : 0 : fprintf(irp->f, "...(%" ZIG_PRI_usize " items)...", instruction->item_count);
693 : : } else {
694 [ # # ]: 0 : for (size_t i = 0; i < instruction->item_count; i += 1) {
695 : 0 : IrInstruction *result_loc = instruction->elem_result_loc_list[i];
696 [ # # ]: 0 : if (i != 0)
697 : 0 : fprintf(irp->f, ", ");
698 : 0 : ir_print_other_instruction(irp, result_loc);
699 : : }
700 : : }
701 : 0 : fprintf(irp->f, "}");
702 : 0 : }
703 : :
704 : 0 : static void ir_print_container_init_fields(IrPrint *irp, IrInstructionContainerInitFields *instruction) {
705 : 0 : ir_print_other_instruction(irp, instruction->container_type);
706 : 0 : fprintf(irp->f, "{");
707 [ # # ]: 0 : for (size_t i = 0; i < instruction->field_count; i += 1) {
708 : 0 : IrInstructionContainerInitFieldsField *field = &instruction->fields[i];
709 [ # # ]: 0 : const char *comma = (i == 0) ? "" : ", ";
710 : 0 : fprintf(irp->f, "%s.%s = ", comma, buf_ptr(field->name));
711 : 0 : ir_print_other_instruction(irp, field->result_loc);
712 : : }
713 : 0 : fprintf(irp->f, "} // container init");
714 : 0 : }
715 : :
716 : 0 : static void ir_print_unreachable(IrPrint *irp, IrInstructionUnreachable *instruction) {
717 : 0 : fprintf(irp->f, "unreachable");
718 : 0 : }
719 : :
720 : 0 : static void ir_print_elem_ptr(IrPrint *irp, IrInstructionElemPtr *instruction) {
721 : 0 : fprintf(irp->f, "&");
722 : 0 : ir_print_other_instruction(irp, instruction->array_ptr);
723 : 0 : fprintf(irp->f, "[");
724 : 0 : ir_print_other_instruction(irp, instruction->elem_index);
725 : 0 : fprintf(irp->f, "]");
726 [ # # ]: 0 : if (!instruction->safety_check_on) {
727 : 0 : fprintf(irp->f, " // no safety");
728 : : }
729 : 0 : }
730 : :
731 : 0 : static void ir_print_var_ptr(IrPrint *irp, IrInstructionVarPtr *instruction) {
732 : 0 : fprintf(irp->f, "&%s", buf_ptr(&instruction->var->name));
733 : 0 : }
734 : :
735 : 0 : static void ir_print_return_ptr(IrPrint *irp, IrInstructionReturnPtr *instruction) {
736 : 0 : fprintf(irp->f, "@ReturnPtr");
737 : 0 : }
738 : :
739 : 0 : static void ir_print_load_ptr(IrPrint *irp, IrInstructionLoadPtr *instruction) {
740 : 0 : ir_print_other_instruction(irp, instruction->ptr);
741 : 0 : fprintf(irp->f, ".*");
742 : 0 : }
743 : :
744 : 0 : static void ir_print_load_ptr_gen(IrPrint *irp, IrInstructionLoadPtrGen *instruction) {
745 : 0 : fprintf(irp->f, "loadptr(");
746 : 0 : ir_print_other_instruction(irp, instruction->ptr);
747 : 0 : fprintf(irp->f, ")result=");
748 : 0 : ir_print_other_instruction(irp, instruction->result_loc);
749 : 0 : }
750 : :
751 : 0 : static void ir_print_store_ptr(IrPrint *irp, IrInstructionStorePtr *instruction) {
752 : 0 : fprintf(irp->f, "*");
753 : 0 : ir_print_var_instruction(irp, instruction->ptr);
754 : 0 : fprintf(irp->f, " = ");
755 : 0 : ir_print_other_instruction(irp, instruction->value);
756 : 0 : }
757 : :
758 : 0 : static void ir_print_typeof(IrPrint *irp, IrInstructionTypeOf *instruction) {
759 : 0 : fprintf(irp->f, "@typeOf(");
760 : 0 : ir_print_other_instruction(irp, instruction->value);
761 : 0 : fprintf(irp->f, ")");
762 : 0 : }
763 : :
764 : 0 : static void ir_print_field_ptr(IrPrint *irp, IrInstructionFieldPtr *instruction) {
765 [ # # ]: 0 : if (instruction->field_name_buffer) {
766 : 0 : fprintf(irp->f, "fieldptr ");
767 : 0 : ir_print_other_instruction(irp, instruction->container_ptr);
768 : 0 : fprintf(irp->f, ".%s", buf_ptr(instruction->field_name_buffer));
769 : : } else {
770 : 0 : assert(instruction->field_name_expr);
771 : 0 : fprintf(irp->f, "@field(");
772 : 0 : ir_print_other_instruction(irp, instruction->container_ptr);
773 : 0 : fprintf(irp->f, ", ");
774 : 0 : ir_print_other_instruction(irp, instruction->field_name_expr);
775 : 0 : fprintf(irp->f, ")");
776 : : }
777 : 0 : }
778 : :
779 : 0 : static void ir_print_struct_field_ptr(IrPrint *irp, IrInstructionStructFieldPtr *instruction) {
780 : 0 : fprintf(irp->f, "@StructFieldPtr(&");
781 : 0 : ir_print_other_instruction(irp, instruction->struct_ptr);
782 : 0 : fprintf(irp->f, ".%s", buf_ptr(instruction->field->name));
783 : 0 : fprintf(irp->f, ")");
784 : 0 : }
785 : :
786 : 0 : static void ir_print_union_field_ptr(IrPrint *irp, IrInstructionUnionFieldPtr *instruction) {
787 : 0 : fprintf(irp->f, "@UnionFieldPtr(&");
788 : 0 : ir_print_other_instruction(irp, instruction->union_ptr);
789 : 0 : fprintf(irp->f, ".%s", buf_ptr(instruction->field->enum_field->name));
790 : 0 : fprintf(irp->f, ")");
791 : 0 : }
792 : :
793 : 0 : static void ir_print_set_cold(IrPrint *irp, IrInstructionSetCold *instruction) {
794 : 0 : fprintf(irp->f, "@setCold(");
795 : 0 : ir_print_other_instruction(irp, instruction->is_cold);
796 : 0 : fprintf(irp->f, ")");
797 : 0 : }
798 : :
799 : 0 : static void ir_print_set_runtime_safety(IrPrint *irp, IrInstructionSetRuntimeSafety *instruction) {
800 : 0 : fprintf(irp->f, "@setRuntimeSafety(");
801 : 0 : ir_print_other_instruction(irp, instruction->safety_on);
802 : 0 : fprintf(irp->f, ")");
803 : 0 : }
804 : :
805 : 0 : static void ir_print_set_float_mode(IrPrint *irp, IrInstructionSetFloatMode *instruction) {
806 : 0 : fprintf(irp->f, "@setFloatMode(");
807 : 0 : ir_print_other_instruction(irp, instruction->scope_value);
808 : 0 : fprintf(irp->f, ", ");
809 : 0 : ir_print_other_instruction(irp, instruction->mode_value);
810 : 0 : fprintf(irp->f, ")");
811 : 0 : }
812 : :
813 : 0 : static void ir_print_array_type(IrPrint *irp, IrInstructionArrayType *instruction) {
814 : 0 : fprintf(irp->f, "[");
815 : 0 : ir_print_other_instruction(irp, instruction->size);
816 : 0 : fprintf(irp->f, "]");
817 : 0 : ir_print_other_instruction(irp, instruction->child_type);
818 : 0 : }
819 : :
820 : 0 : static void ir_print_slice_type(IrPrint *irp, IrInstructionSliceType *instruction) {
821 [ # # ]: 0 : const char *const_kw = instruction->is_const ? "const " : "";
822 : 0 : fprintf(irp->f, "[]%s", const_kw);
823 : 0 : ir_print_other_instruction(irp, instruction->child_type);
824 : 0 : }
825 : :
826 : 0 : static void ir_print_any_frame_type(IrPrint *irp, IrInstructionAnyFrameType *instruction) {
827 [ # # ]: 0 : if (instruction->payload_type == nullptr) {
828 : 0 : fprintf(irp->f, "anyframe");
829 : : } else {
830 : 0 : fprintf(irp->f, "anyframe->");
831 : 0 : ir_print_other_instruction(irp, instruction->payload_type);
832 : : }
833 : 0 : }
834 : :
835 : 0 : static void ir_print_global_asm(IrPrint *irp, IrInstructionGlobalAsm *instruction) {
836 : 0 : fprintf(irp->f, "asm(\"%s\")", buf_ptr(instruction->asm_code));
837 : 0 : }
838 : :
839 : 0 : static void ir_print_asm(IrPrint *irp, IrInstructionAsm *instruction) {
840 : 0 : assert(instruction->base.source_node->type == NodeTypeAsmExpr);
841 : 0 : AstNodeAsmExpr *asm_expr = &instruction->base.source_node->data.asm_expr;
842 [ # # ]: 0 : const char *volatile_kw = instruction->has_side_effects ? " volatile" : "";
843 : 0 : fprintf(irp->f, "asm%s (\"%s\") : ", volatile_kw, buf_ptr(instruction->asm_template));
844 : :
845 [ # # ]: 0 : for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {
846 : 0 : AsmOutput *asm_output = asm_expr->output_list.at(i);
847 [ # # ]: 0 : if (i != 0) fprintf(irp->f, ", ");
848 : :
849 : 0 : fprintf(irp->f, "[%s] \"%s\" (",
850 : : buf_ptr(asm_output->asm_symbolic_name),
851 : : buf_ptr(asm_output->constraint));
852 [ # # ]: 0 : if (asm_output->return_type) {
853 : 0 : fprintf(irp->f, "-> ");
854 : 0 : ir_print_other_instruction(irp, instruction->output_types[i]);
855 : : } else {
856 : 0 : fprintf(irp->f, "%s", buf_ptr(asm_output->variable_name));
857 : : }
858 : 0 : fprintf(irp->f, ")");
859 : : }
860 : :
861 : 0 : fprintf(irp->f, " : ");
862 [ # # ]: 0 : for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {
863 : 0 : AsmInput *asm_input = asm_expr->input_list.at(i);
864 : :
865 [ # # ]: 0 : if (i != 0) fprintf(irp->f, ", ");
866 : 0 : fprintf(irp->f, "[%s] \"%s\" (",
867 : : buf_ptr(asm_input->asm_symbolic_name),
868 : : buf_ptr(asm_input->constraint));
869 : 0 : ir_print_other_instruction(irp, instruction->input_list[i]);
870 : 0 : fprintf(irp->f, ")");
871 : : }
872 : 0 : fprintf(irp->f, " : ");
873 [ # # ]: 0 : for (size_t i = 0; i < asm_expr->clobber_list.length; i += 1) {
874 : 0 : Buf *reg_name = asm_expr->clobber_list.at(i);
875 [ # # ]: 0 : if (i != 0) fprintf(irp->f, ", ");
876 : 0 : fprintf(irp->f, "\"%s\"", buf_ptr(reg_name));
877 : : }
878 : 0 : fprintf(irp->f, ")");
879 : 0 : }
880 : :
881 : 0 : static void ir_print_size_of(IrPrint *irp, IrInstructionSizeOf *instruction) {
882 : 0 : fprintf(irp->f, "@sizeOf(");
883 : 0 : ir_print_other_instruction(irp, instruction->type_value);
884 : 0 : fprintf(irp->f, ")");
885 : 0 : }
886 : :
887 : 0 : static void ir_print_test_non_null(IrPrint *irp, IrInstructionTestNonNull *instruction) {
888 : 0 : ir_print_other_instruction(irp, instruction->value);
889 : 0 : fprintf(irp->f, " != null");
890 : 0 : }
891 : :
892 : 0 : static void ir_print_optional_unwrap_ptr(IrPrint *irp, IrInstructionOptionalUnwrapPtr *instruction) {
893 : 0 : fprintf(irp->f, "&");
894 : 0 : ir_print_other_instruction(irp, instruction->base_ptr);
895 : 0 : fprintf(irp->f, ".*.?");
896 [ # # ]: 0 : if (!instruction->safety_check_on) {
897 : 0 : fprintf(irp->f, " // no safety");
898 : : }
899 : 0 : }
900 : :
901 : 0 : static void ir_print_clz(IrPrint *irp, IrInstructionClz *instruction) {
902 : 0 : fprintf(irp->f, "@clz(");
903 [ # # ]: 0 : if (instruction->type != nullptr) {
904 : 0 : ir_print_other_instruction(irp, instruction->type);
905 : : } else {
906 : 0 : fprintf(irp->f, "null");
907 : : }
908 : 0 : fprintf(irp->f, ",");
909 : 0 : ir_print_other_instruction(irp, instruction->op);
910 : 0 : fprintf(irp->f, ")");
911 : 0 : }
912 : :
913 : 0 : static void ir_print_ctz(IrPrint *irp, IrInstructionCtz *instruction) {
914 : 0 : fprintf(irp->f, "@ctz(");
915 [ # # ]: 0 : if (instruction->type != nullptr) {
916 : 0 : ir_print_other_instruction(irp, instruction->type);
917 : : } else {
918 : 0 : fprintf(irp->f, "null");
919 : : }
920 : 0 : fprintf(irp->f, ",");
921 : 0 : ir_print_other_instruction(irp, instruction->op);
922 : 0 : fprintf(irp->f, ")");
923 : 0 : }
924 : :
925 : 0 : static void ir_print_pop_count(IrPrint *irp, IrInstructionPopCount *instruction) {
926 : 0 : fprintf(irp->f, "@popCount(");
927 [ # # ]: 0 : if (instruction->type != nullptr) {
928 : 0 : ir_print_other_instruction(irp, instruction->type);
929 : : } else {
930 : 0 : fprintf(irp->f, "null");
931 : : }
932 : 0 : fprintf(irp->f, ",");
933 : 0 : ir_print_other_instruction(irp, instruction->op);
934 : 0 : fprintf(irp->f, ")");
935 : 0 : }
936 : :
937 : 0 : static void ir_print_bswap(IrPrint *irp, IrInstructionBswap *instruction) {
938 : 0 : fprintf(irp->f, "@byteSwap(");
939 [ # # ]: 0 : if (instruction->type != nullptr) {
940 : 0 : ir_print_other_instruction(irp, instruction->type);
941 : : } else {
942 : 0 : fprintf(irp->f, "null");
943 : : }
944 : 0 : fprintf(irp->f, ",");
945 : 0 : ir_print_other_instruction(irp, instruction->op);
946 : 0 : fprintf(irp->f, ")");
947 : 0 : }
948 : :
949 : 0 : static void ir_print_bit_reverse(IrPrint *irp, IrInstructionBitReverse *instruction) {
950 : 0 : fprintf(irp->f, "@bitReverse(");
951 [ # # ]: 0 : if (instruction->type != nullptr) {
952 : 0 : ir_print_other_instruction(irp, instruction->type);
953 : : } else {
954 : 0 : fprintf(irp->f, "null");
955 : : }
956 : 0 : fprintf(irp->f, ",");
957 : 0 : ir_print_other_instruction(irp, instruction->op);
958 : 0 : fprintf(irp->f, ")");
959 : 0 : }
960 : :
961 : 0 : static void ir_print_switch_br(IrPrint *irp, IrInstructionSwitchBr *instruction) {
962 : 0 : fprintf(irp->f, "switch (");
963 : 0 : ir_print_other_instruction(irp, instruction->target_value);
964 : 0 : fprintf(irp->f, ") ");
965 [ # # ]: 0 : for (size_t i = 0; i < instruction->case_count; i += 1) {
966 : 0 : IrInstructionSwitchBrCase *this_case = &instruction->cases[i];
967 : 0 : ir_print_other_instruction(irp, this_case->value);
968 : 0 : fprintf(irp->f, " => ");
969 : 0 : ir_print_other_block(irp, this_case->block);
970 : 0 : fprintf(irp->f, ", ");
971 : : }
972 : 0 : fprintf(irp->f, "else => ");
973 : 0 : ir_print_other_block(irp, instruction->else_block);
974 [ # # ]: 0 : if (instruction->is_comptime != nullptr) {
975 : 0 : fprintf(irp->f, " // comptime = ");
976 : 0 : ir_print_other_instruction(irp, instruction->is_comptime);
977 : : }
978 : 0 : }
979 : :
980 : 0 : static void ir_print_switch_var(IrPrint *irp, IrInstructionSwitchVar *instruction) {
981 : 0 : fprintf(irp->f, "switchvar ");
982 : 0 : ir_print_other_instruction(irp, instruction->target_value_ptr);
983 [ # # ]: 0 : for (size_t i = 0; i < instruction->prongs_len; i += 1) {
984 : 0 : fprintf(irp->f, ", ");
985 : 0 : ir_print_other_instruction(irp, instruction->prongs_ptr[i]);
986 : : }
987 : 0 : }
988 : :
989 : 0 : static void ir_print_switch_else_var(IrPrint *irp, IrInstructionSwitchElseVar *instruction) {
990 : 0 : fprintf(irp->f, "switchelsevar ");
991 : 0 : ir_print_other_instruction(irp, &instruction->switch_br->base);
992 : 0 : }
993 : :
994 : 0 : static void ir_print_switch_target(IrPrint *irp, IrInstructionSwitchTarget *instruction) {
995 : 0 : fprintf(irp->f, "switchtarget ");
996 : 0 : ir_print_other_instruction(irp, instruction->target_value_ptr);
997 : 0 : }
998 : :
999 : 0 : static void ir_print_union_tag(IrPrint *irp, IrInstructionUnionTag *instruction) {
1000 : 0 : fprintf(irp->f, "uniontag ");
1001 : 0 : ir_print_other_instruction(irp, instruction->value);
1002 : 0 : }
1003 : :
1004 : 0 : static void ir_print_import(IrPrint *irp, IrInstructionImport *instruction) {
1005 : 0 : fprintf(irp->f, "@import(");
1006 : 0 : ir_print_other_instruction(irp, instruction->name);
1007 : 0 : fprintf(irp->f, ")");
1008 : 0 : }
1009 : :
1010 : 0 : static void ir_print_ref(IrPrint *irp, IrInstructionRef *instruction) {
1011 [ # # ]: 0 : const char *const_str = instruction->is_const ? "const " : "";
1012 [ # # ]: 0 : const char *volatile_str = instruction->is_volatile ? "volatile " : "";
1013 : 0 : fprintf(irp->f, "%s%sref ", const_str, volatile_str);
1014 : 0 : ir_print_other_instruction(irp, instruction->value);
1015 : 0 : }
1016 : :
1017 : 0 : static void ir_print_ref_gen(IrPrint *irp, IrInstructionRefGen *instruction) {
1018 : 0 : fprintf(irp->f, "@ref(");
1019 : 0 : ir_print_other_instruction(irp, instruction->operand);
1020 : 0 : fprintf(irp->f, ")result=");
1021 : 0 : ir_print_other_instruction(irp, instruction->result_loc);
1022 : 0 : }
1023 : :
1024 : 0 : static void ir_print_compile_err(IrPrint *irp, IrInstructionCompileErr *instruction) {
1025 : 0 : fprintf(irp->f, "@compileError(");
1026 : 0 : ir_print_other_instruction(irp, instruction->msg);
1027 : 0 : fprintf(irp->f, ")");
1028 : 0 : }
1029 : :
1030 : 0 : static void ir_print_compile_log(IrPrint *irp, IrInstructionCompileLog *instruction) {
1031 : 0 : fprintf(irp->f, "@compileLog(");
1032 [ # # ]: 0 : for (size_t i = 0; i < instruction->msg_count; i += 1) {
1033 [ # # ]: 0 : if (i != 0)
1034 : 0 : fprintf(irp->f, ",");
1035 : 0 : IrInstruction *msg = instruction->msg_list[i];
1036 : 0 : ir_print_other_instruction(irp, msg);
1037 : : }
1038 : 0 : fprintf(irp->f, ")");
1039 : 0 : }
1040 : :
1041 : 0 : static void ir_print_err_name(IrPrint *irp, IrInstructionErrName *instruction) {
1042 : 0 : fprintf(irp->f, "@errorName(");
1043 : 0 : ir_print_other_instruction(irp, instruction->value);
1044 : 0 : fprintf(irp->f, ")");
1045 : 0 : }
1046 : :
1047 : 0 : static void ir_print_c_import(IrPrint *irp, IrInstructionCImport *instruction) {
1048 : 0 : fprintf(irp->f, "@cImport(...)");
1049 : 0 : }
1050 : :
1051 : 0 : static void ir_print_c_include(IrPrint *irp, IrInstructionCInclude *instruction) {
1052 : 0 : fprintf(irp->f, "@cInclude(");
1053 : 0 : ir_print_other_instruction(irp, instruction->name);
1054 : 0 : fprintf(irp->f, ")");
1055 : 0 : }
1056 : :
1057 : 0 : static void ir_print_c_define(IrPrint *irp, IrInstructionCDefine *instruction) {
1058 : 0 : fprintf(irp->f, "@cDefine(");
1059 : 0 : ir_print_other_instruction(irp, instruction->name);
1060 : 0 : fprintf(irp->f, ", ");
1061 : 0 : ir_print_other_instruction(irp, instruction->value);
1062 : 0 : fprintf(irp->f, ")");
1063 : 0 : }
1064 : :
1065 : 0 : static void ir_print_c_undef(IrPrint *irp, IrInstructionCUndef *instruction) {
1066 : 0 : fprintf(irp->f, "@cUndef(");
1067 : 0 : ir_print_other_instruction(irp, instruction->name);
1068 : 0 : fprintf(irp->f, ")");
1069 : 0 : }
1070 : :
1071 : 0 : static void ir_print_embed_file(IrPrint *irp, IrInstructionEmbedFile *instruction) {
1072 : 0 : fprintf(irp->f, "@embedFile(");
1073 : 0 : ir_print_other_instruction(irp, instruction->name);
1074 : 0 : fprintf(irp->f, ")");
1075 : 0 : }
1076 : :
1077 : 0 : static void ir_print_cmpxchg_src(IrPrint *irp, IrInstructionCmpxchgSrc *instruction) {
1078 : 0 : fprintf(irp->f, "@cmpxchg(");
1079 : 0 : ir_print_other_instruction(irp, instruction->ptr);
1080 : 0 : fprintf(irp->f, ", ");
1081 : 0 : ir_print_other_instruction(irp, instruction->cmp_value);
1082 : 0 : fprintf(irp->f, ", ");
1083 : 0 : ir_print_other_instruction(irp, instruction->new_value);
1084 : 0 : fprintf(irp->f, ", ");
1085 : 0 : ir_print_other_instruction(irp, instruction->success_order_value);
1086 : 0 : fprintf(irp->f, ", ");
1087 : 0 : ir_print_other_instruction(irp, instruction->failure_order_value);
1088 : 0 : fprintf(irp->f, ")result=");
1089 : 0 : ir_print_result_loc(irp, instruction->result_loc);
1090 : 0 : }
1091 : :
1092 : 0 : static void ir_print_cmpxchg_gen(IrPrint *irp, IrInstructionCmpxchgGen *instruction) {
1093 : 0 : fprintf(irp->f, "@cmpxchg(");
1094 : 0 : ir_print_other_instruction(irp, instruction->ptr);
1095 : 0 : fprintf(irp->f, ", ");
1096 : 0 : ir_print_other_instruction(irp, instruction->cmp_value);
1097 : 0 : fprintf(irp->f, ", ");
1098 : 0 : ir_print_other_instruction(irp, instruction->new_value);
1099 : 0 : fprintf(irp->f, ", TODO print atomic orders)result=");
1100 : 0 : ir_print_other_instruction(irp, instruction->result_loc);
1101 : 0 : }
1102 : :
1103 : 0 : static void ir_print_fence(IrPrint *irp, IrInstructionFence *instruction) {
1104 : 0 : fprintf(irp->f, "@fence(");
1105 : 0 : ir_print_other_instruction(irp, instruction->order_value);
1106 : 0 : fprintf(irp->f, ")");
1107 : 0 : }
1108 : :
1109 : 0 : static void ir_print_truncate(IrPrint *irp, IrInstructionTruncate *instruction) {
1110 : 0 : fprintf(irp->f, "@truncate(");
1111 : 0 : ir_print_other_instruction(irp, instruction->dest_type);
1112 : 0 : fprintf(irp->f, ", ");
1113 : 0 : ir_print_other_instruction(irp, instruction->target);
1114 : 0 : fprintf(irp->f, ")");
1115 : 0 : }
1116 : :
1117 : 0 : static void ir_print_int_cast(IrPrint *irp, IrInstructionIntCast *instruction) {
1118 : 0 : fprintf(irp->f, "@intCast(");
1119 : 0 : ir_print_other_instruction(irp, instruction->dest_type);
1120 : 0 : fprintf(irp->f, ", ");
1121 : 0 : ir_print_other_instruction(irp, instruction->target);
1122 : 0 : fprintf(irp->f, ")");
1123 : 0 : }
1124 : :
1125 : 0 : static void ir_print_float_cast(IrPrint *irp, IrInstructionFloatCast *instruction) {
1126 : 0 : fprintf(irp->f, "@floatCast(");
1127 : 0 : ir_print_other_instruction(irp, instruction->dest_type);
1128 : 0 : fprintf(irp->f, ", ");
1129 : 0 : ir_print_other_instruction(irp, instruction->target);
1130 : 0 : fprintf(irp->f, ")");
1131 : 0 : }
1132 : :
1133 : 0 : static void ir_print_err_set_cast(IrPrint *irp, IrInstructionErrSetCast *instruction) {
1134 : 0 : fprintf(irp->f, "@errSetCast(");
1135 : 0 : ir_print_other_instruction(irp, instruction->dest_type);
1136 : 0 : fprintf(irp->f, ", ");
1137 : 0 : ir_print_other_instruction(irp, instruction->target);
1138 : 0 : fprintf(irp->f, ")");
1139 : 0 : }
1140 : :
1141 : 0 : static void ir_print_from_bytes(IrPrint *irp, IrInstructionFromBytes *instruction) {
1142 : 0 : fprintf(irp->f, "@bytesToSlice(");
1143 : 0 : ir_print_other_instruction(irp, instruction->dest_child_type);
1144 : 0 : fprintf(irp->f, ", ");
1145 : 0 : ir_print_other_instruction(irp, instruction->target);
1146 : 0 : fprintf(irp->f, ")");
1147 : 0 : }
1148 : :
1149 : 0 : static void ir_print_to_bytes(IrPrint *irp, IrInstructionToBytes *instruction) {
1150 : 0 : fprintf(irp->f, "@sliceToBytes(");
1151 : 0 : ir_print_other_instruction(irp, instruction->target);
1152 : 0 : fprintf(irp->f, ")");
1153 : 0 : }
1154 : :
1155 : 0 : static void ir_print_int_to_float(IrPrint *irp, IrInstructionIntToFloat *instruction) {
1156 : 0 : fprintf(irp->f, "@intToFloat(");
1157 : 0 : ir_print_other_instruction(irp, instruction->dest_type);
1158 : 0 : fprintf(irp->f, ", ");
1159 : 0 : ir_print_other_instruction(irp, instruction->target);
1160 : 0 : fprintf(irp->f, ")");
1161 : 0 : }
1162 : :
1163 : 0 : static void ir_print_float_to_int(IrPrint *irp, IrInstructionFloatToInt *instruction) {
1164 : 0 : fprintf(irp->f, "@floatToInt(");
1165 : 0 : ir_print_other_instruction(irp, instruction->dest_type);
1166 : 0 : fprintf(irp->f, ", ");
1167 : 0 : ir_print_other_instruction(irp, instruction->target);
1168 : 0 : fprintf(irp->f, ")");
1169 : 0 : }
1170 : :
1171 : 0 : static void ir_print_bool_to_int(IrPrint *irp, IrInstructionBoolToInt *instruction) {
1172 : 0 : fprintf(irp->f, "@boolToInt(");
1173 : 0 : ir_print_other_instruction(irp, instruction->target);
1174 : 0 : fprintf(irp->f, ")");
1175 : 0 : }
1176 : :
1177 : 0 : static void ir_print_int_type(IrPrint *irp, IrInstructionIntType *instruction) {
1178 : 0 : fprintf(irp->f, "@IntType(");
1179 : 0 : ir_print_other_instruction(irp, instruction->is_signed);
1180 : 0 : fprintf(irp->f, ", ");
1181 : 0 : ir_print_other_instruction(irp, instruction->bit_count);
1182 : 0 : fprintf(irp->f, ")");
1183 : 0 : }
1184 : :
1185 : 0 : static void ir_print_vector_type(IrPrint *irp, IrInstructionVectorType *instruction) {
1186 : 0 : fprintf(irp->f, "@Vector(");
1187 : 0 : ir_print_other_instruction(irp, instruction->len);
1188 : 0 : fprintf(irp->f, ", ");
1189 : 0 : ir_print_other_instruction(irp, instruction->elem_type);
1190 : 0 : fprintf(irp->f, ")");
1191 : 0 : }
1192 : :
1193 : 0 : static void ir_print_bool_not(IrPrint *irp, IrInstructionBoolNot *instruction) {
1194 : 0 : fprintf(irp->f, "! ");
1195 : 0 : ir_print_other_instruction(irp, instruction->value);
1196 : 0 : }
1197 : :
1198 : 0 : static void ir_print_memset(IrPrint *irp, IrInstructionMemset *instruction) {
1199 : 0 : fprintf(irp->f, "@memset(");
1200 : 0 : ir_print_other_instruction(irp, instruction->dest_ptr);
1201 : 0 : fprintf(irp->f, ", ");
1202 : 0 : ir_print_other_instruction(irp, instruction->byte);
1203 : 0 : fprintf(irp->f, ", ");
1204 : 0 : ir_print_other_instruction(irp, instruction->count);
1205 : 0 : fprintf(irp->f, ")");
1206 : 0 : }
1207 : :
1208 : 0 : static void ir_print_memcpy(IrPrint *irp, IrInstructionMemcpy *instruction) {
1209 : 0 : fprintf(irp->f, "@memcpy(");
1210 : 0 : ir_print_other_instruction(irp, instruction->dest_ptr);
1211 : 0 : fprintf(irp->f, ", ");
1212 : 0 : ir_print_other_instruction(irp, instruction->src_ptr);
1213 : 0 : fprintf(irp->f, ", ");
1214 : 0 : ir_print_other_instruction(irp, instruction->count);
1215 : 0 : fprintf(irp->f, ")");
1216 : 0 : }
1217 : :
1218 : 0 : static void ir_print_slice_src(IrPrint *irp, IrInstructionSliceSrc *instruction) {
1219 : 0 : ir_print_other_instruction(irp, instruction->ptr);
1220 : 0 : fprintf(irp->f, "[");
1221 : 0 : ir_print_other_instruction(irp, instruction->start);
1222 : 0 : fprintf(irp->f, "..");
1223 [ # # ]: 0 : if (instruction->end)
1224 : 0 : ir_print_other_instruction(irp, instruction->end);
1225 : 0 : fprintf(irp->f, "]result=");
1226 : 0 : ir_print_result_loc(irp, instruction->result_loc);
1227 : 0 : }
1228 : :
1229 : 0 : static void ir_print_slice_gen(IrPrint *irp, IrInstructionSliceGen *instruction) {
1230 : 0 : ir_print_other_instruction(irp, instruction->ptr);
1231 : 0 : fprintf(irp->f, "[");
1232 : 0 : ir_print_other_instruction(irp, instruction->start);
1233 : 0 : fprintf(irp->f, "..");
1234 [ # # ]: 0 : if (instruction->end)
1235 : 0 : ir_print_other_instruction(irp, instruction->end);
1236 : 0 : fprintf(irp->f, "]result=");
1237 : 0 : ir_print_other_instruction(irp, instruction->result_loc);
1238 : 0 : }
1239 : :
1240 : 0 : static void ir_print_member_count(IrPrint *irp, IrInstructionMemberCount *instruction) {
1241 : 0 : fprintf(irp->f, "@memberCount(");
1242 : 0 : ir_print_other_instruction(irp, instruction->container);
1243 : 0 : fprintf(irp->f, ")");
1244 : 0 : }
1245 : :
1246 : 0 : static void ir_print_member_type(IrPrint *irp, IrInstructionMemberType *instruction) {
1247 : 0 : fprintf(irp->f, "@memberType(");
1248 : 0 : ir_print_other_instruction(irp, instruction->container_type);
1249 : 0 : fprintf(irp->f, ", ");
1250 : 0 : ir_print_other_instruction(irp, instruction->member_index);
1251 : 0 : fprintf(irp->f, ")");
1252 : 0 : }
1253 : :
1254 : 0 : static void ir_print_member_name(IrPrint *irp, IrInstructionMemberName *instruction) {
1255 : 0 : fprintf(irp->f, "@memberName(");
1256 : 0 : ir_print_other_instruction(irp, instruction->container_type);
1257 : 0 : fprintf(irp->f, ", ");
1258 : 0 : ir_print_other_instruction(irp, instruction->member_index);
1259 : 0 : fprintf(irp->f, ")");
1260 : 0 : }
1261 : :
1262 : 0 : static void ir_print_breakpoint(IrPrint *irp, IrInstructionBreakpoint *instruction) {
1263 : 0 : fprintf(irp->f, "@breakpoint()");
1264 : 0 : }
1265 : :
1266 : 0 : static void ir_print_frame_address(IrPrint *irp, IrInstructionFrameAddress *instruction) {
1267 : 0 : fprintf(irp->f, "@frameAddress()");
1268 : 0 : }
1269 : :
1270 : 0 : static void ir_print_handle(IrPrint *irp, IrInstructionFrameHandle *instruction) {
1271 : 0 : fprintf(irp->f, "@frame()");
1272 : 0 : }
1273 : :
1274 : 0 : static void ir_print_frame_type(IrPrint *irp, IrInstructionFrameType *instruction) {
1275 : 0 : fprintf(irp->f, "@Frame(");
1276 : 0 : ir_print_other_instruction(irp, instruction->fn);
1277 : 0 : fprintf(irp->f, ")");
1278 : 0 : }
1279 : :
1280 : 0 : static void ir_print_frame_size_src(IrPrint *irp, IrInstructionFrameSizeSrc *instruction) {
1281 : 0 : fprintf(irp->f, "@frameSize(");
1282 : 0 : ir_print_other_instruction(irp, instruction->fn);
1283 : 0 : fprintf(irp->f, ")");
1284 : 0 : }
1285 : :
1286 : 0 : static void ir_print_frame_size_gen(IrPrint *irp, IrInstructionFrameSizeGen *instruction) {
1287 : 0 : fprintf(irp->f, "@frameSize(");
1288 : 0 : ir_print_other_instruction(irp, instruction->fn);
1289 : 0 : fprintf(irp->f, ")");
1290 : 0 : }
1291 : :
1292 : 0 : static void ir_print_return_address(IrPrint *irp, IrInstructionReturnAddress *instruction) {
1293 : 0 : fprintf(irp->f, "@returnAddress()");
1294 : 0 : }
1295 : :
1296 : 0 : static void ir_print_align_of(IrPrint *irp, IrInstructionAlignOf *instruction) {
1297 : 0 : fprintf(irp->f, "@alignOf(");
1298 : 0 : ir_print_other_instruction(irp, instruction->type_value);
1299 : 0 : fprintf(irp->f, ")");
1300 : 0 : }
1301 : :
1302 : 0 : static void ir_print_overflow_op(IrPrint *irp, IrInstructionOverflowOp *instruction) {
1303 [ # # # # : 0 : switch (instruction->op) {
# ]
1304 : 0 : case IrOverflowOpAdd:
1305 : 0 : fprintf(irp->f, "@addWithOverflow(");
1306 : 0 : break;
1307 : 0 : case IrOverflowOpSub:
1308 : 0 : fprintf(irp->f, "@subWithOverflow(");
1309 : 0 : break;
1310 : 0 : case IrOverflowOpMul:
1311 : 0 : fprintf(irp->f, "@mulWithOverflow(");
1312 : 0 : break;
1313 : 0 : case IrOverflowOpShl:
1314 : 0 : fprintf(irp->f, "@shlWithOverflow(");
1315 : 0 : break;
1316 : : }
1317 : 0 : ir_print_other_instruction(irp, instruction->type_value);
1318 : 0 : fprintf(irp->f, ", ");
1319 : 0 : ir_print_other_instruction(irp, instruction->op1);
1320 : 0 : fprintf(irp->f, ", ");
1321 : 0 : ir_print_other_instruction(irp, instruction->op2);
1322 : 0 : fprintf(irp->f, ", ");
1323 : 0 : ir_print_other_instruction(irp, instruction->result_ptr);
1324 : 0 : fprintf(irp->f, ")");
1325 : 0 : }
1326 : :
1327 : 0 : static void ir_print_test_err_src(IrPrint *irp, IrInstructionTestErrSrc *instruction) {
1328 : 0 : fprintf(irp->f, "@testError(");
1329 : 0 : ir_print_other_instruction(irp, instruction->base_ptr);
1330 : 0 : fprintf(irp->f, ")");
1331 : 0 : }
1332 : :
1333 : 0 : static void ir_print_test_err_gen(IrPrint *irp, IrInstructionTestErrGen *instruction) {
1334 : 0 : fprintf(irp->f, "@testError(");
1335 : 0 : ir_print_other_instruction(irp, instruction->err_union);
1336 : 0 : fprintf(irp->f, ")");
1337 : 0 : }
1338 : :
1339 : 0 : static void ir_print_unwrap_err_code(IrPrint *irp, IrInstructionUnwrapErrCode *instruction) {
1340 : 0 : fprintf(irp->f, "UnwrapErrorCode(");
1341 : 0 : ir_print_other_instruction(irp, instruction->err_union_ptr);
1342 : 0 : fprintf(irp->f, ")");
1343 : 0 : }
1344 : :
1345 : 0 : static void ir_print_unwrap_err_payload(IrPrint *irp, IrInstructionUnwrapErrPayload *instruction) {
1346 : 0 : fprintf(irp->f, "ErrorUnionFieldPayload(");
1347 : 0 : ir_print_other_instruction(irp, instruction->value);
1348 : 0 : fprintf(irp->f, ")safety=%d,init=%d",instruction->safety_check_on, instruction->initializing);
1349 : 0 : }
1350 : :
1351 : 0 : static void ir_print_optional_wrap(IrPrint *irp, IrInstructionOptionalWrap *instruction) {
1352 : 0 : fprintf(irp->f, "@optionalWrap(");
1353 : 0 : ir_print_other_instruction(irp, instruction->operand);
1354 : 0 : fprintf(irp->f, ")result=");
1355 : 0 : ir_print_other_instruction(irp, instruction->result_loc);
1356 : 0 : }
1357 : :
1358 : 0 : static void ir_print_err_wrap_code(IrPrint *irp, IrInstructionErrWrapCode *instruction) {
1359 : 0 : fprintf(irp->f, "@errWrapCode(");
1360 : 0 : ir_print_other_instruction(irp, instruction->operand);
1361 : 0 : fprintf(irp->f, ")result=");
1362 : 0 : ir_print_other_instruction(irp, instruction->result_loc);
1363 : 0 : }
1364 : :
1365 : 0 : static void ir_print_err_wrap_payload(IrPrint *irp, IrInstructionErrWrapPayload *instruction) {
1366 : 0 : fprintf(irp->f, "@errWrapPayload(");
1367 : 0 : ir_print_other_instruction(irp, instruction->operand);
1368 : 0 : fprintf(irp->f, ")result=");
1369 : 0 : ir_print_other_instruction(irp, instruction->result_loc);
1370 : 0 : }
1371 : :
1372 : 0 : static void ir_print_fn_proto(IrPrint *irp, IrInstructionFnProto *instruction) {
1373 : 0 : fprintf(irp->f, "fn(");
1374 [ # # ]: 0 : for (size_t i = 0; i < instruction->base.source_node->data.fn_proto.params.length; i += 1) {
1375 [ # # ]: 0 : if (i != 0)
1376 : 0 : fprintf(irp->f, ",");
1377 [ # # ][ # # ]: 0 : if (instruction->is_var_args && i == instruction->base.source_node->data.fn_proto.params.length - 1) {
1378 : 0 : fprintf(irp->f, "...");
1379 : : } else {
1380 : 0 : ir_print_other_instruction(irp, instruction->param_types[i]);
1381 : : }
1382 : : }
1383 : 0 : fprintf(irp->f, ")");
1384 [ # # ]: 0 : if (instruction->align_value != nullptr) {
1385 : 0 : fprintf(irp->f, " align ");
1386 : 0 : ir_print_other_instruction(irp, instruction->align_value);
1387 : 0 : fprintf(irp->f, " ");
1388 : : }
1389 : 0 : fprintf(irp->f, "->");
1390 : 0 : ir_print_other_instruction(irp, instruction->return_type);
1391 : 0 : }
1392 : :
1393 : 0 : static void ir_print_test_comptime(IrPrint *irp, IrInstructionTestComptime *instruction) {
1394 : 0 : fprintf(irp->f, "@testComptime(");
1395 : 0 : ir_print_other_instruction(irp, instruction->value);
1396 : 0 : fprintf(irp->f, ")");
1397 : 0 : }
1398 : :
1399 : 0 : static void ir_print_ptr_cast_src(IrPrint *irp, IrInstructionPtrCastSrc *instruction) {
1400 : 0 : fprintf(irp->f, "@ptrCast(");
1401 [ # # ]: 0 : if (instruction->dest_type) {
1402 : 0 : ir_print_other_instruction(irp, instruction->dest_type);
1403 : : }
1404 : 0 : fprintf(irp->f, ",");
1405 : 0 : ir_print_other_instruction(irp, instruction->ptr);
1406 : 0 : fprintf(irp->f, ")");
1407 : 0 : }
1408 : :
1409 : 0 : static void ir_print_ptr_cast_gen(IrPrint *irp, IrInstructionPtrCastGen *instruction) {
1410 : 0 : fprintf(irp->f, "@ptrCast(");
1411 : 0 : ir_print_other_instruction(irp, instruction->ptr);
1412 : 0 : fprintf(irp->f, ")");
1413 : 0 : }
1414 : :
1415 : 0 : static void ir_print_bit_cast_src(IrPrint *irp, IrInstructionBitCastSrc *instruction) {
1416 : 0 : fprintf(irp->f, "@bitCast(");
1417 : 0 : ir_print_other_instruction(irp, instruction->operand);
1418 : 0 : fprintf(irp->f, ")result=");
1419 : 0 : ir_print_result_loc(irp, &instruction->result_loc_bit_cast->base);
1420 : 0 : }
1421 : :
1422 : 0 : static void ir_print_bit_cast_gen(IrPrint *irp, IrInstructionBitCastGen *instruction) {
1423 : 0 : fprintf(irp->f, "@bitCast(");
1424 : 0 : ir_print_other_instruction(irp, instruction->operand);
1425 : 0 : fprintf(irp->f, ")");
1426 : 0 : }
1427 : :
1428 : 0 : static void ir_print_widen_or_shorten(IrPrint *irp, IrInstructionWidenOrShorten *instruction) {
1429 : 0 : fprintf(irp->f, "WidenOrShorten(");
1430 : 0 : ir_print_other_instruction(irp, instruction->target);
1431 : 0 : fprintf(irp->f, ")");
1432 : 0 : }
1433 : :
1434 : 0 : static void ir_print_ptr_to_int(IrPrint *irp, IrInstructionPtrToInt *instruction) {
1435 : 0 : fprintf(irp->f, "@ptrToInt(");
1436 : 0 : ir_print_other_instruction(irp, instruction->target);
1437 : 0 : fprintf(irp->f, ")");
1438 : 0 : }
1439 : :
1440 : 0 : static void ir_print_int_to_ptr(IrPrint *irp, IrInstructionIntToPtr *instruction) {
1441 : 0 : fprintf(irp->f, "@intToPtr(");
1442 [ # # ]: 0 : if (instruction->dest_type == nullptr) {
1443 : 0 : fprintf(irp->f, "(null)");
1444 : : } else {
1445 : 0 : ir_print_other_instruction(irp, instruction->dest_type);
1446 : : }
1447 : 0 : fprintf(irp->f, ",");
1448 : 0 : ir_print_other_instruction(irp, instruction->target);
1449 : 0 : fprintf(irp->f, ")");
1450 : 0 : }
1451 : :
1452 : 0 : static void ir_print_int_to_enum(IrPrint *irp, IrInstructionIntToEnum *instruction) {
1453 : 0 : fprintf(irp->f, "@intToEnum(");
1454 [ # # ]: 0 : if (instruction->dest_type == nullptr) {
1455 : 0 : fprintf(irp->f, "(null)");
1456 : : } else {
1457 : 0 : ir_print_other_instruction(irp, instruction->dest_type);
1458 : : }
1459 : 0 : ir_print_other_instruction(irp, instruction->target);
1460 : 0 : fprintf(irp->f, ")");
1461 : 0 : }
1462 : :
1463 : 0 : static void ir_print_enum_to_int(IrPrint *irp, IrInstructionEnumToInt *instruction) {
1464 : 0 : fprintf(irp->f, "@enumToInt(");
1465 : 0 : ir_print_other_instruction(irp, instruction->target);
1466 : 0 : fprintf(irp->f, ")");
1467 : 0 : }
1468 : :
1469 : 0 : static void ir_print_check_runtime_scope(IrPrint *irp, IrInstructionCheckRuntimeScope *instruction) {
1470 : 0 : fprintf(irp->f, "@checkRuntimeScope(");
1471 : 0 : ir_print_other_instruction(irp, instruction->scope_is_comptime);
1472 : 0 : fprintf(irp->f, ",");
1473 : 0 : ir_print_other_instruction(irp, instruction->is_comptime);
1474 : 0 : fprintf(irp->f, ")");
1475 : 0 : }
1476 : :
1477 : 0 : static void ir_print_array_to_vector(IrPrint *irp, IrInstructionArrayToVector *instruction) {
1478 : 0 : fprintf(irp->f, "ArrayToVector(");
1479 : 0 : ir_print_other_instruction(irp, instruction->array);
1480 : 0 : fprintf(irp->f, ")");
1481 : 0 : }
1482 : :
1483 : 0 : static void ir_print_vector_to_array(IrPrint *irp, IrInstructionVectorToArray *instruction) {
1484 : 0 : fprintf(irp->f, "VectorToArray(");
1485 : 0 : ir_print_other_instruction(irp, instruction->vector);
1486 : 0 : fprintf(irp->f, ")result=");
1487 : 0 : ir_print_other_instruction(irp, instruction->result_loc);
1488 : 0 : }
1489 : :
1490 : 0 : static void ir_print_ptr_of_array_to_slice(IrPrint *irp, IrInstructionPtrOfArrayToSlice *instruction) {
1491 : 0 : fprintf(irp->f, "PtrOfArrayToSlice(");
1492 : 0 : ir_print_other_instruction(irp, instruction->operand);
1493 : 0 : fprintf(irp->f, ")result=");
1494 : 0 : ir_print_other_instruction(irp, instruction->result_loc);
1495 : 0 : }
1496 : :
1497 : 0 : static void ir_print_assert_zero(IrPrint *irp, IrInstructionAssertZero *instruction) {
1498 : 0 : fprintf(irp->f, "AssertZero(");
1499 : 0 : ir_print_other_instruction(irp, instruction->target);
1500 : 0 : fprintf(irp->f, ")");
1501 : 0 : }
1502 : :
1503 : 0 : static void ir_print_assert_non_null(IrPrint *irp, IrInstructionAssertNonNull *instruction) {
1504 : 0 : fprintf(irp->f, "AssertNonNull(");
1505 : 0 : ir_print_other_instruction(irp, instruction->target);
1506 : 0 : fprintf(irp->f, ")");
1507 : 0 : }
1508 : :
1509 : 0 : static void ir_print_resize_slice(IrPrint *irp, IrInstructionResizeSlice *instruction) {
1510 : 0 : fprintf(irp->f, "@resizeSlice(");
1511 : 0 : ir_print_other_instruction(irp, instruction->operand);
1512 : 0 : fprintf(irp->f, ")result=");
1513 : 0 : ir_print_other_instruction(irp, instruction->result_loc);
1514 : 0 : }
1515 : :
1516 : 0 : static void ir_print_alloca_src(IrPrint *irp, IrInstructionAllocaSrc *instruction) {
1517 : 0 : fprintf(irp->f, "Alloca(align=");
1518 : 0 : ir_print_other_instruction(irp, instruction->align);
1519 : 0 : fprintf(irp->f, ",name=%s)", instruction->name_hint);
1520 : 0 : }
1521 : :
1522 : 0 : static void ir_print_alloca_gen(IrPrint *irp, IrInstructionAllocaGen *instruction) {
1523 : 0 : fprintf(irp->f, "Alloca(align=%" PRIu32 ",name=%s)", instruction->align, instruction->name_hint);
1524 : 0 : }
1525 : :
1526 : 0 : static void ir_print_end_expr(IrPrint *irp, IrInstructionEndExpr *instruction) {
1527 : 0 : fprintf(irp->f, "EndExpr(result=");
1528 : 0 : ir_print_result_loc(irp, instruction->result_loc);
1529 : 0 : fprintf(irp->f, ",value=");
1530 : 0 : ir_print_other_instruction(irp, instruction->value);
1531 : 0 : fprintf(irp->f, ")");
1532 : 0 : }
1533 : :
1534 : 0 : static void ir_print_int_to_err(IrPrint *irp, IrInstructionIntToErr *instruction) {
1535 : 0 : fprintf(irp->f, "inttoerr ");
1536 : 0 : ir_print_other_instruction(irp, instruction->target);
1537 : 0 : }
1538 : :
1539 : 0 : static void ir_print_err_to_int(IrPrint *irp, IrInstructionErrToInt *instruction) {
1540 : 0 : fprintf(irp->f, "errtoint ");
1541 : 0 : ir_print_other_instruction(irp, instruction->target);
1542 : 0 : }
1543 : :
1544 : 0 : static void ir_print_check_switch_prongs(IrPrint *irp, IrInstructionCheckSwitchProngs *instruction) {
1545 : 0 : fprintf(irp->f, "@checkSwitchProngs(");
1546 : 0 : ir_print_other_instruction(irp, instruction->target_value);
1547 : 0 : fprintf(irp->f, ",");
1548 [ # # ]: 0 : for (size_t i = 0; i < instruction->range_count; i += 1) {
1549 [ # # ]: 0 : if (i != 0)
1550 : 0 : fprintf(irp->f, ",");
1551 : 0 : ir_print_other_instruction(irp, instruction->ranges[i].start);
1552 : 0 : fprintf(irp->f, "...");
1553 : 0 : ir_print_other_instruction(irp, instruction->ranges[i].end);
1554 : : }
1555 [ # # ]: 0 : const char *have_else_str = instruction->have_else_prong ? "yes" : "no";
1556 : 0 : fprintf(irp->f, ")else:%s", have_else_str);
1557 : 0 : }
1558 : :
1559 : 0 : static void ir_print_check_statement_is_void(IrPrint *irp, IrInstructionCheckStatementIsVoid *instruction) {
1560 : 0 : fprintf(irp->f, "@checkStatementIsVoid(");
1561 : 0 : ir_print_other_instruction(irp, instruction->statement_value);
1562 : 0 : fprintf(irp->f, ")");
1563 : 0 : }
1564 : :
1565 : 0 : static void ir_print_type_name(IrPrint *irp, IrInstructionTypeName *instruction) {
1566 : 0 : fprintf(irp->f, "typename ");
1567 : 0 : ir_print_other_instruction(irp, instruction->type_value);
1568 : 0 : }
1569 : :
1570 : 0 : static void ir_print_tag_name(IrPrint *irp, IrInstructionTagName *instruction) {
1571 : 0 : fprintf(irp->f, "tagname ");
1572 : 0 : ir_print_other_instruction(irp, instruction->target);
1573 : 0 : }
1574 : :
1575 : 0 : static void ir_print_ptr_type(IrPrint *irp, IrInstructionPtrType *instruction) {
1576 : 0 : fprintf(irp->f, "&");
1577 [ # # ]: 0 : if (instruction->align_value != nullptr) {
1578 : 0 : fprintf(irp->f, "align(");
1579 : 0 : ir_print_other_instruction(irp, instruction->align_value);
1580 : 0 : fprintf(irp->f, ")");
1581 : : }
1582 [ # # ]: 0 : const char *const_str = instruction->is_const ? "const " : "";
1583 [ # # ]: 0 : const char *volatile_str = instruction->is_volatile ? "volatile " : "";
1584 : 0 : fprintf(irp->f, ":%" PRIu32 ":%" PRIu32 " %s%s", instruction->bit_offset_start, instruction->host_int_bytes,
1585 : : const_str, volatile_str);
1586 : 0 : ir_print_other_instruction(irp, instruction->child_type);
1587 : 0 : }
1588 : :
1589 : 0 : static void ir_print_decl_ref(IrPrint *irp, IrInstructionDeclRef *instruction) {
1590 [ # # ]: 0 : const char *ptr_str = (instruction->lval == LValPtr) ? "ptr " : "";
1591 : 0 : fprintf(irp->f, "declref %s%s", ptr_str, buf_ptr(instruction->tld->name));
1592 : 0 : }
1593 : :
1594 : 0 : static void ir_print_panic(IrPrint *irp, IrInstructionPanic *instruction) {
1595 : 0 : fprintf(irp->f, "@panic(");
1596 : 0 : ir_print_other_instruction(irp, instruction->msg);
1597 : 0 : fprintf(irp->f, ")");
1598 : 0 : }
1599 : :
1600 : 0 : static void ir_print_field_parent_ptr(IrPrint *irp, IrInstructionFieldParentPtr *instruction) {
1601 : 0 : fprintf(irp->f, "@fieldParentPtr(");
1602 : 0 : ir_print_other_instruction(irp, instruction->type_value);
1603 : 0 : fprintf(irp->f, ",");
1604 : 0 : ir_print_other_instruction(irp, instruction->field_name);
1605 : 0 : fprintf(irp->f, ",");
1606 : 0 : ir_print_other_instruction(irp, instruction->field_ptr);
1607 : 0 : fprintf(irp->f, ")");
1608 : 0 : }
1609 : :
1610 : 0 : static void ir_print_byte_offset_of(IrPrint *irp, IrInstructionByteOffsetOf *instruction) {
1611 : 0 : fprintf(irp->f, "@byte_offset_of(");
1612 : 0 : ir_print_other_instruction(irp, instruction->type_value);
1613 : 0 : fprintf(irp->f, ",");
1614 : 0 : ir_print_other_instruction(irp, instruction->field_name);
1615 : 0 : fprintf(irp->f, ")");
1616 : 0 : }
1617 : :
1618 : 0 : static void ir_print_bit_offset_of(IrPrint *irp, IrInstructionBitOffsetOf *instruction) {
1619 : 0 : fprintf(irp->f, "@bit_offset_of(");
1620 : 0 : ir_print_other_instruction(irp, instruction->type_value);
1621 : 0 : fprintf(irp->f, ",");
1622 : 0 : ir_print_other_instruction(irp, instruction->field_name);
1623 : 0 : fprintf(irp->f, ")");
1624 : 0 : }
1625 : :
1626 : 0 : static void ir_print_type_info(IrPrint *irp, IrInstructionTypeInfo *instruction) {
1627 : 0 : fprintf(irp->f, "@typeInfo(");
1628 : 0 : ir_print_other_instruction(irp, instruction->type_value);
1629 : 0 : fprintf(irp->f, ")");
1630 : 0 : }
1631 : :
1632 : 0 : static void ir_print_type(IrPrint *irp, IrInstructionType *instruction) {
1633 : 0 : fprintf(irp->f, "@Type(");
1634 : 0 : ir_print_other_instruction(irp, instruction->type_info);
1635 : 0 : fprintf(irp->f, ")");
1636 : 0 : }
1637 : :
1638 : 0 : static void ir_print_has_field(IrPrint *irp, IrInstructionHasField *instruction) {
1639 : 0 : fprintf(irp->f, "@hasField(");
1640 : 0 : ir_print_other_instruction(irp, instruction->container_type);
1641 : 0 : fprintf(irp->f, ",");
1642 : 0 : ir_print_other_instruction(irp, instruction->field_name);
1643 : 0 : fprintf(irp->f, ")");
1644 : 0 : }
1645 : :
1646 : 0 : static void ir_print_type_id(IrPrint *irp, IrInstructionTypeId *instruction) {
1647 : 0 : fprintf(irp->f, "@typeId(");
1648 : 0 : ir_print_other_instruction(irp, instruction->type_value);
1649 : 0 : fprintf(irp->f, ")");
1650 : 0 : }
1651 : :
1652 : 0 : static void ir_print_set_eval_branch_quota(IrPrint *irp, IrInstructionSetEvalBranchQuota *instruction) {
1653 : 0 : fprintf(irp->f, "@setEvalBranchQuota(");
1654 : 0 : ir_print_other_instruction(irp, instruction->new_quota);
1655 : 0 : fprintf(irp->f, ")");
1656 : 0 : }
1657 : :
1658 : 0 : static void ir_print_align_cast(IrPrint *irp, IrInstructionAlignCast *instruction) {
1659 : 0 : fprintf(irp->f, "@alignCast(");
1660 [ # # ]: 0 : if (instruction->align_bytes == nullptr) {
1661 : 0 : fprintf(irp->f, "null");
1662 : : } else {
1663 : 0 : ir_print_other_instruction(irp, instruction->align_bytes);
1664 : : }
1665 : 0 : fprintf(irp->f, ",");
1666 : 0 : ir_print_other_instruction(irp, instruction->target);
1667 : 0 : fprintf(irp->f, ")");
1668 : 0 : }
1669 : :
1670 : 0 : static void ir_print_implicit_cast(IrPrint *irp, IrInstructionImplicitCast *instruction) {
1671 : 0 : fprintf(irp->f, "@implicitCast(");
1672 : 0 : ir_print_other_instruction(irp, instruction->dest_type);
1673 : 0 : fprintf(irp->f, ",");
1674 : 0 : ir_print_other_instruction(irp, instruction->target);
1675 : 0 : fprintf(irp->f, ")");
1676 : 0 : }
1677 : :
1678 : 0 : static void ir_print_resolve_result(IrPrint *irp, IrInstructionResolveResult *instruction) {
1679 : 0 : fprintf(irp->f, "ResolveResult(");
1680 : 0 : ir_print_result_loc(irp, instruction->result_loc);
1681 : 0 : fprintf(irp->f, ")");
1682 : 0 : }
1683 : :
1684 : 0 : static void ir_print_reset_result(IrPrint *irp, IrInstructionResetResult *instruction) {
1685 : 0 : fprintf(irp->f, "ResetResult(");
1686 : 0 : ir_print_result_loc(irp, instruction->result_loc);
1687 : 0 : fprintf(irp->f, ")");
1688 : 0 : }
1689 : :
1690 : 0 : static void ir_print_opaque_type(IrPrint *irp, IrInstructionOpaqueType *instruction) {
1691 : 0 : fprintf(irp->f, "@OpaqueType()");
1692 : 0 : }
1693 : :
1694 : 0 : static void ir_print_set_align_stack(IrPrint *irp, IrInstructionSetAlignStack *instruction) {
1695 : 0 : fprintf(irp->f, "@setAlignStack(");
1696 : 0 : ir_print_other_instruction(irp, instruction->align_bytes);
1697 : 0 : fprintf(irp->f, ")");
1698 : 0 : }
1699 : :
1700 : 0 : static void ir_print_arg_type(IrPrint *irp, IrInstructionArgType *instruction) {
1701 : 0 : fprintf(irp->f, "@ArgType(");
1702 : 0 : ir_print_other_instruction(irp, instruction->fn_type);
1703 : 0 : fprintf(irp->f, ",");
1704 : 0 : ir_print_other_instruction(irp, instruction->arg_index);
1705 : 0 : fprintf(irp->f, ")");
1706 : 0 : }
1707 : :
1708 : 0 : static void ir_print_enum_tag_type(IrPrint *irp, IrInstructionTagType *instruction) {
1709 : 0 : fprintf(irp->f, "@TagType(");
1710 : 0 : ir_print_other_instruction(irp, instruction->target);
1711 : 0 : fprintf(irp->f, ")");
1712 : 0 : }
1713 : :
1714 : 0 : static void ir_print_export(IrPrint *irp, IrInstructionExport *instruction) {
1715 [ # # ]: 0 : if (instruction->linkage == nullptr) {
1716 : 0 : fprintf(irp->f, "@export(");
1717 : 0 : ir_print_other_instruction(irp, instruction->name);
1718 : 0 : fprintf(irp->f, ",");
1719 : 0 : ir_print_other_instruction(irp, instruction->target);
1720 : 0 : fprintf(irp->f, ")");
1721 : : } else {
1722 : 0 : fprintf(irp->f, "@exportWithLinkage(");
1723 : 0 : ir_print_other_instruction(irp, instruction->name);
1724 : 0 : fprintf(irp->f, ",");
1725 : 0 : ir_print_other_instruction(irp, instruction->target);
1726 : 0 : fprintf(irp->f, ",");
1727 : 0 : ir_print_other_instruction(irp, instruction->linkage);
1728 : 0 : fprintf(irp->f, ")");
1729 : : }
1730 : 0 : }
1731 : :
1732 : 0 : static void ir_print_error_return_trace(IrPrint *irp, IrInstructionErrorReturnTrace *instruction) {
1733 : 0 : fprintf(irp->f, "@errorReturnTrace(");
1734 [ # # # ]: 0 : switch (instruction->optional) {
1735 : 0 : case IrInstructionErrorReturnTrace::Null:
1736 : 0 : fprintf(irp->f, "Null");
1737 : 0 : break;
1738 : 0 : case IrInstructionErrorReturnTrace::NonNull:
1739 : 0 : fprintf(irp->f, "NonNull");
1740 : 0 : break;
1741 : : }
1742 : 0 : fprintf(irp->f, ")");
1743 : 0 : }
1744 : :
1745 : 0 : static void ir_print_error_union(IrPrint *irp, IrInstructionErrorUnion *instruction) {
1746 : 0 : ir_print_other_instruction(irp, instruction->err_set);
1747 : 0 : fprintf(irp->f, "!");
1748 : 0 : ir_print_other_instruction(irp, instruction->payload);
1749 : 0 : }
1750 : :
1751 : 0 : static void ir_print_atomic_rmw(IrPrint *irp, IrInstructionAtomicRmw *instruction) {
1752 : 0 : fprintf(irp->f, "@atomicRmw(");
1753 [ # # ]: 0 : if (instruction->operand_type != nullptr) {
1754 : 0 : ir_print_other_instruction(irp, instruction->operand_type);
1755 : : } else {
1756 : 0 : fprintf(irp->f, "[TODO print]");
1757 : : }
1758 : 0 : fprintf(irp->f, ",");
1759 : 0 : ir_print_other_instruction(irp, instruction->ptr);
1760 : 0 : fprintf(irp->f, ",");
1761 [ # # ]: 0 : if (instruction->op != nullptr) {
1762 : 0 : ir_print_other_instruction(irp, instruction->op);
1763 : : } else {
1764 : 0 : fprintf(irp->f, "[TODO print]");
1765 : : }
1766 : 0 : fprintf(irp->f, ",");
1767 : 0 : ir_print_other_instruction(irp, instruction->operand);
1768 : 0 : fprintf(irp->f, ",");
1769 [ # # ]: 0 : if (instruction->ordering != nullptr) {
1770 : 0 : ir_print_other_instruction(irp, instruction->ordering);
1771 : : } else {
1772 : 0 : fprintf(irp->f, "[TODO print]");
1773 : : }
1774 : 0 : fprintf(irp->f, ")");
1775 : 0 : }
1776 : :
1777 : 0 : static void ir_print_atomic_load(IrPrint *irp, IrInstructionAtomicLoad *instruction) {
1778 : 0 : fprintf(irp->f, "@atomicLoad(");
1779 [ # # ]: 0 : if (instruction->operand_type != nullptr) {
1780 : 0 : ir_print_other_instruction(irp, instruction->operand_type);
1781 : : } else {
1782 : 0 : fprintf(irp->f, "[TODO print]");
1783 : : }
1784 : 0 : fprintf(irp->f, ",");
1785 : 0 : ir_print_other_instruction(irp, instruction->ptr);
1786 : 0 : fprintf(irp->f, ",");
1787 [ # # ]: 0 : if (instruction->ordering != nullptr) {
1788 : 0 : ir_print_other_instruction(irp, instruction->ordering);
1789 : : } else {
1790 : 0 : fprintf(irp->f, "[TODO print]");
1791 : : }
1792 : 0 : fprintf(irp->f, ")");
1793 : 0 : }
1794 : :
1795 : 0 : static void ir_print_save_err_ret_addr(IrPrint *irp, IrInstructionSaveErrRetAddr *instruction) {
1796 : 0 : fprintf(irp->f, "@saveErrRetAddr()");
1797 : 0 : }
1798 : :
1799 : 0 : static void ir_print_add_implicit_return_type(IrPrint *irp, IrInstructionAddImplicitReturnType *instruction) {
1800 : 0 : fprintf(irp->f, "@addImplicitReturnType(");
1801 : 0 : ir_print_other_instruction(irp, instruction->value);
1802 : 0 : fprintf(irp->f, ")");
1803 : 0 : }
1804 : :
1805 : 0 : static void ir_print_float_op(IrPrint *irp, IrInstructionFloatOp *instruction) {
1806 : :
1807 : 0 : fprintf(irp->f, "@%s(", float_op_to_name(instruction->op, false));
1808 [ # # ]: 0 : if (instruction->type != nullptr) {
1809 : 0 : ir_print_other_instruction(irp, instruction->type);
1810 : : } else {
1811 : 0 : fprintf(irp->f, "null");
1812 : : }
1813 : 0 : fprintf(irp->f, ",");
1814 : 0 : ir_print_other_instruction(irp, instruction->op1);
1815 : 0 : fprintf(irp->f, ")");
1816 : 0 : }
1817 : :
1818 : 0 : static void ir_print_mul_add(IrPrint *irp, IrInstructionMulAdd *instruction) {
1819 : 0 : fprintf(irp->f, "@mulAdd(");
1820 [ # # ]: 0 : if (instruction->type_value != nullptr) {
1821 : 0 : ir_print_other_instruction(irp, instruction->type_value);
1822 : : } else {
1823 : 0 : fprintf(irp->f, "null");
1824 : : }
1825 : 0 : fprintf(irp->f, ",");
1826 : 0 : ir_print_other_instruction(irp, instruction->op1);
1827 : 0 : fprintf(irp->f, ",");
1828 : 0 : ir_print_other_instruction(irp, instruction->op2);
1829 : 0 : fprintf(irp->f, ",");
1830 : 0 : ir_print_other_instruction(irp, instruction->op3);
1831 : 0 : fprintf(irp->f, ")");
1832 : 0 : }
1833 : :
1834 : 0 : static void ir_print_decl_var_gen(IrPrint *irp, IrInstructionDeclVarGen *decl_var_instruction) {
1835 : 0 : ZigVar *var = decl_var_instruction->var;
1836 [ # # ]: 0 : const char *var_or_const = decl_var_instruction->var->gen_is_const ? "const" : "var";
1837 : 0 : const char *name = buf_ptr(&decl_var_instruction->var->name);
1838 : 0 : fprintf(irp->f, "%s %s: %s align(%u) = ", var_or_const, name, buf_ptr(&var->var_type->name),
1839 : : var->align_bytes);
1840 : :
1841 : 0 : ir_print_other_instruction(irp, decl_var_instruction->var_ptr);
1842 [ # # ]: 0 : if (decl_var_instruction->var->is_comptime != nullptr) {
1843 : 0 : fprintf(irp->f, " // comptime = ");
1844 : 0 : ir_print_other_instruction(irp, decl_var_instruction->var->is_comptime);
1845 : : }
1846 : 0 : }
1847 : :
1848 : 0 : static void ir_print_has_decl(IrPrint *irp, IrInstructionHasDecl *instruction) {
1849 : 0 : fprintf(irp->f, "@hasDecl(");
1850 : 0 : ir_print_other_instruction(irp, instruction->container);
1851 : 0 : fprintf(irp->f, ",");
1852 : 0 : ir_print_other_instruction(irp, instruction->name);
1853 : 0 : fprintf(irp->f, ")");
1854 : 0 : }
1855 : :
1856 : 0 : static void ir_print_undeclared_ident(IrPrint *irp, IrInstructionUndeclaredIdent *instruction) {
1857 : 0 : fprintf(irp->f, "@undeclaredIdent(%s)", buf_ptr(instruction->name));
1858 : 0 : }
1859 : :
1860 : 0 : static void ir_print_union_init_named_field(IrPrint *irp, IrInstructionUnionInitNamedField *instruction) {
1861 : 0 : fprintf(irp->f, "@unionInit(");
1862 : 0 : ir_print_other_instruction(irp, instruction->union_type);
1863 : 0 : fprintf(irp->f, ", ");
1864 : 0 : ir_print_other_instruction(irp, instruction->field_name);
1865 : 0 : fprintf(irp->f, ", ");
1866 : 0 : ir_print_other_instruction(irp, instruction->field_result_loc);
1867 : 0 : fprintf(irp->f, ", ");
1868 : 0 : ir_print_other_instruction(irp, instruction->result_loc);
1869 : 0 : fprintf(irp->f, ")");
1870 : 0 : }
1871 : :
1872 : 0 : static void ir_print_suspend_begin(IrPrint *irp, IrInstructionSuspendBegin *instruction) {
1873 : 0 : fprintf(irp->f, "@suspendBegin()");
1874 : 0 : }
1875 : :
1876 : 0 : static void ir_print_suspend_finish(IrPrint *irp, IrInstructionSuspendFinish *instruction) {
1877 : 0 : fprintf(irp->f, "@suspendFinish()");
1878 : 0 : }
1879 : :
1880 : 0 : static void ir_print_resume(IrPrint *irp, IrInstructionResume *instruction) {
1881 : 0 : fprintf(irp->f, "resume ");
1882 : 0 : ir_print_other_instruction(irp, instruction->frame);
1883 : 0 : }
1884 : :
1885 : 0 : static void ir_print_await_src(IrPrint *irp, IrInstructionAwaitSrc *instruction) {
1886 : 0 : fprintf(irp->f, "@await(");
1887 : 0 : ir_print_other_instruction(irp, instruction->frame);
1888 : 0 : fprintf(irp->f, ",");
1889 : 0 : ir_print_result_loc(irp, instruction->result_loc);
1890 : 0 : fprintf(irp->f, ")");
1891 : 0 : }
1892 : :
1893 : 0 : static void ir_print_await_gen(IrPrint *irp, IrInstructionAwaitGen *instruction) {
1894 : 0 : fprintf(irp->f, "@await(");
1895 : 0 : ir_print_other_instruction(irp, instruction->frame);
1896 : 0 : fprintf(irp->f, ",");
1897 : 0 : ir_print_other_instruction(irp, instruction->result_loc);
1898 : 0 : fprintf(irp->f, ")");
1899 : 0 : }
1900 : :
1901 : 0 : static void ir_print_spill_begin(IrPrint *irp, IrInstructionSpillBegin *instruction) {
1902 : 0 : fprintf(irp->f, "@spillBegin(");
1903 : 0 : ir_print_other_instruction(irp, instruction->operand);
1904 : 0 : fprintf(irp->f, ")");
1905 : 0 : }
1906 : :
1907 : 0 : static void ir_print_spill_end(IrPrint *irp, IrInstructionSpillEnd *instruction) {
1908 : 0 : fprintf(irp->f, "@spillEnd(");
1909 : 0 : ir_print_other_instruction(irp, &instruction->begin->base);
1910 : 0 : fprintf(irp->f, ")");
1911 : 0 : }
1912 : :
1913 : 0 : static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction, bool trailing) {
1914 : 0 : ir_print_prefix(irp, instruction, trailing);
1915 [ # # # # : 0 : switch (instruction->id) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
1916 : 0 : case IrInstructionIdInvalid:
1917 : 0 : zig_unreachable();
1918 : 0 : case IrInstructionIdReturn:
1919 : 0 : ir_print_return(irp, (IrInstructionReturn *)instruction);
1920 : 0 : break;
1921 : 0 : case IrInstructionIdConst:
1922 : 0 : ir_print_const(irp, (IrInstructionConst *)instruction);
1923 : 0 : break;
1924 : 0 : case IrInstructionIdBinOp:
1925 : 0 : ir_print_bin_op(irp, (IrInstructionBinOp *)instruction);
1926 : 0 : break;
1927 : 0 : case IrInstructionIdDeclVarSrc:
1928 : 0 : ir_print_decl_var_src(irp, (IrInstructionDeclVarSrc *)instruction);
1929 : 0 : break;
1930 : 0 : case IrInstructionIdCast:
1931 : 0 : ir_print_cast(irp, (IrInstructionCast *)instruction);
1932 : 0 : break;
1933 : 0 : case IrInstructionIdCallSrc:
1934 : 0 : ir_print_call_src(irp, (IrInstructionCallSrc *)instruction);
1935 : 0 : break;
1936 : 0 : case IrInstructionIdCallGen:
1937 : 0 : ir_print_call_gen(irp, (IrInstructionCallGen *)instruction);
1938 : 0 : break;
1939 : 0 : case IrInstructionIdUnOp:
1940 : 0 : ir_print_un_op(irp, (IrInstructionUnOp *)instruction);
1941 : 0 : break;
1942 : 0 : case IrInstructionIdCondBr:
1943 : 0 : ir_print_cond_br(irp, (IrInstructionCondBr *)instruction);
1944 : 0 : break;
1945 : 0 : case IrInstructionIdBr:
1946 : 0 : ir_print_br(irp, (IrInstructionBr *)instruction);
1947 : 0 : break;
1948 : 0 : case IrInstructionIdPhi:
1949 : 0 : ir_print_phi(irp, (IrInstructionPhi *)instruction);
1950 : 0 : break;
1951 : 0 : case IrInstructionIdContainerInitList:
1952 : 0 : ir_print_container_init_list(irp, (IrInstructionContainerInitList *)instruction);
1953 : 0 : break;
1954 : 0 : case IrInstructionIdContainerInitFields:
1955 : 0 : ir_print_container_init_fields(irp, (IrInstructionContainerInitFields *)instruction);
1956 : 0 : break;
1957 : 0 : case IrInstructionIdUnreachable:
1958 : 0 : ir_print_unreachable(irp, (IrInstructionUnreachable *)instruction);
1959 : 0 : break;
1960 : 0 : case IrInstructionIdElemPtr:
1961 : 0 : ir_print_elem_ptr(irp, (IrInstructionElemPtr *)instruction);
1962 : 0 : break;
1963 : 0 : case IrInstructionIdVarPtr:
1964 : 0 : ir_print_var_ptr(irp, (IrInstructionVarPtr *)instruction);
1965 : 0 : break;
1966 : 0 : case IrInstructionIdReturnPtr:
1967 : 0 : ir_print_return_ptr(irp, (IrInstructionReturnPtr *)instruction);
1968 : 0 : break;
1969 : 0 : case IrInstructionIdLoadPtr:
1970 : 0 : ir_print_load_ptr(irp, (IrInstructionLoadPtr *)instruction);
1971 : 0 : break;
1972 : 0 : case IrInstructionIdLoadPtrGen:
1973 : 0 : ir_print_load_ptr_gen(irp, (IrInstructionLoadPtrGen *)instruction);
1974 : 0 : break;
1975 : 0 : case IrInstructionIdStorePtr:
1976 : 0 : ir_print_store_ptr(irp, (IrInstructionStorePtr *)instruction);
1977 : 0 : break;
1978 : 0 : case IrInstructionIdTypeOf:
1979 : 0 : ir_print_typeof(irp, (IrInstructionTypeOf *)instruction);
1980 : 0 : break;
1981 : 0 : case IrInstructionIdFieldPtr:
1982 : 0 : ir_print_field_ptr(irp, (IrInstructionFieldPtr *)instruction);
1983 : 0 : break;
1984 : 0 : case IrInstructionIdStructFieldPtr:
1985 : 0 : ir_print_struct_field_ptr(irp, (IrInstructionStructFieldPtr *)instruction);
1986 : 0 : break;
1987 : 0 : case IrInstructionIdUnionFieldPtr:
1988 : 0 : ir_print_union_field_ptr(irp, (IrInstructionUnionFieldPtr *)instruction);
1989 : 0 : break;
1990 : 0 : case IrInstructionIdSetCold:
1991 : 0 : ir_print_set_cold(irp, (IrInstructionSetCold *)instruction);
1992 : 0 : break;
1993 : 0 : case IrInstructionIdSetRuntimeSafety:
1994 : 0 : ir_print_set_runtime_safety(irp, (IrInstructionSetRuntimeSafety *)instruction);
1995 : 0 : break;
1996 : 0 : case IrInstructionIdSetFloatMode:
1997 : 0 : ir_print_set_float_mode(irp, (IrInstructionSetFloatMode *)instruction);
1998 : 0 : break;
1999 : 0 : case IrInstructionIdArrayType:
2000 : 0 : ir_print_array_type(irp, (IrInstructionArrayType *)instruction);
2001 : 0 : break;
2002 : 0 : case IrInstructionIdSliceType:
2003 : 0 : ir_print_slice_type(irp, (IrInstructionSliceType *)instruction);
2004 : 0 : break;
2005 : 0 : case IrInstructionIdAnyFrameType:
2006 : 0 : ir_print_any_frame_type(irp, (IrInstructionAnyFrameType *)instruction);
2007 : 0 : break;
2008 : 0 : case IrInstructionIdGlobalAsm:
2009 : 0 : ir_print_global_asm(irp, (IrInstructionGlobalAsm *)instruction);
2010 : 0 : break;
2011 : 0 : case IrInstructionIdAsm:
2012 : 0 : ir_print_asm(irp, (IrInstructionAsm *)instruction);
2013 : 0 : break;
2014 : 0 : case IrInstructionIdSizeOf:
2015 : 0 : ir_print_size_of(irp, (IrInstructionSizeOf *)instruction);
2016 : 0 : break;
2017 : 0 : case IrInstructionIdTestNonNull:
2018 : 0 : ir_print_test_non_null(irp, (IrInstructionTestNonNull *)instruction);
2019 : 0 : break;
2020 : 0 : case IrInstructionIdOptionalUnwrapPtr:
2021 : 0 : ir_print_optional_unwrap_ptr(irp, (IrInstructionOptionalUnwrapPtr *)instruction);
2022 : 0 : break;
2023 : 0 : case IrInstructionIdPopCount:
2024 : 0 : ir_print_pop_count(irp, (IrInstructionPopCount *)instruction);
2025 : 0 : break;
2026 : 0 : case IrInstructionIdClz:
2027 : 0 : ir_print_clz(irp, (IrInstructionClz *)instruction);
2028 : 0 : break;
2029 : 0 : case IrInstructionIdCtz:
2030 : 0 : ir_print_ctz(irp, (IrInstructionCtz *)instruction);
2031 : 0 : break;
2032 : 0 : case IrInstructionIdBswap:
2033 : 0 : ir_print_bswap(irp, (IrInstructionBswap *)instruction);
2034 : 0 : break;
2035 : 0 : case IrInstructionIdBitReverse:
2036 : 0 : ir_print_bit_reverse(irp, (IrInstructionBitReverse *)instruction);
2037 : 0 : break;
2038 : 0 : case IrInstructionIdSwitchBr:
2039 : 0 : ir_print_switch_br(irp, (IrInstructionSwitchBr *)instruction);
2040 : 0 : break;
2041 : 0 : case IrInstructionIdSwitchVar:
2042 : 0 : ir_print_switch_var(irp, (IrInstructionSwitchVar *)instruction);
2043 : 0 : break;
2044 : 0 : case IrInstructionIdSwitchElseVar:
2045 : 0 : ir_print_switch_else_var(irp, (IrInstructionSwitchElseVar *)instruction);
2046 : 0 : break;
2047 : 0 : case IrInstructionIdSwitchTarget:
2048 : 0 : ir_print_switch_target(irp, (IrInstructionSwitchTarget *)instruction);
2049 : 0 : break;
2050 : 0 : case IrInstructionIdUnionTag:
2051 : 0 : ir_print_union_tag(irp, (IrInstructionUnionTag *)instruction);
2052 : 0 : break;
2053 : 0 : case IrInstructionIdImport:
2054 : 0 : ir_print_import(irp, (IrInstructionImport *)instruction);
2055 : 0 : break;
2056 : 0 : case IrInstructionIdRef:
2057 : 0 : ir_print_ref(irp, (IrInstructionRef *)instruction);
2058 : 0 : break;
2059 : 0 : case IrInstructionIdRefGen:
2060 : 0 : ir_print_ref_gen(irp, (IrInstructionRefGen *)instruction);
2061 : 0 : break;
2062 : 0 : case IrInstructionIdCompileErr:
2063 : 0 : ir_print_compile_err(irp, (IrInstructionCompileErr *)instruction);
2064 : 0 : break;
2065 : 0 : case IrInstructionIdCompileLog:
2066 : 0 : ir_print_compile_log(irp, (IrInstructionCompileLog *)instruction);
2067 : 0 : break;
2068 : 0 : case IrInstructionIdErrName:
2069 : 0 : ir_print_err_name(irp, (IrInstructionErrName *)instruction);
2070 : 0 : break;
2071 : 0 : case IrInstructionIdCImport:
2072 : 0 : ir_print_c_import(irp, (IrInstructionCImport *)instruction);
2073 : 0 : break;
2074 : 0 : case IrInstructionIdCInclude:
2075 : 0 : ir_print_c_include(irp, (IrInstructionCInclude *)instruction);
2076 : 0 : break;
2077 : 0 : case IrInstructionIdCDefine:
2078 : 0 : ir_print_c_define(irp, (IrInstructionCDefine *)instruction);
2079 : 0 : break;
2080 : 0 : case IrInstructionIdCUndef:
2081 : 0 : ir_print_c_undef(irp, (IrInstructionCUndef *)instruction);
2082 : 0 : break;
2083 : 0 : case IrInstructionIdEmbedFile:
2084 : 0 : ir_print_embed_file(irp, (IrInstructionEmbedFile *)instruction);
2085 : 0 : break;
2086 : 0 : case IrInstructionIdCmpxchgSrc:
2087 : 0 : ir_print_cmpxchg_src(irp, (IrInstructionCmpxchgSrc *)instruction);
2088 : 0 : break;
2089 : 0 : case IrInstructionIdCmpxchgGen:
2090 : 0 : ir_print_cmpxchg_gen(irp, (IrInstructionCmpxchgGen *)instruction);
2091 : 0 : break;
2092 : 0 : case IrInstructionIdFence:
2093 : 0 : ir_print_fence(irp, (IrInstructionFence *)instruction);
2094 : 0 : break;
2095 : 0 : case IrInstructionIdTruncate:
2096 : 0 : ir_print_truncate(irp, (IrInstructionTruncate *)instruction);
2097 : 0 : break;
2098 : 0 : case IrInstructionIdIntCast:
2099 : 0 : ir_print_int_cast(irp, (IrInstructionIntCast *)instruction);
2100 : 0 : break;
2101 : 0 : case IrInstructionIdFloatCast:
2102 : 0 : ir_print_float_cast(irp, (IrInstructionFloatCast *)instruction);
2103 : 0 : break;
2104 : 0 : case IrInstructionIdErrSetCast:
2105 : 0 : ir_print_err_set_cast(irp, (IrInstructionErrSetCast *)instruction);
2106 : 0 : break;
2107 : 0 : case IrInstructionIdFromBytes:
2108 : 0 : ir_print_from_bytes(irp, (IrInstructionFromBytes *)instruction);
2109 : 0 : break;
2110 : 0 : case IrInstructionIdToBytes:
2111 : 0 : ir_print_to_bytes(irp, (IrInstructionToBytes *)instruction);
2112 : 0 : break;
2113 : 0 : case IrInstructionIdIntToFloat:
2114 : 0 : ir_print_int_to_float(irp, (IrInstructionIntToFloat *)instruction);
2115 : 0 : break;
2116 : 0 : case IrInstructionIdFloatToInt:
2117 : 0 : ir_print_float_to_int(irp, (IrInstructionFloatToInt *)instruction);
2118 : 0 : break;
2119 : 0 : case IrInstructionIdBoolToInt:
2120 : 0 : ir_print_bool_to_int(irp, (IrInstructionBoolToInt *)instruction);
2121 : 0 : break;
2122 : 0 : case IrInstructionIdIntType:
2123 : 0 : ir_print_int_type(irp, (IrInstructionIntType *)instruction);
2124 : 0 : break;
2125 : 0 : case IrInstructionIdVectorType:
2126 : 0 : ir_print_vector_type(irp, (IrInstructionVectorType *)instruction);
2127 : 0 : break;
2128 : 0 : case IrInstructionIdBoolNot:
2129 : 0 : ir_print_bool_not(irp, (IrInstructionBoolNot *)instruction);
2130 : 0 : break;
2131 : 0 : case IrInstructionIdMemset:
2132 : 0 : ir_print_memset(irp, (IrInstructionMemset *)instruction);
2133 : 0 : break;
2134 : 0 : case IrInstructionIdMemcpy:
2135 : 0 : ir_print_memcpy(irp, (IrInstructionMemcpy *)instruction);
2136 : 0 : break;
2137 : 0 : case IrInstructionIdSliceSrc:
2138 : 0 : ir_print_slice_src(irp, (IrInstructionSliceSrc *)instruction);
2139 : 0 : break;
2140 : 0 : case IrInstructionIdSliceGen:
2141 : 0 : ir_print_slice_gen(irp, (IrInstructionSliceGen *)instruction);
2142 : 0 : break;
2143 : 0 : case IrInstructionIdMemberCount:
2144 : 0 : ir_print_member_count(irp, (IrInstructionMemberCount *)instruction);
2145 : 0 : break;
2146 : 0 : case IrInstructionIdMemberType:
2147 : 0 : ir_print_member_type(irp, (IrInstructionMemberType *)instruction);
2148 : 0 : break;
2149 : 0 : case IrInstructionIdMemberName:
2150 : 0 : ir_print_member_name(irp, (IrInstructionMemberName *)instruction);
2151 : 0 : break;
2152 : 0 : case IrInstructionIdBreakpoint:
2153 : 0 : ir_print_breakpoint(irp, (IrInstructionBreakpoint *)instruction);
2154 : 0 : break;
2155 : 0 : case IrInstructionIdReturnAddress:
2156 : 0 : ir_print_return_address(irp, (IrInstructionReturnAddress *)instruction);
2157 : 0 : break;
2158 : 0 : case IrInstructionIdFrameAddress:
2159 : 0 : ir_print_frame_address(irp, (IrInstructionFrameAddress *)instruction);
2160 : 0 : break;
2161 : 0 : case IrInstructionIdFrameHandle:
2162 : 0 : ir_print_handle(irp, (IrInstructionFrameHandle *)instruction);
2163 : 0 : break;
2164 : 0 : case IrInstructionIdFrameType:
2165 : 0 : ir_print_frame_type(irp, (IrInstructionFrameType *)instruction);
2166 : 0 : break;
2167 : 0 : case IrInstructionIdFrameSizeSrc:
2168 : 0 : ir_print_frame_size_src(irp, (IrInstructionFrameSizeSrc *)instruction);
2169 : 0 : break;
2170 : 0 : case IrInstructionIdFrameSizeGen:
2171 : 0 : ir_print_frame_size_gen(irp, (IrInstructionFrameSizeGen *)instruction);
2172 : 0 : break;
2173 : 0 : case IrInstructionIdAlignOf:
2174 : 0 : ir_print_align_of(irp, (IrInstructionAlignOf *)instruction);
2175 : 0 : break;
2176 : 0 : case IrInstructionIdOverflowOp:
2177 : 0 : ir_print_overflow_op(irp, (IrInstructionOverflowOp *)instruction);
2178 : 0 : break;
2179 : 0 : case IrInstructionIdTestErrSrc:
2180 : 0 : ir_print_test_err_src(irp, (IrInstructionTestErrSrc *)instruction);
2181 : 0 : break;
2182 : 0 : case IrInstructionIdTestErrGen:
2183 : 0 : ir_print_test_err_gen(irp, (IrInstructionTestErrGen *)instruction);
2184 : 0 : break;
2185 : 0 : case IrInstructionIdUnwrapErrCode:
2186 : 0 : ir_print_unwrap_err_code(irp, (IrInstructionUnwrapErrCode *)instruction);
2187 : 0 : break;
2188 : 0 : case IrInstructionIdUnwrapErrPayload:
2189 : 0 : ir_print_unwrap_err_payload(irp, (IrInstructionUnwrapErrPayload *)instruction);
2190 : 0 : break;
2191 : 0 : case IrInstructionIdOptionalWrap:
2192 : 0 : ir_print_optional_wrap(irp, (IrInstructionOptionalWrap *)instruction);
2193 : 0 : break;
2194 : 0 : case IrInstructionIdErrWrapCode:
2195 : 0 : ir_print_err_wrap_code(irp, (IrInstructionErrWrapCode *)instruction);
2196 : 0 : break;
2197 : 0 : case IrInstructionIdErrWrapPayload:
2198 : 0 : ir_print_err_wrap_payload(irp, (IrInstructionErrWrapPayload *)instruction);
2199 : 0 : break;
2200 : 0 : case IrInstructionIdFnProto:
2201 : 0 : ir_print_fn_proto(irp, (IrInstructionFnProto *)instruction);
2202 : 0 : break;
2203 : 0 : case IrInstructionIdTestComptime:
2204 : 0 : ir_print_test_comptime(irp, (IrInstructionTestComptime *)instruction);
2205 : 0 : break;
2206 : 0 : case IrInstructionIdPtrCastSrc:
2207 : 0 : ir_print_ptr_cast_src(irp, (IrInstructionPtrCastSrc *)instruction);
2208 : 0 : break;
2209 : 0 : case IrInstructionIdPtrCastGen:
2210 : 0 : ir_print_ptr_cast_gen(irp, (IrInstructionPtrCastGen *)instruction);
2211 : 0 : break;
2212 : 0 : case IrInstructionIdBitCastSrc:
2213 : 0 : ir_print_bit_cast_src(irp, (IrInstructionBitCastSrc *)instruction);
2214 : 0 : break;
2215 : 0 : case IrInstructionIdBitCastGen:
2216 : 0 : ir_print_bit_cast_gen(irp, (IrInstructionBitCastGen *)instruction);
2217 : 0 : break;
2218 : 0 : case IrInstructionIdWidenOrShorten:
2219 : 0 : ir_print_widen_or_shorten(irp, (IrInstructionWidenOrShorten *)instruction);
2220 : 0 : break;
2221 : 0 : case IrInstructionIdPtrToInt:
2222 : 0 : ir_print_ptr_to_int(irp, (IrInstructionPtrToInt *)instruction);
2223 : 0 : break;
2224 : 0 : case IrInstructionIdIntToPtr:
2225 : 0 : ir_print_int_to_ptr(irp, (IrInstructionIntToPtr *)instruction);
2226 : 0 : break;
2227 : 0 : case IrInstructionIdIntToEnum:
2228 : 0 : ir_print_int_to_enum(irp, (IrInstructionIntToEnum *)instruction);
2229 : 0 : break;
2230 : 0 : case IrInstructionIdIntToErr:
2231 : 0 : ir_print_int_to_err(irp, (IrInstructionIntToErr *)instruction);
2232 : 0 : break;
2233 : 0 : case IrInstructionIdErrToInt:
2234 : 0 : ir_print_err_to_int(irp, (IrInstructionErrToInt *)instruction);
2235 : 0 : break;
2236 : 0 : case IrInstructionIdCheckSwitchProngs:
2237 : 0 : ir_print_check_switch_prongs(irp, (IrInstructionCheckSwitchProngs *)instruction);
2238 : 0 : break;
2239 : 0 : case IrInstructionIdCheckStatementIsVoid:
2240 : 0 : ir_print_check_statement_is_void(irp, (IrInstructionCheckStatementIsVoid *)instruction);
2241 : 0 : break;
2242 : 0 : case IrInstructionIdTypeName:
2243 : 0 : ir_print_type_name(irp, (IrInstructionTypeName *)instruction);
2244 : 0 : break;
2245 : 0 : case IrInstructionIdTagName:
2246 : 0 : ir_print_tag_name(irp, (IrInstructionTagName *)instruction);
2247 : 0 : break;
2248 : 0 : case IrInstructionIdPtrType:
2249 : 0 : ir_print_ptr_type(irp, (IrInstructionPtrType *)instruction);
2250 : 0 : break;
2251 : 0 : case IrInstructionIdDeclRef:
2252 : 0 : ir_print_decl_ref(irp, (IrInstructionDeclRef *)instruction);
2253 : 0 : break;
2254 : 0 : case IrInstructionIdPanic:
2255 : 0 : ir_print_panic(irp, (IrInstructionPanic *)instruction);
2256 : 0 : break;
2257 : 0 : case IrInstructionIdFieldParentPtr:
2258 : 0 : ir_print_field_parent_ptr(irp, (IrInstructionFieldParentPtr *)instruction);
2259 : 0 : break;
2260 : 0 : case IrInstructionIdByteOffsetOf:
2261 : 0 : ir_print_byte_offset_of(irp, (IrInstructionByteOffsetOf *)instruction);
2262 : 0 : break;
2263 : 0 : case IrInstructionIdBitOffsetOf:
2264 : 0 : ir_print_bit_offset_of(irp, (IrInstructionBitOffsetOf *)instruction);
2265 : 0 : break;
2266 : 0 : case IrInstructionIdTypeInfo:
2267 : 0 : ir_print_type_info(irp, (IrInstructionTypeInfo *)instruction);
2268 : 0 : break;
2269 : 0 : case IrInstructionIdType:
2270 : 0 : ir_print_type(irp, (IrInstructionType *)instruction);
2271 : 0 : break;
2272 : 0 : case IrInstructionIdHasField:
2273 : 0 : ir_print_has_field(irp, (IrInstructionHasField *)instruction);
2274 : 0 : break;
2275 : 0 : case IrInstructionIdTypeId:
2276 : 0 : ir_print_type_id(irp, (IrInstructionTypeId *)instruction);
2277 : 0 : break;
2278 : 0 : case IrInstructionIdSetEvalBranchQuota:
2279 : 0 : ir_print_set_eval_branch_quota(irp, (IrInstructionSetEvalBranchQuota *)instruction);
2280 : 0 : break;
2281 : 0 : case IrInstructionIdAlignCast:
2282 : 0 : ir_print_align_cast(irp, (IrInstructionAlignCast *)instruction);
2283 : 0 : break;
2284 : 0 : case IrInstructionIdImplicitCast:
2285 : 0 : ir_print_implicit_cast(irp, (IrInstructionImplicitCast *)instruction);
2286 : 0 : break;
2287 : 0 : case IrInstructionIdResolveResult:
2288 : 0 : ir_print_resolve_result(irp, (IrInstructionResolveResult *)instruction);
2289 : 0 : break;
2290 : 0 : case IrInstructionIdResetResult:
2291 : 0 : ir_print_reset_result(irp, (IrInstructionResetResult *)instruction);
2292 : 0 : break;
2293 : 0 : case IrInstructionIdOpaqueType:
2294 : 0 : ir_print_opaque_type(irp, (IrInstructionOpaqueType *)instruction);
2295 : 0 : break;
2296 : 0 : case IrInstructionIdSetAlignStack:
2297 : 0 : ir_print_set_align_stack(irp, (IrInstructionSetAlignStack *)instruction);
2298 : 0 : break;
2299 : 0 : case IrInstructionIdArgType:
2300 : 0 : ir_print_arg_type(irp, (IrInstructionArgType *)instruction);
2301 : 0 : break;
2302 : 0 : case IrInstructionIdTagType:
2303 : 0 : ir_print_enum_tag_type(irp, (IrInstructionTagType *)instruction);
2304 : 0 : break;
2305 : 0 : case IrInstructionIdExport:
2306 : 0 : ir_print_export(irp, (IrInstructionExport *)instruction);
2307 : 0 : break;
2308 : 0 : case IrInstructionIdErrorReturnTrace:
2309 : 0 : ir_print_error_return_trace(irp, (IrInstructionErrorReturnTrace *)instruction);
2310 : 0 : break;
2311 : 0 : case IrInstructionIdErrorUnion:
2312 : 0 : ir_print_error_union(irp, (IrInstructionErrorUnion *)instruction);
2313 : 0 : break;
2314 : 0 : case IrInstructionIdAtomicRmw:
2315 : 0 : ir_print_atomic_rmw(irp, (IrInstructionAtomicRmw *)instruction);
2316 : 0 : break;
2317 : 0 : case IrInstructionIdSaveErrRetAddr:
2318 : 0 : ir_print_save_err_ret_addr(irp, (IrInstructionSaveErrRetAddr *)instruction);
2319 : 0 : break;
2320 : 0 : case IrInstructionIdAddImplicitReturnType:
2321 : 0 : ir_print_add_implicit_return_type(irp, (IrInstructionAddImplicitReturnType *)instruction);
2322 : 0 : break;
2323 : 0 : case IrInstructionIdFloatOp:
2324 : 0 : ir_print_float_op(irp, (IrInstructionFloatOp *)instruction);
2325 : 0 : break;
2326 : 0 : case IrInstructionIdMulAdd:
2327 : 0 : ir_print_mul_add(irp, (IrInstructionMulAdd *)instruction);
2328 : 0 : break;
2329 : 0 : case IrInstructionIdAtomicLoad:
2330 : 0 : ir_print_atomic_load(irp, (IrInstructionAtomicLoad *)instruction);
2331 : 0 : break;
2332 : 0 : case IrInstructionIdEnumToInt:
2333 : 0 : ir_print_enum_to_int(irp, (IrInstructionEnumToInt *)instruction);
2334 : 0 : break;
2335 : 0 : case IrInstructionIdCheckRuntimeScope:
2336 : 0 : ir_print_check_runtime_scope(irp, (IrInstructionCheckRuntimeScope *)instruction);
2337 : 0 : break;
2338 : 0 : case IrInstructionIdDeclVarGen:
2339 : 0 : ir_print_decl_var_gen(irp, (IrInstructionDeclVarGen *)instruction);
2340 : 0 : break;
2341 : 0 : case IrInstructionIdArrayToVector:
2342 : 0 : ir_print_array_to_vector(irp, (IrInstructionArrayToVector *)instruction);
2343 : 0 : break;
2344 : 0 : case IrInstructionIdVectorToArray:
2345 : 0 : ir_print_vector_to_array(irp, (IrInstructionVectorToArray *)instruction);
2346 : 0 : break;
2347 : 0 : case IrInstructionIdPtrOfArrayToSlice:
2348 : 0 : ir_print_ptr_of_array_to_slice(irp, (IrInstructionPtrOfArrayToSlice *)instruction);
2349 : 0 : break;
2350 : 0 : case IrInstructionIdAssertZero:
2351 : 0 : ir_print_assert_zero(irp, (IrInstructionAssertZero *)instruction);
2352 : 0 : break;
2353 : 0 : case IrInstructionIdAssertNonNull:
2354 : 0 : ir_print_assert_non_null(irp, (IrInstructionAssertNonNull *)instruction);
2355 : 0 : break;
2356 : 0 : case IrInstructionIdResizeSlice:
2357 : 0 : ir_print_resize_slice(irp, (IrInstructionResizeSlice *)instruction);
2358 : 0 : break;
2359 : 0 : case IrInstructionIdHasDecl:
2360 : 0 : ir_print_has_decl(irp, (IrInstructionHasDecl *)instruction);
2361 : 0 : break;
2362 : 0 : case IrInstructionIdUndeclaredIdent:
2363 : 0 : ir_print_undeclared_ident(irp, (IrInstructionUndeclaredIdent *)instruction);
2364 : 0 : break;
2365 : 0 : case IrInstructionIdAllocaSrc:
2366 : 0 : ir_print_alloca_src(irp, (IrInstructionAllocaSrc *)instruction);
2367 : 0 : break;
2368 : 0 : case IrInstructionIdAllocaGen:
2369 : 0 : ir_print_alloca_gen(irp, (IrInstructionAllocaGen *)instruction);
2370 : 0 : break;
2371 : 0 : case IrInstructionIdEndExpr:
2372 : 0 : ir_print_end_expr(irp, (IrInstructionEndExpr *)instruction);
2373 : 0 : break;
2374 : 0 : case IrInstructionIdUnionInitNamedField:
2375 : 0 : ir_print_union_init_named_field(irp, (IrInstructionUnionInitNamedField *)instruction);
2376 : 0 : break;
2377 : 0 : case IrInstructionIdSuspendBegin:
2378 : 0 : ir_print_suspend_begin(irp, (IrInstructionSuspendBegin *)instruction);
2379 : 0 : break;
2380 : 0 : case IrInstructionIdSuspendFinish:
2381 : 0 : ir_print_suspend_finish(irp, (IrInstructionSuspendFinish *)instruction);
2382 : 0 : break;
2383 : 0 : case IrInstructionIdResume:
2384 : 0 : ir_print_resume(irp, (IrInstructionResume *)instruction);
2385 : 0 : break;
2386 : 0 : case IrInstructionIdAwaitSrc:
2387 : 0 : ir_print_await_src(irp, (IrInstructionAwaitSrc *)instruction);
2388 : 0 : break;
2389 : 0 : case IrInstructionIdAwaitGen:
2390 : 0 : ir_print_await_gen(irp, (IrInstructionAwaitGen *)instruction);
2391 : 0 : break;
2392 : 0 : case IrInstructionIdSpillBegin:
2393 : 0 : ir_print_spill_begin(irp, (IrInstructionSpillBegin *)instruction);
2394 : 0 : break;
2395 : 0 : case IrInstructionIdSpillEnd:
2396 : 0 : ir_print_spill_end(irp, (IrInstructionSpillEnd *)instruction);
2397 : 0 : break;
2398 : : }
2399 : 0 : fprintf(irp->f, "\n");
2400 : 0 : }
2401 : :
2402 : 0 : void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass) {
2403 : 0 : IrPrint ir_print = {};
2404 : 0 : IrPrint *irp = &ir_print;
2405 : 0 : irp->pass = pass;
2406 : 0 : irp->codegen = codegen;
2407 : 0 : irp->f = f;
2408 : 0 : irp->indent = indent_size;
2409 : 0 : irp->indent_size = indent_size;
2410 : 0 : irp->printed = {};
2411 : 0 : irp->printed.init(64);
2412 : 0 : irp->pending = {};
2413 : :
2414 [ # # ]: 0 : for (size_t bb_i = 0; bb_i < executable->basic_block_list.length; bb_i += 1) {
2415 : 0 : IrBasicBlock *current_block = executable->basic_block_list.at(bb_i);
2416 : 0 : fprintf(irp->f, "%s_%" ZIG_PRI_usize ":\n", current_block->name_hint, current_block->debug_id);
2417 [ # # ]: 0 : for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {
2418 : 0 : IrInstruction *instruction = current_block->instruction_list.at(instr_i);
2419 [ # # ]: 0 : if (irp->pass != IrPassSrc) {
2420 : 0 : irp->printed.put(instruction, 0);
2421 : 0 : irp->pending.clear();
2422 : : }
2423 : 0 : ir_print_instruction(irp, instruction, false);
2424 [ # # ]: 0 : for (size_t j = 0; j < irp->pending.length; ++j)
2425 : 0 : ir_print_instruction(irp, irp->pending.at(j), true);
2426 : : }
2427 : : }
2428 : :
2429 : 0 : irp->pending.deinit();
2430 : 0 : irp->printed.deinit();
2431 : 0 : }
2432 : :
2433 : 0 : void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass) {
2434 : 0 : IrPrint ir_print = {};
2435 : 0 : IrPrint *irp = &ir_print;
2436 : 0 : irp->pass = pass;
2437 : 0 : irp->codegen = codegen;
2438 : 0 : irp->f = f;
2439 : 0 : irp->indent = indent_size;
2440 : 0 : irp->indent_size = indent_size;
2441 : 0 : irp->printed = {};
2442 : 0 : irp->printed.init(4);
2443 : 0 : irp->pending = {};
2444 : :
2445 : 0 : ir_print_instruction(irp, instruction, false);
2446 : 0 : }
|