authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-29 23:33:12-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-29 23:33:12-05:00
loga95dce15ae4bd95cfd2266da51ba860cc6524a1b
treee761ecb74f37ff699d2e1f09d122811b101826e4
parent800ead2810fa573a7e94979e707a14d4e066ef77
parent7ebc624a15c5a01d6bee8eaf9c7487b30ed1904c
signaturelock-open Commit is signed but in an unrecognized format.

Merge remote-tracking branch 'origin/master' into llvm10


95 files changed, 31970 insertions(+), 10652 deletions(-)

doc/langref.html.in+1-1
...@@ -10113,7 +10113,7 @@ Available libcs:...@@ -10113,7 +10113,7 @@ Available libcs:
10113 The Zig Standard Library ({#syntax#}@import("std"){#endsyntax#}) has architecture, environment, and operating system10113 The Zig Standard Library ({#syntax#}@import("std"){#endsyntax#}) has architecture, environment, and operating system
10114 abstractions, and thus takes additional work to support more platforms.10114 abstractions, and thus takes additional work to support more platforms.
10115 Not all standard library code requires operating system abstractions, however,10115 Not all standard library code requires operating system abstractions, however,
10116 so things such as generic data structures work an all above platforms.10116 so things such as generic data structures work on all above platforms.
10117 </p>10117 </p>
10118 <p>The current list of targets supported by the Zig Standard Library is:</p>10118 <p>The current list of targets supported by the Zig Standard Library is:</p>
10119 <ul>10119 <ul>
lib/std/buffer.zig+3-3
...@@ -57,11 +57,11 @@ pub const Buffer = struct {...@@ -57,11 +57,11 @@ pub const Buffer = struct {
5757
58 /// The caller owns the returned memory. The Buffer becomes null and58 /// The caller owns the returned memory. The Buffer becomes null and
59 /// is safe to `deinit`.59 /// is safe to `deinit`.
60 pub fn toOwnedSlice(self: *Buffer) []u8 {60 pub fn toOwnedSlice(self: *Buffer) [:0]u8 {
61 const allocator = self.list.allocator;61 const allocator = self.list.allocator;
62 const result = allocator.shrink(self.list.items, self.len());62 const result = self.list.toOwnedSlice();
63 self.* = initNull(allocator);63 self.* = initNull(allocator);
64 return result;64 return result[0 .. result.len - 1 :0];
65 }65 }
6666
67 pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: var) !Buffer {67 pub fn allocPrint(allocator: *Allocator, comptime format: []const u8, args: var) !Buffer {
lib/std/build.zig+49-1
...@@ -484,6 +484,7 @@ pub const Builder = struct {...@@ -484,6 +484,7 @@ pub const Builder = struct {
484 .arch = builtin.arch,484 .arch = builtin.arch,
485 .os = builtin.os,485 .os = builtin.os,
486 .abi = builtin.abi,486 .abi = builtin.abi,
487 .cpu_features = builtin.cpu_features,
487 },488 },
488 }).linuxTriple(self.allocator);489 }).linuxTriple(self.allocator);
489490
...@@ -1148,6 +1149,7 @@ pub const LibExeObjStep = struct {...@@ -1148,6 +1149,7 @@ pub const LibExeObjStep = struct {
1148 name_prefix: []const u8,1149 name_prefix: []const u8,
1149 filter: ?[]const u8,1150 filter: ?[]const u8,
1150 single_threaded: bool,1151 single_threaded: bool,
1152 code_model: builtin.CodeModel = .default,
11511153
1152 root_src: ?FileSource,1154 root_src: ?FileSource,
1153 out_h_filename: []const u8,1155 out_h_filename: []const u8,
...@@ -1375,6 +1377,7 @@ pub const LibExeObjStep = struct {...@@ -1375,6 +1377,7 @@ pub const LibExeObjStep = struct {
1375 .arch = target_arch,1377 .arch = target_arch,
1376 .os = target_os,1378 .os = target_os,
1377 .abi = target_abi,1379 .abi = target_abi,
1380 .cpu_features = target_arch.getBaselineCpuFeatures(),
1378 },1381 },
1379 });1382 });
1380 }1383 }
...@@ -1968,11 +1971,56 @@ pub const LibExeObjStep = struct {...@@ -1968,11 +1971,56 @@ pub const LibExeObjStep = struct {
1968 try zig_args.append("-fno-sanitize-c");1971 try zig_args.append("-fno-sanitize-c");
1969 }1972 }
19701973
1974 if (self.code_model != .default) {
1975 try zig_args.append("-code-model");
1976 try zig_args.append(@tagName(self.code_model));
1977 }
1978
1971 switch (self.target) {1979 switch (self.target) {
1972 .Native => {},1980 .Native => {},
1973 .Cross => {1981 .Cross => |cross| {
1974 try zig_args.append("-target");1982 try zig_args.append("-target");
1975 try zig_args.append(self.target.zigTriple(builder.allocator) catch unreachable);1983 try zig_args.append(self.target.zigTriple(builder.allocator) catch unreachable);
1984
1985 const all_features = self.target.getArch().allFeaturesList();
1986 var populated_cpu_features = cross.cpu_features.cpu.features;
1987 if (self.target.getArch().subArchFeature()) |sub_arch_index| {
1988 populated_cpu_features.addFeature(sub_arch_index);
1989 }
1990 populated_cpu_features.populateDependencies(all_features);
1991
1992 if (populated_cpu_features.eql(cross.cpu_features.features)) {
1993 // The CPU name alone is sufficient.
1994 // If it is the baseline CPU, no command line args are required.
1995 if (cross.cpu_features.cpu != self.target.getArch().getBaselineCpuFeatures().cpu) {
1996 try zig_args.append("-target-cpu");
1997 try zig_args.append(cross.cpu_features.cpu.name);
1998 }
1999 } else {
2000 try zig_args.append("-target-cpu");
2001 try zig_args.append(cross.cpu_features.cpu.name);
2002
2003 try zig_args.append("-target-feature");
2004 var feature_str_buffer = try std.Buffer.initSize(builder.allocator, 0);
2005 for (all_features) |feature, i_usize| {
2006 const i = @intCast(Target.Cpu.Feature.Set.Index, i_usize);
2007 const in_cpu_set = populated_cpu_features.isEnabled(i);
2008 const in_actual_set = cross.cpu_features.features.isEnabled(i);
2009 if (in_cpu_set and !in_actual_set) {
2010 try feature_str_buffer.appendByte('-');
2011 try feature_str_buffer.append(feature.name);
2012 try feature_str_buffer.appendByte(',');
2013 } else if (!in_cpu_set and in_actual_set) {
2014 try feature_str_buffer.appendByte('+');
2015 try feature_str_buffer.append(feature.name);
2016 try feature_str_buffer.appendByte(',');
2017 }
2018 }
2019 if (mem.endsWith(u8, feature_str_buffer.toSliceConst(), ",")) {
2020 feature_str_buffer.shrink(feature_str_buffer.len() - 1);
2021 }
2022 try zig_args.append(feature_str_buffer.toSliceConst());
2023 }
1976 },2024 },
1977 }2025 }
19782026
lib/std/builtin.zig+24
...@@ -1,5 +1,8 @@...@@ -1,5 +1,8 @@
1pub usingnamespace @import("builtin");1pub usingnamespace @import("builtin");
22
3/// Deprecated: use `std.Target`.
4pub const Target = std.Target;
5
3/// Deprecated: use `std.Target.Os`.6/// Deprecated: use `std.Target.Os`.
4pub const Os = std.Target.Os;7pub const Os = std.Target.Os;
58
...@@ -15,6 +18,12 @@ pub const ObjectFormat = std.Target.ObjectFormat;...@@ -15,6 +18,12 @@ pub const ObjectFormat = std.Target.ObjectFormat;
15/// Deprecated: use `std.Target.SubSystem`.18/// Deprecated: use `std.Target.SubSystem`.
16pub const SubSystem = std.Target.SubSystem;19pub const SubSystem = std.Target.SubSystem;
1720
21/// Deprecated: use `std.Target.CpuFeatures`.
22pub const CpuFeatures = std.Target.CpuFeatures;
23
24/// Deprecated: use `std.Target.Cpu`.
25pub const Cpu = std.Target.Cpu;
26
18/// `explicit_subsystem` is missing when the subsystem is automatically detected,27/// `explicit_subsystem` is missing when the subsystem is automatically detected,
19/// so Zig standard library has the subsystem detection logic here. This should generally be28/// so Zig standard library has the subsystem detection logic here. This should generally be
20/// used rather than `explicit_subsystem`.29/// used rather than `explicit_subsystem`.
...@@ -82,6 +91,21 @@ pub const AtomicRmwOp = enum {...@@ -82,6 +91,21 @@ pub const AtomicRmwOp = enum {
82 Min,91 Min,
83};92};
8493
94/// The code model puts constraints on the location of symbols and the size of code and data.
95/// The selection of a code model is a trade off on speed and restrictions that needs to be selected on a per application basis to meet its requirements.
96/// A slightly more detailed explanation can be found in (for example) the [System V Application Binary Interface (x86_64)](https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-1.0.pdf) 3.5.1.
97///
98/// This data structure is used by the Zig language code generation and
99/// therefore must be kept in sync with the compiler implementation.
100pub const CodeModel = enum {
101 default,
102 tiny,
103 small,
104 kernel,
105 medium,
106 large,
107};
108
85/// This data structure is used by the Zig language code generation and109/// This data structure is used by the Zig language code generation and
86/// therefore must be kept in sync with the compiler implementation.110/// therefore must be kept in sync with the compiler implementation.
87pub const Mode = enum {111pub const Mode = enum {
lib/std/c.zig+6
...@@ -2,6 +2,12 @@ const builtin = @import("builtin");...@@ -2,6 +2,12 @@ const builtin = @import("builtin");
2const std = @import("std");2const std = @import("std");
3const page_size = std.mem.page_size;3const page_size = std.mem.page_size;
44
5pub const tokenizer = @import("c/tokenizer.zig");
6pub const Token = tokenizer.Token;
7pub const Tokenizer = tokenizer.Tokenizer;
8pub const parse = @import("c/parse.zig").parse;
9pub const ast = @import("c/ast.zig");
10
5pub usingnamespace @import("os/bits.zig");11pub usingnamespace @import("os/bits.zig");
612
7pub usingnamespace switch (builtin.os) {13pub usingnamespace switch (builtin.os) {
lib/std/c/ast.zig created+681
...@@ -0,0 +1,681 @@
1const std = @import("std");
2const SegmentedList = std.SegmentedList;
3const Token = std.c.Token;
4const Source = std.c.tokenizer.Source;
5
6pub const TokenIndex = usize;
7
8pub const Tree = struct {
9 tokens: TokenList,
10 sources: SourceList,
11 root_node: *Node.Root,
12 arena_allocator: std.heap.ArenaAllocator,
13 msgs: MsgList,
14
15 pub const SourceList = SegmentedList(Source, 4);
16 pub const TokenList = Source.TokenList;
17 pub const MsgList = SegmentedList(Msg, 0);
18
19 pub fn deinit(self: *Tree) void {
20 // Here we copy the arena allocator into stack memory, because
21 // otherwise it would destroy itself while it was still working.
22 var arena_allocator = self.arena_allocator;
23 arena_allocator.deinit();
24 // self is destroyed
25 }
26
27 pub fn tokenSlice(tree: *Tree, token: TokenIndex) []const u8 {
28 return tree.tokens.at(token).slice();
29 }
30
31 pub fn tokenEql(tree: *Tree, a: TokenIndex, b: TokenIndex) bool {
32 const atok = tree.tokens.at(a);
33 const btok = tree.tokens.at(b);
34 return atok.eql(btok.*);
35 }
36};
37
38pub const Msg = struct {
39 kind: enum {
40 Error,
41 Warning,
42 Note,
43 },
44 inner: Error,
45};
46
47pub const Error = union(enum) {
48 InvalidToken: SingleTokenError("invalid token '{}'"),
49 ExpectedToken: ExpectedToken,
50 ExpectedExpr: SingleTokenError("expected expression, found '{}'"),
51 ExpectedTypeName: SingleTokenError("expected type name, found '{}'"),
52 ExpectedFnBody: SingleTokenError("expected function body, found '{}'"),
53 ExpectedDeclarator: SingleTokenError("expected declarator, found '{}'"),
54 ExpectedInitializer: SingleTokenError("expected initializer, found '{}'"),
55 ExpectedEnumField: SingleTokenError("expected enum field, found '{}'"),
56 ExpectedType: SingleTokenError("expected enum field, found '{}'"),
57 InvalidTypeSpecifier: InvalidTypeSpecifier,
58 InvalidStorageClass: SingleTokenError("invalid storage class, found '{}'"),
59 InvalidDeclarator: SimpleError("invalid declarator"),
60 DuplicateQualifier: SingleTokenError("duplicate type qualifier '{}'"),
61 DuplicateSpecifier: SingleTokenError("duplicate declaration specifier '{}'"),
62 MustUseKwToRefer: MustUseKwToRefer,
63 FnSpecOnNonFn: SingleTokenError("function specifier '{}' on non function"),
64 NothingDeclared: SimpleError("declaration doesn't declare anything"),
65 QualifierIgnored: SingleTokenError("qualifier '{}' ignored"),
66
67 pub fn render(self: *const Error, tree: *Tree, stream: var) !void {
68 switch (self.*) {
69 .InvalidToken => |*x| return x.render(tree, stream),
70 .ExpectedToken => |*x| return x.render(tree, stream),
71 .ExpectedExpr => |*x| return x.render(tree, stream),
72 .ExpectedTypeName => |*x| return x.render(tree, stream),
73 .ExpectedDeclarator => |*x| return x.render(tree, stream),
74 .ExpectedFnBody => |*x| return x.render(tree, stream),
75 .ExpectedInitializer => |*x| return x.render(tree, stream),
76 .ExpectedEnumField => |*x| return x.render(tree, stream),
77 .ExpectedType => |*x| return x.render(tree, stream),
78 .InvalidTypeSpecifier => |*x| return x.render(tree, stream),
79 .InvalidStorageClass => |*x| return x.render(tree, stream),
80 .InvalidDeclarator => |*x| return x.render(tree, stream),
81 .DuplicateQualifier => |*x| return x.render(tree, stream),
82 .DuplicateSpecifier => |*x| return x.render(tree, stream),
83 .MustUseKwToRefer => |*x| return x.render(tree, stream),
84 .FnSpecOnNonFn => |*x| return x.render(tree, stream),
85 .NothingDeclared => |*x| return x.render(tree, stream),
86 .QualifierIgnored => |*x| return x.render(tree, stream),
87 }
88 }
89
90 pub fn loc(self: *const Error) TokenIndex {
91 switch (self.*) {
92 .InvalidToken => |x| return x.token,
93 .ExpectedToken => |x| return x.token,
94 .ExpectedExpr => |x| return x.token,
95 .ExpectedTypeName => |x| return x.token,
96 .ExpectedDeclarator => |x| return x.token,
97 .ExpectedFnBody => |x| return x.token,
98 .ExpectedInitializer => |x| return x.token,
99 .ExpectedEnumField => |x| return x.token,
100 .ExpectedType => |*x| return x.token,
101 .InvalidTypeSpecifier => |x| return x.token,
102 .InvalidStorageClass => |x| return x.token,
103 .InvalidDeclarator => |x| return x.token,
104 .DuplicateQualifier => |x| return x.token,
105 .DuplicateSpecifier => |x| return x.token,
106 .MustUseKwToRefer => |*x| return x.name,
107 .FnSpecOnNonFn => |*x| return x.name,
108 .NothingDeclared => |*x| return x.name,
109 .QualifierIgnored => |*x| return x.name,
110 }
111 }
112
113 pub const ExpectedToken = struct {
114 token: TokenIndex,
115 expected_id: @TagType(Token.Id),
116
117 pub fn render(self: *const ExpectedToken, tree: *Tree, stream: var) !void {
118 const found_token = tree.tokens.at(self.token);
119 if (found_token.id == .Invalid) {
120 return stream.print("expected '{}', found invalid bytes", .{self.expected_id.symbol()});
121 } else {
122 const token_name = found_token.id.symbol();
123 return stream.print("expected '{}', found '{}'", .{ self.expected_id.symbol(), token_name });
124 }
125 }
126 };
127
128 pub const InvalidTypeSpecifier = struct {
129 token: TokenIndex,
130 type_spec: *Node.TypeSpec,
131
132 pub fn render(self: *const ExpectedToken, tree: *Tree, stream: var) !void {
133 try stream.write("invalid type specifier '");
134 try type_spec.spec.print(tree, stream);
135 const token_name = tree.tokens.at(self.token).id.symbol();
136 return stream.print("{}'", .{token_name});
137 }
138 };
139
140 pub const MustUseKwToRefer = struct {
141 kw: TokenIndex,
142 name: TokenIndex,
143
144 pub fn render(self: *const ExpectedToken, tree: *Tree, stream: var) !void {
145 return stream.print("must use '{}' tag to refer to type '{}'", .{ tree.slice(kw), tree.slice(name) });
146 }
147 };
148
149 fn SingleTokenError(comptime msg: []const u8) type {
150 return struct {
151 token: TokenIndex,
152
153 pub fn render(self: *const @This(), tree: *Tree, stream: var) !void {
154 const actual_token = tree.tokens.at(self.token);
155 return stream.print(msg, .{actual_token.id.symbol()});
156 }
157 };
158 }
159
160 fn SimpleError(comptime msg: []const u8) type {
161 return struct {
162 const ThisError = @This();
163
164 token: TokenIndex,
165
166 pub fn render(self: *const ThisError, tokens: *Tree.TokenList, stream: var) !void {
167 return stream.write(msg);
168 }
169 };
170 }
171};
172
173pub const Type = struct {
174 pub const TypeList = std.SegmentedList(*Type, 4);
175 @"const": bool = false,
176 atomic: bool = false,
177 @"volatile": bool = false,
178 restrict: bool = false,
179
180 id: union(enum) {
181 Int: struct {
182 id: Id,
183 is_signed: bool,
184
185 pub const Id = enum {
186 Char,
187 Short,
188 Int,
189 Long,
190 LongLong,
191 };
192 },
193 Float: struct {
194 id: Id,
195
196 pub const Id = enum {
197 Float,
198 Double,
199 LongDouble,
200 };
201 },
202 Pointer: *Type,
203 Function: struct {
204 return_type: *Type,
205 param_types: TypeList,
206 },
207 Typedef: *Type,
208 Record: *Node.RecordType,
209 Enum: *Node.EnumType,
210
211 /// Special case for macro parameters that can be any type.
212 /// Only present if `retain_macros == true`.
213 Macro,
214 },
215};
216
217pub const Node = struct {
218 id: Id,
219
220 pub const Id = enum {
221 Root,
222 EnumField,
223 RecordField,
224 RecordDeclarator,
225 JumpStmt,
226 ExprStmt,
227 LabeledStmt,
228 CompoundStmt,
229 IfStmt,
230 SwitchStmt,
231 WhileStmt,
232 DoStmt,
233 ForStmt,
234 StaticAssert,
235 Declarator,
236 Pointer,
237 FnDecl,
238 Typedef,
239 VarDecl,
240 };
241
242 pub const Root = struct {
243 base: Node = Node{ .id = .Root },
244 decls: DeclList,
245 eof: TokenIndex,
246
247 pub const DeclList = SegmentedList(*Node, 4);
248 };
249
250 pub const DeclSpec = struct {
251 storage_class: union(enum) {
252 Auto: TokenIndex,
253 Extern: TokenIndex,
254 Register: TokenIndex,
255 Static: TokenIndex,
256 Typedef: TokenIndex,
257 None,
258 } = .None,
259 thread_local: ?TokenIndex = null,
260 type_spec: TypeSpec = TypeSpec{},
261 fn_spec: union(enum) {
262 Inline: TokenIndex,
263 Noreturn: TokenIndex,
264 None,
265 } = .None,
266 align_spec: ?struct {
267 alignas: TokenIndex,
268 expr: *Node,
269 rparen: TokenIndex,
270 } = null,
271 };
272
273 pub const TypeSpec = struct {
274 qual: TypeQual = TypeQual{},
275 spec: union(enum) {
276 /// error or default to int
277 None,
278 Void: TokenIndex,
279 Char: struct {
280 sign: ?TokenIndex = null,
281 char: TokenIndex,
282 },
283 Short: struct {
284 sign: ?TokenIndex = null,
285 short: TokenIndex = null,
286 int: ?TokenIndex = null,
287 },
288 Int: struct {
289 sign: ?TokenIndex = null,
290 int: ?TokenIndex = null,
291 },
292 Long: struct {
293 sign: ?TokenIndex = null,
294 long: TokenIndex,
295 longlong: ?TokenIndex = null,
296 int: ?TokenIndex = null,
297 },
298 Float: struct {
299 float: TokenIndex,
300 complex: ?TokenIndex = null,
301 },
302 Double: struct {
303 long: ?TokenIndex = null,
304 double: ?TokenIndex,
305 complex: ?TokenIndex = null,
306 },
307 Bool: TokenIndex,
308 Atomic: struct {
309 atomic: TokenIndex,
310 typename: *Node,
311 rparen: TokenIndex,
312 },
313 Enum: *EnumType,
314 Record: *RecordType,
315 Typedef: struct {
316 sym: TokenIndex,
317 sym_type: *Type,
318 },
319
320 pub fn print(self: *@This(), self: *const @This(), tree: *Tree, stream: var) !void {
321 switch (self.spec) {
322 .None => unreachable,
323 .Void => |index| try stream.write(tree.slice(index)),
324 .Char => |char| {
325 if (char.sign) |s| {
326 try stream.write(tree.slice(s));
327 try stream.writeByte(' ');
328 }
329 try stream.write(tree.slice(char.char));
330 },
331 .Short => |short| {
332 if (short.sign) |s| {
333 try stream.write(tree.slice(s));
334 try stream.writeByte(' ');
335 }
336 try stream.write(tree.slice(short.short));
337 if (short.int) |i| {
338 try stream.writeByte(' ');
339 try stream.write(tree.slice(i));
340 }
341 },
342 .Int => |int| {
343 if (int.sign) |s| {
344 try stream.write(tree.slice(s));
345 try stream.writeByte(' ');
346 }
347 if (int.int) |i| {
348 try stream.writeByte(' ');
349 try stream.write(tree.slice(i));
350 }
351 },
352 .Long => |long| {
353 if (long.sign) |s| {
354 try stream.write(tree.slice(s));
355 try stream.writeByte(' ');
356 }
357 try stream.write(tree.slice(long.long));
358 if (long.longlong) |l| {
359 try stream.writeByte(' ');
360 try stream.write(tree.slice(l));
361 }
362 if (long.int) |i| {
363 try stream.writeByte(' ');
364 try stream.write(tree.slice(i));
365 }
366 },
367 .Float => |float| {
368 try stream.write(tree.slice(float.float));
369 if (float.complex) |c| {
370 try stream.writeByte(' ');
371 try stream.write(tree.slice(c));
372 }
373 },
374 .Double => |double| {
375 if (double.long) |l| {
376 try stream.write(tree.slice(l));
377 try stream.writeByte(' ');
378 }
379 try stream.write(tree.slice(double.double));
380 if (double.complex) |c| {
381 try stream.writeByte(' ');
382 try stream.write(tree.slice(c));
383 }
384 },
385 .Bool => |index| try stream.write(tree.slice(index)),
386 .Typedef => |typedef| try stream.write(tree.slice(typedef.sym)),
387 else => try stream.print("TODO print {}", self.spec),
388 }
389 }
390 } = .None,
391 };
392
393 pub const EnumType = struct {
394 tok: TokenIndex,
395 name: ?TokenIndex,
396 body: ?struct {
397 lbrace: TokenIndex,
398
399 /// always EnumField
400 fields: FieldList,
401 rbrace: TokenIndex,
402 },
403
404 pub const FieldList = Root.DeclList;
405 };
406
407 pub const EnumField = struct {
408 base: Node = Node{ .id = .EnumField },
409 name: TokenIndex,
410 value: ?*Node,
411 };
412
413 pub const RecordType = struct {
414 tok: TokenIndex,
415 kind: enum {
416 Struct,
417 Union,
418 },
419 name: ?TokenIndex,
420 body: ?struct {
421 lbrace: TokenIndex,
422
423 /// RecordField or StaticAssert
424 fields: FieldList,
425 rbrace: TokenIndex,
426 },
427
428 pub const FieldList = Root.DeclList;
429 };
430
431 pub const RecordField = struct {
432 base: Node = Node{ .id = .RecordField },
433 type_spec: TypeSpec,
434 declarators: DeclaratorList,
435 semicolon: TokenIndex,
436
437 pub const DeclaratorList = Root.DeclList;
438 };
439
440 pub const RecordDeclarator = struct {
441 base: Node = Node{ .id = .RecordDeclarator },
442 declarator: ?*Declarator,
443 bit_field_expr: ?*Expr,
444 };
445
446 pub const TypeQual = struct {
447 @"const": ?TokenIndex = null,
448 atomic: ?TokenIndex = null,
449 @"volatile": ?TokenIndex = null,
450 restrict: ?TokenIndex = null,
451 };
452
453 pub const JumpStmt = struct {
454 base: Node = Node{ .id = .JumpStmt },
455 ltoken: TokenIndex,
456 kind: union(enum) {
457 Break,
458 Continue,
459 Return: ?*Node,
460 Goto: TokenIndex,
461 },
462 semicolon: TokenIndex,
463 };
464
465 pub const ExprStmt = struct {
466 base: Node = Node{ .id = .ExprStmt },
467 expr: ?*Expr,
468 semicolon: TokenIndex,
469 };
470
471 pub const LabeledStmt = struct {
472 base: Node = Node{ .id = .LabeledStmt },
473 kind: union(enum) {
474 Label: TokenIndex,
475 Case: TokenIndex,
476 Default: TokenIndex,
477 },
478 stmt: *Node,
479 };
480
481 pub const CompoundStmt = struct {
482 base: Node = Node{ .id = .CompoundStmt },
483 lbrace: TokenIndex,
484 statements: StmtList,
485 rbrace: TokenIndex,
486
487 pub const StmtList = Root.DeclList;
488 };
489
490 pub const IfStmt = struct {
491 base: Node = Node{ .id = .IfStmt },
492 @"if": TokenIndex,
493 cond: *Node,
494 body: *Node,
495 @"else": ?struct {
496 tok: TokenIndex,
497 body: *Node,
498 },
499 };
500
501 pub const SwitchStmt = struct {
502 base: Node = Node{ .id = .SwitchStmt },
503 @"switch": TokenIndex,
504 expr: *Expr,
505 rparen: TokenIndex,
506 stmt: *Node,
507 };
508
509 pub const WhileStmt = struct {
510 base: Node = Node{ .id = .WhileStmt },
511 @"while": TokenIndex,
512 cond: *Expr,
513 rparen: TokenIndex,
514 body: *Node,
515 };
516
517 pub const DoStmt = struct {
518 base: Node = Node{ .id = .DoStmt },
519 do: TokenIndex,
520 body: *Node,
521 @"while": TokenIndex,
522 cond: *Expr,
523 semicolon: TokenIndex,
524 };
525
526 pub const ForStmt = struct {
527 base: Node = Node{ .id = .ForStmt },
528 @"for": TokenIndex,
529 init: ?*Node,
530 cond: ?*Expr,
531 semicolon: TokenIndex,
532 incr: ?*Expr,
533 rparen: TokenIndex,
534 body: *Node,
535 };
536
537 pub const StaticAssert = struct {
538 base: Node = Node{ .id = .StaticAssert },
539 assert: TokenIndex,
540 expr: *Node,
541 semicolon: TokenIndex,
542 };
543
544 pub const Declarator = struct {
545 base: Node = Node{ .id = .Declarator },
546 pointer: ?*Pointer,
547 prefix: union(enum) {
548 None,
549 Identifer: TokenIndex,
550 Complex: struct {
551 lparen: TokenIndex,
552 inner: *Node,
553 rparen: TokenIndex,
554 },
555 },
556 suffix: union(enum) {
557 None,
558 Fn: struct {
559 lparen: TokenIndex,
560 params: Params,
561 rparen: TokenIndex,
562 },
563 Array: Arrays,
564 },
565
566 pub const Arrays = std.SegmentedList(*Array, 2);
567 pub const Params = std.SegmentedList(*Param, 4);
568 };
569
570 pub const Array = struct {
571 lbracket: TokenIndex,
572 inner: union(enum) {
573 Inferred,
574 Unspecified: TokenIndex,
575 Variable: struct {
576 asterisk: ?TokenIndex,
577 static: ?TokenIndex,
578 qual: TypeQual,
579 expr: *Expr,
580 },
581 },
582 rbracket: TokenIndex,
583 };
584
585 pub const Pointer = struct {
586 base: Node = Node{ .id = .Pointer },
587 asterisk: TokenIndex,
588 qual: TypeQual,
589 pointer: ?*Pointer,
590 };
591
592 pub const Param = struct {
593 kind: union(enum) {
594 Variable,
595 Old: TokenIndex,
596 Normal: struct {
597 decl_spec: *DeclSpec,
598 declarator: *Node,
599 },
600 },
601 };
602
603 pub const FnDecl = struct {
604 base: Node = Node{ .id = .FnDecl },
605 decl_spec: DeclSpec,
606 declarator: *Declarator,
607 old_decls: OldDeclList,
608 body: ?*CompoundStmt,
609
610 pub const OldDeclList = SegmentedList(*Node, 0);
611 };
612
613 pub const Typedef = struct {
614 base: Node = Node{ .id = .Typedef },
615 decl_spec: DeclSpec,
616 declarators: DeclaratorList,
617 semicolon: TokenIndex,
618
619 pub const DeclaratorList = Root.DeclList;
620 };
621
622 pub const VarDecl = struct {
623 base: Node = Node{ .id = .VarDecl },
624 decl_spec: DeclSpec,
625 initializers: Initializers,
626 semicolon: TokenIndex,
627
628 pub const Initializers = Root.DeclList;
629 };
630
631 pub const Initialized = struct {
632 base: Node = Node{ .id = Initialized },
633 declarator: *Declarator,
634 eq: TokenIndex,
635 init: Initializer,
636 };
637
638 pub const Initializer = union(enum) {
639 list: struct {
640 initializers: InitializerList,
641 rbrace: TokenIndex,
642 },
643 expr: *Expr,
644 pub const InitializerList = std.SegmentedList(*Initializer, 4);
645 };
646
647 pub const Macro = struct {
648 base: Node = Node{ .id = Macro },
649 kind: union(enum) {
650 Undef: []const u8,
651 Fn: struct {
652 params: []const []const u8,
653 expr: *Expr,
654 },
655 Expr: *Expr,
656 },
657 };
658};
659
660pub const Expr = struct {
661 id: Id,
662 ty: *Type,
663 value: union(enum) {
664 None,
665 },
666
667 pub const Id = enum {
668 Infix,
669 Literal,
670 };
671
672 pub const Infix = struct {
673 base: Expr = Expr{ .id = .Infix },
674 lhs: *Expr,
675 op_token: TokenIndex,
676 op: Op,
677 rhs: *Expr,
678
679 pub const Op = enum {};
680 };
681};
lib/std/c/darwin.zig+3
...@@ -7,7 +7,10 @@ usingnamespace @import("../os/bits.zig");...@@ -7,7 +7,10 @@ usingnamespace @import("../os/bits.zig");
77
8extern "c" fn __error() *c_int;8extern "c" fn __error() *c_int;
9pub extern "c" fn _NSGetExecutablePath(buf: [*]u8, bufsize: *u32) c_int;9pub extern "c" fn _NSGetExecutablePath(buf: [*]u8, bufsize: *u32) c_int;
10pub extern "c" fn _dyld_image_count() u32;
10pub extern "c" fn _dyld_get_image_header(image_index: u32) ?*mach_header;11pub extern "c" fn _dyld_get_image_header(image_index: u32) ?*mach_header;
12pub extern "c" fn _dyld_get_image_vmaddr_slide(image_index: u32) usize;
13pub extern "c" fn _dyld_get_image_name(image_index: u32) [*:0]const u8;
1114
12pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize;15pub extern "c" fn __getdirentries64(fd: c_int, buf_ptr: [*]u8, buf_len: usize, basep: *i64) isize;
1316
lib/std/c/parse.zig created+1431
...@@ -0,0 +1,1431 @@
1const std = @import("std");
2const mem = std.mem;
3const assert = std.debug.assert;
4const Allocator = std.mem.Allocator;
5const ast = std.c.ast;
6const Node = ast.Node;
7const Type = ast.Type;
8const Tree = ast.Tree;
9const TokenIndex = ast.TokenIndex;
10const Token = std.c.Token;
11const TokenIterator = ast.Tree.TokenList.Iterator;
12
13pub const Error = error{ParseError} || Allocator.Error;
14
15pub const Options = struct {
16 // /// Keep simple macros unexpanded and add the definitions to the ast
17 // retain_macros: bool = false,
18 /// Warning or error
19 warn_as_err: union(enum) {
20 /// All warnings are warnings
21 None,
22
23 /// Some warnings are errors
24 Some: []@TagType(ast.Error),
25
26 /// All warnings are errors
27 All,
28 } = .All,
29};
30
31/// Result should be freed with tree.deinit() when there are
32/// no more references to any of the tokens or nodes.
33pub fn parse(allocator: *Allocator, source: []const u8, options: Options) !*Tree {
34 const tree = blk: {
35 // This block looks unnecessary, but is a "foot-shield" to prevent the SegmentedLists
36 // from being initialized with a pointer to this `arena`, which is created on
37 // the stack. Following code should instead refer to `&tree.arena_allocator`, a
38 // pointer to data which lives safely on the heap and will outlive `parse`.
39 var arena = std.heap.ArenaAllocator.init(allocator);
40 errdefer arena.deinit();
41 const tree = try arena.allocator.create(ast.Tree);
42 tree.* = .{
43 .root_node = undefined,
44 .arena_allocator = arena,
45 .tokens = undefined,
46 .sources = undefined,
47 };
48 break :blk tree;
49 };
50 errdefer tree.deinit();
51 const arena = &tree.arena_allocator.allocator;
52
53 tree.tokens = ast.Tree.TokenList.init(arena);
54 tree.sources = ast.Tree.SourceList.init(arena);
55
56 var tokenizer = std.zig.Tokenizer.init(source);
57 while (true) {
58 const tree_token = try tree.tokens.addOne();
59 tree_token.* = tokenizer.next();
60 if (tree_token.id == .Eof) break;
61 }
62 // TODO preprocess here
63 var it = tree.tokens.iterator(0);
64
65 while (true) {
66 const tok = it.peek().?.id;
67 switch (id) {
68 .LineComment,
69 .MultiLineComment,
70 => {
71 _ = it.next();
72 },
73 else => break,
74 }
75 }
76
77 var parse_arena = std.heap.ArenaAllocator.init(allocator);
78 defer parse_arena.deinit();
79
80 var parser = Parser{
81 .scopes = Parser.SymbolList.init(allocator),
82 .arena = &parse_arena.allocator,
83 .it = &it,
84 .tree = tree,
85 .options = options,
86 };
87 defer parser.symbols.deinit();
88
89 tree.root_node = try parser.root();
90 return tree;
91}
92
93const Parser = struct {
94 arena: *Allocator,
95 it: *TokenIterator,
96 tree: *Tree,
97
98 arena: *Allocator,
99 scopes: ScopeList,
100 options: Options,
101
102 const ScopeList = std.SegmentedLists(Scope);
103 const SymbolList = std.SegmentedLists(Symbol);
104
105 const Scope = struct {
106 kind: ScopeKind,
107 syms: SymbolList,
108 };
109
110 const Symbol = struct {
111 name: []const u8,
112 ty: *Type,
113 };
114
115 const ScopeKind = enum {
116 Block,
117 Loop,
118 Root,
119 Switch,
120 };
121
122 fn pushScope(parser: *Parser, kind: ScopeKind) !void {
123 const new = try parser.scopes.addOne();
124 new.* = .{
125 .kind = kind,
126 .syms = SymbolList.init(parser.arena),
127 };
128 }
129
130 fn popScope(parser: *Parser, len: usize) void {
131 _ = parser.scopes.pop();
132 }
133
134 fn getSymbol(parser: *Parser, tok: TokenIndex) ?*Symbol {
135 const name = parser.tree.tokenSlice(tok);
136 var scope_it = parser.scopes.iterator(parser.scopes.len);
137 while (scope_it.prev()) |scope| {
138 var sym_it = scope.syms.iterator(scope.syms.len);
139 while (sym_it.prev()) |sym| {
140 if (mem.eql(u8, sym.name, name)) {
141 return sym;
142 }
143 }
144 }
145 return null;
146 }
147
148 fn declareSymbol(parser: *Parser, type_spec: Node.TypeSpec, dr: *Node.Declarator) Error!void {
149 return; // TODO
150 }
151
152 /// Root <- ExternalDeclaration* eof
153 fn root(parser: *Parser) Allocator.Error!*Node.Root {
154 try parser.pushScope(.Root);
155 defer parser.popScope();
156 const node = try parser.arena.create(Node.Root);
157 node.* = .{
158 .decls = Node.Root.DeclList.init(parser.arena),
159 .eof = undefined,
160 };
161 while (parser.externalDeclarations() catch |e| switch (e) {
162 error.OutOfMemory => return error.OutOfMemory,
163 error.ParseError => return node,
164 }) |decl| {
165 try node.decls.push(decl);
166 }
167 node.eof = parser.eatToken(.Eof) orelse return node;
168 return node;
169 }
170
171 /// ExternalDeclaration
172 /// <- DeclSpec Declarator OldStyleDecl* CompoundStmt
173 /// / Declaration
174 /// OldStyleDecl <- DeclSpec Declarator (COMMA Declarator)* SEMICOLON
175 fn externalDeclarations(parser: *Parser) !?*Node {
176 return parser.declarationExtra(false);
177 }
178
179 /// Declaration
180 /// <- DeclSpec DeclInit SEMICOLON
181 /// / StaticAssert
182 /// DeclInit <- Declarator (EQUAL Initializer)? (COMMA Declarator (EQUAL Initializer)?)*
183 fn declaration(parser: *Parser) !?*Node {
184 return parser.declarationExtra(true);
185 }
186
187 fn declarationExtra(parser: *Parser, local: bool) !?*Node {
188 if (try parser.staticAssert()) |decl| return decl;
189 const begin = parser.it.index + 1;
190 var ds = Node.DeclSpec{};
191 const got_ds = try parser.declSpec(&ds);
192 if (local and !got_ds) {
193 // not a declaration
194 return null;
195 }
196 switch (ds.storage_class) {
197 .Auto, .Register => |tok| return parser.err(.{
198 .InvalidStorageClass = .{ .token = tok },
199 }),
200 .Typedef => {
201 const node = try parser.arena.create(Node.Typedef);
202 node.* = .{
203 .decl_spec = ds,
204 .declarators = Node.Typedef.DeclaratorList.init(parser.arena),
205 .semicolon = undefined,
206 };
207 while (true) {
208 const dr = @fieldParentPtr(Node.Declarator, "base", (try parser.declarator(.Must)) orelse return parser.err(.{
209 .ExpectedDeclarator = .{ .token = parser.it.index },
210 }));
211 try parser.declareSymbol(ds.type_spec, dr);
212 try node.declarators.push(&dr.base);
213 if (parser.eatToken(.Comma)) |_| {} else break;
214 }
215 return &node.base;
216 },
217 else => {},
218 }
219 var first_dr = try parser.declarator(.Must);
220 if (first_dr != null and declaratorIsFunction(first_dr.?)) {
221 // TODO typedeffed fn proto-only
222 const dr = @fieldParentPtr(Node.Declarator, "base", first_dr.?);
223 try parser.declareSymbol(ds.type_spec, dr);
224 var old_decls = Node.FnDecl.OldDeclList.init(parser.arena);
225 const body = if (parser.eatToken(.Semicolon)) |_|
226 null
227 else blk: {
228 if (local) {
229 // TODO nested function warning
230 }
231 // TODO first_dr.is_old
232 // while (true) {
233 // var old_ds = Node.DeclSpec{};
234 // if (!(try parser.declSpec(&old_ds))) {
235 // // not old decl
236 // break;
237 // }
238 // var old_dr = (try parser.declarator(.Must));
239 // // if (old_dr == null)
240 // // try parser.err(.{
241 // // .NoParamName = .{ .token = parser.it.index },
242 // // });
243 // // try old_decls.push(decl);
244 // }
245 const body_node = (try parser.compoundStmt()) orelse return parser.err(.{
246 .ExpectedFnBody = .{ .token = parser.it.index },
247 });
248 break :blk @fieldParentPtr(Node.CompoundStmt, "base", body_node);
249 };
250
251 const node = try parser.arena.create(Node.FnDecl);
252 node.* = .{
253 .decl_spec = ds,
254 .declarator = dr,
255 .old_decls = old_decls,
256 .body = body,
257 };
258 return &node.base;
259 } else {
260 switch (ds.fn_spec) {
261 .Inline, .Noreturn => |tok| return parser.err(.{
262 .FnSpecOnNonFn = .{ .token = tok },
263 }),
264 else => {},
265 }
266 // TODO threadlocal without static or extern on local variable
267 const node = try parser.arena.create(Node.VarDecl);
268 node.* = .{
269 .decl_spec = ds,
270 .initializers = Node.VarDecl.Initializers.init(parser.arena),
271 .semicolon = undefined,
272 };
273 if (first_dr == null) {
274 node.semicolon = try parser.expectToken(.Semicolon);
275 const ok = switch (ds.type_spec.spec) {
276 .Enum => |e| e.name != null,
277 .Record => |r| r.name != null,
278 else => false,
279 };
280 const q = ds.type_spec.qual;
281 if (!ok)
282 try parser.warn(.{
283 .NothingDeclared = .{ .token = begin },
284 })
285 else if (q.@"const" orelse q.atomic orelse q.@"volatile" orelse q.restrict) |tok|
286 try parser.warn(.{
287 .QualifierIgnored = .{ .token = tok },
288 });
289 return &node.base;
290 }
291 var dr = @fieldParentPtr(Node.Declarator, "base", first_dr.?);
292 while (true) {
293 try parser.declareSymbol(ds.type_spec, dr);
294 if (parser.eatToken(.Equal)) |tok| {
295 try node.initializers.push((try parser.initializer(dr)) orelse return parser.err(.{
296 .ExpectedInitializer = .{ .token = parser.it.index },
297 }));
298 } else
299 try node.initializers.push(&dr.base);
300 if (parser.eatToken(.Comma) != null) break;
301 dr = @fieldParentPtr(Node.Declarator, "base", (try parser.declarator(.Must)) orelse return parser.err(.{
302 .ExpectedDeclarator = .{ .token = parser.it.index },
303 }));
304 }
305 node.semicolon = try parser.expectToken(.Semicolon);
306 return &node.base;
307 }
308 }
309
310 fn declaratorIsFunction(node: *Node) bool {
311 if (node.id != .Declarator) return false;
312 assert(node.id == .Declarator);
313 const dr = @fieldParentPtr(Node.Declarator, "base", node);
314 if (dr.suffix != .Fn) return false;
315 switch (dr.prefix) {
316 .None, .Identifer => return true,
317 .Complex => |inner| {
318 var inner_node = inner.inner;
319 while (true) {
320 if (inner_node.id != .Declarator) return false;
321 assert(inner_node.id == .Declarator);
322 const inner_dr = @fieldParentPtr(Node.Declarator, "base", inner_node);
323 if (inner_dr.pointer != null) return false;
324 switch (inner_dr.prefix) {
325 .None, .Identifer => return true,
326 .Complex => |c| inner_node = c.inner,
327 }
328 }
329 },
330 }
331 }
332
333 /// StaticAssert <- Keyword_static_assert LPAREN ConstExpr COMMA STRINGLITERAL RPAREN SEMICOLON
334 fn staticAssert(parser: *Parser) !?*Node {
335 const tok = parser.eatToken(.Keyword_static_assert) orelse return null;
336 _ = try parser.expectToken(.LParen);
337 const const_expr = (try parser.constExpr()) orelse parser.err(.{
338 .ExpectedExpr = .{ .token = parser.it.index },
339 });
340 _ = try parser.expectToken(.Comma);
341 const str = try parser.expectToken(.StringLiteral);
342 _ = try parser.expectToken(.RParen);
343 const node = try parser.arena.create(Node.StaticAssert);
344 node.* = .{
345 .assert = tok,
346 .expr = const_expr,
347 .semicolon = try parser.expectToken(.Semicolon),
348 };
349 return &node.base;
350 }
351
352 /// DeclSpec <- (StorageClassSpec / TypeSpec / FnSpec / AlignSpec)*
353 /// returns true if any tokens were consumed
354 fn declSpec(parser: *Parser, ds: *Node.DeclSpec) !bool {
355 var got = false;
356 while ((try parser.storageClassSpec(ds)) or (try parser.typeSpec(&ds.type_spec)) or (try parser.fnSpec(ds)) or (try parser.alignSpec(ds))) {
357 got = true;
358 }
359 return got;
360 }
361
362 /// StorageClassSpec
363 /// <- Keyword_typedef / Keyword_extern / Keyword_static / Keyword_thread_local / Keyword_auto / Keyword_register
364 fn storageClassSpec(parser: *Parser, ds: *Node.DeclSpec) !bool {
365 blk: {
366 if (parser.eatToken(.Keyword_typedef)) |tok| {
367 if (ds.storage_class != .None or ds.thread_local != null)
368 break :blk;
369 ds.storage_class = .{ .Typedef = tok };
370 } else if (parser.eatToken(.Keyword_extern)) |tok| {
371 if (ds.storage_class != .None)
372 break :blk;
373 ds.storage_class = .{ .Extern = tok };
374 } else if (parser.eatToken(.Keyword_static)) |tok| {
375 if (ds.storage_class != .None)
376 break :blk;
377 ds.storage_class = .{ .Static = tok };
378 } else if (parser.eatToken(.Keyword_thread_local)) |tok| {
379 switch (ds.storage_class) {
380 .None, .Extern, .Static => {},
381 else => break :blk,
382 }
383 ds.thread_local = tok;
384 } else if (parser.eatToken(.Keyword_auto)) |tok| {
385 if (ds.storage_class != .None or ds.thread_local != null)
386 break :blk;
387 ds.storage_class = .{ .Auto = tok };
388 } else if (parser.eatToken(.Keyword_register)) |tok| {
389 if (ds.storage_class != .None or ds.thread_local != null)
390 break :blk;
391 ds.storage_class = .{ .Register = tok };
392 } else return false;
393 return true;
394 }
395 try parser.warn(.{
396 .DuplicateSpecifier = .{ .token = parser.it.index },
397 });
398 return true;
399 }
400
401 /// TypeSpec
402 /// <- Keyword_void / Keyword_char / Keyword_short / Keyword_int / Keyword_long / Keyword_float / Keyword_double
403 /// / Keyword_signed / Keyword_unsigned / Keyword_bool / Keyword_complex / Keyword_imaginary /
404 /// / Keyword_atomic LPAREN TypeName RPAREN
405 /// / EnumSpec
406 /// / RecordSpec
407 /// / IDENTIFIER // typedef name
408 /// / TypeQual
409 fn typeSpec(parser: *Parser, type_spec: *Node.TypeSpec) !bool {
410 blk: {
411 if (parser.eatToken(.Keyword_void)) |tok| {
412 if (type_spec.spec != .None)
413 break :blk;
414 type_spec.spec = .{ .Void = tok };
415 } else if (parser.eatToken(.Keyword_char)) |tok| {
416 switch (type_spec.spec) {
417 .None => {
418 type_spec.spec = .{
419 .Char = .{
420 .char = tok,
421 },
422 };
423 },
424 .Int => |int| {
425 if (int.int != null)
426 break :blk;
427 type_spec.spec = .{
428 .Char = .{
429 .char = tok,
430 .sign = int.sign,
431 },
432 };
433 },
434 else => break :blk,
435 }
436 } else if (parser.eatToken(.Keyword_short)) |tok| {
437 switch (type_spec.spec) {
438 .None => {
439 type_spec.spec = .{
440 .Short = .{
441 .short = tok,
442 },
443 };
444 },
445 .Int => |int| {
446 if (int.int != null)
447 break :blk;
448 type_spec.spec = .{
449 .Short = .{
450 .short = tok,
451 .sign = int.sign,
452 },
453 };
454 },
455 else => break :blk,
456 }
457 } else if (parser.eatToken(.Keyword_long)) |tok| {
458 switch (type_spec.spec) {
459 .None => {
460 type_spec.spec = .{
461 .Long = .{
462 .long = tok,
463 },
464 };
465 },
466 .Int => |int| {
467 type_spec.spec = .{
468 .Long = .{
469 .long = tok,
470 .sign = int.sign,
471 .int = int.int,
472 },
473 };
474 },
475 .Long => |*long| {
476 if (long.longlong != null)
477 break :blk;
478 long.longlong = tok;
479 },
480 .Double => |*double| {
481 if (double.long != null)
482 break :blk;
483 double.long = tok;
484 },
485 else => break :blk,
486 }
487 } else if (parser.eatToken(.Keyword_int)) |tok| {
488 switch (type_spec.spec) {
489 .None => {
490 type_spec.spec = .{
491 .Int = .{
492 .int = tok,
493 },
494 };
495 },
496 .Short => |*short| {
497 if (short.int != null)
498 break :blk;
499 short.int = tok;
500 },
501 .Int => |*int| {
502 if (int.int != null)
503 break :blk;
504 int.int = tok;
505 },
506 .Long => |*long| {
507 if (long.int != null)
508 break :blk;
509 long.int = tok;
510 },
511 else => break :blk,
512 }
513 } else if (parser.eatToken(.Keyword_signed) orelse parser.eatToken(.Keyword_unsigned)) |tok| {
514 switch (type_spec.spec) {
515 .None => {
516 type_spec.spec = .{
517 .Int = .{
518 .sign = tok,
519 },
520 };
521 },
522 .Char => |*char| {
523 if (char.sign != null)
524 break :blk;
525 char.sign = tok;
526 },
527 .Short => |*short| {
528 if (short.sign != null)
529 break :blk;
530 short.sign = tok;
531 },
532 .Int => |*int| {
533 if (int.sign != null)
534 break :blk;
535 int.sign = tok;
536 },
537 .Long => |*long| {
538 if (long.sign != null)
539 break :blk;
540 long.sign = tok;
541 },
542 else => break :blk,
543 }
544 } else if (parser.eatToken(.Keyword_float)) |tok| {
545 if (type_spec.spec != .None)
546 break :blk;
547 type_spec.spec = .{
548 .Float = .{
549 .float = tok,
550 },
551 };
552 } else if (parser.eatToken(.Keyword_double)) |tok| {
553 if (type_spec.spec != .None)
554 break :blk;
555 type_spec.spec = .{
556 .Double = .{
557 .double = tok,
558 },
559 };
560 } else if (parser.eatToken(.Keyword_complex)) |tok| {
561 switch (type_spec.spec) {
562 .None => {
563 type_spec.spec = .{
564 .Double = .{
565 .complex = tok,
566 .double = null,
567 },
568 };
569 },
570 .Float => |*float| {
571 if (float.complex != null)
572 break :blk;
573 float.complex = tok;
574 },
575 .Double => |*double| {
576 if (double.complex != null)
577 break :blk;
578 double.complex = tok;
579 },
580 else => break :blk,
581 }
582 } else if (parser.eatToken(.Keyword_bool)) |tok| {
583 if (type_spec.spec != .None)
584 break :blk;
585 type_spec.spec = .{ .Bool = tok };
586 } else if (parser.eatToken(.Keyword_atomic)) |tok| {
587 // might be _Atomic qualifier
588 if (parser.eatToken(.LParen)) |_| {
589 if (type_spec.spec != .None)
590 break :blk;
591 const name = (try parser.typeName()) orelse return parser.err(.{
592 .ExpectedTypeName = .{ .token = parser.it.index },
593 });
594 type_spec.spec.Atomic = .{
595 .atomic = tok,
596 .typename = name,
597 .rparen = try parser.expectToken(.RParen),
598 };
599 } else {
600 parser.putBackToken(tok);
601 }
602 } else if (parser.eatToken(.Keyword_enum)) |tok| {
603 if (type_spec.spec != .None)
604 break :blk;
605 type_spec.spec.Enum = try parser.enumSpec(tok);
606 } else if (parser.eatToken(.Keyword_union) orelse parser.eatToken(.Keyword_struct)) |tok| {
607 if (type_spec.spec != .None)
608 break :blk;
609 type_spec.spec.Record = try parser.recordSpec(tok);
610 } else if (parser.eatToken(.Identifier)) |tok| {
611 const ty = parser.getSymbol(tok) orelse {
612 parser.putBackToken(tok);
613 return false;
614 };
615 switch (ty.id) {
616 .Enum => |e| blk: {
617 if (e.name) |some|
618 if (!parser.tree.tokenEql(some, tok))
619 break :blk;
620 return parser.err(.{
621 .MustUseKwToRefer = .{ .kw = e.tok, .name = tok },
622 });
623 },
624 .Record => |r| blk: {
625 if (r.name) |some|
626 if (!parser.tree.tokenEql(some, tok))
627 break :blk;
628 return parser.err(.{
629 .MustUseKwToRefer = .{
630 .kw = r.tok,
631 .name = tok,
632 },
633 });
634 },
635 .Typedef => {
636 type_spec.spec = .{
637 .Typedef = .{
638 .sym = tok,
639 .sym_type = ty,
640 },
641 };
642 return true;
643 },
644 else => {},
645 }
646 parser.putBackToken(tok);
647 return false;
648 }
649 return parser.typeQual(&type_spec.qual);
650 }
651 return parser.err(.{
652 .InvalidTypeSpecifier = .{
653 .token = parser.it.index,
654 .type_spec = type_spec,
655 },
656 });
657 }
658
659 /// TypeQual <- Keyword_const / Keyword_restrict / Keyword_volatile / Keyword_atomic
660 fn typeQual(parser: *Parser, qual: *Node.TypeQual) !bool {
661 blk: {
662 if (parser.eatToken(.Keyword_const)) |tok| {
663 if (qual.@"const" != null)
664 break :blk;
665 qual.@"const" = tok;
666 } else if (parser.eatToken(.Keyword_restrict)) |tok| {
667 if (qual.atomic != null)
668 break :blk;
669 qual.atomic = tok;
670 } else if (parser.eatToken(.Keyword_volatile)) |tok| {
671 if (qual.@"volatile" != null)
672 break :blk;
673 qual.@"volatile" = tok;
674 } else if (parser.eatToken(.Keyword_atomic)) |tok| {
675 if (qual.atomic != null)
676 break :blk;
677 qual.atomic = tok;
678 } else return false;
679 return true;
680 }
681 try parser.warn(.{
682 .DuplicateQualifier = .{ .token = parser.it.index },
683 });
684 return true;
685 }
686
687 /// FnSpec <- Keyword_inline / Keyword_noreturn
688 fn fnSpec(parser: *Parser, ds: *Node.DeclSpec) !bool {
689 blk: {
690 if (parser.eatToken(.Keyword_inline)) |tok| {
691 if (ds.fn_spec != .None)
692 break :blk;
693 ds.fn_spec = .{ .Inline = tok };
694 } else if (parser.eatToken(.Keyword_noreturn)) |tok| {
695 if (ds.fn_spec != .None)
696 break :blk;
697 ds.fn_spec = .{ .Noreturn = tok };
698 } else return false;
699 return true;
700 }
701 try parser.warn(.{
702 .DuplicateSpecifier = .{ .token = parser.it.index },
703 });
704 return true;
705 }
706
707 /// AlignSpec <- Keyword_alignas LPAREN (TypeName / ConstExpr) RPAREN
708 fn alignSpec(parser: *Parser, ds: *Node.DeclSpec) !bool {
709 if (parser.eatToken(.Keyword_alignas)) |tok| {
710 _ = try parser.expectToken(.LParen);
711 const node = (try parser.typeName()) orelse (try parser.constExpr()) orelse parser.err(.{
712 .ExpectedExpr = .{ .token = parser.it.index },
713 });
714 if (ds.align_spec != null) {
715 try parser.warn(.{
716 .DuplicateSpecifier = .{ .token = parser.it.index },
717 });
718 }
719 ds.align_spec = .{
720 .alignas = tok,
721 .expr = node,
722 .rparen = try parser.expectToken(.RParen),
723 };
724 return true;
725 }
726 return false;
727 }
728
729 /// EnumSpec <- Keyword_enum IDENTIFIER? (LBRACE EnumField RBRACE)?
730 fn enumSpec(parser: *Parser, tok: TokenIndex) !*Node.EnumType {
731 const node = try parser.arena.create(Node.EnumType);
732 const name = parser.eatToken(.Identifier);
733 node.* = .{
734 .tok = tok,
735 .name = name,
736 .body = null,
737 };
738 const ty = try parser.arena.create(Type);
739 ty.* = .{
740 .id = .{
741 .Enum = node,
742 },
743 };
744 if (name) |some|
745 try parser.symbols.append(.{
746 .name = parser.tree.tokenSlice(some),
747 .ty = ty,
748 });
749 if (parser.eatToken(.LBrace)) |lbrace| {
750 var fields = Node.EnumType.FieldList.init(parser.arena);
751 try fields.push((try parser.enumField()) orelse return parser.err(.{
752 .ExpectedEnumField = .{ .token = parser.it.index },
753 }));
754 while (parser.eatToken(.Comma)) |_| {
755 try fields.push((try parser.enumField()) orelse break);
756 }
757 node.body = .{
758 .lbrace = lbrace,
759 .fields = fields,
760 .rbrace = try parser.expectToken(.RBrace),
761 };
762 }
763 return node;
764 }
765
766 /// EnumField <- IDENTIFIER (EQUAL ConstExpr)? (COMMA EnumField) COMMA?
767 fn enumField(parser: *Parser) !?*Node {
768 const name = parser.eatToken(.Identifier) orelse return null;
769 const node = try parser.arena.create(Node.EnumField);
770 node.* = .{
771 .name = name,
772 .value = null,
773 };
774 if (parser.eatToken(.Equal)) |eq| {
775 node.value = (try parser.constExpr()) orelse parser.err(.{
776 .ExpectedExpr = .{ .token = parser.it.index },
777 });
778 }
779 return &node.base;
780 }
781
782 /// RecordSpec <- (Keyword_struct / Keyword_union) IDENTIFIER? (LBRACE RecordField+ RBRACE)?
783 fn recordSpec(parser: *Parser, tok: TokenIndex) !*Node.RecordType {
784 const node = try parser.arena.create(Node.RecordType);
785 const name = parser.eatToken(.Identifier);
786 const is_struct = parser.tree.tokenSlice(tok)[0] == 's';
787 node.* = .{
788 .tok = tok,
789 .kind = if (is_struct) .Struct else .Union,
790 .name = name,
791 .body = null,
792 };
793 const ty = try parser.arena.create(Type);
794 ty.* = .{
795 .id = .{
796 .Record = node,
797 },
798 };
799 if (name) |some|
800 try parser.symbols.append(.{
801 .name = parser.tree.tokenSlice(some),
802 .ty = ty,
803 });
804 if (parser.eatToken(.LBrace)) |lbrace| {
805 try parser.pushScope(.Block);
806 defer parser.popScope();
807 var fields = Node.RecordType.FieldList.init(parser.arena);
808 while (true) {
809 if (parser.eatToken(.RBrace)) |rbrace| {
810 node.body = .{
811 .lbrace = lbrace,
812 .fields = fields,
813 .rbrace = rbrace,
814 };
815 break;
816 }
817 try fields.push(try parser.recordField());
818 }
819 }
820 return node;
821 }
822
823 /// RecordField
824 /// <- TypeSpec* (RecordDeclarator (COMMA RecordDeclarator))? SEMICOLON
825 /// \ StaticAssert
826 fn recordField(parser: *Parser) Error!*Node {
827 if (try parser.staticAssert()) |decl| return decl;
828 var got = false;
829 var type_spec = Node.TypeSpec{};
830 while (try parser.typeSpec(&type_spec)) got = true;
831 if (!got)
832 return parser.err(.{
833 .ExpectedType = .{ .token = parser.it.index },
834 });
835 const node = try parser.arena.create(Node.RecordField);
836 node.* = .{
837 .type_spec = type_spec,
838 .declarators = Node.RecordField.DeclaratorList.init(parser.arena),
839 .semicolon = undefined,
840 };
841 while (true) {
842 const rdr = try parser.recordDeclarator();
843 try parser.declareSymbol(type_spec, rdr.declarator);
844 try node.declarators.push(&rdr.base);
845 if (parser.eatToken(.Comma)) |_| {} else break;
846 }
847
848 node.semicolon = try parser.expectToken(.Semicolon);
849 return &node.base;
850 }
851
852 /// TypeName <- TypeSpec* AbstractDeclarator?
853 fn typeName(parser: *Parser) Error!?*Node {
854 @panic("TODO");
855 }
856
857 /// RecordDeclarator <- Declarator? (COLON ConstExpr)?
858 fn recordDeclarator(parser: *Parser) Error!*Node.RecordDeclarator {
859 @panic("TODO");
860 }
861
862 /// Pointer <- ASTERISK TypeQual* Pointer?
863 fn pointer(parser: *Parser) Error!?*Node.Pointer {
864 const asterisk = parser.eatToken(.Asterisk) orelse return null;
865 const node = try parser.arena.create(Node.Pointer);
866 node.* = .{
867 .asterisk = asterisk,
868 .qual = .{},
869 .pointer = null,
870 };
871 while (try parser.typeQual(&node.qual)) {}
872 node.pointer = try parser.pointer();
873 return node;
874 }
875
876 const Named = enum {
877 Must,
878 Allowed,
879 Forbidden,
880 };
881
882 /// Declarator <- Pointer? DeclaratorSuffix
883 /// DeclaratorPrefix
884 /// <- IDENTIFIER // if named != .Forbidden
885 /// / LPAREN Declarator RPAREN
886 /// / (none) // if named != .Must
887 /// DeclaratorSuffix
888 /// <- DeclaratorPrefix (LBRACKET ArrayDeclarator? RBRACKET)*
889 /// / DeclaratorPrefix LPAREN (ParamDecl (COMMA ParamDecl)* (COMMA ELLIPSIS)?)? RPAREN
890 fn declarator(parser: *Parser, named: Named) Error!?*Node {
891 const ptr = try parser.pointer();
892 var node: *Node.Declarator = undefined;
893 var inner_fn = false;
894
895 // TODO sizof(int (int))
896 // prefix
897 if (parser.eatToken(.LParen)) |lparen| {
898 const inner = (try parser.declarator(named)) orelse return parser.err(.{
899 .ExpectedDeclarator = .{ .token = lparen + 1 },
900 });
901 inner_fn = declaratorIsFunction(inner);
902 node = try parser.arena.create(Node.Declarator);
903 node.* = .{
904 .pointer = ptr,
905 .prefix = .{
906 .Complex = .{
907 .lparen = lparen,
908 .inner = inner,
909 .rparen = try parser.expectToken(.RParen),
910 },
911 },
912 .suffix = .None,
913 };
914 } else if (named != .Forbidden) {
915 if (parser.eatToken(.Identifier)) |tok| {
916 node = try parser.arena.create(Node.Declarator);
917 node.* = .{
918 .pointer = ptr,
919 .prefix = .{ .Identifer = tok },
920 .suffix = .None,
921 };
922 } else if (named == .Must) {
923 return parser.err(.{
924 .ExpectedToken = .{ .token = parser.it.index, .expected_id = .Identifier },
925 });
926 } else {
927 if (ptr) |some|
928 return &some.base;
929 return null;
930 }
931 } else {
932 node = try parser.arena.create(Node.Declarator);
933 node.* = .{
934 .pointer = ptr,
935 .prefix = .None,
936 .suffix = .None,
937 };
938 }
939 // suffix
940 if (parser.eatToken(.LParen)) |lparen| {
941 if (inner_fn)
942 return parser.err(.{
943 .InvalidDeclarator = .{ .token = lparen },
944 });
945 node.suffix = .{
946 .Fn = .{
947 .lparen = lparen,
948 .params = Node.Declarator.Params.init(parser.arena),
949 .rparen = undefined,
950 },
951 };
952 try parser.paramDecl(node);
953 node.suffix.Fn.rparen = try parser.expectToken(.RParen);
954 } else if (parser.eatToken(.LBracket)) |tok| {
955 if (inner_fn)
956 return parser.err(.{
957 .InvalidDeclarator = .{ .token = tok },
958 });
959 node.suffix = .{ .Array = Node.Declarator.Arrays.init(parser.arena) };
960 var lbrace = tok;
961 while (true) {
962 try node.suffix.Array.push(try parser.arrayDeclarator(lbrace));
963 if (parser.eatToken(.LBracket)) |t| lbrace = t else break;
964 }
965 }
966 if (parser.eatToken(.LParen) orelse parser.eatToken(.LBracket)) |tok|
967 return parser.err(.{
968 .InvalidDeclarator = .{ .token = tok },
969 });
970 return &node.base;
971 }
972
973 /// ArrayDeclarator
974 /// <- ASTERISK
975 /// / Keyword_static TypeQual* AssignmentExpr
976 /// / TypeQual+ (ASTERISK / Keyword_static AssignmentExpr)
977 /// / TypeQual+ AssignmentExpr?
978 /// / AssignmentExpr
979 fn arrayDeclarator(parser: *Parser, lbracket: TokenIndex) !*Node.Array {
980 const arr = try parser.arena.create(Node.Array);
981 arr.* = .{
982 .lbracket = lbracket,
983 .inner = .Inferred,
984 .rbracket = undefined,
985 };
986 if (parser.eatToken(.Asterisk)) |tok| {
987 arr.inner = .{ .Unspecified = tok };
988 } else {
989 // TODO
990 }
991 arr.rbracket = try parser.expectToken(.RBracket);
992 return arr;
993 }
994
995 /// Params <- ParamDecl (COMMA ParamDecl)* (COMMA ELLIPSIS)?
996 /// ParamDecl <- DeclSpec (Declarator / AbstractDeclarator)
997 fn paramDecl(parser: *Parser, dr: *Node.Declarator) !void {
998 var old_style = false;
999 while (true) {
1000 var ds = Node.DeclSpec{};
1001 if (try parser.declSpec(&ds)) {
1002 //TODO
1003 // TODO try parser.declareSymbol(ds.type_spec, dr);
1004 } else if (parser.eatToken(.Identifier)) |tok| {
1005 old_style = true;
1006 } else if (parser.eatToken(.Ellipsis)) |tok| {
1007 // TODO
1008 }
1009 }
1010 }
1011
1012 /// Expr <- AssignmentExpr (COMMA Expr)*
1013 fn expr(parser: *Parser) Error!?*Expr {
1014 @panic("TODO");
1015 }
1016
1017 /// AssignmentExpr
1018 /// <- ConditionalExpr // TODO recursive?
1019 /// / UnaryExpr (EQUAL / ASTERISKEQUAL / SLASHEQUAL / PERCENTEQUAL / PLUSEQUAL / MINUSEQUA /
1020 /// / ANGLEBRACKETANGLEBRACKETLEFTEQUAL / ANGLEBRACKETANGLEBRACKETRIGHTEQUAL /
1021 /// / AMPERSANDEQUAL / CARETEQUAL / PIPEEQUAL) AssignmentExpr
1022 fn assignmentExpr(parser: *Parser) !?*Expr {
1023 @panic("TODO");
1024 }
1025
1026 /// ConstExpr <- ConditionalExpr
1027 fn constExpr(parser: *Parser) Error!?*Expr {
1028 const start = parser.it.index;
1029 const expression = try parser.conditionalExpr();
1030 if (expression != null and expression.?.value == .None)
1031 return parser.err(.{
1032 .ConsExpr = start,
1033 });
1034 return expression;
1035 }
1036
1037 /// ConditionalExpr <- LogicalOrExpr (QUESTIONMARK Expr COLON ConditionalExpr)?
1038 fn conditionalExpr(parser: *Parser) Error!?*Expr {
1039 @panic("TODO");
1040 }
1041
1042 /// LogicalOrExpr <- LogicalAndExpr (PIPEPIPE LogicalOrExpr)*
1043 fn logicalOrExpr(parser: *Parser) !*Node {
1044 const lhs = (try parser.logicalAndExpr()) orelse return null;
1045 }
1046
1047 /// LogicalAndExpr <- BinOrExpr (AMPERSANDAMPERSAND LogicalAndExpr)*
1048 fn logicalAndExpr(parser: *Parser) !*Node {
1049 @panic("TODO");
1050 }
1051
1052 /// BinOrExpr <- BinXorExpr (PIPE BinOrExpr)*
1053 fn binOrExpr(parser: *Parser) !*Node {
1054 @panic("TODO");
1055 }
1056
1057 /// BinXorExpr <- BinAndExpr (CARET BinXorExpr)*
1058 fn binXorExpr(parser: *Parser) !*Node {
1059 @panic("TODO");
1060 }
1061
1062 /// BinAndExpr <- EqualityExpr (AMPERSAND BinAndExpr)*
1063 fn binAndExpr(parser: *Parser) !*Node {
1064 @panic("TODO");
1065 }
1066
1067 /// EqualityExpr <- ComparisionExpr ((EQUALEQUAL / BANGEQUAL) EqualityExpr)*
1068 fn equalityExpr(parser: *Parser) !*Node {
1069 @panic("TODO");
1070 }
1071
1072 /// ComparisionExpr <- ShiftExpr (ANGLEBRACKETLEFT / ANGLEBRACKETLEFTEQUAL /ANGLEBRACKETRIGHT / ANGLEBRACKETRIGHTEQUAL) ComparisionExpr)*
1073 fn comparisionExpr(parser: *Parser) !*Node {
1074 @panic("TODO");
1075 }
1076
1077 /// ShiftExpr <- AdditiveExpr (ANGLEBRACKETANGLEBRACKETLEFT / ANGLEBRACKETANGLEBRACKETRIGHT) ShiftExpr)*
1078 fn shiftExpr(parser: *Parser) !*Node {
1079 @panic("TODO");
1080 }
1081
1082 /// AdditiveExpr <- MultiplicativeExpr (PLUS / MINUS) AdditiveExpr)*
1083 fn additiveExpr(parser: *Parser) !*Node {
1084 @panic("TODO");
1085 }
1086
1087 /// MultiplicativeExpr <- UnaryExpr (ASTERISK / SLASH / PERCENT) MultiplicativeExpr)*
1088 fn multiplicativeExpr(parser: *Parser) !*Node {
1089 @panic("TODO");
1090 }
1091
1092 /// UnaryExpr
1093 /// <- LPAREN TypeName RPAREN UnaryExpr
1094 /// / Keyword_sizeof LAPERN TypeName RPAREN
1095 /// / Keyword_sizeof UnaryExpr
1096 /// / Keyword_alignof LAPERN TypeName RPAREN
1097 /// / (AMPERSAND / ASTERISK / PLUS / PLUSPLUS / MINUS / MINUSMINUS / TILDE / BANG) UnaryExpr
1098 /// / PrimaryExpr PostFixExpr*
1099 fn unaryExpr(parser: *Parser) !*Node {
1100 @panic("TODO");
1101 }
1102
1103 /// PrimaryExpr
1104 /// <- IDENTIFIER
1105 /// / INTEGERLITERAL / FLOATLITERAL / STRINGLITERAL / CHARLITERAL
1106 /// / LPAREN Expr RPAREN
1107 /// / Keyword_generic LPAREN AssignmentExpr (COMMA Generic)+ RPAREN
1108 fn primaryExpr(parser: *Parser) !*Node {
1109 @panic("TODO");
1110 }
1111
1112 /// Generic
1113 /// <- TypeName COLON AssignmentExpr
1114 /// / Keyword_default COLON AssignmentExpr
1115 fn generic(parser: *Parser) !*Node {
1116 @panic("TODO");
1117 }
1118
1119 /// PostFixExpr
1120 /// <- LPAREN TypeName RPAREN LBRACE Initializers RBRACE
1121 /// / LBRACKET Expr RBRACKET
1122 /// / LPAREN (AssignmentExpr (COMMA AssignmentExpr)*)? RPAREN
1123 /// / (PERIOD / ARROW) IDENTIFIER
1124 /// / (PLUSPLUS / MINUSMINUS)
1125 fn postFixExpr(parser: *Parser) !*Node {
1126 @panic("TODO");
1127 }
1128
1129 /// Initializers <- ((Designator+ EQUAL)? Initializer COMMA)* (Designator+ EQUAL)? Initializer COMMA?
1130 fn initializers(parser: *Parser) !*Node {
1131 @panic("TODO");
1132 }
1133
1134 /// Initializer
1135 /// <- LBRACE Initializers RBRACE
1136 /// / AssignmentExpr
1137 fn initializer(parser: *Parser, dr: *Node.Declarator) Error!?*Node {
1138 @panic("TODO");
1139 }
1140
1141 /// Designator
1142 /// <- LBRACKET ConstExpr RBRACKET
1143 /// / PERIOD IDENTIFIER
1144 fn designator(parser: *Parser) !*Node {
1145 @panic("TODO");
1146 }
1147
1148 /// CompoundStmt <- LBRACE (Declaration / Stmt)* RBRACE
1149 fn compoundStmt(parser: *Parser) Error!?*Node {
1150 const lbrace = parser.eatToken(.LBrace) orelse return null;
1151 try parser.pushScope(.Block);
1152 defer parser.popScope();
1153 const body_node = try parser.arena.create(Node.CompoundStmt);
1154 body_node.* = .{
1155 .lbrace = lbrace,
1156 .statements = Node.CompoundStmt.StmtList.init(parser.arena),
1157 .rbrace = undefined,
1158 };
1159 while (true) {
1160 if (parser.eatToken(.RBRACE)) |rbrace| {
1161 body_node.rbrace = rbrace;
1162 break;
1163 }
1164 try body_node.statements.push((try parser.declaration()) orelse (try parser.stmt()));
1165 }
1166 return &body_node.base;
1167 }
1168
1169 /// Stmt
1170 /// <- CompoundStmt
1171 /// / Keyword_if LPAREN Expr RPAREN Stmt (Keyword_ELSE Stmt)?
1172 /// / Keyword_switch LPAREN Expr RPAREN Stmt
1173 /// / Keyword_while LPAREN Expr RPAREN Stmt
1174 /// / Keyword_do statement Keyword_while LPAREN Expr RPAREN SEMICOLON
1175 /// / Keyword_for LPAREN (Declaration / ExprStmt) ExprStmt Expr? RPAREN Stmt
1176 /// / Keyword_default COLON Stmt
1177 /// / Keyword_case ConstExpr COLON Stmt
1178 /// / Keyword_goto IDENTIFIER SEMICOLON
1179 /// / Keyword_continue SEMICOLON
1180 /// / Keyword_break SEMICOLON
1181 /// / Keyword_return Expr? SEMICOLON
1182 /// / IDENTIFIER COLON Stmt
1183 /// / ExprStmt
1184 fn stmt(parser: *Parser) Error!*Node {
1185 if (try parser.compoundStmt()) |node| return node;
1186 if (parser.eatToken(.Keyword_if)) |tok| {
1187 const node = try parser.arena.create(Node.IfStmt);
1188 _ = try parser.expectToken(.LParen);
1189 node.* = .{
1190 .@"if" = tok,
1191 .cond = (try parser.expr()) orelse return parser.err(.{
1192 .ExpectedExpr = .{ .token = parser.it.index },
1193 }),
1194 .body = undefined,
1195 .@"else" = null,
1196 };
1197 _ = try parser.expectToken(.RParen);
1198 node.body = try parser.stmt();
1199 if (parser.eatToken(.Keyword_else)) |else_tok| {
1200 node.@"else" = .{
1201 .tok = else_tok,
1202 .body = try parser.stmt(),
1203 };
1204 }
1205 return &node.base;
1206 }
1207 if (parser.eatToken(.Keyword_while)) |tok| {
1208 try parser.pushScope(.Loop);
1209 defer parser.popScope();
1210 _ = try parser.expectToken(.LParen);
1211 const cond = (try parser.expr()) orelse return parser.err(.{
1212 .ExpectedExpr = .{ .token = parser.it.index },
1213 });
1214 const rparen = try parser.expectToken(.RParen);
1215 const node = try parser.arena.create(Node.WhileStmt);
1216 node.* = .{
1217 .@"while" = tok,
1218 .cond = cond,
1219 .rparen = rparen,
1220 .body = try parser.stmt(),
1221 .semicolon = try parser.expectToken(.Semicolon),
1222 };
1223 return &node.base;
1224 }
1225 if (parser.eatToken(.Keyword_do)) |tok| {
1226 try parser.pushScope(.Loop);
1227 defer parser.popScope();
1228 const body = try parser.stmt();
1229 _ = try parser.expectToken(.LParen);
1230 const cond = (try parser.expr()) orelse return parser.err(.{
1231 .ExpectedExpr = .{ .token = parser.it.index },
1232 });
1233 _ = try parser.expectToken(.RParen);
1234 const node = try parser.arena.create(Node.DoStmt);
1235 node.* = .{
1236 .do = tok,
1237 .body = body,
1238 .cond = cond,
1239 .@"while" = @"while",
1240 .semicolon = try parser.expectToken(.Semicolon),
1241 };
1242 return &node.base;
1243 }
1244 if (parser.eatToken(.Keyword_for)) |tok| {
1245 try parser.pushScope(.Loop);
1246 defer parser.popScope();
1247 _ = try parser.expectToken(.LParen);
1248 const init = if (try parser.declaration()) |decl| blk: {
1249 // TODO disallow storage class other than auto and register
1250 break :blk decl;
1251 } else try parser.exprStmt();
1252 const cond = try parser.expr();
1253 const semicolon = try parser.expectToken(.Semicolon);
1254 const incr = try parser.expr();
1255 const rparen = try parser.expectToken(.RParen);
1256 const node = try parser.arena.create(Node.ForStmt);
1257 node.* = .{
1258 .@"for" = tok,
1259 .init = init,
1260 .cond = cond,
1261 .semicolon = semicolon,
1262 .incr = incr,
1263 .rparen = rparen,
1264 .body = try parser.stmt(),
1265 };
1266 return &node.base;
1267 }
1268 if (parser.eatToken(.Keyword_switch)) |tok| {
1269 try parser.pushScope(.Switch);
1270 defer parser.popScope();
1271 _ = try parser.expectToken(.LParen);
1272 const switch_expr = try parser.exprStmt();
1273 const rparen = try parser.expectToken(.RParen);
1274 const node = try parser.arena.create(Node.SwitchStmt);
1275 node.* = .{
1276 .@"switch" = tok,
1277 .expr = switch_expr,
1278 .rparen = rparen,
1279 .body = try parser.stmt(),
1280 };
1281 return &node.base;
1282 }
1283 if (parser.eatToken(.Keyword_default)) |tok| {
1284 _ = try parser.expectToken(.Colon);
1285 const node = try parser.arena.create(Node.LabeledStmt);
1286 node.* = .{
1287 .kind = .{ .Default = tok },
1288 .stmt = try parser.stmt(),
1289 };
1290 return &node.base;
1291 }
1292 if (parser.eatToken(.Keyword_case)) |tok| {
1293 _ = try parser.expectToken(.Colon);
1294 const node = try parser.arena.create(Node.LabeledStmt);
1295 node.* = .{
1296 .kind = .{ .Case = tok },
1297 .stmt = try parser.stmt(),
1298 };
1299 return &node.base;
1300 }
1301 if (parser.eatToken(.Keyword_goto)) |tok| {
1302 const node = try parser.arena.create(Node.JumpStmt);
1303 node.* = .{
1304 .ltoken = tok,
1305 .kind = .{ .Goto = tok },
1306 .semicolon = try parser.expectToken(.Semicolon),
1307 };
1308 return &node.base;
1309 }
1310 if (parser.eatToken(.Keyword_continue)) |tok| {
1311 const node = try parser.arena.create(Node.JumpStmt);
1312 node.* = .{
1313 .ltoken = tok,
1314 .kind = .Continue,
1315 .semicolon = try parser.expectToken(.Semicolon),
1316 };
1317 return &node.base;
1318 }
1319 if (parser.eatToken(.Keyword_break)) |tok| {
1320 const node = try parser.arena.create(Node.JumpStmt);
1321 node.* = .{
1322 .ltoken = tok,
1323 .kind = .Break,
1324 .semicolon = try parser.expectToken(.Semicolon),
1325 };
1326 return &node.base;
1327 }
1328 if (parser.eatToken(.Keyword_return)) |tok| {
1329 const node = try parser.arena.create(Node.JumpStmt);
1330 node.* = .{
1331 .ltoken = tok,
1332 .kind = .{ .Return = try parser.expr() },
1333 .semicolon = try parser.expectToken(.Semicolon),
1334 };
1335 return &node.base;
1336 }
1337 if (parser.eatToken(.Identifier)) |tok| {
1338 if (parser.eatToken(.Colon)) |_| {
1339 const node = try parser.arena.create(Node.LabeledStmt);
1340 node.* = .{
1341 .kind = .{ .Label = tok },
1342 .stmt = try parser.stmt(),
1343 };
1344 return &node.base;
1345 }
1346 parser.putBackToken(tok);
1347 }
1348 return parser.exprStmt();
1349 }
1350
1351 /// ExprStmt <- Expr? SEMICOLON
1352 fn exprStmt(parser: *Parser) !*Node {
1353 const node = try parser.arena.create(Node.ExprStmt);
1354 node.* = .{
1355 .expr = try parser.expr(),
1356 .semicolon = try parser.expectToken(.Semicolon),
1357 };
1358 return &node.base;
1359 }
1360
1361 fn eatToken(parser: *Parser, id: @TagType(Token.Id)) ?TokenIndex {
1362 while (true) {
1363 switch ((parser.it.next() orelse return null).id) {
1364 .LineComment, .MultiLineComment, .Nl => continue,
1365 else => |next_id| if (next_id == id) {
1366 return parser.it.index;
1367 } else {
1368 _ = parser.it.prev();
1369 return null;
1370 },
1371 }
1372 }
1373 }
1374
1375 fn expectToken(parser: *Parser, id: @TagType(Token.Id)) Error!TokenIndex {
1376 while (true) {
1377 switch ((parser.it.next() orelse return error.ParseError).id) {
1378 .LineComment, .MultiLineComment, .Nl => continue,
1379 else => |next_id| if (next_id != id) {
1380 return parser.err(.{
1381 .ExpectedToken = .{ .token = parser.it.index, .expected_id = id },
1382 });
1383 } else {
1384 return parser.it.index;
1385 },
1386 }
1387 }
1388 }
1389
1390 fn putBackToken(parser: *Parser, putting_back: TokenIndex) void {
1391 while (true) {
1392 const prev_tok = parser.it.next() orelse return;
1393 switch (prev_tok.id) {
1394 .LineComment, .MultiLineComment, .Nl => continue,
1395 else => {
1396 assert(parser.it.list.at(putting_back) == prev_tok);
1397 return;
1398 },
1399 }
1400 }
1401 }
1402
1403 fn err(parser: *Parser, msg: ast.Error) Error {
1404 try parser.tree.msgs.push(.{
1405 .kind = .Error,
1406 .inner = msg,
1407 });
1408 return error.ParseError;
1409 }
1410
1411 fn warn(parser: *Parser, msg: ast.Error) Error!void {
1412 const is_warning = switch (parser.options.warn_as_err) {
1413 .None => true,
1414 .Some => |list| for (list) |item| (if (item == msg) break false) else true,
1415 .All => false,
1416 };
1417 try parser.tree.msgs.push(.{
1418 .kind = if (is_warning) .Warning else .Error,
1419 .inner = msg,
1420 });
1421 if (!is_warning) return error.ParseError;
1422 }
1423
1424 fn note(parser: *Parser, msg: ast.Error) Error!void {
1425 try parser.tree.msgs.push(.{
1426 .kind = .Note,
1427 .inner = msg,
1428 });
1429 }
1430};
1431
lib/std/c/tokenizer.zig created+1583
...@@ -0,0 +1,1583 @@
1const std = @import("std");
2const mem = std.mem;
3
4pub const Source = struct {
5 buffer: []const u8,
6 file_name: []const u8,
7 tokens: TokenList,
8
9 pub const TokenList = std.SegmentedList(Token, 64);
10};
11
12pub const Token = struct {
13 id: Id,
14 start: usize,
15 end: usize,
16 source: *Source,
17
18 pub const Id = union(enum) {
19 Invalid,
20 Eof,
21 Nl,
22 Identifier,
23
24 /// special case for #include <...>
25 MacroString,
26 StringLiteral: StrKind,
27 CharLiteral: StrKind,
28 IntegerLiteral: NumSuffix,
29 FloatLiteral: NumSuffix,
30 Bang,
31 BangEqual,
32 Pipe,
33 PipePipe,
34 PipeEqual,
35 Equal,
36 EqualEqual,
37 LParen,
38 RParen,
39 LBrace,
40 RBrace,
41 LBracket,
42 RBracket,
43 Period,
44 Ellipsis,
45 Caret,
46 CaretEqual,
47 Plus,
48 PlusPlus,
49 PlusEqual,
50 Minus,
51 MinusMinus,
52 MinusEqual,
53 Asterisk,
54 AsteriskEqual,
55 Percent,
56 PercentEqual,
57 Arrow,
58 Colon,
59 Semicolon,
60 Slash,
61 SlashEqual,
62 Comma,
63 Ampersand,
64 AmpersandAmpersand,
65 AmpersandEqual,
66 QuestionMark,
67 AngleBracketLeft,
68 AngleBracketLeftEqual,
69 AngleBracketAngleBracketLeft,
70 AngleBracketAngleBracketLeftEqual,
71 AngleBracketRight,
72 AngleBracketRightEqual,
73 AngleBracketAngleBracketRight,
74 AngleBracketAngleBracketRightEqual,
75 Tilde,
76 LineComment,
77 MultiLineComment,
78 Hash,
79 HashHash,
80
81 Keyword_auto,
82 Keyword_break,
83 Keyword_case,
84 Keyword_char,
85 Keyword_const,
86 Keyword_continue,
87 Keyword_default,
88 Keyword_do,
89 Keyword_double,
90 Keyword_else,
91 Keyword_enum,
92 Keyword_extern,
93 Keyword_float,
94 Keyword_for,
95 Keyword_goto,
96 Keyword_if,
97 Keyword_int,
98 Keyword_long,
99 Keyword_register,
100 Keyword_return,
101 Keyword_short,
102 Keyword_signed,
103 Keyword_sizeof,
104 Keyword_static,
105 Keyword_struct,
106 Keyword_switch,
107 Keyword_typedef,
108 Keyword_union,
109 Keyword_unsigned,
110 Keyword_void,
111 Keyword_volatile,
112 Keyword_while,
113
114 // ISO C99
115 Keyword_bool,
116 Keyword_complex,
117 Keyword_imaginary,
118 Keyword_inline,
119 Keyword_restrict,
120
121 // ISO C11
122 Keyword_alignas,
123 Keyword_alignof,
124 Keyword_atomic,
125 Keyword_generic,
126 Keyword_noreturn,
127 Keyword_static_assert,
128 Keyword_thread_local,
129
130 // Preprocessor directives
131 Keyword_include,
132 Keyword_define,
133 Keyword_ifdef,
134 Keyword_ifndef,
135 Keyword_error,
136 Keyword_pragma,
137
138 pub fn symbol(id: @TagType(Id)) []const u8 {
139 return switch (id) {
140 .Invalid => "Invalid",
141 .Eof => "Eof",
142 .Nl => "NewLine",
143 .Identifier => "Identifier",
144 .MacroString => "MacroString",
145 .StringLiteral => "StringLiteral",
146 .CharLiteral => "CharLiteral",
147 .IntegerLiteral => "IntegerLiteral",
148 .FloatLiteral => "FloatLiteral",
149 .LineComment => "LineComment",
150 .MultiLineComment => "MultiLineComment",
151
152 .Bang => "!",
153 .BangEqual => "!=",
154 .Pipe => "|",
155 .PipePipe => "||",
156 .PipeEqual => "|=",
157 .Equal => "=",
158 .EqualEqual => "==",
159 .LParen => "(",
160 .RParen => ")",
161 .LBrace => "{",
162 .RBrace => "}",
163 .LBracket => "[",
164 .RBracket => "]",
165 .Period => ".",
166 .Ellipsis => "...",
167 .Caret => "^",
168 .CaretEqual => "^=",
169 .Plus => "+",
170 .PlusPlus => "++",
171 .PlusEqual => "+=",
172 .Minus => "-",
173 .MinusMinus => "--",
174 .MinusEqual => "-=",
175 .Asterisk => "*",
176 .AsteriskEqual => "*=",
177 .Percent => "%",
178 .PercentEqual => "%=",
179 .Arrow => "->",
180 .Colon => ":",
181 .Semicolon => ";",
182 .Slash => "/",
183 .SlashEqual => "/=",
184 .Comma => ",",
185 .Ampersand => "&",
186 .AmpersandAmpersand => "&&",
187 .AmpersandEqual => "&=",
188 .QuestionMark => "?",
189 .AngleBracketLeft => "<",
190 .AngleBracketLeftEqual => "<=",
191 .AngleBracketAngleBracketLeft => "<<",
192 .AngleBracketAngleBracketLeftEqual => "<<=",
193 .AngleBracketRight => ">",
194 .AngleBracketRightEqual => ">=",
195 .AngleBracketAngleBracketRight => ">>",
196 .AngleBracketAngleBracketRightEqual => ">>=",
197 .Tilde => "~",
198 .Hash => "#",
199 .HashHash => "##",
200 .Keyword_auto => "auto",
201 .Keyword_break => "break",
202 .Keyword_case => "case",
203 .Keyword_char => "char",
204 .Keyword_const => "const",
205 .Keyword_continue => "continue",
206 .Keyword_default => "default",
207 .Keyword_do => "do",
208 .Keyword_double => "double",
209 .Keyword_else => "else",
210 .Keyword_enum => "enum",
211 .Keyword_extern => "extern",
212 .Keyword_float => "float",
213 .Keyword_for => "for",
214 .Keyword_goto => "goto",
215 .Keyword_if => "if",
216 .Keyword_int => "int",
217 .Keyword_long => "long",
218 .Keyword_register => "register",
219 .Keyword_return => "return",
220 .Keyword_short => "short",
221 .Keyword_signed => "signed",
222 .Keyword_sizeof => "sizeof",
223 .Keyword_static => "static",
224 .Keyword_struct => "struct",
225 .Keyword_switch => "switch",
226 .Keyword_typedef => "typedef",
227 .Keyword_union => "union",
228 .Keyword_unsigned => "unsigned",
229 .Keyword_void => "void",
230 .Keyword_volatile => "volatile",
231 .Keyword_while => "while",
232 .Keyword_bool => "_Bool",
233 .Keyword_complex => "_Complex",
234 .Keyword_imaginary => "_Imaginary",
235 .Keyword_inline => "inline",
236 .Keyword_restrict => "restrict",
237 .Keyword_alignas => "_Alignas",
238 .Keyword_alignof => "_Alignof",
239 .Keyword_atomic => "_Atomic",
240 .Keyword_generic => "_Generic",
241 .Keyword_noreturn => "_Noreturn",
242 .Keyword_static_assert => "_Static_assert",
243 .Keyword_thread_local => "_Thread_local",
244 .Keyword_include => "include",
245 .Keyword_define => "define",
246 .Keyword_ifdef => "ifdef",
247 .Keyword_ifndef => "ifndef",
248 .Keyword_error => "error",
249 .Keyword_pragma => "pragma",
250 };
251 }
252 };
253
254 pub fn eql(a: Token, b: Token) bool {
255 // do we really need this cast here
256 if (@as(@TagType(Id), a.id) != b.id) return false;
257 return mem.eql(u8, a.slice(), b.slice());
258 }
259
260 pub fn slice(tok: Token) []const u8 {
261 return tok.source.buffer[tok.start..tok.end];
262 }
263
264 pub const Keyword = struct {
265 bytes: []const u8,
266 id: Id,
267 hash: u32,
268
269 fn init(bytes: []const u8, id: Id) Keyword {
270 @setEvalBranchQuota(2000);
271 return .{
272 .bytes = bytes,
273 .id = id,
274 .hash = std.hash_map.hashString(bytes),
275 };
276 }
277 };
278
279 // TODO extensions
280 pub const keywords = [_]Keyword{
281 Keyword.init("auto", .Keyword_auto),
282 Keyword.init("break", .Keyword_break),
283 Keyword.init("case", .Keyword_case),
284 Keyword.init("char", .Keyword_char),
285 Keyword.init("const", .Keyword_const),
286 Keyword.init("continue", .Keyword_continue),
287 Keyword.init("default", .Keyword_default),
288 Keyword.init("do", .Keyword_do),
289 Keyword.init("double", .Keyword_double),
290 Keyword.init("else", .Keyword_else),
291 Keyword.init("enum", .Keyword_enum),
292 Keyword.init("extern", .Keyword_extern),
293 Keyword.init("float", .Keyword_float),
294 Keyword.init("for", .Keyword_for),
295 Keyword.init("goto", .Keyword_goto),
296 Keyword.init("if", .Keyword_if),
297 Keyword.init("int", .Keyword_int),
298 Keyword.init("long", .Keyword_long),
299 Keyword.init("register", .Keyword_register),
300 Keyword.init("return", .Keyword_return),
301 Keyword.init("short", .Keyword_short),
302 Keyword.init("signed", .Keyword_signed),
303 Keyword.init("sizeof", .Keyword_sizeof),
304 Keyword.init("static", .Keyword_static),
305 Keyword.init("struct", .Keyword_struct),
306 Keyword.init("switch", .Keyword_switch),
307 Keyword.init("typedef", .Keyword_typedef),
308 Keyword.init("union", .Keyword_union),
309 Keyword.init("unsigned", .Keyword_unsigned),
310 Keyword.init("void", .Keyword_void),
311 Keyword.init("volatile", .Keyword_volatile),
312 Keyword.init("while", .Keyword_while),
313
314 // ISO C99
315 Keyword.init("_Bool", .Keyword_bool),
316 Keyword.init("_Complex", .Keyword_complex),
317 Keyword.init("_Imaginary", .Keyword_imaginary),
318 Keyword.init("inline", .Keyword_inline),
319 Keyword.init("restrict", .Keyword_restrict),
320
321 // ISO C11
322 Keyword.init("_Alignas", .Keyword_alignas),
323 Keyword.init("_Alignof", .Keyword_alignof),
324 Keyword.init("_Atomic", .Keyword_atomic),
325 Keyword.init("_Generic", .Keyword_generic),
326 Keyword.init("_Noreturn", .Keyword_noreturn),
327 Keyword.init("_Static_assert", .Keyword_static_assert),
328 Keyword.init("_Thread_local", .Keyword_thread_local),
329
330 // Preprocessor directives
331 Keyword.init("include", .Keyword_include),
332 Keyword.init("define", .Keyword_define),
333 Keyword.init("ifdef", .Keyword_ifdef),
334 Keyword.init("ifndef", .Keyword_ifndef),
335 Keyword.init("error", .Keyword_error),
336 Keyword.init("pragma", .Keyword_pragma),
337 };
338
339 // TODO perfect hash at comptime
340 // TODO do this in the preprocessor
341 pub fn getKeyword(bytes: []const u8, pp_directive: bool) ?Id {
342 var hash = std.hash_map.hashString(bytes);
343 for (keywords) |kw| {
344 if (kw.hash == hash and mem.eql(u8, kw.bytes, bytes)) {
345 switch (kw.id) {
346 .Keyword_include,
347 .Keyword_define,
348 .Keyword_ifdef,
349 .Keyword_ifndef,
350 .Keyword_error,
351 .Keyword_pragma,
352 => if (!pp_directive) return null,
353 else => {},
354 }
355 return kw.id;
356 }
357 }
358 return null;
359 }
360
361 pub const NumSuffix = enum {
362 None,
363 F,
364 L,
365 U,
366 LU,
367 LL,
368 LLU,
369 };
370
371 pub const StrKind = enum {
372 None,
373 Wide,
374 Utf8,
375 Utf16,
376 Utf32,
377 };
378};
379
380pub const Tokenizer = struct {
381 source: *Source,
382 index: usize = 0,
383 prev_tok_id: @TagType(Token.Id) = .Invalid,
384 pp_directive: bool = false,
385
386 pub fn next(self: *Tokenizer) Token {
387 const start_index = self.index;
388 var result = Token{
389 .id = .Eof,
390 .start = self.index,
391 .end = undefined,
392 .source = self.source,
393 };
394 var state: enum {
395 Start,
396 Cr,
397 BackSlash,
398 BackSlashCr,
399 u,
400 u8,
401 U,
402 L,
403 StringLiteral,
404 CharLiteralStart,
405 CharLiteral,
406 EscapeSequence,
407 CrEscape,
408 OctalEscape,
409 HexEscape,
410 UnicodeEscape,
411 Identifier,
412 Equal,
413 Bang,
414 Pipe,
415 Percent,
416 Asterisk,
417 Plus,
418
419 /// special case for #include <...>
420 MacroString,
421 AngleBracketLeft,
422 AngleBracketAngleBracketLeft,
423 AngleBracketRight,
424 AngleBracketAngleBracketRight,
425 Caret,
426 Period,
427 Period2,
428 Minus,
429 Slash,
430 Ampersand,
431 Hash,
432 LineComment,
433 MultiLineComment,
434 MultiLineCommentAsterisk,
435 Zero,
436 IntegerLiteralOct,
437 IntegerLiteralBinary,
438 IntegerLiteralHex,
439 IntegerLiteral,
440 IntegerSuffix,
441 IntegerSuffixU,
442 IntegerSuffixL,
443 IntegerSuffixLL,
444 IntegerSuffixUL,
445 FloatFraction,
446 FloatFractionHex,
447 FloatExponent,
448 FloatExponentDigits,
449 FloatSuffix,
450 } = .Start;
451 var string = false;
452 var counter: u32 = 0;
453 while (self.index < self.source.buffer.len) : (self.index += 1) {
454 const c = self.source.buffer[self.index];
455 switch (state) {
456 .Start => switch (c) {
457 '\n' => {
458 self.pp_directive = false;
459 result.id = .Nl;
460 self.index += 1;
461 break;
462 },
463 '\r' => {
464 state = .Cr;
465 },
466 '"' => {
467 result.id = .{ .StringLiteral = .None };
468 state = .StringLiteral;
469 },
470 '\'' => {
471 result.id = .{ .CharLiteral = .None };
472 state = .CharLiteralStart;
473 },
474 'u' => {
475 state = .u;
476 },
477 'U' => {
478 state = .U;
479 },
480 'L' => {
481 state = .L;
482 },
483 'a'...'t', 'v'...'z', 'A'...'K', 'M'...'T', 'V'...'Z', '_' => {
484 state = .Identifier;
485 },
486 '=' => {
487 state = .Equal;
488 },
489 '!' => {
490 state = .Bang;
491 },
492 '|' => {
493 state = .Pipe;
494 },
495 '(' => {
496 result.id = .LParen;
497 self.index += 1;
498 break;
499 },
500 ')' => {
501 result.id = .RParen;
502 self.index += 1;
503 break;
504 },
505 '[' => {
506 result.id = .LBracket;
507 self.index += 1;
508 break;
509 },
510 ']' => {
511 result.id = .RBracket;
512 self.index += 1;
513 break;
514 },
515 ';' => {
516 result.id = .Semicolon;
517 self.index += 1;
518 break;
519 },
520 ',' => {
521 result.id = .Comma;
522 self.index += 1;
523 break;
524 },
525 '?' => {
526 result.id = .QuestionMark;
527 self.index += 1;
528 break;
529 },
530 ':' => {
531 result.id = .Colon;
532 self.index += 1;
533 break;
534 },
535 '%' => {
536 state = .Percent;
537 },
538 '*' => {
539 state = .Asterisk;
540 },
541 '+' => {
542 state = .Plus;
543 },
544 '<' => {
545 if (self.prev_tok_id == .Keyword_include)
546 state = .MacroString
547 else
548 state = .AngleBracketLeft;
549 },
550 '>' => {
551 state = .AngleBracketRight;
552 },
553 '^' => {
554 state = .Caret;
555 },
556 '{' => {
557 result.id = .LBrace;
558 self.index += 1;
559 break;
560 },
561 '}' => {
562 result.id = .RBrace;
563 self.index += 1;
564 break;
565 },
566 '~' => {
567 result.id = .Tilde;
568 self.index += 1;
569 break;
570 },
571 '.' => {
572 state = .Period;
573 },
574 '-' => {
575 state = .Minus;
576 },
577 '/' => {
578 state = .Slash;
579 },
580 '&' => {
581 state = .Ampersand;
582 },
583 '#' => {
584 state = .Hash;
585 },
586 '0' => {
587 state = .Zero;
588 },
589 '1'...'9' => {
590 state = .IntegerLiteral;
591 },
592 '\\' => {
593 state = .BackSlash;
594 },
595 '\t', '\x0B', '\x0C', ' ' => {
596 result.start = self.index + 1;
597 },
598 else => {
599 // TODO handle invalid bytes better
600 result.id = .Invalid;
601 self.index += 1;
602 break;
603 },
604 },
605 .Cr => switch (c) {
606 '\n' => {
607 self.pp_directive = false;
608 result.id = .Nl;
609 self.index += 1;
610 break;
611 },
612 else => {
613 result.id = .Invalid;
614 break;
615 },
616 },
617 .BackSlash => switch (c) {
618 '\n' => {
619 state = .Start;
620 },
621 '\r' => {
622 state = .BackSlashCr;
623 },
624 '\t', '\x0B', '\x0C', ' ' => {
625 // TODO warn
626 },
627 else => {
628 result.id = .Invalid;
629 break;
630 },
631 },
632 .BackSlashCr => switch (c) {
633 '\n' => {
634 state = .Start;
635 },
636 else => {
637 result.id = .Invalid;
638 break;
639 },
640 },
641 .u => switch (c) {
642 '8' => {
643 state = .u8;
644 },
645 '\'' => {
646 result.id = .{ .CharLiteral = .Utf16 };
647 state = .CharLiteralStart;
648 },
649 '\"' => {
650 result.id = .{ .StringLiteral = .Utf16 };
651 state = .StringLiteral;
652 },
653 else => {
654 state = .Identifier;
655 },
656 },
657 .u8 => switch (c) {
658 '\"' => {
659 result.id = .{ .StringLiteral = .Utf8 };
660 state = .StringLiteral;
661 },
662 else => {
663 state = .Identifier;
664 },
665 },
666 .U => switch (c) {
667 '\'' => {
668 result.id = .{ .CharLiteral = .Utf32 };
669 state = .CharLiteralStart;
670 },
671 '\"' => {
672 result.id = .{ .StringLiteral = .Utf32 };
673 state = .StringLiteral;
674 },
675 else => {
676 state = .Identifier;
677 },
678 },
679 .L => switch (c) {
680 '\'' => {
681 result.id = .{ .CharLiteral = .Wide };
682 state = .CharLiteralStart;
683 },
684 '\"' => {
685 result.id = .{ .StringLiteral = .Wide };
686 state = .StringLiteral;
687 },
688 else => {
689 state = .Identifier;
690 },
691 },
692 .StringLiteral => switch (c) {
693 '\\' => {
694 string = true;
695 state = .EscapeSequence;
696 },
697 '"' => {
698 self.index += 1;
699 break;
700 },
701 '\n', '\r' => {
702 result.id = .Invalid;
703 break;
704 },
705 else => {},
706 },
707 .CharLiteralStart => switch (c) {
708 '\\' => {
709 string = false;
710 state = .EscapeSequence;
711 },
712 '\'', '\n' => {
713 result.id = .Invalid;
714 break;
715 },
716 else => {
717 state = .CharLiteral;
718 },
719 },
720 .CharLiteral => switch (c) {
721 '\\' => {
722 string = false;
723 state = .EscapeSequence;
724 },
725 '\'' => {
726 self.index += 1;
727 break;
728 },
729 '\n' => {
730 result.id = .Invalid;
731 break;
732 },
733 else => {},
734 },
735 .EscapeSequence => switch (c) {
736 '\'', '"', '?', '\\', 'a', 'b', 'f', 'n', 'r', 't', 'v', '\n' => {
737 state = if (string) .StringLiteral else .CharLiteral;
738 },
739 '\r' => {
740 state = .CrEscape;
741 },
742 '0'...'7' => {
743 counter = 1;
744 state = .OctalEscape;
745 },
746 'x' => {
747 state = .HexEscape;
748 },
749 'u' => {
750 counter = 4;
751 state = .OctalEscape;
752 },
753 'U' => {
754 counter = 8;
755 state = .OctalEscape;
756 },
757 else => {
758 result.id = .Invalid;
759 break;
760 },
761 },
762 .CrEscape => switch (c) {
763 '\n' => {
764 state = if (string) .StringLiteral else .CharLiteral;
765 },
766 else => {
767 result.id = .Invalid;
768 break;
769 },
770 },
771 .OctalEscape => switch (c) {
772 '0'...'7' => {
773 counter += 1;
774 if (counter == 3) {
775 state = if (string) .StringLiteral else .CharLiteral;
776 }
777 },
778 else => {
779 state = if (string) .StringLiteral else .CharLiteral;
780 },
781 },
782 .HexEscape => switch (c) {
783 '0'...'9', 'a'...'f', 'A'...'F' => {},
784 else => {
785 state = if (string) .StringLiteral else .CharLiteral;
786 },
787 },
788 .UnicodeEscape => switch (c) {
789 '0'...'9', 'a'...'f', 'A'...'F' => {
790 counter -= 1;
791 if (counter == 0) {
792 state = if (string) .StringLiteral else .CharLiteral;
793 }
794 },
795 else => {
796 if (counter != 0) {
797 result.id = .Invalid;
798 break;
799 }
800 state = if (string) .StringLiteral else .CharLiteral;
801 },
802 },
803 .Identifier => switch (c) {
804 'a'...'z', 'A'...'Z', '_', '0'...'9' => {},
805 else => {
806 result.id = Token.getKeyword(self.source.buffer[result.start..self.index], self.prev_tok_id == .Hash and !self.pp_directive) orelse .Identifier;
807 if (self.prev_tok_id == .Hash)
808 self.pp_directive = true;
809 break;
810 },
811 },
812 .Equal => switch (c) {
813 '=' => {
814 result.id = .EqualEqual;
815 self.index += 1;
816 break;
817 },
818 else => {
819 result.id = .Equal;
820 break;
821 },
822 },
823 .Bang => switch (c) {
824 '=' => {
825 result.id = .BangEqual;
826 self.index += 1;
827 break;
828 },
829 else => {
830 result.id = .Bang;
831 break;
832 },
833 },
834 .Pipe => switch (c) {
835 '=' => {
836 result.id = .PipeEqual;
837 self.index += 1;
838 break;
839 },
840 '|' => {
841 result.id = .PipePipe;
842 self.index += 1;
843 break;
844 },
845 else => {
846 result.id = .Pipe;
847 break;
848 },
849 },
850 .Percent => switch (c) {
851 '=' => {
852 result.id = .PercentEqual;
853 self.index += 1;
854 break;
855 },
856 else => {
857 result.id = .Percent;
858 break;
859 },
860 },
861 .Asterisk => switch (c) {
862 '=' => {
863 result.id = .AsteriskEqual;
864 self.index += 1;
865 break;
866 },
867 else => {
868 result.id = .Asterisk;
869 break;
870 },
871 },
872 .Plus => switch (c) {
873 '=' => {
874 result.id = .PlusEqual;
875 self.index += 1;
876 break;
877 },
878 '+' => {
879 result.id = .PlusPlus;
880 self.index += 1;
881 break;
882 },
883 else => {
884 result.id = .Plus;
885 break;
886 },
887 },
888 .MacroString => switch (c) {
889 '>' => {
890 result.id = .MacroString;
891 self.index += 1;
892 break;
893 },
894 else => {},
895 },
896 .AngleBracketLeft => switch (c) {
897 '<' => {
898 state = .AngleBracketAngleBracketLeft;
899 },
900 '=' => {
901 result.id = .AngleBracketLeftEqual;
902 self.index += 1;
903 break;
904 },
905 else => {
906 result.id = .AngleBracketLeft;
907 break;
908 },
909 },
910 .AngleBracketAngleBracketLeft => switch (c) {
911 '=' => {
912 result.id = .AngleBracketAngleBracketLeftEqual;
913 self.index += 1;
914 break;
915 },
916 else => {
917 result.id = .AngleBracketAngleBracketLeft;
918 break;
919 },
920 },
921 .AngleBracketRight => switch (c) {
922 '>' => {
923 state = .AngleBracketAngleBracketRight;
924 },
925 '=' => {
926 result.id = .AngleBracketRightEqual;
927 self.index += 1;
928 break;
929 },
930 else => {
931 result.id = .AngleBracketRight;
932 break;
933 },
934 },
935 .AngleBracketAngleBracketRight => switch (c) {
936 '=' => {
937 result.id = .AngleBracketAngleBracketRightEqual;
938 self.index += 1;
939 break;
940 },
941 else => {
942 result.id = .AngleBracketAngleBracketRight;
943 break;
944 },
945 },
946 .Caret => switch (c) {
947 '=' => {
948 result.id = .CaretEqual;
949 self.index += 1;
950 break;
951 },
952 else => {
953 result.id = .Caret;
954 break;
955 },
956 },
957 .Period => switch (c) {
958 '.' => {
959 state = .Period2;
960 },
961 '0'...'9' => {
962 state = .FloatFraction;
963 },
964 else => {
965 result.id = .Period;
966 break;
967 },
968 },
969 .Period2 => switch (c) {
970 '.' => {
971 result.id = .Ellipsis;
972 self.index += 1;
973 break;
974 },
975 else => {
976 result.id = .Period;
977 self.index -= 1;
978 break;
979 },
980 },
981 .Minus => switch (c) {
982 '>' => {
983 result.id = .Arrow;
984 self.index += 1;
985 break;
986 },
987 '=' => {
988 result.id = .MinusEqual;
989 self.index += 1;
990 break;
991 },
992 '-' => {
993 result.id = .MinusMinus;
994 self.index += 1;
995 break;
996 },
997 else => {
998 result.id = .Minus;
999 break;
1000 },
1001 },
1002 .Slash => switch (c) {
1003 '/' => {
1004 state = .LineComment;
1005 },
1006 '*' => {
1007 state = .MultiLineComment;
1008 },
1009 '=' => {
1010 result.id = .SlashEqual;
1011 self.index += 1;
1012 break;
1013 },
1014 else => {
1015 result.id = .Slash;
1016 break;
1017 },
1018 },
1019 .Ampersand => switch (c) {
1020 '&' => {
1021 result.id = .AmpersandAmpersand;
1022 self.index += 1;
1023 break;
1024 },
1025 '=' => {
1026 result.id = .AmpersandEqual;
1027 self.index += 1;
1028 break;
1029 },
1030 else => {
1031 result.id = .Ampersand;
1032 break;
1033 },
1034 },
1035 .Hash => switch (c) {
1036 '#' => {
1037 result.id = .HashHash;
1038 self.index += 1;
1039 break;
1040 },
1041 else => {
1042 result.id = .Hash;
1043 break;
1044 },
1045 },
1046 .LineComment => switch (c) {
1047 '\n' => {
1048 result.id = .LineComment;
1049 self.index += 1;
1050 break;
1051 },
1052 else => {},
1053 },
1054 .MultiLineComment => switch (c) {
1055 '*' => {
1056 state = .MultiLineCommentAsterisk;
1057 },
1058 else => {},
1059 },
1060 .MultiLineCommentAsterisk => switch (c) {
1061 '/' => {
1062 result.id = .MultiLineComment;
1063 self.index += 1;
1064 break;
1065 },
1066 else => {
1067 state = .MultiLineComment;
1068 },
1069 },
1070 .Zero => switch (c) {
1071 '0'...'9' => {
1072 state = .IntegerLiteralOct;
1073 },
1074 'b', 'B' => {
1075 state = .IntegerLiteralBinary;
1076 },
1077 'x', 'X' => {
1078 state = .IntegerLiteralHex;
1079 },
1080 else => {
1081 state = .IntegerSuffix;
1082 self.index -= 1;
1083 },
1084 },
1085 .IntegerLiteralOct => switch (c) {
1086 '0'...'7' => {},
1087 else => {
1088 state = .IntegerSuffix;
1089 self.index -= 1;
1090 },
1091 },
1092 .IntegerLiteralBinary => switch (c) {
1093 '0', '1' => {},
1094 else => {
1095 state = .IntegerSuffix;
1096 self.index -= 1;
1097 },
1098 },
1099 .IntegerLiteralHex => switch (c) {
1100 '0'...'9', 'a'...'f', 'A'...'F' => {},
1101 '.' => {
1102 state = .FloatFractionHex;
1103 },
1104 'p', 'P' => {
1105 state = .FloatExponent;
1106 },
1107 else => {
1108 state = .IntegerSuffix;
1109 self.index -= 1;
1110 },
1111 },
1112 .IntegerLiteral => switch (c) {
1113 '0'...'9' => {},
1114 '.' => {
1115 state = .FloatFraction;
1116 },
1117 'e', 'E' => {
1118 state = .FloatExponent;
1119 },
1120 else => {
1121 state = .IntegerSuffix;
1122 self.index -= 1;
1123 },
1124 },
1125 .IntegerSuffix => switch (c) {
1126 'u', 'U' => {
1127 state = .IntegerSuffixU;
1128 },
1129 'l', 'L' => {
1130 state = .IntegerSuffixL;
1131 },
1132 else => {
1133 result.id = .{ .IntegerLiteral = .None };
1134 break;
1135 },
1136 },
1137 .IntegerSuffixU => switch (c) {
1138 'l', 'L' => {
1139 state = .IntegerSuffixUL;
1140 },
1141 else => {
1142 result.id = .{ .IntegerLiteral = .U };
1143 break;
1144 },
1145 },
1146 .IntegerSuffixL => switch (c) {
1147 'l', 'L' => {
1148 state = .IntegerSuffixLL;
1149 },
1150 'u', 'U' => {
1151 result.id = .{ .IntegerLiteral = .LU };
1152 self.index += 1;
1153 break;
1154 },
1155 else => {
1156 result.id = .{ .IntegerLiteral = .L };
1157 break;
1158 },
1159 },
1160 .IntegerSuffixLL => switch (c) {
1161 'u', 'U' => {
1162 result.id = .{ .IntegerLiteral = .LLU };
1163 self.index += 1;
1164 break;
1165 },
1166 else => {
1167 result.id = .{ .IntegerLiteral = .LL };
1168 break;
1169 },
1170 },
1171 .IntegerSuffixUL => switch (c) {
1172 'l', 'L' => {
1173 result.id = .{ .IntegerLiteral = .LLU };
1174 self.index += 1;
1175 break;
1176 },
1177 else => {
1178 result.id = .{ .IntegerLiteral = .LU };
1179 break;
1180 },
1181 },
1182 .FloatFraction => switch (c) {
1183 '0'...'9' => {},
1184 'e', 'E' => {
1185 state = .FloatExponent;
1186 },
1187 else => {
1188 self.index -= 1;
1189 state = .FloatSuffix;
1190 },
1191 },
1192 .FloatFractionHex => switch (c) {
1193 '0'...'9', 'a'...'f', 'A'...'F' => {},
1194 'p', 'P' => {
1195 state = .FloatExponent;
1196 },
1197 else => {
1198 result.id = .Invalid;
1199 break;
1200 },
1201 },
1202 .FloatExponent => switch (c) {
1203 '+', '-' => {
1204 state = .FloatExponentDigits;
1205 },
1206 else => {
1207 self.index -= 1;
1208 state = .FloatExponentDigits;
1209 },
1210 },
1211 .FloatExponentDigits => switch (c) {
1212 '0'...'9' => {
1213 counter += 1;
1214 },
1215 else => {
1216 if (counter == 0) {
1217 result.id = .Invalid;
1218 break;
1219 }
1220 state = .FloatSuffix;
1221 },
1222 },
1223 .FloatSuffix => switch (c) {
1224 'l', 'L' => {
1225 result.id = .{ .FloatLiteral = .L };
1226 self.index += 1;
1227 break;
1228 },
1229 'f', 'F' => {
1230 result.id = .{ .FloatLiteral = .F };
1231 self.index += 1;
1232 break;
1233 },
1234 else => {
1235 result.id = .{ .FloatLiteral = .None };
1236 break;
1237 },
1238 },
1239 }
1240 } else if (self.index == self.source.buffer.len) {
1241 switch (state) {
1242 .Start => {},
1243 .u, .u8, .U, .L, .Identifier => {
1244 result.id = Token.getKeyword(self.source.buffer[result.start..self.index], self.prev_tok_id == .Hash and !self.pp_directive) orelse .Identifier;
1245 },
1246
1247 .Cr,
1248 .BackSlash,
1249 .BackSlashCr,
1250 .Period2,
1251 .StringLiteral,
1252 .CharLiteralStart,
1253 .CharLiteral,
1254 .EscapeSequence,
1255 .CrEscape,
1256 .OctalEscape,
1257 .HexEscape,
1258 .UnicodeEscape,
1259 .MultiLineComment,
1260 .MultiLineCommentAsterisk,
1261 .FloatFraction,
1262 .FloatFractionHex,
1263 .FloatExponent,
1264 .FloatExponentDigits,
1265 .MacroString,
1266 => result.id = .Invalid,
1267
1268 .IntegerLiteralOct,
1269 .IntegerLiteralBinary,
1270 .IntegerLiteralHex,
1271 .IntegerLiteral,
1272 .IntegerSuffix,
1273 .Zero,
1274 => result.id = .{ .IntegerLiteral = .None },
1275 .IntegerSuffixU => result.id = .{ .IntegerLiteral = .U },
1276 .IntegerSuffixL => result.id = .{ .IntegerLiteral = .L },
1277 .IntegerSuffixLL => result.id = .{ .IntegerLiteral = .LL },
1278 .IntegerSuffixUL => result.id = .{ .IntegerLiteral = .LU },
1279
1280 .FloatSuffix => result.id = .{ .FloatLiteral = .None },
1281 .Equal => result.id = .Equal,
1282 .Bang => result.id = .Bang,
1283 .Minus => result.id = .Minus,
1284 .Slash => result.id = .Slash,
1285 .Ampersand => result.id = .Ampersand,
1286 .Hash => result.id = .Hash,
1287 .Period => result.id = .Period,
1288 .Pipe => result.id = .Pipe,
1289 .AngleBracketAngleBracketRight => result.id = .AngleBracketAngleBracketRight,
1290 .AngleBracketRight => result.id = .AngleBracketRight,
1291 .AngleBracketAngleBracketLeft => result.id = .AngleBracketAngleBracketLeft,
1292 .AngleBracketLeft => result.id = .AngleBracketLeft,
1293 .Plus => result.id = .Plus,
1294 .Percent => result.id = .Percent,
1295 .Caret => result.id = .Caret,
1296 .Asterisk => result.id = .Asterisk,
1297 .LineComment => result.id = .LineComment,
1298 }
1299 }
1300
1301 self.prev_tok_id = result.id;
1302 result.end = self.index;
1303 return result;
1304 }
1305};
1306
1307test "operators" {
1308 expectTokens(
1309 \\ ! != | || |= = ==
1310 \\ ( ) { } [ ] . .. ...
1311 \\ ^ ^= + ++ += - -- -=
1312 \\ * *= % %= -> : ; / /=
1313 \\ , & && &= ? < <= <<
1314 \\ <<= > >= >> >>= ~ # ##
1315 \\
1316 , &[_]Token.Id{
1317 .Bang,
1318 .BangEqual,
1319 .Pipe,
1320 .PipePipe,
1321 .PipeEqual,
1322 .Equal,
1323 .EqualEqual,
1324 .Nl,
1325 .LParen,
1326 .RParen,
1327 .LBrace,
1328 .RBrace,
1329 .LBracket,
1330 .RBracket,
1331 .Period,
1332 .Period,
1333 .Period,
1334 .Ellipsis,
1335 .Nl,
1336 .Caret,
1337 .CaretEqual,
1338 .Plus,
1339 .PlusPlus,
1340 .PlusEqual,
1341 .Minus,
1342 .MinusMinus,
1343 .MinusEqual,
1344 .Nl,
1345 .Asterisk,
1346 .AsteriskEqual,
1347 .Percent,
1348 .PercentEqual,
1349 .Arrow,
1350 .Colon,
1351 .Semicolon,
1352 .Slash,
1353 .SlashEqual,
1354 .Nl,
1355 .Comma,
1356 .Ampersand,
1357 .AmpersandAmpersand,
1358 .AmpersandEqual,
1359 .QuestionMark,
1360 .AngleBracketLeft,
1361 .AngleBracketLeftEqual,
1362 .AngleBracketAngleBracketLeft,
1363 .Nl,
1364 .AngleBracketAngleBracketLeftEqual,
1365 .AngleBracketRight,
1366 .AngleBracketRightEqual,
1367 .AngleBracketAngleBracketRight,
1368 .AngleBracketAngleBracketRightEqual,
1369 .Tilde,
1370 .Hash,
1371 .HashHash,
1372 .Nl,
1373 });
1374}
1375
1376test "keywords" {
1377 expectTokens(
1378 \\auto break case char const continue default do
1379 \\double else enum extern float for goto if int
1380 \\long register return short signed sizeof static
1381 \\struct switch typedef union unsigned void volatile
1382 \\while _Bool _Complex _Imaginary inline restrict _Alignas
1383 \\_Alignof _Atomic _Generic _Noreturn _Static_assert _Thread_local
1384 \\
1385 , &[_]Token.Id{
1386 .Keyword_auto,
1387 .Keyword_break,
1388 .Keyword_case,
1389 .Keyword_char,
1390 .Keyword_const,
1391 .Keyword_continue,
1392 .Keyword_default,
1393 .Keyword_do,
1394 .Nl,
1395 .Keyword_double,
1396 .Keyword_else,
1397 .Keyword_enum,
1398 .Keyword_extern,
1399 .Keyword_float,
1400 .Keyword_for,
1401 .Keyword_goto,
1402 .Keyword_if,
1403 .Keyword_int,
1404 .Nl,
1405 .Keyword_long,
1406 .Keyword_register,
1407 .Keyword_return,
1408 .Keyword_short,
1409 .Keyword_signed,
1410 .Keyword_sizeof,
1411 .Keyword_static,
1412 .Nl,
1413 .Keyword_struct,
1414 .Keyword_switch,
1415 .Keyword_typedef,
1416 .Keyword_union,
1417 .Keyword_unsigned,
1418 .Keyword_void,
1419 .Keyword_volatile,
1420 .Nl,
1421 .Keyword_while,
1422 .Keyword_bool,
1423 .Keyword_complex,
1424 .Keyword_imaginary,
1425 .Keyword_inline,
1426 .Keyword_restrict,
1427 .Keyword_alignas,
1428 .Nl,
1429 .Keyword_alignof,
1430 .Keyword_atomic,
1431 .Keyword_generic,
1432 .Keyword_noreturn,
1433 .Keyword_static_assert,
1434 .Keyword_thread_local,
1435 .Nl,
1436 });
1437}
1438
1439test "preprocessor keywords" {
1440 expectTokens(
1441 \\#include <test>
1442 \\#define #include <1
1443 \\#ifdef
1444 \\#ifndef
1445 \\#error
1446 \\#pragma
1447 \\
1448 , &[_]Token.Id{
1449 .Hash,
1450 .Keyword_include,
1451 .MacroString,
1452 .Nl,
1453 .Hash,
1454 .Keyword_define,
1455 .Hash,
1456 .Identifier,
1457 .AngleBracketLeft,
1458 .{ .IntegerLiteral = .None },
1459 .Nl,
1460 .Hash,
1461 .Keyword_ifdef,
1462 .Nl,
1463 .Hash,
1464 .Keyword_ifndef,
1465 .Nl,
1466 .Hash,
1467 .Keyword_error,
1468 .Nl,
1469 .Hash,
1470 .Keyword_pragma,
1471 .Nl,
1472 });
1473}
1474
1475test "line continuation" {
1476 expectTokens(
1477 \\#define foo \
1478 \\ bar
1479 \\"foo\
1480 \\ bar"
1481 \\#define "foo"
1482 \\ "bar"
1483 \\#define "foo" \
1484 \\ "bar"
1485 , &[_]Token.Id{
1486 .Hash,
1487 .Keyword_define,
1488 .Identifier,
1489 .Identifier,
1490 .Nl,
1491 .{ .StringLiteral = .None },
1492 .Nl,
1493 .Hash,
1494 .Keyword_define,
1495 .{ .StringLiteral = .None },
1496 .Nl,
1497 .{ .StringLiteral = .None },
1498 .Nl,
1499 .Hash,
1500 .Keyword_define,
1501 .{ .StringLiteral = .None },
1502 .{ .StringLiteral = .None },
1503 });
1504}
1505
1506test "string prefix" {
1507 expectTokens(
1508 \\"foo"
1509 \\u"foo"
1510 \\u8"foo"
1511 \\U"foo"
1512 \\L"foo"
1513 \\'foo'
1514 \\u'foo'
1515 \\U'foo'
1516 \\L'foo'
1517 \\
1518 , &[_]Token.Id{
1519 .{ .StringLiteral = .None },
1520 .Nl,
1521 .{ .StringLiteral = .Utf16 },
1522 .Nl,
1523 .{ .StringLiteral = .Utf8 },
1524 .Nl,
1525 .{ .StringLiteral = .Utf32 },
1526 .Nl,
1527 .{ .StringLiteral = .Wide },
1528 .Nl,
1529 .{ .CharLiteral = .None },
1530 .Nl,
1531 .{ .CharLiteral = .Utf16 },
1532 .Nl,
1533 .{ .CharLiteral = .Utf32 },
1534 .Nl,
1535 .{ .CharLiteral = .Wide },
1536 .Nl,
1537 });
1538}
1539
1540test "num suffixes" {
1541 expectTokens(
1542 \\ 1.0f 1.0L 1.0 .0 1.
1543 \\ 0l 0lu 0ll 0llu 0
1544 \\ 1u 1ul 1ull 1
1545 \\
1546 , &[_]Token.Id{
1547 .{ .FloatLiteral = .F },
1548 .{ .FloatLiteral = .L },
1549 .{ .FloatLiteral = .None },
1550 .{ .FloatLiteral = .None },
1551 .{ .FloatLiteral = .None },
1552 .Nl,
1553 .{ .IntegerLiteral = .L },
1554 .{ .IntegerLiteral = .LU },
1555 .{ .IntegerLiteral = .LL },
1556 .{ .IntegerLiteral = .LLU },
1557 .{ .IntegerLiteral = .None },
1558 .Nl,
1559 .{ .IntegerLiteral = .U },
1560 .{ .IntegerLiteral = .LU },
1561 .{ .IntegerLiteral = .LLU },
1562 .{ .IntegerLiteral = .None },
1563 .Nl,
1564 });
1565}
1566
1567fn expectTokens(source: []const u8, expected_tokens: []const Token.Id) void {
1568 var tokenizer = Tokenizer{
1569 .source = &Source{
1570 .buffer = source,
1571 .file_name = undefined,
1572 .tokens = undefined,
1573 },
1574 };
1575 for (expected_tokens) |expected_token_id| {
1576 const token = tokenizer.next();
1577 if (!std.meta.eql(token.id, expected_token_id)) {
1578 std.debug.panic("expected {}, found {}\n", .{ @tagName(expected_token_id), @tagName(token.id) });
1579 }
1580 }
1581 const last_token = tokenizer.next();
1582 std.testing.expect(last_token.id == .Eof);
1583}
lib/std/debug.zig+451-620
...@@ -81,10 +81,20 @@ pub fn getSelfDebugInfo() !*DebugInfo {...@@ -81,10 +81,20 @@ pub fn getSelfDebugInfo() !*DebugInfo {
81 }81 }
82}82}
8383
84fn wantTtyColor() bool {84pub fn detectTTYConfig() TTY.Config {
85 var bytes: [128]u8 = undefined;85 var bytes: [128]u8 = undefined;
86 const allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator;86 const allocator = &std.heap.FixedBufferAllocator.init(bytes[0..]).allocator;
87 return if (process.getEnvVarOwned(allocator, "ZIG_DEBUG_COLOR")) |_| true else |_| stderr_file.isTty();87 if (process.getEnvVarOwned(allocator, "ZIG_DEBUG_COLOR")) |_| {
88 return .escape_codes;
89 } else |_| {
90 if (stderr_file.supportsAnsiEscapeCodes()) {
91 return .escape_codes;
92 } else if (builtin.os == .windows and stderr_file.isTty()) {
93 return .windows_api;
94 } else {
95 return .no_color;
96 }
97 }
88}98}
8999
90/// Tries to print the current stack trace to stderr, unbuffered, and ignores any error returned.100/// Tries to print the current stack trace to stderr, unbuffered, and ignores any error returned.
...@@ -99,7 +109,7 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {...@@ -99,7 +109,7 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
99 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return;109 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return;
100 return;110 return;
101 };111 };
102 writeCurrentStackTrace(stderr, debug_info, wantTtyColor(), start_addr) catch |err| {112 writeCurrentStackTrace(stderr, debug_info, detectTTYConfig(), start_addr) catch |err| {
103 stderr.print("Unable to dump stack trace: {}\n", .{@errorName(err)}) catch return;113 stderr.print("Unable to dump stack trace: {}\n", .{@errorName(err)}) catch return;
104 return;114 return;
105 };115 };
...@@ -118,16 +128,16 @@ pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void {...@@ -118,16 +128,16 @@ pub fn dumpStackTraceFromBase(bp: usize, ip: usize) void {
118 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return;128 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return;
119 return;129 return;
120 };130 };
121 const tty_color = wantTtyColor();131 const tty_config = detectTTYConfig();
122 printSourceAtAddress(debug_info, stderr, ip, tty_color) catch return;132 printSourceAtAddress(debug_info, stderr, ip, tty_config) catch return;
123 const first_return_address = @intToPtr(*const usize, bp + @sizeOf(usize)).*;133 const first_return_address = @intToPtr(*const usize, bp + @sizeOf(usize)).*;
124 printSourceAtAddress(debug_info, stderr, first_return_address - 1, tty_color) catch return;134 printSourceAtAddress(debug_info, stderr, first_return_address - 1, tty_config) catch return;
125 var it = StackIterator{135 var it = StackIterator{
126 .first_addr = null,136 .first_addr = null,
127 .fp = bp,137 .fp = bp,
128 };138 };
129 while (it.next()) |return_address| {139 while (it.next()) |return_address| {
130 printSourceAtAddress(debug_info, stderr, return_address - 1, tty_color) catch return;140 printSourceAtAddress(debug_info, stderr, return_address - 1, tty_config) catch return;
131 }141 }
132}142}
133143
...@@ -191,7 +201,7 @@ pub fn dumpStackTrace(stack_trace: builtin.StackTrace) void {...@@ -191,7 +201,7 @@ pub fn dumpStackTrace(stack_trace: builtin.StackTrace) void {
191 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return;201 stderr.print("Unable to dump stack trace: Unable to open debug info: {}\n", .{@errorName(err)}) catch return;
192 return;202 return;
193 };203 };
194 writeStackTrace(stack_trace, stderr, getDebugInfoAllocator(), debug_info, wantTtyColor()) catch |err| {204 writeStackTrace(stack_trace, stderr, getDebugInfoAllocator(), debug_info, detectTTYConfig()) catch |err| {
195 stderr.print("Unable to dump stack trace: {}\n", .{@errorName(err)}) catch return;205 stderr.print("Unable to dump stack trace: {}\n", .{@errorName(err)}) catch return;
196 return;206 return;
197 };207 };
...@@ -264,7 +274,7 @@ pub fn writeStackTrace(...@@ -264,7 +274,7 @@ pub fn writeStackTrace(
264 out_stream: var,274 out_stream: var,
265 allocator: *mem.Allocator,275 allocator: *mem.Allocator,
266 debug_info: *DebugInfo,276 debug_info: *DebugInfo,
267 tty_color: bool,277 tty_config: TTY.Config,
268) !void {278) !void {
269 if (builtin.strip_debug_info) return error.MissingDebugInfo;279 if (builtin.strip_debug_info) return error.MissingDebugInfo;
270 var frame_index: usize = 0;280 var frame_index: usize = 0;
...@@ -275,7 +285,7 @@ pub fn writeStackTrace(...@@ -275,7 +285,7 @@ pub fn writeStackTrace(
275 frame_index = (frame_index + 1) % stack_trace.instruction_addresses.len;285 frame_index = (frame_index + 1) % stack_trace.instruction_addresses.len;
276 }) {286 }) {
277 const return_address = stack_trace.instruction_addresses[frame_index];287 const return_address = stack_trace.instruction_addresses[frame_index];
278 try printSourceAtAddress(debug_info, out_stream, return_address - 1, tty_color);288 try printSourceAtAddress(debug_info, out_stream, return_address - 1, tty_config);
279 }289 }
280}290}
281291
...@@ -319,20 +329,25 @@ pub const StackIterator = struct {...@@ -319,20 +329,25 @@ pub const StackIterator = struct {
319 }329 }
320};330};
321331
322pub fn writeCurrentStackTrace(out_stream: var, debug_info: *DebugInfo, tty_color: bool, start_addr: ?usize) !void {332pub fn writeCurrentStackTrace(
333 out_stream: var,
334 debug_info: *DebugInfo,
335 tty_config: TTY.Config,
336 start_addr: ?usize,
337) !void {
323 if (builtin.os == .windows) {338 if (builtin.os == .windows) {
324 return writeCurrentStackTraceWindows(out_stream, debug_info, tty_color, start_addr);339 return writeCurrentStackTraceWindows(out_stream, debug_info, tty_config, start_addr);
325 }340 }
326 var it = StackIterator.init(start_addr);341 var it = StackIterator.init(start_addr);
327 while (it.next()) |return_address| {342 while (it.next()) |return_address| {
328 try printSourceAtAddress(debug_info, out_stream, return_address - 1, tty_color);343 try printSourceAtAddress(debug_info, out_stream, return_address - 1, tty_config);
329 }344 }
330}345}
331346
332pub fn writeCurrentStackTraceWindows(347pub fn writeCurrentStackTraceWindows(
333 out_stream: var,348 out_stream: var,
334 debug_info: *DebugInfo,349 debug_info: *DebugInfo,
335 tty_color: bool,350 tty_config: TTY.Config,
336 start_addr: ?usize,351 start_addr: ?usize,
337) !void {352) !void {
338 var addr_buf: [1024]usize = undefined;353 var addr_buf: [1024]usize = undefined;
...@@ -345,23 +360,28 @@ pub fn writeCurrentStackTraceWindows(...@@ -345,23 +360,28 @@ pub fn writeCurrentStackTraceWindows(
345 return;360 return;
346 } else 0;361 } else 0;
347 for (addrs[start_i..]) |addr| {362 for (addrs[start_i..]) |addr| {
348 try printSourceAtAddress(debug_info, out_stream, addr, tty_color);363 try printSourceAtAddress(debug_info, out_stream, addr - 1, tty_config);
349 }364 }
350}365}
351366
352/// TODO once https://github.com/ziglang/zig/issues/3157 is fully implemented,367/// TODO once https://github.com/ziglang/zig/issues/3157 is fully implemented,
353/// make this `noasync fn` and remove the individual noasync calls.368/// make this `noasync fn` and remove the individual noasync calls.
354pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void {369pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: usize, tty_config: TTY.Config) !void {
355 if (builtin.os == .windows) {370 if (builtin.os == .windows) {
356 return noasync printSourceAtAddressWindows(debug_info, out_stream, address, tty_color);371 return noasync printSourceAtAddressWindows(debug_info, out_stream, address, tty_config);
357 }372 }
358 if (comptime std.Target.current.isDarwin()) {373 if (comptime std.Target.current.isDarwin()) {
359 return noasync printSourceAtAddressMacOs(debug_info, out_stream, address, tty_color);374 return noasync printSourceAtAddressMacOs(debug_info, out_stream, address, tty_config);
360 }375 }
361 return noasync printSourceAtAddressPosix(debug_info, out_stream, address, tty_color);376 return noasync printSourceAtAddressPosix(debug_info, out_stream, address, tty_config);
362}377}
363378
364fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_address: usize, tty_color: bool) !void {379fn printSourceAtAddressWindows(
380 di: *DebugInfo,
381 out_stream: var,
382 relocated_address: usize,
383 tty_config: TTY.Config,
384) !void {
365 const allocator = getDebugInfoAllocator();385 const allocator = getDebugInfoAllocator();
366 const base_address = process.getBaseAddress();386 const base_address = process.getBaseAddress();
367 const relative_address = relocated_address - base_address;387 const relative_address = relocated_address - base_address;
...@@ -379,16 +399,7 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres...@@ -379,16 +399,7 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
379 }399 }
380 } else {400 } else {
381 // we have no information to add to the address401 // we have no information to add to the address
382 if (tty_color) {402 return printLineInfo(out_stream, null, relocated_address, "???", "???", tty_config, printLineFromFileAnyOs);
383 try out_stream.print("???:?:?: ", .{});
384 setTtyColor(TtyColor.Dim);
385 try out_stream.print("0x{x} in ??? (???)", .{relocated_address});
386 setTtyColor(TtyColor.Reset);
387 try out_stream.print("\n\n\n", .{});
388 } else {
389 try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{relocated_address});
390 }
391 return;
392 };403 };
393404
394 const mod = &di.modules[mod_index];405 const mod = &di.modules[mod_index];
...@@ -401,7 +412,7 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres...@@ -401,7 +412,7 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
401 if (prefix.RecordLen < 2)412 if (prefix.RecordLen < 2)
402 return error.InvalidDebugInfo;413 return error.InvalidDebugInfo;
403 switch (prefix.RecordKind) {414 switch (prefix.RecordKind) {
404 pdb.SymbolKind.S_LPROC32 => {415 .S_LPROC32, .S_GPROC32 => {
405 const proc_sym = @ptrCast(*pdb.ProcSym, &mod.symbols[symbol_i + @sizeOf(pdb.RecordPrefix)]);416 const proc_sym = @ptrCast(*pdb.ProcSym, &mod.symbols[symbol_i + @sizeOf(pdb.RecordPrefix)]);
406 const vaddr_start = coff_section.header.virtual_address + proc_sym.CodeOffset;417 const vaddr_start = coff_section.header.virtual_address + proc_sym.CodeOffset;
407 const vaddr_end = vaddr_start + proc_sym.CodeSize;418 const vaddr_end = vaddr_start + proc_sym.CodeSize;
...@@ -510,137 +521,86 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres...@@ -510,137 +521,86 @@ fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_addres
510 }521 }
511 };522 };
512523
513 if (tty_color) {524 try printLineInfo(
514 setTtyColor(TtyColor.White);525 out_stream,
515 if (opt_line_info) |li| {526 opt_line_info,
516 try out_stream.print("{}:{}:{}", .{ li.file_name, li.line, li.column });527 relocated_address,
517 } else {528 symbol_name,
518 try out_stream.print("???:?:?", .{});529 obj_basename,
519 }530 tty_config,
520 setTtyColor(TtyColor.Reset);531 printLineFromFileAnyOs,
521 try out_stream.print(": ", .{});532 );
522 setTtyColor(TtyColor.Dim);
523 try out_stream.print("0x{x} in {} ({})", .{ relocated_address, symbol_name, obj_basename });
524 setTtyColor(TtyColor.Reset);
525
526 if (opt_line_info) |line_info| {
527 try out_stream.print("\n", .{});
528 if (printLineFromFileAnyOs(out_stream, line_info)) {
529 if (line_info.column == 0) {
530 try out_stream.write("\n");
531 } else {
532 {
533 var col_i: usize = 1;
534 while (col_i < line_info.column) : (col_i += 1) {
535 try out_stream.writeByte(' ');
536 }
537 }
538 setTtyColor(TtyColor.Green);
539 try out_stream.write("^");
540 setTtyColor(TtyColor.Reset);
541 try out_stream.write("\n");
542 }
543 } else |err| switch (err) {
544 error.EndOfFile => {},
545 error.FileNotFound => {
546 setTtyColor(TtyColor.Dim);
547 try out_stream.write("file not found\n\n");
548 setTtyColor(TtyColor.White);
549 },
550 else => return err,
551 }
552 } else {
553 try out_stream.print("\n\n\n", .{});
554 }
555 } else {
556 if (opt_line_info) |li| {
557 try out_stream.print("{}:{}:{}: 0x{x} in {} ({})\n\n\n", .{
558 li.file_name,
559 li.line,
560 li.column,
561 relocated_address,
562 symbol_name,
563 obj_basename,
564 });
565 } else {
566 try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", .{
567 relocated_address,
568 symbol_name,
569 obj_basename,
570 });
571 }
572 }
573}533}
574534
575const TtyColor = enum {535pub const TTY = struct {
576 Red,536 pub const Color = enum {
577 Green,537 Red,
578 Cyan,538 Green,
579 White,539 Cyan,
580 Dim,540 White,
581 Bold,541 Dim,
582 Reset,542 Bold,
583};543 Reset,
544 };
584545
585/// TODO this is a special case hack right now. clean it up and maybe make it part of std.fmt546 pub const Config = enum {
586fn setTtyColor(tty_color: TtyColor) void {547 no_color,
587 if (stderr_file.supportsAnsiEscapeCodes()) {548 escape_codes,
588 switch (tty_color) {549 // TODO give this a payload of file handle
589 TtyColor.Red => {550 windows_api,
590 stderr_file.write(RED) catch return;551
591 },552 fn setColor(conf: Config, out_stream: var, color: Color) void {
592 TtyColor.Green => {553 switch (conf) {
593 stderr_file.write(GREEN) catch return;554 .no_color => return,
594 },555 .escape_codes => switch (color) {
595 TtyColor.Cyan => {556 .Red => out_stream.write(RED) catch return,
596 stderr_file.write(CYAN) catch return;557 .Green => out_stream.write(GREEN) catch return,
597 },558 .Cyan => out_stream.write(CYAN) catch return,
598 TtyColor.White, TtyColor.Bold => {559 .White, .Bold => out_stream.write(WHITE) catch return,
599 stderr_file.write(WHITE) catch return;560 .Dim => out_stream.write(DIM) catch return,
600 },561 .Reset => out_stream.write(RESET) catch return,
601 TtyColor.Dim => {562 },
602 stderr_file.write(DIM) catch return;563 .windows_api => if (builtin.os == .windows) {
603 },564 const S = struct {
604 TtyColor.Reset => {565 var attrs: windows.WORD = undefined;
605 stderr_file.write(RESET) catch return;566 var init_attrs = false;
606 },567 };
607 }568 if (!S.init_attrs) {
608 } else {569 S.init_attrs = true;
609 const S = struct {570 var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;
610 var attrs: windows.WORD = undefined;571 // TODO handle error
611 var init_attrs = false;572 _ = windows.kernel32.GetConsoleScreenBufferInfo(stderr_file.handle, &info);
612 };573 S.attrs = info.wAttributes;
613 if (!S.init_attrs) {574 }
614 S.init_attrs = true;
615 var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;
616 // TODO handle error
617 _ = windows.kernel32.GetConsoleScreenBufferInfo(stderr_file.handle, &info);
618 S.attrs = info.wAttributes;
619 }
620575
621 // TODO handle errors576 // TODO handle errors
622 switch (tty_color) {577 switch (color) {
623 TtyColor.Red => {578 .Red => {
624 _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_INTENSITY) catch {};579 _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_INTENSITY) catch {};
625 },580 },
626 TtyColor.Green => {581 .Green => {
627 _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_INTENSITY) catch {};582 _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_INTENSITY) catch {};
628 },583 },
629 TtyColor.Cyan => {584 .Cyan => {
630 _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY) catch {};585 _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY) catch {};
631 },586 },
632 TtyColor.White, TtyColor.Bold => {587 .White, .Bold => {
633 _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY) catch {};588 _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY) catch {};
634 },589 },
635 TtyColor.Dim => {590 .Dim => {
636 _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_INTENSITY) catch {};591 _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_INTENSITY) catch {};
637 },592 },
638 TtyColor.Reset => {593 .Reset => {
639 _ = windows.SetConsoleTextAttribute(stderr_file.handle, S.attrs) catch {};594 _ = windows.SetConsoleTextAttribute(stderr_file.handle, S.attrs) catch {};
640 },595 },
596 }
597 } else {
598 unreachable;
599 },
600 }
641 }601 }
642 }602 };
643}603};
644604
645fn populateModule(di: *DebugInfo, mod: *Module) !void {605fn populateModule(di: *DebugInfo, mod: *Module) !void {
646 if (mod.populated)606 if (mod.populated)
...@@ -706,17 +666,12 @@ fn machoSearchSymbols(symbols: []const MachoSymbol, address: usize) ?*const Mach...@@ -706,17 +666,12 @@ fn machoSearchSymbols(symbols: []const MachoSymbol, address: usize) ?*const Mach
706 return null;666 return null;
707}667}
708668
709fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void {669fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tty_config: TTY.Config) !void {
710 const base_addr = process.getBaseAddress();670 const base_addr = process.getBaseAddress();
711 const adjusted_addr = 0x100000000 + (address - base_addr);671 const adjusted_addr = 0x100000000 + (address - base_addr);
712672
713 const symbol = machoSearchSymbols(di.symbols, adjusted_addr) orelse {673 const symbol = machoSearchSymbols(di.symbols, adjusted_addr) orelse {
714 if (tty_color) {674 return printLineInfo(out_stream, null, address, "???", "???", tty_config, printLineFromFileAnyOs);
715 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", .{address});
716 } else {
717 try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{address});
718 }
719 return;
720 };675 };
721676
722 const symbol_name = mem.toSliceConst(u8, @ptrCast([*:0]const u8, di.strings.ptr + symbol.nlist.n_strx));677 const symbol_name = mem.toSliceConst(u8, @ptrCast([*:0]const u8, di.strings.ptr + symbol.nlist.n_strx));
...@@ -724,78 +679,70 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt...@@ -724,78 +679,70 @@ fn printSourceAtAddressMacOs(di: *DebugInfo, out_stream: var, address: usize, tt
724 const ofile_path = mem.toSliceConst(u8, @ptrCast([*:0]const u8, di.strings.ptr + ofile.n_strx));679 const ofile_path = mem.toSliceConst(u8, @ptrCast([*:0]const u8, di.strings.ptr + ofile.n_strx));
725 break :blk fs.path.basename(ofile_path);680 break :blk fs.path.basename(ofile_path);
726 } else "???";681 } else "???";
727 if (getLineNumberInfoMacOs(di, symbol.*, adjusted_addr)) |line_info| {682
728 defer line_info.deinit();683 const line_info = getLineNumberInfoMacOs(di, symbol.*, adjusted_addr) catch |err| switch (err) {
729 try printLineInfo(684 error.MissingDebugInfo, error.InvalidDebugInfo => null,
730 out_stream,
731 line_info,
732 address,
733 symbol_name,
734 compile_unit_name,
735 tty_color,
736 printLineFromFileAnyOs,
737 );
738 } else |err| switch (err) {
739 error.MissingDebugInfo, error.InvalidDebugInfo => {
740 if (tty_color) {
741 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n\n\n", .{
742 address, symbol_name, compile_unit_name,
743 });
744 } else {
745 try out_stream.print("???:?:?: 0x{x} in {} ({})\n\n\n", .{ address, symbol_name, compile_unit_name });
746 }
747 },
748 else => return err,685 else => return err,
749 }686 };
687 defer if (line_info) |li| li.deinit();
688
689 try printLineInfo(
690 out_stream,
691 line_info,
692 address,
693 symbol_name,
694 compile_unit_name,
695 tty_config,
696 printLineFromFileAnyOs,
697 );
750}698}
751699
752pub fn printSourceAtAddressPosix(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void {700pub fn printSourceAtAddressPosix(debug_info: *DebugInfo, out_stream: var, address: usize, tty_config: TTY.Config) !void {
753 return debug_info.printSourceAtAddress(out_stream, address, tty_color, printLineFromFileAnyOs);701 return debug_info.printSourceAtAddress(out_stream, address, tty_config, printLineFromFileAnyOs);
754}702}
755703
756fn printLineInfo(704fn printLineInfo(
757 out_stream: var,705 out_stream: var,
758 line_info: LineInfo,706 line_info: ?LineInfo,
759 address: usize,707 address: usize,
760 symbol_name: []const u8,708 symbol_name: []const u8,
761 compile_unit_name: []const u8,709 compile_unit_name: []const u8,
762 tty_color: bool,710 tty_config: TTY.Config,
763 comptime printLineFromFile: var,711 comptime printLineFromFile: var,
764) !void {712) !void {
765 if (tty_color) {713 tty_config.setColor(out_stream, .White);
766 try out_stream.print(WHITE ++ "{}:{}:{}" ++ RESET ++ ": " ++ DIM ++ "0x{x} in {} ({})" ++ RESET ++ "\n", .{714
767 line_info.file_name,715 if (line_info) |*li| {
768 line_info.line,716 try out_stream.print("{}:{}:{}", .{ li.file_name, li.line, li.column });
769 line_info.column,717 } else {
770 address,718 try out_stream.print("???:?:?", .{});
771 symbol_name,719 }
772 compile_unit_name,720
773 });721 tty_config.setColor(out_stream, .Reset);
774 if (printLineFromFile(out_stream, line_info)) {722 try out_stream.write(": ");
775 if (line_info.column == 0) {723 tty_config.setColor(out_stream, .Dim);
776 try out_stream.write("\n");724 try out_stream.print("0x{x} in {} ({})", .{ address, symbol_name, compile_unit_name });
777 } else {725 tty_config.setColor(out_stream, .Reset);
778 {726 try out_stream.write("\n");
779 var col_i: usize = 1;727
780 while (col_i < line_info.column) : (col_i += 1) {728 // Show the matching source code line if possible
781 try out_stream.writeByte(' ');729 if (line_info) |li| {
782 }730 if (noasync printLineFromFile(out_stream, li)) {
783 }731 if (li.column > 0) {
784 try out_stream.write(GREEN ++ "^" ++ RESET ++ "\n");732 // The caret already takes one char
733 const space_needed = @intCast(usize, li.column - 1);
734
735 try out_stream.writeByteNTimes(' ', space_needed);
736 tty_config.setColor(out_stream, .Green);
737 try out_stream.write("^");
738 tty_config.setColor(out_stream, .Reset);
785 }739 }
740 try out_stream.write("\n");
786 } else |err| switch (err) {741 } else |err| switch (err) {
787 error.EndOfFile, error.FileNotFound => {},742 error.EndOfFile, error.FileNotFound => {},
743 error.BadPathName => {},
788 else => return err,744 else => return err,
789 }745 }
790 } else {
791 try out_stream.print("{}:{}:{}: 0x{x} in {} ({})\n", .{
792 line_info.file_name,
793 line_info.line,
794 line_info.column,
795 address,
796 symbol_name,
797 compile_unit_name,
798 });
799 }746 }
800}747}
801748
...@@ -1016,59 +963,61 @@ pub fn openDwarfDebugInfo(di: *DwarfInfo, allocator: *mem.Allocator) !void {...@@ -1016,59 +963,61 @@ pub fn openDwarfDebugInfo(di: *DwarfInfo, allocator: *mem.Allocator) !void {
1016963
1017pub fn openElfDebugInfo(964pub fn openElfDebugInfo(
1018 allocator: *mem.Allocator,965 allocator: *mem.Allocator,
1019 elf_seekable_stream: *DwarfSeekableStream,966 data: []u8,
1020 elf_in_stream: *DwarfInStream,
1021) !DwarfInfo {967) !DwarfInfo {
1022 var efile = try elf.Elf.openStream(allocator, elf_seekable_stream, elf_in_stream);968 var seekable_stream = io.SliceSeekableInStream.init(data);
1023 errdefer efile.close();969 var efile = try elf.Elf.openStream(
970 allocator,
971 @ptrCast(*DwarfSeekableStream, &seekable_stream.seekable_stream),
972 @ptrCast(*DwarfInStream, &seekable_stream.stream),
973 );
974 defer efile.close();
975
976 const debug_info = (try efile.findSection(".debug_info")) orelse
977 return error.MissingDebugInfo;
978 const debug_abbrev = (try efile.findSection(".debug_abbrev")) orelse
979 return error.MissingDebugInfo;
980 const debug_str = (try efile.findSection(".debug_str")) orelse
981 return error.MissingDebugInfo;
982 const debug_line = (try efile.findSection(".debug_line")) orelse
983 return error.MissingDebugInfo;
984 const opt_debug_ranges = try efile.findSection(".debug_ranges");
1024985
1025 var di = DwarfInfo{986 var di = DwarfInfo{
1026 .dwarf_seekable_stream = elf_seekable_stream,
1027 .dwarf_in_stream = elf_in_stream,
1028 .endian = efile.endian,987 .endian = efile.endian,
1029 .debug_info = (try findDwarfSectionFromElf(&efile, ".debug_info")) orelse return error.MissingDebugInfo,988 .debug_info = (data[@intCast(usize, debug_info.offset)..@intCast(usize, debug_info.offset + debug_info.size)]),
1030 .debug_abbrev = (try findDwarfSectionFromElf(&efile, ".debug_abbrev")) orelse return error.MissingDebugInfo,989 .debug_abbrev = (data[@intCast(usize, debug_abbrev.offset)..@intCast(usize, debug_abbrev.offset + debug_abbrev.size)]),
1031 .debug_str = (try findDwarfSectionFromElf(&efile, ".debug_str")) orelse return error.MissingDebugInfo,990 .debug_str = (data[@intCast(usize, debug_str.offset)..@intCast(usize, debug_str.offset + debug_str.size)]),
1032 .debug_line = (try findDwarfSectionFromElf(&efile, ".debug_line")) orelse return error.MissingDebugInfo,991 .debug_line = (data[@intCast(usize, debug_line.offset)..@intCast(usize, debug_line.offset + debug_line.size)]),
1033 .debug_ranges = (try findDwarfSectionFromElf(&efile, ".debug_ranges")),992 .debug_ranges = if (opt_debug_ranges) |debug_ranges|
1034 .abbrev_table_list = undefined,993 data[@intCast(usize, debug_ranges.offset)..@intCast(usize, debug_ranges.offset + debug_ranges.size)]
1035 .compile_unit_list = undefined,994 else
1036 .func_list = undefined,995 null,
1037 };996 };
997
998 efile.close();
999
1038 try openDwarfDebugInfo(&di, allocator);1000 try openDwarfDebugInfo(&di, allocator);
1039 return di;1001 return di;
1040}1002}
10411003
1042fn openSelfDebugInfoPosix(allocator: *mem.Allocator) !DwarfInfo {1004fn openSelfDebugInfoPosix(allocator: *mem.Allocator) !DwarfInfo {
1043 const S = struct {1005 var exe_file = try fs.openSelfExe();
1044 var self_exe_file: File = undefined;1006 errdefer exe_file.close();
1045 var self_exe_mmap_seekable: io.SliceSeekableInStream = undefined;
1046 };
1047
1048 S.self_exe_file = try fs.openSelfExe();
1049 errdefer S.self_exe_file.close();
10501007
1051 const self_exe_len = math.cast(usize, try S.self_exe_file.getEndPos()) catch return error.DebugInfoTooLarge;1008 const exe_len = math.cast(usize, try exe_file.getEndPos()) catch
1052 const self_exe_mmap_len = mem.alignForward(self_exe_len, mem.page_size);1009 return error.DebugInfoTooLarge;
1053 const self_exe_mmap = try os.mmap(1010 const exe_mmap = try os.mmap(
1054 null,1011 null,
1055 self_exe_mmap_len,1012 exe_len,
1056 os.PROT_READ,1013 os.PROT_READ,
1057 os.MAP_SHARED,1014 os.MAP_SHARED,
1058 S.self_exe_file.handle,1015 exe_file.handle,
1059 0,1016 0,
1060 );1017 );
1061 errdefer os.munmap(self_exe_mmap);1018 errdefer os.munmap(exe_mmap);
10621019
1063 S.self_exe_mmap_seekable = io.SliceSeekableInStream.init(self_exe_mmap);1020 return openElfDebugInfo(allocator, exe_mmap);
1064
1065 return openElfDebugInfo(
1066 allocator,
1067 // TODO https://github.com/ziglang/zig/issues/764
1068 @ptrCast(*DwarfSeekableStream, &S.self_exe_mmap_seekable.seekable_stream),
1069 // TODO https://github.com/ziglang/zig/issues/764
1070 @ptrCast(*DwarfInStream, &S.self_exe_mmap_seekable.stream),
1071 );
1072}1021}
10731022
1074fn openSelfDebugInfoMacOs(allocator: *mem.Allocator) !DebugInfo {1023fn openSelfDebugInfoMacOs(allocator: *mem.Allocator) !DebugInfo {
...@@ -1195,83 +1144,56 @@ const MachoSymbol = struct {...@@ -1195,83 +1144,56 @@ const MachoSymbol = struct {
1195 }1144 }
1196};1145};
11971146
1198const MachOFile = struct {
1199 bytes: []align(@alignOf(macho.mach_header_64)) const u8,
1200 sect_debug_info: ?*const macho.section_64,
1201 sect_debug_line: ?*const macho.section_64,
1202};
1203
1204pub const DwarfSeekableStream = io.SeekableStream(anyerror, anyerror);1147pub const DwarfSeekableStream = io.SeekableStream(anyerror, anyerror);
1205pub const DwarfInStream = io.InStream(anyerror);1148pub const DwarfInStream = io.InStream(anyerror);
12061149
1207pub const DwarfInfo = struct {1150pub const DwarfInfo = struct {
1208 dwarf_seekable_stream: *DwarfSeekableStream,
1209 dwarf_in_stream: *DwarfInStream,
1210 endian: builtin.Endian,1151 endian: builtin.Endian,
1211 debug_info: Section,1152 // No memory is owned by the DwarfInfo
1212 debug_abbrev: Section,1153 debug_info: []u8,
1213 debug_str: Section,1154 debug_abbrev: []u8,
1214 debug_line: Section,1155 debug_str: []u8,
1215 debug_ranges: ?Section,1156 debug_line: []u8,
1216 abbrev_table_list: ArrayList(AbbrevTableHeader),1157 debug_ranges: ?[]u8,
1217 compile_unit_list: ArrayList(CompileUnit),1158 // Filled later by the initializer
1218 func_list: ArrayList(Func),1159 abbrev_table_list: ArrayList(AbbrevTableHeader) = undefined,
12191160 compile_unit_list: ArrayList(CompileUnit) = undefined,
1220 pub const Section = struct {1161 func_list: ArrayList(Func) = undefined,
1221 offset: u64,
1222 size: u64,
1223 };
12241162
1225 pub fn allocator(self: DwarfInfo) *mem.Allocator {1163 pub fn allocator(self: DwarfInfo) *mem.Allocator {
1226 return self.abbrev_table_list.allocator;1164 return self.abbrev_table_list.allocator;
1227 }1165 }
12281166
1229 pub fn readString(self: *DwarfInfo) ![]u8 {
1230 return readStringRaw(self.allocator(), self.dwarf_in_stream);
1231 }
1232
1233 /// This function works in freestanding mode.1167 /// This function works in freestanding mode.
1234 /// fn printLineFromFile(out_stream: var, line_info: LineInfo) !void1168 /// fn printLineFromFile(out_stream: var, line_info: LineInfo) !void
1235 pub fn printSourceAtAddress(1169 pub fn printSourceAtAddress(
1236 self: *DwarfInfo,1170 self: *DwarfInfo,
1237 out_stream: var,1171 out_stream: var,
1238 address: usize,1172 address: usize,
1239 tty_color: bool,1173 tty_config: TTY.Config,
1240 comptime printLineFromFile: var,1174 comptime printLineFromFile: var,
1241 ) !void {1175 ) !void {
1242 const compile_unit = self.findCompileUnit(address) catch {1176 const compile_unit = self.findCompileUnit(address) catch {
1243 if (tty_color) {1177 return printLineInfo(out_stream, null, address, "???", "???", tty_config, printLineFromFile);
1244 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? (???)" ++ RESET ++ "\n\n\n", .{address});
1245 } else {
1246 try out_stream.print("???:?:?: 0x{x} in ??? (???)\n\n\n", .{address});
1247 }
1248 return;
1249 };1178 };
1179
1250 const compile_unit_name = try compile_unit.die.getAttrString(self, DW.AT_name);1180 const compile_unit_name = try compile_unit.die.getAttrString(self, DW.AT_name);
1251 if (self.getLineNumberInfo(compile_unit.*, address)) |line_info| {1181 const symbol_name = self.getSymbolName(address) orelse "???";
1252 defer line_info.deinit();1182 const line_info = self.getLineNumberInfo(compile_unit.*, address) catch |err| switch (err) {
1253 const symbol_name = self.getSymbolName(address) orelse "???";1183 error.MissingDebugInfo, error.InvalidDebugInfo => null,
1254 try printLineInfo(
1255 out_stream,
1256 line_info,
1257 address,
1258 symbol_name,
1259 compile_unit_name,
1260 tty_color,
1261 printLineFromFile,
1262 );
1263 } else |err| switch (err) {
1264 error.MissingDebugInfo, error.InvalidDebugInfo => {
1265 if (tty_color) {
1266 try out_stream.print("???:?:?: " ++ DIM ++ "0x{x} in ??? ({})" ++ RESET ++ "\n\n\n", .{
1267 address, compile_unit_name,
1268 });
1269 } else {
1270 try out_stream.print("???:?:?: 0x{x} in ??? ({})\n\n\n", .{ address, compile_unit_name });
1271 }
1272 },
1273 else => return err,1184 else => return err,
1274 }1185 };
1186 defer if (line_info) |li| li.deinit();
1187
1188 try printLineInfo(
1189 out_stream,
1190 line_info,
1191 address,
1192 symbol_name,
1193 compile_unit_name,
1194 tty_config,
1195 printLineFromFile,
1196 );
1275 }1197 }
12761198
1277 fn getSymbolName(di: *DwarfInfo, address: u64) ?[]const u8 {1199 fn getSymbolName(di: *DwarfInfo, address: u64) ?[]const u8 {
...@@ -1287,35 +1209,38 @@ pub const DwarfInfo = struct {...@@ -1287,35 +1209,38 @@ pub const DwarfInfo = struct {
1287 }1209 }
12881210
1289 fn scanAllFunctions(di: *DwarfInfo) !void {1211 fn scanAllFunctions(di: *DwarfInfo) !void {
1290 const debug_info_end = di.debug_info.offset + di.debug_info.size;1212 var s = io.SliceSeekableInStream.init(di.debug_info);
1291 var this_unit_offset = di.debug_info.offset;1213 var this_unit_offset: u64 = 0;
12921214
1293 while (this_unit_offset < debug_info_end) {1215 while (true) {
1294 try di.dwarf_seekable_stream.seekTo(this_unit_offset);1216 s.seekable_stream.seekTo(this_unit_offset) catch |err| switch (err) {
1217 error.EndOfStream => return,
1218 else => return err,
1219 };
12951220
1296 var is_64: bool = undefined;1221 var is_64: bool = undefined;
1297 const unit_length = try readInitialLength(@TypeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);1222 const unit_length = try readInitialLength(@TypeOf(s.stream.readFn).ReturnType.ErrorSet, &s.stream, &is_64);
1298 if (unit_length == 0) return;1223 if (unit_length == 0) return;
1299 const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));1224 const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
13001225
1301 const version = try di.dwarf_in_stream.readInt(u16, di.endian);1226 const version = try s.stream.readInt(u16, di.endian);
1302 if (version < 2 or version > 5) return error.InvalidDebugInfo;1227 if (version < 2 or version > 5) return error.InvalidDebugInfo;
13031228
1304 const debug_abbrev_offset = if (is_64) try di.dwarf_in_stream.readInt(u64, di.endian) else try di.dwarf_in_stream.readInt(u32, di.endian);1229 const debug_abbrev_offset = if (is_64) try s.stream.readInt(u64, di.endian) else try s.stream.readInt(u32, di.endian);
13051230
1306 const address_size = try di.dwarf_in_stream.readByte();1231 const address_size = try s.stream.readByte();
1307 if (address_size != @sizeOf(usize)) return error.InvalidDebugInfo;1232 if (address_size != @sizeOf(usize)) return error.InvalidDebugInfo;
13081233
1309 const compile_unit_pos = try di.dwarf_seekable_stream.getPos();1234 const compile_unit_pos = try s.seekable_stream.getPos();
1310 const abbrev_table = try di.getAbbrevTable(debug_abbrev_offset);1235 const abbrev_table = try di.getAbbrevTable(debug_abbrev_offset);
13111236
1312 try di.dwarf_seekable_stream.seekTo(compile_unit_pos);1237 try s.seekable_stream.seekTo(compile_unit_pos);
13131238
1314 const next_unit_pos = this_unit_offset + next_offset;1239 const next_unit_pos = this_unit_offset + next_offset;
13151240
1316 while ((try di.dwarf_seekable_stream.getPos()) < next_unit_pos) {1241 while ((try s.seekable_stream.getPos()) < next_unit_pos) {
1317 const die_obj = (try di.parseDie(abbrev_table, is_64)) orelse continue;1242 const die_obj = (try di.parseDie(&s.stream, abbrev_table, is_64)) orelse continue;
1318 const after_die_offset = try di.dwarf_seekable_stream.getPos();1243 const after_die_offset = try s.seekable_stream.getPos();
13191244
1320 switch (die_obj.tag_id) {1245 switch (die_obj.tag_id) {
1321 DW.TAG_subprogram, DW.TAG_inlined_subroutine, DW.TAG_subroutine, DW.TAG_entry_point => {1246 DW.TAG_subprogram, DW.TAG_inlined_subroutine, DW.TAG_subroutine, DW.TAG_entry_point => {
...@@ -1331,14 +1256,14 @@ pub const DwarfInfo = struct {...@@ -1331,14 +1256,14 @@ pub const DwarfInfo = struct {
1331 // Follow the DIE it points to and repeat1256 // Follow the DIE it points to and repeat
1332 const ref_offset = try this_die_obj.getAttrRef(DW.AT_abstract_origin);1257 const ref_offset = try this_die_obj.getAttrRef(DW.AT_abstract_origin);
1333 if (ref_offset > next_offset) return error.InvalidDebugInfo;1258 if (ref_offset > next_offset) return error.InvalidDebugInfo;
1334 try di.dwarf_seekable_stream.seekTo(this_unit_offset + ref_offset);1259 try s.seekable_stream.seekTo(this_unit_offset + ref_offset);
1335 this_die_obj = (try di.parseDie(abbrev_table, is_64)) orelse return error.InvalidDebugInfo;1260 this_die_obj = (try di.parseDie(&s.stream, abbrev_table, is_64)) orelse return error.InvalidDebugInfo;
1336 } else if (this_die_obj.getAttr(DW.AT_specification)) |ref| {1261 } else if (this_die_obj.getAttr(DW.AT_specification)) |ref| {
1337 // Follow the DIE it points to and repeat1262 // Follow the DIE it points to and repeat
1338 const ref_offset = try this_die_obj.getAttrRef(DW.AT_specification);1263 const ref_offset = try this_die_obj.getAttrRef(DW.AT_specification);
1339 if (ref_offset > next_offset) return error.InvalidDebugInfo;1264 if (ref_offset > next_offset) return error.InvalidDebugInfo;
1340 try di.dwarf_seekable_stream.seekTo(this_unit_offset + ref_offset);1265 try s.seekable_stream.seekTo(this_unit_offset + ref_offset);
1341 this_die_obj = (try di.parseDie(abbrev_table, is_64)) orelse return error.InvalidDebugInfo;1266 this_die_obj = (try di.parseDie(&s.stream, abbrev_table, is_64)) orelse return error.InvalidDebugInfo;
1342 } else {1267 } else {
1343 break :x null;1268 break :x null;
1344 }1269 }
...@@ -1376,12 +1301,10 @@ pub const DwarfInfo = struct {...@@ -1376,12 +1301,10 @@ pub const DwarfInfo = struct {
1376 .pc_range = pc_range,1301 .pc_range = pc_range,
1377 });1302 });
1378 },1303 },
1379 else => {1304 else => {},
1380 continue;
1381 },
1382 }1305 }
13831306
1384 try di.dwarf_seekable_stream.seekTo(after_die_offset);1307 try s.seekable_stream.seekTo(after_die_offset);
1385 }1308 }
13861309
1387 this_unit_offset += next_offset;1310 this_unit_offset += next_offset;
...@@ -1389,32 +1312,35 @@ pub const DwarfInfo = struct {...@@ -1389,32 +1312,35 @@ pub const DwarfInfo = struct {
1389 }1312 }
13901313
1391 fn scanAllCompileUnits(di: *DwarfInfo) !void {1314 fn scanAllCompileUnits(di: *DwarfInfo) !void {
1392 const debug_info_end = di.debug_info.offset + di.debug_info.size;1315 var s = io.SliceSeekableInStream.init(di.debug_info);
1393 var this_unit_offset = di.debug_info.offset;1316 var this_unit_offset: u64 = 0;
13941317
1395 while (this_unit_offset < debug_info_end) {1318 while (true) {
1396 try di.dwarf_seekable_stream.seekTo(this_unit_offset);1319 s.seekable_stream.seekTo(this_unit_offset) catch |err| switch (err) {
1320 error.EndOfStream => return,
1321 else => return err,
1322 };
13971323
1398 var is_64: bool = undefined;1324 var is_64: bool = undefined;
1399 const unit_length = try readInitialLength(@TypeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);1325 const unit_length = try readInitialLength(@TypeOf(s.stream.readFn).ReturnType.ErrorSet, &s.stream, &is_64);
1400 if (unit_length == 0) return;1326 if (unit_length == 0) return;
1401 const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));1327 const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
14021328
1403 const version = try di.dwarf_in_stream.readInt(u16, di.endian);1329 const version = try s.stream.readInt(u16, di.endian);
1404 if (version < 2 or version > 5) return error.InvalidDebugInfo;1330 if (version < 2 or version > 5) return error.InvalidDebugInfo;
14051331
1406 const debug_abbrev_offset = if (is_64) try di.dwarf_in_stream.readInt(u64, di.endian) else try di.dwarf_in_stream.readInt(u32, di.endian);1332 const debug_abbrev_offset = if (is_64) try s.stream.readInt(u64, di.endian) else try s.stream.readInt(u32, di.endian);
14071333
1408 const address_size = try di.dwarf_in_stream.readByte();1334 const address_size = try s.stream.readByte();
1409 if (address_size != @sizeOf(usize)) return error.InvalidDebugInfo;1335 if (address_size != @sizeOf(usize)) return error.InvalidDebugInfo;
14101336
1411 const compile_unit_pos = try di.dwarf_seekable_stream.getPos();1337 const compile_unit_pos = try s.seekable_stream.getPos();
1412 const abbrev_table = try di.getAbbrevTable(debug_abbrev_offset);1338 const abbrev_table = try di.getAbbrevTable(debug_abbrev_offset);
14131339
1414 try di.dwarf_seekable_stream.seekTo(compile_unit_pos);1340 try s.seekable_stream.seekTo(compile_unit_pos);
14151341
1416 const compile_unit_die = try di.allocator().create(Die);1342 const compile_unit_die = try di.allocator().create(Die);
1417 compile_unit_die.* = (try di.parseDie(abbrev_table, is_64)) orelse return error.InvalidDebugInfo;1343 compile_unit_die.* = (try di.parseDie(&s.stream, abbrev_table, is_64)) orelse return error.InvalidDebugInfo;
14181344
1419 if (compile_unit_die.tag_id != DW.TAG_compile_unit) return error.InvalidDebugInfo;1345 if (compile_unit_die.tag_id != DW.TAG_compile_unit) return error.InvalidDebugInfo;
14201346
...@@ -1458,28 +1384,38 @@ pub const DwarfInfo = struct {...@@ -1458,28 +1384,38 @@ pub const DwarfInfo = struct {
1458 if (compile_unit.pc_range) |range| {1384 if (compile_unit.pc_range) |range| {
1459 if (target_address >= range.start and target_address < range.end) return compile_unit;1385 if (target_address >= range.start and target_address < range.end) return compile_unit;
1460 }1386 }
1461 if (compile_unit.die.getAttrSecOffset(DW.AT_ranges)) |ranges_offset| {1387 if (di.debug_ranges) |debug_ranges| {
1462 var base_address: usize = 0;1388 if (compile_unit.die.getAttrSecOffset(DW.AT_ranges)) |ranges_offset| {
1463 if (di.debug_ranges) |debug_ranges| {1389 var s = io.SliceSeekableInStream.init(debug_ranges);
1464 try di.dwarf_seekable_stream.seekTo(debug_ranges.offset + ranges_offset);1390
1391 // All the addresses in the list are relative to the value
1392 // specified by DW_AT_low_pc or to some other value encoded
1393 // in the list itself
1394 var base_address = try compile_unit.die.getAttrAddr(DW.AT_low_pc);
1395
1396 try s.seekable_stream.seekTo(ranges_offset);
1397
1465 while (true) {1398 while (true) {
1466 const begin_addr = try di.dwarf_in_stream.readIntLittle(usize);1399 const begin_addr = try s.stream.readIntLittle(usize);
1467 const end_addr = try di.dwarf_in_stream.readIntLittle(usize);1400 const end_addr = try s.stream.readIntLittle(usize);
1468 if (begin_addr == 0 and end_addr == 0) {1401 if (begin_addr == 0 and end_addr == 0) {
1469 break;1402 break;
1470 }1403 }
1404 // This entry selects a new value for the base address
1471 if (begin_addr == maxInt(usize)) {1405 if (begin_addr == maxInt(usize)) {
1472 base_address = begin_addr;1406 base_address = end_addr;
1473 continue;1407 continue;
1474 }1408 }
1475 if (target_address >= begin_addr and target_address < end_addr) {1409 if (target_address >= base_address + begin_addr and target_address < base_address + end_addr) {
1476 return compile_unit;1410 return compile_unit;
1477 }1411 }
1478 }1412 }
1413
1414 return error.InvalidDebugInfo;
1415 } else |err| {
1416 if (err != error.MissingDebugInfo) return err;
1417 continue;
1479 }1418 }
1480 } else |err| {
1481 if (err != error.MissingDebugInfo) return err;
1482 continue;
1483 }1419 }
1484 }1420 }
1485 return error.MissingDebugInfo;1421 return error.MissingDebugInfo;
...@@ -1493,30 +1429,33 @@ pub const DwarfInfo = struct {...@@ -1493,30 +1429,33 @@ pub const DwarfInfo = struct {
1493 return &header.table;1429 return &header.table;
1494 }1430 }
1495 }1431 }
1496 try di.dwarf_seekable_stream.seekTo(di.debug_abbrev.offset + abbrev_offset);
1497 try di.abbrev_table_list.append(AbbrevTableHeader{1432 try di.abbrev_table_list.append(AbbrevTableHeader{
1498 .offset = abbrev_offset,1433 .offset = abbrev_offset,
1499 .table = try di.parseAbbrevTable(),1434 .table = try di.parseAbbrevTable(abbrev_offset),
1500 });1435 });
1501 return &di.abbrev_table_list.items[di.abbrev_table_list.len - 1].table;1436 return &di.abbrev_table_list.items[di.abbrev_table_list.len - 1].table;
1502 }1437 }
15031438
1504 fn parseAbbrevTable(di: *DwarfInfo) !AbbrevTable {1439 fn parseAbbrevTable(di: *DwarfInfo, offset: u64) !AbbrevTable {
1440 var s = io.SliceSeekableInStream.init(di.debug_abbrev);
1441
1442 try s.seekable_stream.seekTo(offset);
1505 var result = AbbrevTable.init(di.allocator());1443 var result = AbbrevTable.init(di.allocator());
1444 errdefer result.deinit();
1506 while (true) {1445 while (true) {
1507 const abbrev_code = try leb.readULEB128(u64, di.dwarf_in_stream);1446 const abbrev_code = try leb.readULEB128(u64, &s.stream);
1508 if (abbrev_code == 0) return result;1447 if (abbrev_code == 0) return result;
1509 try result.append(AbbrevTableEntry{1448 try result.append(AbbrevTableEntry{
1510 .abbrev_code = abbrev_code,1449 .abbrev_code = abbrev_code,
1511 .tag_id = try leb.readULEB128(u64, di.dwarf_in_stream),1450 .tag_id = try leb.readULEB128(u64, &s.stream),
1512 .has_children = (try di.dwarf_in_stream.readByte()) == DW.CHILDREN_yes,1451 .has_children = (try s.stream.readByte()) == DW.CHILDREN_yes,
1513 .attrs = ArrayList(AbbrevAttr).init(di.allocator()),1452 .attrs = ArrayList(AbbrevAttr).init(di.allocator()),
1514 });1453 });
1515 const attrs = &result.items[result.len - 1].attrs;1454 const attrs = &result.items[result.len - 1].attrs;
15161455
1517 while (true) {1456 while (true) {
1518 const attr_id = try leb.readULEB128(u64, di.dwarf_in_stream);1457 const attr_id = try leb.readULEB128(u64, &s.stream);
1519 const form_id = try leb.readULEB128(u64, di.dwarf_in_stream);1458 const form_id = try leb.readULEB128(u64, &s.stream);
1520 if (attr_id == 0 and form_id == 0) break;1459 if (attr_id == 0 and form_id == 0) break;
1521 try attrs.append(AbbrevAttr{1460 try attrs.append(AbbrevAttr{
1522 .attr_id = attr_id,1461 .attr_id = attr_id,
...@@ -1526,8 +1465,8 @@ pub const DwarfInfo = struct {...@@ -1526,8 +1465,8 @@ pub const DwarfInfo = struct {
1526 }1465 }
1527 }1466 }
15281467
1529 fn parseDie(di: *DwarfInfo, abbrev_table: *const AbbrevTable, is_64: bool) !?Die {1468 fn parseDie(di: *DwarfInfo, in_stream: var, abbrev_table: *const AbbrevTable, is_64: bool) !?Die {
1530 const abbrev_code = try leb.readULEB128(u64, di.dwarf_in_stream);1469 const abbrev_code = try leb.readULEB128(u64, in_stream);
1531 if (abbrev_code == 0) return null;1470 if (abbrev_code == 0) return null;
1532 const table_entry = getAbbrevTableEntry(abbrev_table, abbrev_code) orelse return error.InvalidDebugInfo;1471 const table_entry = getAbbrevTableEntry(abbrev_table, abbrev_code) orelse return error.InvalidDebugInfo;
15331472
...@@ -1540,63 +1479,63 @@ pub const DwarfInfo = struct {...@@ -1540,63 +1479,63 @@ pub const DwarfInfo = struct {
1540 for (table_entry.attrs.toSliceConst()) |attr, i| {1479 for (table_entry.attrs.toSliceConst()) |attr, i| {
1541 result.attrs.items[i] = Die.Attr{1480 result.attrs.items[i] = Die.Attr{
1542 .id = attr.attr_id,1481 .id = attr.attr_id,
1543 .value = try parseFormValue(di.allocator(), di.dwarf_in_stream, attr.form_id, is_64),1482 .value = try parseFormValue(di.allocator(), in_stream, attr.form_id, is_64),
1544 };1483 };
1545 }1484 }
1546 return result;1485 return result;
1547 }1486 }
15481487
1549 fn getLineNumberInfo(di: *DwarfInfo, compile_unit: CompileUnit, target_address: usize) !LineInfo {1488 fn getLineNumberInfo(di: *DwarfInfo, compile_unit: CompileUnit, target_address: usize) !LineInfo {
1489 var s = io.SliceSeekableInStream.init(di.debug_line);
1490
1550 const compile_unit_cwd = try compile_unit.die.getAttrString(di, DW.AT_comp_dir);1491 const compile_unit_cwd = try compile_unit.die.getAttrString(di, DW.AT_comp_dir);
1551 const line_info_offset = try compile_unit.die.getAttrSecOffset(DW.AT_stmt_list);1492 const line_info_offset = try compile_unit.die.getAttrSecOffset(DW.AT_stmt_list);
15521493
1553 assert(line_info_offset < di.debug_line.size);1494 try s.seekable_stream.seekTo(line_info_offset);
1554
1555 try di.dwarf_seekable_stream.seekTo(di.debug_line.offset + line_info_offset);
15561495
1557 var is_64: bool = undefined;1496 var is_64: bool = undefined;
1558 const unit_length = try readInitialLength(@TypeOf(di.dwarf_in_stream.readFn).ReturnType.ErrorSet, di.dwarf_in_stream, &is_64);1497 const unit_length = try readInitialLength(@TypeOf(s.stream.readFn).ReturnType.ErrorSet, &s.stream, &is_64);
1559 if (unit_length == 0) {1498 if (unit_length == 0) {
1560 return error.MissingDebugInfo;1499 return error.MissingDebugInfo;
1561 }1500 }
1562 const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));1501 const next_offset = unit_length + (if (is_64) @as(usize, 12) else @as(usize, 4));
15631502
1564 const version = try di.dwarf_in_stream.readInt(u16, di.endian);1503 const version = try s.stream.readInt(u16, di.endian);
1565 // TODO support 3 and 51504 // TODO support 3 and 5
1566 if (version != 2 and version != 4) return error.InvalidDebugInfo;1505 if (version != 2 and version != 4) return error.InvalidDebugInfo;
15671506
1568 const prologue_length = if (is_64) try di.dwarf_in_stream.readInt(u64, di.endian) else try di.dwarf_in_stream.readInt(u32, di.endian);1507 const prologue_length = if (is_64) try s.stream.readInt(u64, di.endian) else try s.stream.readInt(u32, di.endian);
1569 const prog_start_offset = (try di.dwarf_seekable_stream.getPos()) + prologue_length;1508 const prog_start_offset = (try s.seekable_stream.getPos()) + prologue_length;
15701509
1571 const minimum_instruction_length = try di.dwarf_in_stream.readByte();1510 const minimum_instruction_length = try s.stream.readByte();
1572 if (minimum_instruction_length == 0) return error.InvalidDebugInfo;1511 if (minimum_instruction_length == 0) return error.InvalidDebugInfo;
15731512
1574 if (version >= 4) {1513 if (version >= 4) {
1575 // maximum_operations_per_instruction1514 // maximum_operations_per_instruction
1576 _ = try di.dwarf_in_stream.readByte();1515 _ = try s.stream.readByte();
1577 }1516 }
15781517
1579 const default_is_stmt = (try di.dwarf_in_stream.readByte()) != 0;1518 const default_is_stmt = (try s.stream.readByte()) != 0;
1580 const line_base = try di.dwarf_in_stream.readByteSigned();1519 const line_base = try s.stream.readByteSigned();
15811520
1582 const line_range = try di.dwarf_in_stream.readByte();1521 const line_range = try s.stream.readByte();
1583 if (line_range == 0) return error.InvalidDebugInfo;1522 if (line_range == 0) return error.InvalidDebugInfo;
15841523
1585 const opcode_base = try di.dwarf_in_stream.readByte();1524 const opcode_base = try s.stream.readByte();
15861525
1587 const standard_opcode_lengths = try di.allocator().alloc(u8, opcode_base - 1);1526 const standard_opcode_lengths = try di.allocator().alloc(u8, opcode_base - 1);
15881527
1589 {1528 {
1590 var i: usize = 0;1529 var i: usize = 0;
1591 while (i < opcode_base - 1) : (i += 1) {1530 while (i < opcode_base - 1) : (i += 1) {
1592 standard_opcode_lengths[i] = try di.dwarf_in_stream.readByte();1531 standard_opcode_lengths[i] = try s.stream.readByte();
1593 }1532 }
1594 }1533 }
15951534
1596 var include_directories = ArrayList([]u8).init(di.allocator());1535 var include_directories = ArrayList([]u8).init(di.allocator());
1597 try include_directories.append(compile_unit_cwd);1536 try include_directories.append(compile_unit_cwd);
1598 while (true) {1537 while (true) {
1599 const dir = try di.readString();1538 const dir = try readStringRaw(di.allocator(), &s.stream);
1600 if (dir.len == 0) break;1539 if (dir.len == 0) break;
1601 try include_directories.append(dir);1540 try include_directories.append(dir);
1602 }1541 }
...@@ -1605,11 +1544,11 @@ pub const DwarfInfo = struct {...@@ -1605,11 +1544,11 @@ pub const DwarfInfo = struct {
1605 var prog = LineNumberProgram.init(default_is_stmt, include_directories.toSliceConst(), &file_entries, target_address);1544 var prog = LineNumberProgram.init(default_is_stmt, include_directories.toSliceConst(), &file_entries, target_address);
16061545
1607 while (true) {1546 while (true) {
1608 const file_name = try di.readString();1547 const file_name = try readStringRaw(di.allocator(), &s.stream);
1609 if (file_name.len == 0) break;1548 if (file_name.len == 0) break;
1610 const dir_index = try leb.readULEB128(usize, di.dwarf_in_stream);1549 const dir_index = try leb.readULEB128(usize, &s.stream);
1611 const mtime = try leb.readULEB128(usize, di.dwarf_in_stream);1550 const mtime = try leb.readULEB128(usize, &s.stream);
1612 const len_bytes = try leb.readULEB128(usize, di.dwarf_in_stream);1551 const len_bytes = try leb.readULEB128(usize, &s.stream);
1613 try file_entries.append(FileEntry{1552 try file_entries.append(FileEntry{
1614 .file_name = file_name,1553 .file_name = file_name,
1615 .dir_index = dir_index,1554 .dir_index = dir_index,
...@@ -1618,30 +1557,32 @@ pub const DwarfInfo = struct {...@@ -1618,30 +1557,32 @@ pub const DwarfInfo = struct {
1618 });1557 });
1619 }1558 }
16201559
1621 try di.dwarf_seekable_stream.seekTo(prog_start_offset);1560 try s.seekable_stream.seekTo(prog_start_offset);
16221561
1623 while (true) {1562 const next_unit_pos = line_info_offset + next_offset;
1624 const opcode = try di.dwarf_in_stream.readByte();1563
1564 while ((try s.seekable_stream.getPos()) < next_unit_pos) {
1565 const opcode = try s.stream.readByte();
16251566
1626 if (opcode == DW.LNS_extended_op) {1567 if (opcode == DW.LNS_extended_op) {
1627 const op_size = try leb.readULEB128(u64, di.dwarf_in_stream);1568 const op_size = try leb.readULEB128(u64, &s.stream);
1628 if (op_size < 1) return error.InvalidDebugInfo;1569 if (op_size < 1) return error.InvalidDebugInfo;
1629 var sub_op = try di.dwarf_in_stream.readByte();1570 var sub_op = try s.stream.readByte();
1630 switch (sub_op) {1571 switch (sub_op) {
1631 DW.LNE_end_sequence => {1572 DW.LNE_end_sequence => {
1632 prog.end_sequence = true;1573 prog.end_sequence = true;
1633 if (try prog.checkLineMatch()) |info| return info;1574 if (try prog.checkLineMatch()) |info| return info;
1634 return error.MissingDebugInfo;1575 prog.reset();
1635 },1576 },
1636 DW.LNE_set_address => {1577 DW.LNE_set_address => {
1637 const addr = try di.dwarf_in_stream.readInt(usize, di.endian);1578 const addr = try s.stream.readInt(usize, di.endian);
1638 prog.address = addr;1579 prog.address = addr;
1639 },1580 },
1640 DW.LNE_define_file => {1581 DW.LNE_define_file => {
1641 const file_name = try di.readString();1582 const file_name = try readStringRaw(di.allocator(), &s.stream);
1642 const dir_index = try leb.readULEB128(usize, di.dwarf_in_stream);1583 const dir_index = try leb.readULEB128(usize, &s.stream);
1643 const mtime = try leb.readULEB128(usize, di.dwarf_in_stream);1584 const mtime = try leb.readULEB128(usize, &s.stream);
1644 const len_bytes = try leb.readULEB128(usize, di.dwarf_in_stream);1585 const len_bytes = try leb.readULEB128(usize, &s.stream);
1645 try file_entries.append(FileEntry{1586 try file_entries.append(FileEntry{
1646 .file_name = file_name,1587 .file_name = file_name,
1647 .dir_index = dir_index,1588 .dir_index = dir_index,
...@@ -1651,7 +1592,7 @@ pub const DwarfInfo = struct {...@@ -1651,7 +1592,7 @@ pub const DwarfInfo = struct {
1651 },1592 },
1652 else => {1593 else => {
1653 const fwd_amt = math.cast(isize, op_size - 1) catch return error.InvalidDebugInfo;1594 const fwd_amt = math.cast(isize, op_size - 1) catch return error.InvalidDebugInfo;
1654 try di.dwarf_seekable_stream.seekBy(fwd_amt);1595 try s.seekable_stream.seekBy(fwd_amt);
1655 },1596 },
1656 }1597 }
1657 } else if (opcode >= opcode_base) {1598 } else if (opcode >= opcode_base) {
...@@ -1670,19 +1611,19 @@ pub const DwarfInfo = struct {...@@ -1670,19 +1611,19 @@ pub const DwarfInfo = struct {
1670 prog.basic_block = false;1611 prog.basic_block = false;
1671 },1612 },
1672 DW.LNS_advance_pc => {1613 DW.LNS_advance_pc => {
1673 const arg = try leb.readULEB128(usize, di.dwarf_in_stream);1614 const arg = try leb.readULEB128(usize, &s.stream);
1674 prog.address += arg * minimum_instruction_length;1615 prog.address += arg * minimum_instruction_length;
1675 },1616 },
1676 DW.LNS_advance_line => {1617 DW.LNS_advance_line => {
1677 const arg = try leb.readILEB128(i64, di.dwarf_in_stream);1618 const arg = try leb.readILEB128(i64, &s.stream);
1678 prog.line += arg;1619 prog.line += arg;
1679 },1620 },
1680 DW.LNS_set_file => {1621 DW.LNS_set_file => {
1681 const arg = try leb.readULEB128(usize, di.dwarf_in_stream);1622 const arg = try leb.readULEB128(usize, &s.stream);
1682 prog.file = arg;1623 prog.file = arg;
1683 },1624 },
1684 DW.LNS_set_column => {1625 DW.LNS_set_column => {
1685 const arg = try leb.readULEB128(u64, di.dwarf_in_stream);1626 const arg = try leb.readULEB128(u64, &s.stream);
1686 prog.column = arg;1627 prog.column = arg;
1687 },1628 },
1688 DW.LNS_negate_stmt => {1629 DW.LNS_negate_stmt => {
...@@ -1696,14 +1637,14 @@ pub const DwarfInfo = struct {...@@ -1696,14 +1637,14 @@ pub const DwarfInfo = struct {
1696 prog.address += inc_addr;1637 prog.address += inc_addr;
1697 },1638 },
1698 DW.LNS_fixed_advance_pc => {1639 DW.LNS_fixed_advance_pc => {
1699 const arg = try di.dwarf_in_stream.readInt(u16, di.endian);1640 const arg = try s.stream.readInt(u16, di.endian);
1700 prog.address += arg;1641 prog.address += arg;
1701 },1642 },
1702 DW.LNS_set_prologue_end => {},1643 DW.LNS_set_prologue_end => {},
1703 else => {1644 else => {
1704 if (opcode - 1 >= standard_opcode_lengths.len) return error.InvalidDebugInfo;1645 if (opcode - 1 >= standard_opcode_lengths.len) return error.InvalidDebugInfo;
1705 const len_bytes = standard_opcode_lengths[opcode - 1];1646 const len_bytes = standard_opcode_lengths[opcode - 1];
1706 try di.dwarf_seekable_stream.seekBy(len_bytes);1647 try s.seekable_stream.seekBy(len_bytes);
1707 },1648 },
1708 }1649 }
1709 }1650 }
...@@ -1713,9 +1654,17 @@ pub const DwarfInfo = struct {...@@ -1713,9 +1654,17 @@ pub const DwarfInfo = struct {
1713 }1654 }
17141655
1715 fn getString(di: *DwarfInfo, offset: u64) ![]u8 {1656 fn getString(di: *DwarfInfo, offset: u64) ![]u8 {
1716 const pos = di.debug_str.offset + offset;1657 if (offset > di.debug_str.len)
1717 try di.dwarf_seekable_stream.seekTo(pos);1658 return error.InvalidDebugInfo;
1718 return di.readString();1659 const casted_offset = math.cast(usize, offset) catch
1660 return error.InvalidDebugInfo;
1661
1662 // Valid strings always have a terminating zero byte
1663 if (mem.indexOfScalarPos(u8, di.debug_str, casted_offset, 0)) |last| {
1664 return di.debug_str[casted_offset..last];
1665 }
1666
1667 return error.InvalidDebugInfo;
1719 }1668 }
1720};1669};
17211670
...@@ -1727,7 +1676,7 @@ pub const DebugInfo = switch (builtin.os) {...@@ -1727,7 +1676,7 @@ pub const DebugInfo = switch (builtin.os) {
17271676
1728 const OFileTable = std.HashMap(1677 const OFileTable = std.HashMap(
1729 *macho.nlist_64,1678 *macho.nlist_64,
1730 MachOFile,1679 DwarfInfo,
1731 std.hash_map.getHashPtrAddrFn(*macho.nlist_64),1680 std.hash_map.getHashPtrAddrFn(*macho.nlist_64),
1732 std.hash_map.getTrivialEqlFn(*macho.nlist_64),1681 std.hash_map.getTrivialEqlFn(*macho.nlist_64),
1733 );1682 );
...@@ -1888,6 +1837,7 @@ const LineNumberProgram = struct {...@@ -1888,6 +1837,7 @@ const LineNumberProgram = struct {
1888 basic_block: bool,1837 basic_block: bool,
1889 end_sequence: bool,1838 end_sequence: bool,
18901839
1840 default_is_stmt: bool,
1891 target_address: usize,1841 target_address: usize,
1892 include_dirs: []const []const u8,1842 include_dirs: []const []const u8,
1893 file_entries: *ArrayList(FileEntry),1843 file_entries: *ArrayList(FileEntry),
...@@ -1900,6 +1850,25 @@ const LineNumberProgram = struct {...@@ -1900,6 +1850,25 @@ const LineNumberProgram = struct {
1900 prev_basic_block: bool,1850 prev_basic_block: bool,
1901 prev_end_sequence: bool,1851 prev_end_sequence: bool,
19021852
1853 // Reset the state machine following the DWARF specification
1854 pub fn reset(self: *LineNumberProgram) void {
1855 self.address = 0;
1856 self.file = 1;
1857 self.line = 1;
1858 self.column = 0;
1859 self.is_stmt = self.default_is_stmt;
1860 self.basic_block = false;
1861 self.end_sequence = false;
1862 // Invalidate all the remaining fields
1863 self.prev_address = 0;
1864 self.prev_file = undefined;
1865 self.prev_line = undefined;
1866 self.prev_column = undefined;
1867 self.prev_is_stmt = undefined;
1868 self.prev_basic_block = undefined;
1869 self.prev_end_sequence = undefined;
1870 }
1871
1903 pub fn init(is_stmt: bool, include_dirs: []const []const u8, file_entries: *ArrayList(FileEntry), target_address: usize) LineNumberProgram {1872 pub fn init(is_stmt: bool, include_dirs: []const []const u8, file_entries: *ArrayList(FileEntry), target_address: usize) LineNumberProgram {
1904 return LineNumberProgram{1873 return LineNumberProgram{
1905 .address = 0,1874 .address = 0,
...@@ -1911,6 +1880,7 @@ const LineNumberProgram = struct {...@@ -1911,6 +1880,7 @@ const LineNumberProgram = struct {
1911 .end_sequence = false,1880 .end_sequence = false,
1912 .include_dirs = include_dirs,1881 .include_dirs = include_dirs,
1913 .file_entries = file_entries,1882 .file_entries = file_entries,
1883 .default_is_stmt = is_stmt,
1914 .target_address = target_address,1884 .target_address = target_address,
1915 .prev_address = 0,1885 .prev_address = 0,
1916 .prev_file = undefined,1886 .prev_file = undefined,
...@@ -2100,24 +2070,32 @@ fn getAbbrevTableEntry(abbrev_table: *const AbbrevTable, abbrev_code: u64) ?*con...@@ -2100,24 +2070,32 @@ fn getAbbrevTableEntry(abbrev_table: *const AbbrevTable, abbrev_code: u64) ?*con
2100 return null;2070 return null;
2101}2071}
21022072
2103fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: usize) !LineInfo {2073fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, address: usize) !LineInfo {
2104 const ofile = symbol.ofile orelse return error.MissingDebugInfo;2074 const ofile = symbol.ofile orelse return error.MissingDebugInfo;
2105 const gop = try di.ofiles.getOrPut(ofile);2075 const gop = try di.ofiles.getOrPut(ofile);
2106 const mach_o_file = if (gop.found_existing) &gop.kv.value else blk: {2076 const dwarf_info = if (gop.found_existing) &gop.kv.value else blk: {
2107 errdefer _ = di.ofiles.remove(ofile);2077 errdefer _ = di.ofiles.remove(ofile);
2108 const ofile_path = mem.toSliceConst(u8, @ptrCast([*:0]const u8, di.strings.ptr + ofile.n_strx));2078 const ofile_path = mem.toSliceConst(u8, @ptrCast([*:0]const u8, di.strings.ptr + ofile.n_strx));
21092079
2110 gop.kv.value = MachOFile{2080 var exe_file = try std.fs.openFileAbsoluteC(ofile_path, .{});
2111 .bytes = try std.fs.cwd().readFileAllocAligned(2081 errdefer exe_file.close();
2112 di.ofiles.allocator,2082
2113 ofile_path,2083 const exe_len = math.cast(usize, try exe_file.getEndPos()) catch
2114 maxInt(usize),2084 return error.DebugInfoTooLarge;
2115 @alignOf(macho.mach_header_64),2085 const exe_mmap = try os.mmap(
2116 ),2086 null,
2117 .sect_debug_info = null,2087 exe_len,
2118 .sect_debug_line = null,2088 os.PROT_READ,
2119 };2089 os.MAP_SHARED,
2120 const hdr = @ptrCast(*const macho.mach_header_64, gop.kv.value.bytes.ptr);2090 exe_file.handle,
2091 0,
2092 );
2093 errdefer os.munmap(exe_mmap);
2094
2095 const hdr = @ptrCast(
2096 *const macho.mach_header_64,
2097 @alignCast(@alignOf(macho.mach_header_64), exe_mmap.ptr),
2098 );
2121 if (hdr.magic != std.macho.MH_MAGIC_64) return error.InvalidDebugInfo;2099 if (hdr.magic != std.macho.MH_MAGIC_64) return error.InvalidDebugInfo;
21222100
2123 const hdr_base = @ptrCast([*]const u8, hdr);2101 const hdr_base = @ptrCast([*]const u8, hdr);
...@@ -2126,181 +2104,75 @@ fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: u...@@ -2126,181 +2104,75 @@ fn getLineNumberInfoMacOs(di: *DebugInfo, symbol: MachoSymbol, target_address: u
2126 const segcmd = while (ncmd != 0) : (ncmd -= 1) {2104 const segcmd = while (ncmd != 0) : (ncmd -= 1) {
2127 const lc = @ptrCast(*const std.macho.load_command, ptr);2105 const lc = @ptrCast(*const std.macho.load_command, ptr);
2128 switch (lc.cmd) {2106 switch (lc.cmd) {
2129 std.macho.LC_SEGMENT_64 => break @ptrCast(*const std.macho.segment_command_64, @alignCast(@alignOf(std.macho.segment_command_64), ptr)),2107 std.macho.LC_SEGMENT_64 => {
2108 break @ptrCast(
2109 *const std.macho.segment_command_64,
2110 @alignCast(@alignOf(std.macho.segment_command_64), ptr),
2111 );
2112 },
2130 else => {},2113 else => {},
2131 }2114 }
2132 ptr = @alignCast(@alignOf(std.macho.load_command), ptr + lc.cmdsize);2115 ptr = @alignCast(@alignOf(std.macho.load_command), ptr + lc.cmdsize);
2133 } else {2116 } else {
2134 return error.MissingDebugInfo;2117 return error.MissingDebugInfo;
2135 };2118 };
2119
2120 var opt_debug_line: ?*const macho.section_64 = null;
2121 var opt_debug_info: ?*const macho.section_64 = null;
2122 var opt_debug_abbrev: ?*const macho.section_64 = null;
2123 var opt_debug_str: ?*const macho.section_64 = null;
2124 var opt_debug_ranges: ?*const macho.section_64 = null;
2125
2136 const sections = @ptrCast([*]const macho.section_64, @alignCast(@alignOf(macho.section_64), ptr + @sizeOf(std.macho.segment_command_64)))[0..segcmd.nsects];2126 const sections = @ptrCast([*]const macho.section_64, @alignCast(@alignOf(macho.section_64), ptr + @sizeOf(std.macho.segment_command_64)))[0..segcmd.nsects];
2137 for (sections) |*sect| {2127 for (sections) |*sect| {
2138 if (sect.flags & macho.SECTION_TYPE == macho.S_REGULAR and2128 // The section name may not exceed 16 chars and a trailing null may
2139 (sect.flags & macho.SECTION_ATTRIBUTES) & macho.S_ATTR_DEBUG == macho.S_ATTR_DEBUG)2129 // not be present
2140 {2130 const name = if (mem.indexOfScalar(u8, sect.sectname[0..], 0)) |last|
2141 const sect_name = mem.toSliceConst(u8, @ptrCast([*:0]const u8, &sect.sectname));2131 sect.sectname[0..last]
2142 if (mem.eql(u8, sect_name, "__debug_line")) {2132 else
2143 gop.kv.value.sect_debug_line = sect;2133 sect.sectname[0..];
2144 } else if (mem.eql(u8, sect_name, "__debug_info")) {2134
2145 gop.kv.value.sect_debug_info = sect;2135 if (mem.eql(u8, name, "__debug_line")) {
2146 }2136 opt_debug_line = sect;
2137 } else if (mem.eql(u8, name, "__debug_info")) {
2138 opt_debug_info = sect;
2139 } else if (mem.eql(u8, name, "__debug_abbrev")) {
2140 opt_debug_abbrev = sect;
2141 } else if (mem.eql(u8, name, "__debug_str")) {
2142 opt_debug_str = sect;
2143 } else if (mem.eql(u8, name, "__debug_ranges")) {
2144 opt_debug_ranges = sect;
2147 }2145 }
2148 }2146 }
21492147
2150 break :blk &gop.kv.value;2148 var debug_line = opt_debug_line orelse
2151 };2149 return error.MissingDebugInfo;
21522150 var debug_info = opt_debug_info orelse
2153 const sect_debug_line = mach_o_file.sect_debug_line orelse return error.MissingDebugInfo;2151 return error.MissingDebugInfo;
2154 var ptr = mach_o_file.bytes.ptr + sect_debug_line.offset;2152 var debug_str = opt_debug_str orelse
21552153 return error.MissingDebugInfo;
2156 var is_64: bool = undefined;2154 var debug_abbrev = opt_debug_abbrev orelse
2157 const unit_length = try readInitialLengthMem(&ptr, &is_64);2155 return error.MissingDebugInfo;
2158 if (unit_length == 0) return error.MissingDebugInfo;
2159
2160 const version = readIntMem(&ptr, u16, builtin.Endian.Little);
2161 // TODO support 3 and 5
2162 if (version != 2 and version != 4) return error.InvalidDebugInfo;
2163
2164 const prologue_length = if (is_64)
2165 readIntMem(&ptr, u64, builtin.Endian.Little)
2166 else
2167 readIntMem(&ptr, u32, builtin.Endian.Little);
2168 const prog_start = ptr + prologue_length;
2169
2170 const minimum_instruction_length = readByteMem(&ptr);
2171 if (minimum_instruction_length == 0) return error.InvalidDebugInfo;
2172
2173 if (version >= 4) {
2174 // maximum_operations_per_instruction
2175 ptr += 1;
2176 }
2177
2178 const default_is_stmt = readByteMem(&ptr) != 0;
2179 const line_base = readByteSignedMem(&ptr);
2180
2181 const line_range = readByteMem(&ptr);
2182 if (line_range == 0) return error.InvalidDebugInfo;
2183
2184 const opcode_base = readByteMem(&ptr);
2185
2186 const standard_opcode_lengths = ptr[0 .. opcode_base - 1];
2187 ptr += opcode_base - 1;
2188
2189 var include_directories = ArrayList([]const u8).init(di.allocator());
2190 try include_directories.append("");
2191 while (true) {
2192 const dir = readStringMem(&ptr);
2193 if (dir.len == 0) break;
2194 try include_directories.append(dir);
2195 }
2196
2197 var file_entries = ArrayList(FileEntry).init(di.allocator());
2198 var prog = LineNumberProgram.init(default_is_stmt, include_directories.toSliceConst(), &file_entries, target_address);
21992156
2200 while (true) {2157 gop.kv.value = DwarfInfo{
2201 const file_name = readStringMem(&ptr);2158 .endian = .Little,
2202 if (file_name.len == 0) break;2159 .debug_info = exe_mmap[@intCast(usize, debug_info.offset)..@intCast(usize, debug_info.offset + debug_info.size)],
2203 const dir_index = try leb.readULEB128Mem(usize, &ptr);2160 .debug_abbrev = exe_mmap[@intCast(usize, debug_abbrev.offset)..@intCast(usize, debug_abbrev.offset + debug_abbrev.size)],
2204 const mtime = try leb.readULEB128Mem(usize, &ptr);2161 .debug_str = exe_mmap[@intCast(usize, debug_str.offset)..@intCast(usize, debug_str.offset + debug_str.size)],
2205 const len_bytes = try leb.readULEB128Mem(usize, &ptr);2162 .debug_line = exe_mmap[@intCast(usize, debug_line.offset)..@intCast(usize, debug_line.offset + debug_line.size)],
2206 try file_entries.append(FileEntry{2163 .debug_ranges = if (opt_debug_ranges) |debug_ranges|
2207 .file_name = file_name,2164 exe_mmap[@intCast(usize, debug_ranges.offset)..@intCast(usize, debug_ranges.offset + debug_ranges.size)]
2208 .dir_index = dir_index,2165 else
2209 .mtime = mtime,2166 null,
2210 .len_bytes = len_bytes,2167 };
2211 });2168 try openDwarfDebugInfo(&gop.kv.value, di.allocator());
2212 }
22132169
2214 ptr = prog_start;2170 break :blk &gop.kv.value;
2215 while (true) {2171 };
2216 const opcode = readByteMem(&ptr);
2217
2218 if (opcode == DW.LNS_extended_op) {
2219 const op_size = try leb.readULEB128Mem(u64, &ptr);
2220 if (op_size < 1) return error.InvalidDebugInfo;
2221 var sub_op = readByteMem(&ptr);
2222 switch (sub_op) {
2223 DW.LNE_end_sequence => {
2224 prog.end_sequence = true;
2225 if (try prog.checkLineMatch()) |info| return info;
2226 return error.MissingDebugInfo;
2227 },
2228 DW.LNE_set_address => {
2229 const addr = readIntMem(&ptr, usize, builtin.Endian.Little);
2230 prog.address = symbol.reloc + addr;
2231 },
2232 DW.LNE_define_file => {
2233 const file_name = readStringMem(&ptr);
2234 const dir_index = try leb.readULEB128Mem(usize, &ptr);
2235 const mtime = try leb.readULEB128Mem(usize, &ptr);
2236 const len_bytes = try leb.readULEB128Mem(usize, &ptr);
2237 try file_entries.append(FileEntry{
2238 .file_name = file_name,
2239 .dir_index = dir_index,
2240 .mtime = mtime,
2241 .len_bytes = len_bytes,
2242 });
2243 },
2244 else => {
2245 ptr += op_size - 1;
2246 },
2247 }
2248 } else if (opcode >= opcode_base) {
2249 // special opcodes
2250 const adjusted_opcode = opcode - opcode_base;
2251 const inc_addr = minimum_instruction_length * (adjusted_opcode / line_range);
2252 const inc_line = @as(i32, line_base) + @as(i32, adjusted_opcode % line_range);
2253 prog.line += inc_line;
2254 prog.address += inc_addr;
2255 if (try prog.checkLineMatch()) |info| return info;
2256 prog.basic_block = false;
2257 } else {
2258 switch (opcode) {
2259 DW.LNS_copy => {
2260 if (try prog.checkLineMatch()) |info| return info;
2261 prog.basic_block = false;
2262 },
2263 DW.LNS_advance_pc => {
2264 const arg = try leb.readULEB128Mem(usize, &ptr);
2265 prog.address += arg * minimum_instruction_length;
2266 },
2267 DW.LNS_advance_line => {
2268 const arg = try leb.readILEB128Mem(i64, &ptr);
2269 prog.line += arg;
2270 },
2271 DW.LNS_set_file => {
2272 const arg = try leb.readULEB128Mem(usize, &ptr);
2273 prog.file = arg;
2274 },
2275 DW.LNS_set_column => {
2276 const arg = try leb.readULEB128Mem(u64, &ptr);
2277 prog.column = arg;
2278 },
2279 DW.LNS_negate_stmt => {
2280 prog.is_stmt = !prog.is_stmt;
2281 },
2282 DW.LNS_set_basic_block => {
2283 prog.basic_block = true;
2284 },
2285 DW.LNS_const_add_pc => {
2286 const inc_addr = minimum_instruction_length * ((255 - opcode_base) / line_range);
2287 prog.address += inc_addr;
2288 },
2289 DW.LNS_fixed_advance_pc => {
2290 const arg = readIntMem(&ptr, u16, builtin.Endian.Little);
2291 prog.address += arg;
2292 },
2293 DW.LNS_set_prologue_end => {},
2294 else => {
2295 if (opcode - 1 >= standard_opcode_lengths.len) return error.InvalidDebugInfo;
2296 const len_bytes = standard_opcode_lengths[opcode - 1];
2297 ptr += len_bytes;
2298 },
2299 }
2300 }
2301 }
23022172
2303 return error.MissingDebugInfo;2173 const o_file_address = address - symbol.reloc;
2174 const compile_unit = try dwarf_info.findCompileUnit(o_file_address);
2175 return dwarf_info.getLineNumberInfo(compile_unit.*, o_file_address);
2304}2176}
23052177
2306const Func = struct {2178const Func = struct {
...@@ -2308,47 +2180,6 @@ const Func = struct {...@@ -2308,47 +2180,6 @@ const Func = struct {
2308 name: ?[]u8,2180 name: ?[]u8,
2309};2181};
23102182
2311fn readIntMem(ptr: *[*]const u8, comptime T: type, endian: builtin.Endian) T {
2312 // TODO https://github.com/ziglang/zig/issues/863
2313 const size = (T.bit_count + 7) / 8;
2314 const result = mem.readIntSlice(T, ptr.*[0..size], endian);
2315 ptr.* += size;
2316 return result;
2317}
2318
2319fn readByteMem(ptr: *[*]const u8) u8 {
2320 const result = ptr.*[0];
2321 ptr.* += 1;
2322 return result;
2323}
2324
2325fn readByteSignedMem(ptr: *[*]const u8) i8 {
2326 return @bitCast(i8, readByteMem(ptr));
2327}
2328
2329fn readInitialLengthMem(ptr: *[*]const u8, is_64: *bool) !u64 {
2330 // TODO this code can be improved with https://github.com/ziglang/zig/issues/863
2331 const first_32_bits = mem.readIntSliceLittle(u32, ptr.*[0..4]);
2332 is_64.* = (first_32_bits == 0xffffffff);
2333 if (is_64.*) {
2334 ptr.* += 4;
2335 const result = mem.readIntSliceLittle(u64, ptr.*[0..8]);
2336 ptr.* += 8;
2337 return result;
2338 } else {
2339 if (first_32_bits >= 0xfffffff0) return error.InvalidDebugInfo;
2340 ptr.* += 4;
2341 // TODO this cast should not be needed
2342 return @as(u64, first_32_bits);
2343 }
2344}
2345
2346fn readStringMem(ptr: *[*]const u8) [:0]const u8 {
2347 const result = mem.toSliceConst(u8, @ptrCast([*:0]const u8, ptr.*));
2348 ptr.* += result.len + 1;
2349 return result;
2350}
2351
2352fn readInitialLength(comptime E: type, in_stream: *io.InStream(E), is_64: *bool) !u64 {2183fn readInitialLength(comptime E: type, in_stream: *io.InStream(E), is_64: *bool) !u64 {
2353 const first_32_bits = try in_stream.readIntLittle(u32);2184 const first_32_bits = try in_stream.readIntLittle(u32);
2354 is_64.* = (first_32_bits == 0xffffffff);2185 is_64.* = (first_32_bits == 0xffffffff);
lib/std/fmt.zig+5
...@@ -1135,6 +1135,11 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) {...@@ -1135,6 +1135,11 @@ fn countSize(size: *usize, bytes: []const u8) (error{}!void) {
1135 size.* += bytes.len;1135 size.* += bytes.len;
1136}1136}
11371137
1138pub fn allocPrint0(allocator: *mem.Allocator, comptime fmt: []const u8, args: var) AllocPrintError![:0]u8 {
1139 const result = try allocPrint(allocator, fmt ++ "\x00", args);
1140 return result[0 .. result.len - 1 :0];
1141}
1142
1138test "bufPrintInt" {1143test "bufPrintInt" {
1139 var buffer: [100]u8 = undefined;1144 var buffer: [100]u8 = undefined;
1140 const buf = buffer[0..];1145 const buf = buffer[0..];
lib/std/fmt/parse_float.zig+4
...@@ -382,6 +382,10 @@ pub fn parseFloat(comptime T: type, s: []const u8) !T {...@@ -382,6 +382,10 @@ pub fn parseFloat(comptime T: type, s: []const u8) !T {
382}382}
383383
384test "fmt.parseFloat" {384test "fmt.parseFloat" {
385 if (std.Target.current.isWindows()) {
386 // TODO https://github.com/ziglang/zig/issues/508
387 return error.SkipZigTest;
388 }
385 const testing = std.testing;389 const testing = std.testing;
386 const expect = testing.expect;390 const expect = testing.expect;
387 const expectEqual = testing.expectEqual;391 const expectEqual = testing.expectEqual;
lib/std/hash/murmur.zig+3-3
...@@ -15,7 +15,7 @@ pub const Murmur2_32 = struct {...@@ -15,7 +15,7 @@ pub const Murmur2_32 = struct {
15 const m: u32 = 0x5bd1e995;15 const m: u32 = 0x5bd1e995;
16 const len = @truncate(u32, str.len);16 const len = @truncate(u32, str.len);
17 var h1: u32 = seed ^ len;17 var h1: u32 = seed ^ len;
18 for (@ptrCast([*]allowzero align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {18 for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {
19 var k1: u32 = v;19 var k1: u32 = v;
20 if (builtin.endian == builtin.Endian.Big)20 if (builtin.endian == builtin.Endian.Big)
21 k1 = @byteSwap(u32, k1);21 k1 = @byteSwap(u32, k1);
...@@ -100,7 +100,7 @@ pub const Murmur2_64 = struct {...@@ -100,7 +100,7 @@ pub const Murmur2_64 = struct {
100 const m: u64 = 0xc6a4a7935bd1e995;100 const m: u64 = 0xc6a4a7935bd1e995;
101 const len = @as(u64, str.len);101 const len = @as(u64, str.len);
102 var h1: u64 = seed ^ (len *% m);102 var h1: u64 = seed ^ (len *% m);
103 for (@ptrCast([*]allowzero align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| {103 for (@ptrCast([*]align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| {
104 var k1: u64 = v;104 var k1: u64 = v;
105 if (builtin.endian == builtin.Endian.Big)105 if (builtin.endian == builtin.Endian.Big)
106 k1 = @byteSwap(u64, k1);106 k1 = @byteSwap(u64, k1);
...@@ -180,7 +180,7 @@ pub const Murmur3_32 = struct {...@@ -180,7 +180,7 @@ pub const Murmur3_32 = struct {
180 const c2: u32 = 0x1b873593;180 const c2: u32 = 0x1b873593;
181 const len = @truncate(u32, str.len);181 const len = @truncate(u32, str.len);
182 var h1: u32 = seed;182 var h1: u32 = seed;
183 for (@ptrCast([*]allowzero align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {183 for (@ptrCast([*]align(1) const u32, str.ptr)[0..(len >> 2)]) |v| {
184 var k1: u32 = v;184 var k1: u32 = v;
185 if (builtin.endian == builtin.Endian.Big)185 if (builtin.endian == builtin.Endian.Big)
186 k1 = @byteSwap(u32, k1);186 k1 = @byteSwap(u32, k1);
lib/std/http/headers.zig+1-1
...@@ -172,7 +172,7 @@ pub const Headers = struct {...@@ -172,7 +172,7 @@ pub const Headers = struct {
172 var dex = HeaderIndexList.init(self.allocator);172 var dex = HeaderIndexList.init(self.allocator);
173 try dex.append(n - 1);173 try dex.append(n - 1);
174 errdefer dex.deinit();174 errdefer dex.deinit();
175 _ = try self.index.put(name, dex);175 _ = try self.index.put(name_dup, dex);
176 }176 }
177 self.data.appendAssumeCapacity(entry);177 self.data.appendAssumeCapacity(entry);
178 }178 }
lib/std/io/out_stream.zig+8-4
...@@ -45,10 +45,14 @@ pub fn OutStream(comptime WriteError: type) type {...@@ -45,10 +45,14 @@ pub fn OutStream(comptime WriteError: type) type {
45 }45 }
4646
47 pub fn writeByteNTimes(self: *Self, byte: u8, n: usize) Error!void {47 pub fn writeByteNTimes(self: *Self, byte: u8, n: usize) Error!void {
48 const slice = @as(*const [1]u8, &byte)[0..];48 var bytes: [256]u8 = undefined;
49 var i: usize = 0;49 mem.set(u8, bytes[0..], byte);
50 while (i < n) : (i += 1) {50
51 try self.writeFn(self, slice);51 var remaining: usize = n;
52 while (remaining > 0) {
53 const to_write = std.math.min(remaining, bytes.len);
54 try self.writeFn(self, bytes[0..to_write]);
55 remaining -= to_write;
52 }56 }
53 }57 }
5458
lib/std/io/test.zig+4
...@@ -547,6 +547,10 @@ fn testSerializerDeserializer(comptime endian: builtin.Endian, comptime packing:...@@ -547,6 +547,10 @@ fn testSerializerDeserializer(comptime endian: builtin.Endian, comptime packing:
547}547}
548548
549test "Serializer/Deserializer generic" {549test "Serializer/Deserializer generic" {
550 if (std.Target.current.isWindows()) {
551 // TODO https://github.com/ziglang/zig/issues/508
552 return error.SkipZigTest;
553 }
550 try testSerializerDeserializer(builtin.Endian.Big, .Byte);554 try testSerializerDeserializer(builtin.Endian.Big, .Byte);
551 try testSerializerDeserializer(builtin.Endian.Little, .Byte);555 try testSerializerDeserializer(builtin.Endian.Little, .Byte);
552 try testSerializerDeserializer(builtin.Endian.Big, .Bit);556 try testSerializerDeserializer(builtin.Endian.Big, .Bit);
lib/std/math/fabs.zig+4
...@@ -95,6 +95,10 @@ test "math.fabs64.special" {...@@ -95,6 +95,10 @@ test "math.fabs64.special" {
95}95}
9696
97test "math.fabs128.special" {97test "math.fabs128.special" {
98 if (std.Target.current.isWindows()) {
99 // TODO https://github.com/ziglang/zig/issues/508
100 return error.SkipZigTest;
101 }
98 expect(math.isPositiveInf(fabs(math.inf(f128))));102 expect(math.isPositiveInf(fabs(math.inf(f128))));
99 expect(math.isPositiveInf(fabs(-math.inf(f128))));103 expect(math.isPositiveInf(fabs(-math.inf(f128))));
100 expect(math.isNan(fabs(math.nan(f128))));104 expect(math.isNan(fabs(math.nan(f128))));
lib/std/math/isinf.zig+12
...@@ -74,6 +74,10 @@ pub fn isNegativeInf(x: var) bool {...@@ -74,6 +74,10 @@ pub fn isNegativeInf(x: var) bool {
74}74}
7575
76test "math.isInf" {76test "math.isInf" {
77 if (std.Target.current.isWindows()) {
78 // TODO https://github.com/ziglang/zig/issues/508
79 return error.SkipZigTest;
80 }
77 expect(!isInf(@as(f16, 0.0)));81 expect(!isInf(@as(f16, 0.0)));
78 expect(!isInf(@as(f16, -0.0)));82 expect(!isInf(@as(f16, -0.0)));
79 expect(!isInf(@as(f32, 0.0)));83 expect(!isInf(@as(f32, 0.0)));
...@@ -93,6 +97,10 @@ test "math.isInf" {...@@ -93,6 +97,10 @@ test "math.isInf" {
93}97}
9498
95test "math.isPositiveInf" {99test "math.isPositiveInf" {
100 if (std.Target.current.isWindows()) {
101 // TODO https://github.com/ziglang/zig/issues/508
102 return error.SkipZigTest;
103 }
96 expect(!isPositiveInf(@as(f16, 0.0)));104 expect(!isPositiveInf(@as(f16, 0.0)));
97 expect(!isPositiveInf(@as(f16, -0.0)));105 expect(!isPositiveInf(@as(f16, -0.0)));
98 expect(!isPositiveInf(@as(f32, 0.0)));106 expect(!isPositiveInf(@as(f32, 0.0)));
...@@ -112,6 +120,10 @@ test "math.isPositiveInf" {...@@ -112,6 +120,10 @@ test "math.isPositiveInf" {
112}120}
113121
114test "math.isNegativeInf" {122test "math.isNegativeInf" {
123 if (std.Target.current.isWindows()) {
124 // TODO https://github.com/ziglang/zig/issues/508
125 return error.SkipZigTest;
126 }
115 expect(!isNegativeInf(@as(f16, 0.0)));127 expect(!isNegativeInf(@as(f16, 0.0)));
116 expect(!isNegativeInf(@as(f16, -0.0)));128 expect(!isNegativeInf(@as(f16, -0.0)));
117 expect(!isNegativeInf(@as(f32, 0.0)));129 expect(!isNegativeInf(@as(f32, 0.0)));
lib/std/math/isnan.zig+4
...@@ -16,6 +16,10 @@ pub fn isSignalNan(x: var) bool {...@@ -16,6 +16,10 @@ pub fn isSignalNan(x: var) bool {
16}16}
1717
18test "math.isNan" {18test "math.isNan" {
19 if (std.Target.current.isWindows()) {
20 // TODO https://github.com/ziglang/zig/issues/508
21 return error.SkipZigTest;
22 }
19 expect(isNan(math.nan(f16)));23 expect(isNan(math.nan(f16)));
20 expect(isNan(math.nan(f32)));24 expect(isNan(math.nan(f32)));
21 expect(isNan(math.nan(f64)));25 expect(isNan(math.nan(f64)));
lib/std/mem.zig+3
...@@ -175,6 +175,7 @@ pub const Allocator = struct {...@@ -175,6 +175,7 @@ pub const Allocator = struct {
175175
176 const old_byte_slice = @sliceToBytes(old_mem);176 const old_byte_slice = @sliceToBytes(old_mem);
177 const byte_count = math.mul(usize, @sizeOf(T), new_n) catch return Error.OutOfMemory;177 const byte_count = math.mul(usize, @sizeOf(T), new_n) catch return Error.OutOfMemory;
178 // Note: can't set shrunk memory to undefined as memory shouldn't be modified on realloc failure
178 const byte_slice = try self.reallocFn(self, old_byte_slice, Slice.alignment, byte_count, new_alignment);179 const byte_slice = try self.reallocFn(self, old_byte_slice, Slice.alignment, byte_count, new_alignment);
179 assert(byte_slice.len == byte_count);180 assert(byte_slice.len == byte_count);
180 if (new_n > old_mem.len) {181 if (new_n > old_mem.len) {
...@@ -221,6 +222,7 @@ pub const Allocator = struct {...@@ -221,6 +222,7 @@ pub const Allocator = struct {
221 const byte_count = @sizeOf(T) * new_n;222 const byte_count = @sizeOf(T) * new_n;
222223
223 const old_byte_slice = @sliceToBytes(old_mem);224 const old_byte_slice = @sliceToBytes(old_mem);
225 @memset(old_byte_slice.ptr + byte_count, undefined, old_byte_slice.len - byte_count);
224 const byte_slice = self.shrinkFn(self, old_byte_slice, Slice.alignment, byte_count, new_alignment);226 const byte_slice = self.shrinkFn(self, old_byte_slice, Slice.alignment, byte_count, new_alignment);
225 assert(byte_slice.len == byte_count);227 assert(byte_slice.len == byte_count);
226 return @bytesToSlice(T, @alignCast(new_alignment, byte_slice));228 return @bytesToSlice(T, @alignCast(new_alignment, byte_slice));
...@@ -234,6 +236,7 @@ pub const Allocator = struct {...@@ -234,6 +236,7 @@ pub const Allocator = struct {
234 const bytes_len = bytes.len + @boolToInt(Slice.sentinel != null);236 const bytes_len = bytes.len + @boolToInt(Slice.sentinel != null);
235 if (bytes_len == 0) return;237 if (bytes_len == 0) return;
236 const non_const_ptr = @intToPtr([*]u8, @ptrToInt(bytes.ptr));238 const non_const_ptr = @intToPtr([*]u8, @ptrToInt(bytes.ptr));
239 @memset(non_const_ptr, undefined, bytes_len);
237 const shrink_result = self.shrinkFn(self, non_const_ptr[0..bytes_len], Slice.alignment, 0, 1);240 const shrink_result = self.shrinkFn(self, non_const_ptr[0..bytes_len], Slice.alignment, 0, 1);
238 assert(shrink_result.len == 0);241 assert(shrink_result.len == 0);
239 }242 }
lib/std/meta.zig+18
...@@ -556,3 +556,21 @@ pub fn refAllDecls(comptime T: type) void {...@@ -556,3 +556,21 @@ pub fn refAllDecls(comptime T: type) void {
556 if (!builtin.is_test) return;556 if (!builtin.is_test) return;
557 _ = declarations(T);557 _ = declarations(T);
558}558}
559
560/// Returns a slice of pointers to public declarations of a namespace.
561pub fn declList(comptime Namespace: type, comptime Decl: type) []const *const Decl {
562 const S = struct {
563 fn declNameLessThan(lhs: *const Decl, rhs: *const Decl) bool {
564 return mem.lessThan(u8, lhs.name, rhs.name);
565 }
566 };
567 comptime {
568 const decls = declarations(Namespace);
569 var array: [decls.len]*const Decl = undefined;
570 for (decls) |decl, i| {
571 array[i] = &@field(Namespace, decl.name);
572 }
573 std.sort.sort(*const Decl, &array, S.declNameLessThan);
574 return &array;
575 }
576}
lib/std/os.zig+1-1
...@@ -2697,7 +2697,7 @@ pub fn dl_iterate_phdr(...@@ -2697,7 +2697,7 @@ pub fn dl_iterate_phdr(
2697 // the whole ELF image2697 // the whole ELF image
2698 if (it.end()) {2698 if (it.end()) {
2699 var info = dl_phdr_info{2699 var info = dl_phdr_info{
2700 .dlpi_addr = elf_base,2700 .dlpi_addr = 0,
2701 .dlpi_name = "/proc/self/exe",2701 .dlpi_name = "/proc/self/exe",
2702 .dlpi_phdr = phdrs.ptr,2702 .dlpi_phdr = phdrs.ptr,
2703 .dlpi_phnum = ehdr.e_phnum,2703 .dlpi_phnum = ehdr.e_phnum,
lib/std/os/linux.zig-57
...@@ -1041,63 +1041,6 @@ pub fn uname(uts: *utsname) usize {...@@ -1041,63 +1041,6 @@ pub fn uname(uts: *utsname) usize {
1041 return syscall1(SYS_uname, @ptrToInt(uts));1041 return syscall1(SYS_uname, @ptrToInt(uts));
1042}1042}
10431043
1044// XXX: This should be weak
1045extern const __ehdr_start: elf.Ehdr;
1046
1047pub fn dl_iterate_phdr(comptime T: type, callback: extern fn (info: *dl_phdr_info, size: usize, data: ?*T) i32, data: ?*T) isize {
1048 if (builtin.link_libc) {
1049 return std.c.dl_iterate_phdr(@ptrCast(std.c.dl_iterate_phdr_callback, callback), @ptrCast(?*c_void, data));
1050 }
1051
1052 const elf_base = @ptrToInt(&__ehdr_start);
1053 const n_phdr = __ehdr_start.e_phnum;
1054 const phdrs = (@intToPtr([*]elf.Phdr, elf_base + __ehdr_start.e_phoff))[0..n_phdr];
1055
1056 var it = dl.linkmap_iterator(phdrs) catch return 0;
1057
1058 // The executable has no dynamic link segment, create a single entry for
1059 // the whole ELF image
1060 if (it.end()) {
1061 var info = dl_phdr_info{
1062 .dlpi_addr = elf_base,
1063 .dlpi_name = "/proc/self/exe",
1064 .dlpi_phdr = @intToPtr([*]elf.Phdr, elf_base + __ehdr_start.e_phoff),
1065 .dlpi_phnum = __ehdr_start.e_phnum,
1066 };
1067
1068 return callback(&info, @sizeOf(dl_phdr_info), data);
1069 }
1070
1071 // Last return value from the callback function
1072 var last_r: isize = 0;
1073 while (it.next()) |entry| {
1074 var dlpi_phdr: usize = undefined;
1075 var dlpi_phnum: u16 = undefined;
1076
1077 if (entry.l_addr != 0) {
1078 const elf_header = @intToPtr(*elf.Ehdr, entry.l_addr);
1079 dlpi_phdr = entry.l_addr + elf_header.e_phoff;
1080 dlpi_phnum = elf_header.e_phnum;
1081 } else {
1082 // This is the running ELF image
1083 dlpi_phdr = elf_base + __ehdr_start.e_phoff;
1084 dlpi_phnum = __ehdr_start.e_phnum;
1085 }
1086
1087 var info = dl_phdr_info{
1088 .dlpi_addr = entry.l_addr,
1089 .dlpi_name = entry.l_name,
1090 .dlpi_phdr = @intToPtr([*]elf.Phdr, dlpi_phdr),
1091 .dlpi_phnum = dlpi_phnum,
1092 };
1093
1094 last_r = callback(&info, @sizeOf(dl_phdr_info), data);
1095 if (last_r != 0) break;
1096 }
1097
1098 return last_r;
1099}
1100
1101pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize {1044pub fn io_uring_setup(entries: u32, p: *io_uring_params) usize {
1102 return syscall2(SYS_io_uring_setup, entries, @ptrToInt(p));1045 return syscall2(SYS_io_uring_setup, entries, @ptrToInt(p));
1103}1046}
lib/std/os/linux/tls.zig+1-1
...@@ -211,7 +211,7 @@ pub fn initTLS() ?*elf.Phdr {...@@ -211,7 +211,7 @@ pub fn initTLS() ?*elf.Phdr {
211211
212 if (tls_phdr) |phdr| {212 if (tls_phdr) |phdr| {
213 // If the cpu is arm-based, check if it supports the TLS register213 // If the cpu is arm-based, check if it supports the TLS register
214 if (builtin.arch == builtin.Arch.arm and at_hwcap & std.os.linux.HWCAP_TLS == 0) {214 if (builtin.arch == .arm and at_hwcap & std.os.linux.HWCAP_TLS == 0) {
215 // If the CPU does not support TLS via a coprocessor register,215 // If the CPU does not support TLS via a coprocessor register,
216 // a kernel helper function can be used instead on certain linux kernels.216 // a kernel helper function can be used instead on certain linux kernels.
217 // See linux/arch/arm/include/asm/tls.h and musl/src/thread/arm/__set_thread_area.c.217 // See linux/arch/arm/include/asm/tls.h and musl/src/thread/arm/__set_thread_area.c.
lib/std/os/test.zig+2-1
...@@ -186,8 +186,9 @@ fn iter_fn(info: *dl_phdr_info, size: usize, data: ?*usize) callconv(.C) i32 {...@@ -186,8 +186,9 @@ fn iter_fn(info: *dl_phdr_info, size: usize, data: ?*usize) callconv(.C) i32 {
186186
187 if (phdr.p_type != elf.PT_LOAD) continue;187 if (phdr.p_type != elf.PT_LOAD) continue;
188188
189 const reloc_addr = info.dlpi_addr + phdr.p_vaddr;
189 // Find the ELF header190 // Find the ELF header
190 const elf_header = @intToPtr(*elf.Ehdr, phdr.p_vaddr - phdr.p_offset);191 const elf_header = @intToPtr(*elf.Ehdr, reloc_addr - phdr.p_offset);
191 // Validate the magic192 // Validate the magic
192 if (!mem.eql(u8, elf_header.e_ident[0..4], "\x7fELF")) return -1;193 if (!mem.eql(u8, elf_header.e_ident[0..4], "\x7fELF")) return -1;
193 // Consistency check194 // Consistency check
lib/std/sort.zig+7-9
...@@ -7,16 +7,14 @@ const builtin = @import("builtin");...@@ -7,16 +7,14 @@ const builtin = @import("builtin");
77
8/// Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case. O(1) memory (no allocator required).8/// Stable in-place sort. O(n) best case, O(pow(n, 2)) worst case. O(1) memory (no allocator required).
9pub fn insertionSort(comptime T: type, items: []T, lessThan: fn (lhs: T, rhs: T) bool) void {9pub fn insertionSort(comptime T: type, items: []T, lessThan: fn (lhs: T, rhs: T) bool) void {
10 {10 var i: usize = 1;
11 var i: usize = 1;11 while (i < items.len) : (i += 1) {
12 while (i < items.len) : (i += 1) {12 const x = items[i];
13 const x = items[i];13 var j: usize = i;
14 var j: usize = i;14 while (j > 0 and lessThan(x, items[j - 1])) : (j -= 1) {
15 while (j > 0 and lessThan(x, items[j - 1])) : (j -= 1) {15 items[j] = items[j - 1];
16 items[j] = items[j - 1];
17 }
18 items[j] = x;
19 }16 }
17 items[j] = x;
20 }18 }
21}19}
2220
lib/std/special/compiler_rt.zig+1
...@@ -130,6 +130,7 @@ comptime {...@@ -130,6 +130,7 @@ comptime {
130 @export(@import("compiler_rt/int.zig").__udivmoddi4, .{ .name = "__udivmoddi4", .linkage = linkage });130 @export(@import("compiler_rt/int.zig").__udivmoddi4, .{ .name = "__udivmoddi4", .linkage = linkage });
131 @export(@import("compiler_rt/popcountdi2.zig").__popcountdi2, .{ .name = "__popcountdi2", .linkage = linkage });131 @export(@import("compiler_rt/popcountdi2.zig").__popcountdi2, .{ .name = "__popcountdi2", .linkage = linkage });
132132
133 @export(@import("compiler_rt/int.zig").__mulsi3, .{ .name = "__mulsi3", .linkage = linkage });
133 @export(@import("compiler_rt/muldi3.zig").__muldi3, .{ .name = "__muldi3", .linkage = linkage });134 @export(@import("compiler_rt/muldi3.zig").__muldi3, .{ .name = "__muldi3", .linkage = linkage });
134 @export(@import("compiler_rt/int.zig").__divmoddi4, .{ .name = "__divmoddi4", .linkage = linkage });135 @export(@import("compiler_rt/int.zig").__divmoddi4, .{ .name = "__divmoddi4", .linkage = linkage });
135 @export(@import("compiler_rt/int.zig").__divsi3, .{ .name = "__divsi3", .linkage = linkage });136 @export(@import("compiler_rt/int.zig").__divsi3, .{ .name = "__divsi3", .linkage = linkage });
lib/std/special/compiler_rt/addXf3_test.zig+8
...@@ -31,6 +31,10 @@ fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {...@@ -31,6 +31,10 @@ fn test__addtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
31}31}
3232
33test "addtf3" {33test "addtf3" {
34 if (@import("std").Target.current.isWindows()) {
35 // TODO https://github.com/ziglang/zig/issues/508
36 return error.SkipZigTest;
37 }
34 test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);38 test__addtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
3539
36 // NaN + any = NaN40 // NaN + any = NaN
...@@ -71,6 +75,10 @@ fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {...@@ -71,6 +75,10 @@ fn test__subtf3(a: f128, b: f128, expected_hi: u64, expected_lo: u64) void {
71}75}
7276
73test "subtf3" {77test "subtf3" {
78 if (@import("std").Target.current.isWindows()) {
79 // TODO https://github.com/ziglang/zig/issues/508
80 return error.SkipZigTest;
81 }
74 // qNaN - any = qNaN82 // qNaN - any = qNaN
75 test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);83 test__subtf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
7684
lib/std/special/compiler_rt/fixtfdi_test.zig+4
...@@ -11,6 +11,10 @@ fn test__fixtfdi(a: f128, expected: i64) void {...@@ -11,6 +11,10 @@ fn test__fixtfdi(a: f128, expected: i64) void {
11}11}
1212
13test "fixtfdi" {13test "fixtfdi" {
14 if (@import("std").Target.current.isWindows()) {
15 // TODO https://github.com/ziglang/zig/issues/508
16 return error.SkipZigTest;
17 }
14 //warn("\n", .{});18 //warn("\n", .{});
15 test__fixtfdi(-math.f128_max, math.minInt(i64));19 test__fixtfdi(-math.f128_max, math.minInt(i64));
1620
lib/std/special/compiler_rt/fixtfsi_test.zig+4
...@@ -11,6 +11,10 @@ fn test__fixtfsi(a: f128, expected: i32) void {...@@ -11,6 +11,10 @@ fn test__fixtfsi(a: f128, expected: i32) void {
11}11}
1212
13test "fixtfsi" {13test "fixtfsi" {
14 if (@import("std").Target.current.isWindows()) {
15 // TODO https://github.com/ziglang/zig/issues/508
16 return error.SkipZigTest;
17 }
14 //warn("\n", .{});18 //warn("\n", .{});
15 test__fixtfsi(-math.f128_max, math.minInt(i32));19 test__fixtfsi(-math.f128_max, math.minInt(i32));
1620
lib/std/special/compiler_rt/fixtfti_test.zig+4
...@@ -11,6 +11,10 @@ fn test__fixtfti(a: f128, expected: i128) void {...@@ -11,6 +11,10 @@ fn test__fixtfti(a: f128, expected: i128) void {
11}11}
1212
13test "fixtfti" {13test "fixtfti" {
14 if (@import("std").Target.current.isWindows()) {
15 // TODO https://github.com/ziglang/zig/issues/508
16 return error.SkipZigTest;
17 }
14 //warn("\n", .{});18 //warn("\n", .{});
15 test__fixtfti(-math.f128_max, math.minInt(i128));19 test__fixtfti(-math.f128_max, math.minInt(i128));
1620
lib/std/special/compiler_rt/fixunstfdi_test.zig+4
...@@ -7,6 +7,10 @@ fn test__fixunstfdi(a: f128, expected: u64) void {...@@ -7,6 +7,10 @@ fn test__fixunstfdi(a: f128, expected: u64) void {
7}7}
88
9test "fixunstfdi" {9test "fixunstfdi" {
10 if (@import("std").Target.current.isWindows()) {
11 // TODO https://github.com/ziglang/zig/issues/508
12 return error.SkipZigTest;
13 }
10 test__fixunstfdi(0.0, 0);14 test__fixunstfdi(0.0, 0);
1115
12 test__fixunstfdi(0.5, 0);16 test__fixunstfdi(0.5, 0);
lib/std/special/compiler_rt/fixunstfsi_test.zig+4
...@@ -9,6 +9,10 @@ fn test__fixunstfsi(a: f128, expected: u32) void {...@@ -9,6 +9,10 @@ fn test__fixunstfsi(a: f128, expected: u32) void {
9const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));9const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
1010
11test "fixunstfsi" {11test "fixunstfsi" {
12 if (@import("std").Target.current.isWindows()) {
13 // TODO https://github.com/ziglang/zig/issues/508
14 return error.SkipZigTest;
15 }
12 test__fixunstfsi(inf128, 0xffffffff);16 test__fixunstfsi(inf128, 0xffffffff);
13 test__fixunstfsi(0, 0x0);17 test__fixunstfsi(0, 0x0);
14 test__fixunstfsi(0x1.23456789abcdefp+5, 0x24);18 test__fixunstfsi(0x1.23456789abcdefp+5, 0x24);
lib/std/special/compiler_rt/fixunstfti_test.zig+4
...@@ -9,6 +9,10 @@ fn test__fixunstfti(a: f128, expected: u128) void {...@@ -9,6 +9,10 @@ fn test__fixunstfti(a: f128, expected: u128) void {
9const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));9const inf128 = @bitCast(f128, @as(u128, 0x7fff0000000000000000000000000000));
1010
11test "fixunstfti" {11test "fixunstfti" {
12 if (@import("std").Target.current.isWindows()) {
13 // TODO https://github.com/ziglang/zig/issues/508
14 return error.SkipZigTest;
15 }
12 test__fixunstfti(inf128, 0xffffffffffffffffffffffffffffffff);16 test__fixunstfti(inf128, 0xffffffffffffffffffffffffffffffff);
1317
14 test__fixunstfti(0.0, 0);18 test__fixunstfti(0.0, 0);
lib/std/special/compiler_rt/floattitf_test.zig+4
...@@ -7,6 +7,10 @@ fn test__floattitf(a: i128, expected: f128) void {...@@ -7,6 +7,10 @@ fn test__floattitf(a: i128, expected: f128) void {
7}7}
88
9test "floattitf" {9test "floattitf" {
10 if (@import("std").Target.current.isWindows()) {
11 // TODO https://github.com/ziglang/zig/issues/508
12 return error.SkipZigTest;
13 }
10 test__floattitf(0, 0.0);14 test__floattitf(0, 0.0);
1115
12 test__floattitf(1, 1.0);16 test__floattitf(1, 1.0);
lib/std/special/compiler_rt/floatuntitf_test.zig+4
...@@ -7,6 +7,10 @@ fn test__floatuntitf(a: u128, expected: f128) void {...@@ -7,6 +7,10 @@ fn test__floatuntitf(a: u128, expected: f128) void {
7}7}
88
9test "floatuntitf" {9test "floatuntitf" {
10 if (@import("std").Target.current.isWindows()) {
11 // TODO https://github.com/ziglang/zig/issues/508
12 return error.SkipZigTest;
13 }
10 test__floatuntitf(0, 0.0);14 test__floatuntitf(0, 0.0);
1115
12 test__floatuntitf(1, 1.0);16 test__floatuntitf(1, 1.0);
lib/std/special/compiler_rt/int.zig+60
...@@ -1,6 +1,8 @@...@@ -1,6 +1,8 @@
1// Builtin functions that operate on integer types1// Builtin functions that operate on integer types
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const testing = @import("std").testing;3const testing = @import("std").testing;
4const maxInt = @import("std").math.maxInt;
5const minInt = @import("std").math.minInt;
46
5const udivmod = @import("udivmod.zig").udivmod;7const udivmod = @import("udivmod.zig").udivmod;
68
...@@ -578,3 +580,61 @@ fn test_one_umodsi3(a: u32, b: u32, expected_r: u32) void {...@@ -578,3 +580,61 @@ fn test_one_umodsi3(a: u32, b: u32, expected_r: u32) void {
578 const r: u32 = __umodsi3(a, b);580 const r: u32 = __umodsi3(a, b);
579 testing.expect(r == expected_r);581 testing.expect(r == expected_r);
580}582}
583
584pub fn __mulsi3(a: i32, b: i32) callconv(.C) i32 {
585 @setRuntimeSafety(builtin.is_test);
586
587 var ua = @bitCast(u32, a);
588 var ub = @bitCast(u32, b);
589 var r: u32 = 0;
590
591 while (ua > 0) {
592 if ((ua & 1) != 0) r +%= ub;
593 ua >>= 1;
594 ub <<= 1;
595 }
596
597 return @bitCast(i32, r);
598}
599
600fn test_one_mulsi3(a: i32, b: i32, result: i32) void {
601 testing.expectEqual(result, __mulsi3(a, b));
602}
603
604test "mulsi3" {
605 test_one_mulsi3(0, 0, 0);
606 test_one_mulsi3(0, 1, 0);
607 test_one_mulsi3(1, 0, 0);
608 test_one_mulsi3(0, 10, 0);
609 test_one_mulsi3(10, 0, 0);
610 test_one_mulsi3(0, maxInt(i32), 0);
611 test_one_mulsi3(maxInt(i32), 0, 0);
612 test_one_mulsi3(0, -1, 0);
613 test_one_mulsi3(-1, 0, 0);
614 test_one_mulsi3(0, -10, 0);
615 test_one_mulsi3(-10, 0, 0);
616 test_one_mulsi3(0, minInt(i32), 0);
617 test_one_mulsi3(minInt(i32), 0, 0);
618 test_one_mulsi3(1, 1, 1);
619 test_one_mulsi3(1, 10, 10);
620 test_one_mulsi3(10, 1, 10);
621 test_one_mulsi3(1, maxInt(i32), maxInt(i32));
622 test_one_mulsi3(maxInt(i32), 1, maxInt(i32));
623 test_one_mulsi3(1, -1, -1);
624 test_one_mulsi3(1, -10, -10);
625 test_one_mulsi3(-10, 1, -10);
626 test_one_mulsi3(1, minInt(i32), minInt(i32));
627 test_one_mulsi3(minInt(i32), 1, minInt(i32));
628 test_one_mulsi3(46340, 46340, 2147395600);
629 test_one_mulsi3(-46340, 46340, -2147395600);
630 test_one_mulsi3(46340, -46340, -2147395600);
631 test_one_mulsi3(-46340, -46340, 2147395600);
632 test_one_mulsi3(4194303, 8192, @truncate(i32, 34359730176));
633 test_one_mulsi3(-4194303, 8192, @truncate(i32, -34359730176));
634 test_one_mulsi3(4194303, -8192, @truncate(i32, -34359730176));
635 test_one_mulsi3(-4194303, -8192, @truncate(i32, 34359730176));
636 test_one_mulsi3(8192, 4194303, @truncate(i32, 34359730176));
637 test_one_mulsi3(-8192, 4194303, @truncate(i32, -34359730176));
638 test_one_mulsi3(8192, -4194303, @truncate(i32, -34359730176));
639 test_one_mulsi3(-8192, -4194303, @truncate(i32, 34359730176));
640}
lib/std/special/compiler_rt/mulXf3_test.zig+4
...@@ -44,6 +44,10 @@ fn makeNaN128(rand: u64) f128 {...@@ -44,6 +44,10 @@ fn makeNaN128(rand: u64) f128 {
44 return float_result;44 return float_result;
45}45}
46test "multf3" {46test "multf3" {
47 if (@import("std").Target.current.isWindows()) {
48 // TODO https://github.com/ziglang/zig/issues/508
49 return error.SkipZigTest;
50 }
47 // qNaN * any = qNaN51 // qNaN * any = qNaN
48 test__multf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);52 test__multf3(qnan128, 0x1.23456789abcdefp+5, 0x7fff800000000000, 0x0);
4953
lib/std/special/compiler_rt/truncXfYf2_test.zig+8
...@@ -151,6 +151,10 @@ fn test__trunctfsf2(a: f128, expected: u32) void {...@@ -151,6 +151,10 @@ fn test__trunctfsf2(a: f128, expected: u32) void {
151}151}
152152
153test "trunctfsf2" {153test "trunctfsf2" {
154 if (@import("std").Target.current.isWindows()) {
155 // TODO https://github.com/ziglang/zig/issues/508
156 return error.SkipZigTest;
157 }
154 // qnan158 // qnan
155 test__trunctfsf2(@bitCast(f128, @as(u128, 0x7fff800000000000 << 64)), 0x7fc00000);159 test__trunctfsf2(@bitCast(f128, @as(u128, 0x7fff800000000000 << 64)), 0x7fc00000);
156 // nan160 // nan
...@@ -186,6 +190,10 @@ fn test__trunctfdf2(a: f128, expected: u64) void {...@@ -186,6 +190,10 @@ fn test__trunctfdf2(a: f128, expected: u64) void {
186}190}
187191
188test "trunctfdf2" {192test "trunctfdf2" {
193 if (@import("std").Target.current.isWindows()) {
194 // TODO https://github.com/ziglang/zig/issues/508
195 return error.SkipZigTest;
196 }
189 // qnan197 // qnan
190 test__trunctfdf2(@bitCast(f128, @as(u128, 0x7fff800000000000 << 64)), 0x7ff8000000000000);198 test__trunctfdf2(@bitCast(f128, @as(u128, 0x7fff800000000000 << 64)), 0x7ff8000000000000);
191 // nan199 // nan
lib/std/target.zig+370-10
...@@ -49,6 +49,22 @@ pub const Target = union(enum) {...@@ -49,6 +49,22 @@ pub const Target = union(enum) {
49 other,49 other,
50 };50 };
5151
52 pub const aarch64 = @import("target/aarch64.zig");
53 pub const amdgpu = @import("target/amdgpu.zig");
54 pub const arm = @import("target/arm.zig");
55 pub const avr = @import("target/avr.zig");
56 pub const bpf = @import("target/bpf.zig");
57 pub const hexagon = @import("target/hexagon.zig");
58 pub const mips = @import("target/mips.zig");
59 pub const msp430 = @import("target/msp430.zig");
60 pub const nvptx = @import("target/nvptx.zig");
61 pub const powerpc = @import("target/powerpc.zig");
62 pub const riscv = @import("target/riscv.zig");
63 pub const sparc = @import("target/sparc.zig");
64 pub const systemz = @import("target/systemz.zig");
65 pub const wasm = @import("target/wasm.zig");
66 pub const x86 = @import("target/x86.zig");
67
52 pub const Arch = union(enum) {68 pub const Arch = union(enum) {
53 arm: Arm32,69 arm: Arm32,
54 armeb: Arm32,70 armeb: Arm32,
...@@ -108,12 +124,12 @@ pub const Target = union(enum) {...@@ -108,12 +124,12 @@ pub const Target = union(enum) {
108 v8_3a,124 v8_3a,
109 v8_2a,125 v8_2a,
110 v8_1a,126 v8_1a,
111 v8,127 v8a,
112 v8r,128 v8r,
113 v8m_baseline,129 v8m_baseline,
114 v8m_mainline,130 v8m_mainline,
115 v8_1m_mainline,131 v8_1m_mainline,
116 v7,132 v7a,
117 v7em,133 v7em,
118 v7m,134 v7m,
119 v7s,135 v7s,
...@@ -129,8 +145,8 @@ pub const Target = union(enum) {...@@ -129,8 +145,8 @@ pub const Target = union(enum) {
129145
130 pub fn version(version: Arm32) comptime_int {146 pub fn version(version: Arm32) comptime_int {
131 return switch (version) {147 return switch (version) {
132 .v8_5a, .v8_4a, .v8_3a, .v8_2a, .v8_1a, .v8, .v8r, .v8m_baseline, .v8m_mainline, .v8_1m_mainline => 8,148 .v8_5a, .v8_4a, .v8_3a, .v8_2a, .v8_1a, .v8a, .v8r, .v8m_baseline, .v8m_mainline, .v8_1m_mainline => 8,
133 .v7, .v7em, .v7m, .v7s, .v7k, .v7ve => 7,149 .v7a, .v7em, .v7m, .v7s, .v7k, .v7ve => 7,
134 .v6, .v6m, .v6k, .v6t2 => 6,150 .v6, .v6m, .v6k, .v6t2 => 6,
135 .v5, .v5te => 5,151 .v5, .v5te => 5,
136 .v4t => 4,152 .v4t => 4,
...@@ -143,10 +159,7 @@ pub const Target = union(enum) {...@@ -143,10 +159,7 @@ pub const Target = union(enum) {
143 v8_3a,159 v8_3a,
144 v8_2a,160 v8_2a,
145 v8_1a,161 v8_1a,
146 v8,162 v8a,
147 v8r,
148 v8m_baseline,
149 v8m_mainline,
150 };163 };
151 pub const Kalimba = enum {164 pub const Kalimba = enum {
152 v5,165 v5,
...@@ -160,6 +173,54 @@ pub const Target = union(enum) {...@@ -160,6 +173,54 @@ pub const Target = union(enum) {
160 spe,173 spe,
161 };174 };
162175
176 pub fn subArchName(arch: Arch) ?[]const u8 {
177 return switch (arch) {
178 .arm, .armeb, .thumb, .thumbeb => |arm32| @tagName(arm32),
179 .aarch64, .aarch64_be, .aarch64_32 => |arm64| @tagName(arm64),
180 .kalimba => |kalimba| @tagName(kalimba),
181 else => return null,
182 };
183 }
184
185 pub fn subArchFeature(arch: Arch) ?Cpu.Feature.Set.Index {
186 return switch (arch) {
187 .arm, .armeb, .thumb, .thumbeb => |arm32| switch (arm32) {
188 .v8_5a => @enumToInt(arm.Feature.armv8_5_a),
189 .v8_4a => @enumToInt(arm.Feature.armv8_4_a),
190 .v8_3a => @enumToInt(arm.Feature.armv8_3_a),
191 .v8_2a => @enumToInt(arm.Feature.armv8_2_a),
192 .v8_1a => @enumToInt(arm.Feature.armv8_1_a),
193 .v8a => @enumToInt(arm.Feature.armv8_a),
194 .v8r => @enumToInt(arm.Feature.armv8_r),
195 .v8m_baseline => @enumToInt(arm.Feature.armv8_m_base),
196 .v8m_mainline => @enumToInt(arm.Feature.armv8_m_main),
197 .v8_1m_mainline => @enumToInt(arm.Feature.armv8_1_m_main),
198 .v7a => @enumToInt(arm.Feature.armv7_a),
199 .v7em => @enumToInt(arm.Feature.armv7e_m),
200 .v7m => @enumToInt(arm.Feature.armv7_m),
201 .v7s => @enumToInt(arm.Feature.armv7s),
202 .v7k => @enumToInt(arm.Feature.armv7k),
203 .v7ve => @enumToInt(arm.Feature.armv7ve),
204 .v6 => @enumToInt(arm.Feature.armv6),
205 .v6m => @enumToInt(arm.Feature.armv6_m),
206 .v6k => @enumToInt(arm.Feature.armv6k),
207 .v6t2 => @enumToInt(arm.Feature.armv6t2),
208 .v5 => @enumToInt(arm.Feature.armv5t),
209 .v5te => @enumToInt(arm.Feature.armv5te),
210 .v4t => @enumToInt(arm.Feature.armv4t),
211 },
212 .aarch64, .aarch64_be, .aarch64_32 => |arm64| switch (arm64) {
213 .v8_5a => @enumToInt(aarch64.Feature.v8_5a),
214 .v8_4a => @enumToInt(aarch64.Feature.v8_4a),
215 .v8_3a => @enumToInt(aarch64.Feature.v8_3a),
216 .v8_2a => @enumToInt(aarch64.Feature.v8_2a),
217 .v8_1a => @enumToInt(aarch64.Feature.v8_1a),
218 .v8a => @enumToInt(aarch64.Feature.v8a),
219 },
220 else => return null,
221 };
222 }
223
163 pub fn isARM(arch: Arch) bool {224 pub fn isARM(arch: Arch) bool {
164 return switch (arch) {225 return switch (arch) {
165 .arm, .armeb => true,226 .arm, .armeb => true,
...@@ -188,6 +249,53 @@ pub const Target = union(enum) {...@@ -188,6 +249,53 @@ pub const Target = union(enum) {
188 };249 };
189 }250 }
190251
252 pub fn parseCpu(arch: Arch, cpu_name: []const u8) !*const Cpu {
253 for (arch.allCpus()) |cpu| {
254 if (mem.eql(u8, cpu_name, cpu.name)) {
255 return cpu;
256 }
257 }
258 return error.UnknownCpu;
259 }
260
261 /// Comma-separated list of features, with + or - in front of each feature. This
262 /// form represents a deviation from baseline CPU, which is provided as a parameter.
263 /// Extra commas are ignored.
264 pub fn parseCpuFeatureSet(arch: Arch, cpu: *const Cpu, features_text: []const u8) !Cpu.Feature.Set {
265 const all_features = arch.allFeaturesList();
266 var set = cpu.features;
267 var it = mem.tokenize(features_text, ",");
268 while (it.next()) |item_text| {
269 var feature_name: []const u8 = undefined;
270 var op: enum {
271 add,
272 sub,
273 } = undefined;
274 if (mem.startsWith(u8, item_text, "+")) {
275 op = .add;
276 feature_name = item_text[1..];
277 } else if (mem.startsWith(u8, item_text, "-")) {
278 op = .sub;
279 feature_name = item_text[1..];
280 } else {
281 return error.InvalidCpuFeatures;
282 }
283 for (all_features) |feature, index_usize| {
284 const index = @intCast(Cpu.Feature.Set.Index, index_usize);
285 if (mem.eql(u8, feature_name, feature.name)) {
286 switch (op) {
287 .add => set.addFeature(index),
288 .sub => set.removeFeature(index),
289 }
290 break;
291 }
292 } else {
293 return error.UnknownCpuFeature;
294 }
295 }
296 return set;
297 }
298
191 pub fn toElfMachine(arch: Arch) std.elf.EM {299 pub fn toElfMachine(arch: Arch) std.elf.EM {
192 return switch (arch) {300 return switch (arch) {
193 .avr => ._AVR,301 .avr => ._AVR,
...@@ -300,6 +408,109 @@ pub const Target = union(enum) {...@@ -300,6 +408,109 @@ pub const Target = union(enum) {
300 => .Big,408 => .Big,
301 };409 };
302 }410 }
411
412 /// Returns a name that matches the lib/std/target/* directory name.
413 pub fn genericName(arch: Arch) []const u8 {
414 return switch (arch) {
415 .arm, .armeb, .thumb, .thumbeb => "arm",
416 .aarch64, .aarch64_be, .aarch64_32 => "aarch64",
417 .avr => "avr",
418 .bpfel, .bpfeb => "bpf",
419 .hexagon => "hexagon",
420 .mips, .mipsel, .mips64, .mips64el => "mips",
421 .msp430 => "msp430",
422 .powerpc, .powerpc64, .powerpc64le => "powerpc",
423 .amdgcn => "amdgpu",
424 .riscv32, .riscv64 => "riscv",
425 .sparc, .sparcv9, .sparcel => "sparc",
426 .s390x => "systemz",
427 .i386, .x86_64 => "x86",
428 .nvptx, .nvptx64 => "nvptx",
429 .wasm32, .wasm64 => "wasm",
430 else => @tagName(arch),
431 };
432 }
433
434 /// All CPU features Zig is aware of, sorted lexicographically by name.
435 pub fn allFeaturesList(arch: Arch) []const Cpu.Feature {
436 return switch (arch) {
437 .arm, .armeb, .thumb, .thumbeb => &arm.all_features,
438 .aarch64, .aarch64_be, .aarch64_32 => &aarch64.all_features,
439 .avr => &avr.all_features,
440 .bpfel, .bpfeb => &bpf.all_features,
441 .hexagon => &hexagon.all_features,
442 .mips, .mipsel, .mips64, .mips64el => &mips.all_features,
443 .msp430 => &msp430.all_features,
444 .powerpc, .powerpc64, .powerpc64le => &powerpc.all_features,
445 .amdgcn => &amdgpu.all_features,
446 .riscv32, .riscv64 => &riscv.all_features,
447 .sparc, .sparcv9, .sparcel => &sparc.all_features,
448 .s390x => &systemz.all_features,
449 .i386, .x86_64 => &x86.all_features,
450 .nvptx, .nvptx64 => &nvptx.all_features,
451 .wasm32, .wasm64 => &wasm.all_features,
452
453 else => &[0]Cpu.Feature{},
454 };
455 }
456
457 /// The "default" set of CPU features for cross-compiling. A conservative set
458 /// of features that is expected to be supported on most available hardware.
459 pub fn getBaselineCpuFeatures(arch: Arch) CpuFeatures {
460 const S = struct {
461 const generic_cpu = Cpu{
462 .name = "generic",
463 .llvm_name = null,
464 .features = Cpu.Feature.Set.empty,
465 };
466 };
467 const cpu = switch (arch) {
468 .arm, .armeb, .thumb, .thumbeb => &arm.cpu.generic,
469 .aarch64, .aarch64_be, .aarch64_32 => &aarch64.cpu.generic,
470 .avr => &avr.cpu.avr1,
471 .bpfel, .bpfeb => &bpf.cpu.generic,
472 .hexagon => &hexagon.cpu.generic,
473 .mips, .mipsel => &mips.cpu.mips32,
474 .mips64, .mips64el => &mips.cpu.mips64,
475 .msp430 => &msp430.cpu.generic,
476 .powerpc, .powerpc64, .powerpc64le => &powerpc.cpu.generic,
477 .amdgcn => &amdgpu.cpu.generic,
478 .riscv32 => &riscv.cpu.baseline_rv32,
479 .riscv64 => &riscv.cpu.baseline_rv64,
480 .sparc, .sparcv9, .sparcel => &sparc.cpu.generic,
481 .s390x => &systemz.cpu.generic,
482 .i386 => &x86.cpu.pentium4,
483 .x86_64 => &x86.cpu.x86_64,
484 .nvptx, .nvptx64 => &nvptx.cpu.sm_20,
485 .wasm32, .wasm64 => &wasm.cpu.generic,
486
487 else => &S.generic_cpu,
488 };
489 return CpuFeatures.initFromCpu(arch, cpu);
490 }
491
492 /// All CPUs Zig is aware of, sorted lexicographically by name.
493 pub fn allCpus(arch: Arch) []const *const Cpu {
494 return switch (arch) {
495 .arm, .armeb, .thumb, .thumbeb => arm.all_cpus,
496 .aarch64, .aarch64_be, .aarch64_32 => aarch64.all_cpus,
497 .avr => avr.all_cpus,
498 .bpfel, .bpfeb => bpf.all_cpus,
499 .hexagon => hexagon.all_cpus,
500 .mips, .mipsel, .mips64, .mips64el => mips.all_cpus,
501 .msp430 => msp430.all_cpus,
502 .powerpc, .powerpc64, .powerpc64le => powerpc.all_cpus,
503 .amdgcn => amdgpu.all_cpus,
504 .riscv32, .riscv64 => riscv.all_cpus,
505 .sparc, .sparcv9, .sparcel => sparc.all_cpus,
506 .s390x => systemz.all_cpus,
507 .i386, .x86_64 => x86.all_cpus,
508 .nvptx, .nvptx64 => nvptx.all_cpus,
509 .wasm32, .wasm64 => wasm.all_cpus,
510
511 else => &[0]*const Cpu{},
512 };
513 }
303 };514 };
304515
305 pub const Abi = enum {516 pub const Abi = enum {
...@@ -325,6 +536,109 @@ pub const Target = union(enum) {...@@ -325,6 +536,109 @@ pub const Target = union(enum) {
325 macabi,536 macabi,
326 };537 };
327538
539 pub const Cpu = struct {
540 name: []const u8,
541 llvm_name: ?[:0]const u8,
542 features: Feature.Set,
543
544 pub const Feature = struct {
545 /// The bit index into `Set`. Has a default value of `undefined` because the canonical
546 /// structures are populated via comptime logic.
547 index: Set.Index = undefined,
548
549 /// Has a default value of `undefined` because the canonical
550 /// structures are populated via comptime logic.
551 name: []const u8 = undefined,
552
553 /// If this corresponds to an LLVM-recognized feature, this will be populated;
554 /// otherwise null.
555 llvm_name: ?[:0]const u8,
556
557 /// Human-friendly UTF-8 text.
558 description: []const u8,
559
560 /// Sparse `Set` of features this depends on.
561 dependencies: Set,
562
563 /// A bit set of all the features.
564 pub const Set = struct {
565 ints: [usize_count]usize,
566
567 pub const needed_bit_count = 174;
568 pub const byte_count = (needed_bit_count + 7) / 8;
569 pub const usize_count = (byte_count + (@sizeOf(usize) - 1)) / @sizeOf(usize);
570 pub const Index = std.math.Log2Int(@IntType(false, usize_count * @bitSizeOf(usize)));
571 pub const ShiftInt = std.math.Log2Int(usize);
572
573 pub const empty = Set{ .ints = [1]usize{0} ** usize_count };
574 pub fn empty_workaround() Set {
575 return Set{ .ints = [1]usize{0} ** usize_count };
576 }
577
578 pub fn isEnabled(set: Set, arch_feature_index: Index) bool {
579 const usize_index = arch_feature_index / @bitSizeOf(usize);
580 const bit_index = @intCast(ShiftInt, arch_feature_index % @bitSizeOf(usize));
581 return (set.ints[usize_index] & (@as(usize, 1) << bit_index)) != 0;
582 }
583
584 /// Adds the specified feature but not its dependencies.
585 pub fn addFeature(set: *Set, arch_feature_index: Index) void {
586 const usize_index = arch_feature_index / @bitSizeOf(usize);
587 const bit_index = @intCast(ShiftInt, arch_feature_index % @bitSizeOf(usize));
588 set.ints[usize_index] |= @as(usize, 1) << bit_index;
589 }
590
591 /// Removes the specified feature but not its dependents.
592 pub fn removeFeature(set: *Set, arch_feature_index: Index) void {
593 const usize_index = arch_feature_index / @bitSizeOf(usize);
594 const bit_index = @intCast(ShiftInt, arch_feature_index % @bitSizeOf(usize));
595 set.ints[usize_index] &= ~(@as(usize, 1) << bit_index);
596 }
597
598 pub fn populateDependencies(set: *Set, all_features_list: []const Cpu.Feature) void {
599 var old = set.ints;
600 while (true) {
601 for (all_features_list) |feature, index_usize| {
602 const index = @intCast(Index, index_usize);
603 if (set.isEnabled(index)) {
604 set.ints = @as(@Vector(usize_count, usize), set.ints) |
605 @as(@Vector(usize_count, usize), feature.dependencies.ints);
606 }
607 }
608 const nothing_changed = mem.eql(usize, &old, &set.ints);
609 if (nothing_changed) return;
610 old = set.ints;
611 }
612 }
613
614 pub fn asBytes(set: *const Set) *const [byte_count]u8 {
615 return @ptrCast(*const [byte_count]u8, &set.ints);
616 }
617
618 pub fn eql(set: Set, other: Set) bool {
619 return mem.eql(usize, &set.ints, &other.ints);
620 }
621 };
622
623 pub fn feature_set_fns(comptime F: type) type {
624 return struct {
625 /// Populates only the feature bits specified.
626 pub fn featureSet(features: []const F) Set {
627 var x = Set.empty_workaround(); // TODO remove empty_workaround
628 for (features) |feature| {
629 x.addFeature(@enumToInt(feature));
630 }
631 return x;
632 }
633
634 pub fn featureSetHas(set: Set, feature: F) bool {
635 return set.isEnabled(@enumToInt(feature));
636 }
637 };
638 }
639 };
640 };
641
328 pub const ObjectFormat = enum {642 pub const ObjectFormat = enum {
329 unknown,643 unknown,
330 coff,644 coff,
...@@ -348,6 +662,28 @@ pub const Target = union(enum) {...@@ -348,6 +662,28 @@ pub const Target = union(enum) {
348 arch: Arch,662 arch: Arch,
349 os: Os,663 os: Os,
350 abi: Abi,664 abi: Abi,
665 cpu_features: CpuFeatures,
666 };
667
668 pub const CpuFeatures = struct {
669 /// The CPU to target. It has a set of features
670 /// which are overridden with the `features` field.
671 cpu: *const Cpu,
672
673 /// Explicitly provide the entire CPU feature set.
674 features: Cpu.Feature.Set,
675
676 pub fn initFromCpu(arch: Arch, cpu: *const Cpu) CpuFeatures {
677 var features = cpu.features;
678 if (arch.subArchFeature()) |sub_arch_index| {
679 features.addFeature(sub_arch_index);
680 }
681 features.populateDependencies(arch.allFeaturesList());
682 return CpuFeatures{
683 .cpu = cpu,
684 .features = features,
685 };
686 }
351 };687 };
352688
353 pub const current = Target{689 pub const current = Target{
...@@ -355,11 +691,19 @@ pub const Target = union(enum) {...@@ -355,11 +691,19 @@ pub const Target = union(enum) {
355 .arch = builtin.arch,691 .arch = builtin.arch,
356 .os = builtin.os,692 .os = builtin.os,
357 .abi = builtin.abi,693 .abi = builtin.abi,
694 .cpu_features = builtin.cpu_features,
358 },695 },
359 };696 };
360697
361 pub const stack_align = 16;698 pub const stack_align = 16;
362699
700 pub fn getCpuFeatures(self: Target) CpuFeatures {
701 return switch (self) {
702 .Native => builtin.cpu_features,
703 .Cross => |cross| cross.cpu_features,
704 };
705 }
706
363 pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![]u8 {707 pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![]u8 {
364 return std.fmt.allocPrint(allocator, "{}{}-{}-{}", .{708 return std.fmt.allocPrint(allocator, "{}{}-{}-{}", .{
365 @tagName(self.getArch()),709 @tagName(self.getArch()),
...@@ -425,14 +769,18 @@ pub const Target = union(enum) {...@@ -425,14 +769,18 @@ pub const Target = union(enum) {
425 });769 });
426 }770 }
427771
772 /// TODO: Support CPU features here?
773 /// https://github.com/ziglang/zig/issues/4261
428 pub fn parse(text: []const u8) !Target {774 pub fn parse(text: []const u8) !Target {
429 var it = mem.separate(text, "-");775 var it = mem.separate(text, "-");
430 const arch_name = it.next() orelse return error.MissingArchitecture;776 const arch_name = it.next() orelse return error.MissingArchitecture;
431 const os_name = it.next() orelse return error.MissingOperatingSystem;777 const os_name = it.next() orelse return error.MissingOperatingSystem;
432 const abi_name = it.next();778 const abi_name = it.next();
779 const arch = try parseArchSub(arch_name);
433780
434 var cross = Cross{781 var cross = Cross{
435 .arch = try parseArchSub(arch_name),782 .arch = arch,
783 .cpu_features = arch.getBaselineCpuFeatures(),
436 .os = try parseOs(os_name),784 .os = try parseOs(os_name),
437 .abi = undefined,785 .abi = undefined,
438 };786 };
...@@ -498,7 +846,7 @@ pub const Target = union(enum) {...@@ -498,7 +846,7 @@ pub const Target = union(enum) {
498 pub fn parseArchSub(text: []const u8) ParseArchSubError!Arch {846 pub fn parseArchSub(text: []const u8) ParseArchSubError!Arch {
499 const info = @typeInfo(Arch);847 const info = @typeInfo(Arch);
500 inline for (info.Union.fields) |field| {848 inline for (info.Union.fields) |field| {
501 if (mem.eql(u8, text, field.name)) {849 if (mem.startsWith(u8, text, field.name)) {
502 if (field.field_type == void) {850 if (field.field_type == void) {
503 return @as(Arch, @field(Arch, field.name));851 return @as(Arch, @field(Arch, field.name));
504 } else {852 } else {
...@@ -819,3 +1167,15 @@ pub const Target = union(enum) {...@@ -819,3 +1167,15 @@ pub const Target = union(enum) {
819 return .unavailable;1167 return .unavailable;
820 }1168 }
821};1169};
1170
1171test "parseCpuFeatureSet" {
1172 const arch: Target.Arch = .x86_64;
1173 const baseline = arch.getBaselineCpuFeatures();
1174 const set = try arch.parseCpuFeatureSet(baseline.cpu, "-sse,-avx,-cx8");
1175 std.testing.expect(!Target.x86.featureSetHas(set, .sse));
1176 std.testing.expect(!Target.x86.featureSetHas(set, .avx));
1177 std.testing.expect(!Target.x86.featureSetHas(set, .cx8));
1178 // These are expected because they are part of the baseline
1179 std.testing.expect(Target.x86.featureSetHas(set, .cmov));
1180 std.testing.expect(Target.x86.featureSetHas(set, .fxsr));
1181}
lib/std/target/aarch64.zig created+1450
...@@ -0,0 +1,1450 @@
1const std = @import("../std.zig");
2const Cpu = std.Target.Cpu;
3
4pub const Feature = enum {
5 a35,
6 a53,
7 a55,
8 a57,
9 a72,
10 a73,
11 a75,
12 a76,
13 aes,
14 aggressive_fma,
15 alternate_sextload_cvt_f32_pattern,
16 altnzcv,
17 am,
18 arith_bcc_fusion,
19 arith_cbz_fusion,
20 balance_fp_ops,
21 bti,
22 call_saved_x10,
23 call_saved_x11,
24 call_saved_x12,
25 call_saved_x13,
26 call_saved_x14,
27 call_saved_x15,
28 call_saved_x18,
29 call_saved_x8,
30 call_saved_x9,
31 ccdp,
32 ccidx,
33 ccpp,
34 complxnum,
35 crc,
36 crypto,
37 custom_cheap_as_move,
38 cyclone,
39 disable_latency_sched_heuristic,
40 dit,
41 dotprod,
42 exynos_cheap_as_move,
43 exynosm1,
44 exynosm2,
45 exynosm3,
46 exynosm4,
47 falkor,
48 fmi,
49 force_32bit_jump_tables,
50 fp_armv8,
51 fp16fml,
52 fptoint,
53 fullfp16,
54 fuse_address,
55 fuse_aes,
56 fuse_arith_logic,
57 fuse_crypto_eor,
58 fuse_csel,
59 fuse_literals,
60 jsconv,
61 kryo,
62 lor,
63 lse,
64 lsl_fast,
65 mpam,
66 mte,
67 neon,
68 no_neg_immediates,
69 nv,
70 pa,
71 pan,
72 pan_rwv,
73 perfmon,
74 predictable_select_expensive,
75 predres,
76 rand,
77 ras,
78 rasv8_4,
79 rcpc,
80 rcpc_immo,
81 rdm,
82 reserve_x1,
83 reserve_x10,
84 reserve_x11,
85 reserve_x12,
86 reserve_x13,
87 reserve_x14,
88 reserve_x15,
89 reserve_x18,
90 reserve_x2,
91 reserve_x20,
92 reserve_x21,
93 reserve_x22,
94 reserve_x23,
95 reserve_x24,
96 reserve_x25,
97 reserve_x26,
98 reserve_x27,
99 reserve_x28,
100 reserve_x3,
101 reserve_x4,
102 reserve_x5,
103 reserve_x6,
104 reserve_x7,
105 reserve_x9,
106 saphira,
107 sb,
108 sel2,
109 sha2,
110 sha3,
111 slow_misaligned_128store,
112 slow_paired_128,
113 slow_strqro_store,
114 sm4,
115 spe,
116 specrestrict,
117 ssbs,
118 strict_align,
119 sve,
120 sve2,
121 sve2_aes,
122 sve2_bitperm,
123 sve2_sha3,
124 sve2_sm4,
125 thunderx,
126 thunderx2t99,
127 thunderxt81,
128 thunderxt83,
129 thunderxt88,
130 tlb_rmi,
131 tpidr_el1,
132 tpidr_el2,
133 tpidr_el3,
134 tracev8_4,
135 tsv110,
136 uaops,
137 use_aa,
138 use_postra_scheduler,
139 use_reciprocal_square_root,
140 v8a,
141 v8_1a,
142 v8_2a,
143 v8_3a,
144 v8_4a,
145 v8_5a,
146 vh,
147 zcm,
148 zcz,
149 zcz_fp,
150 zcz_fp_workaround,
151 zcz_gp,
152};
153
154pub usingnamespace Cpu.Feature.feature_set_fns(Feature);
155
156pub const all_features = blk: {
157 @setEvalBranchQuota(2000);
158 const len = @typeInfo(Feature).Enum.fields.len;
159 std.debug.assert(len <= Cpu.Feature.Set.needed_bit_count);
160 var result: [len]Cpu.Feature = undefined;
161 result[@enumToInt(Feature.a35)] = .{
162 .llvm_name = "a35",
163 .description = "Cortex-A35 ARM processors",
164 .dependencies = featureSet(&[_]Feature{
165 .crc,
166 .crypto,
167 .fp_armv8,
168 .neon,
169 .perfmon,
170 }),
171 };
172 result[@enumToInt(Feature.a53)] = .{
173 .llvm_name = "a53",
174 .description = "Cortex-A53 ARM processors",
175 .dependencies = featureSet(&[_]Feature{
176 .balance_fp_ops,
177 .crc,
178 .crypto,
179 .custom_cheap_as_move,
180 .fp_armv8,
181 .fuse_aes,
182 .neon,
183 .perfmon,
184 .use_aa,
185 .use_postra_scheduler,
186 }),
187 };
188 result[@enumToInt(Feature.a55)] = .{
189 .llvm_name = "a55",
190 .description = "Cortex-A55 ARM processors",
191 .dependencies = featureSet(&[_]Feature{
192 .crypto,
193 .dotprod,
194 .fp_armv8,
195 .fullfp16,
196 .fuse_aes,
197 .neon,
198 .perfmon,
199 .rcpc,
200 .v8_2a,
201 }),
202 };
203 result[@enumToInt(Feature.a57)] = .{
204 .llvm_name = "a57",
205 .description = "Cortex-A57 ARM processors",
206 .dependencies = featureSet(&[_]Feature{
207 .balance_fp_ops,
208 .crc,
209 .crypto,
210 .custom_cheap_as_move,
211 .fp_armv8,
212 .fuse_aes,
213 .fuse_literals,
214 .neon,
215 .perfmon,
216 .predictable_select_expensive,
217 .use_postra_scheduler,
218 }),
219 };
220 result[@enumToInt(Feature.a72)] = .{
221 .llvm_name = "a72",
222 .description = "Cortex-A72 ARM processors",
223 .dependencies = featureSet(&[_]Feature{
224 .crc,
225 .crypto,
226 .fp_armv8,
227 .fuse_aes,
228 .neon,
229 .perfmon,
230 }),
231 };
232 result[@enumToInt(Feature.a73)] = .{
233 .llvm_name = "a73",
234 .description = "Cortex-A73 ARM processors",
235 .dependencies = featureSet(&[_]Feature{
236 .crc,
237 .crypto,
238 .fp_armv8,
239 .fuse_aes,
240 .neon,
241 .perfmon,
242 }),
243 };
244 result[@enumToInt(Feature.a75)] = .{
245 .llvm_name = "a75",
246 .description = "Cortex-A75 ARM processors",
247 .dependencies = featureSet(&[_]Feature{
248 .crypto,
249 .dotprod,
250 .fp_armv8,
251 .fullfp16,
252 .fuse_aes,
253 .neon,
254 .perfmon,
255 .rcpc,
256 .v8_2a,
257 }),
258 };
259 result[@enumToInt(Feature.a76)] = .{
260 .llvm_name = "a76",
261 .description = "Cortex-A76 ARM processors",
262 .dependencies = featureSet(&[_]Feature{
263 .crypto,
264 .dotprod,
265 .fp_armv8,
266 .fullfp16,
267 .neon,
268 .rcpc,
269 .ssbs,
270 .v8_2a,
271 }),
272 };
273 result[@enumToInt(Feature.aes)] = .{
274 .llvm_name = "aes",
275 .description = "Enable AES support",
276 .dependencies = featureSet(&[_]Feature{
277 .neon,
278 }),
279 };
280 result[@enumToInt(Feature.aggressive_fma)] = .{
281 .llvm_name = "aggressive-fma",
282 .description = "Enable Aggressive FMA for floating-point.",
283 .dependencies = featureSet(&[_]Feature{}),
284 };
285 result[@enumToInt(Feature.alternate_sextload_cvt_f32_pattern)] = .{
286 .llvm_name = "alternate-sextload-cvt-f32-pattern",
287 .description = "Use alternative pattern for sextload convert to f32",
288 .dependencies = featureSet(&[_]Feature{}),
289 };
290 result[@enumToInt(Feature.altnzcv)] = .{
291 .llvm_name = "altnzcv",
292 .description = "Enable alternative NZCV format for floating point comparisons",
293 .dependencies = featureSet(&[_]Feature{}),
294 };
295 result[@enumToInt(Feature.am)] = .{
296 .llvm_name = "am",
297 .description = "Enable v8.4-A Activity Monitors extension",
298 .dependencies = featureSet(&[_]Feature{}),
299 };
300 result[@enumToInt(Feature.arith_bcc_fusion)] = .{
301 .llvm_name = "arith-bcc-fusion",
302 .description = "CPU fuses arithmetic+bcc operations",
303 .dependencies = featureSet(&[_]Feature{}),
304 };
305 result[@enumToInt(Feature.arith_cbz_fusion)] = .{
306 .llvm_name = "arith-cbz-fusion",
307 .description = "CPU fuses arithmetic + cbz/cbnz operations",
308 .dependencies = featureSet(&[_]Feature{}),
309 };
310 result[@enumToInt(Feature.balance_fp_ops)] = .{
311 .llvm_name = "balance-fp-ops",
312 .description = "balance mix of odd and even D-registers for fp multiply(-accumulate) ops",
313 .dependencies = featureSet(&[_]Feature{}),
314 };
315 result[@enumToInt(Feature.bti)] = .{
316 .llvm_name = "bti",
317 .description = "Enable Branch Target Identification",
318 .dependencies = featureSet(&[_]Feature{}),
319 };
320 result[@enumToInt(Feature.call_saved_x10)] = .{
321 .llvm_name = "call-saved-x10",
322 .description = "Make X10 callee saved.",
323 .dependencies = featureSet(&[_]Feature{}),
324 };
325 result[@enumToInt(Feature.call_saved_x11)] = .{
326 .llvm_name = "call-saved-x11",
327 .description = "Make X11 callee saved.",
328 .dependencies = featureSet(&[_]Feature{}),
329 };
330 result[@enumToInt(Feature.call_saved_x12)] = .{
331 .llvm_name = "call-saved-x12",
332 .description = "Make X12 callee saved.",
333 .dependencies = featureSet(&[_]Feature{}),
334 };
335 result[@enumToInt(Feature.call_saved_x13)] = .{
336 .llvm_name = "call-saved-x13",
337 .description = "Make X13 callee saved.",
338 .dependencies = featureSet(&[_]Feature{}),
339 };
340 result[@enumToInt(Feature.call_saved_x14)] = .{
341 .llvm_name = "call-saved-x14",
342 .description = "Make X14 callee saved.",
343 .dependencies = featureSet(&[_]Feature{}),
344 };
345 result[@enumToInt(Feature.call_saved_x15)] = .{
346 .llvm_name = "call-saved-x15",
347 .description = "Make X15 callee saved.",
348 .dependencies = featureSet(&[_]Feature{}),
349 };
350 result[@enumToInt(Feature.call_saved_x18)] = .{
351 .llvm_name = "call-saved-x18",
352 .description = "Make X18 callee saved.",
353 .dependencies = featureSet(&[_]Feature{}),
354 };
355 result[@enumToInt(Feature.call_saved_x8)] = .{
356 .llvm_name = "call-saved-x8",
357 .description = "Make X8 callee saved.",
358 .dependencies = featureSet(&[_]Feature{}),
359 };
360 result[@enumToInt(Feature.call_saved_x9)] = .{
361 .llvm_name = "call-saved-x9",
362 .description = "Make X9 callee saved.",
363 .dependencies = featureSet(&[_]Feature{}),
364 };
365 result[@enumToInt(Feature.ccdp)] = .{
366 .llvm_name = "ccdp",
367 .description = "Enable v8.5 Cache Clean to Point of Deep Persistence",
368 .dependencies = featureSet(&[_]Feature{}),
369 };
370 result[@enumToInt(Feature.ccidx)] = .{
371 .llvm_name = "ccidx",
372 .description = "Enable v8.3-A Extend of the CCSIDR number of sets",
373 .dependencies = featureSet(&[_]Feature{}),
374 };
375 result[@enumToInt(Feature.ccpp)] = .{
376 .llvm_name = "ccpp",
377 .description = "Enable v8.2 data Cache Clean to Point of Persistence",
378 .dependencies = featureSet(&[_]Feature{}),
379 };
380 result[@enumToInt(Feature.complxnum)] = .{
381 .llvm_name = "complxnum",
382 .description = "Enable v8.3-A Floating-point complex number support",
383 .dependencies = featureSet(&[_]Feature{
384 .neon,
385 }),
386 };
387 result[@enumToInt(Feature.crc)] = .{
388 .llvm_name = "crc",
389 .description = "Enable ARMv8 CRC-32 checksum instructions",
390 .dependencies = featureSet(&[_]Feature{}),
391 };
392 result[@enumToInt(Feature.crypto)] = .{
393 .llvm_name = "crypto",
394 .description = "Enable cryptographic instructions",
395 .dependencies = featureSet(&[_]Feature{
396 .aes,
397 .neon,
398 .sha2,
399 }),
400 };
401 result[@enumToInt(Feature.custom_cheap_as_move)] = .{
402 .llvm_name = "custom-cheap-as-move",
403 .description = "Use custom handling of cheap instructions",
404 .dependencies = featureSet(&[_]Feature{}),
405 };
406 result[@enumToInt(Feature.cyclone)] = .{
407 .llvm_name = "cyclone",
408 .description = "Cyclone",
409 .dependencies = featureSet(&[_]Feature{
410 .alternate_sextload_cvt_f32_pattern,
411 .arith_bcc_fusion,
412 .arith_cbz_fusion,
413 .crypto,
414 .disable_latency_sched_heuristic,
415 .fp_armv8,
416 .fuse_aes,
417 .fuse_crypto_eor,
418 .neon,
419 .perfmon,
420 .zcm,
421 .zcz,
422 .zcz_fp_workaround,
423 }),
424 };
425 result[@enumToInt(Feature.disable_latency_sched_heuristic)] = .{
426 .llvm_name = "disable-latency-sched-heuristic",
427 .description = "Disable latency scheduling heuristic",
428 .dependencies = featureSet(&[_]Feature{}),
429 };
430 result[@enumToInt(Feature.dit)] = .{
431 .llvm_name = "dit",
432 .description = "Enable v8.4-A Data Independent Timing instructions",
433 .dependencies = featureSet(&[_]Feature{}),
434 };
435 result[@enumToInt(Feature.dotprod)] = .{
436 .llvm_name = "dotprod",
437 .description = "Enable dot product support",
438 .dependencies = featureSet(&[_]Feature{}),
439 };
440 result[@enumToInt(Feature.exynos_cheap_as_move)] = .{
441 .llvm_name = "exynos-cheap-as-move",
442 .description = "Use Exynos specific handling of cheap instructions",
443 .dependencies = featureSet(&[_]Feature{
444 .custom_cheap_as_move,
445 }),
446 };
447 result[@enumToInt(Feature.exynosm1)] = .{
448 .llvm_name = "exynosm1",
449 .description = "Samsung Exynos-M1 processors",
450 .dependencies = featureSet(&[_]Feature{
451 .crc,
452 .crypto,
453 .exynos_cheap_as_move,
454 .force_32bit_jump_tables,
455 .fuse_aes,
456 .perfmon,
457 .slow_misaligned_128store,
458 .slow_paired_128,
459 .use_postra_scheduler,
460 .use_reciprocal_square_root,
461 .zcz_fp,
462 }),
463 };
464 result[@enumToInt(Feature.exynosm2)] = .{
465 .llvm_name = "exynosm2",
466 .description = "Samsung Exynos-M2 processors",
467 .dependencies = featureSet(&[_]Feature{
468 .crc,
469 .crypto,
470 .exynos_cheap_as_move,
471 .force_32bit_jump_tables,
472 .fuse_aes,
473 .perfmon,
474 .slow_misaligned_128store,
475 .slow_paired_128,
476 .use_postra_scheduler,
477 .zcz_fp,
478 }),
479 };
480 result[@enumToInt(Feature.exynosm3)] = .{
481 .llvm_name = "exynosm3",
482 .description = "Samsung Exynos-M3 processors",
483 .dependencies = featureSet(&[_]Feature{
484 .crc,
485 .crypto,
486 .exynos_cheap_as_move,
487 .force_32bit_jump_tables,
488 .fuse_address,
489 .fuse_aes,
490 .fuse_csel,
491 .fuse_literals,
492 .lsl_fast,
493 .perfmon,
494 .predictable_select_expensive,
495 .use_postra_scheduler,
496 .zcz_fp,
497 }),
498 };
499 result[@enumToInt(Feature.exynosm4)] = .{
500 .llvm_name = "exynosm4",
501 .description = "Samsung Exynos-M4 processors",
502 .dependencies = featureSet(&[_]Feature{
503 .arith_bcc_fusion,
504 .arith_cbz_fusion,
505 .crypto,
506 .dotprod,
507 .exynos_cheap_as_move,
508 .force_32bit_jump_tables,
509 .fullfp16,
510 .fuse_address,
511 .fuse_aes,
512 .fuse_arith_logic,
513 .fuse_csel,
514 .fuse_literals,
515 .lsl_fast,
516 .perfmon,
517 .use_postra_scheduler,
518 .v8_2a,
519 .zcz,
520 }),
521 };
522 result[@enumToInt(Feature.falkor)] = .{
523 .llvm_name = "falkor",
524 .description = "Qualcomm Falkor processors",
525 .dependencies = featureSet(&[_]Feature{
526 .crc,
527 .crypto,
528 .custom_cheap_as_move,
529 .fp_armv8,
530 .lsl_fast,
531 .neon,
532 .perfmon,
533 .predictable_select_expensive,
534 .rdm,
535 .slow_strqro_store,
536 .use_postra_scheduler,
537 .zcz,
538 }),
539 };
540 result[@enumToInt(Feature.fmi)] = .{
541 .llvm_name = "fmi",
542 .description = "Enable v8.4-A Flag Manipulation Instructions",
543 .dependencies = featureSet(&[_]Feature{}),
544 };
545 result[@enumToInt(Feature.force_32bit_jump_tables)] = .{
546 .llvm_name = "force-32bit-jump-tables",
547 .description = "Force jump table entries to be 32-bits wide except at MinSize",
548 .dependencies = featureSet(&[_]Feature{}),
549 };
550 result[@enumToInt(Feature.fp_armv8)] = .{
551 .llvm_name = "fp-armv8",
552 .description = "Enable ARMv8 FP",
553 .dependencies = featureSet(&[_]Feature{}),
554 };
555 result[@enumToInt(Feature.fp16fml)] = .{
556 .llvm_name = "fp16fml",
557 .description = "Enable FP16 FML instructions",
558 .dependencies = featureSet(&[_]Feature{
559 .fullfp16,
560 }),
561 };
562 result[@enumToInt(Feature.fptoint)] = .{
563 .llvm_name = "fptoint",
564 .description = "Enable FRInt[32|64][Z|X] instructions that round a floating-point number to an integer (in FP format) forcing it to fit into a 32- or 64-bit int",
565 .dependencies = featureSet(&[_]Feature{}),
566 };
567 result[@enumToInt(Feature.fullfp16)] = .{
568 .llvm_name = "fullfp16",
569 .description = "Full FP16",
570 .dependencies = featureSet(&[_]Feature{
571 .fp_armv8,
572 }),
573 };
574 result[@enumToInt(Feature.fuse_address)] = .{
575 .llvm_name = "fuse-address",
576 .description = "CPU fuses address generation and memory operations",
577 .dependencies = featureSet(&[_]Feature{}),
578 };
579 result[@enumToInt(Feature.fuse_aes)] = .{
580 .llvm_name = "fuse-aes",
581 .description = "CPU fuses AES crypto operations",
582 .dependencies = featureSet(&[_]Feature{}),
583 };
584 result[@enumToInt(Feature.fuse_arith_logic)] = .{
585 .llvm_name = "fuse-arith-logic",
586 .description = "CPU fuses arithmetic and logic operations",
587 .dependencies = featureSet(&[_]Feature{}),
588 };
589 result[@enumToInt(Feature.fuse_crypto_eor)] = .{
590 .llvm_name = "fuse-crypto-eor",
591 .description = "CPU fuses AES/PMULL and EOR operations",
592 .dependencies = featureSet(&[_]Feature{}),
593 };
594 result[@enumToInt(Feature.fuse_csel)] = .{
595 .llvm_name = "fuse-csel",
596 .description = "CPU fuses conditional select operations",
597 .dependencies = featureSet(&[_]Feature{}),
598 };
599 result[@enumToInt(Feature.fuse_literals)] = .{
600 .llvm_name = "fuse-literals",
601 .description = "CPU fuses literal generation operations",
602 .dependencies = featureSet(&[_]Feature{}),
603 };
604 result[@enumToInt(Feature.jsconv)] = .{
605 .llvm_name = "jsconv",
606 .description = "Enable v8.3-A JavaScript FP conversion enchancement",
607 .dependencies = featureSet(&[_]Feature{
608 .fp_armv8,
609 }),
610 };
611 result[@enumToInt(Feature.kryo)] = .{
612 .llvm_name = "kryo",
613 .description = "Qualcomm Kryo processors",
614 .dependencies = featureSet(&[_]Feature{
615 .crc,
616 .crypto,
617 .custom_cheap_as_move,
618 .fp_armv8,
619 .lsl_fast,
620 .neon,
621 .perfmon,
622 .predictable_select_expensive,
623 .use_postra_scheduler,
624 .zcz,
625 }),
626 };
627 result[@enumToInt(Feature.lor)] = .{
628 .llvm_name = "lor",
629 .description = "Enables ARM v8.1 Limited Ordering Regions extension",
630 .dependencies = featureSet(&[_]Feature{}),
631 };
632 result[@enumToInt(Feature.lse)] = .{
633 .llvm_name = "lse",
634 .description = "Enable ARMv8.1 Large System Extension (LSE) atomic instructions",
635 .dependencies = featureSet(&[_]Feature{}),
636 };
637 result[@enumToInt(Feature.lsl_fast)] = .{
638 .llvm_name = "lsl-fast",
639 .description = "CPU has a fastpath logical shift of up to 3 places",
640 .dependencies = featureSet(&[_]Feature{}),
641 };
642 result[@enumToInt(Feature.mpam)] = .{
643 .llvm_name = "mpam",
644 .description = "Enable v8.4-A Memory system Partitioning and Monitoring extension",
645 .dependencies = featureSet(&[_]Feature{}),
646 };
647 result[@enumToInt(Feature.mte)] = .{
648 .llvm_name = "mte",
649 .description = "Enable Memory Tagging Extension",
650 .dependencies = featureSet(&[_]Feature{}),
651 };
652 result[@enumToInt(Feature.neon)] = .{
653 .llvm_name = "neon",
654 .description = "Enable Advanced SIMD instructions",
655 .dependencies = featureSet(&[_]Feature{
656 .fp_armv8,
657 }),
658 };
659 result[@enumToInt(Feature.no_neg_immediates)] = .{
660 .llvm_name = "no-neg-immediates",
661 .description = "Convert immediates and instructions to their negated or complemented equivalent when the immediate does not fit in the encoding.",
662 .dependencies = featureSet(&[_]Feature{}),
663 };
664 result[@enumToInt(Feature.nv)] = .{
665 .llvm_name = "nv",
666 .description = "Enable v8.4-A Nested Virtualization Enchancement",
667 .dependencies = featureSet(&[_]Feature{}),
668 };
669 result[@enumToInt(Feature.pa)] = .{
670 .llvm_name = "pa",
671 .description = "Enable v8.3-A Pointer Authentication enchancement",
672 .dependencies = featureSet(&[_]Feature{}),
673 };
674 result[@enumToInt(Feature.pan)] = .{
675 .llvm_name = "pan",
676 .description = "Enables ARM v8.1 Privileged Access-Never extension",
677 .dependencies = featureSet(&[_]Feature{}),
678 };
679 result[@enumToInt(Feature.pan_rwv)] = .{
680 .llvm_name = "pan-rwv",
681 .description = "Enable v8.2 PAN s1e1R and s1e1W Variants",
682 .dependencies = featureSet(&[_]Feature{
683 .pan,
684 }),
685 };
686 result[@enumToInt(Feature.perfmon)] = .{
687 .llvm_name = "perfmon",
688 .description = "Enable ARMv8 PMUv3 Performance Monitors extension",
689 .dependencies = featureSet(&[_]Feature{}),
690 };
691 result[@enumToInt(Feature.predictable_select_expensive)] = .{
692 .llvm_name = "predictable-select-expensive",
693 .description = "Prefer likely predicted branches over selects",
694 .dependencies = featureSet(&[_]Feature{}),
695 };
696 result[@enumToInt(Feature.predres)] = .{
697 .llvm_name = "predres",
698 .description = "Enable v8.5a execution and data prediction invalidation instructions",
699 .dependencies = featureSet(&[_]Feature{}),
700 };
701 result[@enumToInt(Feature.rand)] = .{
702 .llvm_name = "rand",
703 .description = "Enable Random Number generation instructions",
704 .dependencies = featureSet(&[_]Feature{}),
705 };
706 result[@enumToInt(Feature.ras)] = .{
707 .llvm_name = "ras",
708 .description = "Enable ARMv8 Reliability, Availability and Serviceability Extensions",
709 .dependencies = featureSet(&[_]Feature{}),
710 };
711 result[@enumToInt(Feature.rasv8_4)] = .{
712 .llvm_name = "rasv8_4",
713 .description = "Enable v8.4-A Reliability, Availability and Serviceability extension",
714 .dependencies = featureSet(&[_]Feature{
715 .ras,
716 }),
717 };
718 result[@enumToInt(Feature.rcpc)] = .{
719 .llvm_name = "rcpc",
720 .description = "Enable support for RCPC extension",
721 .dependencies = featureSet(&[_]Feature{}),
722 };
723 result[@enumToInt(Feature.rcpc_immo)] = .{
724 .llvm_name = "rcpc-immo",
725 .description = "Enable v8.4-A RCPC instructions with Immediate Offsets",
726 .dependencies = featureSet(&[_]Feature{
727 .rcpc,
728 }),
729 };
730 result[@enumToInt(Feature.rdm)] = .{
731 .llvm_name = "rdm",
732 .description = "Enable ARMv8.1 Rounding Double Multiply Add/Subtract instructions",
733 .dependencies = featureSet(&[_]Feature{}),
734 };
735 result[@enumToInt(Feature.reserve_x1)] = .{
736 .llvm_name = "reserve-x1",
737 .description = "Reserve X1, making it unavailable as a GPR",
738 .dependencies = featureSet(&[_]Feature{}),
739 };
740 result[@enumToInt(Feature.reserve_x10)] = .{
741 .llvm_name = "reserve-x10",
742 .description = "Reserve X10, making it unavailable as a GPR",
743 .dependencies = featureSet(&[_]Feature{}),
744 };
745 result[@enumToInt(Feature.reserve_x11)] = .{
746 .llvm_name = "reserve-x11",
747 .description = "Reserve X11, making it unavailable as a GPR",
748 .dependencies = featureSet(&[_]Feature{}),
749 };
750 result[@enumToInt(Feature.reserve_x12)] = .{
751 .llvm_name = "reserve-x12",
752 .description = "Reserve X12, making it unavailable as a GPR",
753 .dependencies = featureSet(&[_]Feature{}),
754 };
755 result[@enumToInt(Feature.reserve_x13)] = .{
756 .llvm_name = "reserve-x13",
757 .description = "Reserve X13, making it unavailable as a GPR",
758 .dependencies = featureSet(&[_]Feature{}),
759 };
760 result[@enumToInt(Feature.reserve_x14)] = .{
761 .llvm_name = "reserve-x14",
762 .description = "Reserve X14, making it unavailable as a GPR",
763 .dependencies = featureSet(&[_]Feature{}),
764 };
765 result[@enumToInt(Feature.reserve_x15)] = .{
766 .llvm_name = "reserve-x15",
767 .description = "Reserve X15, making it unavailable as a GPR",
768 .dependencies = featureSet(&[_]Feature{}),
769 };
770 result[@enumToInt(Feature.reserve_x18)] = .{
771 .llvm_name = "reserve-x18",
772 .description = "Reserve X18, making it unavailable as a GPR",
773 .dependencies = featureSet(&[_]Feature{}),
774 };
775 result[@enumToInt(Feature.reserve_x2)] = .{
776 .llvm_name = "reserve-x2",
777 .description = "Reserve X2, making it unavailable as a GPR",
778 .dependencies = featureSet(&[_]Feature{}),
779 };
780 result[@enumToInt(Feature.reserve_x20)] = .{
781 .llvm_name = "reserve-x20",
782 .description = "Reserve X20, making it unavailable as a GPR",
783 .dependencies = featureSet(&[_]Feature{}),
784 };
785 result[@enumToInt(Feature.reserve_x21)] = .{
786 .llvm_name = "reserve-x21",
787 .description = "Reserve X21, making it unavailable as a GPR",
788 .dependencies = featureSet(&[_]Feature{}),
789 };
790 result[@enumToInt(Feature.reserve_x22)] = .{
791 .llvm_name = "reserve-x22",
792 .description = "Reserve X22, making it unavailable as a GPR",
793 .dependencies = featureSet(&[_]Feature{}),
794 };
795 result[@enumToInt(Feature.reserve_x23)] = .{
796 .llvm_name = "reserve-x23",
797 .description = "Reserve X23, making it unavailable as a GPR",
798 .dependencies = featureSet(&[_]Feature{}),
799 };
800 result[@enumToInt(Feature.reserve_x24)] = .{
801 .llvm_name = "reserve-x24",
802 .description = "Reserve X24, making it unavailable as a GPR",
803 .dependencies = featureSet(&[_]Feature{}),
804 };
805 result[@enumToInt(Feature.reserve_x25)] = .{
806 .llvm_name = "reserve-x25",
807 .description = "Reserve X25, making it unavailable as a GPR",
808 .dependencies = featureSet(&[_]Feature{}),
809 };
810 result[@enumToInt(Feature.reserve_x26)] = .{
811 .llvm_name = "reserve-x26",
812 .description = "Reserve X26, making it unavailable as a GPR",
813 .dependencies = featureSet(&[_]Feature{}),
814 };
815 result[@enumToInt(Feature.reserve_x27)] = .{
816 .llvm_name = "reserve-x27",
817 .description = "Reserve X27, making it unavailable as a GPR",
818 .dependencies = featureSet(&[_]Feature{}),
819 };
820 result[@enumToInt(Feature.reserve_x28)] = .{
821 .llvm_name = "reserve-x28",
822 .description = "Reserve X28, making it unavailable as a GPR",
823 .dependencies = featureSet(&[_]Feature{}),
824 };
825 result[@enumToInt(Feature.reserve_x3)] = .{
826 .llvm_name = "reserve-x3",
827 .description = "Reserve X3, making it unavailable as a GPR",
828 .dependencies = featureSet(&[_]Feature{}),
829 };
830 result[@enumToInt(Feature.reserve_x4)] = .{
831 .llvm_name = "reserve-x4",
832 .description = "Reserve X4, making it unavailable as a GPR",
833 .dependencies = featureSet(&[_]Feature{}),
834 };
835 result[@enumToInt(Feature.reserve_x5)] = .{
836 .llvm_name = "reserve-x5",
837 .description = "Reserve X5, making it unavailable as a GPR",
838 .dependencies = featureSet(&[_]Feature{}),
839 };
840 result[@enumToInt(Feature.reserve_x6)] = .{
841 .llvm_name = "reserve-x6",
842 .description = "Reserve X6, making it unavailable as a GPR",
843 .dependencies = featureSet(&[_]Feature{}),
844 };
845 result[@enumToInt(Feature.reserve_x7)] = .{
846 .llvm_name = "reserve-x7",
847 .description = "Reserve X7, making it unavailable as a GPR",
848 .dependencies = featureSet(&[_]Feature{}),
849 };
850 result[@enumToInt(Feature.reserve_x9)] = .{
851 .llvm_name = "reserve-x9",
852 .description = "Reserve X9, making it unavailable as a GPR",
853 .dependencies = featureSet(&[_]Feature{}),
854 };
855 result[@enumToInt(Feature.saphira)] = .{
856 .llvm_name = "saphira",
857 .description = "Qualcomm Saphira processors",
858 .dependencies = featureSet(&[_]Feature{
859 .crypto,
860 .custom_cheap_as_move,
861 .fp_armv8,
862 .lsl_fast,
863 .neon,
864 .perfmon,
865 .predictable_select_expensive,
866 .spe,
867 .use_postra_scheduler,
868 .v8_4a,
869 .zcz,
870 }),
871 };
872 result[@enumToInt(Feature.sb)] = .{
873 .llvm_name = "sb",
874 .description = "Enable v8.5 Speculation Barrier",
875 .dependencies = featureSet(&[_]Feature{}),
876 };
877 result[@enumToInt(Feature.sel2)] = .{
878 .llvm_name = "sel2",
879 .description = "Enable v8.4-A Secure Exception Level 2 extension",
880 .dependencies = featureSet(&[_]Feature{}),
881 };
882 result[@enumToInt(Feature.sha2)] = .{
883 .llvm_name = "sha2",
884 .description = "Enable SHA1 and SHA256 support",
885 .dependencies = featureSet(&[_]Feature{
886 .neon,
887 }),
888 };
889 result[@enumToInt(Feature.sha3)] = .{
890 .llvm_name = "sha3",
891 .description = "Enable SHA512 and SHA3 support",
892 .dependencies = featureSet(&[_]Feature{
893 .neon,
894 .sha2,
895 }),
896 };
897 result[@enumToInt(Feature.slow_misaligned_128store)] = .{
898 .llvm_name = "slow-misaligned-128store",
899 .description = "Misaligned 128 bit stores are slow",
900 .dependencies = featureSet(&[_]Feature{}),
901 };
902 result[@enumToInt(Feature.slow_paired_128)] = .{
903 .llvm_name = "slow-paired-128",
904 .description = "Paired 128 bit loads and stores are slow",
905 .dependencies = featureSet(&[_]Feature{}),
906 };
907 result[@enumToInt(Feature.slow_strqro_store)] = .{
908 .llvm_name = "slow-strqro-store",
909 .description = "STR of Q register with register offset is slow",
910 .dependencies = featureSet(&[_]Feature{}),
911 };
912 result[@enumToInt(Feature.sm4)] = .{
913 .llvm_name = "sm4",
914 .description = "Enable SM3 and SM4 support",
915 .dependencies = featureSet(&[_]Feature{
916 .neon,
917 }),
918 };
919 result[@enumToInt(Feature.spe)] = .{
920 .llvm_name = "spe",
921 .description = "Enable Statistical Profiling extension",
922 .dependencies = featureSet(&[_]Feature{}),
923 };
924 result[@enumToInt(Feature.specrestrict)] = .{
925 .llvm_name = "specrestrict",
926 .description = "Enable architectural speculation restriction",
927 .dependencies = featureSet(&[_]Feature{}),
928 };
929 result[@enumToInt(Feature.ssbs)] = .{
930 .llvm_name = "ssbs",
931 .description = "Enable Speculative Store Bypass Safe bit",
932 .dependencies = featureSet(&[_]Feature{}),
933 };
934 result[@enumToInt(Feature.strict_align)] = .{
935 .llvm_name = "strict-align",
936 .description = "Disallow all unaligned memory access",
937 .dependencies = featureSet(&[_]Feature{}),
938 };
939 result[@enumToInt(Feature.sve)] = .{
940 .llvm_name = "sve",
941 .description = "Enable Scalable Vector Extension (SVE) instructions",
942 .dependencies = featureSet(&[_]Feature{}),
943 };
944 result[@enumToInt(Feature.sve2)] = .{
945 .llvm_name = "sve2",
946 .description = "Enable Scalable Vector Extension 2 (SVE2) instructions",
947 .dependencies = featureSet(&[_]Feature{
948 .sve,
949 }),
950 };
951 result[@enumToInt(Feature.sve2_aes)] = .{
952 .llvm_name = "sve2-aes",
953 .description = "Enable AES SVE2 instructions",
954 .dependencies = featureSet(&[_]Feature{
955 .aes,
956 .sve2,
957 }),
958 };
959 result[@enumToInt(Feature.sve2_bitperm)] = .{
960 .llvm_name = "sve2-bitperm",
961 .description = "Enable bit permutation SVE2 instructions",
962 .dependencies = featureSet(&[_]Feature{
963 .sve2,
964 }),
965 };
966 result[@enumToInt(Feature.sve2_sha3)] = .{
967 .llvm_name = "sve2-sha3",
968 .description = "Enable SHA3 SVE2 instructions",
969 .dependencies = featureSet(&[_]Feature{
970 .sha3,
971 .sve2,
972 }),
973 };
974 result[@enumToInt(Feature.sve2_sm4)] = .{
975 .llvm_name = "sve2-sm4",
976 .description = "Enable SM4 SVE2 instructions",
977 .dependencies = featureSet(&[_]Feature{
978 .sm4,
979 .sve2,
980 }),
981 };
982 result[@enumToInt(Feature.thunderx)] = .{
983 .llvm_name = "thunderx",
984 .description = "Cavium ThunderX processors",
985 .dependencies = featureSet(&[_]Feature{
986 .crc,
987 .crypto,
988 .fp_armv8,
989 .neon,
990 .perfmon,
991 .predictable_select_expensive,
992 .use_postra_scheduler,
993 }),
994 };
995 result[@enumToInt(Feature.thunderx2t99)] = .{
996 .llvm_name = "thunderx2t99",
997 .description = "Cavium ThunderX2 processors",
998 .dependencies = featureSet(&[_]Feature{
999 .aggressive_fma,
1000 .arith_bcc_fusion,
1001 .crc,
1002 .crypto,
1003 .fp_armv8,
1004 .lse,
1005 .neon,
1006 .predictable_select_expensive,
1007 .use_postra_scheduler,
1008 .v8_1a,
1009 }),
1010 };
1011 result[@enumToInt(Feature.thunderxt81)] = .{
1012 .llvm_name = "thunderxt81",
1013 .description = "Cavium ThunderX processors",
1014 .dependencies = featureSet(&[_]Feature{
1015 .crc,
1016 .crypto,
1017 .fp_armv8,
1018 .neon,
1019 .perfmon,
1020 .predictable_select_expensive,
1021 .use_postra_scheduler,
1022 }),
1023 };
1024 result[@enumToInt(Feature.thunderxt83)] = .{
1025 .llvm_name = "thunderxt83",
1026 .description = "Cavium ThunderX processors",
1027 .dependencies = featureSet(&[_]Feature{
1028 .crc,
1029 .crypto,
1030 .fp_armv8,
1031 .neon,
1032 .perfmon,
1033 .predictable_select_expensive,
1034 .use_postra_scheduler,
1035 }),
1036 };
1037 result[@enumToInt(Feature.thunderxt88)] = .{
1038 .llvm_name = "thunderxt88",
1039 .description = "Cavium ThunderX processors",
1040 .dependencies = featureSet(&[_]Feature{
1041 .crc,
1042 .crypto,
1043 .fp_armv8,
1044 .neon,
1045 .perfmon,
1046 .predictable_select_expensive,
1047 .use_postra_scheduler,
1048 }),
1049 };
1050 result[@enumToInt(Feature.tlb_rmi)] = .{
1051 .llvm_name = "tlb-rmi",
1052 .description = "Enable v8.4-A TLB Range and Maintenance Instructions",
1053 .dependencies = featureSet(&[_]Feature{}),
1054 };
1055 result[@enumToInt(Feature.tpidr_el1)] = .{
1056 .llvm_name = "tpidr-el1",
1057 .description = "Permit use of TPIDR_EL1 for the TLS base",
1058 .dependencies = featureSet(&[_]Feature{}),
1059 };
1060 result[@enumToInt(Feature.tpidr_el2)] = .{
1061 .llvm_name = "tpidr-el2",
1062 .description = "Permit use of TPIDR_EL2 for the TLS base",
1063 .dependencies = featureSet(&[_]Feature{}),
1064 };
1065 result[@enumToInt(Feature.tpidr_el3)] = .{
1066 .llvm_name = "tpidr-el3",
1067 .description = "Permit use of TPIDR_EL3 for the TLS base",
1068 .dependencies = featureSet(&[_]Feature{}),
1069 };
1070 result[@enumToInt(Feature.tracev8_4)] = .{
1071 .llvm_name = "tracev8.4",
1072 .description = "Enable v8.4-A Trace extension",
1073 .dependencies = featureSet(&[_]Feature{}),
1074 };
1075 result[@enumToInt(Feature.tsv110)] = .{
1076 .llvm_name = "tsv110",
1077 .description = "HiSilicon TS-V110 processors",
1078 .dependencies = featureSet(&[_]Feature{
1079 .crypto,
1080 .custom_cheap_as_move,
1081 .dotprod,
1082 .fp_armv8,
1083 .fp16fml,
1084 .fullfp16,
1085 .fuse_aes,
1086 .neon,
1087 .perfmon,
1088 .spe,
1089 .use_postra_scheduler,
1090 .v8_2a,
1091 }),
1092 };
1093 result[@enumToInt(Feature.uaops)] = .{
1094 .llvm_name = "uaops",
1095 .description = "Enable v8.2 UAO PState",
1096 .dependencies = featureSet(&[_]Feature{}),
1097 };
1098 result[@enumToInt(Feature.use_aa)] = .{
1099 .llvm_name = "use-aa",
1100 .description = "Use alias analysis during codegen",
1101 .dependencies = featureSet(&[_]Feature{}),
1102 };
1103 result[@enumToInt(Feature.use_postra_scheduler)] = .{
1104 .llvm_name = "use-postra-scheduler",
1105 .description = "Schedule again after register allocation",
1106 .dependencies = featureSet(&[_]Feature{}),
1107 };
1108 result[@enumToInt(Feature.use_reciprocal_square_root)] = .{
1109 .llvm_name = "use-reciprocal-square-root",
1110 .description = "Use the reciprocal square root approximation",
1111 .dependencies = featureSet(&[_]Feature{}),
1112 };
1113 result[@enumToInt(Feature.v8a)] = .{
1114 .llvm_name = null,
1115 .description = "Support ARM v8a instructions",
1116 .dependencies = featureSet(&[_]Feature{
1117 .fp_armv8,
1118 .neon,
1119 }),
1120 };
1121 result[@enumToInt(Feature.v8_1a)] = .{
1122 .llvm_name = "v8.1a",
1123 .description = "Support ARM v8.1a instructions",
1124 .dependencies = featureSet(&[_]Feature{
1125 .crc,
1126 .lor,
1127 .lse,
1128 .pan,
1129 .rdm,
1130 .vh,
1131 .v8a,
1132 }),
1133 };
1134 result[@enumToInt(Feature.v8_2a)] = .{
1135 .llvm_name = "v8.2a",
1136 .description = "Support ARM v8.2a instructions",
1137 .dependencies = featureSet(&[_]Feature{
1138 .ccpp,
1139 .pan_rwv,
1140 .ras,
1141 .uaops,
1142 .v8_1a,
1143 }),
1144 };
1145 result[@enumToInt(Feature.v8_3a)] = .{
1146 .llvm_name = "v8.3a",
1147 .description = "Support ARM v8.3a instructions",
1148 .dependencies = featureSet(&[_]Feature{
1149 .ccidx,
1150 .complxnum,
1151 .jsconv,
1152 .pa,
1153 .rcpc,
1154 .v8_2a,
1155 }),
1156 };
1157 result[@enumToInt(Feature.v8_4a)] = .{
1158 .llvm_name = "v8.4a",
1159 .description = "Support ARM v8.4a instructions",
1160 .dependencies = featureSet(&[_]Feature{
1161 .am,
1162 .dit,
1163 .dotprod,
1164 .fmi,
1165 .mpam,
1166 .nv,
1167 .rasv8_4,
1168 .rcpc_immo,
1169 .sel2,
1170 .tlb_rmi,
1171 .tracev8_4,
1172 .v8_3a,
1173 }),
1174 };
1175 result[@enumToInt(Feature.v8_5a)] = .{
1176 .llvm_name = "v8.5a",
1177 .description = "Support ARM v8.5a instructions",
1178 .dependencies = featureSet(&[_]Feature{
1179 .altnzcv,
1180 .bti,
1181 .ccdp,
1182 .fptoint,
1183 .predres,
1184 .sb,
1185 .specrestrict,
1186 .ssbs,
1187 .v8_4a,
1188 }),
1189 };
1190 result[@enumToInt(Feature.vh)] = .{
1191 .llvm_name = "vh",
1192 .description = "Enables ARM v8.1 Virtual Host extension",
1193 .dependencies = featureSet(&[_]Feature{}),
1194 };
1195 result[@enumToInt(Feature.zcm)] = .{
1196 .llvm_name = "zcm",
1197 .description = "Has zero-cycle register moves",
1198 .dependencies = featureSet(&[_]Feature{}),
1199 };
1200 result[@enumToInt(Feature.zcz)] = .{
1201 .llvm_name = "zcz",
1202 .description = "Has zero-cycle zeroing instructions",
1203 .dependencies = featureSet(&[_]Feature{
1204 .zcz_fp,
1205 .zcz_gp,
1206 }),
1207 };
1208 result[@enumToInt(Feature.zcz_fp)] = .{
1209 .llvm_name = "zcz-fp",
1210 .description = "Has zero-cycle zeroing instructions for FP registers",
1211 .dependencies = featureSet(&[_]Feature{}),
1212 };
1213 result[@enumToInt(Feature.zcz_fp_workaround)] = .{
1214 .llvm_name = "zcz-fp-workaround",
1215 .description = "The zero-cycle floating-point zeroing instruction has a bug",
1216 .dependencies = featureSet(&[_]Feature{}),
1217 };
1218 result[@enumToInt(Feature.zcz_gp)] = .{
1219 .llvm_name = "zcz-gp",
1220 .description = "Has zero-cycle zeroing instructions for generic registers",
1221 .dependencies = featureSet(&[_]Feature{}),
1222 };
1223 const ti = @typeInfo(Feature);
1224 for (result) |*elem, i| {
1225 elem.index = i;
1226 elem.name = ti.Enum.fields[i].name;
1227 }
1228 break :blk result;
1229};
1230
1231pub const cpu = struct {
1232 pub const apple_latest = Cpu{
1233 .name = "apple_latest",
1234 .llvm_name = "apple-latest",
1235 .features = featureSet(&[_]Feature{
1236 .cyclone,
1237 }),
1238 };
1239 pub const cortex_a35 = Cpu{
1240 .name = "cortex_a35",
1241 .llvm_name = "cortex-a35",
1242 .features = featureSet(&[_]Feature{
1243 .a35,
1244 }),
1245 };
1246 pub const cortex_a53 = Cpu{
1247 .name = "cortex_a53",
1248 .llvm_name = "cortex-a53",
1249 .features = featureSet(&[_]Feature{
1250 .a53,
1251 }),
1252 };
1253 pub const cortex_a55 = Cpu{
1254 .name = "cortex_a55",
1255 .llvm_name = "cortex-a55",
1256 .features = featureSet(&[_]Feature{
1257 .a55,
1258 }),
1259 };
1260 pub const cortex_a57 = Cpu{
1261 .name = "cortex_a57",
1262 .llvm_name = "cortex-a57",
1263 .features = featureSet(&[_]Feature{
1264 .a57,
1265 }),
1266 };
1267 pub const cortex_a72 = Cpu{
1268 .name = "cortex_a72",
1269 .llvm_name = "cortex-a72",
1270 .features = featureSet(&[_]Feature{
1271 .a72,
1272 }),
1273 };
1274 pub const cortex_a73 = Cpu{
1275 .name = "cortex_a73",
1276 .llvm_name = "cortex-a73",
1277 .features = featureSet(&[_]Feature{
1278 .a73,
1279 }),
1280 };
1281 pub const cortex_a75 = Cpu{
1282 .name = "cortex_a75",
1283 .llvm_name = "cortex-a75",
1284 .features = featureSet(&[_]Feature{
1285 .a75,
1286 }),
1287 };
1288 pub const cortex_a76 = Cpu{
1289 .name = "cortex_a76",
1290 .llvm_name = "cortex-a76",
1291 .features = featureSet(&[_]Feature{
1292 .a76,
1293 }),
1294 };
1295 pub const cortex_a76ae = Cpu{
1296 .name = "cortex_a76ae",
1297 .llvm_name = "cortex-a76ae",
1298 .features = featureSet(&[_]Feature{
1299 .a76,
1300 }),
1301 };
1302 pub const cyclone = Cpu{
1303 .name = "cyclone",
1304 .llvm_name = "cyclone",
1305 .features = featureSet(&[_]Feature{
1306 .cyclone,
1307 }),
1308 };
1309 pub const exynos_m1 = Cpu{
1310 .name = "exynos_m1",
1311 .llvm_name = "exynos-m1",
1312 .features = featureSet(&[_]Feature{
1313 .exynosm1,
1314 }),
1315 };
1316 pub const exynos_m2 = Cpu{
1317 .name = "exynos_m2",
1318 .llvm_name = "exynos-m2",
1319 .features = featureSet(&[_]Feature{
1320 .exynosm2,
1321 }),
1322 };
1323 pub const exynos_m3 = Cpu{
1324 .name = "exynos_m3",
1325 .llvm_name = "exynos-m3",
1326 .features = featureSet(&[_]Feature{
1327 .exynosm3,
1328 }),
1329 };
1330 pub const exynos_m4 = Cpu{
1331 .name = "exynos_m4",
1332 .llvm_name = "exynos-m4",
1333 .features = featureSet(&[_]Feature{
1334 .exynosm4,
1335 }),
1336 };
1337 pub const exynos_m5 = Cpu{
1338 .name = "exynos_m5",
1339 .llvm_name = "exynos-m5",
1340 .features = featureSet(&[_]Feature{
1341 .exynosm4,
1342 }),
1343 };
1344 pub const falkor = Cpu{
1345 .name = "falkor",
1346 .llvm_name = "falkor",
1347 .features = featureSet(&[_]Feature{
1348 .falkor,
1349 }),
1350 };
1351 pub const generic = Cpu{
1352 .name = "generic",
1353 .llvm_name = "generic",
1354 .features = featureSet(&[_]Feature{
1355 .fp_armv8,
1356 .fuse_aes,
1357 .neon,
1358 .perfmon,
1359 .use_postra_scheduler,
1360 }),
1361 };
1362 pub const kryo = Cpu{
1363 .name = "kryo",
1364 .llvm_name = "kryo",
1365 .features = featureSet(&[_]Feature{
1366 .kryo,
1367 }),
1368 };
1369 pub const saphira = Cpu{
1370 .name = "saphira",
1371 .llvm_name = "saphira",
1372 .features = featureSet(&[_]Feature{
1373 .saphira,
1374 }),
1375 };
1376 pub const thunderx = Cpu{
1377 .name = "thunderx",
1378 .llvm_name = "thunderx",
1379 .features = featureSet(&[_]Feature{
1380 .thunderx,
1381 }),
1382 };
1383 pub const thunderx2t99 = Cpu{
1384 .name = "thunderx2t99",
1385 .llvm_name = "thunderx2t99",
1386 .features = featureSet(&[_]Feature{
1387 .thunderx2t99,
1388 }),
1389 };
1390 pub const thunderxt81 = Cpu{
1391 .name = "thunderxt81",
1392 .llvm_name = "thunderxt81",
1393 .features = featureSet(&[_]Feature{
1394 .thunderxt81,
1395 }),
1396 };
1397 pub const thunderxt83 = Cpu{
1398 .name = "thunderxt83",
1399 .llvm_name = "thunderxt83",
1400 .features = featureSet(&[_]Feature{
1401 .thunderxt83,
1402 }),
1403 };
1404 pub const thunderxt88 = Cpu{
1405 .name = "thunderxt88",
1406 .llvm_name = "thunderxt88",
1407 .features = featureSet(&[_]Feature{
1408 .thunderxt88,
1409 }),
1410 };
1411 pub const tsv110 = Cpu{
1412 .name = "tsv110",
1413 .llvm_name = "tsv110",
1414 .features = featureSet(&[_]Feature{
1415 .tsv110,
1416 }),
1417 };
1418};
1419
1420/// All aarch64 CPUs, sorted alphabetically by name.
1421/// TODO: Replace this with usage of `std.meta.declList`. It does work, but stage1
1422/// compiler has inefficient memory and CPU usage, affecting build times.
1423pub const all_cpus = &[_]*const Cpu{
1424 &cpu.apple_latest,
1425 &cpu.cortex_a35,
1426 &cpu.cortex_a53,
1427 &cpu.cortex_a55,
1428 &cpu.cortex_a57,
1429 &cpu.cortex_a72,
1430 &cpu.cortex_a73,
1431 &cpu.cortex_a75,
1432 &cpu.cortex_a76,
1433 &cpu.cortex_a76ae,
1434 &cpu.cyclone,
1435 &cpu.exynos_m1,
1436 &cpu.exynos_m2,
1437 &cpu.exynos_m3,
1438 &cpu.exynos_m4,
1439 &cpu.exynos_m5,
1440 &cpu.falkor,
1441 &cpu.generic,
1442 &cpu.kryo,
1443 &cpu.saphira,
1444 &cpu.thunderx,
1445 &cpu.thunderx2t99,
1446 &cpu.thunderxt81,
1447 &cpu.thunderxt83,
1448 &cpu.thunderxt88,
1449 &cpu.tsv110,
1450};
lib/std/target/amdgpu.zig created+1315
...@@ -0,0 +1,1315 @@
1const std = @import("../std.zig");
2const Cpu = std.Target.Cpu;
3
4pub const Feature = enum {
5 @"16_bit_insts",
6 DumpCode,
7 add_no_carry_insts,
8 aperture_regs,
9 atomic_fadd_insts,
10 auto_waitcnt_before_barrier,
11 ci_insts,
12 code_object_v3,
13 cumode,
14 dl_insts,
15 dot1_insts,
16 dot2_insts,
17 dot3_insts,
18 dot4_insts,
19 dot5_insts,
20 dot6_insts,
21 dpp,
22 dpp8,
23 dumpcode,
24 enable_ds128,
25 enable_prt_strict_null,
26 fast_fmaf,
27 flat_address_space,
28 flat_for_global,
29 flat_global_insts,
30 flat_inst_offsets,
31 flat_scratch_insts,
32 flat_segment_offset_bug,
33 fma_mix_insts,
34 fmaf,
35 fp_exceptions,
36 fp16_denormals,
37 fp32_denormals,
38 fp64,
39 fp64_denormals,
40 fp64_fp16_denormals,
41 gcn3_encoding,
42 gfx10,
43 gfx10_insts,
44 gfx7_gfx8_gfx9_insts,
45 gfx8_insts,
46 gfx9,
47 gfx9_insts,
48 half_rate_64_ops,
49 inst_fwd_prefetch_bug,
50 int_clamp_insts,
51 inv_2pi_inline_imm,
52 lds_branch_vmem_war_hazard,
53 lds_misaligned_bug,
54 ldsbankcount16,
55 ldsbankcount32,
56 load_store_opt,
57 localmemorysize0,
58 localmemorysize32768,
59 localmemorysize65536,
60 mad_mix_insts,
61 mai_insts,
62 max_private_element_size_16,
63 max_private_element_size_4,
64 max_private_element_size_8,
65 mimg_r128,
66 movrel,
67 no_data_dep_hazard,
68 no_sdst_cmpx,
69 no_sram_ecc_support,
70 no_xnack_support,
71 nsa_encoding,
72 nsa_to_vmem_bug,
73 offset_3f_bug,
74 pk_fmac_f16_inst,
75 promote_alloca,
76 r128_a16,
77 register_banking,
78 s_memrealtime,
79 scalar_atomics,
80 scalar_flat_scratch_insts,
81 scalar_stores,
82 sdwa,
83 sdwa_mav,
84 sdwa_omod,
85 sdwa_out_mods_vopc,
86 sdwa_scalar,
87 sdwa_sdst,
88 sea_islands,
89 sgpr_init_bug,
90 si_scheduler,
91 smem_to_vector_write_hazard,
92 southern_islands,
93 sram_ecc,
94 trap_handler,
95 trig_reduced_range,
96 unaligned_buffer_access,
97 unaligned_scratch_access,
98 unpacked_d16_vmem,
99 unsafe_ds_offset_folding,
100 vcmpx_exec_war_hazard,
101 vcmpx_permlane_hazard,
102 vgpr_index_mode,
103 vmem_to_scalar_write_hazard,
104 volcanic_islands,
105 vop3_literal,
106 vop3p,
107 vscnt,
108 wavefrontsize16,
109 wavefrontsize32,
110 wavefrontsize64,
111 xnack,
112};
113
114pub usingnamespace Cpu.Feature.feature_set_fns(Feature);
115
116pub const all_features = blk: {
117 const len = @typeInfo(Feature).Enum.fields.len;
118 std.debug.assert(len <= Cpu.Feature.Set.needed_bit_count);
119 var result: [len]Cpu.Feature = undefined;
120 result[@enumToInt(Feature.@"16_bit_insts")] = .{
121 .llvm_name = "16-bit-insts",
122 .description = "Has i16/f16 instructions",
123 .dependencies = featureSet(&[_]Feature{}),
124 };
125 result[@enumToInt(Feature.DumpCode)] = .{
126 .llvm_name = "DumpCode",
127 .description = "Dump MachineInstrs in the CodeEmitter",
128 .dependencies = featureSet(&[_]Feature{}),
129 };
130 result[@enumToInt(Feature.add_no_carry_insts)] = .{
131 .llvm_name = "add-no-carry-insts",
132 .description = "Have VALU add/sub instructions without carry out",
133 .dependencies = featureSet(&[_]Feature{}),
134 };
135 result[@enumToInt(Feature.aperture_regs)] = .{
136 .llvm_name = "aperture-regs",
137 .description = "Has Memory Aperture Base and Size Registers",
138 .dependencies = featureSet(&[_]Feature{}),
139 };
140 result[@enumToInt(Feature.atomic_fadd_insts)] = .{
141 .llvm_name = "atomic-fadd-insts",
142 .description = "Has buffer_atomic_add_f32, buffer_atomic_pk_add_f16, global_atomic_add_f32, global_atomic_pk_add_f16 instructions",
143 .dependencies = featureSet(&[_]Feature{}),
144 };
145 result[@enumToInt(Feature.auto_waitcnt_before_barrier)] = .{
146 .llvm_name = "auto-waitcnt-before-barrier",
147 .description = "Hardware automatically inserts waitcnt before barrier",
148 .dependencies = featureSet(&[_]Feature{}),
149 };
150 result[@enumToInt(Feature.ci_insts)] = .{
151 .llvm_name = "ci-insts",
152 .description = "Additional instructions for CI+",
153 .dependencies = featureSet(&[_]Feature{}),
154 };
155 result[@enumToInt(Feature.code_object_v3)] = .{
156 .llvm_name = "code-object-v3",
157 .description = "Generate code object version 3",
158 .dependencies = featureSet(&[_]Feature{}),
159 };
160 result[@enumToInt(Feature.cumode)] = .{
161 .llvm_name = "cumode",
162 .description = "Enable CU wavefront execution mode",
163 .dependencies = featureSet(&[_]Feature{}),
164 };
165 result[@enumToInt(Feature.dl_insts)] = .{
166 .llvm_name = "dl-insts",
167 .description = "Has v_fmac_f32 and v_xnor_b32 instructions",
168 .dependencies = featureSet(&[_]Feature{}),
169 };
170 result[@enumToInt(Feature.dot1_insts)] = .{
171 .llvm_name = "dot1-insts",
172 .description = "Has v_dot4_i32_i8 and v_dot8_i32_i4 instructions",
173 .dependencies = featureSet(&[_]Feature{}),
174 };
175 result[@enumToInt(Feature.dot2_insts)] = .{
176 .llvm_name = "dot2-insts",
177 .description = "Has v_dot2_f32_f16, v_dot2_i32_i16, v_dot2_u32_u16, v_dot4_u32_u8, v_dot8_u32_u4 instructions",
178 .dependencies = featureSet(&[_]Feature{}),
179 };
180 result[@enumToInt(Feature.dot3_insts)] = .{
181 .llvm_name = "dot3-insts",
182 .description = "Has v_dot8c_i32_i4 instruction",
183 .dependencies = featureSet(&[_]Feature{}),
184 };
185 result[@enumToInt(Feature.dot4_insts)] = .{
186 .llvm_name = "dot4-insts",
187 .description = "Has v_dot2c_i32_i16 instruction",
188 .dependencies = featureSet(&[_]Feature{}),
189 };
190 result[@enumToInt(Feature.dot5_insts)] = .{
191 .llvm_name = "dot5-insts",
192 .description = "Has v_dot2c_f32_f16 instruction",
193 .dependencies = featureSet(&[_]Feature{}),
194 };
195 result[@enumToInt(Feature.dot6_insts)] = .{
196 .llvm_name = "dot6-insts",
197 .description = "Has v_dot4c_i32_i8 instruction",
198 .dependencies = featureSet(&[_]Feature{}),
199 };
200 result[@enumToInt(Feature.dpp)] = .{
201 .llvm_name = "dpp",
202 .description = "Support DPP (Data Parallel Primitives) extension",
203 .dependencies = featureSet(&[_]Feature{}),
204 };
205 result[@enumToInt(Feature.dpp8)] = .{
206 .llvm_name = "dpp8",
207 .description = "Support DPP8 (Data Parallel Primitives) extension",
208 .dependencies = featureSet(&[_]Feature{}),
209 };
210 result[@enumToInt(Feature.dumpcode)] = .{
211 .llvm_name = "dumpcode",
212 .description = "Dump MachineInstrs in the CodeEmitter",
213 .dependencies = featureSet(&[_]Feature{}),
214 };
215 result[@enumToInt(Feature.enable_ds128)] = .{
216 .llvm_name = "enable-ds128",
217 .description = "Use ds_read|write_b128",
218 .dependencies = featureSet(&[_]Feature{}),
219 };
220 result[@enumToInt(Feature.enable_prt_strict_null)] = .{
221 .llvm_name = "enable-prt-strict-null",
222 .description = "Enable zeroing of result registers for sparse texture fetches",
223 .dependencies = featureSet(&[_]Feature{}),
224 };
225 result[@enumToInt(Feature.fast_fmaf)] = .{
226 .llvm_name = "fast-fmaf",
227 .description = "Assuming f32 fma is at least as fast as mul + add",
228 .dependencies = featureSet(&[_]Feature{}),
229 };
230 result[@enumToInt(Feature.flat_address_space)] = .{
231 .llvm_name = "flat-address-space",
232 .description = "Support flat address space",
233 .dependencies = featureSet(&[_]Feature{}),
234 };
235 result[@enumToInt(Feature.flat_for_global)] = .{
236 .llvm_name = "flat-for-global",
237 .description = "Force to generate flat instruction for global",
238 .dependencies = featureSet(&[_]Feature{}),
239 };
240 result[@enumToInt(Feature.flat_global_insts)] = .{
241 .llvm_name = "flat-global-insts",
242 .description = "Have global_* flat memory instructions",
243 .dependencies = featureSet(&[_]Feature{}),
244 };
245 result[@enumToInt(Feature.flat_inst_offsets)] = .{
246 .llvm_name = "flat-inst-offsets",
247 .description = "Flat instructions have immediate offset addressing mode",
248 .dependencies = featureSet(&[_]Feature{}),
249 };
250 result[@enumToInt(Feature.flat_scratch_insts)] = .{
251 .llvm_name = "flat-scratch-insts",
252 .description = "Have scratch_* flat memory instructions",
253 .dependencies = featureSet(&[_]Feature{}),
254 };
255 result[@enumToInt(Feature.flat_segment_offset_bug)] = .{
256 .llvm_name = "flat-segment-offset-bug",
257 .description = "GFX10 bug, inst_offset ignored in flat segment",
258 .dependencies = featureSet(&[_]Feature{}),
259 };
260 result[@enumToInt(Feature.fma_mix_insts)] = .{
261 .llvm_name = "fma-mix-insts",
262 .description = "Has v_fma_mix_f32, v_fma_mixlo_f16, v_fma_mixhi_f16 instructions",
263 .dependencies = featureSet(&[_]Feature{}),
264 };
265 result[@enumToInt(Feature.fmaf)] = .{
266 .llvm_name = "fmaf",
267 .description = "Enable single precision FMA (not as fast as mul+add, but fused)",
268 .dependencies = featureSet(&[_]Feature{}),
269 };
270 result[@enumToInt(Feature.fp_exceptions)] = .{
271 .llvm_name = "fp-exceptions",
272 .description = "Enable floating point exceptions",
273 .dependencies = featureSet(&[_]Feature{}),
274 };
275 result[@enumToInt(Feature.fp16_denormals)] = .{
276 .llvm_name = "fp16-denormals",
277 .description = "Enable half precision denormal handling",
278 .dependencies = featureSet(&[_]Feature{
279 .fp64_fp16_denormals,
280 }),
281 };
282 result[@enumToInt(Feature.fp32_denormals)] = .{
283 .llvm_name = "fp32-denormals",
284 .description = "Enable single precision denormal handling",
285 .dependencies = featureSet(&[_]Feature{}),
286 };
287 result[@enumToInt(Feature.fp64)] = .{
288 .llvm_name = "fp64",
289 .description = "Enable double precision operations",
290 .dependencies = featureSet(&[_]Feature{}),
291 };
292 result[@enumToInt(Feature.fp64_denormals)] = .{
293 .llvm_name = "fp64-denormals",
294 .description = "Enable double and half precision denormal handling",
295 .dependencies = featureSet(&[_]Feature{
296 .fp64,
297 .fp64_fp16_denormals,
298 }),
299 };
300 result[@enumToInt(Feature.fp64_fp16_denormals)] = .{
301 .llvm_name = "fp64-fp16-denormals",
302 .description = "Enable double and half precision denormal handling",
303 .dependencies = featureSet(&[_]Feature{
304 .fp64,
305 }),
306 };
307 result[@enumToInt(Feature.gcn3_encoding)] = .{
308 .llvm_name = "gcn3-encoding",
309 .description = "Encoding format for VI",
310 .dependencies = featureSet(&[_]Feature{}),
311 };
312 result[@enumToInt(Feature.gfx10)] = .{
313 .llvm_name = "gfx10",
314 .description = "GFX10 GPU generation",
315 .dependencies = featureSet(&[_]Feature{
316 .@"16_bit_insts",
317 .add_no_carry_insts,
318 .aperture_regs,
319 .ci_insts,
320 .dpp,
321 .dpp8,
322 .fast_fmaf,
323 .flat_address_space,
324 .flat_global_insts,
325 .flat_inst_offsets,
326 .flat_scratch_insts,
327 .fma_mix_insts,
328 .fp64,
329 .gfx10_insts,
330 .gfx8_insts,
331 .gfx9_insts,
332 .int_clamp_insts,
333 .inv_2pi_inline_imm,
334 .localmemorysize65536,
335 .mimg_r128,
336 .movrel,
337 .no_data_dep_hazard,
338 .no_sdst_cmpx,
339 .no_sram_ecc_support,
340 .pk_fmac_f16_inst,
341 .register_banking,
342 .s_memrealtime,
343 .sdwa,
344 .sdwa_omod,
345 .sdwa_scalar,
346 .sdwa_sdst,
347 .vop3_literal,
348 .vop3p,
349 .vscnt,
350 }),
351 };
352 result[@enumToInt(Feature.gfx10_insts)] = .{
353 .llvm_name = "gfx10-insts",
354 .description = "Additional instructions for GFX10+",
355 .dependencies = featureSet(&[_]Feature{}),
356 };
357 result[@enumToInt(Feature.gfx7_gfx8_gfx9_insts)] = .{
358 .llvm_name = "gfx7-gfx8-gfx9-insts",
359 .description = "Instructions shared in GFX7, GFX8, GFX9",
360 .dependencies = featureSet(&[_]Feature{}),
361 };
362 result[@enumToInt(Feature.gfx8_insts)] = .{
363 .llvm_name = "gfx8-insts",
364 .description = "Additional instructions for GFX8+",
365 .dependencies = featureSet(&[_]Feature{}),
366 };
367 result[@enumToInt(Feature.gfx9)] = .{
368 .llvm_name = "gfx9",
369 .description = "GFX9 GPU generation",
370 .dependencies = featureSet(&[_]Feature{
371 .@"16_bit_insts",
372 .add_no_carry_insts,
373 .aperture_regs,
374 .ci_insts,
375 .dpp,
376 .fast_fmaf,
377 .flat_address_space,
378 .flat_global_insts,
379 .flat_inst_offsets,
380 .flat_scratch_insts,
381 .fp64,
382 .gcn3_encoding,
383 .gfx7_gfx8_gfx9_insts,
384 .gfx8_insts,
385 .gfx9_insts,
386 .int_clamp_insts,
387 .inv_2pi_inline_imm,
388 .localmemorysize65536,
389 .r128_a16,
390 .s_memrealtime,
391 .scalar_atomics,
392 .scalar_flat_scratch_insts,
393 .scalar_stores,
394 .sdwa,
395 .sdwa_omod,
396 .sdwa_scalar,
397 .sdwa_sdst,
398 .vgpr_index_mode,
399 .vop3p,
400 .wavefrontsize64,
401 }),
402 };
403 result[@enumToInt(Feature.gfx9_insts)] = .{
404 .llvm_name = "gfx9-insts",
405 .description = "Additional instructions for GFX9+",
406 .dependencies = featureSet(&[_]Feature{}),
407 };
408 result[@enumToInt(Feature.half_rate_64_ops)] = .{
409 .llvm_name = "half-rate-64-ops",
410 .description = "Most fp64 instructions are half rate instead of quarter",
411 .dependencies = featureSet(&[_]Feature{}),
412 };
413 result[@enumToInt(Feature.inst_fwd_prefetch_bug)] = .{
414 .llvm_name = "inst-fwd-prefetch-bug",
415 .description = "S_INST_PREFETCH instruction causes shader to hang",
416 .dependencies = featureSet(&[_]Feature{}),
417 };
418 result[@enumToInt(Feature.int_clamp_insts)] = .{
419 .llvm_name = "int-clamp-insts",
420 .description = "Support clamp for integer destination",
421 .dependencies = featureSet(&[_]Feature{}),
422 };
423 result[@enumToInt(Feature.inv_2pi_inline_imm)] = .{
424 .llvm_name = "inv-2pi-inline-imm",
425 .description = "Has 1 / (2 * pi) as inline immediate",
426 .dependencies = featureSet(&[_]Feature{}),
427 };
428 result[@enumToInt(Feature.lds_branch_vmem_war_hazard)] = .{
429 .llvm_name = "lds-branch-vmem-war-hazard",
430 .description = "Switching between LDS and VMEM-tex not waiting VM_VSRC=0",
431 .dependencies = featureSet(&[_]Feature{}),
432 };
433 result[@enumToInt(Feature.lds_misaligned_bug)] = .{
434 .llvm_name = "lds-misaligned-bug",
435 .description = "Some GFX10 bug with misaligned multi-dword LDS access in WGP mode",
436 .dependencies = featureSet(&[_]Feature{}),
437 };
438 result[@enumToInt(Feature.ldsbankcount16)] = .{
439 .llvm_name = "ldsbankcount16",
440 .description = "The number of LDS banks per compute unit.",
441 .dependencies = featureSet(&[_]Feature{}),
442 };
443 result[@enumToInt(Feature.ldsbankcount32)] = .{
444 .llvm_name = "ldsbankcount32",
445 .description = "The number of LDS banks per compute unit.",
446 .dependencies = featureSet(&[_]Feature{}),
447 };
448 result[@enumToInt(Feature.load_store_opt)] = .{
449 .llvm_name = "load-store-opt",
450 .description = "Enable SI load/store optimizer pass",
451 .dependencies = featureSet(&[_]Feature{}),
452 };
453 result[@enumToInt(Feature.localmemorysize0)] = .{
454 .llvm_name = "localmemorysize0",
455 .description = "The size of local memory in bytes",
456 .dependencies = featureSet(&[_]Feature{}),
457 };
458 result[@enumToInt(Feature.localmemorysize32768)] = .{
459 .llvm_name = "localmemorysize32768",
460 .description = "The size of local memory in bytes",
461 .dependencies = featureSet(&[_]Feature{}),
462 };
463 result[@enumToInt(Feature.localmemorysize65536)] = .{
464 .llvm_name = "localmemorysize65536",
465 .description = "The size of local memory in bytes",
466 .dependencies = featureSet(&[_]Feature{}),
467 };
468 result[@enumToInt(Feature.mad_mix_insts)] = .{
469 .llvm_name = "mad-mix-insts",
470 .description = "Has v_mad_mix_f32, v_mad_mixlo_f16, v_mad_mixhi_f16 instructions",
471 .dependencies = featureSet(&[_]Feature{}),
472 };
473 result[@enumToInt(Feature.mai_insts)] = .{
474 .llvm_name = "mai-insts",
475 .description = "Has mAI instructions",
476 .dependencies = featureSet(&[_]Feature{}),
477 };
478 result[@enumToInt(Feature.max_private_element_size_16)] = .{
479 .llvm_name = "max-private-element-size-16",
480 .description = "Maximum private access size may be 16",
481 .dependencies = featureSet(&[_]Feature{}),
482 };
483 result[@enumToInt(Feature.max_private_element_size_4)] = .{
484 .llvm_name = "max-private-element-size-4",
485 .description = "Maximum private access size may be 4",
486 .dependencies = featureSet(&[_]Feature{}),
487 };
488 result[@enumToInt(Feature.max_private_element_size_8)] = .{
489 .llvm_name = "max-private-element-size-8",
490 .description = "Maximum private access size may be 8",
491 .dependencies = featureSet(&[_]Feature{}),
492 };
493 result[@enumToInt(Feature.mimg_r128)] = .{
494 .llvm_name = "mimg-r128",
495 .description = "Support 128-bit texture resources",
496 .dependencies = featureSet(&[_]Feature{}),
497 };
498 result[@enumToInt(Feature.movrel)] = .{
499 .llvm_name = "movrel",
500 .description = "Has v_movrel*_b32 instructions",
501 .dependencies = featureSet(&[_]Feature{}),
502 };
503 result[@enumToInt(Feature.no_data_dep_hazard)] = .{
504 .llvm_name = "no-data-dep-hazard",
505 .description = "Does not need SW waitstates",
506 .dependencies = featureSet(&[_]Feature{}),
507 };
508 result[@enumToInt(Feature.no_sdst_cmpx)] = .{
509 .llvm_name = "no-sdst-cmpx",
510 .description = "V_CMPX does not write VCC/SGPR in addition to EXEC",
511 .dependencies = featureSet(&[_]Feature{}),
512 };
513 result[@enumToInt(Feature.no_sram_ecc_support)] = .{
514 .llvm_name = "no-sram-ecc-support",
515 .description = "Hardware does not support SRAM ECC",
516 .dependencies = featureSet(&[_]Feature{}),
517 };
518 result[@enumToInt(Feature.no_xnack_support)] = .{
519 .llvm_name = "no-xnack-support",
520 .description = "Hardware does not support XNACK",
521 .dependencies = featureSet(&[_]Feature{}),
522 };
523 result[@enumToInt(Feature.nsa_encoding)] = .{
524 .llvm_name = "nsa-encoding",
525 .description = "Support NSA encoding for image instructions",
526 .dependencies = featureSet(&[_]Feature{}),
527 };
528 result[@enumToInt(Feature.nsa_to_vmem_bug)] = .{
529 .llvm_name = "nsa-to-vmem-bug",
530 .description = "MIMG-NSA followed by VMEM fail if EXEC_LO or EXEC_HI equals zero",
531 .dependencies = featureSet(&[_]Feature{}),
532 };
533 result[@enumToInt(Feature.offset_3f_bug)] = .{
534 .llvm_name = "offset-3f-bug",
535 .description = "Branch offset of 3f hardware bug",
536 .dependencies = featureSet(&[_]Feature{}),
537 };
538 result[@enumToInt(Feature.pk_fmac_f16_inst)] = .{
539 .llvm_name = "pk-fmac-f16-inst",
540 .description = "Has v_pk_fmac_f16 instruction",
541 .dependencies = featureSet(&[_]Feature{}),
542 };
543 result[@enumToInt(Feature.promote_alloca)] = .{
544 .llvm_name = "promote-alloca",
545 .description = "Enable promote alloca pass",
546 .dependencies = featureSet(&[_]Feature{}),
547 };
548 result[@enumToInt(Feature.r128_a16)] = .{
549 .llvm_name = "r128-a16",
550 .description = "Support 16 bit coordindates/gradients/lod/clamp/mip types on gfx9",
551 .dependencies = featureSet(&[_]Feature{}),
552 };
553 result[@enumToInt(Feature.register_banking)] = .{
554 .llvm_name = "register-banking",
555 .description = "Has register banking",
556 .dependencies = featureSet(&[_]Feature{}),
557 };
558 result[@enumToInt(Feature.s_memrealtime)] = .{
559 .llvm_name = "s-memrealtime",
560 .description = "Has s_memrealtime instruction",
561 .dependencies = featureSet(&[_]Feature{}),
562 };
563 result[@enumToInt(Feature.scalar_atomics)] = .{
564 .llvm_name = "scalar-atomics",
565 .description = "Has atomic scalar memory instructions",
566 .dependencies = featureSet(&[_]Feature{}),
567 };
568 result[@enumToInt(Feature.scalar_flat_scratch_insts)] = .{
569 .llvm_name = "scalar-flat-scratch-insts",
570 .description = "Have s_scratch_* flat memory instructions",
571 .dependencies = featureSet(&[_]Feature{}),
572 };
573 result[@enumToInt(Feature.scalar_stores)] = .{
574 .llvm_name = "scalar-stores",
575 .description = "Has store scalar memory instructions",
576 .dependencies = featureSet(&[_]Feature{}),
577 };
578 result[@enumToInt(Feature.sdwa)] = .{
579 .llvm_name = "sdwa",
580 .description = "Support SDWA (Sub-DWORD Addressing) extension",
581 .dependencies = featureSet(&[_]Feature{}),
582 };
583 result[@enumToInt(Feature.sdwa_mav)] = .{
584 .llvm_name = "sdwa-mav",
585 .description = "Support v_mac_f32/f16 with SDWA (Sub-DWORD Addressing) extension",
586 .dependencies = featureSet(&[_]Feature{}),
587 };
588 result[@enumToInt(Feature.sdwa_omod)] = .{
589 .llvm_name = "sdwa-omod",
590 .description = "Support OMod with SDWA (Sub-DWORD Addressing) extension",
591 .dependencies = featureSet(&[_]Feature{}),
592 };
593 result[@enumToInt(Feature.sdwa_out_mods_vopc)] = .{
594 .llvm_name = "sdwa-out-mods-vopc",
595 .description = "Support clamp for VOPC with SDWA (Sub-DWORD Addressing) extension",
596 .dependencies = featureSet(&[_]Feature{}),
597 };
598 result[@enumToInt(Feature.sdwa_scalar)] = .{
599 .llvm_name = "sdwa-scalar",
600 .description = "Support scalar register with SDWA (Sub-DWORD Addressing) extension",
601 .dependencies = featureSet(&[_]Feature{}),
602 };
603 result[@enumToInt(Feature.sdwa_sdst)] = .{
604 .llvm_name = "sdwa-sdst",
605 .description = "Support scalar dst for VOPC with SDWA (Sub-DWORD Addressing) extension",
606 .dependencies = featureSet(&[_]Feature{}),
607 };
608 result[@enumToInt(Feature.sea_islands)] = .{
609 .llvm_name = "sea-islands",
610 .description = "SEA_ISLANDS GPU generation",
611 .dependencies = featureSet(&[_]Feature{
612 .ci_insts,
613 .flat_address_space,
614 .fp64,
615 .gfx7_gfx8_gfx9_insts,
616 .localmemorysize65536,
617 .mimg_r128,
618 .movrel,
619 .no_sram_ecc_support,
620 .trig_reduced_range,
621 .wavefrontsize64,
622 }),
623 };
624 result[@enumToInt(Feature.sgpr_init_bug)] = .{
625 .llvm_name = "sgpr-init-bug",
626 .description = "VI SGPR initialization bug requiring a fixed SGPR allocation size",
627 .dependencies = featureSet(&[_]Feature{}),
628 };
629 result[@enumToInt(Feature.si_scheduler)] = .{
630 .llvm_name = "si-scheduler",
631 .description = "Enable SI Machine Scheduler",
632 .dependencies = featureSet(&[_]Feature{}),
633 };
634 result[@enumToInt(Feature.smem_to_vector_write_hazard)] = .{
635 .llvm_name = "smem-to-vector-write-hazard",
636 .description = "s_load_dword followed by v_cmp page faults",
637 .dependencies = featureSet(&[_]Feature{}),
638 };
639 result[@enumToInt(Feature.southern_islands)] = .{
640 .llvm_name = "southern-islands",
641 .description = "SOUTHERN_ISLANDS GPU generation",
642 .dependencies = featureSet(&[_]Feature{
643 .fp64,
644 .ldsbankcount32,
645 .localmemorysize32768,
646 .mimg_r128,
647 .movrel,
648 .no_sram_ecc_support,
649 .no_xnack_support,
650 .trig_reduced_range,
651 .wavefrontsize64,
652 }),
653 };
654 result[@enumToInt(Feature.sram_ecc)] = .{
655 .llvm_name = "sram-ecc",
656 .description = "Enable SRAM ECC",
657 .dependencies = featureSet(&[_]Feature{}),
658 };
659 result[@enumToInt(Feature.trap_handler)] = .{
660 .llvm_name = "trap-handler",
661 .description = "Trap handler support",
662 .dependencies = featureSet(&[_]Feature{}),
663 };
664 result[@enumToInt(Feature.trig_reduced_range)] = .{
665 .llvm_name = "trig-reduced-range",
666 .description = "Requires use of fract on arguments to trig instructions",
667 .dependencies = featureSet(&[_]Feature{}),
668 };
669 result[@enumToInt(Feature.unaligned_buffer_access)] = .{
670 .llvm_name = "unaligned-buffer-access",
671 .description = "Support unaligned global loads and stores",
672 .dependencies = featureSet(&[_]Feature{}),
673 };
674 result[@enumToInt(Feature.unaligned_scratch_access)] = .{
675 .llvm_name = "unaligned-scratch-access",
676 .description = "Support unaligned scratch loads and stores",
677 .dependencies = featureSet(&[_]Feature{}),
678 };
679 result[@enumToInt(Feature.unpacked_d16_vmem)] = .{
680 .llvm_name = "unpacked-d16-vmem",
681 .description = "Has unpacked d16 vmem instructions",
682 .dependencies = featureSet(&[_]Feature{}),
683 };
684 result[@enumToInt(Feature.unsafe_ds_offset_folding)] = .{
685 .llvm_name = "unsafe-ds-offset-folding",
686 .description = "Force using DS instruction immediate offsets on SI",
687 .dependencies = featureSet(&[_]Feature{}),
688 };
689 result[@enumToInt(Feature.vcmpx_exec_war_hazard)] = .{
690 .llvm_name = "vcmpx-exec-war-hazard",
691 .description = "V_CMPX WAR hazard on EXEC (V_CMPX issue ONLY)",
692 .dependencies = featureSet(&[_]Feature{}),
693 };
694 result[@enumToInt(Feature.vcmpx_permlane_hazard)] = .{
695 .llvm_name = "vcmpx-permlane-hazard",
696 .description = "TODO: describe me",
697 .dependencies = featureSet(&[_]Feature{}),
698 };
699 result[@enumToInt(Feature.vgpr_index_mode)] = .{
700 .llvm_name = "vgpr-index-mode",
701 .description = "Has VGPR mode register indexing",
702 .dependencies = featureSet(&[_]Feature{}),
703 };
704 result[@enumToInt(Feature.vmem_to_scalar_write_hazard)] = .{
705 .llvm_name = "vmem-to-scalar-write-hazard",
706 .description = "VMEM instruction followed by scalar writing to EXEC mask, M0 or SGPR leads to incorrect execution.",
707 .dependencies = featureSet(&[_]Feature{}),
708 };
709 result[@enumToInt(Feature.volcanic_islands)] = .{
710 .llvm_name = "volcanic-islands",
711 .description = "VOLCANIC_ISLANDS GPU generation",
712 .dependencies = featureSet(&[_]Feature{
713 .@"16_bit_insts",
714 .ci_insts,
715 .dpp,
716 .flat_address_space,
717 .fp64,
718 .gcn3_encoding,
719 .gfx7_gfx8_gfx9_insts,
720 .gfx8_insts,
721 .int_clamp_insts,
722 .inv_2pi_inline_imm,
723 .localmemorysize65536,
724 .mimg_r128,
725 .movrel,
726 .no_sram_ecc_support,
727 .s_memrealtime,
728 .scalar_stores,
729 .sdwa,
730 .sdwa_mav,
731 .sdwa_out_mods_vopc,
732 .trig_reduced_range,
733 .vgpr_index_mode,
734 .wavefrontsize64,
735 }),
736 };
737 result[@enumToInt(Feature.vop3_literal)] = .{
738 .llvm_name = "vop3-literal",
739 .description = "Can use one literal in VOP3",
740 .dependencies = featureSet(&[_]Feature{}),
741 };
742 result[@enumToInt(Feature.vop3p)] = .{
743 .llvm_name = "vop3p",
744 .description = "Has VOP3P packed instructions",
745 .dependencies = featureSet(&[_]Feature{}),
746 };
747 result[@enumToInt(Feature.vscnt)] = .{
748 .llvm_name = "vscnt",
749 .description = "Has separate store vscnt counter",
750 .dependencies = featureSet(&[_]Feature{}),
751 };
752 result[@enumToInt(Feature.wavefrontsize16)] = .{
753 .llvm_name = "wavefrontsize16",
754 .description = "The number of threads per wavefront",
755 .dependencies = featureSet(&[_]Feature{}),
756 };
757 result[@enumToInt(Feature.wavefrontsize32)] = .{
758 .llvm_name = "wavefrontsize32",
759 .description = "The number of threads per wavefront",
760 .dependencies = featureSet(&[_]Feature{}),
761 };
762 result[@enumToInt(Feature.wavefrontsize64)] = .{
763 .llvm_name = "wavefrontsize64",
764 .description = "The number of threads per wavefront",
765 .dependencies = featureSet(&[_]Feature{}),
766 };
767 result[@enumToInt(Feature.xnack)] = .{
768 .llvm_name = "xnack",
769 .description = "Enable XNACK support",
770 .dependencies = featureSet(&[_]Feature{}),
771 };
772 const ti = @typeInfo(Feature);
773 for (result) |*elem, i| {
774 elem.index = i;
775 elem.name = ti.Enum.fields[i].name;
776 }
777 break :blk result;
778};
779
780pub const cpu = struct {
781 pub const bonaire = Cpu{
782 .name = "bonaire",
783 .llvm_name = "bonaire",
784 .features = featureSet(&[_]Feature{
785 .code_object_v3,
786 .ldsbankcount32,
787 .no_xnack_support,
788 .sea_islands,
789 }),
790 };
791 pub const carrizo = Cpu{
792 .name = "carrizo",
793 .llvm_name = "carrizo",
794 .features = featureSet(&[_]Feature{
795 .code_object_v3,
796 .fast_fmaf,
797 .half_rate_64_ops,
798 .ldsbankcount32,
799 .unpacked_d16_vmem,
800 .volcanic_islands,
801 .xnack,
802 }),
803 };
804 pub const fiji = Cpu{
805 .name = "fiji",
806 .llvm_name = "fiji",
807 .features = featureSet(&[_]Feature{
808 .code_object_v3,
809 .ldsbankcount32,
810 .no_xnack_support,
811 .unpacked_d16_vmem,
812 .volcanic_islands,
813 }),
814 };
815 pub const generic = Cpu{
816 .name = "generic",
817 .llvm_name = "generic",
818 .features = featureSet(&[_]Feature{
819 .wavefrontsize64,
820 }),
821 };
822 pub const generic_hsa = Cpu{
823 .name = "generic_hsa",
824 .llvm_name = "generic-hsa",
825 .features = featureSet(&[_]Feature{
826 .flat_address_space,
827 .wavefrontsize64,
828 }),
829 };
830 pub const gfx1010 = Cpu{
831 .name = "gfx1010",
832 .llvm_name = "gfx1010",
833 .features = featureSet(&[_]Feature{
834 .code_object_v3,
835 .dl_insts,
836 .flat_segment_offset_bug,
837 .gfx10,
838 .inst_fwd_prefetch_bug,
839 .lds_branch_vmem_war_hazard,
840 .lds_misaligned_bug,
841 .ldsbankcount32,
842 .no_xnack_support,
843 .nsa_encoding,
844 .nsa_to_vmem_bug,
845 .offset_3f_bug,
846 .scalar_atomics,
847 .scalar_flat_scratch_insts,
848 .scalar_stores,
849 .smem_to_vector_write_hazard,
850 .vcmpx_exec_war_hazard,
851 .vcmpx_permlane_hazard,
852 .vmem_to_scalar_write_hazard,
853 .wavefrontsize32,
854 }),
855 };
856 pub const gfx1011 = Cpu{
857 .name = "gfx1011",
858 .llvm_name = "gfx1011",
859 .features = featureSet(&[_]Feature{
860 .code_object_v3,
861 .dl_insts,
862 .dot1_insts,
863 .dot2_insts,
864 .dot5_insts,
865 .dot6_insts,
866 .flat_segment_offset_bug,
867 .gfx10,
868 .inst_fwd_prefetch_bug,
869 .lds_branch_vmem_war_hazard,
870 .ldsbankcount32,
871 .no_xnack_support,
872 .nsa_encoding,
873 .nsa_to_vmem_bug,
874 .offset_3f_bug,
875 .scalar_atomics,
876 .scalar_flat_scratch_insts,
877 .scalar_stores,
878 .smem_to_vector_write_hazard,
879 .vcmpx_exec_war_hazard,
880 .vcmpx_permlane_hazard,
881 .vmem_to_scalar_write_hazard,
882 .wavefrontsize32,
883 }),
884 };
885 pub const gfx1012 = Cpu{
886 .name = "gfx1012",
887 .llvm_name = "gfx1012",
888 .features = featureSet(&[_]Feature{
889 .code_object_v3,
890 .dl_insts,
891 .dot1_insts,
892 .dot2_insts,
893 .dot5_insts,
894 .dot6_insts,
895 .flat_segment_offset_bug,
896 .gfx10,
897 .inst_fwd_prefetch_bug,
898 .lds_branch_vmem_war_hazard,
899 .lds_misaligned_bug,
900 .ldsbankcount32,
901 .no_xnack_support,
902 .nsa_encoding,
903 .nsa_to_vmem_bug,
904 .offset_3f_bug,
905 .scalar_atomics,
906 .scalar_flat_scratch_insts,
907 .scalar_stores,
908 .smem_to_vector_write_hazard,
909 .vcmpx_exec_war_hazard,
910 .vcmpx_permlane_hazard,
911 .vmem_to_scalar_write_hazard,
912 .wavefrontsize32,
913 }),
914 };
915 pub const gfx600 = Cpu{
916 .name = "gfx600",
917 .llvm_name = "gfx600",
918 .features = featureSet(&[_]Feature{
919 .code_object_v3,
920 .fast_fmaf,
921 .half_rate_64_ops,
922 .ldsbankcount32,
923 .no_xnack_support,
924 .southern_islands,
925 }),
926 };
927 pub const gfx601 = Cpu{
928 .name = "gfx601",
929 .llvm_name = "gfx601",
930 .features = featureSet(&[_]Feature{
931 .code_object_v3,
932 .ldsbankcount32,
933 .no_xnack_support,
934 .southern_islands,
935 }),
936 };
937 pub const gfx700 = Cpu{
938 .name = "gfx700",
939 .llvm_name = "gfx700",
940 .features = featureSet(&[_]Feature{
941 .code_object_v3,
942 .ldsbankcount32,
943 .no_xnack_support,
944 .sea_islands,
945 }),
946 };
947 pub const gfx701 = Cpu{
948 .name = "gfx701",
949 .llvm_name = "gfx701",
950 .features = featureSet(&[_]Feature{
951 .code_object_v3,
952 .fast_fmaf,
953 .half_rate_64_ops,
954 .ldsbankcount32,
955 .no_xnack_support,
956 .sea_islands,
957 }),
958 };
959 pub const gfx702 = Cpu{
960 .name = "gfx702",
961 .llvm_name = "gfx702",
962 .features = featureSet(&[_]Feature{
963 .code_object_v3,
964 .fast_fmaf,
965 .ldsbankcount16,
966 .no_xnack_support,
967 .sea_islands,
968 }),
969 };
970 pub const gfx703 = Cpu{
971 .name = "gfx703",
972 .llvm_name = "gfx703",
973 .features = featureSet(&[_]Feature{
974 .code_object_v3,
975 .ldsbankcount16,
976 .no_xnack_support,
977 .sea_islands,
978 }),
979 };
980 pub const gfx704 = Cpu{
981 .name = "gfx704",
982 .llvm_name = "gfx704",
983 .features = featureSet(&[_]Feature{
984 .code_object_v3,
985 .ldsbankcount32,
986 .no_xnack_support,
987 .sea_islands,
988 }),
989 };
990 pub const gfx801 = Cpu{
991 .name = "gfx801",
992 .llvm_name = "gfx801",
993 .features = featureSet(&[_]Feature{
994 .code_object_v3,
995 .fast_fmaf,
996 .half_rate_64_ops,
997 .ldsbankcount32,
998 .unpacked_d16_vmem,
999 .volcanic_islands,
1000 .xnack,
1001 }),
1002 };
1003 pub const gfx802 = Cpu{
1004 .name = "gfx802",
1005 .llvm_name = "gfx802",
1006 .features = featureSet(&[_]Feature{
1007 .code_object_v3,
1008 .ldsbankcount32,
1009 .no_xnack_support,
1010 .sgpr_init_bug,
1011 .unpacked_d16_vmem,
1012 .volcanic_islands,
1013 }),
1014 };
1015 pub const gfx803 = Cpu{
1016 .name = "gfx803",
1017 .llvm_name = "gfx803",
1018 .features = featureSet(&[_]Feature{
1019 .code_object_v3,
1020 .ldsbankcount32,
1021 .no_xnack_support,
1022 .unpacked_d16_vmem,
1023 .volcanic_islands,
1024 }),
1025 };
1026 pub const gfx810 = Cpu{
1027 .name = "gfx810",
1028 .llvm_name = "gfx810",
1029 .features = featureSet(&[_]Feature{
1030 .code_object_v3,
1031 .ldsbankcount16,
1032 .volcanic_islands,
1033 .xnack,
1034 }),
1035 };
1036 pub const gfx900 = Cpu{
1037 .name = "gfx900",
1038 .llvm_name = "gfx900",
1039 .features = featureSet(&[_]Feature{
1040 .code_object_v3,
1041 .gfx9,
1042 .ldsbankcount32,
1043 .mad_mix_insts,
1044 .no_sram_ecc_support,
1045 .no_xnack_support,
1046 }),
1047 };
1048 pub const gfx902 = Cpu{
1049 .name = "gfx902",
1050 .llvm_name = "gfx902",
1051 .features = featureSet(&[_]Feature{
1052 .code_object_v3,
1053 .gfx9,
1054 .ldsbankcount32,
1055 .mad_mix_insts,
1056 .no_sram_ecc_support,
1057 .xnack,
1058 }),
1059 };
1060 pub const gfx904 = Cpu{
1061 .name = "gfx904",
1062 .llvm_name = "gfx904",
1063 .features = featureSet(&[_]Feature{
1064 .code_object_v3,
1065 .fma_mix_insts,
1066 .gfx9,
1067 .ldsbankcount32,
1068 .no_sram_ecc_support,
1069 .no_xnack_support,
1070 }),
1071 };
1072 pub const gfx906 = Cpu{
1073 .name = "gfx906",
1074 .llvm_name = "gfx906",
1075 .features = featureSet(&[_]Feature{
1076 .code_object_v3,
1077 .dl_insts,
1078 .dot1_insts,
1079 .dot2_insts,
1080 .fma_mix_insts,
1081 .gfx9,
1082 .half_rate_64_ops,
1083 .ldsbankcount32,
1084 .no_xnack_support,
1085 }),
1086 };
1087 pub const gfx908 = Cpu{
1088 .name = "gfx908",
1089 .llvm_name = "gfx908",
1090 .features = featureSet(&[_]Feature{
1091 .atomic_fadd_insts,
1092 .code_object_v3,
1093 .dl_insts,
1094 .dot1_insts,
1095 .dot2_insts,
1096 .dot3_insts,
1097 .dot4_insts,
1098 .dot5_insts,
1099 .dot6_insts,
1100 .fma_mix_insts,
1101 .gfx9,
1102 .half_rate_64_ops,
1103 .ldsbankcount32,
1104 .mai_insts,
1105 .pk_fmac_f16_inst,
1106 .sram_ecc,
1107 }),
1108 };
1109 pub const gfx909 = Cpu{
1110 .name = "gfx909",
1111 .llvm_name = "gfx909",
1112 .features = featureSet(&[_]Feature{
1113 .code_object_v3,
1114 .gfx9,
1115 .ldsbankcount32,
1116 .mad_mix_insts,
1117 .xnack,
1118 }),
1119 };
1120 pub const hainan = Cpu{
1121 .name = "hainan",
1122 .llvm_name = "hainan",
1123 .features = featureSet(&[_]Feature{
1124 .code_object_v3,
1125 .ldsbankcount32,
1126 .no_xnack_support,
1127 .southern_islands,
1128 }),
1129 };
1130 pub const hawaii = Cpu{
1131 .name = "hawaii",
1132 .llvm_name = "hawaii",
1133 .features = featureSet(&[_]Feature{
1134 .code_object_v3,
1135 .fast_fmaf,
1136 .half_rate_64_ops,
1137 .ldsbankcount32,
1138 .no_xnack_support,
1139 .sea_islands,
1140 }),
1141 };
1142 pub const iceland = Cpu{
1143 .name = "iceland",
1144 .llvm_name = "iceland",
1145 .features = featureSet(&[_]Feature{
1146 .code_object_v3,
1147 .ldsbankcount32,
1148 .no_xnack_support,
1149 .sgpr_init_bug,
1150 .unpacked_d16_vmem,
1151 .volcanic_islands,
1152 }),
1153 };
1154 pub const kabini = Cpu{
1155 .name = "kabini",
1156 .llvm_name = "kabini",
1157 .features = featureSet(&[_]Feature{
1158 .code_object_v3,
1159 .ldsbankcount16,
1160 .no_xnack_support,
1161 .sea_islands,
1162 }),
1163 };
1164 pub const kaveri = Cpu{
1165 .name = "kaveri",
1166 .llvm_name = "kaveri",
1167 .features = featureSet(&[_]Feature{
1168 .code_object_v3,
1169 .ldsbankcount32,
1170 .no_xnack_support,
1171 .sea_islands,
1172 }),
1173 };
1174 pub const mullins = Cpu{
1175 .name = "mullins",
1176 .llvm_name = "mullins",
1177 .features = featureSet(&[_]Feature{
1178 .code_object_v3,
1179 .ldsbankcount16,
1180 .no_xnack_support,
1181 .sea_islands,
1182 }),
1183 };
1184 pub const oland = Cpu{
1185 .name = "oland",
1186 .llvm_name = "oland",
1187 .features = featureSet(&[_]Feature{
1188 .code_object_v3,
1189 .ldsbankcount32,
1190 .no_xnack_support,
1191 .southern_islands,
1192 }),
1193 };
1194 pub const pitcairn = Cpu{
1195 .name = "pitcairn",
1196 .llvm_name = "pitcairn",
1197 .features = featureSet(&[_]Feature{
1198 .code_object_v3,
1199 .ldsbankcount32,
1200 .no_xnack_support,
1201 .southern_islands,
1202 }),
1203 };
1204 pub const polaris10 = Cpu{
1205 .name = "polaris10",
1206 .llvm_name = "polaris10",
1207 .features = featureSet(&[_]Feature{
1208 .code_object_v3,
1209 .ldsbankcount32,
1210 .no_xnack_support,
1211 .unpacked_d16_vmem,
1212 .volcanic_islands,
1213 }),
1214 };
1215 pub const polaris11 = Cpu{
1216 .name = "polaris11",
1217 .llvm_name = "polaris11",
1218 .features = featureSet(&[_]Feature{
1219 .code_object_v3,
1220 .ldsbankcount32,
1221 .no_xnack_support,
1222 .unpacked_d16_vmem,
1223 .volcanic_islands,
1224 }),
1225 };
1226 pub const stoney = Cpu{
1227 .name = "stoney",
1228 .llvm_name = "stoney",
1229 .features = featureSet(&[_]Feature{
1230 .code_object_v3,
1231 .ldsbankcount16,
1232 .volcanic_islands,
1233 .xnack,
1234 }),
1235 };
1236 pub const tahiti = Cpu{
1237 .name = "tahiti",
1238 .llvm_name = "tahiti",
1239 .features = featureSet(&[_]Feature{
1240 .code_object_v3,
1241 .fast_fmaf,
1242 .half_rate_64_ops,
1243 .ldsbankcount32,
1244 .no_xnack_support,
1245 .southern_islands,
1246 }),
1247 };
1248 pub const tonga = Cpu{
1249 .name = "tonga",
1250 .llvm_name = "tonga",
1251 .features = featureSet(&[_]Feature{
1252 .code_object_v3,
1253 .ldsbankcount32,
1254 .no_xnack_support,
1255 .sgpr_init_bug,
1256 .unpacked_d16_vmem,
1257 .volcanic_islands,
1258 }),
1259 };
1260 pub const verde = Cpu{
1261 .name = "verde",
1262 .llvm_name = "verde",
1263 .features = featureSet(&[_]Feature{
1264 .code_object_v3,
1265 .ldsbankcount32,
1266 .no_xnack_support,
1267 .southern_islands,
1268 }),
1269 };
1270};
1271
1272/// All amdgpu CPUs, sorted alphabetically by name.
1273/// TODO: Replace this with usage of `std.meta.declList`. It does work, but stage1
1274/// compiler has inefficient memory and CPU usage, affecting build times.
1275pub const all_cpus = &[_]*const Cpu{
1276 &cpu.bonaire,
1277 &cpu.carrizo,
1278 &cpu.fiji,
1279 &cpu.generic,
1280 &cpu.generic_hsa,
1281 &cpu.gfx1010,
1282 &cpu.gfx1011,
1283 &cpu.gfx1012,
1284 &cpu.gfx600,
1285 &cpu.gfx601,
1286 &cpu.gfx700,
1287 &cpu.gfx701,
1288 &cpu.gfx702,
1289 &cpu.gfx703,
1290 &cpu.gfx704,
1291 &cpu.gfx801,
1292 &cpu.gfx802,
1293 &cpu.gfx803,
1294 &cpu.gfx810,
1295 &cpu.gfx900,
1296 &cpu.gfx902,
1297 &cpu.gfx904,
1298 &cpu.gfx906,
1299 &cpu.gfx908,
1300 &cpu.gfx909,
1301 &cpu.hainan,
1302 &cpu.hawaii,
1303 &cpu.iceland,
1304 &cpu.kabini,
1305 &cpu.kaveri,
1306 &cpu.mullins,
1307 &cpu.oland,
1308 &cpu.pitcairn,
1309 &cpu.polaris10,
1310 &cpu.polaris11,
1311 &cpu.stoney,
1312 &cpu.tahiti,
1313 &cpu.tonga,
1314 &cpu.verde,
1315};
lib/std/target/arm.zig created+2333
...@@ -0,0 +1,2333 @@
1const std = @import("../std.zig");
2const Cpu = std.Target.Cpu;
3
4pub const Feature = enum {
5 @"32bit",
6 @"8msecext",
7 a12,
8 a15,
9 a17,
10 a32,
11 a35,
12 a5,
13 a53,
14 a55,
15 a57,
16 a7,
17 a72,
18 a73,
19 a75,
20 a76,
21 a8,
22 a9,
23 aclass,
24 acquire_release,
25 aes,
26 armv2,
27 armv2a,
28 armv3,
29 armv3m,
30 armv4,
31 armv4t,
32 armv5t,
33 armv5te,
34 armv5tej,
35 armv6,
36 armv6_m,
37 armv6j,
38 armv6k,
39 armv6kz,
40 armv6s_m,
41 armv6t2,
42 armv7_a,
43 armv7_m,
44 armv7_r,
45 armv7e_m,
46 armv7k,
47 armv7s,
48 armv7ve,
49 armv8_a,
50 armv8_m_base,
51 armv8_m_main,
52 armv8_r,
53 armv8_1_a,
54 armv8_1_m_main,
55 armv8_2_a,
56 armv8_3_a,
57 armv8_4_a,
58 armv8_5_a,
59 avoid_movs_shop,
60 avoid_partial_cpsr,
61 cheap_predicable_cpsr,
62 crc,
63 crypto,
64 d32,
65 db,
66 dfb,
67 disable_postra_scheduler,
68 dont_widen_vmovs,
69 dotprod,
70 dsp,
71 execute_only,
72 expand_fp_mlx,
73 exynos,
74 fp_armv8,
75 fp_armv8d16,
76 fp_armv8d16sp,
77 fp_armv8sp,
78 fp16,
79 fp16fml,
80 fp64,
81 fpao,
82 fpregs,
83 fpregs16,
84 fpregs64,
85 fullfp16,
86 fuse_aes,
87 fuse_literals,
88 hwdiv,
89 hwdiv_arm,
90 iwmmxt,
91 iwmmxt2,
92 krait,
93 kryo,
94 lob,
95 long_calls,
96 loop_align,
97 m3,
98 mclass,
99 mp,
100 muxed_units,
101 mve,
102 mve_fp,
103 nacl_trap,
104 neon,
105 neon_fpmovs,
106 neonfp,
107 no_branch_predictor,
108 no_movt,
109 no_neg_immediates,
110 noarm,
111 nonpipelined_vfp,
112 perfmon,
113 prefer_ishst,
114 prefer_vmovsr,
115 prof_unpr,
116 r4,
117 r5,
118 r52,
119 r7,
120 ras,
121 rclass,
122 read_tp_hard,
123 reserve_r9,
124 ret_addr_stack,
125 sb,
126 sha2,
127 slow_fp_brcc,
128 slow_load_D_subreg,
129 slow_odd_reg,
130 slow_vdup32,
131 slow_vgetlni32,
132 slowfpvmlx,
133 soft_float,
134 splat_vfp_neon,
135 strict_align,
136 swift,
137 thumb_mode,
138 thumb2,
139 trustzone,
140 use_aa,
141 use_misched,
142 v4t,
143 v5t,
144 v5te,
145 v6,
146 v6k,
147 v6m,
148 v6t2,
149 v7,
150 v7clrex,
151 v8,
152 v8_1a,
153 v8_1m_main,
154 v8_2a,
155 v8_3a,
156 v8_4a,
157 v8_5a,
158 v8m,
159 v8m_main,
160 vfp2,
161 vfp2d16,
162 vfp2d16sp,
163 vfp2sp,
164 vfp3,
165 vfp3d16,
166 vfp3d16sp,
167 vfp3sp,
168 vfp4,
169 vfp4d16,
170 vfp4d16sp,
171 vfp4sp,
172 virtualization,
173 vldn_align,
174 vmlx_forwarding,
175 vmlx_hazards,
176 wide_stride_vfp,
177 xscale,
178 zcz,
179};
180
181pub usingnamespace Cpu.Feature.feature_set_fns(Feature);
182
183pub const all_features = blk: {
184 @setEvalBranchQuota(10000);
185 const len = @typeInfo(Feature).Enum.fields.len;
186 std.debug.assert(len <= Cpu.Feature.Set.needed_bit_count);
187 var result: [len]Cpu.Feature = undefined;
188 result[@enumToInt(Feature.@"32bit")] = .{
189 .llvm_name = "32bit",
190 .description = "Prefer 32-bit Thumb instrs",
191 .dependencies = featureSet(&[_]Feature{}),
192 };
193 result[@enumToInt(Feature.@"8msecext")] = .{
194 .llvm_name = "8msecext",
195 .description = "Enable support for ARMv8-M Security Extensions",
196 .dependencies = featureSet(&[_]Feature{}),
197 };
198 result[@enumToInt(Feature.a12)] = .{
199 .llvm_name = "a12",
200 .description = "Cortex-A12 ARM processors",
201 .dependencies = featureSet(&[_]Feature{}),
202 };
203 result[@enumToInt(Feature.a15)] = .{
204 .llvm_name = "a15",
205 .description = "Cortex-A15 ARM processors",
206 .dependencies = featureSet(&[_]Feature{}),
207 };
208 result[@enumToInt(Feature.a17)] = .{
209 .llvm_name = "a17",
210 .description = "Cortex-A17 ARM processors",
211 .dependencies = featureSet(&[_]Feature{}),
212 };
213 result[@enumToInt(Feature.a32)] = .{
214 .llvm_name = "a32",
215 .description = "Cortex-A32 ARM processors",
216 .dependencies = featureSet(&[_]Feature{}),
217 };
218 result[@enumToInt(Feature.a35)] = .{
219 .llvm_name = "a35",
220 .description = "Cortex-A35 ARM processors",
221 .dependencies = featureSet(&[_]Feature{}),
222 };
223 result[@enumToInt(Feature.a5)] = .{
224 .llvm_name = "a5",
225 .description = "Cortex-A5 ARM processors",
226 .dependencies = featureSet(&[_]Feature{}),
227 };
228 result[@enumToInt(Feature.a53)] = .{
229 .llvm_name = "a53",
230 .description = "Cortex-A53 ARM processors",
231 .dependencies = featureSet(&[_]Feature{}),
232 };
233 result[@enumToInt(Feature.a55)] = .{
234 .llvm_name = "a55",
235 .description = "Cortex-A55 ARM processors",
236 .dependencies = featureSet(&[_]Feature{}),
237 };
238 result[@enumToInt(Feature.a57)] = .{
239 .llvm_name = "a57",
240 .description = "Cortex-A57 ARM processors",
241 .dependencies = featureSet(&[_]Feature{}),
242 };
243 result[@enumToInt(Feature.a7)] = .{
244 .llvm_name = "a7",
245 .description = "Cortex-A7 ARM processors",
246 .dependencies = featureSet(&[_]Feature{}),
247 };
248 result[@enumToInt(Feature.a72)] = .{
249 .llvm_name = "a72",
250 .description = "Cortex-A72 ARM processors",
251 .dependencies = featureSet(&[_]Feature{}),
252 };
253 result[@enumToInt(Feature.a73)] = .{
254 .llvm_name = "a73",
255 .description = "Cortex-A73 ARM processors",
256 .dependencies = featureSet(&[_]Feature{}),
257 };
258 result[@enumToInt(Feature.a75)] = .{
259 .llvm_name = "a75",
260 .description = "Cortex-A75 ARM processors",
261 .dependencies = featureSet(&[_]Feature{}),
262 };
263 result[@enumToInt(Feature.a76)] = .{
264 .llvm_name = "a76",
265 .description = "Cortex-A76 ARM processors",
266 .dependencies = featureSet(&[_]Feature{}),
267 };
268 result[@enumToInt(Feature.a8)] = .{
269 .llvm_name = "a8",
270 .description = "Cortex-A8 ARM processors",
271 .dependencies = featureSet(&[_]Feature{}),
272 };
273 result[@enumToInt(Feature.a9)] = .{
274 .llvm_name = "a9",
275 .description = "Cortex-A9 ARM processors",
276 .dependencies = featureSet(&[_]Feature{}),
277 };
278 result[@enumToInt(Feature.aclass)] = .{
279 .llvm_name = "aclass",
280 .description = "Is application profile ('A' series)",
281 .dependencies = featureSet(&[_]Feature{}),
282 };
283 result[@enumToInt(Feature.acquire_release)] = .{
284 .llvm_name = "acquire-release",
285 .description = "Has v8 acquire/release (lda/ldaex etc) instructions",
286 .dependencies = featureSet(&[_]Feature{}),
287 };
288 result[@enumToInt(Feature.aes)] = .{
289 .llvm_name = "aes",
290 .description = "Enable AES support",
291 .dependencies = featureSet(&[_]Feature{
292 .neon,
293 }),
294 };
295 result[@enumToInt(Feature.armv2)] = .{
296 .llvm_name = "armv2",
297 .description = "ARMv2 architecture",
298 .dependencies = featureSet(&[_]Feature{}),
299 };
300 result[@enumToInt(Feature.armv2a)] = .{
301 .llvm_name = "armv2a",
302 .description = "ARMv2a architecture",
303 .dependencies = featureSet(&[_]Feature{}),
304 };
305 result[@enumToInt(Feature.armv3)] = .{
306 .llvm_name = "armv3",
307 .description = "ARMv3 architecture",
308 .dependencies = featureSet(&[_]Feature{}),
309 };
310 result[@enumToInt(Feature.armv3m)] = .{
311 .llvm_name = "armv3m",
312 .description = "ARMv3m architecture",
313 .dependencies = featureSet(&[_]Feature{}),
314 };
315 result[@enumToInt(Feature.armv4)] = .{
316 .llvm_name = "armv4",
317 .description = "ARMv4 architecture",
318 .dependencies = featureSet(&[_]Feature{}),
319 };
320 result[@enumToInt(Feature.armv4t)] = .{
321 .llvm_name = "armv4t",
322 .description = "ARMv4t architecture",
323 .dependencies = featureSet(&[_]Feature{
324 .v4t,
325 }),
326 };
327 result[@enumToInt(Feature.armv5t)] = .{
328 .llvm_name = "armv5t",
329 .description = "ARMv5t architecture",
330 .dependencies = featureSet(&[_]Feature{
331 .v5t,
332 }),
333 };
334 result[@enumToInt(Feature.armv5te)] = .{
335 .llvm_name = "armv5te",
336 .description = "ARMv5te architecture",
337 .dependencies = featureSet(&[_]Feature{
338 .v5te,
339 }),
340 };
341 result[@enumToInt(Feature.armv5tej)] = .{
342 .llvm_name = "armv5tej",
343 .description = "ARMv5tej architecture",
344 .dependencies = featureSet(&[_]Feature{
345 .v5te,
346 }),
347 };
348 result[@enumToInt(Feature.armv6)] = .{
349 .llvm_name = "armv6",
350 .description = "ARMv6 architecture",
351 .dependencies = featureSet(&[_]Feature{
352 .dsp,
353 .v6,
354 }),
355 };
356 result[@enumToInt(Feature.armv6_m)] = .{
357 .llvm_name = "armv6-m",
358 .description = "ARMv6m architecture",
359 .dependencies = featureSet(&[_]Feature{
360 .db,
361 .mclass,
362 .noarm,
363 .strict_align,
364 .thumb_mode,
365 .v6m,
366 }),
367 };
368 result[@enumToInt(Feature.armv6j)] = .{
369 .llvm_name = "armv6j",
370 .description = "ARMv7a architecture",
371 .dependencies = featureSet(&[_]Feature{
372 .armv6,
373 }),
374 };
375 result[@enumToInt(Feature.armv6k)] = .{
376 .llvm_name = "armv6k",
377 .description = "ARMv6k architecture",
378 .dependencies = featureSet(&[_]Feature{
379 .v6k,
380 }),
381 };
382 result[@enumToInt(Feature.armv6kz)] = .{
383 .llvm_name = "armv6kz",
384 .description = "ARMv6kz architecture",
385 .dependencies = featureSet(&[_]Feature{
386 .trustzone,
387 .v6k,
388 }),
389 };
390 result[@enumToInt(Feature.armv6s_m)] = .{
391 .llvm_name = "armv6s-m",
392 .description = "ARMv6sm architecture",
393 .dependencies = featureSet(&[_]Feature{
394 .db,
395 .mclass,
396 .noarm,
397 .strict_align,
398 .thumb_mode,
399 .v6m,
400 }),
401 };
402 result[@enumToInt(Feature.armv6t2)] = .{
403 .llvm_name = "armv6t2",
404 .description = "ARMv6t2 architecture",
405 .dependencies = featureSet(&[_]Feature{
406 .dsp,
407 .v6t2,
408 }),
409 };
410 result[@enumToInt(Feature.armv7_a)] = .{
411 .llvm_name = "armv7-a",
412 .description = "ARMv7a architecture",
413 .dependencies = featureSet(&[_]Feature{
414 .aclass,
415 .db,
416 .dsp,
417 .neon,
418 .v7,
419 }),
420 };
421 result[@enumToInt(Feature.armv7_m)] = .{
422 .llvm_name = "armv7-m",
423 .description = "ARMv7m architecture",
424 .dependencies = featureSet(&[_]Feature{
425 .db,
426 .hwdiv,
427 .mclass,
428 .noarm,
429 .thumb_mode,
430 .thumb2,
431 .v7,
432 }),
433 };
434 result[@enumToInt(Feature.armv7_r)] = .{
435 .llvm_name = "armv7-r",
436 .description = "ARMv7r architecture",
437 .dependencies = featureSet(&[_]Feature{
438 .db,
439 .dsp,
440 .hwdiv,
441 .rclass,
442 .v7,
443 }),
444 };
445 result[@enumToInt(Feature.armv7e_m)] = .{
446 .llvm_name = "armv7e-m",
447 .description = "ARMv7em architecture",
448 .dependencies = featureSet(&[_]Feature{
449 .db,
450 .dsp,
451 .hwdiv,
452 .mclass,
453 .noarm,
454 .thumb_mode,
455 .thumb2,
456 .v7,
457 }),
458 };
459 result[@enumToInt(Feature.armv7k)] = .{
460 .llvm_name = "armv7k",
461 .description = "ARMv7a architecture",
462 .dependencies = featureSet(&[_]Feature{
463 .armv7_a,
464 }),
465 };
466 result[@enumToInt(Feature.armv7s)] = .{
467 .llvm_name = "armv7s",
468 .description = "ARMv7a architecture",
469 .dependencies = featureSet(&[_]Feature{
470 .armv7_a,
471 }),
472 };
473 result[@enumToInt(Feature.armv7ve)] = .{
474 .llvm_name = "armv7ve",
475 .description = "ARMv7ve architecture",
476 .dependencies = featureSet(&[_]Feature{
477 .aclass,
478 .db,
479 .dsp,
480 .mp,
481 .neon,
482 .trustzone,
483 .v7,
484 .virtualization,
485 }),
486 };
487 result[@enumToInt(Feature.armv8_a)] = .{
488 .llvm_name = "armv8-a",
489 .description = "ARMv8a architecture",
490 .dependencies = featureSet(&[_]Feature{
491 .aclass,
492 .crc,
493 .crypto,
494 .db,
495 .dsp,
496 .fp_armv8,
497 .mp,
498 .neon,
499 .trustzone,
500 .v8,
501 .virtualization,
502 }),
503 };
504 result[@enumToInt(Feature.armv8_m_base)] = .{
505 .llvm_name = "armv8-m.base",
506 .description = "ARMv8mBaseline architecture",
507 .dependencies = featureSet(&[_]Feature{
508 .@"8msecext",
509 .acquire_release,
510 .db,
511 .hwdiv,
512 .mclass,
513 .noarm,
514 .strict_align,
515 .thumb_mode,
516 .v7clrex,
517 .v8m,
518 }),
519 };
520 result[@enumToInt(Feature.armv8_m_main)] = .{
521 .llvm_name = "armv8-m.main",
522 .description = "ARMv8mMainline architecture",
523 .dependencies = featureSet(&[_]Feature{
524 .@"8msecext",
525 .acquire_release,
526 .db,
527 .hwdiv,
528 .mclass,
529 .noarm,
530 .thumb_mode,
531 .v8m_main,
532 }),
533 };
534 result[@enumToInt(Feature.armv8_r)] = .{
535 .llvm_name = "armv8-r",
536 .description = "ARMv8r architecture",
537 .dependencies = featureSet(&[_]Feature{
538 .crc,
539 .db,
540 .dfb,
541 .dsp,
542 .fp_armv8,
543 .mp,
544 .neon,
545 .rclass,
546 .v8,
547 .virtualization,
548 }),
549 };
550 result[@enumToInt(Feature.armv8_1_a)] = .{
551 .llvm_name = "armv8.1-a",
552 .description = "ARMv81a architecture",
553 .dependencies = featureSet(&[_]Feature{
554 .aclass,
555 .crc,
556 .crypto,
557 .db,
558 .dsp,
559 .fp_armv8,
560 .mp,
561 .neon,
562 .trustzone,
563 .v8_1a,
564 .virtualization,
565 }),
566 };
567 result[@enumToInt(Feature.armv8_1_m_main)] = .{
568 .llvm_name = "armv8.1-m.main",
569 .description = "ARMv81mMainline architecture",
570 .dependencies = featureSet(&[_]Feature{
571 .@"8msecext",
572 .acquire_release,
573 .db,
574 .hwdiv,
575 .lob,
576 .mclass,
577 .noarm,
578 .ras,
579 .thumb_mode,
580 .v8_1m_main,
581 }),
582 };
583 result[@enumToInt(Feature.armv8_2_a)] = .{
584 .llvm_name = "armv8.2-a",
585 .description = "ARMv82a architecture",
586 .dependencies = featureSet(&[_]Feature{
587 .aclass,
588 .crc,
589 .crypto,
590 .db,
591 .dsp,
592 .fp_armv8,
593 .mp,
594 .neon,
595 .ras,
596 .trustzone,
597 .v8_2a,
598 .virtualization,
599 }),
600 };
601 result[@enumToInt(Feature.armv8_3_a)] = .{
602 .llvm_name = "armv8.3-a",
603 .description = "ARMv83a architecture",
604 .dependencies = featureSet(&[_]Feature{
605 .aclass,
606 .crc,
607 .crypto,
608 .db,
609 .dsp,
610 .fp_armv8,
611 .mp,
612 .neon,
613 .ras,
614 .trustzone,
615 .v8_3a,
616 .virtualization,
617 }),
618 };
619 result[@enumToInt(Feature.armv8_4_a)] = .{
620 .llvm_name = "armv8.4-a",
621 .description = "ARMv84a architecture",
622 .dependencies = featureSet(&[_]Feature{
623 .aclass,
624 .crc,
625 .crypto,
626 .db,
627 .dotprod,
628 .dsp,
629 .fp_armv8,
630 .mp,
631 .neon,
632 .ras,
633 .trustzone,
634 .v8_4a,
635 .virtualization,
636 }),
637 };
638 result[@enumToInt(Feature.armv8_5_a)] = .{
639 .llvm_name = "armv8.5-a",
640 .description = "ARMv85a architecture",
641 .dependencies = featureSet(&[_]Feature{
642 .aclass,
643 .crc,
644 .crypto,
645 .db,
646 .dotprod,
647 .dsp,
648 .fp_armv8,
649 .mp,
650 .neon,
651 .ras,
652 .trustzone,
653 .v8_5a,
654 .virtualization,
655 }),
656 };
657 result[@enumToInt(Feature.avoid_movs_shop)] = .{
658 .llvm_name = "avoid-movs-shop",
659 .description = "Avoid movs instructions with shifter operand",
660 .dependencies = featureSet(&[_]Feature{}),
661 };
662 result[@enumToInt(Feature.avoid_partial_cpsr)] = .{
663 .llvm_name = "avoid-partial-cpsr",
664 .description = "Avoid CPSR partial update for OOO execution",
665 .dependencies = featureSet(&[_]Feature{}),
666 };
667 result[@enumToInt(Feature.cheap_predicable_cpsr)] = .{
668 .llvm_name = "cheap-predicable-cpsr",
669 .description = "Disable +1 predication cost for instructions updating CPSR",
670 .dependencies = featureSet(&[_]Feature{}),
671 };
672 result[@enumToInt(Feature.crc)] = .{
673 .llvm_name = "crc",
674 .description = "Enable support for CRC instructions",
675 .dependencies = featureSet(&[_]Feature{}),
676 };
677 result[@enumToInt(Feature.crypto)] = .{
678 .llvm_name = "crypto",
679 .description = "Enable support for Cryptography extensions",
680 .dependencies = featureSet(&[_]Feature{
681 .aes,
682 .neon,
683 .sha2,
684 }),
685 };
686 result[@enumToInt(Feature.d32)] = .{
687 .llvm_name = "d32",
688 .description = "Extend FP to 32 double registers",
689 .dependencies = featureSet(&[_]Feature{}),
690 };
691 result[@enumToInt(Feature.db)] = .{
692 .llvm_name = "db",
693 .description = "Has data barrier (dmb/dsb) instructions",
694 .dependencies = featureSet(&[_]Feature{}),
695 };
696 result[@enumToInt(Feature.dfb)] = .{
697 .llvm_name = "dfb",
698 .description = "Has full data barrier (dfb) instruction",
699 .dependencies = featureSet(&[_]Feature{}),
700 };
701 result[@enumToInt(Feature.disable_postra_scheduler)] = .{
702 .llvm_name = "disable-postra-scheduler",
703 .description = "Don't schedule again after register allocation",
704 .dependencies = featureSet(&[_]Feature{}),
705 };
706 result[@enumToInt(Feature.dont_widen_vmovs)] = .{
707 .llvm_name = "dont-widen-vmovs",
708 .description = "Don't widen VMOVS to VMOVD",
709 .dependencies = featureSet(&[_]Feature{}),
710 };
711 result[@enumToInt(Feature.dotprod)] = .{
712 .llvm_name = "dotprod",
713 .description = "Enable support for dot product instructions",
714 .dependencies = featureSet(&[_]Feature{
715 .neon,
716 }),
717 };
718 result[@enumToInt(Feature.dsp)] = .{
719 .llvm_name = "dsp",
720 .description = "Supports DSP instructions in ARM and/or Thumb2",
721 .dependencies = featureSet(&[_]Feature{}),
722 };
723 result[@enumToInt(Feature.execute_only)] = .{
724 .llvm_name = "execute-only",
725 .description = "Enable the generation of execute only code.",
726 .dependencies = featureSet(&[_]Feature{}),
727 };
728 result[@enumToInt(Feature.expand_fp_mlx)] = .{
729 .llvm_name = "expand-fp-mlx",
730 .description = "Expand VFP/NEON MLA/MLS instructions",
731 .dependencies = featureSet(&[_]Feature{}),
732 };
733 result[@enumToInt(Feature.exynos)] = .{
734 .llvm_name = "exynos",
735 .description = "Samsung Exynos processors",
736 .dependencies = featureSet(&[_]Feature{
737 .crc,
738 .crypto,
739 .expand_fp_mlx,
740 .fuse_aes,
741 .fuse_literals,
742 .hwdiv,
743 .hwdiv_arm,
744 .prof_unpr,
745 .ret_addr_stack,
746 .slow_fp_brcc,
747 .slow_vdup32,
748 .slow_vgetlni32,
749 .slowfpvmlx,
750 .splat_vfp_neon,
751 .use_aa,
752 .wide_stride_vfp,
753 .zcz,
754 }),
755 };
756 result[@enumToInt(Feature.fp_armv8)] = .{
757 .llvm_name = "fp-armv8",
758 .description = "Enable ARMv8 FP",
759 .dependencies = featureSet(&[_]Feature{
760 .fp_armv8d16,
761 .fp_armv8sp,
762 .vfp4,
763 }),
764 };
765 result[@enumToInt(Feature.fp_armv8d16)] = .{
766 .llvm_name = "fp-armv8d16",
767 .description = "Enable ARMv8 FP with only 16 d-registers",
768 .dependencies = featureSet(&[_]Feature{
769 .fp_armv8d16sp,
770 .fp64,
771 .vfp4d16,
772 }),
773 };
774 result[@enumToInt(Feature.fp_armv8d16sp)] = .{
775 .llvm_name = "fp-armv8d16sp",
776 .description = "Enable ARMv8 FP with only 16 d-registers and no double precision",
777 .dependencies = featureSet(&[_]Feature{
778 .vfp4d16sp,
779 }),
780 };
781 result[@enumToInt(Feature.fp_armv8sp)] = .{
782 .llvm_name = "fp-armv8sp",
783 .description = "Enable ARMv8 FP with no double precision",
784 .dependencies = featureSet(&[_]Feature{
785 .d32,
786 .fp_armv8d16sp,
787 .vfp4sp,
788 }),
789 };
790 result[@enumToInt(Feature.fp16)] = .{
791 .llvm_name = "fp16",
792 .description = "Enable half-precision floating point",
793 .dependencies = featureSet(&[_]Feature{}),
794 };
795 result[@enumToInt(Feature.fp16fml)] = .{
796 .llvm_name = "fp16fml",
797 .description = "Enable full half-precision floating point fml instructions",
798 .dependencies = featureSet(&[_]Feature{
799 .fullfp16,
800 }),
801 };
802 result[@enumToInt(Feature.fp64)] = .{
803 .llvm_name = "fp64",
804 .description = "Floating point unit supports double precision",
805 .dependencies = featureSet(&[_]Feature{
806 .fpregs64,
807 }),
808 };
809 result[@enumToInt(Feature.fpao)] = .{
810 .llvm_name = "fpao",
811 .description = "Enable fast computation of positive address offsets",
812 .dependencies = featureSet(&[_]Feature{}),
813 };
814 result[@enumToInt(Feature.fpregs)] = .{
815 .llvm_name = "fpregs",
816 .description = "Enable FP registers",
817 .dependencies = featureSet(&[_]Feature{}),
818 };
819 result[@enumToInt(Feature.fpregs16)] = .{
820 .llvm_name = "fpregs16",
821 .description = "Enable 16-bit FP registers",
822 .dependencies = featureSet(&[_]Feature{
823 .fpregs,
824 }),
825 };
826 result[@enumToInt(Feature.fpregs64)] = .{
827 .llvm_name = "fpregs64",
828 .description = "Enable 64-bit FP registers",
829 .dependencies = featureSet(&[_]Feature{
830 .fpregs,
831 }),
832 };
833 result[@enumToInt(Feature.fullfp16)] = .{
834 .llvm_name = "fullfp16",
835 .description = "Enable full half-precision floating point",
836 .dependencies = featureSet(&[_]Feature{
837 .fp_armv8d16sp,
838 .fpregs16,
839 }),
840 };
841 result[@enumToInt(Feature.fuse_aes)] = .{
842 .llvm_name = "fuse-aes",
843 .description = "CPU fuses AES crypto operations",
844 .dependencies = featureSet(&[_]Feature{}),
845 };
846 result[@enumToInt(Feature.fuse_literals)] = .{
847 .llvm_name = "fuse-literals",
848 .description = "CPU fuses literal generation operations",
849 .dependencies = featureSet(&[_]Feature{}),
850 };
851 result[@enumToInt(Feature.hwdiv)] = .{
852 .llvm_name = "hwdiv",
853 .description = "Enable divide instructions in Thumb",
854 .dependencies = featureSet(&[_]Feature{}),
855 };
856 result[@enumToInt(Feature.hwdiv_arm)] = .{
857 .llvm_name = "hwdiv-arm",
858 .description = "Enable divide instructions in ARM mode",
859 .dependencies = featureSet(&[_]Feature{}),
860 };
861 result[@enumToInt(Feature.iwmmxt)] = .{
862 .llvm_name = "iwmmxt",
863 .description = "ARMv5te architecture",
864 .dependencies = featureSet(&[_]Feature{
865 .armv5te,
866 }),
867 };
868 result[@enumToInt(Feature.iwmmxt2)] = .{
869 .llvm_name = "iwmmxt2",
870 .description = "ARMv5te architecture",
871 .dependencies = featureSet(&[_]Feature{
872 .armv5te,
873 }),
874 };
875 result[@enumToInt(Feature.krait)] = .{
876 .llvm_name = "krait",
877 .description = "Qualcomm Krait processors",
878 .dependencies = featureSet(&[_]Feature{}),
879 };
880 result[@enumToInt(Feature.kryo)] = .{
881 .llvm_name = "kryo",
882 .description = "Qualcomm Kryo processors",
883 .dependencies = featureSet(&[_]Feature{}),
884 };
885 result[@enumToInt(Feature.lob)] = .{
886 .llvm_name = "lob",
887 .description = "Enable Low Overhead Branch extensions",
888 .dependencies = featureSet(&[_]Feature{}),
889 };
890 result[@enumToInt(Feature.long_calls)] = .{
891 .llvm_name = "long-calls",
892 .description = "Generate calls via indirect call instructions",
893 .dependencies = featureSet(&[_]Feature{}),
894 };
895 result[@enumToInt(Feature.loop_align)] = .{
896 .llvm_name = "loop-align",
897 .description = "Prefer 32-bit alignment for loops",
898 .dependencies = featureSet(&[_]Feature{}),
899 };
900 result[@enumToInt(Feature.m3)] = .{
901 .llvm_name = "m3",
902 .description = "Cortex-M3 ARM processors",
903 .dependencies = featureSet(&[_]Feature{}),
904 };
905 result[@enumToInt(Feature.mclass)] = .{
906 .llvm_name = "mclass",
907 .description = "Is microcontroller profile ('M' series)",
908 .dependencies = featureSet(&[_]Feature{}),
909 };
910 result[@enumToInt(Feature.mp)] = .{
911 .llvm_name = "mp",
912 .description = "Supports Multiprocessing extension",
913 .dependencies = featureSet(&[_]Feature{}),
914 };
915 result[@enumToInt(Feature.muxed_units)] = .{
916 .llvm_name = "muxed-units",
917 .description = "Has muxed AGU and NEON/FPU",
918 .dependencies = featureSet(&[_]Feature{}),
919 };
920 result[@enumToInt(Feature.mve)] = .{
921 .llvm_name = "mve",
922 .description = "Support M-Class Vector Extension with integer ops",
923 .dependencies = featureSet(&[_]Feature{
924 .dsp,
925 .fpregs16,
926 .fpregs64,
927 .v8_1m_main,
928 }),
929 };
930 result[@enumToInt(Feature.mve_fp)] = .{
931 .llvm_name = "mve.fp",
932 .description = "Support M-Class Vector Extension with integer and floating ops",
933 .dependencies = featureSet(&[_]Feature{
934 .fp_armv8d16sp,
935 .fullfp16,
936 .mve,
937 }),
938 };
939 result[@enumToInt(Feature.nacl_trap)] = .{
940 .llvm_name = "nacl-trap",
941 .description = "NaCl trap",
942 .dependencies = featureSet(&[_]Feature{}),
943 };
944 result[@enumToInt(Feature.neon)] = .{
945 .llvm_name = "neon",
946 .description = "Enable NEON instructions",
947 .dependencies = featureSet(&[_]Feature{
948 .vfp3,
949 }),
950 };
951 result[@enumToInt(Feature.neon_fpmovs)] = .{
952 .llvm_name = "neon-fpmovs",
953 .description = "Convert VMOVSR, VMOVRS, VMOVS to NEON",
954 .dependencies = featureSet(&[_]Feature{}),
955 };
956 result[@enumToInt(Feature.neonfp)] = .{
957 .llvm_name = "neonfp",
958 .description = "Use NEON for single precision FP",
959 .dependencies = featureSet(&[_]Feature{}),
960 };
961 result[@enumToInt(Feature.no_branch_predictor)] = .{
962 .llvm_name = "no-branch-predictor",
963 .description = "Has no branch predictor",
964 .dependencies = featureSet(&[_]Feature{}),
965 };
966 result[@enumToInt(Feature.no_movt)] = .{
967 .llvm_name = "no-movt",
968 .description = "Don't use movt/movw pairs for 32-bit imms",
969 .dependencies = featureSet(&[_]Feature{}),
970 };
971 result[@enumToInt(Feature.no_neg_immediates)] = .{
972 .llvm_name = "no-neg-immediates",
973 .description = "Convert immediates and instructions to their negated or complemented equivalent when the immediate does not fit in the encoding.",
974 .dependencies = featureSet(&[_]Feature{}),
975 };
976 result[@enumToInt(Feature.noarm)] = .{
977 .llvm_name = "noarm",
978 .description = "Does not support ARM mode execution",
979 .dependencies = featureSet(&[_]Feature{}),
980 };
981 result[@enumToInt(Feature.nonpipelined_vfp)] = .{
982 .llvm_name = "nonpipelined-vfp",
983 .description = "VFP instructions are not pipelined",
984 .dependencies = featureSet(&[_]Feature{}),
985 };
986 result[@enumToInt(Feature.perfmon)] = .{
987 .llvm_name = "perfmon",
988 .description = "Enable support for Performance Monitor extensions",
989 .dependencies = featureSet(&[_]Feature{}),
990 };
991 result[@enumToInt(Feature.prefer_ishst)] = .{
992 .llvm_name = "prefer-ishst",
993 .description = "Prefer ISHST barriers",
994 .dependencies = featureSet(&[_]Feature{}),
995 };
996 result[@enumToInt(Feature.prefer_vmovsr)] = .{
997 .llvm_name = "prefer-vmovsr",
998 .description = "Prefer VMOVSR",
999 .dependencies = featureSet(&[_]Feature{}),
1000 };
1001 result[@enumToInt(Feature.prof_unpr)] = .{
1002 .llvm_name = "prof-unpr",
1003 .description = "Is profitable to unpredicate",
1004 .dependencies = featureSet(&[_]Feature{}),
1005 };
1006 result[@enumToInt(Feature.r4)] = .{
1007 .llvm_name = "r4",
1008 .description = "Cortex-R4 ARM processors",
1009 .dependencies = featureSet(&[_]Feature{}),
1010 };
1011 result[@enumToInt(Feature.r5)] = .{
1012 .llvm_name = "r5",
1013 .description = "Cortex-R5 ARM processors",
1014 .dependencies = featureSet(&[_]Feature{}),
1015 };
1016 result[@enumToInt(Feature.r52)] = .{
1017 .llvm_name = "r52",
1018 .description = "Cortex-R52 ARM processors",
1019 .dependencies = featureSet(&[_]Feature{}),
1020 };
1021 result[@enumToInt(Feature.r7)] = .{
1022 .llvm_name = "r7",
1023 .description = "Cortex-R7 ARM processors",
1024 .dependencies = featureSet(&[_]Feature{}),
1025 };
1026 result[@enumToInt(Feature.ras)] = .{
1027 .llvm_name = "ras",
1028 .description = "Enable Reliability, Availability and Serviceability extensions",
1029 .dependencies = featureSet(&[_]Feature{}),
1030 };
1031 result[@enumToInt(Feature.rclass)] = .{
1032 .llvm_name = "rclass",
1033 .description = "Is realtime profile ('R' series)",
1034 .dependencies = featureSet(&[_]Feature{}),
1035 };
1036 result[@enumToInt(Feature.read_tp_hard)] = .{
1037 .llvm_name = "read-tp-hard",
1038 .description = "Reading thread pointer from register",
1039 .dependencies = featureSet(&[_]Feature{}),
1040 };
1041 result[@enumToInt(Feature.reserve_r9)] = .{
1042 .llvm_name = "reserve-r9",
1043 .description = "Reserve R9, making it unavailable as GPR",
1044 .dependencies = featureSet(&[_]Feature{}),
1045 };
1046 result[@enumToInt(Feature.ret_addr_stack)] = .{
1047 .llvm_name = "ret-addr-stack",
1048 .description = "Has return address stack",
1049 .dependencies = featureSet(&[_]Feature{}),
1050 };
1051 result[@enumToInt(Feature.sb)] = .{
1052 .llvm_name = "sb",
1053 .description = "Enable v8.5a Speculation Barrier",
1054 .dependencies = featureSet(&[_]Feature{}),
1055 };
1056 result[@enumToInt(Feature.sha2)] = .{
1057 .llvm_name = "sha2",
1058 .description = "Enable SHA1 and SHA256 support",
1059 .dependencies = featureSet(&[_]Feature{
1060 .neon,
1061 }),
1062 };
1063 result[@enumToInt(Feature.slow_fp_brcc)] = .{
1064 .llvm_name = "slow-fp-brcc",
1065 .description = "FP compare + branch is slow",
1066 .dependencies = featureSet(&[_]Feature{}),
1067 };
1068 result[@enumToInt(Feature.slow_load_D_subreg)] = .{
1069 .llvm_name = "slow-load-D-subreg",
1070 .description = "Loading into D subregs is slow",
1071 .dependencies = featureSet(&[_]Feature{}),
1072 };
1073 result[@enumToInt(Feature.slow_odd_reg)] = .{
1074 .llvm_name = "slow-odd-reg",
1075 .description = "VLDM/VSTM starting with an odd register is slow",
1076 .dependencies = featureSet(&[_]Feature{}),
1077 };
1078 result[@enumToInt(Feature.slow_vdup32)] = .{
1079 .llvm_name = "slow-vdup32",
1080 .description = "Has slow VDUP32 - prefer VMOV",
1081 .dependencies = featureSet(&[_]Feature{}),
1082 };
1083 result[@enumToInt(Feature.slow_vgetlni32)] = .{
1084 .llvm_name = "slow-vgetlni32",
1085 .description = "Has slow VGETLNi32 - prefer VMOV",
1086 .dependencies = featureSet(&[_]Feature{}),
1087 };
1088 result[@enumToInt(Feature.slowfpvmlx)] = .{
1089 .llvm_name = "slowfpvmlx",
1090 .description = "Disable VFP / NEON MAC instructions",
1091 .dependencies = featureSet(&[_]Feature{}),
1092 };
1093 result[@enumToInt(Feature.soft_float)] = .{
1094 .llvm_name = "soft-float",
1095 .description = "Use software floating point features.",
1096 .dependencies = featureSet(&[_]Feature{}),
1097 };
1098 result[@enumToInt(Feature.splat_vfp_neon)] = .{
1099 .llvm_name = "splat-vfp-neon",
1100 .description = "Splat register from VFP to NEON",
1101 .dependencies = featureSet(&[_]Feature{
1102 .dont_widen_vmovs,
1103 }),
1104 };
1105 result[@enumToInt(Feature.strict_align)] = .{
1106 .llvm_name = "strict-align",
1107 .description = "Disallow all unaligned memory access",
1108 .dependencies = featureSet(&[_]Feature{}),
1109 };
1110 result[@enumToInt(Feature.swift)] = .{
1111 .llvm_name = "swift",
1112 .description = "Swift ARM processors",
1113 .dependencies = featureSet(&[_]Feature{}),
1114 };
1115 result[@enumToInt(Feature.thumb_mode)] = .{
1116 .llvm_name = "thumb-mode",
1117 .description = "Thumb mode",
1118 .dependencies = featureSet(&[_]Feature{}),
1119 };
1120 result[@enumToInt(Feature.thumb2)] = .{
1121 .llvm_name = "thumb2",
1122 .description = "Enable Thumb2 instructions",
1123 .dependencies = featureSet(&[_]Feature{}),
1124 };
1125 result[@enumToInt(Feature.trustzone)] = .{
1126 .llvm_name = "trustzone",
1127 .description = "Enable support for TrustZone security extensions",
1128 .dependencies = featureSet(&[_]Feature{}),
1129 };
1130 result[@enumToInt(Feature.use_aa)] = .{
1131 .llvm_name = "use-aa",
1132 .description = "Use alias analysis during codegen",
1133 .dependencies = featureSet(&[_]Feature{}),
1134 };
1135 result[@enumToInt(Feature.use_misched)] = .{
1136 .llvm_name = "use-misched",
1137 .description = "Use the MachineScheduler",
1138 .dependencies = featureSet(&[_]Feature{}),
1139 };
1140 result[@enumToInt(Feature.v4t)] = .{
1141 .llvm_name = "v4t",
1142 .description = "Support ARM v4T instructions",
1143 .dependencies = featureSet(&[_]Feature{}),
1144 };
1145 result[@enumToInt(Feature.v5t)] = .{
1146 .llvm_name = "v5t",
1147 .description = "Support ARM v5T instructions",
1148 .dependencies = featureSet(&[_]Feature{
1149 .v4t,
1150 }),
1151 };
1152 result[@enumToInt(Feature.v5te)] = .{
1153 .llvm_name = "v5te",
1154 .description = "Support ARM v5TE, v5TEj, and v5TExp instructions",
1155 .dependencies = featureSet(&[_]Feature{
1156 .v5t,
1157 }),
1158 };
1159 result[@enumToInt(Feature.v6)] = .{
1160 .llvm_name = "v6",
1161 .description = "Support ARM v6 instructions",
1162 .dependencies = featureSet(&[_]Feature{
1163 .v5te,
1164 }),
1165 };
1166 result[@enumToInt(Feature.v6k)] = .{
1167 .llvm_name = "v6k",
1168 .description = "Support ARM v6k instructions",
1169 .dependencies = featureSet(&[_]Feature{
1170 .v6,
1171 }),
1172 };
1173 result[@enumToInt(Feature.v6m)] = .{
1174 .llvm_name = "v6m",
1175 .description = "Support ARM v6M instructions",
1176 .dependencies = featureSet(&[_]Feature{
1177 .v6,
1178 }),
1179 };
1180 result[@enumToInt(Feature.v6t2)] = .{
1181 .llvm_name = "v6t2",
1182 .description = "Support ARM v6t2 instructions",
1183 .dependencies = featureSet(&[_]Feature{
1184 .thumb2,
1185 .v6k,
1186 .v8m,
1187 }),
1188 };
1189 result[@enumToInt(Feature.v7)] = .{
1190 .llvm_name = "v7",
1191 .description = "Support ARM v7 instructions",
1192 .dependencies = featureSet(&[_]Feature{
1193 .perfmon,
1194 .v6t2,
1195 .v7clrex,
1196 }),
1197 };
1198 result[@enumToInt(Feature.v7clrex)] = .{
1199 .llvm_name = "v7clrex",
1200 .description = "Has v7 clrex instruction",
1201 .dependencies = featureSet(&[_]Feature{}),
1202 };
1203 result[@enumToInt(Feature.v8)] = .{
1204 .llvm_name = "v8",
1205 .description = "Support ARM v8 instructions",
1206 .dependencies = featureSet(&[_]Feature{
1207 .acquire_release,
1208 .v7,
1209 }),
1210 };
1211 result[@enumToInt(Feature.v8_1a)] = .{
1212 .llvm_name = "v8.1a",
1213 .description = "Support ARM v8.1a instructions",
1214 .dependencies = featureSet(&[_]Feature{
1215 .v8,
1216 }),
1217 };
1218 result[@enumToInt(Feature.v8_1m_main)] = .{
1219 .llvm_name = "v8.1m.main",
1220 .description = "Support ARM v8-1M Mainline instructions",
1221 .dependencies = featureSet(&[_]Feature{
1222 .v8m_main,
1223 }),
1224 };
1225 result[@enumToInt(Feature.v8_2a)] = .{
1226 .llvm_name = "v8.2a",
1227 .description = "Support ARM v8.2a instructions",
1228 .dependencies = featureSet(&[_]Feature{
1229 .v8_1a,
1230 }),
1231 };
1232 result[@enumToInt(Feature.v8_3a)] = .{
1233 .llvm_name = "v8.3a",
1234 .description = "Support ARM v8.3a instructions",
1235 .dependencies = featureSet(&[_]Feature{
1236 .v8_2a,
1237 }),
1238 };
1239 result[@enumToInt(Feature.v8_4a)] = .{
1240 .llvm_name = "v8.4a",
1241 .description = "Support ARM v8.4a instructions",
1242 .dependencies = featureSet(&[_]Feature{
1243 .dotprod,
1244 .v8_3a,
1245 }),
1246 };
1247 result[@enumToInt(Feature.v8_5a)] = .{
1248 .llvm_name = "v8.5a",
1249 .description = "Support ARM v8.5a instructions",
1250 .dependencies = featureSet(&[_]Feature{
1251 .sb,
1252 .v8_4a,
1253 }),
1254 };
1255 result[@enumToInt(Feature.v8m)] = .{
1256 .llvm_name = "v8m",
1257 .description = "Support ARM v8M Baseline instructions",
1258 .dependencies = featureSet(&[_]Feature{
1259 .v6m,
1260 }),
1261 };
1262 result[@enumToInt(Feature.v8m_main)] = .{
1263 .llvm_name = "v8m.main",
1264 .description = "Support ARM v8M Mainline instructions",
1265 .dependencies = featureSet(&[_]Feature{
1266 .v7,
1267 }),
1268 };
1269 result[@enumToInt(Feature.vfp2)] = .{
1270 .llvm_name = "vfp2",
1271 .description = "Enable VFP2 instructions",
1272 .dependencies = featureSet(&[_]Feature{
1273 .vfp2d16,
1274 .vfp2sp,
1275 }),
1276 };
1277 result[@enumToInt(Feature.vfp2d16)] = .{
1278 .llvm_name = "vfp2d16",
1279 .description = "Enable VFP2 instructions",
1280 .dependencies = featureSet(&[_]Feature{
1281 .fp64,
1282 .vfp2d16sp,
1283 }),
1284 };
1285 result[@enumToInt(Feature.vfp2d16sp)] = .{
1286 .llvm_name = "vfp2d16sp",
1287 .description = "Enable VFP2 instructions with no double precision",
1288 .dependencies = featureSet(&[_]Feature{
1289 .fpregs,
1290 }),
1291 };
1292 result[@enumToInt(Feature.vfp2sp)] = .{
1293 .llvm_name = "vfp2sp",
1294 .description = "Enable VFP2 instructions with no double precision",
1295 .dependencies = featureSet(&[_]Feature{
1296 .vfp2d16sp,
1297 }),
1298 };
1299 result[@enumToInt(Feature.vfp3)] = .{
1300 .llvm_name = "vfp3",
1301 .description = "Enable VFP3 instructions",
1302 .dependencies = featureSet(&[_]Feature{
1303 .vfp3d16,
1304 .vfp3sp,
1305 }),
1306 };
1307 result[@enumToInt(Feature.vfp3d16)] = .{
1308 .llvm_name = "vfp3d16",
1309 .description = "Enable VFP3 instructions with only 16 d-registers",
1310 .dependencies = featureSet(&[_]Feature{
1311 .fp64,
1312 .vfp2,
1313 .vfp3d16sp,
1314 }),
1315 };
1316 result[@enumToInt(Feature.vfp3d16sp)] = .{
1317 .llvm_name = "vfp3d16sp",
1318 .description = "Enable VFP3 instructions with only 16 d-registers and no double precision",
1319 .dependencies = featureSet(&[_]Feature{
1320 .vfp2sp,
1321 }),
1322 };
1323 result[@enumToInt(Feature.vfp3sp)] = .{
1324 .llvm_name = "vfp3sp",
1325 .description = "Enable VFP3 instructions with no double precision",
1326 .dependencies = featureSet(&[_]Feature{
1327 .d32,
1328 .vfp3d16sp,
1329 }),
1330 };
1331 result[@enumToInt(Feature.vfp4)] = .{
1332 .llvm_name = "vfp4",
1333 .description = "Enable VFP4 instructions",
1334 .dependencies = featureSet(&[_]Feature{
1335 .fp16,
1336 .vfp3,
1337 .vfp4d16,
1338 .vfp4sp,
1339 }),
1340 };
1341 result[@enumToInt(Feature.vfp4d16)] = .{
1342 .llvm_name = "vfp4d16",
1343 .description = "Enable VFP4 instructions with only 16 d-registers",
1344 .dependencies = featureSet(&[_]Feature{
1345 .fp16,
1346 .fp64,
1347 .vfp3d16,
1348 .vfp4d16sp,
1349 }),
1350 };
1351 result[@enumToInt(Feature.vfp4d16sp)] = .{
1352 .llvm_name = "vfp4d16sp",
1353 .description = "Enable VFP4 instructions with only 16 d-registers and no double precision",
1354 .dependencies = featureSet(&[_]Feature{
1355 .fp16,
1356 .vfp3d16sp,
1357 }),
1358 };
1359 result[@enumToInt(Feature.vfp4sp)] = .{
1360 .llvm_name = "vfp4sp",
1361 .description = "Enable VFP4 instructions with no double precision",
1362 .dependencies = featureSet(&[_]Feature{
1363 .d32,
1364 .fp16,
1365 .vfp3sp,
1366 .vfp4d16sp,
1367 }),
1368 };
1369 result[@enumToInt(Feature.virtualization)] = .{
1370 .llvm_name = "virtualization",
1371 .description = "Supports Virtualization extension",
1372 .dependencies = featureSet(&[_]Feature{
1373 .hwdiv,
1374 .hwdiv_arm,
1375 }),
1376 };
1377 result[@enumToInt(Feature.vldn_align)] = .{
1378 .llvm_name = "vldn-align",
1379 .description = "Check for VLDn unaligned access",
1380 .dependencies = featureSet(&[_]Feature{}),
1381 };
1382 result[@enumToInt(Feature.vmlx_forwarding)] = .{
1383 .llvm_name = "vmlx-forwarding",
1384 .description = "Has multiplier accumulator forwarding",
1385 .dependencies = featureSet(&[_]Feature{}),
1386 };
1387 result[@enumToInt(Feature.vmlx_hazards)] = .{
1388 .llvm_name = "vmlx-hazards",
1389 .description = "Has VMLx hazards",
1390 .dependencies = featureSet(&[_]Feature{}),
1391 };
1392 result[@enumToInt(Feature.wide_stride_vfp)] = .{
1393 .llvm_name = "wide-stride-vfp",
1394 .description = "Use a wide stride when allocating VFP registers",
1395 .dependencies = featureSet(&[_]Feature{}),
1396 };
1397 result[@enumToInt(Feature.xscale)] = .{
1398 .llvm_name = "xscale",
1399 .description = "ARMv5te architecture",
1400 .dependencies = featureSet(&[_]Feature{
1401 .armv5te,
1402 }),
1403 };
1404 result[@enumToInt(Feature.zcz)] = .{
1405 .llvm_name = "zcz",
1406 .description = "Has zero-cycle zeroing instructions",
1407 .dependencies = featureSet(&[_]Feature{}),
1408 };
1409 const ti = @typeInfo(Feature);
1410 for (result) |*elem, i| {
1411 elem.index = i;
1412 elem.name = ti.Enum.fields[i].name;
1413 }
1414 break :blk result;
1415};
1416
1417pub const cpu = struct {
1418 pub const arm1020e = Cpu{
1419 .name = "arm1020e",
1420 .llvm_name = "arm1020e",
1421 .features = featureSet(&[_]Feature{
1422 .armv5te,
1423 }),
1424 };
1425 pub const arm1020t = Cpu{
1426 .name = "arm1020t",
1427 .llvm_name = "arm1020t",
1428 .features = featureSet(&[_]Feature{
1429 .armv5t,
1430 }),
1431 };
1432 pub const arm1022e = Cpu{
1433 .name = "arm1022e",
1434 .llvm_name = "arm1022e",
1435 .features = featureSet(&[_]Feature{
1436 .armv5te,
1437 }),
1438 };
1439 pub const arm10e = Cpu{
1440 .name = "arm10e",
1441 .llvm_name = "arm10e",
1442 .features = featureSet(&[_]Feature{
1443 .armv5te,
1444 }),
1445 };
1446 pub const arm10tdmi = Cpu{
1447 .name = "arm10tdmi",
1448 .llvm_name = "arm10tdmi",
1449 .features = featureSet(&[_]Feature{
1450 .armv5t,
1451 }),
1452 };
1453 pub const arm1136j_s = Cpu{
1454 .name = "arm1136j_s",
1455 .llvm_name = "arm1136j-s",
1456 .features = featureSet(&[_]Feature{
1457 .armv6,
1458 }),
1459 };
1460 pub const arm1136jf_s = Cpu{
1461 .name = "arm1136jf_s",
1462 .llvm_name = "arm1136jf-s",
1463 .features = featureSet(&[_]Feature{
1464 .armv6,
1465 .slowfpvmlx,
1466 .vfp2,
1467 }),
1468 };
1469 pub const arm1156t2_s = Cpu{
1470 .name = "arm1156t2_s",
1471 .llvm_name = "arm1156t2-s",
1472 .features = featureSet(&[_]Feature{
1473 .armv6t2,
1474 }),
1475 };
1476 pub const arm1156t2f_s = Cpu{
1477 .name = "arm1156t2f_s",
1478 .llvm_name = "arm1156t2f-s",
1479 .features = featureSet(&[_]Feature{
1480 .armv6t2,
1481 .slowfpvmlx,
1482 .vfp2,
1483 }),
1484 };
1485 pub const arm1176j_s = Cpu{
1486 .name = "arm1176j_s",
1487 .llvm_name = "arm1176j-s",
1488 .features = featureSet(&[_]Feature{
1489 .armv6kz,
1490 }),
1491 };
1492 pub const arm1176jz_s = Cpu{
1493 .name = "arm1176jz_s",
1494 .llvm_name = "arm1176jz-s",
1495 .features = featureSet(&[_]Feature{
1496 .armv6kz,
1497 }),
1498 };
1499 pub const arm1176jzf_s = Cpu{
1500 .name = "arm1176jzf_s",
1501 .llvm_name = "arm1176jzf-s",
1502 .features = featureSet(&[_]Feature{
1503 .armv6kz,
1504 .slowfpvmlx,
1505 .vfp2,
1506 }),
1507 };
1508 pub const arm710t = Cpu{
1509 .name = "arm710t",
1510 .llvm_name = "arm710t",
1511 .features = featureSet(&[_]Feature{
1512 .armv4t,
1513 }),
1514 };
1515 pub const arm720t = Cpu{
1516 .name = "arm720t",
1517 .llvm_name = "arm720t",
1518 .features = featureSet(&[_]Feature{
1519 .armv4t,
1520 }),
1521 };
1522 pub const arm7tdmi = Cpu{
1523 .name = "arm7tdmi",
1524 .llvm_name = "arm7tdmi",
1525 .features = featureSet(&[_]Feature{
1526 .armv4t,
1527 }),
1528 };
1529 pub const arm7tdmi_s = Cpu{
1530 .name = "arm7tdmi_s",
1531 .llvm_name = "arm7tdmi-s",
1532 .features = featureSet(&[_]Feature{
1533 .armv4t,
1534 }),
1535 };
1536 pub const arm8 = Cpu{
1537 .name = "arm8",
1538 .llvm_name = "arm8",
1539 .features = featureSet(&[_]Feature{
1540 .armv4,
1541 }),
1542 };
1543 pub const arm810 = Cpu{
1544 .name = "arm810",
1545 .llvm_name = "arm810",
1546 .features = featureSet(&[_]Feature{
1547 .armv4,
1548 }),
1549 };
1550 pub const arm9 = Cpu{
1551 .name = "arm9",
1552 .llvm_name = "arm9",
1553 .features = featureSet(&[_]Feature{
1554 .armv4t,
1555 }),
1556 };
1557 pub const arm920 = Cpu{
1558 .name = "arm920",
1559 .llvm_name = "arm920",
1560 .features = featureSet(&[_]Feature{
1561 .armv4t,
1562 }),
1563 };
1564 pub const arm920t = Cpu{
1565 .name = "arm920t",
1566 .llvm_name = "arm920t",
1567 .features = featureSet(&[_]Feature{
1568 .armv4t,
1569 }),
1570 };
1571 pub const arm922t = Cpu{
1572 .name = "arm922t",
1573 .llvm_name = "arm922t",
1574 .features = featureSet(&[_]Feature{
1575 .armv4t,
1576 }),
1577 };
1578 pub const arm926ej_s = Cpu{
1579 .name = "arm926ej_s",
1580 .llvm_name = "arm926ej-s",
1581 .features = featureSet(&[_]Feature{
1582 .armv5te,
1583 }),
1584 };
1585 pub const arm940t = Cpu{
1586 .name = "arm940t",
1587 .llvm_name = "arm940t",
1588 .features = featureSet(&[_]Feature{
1589 .armv4t,
1590 }),
1591 };
1592 pub const arm946e_s = Cpu{
1593 .name = "arm946e_s",
1594 .llvm_name = "arm946e-s",
1595 .features = featureSet(&[_]Feature{
1596 .armv5te,
1597 }),
1598 };
1599 pub const arm966e_s = Cpu{
1600 .name = "arm966e_s",
1601 .llvm_name = "arm966e-s",
1602 .features = featureSet(&[_]Feature{
1603 .armv5te,
1604 }),
1605 };
1606 pub const arm968e_s = Cpu{
1607 .name = "arm968e_s",
1608 .llvm_name = "arm968e-s",
1609 .features = featureSet(&[_]Feature{
1610 .armv5te,
1611 }),
1612 };
1613 pub const arm9e = Cpu{
1614 .name = "arm9e",
1615 .llvm_name = "arm9e",
1616 .features = featureSet(&[_]Feature{
1617 .armv5te,
1618 }),
1619 };
1620 pub const arm9tdmi = Cpu{
1621 .name = "arm9tdmi",
1622 .llvm_name = "arm9tdmi",
1623 .features = featureSet(&[_]Feature{
1624 .armv4t,
1625 }),
1626 };
1627 pub const cortex_a12 = Cpu{
1628 .name = "cortex_a12",
1629 .llvm_name = "cortex-a12",
1630 .features = featureSet(&[_]Feature{
1631 .a12,
1632 .armv7_a,
1633 .avoid_partial_cpsr,
1634 .mp,
1635 .ret_addr_stack,
1636 .trustzone,
1637 .vfp4,
1638 .virtualization,
1639 .vmlx_forwarding,
1640 }),
1641 };
1642 pub const cortex_a15 = Cpu{
1643 .name = "cortex_a15",
1644 .llvm_name = "cortex-a15",
1645 .features = featureSet(&[_]Feature{
1646 .a15,
1647 .armv7_a,
1648 .avoid_partial_cpsr,
1649 .dont_widen_vmovs,
1650 .mp,
1651 .muxed_units,
1652 .ret_addr_stack,
1653 .splat_vfp_neon,
1654 .trustzone,
1655 .vfp4,
1656 .virtualization,
1657 .vldn_align,
1658 }),
1659 };
1660 pub const cortex_a17 = Cpu{
1661 .name = "cortex_a17",
1662 .llvm_name = "cortex-a17",
1663 .features = featureSet(&[_]Feature{
1664 .a17,
1665 .armv7_a,
1666 .avoid_partial_cpsr,
1667 .mp,
1668 .ret_addr_stack,
1669 .trustzone,
1670 .vfp4,
1671 .virtualization,
1672 .vmlx_forwarding,
1673 }),
1674 };
1675 pub const cortex_a32 = Cpu{
1676 .name = "cortex_a32",
1677 .llvm_name = "cortex-a32",
1678 .features = featureSet(&[_]Feature{
1679 .armv8_a,
1680 .crc,
1681 .crypto,
1682 .hwdiv,
1683 .hwdiv_arm,
1684 }),
1685 };
1686 pub const cortex_a35 = Cpu{
1687 .name = "cortex_a35",
1688 .llvm_name = "cortex-a35",
1689 .features = featureSet(&[_]Feature{
1690 .a35,
1691 .armv8_a,
1692 .crc,
1693 .crypto,
1694 .hwdiv,
1695 .hwdiv_arm,
1696 }),
1697 };
1698 pub const cortex_a5 = Cpu{
1699 .name = "cortex_a5",
1700 .llvm_name = "cortex-a5",
1701 .features = featureSet(&[_]Feature{
1702 .a5,
1703 .armv7_a,
1704 .mp,
1705 .ret_addr_stack,
1706 .slow_fp_brcc,
1707 .slowfpvmlx,
1708 .trustzone,
1709 .vfp4,
1710 .vmlx_forwarding,
1711 }),
1712 };
1713 pub const cortex_a53 = Cpu{
1714 .name = "cortex_a53",
1715 .llvm_name = "cortex-a53",
1716 .features = featureSet(&[_]Feature{
1717 .a53,
1718 .armv8_a,
1719 .crc,
1720 .crypto,
1721 .fpao,
1722 .hwdiv,
1723 .hwdiv_arm,
1724 }),
1725 };
1726 pub const cortex_a55 = Cpu{
1727 .name = "cortex_a55",
1728 .llvm_name = "cortex-a55",
1729 .features = featureSet(&[_]Feature{
1730 .a55,
1731 .armv8_2_a,
1732 .dotprod,
1733 .hwdiv,
1734 .hwdiv_arm,
1735 }),
1736 };
1737 pub const cortex_a57 = Cpu{
1738 .name = "cortex_a57",
1739 .llvm_name = "cortex-a57",
1740 .features = featureSet(&[_]Feature{
1741 .a57,
1742 .armv8_a,
1743 .avoid_partial_cpsr,
1744 .cheap_predicable_cpsr,
1745 .crc,
1746 .crypto,
1747 .fpao,
1748 .hwdiv,
1749 .hwdiv_arm,
1750 }),
1751 };
1752 pub const cortex_a7 = Cpu{
1753 .name = "cortex_a7",
1754 .llvm_name = "cortex-a7",
1755 .features = featureSet(&[_]Feature{
1756 .a7,
1757 .armv7_a,
1758 .mp,
1759 .ret_addr_stack,
1760 .slow_fp_brcc,
1761 .slowfpvmlx,
1762 .trustzone,
1763 .vfp4,
1764 .virtualization,
1765 .vmlx_forwarding,
1766 .vmlx_hazards,
1767 }),
1768 };
1769 pub const cortex_a72 = Cpu{
1770 .name = "cortex_a72",
1771 .llvm_name = "cortex-a72",
1772 .features = featureSet(&[_]Feature{
1773 .a72,
1774 .armv8_a,
1775 .crc,
1776 .crypto,
1777 .hwdiv,
1778 .hwdiv_arm,
1779 }),
1780 };
1781 pub const cortex_a73 = Cpu{
1782 .name = "cortex_a73",
1783 .llvm_name = "cortex-a73",
1784 .features = featureSet(&[_]Feature{
1785 .a73,
1786 .armv8_a,
1787 .crc,
1788 .crypto,
1789 .hwdiv,
1790 .hwdiv_arm,
1791 }),
1792 };
1793 pub const cortex_a75 = Cpu{
1794 .name = "cortex_a75",
1795 .llvm_name = "cortex-a75",
1796 .features = featureSet(&[_]Feature{
1797 .a75,
1798 .armv8_2_a,
1799 .dotprod,
1800 .hwdiv,
1801 .hwdiv_arm,
1802 }),
1803 };
1804 pub const cortex_a76 = Cpu{
1805 .name = "cortex_a76",
1806 .llvm_name = "cortex-a76",
1807 .features = featureSet(&[_]Feature{
1808 .a76,
1809 .armv8_2_a,
1810 .crc,
1811 .crypto,
1812 .dotprod,
1813 .fullfp16,
1814 .hwdiv,
1815 .hwdiv_arm,
1816 }),
1817 };
1818 pub const cortex_a76ae = Cpu{
1819 .name = "cortex_a76ae",
1820 .llvm_name = "cortex-a76ae",
1821 .features = featureSet(&[_]Feature{
1822 .a76,
1823 .armv8_2_a,
1824 .crc,
1825 .crypto,
1826 .dotprod,
1827 .fullfp16,
1828 .hwdiv,
1829 .hwdiv_arm,
1830 }),
1831 };
1832 pub const cortex_a8 = Cpu{
1833 .name = "cortex_a8",
1834 .llvm_name = "cortex-a8",
1835 .features = featureSet(&[_]Feature{
1836 .a8,
1837 .armv7_a,
1838 .nonpipelined_vfp,
1839 .ret_addr_stack,
1840 .slow_fp_brcc,
1841 .slowfpvmlx,
1842 .trustzone,
1843 .vmlx_forwarding,
1844 .vmlx_hazards,
1845 }),
1846 };
1847 pub const cortex_a9 = Cpu{
1848 .name = "cortex_a9",
1849 .llvm_name = "cortex-a9",
1850 .features = featureSet(&[_]Feature{
1851 .a9,
1852 .armv7_a,
1853 .avoid_partial_cpsr,
1854 .expand_fp_mlx,
1855 .fp16,
1856 .mp,
1857 .muxed_units,
1858 .neon_fpmovs,
1859 .prefer_vmovsr,
1860 .ret_addr_stack,
1861 .trustzone,
1862 .vldn_align,
1863 .vmlx_forwarding,
1864 .vmlx_hazards,
1865 }),
1866 };
1867 pub const cortex_m0 = Cpu{
1868 .name = "cortex_m0",
1869 .llvm_name = "cortex-m0",
1870 .features = featureSet(&[_]Feature{
1871 .armv6_m,
1872 }),
1873 };
1874 pub const cortex_m0plus = Cpu{
1875 .name = "cortex_m0plus",
1876 .llvm_name = "cortex-m0plus",
1877 .features = featureSet(&[_]Feature{
1878 .armv6_m,
1879 }),
1880 };
1881 pub const cortex_m1 = Cpu{
1882 .name = "cortex_m1",
1883 .llvm_name = "cortex-m1",
1884 .features = featureSet(&[_]Feature{
1885 .armv6_m,
1886 }),
1887 };
1888 pub const cortex_m23 = Cpu{
1889 .name = "cortex_m23",
1890 .llvm_name = "cortex-m23",
1891 .features = featureSet(&[_]Feature{
1892 .armv8_m_base,
1893 .no_movt,
1894 }),
1895 };
1896 pub const cortex_m3 = Cpu{
1897 .name = "cortex_m3",
1898 .llvm_name = "cortex-m3",
1899 .features = featureSet(&[_]Feature{
1900 .armv7_m,
1901 .loop_align,
1902 .m3,
1903 .no_branch_predictor,
1904 .use_aa,
1905 .use_misched,
1906 }),
1907 };
1908 pub const cortex_m33 = Cpu{
1909 .name = "cortex_m33",
1910 .llvm_name = "cortex-m33",
1911 .features = featureSet(&[_]Feature{
1912 .armv8_m_main,
1913 .dsp,
1914 .fp_armv8d16sp,
1915 .loop_align,
1916 .no_branch_predictor,
1917 .slowfpvmlx,
1918 .use_aa,
1919 .use_misched,
1920 }),
1921 };
1922 pub const cortex_m35p = Cpu{
1923 .name = "cortex_m35p",
1924 .llvm_name = "cortex-m35p",
1925 .features = featureSet(&[_]Feature{
1926 .armv8_m_main,
1927 .dsp,
1928 .fp_armv8d16sp,
1929 .loop_align,
1930 .no_branch_predictor,
1931 .slowfpvmlx,
1932 .use_aa,
1933 .use_misched,
1934 }),
1935 };
1936 pub const cortex_m4 = Cpu{
1937 .name = "cortex_m4",
1938 .llvm_name = "cortex-m4",
1939 .features = featureSet(&[_]Feature{
1940 .armv7e_m,
1941 .loop_align,
1942 .no_branch_predictor,
1943 .slowfpvmlx,
1944 .use_aa,
1945 .use_misched,
1946 .vfp4d16sp,
1947 }),
1948 };
1949 pub const cortex_m7 = Cpu{
1950 .name = "cortex_m7",
1951 .llvm_name = "cortex-m7",
1952 .features = featureSet(&[_]Feature{
1953 .armv7e_m,
1954 .fp_armv8d16,
1955 }),
1956 };
1957 pub const cortex_r4 = Cpu{
1958 .name = "cortex_r4",
1959 .llvm_name = "cortex-r4",
1960 .features = featureSet(&[_]Feature{
1961 .armv7_r,
1962 .avoid_partial_cpsr,
1963 .r4,
1964 .ret_addr_stack,
1965 }),
1966 };
1967 pub const cortex_r4f = Cpu{
1968 .name = "cortex_r4f",
1969 .llvm_name = "cortex-r4f",
1970 .features = featureSet(&[_]Feature{
1971 .armv7_r,
1972 .avoid_partial_cpsr,
1973 .r4,
1974 .ret_addr_stack,
1975 .slow_fp_brcc,
1976 .slowfpvmlx,
1977 .vfp3d16,
1978 }),
1979 };
1980 pub const cortex_r5 = Cpu{
1981 .name = "cortex_r5",
1982 .llvm_name = "cortex-r5",
1983 .features = featureSet(&[_]Feature{
1984 .armv7_r,
1985 .avoid_partial_cpsr,
1986 .hwdiv_arm,
1987 .r5,
1988 .ret_addr_stack,
1989 .slow_fp_brcc,
1990 .slowfpvmlx,
1991 .vfp3d16,
1992 }),
1993 };
1994 pub const cortex_r52 = Cpu{
1995 .name = "cortex_r52",
1996 .llvm_name = "cortex-r52",
1997 .features = featureSet(&[_]Feature{
1998 .armv8_r,
1999 .fpao,
2000 .r52,
2001 .use_aa,
2002 .use_misched,
2003 }),
2004 };
2005 pub const cortex_r7 = Cpu{
2006 .name = "cortex_r7",
2007 .llvm_name = "cortex-r7",
2008 .features = featureSet(&[_]Feature{
2009 .armv7_r,
2010 .avoid_partial_cpsr,
2011 .fp16,
2012 .hwdiv_arm,
2013 .mp,
2014 .r7,
2015 .ret_addr_stack,
2016 .slow_fp_brcc,
2017 .slowfpvmlx,
2018 .vfp3d16,
2019 }),
2020 };
2021 pub const cortex_r8 = Cpu{
2022 .name = "cortex_r8",
2023 .llvm_name = "cortex-r8",
2024 .features = featureSet(&[_]Feature{
2025 .armv7_r,
2026 .avoid_partial_cpsr,
2027 .fp16,
2028 .hwdiv_arm,
2029 .mp,
2030 .ret_addr_stack,
2031 .slow_fp_brcc,
2032 .slowfpvmlx,
2033 .vfp3d16,
2034 }),
2035 };
2036 pub const cyclone = Cpu{
2037 .name = "cyclone",
2038 .llvm_name = "cyclone",
2039 .features = featureSet(&[_]Feature{
2040 .armv8_a,
2041 .avoid_movs_shop,
2042 .avoid_partial_cpsr,
2043 .crypto,
2044 .disable_postra_scheduler,
2045 .hwdiv,
2046 .hwdiv_arm,
2047 .mp,
2048 .neonfp,
2049 .ret_addr_stack,
2050 .slowfpvmlx,
2051 .swift,
2052 .use_misched,
2053 .vfp4,
2054 .zcz,
2055 }),
2056 };
2057 pub const ep9312 = Cpu{
2058 .name = "ep9312",
2059 .llvm_name = "ep9312",
2060 .features = featureSet(&[_]Feature{
2061 .armv4t,
2062 }),
2063 };
2064 pub const exynos_m1 = Cpu{
2065 .name = "exynos_m1",
2066 .llvm_name = "exynos-m1",
2067 .features = featureSet(&[_]Feature{
2068 .armv8_a,
2069 .exynos,
2070 }),
2071 };
2072 pub const exynos_m2 = Cpu{
2073 .name = "exynos_m2",
2074 .llvm_name = "exynos-m2",
2075 .features = featureSet(&[_]Feature{
2076 .armv8_a,
2077 .exynos,
2078 }),
2079 };
2080 pub const exynos_m3 = Cpu{
2081 .name = "exynos_m3",
2082 .llvm_name = "exynos-m3",
2083 .features = featureSet(&[_]Feature{
2084 .armv8_a,
2085 .exynos,
2086 }),
2087 };
2088 pub const exynos_m4 = Cpu{
2089 .name = "exynos_m4",
2090 .llvm_name = "exynos-m4",
2091 .features = featureSet(&[_]Feature{
2092 .armv8_2_a,
2093 .dotprod,
2094 .exynos,
2095 .fullfp16,
2096 }),
2097 };
2098 pub const exynos_m5 = Cpu{
2099 .name = "exynos_m5",
2100 .llvm_name = "exynos-m5",
2101 .features = featureSet(&[_]Feature{
2102 .armv8_2_a,
2103 .dotprod,
2104 .exynos,
2105 .fullfp16,
2106 }),
2107 };
2108 pub const generic = Cpu{
2109 .name = "generic",
2110 .llvm_name = "generic",
2111 .features = featureSet(&[_]Feature{}),
2112 };
2113 pub const iwmmxt = Cpu{
2114 .name = "iwmmxt",
2115 .llvm_name = "iwmmxt",
2116 .features = featureSet(&[_]Feature{
2117 .armv5te,
2118 }),
2119 };
2120 pub const krait = Cpu{
2121 .name = "krait",
2122 .llvm_name = "krait",
2123 .features = featureSet(&[_]Feature{
2124 .armv7_a,
2125 .avoid_partial_cpsr,
2126 .fp16,
2127 .hwdiv,
2128 .hwdiv_arm,
2129 .krait,
2130 .muxed_units,
2131 .ret_addr_stack,
2132 .vfp4,
2133 .vldn_align,
2134 .vmlx_forwarding,
2135 }),
2136 };
2137 pub const kryo = Cpu{
2138 .name = "kryo",
2139 .llvm_name = "kryo",
2140 .features = featureSet(&[_]Feature{
2141 .armv8_a,
2142 .crc,
2143 .crypto,
2144 .hwdiv,
2145 .hwdiv_arm,
2146 .kryo,
2147 }),
2148 };
2149 pub const mpcore = Cpu{
2150 .name = "mpcore",
2151 .llvm_name = "mpcore",
2152 .features = featureSet(&[_]Feature{
2153 .armv6k,
2154 .slowfpvmlx,
2155 .vfp2,
2156 }),
2157 };
2158 pub const mpcorenovfp = Cpu{
2159 .name = "mpcorenovfp",
2160 .llvm_name = "mpcorenovfp",
2161 .features = featureSet(&[_]Feature{
2162 .armv6k,
2163 }),
2164 };
2165 pub const sc000 = Cpu{
2166 .name = "sc000",
2167 .llvm_name = "sc000",
2168 .features = featureSet(&[_]Feature{
2169 .armv6_m,
2170 }),
2171 };
2172 pub const sc300 = Cpu{
2173 .name = "sc300",
2174 .llvm_name = "sc300",
2175 .features = featureSet(&[_]Feature{
2176 .armv7_m,
2177 .m3,
2178 .no_branch_predictor,
2179 .use_aa,
2180 .use_misched,
2181 }),
2182 };
2183 pub const strongarm = Cpu{
2184 .name = "strongarm",
2185 .llvm_name = "strongarm",
2186 .features = featureSet(&[_]Feature{
2187 .armv4,
2188 }),
2189 };
2190 pub const strongarm110 = Cpu{
2191 .name = "strongarm110",
2192 .llvm_name = "strongarm110",
2193 .features = featureSet(&[_]Feature{
2194 .armv4,
2195 }),
2196 };
2197 pub const strongarm1100 = Cpu{
2198 .name = "strongarm1100",
2199 .llvm_name = "strongarm1100",
2200 .features = featureSet(&[_]Feature{
2201 .armv4,
2202 }),
2203 };
2204 pub const strongarm1110 = Cpu{
2205 .name = "strongarm1110",
2206 .llvm_name = "strongarm1110",
2207 .features = featureSet(&[_]Feature{
2208 .armv4,
2209 }),
2210 };
2211 pub const swift = Cpu{
2212 .name = "swift",
2213 .llvm_name = "swift",
2214 .features = featureSet(&[_]Feature{
2215 .armv7_a,
2216 .avoid_movs_shop,
2217 .avoid_partial_cpsr,
2218 .disable_postra_scheduler,
2219 .hwdiv,
2220 .hwdiv_arm,
2221 .mp,
2222 .neonfp,
2223 .prefer_ishst,
2224 .prof_unpr,
2225 .ret_addr_stack,
2226 .slow_load_D_subreg,
2227 .slow_odd_reg,
2228 .slow_vdup32,
2229 .slow_vgetlni32,
2230 .slowfpvmlx,
2231 .swift,
2232 .use_misched,
2233 .vfp4,
2234 .vmlx_hazards,
2235 .wide_stride_vfp,
2236 }),
2237 };
2238 pub const xscale = Cpu{
2239 .name = "xscale",
2240 .llvm_name = "xscale",
2241 .features = featureSet(&[_]Feature{
2242 .armv5te,
2243 }),
2244 };
2245};
2246
2247/// All arm CPUs, sorted alphabetically by name.
2248/// TODO: Replace this with usage of `std.meta.declList`. It does work, but stage1
2249/// compiler has inefficient memory and CPU usage, affecting build times.
2250pub const all_cpus = &[_]*const Cpu{
2251 &cpu.arm1020e,
2252 &cpu.arm1020t,
2253 &cpu.arm1022e,
2254 &cpu.arm10e,
2255 &cpu.arm10tdmi,
2256 &cpu.arm1136j_s,
2257 &cpu.arm1136jf_s,
2258 &cpu.arm1156t2_s,
2259 &cpu.arm1156t2f_s,
2260 &cpu.arm1176j_s,
2261 &cpu.arm1176jz_s,
2262 &cpu.arm1176jzf_s,
2263 &cpu.arm710t,
2264 &cpu.arm720t,
2265 &cpu.arm7tdmi,
2266 &cpu.arm7tdmi_s,
2267 &cpu.arm8,
2268 &cpu.arm810,
2269 &cpu.arm9,
2270 &cpu.arm920,
2271 &cpu.arm920t,
2272 &cpu.arm922t,
2273 &cpu.arm926ej_s,
2274 &cpu.arm940t,
2275 &cpu.arm946e_s,
2276 &cpu.arm966e_s,
2277 &cpu.arm968e_s,
2278 &cpu.arm9e,
2279 &cpu.arm9tdmi,
2280 &cpu.cortex_a12,
2281 &cpu.cortex_a15,
2282 &cpu.cortex_a17,
2283 &cpu.cortex_a32,
2284 &cpu.cortex_a35,
2285 &cpu.cortex_a5,
2286 &cpu.cortex_a53,
2287 &cpu.cortex_a55,
2288 &cpu.cortex_a57,
2289 &cpu.cortex_a7,
2290 &cpu.cortex_a72,
2291 &cpu.cortex_a73,
2292 &cpu.cortex_a75,
2293 &cpu.cortex_a76,
2294 &cpu.cortex_a76ae,
2295 &cpu.cortex_a8,
2296 &cpu.cortex_a9,
2297 &cpu.cortex_m0,
2298 &cpu.cortex_m0plus,
2299 &cpu.cortex_m1,
2300 &cpu.cortex_m23,
2301 &cpu.cortex_m3,
2302 &cpu.cortex_m33,
2303 &cpu.cortex_m35p,
2304 &cpu.cortex_m4,
2305 &cpu.cortex_m7,
2306 &cpu.cortex_r4,
2307 &cpu.cortex_r4f,
2308 &cpu.cortex_r5,
2309 &cpu.cortex_r52,
2310 &cpu.cortex_r7,
2311 &cpu.cortex_r8,
2312 &cpu.cyclone,
2313 &cpu.ep9312,
2314 &cpu.exynos_m1,
2315 &cpu.exynos_m2,
2316 &cpu.exynos_m3,
2317 &cpu.exynos_m4,
2318 &cpu.exynos_m5,
2319 &cpu.generic,
2320 &cpu.iwmmxt,
2321 &cpu.krait,
2322 &cpu.kryo,
2323 &cpu.mpcore,
2324 &cpu.mpcorenovfp,
2325 &cpu.sc000,
2326 &cpu.sc300,
2327 &cpu.strongarm,
2328 &cpu.strongarm110,
2329 &cpu.strongarm1100,
2330 &cpu.strongarm1110,
2331 &cpu.swift,
2332 &cpu.xscale,
2333};
lib/std/target/avr.zig created+2380
...@@ -0,0 +1,2380 @@
1const std = @import("../std.zig");
2const Cpu = std.Target.Cpu;
3
4pub const Feature = enum {
5 addsubiw,
6 avr0,
7 avr1,
8 avr2,
9 avr25,
10 avr3,
11 avr31,
12 avr35,
13 avr4,
14 avr5,
15 avr51,
16 avr6,
17 avrtiny,
18 @"break",
19 des,
20 eijmpcall,
21 elpm,
22 elpmx,
23 ijmpcall,
24 jmpcall,
25 lpm,
26 lpmx,
27 movw,
28 mul,
29 rmw,
30 smallstack,
31 special,
32 spm,
33 spmx,
34 sram,
35 tinyencoding,
36 xmega,
37 xmegau,
38};
39
40pub usingnamespace Cpu.Feature.feature_set_fns(Feature);
41
42pub const all_features = blk: {
43 const len = @typeInfo(Feature).Enum.fields.len;
44 std.debug.assert(len <= Cpu.Feature.Set.needed_bit_count);
45 var result: [len]Cpu.Feature = undefined;
46 result[@enumToInt(Feature.addsubiw)] = .{
47 .llvm_name = "addsubiw",
48 .description = "Enable 16-bit register-immediate addition and subtraction instructions",
49 .dependencies = featureSet(&[_]Feature{}),
50 };
51 result[@enumToInt(Feature.avr0)] = .{
52 .llvm_name = "avr0",
53 .description = "The device is a part of the avr0 family",
54 .dependencies = featureSet(&[_]Feature{}),
55 };
56 result[@enumToInt(Feature.avr1)] = .{
57 .llvm_name = "avr1",
58 .description = "The device is a part of the avr1 family",
59 .dependencies = featureSet(&[_]Feature{
60 .avr0,
61 .lpm,
62 }),
63 };
64 result[@enumToInt(Feature.avr2)] = .{
65 .llvm_name = "avr2",
66 .description = "The device is a part of the avr2 family",
67 .dependencies = featureSet(&[_]Feature{
68 .addsubiw,
69 .avr1,
70 .ijmpcall,
71 .sram,
72 }),
73 };
74 result[@enumToInt(Feature.avr25)] = .{
75 .llvm_name = "avr25",
76 .description = "The device is a part of the avr25 family",
77 .dependencies = featureSet(&[_]Feature{
78 .avr2,
79 .@"break",
80 .lpmx,
81 .movw,
82 .spm,
83 }),
84 };
85 result[@enumToInt(Feature.avr3)] = .{
86 .llvm_name = "avr3",
87 .description = "The device is a part of the avr3 family",
88 .dependencies = featureSet(&[_]Feature{
89 .avr2,
90 .jmpcall,
91 }),
92 };
93 result[@enumToInt(Feature.avr31)] = .{
94 .llvm_name = "avr31",
95 .description = "The device is a part of the avr31 family",
96 .dependencies = featureSet(&[_]Feature{
97 .avr3,
98 .elpm,
99 }),
100 };
101 result[@enumToInt(Feature.avr35)] = .{
102 .llvm_name = "avr35",
103 .description = "The device is a part of the avr35 family",
104 .dependencies = featureSet(&[_]Feature{
105 .avr3,
106 .@"break",
107 .lpmx,
108 .movw,
109 .spm,
110 }),
111 };
112 result[@enumToInt(Feature.avr4)] = .{
113 .llvm_name = "avr4",
114 .description = "The device is a part of the avr4 family",
115 .dependencies = featureSet(&[_]Feature{
116 .avr2,
117 .@"break",
118 .lpmx,
119 .movw,
120 .mul,
121 .spm,
122 }),
123 };
124 result[@enumToInt(Feature.avr5)] = .{
125 .llvm_name = "avr5",
126 .description = "The device is a part of the avr5 family",
127 .dependencies = featureSet(&[_]Feature{
128 .avr3,
129 .@"break",
130 .lpmx,
131 .movw,
132 .mul,
133 .spm,
134 }),
135 };
136 result[@enumToInt(Feature.avr51)] = .{
137 .llvm_name = "avr51",
138 .description = "The device is a part of the avr51 family",
139 .dependencies = featureSet(&[_]Feature{
140 .avr5,
141 .elpm,
142 .elpmx,
143 }),
144 };
145 result[@enumToInt(Feature.avr6)] = .{
146 .llvm_name = "avr6",
147 .description = "The device is a part of the avr6 family",
148 .dependencies = featureSet(&[_]Feature{
149 .avr51,
150 }),
151 };
152 result[@enumToInt(Feature.avrtiny)] = .{
153 .llvm_name = "avrtiny",
154 .description = "The device is a part of the avrtiny family",
155 .dependencies = featureSet(&[_]Feature{
156 .avr0,
157 .@"break",
158 .sram,
159 .tinyencoding,
160 }),
161 };
162 result[@enumToInt(Feature.@"break")] = .{
163 .llvm_name = "break",
164 .description = "The device supports the `BREAK` debugging instruction",
165 .dependencies = featureSet(&[_]Feature{}),
166 };
167 result[@enumToInt(Feature.des)] = .{
168 .llvm_name = "des",
169 .description = "The device supports the `DES k` encryption instruction",
170 .dependencies = featureSet(&[_]Feature{}),
171 };
172 result[@enumToInt(Feature.eijmpcall)] = .{
173 .llvm_name = "eijmpcall",
174 .description = "The device supports the `EIJMP`/`EICALL` instructions",
175 .dependencies = featureSet(&[_]Feature{}),
176 };
177 result[@enumToInt(Feature.elpm)] = .{
178 .llvm_name = "elpm",
179 .description = "The device supports the ELPM instruction",
180 .dependencies = featureSet(&[_]Feature{}),
181 };
182 result[@enumToInt(Feature.elpmx)] = .{
183 .llvm_name = "elpmx",
184 .description = "The device supports the `ELPM Rd, Z[+]` instructions",
185 .dependencies = featureSet(&[_]Feature{}),
186 };
187 result[@enumToInt(Feature.ijmpcall)] = .{
188 .llvm_name = "ijmpcall",
189 .description = "The device supports `IJMP`/`ICALL`instructions",
190 .dependencies = featureSet(&[_]Feature{}),
191 };
192 result[@enumToInt(Feature.jmpcall)] = .{
193 .llvm_name = "jmpcall",
194 .description = "The device supports the `JMP` and `CALL` instructions",
195 .dependencies = featureSet(&[_]Feature{}),
196 };
197 result[@enumToInt(Feature.lpm)] = .{
198 .llvm_name = "lpm",
199 .description = "The device supports the `LPM` instruction",
200 .dependencies = featureSet(&[_]Feature{}),
201 };
202 result[@enumToInt(Feature.lpmx)] = .{
203 .llvm_name = "lpmx",
204 .description = "The device supports the `LPM Rd, Z[+]` instruction",
205 .dependencies = featureSet(&[_]Feature{}),
206 };
207 result[@enumToInt(Feature.movw)] = .{
208 .llvm_name = "movw",
209 .description = "The device supports the 16-bit MOVW instruction",
210 .dependencies = featureSet(&[_]Feature{}),
211 };
212 result[@enumToInt(Feature.mul)] = .{
213 .llvm_name = "mul",
214 .description = "The device supports the multiplication instructions",
215 .dependencies = featureSet(&[_]Feature{}),
216 };
217 result[@enumToInt(Feature.rmw)] = .{
218 .llvm_name = "rmw",
219 .description = "The device supports the read-write-modify instructions: XCH, LAS, LAC, LAT",
220 .dependencies = featureSet(&[_]Feature{}),
221 };
222 result[@enumToInt(Feature.smallstack)] = .{
223 .llvm_name = "smallstack",
224 .description = "The device has an 8-bit stack pointer",
225 .dependencies = featureSet(&[_]Feature{}),
226 };
227 result[@enumToInt(Feature.special)] = .{
228 .llvm_name = "special",
229 .description = "Enable use of the entire instruction set - used for debugging",
230 .dependencies = featureSet(&[_]Feature{
231 .addsubiw,
232 .@"break",
233 .des,
234 .eijmpcall,
235 .elpm,
236 .elpmx,
237 .ijmpcall,
238 .jmpcall,
239 .lpm,
240 .lpmx,
241 .movw,
242 .mul,
243 .rmw,
244 .spm,
245 .spmx,
246 .sram,
247 }),
248 };
249 result[@enumToInt(Feature.spm)] = .{
250 .llvm_name = "spm",
251 .description = "The device supports the `SPM` instruction",
252 .dependencies = featureSet(&[_]Feature{}),
253 };
254 result[@enumToInt(Feature.spmx)] = .{
255 .llvm_name = "spmx",
256 .description = "The device supports the `SPM Z+` instruction",
257 .dependencies = featureSet(&[_]Feature{}),
258 };
259 result[@enumToInt(Feature.sram)] = .{
260 .llvm_name = "sram",
261 .description = "The device has random access memory",
262 .dependencies = featureSet(&[_]Feature{}),
263 };
264 result[@enumToInt(Feature.tinyencoding)] = .{
265 .llvm_name = "tinyencoding",
266 .description = "The device has Tiny core specific instruction encodings",
267 .dependencies = featureSet(&[_]Feature{}),
268 };
269 result[@enumToInt(Feature.xmega)] = .{
270 .llvm_name = "xmega",
271 .description = "The device is a part of the xmega family",
272 .dependencies = featureSet(&[_]Feature{
273 .avr51,
274 .des,
275 .eijmpcall,
276 .spmx,
277 }),
278 };
279 result[@enumToInt(Feature.xmegau)] = .{
280 .llvm_name = "xmegau",
281 .description = "The device is a part of the xmegau family",
282 .dependencies = featureSet(&[_]Feature{
283 .rmw,
284 .xmega,
285 }),
286 };
287 const ti = @typeInfo(Feature);
288 for (result) |*elem, i| {
289 elem.index = i;
290 elem.name = ti.Enum.fields[i].name;
291 }
292 break :blk result;
293};
294
295pub const cpu = struct {
296 pub const at43usb320 = Cpu{
297 .name = "at43usb320",
298 .llvm_name = "at43usb320",
299 .features = featureSet(&[_]Feature{
300 .avr31,
301 }),
302 };
303 pub const at43usb355 = Cpu{
304 .name = "at43usb355",
305 .llvm_name = "at43usb355",
306 .features = featureSet(&[_]Feature{
307 .avr3,
308 }),
309 };
310 pub const at76c711 = Cpu{
311 .name = "at76c711",
312 .llvm_name = "at76c711",
313 .features = featureSet(&[_]Feature{
314 .avr3,
315 }),
316 };
317 pub const at86rf401 = Cpu{
318 .name = "at86rf401",
319 .llvm_name = "at86rf401",
320 .features = featureSet(&[_]Feature{
321 .avr2,
322 .lpmx,
323 .movw,
324 }),
325 };
326 pub const at90c8534 = Cpu{
327 .name = "at90c8534",
328 .llvm_name = "at90c8534",
329 .features = featureSet(&[_]Feature{
330 .avr2,
331 }),
332 };
333 pub const at90can128 = Cpu{
334 .name = "at90can128",
335 .llvm_name = "at90can128",
336 .features = featureSet(&[_]Feature{
337 .avr51,
338 }),
339 };
340 pub const at90can32 = Cpu{
341 .name = "at90can32",
342 .llvm_name = "at90can32",
343 .features = featureSet(&[_]Feature{
344 .avr5,
345 }),
346 };
347 pub const at90can64 = Cpu{
348 .name = "at90can64",
349 .llvm_name = "at90can64",
350 .features = featureSet(&[_]Feature{
351 .avr5,
352 }),
353 };
354 pub const at90pwm1 = Cpu{
355 .name = "at90pwm1",
356 .llvm_name = "at90pwm1",
357 .features = featureSet(&[_]Feature{
358 .avr4,
359 }),
360 };
361 pub const at90pwm161 = Cpu{
362 .name = "at90pwm161",
363 .llvm_name = "at90pwm161",
364 .features = featureSet(&[_]Feature{
365 .avr5,
366 }),
367 };
368 pub const at90pwm2 = Cpu{
369 .name = "at90pwm2",
370 .llvm_name = "at90pwm2",
371 .features = featureSet(&[_]Feature{
372 .avr4,
373 }),
374 };
375 pub const at90pwm216 = Cpu{
376 .name = "at90pwm216",
377 .llvm_name = "at90pwm216",
378 .features = featureSet(&[_]Feature{
379 .avr5,
380 }),
381 };
382 pub const at90pwm2b = Cpu{
383 .name = "at90pwm2b",
384 .llvm_name = "at90pwm2b",
385 .features = featureSet(&[_]Feature{
386 .avr4,
387 }),
388 };
389 pub const at90pwm3 = Cpu{
390 .name = "at90pwm3",
391 .llvm_name = "at90pwm3",
392 .features = featureSet(&[_]Feature{
393 .avr4,
394 }),
395 };
396 pub const at90pwm316 = Cpu{
397 .name = "at90pwm316",
398 .llvm_name = "at90pwm316",
399 .features = featureSet(&[_]Feature{
400 .avr5,
401 }),
402 };
403 pub const at90pwm3b = Cpu{
404 .name = "at90pwm3b",
405 .llvm_name = "at90pwm3b",
406 .features = featureSet(&[_]Feature{
407 .avr4,
408 }),
409 };
410 pub const at90pwm81 = Cpu{
411 .name = "at90pwm81",
412 .llvm_name = "at90pwm81",
413 .features = featureSet(&[_]Feature{
414 .avr4,
415 }),
416 };
417 pub const at90s1200 = Cpu{
418 .name = "at90s1200",
419 .llvm_name = "at90s1200",
420 .features = featureSet(&[_]Feature{
421 .avr0,
422 }),
423 };
424 pub const at90s2313 = Cpu{
425 .name = "at90s2313",
426 .llvm_name = "at90s2313",
427 .features = featureSet(&[_]Feature{
428 .avr2,
429 }),
430 };
431 pub const at90s2323 = Cpu{
432 .name = "at90s2323",
433 .llvm_name = "at90s2323",
434 .features = featureSet(&[_]Feature{
435 .avr2,
436 }),
437 };
438 pub const at90s2333 = Cpu{
439 .name = "at90s2333",
440 .llvm_name = "at90s2333",
441 .features = featureSet(&[_]Feature{
442 .avr2,
443 }),
444 };
445 pub const at90s2343 = Cpu{
446 .name = "at90s2343",
447 .llvm_name = "at90s2343",
448 .features = featureSet(&[_]Feature{
449 .avr2,
450 }),
451 };
452 pub const at90s4414 = Cpu{
453 .name = "at90s4414",
454 .llvm_name = "at90s4414",
455 .features = featureSet(&[_]Feature{
456 .avr2,
457 }),
458 };
459 pub const at90s4433 = Cpu{
460 .name = "at90s4433",
461 .llvm_name = "at90s4433",
462 .features = featureSet(&[_]Feature{
463 .avr2,
464 }),
465 };
466 pub const at90s4434 = Cpu{
467 .name = "at90s4434",
468 .llvm_name = "at90s4434",
469 .features = featureSet(&[_]Feature{
470 .avr2,
471 }),
472 };
473 pub const at90s8515 = Cpu{
474 .name = "at90s8515",
475 .llvm_name = "at90s8515",
476 .features = featureSet(&[_]Feature{
477 .avr2,
478 }),
479 };
480 pub const at90s8535 = Cpu{
481 .name = "at90s8535",
482 .llvm_name = "at90s8535",
483 .features = featureSet(&[_]Feature{
484 .avr2,
485 }),
486 };
487 pub const at90scr100 = Cpu{
488 .name = "at90scr100",
489 .llvm_name = "at90scr100",
490 .features = featureSet(&[_]Feature{
491 .avr5,
492 }),
493 };
494 pub const at90usb1286 = Cpu{
495 .name = "at90usb1286",
496 .llvm_name = "at90usb1286",
497 .features = featureSet(&[_]Feature{
498 .avr51,
499 }),
500 };
501 pub const at90usb1287 = Cpu{
502 .name = "at90usb1287",
503 .llvm_name = "at90usb1287",
504 .features = featureSet(&[_]Feature{
505 .avr51,
506 }),
507 };
508 pub const at90usb162 = Cpu{
509 .name = "at90usb162",
510 .llvm_name = "at90usb162",
511 .features = featureSet(&[_]Feature{
512 .avr35,
513 }),
514 };
515 pub const at90usb646 = Cpu{
516 .name = "at90usb646",
517 .llvm_name = "at90usb646",
518 .features = featureSet(&[_]Feature{
519 .avr5,
520 }),
521 };
522 pub const at90usb647 = Cpu{
523 .name = "at90usb647",
524 .llvm_name = "at90usb647",
525 .features = featureSet(&[_]Feature{
526 .avr5,
527 }),
528 };
529 pub const at90usb82 = Cpu{
530 .name = "at90usb82",
531 .llvm_name = "at90usb82",
532 .features = featureSet(&[_]Feature{
533 .avr35,
534 }),
535 };
536 pub const at94k = Cpu{
537 .name = "at94k",
538 .llvm_name = "at94k",
539 .features = featureSet(&[_]Feature{
540 .avr3,
541 .lpmx,
542 .movw,
543 .mul,
544 }),
545 };
546 pub const ata5272 = Cpu{
547 .name = "ata5272",
548 .llvm_name = "ata5272",
549 .features = featureSet(&[_]Feature{
550 .avr25,
551 }),
552 };
553 pub const ata5505 = Cpu{
554 .name = "ata5505",
555 .llvm_name = "ata5505",
556 .features = featureSet(&[_]Feature{
557 .avr35,
558 }),
559 };
560 pub const ata5790 = Cpu{
561 .name = "ata5790",
562 .llvm_name = "ata5790",
563 .features = featureSet(&[_]Feature{
564 .avr5,
565 }),
566 };
567 pub const ata5795 = Cpu{
568 .name = "ata5795",
569 .llvm_name = "ata5795",
570 .features = featureSet(&[_]Feature{
571 .avr5,
572 }),
573 };
574 pub const ata6285 = Cpu{
575 .name = "ata6285",
576 .llvm_name = "ata6285",
577 .features = featureSet(&[_]Feature{
578 .avr4,
579 }),
580 };
581 pub const ata6286 = Cpu{
582 .name = "ata6286",
583 .llvm_name = "ata6286",
584 .features = featureSet(&[_]Feature{
585 .avr4,
586 }),
587 };
588 pub const ata6289 = Cpu{
589 .name = "ata6289",
590 .llvm_name = "ata6289",
591 .features = featureSet(&[_]Feature{
592 .avr4,
593 }),
594 };
595 pub const atmega103 = Cpu{
596 .name = "atmega103",
597 .llvm_name = "atmega103",
598 .features = featureSet(&[_]Feature{
599 .avr31,
600 }),
601 };
602 pub const atmega128 = Cpu{
603 .name = "atmega128",
604 .llvm_name = "atmega128",
605 .features = featureSet(&[_]Feature{
606 .avr51,
607 }),
608 };
609 pub const atmega1280 = Cpu{
610 .name = "atmega1280",
611 .llvm_name = "atmega1280",
612 .features = featureSet(&[_]Feature{
613 .avr51,
614 }),
615 };
616 pub const atmega1281 = Cpu{
617 .name = "atmega1281",
618 .llvm_name = "atmega1281",
619 .features = featureSet(&[_]Feature{
620 .avr51,
621 }),
622 };
623 pub const atmega1284 = Cpu{
624 .name = "atmega1284",
625 .llvm_name = "atmega1284",
626 .features = featureSet(&[_]Feature{
627 .avr51,
628 }),
629 };
630 pub const atmega1284p = Cpu{
631 .name = "atmega1284p",
632 .llvm_name = "atmega1284p",
633 .features = featureSet(&[_]Feature{
634 .avr51,
635 }),
636 };
637 pub const atmega1284rfr2 = Cpu{
638 .name = "atmega1284rfr2",
639 .llvm_name = "atmega1284rfr2",
640 .features = featureSet(&[_]Feature{
641 .avr51,
642 }),
643 };
644 pub const atmega128a = Cpu{
645 .name = "atmega128a",
646 .llvm_name = "atmega128a",
647 .features = featureSet(&[_]Feature{
648 .avr51,
649 }),
650 };
651 pub const atmega128rfa1 = Cpu{
652 .name = "atmega128rfa1",
653 .llvm_name = "atmega128rfa1",
654 .features = featureSet(&[_]Feature{
655 .avr51,
656 }),
657 };
658 pub const atmega128rfr2 = Cpu{
659 .name = "atmega128rfr2",
660 .llvm_name = "atmega128rfr2",
661 .features = featureSet(&[_]Feature{
662 .avr51,
663 }),
664 };
665 pub const atmega16 = Cpu{
666 .name = "atmega16",
667 .llvm_name = "atmega16",
668 .features = featureSet(&[_]Feature{
669 .avr5,
670 }),
671 };
672 pub const atmega161 = Cpu{
673 .name = "atmega161",
674 .llvm_name = "atmega161",
675 .features = featureSet(&[_]Feature{
676 .avr3,
677 .lpmx,
678 .movw,
679 .mul,
680 .spm,
681 }),
682 };
683 pub const atmega162 = Cpu{
684 .name = "atmega162",
685 .llvm_name = "atmega162",
686 .features = featureSet(&[_]Feature{
687 .avr5,
688 }),
689 };
690 pub const atmega163 = Cpu{
691 .name = "atmega163",
692 .llvm_name = "atmega163",
693 .features = featureSet(&[_]Feature{
694 .avr3,
695 .lpmx,
696 .movw,
697 .mul,
698 .spm,
699 }),
700 };
701 pub const atmega164a = Cpu{
702 .name = "atmega164a",
703 .llvm_name = "atmega164a",
704 .features = featureSet(&[_]Feature{
705 .avr5,
706 }),
707 };
708 pub const atmega164p = Cpu{
709 .name = "atmega164p",
710 .llvm_name = "atmega164p",
711 .features = featureSet(&[_]Feature{
712 .avr5,
713 }),
714 };
715 pub const atmega164pa = Cpu{
716 .name = "atmega164pa",
717 .llvm_name = "atmega164pa",
718 .features = featureSet(&[_]Feature{
719 .avr5,
720 }),
721 };
722 pub const atmega165 = Cpu{
723 .name = "atmega165",
724 .llvm_name = "atmega165",
725 .features = featureSet(&[_]Feature{
726 .avr5,
727 }),
728 };
729 pub const atmega165a = Cpu{
730 .name = "atmega165a",
731 .llvm_name = "atmega165a",
732 .features = featureSet(&[_]Feature{
733 .avr5,
734 }),
735 };
736 pub const atmega165p = Cpu{
737 .name = "atmega165p",
738 .llvm_name = "atmega165p",
739 .features = featureSet(&[_]Feature{
740 .avr5,
741 }),
742 };
743 pub const atmega165pa = Cpu{
744 .name = "atmega165pa",
745 .llvm_name = "atmega165pa",
746 .features = featureSet(&[_]Feature{
747 .avr5,
748 }),
749 };
750 pub const atmega168 = Cpu{
751 .name = "atmega168",
752 .llvm_name = "atmega168",
753 .features = featureSet(&[_]Feature{
754 .avr5,
755 }),
756 };
757 pub const atmega168a = Cpu{
758 .name = "atmega168a",
759 .llvm_name = "atmega168a",
760 .features = featureSet(&[_]Feature{
761 .avr5,
762 }),
763 };
764 pub const atmega168p = Cpu{
765 .name = "atmega168p",
766 .llvm_name = "atmega168p",
767 .features = featureSet(&[_]Feature{
768 .avr5,
769 }),
770 };
771 pub const atmega168pa = Cpu{
772 .name = "atmega168pa",
773 .llvm_name = "atmega168pa",
774 .features = featureSet(&[_]Feature{
775 .avr5,
776 }),
777 };
778 pub const atmega169 = Cpu{
779 .name = "atmega169",
780 .llvm_name = "atmega169",
781 .features = featureSet(&[_]Feature{
782 .avr5,
783 }),
784 };
785 pub const atmega169a = Cpu{
786 .name = "atmega169a",
787 .llvm_name = "atmega169a",
788 .features = featureSet(&[_]Feature{
789 .avr5,
790 }),
791 };
792 pub const atmega169p = Cpu{
793 .name = "atmega169p",
794 .llvm_name = "atmega169p",
795 .features = featureSet(&[_]Feature{
796 .avr5,
797 }),
798 };
799 pub const atmega169pa = Cpu{
800 .name = "atmega169pa",
801 .llvm_name = "atmega169pa",
802 .features = featureSet(&[_]Feature{
803 .avr5,
804 }),
805 };
806 pub const atmega16a = Cpu{
807 .name = "atmega16a",
808 .llvm_name = "atmega16a",
809 .features = featureSet(&[_]Feature{
810 .avr5,
811 }),
812 };
813 pub const atmega16hva = Cpu{
814 .name = "atmega16hva",
815 .llvm_name = "atmega16hva",
816 .features = featureSet(&[_]Feature{
817 .avr5,
818 }),
819 };
820 pub const atmega16hva2 = Cpu{
821 .name = "atmega16hva2",
822 .llvm_name = "atmega16hva2",
823 .features = featureSet(&[_]Feature{
824 .avr5,
825 }),
826 };
827 pub const atmega16hvb = Cpu{
828 .name = "atmega16hvb",
829 .llvm_name = "atmega16hvb",
830 .features = featureSet(&[_]Feature{
831 .avr5,
832 }),
833 };
834 pub const atmega16hvbrevb = Cpu{
835 .name = "atmega16hvbrevb",
836 .llvm_name = "atmega16hvbrevb",
837 .features = featureSet(&[_]Feature{
838 .avr5,
839 }),
840 };
841 pub const atmega16m1 = Cpu{
842 .name = "atmega16m1",
843 .llvm_name = "atmega16m1",
844 .features = featureSet(&[_]Feature{
845 .avr5,
846 }),
847 };
848 pub const atmega16u2 = Cpu{
849 .name = "atmega16u2",
850 .llvm_name = "atmega16u2",
851 .features = featureSet(&[_]Feature{
852 .avr35,
853 }),
854 };
855 pub const atmega16u4 = Cpu{
856 .name = "atmega16u4",
857 .llvm_name = "atmega16u4",
858 .features = featureSet(&[_]Feature{
859 .avr5,
860 }),
861 };
862 pub const atmega2560 = Cpu{
863 .name = "atmega2560",
864 .llvm_name = "atmega2560",
865 .features = featureSet(&[_]Feature{
866 .avr6,
867 }),
868 };
869 pub const atmega2561 = Cpu{
870 .name = "atmega2561",
871 .llvm_name = "atmega2561",
872 .features = featureSet(&[_]Feature{
873 .avr6,
874 }),
875 };
876 pub const atmega2564rfr2 = Cpu{
877 .name = "atmega2564rfr2",
878 .llvm_name = "atmega2564rfr2",
879 .features = featureSet(&[_]Feature{
880 .avr6,
881 }),
882 };
883 pub const atmega256rfr2 = Cpu{
884 .name = "atmega256rfr2",
885 .llvm_name = "atmega256rfr2",
886 .features = featureSet(&[_]Feature{
887 .avr6,
888 }),
889 };
890 pub const atmega32 = Cpu{
891 .name = "atmega32",
892 .llvm_name = "atmega32",
893 .features = featureSet(&[_]Feature{
894 .avr5,
895 }),
896 };
897 pub const atmega323 = Cpu{
898 .name = "atmega323",
899 .llvm_name = "atmega323",
900 .features = featureSet(&[_]Feature{
901 .avr5,
902 }),
903 };
904 pub const atmega324a = Cpu{
905 .name = "atmega324a",
906 .llvm_name = "atmega324a",
907 .features = featureSet(&[_]Feature{
908 .avr5,
909 }),
910 };
911 pub const atmega324p = Cpu{
912 .name = "atmega324p",
913 .llvm_name = "atmega324p",
914 .features = featureSet(&[_]Feature{
915 .avr5,
916 }),
917 };
918 pub const atmega324pa = Cpu{
919 .name = "atmega324pa",
920 .llvm_name = "atmega324pa",
921 .features = featureSet(&[_]Feature{
922 .avr5,
923 }),
924 };
925 pub const atmega325 = Cpu{
926 .name = "atmega325",
927 .llvm_name = "atmega325",
928 .features = featureSet(&[_]Feature{
929 .avr5,
930 }),
931 };
932 pub const atmega3250 = Cpu{
933 .name = "atmega3250",
934 .llvm_name = "atmega3250",
935 .features = featureSet(&[_]Feature{
936 .avr5,
937 }),
938 };
939 pub const atmega3250a = Cpu{
940 .name = "atmega3250a",
941 .llvm_name = "atmega3250a",
942 .features = featureSet(&[_]Feature{
943 .avr5,
944 }),
945 };
946 pub const atmega3250p = Cpu{
947 .name = "atmega3250p",
948 .llvm_name = "atmega3250p",
949 .features = featureSet(&[_]Feature{
950 .avr5,
951 }),
952 };
953 pub const atmega3250pa = Cpu{
954 .name = "atmega3250pa",
955 .llvm_name = "atmega3250pa",
956 .features = featureSet(&[_]Feature{
957 .avr5,
958 }),
959 };
960 pub const atmega325a = Cpu{
961 .name = "atmega325a",
962 .llvm_name = "atmega325a",
963 .features = featureSet(&[_]Feature{
964 .avr5,
965 }),
966 };
967 pub const atmega325p = Cpu{
968 .name = "atmega325p",
969 .llvm_name = "atmega325p",
970 .features = featureSet(&[_]Feature{
971 .avr5,
972 }),
973 };
974 pub const atmega325pa = Cpu{
975 .name = "atmega325pa",
976 .llvm_name = "atmega325pa",
977 .features = featureSet(&[_]Feature{
978 .avr5,
979 }),
980 };
981 pub const atmega328 = Cpu{
982 .name = "atmega328",
983 .llvm_name = "atmega328",
984 .features = featureSet(&[_]Feature{
985 .avr5,
986 }),
987 };
988 pub const atmega328p = Cpu{
989 .name = "atmega328p",
990 .llvm_name = "atmega328p",
991 .features = featureSet(&[_]Feature{
992 .avr5,
993 }),
994 };
995 pub const atmega329 = Cpu{
996 .name = "atmega329",
997 .llvm_name = "atmega329",
998 .features = featureSet(&[_]Feature{
999 .avr5,
1000 }),
1001 };
1002 pub const atmega3290 = Cpu{
1003 .name = "atmega3290",
1004 .llvm_name = "atmega3290",
1005 .features = featureSet(&[_]Feature{
1006 .avr5,
1007 }),
1008 };
1009 pub const atmega3290a = Cpu{
1010 .name = "atmega3290a",
1011 .llvm_name = "atmega3290a",
1012 .features = featureSet(&[_]Feature{
1013 .avr5,
1014 }),
1015 };
1016 pub const atmega3290p = Cpu{
1017 .name = "atmega3290p",
1018 .llvm_name = "atmega3290p",
1019 .features = featureSet(&[_]Feature{
1020 .avr5,
1021 }),
1022 };
1023 pub const atmega3290pa = Cpu{
1024 .name = "atmega3290pa",
1025 .llvm_name = "atmega3290pa",
1026 .features = featureSet(&[_]Feature{
1027 .avr5,
1028 }),
1029 };
1030 pub const atmega329a = Cpu{
1031 .name = "atmega329a",
1032 .llvm_name = "atmega329a",
1033 .features = featureSet(&[_]Feature{
1034 .avr5,
1035 }),
1036 };
1037 pub const atmega329p = Cpu{
1038 .name = "atmega329p",
1039 .llvm_name = "atmega329p",
1040 .features = featureSet(&[_]Feature{
1041 .avr5,
1042 }),
1043 };
1044 pub const atmega329pa = Cpu{
1045 .name = "atmega329pa",
1046 .llvm_name = "atmega329pa",
1047 .features = featureSet(&[_]Feature{
1048 .avr5,
1049 }),
1050 };
1051 pub const atmega32a = Cpu{
1052 .name = "atmega32a",
1053 .llvm_name = "atmega32a",
1054 .features = featureSet(&[_]Feature{
1055 .avr5,
1056 }),
1057 };
1058 pub const atmega32c1 = Cpu{
1059 .name = "atmega32c1",
1060 .llvm_name = "atmega32c1",
1061 .features = featureSet(&[_]Feature{
1062 .avr5,
1063 }),
1064 };
1065 pub const atmega32hvb = Cpu{
1066 .name = "atmega32hvb",
1067 .llvm_name = "atmega32hvb",
1068 .features = featureSet(&[_]Feature{
1069 .avr5,
1070 }),
1071 };
1072 pub const atmega32hvbrevb = Cpu{
1073 .name = "atmega32hvbrevb",
1074 .llvm_name = "atmega32hvbrevb",
1075 .features = featureSet(&[_]Feature{
1076 .avr5,
1077 }),
1078 };
1079 pub const atmega32m1 = Cpu{
1080 .name = "atmega32m1",
1081 .llvm_name = "atmega32m1",
1082 .features = featureSet(&[_]Feature{
1083 .avr5,
1084 }),
1085 };
1086 pub const atmega32u2 = Cpu{
1087 .name = "atmega32u2",
1088 .llvm_name = "atmega32u2",
1089 .features = featureSet(&[_]Feature{
1090 .avr35,
1091 }),
1092 };
1093 pub const atmega32u4 = Cpu{
1094 .name = "atmega32u4",
1095 .llvm_name = "atmega32u4",
1096 .features = featureSet(&[_]Feature{
1097 .avr5,
1098 }),
1099 };
1100 pub const atmega32u6 = Cpu{
1101 .name = "atmega32u6",
1102 .llvm_name = "atmega32u6",
1103 .features = featureSet(&[_]Feature{
1104 .avr5,
1105 }),
1106 };
1107 pub const atmega406 = Cpu{
1108 .name = "atmega406",
1109 .llvm_name = "atmega406",
1110 .features = featureSet(&[_]Feature{
1111 .avr5,
1112 }),
1113 };
1114 pub const atmega48 = Cpu{
1115 .name = "atmega48",
1116 .llvm_name = "atmega48",
1117 .features = featureSet(&[_]Feature{
1118 .avr4,
1119 }),
1120 };
1121 pub const atmega48a = Cpu{
1122 .name = "atmega48a",
1123 .llvm_name = "atmega48a",
1124 .features = featureSet(&[_]Feature{
1125 .avr4,
1126 }),
1127 };
1128 pub const atmega48p = Cpu{
1129 .name = "atmega48p",
1130 .llvm_name = "atmega48p",
1131 .features = featureSet(&[_]Feature{
1132 .avr4,
1133 }),
1134 };
1135 pub const atmega48pa = Cpu{
1136 .name = "atmega48pa",
1137 .llvm_name = "atmega48pa",
1138 .features = featureSet(&[_]Feature{
1139 .avr4,
1140 }),
1141 };
1142 pub const atmega64 = Cpu{
1143 .name = "atmega64",
1144 .llvm_name = "atmega64",
1145 .features = featureSet(&[_]Feature{
1146 .avr5,
1147 }),
1148 };
1149 pub const atmega640 = Cpu{
1150 .name = "atmega640",
1151 .llvm_name = "atmega640",
1152 .features = featureSet(&[_]Feature{
1153 .avr5,
1154 }),
1155 };
1156 pub const atmega644 = Cpu{
1157 .name = "atmega644",
1158 .llvm_name = "atmega644",
1159 .features = featureSet(&[_]Feature{
1160 .avr5,
1161 }),
1162 };
1163 pub const atmega644a = Cpu{
1164 .name = "atmega644a",
1165 .llvm_name = "atmega644a",
1166 .features = featureSet(&[_]Feature{
1167 .avr5,
1168 }),
1169 };
1170 pub const atmega644p = Cpu{
1171 .name = "atmega644p",
1172 .llvm_name = "atmega644p",
1173 .features = featureSet(&[_]Feature{
1174 .avr5,
1175 }),
1176 };
1177 pub const atmega644pa = Cpu{
1178 .name = "atmega644pa",
1179 .llvm_name = "atmega644pa",
1180 .features = featureSet(&[_]Feature{
1181 .avr5,
1182 }),
1183 };
1184 pub const atmega644rfr2 = Cpu{
1185 .name = "atmega644rfr2",
1186 .llvm_name = "atmega644rfr2",
1187 .features = featureSet(&[_]Feature{
1188 .avr5,
1189 }),
1190 };
1191 pub const atmega645 = Cpu{
1192 .name = "atmega645",
1193 .llvm_name = "atmega645",
1194 .features = featureSet(&[_]Feature{
1195 .avr5,
1196 }),
1197 };
1198 pub const atmega6450 = Cpu{
1199 .name = "atmega6450",
1200 .llvm_name = "atmega6450",
1201 .features = featureSet(&[_]Feature{
1202 .avr5,
1203 }),
1204 };
1205 pub const atmega6450a = Cpu{
1206 .name = "atmega6450a",
1207 .llvm_name = "atmega6450a",
1208 .features = featureSet(&[_]Feature{
1209 .avr5,
1210 }),
1211 };
1212 pub const atmega6450p = Cpu{
1213 .name = "atmega6450p",
1214 .llvm_name = "atmega6450p",
1215 .features = featureSet(&[_]Feature{
1216 .avr5,
1217 }),
1218 };
1219 pub const atmega645a = Cpu{
1220 .name = "atmega645a",
1221 .llvm_name = "atmega645a",
1222 .features = featureSet(&[_]Feature{
1223 .avr5,
1224 }),
1225 };
1226 pub const atmega645p = Cpu{
1227 .name = "atmega645p",
1228 .llvm_name = "atmega645p",
1229 .features = featureSet(&[_]Feature{
1230 .avr5,
1231 }),
1232 };
1233 pub const atmega649 = Cpu{
1234 .name = "atmega649",
1235 .llvm_name = "atmega649",
1236 .features = featureSet(&[_]Feature{
1237 .avr5,
1238 }),
1239 };
1240 pub const atmega6490 = Cpu{
1241 .name = "atmega6490",
1242 .llvm_name = "atmega6490",
1243 .features = featureSet(&[_]Feature{
1244 .avr5,
1245 }),
1246 };
1247 pub const atmega6490a = Cpu{
1248 .name = "atmega6490a",
1249 .llvm_name = "atmega6490a",
1250 .features = featureSet(&[_]Feature{
1251 .avr5,
1252 }),
1253 };
1254 pub const atmega6490p = Cpu{
1255 .name = "atmega6490p",
1256 .llvm_name = "atmega6490p",
1257 .features = featureSet(&[_]Feature{
1258 .avr5,
1259 }),
1260 };
1261 pub const atmega649a = Cpu{
1262 .name = "atmega649a",
1263 .llvm_name = "atmega649a",
1264 .features = featureSet(&[_]Feature{
1265 .avr5,
1266 }),
1267 };
1268 pub const atmega649p = Cpu{
1269 .name = "atmega649p",
1270 .llvm_name = "atmega649p",
1271 .features = featureSet(&[_]Feature{
1272 .avr5,
1273 }),
1274 };
1275 pub const atmega64a = Cpu{
1276 .name = "atmega64a",
1277 .llvm_name = "atmega64a",
1278 .features = featureSet(&[_]Feature{
1279 .avr5,
1280 }),
1281 };
1282 pub const atmega64c1 = Cpu{
1283 .name = "atmega64c1",
1284 .llvm_name = "atmega64c1",
1285 .features = featureSet(&[_]Feature{
1286 .avr5,
1287 }),
1288 };
1289 pub const atmega64hve = Cpu{
1290 .name = "atmega64hve",
1291 .llvm_name = "atmega64hve",
1292 .features = featureSet(&[_]Feature{
1293 .avr5,
1294 }),
1295 };
1296 pub const atmega64m1 = Cpu{
1297 .name = "atmega64m1",
1298 .llvm_name = "atmega64m1",
1299 .features = featureSet(&[_]Feature{
1300 .avr5,
1301 }),
1302 };
1303 pub const atmega64rfr2 = Cpu{
1304 .name = "atmega64rfr2",
1305 .llvm_name = "atmega64rfr2",
1306 .features = featureSet(&[_]Feature{
1307 .avr5,
1308 }),
1309 };
1310 pub const atmega8 = Cpu{
1311 .name = "atmega8",
1312 .llvm_name = "atmega8",
1313 .features = featureSet(&[_]Feature{
1314 .avr4,
1315 }),
1316 };
1317 pub const atmega8515 = Cpu{
1318 .name = "atmega8515",
1319 .llvm_name = "atmega8515",
1320 .features = featureSet(&[_]Feature{
1321 .avr2,
1322 .lpmx,
1323 .movw,
1324 .mul,
1325 .spm,
1326 }),
1327 };
1328 pub const atmega8535 = Cpu{
1329 .name = "atmega8535",
1330 .llvm_name = "atmega8535",
1331 .features = featureSet(&[_]Feature{
1332 .avr2,
1333 .lpmx,
1334 .movw,
1335 .mul,
1336 .spm,
1337 }),
1338 };
1339 pub const atmega88 = Cpu{
1340 .name = "atmega88",
1341 .llvm_name = "atmega88",
1342 .features = featureSet(&[_]Feature{
1343 .avr4,
1344 }),
1345 };
1346 pub const atmega88a = Cpu{
1347 .name = "atmega88a",
1348 .llvm_name = "atmega88a",
1349 .features = featureSet(&[_]Feature{
1350 .avr4,
1351 }),
1352 };
1353 pub const atmega88p = Cpu{
1354 .name = "atmega88p",
1355 .llvm_name = "atmega88p",
1356 .features = featureSet(&[_]Feature{
1357 .avr4,
1358 }),
1359 };
1360 pub const atmega88pa = Cpu{
1361 .name = "atmega88pa",
1362 .llvm_name = "atmega88pa",
1363 .features = featureSet(&[_]Feature{
1364 .avr4,
1365 }),
1366 };
1367 pub const atmega8a = Cpu{
1368 .name = "atmega8a",
1369 .llvm_name = "atmega8a",
1370 .features = featureSet(&[_]Feature{
1371 .avr4,
1372 }),
1373 };
1374 pub const atmega8hva = Cpu{
1375 .name = "atmega8hva",
1376 .llvm_name = "atmega8hva",
1377 .features = featureSet(&[_]Feature{
1378 .avr4,
1379 }),
1380 };
1381 pub const atmega8u2 = Cpu{
1382 .name = "atmega8u2",
1383 .llvm_name = "atmega8u2",
1384 .features = featureSet(&[_]Feature{
1385 .avr35,
1386 }),
1387 };
1388 pub const attiny10 = Cpu{
1389 .name = "attiny10",
1390 .llvm_name = "attiny10",
1391 .features = featureSet(&[_]Feature{
1392 .avrtiny,
1393 }),
1394 };
1395 pub const attiny102 = Cpu{
1396 .name = "attiny102",
1397 .llvm_name = "attiny102",
1398 .features = featureSet(&[_]Feature{
1399 .avrtiny,
1400 }),
1401 };
1402 pub const attiny104 = Cpu{
1403 .name = "attiny104",
1404 .llvm_name = "attiny104",
1405 .features = featureSet(&[_]Feature{
1406 .avrtiny,
1407 }),
1408 };
1409 pub const attiny11 = Cpu{
1410 .name = "attiny11",
1411 .llvm_name = "attiny11",
1412 .features = featureSet(&[_]Feature{
1413 .avr1,
1414 }),
1415 };
1416 pub const attiny12 = Cpu{
1417 .name = "attiny12",
1418 .llvm_name = "attiny12",
1419 .features = featureSet(&[_]Feature{
1420 .avr1,
1421 }),
1422 };
1423 pub const attiny13 = Cpu{
1424 .name = "attiny13",
1425 .llvm_name = "attiny13",
1426 .features = featureSet(&[_]Feature{
1427 .avr25,
1428 }),
1429 };
1430 pub const attiny13a = Cpu{
1431 .name = "attiny13a",
1432 .llvm_name = "attiny13a",
1433 .features = featureSet(&[_]Feature{
1434 .avr25,
1435 }),
1436 };
1437 pub const attiny15 = Cpu{
1438 .name = "attiny15",
1439 .llvm_name = "attiny15",
1440 .features = featureSet(&[_]Feature{
1441 .avr1,
1442 }),
1443 };
1444 pub const attiny1634 = Cpu{
1445 .name = "attiny1634",
1446 .llvm_name = "attiny1634",
1447 .features = featureSet(&[_]Feature{
1448 .avr35,
1449 }),
1450 };
1451 pub const attiny167 = Cpu{
1452 .name = "attiny167",
1453 .llvm_name = "attiny167",
1454 .features = featureSet(&[_]Feature{
1455 .avr35,
1456 }),
1457 };
1458 pub const attiny20 = Cpu{
1459 .name = "attiny20",
1460 .llvm_name = "attiny20",
1461 .features = featureSet(&[_]Feature{
1462 .avrtiny,
1463 }),
1464 };
1465 pub const attiny22 = Cpu{
1466 .name = "attiny22",
1467 .llvm_name = "attiny22",
1468 .features = featureSet(&[_]Feature{
1469 .avr2,
1470 }),
1471 };
1472 pub const attiny2313 = Cpu{
1473 .name = "attiny2313",
1474 .llvm_name = "attiny2313",
1475 .features = featureSet(&[_]Feature{
1476 .avr25,
1477 }),
1478 };
1479 pub const attiny2313a = Cpu{
1480 .name = "attiny2313a",
1481 .llvm_name = "attiny2313a",
1482 .features = featureSet(&[_]Feature{
1483 .avr25,
1484 }),
1485 };
1486 pub const attiny24 = Cpu{
1487 .name = "attiny24",
1488 .llvm_name = "attiny24",
1489 .features = featureSet(&[_]Feature{
1490 .avr25,
1491 }),
1492 };
1493 pub const attiny24a = Cpu{
1494 .name = "attiny24a",
1495 .llvm_name = "attiny24a",
1496 .features = featureSet(&[_]Feature{
1497 .avr25,
1498 }),
1499 };
1500 pub const attiny25 = Cpu{
1501 .name = "attiny25",
1502 .llvm_name = "attiny25",
1503 .features = featureSet(&[_]Feature{
1504 .avr25,
1505 }),
1506 };
1507 pub const attiny26 = Cpu{
1508 .name = "attiny26",
1509 .llvm_name = "attiny26",
1510 .features = featureSet(&[_]Feature{
1511 .avr2,
1512 .lpmx,
1513 }),
1514 };
1515 pub const attiny261 = Cpu{
1516 .name = "attiny261",
1517 .llvm_name = "attiny261",
1518 .features = featureSet(&[_]Feature{
1519 .avr25,
1520 }),
1521 };
1522 pub const attiny261a = Cpu{
1523 .name = "attiny261a",
1524 .llvm_name = "attiny261a",
1525 .features = featureSet(&[_]Feature{
1526 .avr25,
1527 }),
1528 };
1529 pub const attiny28 = Cpu{
1530 .name = "attiny28",
1531 .llvm_name = "attiny28",
1532 .features = featureSet(&[_]Feature{
1533 .avr1,
1534 }),
1535 };
1536 pub const attiny4 = Cpu{
1537 .name = "attiny4",
1538 .llvm_name = "attiny4",
1539 .features = featureSet(&[_]Feature{
1540 .avrtiny,
1541 }),
1542 };
1543 pub const attiny40 = Cpu{
1544 .name = "attiny40",
1545 .llvm_name = "attiny40",
1546 .features = featureSet(&[_]Feature{
1547 .avrtiny,
1548 }),
1549 };
1550 pub const attiny4313 = Cpu{
1551 .name = "attiny4313",
1552 .llvm_name = "attiny4313",
1553 .features = featureSet(&[_]Feature{
1554 .avr25,
1555 }),
1556 };
1557 pub const attiny43u = Cpu{
1558 .name = "attiny43u",
1559 .llvm_name = "attiny43u",
1560 .features = featureSet(&[_]Feature{
1561 .avr25,
1562 }),
1563 };
1564 pub const attiny44 = Cpu{
1565 .name = "attiny44",
1566 .llvm_name = "attiny44",
1567 .features = featureSet(&[_]Feature{
1568 .avr25,
1569 }),
1570 };
1571 pub const attiny44a = Cpu{
1572 .name = "attiny44a",
1573 .llvm_name = "attiny44a",
1574 .features = featureSet(&[_]Feature{
1575 .avr25,
1576 }),
1577 };
1578 pub const attiny45 = Cpu{
1579 .name = "attiny45",
1580 .llvm_name = "attiny45",
1581 .features = featureSet(&[_]Feature{
1582 .avr25,
1583 }),
1584 };
1585 pub const attiny461 = Cpu{
1586 .name = "attiny461",
1587 .llvm_name = "attiny461",
1588 .features = featureSet(&[_]Feature{
1589 .avr25,
1590 }),
1591 };
1592 pub const attiny461a = Cpu{
1593 .name = "attiny461a",
1594 .llvm_name = "attiny461a",
1595 .features = featureSet(&[_]Feature{
1596 .avr25,
1597 }),
1598 };
1599 pub const attiny48 = Cpu{
1600 .name = "attiny48",
1601 .llvm_name = "attiny48",
1602 .features = featureSet(&[_]Feature{
1603 .avr25,
1604 }),
1605 };
1606 pub const attiny5 = Cpu{
1607 .name = "attiny5",
1608 .llvm_name = "attiny5",
1609 .features = featureSet(&[_]Feature{
1610 .avrtiny,
1611 }),
1612 };
1613 pub const attiny828 = Cpu{
1614 .name = "attiny828",
1615 .llvm_name = "attiny828",
1616 .features = featureSet(&[_]Feature{
1617 .avr25,
1618 }),
1619 };
1620 pub const attiny84 = Cpu{
1621 .name = "attiny84",
1622 .llvm_name = "attiny84",
1623 .features = featureSet(&[_]Feature{
1624 .avr25,
1625 }),
1626 };
1627 pub const attiny84a = Cpu{
1628 .name = "attiny84a",
1629 .llvm_name = "attiny84a",
1630 .features = featureSet(&[_]Feature{
1631 .avr25,
1632 }),
1633 };
1634 pub const attiny85 = Cpu{
1635 .name = "attiny85",
1636 .llvm_name = "attiny85",
1637 .features = featureSet(&[_]Feature{
1638 .avr25,
1639 }),
1640 };
1641 pub const attiny861 = Cpu{
1642 .name = "attiny861",
1643 .llvm_name = "attiny861",
1644 .features = featureSet(&[_]Feature{
1645 .avr25,
1646 }),
1647 };
1648 pub const attiny861a = Cpu{
1649 .name = "attiny861a",
1650 .llvm_name = "attiny861a",
1651 .features = featureSet(&[_]Feature{
1652 .avr25,
1653 }),
1654 };
1655 pub const attiny87 = Cpu{
1656 .name = "attiny87",
1657 .llvm_name = "attiny87",
1658 .features = featureSet(&[_]Feature{
1659 .avr25,
1660 }),
1661 };
1662 pub const attiny88 = Cpu{
1663 .name = "attiny88",
1664 .llvm_name = "attiny88",
1665 .features = featureSet(&[_]Feature{
1666 .avr25,
1667 }),
1668 };
1669 pub const attiny9 = Cpu{
1670 .name = "attiny9",
1671 .llvm_name = "attiny9",
1672 .features = featureSet(&[_]Feature{
1673 .avrtiny,
1674 }),
1675 };
1676 pub const atxmega128a1 = Cpu{
1677 .name = "atxmega128a1",
1678 .llvm_name = "atxmega128a1",
1679 .features = featureSet(&[_]Feature{
1680 .xmega,
1681 }),
1682 };
1683 pub const atxmega128a1u = Cpu{
1684 .name = "atxmega128a1u",
1685 .llvm_name = "atxmega128a1u",
1686 .features = featureSet(&[_]Feature{
1687 .xmegau,
1688 }),
1689 };
1690 pub const atxmega128a3 = Cpu{
1691 .name = "atxmega128a3",
1692 .llvm_name = "atxmega128a3",
1693 .features = featureSet(&[_]Feature{
1694 .xmega,
1695 }),
1696 };
1697 pub const atxmega128a3u = Cpu{
1698 .name = "atxmega128a3u",
1699 .llvm_name = "atxmega128a3u",
1700 .features = featureSet(&[_]Feature{
1701 .xmegau,
1702 }),
1703 };
1704 pub const atxmega128a4u = Cpu{
1705 .name = "atxmega128a4u",
1706 .llvm_name = "atxmega128a4u",
1707 .features = featureSet(&[_]Feature{
1708 .xmegau,
1709 }),
1710 };
1711 pub const atxmega128b1 = Cpu{
1712 .name = "atxmega128b1",
1713 .llvm_name = "atxmega128b1",
1714 .features = featureSet(&[_]Feature{
1715 .xmegau,
1716 }),
1717 };
1718 pub const atxmega128b3 = Cpu{
1719 .name = "atxmega128b3",
1720 .llvm_name = "atxmega128b3",
1721 .features = featureSet(&[_]Feature{
1722 .xmegau,
1723 }),
1724 };
1725 pub const atxmega128c3 = Cpu{
1726 .name = "atxmega128c3",
1727 .llvm_name = "atxmega128c3",
1728 .features = featureSet(&[_]Feature{
1729 .xmegau,
1730 }),
1731 };
1732 pub const atxmega128d3 = Cpu{
1733 .name = "atxmega128d3",
1734 .llvm_name = "atxmega128d3",
1735 .features = featureSet(&[_]Feature{
1736 .xmega,
1737 }),
1738 };
1739 pub const atxmega128d4 = Cpu{
1740 .name = "atxmega128d4",
1741 .llvm_name = "atxmega128d4",
1742 .features = featureSet(&[_]Feature{
1743 .xmega,
1744 }),
1745 };
1746 pub const atxmega16a4 = Cpu{
1747 .name = "atxmega16a4",
1748 .llvm_name = "atxmega16a4",
1749 .features = featureSet(&[_]Feature{
1750 .xmega,
1751 }),
1752 };
1753 pub const atxmega16a4u = Cpu{
1754 .name = "atxmega16a4u",
1755 .llvm_name = "atxmega16a4u",
1756 .features = featureSet(&[_]Feature{
1757 .xmegau,
1758 }),
1759 };
1760 pub const atxmega16c4 = Cpu{
1761 .name = "atxmega16c4",
1762 .llvm_name = "atxmega16c4",
1763 .features = featureSet(&[_]Feature{
1764 .xmegau,
1765 }),
1766 };
1767 pub const atxmega16d4 = Cpu{
1768 .name = "atxmega16d4",
1769 .llvm_name = "atxmega16d4",
1770 .features = featureSet(&[_]Feature{
1771 .xmega,
1772 }),
1773 };
1774 pub const atxmega16e5 = Cpu{
1775 .name = "atxmega16e5",
1776 .llvm_name = "atxmega16e5",
1777 .features = featureSet(&[_]Feature{
1778 .xmega,
1779 }),
1780 };
1781 pub const atxmega192a3 = Cpu{
1782 .name = "atxmega192a3",
1783 .llvm_name = "atxmega192a3",
1784 .features = featureSet(&[_]Feature{
1785 .xmega,
1786 }),
1787 };
1788 pub const atxmega192a3u = Cpu{
1789 .name = "atxmega192a3u",
1790 .llvm_name = "atxmega192a3u",
1791 .features = featureSet(&[_]Feature{
1792 .xmegau,
1793 }),
1794 };
1795 pub const atxmega192c3 = Cpu{
1796 .name = "atxmega192c3",
1797 .llvm_name = "atxmega192c3",
1798 .features = featureSet(&[_]Feature{
1799 .xmegau,
1800 }),
1801 };
1802 pub const atxmega192d3 = Cpu{
1803 .name = "atxmega192d3",
1804 .llvm_name = "atxmega192d3",
1805 .features = featureSet(&[_]Feature{
1806 .xmega,
1807 }),
1808 };
1809 pub const atxmega256a3 = Cpu{
1810 .name = "atxmega256a3",
1811 .llvm_name = "atxmega256a3",
1812 .features = featureSet(&[_]Feature{
1813 .xmega,
1814 }),
1815 };
1816 pub const atxmega256a3b = Cpu{
1817 .name = "atxmega256a3b",
1818 .llvm_name = "atxmega256a3b",
1819 .features = featureSet(&[_]Feature{
1820 .xmega,
1821 }),
1822 };
1823 pub const atxmega256a3bu = Cpu{
1824 .name = "atxmega256a3bu",
1825 .llvm_name = "atxmega256a3bu",
1826 .features = featureSet(&[_]Feature{
1827 .xmegau,
1828 }),
1829 };
1830 pub const atxmega256a3u = Cpu{
1831 .name = "atxmega256a3u",
1832 .llvm_name = "atxmega256a3u",
1833 .features = featureSet(&[_]Feature{
1834 .xmegau,
1835 }),
1836 };
1837 pub const atxmega256c3 = Cpu{
1838 .name = "atxmega256c3",
1839 .llvm_name = "atxmega256c3",
1840 .features = featureSet(&[_]Feature{
1841 .xmegau,
1842 }),
1843 };
1844 pub const atxmega256d3 = Cpu{
1845 .name = "atxmega256d3",
1846 .llvm_name = "atxmega256d3",
1847 .features = featureSet(&[_]Feature{
1848 .xmega,
1849 }),
1850 };
1851 pub const atxmega32a4 = Cpu{
1852 .name = "atxmega32a4",
1853 .llvm_name = "atxmega32a4",
1854 .features = featureSet(&[_]Feature{
1855 .xmega,
1856 }),
1857 };
1858 pub const atxmega32a4u = Cpu{
1859 .name = "atxmega32a4u",
1860 .llvm_name = "atxmega32a4u",
1861 .features = featureSet(&[_]Feature{
1862 .xmegau,
1863 }),
1864 };
1865 pub const atxmega32c4 = Cpu{
1866 .name = "atxmega32c4",
1867 .llvm_name = "atxmega32c4",
1868 .features = featureSet(&[_]Feature{
1869 .xmegau,
1870 }),
1871 };
1872 pub const atxmega32d4 = Cpu{
1873 .name = "atxmega32d4",
1874 .llvm_name = "atxmega32d4",
1875 .features = featureSet(&[_]Feature{
1876 .xmega,
1877 }),
1878 };
1879 pub const atxmega32e5 = Cpu{
1880 .name = "atxmega32e5",
1881 .llvm_name = "atxmega32e5",
1882 .features = featureSet(&[_]Feature{
1883 .xmega,
1884 }),
1885 };
1886 pub const atxmega32x1 = Cpu{
1887 .name = "atxmega32x1",
1888 .llvm_name = "atxmega32x1",
1889 .features = featureSet(&[_]Feature{
1890 .xmega,
1891 }),
1892 };
1893 pub const atxmega384c3 = Cpu{
1894 .name = "atxmega384c3",
1895 .llvm_name = "atxmega384c3",
1896 .features = featureSet(&[_]Feature{
1897 .xmegau,
1898 }),
1899 };
1900 pub const atxmega384d3 = Cpu{
1901 .name = "atxmega384d3",
1902 .llvm_name = "atxmega384d3",
1903 .features = featureSet(&[_]Feature{
1904 .xmega,
1905 }),
1906 };
1907 pub const atxmega64a1 = Cpu{
1908 .name = "atxmega64a1",
1909 .llvm_name = "atxmega64a1",
1910 .features = featureSet(&[_]Feature{
1911 .xmega,
1912 }),
1913 };
1914 pub const atxmega64a1u = Cpu{
1915 .name = "atxmega64a1u",
1916 .llvm_name = "atxmega64a1u",
1917 .features = featureSet(&[_]Feature{
1918 .xmegau,
1919 }),
1920 };
1921 pub const atxmega64a3 = Cpu{
1922 .name = "atxmega64a3",
1923 .llvm_name = "atxmega64a3",
1924 .features = featureSet(&[_]Feature{
1925 .xmega,
1926 }),
1927 };
1928 pub const atxmega64a3u = Cpu{
1929 .name = "atxmega64a3u",
1930 .llvm_name = "atxmega64a3u",
1931 .features = featureSet(&[_]Feature{
1932 .xmegau,
1933 }),
1934 };
1935 pub const atxmega64a4u = Cpu{
1936 .name = "atxmega64a4u",
1937 .llvm_name = "atxmega64a4u",
1938 .features = featureSet(&[_]Feature{
1939 .xmegau,
1940 }),
1941 };
1942 pub const atxmega64b1 = Cpu{
1943 .name = "atxmega64b1",
1944 .llvm_name = "atxmega64b1",
1945 .features = featureSet(&[_]Feature{
1946 .xmegau,
1947 }),
1948 };
1949 pub const atxmega64b3 = Cpu{
1950 .name = "atxmega64b3",
1951 .llvm_name = "atxmega64b3",
1952 .features = featureSet(&[_]Feature{
1953 .xmegau,
1954 }),
1955 };
1956 pub const atxmega64c3 = Cpu{
1957 .name = "atxmega64c3",
1958 .llvm_name = "atxmega64c3",
1959 .features = featureSet(&[_]Feature{
1960 .xmegau,
1961 }),
1962 };
1963 pub const atxmega64d3 = Cpu{
1964 .name = "atxmega64d3",
1965 .llvm_name = "atxmega64d3",
1966 .features = featureSet(&[_]Feature{
1967 .xmega,
1968 }),
1969 };
1970 pub const atxmega64d4 = Cpu{
1971 .name = "atxmega64d4",
1972 .llvm_name = "atxmega64d4",
1973 .features = featureSet(&[_]Feature{
1974 .xmega,
1975 }),
1976 };
1977 pub const atxmega8e5 = Cpu{
1978 .name = "atxmega8e5",
1979 .llvm_name = "atxmega8e5",
1980 .features = featureSet(&[_]Feature{
1981 .xmega,
1982 }),
1983 };
1984 pub const avr1 = Cpu{
1985 .name = "avr1",
1986 .llvm_name = "avr1",
1987 .features = featureSet(&[_]Feature{
1988 .avr1,
1989 }),
1990 };
1991 pub const avr2 = Cpu{
1992 .name = "avr2",
1993 .llvm_name = "avr2",
1994 .features = featureSet(&[_]Feature{
1995 .avr2,
1996 }),
1997 };
1998 pub const avr25 = Cpu{
1999 .name = "avr25",
2000 .llvm_name = "avr25",
2001 .features = featureSet(&[_]Feature{
2002 .avr25,
2003 }),
2004 };
2005 pub const avr3 = Cpu{
2006 .name = "avr3",
2007 .llvm_name = "avr3",
2008 .features = featureSet(&[_]Feature{
2009 .avr3,
2010 }),
2011 };
2012 pub const avr31 = Cpu{
2013 .name = "avr31",
2014 .llvm_name = "avr31",
2015 .features = featureSet(&[_]Feature{
2016 .avr31,
2017 }),
2018 };
2019 pub const avr35 = Cpu{
2020 .name = "avr35",
2021 .llvm_name = "avr35",
2022 .features = featureSet(&[_]Feature{
2023 .avr35,
2024 }),
2025 };
2026 pub const avr4 = Cpu{
2027 .name = "avr4",
2028 .llvm_name = "avr4",
2029 .features = featureSet(&[_]Feature{
2030 .avr4,
2031 }),
2032 };
2033 pub const avr5 = Cpu{
2034 .name = "avr5",
2035 .llvm_name = "avr5",
2036 .features = featureSet(&[_]Feature{
2037 .avr5,
2038 }),
2039 };
2040 pub const avr51 = Cpu{
2041 .name = "avr51",
2042 .llvm_name = "avr51",
2043 .features = featureSet(&[_]Feature{
2044 .avr51,
2045 }),
2046 };
2047 pub const avr6 = Cpu{
2048 .name = "avr6",
2049 .llvm_name = "avr6",
2050 .features = featureSet(&[_]Feature{
2051 .avr6,
2052 }),
2053 };
2054 pub const avrtiny = Cpu{
2055 .name = "avrtiny",
2056 .llvm_name = "avrtiny",
2057 .features = featureSet(&[_]Feature{
2058 .avrtiny,
2059 }),
2060 };
2061 pub const avrxmega1 = Cpu{
2062 .name = "avrxmega1",
2063 .llvm_name = "avrxmega1",
2064 .features = featureSet(&[_]Feature{
2065 .xmega,
2066 }),
2067 };
2068 pub const avrxmega2 = Cpu{
2069 .name = "avrxmega2",
2070 .llvm_name = "avrxmega2",
2071 .features = featureSet(&[_]Feature{
2072 .xmega,
2073 }),
2074 };
2075 pub const avrxmega3 = Cpu{
2076 .name = "avrxmega3",
2077 .llvm_name = "avrxmega3",
2078 .features = featureSet(&[_]Feature{
2079 .xmega,
2080 }),
2081 };
2082 pub const avrxmega4 = Cpu{
2083 .name = "avrxmega4",
2084 .llvm_name = "avrxmega4",
2085 .features = featureSet(&[_]Feature{
2086 .xmega,
2087 }),
2088 };
2089 pub const avrxmega5 = Cpu{
2090 .name = "avrxmega5",
2091 .llvm_name = "avrxmega5",
2092 .features = featureSet(&[_]Feature{
2093 .xmega,
2094 }),
2095 };
2096 pub const avrxmega6 = Cpu{
2097 .name = "avrxmega6",
2098 .llvm_name = "avrxmega6",
2099 .features = featureSet(&[_]Feature{
2100 .xmega,
2101 }),
2102 };
2103 pub const avrxmega7 = Cpu{
2104 .name = "avrxmega7",
2105 .llvm_name = "avrxmega7",
2106 .features = featureSet(&[_]Feature{
2107 .xmega,
2108 }),
2109 };
2110 pub const m3000 = Cpu{
2111 .name = "m3000",
2112 .llvm_name = "m3000",
2113 .features = featureSet(&[_]Feature{
2114 .avr5,
2115 }),
2116 };
2117};
2118
2119/// All avr CPUs, sorted alphabetically by name.
2120/// TODO: Replace this with usage of `std.meta.declList`. It does work, but stage1
2121/// compiler has inefficient memory and CPU usage, affecting build times.
2122pub const all_cpus = &[_]*const Cpu{
2123 &cpu.at43usb320,
2124 &cpu.at43usb355,
2125 &cpu.at76c711,
2126 &cpu.at86rf401,
2127 &cpu.at90c8534,
2128 &cpu.at90can128,
2129 &cpu.at90can32,
2130 &cpu.at90can64,
2131 &cpu.at90pwm1,
2132 &cpu.at90pwm161,
2133 &cpu.at90pwm2,
2134 &cpu.at90pwm216,
2135 &cpu.at90pwm2b,
2136 &cpu.at90pwm3,
2137 &cpu.at90pwm316,
2138 &cpu.at90pwm3b,
2139 &cpu.at90pwm81,
2140 &cpu.at90s1200,
2141 &cpu.at90s2313,
2142 &cpu.at90s2323,
2143 &cpu.at90s2333,
2144 &cpu.at90s2343,
2145 &cpu.at90s4414,
2146 &cpu.at90s4433,
2147 &cpu.at90s4434,
2148 &cpu.at90s8515,
2149 &cpu.at90s8535,
2150 &cpu.at90scr100,
2151 &cpu.at90usb1286,
2152 &cpu.at90usb1287,
2153 &cpu.at90usb162,
2154 &cpu.at90usb646,
2155 &cpu.at90usb647,
2156 &cpu.at90usb82,
2157 &cpu.at94k,
2158 &cpu.ata5272,
2159 &cpu.ata5505,
2160 &cpu.ata5790,
2161 &cpu.ata5795,
2162 &cpu.ata6285,
2163 &cpu.ata6286,
2164 &cpu.ata6289,
2165 &cpu.atmega103,
2166 &cpu.atmega128,
2167 &cpu.atmega1280,
2168 &cpu.atmega1281,
2169 &cpu.atmega1284,
2170 &cpu.atmega1284p,
2171 &cpu.atmega1284rfr2,
2172 &cpu.atmega128a,
2173 &cpu.atmega128rfa1,
2174 &cpu.atmega128rfr2,
2175 &cpu.atmega16,
2176 &cpu.atmega161,
2177 &cpu.atmega162,
2178 &cpu.atmega163,
2179 &cpu.atmega164a,
2180 &cpu.atmega164p,
2181 &cpu.atmega164pa,
2182 &cpu.atmega165,
2183 &cpu.atmega165a,
2184 &cpu.atmega165p,
2185 &cpu.atmega165pa,
2186 &cpu.atmega168,
2187 &cpu.atmega168a,
2188 &cpu.atmega168p,
2189 &cpu.atmega168pa,
2190 &cpu.atmega169,
2191 &cpu.atmega169a,
2192 &cpu.atmega169p,
2193 &cpu.atmega169pa,
2194 &cpu.atmega16a,
2195 &cpu.atmega16hva,
2196 &cpu.atmega16hva2,
2197 &cpu.atmega16hvb,
2198 &cpu.atmega16hvbrevb,
2199 &cpu.atmega16m1,
2200 &cpu.atmega16u2,
2201 &cpu.atmega16u4,
2202 &cpu.atmega2560,
2203 &cpu.atmega2561,
2204 &cpu.atmega2564rfr2,
2205 &cpu.atmega256rfr2,
2206 &cpu.atmega32,
2207 &cpu.atmega323,
2208 &cpu.atmega324a,
2209 &cpu.atmega324p,
2210 &cpu.atmega324pa,
2211 &cpu.atmega325,
2212 &cpu.atmega3250,
2213 &cpu.atmega3250a,
2214 &cpu.atmega3250p,
2215 &cpu.atmega3250pa,
2216 &cpu.atmega325a,
2217 &cpu.atmega325p,
2218 &cpu.atmega325pa,
2219 &cpu.atmega328,
2220 &cpu.atmega328p,
2221 &cpu.atmega329,
2222 &cpu.atmega3290,
2223 &cpu.atmega3290a,
2224 &cpu.atmega3290p,
2225 &cpu.atmega3290pa,
2226 &cpu.atmega329a,
2227 &cpu.atmega329p,
2228 &cpu.atmega329pa,
2229 &cpu.atmega32a,
2230 &cpu.atmega32c1,
2231 &cpu.atmega32hvb,
2232 &cpu.atmega32hvbrevb,
2233 &cpu.atmega32m1,
2234 &cpu.atmega32u2,
2235 &cpu.atmega32u4,
2236 &cpu.atmega32u6,
2237 &cpu.atmega406,
2238 &cpu.atmega48,
2239 &cpu.atmega48a,
2240 &cpu.atmega48p,
2241 &cpu.atmega48pa,
2242 &cpu.atmega64,
2243 &cpu.atmega640,
2244 &cpu.atmega644,
2245 &cpu.atmega644a,
2246 &cpu.atmega644p,
2247 &cpu.atmega644pa,
2248 &cpu.atmega644rfr2,
2249 &cpu.atmega645,
2250 &cpu.atmega6450,
2251 &cpu.atmega6450a,
2252 &cpu.atmega6450p,
2253 &cpu.atmega645a,
2254 &cpu.atmega645p,
2255 &cpu.atmega649,
2256 &cpu.atmega6490,
2257 &cpu.atmega6490a,
2258 &cpu.atmega6490p,
2259 &cpu.atmega649a,
2260 &cpu.atmega649p,
2261 &cpu.atmega64a,
2262 &cpu.atmega64c1,
2263 &cpu.atmega64hve,
2264 &cpu.atmega64m1,
2265 &cpu.atmega64rfr2,
2266 &cpu.atmega8,
2267 &cpu.atmega8515,
2268 &cpu.atmega8535,
2269 &cpu.atmega88,
2270 &cpu.atmega88a,
2271 &cpu.atmega88p,
2272 &cpu.atmega88pa,
2273 &cpu.atmega8a,
2274 &cpu.atmega8hva,
2275 &cpu.atmega8u2,
2276 &cpu.attiny10,
2277 &cpu.attiny102,
2278 &cpu.attiny104,
2279 &cpu.attiny11,
2280 &cpu.attiny12,
2281 &cpu.attiny13,
2282 &cpu.attiny13a,
2283 &cpu.attiny15,
2284 &cpu.attiny1634,
2285 &cpu.attiny167,
2286 &cpu.attiny20,
2287 &cpu.attiny22,
2288 &cpu.attiny2313,
2289 &cpu.attiny2313a,
2290 &cpu.attiny24,
2291 &cpu.attiny24a,
2292 &cpu.attiny25,
2293 &cpu.attiny26,
2294 &cpu.attiny261,
2295 &cpu.attiny261a,
2296 &cpu.attiny28,
2297 &cpu.attiny4,
2298 &cpu.attiny40,
2299 &cpu.attiny4313,
2300 &cpu.attiny43u,
2301 &cpu.attiny44,
2302 &cpu.attiny44a,
2303 &cpu.attiny45,
2304 &cpu.attiny461,
2305 &cpu.attiny461a,
2306 &cpu.attiny48,
2307 &cpu.attiny5,
2308 &cpu.attiny828,
2309 &cpu.attiny84,
2310 &cpu.attiny84a,
2311 &cpu.attiny85,
2312 &cpu.attiny861,
2313 &cpu.attiny861a,
2314 &cpu.attiny87,
2315 &cpu.attiny88,
2316 &cpu.attiny9,
2317 &cpu.atxmega128a1,
2318 &cpu.atxmega128a1u,
2319 &cpu.atxmega128a3,
2320 &cpu.atxmega128a3u,
2321 &cpu.atxmega128a4u,
2322 &cpu.atxmega128b1,
2323 &cpu.atxmega128b3,
2324 &cpu.atxmega128c3,
2325 &cpu.atxmega128d3,
2326 &cpu.atxmega128d4,
2327 &cpu.atxmega16a4,
2328 &cpu.atxmega16a4u,
2329 &cpu.atxmega16c4,
2330 &cpu.atxmega16d4,
2331 &cpu.atxmega16e5,
2332 &cpu.atxmega192a3,
2333 &cpu.atxmega192a3u,
2334 &cpu.atxmega192c3,
2335 &cpu.atxmega192d3,
2336 &cpu.atxmega256a3,
2337 &cpu.atxmega256a3b,
2338 &cpu.atxmega256a3bu,
2339 &cpu.atxmega256a3u,
2340 &cpu.atxmega256c3,
2341 &cpu.atxmega256d3,
2342 &cpu.atxmega32a4,
2343 &cpu.atxmega32a4u,
2344 &cpu.atxmega32c4,
2345 &cpu.atxmega32d4,
2346 &cpu.atxmega32e5,
2347 &cpu.atxmega32x1,
2348 &cpu.atxmega384c3,
2349 &cpu.atxmega384d3,
2350 &cpu.atxmega64a1,
2351 &cpu.atxmega64a1u,
2352 &cpu.atxmega64a3,
2353 &cpu.atxmega64a3u,
2354 &cpu.atxmega64a4u,
2355 &cpu.atxmega64b1,
2356 &cpu.atxmega64b3,
2357 &cpu.atxmega64c3,
2358 &cpu.atxmega64d3,
2359 &cpu.atxmega64d4,
2360 &cpu.atxmega8e5,
2361 &cpu.avr1,
2362 &cpu.avr2,
2363 &cpu.avr25,
2364 &cpu.avr3,
2365 &cpu.avr31,
2366 &cpu.avr35,
2367 &cpu.avr4,
2368 &cpu.avr5,
2369 &cpu.avr51,
2370 &cpu.avr6,
2371 &cpu.avrtiny,
2372 &cpu.avrxmega1,
2373 &cpu.avrxmega2,
2374 &cpu.avrxmega3,
2375 &cpu.avrxmega4,
2376 &cpu.avrxmega5,
2377 &cpu.avrxmega6,
2378 &cpu.avrxmega7,
2379 &cpu.m3000,
2380};
lib/std/target/bpf.zig created+76
...@@ -0,0 +1,76 @@
1const std = @import("../std.zig");
2const Cpu = std.Target.Cpu;
3
4pub const Feature = enum {
5 alu32,
6 dummy,
7 dwarfris,
8};
9
10pub usingnamespace Cpu.Feature.feature_set_fns(Feature);
11
12pub const all_features = blk: {
13 const len = @typeInfo(Feature).Enum.fields.len;
14 std.debug.assert(len <= Cpu.Feature.Set.needed_bit_count);
15 var result: [len]Cpu.Feature = undefined;
16 result[@enumToInt(Feature.alu32)] = .{
17 .llvm_name = "alu32",
18 .description = "Enable ALU32 instructions",
19 .dependencies = featureSet(&[_]Feature{}),
20 };
21 result[@enumToInt(Feature.dummy)] = .{
22 .llvm_name = "dummy",
23 .description = "unused feature",
24 .dependencies = featureSet(&[_]Feature{}),
25 };
26 result[@enumToInt(Feature.dwarfris)] = .{
27 .llvm_name = "dwarfris",
28 .description = "Disable MCAsmInfo DwarfUsesRelocationsAcrossSections",
29 .dependencies = featureSet(&[_]Feature{}),
30 };
31 const ti = @typeInfo(Feature);
32 for (result) |*elem, i| {
33 elem.index = i;
34 elem.name = ti.Enum.fields[i].name;
35 }
36 break :blk result;
37};
38
39pub const cpu = struct {
40 pub const generic = Cpu{
41 .name = "generic",
42 .llvm_name = "generic",
43 .features = featureSet(&[_]Feature{}),
44 };
45 pub const probe = Cpu{
46 .name = "probe",
47 .llvm_name = "probe",
48 .features = featureSet(&[_]Feature{}),
49 };
50 pub const v1 = Cpu{
51 .name = "v1",
52 .llvm_name = "v1",
53 .features = featureSet(&[_]Feature{}),
54 };
55 pub const v2 = Cpu{
56 .name = "v2",
57 .llvm_name = "v2",
58 .features = featureSet(&[_]Feature{}),
59 };
60 pub const v3 = Cpu{
61 .name = "v3",
62 .llvm_name = "v3",
63 .features = featureSet(&[_]Feature{}),
64 };
65};
66
67/// All bpf CPUs, sorted alphabetically by name.
68/// TODO: Replace this with usage of `std.meta.declList`. It does work, but stage1
69/// compiler has inefficient memory and CPU usage, affecting build times.
70pub const all_cpus = &[_]*const Cpu{
71 &cpu.generic,
72 &cpu.probe,
73 &cpu.v1,
74 &cpu.v2,
75 &cpu.v3,
76};
lib/std/target/hexagon.zig created+312
...@@ -0,0 +1,312 @@
1const std = @import("../std.zig");
2const Cpu = std.Target.Cpu;
3
4pub const Feature = enum {
5 duplex,
6 hvx,
7 hvx_length128b,
8 hvx_length64b,
9 hvxv60,
10 hvxv62,
11 hvxv65,
12 hvxv66,
13 long_calls,
14 mem_noshuf,
15 memops,
16 noreturn_stack_elim,
17 nvj,
18 nvs,
19 packets,
20 reserved_r19,
21 small_data,
22 v5,
23 v55,
24 v60,
25 v62,
26 v65,
27 v66,
28 zreg,
29};
30
31pub usingnamespace Cpu.Feature.feature_set_fns(Feature);
32
33pub const all_features = blk: {
34 const len = @typeInfo(Feature).Enum.fields.len;
35 std.debug.assert(len <= Cpu.Feature.Set.needed_bit_count);
36 var result: [len]Cpu.Feature = undefined;
37 result[@enumToInt(Feature.duplex)] = .{
38 .llvm_name = "duplex",
39 .description = "Enable generation of duplex instruction",
40 .dependencies = featureSet(&[_]Feature{}),
41 };
42 result[@enumToInt(Feature.hvx)] = .{
43 .llvm_name = "hvx",
44 .description = "Hexagon HVX instructions",
45 .dependencies = featureSet(&[_]Feature{}),
46 };
47 result[@enumToInt(Feature.hvx_length128b)] = .{
48 .llvm_name = "hvx-length128b",
49 .description = "Hexagon HVX 128B instructions",
50 .dependencies = featureSet(&[_]Feature{
51 .hvx,
52 }),
53 };
54 result[@enumToInt(Feature.hvx_length64b)] = .{
55 .llvm_name = "hvx-length64b",
56 .description = "Hexagon HVX 64B instructions",
57 .dependencies = featureSet(&[_]Feature{
58 .hvx,
59 }),
60 };
61 result[@enumToInt(Feature.hvxv60)] = .{
62 .llvm_name = "hvxv60",
63 .description = "Hexagon HVX instructions",
64 .dependencies = featureSet(&[_]Feature{
65 .hvx,
66 }),
67 };
68 result[@enumToInt(Feature.hvxv62)] = .{
69 .llvm_name = "hvxv62",
70 .description = "Hexagon HVX instructions",
71 .dependencies = featureSet(&[_]Feature{
72 .hvx,
73 .hvxv60,
74 }),
75 };
76 result[@enumToInt(Feature.hvxv65)] = .{
77 .llvm_name = "hvxv65",
78 .description = "Hexagon HVX instructions",
79 .dependencies = featureSet(&[_]Feature{
80 .hvx,
81 .hvxv60,
82 .hvxv62,
83 }),
84 };
85 result[@enumToInt(Feature.hvxv66)] = .{
86 .llvm_name = "hvxv66",
87 .description = "Hexagon HVX instructions",
88 .dependencies = featureSet(&[_]Feature{
89 .hvx,
90 .hvxv60,
91 .hvxv62,
92 .hvxv65,
93 .zreg,
94 }),
95 };
96 result[@enumToInt(Feature.long_calls)] = .{
97 .llvm_name = "long-calls",
98 .description = "Use constant-extended calls",
99 .dependencies = featureSet(&[_]Feature{}),
100 };
101 result[@enumToInt(Feature.mem_noshuf)] = .{
102 .llvm_name = "mem_noshuf",
103 .description = "Supports mem_noshuf feature",
104 .dependencies = featureSet(&[_]Feature{}),
105 };
106 result[@enumToInt(Feature.memops)] = .{
107 .llvm_name = "memops",
108 .description = "Use memop instructions",
109 .dependencies = featureSet(&[_]Feature{}),
110 };
111 result[@enumToInt(Feature.noreturn_stack_elim)] = .{
112 .llvm_name = "noreturn-stack-elim",
113 .description = "Eliminate stack allocation in a noreturn function when possible",
114 .dependencies = featureSet(&[_]Feature{}),
115 };
116 result[@enumToInt(Feature.nvj)] = .{
117 .llvm_name = "nvj",
118 .description = "Support for new-value jumps",
119 .dependencies = featureSet(&[_]Feature{
120 .packets,
121 }),
122 };
123 result[@enumToInt(Feature.nvs)] = .{
124 .llvm_name = "nvs",
125 .description = "Support for new-value stores",
126 .dependencies = featureSet(&[_]Feature{
127 .packets,
128 }),
129 };
130 result[@enumToInt(Feature.packets)] = .{
131 .llvm_name = "packets",
132 .description = "Support for instruction packets",
133 .dependencies = featureSet(&[_]Feature{}),
134 };
135 result[@enumToInt(Feature.reserved_r19)] = .{
136 .llvm_name = "reserved-r19",
137 .description = "Reserve register R19",
138 .dependencies = featureSet(&[_]Feature{}),
139 };
140 result[@enumToInt(Feature.small_data)] = .{
141 .llvm_name = "small-data",
142 .description = "Allow GP-relative addressing of global variables",
143 .dependencies = featureSet(&[_]Feature{}),
144 };
145 result[@enumToInt(Feature.v5)] = .{
146 .llvm_name = "v5",
147 .description = "Enable Hexagon V5 architecture",
148 .dependencies = featureSet(&[_]Feature{}),
149 };
150 result[@enumToInt(Feature.v55)] = .{
151 .llvm_name = "v55",
152 .description = "Enable Hexagon V55 architecture",
153 .dependencies = featureSet(&[_]Feature{}),
154 };
155 result[@enumToInt(Feature.v60)] = .{
156 .llvm_name = "v60",
157 .description = "Enable Hexagon V60 architecture",
158 .dependencies = featureSet(&[_]Feature{}),
159 };
160 result[@enumToInt(Feature.v62)] = .{
161 .llvm_name = "v62",
162 .description = "Enable Hexagon V62 architecture",
163 .dependencies = featureSet(&[_]Feature{}),
164 };
165 result[@enumToInt(Feature.v65)] = .{
166 .llvm_name = "v65",
167 .description = "Enable Hexagon V65 architecture",
168 .dependencies = featureSet(&[_]Feature{}),
169 };
170 result[@enumToInt(Feature.v66)] = .{
171 .llvm_name = "v66",
172 .description = "Enable Hexagon V66 architecture",
173 .dependencies = featureSet(&[_]Feature{}),
174 };
175 result[@enumToInt(Feature.zreg)] = .{
176 .llvm_name = "zreg",
177 .description = "Hexagon ZReg extension instructions",
178 .dependencies = featureSet(&[_]Feature{}),
179 };
180 const ti = @typeInfo(Feature);
181 for (result) |*elem, i| {
182 elem.index = i;
183 elem.name = ti.Enum.fields[i].name;
184 }
185 break :blk result;
186};
187
188pub const cpu = struct {
189 pub const generic = Cpu{
190 .name = "generic",
191 .llvm_name = "generic",
192 .features = featureSet(&[_]Feature{
193 .duplex,
194 .memops,
195 .nvj,
196 .nvs,
197 .packets,
198 .small_data,
199 .v5,
200 .v55,
201 .v60,
202 }),
203 };
204 pub const hexagonv5 = Cpu{
205 .name = "hexagonv5",
206 .llvm_name = "hexagonv5",
207 .features = featureSet(&[_]Feature{
208 .duplex,
209 .memops,
210 .nvj,
211 .nvs,
212 .packets,
213 .small_data,
214 .v5,
215 }),
216 };
217 pub const hexagonv55 = Cpu{
218 .name = "hexagonv55",
219 .llvm_name = "hexagonv55",
220 .features = featureSet(&[_]Feature{
221 .duplex,
222 .memops,
223 .nvj,
224 .nvs,
225 .packets,
226 .small_data,
227 .v5,
228 .v55,
229 }),
230 };
231 pub const hexagonv60 = Cpu{
232 .name = "hexagonv60",
233 .llvm_name = "hexagonv60",
234 .features = featureSet(&[_]Feature{
235 .duplex,
236 .memops,
237 .nvj,
238 .nvs,
239 .packets,
240 .small_data,
241 .v5,
242 .v55,
243 .v60,
244 }),
245 };
246 pub const hexagonv62 = Cpu{
247 .name = "hexagonv62",
248 .llvm_name = "hexagonv62",
249 .features = featureSet(&[_]Feature{
250 .duplex,
251 .memops,
252 .nvj,
253 .nvs,
254 .packets,
255 .small_data,
256 .v5,
257 .v55,
258 .v60,
259 .v62,
260 }),
261 };
262 pub const hexagonv65 = Cpu{
263 .name = "hexagonv65",
264 .llvm_name = "hexagonv65",
265 .features = featureSet(&[_]Feature{
266 .duplex,
267 .mem_noshuf,
268 .memops,
269 .nvj,
270 .nvs,
271 .packets,
272 .small_data,
273 .v5,
274 .v55,
275 .v60,
276 .v62,
277 .v65,
278 }),
279 };
280 pub const hexagonv66 = Cpu{
281 .name = "hexagonv66",
282 .llvm_name = "hexagonv66",
283 .features = featureSet(&[_]Feature{
284 .duplex,
285 .mem_noshuf,
286 .memops,
287 .nvj,
288 .nvs,
289 .packets,
290 .small_data,
291 .v5,
292 .v55,
293 .v60,
294 .v62,
295 .v65,
296 .v66,
297 }),
298 };
299};
300
301/// All hexagon CPUs, sorted alphabetically by name.
302/// TODO: Replace this with usage of `std.meta.declList`. It does work, but stage1
303/// compiler has inefficient memory and CPU usage, affecting build times.
304pub const all_cpus = &[_]*const Cpu{
305 &cpu.generic,
306 &cpu.hexagonv5,
307 &cpu.hexagonv55,
308 &cpu.hexagonv60,
309 &cpu.hexagonv62,
310 &cpu.hexagonv65,
311 &cpu.hexagonv66,
312};
lib/std/target/mips.zig created+518
...@@ -0,0 +1,518 @@
1const std = @import("../std.zig");
2const Cpu = std.Target.Cpu;
3
4pub const Feature = enum {
5 abs2008,
6 cnmips,
7 crc,
8 dsp,
9 dspr2,
10 dspr3,
11 eva,
12 fp64,
13 fpxx,
14 ginv,
15 gp64,
16 long_calls,
17 micromips,
18 mips1,
19 mips16,
20 mips2,
21 mips3,
22 mips32,
23 mips32r2,
24 mips32r3,
25 mips32r5,
26 mips32r6,
27 mips3_32,
28 mips3_32r2,
29 mips4,
30 mips4_32,
31 mips4_32r2,
32 mips5,
33 mips5_32r2,
34 mips64,
35 mips64r2,
36 mips64r3,
37 mips64r5,
38 mips64r6,
39 msa,
40 mt,
41 nan2008,
42 noabicalls,
43 nomadd4,
44 nooddspreg,
45 p5600,
46 ptr64,
47 single_float,
48 soft_float,
49 sym32,
50 use_indirect_jump_hazard,
51 use_tcc_in_div,
52 vfpu,
53 virt,
54};
55
56pub usingnamespace Cpu.Feature.feature_set_fns(Feature);
57
58pub const all_features = blk: {
59 const len = @typeInfo(Feature).Enum.fields.len;
60 std.debug.assert(len <= Cpu.Feature.Set.needed_bit_count);
61 var result: [len]Cpu.Feature = undefined;
62 result[@enumToInt(Feature.abs2008)] = .{
63 .llvm_name = "abs2008",
64 .description = "Disable IEEE 754-2008 abs.fmt mode",
65 .dependencies = featureSet(&[_]Feature{}),
66 };
67 result[@enumToInt(Feature.cnmips)] = .{
68 .llvm_name = "cnmips",
69 .description = "Octeon cnMIPS Support",
70 .dependencies = featureSet(&[_]Feature{
71 .mips64r2,
72 }),
73 };
74 result[@enumToInt(Feature.crc)] = .{
75 .llvm_name = "crc",
76 .description = "Mips R6 CRC ASE",
77 .dependencies = featureSet(&[_]Feature{}),
78 };
79 result[@enumToInt(Feature.dsp)] = .{
80 .llvm_name = "dsp",
81 .description = "Mips DSP ASE",
82 .dependencies = featureSet(&[_]Feature{}),
83 };
84 result[@enumToInt(Feature.dspr2)] = .{
85 .llvm_name = "dspr2",
86 .description = "Mips DSP-R2 ASE",
87 .dependencies = featureSet(&[_]Feature{
88 .dsp,
89 }),
90 };
91 result[@enumToInt(Feature.dspr3)] = .{
92 .llvm_name = "dspr3",
93 .description = "Mips DSP-R3 ASE",
94 .dependencies = featureSet(&[_]Feature{
95 .dsp,
96 .dspr2,
97 }),
98 };
99 result[@enumToInt(Feature.eva)] = .{
100 .llvm_name = "eva",
101 .description = "Mips EVA ASE",
102 .dependencies = featureSet(&[_]Feature{}),
103 };
104 result[@enumToInt(Feature.fp64)] = .{
105 .llvm_name = "fp64",
106 .description = "Support 64-bit FP registers",
107 .dependencies = featureSet(&[_]Feature{}),
108 };
109 result[@enumToInt(Feature.fpxx)] = .{
110 .llvm_name = "fpxx",
111 .description = "Support for FPXX",
112 .dependencies = featureSet(&[_]Feature{}),
113 };
114 result[@enumToInt(Feature.ginv)] = .{
115 .llvm_name = "ginv",
116 .description = "Mips Global Invalidate ASE",
117 .dependencies = featureSet(&[_]Feature{}),
118 };
119 result[@enumToInt(Feature.gp64)] = .{
120 .llvm_name = "gp64",
121 .description = "General Purpose Registers are 64-bit wide",
122 .dependencies = featureSet(&[_]Feature{}),
123 };
124 result[@enumToInt(Feature.long_calls)] = .{
125 .llvm_name = "long-calls",
126 .description = "Disable use of the jal instruction",
127 .dependencies = featureSet(&[_]Feature{}),
128 };
129 result[@enumToInt(Feature.micromips)] = .{
130 .llvm_name = "micromips",
131 .description = "microMips mode",
132 .dependencies = featureSet(&[_]Feature{}),
133 };
134 result[@enumToInt(Feature.mips1)] = .{
135 .llvm_name = "mips1",
136 .description = "Mips I ISA Support [highly experimental]",
137 .dependencies = featureSet(&[_]Feature{}),
138 };
139 result[@enumToInt(Feature.mips16)] = .{
140 .llvm_name = "mips16",
141 .description = "Mips16 mode",
142 .dependencies = featureSet(&[_]Feature{}),
143 };
144 result[@enumToInt(Feature.mips2)] = .{
145 .llvm_name = "mips2",
146 .description = "Mips II ISA Support [highly experimental]",
147 .dependencies = featureSet(&[_]Feature{
148 .mips1,
149 }),
150 };
151 result[@enumToInt(Feature.mips3)] = .{
152 .llvm_name = "mips3",
153 .description = "MIPS III ISA Support [highly experimental]",
154 .dependencies = featureSet(&[_]Feature{
155 .fp64,
156 .gp64,
157 .mips2,
158 .mips3_32,
159 .mips3_32r2,
160 }),
161 };
162 result[@enumToInt(Feature.mips32)] = .{
163 .llvm_name = "mips32",
164 .description = "Mips32 ISA Support",
165 .dependencies = featureSet(&[_]Feature{
166 .mips2,
167 .mips3_32,
168 .mips4_32,
169 }),
170 };
171 result[@enumToInt(Feature.mips32r2)] = .{
172 .llvm_name = "mips32r2",
173 .description = "Mips32r2 ISA Support",
174 .dependencies = featureSet(&[_]Feature{
175 .mips32,
176 .mips3_32r2,
177 .mips4_32r2,
178 .mips5_32r2,
179 }),
180 };
181 result[@enumToInt(Feature.mips32r3)] = .{
182 .llvm_name = "mips32r3",
183 .description = "Mips32r3 ISA Support",
184 .dependencies = featureSet(&[_]Feature{
185 .mips32r2,
186 }),
187 };
188 result[@enumToInt(Feature.mips32r5)] = .{
189 .llvm_name = "mips32r5",
190 .description = "Mips32r5 ISA Support",
191 .dependencies = featureSet(&[_]Feature{
192 .mips32r3,
193 }),
194 };
195 result[@enumToInt(Feature.mips32r6)] = .{
196 .llvm_name = "mips32r6",
197 .description = "Mips32r6 ISA Support [experimental]",
198 .dependencies = featureSet(&[_]Feature{
199 .abs2008,
200 .fp64,
201 .mips32r5,
202 .nan2008,
203 }),
204 };
205 result[@enumToInt(Feature.mips3_32)] = .{
206 .llvm_name = "mips3_32",
207 .description = "Subset of MIPS-III that is also in MIPS32 [highly experimental]",
208 .dependencies = featureSet(&[_]Feature{}),
209 };
210 result[@enumToInt(Feature.mips3_32r2)] = .{
211 .llvm_name = "mips3_32r2",
212 .description = "Subset of MIPS-III that is also in MIPS32r2 [highly experimental]",
213 .dependencies = featureSet(&[_]Feature{}),
214 };
215 result[@enumToInt(Feature.mips4)] = .{
216 .llvm_name = "mips4",
217 .description = "MIPS IV ISA Support",
218 .dependencies = featureSet(&[_]Feature{
219 .mips3,
220 .mips4_32,
221 .mips4_32r2,
222 }),
223 };
224 result[@enumToInt(Feature.mips4_32)] = .{
225 .llvm_name = "mips4_32",
226 .description = "Subset of MIPS-IV that is also in MIPS32 [highly experimental]",
227 .dependencies = featureSet(&[_]Feature{}),
228 };
229 result[@enumToInt(Feature.mips4_32r2)] = .{
230 .llvm_name = "mips4_32r2",
231 .description = "Subset of MIPS-IV that is also in MIPS32r2 [highly experimental]",
232 .dependencies = featureSet(&[_]Feature{}),
233 };
234 result[@enumToInt(Feature.mips5)] = .{
235 .llvm_name = "mips5",
236 .description = "MIPS V ISA Support [highly experimental]",
237 .dependencies = featureSet(&[_]Feature{
238 .mips4,
239 .mips5_32r2,
240 }),
241 };
242 result[@enumToInt(Feature.mips5_32r2)] = .{
243 .llvm_name = "mips5_32r2",
244 .description = "Subset of MIPS-V that is also in MIPS32r2 [highly experimental]",
245 .dependencies = featureSet(&[_]Feature{}),
246 };
247 result[@enumToInt(Feature.mips64)] = .{
248 .llvm_name = "mips64",
249 .description = "Mips64 ISA Support",
250 .dependencies = featureSet(&[_]Feature{
251 .mips32,
252 .mips5,
253 }),
254 };
255 result[@enumToInt(Feature.mips64r2)] = .{
256 .llvm_name = "mips64r2",
257 .description = "Mips64r2 ISA Support",
258 .dependencies = featureSet(&[_]Feature{
259 .mips32r2,
260 .mips64,
261 }),
262 };
263 result[@enumToInt(Feature.mips64r3)] = .{
264 .llvm_name = "mips64r3",
265 .description = "Mips64r3 ISA Support",
266 .dependencies = featureSet(&[_]Feature{
267 .mips32r3,
268 .mips64r2,
269 }),
270 };
271 result[@enumToInt(Feature.mips64r5)] = .{
272 .llvm_name = "mips64r5",
273 .description = "Mips64r5 ISA Support",
274 .dependencies = featureSet(&[_]Feature{
275 .mips32r5,
276 .mips64r3,
277 }),
278 };
279 result[@enumToInt(Feature.mips64r6)] = .{
280 .llvm_name = "mips64r6",
281 .description = "Mips64r6 ISA Support [experimental]",
282 .dependencies = featureSet(&[_]Feature{
283 .abs2008,
284 .mips32r6,
285 .mips64r5,
286 .nan2008,
287 }),
288 };
289 result[@enumToInt(Feature.msa)] = .{
290 .llvm_name = "msa",
291 .description = "Mips MSA ASE",
292 .dependencies = featureSet(&[_]Feature{}),
293 };
294 result[@enumToInt(Feature.mt)] = .{
295 .llvm_name = "mt",
296 .description = "Mips MT ASE",
297 .dependencies = featureSet(&[_]Feature{}),
298 };
299 result[@enumToInt(Feature.nan2008)] = .{
300 .llvm_name = "nan2008",
301 .description = "IEEE 754-2008 NaN encoding",
302 .dependencies = featureSet(&[_]Feature{}),
303 };
304 result[@enumToInt(Feature.noabicalls)] = .{
305 .llvm_name = "noabicalls",
306 .description = "Disable SVR4-style position-independent code",
307 .dependencies = featureSet(&[_]Feature{}),
308 };
309 result[@enumToInt(Feature.nomadd4)] = .{
310 .llvm_name = "nomadd4",
311 .description = "Disable 4-operand madd.fmt and related instructions",
312 .dependencies = featureSet(&[_]Feature{}),
313 };
314 result[@enumToInt(Feature.nooddspreg)] = .{
315 .llvm_name = "nooddspreg",
316 .description = "Disable odd numbered single-precision registers",
317 .dependencies = featureSet(&[_]Feature{}),
318 };
319 result[@enumToInt(Feature.p5600)] = .{
320 .llvm_name = "p5600",
321 .description = "The P5600 Processor",
322 .dependencies = featureSet(&[_]Feature{
323 .mips32r5,
324 }),
325 };
326 result[@enumToInt(Feature.ptr64)] = .{
327 .llvm_name = "ptr64",
328 .description = "Pointers are 64-bit wide",
329 .dependencies = featureSet(&[_]Feature{}),
330 };
331 result[@enumToInt(Feature.single_float)] = .{
332 .llvm_name = "single-float",
333 .description = "Only supports single precision float",
334 .dependencies = featureSet(&[_]Feature{}),
335 };
336 result[@enumToInt(Feature.soft_float)] = .{
337 .llvm_name = "soft-float",
338 .description = "Does not support floating point instructions",
339 .dependencies = featureSet(&[_]Feature{}),
340 };
341 result[@enumToInt(Feature.sym32)] = .{
342 .llvm_name = "sym32",
343 .description = "Symbols are 32 bit on Mips64",
344 .dependencies = featureSet(&[_]Feature{}),
345 };
346 result[@enumToInt(Feature.use_indirect_jump_hazard)] = .{
347 .llvm_name = "use-indirect-jump-hazard",
348 .description = "Use indirect jump guards to prevent certain speculation based attacks",
349 .dependencies = featureSet(&[_]Feature{}),
350 };
351 result[@enumToInt(Feature.use_tcc_in_div)] = .{
352 .llvm_name = "use-tcc-in-div",
353 .description = "Force the assembler to use trapping",
354 .dependencies = featureSet(&[_]Feature{}),
355 };
356 result[@enumToInt(Feature.vfpu)] = .{
357 .llvm_name = "vfpu",
358 .description = "Enable vector FPU instructions",
359 .dependencies = featureSet(&[_]Feature{}),
360 };
361 result[@enumToInt(Feature.virt)] = .{
362 .llvm_name = "virt",
363 .description = "Mips Virtualization ASE",
364 .dependencies = featureSet(&[_]Feature{}),
365 };
366 const ti = @typeInfo(Feature);
367 for (result) |*elem, i| {
368 elem.index = i;
369 elem.name = ti.Enum.fields[i].name;
370 }
371 break :blk result;
372};
373
374pub const cpu = struct {
375 pub const mips1 = Cpu{
376 .name = "mips1",
377 .llvm_name = "mips1",
378 .features = featureSet(&[_]Feature{
379 .mips1,
380 }),
381 };
382 pub const mips2 = Cpu{
383 .name = "mips2",
384 .llvm_name = "mips2",
385 .features = featureSet(&[_]Feature{
386 .mips2,
387 }),
388 };
389 pub const mips3 = Cpu{
390 .name = "mips3",
391 .llvm_name = "mips3",
392 .features = featureSet(&[_]Feature{
393 .mips3,
394 }),
395 };
396 pub const mips32 = Cpu{
397 .name = "mips32",
398 .llvm_name = "mips32",
399 .features = featureSet(&[_]Feature{
400 .mips32,
401 }),
402 };
403 pub const mips32r2 = Cpu{
404 .name = "mips32r2",
405 .llvm_name = "mips32r2",
406 .features = featureSet(&[_]Feature{
407 .mips32r2,
408 }),
409 };
410 pub const mips32r3 = Cpu{
411 .name = "mips32r3",
412 .llvm_name = "mips32r3",
413 .features = featureSet(&[_]Feature{
414 .mips32r3,
415 }),
416 };
417 pub const mips32r5 = Cpu{
418 .name = "mips32r5",
419 .llvm_name = "mips32r5",
420 .features = featureSet(&[_]Feature{
421 .mips32r5,
422 }),
423 };
424 pub const mips32r6 = Cpu{
425 .name = "mips32r6",
426 .llvm_name = "mips32r6",
427 .features = featureSet(&[_]Feature{
428 .mips32r6,
429 }),
430 };
431 pub const mips4 = Cpu{
432 .name = "mips4",
433 .llvm_name = "mips4",
434 .features = featureSet(&[_]Feature{
435 .mips4,
436 }),
437 };
438 pub const mips5 = Cpu{
439 .name = "mips5",
440 .llvm_name = "mips5",
441 .features = featureSet(&[_]Feature{
442 .mips5,
443 }),
444 };
445 pub const mips64 = Cpu{
446 .name = "mips64",
447 .llvm_name = "mips64",
448 .features = featureSet(&[_]Feature{
449 .mips64,
450 }),
451 };
452 pub const mips64r2 = Cpu{
453 .name = "mips64r2",
454 .llvm_name = "mips64r2",
455 .features = featureSet(&[_]Feature{
456 .mips64r2,
457 }),
458 };
459 pub const mips64r3 = Cpu{
460 .name = "mips64r3",
461 .llvm_name = "mips64r3",
462 .features = featureSet(&[_]Feature{
463 .mips64r3,
464 }),
465 };
466 pub const mips64r5 = Cpu{
467 .name = "mips64r5",
468 .llvm_name = "mips64r5",
469 .features = featureSet(&[_]Feature{
470 .mips64r5,
471 }),
472 };
473 pub const mips64r6 = Cpu{
474 .name = "mips64r6",
475 .llvm_name = "mips64r6",
476 .features = featureSet(&[_]Feature{
477 .mips64r6,
478 }),
479 };
480 pub const octeon = Cpu{
481 .name = "octeon",
482 .llvm_name = "octeon",
483 .features = featureSet(&[_]Feature{
484 .cnmips,
485 .mips64r2,
486 }),
487 };
488 pub const p5600 = Cpu{
489 .name = "p5600",
490 .llvm_name = "p5600",
491 .features = featureSet(&[_]Feature{
492 .p5600,
493 }),
494 };
495};
496
497/// All mips CPUs, sorted alphabetically by name.
498/// TODO: Replace this with usage of `std.meta.declList`. It does work, but stage1
499/// compiler has inefficient memory and CPU usage, affecting build times.
500pub const all_cpus = &[_]*const Cpu{
501 &cpu.mips1,
502 &cpu.mips2,
503 &cpu.mips3,
504 &cpu.mips32,
505 &cpu.mips32r2,
506 &cpu.mips32r3,
507 &cpu.mips32r5,
508 &cpu.mips32r6,
509 &cpu.mips4,
510 &cpu.mips5,
511 &cpu.mips64,
512 &cpu.mips64r2,
513 &cpu.mips64r3,
514 &cpu.mips64r5,
515 &cpu.mips64r6,
516 &cpu.octeon,
517 &cpu.p5600,
518};
lib/std/target/msp430.zig created+72
...@@ -0,0 +1,72 @@
1const std = @import("../std.zig");
2const Cpu = std.Target.Cpu;
3
4pub const Feature = enum {
5 ext,
6 hwmult16,
7 hwmult32,
8 hwmultf5,
9};
10
11pub usingnamespace Cpu.Feature.feature_set_fns(Feature);
12
13pub const all_features = blk: {
14 const len = @typeInfo(Feature).Enum.fields.len;
15 std.debug.assert(len <= Cpu.Feature.Set.needed_bit_count);
16 var result: [len]Cpu.Feature = undefined;
17 result[@enumToInt(Feature.ext)] = .{
18 .llvm_name = "ext",
19 .description = "Enable MSP430-X extensions",
20 .dependencies = featureSet(&[_]Feature{}),
21 };
22 result[@enumToInt(Feature.hwmult16)] = .{
23 .llvm_name = "hwmult16",
24 .description = "Enable 16-bit hardware multiplier",
25 .dependencies = featureSet(&[_]Feature{}),
26 };
27 result[@enumToInt(Feature.hwmult32)] = .{
28 .llvm_name = "hwmult32",
29 .description = "Enable 32-bit hardware multiplier",
30 .dependencies = featureSet(&[_]Feature{}),
31 };
32 result[@enumToInt(Feature.hwmultf5)] = .{
33 .llvm_name = "hwmultf5",
34 .description = "Enable F5 series hardware multiplier",
35 .dependencies = featureSet(&[_]Feature{}),
36 };
37 const ti = @typeInfo(Feature);
38 for (result) |*elem, i| {
39 elem.index = i;
40 elem.name = ti.Enum.fields[i].name;
41 }
42 break :blk result;
43};
44
45pub const cpu = struct {
46 pub const generic = Cpu{
47 .name = "generic",
48 .llvm_name = "generic",
49 .features = featureSet(&[_]Feature{}),
50 };
51 pub const msp430 = Cpu{
52 .name = "msp430",
53 .llvm_name = "msp430",
54 .features = featureSet(&[_]Feature{}),
55 };
56 pub const msp430x = Cpu{
57 .name = "msp430x",
58 .llvm_name = "msp430x",
59 .features = featureSet(&[_]Feature{
60 .ext,
61 }),
62 };
63};
64
65/// All msp430 CPUs, sorted alphabetically by name.
66/// TODO: Replace this with usage of `std.meta.declList`. It does work, but stage1
67/// compiler has inefficient memory and CPU usage, affecting build times.
68pub const all_cpus = &[_]*const Cpu{
69 &cpu.generic,
70 &cpu.msp430,
71 &cpu.msp430x,
72};
lib/std/target/nvptx.zig created+309
...@@ -0,0 +1,309 @@
1const std = @import("../std.zig");
2const Cpu = std.Target.Cpu;
3
4pub const Feature = enum {
5 ptx32,
6 ptx40,
7 ptx41,
8 ptx42,
9 ptx43,
10 ptx50,
11 ptx60,
12 ptx61,
13 ptx63,
14 ptx64,
15 sm_20,
16 sm_21,
17 sm_30,
18 sm_32,
19 sm_35,
20 sm_37,
21 sm_50,
22 sm_52,
23 sm_53,
24 sm_60,
25 sm_61,
26 sm_62,
27 sm_70,
28 sm_72,
29 sm_75,
30};
31
32pub usingnamespace Cpu.Feature.feature_set_fns(Feature);
33
34pub const all_features = blk: {
35 const len = @typeInfo(Feature).Enum.fields.len;
36 std.debug.assert(len <= Cpu.Feature.Set.needed_bit_count);
37 var result: [len]Cpu.Feature = undefined;
38 result[@enumToInt(Feature.ptx32)] = .{
39 .llvm_name = "ptx32",
40 .description = "Use PTX version 3.2",
41 .dependencies = featureSet(&[_]Feature{}),
42 };
43 result[@enumToInt(Feature.ptx40)] = .{
44 .llvm_name = "ptx40",
45 .description = "Use PTX version 4.0",
46 .dependencies = featureSet(&[_]Feature{}),
47 };
48 result[@enumToInt(Feature.ptx41)] = .{
49 .llvm_name = "ptx41",
50 .description = "Use PTX version 4.1",
51 .dependencies = featureSet(&[_]Feature{}),
52 };
53 result[@enumToInt(Feature.ptx42)] = .{
54 .llvm_name = "ptx42",
55 .description = "Use PTX version 4.2",
56 .dependencies = featureSet(&[_]Feature{}),
57 };
58 result[@enumToInt(Feature.ptx43)] = .{
59 .llvm_name = "ptx43",
60 .description = "Use PTX version 4.3",
61 .dependencies = featureSet(&[_]Feature{}),
62 };
63 result[@enumToInt(Feature.ptx50)] = .{
64 .llvm_name = "ptx50",
65 .description = "Use PTX version 5.0",
66 .dependencies = featureSet(&[_]Feature{}),
67 };
68 result[@enumToInt(Feature.ptx60)] = .{
69 .llvm_name = "ptx60",
70 .description = "Use PTX version 6.0",
71 .dependencies = featureSet(&[_]Feature{}),
72 };
73 result[@enumToInt(Feature.ptx61)] = .{
74 .llvm_name = "ptx61",
75 .description = "Use PTX version 6.1",
76 .dependencies = featureSet(&[_]Feature{}),
77 };
78 result[@enumToInt(Feature.ptx63)] = .{
79 .llvm_name = "ptx63",
80 .description = "Use PTX version 6.3",
81 .dependencies = featureSet(&[_]Feature{}),
82 };
83 result[@enumToInt(Feature.ptx64)] = .{
84 .llvm_name = "ptx64",
85 .description = "Use PTX version 6.4",
86 .dependencies = featureSet(&[_]Feature{}),
87 };
88 result[@enumToInt(Feature.sm_20)] = .{
89 .llvm_name = "sm_20",
90 .description = "Target SM 2.0",
91 .dependencies = featureSet(&[_]Feature{}),
92 };
93 result[@enumToInt(Feature.sm_21)] = .{
94 .llvm_name = "sm_21",
95 .description = "Target SM 2.1",
96 .dependencies = featureSet(&[_]Feature{}),
97 };
98 result[@enumToInt(Feature.sm_30)] = .{
99 .llvm_name = "sm_30",
100 .description = "Target SM 3.0",
101 .dependencies = featureSet(&[_]Feature{}),
102 };
103 result[@enumToInt(Feature.sm_32)] = .{
104 .llvm_name = "sm_32",
105 .description = "Target SM 3.2",
106 .dependencies = featureSet(&[_]Feature{}),
107 };
108 result[@enumToInt(Feature.sm_35)] = .{
109 .llvm_name = "sm_35",
110 .description = "Target SM 3.5",
111 .dependencies = featureSet(&[_]Feature{}),
112 };
113 result[@enumToInt(Feature.sm_37)] = .{
114 .llvm_name = "sm_37",
115 .description = "Target SM 3.7",
116 .dependencies = featureSet(&[_]Feature{}),
117 };
118 result[@enumToInt(Feature.sm_50)] = .{
119 .llvm_name = "sm_50",
120 .description = "Target SM 5.0",
121 .dependencies = featureSet(&[_]Feature{}),
122 };
123 result[@enumToInt(Feature.sm_52)] = .{
124 .llvm_name = "sm_52",
125 .description = "Target SM 5.2",
126 .dependencies = featureSet(&[_]Feature{}),
127 };
128 result[@enumToInt(Feature.sm_53)] = .{
129 .llvm_name = "sm_53",
130 .description = "Target SM 5.3",
131 .dependencies = featureSet(&[_]Feature{}),
132 };
133 result[@enumToInt(Feature.sm_60)] = .{
134 .llvm_name = "sm_60",
135 .description = "Target SM 6.0",
136 .dependencies = featureSet(&[_]Feature{}),
137 };
138 result[@enumToInt(Feature.sm_61)] = .{
139 .llvm_name = "sm_61",
140 .description = "Target SM 6.1",
141 .dependencies = featureSet(&[_]Feature{}),
142 };
143 result[@enumToInt(Feature.sm_62)] = .{
144 .llvm_name = "sm_62",
145 .description = "Target SM 6.2",
146 .dependencies = featureSet(&[_]Feature{}),
147 };
148 result[@enumToInt(Feature.sm_70)] = .{
149 .llvm_name = "sm_70",
150 .description = "Target SM 7.0",
151 .dependencies = featureSet(&[_]Feature{}),
152 };
153 result[@enumToInt(Feature.sm_72)] = .{
154 .llvm_name = "sm_72",
155 .description = "Target SM 7.2",
156 .dependencies = featureSet(&[_]Feature{}),
157 };
158 result[@enumToInt(Feature.sm_75)] = .{
159 .llvm_name = "sm_75",
160 .description = "Target SM 7.5",
161 .dependencies = featureSet(&[_]Feature{}),
162 };
163 const ti = @typeInfo(Feature);
164 for (result) |*elem, i| {
165 elem.index = i;
166 elem.name = ti.Enum.fields[i].name;
167 }
168 break :blk result;
169};
170
171pub const cpu = struct {
172 pub const sm_20 = Cpu{
173 .name = "sm_20",
174 .llvm_name = "sm_20",
175 .features = featureSet(&[_]Feature{
176 .sm_20,
177 }),
178 };
179 pub const sm_21 = Cpu{
180 .name = "sm_21",
181 .llvm_name = "sm_21",
182 .features = featureSet(&[_]Feature{
183 .sm_21,
184 }),
185 };
186 pub const sm_30 = Cpu{
187 .name = "sm_30",
188 .llvm_name = "sm_30",
189 .features = featureSet(&[_]Feature{
190 .sm_30,
191 }),
192 };
193 pub const sm_32 = Cpu{
194 .name = "sm_32",
195 .llvm_name = "sm_32",
196 .features = featureSet(&[_]Feature{
197 .ptx40,
198 .sm_32,
199 }),
200 };
201 pub const sm_35 = Cpu{
202 .name = "sm_35",
203 .llvm_name = "sm_35",
204 .features = featureSet(&[_]Feature{
205 .sm_35,
206 }),
207 };
208 pub const sm_37 = Cpu{
209 .name = "sm_37",
210 .llvm_name = "sm_37",
211 .features = featureSet(&[_]Feature{
212 .ptx41,
213 .sm_37,
214 }),
215 };
216 pub const sm_50 = Cpu{
217 .name = "sm_50",
218 .llvm_name = "sm_50",
219 .features = featureSet(&[_]Feature{
220 .ptx40,
221 .sm_50,
222 }),
223 };
224 pub const sm_52 = Cpu{
225 .name = "sm_52",
226 .llvm_name = "sm_52",
227 .features = featureSet(&[_]Feature{
228 .ptx41,
229 .sm_52,
230 }),
231 };
232 pub const sm_53 = Cpu{
233 .name = "sm_53",
234 .llvm_name = "sm_53",
235 .features = featureSet(&[_]Feature{
236 .ptx42,
237 .sm_53,
238 }),
239 };
240 pub const sm_60 = Cpu{
241 .name = "sm_60",
242 .llvm_name = "sm_60",
243 .features = featureSet(&[_]Feature{
244 .ptx50,
245 .sm_60,
246 }),
247 };
248 pub const sm_61 = Cpu{
249 .name = "sm_61",
250 .llvm_name = "sm_61",
251 .features = featureSet(&[_]Feature{
252 .ptx50,
253 .sm_61,
254 }),
255 };
256 pub const sm_62 = Cpu{
257 .name = "sm_62",
258 .llvm_name = "sm_62",
259 .features = featureSet(&[_]Feature{
260 .ptx50,
261 .sm_62,
262 }),
263 };
264 pub const sm_70 = Cpu{
265 .name = "sm_70",
266 .llvm_name = "sm_70",
267 .features = featureSet(&[_]Feature{
268 .ptx60,
269 .sm_70,
270 }),
271 };
272 pub const sm_72 = Cpu{
273 .name = "sm_72",
274 .llvm_name = "sm_72",
275 .features = featureSet(&[_]Feature{
276 .ptx61,
277 .sm_72,
278 }),
279 };
280 pub const sm_75 = Cpu{
281 .name = "sm_75",
282 .llvm_name = "sm_75",
283 .features = featureSet(&[_]Feature{
284 .ptx63,
285 .sm_75,
286 }),
287 };
288};
289
290/// All nvptx CPUs, sorted alphabetically by name.
291/// TODO: Replace this with usage of `std.meta.declList`. It does work, but stage1
292/// compiler has inefficient memory and CPU usage, affecting build times.
293pub const all_cpus = &[_]*const Cpu{
294 &cpu.sm_20,
295 &cpu.sm_21,
296 &cpu.sm_30,
297 &cpu.sm_32,
298 &cpu.sm_35,
299 &cpu.sm_37,
300 &cpu.sm_50,
301 &cpu.sm_52,
302 &cpu.sm_53,
303 &cpu.sm_60,
304 &cpu.sm_61,
305 &cpu.sm_62,
306 &cpu.sm_70,
307 &cpu.sm_72,
308 &cpu.sm_75,
309};
lib/std/target/powerpc.zig created+938
...@@ -0,0 +1,938 @@
1const std = @import("../std.zig");
2const Cpu = std.Target.Cpu;
3
4pub const Feature = enum {
5 @"64bit",
6 @"64bitregs",
7 altivec,
8 booke,
9 bpermd,
10 cmpb,
11 crbits,
12 crypto,
13 direct_move,
14 e500,
15 extdiv,
16 fcpsgn,
17 float128,
18 fpcvt,
19 fprnd,
20 fpu,
21 fre,
22 fres,
23 frsqrte,
24 frsqrtes,
25 fsqrt,
26 hard_float,
27 htm,
28 icbt,
29 invariant_function_descriptors,
30 isa_v30_instructions,
31 isel,
32 ldbrx,
33 lfiwax,
34 longcall,
35 mfocrf,
36 msync,
37 partword_atomics,
38 popcntd,
39 power8_altivec,
40 power8_vector,
41 power9_altivec,
42 power9_vector,
43 ppc_postra_sched,
44 ppc_prera_sched,
45 ppc4xx,
46 ppc6xx,
47 qpx,
48 recipprec,
49 secure_plt,
50 slow_popcntd,
51 spe,
52 stfiwx,
53 two_const_nr,
54 vectors_use_two_units,
55 vsx,
56};
57
58pub usingnamespace Cpu.Feature.feature_set_fns(Feature);
59
60pub const all_features = blk: {
61 const len = @typeInfo(Feature).Enum.fields.len;
62 std.debug.assert(len <= Cpu.Feature.Set.needed_bit_count);
63 var result: [len]Cpu.Feature = undefined;
64 result[@enumToInt(Feature.@"64bit")] = .{
65 .llvm_name = "64bit",
66 .description = "Enable 64-bit instructions",
67 .dependencies = featureSet(&[_]Feature{}),
68 };
69 result[@enumToInt(Feature.@"64bitregs")] = .{
70 .llvm_name = "64bitregs",
71 .description = "Enable 64-bit registers usage for ppc32 [beta]",
72 .dependencies = featureSet(&[_]Feature{}),
73 };
74 result[@enumToInt(Feature.altivec)] = .{
75 .llvm_name = "altivec",
76 .description = "Enable Altivec instructions",
77 .dependencies = featureSet(&[_]Feature{
78 .fpu,
79 }),
80 };
81 result[@enumToInt(Feature.booke)] = .{
82 .llvm_name = "booke",
83 .description = "Enable Book E instructions",
84 .dependencies = featureSet(&[_]Feature{
85 .icbt,
86 }),
87 };
88 result[@enumToInt(Feature.bpermd)] = .{
89 .llvm_name = "bpermd",
90 .description = "Enable the bpermd instruction",
91 .dependencies = featureSet(&[_]Feature{}),
92 };
93 result[@enumToInt(Feature.cmpb)] = .{
94 .llvm_name = "cmpb",
95 .description = "Enable the cmpb instruction",
96 .dependencies = featureSet(&[_]Feature{}),
97 };
98 result[@enumToInt(Feature.crbits)] = .{
99 .llvm_name = "crbits",
100 .description = "Use condition-register bits individually",
101 .dependencies = featureSet(&[_]Feature{}),
102 };
103 result[@enumToInt(Feature.crypto)] = .{
104 .llvm_name = "crypto",
105 .description = "Enable POWER8 Crypto instructions",
106 .dependencies = featureSet(&[_]Feature{
107 .power8_altivec,
108 }),
109 };
110 result[@enumToInt(Feature.direct_move)] = .{
111 .llvm_name = "direct-move",
112 .description = "Enable Power8 direct move instructions",
113 .dependencies = featureSet(&[_]Feature{
114 .vsx,
115 }),
116 };
117 result[@enumToInt(Feature.e500)] = .{
118 .llvm_name = "e500",
119 .description = "Enable E500/E500mc instructions",
120 .dependencies = featureSet(&[_]Feature{}),
121 };
122 result[@enumToInt(Feature.extdiv)] = .{
123 .llvm_name = "extdiv",
124 .description = "Enable extended divide instructions",
125 .dependencies = featureSet(&[_]Feature{}),
126 };
127 result[@enumToInt(Feature.fcpsgn)] = .{
128 .llvm_name = "fcpsgn",
129 .description = "Enable the fcpsgn instruction",
130 .dependencies = featureSet(&[_]Feature{
131 .fpu,
132 }),
133 };
134 result[@enumToInt(Feature.float128)] = .{
135 .llvm_name = "float128",
136 .description = "Enable the __float128 data type for IEEE-754R Binary128.",
137 .dependencies = featureSet(&[_]Feature{
138 .vsx,
139 }),
140 };
141 result[@enumToInt(Feature.fpcvt)] = .{
142 .llvm_name = "fpcvt",
143 .description = "Enable fc[ft]* (unsigned and single-precision) and lfiwzx instructions",
144 .dependencies = featureSet(&[_]Feature{
145 .fpu,
146 }),
147 };
148 result[@enumToInt(Feature.fprnd)] = .{
149 .llvm_name = "fprnd",
150 .description = "Enable the fri[mnpz] instructions",
151 .dependencies = featureSet(&[_]Feature{
152 .fpu,
153 }),
154 };
155 result[@enumToInt(Feature.fpu)] = .{
156 .llvm_name = "fpu",
157 .description = "Enable classic FPU instructions",
158 .dependencies = featureSet(&[_]Feature{
159 .hard_float,
160 }),
161 };
162 result[@enumToInt(Feature.fre)] = .{
163 .llvm_name = "fre",
164 .description = "Enable the fre instruction",
165 .dependencies = featureSet(&[_]Feature{
166 .fpu,
167 }),
168 };
169 result[@enumToInt(Feature.fres)] = .{
170 .llvm_name = "fres",
171 .description = "Enable the fres instruction",
172 .dependencies = featureSet(&[_]Feature{
173 .fpu,
174 }),
175 };
176 result[@enumToInt(Feature.frsqrte)] = .{
177 .llvm_name = "frsqrte",
178 .description = "Enable the frsqrte instruction",
179 .dependencies = featureSet(&[_]Feature{
180 .fpu,
181 }),
182 };
183 result[@enumToInt(Feature.frsqrtes)] = .{
184 .llvm_name = "frsqrtes",
185 .description = "Enable the frsqrtes instruction",
186 .dependencies = featureSet(&[_]Feature{
187 .fpu,
188 }),
189 };
190 result[@enumToInt(Feature.fsqrt)] = .{
191 .llvm_name = "fsqrt",
192 .description = "Enable the fsqrt instruction",
193 .dependencies = featureSet(&[_]Feature{
194 .fpu,
195 }),
196 };
197 result[@enumToInt(Feature.hard_float)] = .{
198 .llvm_name = "hard-float",
199 .description = "Enable floating-point instructions",
200 .dependencies = featureSet(&[_]Feature{}),
201 };
202 result[@enumToInt(Feature.htm)] = .{
203 .llvm_name = "htm",
204 .description = "Enable Hardware Transactional Memory instructions",
205 .dependencies = featureSet(&[_]Feature{}),
206 };
207 result[@enumToInt(Feature.icbt)] = .{
208 .llvm_name = "icbt",
209 .description = "Enable icbt instruction",
210 .dependencies = featureSet(&[_]Feature{}),
211 };
212 result[@enumToInt(Feature.invariant_function_descriptors)] = .{
213 .llvm_name = "invariant-function-descriptors",
214 .description = "Assume function descriptors are invariant",
215 .dependencies = featureSet(&[_]Feature{}),
216 };
217 result[@enumToInt(Feature.isa_v30_instructions)] = .{
218 .llvm_name = "isa-v30-instructions",
219 .description = "Enable instructions added in ISA 3.0.",
220 .dependencies = featureSet(&[_]Feature{}),
221 };
222 result[@enumToInt(Feature.isel)] = .{
223 .llvm_name = "isel",
224 .description = "Enable the isel instruction",
225 .dependencies = featureSet(&[_]Feature{}),
226 };
227 result[@enumToInt(Feature.ldbrx)] = .{
228 .llvm_name = "ldbrx",
229 .description = "Enable the ldbrx instruction",
230 .dependencies = featureSet(&[_]Feature{}),
231 };
232 result[@enumToInt(Feature.lfiwax)] = .{
233 .llvm_name = "lfiwax",
234 .description = "Enable the lfiwax instruction",
235 .dependencies = featureSet(&[_]Feature{
236 .fpu,
237 }),
238 };
239 result[@enumToInt(Feature.longcall)] = .{
240 .llvm_name = "longcall",
241 .description = "Always use indirect calls",
242 .dependencies = featureSet(&[_]Feature{}),
243 };
244 result[@enumToInt(Feature.mfocrf)] = .{
245 .llvm_name = "mfocrf",
246 .description = "Enable the MFOCRF instruction",
247 .dependencies = featureSet(&[_]Feature{}),
248 };
249 result[@enumToInt(Feature.msync)] = .{
250 .llvm_name = "msync",
251 .description = "Has only the msync instruction instead of sync",
252 .dependencies = featureSet(&[_]Feature{
253 .booke,
254 }),
255 };
256 result[@enumToInt(Feature.partword_atomics)] = .{
257 .llvm_name = "partword-atomics",
258 .description = "Enable l[bh]arx and st[bh]cx.",
259 .dependencies = featureSet(&[_]Feature{}),
260 };
261 result[@enumToInt(Feature.popcntd)] = .{
262 .llvm_name = "popcntd",
263 .description = "Enable the popcnt[dw] instructions",
264 .dependencies = featureSet(&[_]Feature{}),
265 };
266 result[@enumToInt(Feature.power8_altivec)] = .{
267 .llvm_name = "power8-altivec",
268 .description = "Enable POWER8 Altivec instructions",
269 .dependencies = featureSet(&[_]Feature{
270 .altivec,
271 }),
272 };
273 result[@enumToInt(Feature.power8_vector)] = .{
274 .llvm_name = "power8-vector",
275 .description = "Enable POWER8 vector instructions",
276 .dependencies = featureSet(&[_]Feature{
277 .power8_altivec,
278 .vsx,
279 }),
280 };
281 result[@enumToInt(Feature.power9_altivec)] = .{
282 .llvm_name = "power9-altivec",
283 .description = "Enable POWER9 Altivec instructions",
284 .dependencies = featureSet(&[_]Feature{
285 .isa_v30_instructions,
286 .power8_altivec,
287 }),
288 };
289 result[@enumToInt(Feature.power9_vector)] = .{
290 .llvm_name = "power9-vector",
291 .description = "Enable POWER9 vector instructions",
292 .dependencies = featureSet(&[_]Feature{
293 .isa_v30_instructions,
294 .power8_vector,
295 .power9_altivec,
296 }),
297 };
298 result[@enumToInt(Feature.ppc_postra_sched)] = .{
299 .llvm_name = "ppc-postra-sched",
300 .description = "Use PowerPC post-RA scheduling strategy",
301 .dependencies = featureSet(&[_]Feature{}),
302 };
303 result[@enumToInt(Feature.ppc_prera_sched)] = .{
304 .llvm_name = "ppc-prera-sched",
305 .description = "Use PowerPC pre-RA scheduling strategy",
306 .dependencies = featureSet(&[_]Feature{}),
307 };
308 result[@enumToInt(Feature.ppc4xx)] = .{
309 .llvm_name = "ppc4xx",
310 .description = "Enable PPC 4xx instructions",
311 .dependencies = featureSet(&[_]Feature{}),
312 };
313 result[@enumToInt(Feature.ppc6xx)] = .{
314 .llvm_name = "ppc6xx",
315 .description = "Enable PPC 6xx instructions",
316 .dependencies = featureSet(&[_]Feature{}),
317 };
318 result[@enumToInt(Feature.qpx)] = .{
319 .llvm_name = "qpx",
320 .description = "Enable QPX instructions",
321 .dependencies = featureSet(&[_]Feature{
322 .fpu,
323 }),
324 };
325 result[@enumToInt(Feature.recipprec)] = .{
326 .llvm_name = "recipprec",
327 .description = "Assume higher precision reciprocal estimates",
328 .dependencies = featureSet(&[_]Feature{}),
329 };
330 result[@enumToInt(Feature.secure_plt)] = .{
331 .llvm_name = "secure-plt",
332 .description = "Enable secure plt mode",
333 .dependencies = featureSet(&[_]Feature{}),
334 };
335 result[@enumToInt(Feature.slow_popcntd)] = .{
336 .llvm_name = "slow-popcntd",
337 .description = "Has slow popcnt[dw] instructions",
338 .dependencies = featureSet(&[_]Feature{}),
339 };
340 result[@enumToInt(Feature.spe)] = .{
341 .llvm_name = "spe",
342 .description = "Enable SPE instructions",
343 .dependencies = featureSet(&[_]Feature{
344 .hard_float,
345 }),
346 };
347 result[@enumToInt(Feature.stfiwx)] = .{
348 .llvm_name = "stfiwx",
349 .description = "Enable the stfiwx instruction",
350 .dependencies = featureSet(&[_]Feature{
351 .fpu,
352 }),
353 };
354 result[@enumToInt(Feature.two_const_nr)] = .{
355 .llvm_name = "two-const-nr",
356 .description = "Requires two constant Newton-Raphson computation",
357 .dependencies = featureSet(&[_]Feature{}),
358 };
359 result[@enumToInt(Feature.vectors_use_two_units)] = .{
360 .llvm_name = "vectors-use-two-units",
361 .description = "Vectors use two units",
362 .dependencies = featureSet(&[_]Feature{}),
363 };
364 result[@enumToInt(Feature.vsx)] = .{
365 .llvm_name = "vsx",
366 .description = "Enable VSX instructions",
367 .dependencies = featureSet(&[_]Feature{
368 .altivec,
369 }),
370 };
371 const ti = @typeInfo(Feature);
372 for (result) |*elem, i| {
373 elem.index = i;
374 elem.name = ti.Enum.fields[i].name;
375 }
376 break :blk result;
377};
378
379pub const cpu = struct {
380 pub const @"440" = Cpu{
381 .name = "440",
382 .llvm_name = "440",
383 .features = featureSet(&[_]Feature{
384 .booke,
385 .fres,
386 .frsqrte,
387 .icbt,
388 .isel,
389 .msync,
390 }),
391 };
392 pub const @"450" = Cpu{
393 .name = "450",
394 .llvm_name = "450",
395 .features = featureSet(&[_]Feature{
396 .booke,
397 .fres,
398 .frsqrte,
399 .icbt,
400 .isel,
401 .msync,
402 }),
403 };
404 pub const @"601" = Cpu{
405 .name = "601",
406 .llvm_name = "601",
407 .features = featureSet(&[_]Feature{
408 .fpu,
409 }),
410 };
411 pub const @"602" = Cpu{
412 .name = "602",
413 .llvm_name = "602",
414 .features = featureSet(&[_]Feature{
415 .fpu,
416 }),
417 };
418 pub const @"603" = Cpu{
419 .name = "603",
420 .llvm_name = "603",
421 .features = featureSet(&[_]Feature{
422 .fres,
423 .frsqrte,
424 }),
425 };
426 pub const @"603e" = Cpu{
427 .name = "603e",
428 .llvm_name = "603e",
429 .features = featureSet(&[_]Feature{
430 .fres,
431 .frsqrte,
432 }),
433 };
434 pub const @"603ev" = Cpu{
435 .name = "603ev",
436 .llvm_name = "603ev",
437 .features = featureSet(&[_]Feature{
438 .fres,
439 .frsqrte,
440 }),
441 };
442 pub const @"604" = Cpu{
443 .name = "604",
444 .llvm_name = "604",
445 .features = featureSet(&[_]Feature{
446 .fres,
447 .frsqrte,
448 }),
449 };
450 pub const @"604e" = Cpu{
451 .name = "604e",
452 .llvm_name = "604e",
453 .features = featureSet(&[_]Feature{
454 .fres,
455 .frsqrte,
456 }),
457 };
458 pub const @"620" = Cpu{
459 .name = "620",
460 .llvm_name = "620",
461 .features = featureSet(&[_]Feature{
462 .fres,
463 .frsqrte,
464 }),
465 };
466 pub const @"7400" = Cpu{
467 .name = "7400",
468 .llvm_name = "7400",
469 .features = featureSet(&[_]Feature{
470 .altivec,
471 .fres,
472 .frsqrte,
473 }),
474 };
475 pub const @"7450" = Cpu{
476 .name = "7450",
477 .llvm_name = "7450",
478 .features = featureSet(&[_]Feature{
479 .altivec,
480 .fres,
481 .frsqrte,
482 }),
483 };
484 pub const @"750" = Cpu{
485 .name = "750",
486 .llvm_name = "750",
487 .features = featureSet(&[_]Feature{
488 .fres,
489 .frsqrte,
490 }),
491 };
492 pub const @"970" = Cpu{
493 .name = "970",
494 .llvm_name = "970",
495 .features = featureSet(&[_]Feature{
496 .@"64bit",
497 .altivec,
498 .fres,
499 .frsqrte,
500 .fsqrt,
501 .mfocrf,
502 .stfiwx,
503 }),
504 };
505 pub const a2 = Cpu{
506 .name = "a2",
507 .llvm_name = "a2",
508 .features = featureSet(&[_]Feature{
509 .@"64bit",
510 .booke,
511 .cmpb,
512 .fcpsgn,
513 .fpcvt,
514 .fprnd,
515 .fre,
516 .fres,
517 .frsqrte,
518 .frsqrtes,
519 .fsqrt,
520 .icbt,
521 .isel,
522 .ldbrx,
523 .lfiwax,
524 .mfocrf,
525 .recipprec,
526 .slow_popcntd,
527 .stfiwx,
528 }),
529 };
530 pub const a2q = Cpu{
531 .name = "a2q",
532 .llvm_name = "a2q",
533 .features = featureSet(&[_]Feature{
534 .@"64bit",
535 .booke,
536 .cmpb,
537 .fcpsgn,
538 .fpcvt,
539 .fprnd,
540 .fre,
541 .fres,
542 .frsqrte,
543 .frsqrtes,
544 .fsqrt,
545 .icbt,
546 .isel,
547 .ldbrx,
548 .lfiwax,
549 .mfocrf,
550 .qpx,
551 .recipprec,
552 .slow_popcntd,
553 .stfiwx,
554 }),
555 };
556 pub const e500 = Cpu{
557 .name = "e500",
558 .llvm_name = "e500",
559 .features = featureSet(&[_]Feature{
560 .booke,
561 .icbt,
562 .isel,
563 }),
564 };
565 pub const e500mc = Cpu{
566 .name = "e500mc",
567 .llvm_name = "e500mc",
568 .features = featureSet(&[_]Feature{
569 .booke,
570 .icbt,
571 .isel,
572 .stfiwx,
573 }),
574 };
575 pub const e5500 = Cpu{
576 .name = "e5500",
577 .llvm_name = "e5500",
578 .features = featureSet(&[_]Feature{
579 .@"64bit",
580 .booke,
581 .icbt,
582 .isel,
583 .mfocrf,
584 .stfiwx,
585 }),
586 };
587 pub const g3 = Cpu{
588 .name = "g3",
589 .llvm_name = "g3",
590 .features = featureSet(&[_]Feature{
591 .fres,
592 .frsqrte,
593 }),
594 };
595 pub const g4 = Cpu{
596 .name = "g4",
597 .llvm_name = "g4",
598 .features = featureSet(&[_]Feature{
599 .altivec,
600 .fres,
601 .frsqrte,
602 }),
603 };
604 pub const @"g4+" = Cpu{
605 .name = "g4+",
606 .llvm_name = "g4+",
607 .features = featureSet(&[_]Feature{
608 .altivec,
609 .fres,
610 .frsqrte,
611 }),
612 };
613 pub const g5 = Cpu{
614 .name = "g5",
615 .llvm_name = "g5",
616 .features = featureSet(&[_]Feature{
617 .@"64bit",
618 .altivec,
619 .fres,
620 .frsqrte,
621 .fsqrt,
622 .mfocrf,
623 .stfiwx,
624 }),
625 };
626 pub const generic = Cpu{
627 .name = "generic",
628 .llvm_name = "generic",
629 .features = featureSet(&[_]Feature{
630 .hard_float,
631 }),
632 };
633 pub const ppc = Cpu{
634 .name = "ppc",
635 .llvm_name = "ppc",
636 .features = featureSet(&[_]Feature{
637 .hard_float,
638 }),
639 };
640 pub const ppc32 = Cpu{
641 .name = "ppc32",
642 .llvm_name = "ppc32",
643 .features = featureSet(&[_]Feature{
644 .hard_float,
645 }),
646 };
647 pub const ppc64 = Cpu{
648 .name = "ppc64",
649 .llvm_name = "ppc64",
650 .features = featureSet(&[_]Feature{
651 .@"64bit",
652 .altivec,
653 .fres,
654 .frsqrte,
655 .fsqrt,
656 .mfocrf,
657 .stfiwx,
658 }),
659 };
660 pub const ppc64le = Cpu{
661 .name = "ppc64le",
662 .llvm_name = "ppc64le",
663 .features = featureSet(&[_]Feature{
664 .@"64bit",
665 .altivec,
666 .bpermd,
667 .cmpb,
668 .crypto,
669 .direct_move,
670 .extdiv,
671 .fcpsgn,
672 .fpcvt,
673 .fprnd,
674 .fre,
675 .fres,
676 .frsqrte,
677 .frsqrtes,
678 .fsqrt,
679 .htm,
680 .icbt,
681 .isel,
682 .ldbrx,
683 .lfiwax,
684 .mfocrf,
685 .partword_atomics,
686 .popcntd,
687 .power8_altivec,
688 .power8_vector,
689 .recipprec,
690 .stfiwx,
691 .two_const_nr,
692 .vsx,
693 }),
694 };
695 pub const pwr3 = Cpu{
696 .name = "pwr3",
697 .llvm_name = "pwr3",
698 .features = featureSet(&[_]Feature{
699 .@"64bit",
700 .altivec,
701 .fres,
702 .frsqrte,
703 .mfocrf,
704 .stfiwx,
705 }),
706 };
707 pub const pwr4 = Cpu{
708 .name = "pwr4",
709 .llvm_name = "pwr4",
710 .features = featureSet(&[_]Feature{
711 .@"64bit",
712 .altivec,
713 .fres,
714 .frsqrte,
715 .fsqrt,
716 .mfocrf,
717 .stfiwx,
718 }),
719 };
720 pub const pwr5 = Cpu{
721 .name = "pwr5",
722 .llvm_name = "pwr5",
723 .features = featureSet(&[_]Feature{
724 .@"64bit",
725 .altivec,
726 .fre,
727 .fres,
728 .frsqrte,
729 .frsqrtes,
730 .fsqrt,
731 .mfocrf,
732 .stfiwx,
733 }),
734 };
735 pub const pwr5x = Cpu{
736 .name = "pwr5x",
737 .llvm_name = "pwr5x",
738 .features = featureSet(&[_]Feature{
739 .@"64bit",
740 .altivec,
741 .fprnd,
742 .fre,
743 .fres,
744 .frsqrte,
745 .frsqrtes,
746 .fsqrt,
747 .mfocrf,
748 .stfiwx,
749 }),
750 };
751 pub const pwr6 = Cpu{
752 .name = "pwr6",
753 .llvm_name = "pwr6",
754 .features = featureSet(&[_]Feature{
755 .@"64bit",
756 .altivec,
757 .cmpb,
758 .fcpsgn,
759 .fprnd,
760 .fre,
761 .fres,
762 .frsqrte,
763 .frsqrtes,
764 .fsqrt,
765 .lfiwax,
766 .mfocrf,
767 .recipprec,
768 .stfiwx,
769 }),
770 };
771 pub const pwr6x = Cpu{
772 .name = "pwr6x",
773 .llvm_name = "pwr6x",
774 .features = featureSet(&[_]Feature{
775 .@"64bit",
776 .altivec,
777 .cmpb,
778 .fcpsgn,
779 .fprnd,
780 .fre,
781 .fres,
782 .frsqrte,
783 .frsqrtes,
784 .fsqrt,
785 .lfiwax,
786 .mfocrf,
787 .recipprec,
788 .stfiwx,
789 }),
790 };
791 pub const pwr7 = Cpu{
792 .name = "pwr7",
793 .llvm_name = "pwr7",
794 .features = featureSet(&[_]Feature{
795 .@"64bit",
796 .altivec,
797 .bpermd,
798 .cmpb,
799 .extdiv,
800 .fcpsgn,
801 .fpcvt,
802 .fprnd,
803 .fre,
804 .fres,
805 .frsqrte,
806 .frsqrtes,
807 .fsqrt,
808 .isel,
809 .ldbrx,
810 .lfiwax,
811 .mfocrf,
812 .popcntd,
813 .recipprec,
814 .stfiwx,
815 .two_const_nr,
816 .vsx,
817 }),
818 };
819 pub const pwr8 = Cpu{
820 .name = "pwr8",
821 .llvm_name = "pwr8",
822 .features = featureSet(&[_]Feature{
823 .@"64bit",
824 .altivec,
825 .bpermd,
826 .cmpb,
827 .crypto,
828 .direct_move,
829 .extdiv,
830 .fcpsgn,
831 .fpcvt,
832 .fprnd,
833 .fre,
834 .fres,
835 .frsqrte,
836 .frsqrtes,
837 .fsqrt,
838 .htm,
839 .icbt,
840 .isel,
841 .ldbrx,
842 .lfiwax,
843 .mfocrf,
844 .partword_atomics,
845 .popcntd,
846 .power8_altivec,
847 .power8_vector,
848 .recipprec,
849 .stfiwx,
850 .two_const_nr,
851 .vsx,
852 }),
853 };
854 pub const pwr9 = Cpu{
855 .name = "pwr9",
856 .llvm_name = "pwr9",
857 .features = featureSet(&[_]Feature{
858 .@"64bit",
859 .altivec,
860 .bpermd,
861 .cmpb,
862 .crypto,
863 .direct_move,
864 .extdiv,
865 .fcpsgn,
866 .fpcvt,
867 .fprnd,
868 .fre,
869 .fres,
870 .frsqrte,
871 .frsqrtes,
872 .fsqrt,
873 .htm,
874 .icbt,
875 .isa_v30_instructions,
876 .isel,
877 .ldbrx,
878 .lfiwax,
879 .mfocrf,
880 .partword_atomics,
881 .popcntd,
882 .power8_altivec,
883 .power8_vector,
884 .power9_altivec,
885 .power9_vector,
886 .ppc_postra_sched,
887 .ppc_prera_sched,
888 .recipprec,
889 .stfiwx,
890 .two_const_nr,
891 .vectors_use_two_units,
892 .vsx,
893 }),
894 };
895};
896
897/// All powerpc CPUs, sorted alphabetically by name.
898/// TODO: Replace this with usage of `std.meta.declList`. It does work, but stage1
899/// compiler has inefficient memory and CPU usage, affecting build times.
900pub const all_cpus = &[_]*const Cpu{
901 &cpu.@"440",
902 &cpu.@"450",
903 &cpu.@"601",
904 &cpu.@"602",
905 &cpu.@"603",
906 &cpu.@"603e",
907 &cpu.@"603ev",
908 &cpu.@"604",
909 &cpu.@"604e",
910 &cpu.@"620",
911 &cpu.@"7400",
912 &cpu.@"7450",
913 &cpu.@"750",
914 &cpu.@"970",
915 &cpu.a2,
916 &cpu.a2q,
917 &cpu.e500,
918 &cpu.e500mc,
919 &cpu.e5500,
920 &cpu.g3,
921 &cpu.g4,
922 &cpu.@"g4+",
923 &cpu.g5,
924 &cpu.generic,
925 &cpu.ppc,
926 &cpu.ppc32,
927 &cpu.ppc64,
928 &cpu.ppc64le,
929 &cpu.pwr3,
930 &cpu.pwr4,
931 &cpu.pwr5,
932 &cpu.pwr5x,
933 &cpu.pwr6,
934 &cpu.pwr6x,
935 &cpu.pwr7,
936 &cpu.pwr8,
937 &cpu.pwr9,
938};
lib/std/target/riscv.zig created+122
...@@ -0,0 +1,122 @@
1const std = @import("../std.zig");
2const Cpu = std.Target.Cpu;
3
4pub const Feature = enum {
5 @"64bit",
6 a,
7 c,
8 d,
9 e,
10 f,
11 m,
12 relax,
13};
14
15pub usingnamespace Cpu.Feature.feature_set_fns(Feature);
16
17pub const all_features = blk: {
18 const len = @typeInfo(Feature).Enum.fields.len;
19 std.debug.assert(len <= Cpu.Feature.Set.needed_bit_count);
20 var result: [len]Cpu.Feature = undefined;
21 result[@enumToInt(Feature.@"64bit")] = .{
22 .llvm_name = "64bit",
23 .description = "Implements RV64",
24 .dependencies = featureSet(&[_]Feature{}),
25 };
26 result[@enumToInt(Feature.a)] = .{
27 .llvm_name = "a",
28 .description = "'A' (Atomic Instructions)",
29 .dependencies = featureSet(&[_]Feature{}),
30 };
31 result[@enumToInt(Feature.c)] = .{
32 .llvm_name = "c",
33 .description = "'C' (Compressed Instructions)",
34 .dependencies = featureSet(&[_]Feature{}),
35 };
36 result[@enumToInt(Feature.d)] = .{
37 .llvm_name = "d",
38 .description = "'D' (Double-Precision Floating-Point)",
39 .dependencies = featureSet(&[_]Feature{
40 .f,
41 }),
42 };
43 result[@enumToInt(Feature.e)] = .{
44 .llvm_name = "e",
45 .description = "Implements RV32E (provides 16 rather than 32 GPRs)",
46 .dependencies = featureSet(&[_]Feature{}),
47 };
48 result[@enumToInt(Feature.f)] = .{
49 .llvm_name = "f",
50 .description = "'F' (Single-Precision Floating-Point)",
51 .dependencies = featureSet(&[_]Feature{}),
52 };
53 result[@enumToInt(Feature.m)] = .{
54 .llvm_name = "m",
55 .description = "'M' (Integer Multiplication and Division)",
56 .dependencies = featureSet(&[_]Feature{}),
57 };
58 result[@enumToInt(Feature.relax)] = .{
59 .llvm_name = "relax",
60 .description = "Enable Linker relaxation.",
61 .dependencies = featureSet(&[_]Feature{}),
62 };
63 const ti = @typeInfo(Feature);
64 for (result) |*elem, i| {
65 elem.index = i;
66 elem.name = ti.Enum.fields[i].name;
67 }
68 break :blk result;
69};
70
71pub const cpu = struct {
72 pub const baseline_rv32 = Cpu{
73 .name = "baseline_rv32",
74 .llvm_name = "generic-rv32",
75 .features = featureSet(&[_]Feature{
76 .a,
77 .c,
78 .d,
79 .f,
80 .m,
81 .relax,
82 }),
83 };
84
85 pub const baseline_rv64 = Cpu{
86 .name = "baseline_rv64",
87 .llvm_name = "generic-rv64",
88 .features = featureSet(&[_]Feature{
89 .@"64bit",
90 .a,
91 .c,
92 .d,
93 .f,
94 .m,
95 .relax,
96 }),
97 };
98
99 pub const generic_rv32 = Cpu{
100 .name = "generic_rv32",
101 .llvm_name = "generic-rv32",
102 .features = featureSet(&[_]Feature{}),
103 };
104
105 pub const generic_rv64 = Cpu{
106 .name = "generic_rv64",
107 .llvm_name = "generic-rv64",
108 .features = featureSet(&[_]Feature{
109 .@"64bit",
110 }),
111 };
112};
113
114/// All riscv CPUs, sorted alphabetically by name.
115/// TODO: Replace this with usage of `std.meta.declList`. It does work, but stage1
116/// compiler has inefficient memory and CPU usage, affecting build times.
117pub const all_cpus = &[_]*const Cpu{
118 &cpu.baseline_rv32,
119 &cpu.baseline_rv64,
120 &cpu.generic_rv32,
121 &cpu.generic_rv64,
122};
lib/std/target/sparc.zig created+495
...@@ -0,0 +1,495 @@
1const std = @import("../std.zig");
2const Cpu = std.Target.Cpu;
3
4pub const Feature = enum {
5 deprecated_v8,
6 detectroundchange,
7 fixallfdivsqrt,
8 hard_quad_float,
9 hasleoncasa,
10 hasumacsmac,
11 insertnopload,
12 leon,
13 leoncyclecounter,
14 leonpwrpsr,
15 no_fmuls,
16 no_fsmuld,
17 popc,
18 soft_float,
19 soft_mul_div,
20 v9,
21 vis,
22 vis2,
23 vis3,
24};
25
26pub usingnamespace Cpu.Feature.feature_set_fns(Feature);
27
28pub const all_features = blk: {
29 const len = @typeInfo(Feature).Enum.fields.len;
30 std.debug.assert(len <= Cpu.Feature.Set.needed_bit_count);
31 var result: [len]Cpu.Feature = undefined;
32 result[@enumToInt(Feature.deprecated_v8)] = .{
33 .llvm_name = "deprecated-v8",
34 .description = "Enable deprecated V8 instructions in V9 mode",
35 .dependencies = featureSet(&[_]Feature{}),
36 };
37 result[@enumToInt(Feature.detectroundchange)] = .{
38 .llvm_name = "detectroundchange",
39 .description = "LEON3 erratum detection: Detects any rounding mode change request: use only the round-to-nearest rounding mode",
40 .dependencies = featureSet(&[_]Feature{}),
41 };
42 result[@enumToInt(Feature.fixallfdivsqrt)] = .{
43 .llvm_name = "fixallfdivsqrt",
44 .description = "LEON erratum fix: Fix FDIVS/FDIVD/FSQRTS/FSQRTD instructions with NOPs and floating-point store",
45 .dependencies = featureSet(&[_]Feature{}),
46 };
47 result[@enumToInt(Feature.hard_quad_float)] = .{
48 .llvm_name = "hard-quad-float",
49 .description = "Enable quad-word floating point instructions",
50 .dependencies = featureSet(&[_]Feature{}),
51 };
52 result[@enumToInt(Feature.hasleoncasa)] = .{
53 .llvm_name = "hasleoncasa",
54 .description = "Enable CASA instruction for LEON3 and LEON4 processors",
55 .dependencies = featureSet(&[_]Feature{}),
56 };
57 result[@enumToInt(Feature.hasumacsmac)] = .{
58 .llvm_name = "hasumacsmac",
59 .description = "Enable UMAC and SMAC for LEON3 and LEON4 processors",
60 .dependencies = featureSet(&[_]Feature{}),
61 };
62 result[@enumToInt(Feature.insertnopload)] = .{
63 .llvm_name = "insertnopload",
64 .description = "LEON3 erratum fix: Insert a NOP instruction after every single-cycle load instruction when the next instruction is another load/store instruction",
65 .dependencies = featureSet(&[_]Feature{}),
66 };
67 result[@enumToInt(Feature.leon)] = .{
68 .llvm_name = "leon",
69 .description = "Enable LEON extensions",
70 .dependencies = featureSet(&[_]Feature{}),
71 };
72 result[@enumToInt(Feature.leoncyclecounter)] = .{
73 .llvm_name = "leoncyclecounter",
74 .description = "Use the Leon cycle counter register",
75 .dependencies = featureSet(&[_]Feature{}),
76 };
77 result[@enumToInt(Feature.leonpwrpsr)] = .{
78 .llvm_name = "leonpwrpsr",
79 .description = "Enable the PWRPSR instruction",
80 .dependencies = featureSet(&[_]Feature{}),
81 };
82 result[@enumToInt(Feature.no_fmuls)] = .{
83 .llvm_name = "no-fmuls",
84 .description = "Disable the fmuls instruction.",
85 .dependencies = featureSet(&[_]Feature{}),
86 };
87 result[@enumToInt(Feature.no_fsmuld)] = .{
88 .llvm_name = "no-fsmuld",
89 .description = "Disable the fsmuld instruction.",
90 .dependencies = featureSet(&[_]Feature{}),
91 };
92 result[@enumToInt(Feature.popc)] = .{
93 .llvm_name = "popc",
94 .description = "Use the popc (population count) instruction",
95 .dependencies = featureSet(&[_]Feature{}),
96 };
97 result[@enumToInt(Feature.soft_float)] = .{
98 .llvm_name = "soft-float",
99 .description = "Use software emulation for floating point",
100 .dependencies = featureSet(&[_]Feature{}),
101 };
102 result[@enumToInt(Feature.soft_mul_div)] = .{
103 .llvm_name = "soft-mul-div",
104 .description = "Use software emulation for integer multiply and divide",
105 .dependencies = featureSet(&[_]Feature{}),
106 };
107 result[@enumToInt(Feature.v9)] = .{
108 .llvm_name = "v9",
109 .description = "Enable SPARC-V9 instructions",
110 .dependencies = featureSet(&[_]Feature{}),
111 };
112 result[@enumToInt(Feature.vis)] = .{
113 .llvm_name = "vis",
114 .description = "Enable UltraSPARC Visual Instruction Set extensions",
115 .dependencies = featureSet(&[_]Feature{}),
116 };
117 result[@enumToInt(Feature.vis2)] = .{
118 .llvm_name = "vis2",
119 .description = "Enable Visual Instruction Set extensions II",
120 .dependencies = featureSet(&[_]Feature{}),
121 };
122 result[@enumToInt(Feature.vis3)] = .{
123 .llvm_name = "vis3",
124 .description = "Enable Visual Instruction Set extensions III",
125 .dependencies = featureSet(&[_]Feature{}),
126 };
127 const ti = @typeInfo(Feature);
128 for (result) |*elem, i| {
129 elem.index = i;
130 elem.name = ti.Enum.fields[i].name;
131 }
132 break :blk result;
133};
134
135pub const cpu = struct {
136 pub const at697e = Cpu{
137 .name = "at697e",
138 .llvm_name = "at697e",
139 .features = featureSet(&[_]Feature{
140 .insertnopload,
141 .leon,
142 }),
143 };
144 pub const at697f = Cpu{
145 .name = "at697f",
146 .llvm_name = "at697f",
147 .features = featureSet(&[_]Feature{
148 .insertnopload,
149 .leon,
150 }),
151 };
152 pub const f934 = Cpu{
153 .name = "f934",
154 .llvm_name = "f934",
155 .features = featureSet(&[_]Feature{}),
156 };
157 pub const generic = Cpu{
158 .name = "generic",
159 .llvm_name = "generic",
160 .features = featureSet(&[_]Feature{}),
161 };
162 pub const gr712rc = Cpu{
163 .name = "gr712rc",
164 .llvm_name = "gr712rc",
165 .features = featureSet(&[_]Feature{
166 .hasleoncasa,
167 .leon,
168 }),
169 };
170 pub const gr740 = Cpu{
171 .name = "gr740",
172 .llvm_name = "gr740",
173 .features = featureSet(&[_]Feature{
174 .hasleoncasa,
175 .hasumacsmac,
176 .leon,
177 .leoncyclecounter,
178 .leonpwrpsr,
179 }),
180 };
181 pub const hypersparc = Cpu{
182 .name = "hypersparc",
183 .llvm_name = "hypersparc",
184 .features = featureSet(&[_]Feature{}),
185 };
186 pub const leon2 = Cpu{
187 .name = "leon2",
188 .llvm_name = "leon2",
189 .features = featureSet(&[_]Feature{
190 .leon,
191 }),
192 };
193 pub const leon3 = Cpu{
194 .name = "leon3",
195 .llvm_name = "leon3",
196 .features = featureSet(&[_]Feature{
197 .hasumacsmac,
198 .leon,
199 }),
200 };
201 pub const leon4 = Cpu{
202 .name = "leon4",
203 .llvm_name = "leon4",
204 .features = featureSet(&[_]Feature{
205 .hasleoncasa,
206 .hasumacsmac,
207 .leon,
208 }),
209 };
210 pub const ma2080 = Cpu{
211 .name = "ma2080",
212 .llvm_name = "ma2080",
213 .features = featureSet(&[_]Feature{
214 .hasleoncasa,
215 .leon,
216 }),
217 };
218 pub const ma2085 = Cpu{
219 .name = "ma2085",
220 .llvm_name = "ma2085",
221 .features = featureSet(&[_]Feature{
222 .hasleoncasa,
223 .leon,
224 }),
225 };
226 pub const ma2100 = Cpu{
227 .name = "ma2100",
228 .llvm_name = "ma2100",
229 .features = featureSet(&[_]Feature{
230 .hasleoncasa,
231 .leon,
232 }),
233 };
234 pub const ma2150 = Cpu{
235 .name = "ma2150",
236 .llvm_name = "ma2150",
237 .features = featureSet(&[_]Feature{
238 .hasleoncasa,
239 .leon,
240 }),
241 };
242 pub const ma2155 = Cpu{
243 .name = "ma2155",
244 .llvm_name = "ma2155",
245 .features = featureSet(&[_]Feature{
246 .hasleoncasa,
247 .leon,
248 }),
249 };
250 pub const ma2450 = Cpu{
251 .name = "ma2450",
252 .llvm_name = "ma2450",
253 .features = featureSet(&[_]Feature{
254 .hasleoncasa,
255 .leon,
256 }),
257 };
258 pub const ma2455 = Cpu{
259 .name = "ma2455",
260 .llvm_name = "ma2455",
261 .features = featureSet(&[_]Feature{
262 .hasleoncasa,
263 .leon,
264 }),
265 };
266 pub const ma2480 = Cpu{
267 .name = "ma2480",
268 .llvm_name = "ma2480",
269 .features = featureSet(&[_]Feature{
270 .hasleoncasa,
271 .leon,
272 }),
273 };
274 pub const ma2485 = Cpu{
275 .name = "ma2485",
276 .llvm_name = "ma2485",
277 .features = featureSet(&[_]Feature{
278 .hasleoncasa,
279 .leon,
280 }),
281 };
282 pub const ma2x5x = Cpu{
283 .name = "ma2x5x",
284 .llvm_name = "ma2x5x",
285 .features = featureSet(&[_]Feature{
286 .hasleoncasa,
287 .leon,
288 }),
289 };
290 pub const ma2x8x = Cpu{
291 .name = "ma2x8x",
292 .llvm_name = "ma2x8x",
293 .features = featureSet(&[_]Feature{
294 .hasleoncasa,
295 .leon,
296 }),
297 };
298 pub const myriad2 = Cpu{
299 .name = "myriad2",
300 .llvm_name = "myriad2",
301 .features = featureSet(&[_]Feature{
302 .hasleoncasa,
303 .leon,
304 }),
305 };
306 pub const myriad2_1 = Cpu{
307 .name = "myriad2_1",
308 .llvm_name = "myriad2.1",
309 .features = featureSet(&[_]Feature{
310 .hasleoncasa,
311 .leon,
312 }),
313 };
314 pub const myriad2_2 = Cpu{
315 .name = "myriad2_2",
316 .llvm_name = "myriad2.2",
317 .features = featureSet(&[_]Feature{
318 .hasleoncasa,
319 .leon,
320 }),
321 };
322 pub const myriad2_3 = Cpu{
323 .name = "myriad2_3",
324 .llvm_name = "myriad2.3",
325 .features = featureSet(&[_]Feature{
326 .hasleoncasa,
327 .leon,
328 }),
329 };
330 pub const niagara = Cpu{
331 .name = "niagara",
332 .llvm_name = "niagara",
333 .features = featureSet(&[_]Feature{
334 .deprecated_v8,
335 .v9,
336 .vis,
337 .vis2,
338 }),
339 };
340 pub const niagara2 = Cpu{
341 .name = "niagara2",
342 .llvm_name = "niagara2",
343 .features = featureSet(&[_]Feature{
344 .deprecated_v8,
345 .popc,
346 .v9,
347 .vis,
348 .vis2,
349 }),
350 };
351 pub const niagara3 = Cpu{
352 .name = "niagara3",
353 .llvm_name = "niagara3",
354 .features = featureSet(&[_]Feature{
355 .deprecated_v8,
356 .popc,
357 .v9,
358 .vis,
359 .vis2,
360 }),
361 };
362 pub const niagara4 = Cpu{
363 .name = "niagara4",
364 .llvm_name = "niagara4",
365 .features = featureSet(&[_]Feature{
366 .deprecated_v8,
367 .popc,
368 .v9,
369 .vis,
370 .vis2,
371 .vis3,
372 }),
373 };
374 pub const sparclet = Cpu{
375 .name = "sparclet",
376 .llvm_name = "sparclet",
377 .features = featureSet(&[_]Feature{}),
378 };
379 pub const sparclite = Cpu{
380 .name = "sparclite",
381 .llvm_name = "sparclite",
382 .features = featureSet(&[_]Feature{}),
383 };
384 pub const sparclite86x = Cpu{
385 .name = "sparclite86x",
386 .llvm_name = "sparclite86x",
387 .features = featureSet(&[_]Feature{}),
388 };
389 pub const supersparc = Cpu{
390 .name = "supersparc",
391 .llvm_name = "supersparc",
392 .features = featureSet(&[_]Feature{}),
393 };
394 pub const tsc701 = Cpu{
395 .name = "tsc701",
396 .llvm_name = "tsc701",
397 .features = featureSet(&[_]Feature{}),
398 };
399 pub const ultrasparc = Cpu{
400 .name = "ultrasparc",
401 .llvm_name = "ultrasparc",
402 .features = featureSet(&[_]Feature{
403 .deprecated_v8,
404 .v9,
405 .vis,
406 }),
407 };
408 pub const ultrasparc3 = Cpu{
409 .name = "ultrasparc3",
410 .llvm_name = "ultrasparc3",
411 .features = featureSet(&[_]Feature{
412 .deprecated_v8,
413 .v9,
414 .vis,
415 .vis2,
416 }),
417 };
418 pub const ut699 = Cpu{
419 .name = "ut699",
420 .llvm_name = "ut699",
421 .features = featureSet(&[_]Feature{
422 .fixallfdivsqrt,
423 .insertnopload,
424 .leon,
425 .no_fmuls,
426 .no_fsmuld,
427 }),
428 };
429 pub const v7 = Cpu{
430 .name = "v7",
431 .llvm_name = "v7",
432 .features = featureSet(&[_]Feature{
433 .no_fsmuld,
434 .soft_mul_div,
435 }),
436 };
437 pub const v8 = Cpu{
438 .name = "v8",
439 .llvm_name = "v8",
440 .features = featureSet(&[_]Feature{}),
441 };
442 pub const v9 = Cpu{
443 .name = "v9",
444 .llvm_name = "v9",
445 .features = featureSet(&[_]Feature{
446 .v9,
447 }),
448 };
449};
450
451/// All sparc CPUs, sorted alphabetically by name.
452/// TODO: Replace this with usage of `std.meta.declList`. It does work, but stage1
453/// compiler has inefficient memory and CPU usage, affecting build times.
454pub const all_cpus = &[_]*const Cpu{
455 &cpu.at697e,
456 &cpu.at697f,
457 &cpu.f934,
458 &cpu.generic,
459 &cpu.gr712rc,
460 &cpu.gr740,
461 &cpu.hypersparc,
462 &cpu.leon2,
463 &cpu.leon3,
464 &cpu.leon4,
465 &cpu.ma2080,
466 &cpu.ma2085,
467 &cpu.ma2100,
468 &cpu.ma2150,
469 &cpu.ma2155,
470 &cpu.ma2450,
471 &cpu.ma2455,
472 &cpu.ma2480,
473 &cpu.ma2485,
474 &cpu.ma2x5x,
475 &cpu.ma2x8x,
476 &cpu.myriad2,
477 &cpu.myriad2_1,
478 &cpu.myriad2_2,
479 &cpu.myriad2_3,
480 &cpu.niagara,
481 &cpu.niagara2,
482 &cpu.niagara3,
483 &cpu.niagara4,
484 &cpu.sparclet,
485 &cpu.sparclite,
486 &cpu.sparclite86x,
487 &cpu.supersparc,
488 &cpu.tsc701,
489 &cpu.ultrasparc,
490 &cpu.ultrasparc3,
491 &cpu.ut699,
492 &cpu.v7,
493 &cpu.v8,
494 &cpu.v9,
495};
lib/std/target/systemz.zig created+510
...@@ -0,0 +1,510 @@
1const std = @import("../std.zig");
2const Cpu = std.Target.Cpu;
3
4pub const Feature = enum {
5 deflate_conversion,
6 dfp_packed_conversion,
7 dfp_zoned_conversion,
8 distinct_ops,
9 enhanced_dat_2,
10 enhanced_sort,
11 execution_hint,
12 fast_serialization,
13 fp_extension,
14 guarded_storage,
15 high_word,
16 insert_reference_bits_multiple,
17 interlocked_access1,
18 load_and_trap,
19 load_and_zero_rightmost_byte,
20 load_store_on_cond,
21 load_store_on_cond_2,
22 message_security_assist_extension3,
23 message_security_assist_extension4,
24 message_security_assist_extension5,
25 message_security_assist_extension7,
26 message_security_assist_extension8,
27 message_security_assist_extension9,
28 miscellaneous_extensions,
29 miscellaneous_extensions_2,
30 miscellaneous_extensions_3,
31 population_count,
32 processor_assist,
33 reset_reference_bits_multiple,
34 transactional_execution,
35 vector,
36 vector_enhancements_1,
37 vector_enhancements_2,
38 vector_packed_decimal,
39 vector_packed_decimal_enhancement,
40};
41
42pub usingnamespace Cpu.Feature.feature_set_fns(Feature);
43
44pub const all_features = blk: {
45 const len = @typeInfo(Feature).Enum.fields.len;
46 std.debug.assert(len <= Cpu.Feature.Set.needed_bit_count);
47 var result: [len]Cpu.Feature = undefined;
48 result[@enumToInt(Feature.deflate_conversion)] = .{
49 .llvm_name = "deflate-conversion",
50 .description = "Assume that the deflate-conversion facility is installed",
51 .dependencies = featureSet(&[_]Feature{}),
52 };
53 result[@enumToInt(Feature.dfp_packed_conversion)] = .{
54 .llvm_name = "dfp-packed-conversion",
55 .description = "Assume that the DFP packed-conversion facility is installed",
56 .dependencies = featureSet(&[_]Feature{}),
57 };
58 result[@enumToInt(Feature.dfp_zoned_conversion)] = .{
59 .llvm_name = "dfp-zoned-conversion",
60 .description = "Assume that the DFP zoned-conversion facility is installed",
61 .dependencies = featureSet(&[_]Feature{}),
62 };
63 result[@enumToInt(Feature.distinct_ops)] = .{
64 .llvm_name = "distinct-ops",
65 .description = "Assume that the distinct-operands facility is installed",
66 .dependencies = featureSet(&[_]Feature{}),
67 };
68 result[@enumToInt(Feature.enhanced_dat_2)] = .{
69 .llvm_name = "enhanced-dat-2",
70 .description = "Assume that the enhanced-DAT facility 2 is installed",
71 .dependencies = featureSet(&[_]Feature{}),
72 };
73 result[@enumToInt(Feature.enhanced_sort)] = .{
74 .llvm_name = "enhanced-sort",
75 .description = "Assume that the enhanced-sort facility is installed",
76 .dependencies = featureSet(&[_]Feature{}),
77 };
78 result[@enumToInt(Feature.execution_hint)] = .{
79 .llvm_name = "execution-hint",
80 .description = "Assume that the execution-hint facility is installed",
81 .dependencies = featureSet(&[_]Feature{}),
82 };
83 result[@enumToInt(Feature.fast_serialization)] = .{
84 .llvm_name = "fast-serialization",
85 .description = "Assume that the fast-serialization facility is installed",
86 .dependencies = featureSet(&[_]Feature{}),
87 };
88 result[@enumToInt(Feature.fp_extension)] = .{
89 .llvm_name = "fp-extension",
90 .description = "Assume that the floating-point extension facility is installed",
91 .dependencies = featureSet(&[_]Feature{}),
92 };
93 result[@enumToInt(Feature.guarded_storage)] = .{
94 .llvm_name = "guarded-storage",
95 .description = "Assume that the guarded-storage facility is installed",
96 .dependencies = featureSet(&[_]Feature{}),
97 };
98 result[@enumToInt(Feature.high_word)] = .{
99 .llvm_name = "high-word",
100 .description = "Assume that the high-word facility is installed",
101 .dependencies = featureSet(&[_]Feature{}),
102 };
103 result[@enumToInt(Feature.insert_reference_bits_multiple)] = .{
104 .llvm_name = "insert-reference-bits-multiple",
105 .description = "Assume that the insert-reference-bits-multiple facility is installed",
106 .dependencies = featureSet(&[_]Feature{}),
107 };
108 result[@enumToInt(Feature.interlocked_access1)] = .{
109 .llvm_name = "interlocked-access1",
110 .description = "Assume that interlocked-access facility 1 is installed",
111 .dependencies = featureSet(&[_]Feature{}),
112 };
113 result[@enumToInt(Feature.load_and_trap)] = .{
114 .llvm_name = "load-and-trap",
115 .description = "Assume that the load-and-trap facility is installed",
116 .dependencies = featureSet(&[_]Feature{}),
117 };
118 result[@enumToInt(Feature.load_and_zero_rightmost_byte)] = .{
119 .llvm_name = "load-and-zero-rightmost-byte",
120 .description = "Assume that the load-and-zero-rightmost-byte facility is installed",
121 .dependencies = featureSet(&[_]Feature{}),
122 };
123 result[@enumToInt(Feature.load_store_on_cond)] = .{
124 .llvm_name = "load-store-on-cond",
125 .description = "Assume that the load/store-on-condition facility is installed",
126 .dependencies = featureSet(&[_]Feature{}),
127 };
128 result[@enumToInt(Feature.load_store_on_cond_2)] = .{
129 .llvm_name = "load-store-on-cond-2",
130 .description = "Assume that the load/store-on-condition facility 2 is installed",
131 .dependencies = featureSet(&[_]Feature{}),
132 };
133 result[@enumToInt(Feature.message_security_assist_extension3)] = .{
134 .llvm_name = "message-security-assist-extension3",
135 .description = "Assume that the message-security-assist extension facility 3 is installed",
136 .dependencies = featureSet(&[_]Feature{}),
137 };
138 result[@enumToInt(Feature.message_security_assist_extension4)] = .{
139 .llvm_name = "message-security-assist-extension4",
140 .description = "Assume that the message-security-assist extension facility 4 is installed",
141 .dependencies = featureSet(&[_]Feature{}),
142 };
143 result[@enumToInt(Feature.message_security_assist_extension5)] = .{
144 .llvm_name = "message-security-assist-extension5",
145 .description = "Assume that the message-security-assist extension facility 5 is installed",
146 .dependencies = featureSet(&[_]Feature{}),
147 };
148 result[@enumToInt(Feature.message_security_assist_extension7)] = .{
149 .llvm_name = "message-security-assist-extension7",
150 .description = "Assume that the message-security-assist extension facility 7 is installed",
151 .dependencies = featureSet(&[_]Feature{}),
152 };
153 result[@enumToInt(Feature.message_security_assist_extension8)] = .{
154 .llvm_name = "message-security-assist-extension8",
155 .description = "Assume that the message-security-assist extension facility 8 is installed",
156 .dependencies = featureSet(&[_]Feature{}),
157 };
158 result[@enumToInt(Feature.message_security_assist_extension9)] = .{
159 .llvm_name = "message-security-assist-extension9",
160 .description = "Assume that the message-security-assist extension facility 9 is installed",
161 .dependencies = featureSet(&[_]Feature{}),
162 };
163 result[@enumToInt(Feature.miscellaneous_extensions)] = .{
164 .llvm_name = "miscellaneous-extensions",
165 .description = "Assume that the miscellaneous-extensions facility is installed",
166 .dependencies = featureSet(&[_]Feature{}),
167 };
168 result[@enumToInt(Feature.miscellaneous_extensions_2)] = .{
169 .llvm_name = "miscellaneous-extensions-2",
170 .description = "Assume that the miscellaneous-extensions facility 2 is installed",
171 .dependencies = featureSet(&[_]Feature{}),
172 };
173 result[@enumToInt(Feature.miscellaneous_extensions_3)] = .{
174 .llvm_name = "miscellaneous-extensions-3",
175 .description = "Assume that the miscellaneous-extensions facility 3 is installed",
176 .dependencies = featureSet(&[_]Feature{}),
177 };
178 result[@enumToInt(Feature.population_count)] = .{
179 .llvm_name = "population-count",
180 .description = "Assume that the population-count facility is installed",
181 .dependencies = featureSet(&[_]Feature{}),
182 };
183 result[@enumToInt(Feature.processor_assist)] = .{
184 .llvm_name = "processor-assist",
185 .description = "Assume that the processor-assist facility is installed",
186 .dependencies = featureSet(&[_]Feature{}),
187 };
188 result[@enumToInt(Feature.reset_reference_bits_multiple)] = .{
189 .llvm_name = "reset-reference-bits-multiple",
190 .description = "Assume that the reset-reference-bits-multiple facility is installed",
191 .dependencies = featureSet(&[_]Feature{}),
192 };
193 result[@enumToInt(Feature.transactional_execution)] = .{
194 .llvm_name = "transactional-execution",
195 .description = "Assume that the transactional-execution facility is installed",
196 .dependencies = featureSet(&[_]Feature{}),
197 };
198 result[@enumToInt(Feature.vector)] = .{
199 .llvm_name = "vector",
200 .description = "Assume that the vectory facility is installed",
201 .dependencies = featureSet(&[_]Feature{}),
202 };
203 result[@enumToInt(Feature.vector_enhancements_1)] = .{
204 .llvm_name = "vector-enhancements-1",
205 .description = "Assume that the vector enhancements facility 1 is installed",
206 .dependencies = featureSet(&[_]Feature{}),
207 };
208 result[@enumToInt(Feature.vector_enhancements_2)] = .{
209 .llvm_name = "vector-enhancements-2",
210 .description = "Assume that the vector enhancements facility 2 is installed",
211 .dependencies = featureSet(&[_]Feature{}),
212 };
213 result[@enumToInt(Feature.vector_packed_decimal)] = .{
214 .llvm_name = "vector-packed-decimal",
215 .description = "Assume that the vector packed decimal facility is installed",
216 .dependencies = featureSet(&[_]Feature{}),
217 };
218 result[@enumToInt(Feature.vector_packed_decimal_enhancement)] = .{
219 .llvm_name = "vector-packed-decimal-enhancement",
220 .description = "Assume that the vector packed decimal enhancement facility is installed",
221 .dependencies = featureSet(&[_]Feature{}),
222 };
223 const ti = @typeInfo(Feature);
224 for (result) |*elem, i| {
225 elem.index = i;
226 elem.name = ti.Enum.fields[i].name;
227 }
228 break :blk result;
229};
230
231pub const cpu = struct {
232 pub const arch10 = Cpu{
233 .name = "arch10",
234 .llvm_name = "arch10",
235 .features = featureSet(&[_]Feature{
236 .dfp_zoned_conversion,
237 .distinct_ops,
238 .enhanced_dat_2,
239 .execution_hint,
240 .fast_serialization,
241 .fp_extension,
242 .high_word,
243 .interlocked_access1,
244 .load_and_trap,
245 .load_store_on_cond,
246 .message_security_assist_extension3,
247 .message_security_assist_extension4,
248 .miscellaneous_extensions,
249 .population_count,
250 .processor_assist,
251 .reset_reference_bits_multiple,
252 .transactional_execution,
253 }),
254 };
255 pub const arch11 = Cpu{
256 .name = "arch11",
257 .llvm_name = "arch11",
258 .features = featureSet(&[_]Feature{
259 .dfp_packed_conversion,
260 .dfp_zoned_conversion,
261 .distinct_ops,
262 .enhanced_dat_2,
263 .execution_hint,
264 .fast_serialization,
265 .fp_extension,
266 .high_word,
267 .interlocked_access1,
268 .load_and_trap,
269 .load_and_zero_rightmost_byte,
270 .load_store_on_cond,
271 .load_store_on_cond_2,
272 .message_security_assist_extension3,
273 .message_security_assist_extension4,
274 .message_security_assist_extension5,
275 .miscellaneous_extensions,
276 .population_count,
277 .processor_assist,
278 .reset_reference_bits_multiple,
279 .transactional_execution,
280 .vector,
281 }),
282 };
283 pub const arch12 = Cpu{
284 .name = "arch12",
285 .llvm_name = "arch12",
286 .features = featureSet(&[_]Feature{
287 .dfp_packed_conversion,
288 .dfp_zoned_conversion,
289 .distinct_ops,
290 .enhanced_dat_2,
291 .execution_hint,
292 .fast_serialization,
293 .fp_extension,
294 .guarded_storage,
295 .high_word,
296 .insert_reference_bits_multiple,
297 .interlocked_access1,
298 .load_and_trap,
299 .load_and_zero_rightmost_byte,
300 .load_store_on_cond,
301 .load_store_on_cond_2,
302 .message_security_assist_extension3,
303 .message_security_assist_extension4,
304 .message_security_assist_extension5,
305 .message_security_assist_extension7,
306 .message_security_assist_extension8,
307 .miscellaneous_extensions,
308 .miscellaneous_extensions_2,
309 .population_count,
310 .processor_assist,
311 .reset_reference_bits_multiple,
312 .transactional_execution,
313 .vector,
314 .vector_enhancements_1,
315 .vector_packed_decimal,
316 }),
317 };
318 pub const arch13 = Cpu{
319 .name = "arch13",
320 .llvm_name = "arch13",
321 .features = featureSet(&[_]Feature{
322 .deflate_conversion,
323 .dfp_packed_conversion,
324 .dfp_zoned_conversion,
325 .distinct_ops,
326 .enhanced_dat_2,
327 .enhanced_sort,
328 .execution_hint,
329 .fast_serialization,
330 .fp_extension,
331 .guarded_storage,
332 .high_word,
333 .insert_reference_bits_multiple,
334 .interlocked_access1,
335 .load_and_trap,
336 .load_and_zero_rightmost_byte,
337 .load_store_on_cond,
338 .load_store_on_cond_2,
339 .message_security_assist_extension3,
340 .message_security_assist_extension4,
341 .message_security_assist_extension5,
342 .message_security_assist_extension7,
343 .message_security_assist_extension8,
344 .message_security_assist_extension9,
345 .miscellaneous_extensions,
346 .miscellaneous_extensions_2,
347 .miscellaneous_extensions_3,
348 .population_count,
349 .processor_assist,
350 .reset_reference_bits_multiple,
351 .transactional_execution,
352 .vector,
353 .vector_enhancements_1,
354 .vector_enhancements_2,
355 .vector_packed_decimal,
356 .vector_packed_decimal_enhancement,
357 }),
358 };
359 pub const arch8 = Cpu{
360 .name = "arch8",
361 .llvm_name = "arch8",
362 .features = featureSet(&[_]Feature{}),
363 };
364 pub const arch9 = Cpu{
365 .name = "arch9",
366 .llvm_name = "arch9",
367 .features = featureSet(&[_]Feature{
368 .distinct_ops,
369 .fast_serialization,
370 .fp_extension,
371 .high_word,
372 .interlocked_access1,
373 .load_store_on_cond,
374 .message_security_assist_extension3,
375 .message_security_assist_extension4,
376 .population_count,
377 .reset_reference_bits_multiple,
378 }),
379 };
380 pub const generic = Cpu{
381 .name = "generic",
382 .llvm_name = "generic",
383 .features = featureSet(&[_]Feature{}),
384 };
385 pub const z10 = Cpu{
386 .name = "z10",
387 .llvm_name = "z10",
388 .features = featureSet(&[_]Feature{}),
389 };
390 pub const z13 = Cpu{
391 .name = "z13",
392 .llvm_name = "z13",
393 .features = featureSet(&[_]Feature{
394 .dfp_packed_conversion,
395 .dfp_zoned_conversion,
396 .distinct_ops,
397 .enhanced_dat_2,
398 .execution_hint,
399 .fast_serialization,
400 .fp_extension,
401 .high_word,
402 .interlocked_access1,
403 .load_and_trap,
404 .load_and_zero_rightmost_byte,
405 .load_store_on_cond,
406 .load_store_on_cond_2,
407 .message_security_assist_extension3,
408 .message_security_assist_extension4,
409 .message_security_assist_extension5,
410 .miscellaneous_extensions,
411 .population_count,
412 .processor_assist,
413 .reset_reference_bits_multiple,
414 .transactional_execution,
415 .vector,
416 }),
417 };
418 pub const z14 = Cpu{
419 .name = "z14",
420 .llvm_name = "z14",
421 .features = featureSet(&[_]Feature{
422 .dfp_packed_conversion,
423 .dfp_zoned_conversion,
424 .distinct_ops,
425 .enhanced_dat_2,
426 .execution_hint,
427 .fast_serialization,
428 .fp_extension,
429 .guarded_storage,
430 .high_word,
431 .insert_reference_bits_multiple,
432 .interlocked_access1,
433 .load_and_trap,
434 .load_and_zero_rightmost_byte,
435 .load_store_on_cond,
436 .load_store_on_cond_2,
437 .message_security_assist_extension3,
438 .message_security_assist_extension4,
439 .message_security_assist_extension5,
440 .message_security_assist_extension7,
441 .message_security_assist_extension8,
442 .miscellaneous_extensions,
443 .miscellaneous_extensions_2,
444 .population_count,
445 .processor_assist,
446 .reset_reference_bits_multiple,
447 .transactional_execution,
448 .vector,
449 .vector_enhancements_1,
450 .vector_packed_decimal,
451 }),
452 };
453 pub const z196 = Cpu{
454 .name = "z196",
455 .llvm_name = "z196",
456 .features = featureSet(&[_]Feature{
457 .distinct_ops,
458 .fast_serialization,
459 .fp_extension,
460 .high_word,
461 .interlocked_access1,
462 .load_store_on_cond,
463 .message_security_assist_extension3,
464 .message_security_assist_extension4,
465 .population_count,
466 .reset_reference_bits_multiple,
467 }),
468 };
469 pub const zEC12 = Cpu{
470 .name = "zEC12",
471 .llvm_name = "zEC12",
472 .features = featureSet(&[_]Feature{
473 .dfp_zoned_conversion,
474 .distinct_ops,
475 .enhanced_dat_2,
476 .execution_hint,
477 .fast_serialization,
478 .fp_extension,
479 .high_word,
480 .interlocked_access1,
481 .load_and_trap,
482 .load_store_on_cond,
483 .message_security_assist_extension3,
484 .message_security_assist_extension4,
485 .miscellaneous_extensions,
486 .population_count,
487 .processor_assist,
488 .reset_reference_bits_multiple,
489 .transactional_execution,
490 }),
491 };
492};
493
494/// All systemz CPUs, sorted alphabetically by name.
495/// TODO: Replace this with usage of `std.meta.declList`. It does work, but stage1
496/// compiler has inefficient memory and CPU usage, affecting build times.
497pub const all_cpus = &[_]*const Cpu{
498 &cpu.arch10,
499 &cpu.arch11,
500 &cpu.arch12,
501 &cpu.arch13,
502 &cpu.arch8,
503 &cpu.arch9,
504 &cpu.generic,
505 &cpu.z10,
506 &cpu.z13,
507 &cpu.z14,
508 &cpu.z196,
509 &cpu.zEC12,
510};
lib/std/target/wasm.zig created+114
...@@ -0,0 +1,114 @@
1const std = @import("../std.zig");
2const Cpu = std.Target.Cpu;
3
4pub const Feature = enum {
5 atomics,
6 bulk_memory,
7 exception_handling,
8 multivalue,
9 mutable_globals,
10 nontrapping_fptoint,
11 sign_ext,
12 simd128,
13 tail_call,
14 unimplemented_simd128,
15};
16
17pub usingnamespace Cpu.Feature.feature_set_fns(Feature);
18
19pub const all_features = blk: {
20 const len = @typeInfo(Feature).Enum.fields.len;
21 std.debug.assert(len <= Cpu.Feature.Set.needed_bit_count);
22 var result: [len]Cpu.Feature = undefined;
23 result[@enumToInt(Feature.atomics)] = .{
24 .llvm_name = "atomics",
25 .description = "Enable Atomics",
26 .dependencies = featureSet(&[_]Feature{}),
27 };
28 result[@enumToInt(Feature.bulk_memory)] = .{
29 .llvm_name = "bulk-memory",
30 .description = "Enable bulk memory operations",
31 .dependencies = featureSet(&[_]Feature{}),
32 };
33 result[@enumToInt(Feature.exception_handling)] = .{
34 .llvm_name = "exception-handling",
35 .description = "Enable Wasm exception handling",
36 .dependencies = featureSet(&[_]Feature{}),
37 };
38 result[@enumToInt(Feature.multivalue)] = .{
39 .llvm_name = "multivalue",
40 .description = "Enable multivalue blocks, instructions, and functions",
41 .dependencies = featureSet(&[_]Feature{}),
42 };
43 result[@enumToInt(Feature.mutable_globals)] = .{
44 .llvm_name = "mutable-globals",
45 .description = "Enable mutable globals",
46 .dependencies = featureSet(&[_]Feature{}),
47 };
48 result[@enumToInt(Feature.nontrapping_fptoint)] = .{
49 .llvm_name = "nontrapping-fptoint",
50 .description = "Enable non-trapping float-to-int conversion operators",
51 .dependencies = featureSet(&[_]Feature{}),
52 };
53 result[@enumToInt(Feature.sign_ext)] = .{
54 .llvm_name = "sign-ext",
55 .description = "Enable sign extension operators",
56 .dependencies = featureSet(&[_]Feature{}),
57 };
58 result[@enumToInt(Feature.simd128)] = .{
59 .llvm_name = "simd128",
60 .description = "Enable 128-bit SIMD",
61 .dependencies = featureSet(&[_]Feature{}),
62 };
63 result[@enumToInt(Feature.tail_call)] = .{
64 .llvm_name = "tail-call",
65 .description = "Enable tail call instructions",
66 .dependencies = featureSet(&[_]Feature{}),
67 };
68 result[@enumToInt(Feature.unimplemented_simd128)] = .{
69 .llvm_name = "unimplemented-simd128",
70 .description = "Enable 128-bit SIMD not yet implemented in engines",
71 .dependencies = featureSet(&[_]Feature{
72 .simd128,
73 }),
74 };
75 const ti = @typeInfo(Feature);
76 for (result) |*elem, i| {
77 elem.index = i;
78 elem.name = ti.Enum.fields[i].name;
79 }
80 break :blk result;
81};
82
83pub const cpu = struct {
84 pub const bleeding_edge = Cpu{
85 .name = "bleeding_edge",
86 .llvm_name = "bleeding-edge",
87 .features = featureSet(&[_]Feature{
88 .atomics,
89 .mutable_globals,
90 .nontrapping_fptoint,
91 .sign_ext,
92 .simd128,
93 }),
94 };
95 pub const generic = Cpu{
96 .name = "generic",
97 .llvm_name = "generic",
98 .features = featureSet(&[_]Feature{}),
99 };
100 pub const mvp = Cpu{
101 .name = "mvp",
102 .llvm_name = "mvp",
103 .features = featureSet(&[_]Feature{}),
104 };
105};
106
107/// All wasm CPUs, sorted alphabetically by name.
108/// TODO: Replace this with usage of `std.meta.declList`. It does work, but stage1
109/// compiler has inefficient memory and CPU usage, affecting build times.
110pub const all_cpus = &[_]*const Cpu{
111 &cpu.bleeding_edge,
112 &cpu.generic,
113 &cpu.mvp,
114};
lib/std/target/x86.zig created+2859
...@@ -0,0 +1,2859 @@
1const std = @import("../std.zig");
2const Cpu = std.Target.Cpu;
3
4pub const Feature = enum {
5 @"3dnow",
6 @"3dnowa",
7 @"64bit",
8 adx,
9 aes,
10 avx,
11 avx2,
12 avx512bf16,
13 avx512bitalg,
14 avx512bw,
15 avx512cd,
16 avx512dq,
17 avx512er,
18 avx512f,
19 avx512ifma,
20 avx512pf,
21 avx512vbmi,
22 avx512vbmi2,
23 avx512vl,
24 avx512vnni,
25 avx512vp2intersect,
26 avx512vpopcntdq,
27 bmi,
28 bmi2,
29 branchfusion,
30 cldemote,
31 clflushopt,
32 clwb,
33 clzero,
34 cmov,
35 cx16,
36 cx8,
37 enqcmd,
38 ermsb,
39 f16c,
40 false_deps_lzcnt_tzcnt,
41 false_deps_popcnt,
42 fast_11bytenop,
43 fast_15bytenop,
44 fast_bextr,
45 fast_gather,
46 fast_hops,
47 fast_lzcnt,
48 fast_partial_ymm_or_zmm_write,
49 fast_scalar_fsqrt,
50 fast_scalar_shift_masks,
51 fast_shld_rotate,
52 fast_variable_shuffle,
53 fast_vector_fsqrt,
54 fast_vector_shift_masks,
55 fma,
56 fma4,
57 fsgsbase,
58 fxsr,
59 gfni,
60 idivl_to_divb,
61 idivq_to_divl,
62 invpcid,
63 lea_sp,
64 lea_uses_ag,
65 lwp,
66 lzcnt,
67 macrofusion,
68 merge_to_threeway_branch,
69 mmx,
70 movbe,
71 movdir64b,
72 movdiri,
73 mpx,
74 mwaitx,
75 nopl,
76 pad_short_functions,
77 pclmul,
78 pconfig,
79 pku,
80 popcnt,
81 prefer_256_bit,
82 prefetchwt1,
83 prfchw,
84 ptwrite,
85 rdpid,
86 rdrnd,
87 rdseed,
88 retpoline,
89 retpoline_external_thunk,
90 retpoline_indirect_branches,
91 retpoline_indirect_calls,
92 rtm,
93 sahf,
94 sgx,
95 sha,
96 shstk,
97 slow_3ops_lea,
98 slow_incdec,
99 slow_lea,
100 slow_pmaddwd,
101 slow_pmulld,
102 slow_shld,
103 slow_two_mem_ops,
104 slow_unaligned_mem_16,
105 slow_unaligned_mem_32,
106 soft_float,
107 sse,
108 sse_unaligned_mem,
109 sse2,
110 sse3,
111 sse4_1,
112 sse4_2,
113 sse4a,
114 ssse3,
115 tbm,
116 vaes,
117 vpclmulqdq,
118 waitpkg,
119 wbnoinvd,
120 x87,
121 xop,
122 xsave,
123 xsavec,
124 xsaveopt,
125 xsaves,
126};
127
128pub usingnamespace Cpu.Feature.feature_set_fns(Feature);
129
130pub const all_features = blk: {
131 const len = @typeInfo(Feature).Enum.fields.len;
132 std.debug.assert(len <= Cpu.Feature.Set.needed_bit_count);
133 var result: [len]Cpu.Feature = undefined;
134 result[@enumToInt(Feature.@"3dnow")] = .{
135 .llvm_name = "3dnow",
136 .description = "Enable 3DNow! instructions",
137 .dependencies = featureSet(&[_]Feature{
138 .mmx,
139 }),
140 };
141 result[@enumToInt(Feature.@"3dnowa")] = .{
142 .llvm_name = "3dnowa",
143 .description = "Enable 3DNow! Athlon instructions",
144 .dependencies = featureSet(&[_]Feature{
145 .@"3dnow",
146 }),
147 };
148 result[@enumToInt(Feature.@"64bit")] = .{
149 .llvm_name = "64bit",
150 .description = "Support 64-bit instructions",
151 .dependencies = featureSet(&[_]Feature{}),
152 };
153 result[@enumToInt(Feature.adx)] = .{
154 .llvm_name = "adx",
155 .description = "Support ADX instructions",
156 .dependencies = featureSet(&[_]Feature{}),
157 };
158 result[@enumToInt(Feature.aes)] = .{
159 .llvm_name = "aes",
160 .description = "Enable AES instructions",
161 .dependencies = featureSet(&[_]Feature{
162 .sse2,
163 }),
164 };
165 result[@enumToInt(Feature.avx)] = .{
166 .llvm_name = "avx",
167 .description = "Enable AVX instructions",
168 .dependencies = featureSet(&[_]Feature{
169 .sse4_2,
170 }),
171 };
172 result[@enumToInt(Feature.avx2)] = .{
173 .llvm_name = "avx2",
174 .description = "Enable AVX2 instructions",
175 .dependencies = featureSet(&[_]Feature{
176 .avx,
177 }),
178 };
179 result[@enumToInt(Feature.avx512bf16)] = .{
180 .llvm_name = "avx512bf16",
181 .description = "Support bfloat16 floating point",
182 .dependencies = featureSet(&[_]Feature{
183 .avx512bw,
184 }),
185 };
186 result[@enumToInt(Feature.avx512bitalg)] = .{
187 .llvm_name = "avx512bitalg",
188 .description = "Enable AVX-512 Bit Algorithms",
189 .dependencies = featureSet(&[_]Feature{
190 .avx512bw,
191 }),
192 };
193 result[@enumToInt(Feature.avx512bw)] = .{
194 .llvm_name = "avx512bw",
195 .description = "Enable AVX-512 Byte and Word Instructions",
196 .dependencies = featureSet(&[_]Feature{
197 .avx512f,
198 }),
199 };
200 result[@enumToInt(Feature.avx512cd)] = .{
201 .llvm_name = "avx512cd",
202 .description = "Enable AVX-512 Conflict Detection Instructions",
203 .dependencies = featureSet(&[_]Feature{
204 .avx512f,
205 }),
206 };
207 result[@enumToInt(Feature.avx512dq)] = .{
208 .llvm_name = "avx512dq",
209 .description = "Enable AVX-512 Doubleword and Quadword Instructions",
210 .dependencies = featureSet(&[_]Feature{
211 .avx512f,
212 }),
213 };
214 result[@enumToInt(Feature.avx512er)] = .{
215 .llvm_name = "avx512er",
216 .description = "Enable AVX-512 Exponential and Reciprocal Instructions",
217 .dependencies = featureSet(&[_]Feature{
218 .avx512f,
219 }),
220 };
221 result[@enumToInt(Feature.avx512f)] = .{
222 .llvm_name = "avx512f",
223 .description = "Enable AVX-512 instructions",
224 .dependencies = featureSet(&[_]Feature{
225 .avx2,
226 .f16c,
227 .fma,
228 }),
229 };
230 result[@enumToInt(Feature.avx512ifma)] = .{
231 .llvm_name = "avx512ifma",
232 .description = "Enable AVX-512 Integer Fused Multiple-Add",
233 .dependencies = featureSet(&[_]Feature{
234 .avx512f,
235 }),
236 };
237 result[@enumToInt(Feature.avx512pf)] = .{
238 .llvm_name = "avx512pf",
239 .description = "Enable AVX-512 PreFetch Instructions",
240 .dependencies = featureSet(&[_]Feature{
241 .avx512f,
242 }),
243 };
244 result[@enumToInt(Feature.avx512vbmi)] = .{
245 .llvm_name = "avx512vbmi",
246 .description = "Enable AVX-512 Vector Byte Manipulation Instructions",
247 .dependencies = featureSet(&[_]Feature{
248 .avx512bw,
249 }),
250 };
251 result[@enumToInt(Feature.avx512vbmi2)] = .{
252 .llvm_name = "avx512vbmi2",
253 .description = "Enable AVX-512 further Vector Byte Manipulation Instructions",
254 .dependencies = featureSet(&[_]Feature{
255 .avx512bw,
256 }),
257 };
258 result[@enumToInt(Feature.avx512vl)] = .{
259 .llvm_name = "avx512vl",
260 .description = "Enable AVX-512 Vector Length eXtensions",
261 .dependencies = featureSet(&[_]Feature{
262 .avx512f,
263 }),
264 };
265 result[@enumToInt(Feature.avx512vnni)] = .{
266 .llvm_name = "avx512vnni",
267 .description = "Enable AVX-512 Vector Neural Network Instructions",
268 .dependencies = featureSet(&[_]Feature{
269 .avx512f,
270 }),
271 };
272 result[@enumToInt(Feature.avx512vp2intersect)] = .{
273 .llvm_name = "avx512vp2intersect",
274 .description = "Enable AVX-512 vp2intersect",
275 .dependencies = featureSet(&[_]Feature{
276 .avx512f,
277 }),
278 };
279 result[@enumToInt(Feature.avx512vpopcntdq)] = .{
280 .llvm_name = "avx512vpopcntdq",
281 .description = "Enable AVX-512 Population Count Instructions",
282 .dependencies = featureSet(&[_]Feature{
283 .avx512f,
284 }),
285 };
286 result[@enumToInt(Feature.bmi)] = .{
287 .llvm_name = "bmi",
288 .description = "Support BMI instructions",
289 .dependencies = featureSet(&[_]Feature{}),
290 };
291 result[@enumToInt(Feature.bmi2)] = .{
292 .llvm_name = "bmi2",
293 .description = "Support BMI2 instructions",
294 .dependencies = featureSet(&[_]Feature{}),
295 };
296 result[@enumToInt(Feature.branchfusion)] = .{
297 .llvm_name = "branchfusion",
298 .description = "CMP/TEST can be fused with conditional branches",
299 .dependencies = featureSet(&[_]Feature{}),
300 };
301 result[@enumToInt(Feature.cldemote)] = .{
302 .llvm_name = "cldemote",
303 .description = "Enable Cache Demote",
304 .dependencies = featureSet(&[_]Feature{}),
305 };
306 result[@enumToInt(Feature.clflushopt)] = .{
307 .llvm_name = "clflushopt",
308 .description = "Flush A Cache Line Optimized",
309 .dependencies = featureSet(&[_]Feature{}),
310 };
311 result[@enumToInt(Feature.clwb)] = .{
312 .llvm_name = "clwb",
313 .description = "Cache Line Write Back",
314 .dependencies = featureSet(&[_]Feature{}),
315 };
316 result[@enumToInt(Feature.clzero)] = .{
317 .llvm_name = "clzero",
318 .description = "Enable Cache Line Zero",
319 .dependencies = featureSet(&[_]Feature{}),
320 };
321 result[@enumToInt(Feature.cmov)] = .{
322 .llvm_name = "cmov",
323 .description = "Enable conditional move instructions",
324 .dependencies = featureSet(&[_]Feature{}),
325 };
326 result[@enumToInt(Feature.cx16)] = .{
327 .llvm_name = "cx16",
328 .description = "64-bit with cmpxchg16b",
329 .dependencies = featureSet(&[_]Feature{
330 .cx8,
331 }),
332 };
333 result[@enumToInt(Feature.cx8)] = .{
334 .llvm_name = "cx8",
335 .description = "Support CMPXCHG8B instructions",
336 .dependencies = featureSet(&[_]Feature{}),
337 };
338 result[@enumToInt(Feature.enqcmd)] = .{
339 .llvm_name = "enqcmd",
340 .description = "Has ENQCMD instructions",
341 .dependencies = featureSet(&[_]Feature{}),
342 };
343 result[@enumToInt(Feature.ermsb)] = .{
344 .llvm_name = "ermsb",
345 .description = "REP MOVS/STOS are fast",
346 .dependencies = featureSet(&[_]Feature{}),
347 };
348 result[@enumToInt(Feature.f16c)] = .{
349 .llvm_name = "f16c",
350 .description = "Support 16-bit floating point conversion instructions",
351 .dependencies = featureSet(&[_]Feature{
352 .avx,
353 }),
354 };
355 result[@enumToInt(Feature.false_deps_lzcnt_tzcnt)] = .{
356 .llvm_name = "false-deps-lzcnt-tzcnt",
357 .description = "LZCNT/TZCNT have a false dependency on dest register",
358 .dependencies = featureSet(&[_]Feature{}),
359 };
360 result[@enumToInt(Feature.false_deps_popcnt)] = .{
361 .llvm_name = "false-deps-popcnt",
362 .description = "POPCNT has a false dependency on dest register",
363 .dependencies = featureSet(&[_]Feature{}),
364 };
365 result[@enumToInt(Feature.fast_11bytenop)] = .{
366 .llvm_name = "fast-11bytenop",
367 .description = "Target can quickly decode up to 11 byte NOPs",
368 .dependencies = featureSet(&[_]Feature{}),
369 };
370 result[@enumToInt(Feature.fast_15bytenop)] = .{
371 .llvm_name = "fast-15bytenop",
372 .description = "Target can quickly decode up to 15 byte NOPs",
373 .dependencies = featureSet(&[_]Feature{}),
374 };
375 result[@enumToInt(Feature.fast_bextr)] = .{
376 .llvm_name = "fast-bextr",
377 .description = "Indicates that the BEXTR instruction is implemented as a single uop with good throughput",
378 .dependencies = featureSet(&[_]Feature{}),
379 };
380 result[@enumToInt(Feature.fast_gather)] = .{
381 .llvm_name = "fast-gather",
382 .description = "Indicates if gather is reasonably fast",
383 .dependencies = featureSet(&[_]Feature{}),
384 };
385 result[@enumToInt(Feature.fast_hops)] = .{
386 .llvm_name = "fast-hops",
387 .description = "Prefer horizontal vector math instructions (haddp, phsub, etc.) over normal vector instructions with shuffles",
388 .dependencies = featureSet(&[_]Feature{
389 .sse3,
390 }),
391 };
392 result[@enumToInt(Feature.fast_lzcnt)] = .{
393 .llvm_name = "fast-lzcnt",
394 .description = "LZCNT instructions are as fast as most simple integer ops",
395 .dependencies = featureSet(&[_]Feature{}),
396 };
397 result[@enumToInt(Feature.fast_partial_ymm_or_zmm_write)] = .{
398 .llvm_name = "fast-partial-ymm-or-zmm-write",
399 .description = "Partial writes to YMM/ZMM registers are fast",
400 .dependencies = featureSet(&[_]Feature{}),
401 };
402 result[@enumToInt(Feature.fast_scalar_fsqrt)] = .{
403 .llvm_name = "fast-scalar-fsqrt",
404 .description = "Scalar SQRT is fast (disable Newton-Raphson)",
405 .dependencies = featureSet(&[_]Feature{}),
406 };
407 result[@enumToInt(Feature.fast_scalar_shift_masks)] = .{
408 .llvm_name = "fast-scalar-shift-masks",
409 .description = "Prefer a left/right scalar logical shift pair over a shift+and pair",
410 .dependencies = featureSet(&[_]Feature{}),
411 };
412 result[@enumToInt(Feature.fast_shld_rotate)] = .{
413 .llvm_name = "fast-shld-rotate",
414 .description = "SHLD can be used as a faster rotate",
415 .dependencies = featureSet(&[_]Feature{}),
416 };
417 result[@enumToInt(Feature.fast_variable_shuffle)] = .{
418 .llvm_name = "fast-variable-shuffle",
419 .description = "Shuffles with variable masks are fast",
420 .dependencies = featureSet(&[_]Feature{}),
421 };
422 result[@enumToInt(Feature.fast_vector_fsqrt)] = .{
423 .llvm_name = "fast-vector-fsqrt",
424 .description = "Vector SQRT is fast (disable Newton-Raphson)",
425 .dependencies = featureSet(&[_]Feature{}),
426 };
427 result[@enumToInt(Feature.fast_vector_shift_masks)] = .{
428 .llvm_name = "fast-vector-shift-masks",
429 .description = "Prefer a left/right vector logical shift pair over a shift+and pair",
430 .dependencies = featureSet(&[_]Feature{}),
431 };
432 result[@enumToInt(Feature.fma)] = .{
433 .llvm_name = "fma",
434 .description = "Enable three-operand fused multiple-add",
435 .dependencies = featureSet(&[_]Feature{
436 .avx,
437 }),
438 };
439 result[@enumToInt(Feature.fma4)] = .{
440 .llvm_name = "fma4",
441 .description = "Enable four-operand fused multiple-add",
442 .dependencies = featureSet(&[_]Feature{
443 .avx,
444 .sse4a,
445 }),
446 };
447 result[@enumToInt(Feature.fsgsbase)] = .{
448 .llvm_name = "fsgsbase",
449 .description = "Support FS/GS Base instructions",
450 .dependencies = featureSet(&[_]Feature{}),
451 };
452 result[@enumToInt(Feature.fxsr)] = .{
453 .llvm_name = "fxsr",
454 .description = "Support fxsave/fxrestore instructions",
455 .dependencies = featureSet(&[_]Feature{}),
456 };
457 result[@enumToInt(Feature.gfni)] = .{
458 .llvm_name = "gfni",
459 .description = "Enable Galois Field Arithmetic Instructions",
460 .dependencies = featureSet(&[_]Feature{
461 .sse2,
462 }),
463 };
464 result[@enumToInt(Feature.idivl_to_divb)] = .{
465 .llvm_name = "idivl-to-divb",
466 .description = "Use 8-bit divide for positive values less than 256",
467 .dependencies = featureSet(&[_]Feature{}),
468 };
469 result[@enumToInt(Feature.idivq_to_divl)] = .{
470 .llvm_name = "idivq-to-divl",
471 .description = "Use 32-bit divide for positive values less than 2^32",
472 .dependencies = featureSet(&[_]Feature{}),
473 };
474 result[@enumToInt(Feature.invpcid)] = .{
475 .llvm_name = "invpcid",
476 .description = "Invalidate Process-Context Identifier",
477 .dependencies = featureSet(&[_]Feature{}),
478 };
479 result[@enumToInt(Feature.lea_sp)] = .{
480 .llvm_name = "lea-sp",
481 .description = "Use LEA for adjusting the stack pointer",
482 .dependencies = featureSet(&[_]Feature{}),
483 };
484 result[@enumToInt(Feature.lea_uses_ag)] = .{
485 .llvm_name = "lea-uses-ag",
486 .description = "LEA instruction needs inputs at AG stage",
487 .dependencies = featureSet(&[_]Feature{}),
488 };
489 result[@enumToInt(Feature.lwp)] = .{
490 .llvm_name = "lwp",
491 .description = "Enable LWP instructions",
492 .dependencies = featureSet(&[_]Feature{}),
493 };
494 result[@enumToInt(Feature.lzcnt)] = .{
495 .llvm_name = "lzcnt",
496 .description = "Support LZCNT instruction",
497 .dependencies = featureSet(&[_]Feature{}),
498 };
499 result[@enumToInt(Feature.macrofusion)] = .{
500 .llvm_name = "macrofusion",
501 .description = "Various instructions can be fused with conditional branches",
502 .dependencies = featureSet(&[_]Feature{}),
503 };
504 result[@enumToInt(Feature.merge_to_threeway_branch)] = .{
505 .llvm_name = "merge-to-threeway-branch",
506 .description = "Merge branches to a three-way conditional branch",
507 .dependencies = featureSet(&[_]Feature{}),
508 };
509 result[@enumToInt(Feature.mmx)] = .{
510 .llvm_name = "mmx",
511 .description = "Enable MMX instructions",
512 .dependencies = featureSet(&[_]Feature{}),
513 };
514 result[@enumToInt(Feature.movbe)] = .{
515 .llvm_name = "movbe",
516 .description = "Support MOVBE instruction",
517 .dependencies = featureSet(&[_]Feature{}),
518 };
519 result[@enumToInt(Feature.movdir64b)] = .{
520 .llvm_name = "movdir64b",
521 .description = "Support movdir64b instruction",
522 .dependencies = featureSet(&[_]Feature{}),
523 };
524 result[@enumToInt(Feature.movdiri)] = .{
525 .llvm_name = "movdiri",
526 .description = "Support movdiri instruction",
527 .dependencies = featureSet(&[_]Feature{}),
528 };
529 result[@enumToInt(Feature.mpx)] = .{
530 .llvm_name = "mpx",
531 .description = "Support MPX instructions",
532 .dependencies = featureSet(&[_]Feature{}),
533 };
534 result[@enumToInt(Feature.mwaitx)] = .{
535 .llvm_name = "mwaitx",
536 .description = "Enable MONITORX/MWAITX timer functionality",
537 .dependencies = featureSet(&[_]Feature{}),
538 };
539 result[@enumToInt(Feature.nopl)] = .{
540 .llvm_name = "nopl",
541 .description = "Enable NOPL instruction",
542 .dependencies = featureSet(&[_]Feature{}),
543 };
544 result[@enumToInt(Feature.pad_short_functions)] = .{
545 .llvm_name = "pad-short-functions",
546 .description = "Pad short functions",
547 .dependencies = featureSet(&[_]Feature{}),
548 };
549 result[@enumToInt(Feature.pclmul)] = .{
550 .llvm_name = "pclmul",
551 .description = "Enable packed carry-less multiplication instructions",
552 .dependencies = featureSet(&[_]Feature{
553 .sse2,
554 }),
555 };
556 result[@enumToInt(Feature.pconfig)] = .{
557 .llvm_name = "pconfig",
558 .description = "platform configuration instruction",
559 .dependencies = featureSet(&[_]Feature{}),
560 };
561 result[@enumToInt(Feature.pku)] = .{
562 .llvm_name = "pku",
563 .description = "Enable protection keys",
564 .dependencies = featureSet(&[_]Feature{}),
565 };
566 result[@enumToInt(Feature.popcnt)] = .{
567 .llvm_name = "popcnt",
568 .description = "Support POPCNT instruction",
569 .dependencies = featureSet(&[_]Feature{}),
570 };
571 result[@enumToInt(Feature.prefer_256_bit)] = .{
572 .llvm_name = "prefer-256-bit",
573 .description = "Prefer 256-bit AVX instructions",
574 .dependencies = featureSet(&[_]Feature{}),
575 };
576 result[@enumToInt(Feature.prefetchwt1)] = .{
577 .llvm_name = "prefetchwt1",
578 .description = "Prefetch with Intent to Write and T1 Hint",
579 .dependencies = featureSet(&[_]Feature{}),
580 };
581 result[@enumToInt(Feature.prfchw)] = .{
582 .llvm_name = "prfchw",
583 .description = "Support PRFCHW instructions",
584 .dependencies = featureSet(&[_]Feature{}),
585 };
586 result[@enumToInt(Feature.ptwrite)] = .{
587 .llvm_name = "ptwrite",
588 .description = "Support ptwrite instruction",
589 .dependencies = featureSet(&[_]Feature{}),
590 };
591 result[@enumToInt(Feature.rdpid)] = .{
592 .llvm_name = "rdpid",
593 .description = "Support RDPID instructions",
594 .dependencies = featureSet(&[_]Feature{}),
595 };
596 result[@enumToInt(Feature.rdrnd)] = .{
597 .llvm_name = "rdrnd",
598 .description = "Support RDRAND instruction",
599 .dependencies = featureSet(&[_]Feature{}),
600 };
601 result[@enumToInt(Feature.rdseed)] = .{
602 .llvm_name = "rdseed",
603 .description = "Support RDSEED instruction",
604 .dependencies = featureSet(&[_]Feature{}),
605 };
606 result[@enumToInt(Feature.retpoline)] = .{
607 .llvm_name = "retpoline",
608 .description = "Remove speculation of indirect branches from the generated code, either by avoiding them entirely or lowering them with a speculation blocking construct",
609 .dependencies = featureSet(&[_]Feature{
610 .retpoline_indirect_branches,
611 .retpoline_indirect_calls,
612 }),
613 };
614 result[@enumToInt(Feature.retpoline_external_thunk)] = .{
615 .llvm_name = "retpoline-external-thunk",
616 .description = "When lowering an indirect call or branch using a `retpoline`, rely on the specified user provided thunk rather than emitting one ourselves. Only has effect when combined with some other retpoline feature",
617 .dependencies = featureSet(&[_]Feature{
618 .retpoline_indirect_calls,
619 }),
620 };
621 result[@enumToInt(Feature.retpoline_indirect_branches)] = .{
622 .llvm_name = "retpoline-indirect-branches",
623 .description = "Remove speculation of indirect branches from the generated code",
624 .dependencies = featureSet(&[_]Feature{}),
625 };
626 result[@enumToInt(Feature.retpoline_indirect_calls)] = .{
627 .llvm_name = "retpoline-indirect-calls",
628 .description = "Remove speculation of indirect calls from the generated code",
629 .dependencies = featureSet(&[_]Feature{}),
630 };
631 result[@enumToInt(Feature.rtm)] = .{
632 .llvm_name = "rtm",
633 .description = "Support RTM instructions",
634 .dependencies = featureSet(&[_]Feature{}),
635 };
636 result[@enumToInt(Feature.sahf)] = .{
637 .llvm_name = "sahf",
638 .description = "Support LAHF and SAHF instructions",
639 .dependencies = featureSet(&[_]Feature{}),
640 };
641 result[@enumToInt(Feature.sgx)] = .{
642 .llvm_name = "sgx",
643 .description = "Enable Software Guard Extensions",
644 .dependencies = featureSet(&[_]Feature{}),
645 };
646 result[@enumToInt(Feature.sha)] = .{
647 .llvm_name = "sha",
648 .description = "Enable SHA instructions",
649 .dependencies = featureSet(&[_]Feature{
650 .sse2,
651 }),
652 };
653 result[@enumToInt(Feature.shstk)] = .{
654 .llvm_name = "shstk",
655 .description = "Support CET Shadow-Stack instructions",
656 .dependencies = featureSet(&[_]Feature{}),
657 };
658 result[@enumToInt(Feature.slow_3ops_lea)] = .{
659 .llvm_name = "slow-3ops-lea",
660 .description = "LEA instruction with 3 ops or certain registers is slow",
661 .dependencies = featureSet(&[_]Feature{}),
662 };
663 result[@enumToInt(Feature.slow_incdec)] = .{
664 .llvm_name = "slow-incdec",
665 .description = "INC and DEC instructions are slower than ADD and SUB",
666 .dependencies = featureSet(&[_]Feature{}),
667 };
668 result[@enumToInt(Feature.slow_lea)] = .{
669 .llvm_name = "slow-lea",
670 .description = "LEA instruction with certain arguments is slow",
671 .dependencies = featureSet(&[_]Feature{}),
672 };
673 result[@enumToInt(Feature.slow_pmaddwd)] = .{
674 .llvm_name = "slow-pmaddwd",
675 .description = "PMADDWD is slower than PMULLD",
676 .dependencies = featureSet(&[_]Feature{}),
677 };
678 result[@enumToInt(Feature.slow_pmulld)] = .{
679 .llvm_name = "slow-pmulld",
680 .description = "PMULLD instruction is slow",
681 .dependencies = featureSet(&[_]Feature{}),
682 };
683 result[@enumToInt(Feature.slow_shld)] = .{
684 .llvm_name = "slow-shld",
685 .description = "SHLD instruction is slow",
686 .dependencies = featureSet(&[_]Feature{}),
687 };
688 result[@enumToInt(Feature.slow_two_mem_ops)] = .{
689 .llvm_name = "slow-two-mem-ops",
690 .description = "Two memory operand instructions are slow",
691 .dependencies = featureSet(&[_]Feature{}),
692 };
693 result[@enumToInt(Feature.slow_unaligned_mem_16)] = .{
694 .llvm_name = "slow-unaligned-mem-16",
695 .description = "Slow unaligned 16-byte memory access",
696 .dependencies = featureSet(&[_]Feature{}),
697 };
698 result[@enumToInt(Feature.slow_unaligned_mem_32)] = .{
699 .llvm_name = "slow-unaligned-mem-32",
700 .description = "Slow unaligned 32-byte memory access",
701 .dependencies = featureSet(&[_]Feature{}),
702 };
703 result[@enumToInt(Feature.soft_float)] = .{
704 .llvm_name = "soft-float",
705 .description = "Use software floating point features",
706 .dependencies = featureSet(&[_]Feature{}),
707 };
708 result[@enumToInt(Feature.sse)] = .{
709 .llvm_name = "sse",
710 .description = "Enable SSE instructions",
711 .dependencies = featureSet(&[_]Feature{}),
712 };
713 result[@enumToInt(Feature.sse_unaligned_mem)] = .{
714 .llvm_name = "sse-unaligned-mem",
715 .description = "Allow unaligned memory operands with SSE instructions",
716 .dependencies = featureSet(&[_]Feature{}),
717 };
718 result[@enumToInt(Feature.sse2)] = .{
719 .llvm_name = "sse2",
720 .description = "Enable SSE2 instructions",
721 .dependencies = featureSet(&[_]Feature{
722 .sse,
723 }),
724 };
725 result[@enumToInt(Feature.sse3)] = .{
726 .llvm_name = "sse3",
727 .description = "Enable SSE3 instructions",
728 .dependencies = featureSet(&[_]Feature{
729 .sse2,
730 }),
731 };
732 result[@enumToInt(Feature.sse4_1)] = .{
733 .llvm_name = "sse4.1",
734 .description = "Enable SSE 4.1 instructions",
735 .dependencies = featureSet(&[_]Feature{
736 .ssse3,
737 }),
738 };
739 result[@enumToInt(Feature.sse4_2)] = .{
740 .llvm_name = "sse4.2",
741 .description = "Enable SSE 4.2 instructions",
742 .dependencies = featureSet(&[_]Feature{
743 .sse4_1,
744 }),
745 };
746 result[@enumToInt(Feature.sse4a)] = .{
747 .llvm_name = "sse4a",
748 .description = "Support SSE 4a instructions",
749 .dependencies = featureSet(&[_]Feature{
750 .sse3,
751 }),
752 };
753 result[@enumToInt(Feature.ssse3)] = .{
754 .llvm_name = "ssse3",
755 .description = "Enable SSSE3 instructions",
756 .dependencies = featureSet(&[_]Feature{
757 .sse3,
758 }),
759 };
760 result[@enumToInt(Feature.tbm)] = .{
761 .llvm_name = "tbm",
762 .description = "Enable TBM instructions",
763 .dependencies = featureSet(&[_]Feature{}),
764 };
765 result[@enumToInt(Feature.vaes)] = .{
766 .llvm_name = "vaes",
767 .description = "Promote selected AES instructions to AVX512/AVX registers",
768 .dependencies = featureSet(&[_]Feature{
769 .aes,
770 .avx,
771 }),
772 };
773 result[@enumToInt(Feature.vpclmulqdq)] = .{
774 .llvm_name = "vpclmulqdq",
775 .description = "Enable vpclmulqdq instructions",
776 .dependencies = featureSet(&[_]Feature{
777 .avx,
778 .pclmul,
779 }),
780 };
781 result[@enumToInt(Feature.waitpkg)] = .{
782 .llvm_name = "waitpkg",
783 .description = "Wait and pause enhancements",
784 .dependencies = featureSet(&[_]Feature{}),
785 };
786 result[@enumToInt(Feature.wbnoinvd)] = .{
787 .llvm_name = "wbnoinvd",
788 .description = "Write Back No Invalidate",
789 .dependencies = featureSet(&[_]Feature{}),
790 };
791 result[@enumToInt(Feature.x87)] = .{
792 .llvm_name = "x87",
793 .description = "Enable X87 float instructions",
794 .dependencies = featureSet(&[_]Feature{}),
795 };
796 result[@enumToInt(Feature.xop)] = .{
797 .llvm_name = "xop",
798 .description = "Enable XOP instructions",
799 .dependencies = featureSet(&[_]Feature{
800 .fma4,
801 }),
802 };
803 result[@enumToInt(Feature.xsave)] = .{
804 .llvm_name = "xsave",
805 .description = "Support xsave instructions",
806 .dependencies = featureSet(&[_]Feature{}),
807 };
808 result[@enumToInt(Feature.xsavec)] = .{
809 .llvm_name = "xsavec",
810 .description = "Support xsavec instructions",
811 .dependencies = featureSet(&[_]Feature{}),
812 };
813 result[@enumToInt(Feature.xsaveopt)] = .{
814 .llvm_name = "xsaveopt",
815 .description = "Support xsaveopt instructions",
816 .dependencies = featureSet(&[_]Feature{}),
817 };
818 result[@enumToInt(Feature.xsaves)] = .{
819 .llvm_name = "xsaves",
820 .description = "Support xsaves instructions",
821 .dependencies = featureSet(&[_]Feature{}),
822 };
823 const ti = @typeInfo(Feature);
824 for (result) |*elem, i| {
825 elem.index = i;
826 elem.name = ti.Enum.fields[i].name;
827 }
828 break :blk result;
829};
830
831pub const cpu = struct {
832 pub const amdfam10 = Cpu{
833 .name = "amdfam10",
834 .llvm_name = "amdfam10",
835 .features = featureSet(&[_]Feature{
836 .@"3dnowa",
837 .@"64bit",
838 .cmov,
839 .cx16,
840 .cx8,
841 .fast_scalar_shift_masks,
842 .fxsr,
843 .lzcnt,
844 .nopl,
845 .popcnt,
846 .sahf,
847 .slow_shld,
848 .sse4a,
849 .x87,
850 }),
851 };
852 pub const athlon = Cpu{
853 .name = "athlon",
854 .llvm_name = "athlon",
855 .features = featureSet(&[_]Feature{
856 .@"3dnowa",
857 .cmov,
858 .cx8,
859 .nopl,
860 .slow_shld,
861 .slow_unaligned_mem_16,
862 .x87,
863 }),
864 };
865 pub const athlon_4 = Cpu{
866 .name = "athlon_4",
867 .llvm_name = "athlon-4",
868 .features = featureSet(&[_]Feature{
869 .@"3dnowa",
870 .cmov,
871 .cx8,
872 .fxsr,
873 .nopl,
874 .slow_shld,
875 .slow_unaligned_mem_16,
876 .sse,
877 .x87,
878 }),
879 };
880 pub const athlon_fx = Cpu{
881 .name = "athlon_fx",
882 .llvm_name = "athlon-fx",
883 .features = featureSet(&[_]Feature{
884 .@"3dnowa",
885 .@"64bit",
886 .cmov,
887 .cx8,
888 .fast_scalar_shift_masks,
889 .fxsr,
890 .nopl,
891 .slow_shld,
892 .slow_unaligned_mem_16,
893 .sse2,
894 .x87,
895 }),
896 };
897 pub const athlon_mp = Cpu{
898 .name = "athlon_mp",
899 .llvm_name = "athlon-mp",
900 .features = featureSet(&[_]Feature{
901 .@"3dnowa",
902 .cmov,
903 .cx8,
904 .fxsr,
905 .nopl,
906 .slow_shld,
907 .slow_unaligned_mem_16,
908 .sse,
909 .x87,
910 }),
911 };
912 pub const athlon_tbird = Cpu{
913 .name = "athlon_tbird",
914 .llvm_name = "athlon-tbird",
915 .features = featureSet(&[_]Feature{
916 .@"3dnowa",
917 .cmov,
918 .cx8,
919 .nopl,
920 .slow_shld,
921 .slow_unaligned_mem_16,
922 .x87,
923 }),
924 };
925 pub const athlon_xp = Cpu{
926 .name = "athlon_xp",
927 .llvm_name = "athlon-xp",
928 .features = featureSet(&[_]Feature{
929 .@"3dnowa",
930 .cmov,
931 .cx8,
932 .fxsr,
933 .nopl,
934 .slow_shld,
935 .slow_unaligned_mem_16,
936 .sse,
937 .x87,
938 }),
939 };
940 pub const athlon64 = Cpu{
941 .name = "athlon64",
942 .llvm_name = "athlon64",
943 .features = featureSet(&[_]Feature{
944 .@"3dnowa",
945 .@"64bit",
946 .cmov,
947 .cx8,
948 .fast_scalar_shift_masks,
949 .fxsr,
950 .nopl,
951 .slow_shld,
952 .slow_unaligned_mem_16,
953 .sse2,
954 .x87,
955 }),
956 };
957 pub const athlon64_sse3 = Cpu{
958 .name = "athlon64_sse3",
959 .llvm_name = "athlon64-sse3",
960 .features = featureSet(&[_]Feature{
961 .@"3dnowa",
962 .@"64bit",
963 .cmov,
964 .cx16,
965 .cx8,
966 .fast_scalar_shift_masks,
967 .fxsr,
968 .nopl,
969 .slow_shld,
970 .slow_unaligned_mem_16,
971 .sse3,
972 .x87,
973 }),
974 };
975 pub const atom = Cpu{
976 .name = "atom",
977 .llvm_name = "atom",
978 .features = featureSet(&[_]Feature{
979 .@"64bit",
980 .cmov,
981 .cx16,
982 .cx8,
983 .fxsr,
984 .idivl_to_divb,
985 .idivq_to_divl,
986 .lea_sp,
987 .lea_uses_ag,
988 .mmx,
989 .movbe,
990 .nopl,
991 .pad_short_functions,
992 .sahf,
993 .slow_two_mem_ops,
994 .slow_unaligned_mem_16,
995 .ssse3,
996 .x87,
997 }),
998 };
999 pub const barcelona = Cpu{
1000 .name = "barcelona",
1001 .llvm_name = "barcelona",
1002 .features = featureSet(&[_]Feature{
1003 .@"3dnowa",
1004 .@"64bit",
1005 .cmov,
1006 .cx16,
1007 .cx8,
1008 .fast_scalar_shift_masks,
1009 .fxsr,
1010 .lzcnt,
1011 .nopl,
1012 .popcnt,
1013 .sahf,
1014 .slow_shld,
1015 .sse4a,
1016 .x87,
1017 }),
1018 };
1019 pub const bdver1 = Cpu{
1020 .name = "bdver1",
1021 .llvm_name = "bdver1",
1022 .features = featureSet(&[_]Feature{
1023 .@"64bit",
1024 .aes,
1025 .branchfusion,
1026 .cmov,
1027 .cx16,
1028 .cx8,
1029 .fast_11bytenop,
1030 .fast_scalar_shift_masks,
1031 .fxsr,
1032 .lwp,
1033 .lzcnt,
1034 .mmx,
1035 .nopl,
1036 .pclmul,
1037 .popcnt,
1038 .prfchw,
1039 .sahf,
1040 .slow_shld,
1041 .x87,
1042 .xop,
1043 .xsave,
1044 }),
1045 };
1046 pub const bdver2 = Cpu{
1047 .name = "bdver2",
1048 .llvm_name = "bdver2",
1049 .features = featureSet(&[_]Feature{
1050 .@"64bit",
1051 .aes,
1052 .bmi,
1053 .branchfusion,
1054 .cmov,
1055 .cx16,
1056 .cx8,
1057 .f16c,
1058 .fast_11bytenop,
1059 .fast_bextr,
1060 .fast_scalar_shift_masks,
1061 .fma,
1062 .fxsr,
1063 .lwp,
1064 .lzcnt,
1065 .mmx,
1066 .nopl,
1067 .pclmul,
1068 .popcnt,
1069 .prfchw,
1070 .sahf,
1071 .slow_shld,
1072 .tbm,
1073 .x87,
1074 .xop,
1075 .xsave,
1076 }),
1077 };
1078 pub const bdver3 = Cpu{
1079 .name = "bdver3",
1080 .llvm_name = "bdver3",
1081 .features = featureSet(&[_]Feature{
1082 .@"64bit",
1083 .aes,
1084 .bmi,
1085 .branchfusion,
1086 .cmov,
1087 .cx16,
1088 .cx8,
1089 .f16c,
1090 .fast_11bytenop,
1091 .fast_bextr,
1092 .fast_scalar_shift_masks,
1093 .fma,
1094 .fsgsbase,
1095 .fxsr,
1096 .lwp,
1097 .lzcnt,
1098 .mmx,
1099 .nopl,
1100 .pclmul,
1101 .popcnt,
1102 .prfchw,
1103 .sahf,
1104 .slow_shld,
1105 .tbm,
1106 .x87,
1107 .xop,
1108 .xsave,
1109 .xsaveopt,
1110 }),
1111 };
1112 pub const bdver4 = Cpu{
1113 .name = "bdver4",
1114 .llvm_name = "bdver4",
1115 .features = featureSet(&[_]Feature{
1116 .@"64bit",
1117 .aes,
1118 .avx2,
1119 .bmi,
1120 .bmi2,
1121 .branchfusion,
1122 .cmov,
1123 .cx16,
1124 .cx8,
1125 .f16c,
1126 .fast_11bytenop,
1127 .fast_bextr,
1128 .fast_scalar_shift_masks,
1129 .fma,
1130 .fsgsbase,
1131 .fxsr,
1132 .lwp,
1133 .lzcnt,
1134 .mmx,
1135 .mwaitx,
1136 .nopl,
1137 .pclmul,
1138 .popcnt,
1139 .prfchw,
1140 .sahf,
1141 .slow_shld,
1142 .tbm,
1143 .x87,
1144 .xop,
1145 .xsave,
1146 .xsaveopt,
1147 }),
1148 };
1149 pub const bonnell = Cpu{
1150 .name = "bonnell",
1151 .llvm_name = "bonnell",
1152 .features = featureSet(&[_]Feature{
1153 .@"64bit",
1154 .cmov,
1155 .cx16,
1156 .cx8,
1157 .fxsr,
1158 .idivl_to_divb,
1159 .idivq_to_divl,
1160 .lea_sp,
1161 .lea_uses_ag,
1162 .mmx,
1163 .movbe,
1164 .nopl,
1165 .pad_short_functions,
1166 .sahf,
1167 .slow_two_mem_ops,
1168 .slow_unaligned_mem_16,
1169 .ssse3,
1170 .x87,
1171 }),
1172 };
1173 pub const broadwell = Cpu{
1174 .name = "broadwell",
1175 .llvm_name = "broadwell",
1176 .features = featureSet(&[_]Feature{
1177 .@"64bit",
1178 .adx,
1179 .avx,
1180 .avx2,
1181 .bmi,
1182 .bmi2,
1183 .cmov,
1184 .cx16,
1185 .cx8,
1186 .ermsb,
1187 .f16c,
1188 .false_deps_lzcnt_tzcnt,
1189 .false_deps_popcnt,
1190 .fast_scalar_fsqrt,
1191 .fast_shld_rotate,
1192 .fast_variable_shuffle,
1193 .fma,
1194 .fsgsbase,
1195 .fxsr,
1196 .idivq_to_divl,
1197 .invpcid,
1198 .lzcnt,
1199 .macrofusion,
1200 .merge_to_threeway_branch,
1201 .mmx,
1202 .movbe,
1203 .nopl,
1204 .pclmul,
1205 .popcnt,
1206 .prfchw,
1207 .rdrnd,
1208 .rdseed,
1209 .sahf,
1210 .slow_3ops_lea,
1211 .sse4_2,
1212 .x87,
1213 .xsave,
1214 .xsaveopt,
1215 }),
1216 };
1217 pub const btver1 = Cpu{
1218 .name = "btver1",
1219 .llvm_name = "btver1",
1220 .features = featureSet(&[_]Feature{
1221 .@"64bit",
1222 .cmov,
1223 .cx16,
1224 .cx8,
1225 .fast_15bytenop,
1226 .fast_scalar_shift_masks,
1227 .fast_vector_shift_masks,
1228 .fxsr,
1229 .lzcnt,
1230 .mmx,
1231 .nopl,
1232 .popcnt,
1233 .prfchw,
1234 .sahf,
1235 .slow_shld,
1236 .sse4a,
1237 .ssse3,
1238 .x87,
1239 }),
1240 };
1241 pub const btver2 = Cpu{
1242 .name = "btver2",
1243 .llvm_name = "btver2",
1244 .features = featureSet(&[_]Feature{
1245 .@"64bit",
1246 .aes,
1247 .avx,
1248 .bmi,
1249 .cmov,
1250 .cx16,
1251 .cx8,
1252 .f16c,
1253 .fast_15bytenop,
1254 .fast_bextr,
1255 .fast_hops,
1256 .fast_lzcnt,
1257 .fast_partial_ymm_or_zmm_write,
1258 .fast_scalar_shift_masks,
1259 .fast_vector_shift_masks,
1260 .fxsr,
1261 .lzcnt,
1262 .mmx,
1263 .movbe,
1264 .nopl,
1265 .pclmul,
1266 .popcnt,
1267 .prfchw,
1268 .sahf,
1269 .slow_shld,
1270 .sse4a,
1271 .ssse3,
1272 .x87,
1273 .xsave,
1274 .xsaveopt,
1275 }),
1276 };
1277 pub const c3 = Cpu{
1278 .name = "c3",
1279 .llvm_name = "c3",
1280 .features = featureSet(&[_]Feature{
1281 .@"3dnow",
1282 .slow_unaligned_mem_16,
1283 .x87,
1284 }),
1285 };
1286 pub const c3_2 = Cpu{
1287 .name = "c3_2",
1288 .llvm_name = "c3-2",
1289 .features = featureSet(&[_]Feature{
1290 .cmov,
1291 .cx8,
1292 .fxsr,
1293 .mmx,
1294 .slow_unaligned_mem_16,
1295 .sse,
1296 .x87,
1297 }),
1298 };
1299 pub const cannonlake = Cpu{
1300 .name = "cannonlake",
1301 .llvm_name = "cannonlake",
1302 .features = featureSet(&[_]Feature{
1303 .@"64bit",
1304 .adx,
1305 .aes,
1306 .avx,
1307 .avx2,
1308 .avx512bw,
1309 .avx512cd,
1310 .avx512dq,
1311 .avx512f,
1312 .avx512ifma,
1313 .avx512vbmi,
1314 .avx512vl,
1315 .bmi,
1316 .bmi2,
1317 .clflushopt,
1318 .cmov,
1319 .cx16,
1320 .cx8,
1321 .ermsb,
1322 .f16c,
1323 .fast_gather,
1324 .fast_scalar_fsqrt,
1325 .fast_shld_rotate,
1326 .fast_variable_shuffle,
1327 .fast_vector_fsqrt,
1328 .fma,
1329 .fsgsbase,
1330 .fxsr,
1331 .idivq_to_divl,
1332 .invpcid,
1333 .lzcnt,
1334 .macrofusion,
1335 .merge_to_threeway_branch,
1336 .mmx,
1337 .movbe,
1338 .mpx,
1339 .nopl,
1340 .pclmul,
1341 .pku,
1342 .popcnt,
1343 .prfchw,
1344 .rdrnd,
1345 .rdseed,
1346 .sahf,
1347 .sgx,
1348 .sha,
1349 .slow_3ops_lea,
1350 .sse4_2,
1351 .x87,
1352 .xsave,
1353 .xsavec,
1354 .xsaveopt,
1355 .xsaves,
1356 }),
1357 };
1358 pub const cascadelake = Cpu{
1359 .name = "cascadelake",
1360 .llvm_name = "cascadelake",
1361 .features = featureSet(&[_]Feature{
1362 .@"64bit",
1363 .adx,
1364 .aes,
1365 .avx,
1366 .avx2,
1367 .avx512bw,
1368 .avx512cd,
1369 .avx512dq,
1370 .avx512f,
1371 .avx512vl,
1372 .avx512vnni,
1373 .bmi,
1374 .bmi2,
1375 .clflushopt,
1376 .clwb,
1377 .cmov,
1378 .cx16,
1379 .cx8,
1380 .ermsb,
1381 .f16c,
1382 .false_deps_popcnt,
1383 .fast_gather,
1384 .fast_scalar_fsqrt,
1385 .fast_shld_rotate,
1386 .fast_variable_shuffle,
1387 .fast_vector_fsqrt,
1388 .fma,
1389 .fsgsbase,
1390 .fxsr,
1391 .idivq_to_divl,
1392 .invpcid,
1393 .lzcnt,
1394 .macrofusion,
1395 .merge_to_threeway_branch,
1396 .mmx,
1397 .movbe,
1398 .mpx,
1399 .nopl,
1400 .pclmul,
1401 .pku,
1402 .popcnt,
1403 .prfchw,
1404 .rdrnd,
1405 .rdseed,
1406 .sahf,
1407 .slow_3ops_lea,
1408 .sse4_2,
1409 .x87,
1410 .xsave,
1411 .xsavec,
1412 .xsaveopt,
1413 .xsaves,
1414 }),
1415 };
1416 pub const cooperlake = Cpu{
1417 .name = "cooperlake",
1418 .llvm_name = "cooperlake",
1419 .features = featureSet(&[_]Feature{
1420 .@"64bit",
1421 .adx,
1422 .aes,
1423 .avx,
1424 .avx2,
1425 .avx512bf16,
1426 .avx512bw,
1427 .avx512cd,
1428 .avx512dq,
1429 .avx512f,
1430 .avx512vl,
1431 .avx512vnni,
1432 .bmi,
1433 .bmi2,
1434 .clflushopt,
1435 .clwb,
1436 .cmov,
1437 .cx16,
1438 .cx8,
1439 .ermsb,
1440 .f16c,
1441 .false_deps_popcnt,
1442 .fast_gather,
1443 .fast_scalar_fsqrt,
1444 .fast_shld_rotate,
1445 .fast_variable_shuffle,
1446 .fast_vector_fsqrt,
1447 .fma,
1448 .fsgsbase,
1449 .fxsr,
1450 .idivq_to_divl,
1451 .invpcid,
1452 .lzcnt,
1453 .macrofusion,
1454 .merge_to_threeway_branch,
1455 .mmx,
1456 .movbe,
1457 .mpx,
1458 .nopl,
1459 .pclmul,
1460 .pku,
1461 .popcnt,
1462 .prfchw,
1463 .rdrnd,
1464 .rdseed,
1465 .sahf,
1466 .slow_3ops_lea,
1467 .sse4_2,
1468 .x87,
1469 .xsave,
1470 .xsavec,
1471 .xsaveopt,
1472 .xsaves,
1473 }),
1474 };
1475 pub const core_avx_i = Cpu{
1476 .name = "core_avx_i",
1477 .llvm_name = "core-avx-i",
1478 .features = featureSet(&[_]Feature{
1479 .@"64bit",
1480 .avx,
1481 .cmov,
1482 .cx16,
1483 .cx8,
1484 .f16c,
1485 .false_deps_popcnt,
1486 .fast_scalar_fsqrt,
1487 .fast_shld_rotate,
1488 .fsgsbase,
1489 .fxsr,
1490 .idivq_to_divl,
1491 .macrofusion,
1492 .merge_to_threeway_branch,
1493 .mmx,
1494 .nopl,
1495 .pclmul,
1496 .popcnt,
1497 .rdrnd,
1498 .sahf,
1499 .slow_3ops_lea,
1500 .slow_unaligned_mem_32,
1501 .sse4_2,
1502 .x87,
1503 .xsave,
1504 .xsaveopt,
1505 }),
1506 };
1507 pub const core_avx2 = Cpu{
1508 .name = "core_avx2",
1509 .llvm_name = "core-avx2",
1510 .features = featureSet(&[_]Feature{
1511 .@"64bit",
1512 .avx,
1513 .avx2,
1514 .bmi,
1515 .bmi2,
1516 .cmov,
1517 .cx16,
1518 .cx8,
1519 .ermsb,
1520 .f16c,
1521 .false_deps_lzcnt_tzcnt,
1522 .false_deps_popcnt,
1523 .fast_scalar_fsqrt,
1524 .fast_shld_rotate,
1525 .fast_variable_shuffle,
1526 .fma,
1527 .fsgsbase,
1528 .fxsr,
1529 .idivq_to_divl,
1530 .invpcid,
1531 .lzcnt,
1532 .macrofusion,
1533 .merge_to_threeway_branch,
1534 .mmx,
1535 .movbe,
1536 .nopl,
1537 .pclmul,
1538 .popcnt,
1539 .rdrnd,
1540 .sahf,
1541 .slow_3ops_lea,
1542 .sse4_2,
1543 .x87,
1544 .xsave,
1545 .xsaveopt,
1546 }),
1547 };
1548 pub const core2 = Cpu{
1549 .name = "core2",
1550 .llvm_name = "core2",
1551 .features = featureSet(&[_]Feature{
1552 .@"64bit",
1553 .cmov,
1554 .cx16,
1555 .cx8,
1556 .fxsr,
1557 .macrofusion,
1558 .mmx,
1559 .nopl,
1560 .sahf,
1561 .slow_unaligned_mem_16,
1562 .ssse3,
1563 .x87,
1564 }),
1565 };
1566 pub const corei7 = Cpu{
1567 .name = "corei7",
1568 .llvm_name = "corei7",
1569 .features = featureSet(&[_]Feature{
1570 .@"64bit",
1571 .cmov,
1572 .cx16,
1573 .cx8,
1574 .fxsr,
1575 .macrofusion,
1576 .mmx,
1577 .nopl,
1578 .popcnt,
1579 .sahf,
1580 .sse4_2,
1581 .x87,
1582 }),
1583 };
1584 pub const corei7_avx = Cpu{
1585 .name = "corei7_avx",
1586 .llvm_name = "corei7-avx",
1587 .features = featureSet(&[_]Feature{
1588 .@"64bit",
1589 .avx,
1590 .cmov,
1591 .cx16,
1592 .cx8,
1593 .false_deps_popcnt,
1594 .fast_scalar_fsqrt,
1595 .fast_shld_rotate,
1596 .fxsr,
1597 .idivq_to_divl,
1598 .macrofusion,
1599 .merge_to_threeway_branch,
1600 .mmx,
1601 .nopl,
1602 .pclmul,
1603 .popcnt,
1604 .sahf,
1605 .slow_3ops_lea,
1606 .slow_unaligned_mem_32,
1607 .sse4_2,
1608 .x87,
1609 .xsave,
1610 .xsaveopt,
1611 }),
1612 };
1613 pub const generic = Cpu{
1614 .name = "generic",
1615 .llvm_name = "generic",
1616 .features = featureSet(&[_]Feature{
1617 .cx8,
1618 .slow_unaligned_mem_16,
1619 .x87,
1620 }),
1621 };
1622 pub const geode = Cpu{
1623 .name = "geode",
1624 .llvm_name = "geode",
1625 .features = featureSet(&[_]Feature{
1626 .@"3dnowa",
1627 .cx8,
1628 .slow_unaligned_mem_16,
1629 .x87,
1630 }),
1631 };
1632 pub const goldmont = Cpu{
1633 .name = "goldmont",
1634 .llvm_name = "goldmont",
1635 .features = featureSet(&[_]Feature{
1636 .@"64bit",
1637 .aes,
1638 .clflushopt,
1639 .cmov,
1640 .cx16,
1641 .cx8,
1642 .false_deps_popcnt,
1643 .fsgsbase,
1644 .fxsr,
1645 .mmx,
1646 .movbe,
1647 .mpx,
1648 .nopl,
1649 .pclmul,
1650 .popcnt,
1651 .prfchw,
1652 .rdrnd,
1653 .rdseed,
1654 .sahf,
1655 .sha,
1656 .slow_incdec,
1657 .slow_lea,
1658 .slow_two_mem_ops,
1659 .sse4_2,
1660 .ssse3,
1661 .x87,
1662 .xsave,
1663 .xsavec,
1664 .xsaveopt,
1665 .xsaves,
1666 }),
1667 };
1668 pub const goldmont_plus = Cpu{
1669 .name = "goldmont_plus",
1670 .llvm_name = "goldmont-plus",
1671 .features = featureSet(&[_]Feature{
1672 .@"64bit",
1673 .aes,
1674 .clflushopt,
1675 .cmov,
1676 .cx16,
1677 .cx8,
1678 .fsgsbase,
1679 .fxsr,
1680 .mmx,
1681 .movbe,
1682 .mpx,
1683 .nopl,
1684 .pclmul,
1685 .popcnt,
1686 .prfchw,
1687 .ptwrite,
1688 .rdpid,
1689 .rdrnd,
1690 .rdseed,
1691 .sahf,
1692 .sgx,
1693 .sha,
1694 .slow_incdec,
1695 .slow_lea,
1696 .slow_two_mem_ops,
1697 .sse4_2,
1698 .ssse3,
1699 .x87,
1700 .xsave,
1701 .xsavec,
1702 .xsaveopt,
1703 .xsaves,
1704 }),
1705 };
1706 pub const haswell = Cpu{
1707 .name = "haswell",
1708 .llvm_name = "haswell",
1709 .features = featureSet(&[_]Feature{
1710 .@"64bit",
1711 .avx,
1712 .avx2,
1713 .bmi,
1714 .bmi2,
1715 .cmov,
1716 .cx16,
1717 .cx8,
1718 .ermsb,
1719 .f16c,
1720 .false_deps_lzcnt_tzcnt,
1721 .false_deps_popcnt,
1722 .fast_scalar_fsqrt,
1723 .fast_shld_rotate,
1724 .fast_variable_shuffle,
1725 .fma,
1726 .fsgsbase,
1727 .fxsr,
1728 .idivq_to_divl,
1729 .invpcid,
1730 .lzcnt,
1731 .macrofusion,
1732 .merge_to_threeway_branch,
1733 .mmx,
1734 .movbe,
1735 .nopl,
1736 .pclmul,
1737 .popcnt,
1738 .rdrnd,
1739 .sahf,
1740 .slow_3ops_lea,
1741 .sse4_2,
1742 .x87,
1743 .xsave,
1744 .xsaveopt,
1745 }),
1746 };
1747 pub const _i386 = Cpu{
1748 .name = "_i386",
1749 .llvm_name = "i386",
1750 .features = featureSet(&[_]Feature{
1751 .slow_unaligned_mem_16,
1752 .x87,
1753 }),
1754 };
1755 pub const _i486 = Cpu{
1756 .name = "_i486",
1757 .llvm_name = "i486",
1758 .features = featureSet(&[_]Feature{
1759 .slow_unaligned_mem_16,
1760 .x87,
1761 }),
1762 };
1763 pub const _i586 = Cpu{
1764 .name = "_i586",
1765 .llvm_name = "i586",
1766 .features = featureSet(&[_]Feature{
1767 .cx8,
1768 .slow_unaligned_mem_16,
1769 .x87,
1770 }),
1771 };
1772 pub const _i686 = Cpu{
1773 .name = "_i686",
1774 .llvm_name = "i686",
1775 .features = featureSet(&[_]Feature{
1776 .cmov,
1777 .cx8,
1778 .slow_unaligned_mem_16,
1779 .x87,
1780 }),
1781 };
1782 pub const icelake_client = Cpu{
1783 .name = "icelake_client",
1784 .llvm_name = "icelake-client",
1785 .features = featureSet(&[_]Feature{
1786 .@"64bit",
1787 .adx,
1788 .aes,
1789 .avx,
1790 .avx2,
1791 .avx512bitalg,
1792 .avx512bw,
1793 .avx512cd,
1794 .avx512dq,
1795 .avx512f,
1796 .avx512ifma,
1797 .avx512vbmi,
1798 .avx512vbmi2,
1799 .avx512vl,
1800 .avx512vnni,
1801 .avx512vpopcntdq,
1802 .bmi,
1803 .bmi2,
1804 .clflushopt,
1805 .clwb,
1806 .cmov,
1807 .cx16,
1808 .cx8,
1809 .ermsb,
1810 .f16c,
1811 .fast_gather,
1812 .fast_scalar_fsqrt,
1813 .fast_shld_rotate,
1814 .fast_variable_shuffle,
1815 .fast_vector_fsqrt,
1816 .fma,
1817 .fsgsbase,
1818 .fxsr,
1819 .gfni,
1820 .idivq_to_divl,
1821 .invpcid,
1822 .lzcnt,
1823 .macrofusion,
1824 .merge_to_threeway_branch,
1825 .mmx,
1826 .movbe,
1827 .mpx,
1828 .nopl,
1829 .pclmul,
1830 .pku,
1831 .popcnt,
1832 .prfchw,
1833 .rdpid,
1834 .rdrnd,
1835 .rdseed,
1836 .sahf,
1837 .sgx,
1838 .sha,
1839 .slow_3ops_lea,
1840 .sse4_2,
1841 .vaes,
1842 .vpclmulqdq,
1843 .x87,
1844 .xsave,
1845 .xsavec,
1846 .xsaveopt,
1847 .xsaves,
1848 }),
1849 };
1850 pub const icelake_server = Cpu{
1851 .name = "icelake_server",
1852 .llvm_name = "icelake-server",
1853 .features = featureSet(&[_]Feature{
1854 .@"64bit",
1855 .adx,
1856 .aes,
1857 .avx,
1858 .avx2,
1859 .avx512bitalg,
1860 .avx512bw,
1861 .avx512cd,
1862 .avx512dq,
1863 .avx512f,
1864 .avx512ifma,
1865 .avx512vbmi,
1866 .avx512vbmi2,
1867 .avx512vl,
1868 .avx512vnni,
1869 .avx512vpopcntdq,
1870 .bmi,
1871 .bmi2,
1872 .clflushopt,
1873 .clwb,
1874 .cmov,
1875 .cx16,
1876 .cx8,
1877 .ermsb,
1878 .f16c,
1879 .fast_gather,
1880 .fast_scalar_fsqrt,
1881 .fast_shld_rotate,
1882 .fast_variable_shuffle,
1883 .fast_vector_fsqrt,
1884 .fma,
1885 .fsgsbase,
1886 .fxsr,
1887 .gfni,
1888 .idivq_to_divl,
1889 .invpcid,
1890 .lzcnt,
1891 .macrofusion,
1892 .merge_to_threeway_branch,
1893 .mmx,
1894 .movbe,
1895 .mpx,
1896 .nopl,
1897 .pclmul,
1898 .pconfig,
1899 .pku,
1900 .popcnt,
1901 .prfchw,
1902 .rdpid,
1903 .rdrnd,
1904 .rdseed,
1905 .sahf,
1906 .sgx,
1907 .sha,
1908 .slow_3ops_lea,
1909 .sse4_2,
1910 .vaes,
1911 .vpclmulqdq,
1912 .wbnoinvd,
1913 .x87,
1914 .xsave,
1915 .xsavec,
1916 .xsaveopt,
1917 .xsaves,
1918 }),
1919 };
1920 pub const ivybridge = Cpu{
1921 .name = "ivybridge",
1922 .llvm_name = "ivybridge",
1923 .features = featureSet(&[_]Feature{
1924 .@"64bit",
1925 .avx,
1926 .cmov,
1927 .cx16,
1928 .cx8,
1929 .f16c,
1930 .false_deps_popcnt,
1931 .fast_scalar_fsqrt,
1932 .fast_shld_rotate,
1933 .fsgsbase,
1934 .fxsr,
1935 .idivq_to_divl,
1936 .macrofusion,
1937 .merge_to_threeway_branch,
1938 .mmx,
1939 .nopl,
1940 .pclmul,
1941 .popcnt,
1942 .rdrnd,
1943 .sahf,
1944 .slow_3ops_lea,
1945 .slow_unaligned_mem_32,
1946 .sse4_2,
1947 .x87,
1948 .xsave,
1949 .xsaveopt,
1950 }),
1951 };
1952 pub const k6 = Cpu{
1953 .name = "k6",
1954 .llvm_name = "k6",
1955 .features = featureSet(&[_]Feature{
1956 .cx8,
1957 .mmx,
1958 .slow_unaligned_mem_16,
1959 .x87,
1960 }),
1961 };
1962 pub const k6_2 = Cpu{
1963 .name = "k6_2",
1964 .llvm_name = "k6-2",
1965 .features = featureSet(&[_]Feature{
1966 .@"3dnow",
1967 .cx8,
1968 .slow_unaligned_mem_16,
1969 .x87,
1970 }),
1971 };
1972 pub const k6_3 = Cpu{
1973 .name = "k6_3",
1974 .llvm_name = "k6-3",
1975 .features = featureSet(&[_]Feature{
1976 .@"3dnow",
1977 .cx8,
1978 .slow_unaligned_mem_16,
1979 .x87,
1980 }),
1981 };
1982 pub const k8 = Cpu{
1983 .name = "k8",
1984 .llvm_name = "k8",
1985 .features = featureSet(&[_]Feature{
1986 .@"3dnowa",
1987 .@"64bit",
1988 .cmov,
1989 .cx8,
1990 .fast_scalar_shift_masks,
1991 .fxsr,
1992 .nopl,
1993 .slow_shld,
1994 .slow_unaligned_mem_16,
1995 .sse2,
1996 .x87,
1997 }),
1998 };
1999 pub const k8_sse3 = Cpu{
2000 .name = "k8_sse3",
2001 .llvm_name = "k8-sse3",
2002 .features = featureSet(&[_]Feature{
2003 .@"3dnowa",
2004 .@"64bit",
2005 .cmov,
2006 .cx16,
2007 .cx8,
2008 .fast_scalar_shift_masks,
2009 .fxsr,
2010 .nopl,
2011 .slow_shld,
2012 .slow_unaligned_mem_16,
2013 .sse3,
2014 .x87,
2015 }),
2016 };
2017 pub const knl = Cpu{
2018 .name = "knl",
2019 .llvm_name = "knl",
2020 .features = featureSet(&[_]Feature{
2021 .@"64bit",
2022 .adx,
2023 .aes,
2024 .avx512cd,
2025 .avx512er,
2026 .avx512f,
2027 .avx512pf,
2028 .bmi,
2029 .bmi2,
2030 .cmov,
2031 .cx16,
2032 .cx8,
2033 .f16c,
2034 .fast_gather,
2035 .fast_partial_ymm_or_zmm_write,
2036 .fma,
2037 .fsgsbase,
2038 .fxsr,
2039 .idivq_to_divl,
2040 .lzcnt,
2041 .mmx,
2042 .movbe,
2043 .nopl,
2044 .pclmul,
2045 .popcnt,
2046 .prefetchwt1,
2047 .prfchw,
2048 .rdrnd,
2049 .rdseed,
2050 .sahf,
2051 .slow_3ops_lea,
2052 .slow_incdec,
2053 .slow_pmaddwd,
2054 .slow_two_mem_ops,
2055 .x87,
2056 .xsave,
2057 .xsaveopt,
2058 }),
2059 };
2060 pub const knm = Cpu{
2061 .name = "knm",
2062 .llvm_name = "knm",
2063 .features = featureSet(&[_]Feature{
2064 .@"64bit",
2065 .adx,
2066 .aes,
2067 .avx512cd,
2068 .avx512er,
2069 .avx512f,
2070 .avx512pf,
2071 .avx512vpopcntdq,
2072 .bmi,
2073 .bmi2,
2074 .cmov,
2075 .cx16,
2076 .cx8,
2077 .f16c,
2078 .fast_gather,
2079 .fast_partial_ymm_or_zmm_write,
2080 .fma,
2081 .fsgsbase,
2082 .fxsr,
2083 .idivq_to_divl,
2084 .lzcnt,
2085 .mmx,
2086 .movbe,
2087 .nopl,
2088 .pclmul,
2089 .popcnt,
2090 .prefetchwt1,
2091 .prfchw,
2092 .rdrnd,
2093 .rdseed,
2094 .sahf,
2095 .slow_3ops_lea,
2096 .slow_incdec,
2097 .slow_pmaddwd,
2098 .slow_two_mem_ops,
2099 .x87,
2100 .xsave,
2101 .xsaveopt,
2102 }),
2103 };
2104 pub const lakemont = Cpu{
2105 .name = "lakemont",
2106 .llvm_name = "lakemont",
2107 .features = featureSet(&[_]Feature{}),
2108 };
2109 pub const nehalem = Cpu{
2110 .name = "nehalem",
2111 .llvm_name = "nehalem",
2112 .features = featureSet(&[_]Feature{
2113 .@"64bit",
2114 .cmov,
2115 .cx16,
2116 .cx8,
2117 .fxsr,
2118 .macrofusion,
2119 .mmx,
2120 .nopl,
2121 .popcnt,
2122 .sahf,
2123 .sse4_2,
2124 .x87,
2125 }),
2126 };
2127 pub const nocona = Cpu{
2128 .name = "nocona",
2129 .llvm_name = "nocona",
2130 .features = featureSet(&[_]Feature{
2131 .@"64bit",
2132 .cmov,
2133 .cx16,
2134 .cx8,
2135 .fxsr,
2136 .mmx,
2137 .nopl,
2138 .slow_unaligned_mem_16,
2139 .sse3,
2140 .x87,
2141 }),
2142 };
2143 pub const opteron = Cpu{
2144 .name = "opteron",
2145 .llvm_name = "opteron",
2146 .features = featureSet(&[_]Feature{
2147 .@"3dnowa",
2148 .@"64bit",
2149 .cmov,
2150 .cx8,
2151 .fast_scalar_shift_masks,
2152 .fxsr,
2153 .nopl,
2154 .slow_shld,
2155 .slow_unaligned_mem_16,
2156 .sse2,
2157 .x87,
2158 }),
2159 };
2160 pub const opteron_sse3 = Cpu{
2161 .name = "opteron_sse3",
2162 .llvm_name = "opteron-sse3",
2163 .features = featureSet(&[_]Feature{
2164 .@"3dnowa",
2165 .@"64bit",
2166 .cmov,
2167 .cx16,
2168 .cx8,
2169 .fast_scalar_shift_masks,
2170 .fxsr,
2171 .nopl,
2172 .slow_shld,
2173 .slow_unaligned_mem_16,
2174 .sse3,
2175 .x87,
2176 }),
2177 };
2178 pub const penryn = Cpu{
2179 .name = "penryn",
2180 .llvm_name = "penryn",
2181 .features = featureSet(&[_]Feature{
2182 .@"64bit",
2183 .cmov,
2184 .cx16,
2185 .cx8,
2186 .fxsr,
2187 .macrofusion,
2188 .mmx,
2189 .nopl,
2190 .sahf,
2191 .slow_unaligned_mem_16,
2192 .sse4_1,
2193 .x87,
2194 }),
2195 };
2196 pub const pentium = Cpu{
2197 .name = "pentium",
2198 .llvm_name = "pentium",
2199 .features = featureSet(&[_]Feature{
2200 .cx8,
2201 .slow_unaligned_mem_16,
2202 .x87,
2203 }),
2204 };
2205 pub const pentium_m = Cpu{
2206 .name = "pentium_m",
2207 .llvm_name = "pentium-m",
2208 .features = featureSet(&[_]Feature{
2209 .cmov,
2210 .cx8,
2211 .fxsr,
2212 .mmx,
2213 .nopl,
2214 .slow_unaligned_mem_16,
2215 .sse2,
2216 .x87,
2217 }),
2218 };
2219 pub const pentium_mmx = Cpu{
2220 .name = "pentium_mmx",
2221 .llvm_name = "pentium-mmx",
2222 .features = featureSet(&[_]Feature{
2223 .cx8,
2224 .mmx,
2225 .slow_unaligned_mem_16,
2226 .x87,
2227 }),
2228 };
2229 pub const pentium2 = Cpu{
2230 .name = "pentium2",
2231 .llvm_name = "pentium2",
2232 .features = featureSet(&[_]Feature{
2233 .cmov,
2234 .cx8,
2235 .fxsr,
2236 .mmx,
2237 .nopl,
2238 .slow_unaligned_mem_16,
2239 .x87,
2240 }),
2241 };
2242 pub const pentium3 = Cpu{
2243 .name = "pentium3",
2244 .llvm_name = "pentium3",
2245 .features = featureSet(&[_]Feature{
2246 .cmov,
2247 .cx8,
2248 .fxsr,
2249 .mmx,
2250 .nopl,
2251 .slow_unaligned_mem_16,
2252 .sse,
2253 .x87,
2254 }),
2255 };
2256 pub const pentium3m = Cpu{
2257 .name = "pentium3m",
2258 .llvm_name = "pentium3m",
2259 .features = featureSet(&[_]Feature{
2260 .cmov,
2261 .cx8,
2262 .fxsr,
2263 .mmx,
2264 .nopl,
2265 .slow_unaligned_mem_16,
2266 .sse,
2267 .x87,
2268 }),
2269 };
2270 pub const pentium4 = Cpu{
2271 .name = "pentium4",
2272 .llvm_name = "pentium4",
2273 .features = featureSet(&[_]Feature{
2274 .cmov,
2275 .cx8,
2276 .fxsr,
2277 .mmx,
2278 .nopl,
2279 .slow_unaligned_mem_16,
2280 .sse2,
2281 .x87,
2282 }),
2283 };
2284 pub const pentium4m = Cpu{
2285 .name = "pentium4m",
2286 .llvm_name = "pentium4m",
2287 .features = featureSet(&[_]Feature{
2288 .cmov,
2289 .cx8,
2290 .fxsr,
2291 .mmx,
2292 .nopl,
2293 .slow_unaligned_mem_16,
2294 .sse2,
2295 .x87,
2296 }),
2297 };
2298 pub const pentiumpro = Cpu{
2299 .name = "pentiumpro",
2300 .llvm_name = "pentiumpro",
2301 .features = featureSet(&[_]Feature{
2302 .cmov,
2303 .cx8,
2304 .nopl,
2305 .slow_unaligned_mem_16,
2306 .x87,
2307 }),
2308 };
2309 pub const prescott = Cpu{
2310 .name = "prescott",
2311 .llvm_name = "prescott",
2312 .features = featureSet(&[_]Feature{
2313 .cmov,
2314 .cx8,
2315 .fxsr,
2316 .mmx,
2317 .nopl,
2318 .slow_unaligned_mem_16,
2319 .sse3,
2320 .x87,
2321 }),
2322 };
2323 pub const sandybridge = Cpu{
2324 .name = "sandybridge",
2325 .llvm_name = "sandybridge",
2326 .features = featureSet(&[_]Feature{
2327 .@"64bit",
2328 .avx,
2329 .cmov,
2330 .cx16,
2331 .cx8,
2332 .false_deps_popcnt,
2333 .fast_scalar_fsqrt,
2334 .fast_shld_rotate,
2335 .fxsr,
2336 .idivq_to_divl,
2337 .macrofusion,
2338 .merge_to_threeway_branch,
2339 .mmx,
2340 .nopl,
2341 .pclmul,
2342 .popcnt,
2343 .sahf,
2344 .slow_3ops_lea,
2345 .slow_unaligned_mem_32,
2346 .sse4_2,
2347 .x87,
2348 .xsave,
2349 .xsaveopt,
2350 }),
2351 };
2352 pub const silvermont = Cpu{
2353 .name = "silvermont",
2354 .llvm_name = "silvermont",
2355 .features = featureSet(&[_]Feature{
2356 .@"64bit",
2357 .cmov,
2358 .cx16,
2359 .cx8,
2360 .false_deps_popcnt,
2361 .fxsr,
2362 .idivq_to_divl,
2363 .mmx,
2364 .movbe,
2365 .nopl,
2366 .pclmul,
2367 .popcnt,
2368 .prfchw,
2369 .rdrnd,
2370 .sahf,
2371 .slow_incdec,
2372 .slow_lea,
2373 .slow_pmulld,
2374 .slow_two_mem_ops,
2375 .sse4_2,
2376 .ssse3,
2377 .x87,
2378 }),
2379 };
2380 pub const skx = Cpu{
2381 .name = "skx",
2382 .llvm_name = "skx",
2383 .features = featureSet(&[_]Feature{
2384 .@"64bit",
2385 .adx,
2386 .aes,
2387 .avx,
2388 .avx2,
2389 .avx512bw,
2390 .avx512cd,
2391 .avx512dq,
2392 .avx512f,
2393 .avx512vl,
2394 .bmi,
2395 .bmi2,
2396 .clflushopt,
2397 .clwb,
2398 .cmov,
2399 .cx16,
2400 .cx8,
2401 .ermsb,
2402 .f16c,
2403 .false_deps_popcnt,
2404 .fast_gather,
2405 .fast_scalar_fsqrt,
2406 .fast_shld_rotate,
2407 .fast_variable_shuffle,
2408 .fast_vector_fsqrt,
2409 .fma,
2410 .fsgsbase,
2411 .fxsr,
2412 .idivq_to_divl,
2413 .invpcid,
2414 .lzcnt,
2415 .macrofusion,
2416 .merge_to_threeway_branch,
2417 .mmx,
2418 .movbe,
2419 .mpx,
2420 .nopl,
2421 .pclmul,
2422 .pku,
2423 .popcnt,
2424 .prfchw,
2425 .rdrnd,
2426 .rdseed,
2427 .sahf,
2428 .slow_3ops_lea,
2429 .sse4_2,
2430 .x87,
2431 .xsave,
2432 .xsavec,
2433 .xsaveopt,
2434 .xsaves,
2435 }),
2436 };
2437 pub const skylake = Cpu{
2438 .name = "skylake",
2439 .llvm_name = "skylake",
2440 .features = featureSet(&[_]Feature{
2441 .@"64bit",
2442 .adx,
2443 .aes,
2444 .avx,
2445 .avx2,
2446 .bmi,
2447 .bmi2,
2448 .clflushopt,
2449 .cmov,
2450 .cx16,
2451 .cx8,
2452 .ermsb,
2453 .f16c,
2454 .false_deps_popcnt,
2455 .fast_gather,
2456 .fast_scalar_fsqrt,
2457 .fast_shld_rotate,
2458 .fast_variable_shuffle,
2459 .fast_vector_fsqrt,
2460 .fma,
2461 .fsgsbase,
2462 .fxsr,
2463 .idivq_to_divl,
2464 .invpcid,
2465 .lzcnt,
2466 .macrofusion,
2467 .merge_to_threeway_branch,
2468 .mmx,
2469 .movbe,
2470 .mpx,
2471 .nopl,
2472 .pclmul,
2473 .popcnt,
2474 .prfchw,
2475 .rdrnd,
2476 .rdseed,
2477 .sahf,
2478 .sgx,
2479 .slow_3ops_lea,
2480 .sse4_2,
2481 .x87,
2482 .xsave,
2483 .xsavec,
2484 .xsaveopt,
2485 .xsaves,
2486 }),
2487 };
2488 pub const skylake_avx512 = Cpu{
2489 .name = "skylake_avx512",
2490 .llvm_name = "skylake-avx512",
2491 .features = featureSet(&[_]Feature{
2492 .@"64bit",
2493 .adx,
2494 .aes,
2495 .avx,
2496 .avx2,
2497 .avx512bw,
2498 .avx512cd,
2499 .avx512dq,
2500 .avx512f,
2501 .avx512vl,
2502 .bmi,
2503 .bmi2,
2504 .clflushopt,
2505 .clwb,
2506 .cmov,
2507 .cx16,
2508 .cx8,
2509 .ermsb,
2510 .f16c,
2511 .false_deps_popcnt,
2512 .fast_gather,
2513 .fast_scalar_fsqrt,
2514 .fast_shld_rotate,
2515 .fast_variable_shuffle,
2516 .fast_vector_fsqrt,
2517 .fma,
2518 .fsgsbase,
2519 .fxsr,
2520 .idivq_to_divl,
2521 .invpcid,
2522 .lzcnt,
2523 .macrofusion,
2524 .merge_to_threeway_branch,
2525 .mmx,
2526 .movbe,
2527 .mpx,
2528 .nopl,
2529 .pclmul,
2530 .pku,
2531 .popcnt,
2532 .prfchw,
2533 .rdrnd,
2534 .rdseed,
2535 .sahf,
2536 .slow_3ops_lea,
2537 .sse4_2,
2538 .x87,
2539 .xsave,
2540 .xsavec,
2541 .xsaveopt,
2542 .xsaves,
2543 }),
2544 };
2545 pub const slm = Cpu{
2546 .name = "slm",
2547 .llvm_name = "slm",
2548 .features = featureSet(&[_]Feature{
2549 .@"64bit",
2550 .cmov,
2551 .cx16,
2552 .cx8,
2553 .false_deps_popcnt,
2554 .fxsr,
2555 .idivq_to_divl,
2556 .mmx,
2557 .movbe,
2558 .nopl,
2559 .pclmul,
2560 .popcnt,
2561 .prfchw,
2562 .rdrnd,
2563 .sahf,
2564 .slow_incdec,
2565 .slow_lea,
2566 .slow_pmulld,
2567 .slow_two_mem_ops,
2568 .sse4_2,
2569 .ssse3,
2570 .x87,
2571 }),
2572 };
2573 pub const tremont = Cpu{
2574 .name = "tremont",
2575 .llvm_name = "tremont",
2576 .features = featureSet(&[_]Feature{
2577 .@"64bit",
2578 .aes,
2579 .cldemote,
2580 .clflushopt,
2581 .cmov,
2582 .cx16,
2583 .cx8,
2584 .fsgsbase,
2585 .fxsr,
2586 .gfni,
2587 .mmx,
2588 .movbe,
2589 .movdir64b,
2590 .movdiri,
2591 .mpx,
2592 .nopl,
2593 .pclmul,
2594 .popcnt,
2595 .prfchw,
2596 .ptwrite,
2597 .rdpid,
2598 .rdrnd,
2599 .rdseed,
2600 .sahf,
2601 .sgx,
2602 .sha,
2603 .slow_incdec,
2604 .slow_lea,
2605 .slow_two_mem_ops,
2606 .sse4_2,
2607 .ssse3,
2608 .waitpkg,
2609 .x87,
2610 .xsave,
2611 .xsavec,
2612 .xsaveopt,
2613 .xsaves,
2614 }),
2615 };
2616 pub const westmere = Cpu{
2617 .name = "westmere",
2618 .llvm_name = "westmere",
2619 .features = featureSet(&[_]Feature{
2620 .@"64bit",
2621 .cmov,
2622 .cx16,
2623 .cx8,
2624 .fxsr,
2625 .macrofusion,
2626 .mmx,
2627 .nopl,
2628 .pclmul,
2629 .popcnt,
2630 .sahf,
2631 .sse4_2,
2632 .x87,
2633 }),
2634 };
2635 pub const winchip_c6 = Cpu{
2636 .name = "winchip_c6",
2637 .llvm_name = "winchip-c6",
2638 .features = featureSet(&[_]Feature{
2639 .mmx,
2640 .slow_unaligned_mem_16,
2641 .x87,
2642 }),
2643 };
2644 pub const winchip2 = Cpu{
2645 .name = "winchip2",
2646 .llvm_name = "winchip2",
2647 .features = featureSet(&[_]Feature{
2648 .@"3dnow",
2649 .slow_unaligned_mem_16,
2650 .x87,
2651 }),
2652 };
2653 pub const x86_64 = Cpu{
2654 .name = "x86_64",
2655 .llvm_name = "x86-64",
2656 .features = featureSet(&[_]Feature{
2657 .@"64bit",
2658 .cmov,
2659 .cx8,
2660 .fxsr,
2661 .macrofusion,
2662 .mmx,
2663 .nopl,
2664 .slow_3ops_lea,
2665 .slow_incdec,
2666 .sse2,
2667 .x87,
2668 }),
2669 };
2670 pub const yonah = Cpu{
2671 .name = "yonah",
2672 .llvm_name = "yonah",
2673 .features = featureSet(&[_]Feature{
2674 .cmov,
2675 .cx8,
2676 .fxsr,
2677 .mmx,
2678 .nopl,
2679 .slow_unaligned_mem_16,
2680 .sse3,
2681 .x87,
2682 }),
2683 };
2684 pub const znver1 = Cpu{
2685 .name = "znver1",
2686 .llvm_name = "znver1",
2687 .features = featureSet(&[_]Feature{
2688 .@"64bit",
2689 .adx,
2690 .aes,
2691 .avx2,
2692 .bmi,
2693 .bmi2,
2694 .branchfusion,
2695 .clflushopt,
2696 .clzero,
2697 .cmov,
2698 .cx16,
2699 .f16c,
2700 .fast_15bytenop,
2701 .fast_bextr,
2702 .fast_lzcnt,
2703 .fast_scalar_shift_masks,
2704 .fma,
2705 .fsgsbase,
2706 .fxsr,
2707 .lzcnt,
2708 .mmx,
2709 .movbe,
2710 .mwaitx,
2711 .nopl,
2712 .pclmul,
2713 .popcnt,
2714 .prfchw,
2715 .rdrnd,
2716 .rdseed,
2717 .sahf,
2718 .sha,
2719 .slow_shld,
2720 .sse4a,
2721 .x87,
2722 .xsave,
2723 .xsavec,
2724 .xsaveopt,
2725 .xsaves,
2726 }),
2727 };
2728 pub const znver2 = Cpu{
2729 .name = "znver2",
2730 .llvm_name = "znver2",
2731 .features = featureSet(&[_]Feature{
2732 .@"64bit",
2733 .adx,
2734 .aes,
2735 .avx2,
2736 .bmi,
2737 .bmi2,
2738 .branchfusion,
2739 .clflushopt,
2740 .clwb,
2741 .clzero,
2742 .cmov,
2743 .cx16,
2744 .f16c,
2745 .fast_15bytenop,
2746 .fast_bextr,
2747 .fast_lzcnt,
2748 .fast_scalar_shift_masks,
2749 .fma,
2750 .fsgsbase,
2751 .fxsr,
2752 .lzcnt,
2753 .mmx,
2754 .movbe,
2755 .mwaitx,
2756 .nopl,
2757 .pclmul,
2758 .popcnt,
2759 .prfchw,
2760 .rdpid,
2761 .rdrnd,
2762 .rdseed,
2763 .sahf,
2764 .sha,
2765 .slow_shld,
2766 .sse4a,
2767 .wbnoinvd,
2768 .x87,
2769 .xsave,
2770 .xsavec,
2771 .xsaveopt,
2772 .xsaves,
2773 }),
2774 };
2775};
2776
2777/// All x86 CPUs, sorted alphabetically by name.
2778/// TODO: Replace this with usage of `std.meta.declList`. It does work, but stage1
2779/// compiler has inefficient memory and CPU usage, affecting build times.
2780pub const all_cpus = &[_]*const Cpu{
2781 &cpu.amdfam10,
2782 &cpu.athlon,
2783 &cpu.athlon_4,
2784 &cpu.athlon_fx,
2785 &cpu.athlon_mp,
2786 &cpu.athlon_tbird,
2787 &cpu.athlon_xp,
2788 &cpu.athlon64,
2789 &cpu.athlon64_sse3,
2790 &cpu.atom,
2791 &cpu.barcelona,
2792 &cpu.bdver1,
2793 &cpu.bdver2,
2794 &cpu.bdver3,
2795 &cpu.bdver4,
2796 &cpu.bonnell,
2797 &cpu.broadwell,
2798 &cpu.btver1,
2799 &cpu.btver2,
2800 &cpu.c3,
2801 &cpu.c3_2,
2802 &cpu.cannonlake,
2803 &cpu.cascadelake,
2804 &cpu.cooperlake,
2805 &cpu.core_avx_i,
2806 &cpu.core_avx2,
2807 &cpu.core2,
2808 &cpu.corei7,
2809 &cpu.corei7_avx,
2810 &cpu.generic,
2811 &cpu.geode,
2812 &cpu.goldmont,
2813 &cpu.goldmont_plus,
2814 &cpu.haswell,
2815 &cpu._i386,
2816 &cpu._i486,
2817 &cpu._i586,
2818 &cpu._i686,
2819 &cpu.icelake_client,
2820 &cpu.icelake_server,
2821 &cpu.ivybridge,
2822 &cpu.k6,
2823 &cpu.k6_2,
2824 &cpu.k6_3,
2825 &cpu.k8,
2826 &cpu.k8_sse3,
2827 &cpu.knl,
2828 &cpu.knm,
2829 &cpu.lakemont,
2830 &cpu.nehalem,
2831 &cpu.nocona,
2832 &cpu.opteron,
2833 &cpu.opteron_sse3,
2834 &cpu.penryn,
2835 &cpu.pentium,
2836 &cpu.pentium_m,
2837 &cpu.pentium_mmx,
2838 &cpu.pentium2,
2839 &cpu.pentium3,
2840 &cpu.pentium3m,
2841 &cpu.pentium4,
2842 &cpu.pentium4m,
2843 &cpu.pentiumpro,
2844 &cpu.prescott,
2845 &cpu.sandybridge,
2846 &cpu.silvermont,
2847 &cpu.skx,
2848 &cpu.skylake,
2849 &cpu.skylake_avx512,
2850 &cpu.slm,
2851 &cpu.tremont,
2852 &cpu.westmere,
2853 &cpu.winchip_c6,
2854 &cpu.winchip2,
2855 &cpu.x86_64,
2856 &cpu.yonah,
2857 &cpu.znver1,
2858 &cpu.znver2,
2859};
src-self-hosted/clang.zig+2
...@@ -776,6 +776,7 @@ pub extern fn ZigClangFieldDecl_getCanonicalDecl(field_decl: ?*const struct_ZigC...@@ -776,6 +776,7 @@ pub extern fn ZigClangFieldDecl_getCanonicalDecl(field_decl: ?*const struct_ZigC
776pub extern fn ZigClangEnumDecl_getCanonicalDecl(self: ?*const struct_ZigClangEnumDecl) ?*const struct_ZigClangTagDecl;776pub extern fn ZigClangEnumDecl_getCanonicalDecl(self: ?*const struct_ZigClangEnumDecl) ?*const struct_ZigClangTagDecl;
777pub extern fn ZigClangTypedefNameDecl_getCanonicalDecl(self: ?*const struct_ZigClangTypedefNameDecl) ?*const struct_ZigClangTypedefNameDecl;777pub extern fn ZigClangTypedefNameDecl_getCanonicalDecl(self: ?*const struct_ZigClangTypedefNameDecl) ?*const struct_ZigClangTypedefNameDecl;
778pub extern fn ZigClangFunctionDecl_getCanonicalDecl(self: ?*const struct_ZigClangFunctionDecl) ?*const struct_ZigClangFunctionDecl;778pub extern fn ZigClangFunctionDecl_getCanonicalDecl(self: ?*const struct_ZigClangFunctionDecl) ?*const struct_ZigClangFunctionDecl;
779pub extern fn ZigClangParmVarDecl_getOriginalType(self: ?*const struct_ZigClangParmVarDecl) struct_ZigClangQualType;
779pub extern fn ZigClangVarDecl_getCanonicalDecl(self: ?*const struct_ZigClangVarDecl) ?*const struct_ZigClangVarDecl;780pub extern fn ZigClangVarDecl_getCanonicalDecl(self: ?*const struct_ZigClangVarDecl) ?*const struct_ZigClangVarDecl;
780pub extern fn ZigClangVarDecl_getSectionAttribute(self: *const ZigClangVarDecl, len: *usize) ?[*]const u8;781pub extern fn ZigClangVarDecl_getSectionAttribute(self: *const ZigClangVarDecl, len: *usize) ?[*]const u8;
781pub extern fn ZigClangFunctionDecl_getAlignedAttribute(self: *const ZigClangFunctionDecl, *const ZigClangASTContext) c_uint;782pub extern fn ZigClangFunctionDecl_getAlignedAttribute(self: *const ZigClangFunctionDecl, *const ZigClangASTContext) c_uint;
...@@ -817,6 +818,7 @@ pub extern fn ZigClangQualType_isRestrictQualified(self: struct_ZigClangQualType...@@ -817,6 +818,7 @@ pub extern fn ZigClangQualType_isRestrictQualified(self: struct_ZigClangQualType
817pub extern fn ZigClangType_getTypeClass(self: ?*const struct_ZigClangType) ZigClangTypeClass;818pub extern fn ZigClangType_getTypeClass(self: ?*const struct_ZigClangType) ZigClangTypeClass;
818pub extern fn ZigClangType_getPointeeType(self: ?*const struct_ZigClangType) struct_ZigClangQualType;819pub extern fn ZigClangType_getPointeeType(self: ?*const struct_ZigClangType) struct_ZigClangQualType;
819pub extern fn ZigClangType_isVoidType(self: ?*const struct_ZigClangType) bool;820pub extern fn ZigClangType_isVoidType(self: ?*const struct_ZigClangType) bool;
821pub extern fn ZigClangType_isConstantArrayType(self: ?*const struct_ZigClangType) bool;
820pub extern fn ZigClangType_isRecordType(self: ?*const struct_ZigClangType) bool;822pub extern fn ZigClangType_isRecordType(self: ?*const struct_ZigClangType) bool;
821pub extern fn ZigClangType_isArrayType(self: ?*const struct_ZigClangType) bool;823pub extern fn ZigClangType_isArrayType(self: ?*const struct_ZigClangType) bool;
822pub extern fn ZigClangType_isBooleanType(self: ?*const struct_ZigClangType) bool;824pub extern fn ZigClangType_isBooleanType(self: ?*const struct_ZigClangType) bool;
src-self-hosted/main.zig+3-43
...@@ -79,7 +79,9 @@ pub fn main() !void {...@@ -79,7 +79,9 @@ pub fn main() !void {
79 } else if (mem.eql(u8, cmd, "libc")) {79 } else if (mem.eql(u8, cmd, "libc")) {
80 return cmdLibC(allocator, cmd_args);80 return cmdLibC(allocator, cmd_args);
81 } else if (mem.eql(u8, cmd, "targets")) {81 } else if (mem.eql(u8, cmd, "targets")) {
82 return cmdTargets(allocator, cmd_args);82 // TODO figure out the current target rather than using the target that was specified when
83 // compiling the compiler
84 return @import("print_targets.zig").cmdTargets(allocator, cmd_args, stdout, Target.current);
83 } else if (mem.eql(u8, cmd, "version")) {85 } else if (mem.eql(u8, cmd, "version")) {
84 return cmdVersion(allocator, cmd_args);86 return cmdVersion(allocator, cmd_args);
85 } else if (mem.eql(u8, cmd, "zen")) {87 } else if (mem.eql(u8, cmd, "zen")) {
...@@ -789,48 +791,6 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro...@@ -789,48 +791,6 @@ async fn fmtPath(fmt: *Fmt, file_path_ref: []const u8, check_mode: bool) FmtErro
789 }791 }
790}792}
791793
792// cmd:targets /////////////////////////////////////////////////////////////////////////////////////
793
794fn cmdTargets(allocator: *Allocator, args: []const []const u8) !void {
795 try stdout.write("Architectures:\n");
796 {
797 comptime var i: usize = 0;
798 inline while (i < @memberCount(builtin.Arch)) : (i += 1) {
799 comptime const arch_tag = @memberName(builtin.Arch, i);
800 // NOTE: Cannot use empty string, see #918.
801 comptime const native_str = if (comptime mem.eql(u8, arch_tag, @tagName(builtin.arch))) " (native)\n" else "\n";
802
803 try stdout.print(" {}{}", .{ arch_tag, native_str });
804 }
805 }
806 try stdout.write("\n");
807
808 try stdout.write("Operating Systems:\n");
809 {
810 comptime var i: usize = 0;
811 inline while (i < @memberCount(Target.Os)) : (i += 1) {
812 comptime const os_tag = @memberName(Target.Os, i);
813 // NOTE: Cannot use empty string, see #918.
814 comptime const native_str = if (comptime mem.eql(u8, os_tag, @tagName(builtin.os))) " (native)\n" else "\n";
815
816 try stdout.print(" {}{}", .{ os_tag, native_str });
817 }
818 }
819 try stdout.write("\n");
820
821 try stdout.write("C ABIs:\n");
822 {
823 comptime var i: usize = 0;
824 inline while (i < @memberCount(Target.Abi)) : (i += 1) {
825 comptime const abi_tag = @memberName(Target.Abi, i);
826 // NOTE: Cannot use empty string, see #918.
827 comptime const native_str = if (comptime mem.eql(u8, abi_tag, @tagName(builtin.abi))) " (native)\n" else "\n";
828
829 try stdout.print(" {}{}", .{ abi_tag, native_str });
830 }
831 }
832}
833
834fn cmdVersion(allocator: *Allocator, args: []const []const u8) !void {794fn cmdVersion(allocator: *Allocator, args: []const []const u8) !void {
835 try stdout.print("{}\n", .{std.mem.toSliceConst(u8, c.ZIG_VERSION_STRING)});795 try stdout.print("{}\n", .{std.mem.toSliceConst(u8, c.ZIG_VERSION_STRING)});
836}796}
src-self-hosted/print_targets.zig created+251
...@@ -0,0 +1,251 @@
1const std = @import("std");
2const fs = std.fs;
3const io = std.io;
4const mem = std.mem;
5const Allocator = mem.Allocator;
6const Target = std.Target;
7
8// TODO this is hard-coded until self-hosted gains this information canonically
9const available_libcs = [_][]const u8{
10 "aarch64_be-linux-gnu",
11 "aarch64_be-linux-musl",
12 "aarch64_be-windows-gnu",
13 "aarch64-linux-gnu",
14 "aarch64-linux-musl",
15 "aarch64-windows-gnu",
16 "armeb-linux-gnueabi",
17 "armeb-linux-gnueabihf",
18 "armeb-linux-musleabi",
19 "armeb-linux-musleabihf",
20 "armeb-windows-gnu",
21 "arm-linux-gnueabi",
22 "arm-linux-gnueabihf",
23 "arm-linux-musleabi",
24 "arm-linux-musleabihf",
25 "arm-windows-gnu",
26 "i386-linux-gnu",
27 "i386-linux-musl",
28 "i386-windows-gnu",
29 "mips64el-linux-gnuabi64",
30 "mips64el-linux-gnuabin32",
31 "mips64el-linux-musl",
32 "mips64-linux-gnuabi64",
33 "mips64-linux-gnuabin32",
34 "mips64-linux-musl",
35 "mipsel-linux-gnu",
36 "mipsel-linux-musl",
37 "mips-linux-gnu",
38 "mips-linux-musl",
39 "powerpc64le-linux-gnu",
40 "powerpc64le-linux-musl",
41 "powerpc64-linux-gnu",
42 "powerpc64-linux-musl",
43 "powerpc-linux-gnu",
44 "powerpc-linux-musl",
45 "riscv64-linux-gnu",
46 "riscv64-linux-musl",
47 "s390x-linux-gnu",
48 "s390x-linux-musl",
49 "sparc-linux-gnu",
50 "sparcv9-linux-gnu",
51 "wasm32-freestanding-musl",
52 "x86_64-linux-gnu (native)",
53 "x86_64-linux-gnux32",
54 "x86_64-linux-musl",
55 "x86_64-windows-gnu",
56};
57
58// TODO this is hard-coded until self-hosted gains this information canonically
59const available_glibcs = [_][]const u8{
60 "2.0",
61 "2.1",
62 "2.1.1",
63 "2.1.2",
64 "2.1.3",
65 "2.2",
66 "2.2.1",
67 "2.2.2",
68 "2.2.3",
69 "2.2.4",
70 "2.2.5",
71 "2.2.6",
72 "2.3",
73 "2.3.2",
74 "2.3.3",
75 "2.3.4",
76 "2.4",
77 "2.5",
78 "2.6",
79 "2.7",
80 "2.8",
81 "2.9",
82 "2.10",
83 "2.11",
84 "2.12",
85 "2.13",
86 "2.14",
87 "2.15",
88 "2.16",
89 "2.17",
90 "2.18",
91 "2.19",
92 "2.22",
93 "2.23",
94 "2.24",
95 "2.25",
96 "2.26",
97 "2.27",
98 "2.28",
99 "2.29",
100 "2.30",
101};
102
103pub fn cmdTargets(
104 allocator: *Allocator,
105 args: []const []const u8,
106 stdout: *io.OutStream(fs.File.WriteError),
107 native_target: Target,
108) !void {
109 const BOS = io.BufferedOutStream(fs.File.WriteError);
110 var bos = BOS.init(stdout);
111 var jws = std.json.WriteStream(BOS.Stream, 6).init(&bos.stream);
112
113 try jws.beginObject();
114
115 try jws.objectField("arch");
116 try jws.beginObject();
117 {
118 inline for (@typeInfo(Target.Arch).Union.fields) |field| {
119 try jws.objectField(field.name);
120 if (field.field_type == void) {
121 try jws.emitNull();
122 } else {
123 try jws.emitString(@typeName(field.field_type));
124 }
125 }
126 }
127 try jws.endObject();
128
129 try jws.objectField("subArch");
130 try jws.beginObject();
131 const sub_arch_list = [_]type{
132 Target.Arch.Arm32,
133 Target.Arch.Arm64,
134 Target.Arch.Kalimba,
135 Target.Arch.Mips,
136 };
137 inline for (sub_arch_list) |SubArch| {
138 try jws.objectField(@typeName(SubArch));
139 try jws.beginArray();
140 inline for (@typeInfo(SubArch).Enum.fields) |field| {
141 try jws.arrayElem();
142 try jws.emitString(field.name);
143 }
144 try jws.endArray();
145 }
146 try jws.endObject();
147
148 try jws.objectField("os");
149 try jws.beginArray();
150 inline for (@typeInfo(Target.Os).Enum.fields) |field| {
151 try jws.arrayElem();
152 try jws.emitString(field.name);
153 }
154 try jws.endArray();
155
156 try jws.objectField("abi");
157 try jws.beginArray();
158 inline for (@typeInfo(Target.Abi).Enum.fields) |field| {
159 try jws.arrayElem();
160 try jws.emitString(field.name);
161 }
162 try jws.endArray();
163
164 try jws.objectField("libc");
165 try jws.beginArray();
166 for (available_libcs) |libc| {
167 try jws.arrayElem();
168 try jws.emitString(libc);
169 }
170 try jws.endArray();
171
172 try jws.objectField("glibc");
173 try jws.beginArray();
174 for (available_glibcs) |glibc| {
175 try jws.arrayElem();
176 try jws.emitString(glibc);
177 }
178 try jws.endArray();
179
180 try jws.objectField("cpus");
181 try jws.beginObject();
182 inline for (@typeInfo(Target.Arch).Union.fields) |field| {
183 try jws.objectField(field.name);
184 try jws.beginObject();
185 const arch = @unionInit(Target.Arch, field.name, undefined);
186 for (arch.allCpus()) |cpu| {
187 try jws.objectField(cpu.name);
188 try jws.beginArray();
189 for (arch.allFeaturesList()) |feature, i| {
190 if (cpu.features.isEnabled(@intCast(u8, i))) {
191 try jws.arrayElem();
192 try jws.emitString(feature.name);
193 }
194 }
195 try jws.endArray();
196 }
197 try jws.endObject();
198 }
199 try jws.endObject();
200
201 try jws.objectField("cpuFeatures");
202 try jws.beginObject();
203 inline for (@typeInfo(Target.Arch).Union.fields) |field| {
204 try jws.objectField(field.name);
205 try jws.beginArray();
206 const arch = @unionInit(Target.Arch, field.name, undefined);
207 for (arch.allFeaturesList()) |feature| {
208 try jws.arrayElem();
209 try jws.emitString(feature.name);
210 }
211 try jws.endArray();
212 }
213 try jws.endObject();
214
215 try jws.objectField("native");
216 try jws.beginObject();
217 {
218 const triple = try native_target.zigTriple(allocator);
219 defer allocator.free(triple);
220 try jws.objectField("triple");
221 try jws.emitString(triple);
222 }
223 try jws.objectField("arch");
224 try jws.emitString(@tagName(native_target.getArch()));
225 try jws.objectField("os");
226 try jws.emitString(@tagName(native_target.getOs()));
227 try jws.objectField("abi");
228 try jws.emitString(@tagName(native_target.getAbi()));
229 try jws.objectField("cpuName");
230 const cpu_features = native_target.getCpuFeatures();
231 try jws.emitString(cpu_features.cpu.name);
232 {
233 try jws.objectField("cpuFeatures");
234 try jws.beginArray();
235 for (native_target.getArch().allFeaturesList()) |feature, i_usize| {
236 const index = @intCast(Target.Cpu.Feature.Set.Index, i_usize);
237 if (cpu_features.features.isEnabled(index)) {
238 try jws.arrayElem();
239 try jws.emitString(feature.name);
240 }
241 }
242 try jws.endArray();
243 }
244 // TODO implement native glibc version detection in self-hosted
245 try jws.endObject();
246
247 try jws.endObject();
248
249 try bos.stream.writeByte('\n');
250 return bos.flush();
251}
src-self-hosted/stage1.zig+304-1
...@@ -9,9 +9,11 @@ const process = std.process;...@@ -9,9 +9,11 @@ const process = std.process;
9const Allocator = mem.Allocator;9const Allocator = mem.Allocator;
10const ArrayList = std.ArrayList;10const ArrayList = std.ArrayList;
11const Buffer = std.Buffer;11const Buffer = std.Buffer;
12const Target = std.Target;
12const self_hosted_main = @import("main.zig");13const self_hosted_main = @import("main.zig");
13const errmsg = @import("errmsg.zig");14const errmsg = @import("errmsg.zig");
14const DepTokenizer = @import("dep_tokenizer.zig").Tokenizer;15const DepTokenizer = @import("dep_tokenizer.zig").Tokenizer;
16const assert = std.debug.assert;
1517
16var stderr_file: fs.File = undefined;18var stderr_file: fs.File = undefined;
17var stderr: *io.OutStream(fs.File.WriteError) = undefined;19var stderr: *io.OutStream(fs.File.WriteError) = undefined;
...@@ -63,6 +65,7 @@ const Error = extern enum {...@@ -63,6 +65,7 @@ const Error = extern enum {
63 CacheUnavailable,65 CacheUnavailable,
64 PathTooLong,66 PathTooLong,
65 CCompilerCannotFindFile,67 CCompilerCannotFindFile,
68 NoCCompilerInstalled,
66 ReadingDepFile,69 ReadingDepFile,
67 InvalidDepFile,70 InvalidDepFile,
68 MissingArchitecture,71 MissingArchitecture,
...@@ -80,6 +83,15 @@ const Error = extern enum {...@@ -80,6 +83,15 @@ const Error = extern enum {
80 OperationAborted,83 OperationAborted,
81 BrokenPipe,84 BrokenPipe,
82 NoSpaceLeft,85 NoSpaceLeft,
86 NotLazy,
87 IsAsync,
88 ImportOutsidePkgPath,
89 UnknownCpu,
90 UnknownSubArchitecture,
91 UnknownCpuFeature,
92 InvalidCpuFeatures,
93 InvalidLlvmCpuFeaturesFormat,
94 UnknownApplicationBinaryInterface,
83};95};
8496
85const FILE = std.c.FILE;97const FILE = std.c.FILE;
...@@ -149,7 +161,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {...@@ -149,7 +161,7 @@ fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {
149 const argc_usize = @intCast(usize, argc);161 const argc_usize = @intCast(usize, argc);
150 var arg_i: usize = 0;162 var arg_i: usize = 0;
151 while (arg_i < argc_usize) : (arg_i += 1) {163 while (arg_i < argc_usize) : (arg_i += 1) {
152 try args_list.append(std.mem.toSliceConst(u8, argv[arg_i]));164 try args_list.append(mem.toSliceConst(u8, argv[arg_i]));
153 }165 }
154166
155 stdout = &std.io.getStdOut().outStream().stream;167 stdout = &std.io.getStdOut().outStream().stream;
...@@ -527,3 +539,294 @@ export fn stage2_progress_update_node(node: *std.Progress.Node, done_count: usiz...@@ -527,3 +539,294 @@ export fn stage2_progress_update_node(node: *std.Progress.Node, done_count: usiz
527 node.activate();539 node.activate();
528 node.context.maybeRefresh();540 node.context.maybeRefresh();
529}541}
542
543fn cpuFeaturesFromLLVM(
544 arch: Target.Arch,
545 llvm_cpu_name_z: ?[*:0]const u8,
546 llvm_cpu_features_opt: ?[*:0]const u8,
547) !Target.CpuFeatures {
548 var result = arch.getBaselineCpuFeatures();
549
550 if (llvm_cpu_name_z) |cpu_name_z| {
551 const llvm_cpu_name = mem.toSliceConst(u8, cpu_name_z);
552
553 for (arch.allCpus()) |cpu| {
554 const this_llvm_name = cpu.llvm_name orelse continue;
555 if (mem.eql(u8, this_llvm_name, llvm_cpu_name)) {
556 // Here we use the non-dependencies-populated set,
557 // so that subtracting features later in this function
558 // affect the prepopulated set.
559 result = Target.CpuFeatures{
560 .cpu = cpu,
561 .features = cpu.features,
562 };
563 break;
564 }
565 }
566 }
567
568 const all_features = arch.allFeaturesList();
569
570 if (llvm_cpu_features_opt) |llvm_cpu_features| {
571 var it = mem.tokenize(mem.toSliceConst(u8, llvm_cpu_features), ",");
572 while (it.next()) |decorated_llvm_feat| {
573 var op: enum {
574 add,
575 sub,
576 } = undefined;
577 var llvm_feat: []const u8 = undefined;
578 if (mem.startsWith(u8, decorated_llvm_feat, "+")) {
579 op = .add;
580 llvm_feat = decorated_llvm_feat[1..];
581 } else if (mem.startsWith(u8, decorated_llvm_feat, "-")) {
582 op = .sub;
583 llvm_feat = decorated_llvm_feat[1..];
584 } else {
585 return error.InvalidLlvmCpuFeaturesFormat;
586 }
587 for (all_features) |feature, index_usize| {
588 const this_llvm_name = feature.llvm_name orelse continue;
589 if (mem.eql(u8, llvm_feat, this_llvm_name)) {
590 const index = @intCast(Target.Cpu.Feature.Set.Index, index_usize);
591 switch (op) {
592 .add => result.features.addFeature(index),
593 .sub => result.features.removeFeature(index),
594 }
595 break;
596 }
597 }
598 }
599 }
600
601 result.features.populateDependencies(all_features);
602 return result;
603}
604
605// ABI warning
606export fn stage2_cmd_targets(zig_triple: [*:0]const u8) c_int {
607 cmdTargets(zig_triple) catch |err| {
608 std.debug.warn("unable to list targets: {}\n", .{@errorName(err)});
609 return -1;
610 };
611 return 0;
612}
613
614fn cmdTargets(zig_triple: [*:0]const u8) !void {
615 var target = try Target.parse(mem.toSliceConst(u8, zig_triple));
616 target.Cross.cpu_features = blk: {
617 const llvm = @import("llvm.zig");
618 const llvm_cpu_name = llvm.GetHostCPUName();
619 const llvm_cpu_features = llvm.GetNativeFeatures();
620 break :blk try cpuFeaturesFromLLVM(target.Cross.arch, llvm_cpu_name, llvm_cpu_features);
621 };
622 return @import("print_targets.zig").cmdTargets(
623 std.heap.c_allocator,
624 &[0][]u8{},
625 &std.io.getStdOut().outStream().stream,
626 target,
627 );
628}
629
630const Stage2CpuFeatures = struct {
631 allocator: *mem.Allocator,
632 cpu_features: Target.CpuFeatures,
633
634 llvm_features_str: ?[*:0]const u8,
635
636 builtin_str: [:0]const u8,
637 cache_hash: [:0]const u8,
638
639 const Self = @This();
640
641 fn createFromNative(allocator: *mem.Allocator) !*Self {
642 const arch = Target.current.getArch();
643 const llvm = @import("llvm.zig");
644 const llvm_cpu_name = llvm.GetHostCPUName();
645 const llvm_cpu_features = llvm.GetNativeFeatures();
646 const cpu_features = try cpuFeaturesFromLLVM(arch, llvm_cpu_name, llvm_cpu_features);
647 return createFromCpuFeatures(allocator, arch, cpu_features);
648 }
649
650 fn createFromCpuFeatures(
651 allocator: *mem.Allocator,
652 arch: Target.Arch,
653 cpu_features: Target.CpuFeatures,
654 ) !*Self {
655 const self = try allocator.create(Self);
656 errdefer allocator.destroy(self);
657
658 const cache_hash = try std.fmt.allocPrint0(allocator, "{}\n{}", .{
659 cpu_features.cpu.name,
660 cpu_features.features.asBytes(),
661 });
662 errdefer allocator.free(cache_hash);
663
664 const generic_arch_name = arch.genericName();
665 var builtin_str_buffer = try std.Buffer.allocPrint(allocator,
666 \\CpuFeatures{{
667 \\ .cpu = &Target.{}.cpu.{},
668 \\ .features = Target.{}.featureSet(&[_]Target.{}.Feature{{
669 \\
670 , .{
671 generic_arch_name,
672 cpu_features.cpu.name,
673 generic_arch_name,
674 generic_arch_name,
675 });
676 defer builtin_str_buffer.deinit();
677
678 var llvm_features_buffer = try std.Buffer.initSize(allocator, 0);
679 defer llvm_features_buffer.deinit();
680
681 for (arch.allFeaturesList()) |feature, index_usize| {
682 const index = @intCast(Target.Cpu.Feature.Set.Index, index_usize);
683 const is_enabled = cpu_features.features.isEnabled(index);
684
685 if (feature.llvm_name) |llvm_name| {
686 const plus_or_minus = "-+"[@boolToInt(is_enabled)];
687 try llvm_features_buffer.appendByte(plus_or_minus);
688 try llvm_features_buffer.append(llvm_name);
689 try llvm_features_buffer.append(",");
690 }
691
692 if (is_enabled) {
693 // TODO some kind of "zig identifier escape" function rather than
694 // unconditionally using @"" syntax
695 try builtin_str_buffer.append(" .@\"");
696 try builtin_str_buffer.append(feature.name);
697 try builtin_str_buffer.append("\",\n");
698 }
699 }
700
701 try builtin_str_buffer.append(
702 \\ }),
703 \\};
704 \\
705 );
706
707 assert(mem.endsWith(u8, llvm_features_buffer.toSliceConst(), ","));
708 llvm_features_buffer.shrink(llvm_features_buffer.len() - 1);
709
710 self.* = Self{
711 .allocator = allocator,
712 .cpu_features = cpu_features,
713 .llvm_features_str = llvm_features_buffer.toOwnedSlice().ptr,
714 .builtin_str = builtin_str_buffer.toOwnedSlice(),
715 .cache_hash = cache_hash,
716 };
717 return self;
718 }
719
720 fn destroy(self: *Self) void {
721 self.allocator.free(self.cache_hash);
722 self.allocator.free(self.builtin_str);
723 // TODO if (self.llvm_features_str) |llvm_features_str| self.allocator.free(llvm_features_str);
724 self.allocator.destroy(self);
725 }
726};
727
728// ABI warning
729export fn stage2_cpu_features_parse(
730 result: **Stage2CpuFeatures,
731 zig_triple: ?[*:0]const u8,
732 cpu_name: ?[*:0]const u8,
733 cpu_features: ?[*:0]const u8,
734) Error {
735 result.* = stage2ParseCpuFeatures(zig_triple, cpu_name, cpu_features) catch |err| switch (err) {
736 error.OutOfMemory => return .OutOfMemory,
737 error.UnknownArchitecture => return .UnknownArchitecture,
738 error.UnknownSubArchitecture => return .UnknownSubArchitecture,
739 error.UnknownOperatingSystem => return .UnknownOperatingSystem,
740 error.UnknownApplicationBinaryInterface => return .UnknownApplicationBinaryInterface,
741 error.MissingOperatingSystem => return .MissingOperatingSystem,
742 error.MissingArchitecture => return .MissingArchitecture,
743 error.InvalidLlvmCpuFeaturesFormat => return .InvalidLlvmCpuFeaturesFormat,
744 error.InvalidCpuFeatures => return .InvalidCpuFeatures,
745 };
746 return .None;
747}
748
749fn stage2ParseCpuFeatures(
750 zig_triple_oz: ?[*:0]const u8,
751 cpu_name_oz: ?[*:0]const u8,
752 cpu_features_oz: ?[*:0]const u8,
753) !*Stage2CpuFeatures {
754 const zig_triple_z = zig_triple_oz orelse return Stage2CpuFeatures.createFromNative(std.heap.c_allocator);
755 const target = try Target.parse(mem.toSliceConst(u8, zig_triple_z));
756 const arch = target.Cross.arch;
757
758 const cpu = if (cpu_name_oz) |cpu_name_z| blk: {
759 const cpu_name = mem.toSliceConst(u8, cpu_name_z);
760 break :blk arch.parseCpu(cpu_name) catch |err| switch (err) {
761 error.UnknownCpu => {
762 std.debug.warn("Unknown CPU: '{}'\nAvailable CPUs for architecture '{}':\n", .{
763 cpu_name,
764 @tagName(arch),
765 });
766 for (arch.allCpus()) |cpu| {
767 std.debug.warn(" {}\n", .{cpu.name});
768 }
769 process.exit(1);
770 },
771 else => |e| return e,
772 };
773 } else target.Cross.cpu_features.cpu;
774
775 var set = if (cpu_features_oz) |cpu_features_z| blk: {
776 const cpu_features = mem.toSliceConst(u8, cpu_features_z);
777 break :blk arch.parseCpuFeatureSet(cpu, cpu_features) catch |err| switch (err) {
778 error.UnknownCpuFeature => {
779 std.debug.warn(
780 \\Unknown CPU features specified.
781 \\Available CPU features for architecture '{}':
782 \\
783 , .{@tagName(arch)});
784 for (arch.allFeaturesList()) |feature| {
785 std.debug.warn(" {}\n", .{feature.name});
786 }
787 process.exit(1);
788 },
789 else => |e| return e,
790 };
791 } else cpu.features;
792
793 if (arch.subArchFeature()) |index| {
794 set.addFeature(index);
795 }
796 set.populateDependencies(arch.allFeaturesList());
797
798 return Stage2CpuFeatures.createFromCpuFeatures(std.heap.c_allocator, arch, .{
799 .cpu = cpu,
800 .features = set,
801 });
802}
803
804// ABI warning
805export fn stage2_cpu_features_get_cache_hash(
806 cpu_features: *const Stage2CpuFeatures,
807 ptr: *[*:0]const u8,
808 len: *usize,
809) void {
810 ptr.* = cpu_features.cache_hash.ptr;
811 len.* = cpu_features.cache_hash.len;
812}
813
814// ABI warning
815export fn stage2_cpu_features_get_builtin_str(
816 cpu_features: *const Stage2CpuFeatures,
817 ptr: *[*:0]const u8,
818 len: *usize,
819) void {
820 ptr.* = cpu_features.builtin_str.ptr;
821 len.* = cpu_features.builtin_str.len;
822}
823
824// ABI warning
825export fn stage2_cpu_features_get_llvm_cpu(cpu_features: *const Stage2CpuFeatures) ?[*:0]const u8 {
826 return if (cpu_features.cpu_features.cpu.llvm_name) |s| s.ptr else null;
827}
828
829// ABI warning
830export fn stage2_cpu_features_get_llvm_features(cpu_features: *const Stage2CpuFeatures) ?[*:0]const u8 {
831 return cpu_features.llvm_features_str;
832}
src-self-hosted/translate_c.zig+36-15
...@@ -443,12 +443,22 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {...@@ -443,12 +443,22 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
443 };443 };
444444
445 var fn_qt = ZigClangFunctionDecl_getType(fn_decl);445 var fn_qt = ZigClangFunctionDecl_getType(fn_decl);
446 var fn_type = ZigClangQualType_getTypePtr(fn_qt);446
447 if (ZigClangType_getTypeClass(fn_type) == .Attributed) {447 const fn_type = while (true) {
448 const attr_type = @ptrCast(*const ZigClangAttributedType, fn_type);448 const fn_type = ZigClangQualType_getTypePtr(fn_qt);
449 fn_qt = ZigClangAttributedType_getEquivalentType(attr_type);449
450 fn_type = ZigClangQualType_getTypePtr(fn_qt);450 switch (ZigClangType_getTypeClass(fn_type)) {
451 }451 .Attributed => {
452 const attr_type = @ptrCast(*const ZigClangAttributedType, fn_type);
453 fn_qt = ZigClangAttributedType_getEquivalentType(attr_type);
454 },
455 .Paren => {
456 const paren_type = @ptrCast(*const ZigClangParenType, fn_type);
457 fn_qt = ZigClangParenType_getInnerType(paren_type);
458 },
459 else => break fn_type,
460 }
461 } else unreachable;
452462
453 const proto_node = switch (ZigClangType_getTypeClass(fn_type)) {463 const proto_node = switch (ZigClangType_getTypeClass(fn_type)) {
454 .FunctionProto => blk: {464 .FunctionProto => blk: {
...@@ -485,6 +495,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {...@@ -485,6 +495,7 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
485 block_scope.block_node = block_node;495 block_scope.block_node = block_node;
486496
487 var it = proto_node.params.iterator(0);497 var it = proto_node.params.iterator(0);
498 var param_id: c_uint = 0;
488 while (it.next()) |p| {499 while (it.next()) |p| {
489 const param = @fieldParentPtr(ast.Node.ParamDecl, "base", p.*);500 const param = @fieldParentPtr(ast.Node.ParamDecl, "base", p.*);
490 const param_name = if (param.name_token) |name_tok|501 const param_name = if (param.name_token) |name_tok|
...@@ -498,18 +509,27 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {...@@ -498,18 +509,27 @@ fn visitFnDecl(c: *Context, fn_decl: *const ZigClangFunctionDecl) Error!void {
498509
499 const mangled_param_name = try block_scope.makeMangledName(c, param_name);510 const mangled_param_name = try block_scope.makeMangledName(c, param_name);
500511
512 const c_param = ZigClangFunctionDecl_getParamDecl(fn_decl, param_id);
513 const qual_type = ZigClangParmVarDecl_getOriginalType(c_param);
514 const is_const = ZigClangQualType_isConstQualified(qual_type);
515
501 const arg_name = blk: {516 const arg_name = blk: {
502 const bare_arg_name = try std.fmt.allocPrint(c.a(), "arg_{}", .{mangled_param_name});517 const param_prefix = if (is_const) "" else "arg_";
518 const bare_arg_name = try std.fmt.allocPrint(c.a(), "{}{}", .{ param_prefix, mangled_param_name });
503 break :blk try block_scope.makeMangledName(c, bare_arg_name);519 break :blk try block_scope.makeMangledName(c, bare_arg_name);
504 };520 };
505521
506 const node = try transCreateNodeVarDecl(c, false, false, mangled_param_name);522 if (!is_const) {
507 node.eq_token = try appendToken(c, .Equal, "=");523 const node = try transCreateNodeVarDecl(c, false, false, mangled_param_name);
508 node.init_node = try transCreateNodeIdentifier(c, arg_name);524 node.eq_token = try appendToken(c, .Equal, "=");
509 node.semicolon_token = try appendToken(c, .Semicolon, ";");525 node.init_node = try transCreateNodeIdentifier(c, arg_name);
510 try block_node.statements.push(&node.base);526 node.semicolon_token = try appendToken(c, .Semicolon, ";");
511 param.name_token = try appendIdentifier(c, arg_name);527 try block_node.statements.push(&node.base);
512 _ = try appendToken(c, .Colon, ":");528 param.name_token = try appendIdentifier(c, arg_name);
529 _ = try appendToken(c, .Colon, ":");
530 }
531
532 param_id += 1;
513 }533 }
514534
515 transCompoundStmtInline(rp, &block_scope.base, @ptrCast(*const ZigClangCompoundStmt, body_stmt), block_node) catch |err| switch (err) {535 transCompoundStmtInline(rp, &block_scope.base, @ptrCast(*const ZigClangCompoundStmt, body_stmt), block_node) catch |err| switch (err) {
...@@ -1982,7 +2002,8 @@ fn transInitListExprArray(...@@ -1982,7 +2002,8 @@ fn transInitListExprArray(
1982 const arr_type = ZigClangType_getAsArrayTypeUnsafe(ty);2002 const arr_type = ZigClangType_getAsArrayTypeUnsafe(ty);
1983 const child_qt = ZigClangArrayType_getElementType(arr_type);2003 const child_qt = ZigClangArrayType_getElementType(arr_type);
1984 const init_count = ZigClangInitListExpr_getNumInits(expr);2004 const init_count = ZigClangInitListExpr_getNumInits(expr);
1985 const const_arr_ty = @ptrCast(*const ZigClangConstantArrayType, ty);2005 assert(ZigClangType_isConstantArrayType(@ptrCast(*const ZigClangType, arr_type)));
2006 const const_arr_ty = @ptrCast(*const ZigClangConstantArrayType, arr_type);
1986 const size_ap_int = ZigClangConstantArrayType_getSize(const_arr_ty);2007 const size_ap_int = ZigClangConstantArrayType_getSize(const_arr_ty);
1987 const all_count = ZigClangAPInt_getLimitedValue(size_ap_int, math.maxInt(usize));2008 const all_count = ZigClangAPInt_getLimitedValue(size_ap_int, math.maxInt(usize));
1988 const leftover_count = all_count - init_count;2009 const leftover_count = all_count - init_count;
src/all_types.hpp+1397-909
...@@ -33,12 +33,15 @@ struct BuiltinFnEntry;...@@ -33,12 +33,15 @@ struct BuiltinFnEntry;
33struct TypeStructField;33struct TypeStructField;
34struct CodeGen;34struct CodeGen;
35struct ZigValue;35struct ZigValue;
36struct IrInstruction;36struct IrInst;
37struct IrInstructionCast;37struct IrInstSrc;
38struct IrInstructionAllocaGen;38struct IrInstGen;
39struct IrInstructionCallGen;39struct IrInstGenCast;
40struct IrInstructionAwaitGen;40struct IrInstGenAlloca;
41struct IrBasicBlock;41struct IrInstGenCall;
42struct IrInstGenAwait;
43struct IrBasicBlockSrc;
44struct IrBasicBlockGen;
42struct ScopeDecls;45struct ScopeDecls;
43struct ZigWindowsSDK;46struct ZigWindowsSDK;
44struct Tld;47struct Tld;
...@@ -50,6 +53,7 @@ struct ResultLocPeerParent;...@@ -50,6 +53,7 @@ struct ResultLocPeerParent;
50struct ResultLocBitCast;53struct ResultLocBitCast;
51struct ResultLocCast;54struct ResultLocCast;
52struct ResultLocReturn;55struct ResultLocReturn;
56struct IrExecutableGen;
5357
54enum PtrLen {58enum PtrLen {
55 PtrLenUnknown,59 PtrLenUnknown,
...@@ -97,8 +101,8 @@ enum X64CABIClass {...@@ -97,8 +101,8 @@ enum X64CABIClass {
97 X64CABIClass_SSE,101 X64CABIClass_SSE,
98};102};
99103
100struct IrExecutable {104struct IrExecutableSrc {
101 ZigList<IrBasicBlock *> basic_block_list;105 ZigList<IrBasicBlockSrc *> basic_block_list;
102 Buf *name;106 Buf *name;
103 ZigFn *name_fn;107 ZigFn *name_fn;
104 size_t mem_slot_count;108 size_t mem_slot_count;
...@@ -108,8 +112,7 @@ struct IrExecutable {...@@ -108,8 +112,7 @@ struct IrExecutable {
108 ZigFn *fn_entry;112 ZigFn *fn_entry;
109 Buf *c_import_buf;113 Buf *c_import_buf;
110 AstNode *source_node;114 AstNode *source_node;
111 IrExecutable *parent_exec;115 IrExecutableGen *parent_exec;
112 IrExecutable *source_exec;
113 IrAnalyze *analysis;116 IrAnalyze *analysis;
114 Scope *begin_scope;117 Scope *begin_scope;
115 ErrorMsg *first_err_trace_msg;118 ErrorMsg *first_err_trace_msg;
...@@ -124,6 +127,32 @@ struct IrExecutable {...@@ -124,6 +127,32 @@ struct IrExecutable {
124 void src();127 void src();
125};128};
126129
130struct IrExecutableGen {
131 ZigList<IrBasicBlockGen *> basic_block_list;
132 Buf *name;
133 ZigFn *name_fn;
134 size_t mem_slot_count;
135 size_t next_debug_id;
136 size_t *backward_branch_count;
137 size_t *backward_branch_quota;
138 ZigFn *fn_entry;
139 Buf *c_import_buf;
140 AstNode *source_node;
141 IrExecutableGen *parent_exec;
142 IrExecutableSrc *source_exec;
143 Scope *begin_scope;
144 ErrorMsg *first_err_trace_msg;
145 ZigList<Tld *> tld_list;
146
147 bool is_inline;
148 bool is_generic_instantiation;
149 bool need_err_code_spill;
150
151 // This is a function for use in the debugger to print
152 // the source location.
153 void src();
154};
155
127enum OutType {156enum OutType {
128 OutTypeUnknown,157 OutTypeUnknown,
129 OutTypeExe,158 OutTypeExe,
...@@ -287,7 +316,8 @@ struct ConstErrValue {...@@ -287,7 +316,8 @@ struct ConstErrValue {
287316
288struct ConstBoundFnValue {317struct ConstBoundFnValue {
289 ZigFn *fn;318 ZigFn *fn;
290 IrInstruction *first_arg;319 IrInstGen *first_arg;
320 IrInst *first_arg_src;
291};321};
292322
293struct ConstArgTuple {323struct ConstArgTuple {
...@@ -350,14 +380,14 @@ struct LazyValueAlignOf {...@@ -350,14 +380,14 @@ struct LazyValueAlignOf {
350 LazyValue base;380 LazyValue base;
351381
352 IrAnalyze *ira;382 IrAnalyze *ira;
353 IrInstruction *target_type;383 IrInstGen *target_type;
354};384};
355385
356struct LazyValueSizeOf {386struct LazyValueSizeOf {
357 LazyValue base;387 LazyValue base;
358388
359 IrAnalyze *ira;389 IrAnalyze *ira;
360 IrInstruction *target_type;390 IrInstGen *target_type;
361391
362 bool bit_size;392 bool bit_size;
363};393};
...@@ -366,9 +396,9 @@ struct LazyValueSliceType {...@@ -366,9 +396,9 @@ struct LazyValueSliceType {
366 LazyValue base;396 LazyValue base;
367397
368 IrAnalyze *ira;398 IrAnalyze *ira;
369 IrInstruction *sentinel; // can be null399 IrInstGen *sentinel; // can be null
370 IrInstruction *elem_type;400 IrInstGen *elem_type;
371 IrInstruction *align_inst; // can be null401 IrInstGen *align_inst; // can be null
372402
373 bool is_const;403 bool is_const;
374 bool is_volatile;404 bool is_volatile;
...@@ -379,8 +409,8 @@ struct LazyValueArrayType {...@@ -379,8 +409,8 @@ struct LazyValueArrayType {
379 LazyValue base;409 LazyValue base;
380410
381 IrAnalyze *ira;411 IrAnalyze *ira;
382 IrInstruction *sentinel; // can be null412 IrInstGen *sentinel; // can be null
383 IrInstruction *elem_type;413 IrInstGen *elem_type;
384 uint64_t length;414 uint64_t length;
385};415};
386416
...@@ -388,9 +418,9 @@ struct LazyValuePtrType {...@@ -388,9 +418,9 @@ struct LazyValuePtrType {
388 LazyValue base;418 LazyValue base;
389419
390 IrAnalyze *ira;420 IrAnalyze *ira;
391 IrInstruction *sentinel; // can be null421 IrInstGen *sentinel; // can be null
392 IrInstruction *elem_type;422 IrInstGen *elem_type;
393 IrInstruction *align_inst; // can be null423 IrInstGen *align_inst; // can be null
394424
395 PtrLen ptr_len;425 PtrLen ptr_len;
396 uint32_t bit_offset_in_host;426 uint32_t bit_offset_in_host;
...@@ -405,7 +435,7 @@ struct LazyValueOptType {...@@ -405,7 +435,7 @@ struct LazyValueOptType {
405 LazyValue base;435 LazyValue base;
406436
407 IrAnalyze *ira;437 IrAnalyze *ira;
408 IrInstruction *payload_type;438 IrInstGen *payload_type;
409};439};
410440
411struct LazyValueFnType {441struct LazyValueFnType {
...@@ -413,9 +443,9 @@ struct LazyValueFnType {...@@ -413,9 +443,9 @@ struct LazyValueFnType {
413443
414 IrAnalyze *ira;444 IrAnalyze *ira;
415 AstNode *proto_node;445 AstNode *proto_node;
416 IrInstruction **param_types;446 IrInstGen **param_types;
417 IrInstruction *align_inst; // can be null447 IrInstGen *align_inst; // can be null
418 IrInstruction *return_type;448 IrInstGen *return_type;
419449
420 CallingConvention cc;450 CallingConvention cc;
421 bool is_generic;451 bool is_generic;
...@@ -425,8 +455,8 @@ struct LazyValueErrUnionType {...@@ -425,8 +455,8 @@ struct LazyValueErrUnionType {
425 LazyValue base;455 LazyValue base;
426456
427 IrAnalyze *ira;457 IrAnalyze *ira;
428 IrInstruction *err_set_type;458 IrInstGen *err_set_type;
429 IrInstruction *payload_type;459 IrInstGen *payload_type;
430 Buf *type_name;460 Buf *type_name;
431};461};
432462
...@@ -473,6 +503,9 @@ struct ZigValue {...@@ -473,6 +503,9 @@ struct ZigValue {
473 // uncomment these to find bugs. can't leave them uncommented because of a gcc-9 warning503 // uncomment these to find bugs. can't leave them uncommented because of a gcc-9 warning
474 //ZigValue(const ZigValue &other) = delete; // plz zero initialize with {}504 //ZigValue(const ZigValue &other) = delete; // plz zero initialize with {}
475 //ZigValue& operator= (const ZigValue &other) = delete; // use copy_const_val505 //ZigValue& operator= (const ZigValue &other) = delete; // use copy_const_val
506
507 // for use in debuggers
508 void dump();
476};509};
477510
478enum ReturnKnowledge {511enum ReturnKnowledge {
...@@ -1227,6 +1260,7 @@ static const uint32_t VECTOR_INDEX_RUNTIME = UINT32_MAX - 1;...@@ -1227,6 +1260,7 @@ static const uint32_t VECTOR_INDEX_RUNTIME = UINT32_MAX - 1;
1227struct InferredStructField {1260struct InferredStructField {
1228 ZigType *inferred_struct_type;1261 ZigType *inferred_struct_type;
1229 Buf *field_name;1262 Buf *field_name;
1263 bool already_resolved;
1230};1264};
12311265
1232struct ZigTypePointer {1266struct ZigTypePointer {
...@@ -1602,19 +1636,19 @@ struct ZigFn {...@@ -1602,19 +1636,19 @@ struct ZigFn {
1602 // in the case of async functions this is the implicit return type according to the1636 // in the case of async functions this is the implicit return type according to the
1603 // zig source code, not according to zig ir1637 // zig source code, not according to zig ir
1604 ZigType *src_implicit_return_type;1638 ZigType *src_implicit_return_type;
1605 IrExecutable *ir_executable;1639 IrExecutableSrc *ir_executable;
1606 IrExecutable analyzed_executable;1640 IrExecutableGen analyzed_executable;
1607 size_t prealloc_bbc;1641 size_t prealloc_bbc;
1608 size_t prealloc_backward_branch_quota;1642 size_t prealloc_backward_branch_quota;
1609 AstNode **param_source_nodes;1643 AstNode **param_source_nodes;
1610 Buf **param_names;1644 Buf **param_names;
1611 IrInstruction *err_code_spill;1645 IrInstGen *err_code_spill;
1612 AstNode *assumed_non_async;1646 AstNode *assumed_non_async;
16131647
1614 AstNode *fn_no_inline_set_node;1648 AstNode *fn_no_inline_set_node;
1615 AstNode *fn_static_eval_set_node;1649 AstNode *fn_static_eval_set_node;
16161650
1617 ZigList<IrInstructionAllocaGen *> alloca_gen_list;1651 ZigList<IrInstGenAlloca *> alloca_gen_list;
1618 ZigList<ZigVar *> variable_list;1652 ZigList<ZigVar *> variable_list;
16191653
1620 Buf *section_name;1654 Buf *section_name;
...@@ -1626,8 +1660,8 @@ struct ZigFn {...@@ -1626,8 +1660,8 @@ struct ZigFn {
1626 AstNode *non_async_node;1660 AstNode *non_async_node;
16271661
1628 ZigList<GlobalExport> export_list;1662 ZigList<GlobalExport> export_list;
1629 ZigList<IrInstructionCallGen *> call_list;1663 ZigList<IrInstGenCall *> call_list;
1630 ZigList<IrInstructionAwaitGen *> await_list;1664 ZigList<IrInstGenAwait *> await_list;
16311665
1632 LLVMValueRef valgrind_client_request_array;1666 LLVMValueRef valgrind_client_request_array;
16331667
...@@ -1913,6 +1947,15 @@ enum BuildMode {...@@ -1913,6 +1947,15 @@ enum BuildMode {
1913 BuildModeSmallRelease,1947 BuildModeSmallRelease,
1914};1948};
19151949
1950enum CodeModel {
1951 CodeModelDefault,
1952 CodeModelTiny,
1953 CodeModelSmall,
1954 CodeModelKernel,
1955 CodeModelMedium,
1956 CodeModelLarge,
1957};
1958
1916enum EmitFileType {1959enum EmitFileType {
1917 EmitFileTypeBinary,1960 EmitFileTypeBinary,
1918 EmitFileTypeAssembly,1961 EmitFileTypeAssembly,
...@@ -2098,8 +2141,9 @@ struct CodeGen {...@@ -2098,8 +2141,9 @@ struct CodeGen {
2098 Buf *zig_c_headers_dir; // Cannot be overridden; derived from zig_lib_dir.2141 Buf *zig_c_headers_dir; // Cannot be overridden; derived from zig_lib_dir.
2099 Buf *zig_std_special_dir; // Cannot be overridden; derived from zig_lib_dir.2142 Buf *zig_std_special_dir; // Cannot be overridden; derived from zig_lib_dir.
21002143
2101 IrInstruction *invalid_instruction;2144 IrInstSrc *invalid_inst_src;
2102 IrInstruction *unreach_instruction;2145 IrInstGen *invalid_inst_gen;
2146 IrInstGen *unreach_instruction;
21032147
2104 ZigValue panic_msg_vals[PanicMsgIdCount];2148 ZigValue panic_msg_vals[PanicMsgIdCount];
21052149
...@@ -2144,6 +2188,7 @@ struct CodeGen {...@@ -2144,6 +2188,7 @@ struct CodeGen {
2144 bool verbose_llvm_ir;2188 bool verbose_llvm_ir;
2145 bool verbose_cimport;2189 bool verbose_cimport;
2146 bool verbose_cc;2190 bool verbose_cc;
2191 bool verbose_llvm_cpu_features;
2147 bool error_during_imports;2192 bool error_during_imports;
2148 bool generate_error_name_table;2193 bool generate_error_name_table;
2149 bool enable_cache; // mutually exclusive with output_dir2194 bool enable_cache; // mutually exclusive with output_dir
...@@ -2199,6 +2244,7 @@ struct CodeGen {...@@ -2199,6 +2244,7 @@ struct CodeGen {
2199 bool enable_dump_analysis;2244 bool enable_dump_analysis;
2200 bool enable_doc_generation;2245 bool enable_doc_generation;
2201 bool disable_bin_generation;2246 bool disable_bin_generation;
2247 CodeModel code_model;
22022248
2203 Buf *mmacosx_version_min;2249 Buf *mmacosx_version_min;
2204 Buf *mios_version_min;2250 Buf *mios_version_min;
...@@ -2222,8 +2268,8 @@ struct ZigVar {...@@ -2222,8 +2268,8 @@ struct ZigVar {
2222 ZigValue *const_value;2268 ZigValue *const_value;
2223 ZigType *var_type;2269 ZigType *var_type;
2224 LLVMValueRef value_ref;2270 LLVMValueRef value_ref;
2225 IrInstruction *is_comptime;2271 IrInstSrc *is_comptime;
2226 IrInstruction *ptr_instruction;2272 IrInstGen *ptr_instruction;
2227 // which node is the declaration of the variable2273 // which node is the declaration of the variable
2228 AstNode *decl_node;2274 AstNode *decl_node;
2229 ZigLLVMDILocalVariable *di_loc_var;2275 ZigLLVMDILocalVariable *di_loc_var;
...@@ -2231,8 +2277,7 @@ struct ZigVar {...@@ -2231,8 +2277,7 @@ struct ZigVar {
2231 Scope *parent_scope;2277 Scope *parent_scope;
2232 Scope *child_scope;2278 Scope *child_scope;
2233 LLVMValueRef param_value_ref;2279 LLVMValueRef param_value_ref;
2234 size_t mem_slot_index;2280 IrExecutableSrc *owner_exec;
2235 IrExecutable *owner_exec;
22362281
2237 Buf *section_name;2282 Buf *section_name;
22382283
...@@ -2252,6 +2297,7 @@ struct ZigVar {...@@ -2252,6 +2297,7 @@ struct ZigVar {
2252 bool is_thread_local;2297 bool is_thread_local;
2253 bool is_comptime_memoized;2298 bool is_comptime_memoized;
2254 bool is_comptime_memoized_value;2299 bool is_comptime_memoized_value;
2300 bool did_the_decl_codegen;
2255};2301};
22562302
2257struct ErrorTableEntry {2303struct ErrorTableEntry {
...@@ -2323,11 +2369,11 @@ struct ScopeBlock {...@@ -2323,11 +2369,11 @@ struct ScopeBlock {
2323 Scope base;2369 Scope base;
23242370
2325 Buf *name;2371 Buf *name;
2326 IrBasicBlock *end_block;2372 IrBasicBlockSrc *end_block;
2327 IrInstruction *is_comptime;2373 IrInstSrc *is_comptime;
2328 ResultLocPeerParent *peer_parent;2374 ResultLocPeerParent *peer_parent;
2329 ZigList<IrInstruction *> *incoming_values;2375 ZigList<IrInstSrc *> *incoming_values;
2330 ZigList<IrBasicBlock *> *incoming_blocks;2376 ZigList<IrBasicBlockSrc *> *incoming_blocks;
23312377
2332 AstNode *safety_set_node;2378 AstNode *safety_set_node;
2333 AstNode *fast_math_set_node;2379 AstNode *fast_math_set_node;
...@@ -2378,11 +2424,11 @@ struct ScopeLoop {...@@ -2378,11 +2424,11 @@ struct ScopeLoop {
23782424
2379 LVal lval;2425 LVal lval;
2380 Buf *name;2426 Buf *name;
2381 IrBasicBlock *break_block;2427 IrBasicBlockSrc *break_block;
2382 IrBasicBlock *continue_block;2428 IrBasicBlockSrc *continue_block;
2383 IrInstruction *is_comptime;2429 IrInstSrc *is_comptime;
2384 ZigList<IrInstruction *> *incoming_values;2430 ZigList<IrInstSrc *> *incoming_values;
2385 ZigList<IrBasicBlock *> *incoming_blocks;2431 ZigList<IrBasicBlockSrc *> *incoming_blocks;
2386 ResultLocPeerParent *peer_parent;2432 ResultLocPeerParent *peer_parent;
2387 ScopeExpr *spill_scope;2433 ScopeExpr *spill_scope;
2388};2434};
...@@ -2393,7 +2439,7 @@ struct ScopeLoop {...@@ -2393,7 +2439,7 @@ struct ScopeLoop {
2393struct ScopeRuntime {2439struct ScopeRuntime {
2394 Scope base;2440 Scope base;
23952441
2396 IrInstruction *is_comptime;2442 IrInstSrc *is_comptime;
2397};2443};
23982444
2399// This scope is created for a suspend block in order to have labeled2445// This scope is created for a suspend block in order to have labeled
...@@ -2472,319 +2518,450 @@ enum AtomicRmwOp {...@@ -2472,319 +2518,450 @@ enum AtomicRmwOp {
2472// to another basic block.2518// to another basic block.
2473// Phi instructions must be first in a basic block.2519// Phi instructions must be first in a basic block.
2474// The last instruction in a basic block must be of type unreachable.2520// The last instruction in a basic block must be of type unreachable.
2475struct IrBasicBlock {2521struct IrBasicBlockSrc {
2476 ZigList<IrInstruction *> instruction_list;2522 ZigList<IrInstSrc *> instruction_list;
2477 IrBasicBlock *other;2523 IrBasicBlockGen *child;
2478 Scope *scope;2524 Scope *scope;
2479 const char *name_hint;2525 const char *name_hint;
2480 size_t debug_id;2526 IrInst *suspend_instruction_ref;
2481 size_t ref_count;2527
2482 // index into the basic block list2528 uint32_t ref_count;
2483 size_t index;2529 uint32_t index; // index into the basic block list
2530
2531 uint32_t debug_id;
2532 bool suspended;
2533 bool in_resume_stack;
2534};
2535
2536struct IrBasicBlockGen {
2537 ZigList<IrInstGen *> instruction_list;
2538 IrBasicBlockSrc *parent;
2539 Scope *scope;
2540 const char *name_hint;
2541 uint32_t index; // index into the basic block list
2542 uint32_t ref_count;
2484 LLVMBasicBlockRef llvm_block;2543 LLVMBasicBlockRef llvm_block;
2485 LLVMBasicBlockRef llvm_exit_block;2544 LLVMBasicBlockRef llvm_exit_block;
2486 // The instruction that referenced this basic block and caused us to2545 // The instruction that referenced this basic block and caused us to
2487 // analyze the basic block. If the same instruction wants us to emit2546 // analyze the basic block. If the same instruction wants us to emit
2488 // the same basic block, then we re-generate it instead of saving it.2547 // the same basic block, then we re-generate it instead of saving it.
2489 IrInstruction *ref_instruction;2548 IrInst *ref_instruction;
2490 // When this is non-null, a branch to this basic block is only allowed2549 // When this is non-null, a branch to this basic block is only allowed
2491 // if the branch is comptime. The instruction points to the reason2550 // if the branch is comptime. The instruction points to the reason
2492 // the basic block must be comptime.2551 // the basic block must be comptime.
2493 IrInstruction *must_be_comptime_source_instr;2552 IrInst *must_be_comptime_source_instr;
2494 IrInstruction *suspend_instruction_ref;2553
2554 uint32_t debug_id;
2495 bool already_appended;2555 bool already_appended;
2496 bool suspended;
2497 bool in_resume_stack;
2498};2556};
24992557
2500// These instructions are in transition to having "pass 1" instructions
2501// and "pass 2" instructions. The pass 1 instructions are suffixed with Src
2502// and pass 2 are suffixed with Gen.
2503// Once all instructions are separated in this way, they'll have different
2504// base types for better type safety.
2505// Src instructions are generated by ir_gen_* functions in ir.cpp from AST.2558// Src instructions are generated by ir_gen_* functions in ir.cpp from AST.
2506// ir_analyze_* functions consume Src instructions and produce Gen instructions.2559// ir_analyze_* functions consume Src instructions and produce Gen instructions.
2560// Src instructions do not have type information; Gen instructions do.
2561enum IrInstSrcId {
2562 IrInstSrcIdInvalid,
2563 IrInstSrcIdDeclVar,
2564 IrInstSrcIdBr,
2565 IrInstSrcIdCondBr,
2566 IrInstSrcIdSwitchBr,
2567 IrInstSrcIdSwitchVar,
2568 IrInstSrcIdSwitchElseVar,
2569 IrInstSrcIdSwitchTarget,
2570 IrInstSrcIdPhi,
2571 IrInstSrcIdUnOp,
2572 IrInstSrcIdBinOp,
2573 IrInstSrcIdMergeErrSets,
2574 IrInstSrcIdLoadPtr,
2575 IrInstSrcIdStorePtr,
2576 IrInstSrcIdFieldPtr,
2577 IrInstSrcIdElemPtr,
2578 IrInstSrcIdVarPtr,
2579 IrInstSrcIdCall,
2580 IrInstSrcIdCallArgs,
2581 IrInstSrcIdCallExtra,
2582 IrInstSrcIdConst,
2583 IrInstSrcIdReturn,
2584 IrInstSrcIdContainerInitList,
2585 IrInstSrcIdContainerInitFields,
2586 IrInstSrcIdUnreachable,
2587 IrInstSrcIdTypeOf,
2588 IrInstSrcIdSetCold,
2589 IrInstSrcIdSetRuntimeSafety,
2590 IrInstSrcIdSetFloatMode,
2591 IrInstSrcIdArrayType,
2592 IrInstSrcIdAnyFrameType,
2593 IrInstSrcIdSliceType,
2594 IrInstSrcIdAsm,
2595 IrInstSrcIdSizeOf,
2596 IrInstSrcIdTestNonNull,
2597 IrInstSrcIdOptionalUnwrapPtr,
2598 IrInstSrcIdClz,
2599 IrInstSrcIdCtz,
2600 IrInstSrcIdPopCount,
2601 IrInstSrcIdBswap,
2602 IrInstSrcIdBitReverse,
2603 IrInstSrcIdImport,
2604 IrInstSrcIdCImport,
2605 IrInstSrcIdCInclude,
2606 IrInstSrcIdCDefine,
2607 IrInstSrcIdCUndef,
2608 IrInstSrcIdRef,
2609 IrInstSrcIdCompileErr,
2610 IrInstSrcIdCompileLog,
2611 IrInstSrcIdErrName,
2612 IrInstSrcIdEmbedFile,
2613 IrInstSrcIdCmpxchg,
2614 IrInstSrcIdFence,
2615 IrInstSrcIdTruncate,
2616 IrInstSrcIdIntCast,
2617 IrInstSrcIdFloatCast,
2618 IrInstSrcIdIntToFloat,
2619 IrInstSrcIdFloatToInt,
2620 IrInstSrcIdBoolToInt,
2621 IrInstSrcIdIntType,
2622 IrInstSrcIdVectorType,
2623 IrInstSrcIdShuffleVector,
2624 IrInstSrcIdSplat,
2625 IrInstSrcIdBoolNot,
2626 IrInstSrcIdMemset,
2627 IrInstSrcIdMemcpy,
2628 IrInstSrcIdSlice,
2629 IrInstSrcIdMemberCount,
2630 IrInstSrcIdMemberType,
2631 IrInstSrcIdMemberName,
2632 IrInstSrcIdBreakpoint,
2633 IrInstSrcIdReturnAddress,
2634 IrInstSrcIdFrameAddress,
2635 IrInstSrcIdFrameHandle,
2636 IrInstSrcIdFrameType,
2637 IrInstSrcIdFrameSize,
2638 IrInstSrcIdAlignOf,
2639 IrInstSrcIdOverflowOp,
2640 IrInstSrcIdTestErr,
2641 IrInstSrcIdMulAdd,
2642 IrInstSrcIdFloatOp,
2643 IrInstSrcIdUnwrapErrCode,
2644 IrInstSrcIdUnwrapErrPayload,
2645 IrInstSrcIdFnProto,
2646 IrInstSrcIdTestComptime,
2647 IrInstSrcIdPtrCast,
2648 IrInstSrcIdBitCast,
2649 IrInstSrcIdIntToPtr,
2650 IrInstSrcIdPtrToInt,
2651 IrInstSrcIdIntToEnum,
2652 IrInstSrcIdEnumToInt,
2653 IrInstSrcIdIntToErr,
2654 IrInstSrcIdErrToInt,
2655 IrInstSrcIdCheckSwitchProngs,
2656 IrInstSrcIdCheckStatementIsVoid,
2657 IrInstSrcIdTypeName,
2658 IrInstSrcIdDeclRef,
2659 IrInstSrcIdPanic,
2660 IrInstSrcIdTagName,
2661 IrInstSrcIdTagType,
2662 IrInstSrcIdFieldParentPtr,
2663 IrInstSrcIdByteOffsetOf,
2664 IrInstSrcIdBitOffsetOf,
2665 IrInstSrcIdTypeInfo,
2666 IrInstSrcIdType,
2667 IrInstSrcIdHasField,
2668 IrInstSrcIdTypeId,
2669 IrInstSrcIdSetEvalBranchQuota,
2670 IrInstSrcIdPtrType,
2671 IrInstSrcIdAlignCast,
2672 IrInstSrcIdImplicitCast,
2673 IrInstSrcIdResolveResult,
2674 IrInstSrcIdResetResult,
2675 IrInstSrcIdOpaqueType,
2676 IrInstSrcIdSetAlignStack,
2677 IrInstSrcIdArgType,
2678 IrInstSrcIdExport,
2679 IrInstSrcIdErrorReturnTrace,
2680 IrInstSrcIdErrorUnion,
2681 IrInstSrcIdAtomicRmw,
2682 IrInstSrcIdAtomicLoad,
2683 IrInstSrcIdAtomicStore,
2684 IrInstSrcIdSaveErrRetAddr,
2685 IrInstSrcIdAddImplicitReturnType,
2686 IrInstSrcIdErrSetCast,
2687 IrInstSrcIdToBytes,
2688 IrInstSrcIdFromBytes,
2689 IrInstSrcIdCheckRuntimeScope,
2690 IrInstSrcIdHasDecl,
2691 IrInstSrcIdUndeclaredIdent,
2692 IrInstSrcIdAlloca,
2693 IrInstSrcIdEndExpr,
2694 IrInstSrcIdUnionInitNamedField,
2695 IrInstSrcIdSuspendBegin,
2696 IrInstSrcIdSuspendFinish,
2697 IrInstSrcIdAwait,
2698 IrInstSrcIdResume,
2699 IrInstSrcIdSpillBegin,
2700 IrInstSrcIdSpillEnd,
2701};
2702
2507// ir_render_* functions in codegen.cpp consume Gen instructions and produce LLVM IR.2703// ir_render_* functions in codegen.cpp consume Gen instructions and produce LLVM IR.
2508// Src instructions do not have type information; Gen instructions do.2704// Src instructions do not have type information; Gen instructions do.
2509enum IrInstructionId {2705enum IrInstGenId {
2510 IrInstructionIdInvalid,2706 IrInstGenIdInvalid,
2511 IrInstructionIdDeclVarSrc,2707 IrInstGenIdDeclVar,
2512 IrInstructionIdDeclVarGen,2708 IrInstGenIdBr,
2513 IrInstructionIdBr,2709 IrInstGenIdCondBr,
2514 IrInstructionIdCondBr,2710 IrInstGenIdSwitchBr,
2515 IrInstructionIdSwitchBr,2711 IrInstGenIdPhi,
2516 IrInstructionIdSwitchVar,2712 IrInstGenIdBinaryNot,
2517 IrInstructionIdSwitchElseVar,2713 IrInstGenIdNegation,
2518 IrInstructionIdSwitchTarget,2714 IrInstGenIdNegationWrapping,
2519 IrInstructionIdPhi,2715 IrInstGenIdBinOp,
2520 IrInstructionIdUnOp,2716 IrInstGenIdLoadPtr,
2521 IrInstructionIdBinOp,2717 IrInstGenIdStorePtr,
2522 IrInstructionIdMergeErrSets,2718 IrInstGenIdVectorStoreElem,
2523 IrInstructionIdLoadPtr,2719 IrInstGenIdStructFieldPtr,
2524 IrInstructionIdLoadPtrGen,2720 IrInstGenIdUnionFieldPtr,
2525 IrInstructionIdStorePtr,2721 IrInstGenIdElemPtr,
2526 IrInstructionIdVectorStoreElem,2722 IrInstGenIdVarPtr,
2527 IrInstructionIdFieldPtr,2723 IrInstGenIdReturnPtr,
2528 IrInstructionIdStructFieldPtr,2724 IrInstGenIdCall,
2529 IrInstructionIdUnionFieldPtr,2725 IrInstGenIdReturn,
2530 IrInstructionIdElemPtr,2726 IrInstGenIdCast,
2531 IrInstructionIdVarPtr,2727 IrInstGenIdResizeSlice,
2532 IrInstructionIdReturnPtr,2728 IrInstGenIdUnreachable,
2533 IrInstructionIdCallSrc,2729 IrInstGenIdAsm,
2534 IrInstructionIdCallSrcArgs,2730 IrInstGenIdTestNonNull,
2535 IrInstructionIdCallExtra,2731 IrInstGenIdOptionalUnwrapPtr,
2536 IrInstructionIdCallGen,2732 IrInstGenIdOptionalWrap,
2537 IrInstructionIdConst,2733 IrInstGenIdUnionTag,
2538 IrInstructionIdReturn,2734 IrInstGenIdClz,
2539 IrInstructionIdCast,2735 IrInstGenIdCtz,
2540 IrInstructionIdResizeSlice,2736 IrInstGenIdPopCount,
2541 IrInstructionIdContainerInitList,2737 IrInstGenIdBswap,
2542 IrInstructionIdContainerInitFields,2738 IrInstGenIdBitReverse,
2543 IrInstructionIdUnreachable,2739 IrInstGenIdRef,
2544 IrInstructionIdTypeOf,2740 IrInstGenIdErrName,
2545 IrInstructionIdSetCold,2741 IrInstGenIdCmpxchg,
2546 IrInstructionIdSetRuntimeSafety,2742 IrInstGenIdFence,
2547 IrInstructionIdSetFloatMode,2743 IrInstGenIdTruncate,
2548 IrInstructionIdArrayType,2744 IrInstGenIdShuffleVector,
2549 IrInstructionIdAnyFrameType,2745 IrInstGenIdSplat,
2550 IrInstructionIdSliceType,2746 IrInstGenIdBoolNot,
2551 IrInstructionIdAsmSrc,2747 IrInstGenIdMemset,
2552 IrInstructionIdAsmGen,2748 IrInstGenIdMemcpy,
2553 IrInstructionIdSizeOf,2749 IrInstGenIdSlice,
2554 IrInstructionIdTestNonNull,2750 IrInstGenIdBreakpoint,
2555 IrInstructionIdOptionalUnwrapPtr,2751 IrInstGenIdReturnAddress,
2556 IrInstructionIdOptionalWrap,2752 IrInstGenIdFrameAddress,
2557 IrInstructionIdUnionTag,2753 IrInstGenIdFrameHandle,
2558 IrInstructionIdClz,2754 IrInstGenIdFrameSize,
2559 IrInstructionIdCtz,2755 IrInstGenIdOverflowOp,
2560 IrInstructionIdPopCount,2756 IrInstGenIdTestErr,
2561 IrInstructionIdBswap,2757 IrInstGenIdMulAdd,
2562 IrInstructionIdBitReverse,2758 IrInstGenIdFloatOp,
2563 IrInstructionIdImport,2759 IrInstGenIdUnwrapErrCode,
2564 IrInstructionIdCImport,2760 IrInstGenIdUnwrapErrPayload,
2565 IrInstructionIdCInclude,2761 IrInstGenIdErrWrapCode,
2566 IrInstructionIdCDefine,2762 IrInstGenIdErrWrapPayload,
2567 IrInstructionIdCUndef,2763 IrInstGenIdPtrCast,
2568 IrInstructionIdRef,2764 IrInstGenIdBitCast,
2569 IrInstructionIdRefGen,2765 IrInstGenIdWidenOrShorten,
2570 IrInstructionIdCompileErr,2766 IrInstGenIdIntToPtr,
2571 IrInstructionIdCompileLog,2767 IrInstGenIdPtrToInt,
2572 IrInstructionIdErrName,2768 IrInstGenIdIntToEnum,
2573 IrInstructionIdEmbedFile,2769 IrInstGenIdIntToErr,
2574 IrInstructionIdCmpxchgSrc,2770 IrInstGenIdErrToInt,
2575 IrInstructionIdCmpxchgGen,2771 IrInstGenIdPanic,
2576 IrInstructionIdFence,2772 IrInstGenIdTagName,
2577 IrInstructionIdTruncate,2773 IrInstGenIdFieldParentPtr,
2578 IrInstructionIdIntCast,2774 IrInstGenIdAlignCast,
2579 IrInstructionIdFloatCast,2775 IrInstGenIdErrorReturnTrace,
2580 IrInstructionIdIntToFloat,2776 IrInstGenIdAtomicRmw,
2581 IrInstructionIdFloatToInt,2777 IrInstGenIdAtomicLoad,
2582 IrInstructionIdBoolToInt,2778 IrInstGenIdAtomicStore,
2583 IrInstructionIdIntType,2779 IrInstGenIdSaveErrRetAddr,
2584 IrInstructionIdVectorType,2780 IrInstGenIdVectorToArray,
2585 IrInstructionIdShuffleVector,2781 IrInstGenIdArrayToVector,
2586 IrInstructionIdSplatSrc,2782 IrInstGenIdAssertZero,
2587 IrInstructionIdSplatGen,2783 IrInstGenIdAssertNonNull,
2588 IrInstructionIdBoolNot,2784 IrInstGenIdPtrOfArrayToSlice,
2589 IrInstructionIdMemset,2785 IrInstGenIdSuspendBegin,
2590 IrInstructionIdMemcpy,2786 IrInstGenIdSuspendFinish,
2591 IrInstructionIdSliceSrc,2787 IrInstGenIdAwait,
2592 IrInstructionIdSliceGen,2788 IrInstGenIdResume,
2593 IrInstructionIdMemberCount,2789 IrInstGenIdSpillBegin,
2594 IrInstructionIdMemberType,2790 IrInstGenIdSpillEnd,
2595 IrInstructionIdMemberName,2791 IrInstGenIdVectorExtractElem,
2596 IrInstructionIdBreakpoint,2792 IrInstGenIdAlloca,
2597 IrInstructionIdReturnAddress,2793 IrInstGenIdConst,
2598 IrInstructionIdFrameAddress,2794};
2599 IrInstructionIdFrameHandle,2795
2600 IrInstructionIdFrameType,2796// Common fields between IrInstSrc and IrInstGen. This allows future passes
2601 IrInstructionIdFrameSizeSrc,2797// after pass2 to be added to zig.
2602 IrInstructionIdFrameSizeGen,2798struct IrInst {
2603 IrInstructionIdAlignOf,
2604 IrInstructionIdOverflowOp,
2605 IrInstructionIdTestErrSrc,
2606 IrInstructionIdTestErrGen,
2607 IrInstructionIdMulAdd,
2608 IrInstructionIdFloatOp,
2609 IrInstructionIdUnwrapErrCode,
2610 IrInstructionIdUnwrapErrPayload,
2611 IrInstructionIdErrWrapCode,
2612 IrInstructionIdErrWrapPayload,
2613 IrInstructionIdFnProto,
2614 IrInstructionIdTestComptime,
2615 IrInstructionIdPtrCastSrc,
2616 IrInstructionIdPtrCastGen,
2617 IrInstructionIdBitCastSrc,
2618 IrInstructionIdBitCastGen,
2619 IrInstructionIdWidenOrShorten,
2620 IrInstructionIdIntToPtr,
2621 IrInstructionIdPtrToInt,
2622 IrInstructionIdIntToEnum,
2623 IrInstructionIdEnumToInt,
2624 IrInstructionIdIntToErr,
2625 IrInstructionIdErrToInt,
2626 IrInstructionIdCheckSwitchProngs,
2627 IrInstructionIdCheckStatementIsVoid,
2628 IrInstructionIdTypeName,
2629 IrInstructionIdDeclRef,
2630 IrInstructionIdPanic,
2631 IrInstructionIdTagName,
2632 IrInstructionIdTagType,
2633 IrInstructionIdFieldParentPtr,
2634 IrInstructionIdByteOffsetOf,
2635 IrInstructionIdBitOffsetOf,
2636 IrInstructionIdTypeInfo,
2637 IrInstructionIdType,
2638 IrInstructionIdHasField,
2639 IrInstructionIdTypeId,
2640 IrInstructionIdSetEvalBranchQuota,
2641 IrInstructionIdPtrType,
2642 IrInstructionIdAlignCast,
2643 IrInstructionIdImplicitCast,
2644 IrInstructionIdResolveResult,
2645 IrInstructionIdResetResult,
2646 IrInstructionIdOpaqueType,
2647 IrInstructionIdSetAlignStack,
2648 IrInstructionIdArgType,
2649 IrInstructionIdExport,
2650 IrInstructionIdErrorReturnTrace,
2651 IrInstructionIdErrorUnion,
2652 IrInstructionIdAtomicRmw,
2653 IrInstructionIdAtomicLoad,
2654 IrInstructionIdAtomicStore,
2655 IrInstructionIdSaveErrRetAddr,
2656 IrInstructionIdAddImplicitReturnType,
2657 IrInstructionIdErrSetCast,
2658 IrInstructionIdToBytes,
2659 IrInstructionIdFromBytes,
2660 IrInstructionIdCheckRuntimeScope,
2661 IrInstructionIdVectorToArray,
2662 IrInstructionIdArrayToVector,
2663 IrInstructionIdAssertZero,
2664 IrInstructionIdAssertNonNull,
2665 IrInstructionIdHasDecl,
2666 IrInstructionIdUndeclaredIdent,
2667 IrInstructionIdAllocaSrc,
2668 IrInstructionIdAllocaGen,
2669 IrInstructionIdEndExpr,
2670 IrInstructionIdPtrOfArrayToSlice,
2671 IrInstructionIdUnionInitNamedField,
2672 IrInstructionIdSuspendBegin,
2673 IrInstructionIdSuspendFinish,
2674 IrInstructionIdAwaitSrc,
2675 IrInstructionIdAwaitGen,
2676 IrInstructionIdResume,
2677 IrInstructionIdSpillBegin,
2678 IrInstructionIdSpillEnd,
2679 IrInstructionIdVectorExtractElem,
2680};
2681
2682struct IrInstruction {
2683 Scope *scope;
2684 AstNode *source_node;
2685 LLVMValueRef llvm_value;
2686 ZigValue *value;
2687 uint32_t debug_id;
2688 // if ref_count is zero and the instruction has no side effects,2799 // if ref_count is zero and the instruction has no side effects,
2689 // the instruction can be omitted in codegen2800 // the instruction can be omitted in codegen
2690 uint32_t ref_count;2801 uint32_t ref_count;
2802 uint32_t debug_id;
2803
2804 Scope *scope;
2805 AstNode *source_node;
2806
2807 // for debugging purposes, these are useful to call to inspect the instruction
2808 void dump();
2809 void src();
2810};
2811
2812struct IrInstSrc {
2813 IrInst base;
2814
2815 IrInstSrcId id;
2816 // true if this instruction was generated by zig and not from user code
2817 // this matters for the "unreachable code" compile error
2818 bool is_gen;
2819 bool is_noreturn;
2820
2691 // When analyzing IR, instructions that point to this instruction in the "old ir"2821 // When analyzing IR, instructions that point to this instruction in the "old ir"
2692 // can find the instruction that corresponds to this value in the "new ir"2822 // can find the instruction that corresponds to this value in the "new ir"
2693 // with this child field.2823 // with this child field.
2694 IrInstruction *child;2824 IrInstGen *child;
2695 IrBasicBlock *owner_bb;2825 IrBasicBlockSrc *owner_bb;
2826
2827 // for debugging purposes, these are useful to call to inspect the instruction
2828 void dump();
2829 void src();
2830};
2831
2832struct IrInstGen {
2833 IrInst base;
2834
2835 IrInstGenId id;
2836
2837 LLVMValueRef llvm_value;
2838 ZigValue *value;
2839 IrBasicBlockGen *owner_bb;
2696 // Nearly any instruction can have to be stored as a local variable before suspending2840 // Nearly any instruction can have to be stored as a local variable before suspending
2697 // and then loaded after resuming, in case there is an expression with a suspend point2841 // and then loaded after resuming, in case there is an expression with a suspend point
2698 // in it, such as: x + await y2842 // in it, such as: x + await y
2699 IrInstruction *spill;2843 IrInstGen *spill;
2700 IrInstructionId id;
2701 // true if this instruction was generated by zig and not from user code
2702 bool is_gen;
27032844
2704 // for debugging purposes, these are useful to call to inspect the instruction2845 // for debugging purposes, these are useful to call to inspect the instruction
2705 void dump();2846 void dump();
2706 void src();2847 void src();
2707};2848};
27082849
2709struct IrInstructionDeclVarSrc {2850struct IrInstSrcDeclVar {
2710 IrInstruction base;2851 IrInstSrc base;
27112852
2712 ZigVar *var;2853 ZigVar *var;
2713 IrInstruction *var_type;2854 IrInstSrc *var_type;
2714 IrInstruction *align_value;2855 IrInstSrc *align_value;
2715 IrInstruction *ptr;2856 IrInstSrc *ptr;
2716};2857};
27172858
2718struct IrInstructionDeclVarGen {2859struct IrInstGenDeclVar {
2719 IrInstruction base;2860 IrInstGen base;
27202861
2721 ZigVar *var;2862 ZigVar *var;
2722 IrInstruction *var_ptr;2863 IrInstGen *var_ptr;
2723};2864};
27242865
2725struct IrInstructionCondBr {2866struct IrInstSrcCondBr {
2726 IrInstruction base;2867 IrInstSrc base;
27272868
2728 IrInstruction *condition;2869 IrInstSrc *condition;
2729 IrBasicBlock *then_block;2870 IrBasicBlockSrc *then_block;
2730 IrBasicBlock *else_block;2871 IrBasicBlockSrc *else_block;
2731 IrInstruction *is_comptime;2872 IrInstSrc *is_comptime;
2732 ResultLoc *result_loc;2873 ResultLoc *result_loc;
2733};2874};
27342875
2735struct IrInstructionBr {2876struct IrInstGenCondBr {
2736 IrInstruction base;2877 IrInstGen base;
2878
2879 IrInstGen *condition;
2880 IrBasicBlockGen *then_block;
2881 IrBasicBlockGen *else_block;
2882};
2883
2884struct IrInstSrcBr {
2885 IrInstSrc base;
27372886
2738 IrBasicBlock *dest_block;2887 IrBasicBlockSrc *dest_block;
2739 IrInstruction *is_comptime;2888 IrInstSrc *is_comptime;
2740};2889};
27412890
2742struct IrInstructionSwitchBrCase {2891struct IrInstGenBr {
2743 IrInstruction *value;2892 IrInstGen base;
2744 IrBasicBlock *block;2893
2894 IrBasicBlockGen *dest_block;
2895};
2896
2897struct IrInstSrcSwitchBrCase {
2898 IrInstSrc *value;
2899 IrBasicBlockSrc *block;
2745};2900};
27462901
2747struct IrInstructionSwitchBr {2902struct IrInstSrcSwitchBr {
2748 IrInstruction base;2903 IrInstSrc base;
27492904
2750 IrInstruction *target_value;2905 IrInstSrc *target_value;
2751 IrBasicBlock *else_block;2906 IrBasicBlockSrc *else_block;
2752 size_t case_count;2907 size_t case_count;
2753 IrInstructionSwitchBrCase *cases;2908 IrInstSrcSwitchBrCase *cases;
2754 IrInstruction *is_comptime;2909 IrInstSrc *is_comptime;
2755 IrInstruction *switch_prongs_void;2910 IrInstSrc *switch_prongs_void;
2756};2911};
27572912
2758struct IrInstructionSwitchVar {2913struct IrInstGenSwitchBrCase {
2759 IrInstruction base;2914 IrInstGen *value;
2915 IrBasicBlockGen *block;
2916};
27602917
2761 IrInstruction *target_value_ptr;2918struct IrInstGenSwitchBr {
2762 IrInstruction **prongs_ptr;2919 IrInstGen base;
2920
2921 IrInstGen *target_value;
2922 IrBasicBlockGen *else_block;
2923 size_t case_count;
2924 IrInstGenSwitchBrCase *cases;
2925};
2926
2927struct IrInstSrcSwitchVar {
2928 IrInstSrc base;
2929
2930 IrInstSrc *target_value_ptr;
2931 IrInstSrc **prongs_ptr;
2763 size_t prongs_len;2932 size_t prongs_len;
2764};2933};
27652934
2766struct IrInstructionSwitchElseVar {2935struct IrInstSrcSwitchElseVar {
2767 IrInstruction base;2936 IrInstSrc base;
27682937
2769 IrInstruction *target_value_ptr;2938 IrInstSrc *target_value_ptr;
2770 IrInstructionSwitchBr *switch_br;2939 IrInstSrcSwitchBr *switch_br;
2771};2940};
27722941
2773struct IrInstructionSwitchTarget {2942struct IrInstSrcSwitchTarget {
2774 IrInstruction base;2943 IrInstSrc base;
27752944
2776 IrInstruction *target_value_ptr;2945 IrInstSrc *target_value_ptr;
2777};2946};
27782947
2779struct IrInstructionPhi {2948struct IrInstSrcPhi {
2780 IrInstruction base;2949 IrInstSrc base;
27812950
2782 size_t incoming_count;2951 size_t incoming_count;
2783 IrBasicBlock **incoming_blocks;2952 IrBasicBlockSrc **incoming_blocks;
2784 IrInstruction **incoming_values;2953 IrInstSrc **incoming_values;
2785 ResultLocPeerParent *peer_parent;2954 ResultLocPeerParent *peer_parent;
2786};2955};
27872956
2957struct IrInstGenPhi {
2958 IrInstGen base;
2959
2960 size_t incoming_count;
2961 IrBasicBlockGen **incoming_blocks;
2962 IrInstGen **incoming_values;
2963};
2964
2788enum IrUnOp {2965enum IrUnOp {
2789 IrUnOpInvalid,2966 IrUnOpInvalid,
2790 IrUnOpBinNot,2967 IrUnOpBinNot,
...@@ -2794,15 +2971,30 @@ enum IrUnOp {...@@ -2794,15 +2971,30 @@ enum IrUnOp {
2794 IrUnOpOptional,2971 IrUnOpOptional,
2795};2972};
27962973
2797struct IrInstructionUnOp {2974struct IrInstSrcUnOp {
2798 IrInstruction base;2975 IrInstSrc base;
27992976
2800 IrUnOp op_id;2977 IrUnOp op_id;
2801 LVal lval;2978 LVal lval;
2802 IrInstruction *value;2979 IrInstSrc *value;
2803 ResultLoc *result_loc;2980 ResultLoc *result_loc;
2804};2981};
28052982
2983struct IrInstGenBinaryNot {
2984 IrInstGen base;
2985 IrInstGen *operand;
2986};
2987
2988struct IrInstGenNegation {
2989 IrInstGen base;
2990 IrInstGen *operand;
2991};
2992
2993struct IrInstGenNegationWrapping {
2994 IrInstGen base;
2995 IrInstGen *operand;
2996};
2997
2806enum IrBinOp {2998enum IrBinOp {
2807 IrBinOpInvalid,2999 IrBinOpInvalid,
2808 IrBinOpBoolOr,3000 IrBinOpBoolOr,
...@@ -2837,113 +3029,144 @@ enum IrBinOp {...@@ -2837,113 +3029,144 @@ enum IrBinOp {
2837 IrBinOpArrayMult,3029 IrBinOpArrayMult,
2838};3030};
28393031
2840struct IrInstructionBinOp {3032struct IrInstSrcBinOp {
2841 IrInstruction base;3033 IrInstSrc base;
28423034
2843 IrInstruction *op1;3035 IrInstSrc *op1;
2844 IrInstruction *op2;3036 IrInstSrc *op2;
2845 IrBinOp op_id;3037 IrBinOp op_id;
2846 bool safety_check_on;3038 bool safety_check_on;
2847};3039};
28483040
2849struct IrInstructionMergeErrSets {3041struct IrInstGenBinOp {
2850 IrInstruction base;3042 IrInstGen base;
28513043
2852 IrInstruction *op1;3044 IrInstGen *op1;
2853 IrInstruction *op2;3045 IrInstGen *op2;
3046 IrBinOp op_id;
3047 bool safety_check_on;
3048};
3049
3050struct IrInstSrcMergeErrSets {
3051 IrInstSrc base;
3052
3053 IrInstSrc *op1;
3054 IrInstSrc *op2;
2854 Buf *type_name;3055 Buf *type_name;
2855};3056};
28563057
2857struct IrInstructionLoadPtr {3058struct IrInstSrcLoadPtr {
2858 IrInstruction base;3059 IrInstSrc base;
28593060
2860 IrInstruction *ptr;3061 IrInstSrc *ptr;
2861};3062};
28623063
2863struct IrInstructionLoadPtrGen {3064struct IrInstGenLoadPtr {
2864 IrInstruction base;3065 IrInstGen base;
28653066
2866 IrInstruction *ptr;3067 IrInstGen *ptr;
2867 IrInstruction *result_loc;3068 IrInstGen *result_loc;
2868};3069};
28693070
2870struct IrInstructionStorePtr {3071struct IrInstSrcStorePtr {
2871 IrInstruction base;3072 IrInstSrc base;
3073
3074 IrInstSrc *ptr;
3075 IrInstSrc *value;
28723076
2873 bool allow_write_through_const;3077 bool allow_write_through_const;
2874 IrInstruction *ptr;
2875 IrInstruction *value;
2876};3078};
28773079
2878struct IrInstructionVectorStoreElem {3080struct IrInstGenStorePtr {
2879 IrInstruction base;3081 IrInstGen base;
28803082
2881 IrInstruction *vector_ptr;3083 IrInstGen *ptr;
2882 IrInstruction *index;3084 IrInstGen *value;
2883 IrInstruction *value;
2884};3085};
28853086
2886struct IrInstructionFieldPtr {3087struct IrInstGenVectorStoreElem {
2887 IrInstruction base;3088 IrInstGen base;
28883089
2889 bool initializing;3090 IrInstGen *vector_ptr;
2890 IrInstruction *container_ptr;3091 IrInstGen *index;
3092 IrInstGen *value;
3093};
3094
3095struct IrInstSrcFieldPtr {
3096 IrInstSrc base;
3097
3098 IrInstSrc *container_ptr;
2891 Buf *field_name_buffer;3099 Buf *field_name_buffer;
2892 IrInstruction *field_name_expr;3100 IrInstSrc *field_name_expr;
3101 bool initializing;
2893};3102};
28943103
2895struct IrInstructionStructFieldPtr {3104struct IrInstGenStructFieldPtr {
2896 IrInstruction base;3105 IrInstGen base;
28973106
2898 IrInstruction *struct_ptr;3107 IrInstGen *struct_ptr;
2899 TypeStructField *field;3108 TypeStructField *field;
2900 bool is_const;3109 bool is_const;
2901};3110};
29023111
2903struct IrInstructionUnionFieldPtr {3112struct IrInstGenUnionFieldPtr {
2904 IrInstruction base;3113 IrInstGen base;
29053114
3115 IrInstGen *union_ptr;
3116 TypeUnionField *field;
2906 bool safety_check_on;3117 bool safety_check_on;
2907 bool initializing;3118 bool initializing;
2908 IrInstruction *union_ptr;
2909 TypeUnionField *field;
2910};3119};
29113120
2912struct IrInstructionElemPtr {3121struct IrInstSrcElemPtr {
2913 IrInstruction base;3122 IrInstSrc base;
29143123
2915 IrInstruction *array_ptr;3124 IrInstSrc *array_ptr;
2916 IrInstruction *elem_index;3125 IrInstSrc *elem_index;
2917 AstNode *init_array_type_source_node;3126 AstNode *init_array_type_source_node;
2918 PtrLen ptr_len;3127 PtrLen ptr_len;
2919 bool safety_check_on;3128 bool safety_check_on;
2920};3129};
29213130
2922struct IrInstructionVarPtr {3131struct IrInstGenElemPtr {
2923 IrInstruction base;3132 IrInstGen base;
3133
3134 IrInstGen *array_ptr;
3135 IrInstGen *elem_index;
3136 bool safety_check_on;
3137};
3138
3139struct IrInstSrcVarPtr {
3140 IrInstSrc base;
29243141
2925 ZigVar *var;3142 ZigVar *var;
2926 ScopeFnDef *crossed_fndef_scope;3143 ScopeFnDef *crossed_fndef_scope;
2927};3144};
29283145
3146struct IrInstGenVarPtr {
3147 IrInstGen base;
3148
3149 ZigVar *var;
3150};
3151
2929// For functions that have a return type for which handle_is_ptr is true, a3152// For functions that have a return type for which handle_is_ptr is true, a
2930// result location pointer is the secret first parameter ("sret"). This3153// result location pointer is the secret first parameter ("sret"). This
2931// instruction returns that pointer.3154// instruction returns that pointer.
2932struct IrInstructionReturnPtr {3155struct IrInstGenReturnPtr {
2933 IrInstruction base;3156 IrInstGen base;
2934};3157};
29353158
2936struct IrInstructionCallSrc {3159struct IrInstSrcCall {
2937 IrInstruction base;3160 IrInstSrc base;
29383161
2939 IrInstruction *fn_ref;3162 IrInstSrc *fn_ref;
2940 ZigFn *fn_entry;3163 ZigFn *fn_entry;
2941 size_t arg_count;3164 size_t arg_count;
2942 IrInstruction **args;3165 IrInstSrc **args;
2943 IrInstruction *ret_ptr;3166 IrInstSrc *ret_ptr;
2944 ResultLoc *result_loc;3167 ResultLoc *result_loc;
29453168
2946 IrInstruction *new_stack;3169 IrInstSrc *new_stack;
29473170
2948 CallModifier modifier;3171 CallModifier modifier;
2949 bool is_async_call_builtin;3172 bool is_async_call_builtin;
...@@ -2951,12 +3174,12 @@ struct IrInstructionCallSrc {...@@ -2951,12 +3174,12 @@ struct IrInstructionCallSrc {
29513174
2952// This is a pass1 instruction, used by @call when the args node is3175// This is a pass1 instruction, used by @call when the args node is
2953// a tuple or struct literal.3176// a tuple or struct literal.
2954struct IrInstructionCallSrcArgs {3177struct IrInstSrcCallArgs {
2955 IrInstruction base;3178 IrInstSrc base;
29563179
2957 IrInstruction *options;3180 IrInstSrc *options;
2958 IrInstruction *fn_ref;3181 IrInstSrc *fn_ref;
2959 IrInstruction **args_ptr;3182 IrInstSrc **args_ptr;
2960 size_t args_len;3183 size_t args_len;
2961 ResultLoc *result_loc;3184 ResultLoc *result_loc;
2962};3185};
...@@ -2964,42 +3187,54 @@ struct IrInstructionCallSrcArgs {...@@ -2964,42 +3187,54 @@ struct IrInstructionCallSrcArgs {
2964// This is a pass1 instruction, used by @call, when the args node3187// This is a pass1 instruction, used by @call, when the args node
2965// is not a literal.3188// is not a literal.
2966// `args` is expected to be either a struct or a tuple.3189// `args` is expected to be either a struct or a tuple.
2967struct IrInstructionCallExtra {3190struct IrInstSrcCallExtra {
2968 IrInstruction base;3191 IrInstSrc base;
29693192
2970 IrInstruction *options;3193 IrInstSrc *options;
2971 IrInstruction *fn_ref;3194 IrInstSrc *fn_ref;
2972 IrInstruction *args;3195 IrInstSrc *args;
2973 ResultLoc *result_loc;3196 ResultLoc *result_loc;
2974};3197};
29753198
2976struct IrInstructionCallGen {3199struct IrInstGenCall {
2977 IrInstruction base;3200 IrInstGen base;
29783201
2979 IrInstruction *fn_ref;3202 IrInstGen *fn_ref;
2980 ZigFn *fn_entry;3203 ZigFn *fn_entry;
2981 size_t arg_count;3204 size_t arg_count;
2982 IrInstruction **args;3205 IrInstGen **args;
2983 IrInstruction *result_loc;3206 IrInstGen *result_loc;
2984 IrInstruction *frame_result_loc;3207 IrInstGen *frame_result_loc;
2985 IrInstruction *new_stack;3208 IrInstGen *new_stack;
29863209
2987 CallModifier modifier;3210 CallModifier modifier;
29883211
2989 bool is_async_call_builtin;3212 bool is_async_call_builtin;
2990};3213};
29913214
2992struct IrInstructionConst {3215struct IrInstSrcConst {
2993 IrInstruction base;3216 IrInstSrc base;
3217
3218 ZigValue *value;
3219};
3220
3221struct IrInstGenConst {
3222 IrInstGen base;
3223};
3224
3225struct IrInstSrcReturn {
3226 IrInstSrc base;
3227
3228 IrInstSrc *operand;
2994};3229};
29953230
2996// When an IrExecutable is not in a function, a return instruction means that3231// When an IrExecutable is not in a function, a return instruction means that
2997// the expression returns with that value, even though a return statement from3232// the expression returns with that value, even though a return statement from
2998// an AST perspective is invalid.3233// an AST perspective is invalid.
2999struct IrInstructionReturn {3234struct IrInstGenReturn {
3000 IrInstruction base;3235 IrInstGen base;
30013236
3002 IrInstruction *operand;3237 IrInstGen *operand;
3003};3238};
30043239
3005enum CastOp {3240enum CastOp {
...@@ -3014,89 +3249,92 @@ enum CastOp {...@@ -3014,89 +3249,92 @@ enum CastOp {
3014};3249};
30153250
3016// TODO get rid of this instruction, replace with instructions for each op code3251// TODO get rid of this instruction, replace with instructions for each op code
3017struct IrInstructionCast {3252struct IrInstGenCast {
3018 IrInstruction base;3253 IrInstGen base;
30193254
3020 IrInstruction *value;3255 IrInstGen *value;
3021 ZigType *dest_type;
3022 CastOp cast_op;3256 CastOp cast_op;
3023};3257};
30243258
3025struct IrInstructionResizeSlice {3259struct IrInstGenResizeSlice {
3026 IrInstruction base;3260 IrInstGen base;
30273261
3028 IrInstruction *operand;3262 IrInstGen *operand;
3029 IrInstruction *result_loc;3263 IrInstGen *result_loc;
3030};3264};
30313265
3032struct IrInstructionContainerInitList {3266struct IrInstSrcContainerInitList {
3033 IrInstruction base;3267 IrInstSrc base;
30343268
3035 IrInstruction *elem_type;3269 IrInstSrc *elem_type;
3036 size_t item_count;3270 size_t item_count;
3037 IrInstruction **elem_result_loc_list;3271 IrInstSrc **elem_result_loc_list;
3038 IrInstruction *result_loc;3272 IrInstSrc *result_loc;
3039 AstNode *init_array_type_source_node;3273 AstNode *init_array_type_source_node;
3040};3274};
30413275
3042struct IrInstructionContainerInitFieldsField {3276struct IrInstSrcContainerInitFieldsField {
3043 Buf *name;3277 Buf *name;
3044 AstNode *source_node;3278 AstNode *source_node;
3045 TypeStructField *type_struct_field;3279 TypeStructField *type_struct_field;
3046 IrInstruction *result_loc;3280 IrInstSrc *result_loc;
3047};3281};
30483282
3049struct IrInstructionContainerInitFields {3283struct IrInstSrcContainerInitFields {
3050 IrInstruction base;3284 IrInstSrc base;
30513285
3052 size_t field_count;3286 size_t field_count;
3053 IrInstructionContainerInitFieldsField *fields;3287 IrInstSrcContainerInitFieldsField *fields;
3054 IrInstruction *result_loc;3288 IrInstSrc *result_loc;
3289};
3290
3291struct IrInstSrcUnreachable {
3292 IrInstSrc base;
3055};3293};
30563294
3057struct IrInstructionUnreachable {3295struct IrInstGenUnreachable {
3058 IrInstruction base;3296 IrInstGen base;
3059};3297};
30603298
3061struct IrInstructionTypeOf {3299struct IrInstSrcTypeOf {
3062 IrInstruction base;3300 IrInstSrc base;
30633301
3064 IrInstruction *value;3302 IrInstSrc *value;
3065};3303};
30663304
3067struct IrInstructionSetCold {3305struct IrInstSrcSetCold {
3068 IrInstruction base;3306 IrInstSrc base;
30693307
3070 IrInstruction *is_cold;3308 IrInstSrc *is_cold;
3071};3309};
30723310
3073struct IrInstructionSetRuntimeSafety {3311struct IrInstSrcSetRuntimeSafety {
3074 IrInstruction base;3312 IrInstSrc base;
30753313
3076 IrInstruction *safety_on;3314 IrInstSrc *safety_on;
3077};3315};
30783316
3079struct IrInstructionSetFloatMode {3317struct IrInstSrcSetFloatMode {
3080 IrInstruction base;3318 IrInstSrc base;
30813319
3082 IrInstruction *scope_value;3320 IrInstSrc *scope_value;
3083 IrInstruction *mode_value;3321 IrInstSrc *mode_value;
3084};3322};
30853323
3086struct IrInstructionArrayType {3324struct IrInstSrcArrayType {
3087 IrInstruction base;3325 IrInstSrc base;
30883326
3089 IrInstruction *size;3327 IrInstSrc *size;
3090 IrInstruction *sentinel;3328 IrInstSrc *sentinel;
3091 IrInstruction *child_type;3329 IrInstSrc *child_type;
3092};3330};
30933331
3094struct IrInstructionPtrType {3332struct IrInstSrcPtrType {
3095 IrInstruction base;3333 IrInstSrc base;
30963334
3097 IrInstruction *sentinel;3335 IrInstSrc *sentinel;
3098 IrInstruction *align_value;3336 IrInstSrc *align_value;
3099 IrInstruction *child_type;3337 IrInstSrc *child_type;
3100 uint32_t bit_offset_start;3338 uint32_t bit_offset_start;
3101 uint32_t host_int_bytes;3339 uint32_t host_int_bytes;
3102 PtrLen ptr_len;3340 PtrLen ptr_len;
...@@ -3105,375 +3343,459 @@ struct IrInstructionPtrType {...@@ -3105,375 +3343,459 @@ struct IrInstructionPtrType {
3105 bool is_allow_zero;3343 bool is_allow_zero;
3106};3344};
31073345
3108struct IrInstructionAnyFrameType {3346struct IrInstSrcAnyFrameType {
3109 IrInstruction base;3347 IrInstSrc base;
31103348
3111 IrInstruction *payload_type;3349 IrInstSrc *payload_type;
3112};3350};
31133351
3114struct IrInstructionSliceType {3352struct IrInstSrcSliceType {
3115 IrInstruction base;3353 IrInstSrc base;
31163354
3117 IrInstruction *sentinel;3355 IrInstSrc *sentinel;
3118 IrInstruction *align_value;3356 IrInstSrc *align_value;
3119 IrInstruction *child_type;3357 IrInstSrc *child_type;
3120 bool is_const;3358 bool is_const;
3121 bool is_volatile;3359 bool is_volatile;
3122 bool is_allow_zero;3360 bool is_allow_zero;
3123};3361};
31243362
3125struct IrInstructionAsmSrc {3363struct IrInstSrcAsm {
3126 IrInstruction base;3364 IrInstSrc base;
31273365
3128 IrInstruction *asm_template;3366 IrInstSrc *asm_template;
3129 IrInstruction **input_list;3367 IrInstSrc **input_list;
3130 IrInstruction **output_types;3368 IrInstSrc **output_types;
3131 ZigVar **output_vars;3369 ZigVar **output_vars;
3132 size_t return_count;3370 size_t return_count;
3133 bool has_side_effects;3371 bool has_side_effects;
3134 bool is_global;3372 bool is_global;
3135};3373};
31363374
3137struct IrInstructionAsmGen {3375struct IrInstGenAsm {
3138 IrInstruction base;3376 IrInstGen base;
31393377
3140 Buf *asm_template;3378 Buf *asm_template;
3141 AsmToken *token_list;3379 AsmToken *token_list;
3142 size_t token_list_len;3380 size_t token_list_len;
3143 IrInstruction **input_list;3381 IrInstGen **input_list;
3144 IrInstruction **output_types;3382 IrInstGen **output_types;
3145 ZigVar **output_vars;3383 ZigVar **output_vars;
3146 size_t return_count;3384 size_t return_count;
3147 bool has_side_effects;3385 bool has_side_effects;
3148};3386};
31493387
3150struct IrInstructionSizeOf {3388struct IrInstSrcSizeOf {
3151 IrInstruction base;3389 IrInstSrc base;
31523390
3391 IrInstSrc *type_value;
3153 bool bit_size;3392 bool bit_size;
3154 IrInstruction *type_value;
3155};3393};
31563394
3157// returns true if nonnull, returns false if null3395// returns true if nonnull, returns false if null
3158// this is so that `zeroes` sets maybe values to null3396struct IrInstSrcTestNonNull {
3159struct IrInstructionTestNonNull {3397 IrInstSrc base;
3160 IrInstruction base;3398
3399 IrInstSrc *value;
3400};
3401
3402struct IrInstGenTestNonNull {
3403 IrInstGen base;
31613404
3162 IrInstruction *value;3405 IrInstGen *value;
3163};3406};
31643407
3165// Takes a pointer to an optional value, returns a pointer3408// Takes a pointer to an optional value, returns a pointer
3166// to the payload.3409// to the payload.
3167struct IrInstructionOptionalUnwrapPtr {3410struct IrInstSrcOptionalUnwrapPtr {
3168 IrInstruction base;3411 IrInstSrc base;
31693412
3413 IrInstSrc *base_ptr;
3170 bool safety_check_on;3414 bool safety_check_on;
3171 bool initializing;3415 bool initializing;
3172 IrInstruction *base_ptr;
3173};3416};
31743417
3175struct IrInstructionCtz {3418struct IrInstGenOptionalUnwrapPtr {
3176 IrInstruction base;3419 IrInstGen base;
31773420
3178 IrInstruction *type;3421 IrInstGen *base_ptr;
3179 IrInstruction *op;3422 bool safety_check_on;
3423 bool initializing;
3424};
3425
3426struct IrInstSrcCtz {
3427 IrInstSrc base;
3428
3429 IrInstSrc *type;
3430 IrInstSrc *op;
3180};3431};
31813432
3182struct IrInstructionClz {3433struct IrInstGenCtz {
3183 IrInstruction base;3434 IrInstGen base;
31843435
3185 IrInstruction *type;3436 IrInstGen *op;
3186 IrInstruction *op;
3187};3437};
31883438
3189struct IrInstructionPopCount {3439struct IrInstSrcClz {
3190 IrInstruction base;3440 IrInstSrc base;
31913441
3192 IrInstruction *type;3442 IrInstSrc *type;
3193 IrInstruction *op;3443 IrInstSrc *op;
3194};3444};
31953445
3196struct IrInstructionUnionTag {3446struct IrInstGenClz {
3197 IrInstruction base;3447 IrInstGen base;
31983448
3199 IrInstruction *value;3449 IrInstGen *op;
3200};3450};
32013451
3202struct IrInstructionImport {3452struct IrInstSrcPopCount {
3203 IrInstruction base;3453 IrInstSrc base;
32043454
3205 IrInstruction *name;3455 IrInstSrc *type;
3456 IrInstSrc *op;
3206};3457};
32073458
3208struct IrInstructionRef {3459struct IrInstGenPopCount {
3209 IrInstruction base;3460 IrInstGen base;
32103461
3211 IrInstruction *value;3462 IrInstGen *op;
3463};
3464
3465struct IrInstGenUnionTag {
3466 IrInstGen base;
3467
3468 IrInstGen *value;
3469};
3470
3471struct IrInstSrcImport {
3472 IrInstSrc base;
3473
3474 IrInstSrc *name;
3475};
3476
3477struct IrInstSrcRef {
3478 IrInstSrc base;
3479
3480 IrInstSrc *value;
3212 bool is_const;3481 bool is_const;
3213 bool is_volatile;3482 bool is_volatile;
3214};3483};
32153484
3216struct IrInstructionRefGen {3485struct IrInstGenRef {
3217 IrInstruction base;3486 IrInstGen base;
32183487
3219 IrInstruction *operand;3488 IrInstGen *operand;
3220 IrInstruction *result_loc;3489 IrInstGen *result_loc;
3221};3490};
32223491
3223struct IrInstructionCompileErr {3492struct IrInstSrcCompileErr {
3224 IrInstruction base;3493 IrInstSrc base;
32253494
3226 IrInstruction *msg;3495 IrInstSrc *msg;
3227};3496};
32283497
3229struct IrInstructionCompileLog {3498struct IrInstSrcCompileLog {
3230 IrInstruction base;3499 IrInstSrc base;
32313500
3232 size_t msg_count;3501 size_t msg_count;
3233 IrInstruction **msg_list;3502 IrInstSrc **msg_list;
3503};
3504
3505struct IrInstSrcErrName {
3506 IrInstSrc base;
3507
3508 IrInstSrc *value;
3234};3509};
32353510
3236struct IrInstructionErrName {3511struct IrInstGenErrName {
3237 IrInstruction base;3512 IrInstGen base;
32383513
3239 IrInstruction *value;3514 IrInstGen *value;
3240};3515};
32413516
3242struct IrInstructionCImport {3517struct IrInstSrcCImport {
3243 IrInstruction base;3518 IrInstSrc base;
3244};3519};
32453520
3246struct IrInstructionCInclude {3521struct IrInstSrcCInclude {
3247 IrInstruction base;3522 IrInstSrc base;
32483523
3249 IrInstruction *name;3524 IrInstSrc *name;
3250};3525};
32513526
3252struct IrInstructionCDefine {3527struct IrInstSrcCDefine {
3253 IrInstruction base;3528 IrInstSrc base;
32543529
3255 IrInstruction *name;3530 IrInstSrc *name;
3256 IrInstruction *value;3531 IrInstSrc *value;
3257};3532};
32583533
3259struct IrInstructionCUndef {3534struct IrInstSrcCUndef {
3260 IrInstruction base;3535 IrInstSrc base;
32613536
3262 IrInstruction *name;3537 IrInstSrc *name;
3263};3538};
32643539
3265struct IrInstructionEmbedFile {3540struct IrInstSrcEmbedFile {
3266 IrInstruction base;3541 IrInstSrc base;
32673542
3268 IrInstruction *name;3543 IrInstSrc *name;
3269};3544};
32703545
3271struct IrInstructionCmpxchgSrc {3546struct IrInstSrcCmpxchg {
3272 IrInstruction base;3547 IrInstSrc base;
32733548
3274 bool is_weak;3549 bool is_weak;
3275 IrInstruction *type_value;3550 IrInstSrc *type_value;
3276 IrInstruction *ptr;3551 IrInstSrc *ptr;
3277 IrInstruction *cmp_value;3552 IrInstSrc *cmp_value;
3278 IrInstruction *new_value;3553 IrInstSrc *new_value;
3279 IrInstruction *success_order_value;3554 IrInstSrc *success_order_value;
3280 IrInstruction *failure_order_value;3555 IrInstSrc *failure_order_value;
3281 ResultLoc *result_loc;3556 ResultLoc *result_loc;
3282};3557};
32833558
3284struct IrInstructionCmpxchgGen {3559struct IrInstGenCmpxchg {
3285 IrInstruction base;3560 IrInstGen base;
32863561
3287 bool is_weak;
3288 AtomicOrder success_order;3562 AtomicOrder success_order;
3289 AtomicOrder failure_order;3563 AtomicOrder failure_order;
3290 IrInstruction *ptr;3564 IrInstGen *ptr;
3291 IrInstruction *cmp_value;3565 IrInstGen *cmp_value;
3292 IrInstruction *new_value;3566 IrInstGen *new_value;
3293 IrInstruction *result_loc;3567 IrInstGen *result_loc;
3568 bool is_weak;
3294};3569};
32953570
3296struct IrInstructionFence {3571struct IrInstSrcFence {
3297 IrInstruction base;3572 IrInstSrc base;
3573
3574 IrInstSrc *order;
3575};
32983576
3299 IrInstruction *order_value;3577struct IrInstGenFence {
3578 IrInstGen base;
33003579
3301 // if this instruction gets to runtime then we know these values:
3302 AtomicOrder order;3580 AtomicOrder order;
3303};3581};
33043582
3305struct IrInstructionTruncate {3583struct IrInstSrcTruncate {
3306 IrInstruction base;3584 IrInstSrc base;
33073585
3308 IrInstruction *dest_type;3586 IrInstSrc *dest_type;
3309 IrInstruction *target;3587 IrInstSrc *target;
3310};3588};
33113589
3312struct IrInstructionIntCast {3590struct IrInstGenTruncate {
3313 IrInstruction base;3591 IrInstGen base;
33143592
3315 IrInstruction *dest_type;3593 IrInstGen *target;
3316 IrInstruction *target;
3317};3594};
33183595
3319struct IrInstructionFloatCast {3596struct IrInstSrcIntCast {
3320 IrInstruction base;3597 IrInstSrc base;
33213598
3322 IrInstruction *dest_type;3599 IrInstSrc *dest_type;
3323 IrInstruction *target;3600 IrInstSrc *target;
3324};3601};
33253602
3326struct IrInstructionErrSetCast {3603struct IrInstSrcFloatCast {
3327 IrInstruction base;3604 IrInstSrc base;
33283605
3329 IrInstruction *dest_type;3606 IrInstSrc *dest_type;
3330 IrInstruction *target;3607 IrInstSrc *target;
3331};3608};
33323609
3333struct IrInstructionToBytes {3610struct IrInstSrcErrSetCast {
3334 IrInstruction base;3611 IrInstSrc base;
33353612
3336 IrInstruction *target;3613 IrInstSrc *dest_type;
3614 IrInstSrc *target;
3615};
3616
3617struct IrInstSrcToBytes {
3618 IrInstSrc base;
3619
3620 IrInstSrc *target;
3337 ResultLoc *result_loc;3621 ResultLoc *result_loc;
3338};3622};
33393623
3340struct IrInstructionFromBytes {3624struct IrInstSrcFromBytes {
3341 IrInstruction base;3625 IrInstSrc base;
33423626
3343 IrInstruction *dest_child_type;3627 IrInstSrc *dest_child_type;
3344 IrInstruction *target;3628 IrInstSrc *target;
3345 ResultLoc *result_loc;3629 ResultLoc *result_loc;
3346};3630};
33473631
3348struct IrInstructionIntToFloat {3632struct IrInstSrcIntToFloat {
3349 IrInstruction base;3633 IrInstSrc base;
33503634
3351 IrInstruction *dest_type;3635 IrInstSrc *dest_type;
3352 IrInstruction *target;3636 IrInstSrc *target;
3353};3637};
33543638
3355struct IrInstructionFloatToInt {3639struct IrInstSrcFloatToInt {
3356 IrInstruction base;3640 IrInstSrc base;
33573641
3358 IrInstruction *dest_type;3642 IrInstSrc *dest_type;
3359 IrInstruction *target;3643 IrInstSrc *target;
3360};3644};
33613645
3362struct IrInstructionBoolToInt {3646struct IrInstSrcBoolToInt {
3363 IrInstruction base;3647 IrInstSrc base;
33643648
3365 IrInstruction *target;3649 IrInstSrc *target;
3366};3650};
33673651
3368struct IrInstructionIntType {3652struct IrInstSrcIntType {
3369 IrInstruction base;3653 IrInstSrc base;
33703654
3371 IrInstruction *is_signed;3655 IrInstSrc *is_signed;
3372 IrInstruction *bit_count;3656 IrInstSrc *bit_count;
3373};3657};
33743658
3375struct IrInstructionVectorType {3659struct IrInstSrcVectorType {
3376 IrInstruction base;3660 IrInstSrc base;
33773661
3378 IrInstruction *len;3662 IrInstSrc *len;
3379 IrInstruction *elem_type;3663 IrInstSrc *elem_type;
3380};3664};
33813665
3382struct IrInstructionBoolNot {3666struct IrInstSrcBoolNot {
3383 IrInstruction base;3667 IrInstSrc base;
33843668
3385 IrInstruction *value;3669 IrInstSrc *value;
3386};3670};
33873671
3388struct IrInstructionMemset {3672struct IrInstGenBoolNot {
3389 IrInstruction base;3673 IrInstGen base;
33903674
3391 IrInstruction *dest_ptr;3675 IrInstGen *value;
3392 IrInstruction *byte;
3393 IrInstruction *count;
3394};3676};
33953677
3396struct IrInstructionMemcpy {3678struct IrInstSrcMemset {
3397 IrInstruction base;3679 IrInstSrc base;
33983680
3399 IrInstruction *dest_ptr;3681 IrInstSrc *dest_ptr;
3400 IrInstruction *src_ptr;3682 IrInstSrc *byte;
3401 IrInstruction *count;3683 IrInstSrc *count;
3402};3684};
34033685
3404struct IrInstructionSliceSrc {3686struct IrInstGenMemset {
3405 IrInstruction base;3687 IrInstGen base;
34063688
3407 bool safety_check_on;3689 IrInstGen *dest_ptr;
3408 IrInstruction *ptr;3690 IrInstGen *byte;
3409 IrInstruction *start;3691 IrInstGen *count;
3410 IrInstruction *end;3692};
3411 IrInstruction *sentinel;3693
3694struct IrInstSrcMemcpy {
3695 IrInstSrc base;
3696
3697 IrInstSrc *dest_ptr;
3698 IrInstSrc *src_ptr;
3699 IrInstSrc *count;
3700};
3701
3702struct IrInstGenMemcpy {
3703 IrInstGen base;
3704
3705 IrInstGen *dest_ptr;
3706 IrInstGen *src_ptr;
3707 IrInstGen *count;
3708};
3709
3710struct IrInstSrcSlice {
3711 IrInstSrc base;
3712
3713 IrInstSrc *ptr;
3714 IrInstSrc *start;
3715 IrInstSrc *end;
3716 IrInstSrc *sentinel;
3412 ResultLoc *result_loc;3717 ResultLoc *result_loc;
3718 bool safety_check_on;
3413};3719};
34143720
3415struct IrInstructionSliceGen {3721struct IrInstGenSlice {
3416 IrInstruction base;3722 IrInstGen base;
34173723
3724 IrInstGen *ptr;
3725 IrInstGen *start;
3726 IrInstGen *end;
3727 IrInstGen *result_loc;
3418 bool safety_check_on;3728 bool safety_check_on;
3419 IrInstruction *ptr;
3420 IrInstruction *start;
3421 IrInstruction *end;
3422 IrInstruction *result_loc;
3423};3729};
34243730
3425struct IrInstructionMemberCount {3731struct IrInstSrcMemberCount {
3426 IrInstruction base;3732 IrInstSrc base;
3733
3734 IrInstSrc *container;
3735};
3736
3737struct IrInstSrcMemberType {
3738 IrInstSrc base;
3739
3740 IrInstSrc *container_type;
3741 IrInstSrc *member_index;
3742};
3743
3744struct IrInstSrcMemberName {
3745 IrInstSrc base;
34273746
3428 IrInstruction *container;3747 IrInstSrc *container_type;
3748 IrInstSrc *member_index;
3429};3749};
34303750
3431struct IrInstructionMemberType {3751struct IrInstSrcBreakpoint {
3432 IrInstruction base;3752 IrInstSrc base;
3753};
34333754
3434 IrInstruction *container_type;3755struct IrInstGenBreakpoint {
3435 IrInstruction *member_index;3756 IrInstGen base;
3436};3757};
34373758
3438struct IrInstructionMemberName {3759struct IrInstSrcReturnAddress {
3439 IrInstruction base;3760 IrInstSrc base;
3761};
34403762
3441 IrInstruction *container_type;3763struct IrInstGenReturnAddress {
3442 IrInstruction *member_index;3764 IrInstGen base;
3443};3765};
34443766
3445struct IrInstructionBreakpoint {3767struct IrInstSrcFrameAddress {
3446 IrInstruction base;3768 IrInstSrc base;
3447};3769};
34483770
3449struct IrInstructionReturnAddress {3771struct IrInstGenFrameAddress {
3450 IrInstruction base;3772 IrInstGen base;
3451};3773};
34523774
3453struct IrInstructionFrameAddress {3775struct IrInstSrcFrameHandle {
3454 IrInstruction base;3776 IrInstSrc base;
3455};3777};
34563778
3457struct IrInstructionFrameHandle {3779struct IrInstGenFrameHandle {
3458 IrInstruction base;3780 IrInstGen base;
3459};3781};
34603782
3461struct IrInstructionFrameType {3783struct IrInstSrcFrameType {
3462 IrInstruction base;3784 IrInstSrc base;
34633785
3464 IrInstruction *fn;3786 IrInstSrc *fn;
3465};3787};
34663788
3467struct IrInstructionFrameSizeSrc {3789struct IrInstSrcFrameSize {
3468 IrInstruction base;3790 IrInstSrc base;
34693791
3470 IrInstruction *fn;3792 IrInstSrc *fn;
3471};3793};
34723794
3473struct IrInstructionFrameSizeGen {3795struct IrInstGenFrameSize {
3474 IrInstruction base;3796 IrInstGen base;
34753797
3476 IrInstruction *fn;3798 IrInstGen *fn;
3477};3799};
34783800
3479enum IrOverflowOp {3801enum IrOverflowOp {
...@@ -3483,560 +3805,713 @@ enum IrOverflowOp {...@@ -3483,560 +3805,713 @@ enum IrOverflowOp {
3483 IrOverflowOpShl,3805 IrOverflowOpShl,
3484};3806};
34853807
3486struct IrInstructionOverflowOp {3808struct IrInstSrcOverflowOp {
3487 IrInstruction base;3809 IrInstSrc base;
3810
3811 IrOverflowOp op;
3812 IrInstSrc *type_value;
3813 IrInstSrc *op1;
3814 IrInstSrc *op2;
3815 IrInstSrc *result_ptr;
3816};
3817
3818struct IrInstGenOverflowOp {
3819 IrInstGen base;
34883820
3489 IrOverflowOp op;3821 IrOverflowOp op;
3490 IrInstruction *type_value;3822 IrInstGen *op1;
3491 IrInstruction *op1;3823 IrInstGen *op2;
3492 IrInstruction *op2;3824 IrInstGen *result_ptr;
3493 IrInstruction *result_ptr;
34943825
3826 // TODO can this field be removed?
3495 ZigType *result_ptr_type;3827 ZigType *result_ptr_type;
3496};3828};
34973829
3498struct IrInstructionMulAdd {3830struct IrInstSrcMulAdd {
3499 IrInstruction base;3831 IrInstSrc base;
3832
3833 IrInstSrc *type_value;
3834 IrInstSrc *op1;
3835 IrInstSrc *op2;
3836 IrInstSrc *op3;
3837};
3838
3839struct IrInstGenMulAdd {
3840 IrInstGen base;
35003841
3501 IrInstruction *type_value;3842 IrInstGen *op1;
3502 IrInstruction *op1;3843 IrInstGen *op2;
3503 IrInstruction *op2;3844 IrInstGen *op3;
3504 IrInstruction *op3;
3505};3845};
35063846
3507struct IrInstructionAlignOf {3847struct IrInstSrcAlignOf {
3508 IrInstruction base;3848 IrInstSrc base;
35093849
3510 IrInstruction *type_value;3850 IrInstSrc *type_value;
3511};3851};
35123852
3513// returns true if error, returns false if not error3853// returns true if error, returns false if not error
3514struct IrInstructionTestErrSrc {3854struct IrInstSrcTestErr {
3515 IrInstruction base;3855 IrInstSrc base;
35163856
3857 IrInstSrc *base_ptr;
3517 bool resolve_err_set;3858 bool resolve_err_set;
3518 bool base_ptr_is_payload;3859 bool base_ptr_is_payload;
3519 IrInstruction *base_ptr;
3520};3860};
35213861
3522struct IrInstructionTestErrGen {3862struct IrInstGenTestErr {
3523 IrInstruction base;3863 IrInstGen base;
35243864
3525 IrInstruction *err_union;3865 IrInstGen *err_union;
3526};3866};
35273867
3528// Takes an error union pointer, returns a pointer to the error code.3868// Takes an error union pointer, returns a pointer to the error code.
3529struct IrInstructionUnwrapErrCode {3869struct IrInstSrcUnwrapErrCode {
3530 IrInstruction base;3870 IrInstSrc base;
3871
3872 IrInstSrc *err_union_ptr;
3873 bool initializing;
3874};
3875
3876struct IrInstGenUnwrapErrCode {
3877 IrInstGen base;
3878
3879 IrInstGen *err_union_ptr;
3880 bool initializing;
3881};
35313882
3883struct IrInstSrcUnwrapErrPayload {
3884 IrInstSrc base;
3885
3886 IrInstSrc *value;
3887 bool safety_check_on;
3532 bool initializing;3888 bool initializing;
3533 IrInstruction *err_union_ptr;
3534};3889};
35353890
3536struct IrInstructionUnwrapErrPayload {3891struct IrInstGenUnwrapErrPayload {
3537 IrInstruction base;3892 IrInstGen base;
35383893
3894 IrInstGen *value;
3539 bool safety_check_on;3895 bool safety_check_on;
3540 bool initializing;3896 bool initializing;
3541 IrInstruction *value;
3542};3897};
35433898
3544struct IrInstructionOptionalWrap {3899struct IrInstGenOptionalWrap {
3545 IrInstruction base;3900 IrInstGen base;
35463901
3547 IrInstruction *operand;3902 IrInstGen *operand;
3548 IrInstruction *result_loc;3903 IrInstGen *result_loc;
3549};3904};
35503905
3551struct IrInstructionErrWrapPayload {3906struct IrInstGenErrWrapPayload {
3552 IrInstruction base;3907 IrInstGen base;
35533908
3554 IrInstruction *operand;3909 IrInstGen *operand;
3555 IrInstruction *result_loc;3910 IrInstGen *result_loc;
3556};3911};
35573912
3558struct IrInstructionErrWrapCode {3913struct IrInstGenErrWrapCode {
3559 IrInstruction base;3914 IrInstGen base;
35603915
3561 IrInstruction *operand;3916 IrInstGen *operand;
3562 IrInstruction *result_loc;3917 IrInstGen *result_loc;
3563};3918};
35643919
3565struct IrInstructionFnProto {3920struct IrInstSrcFnProto {
3566 IrInstruction base;3921 IrInstSrc base;
35673922
3568 IrInstruction **param_types;3923 IrInstSrc **param_types;
3569 IrInstruction *align_value;3924 IrInstSrc *align_value;
3570 IrInstruction *callconv_value;3925 IrInstSrc *callconv_value;
3571 IrInstruction *return_type;3926 IrInstSrc *return_type;
3572 bool is_var_args;3927 bool is_var_args;
3573};3928};
35743929
3575// true if the target value is compile time known, false otherwise3930// true if the target value is compile time known, false otherwise
3576struct IrInstructionTestComptime {3931struct IrInstSrcTestComptime {
3577 IrInstruction base;3932 IrInstSrc base;
35783933
3579 IrInstruction *value;3934 IrInstSrc *value;
3580};3935};
35813936
3582struct IrInstructionPtrCastSrc {3937struct IrInstSrcPtrCast {
3583 IrInstruction base;3938 IrInstSrc base;
35843939
3585 IrInstruction *dest_type;3940 IrInstSrc *dest_type;
3586 IrInstruction *ptr;3941 IrInstSrc *ptr;
3587 bool safety_check_on;3942 bool safety_check_on;
3588};3943};
35893944
3590struct IrInstructionPtrCastGen {3945struct IrInstGenPtrCast {
3591 IrInstruction base;3946 IrInstGen base;
35923947
3593 IrInstruction *ptr;3948 IrInstGen *ptr;
3594 bool safety_check_on;3949 bool safety_check_on;
3595};3950};
35963951
3597struct IrInstructionImplicitCast {3952struct IrInstSrcImplicitCast {
3598 IrInstruction base;3953 IrInstSrc base;
35993954
3600 IrInstruction *operand;3955 IrInstSrc *operand;
3601 ResultLocCast *result_loc_cast;3956 ResultLocCast *result_loc_cast;
3602};3957};
36033958
3604struct IrInstructionBitCastSrc {3959struct IrInstSrcBitCast {
3605 IrInstruction base;3960 IrInstSrc base;
36063961
3607 IrInstruction *operand;3962 IrInstSrc *operand;
3608 ResultLocBitCast *result_loc_bit_cast;3963 ResultLocBitCast *result_loc_bit_cast;
3609};3964};
36103965
3611struct IrInstructionBitCastGen {3966struct IrInstGenBitCast {
3612 IrInstruction base;3967 IrInstGen base;
3968
3969 IrInstGen *operand;
3970};
3971
3972struct IrInstGenWidenOrShorten {
3973 IrInstGen base;
3974
3975 IrInstGen *target;
3976};
3977
3978struct IrInstSrcPtrToInt {
3979 IrInstSrc base;
36133980
3614 IrInstruction *operand;3981 IrInstSrc *target;
3615};3982};
36163983
3617struct IrInstructionWidenOrShorten {3984struct IrInstGenPtrToInt {
3618 IrInstruction base;3985 IrInstGen base;
36193986
3620 IrInstruction *target;3987 IrInstGen *target;
3621};3988};
36223989
3623struct IrInstructionPtrToInt {3990struct IrInstSrcIntToPtr {
3624 IrInstruction base;3991 IrInstSrc base;
36253992
3626 IrInstruction *target;3993 IrInstSrc *dest_type;
3994 IrInstSrc *target;
3627};3995};
36283996
3629struct IrInstructionIntToPtr {3997struct IrInstGenIntToPtr {
3630 IrInstruction base;3998 IrInstGen base;
36313999
3632 IrInstruction *dest_type;4000 IrInstGen *target;
3633 IrInstruction *target;
3634};4001};
36354002
3636struct IrInstructionIntToEnum {4003struct IrInstSrcIntToEnum {
3637 IrInstruction base;4004 IrInstSrc base;
36384005
3639 IrInstruction *dest_type;4006 IrInstSrc *dest_type;
3640 IrInstruction *target;4007 IrInstSrc *target;
3641};4008};
36424009
3643struct IrInstructionEnumToInt {4010struct IrInstGenIntToEnum {
3644 IrInstruction base;4011 IrInstGen base;
36454012
3646 IrInstruction *target;4013 IrInstGen *target;
3647};4014};
36484015
3649struct IrInstructionIntToErr {4016struct IrInstSrcEnumToInt {
3650 IrInstruction base;4017 IrInstSrc base;
36514018
3652 IrInstruction *target;4019 IrInstSrc *target;
3653};4020};
36544021
3655struct IrInstructionErrToInt {4022struct IrInstSrcIntToErr {
3656 IrInstruction base;4023 IrInstSrc base;
36574024
3658 IrInstruction *target;4025 IrInstSrc *target;
3659};4026};
36604027
3661struct IrInstructionCheckSwitchProngsRange {4028struct IrInstGenIntToErr {
3662 IrInstruction *start;4029 IrInstGen base;
3663 IrInstruction *end;4030
4031 IrInstGen *target;
4032};
4033
4034struct IrInstSrcErrToInt {
4035 IrInstSrc base;
4036
4037 IrInstSrc *target;
4038};
4039
4040struct IrInstGenErrToInt {
4041 IrInstGen base;
4042
4043 IrInstGen *target;
4044};
4045
4046struct IrInstSrcCheckSwitchProngsRange {
4047 IrInstSrc *start;
4048 IrInstSrc *end;
3664};4049};
36654050
3666struct IrInstructionCheckSwitchProngs {4051struct IrInstSrcCheckSwitchProngs {
3667 IrInstruction base;4052 IrInstSrc base;
36684053
3669 IrInstruction *target_value;4054 IrInstSrc *target_value;
3670 IrInstructionCheckSwitchProngsRange *ranges;4055 IrInstSrcCheckSwitchProngsRange *ranges;
3671 size_t range_count;4056 size_t range_count;
3672 bool have_else_prong;4057 bool have_else_prong;
3673 bool have_underscore_prong;4058 bool have_underscore_prong;
3674};4059};
36754060
3676struct IrInstructionCheckStatementIsVoid {4061struct IrInstSrcCheckStatementIsVoid {
3677 IrInstruction base;4062 IrInstSrc base;
36784063
3679 IrInstruction *statement_value;4064 IrInstSrc *statement_value;
3680};4065};
36814066
3682struct IrInstructionTypeName {4067struct IrInstSrcTypeName {
3683 IrInstruction base;4068 IrInstSrc base;
36844069
3685 IrInstruction *type_value;4070 IrInstSrc *type_value;
3686};4071};
36874072
3688struct IrInstructionDeclRef {4073struct IrInstSrcDeclRef {
3689 IrInstruction base;4074 IrInstSrc base;
36904075
3691 LVal lval;4076 LVal lval;
3692 Tld *tld;4077 Tld *tld;
3693};4078};
36944079
3695struct IrInstructionPanic {4080struct IrInstSrcPanic {
3696 IrInstruction base;4081 IrInstSrc base;
36974082
3698 IrInstruction *msg;4083 IrInstSrc *msg;
3699};4084};
37004085
3701struct IrInstructionTagName {4086struct IrInstGenPanic {
3702 IrInstruction base;4087 IrInstGen base;
37034088
3704 IrInstruction *target;4089 IrInstGen *msg;
3705};4090};
37064091
3707struct IrInstructionTagType {4092struct IrInstSrcTagName {
3708 IrInstruction base;4093 IrInstSrc base;
37094094
3710 IrInstruction *target;4095 IrInstSrc *target;
3711};4096};
37124097
3713struct IrInstructionFieldParentPtr {4098struct IrInstGenTagName {
3714 IrInstruction base;4099 IrInstGen base;
4100
4101 IrInstGen *target;
4102};
4103
4104struct IrInstSrcTagType {
4105 IrInstSrc base;
4106
4107 IrInstSrc *target;
4108};
4109
4110struct IrInstSrcFieldParentPtr {
4111 IrInstSrc base;
4112
4113 IrInstSrc *type_value;
4114 IrInstSrc *field_name;
4115 IrInstSrc *field_ptr;
4116};
37154117
3716 IrInstruction *type_value;4118struct IrInstGenFieldParentPtr {
3717 IrInstruction *field_name;4119 IrInstGen base;
3718 IrInstruction *field_ptr;4120
4121 IrInstGen *field_ptr;
3719 TypeStructField *field;4122 TypeStructField *field;
3720};4123};
37214124
3722struct IrInstructionByteOffsetOf {4125struct IrInstSrcByteOffsetOf {
3723 IrInstruction base;4126 IrInstSrc base;
4127
4128 IrInstSrc *type_value;
4129 IrInstSrc *field_name;
4130};
4131
4132struct IrInstSrcBitOffsetOf {
4133 IrInstSrc base;
37244134
3725 IrInstruction *type_value;4135 IrInstSrc *type_value;
3726 IrInstruction *field_name;4136 IrInstSrc *field_name;
3727};4137};
37284138
3729struct IrInstructionBitOffsetOf {4139struct IrInstSrcTypeInfo {
3730 IrInstruction base;4140 IrInstSrc base;
37314141
3732 IrInstruction *type_value;4142 IrInstSrc *type_value;
3733 IrInstruction *field_name;
3734};4143};
37354144
3736struct IrInstructionTypeInfo {4145struct IrInstSrcType {
3737 IrInstruction base;4146 IrInstSrc base;
37384147
3739 IrInstruction *type_value;4148 IrInstSrc *type_info;
3740};4149};
37414150
3742struct IrInstructionType {4151struct IrInstSrcHasField {
3743 IrInstruction base;4152 IrInstSrc base;
37444153
3745 IrInstruction *type_info;4154 IrInstSrc *container_type;
4155 IrInstSrc *field_name;
3746};4156};
37474157
3748struct IrInstructionHasField {4158struct IrInstSrcTypeId {
3749 IrInstruction base;4159 IrInstSrc base;
37504160
3751 IrInstruction *container_type;4161 IrInstSrc *type_value;
3752 IrInstruction *field_name;
3753};4162};
37544163
3755struct IrInstructionTypeId {4164struct IrInstSrcSetEvalBranchQuota {
3756 IrInstruction base;4165 IrInstSrc base;
37574166
3758 IrInstruction *type_value;4167 IrInstSrc *new_quota;
3759};4168};
37604169
3761struct IrInstructionSetEvalBranchQuota {4170struct IrInstSrcAlignCast {
3762 IrInstruction base;4171 IrInstSrc base;
37634172
3764 IrInstruction *new_quota;4173 IrInstSrc *align_bytes;
4174 IrInstSrc *target;
3765};4175};
37664176
3767struct IrInstructionAlignCast {4177struct IrInstGenAlignCast {
3768 IrInstruction base;4178 IrInstGen base;
37694179
3770 IrInstruction *align_bytes;4180 IrInstGen *target;
3771 IrInstruction *target;
3772};4181};
37734182
3774struct IrInstructionOpaqueType {4183struct IrInstSrcOpaqueType {
3775 IrInstruction base;4184 IrInstSrc base;
3776};4185};
37774186
3778struct IrInstructionSetAlignStack {4187struct IrInstSrcSetAlignStack {
3779 IrInstruction base;4188 IrInstSrc base;
37804189
3781 IrInstruction *align_bytes;4190 IrInstSrc *align_bytes;
3782};4191};
37834192
3784struct IrInstructionArgType {4193struct IrInstSrcArgType {
3785 IrInstruction base;4194 IrInstSrc base;
37864195
3787 IrInstruction *fn_type;4196 IrInstSrc *fn_type;
3788 IrInstruction *arg_index;4197 IrInstSrc *arg_index;
3789 bool allow_var;4198 bool allow_var;
3790};4199};
37914200
3792struct IrInstructionExport {4201struct IrInstSrcExport {
3793 IrInstruction base;4202 IrInstSrc base;
4203
4204 IrInstSrc *target;
4205 IrInstSrc *options;
4206};
4207
4208enum IrInstErrorReturnTraceOptional {
4209 IrInstErrorReturnTraceNull,
4210 IrInstErrorReturnTraceNonNull,
4211};
4212
4213struct IrInstSrcErrorReturnTrace {
4214 IrInstSrc base;
37944215
3795 IrInstruction *target;4216 IrInstErrorReturnTraceOptional optional;
3796 IrInstruction *options;
3797};4217};
37984218
3799struct IrInstructionErrorReturnTrace {4219struct IrInstGenErrorReturnTrace {
3800 IrInstruction base;4220 IrInstGen base;
38014221
3802 enum Optional {4222 IrInstErrorReturnTraceOptional optional;
3803 Null,
3804 NonNull,
3805 } optional;
3806};4223};
38074224
3808struct IrInstructionErrorUnion {4225struct IrInstSrcErrorUnion {
3809 IrInstruction base;4226 IrInstSrc base;
38104227
3811 IrInstruction *err_set;4228 IrInstSrc *err_set;
3812 IrInstruction *payload;4229 IrInstSrc *payload;
3813 Buf *type_name;4230 Buf *type_name;
3814};4231};
38154232
3816struct IrInstructionAtomicRmw {4233struct IrInstSrcAtomicRmw {
3817 IrInstruction base;4234 IrInstSrc base;
4235
4236 IrInstSrc *operand_type;
4237 IrInstSrc *ptr;
4238 IrInstSrc *op;
4239 IrInstSrc *operand;
4240 IrInstSrc *ordering;
4241};
4242
4243struct IrInstGenAtomicRmw {
4244 IrInstGen base;
38184245
3819 IrInstruction *operand_type;4246 IrInstGen *ptr;
3820 IrInstruction *ptr;4247 IrInstGen *operand;
3821 IrInstruction *op;4248 AtomicRmwOp op;
3822 AtomicRmwOp resolved_op;4249 AtomicOrder ordering;
3823 IrInstruction *operand;
3824 IrInstruction *ordering;
3825 AtomicOrder resolved_ordering;
3826};4250};
38274251
3828struct IrInstructionAtomicLoad {4252struct IrInstSrcAtomicLoad {
3829 IrInstruction base;4253 IrInstSrc base;
38304254
3831 IrInstruction *operand_type;4255 IrInstSrc *operand_type;
3832 IrInstruction *ptr;4256 IrInstSrc *ptr;
3833 IrInstruction *ordering;4257 IrInstSrc *ordering;
3834 AtomicOrder resolved_ordering;
3835};4258};
38364259
3837struct IrInstructionAtomicStore {4260struct IrInstGenAtomicLoad {
3838 IrInstruction base;4261 IrInstGen base;
38394262
3840 IrInstruction *operand_type;4263 IrInstGen *ptr;
3841 IrInstruction *ptr;4264 AtomicOrder ordering;
3842 IrInstruction *value;
3843 IrInstruction *ordering;
3844 AtomicOrder resolved_ordering;
3845};4265};
38464266
3847struct IrInstructionSaveErrRetAddr {4267struct IrInstSrcAtomicStore {
3848 IrInstruction base;4268 IrInstSrc base;
4269
4270 IrInstSrc *operand_type;
4271 IrInstSrc *ptr;
4272 IrInstSrc *value;
4273 IrInstSrc *ordering;
3849};4274};
38504275
3851struct IrInstructionAddImplicitReturnType {4276struct IrInstGenAtomicStore {
3852 IrInstruction base;4277 IrInstGen base;
4278
4279 IrInstGen *ptr;
4280 IrInstGen *value;
4281 AtomicOrder ordering;
4282};
38534283
3854 IrInstruction *value;4284struct IrInstSrcSaveErrRetAddr {
4285 IrInstSrc base;
4286};
4287
4288struct IrInstGenSaveErrRetAddr {
4289 IrInstGen base;
4290};
4291
4292struct IrInstSrcAddImplicitReturnType {
4293 IrInstSrc base;
4294
4295 IrInstSrc *value;
3855 ResultLocReturn *result_loc_ret;4296 ResultLocReturn *result_loc_ret;
3856};4297};
38574298
3858// For float ops which take a single argument4299// For float ops that take a single argument
3859struct IrInstructionFloatOp {4300struct IrInstSrcFloatOp {
3860 IrInstruction base;4301 IrInstSrc base;
4302
4303 IrInstSrc *operand;
4304 BuiltinFnId fn_id;
4305};
4306
4307struct IrInstGenFloatOp {
4308 IrInstGen base;
38614309
4310 IrInstGen *operand;
3862 BuiltinFnId fn_id;4311 BuiltinFnId fn_id;
3863 IrInstruction *operand;
3864};4312};
38654313
3866struct IrInstructionCheckRuntimeScope {4314struct IrInstSrcCheckRuntimeScope {
3867 IrInstruction base;4315 IrInstSrc base;
4316
4317 IrInstSrc *scope_is_comptime;
4318 IrInstSrc *is_comptime;
4319};
4320
4321struct IrInstSrcBswap {
4322 IrInstSrc base;
4323
4324 IrInstSrc *type;
4325 IrInstSrc *op;
4326};
4327
4328struct IrInstGenBswap {
4329 IrInstGen base;
4330
4331 IrInstGen *op;
4332};
4333
4334struct IrInstSrcBitReverse {
4335 IrInstSrc base;
38684336
3869 IrInstruction *scope_is_comptime;4337 IrInstSrc *type;
3870 IrInstruction *is_comptime;4338 IrInstSrc *op;
3871};4339};
38724340
3873struct IrInstructionBswap {4341struct IrInstGenBitReverse {
3874 IrInstruction base;4342 IrInstGen base;
38754343
3876 IrInstruction *type;4344 IrInstGen *op;
3877 IrInstruction *op;
3878};4345};
38794346
3880struct IrInstructionBitReverse {4347struct IrInstGenArrayToVector {
3881 IrInstruction base;4348 IrInstGen base;
38824349
3883 IrInstruction *type;4350 IrInstGen *array;
3884 IrInstruction *op;
3885};4351};
38864352
3887struct IrInstructionArrayToVector {4353struct IrInstGenVectorToArray {
3888 IrInstruction base;4354 IrInstGen base;
38894355
3890 IrInstruction *array;4356 IrInstGen *vector;
4357 IrInstGen *result_loc;
3891};4358};
38924359
3893struct IrInstructionVectorToArray {4360struct IrInstSrcShuffleVector {
3894 IrInstruction base;4361 IrInstSrc base;
38954362
3896 IrInstruction *vector;4363 IrInstSrc *scalar_type;
3897 IrInstruction *result_loc;4364 IrInstSrc *a;
4365 IrInstSrc *b;
4366 IrInstSrc *mask; // This is in zig-format, not llvm format
3898};4367};
38994368
3900struct IrInstructionShuffleVector {4369struct IrInstGenShuffleVector {
3901 IrInstruction base;4370 IrInstGen base;
39024371
3903 IrInstruction *scalar_type;4372 IrInstGen *a;
3904 IrInstruction *a;4373 IrInstGen *b;
3905 IrInstruction *b;4374 IrInstGen *mask; // This is in zig-format, not llvm format
3906 IrInstruction *mask; // This is in zig-format, not llvm format
3907};4375};
39084376
3909struct IrInstructionSplatSrc {4377struct IrInstSrcSplat {
3910 IrInstruction base;4378 IrInstSrc base;
39114379
3912 IrInstruction *len;4380 IrInstSrc *len;
3913 IrInstruction *scalar;4381 IrInstSrc *scalar;
3914};4382};
39154383
3916struct IrInstructionSplatGen {4384struct IrInstGenSplat {
3917 IrInstruction base;4385 IrInstGen base;
39184386
3919 IrInstruction *scalar;4387 IrInstGen *scalar;
3920};4388};
39214389
3922struct IrInstructionAssertZero {4390struct IrInstGenAssertZero {
3923 IrInstruction base;4391 IrInstGen base;
39244392
3925 IrInstruction *target;4393 IrInstGen *target;
3926};4394};
39274395
3928struct IrInstructionAssertNonNull {4396struct IrInstGenAssertNonNull {
3929 IrInstruction base;4397 IrInstGen base;
39304398
3931 IrInstruction *target;4399 IrInstGen *target;
3932};4400};
39334401
3934struct IrInstructionUnionInitNamedField {4402struct IrInstSrcUnionInitNamedField {
3935 IrInstruction base;4403 IrInstSrc base;
39364404
3937 IrInstruction *union_type;4405 IrInstSrc *union_type;
3938 IrInstruction *field_name;4406 IrInstSrc *field_name;
3939 IrInstruction *field_result_loc;4407 IrInstSrc *field_result_loc;
3940 IrInstruction *result_loc;4408 IrInstSrc *result_loc;
3941};4409};
39424410
3943struct IrInstructionHasDecl {4411struct IrInstSrcHasDecl {
3944 IrInstruction base;4412 IrInstSrc base;
39454413
3946 IrInstruction *container;4414 IrInstSrc *container;
3947 IrInstruction *name;4415 IrInstSrc *name;
3948};4416};
39494417
3950struct IrInstructionUndeclaredIdent {4418struct IrInstSrcUndeclaredIdent {
3951 IrInstruction base;4419 IrInstSrc base;
39524420
3953 Buf *name;4421 Buf *name;
3954};4422};
39554423
3956struct IrInstructionAllocaSrc {4424struct IrInstSrcAlloca {
3957 IrInstruction base;4425 IrInstSrc base;
39584426
3959 IrInstruction *align;4427 IrInstSrc *align;
3960 IrInstruction *is_comptime;4428 IrInstSrc *is_comptime;
3961 const char *name_hint;4429 const char *name_hint;
3962};4430};
39634431
3964struct IrInstructionAllocaGen {4432struct IrInstGenAlloca {
3965 IrInstruction base;4433 IrInstGen base;
39664434
3967 uint32_t align;4435 uint32_t align;
3968 const char *name_hint;4436 const char *name_hint;
3969 size_t field_index;4437 size_t field_index;
3970};4438};
39714439
3972struct IrInstructionEndExpr {4440struct IrInstSrcEndExpr {
3973 IrInstruction base;4441 IrInstSrc base;
39744442
3975 IrInstruction *value;4443 IrInstSrc *value;
3976 ResultLoc *result_loc;4444 ResultLoc *result_loc;
3977};4445};
39784446
3979// This one is for writing through the result pointer.4447// This one is for writing through the result pointer.
3980struct IrInstructionResolveResult {4448struct IrInstSrcResolveResult {
3981 IrInstruction base;4449 IrInstSrc base;
39824450
3983 ResultLoc *result_loc;4451 ResultLoc *result_loc;
3984 IrInstruction *ty;4452 IrInstSrc *ty;
3985};4453};
39864454
3987// This one is when you want to read the value of the result.4455struct IrInstSrcResetResult {
3988// You have to give the value in case it is comptime.4456 IrInstSrc base;
3989struct IrInstructionResultPtr {
3990 IrInstruction base;
39914457
3992 ResultLoc *result_loc;4458 ResultLoc *result_loc;
3993 IrInstruction *result;
3994};4459};
39954460
3996struct IrInstructionResetResult {4461struct IrInstGenPtrOfArrayToSlice {
3997 IrInstruction base;4462 IrInstGen base;
39984463
3999 ResultLoc *result_loc;4464 IrInstGen *operand;
4465 IrInstGen *result_loc;
4000};4466};
40014467
4002struct IrInstructionPtrOfArrayToSlice {4468struct IrInstSrcSuspendBegin {
4003 IrInstruction base;4469 IrInstSrc base;
4004
4005 IrInstruction *operand;
4006 IrInstruction *result_loc;
4007};4470};
40084471
4009struct IrInstructionSuspendBegin {4472struct IrInstGenSuspendBegin {
4010 IrInstruction base;4473 IrInstGen base;
40114474
4012 LLVMBasicBlockRef resume_bb;4475 LLVMBasicBlockRef resume_bb;
4013};4476};
40144477
4015struct IrInstructionSuspendFinish {4478struct IrInstSrcSuspendFinish {
4016 IrInstruction base;4479 IrInstSrc base;
4480
4481 IrInstSrcSuspendBegin *begin;
4482};
4483
4484struct IrInstGenSuspendFinish {
4485 IrInstGen base;
40174486
4018 IrInstructionSuspendBegin *begin;4487 IrInstGenSuspendBegin *begin;
4019};4488};
40204489
4021struct IrInstructionAwaitSrc {4490struct IrInstSrcAwait {
4022 IrInstruction base;4491 IrInstSrc base;
40234492
4024 IrInstruction *frame;4493 IrInstSrc *frame;
4025 ResultLoc *result_loc;4494 ResultLoc *result_loc;
4026};4495};
40274496
4028struct IrInstructionAwaitGen {4497struct IrInstGenAwait {
4029 IrInstruction base;4498 IrInstGen base;
40304499
4031 IrInstruction *frame;4500 IrInstGen *frame;
4032 IrInstruction *result_loc;4501 IrInstGen *result_loc;
4033 ZigFn *target_fn;4502 ZigFn *target_fn;
4034};4503};
40354504
4036struct IrInstructionResume {4505struct IrInstSrcResume {
4037 IrInstruction base;4506 IrInstSrc base;
4507
4508 IrInstSrc *frame;
4509};
4510
4511struct IrInstGenResume {
4512 IrInstGen base;
40384513
4039 IrInstruction *frame;4514 IrInstGen *frame;
4040};4515};
40414516
4042enum SpillId {4517enum SpillId {
...@@ -4044,24 +4519,37 @@ enum SpillId {...@@ -4044,24 +4519,37 @@ enum SpillId {
4044 SpillIdRetErrCode,4519 SpillIdRetErrCode,
4045};4520};
40464521
4047struct IrInstructionSpillBegin {4522struct IrInstSrcSpillBegin {
4048 IrInstruction base;4523 IrInstSrc base;
4524
4525 IrInstSrc *operand;
4526 SpillId spill_id;
4527};
4528
4529struct IrInstGenSpillBegin {
4530 IrInstGen base;
40494531
4050 SpillId spill_id;4532 SpillId spill_id;
4051 IrInstruction *operand;4533 IrInstGen *operand;
4534};
4535
4536struct IrInstSrcSpillEnd {
4537 IrInstSrc base;
4538
4539 IrInstSrcSpillBegin *begin;
4052};4540};
40534541
4054struct IrInstructionSpillEnd {4542struct IrInstGenSpillEnd {
4055 IrInstruction base;4543 IrInstGen base;
40564544
4057 IrInstructionSpillBegin *begin;4545 IrInstGenSpillBegin *begin;
4058};4546};
40594547
4060struct IrInstructionVectorExtractElem {4548struct IrInstGenVectorExtractElem {
4061 IrInstruction base;4549 IrInstGen base;
40624550
4063 IrInstruction *vector;4551 IrInstGen *vector;
4064 IrInstruction *index;4552 IrInstGen *index;
4065};4553};
40664554
4067enum ResultLocId {4555enum ResultLocId {
...@@ -4082,9 +4570,9 @@ struct ResultLoc {...@@ -4082,9 +4570,9 @@ struct ResultLoc {
4082 ResultLocId id;4570 ResultLocId id;
4083 bool written;4571 bool written;
4084 bool allow_write_through_const;4572 bool allow_write_through_const;
4085 IrInstruction *resolved_loc; // result ptr4573 IrInstGen *resolved_loc; // result ptr
4086 IrInstruction *source_instruction;4574 IrInstSrc *source_instruction;
4087 IrInstruction *gen_instruction; // value to store to the result loc4575 IrInstGen *gen_instruction; // value to store to the result loc
4088 ZigType *implicit_elem_type;4576 ZigType *implicit_elem_type;
4089};4577};
40904578
...@@ -4114,18 +4602,18 @@ struct ResultLocPeerParent {...@@ -4114,18 +4602,18 @@ struct ResultLocPeerParent {
41144602
4115 bool skipped;4603 bool skipped;
4116 bool done_resuming;4604 bool done_resuming;
4117 IrBasicBlock *end_bb;4605 IrBasicBlockSrc *end_bb;
4118 ResultLoc *parent;4606 ResultLoc *parent;
4119 ZigList<ResultLocPeer *> peers;4607 ZigList<ResultLocPeer *> peers;
4120 ZigType *resolved_type;4608 ZigType *resolved_type;
4121 IrInstruction *is_comptime;4609 IrInstSrc *is_comptime;
4122};4610};
41234611
4124struct ResultLocPeer {4612struct ResultLocPeer {
4125 ResultLoc base;4613 ResultLoc base;
41264614
4127 ResultLocPeerParent *parent;4615 ResultLocPeerParent *parent;
4128 IrBasicBlock *next_bb;4616 IrBasicBlockSrc *next_bb;
4129 IrSuspendPosition suspend_pos;4617 IrSuspendPosition suspend_pos;
4130};4618};
41314619
...@@ -4196,7 +4684,7 @@ struct FnWalkAttrs {...@@ -4196,7 +4684,7 @@ struct FnWalkAttrs {
4196struct FnWalkCall {4684struct FnWalkCall {
4197 ZigList<LLVMValueRef> *gen_param_values;4685 ZigList<LLVMValueRef> *gen_param_values;
4198 ZigList<ZigType *> *gen_param_types;4686 ZigList<ZigType *> *gen_param_types;
4199 IrInstructionCallGen *inst;4687 IrInstGenCall *inst;
4200 bool is_var_args;4688 bool is_var_args;
4201};4689};
42024690
src/analyze.cpp+330-71
...@@ -199,7 +199,7 @@ ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent) {...@@ -199,7 +199,7 @@ ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent) {
199 return scope;199 return scope;
200}200}
201201
202Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruction *is_comptime) {202Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstSrc *is_comptime) {
203 ScopeRuntime *scope = allocate<ScopeRuntime>(1);203 ScopeRuntime *scope = allocate<ScopeRuntime>(1);
204 scope->is_comptime = is_comptime;204 scope->is_comptime = is_comptime;
205 init_scope(g, &scope->base, ScopeIdRuntime, node, parent);205 init_scope(g, &scope->base, ScopeIdRuntime, node, parent);
...@@ -593,9 +593,9 @@ ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type, bool is_con...@@ -593,9 +593,9 @@ ZigType *get_pointer_to_type_extra2(CodeGen *g, ZigType *child_type, bool is_con
593 }593 }
594594
595 if (inferred_struct_field != nullptr) {595 if (inferred_struct_field != nullptr) {
596 entry->abi_size = g->builtin_types.entry_usize->abi_size;596 entry->abi_size = SIZE_MAX;
597 entry->size_in_bits = g->builtin_types.entry_usize->size_in_bits;597 entry->size_in_bits = SIZE_MAX;
598 entry->abi_align = g->builtin_types.entry_usize->abi_align;598 entry->abi_align = UINT32_MAX;
599 } else if (type_is_resolved(child_type, ResolveStatusZeroBitsKnown)) {599 } else if (type_is_resolved(child_type, ResolveStatusZeroBitsKnown)) {
600 if (type_has_bits(child_type)) {600 if (type_has_bits(child_type)) {
601 entry->abi_size = g->builtin_types.entry_usize->abi_size;601 entry->abi_size = g->builtin_types.entry_usize->abi_size;
...@@ -1102,11 +1102,28 @@ ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind...@@ -1102,11 +1102,28 @@ ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind
1102ZigValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry,1102ZigValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry,
1103 Buf *type_name, UndefAllowed undef)1103 Buf *type_name, UndefAllowed undef)
1104{1104{
1105 Error err;
1106
1107 ZigValue *result = create_const_vals(1);
1108 ZigValue *result_ptr = create_const_vals(1);
1109 result->special = ConstValSpecialUndef;
1110 result->type = (type_entry == nullptr) ? g->builtin_types.entry_var : type_entry;
1111 result_ptr->special = ConstValSpecialStatic;
1112 result_ptr->type = get_pointer_to_type(g, result->type, false);
1113 result_ptr->data.x_ptr.mut = ConstPtrMutComptimeVar;
1114 result_ptr->data.x_ptr.special = ConstPtrSpecialRef;
1115 result_ptr->data.x_ptr.data.ref.pointee = result;
1116
1105 size_t backward_branch_count = 0;1117 size_t backward_branch_count = 0;
1106 size_t backward_branch_quota = default_backward_branch_quota;1118 size_t backward_branch_quota = default_backward_branch_quota;
1107 return ir_eval_const_value(g, scope, node, type_entry,1119 if ((err = ir_eval_const_value(g, scope, node, result_ptr,
1108 &backward_branch_count, &backward_branch_quota,1120 &backward_branch_count, &backward_branch_quota,
1109 nullptr, nullptr, node, type_name, nullptr, nullptr, undef);1121 nullptr, nullptr, node, type_name, nullptr, nullptr, undef)))
1122 {
1123 return g->invalid_inst_gen->value;
1124 }
1125 destroy(result_ptr, "ZigValue");
1126 return result;
1110}1127}
11111128
1112Error type_val_resolve_zero_bits(CodeGen *g, ZigValue *type_val, ZigType *parent_type,1129Error type_val_resolve_zero_bits(CodeGen *g, ZigValue *type_val, ZigType *parent_type,
...@@ -3350,7 +3367,7 @@ static void get_fully_qualified_decl_name(CodeGen *g, Buf *buf, Tld *tld, bool i...@@ -3350,7 +3367,7 @@ static void get_fully_qualified_decl_name(CodeGen *g, Buf *buf, Tld *tld, bool i
33503367
3351ZigFn *create_fn_raw(CodeGen *g, FnInline inline_value) {3368ZigFn *create_fn_raw(CodeGen *g, FnInline inline_value) {
3352 ZigFn *fn_entry = allocate<ZigFn>(1, "ZigFn");3369 ZigFn *fn_entry = allocate<ZigFn>(1, "ZigFn");
3353 fn_entry->ir_executable = allocate<IrExecutable>(1, "IrExecutablePass1");3370 fn_entry->ir_executable = allocate<IrExecutableSrc>(1, "IrExecutableSrc");
33543371
3355 fn_entry->prealloc_backward_branch_quota = default_backward_branch_quota;3372 fn_entry->prealloc_backward_branch_quota = default_backward_branch_quota;
33563373
...@@ -3829,7 +3846,6 @@ ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf...@@ -3829,7 +3846,6 @@ ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf
3829 variable_entry->var_type = var_type;3846 variable_entry->var_type = var_type;
3830 variable_entry->parent_scope = parent_scope;3847 variable_entry->parent_scope = parent_scope;
3831 variable_entry->shadowable = false;3848 variable_entry->shadowable = false;
3832 variable_entry->mem_slot_index = SIZE_MAX;
3833 variable_entry->src_arg_index = SIZE_MAX;3849 variable_entry->src_arg_index = SIZE_MAX;
38343850
3835 assert(name);3851 assert(name);
...@@ -3930,7 +3946,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {...@@ -3930,7 +3946,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {
39303946
3931 // TODO more validation for types that can't be used for export/extern variables3947 // TODO more validation for types that can't be used for export/extern variables
3932 ZigType *implicit_type = nullptr;3948 ZigType *implicit_type = nullptr;
3933 if (explicit_type && explicit_type->id == ZigTypeIdInvalid) {3949 if (explicit_type != nullptr && explicit_type->id == ZigTypeIdInvalid) {
3934 implicit_type = explicit_type;3950 implicit_type = explicit_type;
3935 } else if (var_decl->expr) {3951 } else if (var_decl->expr) {
3936 init_value = analyze_const_value(g, tld_var->base.parent_scope, var_decl->expr, explicit_type,3952 init_value = analyze_const_value(g, tld_var->base.parent_scope, var_decl->expr, explicit_type,
...@@ -4097,7 +4113,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco...@@ -4097,7 +4113,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco
4097 if (type_is_invalid(result->type)) {4113 if (type_is_invalid(result->type)) {
4098 dest_decls_scope->any_imports_failed = true;4114 dest_decls_scope->any_imports_failed = true;
4099 using_namespace->base.resolution = TldResolutionInvalid;4115 using_namespace->base.resolution = TldResolutionInvalid;
4100 using_namespace->using_namespace_value = g->invalid_instruction->value;4116 using_namespace->using_namespace_value = g->invalid_inst_gen->value;
4101 return;4117 return;
4102 }4118 }
41034119
...@@ -4106,7 +4122,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco...@@ -4106,7 +4122,7 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco
4106 buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&result->data.x_type->name)));4122 buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&result->data.x_type->name)));
4107 dest_decls_scope->any_imports_failed = true;4123 dest_decls_scope->any_imports_failed = true;
4108 using_namespace->base.resolution = TldResolutionInvalid;4124 using_namespace->base.resolution = TldResolutionInvalid;
4109 using_namespace->using_namespace_value = g->invalid_instruction->value;4125 using_namespace->using_namespace_value = g->invalid_inst_gen->value;
4110 return;4126 return;
4111 }4127 }
4112}4128}
...@@ -4667,12 +4683,12 @@ static void analyze_fn_async(CodeGen *g, ZigFn *fn, bool resolve_frame) {...@@ -4667,12 +4683,12 @@ static void analyze_fn_async(CodeGen *g, ZigFn *fn, bool resolve_frame) {
4667 }4683 }
46684684
4669 for (size_t i = 0; i < fn->call_list.length; i += 1) {4685 for (size_t i = 0; i < fn->call_list.length; i += 1) {
4670 IrInstructionCallGen *call = fn->call_list.at(i);4686 IrInstGenCall *call = fn->call_list.at(i);
4671 if (call->fn_entry == nullptr) {4687 if (call->fn_entry == nullptr) {
4672 // TODO function pointer call here, could be anything4688 // TODO function pointer call here, could be anything
4673 continue;4689 continue;
4674 }4690 }
4675 switch (analyze_callee_async(g, fn, call->fn_entry, call->base.source_node, must_not_be_async,4691 switch (analyze_callee_async(g, fn, call->fn_entry, call->base.base.source_node, must_not_be_async,
4676 call->modifier))4692 call->modifier))
4677 {4693 {
4678 case ErrorSemanticAnalyzeFail:4694 case ErrorSemanticAnalyzeFail:
...@@ -4690,10 +4706,10 @@ static void analyze_fn_async(CodeGen *g, ZigFn *fn, bool resolve_frame) {...@@ -4690,10 +4706,10 @@ static void analyze_fn_async(CodeGen *g, ZigFn *fn, bool resolve_frame) {
4690 }4706 }
4691 }4707 }
4692 for (size_t i = 0; i < fn->await_list.length; i += 1) {4708 for (size_t i = 0; i < fn->await_list.length; i += 1) {
4693 IrInstructionAwaitGen *await = fn->await_list.at(i);4709 IrInstGenAwait *await = fn->await_list.at(i);
4694 // TODO If this is a noasync await, it doesn't count4710 // TODO If this is a noasync await, it doesn't count
4695 // https://github.com/ziglang/zig/issues/31574711 // https://github.com/ziglang/zig/issues/3157
4696 switch (analyze_callee_async(g, fn, await->target_fn, await->base.source_node, must_not_be_async,4712 switch (analyze_callee_async(g, fn, await->target_fn, await->base.base.source_node, must_not_be_async,
4697 CallModifierNone))4713 CallModifierNone))
4698 {4714 {
4699 case ErrorSemanticAnalyzeFail:4715 case ErrorSemanticAnalyzeFail:
...@@ -4718,8 +4734,14 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {...@@ -4718,8 +4734,14 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {
4718 assert(!fn_type->data.fn.is_generic);4734 assert(!fn_type->data.fn.is_generic);
4719 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;4735 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
47204736
4737 if (fn->analyzed_executable.begin_scope == nullptr) {
4738 fn->analyzed_executable.begin_scope = &fn->def_scope->base;
4739 }
4740 if (fn->analyzed_executable.source_node == nullptr) {
4741 fn->analyzed_executable.source_node = fn->body_node;
4742 }
4721 ZigType *block_return_type = ir_analyze(g, fn->ir_executable,4743 ZigType *block_return_type = ir_analyze(g, fn->ir_executable,
4722 &fn->analyzed_executable, fn_type_id->return_type, return_type_node);4744 &fn->analyzed_executable, fn_type_id->return_type, return_type_node, nullptr);
4723 fn->src_implicit_return_type = block_return_type;4745 fn->src_implicit_return_type = block_return_type;
47244746
4725 if (type_is_invalid(block_return_type) || fn->analyzed_executable.first_err_trace_msg != nullptr) {4747 if (type_is_invalid(block_return_type) || fn->analyzed_executable.first_err_trace_msg != nullptr) {
...@@ -4784,7 +4806,7 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {...@@ -4784,7 +4806,7 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {
47844806
4785 if (g->verbose_ir) {4807 if (g->verbose_ir) {
4786 fprintf(stderr, "fn %s() { // (analyzed)\n", buf_ptr(&fn->symbol_name));4808 fprintf(stderr, "fn %s() { // (analyzed)\n", buf_ptr(&fn->symbol_name));
4787 ir_print(g, stderr, &fn->analyzed_executable, 4, IrPassGen);4809 ir_print_gen(g, stderr, &fn->analyzed_executable, 4);
4788 fprintf(stderr, "}\n");4810 fprintf(stderr, "}\n");
4789 }4811 }
4790 fn->anal_state = FnAnalStateComplete;4812 fn->anal_state = FnAnalStateComplete;
...@@ -4827,7 +4849,7 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) {...@@ -4827,7 +4849,7 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) {
4827 fprintf(stderr, "\n");4849 fprintf(stderr, "\n");
4828 ast_render(stderr, fn_table_entry->body_node, 4);4850 ast_render(stderr, fn_table_entry->body_node, 4);
4829 fprintf(stderr, "\nfn %s() { // (IR)\n", buf_ptr(&fn_table_entry->symbol_name));4851 fprintf(stderr, "\nfn %s() { // (IR)\n", buf_ptr(&fn_table_entry->symbol_name));
4830 ir_print(g, stderr, fn_table_entry->ir_executable, 4, IrPassSrc);4852 ir_print_src(g, stderr, fn_table_entry->ir_executable, 4);
4831 fprintf(stderr, "}\n");4853 fprintf(stderr, "}\n");
4832 }4854 }
48334855
...@@ -5619,6 +5641,8 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {...@@ -5619,6 +5641,8 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
5619 return OnePossibleValueYes;5641 return OnePossibleValueYes;
5620 return type_has_one_possible_value(g, type_entry->data.array.child_type);5642 return type_has_one_possible_value(g, type_entry->data.array.child_type);
5621 case ZigTypeIdStruct:5643 case ZigTypeIdStruct:
5644 // If the recursive function call asks, then we are not one possible value.
5645 type_entry->one_possible_value = OnePossibleValueNo;
5622 for (size_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {5646 for (size_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {
5623 TypeStructField *field = type_entry->data.structure.fields[i];5647 TypeStructField *field = type_entry->data.structure.fields[i];
5624 OnePossibleValue opv = (field->type_entry != nullptr) ?5648 OnePossibleValue opv = (field->type_entry != nullptr) ?
...@@ -5626,6 +5650,7 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {...@@ -5626,6 +5650,7 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
5626 type_val_resolve_has_one_possible_value(g, field->type_val);5650 type_val_resolve_has_one_possible_value(g, field->type_val);
5627 switch (opv) {5651 switch (opv) {
5628 case OnePossibleValueInvalid:5652 case OnePossibleValueInvalid:
5653 type_entry->one_possible_value = OnePossibleValueInvalid;
5629 return OnePossibleValueInvalid;5654 return OnePossibleValueInvalid;
5630 case OnePossibleValueNo:5655 case OnePossibleValueNo:
5631 return OnePossibleValueNo;5656 return OnePossibleValueNo;
...@@ -5633,6 +5658,7 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {...@@ -5633,6 +5658,7 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
5633 continue;5658 continue;
5634 }5659 }
5635 }5660 }
5661 type_entry->one_possible_value = OnePossibleValueYes;
5636 return OnePossibleValueYes;5662 return OnePossibleValueYes;
5637 case ZigTypeIdErrorSet:5663 case ZigTypeIdErrorSet:
5638 case ZigTypeIdEnum:5664 case ZigTypeIdEnum:
...@@ -5678,6 +5704,9 @@ ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry) {...@@ -5678,6 +5704,9 @@ ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry) {
5678 assert(field_type != nullptr);5704 assert(field_type != nullptr);
5679 result->data.x_struct.fields[i] = get_the_one_possible_value(g, field_type);5705 result->data.x_struct.fields[i] = get_the_one_possible_value(g, field_type);
5680 }5706 }
5707 } else if (result->type->id == ZigTypeIdPointer) {
5708 result->data.x_ptr.special = ConstPtrSpecialRef;
5709 result->data.x_ptr.data.ref.pointee = get_the_one_possible_value(g, result->type->data.pointer.child_type);
5681 }5710 }
5682 g->one_possible_values.put(type_entry, result);5711 g->one_possible_values.put(type_entry, result);
5683 return result;5712 return result;
...@@ -6191,13 +6220,13 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6191,13 +6220,13 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6191 ZigType *fn_type = get_async_fn_type(g, fn->type_entry);6220 ZigType *fn_type = get_async_fn_type(g, fn->type_entry);
61926221
6193 if (fn->analyzed_executable.need_err_code_spill) {6222 if (fn->analyzed_executable.need_err_code_spill) {
6194 IrInstructionAllocaGen *alloca_gen = allocate<IrInstructionAllocaGen>(1);6223 IrInstGenAlloca *alloca_gen = allocate<IrInstGenAlloca>(1);
6195 alloca_gen->base.id = IrInstructionIdAllocaGen;6224 alloca_gen->base.id = IrInstGenIdAlloca;
6196 alloca_gen->base.source_node = fn->proto_node;6225 alloca_gen->base.base.source_node = fn->proto_node;
6197 alloca_gen->base.scope = fn->child_scope;6226 alloca_gen->base.base.scope = fn->child_scope;
6198 alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue");6227 alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue");
6199 alloca_gen->base.value->type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);6228 alloca_gen->base.value->type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false);
6200 alloca_gen->base.ref_count = 1;6229 alloca_gen->base.base.ref_count = 1;
6201 alloca_gen->name_hint = "";6230 alloca_gen->name_hint = "";
6202 fn->alloca_gen_list.append(alloca_gen);6231 fn->alloca_gen_list.append(alloca_gen);
6203 fn->err_code_spill = &alloca_gen->base;6232 fn->err_code_spill = &alloca_gen->base;
...@@ -6205,18 +6234,18 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6205,18 +6234,18 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
62056234
6206 ZigType *largest_call_frame_type = nullptr;6235 ZigType *largest_call_frame_type = nullptr;
6207 // Later we'll change this to be largest_call_frame_type instead of void.6236 // Later we'll change this to be largest_call_frame_type instead of void.
6208 IrInstruction *all_calls_alloca = ir_create_alloca(g, &fn->fndef_scope->base, fn->body_node,6237 IrInstGen *all_calls_alloca = ir_create_alloca(g, &fn->fndef_scope->base, fn->body_node,
6209 fn, g->builtin_types.entry_void, "@async_call_frame");6238 fn, g->builtin_types.entry_void, "@async_call_frame");
62106239
6211 for (size_t i = 0; i < fn->call_list.length; i += 1) {6240 for (size_t i = 0; i < fn->call_list.length; i += 1) {
6212 IrInstructionCallGen *call = fn->call_list.at(i);6241 IrInstGenCall *call = fn->call_list.at(i);
6213 if (call->new_stack != nullptr) {6242 if (call->new_stack != nullptr) {
6214 // don't need to allocate a frame for this6243 // don't need to allocate a frame for this
6215 continue;6244 continue;
6216 }6245 }
6217 ZigFn *callee = call->fn_entry;6246 ZigFn *callee = call->fn_entry;
6218 if (callee == nullptr) {6247 if (callee == nullptr) {
6219 add_node_error(g, call->base.source_node,6248 add_node_error(g, call->base.base.source_node,
6220 buf_sprintf("function is not comptime-known; @asyncCall required"));6249 buf_sprintf("function is not comptime-known; @asyncCall required"));
6221 return ErrorSemanticAnalyzeFail;6250 return ErrorSemanticAnalyzeFail;
6222 }6251 }
...@@ -6226,14 +6255,14 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6226,14 +6255,14 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6226 if (callee->anal_state == FnAnalStateProbing) {6255 if (callee->anal_state == FnAnalStateProbing) {
6227 ErrorMsg *msg = add_node_error(g, fn->proto_node,6256 ErrorMsg *msg = add_node_error(g, fn->proto_node,
6228 buf_sprintf("unable to determine async function frame of '%s'", buf_ptr(&fn->symbol_name)));6257 buf_sprintf("unable to determine async function frame of '%s'", buf_ptr(&fn->symbol_name)));
6229 g->trace_err = add_error_note(g, msg, call->base.source_node,6258 g->trace_err = add_error_note(g, msg, call->base.base.source_node,
6230 buf_sprintf("analysis of function '%s' depends on the frame", buf_ptr(&callee->symbol_name)));6259 buf_sprintf("analysis of function '%s' depends on the frame", buf_ptr(&callee->symbol_name)));
6231 return ErrorSemanticAnalyzeFail;6260 return ErrorSemanticAnalyzeFail;
6232 }6261 }
62336262
6234 ZigType *callee_frame_type = get_fn_frame_type(g, callee);6263 ZigType *callee_frame_type = get_fn_frame_type(g, callee);
6235 frame_type->data.frame.resolve_loop_type = callee_frame_type;6264 frame_type->data.frame.resolve_loop_type = callee_frame_type;
6236 frame_type->data.frame.resolve_loop_src_node = call->base.source_node;6265 frame_type->data.frame.resolve_loop_src_node = call->base.base.source_node;
62376266
6238 analyze_fn_body(g, callee);6267 analyze_fn_body(g, callee);
6239 if (callee->anal_state == FnAnalStateInvalid) {6268 if (callee->anal_state == FnAnalStateInvalid) {
...@@ -6249,7 +6278,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6249,7 +6278,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6249 if (!fn_is_async(callee))6278 if (!fn_is_async(callee))
6250 continue;6279 continue;
62516280
6252 mark_suspension_point(call->base.scope);6281 mark_suspension_point(call->base.base.scope);
62536282
6254 if ((err = type_resolve(g, callee_frame_type, ResolveStatusSizeKnown))) {6283 if ((err = type_resolve(g, callee_frame_type, ResolveStatusSizeKnown))) {
6255 return err;6284 return err;
...@@ -6271,7 +6300,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6271,7 +6300,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6271 // For example: foo() + await z6300 // For example: foo() + await z
6272 // The funtion call result of foo() must be spilled.6301 // The funtion call result of foo() must be spilled.
6273 for (size_t i = 0; i < fn->await_list.length; i += 1) {6302 for (size_t i = 0; i < fn->await_list.length; i += 1) {
6274 IrInstructionAwaitGen *await = fn->await_list.at(i);6303 IrInstGenAwait *await = fn->await_list.at(i);
6275 // TODO If this is a noasync await, it doesn't suspend6304 // TODO If this is a noasync await, it doesn't suspend
6276 // https://github.com/ziglang/zig/issues/31576305 // https://github.com/ziglang/zig/issues/3157
6277 if (await->base.value->special != ConstValSpecialRuntime) {6306 if (await->base.value->special != ConstValSpecialRuntime) {
...@@ -6293,52 +6322,51 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6293,52 +6322,51 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6293 }6322 }
6294 // This await is a suspend point, but it might not need a spill.6323 // This await is a suspend point, but it might not need a spill.
6295 // We do need to mark the ExprScope as having a suspend point in it.6324 // We do need to mark the ExprScope as having a suspend point in it.
6296 mark_suspension_point(await->base.scope);6325 mark_suspension_point(await->base.base.scope);
62976326
6298 if (await->result_loc != nullptr) {6327 if (await->result_loc != nullptr) {
6299 // If there's a result location, that is the spill6328 // If there's a result location, that is the spill
6300 continue;6329 continue;
6301 }6330 }
6302 if (await->base.ref_count == 0)6331 if (await->base.base.ref_count == 0)
6303 continue;6332 continue;
6304 if (!type_has_bits(await->base.value->type))6333 if (!type_has_bits(await->base.value->type))
6305 continue;6334 continue;
6306 await->result_loc = ir_create_alloca(g, await->base.scope, await->base.source_node, fn,6335 await->result_loc = ir_create_alloca(g, await->base.base.scope, await->base.base.source_node, fn,
6307 await->base.value->type, "");6336 await->base.value->type, "");
6308 }6337 }
6309 for (size_t block_i = 0; block_i < fn->analyzed_executable.basic_block_list.length; block_i += 1) {6338 for (size_t block_i = 0; block_i < fn->analyzed_executable.basic_block_list.length; block_i += 1) {
6310 IrBasicBlock *block = fn->analyzed_executable.basic_block_list.at(block_i);6339 IrBasicBlockGen *block = fn->analyzed_executable.basic_block_list.at(block_i);
6311 for (size_t instr_i = 0; instr_i < block->instruction_list.length; instr_i += 1) {6340 for (size_t instr_i = 0; instr_i < block->instruction_list.length; instr_i += 1) {
6312 IrInstruction *instruction = block->instruction_list.at(instr_i);6341 IrInstGen *instruction = block->instruction_list.at(instr_i);
6313 if (instruction->id == IrInstructionIdSuspendFinish) {6342 if (instruction->id == IrInstGenIdSuspendFinish) {
6314 mark_suspension_point(instruction->scope);6343 mark_suspension_point(instruction->base.scope);
6315 }6344 }
6316 }6345 }
6317 }6346 }
6318 // Now that we've marked all the expr scopes that have to spill, we go over the instructions6347 // Now that we've marked all the expr scopes that have to spill, we go over the instructions
6319 // and spill the relevant ones.6348 // and spill the relevant ones.
6320 for (size_t block_i = 0; block_i < fn->analyzed_executable.basic_block_list.length; block_i += 1) {6349 for (size_t block_i = 0; block_i < fn->analyzed_executable.basic_block_list.length; block_i += 1) {
6321 IrBasicBlock *block = fn->analyzed_executable.basic_block_list.at(block_i);6350 IrBasicBlockGen *block = fn->analyzed_executable.basic_block_list.at(block_i);
6322 for (size_t instr_i = 0; instr_i < block->instruction_list.length; instr_i += 1) {6351 for (size_t instr_i = 0; instr_i < block->instruction_list.length; instr_i += 1) {
6323 IrInstruction *instruction = block->instruction_list.at(instr_i);6352 IrInstGen *instruction = block->instruction_list.at(instr_i);
6324 if (instruction->id == IrInstructionIdAwaitGen ||6353 if (instruction->id == IrInstGenIdAwait ||
6325 instruction->id == IrInstructionIdVarPtr ||6354 instruction->id == IrInstGenIdVarPtr ||
6326 instruction->id == IrInstructionIdDeclRef ||6355 instruction->id == IrInstGenIdAlloca)
6327 instruction->id == IrInstructionIdAllocaGen)
6328 {6356 {
6329 // This instruction does its own spilling specially, or otherwise doesn't need it.6357 // This instruction does its own spilling specially, or otherwise doesn't need it.
6330 continue;6358 continue;
6331 }6359 }
6332 if (instruction->value->special != ConstValSpecialRuntime)6360 if (instruction->value->special != ConstValSpecialRuntime)
6333 continue;6361 continue;
6334 if (instruction->ref_count == 0)6362 if (instruction->base.ref_count == 0)
6335 continue;6363 continue;
6336 if ((err = type_resolve(g, instruction->value->type, ResolveStatusZeroBitsKnown)))6364 if ((err = type_resolve(g, instruction->value->type, ResolveStatusZeroBitsKnown)))
6337 return ErrorSemanticAnalyzeFail;6365 return ErrorSemanticAnalyzeFail;
6338 if (!type_has_bits(instruction->value->type))6366 if (!type_has_bits(instruction->value->type))
6339 continue;6367 continue;
6340 if (scope_needs_spill(instruction->scope)) {6368 if (scope_needs_spill(instruction->base.scope)) {
6341 instruction->spill = ir_create_alloca(g, instruction->scope, instruction->source_node,6369 instruction->spill = ir_create_alloca(g, instruction->base.scope, instruction->base.source_node,
6342 fn, instruction->value->type, "");6370 fn, instruction->value->type, "");
6343 }6371 }
6344 }6372 }
...@@ -6389,14 +6417,14 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6389,14 +6417,14 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6389 }6417 }
63906418
6391 for (size_t alloca_i = 0; alloca_i < fn->alloca_gen_list.length; alloca_i += 1) {6419 for (size_t alloca_i = 0; alloca_i < fn->alloca_gen_list.length; alloca_i += 1) {
6392 IrInstructionAllocaGen *instruction = fn->alloca_gen_list.at(alloca_i);6420 IrInstGenAlloca *instruction = fn->alloca_gen_list.at(alloca_i);
6393 instruction->field_index = SIZE_MAX;6421 instruction->field_index = SIZE_MAX;
6394 ZigType *ptr_type = instruction->base.value->type;6422 ZigType *ptr_type = instruction->base.value->type;
6395 assert(ptr_type->id == ZigTypeIdPointer);6423 assert(ptr_type->id == ZigTypeIdPointer);
6396 ZigType *child_type = ptr_type->data.pointer.child_type;6424 ZigType *child_type = ptr_type->data.pointer.child_type;
6397 if (!type_has_bits(child_type))6425 if (!type_has_bits(child_type))
6398 continue;6426 continue;
6399 if (instruction->base.ref_count == 0)6427 if (instruction->base.base.ref_count == 0)
6400 continue;6428 continue;
6401 if (instruction->base.value->special != ConstValSpecialRuntime) {6429 if (instruction->base.value->special != ConstValSpecialRuntime) {
6402 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=6430 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=
...@@ -6407,7 +6435,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6407,7 +6435,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6407 }6435 }
64086436
6409 frame_type->data.frame.resolve_loop_type = child_type;6437 frame_type->data.frame.resolve_loop_type = child_type;
6410 frame_type->data.frame.resolve_loop_src_node = instruction->base.source_node;6438 frame_type->data.frame.resolve_loop_src_node = instruction->base.base.source_node;
6411 if ((err = type_resolve(g, child_type, ResolveStatusSizeKnown))) {6439 if ((err = type_resolve(g, child_type, ResolveStatusSizeKnown))) {
6412 return err;6440 return err;
6413 }6441 }
...@@ -6421,7 +6449,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {...@@ -6421,7 +6449,7 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
6421 instruction->field_index = fields.length;6449 instruction->field_index = fields.length;
64226450
6423 src_assert(child_type->id != ZigTypeIdPointer || child_type->data.pointer.inferred_struct_field == nullptr,6451 src_assert(child_type->id != ZigTypeIdPointer || child_type->data.pointer.inferred_struct_field == nullptr,
6424 instruction->base.source_node);6452 instruction->base.base.source_node);
6425 fields.append({name, child_type, instruction->align});6453 fields.append({name, child_type, instruction->align});
6426 }6454 }
64276455
...@@ -6453,7 +6481,21 @@ static Error resolve_pointer_zero_bits(CodeGen *g, ZigType *ty) {...@@ -6453,7 +6481,21 @@ static Error resolve_pointer_zero_bits(CodeGen *g, ZigType *ty) {
6453 }6481 }
6454 ty->data.pointer.resolve_loop_flag_zero_bits = true;6482 ty->data.pointer.resolve_loop_flag_zero_bits = true;
64556483
6456 ZigType *elem_type = ty->data.pointer.child_type;6484 ZigType *elem_type;
6485 InferredStructField *isf = ty->data.pointer.inferred_struct_field;
6486 if (isf != nullptr) {
6487 TypeStructField *field = find_struct_type_field(isf->inferred_struct_type, isf->field_name);
6488 assert(field != nullptr);
6489 if (field->is_comptime) {
6490 ty->abi_size = 0;
6491 ty->size_in_bits = 0;
6492 ty->abi_align = 0;
6493 return ErrorNone;
6494 }
6495 elem_type = field->type_entry;
6496 } else {
6497 elem_type = ty->data.pointer.child_type;
6498 }
64576499
6458 bool has_bits;6500 bool has_bits;
6459 if ((err = type_has_bits2(g, elem_type, &has_bits)))6501 if ((err = type_has_bits2(g, elem_type, &has_bits)))
...@@ -6554,8 +6596,10 @@ bool ir_get_var_is_comptime(ZigVar *var) {...@@ -6554,8 +6596,10 @@ bool ir_get_var_is_comptime(ZigVar *var) {
6554 // As an optimization, is_comptime values which are constant are allowed6596 // As an optimization, is_comptime values which are constant are allowed
6555 // to be omitted from analysis. In this case, there is no child instruction6597 // to be omitted from analysis. In this case, there is no child instruction
6556 // and we simply look at the unanalyzed const parent instruction.6598 // and we simply look at the unanalyzed const parent instruction.
6557 assert(var->is_comptime->value->type->id == ZigTypeIdBool);6599 assert(var->is_comptime->id == IrInstSrcIdConst);
6558 var->is_comptime_memoized_value = var->is_comptime->value->data.x_bool;6600 IrInstSrcConst *const_inst = reinterpret_cast<IrInstSrcConst *>(var->is_comptime);
6601 assert(const_inst->value->type->id == ZigTypeIdBool);
6602 var->is_comptime_memoized_value = const_inst->value->data.x_bool;
6559 var->is_comptime = nullptr;6603 var->is_comptime = nullptr;
6560 return var->is_comptime_memoized_value;6604 return var->is_comptime_memoized_value;
6561}6605}
...@@ -6874,6 +6918,7 @@ static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ZigValu...@@ -6874,6 +6918,7 @@ static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ZigValu
6874 }6918 }
6875 case ConstArraySpecialNone: {6919 case ConstArraySpecialNone: {
6876 ZigValue *base = &array->data.s_none.elements[start];6920 ZigValue *base = &array->data.s_none.elements[start];
6921 assert(base != nullptr);
6877 assert(start + len <= const_val->type->data.array.len);6922 assert(start + len <= const_val->type->data.array.len);
68786923
6879 buf_appendf(buf, "%s{", buf_ptr(type_name));6924 buf_appendf(buf, "%s{", buf_ptr(type_name));
...@@ -6889,6 +6934,10 @@ static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ZigValu...@@ -6889,6 +6934,10 @@ static void render_const_val_array(CodeGen *g, Buf *buf, Buf *type_name, ZigValu
6889}6934}
68906935
6891void render_const_value(CodeGen *g, Buf *buf, ZigValue *const_val) {6936void render_const_value(CodeGen *g, Buf *buf, ZigValue *const_val) {
6937 if (const_val == nullptr) {
6938 buf_appendf(buf, "(invalid nullptr value)");
6939 return;
6940 }
6892 switch (const_val->special) {6941 switch (const_val->special) {
6893 case ConstValSpecialRuntime:6942 case ConstValSpecialRuntime:
6894 buf_appendf(buf, "(runtime value)");6943 buf_appendf(buf, "(runtime value)");
...@@ -9193,21 +9242,6 @@ void src_assert(bool ok, AstNode *source_node) {...@@ -9193,21 +9242,6 @@ void src_assert(bool ok, AstNode *source_node) {
9193 stage2_panic(msg, strlen(msg));9242 stage2_panic(msg, strlen(msg));
9194}9243}
91959244
9196IrInstruction *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigFn *fn,
9197 ZigType *var_type, const char *name_hint)
9198{
9199 IrInstructionAllocaGen *alloca_gen = allocate<IrInstructionAllocaGen>(1);
9200 alloca_gen->base.id = IrInstructionIdAllocaGen;
9201 alloca_gen->base.source_node = source_node;
9202 alloca_gen->base.scope = scope;
9203 alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue");
9204 alloca_gen->base.value->type = get_pointer_to_type(g, var_type, false);
9205 alloca_gen->base.ref_count = 1;
9206 alloca_gen->name_hint = name_hint;
9207 fn->alloca_gen_list.append(alloca_gen);
9208 return &alloca_gen->base;
9209}
9210
9211Error analyze_import(CodeGen *g, ZigType *source_import, Buf *import_target_str,9245Error analyze_import(CodeGen *g, ZigType *source_import, Buf *import_target_str,
9212 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path)9246 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path)
9213{9247{
...@@ -9268,8 +9302,17 @@ Error analyze_import(CodeGen *g, ZigType *source_import, Buf *import_target_str,...@@ -9268,8 +9302,17 @@ Error analyze_import(CodeGen *g, ZigType *source_import, Buf *import_target_str,
9268}9302}
92699303
92709304
9271void IrExecutable::src() {9305void IrExecutableSrc::src() {
9272 IrExecutable *it;9306 if (this->source_node != nullptr) {
9307 this->source_node->src();
9308 }
9309 if (this->parent_exec != nullptr) {
9310 this->parent_exec->src();
9311 }
9312}
9313
9314void IrExecutableGen::src() {
9315 IrExecutableGen *it;
9273 for (it = this; it != nullptr && it->source_node != nullptr; it = it->parent_exec) {9316 for (it = this; it != nullptr && it->source_node != nullptr; it = it->parent_exec) {
9274 it->source_node->src();9317 it->source_node->src();
9275 }9318 }
...@@ -9300,10 +9343,13 @@ bool type_has_optional_repr(ZigType *ty) {...@@ -9300,10 +9343,13 @@ bool type_has_optional_repr(ZigType *ty) {
9300}9343}
93019344
9302void copy_const_val(ZigValue *dest, ZigValue *src) {9345void copy_const_val(ZigValue *dest, ZigValue *src) {
9346 uint32_t prev_align = dest->llvm_align;
9347 ConstParent prev_parent = dest->parent;
9303 memcpy(dest, src, sizeof(ZigValue));9348 memcpy(dest, src, sizeof(ZigValue));
9349 dest->llvm_align = prev_align;
9304 if (src->special != ConstValSpecialStatic)9350 if (src->special != ConstValSpecialStatic)
9305 return;9351 return;
9306 dest->parent.id = ConstParentIdNone;9352 dest->parent = prev_parent;
9307 if (dest->type->id == ZigTypeIdStruct) {9353 if (dest->type->id == ZigTypeIdStruct) {
9308 dest->data.x_struct.fields = alloc_const_vals_ptrs(dest->type->data.structure.src_field_count);9354 dest->data.x_struct.fields = alloc_const_vals_ptrs(dest->type->data.structure.src_field_count);
9309 for (size_t i = 0; i < dest->type->data.structure.src_field_count; i += 1) {9355 for (size_t i = 0; i < dest->type->data.structure.src_field_count; i += 1) {
...@@ -9312,6 +9358,16 @@ void copy_const_val(ZigValue *dest, ZigValue *src) {...@@ -9312,6 +9358,16 @@ void copy_const_val(ZigValue *dest, ZigValue *src) {
9312 dest->data.x_struct.fields[i]->parent.data.p_struct.struct_val = dest;9358 dest->data.x_struct.fields[i]->parent.data.p_struct.struct_val = dest;
9313 dest->data.x_struct.fields[i]->parent.data.p_struct.field_index = i;9359 dest->data.x_struct.fields[i]->parent.data.p_struct.field_index = i;
9314 }9360 }
9361 } else if (dest->type->id == ZigTypeIdArray) {
9362 if (dest->data.x_array.special == ConstArraySpecialNone) {
9363 dest->data.x_array.data.s_none.elements = create_const_vals(dest->type->data.array.len);
9364 for (uint64_t i = 0; i < dest->type->data.array.len; i += 1) {
9365 copy_const_val(&dest->data.x_array.data.s_none.elements[i], &src->data.x_array.data.s_none.elements[i]);
9366 dest->data.x_array.data.s_none.elements[i].parent.id = ConstParentIdArray;
9367 dest->data.x_array.data.s_none.elements[i].parent.data.p_array.array_val = dest;
9368 dest->data.x_array.data.s_none.elements[i].parent.data.p_array.elem_index = i;
9369 }
9370 }
9315 } else if (type_has_optional_repr(dest->type) && dest->data.x_optional != nullptr) {9371 } else if (type_has_optional_repr(dest->type) && dest->data.x_optional != nullptr) {
9316 dest->data.x_optional = create_const_vals(1);9372 dest->data.x_optional = create_const_vals(1);
9317 copy_const_val(dest->data.x_optional, src->data.x_optional);9373 copy_const_val(dest->data.x_optional, src->data.x_optional);
...@@ -9357,3 +9413,206 @@ bool type_is_numeric(ZigType *ty) {...@@ -9357,3 +9413,206 @@ bool type_is_numeric(ZigType *ty) {
9357 }9413 }
9358 zig_unreachable();9414 zig_unreachable();
9359}9415}
9416
9417static void dump_value_indent(ZigValue *val, int indent) {
9418 for (int i = 0; i < indent; i += 1) {
9419 fprintf(stderr, " ");
9420 }
9421 fprintf(stderr, "Value@%p(", val);
9422 if (val->type != nullptr) {
9423 fprintf(stderr, "%s)", buf_ptr(&val->type->name));
9424 } else {
9425 fprintf(stderr, "type=nullptr)");
9426 }
9427 switch (val->special) {
9428 case ConstValSpecialUndef:
9429 fprintf(stderr, "[undefined]\n");
9430 return;
9431 case ConstValSpecialLazy:
9432 fprintf(stderr, "[lazy]\n");
9433 return;
9434 case ConstValSpecialRuntime:
9435 fprintf(stderr, "[runtime]\n");
9436 return;
9437 case ConstValSpecialStatic:
9438 break;
9439 }
9440 if (val->type == nullptr)
9441 return;
9442 switch (val->type->id) {
9443 case ZigTypeIdInvalid:
9444 fprintf(stderr, "<invalid>\n");
9445 return;
9446 case ZigTypeIdUnreachable:
9447 fprintf(stderr, "<unreachable>\n");
9448 return;
9449 case ZigTypeIdUndefined:
9450 fprintf(stderr, "<undefined>\n");
9451 return;
9452 case ZigTypeIdVoid:
9453 fprintf(stderr, "<{}>\n");
9454 return;
9455 case ZigTypeIdMetaType:
9456 fprintf(stderr, "<%s>\n", buf_ptr(&val->data.x_type->name));
9457 return;
9458 case ZigTypeIdBool:
9459 fprintf(stderr, "<%s>\n", val->data.x_bool ? "true" : "false");
9460 return;
9461 case ZigTypeIdComptimeInt:
9462 case ZigTypeIdInt: {
9463 Buf *tmp_buf = buf_alloc();
9464 bigint_append_buf(tmp_buf, &val->data.x_bigint, 10);
9465 fprintf(stderr, "<%s>\n", buf_ptr(tmp_buf));
9466 buf_destroy(tmp_buf);
9467 return;
9468 }
9469 case ZigTypeIdComptimeFloat:
9470 case ZigTypeIdFloat:
9471 fprintf(stderr, "<TODO dump number>\n");
9472 return;
9473
9474 case ZigTypeIdStruct:
9475 fprintf(stderr, "<struct\n");
9476 for (size_t i = 0; i < val->type->data.structure.src_field_count; i += 1) {
9477 for (int j = 0; j < indent; j += 1) {
9478 fprintf(stderr, " ");
9479 }
9480 fprintf(stderr, "%s: ", buf_ptr(val->type->data.structure.fields[i]->name));
9481 if (val->data.x_struct.fields == nullptr) {
9482 fprintf(stderr, "<null>\n");
9483 } else {
9484 dump_value_indent(val->data.x_struct.fields[i], 1);
9485 }
9486 }
9487 for (int i = 0; i < indent; i += 1) {
9488 fprintf(stderr, " ");
9489 }
9490 fprintf(stderr, ">\n");
9491 return;
9492
9493 case ZigTypeIdOptional:
9494 fprintf(stderr, "<\n");
9495 dump_value_indent(val->data.x_optional, indent + 1);
9496
9497 for (int i = 0; i < indent; i += 1) {
9498 fprintf(stderr, " ");
9499 }
9500 fprintf(stderr, ">\n");
9501 return;
9502
9503 case ZigTypeIdErrorUnion:
9504 if (val->data.x_err_union.payload != nullptr) {
9505 fprintf(stderr, "<\n");
9506 dump_value_indent(val->data.x_err_union.payload, indent + 1);
9507 } else {
9508 fprintf(stderr, "<\n");
9509 dump_value_indent(val->data.x_err_union.error_set, 0);
9510 }
9511 for (int i = 0; i < indent; i += 1) {
9512 fprintf(stderr, " ");
9513 }
9514 fprintf(stderr, ">\n");
9515 return;
9516
9517 case ZigTypeIdPointer:
9518 switch (val->data.x_ptr.special) {
9519 case ConstPtrSpecialInvalid:
9520 fprintf(stderr, "<!invalid ptr!>\n");
9521 return;
9522 case ConstPtrSpecialRef:
9523 fprintf(stderr, "<ref\n");
9524 dump_value_indent(val->data.x_ptr.data.ref.pointee, indent + 1);
9525 break;
9526 case ConstPtrSpecialBaseStruct: {
9527 ZigValue *struct_val = val->data.x_ptr.data.base_struct.struct_val;
9528 size_t field_index = val->data.x_ptr.data.base_struct.field_index;
9529 fprintf(stderr, "<struct %p field %zu\n", struct_val, field_index);
9530 if (struct_val != nullptr) {
9531 ZigValue *field_val = struct_val->data.x_struct.fields[field_index];
9532 if (field_val != nullptr) {
9533 dump_value_indent(field_val, indent + 1);
9534 } else {
9535 for (int i = 0; i < indent; i += 1) {
9536 fprintf(stderr, " ");
9537 }
9538 fprintf(stderr, "(invalid null field)\n");
9539 }
9540 }
9541 break;
9542 }
9543 case ConstPtrSpecialBaseOptionalPayload: {
9544 ZigValue *optional_val = val->data.x_ptr.data.base_optional_payload.optional_val;
9545 fprintf(stderr, "<optional %p payload\n", optional_val);
9546 if (optional_val != nullptr) {
9547 dump_value_indent(optional_val, indent + 1);
9548 }
9549 break;
9550 }
9551 default:
9552 fprintf(stderr, "TODO dump more pointer things\n");
9553 }
9554 for (int i = 0; i < indent; i += 1) {
9555 fprintf(stderr, " ");
9556 }
9557 fprintf(stderr, ">\n");
9558 return;
9559
9560 case ZigTypeIdVector:
9561 case ZigTypeIdArray:
9562 case ZigTypeIdNull:
9563 case ZigTypeIdErrorSet:
9564 case ZigTypeIdEnum:
9565 case ZigTypeIdUnion:
9566 case ZigTypeIdFn:
9567 case ZigTypeIdBoundFn:
9568 case ZigTypeIdOpaque:
9569 case ZigTypeIdFnFrame:
9570 case ZigTypeIdAnyFrame:
9571 case ZigTypeIdEnumLiteral:
9572 fprintf(stderr, "<TODO dump value>\n");
9573 return;
9574 }
9575 zig_unreachable();
9576}
9577
9578void ZigValue::dump() {
9579 dump_value_indent(this, 0);
9580}
9581
9582// float ops that take a single argument
9583//TODO Powi, Pow, minnum, maxnum, maximum, minimum, copysign, lround, llround, lrint, llrint
9584const char *float_op_to_name(BuiltinFnId op) {
9585 switch (op) {
9586 case BuiltinFnIdSqrt:
9587 return "sqrt";
9588 case BuiltinFnIdSin:
9589 return "sin";
9590 case BuiltinFnIdCos:
9591 return "cos";
9592 case BuiltinFnIdExp:
9593 return "exp";
9594 case BuiltinFnIdExp2:
9595 return "exp2";
9596 case BuiltinFnIdLog:
9597 return "log";
9598 case BuiltinFnIdLog10:
9599 return "log10";
9600 case BuiltinFnIdLog2:
9601 return "log2";
9602 case BuiltinFnIdFabs:
9603 return "fabs";
9604 case BuiltinFnIdFloor:
9605 return "floor";
9606 case BuiltinFnIdCeil:
9607 return "ceil";
9608 case BuiltinFnIdTrunc:
9609 return "trunc";
9610 case BuiltinFnIdNearbyInt:
9611 return "nearbyint";
9612 case BuiltinFnIdRound:
9613 return "round";
9614 default:
9615 zig_unreachable();
9616 }
9617}
9618
src/analyze.hpp+2-3
...@@ -120,7 +120,7 @@ ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent);...@@ -120,7 +120,7 @@ ScopeLoop *create_loop_scope(CodeGen *g, AstNode *node, Scope *parent);
120ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent);120ScopeSuspend *create_suspend_scope(CodeGen *g, AstNode *node, Scope *parent);
121ScopeFnDef *create_fndef_scope(CodeGen *g, AstNode *node, Scope *parent, ZigFn *fn_entry);121ScopeFnDef *create_fndef_scope(CodeGen *g, AstNode *node, Scope *parent, ZigFn *fn_entry);
122Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent);122Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent);
123Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruction *is_comptime);123Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstSrc *is_comptime);
124Scope *create_typeof_scope(CodeGen *g, AstNode *node, Scope *parent);124Scope *create_typeof_scope(CodeGen *g, AstNode *node, Scope *parent);
125ScopeExpr *create_expr_scope(CodeGen *g, AstNode *node, Scope *parent);125ScopeExpr *create_expr_scope(CodeGen *g, AstNode *node, Scope *parent);
126126
...@@ -271,8 +271,6 @@ ZigType *resolve_struct_field_type(CodeGen *g, TypeStructField *struct_field);...@@ -271,8 +271,6 @@ ZigType *resolve_struct_field_type(CodeGen *g, TypeStructField *struct_field);
271271
272void add_async_error_notes(CodeGen *g, ErrorMsg *msg, ZigFn *fn);272void add_async_error_notes(CodeGen *g, ErrorMsg *msg, ZigFn *fn);
273273
274IrInstruction *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigFn *fn,
275 ZigType *var_type, const char *name_hint);
276Error analyze_import(CodeGen *codegen, ZigType *source_import, Buf *import_target_str,274Error analyze_import(CodeGen *codegen, ZigType *source_import, Buf *import_target_str,
277 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path);275 ZigType **out_import, Buf **out_import_target_path, Buf *out_full_path);
278ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry);276ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry);
...@@ -281,4 +279,5 @@ void copy_const_val(ZigValue *dest, ZigValue *src);...@@ -281,4 +279,5 @@ void copy_const_val(ZigValue *dest, ZigValue *src);
281bool type_has_optional_repr(ZigType *ty);279bool type_has_optional_repr(ZigType *ty);
282bool is_opt_err_set(ZigType *ty);280bool is_opt_err_set(ZigType *ty);
283bool type_is_numeric(ZigType *ty);281bool type_is_numeric(ZigType *ty);
282const char *float_op_to_name(BuiltinFnId op);
284#endif283#endif
src/codegen.cpp+528-520
...@@ -20,6 +20,7 @@...@@ -20,6 +20,7 @@
20#include "zig_llvm.h"20#include "zig_llvm.h"
21#include "userland.h"21#include "userland.h"
22#include "dump_analysis.hpp"22#include "dump_analysis.hpp"
23#include "softfloat.hpp"
2324
24#include <stdio.h>25#include <stdio.h>
25#include <errno.h>26#include <errno.h>
...@@ -30,11 +31,6 @@ enum ResumeId {...@@ -30,11 +31,6 @@ enum ResumeId {
30 ResumeIdCall,31 ResumeIdCall,
31};32};
3233
33// TODO https://github.com/ziglang/zig/issues/2883
34// Until then we have this same default as Clang.
35// This avoids https://github.com/ziglang/zig/issues/3275
36static const char *riscv_default_features = "+a,+c,+d,+f,+m,+relax";
37
38static void init_darwin_native(CodeGen *g) {34static void init_darwin_native(CodeGen *g) {
39 char *osx_target = getenv("MACOSX_DEPLOYMENT_TARGET");35 char *osx_target = getenv("MACOSX_DEPLOYMENT_TARGET");
40 char *ios_target = getenv("IPHONEOS_DEPLOYMENT_TARGET");36 char *ios_target = getenv("IPHONEOS_DEPLOYMENT_TARGET");
...@@ -191,7 +187,7 @@ static void generate_error_name_table(CodeGen *g);...@@ -191,7 +187,7 @@ static void generate_error_name_table(CodeGen *g);
191static bool value_is_all_undef(CodeGen *g, ZigValue *const_val);187static bool value_is_all_undef(CodeGen *g, ZigValue *const_val);
192static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_type, LLVMValueRef ptr);188static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_type, LLVMValueRef ptr);
193static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment);189static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment);
194static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_instr,190static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstGen *source_instr,
195 LLVMValueRef target_frame_ptr, ZigType *result_type, ZigType *ptr_result_type,191 LLVMValueRef target_frame_ptr, ZigType *result_type, ZigType *ptr_result_type,
196 LLVMValueRef result_loc, bool non_async);192 LLVMValueRef result_loc, bool non_async);
197static Error get_tmp_filename(CodeGen *g, Buf *out, Buf *suffix);193static Error get_tmp_filename(CodeGen *g, Buf *out, Buf *suffix);
...@@ -877,14 +873,14 @@ static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, ZigType *type...@@ -877,14 +873,14 @@ static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, ZigType *type
877 }873 }
878}874}
879875
880static void ir_assert(bool ok, IrInstruction *source_instruction) {876static void ir_assert(bool ok, IrInstGen *source_instruction) {
881 if (ok) return;877 if (ok) return;
882 src_assert(ok, source_instruction->source_node);878 src_assert(ok, source_instruction->base.source_node);
883}879}
884880
885static bool ir_want_fast_math(CodeGen *g, IrInstruction *instruction) {881static bool ir_want_fast_math(CodeGen *g, IrInstGen *instruction) {
886 // TODO memoize882 // TODO memoize
887 Scope *scope = instruction->scope;883 Scope *scope = instruction->base.scope;
888 while (scope) {884 while (scope) {
889 if (scope->id == ScopeIdBlock) {885 if (scope->id == ScopeIdBlock) {
890 ScopeBlock *block_scope = (ScopeBlock *)scope;886 ScopeBlock *block_scope = (ScopeBlock *)scope;
...@@ -919,8 +915,8 @@ static bool ir_want_runtime_safety_scope(CodeGen *g, Scope *scope) {...@@ -919,8 +915,8 @@ static bool ir_want_runtime_safety_scope(CodeGen *g, Scope *scope) {
919 g->build_mode != BuildModeSmallRelease);915 g->build_mode != BuildModeSmallRelease);
920}916}
921917
922static bool ir_want_runtime_safety(CodeGen *g, IrInstruction *instruction) {918static bool ir_want_runtime_safety(CodeGen *g, IrInstGen *instruction) {
923 return ir_want_runtime_safety_scope(g, instruction->scope);919 return ir_want_runtime_safety_scope(g, instruction->base.scope);
924}920}
925921
926static Buf *panic_msg_buf(PanicMsgId msg_id) {922static Buf *panic_msg_buf(PanicMsgId msg_id) {
...@@ -1046,8 +1042,8 @@ static void gen_assertion_scope(CodeGen *g, PanicMsgId msg_id, Scope *source_sco...@@ -1046,8 +1042,8 @@ static void gen_assertion_scope(CodeGen *g, PanicMsgId msg_id, Scope *source_sco
1046 }1042 }
1047}1043}
10481044
1049static void gen_assertion(CodeGen *g, PanicMsgId msg_id, IrInstruction *source_instruction) {1045static void gen_assertion(CodeGen *g, PanicMsgId msg_id, IrInstGen *source_instruction) {
1050 return gen_assertion_scope(g, msg_id, source_instruction->scope);1046 return gen_assertion_scope(g, msg_id, source_instruction->base.scope);
1051}1047}
10521048
1053static LLVMValueRef get_stacksave_fn_val(CodeGen *g) {1049static LLVMValueRef get_stacksave_fn_val(CodeGen *g) {
...@@ -1761,7 +1757,7 @@ static void gen_var_debug_decl(CodeGen *g, ZigVar *var) {...@@ -1761,7 +1757,7 @@ static void gen_var_debug_decl(CodeGen *g, ZigVar *var) {
1761 LLVMGetInsertBlock(g->builder));1757 LLVMGetInsertBlock(g->builder));
1762}1758}
17631759
1764static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {1760static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstGen *instruction) {
1765 Error err;1761 Error err;
17661762
1767 bool value_has_bits;1763 bool value_has_bits;
...@@ -1772,8 +1768,8 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {...@@ -1772,8 +1768,8 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
1772 return nullptr;1768 return nullptr;
17731769
1774 if (!instruction->llvm_value) {1770 if (!instruction->llvm_value) {
1775 if (instruction->id == IrInstructionIdAwaitGen) {1771 if (instruction->id == IrInstGenIdAwait) {
1776 IrInstructionAwaitGen *await = reinterpret_cast<IrInstructionAwaitGen*>(instruction);1772 IrInstGenAwait *await = reinterpret_cast<IrInstGenAwait*>(instruction);
1777 if (await->result_loc != nullptr) {1773 if (await->result_loc != nullptr) {
1778 return get_handle_value(g, ir_llvm_value(g, await->result_loc),1774 return get_handle_value(g, ir_llvm_value(g, await->result_loc),
1779 await->result_loc->value->type->data.pointer.child_type, await->result_loc->value->type);1775 await->result_loc->value->type->data.pointer.child_type, await->result_loc->value->type);
...@@ -1856,9 +1852,9 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_...@@ -1856,9 +1852,9 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
1856 case FnWalkIdCall: {1852 case FnWalkIdCall: {
1857 if (src_i >= fn_walk->data.call.inst->arg_count)1853 if (src_i >= fn_walk->data.call.inst->arg_count)
1858 return false;1854 return false;
1859 IrInstruction *arg = fn_walk->data.call.inst->args[src_i];1855 IrInstGen *arg = fn_walk->data.call.inst->args[src_i];
1860 ty = arg->value->type;1856 ty = arg->value->type;
1861 source_node = arg->source_node;1857 source_node = arg->base.source_node;
1862 val = ir_llvm_value(g, arg);1858 val = ir_llvm_value(g, arg);
1863 break;1859 break;
1864 }1860 }
...@@ -2091,10 +2087,10 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {...@@ -2091,10 +2087,10 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) {
2091 return;2087 return;
2092 }2088 }
2093 if (fn_walk->id == FnWalkIdCall) {2089 if (fn_walk->id == FnWalkIdCall) {
2094 IrInstructionCallGen *instruction = fn_walk->data.call.inst;2090 IrInstGenCall *instruction = fn_walk->data.call.inst;
2095 bool is_var_args = fn_walk->data.call.is_var_args;2091 bool is_var_args = fn_walk->data.call.is_var_args;
2096 for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) {2092 for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) {
2097 IrInstruction *param_instruction = instruction->args[call_i];2093 IrInstGen *param_instruction = instruction->args[call_i];
2098 ZigType *param_type = param_instruction->value->type;2094 ZigType *param_type = param_instruction->value->type;
2099 if (is_var_args || type_has_bits(param_type)) {2095 if (is_var_args || type_has_bits(param_type)) {
2100 LLVMValueRef param_value = ir_llvm_value(g, param_instruction);2096 LLVMValueRef param_value = ir_llvm_value(g, param_instruction);
...@@ -2309,14 +2305,14 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) {...@@ -2309,14 +2305,14 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) {
2309 return fn_val;2305 return fn_val;
23102306
2311}2307}
2312static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *executable,2308static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutableGen *executable,
2313 IrInstructionSaveErrRetAddr *save_err_ret_addr_instruction)2309 IrInstGenSaveErrRetAddr *save_err_ret_addr_instruction)
2314{2310{
2315 assert(g->have_err_ret_tracing);2311 assert(g->have_err_ret_tracing);
23162312
2317 LLVMValueRef return_err_fn = get_return_err_fn(g);2313 LLVMValueRef return_err_fn = get_return_err_fn(g);
2318 bool is_llvm_alloca;2314 bool is_llvm_alloca;
2319 LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, save_err_ret_addr_instruction->base.scope,2315 LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, save_err_ret_addr_instruction->base.base.scope,
2320 &is_llvm_alloca);2316 &is_llvm_alloca);
2321 ZigLLVMBuildCall(g->builder, return_err_fn, &my_err_trace_val, 1,2317 ZigLLVMBuildCall(g->builder, return_err_fn, &my_err_trace_val, 1,
2322 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");2318 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
...@@ -2331,7 +2327,7 @@ static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *execut...@@ -2331,7 +2327,7 @@ static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *execut
2331 return nullptr;2327 return nullptr;
2332}2328}
23332329
2334static void gen_assert_resume_id(CodeGen *g, IrInstruction *source_instr, ResumeId resume_id, PanicMsgId msg_id,2330static void gen_assert_resume_id(CodeGen *g, IrInstGen *source_instr, ResumeId resume_id, PanicMsgId msg_id,
2335 LLVMBasicBlockRef end_bb)2331 LLVMBasicBlockRef end_bb)
2336{2332{
2337 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;2333 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
...@@ -2408,7 +2404,7 @@ static LLVMValueRef gen_maybe_atomic_op(CodeGen *g, LLVMAtomicRMWBinOp op, LLVMV...@@ -2408,7 +2404,7 @@ static LLVMValueRef gen_maybe_atomic_op(CodeGen *g, LLVMAtomicRMWBinOp op, LLVMV
2408 }2404 }
2409}2405}
24102406
2411static void gen_async_return(CodeGen *g, IrInstructionReturn *instruction) {2407static void gen_async_return(CodeGen *g, IrInstGenReturn *instruction) {
2412 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;2408 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
24132409
2414 ZigType *operand_type = (instruction->operand != nullptr) ? instruction->operand->value->type : nullptr;2410 ZigType *operand_type = (instruction->operand != nullptr) ? instruction->operand->value->type : nullptr;
...@@ -2487,7 +2483,7 @@ static void gen_async_return(CodeGen *g, IrInstructionReturn *instruction) {...@@ -2487,7 +2483,7 @@ static void gen_async_return(CodeGen *g, IrInstructionReturn *instruction) {
2487 frame_index_trace_arg(g, ret_type) + 1, "");2483 frame_index_trace_arg(g, ret_type) + 1, "");
2488 LLVMValueRef dest_trace_ptr = LLVMBuildLoad(g->builder, awaiter_trace_ptr_ptr, "");2484 LLVMValueRef dest_trace_ptr = LLVMBuildLoad(g->builder, awaiter_trace_ptr_ptr, "");
2489 bool is_llvm_alloca;2485 bool is_llvm_alloca;
2490 LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca);2486 LLVMValueRef my_err_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);
2491 LLVMValueRef args[] = { dest_trace_ptr, my_err_trace_val };2487 LLVMValueRef args[] = { dest_trace_ptr, my_err_trace_val };
2492 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,2488 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,
2493 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");2489 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
...@@ -2502,7 +2498,7 @@ static void gen_async_return(CodeGen *g, IrInstructionReturn *instruction) {...@@ -2502,7 +2498,7 @@ static void gen_async_return(CodeGen *g, IrInstructionReturn *instruction) {
2502 LLVMBuildRetVoid(g->builder);2498 LLVMBuildRetVoid(g->builder);
2503}2499}
25042500
2505static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrInstructionReturn *instruction) {2501static LLVMValueRef ir_render_return(CodeGen *g, IrExecutableGen *executable, IrInstGenReturn *instruction) {
2506 if (fn_is_async(g->cur_fn)) {2502 if (fn_is_async(g->cur_fn)) {
2507 gen_async_return(g, instruction);2503 gen_async_return(g, instruction);
2508 return nullptr;2504 return nullptr;
...@@ -2843,12 +2839,12 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast...@@ -2843,12 +2839,12 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast
28432839
2844}2840}
28452841
2846static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,2842static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutableGen *executable,
2847 IrInstructionBinOp *bin_op_instruction)2843 IrInstGenBinOp *bin_op_instruction)
2848{2844{
2849 IrBinOp op_id = bin_op_instruction->op_id;2845 IrBinOp op_id = bin_op_instruction->op_id;
2850 IrInstruction *op1 = bin_op_instruction->op1;2846 IrInstGen *op1 = bin_op_instruction->op1;
2851 IrInstruction *op2 = bin_op_instruction->op2;2847 IrInstGen *op2 = bin_op_instruction->op2;
28522848
2853 ZigType *operand_type = op1->value->type;2849 ZigType *operand_type = op1->value->type;
2854 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type;2850 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type;
...@@ -3053,8 +3049,8 @@ static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *in...@@ -3053,8 +3049,8 @@ static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *in
3053 }3049 }
3054}3050}
30553051
3056static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable,3052static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutableGen *executable,
3057 IrInstructionResizeSlice *instruction)3053 IrInstGenResizeSlice *instruction)
3058{3054{
3059 ZigType *actual_type = instruction->operand->value->type;3055 ZigType *actual_type = instruction->operand->value->type;
3060 ZigType *wanted_type = instruction->base.value->type;3056 ZigType *wanted_type = instruction->base.value->type;
...@@ -3121,11 +3117,17 @@ static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable,...@@ -3121,11 +3117,17 @@ static LLVMValueRef ir_render_resize_slice(CodeGen *g, IrExecutable *executable,
3121 return result_loc;3117 return result_loc;
3122}3118}
31233119
3124static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,3120static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutableGen *executable,
3125 IrInstructionCast *cast_instruction)3121 IrInstGenCast *cast_instruction)
3126{3122{
3123 Error err;
3127 ZigType *actual_type = cast_instruction->value->value->type;3124 ZigType *actual_type = cast_instruction->value->value->type;
3128 ZigType *wanted_type = cast_instruction->base.value->type;3125 ZigType *wanted_type = cast_instruction->base.value->type;
3126 bool wanted_type_has_bits;
3127 if ((err = type_has_bits2(g, wanted_type, &wanted_type_has_bits)))
3128 codegen_report_errors_and_exit(g);
3129 if (!wanted_type_has_bits)
3130 return nullptr;
3129 LLVMValueRef expr_val = ir_llvm_value(g, cast_instruction->value);3131 LLVMValueRef expr_val = ir_llvm_value(g, cast_instruction->value);
3130 ir_assert(expr_val, &cast_instruction->base);3132 ir_assert(expr_val, &cast_instruction->base);
31313133
...@@ -3199,8 +3201,8 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,...@@ -3199,8 +3201,8 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
3199 zig_unreachable();3201 zig_unreachable();
3200}3202}
32013203
3202static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *executable,3204static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutableGen *executable,
3203 IrInstructionPtrOfArrayToSlice *instruction)3205 IrInstGenPtrOfArrayToSlice *instruction)
3204{3206{
3205 ZigType *actual_type = instruction->operand->value->type;3207 ZigType *actual_type = instruction->operand->value->type;
3206 ZigType *slice_type = instruction->base.value->type;3208 ZigType *slice_type = instruction->base.value->type;
...@@ -3236,8 +3238,8 @@ static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *ex...@@ -3236,8 +3238,8 @@ static LLVMValueRef ir_render_ptr_of_array_to_slice(CodeGen *g, IrExecutable *ex
3236 return result_loc;3238 return result_loc;
3237}3239}
32383240
3239static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,3241static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutableGen *executable,
3240 IrInstructionPtrCastGen *instruction)3242 IrInstGenPtrCast *instruction)
3241{3243{
3242 ZigType *wanted_type = instruction->base.value->type;3244 ZigType *wanted_type = instruction->base.value->type;
3243 if (!type_has_bits(wanted_type)) {3245 if (!type_has_bits(wanted_type)) {
...@@ -3262,8 +3264,8 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,...@@ -3262,8 +3264,8 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable,
3262 return result_ptr;3264 return result_ptr;
3263}3265}
32643266
3265static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,3267static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutableGen *executable,
3266 IrInstructionBitCastGen *instruction)3268 IrInstGenBitCast *instruction)
3267{3269{
3268 ZigType *wanted_type = instruction->base.value->type;3270 ZigType *wanted_type = instruction->base.value->type;
3269 ZigType *actual_type = instruction->operand->value->type;3271 ZigType *actual_type = instruction->operand->value->type;
...@@ -3286,8 +3288,8 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,...@@ -3286,8 +3288,8 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable,
3286 }3288 }
3287}3289}
32883290
3289static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executable,3291static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutableGen *executable,
3290 IrInstructionWidenOrShorten *instruction)3292 IrInstGenWidenOrShorten *instruction)
3291{3293{
3292 ZigType *actual_type = instruction->target->value->type;3294 ZigType *actual_type = instruction->target->value->type;
3293 // TODO instead of this logic, use the Noop instruction to change the type from3295 // TODO instead of this logic, use the Noop instruction to change the type from
...@@ -3303,7 +3305,7 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa...@@ -3303,7 +3305,7 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa
3303 instruction->base.value->type, target_val);3305 instruction->base.value->type, target_val);
3304}3306}
33053307
3306static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutable *executable, IrInstructionIntToPtr *instruction) {3308static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutableGen *executable, IrInstGenIntToPtr *instruction) {
3307 ZigType *wanted_type = instruction->base.value->type;3309 ZigType *wanted_type = instruction->base.value->type;
3308 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);3310 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
33093311
...@@ -3341,13 +3343,13 @@ static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutable *executable, I...@@ -3341,13 +3343,13 @@ static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutable *executable, I
3341 return LLVMBuildIntToPtr(g->builder, target_val, get_llvm_type(g, wanted_type), "");3343 return LLVMBuildIntToPtr(g->builder, target_val, get_llvm_type(g, wanted_type), "");
3342}3344}
33433345
3344static LLVMValueRef ir_render_ptr_to_int(CodeGen *g, IrExecutable *executable, IrInstructionPtrToInt *instruction) {3346static LLVMValueRef ir_render_ptr_to_int(CodeGen *g, IrExecutableGen *executable, IrInstGenPtrToInt *instruction) {
3345 ZigType *wanted_type = instruction->base.value->type;3347 ZigType *wanted_type = instruction->base.value->type;
3346 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);3348 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
3347 return LLVMBuildPtrToInt(g->builder, target_val, get_llvm_type(g, wanted_type), "");3349 return LLVMBuildPtrToInt(g->builder, target_val, get_llvm_type(g, wanted_type), "");
3348}3350}
33493351
3350static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable, IrInstructionIntToEnum *instruction) {3352static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutableGen *executable, IrInstGenIntToEnum *instruction) {
3351 ZigType *wanted_type = instruction->base.value->type;3353 ZigType *wanted_type = instruction->base.value->type;
3352 assert(wanted_type->id == ZigTypeIdEnum);3354 assert(wanted_type->id == ZigTypeIdEnum);
3353 ZigType *tag_int_type = wanted_type->data.enumeration.tag_int_type;3355 ZigType *tag_int_type = wanted_type->data.enumeration.tag_int_type;
...@@ -3374,7 +3376,7 @@ static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable,...@@ -3374,7 +3376,7 @@ static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable,
3374 return tag_int_value;3376 return tag_int_value;
3375}3377}
33763378
3377static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, IrInstructionIntToErr *instruction) {3379static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutableGen *executable, IrInstGenIntToErr *instruction) {
3378 ZigType *wanted_type = instruction->base.value->type;3380 ZigType *wanted_type = instruction->base.value->type;
3379 assert(wanted_type->id == ZigTypeIdErrorSet);3381 assert(wanted_type->id == ZigTypeIdErrorSet);
33803382
...@@ -3391,7 +3393,7 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I...@@ -3391,7 +3393,7 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I
3391 return gen_widen_or_shorten(g, false, actual_type, g->err_tag_type, target_val);3393 return gen_widen_or_shorten(g, false, actual_type, g->err_tag_type, target_val);
3392}3394}
33933395
3394static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, IrInstructionErrToInt *instruction) {3396static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutableGen *executable, IrInstGenErrToInt *instruction) {
3395 ZigType *wanted_type = instruction->base.value->type;3397 ZigType *wanted_type = instruction->base.value->type;
3396 assert(wanted_type->id == ZigTypeIdInt);3398 assert(wanted_type->id == ZigTypeIdInt);
3397 assert(!wanted_type->data.integral.is_signed);3399 assert(!wanted_type->data.integral.is_signed);
...@@ -3417,8 +3419,8 @@ static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, I...@@ -3417,8 +3419,8 @@ static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, I
3417 }3419 }
3418}3420}
34193421
3420static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutable *executable,3422static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutableGen *executable,
3421 IrInstructionUnreachable *unreachable_instruction)3423 IrInstGenUnreachable *unreachable_instruction)
3422{3424{
3423 if (ir_want_runtime_safety(g, &unreachable_instruction->base)) {3425 if (ir_want_runtime_safety(g, &unreachable_instruction->base)) {
3424 gen_safety_crash(g, PanicMsgIdUnreachable);3426 gen_safety_crash(g, PanicMsgIdUnreachable);
...@@ -3428,8 +3430,8 @@ static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutable *executable,...@@ -3428,8 +3430,8 @@ static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutable *executable,
3428 return nullptr;3430 return nullptr;
3429}3431}
34303432
3431static LLVMValueRef ir_render_cond_br(CodeGen *g, IrExecutable *executable,3433static LLVMValueRef ir_render_cond_br(CodeGen *g, IrExecutableGen *executable,
3432 IrInstructionCondBr *cond_br_instruction)3434 IrInstGenCondBr *cond_br_instruction)
3433{3435{
3434 LLVMBuildCondBr(g->builder,3436 LLVMBuildCondBr(g->builder,
3435 ir_llvm_value(g, cond_br_instruction->condition),3437 ir_llvm_value(g, cond_br_instruction->condition),
...@@ -3438,51 +3440,56 @@ static LLVMValueRef ir_render_cond_br(CodeGen *g, IrExecutable *executable,...@@ -3438,51 +3440,56 @@ static LLVMValueRef ir_render_cond_br(CodeGen *g, IrExecutable *executable,
3438 return nullptr;3440 return nullptr;
3439}3441}
34403442
3441static LLVMValueRef ir_render_br(CodeGen *g, IrExecutable *executable, IrInstructionBr *br_instruction) {3443static LLVMValueRef ir_render_br(CodeGen *g, IrExecutableGen *executable, IrInstGenBr *br_instruction) {
3442 LLVMBuildBr(g->builder, br_instruction->dest_block->llvm_block);3444 LLVMBuildBr(g->builder, br_instruction->dest_block->llvm_block);
3443 return nullptr;3445 return nullptr;
3444}3446}
34453447
3446static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInstructionUnOp *un_op_instruction) {3448static LLVMValueRef ir_render_binary_not(CodeGen *g, IrExecutableGen *executable,
3447 IrUnOp op_id = un_op_instruction->op_id;3449 IrInstGenBinaryNot *inst)
3448 LLVMValueRef expr = ir_llvm_value(g, un_op_instruction->value);3450{
3449 ZigType *operand_type = un_op_instruction->value->value->type;3451 LLVMValueRef operand = ir_llvm_value(g, inst->operand);
3450 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ? operand_type->data.vector.elem_type : operand_type;3452 return LLVMBuildNot(g->builder, operand, "");
34513453}
3452 switch (op_id) {3454
3453 case IrUnOpInvalid:3455static LLVMValueRef ir_gen_negation(CodeGen *g, IrInstGen *inst, IrInstGen *operand, bool wrapping) {
3454 case IrUnOpOptional:3456 LLVMValueRef llvm_operand = ir_llvm_value(g, operand);
3455 case IrUnOpDereference:3457 ZigType *operand_type = operand->value->type;
3456 zig_unreachable();3458 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ?
3457 case IrUnOpNegation:3459 operand_type->data.vector.elem_type : operand_type;
3458 case IrUnOpNegationWrap:3460
3459 {3461 if (scalar_type->id == ZigTypeIdFloat) {
3460 if (scalar_type->id == ZigTypeIdFloat) {3462 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, inst));
3461 ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &un_op_instruction->base));3463 return LLVMBuildFNeg(g->builder, llvm_operand, "");
3462 return LLVMBuildFNeg(g->builder, expr, "");3464 } else if (scalar_type->id == ZigTypeIdInt) {
3463 } else if (scalar_type->id == ZigTypeIdInt) {3465 if (wrapping) {
3464 if (op_id == IrUnOpNegationWrap) {3466 return LLVMBuildNeg(g->builder, llvm_operand, "");
3465 return LLVMBuildNeg(g->builder, expr, "");3467 } else if (ir_want_runtime_safety(g, inst)) {
3466 } else if (ir_want_runtime_safety(g, &un_op_instruction->base)) {3468 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(llvm_operand));
3467 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(expr));3469 return gen_overflow_op(g, operand_type, AddSubMulSub, zero, llvm_operand);
3468 return gen_overflow_op(g, operand_type, AddSubMulSub, zero, expr);3470 } else if (scalar_type->data.integral.is_signed) {
3469 } else if (scalar_type->data.integral.is_signed) {3471 return LLVMBuildNSWNeg(g->builder, llvm_operand, "");
3470 return LLVMBuildNSWNeg(g->builder, expr, "");3472 } else {
3471 } else {3473 return LLVMBuildNUWNeg(g->builder, llvm_operand, "");
3472 return LLVMBuildNUWNeg(g->builder, expr, "");3474 }
3473 }3475 } else {
3474 } else {3476 zig_unreachable();
3475 zig_unreachable();
3476 }
3477 }
3478 case IrUnOpBinNot:
3479 return LLVMBuildNot(g->builder, expr, "");
3480 }3477 }
3478}
34813479
3482 zig_unreachable();3480static LLVMValueRef ir_render_negation(CodeGen *g, IrExecutableGen *executable,
3481 IrInstGenNegation *inst)
3482{
3483 return ir_gen_negation(g, &inst->base, inst->operand, false);
3484}
3485
3486static LLVMValueRef ir_render_negation_wrapping(CodeGen *g, IrExecutableGen *executable,
3487 IrInstGenNegationWrapping *inst)
3488{
3489 return ir_gen_negation(g, &inst->base, inst->operand, true);
3483}3490}
34843491
3485static LLVMValueRef ir_render_bool_not(CodeGen *g, IrExecutable *executable, IrInstructionBoolNot *instruction) {3492static LLVMValueRef ir_render_bool_not(CodeGen *g, IrExecutableGen *executable, IrInstGenBoolNot *instruction) {
3486 LLVMValueRef value = ir_llvm_value(g, instruction->value);3493 LLVMValueRef value = ir_llvm_value(g, instruction->value);
3487 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(value));3494 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(value));
3488 return LLVMBuildICmp(g->builder, LLVMIntEQ, value, zero, "");3495 return LLVMBuildICmp(g->builder, LLVMIntEQ, value, zero, "");
...@@ -3496,14 +3503,15 @@ static void render_decl_var(CodeGen *g, ZigVar *var) {...@@ -3496,14 +3503,15 @@ static void render_decl_var(CodeGen *g, ZigVar *var) {
3496 gen_var_debug_decl(g, var);3503 gen_var_debug_decl(g, var);
3497}3504}
34983505
3499static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable, IrInstructionDeclVarGen *instruction) {3506static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutableGen *executable, IrInstGenDeclVar *instruction) {
3500 instruction->var->ptr_instruction = instruction->var_ptr;3507 instruction->var->ptr_instruction = instruction->var_ptr;
3508 instruction->var->did_the_decl_codegen = true;
3501 render_decl_var(g, instruction->var);3509 render_decl_var(g, instruction->var);
3502 return nullptr;3510 return nullptr;
3503}3511}
35043512
3505static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable,3513static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutableGen *executable,
3506 IrInstructionLoadPtrGen *instruction)3514 IrInstGenLoadPtr *instruction)
3507{3515{
3508 ZigType *child_type = instruction->base.value->type;3516 ZigType *child_type = instruction->base.value->type;
3509 if (!type_has_bits(child_type))3517 if (!type_has_bits(child_type))
...@@ -3705,7 +3713,7 @@ static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_...@@ -3705,7 +3713,7 @@ static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_
3705 }3713 }
3706}3714}
37073715
3708static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, IrInstructionStorePtr *instruction) {3716static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutableGen *executable, IrInstGenStorePtr *instruction) {
3709 Error err;3717 Error err;
37103718
3711 ZigType *ptr_type = instruction->ptr->value->type;3719 ZigType *ptr_type = instruction->ptr->value->type;
...@@ -3715,7 +3723,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir...@@ -3715,7 +3723,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
3715 codegen_report_errors_and_exit(g);3723 codegen_report_errors_and_exit(g);
3716 if (!ptr_type_has_bits)3724 if (!ptr_type_has_bits)
3717 return nullptr;3725 return nullptr;
3718 if (instruction->ptr->ref_count == 0) {3726 if (instruction->ptr->base.ref_count == 0) {
3719 // In this case, this StorePtr instruction should be elided. Something happened like this:3727 // In this case, this StorePtr instruction should be elided. Something happened like this:
3720 // var t = true;3728 // var t = true;
3721 // const x = if (t) Num.Two else unreachable;3729 // const x = if (t) Num.Two else unreachable;
...@@ -3737,8 +3745,8 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir...@@ -3737,8 +3745,8 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
3737 return nullptr;3745 return nullptr;
3738}3746}
37393747
3740static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutable *executable,3748static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutableGen *executable,
3741 IrInstructionVectorStoreElem *instruction)3749 IrInstGenVectorStoreElem *instruction)
3742{3750{
3743 LLVMValueRef vector_ptr = ir_llvm_value(g, instruction->vector_ptr);3751 LLVMValueRef vector_ptr = ir_llvm_value(g, instruction->vector_ptr);
3744 LLVMValueRef index = ir_llvm_value(g, instruction->index);3752 LLVMValueRef index = ir_llvm_value(g, instruction->index);
...@@ -3750,7 +3758,7 @@ static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutable *execut...@@ -3750,7 +3758,7 @@ static LLVMValueRef ir_render_vector_store_elem(CodeGen *g, IrExecutable *execut
3750 return nullptr;3758 return nullptr;
3751}3759}
37523760
3753static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrInstructionVarPtr *instruction) {3761static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutableGen *executable, IrInstGenVarPtr *instruction) {
3754 if (instruction->base.value->special != ConstValSpecialRuntime)3762 if (instruction->base.value->special != ConstValSpecialRuntime)
3755 return ir_llvm_value(g, &instruction->base);3763 return ir_llvm_value(g, &instruction->base);
3756 ZigVar *var = instruction->var;3764 ZigVar *var = instruction->var;
...@@ -3762,8 +3770,8 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn...@@ -3762,8 +3770,8 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn
3762 }3770 }
3763}3771}
37643772
3765static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable,3773static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutableGen *executable,
3766 IrInstructionReturnPtr *instruction)3774 IrInstGenReturnPtr *instruction)
3767{3775{
3768 if (!type_has_bits(instruction->base.value->type))3776 if (!type_has_bits(instruction->base.value->type))
3769 return nullptr;3777 return nullptr;
...@@ -3771,7 +3779,7 @@ static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable,...@@ -3771,7 +3779,7 @@ static LLVMValueRef ir_render_return_ptr(CodeGen *g, IrExecutable *executable,
3771 return g->cur_ret_ptr;3779 return g->cur_ret_ptr;
3772}3780}
37733781
3774static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrInstructionElemPtr *instruction) {3782static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutableGen *executable, IrInstGenElemPtr *instruction) {
3775 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr);3783 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr);
3776 ZigType *array_ptr_type = instruction->array_ptr->value->type;3784 ZigType *array_ptr_type = instruction->array_ptr->value->type;
3777 assert(array_ptr_type->id == ZigTypeIdPointer);3785 assert(array_ptr_type->id == ZigTypeIdPointer);
...@@ -3947,7 +3955,7 @@ static void render_async_spills(CodeGen *g) {...@@ -3947,7 +3955,7 @@ static void render_async_spills(CodeGen *g) {
3947 ZigType *frame_type = g->cur_fn->frame_type->data.frame.locals_struct;3955 ZigType *frame_type = g->cur_fn->frame_type->data.frame.locals_struct;
39483956
3949 for (size_t alloca_i = 0; alloca_i < g->cur_fn->alloca_gen_list.length; alloca_i += 1) {3957 for (size_t alloca_i = 0; alloca_i < g->cur_fn->alloca_gen_list.length; alloca_i += 1) {
3950 IrInstructionAllocaGen *instruction = g->cur_fn->alloca_gen_list.at(alloca_i);3958 IrInstGenAlloca *instruction = g->cur_fn->alloca_gen_list.at(alloca_i);
3951 if (instruction->field_index == SIZE_MAX)3959 if (instruction->field_index == SIZE_MAX)
3952 continue;3960 continue;
39533961
...@@ -3966,7 +3974,7 @@ static void render_async_var_decls(CodeGen *g, Scope *scope) {...@@ -3966,7 +3974,7 @@ static void render_async_var_decls(CodeGen *g, Scope *scope) {
3966 return;3974 return;
3967 case ScopeIdVarDecl: {3975 case ScopeIdVarDecl: {
3968 ZigVar *var = reinterpret_cast<ScopeVarDecl *>(scope)->var;3976 ZigVar *var = reinterpret_cast<ScopeVarDecl *>(scope)->var;
3969 if (var->ptr_instruction != nullptr) {3977 if (var->did_the_decl_codegen) {
3970 render_decl_var(g, var);3978 render_decl_var(g, var);
3971 }3979 }
3972 // fallthrough3980 // fallthrough
...@@ -4014,7 +4022,7 @@ static void gen_init_stack_trace(CodeGen *g, LLVMValueRef trace_field_ptr, LLVMV...@@ -4014,7 +4022,7 @@ static void gen_init_stack_trace(CodeGen *g, LLVMValueRef trace_field_ptr, LLVMV
4014 LLVMBuildStore(g->builder, LLVMConstInt(usize_type_ref, stack_trace_ptr_count, false), addrs_len_ptr);4022 LLVMBuildStore(g->builder, LLVMConstInt(usize_type_ref, stack_trace_ptr_count, false), addrs_len_ptr);
4015}4023}
40164024
4017static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstructionCallGen *instruction) {4025static LLVMValueRef ir_render_call(CodeGen *g, IrExecutableGen *executable, IrInstGenCall *instruction) {
4018 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;4026 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
40194027
4020 LLVMValueRef fn_val;4028 LLVMValueRef fn_val;
...@@ -4149,7 +4157,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -4149,7 +4157,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
4149 LLVMValueRef err_ret_trace_ptr_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc,4157 LLVMValueRef err_ret_trace_ptr_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc,
4150 frame_index_trace_arg(g, src_return_type) + 1, "");4158 frame_index_trace_arg(g, src_return_type) + 1, "");
4151 bool is_llvm_alloca;4159 bool is_llvm_alloca;
4152 LLVMValueRef my_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope,4160 LLVMValueRef my_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope,
4153 &is_llvm_alloca);4161 &is_llvm_alloca);
4154 LLVMBuildStore(g->builder, my_err_ret_trace_val, err_ret_trace_ptr_ptr);4162 LLVMBuildStore(g->builder, my_err_ret_trace_val, err_ret_trace_ptr_ptr);
4155 }4163 }
...@@ -4208,7 +4216,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -4208,7 +4216,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
4208 gen_init_stack_trace(g, trace_field_ptr, addrs_field_ptr);4216 gen_init_stack_trace(g, trace_field_ptr, addrs_field_ptr);
42094217
4210 bool is_llvm_alloca;4218 bool is_llvm_alloca;
4211 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca));4219 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca));
4212 }4220 }
4213 }4221 }
4214 } else {4222 } else {
...@@ -4217,7 +4225,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -4217,7 +4225,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
4217 }4225 }
4218 if (prefix_arg_err_ret_stack) {4226 if (prefix_arg_err_ret_stack) {
4219 bool is_llvm_alloca;4227 bool is_llvm_alloca;
4220 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca));4228 gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca));
4221 }4229 }
4222 }4230 }
4223 FnWalk fn_walk = {};4231 FnWalk fn_walk = {};
...@@ -4327,13 +4335,13 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -4327,13 +4335,13 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
43274335
4328 LLVMPositionBuilderAtEnd(g->builder, call_bb);4336 LLVMPositionBuilderAtEnd(g->builder, call_bb);
4329 gen_assert_resume_id(g, &instruction->base, ResumeIdReturn, PanicMsgIdResumedAnAwaitingFn, nullptr);4337 gen_assert_resume_id(g, &instruction->base, ResumeIdReturn, PanicMsgIdResumedAnAwaitingFn, nullptr);
4330 render_async_var_decls(g, instruction->base.scope);4338 render_async_var_decls(g, instruction->base.base.scope);
43314339
4332 if (!type_has_bits(src_return_type))4340 if (!type_has_bits(src_return_type))
4333 return nullptr;4341 return nullptr;
43344342
4335 if (result_loc != nullptr) {4343 if (result_loc != nullptr) {
4336 if (instruction->result_loc->id == IrInstructionIdReturnPtr) {4344 if (instruction->result_loc->id == IrInstGenIdReturnPtr) {
4337 instruction->base.spill = nullptr;4345 instruction->base.spill = nullptr;
4338 return g->cur_ret_ptr;4346 return g->cur_ret_ptr;
4339 } else {4347 } else {
...@@ -4393,8 +4401,8 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr...@@ -4393,8 +4401,8 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
4393 }4401 }
4394}4402}
43954403
4396static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executable,4404static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutableGen *executable,
4397 IrInstructionStructFieldPtr *instruction)4405 IrInstGenStructFieldPtr *instruction)
4398{4406{
4399 Error err;4407 Error err;
44004408
...@@ -4444,8 +4452,8 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa...@@ -4444,8 +4452,8 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa
4444 return field_ptr_val;4452 return field_ptr_val;
4445}4453}
44464454
4447static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executable,4455static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutableGen *executable,
4448 IrInstructionUnionFieldPtr *instruction)4456 IrInstGenUnionFieldPtr *instruction)
4449{4457{
4450 if (instruction->base.value->special != ConstValSpecialRuntime)4458 if (instruction->base.value->special != ConstValSpecialRuntime)
4451 return nullptr;4459 return nullptr;
...@@ -4544,8 +4552,8 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_...@@ -4544,8 +4552,8 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_
4544 return SIZE_MAX;4552 return SIZE_MAX;
4545}4553}
45464554
4547static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutable *executable, IrInstructionAsmGen *instruction) {4555static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutableGen *executable, IrInstGenAsm *instruction) {
4548 AstNode *asm_node = instruction->base.source_node;4556 AstNode *asm_node = instruction->base.base.source_node;
4549 assert(asm_node->type == NodeTypeAsmExpr);4557 assert(asm_node->type == NodeTypeAsmExpr);
4550 AstNodeAsmExpr *asm_expr = &asm_node->data.asm_expr;4558 AstNodeAsmExpr *asm_expr = &asm_node->data.asm_expr;
45514559
...@@ -4629,7 +4637,7 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutable *executable, IrIn...@@ -4629,7 +4637,7 @@ static LLVMValueRef ir_render_asm_gen(CodeGen *g, IrExecutable *executable, IrIn
4629 for (size_t i = 0; i < asm_expr->input_list.length; i += 1, total_index += 1, param_index += 1) {4637 for (size_t i = 0; i < asm_expr->input_list.length; i += 1, total_index += 1, param_index += 1) {
4630 AsmInput *asm_input = asm_expr->input_list.at(i);4638 AsmInput *asm_input = asm_expr->input_list.at(i);
4631 buf_replace(asm_input->constraint, ',', '|');4639 buf_replace(asm_input->constraint, ',', '|');
4632 IrInstruction *ir_input = instruction->input_list[i];4640 IrInstGen *ir_input = instruction->input_list[i];
4633 buf_append_buf(&constraint_buf, asm_input->constraint);4641 buf_append_buf(&constraint_buf, asm_input->constraint);
4634 if (total_index + 1 < total_constraint_count) {4642 if (total_index + 1 < total_constraint_count) {
4635 buf_append_char(&constraint_buf, ',');4643 buf_append_char(&constraint_buf, ',');
...@@ -4692,14 +4700,14 @@ static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueR...@@ -4692,14 +4700,14 @@ static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueR
4692 return gen_load_untyped(g, maybe_field_ptr, 0, false, "");4700 return gen_load_untyped(g, maybe_field_ptr, 0, false, "");
4693}4701}
46944702
4695static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutable *executable,4703static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutableGen *executable,
4696 IrInstructionTestNonNull *instruction)4704 IrInstGenTestNonNull *instruction)
4697{4705{
4698 return gen_non_null_bit(g, instruction->value->value->type, ir_llvm_value(g, instruction->value));4706 return gen_non_null_bit(g, instruction->value->value->type, ir_llvm_value(g, instruction->value));
4699}4707}
47004708
4701static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutable *executable,4709static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutableGen *executable,
4702 IrInstructionOptionalUnwrapPtr *instruction)4710 IrInstGenOptionalUnwrapPtr *instruction)
4703{4711{
4704 if (instruction->base.value->special != ConstValSpecialRuntime)4712 if (instruction->base.value->special != ConstValSpecialRuntime)
4705 return nullptr;4713 return nullptr;
...@@ -4723,6 +4731,10 @@ static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutable *exec...@@ -4723,6 +4731,10 @@ static LLVMValueRef ir_render_optional_unwrap_ptr(CodeGen *g, IrExecutable *exec
4723 LLVMPositionBuilderAtEnd(g->builder, ok_block);4731 LLVMPositionBuilderAtEnd(g->builder, ok_block);
4724 }4732 }
4725 if (!type_has_bits(child_type)) {4733 if (!type_has_bits(child_type)) {
4734 if (instruction->initializing) {
4735 LLVMValueRef non_null_bit = LLVMConstInt(LLVMInt1Type(), 1, false);
4736 gen_store_untyped(g, non_null_bit, base_ptr, 0, false);
4737 }
4726 return nullptr;4738 return nullptr;
4727 } else {4739 } else {
4728 bool is_scalar = !handle_is_ptr(maybe_type);4740 bool is_scalar = !handle_is_ptr(maybe_type);
...@@ -4801,7 +4813,7 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, ZigType *expr_type, BuiltinFn...@@ -4801,7 +4813,7 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, ZigType *expr_type, BuiltinFn
4801 return fn_val;4813 return fn_val;
4802}4814}
48034815
4804static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstructionClz *instruction) {4816static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutableGen *executable, IrInstGenClz *instruction) {
4805 ZigType *int_type = instruction->op->value->type;4817 ZigType *int_type = instruction->op->value->type;
4806 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdClz);4818 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdClz);
4807 LLVMValueRef operand = ir_llvm_value(g, instruction->op);4819 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
...@@ -4813,7 +4825,7 @@ static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstru...@@ -4813,7 +4825,7 @@ static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstru
4813 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);4825 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);
4814}4826}
48154827
4816static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstructionCtz *instruction) {4828static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutableGen *executable, IrInstGenCtz *instruction) {
4817 ZigType *int_type = instruction->op->value->type;4829 ZigType *int_type = instruction->op->value->type;
4818 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdCtz);4830 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdCtz);
4819 LLVMValueRef operand = ir_llvm_value(g, instruction->op);4831 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
...@@ -4825,7 +4837,7 @@ static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstru...@@ -4825,7 +4837,7 @@ static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstru
4825 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);4837 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);
4826}4838}
48274839
4828static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executable, IrInstructionShuffleVector *instruction) {4840static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutableGen *executable, IrInstGenShuffleVector *instruction) {
4829 uint64_t len_a = instruction->a->value->type->data.vector.len;4841 uint64_t len_a = instruction->a->value->type->data.vector.len;
4830 uint64_t len_mask = instruction->mask->value->type->data.vector.len;4842 uint64_t len_mask = instruction->mask->value->type->data.vector.len;
48314843
...@@ -4834,7 +4846,7 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executabl...@@ -4834,7 +4846,7 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executabl
4834 // when changing code, so Zig uses negative numbers to index the4846 // when changing code, so Zig uses negative numbers to index the
4835 // second vector. These start at -1 and go down, and are easiest to use4847 // second vector. These start at -1 and go down, and are easiest to use
4836 // with the ~ operator. Here we convert between the two formats.4848 // with the ~ operator. Here we convert between the two formats.
4837 IrInstruction *mask = instruction->mask;4849 IrInstGen *mask = instruction->mask;
4838 LLVMValueRef *values = allocate<LLVMValueRef>(len_mask);4850 LLVMValueRef *values = allocate<LLVMValueRef>(len_mask);
4839 for (uint64_t i = 0; i < len_mask; i++) {4851 for (uint64_t i = 0; i < len_mask; i++) {
4840 if (mask->value->data.x_array.data.s_none.elements[i].special == ConstValSpecialUndef) {4852 if (mask->value->data.x_array.data.s_none.elements[i].special == ConstValSpecialUndef) {
...@@ -4855,7 +4867,7 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executabl...@@ -4855,7 +4867,7 @@ static LLVMValueRef ir_render_shuffle_vector(CodeGen *g, IrExecutable *executabl
4855 llvm_mask_value, "");4867 llvm_mask_value, "");
4856}4868}
48574869
4858static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutable *executable, IrInstructionSplatGen *instruction) {4870static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutableGen *executable, IrInstGenSplat *instruction) {
4859 ZigType *result_type = instruction->base.value->type;4871 ZigType *result_type = instruction->base.value->type;
4860 ir_assert(result_type->id == ZigTypeIdVector, &instruction->base);4872 ir_assert(result_type->id == ZigTypeIdVector, &instruction->base);
4861 uint32_t len = result_type->data.vector.len;4873 uint32_t len = result_type->data.vector.len;
...@@ -4867,7 +4879,7 @@ static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutable *executable, IrInst...@@ -4867,7 +4879,7 @@ static LLVMValueRef ir_render_splat(CodeGen *g, IrExecutable *executable, IrInst
4867 return LLVMBuildShuffleVector(g->builder, op_vector, undef_vector, LLVMConstNull(mask_llvm_type), "");4879 return LLVMBuildShuffleVector(g->builder, op_vector, undef_vector, LLVMConstNull(mask_llvm_type), "");
4868}4880}
48694881
4870static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutable *executable, IrInstructionPopCount *instruction) {4882static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutableGen *executable, IrInstGenPopCount *instruction) {
4871 ZigType *int_type = instruction->op->value->type;4883 ZigType *int_type = instruction->op->value->type;
4872 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdPopCount);4884 LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdPopCount);
4873 LLVMValueRef operand = ir_llvm_value(g, instruction->op);4885 LLVMValueRef operand = ir_llvm_value(g, instruction->op);
...@@ -4875,7 +4887,7 @@ static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutable *executable, Ir...@@ -4875,7 +4887,7 @@ static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutable *executable, Ir
4875 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);4887 return gen_widen_or_shorten(g, false, int_type, instruction->base.value->type, wrong_size_int);
4876}4888}
48774889
4878static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, IrInstructionSwitchBr *instruction) {4890static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutableGen *executable, IrInstGenSwitchBr *instruction) {
4879 ZigType *target_type = instruction->target_value->value->type;4891 ZigType *target_type = instruction->target_value->value->type;
4880 LLVMBasicBlockRef else_block = instruction->else_block->llvm_block;4892 LLVMBasicBlockRef else_block = instruction->else_block->llvm_block;
48814893
...@@ -4889,7 +4901,7 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, Ir...@@ -4889,7 +4901,7 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, Ir
4889 (unsigned)instruction->case_count);4901 (unsigned)instruction->case_count);
48904902
4891 for (size_t i = 0; i < instruction->case_count; i += 1) {4903 for (size_t i = 0; i < instruction->case_count; i += 1) {
4892 IrInstructionSwitchBrCase *this_case = &instruction->cases[i];4904 IrInstGenSwitchBrCase *this_case = &instruction->cases[i];
48934905
4894 LLVMValueRef case_value = ir_llvm_value(g, this_case->value);4906 LLVMValueRef case_value = ir_llvm_value(g, this_case->value);
4895 if (target_type->id == ZigTypeIdPointer) {4907 if (target_type->id == ZigTypeIdPointer) {
...@@ -4903,7 +4915,7 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, Ir...@@ -4903,7 +4915,7 @@ static LLVMValueRef ir_render_switch_br(CodeGen *g, IrExecutable *executable, Ir
4903 return nullptr;4915 return nullptr;
4904}4916}
49054917
4906static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstructionPhi *instruction) {4918static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutableGen *executable, IrInstGenPhi *instruction) {
4907 if (!type_has_bits(instruction->base.value->type))4919 if (!type_has_bits(instruction->base.value->type))
4908 return nullptr;4920 return nullptr;
49094921
...@@ -4925,7 +4937,7 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstru...@@ -4925,7 +4937,7 @@ static LLVMValueRef ir_render_phi(CodeGen *g, IrExecutable *executable, IrInstru
4925 return phi;4937 return phi;
4926}4938}
49274939
4928static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutable *executable, IrInstructionRefGen *instruction) {4940static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutableGen *executable, IrInstGenRef *instruction) {
4929 if (!type_has_bits(instruction->base.value->type)) {4941 if (!type_has_bits(instruction->base.value->type)) {
4930 return nullptr;4942 return nullptr;
4931 }4943 }
...@@ -4939,7 +4951,7 @@ static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutable *executable, IrInstru...@@ -4939,7 +4951,7 @@ static LLVMValueRef ir_render_ref(CodeGen *g, IrExecutable *executable, IrInstru
4939 }4951 }
4940}4952}
49414953
4942static LLVMValueRef ir_render_err_name(CodeGen *g, IrExecutable *executable, IrInstructionErrName *instruction) {4954static LLVMValueRef ir_render_err_name(CodeGen *g, IrExecutableGen *executable, IrInstGenErrName *instruction) {
4943 assert(g->generate_error_name_table);4955 assert(g->generate_error_name_table);
49444956
4945 if (g->errors_by_index.length == 1) {4957 if (g->errors_by_index.length == 1) {
...@@ -5060,13 +5072,13 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {...@@ -5060,13 +5072,13 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {
5060 return fn_val;5072 return fn_val;
5061}5073}
50625074
5063static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable,5075static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutableGen *executable,
5064 IrInstructionTagName *instruction)5076 IrInstGenTagName *instruction)
5065{5077{
5066 ZigType *enum_type = instruction->target->value->type;5078 ZigType *enum_type = instruction->target->value->type;
5067 assert(enum_type->id == ZigTypeIdEnum);5079 assert(enum_type->id == ZigTypeIdEnum);
5068 if (enum_type->data.enumeration.non_exhaustive) {5080 if (enum_type->data.enumeration.non_exhaustive) {
5069 add_node_error(g, instruction->base.source_node,5081 add_node_error(g, instruction->base.base.source_node,
5070 buf_sprintf("TODO @tagName on non-exhaustive enum https://github.com/ziglang/zig/issues/3991"));5082 buf_sprintf("TODO @tagName on non-exhaustive enum https://github.com/ziglang/zig/issues/3991"));
5071 codegen_report_errors_and_exit(g);5083 codegen_report_errors_and_exit(g);
5072 }5084 }
...@@ -5078,8 +5090,8 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable...@@ -5078,8 +5090,8 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable
5078 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");5090 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
5079}5091}
50805092
5081static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executable,5093static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutableGen *executable,
5082 IrInstructionFieldParentPtr *instruction)5094 IrInstGenFieldParentPtr *instruction)
5083{5095{
5084 ZigType *container_ptr_type = instruction->base.value->type;5096 ZigType *container_ptr_type = instruction->base.value->type;
5085 assert(container_ptr_type->id == ZigTypeIdPointer);5097 assert(container_ptr_type->id == ZigTypeIdPointer);
...@@ -5105,7 +5117,7 @@ static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executa...@@ -5105,7 +5117,7 @@ static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executa
5105 }5117 }
5106}5118}
51075119
5108static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, IrInstructionAlignCast *instruction) {5120static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutableGen *executable, IrInstGenAlignCast *instruction) {
5109 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);5121 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
5110 assert(target_val);5122 assert(target_val);
51115123
...@@ -5168,11 +5180,11 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I...@@ -5168,11 +5180,11 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I
5168 return target_val;5180 return target_val;
5169}5181}
51705182
5171static LLVMValueRef ir_render_error_return_trace(CodeGen *g, IrExecutable *executable,5183static LLVMValueRef ir_render_error_return_trace(CodeGen *g, IrExecutableGen *executable,
5172 IrInstructionErrorReturnTrace *instruction)5184 IrInstGenErrorReturnTrace *instruction)
5173{5185{
5174 bool is_llvm_alloca;5186 bool is_llvm_alloca;
5175 LLVMValueRef cur_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca);5187 LLVMValueRef cur_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);
5176 if (cur_err_ret_trace_val == nullptr) {5188 if (cur_err_ret_trace_val == nullptr) {
5177 return LLVMConstNull(get_llvm_type(g, ptr_to_stack_trace_type(g)));5189 return LLVMConstNull(get_llvm_type(g, ptr_to_stack_trace_type(g)));
5178 }5190 }
...@@ -5210,7 +5222,7 @@ static enum ZigLLVM_AtomicRMWBinOp to_ZigLLVMAtomicRMWBinOp(AtomicRmwOp op, bool...@@ -5210,7 +5222,7 @@ static enum ZigLLVM_AtomicRMWBinOp to_ZigLLVMAtomicRMWBinOp(AtomicRmwOp op, bool
5210 zig_unreachable();5222 zig_unreachable();
5211}5223}
52125224
5213static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrInstructionCmpxchgGen *instruction) {5225static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutableGen *executable, IrInstGenCmpxchg *instruction) {
5214 LLVMValueRef ptr_val = ir_llvm_value(g, instruction->ptr);5226 LLVMValueRef ptr_val = ir_llvm_value(g, instruction->ptr);
5215 LLVMValueRef cmp_val = ir_llvm_value(g, instruction->cmp_value);5227 LLVMValueRef cmp_val = ir_llvm_value(g, instruction->cmp_value);
5216 LLVMValueRef new_val = ir_llvm_value(g, instruction->new_value);5228 LLVMValueRef new_val = ir_llvm_value(g, instruction->new_value);
...@@ -5251,13 +5263,13 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn...@@ -5251,13 +5263,13 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn
5251 return result_loc;5263 return result_loc;
5252}5264}
52535265
5254static LLVMValueRef ir_render_fence(CodeGen *g, IrExecutable *executable, IrInstructionFence *instruction) {5266static LLVMValueRef ir_render_fence(CodeGen *g, IrExecutableGen *executable, IrInstGenFence *instruction) {
5255 LLVMAtomicOrdering atomic_order = to_LLVMAtomicOrdering(instruction->order);5267 LLVMAtomicOrdering atomic_order = to_LLVMAtomicOrdering(instruction->order);
5256 LLVMBuildFence(g->builder, atomic_order, false, "");5268 LLVMBuildFence(g->builder, atomic_order, false, "");
5257 return nullptr;5269 return nullptr;
5258}5270}
52595271
5260static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrInstructionTruncate *instruction) {5272static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutableGen *executable, IrInstGenTruncate *instruction) {
5261 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);5273 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
5262 ZigType *dest_type = instruction->base.value->type;5274 ZigType *dest_type = instruction->base.value->type;
5263 ZigType *src_type = instruction->target->value->type;5275 ZigType *src_type = instruction->target->value->type;
...@@ -5272,7 +5284,7 @@ static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrI...@@ -5272,7 +5284,7 @@ static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrI
5272 }5284 }
5273}5285}
52745286
5275static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrInstructionMemset *instruction) {5287static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutableGen *executable, IrInstGenMemset *instruction) {
5276 LLVMValueRef dest_ptr = ir_llvm_value(g, instruction->dest_ptr);5288 LLVMValueRef dest_ptr = ir_llvm_value(g, instruction->dest_ptr);
5277 LLVMValueRef len_val = ir_llvm_value(g, instruction->count);5289 LLVMValueRef len_val = ir_llvm_value(g, instruction->count);
52785290
...@@ -5284,7 +5296,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns...@@ -5284,7 +5296,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns
52845296
5285 bool val_is_undef = value_is_all_undef(g, instruction->byte->value);5297 bool val_is_undef = value_is_all_undef(g, instruction->byte->value);
5286 LLVMValueRef fill_char;5298 LLVMValueRef fill_char;
5287 if (val_is_undef && ir_want_runtime_safety_scope(g, instruction->base.scope)) {5299 if (val_is_undef && ir_want_runtime_safety_scope(g, instruction->base.base.scope)) {
5288 fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false);5300 fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false);
5289 } else {5301 } else {
5290 fill_char = ir_llvm_value(g, instruction->byte);5302 fill_char = ir_llvm_value(g, instruction->byte);
...@@ -5298,7 +5310,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns...@@ -5298,7 +5310,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns
5298 return nullptr;5310 return nullptr;
5299}5311}
53005312
5301static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrInstructionMemcpy *instruction) {5313static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutableGen *executable, IrInstGenMemcpy *instruction) {
5302 LLVMValueRef dest_ptr = ir_llvm_value(g, instruction->dest_ptr);5314 LLVMValueRef dest_ptr = ir_llvm_value(g, instruction->dest_ptr);
5303 LLVMValueRef src_ptr = ir_llvm_value(g, instruction->src_ptr);5315 LLVMValueRef src_ptr = ir_llvm_value(g, instruction->src_ptr);
5304 LLVMValueRef len_val = ir_llvm_value(g, instruction->count);5316 LLVMValueRef len_val = ir_llvm_value(g, instruction->count);
...@@ -5320,7 +5332,7 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns...@@ -5320,7 +5332,7 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns
5320 return nullptr;5332 return nullptr;
5321}5333}
53225334
5323static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInstructionSliceGen *instruction) {5335static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutableGen *executable, IrInstGenSlice *instruction) {
5324 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->ptr);5336 LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->ptr);
5325 ZigType *array_ptr_type = instruction->ptr->value->type;5337 ZigType *array_ptr_type = instruction->ptr->value->type;
5326 assert(array_ptr_type->id == ZigTypeIdPointer);5338 assert(array_ptr_type->id == ZigTypeIdPointer);
...@@ -5482,13 +5494,13 @@ static LLVMValueRef get_trap_fn_val(CodeGen *g) {...@@ -5482,13 +5494,13 @@ static LLVMValueRef get_trap_fn_val(CodeGen *g) {
5482}5494}
54835495
54845496
5485static LLVMValueRef ir_render_breakpoint(CodeGen *g, IrExecutable *executable, IrInstructionBreakpoint *instruction) {5497static LLVMValueRef ir_render_breakpoint(CodeGen *g, IrExecutableGen *executable, IrInstGenBreakpoint *instruction) {
5486 LLVMBuildCall(g->builder, get_trap_fn_val(g), nullptr, 0, "");5498 LLVMBuildCall(g->builder, get_trap_fn_val(g), nullptr, 0, "");
5487 return nullptr;5499 return nullptr;
5488}5500}
54895501
5490static LLVMValueRef ir_render_return_address(CodeGen *g, IrExecutable *executable,5502static LLVMValueRef ir_render_return_address(CodeGen *g, IrExecutableGen *executable,
5491 IrInstructionReturnAddress *instruction)5503 IrInstGenReturnAddress *instruction)
5492{5504{
5493 LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->llvm_type);5505 LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->llvm_type);
5494 LLVMValueRef ptr_val = LLVMBuildCall(g->builder, get_return_address_fn_val(g), &zero, 1, "");5506 LLVMValueRef ptr_val = LLVMBuildCall(g->builder, get_return_address_fn_val(g), &zero, 1, "");
...@@ -5509,19 +5521,19 @@ static LLVMValueRef get_frame_address_fn_val(CodeGen *g) {...@@ -5509,19 +5521,19 @@ static LLVMValueRef get_frame_address_fn_val(CodeGen *g) {
5509 return g->frame_address_fn_val;5521 return g->frame_address_fn_val;
5510}5522}
55115523
5512static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutable *executable,5524static LLVMValueRef ir_render_frame_address(CodeGen *g, IrExecutableGen *executable,
5513 IrInstructionFrameAddress *instruction)5525 IrInstGenFrameAddress *instruction)
5514{5526{
5515 LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->llvm_type);5527 LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->llvm_type);
5516 LLVMValueRef ptr_val = LLVMBuildCall(g->builder, get_frame_address_fn_val(g), &zero, 1, "");5528 LLVMValueRef ptr_val = LLVMBuildCall(g->builder, get_frame_address_fn_val(g), &zero, 1, "");
5517 return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->llvm_type, "");5529 return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->llvm_type, "");
5518}5530}
55195531
5520static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutable *executable, IrInstructionFrameHandle *instruction) {5532static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutableGen *executable, IrInstGenFrameHandle *instruction) {
5521 return g->cur_frame_ptr;5533 return g->cur_frame_ptr;
5522}5534}
55235535
5524static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp *instruction) {5536static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstGenOverflowOp *instruction) {
5525 ZigType *int_type = instruction->result_ptr_type;5537 ZigType *int_type = instruction->result_ptr_type;
5526 assert(int_type->id == ZigTypeIdInt);5538 assert(int_type->id == ZigTypeIdInt);
55275539
...@@ -5546,7 +5558,7 @@ static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp...@@ -5546,7 +5558,7 @@ static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp
5546 return overflow_bit;5558 return overflow_bit;
5547}5559}
55485560
5549static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable, IrInstructionOverflowOp *instruction) {5561static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutableGen *executable, IrInstGenOverflowOp *instruction) {
5550 AddSubMul add_sub_mul;5562 AddSubMul add_sub_mul;
5551 switch (instruction->op) {5563 switch (instruction->op) {
5552 case IrOverflowOpAdd:5564 case IrOverflowOpAdd:
...@@ -5584,7 +5596,7 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,...@@ -5584,7 +5596,7 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable,
5584 return overflow_bit;5596 return overflow_bit;
5585}5597}
55865598
5587static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrInstructionTestErrGen *instruction) {5599static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutableGen *executable, IrInstGenTestErr *instruction) {
5588 ZigType *err_union_type = instruction->err_union->value->type;5600 ZigType *err_union_type = instruction->err_union->value->type;
5589 ZigType *payload_type = err_union_type->data.error_union.payload_type;5601 ZigType *payload_type = err_union_type->data.error_union.payload_type;
5590 LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->err_union);5602 LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->err_union);
...@@ -5601,8 +5613,8 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI...@@ -5601,8 +5613,8 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI
5601 return LLVMBuildICmp(g->builder, LLVMIntNE, err_val, zero, "");5613 return LLVMBuildICmp(g->builder, LLVMIntNE, err_val, zero, "");
5602}5614}
56035615
5604static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable,5616static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutableGen *executable,
5605 IrInstructionUnwrapErrCode *instruction)5617 IrInstGenUnwrapErrCode *instruction)
5606{5618{
5607 if (instruction->base.value->special != ConstValSpecialRuntime)5619 if (instruction->base.value->special != ConstValSpecialRuntime)
5608 return nullptr;5620 return nullptr;
...@@ -5621,8 +5633,8 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab...@@ -5621,8 +5633,8 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab
5621 }5633 }
5622}5634}
56235635
5624static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable,5636static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutableGen *executable,
5625 IrInstructionUnwrapErrPayload *instruction)5637 IrInstGenUnwrapErrPayload *instruction)
5626{5638{
5627 Error err;5639 Error err;
56285640
...@@ -5665,7 +5677,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu...@@ -5665,7 +5677,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
5665 LLVMBuildCondBr(g->builder, cond_val, ok_block, err_block);5677 LLVMBuildCondBr(g->builder, cond_val, ok_block, err_block);
56665678
5667 LLVMPositionBuilderAtEnd(g->builder, err_block);5679 LLVMPositionBuilderAtEnd(g->builder, err_block);
5668 gen_safety_crash_for_err(g, err_val, instruction->base.scope);5680 gen_safety_crash_for_err(g, err_val, instruction->base.base.scope);
56695681
5670 LLVMPositionBuilderAtEnd(g->builder, ok_block);5682 LLVMPositionBuilderAtEnd(g->builder, ok_block);
5671 }5683 }
...@@ -5682,7 +5694,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu...@@ -5682,7 +5694,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
5682 }5694 }
5683}5695}
56845696
5685static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable, IrInstructionOptionalWrap *instruction) {5697static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutableGen *executable, IrInstGenOptionalWrap *instruction) {
5686 ZigType *wanted_type = instruction->base.value->type;5698 ZigType *wanted_type = instruction->base.value->type;
56875699
5688 assert(wanted_type->id == ZigTypeIdOptional);5700 assert(wanted_type->id == ZigTypeIdOptional);
...@@ -5718,7 +5730,7 @@ static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable...@@ -5718,7 +5730,7 @@ static LLVMValueRef ir_render_optional_wrap(CodeGen *g, IrExecutable *executable
5718 return result_loc;5730 return result_loc;
5719}5731}
57205732
5721static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapCode *instruction) {5733static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutableGen *executable, IrInstGenErrWrapCode *instruction) {
5722 ZigType *wanted_type = instruction->base.value->type;5734 ZigType *wanted_type = instruction->base.value->type;
57235735
5724 assert(wanted_type->id == ZigTypeIdErrorUnion);5736 assert(wanted_type->id == ZigTypeIdErrorUnion);
...@@ -5738,7 +5750,7 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable...@@ -5738,7 +5750,7 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable
5738 return result_loc;5750 return result_loc;
5739}5751}
57405752
5741static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapPayload *instruction) {5753static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutableGen *executable, IrInstGenErrWrapPayload *instruction) {
5742 ZigType *wanted_type = instruction->base.value->type;5754 ZigType *wanted_type = instruction->base.value->type;
57435755
5744 assert(wanted_type->id == ZigTypeIdErrorUnion);5756 assert(wanted_type->id == ZigTypeIdErrorUnion);
...@@ -5769,7 +5781,7 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executa...@@ -5769,7 +5781,7 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executa
5769 return result_loc;5781 return result_loc;
5770}5782}
57715783
5772static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, IrInstructionUnionTag *instruction) {5784static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutableGen *executable, IrInstGenUnionTag *instruction) {
5773 ZigType *union_type = instruction->value->value->type;5785 ZigType *union_type = instruction->value->value->type;
57745786
5775 ZigType *tag_type = union_type->data.unionation.tag_type;5787 ZigType *tag_type = union_type->data.unionation.tag_type;
...@@ -5787,15 +5799,15 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, Ir...@@ -5787,15 +5799,15 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, Ir
5787 return get_handle_value(g, tag_field_ptr, tag_type, ptr_type);5799 return get_handle_value(g, tag_field_ptr, tag_type, ptr_type);
5788}5800}
57895801
5790static LLVMValueRef ir_render_panic(CodeGen *g, IrExecutable *executable, IrInstructionPanic *instruction) {5802static LLVMValueRef ir_render_panic(CodeGen *g, IrExecutableGen *executable, IrInstGenPanic *instruction) {
5791 bool is_llvm_alloca;5803 bool is_llvm_alloca;
5792 LLVMValueRef err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca);5804 LLVMValueRef err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);
5793 gen_panic(g, ir_llvm_value(g, instruction->msg), err_ret_trace_val, is_llvm_alloca);5805 gen_panic(g, ir_llvm_value(g, instruction->msg), err_ret_trace_val, is_llvm_alloca);
5794 return nullptr;5806 return nullptr;
5795}5807}
57965808
5797static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,5809static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutableGen *executable,
5798 IrInstructionAtomicRmw *instruction)5810 IrInstGenAtomicRmw *instruction)
5799{5811{
5800 bool is_signed;5812 bool is_signed;
5801 ZigType *operand_type = instruction->operand->value->type;5813 ZigType *operand_type = instruction->operand->value->type;
...@@ -5805,8 +5817,8 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,...@@ -5805,8 +5817,8 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,
5805 } else {5817 } else {
5806 is_signed = false;5818 is_signed = false;
5807 }5819 }
5808 enum ZigLLVM_AtomicRMWBinOp op = to_ZigLLVMAtomicRMWBinOp(instruction->resolved_op, is_signed, is_float);5820 enum ZigLLVM_AtomicRMWBinOp op = to_ZigLLVMAtomicRMWBinOp(instruction->op, is_signed, is_float);
5809 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering);5821 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->ordering);
5810 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);5822 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
5811 LLVMValueRef operand = ir_llvm_value(g, instruction->operand);5823 LLVMValueRef operand = ir_llvm_value(g, instruction->operand);
58125824
...@@ -5823,20 +5835,20 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,...@@ -5823,20 +5835,20 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable,
5823 return LLVMBuildIntToPtr(g->builder, uncasted_result, get_llvm_type(g, operand_type), "");5835 return LLVMBuildIntToPtr(g->builder, uncasted_result, get_llvm_type(g, operand_type), "");
5824}5836}
58255837
5826static LLVMValueRef ir_render_atomic_load(CodeGen *g, IrExecutable *executable,5838static LLVMValueRef ir_render_atomic_load(CodeGen *g, IrExecutableGen *executable,
5827 IrInstructionAtomicLoad *instruction)5839 IrInstGenAtomicLoad *instruction)
5828{5840{
5829 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering);5841 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->ordering);
5830 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);5842 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
5831 LLVMValueRef load_inst = gen_load(g, ptr, instruction->ptr->value->type, "");5843 LLVMValueRef load_inst = gen_load(g, ptr, instruction->ptr->value->type, "");
5832 LLVMSetOrdering(load_inst, ordering);5844 LLVMSetOrdering(load_inst, ordering);
5833 return load_inst;5845 return load_inst;
5834}5846}
58355847
5836static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutable *executable,5848static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutableGen *executable,
5837 IrInstructionAtomicStore *instruction)5849 IrInstGenAtomicStore *instruction)
5838{5850{
5839 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->resolved_ordering);5851 LLVMAtomicOrdering ordering = to_LLVMAtomicOrdering(instruction->ordering);
5840 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);5852 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
5841 LLVMValueRef value = ir_llvm_value(g, instruction->value);5853 LLVMValueRef value = ir_llvm_value(g, instruction->value);
5842 LLVMValueRef store_inst = gen_store(g, value, ptr, instruction->ptr->value->type);5854 LLVMValueRef store_inst = gen_store(g, value, ptr, instruction->ptr->value->type);
...@@ -5844,13 +5856,13 @@ static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutable *executable,...@@ -5844,13 +5856,13 @@ static LLVMValueRef ir_render_atomic_store(CodeGen *g, IrExecutable *executable,
5844 return nullptr;5856 return nullptr;
5845}5857}
58465858
5847static LLVMValueRef ir_render_float_op(CodeGen *g, IrExecutable *executable, IrInstructionFloatOp *instruction) {5859static LLVMValueRef ir_render_float_op(CodeGen *g, IrExecutableGen *executable, IrInstGenFloatOp *instruction) {
5848 LLVMValueRef operand = ir_llvm_value(g, instruction->operand);5860 LLVMValueRef operand = ir_llvm_value(g, instruction->operand);
5849 LLVMValueRef fn_val = get_float_fn(g, instruction->base.value->type, ZigLLVMFnIdFloatOp, instruction->fn_id);5861 LLVMValueRef fn_val = get_float_fn(g, instruction->base.value->type, ZigLLVMFnIdFloatOp, instruction->fn_id);
5850 return LLVMBuildCall(g->builder, fn_val, &operand, 1, "");5862 return LLVMBuildCall(g->builder, fn_val, &operand, 1, "");
5851}5863}
58525864
5853static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutable *executable, IrInstructionMulAdd *instruction) {5865static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutableGen *executable, IrInstGenMulAdd *instruction) {
5854 LLVMValueRef op1 = ir_llvm_value(g, instruction->op1);5866 LLVMValueRef op1 = ir_llvm_value(g, instruction->op1);
5855 LLVMValueRef op2 = ir_llvm_value(g, instruction->op2);5867 LLVMValueRef op2 = ir_llvm_value(g, instruction->op2);
5856 LLVMValueRef op3 = ir_llvm_value(g, instruction->op3);5868 LLVMValueRef op3 = ir_llvm_value(g, instruction->op3);
...@@ -5865,7 +5877,7 @@ static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutable *executable, IrIn...@@ -5865,7 +5877,7 @@ static LLVMValueRef ir_render_mul_add(CodeGen *g, IrExecutable *executable, IrIn
5865 return LLVMBuildCall(g->builder, fn_val, args, 3, "");5877 return LLVMBuildCall(g->builder, fn_val, args, 3, "");
5866}5878}
58675879
5868static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutable *executable, IrInstructionBswap *instruction) {5880static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutableGen *executable, IrInstGenBswap *instruction) {
5869 LLVMValueRef op = ir_llvm_value(g, instruction->op);5881 LLVMValueRef op = ir_llvm_value(g, instruction->op);
5870 ZigType *expr_type = instruction->base.value->type;5882 ZigType *expr_type = instruction->base.value->type;
5871 bool is_vector = expr_type->id == ZigTypeIdVector;5883 bool is_vector = expr_type->id == ZigTypeIdVector;
...@@ -5899,7 +5911,7 @@ static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutable *executable, IrInst...@@ -5899,7 +5911,7 @@ static LLVMValueRef ir_render_bswap(CodeGen *g, IrExecutable *executable, IrInst
5899 return LLVMBuildTrunc(g->builder, shifted, get_llvm_type(g, expr_type), "");5911 return LLVMBuildTrunc(g->builder, shifted, get_llvm_type(g, expr_type), "");
5900}5912}
59015913
5902static LLVMValueRef ir_render_bit_reverse(CodeGen *g, IrExecutable *executable, IrInstructionBitReverse *instruction) {5914static LLVMValueRef ir_render_bit_reverse(CodeGen *g, IrExecutableGen *executable, IrInstGenBitReverse *instruction) {
5903 LLVMValueRef op = ir_llvm_value(g, instruction->op);5915 LLVMValueRef op = ir_llvm_value(g, instruction->op);
5904 ZigType *int_type = instruction->base.value->type;5916 ZigType *int_type = instruction->base.value->type;
5905 assert(int_type->id == ZigTypeIdInt);5917 assert(int_type->id == ZigTypeIdInt);
...@@ -5907,8 +5919,8 @@ static LLVMValueRef ir_render_bit_reverse(CodeGen *g, IrExecutable *executable,...@@ -5907,8 +5919,8 @@ static LLVMValueRef ir_render_bit_reverse(CodeGen *g, IrExecutable *executable,
5907 return LLVMBuildCall(g->builder, fn_val, &op, 1, "");5919 return LLVMBuildCall(g->builder, fn_val, &op, 1, "");
5908}5920}
59095921
5910static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executable,5922static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutableGen *executable,
5911 IrInstructionVectorToArray *instruction)5923 IrInstGenVectorToArray *instruction)
5912{5924{
5913 ZigType *array_type = instruction->base.value->type;5925 ZigType *array_type = instruction->base.value->type;
5914 assert(array_type->id == ZigTypeIdArray);5926 assert(array_type->id == ZigTypeIdArray);
...@@ -5941,8 +5953,8 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executab...@@ -5941,8 +5953,8 @@ static LLVMValueRef ir_render_vector_to_array(CodeGen *g, IrExecutable *executab
5941 return result_loc;5953 return result_loc;
5942}5954}
59435955
5944static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executable,5956static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutableGen *executable,
5945 IrInstructionArrayToVector *instruction)5957 IrInstGenArrayToVector *instruction)
5946{5958{
5947 ZigType *vector_type = instruction->base.value->type;5959 ZigType *vector_type = instruction->base.value->type;
5948 assert(vector_type->id == ZigTypeIdVector);5960 assert(vector_type->id == ZigTypeIdVector);
...@@ -5978,8 +5990,8 @@ static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executab...@@ -5978,8 +5990,8 @@ static LLVMValueRef ir_render_array_to_vector(CodeGen *g, IrExecutable *executab
5978 }5990 }
5979}5991}
59805992
5981static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutable *executable,5993static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutableGen *executable,
5982 IrInstructionAssertZero *instruction)5994 IrInstGenAssertZero *instruction)
5983{5995{
5984 LLVMValueRef target = ir_llvm_value(g, instruction->target);5996 LLVMValueRef target = ir_llvm_value(g, instruction->target);
5985 ZigType *int_type = instruction->target->value->type;5997 ZigType *int_type = instruction->target->value->type;
...@@ -5989,8 +6001,8 @@ static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutable *executable,...@@ -5989,8 +6001,8 @@ static LLVMValueRef ir_render_assert_zero(CodeGen *g, IrExecutable *executable,
5989 return nullptr;6001 return nullptr;
5990}6002}
59916003
5992static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutable *executable,6004static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutableGen *executable,
5993 IrInstructionAssertNonNull *instruction)6005 IrInstGenAssertNonNull *instruction)
5994{6006{
5995 LLVMValueRef target = ir_llvm_value(g, instruction->target);6007 LLVMValueRef target = ir_llvm_value(g, instruction->target);
5996 ZigType *target_type = instruction->target->value->type;6008 ZigType *target_type = instruction->target->value->type;
...@@ -6014,8 +6026,8 @@ static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutable *executab...@@ -6014,8 +6026,8 @@ static LLVMValueRef ir_render_assert_non_null(CodeGen *g, IrExecutable *executab
6014 return nullptr;6026 return nullptr;
6015}6027}
60166028
6017static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutable *executable,6029static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutableGen *executable,
6018 IrInstructionSuspendBegin *instruction)6030 IrInstGenSuspendBegin *instruction)
6019{6031{
6020 if (fn_is_async(g->cur_fn)) {6032 if (fn_is_async(g->cur_fn)) {
6021 instruction->resume_bb = gen_suspend_begin(g, "SuspendResume");6033 instruction->resume_bb = gen_suspend_begin(g, "SuspendResume");
...@@ -6023,8 +6035,8 @@ static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutable *executable...@@ -6023,8 +6035,8 @@ static LLVMValueRef ir_render_suspend_begin(CodeGen *g, IrExecutable *executable
6023 return nullptr;6035 return nullptr;
6024}6036}
60256037
6026static LLVMValueRef ir_render_suspend_finish(CodeGen *g, IrExecutable *executable,6038static LLVMValueRef ir_render_suspend_finish(CodeGen *g, IrExecutableGen *executable,
6027 IrInstructionSuspendFinish *instruction)6039 IrInstGenSuspendFinish *instruction)
6028{6040{
6029 LLVMBuildRetVoid(g->builder);6041 LLVMBuildRetVoid(g->builder);
60306042
...@@ -6032,11 +6044,11 @@ static LLVMValueRef ir_render_suspend_finish(CodeGen *g, IrExecutable *executabl...@@ -6032,11 +6044,11 @@ static LLVMValueRef ir_render_suspend_finish(CodeGen *g, IrExecutable *executabl
6032 if (ir_want_runtime_safety(g, &instruction->base)) {6044 if (ir_want_runtime_safety(g, &instruction->base)) {
6033 LLVMBuildStore(g->builder, g->cur_bad_not_suspended_index, g->cur_async_resume_index_ptr);6045 LLVMBuildStore(g->builder, g->cur_bad_not_suspended_index, g->cur_async_resume_index_ptr);
6034 }6046 }
6035 render_async_var_decls(g, instruction->base.scope);6047 render_async_var_decls(g, instruction->base.base.scope);
6036 return nullptr;6048 return nullptr;
6037}6049}
60386050
6039static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_instr,6051static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstGen *source_instr,
6040 LLVMValueRef target_frame_ptr, ZigType *result_type, ZigType *ptr_result_type,6052 LLVMValueRef target_frame_ptr, ZigType *result_type, ZigType *ptr_result_type,
6041 LLVMValueRef result_loc, bool non_async)6053 LLVMValueRef result_loc, bool non_async)
6042{6054{
...@@ -6062,7 +6074,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_ins...@@ -6062,7 +6074,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_ins
6062 frame_index_trace_arg(g, result_type), "");6074 frame_index_trace_arg(g, result_type), "");
6063 LLVMValueRef src_trace_ptr = LLVMBuildLoad(g->builder, their_trace_ptr_ptr, "");6075 LLVMValueRef src_trace_ptr = LLVMBuildLoad(g->builder, their_trace_ptr_ptr, "");
6064 bool is_llvm_alloca;6076 bool is_llvm_alloca;
6065 LLVMValueRef dest_trace_ptr = get_cur_err_ret_trace_val(g, source_instr->scope, &is_llvm_alloca);6077 LLVMValueRef dest_trace_ptr = get_cur_err_ret_trace_val(g, source_instr->base.scope, &is_llvm_alloca);
6066 LLVMValueRef args[] = { dest_trace_ptr, src_trace_ptr };6078 LLVMValueRef args[] = { dest_trace_ptr, src_trace_ptr };
6067 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,6079 ZigLLVMBuildCall(g->builder, get_merge_err_ret_traces_fn_val(g), args, 2,
6068 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");6080 get_llvm_cc(g, CallingConventionUnspecified), ZigLLVM_CallAttrAuto, "");
...@@ -6075,7 +6087,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_ins...@@ -6075,7 +6087,7 @@ static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_ins
6075 }6087 }
6076}6088}
60776089
6078static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInstructionAwaitGen *instruction) {6090static LLVMValueRef ir_render_await(CodeGen *g, IrExecutableGen *executable, IrInstGenAwait *instruction) {
6079 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;6091 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
6080 LLVMValueRef zero = LLVMConstNull(usize_type_ref);6092 LLVMValueRef zero = LLVMConstNull(usize_type_ref);
6081 LLVMValueRef target_frame_ptr = ir_llvm_value(g, instruction->frame);6093 LLVMValueRef target_frame_ptr = ir_llvm_value(g, instruction->frame);
...@@ -6112,7 +6124,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst...@@ -6112,7 +6124,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst
6112 // supply the error return trace pointer6124 // supply the error return trace pointer
6113 if (codegen_fn_has_err_ret_tracing_arg(g, result_type)) {6125 if (codegen_fn_has_err_ret_tracing_arg(g, result_type)) {
6114 bool is_llvm_alloca;6126 bool is_llvm_alloca;
6115 LLVMValueRef my_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope, &is_llvm_alloca);6127 LLVMValueRef my_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.base.scope, &is_llvm_alloca);
6116 assert(my_err_ret_trace_val != nullptr);6128 assert(my_err_ret_trace_val != nullptr);
6117 LLVMValueRef err_ret_trace_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr,6129 LLVMValueRef err_ret_trace_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr,
6118 frame_index_trace_arg(g, result_type) + 1, "");6130 frame_index_trace_arg(g, result_type) + 1, "");
...@@ -6160,7 +6172,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst...@@ -6160,7 +6172,7 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst
6160 return nullptr;6172 return nullptr;
6161}6173}
61626174
6163static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutable *executable, IrInstructionResume *instruction) {6175static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutableGen *executable, IrInstGenResume *instruction) {
6164 LLVMValueRef frame = ir_llvm_value(g, instruction->frame);6176 LLVMValueRef frame = ir_llvm_value(g, instruction->frame);
6165 ZigType *frame_type = instruction->frame->value->type;6177 ZigType *frame_type = instruction->frame->value->type;
6166 assert(frame_type->id == ZigTypeIdAnyFrame);6178 assert(frame_type->id == ZigTypeIdAnyFrame);
...@@ -6169,15 +6181,15 @@ static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutable *executable, IrIns...@@ -6169,15 +6181,15 @@ static LLVMValueRef ir_render_resume(CodeGen *g, IrExecutable *executable, IrIns
6169 return nullptr;6181 return nullptr;
6170}6182}
61716183
6172static LLVMValueRef ir_render_frame_size(CodeGen *g, IrExecutable *executable,6184static LLVMValueRef ir_render_frame_size(CodeGen *g, IrExecutableGen *executable,
6173 IrInstructionFrameSizeGen *instruction)6185 IrInstGenFrameSize *instruction)
6174{6186{
6175 LLVMValueRef fn_val = ir_llvm_value(g, instruction->fn);6187 LLVMValueRef fn_val = ir_llvm_value(g, instruction->fn);
6176 return gen_frame_size(g, fn_val);6188 return gen_frame_size(g, fn_val);
6177}6189}
61786190
6179static LLVMValueRef ir_render_spill_begin(CodeGen *g, IrExecutable *executable,6191static LLVMValueRef ir_render_spill_begin(CodeGen *g, IrExecutableGen *executable,
6180 IrInstructionSpillBegin *instruction)6192 IrInstGenSpillBegin *instruction)
6181{6193{
6182 if (!fn_is_async(g->cur_fn))6194 if (!fn_is_async(g->cur_fn))
6183 return nullptr;6195 return nullptr;
...@@ -6196,7 +6208,7 @@ static LLVMValueRef ir_render_spill_begin(CodeGen *g, IrExecutable *executable,...@@ -6196,7 +6208,7 @@ static LLVMValueRef ir_render_spill_begin(CodeGen *g, IrExecutable *executable,
6196 zig_unreachable();6208 zig_unreachable();
6197}6209}
61986210
6199static LLVMValueRef ir_render_spill_end(CodeGen *g, IrExecutable *executable, IrInstructionSpillEnd *instruction) {6211static LLVMValueRef ir_render_spill_end(CodeGen *g, IrExecutableGen *executable, IrInstGenSpillEnd *instruction) {
6200 if (!fn_is_async(g->cur_fn))6212 if (!fn_is_async(g->cur_fn))
6201 return ir_llvm_value(g, instruction->begin->operand);6213 return ir_llvm_value(g, instruction->begin->operand);
62026214
...@@ -6212,17 +6224,17 @@ static LLVMValueRef ir_render_spill_end(CodeGen *g, IrExecutable *executable, Ir...@@ -6212,17 +6224,17 @@ static LLVMValueRef ir_render_spill_end(CodeGen *g, IrExecutable *executable, Ir
6212 zig_unreachable();6224 zig_unreachable();
6213}6225}
62146226
6215static LLVMValueRef ir_render_vector_extract_elem(CodeGen *g, IrExecutable *executable,6227static LLVMValueRef ir_render_vector_extract_elem(CodeGen *g, IrExecutableGen *executable,
6216 IrInstructionVectorExtractElem *instruction)6228 IrInstGenVectorExtractElem *instruction)
6217{6229{
6218 LLVMValueRef vector = ir_llvm_value(g, instruction->vector);6230 LLVMValueRef vector = ir_llvm_value(g, instruction->vector);
6219 LLVMValueRef index = ir_llvm_value(g, instruction->index);6231 LLVMValueRef index = ir_llvm_value(g, instruction->index);
6220 return LLVMBuildExtractElement(g->builder, vector, index, "");6232 return LLVMBuildExtractElement(g->builder, vector, index, "");
6221}6233}
62226234
6223static void set_debug_location(CodeGen *g, IrInstruction *instruction) {6235static void set_debug_location(CodeGen *g, IrInstGen *instruction) {
6224 AstNode *source_node = instruction->source_node;6236 AstNode *source_node = instruction->base.source_node;
6225 Scope *scope = instruction->scope;6237 Scope *scope = instruction->base.scope;
62266238
6227 assert(source_node);6239 assert(source_node);
6228 assert(scope);6240 assert(scope);
...@@ -6231,263 +6243,183 @@ static void set_debug_location(CodeGen *g, IrInstruction *instruction) {...@@ -6231,263 +6243,183 @@ static void set_debug_location(CodeGen *g, IrInstruction *instruction) {
6231 (int)source_node->column + 1, get_di_scope(g, scope));6243 (int)source_node->column + 1, get_di_scope(g, scope));
6232}6244}
62336245
6234static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, IrInstruction *instruction) {6246static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutableGen *executable, IrInstGen *instruction) {
6235 switch (instruction->id) {6247 switch (instruction->id) {
6236 case IrInstructionIdInvalid:6248 case IrInstGenIdInvalid:
6237 case IrInstructionIdConst:6249 case IrInstGenIdConst:
6238 case IrInstructionIdTypeOf:6250 case IrInstGenIdAlloca:
6239 case IrInstructionIdFieldPtr:
6240 case IrInstructionIdSetCold:
6241 case IrInstructionIdSetRuntimeSafety:
6242 case IrInstructionIdSetFloatMode:
6243 case IrInstructionIdArrayType:
6244 case IrInstructionIdAnyFrameType:
6245 case IrInstructionIdSliceType:
6246 case IrInstructionIdSizeOf:
6247 case IrInstructionIdSwitchTarget:
6248 case IrInstructionIdContainerInitFields:
6249 case IrInstructionIdCompileErr:
6250 case IrInstructionIdCompileLog:
6251 case IrInstructionIdImport:
6252 case IrInstructionIdCImport:
6253 case IrInstructionIdCInclude:
6254 case IrInstructionIdCDefine:
6255 case IrInstructionIdCUndef:
6256 case IrInstructionIdEmbedFile:
6257 case IrInstructionIdIntType:
6258 case IrInstructionIdVectorType:
6259 case IrInstructionIdMemberCount:
6260 case IrInstructionIdMemberType:
6261 case IrInstructionIdMemberName:
6262 case IrInstructionIdAlignOf:
6263 case IrInstructionIdFnProto:
6264 case IrInstructionIdTestComptime:
6265 case IrInstructionIdCheckSwitchProngs:
6266 case IrInstructionIdCheckStatementIsVoid:
6267 case IrInstructionIdTypeName:
6268 case IrInstructionIdDeclRef:
6269 case IrInstructionIdSwitchVar:
6270 case IrInstructionIdSwitchElseVar:
6271 case IrInstructionIdByteOffsetOf:
6272 case IrInstructionIdBitOffsetOf:
6273 case IrInstructionIdTypeInfo:
6274 case IrInstructionIdType:
6275 case IrInstructionIdHasField:
6276 case IrInstructionIdTypeId:
6277 case IrInstructionIdSetEvalBranchQuota:
6278 case IrInstructionIdPtrType:
6279 case IrInstructionIdOpaqueType:
6280 case IrInstructionIdSetAlignStack:
6281 case IrInstructionIdArgType:
6282 case IrInstructionIdTagType:
6283 case IrInstructionIdExport:
6284 case IrInstructionIdErrorUnion:
6285 case IrInstructionIdAddImplicitReturnType:
6286 case IrInstructionIdIntCast:
6287 case IrInstructionIdFloatCast:
6288 case IrInstructionIdIntToFloat:
6289 case IrInstructionIdFloatToInt:
6290 case IrInstructionIdBoolToInt:
6291 case IrInstructionIdErrSetCast:
6292 case IrInstructionIdFromBytes:
6293 case IrInstructionIdToBytes:
6294 case IrInstructionIdEnumToInt:
6295 case IrInstructionIdCheckRuntimeScope:
6296 case IrInstructionIdDeclVarSrc:
6297 case IrInstructionIdPtrCastSrc:
6298 case IrInstructionIdCmpxchgSrc:
6299 case IrInstructionIdLoadPtr:
6300 case IrInstructionIdHasDecl:
6301 case IrInstructionIdUndeclaredIdent:
6302 case IrInstructionIdCallExtra:
6303 case IrInstructionIdCallSrc:
6304 case IrInstructionIdCallSrcArgs:
6305 case IrInstructionIdAllocaSrc:
6306 case IrInstructionIdEndExpr:
6307 case IrInstructionIdImplicitCast:
6308 case IrInstructionIdResolveResult:
6309 case IrInstructionIdResetResult:
6310 case IrInstructionIdContainerInitList:
6311 case IrInstructionIdSliceSrc:
6312 case IrInstructionIdRef:
6313 case IrInstructionIdBitCastSrc:
6314 case IrInstructionIdTestErrSrc:
6315 case IrInstructionIdUnionInitNamedField:
6316 case IrInstructionIdFrameType:
6317 case IrInstructionIdFrameSizeSrc:
6318 case IrInstructionIdAllocaGen:
6319 case IrInstructionIdAwaitSrc:
6320 case IrInstructionIdSplatSrc:
6321 case IrInstructionIdMergeErrSets:
6322 case IrInstructionIdAsmSrc:
6323 zig_unreachable();6251 zig_unreachable();
63246252
6325 case IrInstructionIdDeclVarGen:6253 case IrInstGenIdDeclVar:
6326 return ir_render_decl_var(g, executable, (IrInstructionDeclVarGen *)instruction);6254 return ir_render_decl_var(g, executable, (IrInstGenDeclVar *)instruction);
6327 case IrInstructionIdReturn:6255 case IrInstGenIdReturn:
6328 return ir_render_return(g, executable, (IrInstructionReturn *)instruction);6256 return ir_render_return(g, executable, (IrInstGenReturn *)instruction);
6329 case IrInstructionIdBinOp:6257 case IrInstGenIdBinOp:
6330 return ir_render_bin_op(g, executable, (IrInstructionBinOp *)instruction);6258 return ir_render_bin_op(g, executable, (IrInstGenBinOp *)instruction);
6331 case IrInstructionIdCast:6259 case IrInstGenIdCast:
6332 return ir_render_cast(g, executable, (IrInstructionCast *)instruction);6260 return ir_render_cast(g, executable, (IrInstGenCast *)instruction);
6333 case IrInstructionIdUnreachable:6261 case IrInstGenIdUnreachable:
6334 return ir_render_unreachable(g, executable, (IrInstructionUnreachable *)instruction);6262 return ir_render_unreachable(g, executable, (IrInstGenUnreachable *)instruction);
6335 case IrInstructionIdCondBr:6263 case IrInstGenIdCondBr:
6336 return ir_render_cond_br(g, executable, (IrInstructionCondBr *)instruction);6264 return ir_render_cond_br(g, executable, (IrInstGenCondBr *)instruction);
6337 case IrInstructionIdBr:6265 case IrInstGenIdBr:
6338 return ir_render_br(g, executable, (IrInstructionBr *)instruction);6266 return ir_render_br(g, executable, (IrInstGenBr *)instruction);
6339 case IrInstructionIdUnOp:6267 case IrInstGenIdBinaryNot:
6340 return ir_render_un_op(g, executable, (IrInstructionUnOp *)instruction);6268 return ir_render_binary_not(g, executable, (IrInstGenBinaryNot *)instruction);
6341 case IrInstructionIdLoadPtrGen:6269 case IrInstGenIdNegation:
6342 return ir_render_load_ptr(g, executable, (IrInstructionLoadPtrGen *)instruction);6270 return ir_render_negation(g, executable, (IrInstGenNegation *)instruction);
6343 case IrInstructionIdStorePtr:6271 case IrInstGenIdNegationWrapping:
6344 return ir_render_store_ptr(g, executable, (IrInstructionStorePtr *)instruction);6272 return ir_render_negation_wrapping(g, executable, (IrInstGenNegationWrapping *)instruction);
6345 case IrInstructionIdVectorStoreElem:6273 case IrInstGenIdLoadPtr:
6346 return ir_render_vector_store_elem(g, executable, (IrInstructionVectorStoreElem *)instruction);6274 return ir_render_load_ptr(g, executable, (IrInstGenLoadPtr *)instruction);
6347 case IrInstructionIdVarPtr:6275 case IrInstGenIdStorePtr:
6348 return ir_render_var_ptr(g, executable, (IrInstructionVarPtr *)instruction);6276 return ir_render_store_ptr(g, executable, (IrInstGenStorePtr *)instruction);
6349 case IrInstructionIdReturnPtr:6277 case IrInstGenIdVectorStoreElem:
6350 return ir_render_return_ptr(g, executable, (IrInstructionReturnPtr *)instruction);6278 return ir_render_vector_store_elem(g, executable, (IrInstGenVectorStoreElem *)instruction);
6351 case IrInstructionIdElemPtr:6279 case IrInstGenIdVarPtr:
6352 return ir_render_elem_ptr(g, executable, (IrInstructionElemPtr *)instruction);6280 return ir_render_var_ptr(g, executable, (IrInstGenVarPtr *)instruction);
6353 case IrInstructionIdCallGen:6281 case IrInstGenIdReturnPtr:
6354 return ir_render_call(g, executable, (IrInstructionCallGen *)instruction);6282 return ir_render_return_ptr(g, executable, (IrInstGenReturnPtr *)instruction);
6355 case IrInstructionIdStructFieldPtr:6283 case IrInstGenIdElemPtr:
6356 return ir_render_struct_field_ptr(g, executable, (IrInstructionStructFieldPtr *)instruction);6284 return ir_render_elem_ptr(g, executable, (IrInstGenElemPtr *)instruction);
6357 case IrInstructionIdUnionFieldPtr:6285 case IrInstGenIdCall:
6358 return ir_render_union_field_ptr(g, executable, (IrInstructionUnionFieldPtr *)instruction);6286 return ir_render_call(g, executable, (IrInstGenCall *)instruction);
6359 case IrInstructionIdAsmGen:6287 case IrInstGenIdStructFieldPtr:
6360 return ir_render_asm_gen(g, executable, (IrInstructionAsmGen *)instruction);6288 return ir_render_struct_field_ptr(g, executable, (IrInstGenStructFieldPtr *)instruction);
6361 case IrInstructionIdTestNonNull:6289 case IrInstGenIdUnionFieldPtr:
6362 return ir_render_test_non_null(g, executable, (IrInstructionTestNonNull *)instruction);6290 return ir_render_union_field_ptr(g, executable, (IrInstGenUnionFieldPtr *)instruction);
6363 case IrInstructionIdOptionalUnwrapPtr:6291 case IrInstGenIdAsm:
6364 return ir_render_optional_unwrap_ptr(g, executable, (IrInstructionOptionalUnwrapPtr *)instruction);6292 return ir_render_asm_gen(g, executable, (IrInstGenAsm *)instruction);
6365 case IrInstructionIdClz:6293 case IrInstGenIdTestNonNull:
6366 return ir_render_clz(g, executable, (IrInstructionClz *)instruction);6294 return ir_render_test_non_null(g, executable, (IrInstGenTestNonNull *)instruction);
6367 case IrInstructionIdCtz:6295 case IrInstGenIdOptionalUnwrapPtr:
6368 return ir_render_ctz(g, executable, (IrInstructionCtz *)instruction);6296 return ir_render_optional_unwrap_ptr(g, executable, (IrInstGenOptionalUnwrapPtr *)instruction);
6369 case IrInstructionIdPopCount:6297 case IrInstGenIdClz:
6370 return ir_render_pop_count(g, executable, (IrInstructionPopCount *)instruction);6298 return ir_render_clz(g, executable, (IrInstGenClz *)instruction);
6371 case IrInstructionIdSwitchBr:6299 case IrInstGenIdCtz:
6372 return ir_render_switch_br(g, executable, (IrInstructionSwitchBr *)instruction);6300 return ir_render_ctz(g, executable, (IrInstGenCtz *)instruction);
6373 case IrInstructionIdBswap:6301 case IrInstGenIdPopCount:
6374 return ir_render_bswap(g, executable, (IrInstructionBswap *)instruction);6302 return ir_render_pop_count(g, executable, (IrInstGenPopCount *)instruction);
6375 case IrInstructionIdBitReverse:6303 case IrInstGenIdSwitchBr:
6376 return ir_render_bit_reverse(g, executable, (IrInstructionBitReverse *)instruction);6304 return ir_render_switch_br(g, executable, (IrInstGenSwitchBr *)instruction);
6377 case IrInstructionIdPhi:6305 case IrInstGenIdBswap:
6378 return ir_render_phi(g, executable, (IrInstructionPhi *)instruction);6306 return ir_render_bswap(g, executable, (IrInstGenBswap *)instruction);
6379 case IrInstructionIdRefGen:6307 case IrInstGenIdBitReverse:
6380 return ir_render_ref(g, executable, (IrInstructionRefGen *)instruction);6308 return ir_render_bit_reverse(g, executable, (IrInstGenBitReverse *)instruction);
6381 case IrInstructionIdErrName:6309 case IrInstGenIdPhi:
6382 return ir_render_err_name(g, executable, (IrInstructionErrName *)instruction);6310 return ir_render_phi(g, executable, (IrInstGenPhi *)instruction);
6383 case IrInstructionIdCmpxchgGen:6311 case IrInstGenIdRef:
6384 return ir_render_cmpxchg(g, executable, (IrInstructionCmpxchgGen *)instruction);6312 return ir_render_ref(g, executable, (IrInstGenRef *)instruction);
6385 case IrInstructionIdFence:6313 case IrInstGenIdErrName:
6386 return ir_render_fence(g, executable, (IrInstructionFence *)instruction);6314 return ir_render_err_name(g, executable, (IrInstGenErrName *)instruction);
6387 case IrInstructionIdTruncate:6315 case IrInstGenIdCmpxchg:
6388 return ir_render_truncate(g, executable, (IrInstructionTruncate *)instruction);6316 return ir_render_cmpxchg(g, executable, (IrInstGenCmpxchg *)instruction);
6389 case IrInstructionIdBoolNot:6317 case IrInstGenIdFence:
6390 return ir_render_bool_not(g, executable, (IrInstructionBoolNot *)instruction);6318 return ir_render_fence(g, executable, (IrInstGenFence *)instruction);
6391 case IrInstructionIdMemset:6319 case IrInstGenIdTruncate:
6392 return ir_render_memset(g, executable, (IrInstructionMemset *)instruction);6320 return ir_render_truncate(g, executable, (IrInstGenTruncate *)instruction);
6393 case IrInstructionIdMemcpy:6321 case IrInstGenIdBoolNot:
6394 return ir_render_memcpy(g, executable, (IrInstructionMemcpy *)instruction);6322 return ir_render_bool_not(g, executable, (IrInstGenBoolNot *)instruction);
6395 case IrInstructionIdSliceGen:6323 case IrInstGenIdMemset:
6396 return ir_render_slice(g, executable, (IrInstructionSliceGen *)instruction);6324 return ir_render_memset(g, executable, (IrInstGenMemset *)instruction);
6397 case IrInstructionIdBreakpoint:6325 case IrInstGenIdMemcpy:
6398 return ir_render_breakpoint(g, executable, (IrInstructionBreakpoint *)instruction);6326 return ir_render_memcpy(g, executable, (IrInstGenMemcpy *)instruction);
6399 case IrInstructionIdReturnAddress:6327 case IrInstGenIdSlice:
6400 return ir_render_return_address(g, executable, (IrInstructionReturnAddress *)instruction);6328 return ir_render_slice(g, executable, (IrInstGenSlice *)instruction);
6401 case IrInstructionIdFrameAddress:6329 case IrInstGenIdBreakpoint:
6402 return ir_render_frame_address(g, executable, (IrInstructionFrameAddress *)instruction);6330 return ir_render_breakpoint(g, executable, (IrInstGenBreakpoint *)instruction);
6403 case IrInstructionIdFrameHandle:6331 case IrInstGenIdReturnAddress:
6404 return ir_render_handle(g, executable, (IrInstructionFrameHandle *)instruction);6332 return ir_render_return_address(g, executable, (IrInstGenReturnAddress *)instruction);
6405 case IrInstructionIdOverflowOp:6333 case IrInstGenIdFrameAddress:
6406 return ir_render_overflow_op(g, executable, (IrInstructionOverflowOp *)instruction);6334 return ir_render_frame_address(g, executable, (IrInstGenFrameAddress *)instruction);
6407 case IrInstructionIdTestErrGen:6335 case IrInstGenIdFrameHandle:
6408 return ir_render_test_err(g, executable, (IrInstructionTestErrGen *)instruction);6336 return ir_render_handle(g, executable, (IrInstGenFrameHandle *)instruction);
6409 case IrInstructionIdUnwrapErrCode:6337 case IrInstGenIdOverflowOp:
6410 return ir_render_unwrap_err_code(g, executable, (IrInstructionUnwrapErrCode *)instruction);6338 return ir_render_overflow_op(g, executable, (IrInstGenOverflowOp *)instruction);
6411 case IrInstructionIdUnwrapErrPayload:6339 case IrInstGenIdTestErr:
6412 return ir_render_unwrap_err_payload(g, executable, (IrInstructionUnwrapErrPayload *)instruction);6340 return ir_render_test_err(g, executable, (IrInstGenTestErr *)instruction);
6413 case IrInstructionIdOptionalWrap:6341 case IrInstGenIdUnwrapErrCode:
6414 return ir_render_optional_wrap(g, executable, (IrInstructionOptionalWrap *)instruction);6342 return ir_render_unwrap_err_code(g, executable, (IrInstGenUnwrapErrCode *)instruction);
6415 case IrInstructionIdErrWrapCode:6343 case IrInstGenIdUnwrapErrPayload:
6416 return ir_render_err_wrap_code(g, executable, (IrInstructionErrWrapCode *)instruction);6344 return ir_render_unwrap_err_payload(g, executable, (IrInstGenUnwrapErrPayload *)instruction);
6417 case IrInstructionIdErrWrapPayload:6345 case IrInstGenIdOptionalWrap:
6418 return ir_render_err_wrap_payload(g, executable, (IrInstructionErrWrapPayload *)instruction);6346 return ir_render_optional_wrap(g, executable, (IrInstGenOptionalWrap *)instruction);
6419 case IrInstructionIdUnionTag:6347 case IrInstGenIdErrWrapCode:
6420 return ir_render_union_tag(g, executable, (IrInstructionUnionTag *)instruction);6348 return ir_render_err_wrap_code(g, executable, (IrInstGenErrWrapCode *)instruction);
6421 case IrInstructionIdPtrCastGen:6349 case IrInstGenIdErrWrapPayload:
6422 return ir_render_ptr_cast(g, executable, (IrInstructionPtrCastGen *)instruction);6350 return ir_render_err_wrap_payload(g, executable, (IrInstGenErrWrapPayload *)instruction);
6423 case IrInstructionIdBitCastGen:6351 case IrInstGenIdUnionTag:
6424 return ir_render_bit_cast(g, executable, (IrInstructionBitCastGen *)instruction);6352 return ir_render_union_tag(g, executable, (IrInstGenUnionTag *)instruction);
6425 case IrInstructionIdWidenOrShorten:6353 case IrInstGenIdPtrCast:
6426 return ir_render_widen_or_shorten(g, executable, (IrInstructionWidenOrShorten *)instruction);6354 return ir_render_ptr_cast(g, executable, (IrInstGenPtrCast *)instruction);
6427 case IrInstructionIdPtrToInt:6355 case IrInstGenIdBitCast:
6428 return ir_render_ptr_to_int(g, executable, (IrInstructionPtrToInt *)instruction);6356 return ir_render_bit_cast(g, executable, (IrInstGenBitCast *)instruction);
6429 case IrInstructionIdIntToPtr:6357 case IrInstGenIdWidenOrShorten:
6430 return ir_render_int_to_ptr(g, executable, (IrInstructionIntToPtr *)instruction);6358 return ir_render_widen_or_shorten(g, executable, (IrInstGenWidenOrShorten *)instruction);
6431 case IrInstructionIdIntToEnum:6359 case IrInstGenIdPtrToInt:
6432 return ir_render_int_to_enum(g, executable, (IrInstructionIntToEnum *)instruction);6360 return ir_render_ptr_to_int(g, executable, (IrInstGenPtrToInt *)instruction);
6433 case IrInstructionIdIntToErr:6361 case IrInstGenIdIntToPtr:
6434 return ir_render_int_to_err(g, executable, (IrInstructionIntToErr *)instruction);6362 return ir_render_int_to_ptr(g, executable, (IrInstGenIntToPtr *)instruction);
6435 case IrInstructionIdErrToInt:6363 case IrInstGenIdIntToEnum:
6436 return ir_render_err_to_int(g, executable, (IrInstructionErrToInt *)instruction);6364 return ir_render_int_to_enum(g, executable, (IrInstGenIntToEnum *)instruction);
6437 case IrInstructionIdPanic:6365 case IrInstGenIdIntToErr:
6438 return ir_render_panic(g, executable, (IrInstructionPanic *)instruction);6366 return ir_render_int_to_err(g, executable, (IrInstGenIntToErr *)instruction);
6439 case IrInstructionIdTagName:6367 case IrInstGenIdErrToInt:
6440 return ir_render_enum_tag_name(g, executable, (IrInstructionTagName *)instruction);6368 return ir_render_err_to_int(g, executable, (IrInstGenErrToInt *)instruction);
6441 case IrInstructionIdFieldParentPtr:6369 case IrInstGenIdPanic:
6442 return ir_render_field_parent_ptr(g, executable, (IrInstructionFieldParentPtr *)instruction);6370 return ir_render_panic(g, executable, (IrInstGenPanic *)instruction);
6443 case IrInstructionIdAlignCast:6371 case IrInstGenIdTagName:
6444 return ir_render_align_cast(g, executable, (IrInstructionAlignCast *)instruction);6372 return ir_render_enum_tag_name(g, executable, (IrInstGenTagName *)instruction);
6445 case IrInstructionIdErrorReturnTrace:6373 case IrInstGenIdFieldParentPtr:
6446 return ir_render_error_return_trace(g, executable, (IrInstructionErrorReturnTrace *)instruction);6374 return ir_render_field_parent_ptr(g, executable, (IrInstGenFieldParentPtr *)instruction);
6447 case IrInstructionIdAtomicRmw:6375 case IrInstGenIdAlignCast:
6448 return ir_render_atomic_rmw(g, executable, (IrInstructionAtomicRmw *)instruction);6376 return ir_render_align_cast(g, executable, (IrInstGenAlignCast *)instruction);
6449 case IrInstructionIdAtomicLoad:6377 case IrInstGenIdErrorReturnTrace:
6450 return ir_render_atomic_load(g, executable, (IrInstructionAtomicLoad *)instruction);6378 return ir_render_error_return_trace(g, executable, (IrInstGenErrorReturnTrace *)instruction);
6451 case IrInstructionIdAtomicStore:6379 case IrInstGenIdAtomicRmw:
6452 return ir_render_atomic_store(g, executable, (IrInstructionAtomicStore *)instruction);6380 return ir_render_atomic_rmw(g, executable, (IrInstGenAtomicRmw *)instruction);
6453 case IrInstructionIdSaveErrRetAddr:6381 case IrInstGenIdAtomicLoad:
6454 return ir_render_save_err_ret_addr(g, executable, (IrInstructionSaveErrRetAddr *)instruction);6382 return ir_render_atomic_load(g, executable, (IrInstGenAtomicLoad *)instruction);
6455 case IrInstructionIdFloatOp:6383 case IrInstGenIdAtomicStore:
6456 return ir_render_float_op(g, executable, (IrInstructionFloatOp *)instruction);6384 return ir_render_atomic_store(g, executable, (IrInstGenAtomicStore *)instruction);
6457 case IrInstructionIdMulAdd:6385 case IrInstGenIdSaveErrRetAddr:
6458 return ir_render_mul_add(g, executable, (IrInstructionMulAdd *)instruction);6386 return ir_render_save_err_ret_addr(g, executable, (IrInstGenSaveErrRetAddr *)instruction);
6459 case IrInstructionIdArrayToVector:6387 case IrInstGenIdFloatOp:
6460 return ir_render_array_to_vector(g, executable, (IrInstructionArrayToVector *)instruction);6388 return ir_render_float_op(g, executable, (IrInstGenFloatOp *)instruction);
6461 case IrInstructionIdVectorToArray:6389 case IrInstGenIdMulAdd:
6462 return ir_render_vector_to_array(g, executable, (IrInstructionVectorToArray *)instruction);6390 return ir_render_mul_add(g, executable, (IrInstGenMulAdd *)instruction);
6463 case IrInstructionIdAssertZero:6391 case IrInstGenIdArrayToVector:
6464 return ir_render_assert_zero(g, executable, (IrInstructionAssertZero *)instruction);6392 return ir_render_array_to_vector(g, executable, (IrInstGenArrayToVector *)instruction);
6465 case IrInstructionIdAssertNonNull:6393 case IrInstGenIdVectorToArray:
6466 return ir_render_assert_non_null(g, executable, (IrInstructionAssertNonNull *)instruction);6394 return ir_render_vector_to_array(g, executable, (IrInstGenVectorToArray *)instruction);
6467 case IrInstructionIdResizeSlice:6395 case IrInstGenIdAssertZero:
6468 return ir_render_resize_slice(g, executable, (IrInstructionResizeSlice *)instruction);6396 return ir_render_assert_zero(g, executable, (IrInstGenAssertZero *)instruction);
6469 case IrInstructionIdPtrOfArrayToSlice:6397 case IrInstGenIdAssertNonNull:
6470 return ir_render_ptr_of_array_to_slice(g, executable, (IrInstructionPtrOfArrayToSlice *)instruction);6398 return ir_render_assert_non_null(g, executable, (IrInstGenAssertNonNull *)instruction);
6471 case IrInstructionIdSuspendBegin:6399 case IrInstGenIdResizeSlice:
6472 return ir_render_suspend_begin(g, executable, (IrInstructionSuspendBegin *)instruction);6400 return ir_render_resize_slice(g, executable, (IrInstGenResizeSlice *)instruction);
6473 case IrInstructionIdSuspendFinish:6401 case IrInstGenIdPtrOfArrayToSlice:
6474 return ir_render_suspend_finish(g, executable, (IrInstructionSuspendFinish *)instruction);6402 return ir_render_ptr_of_array_to_slice(g, executable, (IrInstGenPtrOfArrayToSlice *)instruction);
6475 case IrInstructionIdResume:6403 case IrInstGenIdSuspendBegin:
6476 return ir_render_resume(g, executable, (IrInstructionResume *)instruction);6404 return ir_render_suspend_begin(g, executable, (IrInstGenSuspendBegin *)instruction);
6477 case IrInstructionIdFrameSizeGen:6405 case IrInstGenIdSuspendFinish:
6478 return ir_render_frame_size(g, executable, (IrInstructionFrameSizeGen *)instruction);6406 return ir_render_suspend_finish(g, executable, (IrInstGenSuspendFinish *)instruction);
6479 case IrInstructionIdAwaitGen:6407 case IrInstGenIdResume:
6480 return ir_render_await(g, executable, (IrInstructionAwaitGen *)instruction);6408 return ir_render_resume(g, executable, (IrInstGenResume *)instruction);
6481 case IrInstructionIdSpillBegin:6409 case IrInstGenIdFrameSize:
6482 return ir_render_spill_begin(g, executable, (IrInstructionSpillBegin *)instruction);6410 return ir_render_frame_size(g, executable, (IrInstGenFrameSize *)instruction);
6483 case IrInstructionIdSpillEnd:6411 case IrInstGenIdAwait:
6484 return ir_render_spill_end(g, executable, (IrInstructionSpillEnd *)instruction);6412 return ir_render_await(g, executable, (IrInstGenAwait *)instruction);
6485 case IrInstructionIdShuffleVector:6413 case IrInstGenIdSpillBegin:
6486 return ir_render_shuffle_vector(g, executable, (IrInstructionShuffleVector *) instruction);6414 return ir_render_spill_begin(g, executable, (IrInstGenSpillBegin *)instruction);
6487 case IrInstructionIdSplatGen:6415 case IrInstGenIdSpillEnd:
6488 return ir_render_splat(g, executable, (IrInstructionSplatGen *) instruction);6416 return ir_render_spill_end(g, executable, (IrInstGenSpillEnd *)instruction);
6489 case IrInstructionIdVectorExtractElem:6417 case IrInstGenIdShuffleVector:
6490 return ir_render_vector_extract_elem(g, executable, (IrInstructionVectorExtractElem *) instruction);6418 return ir_render_shuffle_vector(g, executable, (IrInstGenShuffleVector *) instruction);
6419 case IrInstGenIdSplat:
6420 return ir_render_splat(g, executable, (IrInstGenSplat *) instruction);
6421 case IrInstGenIdVectorExtractElem:
6422 return ir_render_vector_extract_elem(g, executable, (IrInstGenVectorExtractElem *) instruction);
6491 }6423 }
6492 zig_unreachable();6424 zig_unreachable();
6493}6425}
...@@ -6495,21 +6427,21 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -6495,21 +6427,21 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
6495static void ir_render(CodeGen *g, ZigFn *fn_entry) {6427static void ir_render(CodeGen *g, ZigFn *fn_entry) {
6496 assert(fn_entry);6428 assert(fn_entry);
64976429
6498 IrExecutable *executable = &fn_entry->analyzed_executable;6430 IrExecutableGen *executable = &fn_entry->analyzed_executable;
6499 assert(executable->basic_block_list.length > 0);6431 assert(executable->basic_block_list.length > 0);
65006432
6501 for (size_t block_i = 0; block_i < executable->basic_block_list.length; block_i += 1) {6433 for (size_t block_i = 0; block_i < executable->basic_block_list.length; block_i += 1) {
6502 IrBasicBlock *current_block = executable->basic_block_list.at(block_i);6434 IrBasicBlockGen *current_block = executable->basic_block_list.at(block_i);
6503 if (get_scope_typeof(current_block->scope) != nullptr) {6435 if (get_scope_typeof(current_block->scope) != nullptr) {
6504 LLVMBuildBr(g->builder, current_block->llvm_block);6436 LLVMBuildBr(g->builder, current_block->llvm_block);
6505 }6437 }
6506 assert(current_block->llvm_block);6438 assert(current_block->llvm_block);
6507 LLVMPositionBuilderAtEnd(g->builder, current_block->llvm_block);6439 LLVMPositionBuilderAtEnd(g->builder, current_block->llvm_block);
6508 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {6440 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {
6509 IrInstruction *instruction = current_block->instruction_list.at(instr_i);6441 IrInstGen *instruction = current_block->instruction_list.at(instr_i);
6510 if (instruction->ref_count == 0 && !ir_has_side_effects(instruction))6442 if (instruction->base.ref_count == 0 && !ir_inst_gen_has_side_effects(instruction))
6511 continue;6443 continue;
6512 if (get_scope_typeof(instruction->scope) != nullptr)6444 if (get_scope_typeof(instruction->base.scope) != nullptr)
6513 continue;6445 continue;
65146446
6515 if (!g->strip_debug_symbols) {6447 if (!g->strip_debug_symbols) {
...@@ -7401,7 +7333,7 @@ static void generate_error_name_table(CodeGen *g) {...@@ -7401,7 +7333,7 @@ static void generate_error_name_table(CodeGen *g) {
7401}7333}
74027334
7403static void build_all_basic_blocks(CodeGen *g, ZigFn *fn) {7335static void build_all_basic_blocks(CodeGen *g, ZigFn *fn) {
7404 IrExecutable *executable = &fn->analyzed_executable;7336 IrExecutableGen *executable = &fn->analyzed_executable;
7405 assert(executable->basic_block_list.length > 0);7337 assert(executable->basic_block_list.length > 0);
7406 LLVMValueRef fn_val = fn_llvm_value(g, fn);7338 LLVMValueRef fn_val = fn_llvm_value(g, fn);
7407 LLVMBasicBlockRef first_bb = nullptr;7339 LLVMBasicBlockRef first_bb = nullptr;
...@@ -7410,7 +7342,7 @@ static void build_all_basic_blocks(CodeGen *g, ZigFn *fn) {...@@ -7410,7 +7342,7 @@ static void build_all_basic_blocks(CodeGen *g, ZigFn *fn) {
7410 g->cur_preamble_llvm_block = first_bb;7342 g->cur_preamble_llvm_block = first_bb;
7411 }7343 }
7412 for (size_t block_i = 0; block_i < executable->basic_block_list.length; block_i += 1) {7344 for (size_t block_i = 0; block_i < executable->basic_block_list.length; block_i += 1) {
7413 IrBasicBlock *bb = executable->basic_block_list.at(block_i);7345 IrBasicBlockGen *bb = executable->basic_block_list.at(block_i);
7414 bb->llvm_block = LLVMAppendBasicBlock(fn_val, bb->name_hint);7346 bb->llvm_block = LLVMAppendBasicBlock(fn_val, bb->name_hint);
7415 }7347 }
7416 if (first_bb == nullptr) {7348 if (first_bb == nullptr) {
...@@ -7609,7 +7541,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7609,7 +7541,7 @@ static void do_code_gen(CodeGen *g) {
7609 } else {7541 } else {
7610 if (want_sret) {7542 if (want_sret) {
7611 g->cur_ret_ptr = LLVMGetParam(fn, 0);7543 g->cur_ret_ptr = LLVMGetParam(fn, 0);
7612 } else if (handle_is_ptr(fn_type_id->return_type)) {7544 } else if (type_has_bits(fn_type_id->return_type)) {
7613 g->cur_ret_ptr = build_alloca(g, fn_type_id->return_type, "result", 0);7545 g->cur_ret_ptr = build_alloca(g, fn_type_id->return_type, "result", 0);
7614 // TODO add debug info variable for this7546 // TODO add debug info variable for this
7615 } else {7547 } else {
...@@ -7643,10 +7575,10 @@ static void do_code_gen(CodeGen *g) {...@@ -7643,10 +7575,10 @@ static void do_code_gen(CodeGen *g) {
7643 if (!is_async) {7575 if (!is_async) {
7644 // allocate async frames for noasync calls & awaits to async functions7576 // allocate async frames for noasync calls & awaits to async functions
7645 ZigType *largest_call_frame_type = nullptr;7577 ZigType *largest_call_frame_type = nullptr;
7646 IrInstruction *all_calls_alloca = ir_create_alloca(g, &fn_table_entry->fndef_scope->base,7578 IrInstGen *all_calls_alloca = ir_create_alloca(g, &fn_table_entry->fndef_scope->base,
7647 fn_table_entry->body_node, fn_table_entry, g->builtin_types.entry_void, "@async_call_frame");7579 fn_table_entry->body_node, fn_table_entry, g->builtin_types.entry_void, "@async_call_frame");
7648 for (size_t i = 0; i < fn_table_entry->call_list.length; i += 1) {7580 for (size_t i = 0; i < fn_table_entry->call_list.length; i += 1) {
7649 IrInstructionCallGen *call = fn_table_entry->call_list.at(i);7581 IrInstGenCall *call = fn_table_entry->call_list.at(i);
7650 if (call->fn_entry == nullptr)7582 if (call->fn_entry == nullptr)
7651 continue;7583 continue;
7652 if (!fn_is_async(call->fn_entry))7584 if (!fn_is_async(call->fn_entry))
...@@ -7668,7 +7600,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7668,7 +7600,7 @@ static void do_code_gen(CodeGen *g) {
7668 }7600 }
7669 // allocate temporary stack data7601 // allocate temporary stack data
7670 for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_gen_list.length; alloca_i += 1) {7602 for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_gen_list.length; alloca_i += 1) {
7671 IrInstructionAllocaGen *instruction = fn_table_entry->alloca_gen_list.at(alloca_i);7603 IrInstGenAlloca *instruction = fn_table_entry->alloca_gen_list.at(alloca_i);
7672 ZigType *ptr_type = instruction->base.value->type;7604 ZigType *ptr_type = instruction->base.value->type;
7673 assert(ptr_type->id == ZigTypeIdPointer);7605 assert(ptr_type->id == ZigTypeIdPointer);
7674 ZigType *child_type = ptr_type->data.pointer.child_type;7606 ZigType *child_type = ptr_type->data.pointer.child_type;
...@@ -7676,7 +7608,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7676,7 +7608,7 @@ static void do_code_gen(CodeGen *g) {
7676 zig_unreachable();7608 zig_unreachable();
7677 if (!type_has_bits(child_type))7609 if (!type_has_bits(child_type))
7678 continue;7610 continue;
7679 if (instruction->base.ref_count == 0)7611 if (instruction->base.base.ref_count == 0)
7680 continue;7612 continue;
7681 if (instruction->base.value->special != ConstValSpecialRuntime) {7613 if (instruction->base.value->special != ConstValSpecialRuntime) {
7682 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=7614 if (const_ptr_pointee(nullptr, g, instruction->base.value, nullptr)->special !=
...@@ -7793,7 +7725,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7793,7 +7725,7 @@ static void do_code_gen(CodeGen *g) {
7793 ZigLLVMSetCurrentDebugLocation(g->builder, (int)source_node->line + 1,7725 ZigLLVMSetCurrentDebugLocation(g->builder, (int)source_node->line + 1,
7794 (int)source_node->column + 1, get_di_scope(g, fn_table_entry->child_scope));7726 (int)source_node->column + 1, get_di_scope(g, fn_table_entry->child_scope));
7795 }7727 }
7796 IrExecutable *executable = &fn_table_entry->analyzed_executable;7728 IrExecutableGen *executable = &fn_table_entry->analyzed_executable;
7797 LLVMBasicBlockRef bad_resume_block = LLVMAppendBasicBlock(g->cur_fn_val, "BadResume");7729 LLVMBasicBlockRef bad_resume_block = LLVMAppendBasicBlock(g->cur_fn_val, "BadResume");
7798 LLVMPositionBuilderAtEnd(g->builder, bad_resume_block);7730 LLVMPositionBuilderAtEnd(g->builder, bad_resume_block);
7799 gen_assertion_scope(g, PanicMsgIdBadResume, fn_table_entry->child_scope);7731 gen_assertion_scope(g, PanicMsgIdBadResume, fn_table_entry->child_scope);
...@@ -7820,7 +7752,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7820,7 +7752,7 @@ static void do_code_gen(CodeGen *g) {
7820 g->cur_async_switch_instr = switch_instr;7752 g->cur_async_switch_instr = switch_instr;
78217753
7822 LLVMValueRef zero = LLVMConstNull(usize_type_ref);7754 LLVMValueRef zero = LLVMConstNull(usize_type_ref);
7823 IrBasicBlock *entry_block = executable->basic_block_list.at(0);7755 IrBasicBlockGen *entry_block = executable->basic_block_list.at(0);
7824 LLVMAddCase(switch_instr, zero, entry_block->llvm_block);7756 LLVMAddCase(switch_instr, zero, entry_block->llvm_block);
7825 g->cur_resume_block_count += 1;7757 g->cur_resume_block_count += 1;
78267758
...@@ -7852,7 +7784,7 @@ static void do_code_gen(CodeGen *g) {...@@ -7852,7 +7784,7 @@ static void do_code_gen(CodeGen *g) {
78527784
7853 gen_init_stack_trace(g, trace_field_ptr, addrs_field_ptr);7785 gen_init_stack_trace(g, trace_field_ptr, addrs_field_ptr);
7854 }7786 }
7855 render_async_var_decls(g, entry_block->instruction_list.at(0)->scope);7787 render_async_var_decls(g, entry_block->instruction_list.at(0)->base.scope);
7856 } else {7788 } else {
7857 // create debug variable declarations for parameters7789 // create debug variable declarations for parameters
7858 // rely on the first variables in the variable_list being parameters.7790 // rely on the first variables in the variable_list being parameters.
...@@ -7941,6 +7873,12 @@ static void zig_llvm_emit_output(CodeGen *g) {...@@ -7941,6 +7873,12 @@ static void zig_llvm_emit_output(CodeGen *g) {
7941 default:7873 default:
7942 zig_unreachable();7874 zig_unreachable();
7943 }7875 }
7876 LLVMDisposeModule(g->module);
7877 g->module = nullptr;
7878 LLVMDisposeTargetData(g->target_data_ref);
7879 g->target_data_ref = nullptr;
7880 LLVMDisposeTargetMachine(g->target_machine);
7881 g->target_machine = nullptr;
7944}7882}
79457883
7946struct CIntTypeInfo {7884struct CIntTypeInfo {
...@@ -8427,6 +8365,25 @@ static bool detect_err_ret_tracing(CodeGen *g) {...@@ -8427,6 +8365,25 @@ static bool detect_err_ret_tracing(CodeGen *g) {
8427 g->build_mode != BuildModeSmallRelease;8365 g->build_mode != BuildModeSmallRelease;
8428}8366}
84298367
8368static LLVMCodeModel to_llvm_code_model(CodeGen *g) {
8369 switch (g->code_model) {
8370 case CodeModelDefault:
8371 return LLVMCodeModelDefault;
8372 case CodeModelTiny:
8373 return LLVMCodeModelTiny;
8374 case CodeModelSmall:
8375 return LLVMCodeModelSmall;
8376 case CodeModelKernel:
8377 return LLVMCodeModelKernel;
8378 case CodeModelMedium:
8379 return LLVMCodeModelMedium;
8380 case CodeModelLarge:
8381 return LLVMCodeModelLarge;
8382 }
8383
8384 zig_unreachable();
8385}
8386
8430Buf *codegen_generate_builtin_source(CodeGen *g) {8387Buf *codegen_generate_builtin_source(CodeGen *g) {
8431 g->have_dynamic_link = detect_dynamic_link(g);8388 g->have_dynamic_link = detect_dynamic_link(g);
8432 g->have_pic = detect_pic(g);8389 g->have_pic = detect_pic(g);
...@@ -8578,6 +8535,17 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -8578,6 +8535,17 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
8578 buf_appendf(contents, "pub const os = Os.%s;\n", cur_os);8535 buf_appendf(contents, "pub const os = Os.%s;\n", cur_os);
8579 buf_appendf(contents, "pub const arch = %s;\n", cur_arch);8536 buf_appendf(contents, "pub const arch = %s;\n", cur_arch);
8580 buf_appendf(contents, "pub const abi = Abi.%s;\n", cur_abi);8537 buf_appendf(contents, "pub const abi = Abi.%s;\n", cur_abi);
8538 {
8539 buf_append_str(contents, "pub const cpu_features: CpuFeatures = ");
8540 if (g->zig_target->cpu_features != nullptr) {
8541 const char *ptr;
8542 size_t len;
8543 stage2_cpu_features_get_builtin_str(g->zig_target->cpu_features, &ptr, &len);
8544 buf_append_mem(contents, ptr, len);
8545 } else {
8546 buf_append_str(contents, "arch.getBaselineCpuFeatures();\n");
8547 }
8548 }
8581 if (g->libc_link_lib != nullptr && g->zig_target->glibc_version != nullptr) {8549 if (g->libc_link_lib != nullptr && g->zig_target->glibc_version != nullptr) {
8582 buf_appendf(contents,8550 buf_appendf(contents,
8583 "pub const glibc_version: ?Version = Version{.major = %d, .minor = %d, .patch = %d};\n",8551 "pub const glibc_version: ?Version = Version{.major = %d, .minor = %d, .patch = %d};\n",
...@@ -8595,6 +8563,34 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -8595,6 +8563,34 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
8595 buf_appendf(contents, "pub const position_independent_code = %s;\n", bool_to_str(g->have_pic));8563 buf_appendf(contents, "pub const position_independent_code = %s;\n", bool_to_str(g->have_pic));
8596 buf_appendf(contents, "pub const strip_debug_info = %s;\n", bool_to_str(g->strip_debug_symbols));8564 buf_appendf(contents, "pub const strip_debug_info = %s;\n", bool_to_str(g->strip_debug_symbols));
85978565
8566 {
8567 const char *code_model;
8568 switch (g->code_model) {
8569 case CodeModelDefault:
8570 code_model = "default";
8571 break;
8572 case CodeModelTiny:
8573 code_model = "tiny";
8574 break;
8575 case CodeModelSmall:
8576 code_model = "small";
8577 break;
8578 case CodeModelKernel:
8579 code_model = "kernel";
8580 break;
8581 case CodeModelMedium:
8582 code_model = "medium";
8583 break;
8584 case CodeModelLarge:
8585 code_model = "large";
8586 break;
8587 default:
8588 zig_unreachable();
8589 }
8590
8591 buf_appendf(contents, "pub const code_model = CodeModel.%s;\n", code_model);
8592 }
8593
8598 {8594 {
8599 TargetSubsystem detected_subsystem = detect_subsystem(g);8595 TargetSubsystem detected_subsystem = detect_subsystem(g);
8600 if (detected_subsystem != TargetSubsystemAuto) {8596 if (detected_subsystem != TargetSubsystemAuto) {
...@@ -8639,12 +8635,19 @@ static Error define_builtin_compile_vars(CodeGen *g) {...@@ -8639,12 +8635,19 @@ static Error define_builtin_compile_vars(CodeGen *g) {
8639 cache_bool(&cache_hash, g->is_dynamic);8635 cache_bool(&cache_hash, g->is_dynamic);
8640 cache_bool(&cache_hash, g->is_test_build);8636 cache_bool(&cache_hash, g->is_test_build);
8641 cache_bool(&cache_hash, g->is_single_threaded);8637 cache_bool(&cache_hash, g->is_single_threaded);
8638 cache_int(&cache_hash, g->code_model);
8642 cache_int(&cache_hash, g->zig_target->is_native);8639 cache_int(&cache_hash, g->zig_target->is_native);
8643 cache_int(&cache_hash, g->zig_target->arch);8640 cache_int(&cache_hash, g->zig_target->arch);
8644 cache_int(&cache_hash, g->zig_target->sub_arch);8641 cache_int(&cache_hash, g->zig_target->sub_arch);
8645 cache_int(&cache_hash, g->zig_target->vendor);8642 cache_int(&cache_hash, g->zig_target->vendor);
8646 cache_int(&cache_hash, g->zig_target->os);8643 cache_int(&cache_hash, g->zig_target->os);
8647 cache_int(&cache_hash, g->zig_target->abi);8644 cache_int(&cache_hash, g->zig_target->abi);
8645 if (g->zig_target->cpu_features != nullptr) {
8646 const char *ptr;
8647 size_t len;
8648 stage2_cpu_features_get_cache_hash(g->zig_target->cpu_features, &ptr, &len);
8649 cache_str(&cache_hash, ptr);
8650 }
8648 if (g->zig_target->glibc_version != nullptr) {8651 if (g->zig_target->glibc_version != nullptr) {
8649 cache_int(&cache_hash, g->zig_target->glibc_version->major);8652 cache_int(&cache_hash, g->zig_target->glibc_version->major);
8650 cache_int(&cache_hash, g->zig_target->glibc_version->minor);8653 cache_int(&cache_hash, g->zig_target->glibc_version->minor);
...@@ -8769,40 +8772,28 @@ static void init(CodeGen *g) {...@@ -8769,40 +8772,28 @@ static void init(CodeGen *g) {
8769 reloc_mode = LLVMRelocStatic;8772 reloc_mode = LLVMRelocStatic;
8770 }8773 }
87718774
8772 const char *target_specific_cpu_args;8775 const char *target_specific_cpu_args = "";
8773 const char *target_specific_features;8776 const char *target_specific_features = "";
8777
8774 if (g->zig_target->is_native) {8778 if (g->zig_target->is_native) {
8775 // LLVM creates invalid binaries on Windows sometimes.8779 target_specific_cpu_args = ZigLLVMGetHostCPUName();
8776 // See https://github.com/ziglang/zig/issues/5088780 target_specific_features = ZigLLVMGetNativeFeatures();
8777 // As a workaround we do not use target native features on Windows.
8778 if (g->zig_target->os == OsWindows || g->zig_target->os == OsUefi) {
8779 target_specific_cpu_args = "";
8780 target_specific_features = "";
8781 } else {
8782 target_specific_cpu_args = ZigLLVMGetHostCPUName();
8783 target_specific_features = ZigLLVMGetNativeFeatures();
8784 }
8785 } else if (target_is_riscv(g->zig_target)) {
8786 // TODO https://github.com/ziglang/zig/issues/2883
8787 // Be aware of https://github.com/ziglang/zig/issues/3275
8788 target_specific_cpu_args = "";
8789 target_specific_features = riscv_default_features;
8790 } else if (g->zig_target->arch == ZigLLVM_x86) {
8791 // This is because we're really targeting i686 rather than i386.
8792 // It's pretty much impossible to use many of the language features
8793 // such as fp16 if you stick use the x87 only. This is also what clang
8794 // uses as base cpu.
8795 // TODO https://github.com/ziglang/zig/issues/2883
8796 target_specific_cpu_args = "pentium4";
8797 target_specific_features = (g->zig_target->os == OsFreestanding) ? "-sse": "";
8798 } else {
8799 target_specific_cpu_args = "";
8800 target_specific_features = "";
8801 }8781 }
88028782
8783 // Override CPU and features if defined by user.
8784 if (g->zig_target->cpu_features != nullptr) {
8785 target_specific_cpu_args = stage2_cpu_features_get_llvm_cpu(g->zig_target->cpu_features);
8786 target_specific_features = stage2_cpu_features_get_llvm_features(g->zig_target->cpu_features);
8787 }
8788 if (g->verbose_llvm_cpu_features) {
8789 fprintf(stderr, "name=%s triple=%s\n", buf_ptr(g->root_out_name), buf_ptr(&g->llvm_triple_str));
8790 fprintf(stderr, "name=%s target_specific_cpu_args=%s\n", buf_ptr(g->root_out_name), target_specific_cpu_args);
8791 fprintf(stderr, "name=%s target_specific_features=%s\n", buf_ptr(g->root_out_name), target_specific_features);
8792 }
8793
8803 g->target_machine = ZigLLVMCreateTargetMachine(target_ref, buf_ptr(&g->llvm_triple_str),8794 g->target_machine = ZigLLVMCreateTargetMachine(target_ref, buf_ptr(&g->llvm_triple_str),
8804 target_specific_cpu_args, target_specific_features, opt_level, reloc_mode,8795 target_specific_cpu_args, target_specific_features, opt_level, reloc_mode,
8805 LLVMCodeModelDefault, g->function_sections);8796 to_llvm_code_model(g), g->function_sections);
88068797
8807 g->target_data_ref = LLVMCreateTargetDataLayout(g->target_machine);8798 g->target_data_ref = LLVMCreateTargetDataLayout(g->target_machine);
88088799
...@@ -8846,15 +8837,17 @@ static void init(CodeGen *g) {...@@ -8846,15 +8837,17 @@ static void init(CodeGen *g) {
8846 define_builtin_types(g);8837 define_builtin_types(g);
8847 define_intern_values(g);8838 define_intern_values(g);
88488839
8849 IrInstruction *sentinel_instructions = allocate<IrInstruction>(2);8840 IrInstGen *sentinel_instructions = allocate<IrInstGen>(2);
8850 g->invalid_instruction = &sentinel_instructions[0];8841 g->invalid_inst_gen = &sentinel_instructions[0];
8851 g->invalid_instruction->value = allocate<ZigValue>(1, "ZigValue");8842 g->invalid_inst_gen->value = allocate<ZigValue>(1, "ZigValue");
8852 g->invalid_instruction->value->type = g->builtin_types.entry_invalid;8843 g->invalid_inst_gen->value->type = g->builtin_types.entry_invalid;
88538844
8854 g->unreach_instruction = &sentinel_instructions[1];8845 g->unreach_instruction = &sentinel_instructions[1];
8855 g->unreach_instruction->value = allocate<ZigValue>(1, "ZigValue");8846 g->unreach_instruction->value = allocate<ZigValue>(1, "ZigValue");
8856 g->unreach_instruction->value->type = g->builtin_types.entry_unreachable;8847 g->unreach_instruction->value->type = g->builtin_types.entry_unreachable;
88578848
8849 g->invalid_inst_src = allocate<IrInstSrc>(1);
8850
8858 define_builtin_fns(g);8851 define_builtin_fns(g);
8859 Error err;8852 Error err;
8860 if ((err = define_builtin_compile_vars(g))) {8853 if ((err = define_builtin_compile_vars(g))) {
...@@ -8996,7 +8989,10 @@ static void detect_libc(CodeGen *g) {...@@ -8996,7 +8989,10 @@ static void detect_libc(CodeGen *g) {
8996 "See `zig libc --help` for more details.\n", err_str(err));8989 "See `zig libc --help` for more details.\n", err_str(err));
8997 exit(1);8990 exit(1);
8998 }8991 }
8999 if ((err = os_make_path(g->cache_dir))) {8992 Buf libc_txt_dir = BUF_INIT;
8993 os_path_dirname(libc_txt, &libc_txt_dir);
8994 buf_deinit(&libc_txt_dir);
8995 if ((err = os_make_path(&libc_txt_dir))) {
9000 fprintf(stderr, "Unable to create %s directory: %s\n",8996 fprintf(stderr, "Unable to create %s directory: %s\n",
9001 buf_ptr(g->cache_dir), err_str(err));8997 buf_ptr(g->cache_dir), err_str(err));
9002 exit(1);8998 exit(1);
...@@ -9125,21 +9121,22 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa...@@ -9125,21 +9121,22 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa
9125 args.append("-target");9121 args.append("-target");
9126 args.append(buf_ptr(&g->llvm_triple_str));9122 args.append(buf_ptr(&g->llvm_triple_str));
91279123
9128 if (target_is_musl(g->zig_target) && target_is_riscv(g->zig_target)) {9124 const char *llvm_cpu = stage2_cpu_features_get_llvm_cpu(g->zig_target->cpu_features);
9129 // Musl depends on atomic instructions, which are disabled by default in Clang/LLVM's9125 if (llvm_cpu != nullptr) {
9130 // cross compilation CPU info for RISCV.
9131 // TODO: https://github.com/ziglang/zig/issues/2883
9132 args.append("-Xclang");9126 args.append("-Xclang");
9133 args.append("-target-feature");9127 args.append("-target-cpu");
9134 args.append("-Xclang");9128 args.append("-Xclang");
9135 args.append(riscv_default_features);9129 args.append(llvm_cpu);
9136 } else if (g->zig_target->os == OsFreestanding && g->zig_target->arch == ZigLLVM_x86) {9130 }
9131 const char *llvm_target_features = stage2_cpu_features_get_llvm_features(g->zig_target->cpu_features);
9132 if (llvm_target_features != nullptr) {
9137 args.append("-Xclang");9133 args.append("-Xclang");
9138 args.append("-target-feature");9134 args.append("-target-feature");
9139 args.append("-Xclang");9135 args.append("-Xclang");
9140 args.append("-sse");9136 args.append(llvm_target_features);
9141 }9137 }
9142 }9138 }
9139
9143 if (g->zig_target->os == OsFreestanding) {9140 if (g->zig_target->os == OsFreestanding) {
9144 args.append("-ffreestanding");9141 args.append("-ffreestanding");
9145 }9142 }
...@@ -9578,6 +9575,8 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose...@@ -9578,6 +9575,8 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose
9578 cache_bool(cache_hash, g->have_sanitize_c);9575 cache_bool(cache_hash, g->have_sanitize_c);
9579 cache_bool(cache_hash, want_valgrind_support(g));9576 cache_bool(cache_hash, want_valgrind_support(g));
9580 cache_bool(cache_hash, g->function_sections);9577 cache_bool(cache_hash, g->function_sections);
9578 cache_int(cache_hash, g->code_model);
9579
9581 for (size_t arg_i = 0; arg_i < g->clang_argv_len; arg_i += 1) {9580 for (size_t arg_i = 0; arg_i < g->clang_argv_len; arg_i += 1) {
9582 cache_str(cache_hash, g->clang_argv[arg_i]);9581 cache_str(cache_hash, g->clang_argv[arg_i]);
9583 }9582 }
...@@ -9787,6 +9786,7 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e...@@ -9787,6 +9786,7 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e
9787 zig_unreachable();9786 zig_unreachable();
9788 case ZigTypeIdVoid:9787 case ZigTypeIdVoid:
9789 case ZigTypeIdUnreachable:9788 case ZigTypeIdUnreachable:
9789 return;
9790 case ZigTypeIdBool:9790 case ZigTypeIdBool:
9791 g->c_want_stdbool = true;9791 g->c_want_stdbool = true;
9792 return;9792 return;
...@@ -10333,6 +10333,12 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {...@@ -10333,6 +10333,12 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
10333 cache_int(ch, g->zig_target->vendor);10333 cache_int(ch, g->zig_target->vendor);
10334 cache_int(ch, g->zig_target->os);10334 cache_int(ch, g->zig_target->os);
10335 cache_int(ch, g->zig_target->abi);10335 cache_int(ch, g->zig_target->abi);
10336 if (g->zig_target->cpu_features != nullptr) {
10337 const char *ptr;
10338 size_t len;
10339 stage2_cpu_features_get_cache_hash(g->zig_target->cpu_features, &ptr, &len);
10340 cache_str(ch, ptr);
10341 }
10336 if (g->zig_target->glibc_version != nullptr) {10342 if (g->zig_target->glibc_version != nullptr) {
10337 cache_int(ch, g->zig_target->glibc_version->major);10343 cache_int(ch, g->zig_target->glibc_version->major);
10338 cache_int(ch, g->zig_target->glibc_version->minor);10344 cache_int(ch, g->zig_target->glibc_version->minor);
...@@ -10673,6 +10679,7 @@ CodeGen *create_child_codegen(CodeGen *parent_gen, Buf *root_src_path, OutType o...@@ -10673,6 +10679,7 @@ CodeGen *create_child_codegen(CodeGen *parent_gen, Buf *root_src_path, OutType o
10673 child_gen->verbose_llvm_ir = parent_gen->verbose_llvm_ir;10679 child_gen->verbose_llvm_ir = parent_gen->verbose_llvm_ir;
10674 child_gen->verbose_cimport = parent_gen->verbose_cimport;10680 child_gen->verbose_cimport = parent_gen->verbose_cimport;
10675 child_gen->verbose_cc = parent_gen->verbose_cc;10681 child_gen->verbose_cc = parent_gen->verbose_cc;
10682 child_gen->verbose_llvm_cpu_features = parent_gen->verbose_llvm_cpu_features;
10676 child_gen->llvm_argv = parent_gen->llvm_argv;10683 child_gen->llvm_argv = parent_gen->llvm_argv;
10677 child_gen->dynamic_linker_path = parent_gen->dynamic_linker_path;10684 child_gen->dynamic_linker_path = parent_gen->dynamic_linker_path;
1067810685
...@@ -10739,6 +10746,7 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget...@@ -10739,6 +10746,7 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget
10739 g->one_possible_values.init(32);10746 g->one_possible_values.init(32);
10740 g->is_test_build = is_test_build;10747 g->is_test_build = is_test_build;
10741 g->is_single_threaded = false;10748 g->is_single_threaded = false;
10749 g->code_model = CodeModelDefault;
10742 buf_resize(&g->global_asm, 0);10750 buf_resize(&g->global_asm, 0);
1074310751
10744 for (size_t i = 0; i < array_length(symbols_that_llvm_depends_on); i += 1) {10752 for (size_t i = 0; i < array_length(symbols_that_llvm_depends_on); i += 1) {
src/error.cpp+6
...@@ -58,6 +58,12 @@ const char *err_str(Error err) {...@@ -58,6 +58,12 @@ const char *err_str(Error err) {
58 case ErrorNotLazy: return "not lazy";58 case ErrorNotLazy: return "not lazy";
59 case ErrorIsAsync: return "is async";59 case ErrorIsAsync: return "is async";
60 case ErrorImportOutsidePkgPath: return "import of file outside package path";60 case ErrorImportOutsidePkgPath: return "import of file outside package path";
61 case ErrorUnknownCpu: return "unknown CPU";
62 case ErrorUnknownSubArchitecture: return "unknown sub-architecture";
63 case ErrorUnknownCpuFeature: return "unknown CPU feature";
64 case ErrorInvalidCpuFeatures: return "invalid CPU features";
65 case ErrorInvalidLlvmCpuFeaturesFormat: return "invalid LLVM CPU features format";
66 case ErrorUnknownApplicationBinaryInterface: return "unknown application binary interface";
61 }67 }
62 return "(invalid error)";68 return "(invalid error)";
63}69}
src/ir.cpp+7726-6731
...@@ -17,31 +17,33 @@...@@ -17,31 +17,33 @@
1717
18#include <errno.h>18#include <errno.h>
1919
20struct IrExecContext {20struct IrBuilderSrc {
21 ZigList<ZigValue *> mem_slot_list;21 CodeGen *codegen;
22 IrExecutableSrc *exec;
23 IrBasicBlockSrc *current_basic_block;
24 AstNode *main_block_node;
22};25};
2326
24struct IrBuilder {27struct IrBuilderGen {
25 CodeGen *codegen;28 CodeGen *codegen;
26 IrExecutable *exec;29 IrExecutableGen *exec;
27 IrBasicBlock *current_basic_block;30 IrBasicBlockGen *current_basic_block;
28 AstNode *main_block_node;
29};31};
3032
31struct IrAnalyze {33struct IrAnalyze {
32 CodeGen *codegen;34 CodeGen *codegen;
33 IrBuilder old_irb;35 IrBuilderSrc old_irb;
34 IrBuilder new_irb;36 IrBuilderGen new_irb;
35 IrExecContext exec_context;
36 size_t old_bb_index;37 size_t old_bb_index;
37 size_t instruction_index;38 size_t instruction_index;
38 ZigType *explicit_return_type;39 ZigType *explicit_return_type;
39 AstNode *explicit_return_type_source_node;40 AstNode *explicit_return_type_source_node;
40 ZigList<IrInstruction *> src_implicit_return_type_list;41 ZigList<IrInstGen *> src_implicit_return_type_list;
41 ZigList<IrSuspendPosition> resume_stack;42 ZigList<IrSuspendPosition> resume_stack;
42 IrBasicBlock *const_predecessor_bb;43 IrBasicBlockSrc *const_predecessor_bb;
43 size_t ref_count;44 size_t ref_count;
44 size_t break_debug_id; // for debugging purposes45 size_t break_debug_id; // for debugging purposes
46 IrInstGen *return_ptr;
4547
46 // For the purpose of using in a debugger48 // For the purpose of using in a debugger
47 void dump();49 void dump();
...@@ -206,412 +208,538 @@ struct DbgIrBreakPoint {...@@ -206,412 +208,538 @@ struct DbgIrBreakPoint {
206DbgIrBreakPoint dbg_ir_breakpoints_buf[20];208DbgIrBreakPoint dbg_ir_breakpoints_buf[20];
207size_t dbg_ir_breakpoints_count = 0;209size_t dbg_ir_breakpoints_count = 0;
208210
209static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope);211static IrInstSrc *ir_gen_node(IrBuilderSrc *irb, AstNode *node, Scope *scope);
210static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval,212static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *scope, LVal lval,
211 ResultLoc *result_loc);213 ResultLoc *result_loc);
212static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type);214static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *expected_type);
213static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_source_instr,215static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr,
214 IrInstruction *value, ZigType *expected_type);216 IrInstGen *value, ZigType *expected_type);
215static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr,217static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst *source_instr, IrInstGen *ptr,
216 ResultLoc *result_loc);218 ResultLoc *result_loc);
217static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg);219static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutableSrc *exec, AstNode *source_node, Buf *msg);
218static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,220static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
219 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type, bool initializing);221 IrInst* source_instr, IrInstGen *container_ptr, IrInst *container_ptr_src,
220static void ir_assert(bool ok, IrInstruction *source_instruction);222 ZigType *container_type, bool initializing);
221static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var);223static void ir_assert(bool ok, IrInst* source_instruction);
222static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op);224static void ir_assert_gen(bool ok, IrInstGen *source_instruction);
223static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval, ResultLoc *result_loc);225static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var);
224static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc);226static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op);
227static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value, LVal lval, ResultLoc *result_loc);
228static IrInstSrc *ir_expr_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc);
225static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);229static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align);
226static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align);230static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align);
227static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ZigValue *val);231static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ZigValue *val);
228static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val);232static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val);
229static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,233static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
230 ZigValue *out_val, ZigValue *ptr_val);234 ZigValue *out_val, ZigValue *ptr_val);
231static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr,235static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr,
232 ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on);236 IrInst *ptr_src, ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on);
233static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed);237static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed);
234static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);238static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align);
235static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,239static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,
236 ZigType *ptr_type);240 ZigType *ptr_type);
237static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,241static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,
238 ZigType *dest_type);242 ZigType *dest_type);
239static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,243static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr,
240 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,244 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, bool allow_discard);
241 bool non_null_comptime, bool allow_discard);245static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr,
242static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr,246 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime, bool allow_discard);
243 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,247static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr,
244 bool non_null_comptime, bool allow_discard);248 IrInstGen *base_ptr, bool safety_check_on, bool initializing);
245static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr,249static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source_instr,
246 IrInstruction *base_ptr, bool safety_check_on, bool initializing);250 IrInstGen *base_ptr, bool safety_check_on, bool initializing);
247static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr,251static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_instr,
248 IrInstruction *base_ptr, bool safety_check_on, bool initializing);252 IrInstGen *base_ptr, bool initializing);
249static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *source_instr,253static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
250 IrInstruction *base_ptr, bool initializing);254 IrInstGen *ptr, IrInstGen *uncasted_value, bool allow_write_through_const);
251static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr,255static IrInstSrc *ir_gen_union_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
252 IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const);256 IrInstSrc *union_type, IrInstSrc *field_name, AstNode *expr_node,
253static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNode *source_node,
254 IrInstruction *union_type, IrInstruction *field_name, AstNode *expr_node,
255 LVal lval, ResultLoc *parent_result_loc);257 LVal lval, ResultLoc *parent_result_loc);
256static void ir_reset_result(ResultLoc *result_loc);258static void ir_reset_result(ResultLoc *result_loc);
257static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name,259static Buf *get_anon_type_name(CodeGen *codegen, IrExecutableSrc *exec, const char *kind_name,
258 Scope *scope, AstNode *source_node, Buf *out_bare_name);260 Scope *scope, AstNode *source_node, Buf *out_bare_name);
259static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *dest_type,261static ResultLocCast *ir_build_cast_result_loc(IrBuilderSrc *irb, IrInstSrc *dest_type,
260 ResultLoc *parent_result_loc);262 ResultLoc *parent_result_loc);
261static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction *source_instr,263static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_instr,
262 TypeStructField *field, IrInstruction *struct_ptr, ZigType *struct_type, bool initializing);264 TypeStructField *field, IrInstGen *struct_ptr, ZigType *struct_type, bool initializing);
263static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,265static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
264 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type);266 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type);
265static ResultLoc *no_result_loc(void);267static ResultLoc *no_result_loc(void);
266static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *source_inst, IrInstruction *value);268static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value);
269static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst *source_instr);
270
271static void destroy_instruction_src(IrInstSrc *inst) {
272#ifdef ZIG_ENABLE_MEM_PROFILE
273 const char *name = ir_inst_src_type_str(inst->id);
274#else
275 const char *name = nullptr;
276#endif
277 switch (inst->id) {
278 case IrInstSrcIdInvalid:
279 zig_unreachable();
280 case IrInstSrcIdReturn:
281 return destroy(reinterpret_cast<IrInstSrcReturn *>(inst), name);
282 case IrInstSrcIdConst:
283 return destroy(reinterpret_cast<IrInstSrcConst *>(inst), name);
284 case IrInstSrcIdBinOp:
285 return destroy(reinterpret_cast<IrInstSrcBinOp *>(inst), name);
286 case IrInstSrcIdMergeErrSets:
287 return destroy(reinterpret_cast<IrInstSrcMergeErrSets *>(inst), name);
288 case IrInstSrcIdDeclVar:
289 return destroy(reinterpret_cast<IrInstSrcDeclVar *>(inst), name);
290 case IrInstSrcIdCall:
291 return destroy(reinterpret_cast<IrInstSrcCall *>(inst), name);
292 case IrInstSrcIdCallExtra:
293 return destroy(reinterpret_cast<IrInstSrcCallExtra *>(inst), name);
294 case IrInstSrcIdUnOp:
295 return destroy(reinterpret_cast<IrInstSrcUnOp *>(inst), name);
296 case IrInstSrcIdCondBr:
297 return destroy(reinterpret_cast<IrInstSrcCondBr *>(inst), name);
298 case IrInstSrcIdBr:
299 return destroy(reinterpret_cast<IrInstSrcBr *>(inst), name);
300 case IrInstSrcIdPhi:
301 return destroy(reinterpret_cast<IrInstSrcPhi *>(inst), name);
302 case IrInstSrcIdContainerInitList:
303 return destroy(reinterpret_cast<IrInstSrcContainerInitList *>(inst), name);
304 case IrInstSrcIdContainerInitFields:
305 return destroy(reinterpret_cast<IrInstSrcContainerInitFields *>(inst), name);
306 case IrInstSrcIdUnreachable:
307 return destroy(reinterpret_cast<IrInstSrcUnreachable *>(inst), name);
308 case IrInstSrcIdElemPtr:
309 return destroy(reinterpret_cast<IrInstSrcElemPtr *>(inst), name);
310 case IrInstSrcIdVarPtr:
311 return destroy(reinterpret_cast<IrInstSrcVarPtr *>(inst), name);
312 case IrInstSrcIdLoadPtr:
313 return destroy(reinterpret_cast<IrInstSrcLoadPtr *>(inst), name);
314 case IrInstSrcIdStorePtr:
315 return destroy(reinterpret_cast<IrInstSrcStorePtr *>(inst), name);
316 case IrInstSrcIdTypeOf:
317 return destroy(reinterpret_cast<IrInstSrcTypeOf *>(inst), name);
318 case IrInstSrcIdFieldPtr:
319 return destroy(reinterpret_cast<IrInstSrcFieldPtr *>(inst), name);
320 case IrInstSrcIdSetCold:
321 return destroy(reinterpret_cast<IrInstSrcSetCold *>(inst), name);
322 case IrInstSrcIdSetRuntimeSafety:
323 return destroy(reinterpret_cast<IrInstSrcSetRuntimeSafety *>(inst), name);
324 case IrInstSrcIdSetFloatMode:
325 return destroy(reinterpret_cast<IrInstSrcSetFloatMode *>(inst), name);
326 case IrInstSrcIdArrayType:
327 return destroy(reinterpret_cast<IrInstSrcArrayType *>(inst), name);
328 case IrInstSrcIdSliceType:
329 return destroy(reinterpret_cast<IrInstSrcSliceType *>(inst), name);
330 case IrInstSrcIdAnyFrameType:
331 return destroy(reinterpret_cast<IrInstSrcAnyFrameType *>(inst), name);
332 case IrInstSrcIdAsm:
333 return destroy(reinterpret_cast<IrInstSrcAsm *>(inst), name);
334 case IrInstSrcIdSizeOf:
335 return destroy(reinterpret_cast<IrInstSrcSizeOf *>(inst), name);
336 case IrInstSrcIdTestNonNull:
337 return destroy(reinterpret_cast<IrInstSrcTestNonNull *>(inst), name);
338 case IrInstSrcIdOptionalUnwrapPtr:
339 return destroy(reinterpret_cast<IrInstSrcOptionalUnwrapPtr *>(inst), name);
340 case IrInstSrcIdPopCount:
341 return destroy(reinterpret_cast<IrInstSrcPopCount *>(inst), name);
342 case IrInstSrcIdClz:
343 return destroy(reinterpret_cast<IrInstSrcClz *>(inst), name);
344 case IrInstSrcIdCtz:
345 return destroy(reinterpret_cast<IrInstSrcCtz *>(inst), name);
346 case IrInstSrcIdBswap:
347 return destroy(reinterpret_cast<IrInstSrcBswap *>(inst), name);
348 case IrInstSrcIdBitReverse:
349 return destroy(reinterpret_cast<IrInstSrcBitReverse *>(inst), name);
350 case IrInstSrcIdSwitchBr:
351 return destroy(reinterpret_cast<IrInstSrcSwitchBr *>(inst), name);
352 case IrInstSrcIdSwitchVar:
353 return destroy(reinterpret_cast<IrInstSrcSwitchVar *>(inst), name);
354 case IrInstSrcIdSwitchElseVar:
355 return destroy(reinterpret_cast<IrInstSrcSwitchElseVar *>(inst), name);
356 case IrInstSrcIdSwitchTarget:
357 return destroy(reinterpret_cast<IrInstSrcSwitchTarget *>(inst), name);
358 case IrInstSrcIdImport:
359 return destroy(reinterpret_cast<IrInstSrcImport *>(inst), name);
360 case IrInstSrcIdRef:
361 return destroy(reinterpret_cast<IrInstSrcRef *>(inst), name);
362 case IrInstSrcIdCompileErr:
363 return destroy(reinterpret_cast<IrInstSrcCompileErr *>(inst), name);
364 case IrInstSrcIdCompileLog:
365 return destroy(reinterpret_cast<IrInstSrcCompileLog *>(inst), name);
366 case IrInstSrcIdErrName:
367 return destroy(reinterpret_cast<IrInstSrcErrName *>(inst), name);
368 case IrInstSrcIdCImport:
369 return destroy(reinterpret_cast<IrInstSrcCImport *>(inst), name);
370 case IrInstSrcIdCInclude:
371 return destroy(reinterpret_cast<IrInstSrcCInclude *>(inst), name);
372 case IrInstSrcIdCDefine:
373 return destroy(reinterpret_cast<IrInstSrcCDefine *>(inst), name);
374 case IrInstSrcIdCUndef:
375 return destroy(reinterpret_cast<IrInstSrcCUndef *>(inst), name);
376 case IrInstSrcIdEmbedFile:
377 return destroy(reinterpret_cast<IrInstSrcEmbedFile *>(inst), name);
378 case IrInstSrcIdCmpxchg:
379 return destroy(reinterpret_cast<IrInstSrcCmpxchg *>(inst), name);
380 case IrInstSrcIdFence:
381 return destroy(reinterpret_cast<IrInstSrcFence *>(inst), name);
382 case IrInstSrcIdTruncate:
383 return destroy(reinterpret_cast<IrInstSrcTruncate *>(inst), name);
384 case IrInstSrcIdIntCast:
385 return destroy(reinterpret_cast<IrInstSrcIntCast *>(inst), name);
386 case IrInstSrcIdFloatCast:
387 return destroy(reinterpret_cast<IrInstSrcFloatCast *>(inst), name);
388 case IrInstSrcIdErrSetCast:
389 return destroy(reinterpret_cast<IrInstSrcErrSetCast *>(inst), name);
390 case IrInstSrcIdFromBytes:
391 return destroy(reinterpret_cast<IrInstSrcFromBytes *>(inst), name);
392 case IrInstSrcIdToBytes:
393 return destroy(reinterpret_cast<IrInstSrcToBytes *>(inst), name);
394 case IrInstSrcIdIntToFloat:
395 return destroy(reinterpret_cast<IrInstSrcIntToFloat *>(inst), name);
396 case IrInstSrcIdFloatToInt:
397 return destroy(reinterpret_cast<IrInstSrcFloatToInt *>(inst), name);
398 case IrInstSrcIdBoolToInt:
399 return destroy(reinterpret_cast<IrInstSrcBoolToInt *>(inst), name);
400 case IrInstSrcIdIntType:
401 return destroy(reinterpret_cast<IrInstSrcIntType *>(inst), name);
402 case IrInstSrcIdVectorType:
403 return destroy(reinterpret_cast<IrInstSrcVectorType *>(inst), name);
404 case IrInstSrcIdShuffleVector:
405 return destroy(reinterpret_cast<IrInstSrcShuffleVector *>(inst), name);
406 case IrInstSrcIdSplat:
407 return destroy(reinterpret_cast<IrInstSrcSplat *>(inst), name);
408 case IrInstSrcIdBoolNot:
409 return destroy(reinterpret_cast<IrInstSrcBoolNot *>(inst), name);
410 case IrInstSrcIdMemset:
411 return destroy(reinterpret_cast<IrInstSrcMemset *>(inst), name);
412 case IrInstSrcIdMemcpy:
413 return destroy(reinterpret_cast<IrInstSrcMemcpy *>(inst), name);
414 case IrInstSrcIdSlice:
415 return destroy(reinterpret_cast<IrInstSrcSlice *>(inst), name);
416 case IrInstSrcIdMemberCount:
417 return destroy(reinterpret_cast<IrInstSrcMemberCount *>(inst), name);
418 case IrInstSrcIdMemberType:
419 return destroy(reinterpret_cast<IrInstSrcMemberType *>(inst), name);
420 case IrInstSrcIdMemberName:
421 return destroy(reinterpret_cast<IrInstSrcMemberName *>(inst), name);
422 case IrInstSrcIdBreakpoint:
423 return destroy(reinterpret_cast<IrInstSrcBreakpoint *>(inst), name);
424 case IrInstSrcIdReturnAddress:
425 return destroy(reinterpret_cast<IrInstSrcReturnAddress *>(inst), name);
426 case IrInstSrcIdFrameAddress:
427 return destroy(reinterpret_cast<IrInstSrcFrameAddress *>(inst), name);
428 case IrInstSrcIdFrameHandle:
429 return destroy(reinterpret_cast<IrInstSrcFrameHandle *>(inst), name);
430 case IrInstSrcIdFrameType:
431 return destroy(reinterpret_cast<IrInstSrcFrameType *>(inst), name);
432 case IrInstSrcIdFrameSize:
433 return destroy(reinterpret_cast<IrInstSrcFrameSize *>(inst), name);
434 case IrInstSrcIdAlignOf:
435 return destroy(reinterpret_cast<IrInstSrcAlignOf *>(inst), name);
436 case IrInstSrcIdOverflowOp:
437 return destroy(reinterpret_cast<IrInstSrcOverflowOp *>(inst), name);
438 case IrInstSrcIdTestErr:
439 return destroy(reinterpret_cast<IrInstSrcTestErr *>(inst), name);
440 case IrInstSrcIdUnwrapErrCode:
441 return destroy(reinterpret_cast<IrInstSrcUnwrapErrCode *>(inst), name);
442 case IrInstSrcIdUnwrapErrPayload:
443 return destroy(reinterpret_cast<IrInstSrcUnwrapErrPayload *>(inst), name);
444 case IrInstSrcIdFnProto:
445 return destroy(reinterpret_cast<IrInstSrcFnProto *>(inst), name);
446 case IrInstSrcIdTestComptime:
447 return destroy(reinterpret_cast<IrInstSrcTestComptime *>(inst), name);
448 case IrInstSrcIdPtrCast:
449 return destroy(reinterpret_cast<IrInstSrcPtrCast *>(inst), name);
450 case IrInstSrcIdBitCast:
451 return destroy(reinterpret_cast<IrInstSrcBitCast *>(inst), name);
452 case IrInstSrcIdPtrToInt:
453 return destroy(reinterpret_cast<IrInstSrcPtrToInt *>(inst), name);
454 case IrInstSrcIdIntToPtr:
455 return destroy(reinterpret_cast<IrInstSrcIntToPtr *>(inst), name);
456 case IrInstSrcIdIntToEnum:
457 return destroy(reinterpret_cast<IrInstSrcIntToEnum *>(inst), name);
458 case IrInstSrcIdIntToErr:
459 return destroy(reinterpret_cast<IrInstSrcIntToErr *>(inst), name);
460 case IrInstSrcIdErrToInt:
461 return destroy(reinterpret_cast<IrInstSrcErrToInt *>(inst), name);
462 case IrInstSrcIdCheckSwitchProngs:
463 return destroy(reinterpret_cast<IrInstSrcCheckSwitchProngs *>(inst), name);
464 case IrInstSrcIdCheckStatementIsVoid:
465 return destroy(reinterpret_cast<IrInstSrcCheckStatementIsVoid *>(inst), name);
466 case IrInstSrcIdTypeName:
467 return destroy(reinterpret_cast<IrInstSrcTypeName *>(inst), name);
468 case IrInstSrcIdTagName:
469 return destroy(reinterpret_cast<IrInstSrcTagName *>(inst), name);
470 case IrInstSrcIdPtrType:
471 return destroy(reinterpret_cast<IrInstSrcPtrType *>(inst), name);
472 case IrInstSrcIdDeclRef:
473 return destroy(reinterpret_cast<IrInstSrcDeclRef *>(inst), name);
474 case IrInstSrcIdPanic:
475 return destroy(reinterpret_cast<IrInstSrcPanic *>(inst), name);
476 case IrInstSrcIdFieldParentPtr:
477 return destroy(reinterpret_cast<IrInstSrcFieldParentPtr *>(inst), name);
478 case IrInstSrcIdByteOffsetOf:
479 return destroy(reinterpret_cast<IrInstSrcByteOffsetOf *>(inst), name);
480 case IrInstSrcIdBitOffsetOf:
481 return destroy(reinterpret_cast<IrInstSrcBitOffsetOf *>(inst), name);
482 case IrInstSrcIdTypeInfo:
483 return destroy(reinterpret_cast<IrInstSrcTypeInfo *>(inst), name);
484 case IrInstSrcIdType:
485 return destroy(reinterpret_cast<IrInstSrcType *>(inst), name);
486 case IrInstSrcIdHasField:
487 return destroy(reinterpret_cast<IrInstSrcHasField *>(inst), name);
488 case IrInstSrcIdTypeId:
489 return destroy(reinterpret_cast<IrInstSrcTypeId *>(inst), name);
490 case IrInstSrcIdSetEvalBranchQuota:
491 return destroy(reinterpret_cast<IrInstSrcSetEvalBranchQuota *>(inst), name);
492 case IrInstSrcIdAlignCast:
493 return destroy(reinterpret_cast<IrInstSrcAlignCast *>(inst), name);
494 case IrInstSrcIdImplicitCast:
495 return destroy(reinterpret_cast<IrInstSrcImplicitCast *>(inst), name);
496 case IrInstSrcIdResolveResult:
497 return destroy(reinterpret_cast<IrInstSrcResolveResult *>(inst), name);
498 case IrInstSrcIdResetResult:
499 return destroy(reinterpret_cast<IrInstSrcResetResult *>(inst), name);
500 case IrInstSrcIdOpaqueType:
501 return destroy(reinterpret_cast<IrInstSrcOpaqueType *>(inst), name);
502 case IrInstSrcIdSetAlignStack:
503 return destroy(reinterpret_cast<IrInstSrcSetAlignStack *>(inst), name);
504 case IrInstSrcIdArgType:
505 return destroy(reinterpret_cast<IrInstSrcArgType *>(inst), name);
506 case IrInstSrcIdTagType:
507 return destroy(reinterpret_cast<IrInstSrcTagType *>(inst), name);
508 case IrInstSrcIdExport:
509 return destroy(reinterpret_cast<IrInstSrcExport *>(inst), name);
510 case IrInstSrcIdErrorReturnTrace:
511 return destroy(reinterpret_cast<IrInstSrcErrorReturnTrace *>(inst), name);
512 case IrInstSrcIdErrorUnion:
513 return destroy(reinterpret_cast<IrInstSrcErrorUnion *>(inst), name);
514 case IrInstSrcIdAtomicRmw:
515 return destroy(reinterpret_cast<IrInstSrcAtomicRmw *>(inst), name);
516 case IrInstSrcIdSaveErrRetAddr:
517 return destroy(reinterpret_cast<IrInstSrcSaveErrRetAddr *>(inst), name);
518 case IrInstSrcIdAddImplicitReturnType:
519 return destroy(reinterpret_cast<IrInstSrcAddImplicitReturnType *>(inst), name);
520 case IrInstSrcIdFloatOp:
521 return destroy(reinterpret_cast<IrInstSrcFloatOp *>(inst), name);
522 case IrInstSrcIdMulAdd:
523 return destroy(reinterpret_cast<IrInstSrcMulAdd *>(inst), name);
524 case IrInstSrcIdAtomicLoad:
525 return destroy(reinterpret_cast<IrInstSrcAtomicLoad *>(inst), name);
526 case IrInstSrcIdAtomicStore:
527 return destroy(reinterpret_cast<IrInstSrcAtomicStore *>(inst), name);
528 case IrInstSrcIdEnumToInt:
529 return destroy(reinterpret_cast<IrInstSrcEnumToInt *>(inst), name);
530 case IrInstSrcIdCheckRuntimeScope:
531 return destroy(reinterpret_cast<IrInstSrcCheckRuntimeScope *>(inst), name);
532 case IrInstSrcIdHasDecl:
533 return destroy(reinterpret_cast<IrInstSrcHasDecl *>(inst), name);
534 case IrInstSrcIdUndeclaredIdent:
535 return destroy(reinterpret_cast<IrInstSrcUndeclaredIdent *>(inst), name);
536 case IrInstSrcIdAlloca:
537 return destroy(reinterpret_cast<IrInstSrcAlloca *>(inst), name);
538 case IrInstSrcIdEndExpr:
539 return destroy(reinterpret_cast<IrInstSrcEndExpr *>(inst), name);
540 case IrInstSrcIdUnionInitNamedField:
541 return destroy(reinterpret_cast<IrInstSrcUnionInitNamedField *>(inst), name);
542 case IrInstSrcIdSuspendBegin:
543 return destroy(reinterpret_cast<IrInstSrcSuspendBegin *>(inst), name);
544 case IrInstSrcIdSuspendFinish:
545 return destroy(reinterpret_cast<IrInstSrcSuspendFinish *>(inst), name);
546 case IrInstSrcIdResume:
547 return destroy(reinterpret_cast<IrInstSrcResume *>(inst), name);
548 case IrInstSrcIdAwait:
549 return destroy(reinterpret_cast<IrInstSrcAwait *>(inst), name);
550 case IrInstSrcIdSpillBegin:
551 return destroy(reinterpret_cast<IrInstSrcSpillBegin *>(inst), name);
552 case IrInstSrcIdSpillEnd:
553 return destroy(reinterpret_cast<IrInstSrcSpillEnd *>(inst), name);
554 case IrInstSrcIdCallArgs:
555 return destroy(reinterpret_cast<IrInstSrcCallArgs *>(inst), name);
556 }
557 zig_unreachable();
558}
267559
268static void destroy_instruction(IrInstruction *inst) {560void destroy_instruction_gen(IrInstGen *inst) {
269#ifdef ZIG_ENABLE_MEM_PROFILE561#ifdef ZIG_ENABLE_MEM_PROFILE
270 const char *name = ir_instruction_type_str(inst->id);562 const char *name = ir_inst_gen_type_str(inst->id);
271#else563#else
272 const char *name = nullptr;564 const char *name = nullptr;
273#endif565#endif
274 switch (inst->id) {566 switch (inst->id) {
275 case IrInstructionIdInvalid:567 case IrInstGenIdInvalid:
276 zig_unreachable();568 zig_unreachable();
277 case IrInstructionIdReturn:569 case IrInstGenIdReturn:
278 return destroy(reinterpret_cast<IrInstructionReturn *>(inst), name);570 return destroy(reinterpret_cast<IrInstGenReturn *>(inst), name);
279 case IrInstructionIdConst:571 case IrInstGenIdConst:
280 return destroy(reinterpret_cast<IrInstructionConst *>(inst), name);572 return destroy(reinterpret_cast<IrInstGenConst *>(inst), name);
281 case IrInstructionIdBinOp:573 case IrInstGenIdBinOp:
282 return destroy(reinterpret_cast<IrInstructionBinOp *>(inst), name);574 return destroy(reinterpret_cast<IrInstGenBinOp *>(inst), name);
283 case IrInstructionIdMergeErrSets:575 case IrInstGenIdCast:
284 return destroy(reinterpret_cast<IrInstructionMergeErrSets *>(inst), name);576 return destroy(reinterpret_cast<IrInstGenCast *>(inst), name);
285 case IrInstructionIdDeclVarSrc:577 case IrInstGenIdCall:
286 return destroy(reinterpret_cast<IrInstructionDeclVarSrc *>(inst), name);578 return destroy(reinterpret_cast<IrInstGenCall *>(inst), name);
287 case IrInstructionIdCast:579 case IrInstGenIdCondBr:
288 return destroy(reinterpret_cast<IrInstructionCast *>(inst), name);580 return destroy(reinterpret_cast<IrInstGenCondBr *>(inst), name);
289 case IrInstructionIdCallSrc:581 case IrInstGenIdBr:
290 return destroy(reinterpret_cast<IrInstructionCallSrc *>(inst), name);582 return destroy(reinterpret_cast<IrInstGenBr *>(inst), name);
291 case IrInstructionIdCallSrcArgs:583 case IrInstGenIdPhi:
292 return destroy(reinterpret_cast<IrInstructionCallSrcArgs *>(inst), name);584 return destroy(reinterpret_cast<IrInstGenPhi *>(inst), name);
293 case IrInstructionIdCallExtra:585 case IrInstGenIdUnreachable:
294 return destroy(reinterpret_cast<IrInstructionCallExtra *>(inst), name);586 return destroy(reinterpret_cast<IrInstGenUnreachable *>(inst), name);
295 case IrInstructionIdCallGen:587 case IrInstGenIdElemPtr:
296 return destroy(reinterpret_cast<IrInstructionCallGen *>(inst), name);588 return destroy(reinterpret_cast<IrInstGenElemPtr *>(inst), name);
297 case IrInstructionIdUnOp:589 case IrInstGenIdVarPtr:
298 return destroy(reinterpret_cast<IrInstructionUnOp *>(inst), name);590 return destroy(reinterpret_cast<IrInstGenVarPtr *>(inst), name);
299 case IrInstructionIdCondBr:591 case IrInstGenIdReturnPtr:
300 return destroy(reinterpret_cast<IrInstructionCondBr *>(inst), name);592 return destroy(reinterpret_cast<IrInstGenReturnPtr *>(inst), name);
301 case IrInstructionIdBr:593 case IrInstGenIdLoadPtr:
302 return destroy(reinterpret_cast<IrInstructionBr *>(inst), name);594 return destroy(reinterpret_cast<IrInstGenLoadPtr *>(inst), name);
303 case IrInstructionIdPhi:595 case IrInstGenIdStorePtr:
304 return destroy(reinterpret_cast<IrInstructionPhi *>(inst), name);596 return destroy(reinterpret_cast<IrInstGenStorePtr *>(inst), name);
305 case IrInstructionIdContainerInitList:597 case IrInstGenIdVectorStoreElem:
306 return destroy(reinterpret_cast<IrInstructionContainerInitList *>(inst), name);598 return destroy(reinterpret_cast<IrInstGenVectorStoreElem *>(inst), name);
307 case IrInstructionIdContainerInitFields:599 case IrInstGenIdStructFieldPtr:
308 return destroy(reinterpret_cast<IrInstructionContainerInitFields *>(inst), name);600 return destroy(reinterpret_cast<IrInstGenStructFieldPtr *>(inst), name);
309 case IrInstructionIdUnreachable:601 case IrInstGenIdUnionFieldPtr:
310 return destroy(reinterpret_cast<IrInstructionUnreachable *>(inst), name);602 return destroy(reinterpret_cast<IrInstGenUnionFieldPtr *>(inst), name);
311 case IrInstructionIdElemPtr:603 case IrInstGenIdAsm:
312 return destroy(reinterpret_cast<IrInstructionElemPtr *>(inst), name);604 return destroy(reinterpret_cast<IrInstGenAsm *>(inst), name);
313 case IrInstructionIdVarPtr:605 case IrInstGenIdTestNonNull:
314 return destroy(reinterpret_cast<IrInstructionVarPtr *>(inst), name);606 return destroy(reinterpret_cast<IrInstGenTestNonNull *>(inst), name);
315 case IrInstructionIdReturnPtr:607 case IrInstGenIdOptionalUnwrapPtr:
316 return destroy(reinterpret_cast<IrInstructionReturnPtr *>(inst), name);608 return destroy(reinterpret_cast<IrInstGenOptionalUnwrapPtr *>(inst), name);
317 case IrInstructionIdLoadPtr:609 case IrInstGenIdPopCount:
318 return destroy(reinterpret_cast<IrInstructionLoadPtr *>(inst), name);610 return destroy(reinterpret_cast<IrInstGenPopCount *>(inst), name);
319 case IrInstructionIdLoadPtrGen:611 case IrInstGenIdClz:
320 return destroy(reinterpret_cast<IrInstructionLoadPtrGen *>(inst), name);612 return destroy(reinterpret_cast<IrInstGenClz *>(inst), name);
321 case IrInstructionIdStorePtr:613 case IrInstGenIdCtz:
322 return destroy(reinterpret_cast<IrInstructionStorePtr *>(inst), name);614 return destroy(reinterpret_cast<IrInstGenCtz *>(inst), name);
323 case IrInstructionIdVectorStoreElem:615 case IrInstGenIdBswap:
324 return destroy(reinterpret_cast<IrInstructionVectorStoreElem *>(inst), name);616 return destroy(reinterpret_cast<IrInstGenBswap *>(inst), name);
325 case IrInstructionIdTypeOf:617 case IrInstGenIdBitReverse:
326 return destroy(reinterpret_cast<IrInstructionTypeOf *>(inst), name);618 return destroy(reinterpret_cast<IrInstGenBitReverse *>(inst), name);
327 case IrInstructionIdFieldPtr:619 case IrInstGenIdSwitchBr:
328 return destroy(reinterpret_cast<IrInstructionFieldPtr *>(inst), name);620 return destroy(reinterpret_cast<IrInstGenSwitchBr *>(inst), name);
329 case IrInstructionIdStructFieldPtr:621 case IrInstGenIdUnionTag:
330 return destroy(reinterpret_cast<IrInstructionStructFieldPtr *>(inst), name);622 return destroy(reinterpret_cast<IrInstGenUnionTag *>(inst), name);
331 case IrInstructionIdUnionFieldPtr:623 case IrInstGenIdRef:
332 return destroy(reinterpret_cast<IrInstructionUnionFieldPtr *>(inst), name);624 return destroy(reinterpret_cast<IrInstGenRef *>(inst), name);
333 case IrInstructionIdSetCold:625 case IrInstGenIdErrName:
334 return destroy(reinterpret_cast<IrInstructionSetCold *>(inst), name);626 return destroy(reinterpret_cast<IrInstGenErrName *>(inst), name);
335 case IrInstructionIdSetRuntimeSafety:627 case IrInstGenIdCmpxchg:
336 return destroy(reinterpret_cast<IrInstructionSetRuntimeSafety *>(inst), name);628 return destroy(reinterpret_cast<IrInstGenCmpxchg *>(inst), name);
337 case IrInstructionIdSetFloatMode:629 case IrInstGenIdFence:
338 return destroy(reinterpret_cast<IrInstructionSetFloatMode *>(inst), name);630 return destroy(reinterpret_cast<IrInstGenFence *>(inst), name);
339 case IrInstructionIdArrayType:631 case IrInstGenIdTruncate:
340 return destroy(reinterpret_cast<IrInstructionArrayType *>(inst), name);632 return destroy(reinterpret_cast<IrInstGenTruncate *>(inst), name);
341 case IrInstructionIdSliceType:633 case IrInstGenIdShuffleVector:
342 return destroy(reinterpret_cast<IrInstructionSliceType *>(inst), name);634 return destroy(reinterpret_cast<IrInstGenShuffleVector *>(inst), name);
343 case IrInstructionIdAnyFrameType:635 case IrInstGenIdSplat:
344 return destroy(reinterpret_cast<IrInstructionAnyFrameType *>(inst), name);636 return destroy(reinterpret_cast<IrInstGenSplat *>(inst), name);
345 case IrInstructionIdAsmSrc:637 case IrInstGenIdBoolNot:
346 return destroy(reinterpret_cast<IrInstructionAsmSrc *>(inst), name);638 return destroy(reinterpret_cast<IrInstGenBoolNot *>(inst), name);
347 case IrInstructionIdAsmGen:639 case IrInstGenIdMemset:
348 return destroy(reinterpret_cast<IrInstructionAsmGen *>(inst), name);640 return destroy(reinterpret_cast<IrInstGenMemset *>(inst), name);
349 case IrInstructionIdSizeOf:641 case IrInstGenIdMemcpy:
350 return destroy(reinterpret_cast<IrInstructionSizeOf *>(inst), name);642 return destroy(reinterpret_cast<IrInstGenMemcpy *>(inst), name);
351 case IrInstructionIdTestNonNull:643 case IrInstGenIdSlice:
352 return destroy(reinterpret_cast<IrInstructionTestNonNull *>(inst), name);644 return destroy(reinterpret_cast<IrInstGenSlice *>(inst), name);
353 case IrInstructionIdOptionalUnwrapPtr:645 case IrInstGenIdBreakpoint:
354 return destroy(reinterpret_cast<IrInstructionOptionalUnwrapPtr *>(inst), name);646 return destroy(reinterpret_cast<IrInstGenBreakpoint *>(inst), name);
355 case IrInstructionIdPopCount:647 case IrInstGenIdReturnAddress:
356 return destroy(reinterpret_cast<IrInstructionPopCount *>(inst), name);648 return destroy(reinterpret_cast<IrInstGenReturnAddress *>(inst), name);
357 case IrInstructionIdClz:649 case IrInstGenIdFrameAddress:
358 return destroy(reinterpret_cast<IrInstructionClz *>(inst), name);650 return destroy(reinterpret_cast<IrInstGenFrameAddress *>(inst), name);
359 case IrInstructionIdCtz:651 case IrInstGenIdFrameHandle:
360 return destroy(reinterpret_cast<IrInstructionCtz *>(inst), name);652 return destroy(reinterpret_cast<IrInstGenFrameHandle *>(inst), name);
361 case IrInstructionIdBswap:653 case IrInstGenIdFrameSize:
362 return destroy(reinterpret_cast<IrInstructionBswap *>(inst), name);654 return destroy(reinterpret_cast<IrInstGenFrameSize *>(inst), name);
363 case IrInstructionIdBitReverse:655 case IrInstGenIdOverflowOp:
364 return destroy(reinterpret_cast<IrInstructionBitReverse *>(inst), name);656 return destroy(reinterpret_cast<IrInstGenOverflowOp *>(inst), name);
365 case IrInstructionIdSwitchBr:657 case IrInstGenIdTestErr:
366 return destroy(reinterpret_cast<IrInstructionSwitchBr *>(inst), name);658 return destroy(reinterpret_cast<IrInstGenTestErr *>(inst), name);
367 case IrInstructionIdSwitchVar:659 case IrInstGenIdUnwrapErrCode:
368 return destroy(reinterpret_cast<IrInstructionSwitchVar *>(inst), name);660 return destroy(reinterpret_cast<IrInstGenUnwrapErrCode *>(inst), name);
369 case IrInstructionIdSwitchElseVar:661 case IrInstGenIdUnwrapErrPayload:
370 return destroy(reinterpret_cast<IrInstructionSwitchElseVar *>(inst), name);662 return destroy(reinterpret_cast<IrInstGenUnwrapErrPayload *>(inst), name);
371 case IrInstructionIdSwitchTarget:663 case IrInstGenIdOptionalWrap:
372 return destroy(reinterpret_cast<IrInstructionSwitchTarget *>(inst), name);664 return destroy(reinterpret_cast<IrInstGenOptionalWrap *>(inst), name);
373 case IrInstructionIdUnionTag:665 case IrInstGenIdErrWrapCode:
374 return destroy(reinterpret_cast<IrInstructionUnionTag *>(inst), name);666 return destroy(reinterpret_cast<IrInstGenErrWrapCode *>(inst), name);
375 case IrInstructionIdImport:667 case IrInstGenIdErrWrapPayload:
376 return destroy(reinterpret_cast<IrInstructionImport *>(inst), name);668 return destroy(reinterpret_cast<IrInstGenErrWrapPayload *>(inst), name);
377 case IrInstructionIdRef:669 case IrInstGenIdPtrCast:
378 return destroy(reinterpret_cast<IrInstructionRef *>(inst), name);670 return destroy(reinterpret_cast<IrInstGenPtrCast *>(inst), name);
379 case IrInstructionIdRefGen:671 case IrInstGenIdBitCast:
380 return destroy(reinterpret_cast<IrInstructionRefGen *>(inst), name);672 return destroy(reinterpret_cast<IrInstGenBitCast *>(inst), name);
381 case IrInstructionIdCompileErr:673 case IrInstGenIdWidenOrShorten:
382 return destroy(reinterpret_cast<IrInstructionCompileErr *>(inst), name);674 return destroy(reinterpret_cast<IrInstGenWidenOrShorten *>(inst), name);
383 case IrInstructionIdCompileLog:675 case IrInstGenIdPtrToInt:
384 return destroy(reinterpret_cast<IrInstructionCompileLog *>(inst), name);676 return destroy(reinterpret_cast<IrInstGenPtrToInt *>(inst), name);
385 case IrInstructionIdErrName:677 case IrInstGenIdIntToPtr:
386 return destroy(reinterpret_cast<IrInstructionErrName *>(inst), name);678 return destroy(reinterpret_cast<IrInstGenIntToPtr *>(inst), name);
387 case IrInstructionIdCImport:679 case IrInstGenIdIntToEnum:
388 return destroy(reinterpret_cast<IrInstructionCImport *>(inst), name);680 return destroy(reinterpret_cast<IrInstGenIntToEnum *>(inst), name);
389 case IrInstructionIdCInclude:681 case IrInstGenIdIntToErr:
390 return destroy(reinterpret_cast<IrInstructionCInclude *>(inst), name);682 return destroy(reinterpret_cast<IrInstGenIntToErr *>(inst), name);
391 case IrInstructionIdCDefine:683 case IrInstGenIdErrToInt:
392 return destroy(reinterpret_cast<IrInstructionCDefine *>(inst), name);684 return destroy(reinterpret_cast<IrInstGenErrToInt *>(inst), name);
393 case IrInstructionIdCUndef:685 case IrInstGenIdTagName:
394 return destroy(reinterpret_cast<IrInstructionCUndef *>(inst), name);686 return destroy(reinterpret_cast<IrInstGenTagName *>(inst), name);
395 case IrInstructionIdEmbedFile:687 case IrInstGenIdPanic:
396 return destroy(reinterpret_cast<IrInstructionEmbedFile *>(inst), name);688 return destroy(reinterpret_cast<IrInstGenPanic *>(inst), name);
397 case IrInstructionIdCmpxchgSrc:689 case IrInstGenIdFieldParentPtr:
398 return destroy(reinterpret_cast<IrInstructionCmpxchgSrc *>(inst), name);690 return destroy(reinterpret_cast<IrInstGenFieldParentPtr *>(inst), name);
399 case IrInstructionIdCmpxchgGen:691 case IrInstGenIdAlignCast:
400 return destroy(reinterpret_cast<IrInstructionCmpxchgGen *>(inst), name);692 return destroy(reinterpret_cast<IrInstGenAlignCast *>(inst), name);
401 case IrInstructionIdFence:693 case IrInstGenIdErrorReturnTrace:
402 return destroy(reinterpret_cast<IrInstructionFence *>(inst), name);694 return destroy(reinterpret_cast<IrInstGenErrorReturnTrace *>(inst), name);
403 case IrInstructionIdTruncate:695 case IrInstGenIdAtomicRmw:
404 return destroy(reinterpret_cast<IrInstructionTruncate *>(inst), name);696 return destroy(reinterpret_cast<IrInstGenAtomicRmw *>(inst), name);
405 case IrInstructionIdIntCast:697 case IrInstGenIdSaveErrRetAddr:
406 return destroy(reinterpret_cast<IrInstructionIntCast *>(inst), name);698 return destroy(reinterpret_cast<IrInstGenSaveErrRetAddr *>(inst), name);
407 case IrInstructionIdFloatCast:699 case IrInstGenIdFloatOp:
408 return destroy(reinterpret_cast<IrInstructionFloatCast *>(inst), name);700 return destroy(reinterpret_cast<IrInstGenFloatOp *>(inst), name);
409 case IrInstructionIdErrSetCast:701 case IrInstGenIdMulAdd:
410 return destroy(reinterpret_cast<IrInstructionErrSetCast *>(inst), name);702 return destroy(reinterpret_cast<IrInstGenMulAdd *>(inst), name);
411 case IrInstructionIdFromBytes:703 case IrInstGenIdAtomicLoad:
412 return destroy(reinterpret_cast<IrInstructionFromBytes *>(inst), name);704 return destroy(reinterpret_cast<IrInstGenAtomicLoad *>(inst), name);
413 case IrInstructionIdToBytes:705 case IrInstGenIdAtomicStore:
414 return destroy(reinterpret_cast<IrInstructionToBytes *>(inst), name);706 return destroy(reinterpret_cast<IrInstGenAtomicStore *>(inst), name);
415 case IrInstructionIdIntToFloat:707 case IrInstGenIdDeclVar:
416 return destroy(reinterpret_cast<IrInstructionIntToFloat *>(inst), name);708 return destroy(reinterpret_cast<IrInstGenDeclVar *>(inst), name);
417 case IrInstructionIdFloatToInt:709 case IrInstGenIdArrayToVector:
418 return destroy(reinterpret_cast<IrInstructionFloatToInt *>(inst), name);710 return destroy(reinterpret_cast<IrInstGenArrayToVector *>(inst), name);
419 case IrInstructionIdBoolToInt:711 case IrInstGenIdVectorToArray:
420 return destroy(reinterpret_cast<IrInstructionBoolToInt *>(inst), name);712 return destroy(reinterpret_cast<IrInstGenVectorToArray *>(inst), name);
421 case IrInstructionIdIntType:713 case IrInstGenIdPtrOfArrayToSlice:
422 return destroy(reinterpret_cast<IrInstructionIntType *>(inst), name);714 return destroy(reinterpret_cast<IrInstGenPtrOfArrayToSlice *>(inst), name);
423 case IrInstructionIdVectorType:715 case IrInstGenIdAssertZero:
424 return destroy(reinterpret_cast<IrInstructionVectorType *>(inst), name);716 return destroy(reinterpret_cast<IrInstGenAssertZero *>(inst), name);
425 case IrInstructionIdShuffleVector:717 case IrInstGenIdAssertNonNull:
426 return destroy(reinterpret_cast<IrInstructionShuffleVector *>(inst), name);718 return destroy(reinterpret_cast<IrInstGenAssertNonNull *>(inst), name);
427 case IrInstructionIdSplatSrc:719 case IrInstGenIdResizeSlice:
428 return destroy(reinterpret_cast<IrInstructionSplatSrc *>(inst), name);720 return destroy(reinterpret_cast<IrInstGenResizeSlice *>(inst), name);
429 case IrInstructionIdSplatGen:721 case IrInstGenIdAlloca:
430 return destroy(reinterpret_cast<IrInstructionSplatGen *>(inst), name);722 return destroy(reinterpret_cast<IrInstGenAlloca *>(inst), name);
431 case IrInstructionIdBoolNot:723 case IrInstGenIdSuspendBegin:
432 return destroy(reinterpret_cast<IrInstructionBoolNot *>(inst), name);724 return destroy(reinterpret_cast<IrInstGenSuspendBegin *>(inst), name);
433 case IrInstructionIdMemset:725 case IrInstGenIdSuspendFinish:
434 return destroy(reinterpret_cast<IrInstructionMemset *>(inst), name);726 return destroy(reinterpret_cast<IrInstGenSuspendFinish *>(inst), name);
435 case IrInstructionIdMemcpy:727 case IrInstGenIdResume:
436 return destroy(reinterpret_cast<IrInstructionMemcpy *>(inst), name);728 return destroy(reinterpret_cast<IrInstGenResume *>(inst), name);
437 case IrInstructionIdSliceSrc:729 case IrInstGenIdAwait:
438 return destroy(reinterpret_cast<IrInstructionSliceSrc *>(inst), name);730 return destroy(reinterpret_cast<IrInstGenAwait *>(inst), name);
439 case IrInstructionIdSliceGen:731 case IrInstGenIdSpillBegin:
440 return destroy(reinterpret_cast<IrInstructionSliceGen *>(inst), name);732 return destroy(reinterpret_cast<IrInstGenSpillBegin *>(inst), name);
441 case IrInstructionIdMemberCount:733 case IrInstGenIdSpillEnd:
442 return destroy(reinterpret_cast<IrInstructionMemberCount *>(inst), name);734 return destroy(reinterpret_cast<IrInstGenSpillEnd *>(inst), name);
443 case IrInstructionIdMemberType:735 case IrInstGenIdVectorExtractElem:
444 return destroy(reinterpret_cast<IrInstructionMemberType *>(inst), name);736 return destroy(reinterpret_cast<IrInstGenVectorExtractElem *>(inst), name);
445 case IrInstructionIdMemberName:737 case IrInstGenIdBinaryNot:
446 return destroy(reinterpret_cast<IrInstructionMemberName *>(inst), name);738 return destroy(reinterpret_cast<IrInstGenBinaryNot *>(inst), name);
447 case IrInstructionIdBreakpoint:739 case IrInstGenIdNegation:
448 return destroy(reinterpret_cast<IrInstructionBreakpoint *>(inst), name);740 return destroy(reinterpret_cast<IrInstGenNegation *>(inst), name);
449 case IrInstructionIdReturnAddress:741 case IrInstGenIdNegationWrapping:
450 return destroy(reinterpret_cast<IrInstructionReturnAddress *>(inst), name);742 return destroy(reinterpret_cast<IrInstGenNegationWrapping *>(inst), name);
451 case IrInstructionIdFrameAddress:
452 return destroy(reinterpret_cast<IrInstructionFrameAddress *>(inst), name);
453 case IrInstructionIdFrameHandle:
454 return destroy(reinterpret_cast<IrInstructionFrameHandle *>(inst), name);
455 case IrInstructionIdFrameType:
456 return destroy(reinterpret_cast<IrInstructionFrameType *>(inst), name);
457 case IrInstructionIdFrameSizeSrc:
458 return destroy(reinterpret_cast<IrInstructionFrameSizeSrc *>(inst), name);
459 case IrInstructionIdFrameSizeGen:
460 return destroy(reinterpret_cast<IrInstructionFrameSizeGen *>(inst), name);
461 case IrInstructionIdAlignOf:
462 return destroy(reinterpret_cast<IrInstructionAlignOf *>(inst), name);
463 case IrInstructionIdOverflowOp:
464 return destroy(reinterpret_cast<IrInstructionOverflowOp *>(inst), name);
465 case IrInstructionIdTestErrSrc:
466 return destroy(reinterpret_cast<IrInstructionTestErrSrc *>(inst), name);
467 case IrInstructionIdTestErrGen:
468 return destroy(reinterpret_cast<IrInstructionTestErrGen *>(inst), name);
469 case IrInstructionIdUnwrapErrCode:
470 return destroy(reinterpret_cast<IrInstructionUnwrapErrCode *>(inst), name);
471 case IrInstructionIdUnwrapErrPayload:
472 return destroy(reinterpret_cast<IrInstructionUnwrapErrPayload *>(inst), name);
473 case IrInstructionIdOptionalWrap:
474 return destroy(reinterpret_cast<IrInstructionOptionalWrap *>(inst), name);
475 case IrInstructionIdErrWrapCode:
476 return destroy(reinterpret_cast<IrInstructionErrWrapCode *>(inst), name);
477 case IrInstructionIdErrWrapPayload:
478 return destroy(reinterpret_cast<IrInstructionErrWrapPayload *>(inst), name);
479 case IrInstructionIdFnProto:
480 return destroy(reinterpret_cast<IrInstructionFnProto *>(inst), name);
481 case IrInstructionIdTestComptime:
482 return destroy(reinterpret_cast<IrInstructionTestComptime *>(inst), name);
483 case IrInstructionIdPtrCastSrc:
484 return destroy(reinterpret_cast<IrInstructionPtrCastSrc *>(inst), name);
485 case IrInstructionIdPtrCastGen:
486 return destroy(reinterpret_cast<IrInstructionPtrCastGen *>(inst), name);
487 case IrInstructionIdBitCastSrc:
488 return destroy(reinterpret_cast<IrInstructionBitCastSrc *>(inst), name);
489 case IrInstructionIdBitCastGen:
490 return destroy(reinterpret_cast<IrInstructionBitCastGen *>(inst), name);
491 case IrInstructionIdWidenOrShorten:
492 return destroy(reinterpret_cast<IrInstructionWidenOrShorten *>(inst), name);
493 case IrInstructionIdPtrToInt:
494 return destroy(reinterpret_cast<IrInstructionPtrToInt *>(inst), name);
495 case IrInstructionIdIntToPtr:
496 return destroy(reinterpret_cast<IrInstructionIntToPtr *>(inst), name);
497 case IrInstructionIdIntToEnum:
498 return destroy(reinterpret_cast<IrInstructionIntToEnum *>(inst), name);
499 case IrInstructionIdIntToErr:
500 return destroy(reinterpret_cast<IrInstructionIntToErr *>(inst), name);
501 case IrInstructionIdErrToInt:
502 return destroy(reinterpret_cast<IrInstructionErrToInt *>(inst), name);
503 case IrInstructionIdCheckSwitchProngs:
504 return destroy(reinterpret_cast<IrInstructionCheckSwitchProngs *>(inst), name);
505 case IrInstructionIdCheckStatementIsVoid:
506 return destroy(reinterpret_cast<IrInstructionCheckStatementIsVoid *>(inst), name);
507 case IrInstructionIdTypeName:
508 return destroy(reinterpret_cast<IrInstructionTypeName *>(inst), name);
509 case IrInstructionIdTagName:
510 return destroy(reinterpret_cast<IrInstructionTagName *>(inst), name);
511 case IrInstructionIdPtrType:
512 return destroy(reinterpret_cast<IrInstructionPtrType *>(inst), name);
513 case IrInstructionIdDeclRef:
514 return destroy(reinterpret_cast<IrInstructionDeclRef *>(inst), name);
515 case IrInstructionIdPanic:
516 return destroy(reinterpret_cast<IrInstructionPanic *>(inst), name);
517 case IrInstructionIdFieldParentPtr:
518 return destroy(reinterpret_cast<IrInstructionFieldParentPtr *>(inst), name);
519 case IrInstructionIdByteOffsetOf:
520 return destroy(reinterpret_cast<IrInstructionByteOffsetOf *>(inst), name);
521 case IrInstructionIdBitOffsetOf:
522 return destroy(reinterpret_cast<IrInstructionBitOffsetOf *>(inst), name);
523 case IrInstructionIdTypeInfo:
524 return destroy(reinterpret_cast<IrInstructionTypeInfo *>(inst), name);
525 case IrInstructionIdType:
526 return destroy(reinterpret_cast<IrInstructionType *>(inst), name);
527 case IrInstructionIdHasField:
528 return destroy(reinterpret_cast<IrInstructionHasField *>(inst), name);
529 case IrInstructionIdTypeId:
530 return destroy(reinterpret_cast<IrInstructionTypeId *>(inst), name);
531 case IrInstructionIdSetEvalBranchQuota:
532 return destroy(reinterpret_cast<IrInstructionSetEvalBranchQuota *>(inst), name);
533 case IrInstructionIdAlignCast:
534 return destroy(reinterpret_cast<IrInstructionAlignCast *>(inst), name);
535 case IrInstructionIdImplicitCast:
536 return destroy(reinterpret_cast<IrInstructionImplicitCast *>(inst), name);
537 case IrInstructionIdResolveResult:
538 return destroy(reinterpret_cast<IrInstructionResolveResult *>(inst), name);
539 case IrInstructionIdResetResult:
540 return destroy(reinterpret_cast<IrInstructionResetResult *>(inst), name);
541 case IrInstructionIdOpaqueType:
542 return destroy(reinterpret_cast<IrInstructionOpaqueType *>(inst), name);
543 case IrInstructionIdSetAlignStack:
544 return destroy(reinterpret_cast<IrInstructionSetAlignStack *>(inst), name);
545 case IrInstructionIdArgType:
546 return destroy(reinterpret_cast<IrInstructionArgType *>(inst), name);
547 case IrInstructionIdTagType:
548 return destroy(reinterpret_cast<IrInstructionTagType *>(inst), name);
549 case IrInstructionIdExport:
550 return destroy(reinterpret_cast<IrInstructionExport *>(inst), name);
551 case IrInstructionIdErrorReturnTrace:
552 return destroy(reinterpret_cast<IrInstructionErrorReturnTrace *>(inst), name);
553 case IrInstructionIdErrorUnion:
554 return destroy(reinterpret_cast<IrInstructionErrorUnion *>(inst), name);
555 case IrInstructionIdAtomicRmw:
556 return destroy(reinterpret_cast<IrInstructionAtomicRmw *>(inst), name);
557 case IrInstructionIdSaveErrRetAddr:
558 return destroy(reinterpret_cast<IrInstructionSaveErrRetAddr *>(inst), name);
559 case IrInstructionIdAddImplicitReturnType:
560 return destroy(reinterpret_cast<IrInstructionAddImplicitReturnType *>(inst), name);
561 case IrInstructionIdFloatOp:
562 return destroy(reinterpret_cast<IrInstructionFloatOp *>(inst), name);
563 case IrInstructionIdMulAdd:
564 return destroy(reinterpret_cast<IrInstructionMulAdd *>(inst), name);
565 case IrInstructionIdAtomicLoad:
566 return destroy(reinterpret_cast<IrInstructionAtomicLoad *>(inst), name);
567 case IrInstructionIdAtomicStore:
568 return destroy(reinterpret_cast<IrInstructionAtomicStore *>(inst), name);
569 case IrInstructionIdEnumToInt:
570 return destroy(reinterpret_cast<IrInstructionEnumToInt *>(inst), name);
571 case IrInstructionIdCheckRuntimeScope:
572 return destroy(reinterpret_cast<IrInstructionCheckRuntimeScope *>(inst), name);
573 case IrInstructionIdDeclVarGen:
574 return destroy(reinterpret_cast<IrInstructionDeclVarGen *>(inst), name);
575 case IrInstructionIdArrayToVector:
576 return destroy(reinterpret_cast<IrInstructionArrayToVector *>(inst), name);
577 case IrInstructionIdVectorToArray:
578 return destroy(reinterpret_cast<IrInstructionVectorToArray *>(inst), name);
579 case IrInstructionIdPtrOfArrayToSlice:
580 return destroy(reinterpret_cast<IrInstructionPtrOfArrayToSlice *>(inst), name);
581 case IrInstructionIdAssertZero:
582 return destroy(reinterpret_cast<IrInstructionAssertZero *>(inst), name);
583 case IrInstructionIdAssertNonNull:
584 return destroy(reinterpret_cast<IrInstructionAssertNonNull *>(inst), name);
585 case IrInstructionIdResizeSlice:
586 return destroy(reinterpret_cast<IrInstructionResizeSlice *>(inst), name);
587 case IrInstructionIdHasDecl:
588 return destroy(reinterpret_cast<IrInstructionHasDecl *>(inst), name);
589 case IrInstructionIdUndeclaredIdent:
590 return destroy(reinterpret_cast<IrInstructionUndeclaredIdent *>(inst), name);
591 case IrInstructionIdAllocaSrc:
592 return destroy(reinterpret_cast<IrInstructionAllocaSrc *>(inst), name);
593 case IrInstructionIdAllocaGen:
594 return destroy(reinterpret_cast<IrInstructionAllocaGen *>(inst), name);
595 case IrInstructionIdEndExpr:
596 return destroy(reinterpret_cast<IrInstructionEndExpr *>(inst), name);
597 case IrInstructionIdUnionInitNamedField:
598 return destroy(reinterpret_cast<IrInstructionUnionInitNamedField *>(inst), name);
599 case IrInstructionIdSuspendBegin:
600 return destroy(reinterpret_cast<IrInstructionSuspendBegin *>(inst), name);
601 case IrInstructionIdSuspendFinish:
602 return destroy(reinterpret_cast<IrInstructionSuspendFinish *>(inst), name);
603 case IrInstructionIdResume:
604 return destroy(reinterpret_cast<IrInstructionResume *>(inst), name);
605 case IrInstructionIdAwaitSrc:
606 return destroy(reinterpret_cast<IrInstructionAwaitSrc *>(inst), name);
607 case IrInstructionIdAwaitGen:
608 return destroy(reinterpret_cast<IrInstructionAwaitGen *>(inst), name);
609 case IrInstructionIdSpillBegin:
610 return destroy(reinterpret_cast<IrInstructionSpillBegin *>(inst), name);
611 case IrInstructionIdSpillEnd:
612 return destroy(reinterpret_cast<IrInstructionSpillEnd *>(inst), name);
613 case IrInstructionIdVectorExtractElem:
614 return destroy(reinterpret_cast<IrInstructionVectorExtractElem *>(inst), name);
615 }743 }
616 zig_unreachable();744 zig_unreachable();
617}745}
...@@ -627,20 +755,19 @@ static void ira_deref(IrAnalyze *ira) {...@@ -627,20 +755,19 @@ static void ira_deref(IrAnalyze *ira) {
627 assert(ira->ref_count != 0);755 assert(ira->ref_count != 0);
628756
629 for (size_t bb_i = 0; bb_i < ira->old_irb.exec->basic_block_list.length; bb_i += 1) {757 for (size_t bb_i = 0; bb_i < ira->old_irb.exec->basic_block_list.length; bb_i += 1) {
630 IrBasicBlock *pass1_bb = ira->old_irb.exec->basic_block_list.items[bb_i];758 IrBasicBlockSrc *pass1_bb = ira->old_irb.exec->basic_block_list.items[bb_i];
631 for (size_t inst_i = 0; inst_i < pass1_bb->instruction_list.length; inst_i += 1) {759 for (size_t inst_i = 0; inst_i < pass1_bb->instruction_list.length; inst_i += 1) {
632 IrInstruction *pass1_inst = pass1_bb->instruction_list.items[inst_i];760 IrInstSrc *pass1_inst = pass1_bb->instruction_list.items[inst_i];
633 destroy_instruction(pass1_inst);761 destroy_instruction_src(pass1_inst);
634 }762 }
635 destroy(pass1_bb, "IrBasicBlock");763 destroy(pass1_bb, "IrBasicBlockSrc");
636 }764 }
637 ira->old_irb.exec->basic_block_list.deinit();765 ira->old_irb.exec->basic_block_list.deinit();
638 ira->old_irb.exec->tld_list.deinit();766 ira->old_irb.exec->tld_list.deinit();
639 // cannot destroy here because of var->owner_exec767 // cannot destroy here because of var->owner_exec
640 //destroy(ira->old_irb.exec, "IrExecutablePass1");768 //destroy(ira->old_irb.exec, "IrExecutableSrc");
641 ira->src_implicit_return_type_list.deinit();769 ira->src_implicit_return_type_list.deinit();
642 ira->resume_stack.deinit();770 ira->resume_stack.deinit();
643 ira->exec_context.mem_slot_list.deinit();
644 destroy(ira, "IrAnalyze");771 destroy(ira, "IrAnalyze");
645}772}
646773
...@@ -754,7 +881,6 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte...@@ -754,7 +881,6 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte
754 case ZigTypeIdComptimeFloat:881 case ZigTypeIdComptimeFloat:
755 case ZigTypeIdComptimeInt:882 case ZigTypeIdComptimeInt:
756 case ZigTypeIdEnumLiteral:883 case ZigTypeIdEnumLiteral:
757 case ZigTypeIdPointer:
758 case ZigTypeIdUndefined:884 case ZigTypeIdUndefined:
759 case ZigTypeIdNull:885 case ZigTypeIdNull:
760 case ZigTypeIdBoundFn:886 case ZigTypeIdBoundFn:
...@@ -763,6 +889,8 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte...@@ -763,6 +889,8 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte
763 case ZigTypeIdAnyFrame:889 case ZigTypeIdAnyFrame:
764 case ZigTypeIdFn:890 case ZigTypeIdFn:
765 return true;891 return true;
892 case ZigTypeIdPointer:
893 return expected->data.pointer.inferred_struct_field == actual->data.pointer.inferred_struct_field;
766 case ZigTypeIdFloat:894 case ZigTypeIdFloat:
767 return expected->data.floating.bit_count == actual->data.floating.bit_count;895 return expected->data.floating.bit_count == actual->data.floating.bit_count;
768 case ZigTypeIdInt:896 case ZigTypeIdInt:
...@@ -785,7 +913,7 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte...@@ -785,7 +913,7 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte
785 zig_unreachable();913 zig_unreachable();
786}914}
787915
788static bool ir_should_inline(IrExecutable *exec, Scope *scope) {916static bool ir_should_inline(IrExecutableSrc *exec, Scope *scope) {
789 if (exec->is_inline)917 if (exec->is_inline)
790 return true;918 return true;
791919
...@@ -801,29 +929,35 @@ static bool ir_should_inline(IrExecutable *exec, Scope *scope) {...@@ -801,29 +929,35 @@ static bool ir_should_inline(IrExecutable *exec, Scope *scope) {
801 return false;929 return false;
802}930}
803931
804static void ir_instruction_append(IrBasicBlock *basic_block, IrInstruction *instruction) {932static void ir_instruction_append(IrBasicBlockSrc *basic_block, IrInstSrc *instruction) {
933 assert(basic_block);
934 assert(instruction);
935 basic_block->instruction_list.append(instruction);
936}
937
938static void ir_inst_gen_append(IrBasicBlockGen *basic_block, IrInstGen *instruction) {
805 assert(basic_block);939 assert(basic_block);
806 assert(instruction);940 assert(instruction);
807 basic_block->instruction_list.append(instruction);941 basic_block->instruction_list.append(instruction);
808}942}
809943
810static size_t exec_next_debug_id(IrExecutable *exec) {944static size_t exec_next_debug_id(IrExecutableSrc *exec) {
811 size_t result = exec->next_debug_id;945 size_t result = exec->next_debug_id;
812 exec->next_debug_id += 1;946 exec->next_debug_id += 1;
813 return result;947 return result;
814}948}
815949
816static size_t exec_next_mem_slot(IrExecutable *exec) {950static size_t exec_next_debug_id_gen(IrExecutableGen *exec) {
817 size_t result = exec->mem_slot_count;951 size_t result = exec->next_debug_id;
818 exec->mem_slot_count += 1;952 exec->next_debug_id += 1;
819 return result;953 return result;
820}954}
821955
822static ZigFn *exec_fn_entry(IrExecutable *exec) {956static ZigFn *exec_fn_entry(IrExecutableSrc *exec) {
823 return exec->fn_entry;957 return exec->fn_entry;
824}958}
825959
826static Buf *exec_c_import_buf(IrExecutable *exec) {960static Buf *exec_c_import_buf(IrExecutableSrc *exec) {
827 return exec->c_import_buf;961 return exec->c_import_buf;
828}962}
829963
...@@ -831,1002 +965,1343 @@ static bool value_is_comptime(ZigValue *const_val) {...@@ -831,1002 +965,1343 @@ static bool value_is_comptime(ZigValue *const_val) {
831 return const_val->special != ConstValSpecialRuntime;965 return const_val->special != ConstValSpecialRuntime;
832}966}
833967
834static bool instr_is_comptime(IrInstruction *instruction) {968static bool instr_is_comptime(IrInstGen *instruction) {
835 return value_is_comptime(instruction->value);969 return value_is_comptime(instruction->value);
836}970}
837971
838static bool instr_is_unreachable(IrInstruction *instruction) {972static bool instr_is_unreachable(IrInstSrc *instruction) {
839 return instruction->value->type && instruction->value->type->id == ZigTypeIdUnreachable;973 return instruction->is_noreturn;
840}974}
841975
842static void ir_link_new_bb(IrBasicBlock *new_bb, IrBasicBlock *old_bb) {976static void ir_link_new_bb(IrBasicBlockGen *new_bb, IrBasicBlockSrc *old_bb) {
843 new_bb->other = old_bb;977 new_bb->parent = old_bb;
844 old_bb->other = new_bb;978 old_bb->child = new_bb;
845}979}
846980
847static void ir_ref_bb(IrBasicBlock *bb) {981static void ir_ref_bb(IrBasicBlockSrc *bb) {
848 bb->ref_count += 1;982 bb->ref_count += 1;
849}983}
850984
851static void ir_ref_instruction(IrInstruction *instruction, IrBasicBlock *cur_bb) {985static void ir_ref_bb_gen(IrBasicBlockGen *bb) {
852 assert(instruction->id != IrInstructionIdInvalid);986 bb->ref_count += 1;
853 instruction->ref_count += 1;987}
854 if (instruction->owner_bb != cur_bb && !instr_is_comptime(instruction))988
989static void ir_ref_instruction(IrInstSrc *instruction, IrBasicBlockSrc *cur_bb) {
990 assert(instruction->id != IrInstSrcIdInvalid);
991 instruction->base.ref_count += 1;
992 if (instruction->owner_bb != cur_bb && !instr_is_unreachable(instruction)
993 && instruction->id != IrInstSrcIdConst)
994 {
855 ir_ref_bb(instruction->owner_bb);995 ir_ref_bb(instruction->owner_bb);
996 }
997}
998
999static void ir_ref_inst_gen(IrInstGen *instruction, IrBasicBlockGen *cur_bb) {
1000 assert(instruction->id != IrInstGenIdInvalid);
1001 instruction->base.ref_count += 1;
1002 if (instruction->owner_bb != cur_bb && !instr_is_comptime(instruction))
1003 ir_ref_bb_gen(instruction->owner_bb);
856}1004}
8571005
858static void ir_ref_var(ZigVar *var) {1006static void ir_ref_var(ZigVar *var) {
859 var->ref_count += 1;1007 var->ref_count += 1;
860}1008}
8611009
1010static void create_result_ptr(CodeGen *codegen, ZigType *expected_type,
1011 ZigValue **out_result, ZigValue **out_result_ptr)
1012{
1013 ZigValue *result = create_const_vals(1);
1014 ZigValue *result_ptr = create_const_vals(1);
1015 result->special = ConstValSpecialUndef;
1016 result->type = expected_type;
1017 result_ptr->special = ConstValSpecialStatic;
1018 result_ptr->type = get_pointer_to_type(codegen, result->type, false);
1019 result_ptr->data.x_ptr.mut = ConstPtrMutComptimeVar;
1020 result_ptr->data.x_ptr.special = ConstPtrSpecialRef;
1021 result_ptr->data.x_ptr.data.ref.pointee = result;
1022
1023 *out_result = result;
1024 *out_result_ptr = result_ptr;
1025}
1026
862ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) {1027ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) {
863 ZigValue *result = ir_eval_const_value(ira->codegen, scope, node, ira->codegen->builtin_types.entry_type,1028 Error err;
864 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, nullptr,1029
865 node, nullptr, ira->new_irb.exec, nullptr, UndefBad);1030 ZigValue *result;
1031 ZigValue *result_ptr;
1032 create_result_ptr(ira->codegen, ira->codegen->builtin_types.entry_type, &result, &result_ptr);
8661033
1034 if ((err = ir_eval_const_value(ira->codegen, scope, node, result_ptr,
1035 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota,
1036 nullptr, nullptr, node, nullptr, ira->new_irb.exec, nullptr, UndefBad)))
1037 {
1038 return ira->codegen->builtin_types.entry_invalid;
1039 }
867 if (type_is_invalid(result->type))1040 if (type_is_invalid(result->type))
868 return ira->codegen->builtin_types.entry_invalid;1041 return ira->codegen->builtin_types.entry_invalid;
8691042
870 assert(result->special != ConstValSpecialRuntime);1043 assert(result->special != ConstValSpecialRuntime);
871 return result->data.x_type;1044 ZigType *res_type = result->data.x_type;
1045
1046 destroy(result_ptr, "ZigValue");
1047 destroy(result, "ZigValue");
1048
1049 return res_type;
872}1050}
8731051
874static IrBasicBlock *ir_create_basic_block(IrBuilder *irb, Scope *scope, const char *name_hint) {1052static IrBasicBlockSrc *ir_create_basic_block(IrBuilderSrc *irb, Scope *scope, const char *name_hint) {
875 IrBasicBlock *result = allocate<IrBasicBlock>(1, "IrBasicBlock");1053 IrBasicBlockSrc *result = allocate<IrBasicBlockSrc>(1, "IrBasicBlockSrc");
876 result->scope = scope;1054 result->scope = scope;
877 result->name_hint = name_hint;1055 result->name_hint = name_hint;
878 result->debug_id = exec_next_debug_id(irb->exec);1056 result->debug_id = exec_next_debug_id(irb->exec);
879 result->index = SIZE_MAX; // set later1057 result->index = UINT32_MAX; // set later
1058 return result;
1059}
1060
1061static IrBasicBlockGen *ir_create_basic_block_gen(IrAnalyze *ira, Scope *scope, const char *name_hint) {
1062 IrBasicBlockGen *result = allocate<IrBasicBlockGen>(1, "IrBasicBlockGen");
1063 result->scope = scope;
1064 result->name_hint = name_hint;
1065 result->debug_id = exec_next_debug_id_gen(ira->new_irb.exec);
1066 result->index = UINT32_MAX; // set later
880 return result;1067 return result;
881}1068}
8821069
883static IrBasicBlock *ir_build_bb_from(IrBuilder *irb, IrBasicBlock *other_bb) {1070static IrBasicBlockGen *ir_build_bb_from(IrAnalyze *ira, IrBasicBlockSrc *other_bb) {
884 IrBasicBlock *new_bb = ir_create_basic_block(irb, other_bb->scope, other_bb->name_hint);1071 IrBasicBlockGen *new_bb = ir_create_basic_block_gen(ira, other_bb->scope, other_bb->name_hint);
885 ir_link_new_bb(new_bb, other_bb);1072 ir_link_new_bb(new_bb, other_bb);
886 return new_bb;1073 return new_bb;
887}1074}
8881075
889static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclVarSrc *) {1076static constexpr IrInstSrcId ir_inst_id(IrInstSrcDeclVar *) {
890 return IrInstructionIdDeclVarSrc;1077 return IrInstSrcIdDeclVar;
1078}
1079
1080static constexpr IrInstSrcId ir_inst_id(IrInstSrcBr *) {
1081 return IrInstSrcIdBr;
1082}
1083
1084static constexpr IrInstSrcId ir_inst_id(IrInstSrcCondBr *) {
1085 return IrInstSrcIdCondBr;
1086}
1087
1088static constexpr IrInstSrcId ir_inst_id(IrInstSrcSwitchBr *) {
1089 return IrInstSrcIdSwitchBr;
1090}
1091
1092static constexpr IrInstSrcId ir_inst_id(IrInstSrcSwitchVar *) {
1093 return IrInstSrcIdSwitchVar;
1094}
1095
1096static constexpr IrInstSrcId ir_inst_id(IrInstSrcSwitchElseVar *) {
1097 return IrInstSrcIdSwitchElseVar;
1098}
1099
1100static constexpr IrInstSrcId ir_inst_id(IrInstSrcSwitchTarget *) {
1101 return IrInstSrcIdSwitchTarget;
1102}
1103
1104static constexpr IrInstSrcId ir_inst_id(IrInstSrcPhi *) {
1105 return IrInstSrcIdPhi;
1106}
1107
1108static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnOp *) {
1109 return IrInstSrcIdUnOp;
1110}
1111
1112static constexpr IrInstSrcId ir_inst_id(IrInstSrcBinOp *) {
1113 return IrInstSrcIdBinOp;
1114}
1115
1116static constexpr IrInstSrcId ir_inst_id(IrInstSrcMergeErrSets *) {
1117 return IrInstSrcIdMergeErrSets;
1118}
1119
1120static constexpr IrInstSrcId ir_inst_id(IrInstSrcLoadPtr *) {
1121 return IrInstSrcIdLoadPtr;
1122}
1123
1124static constexpr IrInstSrcId ir_inst_id(IrInstSrcStorePtr *) {
1125 return IrInstSrcIdStorePtr;
1126}
1127
1128static constexpr IrInstSrcId ir_inst_id(IrInstSrcFieldPtr *) {
1129 return IrInstSrcIdFieldPtr;
1130}
1131
1132static constexpr IrInstSrcId ir_inst_id(IrInstSrcElemPtr *) {
1133 return IrInstSrcIdElemPtr;
1134}
1135
1136static constexpr IrInstSrcId ir_inst_id(IrInstSrcVarPtr *) {
1137 return IrInstSrcIdVarPtr;
1138}
1139
1140static constexpr IrInstSrcId ir_inst_id(IrInstSrcCall *) {
1141 return IrInstSrcIdCall;
1142}
1143
1144static constexpr IrInstSrcId ir_inst_id(IrInstSrcCallArgs *) {
1145 return IrInstSrcIdCallArgs;
1146}
1147
1148static constexpr IrInstSrcId ir_inst_id(IrInstSrcCallExtra *) {
1149 return IrInstSrcIdCallExtra;
1150}
1151
1152static constexpr IrInstSrcId ir_inst_id(IrInstSrcConst *) {
1153 return IrInstSrcIdConst;
1154}
1155
1156static constexpr IrInstSrcId ir_inst_id(IrInstSrcReturn *) {
1157 return IrInstSrcIdReturn;
1158}
1159
1160static constexpr IrInstSrcId ir_inst_id(IrInstSrcContainerInitList *) {
1161 return IrInstSrcIdContainerInitList;
1162}
1163
1164static constexpr IrInstSrcId ir_inst_id(IrInstSrcContainerInitFields *) {
1165 return IrInstSrcIdContainerInitFields;
1166}
1167
1168static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnreachable *) {
1169 return IrInstSrcIdUnreachable;
1170}
1171
1172static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeOf *) {
1173 return IrInstSrcIdTypeOf;
1174}
1175
1176static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetCold *) {
1177 return IrInstSrcIdSetCold;
1178}
1179
1180static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetRuntimeSafety *) {
1181 return IrInstSrcIdSetRuntimeSafety;
1182}
1183
1184static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetFloatMode *) {
1185 return IrInstSrcIdSetFloatMode;
1186}
1187
1188static constexpr IrInstSrcId ir_inst_id(IrInstSrcArrayType *) {
1189 return IrInstSrcIdArrayType;
1190}
1191
1192static constexpr IrInstSrcId ir_inst_id(IrInstSrcAnyFrameType *) {
1193 return IrInstSrcIdAnyFrameType;
1194}
1195
1196static constexpr IrInstSrcId ir_inst_id(IrInstSrcSliceType *) {
1197 return IrInstSrcIdSliceType;
1198}
1199
1200static constexpr IrInstSrcId ir_inst_id(IrInstSrcAsm *) {
1201 return IrInstSrcIdAsm;
1202}
1203
1204static constexpr IrInstSrcId ir_inst_id(IrInstSrcSizeOf *) {
1205 return IrInstSrcIdSizeOf;
1206}
1207
1208static constexpr IrInstSrcId ir_inst_id(IrInstSrcTestNonNull *) {
1209 return IrInstSrcIdTestNonNull;
1210}
1211
1212static constexpr IrInstSrcId ir_inst_id(IrInstSrcOptionalUnwrapPtr *) {
1213 return IrInstSrcIdOptionalUnwrapPtr;
1214}
1215
1216static constexpr IrInstSrcId ir_inst_id(IrInstSrcClz *) {
1217 return IrInstSrcIdClz;
1218}
1219
1220static constexpr IrInstSrcId ir_inst_id(IrInstSrcCtz *) {
1221 return IrInstSrcIdCtz;
1222}
1223
1224static constexpr IrInstSrcId ir_inst_id(IrInstSrcPopCount *) {
1225 return IrInstSrcIdPopCount;
1226}
1227
1228static constexpr IrInstSrcId ir_inst_id(IrInstSrcBswap *) {
1229 return IrInstSrcIdBswap;
1230}
1231
1232static constexpr IrInstSrcId ir_inst_id(IrInstSrcBitReverse *) {
1233 return IrInstSrcIdBitReverse;
891}1234}
8921235
893static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclVarGen *) {1236static constexpr IrInstSrcId ir_inst_id(IrInstSrcImport *) {
894 return IrInstructionIdDeclVarGen;1237 return IrInstSrcIdImport;
895}1238}
8961239
897static constexpr IrInstructionId ir_instruction_id(IrInstructionCondBr *) {1240static constexpr IrInstSrcId ir_inst_id(IrInstSrcCImport *) {
898 return IrInstructionIdCondBr;1241 return IrInstSrcIdCImport;
899}1242}
9001243
901static constexpr IrInstructionId ir_instruction_id(IrInstructionBr *) {1244static constexpr IrInstSrcId ir_inst_id(IrInstSrcCInclude *) {
902 return IrInstructionIdBr;1245 return IrInstSrcIdCInclude;
903}1246}
9041247
905static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchBr *) {1248static constexpr IrInstSrcId ir_inst_id(IrInstSrcCDefine *) {
906 return IrInstructionIdSwitchBr;1249 return IrInstSrcIdCDefine;
907}1250}
9081251
909static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchVar *) {1252static constexpr IrInstSrcId ir_inst_id(IrInstSrcCUndef *) {
910 return IrInstructionIdSwitchVar;1253 return IrInstSrcIdCUndef;
911}1254}
9121255
913static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchElseVar *) {1256static constexpr IrInstSrcId ir_inst_id(IrInstSrcRef *) {
914 return IrInstructionIdSwitchElseVar;1257 return IrInstSrcIdRef;
915}1258}
9161259
917static constexpr IrInstructionId ir_instruction_id(IrInstructionSwitchTarget *) {1260static constexpr IrInstSrcId ir_inst_id(IrInstSrcCompileErr *) {
918 return IrInstructionIdSwitchTarget;1261 return IrInstSrcIdCompileErr;
919}1262}
9201263
921static constexpr IrInstructionId ir_instruction_id(IrInstructionPhi *) {1264static constexpr IrInstSrcId ir_inst_id(IrInstSrcCompileLog *) {
922 return IrInstructionIdPhi;1265 return IrInstSrcIdCompileLog;
923}1266}
9241267
925static constexpr IrInstructionId ir_instruction_id(IrInstructionUnOp *) {1268static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrName *) {
926 return IrInstructionIdUnOp;1269 return IrInstSrcIdErrName;
927}1270}
9281271
929static constexpr IrInstructionId ir_instruction_id(IrInstructionBinOp *) {1272static constexpr IrInstSrcId ir_inst_id(IrInstSrcEmbedFile *) {
930 return IrInstructionIdBinOp;1273 return IrInstSrcIdEmbedFile;
931}1274}
9321275
933static constexpr IrInstructionId ir_instruction_id(IrInstructionMergeErrSets *) {1276static constexpr IrInstSrcId ir_inst_id(IrInstSrcCmpxchg *) {
934 return IrInstructionIdMergeErrSets;1277 return IrInstSrcIdCmpxchg;
935}1278}
9361279
937static constexpr IrInstructionId ir_instruction_id(IrInstructionExport *) {1280static constexpr IrInstSrcId ir_inst_id(IrInstSrcFence *) {
938 return IrInstructionIdExport;1281 return IrInstSrcIdFence;
939}1282}
9401283
941static constexpr IrInstructionId ir_instruction_id(IrInstructionLoadPtr *) {1284static constexpr IrInstSrcId ir_inst_id(IrInstSrcTruncate *) {
942 return IrInstructionIdLoadPtr;1285 return IrInstSrcIdTruncate;
943}1286}
9441287
945static constexpr IrInstructionId ir_instruction_id(IrInstructionLoadPtrGen *) {1288static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntCast *) {
946 return IrInstructionIdLoadPtrGen;1289 return IrInstSrcIdIntCast;
947}1290}
9481291
949static constexpr IrInstructionId ir_instruction_id(IrInstructionStorePtr *) {1292static constexpr IrInstSrcId ir_inst_id(IrInstSrcFloatCast *) {
950 return IrInstructionIdStorePtr;1293 return IrInstSrcIdFloatCast;
951}1294}
9521295
953static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorStoreElem *) {1296static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToFloat *) {
954 return IrInstructionIdVectorStoreElem;1297 return IrInstSrcIdIntToFloat;
955}1298}
9561299
957static constexpr IrInstructionId ir_instruction_id(IrInstructionFieldPtr *) {1300static constexpr IrInstSrcId ir_inst_id(IrInstSrcFloatToInt *) {
958 return IrInstructionIdFieldPtr;1301 return IrInstSrcIdFloatToInt;
959}1302}
9601303
961static constexpr IrInstructionId ir_instruction_id(IrInstructionStructFieldPtr *) {1304static constexpr IrInstSrcId ir_inst_id(IrInstSrcBoolToInt *) {
962 return IrInstructionIdStructFieldPtr;1305 return IrInstSrcIdBoolToInt;
963}1306}
9641307
965static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionFieldPtr *) {1308static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntType *) {
966 return IrInstructionIdUnionFieldPtr;1309 return IrInstSrcIdIntType;
967}1310}
9681311
969static constexpr IrInstructionId ir_instruction_id(IrInstructionElemPtr *) {1312static constexpr IrInstSrcId ir_inst_id(IrInstSrcVectorType *) {
970 return IrInstructionIdElemPtr;1313 return IrInstSrcIdVectorType;
971}1314}
9721315
973static constexpr IrInstructionId ir_instruction_id(IrInstructionVarPtr *) {1316static constexpr IrInstSrcId ir_inst_id(IrInstSrcShuffleVector *) {
974 return IrInstructionIdVarPtr;1317 return IrInstSrcIdShuffleVector;
975}1318}
9761319
977static constexpr IrInstructionId ir_instruction_id(IrInstructionReturnPtr *) {1320static constexpr IrInstSrcId ir_inst_id(IrInstSrcSplat *) {
978 return IrInstructionIdReturnPtr;1321 return IrInstSrcIdSplat;
979}1322}
9801323
981static constexpr IrInstructionId ir_instruction_id(IrInstructionCallSrc *) {1324static constexpr IrInstSrcId ir_inst_id(IrInstSrcBoolNot *) {
982 return IrInstructionIdCallSrc;1325 return IrInstSrcIdBoolNot;
983}1326}
9841327
985static constexpr IrInstructionId ir_instruction_id(IrInstructionCallSrcArgs *) {1328static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemset *) {
986 return IrInstructionIdCallSrcArgs;1329 return IrInstSrcIdMemset;
987}1330}
9881331
989static constexpr IrInstructionId ir_instruction_id(IrInstructionCallExtra *) {1332static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemcpy *) {
990 return IrInstructionIdCallExtra;1333 return IrInstSrcIdMemcpy;
991}1334}
9921335
993static constexpr IrInstructionId ir_instruction_id(IrInstructionCallGen *) {1336static constexpr IrInstSrcId ir_inst_id(IrInstSrcSlice *) {
994 return IrInstructionIdCallGen;1337 return IrInstSrcIdSlice;
995}1338}
9961339
997static constexpr IrInstructionId ir_instruction_id(IrInstructionConst *) {1340static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberCount *) {
998 return IrInstructionIdConst;1341 return IrInstSrcIdMemberCount;
999}1342}
10001343
1001static constexpr IrInstructionId ir_instruction_id(IrInstructionReturn *) {1344static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberType *) {
1002 return IrInstructionIdReturn;1345 return IrInstSrcIdMemberType;
1003}1346}
10041347
1005static constexpr IrInstructionId ir_instruction_id(IrInstructionCast *) {1348static constexpr IrInstSrcId ir_inst_id(IrInstSrcMemberName *) {
1006 return IrInstructionIdCast;1349 return IrInstSrcIdMemberName;
1007}1350}
10081351
1009static constexpr IrInstructionId ir_instruction_id(IrInstructionResizeSlice *) {1352static constexpr IrInstSrcId ir_inst_id(IrInstSrcBreakpoint *) {
1010 return IrInstructionIdResizeSlice;1353 return IrInstSrcIdBreakpoint;
1011}1354}
10121355
1013static constexpr IrInstructionId ir_instruction_id(IrInstructionContainerInitList *) {1356static constexpr IrInstSrcId ir_inst_id(IrInstSrcReturnAddress *) {
1014 return IrInstructionIdContainerInitList;1357 return IrInstSrcIdReturnAddress;
1015}1358}
10161359
1017static constexpr IrInstructionId ir_instruction_id(IrInstructionContainerInitFields *) {1360static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameAddress *) {
1018 return IrInstructionIdContainerInitFields;1361 return IrInstSrcIdFrameAddress;
1019}1362}
10201363
1021static constexpr IrInstructionId ir_instruction_id(IrInstructionUnreachable *) {1364static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameHandle *) {
1022 return IrInstructionIdUnreachable;1365 return IrInstSrcIdFrameHandle;
1023}1366}
10241367
1025static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeOf *) {1368static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameType *) {
1026 return IrInstructionIdTypeOf;1369 return IrInstSrcIdFrameType;
1027}1370}
10281371
1029static constexpr IrInstructionId ir_instruction_id(IrInstructionSetCold *) {1372static constexpr IrInstSrcId ir_inst_id(IrInstSrcFrameSize *) {
1030 return IrInstructionIdSetCold;1373 return IrInstSrcIdFrameSize;
1031}1374}
10321375
1033static constexpr IrInstructionId ir_instruction_id(IrInstructionSetRuntimeSafety *) {1376static constexpr IrInstSrcId ir_inst_id(IrInstSrcAlignOf *) {
1034 return IrInstructionIdSetRuntimeSafety;1377 return IrInstSrcIdAlignOf;
1035}1378}
10361379
1037static constexpr IrInstructionId ir_instruction_id(IrInstructionSetFloatMode *) {1380static constexpr IrInstSrcId ir_inst_id(IrInstSrcOverflowOp *) {
1038 return IrInstructionIdSetFloatMode;1381 return IrInstSrcIdOverflowOp;
1039}1382}
10401383
1041static constexpr IrInstructionId ir_instruction_id(IrInstructionArrayType *) {1384static constexpr IrInstSrcId ir_inst_id(IrInstSrcTestErr *) {
1042 return IrInstructionIdArrayType;1385 return IrInstSrcIdTestErr;
1043}1386}
10441387
1045static constexpr IrInstructionId ir_instruction_id(IrInstructionAnyFrameType *) {1388static constexpr IrInstSrcId ir_inst_id(IrInstSrcMulAdd *) {
1046 return IrInstructionIdAnyFrameType;1389 return IrInstSrcIdMulAdd;
1047}1390}
10481391
1049static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceType *) {1392static constexpr IrInstSrcId ir_inst_id(IrInstSrcFloatOp *) {
1050 return IrInstructionIdSliceType;1393 return IrInstSrcIdFloatOp;
1051}1394}
10521395
1053static constexpr IrInstructionId ir_instruction_id(IrInstructionAsmSrc *) {1396static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnwrapErrCode *) {
1054 return IrInstructionIdAsmSrc;1397 return IrInstSrcIdUnwrapErrCode;
1055}1398}
10561399
1057static constexpr IrInstructionId ir_instruction_id(IrInstructionAsmGen *) {1400static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnwrapErrPayload *) {
1058 return IrInstructionIdAsmGen;1401 return IrInstSrcIdUnwrapErrPayload;
1059}1402}
10601403
1061static constexpr IrInstructionId ir_instruction_id(IrInstructionSizeOf *) {1404static constexpr IrInstSrcId ir_inst_id(IrInstSrcFnProto *) {
1062 return IrInstructionIdSizeOf;1405 return IrInstSrcIdFnProto;
1063}1406}
10641407
1065static constexpr IrInstructionId ir_instruction_id(IrInstructionTestNonNull *) {1408static constexpr IrInstSrcId ir_inst_id(IrInstSrcTestComptime *) {
1066 return IrInstructionIdTestNonNull;1409 return IrInstSrcIdTestComptime;
1067}1410}
10681411
1069static constexpr IrInstructionId ir_instruction_id(IrInstructionOptionalUnwrapPtr *) {1412static constexpr IrInstSrcId ir_inst_id(IrInstSrcPtrCast *) {
1070 return IrInstructionIdOptionalUnwrapPtr;1413 return IrInstSrcIdPtrCast;
1071}1414}
10721415
1073static constexpr IrInstructionId ir_instruction_id(IrInstructionClz *) {1416static constexpr IrInstSrcId ir_inst_id(IrInstSrcBitCast *) {
1074 return IrInstructionIdClz;1417 return IrInstSrcIdBitCast;
1075}1418}
10761419
1077static constexpr IrInstructionId ir_instruction_id(IrInstructionCtz *) {1420static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToPtr *) {
1078 return IrInstructionIdCtz;1421 return IrInstSrcIdIntToPtr;
1079}1422}
10801423
1081static constexpr IrInstructionId ir_instruction_id(IrInstructionPopCount *) {1424static constexpr IrInstSrcId ir_inst_id(IrInstSrcPtrToInt *) {
1082 return IrInstructionIdPopCount;1425 return IrInstSrcIdPtrToInt;
1083}1426}
10841427
1085static constexpr IrInstructionId ir_instruction_id(IrInstructionBswap *) {1428static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToEnum *) {
1086 return IrInstructionIdBswap;1429 return IrInstSrcIdIntToEnum;
1087}1430}
10881431
1089static constexpr IrInstructionId ir_instruction_id(IrInstructionBitReverse *) {1432static constexpr IrInstSrcId ir_inst_id(IrInstSrcEnumToInt *) {
1090 return IrInstructionIdBitReverse;1433 return IrInstSrcIdEnumToInt;
1091}1434}
10921435
1093static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionTag *) {1436static constexpr IrInstSrcId ir_inst_id(IrInstSrcIntToErr *) {
1094 return IrInstructionIdUnionTag;1437 return IrInstSrcIdIntToErr;
1095}1438}
10961439
1097static constexpr IrInstructionId ir_instruction_id(IrInstructionImport *) {1440static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrToInt *) {
1098 return IrInstructionIdImport;1441 return IrInstSrcIdErrToInt;
1099}1442}
11001443
1101static constexpr IrInstructionId ir_instruction_id(IrInstructionCImport *) {1444static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckSwitchProngs *) {
1102 return IrInstructionIdCImport;1445 return IrInstSrcIdCheckSwitchProngs;
1103}1446}
11041447
1105static constexpr IrInstructionId ir_instruction_id(IrInstructionCInclude *) {1448static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckStatementIsVoid *) {
1106 return IrInstructionIdCInclude;1449 return IrInstSrcIdCheckStatementIsVoid;
1107}1450}
11081451
1109static constexpr IrInstructionId ir_instruction_id(IrInstructionCDefine *) {1452static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeName *) {
1110 return IrInstructionIdCDefine;1453 return IrInstSrcIdTypeName;
1111}1454}
11121455
1113static constexpr IrInstructionId ir_instruction_id(IrInstructionCUndef *) {1456static constexpr IrInstSrcId ir_inst_id(IrInstSrcDeclRef *) {
1114 return IrInstructionIdCUndef;1457 return IrInstSrcIdDeclRef;
1115}1458}
11161459
1117static constexpr IrInstructionId ir_instruction_id(IrInstructionRef *) {1460static constexpr IrInstSrcId ir_inst_id(IrInstSrcPanic *) {
1118 return IrInstructionIdRef;1461 return IrInstSrcIdPanic;
1119}1462}
11201463
1121static constexpr IrInstructionId ir_instruction_id(IrInstructionRefGen *) {1464static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagName *) {
1122 return IrInstructionIdRefGen;1465 return IrInstSrcIdTagName;
1123}1466}
11241467
1125static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileErr *) {1468static constexpr IrInstSrcId ir_inst_id(IrInstSrcTagType *) {
1126 return IrInstructionIdCompileErr;1469 return IrInstSrcIdTagType;
1127}1470}
11281471
1129static constexpr IrInstructionId ir_instruction_id(IrInstructionCompileLog *) {1472static constexpr IrInstSrcId ir_inst_id(IrInstSrcFieldParentPtr *) {
1130 return IrInstructionIdCompileLog;1473 return IrInstSrcIdFieldParentPtr;
1131}1474}
11321475
1133static constexpr IrInstructionId ir_instruction_id(IrInstructionErrName *) {1476static constexpr IrInstSrcId ir_inst_id(IrInstSrcByteOffsetOf *) {
1134 return IrInstructionIdErrName;1477 return IrInstSrcIdByteOffsetOf;
1135}1478}
11361479
1137static constexpr IrInstructionId ir_instruction_id(IrInstructionEmbedFile *) {1480static constexpr IrInstSrcId ir_inst_id(IrInstSrcBitOffsetOf *) {
1138 return IrInstructionIdEmbedFile;1481 return IrInstSrcIdBitOffsetOf;
1139}1482}
11401483
1141static constexpr IrInstructionId ir_instruction_id(IrInstructionCmpxchgSrc *) {1484static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeInfo *) {
1142 return IrInstructionIdCmpxchgSrc;1485 return IrInstSrcIdTypeInfo;
1143}1486}
11441487
1145static constexpr IrInstructionId ir_instruction_id(IrInstructionCmpxchgGen *) {1488static constexpr IrInstSrcId ir_inst_id(IrInstSrcType *) {
1146 return IrInstructionIdCmpxchgGen;1489 return IrInstSrcIdType;
1147}1490}
11481491
1149static constexpr IrInstructionId ir_instruction_id(IrInstructionFence *) {1492static constexpr IrInstSrcId ir_inst_id(IrInstSrcHasField *) {
1150 return IrInstructionIdFence;1493 return IrInstSrcIdHasField;
1151}1494}
11521495
1153static constexpr IrInstructionId ir_instruction_id(IrInstructionTruncate *) {1496static constexpr IrInstSrcId ir_inst_id(IrInstSrcTypeId *) {
1154 return IrInstructionIdTruncate;1497 return IrInstSrcIdTypeId;
1155}1498}
11561499
1157static constexpr IrInstructionId ir_instruction_id(IrInstructionIntCast *) {1500static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetEvalBranchQuota *) {
1158 return IrInstructionIdIntCast;1501 return IrInstSrcIdSetEvalBranchQuota;
1159}1502}
11601503
1161static constexpr IrInstructionId ir_instruction_id(IrInstructionFloatCast *) {1504static constexpr IrInstSrcId ir_inst_id(IrInstSrcPtrType *) {
1162 return IrInstructionIdFloatCast;1505 return IrInstSrcIdPtrType;
1163}1506}
11641507
1165static constexpr IrInstructionId ir_instruction_id(IrInstructionErrSetCast *) {1508static constexpr IrInstSrcId ir_inst_id(IrInstSrcAlignCast *) {
1166 return IrInstructionIdErrSetCast;1509 return IrInstSrcIdAlignCast;
1167}1510}
11681511
1169static constexpr IrInstructionId ir_instruction_id(IrInstructionToBytes *) {1512static constexpr IrInstSrcId ir_inst_id(IrInstSrcImplicitCast *) {
1170 return IrInstructionIdToBytes;1513 return IrInstSrcIdImplicitCast;
1171}1514}
11721515
1173static constexpr IrInstructionId ir_instruction_id(IrInstructionFromBytes *) {1516static constexpr IrInstSrcId ir_inst_id(IrInstSrcResolveResult *) {
1174 return IrInstructionIdFromBytes;1517 return IrInstSrcIdResolveResult;
1175}1518}
11761519
1177static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToFloat *) {1520static constexpr IrInstSrcId ir_inst_id(IrInstSrcResetResult *) {
1178 return IrInstructionIdIntToFloat;1521 return IrInstSrcIdResetResult;
1179}1522}
11801523
1181static constexpr IrInstructionId ir_instruction_id(IrInstructionFloatToInt *) {1524static constexpr IrInstSrcId ir_inst_id(IrInstSrcOpaqueType *) {
1182 return IrInstructionIdFloatToInt;1525 return IrInstSrcIdOpaqueType;
1183}1526}
11841527
1185static constexpr IrInstructionId ir_instruction_id(IrInstructionBoolToInt *) {1528static constexpr IrInstSrcId ir_inst_id(IrInstSrcSetAlignStack *) {
1186 return IrInstructionIdBoolToInt;1529 return IrInstSrcIdSetAlignStack;
1187}1530}
11881531
1189static constexpr IrInstructionId ir_instruction_id(IrInstructionIntType *) {1532static constexpr IrInstSrcId ir_inst_id(IrInstSrcArgType *) {
1190 return IrInstructionIdIntType;1533 return IrInstSrcIdArgType;
1191}1534}
11921535
1193static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorType *) {1536static constexpr IrInstSrcId ir_inst_id(IrInstSrcExport *) {
1194 return IrInstructionIdVectorType;1537 return IrInstSrcIdExport;
1195}1538}
11961539
1197static constexpr IrInstructionId ir_instruction_id(IrInstructionShuffleVector *) {1540static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrorReturnTrace *) {
1198 return IrInstructionIdShuffleVector;1541 return IrInstSrcIdErrorReturnTrace;
1199}1542}
12001543
1201static constexpr IrInstructionId ir_instruction_id(IrInstructionSplatSrc *) {1544static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrorUnion *) {
1202 return IrInstructionIdSplatSrc;1545 return IrInstSrcIdErrorUnion;
1203}1546}
12041547
1205static constexpr IrInstructionId ir_instruction_id(IrInstructionSplatGen *) {1548static constexpr IrInstSrcId ir_inst_id(IrInstSrcAtomicRmw *) {
1206 return IrInstructionIdSplatGen;1549 return IrInstSrcIdAtomicRmw;
1207}1550}
12081551
1209static constexpr IrInstructionId ir_instruction_id(IrInstructionBoolNot *) {1552static constexpr IrInstSrcId ir_inst_id(IrInstSrcAtomicLoad *) {
1210 return IrInstructionIdBoolNot;1553 return IrInstSrcIdAtomicLoad;
1211}1554}
12121555
1213static constexpr IrInstructionId ir_instruction_id(IrInstructionMemset *) {1556static constexpr IrInstSrcId ir_inst_id(IrInstSrcAtomicStore *) {
1214 return IrInstructionIdMemset;1557 return IrInstSrcIdAtomicStore;
1215}1558}
12161559
1217static constexpr IrInstructionId ir_instruction_id(IrInstructionMemcpy *) {1560static constexpr IrInstSrcId ir_inst_id(IrInstSrcSaveErrRetAddr *) {
1218 return IrInstructionIdMemcpy;1561 return IrInstSrcIdSaveErrRetAddr;
1219}1562}
12201563
1221static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceSrc *) {1564static constexpr IrInstSrcId ir_inst_id(IrInstSrcAddImplicitReturnType *) {
1222 return IrInstructionIdSliceSrc;1565 return IrInstSrcIdAddImplicitReturnType;
1223}1566}
12241567
1225static constexpr IrInstructionId ir_instruction_id(IrInstructionSliceGen *) {1568static constexpr IrInstSrcId ir_inst_id(IrInstSrcErrSetCast *) {
1226 return IrInstructionIdSliceGen;1569 return IrInstSrcIdErrSetCast;
1227}1570}
12281571
1229static constexpr IrInstructionId ir_instruction_id(IrInstructionMemberCount *) {1572static constexpr IrInstSrcId ir_inst_id(IrInstSrcToBytes *) {
1230 return IrInstructionIdMemberCount;1573 return IrInstSrcIdToBytes;
1231}1574}
12321575
1233static constexpr IrInstructionId ir_instruction_id(IrInstructionMemberType *) {1576static constexpr IrInstSrcId ir_inst_id(IrInstSrcFromBytes *) {
1234 return IrInstructionIdMemberType;1577 return IrInstSrcIdFromBytes;
1235}1578}
12361579
1237static constexpr IrInstructionId ir_instruction_id(IrInstructionMemberName *) {1580static constexpr IrInstSrcId ir_inst_id(IrInstSrcCheckRuntimeScope *) {
1238 return IrInstructionIdMemberName;1581 return IrInstSrcIdCheckRuntimeScope;
1239}1582}
12401583
1241static constexpr IrInstructionId ir_instruction_id(IrInstructionBreakpoint *) {1584static constexpr IrInstSrcId ir_inst_id(IrInstSrcHasDecl *) {
1242 return IrInstructionIdBreakpoint;1585 return IrInstSrcIdHasDecl;
1243}1586}
12441587
1245static constexpr IrInstructionId ir_instruction_id(IrInstructionReturnAddress *) {1588static constexpr IrInstSrcId ir_inst_id(IrInstSrcUndeclaredIdent *) {
1246 return IrInstructionIdReturnAddress;1589 return IrInstSrcIdUndeclaredIdent;
1247}1590}
12481591
1249static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameAddress *) {1592static constexpr IrInstSrcId ir_inst_id(IrInstSrcAlloca *) {
1250 return IrInstructionIdFrameAddress;1593 return IrInstSrcIdAlloca;
1251}1594}
12521595
1253static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameHandle *) {1596static constexpr IrInstSrcId ir_inst_id(IrInstSrcEndExpr *) {
1254 return IrInstructionIdFrameHandle;1597 return IrInstSrcIdEndExpr;
1255}1598}
12561599
1257static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameType *) {1600static constexpr IrInstSrcId ir_inst_id(IrInstSrcUnionInitNamedField *) {
1258 return IrInstructionIdFrameType;1601 return IrInstSrcIdUnionInitNamedField;
1259}1602}
12601603
1261static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameSizeSrc *) {1604static constexpr IrInstSrcId ir_inst_id(IrInstSrcSuspendBegin *) {
1262 return IrInstructionIdFrameSizeSrc;1605 return IrInstSrcIdSuspendBegin;
1263}1606}
12641607
1265static constexpr IrInstructionId ir_instruction_id(IrInstructionFrameSizeGen *) {1608static constexpr IrInstSrcId ir_inst_id(IrInstSrcSuspendFinish *) {
1266 return IrInstructionIdFrameSizeGen;1609 return IrInstSrcIdSuspendFinish;
1267}1610}
12681611
1269static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignOf *) {1612static constexpr IrInstSrcId ir_inst_id(IrInstSrcAwait *) {
1270 return IrInstructionIdAlignOf;1613 return IrInstSrcIdAwait;
1271}1614}
12721615
1273static constexpr IrInstructionId ir_instruction_id(IrInstructionOverflowOp *) {1616static constexpr IrInstSrcId ir_inst_id(IrInstSrcResume *) {
1274 return IrInstructionIdOverflowOp;1617 return IrInstSrcIdResume;
1275}1618}
12761619
1277static constexpr IrInstructionId ir_instruction_id(IrInstructionTestErrSrc *) {1620static constexpr IrInstSrcId ir_inst_id(IrInstSrcSpillBegin *) {
1278 return IrInstructionIdTestErrSrc;1621 return IrInstSrcIdSpillBegin;
1279}1622}
12801623
1281static constexpr IrInstructionId ir_instruction_id(IrInstructionTestErrGen *) {1624static constexpr IrInstSrcId ir_inst_id(IrInstSrcSpillEnd *) {
1282 return IrInstructionIdTestErrGen;1625 return IrInstSrcIdSpillEnd;
1283}1626}
12841627
1285static constexpr IrInstructionId ir_instruction_id(IrInstructionMulAdd *) {1628
1286 return IrInstructionIdMulAdd;1629static constexpr IrInstGenId ir_inst_id(IrInstGenDeclVar *) {
1630 return IrInstGenIdDeclVar;
1631}
1632
1633static constexpr IrInstGenId ir_inst_id(IrInstGenBr *) {
1634 return IrInstGenIdBr;
1635}
1636
1637static constexpr IrInstGenId ir_inst_id(IrInstGenCondBr *) {
1638 return IrInstGenIdCondBr;
1639}
1640
1641static constexpr IrInstGenId ir_inst_id(IrInstGenSwitchBr *) {
1642 return IrInstGenIdSwitchBr;
1643}
1644
1645static constexpr IrInstGenId ir_inst_id(IrInstGenPhi *) {
1646 return IrInstGenIdPhi;
1647}
1648
1649static constexpr IrInstGenId ir_inst_id(IrInstGenBinaryNot *) {
1650 return IrInstGenIdBinaryNot;
1651}
1652
1653static constexpr IrInstGenId ir_inst_id(IrInstGenNegation *) {
1654 return IrInstGenIdNegation;
1655}
1656
1657static constexpr IrInstGenId ir_inst_id(IrInstGenNegationWrapping *) {
1658 return IrInstGenIdNegationWrapping;
1659}
1660
1661static constexpr IrInstGenId ir_inst_id(IrInstGenBinOp *) {
1662 return IrInstGenIdBinOp;
1663}
1664
1665static constexpr IrInstGenId ir_inst_id(IrInstGenLoadPtr *) {
1666 return IrInstGenIdLoadPtr;
1667}
1668
1669static constexpr IrInstGenId ir_inst_id(IrInstGenStorePtr *) {
1670 return IrInstGenIdStorePtr;
1671}
1672
1673static constexpr IrInstGenId ir_inst_id(IrInstGenVectorStoreElem *) {
1674 return IrInstGenIdVectorStoreElem;
1675}
1676
1677static constexpr IrInstGenId ir_inst_id(IrInstGenStructFieldPtr *) {
1678 return IrInstGenIdStructFieldPtr;
1679}
1680
1681static constexpr IrInstGenId ir_inst_id(IrInstGenUnionFieldPtr *) {
1682 return IrInstGenIdUnionFieldPtr;
1683}
1684
1685static constexpr IrInstGenId ir_inst_id(IrInstGenElemPtr *) {
1686 return IrInstGenIdElemPtr;
1687}
1688
1689static constexpr IrInstGenId ir_inst_id(IrInstGenVarPtr *) {
1690 return IrInstGenIdVarPtr;
1691}
1692
1693static constexpr IrInstGenId ir_inst_id(IrInstGenReturnPtr *) {
1694 return IrInstGenIdReturnPtr;
1695}
1696
1697static constexpr IrInstGenId ir_inst_id(IrInstGenCall *) {
1698 return IrInstGenIdCall;
1699}
1700
1701static constexpr IrInstGenId ir_inst_id(IrInstGenReturn *) {
1702 return IrInstGenIdReturn;
1287}1703}
12881704
1289static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrCode *) {1705static constexpr IrInstGenId ir_inst_id(IrInstGenCast *) {
1290 return IrInstructionIdUnwrapErrCode;1706 return IrInstGenIdCast;
1291}1707}
12921708
1293static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrPayload *) {1709static constexpr IrInstGenId ir_inst_id(IrInstGenResizeSlice *) {
1294 return IrInstructionIdUnwrapErrPayload;1710 return IrInstGenIdResizeSlice;
1295}1711}
12961712
1297static constexpr IrInstructionId ir_instruction_id(IrInstructionOptionalWrap *) {1713static constexpr IrInstGenId ir_inst_id(IrInstGenUnreachable *) {
1298 return IrInstructionIdOptionalWrap;1714 return IrInstGenIdUnreachable;
1299}1715}
13001716
1301static constexpr IrInstructionId ir_instruction_id(IrInstructionErrWrapPayload *) {1717static constexpr IrInstGenId ir_inst_id(IrInstGenAsm *) {
1302 return IrInstructionIdErrWrapPayload;1718 return IrInstGenIdAsm;
1303}1719}
13041720
1305static constexpr IrInstructionId ir_instruction_id(IrInstructionErrWrapCode *) {1721static constexpr IrInstGenId ir_inst_id(IrInstGenTestNonNull *) {
1306 return IrInstructionIdErrWrapCode;1722 return IrInstGenIdTestNonNull;
1307}1723}
13081724
1309static constexpr IrInstructionId ir_instruction_id(IrInstructionFnProto *) {1725static constexpr IrInstGenId ir_inst_id(IrInstGenOptionalUnwrapPtr *) {
1310 return IrInstructionIdFnProto;1726 return IrInstGenIdOptionalUnwrapPtr;
1311}1727}
13121728
1313static constexpr IrInstructionId ir_instruction_id(IrInstructionTestComptime *) {1729static constexpr IrInstGenId ir_inst_id(IrInstGenOptionalWrap *) {
1314 return IrInstructionIdTestComptime;1730 return IrInstGenIdOptionalWrap;
1315}1731}
13161732
1317static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrCastSrc *) {1733static constexpr IrInstGenId ir_inst_id(IrInstGenUnionTag *) {
1318 return IrInstructionIdPtrCastSrc;1734 return IrInstGenIdUnionTag;
1319}1735}
13201736
1321static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrCastGen *) {1737static constexpr IrInstGenId ir_inst_id(IrInstGenClz *) {
1322 return IrInstructionIdPtrCastGen;1738 return IrInstGenIdClz;
1323}1739}
13241740
1325static constexpr IrInstructionId ir_instruction_id(IrInstructionBitCastSrc *) {1741static constexpr IrInstGenId ir_inst_id(IrInstGenCtz *) {
1326 return IrInstructionIdBitCastSrc;1742 return IrInstGenIdCtz;
1327}1743}
13281744
1329static constexpr IrInstructionId ir_instruction_id(IrInstructionBitCastGen *) {1745static constexpr IrInstGenId ir_inst_id(IrInstGenPopCount *) {
1330 return IrInstructionIdBitCastGen;1746 return IrInstGenIdPopCount;
1331}1747}
13321748
1333static constexpr IrInstructionId ir_instruction_id(IrInstructionWidenOrShorten *) {1749static constexpr IrInstGenId ir_inst_id(IrInstGenBswap *) {
1334 return IrInstructionIdWidenOrShorten;1750 return IrInstGenIdBswap;
1335}1751}
13361752
1337static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrToInt *) {1753static constexpr IrInstGenId ir_inst_id(IrInstGenBitReverse *) {
1338 return IrInstructionIdPtrToInt;1754 return IrInstGenIdBitReverse;
1339}1755}
13401756
1341static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToPtr *) {1757static constexpr IrInstGenId ir_inst_id(IrInstGenRef *) {
1342 return IrInstructionIdIntToPtr;1758 return IrInstGenIdRef;
1343}1759}
13441760
1345static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToEnum *) {1761static constexpr IrInstGenId ir_inst_id(IrInstGenErrName *) {
1346 return IrInstructionIdIntToEnum;1762 return IrInstGenIdErrName;
1347}1763}
13481764
1349static constexpr IrInstructionId ir_instruction_id(IrInstructionEnumToInt *) {1765static constexpr IrInstGenId ir_inst_id(IrInstGenCmpxchg *) {
1350 return IrInstructionIdEnumToInt;1766 return IrInstGenIdCmpxchg;
1351}1767}
13521768
1353static constexpr IrInstructionId ir_instruction_id(IrInstructionIntToErr *) {1769static constexpr IrInstGenId ir_inst_id(IrInstGenFence *) {
1354 return IrInstructionIdIntToErr;1770 return IrInstGenIdFence;
1355}1771}
13561772
1357static constexpr IrInstructionId ir_instruction_id(IrInstructionErrToInt *) {1773static constexpr IrInstGenId ir_inst_id(IrInstGenTruncate *) {
1358 return IrInstructionIdErrToInt;1774 return IrInstGenIdTruncate;
1359}1775}
13601776
1361static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckSwitchProngs *) {1777static constexpr IrInstGenId ir_inst_id(IrInstGenShuffleVector *) {
1362 return IrInstructionIdCheckSwitchProngs;1778 return IrInstGenIdShuffleVector;
1363}1779}
13641780
1365static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckStatementIsVoid *) {1781static constexpr IrInstGenId ir_inst_id(IrInstGenSplat *) {
1366 return IrInstructionIdCheckStatementIsVoid;1782 return IrInstGenIdSplat;
1367}1783}
13681784
1369static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeName *) {1785static constexpr IrInstGenId ir_inst_id(IrInstGenBoolNot *) {
1370 return IrInstructionIdTypeName;1786 return IrInstGenIdBoolNot;
1371}1787}
13721788
1373static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclRef *) {1789static constexpr IrInstGenId ir_inst_id(IrInstGenMemset *) {
1374 return IrInstructionIdDeclRef;1790 return IrInstGenIdMemset;
1375}1791}
13761792
1377static constexpr IrInstructionId ir_instruction_id(IrInstructionPanic *) {1793static constexpr IrInstGenId ir_inst_id(IrInstGenMemcpy *) {
1378 return IrInstructionIdPanic;1794 return IrInstGenIdMemcpy;
1379}1795}
13801796
1381static constexpr IrInstructionId ir_instruction_id(IrInstructionTagName *) {1797static constexpr IrInstGenId ir_inst_id(IrInstGenSlice *) {
1382 return IrInstructionIdTagName;1798 return IrInstGenIdSlice;
1383}1799}
13841800
1385static constexpr IrInstructionId ir_instruction_id(IrInstructionTagType *) {1801static constexpr IrInstGenId ir_inst_id(IrInstGenBreakpoint *) {
1386 return IrInstructionIdTagType;1802 return IrInstGenIdBreakpoint;
1387}1803}
13881804
1389static constexpr IrInstructionId ir_instruction_id(IrInstructionFieldParentPtr *) {1805static constexpr IrInstGenId ir_inst_id(IrInstGenReturnAddress *) {
1390 return IrInstructionIdFieldParentPtr;1806 return IrInstGenIdReturnAddress;
1391}1807}
13921808
1393static constexpr IrInstructionId ir_instruction_id(IrInstructionByteOffsetOf *) {1809static constexpr IrInstGenId ir_inst_id(IrInstGenFrameAddress *) {
1394 return IrInstructionIdByteOffsetOf;1810 return IrInstGenIdFrameAddress;
1395}1811}
13961812
1397static constexpr IrInstructionId ir_instruction_id(IrInstructionBitOffsetOf *) {1813static constexpr IrInstGenId ir_inst_id(IrInstGenFrameHandle *) {
1398 return IrInstructionIdBitOffsetOf;1814 return IrInstGenIdFrameHandle;
1399}1815}
14001816
1401static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeInfo *) {1817static constexpr IrInstGenId ir_inst_id(IrInstGenFrameSize *) {
1402 return IrInstructionIdTypeInfo;1818 return IrInstGenIdFrameSize;
1403}1819}
14041820
1405static constexpr IrInstructionId ir_instruction_id(IrInstructionType *) {1821static constexpr IrInstGenId ir_inst_id(IrInstGenOverflowOp *) {
1406 return IrInstructionIdType;1822 return IrInstGenIdOverflowOp;
1407}1823}
14081824
1409static constexpr IrInstructionId ir_instruction_id(IrInstructionHasField *) {1825static constexpr IrInstGenId ir_inst_id(IrInstGenTestErr *) {
1410 return IrInstructionIdHasField;1826 return IrInstGenIdTestErr;
1411}1827}
14121828
1413static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeId *) {1829static constexpr IrInstGenId ir_inst_id(IrInstGenMulAdd *) {
1414 return IrInstructionIdTypeId;1830 return IrInstGenIdMulAdd;
1415}1831}
14161832
1417static constexpr IrInstructionId ir_instruction_id(IrInstructionSetEvalBranchQuota *) {1833static constexpr IrInstGenId ir_inst_id(IrInstGenFloatOp *) {
1418 return IrInstructionIdSetEvalBranchQuota;1834 return IrInstGenIdFloatOp;
1419}1835}
14201836
1421static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrType *) {1837static constexpr IrInstGenId ir_inst_id(IrInstGenUnwrapErrCode *) {
1422 return IrInstructionIdPtrType;1838 return IrInstGenIdUnwrapErrCode;
1423}1839}
14241840
1425static constexpr IrInstructionId ir_instruction_id(IrInstructionAlignCast *) {1841static constexpr IrInstGenId ir_inst_id(IrInstGenUnwrapErrPayload *) {
1426 return IrInstructionIdAlignCast;1842 return IrInstGenIdUnwrapErrPayload;
1427}1843}
14281844
1429static constexpr IrInstructionId ir_instruction_id(IrInstructionImplicitCast *) {1845static constexpr IrInstGenId ir_inst_id(IrInstGenErrWrapCode *) {
1430 return IrInstructionIdImplicitCast;1846 return IrInstGenIdErrWrapCode;
1431}1847}
14321848
1433static constexpr IrInstructionId ir_instruction_id(IrInstructionResolveResult *) {1849static constexpr IrInstGenId ir_inst_id(IrInstGenErrWrapPayload *) {
1434 return IrInstructionIdResolveResult;1850 return IrInstGenIdErrWrapPayload;
1435}1851}
14361852
1437static constexpr IrInstructionId ir_instruction_id(IrInstructionResetResult *) {1853static constexpr IrInstGenId ir_inst_id(IrInstGenPtrCast *) {
1438 return IrInstructionIdResetResult;1854 return IrInstGenIdPtrCast;
1439}1855}
14401856
1441static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrOfArrayToSlice *) {1857static constexpr IrInstGenId ir_inst_id(IrInstGenBitCast *) {
1442 return IrInstructionIdPtrOfArrayToSlice;1858 return IrInstGenIdBitCast;
1443}1859}
14441860
1445static constexpr IrInstructionId ir_instruction_id(IrInstructionOpaqueType *) {1861static constexpr IrInstGenId ir_inst_id(IrInstGenWidenOrShorten *) {
1446 return IrInstructionIdOpaqueType;1862 return IrInstGenIdWidenOrShorten;
1447}1863}
14481864
1449static constexpr IrInstructionId ir_instruction_id(IrInstructionSetAlignStack *) {1865static constexpr IrInstGenId ir_inst_id(IrInstGenIntToPtr *) {
1450 return IrInstructionIdSetAlignStack;1866 return IrInstGenIdIntToPtr;
1451}1867}
14521868
1453static constexpr IrInstructionId ir_instruction_id(IrInstructionArgType *) {1869static constexpr IrInstGenId ir_inst_id(IrInstGenPtrToInt *) {
1454 return IrInstructionIdArgType;1870 return IrInstGenIdPtrToInt;
1455}1871}
14561872
1457static constexpr IrInstructionId ir_instruction_id(IrInstructionErrorReturnTrace *) {1873static constexpr IrInstGenId ir_inst_id(IrInstGenIntToEnum *) {
1458 return IrInstructionIdErrorReturnTrace;1874 return IrInstGenIdIntToEnum;
1459}1875}
14601876
1461static constexpr IrInstructionId ir_instruction_id(IrInstructionErrorUnion *) {1877static constexpr IrInstGenId ir_inst_id(IrInstGenIntToErr *) {
1462 return IrInstructionIdErrorUnion;1878 return IrInstGenIdIntToErr;
1463}1879}
14641880
1465static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicRmw *) {1881static constexpr IrInstGenId ir_inst_id(IrInstGenErrToInt *) {
1466 return IrInstructionIdAtomicRmw;1882 return IrInstGenIdErrToInt;
1467}1883}
14681884
1469static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicLoad *) {1885static constexpr IrInstGenId ir_inst_id(IrInstGenPanic *) {
1470 return IrInstructionIdAtomicLoad;1886 return IrInstGenIdPanic;
1471}1887}
14721888
1473static constexpr IrInstructionId ir_instruction_id(IrInstructionAtomicStore *) {1889static constexpr IrInstGenId ir_inst_id(IrInstGenTagName *) {
1474 return IrInstructionIdAtomicStore;1890 return IrInstGenIdTagName;
1475}1891}
14761892
1477static constexpr IrInstructionId ir_instruction_id(IrInstructionSaveErrRetAddr *) {1893static constexpr IrInstGenId ir_inst_id(IrInstGenFieldParentPtr *) {
1478 return IrInstructionIdSaveErrRetAddr;1894 return IrInstGenIdFieldParentPtr;
1479}1895}
14801896
1481static constexpr IrInstructionId ir_instruction_id(IrInstructionAddImplicitReturnType *) {1897static constexpr IrInstGenId ir_inst_id(IrInstGenAlignCast *) {
1482 return IrInstructionIdAddImplicitReturnType;1898 return IrInstGenIdAlignCast;
1483}1899}
14841900
1485static constexpr IrInstructionId ir_instruction_id(IrInstructionFloatOp *) {1901static constexpr IrInstGenId ir_inst_id(IrInstGenErrorReturnTrace *) {
1486 return IrInstructionIdFloatOp;1902 return IrInstGenIdErrorReturnTrace;
1487}1903}
14881904
1489static constexpr IrInstructionId ir_instruction_id(IrInstructionCheckRuntimeScope *) {1905static constexpr IrInstGenId ir_inst_id(IrInstGenAtomicRmw *) {
1490 return IrInstructionIdCheckRuntimeScope;1906 return IrInstGenIdAtomicRmw;
1491}1907}
14921908
1493static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorToArray *) {1909static constexpr IrInstGenId ir_inst_id(IrInstGenAtomicLoad *) {
1494 return IrInstructionIdVectorToArray;1910 return IrInstGenIdAtomicLoad;
1495}1911}
14961912
1497static constexpr IrInstructionId ir_instruction_id(IrInstructionArrayToVector *) {1913static constexpr IrInstGenId ir_inst_id(IrInstGenAtomicStore *) {
1498 return IrInstructionIdArrayToVector;1914 return IrInstGenIdAtomicStore;
1499}1915}
15001916
1501static constexpr IrInstructionId ir_instruction_id(IrInstructionAssertZero *) {1917static constexpr IrInstGenId ir_inst_id(IrInstGenSaveErrRetAddr *) {
1502 return IrInstructionIdAssertZero;1918 return IrInstGenIdSaveErrRetAddr;
1503}1919}
15041920
1505static constexpr IrInstructionId ir_instruction_id(IrInstructionAssertNonNull *) {1921static constexpr IrInstGenId ir_inst_id(IrInstGenVectorToArray *) {
1506 return IrInstructionIdAssertNonNull;1922 return IrInstGenIdVectorToArray;
1507}1923}
15081924
1509static constexpr IrInstructionId ir_instruction_id(IrInstructionHasDecl *) {1925static constexpr IrInstGenId ir_inst_id(IrInstGenArrayToVector *) {
1510 return IrInstructionIdHasDecl;1926 return IrInstGenIdArrayToVector;
1511}1927}
15121928
1513static constexpr IrInstructionId ir_instruction_id(IrInstructionUndeclaredIdent *) {1929static constexpr IrInstGenId ir_inst_id(IrInstGenAssertZero *) {
1514 return IrInstructionIdUndeclaredIdent;1930 return IrInstGenIdAssertZero;
1515}1931}
15161932
1517static constexpr IrInstructionId ir_instruction_id(IrInstructionAllocaSrc *) {1933static constexpr IrInstGenId ir_inst_id(IrInstGenAssertNonNull *) {
1518 return IrInstructionIdAllocaSrc;1934 return IrInstGenIdAssertNonNull;
1519}1935}
15201936
1521static constexpr IrInstructionId ir_instruction_id(IrInstructionAllocaGen *) {1937static constexpr IrInstGenId ir_inst_id(IrInstGenPtrOfArrayToSlice *) {
1522 return IrInstructionIdAllocaGen;1938 return IrInstGenIdPtrOfArrayToSlice;
1523}1939}
15241940
1525static constexpr IrInstructionId ir_instruction_id(IrInstructionEndExpr *) {1941static constexpr IrInstGenId ir_inst_id(IrInstGenSuspendBegin *) {
1526 return IrInstructionIdEndExpr;1942 return IrInstGenIdSuspendBegin;
1527}1943}
15281944
1529static constexpr IrInstructionId ir_instruction_id(IrInstructionUnionInitNamedField *) {1945static constexpr IrInstGenId ir_inst_id(IrInstGenSuspendFinish *) {
1530 return IrInstructionIdUnionInitNamedField;1946 return IrInstGenIdSuspendFinish;
1531}1947}
15321948
1533static constexpr IrInstructionId ir_instruction_id(IrInstructionSuspendBegin *) {1949static constexpr IrInstGenId ir_inst_id(IrInstGenAwait *) {
1534 return IrInstructionIdSuspendBegin;1950 return IrInstGenIdAwait;
1535}1951}
15361952
1537static constexpr IrInstructionId ir_instruction_id(IrInstructionSuspendFinish *) {1953static constexpr IrInstGenId ir_inst_id(IrInstGenResume *) {
1538 return IrInstructionIdSuspendFinish;1954 return IrInstGenIdResume;
1539}1955}
15401956
1541static constexpr IrInstructionId ir_instruction_id(IrInstructionAwaitSrc *) {1957static constexpr IrInstGenId ir_inst_id(IrInstGenSpillBegin *) {
1542 return IrInstructionIdAwaitSrc;1958 return IrInstGenIdSpillBegin;
1543}1959}
15441960
1545static constexpr IrInstructionId ir_instruction_id(IrInstructionAwaitGen *) {1961static constexpr IrInstGenId ir_inst_id(IrInstGenSpillEnd *) {
1546 return IrInstructionIdAwaitGen;1962 return IrInstGenIdSpillEnd;
1547}1963}
15481964
1549static constexpr IrInstructionId ir_instruction_id(IrInstructionResume *) {1965static constexpr IrInstGenId ir_inst_id(IrInstGenVectorExtractElem *) {
1550 return IrInstructionIdResume;1966 return IrInstGenIdVectorExtractElem;
1551}1967}
15521968
1553static constexpr IrInstructionId ir_instruction_id(IrInstructionSpillBegin *) {1969static constexpr IrInstGenId ir_inst_id(IrInstGenAlloca *) {
1554 return IrInstructionIdSpillBegin;1970 return IrInstGenIdAlloca;
1555}1971}
15561972
1557static constexpr IrInstructionId ir_instruction_id(IrInstructionSpillEnd *) {1973static constexpr IrInstGenId ir_inst_id(IrInstGenConst *) {
1558 return IrInstructionIdSpillEnd;1974 return IrInstGenIdConst;
1559}1975}
15601976
1561static constexpr IrInstructionId ir_instruction_id(IrInstructionVectorExtractElem *) {1977template<typename T>
1562 return IrInstructionIdVectorExtractElem;1978static T *ir_create_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
1979 const char *name = nullptr;
1980#ifdef ZIG_ENABLE_MEM_PROFILE
1981 T *dummy = nullptr;
1982 name = ir_inst_src_type_str(ir_inst_id(dummy));
1983#endif
1984 T *special_instruction = allocate<T>(1, name);
1985 special_instruction->base.id = ir_inst_id(special_instruction);
1986 special_instruction->base.base.scope = scope;
1987 special_instruction->base.base.source_node = source_node;
1988 special_instruction->base.base.debug_id = exec_next_debug_id(irb->exec);
1989 special_instruction->base.owner_bb = irb->current_basic_block;
1990 return special_instruction;
1563}1991}
15641992
1565template<typename T>1993template<typename T>
1566static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) {1994static T *ir_create_inst_gen(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
1567 const char *name = nullptr;1995 const char *name = nullptr;
1568#ifdef ZIG_ENABLE_MEM_PROFILE1996#ifdef ZIG_ENABLE_MEM_PROFILE
1569 T *dummy = nullptr;1997 T *dummy = nullptr;
1570 name = ir_instruction_type_str(ir_instruction_id(dummy));1998 name = ir_inst_gen_type_str(ir_inst_id(dummy));
1571#endif1999#endif
1572 T *special_instruction = allocate<T>(1, name);2000 T *special_instruction = allocate<T>(1, name);
1573 special_instruction->base.id = ir_instruction_id(special_instruction);2001 special_instruction->base.id = ir_inst_id(special_instruction);
1574 special_instruction->base.scope = scope;2002 special_instruction->base.base.scope = scope;
1575 special_instruction->base.source_node = source_node;2003 special_instruction->base.base.source_node = source_node;
1576 special_instruction->base.debug_id = exec_next_debug_id(irb->exec);2004 special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec);
1577 special_instruction->base.owner_bb = irb->current_basic_block;2005 special_instruction->base.owner_bb = irb->current_basic_block;
1578 special_instruction->base.value = allocate<ZigValue>(1, "ZigValue");2006 special_instruction->base.value = allocate<ZigValue>(1, "ZigValue");
1579 return special_instruction;2007 return special_instruction;
1580}2008}
15812009
1582template<typename T>2010template<typename T>
1583static T *ir_create_instruction_noval(IrBuilder *irb, Scope *scope, AstNode *source_node) {2011static T *ir_create_inst_noval(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
1584 const char *name = nullptr;2012 const char *name = nullptr;
1585#ifdef ZIG_ENABLE_MEM_PROFILE2013#ifdef ZIG_ENABLE_MEM_PROFILE
1586 T *dummy = nullptr;2014 T *dummy = nullptr;
1587 name = ir_instruction_type_str(ir_instruction_id(dummy));2015 name = ir_inst_gen_type_str(ir_inst_id(dummy));
1588#endif2016#endif
1589 T *special_instruction = allocate<T>(1, name);2017 T *special_instruction = allocate<T>(1, name);
1590 special_instruction->base.id = ir_instruction_id(special_instruction);2018 special_instruction->base.id = ir_inst_id(special_instruction);
1591 special_instruction->base.scope = scope;2019 special_instruction->base.base.scope = scope;
1592 special_instruction->base.source_node = source_node;2020 special_instruction->base.base.source_node = source_node;
1593 special_instruction->base.debug_id = exec_next_debug_id(irb->exec);2021 special_instruction->base.base.debug_id = exec_next_debug_id_gen(irb->exec);
1594 special_instruction->base.owner_bb = irb->current_basic_block;2022 special_instruction->base.owner_bb = irb->current_basic_block;
1595 return special_instruction;2023 return special_instruction;
1596}2024}
15972025
1598template<typename T>2026template<typename T>
1599static T *ir_build_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node) {2027static T *ir_build_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
1600 T *special_instruction = ir_create_instruction<T>(irb, scope, source_node);2028 T *special_instruction = ir_create_instruction<T>(irb, scope, source_node);
1601 ir_instruction_append(irb->current_basic_block, &special_instruction->base);2029 ir_instruction_append(irb->current_basic_block, &special_instruction->base);
1602 return special_instruction;2030 return special_instruction;
1603}2031}
16042032
1605static IrInstruction *ir_build_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *dest_type,2033template<typename T>
1606 IrInstruction *value, CastOp cast_op)2034static T *ir_build_inst_gen(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
2035 T *special_instruction = ir_create_inst_gen<T>(irb, scope, source_node);
2036 ir_inst_gen_append(irb->current_basic_block, &special_instruction->base);
2037 return special_instruction;
2038}
2039
2040template<typename T>
2041static T *ir_build_inst_noreturn(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
2042 T *special_instruction = ir_create_inst_noval<T>(irb, scope, source_node);
2043 special_instruction->base.value = irb->codegen->intern.for_unreachable();
2044 ir_inst_gen_append(irb->current_basic_block, &special_instruction->base);
2045 return special_instruction;
2046}
2047
2048template<typename T>
2049static T *ir_build_inst_void(IrBuilderGen *irb, Scope *scope, AstNode *source_node) {
2050 T *special_instruction = ir_create_inst_noval<T>(irb, scope, source_node);
2051 special_instruction->base.value = irb->codegen->intern.for_void();
2052 ir_inst_gen_append(irb->current_basic_block, &special_instruction->base);
2053 return special_instruction;
2054}
2055
2056IrInstGen *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigFn *fn,
2057 ZigType *var_type, const char *name_hint)
1607{2058{
1608 IrInstructionCast *cast_instruction = ir_build_instruction<IrInstructionCast>(irb, scope, source_node);2059 IrInstGenAlloca *alloca_gen = allocate<IrInstGenAlloca>(1);
1609 cast_instruction->dest_type = dest_type;2060 alloca_gen->base.id = IrInstGenIdAlloca;
1610 cast_instruction->value = value;2061 alloca_gen->base.base.source_node = source_node;
1611 cast_instruction->cast_op = cast_op;2062 alloca_gen->base.base.scope = scope;
2063 alloca_gen->base.value = allocate<ZigValue>(1, "ZigValue");
2064 alloca_gen->base.value->type = get_pointer_to_type(g, var_type, false);
2065 alloca_gen->base.base.ref_count = 1;
2066 alloca_gen->name_hint = name_hint;
2067 fn->alloca_gen_list.append(alloca_gen);
2068 return &alloca_gen->base;
2069}
16122070
1613 ir_ref_instruction(value, irb->current_basic_block);2071static IrInstGen *ir_build_cast(IrAnalyze *ira, IrInst *source_instr,ZigType *dest_type,
2072 IrInstGen *value, CastOp cast_op)
2073{
2074 IrInstGenCast *inst = ir_build_inst_gen<IrInstGenCast>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2075 inst->base.value->type = dest_type;
2076 inst->value = value;
2077 inst->cast_op = cast_op;
2078
2079 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
16142080
1615 return &cast_instruction->base;2081 return &inst->base;
1616}2082}
16172083
1618static IrInstruction *ir_build_cond_br(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *condition,2084static IrInstSrc *ir_build_cond_br(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *condition,
1619 IrBasicBlock *then_block, IrBasicBlock *else_block, IrInstruction *is_comptime)2085 IrBasicBlockSrc *then_block, IrBasicBlockSrc *else_block, IrInstSrc *is_comptime)
1620{2086{
1621 IrInstructionCondBr *cond_br_instruction = ir_build_instruction<IrInstructionCondBr>(irb, scope, source_node);2087 IrInstSrcCondBr *inst = ir_build_instruction<IrInstSrcCondBr>(irb, scope, source_node);
1622 cond_br_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;2088 inst->base.is_noreturn = true;
1623 cond_br_instruction->base.value->special = ConstValSpecialStatic;2089 inst->condition = condition;
1624 cond_br_instruction->condition = condition;2090 inst->then_block = then_block;
1625 cond_br_instruction->then_block = then_block;2091 inst->else_block = else_block;
1626 cond_br_instruction->else_block = else_block;2092 inst->is_comptime = is_comptime;
1627 cond_br_instruction->is_comptime = is_comptime;
16282093
1629 ir_ref_instruction(condition, irb->current_basic_block);2094 ir_ref_instruction(condition, irb->current_basic_block);
1630 ir_ref_bb(then_block);2095 ir_ref_bb(then_block);
1631 ir_ref_bb(else_block);2096 ir_ref_bb(else_block);
1632 if (is_comptime != nullptr) ir_ref_instruction(is_comptime, irb->current_basic_block);2097 if (is_comptime != nullptr) ir_ref_instruction(is_comptime, irb->current_basic_block);
16332098
1634 return &cond_br_instruction->base;2099 return &inst->base;
1635}2100}
16362101
1637static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *source_node,2102static IrInstGen *ir_build_cond_br_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *condition,
1638 IrInstruction *operand)2103 IrBasicBlockGen *then_block, IrBasicBlockGen *else_block)
1639{2104{
1640 IrInstructionReturn *return_instruction = ir_build_instruction<IrInstructionReturn>(irb, scope, source_node);2105 IrInstGenCondBr *inst = ir_build_inst_noreturn<IrInstGenCondBr>(&ira->new_irb, source_instr->scope, source_instr->source_node);
1641 return_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;2106 inst->condition = condition;
1642 return_instruction->base.value->special = ConstValSpecialStatic;2107 inst->then_block = then_block;
1643 return_instruction->operand = operand;2108 inst->else_block = else_block;
2109
2110 ir_ref_inst_gen(condition, ira->new_irb.current_basic_block);
2111 ir_ref_bb_gen(then_block);
2112 ir_ref_bb_gen(else_block);
2113
2114 return &inst->base;
2115}
2116
2117static IrInstSrc *ir_build_return_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *operand) {
2118 IrInstSrcReturn *inst = ir_build_instruction<IrInstSrcReturn>(irb, scope, source_node);
2119 inst->base.is_noreturn = true;
2120 inst->operand = operand;
16442121
1645 if (operand != nullptr) ir_ref_instruction(operand, irb->current_basic_block);2122 if (operand != nullptr) ir_ref_instruction(operand, irb->current_basic_block);
16462123
1647 return &return_instruction->base;2124 return &inst->base;
2125}
2126
2127static IrInstGen *ir_build_return_gen(IrAnalyze *ira, IrInst *source_inst, IrInstGen *operand) {
2128 IrInstGenReturn *inst = ir_build_inst_noreturn<IrInstGenReturn>(&ira->new_irb,
2129 source_inst->scope, source_inst->source_node);
2130 inst->operand = operand;
2131
2132 if (operand != nullptr) ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2133
2134 return &inst->base;
1648}2135}
16492136
1650static IrInstruction *ir_build_const_void(IrBuilder *irb, Scope *scope, AstNode *source_node) {2137static IrInstSrc *ir_build_const_void(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
1651 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node);2138 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
1652 ir_instruction_append(irb->current_basic_block, &const_instruction->base);2139 ir_instruction_append(irb->current_basic_block, &const_instruction->base);
1653 const_instruction->base.value = irb->codegen->intern.for_void();2140 const_instruction->value = irb->codegen->intern.for_void();
1654 return &const_instruction->base;2141 return &const_instruction->base;
1655}2142}
16562143
1657static IrInstruction *ir_build_const_undefined(IrBuilder *irb, Scope *scope, AstNode *source_node) {2144static IrInstSrc *ir_build_const_undefined(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
1658 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node);2145 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
1659 ir_instruction_append(irb->current_basic_block, &const_instruction->base);2146 ir_instruction_append(irb->current_basic_block, &const_instruction->base);
1660 const_instruction->base.value = irb->codegen->intern.for_undefined();2147 const_instruction->value = irb->codegen->intern.for_undefined();
1661 return &const_instruction->base;2148 return &const_instruction->base;
1662}2149}
16632150
1664static IrInstruction *ir_build_const_uint(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) {2151static IrInstSrc *ir_build_const_uint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) {
1665 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);2152 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
1666 const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_int;2153 const_instruction->value = create_const_vals(1);
1667 const_instruction->base.value->special = ConstValSpecialStatic;2154 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int;
1668 bigint_init_unsigned(&const_instruction->base.value->data.x_bigint, value);2155 const_instruction->value->special = ConstValSpecialStatic;
2156 bigint_init_unsigned(&const_instruction->value->data.x_bigint, value);
1669 return &const_instruction->base;2157 return &const_instruction->base;
1670}2158}
16712159
1672static IrInstruction *ir_build_const_bigint(IrBuilder *irb, Scope *scope, AstNode *source_node, BigInt *bigint) {2160static IrInstSrc *ir_build_const_bigint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, BigInt *bigint) {
1673 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);2161 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
1674 const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_int;2162 const_instruction->value = create_const_vals(1);
1675 const_instruction->base.value->special = ConstValSpecialStatic;2163 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_int;
1676 bigint_init_bigint(&const_instruction->base.value->data.x_bigint, bigint);2164 const_instruction->value->special = ConstValSpecialStatic;
2165 bigint_init_bigint(&const_instruction->value->data.x_bigint, bigint);
1677 return &const_instruction->base;2166 return &const_instruction->base;
1678}2167}
16792168
1680static IrInstruction *ir_build_const_bigfloat(IrBuilder *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) {2169static IrInstSrc *ir_build_const_bigfloat(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) {
1681 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);2170 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
1682 const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_float;2171 const_instruction->value = create_const_vals(1);
1683 const_instruction->base.value->special = ConstValSpecialStatic;2172 const_instruction->value->type = irb->codegen->builtin_types.entry_num_lit_float;
1684 bigfloat_init_bigfloat(&const_instruction->base.value->data.x_bigfloat, bigfloat);2173 const_instruction->value->special = ConstValSpecialStatic;
2174 bigfloat_init_bigfloat(&const_instruction->value->data.x_bigfloat, bigfloat);
1685 return &const_instruction->base;2175 return &const_instruction->base;
1686}2176}
16872177
1688static IrInstruction *ir_build_const_null(IrBuilder *irb, Scope *scope, AstNode *source_node) {2178static IrInstSrc *ir_build_const_null(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
1689 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node);2179 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
1690 ir_instruction_append(irb->current_basic_block, &const_instruction->base);2180 ir_instruction_append(irb->current_basic_block, &const_instruction->base);
1691 const_instruction->base.value = irb->codegen->intern.for_null();2181 const_instruction->value = irb->codegen->intern.for_null();
1692 return &const_instruction->base;2182 return &const_instruction->base;
1693}2183}
16942184
1695static IrInstruction *ir_build_const_usize(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) {2185static IrInstSrc *ir_build_const_usize(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, uint64_t value) {
1696 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);2186 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
1697 const_instruction->base.value->type = irb->codegen->builtin_types.entry_usize;2187 const_instruction->value = create_const_vals(1);
1698 const_instruction->base.value->special = ConstValSpecialStatic;2188 const_instruction->value->type = irb->codegen->builtin_types.entry_usize;
1699 bigint_init_unsigned(&const_instruction->base.value->data.x_bigint, value);2189 const_instruction->value->special = ConstValSpecialStatic;
2190 bigint_init_unsigned(&const_instruction->value->data.x_bigint, value);
1700 return &const_instruction->base;2191 return &const_instruction->base;
1701}2192}
17022193
1703static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,2194static IrInstSrc *ir_create_const_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1704 ZigType *type_entry)2195 ZigType *type_entry)
1705{2196{
1706 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);2197 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
1707 const_instruction->base.value->type = irb->codegen->builtin_types.entry_type;2198 const_instruction->value = create_const_vals(1);
1708 const_instruction->base.value->special = ConstValSpecialStatic;2199 const_instruction->value->type = irb->codegen->builtin_types.entry_type;
1709 const_instruction->base.value->data.x_type = type_entry;2200 const_instruction->value->special = ConstValSpecialStatic;
2201 const_instruction->value->data.x_type = type_entry;
1710 return &const_instruction->base;2202 return &const_instruction->base;
1711}2203}
17122204
1713static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node,2205static IrInstSrc *ir_build_const_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1714 ZigType *type_entry)2206 ZigType *type_entry)
1715{2207{
1716 IrInstruction *instruction = ir_create_const_type(irb, scope, source_node, type_entry);2208 IrInstSrc *instruction = ir_create_const_type(irb, scope, source_node, type_entry);
1717 ir_instruction_append(irb->current_basic_block, instruction);2209 ir_instruction_append(irb->current_basic_block, instruction);
1718 return instruction;2210 return instruction;
1719}2211}
17202212
1721static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) {2213static IrInstSrc *ir_build_const_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigType *import) {
1722 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);2214 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
1723 const_instruction->base.value->type = fn_entry->type_entry;2215 const_instruction->value = create_const_vals(1);
1724 const_instruction->base.value->special = ConstValSpecialStatic;2216 const_instruction->value->type = irb->codegen->builtin_types.entry_type;
1725 const_instruction->base.value->data.x_ptr.data.fn.fn_entry = fn_entry;2217 const_instruction->value->special = ConstValSpecialStatic;
1726 const_instruction->base.value->data.x_ptr.mut = ConstPtrMutComptimeConst;2218 const_instruction->value->data.x_type = import;
1727 const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialFunction;
1728 return &const_instruction->base;
1729}
1730
1731static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *import) {
1732 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1733 const_instruction->base.value->type = irb->codegen->builtin_types.entry_type;
1734 const_instruction->base.value->special = ConstValSpecialStatic;
1735 const_instruction->base.value->data.x_type = import;
1736 return &const_instruction->base;
1737}
1738
1739static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode *source_node, bool value) {
1740 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);
1741 const_instruction->base.value->type = irb->codegen->builtin_types.entry_bool;
1742 const_instruction->base.value->special = ConstValSpecialStatic;
1743 const_instruction->base.value->data.x_bool = value;
1744 return &const_instruction->base;2219 return &const_instruction->base;
1745}2220}
17462221
1747static IrInstruction *ir_build_const_enum_literal(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *name) {2222static IrInstSrc *ir_build_const_bool(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, bool value) {
1748 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);2223 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
1749 const_instruction->base.value->type = irb->codegen->builtin_types.entry_enum_literal;2224 const_instruction->value = create_const_vals(1);
1750 const_instruction->base.value->special = ConstValSpecialStatic;2225 const_instruction->value->type = irb->codegen->builtin_types.entry_bool;
1751 const_instruction->base.value->data.x_enum_literal = name;2226 const_instruction->value->special = ConstValSpecialStatic;
2227 const_instruction->value->data.x_bool = value;
1752 return &const_instruction->base;2228 return &const_instruction->base;
1753}2229}
17542230
1755static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstNode *source_node,2231static IrInstSrc *ir_build_const_enum_literal(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *name) {
1756 ZigFn *fn_entry, IrInstruction *first_arg)2232 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, source_node);
1757{2233 const_instruction->value = create_const_vals(1);
1758 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node);2234 const_instruction->value->type = irb->codegen->builtin_types.entry_enum_literal;
1759 const_instruction->base.value->type = get_bound_fn_type(irb->codegen, fn_entry);2235 const_instruction->value->special = ConstValSpecialStatic;
1760 const_instruction->base.value->special = ConstValSpecialStatic;2236 const_instruction->value->data.x_enum_literal = name;
1761 const_instruction->base.value->data.x_bound_fn.fn = fn_entry;
1762 const_instruction->base.value->data.x_bound_fn.first_arg = first_arg;
1763 return &const_instruction->base;2237 return &const_instruction->base;
1764}2238}
17652239
1766static IrInstruction *ir_create_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) {2240static IrInstSrc *ir_create_const_str_lit(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *str) {
1767 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node);2241 IrInstSrcConst *const_instruction = ir_create_instruction<IrInstSrcConst>(irb, scope, source_node);
1768 init_const_str_lit(irb->codegen, const_instruction->base.value, str);2242 const_instruction->value = create_const_vals(1);
2243 init_const_str_lit(irb->codegen, const_instruction->value, str);
17692244
1770 return &const_instruction->base;2245 return &const_instruction->base;
1771}2246}
17722247
1773static IrInstruction *ir_build_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) {2248static IrInstSrc *ir_build_const_str_lit(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *str) {
1774 IrInstruction *instruction = ir_create_const_str_lit(irb, scope, source_node, str);2249 IrInstSrc *instruction = ir_create_const_str_lit(irb, scope, source_node, str);
1775 ir_instruction_append(irb->current_basic_block, instruction);2250 ir_instruction_append(irb->current_basic_block, instruction);
1776 return instruction;2251 return instruction;
1777}2252}
17782253
1779static IrInstruction *ir_build_bin_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrBinOp op_id,2254static IrInstSrc *ir_build_bin_op(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrBinOp op_id,
1780 IrInstruction *op1, IrInstruction *op2, bool safety_check_on)2255 IrInstSrc *op1, IrInstSrc *op2, bool safety_check_on)
1781{2256{
1782 IrInstructionBinOp *bin_op_instruction = ir_build_instruction<IrInstructionBinOp>(irb, scope, source_node);2257 IrInstSrcBinOp *inst = ir_build_instruction<IrInstSrcBinOp>(irb, scope, source_node);
1783 bin_op_instruction->op_id = op_id;2258 inst->op_id = op_id;
1784 bin_op_instruction->op1 = op1;2259 inst->op1 = op1;
1785 bin_op_instruction->op2 = op2;2260 inst->op2 = op2;
1786 bin_op_instruction->safety_check_on = safety_check_on;2261 inst->safety_check_on = safety_check_on;
17872262
1788 ir_ref_instruction(op1, irb->current_basic_block);2263 ir_ref_instruction(op1, irb->current_basic_block);
1789 ir_ref_instruction(op2, irb->current_basic_block);2264 ir_ref_instruction(op2, irb->current_basic_block);
17902265
1791 return &bin_op_instruction->base;2266 return &inst->base;
1792}2267}
17932268
1794static IrInstruction *ir_build_bin_op_gen(IrAnalyze *ira, IrInstruction *source_instr, ZigType *res_type,2269static IrInstGen *ir_build_bin_op_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *res_type,
1795 IrBinOp op_id, IrInstruction *op1, IrInstruction *op2, bool safety_check_on)2270 IrBinOp op_id, IrInstGen *op1, IrInstGen *op2, bool safety_check_on)
1796{2271{
1797 IrInstructionBinOp *bin_op_instruction = ir_build_instruction<IrInstructionBinOp>(&ira->new_irb,2272 IrInstGenBinOp *inst = ir_build_inst_gen<IrInstGenBinOp>(&ira->new_irb,
1798 source_instr->scope, source_instr->source_node);2273 source_instr->scope, source_instr->source_node);
1799 bin_op_instruction->base.value->type = res_type;2274 inst->base.value->type = res_type;
1800 bin_op_instruction->op_id = op_id;2275 inst->op_id = op_id;
1801 bin_op_instruction->op1 = op1;2276 inst->op1 = op1;
1802 bin_op_instruction->op2 = op2;2277 inst->op2 = op2;
1803 bin_op_instruction->safety_check_on = safety_check_on;2278 inst->safety_check_on = safety_check_on;
18042279
1805 ir_ref_instruction(op1, ira->new_irb.current_basic_block);2280 ir_ref_inst_gen(op1, ira->new_irb.current_basic_block);
1806 ir_ref_instruction(op2, ira->new_irb.current_basic_block);2281 ir_ref_inst_gen(op2, ira->new_irb.current_basic_block);
18072282
1808 return &bin_op_instruction->base;2283 return &inst->base;
1809}2284}
18102285
18112286
1812static IrInstruction *ir_build_merge_err_sets(IrBuilder *irb, Scope *scope, AstNode *source_node,2287static IrInstSrc *ir_build_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1813 IrInstruction *op1, IrInstruction *op2, Buf *type_name)2288 IrInstSrc *op1, IrInstSrc *op2, Buf *type_name)
1814{2289{
1815 IrInstructionMergeErrSets *merge_err_sets_instruction = ir_build_instruction<IrInstructionMergeErrSets>(irb, scope, source_node);2290 IrInstSrcMergeErrSets *inst = ir_build_instruction<IrInstSrcMergeErrSets>(irb, scope, source_node);
1816 merge_err_sets_instruction->op1 = op1;2291 inst->op1 = op1;
1817 merge_err_sets_instruction->op2 = op2;2292 inst->op2 = op2;
1818 merge_err_sets_instruction->type_name = type_name;2293 inst->type_name = type_name;
18192294
1820 ir_ref_instruction(op1, irb->current_basic_block);2295 ir_ref_instruction(op1, irb->current_basic_block);
1821 ir_ref_instruction(op2, irb->current_basic_block);2296 ir_ref_instruction(op2, irb->current_basic_block);
18222297
1823 return &merge_err_sets_instruction->base;2298 return &inst->base;
1824}2299}
18252300
1826static IrInstruction *ir_build_var_ptr_x(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var,2301static IrInstSrc *ir_build_var_ptr_x(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var,
1827 ScopeFnDef *crossed_fndef_scope)2302 ScopeFnDef *crossed_fndef_scope)
1828{2303{
1829 IrInstructionVarPtr *instruction = ir_build_instruction<IrInstructionVarPtr>(irb, scope, source_node);2304 IrInstSrcVarPtr *instruction = ir_build_instruction<IrInstSrcVarPtr>(irb, scope, source_node);
1830 instruction->var = var;2305 instruction->var = var;
1831 instruction->crossed_fndef_scope = crossed_fndef_scope;2306 instruction->crossed_fndef_scope = crossed_fndef_scope;
18322307
...@@ -1835,22 +2310,30 @@ static IrInstruction *ir_build_var_ptr_x(IrBuilder *irb, Scope *scope, AstNode *...@@ -1835,22 +2310,30 @@ static IrInstruction *ir_build_var_ptr_x(IrBuilder *irb, Scope *scope, AstNode *
1835 return &instruction->base;2310 return &instruction->base;
1836}2311}
18372312
1838static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var) {2313static IrInstSrc *ir_build_var_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var) {
1839 return ir_build_var_ptr_x(irb, scope, source_node, var, nullptr);2314 return ir_build_var_ptr_x(irb, scope, source_node, var, nullptr);
1840}2315}
18412316
1842static IrInstruction *ir_build_return_ptr(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {2317static IrInstGen *ir_build_var_ptr_gen(IrAnalyze *ira, IrInst *source_instr, ZigVar *var) {
1843 IrInstructionReturnPtr *instruction = ir_build_instruction<IrInstructionReturnPtr>(&ira->new_irb,2318 IrInstGenVarPtr *instruction = ir_build_inst_gen<IrInstGenVarPtr>(&ira->new_irb, source_instr->scope, source_instr->source_node);
1844 source_instruction->scope, source_instruction->source_node);2319 instruction->var = var;
2320
2321 ir_ref_var(var);
2322
2323 return &instruction->base;
2324}
2325
2326static IrInstGen *ir_build_return_ptr(IrAnalyze *ira, Scope *scope, AstNode *source_node, ZigType *ty) {
2327 IrInstGenReturnPtr *instruction = ir_build_inst_gen<IrInstGenReturnPtr>(&ira->new_irb, scope, source_node);
1845 instruction->base.value->type = ty;2328 instruction->base.value->type = ty;
1846 return &instruction->base;2329 return &instruction->base;
1847}2330}
18482331
1849static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,2332static IrInstSrc *ir_build_elem_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1850 IrInstruction *array_ptr, IrInstruction *elem_index, bool safety_check_on, PtrLen ptr_len,2333 IrInstSrc *array_ptr, IrInstSrc *elem_index, bool safety_check_on, PtrLen ptr_len,
1851 AstNode *init_array_type_source_node)2334 AstNode *init_array_type_source_node)
1852{2335{
1853 IrInstructionElemPtr *instruction = ir_build_instruction<IrInstructionElemPtr>(irb, scope, source_node);2336 IrInstSrcElemPtr *instruction = ir_build_instruction<IrInstSrcElemPtr>(irb, scope, source_node);
1854 instruction->array_ptr = array_ptr;2337 instruction->array_ptr = array_ptr;
1855 instruction->elem_index = elem_index;2338 instruction->elem_index = elem_index;
1856 instruction->safety_check_on = safety_check_on;2339 instruction->safety_check_on = safety_check_on;
...@@ -1863,10 +2346,25 @@ static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *s...@@ -1863,10 +2346,25 @@ static IrInstruction *ir_build_elem_ptr(IrBuilder *irb, Scope *scope, AstNode *s
1863 return &instruction->base;2346 return &instruction->base;
1864}2347}
18652348
1866static IrInstruction *ir_build_field_ptr_instruction(IrBuilder *irb, Scope *scope, AstNode *source_node,2349static IrInstGen *ir_build_elem_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
1867 IrInstruction *container_ptr, IrInstruction *field_name_expr, bool initializing)2350 IrInstGen *array_ptr, IrInstGen *elem_index, bool safety_check_on, ZigType *return_type)
2351{
2352 IrInstGenElemPtr *instruction = ir_build_inst_gen<IrInstGenElemPtr>(&ira->new_irb, scope, source_node);
2353 instruction->base.value->type = return_type;
2354 instruction->array_ptr = array_ptr;
2355 instruction->elem_index = elem_index;
2356 instruction->safety_check_on = safety_check_on;
2357
2358 ir_ref_inst_gen(array_ptr, ira->new_irb.current_basic_block);
2359 ir_ref_inst_gen(elem_index, ira->new_irb.current_basic_block);
2360
2361 return &instruction->base;
2362}
2363
2364static IrInstSrc *ir_build_field_ptr_instruction(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2365 IrInstSrc *container_ptr, IrInstSrc *field_name_expr, bool initializing)
1868{2366{
1869 IrInstructionFieldPtr *instruction = ir_build_instruction<IrInstructionFieldPtr>(irb, scope, source_node);2367 IrInstSrcFieldPtr *instruction = ir_build_instruction<IrInstSrcFieldPtr>(irb, scope, source_node);
1870 instruction->container_ptr = container_ptr;2368 instruction->container_ptr = container_ptr;
1871 instruction->field_name_buffer = nullptr;2369 instruction->field_name_buffer = nullptr;
1872 instruction->field_name_expr = field_name_expr;2370 instruction->field_name_expr = field_name_expr;
...@@ -1878,10 +2376,10 @@ static IrInstruction *ir_build_field_ptr_instruction(IrBuilder *irb, Scope *scop...@@ -1878,10 +2376,10 @@ static IrInstruction *ir_build_field_ptr_instruction(IrBuilder *irb, Scope *scop
1878 return &instruction->base;2376 return &instruction->base;
1879}2377}
18802378
1881static IrInstruction *ir_build_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,2379static IrInstSrc *ir_build_field_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1882 IrInstruction *container_ptr, Buf *field_name, bool initializing)2380 IrInstSrc *container_ptr, Buf *field_name, bool initializing)
1883{2381{
1884 IrInstructionFieldPtr *instruction = ir_build_instruction<IrInstructionFieldPtr>(irb, scope, source_node);2382 IrInstSrcFieldPtr *instruction = ir_build_instruction<IrInstSrcFieldPtr>(irb, scope, source_node);
1885 instruction->container_ptr = container_ptr;2383 instruction->container_ptr = container_ptr;
1886 instruction->field_name_buffer = field_name;2384 instruction->field_name_buffer = field_name;
1887 instruction->field_name_expr = nullptr;2385 instruction->field_name_expr = nullptr;
...@@ -1892,10 +2390,10 @@ static IrInstruction *ir_build_field_ptr(IrBuilder *irb, Scope *scope, AstNode *...@@ -1892,10 +2390,10 @@ static IrInstruction *ir_build_field_ptr(IrBuilder *irb, Scope *scope, AstNode *
1892 return &instruction->base;2390 return &instruction->base;
1893}2391}
18942392
1895static IrInstruction *ir_build_has_field(IrBuilder *irb, Scope *scope, AstNode *source_node,2393static IrInstSrc *ir_build_has_field(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1896 IrInstruction *container_type, IrInstruction *field_name)2394 IrInstSrc *container_type, IrInstSrc *field_name)
1897{2395{
1898 IrInstructionHasField *instruction = ir_build_instruction<IrInstructionHasField>(irb, scope, source_node);2396 IrInstSrcHasField *instruction = ir_build_instruction<IrInstSrcHasField>(irb, scope, source_node);
1899 instruction->container_type = container_type;2397 instruction->container_type = container_type;
1900 instruction->field_name = field_name;2398 instruction->field_name = field_name;
19012399
...@@ -1905,36 +2403,39 @@ static IrInstruction *ir_build_has_field(IrBuilder *irb, Scope *scope, AstNode *...@@ -1905,36 +2403,39 @@ static IrInstruction *ir_build_has_field(IrBuilder *irb, Scope *scope, AstNode *
1905 return &instruction->base;2403 return &instruction->base;
1906}2404}
19072405
1908static IrInstruction *ir_build_struct_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,2406static IrInstGen *ir_build_struct_field_ptr(IrAnalyze *ira, IrInst *source_instr,
1909 IrInstruction *struct_ptr, TypeStructField *field)2407 IrInstGen *struct_ptr, TypeStructField *field, ZigType *ptr_type)
1910{2408{
1911 IrInstructionStructFieldPtr *instruction = ir_build_instruction<IrInstructionStructFieldPtr>(irb, scope, source_node);2409 IrInstGenStructFieldPtr *inst = ir_build_inst_gen<IrInstGenStructFieldPtr>(&ira->new_irb, source_instr->scope, source_instr->source_node);
1912 instruction->struct_ptr = struct_ptr;2410 inst->base.value->type = ptr_type;
1913 instruction->field = field;2411 inst->struct_ptr = struct_ptr;
2412 inst->field = field;
19142413
1915 ir_ref_instruction(struct_ptr, irb->current_basic_block);2414 ir_ref_inst_gen(struct_ptr, ira->new_irb.current_basic_block);
19162415
1917 return &instruction->base;2416 return &inst->base;
1918}2417}
19192418
1920static IrInstruction *ir_build_union_field_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,2419static IrInstGen *ir_build_union_field_ptr(IrAnalyze *ira, IrInst *source_instr,
1921 IrInstruction *union_ptr, TypeUnionField *field, bool safety_check_on, bool initializing)2420 IrInstGen *union_ptr, TypeUnionField *field, bool safety_check_on, bool initializing, ZigType *ptr_type)
1922{2421{
1923 IrInstructionUnionFieldPtr *instruction = ir_build_instruction<IrInstructionUnionFieldPtr>(irb, scope, source_node);2422 IrInstGenUnionFieldPtr *inst = ir_build_inst_gen<IrInstGenUnionFieldPtr>(&ira->new_irb,
1924 instruction->initializing = initializing;2423 source_instr->scope, source_instr->source_node);
1925 instruction->safety_check_on = safety_check_on;2424 inst->base.value->type = ptr_type;
1926 instruction->union_ptr = union_ptr;2425 inst->initializing = initializing;
1927 instruction->field = field;2426 inst->safety_check_on = safety_check_on;
2427 inst->union_ptr = union_ptr;
2428 inst->field = field;
19282429
1929 ir_ref_instruction(union_ptr, irb->current_basic_block);2430 ir_ref_inst_gen(union_ptr, ira->new_irb.current_basic_block);
19302431
1931 return &instruction->base;2432 return &inst->base;
1932}2433}
19332434
1934static IrInstruction *ir_build_call_extra(IrBuilder *irb, Scope *scope, AstNode *source_node,2435static IrInstSrc *ir_build_call_extra(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1935 IrInstruction *options, IrInstruction *fn_ref, IrInstruction *args, ResultLoc *result_loc)2436 IrInstSrc *options, IrInstSrc *fn_ref, IrInstSrc *args, ResultLoc *result_loc)
1936{2437{
1937 IrInstructionCallExtra *call_instruction = ir_build_instruction<IrInstructionCallExtra>(irb, scope, source_node);2438 IrInstSrcCallExtra *call_instruction = ir_build_instruction<IrInstSrcCallExtra>(irb, scope, source_node);
1938 call_instruction->options = options;2439 call_instruction->options = options;
1939 call_instruction->fn_ref = fn_ref;2440 call_instruction->fn_ref = fn_ref;
1940 call_instruction->args = args;2441 call_instruction->args = args;
...@@ -1947,11 +2448,11 @@ static IrInstruction *ir_build_call_extra(IrBuilder *irb, Scope *scope, AstNode...@@ -1947,11 +2448,11 @@ static IrInstruction *ir_build_call_extra(IrBuilder *irb, Scope *scope, AstNode
1947 return &call_instruction->base;2448 return &call_instruction->base;
1948}2449}
19492450
1950static IrInstruction *ir_build_call_src_args(IrBuilder *irb, Scope *scope, AstNode *source_node,2451static IrInstSrc *ir_build_call_args(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1951 IrInstruction *options, IrInstruction *fn_ref, IrInstruction **args_ptr, size_t args_len,2452 IrInstSrc *options, IrInstSrc *fn_ref, IrInstSrc **args_ptr, size_t args_len,
1952 ResultLoc *result_loc)2453 ResultLoc *result_loc)
1953{2454{
1954 IrInstructionCallSrcArgs *call_instruction = ir_build_instruction<IrInstructionCallSrcArgs>(irb, scope, source_node);2455 IrInstSrcCallArgs *call_instruction = ir_build_instruction<IrInstSrcCallArgs>(irb, scope, source_node);
1955 call_instruction->options = options;2456 call_instruction->options = options;
1956 call_instruction->fn_ref = fn_ref;2457 call_instruction->fn_ref = fn_ref;
1957 call_instruction->args_ptr = args_ptr;2458 call_instruction->args_ptr = args_ptr;
...@@ -1966,12 +2467,12 @@ static IrInstruction *ir_build_call_src_args(IrBuilder *irb, Scope *scope, AstNo...@@ -1966,12 +2467,12 @@ static IrInstruction *ir_build_call_src_args(IrBuilder *irb, Scope *scope, AstNo
1966 return &call_instruction->base;2467 return &call_instruction->base;
1967}2468}
19682469
1969static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *source_node,2470static IrInstSrc *ir_build_call_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
1970 ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,2471 ZigFn *fn_entry, IrInstSrc *fn_ref, size_t arg_count, IrInstSrc **args,
1971 IrInstruction *ret_ptr, CallModifier modifier, bool is_async_call_builtin,2472 IrInstSrc *ret_ptr, CallModifier modifier, bool is_async_call_builtin,
1972 IrInstruction *new_stack, ResultLoc *result_loc)2473 IrInstSrc *new_stack, ResultLoc *result_loc)
1973{2474{
1974 IrInstructionCallSrc *call_instruction = ir_build_instruction<IrInstructionCallSrc>(irb, scope, source_node);2475 IrInstSrcCall *call_instruction = ir_build_instruction<IrInstSrcCall>(irb, scope, source_node);
1975 call_instruction->fn_entry = fn_entry;2476 call_instruction->fn_entry = fn_entry;
1976 call_instruction->fn_ref = fn_ref;2477 call_instruction->fn_ref = fn_ref;
1977 call_instruction->args = args;2478 call_instruction->args = args;
...@@ -1991,12 +2492,12 @@ static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *s...@@ -1991,12 +2492,12 @@ static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *s
1991 return &call_instruction->base;2492 return &call_instruction->base;
1992}2493}
19932494
1994static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *source_instruction,2495static IrInstGenCall *ir_build_call_gen(IrAnalyze *ira, IrInst *source_instruction,
1995 ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,2496 ZigFn *fn_entry, IrInstGen *fn_ref, size_t arg_count, IrInstGen **args,
1996 CallModifier modifier, IrInstruction *new_stack, bool is_async_call_builtin,2497 CallModifier modifier, IrInstGen *new_stack, bool is_async_call_builtin,
1997 IrInstruction *result_loc, ZigType *return_type)2498 IrInstGen *result_loc, ZigType *return_type)
1998{2499{
1999 IrInstructionCallGen *call_instruction = ir_build_instruction<IrInstructionCallGen>(&ira->new_irb,2500 IrInstGenCall *call_instruction = ir_build_inst_gen<IrInstGenCall>(&ira->new_irb,
2000 source_instruction->scope, source_instruction->source_node);2501 source_instruction->scope, source_instruction->source_node);
2001 call_instruction->base.value->type = return_type;2502 call_instruction->base.value->type = return_type;
2002 call_instruction->fn_entry = fn_entry;2503 call_instruction->fn_entry = fn_entry;
...@@ -2008,23 +2509,23 @@ static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *so...@@ -2008,23 +2509,23 @@ static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *so
2008 call_instruction->new_stack = new_stack;2509 call_instruction->new_stack = new_stack;
2009 call_instruction->result_loc = result_loc;2510 call_instruction->result_loc = result_loc;
20102511
2011 if (fn_ref != nullptr) ir_ref_instruction(fn_ref, ira->new_irb.current_basic_block);2512 if (fn_ref != nullptr) ir_ref_inst_gen(fn_ref, ira->new_irb.current_basic_block);
2012 for (size_t i = 0; i < arg_count; i += 1)2513 for (size_t i = 0; i < arg_count; i += 1)
2013 ir_ref_instruction(args[i], ira->new_irb.current_basic_block);2514 ir_ref_inst_gen(args[i], ira->new_irb.current_basic_block);
2014 if (new_stack != nullptr) ir_ref_instruction(new_stack, ira->new_irb.current_basic_block);2515 if (new_stack != nullptr) ir_ref_inst_gen(new_stack, ira->new_irb.current_basic_block);
2015 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);2516 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
20162517
2017 return call_instruction;2518 return call_instruction;
2018}2519}
20192520
2020static IrInstruction *ir_build_phi(IrBuilder *irb, Scope *scope, AstNode *source_node,2521static IrInstSrc *ir_build_phi(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2021 size_t incoming_count, IrBasicBlock **incoming_blocks, IrInstruction **incoming_values,2522 size_t incoming_count, IrBasicBlockSrc **incoming_blocks, IrInstSrc **incoming_values,
2022 ResultLocPeerParent *peer_parent)2523 ResultLocPeerParent *peer_parent)
2023{2524{
2024 assert(incoming_count != 0);2525 assert(incoming_count != 0);
2025 assert(incoming_count != SIZE_MAX);2526 assert(incoming_count != SIZE_MAX);
20262527
2027 IrInstructionPhi *phi_instruction = ir_build_instruction<IrInstructionPhi>(irb, scope, source_node);2528 IrInstSrcPhi *phi_instruction = ir_build_instruction<IrInstSrcPhi>(irb, scope, source_node);
2028 phi_instruction->incoming_count = incoming_count;2529 phi_instruction->incoming_count = incoming_count;
2029 phi_instruction->incoming_blocks = incoming_blocks;2530 phi_instruction->incoming_blocks = incoming_blocks;
2030 phi_instruction->incoming_values = incoming_values;2531 phi_instruction->incoming_values = incoming_values;
...@@ -2038,56 +2539,77 @@ static IrInstruction *ir_build_phi(IrBuilder *irb, Scope *scope, AstNode *source...@@ -2038,56 +2539,77 @@ static IrInstruction *ir_build_phi(IrBuilder *irb, Scope *scope, AstNode *source
2038 return &phi_instruction->base;2539 return &phi_instruction->base;
2039}2540}
20402541
2041static IrInstruction *ir_create_br(IrBuilder *irb, Scope *scope, AstNode *source_node,2542static IrInstGen *ir_build_phi_gen(IrAnalyze *ira, IrInst *source_instr, size_t incoming_count,
2042 IrBasicBlock *dest_block, IrInstruction *is_comptime)2543 IrBasicBlockGen **incoming_blocks, IrInstGen **incoming_values, ZigType *result_type)
2043{2544{
2044 IrInstructionBr *br_instruction = ir_create_instruction<IrInstructionBr>(irb, scope, source_node);2545 assert(incoming_count != 0);
2045 br_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;2546 assert(incoming_count != SIZE_MAX);
2046 br_instruction->base.value->special = ConstValSpecialStatic;
2047 br_instruction->dest_block = dest_block;
2048 br_instruction->is_comptime = is_comptime;
20492547
2050 ir_ref_bb(dest_block);2548 IrInstGenPhi *phi_instruction = ir_build_inst_gen<IrInstGenPhi>(&ira->new_irb,
2051 if (is_comptime) ir_ref_instruction(is_comptime, irb->current_basic_block);2549 source_instr->scope, source_instr->source_node);
2550 phi_instruction->base.value->type = result_type;
2551 phi_instruction->incoming_count = incoming_count;
2552 phi_instruction->incoming_blocks = incoming_blocks;
2553 phi_instruction->incoming_values = incoming_values;
20522554
2053 return &br_instruction->base;2555 for (size_t i = 0; i < incoming_count; i += 1) {
2054}2556 ir_ref_bb_gen(incoming_blocks[i]);
2557 ir_ref_inst_gen(incoming_values[i], ira->new_irb.current_basic_block);
2558 }
20552559
2056static IrInstruction *ir_build_br(IrBuilder *irb, Scope *scope, AstNode *source_node,2560 return &phi_instruction->base;
2057 IrBasicBlock *dest_block, IrInstruction *is_comptime)
2058{
2059 IrInstruction *instruction = ir_create_br(irb, scope, source_node, dest_block, is_comptime);
2060 ir_instruction_append(irb->current_basic_block, instruction);
2061 return instruction;
2062}2561}
20632562
2064static IrInstruction *ir_build_ptr_type(IrBuilder *irb, Scope *scope, AstNode *source_node,2563static IrInstSrc *ir_build_br(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2065 IrInstruction *child_type, bool is_const, bool is_volatile, PtrLen ptr_len,2564 IrBasicBlockSrc *dest_block, IrInstSrc *is_comptime)
2066 IrInstruction *sentinel, IrInstruction *align_value,
2067 uint32_t bit_offset_start, uint32_t host_int_bytes, bool is_allow_zero)
2068{2565{
2069 IrInstructionPtrType *ptr_type_of_instruction = ir_build_instruction<IrInstructionPtrType>(irb, scope, source_node);2566 IrInstSrcBr *inst = ir_build_instruction<IrInstSrcBr>(irb, scope, source_node);
2070 ptr_type_of_instruction->sentinel = sentinel;2567 inst->base.is_noreturn = true;
2071 ptr_type_of_instruction->align_value = align_value;2568 inst->dest_block = dest_block;
2072 ptr_type_of_instruction->child_type = child_type;2569 inst->is_comptime = is_comptime;
2073 ptr_type_of_instruction->is_const = is_const;
2074 ptr_type_of_instruction->is_volatile = is_volatile;
2075 ptr_type_of_instruction->ptr_len = ptr_len;
2076 ptr_type_of_instruction->bit_offset_start = bit_offset_start;
2077 ptr_type_of_instruction->host_int_bytes = host_int_bytes;
2078 ptr_type_of_instruction->is_allow_zero = is_allow_zero;
20792570
2080 if (sentinel) ir_ref_instruction(sentinel, irb->current_basic_block);2571 ir_ref_bb(dest_block);
2081 if (align_value) ir_ref_instruction(align_value, irb->current_basic_block);2572 if (is_comptime) ir_ref_instruction(is_comptime, irb->current_basic_block);
2082 ir_ref_instruction(child_type, irb->current_basic_block);2573
2574 return &inst->base;
2575}
2576
2577static IrInstGen *ir_build_br_gen(IrAnalyze *ira, IrInst *source_instr, IrBasicBlockGen *dest_block) {
2578 IrInstGenBr *inst = ir_build_inst_noreturn<IrInstGenBr>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2579 inst->dest_block = dest_block;
2580
2581 ir_ref_bb_gen(dest_block);
2582
2583 return &inst->base;
2584}
2585
2586static IrInstSrc *ir_build_ptr_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2587 IrInstSrc *child_type, bool is_const, bool is_volatile, PtrLen ptr_len,
2588 IrInstSrc *sentinel, IrInstSrc *align_value,
2589 uint32_t bit_offset_start, uint32_t host_int_bytes, bool is_allow_zero)
2590{
2591 IrInstSrcPtrType *inst = ir_build_instruction<IrInstSrcPtrType>(irb, scope, source_node);
2592 inst->sentinel = sentinel;
2593 inst->align_value = align_value;
2594 inst->child_type = child_type;
2595 inst->is_const = is_const;
2596 inst->is_volatile = is_volatile;
2597 inst->ptr_len = ptr_len;
2598 inst->bit_offset_start = bit_offset_start;
2599 inst->host_int_bytes = host_int_bytes;
2600 inst->is_allow_zero = is_allow_zero;
20832601
2084 return &ptr_type_of_instruction->base;2602 if (sentinel) ir_ref_instruction(sentinel, irb->current_basic_block);
2603 if (align_value) ir_ref_instruction(align_value, irb->current_basic_block);
2604 ir_ref_instruction(child_type, irb->current_basic_block);
2605
2606 return &inst->base;
2085}2607}
20862608
2087static IrInstruction *ir_build_un_op_lval(IrBuilder *irb, Scope *scope, AstNode *source_node, IrUnOp op_id,2609static IrInstSrc *ir_build_un_op_lval(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrUnOp op_id,
2088 IrInstruction *value, LVal lval, ResultLoc *result_loc)2610 IrInstSrc *value, LVal lval, ResultLoc *result_loc)
2089{2611{
2090 IrInstructionUnOp *instruction = ir_build_instruction<IrInstructionUnOp>(irb, scope, source_node);2612 IrInstSrcUnOp *instruction = ir_build_instruction<IrInstSrcUnOp>(irb, scope, source_node);
2091 instruction->op_id = op_id;2613 instruction->op_id = op_id;
2092 instruction->value = value;2614 instruction->value = value;
2093 instruction->lval = lval;2615 instruction->lval = lval;
...@@ -2098,18 +2620,55 @@ static IrInstruction *ir_build_un_op_lval(IrBuilder *irb, Scope *scope, AstNode...@@ -2098,18 +2620,55 @@ static IrInstruction *ir_build_un_op_lval(IrBuilder *irb, Scope *scope, AstNode
2098 return &instruction->base;2620 return &instruction->base;
2099}2621}
21002622
2101static IrInstruction *ir_build_un_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrUnOp op_id,2623static IrInstSrc *ir_build_un_op(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrUnOp op_id,
2102 IrInstruction *value)2624 IrInstSrc *value)
2103{2625{
2104 return ir_build_un_op_lval(irb, scope, source_node, op_id, value, LValNone, nullptr);2626 return ir_build_un_op_lval(irb, scope, source_node, op_id, value, LValNone, nullptr);
2105}2627}
21062628
2107static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope, AstNode *source_node,2629static IrInstGen *ir_build_negation(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand, ZigType *expr_type) {
2108 size_t item_count, IrInstruction **elem_result_loc_list, IrInstruction *result_loc,2630 IrInstGenNegation *instruction = ir_build_inst_gen<IrInstGenNegation>(&ira->new_irb,
2631 source_instr->scope, source_instr->source_node);
2632 instruction->base.value->type = expr_type;
2633 instruction->operand = operand;
2634
2635 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2636
2637 return &instruction->base;
2638}
2639
2640static IrInstGen *ir_build_negation_wrapping(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand,
2641 ZigType *expr_type)
2642{
2643 IrInstGenNegationWrapping *instruction = ir_build_inst_gen<IrInstGenNegationWrapping>(&ira->new_irb,
2644 source_instr->scope, source_instr->source_node);
2645 instruction->base.value->type = expr_type;
2646 instruction->operand = operand;
2647
2648 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2649
2650 return &instruction->base;
2651}
2652
2653static IrInstGen *ir_build_binary_not(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand,
2654 ZigType *expr_type)
2655{
2656 IrInstGenBinaryNot *instruction = ir_build_inst_gen<IrInstGenBinaryNot>(&ira->new_irb,
2657 source_instr->scope, source_instr->source_node);
2658 instruction->base.value->type = expr_type;
2659 instruction->operand = operand;
2660
2661 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2662
2663 return &instruction->base;
2664}
2665
2666static IrInstSrc *ir_build_container_init_list(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2667 size_t item_count, IrInstSrc **elem_result_loc_list, IrInstSrc *result_loc,
2109 AstNode *init_array_type_source_node)2668 AstNode *init_array_type_source_node)
2110{2669{
2111 IrInstructionContainerInitList *container_init_list_instruction =2670 IrInstSrcContainerInitList *container_init_list_instruction =
2112 ir_build_instruction<IrInstructionContainerInitList>(irb, scope, source_node);2671 ir_build_instruction<IrInstSrcContainerInitList>(irb, scope, source_node);
2113 container_init_list_instruction->item_count = item_count;2672 container_init_list_instruction->item_count = item_count;
2114 container_init_list_instruction->elem_result_loc_list = elem_result_loc_list;2673 container_init_list_instruction->elem_result_loc_list = elem_result_loc_list;
2115 container_init_list_instruction->result_loc = result_loc;2674 container_init_list_instruction->result_loc = result_loc;
...@@ -2123,11 +2682,11 @@ static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope,...@@ -2123,11 +2682,11 @@ static IrInstruction *ir_build_container_init_list(IrBuilder *irb, Scope *scope,
2123 return &container_init_list_instruction->base;2682 return &container_init_list_instruction->base;
2124}2683}
21252684
2126static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scope, AstNode *source_node,2685static IrInstSrc *ir_build_container_init_fields(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2127 size_t field_count, IrInstructionContainerInitFieldsField *fields, IrInstruction *result_loc)2686 size_t field_count, IrInstSrcContainerInitFieldsField *fields, IrInstSrc *result_loc)
2128{2687{
2129 IrInstructionContainerInitFields *container_init_fields_instruction =2688 IrInstSrcContainerInitFields *container_init_fields_instruction =
2130 ir_build_instruction<IrInstructionContainerInitFields>(irb, scope, source_node);2689 ir_build_instruction<IrInstSrcContainerInitFields>(irb, scope, source_node);
2131 container_init_fields_instruction->field_count = field_count;2690 container_init_fields_instruction->field_count = field_count;
2132 container_init_fields_instruction->fields = fields;2691 container_init_fields_instruction->fields = fields;
2133 container_init_fields_instruction->result_loc = result_loc;2692 container_init_fields_instruction->result_loc = result_loc;
...@@ -2140,20 +2699,21 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop...@@ -2140,20 +2699,21 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop
2140 return &container_init_fields_instruction->base;2699 return &container_init_fields_instruction->base;
2141}2700}
21422701
2143static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node) {2702static IrInstSrc *ir_build_unreachable(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
2144 IrInstructionUnreachable *unreachable_instruction =2703 IrInstSrcUnreachable *inst = ir_build_instruction<IrInstSrcUnreachable>(irb, scope, source_node);
2145 ir_build_instruction<IrInstructionUnreachable>(irb, scope, source_node);2704 inst->base.is_noreturn = true;
2146 unreachable_instruction->base.value->special = ConstValSpecialStatic;2705 return &inst->base;
2147 unreachable_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
2148 return &unreachable_instruction->base;
2149}2706}
21502707
2151static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,2708static IrInstGen *ir_build_unreachable_gen(IrAnalyze *ira, IrInst *source_instr) {
2152 IrInstruction *ptr, IrInstruction *value)2709 IrInstGenUnreachable *inst = ir_build_inst_noreturn<IrInstGenUnreachable>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2710 return &inst->base;
2711}
2712
2713static IrInstSrcStorePtr *ir_build_store_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2714 IrInstSrc *ptr, IrInstSrc *value)
2153{2715{
2154 IrInstructionStorePtr *instruction = ir_build_instruction<IrInstructionStorePtr>(irb, scope, source_node);2716 IrInstSrcStorePtr *instruction = ir_build_instruction<IrInstSrcStorePtr>(irb, scope, source_node);
2155 instruction->base.value->special = ConstValSpecialStatic;
2156 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
2157 instruction->ptr = ptr;2717 instruction->ptr = ptr;
2158 instruction->value = value;2718 instruction->value = value;
21592719
...@@ -2163,76 +2723,83 @@ static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, A...@@ -2163,76 +2723,83 @@ static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, A
2163 return instruction;2723 return instruction;
2164}2724}
21652725
2166static IrInstruction *ir_build_vector_store_elem(IrAnalyze *ira, IrInstruction *source_instruction,2726static IrInstGen *ir_build_store_ptr_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *ptr, IrInstGen *value) {
2167 IrInstruction *vector_ptr, IrInstruction *index, IrInstruction *value)2727 IrInstGenStorePtr *instruction = ir_build_inst_void<IrInstGenStorePtr>(&ira->new_irb,
2728 source_instr->scope, source_instr->source_node);
2729 instruction->ptr = ptr;
2730 instruction->value = value;
2731
2732 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
2733 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
2734
2735 return &instruction->base;
2736}
2737
2738static IrInstGen *ir_build_vector_store_elem(IrAnalyze *ira, IrInst *src_inst,
2739 IrInstGen *vector_ptr, IrInstGen *index, IrInstGen *value)
2168{2740{
2169 IrInstructionVectorStoreElem *inst = ir_build_instruction<IrInstructionVectorStoreElem>(2741 IrInstGenVectorStoreElem *inst = ir_build_inst_void<IrInstGenVectorStoreElem>(
2170 &ira->new_irb, source_instruction->scope, source_instruction->source_node);2742 &ira->new_irb, src_inst->scope, src_inst->source_node);
2171 inst->base.value->type = ira->codegen->builtin_types.entry_void;
2172 inst->vector_ptr = vector_ptr;2743 inst->vector_ptr = vector_ptr;
2173 inst->index = index;2744 inst->index = index;
2174 inst->value = value;2745 inst->value = value;
21752746
2176 ir_ref_instruction(vector_ptr, ira->new_irb.current_basic_block);2747 ir_ref_inst_gen(vector_ptr, ira->new_irb.current_basic_block);
2177 ir_ref_instruction(index, ira->new_irb.current_basic_block);2748 ir_ref_inst_gen(index, ira->new_irb.current_basic_block);
2178 ir_ref_instruction(value, ira->new_irb.current_basic_block);2749 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
21792750
2180 return &inst->base;2751 return &inst->base;
2181}2752}
21822753
2183static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNode *source_node,2754static IrInstSrc *ir_build_var_decl_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2184 ZigVar *var, IrInstruction *align_value, IrInstruction *ptr)2755 ZigVar *var, IrInstSrc *align_value, IrInstSrc *ptr)
2185{2756{
2186 IrInstructionDeclVarSrc *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarSrc>(irb, scope, source_node);2757 IrInstSrcDeclVar *inst = ir_build_instruction<IrInstSrcDeclVar>(irb, scope, source_node);
2187 decl_var_instruction->base.value->special = ConstValSpecialStatic;2758 inst->var = var;
2188 decl_var_instruction->base.value->type = irb->codegen->builtin_types.entry_void;2759 inst->align_value = align_value;
2189 decl_var_instruction->var = var;2760 inst->ptr = ptr;
2190 decl_var_instruction->align_value = align_value;
2191 decl_var_instruction->ptr = ptr;
21922761
2193 if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block);2762 if (align_value != nullptr) ir_ref_instruction(align_value, irb->current_basic_block);
2194 ir_ref_instruction(ptr, irb->current_basic_block);2763 ir_ref_instruction(ptr, irb->current_basic_block);
21952764
2196 return &decl_var_instruction->base;2765 return &inst->base;
2197}2766}
21982767
2199static IrInstruction *ir_build_var_decl_gen(IrAnalyze *ira, IrInstruction *source_instruction,2768static IrInstGen *ir_build_var_decl_gen(IrAnalyze *ira, IrInst *source_instruction,
2200 ZigVar *var, IrInstruction *var_ptr)2769 ZigVar *var, IrInstGen *var_ptr)
2201{2770{
2202 IrInstructionDeclVarGen *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarGen>(&ira->new_irb,2771 IrInstGenDeclVar *inst = ir_build_inst_gen<IrInstGenDeclVar>(&ira->new_irb,
2203 source_instruction->scope, source_instruction->source_node);2772 source_instruction->scope, source_instruction->source_node);
2204 decl_var_instruction->base.value->special = ConstValSpecialStatic;2773 inst->base.value->special = ConstValSpecialStatic;
2205 decl_var_instruction->base.value->type = ira->codegen->builtin_types.entry_void;2774 inst->base.value->type = ira->codegen->builtin_types.entry_void;
2206 decl_var_instruction->var = var;2775 inst->var = var;
2207 decl_var_instruction->var_ptr = var_ptr;2776 inst->var_ptr = var_ptr;
22082777
2209 ir_ref_instruction(var_ptr, ira->new_irb.current_basic_block);2778 ir_ref_inst_gen(var_ptr, ira->new_irb.current_basic_block);
22102779
2211 return &decl_var_instruction->base;2780 return &inst->base;
2212}2781}
22132782
2214static IrInstruction *ir_build_resize_slice(IrAnalyze *ira, IrInstruction *source_instruction,2783static IrInstGen *ir_build_resize_slice(IrAnalyze *ira, IrInst *source_instruction,
2215 IrInstruction *operand, ZigType *ty, IrInstruction *result_loc)2784 IrInstGen *operand, ZigType *ty, IrInstGen *result_loc)
2216{2785{
2217 IrInstructionResizeSlice *instruction = ir_build_instruction<IrInstructionResizeSlice>(&ira->new_irb,2786 IrInstGenResizeSlice *instruction = ir_build_inst_gen<IrInstGenResizeSlice>(&ira->new_irb,
2218 source_instruction->scope, source_instruction->source_node);2787 source_instruction->scope, source_instruction->source_node);
2219 instruction->base.value->type = ty;2788 instruction->base.value->type = ty;
2220 instruction->operand = operand;2789 instruction->operand = operand;
2221 instruction->result_loc = result_loc;2790 instruction->result_loc = result_loc;
22222791
2223 ir_ref_instruction(operand, ira->new_irb.current_basic_block);2792 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2224 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);2793 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
22252794
2226 return &instruction->base;2795 return &instruction->base;
2227}2796}
22282797
2229static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *source_node,2798static IrInstSrc *ir_build_export(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2230 IrInstruction *target, IrInstruction *options)2799 IrInstSrc *target, IrInstSrc *options)
2231{2800{
2232 IrInstructionExport *export_instruction = ir_build_instruction<IrInstructionExport>(2801 IrInstSrcExport *export_instruction = ir_build_instruction<IrInstSrcExport>(
2233 irb, scope, source_node);2802 irb, scope, source_node);
2234 export_instruction->base.value->special = ConstValSpecialStatic;
2235 export_instruction->base.value->type = irb->codegen->builtin_types.entry_void;
2236 export_instruction->target = target;2803 export_instruction->target = target;
2237 export_instruction->options = options;2804 export_instruction->options = options;
22382805
...@@ -2242,8 +2809,8 @@ static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *sou...@@ -2242,8 +2809,8 @@ static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *sou
2242 return &export_instruction->base;2809 return &export_instruction->base;
2243}2810}
22442811
2245static IrInstruction *ir_build_load_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *ptr) {2812static IrInstSrc *ir_build_load_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *ptr) {
2246 IrInstructionLoadPtr *instruction = ir_build_instruction<IrInstructionLoadPtr>(irb, scope, source_node);2813 IrInstSrcLoadPtr *instruction = ir_build_instruction<IrInstSrcLoadPtr>(irb, scope, source_node);
2247 instruction->ptr = ptr;2814 instruction->ptr = ptr;
22482815
2249 ir_ref_instruction(ptr, irb->current_basic_block);2816 ir_ref_instruction(ptr, irb->current_basic_block);
...@@ -2251,8 +2818,23 @@ static IrInstruction *ir_build_load_ptr(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2251,8 +2818,23 @@ static IrInstruction *ir_build_load_ptr(IrBuilder *irb, Scope *scope, AstNode *s
2251 return &instruction->base;2818 return &instruction->base;
2252}2819}
22532820
2254static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {2821static IrInstGen *ir_build_load_ptr_gen(IrAnalyze *ira, IrInst *source_instruction,
2255 IrInstructionTypeOf *instruction = ir_build_instruction<IrInstructionTypeOf>(irb, scope, source_node);2822 IrInstGen *ptr, ZigType *ty, IrInstGen *result_loc)
2823{
2824 IrInstGenLoadPtr *instruction = ir_build_inst_gen<IrInstGenLoadPtr>(
2825 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2826 instruction->base.value->type = ty;
2827 instruction->ptr = ptr;
2828 instruction->result_loc = result_loc;
2829
2830 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
2831 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
2832
2833 return &instruction->base;
2834}
2835
2836static IrInstSrc *ir_build_typeof(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) {
2837 IrInstSrcTypeOf *instruction = ir_build_instruction<IrInstSrcTypeOf>(irb, scope, source_node);
2256 instruction->value = value;2838 instruction->value = value;
22572839
2258 ir_ref_instruction(value, irb->current_basic_block);2840 ir_ref_instruction(value, irb->current_basic_block);
...@@ -2260,8 +2842,8 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *sou...@@ -2260,8 +2842,8 @@ static IrInstruction *ir_build_typeof(IrBuilder *irb, Scope *scope, AstNode *sou
2260 return &instruction->base;2842 return &instruction->base;
2261}2843}
22622844
2263static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *is_cold) {2845static IrInstSrc *ir_build_set_cold(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *is_cold) {
2264 IrInstructionSetCold *instruction = ir_build_instruction<IrInstructionSetCold>(irb, scope, source_node);2846 IrInstSrcSetCold *instruction = ir_build_instruction<IrInstSrcSetCold>(irb, scope, source_node);
2265 instruction->is_cold = is_cold;2847 instruction->is_cold = is_cold;
22662848
2267 ir_ref_instruction(is_cold, irb->current_basic_block);2849 ir_ref_instruction(is_cold, irb->current_basic_block);
...@@ -2269,21 +2851,21 @@ static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2269,21 +2851,21 @@ static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *s
2269 return &instruction->base;2851 return &instruction->base;
2270}2852}
22712853
2272static IrInstruction *ir_build_set_runtime_safety(IrBuilder *irb, Scope *scope, AstNode *source_node,2854static IrInstSrc *ir_build_set_runtime_safety(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2273 IrInstruction *safety_on)2855 IrInstSrc *safety_on)
2274{2856{
2275 IrInstructionSetRuntimeSafety *instruction = ir_build_instruction<IrInstructionSetRuntimeSafety>(irb, scope, source_node);2857 IrInstSrcSetRuntimeSafety *inst = ir_build_instruction<IrInstSrcSetRuntimeSafety>(irb, scope, source_node);
2276 instruction->safety_on = safety_on;2858 inst->safety_on = safety_on;
22772859
2278 ir_ref_instruction(safety_on, irb->current_basic_block);2860 ir_ref_instruction(safety_on, irb->current_basic_block);
22792861
2280 return &instruction->base;2862 return &inst->base;
2281}2863}
22822864
2283static IrInstruction *ir_build_set_float_mode(IrBuilder *irb, Scope *scope, AstNode *source_node,2865static IrInstSrc *ir_build_set_float_mode(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2284 IrInstruction *mode_value)2866 IrInstSrc *mode_value)
2285{2867{
2286 IrInstructionSetFloatMode *instruction = ir_build_instruction<IrInstructionSetFloatMode>(irb, scope, source_node);2868 IrInstSrcSetFloatMode *instruction = ir_build_instruction<IrInstSrcSetFloatMode>(irb, scope, source_node);
2287 instruction->mode_value = mode_value;2869 instruction->mode_value = mode_value;
22882870
2289 ir_ref_instruction(mode_value, irb->current_basic_block);2871 ir_ref_instruction(mode_value, irb->current_basic_block);
...@@ -2291,10 +2873,10 @@ static IrInstruction *ir_build_set_float_mode(IrBuilder *irb, Scope *scope, AstN...@@ -2291,10 +2873,10 @@ static IrInstruction *ir_build_set_float_mode(IrBuilder *irb, Scope *scope, AstN
2291 return &instruction->base;2873 return &instruction->base;
2292}2874}
22932875
2294static IrInstruction *ir_build_array_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *size,2876static IrInstSrc *ir_build_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *size,
2295 IrInstruction *sentinel, IrInstruction *child_type)2877 IrInstSrc *sentinel, IrInstSrc *child_type)
2296{2878{
2297 IrInstructionArrayType *instruction = ir_build_instruction<IrInstructionArrayType>(irb, scope, source_node);2879 IrInstSrcArrayType *instruction = ir_build_instruction<IrInstSrcArrayType>(irb, scope, source_node);
2298 instruction->size = size;2880 instruction->size = size;
2299 instruction->sentinel = sentinel;2881 instruction->sentinel = sentinel;
2300 instruction->child_type = child_type;2882 instruction->child_type = child_type;
...@@ -2306,10 +2888,10 @@ static IrInstruction *ir_build_array_type(IrBuilder *irb, Scope *scope, AstNode...@@ -2306,10 +2888,10 @@ static IrInstruction *ir_build_array_type(IrBuilder *irb, Scope *scope, AstNode
2306 return &instruction->base;2888 return &instruction->base;
2307}2889}
23082890
2309static IrInstruction *ir_build_anyframe_type(IrBuilder *irb, Scope *scope, AstNode *source_node,2891static IrInstSrc *ir_build_anyframe_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2310 IrInstruction *payload_type)2892 IrInstSrc *payload_type)
2311{2893{
2312 IrInstructionAnyFrameType *instruction = ir_build_instruction<IrInstructionAnyFrameType>(irb, scope, source_node);2894 IrInstSrcAnyFrameType *instruction = ir_build_instruction<IrInstSrcAnyFrameType>(irb, scope, source_node);
2313 instruction->payload_type = payload_type;2895 instruction->payload_type = payload_type;
23142896
2315 if (payload_type != nullptr) ir_ref_instruction(payload_type, irb->current_basic_block);2897 if (payload_type != nullptr) ir_ref_instruction(payload_type, irb->current_basic_block);
...@@ -2317,11 +2899,11 @@ static IrInstruction *ir_build_anyframe_type(IrBuilder *irb, Scope *scope, AstNo...@@ -2317,11 +2899,11 @@ static IrInstruction *ir_build_anyframe_type(IrBuilder *irb, Scope *scope, AstNo
2317 return &instruction->base;2899 return &instruction->base;
2318}2900}
23192901
2320static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode *source_node,2902static IrInstSrc *ir_build_slice_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2321 IrInstruction *child_type, bool is_const, bool is_volatile,2903 IrInstSrc *child_type, bool is_const, bool is_volatile,
2322 IrInstruction *sentinel, IrInstruction *align_value, bool is_allow_zero)2904 IrInstSrc *sentinel, IrInstSrc *align_value, bool is_allow_zero)
2323{2905{
2324 IrInstructionSliceType *instruction = ir_build_instruction<IrInstructionSliceType>(irb, scope, source_node);2906 IrInstSrcSliceType *instruction = ir_build_instruction<IrInstSrcSliceType>(irb, scope, source_node);
2325 instruction->is_const = is_const;2907 instruction->is_const = is_const;
2326 instruction->is_volatile = is_volatile;2908 instruction->is_volatile = is_volatile;
2327 instruction->child_type = child_type;2909 instruction->child_type = child_type;
...@@ -2336,11 +2918,11 @@ static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode...@@ -2336,11 +2918,11 @@ static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode
2336 return &instruction->base;2918 return &instruction->base;
2337}2919}
23382920
2339static IrInstruction *ir_build_asm_src(IrBuilder *irb, Scope *scope, AstNode *source_node,2921static IrInstSrc *ir_build_asm_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2340 IrInstruction *asm_template, IrInstruction **input_list, IrInstruction **output_types,2922 IrInstSrc *asm_template, IrInstSrc **input_list, IrInstSrc **output_types,
2341 ZigVar **output_vars, size_t return_count, bool has_side_effects, bool is_global)2923 ZigVar **output_vars, size_t return_count, bool has_side_effects, bool is_global)
2342{2924{
2343 IrInstructionAsmSrc *instruction = ir_build_instruction<IrInstructionAsmSrc>(irb, scope, source_node);2925 IrInstSrcAsm *instruction = ir_build_instruction<IrInstSrcAsm>(irb, scope, source_node);
2344 instruction->asm_template = asm_template;2926 instruction->asm_template = asm_template;
2345 instruction->input_list = input_list;2927 instruction->input_list = input_list;
2346 instruction->output_types = output_types;2928 instruction->output_types = output_types;
...@@ -2351,24 +2933,25 @@ static IrInstruction *ir_build_asm_src(IrBuilder *irb, Scope *scope, AstNode *so...@@ -2351,24 +2933,25 @@ static IrInstruction *ir_build_asm_src(IrBuilder *irb, Scope *scope, AstNode *so
23512933
2352 assert(source_node->type == NodeTypeAsmExpr);2934 assert(source_node->type == NodeTypeAsmExpr);
2353 for (size_t i = 0; i < source_node->data.asm_expr.output_list.length; i += 1) {2935 for (size_t i = 0; i < source_node->data.asm_expr.output_list.length; i += 1) {
2354 IrInstruction *output_type = output_types[i];2936 IrInstSrc *output_type = output_types[i];
2355 if (output_type) ir_ref_instruction(output_type, irb->current_basic_block);2937 if (output_type) ir_ref_instruction(output_type, irb->current_basic_block);
2356 }2938 }
23572939
2358 for (size_t i = 0; i < source_node->data.asm_expr.input_list.length; i += 1) {2940 for (size_t i = 0; i < source_node->data.asm_expr.input_list.length; i += 1) {
2359 IrInstruction *input_value = input_list[i];2941 IrInstSrc *input_value = input_list[i];
2360 ir_ref_instruction(input_value, irb->current_basic_block);2942 ir_ref_instruction(input_value, irb->current_basic_block);
2361 }2943 }
23622944
2363 return &instruction->base;2945 return &instruction->base;
2364}2946}
23652947
2366static IrInstruction *ir_build_asm_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,2948static IrInstGen *ir_build_asm_gen(IrAnalyze *ira, IrInst *source_instr,
2367 Buf *asm_template, AsmToken *token_list, size_t token_list_len,2949 Buf *asm_template, AsmToken *token_list, size_t token_list_len,
2368 IrInstruction **input_list, IrInstruction **output_types, ZigVar **output_vars, size_t return_count,2950 IrInstGen **input_list, IrInstGen **output_types, ZigVar **output_vars, size_t return_count,
2369 bool has_side_effects)2951 bool has_side_effects, ZigType *return_type)
2370{2952{
2371 IrInstructionAsmGen *instruction = ir_build_instruction<IrInstructionAsmGen>(&ira->new_irb, scope, source_node);2953 IrInstGenAsm *instruction = ir_build_inst_gen<IrInstGenAsm>(&ira->new_irb, source_instr->scope, source_instr->source_node);
2954 instruction->base.value->type = return_type;
2372 instruction->asm_template = asm_template;2955 instruction->asm_template = asm_template;
2373 instruction->token_list = token_list;2956 instruction->token_list = token_list;
2374 instruction->token_list_len = token_list_len;2957 instruction->token_list_len = token_list_len;
...@@ -2378,22 +2961,24 @@ static IrInstruction *ir_build_asm_gen(IrAnalyze *ira, Scope *scope, AstNode *so...@@ -2378,22 +2961,24 @@ static IrInstruction *ir_build_asm_gen(IrAnalyze *ira, Scope *scope, AstNode *so
2378 instruction->return_count = return_count;2961 instruction->return_count = return_count;
2379 instruction->has_side_effects = has_side_effects;2962 instruction->has_side_effects = has_side_effects;
23802963
2381 assert(source_node->type == NodeTypeAsmExpr);2964 assert(source_instr->source_node->type == NodeTypeAsmExpr);
2382 for (size_t i = 0; i < source_node->data.asm_expr.output_list.length; i += 1) {2965 for (size_t i = 0; i < source_instr->source_node->data.asm_expr.output_list.length; i += 1) {
2383 IrInstruction *output_type = output_types[i];2966 IrInstGen *output_type = output_types[i];
2384 if (output_type) ir_ref_instruction(output_type, ira->new_irb.current_basic_block);2967 if (output_type) ir_ref_inst_gen(output_type, ira->new_irb.current_basic_block);
2385 }2968 }
23862969
2387 for (size_t i = 0; i < source_node->data.asm_expr.input_list.length; i += 1) {2970 for (size_t i = 0; i < source_instr->source_node->data.asm_expr.input_list.length; i += 1) {
2388 IrInstruction *input_value = input_list[i];2971 IrInstGen *input_value = input_list[i];
2389 ir_ref_instruction(input_value, ira->new_irb.current_basic_block);2972 ir_ref_inst_gen(input_value, ira->new_irb.current_basic_block);
2390 }2973 }
23912974
2392 return &instruction->base;2975 return &instruction->base;
2393}2976}
23942977
2395static IrInstruction *ir_build_size_of(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_value, bool bit_size) {2978static IrInstSrc *ir_build_size_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value,
2396 IrInstructionSizeOf *instruction = ir_build_instruction<IrInstructionSizeOf>(irb, scope, source_node);2979 bool bit_size)
2980{
2981 IrInstSrcSizeOf *instruction = ir_build_instruction<IrInstSrcSizeOf>(irb, scope, source_node);
2397 instruction->type_value = type_value;2982 instruction->type_value = type_value;
2398 instruction->bit_size = bit_size;2983 instruction->bit_size = bit_size;
23992984
...@@ -2402,8 +2987,10 @@ static IrInstruction *ir_build_size_of(IrBuilder *irb, Scope *scope, AstNode *so...@@ -2402,8 +2987,10 @@ static IrInstruction *ir_build_size_of(IrBuilder *irb, Scope *scope, AstNode *so
2402 return &instruction->base;2987 return &instruction->base;
2403}2988}
24042989
2405static IrInstruction *ir_build_test_nonnull(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {2990static IrInstSrc *ir_build_test_non_null_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2406 IrInstructionTestNonNull *instruction = ir_build_instruction<IrInstructionTestNonNull>(irb, scope, source_node);2991 IrInstSrc *value)
2992{
2993 IrInstSrcTestNonNull *instruction = ir_build_instruction<IrInstSrcTestNonNull>(irb, scope, source_node);
2407 instruction->value = value;2994 instruction->value = value;
24082995
2409 ir_ref_instruction(value, irb->current_basic_block);2996 ir_ref_instruction(value, irb->current_basic_block);
...@@ -2411,10 +2998,21 @@ static IrInstruction *ir_build_test_nonnull(IrBuilder *irb, Scope *scope, AstNod...@@ -2411,10 +2998,21 @@ static IrInstruction *ir_build_test_nonnull(IrBuilder *irb, Scope *scope, AstNod
2411 return &instruction->base;2998 return &instruction->base;
2412}2999}
24133000
2414static IrInstruction *ir_build_optional_unwrap_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,3001static IrInstGen *ir_build_test_non_null_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value) {
2415 IrInstruction *base_ptr, bool safety_check_on, bool initializing)3002 IrInstGenTestNonNull *inst = ir_build_inst_gen<IrInstGenTestNonNull>(&ira->new_irb,
3003 source_instr->scope, source_instr->source_node);
3004 inst->base.value->type = ira->codegen->builtin_types.entry_bool;
3005 inst->value = value;
3006
3007 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
3008
3009 return &inst->base;
3010}
3011
3012static IrInstSrc *ir_build_optional_unwrap_ptr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3013 IrInstSrc *base_ptr, bool safety_check_on, bool initializing)
2416{3014{
2417 IrInstructionOptionalUnwrapPtr *instruction = ir_build_instruction<IrInstructionOptionalUnwrapPtr>(irb, scope, source_node);3015 IrInstSrcOptionalUnwrapPtr *instruction = ir_build_instruction<IrInstSrcOptionalUnwrapPtr>(irb, scope, source_node);
2418 instruction->base_ptr = base_ptr;3016 instruction->base_ptr = base_ptr;
2419 instruction->safety_check_on = safety_check_on;3017 instruction->safety_check_on = safety_check_on;
2420 instruction->initializing = initializing;3018 instruction->initializing = initializing;
...@@ -2424,113 +3022,198 @@ static IrInstruction *ir_build_optional_unwrap_ptr(IrBuilder *irb, Scope *scope,...@@ -2424,113 +3022,198 @@ static IrInstruction *ir_build_optional_unwrap_ptr(IrBuilder *irb, Scope *scope,
2424 return &instruction->base;3022 return &instruction->base;
2425}3023}
24263024
2427static IrInstruction *ir_build_optional_wrap(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_ty,3025static IrInstGen *ir_build_optional_unwrap_ptr_gen(IrAnalyze *ira, IrInst *source_instr,
2428 IrInstruction *operand, IrInstruction *result_loc)3026 IrInstGen *base_ptr, bool safety_check_on, bool initializing, ZigType *result_type)
2429{3027{
2430 IrInstructionOptionalWrap *instruction = ir_build_instruction<IrInstructionOptionalWrap>(3028 IrInstGenOptionalUnwrapPtr *inst = ir_build_inst_gen<IrInstGenOptionalUnwrapPtr>(&ira->new_irb,
3029 source_instr->scope, source_instr->source_node);
3030 inst->base.value->type = result_type;
3031 inst->base_ptr = base_ptr;
3032 inst->safety_check_on = safety_check_on;
3033 inst->initializing = initializing;
3034
3035 ir_ref_inst_gen(base_ptr, ira->new_irb.current_basic_block);
3036
3037 return &inst->base;
3038}
3039
3040static IrInstGen *ir_build_optional_wrap(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_ty,
3041 IrInstGen *operand, IrInstGen *result_loc)
3042{
3043 IrInstGenOptionalWrap *instruction = ir_build_inst_gen<IrInstGenOptionalWrap>(
2431 &ira->new_irb, source_instruction->scope, source_instruction->source_node);3044 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2432 instruction->base.value->type = result_ty;3045 instruction->base.value->type = result_ty;
2433 instruction->operand = operand;3046 instruction->operand = operand;
2434 instruction->result_loc = result_loc;3047 instruction->result_loc = result_loc;
24353048
2436 ir_ref_instruction(operand, ira->new_irb.current_basic_block);3049 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2437 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);3050 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
24383051
2439 return &instruction->base;3052 return &instruction->base;
2440}3053}
24413054
2442static IrInstruction *ir_build_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instruction,3055static IrInstGen *ir_build_err_wrap_payload(IrAnalyze *ira, IrInst *source_instruction,
2443 ZigType *result_type, IrInstruction *operand, IrInstruction *result_loc)3056 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)
2444{3057{
2445 IrInstructionErrWrapPayload *instruction = ir_build_instruction<IrInstructionErrWrapPayload>(3058 IrInstGenErrWrapPayload *instruction = ir_build_inst_gen<IrInstGenErrWrapPayload>(
2446 &ira->new_irb, source_instruction->scope, source_instruction->source_node);3059 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2447 instruction->base.value->type = result_type;3060 instruction->base.value->type = result_type;
2448 instruction->operand = operand;3061 instruction->operand = operand;
2449 instruction->result_loc = result_loc;3062 instruction->result_loc = result_loc;
24503063
2451 ir_ref_instruction(operand, ira->new_irb.current_basic_block);3064 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2452 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);3065 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
24533066
2454 return &instruction->base;3067 return &instruction->base;
2455}3068}
24563069
2457static IrInstruction *ir_build_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instruction,3070static IrInstGen *ir_build_err_wrap_code(IrAnalyze *ira, IrInst *source_instruction,
2458 ZigType *result_type, IrInstruction *operand, IrInstruction *result_loc)3071 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)
2459{3072{
2460 IrInstructionErrWrapCode *instruction = ir_build_instruction<IrInstructionErrWrapCode>(3073 IrInstGenErrWrapCode *instruction = ir_build_inst_gen<IrInstGenErrWrapCode>(
2461 &ira->new_irb, source_instruction->scope, source_instruction->source_node);3074 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2462 instruction->base.value->type = result_type;3075 instruction->base.value->type = result_type;
2463 instruction->operand = operand;3076 instruction->operand = operand;
2464 instruction->result_loc = result_loc;3077 instruction->result_loc = result_loc;
24653078
2466 ir_ref_instruction(operand, ira->new_irb.current_basic_block);3079 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2467 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);3080 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
24683081
2469 return &instruction->base;3082 return &instruction->base;
2470}3083}
24713084
2472static IrInstruction *ir_build_clz(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) {3085static IrInstSrc *ir_build_clz(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
2473 IrInstructionClz *instruction = ir_build_instruction<IrInstructionClz>(irb, scope, source_node);3086 IrInstSrc *op)
3087{
3088 IrInstSrcClz *instruction = ir_build_instruction<IrInstSrcClz>(irb, scope, source_node);
2474 instruction->type = type;3089 instruction->type = type;
2475 instruction->op = op;3090 instruction->op = op;
24763091
2477 if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block);3092 ir_ref_instruction(type, irb->current_basic_block);
2478 ir_ref_instruction(op, irb->current_basic_block);3093 ir_ref_instruction(op, irb->current_basic_block);
24793094
2480 return &instruction->base;3095 return &instruction->base;
2481}3096}
24823097
2483static IrInstruction *ir_build_ctz(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) {3098static IrInstGen *ir_build_clz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, IrInstGen *op) {
2484 IrInstructionCtz *instruction = ir_build_instruction<IrInstructionCtz>(irb, scope, source_node);3099 IrInstGenClz *instruction = ir_build_inst_gen<IrInstGenClz>(&ira->new_irb,
3100 source_instr->scope, source_instr->source_node);
3101 instruction->base.value->type = result_type;
3102 instruction->op = op;
3103
3104 ir_ref_inst_gen(op, ira->new_irb.current_basic_block);
3105
3106 return &instruction->base;
3107}
3108
3109static IrInstSrc *ir_build_ctz(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
3110 IrInstSrc *op)
3111{
3112 IrInstSrcCtz *instruction = ir_build_instruction<IrInstSrcCtz>(irb, scope, source_node);
2485 instruction->type = type;3113 instruction->type = type;
2486 instruction->op = op;3114 instruction->op = op;
24873115
2488 if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block);3116 ir_ref_instruction(type, irb->current_basic_block);
2489 ir_ref_instruction(op, irb->current_basic_block);3117 ir_ref_instruction(op, irb->current_basic_block);
24903118
2491 return &instruction->base;3119 return &instruction->base;
2492}3120}
24933121
2494static IrInstruction *ir_build_pop_count(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) {3122static IrInstGen *ir_build_ctz_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type, IrInstGen *op) {
2495 IrInstructionPopCount *instruction = ir_build_instruction<IrInstructionPopCount>(irb, scope, source_node);3123 IrInstGenCtz *instruction = ir_build_inst_gen<IrInstGenCtz>(&ira->new_irb,
3124 source_instr->scope, source_instr->source_node);
3125 instruction->base.value->type = result_type;
3126 instruction->op = op;
3127
3128 ir_ref_inst_gen(op, ira->new_irb.current_basic_block);
3129
3130 return &instruction->base;
3131}
3132
3133static IrInstSrc *ir_build_pop_count(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
3134 IrInstSrc *op)
3135{
3136 IrInstSrcPopCount *instruction = ir_build_instruction<IrInstSrcPopCount>(irb, scope, source_node);
2496 instruction->type = type;3137 instruction->type = type;
2497 instruction->op = op;3138 instruction->op = op;
24983139
2499 if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block);3140 ir_ref_instruction(type, irb->current_basic_block);
2500 ir_ref_instruction(op, irb->current_basic_block);3141 ir_ref_instruction(op, irb->current_basic_block);
25013142
2502 return &instruction->base;3143 return &instruction->base;
2503}3144}
25043145
2505static IrInstruction *ir_build_bswap(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) {3146static IrInstGen *ir_build_pop_count_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *result_type,
2506 IrInstructionBswap *instruction = ir_build_instruction<IrInstructionBswap>(irb, scope, source_node);3147 IrInstGen *op)
3148{
3149 IrInstGenPopCount *instruction = ir_build_inst_gen<IrInstGenPopCount>(&ira->new_irb,
3150 source_instr->scope, source_instr->source_node);
3151 instruction->base.value->type = result_type;
3152 instruction->op = op;
3153
3154 ir_ref_inst_gen(op, ira->new_irb.current_basic_block);
3155
3156 return &instruction->base;
3157}
3158
3159static IrInstSrc *ir_build_bswap(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
3160 IrInstSrc *op)
3161{
3162 IrInstSrcBswap *instruction = ir_build_instruction<IrInstSrcBswap>(irb, scope, source_node);
2507 instruction->type = type;3163 instruction->type = type;
2508 instruction->op = op;3164 instruction->op = op;
25093165
2510 if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block);3166 ir_ref_instruction(type, irb->current_basic_block);
2511 ir_ref_instruction(op, irb->current_basic_block);3167 ir_ref_instruction(op, irb->current_basic_block);
25123168
2513 return &instruction->base;3169 return &instruction->base;
2514}3170}
25153171
2516static IrInstruction *ir_build_bit_reverse(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type, IrInstruction *op) {3172static IrInstGen *ir_build_bswap_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *op_type,
2517 IrInstructionBitReverse *instruction = ir_build_instruction<IrInstructionBitReverse>(irb, scope, source_node);3173 IrInstGen *op)
3174{
3175 IrInstGenBswap *instruction = ir_build_inst_gen<IrInstGenBswap>(&ira->new_irb,
3176 source_instr->scope, source_instr->source_node);
3177 instruction->base.value->type = op_type;
3178 instruction->op = op;
3179
3180 ir_ref_inst_gen(op, ira->new_irb.current_basic_block);
3181
3182 return &instruction->base;
3183}
3184
3185static IrInstSrc *ir_build_bit_reverse(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type,
3186 IrInstSrc *op)
3187{
3188 IrInstSrcBitReverse *instruction = ir_build_instruction<IrInstSrcBitReverse>(irb, scope, source_node);
2518 instruction->type = type;3189 instruction->type = type;
2519 instruction->op = op;3190 instruction->op = op;
25203191
2521 if (type != nullptr) ir_ref_instruction(type, irb->current_basic_block);3192 ir_ref_instruction(type, irb->current_basic_block);
2522 ir_ref_instruction(op, irb->current_basic_block);3193 ir_ref_instruction(op, irb->current_basic_block);
25233194
2524 return &instruction->base;3195 return &instruction->base;
2525}3196}
25263197
2527static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *target_value,3198static IrInstGen *ir_build_bit_reverse_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *int_type,
2528 IrBasicBlock *else_block, size_t case_count, IrInstructionSwitchBrCase *cases, IrInstruction *is_comptime,3199 IrInstGen *op)
2529 IrInstruction *switch_prongs_void)
2530{3200{
2531 IrInstructionSwitchBr *instruction = ir_build_instruction<IrInstructionSwitchBr>(irb, scope, source_node);3201 IrInstGenBitReverse *instruction = ir_build_inst_gen<IrInstGenBitReverse>(&ira->new_irb,
2532 instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;3202 source_instr->scope, source_instr->source_node);
2533 instruction->base.value->special = ConstValSpecialStatic;3203 instruction->base.value->type = int_type;
3204 instruction->op = op;
3205
3206 ir_ref_inst_gen(op, ira->new_irb.current_basic_block);
3207
3208 return &instruction->base;
3209}
3210
3211static IrInstSrcSwitchBr *ir_build_switch_br_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3212 IrInstSrc *target_value, IrBasicBlockSrc *else_block, size_t case_count, IrInstSrcSwitchBrCase *cases,
3213 IrInstSrc *is_comptime, IrInstSrc *switch_prongs_void)
3214{
3215 IrInstSrcSwitchBr *instruction = ir_build_instruction<IrInstSrcSwitchBr>(irb, scope, source_node);
3216 instruction->base.is_noreturn = true;
2534 instruction->target_value = target_value;3217 instruction->target_value = target_value;
2535 instruction->else_block = else_block;3218 instruction->else_block = else_block;
2536 instruction->case_count = case_count;3219 instruction->case_count = case_count;
...@@ -2539,9 +3222,9 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A...@@ -2539,9 +3222,9 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A
2539 instruction->switch_prongs_void = switch_prongs_void;3222 instruction->switch_prongs_void = switch_prongs_void;
25403223
2541 ir_ref_instruction(target_value, irb->current_basic_block);3224 ir_ref_instruction(target_value, irb->current_basic_block);
2542 if (is_comptime) ir_ref_instruction(is_comptime, irb->current_basic_block);3225 ir_ref_instruction(is_comptime, irb->current_basic_block);
2543 ir_ref_bb(else_block);3226 ir_ref_bb(else_block);
2544 if (switch_prongs_void) ir_ref_instruction(switch_prongs_void, irb->current_basic_block);3227 ir_ref_instruction(switch_prongs_void, irb->current_basic_block);
25453228
2546 for (size_t i = 0; i < case_count; i += 1) {3229 for (size_t i = 0; i < case_count; i += 1) {
2547 ir_ref_instruction(cases[i].value, irb->current_basic_block);3230 ir_ref_instruction(cases[i].value, irb->current_basic_block);
...@@ -2551,10 +3234,31 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A...@@ -2551,10 +3234,31 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A
2551 return instruction;3234 return instruction;
2552}3235}
25533236
2554static IrInstruction *ir_build_switch_target(IrBuilder *irb, Scope *scope, AstNode *source_node,3237static IrInstGenSwitchBr *ir_build_switch_br_gen(IrAnalyze *ira, IrInst *source_instr,
2555 IrInstruction *target_value_ptr)3238 IrInstGen *target_value, IrBasicBlockGen *else_block, size_t case_count, IrInstGenSwitchBrCase *cases)
2556{3239{
2557 IrInstructionSwitchTarget *instruction = ir_build_instruction<IrInstructionSwitchTarget>(irb, scope, source_node);3240 IrInstGenSwitchBr *instruction = ir_build_inst_noreturn<IrInstGenSwitchBr>(&ira->new_irb,
3241 source_instr->scope, source_instr->source_node);
3242 instruction->target_value = target_value;
3243 instruction->else_block = else_block;
3244 instruction->case_count = case_count;
3245 instruction->cases = cases;
3246
3247 ir_ref_inst_gen(target_value, ira->new_irb.current_basic_block);
3248 ir_ref_bb_gen(else_block);
3249
3250 for (size_t i = 0; i < case_count; i += 1) {
3251 ir_ref_inst_gen(cases[i].value, ira->new_irb.current_basic_block);
3252 ir_ref_bb_gen(cases[i].block);
3253 }
3254
3255 return instruction;
3256}
3257
3258static IrInstSrc *ir_build_switch_target(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3259 IrInstSrc *target_value_ptr)
3260{
3261 IrInstSrcSwitchTarget *instruction = ir_build_instruction<IrInstSrcSwitchTarget>(irb, scope, source_node);
2558 instruction->target_value_ptr = target_value_ptr;3262 instruction->target_value_ptr = target_value_ptr;
25593263
2560 ir_ref_instruction(target_value_ptr, irb->current_basic_block);3264 ir_ref_instruction(target_value_ptr, irb->current_basic_block);
...@@ -2562,10 +3266,10 @@ static IrInstruction *ir_build_switch_target(IrBuilder *irb, Scope *scope, AstNo...@@ -2562,10 +3266,10 @@ static IrInstruction *ir_build_switch_target(IrBuilder *irb, Scope *scope, AstNo
2562 return &instruction->base;3266 return &instruction->base;
2563}3267}
25643268
2565static IrInstruction *ir_build_switch_var(IrBuilder *irb, Scope *scope, AstNode *source_node,3269static IrInstSrc *ir_build_switch_var(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2566 IrInstruction *target_value_ptr, IrInstruction **prongs_ptr, size_t prongs_len)3270 IrInstSrc *target_value_ptr, IrInstSrc **prongs_ptr, size_t prongs_len)
2567{3271{
2568 IrInstructionSwitchVar *instruction = ir_build_instruction<IrInstructionSwitchVar>(irb, scope, source_node);3272 IrInstSrcSwitchVar *instruction = ir_build_instruction<IrInstSrcSwitchVar>(irb, scope, source_node);
2569 instruction->target_value_ptr = target_value_ptr;3273 instruction->target_value_ptr = target_value_ptr;
2570 instruction->prongs_ptr = prongs_ptr;3274 instruction->prongs_ptr = prongs_ptr;
2571 instruction->prongs_len = prongs_len;3275 instruction->prongs_len = prongs_len;
...@@ -2579,10 +3283,10 @@ static IrInstruction *ir_build_switch_var(IrBuilder *irb, Scope *scope, AstNode...@@ -2579,10 +3283,10 @@ static IrInstruction *ir_build_switch_var(IrBuilder *irb, Scope *scope, AstNode
2579}3283}
25803284
2581// For this instruction the switch_br must be set later.3285// For this instruction the switch_br must be set later.
2582static IrInstructionSwitchElseVar *ir_build_switch_else_var(IrBuilder *irb, Scope *scope, AstNode *source_node,3286static IrInstSrcSwitchElseVar *ir_build_switch_else_var(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2583 IrInstruction *target_value_ptr)3287 IrInstSrc *target_value_ptr)
2584{3288{
2585 IrInstructionSwitchElseVar *instruction = ir_build_instruction<IrInstructionSwitchElseVar>(irb, scope, source_node);3289 IrInstSrcSwitchElseVar *instruction = ir_build_instruction<IrInstSrcSwitchElseVar>(irb, scope, source_node);
2586 instruction->target_value_ptr = target_value_ptr;3290 instruction->target_value_ptr = target_value_ptr;
25873291
2588 ir_ref_instruction(target_value_ptr, irb->current_basic_block);3292 ir_ref_instruction(target_value_ptr, irb->current_basic_block);
...@@ -2590,17 +3294,21 @@ static IrInstructionSwitchElseVar *ir_build_switch_else_var(IrBuilder *irb, Scop...@@ -2590,17 +3294,21 @@ static IrInstructionSwitchElseVar *ir_build_switch_else_var(IrBuilder *irb, Scop
2590 return instruction;3294 return instruction;
2591}3295}
25923296
2593static IrInstruction *ir_build_union_tag(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {3297static IrInstGen *ir_build_union_tag(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value,
2594 IrInstructionUnionTag *instruction = ir_build_instruction<IrInstructionUnionTag>(irb, scope, source_node);3298 ZigType *tag_type)
3299{
3300 IrInstGenUnionTag *instruction = ir_build_inst_gen<IrInstGenUnionTag>(&ira->new_irb,
3301 source_instr->scope, source_instr->source_node);
2595 instruction->value = value;3302 instruction->value = value;
3303 instruction->base.value->type = tag_type;
25963304
2597 ir_ref_instruction(value, irb->current_basic_block);3305 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
25983306
2599 return &instruction->base;3307 return &instruction->base;
2600}3308}
26013309
2602static IrInstruction *ir_build_import(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) {3310static IrInstSrc *ir_build_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) {
2603 IrInstructionImport *instruction = ir_build_instruction<IrInstructionImport>(irb, scope, source_node);3311 IrInstSrcImport *instruction = ir_build_instruction<IrInstSrcImport>(irb, scope, source_node);
2604 instruction->name = name;3312 instruction->name = name;
26053313
2606 ir_ref_instruction(name, irb->current_basic_block);3314 ir_ref_instruction(name, irb->current_basic_block);
...@@ -2608,10 +3316,10 @@ static IrInstruction *ir_build_import(IrBuilder *irb, Scope *scope, AstNode *sou...@@ -2608,10 +3316,10 @@ static IrInstruction *ir_build_import(IrBuilder *irb, Scope *scope, AstNode *sou
2608 return &instruction->base;3316 return &instruction->base;
2609}3317}
26103318
2611static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value,3319static IrInstSrc *ir_build_ref_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value,
2612 bool is_const, bool is_volatile)3320 bool is_const, bool is_volatile)
2613{3321{
2614 IrInstructionRef *instruction = ir_build_instruction<IrInstructionRef>(irb, scope, source_node);3322 IrInstSrcRef *instruction = ir_build_instruction<IrInstSrcRef>(irb, scope, source_node);
2615 instruction->value = value;3323 instruction->value = value;
2616 instruction->is_const = is_const;3324 instruction->is_const = is_const;
2617 instruction->is_volatile = is_volatile;3325 instruction->is_volatile = is_volatile;
...@@ -2621,23 +3329,23 @@ static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source...@@ -2621,23 +3329,23 @@ static IrInstruction *ir_build_ref(IrBuilder *irb, Scope *scope, AstNode *source
2621 return &instruction->base;3329 return &instruction->base;
2622}3330}
26233331
2624static IrInstruction *ir_build_ref_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_type,3332static IrInstGen *ir_build_ref_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type,
2625 IrInstruction *operand, IrInstruction *result_loc)3333 IrInstGen *operand, IrInstGen *result_loc)
2626{3334{
2627 IrInstructionRefGen *instruction = ir_build_instruction<IrInstructionRefGen>(&ira->new_irb,3335 IrInstGenRef *instruction = ir_build_inst_gen<IrInstGenRef>(&ira->new_irb,
2628 source_instruction->scope, source_instruction->source_node);3336 source_instruction->scope, source_instruction->source_node);
2629 instruction->base.value->type = result_type;3337 instruction->base.value->type = result_type;
2630 instruction->operand = operand;3338 instruction->operand = operand;
2631 instruction->result_loc = result_loc;3339 instruction->result_loc = result_loc;
26323340
2633 ir_ref_instruction(operand, ira->new_irb.current_basic_block);3341 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
2634 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);3342 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
26353343
2636 return &instruction->base;3344 return &instruction->base;
2637}3345}
26383346
2639static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) {3347static IrInstSrc *ir_build_compile_err(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *msg) {
2640 IrInstructionCompileErr *instruction = ir_build_instruction<IrInstructionCompileErr>(irb, scope, source_node);3348 IrInstSrcCompileErr *instruction = ir_build_instruction<IrInstSrcCompileErr>(irb, scope, source_node);
2641 instruction->msg = msg;3349 instruction->msg = msg;
26423350
2643 ir_ref_instruction(msg, irb->current_basic_block);3351 ir_ref_instruction(msg, irb->current_basic_block);
...@@ -2645,10 +3353,10 @@ static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode...@@ -2645,10 +3353,10 @@ static IrInstruction *ir_build_compile_err(IrBuilder *irb, Scope *scope, AstNode
2645 return &instruction->base;3353 return &instruction->base;
2646}3354}
26473355
2648static IrInstruction *ir_build_compile_log(IrBuilder *irb, Scope *scope, AstNode *source_node,3356static IrInstSrc *ir_build_compile_log(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2649 size_t msg_count, IrInstruction **msg_list)3357 size_t msg_count, IrInstSrc **msg_list)
2650{3358{
2651 IrInstructionCompileLog *instruction = ir_build_instruction<IrInstructionCompileLog>(irb, scope, source_node);3359 IrInstSrcCompileLog *instruction = ir_build_instruction<IrInstSrcCompileLog>(irb, scope, source_node);
2652 instruction->msg_count = msg_count;3360 instruction->msg_count = msg_count;
2653 instruction->msg_list = msg_list;3361 instruction->msg_list = msg_list;
26543362
...@@ -2659,8 +3367,8 @@ static IrInstruction *ir_build_compile_log(IrBuilder *irb, Scope *scope, AstNode...@@ -2659,8 +3367,8 @@ static IrInstruction *ir_build_compile_log(IrBuilder *irb, Scope *scope, AstNode
2659 return &instruction->base;3367 return &instruction->base;
2660}3368}
26613369
2662static IrInstruction *ir_build_err_name(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {3370static IrInstSrc *ir_build_err_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) {
2663 IrInstructionErrName *instruction = ir_build_instruction<IrInstructionErrName>(irb, scope, source_node);3371 IrInstSrcErrName *instruction = ir_build_instruction<IrInstSrcErrName>(irb, scope, source_node);
2664 instruction->value = value;3372 instruction->value = value;
26653373
2666 ir_ref_instruction(value, irb->current_basic_block);3374 ir_ref_instruction(value, irb->current_basic_block);
...@@ -2668,13 +3376,26 @@ static IrInstruction *ir_build_err_name(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2668,13 +3376,26 @@ static IrInstruction *ir_build_err_name(IrBuilder *irb, Scope *scope, AstNode *s
2668 return &instruction->base;3376 return &instruction->base;
2669}3377}
26703378
2671static IrInstruction *ir_build_c_import(IrBuilder *irb, Scope *scope, AstNode *source_node) {3379static IrInstGen *ir_build_err_name_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value,
2672 IrInstructionCImport *instruction = ir_build_instruction<IrInstructionCImport>(irb, scope, source_node);3380 ZigType *str_type)
3381{
3382 IrInstGenErrName *instruction = ir_build_inst_gen<IrInstGenErrName>(&ira->new_irb,
3383 source_instr->scope, source_instr->source_node);
3384 instruction->base.value->type = str_type;
3385 instruction->value = value;
3386
3387 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
3388
2673 return &instruction->base;3389 return &instruction->base;
2674}3390}
26753391
2676static IrInstruction *ir_build_c_include(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) {3392static IrInstSrc *ir_build_c_import(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
2677 IrInstructionCInclude *instruction = ir_build_instruction<IrInstructionCInclude>(irb, scope, source_node);3393 IrInstSrcCImport *instruction = ir_build_instruction<IrInstSrcCImport>(irb, scope, source_node);
3394 return &instruction->base;
3395}
3396
3397static IrInstSrc *ir_build_c_include(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) {
3398 IrInstSrcCInclude *instruction = ir_build_instruction<IrInstSrcCInclude>(irb, scope, source_node);
2678 instruction->name = name;3399 instruction->name = name;
26793400
2680 ir_ref_instruction(name, irb->current_basic_block);3401 ir_ref_instruction(name, irb->current_basic_block);
...@@ -2682,8 +3403,8 @@ static IrInstruction *ir_build_c_include(IrBuilder *irb, Scope *scope, AstNode *...@@ -2682,8 +3403,8 @@ static IrInstruction *ir_build_c_include(IrBuilder *irb, Scope *scope, AstNode *
2682 return &instruction->base;3403 return &instruction->base;
2683}3404}
26843405
2685static IrInstruction *ir_build_c_define(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name, IrInstruction *value) {3406static IrInstSrc *ir_build_c_define(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name, IrInstSrc *value) {
2686 IrInstructionCDefine *instruction = ir_build_instruction<IrInstructionCDefine>(irb, scope, source_node);3407 IrInstSrcCDefine *instruction = ir_build_instruction<IrInstSrcCDefine>(irb, scope, source_node);
2687 instruction->name = name;3408 instruction->name = name;
2688 instruction->value = value;3409 instruction->value = value;
26893410
...@@ -2693,8 +3414,8 @@ static IrInstruction *ir_build_c_define(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2693,8 +3414,8 @@ static IrInstruction *ir_build_c_define(IrBuilder *irb, Scope *scope, AstNode *s
2693 return &instruction->base;3414 return &instruction->base;
2694}3415}
26953416
2696static IrInstruction *ir_build_c_undef(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) {3417static IrInstSrc *ir_build_c_undef(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) {
2697 IrInstructionCUndef *instruction = ir_build_instruction<IrInstructionCUndef>(irb, scope, source_node);3418 IrInstSrcCUndef *instruction = ir_build_instruction<IrInstSrcCUndef>(irb, scope, source_node);
2698 instruction->name = name;3419 instruction->name = name;
26993420
2700 ir_ref_instruction(name, irb->current_basic_block);3421 ir_ref_instruction(name, irb->current_basic_block);
...@@ -2702,8 +3423,8 @@ static IrInstruction *ir_build_c_undef(IrBuilder *irb, Scope *scope, AstNode *so...@@ -2702,8 +3423,8 @@ static IrInstruction *ir_build_c_undef(IrBuilder *irb, Scope *scope, AstNode *so
2702 return &instruction->base;3423 return &instruction->base;
2703}3424}
27043425
2705static IrInstruction *ir_build_embed_file(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *name) {3426static IrInstSrc *ir_build_embed_file(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *name) {
2706 IrInstructionEmbedFile *instruction = ir_build_instruction<IrInstructionEmbedFile>(irb, scope, source_node);3427 IrInstSrcEmbedFile *instruction = ir_build_instruction<IrInstSrcEmbedFile>(irb, scope, source_node);
2707 instruction->name = name;3428 instruction->name = name;
27083429
2709 ir_ref_instruction(name, irb->current_basic_block);3430 ir_ref_instruction(name, irb->current_basic_block);
...@@ -2711,11 +3432,11 @@ static IrInstruction *ir_build_embed_file(IrBuilder *irb, Scope *scope, AstNode...@@ -2711,11 +3432,11 @@ static IrInstruction *ir_build_embed_file(IrBuilder *irb, Scope *scope, AstNode
2711 return &instruction->base;3432 return &instruction->base;
2712}3433}
27133434
2714static IrInstruction *ir_build_cmpxchg_src(IrBuilder *irb, Scope *scope, AstNode *source_node,3435static IrInstSrc *ir_build_cmpxchg_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2715 IrInstruction *type_value, IrInstruction *ptr, IrInstruction *cmp_value, IrInstruction *new_value,3436 IrInstSrc *type_value, IrInstSrc *ptr, IrInstSrc *cmp_value, IrInstSrc *new_value,
2716 IrInstruction *success_order_value, IrInstruction *failure_order_value, bool is_weak, ResultLoc *result_loc)3437 IrInstSrc *success_order_value, IrInstSrc *failure_order_value, bool is_weak, ResultLoc *result_loc)
2717{3438{
2718 IrInstructionCmpxchgSrc *instruction = ir_build_instruction<IrInstructionCmpxchgSrc>(irb, scope, source_node);3439 IrInstSrcCmpxchg *instruction = ir_build_instruction<IrInstSrcCmpxchg>(irb, scope, source_node);
2719 instruction->type_value = type_value;3440 instruction->type_value = type_value;
2720 instruction->ptr = ptr;3441 instruction->ptr = ptr;
2721 instruction->cmp_value = cmp_value;3442 instruction->cmp_value = cmp_value;
...@@ -2735,11 +3456,11 @@ static IrInstruction *ir_build_cmpxchg_src(IrBuilder *irb, Scope *scope, AstNode...@@ -2735,11 +3456,11 @@ static IrInstruction *ir_build_cmpxchg_src(IrBuilder *irb, Scope *scope, AstNode
2735 return &instruction->base;3456 return &instruction->base;
2736}3457}
27373458
2738static IrInstruction *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_type,3459static IrInstGen *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type,
2739 IrInstruction *ptr, IrInstruction *cmp_value, IrInstruction *new_value,3460 IrInstGen *ptr, IrInstGen *cmp_value, IrInstGen *new_value,
2740 AtomicOrder success_order, AtomicOrder failure_order, bool is_weak, IrInstruction *result_loc)3461 AtomicOrder success_order, AtomicOrder failure_order, bool is_weak, IrInstGen *result_loc)
2741{3462{
2742 IrInstructionCmpxchgGen *instruction = ir_build_instruction<IrInstructionCmpxchgGen>(&ira->new_irb,3463 IrInstGenCmpxchg *instruction = ir_build_inst_gen<IrInstGenCmpxchg>(&ira->new_irb,
2743 source_instruction->scope, source_instruction->source_node);3464 source_instruction->scope, source_instruction->source_node);
2744 instruction->base.value->type = result_type;3465 instruction->base.value->type = result_type;
2745 instruction->ptr = ptr;3466 instruction->ptr = ptr;
...@@ -2750,26 +3471,35 @@ static IrInstruction *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInstruction *source...@@ -2750,26 +3471,35 @@ static IrInstruction *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInstruction *source
2750 instruction->is_weak = is_weak;3471 instruction->is_weak = is_weak;
2751 instruction->result_loc = result_loc;3472 instruction->result_loc = result_loc;
27523473
2753 ir_ref_instruction(ptr, ira->new_irb.current_basic_block);3474 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
2754 ir_ref_instruction(cmp_value, ira->new_irb.current_basic_block);3475 ir_ref_inst_gen(cmp_value, ira->new_irb.current_basic_block);
2755 ir_ref_instruction(new_value, ira->new_irb.current_basic_block);3476 ir_ref_inst_gen(new_value, ira->new_irb.current_basic_block);
2756 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);3477 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
27573478
2758 return &instruction->base;3479 return &instruction->base;
2759}3480}
27603481
2761static IrInstruction *ir_build_fence(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *order_value, AtomicOrder order) {3482static IrInstSrc *ir_build_fence(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *order) {
2762 IrInstructionFence *instruction = ir_build_instruction<IrInstructionFence>(irb, scope, source_node);3483 IrInstSrcFence *instruction = ir_build_instruction<IrInstSrcFence>(irb, scope, source_node);
2763 instruction->order_value = order_value;
2764 instruction->order = order;3484 instruction->order = order;
27653485
2766 ir_ref_instruction(order_value, irb->current_basic_block);3486 ir_ref_instruction(order, irb->current_basic_block);
3487
3488 return &instruction->base;
3489}
3490
3491static IrInstGen *ir_build_fence_gen(IrAnalyze *ira, IrInst *source_instr, AtomicOrder order) {
3492 IrInstGenFence *instruction = ir_build_inst_void<IrInstGenFence>(&ira->new_irb,
3493 source_instr->scope, source_instr->source_node);
3494 instruction->order = order;
27673495
2768 return &instruction->base;3496 return &instruction->base;
2769}3497}
27703498
2771static IrInstruction *ir_build_truncate(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {3499static IrInstSrc *ir_build_truncate(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2772 IrInstructionTruncate *instruction = ir_build_instruction<IrInstructionTruncate>(irb, scope, source_node);3500 IrInstSrc *dest_type, IrInstSrc *target)
3501{
3502 IrInstSrcTruncate *instruction = ir_build_instruction<IrInstSrcTruncate>(irb, scope, source_node);
2773 instruction->dest_type = dest_type;3503 instruction->dest_type = dest_type;
2774 instruction->target = target;3504 instruction->target = target;
27753505
...@@ -2779,8 +3509,23 @@ static IrInstruction *ir_build_truncate(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2779,8 +3509,23 @@ static IrInstruction *ir_build_truncate(IrBuilder *irb, Scope *scope, AstNode *s
2779 return &instruction->base;3509 return &instruction->base;
2780}3510}
27813511
2782static IrInstruction *ir_build_int_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {3512static IrInstGen *ir_build_truncate_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *dest_type,
2783 IrInstructionIntCast *instruction = ir_build_instruction<IrInstructionIntCast>(irb, scope, source_node);3513 IrInstGen *target)
3514{
3515 IrInstGenTruncate *instruction = ir_build_inst_gen<IrInstGenTruncate>(&ira->new_irb,
3516 source_instr->scope, source_instr->source_node);
3517 instruction->base.value->type = dest_type;
3518 instruction->target = target;
3519
3520 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
3521
3522 return &instruction->base;
3523}
3524
3525static IrInstSrc *ir_build_int_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *dest_type,
3526 IrInstSrc *target)
3527{
3528 IrInstSrcIntCast *instruction = ir_build_instruction<IrInstSrcIntCast>(irb, scope, source_node);
2784 instruction->dest_type = dest_type;3529 instruction->dest_type = dest_type;
2785 instruction->target = target;3530 instruction->target = target;
27863531
...@@ -2790,8 +3535,10 @@ static IrInstruction *ir_build_int_cast(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2790,8 +3535,10 @@ static IrInstruction *ir_build_int_cast(IrBuilder *irb, Scope *scope, AstNode *s
2790 return &instruction->base;3535 return &instruction->base;
2791}3536}
27923537
2793static IrInstruction *ir_build_float_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {3538static IrInstSrc *ir_build_float_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *dest_type,
2794 IrInstructionFloatCast *instruction = ir_build_instruction<IrInstructionFloatCast>(irb, scope, source_node);3539 IrInstSrc *target)
3540{
3541 IrInstSrcFloatCast *instruction = ir_build_instruction<IrInstSrcFloatCast>(irb, scope, source_node);
2795 instruction->dest_type = dest_type;3542 instruction->dest_type = dest_type;
2796 instruction->target = target;3543 instruction->target = target;
27973544
...@@ -2801,8 +3548,10 @@ static IrInstruction *ir_build_float_cast(IrBuilder *irb, Scope *scope, AstNode...@@ -2801,8 +3548,10 @@ static IrInstruction *ir_build_float_cast(IrBuilder *irb, Scope *scope, AstNode
2801 return &instruction->base;3548 return &instruction->base;
2802}3549}
28033550
2804static IrInstruction *ir_build_err_set_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {3551static IrInstSrc *ir_build_err_set_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2805 IrInstructionErrSetCast *instruction = ir_build_instruction<IrInstructionErrSetCast>(irb, scope, source_node);3552 IrInstSrc *dest_type, IrInstSrc *target)
3553{
3554 IrInstSrcErrSetCast *instruction = ir_build_instruction<IrInstSrcErrSetCast>(irb, scope, source_node);
2806 instruction->dest_type = dest_type;3555 instruction->dest_type = dest_type;
2807 instruction->target = target;3556 instruction->target = target;
28083557
...@@ -2812,10 +3561,10 @@ static IrInstruction *ir_build_err_set_cast(IrBuilder *irb, Scope *scope, AstNod...@@ -2812,10 +3561,10 @@ static IrInstruction *ir_build_err_set_cast(IrBuilder *irb, Scope *scope, AstNod
2812 return &instruction->base;3561 return &instruction->base;
2813}3562}
28143563
2815static IrInstruction *ir_build_to_bytes(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *target,3564static IrInstSrc *ir_build_to_bytes(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target,
2816 ResultLoc *result_loc)3565 ResultLoc *result_loc)
2817{3566{
2818 IrInstructionToBytes *instruction = ir_build_instruction<IrInstructionToBytes>(irb, scope, source_node);3567 IrInstSrcToBytes *instruction = ir_build_instruction<IrInstSrcToBytes>(irb, scope, source_node);
2819 instruction->target = target;3568 instruction->target = target;
2820 instruction->result_loc = result_loc;3569 instruction->result_loc = result_loc;
28213570
...@@ -2824,10 +3573,10 @@ static IrInstruction *ir_build_to_bytes(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2824,10 +3573,10 @@ static IrInstruction *ir_build_to_bytes(IrBuilder *irb, Scope *scope, AstNode *s
2824 return &instruction->base;3573 return &instruction->base;
2825}3574}
28263575
2827static IrInstruction *ir_build_from_bytes(IrBuilder *irb, Scope *scope, AstNode *source_node,3576static IrInstSrc *ir_build_from_bytes(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2828 IrInstruction *dest_child_type, IrInstruction *target, ResultLoc *result_loc)3577 IrInstSrc *dest_child_type, IrInstSrc *target, ResultLoc *result_loc)
2829{3578{
2830 IrInstructionFromBytes *instruction = ir_build_instruction<IrInstructionFromBytes>(irb, scope, source_node);3579 IrInstSrcFromBytes *instruction = ir_build_instruction<IrInstSrcFromBytes>(irb, scope, source_node);
2831 instruction->dest_child_type = dest_child_type;3580 instruction->dest_child_type = dest_child_type;
2832 instruction->target = target;3581 instruction->target = target;
2833 instruction->result_loc = result_loc;3582 instruction->result_loc = result_loc;
...@@ -2838,8 +3587,10 @@ static IrInstruction *ir_build_from_bytes(IrBuilder *irb, Scope *scope, AstNode...@@ -2838,8 +3587,10 @@ static IrInstruction *ir_build_from_bytes(IrBuilder *irb, Scope *scope, AstNode
2838 return &instruction->base;3587 return &instruction->base;
2839}3588}
28403589
2841static IrInstruction *ir_build_int_to_float(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {3590static IrInstSrc *ir_build_int_to_float(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2842 IrInstructionIntToFloat *instruction = ir_build_instruction<IrInstructionIntToFloat>(irb, scope, source_node);3591 IrInstSrc *dest_type, IrInstSrc *target)
3592{
3593 IrInstSrcIntToFloat *instruction = ir_build_instruction<IrInstSrcIntToFloat>(irb, scope, source_node);
2843 instruction->dest_type = dest_type;3594 instruction->dest_type = dest_type;
2844 instruction->target = target;3595 instruction->target = target;
28453596
...@@ -2849,8 +3600,10 @@ static IrInstruction *ir_build_int_to_float(IrBuilder *irb, Scope *scope, AstNod...@@ -2849,8 +3600,10 @@ static IrInstruction *ir_build_int_to_float(IrBuilder *irb, Scope *scope, AstNod
2849 return &instruction->base;3600 return &instruction->base;
2850}3601}
28513602
2852static IrInstruction *ir_build_float_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *dest_type, IrInstruction *target) {3603static IrInstSrc *ir_build_float_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2853 IrInstructionFloatToInt *instruction = ir_build_instruction<IrInstructionFloatToInt>(irb, scope, source_node);3604 IrInstSrc *dest_type, IrInstSrc *target)
3605{
3606 IrInstSrcFloatToInt *instruction = ir_build_instruction<IrInstSrcFloatToInt>(irb, scope, source_node);
2854 instruction->dest_type = dest_type;3607 instruction->dest_type = dest_type;
2855 instruction->target = target;3608 instruction->target = target;
28563609
...@@ -2860,8 +3613,8 @@ static IrInstruction *ir_build_float_to_int(IrBuilder *irb, Scope *scope, AstNod...@@ -2860,8 +3613,8 @@ static IrInstruction *ir_build_float_to_int(IrBuilder *irb, Scope *scope, AstNod
2860 return &instruction->base;3613 return &instruction->base;
2861}3614}
28623615
2863static IrInstruction *ir_build_bool_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *target) {3616static IrInstSrc *ir_build_bool_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target) {
2864 IrInstructionBoolToInt *instruction = ir_build_instruction<IrInstructionBoolToInt>(irb, scope, source_node);3617 IrInstSrcBoolToInt *instruction = ir_build_instruction<IrInstSrcBoolToInt>(irb, scope, source_node);
2865 instruction->target = target;3618 instruction->target = target;
28663619
2867 ir_ref_instruction(target, irb->current_basic_block);3620 ir_ref_instruction(target, irb->current_basic_block);
...@@ -2869,8 +3622,10 @@ static IrInstruction *ir_build_bool_to_int(IrBuilder *irb, Scope *scope, AstNode...@@ -2869,8 +3622,10 @@ static IrInstruction *ir_build_bool_to_int(IrBuilder *irb, Scope *scope, AstNode
2869 return &instruction->base;3622 return &instruction->base;
2870}3623}
28713624
2872static IrInstruction *ir_build_int_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *is_signed, IrInstruction *bit_count) {3625static IrInstSrc *ir_build_int_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *is_signed,
2873 IrInstructionIntType *instruction = ir_build_instruction<IrInstructionIntType>(irb, scope, source_node);3626 IrInstSrc *bit_count)
3627{
3628 IrInstSrcIntType *instruction = ir_build_instruction<IrInstSrcIntType>(irb, scope, source_node);
2874 instruction->is_signed = is_signed;3629 instruction->is_signed = is_signed;
2875 instruction->bit_count = bit_count;3630 instruction->bit_count = bit_count;
28763631
...@@ -2880,10 +3635,10 @@ static IrInstruction *ir_build_int_type(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2880,10 +3635,10 @@ static IrInstruction *ir_build_int_type(IrBuilder *irb, Scope *scope, AstNode *s
2880 return &instruction->base;3635 return &instruction->base;
2881}3636}
28823637
2883static IrInstruction *ir_build_vector_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *len,3638static IrInstSrc *ir_build_vector_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *len,
2884 IrInstruction *elem_type)3639 IrInstSrc *elem_type)
2885{3640{
2886 IrInstructionVectorType *instruction = ir_build_instruction<IrInstructionVectorType>(irb, scope, source_node);3641 IrInstSrcVectorType *instruction = ir_build_instruction<IrInstSrcVectorType>(irb, scope, source_node);
2887 instruction->len = len;3642 instruction->len = len;
2888 instruction->elem_type = elem_type;3643 instruction->elem_type = elem_type;
28893644
...@@ -2893,18 +3648,16 @@ static IrInstruction *ir_build_vector_type(IrBuilder *irb, Scope *scope, AstNode...@@ -2893,18 +3648,16 @@ static IrInstruction *ir_build_vector_type(IrBuilder *irb, Scope *scope, AstNode
2893 return &instruction->base;3648 return &instruction->base;
2894}3649}
28953650
2896static IrInstruction *ir_build_shuffle_vector(IrBuilder *irb, Scope *scope, AstNode *source_node,3651static IrInstSrc *ir_build_shuffle_vector(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
2897 IrInstruction *scalar_type, IrInstruction *a, IrInstruction *b, IrInstruction *mask)3652 IrInstSrc *scalar_type, IrInstSrc *a, IrInstSrc *b, IrInstSrc *mask)
2898{3653{
2899 IrInstructionShuffleVector *instruction = ir_build_instruction<IrInstructionShuffleVector>(irb, scope, source_node);3654 IrInstSrcShuffleVector *instruction = ir_build_instruction<IrInstSrcShuffleVector>(irb, scope, source_node);
2900 instruction->scalar_type = scalar_type;3655 instruction->scalar_type = scalar_type;
2901 instruction->a = a;3656 instruction->a = a;
2902 instruction->b = b;3657 instruction->b = b;
2903 instruction->mask = mask;3658 instruction->mask = mask;
29043659
2905 if (scalar_type != nullptr) {3660 if (scalar_type != nullptr) ir_ref_instruction(scalar_type, irb->current_basic_block);
2906 ir_ref_instruction(scalar_type, irb->current_basic_block);
2907 }
2908 ir_ref_instruction(a, irb->current_basic_block);3661 ir_ref_instruction(a, irb->current_basic_block);
2909 ir_ref_instruction(b, irb->current_basic_block);3662 ir_ref_instruction(b, irb->current_basic_block);
2910 ir_ref_instruction(mask, irb->current_basic_block);3663 ir_ref_instruction(mask, irb->current_basic_block);
...@@ -2912,10 +3665,26 @@ static IrInstruction *ir_build_shuffle_vector(IrBuilder *irb, Scope *scope, AstN...@@ -2912,10 +3665,26 @@ static IrInstruction *ir_build_shuffle_vector(IrBuilder *irb, Scope *scope, AstN
2912 return &instruction->base;3665 return &instruction->base;
2913}3666}
29143667
2915static IrInstruction *ir_build_splat_src(IrBuilder *irb, Scope *scope, AstNode *source_node,3668static IrInstGen *ir_build_shuffle_vector_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
2916 IrInstruction *len, IrInstruction *scalar)3669 ZigType *result_type, IrInstGen *a, IrInstGen *b, IrInstGen *mask)
2917{3670{
2918 IrInstructionSplatSrc *instruction = ir_build_instruction<IrInstructionSplatSrc>(irb, scope, source_node);3671 IrInstGenShuffleVector *inst = ir_build_inst_gen<IrInstGenShuffleVector>(&ira->new_irb, scope, source_node);
3672 inst->base.value->type = result_type;
3673 inst->a = a;
3674 inst->b = b;
3675 inst->mask = mask;
3676
3677 ir_ref_inst_gen(a, ira->new_irb.current_basic_block);
3678 ir_ref_inst_gen(b, ira->new_irb.current_basic_block);
3679 ir_ref_inst_gen(mask, ira->new_irb.current_basic_block);
3680
3681 return &inst->base;
3682}
3683
3684static IrInstSrc *ir_build_splat_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3685 IrInstSrc *len, IrInstSrc *scalar)
3686{
3687 IrInstSrcSplat *instruction = ir_build_instruction<IrInstSrcSplat>(irb, scope, source_node);
2919 instruction->len = len;3688 instruction->len = len;
2920 instruction->scalar = scalar;3689 instruction->scalar = scalar;
29213690
...@@ -2925,8 +3694,21 @@ static IrInstruction *ir_build_splat_src(IrBuilder *irb, Scope *scope, AstNode *...@@ -2925,8 +3694,21 @@ static IrInstruction *ir_build_splat_src(IrBuilder *irb, Scope *scope, AstNode *
2925 return &instruction->base;3694 return &instruction->base;
2926}3695}
29273696
2928static IrInstruction *ir_build_bool_not(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {3697static IrInstGen *ir_build_splat_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *result_type,
2929 IrInstructionBoolNot *instruction = ir_build_instruction<IrInstructionBoolNot>(irb, scope, source_node);3698 IrInstGen *scalar)
3699{
3700 IrInstGenSplat *instruction = ir_build_inst_gen<IrInstGenSplat>(
3701 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
3702 instruction->base.value->type = result_type;
3703 instruction->scalar = scalar;
3704
3705 ir_ref_inst_gen(scalar, ira->new_irb.current_basic_block);
3706
3707 return &instruction->base;
3708}
3709
3710static IrInstSrc *ir_build_bool_not(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) {
3711 IrInstSrcBoolNot *instruction = ir_build_instruction<IrInstSrcBoolNot>(irb, scope, source_node);
2930 instruction->value = value;3712 instruction->value = value;
29313713
2932 ir_ref_instruction(value, irb->current_basic_block);3714 ir_ref_instruction(value, irb->current_basic_block);
...@@ -2934,10 +3716,21 @@ static IrInstruction *ir_build_bool_not(IrBuilder *irb, Scope *scope, AstNode *s...@@ -2934,10 +3716,21 @@ static IrInstruction *ir_build_bool_not(IrBuilder *irb, Scope *scope, AstNode *s
2934 return &instruction->base;3716 return &instruction->base;
2935}3717}
29363718
2937static IrInstruction *ir_build_memset(IrBuilder *irb, Scope *scope, AstNode *source_node,3719static IrInstGen *ir_build_bool_not_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value) {
2938 IrInstruction *dest_ptr, IrInstruction *byte, IrInstruction *count)3720 IrInstGenBoolNot *instruction = ir_build_inst_gen<IrInstGenBoolNot>(&ira->new_irb,
3721 source_instr->scope, source_instr->source_node);
3722 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;
3723 instruction->value = value;
3724
3725 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
3726
3727 return &instruction->base;
3728}
3729
3730static IrInstSrc *ir_build_memset_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3731 IrInstSrc *dest_ptr, IrInstSrc *byte, IrInstSrc *count)
2939{3732{
2940 IrInstructionMemset *instruction = ir_build_instruction<IrInstructionMemset>(irb, scope, source_node);3733 IrInstSrcMemset *instruction = ir_build_instruction<IrInstSrcMemset>(irb, scope, source_node);
2941 instruction->dest_ptr = dest_ptr;3734 instruction->dest_ptr = dest_ptr;
2942 instruction->byte = byte;3735 instruction->byte = byte;
2943 instruction->count = count;3736 instruction->count = count;
...@@ -2949,10 +3742,26 @@ static IrInstruction *ir_build_memset(IrBuilder *irb, Scope *scope, AstNode *sou...@@ -2949,10 +3742,26 @@ static IrInstruction *ir_build_memset(IrBuilder *irb, Scope *scope, AstNode *sou
2949 return &instruction->base;3742 return &instruction->base;
2950}3743}
29513744
2952static IrInstruction *ir_build_memcpy(IrBuilder *irb, Scope *scope, AstNode *source_node,3745static IrInstGen *ir_build_memset_gen(IrAnalyze *ira, IrInst *source_instr,
2953 IrInstruction *dest_ptr, IrInstruction *src_ptr, IrInstruction *count)3746 IrInstGen *dest_ptr, IrInstGen *byte, IrInstGen *count)
2954{3747{
2955 IrInstructionMemcpy *instruction = ir_build_instruction<IrInstructionMemcpy>(irb, scope, source_node);3748 IrInstGenMemset *instruction = ir_build_inst_void<IrInstGenMemset>(&ira->new_irb,
3749 source_instr->scope, source_instr->source_node);
3750 instruction->dest_ptr = dest_ptr;
3751 instruction->byte = byte;
3752 instruction->count = count;
3753
3754 ir_ref_inst_gen(dest_ptr, ira->new_irb.current_basic_block);
3755 ir_ref_inst_gen(byte, ira->new_irb.current_basic_block);
3756 ir_ref_inst_gen(count, ira->new_irb.current_basic_block);
3757
3758 return &instruction->base;
3759}
3760
3761static IrInstSrc *ir_build_memcpy_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3762 IrInstSrc *dest_ptr, IrInstSrc *src_ptr, IrInstSrc *count)
3763{
3764 IrInstSrcMemcpy *instruction = ir_build_instruction<IrInstSrcMemcpy>(irb, scope, source_node);
2956 instruction->dest_ptr = dest_ptr;3765 instruction->dest_ptr = dest_ptr;
2957 instruction->src_ptr = src_ptr;3766 instruction->src_ptr = src_ptr;
2958 instruction->count = count;3767 instruction->count = count;
...@@ -2964,11 +3773,27 @@ static IrInstruction *ir_build_memcpy(IrBuilder *irb, Scope *scope, AstNode *sou...@@ -2964,11 +3773,27 @@ static IrInstruction *ir_build_memcpy(IrBuilder *irb, Scope *scope, AstNode *sou
2964 return &instruction->base;3773 return &instruction->base;
2965}3774}
29663775
2967static IrInstruction *ir_build_slice_src(IrBuilder *irb, Scope *scope, AstNode *source_node,3776static IrInstGen *ir_build_memcpy_gen(IrAnalyze *ira, IrInst *source_instr,
2968 IrInstruction *ptr, IrInstruction *start, IrInstruction *end, IrInstruction *sentinel,3777 IrInstGen *dest_ptr, IrInstGen *src_ptr, IrInstGen *count)
3778{
3779 IrInstGenMemcpy *instruction = ir_build_inst_void<IrInstGenMemcpy>(&ira->new_irb,
3780 source_instr->scope, source_instr->source_node);
3781 instruction->dest_ptr = dest_ptr;
3782 instruction->src_ptr = src_ptr;
3783 instruction->count = count;
3784
3785 ir_ref_inst_gen(dest_ptr, ira->new_irb.current_basic_block);
3786 ir_ref_inst_gen(src_ptr, ira->new_irb.current_basic_block);
3787 ir_ref_inst_gen(count, ira->new_irb.current_basic_block);
3788
3789 return &instruction->base;
3790}
3791
3792static IrInstSrc *ir_build_slice_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3793 IrInstSrc *ptr, IrInstSrc *start, IrInstSrc *end, IrInstSrc *sentinel,
2969 bool safety_check_on, ResultLoc *result_loc)3794 bool safety_check_on, ResultLoc *result_loc)
2970{3795{
2971 IrInstructionSliceSrc *instruction = ir_build_instruction<IrInstructionSliceSrc>(irb, scope, source_node);3796 IrInstSrcSlice *instruction = ir_build_instruction<IrInstSrcSlice>(irb, scope, source_node);
2972 instruction->ptr = ptr;3797 instruction->ptr = ptr;
2973 instruction->start = start;3798 instruction->start = start;
2974 instruction->end = end;3799 instruction->end = end;
...@@ -2984,23 +3809,10 @@ static IrInstruction *ir_build_slice_src(IrBuilder *irb, Scope *scope, AstNode *...@@ -2984,23 +3809,10 @@ static IrInstruction *ir_build_slice_src(IrBuilder *irb, Scope *scope, AstNode *
2984 return &instruction->base;3809 return &instruction->base;
2985}3810}
29863811
2987static IrInstruction *ir_build_splat_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *result_type,3812static IrInstGen *ir_build_slice_gen(IrAnalyze *ira, IrInst *source_instruction, ZigType *slice_type,
2988 IrInstruction *scalar)3813 IrInstGen *ptr, IrInstGen *start, IrInstGen *end, bool safety_check_on, IrInstGen *result_loc)
2989{
2990 IrInstructionSplatGen *instruction = ir_build_instruction<IrInstructionSplatGen>(
2991 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
2992 instruction->base.value->type = result_type;
2993 instruction->scalar = scalar;
2994
2995 ir_ref_instruction(scalar, ira->new_irb.current_basic_block);
2996
2997 return &instruction->base;
2998}
2999
3000static IrInstruction *ir_build_slice_gen(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *slice_type,
3001 IrInstruction *ptr, IrInstruction *start, IrInstruction *end, bool safety_check_on, IrInstruction *result_loc)
3002{3814{
3003 IrInstructionSliceGen *instruction = ir_build_instruction<IrInstructionSliceGen>(3815 IrInstGenSlice *instruction = ir_build_inst_gen<IrInstGenSlice>(
3004 &ira->new_irb, source_instruction->scope, source_instruction->source_node);3816 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
3005 instruction->base.value->type = slice_type;3817 instruction->base.value->type = slice_type;
3006 instruction->ptr = ptr;3818 instruction->ptr = ptr;
...@@ -3009,16 +3821,16 @@ static IrInstruction *ir_build_slice_gen(IrAnalyze *ira, IrInstruction *source_i...@@ -3009,16 +3821,16 @@ static IrInstruction *ir_build_slice_gen(IrAnalyze *ira, IrInstruction *source_i
3009 instruction->safety_check_on = safety_check_on;3821 instruction->safety_check_on = safety_check_on;
3010 instruction->result_loc = result_loc;3822 instruction->result_loc = result_loc;
30113823
3012 ir_ref_instruction(ptr, ira->new_irb.current_basic_block);3824 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
3013 ir_ref_instruction(start, ira->new_irb.current_basic_block);3825 ir_ref_inst_gen(start, ira->new_irb.current_basic_block);
3014 if (end) ir_ref_instruction(end, ira->new_irb.current_basic_block);3826 if (end) ir_ref_inst_gen(end, ira->new_irb.current_basic_block);
3015 ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);3827 ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
30163828
3017 return &instruction->base;3829 return &instruction->base;
3018}3830}
30193831
3020static IrInstruction *ir_build_member_count(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *container) {3832static IrInstSrc *ir_build_member_count(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *container) {
3021 IrInstructionMemberCount *instruction = ir_build_instruction<IrInstructionMemberCount>(irb, scope, source_node);3833 IrInstSrcMemberCount *instruction = ir_build_instruction<IrInstSrcMemberCount>(irb, scope, source_node);
3022 instruction->container = container;3834 instruction->container = container;
30233835
3024 ir_ref_instruction(container, irb->current_basic_block);3836 ir_ref_instruction(container, irb->current_basic_block);
...@@ -3026,10 +3838,10 @@ static IrInstruction *ir_build_member_count(IrBuilder *irb, Scope *scope, AstNod...@@ -3026,10 +3838,10 @@ static IrInstruction *ir_build_member_count(IrBuilder *irb, Scope *scope, AstNod
3026 return &instruction->base;3838 return &instruction->base;
3027}3839}
30283840
3029static IrInstruction *ir_build_member_type(IrBuilder *irb, Scope *scope, AstNode *source_node,3841static IrInstSrc *ir_build_member_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3030 IrInstruction *container_type, IrInstruction *member_index)3842 IrInstSrc *container_type, IrInstSrc *member_index)
3031{3843{
3032 IrInstructionMemberType *instruction = ir_build_instruction<IrInstructionMemberType>(irb, scope, source_node);3844 IrInstSrcMemberType *instruction = ir_build_instruction<IrInstSrcMemberType>(irb, scope, source_node);
3033 instruction->container_type = container_type;3845 instruction->container_type = container_type;
3034 instruction->member_index = member_index;3846 instruction->member_index = member_index;
30353847
...@@ -3039,10 +3851,10 @@ static IrInstruction *ir_build_member_type(IrBuilder *irb, Scope *scope, AstNode...@@ -3039,10 +3851,10 @@ static IrInstruction *ir_build_member_type(IrBuilder *irb, Scope *scope, AstNode
3039 return &instruction->base;3851 return &instruction->base;
3040}3852}
30413853
3042static IrInstruction *ir_build_member_name(IrBuilder *irb, Scope *scope, AstNode *source_node,3854static IrInstSrc *ir_build_member_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3043 IrInstruction *container_type, IrInstruction *member_index)3855 IrInstSrc *container_type, IrInstSrc *member_index)
3044{3856{
3045 IrInstructionMemberName *instruction = ir_build_instruction<IrInstructionMemberName>(irb, scope, source_node);3857 IrInstSrcMemberName *instruction = ir_build_instruction<IrInstSrcMemberName>(irb, scope, source_node);
3046 instruction->container_type = container_type;3858 instruction->container_type = container_type;
3047 instruction->member_index = member_index;3859 instruction->member_index = member_index;
30483860
...@@ -3052,65 +3864,88 @@ static IrInstruction *ir_build_member_name(IrBuilder *irb, Scope *scope, AstNode...@@ -3052,65 +3864,88 @@ static IrInstruction *ir_build_member_name(IrBuilder *irb, Scope *scope, AstNode
3052 return &instruction->base;3864 return &instruction->base;
3053}3865}
30543866
3055static IrInstruction *ir_build_breakpoint(IrBuilder *irb, Scope *scope, AstNode *source_node) {3867static IrInstSrc *ir_build_breakpoint(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3056 IrInstructionBreakpoint *instruction = ir_build_instruction<IrInstructionBreakpoint>(irb, scope, source_node);3868 IrInstSrcBreakpoint *instruction = ir_build_instruction<IrInstSrcBreakpoint>(irb, scope, source_node);
3057 return &instruction->base;3869 return &instruction->base;
3058}3870}
30593871
3060static IrInstruction *ir_build_return_address(IrBuilder *irb, Scope *scope, AstNode *source_node) {3872static IrInstGen *ir_build_breakpoint_gen(IrAnalyze *ira, IrInst *source_instr) {
3061 IrInstructionReturnAddress *instruction = ir_build_instruction<IrInstructionReturnAddress>(irb, scope, source_node);3873 IrInstGenBreakpoint *instruction = ir_build_inst_void<IrInstGenBreakpoint>(&ira->new_irb,
3874 source_instr->scope, source_instr->source_node);
3062 return &instruction->base;3875 return &instruction->base;
3063}3876}
30643877
3065static IrInstruction *ir_build_frame_address(IrBuilder *irb, Scope *scope, AstNode *source_node) {3878static IrInstSrc *ir_build_return_address_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3066 IrInstructionFrameAddress *instruction = ir_build_instruction<IrInstructionFrameAddress>(irb, scope, source_node);3879 IrInstSrcReturnAddress *instruction = ir_build_instruction<IrInstSrcReturnAddress>(irb, scope, source_node);
3067 return &instruction->base;3880 return &instruction->base;
3068}3881}
30693882
3070static IrInstruction *ir_build_handle(IrBuilder *irb, Scope *scope, AstNode *source_node) {3883static IrInstGen *ir_build_return_address_gen(IrAnalyze *ira, IrInst *source_instr) {
3071 IrInstructionFrameHandle *instruction = ir_build_instruction<IrInstructionFrameHandle>(irb, scope, source_node);3884 IrInstGenReturnAddress *inst = ir_build_inst_gen<IrInstGenReturnAddress>(&ira->new_irb, source_instr->scope, source_instr->source_node);
3072 return &instruction->base;3885 inst->base.value->type = ira->codegen->builtin_types.entry_usize;
3886 return &inst->base;
3887}
3888
3889static IrInstSrc *ir_build_frame_address_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3890 IrInstSrcFrameAddress *inst = ir_build_instruction<IrInstSrcFrameAddress>(irb, scope, source_node);
3891 return &inst->base;
3892}
3893
3894static IrInstGen *ir_build_frame_address_gen(IrAnalyze *ira, IrInst *source_instr) {
3895 IrInstGenFrameAddress *inst = ir_build_inst_gen<IrInstGenFrameAddress>(&ira->new_irb, source_instr->scope, source_instr->source_node);
3896 inst->base.value->type = ira->codegen->builtin_types.entry_usize;
3897 return &inst->base;
3898}
3899
3900static IrInstSrc *ir_build_handle_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3901 IrInstSrcFrameHandle *inst = ir_build_instruction<IrInstSrcFrameHandle>(irb, scope, source_node);
3902 return &inst->base;
3903}
3904
3905static IrInstGen *ir_build_handle_gen(IrAnalyze *ira, IrInst *source_instr, ZigType *ty) {
3906 IrInstGenFrameHandle *inst = ir_build_inst_gen<IrInstGenFrameHandle>(&ira->new_irb, source_instr->scope, source_instr->source_node);
3907 inst->base.value->type = ty;
3908 return &inst->base;
3073}3909}
30743910
3075static IrInstruction *ir_build_frame_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn) {3911static IrInstSrc *ir_build_frame_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *fn) {
3076 IrInstructionFrameType *instruction = ir_build_instruction<IrInstructionFrameType>(irb, scope, source_node);3912 IrInstSrcFrameType *inst = ir_build_instruction<IrInstSrcFrameType>(irb, scope, source_node);
3077 instruction->fn = fn;3913 inst->fn = fn;
30783914
3079 ir_ref_instruction(fn, irb->current_basic_block);3915 ir_ref_instruction(fn, irb->current_basic_block);
30803916
3081 return &instruction->base;3917 return &inst->base;
3082}3918}
30833919
3084static IrInstruction *ir_build_frame_size_src(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn) {3920static IrInstSrc *ir_build_frame_size_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *fn) {
3085 IrInstructionFrameSizeSrc *instruction = ir_build_instruction<IrInstructionFrameSizeSrc>(irb, scope, source_node);3921 IrInstSrcFrameSize *inst = ir_build_instruction<IrInstSrcFrameSize>(irb, scope, source_node);
3086 instruction->fn = fn;3922 inst->fn = fn;
30873923
3088 ir_ref_instruction(fn, irb->current_basic_block);3924 ir_ref_instruction(fn, irb->current_basic_block);
30893925
3090 return &instruction->base;3926 return &inst->base;
3091}3927}
30923928
3093static IrInstruction *ir_build_frame_size_gen(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *fn)3929static IrInstGen *ir_build_frame_size_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *fn)
3094{3930{
3095 IrInstructionFrameSizeGen *instruction = ir_build_instruction<IrInstructionFrameSizeGen>(irb, scope, source_node);3931 IrInstGenFrameSize *inst = ir_build_inst_gen<IrInstGenFrameSize>(&ira->new_irb, source_instr->scope, source_instr->source_node);
3096 instruction->fn = fn;3932 inst->base.value->type = ira->codegen->builtin_types.entry_usize;
3933 inst->fn = fn;
30973934
3098 ir_ref_instruction(fn, irb->current_basic_block);3935 ir_ref_inst_gen(fn, ira->new_irb.current_basic_block);
30993936
3100 return &instruction->base;3937 return &inst->base;
3101}3938}
31023939
3103static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode *source_node,3940static IrInstSrc *ir_build_overflow_op_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3104 IrOverflowOp op, IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2,3941 IrOverflowOp op, IrInstSrc *type_value, IrInstSrc *op1, IrInstSrc *op2, IrInstSrc *result_ptr)
3105 IrInstruction *result_ptr, ZigType *result_ptr_type)
3106{3942{
3107 IrInstructionOverflowOp *instruction = ir_build_instruction<IrInstructionOverflowOp>(irb, scope, source_node);3943 IrInstSrcOverflowOp *instruction = ir_build_instruction<IrInstSrcOverflowOp>(irb, scope, source_node);
3108 instruction->op = op;3944 instruction->op = op;
3109 instruction->type_value = type_value;3945 instruction->type_value = type_value;
3110 instruction->op1 = op1;3946 instruction->op1 = op1;
3111 instruction->op2 = op2;3947 instruction->op2 = op2;
3112 instruction->result_ptr = result_ptr;3948 instruction->result_ptr = result_ptr;
3113 instruction->result_ptr_type = result_ptr_type;
31143949
3115 ir_ref_instruction(type_value, irb->current_basic_block);3950 ir_ref_instruction(type_value, irb->current_basic_block);
3116 ir_ref_instruction(op1, irb->current_basic_block);3951 ir_ref_instruction(op1, irb->current_basic_block);
...@@ -3120,49 +3955,30 @@ static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode...@@ -3120,49 +3955,30 @@ static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode
3120 return &instruction->base;3955 return &instruction->base;
3121}3956}
31223957
3958static IrInstGen *ir_build_overflow_op_gen(IrAnalyze *ira, IrInst *source_instr,
3959 IrOverflowOp op, IrInstGen *op1, IrInstGen *op2, IrInstGen *result_ptr,
3960 ZigType *result_ptr_type)
3961{
3962 IrInstGenOverflowOp *instruction = ir_build_inst_gen<IrInstGenOverflowOp>(&ira->new_irb,
3963 source_instr->scope, source_instr->source_node);
3964 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;
3965 instruction->op = op;
3966 instruction->op1 = op1;
3967 instruction->op2 = op2;
3968 instruction->result_ptr = result_ptr;
3969 instruction->result_ptr_type = result_ptr_type;
31233970
3124//TODO Powi, Pow, minnum, maxnum, maximum, minimum, copysign,3971 ir_ref_inst_gen(op1, ira->new_irb.current_basic_block);
3125// lround, llround, lrint, llrint3972 ir_ref_inst_gen(op2, ira->new_irb.current_basic_block);
3126// So far this is only non-complicated type functions.3973 ir_ref_inst_gen(result_ptr, ira->new_irb.current_basic_block);
3127const char *float_op_to_name(BuiltinFnId op) {3974
3128 switch (op) {3975 return &instruction->base;
3129 case BuiltinFnIdSqrt:
3130 return "sqrt";
3131 case BuiltinFnIdSin:
3132 return "sin";
3133 case BuiltinFnIdCos:
3134 return "cos";
3135 case BuiltinFnIdExp:
3136 return "exp";
3137 case BuiltinFnIdExp2:
3138 return "exp2";
3139 case BuiltinFnIdLog:
3140 return "log";
3141 case BuiltinFnIdLog10:
3142 return "log10";
3143 case BuiltinFnIdLog2:
3144 return "log2";
3145 case BuiltinFnIdFabs:
3146 return "fabs";
3147 case BuiltinFnIdFloor:
3148 return "floor";
3149 case BuiltinFnIdCeil:
3150 return "ceil";
3151 case BuiltinFnIdTrunc:
3152 return "trunc";
3153 case BuiltinFnIdNearbyInt:
3154 return "nearbyint";
3155 case BuiltinFnIdRound:
3156 return "round";
3157 default:
3158 zig_unreachable();
3159 }
3160}3976}
31613977
3162static IrInstruction *ir_build_float_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *operand,3978static IrInstSrc *ir_build_float_op_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *operand,
3163 BuiltinFnId fn_id)3979 BuiltinFnId fn_id)
3164{3980{
3165 IrInstructionFloatOp *instruction = ir_build_instruction<IrInstructionFloatOp>(irb, scope, source_node);3981 IrInstSrcFloatOp *instruction = ir_build_instruction<IrInstSrcFloatOp>(irb, scope, source_node);
3166 instruction->operand = operand;3982 instruction->operand = operand;
3167 instruction->fn_id = fn_id;3983 instruction->fn_id = fn_id;
31683984
...@@ -3171,9 +3987,24 @@ static IrInstruction *ir_build_float_op(IrBuilder *irb, Scope *scope, AstNode *s...@@ -3171,9 +3987,24 @@ static IrInstruction *ir_build_float_op(IrBuilder *irb, Scope *scope, AstNode *s
3171 return &instruction->base;3987 return &instruction->base;
3172}3988}
31733989
3174static IrInstruction *ir_build_mul_add(IrBuilder *irb, Scope *scope, AstNode *source_node,3990static IrInstGen *ir_build_float_op_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand,
3175 IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2, IrInstruction *op3) {3991 BuiltinFnId fn_id, ZigType *operand_type)
3176 IrInstructionMulAdd *instruction = ir_build_instruction<IrInstructionMulAdd>(irb, scope, source_node);3992{
3993 IrInstGenFloatOp *instruction = ir_build_inst_gen<IrInstGenFloatOp>(&ira->new_irb,
3994 source_instr->scope, source_instr->source_node);
3995 instruction->base.value->type = operand_type;
3996 instruction->operand = operand;
3997 instruction->fn_id = fn_id;
3998
3999 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
4000
4001 return &instruction->base;
4002}
4003
4004static IrInstSrc *ir_build_mul_add_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4005 IrInstSrc *type_value, IrInstSrc *op1, IrInstSrc *op2, IrInstSrc *op3)
4006{
4007 IrInstSrcMulAdd *instruction = ir_build_instruction<IrInstSrcMulAdd>(irb, scope, source_node);
3177 instruction->type_value = type_value;4008 instruction->type_value = type_value;
3178 instruction->op1 = op1;4009 instruction->op1 = op1;
3179 instruction->op2 = op2;4010 instruction->op2 = op2;
...@@ -3187,8 +4018,25 @@ static IrInstruction *ir_build_mul_add(IrBuilder *irb, Scope *scope, AstNode *so...@@ -3187,8 +4018,25 @@ static IrInstruction *ir_build_mul_add(IrBuilder *irb, Scope *scope, AstNode *so
3187 return &instruction->base;4018 return &instruction->base;
3188}4019}
31894020
3190static IrInstruction *ir_build_align_of(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_value) {4021static IrInstGen *ir_build_mul_add_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *op1, IrInstGen *op2,
3191 IrInstructionAlignOf *instruction = ir_build_instruction<IrInstructionAlignOf>(irb, scope, source_node);4022 IrInstGen *op3, ZigType *expr_type)
4023{
4024 IrInstGenMulAdd *instruction = ir_build_inst_gen<IrInstGenMulAdd>(&ira->new_irb,
4025 source_instr->scope, source_instr->source_node);
4026 instruction->base.value->type = expr_type;
4027 instruction->op1 = op1;
4028 instruction->op2 = op2;
4029 instruction->op3 = op3;
4030
4031 ir_ref_inst_gen(op1, ira->new_irb.current_basic_block);
4032 ir_ref_inst_gen(op2, ira->new_irb.current_basic_block);
4033 ir_ref_inst_gen(op3, ira->new_irb.current_basic_block);
4034
4035 return &instruction->base;
4036}
4037
4038static IrInstSrc *ir_build_align_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) {
4039 IrInstSrcAlignOf *instruction = ir_build_instruction<IrInstSrcAlignOf>(irb, scope, source_node);
3192 instruction->type_value = type_value;4040 instruction->type_value = type_value;
31934041
3194 ir_ref_instruction(type_value, irb->current_basic_block);4042 ir_ref_instruction(type_value, irb->current_basic_block);
...@@ -3196,10 +4044,10 @@ static IrInstruction *ir_build_align_of(IrBuilder *irb, Scope *scope, AstNode *s...@@ -3196,10 +4044,10 @@ static IrInstruction *ir_build_align_of(IrBuilder *irb, Scope *scope, AstNode *s
3196 return &instruction->base;4044 return &instruction->base;
3197}4045}
31984046
3199static IrInstruction *ir_build_test_err_src(IrBuilder *irb, Scope *scope, AstNode *source_node,4047static IrInstSrc *ir_build_test_err_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3200 IrInstruction *base_ptr, bool resolve_err_set, bool base_ptr_is_payload)4048 IrInstSrc *base_ptr, bool resolve_err_set, bool base_ptr_is_payload)
3201{4049{
3202 IrInstructionTestErrSrc *instruction = ir_build_instruction<IrInstructionTestErrSrc>(irb, scope, source_node);4050 IrInstSrcTestErr *instruction = ir_build_instruction<IrInstSrcTestErr>(irb, scope, source_node);
3203 instruction->base_ptr = base_ptr;4051 instruction->base_ptr = base_ptr;
3204 instruction->resolve_err_set = resolve_err_set;4052 instruction->resolve_err_set = resolve_err_set;
3205 instruction->base_ptr_is_payload = base_ptr_is_payload;4053 instruction->base_ptr_is_payload = base_ptr_is_payload;
...@@ -3209,48 +4057,72 @@ static IrInstruction *ir_build_test_err_src(IrBuilder *irb, Scope *scope, AstNod...@@ -3209,48 +4057,72 @@ static IrInstruction *ir_build_test_err_src(IrBuilder *irb, Scope *scope, AstNod
3209 return &instruction->base;4057 return &instruction->base;
3210}4058}
32114059
3212static IrInstruction *ir_build_test_err_gen(IrAnalyze *ira, IrInstruction *source_instruction,4060static IrInstGen *ir_build_test_err_gen(IrAnalyze *ira, IrInst *source_instruction, IrInstGen *err_union) {
3213 IrInstruction *err_union)4061 IrInstGenTestErr *instruction = ir_build_inst_gen<IrInstGenTestErr>(
3214{
3215 IrInstructionTestErrGen *instruction = ir_build_instruction<IrInstructionTestErrGen>(
3216 &ira->new_irb, source_instruction->scope, source_instruction->source_node);4062 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
3217 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;4063 instruction->base.value->type = ira->codegen->builtin_types.entry_bool;
3218 instruction->err_union = err_union;4064 instruction->err_union = err_union;
32194065
3220 ir_ref_instruction(err_union, ira->new_irb.current_basic_block);4066 ir_ref_inst_gen(err_union, ira->new_irb.current_basic_block);
32214067
3222 return &instruction->base;4068 return &instruction->base;
3223}4069}
32244070
3225static IrInstruction *ir_build_unwrap_err_code(IrBuilder *irb, Scope *scope, AstNode *source_node,4071static IrInstSrc *ir_build_unwrap_err_code_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3226 IrInstruction *err_union_ptr)4072 IrInstSrc *err_union_ptr)
3227{4073{
3228 IrInstructionUnwrapErrCode *instruction = ir_build_instruction<IrInstructionUnwrapErrCode>(irb, scope, source_node);4074 IrInstSrcUnwrapErrCode *inst = ir_build_instruction<IrInstSrcUnwrapErrCode>(irb, scope, source_node);
3229 instruction->err_union_ptr = err_union_ptr;4075 inst->err_union_ptr = err_union_ptr;
32304076
3231 ir_ref_instruction(err_union_ptr, irb->current_basic_block);4077 ir_ref_instruction(err_union_ptr, irb->current_basic_block);
32324078
3233 return &instruction->base;4079 return &inst->base;
3234}4080}
32354081
3236static IrInstruction *ir_build_unwrap_err_payload(IrBuilder *irb, Scope *scope, AstNode *source_node,4082static IrInstGen *ir_build_unwrap_err_code_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
3237 IrInstruction *value, bool safety_check_on, bool initializing)4083 IrInstGen *err_union_ptr, ZigType *result_type)
3238{4084{
3239 IrInstructionUnwrapErrPayload *instruction = ir_build_instruction<IrInstructionUnwrapErrPayload>(irb, scope, source_node);4085 IrInstGenUnwrapErrCode *inst = ir_build_inst_gen<IrInstGenUnwrapErrCode>(&ira->new_irb, scope, source_node);
3240 instruction->value = value;4086 inst->base.value->type = result_type;
3241 instruction->safety_check_on = safety_check_on;4087 inst->err_union_ptr = err_union_ptr;
3242 instruction->initializing = initializing;4088
4089 ir_ref_inst_gen(err_union_ptr, ira->new_irb.current_basic_block);
4090
4091 return &inst->base;
4092}
4093
4094static IrInstSrc *ir_build_unwrap_err_payload_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4095 IrInstSrc *value, bool safety_check_on, bool initializing)
4096{
4097 IrInstSrcUnwrapErrPayload *inst = ir_build_instruction<IrInstSrcUnwrapErrPayload>(irb, scope, source_node);
4098 inst->value = value;
4099 inst->safety_check_on = safety_check_on;
4100 inst->initializing = initializing;
32434101
3244 ir_ref_instruction(value, irb->current_basic_block);4102 ir_ref_instruction(value, irb->current_basic_block);
32454103
3246 return &instruction->base;4104 return &inst->base;
3247}4105}
32484106
3249static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *source_node,4107static IrInstGen *ir_build_unwrap_err_payload_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
3250 IrInstruction **param_types, IrInstruction *align_value, IrInstruction *callconv_value,4108 IrInstGen *value, bool safety_check_on, bool initializing, ZigType *result_type)
3251 IrInstruction *return_type, bool is_var_args)
3252{4109{
3253 IrInstructionFnProto *instruction = ir_build_instruction<IrInstructionFnProto>(irb, scope, source_node);4110 IrInstGenUnwrapErrPayload *inst = ir_build_inst_gen<IrInstGenUnwrapErrPayload>(&ira->new_irb, scope, source_node);
4111 inst->base.value->type = result_type;
4112 inst->value = value;
4113 inst->safety_check_on = safety_check_on;
4114 inst->initializing = initializing;
4115
4116 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
4117
4118 return &inst->base;
4119}
4120
4121static IrInstSrc *ir_build_fn_proto(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4122 IrInstSrc **param_types, IrInstSrc *align_value, IrInstSrc *callconv_value,
4123 IrInstSrc *return_type, bool is_var_args)
4124{
4125 IrInstSrcFnProto *instruction = ir_build_instruction<IrInstSrcFnProto>(irb, scope, source_node);
3254 instruction->param_types = param_types;4126 instruction->param_types = param_types;
3255 instruction->align_value = align_value;4127 instruction->align_value = align_value;
3256 instruction->callconv_value = callconv_value;4128 instruction->callconv_value = callconv_value;
...@@ -3270,8 +4142,8 @@ static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *s...@@ -3270,8 +4142,8 @@ static IrInstruction *ir_build_fn_proto(IrBuilder *irb, Scope *scope, AstNode *s
3270 return &instruction->base;4142 return &instruction->base;
3271}4143}
32724144
3273static IrInstruction *ir_build_test_comptime(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *value) {4145static IrInstSrc *ir_build_test_comptime(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *value) {
3274 IrInstructionTestComptime *instruction = ir_build_instruction<IrInstructionTestComptime>(irb, scope, source_node);4146 IrInstSrcTestComptime *instruction = ir_build_instruction<IrInstSrcTestComptime>(irb, scope, source_node);
3275 instruction->value = value;4147 instruction->value = value;
32764148
3277 ir_ref_instruction(value, irb->current_basic_block);4149 ir_ref_instruction(value, irb->current_basic_block);
...@@ -3279,10 +4151,10 @@ static IrInstruction *ir_build_test_comptime(IrBuilder *irb, Scope *scope, AstNo...@@ -3279,10 +4151,10 @@ static IrInstruction *ir_build_test_comptime(IrBuilder *irb, Scope *scope, AstNo
3279 return &instruction->base;4151 return &instruction->base;
3280}4152}
32814153
3282static IrInstruction *ir_build_ptr_cast_src(IrBuilder *irb, Scope *scope, AstNode *source_node,4154static IrInstSrc *ir_build_ptr_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3283 IrInstruction *dest_type, IrInstruction *ptr, bool safety_check_on)4155 IrInstSrc *dest_type, IrInstSrc *ptr, bool safety_check_on)
3284{4156{
3285 IrInstructionPtrCastSrc *instruction = ir_build_instruction<IrInstructionPtrCastSrc>(4157 IrInstSrcPtrCast *instruction = ir_build_instruction<IrInstSrcPtrCast>(
3286 irb, scope, source_node);4158 irb, scope, source_node);
3287 instruction->dest_type = dest_type;4159 instruction->dest_type = dest_type;
3288 instruction->ptr = ptr;4160 instruction->ptr = ptr;
...@@ -3294,39 +4166,24 @@ static IrInstruction *ir_build_ptr_cast_src(IrBuilder *irb, Scope *scope, AstNod...@@ -3294,39 +4166,24 @@ static IrInstruction *ir_build_ptr_cast_src(IrBuilder *irb, Scope *scope, AstNod
3294 return &instruction->base;4166 return &instruction->base;
3295}4167}
32964168
3297static IrInstruction *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInstruction *source_instruction,4169static IrInstGen *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInst *source_instruction,
3298 ZigType *ptr_type, IrInstruction *ptr, bool safety_check_on)4170 ZigType *ptr_type, IrInstGen *ptr, bool safety_check_on)
3299{4171{
3300 IrInstructionPtrCastGen *instruction = ir_build_instruction<IrInstructionPtrCastGen>(4172 IrInstGenPtrCast *instruction = ir_build_inst_gen<IrInstGenPtrCast>(
3301 &ira->new_irb, source_instruction->scope, source_instruction->source_node);4173 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
3302 instruction->base.value->type = ptr_type;4174 instruction->base.value->type = ptr_type;
3303 instruction->ptr = ptr;4175 instruction->ptr = ptr;
3304 instruction->safety_check_on = safety_check_on;4176 instruction->safety_check_on = safety_check_on;
33054177
3306 ir_ref_instruction(ptr, ira->new_irb.current_basic_block);4178 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
3307
3308 return &instruction->base;
3309}
3310
3311static IrInstruction *ir_build_load_ptr_gen(IrAnalyze *ira, IrInstruction *source_instruction,
3312 IrInstruction *ptr, ZigType *ty, IrInstruction *result_loc)
3313{
3314 IrInstructionLoadPtrGen *instruction = ir_build_instruction<IrInstructionLoadPtrGen>(
3315 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
3316 instruction->base.value->type = ty;
3317 instruction->ptr = ptr;
3318 instruction->result_loc = result_loc;
3319
3320 ir_ref_instruction(ptr, ira->new_irb.current_basic_block);
3321 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);
33224179
3323 return &instruction->base;4180 return &instruction->base;
3324}4181}
33254182
3326static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNode *source_node,4183static IrInstSrc *ir_build_implicit_cast(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3327 IrInstruction *operand, ResultLocCast *result_loc_cast)4184 IrInstSrc *operand, ResultLocCast *result_loc_cast)
3328{4185{
3329 IrInstructionImplicitCast *instruction = ir_build_instruction<IrInstructionImplicitCast>(irb, scope, source_node);4186 IrInstSrcImplicitCast *instruction = ir_build_instruction<IrInstSrcImplicitCast>(irb, scope, source_node);
3330 instruction->operand = operand;4187 instruction->operand = operand;
3331 instruction->result_loc_cast = result_loc_cast;4188 instruction->result_loc_cast = result_loc_cast;
33324189
...@@ -3335,10 +4192,10 @@ static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNo...@@ -3335,10 +4192,10 @@ static IrInstruction *ir_build_implicit_cast(IrBuilder *irb, Scope *scope, AstNo
3335 return &instruction->base;4192 return &instruction->base;
3336}4193}
33374194
3338static IrInstruction *ir_build_bit_cast_src(IrBuilder *irb, Scope *scope, AstNode *source_node,4195static IrInstSrc *ir_build_bit_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3339 IrInstruction *operand, ResultLocBitCast *result_loc_bit_cast)4196 IrInstSrc *operand, ResultLocBitCast *result_loc_bit_cast)
3340{4197{
3341 IrInstructionBitCastSrc *instruction = ir_build_instruction<IrInstructionBitCastSrc>(irb, scope, source_node);4198 IrInstSrcBitCast *instruction = ir_build_instruction<IrInstSrcBitCast>(irb, scope, source_node);
3342 instruction->operand = operand;4199 instruction->operand = operand;
3343 instruction->result_loc_bit_cast = result_loc_bit_cast;4200 instruction->result_loc_bit_cast = result_loc_bit_cast;
33444201
...@@ -3347,62 +4204,81 @@ static IrInstruction *ir_build_bit_cast_src(IrBuilder *irb, Scope *scope, AstNod...@@ -3347,62 +4204,81 @@ static IrInstruction *ir_build_bit_cast_src(IrBuilder *irb, Scope *scope, AstNod
3347 return &instruction->base;4204 return &instruction->base;
3348}4205}
33494206
3350static IrInstruction *ir_build_bit_cast_gen(IrAnalyze *ira, IrInstruction *source_instruction,4207static IrInstGen *ir_build_bit_cast_gen(IrAnalyze *ira, IrInst *source_instruction,
3351 IrInstruction *operand, ZigType *ty)4208 IrInstGen *operand, ZigType *ty)
3352{4209{
3353 IrInstructionBitCastGen *instruction = ir_build_instruction<IrInstructionBitCastGen>(4210 IrInstGenBitCast *instruction = ir_build_inst_gen<IrInstGenBitCast>(
3354 &ira->new_irb, source_instruction->scope, source_instruction->source_node);4211 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
3355 instruction->base.value->type = ty;4212 instruction->base.value->type = ty;
3356 instruction->operand = operand;4213 instruction->operand = operand;
33574214
3358 ir_ref_instruction(operand, ira->new_irb.current_basic_block);4215 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
33594216
3360 return &instruction->base;4217 return &instruction->base;
3361}4218}
33624219
3363static IrInstruction *ir_build_widen_or_shorten(IrBuilder *irb, Scope *scope, AstNode *source_node,4220static IrInstGen *ir_build_widen_or_shorten(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
3364 IrInstruction *target)4221 ZigType *result_type)
3365{4222{
3366 IrInstructionWidenOrShorten *instruction = ir_build_instruction<IrInstructionWidenOrShorten>(4223 IrInstGenWidenOrShorten *inst = ir_build_inst_gen<IrInstGenWidenOrShorten>(&ira->new_irb, scope, source_node);
3367 irb, scope, source_node);4224 inst->base.value->type = result_type;
3368 instruction->target = target;4225 inst->target = target;
33694226
3370 ir_ref_instruction(target, irb->current_basic_block);4227 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
33714228
3372 return &instruction->base;4229 return &inst->base;
3373}4230}
33744231
3375static IrInstruction *ir_build_int_to_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,4232static IrInstSrc *ir_build_int_to_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3376 IrInstruction *dest_type, IrInstruction *target)4233 IrInstSrc *dest_type, IrInstSrc *target)
3377{4234{
3378 IrInstructionIntToPtr *instruction = ir_build_instruction<IrInstructionIntToPtr>(4235 IrInstSrcIntToPtr *instruction = ir_build_instruction<IrInstSrcIntToPtr>(irb, scope, source_node);
3379 irb, scope, source_node);
3380 instruction->dest_type = dest_type;4236 instruction->dest_type = dest_type;
3381 instruction->target = target;4237 instruction->target = target;
33824238
3383 if (dest_type) ir_ref_instruction(dest_type, irb->current_basic_block);4239 ir_ref_instruction(dest_type, irb->current_basic_block);
3384 ir_ref_instruction(target, irb->current_basic_block);4240 ir_ref_instruction(target, irb->current_basic_block);
33854241
3386 return &instruction->base;4242 return &instruction->base;
3387}4243}
33884244
3389static IrInstruction *ir_build_ptr_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node,4245static IrInstGen *ir_build_int_to_ptr_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
3390 IrInstruction *target)4246 IrInstGen *target, ZigType *ptr_type)
3391{4247{
3392 IrInstructionPtrToInt *instruction = ir_build_instruction<IrInstructionPtrToInt>(4248 IrInstGenIntToPtr *instruction = ir_build_inst_gen<IrInstGenIntToPtr>(&ira->new_irb, scope, source_node);
3393 irb, scope, source_node);4249 instruction->base.value->type = ptr_type;
3394 instruction->target = target;4250 instruction->target = target;
33954251
3396 ir_ref_instruction(target, irb->current_basic_block);4252 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
33974253
3398 return &instruction->base;4254 return &instruction->base;
3399}4255}
34004256
3401static IrInstruction *ir_build_int_to_enum(IrBuilder *irb, Scope *scope, AstNode *source_node,4257static IrInstSrc *ir_build_ptr_to_int_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3402 IrInstruction *dest_type, IrInstruction *target)4258 IrInstSrc *target)
3403{4259{
3404 IrInstructionIntToEnum *instruction = ir_build_instruction<IrInstructionIntToEnum>(4260 IrInstSrcPtrToInt *inst = ir_build_instruction<IrInstSrcPtrToInt>(irb, scope, source_node);
3405 irb, scope, source_node);4261 inst->target = target;
4262
4263 ir_ref_instruction(target, irb->current_basic_block);
4264
4265 return &inst->base;
4266}
4267
4268static IrInstGen *ir_build_ptr_to_int_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target) {
4269 IrInstGenPtrToInt *inst = ir_build_inst_gen<IrInstGenPtrToInt>(&ira->new_irb, source_instr->scope, source_instr->source_node);
4270 inst->base.value->type = ira->codegen->builtin_types.entry_usize;
4271 inst->target = target;
4272
4273 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
4274
4275 return &inst->base;
4276}
4277
4278static IrInstSrc *ir_build_int_to_enum_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4279 IrInstSrc *dest_type, IrInstSrc *target)
4280{
4281 IrInstSrcIntToEnum *instruction = ir_build_instruction<IrInstSrcIntToEnum>(irb, scope, source_node);
3406 instruction->dest_type = dest_type;4282 instruction->dest_type = dest_type;
3407 instruction->target = target;4283 instruction->target = target;
34084284
...@@ -3412,12 +4288,22 @@ static IrInstruction *ir_build_int_to_enum(IrBuilder *irb, Scope *scope, AstNode...@@ -3412,12 +4288,22 @@ static IrInstruction *ir_build_int_to_enum(IrBuilder *irb, Scope *scope, AstNode
3412 return &instruction->base;4288 return &instruction->base;
3413}4289}
34144290
4291static IrInstGen *ir_build_int_to_enum_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
4292 ZigType *dest_type, IrInstGen *target)
4293{
4294 IrInstGenIntToEnum *instruction = ir_build_inst_gen<IrInstGenIntToEnum>(&ira->new_irb, scope, source_node);
4295 instruction->base.value->type = dest_type;
4296 instruction->target = target;
4297
4298 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
34154299
4300 return &instruction->base;
4301}
34164302
3417static IrInstruction *ir_build_enum_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node,4303static IrInstSrc *ir_build_enum_to_int(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3418 IrInstruction *target)4304 IrInstSrc *target)
3419{4305{
3420 IrInstructionEnumToInt *instruction = ir_build_instruction<IrInstructionEnumToInt>(4306 IrInstSrcEnumToInt *instruction = ir_build_instruction<IrInstSrcEnumToInt>(
3421 irb, scope, source_node);4307 irb, scope, source_node);
3422 instruction->target = target;4308 instruction->target = target;
34234309
...@@ -3426,11 +4312,10 @@ static IrInstruction *ir_build_enum_to_int(IrBuilder *irb, Scope *scope, AstNode...@@ -3426,11 +4312,10 @@ static IrInstruction *ir_build_enum_to_int(IrBuilder *irb, Scope *scope, AstNode
3426 return &instruction->base;4312 return &instruction->base;
3427}4313}
34284314
3429static IrInstruction *ir_build_int_to_err(IrBuilder *irb, Scope *scope, AstNode *source_node,4315static IrInstSrc *ir_build_int_to_err_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3430 IrInstruction *target)4316 IrInstSrc *target)
3431{4317{
3432 IrInstructionIntToErr *instruction = ir_build_instruction<IrInstructionIntToErr>(4318 IrInstSrcIntToErr *instruction = ir_build_instruction<IrInstSrcIntToErr>(irb, scope, source_node);
3433 irb, scope, source_node);
3434 instruction->target = target;4319 instruction->target = target;
34354320
3436 ir_ref_instruction(target, irb->current_basic_block);4321 ir_ref_instruction(target, irb->current_basic_block);
...@@ -3438,10 +4323,22 @@ static IrInstruction *ir_build_int_to_err(IrBuilder *irb, Scope *scope, AstNode...@@ -3438,10 +4323,22 @@ static IrInstruction *ir_build_int_to_err(IrBuilder *irb, Scope *scope, AstNode
3438 return &instruction->base;4323 return &instruction->base;
3439}4324}
34404325
3441static IrInstruction *ir_build_err_to_int(IrBuilder *irb, Scope *scope, AstNode *source_node,4326static IrInstGen *ir_build_int_to_err_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
3442 IrInstruction *target)4327 ZigType *wanted_type)
4328{
4329 IrInstGenIntToErr *instruction = ir_build_inst_gen<IrInstGenIntToErr>(&ira->new_irb, scope, source_node);
4330 instruction->base.value->type = wanted_type;
4331 instruction->target = target;
4332
4333 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
4334
4335 return &instruction->base;
4336}
4337
4338static IrInstSrc *ir_build_err_to_int_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4339 IrInstSrc *target)
3443{4340{
3444 IrInstructionErrToInt *instruction = ir_build_instruction<IrInstructionErrToInt>(4341 IrInstSrcErrToInt *instruction = ir_build_instruction<IrInstSrcErrToInt>(
3445 irb, scope, source_node);4342 irb, scope, source_node);
3446 instruction->target = target;4343 instruction->target = target;
34474344
...@@ -3450,11 +4347,23 @@ static IrInstruction *ir_build_err_to_int(IrBuilder *irb, Scope *scope, AstNode...@@ -3450,11 +4347,23 @@ static IrInstruction *ir_build_err_to_int(IrBuilder *irb, Scope *scope, AstNode
3450 return &instruction->base;4347 return &instruction->base;
3451}4348}
34524349
3453static IrInstruction *ir_build_check_switch_prongs(IrBuilder *irb, Scope *scope, AstNode *source_node,4350static IrInstGen *ir_build_err_to_int_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
3454 IrInstruction *target_value, IrInstructionCheckSwitchProngsRange *ranges, size_t range_count,4351 ZigType *wanted_type)
4352{
4353 IrInstGenErrToInt *instruction = ir_build_inst_gen<IrInstGenErrToInt>(&ira->new_irb, scope, source_node);
4354 instruction->base.value->type = wanted_type;
4355 instruction->target = target;
4356
4357 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
4358
4359 return &instruction->base;
4360}
4361
4362static IrInstSrc *ir_build_check_switch_prongs(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4363 IrInstSrc *target_value, IrInstSrcCheckSwitchProngsRange *ranges, size_t range_count,
3455 bool have_else_prong, bool have_underscore_prong)4364 bool have_else_prong, bool have_underscore_prong)
3456{4365{
3457 IrInstructionCheckSwitchProngs *instruction = ir_build_instruction<IrInstructionCheckSwitchProngs>(4366 IrInstSrcCheckSwitchProngs *instruction = ir_build_instruction<IrInstSrcCheckSwitchProngs>(
3458 irb, scope, source_node);4367 irb, scope, source_node);
3459 instruction->target_value = target_value;4368 instruction->target_value = target_value;
3460 instruction->ranges = ranges;4369 instruction->ranges = ranges;
...@@ -3471,10 +4380,10 @@ static IrInstruction *ir_build_check_switch_prongs(IrBuilder *irb, Scope *scope,...@@ -3471,10 +4380,10 @@ static IrInstruction *ir_build_check_switch_prongs(IrBuilder *irb, Scope *scope,
3471 return &instruction->base;4380 return &instruction->base;
3472}4381}
34734382
3474static IrInstruction *ir_build_check_statement_is_void(IrBuilder *irb, Scope *scope, AstNode *source_node,4383static IrInstSrc *ir_build_check_statement_is_void(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3475 IrInstruction* statement_value)4384 IrInstSrc* statement_value)
3476{4385{
3477 IrInstructionCheckStatementIsVoid *instruction = ir_build_instruction<IrInstructionCheckStatementIsVoid>(4386 IrInstSrcCheckStatementIsVoid *instruction = ir_build_instruction<IrInstSrcCheckStatementIsVoid>(
3478 irb, scope, source_node);4387 irb, scope, source_node);
3479 instruction->statement_value = statement_value;4388 instruction->statement_value = statement_value;
34804389
...@@ -3483,11 +4392,10 @@ static IrInstruction *ir_build_check_statement_is_void(IrBuilder *irb, Scope *sc...@@ -3483,11 +4392,10 @@ static IrInstruction *ir_build_check_statement_is_void(IrBuilder *irb, Scope *sc
3483 return &instruction->base;4392 return &instruction->base;
3484}4393}
34854394
3486static IrInstruction *ir_build_type_name(IrBuilder *irb, Scope *scope, AstNode *source_node,4395static IrInstSrc *ir_build_type_name(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3487 IrInstruction *type_value)4396 IrInstSrc *type_value)
3488{4397{
3489 IrInstructionTypeName *instruction = ir_build_instruction<IrInstructionTypeName>(4398 IrInstSrcTypeName *instruction = ir_build_instruction<IrInstSrcTypeName>(irb, scope, source_node);
3490 irb, scope, source_node);
3491 instruction->type_value = type_value;4399 instruction->type_value = type_value;
34924400
3493 ir_ref_instruction(type_value, irb->current_basic_block);4401 ir_ref_instruction(type_value, irb->current_basic_block);
...@@ -3495,18 +4403,17 @@ static IrInstruction *ir_build_type_name(IrBuilder *irb, Scope *scope, AstNode *...@@ -3495,18 +4403,17 @@ static IrInstruction *ir_build_type_name(IrBuilder *irb, Scope *scope, AstNode *
3495 return &instruction->base;4403 return &instruction->base;
3496}4404}
34974405
3498static IrInstruction *ir_build_decl_ref(IrBuilder *irb, Scope *scope, AstNode *source_node, Tld *tld, LVal lval) {4406static IrInstSrc *ir_build_decl_ref(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Tld *tld, LVal lval) {
3499 IrInstructionDeclRef *instruction = ir_build_instruction<IrInstructionDeclRef>(irb, scope, source_node);4407 IrInstSrcDeclRef *instruction = ir_build_instruction<IrInstSrcDeclRef>(irb, scope, source_node);
3500 instruction->tld = tld;4408 instruction->tld = tld;
3501 instruction->lval = lval;4409 instruction->lval = lval;
35024410
3503 return &instruction->base;4411 return &instruction->base;
3504}4412}
35054413
3506static IrInstruction *ir_build_panic(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) {4414static IrInstSrc *ir_build_panic_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *msg) {
3507 IrInstructionPanic *instruction = ir_build_instruction<IrInstructionPanic>(irb, scope, source_node);4415 IrInstSrcPanic *instruction = ir_build_instruction<IrInstSrcPanic>(irb, scope, source_node);
3508 instruction->base.value->special = ConstValSpecialStatic;4416 instruction->base.is_noreturn = true;
3509 instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable;
3510 instruction->msg = msg;4417 instruction->msg = msg;
35114418
3512 ir_ref_instruction(msg, irb->current_basic_block);4419 ir_ref_instruction(msg, irb->current_basic_block);
...@@ -3514,10 +4421,18 @@ static IrInstruction *ir_build_panic(IrBuilder *irb, Scope *scope, AstNode *sour...@@ -3514,10 +4421,18 @@ static IrInstruction *ir_build_panic(IrBuilder *irb, Scope *scope, AstNode *sour
3514 return &instruction->base;4421 return &instruction->base;
3515}4422}
35164423
3517static IrInstruction *ir_build_tag_name(IrBuilder *irb, Scope *scope, AstNode *source_node,4424static IrInstGen *ir_build_panic_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *msg) {
3518 IrInstruction *target)4425 IrInstGenPanic *instruction = ir_build_inst_noreturn<IrInstGenPanic>(&ira->new_irb,
3519{4426 source_instr->scope, source_instr->source_node);
3520 IrInstructionTagName *instruction = ir_build_instruction<IrInstructionTagName>(irb, scope, source_node);4427 instruction->msg = msg;
4428
4429 ir_ref_inst_gen(msg, ira->new_irb.current_basic_block);
4430
4431 return &instruction->base;
4432}
4433
4434static IrInstSrc *ir_build_tag_name_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *target) {
4435 IrInstSrcTagName *instruction = ir_build_instruction<IrInstSrcTagName>(irb, scope, source_node);
3521 instruction->target = target;4436 instruction->target = target;
35224437
3523 ir_ref_instruction(target, irb->current_basic_block);4438 ir_ref_instruction(target, irb->current_basic_block);
...@@ -3525,10 +4440,23 @@ static IrInstruction *ir_build_tag_name(IrBuilder *irb, Scope *scope, AstNode *s...@@ -3525,10 +4440,23 @@ static IrInstruction *ir_build_tag_name(IrBuilder *irb, Scope *scope, AstNode *s
3525 return &instruction->base;4440 return &instruction->base;
3526}4441}
35274442
3528static IrInstruction *ir_build_tag_type(IrBuilder *irb, Scope *scope, AstNode *source_node,4443static IrInstGen *ir_build_tag_name_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target,
3529 IrInstruction *target)4444 ZigType *result_type)
3530{4445{
3531 IrInstructionTagType *instruction = ir_build_instruction<IrInstructionTagType>(irb, scope, source_node);4446 IrInstGenTagName *instruction = ir_build_inst_gen<IrInstGenTagName>(&ira->new_irb,
4447 source_instr->scope, source_instr->source_node);
4448 instruction->base.value->type = result_type;
4449 instruction->target = target;
4450
4451 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
4452
4453 return &instruction->base;
4454}
4455
4456static IrInstSrc *ir_build_tag_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4457 IrInstSrc *target)
4458{
4459 IrInstSrcTagType *instruction = ir_build_instruction<IrInstSrcTagType>(irb, scope, source_node);
3532 instruction->target = target;4460 instruction->target = target;
35334461
3534 ir_ref_instruction(target, irb->current_basic_block);4462 ir_ref_instruction(target, irb->current_basic_block);
...@@ -3536,27 +4464,40 @@ static IrInstruction *ir_build_tag_type(IrBuilder *irb, Scope *scope, AstNode *s...@@ -3536,27 +4464,40 @@ static IrInstruction *ir_build_tag_type(IrBuilder *irb, Scope *scope, AstNode *s
3536 return &instruction->base;4464 return &instruction->base;
3537}4465}
35384466
3539static IrInstruction *ir_build_field_parent_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node,4467static IrInstSrc *ir_build_field_parent_ptr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3540 IrInstruction *type_value, IrInstruction *field_name, IrInstruction *field_ptr, TypeStructField *field)4468 IrInstSrc *type_value, IrInstSrc *field_name, IrInstSrc *field_ptr)
3541{4469{
3542 IrInstructionFieldParentPtr *instruction = ir_build_instruction<IrInstructionFieldParentPtr>(4470 IrInstSrcFieldParentPtr *inst = ir_build_instruction<IrInstSrcFieldParentPtr>(
3543 irb, scope, source_node);4471 irb, scope, source_node);
3544 instruction->type_value = type_value;4472 inst->type_value = type_value;
3545 instruction->field_name = field_name;4473 inst->field_name = field_name;
3546 instruction->field_ptr = field_ptr;4474 inst->field_ptr = field_ptr;
3547 instruction->field = field;
35484475
3549 ir_ref_instruction(type_value, irb->current_basic_block);4476 ir_ref_instruction(type_value, irb->current_basic_block);
3550 ir_ref_instruction(field_name, irb->current_basic_block);4477 ir_ref_instruction(field_name, irb->current_basic_block);
3551 ir_ref_instruction(field_ptr, irb->current_basic_block);4478 ir_ref_instruction(field_ptr, irb->current_basic_block);
35524479
3553 return &instruction->base;4480 return &inst->base;
3554}4481}
35554482
3556static IrInstruction *ir_build_byte_offset_of(IrBuilder *irb, Scope *scope, AstNode *source_node,4483static IrInstGen *ir_build_field_parent_ptr_gen(IrAnalyze *ira, IrInst *source_instr,
3557 IrInstruction *type_value, IrInstruction *field_name)4484 IrInstGen *field_ptr, TypeStructField *field, ZigType *result_type)
3558{4485{
3559 IrInstructionByteOffsetOf *instruction = ir_build_instruction<IrInstructionByteOffsetOf>(irb, scope, source_node);4486 IrInstGenFieldParentPtr *inst = ir_build_inst_gen<IrInstGenFieldParentPtr>(&ira->new_irb,
4487 source_instr->scope, source_instr->source_node);
4488 inst->base.value->type = result_type;
4489 inst->field_ptr = field_ptr;
4490 inst->field = field;
4491
4492 ir_ref_inst_gen(field_ptr, ira->new_irb.current_basic_block);
4493
4494 return &inst->base;
4495}
4496
4497static IrInstSrc *ir_build_byte_offset_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4498 IrInstSrc *type_value, IrInstSrc *field_name)
4499{
4500 IrInstSrcByteOffsetOf *instruction = ir_build_instruction<IrInstSrcByteOffsetOf>(irb, scope, source_node);
3560 instruction->type_value = type_value;4501 instruction->type_value = type_value;
3561 instruction->field_name = field_name;4502 instruction->field_name = field_name;
35624503
...@@ -3566,10 +4507,10 @@ static IrInstruction *ir_build_byte_offset_of(IrBuilder *irb, Scope *scope, AstN...@@ -3566,10 +4507,10 @@ static IrInstruction *ir_build_byte_offset_of(IrBuilder *irb, Scope *scope, AstN
3566 return &instruction->base;4507 return &instruction->base;
3567}4508}
35684509
3569static IrInstruction *ir_build_bit_offset_of(IrBuilder *irb, Scope *scope, AstNode *source_node,4510static IrInstSrc *ir_build_bit_offset_of(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3570 IrInstruction *type_value, IrInstruction *field_name)4511 IrInstSrc *type_value, IrInstSrc *field_name)
3571{4512{
3572 IrInstructionBitOffsetOf *instruction = ir_build_instruction<IrInstructionBitOffsetOf>(irb, scope, source_node);4513 IrInstSrcBitOffsetOf *instruction = ir_build_instruction<IrInstSrcBitOffsetOf>(irb, scope, source_node);
3573 instruction->type_value = type_value;4514 instruction->type_value = type_value;
3574 instruction->field_name = field_name;4515 instruction->field_name = field_name;
35754516
...@@ -3579,9 +4520,8 @@ static IrInstruction *ir_build_bit_offset_of(IrBuilder *irb, Scope *scope, AstNo...@@ -3579,9 +4520,8 @@ static IrInstruction *ir_build_bit_offset_of(IrBuilder *irb, Scope *scope, AstNo
3579 return &instruction->base;4520 return &instruction->base;
3580}4521}
35814522
3582static IrInstruction *ir_build_type_info(IrBuilder *irb, Scope *scope, AstNode *source_node,4523static IrInstSrc *ir_build_type_info(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) {
3583 IrInstruction *type_value) {4524 IrInstSrcTypeInfo *instruction = ir_build_instruction<IrInstSrcTypeInfo>(irb, scope, source_node);
3584 IrInstructionTypeInfo *instruction = ir_build_instruction<IrInstructionTypeInfo>(irb, scope, source_node);
3585 instruction->type_value = type_value;4525 instruction->type_value = type_value;
35864526
3587 ir_ref_instruction(type_value, irb->current_basic_block);4527 ir_ref_instruction(type_value, irb->current_basic_block);
...@@ -3589,8 +4529,8 @@ static IrInstruction *ir_build_type_info(IrBuilder *irb, Scope *scope, AstNode *...@@ -3589,8 +4529,8 @@ static IrInstruction *ir_build_type_info(IrBuilder *irb, Scope *scope, AstNode *
3589 return &instruction->base;4529 return &instruction->base;
3590}4530}
35914531
3592static IrInstruction *ir_build_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_info) {4532static IrInstSrc *ir_build_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_info) {
3593 IrInstructionType *instruction = ir_build_instruction<IrInstructionType>(irb, scope, source_node);4533 IrInstSrcType *instruction = ir_build_instruction<IrInstSrcType>(irb, scope, source_node);
3594 instruction->type_info = type_info;4534 instruction->type_info = type_info;
35954535
3596 ir_ref_instruction(type_info, irb->current_basic_block);4536 ir_ref_instruction(type_info, irb->current_basic_block);
...@@ -3598,10 +4538,8 @@ static IrInstruction *ir_build_type(IrBuilder *irb, Scope *scope, AstNode *sourc...@@ -3598,10 +4538,8 @@ static IrInstruction *ir_build_type(IrBuilder *irb, Scope *scope, AstNode *sourc
3598 return &instruction->base;4538 return &instruction->base;
3599}4539}
36004540
3601static IrInstruction *ir_build_type_id(IrBuilder *irb, Scope *scope, AstNode *source_node,4541static IrInstSrc *ir_build_type_id(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *type_value) {
3602 IrInstruction *type_value)4542 IrInstSrcTypeId *instruction = ir_build_instruction<IrInstSrcTypeId>(irb, scope, source_node);
3603{
3604 IrInstructionTypeId *instruction = ir_build_instruction<IrInstructionTypeId>(irb, scope, source_node);
3605 instruction->type_value = type_value;4543 instruction->type_value = type_value;
36064544
3607 ir_ref_instruction(type_value, irb->current_basic_block);4545 ir_ref_instruction(type_value, irb->current_basic_block);
...@@ -3609,10 +4547,10 @@ static IrInstruction *ir_build_type_id(IrBuilder *irb, Scope *scope, AstNode *so...@@ -3609,10 +4547,10 @@ static IrInstruction *ir_build_type_id(IrBuilder *irb, Scope *scope, AstNode *so
3609 return &instruction->base;4547 return &instruction->base;
3610}4548}
36114549
3612static IrInstruction *ir_build_set_eval_branch_quota(IrBuilder *irb, Scope *scope, AstNode *source_node,4550static IrInstSrc *ir_build_set_eval_branch_quota(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3613 IrInstruction *new_quota)4551 IrInstSrc *new_quota)
3614{4552{
3615 IrInstructionSetEvalBranchQuota *instruction = ir_build_instruction<IrInstructionSetEvalBranchQuota>(irb, scope, source_node);4553 IrInstSrcSetEvalBranchQuota *instruction = ir_build_instruction<IrInstSrcSetEvalBranchQuota>(irb, scope, source_node);
3616 instruction->new_quota = new_quota;4554 instruction->new_quota = new_quota;
36174555
3618 ir_ref_instruction(new_quota, irb->current_basic_block);4556 ir_ref_instruction(new_quota, irb->current_basic_block);
...@@ -3620,23 +4558,35 @@ static IrInstruction *ir_build_set_eval_branch_quota(IrBuilder *irb, Scope *scop...@@ -3620,23 +4558,35 @@ static IrInstruction *ir_build_set_eval_branch_quota(IrBuilder *irb, Scope *scop
3620 return &instruction->base;4558 return &instruction->base;
3621}4559}
36224560
3623static IrInstruction *ir_build_align_cast(IrBuilder *irb, Scope *scope, AstNode *source_node,4561static IrInstSrc *ir_build_align_cast_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3624 IrInstruction *align_bytes, IrInstruction *target)4562 IrInstSrc *align_bytes, IrInstSrc *target)
3625{4563{
3626 IrInstructionAlignCast *instruction = ir_build_instruction<IrInstructionAlignCast>(irb, scope, source_node);4564 IrInstSrcAlignCast *instruction = ir_build_instruction<IrInstSrcAlignCast>(irb, scope, source_node);
3627 instruction->align_bytes = align_bytes;4565 instruction->align_bytes = align_bytes;
3628 instruction->target = target;4566 instruction->target = target;
36294567
3630 if (align_bytes) ir_ref_instruction(align_bytes, irb->current_basic_block);4568 ir_ref_instruction(align_bytes, irb->current_basic_block);
3631 ir_ref_instruction(target, irb->current_basic_block);4569 ir_ref_instruction(target, irb->current_basic_block);
36324570
3633 return &instruction->base;4571 return &instruction->base;
3634}4572}
36354573
3636static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstNode *source_node,4574static IrInstGen *ir_build_align_cast_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node, IrInstGen *target,
3637 ResultLoc *result_loc, IrInstruction *ty)4575 ZigType *result_type)
4576{
4577 IrInstGenAlignCast *instruction = ir_build_inst_gen<IrInstGenAlignCast>(&ira->new_irb, scope, source_node);
4578 instruction->base.value->type = result_type;
4579 instruction->target = target;
4580
4581 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
4582
4583 return &instruction->base;
4584}
4585
4586static IrInstSrc *ir_build_resolve_result(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4587 ResultLoc *result_loc, IrInstSrc *ty)
3638{4588{
3639 IrInstructionResolveResult *instruction = ir_build_instruction<IrInstructionResolveResult>(irb, scope, source_node);4589 IrInstSrcResolveResult *instruction = ir_build_instruction<IrInstSrcResolveResult>(irb, scope, source_node);
3640 instruction->result_loc = result_loc;4590 instruction->result_loc = result_loc;
3641 instruction->ty = ty;4591 instruction->ty = ty;
36424592
...@@ -3645,25 +4595,26 @@ static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstN...@@ -3645,25 +4595,26 @@ static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstN
3645 return &instruction->base;4595 return &instruction->base;
3646}4596}
36474597
3648static IrInstruction *ir_build_reset_result(IrBuilder *irb, Scope *scope, AstNode *source_node,4598static IrInstSrc *ir_build_reset_result(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3649 ResultLoc *result_loc)4599 ResultLoc *result_loc)
3650{4600{
3651 IrInstructionResetResult *instruction = ir_build_instruction<IrInstructionResetResult>(irb, scope, source_node);4601 IrInstSrcResetResult *instruction = ir_build_instruction<IrInstSrcResetResult>(irb, scope, source_node);
3652 instruction->result_loc = result_loc;4602 instruction->result_loc = result_loc;
4603 instruction->base.is_gen = true;
36534604
3654 return &instruction->base;4605 return &instruction->base;
3655}4606}
36564607
3657static IrInstruction *ir_build_opaque_type(IrBuilder *irb, Scope *scope, AstNode *source_node) {4608static IrInstSrc *ir_build_opaque_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3658 IrInstructionOpaqueType *instruction = ir_build_instruction<IrInstructionOpaqueType>(irb, scope, source_node);4609 IrInstSrcOpaqueType *instruction = ir_build_instruction<IrInstSrcOpaqueType>(irb, scope, source_node);
36594610
3660 return &instruction->base;4611 return &instruction->base;
3661}4612}
36624613
3663static IrInstruction *ir_build_set_align_stack(IrBuilder *irb, Scope *scope, AstNode *source_node,4614static IrInstSrc *ir_build_set_align_stack(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3664 IrInstruction *align_bytes)4615 IrInstSrc *align_bytes)
3665{4616{
3666 IrInstructionSetAlignStack *instruction = ir_build_instruction<IrInstructionSetAlignStack>(irb, scope, source_node);4617 IrInstSrcSetAlignStack *instruction = ir_build_instruction<IrInstSrcSetAlignStack>(irb, scope, source_node);
3667 instruction->align_bytes = align_bytes;4618 instruction->align_bytes = align_bytes;
36684619
3669 ir_ref_instruction(align_bytes, irb->current_basic_block);4620 ir_ref_instruction(align_bytes, irb->current_basic_block);
...@@ -3671,10 +4622,10 @@ static IrInstruction *ir_build_set_align_stack(IrBuilder *irb, Scope *scope, Ast...@@ -3671,10 +4622,10 @@ static IrInstruction *ir_build_set_align_stack(IrBuilder *irb, Scope *scope, Ast
3671 return &instruction->base;4622 return &instruction->base;
3672}4623}
36734624
3674static IrInstruction *ir_build_arg_type(IrBuilder *irb, Scope *scope, AstNode *source_node,4625static IrInstSrc *ir_build_arg_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3675 IrInstruction *fn_type, IrInstruction *arg_index, bool allow_var)4626 IrInstSrc *fn_type, IrInstSrc *arg_index, bool allow_var)
3676{4627{
3677 IrInstructionArgType *instruction = ir_build_instruction<IrInstructionArgType>(irb, scope, source_node);4628 IrInstSrcArgType *instruction = ir_build_instruction<IrInstSrcArgType>(irb, scope, source_node);
3678 instruction->fn_type = fn_type;4629 instruction->fn_type = fn_type;
3679 instruction->arg_index = arg_index;4630 instruction->arg_index = arg_index;
3680 instruction->allow_var = allow_var;4631 instruction->allow_var = allow_var;
...@@ -3685,17 +4636,29 @@ static IrInstruction *ir_build_arg_type(IrBuilder *irb, Scope *scope, AstNode *s...@@ -3685,17 +4636,29 @@ static IrInstruction *ir_build_arg_type(IrBuilder *irb, Scope *scope, AstNode *s
3685 return &instruction->base;4636 return &instruction->base;
3686}4637}
36874638
3688static IrInstruction *ir_build_error_return_trace(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstructionErrorReturnTrace::Optional optional) {4639static IrInstSrc *ir_build_error_return_trace_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3689 IrInstructionErrorReturnTrace *instruction = ir_build_instruction<IrInstructionErrorReturnTrace>(irb, scope, source_node);4640 IrInstErrorReturnTraceOptional optional)
3690 instruction->optional = optional;4641{
4642 IrInstSrcErrorReturnTrace *inst = ir_build_instruction<IrInstSrcErrorReturnTrace>(irb, scope, source_node);
4643 inst->optional = optional;
36914644
3692 return &instruction->base;4645 return &inst->base;
4646}
4647
4648static IrInstGen *ir_build_error_return_trace_gen(IrAnalyze *ira, Scope *scope, AstNode *source_node,
4649 IrInstErrorReturnTraceOptional optional, ZigType *result_type)
4650{
4651 IrInstGenErrorReturnTrace *inst = ir_build_inst_gen<IrInstGenErrorReturnTrace>(&ira->new_irb, scope, source_node);
4652 inst->base.value->type = result_type;
4653 inst->optional = optional;
4654
4655 return &inst->base;
3693}4656}
36944657
3695static IrInstruction *ir_build_error_union(IrBuilder *irb, Scope *scope, AstNode *source_node,4658static IrInstSrc *ir_build_error_union(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3696 IrInstruction *err_set, IrInstruction *payload)4659 IrInstSrc *err_set, IrInstSrc *payload)
3697{4660{
3698 IrInstructionErrorUnion *instruction = ir_build_instruction<IrInstructionErrorUnion>(irb, scope, source_node);4661 IrInstSrcErrorUnion *instruction = ir_build_instruction<IrInstSrcErrorUnion>(irb, scope, source_node);
3699 instruction->err_set = err_set;4662 instruction->err_set = err_set;
3700 instruction->payload = payload;4663 instruction->payload = payload;
37014664
...@@ -3705,85 +4668,130 @@ static IrInstruction *ir_build_error_union(IrBuilder *irb, Scope *scope, AstNode...@@ -3705,85 +4668,130 @@ static IrInstruction *ir_build_error_union(IrBuilder *irb, Scope *scope, AstNode
3705 return &instruction->base;4668 return &instruction->base;
3706}4669}
37074670
3708static IrInstruction *ir_build_atomic_rmw(IrBuilder *irb, Scope *scope, AstNode *source_node,4671static IrInstSrc *ir_build_atomic_rmw_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3709 IrInstruction *operand_type, IrInstruction *ptr, IrInstruction *op, IrInstruction *operand,4672 IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *op, IrInstSrc *operand,
3710 IrInstruction *ordering, AtomicRmwOp resolved_op, AtomicOrder resolved_ordering)4673 IrInstSrc *ordering)
3711{4674{
3712 IrInstructionAtomicRmw *instruction = ir_build_instruction<IrInstructionAtomicRmw>(irb, scope, source_node);4675 IrInstSrcAtomicRmw *instruction = ir_build_instruction<IrInstSrcAtomicRmw>(irb, scope, source_node);
3713 instruction->operand_type = operand_type;4676 instruction->operand_type = operand_type;
3714 instruction->ptr = ptr;4677 instruction->ptr = ptr;
3715 instruction->op = op;4678 instruction->op = op;
3716 instruction->operand = operand;4679 instruction->operand = operand;
3717 instruction->ordering = ordering;4680 instruction->ordering = ordering;
3718 instruction->resolved_op = resolved_op;
3719 instruction->resolved_ordering = resolved_ordering;
37204681
3721 if (operand_type != nullptr) ir_ref_instruction(operand_type, irb->current_basic_block);4682 ir_ref_instruction(operand_type, irb->current_basic_block);
3722 ir_ref_instruction(ptr, irb->current_basic_block);4683 ir_ref_instruction(ptr, irb->current_basic_block);
3723 if (op != nullptr) ir_ref_instruction(op, irb->current_basic_block);4684 ir_ref_instruction(op, irb->current_basic_block);
3724 ir_ref_instruction(operand, irb->current_basic_block);4685 ir_ref_instruction(operand, irb->current_basic_block);
3725 if (ordering != nullptr) ir_ref_instruction(ordering, irb->current_basic_block);4686 ir_ref_instruction(ordering, irb->current_basic_block);
4687
4688 return &instruction->base;
4689}
4690
4691static IrInstGen *ir_build_atomic_rmw_gen(IrAnalyze *ira, IrInst *source_instr,
4692 IrInstGen *ptr, IrInstGen *operand, AtomicRmwOp op, AtomicOrder ordering, ZigType *operand_type)
4693{
4694 IrInstGenAtomicRmw *instruction = ir_build_inst_gen<IrInstGenAtomicRmw>(&ira->new_irb, source_instr->scope, source_instr->source_node);
4695 instruction->base.value->type = operand_type;
4696 instruction->ptr = ptr;
4697 instruction->op = op;
4698 instruction->operand = operand;
4699 instruction->ordering = ordering;
4700
4701 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
4702 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
37264703
3727 return &instruction->base;4704 return &instruction->base;
3728}4705}
37294706
3730static IrInstruction *ir_build_atomic_load(IrBuilder *irb, Scope *scope, AstNode *source_node,4707static IrInstSrc *ir_build_atomic_load_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3731 IrInstruction *operand_type, IrInstruction *ptr,4708 IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *ordering)
3732 IrInstruction *ordering, AtomicOrder resolved_ordering)
3733{4709{
3734 IrInstructionAtomicLoad *instruction = ir_build_instruction<IrInstructionAtomicLoad>(irb, scope, source_node);4710 IrInstSrcAtomicLoad *instruction = ir_build_instruction<IrInstSrcAtomicLoad>(irb, scope, source_node);
3735 instruction->operand_type = operand_type;4711 instruction->operand_type = operand_type;
3736 instruction->ptr = ptr;4712 instruction->ptr = ptr;
3737 instruction->ordering = ordering;4713 instruction->ordering = ordering;
3738 instruction->resolved_ordering = resolved_ordering;
37394714
3740 if (operand_type != nullptr) ir_ref_instruction(operand_type, irb->current_basic_block);4715 ir_ref_instruction(operand_type, irb->current_basic_block);
3741 ir_ref_instruction(ptr, irb->current_basic_block);4716 ir_ref_instruction(ptr, irb->current_basic_block);
3742 if (ordering != nullptr) ir_ref_instruction(ordering, irb->current_basic_block);4717 ir_ref_instruction(ordering, irb->current_basic_block);
4718
4719 return &instruction->base;
4720}
4721
4722static IrInstGen *ir_build_atomic_load_gen(IrAnalyze *ira, IrInst *source_instr,
4723 IrInstGen *ptr, AtomicOrder ordering, ZigType *operand_type)
4724{
4725 IrInstGenAtomicLoad *instruction = ir_build_inst_gen<IrInstGenAtomicLoad>(&ira->new_irb,
4726 source_instr->scope, source_instr->source_node);
4727 instruction->base.value->type = operand_type;
4728 instruction->ptr = ptr;
4729 instruction->ordering = ordering;
4730
4731 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
37434732
3744 return &instruction->base;4733 return &instruction->base;
3745}4734}
37464735
3747static IrInstruction *ir_build_atomic_store(IrBuilder *irb, Scope *scope, AstNode *source_node,4736static IrInstSrc *ir_build_atomic_store_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3748 IrInstruction *operand_type, IrInstruction *ptr, IrInstruction *value,4737 IrInstSrc *operand_type, IrInstSrc *ptr, IrInstSrc *value, IrInstSrc *ordering)
3749 IrInstruction *ordering, AtomicOrder resolved_ordering)
3750{4738{
3751 IrInstructionAtomicStore *instruction = ir_build_instruction<IrInstructionAtomicStore>(irb, scope, source_node);4739 IrInstSrcAtomicStore *instruction = ir_build_instruction<IrInstSrcAtomicStore>(irb, scope, source_node);
3752 instruction->operand_type = operand_type;4740 instruction->operand_type = operand_type;
3753 instruction->ptr = ptr;4741 instruction->ptr = ptr;
3754 instruction->value = value;4742 instruction->value = value;
3755 instruction->ordering = ordering;4743 instruction->ordering = ordering;
3756 instruction->resolved_ordering = resolved_ordering;
37574744
3758 if (operand_type != nullptr) ir_ref_instruction(operand_type, irb->current_basic_block);4745 ir_ref_instruction(operand_type, irb->current_basic_block);
3759 ir_ref_instruction(ptr, irb->current_basic_block);4746 ir_ref_instruction(ptr, irb->current_basic_block);
3760 ir_ref_instruction(value, irb->current_basic_block);4747 ir_ref_instruction(value, irb->current_basic_block);
3761 if (ordering != nullptr) ir_ref_instruction(ordering, irb->current_basic_block);4748 ir_ref_instruction(ordering, irb->current_basic_block);
37624749
3763 return &instruction->base;4750 return &instruction->base;
3764}4751}
37654752
3766static IrInstruction *ir_build_save_err_ret_addr(IrBuilder *irb, Scope *scope, AstNode *source_node) {4753static IrInstGen *ir_build_atomic_store_gen(IrAnalyze *ira, IrInst *source_instr,
3767 IrInstructionSaveErrRetAddr *instruction = ir_build_instruction<IrInstructionSaveErrRetAddr>(irb, scope, source_node);4754 IrInstGen *ptr, IrInstGen *value, AtomicOrder ordering)
4755{
4756 IrInstGenAtomicStore *instruction = ir_build_inst_void<IrInstGenAtomicStore>(&ira->new_irb,
4757 source_instr->scope, source_instr->source_node);
4758 instruction->ptr = ptr;
4759 instruction->value = value;
4760 instruction->ordering = ordering;
4761
4762 ir_ref_inst_gen(ptr, ira->new_irb.current_basic_block);
4763 ir_ref_inst_gen(value, ira->new_irb.current_basic_block);
4764
3768 return &instruction->base;4765 return &instruction->base;
3769}4766}
37704767
3771static IrInstruction *ir_build_add_implicit_return_type(IrBuilder *irb, Scope *scope, AstNode *source_node,4768static IrInstSrc *ir_build_save_err_ret_addr_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3772 IrInstruction *value, ResultLocReturn *result_loc_ret)4769 IrInstSrcSaveErrRetAddr *inst = ir_build_instruction<IrInstSrcSaveErrRetAddr>(irb, scope, source_node);
4770 return &inst->base;
4771}
4772
4773static IrInstGen *ir_build_save_err_ret_addr_gen(IrAnalyze *ira, IrInst *source_instr) {
4774 IrInstGenSaveErrRetAddr *inst = ir_build_inst_void<IrInstGenSaveErrRetAddr>(&ira->new_irb,
4775 source_instr->scope, source_instr->source_node);
4776 return &inst->base;
4777}
4778
4779static IrInstSrc *ir_build_add_implicit_return_type(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
4780 IrInstSrc *value, ResultLocReturn *result_loc_ret)
3773{4781{
3774 IrInstructionAddImplicitReturnType *instruction = ir_build_instruction<IrInstructionAddImplicitReturnType>(irb, scope, source_node);4782 IrInstSrcAddImplicitReturnType *inst = ir_build_instruction<IrInstSrcAddImplicitReturnType>(irb, scope, source_node);
3775 instruction->value = value;4783 inst->value = value;
3776 instruction->result_loc_ret = result_loc_ret;4784 inst->result_loc_ret = result_loc_ret;
37774785
3778 ir_ref_instruction(value, irb->current_basic_block);4786 ir_ref_instruction(value, irb->current_basic_block);
37794787
3780 return &instruction->base;4788 return &inst->base;
3781}4789}
37824790
3783static IrInstruction *ir_build_has_decl(IrBuilder *irb, Scope *scope, AstNode *source_node,4791static IrInstSrc *ir_build_has_decl(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3784 IrInstruction *container, IrInstruction *name)4792 IrInstSrc *container, IrInstSrc *name)
3785{4793{
3786 IrInstructionHasDecl *instruction = ir_build_instruction<IrInstructionHasDecl>(irb, scope, source_node);4794 IrInstSrcHasDecl *instruction = ir_build_instruction<IrInstSrcHasDecl>(irb, scope, source_node);
3787 instruction->container = container;4795 instruction->container = container;
3788 instruction->name = name;4796 instruction->name = name;
37894797
...@@ -3793,17 +4801,15 @@ static IrInstruction *ir_build_has_decl(IrBuilder *irb, Scope *scope, AstNode *s...@@ -3793,17 +4801,15 @@ static IrInstruction *ir_build_has_decl(IrBuilder *irb, Scope *scope, AstNode *s
3793 return &instruction->base;4801 return &instruction->base;
3794}4802}
37954803
3796static IrInstruction *ir_build_undeclared_identifier(IrBuilder *irb, Scope *scope, AstNode *source_node,4804static IrInstSrc *ir_build_undeclared_identifier(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, Buf *name) {
3797 Buf *name)4805 IrInstSrcUndeclaredIdent *instruction = ir_build_instruction<IrInstSrcUndeclaredIdent>(irb, scope, source_node);
3798{
3799 IrInstructionUndeclaredIdent *instruction = ir_build_instruction<IrInstructionUndeclaredIdent>(irb, scope, source_node);
3800 instruction->name = name;4806 instruction->name = name;
38014807
3802 return &instruction->base;4808 return &instruction->base;
3803}4809}
38044810
3805static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *scope_is_comptime, IrInstruction *is_comptime) {4811static IrInstSrc *ir_build_check_runtime_scope(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *scope_is_comptime, IrInstSrc *is_comptime) {
3806 IrInstructionCheckRuntimeScope *instruction = ir_build_instruction<IrInstructionCheckRuntimeScope>(irb, scope, source_node);4812 IrInstSrcCheckRuntimeScope *instruction = ir_build_instruction<IrInstSrcCheckRuntimeScope>(irb, scope, source_node);
3807 instruction->scope_is_comptime = scope_is_comptime;4813 instruction->scope_is_comptime = scope_is_comptime;
3808 instruction->is_comptime = is_comptime;4814 instruction->is_comptime = is_comptime;
38094815
...@@ -3813,10 +4819,10 @@ static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope,...@@ -3813,10 +4819,10 @@ static IrInstruction *ir_build_check_runtime_scope(IrBuilder *irb, Scope *scope,
3813 return &instruction->base;4819 return &instruction->base;
3814}4820}
38154821
3816static IrInstruction *ir_build_union_init_named_field(IrBuilder *irb, Scope *scope, AstNode *source_node,4822static IrInstSrc *ir_build_union_init_named_field(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3817 IrInstruction *union_type, IrInstruction *field_name, IrInstruction *field_result_loc, IrInstruction *result_loc)4823 IrInstSrc *union_type, IrInstSrc *field_name, IrInstSrc *field_result_loc, IrInstSrc *result_loc)
3818{4824{
3819 IrInstructionUnionInitNamedField *instruction = ir_build_instruction<IrInstructionUnionInitNamedField>(irb, scope, source_node);4825 IrInstSrcUnionInitNamedField *instruction = ir_build_instruction<IrInstSrcUnionInitNamedField>(irb, scope, source_node);
3820 instruction->union_type = union_type;4826 instruction->union_type = union_type;
3821 instruction->field_name = field_name;4827 instruction->field_name = field_name;
3822 instruction->field_result_loc = field_result_loc;4828 instruction->field_result_loc = field_result_loc;
...@@ -3831,79 +4837,79 @@ static IrInstruction *ir_build_union_init_named_field(IrBuilder *irb, Scope *sco...@@ -3831,79 +4837,79 @@ static IrInstruction *ir_build_union_init_named_field(IrBuilder *irb, Scope *sco
3831}4837}
38324838
38334839
3834static IrInstruction *ir_build_vector_to_array(IrAnalyze *ira, IrInstruction *source_instruction,4840static IrInstGen *ir_build_vector_to_array(IrAnalyze *ira, IrInst *source_instruction,
3835 ZigType *result_type, IrInstruction *vector, IrInstruction *result_loc)4841 ZigType *result_type, IrInstGen *vector, IrInstGen *result_loc)
3836{4842{
3837 IrInstructionVectorToArray *instruction = ir_build_instruction<IrInstructionVectorToArray>(&ira->new_irb,4843 IrInstGenVectorToArray *instruction = ir_build_inst_gen<IrInstGenVectorToArray>(&ira->new_irb,
3838 source_instruction->scope, source_instruction->source_node);4844 source_instruction->scope, source_instruction->source_node);
3839 instruction->base.value->type = result_type;4845 instruction->base.value->type = result_type;
3840 instruction->vector = vector;4846 instruction->vector = vector;
3841 instruction->result_loc = result_loc;4847 instruction->result_loc = result_loc;
38424848
3843 ir_ref_instruction(vector, ira->new_irb.current_basic_block);4849 ir_ref_inst_gen(vector, ira->new_irb.current_basic_block);
3844 ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);4850 ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
38454851
3846 return &instruction->base;4852 return &instruction->base;
3847}4853}
38484854
3849static IrInstruction *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instruction,4855static IrInstGen *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInst *source_instruction,
3850 ZigType *result_type, IrInstruction *operand, IrInstruction *result_loc)4856 ZigType *result_type, IrInstGen *operand, IrInstGen *result_loc)
3851{4857{
3852 IrInstructionPtrOfArrayToSlice *instruction = ir_build_instruction<IrInstructionPtrOfArrayToSlice>(&ira->new_irb,4858 IrInstGenPtrOfArrayToSlice *instruction = ir_build_inst_gen<IrInstGenPtrOfArrayToSlice>(&ira->new_irb,
3853 source_instruction->scope, source_instruction->source_node);4859 source_instruction->scope, source_instruction->source_node);
3854 instruction->base.value->type = result_type;4860 instruction->base.value->type = result_type;
3855 instruction->operand = operand;4861 instruction->operand = operand;
3856 instruction->result_loc = result_loc;4862 instruction->result_loc = result_loc;
38574863
3858 ir_ref_instruction(operand, ira->new_irb.current_basic_block);4864 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
3859 ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);4865 ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
38604866
3861 return &instruction->base;4867 return &instruction->base;
3862}4868}
38634869
3864static IrInstruction *ir_build_array_to_vector(IrAnalyze *ira, IrInstruction *source_instruction,4870static IrInstGen *ir_build_array_to_vector(IrAnalyze *ira, IrInst *source_instruction,
3865 IrInstruction *array, ZigType *result_type)4871 IrInstGen *array, ZigType *result_type)
3866{4872{
3867 IrInstructionArrayToVector *instruction = ir_build_instruction<IrInstructionArrayToVector>(&ira->new_irb,4873 IrInstGenArrayToVector *instruction = ir_build_inst_gen<IrInstGenArrayToVector>(&ira->new_irb,
3868 source_instruction->scope, source_instruction->source_node);4874 source_instruction->scope, source_instruction->source_node);
3869 instruction->base.value->type = result_type;4875 instruction->base.value->type = result_type;
3870 instruction->array = array;4876 instruction->array = array;
38714877
3872 ir_ref_instruction(array, ira->new_irb.current_basic_block);4878 ir_ref_inst_gen(array, ira->new_irb.current_basic_block);
38734879
3874 return &instruction->base;4880 return &instruction->base;
3875}4881}
38764882
3877static IrInstruction *ir_build_assert_zero(IrAnalyze *ira, IrInstruction *source_instruction,4883static IrInstGen *ir_build_assert_zero(IrAnalyze *ira, IrInst *source_instruction,
3878 IrInstruction *target)4884 IrInstGen *target)
3879{4885{
3880 IrInstructionAssertZero *instruction = ir_build_instruction<IrInstructionAssertZero>(&ira->new_irb,4886 IrInstGenAssertZero *instruction = ir_build_inst_gen<IrInstGenAssertZero>(&ira->new_irb,
3881 source_instruction->scope, source_instruction->source_node);4887 source_instruction->scope, source_instruction->source_node);
3882 instruction->base.value->type = ira->codegen->builtin_types.entry_void;4888 instruction->base.value->type = ira->codegen->builtin_types.entry_void;
3883 instruction->target = target;4889 instruction->target = target;
38844890
3885 ir_ref_instruction(target, ira->new_irb.current_basic_block);4891 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
38864892
3887 return &instruction->base;4893 return &instruction->base;
3888}4894}
38894895
3890static IrInstruction *ir_build_assert_non_null(IrAnalyze *ira, IrInstruction *source_instruction,4896static IrInstGen *ir_build_assert_non_null(IrAnalyze *ira, IrInst *source_instruction,
3891 IrInstruction *target)4897 IrInstGen *target)
3892{4898{
3893 IrInstructionAssertNonNull *instruction = ir_build_instruction<IrInstructionAssertNonNull>(&ira->new_irb,4899 IrInstGenAssertNonNull *instruction = ir_build_inst_gen<IrInstGenAssertNonNull>(&ira->new_irb,
3894 source_instruction->scope, source_instruction->source_node);4900 source_instruction->scope, source_instruction->source_node);
3895 instruction->base.value->type = ira->codegen->builtin_types.entry_void;4901 instruction->base.value->type = ira->codegen->builtin_types.entry_void;
3896 instruction->target = target;4902 instruction->target = target;
38974903
3898 ir_ref_instruction(target, ira->new_irb.current_basic_block);4904 ir_ref_inst_gen(target, ira->new_irb.current_basic_block);
38994905
3900 return &instruction->base;4906 return &instruction->base;
3901}4907}
39024908
3903static IrInstruction *ir_build_alloca_src(IrBuilder *irb, Scope *scope, AstNode *source_node,4909static IrInstSrc *ir_build_alloca_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3904 IrInstruction *align, const char *name_hint, IrInstruction *is_comptime)4910 IrInstSrc *align, const char *name_hint, IrInstSrc *is_comptime)
3905{4911{
3906 IrInstructionAllocaSrc *instruction = ir_build_instruction<IrInstructionAllocaSrc>(irb, scope, source_node);4912 IrInstSrcAlloca *instruction = ir_build_instruction<IrInstSrcAlloca>(irb, scope, source_node);
3907 instruction->base.is_gen = true;4913 instruction->base.is_gen = true;
3908 instruction->align = align;4914 instruction->align = align;
3909 instruction->name_hint = name_hint;4915 instruction->name_hint = name_hint;
...@@ -3915,10 +4921,10 @@ static IrInstruction *ir_build_alloca_src(IrBuilder *irb, Scope *scope, AstNode...@@ -3915,10 +4921,10 @@ static IrInstruction *ir_build_alloca_src(IrBuilder *irb, Scope *scope, AstNode
3915 return &instruction->base;4921 return &instruction->base;
3916}4922}
39174923
3918static IrInstructionAllocaGen *ir_build_alloca_gen(IrAnalyze *ira, IrInstruction *source_instruction,4924static IrInstGenAlloca *ir_build_alloca_gen(IrAnalyze *ira, IrInst *source_instruction,
3919 uint32_t align, const char *name_hint)4925 uint32_t align, const char *name_hint)
3920{4926{
3921 IrInstructionAllocaGen *instruction = ir_create_instruction<IrInstructionAllocaGen>(&ira->new_irb,4927 IrInstGenAlloca *instruction = ir_create_inst_gen<IrInstGenAlloca>(&ira->new_irb,
3922 source_instruction->scope, source_instruction->source_node);4928 source_instruction->scope, source_instruction->source_node);
3923 instruction->align = align;4929 instruction->align = align;
3924 instruction->name_hint = name_hint;4930 instruction->name_hint = name_hint;
...@@ -3926,10 +4932,10 @@ static IrInstructionAllocaGen *ir_build_alloca_gen(IrAnalyze *ira, IrInstruction...@@ -3926,10 +4932,10 @@ static IrInstructionAllocaGen *ir_build_alloca_gen(IrAnalyze *ira, IrInstruction
3926 return instruction;4932 return instruction;
3927}4933}
39284934
3929static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *source_node,4935static IrInstSrc *ir_build_end_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3930 IrInstruction *value, ResultLoc *result_loc)4936 IrInstSrc *value, ResultLoc *result_loc)
3931{4937{
3932 IrInstructionEndExpr *instruction = ir_build_instruction<IrInstructionEndExpr>(irb, scope, source_node);4938 IrInstSrcEndExpr *instruction = ir_build_instruction<IrInstSrcEndExpr>(irb, scope, source_node);
3933 instruction->base.is_gen = true;4939 instruction->base.is_gen = true;
3934 instruction->value = value;4940 instruction->value = value;
3935 instruction->result_loc = result_loc;4941 instruction->result_loc = result_loc;
...@@ -3939,29 +4945,41 @@ static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *s...@@ -3939,29 +4945,41 @@ static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *s
3939 return &instruction->base;4945 return &instruction->base;
3940}4946}
39414947
3942static IrInstructionSuspendBegin *ir_build_suspend_begin(IrBuilder *irb, Scope *scope, AstNode *source_node) {4948static IrInstSrcSuspendBegin *ir_build_suspend_begin_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node) {
3943 IrInstructionSuspendBegin *instruction = ir_build_instruction<IrInstructionSuspendBegin>(irb, scope, source_node);4949 return ir_build_instruction<IrInstSrcSuspendBegin>(irb, scope, source_node);
3944 instruction->base.value->type = irb->codegen->builtin_types.entry_void;4950}
39454951
3946 return instruction;4952static IrInstGen *ir_build_suspend_begin_gen(IrAnalyze *ira, IrInst *source_instr) {
4953 IrInstGenSuspendBegin *inst = ir_build_inst_void<IrInstGenSuspendBegin>(&ira->new_irb,
4954 source_instr->scope, source_instr->source_node);
4955 return &inst->base;
3947}4956}
39484957
3949static IrInstruction *ir_build_suspend_finish(IrBuilder *irb, Scope *scope, AstNode *source_node,4958static IrInstSrc *ir_build_suspend_finish_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3950 IrInstructionSuspendBegin *begin)4959 IrInstSrcSuspendBegin *begin)
3951{4960{
3952 IrInstructionSuspendFinish *instruction = ir_build_instruction<IrInstructionSuspendFinish>(irb, scope, source_node);4961 IrInstSrcSuspendFinish *inst = ir_build_instruction<IrInstSrcSuspendFinish>(irb, scope, source_node);
3953 instruction->base.value->type = irb->codegen->builtin_types.entry_void;4962 inst->begin = begin;
3954 instruction->begin = begin;
39554963
3956 ir_ref_instruction(&begin->base, irb->current_basic_block);4964 ir_ref_instruction(&begin->base, irb->current_basic_block);
39574965
3958 return &instruction->base;4966 return &inst->base;
4967}
4968
4969static IrInstGen *ir_build_suspend_finish_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGenSuspendBegin *begin) {
4970 IrInstGenSuspendFinish *inst = ir_build_inst_void<IrInstGenSuspendFinish>(&ira->new_irb,
4971 source_instr->scope, source_instr->source_node);
4972 inst->begin = begin;
4973
4974 ir_ref_inst_gen(&begin->base, ira->new_irb.current_basic_block);
4975
4976 return &inst->base;
3959}4977}
39604978
3961static IrInstruction *ir_build_await_src(IrBuilder *irb, Scope *scope, AstNode *source_node,4979static IrInstSrc *ir_build_await_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
3962 IrInstruction *frame, ResultLoc *result_loc)4980 IrInstSrc *frame, ResultLoc *result_loc)
3963{4981{
3964 IrInstructionAwaitSrc *instruction = ir_build_instruction<IrInstructionAwaitSrc>(irb, scope, source_node);4982 IrInstSrcAwait *instruction = ir_build_instruction<IrInstSrcAwait>(irb, scope, source_node);
3965 instruction->frame = frame;4983 instruction->frame = frame;
3966 instruction->result_loc = result_loc;4984 instruction->result_loc = result_loc;
39674985
...@@ -3970,24 +4988,23 @@ static IrInstruction *ir_build_await_src(IrBuilder *irb, Scope *scope, AstNode *...@@ -3970,24 +4988,23 @@ static IrInstruction *ir_build_await_src(IrBuilder *irb, Scope *scope, AstNode *
3970 return &instruction->base;4988 return &instruction->base;
3971}4989}
39724990
3973static IrInstructionAwaitGen *ir_build_await_gen(IrAnalyze *ira, IrInstruction *source_instruction,4991static IrInstGenAwait *ir_build_await_gen(IrAnalyze *ira, IrInst *source_instruction,
3974 IrInstruction *frame, ZigType *result_type, IrInstruction *result_loc)4992 IrInstGen *frame, ZigType *result_type, IrInstGen *result_loc)
3975{4993{
3976 IrInstructionAwaitGen *instruction = ir_build_instruction<IrInstructionAwaitGen>(&ira->new_irb,4994 IrInstGenAwait *instruction = ir_build_inst_gen<IrInstGenAwait>(&ira->new_irb,
3977 source_instruction->scope, source_instruction->source_node);4995 source_instruction->scope, source_instruction->source_node);
3978 instruction->base.value->type = result_type;4996 instruction->base.value->type = result_type;
3979 instruction->frame = frame;4997 instruction->frame = frame;
3980 instruction->result_loc = result_loc;4998 instruction->result_loc = result_loc;
39814999
3982 ir_ref_instruction(frame, ira->new_irb.current_basic_block);5000 ir_ref_inst_gen(frame, ira->new_irb.current_basic_block);
3983 if (result_loc != nullptr) ir_ref_instruction(result_loc, ira->new_irb.current_basic_block);5001 if (result_loc != nullptr) ir_ref_inst_gen(result_loc, ira->new_irb.current_basic_block);
39845002
3985 return instruction;5003 return instruction;
3986}5004}
39875005
3988static IrInstruction *ir_build_resume(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *frame) {5006static IrInstSrc *ir_build_resume_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, IrInstSrc *frame) {
3989 IrInstructionResume *instruction = ir_build_instruction<IrInstructionResume>(irb, scope, source_node);5007 IrInstSrcResume *instruction = ir_build_instruction<IrInstSrcResume>(irb, scope, source_node);
3990 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
3991 instruction->frame = frame;5008 instruction->frame = frame;
39925009
3993 ir_ref_instruction(frame, irb->current_basic_block);5010 ir_ref_instruction(frame, irb->current_basic_block);
...@@ -3995,12 +5012,20 @@ static IrInstruction *ir_build_resume(IrBuilder *irb, Scope *scope, AstNode *sou...@@ -3995,12 +5012,20 @@ static IrInstruction *ir_build_resume(IrBuilder *irb, Scope *scope, AstNode *sou
3995 return &instruction->base;5012 return &instruction->base;
3996}5013}
39975014
3998static IrInstructionSpillBegin *ir_build_spill_begin(IrBuilder *irb, Scope *scope, AstNode *source_node,5015static IrInstGen *ir_build_resume_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *frame) {
3999 IrInstruction *operand, SpillId spill_id)5016 IrInstGenResume *instruction = ir_build_inst_void<IrInstGenResume>(&ira->new_irb,
5017 source_instr->scope, source_instr->source_node);
5018 instruction->frame = frame;
5019
5020 ir_ref_inst_gen(frame, ira->new_irb.current_basic_block);
5021
5022 return &instruction->base;
5023}
5024
5025static IrInstSrcSpillBegin *ir_build_spill_begin_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
5026 IrInstSrc *operand, SpillId spill_id)
4000{5027{
4001 IrInstructionSpillBegin *instruction = ir_build_instruction<IrInstructionSpillBegin>(irb, scope, source_node);5028 IrInstSrcSpillBegin *instruction = ir_build_instruction<IrInstSrcSpillBegin>(irb, scope, source_node);
4002 instruction->base.value->special = ConstValSpecialStatic;
4003 instruction->base.value->type = irb->codegen->builtin_types.entry_void;
4004 instruction->operand = operand;5029 instruction->operand = operand;
4005 instruction->spill_id = spill_id;5030 instruction->spill_id = spill_id;
40065031
...@@ -4009,10 +5034,23 @@ static IrInstructionSpillBegin *ir_build_spill_begin(IrBuilder *irb, Scope *scop...@@ -4009,10 +5034,23 @@ static IrInstructionSpillBegin *ir_build_spill_begin(IrBuilder *irb, Scope *scop
4009 return instruction;5034 return instruction;
4010}5035}
40115036
4012static IrInstruction *ir_build_spill_end(IrBuilder *irb, Scope *scope, AstNode *source_node,5037static IrInstGen *ir_build_spill_begin_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGen *operand,
4013 IrInstructionSpillBegin *begin)5038 SpillId spill_id)
5039{
5040 IrInstGenSpillBegin *instruction = ir_build_inst_void<IrInstGenSpillBegin>(&ira->new_irb,
5041 source_instr->scope, source_instr->source_node);
5042 instruction->operand = operand;
5043 instruction->spill_id = spill_id;
5044
5045 ir_ref_inst_gen(operand, ira->new_irb.current_basic_block);
5046
5047 return &instruction->base;
5048}
5049
5050static IrInstSrc *ir_build_spill_end_src(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
5051 IrInstSrcSpillBegin *begin)
4014{5052{
4015 IrInstructionSpillEnd *instruction = ir_build_instruction<IrInstructionSpillEnd>(irb, scope, source_node);5053 IrInstSrcSpillEnd *instruction = ir_build_instruction<IrInstSrcSpillEnd>(irb, scope, source_node);
4016 instruction->begin = begin;5054 instruction->begin = begin;
40175055
4018 ir_ref_instruction(&begin->base, irb->current_basic_block);5056 ir_ref_instruction(&begin->base, irb->current_basic_block);
...@@ -4020,22 +5058,35 @@ static IrInstruction *ir_build_spill_end(IrBuilder *irb, Scope *scope, AstNode *...@@ -4020,22 +5058,35 @@ static IrInstruction *ir_build_spill_end(IrBuilder *irb, Scope *scope, AstNode *
4020 return &instruction->base;5058 return &instruction->base;
4021}5059}
40225060
4023static IrInstruction *ir_build_vector_extract_elem(IrAnalyze *ira, IrInstruction *source_instruction,5061static IrInstGen *ir_build_spill_end_gen(IrAnalyze *ira, IrInst *source_instr, IrInstGenSpillBegin *begin,
4024 IrInstruction *vector, IrInstruction *index)5062 ZigType *result_type)
5063{
5064 IrInstGenSpillEnd *instruction = ir_build_inst_gen<IrInstGenSpillEnd>(&ira->new_irb,
5065 source_instr->scope, source_instr->source_node);
5066 instruction->base.value->type = result_type;
5067 instruction->begin = begin;
5068
5069 ir_ref_inst_gen(&begin->base, ira->new_irb.current_basic_block);
5070
5071 return &instruction->base;
5072}
5073
5074static IrInstGen *ir_build_vector_extract_elem(IrAnalyze *ira, IrInst *source_instruction,
5075 IrInstGen *vector, IrInstGen *index)
4025{5076{
4026 IrInstructionVectorExtractElem *instruction = ir_build_instruction<IrInstructionVectorExtractElem>(5077 IrInstGenVectorExtractElem *instruction = ir_build_inst_gen<IrInstGenVectorExtractElem>(
4027 &ira->new_irb, source_instruction->scope, source_instruction->source_node);5078 &ira->new_irb, source_instruction->scope, source_instruction->source_node);
4028 instruction->base.value->type = vector->value->type->data.vector.elem_type;5079 instruction->base.value->type = vector->value->type->data.vector.elem_type;
4029 instruction->vector = vector;5080 instruction->vector = vector;
4030 instruction->index = index;5081 instruction->index = index;
40315082
4032 ir_ref_instruction(vector, ira->new_irb.current_basic_block);5083 ir_ref_inst_gen(vector, ira->new_irb.current_basic_block);
4033 ir_ref_instruction(index, ira->new_irb.current_basic_block);5084 ir_ref_inst_gen(index, ira->new_irb.current_basic_block);
40345085
4035 return &instruction->base;5086 return &instruction->base;
4036}5087}
40375088
4038static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) {5089static void ir_count_defers(IrBuilderSrc *irb, Scope *inner_scope, Scope *outer_scope, size_t *results) {
4039 results[ReturnKindUnconditional] = 0;5090 results[ReturnKindUnconditional] = 0;
4040 results[ReturnKindError] = 0;5091 results[ReturnKindError] = 0;
40415092
...@@ -4072,12 +5123,12 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco...@@ -4072,12 +5123,12 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco
4072 }5123 }
4073}5124}
40745125
4075static IrInstruction *ir_mark_gen(IrInstruction *instruction) {5126static IrInstSrc *ir_mark_gen(IrInstSrc *instruction) {
4076 instruction->is_gen = true;5127 instruction->is_gen = true;
4077 return instruction;5128 return instruction;
4078}5129}
40795130
4080static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *outer_scope, bool gen_error_defers) {5131static bool ir_gen_defers_for_block(IrBuilderSrc *irb, Scope *inner_scope, Scope *outer_scope, bool gen_error_defers) {
4081 Scope *scope = inner_scope;5132 Scope *scope = inner_scope;
4082 bool is_noreturn = false;5133 bool is_noreturn = false;
4083 while (scope != outer_scope) {5134 while (scope != outer_scope) {
...@@ -4094,11 +5145,9 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o...@@ -4094,11 +5145,9 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
4094 {5145 {
4095 AstNode *defer_expr_node = defer_node->data.defer.expr;5146 AstNode *defer_expr_node = defer_node->data.defer.expr;
4096 Scope *defer_expr_scope = defer_node->data.defer.expr_scope;5147 Scope *defer_expr_scope = defer_node->data.defer.expr_scope;
4097 IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);5148 IrInstSrc *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);
4098 if (defer_expr_value != irb->codegen->invalid_instruction) {5149 if (defer_expr_value != irb->codegen->invalid_inst_src) {
4099 if (defer_expr_value->value->type != nullptr &&5150 if (defer_expr_value->is_noreturn) {
4100 defer_expr_value->value->type->id == ZigTypeIdUnreachable)
4101 {
4102 is_noreturn = true;5151 is_noreturn = true;
4103 } else {5152 } else {
4104 ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node,5153 ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node,
...@@ -4130,13 +5179,17 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o...@@ -4130,13 +5179,17 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
4130 return is_noreturn;5179 return is_noreturn;
4131}5180}
41325181
4133static void ir_set_cursor_at_end(IrBuilder *irb, IrBasicBlock *basic_block) {5182static void ir_set_cursor_at_end_gen(IrBuilderGen *irb, IrBasicBlockGen *basic_block) {
4134 assert(basic_block);5183 assert(basic_block);
5184 irb->current_basic_block = basic_block;
5185}
41355186
5187static void ir_set_cursor_at_end(IrBuilderSrc *irb, IrBasicBlockSrc *basic_block) {
5188 assert(basic_block);
4136 irb->current_basic_block = basic_block;5189 irb->current_basic_block = basic_block;
4137}5190}
41385191
4139static void ir_set_cursor_at_end_and_append_block(IrBuilder *irb, IrBasicBlock *basic_block) {5192static void ir_set_cursor_at_end_and_append_block(IrBuilderSrc *irb, IrBasicBlockSrc *basic_block) {
4140 basic_block->index = irb->exec->basic_block_list.length;5193 basic_block->index = irb->exec->basic_block_list.length;
4141 irb->exec->basic_block_list.append(basic_block);5194 irb->exec->basic_block_list.append(basic_block);
4142 ir_set_cursor_at_end(irb, basic_block);5195 ir_set_cursor_at_end(irb, basic_block);
...@@ -4166,22 +5219,16 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) {...@@ -4166,22 +5219,16 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) {
4166 return nullptr;5219 return nullptr;
4167}5220}
41685221
4169static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {5222static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
4170 assert(node->type == NodeTypeReturnExpr);5223 assert(node->type == NodeTypeReturnExpr);
41715224
4172 ZigFn *fn_entry = exec_fn_entry(irb->exec);
4173 if (!fn_entry) {
4174 add_node_error(irb->codegen, node, buf_sprintf("return expression outside function definition"));
4175 return irb->codegen->invalid_instruction;
4176 }
4177
4178 ScopeDeferExpr *scope_defer_expr = get_scope_defer_expr(scope);5225 ScopeDeferExpr *scope_defer_expr = get_scope_defer_expr(scope);
4179 if (scope_defer_expr) {5226 if (scope_defer_expr) {
4180 if (!scope_defer_expr->reported_err) {5227 if (!scope_defer_expr->reported_err) {
4181 add_node_error(irb->codegen, node, buf_sprintf("cannot return from defer expression"));5228 add_node_error(irb->codegen, node, buf_sprintf("cannot return from defer expression"));
4182 scope_defer_expr->reported_err = true;5229 scope_defer_expr->reported_err = true;
4183 }5230 }
4184 return irb->codegen->invalid_instruction;5231 return irb->codegen->invalid_inst_src;
4185 }5232 }
41865233
4187 Scope *outer_scope = irb->exec->begin_scope;5234 Scope *outer_scope = irb->exec->begin_scope;
...@@ -4194,15 +5241,15 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4194,15 +5241,15 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
4194 result_loc_ret->base.id = ResultLocIdReturn;5241 result_loc_ret->base.id = ResultLocIdReturn;
4195 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);5242 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);
41965243
4197 IrInstruction *return_value;5244 IrInstSrc *return_value;
4198 if (expr_node) {5245 if (expr_node) {
4199 // Temporarily set this so that if we return a type it gets the name of the function5246 // Temporarily set this so that if we return a type it gets the name of the function
4200 ZigFn *prev_name_fn = irb->exec->name_fn;5247 ZigFn *prev_name_fn = irb->exec->name_fn;
4201 irb->exec->name_fn = exec_fn_entry(irb->exec);5248 irb->exec->name_fn = exec_fn_entry(irb->exec);
4202 return_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, &result_loc_ret->base);5249 return_value = ir_gen_node_extra(irb, expr_node, scope, LValNone, &result_loc_ret->base);
4203 irb->exec->name_fn = prev_name_fn;5250 irb->exec->name_fn = prev_name_fn;
4204 if (return_value == irb->codegen->invalid_instruction)5251 if (return_value == irb->codegen->invalid_inst_src)
4205 return irb->codegen->invalid_instruction;5252 return irb->codegen->invalid_inst_src;
4206 } else {5253 } else {
4207 return_value = ir_build_const_void(irb, scope, node);5254 return_value = ir_build_const_void(irb, scope, node);
4208 }5255 }
...@@ -4215,22 +5262,22 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4215,22 +5262,22 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
4215 if (!have_err_defers && !irb->codegen->have_err_ret_tracing) {5262 if (!have_err_defers && !irb->codegen->have_err_ret_tracing) {
4216 // only generate unconditional defers5263 // only generate unconditional defers
4217 ir_gen_defers_for_block(irb, scope, outer_scope, false);5264 ir_gen_defers_for_block(irb, scope, outer_scope, false);
4218 IrInstruction *result = ir_build_return(irb, scope, node, return_value);5265 IrInstSrc *result = ir_build_return_src(irb, scope, node, return_value);
4219 result_loc_ret->base.source_instruction = result;5266 result_loc_ret->base.source_instruction = result;
4220 return result;5267 return result;
4221 }5268 }
4222 bool should_inline = ir_should_inline(irb->exec, scope);5269 bool should_inline = ir_should_inline(irb->exec, scope);
42235270
4224 IrBasicBlock *err_block = ir_create_basic_block(irb, scope, "ErrRetErr");5271 IrBasicBlockSrc *err_block = ir_create_basic_block(irb, scope, "ErrRetErr");
4225 IrBasicBlock *ok_block = ir_create_basic_block(irb, scope, "ErrRetOk");5272 IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, scope, "ErrRetOk");
42265273
4227 if (!have_err_defers) {5274 if (!have_err_defers) {
4228 ir_gen_defers_for_block(irb, scope, outer_scope, false);5275 ir_gen_defers_for_block(irb, scope, outer_scope, false);
4229 }5276 }
42305277
4231 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, return_value, false, true);5278 IrInstSrc *is_err = ir_build_test_err_src(irb, scope, node, return_value, false, true);
42325279
4233 IrInstruction *is_comptime;5280 IrInstSrc *is_comptime;
4234 if (should_inline) {5281 if (should_inline) {
4235 is_comptime = ir_build_const_bool(irb, scope, node, should_inline);5282 is_comptime = ir_build_const_bool(irb, scope, node, should_inline);
4236 } else {5283 } else {
...@@ -4238,14 +5285,14 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4238,14 +5285,14 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
4238 }5285 }
42395286
4240 ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err, err_block, ok_block, is_comptime));5287 ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err, err_block, ok_block, is_comptime));
4241 IrBasicBlock *ret_stmt_block = ir_create_basic_block(irb, scope, "RetStmt");5288 IrBasicBlockSrc *ret_stmt_block = ir_create_basic_block(irb, scope, "RetStmt");
42425289
4243 ir_set_cursor_at_end_and_append_block(irb, err_block);5290 ir_set_cursor_at_end_and_append_block(irb, err_block);
4244 if (have_err_defers) {5291 if (have_err_defers) {
4245 ir_gen_defers_for_block(irb, scope, outer_scope, true);5292 ir_gen_defers_for_block(irb, scope, outer_scope, true);
4246 }5293 }
4247 if (irb->codegen->have_err_ret_tracing && !should_inline) {5294 if (irb->codegen->have_err_ret_tracing && !should_inline) {
4248 ir_build_save_err_ret_addr(irb, scope, node);5295 ir_build_save_err_ret_addr_src(irb, scope, node);
4249 }5296 }
4250 ir_build_br(irb, scope, node, ret_stmt_block, is_comptime);5297 ir_build_br(irb, scope, node, ret_stmt_block, is_comptime);
42515298
...@@ -4256,21 +5303,21 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4256,21 +5303,21 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
4256 ir_build_br(irb, scope, node, ret_stmt_block, is_comptime);5303 ir_build_br(irb, scope, node, ret_stmt_block, is_comptime);
42575304
4258 ir_set_cursor_at_end_and_append_block(irb, ret_stmt_block);5305 ir_set_cursor_at_end_and_append_block(irb, ret_stmt_block);
4259 IrInstruction *result = ir_build_return(irb, scope, node, return_value);5306 IrInstSrc *result = ir_build_return_src(irb, scope, node, return_value);
4260 result_loc_ret->base.source_instruction = result;5307 result_loc_ret->base.source_instruction = result;
4261 return result;5308 return result;
4262 }5309 }
4263 case ReturnKindError:5310 case ReturnKindError:
4264 {5311 {
4265 assert(expr_node);5312 assert(expr_node);
4266 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);5313 IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
4267 if (err_union_ptr == irb->codegen->invalid_instruction)5314 if (err_union_ptr == irb->codegen->invalid_inst_src)
4268 return irb->codegen->invalid_instruction;5315 return irb->codegen->invalid_inst_src;
4269 IrInstruction *is_err_val = ir_build_test_err_src(irb, scope, node, err_union_ptr, true, false);5316 IrInstSrc *is_err_val = ir_build_test_err_src(irb, scope, node, err_union_ptr, true, false);
42705317
4271 IrBasicBlock *return_block = ir_create_basic_block(irb, scope, "ErrRetReturn");5318 IrBasicBlockSrc *return_block = ir_create_basic_block(irb, scope, "ErrRetReturn");
4272 IrBasicBlock *continue_block = ir_create_basic_block(irb, scope, "ErrRetContinue");5319 IrBasicBlockSrc *continue_block = ir_create_basic_block(irb, scope, "ErrRetContinue");
4273 IrInstruction *is_comptime;5320 IrInstSrc *is_comptime;
4274 bool should_inline = ir_should_inline(irb->exec, scope);5321 bool should_inline = ir_should_inline(irb->exec, scope);
4275 if (should_inline) {5322 if (should_inline) {
4276 is_comptime = ir_build_const_bool(irb, scope, node, true);5323 is_comptime = ir_build_const_bool(irb, scope, node, true);
...@@ -4280,10 +5327,10 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4280,10 +5327,10 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
4280 ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err_val, return_block, continue_block, is_comptime));5327 ir_mark_gen(ir_build_cond_br(irb, scope, node, is_err_val, return_block, continue_block, is_comptime));
42815328
4282 ir_set_cursor_at_end_and_append_block(irb, return_block);5329 ir_set_cursor_at_end_and_append_block(irb, return_block);
4283 IrInstruction *err_val_ptr = ir_build_unwrap_err_code(irb, scope, node, err_union_ptr);5330 IrInstSrc *err_val_ptr = ir_build_unwrap_err_code_src(irb, scope, node, err_union_ptr);
4284 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);5331 IrInstSrc *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);
4285 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, node, err_val, nullptr));5332 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, node, err_val, nullptr));
4286 IrInstructionSpillBegin *spill_begin = ir_build_spill_begin(irb, scope, node, err_val,5333 IrInstSrcSpillBegin *spill_begin = ir_build_spill_begin_src(irb, scope, node, err_val,
4287 SpillIdRetErrCode);5334 SpillIdRetErrCode);
4288 ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn");5335 ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn");
4289 result_loc_ret->base.id = ResultLocIdReturn;5336 result_loc_ret->base.id = ResultLocIdReturn;
...@@ -4291,15 +5338,15 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4291,15 +5338,15 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
4291 ir_build_end_expr(irb, scope, node, err_val, &result_loc_ret->base);5338 ir_build_end_expr(irb, scope, node, err_val, &result_loc_ret->base);
4292 if (!ir_gen_defers_for_block(irb, scope, outer_scope, true)) {5339 if (!ir_gen_defers_for_block(irb, scope, outer_scope, true)) {
4293 if (irb->codegen->have_err_ret_tracing && !should_inline) {5340 if (irb->codegen->have_err_ret_tracing && !should_inline) {
4294 ir_build_save_err_ret_addr(irb, scope, node);5341 ir_build_save_err_ret_addr_src(irb, scope, node);
4295 }5342 }
4296 err_val = ir_build_spill_end(irb, scope, node, spill_begin);5343 err_val = ir_build_spill_end_src(irb, scope, node, spill_begin);
4297 IrInstruction *ret_inst = ir_build_return(irb, scope, node, err_val);5344 IrInstSrc *ret_inst = ir_build_return_src(irb, scope, node, err_val);
4298 result_loc_ret->base.source_instruction = ret_inst;5345 result_loc_ret->base.source_instruction = ret_inst;
4299 }5346 }
43005347
4301 ir_set_cursor_at_end_and_append_block(irb, continue_block);5348 ir_set_cursor_at_end_and_append_block(irb, continue_block);
4302 IrInstruction *unwrapped_ptr = ir_build_unwrap_err_payload(irb, scope, node, err_union_ptr, false, false);5349 IrInstSrc *unwrapped_ptr = ir_build_unwrap_err_payload_src(irb, scope, node, err_union_ptr, false, false);
4303 if (lval == LValPtr)5350 if (lval == LValPtr)
4304 return unwrapped_ptr;5351 return unwrapped_ptr;
4305 else5352 else
...@@ -4310,19 +5357,18 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4310,19 +5357,18 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
4310}5357}
43115358
4312static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope,5359static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope,
4313 Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime,5360 Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime,
4314 bool skip_name_check)5361 bool skip_name_check)
4315{5362{
4316 ZigVar *variable_entry = allocate<ZigVar>(1, "ZigVar");5363 ZigVar *variable_entry = allocate<ZigVar>(1, "ZigVar");
4317 variable_entry->parent_scope = parent_scope;5364 variable_entry->parent_scope = parent_scope;
4318 variable_entry->shadowable = is_shadowable;5365 variable_entry->shadowable = is_shadowable;
4319 variable_entry->mem_slot_index = SIZE_MAX;
4320 variable_entry->is_comptime = is_comptime;5366 variable_entry->is_comptime = is_comptime;
4321 variable_entry->src_arg_index = SIZE_MAX;5367 variable_entry->src_arg_index = SIZE_MAX;
4322 variable_entry->const_value = create_const_vals(1);5368 variable_entry->const_value = create_const_vals(1);
43235369
4324 if (is_comptime != nullptr) {5370 if (is_comptime != nullptr) {
4325 is_comptime->ref_count += 1;5371 is_comptime->base.ref_count += 1;
4326 }5372 }
43275373
4328 if (name) {5374 if (name) {
...@@ -4372,15 +5418,14 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s...@@ -4372,15 +5418,14 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s
43725418
4373// Set name to nullptr to make the variable anonymous (not visible to programmer).5419// Set name to nullptr to make the variable anonymous (not visible to programmer).
4374// After you call this function var->child_scope has the variable in scope5420// After you call this function var->child_scope has the variable in scope
4375static ZigVar *ir_create_var(IrBuilder *irb, AstNode *node, Scope *scope, Buf *name,5421static ZigVar *ir_create_var(IrBuilderSrc *irb, AstNode *node, Scope *scope, Buf *name,
4376 bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime)5422 bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime)
4377{5423{
4378 bool is_underscored = name ? buf_eql_str(name, "_") : false;5424 bool is_underscored = name ? buf_eql_str(name, "_") : false;
4379 ZigVar *var = create_local_var(irb->codegen, node, scope,5425 ZigVar *var = create_local_var(irb->codegen, node, scope,
4380 (is_underscored ? nullptr : name), src_is_const, gen_is_const,5426 (is_underscored ? nullptr : name), src_is_const, gen_is_const,
4381 (is_underscored ? true : is_shadowable), is_comptime, false);5427 (is_underscored ? true : is_shadowable), is_comptime, false);
4382 if (is_comptime != nullptr || gen_is_const) {5428 if (is_comptime != nullptr || gen_is_const) {
4383 var->mem_slot_index = exec_next_mem_slot(irb->exec);
4384 var->owner_exec = irb->exec;5429 var->owner_exec = irb->exec;
4385 }5430 }
4386 assert(var->child_scope);5431 assert(var->child_scope);
...@@ -4396,13 +5441,13 @@ static ResultLocPeer *create_peer_result(ResultLocPeerParent *peer_parent) {...@@ -4396,13 +5441,13 @@ static ResultLocPeer *create_peer_result(ResultLocPeerParent *peer_parent) {
4396 return result;5441 return result;
4397}5442}
43985443
4399static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode *block_node, LVal lval,5444static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *block_node, LVal lval,
4400 ResultLoc *result_loc)5445 ResultLoc *result_loc)
4401{5446{
4402 assert(block_node->type == NodeTypeBlock);5447 assert(block_node->type == NodeTypeBlock);
44035448
4404 ZigList<IrInstruction *> incoming_values = {0};5449 ZigList<IrInstSrc *> incoming_values = {0};
4405 ZigList<IrBasicBlock *> incoming_blocks = {0};5450 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
44065451
4407 ScopeBlock *scope_block = create_block_scope(irb->codegen, block_node, parent_scope);5452 ScopeBlock *scope_block = create_block_scope(irb->codegen, block_node, parent_scope);
44085453
...@@ -4438,11 +5483,11 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -4438,11 +5483,11 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
4438 }5483 }
44395484
4440 bool is_continuation_unreachable = false;5485 bool is_continuation_unreachable = false;
4441 IrInstruction *noreturn_return_value = nullptr;5486 IrInstSrc *noreturn_return_value = nullptr;
4442 for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) {5487 for (size_t i = 0; i < block_node->data.block.statements.length; i += 1) {
4443 AstNode *statement_node = block_node->data.block.statements.at(i);5488 AstNode *statement_node = block_node->data.block.statements.at(i);
44445489
4445 IrInstruction *statement_value = ir_gen_node(irb, statement_node, child_scope);5490 IrInstSrc *statement_value = ir_gen_node(irb, statement_node, child_scope);
4446 is_continuation_unreachable = instr_is_unreachable(statement_value);5491 is_continuation_unreachable = instr_is_unreachable(statement_value);
4447 if (is_continuation_unreachable) {5492 if (is_continuation_unreachable) {
4448 // keep the last noreturn statement value around in case we need to return it5493 // keep the last noreturn statement value around in case we need to return it
...@@ -4450,15 +5495,15 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -4450,15 +5495,15 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
4450 }5495 }
4451 // This logic must be kept in sync with5496 // This logic must be kept in sync with
4452 // [STMT_EXPR_TEST_THING] <--- (search this token)5497 // [STMT_EXPR_TEST_THING] <--- (search this token)
4453 if (statement_node->type == NodeTypeDefer && statement_value != irb->codegen->invalid_instruction) {5498 if (statement_node->type == NodeTypeDefer && statement_value != irb->codegen->invalid_inst_src) {
4454 // defer starts a new scope5499 // defer starts a new scope
4455 child_scope = statement_node->data.defer.child_scope;5500 child_scope = statement_node->data.defer.child_scope;
4456 assert(child_scope);5501 assert(child_scope);
4457 } else if (statement_value->id == IrInstructionIdDeclVarSrc) {5502 } else if (statement_value->id == IrInstSrcIdDeclVar) {
4458 // variable declarations start a new scope5503 // variable declarations start a new scope
4459 IrInstructionDeclVarSrc *decl_var_instruction = (IrInstructionDeclVarSrc *)statement_value;5504 IrInstSrcDeclVar *decl_var_instruction = (IrInstSrcDeclVar *)statement_value;
4460 child_scope = decl_var_instruction->var->child_scope;5505 child_scope = decl_var_instruction->var->child_scope;
4461 } else if (statement_value != irb->codegen->invalid_instruction && !is_continuation_unreachable) {5506 } else if (statement_value != irb->codegen->invalid_inst_src && !is_continuation_unreachable) {
4462 // this statement's value must be void5507 // this statement's value must be void
4463 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, statement_node, statement_value));5508 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, statement_node, statement_value));
4464 }5509 }
...@@ -4474,12 +5519,12 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -4474,12 +5519,12 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
4474 scope_block->peer_parent->peers.last()->next_bb = scope_block->end_block;5519 scope_block->peer_parent->peers.last()->next_bb = scope_block->end_block;
4475 }5520 }
4476 ir_set_cursor_at_end_and_append_block(irb, scope_block->end_block);5521 ir_set_cursor_at_end_and_append_block(irb, scope_block->end_block);
4477 IrInstruction *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length,5522 IrInstSrc *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length,
4478 incoming_blocks.items, incoming_values.items, scope_block->peer_parent);5523 incoming_blocks.items, incoming_values.items, scope_block->peer_parent);
4479 return ir_expr_wrap(irb, parent_scope, phi, result_loc);5524 return ir_expr_wrap(irb, parent_scope, phi, result_loc);
4480 } else {5525 } else {
4481 incoming_blocks.append(irb->current_basic_block);5526 incoming_blocks.append(irb->current_basic_block);
4482 IrInstruction *else_expr_result = ir_mark_gen(ir_build_const_void(irb, parent_scope, block_node));5527 IrInstSrc *else_expr_result = ir_mark_gen(ir_build_const_void(irb, parent_scope, block_node));
44835528
4484 if (scope_block->peer_parent != nullptr) {5529 if (scope_block->peer_parent != nullptr) {
4485 ResultLocPeer *peer_result = create_peer_result(scope_block->peer_parent);5530 ResultLocPeer *peer_result = create_peer_result(scope_block->peer_parent);
...@@ -4499,15 +5544,15 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -4499,15 +5544,15 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
4499 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false);5544 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false);
4500 }5545 }
45015546
4502 IrInstruction *result;5547 IrInstSrc *result;
4503 if (block_node->data.block.name != nullptr) {5548 if (block_node->data.block.name != nullptr) {
4504 ir_mark_gen(ir_build_br(irb, parent_scope, block_node, scope_block->end_block, scope_block->is_comptime));5549 ir_mark_gen(ir_build_br(irb, parent_scope, block_node, scope_block->end_block, scope_block->is_comptime));
4505 ir_set_cursor_at_end_and_append_block(irb, scope_block->end_block);5550 ir_set_cursor_at_end_and_append_block(irb, scope_block->end_block);
4506 IrInstruction *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length,5551 IrInstSrc *phi = ir_build_phi(irb, parent_scope, block_node, incoming_blocks.length,
4507 incoming_blocks.items, incoming_values.items, scope_block->peer_parent);5552 incoming_blocks.items, incoming_values.items, scope_block->peer_parent);
4508 result = ir_expr_wrap(irb, parent_scope, phi, result_loc);5553 result = ir_expr_wrap(irb, parent_scope, phi, result_loc);
4509 } else {5554 } else {
4510 IrInstruction *void_inst = ir_mark_gen(ir_build_const_void(irb, child_scope, block_node));5555 IrInstSrc *void_inst = ir_mark_gen(ir_build_const_void(irb, child_scope, block_node));
4511 result = ir_lval_wrap(irb, parent_scope, void_inst, lval, result_loc);5556 result = ir_lval_wrap(irb, parent_scope, void_inst, lval, result_loc);
4512 }5557 }
4513 if (!is_return_from_fn)5558 if (!is_return_from_fn)
...@@ -4517,31 +5562,35 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -4517,31 +5562,35 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
4517 // only generate unconditional defers5562 // only generate unconditional defers
45185563
4519 ir_mark_gen(ir_build_add_implicit_return_type(irb, child_scope, block_node, result, nullptr));5564 ir_mark_gen(ir_build_add_implicit_return_type(irb, child_scope, block_node, result, nullptr));
5565 ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn");
5566 result_loc_ret->base.id = ResultLocIdReturn;
5567 ir_build_reset_result(irb, parent_scope, block_node, &result_loc_ret->base);
5568 ir_mark_gen(ir_build_end_expr(irb, parent_scope, block_node, result, &result_loc_ret->base));
4520 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false);5569 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false);
4521 return ir_mark_gen(ir_build_return(irb, child_scope, result->source_node, result));5570 return ir_mark_gen(ir_build_return_src(irb, child_scope, result->base.source_node, result));
4522}5571}
45235572
4524static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) {5573static IrInstSrc *ir_gen_bin_op_id(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrBinOp op_id) {
4525 Scope *inner_scope = scope;5574 Scope *inner_scope = scope;
4526 if (op_id == IrBinOpArrayCat || op_id == IrBinOpArrayMult) {5575 if (op_id == IrBinOpArrayCat || op_id == IrBinOpArrayMult) {
4527 inner_scope = create_comptime_scope(irb->codegen, node, scope);5576 inner_scope = create_comptime_scope(irb->codegen, node, scope);
4528 }5577 }
45295578
4530 IrInstruction *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, inner_scope);5579 IrInstSrc *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, inner_scope);
4531 IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, inner_scope);5580 IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, inner_scope);
45325581
4533 if (op1 == irb->codegen->invalid_instruction || op2 == irb->codegen->invalid_instruction)5582 if (op1 == irb->codegen->invalid_inst_src || op2 == irb->codegen->invalid_inst_src)
4534 return irb->codegen->invalid_instruction;5583 return irb->codegen->invalid_inst_src;
45355584
4536 return ir_build_bin_op(irb, scope, node, op_id, op1, op2, true);5585 return ir_build_bin_op(irb, scope, node, op_id, op1, op2, true);
4537}5586}
45385587
4539static IrInstruction *ir_gen_merge_err_sets(IrBuilder *irb, Scope *scope, AstNode *node) {5588static IrInstSrc *ir_gen_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
4540 IrInstruction *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);5589 IrInstSrc *op1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
4541 IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);5590 IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
45425591
4543 if (op1 == irb->codegen->invalid_instruction || op2 == irb->codegen->invalid_instruction)5592 if (op1 == irb->codegen->invalid_inst_src || op2 == irb->codegen->invalid_inst_src)
4544 return irb->codegen->invalid_instruction;5593 return irb->codegen->invalid_inst_src;
45455594
4546 // TODO only pass type_name when the || operator is the top level AST node in the var decl expr5595 // TODO only pass type_name when the || operator is the top level AST node in the var decl expr
4547 Buf bare_name = BUF_INIT;5596 Buf bare_name = BUF_INIT;
...@@ -4550,10 +5599,10 @@ static IrInstruction *ir_gen_merge_err_sets(IrBuilder *irb, Scope *scope, AstNod...@@ -4550,10 +5599,10 @@ static IrInstruction *ir_gen_merge_err_sets(IrBuilder *irb, Scope *scope, AstNod
4550 return ir_build_merge_err_sets(irb, scope, node, op1, op2, type_name);5599 return ir_build_merge_err_sets(irb, scope, node, op1, op2, type_name);
4551}5600}
45525601
4553static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) {5602static IrInstSrc *ir_gen_assign(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
4554 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);5603 IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
4555 if (lvalue == irb->codegen->invalid_instruction)5604 if (lvalue == irb->codegen->invalid_inst_src)
4556 return irb->codegen->invalid_instruction;5605 return irb->codegen->invalid_inst_src;
45575606
4558 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1, "ResultLocInstruction");5607 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1, "ResultLocInstruction");
4559 result_loc_inst->base.id = ResultLocIdInstruction;5608 result_loc_inst->base.id = ResultLocIdInstruction;
...@@ -4561,49 +5610,49 @@ static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node)...@@ -4561,49 +5610,49 @@ static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node)
4561 ir_ref_instruction(lvalue, irb->current_basic_block);5610 ir_ref_instruction(lvalue, irb->current_basic_block);
4562 ir_build_reset_result(irb, scope, node, &result_loc_inst->base);5611 ir_build_reset_result(irb, scope, node, &result_loc_inst->base);
45635612
4564 IrInstruction *rvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op2, scope, LValNone,5613 IrInstSrc *rvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op2, scope, LValNone,
4565 &result_loc_inst->base);5614 &result_loc_inst->base);
4566 if (rvalue == irb->codegen->invalid_instruction)5615 if (rvalue == irb->codegen->invalid_inst_src)
4567 return irb->codegen->invalid_instruction;5616 return irb->codegen->invalid_inst_src;
45685617
4569 return ir_build_const_void(irb, scope, node);5618 return ir_build_const_void(irb, scope, node);
4570}5619}
45715620
4572static IrInstruction *ir_gen_assign_merge_err_sets(IrBuilder *irb, Scope *scope, AstNode *node) {5621static IrInstSrc *ir_gen_assign_merge_err_sets(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
4573 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);5622 IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
4574 if (lvalue == irb->codegen->invalid_instruction)5623 if (lvalue == irb->codegen->invalid_inst_src)
4575 return lvalue;5624 return lvalue;
4576 IrInstruction *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue);5625 IrInstSrc *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue);
4577 IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);5626 IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
4578 if (op2 == irb->codegen->invalid_instruction)5627 if (op2 == irb->codegen->invalid_inst_src)
4579 return op2;5628 return op2;
4580 IrInstruction *result = ir_build_merge_err_sets(irb, scope, node, op1, op2, nullptr);5629 IrInstSrc *result = ir_build_merge_err_sets(irb, scope, node, op1, op2, nullptr);
4581 ir_build_store_ptr(irb, scope, node, lvalue, result);5630 ir_build_store_ptr(irb, scope, node, lvalue, result);
4582 return ir_build_const_void(irb, scope, node);5631 return ir_build_const_void(irb, scope, node);
4583}5632}
45845633
4585static IrInstruction *ir_gen_assign_op(IrBuilder *irb, Scope *scope, AstNode *node, IrBinOp op_id) {5634static IrInstSrc *ir_gen_assign_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrBinOp op_id) {
4586 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);5635 IrInstSrc *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
4587 if (lvalue == irb->codegen->invalid_instruction)5636 if (lvalue == irb->codegen->invalid_inst_src)
4588 return lvalue;5637 return lvalue;
4589 IrInstruction *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue);5638 IrInstSrc *op1 = ir_build_load_ptr(irb, scope, node->data.bin_op_expr.op1, lvalue);
4590 IrInstruction *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);5639 IrInstSrc *op2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
4591 if (op2 == irb->codegen->invalid_instruction)5640 if (op2 == irb->codegen->invalid_inst_src)
4592 return op2;5641 return op2;
4593 IrInstruction *result = ir_build_bin_op(irb, scope, node, op_id, op1, op2, true);5642 IrInstSrc *result = ir_build_bin_op(irb, scope, node, op_id, op1, op2, true);
4594 ir_build_store_ptr(irb, scope, node, lvalue, result);5643 ir_build_store_ptr(irb, scope, node, lvalue, result);
4595 return ir_build_const_void(irb, scope, node);5644 return ir_build_const_void(irb, scope, node);
4596}5645}
45975646
4598static IrInstruction *ir_gen_bool_or(IrBuilder *irb, Scope *scope, AstNode *node) {5647static IrInstSrc *ir_gen_bool_or(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
4599 assert(node->type == NodeTypeBinOpExpr);5648 assert(node->type == NodeTypeBinOpExpr);
46005649
4601 IrInstruction *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);5650 IrInstSrc *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
4602 if (val1 == irb->codegen->invalid_instruction)5651 if (val1 == irb->codegen->invalid_inst_src)
4603 return irb->codegen->invalid_instruction;5652 return irb->codegen->invalid_inst_src;
4604 IrBasicBlock *post_val1_block = irb->current_basic_block;5653 IrBasicBlockSrc *post_val1_block = irb->current_basic_block;
46055654
4606 IrInstruction *is_comptime;5655 IrInstSrc *is_comptime;
4607 if (ir_should_inline(irb->exec, scope)) {5656 if (ir_should_inline(irb->exec, scope)) {
4608 is_comptime = ir_build_const_bool(irb, scope, node, true);5657 is_comptime = ir_build_const_bool(irb, scope, node, true);
4609 } else {5658 } else {
...@@ -4611,41 +5660,41 @@ static IrInstruction *ir_gen_bool_or(IrBuilder *irb, Scope *scope, AstNode *node...@@ -4611,41 +5660,41 @@ static IrInstruction *ir_gen_bool_or(IrBuilder *irb, Scope *scope, AstNode *node
4611 }5660 }
46125661
4613 // block for when val1 == false5662 // block for when val1 == false
4614 IrBasicBlock *false_block = ir_create_basic_block(irb, scope, "BoolOrFalse");5663 IrBasicBlockSrc *false_block = ir_create_basic_block(irb, scope, "BoolOrFalse");
4615 // block for when val1 == true (don't even evaluate the second part)5664 // block for when val1 == true (don't even evaluate the second part)
4616 IrBasicBlock *true_block = ir_create_basic_block(irb, scope, "BoolOrTrue");5665 IrBasicBlockSrc *true_block = ir_create_basic_block(irb, scope, "BoolOrTrue");
46175666
4618 ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime);5667 ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime);
46195668
4620 ir_set_cursor_at_end_and_append_block(irb, false_block);5669 ir_set_cursor_at_end_and_append_block(irb, false_block);
4621 IrInstruction *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);5670 IrInstSrc *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
4622 if (val2 == irb->codegen->invalid_instruction)5671 if (val2 == irb->codegen->invalid_inst_src)
4623 return irb->codegen->invalid_instruction;5672 return irb->codegen->invalid_inst_src;
4624 IrBasicBlock *post_val2_block = irb->current_basic_block;5673 IrBasicBlockSrc *post_val2_block = irb->current_basic_block;
46255674
4626 ir_build_br(irb, scope, node, true_block, is_comptime);5675 ir_build_br(irb, scope, node, true_block, is_comptime);
46275676
4628 ir_set_cursor_at_end_and_append_block(irb, true_block);5677 ir_set_cursor_at_end_and_append_block(irb, true_block);
46295678
4630 IrInstruction **incoming_values = allocate<IrInstruction *>(2, "IrInstruction *");5679 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2, "IrInstSrc *");
4631 incoming_values[0] = val1;5680 incoming_values[0] = val1;
4632 incoming_values[1] = val2;5681 incoming_values[1] = val2;
4633 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");5682 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
4634 incoming_blocks[0] = post_val1_block;5683 incoming_blocks[0] = post_val1_block;
4635 incoming_blocks[1] = post_val2_block;5684 incoming_blocks[1] = post_val2_block;
46365685
4637 return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr);5686 return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr);
4638}5687}
46395688
4640static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *node) {5689static IrInstSrc *ir_gen_bool_and(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
4641 assert(node->type == NodeTypeBinOpExpr);5690 assert(node->type == NodeTypeBinOpExpr);
46425691
4643 IrInstruction *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);5692 IrInstSrc *val1 = ir_gen_node(irb, node->data.bin_op_expr.op1, scope);
4644 if (val1 == irb->codegen->invalid_instruction)5693 if (val1 == irb->codegen->invalid_inst_src)
4645 return irb->codegen->invalid_instruction;5694 return irb->codegen->invalid_inst_src;
4646 IrBasicBlock *post_val1_block = irb->current_basic_block;5695 IrBasicBlockSrc *post_val1_block = irb->current_basic_block;
46475696
4648 IrInstruction *is_comptime;5697 IrInstSrc *is_comptime;
4649 if (ir_should_inline(irb->exec, scope)) {5698 if (ir_should_inline(irb->exec, scope)) {
4650 is_comptime = ir_build_const_bool(irb, scope, node, true);5699 is_comptime = ir_build_const_bool(irb, scope, node, true);
4651 } else {5700 } else {
...@@ -4653,34 +5702,34 @@ static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -4653,34 +5702,34 @@ static IrInstruction *ir_gen_bool_and(IrBuilder *irb, Scope *scope, AstNode *nod
4653 }5702 }
46545703
4655 // block for when val1 == true5704 // block for when val1 == true
4656 IrBasicBlock *true_block = ir_create_basic_block(irb, scope, "BoolAndTrue");5705 IrBasicBlockSrc *true_block = ir_create_basic_block(irb, scope, "BoolAndTrue");
4657 // block for when val1 == false (don't even evaluate the second part)5706 // block for when val1 == false (don't even evaluate the second part)
4658 IrBasicBlock *false_block = ir_create_basic_block(irb, scope, "BoolAndFalse");5707 IrBasicBlockSrc *false_block = ir_create_basic_block(irb, scope, "BoolAndFalse");
46595708
4660 ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime);5709 ir_build_cond_br(irb, scope, node, val1, true_block, false_block, is_comptime);
46615710
4662 ir_set_cursor_at_end_and_append_block(irb, true_block);5711 ir_set_cursor_at_end_and_append_block(irb, true_block);
4663 IrInstruction *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);5712 IrInstSrc *val2 = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
4664 if (val2 == irb->codegen->invalid_instruction)5713 if (val2 == irb->codegen->invalid_inst_src)
4665 return irb->codegen->invalid_instruction;5714 return irb->codegen->invalid_inst_src;
4666 IrBasicBlock *post_val2_block = irb->current_basic_block;5715 IrBasicBlockSrc *post_val2_block = irb->current_basic_block;
46675716
4668 ir_build_br(irb, scope, node, false_block, is_comptime);5717 ir_build_br(irb, scope, node, false_block, is_comptime);
46695718
4670 ir_set_cursor_at_end_and_append_block(irb, false_block);5719 ir_set_cursor_at_end_and_append_block(irb, false_block);
46715720
4672 IrInstruction **incoming_values = allocate<IrInstruction *>(2);5721 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
4673 incoming_values[0] = val1;5722 incoming_values[0] = val1;
4674 incoming_values[1] = val2;5723 incoming_values[1] = val2;
4675 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");5724 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
4676 incoming_blocks[0] = post_val1_block;5725 incoming_blocks[0] = post_val1_block;
4677 incoming_blocks[1] = post_val2_block;5726 incoming_blocks[1] = post_val2_block;
46785727
4679 return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr);5728 return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, nullptr);
4680}5729}
46815730
4682static ResultLocPeerParent *ir_build_result_peers(IrBuilder *irb, IrInstruction *cond_br_inst,5731static ResultLocPeerParent *ir_build_result_peers(IrBuilderSrc *irb, IrInstSrc *cond_br_inst,
4683 IrBasicBlock *end_block, ResultLoc *parent, IrInstruction *is_comptime)5732 IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime)
4684{5733{
4685 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);5734 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
4686 peer_parent->base.id = ResultLocIdPeerParent;5735 peer_parent->base.id = ResultLocIdPeerParent;
...@@ -4690,17 +5739,17 @@ static ResultLocPeerParent *ir_build_result_peers(IrBuilder *irb, IrInstruction...@@ -4690,17 +5739,17 @@ static ResultLocPeerParent *ir_build_result_peers(IrBuilder *irb, IrInstruction
4690 peer_parent->is_comptime = is_comptime;5739 peer_parent->is_comptime = is_comptime;
4691 peer_parent->parent = parent;5740 peer_parent->parent = parent;
46925741
4693 IrInstruction *popped_inst = irb->current_basic_block->instruction_list.pop();5742 IrInstSrc *popped_inst = irb->current_basic_block->instruction_list.pop();
4694 ir_assert(popped_inst == cond_br_inst, cond_br_inst);5743 ir_assert(popped_inst == cond_br_inst, &cond_br_inst->base);
46955744
4696 ir_build_reset_result(irb, cond_br_inst->scope, cond_br_inst->source_node, &peer_parent->base);5745 ir_build_reset_result(irb, cond_br_inst->base.scope, cond_br_inst->base.source_node, &peer_parent->base);
4697 irb->current_basic_block->instruction_list.append(popped_inst);5746 irb->current_basic_block->instruction_list.append(popped_inst);
46985747
4699 return peer_parent;5748 return peer_parent;
4700}5749}
47015750
4702static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilder *irb, IrInstruction *cond_br_inst,5751static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilderSrc *irb, IrInstSrc *cond_br_inst,
4703 IrBasicBlock *else_block, IrBasicBlock *end_block, ResultLoc *parent, IrInstruction *is_comptime)5752 IrBasicBlockSrc *else_block, IrBasicBlockSrc *end_block, ResultLoc *parent, IrInstSrc *is_comptime)
4704{5753{
4705 ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, parent, is_comptime);5754 ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, parent, is_comptime);
47065755
...@@ -4713,7 +5762,7 @@ static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilder *irb, IrInstr...@@ -4713,7 +5762,7 @@ static ResultLocPeerParent *ir_build_binary_result_peers(IrBuilder *irb, IrInstr
4713 return peer_parent;5762 return peer_parent;
4714}5763}
47155764
4716static IrInstruction *ir_gen_orelse(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval,5765static IrInstSrc *ir_gen_orelse(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval,
4717 ResultLoc *result_loc)5766 ResultLoc *result_loc)
4718{5767{
4719 assert(node->type == NodeTypeBinOpExpr);5768 assert(node->type == NodeTypeBinOpExpr);
...@@ -4721,73 +5770,73 @@ static IrInstruction *ir_gen_orelse(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -4721,73 +5770,73 @@ static IrInstruction *ir_gen_orelse(IrBuilder *irb, Scope *parent_scope, AstNode
4721 AstNode *op1_node = node->data.bin_op_expr.op1;5770 AstNode *op1_node = node->data.bin_op_expr.op1;
4722 AstNode *op2_node = node->data.bin_op_expr.op2;5771 AstNode *op2_node = node->data.bin_op_expr.op2;
47235772
4724 IrInstruction *maybe_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr);5773 IrInstSrc *maybe_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr);
4725 if (maybe_ptr == irb->codegen->invalid_instruction)5774 if (maybe_ptr == irb->codegen->invalid_inst_src)
4726 return irb->codegen->invalid_instruction;5775 return irb->codegen->invalid_inst_src;
47275776
4728 IrInstruction *maybe_val = ir_build_load_ptr(irb, parent_scope, node, maybe_ptr);5777 IrInstSrc *maybe_val = ir_build_load_ptr(irb, parent_scope, node, maybe_ptr);
4729 IrInstruction *is_non_null = ir_build_test_nonnull(irb, parent_scope, node, maybe_val);5778 IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, parent_scope, node, maybe_val);
47305779
4731 IrInstruction *is_comptime;5780 IrInstSrc *is_comptime;
4732 if (ir_should_inline(irb->exec, parent_scope)) {5781 if (ir_should_inline(irb->exec, parent_scope)) {
4733 is_comptime = ir_build_const_bool(irb, parent_scope, node, true);5782 is_comptime = ir_build_const_bool(irb, parent_scope, node, true);
4734 } else {5783 } else {
4735 is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_non_null);5784 is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_non_null);
4736 }5785 }
47375786
4738 IrBasicBlock *ok_block = ir_create_basic_block(irb, parent_scope, "OptionalNonNull");5787 IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, parent_scope, "OptionalNonNull");
4739 IrBasicBlock *null_block = ir_create_basic_block(irb, parent_scope, "OptionalNull");5788 IrBasicBlockSrc *null_block = ir_create_basic_block(irb, parent_scope, "OptionalNull");
4740 IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "OptionalEnd");5789 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, parent_scope, "OptionalEnd");
4741 IrInstruction *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_non_null, ok_block, null_block, is_comptime);5790 IrInstSrc *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_non_null, ok_block, null_block, is_comptime);
47425791
4743 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, ok_block, end_block,5792 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, ok_block, end_block,
4744 result_loc, is_comptime);5793 result_loc, is_comptime);
47455794
4746 ir_set_cursor_at_end_and_append_block(irb, null_block);5795 ir_set_cursor_at_end_and_append_block(irb, null_block);
4747 IrInstruction *null_result = ir_gen_node_extra(irb, op2_node, parent_scope, LValNone,5796 IrInstSrc *null_result = ir_gen_node_extra(irb, op2_node, parent_scope, LValNone,
4748 &peer_parent->peers.at(0)->base);5797 &peer_parent->peers.at(0)->base);
4749 if (null_result == irb->codegen->invalid_instruction)5798 if (null_result == irb->codegen->invalid_inst_src)
4750 return irb->codegen->invalid_instruction;5799 return irb->codegen->invalid_inst_src;
4751 IrBasicBlock *after_null_block = irb->current_basic_block;5800 IrBasicBlockSrc *after_null_block = irb->current_basic_block;
4752 if (!instr_is_unreachable(null_result))5801 if (!instr_is_unreachable(null_result))
4753 ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime));5802 ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime));
47545803
4755 ir_set_cursor_at_end_and_append_block(irb, ok_block);5804 ir_set_cursor_at_end_and_append_block(irb, ok_block);
4756 IrInstruction *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, parent_scope, node, maybe_ptr, false, false);5805 IrInstSrc *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, parent_scope, node, maybe_ptr, false, false);
4757 IrInstruction *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr);5806 IrInstSrc *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr);
4758 ir_build_end_expr(irb, parent_scope, node, unwrapped_payload, &peer_parent->peers.at(1)->base);5807 ir_build_end_expr(irb, parent_scope, node, unwrapped_payload, &peer_parent->peers.at(1)->base);
4759 IrBasicBlock *after_ok_block = irb->current_basic_block;5808 IrBasicBlockSrc *after_ok_block = irb->current_basic_block;
4760 ir_build_br(irb, parent_scope, node, end_block, is_comptime);5809 ir_build_br(irb, parent_scope, node, end_block, is_comptime);
47615810
4762 ir_set_cursor_at_end_and_append_block(irb, end_block);5811 ir_set_cursor_at_end_and_append_block(irb, end_block);
4763 IrInstruction **incoming_values = allocate<IrInstruction *>(2);5812 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
4764 incoming_values[0] = null_result;5813 incoming_values[0] = null_result;
4765 incoming_values[1] = unwrapped_payload;5814 incoming_values[1] = unwrapped_payload;
4766 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");5815 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
4767 incoming_blocks[0] = after_null_block;5816 incoming_blocks[0] = after_null_block;
4768 incoming_blocks[1] = after_ok_block;5817 incoming_blocks[1] = after_ok_block;
4769 IrInstruction *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);5818 IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);
4770 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);5819 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);
4771}5820}
47725821
4773static IrInstruction *ir_gen_error_union(IrBuilder *irb, Scope *parent_scope, AstNode *node) {5822static IrInstSrc *ir_gen_error_union(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
4774 assert(node->type == NodeTypeBinOpExpr);5823 assert(node->type == NodeTypeBinOpExpr);
47755824
4776 AstNode *op1_node = node->data.bin_op_expr.op1;5825 AstNode *op1_node = node->data.bin_op_expr.op1;
4777 AstNode *op2_node = node->data.bin_op_expr.op2;5826 AstNode *op2_node = node->data.bin_op_expr.op2;
47785827
4779 IrInstruction *err_set = ir_gen_node(irb, op1_node, parent_scope);5828 IrInstSrc *err_set = ir_gen_node(irb, op1_node, parent_scope);
4780 if (err_set == irb->codegen->invalid_instruction)5829 if (err_set == irb->codegen->invalid_inst_src)
4781 return irb->codegen->invalid_instruction;5830 return irb->codegen->invalid_inst_src;
47825831
4783 IrInstruction *payload = ir_gen_node(irb, op2_node, parent_scope);5832 IrInstSrc *payload = ir_gen_node(irb, op2_node, parent_scope);
4784 if (payload == irb->codegen->invalid_instruction)5833 if (payload == irb->codegen->invalid_inst_src)
4785 return irb->codegen->invalid_instruction;5834 return irb->codegen->invalid_inst_src;
47865835
4787 return ir_build_error_union(irb, parent_scope, node, err_set, payload);5836 return ir_build_error_union(irb, parent_scope, node, err_set, payload);
4788}5837}
47895838
4790static IrInstruction *ir_gen_bin_op(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {5839static IrInstSrc *ir_gen_bin_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
4791 assert(node->type == NodeTypeBinOpExpr);5840 assert(node->type == NodeTypeBinOpExpr);
47925841
4793 BinOpType bin_op_type = node->data.bin_op_expr.bin_op;5842 BinOpType bin_op_type = node->data.bin_op_expr.bin_op;
...@@ -4880,30 +5929,30 @@ static IrInstruction *ir_gen_bin_op(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4880,30 +5929,30 @@ static IrInstruction *ir_gen_bin_op(IrBuilder *irb, Scope *scope, AstNode *node,
4880 zig_unreachable();5929 zig_unreachable();
4881}5930}
48825931
4883static IrInstruction *ir_gen_int_lit(IrBuilder *irb, Scope *scope, AstNode *node) {5932static IrInstSrc *ir_gen_int_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
4884 assert(node->type == NodeTypeIntLiteral);5933 assert(node->type == NodeTypeIntLiteral);
48855934
4886 return ir_build_const_bigint(irb, scope, node, node->data.int_literal.bigint);5935 return ir_build_const_bigint(irb, scope, node, node->data.int_literal.bigint);
4887}5936}
48885937
4889static IrInstruction *ir_gen_float_lit(IrBuilder *irb, Scope *scope, AstNode *node) {5938static IrInstSrc *ir_gen_float_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
4890 assert(node->type == NodeTypeFloatLiteral);5939 assert(node->type == NodeTypeFloatLiteral);
48915940
4892 if (node->data.float_literal.overflow) {5941 if (node->data.float_literal.overflow) {
4893 add_node_error(irb->codegen, node, buf_sprintf("float literal out of range of any type"));5942 add_node_error(irb->codegen, node, buf_sprintf("float literal out of range of any type"));
4894 return irb->codegen->invalid_instruction;5943 return irb->codegen->invalid_inst_src;
4895 }5944 }
48965945
4897 return ir_build_const_bigfloat(irb, scope, node, node->data.float_literal.bigfloat);5946 return ir_build_const_bigfloat(irb, scope, node, node->data.float_literal.bigfloat);
4898}5947}
48995948
4900static IrInstruction *ir_gen_char_lit(IrBuilder *irb, Scope *scope, AstNode *node) {5949static IrInstSrc *ir_gen_char_lit(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
4901 assert(node->type == NodeTypeCharLiteral);5950 assert(node->type == NodeTypeCharLiteral);
49025951
4903 return ir_build_const_uint(irb, scope, node, node->data.char_literal.value);5952 return ir_build_const_uint(irb, scope, node, node->data.char_literal.value);
4904}5953}
49055954
4906static IrInstruction *ir_gen_null_literal(IrBuilder *irb, Scope *scope, AstNode *node) {5955static IrInstSrc *ir_gen_null_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
4907 assert(node->type == NodeTypeNullLiteral);5956 assert(node->type == NodeTypeNullLiteral);
49085957
4909 return ir_build_const_null(irb, scope, node);5958 return ir_build_const_null(irb, scope, node);
...@@ -4921,11 +5970,11 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode...@@ -4921,11 +5970,11 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode
4921 init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base);5970 init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base);
4922 tld_var->base.resolution = TldResolutionInvalid;5971 tld_var->base.resolution = TldResolutionInvalid;
4923 tld_var->var = add_variable(g, node, &scope_decls->base, var_name, false,5972 tld_var->var = add_variable(g, node, &scope_decls->base, var_name, false,
4924 g->invalid_instruction->value, &tld_var->base, g->builtin_types.entry_invalid);5973 g->invalid_inst_gen->value, &tld_var->base, g->builtin_types.entry_invalid);
4925 scope_decls->decl_table.put(var_name, &tld_var->base);5974 scope_decls->decl_table.put(var_name, &tld_var->base);
4926}5975}
49275976
4928static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {5977static IrInstSrc *ir_gen_symbol(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
4929 Error err;5978 Error err;
4930 assert(node->type == NodeTypeSymbol);5979 assert(node->type == NodeTypeSymbol);
49315980
...@@ -4933,15 +5982,16 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4933,15 +5982,16 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
49335982
4934 if (buf_eql_str(variable_name, "_")) {5983 if (buf_eql_str(variable_name, "_")) {
4935 if (lval == LValPtr) {5984 if (lval == LValPtr) {
4936 IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, node);5985 IrInstSrcConst *const_instruction = ir_build_instruction<IrInstSrcConst>(irb, scope, node);
4937 const_instruction->base.value->type = get_pointer_to_type(irb->codegen,5986 const_instruction->value = create_const_vals(1);
5987 const_instruction->value->type = get_pointer_to_type(irb->codegen,
4938 irb->codegen->builtin_types.entry_void, false);5988 irb->codegen->builtin_types.entry_void, false);
4939 const_instruction->base.value->special = ConstValSpecialStatic;5989 const_instruction->value->special = ConstValSpecialStatic;
4940 const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialDiscard;5990 const_instruction->value->data.x_ptr.special = ConstPtrSpecialDiscard;
4941 return &const_instruction->base;5991 return &const_instruction->base;
4942 } else {5992 } else {
4943 add_node_error(irb->codegen, node, buf_sprintf("`_` may only be used to assign things to"));5993 add_node_error(irb->codegen, node, buf_sprintf("`_` may only be used to assign things to"));
4944 return irb->codegen->invalid_instruction;5994 return irb->codegen->invalid_inst_src;
4945 }5995 }
4946 }5996 }
49475997
...@@ -4951,13 +6001,13 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4951,13 +6001,13 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
4951 add_node_error(irb->codegen, node,6001 add_node_error(irb->codegen, node,
4952 buf_sprintf("primitive integer type '%s' exceeds maximum bit width of 65535",6002 buf_sprintf("primitive integer type '%s' exceeds maximum bit width of 65535",
4953 buf_ptr(variable_name)));6003 buf_ptr(variable_name)));
4954 return irb->codegen->invalid_instruction;6004 return irb->codegen->invalid_inst_src;
4955 }6005 }
4956 assert(err == ErrorPrimitiveTypeNotFound);6006 assert(err == ErrorPrimitiveTypeNotFound);
4957 } else {6007 } else {
4958 IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_type);6008 IrInstSrc *value = ir_build_const_type(irb, scope, node, primitive_type);
4959 if (lval == LValPtr) {6009 if (lval == LValPtr) {
4960 return ir_build_ref(irb, scope, node, value, false, false);6010 return ir_build_ref_src(irb, scope, node, value, false, false);
4961 } else {6011 } else {
4962 return ir_expr_wrap(irb, scope, value, result_loc);6012 return ir_expr_wrap(irb, scope, value, result_loc);
4963 }6013 }
...@@ -4966,7 +6016,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4966,7 +6016,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
4966 ScopeFnDef *crossed_fndef_scope;6016 ScopeFnDef *crossed_fndef_scope;
4967 ZigVar *var = find_variable(irb->codegen, scope, variable_name, &crossed_fndef_scope);6017 ZigVar *var = find_variable(irb->codegen, scope, variable_name, &crossed_fndef_scope);
4968 if (var) {6018 if (var) {
4969 IrInstruction *var_ptr = ir_build_var_ptr_x(irb, scope, node, var, crossed_fndef_scope);6019 IrInstSrc *var_ptr = ir_build_var_ptr_x(irb, scope, node, var, crossed_fndef_scope);
4970 if (lval == LValPtr) {6020 if (lval == LValPtr) {
4971 return var_ptr;6021 return var_ptr;
4972 } else {6022 } else {
...@@ -4976,7 +6026,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4976,7 +6026,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
49766026
4977 Tld *tld = find_decl(irb->codegen, scope, variable_name);6027 Tld *tld = find_decl(irb->codegen, scope, variable_name);
4978 if (tld) {6028 if (tld) {
4979 IrInstruction *decl_ref = ir_build_decl_ref(irb, scope, node, tld, lval);6029 IrInstSrc *decl_ref = ir_build_decl_ref(irb, scope, node, tld, lval);
4980 if (lval == LValPtr) {6030 if (lval == LValPtr) {
4981 return decl_ref;6031 return decl_ref;
4982 } else {6032 } else {
...@@ -4987,50 +6037,50 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -4987,50 +6037,50 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
4987 if (get_container_scope(node->owner)->any_imports_failed) {6037 if (get_container_scope(node->owner)->any_imports_failed) {
4988 // skip the error message since we had a failing import in this file6038 // skip the error message since we had a failing import in this file
4989 // if an import breaks we don't need redundant undeclared identifier errors6039 // if an import breaks we don't need redundant undeclared identifier errors
4990 return irb->codegen->invalid_instruction;6040 return irb->codegen->invalid_inst_src;
4991 }6041 }
49926042
4993 return ir_build_undeclared_identifier(irb, scope, node, variable_name);6043 return ir_build_undeclared_identifier(irb, scope, node, variable_name);
4994}6044}
49956045
4996static IrInstruction *ir_gen_array_access(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,6046static IrInstSrc *ir_gen_array_access(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
4997 ResultLoc *result_loc)6047 ResultLoc *result_loc)
4998{6048{
4999 assert(node->type == NodeTypeArrayAccessExpr);6049 assert(node->type == NodeTypeArrayAccessExpr);
50006050
5001 AstNode *array_ref_node = node->data.array_access_expr.array_ref_expr;6051 AstNode *array_ref_node = node->data.array_access_expr.array_ref_expr;
5002 IrInstruction *array_ref_instruction = ir_gen_node_extra(irb, array_ref_node, scope, LValPtr, nullptr);6052 IrInstSrc *array_ref_instruction = ir_gen_node_extra(irb, array_ref_node, scope, LValPtr, nullptr);
5003 if (array_ref_instruction == irb->codegen->invalid_instruction)6053 if (array_ref_instruction == irb->codegen->invalid_inst_src)
5004 return array_ref_instruction;6054 return array_ref_instruction;
50056055
5006 AstNode *subscript_node = node->data.array_access_expr.subscript;6056 AstNode *subscript_node = node->data.array_access_expr.subscript;
5007 IrInstruction *subscript_instruction = ir_gen_node(irb, subscript_node, scope);6057 IrInstSrc *subscript_instruction = ir_gen_node(irb, subscript_node, scope);
5008 if (subscript_instruction == irb->codegen->invalid_instruction)6058 if (subscript_instruction == irb->codegen->invalid_inst_src)
5009 return subscript_instruction;6059 return subscript_instruction;
50106060
5011 IrInstruction *ptr_instruction = ir_build_elem_ptr(irb, scope, node, array_ref_instruction,6061 IrInstSrc *ptr_instruction = ir_build_elem_ptr(irb, scope, node, array_ref_instruction,
5012 subscript_instruction, true, PtrLenSingle, nullptr);6062 subscript_instruction, true, PtrLenSingle, nullptr);
5013 if (lval == LValPtr)6063 if (lval == LValPtr)
5014 return ptr_instruction;6064 return ptr_instruction;
50156065
5016 IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);6066 IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);
5017 return ir_expr_wrap(irb, scope, load_ptr, result_loc);6067 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
5018}6068}
50196069
5020static IrInstruction *ir_gen_field_access(IrBuilder *irb, Scope *scope, AstNode *node) {6070static IrInstSrc *ir_gen_field_access(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
5021 assert(node->type == NodeTypeFieldAccessExpr);6071 assert(node->type == NodeTypeFieldAccessExpr);
50226072
5023 AstNode *container_ref_node = node->data.field_access_expr.struct_expr;6073 AstNode *container_ref_node = node->data.field_access_expr.struct_expr;
5024 Buf *field_name = node->data.field_access_expr.field_name;6074 Buf *field_name = node->data.field_access_expr.field_name;
50256075
5026 IrInstruction *container_ref_instruction = ir_gen_node_extra(irb, container_ref_node, scope, LValPtr, nullptr);6076 IrInstSrc *container_ref_instruction = ir_gen_node_extra(irb, container_ref_node, scope, LValPtr, nullptr);
5027 if (container_ref_instruction == irb->codegen->invalid_instruction)6077 if (container_ref_instruction == irb->codegen->invalid_inst_src)
5028 return container_ref_instruction;6078 return container_ref_instruction;
50296079
5030 return ir_build_field_ptr(irb, scope, node, container_ref_instruction, field_name, false);6080 return ir_build_field_ptr(irb, scope, node, container_ref_instruction, field_name, false);
5031}6081}
50326082
5033static IrInstruction *ir_gen_overflow_op(IrBuilder *irb, Scope *scope, AstNode *node, IrOverflowOp op) {6083static IrInstSrc *ir_gen_overflow_op(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrOverflowOp op) {
5034 assert(node->type == NodeTypeFnCallExpr);6084 assert(node->type == NodeTypeFnCallExpr);
50356085
5036 AstNode *type_node = node->data.fn_call_expr.params.at(0);6086 AstNode *type_node = node->data.fn_call_expr.params.at(0);
...@@ -5039,26 +6089,26 @@ static IrInstruction *ir_gen_overflow_op(IrBuilder *irb, Scope *scope, AstNode *...@@ -5039,26 +6089,26 @@ static IrInstruction *ir_gen_overflow_op(IrBuilder *irb, Scope *scope, AstNode *
5039 AstNode *result_ptr_node = node->data.fn_call_expr.params.at(3);6089 AstNode *result_ptr_node = node->data.fn_call_expr.params.at(3);
50406090
50416091
5042 IrInstruction *type_value = ir_gen_node(irb, type_node, scope);6092 IrInstSrc *type_value = ir_gen_node(irb, type_node, scope);
5043 if (type_value == irb->codegen->invalid_instruction)6093 if (type_value == irb->codegen->invalid_inst_src)
5044 return irb->codegen->invalid_instruction;6094 return irb->codegen->invalid_inst_src;
50456095
5046 IrInstruction *op1 = ir_gen_node(irb, op1_node, scope);6096 IrInstSrc *op1 = ir_gen_node(irb, op1_node, scope);
5047 if (op1 == irb->codegen->invalid_instruction)6097 if (op1 == irb->codegen->invalid_inst_src)
5048 return irb->codegen->invalid_instruction;6098 return irb->codegen->invalid_inst_src;
50496099
5050 IrInstruction *op2 = ir_gen_node(irb, op2_node, scope);6100 IrInstSrc *op2 = ir_gen_node(irb, op2_node, scope);
5051 if (op2 == irb->codegen->invalid_instruction)6101 if (op2 == irb->codegen->invalid_inst_src)
5052 return irb->codegen->invalid_instruction;6102 return irb->codegen->invalid_inst_src;
50536103
5054 IrInstruction *result_ptr = ir_gen_node(irb, result_ptr_node, scope);6104 IrInstSrc *result_ptr = ir_gen_node(irb, result_ptr_node, scope);
5055 if (result_ptr == irb->codegen->invalid_instruction)6105 if (result_ptr == irb->codegen->invalid_inst_src)
5056 return irb->codegen->invalid_instruction;6106 return irb->codegen->invalid_inst_src;
50576107
5058 return ir_build_overflow_op(irb, scope, node, op, type_value, op1, op2, result_ptr, nullptr);6108 return ir_build_overflow_op_src(irb, scope, node, op, type_value, op1, op2, result_ptr);
5059}6109}
50606110
5061static IrInstruction *ir_gen_mul_add(IrBuilder *irb, Scope *scope, AstNode *node) {6111static IrInstSrc *ir_gen_mul_add(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
5062 assert(node->type == NodeTypeFnCallExpr);6112 assert(node->type == NodeTypeFnCallExpr);
50636113
5064 AstNode *type_node = node->data.fn_call_expr.params.at(0);6114 AstNode *type_node = node->data.fn_call_expr.params.at(0);
...@@ -5066,26 +6116,26 @@ static IrInstruction *ir_gen_mul_add(IrBuilder *irb, Scope *scope, AstNode *node...@@ -5066,26 +6116,26 @@ static IrInstruction *ir_gen_mul_add(IrBuilder *irb, Scope *scope, AstNode *node
5066 AstNode *op2_node = node->data.fn_call_expr.params.at(2);6116 AstNode *op2_node = node->data.fn_call_expr.params.at(2);
5067 AstNode *op3_node = node->data.fn_call_expr.params.at(3);6117 AstNode *op3_node = node->data.fn_call_expr.params.at(3);
50686118
5069 IrInstruction *type_value = ir_gen_node(irb, type_node, scope);6119 IrInstSrc *type_value = ir_gen_node(irb, type_node, scope);
5070 if (type_value == irb->codegen->invalid_instruction)6120 if (type_value == irb->codegen->invalid_inst_src)
5071 return irb->codegen->invalid_instruction;6121 return irb->codegen->invalid_inst_src;
50726122
5073 IrInstruction *op1 = ir_gen_node(irb, op1_node, scope);6123 IrInstSrc *op1 = ir_gen_node(irb, op1_node, scope);
5074 if (op1 == irb->codegen->invalid_instruction)6124 if (op1 == irb->codegen->invalid_inst_src)
5075 return irb->codegen->invalid_instruction;6125 return irb->codegen->invalid_inst_src;
50766126
5077 IrInstruction *op2 = ir_gen_node(irb, op2_node, scope);6127 IrInstSrc *op2 = ir_gen_node(irb, op2_node, scope);
5078 if (op2 == irb->codegen->invalid_instruction)6128 if (op2 == irb->codegen->invalid_inst_src)
5079 return irb->codegen->invalid_instruction;6129 return irb->codegen->invalid_inst_src;
50806130
5081 IrInstruction *op3 = ir_gen_node(irb, op3_node, scope);6131 IrInstSrc *op3 = ir_gen_node(irb, op3_node, scope);
5082 if (op3 == irb->codegen->invalid_instruction)6132 if (op3 == irb->codegen->invalid_inst_src)
5083 return irb->codegen->invalid_instruction;6133 return irb->codegen->invalid_inst_src;
50846134
5085 return ir_build_mul_add(irb, scope, node, type_value, op1, op2, op3);6135 return ir_build_mul_add_src(irb, scope, node, type_value, op1, op2, op3);
5086}6136}
50876137
5088static IrInstruction *ir_gen_this(IrBuilder *irb, Scope *orig_scope, AstNode *node) {6138static IrInstSrc *ir_gen_this(IrBuilderSrc *irb, Scope *orig_scope, AstNode *node) {
5089 for (Scope *it_scope = orig_scope; it_scope != nullptr; it_scope = it_scope->parent) {6139 for (Scope *it_scope = orig_scope; it_scope != nullptr; it_scope = it_scope->parent) {
5090 if (it_scope->id == ScopeIdDecls) {6140 if (it_scope->id == ScopeIdDecls) {
5091 ScopeDecls *decls_scope = (ScopeDecls *)it_scope;6141 ScopeDecls *decls_scope = (ScopeDecls *)it_scope;
...@@ -5100,7 +6150,7 @@ static IrInstruction *ir_gen_this(IrBuilder *irb, Scope *orig_scope, AstNode *no...@@ -5100,7 +6150,7 @@ static IrInstruction *ir_gen_this(IrBuilder *irb, Scope *orig_scope, AstNode *no
5100 zig_unreachable();6150 zig_unreachable();
5101}6151}
51026152
5103static IrInstruction *ir_gen_async_call(IrBuilder *irb, Scope *scope, AstNode *await_node, AstNode *call_node,6153static IrInstSrc *ir_gen_async_call(IrBuilderSrc *irb, Scope *scope, AstNode *await_node, AstNode *call_node,
5104 LVal lval, ResultLoc *result_loc)6154 LVal lval, ResultLoc *result_loc)
5105{6155{
5106 size_t arg_offset = 3;6156 size_t arg_offset = 3;
...@@ -5108,71 +6158,71 @@ static IrInstruction *ir_gen_async_call(IrBuilder *irb, Scope *scope, AstNode *a...@@ -5108,71 +6158,71 @@ static IrInstruction *ir_gen_async_call(IrBuilder *irb, Scope *scope, AstNode *a
5108 add_node_error(irb->codegen, call_node,6158 add_node_error(irb->codegen, call_node,
5109 buf_sprintf("expected at least %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize,6159 buf_sprintf("expected at least %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize,
5110 arg_offset, call_node->data.fn_call_expr.params.length));6160 arg_offset, call_node->data.fn_call_expr.params.length));
5111 return irb->codegen->invalid_instruction;6161 return irb->codegen->invalid_inst_src;
5112 }6162 }
51136163
5114 AstNode *bytes_node = call_node->data.fn_call_expr.params.at(0);6164 AstNode *bytes_node = call_node->data.fn_call_expr.params.at(0);
5115 IrInstruction *bytes = ir_gen_node(irb, bytes_node, scope);6165 IrInstSrc *bytes = ir_gen_node(irb, bytes_node, scope);
5116 if (bytes == irb->codegen->invalid_instruction)6166 if (bytes == irb->codegen->invalid_inst_src)
5117 return bytes;6167 return bytes;
51186168
5119 AstNode *ret_ptr_node = call_node->data.fn_call_expr.params.at(1);6169 AstNode *ret_ptr_node = call_node->data.fn_call_expr.params.at(1);
5120 IrInstruction *ret_ptr = ir_gen_node(irb, ret_ptr_node, scope);6170 IrInstSrc *ret_ptr = ir_gen_node(irb, ret_ptr_node, scope);
5121 if (ret_ptr == irb->codegen->invalid_instruction)6171 if (ret_ptr == irb->codegen->invalid_inst_src)
5122 return ret_ptr;6172 return ret_ptr;
51236173
5124 AstNode *fn_ref_node = call_node->data.fn_call_expr.params.at(2);6174 AstNode *fn_ref_node = call_node->data.fn_call_expr.params.at(2);
5125 IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope);6175 IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
5126 if (fn_ref == irb->codegen->invalid_instruction)6176 if (fn_ref == irb->codegen->invalid_inst_src)
5127 return fn_ref;6177 return fn_ref;
51286178
5129 size_t arg_count = call_node->data.fn_call_expr.params.length - arg_offset;6179 size_t arg_count = call_node->data.fn_call_expr.params.length - arg_offset;
5130 IrInstruction **args = allocate<IrInstruction*>(arg_count);6180 IrInstSrc **args = allocate<IrInstSrc*>(arg_count);
5131 for (size_t i = 0; i < arg_count; i += 1) {6181 for (size_t i = 0; i < arg_count; i += 1) {
5132 AstNode *arg_node = call_node->data.fn_call_expr.params.at(i + arg_offset);6182 AstNode *arg_node = call_node->data.fn_call_expr.params.at(i + arg_offset);
5133 IrInstruction *arg = ir_gen_node(irb, arg_node, scope);6183 IrInstSrc *arg = ir_gen_node(irb, arg_node, scope);
5134 if (arg == irb->codegen->invalid_instruction)6184 if (arg == irb->codegen->invalid_inst_src)
5135 return arg;6185 return arg;
5136 args[i] = arg;6186 args[i] = arg;
5137 }6187 }
51386188
5139 CallModifier modifier = (await_node == nullptr) ? CallModifierAsync : CallModifierNone;6189 CallModifier modifier = (await_node == nullptr) ? CallModifierAsync : CallModifierNone;
5140 bool is_async_call_builtin = true;6190 bool is_async_call_builtin = true;
5141 IrInstruction *call = ir_build_call_src(irb, scope, call_node, nullptr, fn_ref, arg_count, args,6191 IrInstSrc *call = ir_build_call_src(irb, scope, call_node, nullptr, fn_ref, arg_count, args,
5142 ret_ptr, modifier, is_async_call_builtin, bytes, result_loc);6192 ret_ptr, modifier, is_async_call_builtin, bytes, result_loc);
5143 return ir_lval_wrap(irb, scope, call, lval, result_loc);6193 return ir_lval_wrap(irb, scope, call, lval, result_loc);
5144}6194}
51456195
5146static IrInstruction *ir_gen_fn_call_with_args(IrBuilder *irb, Scope *scope, AstNode *source_node,6196static IrInstSrc *ir_gen_fn_call_with_args(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
5147 AstNode *fn_ref_node, CallModifier modifier, IrInstruction *options,6197 AstNode *fn_ref_node, CallModifier modifier, IrInstSrc *options,
5148 AstNode **args_ptr, size_t args_len, LVal lval, ResultLoc *result_loc)6198 AstNode **args_ptr, size_t args_len, LVal lval, ResultLoc *result_loc)
5149{6199{
5150 IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope);6200 IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
5151 if (fn_ref == irb->codegen->invalid_instruction)6201 if (fn_ref == irb->codegen->invalid_inst_src)
5152 return fn_ref;6202 return fn_ref;
51536203
5154 IrInstruction *fn_type = ir_build_typeof(irb, scope, source_node, fn_ref);6204 IrInstSrc *fn_type = ir_build_typeof(irb, scope, source_node, fn_ref);
51556205
5156 IrInstruction **args = allocate<IrInstruction*>(args_len);6206 IrInstSrc **args = allocate<IrInstSrc*>(args_len);
5157 for (size_t i = 0; i < args_len; i += 1) {6207 for (size_t i = 0; i < args_len; i += 1) {
5158 AstNode *arg_node = args_ptr[i];6208 AstNode *arg_node = args_ptr[i];
51596209
5160 IrInstruction *arg_index = ir_build_const_usize(irb, scope, arg_node, i);6210 IrInstSrc *arg_index = ir_build_const_usize(irb, scope, arg_node, i);
5161 IrInstruction *arg_type = ir_build_arg_type(irb, scope, source_node, fn_type, arg_index, true);6211 IrInstSrc *arg_type = ir_build_arg_type(irb, scope, source_node, fn_type, arg_index, true);
5162 ResultLoc *no_result = no_result_loc();6212 ResultLoc *no_result = no_result_loc();
5163 ir_build_reset_result(irb, scope, source_node, no_result);6213 ir_build_reset_result(irb, scope, source_node, no_result);
5164 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, arg_type, no_result);6214 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, arg_type, no_result);
51656215
5166 IrInstruction *arg = ir_gen_node_extra(irb, arg_node, scope, LValNone, &result_loc_cast->base);6216 IrInstSrc *arg = ir_gen_node_extra(irb, arg_node, scope, LValNone, &result_loc_cast->base);
5167 if (arg == irb->codegen->invalid_instruction)6217 if (arg == irb->codegen->invalid_inst_src)
5168 return arg;6218 return arg;
51696219
5170 args[i] = ir_build_implicit_cast(irb, scope, arg_node, arg, result_loc_cast);6220 args[i] = ir_build_implicit_cast(irb, scope, arg_node, arg, result_loc_cast);
5171 }6221 }
51726222
5173 IrInstruction *fn_call;6223 IrInstSrc *fn_call;
5174 if (options != nullptr) {6224 if (options != nullptr) {
5175 fn_call = ir_build_call_src_args(irb, scope, source_node, options, fn_ref, args, args_len, result_loc);6225 fn_call = ir_build_call_args(irb, scope, source_node, options, fn_ref, args, args_len, result_loc);
5176 } else {6226 } else {
5177 fn_call = ir_build_call_src(irb, scope, source_node, nullptr, fn_ref, args_len, args, nullptr,6227 fn_call = ir_build_call_src(irb, scope, source_node, nullptr, fn_ref, args_len, args, nullptr,
5178 modifier, false, nullptr, result_loc);6228 modifier, false, nullptr, result_loc);
...@@ -5180,7 +6230,7 @@ static IrInstruction *ir_gen_fn_call_with_args(IrBuilder *irb, Scope *scope, Ast...@@ -5180,7 +6230,7 @@ static IrInstruction *ir_gen_fn_call_with_args(IrBuilder *irb, Scope *scope, Ast
5180 return ir_lval_wrap(irb, scope, fn_call, lval, result_loc);6230 return ir_lval_wrap(irb, scope, fn_call, lval, result_loc);
5181}6231}
51826232
5183static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,6233static IrInstSrc *ir_gen_builtin_fn_call(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
5184 ResultLoc *result_loc)6234 ResultLoc *result_loc)
5185{6235{
5186 assert(node->type == NodeTypeFnCallExpr);6236 assert(node->type == NodeTypeFnCallExpr);
...@@ -5192,7 +6242,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -5192,7 +6242,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
5192 if (!entry) {6242 if (!entry) {
5193 add_node_error(irb->codegen, node,6243 add_node_error(irb->codegen, node,
5194 buf_sprintf("invalid builtin function: '%s'", buf_ptr(name)));6244 buf_sprintf("invalid builtin function: '%s'", buf_ptr(name)));
5195 return irb->codegen->invalid_instruction;6245 return irb->codegen->invalid_inst_src;
5196 }6246 }
51976247
5198 BuiltinFnEntry *builtin_fn = entry->value;6248 BuiltinFnEntry *builtin_fn = entry->value;
...@@ -5202,7 +6252,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -5202,7 +6252,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
5202 add_node_error(irb->codegen, node,6252 add_node_error(irb->codegen, node,
5203 buf_sprintf("expected %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize,6253 buf_sprintf("expected %" ZIG_PRI_usize " arguments, found %" ZIG_PRI_usize,
5204 builtin_fn->param_count, actual_param_count));6254 builtin_fn->param_count, actual_param_count));
5205 return irb->codegen->invalid_instruction;6255 return irb->codegen->invalid_inst_src;
5206 }6256 }
52076257
5208 switch (builtin_fn->id) {6258 switch (builtin_fn->id) {
...@@ -5213,197 +6263,197 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -5213,197 +6263,197 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
5213 Scope *sub_scope = create_typeof_scope(irb->codegen, node, scope);6263 Scope *sub_scope = create_typeof_scope(irb->codegen, node, scope);
52146264
5215 AstNode *arg_node = node->data.fn_call_expr.params.at(0);6265 AstNode *arg_node = node->data.fn_call_expr.params.at(0);
5216 IrInstruction *arg = ir_gen_node(irb, arg_node, sub_scope);6266 IrInstSrc *arg = ir_gen_node(irb, arg_node, sub_scope);
5217 if (arg == irb->codegen->invalid_instruction)6267 if (arg == irb->codegen->invalid_inst_src)
5218 return arg;6268 return arg;
52196269
5220 IrInstruction *type_of = ir_build_typeof(irb, scope, node, arg);6270 IrInstSrc *type_of = ir_build_typeof(irb, scope, node, arg);
5221 return ir_lval_wrap(irb, scope, type_of, lval, result_loc);6271 return ir_lval_wrap(irb, scope, type_of, lval, result_loc);
5222 }6272 }
5223 case BuiltinFnIdSetCold:6273 case BuiltinFnIdSetCold:
5224 {6274 {
5225 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6275 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5226 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6276 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5227 if (arg0_value == irb->codegen->invalid_instruction)6277 if (arg0_value == irb->codegen->invalid_inst_src)
5228 return arg0_value;6278 return arg0_value;
52296279
5230 IrInstruction *set_cold = ir_build_set_cold(irb, scope, node, arg0_value);6280 IrInstSrc *set_cold = ir_build_set_cold(irb, scope, node, arg0_value);
5231 return ir_lval_wrap(irb, scope, set_cold, lval, result_loc);6281 return ir_lval_wrap(irb, scope, set_cold, lval, result_loc);
5232 }6282 }
5233 case BuiltinFnIdSetRuntimeSafety:6283 case BuiltinFnIdSetRuntimeSafety:
5234 {6284 {
5235 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6285 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5236 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6286 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5237 if (arg0_value == irb->codegen->invalid_instruction)6287 if (arg0_value == irb->codegen->invalid_inst_src)
5238 return arg0_value;6288 return arg0_value;
52396289
5240 IrInstruction *set_safety = ir_build_set_runtime_safety(irb, scope, node, arg0_value);6290 IrInstSrc *set_safety = ir_build_set_runtime_safety(irb, scope, node, arg0_value);
5241 return ir_lval_wrap(irb, scope, set_safety, lval, result_loc);6291 return ir_lval_wrap(irb, scope, set_safety, lval, result_loc);
5242 }6292 }
5243 case BuiltinFnIdSetFloatMode:6293 case BuiltinFnIdSetFloatMode:
5244 {6294 {
5245 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6295 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5246 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6296 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5247 if (arg0_value == irb->codegen->invalid_instruction)6297 if (arg0_value == irb->codegen->invalid_inst_src)
5248 return arg0_value;6298 return arg0_value;
52496299
5250 IrInstruction *set_float_mode = ir_build_set_float_mode(irb, scope, node, arg0_value);6300 IrInstSrc *set_float_mode = ir_build_set_float_mode(irb, scope, node, arg0_value);
5251 return ir_lval_wrap(irb, scope, set_float_mode, lval, result_loc);6301 return ir_lval_wrap(irb, scope, set_float_mode, lval, result_loc);
5252 }6302 }
5253 case BuiltinFnIdSizeof:6303 case BuiltinFnIdSizeof:
5254 case BuiltinFnIdBitSizeof:6304 case BuiltinFnIdBitSizeof:
5255 {6305 {
5256 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6306 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5257 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6307 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5258 if (arg0_value == irb->codegen->invalid_instruction)6308 if (arg0_value == irb->codegen->invalid_inst_src)
5259 return arg0_value;6309 return arg0_value;
52606310
5261 IrInstruction *size_of = ir_build_size_of(irb, scope, node, arg0_value, builtin_fn->id == BuiltinFnIdBitSizeof);6311 IrInstSrc *size_of = ir_build_size_of(irb, scope, node, arg0_value, builtin_fn->id == BuiltinFnIdBitSizeof);
5262 return ir_lval_wrap(irb, scope, size_of, lval, result_loc);6312 return ir_lval_wrap(irb, scope, size_of, lval, result_loc);
5263 }6313 }
5264 case BuiltinFnIdImport:6314 case BuiltinFnIdImport:
5265 {6315 {
5266 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6316 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5267 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6317 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5268 if (arg0_value == irb->codegen->invalid_instruction)6318 if (arg0_value == irb->codegen->invalid_inst_src)
5269 return arg0_value;6319 return arg0_value;
52706320
5271 IrInstruction *import = ir_build_import(irb, scope, node, arg0_value);6321 IrInstSrc *import = ir_build_import(irb, scope, node, arg0_value);
5272 return ir_lval_wrap(irb, scope, import, lval, result_loc);6322 return ir_lval_wrap(irb, scope, import, lval, result_loc);
5273 }6323 }
5274 case BuiltinFnIdCImport:6324 case BuiltinFnIdCImport:
5275 {6325 {
5276 IrInstruction *c_import = ir_build_c_import(irb, scope, node);6326 IrInstSrc *c_import = ir_build_c_import(irb, scope, node);
5277 return ir_lval_wrap(irb, scope, c_import, lval, result_loc);6327 return ir_lval_wrap(irb, scope, c_import, lval, result_loc);
5278 }6328 }
5279 case BuiltinFnIdCInclude:6329 case BuiltinFnIdCInclude:
5280 {6330 {
5281 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6331 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5282 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6332 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5283 if (arg0_value == irb->codegen->invalid_instruction)6333 if (arg0_value == irb->codegen->invalid_inst_src)
5284 return arg0_value;6334 return arg0_value;
52856335
5286 if (!exec_c_import_buf(irb->exec)) {6336 if (!exec_c_import_buf(irb->exec)) {
5287 add_node_error(irb->codegen, node, buf_sprintf("C include valid only inside C import block"));6337 add_node_error(irb->codegen, node, buf_sprintf("C include valid only inside C import block"));
5288 return irb->codegen->invalid_instruction;6338 return irb->codegen->invalid_inst_src;
5289 }6339 }
52906340
5291 IrInstruction *c_include = ir_build_c_include(irb, scope, node, arg0_value);6341 IrInstSrc *c_include = ir_build_c_include(irb, scope, node, arg0_value);
5292 return ir_lval_wrap(irb, scope, c_include, lval, result_loc);6342 return ir_lval_wrap(irb, scope, c_include, lval, result_loc);
5293 }6343 }
5294 case BuiltinFnIdCDefine:6344 case BuiltinFnIdCDefine:
5295 {6345 {
5296 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6346 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5297 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6347 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5298 if (arg0_value == irb->codegen->invalid_instruction)6348 if (arg0_value == irb->codegen->invalid_inst_src)
5299 return arg0_value;6349 return arg0_value;
53006350
5301 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6351 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5302 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6352 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5303 if (arg1_value == irb->codegen->invalid_instruction)6353 if (arg1_value == irb->codegen->invalid_inst_src)
5304 return arg1_value;6354 return arg1_value;
53056355
5306 if (!exec_c_import_buf(irb->exec)) {6356 if (!exec_c_import_buf(irb->exec)) {
5307 add_node_error(irb->codegen, node, buf_sprintf("C define valid only inside C import block"));6357 add_node_error(irb->codegen, node, buf_sprintf("C define valid only inside C import block"));
5308 return irb->codegen->invalid_instruction;6358 return irb->codegen->invalid_inst_src;
5309 }6359 }
53106360
5311 IrInstruction *c_define = ir_build_c_define(irb, scope, node, arg0_value, arg1_value);6361 IrInstSrc *c_define = ir_build_c_define(irb, scope, node, arg0_value, arg1_value);
5312 return ir_lval_wrap(irb, scope, c_define, lval, result_loc);6362 return ir_lval_wrap(irb, scope, c_define, lval, result_loc);
5313 }6363 }
5314 case BuiltinFnIdCUndef:6364 case BuiltinFnIdCUndef:
5315 {6365 {
5316 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6366 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5317 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6367 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5318 if (arg0_value == irb->codegen->invalid_instruction)6368 if (arg0_value == irb->codegen->invalid_inst_src)
5319 return arg0_value;6369 return arg0_value;
53206370
5321 if (!exec_c_import_buf(irb->exec)) {6371 if (!exec_c_import_buf(irb->exec)) {
5322 add_node_error(irb->codegen, node, buf_sprintf("C undef valid only inside C import block"));6372 add_node_error(irb->codegen, node, buf_sprintf("C undef valid only inside C import block"));
5323 return irb->codegen->invalid_instruction;6373 return irb->codegen->invalid_inst_src;
5324 }6374 }
53256375
5326 IrInstruction *c_undef = ir_build_c_undef(irb, scope, node, arg0_value);6376 IrInstSrc *c_undef = ir_build_c_undef(irb, scope, node, arg0_value);
5327 return ir_lval_wrap(irb, scope, c_undef, lval, result_loc);6377 return ir_lval_wrap(irb, scope, c_undef, lval, result_loc);
5328 }6378 }
5329 case BuiltinFnIdCompileErr:6379 case BuiltinFnIdCompileErr:
5330 {6380 {
5331 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6381 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5332 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6382 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5333 if (arg0_value == irb->codegen->invalid_instruction)6383 if (arg0_value == irb->codegen->invalid_inst_src)
5334 return arg0_value;6384 return arg0_value;
53356385
5336 IrInstruction *compile_err = ir_build_compile_err(irb, scope, node, arg0_value);6386 IrInstSrc *compile_err = ir_build_compile_err(irb, scope, node, arg0_value);
5337 return ir_lval_wrap(irb, scope, compile_err, lval, result_loc);6387 return ir_lval_wrap(irb, scope, compile_err, lval, result_loc);
5338 }6388 }
5339 case BuiltinFnIdCompileLog:6389 case BuiltinFnIdCompileLog:
5340 {6390 {
5341 IrInstruction **args = allocate<IrInstruction*>(actual_param_count);6391 IrInstSrc **args = allocate<IrInstSrc*>(actual_param_count);
53426392
5343 for (size_t i = 0; i < actual_param_count; i += 1) {6393 for (size_t i = 0; i < actual_param_count; i += 1) {
5344 AstNode *arg_node = node->data.fn_call_expr.params.at(i);6394 AstNode *arg_node = node->data.fn_call_expr.params.at(i);
5345 args[i] = ir_gen_node(irb, arg_node, scope);6395 args[i] = ir_gen_node(irb, arg_node, scope);
5346 if (args[i] == irb->codegen->invalid_instruction)6396 if (args[i] == irb->codegen->invalid_inst_src)
5347 return irb->codegen->invalid_instruction;6397 return irb->codegen->invalid_inst_src;
5348 }6398 }
53496399
5350 IrInstruction *compile_log = ir_build_compile_log(irb, scope, node, actual_param_count, args);6400 IrInstSrc *compile_log = ir_build_compile_log(irb, scope, node, actual_param_count, args);
5351 return ir_lval_wrap(irb, scope, compile_log, lval, result_loc);6401 return ir_lval_wrap(irb, scope, compile_log, lval, result_loc);
5352 }6402 }
5353 case BuiltinFnIdErrName:6403 case BuiltinFnIdErrName:
5354 {6404 {
5355 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6405 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5356 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6406 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5357 if (arg0_value == irb->codegen->invalid_instruction)6407 if (arg0_value == irb->codegen->invalid_inst_src)
5358 return arg0_value;6408 return arg0_value;
53596409
5360 IrInstruction *err_name = ir_build_err_name(irb, scope, node, arg0_value);6410 IrInstSrc *err_name = ir_build_err_name(irb, scope, node, arg0_value);
5361 return ir_lval_wrap(irb, scope, err_name, lval, result_loc);6411 return ir_lval_wrap(irb, scope, err_name, lval, result_loc);
5362 }6412 }
5363 case BuiltinFnIdEmbedFile:6413 case BuiltinFnIdEmbedFile:
5364 {6414 {
5365 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6415 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5366 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6416 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5367 if (arg0_value == irb->codegen->invalid_instruction)6417 if (arg0_value == irb->codegen->invalid_inst_src)
5368 return arg0_value;6418 return arg0_value;
53696419
5370 IrInstruction *embed_file = ir_build_embed_file(irb, scope, node, arg0_value);6420 IrInstSrc *embed_file = ir_build_embed_file(irb, scope, node, arg0_value);
5371 return ir_lval_wrap(irb, scope, embed_file, lval, result_loc);6421 return ir_lval_wrap(irb, scope, embed_file, lval, result_loc);
5372 }6422 }
5373 case BuiltinFnIdCmpxchgWeak:6423 case BuiltinFnIdCmpxchgWeak:
5374 case BuiltinFnIdCmpxchgStrong:6424 case BuiltinFnIdCmpxchgStrong:
5375 {6425 {
5376 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6426 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5377 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6427 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5378 if (arg0_value == irb->codegen->invalid_instruction)6428 if (arg0_value == irb->codegen->invalid_inst_src)
5379 return arg0_value;6429 return arg0_value;
53806430
5381 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6431 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5382 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6432 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5383 if (arg1_value == irb->codegen->invalid_instruction)6433 if (arg1_value == irb->codegen->invalid_inst_src)
5384 return arg1_value;6434 return arg1_value;
53856435
5386 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);6436 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
5387 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);6437 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
5388 if (arg2_value == irb->codegen->invalid_instruction)6438 if (arg2_value == irb->codegen->invalid_inst_src)
5389 return arg2_value;6439 return arg2_value;
53906440
5391 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);6441 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
5392 IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope);6442 IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope);
5393 if (arg3_value == irb->codegen->invalid_instruction)6443 if (arg3_value == irb->codegen->invalid_inst_src)
5394 return arg3_value;6444 return arg3_value;
53956445
5396 AstNode *arg4_node = node->data.fn_call_expr.params.at(4);6446 AstNode *arg4_node = node->data.fn_call_expr.params.at(4);
5397 IrInstruction *arg4_value = ir_gen_node(irb, arg4_node, scope);6447 IrInstSrc *arg4_value = ir_gen_node(irb, arg4_node, scope);
5398 if (arg4_value == irb->codegen->invalid_instruction)6448 if (arg4_value == irb->codegen->invalid_inst_src)
5399 return arg4_value;6449 return arg4_value;
54006450
5401 AstNode *arg5_node = node->data.fn_call_expr.params.at(5);6451 AstNode *arg5_node = node->data.fn_call_expr.params.at(5);
5402 IrInstruction *arg5_value = ir_gen_node(irb, arg5_node, scope);6452 IrInstSrc *arg5_value = ir_gen_node(irb, arg5_node, scope);
5403 if (arg5_value == irb->codegen->invalid_instruction)6453 if (arg5_value == irb->codegen->invalid_inst_src)
5404 return arg5_value;6454 return arg5_value;
54056455
5406 IrInstruction *cmpxchg = ir_build_cmpxchg_src(irb, scope, node, arg0_value, arg1_value,6456 IrInstSrc *cmpxchg = ir_build_cmpxchg_src(irb, scope, node, arg0_value, arg1_value,
5407 arg2_value, arg3_value, arg4_value, arg5_value, (builtin_fn->id == BuiltinFnIdCmpxchgWeak),6457 arg2_value, arg3_value, arg4_value, arg5_value, (builtin_fn->id == BuiltinFnIdCmpxchgWeak),
5408 result_loc);6458 result_loc);
5409 return ir_lval_wrap(irb, scope, cmpxchg, lval, result_loc);6459 return ir_lval_wrap(irb, scope, cmpxchg, lval, result_loc);
...@@ -5411,86 +6461,86 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -5411,86 +6461,86 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
5411 case BuiltinFnIdFence:6461 case BuiltinFnIdFence:
5412 {6462 {
5413 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6463 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5414 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6464 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5415 if (arg0_value == irb->codegen->invalid_instruction)6465 if (arg0_value == irb->codegen->invalid_inst_src)
5416 return arg0_value;6466 return arg0_value;
54176467
5418 IrInstruction *fence = ir_build_fence(irb, scope, node, arg0_value, AtomicOrderUnordered);6468 IrInstSrc *fence = ir_build_fence(irb, scope, node, arg0_value);
5419 return ir_lval_wrap(irb, scope, fence, lval, result_loc);6469 return ir_lval_wrap(irb, scope, fence, lval, result_loc);
5420 }6470 }
5421 case BuiltinFnIdDivExact:6471 case BuiltinFnIdDivExact:
5422 {6472 {
5423 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6473 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5424 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6474 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5425 if (arg0_value == irb->codegen->invalid_instruction)6475 if (arg0_value == irb->codegen->invalid_inst_src)
5426 return arg0_value;6476 return arg0_value;
54276477
5428 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6478 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5429 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6479 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5430 if (arg1_value == irb->codegen->invalid_instruction)6480 if (arg1_value == irb->codegen->invalid_inst_src)
5431 return arg1_value;6481 return arg1_value;
54326482
5433 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivExact, arg0_value, arg1_value, true);6483 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivExact, arg0_value, arg1_value, true);
5434 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);6484 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
5435 }6485 }
5436 case BuiltinFnIdDivTrunc:6486 case BuiltinFnIdDivTrunc:
5437 {6487 {
5438 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6488 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5439 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6489 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5440 if (arg0_value == irb->codegen->invalid_instruction)6490 if (arg0_value == irb->codegen->invalid_inst_src)
5441 return arg0_value;6491 return arg0_value;
54426492
5443 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6493 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5444 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6494 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5445 if (arg1_value == irb->codegen->invalid_instruction)6495 if (arg1_value == irb->codegen->invalid_inst_src)
5446 return arg1_value;6496 return arg1_value;
54476497
5448 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivTrunc, arg0_value, arg1_value, true);6498 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivTrunc, arg0_value, arg1_value, true);
5449 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);6499 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
5450 }6500 }
5451 case BuiltinFnIdDivFloor:6501 case BuiltinFnIdDivFloor:
5452 {6502 {
5453 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6503 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5454 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6504 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5455 if (arg0_value == irb->codegen->invalid_instruction)6505 if (arg0_value == irb->codegen->invalid_inst_src)
5456 return arg0_value;6506 return arg0_value;
54576507
5458 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6508 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5459 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6509 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5460 if (arg1_value == irb->codegen->invalid_instruction)6510 if (arg1_value == irb->codegen->invalid_inst_src)
5461 return arg1_value;6511 return arg1_value;
54626512
5463 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivFloor, arg0_value, arg1_value, true);6513 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpDivFloor, arg0_value, arg1_value, true);
5464 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);6514 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
5465 }6515 }
5466 case BuiltinFnIdRem:6516 case BuiltinFnIdRem:
5467 {6517 {
5468 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6518 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5469 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6519 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5470 if (arg0_value == irb->codegen->invalid_instruction)6520 if (arg0_value == irb->codegen->invalid_inst_src)
5471 return arg0_value;6521 return arg0_value;
54726522
5473 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6523 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5474 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6524 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5475 if (arg1_value == irb->codegen->invalid_instruction)6525 if (arg1_value == irb->codegen->invalid_inst_src)
5476 return arg1_value;6526 return arg1_value;
54776527
5478 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemRem, arg0_value, arg1_value, true);6528 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemRem, arg0_value, arg1_value, true);
5479 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);6529 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
5480 }6530 }
5481 case BuiltinFnIdMod:6531 case BuiltinFnIdMod:
5482 {6532 {
5483 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6533 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5484 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6534 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5485 if (arg0_value == irb->codegen->invalid_instruction)6535 if (arg0_value == irb->codegen->invalid_inst_src)
5486 return arg0_value;6536 return arg0_value;
54876537
5488 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6538 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5489 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6539 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5490 if (arg1_value == irb->codegen->invalid_instruction)6540 if (arg1_value == irb->codegen->invalid_inst_src)
5491 return arg1_value;6541 return arg1_value;
54926542
5493 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemMod, arg0_value, arg1_value, true);6543 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpRemMod, arg0_value, arg1_value, true);
5494 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);6544 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
5495 }6545 }
5496 case BuiltinFnIdSqrt:6546 case BuiltinFnIdSqrt:
...@@ -5509,406 +6559,406 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -5509,406 +6559,406 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
5509 case BuiltinFnIdRound:6559 case BuiltinFnIdRound:
5510 {6560 {
5511 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6561 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5512 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6562 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5513 if (arg0_value == irb->codegen->invalid_instruction)6563 if (arg0_value == irb->codegen->invalid_inst_src)
5514 return arg0_value;6564 return arg0_value;
55156565
5516 IrInstruction *inst = ir_build_float_op(irb, scope, node, arg0_value, builtin_fn->id);6566 IrInstSrc *inst = ir_build_float_op_src(irb, scope, node, arg0_value, builtin_fn->id);
5517 return ir_lval_wrap(irb, scope, inst, lval, result_loc);6567 return ir_lval_wrap(irb, scope, inst, lval, result_loc);
5518 }6568 }
5519 case BuiltinFnIdTruncate:6569 case BuiltinFnIdTruncate:
5520 {6570 {
5521 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6571 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5522 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6572 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5523 if (arg0_value == irb->codegen->invalid_instruction)6573 if (arg0_value == irb->codegen->invalid_inst_src)
5524 return arg0_value;6574 return arg0_value;
55256575
5526 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6576 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5527 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6577 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5528 if (arg1_value == irb->codegen->invalid_instruction)6578 if (arg1_value == irb->codegen->invalid_inst_src)
5529 return arg1_value;6579 return arg1_value;
55306580
5531 IrInstruction *truncate = ir_build_truncate(irb, scope, node, arg0_value, arg1_value);6581 IrInstSrc *truncate = ir_build_truncate(irb, scope, node, arg0_value, arg1_value);
5532 return ir_lval_wrap(irb, scope, truncate, lval, result_loc);6582 return ir_lval_wrap(irb, scope, truncate, lval, result_loc);
5533 }6583 }
5534 case BuiltinFnIdIntCast:6584 case BuiltinFnIdIntCast:
5535 {6585 {
5536 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6586 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5537 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6587 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5538 if (arg0_value == irb->codegen->invalid_instruction)6588 if (arg0_value == irb->codegen->invalid_inst_src)
5539 return arg0_value;6589 return arg0_value;
55406590
5541 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6591 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5542 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6592 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5543 if (arg1_value == irb->codegen->invalid_instruction)6593 if (arg1_value == irb->codegen->invalid_inst_src)
5544 return arg1_value;6594 return arg1_value;
55456595
5546 IrInstruction *result = ir_build_int_cast(irb, scope, node, arg0_value, arg1_value);6596 IrInstSrc *result = ir_build_int_cast(irb, scope, node, arg0_value, arg1_value);
5547 return ir_lval_wrap(irb, scope, result, lval, result_loc);6597 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5548 }6598 }
5549 case BuiltinFnIdFloatCast:6599 case BuiltinFnIdFloatCast:
5550 {6600 {
5551 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6601 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5552 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6602 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5553 if (arg0_value == irb->codegen->invalid_instruction)6603 if (arg0_value == irb->codegen->invalid_inst_src)
5554 return arg0_value;6604 return arg0_value;
55556605
5556 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6606 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5557 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6607 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5558 if (arg1_value == irb->codegen->invalid_instruction)6608 if (arg1_value == irb->codegen->invalid_inst_src)
5559 return arg1_value;6609 return arg1_value;
55606610
5561 IrInstruction *result = ir_build_float_cast(irb, scope, node, arg0_value, arg1_value);6611 IrInstSrc *result = ir_build_float_cast(irb, scope, node, arg0_value, arg1_value);
5562 return ir_lval_wrap(irb, scope, result, lval, result_loc);6612 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5563 }6613 }
5564 case BuiltinFnIdErrSetCast:6614 case BuiltinFnIdErrSetCast:
5565 {6615 {
5566 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6616 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5567 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6617 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5568 if (arg0_value == irb->codegen->invalid_instruction)6618 if (arg0_value == irb->codegen->invalid_inst_src)
5569 return arg0_value;6619 return arg0_value;
55706620
5571 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6621 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5572 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6622 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5573 if (arg1_value == irb->codegen->invalid_instruction)6623 if (arg1_value == irb->codegen->invalid_inst_src)
5574 return arg1_value;6624 return arg1_value;
55756625
5576 IrInstruction *result = ir_build_err_set_cast(irb, scope, node, arg0_value, arg1_value);6626 IrInstSrc *result = ir_build_err_set_cast(irb, scope, node, arg0_value, arg1_value);
5577 return ir_lval_wrap(irb, scope, result, lval, result_loc);6627 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5578 }6628 }
5579 case BuiltinFnIdFromBytes:6629 case BuiltinFnIdFromBytes:
5580 {6630 {
5581 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6631 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5582 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6632 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5583 if (arg0_value == irb->codegen->invalid_instruction)6633 if (arg0_value == irb->codegen->invalid_inst_src)
5584 return arg0_value;6634 return arg0_value;
55856635
5586 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6636 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5587 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6637 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5588 if (arg1_value == irb->codegen->invalid_instruction)6638 if (arg1_value == irb->codegen->invalid_inst_src)
5589 return arg1_value;6639 return arg1_value;
55906640
5591 IrInstruction *result = ir_build_from_bytes(irb, scope, node, arg0_value, arg1_value, result_loc);6641 IrInstSrc *result = ir_build_from_bytes(irb, scope, node, arg0_value, arg1_value, result_loc);
5592 return ir_lval_wrap(irb, scope, result, lval, result_loc);6642 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5593 }6643 }
5594 case BuiltinFnIdToBytes:6644 case BuiltinFnIdToBytes:
5595 {6645 {
5596 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6646 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5597 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6647 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5598 if (arg0_value == irb->codegen->invalid_instruction)6648 if (arg0_value == irb->codegen->invalid_inst_src)
5599 return arg0_value;6649 return arg0_value;
56006650
5601 IrInstruction *result = ir_build_to_bytes(irb, scope, node, arg0_value, result_loc);6651 IrInstSrc *result = ir_build_to_bytes(irb, scope, node, arg0_value, result_loc);
5602 return ir_lval_wrap(irb, scope, result, lval, result_loc);6652 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5603 }6653 }
5604 case BuiltinFnIdIntToFloat:6654 case BuiltinFnIdIntToFloat:
5605 {6655 {
5606 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6656 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5607 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6657 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5608 if (arg0_value == irb->codegen->invalid_instruction)6658 if (arg0_value == irb->codegen->invalid_inst_src)
5609 return arg0_value;6659 return arg0_value;
56106660
5611 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6661 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5612 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6662 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5613 if (arg1_value == irb->codegen->invalid_instruction)6663 if (arg1_value == irb->codegen->invalid_inst_src)
5614 return arg1_value;6664 return arg1_value;
56156665
5616 IrInstruction *result = ir_build_int_to_float(irb, scope, node, arg0_value, arg1_value);6666 IrInstSrc *result = ir_build_int_to_float(irb, scope, node, arg0_value, arg1_value);
5617 return ir_lval_wrap(irb, scope, result, lval, result_loc);6667 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5618 }6668 }
5619 case BuiltinFnIdFloatToInt:6669 case BuiltinFnIdFloatToInt:
5620 {6670 {
5621 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6671 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5622 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6672 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5623 if (arg0_value == irb->codegen->invalid_instruction)6673 if (arg0_value == irb->codegen->invalid_inst_src)
5624 return arg0_value;6674 return arg0_value;
56256675
5626 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6676 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5627 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6677 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5628 if (arg1_value == irb->codegen->invalid_instruction)6678 if (arg1_value == irb->codegen->invalid_inst_src)
5629 return arg1_value;6679 return arg1_value;
56306680
5631 IrInstruction *result = ir_build_float_to_int(irb, scope, node, arg0_value, arg1_value);6681 IrInstSrc *result = ir_build_float_to_int(irb, scope, node, arg0_value, arg1_value);
5632 return ir_lval_wrap(irb, scope, result, lval, result_loc);6682 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5633 }6683 }
5634 case BuiltinFnIdErrToInt:6684 case BuiltinFnIdErrToInt:
5635 {6685 {
5636 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6686 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5637 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6687 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5638 if (arg0_value == irb->codegen->invalid_instruction)6688 if (arg0_value == irb->codegen->invalid_inst_src)
5639 return arg0_value;6689 return arg0_value;
56406690
5641 IrInstruction *result = ir_build_err_to_int(irb, scope, node, arg0_value);6691 IrInstSrc *result = ir_build_err_to_int_src(irb, scope, node, arg0_value);
5642 return ir_lval_wrap(irb, scope, result, lval, result_loc);6692 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5643 }6693 }
5644 case BuiltinFnIdIntToErr:6694 case BuiltinFnIdIntToErr:
5645 {6695 {
5646 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6696 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5647 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6697 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5648 if (arg0_value == irb->codegen->invalid_instruction)6698 if (arg0_value == irb->codegen->invalid_inst_src)
5649 return arg0_value;6699 return arg0_value;
56506700
5651 IrInstruction *result = ir_build_int_to_err(irb, scope, node, arg0_value);6701 IrInstSrc *result = ir_build_int_to_err_src(irb, scope, node, arg0_value);
5652 return ir_lval_wrap(irb, scope, result, lval, result_loc);6702 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5653 }6703 }
5654 case BuiltinFnIdBoolToInt:6704 case BuiltinFnIdBoolToInt:
5655 {6705 {
5656 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6706 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5657 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6707 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5658 if (arg0_value == irb->codegen->invalid_instruction)6708 if (arg0_value == irb->codegen->invalid_inst_src)
5659 return arg0_value;6709 return arg0_value;
56606710
5661 IrInstruction *result = ir_build_bool_to_int(irb, scope, node, arg0_value);6711 IrInstSrc *result = ir_build_bool_to_int(irb, scope, node, arg0_value);
5662 return ir_lval_wrap(irb, scope, result, lval, result_loc);6712 return ir_lval_wrap(irb, scope, result, lval, result_loc);
5663 }6713 }
5664 case BuiltinFnIdIntType:6714 case BuiltinFnIdIntType:
5665 {6715 {
5666 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6716 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5667 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6717 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5668 if (arg0_value == irb->codegen->invalid_instruction)6718 if (arg0_value == irb->codegen->invalid_inst_src)
5669 return arg0_value;6719 return arg0_value;
56706720
5671 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6721 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5672 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6722 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5673 if (arg1_value == irb->codegen->invalid_instruction)6723 if (arg1_value == irb->codegen->invalid_inst_src)
5674 return arg1_value;6724 return arg1_value;
56756725
5676 IrInstruction *int_type = ir_build_int_type(irb, scope, node, arg0_value, arg1_value);6726 IrInstSrc *int_type = ir_build_int_type(irb, scope, node, arg0_value, arg1_value);
5677 return ir_lval_wrap(irb, scope, int_type, lval, result_loc);6727 return ir_lval_wrap(irb, scope, int_type, lval, result_loc);
5678 }6728 }
5679 case BuiltinFnIdVectorType:6729 case BuiltinFnIdVectorType:
5680 {6730 {
5681 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6731 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5682 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6732 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5683 if (arg0_value == irb->codegen->invalid_instruction)6733 if (arg0_value == irb->codegen->invalid_inst_src)
5684 return arg0_value;6734 return arg0_value;
56856735
5686 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6736 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5687 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6737 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5688 if (arg1_value == irb->codegen->invalid_instruction)6738 if (arg1_value == irb->codegen->invalid_inst_src)
5689 return arg1_value;6739 return arg1_value;
56906740
5691 IrInstruction *vector_type = ir_build_vector_type(irb, scope, node, arg0_value, arg1_value);6741 IrInstSrc *vector_type = ir_build_vector_type(irb, scope, node, arg0_value, arg1_value);
5692 return ir_lval_wrap(irb, scope, vector_type, lval, result_loc);6742 return ir_lval_wrap(irb, scope, vector_type, lval, result_loc);
5693 }6743 }
5694 case BuiltinFnIdShuffle:6744 case BuiltinFnIdShuffle:
5695 {6745 {
5696 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6746 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5697 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6747 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5698 if (arg0_value == irb->codegen->invalid_instruction)6748 if (arg0_value == irb->codegen->invalid_inst_src)
5699 return arg0_value;6749 return arg0_value;
57006750
5701 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6751 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5702 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6752 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5703 if (arg1_value == irb->codegen->invalid_instruction)6753 if (arg1_value == irb->codegen->invalid_inst_src)
5704 return arg1_value;6754 return arg1_value;
57056755
5706 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);6756 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
5707 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);6757 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
5708 if (arg2_value == irb->codegen->invalid_instruction)6758 if (arg2_value == irb->codegen->invalid_inst_src)
5709 return arg2_value;6759 return arg2_value;
57106760
5711 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);6761 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
5712 IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope);6762 IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope);
5713 if (arg3_value == irb->codegen->invalid_instruction)6763 if (arg3_value == irb->codegen->invalid_inst_src)
5714 return arg3_value;6764 return arg3_value;
57156765
5716 IrInstruction *shuffle_vector = ir_build_shuffle_vector(irb, scope, node,6766 IrInstSrc *shuffle_vector = ir_build_shuffle_vector(irb, scope, node,
5717 arg0_value, arg1_value, arg2_value, arg3_value);6767 arg0_value, arg1_value, arg2_value, arg3_value);
5718 return ir_lval_wrap(irb, scope, shuffle_vector, lval, result_loc);6768 return ir_lval_wrap(irb, scope, shuffle_vector, lval, result_loc);
5719 }6769 }
5720 case BuiltinFnIdSplat:6770 case BuiltinFnIdSplat:
5721 {6771 {
5722 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6772 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5723 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6773 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5724 if (arg0_value == irb->codegen->invalid_instruction)6774 if (arg0_value == irb->codegen->invalid_inst_src)
5725 return arg0_value;6775 return arg0_value;
57266776
5727 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6777 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5728 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6778 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5729 if (arg1_value == irb->codegen->invalid_instruction)6779 if (arg1_value == irb->codegen->invalid_inst_src)
5730 return arg1_value;6780 return arg1_value;
57316781
5732 IrInstruction *splat = ir_build_splat_src(irb, scope, node,6782 IrInstSrc *splat = ir_build_splat_src(irb, scope, node,
5733 arg0_value, arg1_value);6783 arg0_value, arg1_value);
5734 return ir_lval_wrap(irb, scope, splat, lval, result_loc);6784 return ir_lval_wrap(irb, scope, splat, lval, result_loc);
5735 }6785 }
5736 case BuiltinFnIdMemcpy:6786 case BuiltinFnIdMemcpy:
5737 {6787 {
5738 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6788 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5739 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6789 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5740 if (arg0_value == irb->codegen->invalid_instruction)6790 if (arg0_value == irb->codegen->invalid_inst_src)
5741 return arg0_value;6791 return arg0_value;
57426792
5743 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6793 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5744 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6794 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5745 if (arg1_value == irb->codegen->invalid_instruction)6795 if (arg1_value == irb->codegen->invalid_inst_src)
5746 return arg1_value;6796 return arg1_value;
57476797
5748 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);6798 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
5749 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);6799 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
5750 if (arg2_value == irb->codegen->invalid_instruction)6800 if (arg2_value == irb->codegen->invalid_inst_src)
5751 return arg2_value;6801 return arg2_value;
57526802
5753 IrInstruction *ir_memcpy = ir_build_memcpy(irb, scope, node, arg0_value, arg1_value, arg2_value);6803 IrInstSrc *ir_memcpy = ir_build_memcpy_src(irb, scope, node, arg0_value, arg1_value, arg2_value);
5754 return ir_lval_wrap(irb, scope, ir_memcpy, lval, result_loc);6804 return ir_lval_wrap(irb, scope, ir_memcpy, lval, result_loc);
5755 }6805 }
5756 case BuiltinFnIdMemset:6806 case BuiltinFnIdMemset:
5757 {6807 {
5758 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6808 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5759 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6809 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5760 if (arg0_value == irb->codegen->invalid_instruction)6810 if (arg0_value == irb->codegen->invalid_inst_src)
5761 return arg0_value;6811 return arg0_value;
57626812
5763 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6813 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5764 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6814 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5765 if (arg1_value == irb->codegen->invalid_instruction)6815 if (arg1_value == irb->codegen->invalid_inst_src)
5766 return arg1_value;6816 return arg1_value;
57676817
5768 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);6818 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
5769 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);6819 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
5770 if (arg2_value == irb->codegen->invalid_instruction)6820 if (arg2_value == irb->codegen->invalid_inst_src)
5771 return arg2_value;6821 return arg2_value;
57726822
5773 IrInstruction *ir_memset = ir_build_memset(irb, scope, node, arg0_value, arg1_value, arg2_value);6823 IrInstSrc *ir_memset = ir_build_memset_src(irb, scope, node, arg0_value, arg1_value, arg2_value);
5774 return ir_lval_wrap(irb, scope, ir_memset, lval, result_loc);6824 return ir_lval_wrap(irb, scope, ir_memset, lval, result_loc);
5775 }6825 }
5776 case BuiltinFnIdMemberCount:6826 case BuiltinFnIdMemberCount:
5777 {6827 {
5778 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6828 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5779 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6829 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5780 if (arg0_value == irb->codegen->invalid_instruction)6830 if (arg0_value == irb->codegen->invalid_inst_src)
5781 return arg0_value;6831 return arg0_value;
57826832
5783 IrInstruction *member_count = ir_build_member_count(irb, scope, node, arg0_value);6833 IrInstSrc *member_count = ir_build_member_count(irb, scope, node, arg0_value);
5784 return ir_lval_wrap(irb, scope, member_count, lval, result_loc);6834 return ir_lval_wrap(irb, scope, member_count, lval, result_loc);
5785 }6835 }
5786 case BuiltinFnIdMemberType:6836 case BuiltinFnIdMemberType:
5787 {6837 {
5788 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6838 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5789 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6839 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5790 if (arg0_value == irb->codegen->invalid_instruction)6840 if (arg0_value == irb->codegen->invalid_inst_src)
5791 return arg0_value;6841 return arg0_value;
57926842
5793 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6843 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5794 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6844 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5795 if (arg1_value == irb->codegen->invalid_instruction)6845 if (arg1_value == irb->codegen->invalid_inst_src)
5796 return arg1_value;6846 return arg1_value;
57976847
57986848
5799 IrInstruction *member_type = ir_build_member_type(irb, scope, node, arg0_value, arg1_value);6849 IrInstSrc *member_type = ir_build_member_type(irb, scope, node, arg0_value, arg1_value);
5800 return ir_lval_wrap(irb, scope, member_type, lval, result_loc);6850 return ir_lval_wrap(irb, scope, member_type, lval, result_loc);
5801 }6851 }
5802 case BuiltinFnIdMemberName:6852 case BuiltinFnIdMemberName:
5803 {6853 {
5804 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6854 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5805 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6855 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5806 if (arg0_value == irb->codegen->invalid_instruction)6856 if (arg0_value == irb->codegen->invalid_inst_src)
5807 return arg0_value;6857 return arg0_value;
58086858
5809 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6859 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5810 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6860 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5811 if (arg1_value == irb->codegen->invalid_instruction)6861 if (arg1_value == irb->codegen->invalid_inst_src)
5812 return arg1_value;6862 return arg1_value;
58136863
58146864
5815 IrInstruction *member_name = ir_build_member_name(irb, scope, node, arg0_value, arg1_value);6865 IrInstSrc *member_name = ir_build_member_name(irb, scope, node, arg0_value, arg1_value);
5816 return ir_lval_wrap(irb, scope, member_name, lval, result_loc);6866 return ir_lval_wrap(irb, scope, member_name, lval, result_loc);
5817 }6867 }
5818 case BuiltinFnIdField:6868 case BuiltinFnIdField:
5819 {6869 {
5820 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6870 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5821 IrInstruction *arg0_value = ir_gen_node_extra(irb, arg0_node, scope, LValPtr, nullptr);6871 IrInstSrc *arg0_value = ir_gen_node_extra(irb, arg0_node, scope, LValPtr, nullptr);
5822 if (arg0_value == irb->codegen->invalid_instruction)6872 if (arg0_value == irb->codegen->invalid_inst_src)
5823 return arg0_value;6873 return arg0_value;
58246874
5825 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6875 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5826 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6876 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5827 if (arg1_value == irb->codegen->invalid_instruction)6877 if (arg1_value == irb->codegen->invalid_inst_src)
5828 return arg1_value;6878 return arg1_value;
58296879
5830 IrInstruction *ptr_instruction = ir_build_field_ptr_instruction(irb, scope, node,6880 IrInstSrc *ptr_instruction = ir_build_field_ptr_instruction(irb, scope, node,
5831 arg0_value, arg1_value, false);6881 arg0_value, arg1_value, false);
58326882
5833 if (lval == LValPtr)6883 if (lval == LValPtr)
5834 return ptr_instruction;6884 return ptr_instruction;
58356885
5836 IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);6886 IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);
5837 return ir_expr_wrap(irb, scope, load_ptr, result_loc);6887 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
5838 }6888 }
5839 case BuiltinFnIdHasField:6889 case BuiltinFnIdHasField:
5840 {6890 {
5841 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6891 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5842 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6892 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5843 if (arg0_value == irb->codegen->invalid_instruction)6893 if (arg0_value == irb->codegen->invalid_inst_src)
5844 return arg0_value;6894 return arg0_value;
58456895
5846 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);6896 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5847 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);6897 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5848 if (arg1_value == irb->codegen->invalid_instruction)6898 if (arg1_value == irb->codegen->invalid_inst_src)
5849 return arg1_value;6899 return arg1_value;
58506900
5851 IrInstruction *type_info = ir_build_has_field(irb, scope, node, arg0_value, arg1_value);6901 IrInstSrc *type_info = ir_build_has_field(irb, scope, node, arg0_value, arg1_value);
5852 return ir_lval_wrap(irb, scope, type_info, lval, result_loc);6902 return ir_lval_wrap(irb, scope, type_info, lval, result_loc);
5853 }6903 }
5854 case BuiltinFnIdTypeInfo:6904 case BuiltinFnIdTypeInfo:
5855 {6905 {
5856 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6906 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5857 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6907 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5858 if (arg0_value == irb->codegen->invalid_instruction)6908 if (arg0_value == irb->codegen->invalid_inst_src)
5859 return arg0_value;6909 return arg0_value;
58606910
5861 IrInstruction *type_info = ir_build_type_info(irb, scope, node, arg0_value);6911 IrInstSrc *type_info = ir_build_type_info(irb, scope, node, arg0_value);
5862 return ir_lval_wrap(irb, scope, type_info, lval, result_loc);6912 return ir_lval_wrap(irb, scope, type_info, lval, result_loc);
5863 }6913 }
5864 case BuiltinFnIdType:6914 case BuiltinFnIdType:
5865 {6915 {
5866 AstNode *arg_node = node->data.fn_call_expr.params.at(0);6916 AstNode *arg_node = node->data.fn_call_expr.params.at(0);
5867 IrInstruction *arg = ir_gen_node(irb, arg_node, scope);6917 IrInstSrc *arg = ir_gen_node(irb, arg_node, scope);
5868 if (arg == irb->codegen->invalid_instruction)6918 if (arg == irb->codegen->invalid_inst_src)
5869 return arg;6919 return arg;
58706920
5871 IrInstruction *type = ir_build_type(irb, scope, node, arg);6921 IrInstSrc *type = ir_build_type(irb, scope, node, arg);
5872 return ir_lval_wrap(irb, scope, type, lval, result_loc);6922 return ir_lval_wrap(irb, scope, type, lval, result_loc);
5873 }6923 }
5874 case BuiltinFnIdBreakpoint:6924 case BuiltinFnIdBreakpoint:
5875 return ir_lval_wrap(irb, scope, ir_build_breakpoint(irb, scope, node), lval, result_loc);6925 return ir_lval_wrap(irb, scope, ir_build_breakpoint(irb, scope, node), lval, result_loc);
5876 case BuiltinFnIdReturnAddress:6926 case BuiltinFnIdReturnAddress:
5877 return ir_lval_wrap(irb, scope, ir_build_return_address(irb, scope, node), lval, result_loc);6927 return ir_lval_wrap(irb, scope, ir_build_return_address_src(irb, scope, node), lval, result_loc);
5878 case BuiltinFnIdFrameAddress:6928 case BuiltinFnIdFrameAddress:
5879 return ir_lval_wrap(irb, scope, ir_build_frame_address(irb, scope, node), lval, result_loc);6929 return ir_lval_wrap(irb, scope, ir_build_frame_address_src(irb, scope, node), lval, result_loc);
5880 case BuiltinFnIdFrameHandle:6930 case BuiltinFnIdFrameHandle:
5881 if (!irb->exec->fn_entry) {6931 if (!irb->exec->fn_entry) {
5882 add_node_error(irb->codegen, node, buf_sprintf("@frame() called outside of function definition"));6932 add_node_error(irb->codegen, node, buf_sprintf("@frame() called outside of function definition"));
5883 return irb->codegen->invalid_instruction;6933 return irb->codegen->invalid_inst_src;
5884 }6934 }
5885 return ir_lval_wrap(irb, scope, ir_build_handle(irb, scope, node), lval, result_loc);6935 return ir_lval_wrap(irb, scope, ir_build_handle_src(irb, scope, node), lval, result_loc);
5886 case BuiltinFnIdFrameType: {6936 case BuiltinFnIdFrameType: {
5887 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6937 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5888 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6938 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5889 if (arg0_value == irb->codegen->invalid_instruction)6939 if (arg0_value == irb->codegen->invalid_inst_src)
5890 return arg0_value;6940 return arg0_value;
58916941
5892 IrInstruction *frame_type = ir_build_frame_type(irb, scope, node, arg0_value);6942 IrInstSrc *frame_type = ir_build_frame_type(irb, scope, node, arg0_value);
5893 return ir_lval_wrap(irb, scope, frame_type, lval, result_loc);6943 return ir_lval_wrap(irb, scope, frame_type, lval, result_loc);
5894 }6944 }
5895 case BuiltinFnIdFrameSize: {6945 case BuiltinFnIdFrameSize: {
5896 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6946 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5897 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6947 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5898 if (arg0_value == irb->codegen->invalid_instruction)6948 if (arg0_value == irb->codegen->invalid_inst_src)
5899 return arg0_value;6949 return arg0_value;
59006950
5901 IrInstruction *frame_size = ir_build_frame_size_src(irb, scope, node, arg0_value);6951 IrInstSrc *frame_size = ir_build_frame_size_src(irb, scope, node, arg0_value);
5902 return ir_lval_wrap(irb, scope, frame_size, lval, result_loc);6952 return ir_lval_wrap(irb, scope, frame_size, lval, result_loc);
5903 }6953 }
5904 case BuiltinFnIdAlignOf:6954 case BuiltinFnIdAlignOf:
5905 {6955 {
5906 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6956 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5907 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6957 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5908 if (arg0_value == irb->codegen->invalid_instruction)6958 if (arg0_value == irb->codegen->invalid_inst_src)
5909 return arg0_value;6959 return arg0_value;
59106960
5911 IrInstruction *align_of = ir_build_align_of(irb, scope, node, arg0_value);6961 IrInstSrc *align_of = ir_build_align_of(irb, scope, node, arg0_value);
5912 return ir_lval_wrap(irb, scope, align_of, lval, result_loc);6962 return ir_lval_wrap(irb, scope, align_of, lval, result_loc);
5913 }6963 }
5914 case BuiltinFnIdAddWithOverflow:6964 case BuiltinFnIdAddWithOverflow:
...@@ -5924,173 +6974,175 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -5924,173 +6974,175 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
5924 case BuiltinFnIdTypeName:6974 case BuiltinFnIdTypeName:
5925 {6975 {
5926 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6976 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5927 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6977 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5928 if (arg0_value == irb->codegen->invalid_instruction)6978 if (arg0_value == irb->codegen->invalid_inst_src)
5929 return arg0_value;6979 return arg0_value;
59306980
5931 IrInstruction *type_name = ir_build_type_name(irb, scope, node, arg0_value);6981 IrInstSrc *type_name = ir_build_type_name(irb, scope, node, arg0_value);
5932 return ir_lval_wrap(irb, scope, type_name, lval, result_loc);6982 return ir_lval_wrap(irb, scope, type_name, lval, result_loc);
5933 }6983 }
5934 case BuiltinFnIdPanic:6984 case BuiltinFnIdPanic:
5935 {6985 {
5936 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6986 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5937 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6987 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5938 if (arg0_value == irb->codegen->invalid_instruction)6988 if (arg0_value == irb->codegen->invalid_inst_src)
5939 return arg0_value;6989 return arg0_value;
59406990
5941 IrInstruction *panic = ir_build_panic(irb, scope, node, arg0_value);6991 IrInstSrc *panic = ir_build_panic_src(irb, scope, node, arg0_value);
5942 return ir_lval_wrap(irb, scope, panic, lval, result_loc);6992 return ir_lval_wrap(irb, scope, panic, lval, result_loc);
5943 }6993 }
5944 case BuiltinFnIdPtrCast:6994 case BuiltinFnIdPtrCast:
5945 {6995 {
5946 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);6996 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
5947 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);6997 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
5948 if (arg0_value == irb->codegen->invalid_instruction)6998 if (arg0_value == irb->codegen->invalid_inst_src)
5949 return arg0_value;6999 return arg0_value;
59507000
5951 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7001 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5952 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7002 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
5953 if (arg1_value == irb->codegen->invalid_instruction)7003 if (arg1_value == irb->codegen->invalid_inst_src)
5954 return arg1_value;7004 return arg1_value;
59557005
5956 IrInstruction *ptr_cast = ir_build_ptr_cast_src(irb, scope, node, arg0_value, arg1_value, true);7006 IrInstSrc *ptr_cast = ir_build_ptr_cast_src(irb, scope, node, arg0_value, arg1_value, true);
5957 return ir_lval_wrap(irb, scope, ptr_cast, lval, result_loc);7007 return ir_lval_wrap(irb, scope, ptr_cast, lval, result_loc);
5958 }7008 }
5959 case BuiltinFnIdBitCast:7009 case BuiltinFnIdBitCast:
5960 {7010 {
5961 AstNode *dest_type_node = node->data.fn_call_expr.params.at(0);7011 AstNode *dest_type_node = node->data.fn_call_expr.params.at(0);
5962 IrInstruction *dest_type = ir_gen_node(irb, dest_type_node, scope);7012 IrInstSrc *dest_type = ir_gen_node(irb, dest_type_node, scope);
5963 if (dest_type == irb->codegen->invalid_instruction)7013 if (dest_type == irb->codegen->invalid_inst_src)
5964 return dest_type;7014 return dest_type;
59657015
5966 ResultLocBitCast *result_loc_bit_cast = allocate<ResultLocBitCast>(1);7016 ResultLocBitCast *result_loc_bit_cast = allocate<ResultLocBitCast>(1);
5967 result_loc_bit_cast->base.id = ResultLocIdBitCast;7017 result_loc_bit_cast->base.id = ResultLocIdBitCast;
5968 result_loc_bit_cast->base.source_instruction = dest_type;7018 result_loc_bit_cast->base.source_instruction = dest_type;
7019 result_loc_bit_cast->base.allow_write_through_const = result_loc->allow_write_through_const;
5969 ir_ref_instruction(dest_type, irb->current_basic_block);7020 ir_ref_instruction(dest_type, irb->current_basic_block);
5970 result_loc_bit_cast->parent = result_loc;7021 result_loc_bit_cast->parent = result_loc;
59717022
5972 ir_build_reset_result(irb, scope, node, &result_loc_bit_cast->base);7023 ir_build_reset_result(irb, scope, node, &result_loc_bit_cast->base);
59737024
5974 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7025 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5975 IrInstruction *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone,7026 IrInstSrc *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone,
5976 &result_loc_bit_cast->base);7027 &result_loc_bit_cast->base);
5977 if (arg1_value == irb->codegen->invalid_instruction)7028 if (arg1_value == irb->codegen->invalid_inst_src)
5978 return arg1_value;7029 return arg1_value;
59797030
5980 IrInstruction *bitcast = ir_build_bit_cast_src(irb, scope, arg1_node, arg1_value, result_loc_bit_cast);7031 IrInstSrc *bitcast = ir_build_bit_cast_src(irb, scope, arg1_node, arg1_value, result_loc_bit_cast);
5981 return ir_lval_wrap(irb, scope, bitcast, lval, result_loc);7032 return ir_lval_wrap(irb, scope, bitcast, lval, result_loc);
5982 }7033 }
5983 case BuiltinFnIdAs:7034 case BuiltinFnIdAs:
5984 {7035 {
5985 AstNode *dest_type_node = node->data.fn_call_expr.params.at(0);7036 AstNode *dest_type_node = node->data.fn_call_expr.params.at(0);
5986 IrInstruction *dest_type = ir_gen_node(irb, dest_type_node, scope);7037 IrInstSrc *dest_type = ir_gen_node(irb, dest_type_node, scope);
5987 if (dest_type == irb->codegen->invalid_instruction)7038 if (dest_type == irb->codegen->invalid_inst_src)
5988 return dest_type;7039 return dest_type;
59897040
5990 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, dest_type, result_loc);7041 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, dest_type, result_loc);
59917042
5992 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7043 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
5993 IrInstruction *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone,7044 IrInstSrc *arg1_value = ir_gen_node_extra(irb, arg1_node, scope, LValNone,
5994 &result_loc_cast->base);7045 &result_loc_cast->base);
5995 if (arg1_value == irb->codegen->invalid_instruction)7046 if (arg1_value == irb->codegen->invalid_inst_src)
5996 return arg1_value;7047 return arg1_value;
59977048
5998 IrInstruction *result = ir_build_implicit_cast(irb, scope, node, arg1_value, result_loc_cast);7049 IrInstSrc *result = ir_build_implicit_cast(irb, scope, node, arg1_value, result_loc_cast);
5999 return ir_lval_wrap(irb, scope, result, lval, result_loc);7050 return ir_lval_wrap(irb, scope, result, lval, result_loc);
6000 }7051 }
6001 case BuiltinFnIdIntToPtr:7052 case BuiltinFnIdIntToPtr:
6002 {7053 {
6003 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7054 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6004 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7055 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6005 if (arg0_value == irb->codegen->invalid_instruction)7056 if (arg0_value == irb->codegen->invalid_inst_src)
6006 return arg0_value;7057 return arg0_value;
60077058
6008 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7059 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6009 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7060 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6010 if (arg1_value == irb->codegen->invalid_instruction)7061 if (arg1_value == irb->codegen->invalid_inst_src)
6011 return arg1_value;7062 return arg1_value;
60127063
6013 IrInstruction *int_to_ptr = ir_build_int_to_ptr(irb, scope, node, arg0_value, arg1_value);7064 IrInstSrc *int_to_ptr = ir_build_int_to_ptr_src(irb, scope, node, arg0_value, arg1_value);
6014 return ir_lval_wrap(irb, scope, int_to_ptr, lval, result_loc);7065 return ir_lval_wrap(irb, scope, int_to_ptr, lval, result_loc);
6015 }7066 }
6016 case BuiltinFnIdPtrToInt:7067 case BuiltinFnIdPtrToInt:
6017 {7068 {
6018 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7069 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6019 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7070 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6020 if (arg0_value == irb->codegen->invalid_instruction)7071 if (arg0_value == irb->codegen->invalid_inst_src)
6021 return arg0_value;7072 return arg0_value;
60227073
6023 IrInstruction *ptr_to_int = ir_build_ptr_to_int(irb, scope, node, arg0_value);7074 IrInstSrc *ptr_to_int = ir_build_ptr_to_int_src(irb, scope, node, arg0_value);
6024 return ir_lval_wrap(irb, scope, ptr_to_int, lval, result_loc);7075 return ir_lval_wrap(irb, scope, ptr_to_int, lval, result_loc);
6025 }7076 }
6026 case BuiltinFnIdTagName:7077 case BuiltinFnIdTagName:
6027 {7078 {
6028 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7079 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6029 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7080 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6030 if (arg0_value == irb->codegen->invalid_instruction)7081 if (arg0_value == irb->codegen->invalid_inst_src)
6031 return arg0_value;7082 return arg0_value;
60327083
6033 IrInstruction *tag_name = ir_build_tag_name(irb, scope, node, arg0_value);7084 IrInstSrc *tag_name = ir_build_tag_name_src(irb, scope, node, arg0_value);
6034 return ir_lval_wrap(irb, scope, tag_name, lval, result_loc);7085 return ir_lval_wrap(irb, scope, tag_name, lval, result_loc);
6035 }7086 }
6036 case BuiltinFnIdTagType:7087 case BuiltinFnIdTagType:
6037 {7088 {
6038 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7089 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6039 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7090 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6040 if (arg0_value == irb->codegen->invalid_instruction)7091 if (arg0_value == irb->codegen->invalid_inst_src)
6041 return arg0_value;7092 return arg0_value;
60427093
6043 IrInstruction *tag_type = ir_build_tag_type(irb, scope, node, arg0_value);7094 IrInstSrc *tag_type = ir_build_tag_type(irb, scope, node, arg0_value);
6044 return ir_lval_wrap(irb, scope, tag_type, lval, result_loc);7095 return ir_lval_wrap(irb, scope, tag_type, lval, result_loc);
6045 }7096 }
6046 case BuiltinFnIdFieldParentPtr:7097 case BuiltinFnIdFieldParentPtr:
6047 {7098 {
6048 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7099 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6049 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7100 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6050 if (arg0_value == irb->codegen->invalid_instruction)7101 if (arg0_value == irb->codegen->invalid_inst_src)
6051 return arg0_value;7102 return arg0_value;
60527103
6053 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7104 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6054 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7105 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6055 if (arg1_value == irb->codegen->invalid_instruction)7106 if (arg1_value == irb->codegen->invalid_inst_src)
6056 return arg1_value;7107 return arg1_value;
60577108
6058 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);7109 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
6059 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);7110 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
6060 if (arg2_value == irb->codegen->invalid_instruction)7111 if (arg2_value == irb->codegen->invalid_inst_src)
6061 return arg2_value;7112 return arg2_value;
60627113
6063 IrInstruction *field_parent_ptr = ir_build_field_parent_ptr(irb, scope, node, arg0_value, arg1_value, arg2_value, nullptr);7114 IrInstSrc *field_parent_ptr = ir_build_field_parent_ptr_src(irb, scope, node,
7115 arg0_value, arg1_value, arg2_value);
6064 return ir_lval_wrap(irb, scope, field_parent_ptr, lval, result_loc);7116 return ir_lval_wrap(irb, scope, field_parent_ptr, lval, result_loc);
6065 }7117 }
6066 case BuiltinFnIdByteOffsetOf:7118 case BuiltinFnIdByteOffsetOf:
6067 {7119 {
6068 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7120 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6069 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7121 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6070 if (arg0_value == irb->codegen->invalid_instruction)7122 if (arg0_value == irb->codegen->invalid_inst_src)
6071 return arg0_value;7123 return arg0_value;
60727124
6073 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7125 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6074 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7126 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6075 if (arg1_value == irb->codegen->invalid_instruction)7127 if (arg1_value == irb->codegen->invalid_inst_src)
6076 return arg1_value;7128 return arg1_value;
60777129
6078 IrInstruction *offset_of = ir_build_byte_offset_of(irb, scope, node, arg0_value, arg1_value);7130 IrInstSrc *offset_of = ir_build_byte_offset_of(irb, scope, node, arg0_value, arg1_value);
6079 return ir_lval_wrap(irb, scope, offset_of, lval, result_loc);7131 return ir_lval_wrap(irb, scope, offset_of, lval, result_loc);
6080 }7132 }
6081 case BuiltinFnIdBitOffsetOf:7133 case BuiltinFnIdBitOffsetOf:
6082 {7134 {
6083 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7135 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6084 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7136 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6085 if (arg0_value == irb->codegen->invalid_instruction)7137 if (arg0_value == irb->codegen->invalid_inst_src)
6086 return arg0_value;7138 return arg0_value;
60877139
6088 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7140 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6089 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7141 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6090 if (arg1_value == irb->codegen->invalid_instruction)7142 if (arg1_value == irb->codegen->invalid_inst_src)
6091 return arg1_value;7143 return arg1_value;
60927144
6093 IrInstruction *offset_of = ir_build_bit_offset_of(irb, scope, node, arg0_value, arg1_value);7145 IrInstSrc *offset_of = ir_build_bit_offset_of(irb, scope, node, arg0_value, arg1_value);
6094 return ir_lval_wrap(irb, scope, offset_of, lval, result_loc);7146 return ir_lval_wrap(irb, scope, offset_of, lval, result_loc);
6095 }7147 }
6096 case BuiltinFnIdNewStackCall:7148 case BuiltinFnIdNewStackCall:
...@@ -6099,45 +7151,45 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -6099,45 +7151,45 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
6099 add_node_error(irb->codegen, node,7151 add_node_error(irb->codegen, node,
6100 buf_sprintf("expected at least 2 arguments, found %" ZIG_PRI_usize,7152 buf_sprintf("expected at least 2 arguments, found %" ZIG_PRI_usize,
6101 node->data.fn_call_expr.params.length));7153 node->data.fn_call_expr.params.length));
6102 return irb->codegen->invalid_instruction;7154 return irb->codegen->invalid_inst_src;
6103 }7155 }
61047156
6105 AstNode *new_stack_node = node->data.fn_call_expr.params.at(0);7157 AstNode *new_stack_node = node->data.fn_call_expr.params.at(0);
6106 IrInstruction *new_stack = ir_gen_node(irb, new_stack_node, scope);7158 IrInstSrc *new_stack = ir_gen_node(irb, new_stack_node, scope);
6107 if (new_stack == irb->codegen->invalid_instruction)7159 if (new_stack == irb->codegen->invalid_inst_src)
6108 return new_stack;7160 return new_stack;
61097161
6110 AstNode *fn_ref_node = node->data.fn_call_expr.params.at(1);7162 AstNode *fn_ref_node = node->data.fn_call_expr.params.at(1);
6111 IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope);7163 IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
6112 if (fn_ref == irb->codegen->invalid_instruction)7164 if (fn_ref == irb->codegen->invalid_inst_src)
6113 return fn_ref;7165 return fn_ref;
61147166
6115 size_t arg_count = node->data.fn_call_expr.params.length - 2;7167 size_t arg_count = node->data.fn_call_expr.params.length - 2;
61167168
6117 IrInstruction **args = allocate<IrInstruction*>(arg_count);7169 IrInstSrc **args = allocate<IrInstSrc*>(arg_count);
6118 for (size_t i = 0; i < arg_count; i += 1) {7170 for (size_t i = 0; i < arg_count; i += 1) {
6119 AstNode *arg_node = node->data.fn_call_expr.params.at(i + 2);7171 AstNode *arg_node = node->data.fn_call_expr.params.at(i + 2);
6120 args[i] = ir_gen_node(irb, arg_node, scope);7172 args[i] = ir_gen_node(irb, arg_node, scope);
6121 if (args[i] == irb->codegen->invalid_instruction)7173 if (args[i] == irb->codegen->invalid_inst_src)
6122 return args[i];7174 return args[i];
6123 }7175 }
61247176
6125 IrInstruction *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args,7177 IrInstSrc *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args,
6126 nullptr, CallModifierNone, false, new_stack, result_loc);7178 nullptr, CallModifierNone, false, new_stack, result_loc);
6127 return ir_lval_wrap(irb, scope, call, lval, result_loc);7179 return ir_lval_wrap(irb, scope, call, lval, result_loc);
6128 }7180 }
6129 case BuiltinFnIdCall: {7181 case BuiltinFnIdCall: {
6130 // Cast the options parameter to the options type7182 // Cast the options parameter to the options type
6131 ZigType *options_type = get_builtin_type(irb->codegen, "CallOptions");7183 ZigType *options_type = get_builtin_type(irb->codegen, "CallOptions");
6132 IrInstruction *options_type_inst = ir_build_const_type(irb, scope, node, options_type);7184 IrInstSrc *options_type_inst = ir_build_const_type(irb, scope, node, options_type);
6133 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc());7185 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc());
61347186
6135 AstNode *options_node = node->data.fn_call_expr.params.at(0);7187 AstNode *options_node = node->data.fn_call_expr.params.at(0);
6136 IrInstruction *options_inner = ir_gen_node_extra(irb, options_node, scope,7188 IrInstSrc *options_inner = ir_gen_node_extra(irb, options_node, scope,
6137 LValNone, &result_loc_cast->base);7189 LValNone, &result_loc_cast->base);
6138 if (options_inner == irb->codegen->invalid_instruction)7190 if (options_inner == irb->codegen->invalid_inst_src)
6139 return options_inner;7191 return options_inner;
6140 IrInstruction *options = ir_build_implicit_cast(irb, scope, options_node, options_inner, result_loc_cast);7192 IrInstSrc *options = ir_build_implicit_cast(irb, scope, options_node, options_inner, result_loc_cast);
61417193
6142 AstNode *fn_ref_node = node->data.fn_call_expr.params.at(1);7194 AstNode *fn_ref_node = node->data.fn_call_expr.params.at(1);
6143 AstNode *args_node = node->data.fn_call_expr.params.at(2);7195 AstNode *args_node = node->data.fn_call_expr.params.at(2);
...@@ -6153,18 +7205,18 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -6153,18 +7205,18 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
6153 } else {7205 } else {
6154 exec_add_error_node(irb->codegen, irb->exec, args_node,7206 exec_add_error_node(irb->codegen, irb->exec, args_node,
6155 buf_sprintf("TODO: @call with anon struct literal"));7207 buf_sprintf("TODO: @call with anon struct literal"));
6156 return irb->codegen->invalid_instruction;7208 return irb->codegen->invalid_inst_src;
6157 }7209 }
6158 } else {7210 } else {
6159 IrInstruction *fn_ref = ir_gen_node(irb, fn_ref_node, scope);7211 IrInstSrc *fn_ref = ir_gen_node(irb, fn_ref_node, scope);
6160 if (fn_ref == irb->codegen->invalid_instruction)7212 if (fn_ref == irb->codegen->invalid_inst_src)
6161 return fn_ref;7213 return fn_ref;
61627214
6163 IrInstruction *args = ir_gen_node(irb, args_node, scope);7215 IrInstSrc *args = ir_gen_node(irb, args_node, scope);
6164 if (args == irb->codegen->invalid_instruction)7216 if (args == irb->codegen->invalid_inst_src)
6165 return args;7217 return args;
61667218
6167 IrInstruction *call = ir_build_call_extra(irb, scope, node, options, fn_ref, args, result_loc);7219 IrInstSrc *call = ir_build_call_extra(irb, scope, node, options, fn_ref, args, result_loc);
6168 return ir_lval_wrap(irb, scope, call, lval, result_loc);7220 return ir_lval_wrap(irb, scope, call, lval, result_loc);
6169 }7221 }
6170 }7222 }
...@@ -6173,237 +7225,233 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -6173,237 +7225,233 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
6173 case BuiltinFnIdTypeId:7225 case BuiltinFnIdTypeId:
6174 {7226 {
6175 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7227 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6176 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7228 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6177 if (arg0_value == irb->codegen->invalid_instruction)7229 if (arg0_value == irb->codegen->invalid_inst_src)
6178 return arg0_value;7230 return arg0_value;
61797231
6180 IrInstruction *type_id = ir_build_type_id(irb, scope, node, arg0_value);7232 IrInstSrc *type_id = ir_build_type_id(irb, scope, node, arg0_value);
6181 return ir_lval_wrap(irb, scope, type_id, lval, result_loc);7233 return ir_lval_wrap(irb, scope, type_id, lval, result_loc);
6182 }7234 }
6183 case BuiltinFnIdShlExact:7235 case BuiltinFnIdShlExact:
6184 {7236 {
6185 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7237 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6186 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7238 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6187 if (arg0_value == irb->codegen->invalid_instruction)7239 if (arg0_value == irb->codegen->invalid_inst_src)
6188 return arg0_value;7240 return arg0_value;
61897241
6190 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7242 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6191 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7243 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6192 if (arg1_value == irb->codegen->invalid_instruction)7244 if (arg1_value == irb->codegen->invalid_inst_src)
6193 return arg1_value;7245 return arg1_value;
61947246
6195 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftLeftExact, arg0_value, arg1_value, true);7247 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftLeftExact, arg0_value, arg1_value, true);
6196 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);7248 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
6197 }7249 }
6198 case BuiltinFnIdShrExact:7250 case BuiltinFnIdShrExact:
6199 {7251 {
6200 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7252 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6201 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7253 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6202 if (arg0_value == irb->codegen->invalid_instruction)7254 if (arg0_value == irb->codegen->invalid_inst_src)
6203 return arg0_value;7255 return arg0_value;
62047256
6205 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7257 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6206 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7258 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6207 if (arg1_value == irb->codegen->invalid_instruction)7259 if (arg1_value == irb->codegen->invalid_inst_src)
6208 return arg1_value;7260 return arg1_value;
62097261
6210 IrInstruction *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftRightExact, arg0_value, arg1_value, true);7262 IrInstSrc *bin_op = ir_build_bin_op(irb, scope, node, IrBinOpBitShiftRightExact, arg0_value, arg1_value, true);
6211 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);7263 return ir_lval_wrap(irb, scope, bin_op, lval, result_loc);
6212 }7264 }
6213 case BuiltinFnIdSetEvalBranchQuota:7265 case BuiltinFnIdSetEvalBranchQuota:
6214 {7266 {
6215 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7267 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6216 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7268 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6217 if (arg0_value == irb->codegen->invalid_instruction)7269 if (arg0_value == irb->codegen->invalid_inst_src)
6218 return arg0_value;7270 return arg0_value;
62197271
6220 IrInstruction *set_eval_branch_quota = ir_build_set_eval_branch_quota(irb, scope, node, arg0_value);7272 IrInstSrc *set_eval_branch_quota = ir_build_set_eval_branch_quota(irb, scope, node, arg0_value);
6221 return ir_lval_wrap(irb, scope, set_eval_branch_quota, lval, result_loc);7273 return ir_lval_wrap(irb, scope, set_eval_branch_quota, lval, result_loc);
6222 }7274 }
6223 case BuiltinFnIdAlignCast:7275 case BuiltinFnIdAlignCast:
6224 {7276 {
6225 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7277 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6226 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7278 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6227 if (arg0_value == irb->codegen->invalid_instruction)7279 if (arg0_value == irb->codegen->invalid_inst_src)
6228 return arg0_value;7280 return arg0_value;
62297281
6230 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7282 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6231 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7283 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6232 if (arg1_value == irb->codegen->invalid_instruction)7284 if (arg1_value == irb->codegen->invalid_inst_src)
6233 return arg1_value;7285 return arg1_value;
62347286
6235 IrInstruction *align_cast = ir_build_align_cast(irb, scope, node, arg0_value, arg1_value);7287 IrInstSrc *align_cast = ir_build_align_cast_src(irb, scope, node, arg0_value, arg1_value);
6236 return ir_lval_wrap(irb, scope, align_cast, lval, result_loc);7288 return ir_lval_wrap(irb, scope, align_cast, lval, result_loc);
6237 }7289 }
6238 case BuiltinFnIdOpaqueType:7290 case BuiltinFnIdOpaqueType:
6239 {7291 {
6240 IrInstruction *opaque_type = ir_build_opaque_type(irb, scope, node);7292 IrInstSrc *opaque_type = ir_build_opaque_type(irb, scope, node);
6241 return ir_lval_wrap(irb, scope, opaque_type, lval, result_loc);7293 return ir_lval_wrap(irb, scope, opaque_type, lval, result_loc);
6242 }7294 }
6243 case BuiltinFnIdThis:7295 case BuiltinFnIdThis:
6244 {7296 {
6245 IrInstruction *this_inst = ir_gen_this(irb, scope, node);7297 IrInstSrc *this_inst = ir_gen_this(irb, scope, node);
6246 return ir_lval_wrap(irb, scope, this_inst, lval, result_loc);7298 return ir_lval_wrap(irb, scope, this_inst, lval, result_loc);
6247 }7299 }
6248 case BuiltinFnIdSetAlignStack:7300 case BuiltinFnIdSetAlignStack:
6249 {7301 {
6250 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7302 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6251 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7303 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6252 if (arg0_value == irb->codegen->invalid_instruction)7304 if (arg0_value == irb->codegen->invalid_inst_src)
6253 return arg0_value;7305 return arg0_value;
62547306
6255 IrInstruction *set_align_stack = ir_build_set_align_stack(irb, scope, node, arg0_value);7307 IrInstSrc *set_align_stack = ir_build_set_align_stack(irb, scope, node, arg0_value);
6256 return ir_lval_wrap(irb, scope, set_align_stack, lval, result_loc);7308 return ir_lval_wrap(irb, scope, set_align_stack, lval, result_loc);
6257 }7309 }
6258 case BuiltinFnIdArgType:7310 case BuiltinFnIdArgType:
6259 {7311 {
6260 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7312 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6261 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7313 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6262 if (arg0_value == irb->codegen->invalid_instruction)7314 if (arg0_value == irb->codegen->invalid_inst_src)
6263 return arg0_value;7315 return arg0_value;
62647316
6265 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7317 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6266 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7318 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6267 if (arg1_value == irb->codegen->invalid_instruction)7319 if (arg1_value == irb->codegen->invalid_inst_src)
6268 return arg1_value;7320 return arg1_value;
62697321
6270 IrInstruction *arg_type = ir_build_arg_type(irb, scope, node, arg0_value, arg1_value, false);7322 IrInstSrc *arg_type = ir_build_arg_type(irb, scope, node, arg0_value, arg1_value, false);
6271 return ir_lval_wrap(irb, scope, arg_type, lval, result_loc);7323 return ir_lval_wrap(irb, scope, arg_type, lval, result_loc);
6272 }7324 }
6273 case BuiltinFnIdExport:7325 case BuiltinFnIdExport:
6274 {7326 {
6275 // Cast the options parameter to the options type7327 // Cast the options parameter to the options type
6276 ZigType *options_type = get_builtin_type(irb->codegen, "ExportOptions");7328 ZigType *options_type = get_builtin_type(irb->codegen, "ExportOptions");
6277 IrInstruction *options_type_inst = ir_build_const_type(irb, scope, node, options_type);7329 IrInstSrc *options_type_inst = ir_build_const_type(irb, scope, node, options_type);
6278 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc());7330 ResultLocCast *result_loc_cast = ir_build_cast_result_loc(irb, options_type_inst, no_result_loc());
62797331
6280 AstNode *target_node = node->data.fn_call_expr.params.at(0);7332 AstNode *target_node = node->data.fn_call_expr.params.at(0);
6281 IrInstruction *target_value = ir_gen_node(irb, target_node, scope);7333 IrInstSrc *target_value = ir_gen_node(irb, target_node, scope);
6282 if (target_value == irb->codegen->invalid_instruction)7334 if (target_value == irb->codegen->invalid_inst_src)
6283 return target_value;7335 return target_value;
62847336
6285 AstNode *options_node = node->data.fn_call_expr.params.at(1);7337 AstNode *options_node = node->data.fn_call_expr.params.at(1);
6286 IrInstruction *options_value = ir_gen_node_extra(irb, options_node,7338 IrInstSrc *options_value = ir_gen_node_extra(irb, options_node,
6287 scope, LValNone, &result_loc_cast->base);7339 scope, LValNone, &result_loc_cast->base);
6288 if (options_value == irb->codegen->invalid_instruction)7340 if (options_value == irb->codegen->invalid_inst_src)
6289 return options_value;7341 return options_value;
62907342
6291 IrInstruction *casted_options_value = ir_build_implicit_cast(7343 IrInstSrc *casted_options_value = ir_build_implicit_cast(
6292 irb, scope, options_node, options_value, result_loc_cast);7344 irb, scope, options_node, options_value, result_loc_cast);
62937345
6294 IrInstruction *ir_export = ir_build_export(irb, scope, node, target_value, casted_options_value);7346 IrInstSrc *ir_export = ir_build_export(irb, scope, node, target_value, casted_options_value);
6295 return ir_lval_wrap(irb, scope, ir_export, lval, result_loc);7347 return ir_lval_wrap(irb, scope, ir_export, lval, result_loc);
6296 }7348 }
6297 case BuiltinFnIdErrorReturnTrace:7349 case BuiltinFnIdErrorReturnTrace:
6298 {7350 {
6299 IrInstruction *error_return_trace = ir_build_error_return_trace(irb, scope, node, IrInstructionErrorReturnTrace::Null);7351 IrInstSrc *error_return_trace = ir_build_error_return_trace_src(irb, scope, node,
7352 IrInstErrorReturnTraceNull);
6300 return ir_lval_wrap(irb, scope, error_return_trace, lval, result_loc);7353 return ir_lval_wrap(irb, scope, error_return_trace, lval, result_loc);
6301 }7354 }
6302 case BuiltinFnIdAtomicRmw:7355 case BuiltinFnIdAtomicRmw:
6303 {7356 {
6304 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7357 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6305 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7358 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6306 if (arg0_value == irb->codegen->invalid_instruction)7359 if (arg0_value == irb->codegen->invalid_inst_src)
6307 return arg0_value;7360 return arg0_value;
63087361
6309 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7362 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6310 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7363 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6311 if (arg1_value == irb->codegen->invalid_instruction)7364 if (arg1_value == irb->codegen->invalid_inst_src)
6312 return arg1_value;7365 return arg1_value;
63137366
6314 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);7367 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
6315 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);7368 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
6316 if (arg2_value == irb->codegen->invalid_instruction)7369 if (arg2_value == irb->codegen->invalid_inst_src)
6317 return arg2_value;7370 return arg2_value;
63187371
6319 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);7372 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
6320 IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope);7373 IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope);
6321 if (arg3_value == irb->codegen->invalid_instruction)7374 if (arg3_value == irb->codegen->invalid_inst_src)
6322 return arg3_value;7375 return arg3_value;
63237376
6324 AstNode *arg4_node = node->data.fn_call_expr.params.at(4);7377 AstNode *arg4_node = node->data.fn_call_expr.params.at(4);
6325 IrInstruction *arg4_value = ir_gen_node(irb, arg4_node, scope);7378 IrInstSrc *arg4_value = ir_gen_node(irb, arg4_node, scope);
6326 if (arg4_value == irb->codegen->invalid_instruction)7379 if (arg4_value == irb->codegen->invalid_inst_src)
6327 return arg4_value;7380 return arg4_value;
63287381
6329 IrInstruction *inst = ir_build_atomic_rmw(irb, scope, node, arg0_value, arg1_value, arg2_value, arg3_value,7382 IrInstSrc *inst = ir_build_atomic_rmw_src(irb, scope, node,
6330 arg4_value,7383 arg0_value, arg1_value, arg2_value, arg3_value, arg4_value);
6331 // these 2 values don't mean anything since we passed non-null values for other args
6332 AtomicRmwOp_xchg, AtomicOrderMonotonic);
6333 return ir_lval_wrap(irb, scope, inst, lval, result_loc);7384 return ir_lval_wrap(irb, scope, inst, lval, result_loc);
6334 }7385 }
6335 case BuiltinFnIdAtomicLoad:7386 case BuiltinFnIdAtomicLoad:
6336 {7387 {
6337 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7388 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6338 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7389 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6339 if (arg0_value == irb->codegen->invalid_instruction)7390 if (arg0_value == irb->codegen->invalid_inst_src)
6340 return arg0_value;7391 return arg0_value;
63417392
6342 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7393 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6343 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7394 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6344 if (arg1_value == irb->codegen->invalid_instruction)7395 if (arg1_value == irb->codegen->invalid_inst_src)
6345 return arg1_value;7396 return arg1_value;
63467397
6347 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);7398 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
6348 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);7399 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
6349 if (arg2_value == irb->codegen->invalid_instruction)7400 if (arg2_value == irb->codegen->invalid_inst_src)
6350 return arg2_value;7401 return arg2_value;
63517402
6352 IrInstruction *inst = ir_build_atomic_load(irb, scope, node, arg0_value, arg1_value, arg2_value,7403 IrInstSrc *inst = ir_build_atomic_load_src(irb, scope, node, arg0_value, arg1_value, arg2_value);
6353 // this value does not mean anything since we passed non-null values for other arg
6354 AtomicOrderMonotonic);
6355 return ir_lval_wrap(irb, scope, inst, lval, result_loc);7404 return ir_lval_wrap(irb, scope, inst, lval, result_loc);
6356 }7405 }
6357 case BuiltinFnIdAtomicStore:7406 case BuiltinFnIdAtomicStore:
6358 {7407 {
6359 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7408 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6360 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7409 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6361 if (arg0_value == irb->codegen->invalid_instruction)7410 if (arg0_value == irb->codegen->invalid_inst_src)
6362 return arg0_value;7411 return arg0_value;
63637412
6364 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7413 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6365 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7414 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6366 if (arg1_value == irb->codegen->invalid_instruction)7415 if (arg1_value == irb->codegen->invalid_inst_src)
6367 return arg1_value;7416 return arg1_value;
63687417
6369 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);7418 AstNode *arg2_node = node->data.fn_call_expr.params.at(2);
6370 IrInstruction *arg2_value = ir_gen_node(irb, arg2_node, scope);7419 IrInstSrc *arg2_value = ir_gen_node(irb, arg2_node, scope);
6371 if (arg2_value == irb->codegen->invalid_instruction)7420 if (arg2_value == irb->codegen->invalid_inst_src)
6372 return arg2_value;7421 return arg2_value;
63737422
6374 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);7423 AstNode *arg3_node = node->data.fn_call_expr.params.at(3);
6375 IrInstruction *arg3_value = ir_gen_node(irb, arg3_node, scope);7424 IrInstSrc *arg3_value = ir_gen_node(irb, arg3_node, scope);
6376 if (arg3_value == irb->codegen->invalid_instruction)7425 if (arg3_value == irb->codegen->invalid_inst_src)
6377 return arg3_value;7426 return arg3_value;
63787427
6379 IrInstruction *inst = ir_build_atomic_store(irb, scope, node, arg0_value, arg1_value, arg2_value, arg3_value,7428 IrInstSrc *inst = ir_build_atomic_store_src(irb, scope, node, arg0_value, arg1_value,
6380 // this value does not mean anything since we passed non-null values for other arg7429 arg2_value, arg3_value);
6381 AtomicOrderMonotonic);
6382 return ir_lval_wrap(irb, scope, inst, lval, result_loc);7430 return ir_lval_wrap(irb, scope, inst, lval, result_loc);
6383 }7431 }
6384 case BuiltinFnIdIntToEnum:7432 case BuiltinFnIdIntToEnum:
6385 {7433 {
6386 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7434 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6387 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7435 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6388 if (arg0_value == irb->codegen->invalid_instruction)7436 if (arg0_value == irb->codegen->invalid_inst_src)
6389 return arg0_value;7437 return arg0_value;
63907438
6391 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7439 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6392 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7440 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6393 if (arg1_value == irb->codegen->invalid_instruction)7441 if (arg1_value == irb->codegen->invalid_inst_src)
6394 return arg1_value;7442 return arg1_value;
63957443
6396 IrInstruction *result = ir_build_int_to_enum(irb, scope, node, arg0_value, arg1_value);7444 IrInstSrc *result = ir_build_int_to_enum_src(irb, scope, node, arg0_value, arg1_value);
6397 return ir_lval_wrap(irb, scope, result, lval, result_loc);7445 return ir_lval_wrap(irb, scope, result, lval, result_loc);
6398 }7446 }
6399 case BuiltinFnIdEnumToInt:7447 case BuiltinFnIdEnumToInt:
6400 {7448 {
6401 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7449 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6402 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7450 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6403 if (arg0_value == irb->codegen->invalid_instruction)7451 if (arg0_value == irb->codegen->invalid_inst_src)
6404 return arg0_value;7452 return arg0_value;
64057453
6406 IrInstruction *result = ir_build_enum_to_int(irb, scope, node, arg0_value);7454 IrInstSrc *result = ir_build_enum_to_int(irb, scope, node, arg0_value);
6407 return ir_lval_wrap(irb, scope, result, lval, result_loc);7455 return ir_lval_wrap(irb, scope, result, lval, result_loc);
6408 }7456 }
6409 case BuiltinFnIdCtz:7457 case BuiltinFnIdCtz:
...@@ -6413,16 +7461,16 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -6413,16 +7461,16 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
6413 case BuiltinFnIdBitReverse:7461 case BuiltinFnIdBitReverse:
6414 {7462 {
6415 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7463 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6416 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7464 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6417 if (arg0_value == irb->codegen->invalid_instruction)7465 if (arg0_value == irb->codegen->invalid_inst_src)
6418 return arg0_value;7466 return arg0_value;
64197467
6420 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7468 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6421 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7469 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6422 if (arg1_value == irb->codegen->invalid_instruction)7470 if (arg1_value == irb->codegen->invalid_inst_src)
6423 return arg1_value;7471 return arg1_value;
64247472
6425 IrInstruction *result;7473 IrInstSrc *result;
6426 switch (builtin_fn->id) {7474 switch (builtin_fn->id) {
6427 case BuiltinFnIdCtz:7475 case BuiltinFnIdCtz:
6428 result = ir_build_ctz(irb, scope, node, arg0_value, arg1_value);7476 result = ir_build_ctz(irb, scope, node, arg0_value, arg1_value);
...@@ -6447,28 +7495,28 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -6447,28 +7495,28 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
6447 case BuiltinFnIdHasDecl:7495 case BuiltinFnIdHasDecl:
6448 {7496 {
6449 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);7497 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
6450 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);7498 IrInstSrc *arg0_value = ir_gen_node(irb, arg0_node, scope);
6451 if (arg0_value == irb->codegen->invalid_instruction)7499 if (arg0_value == irb->codegen->invalid_inst_src)
6452 return arg0_value;7500 return arg0_value;
64537501
6454 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);7502 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
6455 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);7503 IrInstSrc *arg1_value = ir_gen_node(irb, arg1_node, scope);
6456 if (arg1_value == irb->codegen->invalid_instruction)7504 if (arg1_value == irb->codegen->invalid_inst_src)
6457 return arg1_value;7505 return arg1_value;
64587506
6459 IrInstruction *has_decl = ir_build_has_decl(irb, scope, node, arg0_value, arg1_value);7507 IrInstSrc *has_decl = ir_build_has_decl(irb, scope, node, arg0_value, arg1_value);
6460 return ir_lval_wrap(irb, scope, has_decl, lval, result_loc);7508 return ir_lval_wrap(irb, scope, has_decl, lval, result_loc);
6461 }7509 }
6462 case BuiltinFnIdUnionInit:7510 case BuiltinFnIdUnionInit:
6463 {7511 {
6464 AstNode *union_type_node = node->data.fn_call_expr.params.at(0);7512 AstNode *union_type_node = node->data.fn_call_expr.params.at(0);
6465 IrInstruction *union_type_inst = ir_gen_node(irb, union_type_node, scope);7513 IrInstSrc *union_type_inst = ir_gen_node(irb, union_type_node, scope);
6466 if (union_type_inst == irb->codegen->invalid_instruction)7514 if (union_type_inst == irb->codegen->invalid_inst_src)
6467 return union_type_inst;7515 return union_type_inst;
64687516
6469 AstNode *name_node = node->data.fn_call_expr.params.at(1);7517 AstNode *name_node = node->data.fn_call_expr.params.at(1);
6470 IrInstruction *name_inst = ir_gen_node(irb, name_node, scope);7518 IrInstSrc *name_inst = ir_gen_node(irb, name_node, scope);
6471 if (name_inst == irb->codegen->invalid_instruction)7519 if (name_inst == irb->codegen->invalid_inst_src)
6472 return name_inst;7520 return name_inst;
64737521
6474 AstNode *init_node = node->data.fn_call_expr.params.at(2);7522 AstNode *init_node = node->data.fn_call_expr.params.at(2);
...@@ -6480,7 +7528,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -6480,7 +7528,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
6480 zig_unreachable();7528 zig_unreachable();
6481}7529}
64827530
6483static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,7531static IrInstSrc *ir_gen_fn_call(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
6484 ResultLoc *result_loc)7532 ResultLoc *result_loc)
6485{7533{
6486 assert(node->type == NodeTypeFnCallExpr);7534 assert(node->type == NodeTypeFnCallExpr);
...@@ -6493,16 +7541,16 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node...@@ -6493,16 +7541,16 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node
6493 nullptr, node->data.fn_call_expr.params.items, node->data.fn_call_expr.params.length, lval, result_loc);7541 nullptr, node->data.fn_call_expr.params.items, node->data.fn_call_expr.params.length, lval, result_loc);
6494}7542}
64957543
6496static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,7544static IrInstSrc *ir_gen_if_bool_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
6497 ResultLoc *result_loc)7545 ResultLoc *result_loc)
6498{7546{
6499 assert(node->type == NodeTypeIfBoolExpr);7547 assert(node->type == NodeTypeIfBoolExpr);
65007548
6501 IrInstruction *condition = ir_gen_node(irb, node->data.if_bool_expr.condition, scope);7549 IrInstSrc *condition = ir_gen_node(irb, node->data.if_bool_expr.condition, scope);
6502 if (condition == irb->codegen->invalid_instruction)7550 if (condition == irb->codegen->invalid_inst_src)
6503 return irb->codegen->invalid_instruction;7551 return irb->codegen->invalid_inst_src;
65047552
6505 IrInstruction *is_comptime;7553 IrInstSrc *is_comptime;
6506 if (ir_should_inline(irb->exec, scope)) {7554 if (ir_should_inline(irb->exec, scope)) {
6507 is_comptime = ir_build_const_bool(irb, scope, node, true);7555 is_comptime = ir_build_const_bool(irb, scope, node, true);
6508 } else {7556 } else {
...@@ -6512,11 +7560,11 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode...@@ -6512,11 +7560,11 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode
6512 AstNode *then_node = node->data.if_bool_expr.then_block;7560 AstNode *then_node = node->data.if_bool_expr.then_block;
6513 AstNode *else_node = node->data.if_bool_expr.else_node;7561 AstNode *else_node = node->data.if_bool_expr.else_node;
65147562
6515 IrBasicBlock *then_block = ir_create_basic_block(irb, scope, "Then");7563 IrBasicBlockSrc *then_block = ir_create_basic_block(irb, scope, "Then");
6516 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "Else");7564 IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "Else");
6517 IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "EndIf");7565 IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "EndIf");
65187566
6519 IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, condition,7567 IrInstSrc *cond_br_inst = ir_build_cond_br(irb, scope, node, condition,
6520 then_block, else_block, is_comptime);7568 then_block, else_block, is_comptime);
6521 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,7569 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,
6522 result_loc, is_comptime);7570 result_loc, is_comptime);
...@@ -6524,70 +7572,70 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode...@@ -6524,70 +7572,70 @@ static IrInstruction *ir_gen_if_bool_expr(IrBuilder *irb, Scope *scope, AstNode
6524 ir_set_cursor_at_end_and_append_block(irb, then_block);7572 ir_set_cursor_at_end_and_append_block(irb, then_block);
65257573
6526 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);7574 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);
6527 IrInstruction *then_expr_result = ir_gen_node_extra(irb, then_node, subexpr_scope, lval,7575 IrInstSrc *then_expr_result = ir_gen_node_extra(irb, then_node, subexpr_scope, lval,
6528 &peer_parent->peers.at(0)->base);7576 &peer_parent->peers.at(0)->base);
6529 if (then_expr_result == irb->codegen->invalid_instruction)7577 if (then_expr_result == irb->codegen->invalid_inst_src)
6530 return irb->codegen->invalid_instruction;7578 return irb->codegen->invalid_inst_src;
6531 IrBasicBlock *after_then_block = irb->current_basic_block;7579 IrBasicBlockSrc *after_then_block = irb->current_basic_block;
6532 if (!instr_is_unreachable(then_expr_result))7580 if (!instr_is_unreachable(then_expr_result))
6533 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));7581 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
65347582
6535 ir_set_cursor_at_end_and_append_block(irb, else_block);7583 ir_set_cursor_at_end_and_append_block(irb, else_block);
6536 IrInstruction *else_expr_result;7584 IrInstSrc *else_expr_result;
6537 if (else_node) {7585 if (else_node) {
6538 else_expr_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base);7586 else_expr_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base);
6539 if (else_expr_result == irb->codegen->invalid_instruction)7587 if (else_expr_result == irb->codegen->invalid_inst_src)
6540 return irb->codegen->invalid_instruction;7588 return irb->codegen->invalid_inst_src;
6541 } else {7589 } else {
6542 else_expr_result = ir_build_const_void(irb, scope, node);7590 else_expr_result = ir_build_const_void(irb, scope, node);
6543 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);7591 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);
6544 }7592 }
6545 IrBasicBlock *after_else_block = irb->current_basic_block;7593 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
6546 if (!instr_is_unreachable(else_expr_result))7594 if (!instr_is_unreachable(else_expr_result))
6547 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));7595 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
65487596
6549 ir_set_cursor_at_end_and_append_block(irb, endif_block);7597 ir_set_cursor_at_end_and_append_block(irb, endif_block);
6550 IrInstruction **incoming_values = allocate<IrInstruction *>(2);7598 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
6551 incoming_values[0] = then_expr_result;7599 incoming_values[0] = then_expr_result;
6552 incoming_values[1] = else_expr_result;7600 incoming_values[1] = else_expr_result;
6553 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");7601 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
6554 incoming_blocks[0] = after_then_block;7602 incoming_blocks[0] = after_then_block;
6555 incoming_blocks[1] = after_else_block;7603 incoming_blocks[1] = after_else_block;
65567604
6557 IrInstruction *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);7605 IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
6558 return ir_expr_wrap(irb, scope, phi, result_loc);7606 return ir_expr_wrap(irb, scope, phi, result_loc);
6559}7607}
65607608
6561static IrInstruction *ir_gen_prefix_op_id_lval(IrBuilder *irb, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) {7609static IrInstSrc *ir_gen_prefix_op_id_lval(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrUnOp op_id, LVal lval) {
6562 assert(node->type == NodeTypePrefixOpExpr);7610 assert(node->type == NodeTypePrefixOpExpr);
6563 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;7611 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
65647612
6565 IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr);7613 IrInstSrc *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr);
6566 if (value == irb->codegen->invalid_instruction)7614 if (value == irb->codegen->invalid_inst_src)
6567 return value;7615 return value;
65687616
6569 return ir_build_un_op(irb, scope, node, op_id, value);7617 return ir_build_un_op(irb, scope, node, op_id, value);
6570}7618}
65717619
6572static IrInstruction *ir_gen_prefix_op_id(IrBuilder *irb, Scope *scope, AstNode *node, IrUnOp op_id) {7620static IrInstSrc *ir_gen_prefix_op_id(IrBuilderSrc *irb, Scope *scope, AstNode *node, IrUnOp op_id) {
6573 return ir_gen_prefix_op_id_lval(irb, scope, node, op_id, LValNone);7621 return ir_gen_prefix_op_id_lval(irb, scope, node, op_id, LValNone);
6574}7622}
65757623
6576static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc) {7624static IrInstSrc *ir_expr_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *inst, ResultLoc *result_loc) {
6577 if (inst == irb->codegen->invalid_instruction) return inst;7625 if (inst == irb->codegen->invalid_inst_src) return inst;
6578 ir_build_end_expr(irb, scope, inst->source_node, inst, result_loc);7626 ir_build_end_expr(irb, scope, inst->base.source_node, inst, result_loc);
6579 return inst;7627 return inst;
6580}7628}
65817629
6582static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval,7630static IrInstSrc *ir_lval_wrap(IrBuilderSrc *irb, Scope *scope, IrInstSrc *value, LVal lval,
6583 ResultLoc *result_loc)7631 ResultLoc *result_loc)
6584{7632{
6585 // This logic must be kept in sync with7633 // This logic must be kept in sync with
6586 // [STMT_EXPR_TEST_THING] <--- (search this token)7634 // [STMT_EXPR_TEST_THING] <--- (search this token)
6587 if (value == irb->codegen->invalid_instruction ||7635 if (value == irb->codegen->invalid_inst_src ||
6588 instr_is_unreachable(value) ||7636 instr_is_unreachable(value) ||
6589 value->source_node->type == NodeTypeDefer ||7637 value->base.source_node->type == NodeTypeDefer ||
6590 value->id == IrInstructionIdDeclVarSrc)7638 value->id == IrInstSrcIdDeclVar)
6591 {7639 {
6592 return value;7640 return value;
6593 }7641 }
...@@ -6595,7 +7643,7 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *...@@ -6595,7 +7643,7 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *
6595 if (lval == LValPtr) {7643 if (lval == LValPtr) {
6596 // We needed a pointer to a value, but we got a value. So we create7644 // We needed a pointer to a value, but we got a value. So we create
6597 // an instruction which just makes a pointer of it.7645 // an instruction which just makes a pointer of it.
6598 return ir_build_ref(irb, scope, value->source_node, value, false, false);7646 return ir_build_ref_src(irb, scope, value->base.source_node, value, false, false);
6599 } else if (result_loc != nullptr) {7647 } else if (result_loc != nullptr) {
6600 return ir_expr_wrap(irb, scope, value, result_loc);7648 return ir_expr_wrap(irb, scope, value, result_loc);
6601 } else {7649 } else {
...@@ -6618,7 +7666,7 @@ static PtrLen star_token_to_ptr_len(TokenId token_id) {...@@ -6618,7 +7666,7 @@ static PtrLen star_token_to_ptr_len(TokenId token_id) {
6618 }7666 }
6619}7667}
66207668
6621static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode *node) {7669static IrInstSrc *ir_gen_pointer_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
6622 assert(node->type == NodeTypePointerType);7670 assert(node->type == NodeTypePointerType);
66237671
6624 PtrLen ptr_len = star_token_to_ptr_len(node->data.pointer_type.star_token->id);7672 PtrLen ptr_len = star_token_to_ptr_len(node->data.pointer_type.star_token->id);
...@@ -6630,26 +7678,26 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode...@@ -6630,26 +7678,26 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
6630 AstNode *expr_node = node->data.pointer_type.op_expr;7678 AstNode *expr_node = node->data.pointer_type.op_expr;
6631 AstNode *align_expr = node->data.pointer_type.align_expr;7679 AstNode *align_expr = node->data.pointer_type.align_expr;
66327680
6633 IrInstruction *sentinel;7681 IrInstSrc *sentinel;
6634 if (sentinel_expr != nullptr) {7682 if (sentinel_expr != nullptr) {
6635 sentinel = ir_gen_node(irb, sentinel_expr, scope);7683 sentinel = ir_gen_node(irb, sentinel_expr, scope);
6636 if (sentinel == irb->codegen->invalid_instruction)7684 if (sentinel == irb->codegen->invalid_inst_src)
6637 return sentinel;7685 return sentinel;
6638 } else {7686 } else {
6639 sentinel = nullptr;7687 sentinel = nullptr;
6640 }7688 }
66417689
6642 IrInstruction *align_value;7690 IrInstSrc *align_value;
6643 if (align_expr != nullptr) {7691 if (align_expr != nullptr) {
6644 align_value = ir_gen_node(irb, align_expr, scope);7692 align_value = ir_gen_node(irb, align_expr, scope);
6645 if (align_value == irb->codegen->invalid_instruction)7693 if (align_value == irb->codegen->invalid_inst_src)
6646 return align_value;7694 return align_value;
6647 } else {7695 } else {
6648 align_value = nullptr;7696 align_value = nullptr;
6649 }7697 }
66507698
6651 IrInstruction *child_type = ir_gen_node(irb, expr_node, scope);7699 IrInstSrc *child_type = ir_gen_node(irb, expr_node, scope);
6652 if (child_type == irb->codegen->invalid_instruction)7700 if (child_type == irb->codegen->invalid_inst_src)
6653 return child_type;7701 return child_type;
66547702
6655 uint32_t bit_offset_start = 0;7703 uint32_t bit_offset_start = 0;
...@@ -6659,7 +7707,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode...@@ -6659,7 +7707,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
6659 bigint_append_buf(val_buf, node->data.pointer_type.bit_offset_start, 10);7707 bigint_append_buf(val_buf, node->data.pointer_type.bit_offset_start, 10);
6660 exec_add_error_node(irb->codegen, irb->exec, node,7708 exec_add_error_node(irb->codegen, irb->exec, node,
6661 buf_sprintf("value %s too large for u32 bit offset", buf_ptr(val_buf)));7709 buf_sprintf("value %s too large for u32 bit offset", buf_ptr(val_buf)));
6662 return irb->codegen->invalid_instruction;7710 return irb->codegen->invalid_inst_src;
6663 }7711 }
6664 bit_offset_start = bigint_as_u32(node->data.pointer_type.bit_offset_start);7712 bit_offset_start = bigint_as_u32(node->data.pointer_type.bit_offset_start);
6665 }7713 }
...@@ -6671,7 +7719,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode...@@ -6671,7 +7719,7 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
6671 bigint_append_buf(val_buf, node->data.pointer_type.host_int_bytes, 10);7719 bigint_append_buf(val_buf, node->data.pointer_type.host_int_bytes, 10);
6672 exec_add_error_node(irb->codegen, irb->exec, node,7720 exec_add_error_node(irb->codegen, irb->exec, node,
6673 buf_sprintf("value %s too large for u32 byte count", buf_ptr(val_buf)));7721 buf_sprintf("value %s too large for u32 byte count", buf_ptr(val_buf)));
6674 return irb->codegen->invalid_instruction;7722 return irb->codegen->invalid_inst_src;
6675 }7723 }
6676 host_int_bytes = bigint_as_u32(node->data.pointer_type.host_int_bytes);7724 host_int_bytes = bigint_as_u32(node->data.pointer_type.host_int_bytes);
6677 }7725 }
...@@ -6679,43 +7727,43 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode...@@ -6679,43 +7727,43 @@ static IrInstruction *ir_gen_pointer_type(IrBuilder *irb, Scope *scope, AstNode
6679 if (host_int_bytes != 0 && bit_offset_start >= host_int_bytes * 8) {7727 if (host_int_bytes != 0 && bit_offset_start >= host_int_bytes * 8) {
6680 exec_add_error_node(irb->codegen, irb->exec, node,7728 exec_add_error_node(irb->codegen, irb->exec, node,
6681 buf_sprintf("bit offset starts after end of host integer"));7729 buf_sprintf("bit offset starts after end of host integer"));
6682 return irb->codegen->invalid_instruction;7730 return irb->codegen->invalid_inst_src;
6683 }7731 }
66847732
6685 return ir_build_ptr_type(irb, scope, node, child_type, is_const, is_volatile,7733 return ir_build_ptr_type(irb, scope, node, child_type, is_const, is_volatile,
6686 ptr_len, sentinel, align_value, bit_offset_start, host_int_bytes, is_allow_zero);7734 ptr_len, sentinel, align_value, bit_offset_start, host_int_bytes, is_allow_zero);
6687}7735}
66887736
6689static IrInstruction *ir_gen_catch_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node,7737static IrInstSrc *ir_gen_catch_unreachable(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
6690 AstNode *expr_node, LVal lval, ResultLoc *result_loc)7738 AstNode *expr_node, LVal lval, ResultLoc *result_loc)
6691{7739{
6692 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);7740 IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
6693 if (err_union_ptr == irb->codegen->invalid_instruction)7741 if (err_union_ptr == irb->codegen->invalid_inst_src)
6694 return irb->codegen->invalid_instruction;7742 return irb->codegen->invalid_inst_src;
66957743
6696 IrInstruction *payload_ptr = ir_build_unwrap_err_payload(irb, scope, source_node, err_union_ptr, true, false);7744 IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, scope, source_node, err_union_ptr, true, false);
6697 if (payload_ptr == irb->codegen->invalid_instruction)7745 if (payload_ptr == irb->codegen->invalid_inst_src)
6698 return irb->codegen->invalid_instruction;7746 return irb->codegen->invalid_inst_src;
66997747
6700 if (lval == LValPtr)7748 if (lval == LValPtr)
6701 return payload_ptr;7749 return payload_ptr;
67027750
6703 IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, source_node, payload_ptr);7751 IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, source_node, payload_ptr);
6704 return ir_expr_wrap(irb, scope, load_ptr, result_loc);7752 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
6705}7753}
67067754
6707static IrInstruction *ir_gen_bool_not(IrBuilder *irb, Scope *scope, AstNode *node) {7755static IrInstSrc *ir_gen_bool_not(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
6708 assert(node->type == NodeTypePrefixOpExpr);7756 assert(node->type == NodeTypePrefixOpExpr);
6709 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;7757 AstNode *expr_node = node->data.prefix_op_expr.primary_expr;
67107758
6711 IrInstruction *value = ir_gen_node(irb, expr_node, scope);7759 IrInstSrc *value = ir_gen_node(irb, expr_node, scope);
6712 if (value == irb->codegen->invalid_instruction)7760 if (value == irb->codegen->invalid_inst_src)
6713 return irb->codegen->invalid_instruction;7761 return irb->codegen->invalid_inst_src;
67147762
6715 return ir_build_bool_not(irb, scope, node, value);7763 return ir_build_bool_not(irb, scope, node, value);
6716}7764}
67177765
6718static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,7766static IrInstSrc *ir_gen_prefix_op_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
6719 ResultLoc *result_loc)7767 ResultLoc *result_loc)
6720{7768{
6721 assert(node->type == NodeTypePrefixOpExpr);7769 assert(node->type == NodeTypePrefixOpExpr);
...@@ -6743,12 +7791,12 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod...@@ -6743,12 +7791,12 @@ static IrInstruction *ir_gen_prefix_op_expr(IrBuilder *irb, Scope *scope, AstNod
6743 zig_unreachable();7791 zig_unreachable();
6744}7792}
67457793
6746static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNode *source_node,7794static IrInstSrc *ir_gen_union_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *source_node,
6747 IrInstruction *union_type, IrInstruction *field_name, AstNode *expr_node,7795 IrInstSrc *union_type, IrInstSrc *field_name, AstNode *expr_node,
6748 LVal lval, ResultLoc *parent_result_loc)7796 LVal lval, ResultLoc *parent_result_loc)
6749{7797{
6750 IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, source_node, parent_result_loc, union_type);7798 IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, source_node, parent_result_loc, union_type);
6751 IrInstruction *field_ptr = ir_build_field_ptr_instruction(irb, scope, source_node, container_ptr,7799 IrInstSrc *field_ptr = ir_build_field_ptr_instruction(irb, scope, source_node, container_ptr,
6752 field_name, true);7800 field_name, true);
67537801
6754 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);7802 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
...@@ -6757,18 +7805,18 @@ static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNo...@@ -6757,18 +7805,18 @@ static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNo
6757 ir_ref_instruction(field_ptr, irb->current_basic_block);7805 ir_ref_instruction(field_ptr, irb->current_basic_block);
6758 ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base);7806 ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base);
67597807
6760 IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone,7808 IrInstSrc *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone,
6761 &result_loc_inst->base);7809 &result_loc_inst->base);
6762 if (expr_value == irb->codegen->invalid_instruction)7810 if (expr_value == irb->codegen->invalid_inst_src)
6763 return expr_value;7811 return expr_value;
67647812
6765 IrInstruction *init_union = ir_build_union_init_named_field(irb, scope, source_node, union_type,7813 IrInstSrc *init_union = ir_build_union_init_named_field(irb, scope, source_node, union_type,
6766 field_name, field_ptr, container_ptr);7814 field_name, field_ptr, container_ptr);
67677815
6768 return ir_lval_wrap(irb, scope, init_union, lval, parent_result_loc);7816 return ir_lval_wrap(irb, scope, init_union, lval, parent_result_loc);
6769}7817}
67707818
6771static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,7819static IrInstSrc *ir_gen_container_init_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
6772 ResultLoc *parent_result_loc)7820 ResultLoc *parent_result_loc)
6773{7821{
6774 assert(node->type == NodeTypeContainerInitExpr);7822 assert(node->type == NodeTypeContainerInitExpr);
...@@ -6780,42 +7828,42 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -6780,42 +7828,42 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
6780 ResultLoc *child_result_loc;7828 ResultLoc *child_result_loc;
6781 AstNode *init_array_type_source_node;7829 AstNode *init_array_type_source_node;
6782 if (container_init_expr->type != nullptr) {7830 if (container_init_expr->type != nullptr) {
6783 IrInstruction *container_type;7831 IrInstSrc *container_type;
6784 if (container_init_expr->type->type == NodeTypeInferredArrayType) {7832 if (container_init_expr->type->type == NodeTypeInferredArrayType) {
6785 if (kind == ContainerInitKindStruct) {7833 if (kind == ContainerInitKindStruct) {
6786 add_node_error(irb->codegen, container_init_expr->type,7834 add_node_error(irb->codegen, container_init_expr->type,
6787 buf_sprintf("initializing array with struct syntax"));7835 buf_sprintf("initializing array with struct syntax"));
6788 return irb->codegen->invalid_instruction;7836 return irb->codegen->invalid_inst_src;
6789 }7837 }
6790 IrInstruction *sentinel;7838 IrInstSrc *sentinel;
6791 if (container_init_expr->type->data.inferred_array_type.sentinel != nullptr) {7839 if (container_init_expr->type->data.inferred_array_type.sentinel != nullptr) {
6792 sentinel = ir_gen_node(irb, container_init_expr->type->data.inferred_array_type.sentinel, scope);7840 sentinel = ir_gen_node(irb, container_init_expr->type->data.inferred_array_type.sentinel, scope);
6793 if (sentinel == irb->codegen->invalid_instruction)7841 if (sentinel == irb->codegen->invalid_inst_src)
6794 return sentinel;7842 return sentinel;
6795 } else {7843 } else {
6796 sentinel = nullptr;7844 sentinel = nullptr;
6797 }7845 }
67987846
6799 IrInstruction *elem_type = ir_gen_node(irb,7847 IrInstSrc *elem_type = ir_gen_node(irb,
6800 container_init_expr->type->data.inferred_array_type.child_type, scope);7848 container_init_expr->type->data.inferred_array_type.child_type, scope);
6801 if (elem_type == irb->codegen->invalid_instruction)7849 if (elem_type == irb->codegen->invalid_inst_src)
6802 return elem_type;7850 return elem_type;
6803 size_t item_count = container_init_expr->entries.length;7851 size_t item_count = container_init_expr->entries.length;
6804 IrInstruction *item_count_inst = ir_build_const_usize(irb, scope, node, item_count);7852 IrInstSrc *item_count_inst = ir_build_const_usize(irb, scope, node, item_count);
6805 container_type = ir_build_array_type(irb, scope, node, item_count_inst, sentinel, elem_type);7853 container_type = ir_build_array_type(irb, scope, node, item_count_inst, sentinel, elem_type);
6806 } else {7854 } else {
6807 container_type = ir_gen_node(irb, container_init_expr->type, scope);7855 container_type = ir_gen_node(irb, container_init_expr->type, scope);
6808 if (container_type == irb->codegen->invalid_instruction)7856 if (container_type == irb->codegen->invalid_inst_src)
6809 return container_type;7857 return container_type;
6810 }7858 }
68117859
6812 result_loc_cast = ir_build_cast_result_loc(irb, container_type, parent_result_loc);7860 result_loc_cast = ir_build_cast_result_loc(irb, container_type, parent_result_loc);
6813 child_result_loc = &result_loc_cast->base;7861 child_result_loc = &result_loc_cast->base;
6814 init_array_type_source_node = container_type->source_node;7862 init_array_type_source_node = container_type->base.source_node;
6815 } else {7863 } else {
6816 child_result_loc = parent_result_loc;7864 child_result_loc = parent_result_loc;
6817 if (parent_result_loc->source_instruction != nullptr) {7865 if (parent_result_loc->source_instruction != nullptr) {
6818 init_array_type_source_node = parent_result_loc->source_instruction->source_node;7866 init_array_type_source_node = parent_result_loc->source_instruction->base.source_node;
6819 } else {7867 } else {
6820 init_array_type_source_node = node;7868 init_array_type_source_node = node;
6821 }7869 }
...@@ -6823,11 +7871,11 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -6823,11 +7871,11 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
68237871
6824 switch (kind) {7872 switch (kind) {
6825 case ContainerInitKindStruct: {7873 case ContainerInitKindStruct: {
6826 IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc,7874 IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc,
6827 nullptr);7875 nullptr);
68287876
6829 size_t field_count = container_init_expr->entries.length;7877 size_t field_count = container_init_expr->entries.length;
6830 IrInstructionContainerInitFieldsField *fields = allocate<IrInstructionContainerInitFieldsField>(field_count);7878 IrInstSrcContainerInitFieldsField *fields = allocate<IrInstSrcContainerInitFieldsField>(field_count);
6831 for (size_t i = 0; i < field_count; i += 1) {7879 for (size_t i = 0; i < field_count; i += 1) {
6832 AstNode *entry_node = container_init_expr->entries.at(i);7880 AstNode *entry_node = container_init_expr->entries.at(i);
6833 assert(entry_node->type == NodeTypeStructValueField);7881 assert(entry_node->type == NodeTypeStructValueField);
...@@ -6835,7 +7883,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -6835,7 +7883,7 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
6835 Buf *name = entry_node->data.struct_val_field.name;7883 Buf *name = entry_node->data.struct_val_field.name;
6836 AstNode *expr_node = entry_node->data.struct_val_field.expr;7884 AstNode *expr_node = entry_node->data.struct_val_field.expr;
68377885
6838 IrInstruction *field_ptr = ir_build_field_ptr(irb, scope, entry_node, container_ptr, name, true);7886 IrInstSrc *field_ptr = ir_build_field_ptr(irb, scope, entry_node, container_ptr, name, true);
6839 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);7887 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
6840 result_loc_inst->base.id = ResultLocIdInstruction;7888 result_loc_inst->base.id = ResultLocIdInstruction;
6841 result_loc_inst->base.source_instruction = field_ptr;7889 result_loc_inst->base.source_instruction = field_ptr;
...@@ -6843,16 +7891,16 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -6843,16 +7891,16 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
6843 ir_ref_instruction(field_ptr, irb->current_basic_block);7891 ir_ref_instruction(field_ptr, irb->current_basic_block);
6844 ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base);7892 ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base);
68457893
6846 IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone,7894 IrInstSrc *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone,
6847 &result_loc_inst->base);7895 &result_loc_inst->base);
6848 if (expr_value == irb->codegen->invalid_instruction)7896 if (expr_value == irb->codegen->invalid_inst_src)
6849 return expr_value;7897 return expr_value;
68507898
6851 fields[i].name = name;7899 fields[i].name = name;
6852 fields[i].source_node = entry_node;7900 fields[i].source_node = entry_node;
6853 fields[i].result_loc = field_ptr;7901 fields[i].result_loc = field_ptr;
6854 }7902 }
6855 IrInstruction *result = ir_build_container_init_fields(irb, scope, node, field_count,7903 IrInstSrc *result = ir_build_container_init_fields(irb, scope, node, field_count,
6856 fields, container_ptr);7904 fields, container_ptr);
68577905
6858 if (result_loc_cast != nullptr) {7906 if (result_loc_cast != nullptr) {
...@@ -6863,15 +7911,15 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -6863,15 +7911,15 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
6863 case ContainerInitKindArray: {7911 case ContainerInitKindArray: {
6864 size_t item_count = container_init_expr->entries.length;7912 size_t item_count = container_init_expr->entries.length;
68657913
6866 IrInstruction *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc,7914 IrInstSrc *container_ptr = ir_build_resolve_result(irb, scope, node, child_result_loc,
6867 nullptr);7915 nullptr);
68687916
6869 IrInstruction **result_locs = allocate<IrInstruction *>(item_count);7917 IrInstSrc **result_locs = allocate<IrInstSrc *>(item_count);
6870 for (size_t i = 0; i < item_count; i += 1) {7918 for (size_t i = 0; i < item_count; i += 1) {
6871 AstNode *expr_node = container_init_expr->entries.at(i);7919 AstNode *expr_node = container_init_expr->entries.at(i);
68727920
6873 IrInstruction *elem_index = ir_build_const_usize(irb, scope, expr_node, i);7921 IrInstSrc *elem_index = ir_build_const_usize(irb, scope, expr_node, i);
6874 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr,7922 IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, scope, expr_node, container_ptr,
6875 elem_index, false, PtrLenSingle, init_array_type_source_node);7923 elem_index, false, PtrLenSingle, init_array_type_source_node);
6876 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);7924 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
6877 result_loc_inst->base.id = ResultLocIdInstruction;7925 result_loc_inst->base.id = ResultLocIdInstruction;
...@@ -6880,14 +7928,14 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -6880,14 +7928,14 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
6880 ir_ref_instruction(elem_ptr, irb->current_basic_block);7928 ir_ref_instruction(elem_ptr, irb->current_basic_block);
6881 ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base);7929 ir_build_reset_result(irb, scope, expr_node, &result_loc_inst->base);
68827930
6883 IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone,7931 IrInstSrc *expr_value = ir_gen_node_extra(irb, expr_node, scope, LValNone,
6884 &result_loc_inst->base);7932 &result_loc_inst->base);
6885 if (expr_value == irb->codegen->invalid_instruction)7933 if (expr_value == irb->codegen->invalid_inst_src)
6886 return expr_value;7934 return expr_value;
68877935
6888 result_locs[i] = elem_ptr;7936 result_locs[i] = elem_ptr;
6889 }7937 }
6890 IrInstruction *result = ir_build_container_init_list(irb, scope, node, item_count,7938 IrInstSrc *result = ir_build_container_init_list(irb, scope, node, item_count,
6891 result_locs, container_ptr, init_array_type_source_node);7939 result_locs, container_ptr, init_array_type_source_node);
6892 if (result_loc_cast != nullptr) {7940 if (result_loc_cast != nullptr) {
6893 result = ir_build_implicit_cast(irb, scope, node, result, result_loc_cast);7941 result = ir_build_implicit_cast(irb, scope, node, result, result_loc_cast);
...@@ -6898,19 +7946,19 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -6898,19 +7946,19 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
6898 zig_unreachable();7946 zig_unreachable();
6899}7947}
69007948
6901static ResultLocVar *ir_build_var_result_loc(IrBuilder *irb, IrInstruction *alloca, ZigVar *var) {7949static ResultLocVar *ir_build_var_result_loc(IrBuilderSrc *irb, IrInstSrc *alloca, ZigVar *var) {
6902 ResultLocVar *result_loc_var = allocate<ResultLocVar>(1);7950 ResultLocVar *result_loc_var = allocate<ResultLocVar>(1);
6903 result_loc_var->base.id = ResultLocIdVar;7951 result_loc_var->base.id = ResultLocIdVar;
6904 result_loc_var->base.source_instruction = alloca;7952 result_loc_var->base.source_instruction = alloca;
6905 result_loc_var->base.allow_write_through_const = true;7953 result_loc_var->base.allow_write_through_const = true;
6906 result_loc_var->var = var;7954 result_loc_var->var = var;
69077955
6908 ir_build_reset_result(irb, alloca->scope, alloca->source_node, &result_loc_var->base);7956 ir_build_reset_result(irb, alloca->base.scope, alloca->base.source_node, &result_loc_var->base);
69097957
6910 return result_loc_var;7958 return result_loc_var;
6911}7959}
69127960
6913static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *dest_type,7961static ResultLocCast *ir_build_cast_result_loc(IrBuilderSrc *irb, IrInstSrc *dest_type,
6914 ResultLoc *parent_result_loc)7962 ResultLoc *parent_result_loc)
6915{7963{
6916 ResultLocCast *result_loc_cast = allocate<ResultLocCast>(1);7964 ResultLocCast *result_loc_cast = allocate<ResultLocCast>(1);
...@@ -6920,37 +7968,37 @@ static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *de...@@ -6920,37 +7968,37 @@ static ResultLocCast *ir_build_cast_result_loc(IrBuilder *irb, IrInstruction *de
6920 ir_ref_instruction(dest_type, irb->current_basic_block);7968 ir_ref_instruction(dest_type, irb->current_basic_block);
6921 result_loc_cast->parent = parent_result_loc;7969 result_loc_cast->parent = parent_result_loc;
69227970
6923 ir_build_reset_result(irb, dest_type->scope, dest_type->source_node, &result_loc_cast->base);7971 ir_build_reset_result(irb, dest_type->base.scope, dest_type->base.source_node, &result_loc_cast->base);
69247972
6925 return result_loc_cast;7973 return result_loc_cast;
6926}7974}
69277975
6928static void build_decl_var_and_init(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var,7976static void build_decl_var_and_init(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var,
6929 IrInstruction *init, const char *name_hint, IrInstruction *is_comptime)7977 IrInstSrc *init, const char *name_hint, IrInstSrc *is_comptime)
6930{7978{
6931 IrInstruction *alloca = ir_build_alloca_src(irb, scope, source_node, nullptr, name_hint, is_comptime);7979 IrInstSrc *alloca = ir_build_alloca_src(irb, scope, source_node, nullptr, name_hint, is_comptime);
6932 ResultLocVar *var_result_loc = ir_build_var_result_loc(irb, alloca, var);7980 ResultLocVar *var_result_loc = ir_build_var_result_loc(irb, alloca, var);
6933 ir_build_end_expr(irb, scope, source_node, init, &var_result_loc->base);7981 ir_build_end_expr(irb, scope, source_node, init, &var_result_loc->base);
6934 ir_build_var_decl_src(irb, scope, source_node, var, nullptr, alloca);7982 ir_build_var_decl_src(irb, scope, source_node, var, nullptr, alloca);
6935}7983}
69367984
6937static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *node) {7985static IrInstSrc *ir_gen_var_decl(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
6938 assert(node->type == NodeTypeVariableDeclaration);7986 assert(node->type == NodeTypeVariableDeclaration);
69397987
6940 AstNodeVariableDeclaration *variable_declaration = &node->data.variable_declaration;7988 AstNodeVariableDeclaration *variable_declaration = &node->data.variable_declaration;
69417989
6942 if (buf_eql_str(variable_declaration->symbol, "_")) {7990 if (buf_eql_str(variable_declaration->symbol, "_")) {
6943 add_node_error(irb->codegen, node, buf_sprintf("`_` is not a declarable symbol"));7991 add_node_error(irb->codegen, node, buf_sprintf("`_` is not a declarable symbol"));
6944 return irb->codegen->invalid_instruction;7992 return irb->codegen->invalid_inst_src;
6945 }7993 }
69467994
6947 // Used for the type expr and the align expr7995 // Used for the type expr and the align expr
6948 Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope);7996 Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope);
69497997
6950 IrInstruction *type_instruction;7998 IrInstSrc *type_instruction;
6951 if (variable_declaration->type != nullptr) {7999 if (variable_declaration->type != nullptr) {
6952 type_instruction = ir_gen_node(irb, variable_declaration->type, comptime_scope);8000 type_instruction = ir_gen_node(irb, variable_declaration->type, comptime_scope);
6953 if (type_instruction == irb->codegen->invalid_instruction)8001 if (type_instruction == irb->codegen->invalid_inst_src)
6954 return type_instruction;8002 return type_instruction;
6955 } else {8003 } else {
6956 type_instruction = nullptr;8004 type_instruction = nullptr;
...@@ -6961,22 +8009,22 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -6961,22 +8009,22 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
6961 bool is_extern = variable_declaration->is_extern;8009 bool is_extern = variable_declaration->is_extern;
69628010
6963 bool is_comptime_scalar = ir_should_inline(irb->exec, scope) || variable_declaration->is_comptime;8011 bool is_comptime_scalar = ir_should_inline(irb->exec, scope) || variable_declaration->is_comptime;
6964 IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, is_comptime_scalar);8012 IrInstSrc *is_comptime = ir_build_const_bool(irb, scope, node, is_comptime_scalar);
6965 ZigVar *var = ir_create_var(irb, node, scope, variable_declaration->symbol,8013 ZigVar *var = ir_create_var(irb, node, scope, variable_declaration->symbol,
6966 is_const, is_const, is_shadowable, is_comptime);8014 is_const, is_const, is_shadowable, is_comptime);
6967 // we detect IrInstructionIdDeclVarSrc in gen_block to make sure the next node8015 // we detect IrInstSrcDeclVar in gen_block to make sure the next node
6968 // is inside var->child_scope8016 // is inside var->child_scope
69698017
6970 if (!is_extern && !variable_declaration->expr) {8018 if (!is_extern && !variable_declaration->expr) {
6971 var->var_type = irb->codegen->builtin_types.entry_invalid;8019 var->var_type = irb->codegen->builtin_types.entry_invalid;
6972 add_node_error(irb->codegen, node, buf_sprintf("variables must be initialized"));8020 add_node_error(irb->codegen, node, buf_sprintf("variables must be initialized"));
6973 return irb->codegen->invalid_instruction;8021 return irb->codegen->invalid_inst_src;
6974 }8022 }
69758023
6976 IrInstruction *align_value = nullptr;8024 IrInstSrc *align_value = nullptr;
6977 if (variable_declaration->align_expr != nullptr) {8025 if (variable_declaration->align_expr != nullptr) {
6978 align_value = ir_gen_node(irb, variable_declaration->align_expr, comptime_scope);8026 align_value = ir_gen_node(irb, variable_declaration->align_expr, comptime_scope);
6979 if (align_value == irb->codegen->invalid_instruction)8027 if (align_value == irb->codegen->invalid_inst_src)
6980 return align_value;8028 return align_value;
6981 }8029 }
69828030
...@@ -6988,7 +8036,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -6988,7 +8036,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
6988 // Parser should ensure that this never happens8036 // Parser should ensure that this never happens
6989 assert(variable_declaration->threadlocal_tok == nullptr);8037 assert(variable_declaration->threadlocal_tok == nullptr);
69908038
6991 IrInstruction *alloca = ir_build_alloca_src(irb, scope, node, align_value,8039 IrInstSrc *alloca = ir_build_alloca_src(irb, scope, node, align_value,
6992 buf_ptr(variable_declaration->symbol), is_comptime);8040 buf_ptr(variable_declaration->symbol), is_comptime);
69938041
6994 // Create a result location for the initialization expression.8042 // Create a result location for the initialization expression.
...@@ -7006,19 +8054,19 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -7006,19 +8054,19 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
7006 Scope *init_scope = is_comptime_scalar ?8054 Scope *init_scope = is_comptime_scalar ?
7007 create_comptime_scope(irb->codegen, variable_declaration->expr, scope) : scope;8055 create_comptime_scope(irb->codegen, variable_declaration->expr, scope) : scope;
70088056
7009 // Temporarily set the name of the IrExecutable to the VariableDeclaration8057 // Temporarily set the name of the IrExecutableSrc to the VariableDeclaration
7010 // so that the struct or enum from the init expression inherits the name.8058 // so that the struct or enum from the init expression inherits the name.
7011 Buf *old_exec_name = irb->exec->name;8059 Buf *old_exec_name = irb->exec->name;
7012 irb->exec->name = variable_declaration->symbol;8060 irb->exec->name = variable_declaration->symbol;
7013 IrInstruction *init_value = ir_gen_node_extra(irb, variable_declaration->expr, init_scope,8061 IrInstSrc *init_value = ir_gen_node_extra(irb, variable_declaration->expr, init_scope,
7014 LValNone, init_result_loc);8062 LValNone, init_result_loc);
7015 irb->exec->name = old_exec_name;8063 irb->exec->name = old_exec_name;
70168064
7017 if (init_value == irb->codegen->invalid_instruction)8065 if (init_value == irb->codegen->invalid_inst_src)
7018 return irb->codegen->invalid_instruction;8066 return irb->codegen->invalid_inst_src;
70198067
7020 if (result_loc_cast != nullptr) {8068 if (result_loc_cast != nullptr) {
7021 IrInstruction *implicit_cast = ir_build_implicit_cast(irb, scope, init_value->source_node,8069 IrInstSrc *implicit_cast = ir_build_implicit_cast(irb, scope, init_value->base.source_node,
7022 init_value, result_loc_cast);8070 init_value, result_loc_cast);
7023 ir_build_end_expr(irb, scope, node, implicit_cast, &result_loc_var->base);8071 ir_build_end_expr(irb, scope, node, implicit_cast, &result_loc_var->base);
7024 }8072 }
...@@ -7026,7 +8074,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -7026,7 +8074,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
7026 return ir_build_var_decl_src(irb, scope, node, var, align_value, alloca);8074 return ir_build_var_decl_src(irb, scope, node, var, align_value, alloca);
7027}8075}
70288076
7029static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,8077static IrInstSrc *ir_gen_while_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
7030 ResultLoc *result_loc)8078 ResultLoc *result_loc)
7031{8079{
7032 assert(node->type == NodeTypeWhileExpr);8080 assert(node->type == NodeTypeWhileExpr);
...@@ -7034,15 +8082,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7034,15 +8082,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7034 AstNode *continue_expr_node = node->data.while_expr.continue_expr;8082 AstNode *continue_expr_node = node->data.while_expr.continue_expr;
7035 AstNode *else_node = node->data.while_expr.else_node;8083 AstNode *else_node = node->data.while_expr.else_node;
70368084
7037 IrBasicBlock *cond_block = ir_create_basic_block(irb, scope, "WhileCond");8085 IrBasicBlockSrc *cond_block = ir_create_basic_block(irb, scope, "WhileCond");
7038 IrBasicBlock *body_block = ir_create_basic_block(irb, scope, "WhileBody");8086 IrBasicBlockSrc *body_block = ir_create_basic_block(irb, scope, "WhileBody");
7039 IrBasicBlock *continue_block = continue_expr_node ?8087 IrBasicBlockSrc *continue_block = continue_expr_node ?
7040 ir_create_basic_block(irb, scope, "WhileContinue") : cond_block;8088 ir_create_basic_block(irb, scope, "WhileContinue") : cond_block;
7041 IrBasicBlock *end_block = ir_create_basic_block(irb, scope, "WhileEnd");8089 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, scope, "WhileEnd");
7042 IrBasicBlock *else_block = else_node ?8090 IrBasicBlockSrc *else_block = else_node ?
7043 ir_create_basic_block(irb, scope, "WhileElse") : end_block;8091 ir_create_basic_block(irb, scope, "WhileElse") : end_block;
70448092
7045 IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node,8093 IrInstSrc *is_comptime = ir_build_const_bool(irb, scope, node,
7046 ir_should_inline(irb->exec, scope) || node->data.while_expr.is_inline);8094 ir_should_inline(irb->exec, scope) || node->data.while_expr.is_inline);
7047 ir_build_br(irb, scope, node, cond_block, is_comptime);8095 ir_build_br(irb, scope, node, cond_block, is_comptime);
70488096
...@@ -7063,15 +8111,16 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7063,15 +8111,16 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7063 } else {8111 } else {
7064 payload_scope = subexpr_scope;8112 payload_scope = subexpr_scope;
7065 }8113 }
7066 IrInstruction *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope,8114 ScopeExpr *spill_scope = create_expr_scope(irb->codegen, node, payload_scope);
8115 IrInstSrc *err_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope,
7067 LValPtr, nullptr);8116 LValPtr, nullptr);
7068 if (err_val_ptr == irb->codegen->invalid_instruction)8117 if (err_val_ptr == irb->codegen->invalid_inst_src)
7069 return err_val_ptr;8118 return err_val_ptr;
7070 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node->data.while_expr.condition, err_val_ptr,8119 IrInstSrc *is_err = ir_build_test_err_src(irb, scope, node->data.while_expr.condition, err_val_ptr,
7071 true, false);8120 true, false);
7072 IrBasicBlock *after_cond_block = irb->current_basic_block;8121 IrBasicBlockSrc *after_cond_block = irb->current_basic_block;
7073 IrInstruction *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));8122 IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
7074 IrInstruction *cond_br_inst;8123 IrInstSrc *cond_br_inst;
7075 if (!instr_is_unreachable(is_err)) {8124 if (!instr_is_unreachable(is_err)) {
7076 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_err,8125 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_err,
7077 else_block, body_block, is_comptime);8126 else_block, body_block, is_comptime);
...@@ -7086,15 +8135,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7086,15 +8135,15 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
70868135
7087 ir_set_cursor_at_end_and_append_block(irb, body_block);8136 ir_set_cursor_at_end_and_append_block(irb, body_block);
7088 if (var_symbol) {8137 if (var_symbol) {
7089 IrInstruction *payload_ptr = ir_build_unwrap_err_payload(irb, payload_scope, symbol_node,8138 IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, &spill_scope->base, symbol_node,
7090 err_val_ptr, false, false);8139 err_val_ptr, false, false);
7091 IrInstruction *var_ptr = node->data.while_expr.var_is_ptr ?8140 IrInstSrc *var_ptr = node->data.while_expr.var_is_ptr ?
7092 ir_build_ref(irb, payload_scope, symbol_node, payload_ptr, true, false) : payload_ptr;8141 ir_build_ref_src(irb, &spill_scope->base, symbol_node, payload_ptr, true, false) : payload_ptr;
7093 ir_build_var_decl_src(irb, payload_scope, symbol_node, payload_var, nullptr, var_ptr);8142 ir_build_var_decl_src(irb, payload_scope, symbol_node, payload_var, nullptr, var_ptr);
7094 }8143 }
70958144
7096 ZigList<IrInstruction *> incoming_values = {0};8145 ZigList<IrInstSrc *> incoming_values = {0};
7097 ZigList<IrBasicBlock *> incoming_blocks = {0};8146 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
70988147
7099 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, payload_scope);8148 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, payload_scope);
7100 loop_scope->break_block = end_block;8149 loop_scope->break_block = end_block;
...@@ -7104,12 +8153,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7104,12 +8153,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7104 loop_scope->incoming_values = &incoming_values;8153 loop_scope->incoming_values = &incoming_values;
7105 loop_scope->lval = lval;8154 loop_scope->lval = lval;
7106 loop_scope->peer_parent = peer_parent;8155 loop_scope->peer_parent = peer_parent;
8156 loop_scope->spill_scope = spill_scope;
71078157
7108 // Note the body block of the loop is not the place that lval and result_loc are used -8158 // Note the body block of the loop is not the place that lval and result_loc are used -
7109 // it's actually in break statements, handled similarly to return statements.8159 // it's actually in break statements, handled similarly to return statements.
7110 // That is why we set those values in loop_scope above and not in this ir_gen_node call.8160 // That is why we set those values in loop_scope above and not in this ir_gen_node call.
7111 IrInstruction *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);8161 IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);
7112 if (body_result == irb->codegen->invalid_instruction)8162 if (body_result == irb->codegen->invalid_inst_src)
7113 return body_result;8163 return body_result;
71148164
7115 if (!instr_is_unreachable(body_result)) {8165 if (!instr_is_unreachable(body_result)) {
...@@ -7119,8 +8169,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7119,8 +8169,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
71198169
7120 if (continue_expr_node) {8170 if (continue_expr_node) {
7121 ir_set_cursor_at_end_and_append_block(irb, continue_block);8171 ir_set_cursor_at_end_and_append_block(irb, continue_block);
7122 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, payload_scope);8172 IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, payload_scope);
7123 if (expr_result == irb->codegen->invalid_instruction)8173 if (expr_result == irb->codegen->invalid_inst_src)
7124 return expr_result;8174 return expr_result;
7125 if (!instr_is_unreachable(expr_result)) {8175 if (!instr_is_unreachable(expr_result)) {
7126 ir_mark_gen(ir_build_check_statement_is_void(irb, payload_scope, continue_expr_node, expr_result));8176 ir_mark_gen(ir_build_check_statement_is_void(irb, payload_scope, continue_expr_node, expr_result));
...@@ -7136,7 +8186,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7136,7 +8186,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7136 ZigVar *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol,8186 ZigVar *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol,
7137 true, false, false, is_comptime);8187 true, false, false, is_comptime);
7138 Scope *err_scope = err_var->child_scope;8188 Scope *err_scope = err_var->child_scope;
7139 IrInstruction *err_ptr = ir_build_unwrap_err_code(irb, err_scope, err_symbol_node, err_val_ptr);8189 IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, err_scope, err_symbol_node, err_val_ptr);
7140 ir_build_var_decl_src(irb, err_scope, symbol_node, err_var, nullptr, err_ptr);8190 ir_build_var_decl_src(irb, err_scope, symbol_node, err_var, nullptr, err_ptr);
71418191
7142 if (peer_parent->peers.length != 0) {8192 if (peer_parent->peers.length != 0) {
...@@ -7144,12 +8194,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7144,12 +8194,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7144 }8194 }
7145 ResultLocPeer *peer_result = create_peer_result(peer_parent);8195 ResultLocPeer *peer_result = create_peer_result(peer_parent);
7146 peer_parent->peers.append(peer_result);8196 peer_parent->peers.append(peer_result);
7147 IrInstruction *else_result = ir_gen_node_extra(irb, else_node, err_scope, lval, &peer_result->base);8197 IrInstSrc *else_result = ir_gen_node_extra(irb, else_node, err_scope, lval, &peer_result->base);
7148 if (else_result == irb->codegen->invalid_instruction)8198 if (else_result == irb->codegen->invalid_inst_src)
7149 return else_result;8199 return else_result;
7150 if (!instr_is_unreachable(else_result))8200 if (!instr_is_unreachable(else_result))
7151 ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime));8201 ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime));
7152 IrBasicBlock *after_else_block = irb->current_basic_block;8202 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
7153 ir_set_cursor_at_end_and_append_block(irb, end_block);8203 ir_set_cursor_at_end_and_append_block(irb, end_block);
7154 if (else_result) {8204 if (else_result) {
7155 incoming_blocks.append(after_else_block);8205 incoming_blocks.append(after_else_block);
...@@ -7162,7 +8212,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7162,7 +8212,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7162 peer_parent->peers.last()->next_bb = end_block;8212 peer_parent->peers.last()->next_bb = end_block;
7163 }8213 }
71648214
7165 IrInstruction *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,8215 IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,
7166 incoming_blocks.items, incoming_values.items, peer_parent);8216 incoming_blocks.items, incoming_values.items, peer_parent);
7167 return ir_expr_wrap(irb, scope, phi, result_loc);8217 return ir_expr_wrap(irb, scope, phi, result_loc);
7168 } else if (var_symbol != nullptr) {8218 } else if (var_symbol != nullptr) {
...@@ -7174,15 +8224,16 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7174,15 +8224,16 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7174 ZigVar *payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol,8224 ZigVar *payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol,
7175 true, false, false, is_comptime);8225 true, false, false, is_comptime);
7176 Scope *child_scope = payload_var->child_scope;8226 Scope *child_scope = payload_var->child_scope;
7177 IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope,8227 ScopeExpr *spill_scope = create_expr_scope(irb->codegen, node, child_scope);
8228 IrInstSrc *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope,
7178 LValPtr, nullptr);8229 LValPtr, nullptr);
7179 if (maybe_val_ptr == irb->codegen->invalid_instruction)8230 if (maybe_val_ptr == irb->codegen->invalid_inst_src)
7180 return maybe_val_ptr;8231 return maybe_val_ptr;
7181 IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, maybe_val_ptr);8232 IrInstSrc *maybe_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, maybe_val_ptr);
7182 IrInstruction *is_non_null = ir_build_test_nonnull(irb, scope, node->data.while_expr.condition, maybe_val);8233 IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, scope, node->data.while_expr.condition, maybe_val);
7183 IrBasicBlock *after_cond_block = irb->current_basic_block;8234 IrBasicBlockSrc *after_cond_block = irb->current_basic_block;
7184 IrInstruction *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));8235 IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
7185 IrInstruction *cond_br_inst;8236 IrInstSrc *cond_br_inst;
7186 if (!instr_is_unreachable(is_non_null)) {8237 if (!instr_is_unreachable(is_non_null)) {
7187 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_non_null,8238 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, is_non_null,
7188 body_block, else_block, is_comptime);8239 body_block, else_block, is_comptime);
...@@ -7196,13 +8247,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7196,13 +8247,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7196 is_comptime);8247 is_comptime);
71978248
7198 ir_set_cursor_at_end_and_append_block(irb, body_block);8249 ir_set_cursor_at_end_and_append_block(irb, body_block);
7199 IrInstruction *payload_ptr = ir_build_optional_unwrap_ptr(irb, child_scope, symbol_node, maybe_val_ptr, false, false);8250 IrInstSrc *payload_ptr = ir_build_optional_unwrap_ptr(irb, &spill_scope->base, symbol_node, maybe_val_ptr, false, false);
7200 IrInstruction *var_ptr = node->data.while_expr.var_is_ptr ?8251 IrInstSrc *var_ptr = node->data.while_expr.var_is_ptr ?
7201 ir_build_ref(irb, child_scope, symbol_node, payload_ptr, true, false) : payload_ptr;8252 ir_build_ref_src(irb, &spill_scope->base, symbol_node, payload_ptr, true, false) : payload_ptr;
7202 ir_build_var_decl_src(irb, child_scope, symbol_node, payload_var, nullptr, var_ptr);8253 ir_build_var_decl_src(irb, child_scope, symbol_node, payload_var, nullptr, var_ptr);
72038254
7204 ZigList<IrInstruction *> incoming_values = {0};8255 ZigList<IrInstSrc *> incoming_values = {0};
7205 ZigList<IrBasicBlock *> incoming_blocks = {0};8256 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
72068257
7207 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope);8258 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope);
7208 loop_scope->break_block = end_block;8259 loop_scope->break_block = end_block;
...@@ -7212,12 +8263,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7212,12 +8263,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7212 loop_scope->incoming_values = &incoming_values;8263 loop_scope->incoming_values = &incoming_values;
7213 loop_scope->lval = lval;8264 loop_scope->lval = lval;
7214 loop_scope->peer_parent = peer_parent;8265 loop_scope->peer_parent = peer_parent;
8266 loop_scope->spill_scope = spill_scope;
72158267
7216 // Note the body block of the loop is not the place that lval and result_loc are used -8268 // Note the body block of the loop is not the place that lval and result_loc are used -
7217 // it's actually in break statements, handled similarly to return statements.8269 // it's actually in break statements, handled similarly to return statements.
7218 // That is why we set those values in loop_scope above and not in this ir_gen_node call.8270 // That is why we set those values in loop_scope above and not in this ir_gen_node call.
7219 IrInstruction *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);8271 IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);
7220 if (body_result == irb->codegen->invalid_instruction)8272 if (body_result == irb->codegen->invalid_inst_src)
7221 return body_result;8273 return body_result;
72228274
7223 if (!instr_is_unreachable(body_result)) {8275 if (!instr_is_unreachable(body_result)) {
...@@ -7227,8 +8279,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7227,8 +8279,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
72278279
7228 if (continue_expr_node) {8280 if (continue_expr_node) {
7229 ir_set_cursor_at_end_and_append_block(irb, continue_block);8281 ir_set_cursor_at_end_and_append_block(irb, continue_block);
7230 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, child_scope);8282 IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, child_scope);
7231 if (expr_result == irb->codegen->invalid_instruction)8283 if (expr_result == irb->codegen->invalid_inst_src)
7232 return expr_result;8284 return expr_result;
7233 if (!instr_is_unreachable(expr_result)) {8285 if (!instr_is_unreachable(expr_result)) {
7234 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, continue_expr_node, expr_result));8286 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, continue_expr_node, expr_result));
...@@ -7236,7 +8288,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7236,7 +8288,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7236 }8288 }
7237 }8289 }
72388290
7239 IrInstruction *else_result = nullptr;8291 IrInstSrc *else_result = nullptr;
7240 if (else_node) {8292 if (else_node) {
7241 ir_set_cursor_at_end_and_append_block(irb, else_block);8293 ir_set_cursor_at_end_and_append_block(irb, else_block);
72428294
...@@ -7246,12 +8298,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7246,12 +8298,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7246 ResultLocPeer *peer_result = create_peer_result(peer_parent);8298 ResultLocPeer *peer_result = create_peer_result(peer_parent);
7247 peer_parent->peers.append(peer_result);8299 peer_parent->peers.append(peer_result);
7248 else_result = ir_gen_node_extra(irb, else_node, scope, lval, &peer_result->base);8300 else_result = ir_gen_node_extra(irb, else_node, scope, lval, &peer_result->base);
7249 if (else_result == irb->codegen->invalid_instruction)8301 if (else_result == irb->codegen->invalid_inst_src)
7250 return else_result;8302 return else_result;
7251 if (!instr_is_unreachable(else_result))8303 if (!instr_is_unreachable(else_result))
7252 ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime));8304 ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime));
7253 }8305 }
7254 IrBasicBlock *after_else_block = irb->current_basic_block;8306 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
7255 ir_set_cursor_at_end_and_append_block(irb, end_block);8307 ir_set_cursor_at_end_and_append_block(irb, end_block);
7256 if (else_result) {8308 if (else_result) {
7257 incoming_blocks.append(after_else_block);8309 incoming_blocks.append(after_else_block);
...@@ -7264,17 +8316,17 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7264,17 +8316,17 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7264 peer_parent->peers.last()->next_bb = end_block;8316 peer_parent->peers.last()->next_bb = end_block;
7265 }8317 }
72668318
7267 IrInstruction *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,8319 IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,
7268 incoming_blocks.items, incoming_values.items, peer_parent);8320 incoming_blocks.items, incoming_values.items, peer_parent);
7269 return ir_expr_wrap(irb, scope, phi, result_loc);8321 return ir_expr_wrap(irb, scope, phi, result_loc);
7270 } else {8322 } else {
7271 ir_set_cursor_at_end_and_append_block(irb, cond_block);8323 ir_set_cursor_at_end_and_append_block(irb, cond_block);
7272 IrInstruction *cond_val = ir_gen_node(irb, node->data.while_expr.condition, scope);8324 IrInstSrc *cond_val = ir_gen_node(irb, node->data.while_expr.condition, scope);
7273 if (cond_val == irb->codegen->invalid_instruction)8325 if (cond_val == irb->codegen->invalid_inst_src)
7274 return cond_val;8326 return cond_val;
7275 IrBasicBlock *after_cond_block = irb->current_basic_block;8327 IrBasicBlockSrc *after_cond_block = irb->current_basic_block;
7276 IrInstruction *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));8328 IrInstSrc *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node));
7277 IrInstruction *cond_br_inst;8329 IrInstSrc *cond_br_inst;
7278 if (!instr_is_unreachable(cond_val)) {8330 if (!instr_is_unreachable(cond_val)) {
7279 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, cond_val,8331 cond_br_inst = ir_build_cond_br(irb, scope, node->data.while_expr.condition, cond_val,
7280 body_block, else_block, is_comptime);8332 body_block, else_block, is_comptime);
...@@ -7288,8 +8340,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7288,8 +8340,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7288 is_comptime);8340 is_comptime);
7289 ir_set_cursor_at_end_and_append_block(irb, body_block);8341 ir_set_cursor_at_end_and_append_block(irb, body_block);
72908342
7291 ZigList<IrInstruction *> incoming_values = {0};8343 ZigList<IrInstSrc *> incoming_values = {0};
7292 ZigList<IrBasicBlock *> incoming_blocks = {0};8344 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
72938345
7294 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);8346 Scope *subexpr_scope = create_runtime_scope(irb->codegen, node, scope, is_comptime);
72958347
...@@ -7305,8 +8357,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7305,8 +8357,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7305 // Note the body block of the loop is not the place that lval and result_loc are used -8357 // Note the body block of the loop is not the place that lval and result_loc are used -
7306 // it's actually in break statements, handled similarly to return statements.8358 // it's actually in break statements, handled similarly to return statements.
7307 // That is why we set those values in loop_scope above and not in this ir_gen_node call.8359 // That is why we set those values in loop_scope above and not in this ir_gen_node call.
7308 IrInstruction *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);8360 IrInstSrc *body_result = ir_gen_node(irb, node->data.while_expr.body, &loop_scope->base);
7309 if (body_result == irb->codegen->invalid_instruction)8361 if (body_result == irb->codegen->invalid_inst_src)
7310 return body_result;8362 return body_result;
73118363
7312 if (!instr_is_unreachable(body_result)) {8364 if (!instr_is_unreachable(body_result)) {
...@@ -7316,8 +8368,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7316,8 +8368,8 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
73168368
7317 if (continue_expr_node) {8369 if (continue_expr_node) {
7318 ir_set_cursor_at_end_and_append_block(irb, continue_block);8370 ir_set_cursor_at_end_and_append_block(irb, continue_block);
7319 IrInstruction *expr_result = ir_gen_node(irb, continue_expr_node, subexpr_scope);8371 IrInstSrc *expr_result = ir_gen_node(irb, continue_expr_node, subexpr_scope);
7320 if (expr_result == irb->codegen->invalid_instruction)8372 if (expr_result == irb->codegen->invalid_inst_src)
7321 return expr_result;8373 return expr_result;
7322 if (!instr_is_unreachable(expr_result)) {8374 if (!instr_is_unreachable(expr_result)) {
7323 ir_mark_gen(ir_build_check_statement_is_void(irb, scope, continue_expr_node, expr_result));8375 ir_mark_gen(ir_build_check_statement_is_void(irb, scope, continue_expr_node, expr_result));
...@@ -7325,7 +8377,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7325,7 +8377,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7325 }8377 }
7326 }8378 }
73278379
7328 IrInstruction *else_result = nullptr;8380 IrInstSrc *else_result = nullptr;
7329 if (else_node) {8381 if (else_node) {
7330 ir_set_cursor_at_end_and_append_block(irb, else_block);8382 ir_set_cursor_at_end_and_append_block(irb, else_block);
73318383
...@@ -7336,12 +8388,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7336,12 +8388,12 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7336 peer_parent->peers.append(peer_result);8388 peer_parent->peers.append(peer_result);
73378389
7338 else_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_result->base);8390 else_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_result->base);
7339 if (else_result == irb->codegen->invalid_instruction)8391 if (else_result == irb->codegen->invalid_inst_src)
7340 return else_result;8392 return else_result;
7341 if (!instr_is_unreachable(else_result))8393 if (!instr_is_unreachable(else_result))
7342 ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime));8394 ir_mark_gen(ir_build_br(irb, scope, node, end_block, is_comptime));
7343 }8395 }
7344 IrBasicBlock *after_else_block = irb->current_basic_block;8396 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
7345 ir_set_cursor_at_end_and_append_block(irb, end_block);8397 ir_set_cursor_at_end_and_append_block(irb, end_block);
7346 if (else_result) {8398 if (else_result) {
7347 incoming_blocks.append(after_else_block);8399 incoming_blocks.append(after_else_block);
...@@ -7354,13 +8406,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7354,13 +8406,13 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n
7354 peer_parent->peers.last()->next_bb = end_block;8406 peer_parent->peers.last()->next_bb = end_block;
7355 }8407 }
73568408
7357 IrInstruction *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,8409 IrInstSrc *phi = ir_build_phi(irb, scope, node, incoming_blocks.length,
7358 incoming_blocks.items, incoming_values.items, peer_parent);8410 incoming_blocks.items, incoming_values.items, peer_parent);
7359 return ir_expr_wrap(irb, scope, phi, result_loc);8411 return ir_expr_wrap(irb, scope, phi, result_loc);
7360 }8412 }
7361}8413}
73628414
7363static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval,8415static IrInstSrc *ir_gen_for_expr(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval,
7364 ResultLoc *result_loc)8416 ResultLoc *result_loc)
7365{8417{
7366 assert(node->type == NodeTypeForExpr);8418 assert(node->type == NodeTypeForExpr);
...@@ -7373,17 +8425,17 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -7373,17 +8425,17 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
73738425
7374 if (!elem_node) {8426 if (!elem_node) {
7375 add_node_error(irb->codegen, node, buf_sprintf("for loop expression missing element parameter"));8427 add_node_error(irb->codegen, node, buf_sprintf("for loop expression missing element parameter"));
7376 return irb->codegen->invalid_instruction;8428 return irb->codegen->invalid_inst_src;
7377 }8429 }
7378 assert(elem_node->type == NodeTypeSymbol);8430 assert(elem_node->type == NodeTypeSymbol);
73798431
7380 ScopeExpr *spill_scope = create_expr_scope(irb->codegen, node, parent_scope);8432 ScopeExpr *spill_scope = create_expr_scope(irb->codegen, node, parent_scope);
73818433
7382 IrInstruction *array_val_ptr = ir_gen_node_extra(irb, array_node, &spill_scope->base, LValPtr, nullptr);8434 IrInstSrc *array_val_ptr = ir_gen_node_extra(irb, array_node, &spill_scope->base, LValPtr, nullptr);
7383 if (array_val_ptr == irb->codegen->invalid_instruction)8435 if (array_val_ptr == irb->codegen->invalid_inst_src)
7384 return array_val_ptr;8436 return array_val_ptr;
73858437
7386 IrInstruction *is_comptime = ir_build_const_bool(irb, parent_scope, node,8438 IrInstSrc *is_comptime = ir_build_const_bool(irb, parent_scope, node,
7387 ir_should_inline(irb->exec, parent_scope) || node->data.for_expr.is_inline);8439 ir_should_inline(irb->exec, parent_scope) || node->data.for_expr.is_inline);
73888440
7389 AstNode *index_var_source_node;8441 AstNode *index_var_source_node;
...@@ -7400,50 +8452,49 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -7400,50 +8452,49 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
7400 index_var_name = "i";8452 index_var_name = "i";
7401 }8453 }
74028454
7403 IrInstruction *zero = ir_build_const_usize(irb, parent_scope, node, 0);8455 IrInstSrc *zero = ir_build_const_usize(irb, parent_scope, node, 0);
7404 build_decl_var_and_init(irb, parent_scope, index_var_source_node, index_var, zero, index_var_name, is_comptime);8456 build_decl_var_and_init(irb, parent_scope, index_var_source_node, index_var, zero, index_var_name, is_comptime);
7405 parent_scope = index_var->child_scope;8457 parent_scope = index_var->child_scope;
74068458
7407 IrInstruction *one = ir_build_const_usize(irb, parent_scope, node, 1);8459 IrInstSrc *one = ir_build_const_usize(irb, parent_scope, node, 1);
7408 IrInstruction *index_ptr = ir_build_var_ptr(irb, parent_scope, node, index_var);8460 IrInstSrc *index_ptr = ir_build_var_ptr(irb, parent_scope, node, index_var);
74098461
74108462
7411 IrBasicBlock *cond_block = ir_create_basic_block(irb, parent_scope, "ForCond");8463 IrBasicBlockSrc *cond_block = ir_create_basic_block(irb, parent_scope, "ForCond");
7412 IrBasicBlock *body_block = ir_create_basic_block(irb, parent_scope, "ForBody");8464 IrBasicBlockSrc *body_block = ir_create_basic_block(irb, parent_scope, "ForBody");
7413 IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "ForEnd");8465 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, parent_scope, "ForEnd");
7414 IrBasicBlock *else_block = else_node ? ir_create_basic_block(irb, parent_scope, "ForElse") : end_block;8466 IrBasicBlockSrc *else_block = else_node ? ir_create_basic_block(irb, parent_scope, "ForElse") : end_block;
7415 IrBasicBlock *continue_block = ir_create_basic_block(irb, parent_scope, "ForContinue");8467 IrBasicBlockSrc *continue_block = ir_create_basic_block(irb, parent_scope, "ForContinue");
74168468
7417 Buf *len_field_name = buf_create_from_str("len");8469 Buf *len_field_name = buf_create_from_str("len");
7418 IrInstruction *len_ref = ir_build_field_ptr(irb, parent_scope, node, array_val_ptr, len_field_name, false);8470 IrInstSrc *len_ref = ir_build_field_ptr(irb, parent_scope, node, array_val_ptr, len_field_name, false);
7419 IrInstruction *len_val = ir_build_load_ptr(irb, &spill_scope->base, node, len_ref);8471 IrInstSrc *len_val = ir_build_load_ptr(irb, &spill_scope->base, node, len_ref);
7420 ir_build_br(irb, parent_scope, node, cond_block, is_comptime);8472 ir_build_br(irb, parent_scope, node, cond_block, is_comptime);
74218473
7422 ir_set_cursor_at_end_and_append_block(irb, cond_block);8474 ir_set_cursor_at_end_and_append_block(irb, cond_block);
7423 IrInstruction *index_val = ir_build_load_ptr(irb, &spill_scope->base, node, index_ptr);8475 IrInstSrc *index_val = ir_build_load_ptr(irb, &spill_scope->base, node, index_ptr);
7424 IrInstruction *cond = ir_build_bin_op(irb, parent_scope, node, IrBinOpCmpLessThan, index_val, len_val, false);8476 IrInstSrc *cond = ir_build_bin_op(irb, parent_scope, node, IrBinOpCmpLessThan, index_val, len_val, false);
7425 IrBasicBlock *after_cond_block = irb->current_basic_block;8477 IrBasicBlockSrc *after_cond_block = irb->current_basic_block;
7426 IrInstruction *void_else_value = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, parent_scope, node));8478 IrInstSrc *void_else_value = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, parent_scope, node));
7427 IrInstruction *cond_br_inst = ir_mark_gen(ir_build_cond_br(irb, parent_scope, node, cond,8479 IrInstSrc *cond_br_inst = ir_mark_gen(ir_build_cond_br(irb, parent_scope, node, cond,
7428 body_block, else_block, is_comptime));8480 body_block, else_block, is_comptime));
74298481
7430 ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, result_loc, is_comptime);8482 ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, result_loc, is_comptime);
74318483
7432 ir_set_cursor_at_end_and_append_block(irb, body_block);8484 ir_set_cursor_at_end_and_append_block(irb, body_block);
7433 Scope *elem_ptr_scope = node->data.for_expr.elem_is_ptr ? parent_scope : &spill_scope->base;8485 IrInstSrc *elem_ptr = ir_build_elem_ptr(irb, &spill_scope->base, node, array_val_ptr, index_val,
7434 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, elem_ptr_scope, node, array_val_ptr, index_val, false,8486 false, PtrLenSingle, nullptr);
7435 PtrLenSingle, nullptr);
7436 // TODO make it an error to write to element variable or i variable.8487 // TODO make it an error to write to element variable or i variable.
7437 Buf *elem_var_name = elem_node->data.symbol_expr.symbol;8488 Buf *elem_var_name = elem_node->data.symbol_expr.symbol;
7438 ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime);8489 ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime);
7439 Scope *child_scope = elem_var->child_scope;8490 Scope *child_scope = elem_var->child_scope;
74408491
7441 IrInstruction *var_ptr = node->data.for_expr.elem_is_ptr ?8492 IrInstSrc *var_ptr = node->data.for_expr.elem_is_ptr ?
7442 ir_build_ref(irb, &spill_scope->base, elem_node, elem_ptr, true, false) : elem_ptr;8493 ir_build_ref_src(irb, &spill_scope->base, elem_node, elem_ptr, true, false) : elem_ptr;
7443 ir_build_var_decl_src(irb, parent_scope, elem_node, elem_var, nullptr, var_ptr);8494 ir_build_var_decl_src(irb, parent_scope, elem_node, elem_var, nullptr, var_ptr);
74448495
7445 ZigList<IrInstruction *> incoming_values = {0};8496 ZigList<IrInstSrc *> incoming_values = {0};
7446 ZigList<IrBasicBlock *> incoming_blocks = {0};8497 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
7447 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope);8498 ScopeLoop *loop_scope = create_loop_scope(irb->codegen, node, child_scope);
7448 loop_scope->break_block = end_block;8499 loop_scope->break_block = end_block;
7449 loop_scope->continue_block = continue_block;8500 loop_scope->continue_block = continue_block;
...@@ -7457,9 +8508,9 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -7457,9 +8508,9 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
7457 // Note the body block of the loop is not the place that lval and result_loc are used -8508 // Note the body block of the loop is not the place that lval and result_loc are used -
7458 // it's actually in break statements, handled similarly to return statements.8509 // it's actually in break statements, handled similarly to return statements.
7459 // That is why we set those values in loop_scope above and not in this ir_gen_node call.8510 // That is why we set those values in loop_scope above and not in this ir_gen_node call.
7460 IrInstruction *body_result = ir_gen_node(irb, body_node, &loop_scope->base);8511 IrInstSrc *body_result = ir_gen_node(irb, body_node, &loop_scope->base);
7461 if (body_result == irb->codegen->invalid_instruction)8512 if (body_result == irb->codegen->invalid_inst_src)
7462 return irb->codegen->invalid_instruction;8513 return irb->codegen->invalid_inst_src;
74638514
7464 if (!instr_is_unreachable(body_result)) {8515 if (!instr_is_unreachable(body_result)) {
7465 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.for_expr.body, body_result));8516 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.for_expr.body, body_result));
...@@ -7467,11 +8518,11 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -7467,11 +8518,11 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
7467 }8518 }
74688519
7469 ir_set_cursor_at_end_and_append_block(irb, continue_block);8520 ir_set_cursor_at_end_and_append_block(irb, continue_block);
7470 IrInstruction *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false);8521 IrInstSrc *new_index_val = ir_build_bin_op(irb, child_scope, node, IrBinOpAdd, index_val, one, false);
7471 ir_build_store_ptr(irb, child_scope, node, index_ptr, new_index_val)->allow_write_through_const = true;8522 ir_build_store_ptr(irb, child_scope, node, index_ptr, new_index_val)->allow_write_through_const = true;
7472 ir_build_br(irb, child_scope, node, cond_block, is_comptime);8523 ir_build_br(irb, child_scope, node, cond_block, is_comptime);
74738524
7474 IrInstruction *else_result = nullptr;8525 IrInstSrc *else_result = nullptr;
7475 if (else_node) {8526 if (else_node) {
7476 ir_set_cursor_at_end_and_append_block(irb, else_block);8527 ir_set_cursor_at_end_and_append_block(irb, else_block);
74778528
...@@ -7481,12 +8532,12 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -7481,12 +8532,12 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
7481 ResultLocPeer *peer_result = create_peer_result(peer_parent);8532 ResultLocPeer *peer_result = create_peer_result(peer_parent);
7482 peer_parent->peers.append(peer_result);8533 peer_parent->peers.append(peer_result);
7483 else_result = ir_gen_node_extra(irb, else_node, parent_scope, LValNone, &peer_result->base);8534 else_result = ir_gen_node_extra(irb, else_node, parent_scope, LValNone, &peer_result->base);
7484 if (else_result == irb->codegen->invalid_instruction)8535 if (else_result == irb->codegen->invalid_inst_src)
7485 return else_result;8536 return else_result;
7486 if (!instr_is_unreachable(else_result))8537 if (!instr_is_unreachable(else_result))
7487 ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime));8538 ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime));
7488 }8539 }
7489 IrBasicBlock *after_else_block = irb->current_basic_block;8540 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
7490 ir_set_cursor_at_end_and_append_block(irb, end_block);8541 ir_set_cursor_at_end_and_append_block(irb, end_block);
74918542
7492 if (else_result) {8543 if (else_result) {
...@@ -7500,29 +8551,29 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -7500,29 +8551,29 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
7500 peer_parent->peers.last()->next_bb = end_block;8551 peer_parent->peers.last()->next_bb = end_block;
7501 }8552 }
75028553
7503 IrInstruction *phi = ir_build_phi(irb, parent_scope, node, incoming_blocks.length,8554 IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, incoming_blocks.length,
7504 incoming_blocks.items, incoming_values.items, peer_parent);8555 incoming_blocks.items, incoming_values.items, peer_parent);
7505 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);8556 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);
7506}8557}
75078558
7508static IrInstruction *ir_gen_bool_literal(IrBuilder *irb, Scope *scope, AstNode *node) {8559static IrInstSrc *ir_gen_bool_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
7509 assert(node->type == NodeTypeBoolLiteral);8560 assert(node->type == NodeTypeBoolLiteral);
7510 return ir_build_const_bool(irb, scope, node, node->data.bool_literal.value);8561 return ir_build_const_bool(irb, scope, node, node->data.bool_literal.value);
7511}8562}
75128563
7513static IrInstruction *ir_gen_enum_literal(IrBuilder *irb, Scope *scope, AstNode *node) {8564static IrInstSrc *ir_gen_enum_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
7514 assert(node->type == NodeTypeEnumLiteral);8565 assert(node->type == NodeTypeEnumLiteral);
7515 Buf *name = &node->data.enum_literal.identifier->data.str_lit.str;8566 Buf *name = &node->data.enum_literal.identifier->data.str_lit.str;
7516 return ir_build_const_enum_literal(irb, scope, node, name);8567 return ir_build_const_enum_literal(irb, scope, node, name);
7517}8568}
75188569
7519static IrInstruction *ir_gen_string_literal(IrBuilder *irb, Scope *scope, AstNode *node) {8570static IrInstSrc *ir_gen_string_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
7520 assert(node->type == NodeTypeStringLiteral);8571 assert(node->type == NodeTypeStringLiteral);
75218572
7522 return ir_build_const_str_lit(irb, scope, node, node->data.string_literal.buf);8573 return ir_build_const_str_lit(irb, scope, node, node->data.string_literal.buf);
7523}8574}
75248575
7525static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *node) {8576static IrInstSrc *ir_gen_array_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
7526 assert(node->type == NodeTypeArrayType);8577 assert(node->type == NodeTypeArrayType);
75278578
7528 AstNode *size_node = node->data.array_type.size;8579 AstNode *size_node = node->data.array_type.size;
...@@ -7535,10 +8586,10 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7535,10 +8586,10 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n
75358586
7536 Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope);8587 Scope *comptime_scope = create_comptime_scope(irb->codegen, node, scope);
75378588
7538 IrInstruction *sentinel;8589 IrInstSrc *sentinel;
7539 if (sentinel_expr != nullptr) {8590 if (sentinel_expr != nullptr) {
7540 sentinel = ir_gen_node(irb, sentinel_expr, comptime_scope);8591 sentinel = ir_gen_node(irb, sentinel_expr, comptime_scope);
7541 if (sentinel == irb->codegen->invalid_instruction)8592 if (sentinel == irb->codegen->invalid_inst_src)
7542 return sentinel;8593 return sentinel;
7543 } else {8594 } else {
7544 sentinel = nullptr;8595 sentinel = nullptr;
...@@ -7547,42 +8598,42 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7547,42 +8598,42 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n
7547 if (size_node) {8598 if (size_node) {
7548 if (is_const) {8599 if (is_const) {
7549 add_node_error(irb->codegen, node, buf_create_from_str("const qualifier invalid on array type"));8600 add_node_error(irb->codegen, node, buf_create_from_str("const qualifier invalid on array type"));
7550 return irb->codegen->invalid_instruction;8601 return irb->codegen->invalid_inst_src;
7551 }8602 }
7552 if (is_volatile) {8603 if (is_volatile) {
7553 add_node_error(irb->codegen, node, buf_create_from_str("volatile qualifier invalid on array type"));8604 add_node_error(irb->codegen, node, buf_create_from_str("volatile qualifier invalid on array type"));
7554 return irb->codegen->invalid_instruction;8605 return irb->codegen->invalid_inst_src;
7555 }8606 }
7556 if (is_allow_zero) {8607 if (is_allow_zero) {
7557 add_node_error(irb->codegen, node, buf_create_from_str("allowzero qualifier invalid on array type"));8608 add_node_error(irb->codegen, node, buf_create_from_str("allowzero qualifier invalid on array type"));
7558 return irb->codegen->invalid_instruction;8609 return irb->codegen->invalid_inst_src;
7559 }8610 }
7560 if (align_expr != nullptr) {8611 if (align_expr != nullptr) {
7561 add_node_error(irb->codegen, node, buf_create_from_str("align qualifier invalid on array type"));8612 add_node_error(irb->codegen, node, buf_create_from_str("align qualifier invalid on array type"));
7562 return irb->codegen->invalid_instruction;8613 return irb->codegen->invalid_inst_src;
7563 }8614 }
75648615
7565 IrInstruction *size_value = ir_gen_node(irb, size_node, comptime_scope);8616 IrInstSrc *size_value = ir_gen_node(irb, size_node, comptime_scope);
7566 if (size_value == irb->codegen->invalid_instruction)8617 if (size_value == irb->codegen->invalid_inst_src)
7567 return size_value;8618 return size_value;
75688619
7569 IrInstruction *child_type = ir_gen_node(irb, child_type_node, comptime_scope);8620 IrInstSrc *child_type = ir_gen_node(irb, child_type_node, comptime_scope);
7570 if (child_type == irb->codegen->invalid_instruction)8621 if (child_type == irb->codegen->invalid_inst_src)
7571 return child_type;8622 return child_type;
75728623
7573 return ir_build_array_type(irb, scope, node, size_value, sentinel, child_type);8624 return ir_build_array_type(irb, scope, node, size_value, sentinel, child_type);
7574 } else {8625 } else {
7575 IrInstruction *align_value;8626 IrInstSrc *align_value;
7576 if (align_expr != nullptr) {8627 if (align_expr != nullptr) {
7577 align_value = ir_gen_node(irb, align_expr, comptime_scope);8628 align_value = ir_gen_node(irb, align_expr, comptime_scope);
7578 if (align_value == irb->codegen->invalid_instruction)8629 if (align_value == irb->codegen->invalid_inst_src)
7579 return align_value;8630 return align_value;
7580 } else {8631 } else {
7581 align_value = nullptr;8632 align_value = nullptr;
7582 }8633 }
75838634
7584 IrInstruction *child_type = ir_gen_node(irb, child_type_node, comptime_scope);8635 IrInstSrc *child_type = ir_gen_node(irb, child_type_node, comptime_scope);
7585 if (child_type == irb->codegen->invalid_instruction)8636 if (child_type == irb->codegen->invalid_inst_src)
7586 return child_type;8637 return child_type;
75878638
7588 return ir_build_slice_type(irb, scope, node, child_type, is_const, is_volatile, sentinel,8639 return ir_build_slice_type(irb, scope, node, child_type, is_const, is_volatile, sentinel,
...@@ -7590,15 +8641,15 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n...@@ -7590,15 +8641,15 @@ static IrInstruction *ir_gen_array_type(IrBuilder *irb, Scope *scope, AstNode *n
7590 }8641 }
7591}8642}
75928643
7593static IrInstruction *ir_gen_anyframe_type(IrBuilder *irb, Scope *scope, AstNode *node) {8644static IrInstSrc *ir_gen_anyframe_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
7594 assert(node->type == NodeTypeAnyFrameType);8645 assert(node->type == NodeTypeAnyFrameType);
75958646
7596 AstNode *payload_type_node = node->data.anyframe_type.payload_type;8647 AstNode *payload_type_node = node->data.anyframe_type.payload_type;
7597 IrInstruction *payload_type_value = nullptr;8648 IrInstSrc *payload_type_value = nullptr;
75988649
7599 if (payload_type_node != nullptr) {8650 if (payload_type_node != nullptr) {
7600 payload_type_value = ir_gen_node(irb, payload_type_node, scope);8651 payload_type_value = ir_gen_node(irb, payload_type_node, scope);
7601 if (payload_type_value == irb->codegen->invalid_instruction)8652 if (payload_type_value == irb->codegen->invalid_inst_src)
7602 return payload_type_value;8653 return payload_type_value;
76038654
7604 }8655 }
...@@ -7606,7 +8657,7 @@ static IrInstruction *ir_gen_anyframe_type(IrBuilder *irb, Scope *scope, AstNode...@@ -7606,7 +8657,7 @@ static IrInstruction *ir_gen_anyframe_type(IrBuilder *irb, Scope *scope, AstNode
7606 return ir_build_anyframe_type(irb, scope, node, payload_type_value);8657 return ir_build_anyframe_type(irb, scope, node, payload_type_value);
7607}8658}
76088659
7609static IrInstruction *ir_gen_undefined_literal(IrBuilder *irb, Scope *scope, AstNode *node) {8660static IrInstSrc *ir_gen_undefined_literal(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
7610 assert(node->type == NodeTypeUndefinedLiteral);8661 assert(node->type == NodeTypeUndefinedLiteral);
7611 return ir_build_const_undefined(irb, scope, node);8662 return ir_build_const_undefined(irb, scope, node);
7612}8663}
...@@ -7723,13 +8774,13 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_...@@ -7723,13 +8774,13 @@ static size_t find_asm_index(CodeGen *g, AstNode *node, AsmToken *tok, Buf *src_
7723 return SIZE_MAX;8774 return SIZE_MAX;
7724}8775}
77258776
7726static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *node) {8777static IrInstSrc *ir_gen_asm_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
7727 assert(node->type == NodeTypeAsmExpr);8778 assert(node->type == NodeTypeAsmExpr);
7728 AstNodeAsmExpr *asm_expr = &node->data.asm_expr;8779 AstNodeAsmExpr *asm_expr = &node->data.asm_expr;
77298780
7730 IrInstruction *asm_template = ir_gen_node(irb, asm_expr->asm_template, scope);8781 IrInstSrc *asm_template = ir_gen_node(irb, asm_expr->asm_template, scope);
7731 if (asm_template == irb->codegen->invalid_instruction)8782 if (asm_template == irb->codegen->invalid_inst_src)
7732 return irb->codegen->invalid_instruction;8783 return irb->codegen->invalid_inst_src;
77338784
7734 bool is_volatile = asm_expr->volatile_token != nullptr;8785 bool is_volatile = asm_expr->volatile_token != nullptr;
7735 bool in_fn_scope = (scope_fn_entry(scope) != nullptr);8786 bool in_fn_scope = (scope_fn_entry(scope) != nullptr);
...@@ -7738,7 +8789,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -7738,7 +8789,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
7738 if (is_volatile) {8789 if (is_volatile) {
7739 add_token_error(irb->codegen, node->owner, asm_expr->volatile_token,8790 add_token_error(irb->codegen, node->owner, asm_expr->volatile_token,
7740 buf_sprintf("volatile is meaningless on global assembly"));8791 buf_sprintf("volatile is meaningless on global assembly"));
7741 return irb->codegen->invalid_instruction;8792 return irb->codegen->invalid_inst_src;
7742 }8793 }
77438794
7744 if (asm_expr->output_list.length != 0 || asm_expr->input_list.length != 0 ||8795 if (asm_expr->output_list.length != 0 || asm_expr->input_list.length != 0 ||
...@@ -7746,34 +8797,34 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -7746,34 +8797,34 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
7746 {8797 {
7747 add_node_error(irb->codegen, node,8798 add_node_error(irb->codegen, node,
7748 buf_sprintf("global assembly cannot have inputs, outputs, or clobbers"));8799 buf_sprintf("global assembly cannot have inputs, outputs, or clobbers"));
7749 return irb->codegen->invalid_instruction;8800 return irb->codegen->invalid_inst_src;
7750 }8801 }
77518802
7752 return ir_build_asm_src(irb, scope, node, asm_template, nullptr, nullptr,8803 return ir_build_asm_src(irb, scope, node, asm_template, nullptr, nullptr,
7753 nullptr, 0, is_volatile, true);8804 nullptr, 0, is_volatile, true);
7754 }8805 }
77558806
7756 IrInstruction **input_list = allocate<IrInstruction *>(asm_expr->input_list.length);8807 IrInstSrc **input_list = allocate<IrInstSrc *>(asm_expr->input_list.length);
7757 IrInstruction **output_types = allocate<IrInstruction *>(asm_expr->output_list.length);8808 IrInstSrc **output_types = allocate<IrInstSrc *>(asm_expr->output_list.length);
7758 ZigVar **output_vars = allocate<ZigVar *>(asm_expr->output_list.length);8809 ZigVar **output_vars = allocate<ZigVar *>(asm_expr->output_list.length);
7759 size_t return_count = 0;8810 size_t return_count = 0;
7760 if (!is_volatile && asm_expr->output_list.length == 0) {8811 if (!is_volatile && asm_expr->output_list.length == 0) {
7761 add_node_error(irb->codegen, node,8812 add_node_error(irb->codegen, node,
7762 buf_sprintf("assembly expression with no output must be marked volatile"));8813 buf_sprintf("assembly expression with no output must be marked volatile"));
7763 return irb->codegen->invalid_instruction;8814 return irb->codegen->invalid_inst_src;
7764 }8815 }
7765 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {8816 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {
7766 AsmOutput *asm_output = asm_expr->output_list.at(i);8817 AsmOutput *asm_output = asm_expr->output_list.at(i);
7767 if (asm_output->return_type) {8818 if (asm_output->return_type) {
7768 return_count += 1;8819 return_count += 1;
77698820
7770 IrInstruction *return_type = ir_gen_node(irb, asm_output->return_type, scope);8821 IrInstSrc *return_type = ir_gen_node(irb, asm_output->return_type, scope);
7771 if (return_type == irb->codegen->invalid_instruction)8822 if (return_type == irb->codegen->invalid_inst_src)
7772 return irb->codegen->invalid_instruction;8823 return irb->codegen->invalid_inst_src;
7773 if (return_count > 1) {8824 if (return_count > 1) {
7774 add_node_error(irb->codegen, node,8825 add_node_error(irb->codegen, node,
7775 buf_sprintf("inline assembly allows up to one output value"));8826 buf_sprintf("inline assembly allows up to one output value"));
7776 return irb->codegen->invalid_instruction;8827 return irb->codegen->invalid_inst_src;
7777 }8828 }
7778 output_types[i] = return_type;8829 output_types[i] = return_type;
7779 } else {8830 } else {
...@@ -7786,7 +8837,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -7786,7 +8837,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
7786 } else {8837 } else {
7787 add_node_error(irb->codegen, node,8838 add_node_error(irb->codegen, node,
7788 buf_sprintf("use of undeclared identifier '%s'", buf_ptr(variable_name)));8839 buf_sprintf("use of undeclared identifier '%s'", buf_ptr(variable_name)));
7789 return irb->codegen->invalid_instruction;8840 return irb->codegen->invalid_inst_src;
7790 }8841 }
7791 }8842 }
77928843
...@@ -7796,14 +8847,14 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -7796,14 +8847,14 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
7796 buf_sprintf("invalid modifier starting output constraint for '%s': '%c', only '=' is supported."8847 buf_sprintf("invalid modifier starting output constraint for '%s': '%c', only '=' is supported."
7797 " Compiler TODO: see https://github.com/ziglang/zig/issues/215",8848 " Compiler TODO: see https://github.com/ziglang/zig/issues/215",
7798 buf_ptr(asm_output->asm_symbolic_name), modifier));8849 buf_ptr(asm_output->asm_symbolic_name), modifier));
7799 return irb->codegen->invalid_instruction;8850 return irb->codegen->invalid_inst_src;
7800 }8851 }
7801 }8852 }
7802 for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {8853 for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {
7803 AsmInput *asm_input = asm_expr->input_list.at(i);8854 AsmInput *asm_input = asm_expr->input_list.at(i);
7804 IrInstruction *input_value = ir_gen_node(irb, asm_input->expr, scope);8855 IrInstSrc *input_value = ir_gen_node(irb, asm_input->expr, scope);
7805 if (input_value == irb->codegen->invalid_instruction)8856 if (input_value == irb->codegen->invalid_inst_src)
7806 return irb->codegen->invalid_instruction;8857 return irb->codegen->invalid_inst_src;
78078858
7808 input_list[i] = input_value;8859 input_list[i] = input_value;
7809 }8860 }
...@@ -7812,7 +8863,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -7812,7 +8863,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod
7812 output_vars, return_count, is_volatile, false);8863 output_vars, return_count, is_volatile, false);
7813}8864}
78148865
7815static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,8866static IrInstSrc *ir_gen_if_optional_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
7816 ResultLoc *result_loc)8867 ResultLoc *result_loc)
7817{8868{
7818 assert(node->type == NodeTypeIfOptional);8869 assert(node->type == NodeTypeIfOptional);
...@@ -7823,24 +8874,24 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN...@@ -7823,24 +8874,24 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN
7823 AstNode *else_node = node->data.test_expr.else_node;8874 AstNode *else_node = node->data.test_expr.else_node;
7824 bool var_is_ptr = node->data.test_expr.var_is_ptr;8875 bool var_is_ptr = node->data.test_expr.var_is_ptr;
78258876
7826 IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);8877 IrInstSrc *maybe_val_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
7827 if (maybe_val_ptr == irb->codegen->invalid_instruction)8878 if (maybe_val_ptr == irb->codegen->invalid_inst_src)
7828 return maybe_val_ptr;8879 return maybe_val_ptr;
78298880
7830 IrInstruction *maybe_val = ir_build_load_ptr(irb, scope, node, maybe_val_ptr);8881 IrInstSrc *maybe_val = ir_build_load_ptr(irb, scope, node, maybe_val_ptr);
7831 IrInstruction *is_non_null = ir_build_test_nonnull(irb, scope, node, maybe_val);8882 IrInstSrc *is_non_null = ir_build_test_non_null_src(irb, scope, node, maybe_val);
78328883
7833 IrBasicBlock *then_block = ir_create_basic_block(irb, scope, "OptionalThen");8884 IrBasicBlockSrc *then_block = ir_create_basic_block(irb, scope, "OptionalThen");
7834 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "OptionalElse");8885 IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "OptionalElse");
7835 IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "OptionalEndIf");8886 IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "OptionalEndIf");
78368887
7837 IrInstruction *is_comptime;8888 IrInstSrc *is_comptime;
7838 if (ir_should_inline(irb->exec, scope)) {8889 if (ir_should_inline(irb->exec, scope)) {
7839 is_comptime = ir_build_const_bool(irb, scope, node, true);8890 is_comptime = ir_build_const_bool(irb, scope, node, true);
7840 } else {8891 } else {
7841 is_comptime = ir_build_test_comptime(irb, scope, node, is_non_null);8892 is_comptime = ir_build_test_comptime(irb, scope, node, is_non_null);
7842 }8893 }
7843 IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, is_non_null,8894 IrInstSrc *cond_br_inst = ir_build_cond_br(irb, scope, node, is_non_null,
7844 then_block, else_block, is_comptime);8895 then_block, else_block, is_comptime);
78458896
7846 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,8897 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,
...@@ -7856,48 +8907,48 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN...@@ -7856,48 +8907,48 @@ static IrInstruction *ir_gen_if_optional_expr(IrBuilder *irb, Scope *scope, AstN
7856 ZigVar *var = ir_create_var(irb, node, subexpr_scope,8907 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
7857 var_symbol, is_const, is_const, is_shadowable, is_comptime);8908 var_symbol, is_const, is_const, is_shadowable, is_comptime);
78588909
7859 IrInstruction *payload_ptr = ir_build_optional_unwrap_ptr(irb, subexpr_scope, node, maybe_val_ptr, false, false);8910 IrInstSrc *payload_ptr = ir_build_optional_unwrap_ptr(irb, subexpr_scope, node, maybe_val_ptr, false, false);
7860 IrInstruction *var_ptr = var_is_ptr ? ir_build_ref(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr;8911 IrInstSrc *var_ptr = var_is_ptr ? ir_build_ref_src(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr;
7861 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_ptr);8912 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_ptr);
7862 var_scope = var->child_scope;8913 var_scope = var->child_scope;
7863 } else {8914 } else {
7864 var_scope = subexpr_scope;8915 var_scope = subexpr_scope;
7865 }8916 }
7866 IrInstruction *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval,8917 IrInstSrc *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval,
7867 &peer_parent->peers.at(0)->base);8918 &peer_parent->peers.at(0)->base);
7868 if (then_expr_result == irb->codegen->invalid_instruction)8919 if (then_expr_result == irb->codegen->invalid_inst_src)
7869 return then_expr_result;8920 return then_expr_result;
7870 IrBasicBlock *after_then_block = irb->current_basic_block;8921 IrBasicBlockSrc *after_then_block = irb->current_basic_block;
7871 if (!instr_is_unreachable(then_expr_result))8922 if (!instr_is_unreachable(then_expr_result))
7872 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));8923 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
78738924
7874 ir_set_cursor_at_end_and_append_block(irb, else_block);8925 ir_set_cursor_at_end_and_append_block(irb, else_block);
7875 IrInstruction *else_expr_result;8926 IrInstSrc *else_expr_result;
7876 if (else_node) {8927 if (else_node) {
7877 else_expr_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base);8928 else_expr_result = ir_gen_node_extra(irb, else_node, subexpr_scope, lval, &peer_parent->peers.at(1)->base);
7878 if (else_expr_result == irb->codegen->invalid_instruction)8929 if (else_expr_result == irb->codegen->invalid_inst_src)
7879 return else_expr_result;8930 return else_expr_result;
7880 } else {8931 } else {
7881 else_expr_result = ir_build_const_void(irb, scope, node);8932 else_expr_result = ir_build_const_void(irb, scope, node);
7882 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);8933 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);
7883 }8934 }
7884 IrBasicBlock *after_else_block = irb->current_basic_block;8935 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
7885 if (!instr_is_unreachable(else_expr_result))8936 if (!instr_is_unreachable(else_expr_result))
7886 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));8937 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
78878938
7888 ir_set_cursor_at_end_and_append_block(irb, endif_block);8939 ir_set_cursor_at_end_and_append_block(irb, endif_block);
7889 IrInstruction **incoming_values = allocate<IrInstruction *>(2);8940 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
7890 incoming_values[0] = then_expr_result;8941 incoming_values[0] = then_expr_result;
7891 incoming_values[1] = else_expr_result;8942 incoming_values[1] = else_expr_result;
7892 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");8943 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
7893 incoming_blocks[0] = after_then_block;8944 incoming_blocks[0] = after_then_block;
7894 incoming_blocks[1] = after_else_block;8945 incoming_blocks[1] = after_else_block;
78958946
7896 IrInstruction *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);8947 IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
7897 return ir_expr_wrap(irb, scope, phi, result_loc);8948 return ir_expr_wrap(irb, scope, phi, result_loc);
7898}8949}
78998950
7900static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,8951static IrInstSrc *ir_gen_if_err_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
7901 ResultLoc *result_loc)8952 ResultLoc *result_loc)
7902{8953{
7903 assert(node->type == NodeTypeIfErrorExpr);8954 assert(node->type == NodeTypeIfErrorExpr);
...@@ -7910,20 +8961,20 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -7910,20 +8961,20 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
7910 Buf *var_symbol = node->data.if_err_expr.var_symbol;8961 Buf *var_symbol = node->data.if_err_expr.var_symbol;
7911 Buf *err_symbol = node->data.if_err_expr.err_symbol;8962 Buf *err_symbol = node->data.if_err_expr.err_symbol;
79128963
7913 IrInstruction *err_val_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr);8964 IrInstSrc *err_val_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr);
7914 if (err_val_ptr == irb->codegen->invalid_instruction)8965 if (err_val_ptr == irb->codegen->invalid_inst_src)
7915 return err_val_ptr;8966 return err_val_ptr;
79168967
7917 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);8968 IrInstSrc *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);
7918 IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, err_val_ptr, true, false);8969 IrInstSrc *is_err = ir_build_test_err_src(irb, scope, node, err_val_ptr, true, false);
79198970
7920 IrBasicBlock *ok_block = ir_create_basic_block(irb, scope, "TryOk");8971 IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, scope, "TryOk");
7921 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "TryElse");8972 IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "TryElse");
7922 IrBasicBlock *endif_block = ir_create_basic_block(irb, scope, "TryEnd");8973 IrBasicBlockSrc *endif_block = ir_create_basic_block(irb, scope, "TryEnd");
79238974
7924 bool force_comptime = ir_should_inline(irb->exec, scope);8975 bool force_comptime = ir_should_inline(irb->exec, scope);
7925 IrInstruction *is_comptime = force_comptime ? ir_build_const_bool(irb, scope, node, true) : ir_build_test_comptime(irb, scope, node, is_err);8976 IrInstSrc *is_comptime = force_comptime ? ir_build_const_bool(irb, scope, node, true) : ir_build_test_comptime(irb, scope, node, is_err);
7926 IrInstruction *cond_br_inst = ir_build_cond_br(irb, scope, node, is_err, else_block, ok_block, is_comptime);8977 IrInstSrc *cond_br_inst = ir_build_cond_br(irb, scope, node, is_err, else_block, ok_block, is_comptime);
79278978
7928 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,8979 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, else_block, endif_block,
7929 result_loc, is_comptime);8980 result_loc, is_comptime);
...@@ -7934,29 +8985,29 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -7934,29 +8985,29 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
7934 Scope *var_scope;8985 Scope *var_scope;
7935 if (var_symbol) {8986 if (var_symbol) {
7936 bool is_shadowable = false;8987 bool is_shadowable = false;
7937 IrInstruction *var_is_comptime = force_comptime ? ir_build_const_bool(irb, subexpr_scope, node, true) : ir_build_test_comptime(irb, subexpr_scope, node, err_val);8988 IrInstSrc *var_is_comptime = force_comptime ? ir_build_const_bool(irb, subexpr_scope, node, true) : ir_build_test_comptime(irb, subexpr_scope, node, err_val);
7938 ZigVar *var = ir_create_var(irb, node, subexpr_scope,8989 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
7939 var_symbol, var_is_const, var_is_const, is_shadowable, var_is_comptime);8990 var_symbol, var_is_const, var_is_const, is_shadowable, var_is_comptime);
79408991
7941 IrInstruction *payload_ptr = ir_build_unwrap_err_payload(irb, subexpr_scope, node, err_val_ptr, false, false);8992 IrInstSrc *payload_ptr = ir_build_unwrap_err_payload_src(irb, subexpr_scope, node, err_val_ptr, false, false);
7942 IrInstruction *var_ptr = var_is_ptr ?8993 IrInstSrc *var_ptr = var_is_ptr ?
7943 ir_build_ref(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr;8994 ir_build_ref_src(irb, subexpr_scope, node, payload_ptr, true, false) : payload_ptr;
7944 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_ptr);8995 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, var_ptr);
7945 var_scope = var->child_scope;8996 var_scope = var->child_scope;
7946 } else {8997 } else {
7947 var_scope = subexpr_scope;8998 var_scope = subexpr_scope;
7948 }8999 }
7949 IrInstruction *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval,9000 IrInstSrc *then_expr_result = ir_gen_node_extra(irb, then_node, var_scope, lval,
7950 &peer_parent->peers.at(0)->base);9001 &peer_parent->peers.at(0)->base);
7951 if (then_expr_result == irb->codegen->invalid_instruction)9002 if (then_expr_result == irb->codegen->invalid_inst_src)
7952 return then_expr_result;9003 return then_expr_result;
7953 IrBasicBlock *after_then_block = irb->current_basic_block;9004 IrBasicBlockSrc *after_then_block = irb->current_basic_block;
7954 if (!instr_is_unreachable(then_expr_result))9005 if (!instr_is_unreachable(then_expr_result))
7955 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));9006 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
79569007
7957 ir_set_cursor_at_end_and_append_block(irb, else_block);9008 ir_set_cursor_at_end_and_append_block(irb, else_block);
79589009
7959 IrInstruction *else_expr_result;9010 IrInstSrc *else_expr_result;
7960 if (else_node) {9011 if (else_node) {
7961 Scope *err_var_scope;9012 Scope *err_var_scope;
7962 if (err_symbol) {9013 if (err_symbol) {
...@@ -7965,40 +9016,40 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -7965,40 +9016,40 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *
7965 ZigVar *var = ir_create_var(irb, node, subexpr_scope,9016 ZigVar *var = ir_create_var(irb, node, subexpr_scope,
7966 err_symbol, is_const, is_const, is_shadowable, is_comptime);9017 err_symbol, is_const, is_const, is_shadowable, is_comptime);
79679018
7968 IrInstruction *err_ptr = ir_build_unwrap_err_code(irb, subexpr_scope, node, err_val_ptr);9019 IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, subexpr_scope, node, err_val_ptr);
7969 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, err_ptr);9020 ir_build_var_decl_src(irb, subexpr_scope, node, var, nullptr, err_ptr);
7970 err_var_scope = var->child_scope;9021 err_var_scope = var->child_scope;
7971 } else {9022 } else {
7972 err_var_scope = subexpr_scope;9023 err_var_scope = subexpr_scope;
7973 }9024 }
7974 else_expr_result = ir_gen_node_extra(irb, else_node, err_var_scope, lval, &peer_parent->peers.at(1)->base);9025 else_expr_result = ir_gen_node_extra(irb, else_node, err_var_scope, lval, &peer_parent->peers.at(1)->base);
7975 if (else_expr_result == irb->codegen->invalid_instruction)9026 if (else_expr_result == irb->codegen->invalid_inst_src)
7976 return else_expr_result;9027 return else_expr_result;
7977 } else {9028 } else {
7978 else_expr_result = ir_build_const_void(irb, scope, node);9029 else_expr_result = ir_build_const_void(irb, scope, node);
7979 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);9030 ir_build_end_expr(irb, scope, node, else_expr_result, &peer_parent->peers.at(1)->base);
7980 }9031 }
7981 IrBasicBlock *after_else_block = irb->current_basic_block;9032 IrBasicBlockSrc *after_else_block = irb->current_basic_block;
7982 if (!instr_is_unreachable(else_expr_result))9033 if (!instr_is_unreachable(else_expr_result))
7983 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));9034 ir_mark_gen(ir_build_br(irb, scope, node, endif_block, is_comptime));
79849035
7985 ir_set_cursor_at_end_and_append_block(irb, endif_block);9036 ir_set_cursor_at_end_and_append_block(irb, endif_block);
7986 IrInstruction **incoming_values = allocate<IrInstruction *>(2);9037 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
7987 incoming_values[0] = then_expr_result;9038 incoming_values[0] = then_expr_result;
7988 incoming_values[1] = else_expr_result;9039 incoming_values[1] = else_expr_result;
7989 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");9040 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
7990 incoming_blocks[0] = after_then_block;9041 incoming_blocks[0] = after_then_block;
7991 incoming_blocks[1] = after_else_block;9042 incoming_blocks[1] = after_else_block;
79929043
7993 IrInstruction *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);9044 IrInstSrc *phi = ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values, peer_parent);
7994 return ir_expr_wrap(irb, scope, phi, result_loc);9045 return ir_expr_wrap(irb, scope, phi, result_loc);
7995}9046}
79969047
7997static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *switch_node, AstNode *prong_node,9048static bool ir_gen_switch_prong_expr(IrBuilderSrc *irb, Scope *scope, AstNode *switch_node, AstNode *prong_node,
7998 IrBasicBlock *end_block, IrInstruction *is_comptime, IrInstruction *var_is_comptime,9049 IrBasicBlockSrc *end_block, IrInstSrc *is_comptime, IrInstSrc *var_is_comptime,
7999 IrInstruction *target_value_ptr, IrInstruction **prong_values, size_t prong_values_len,9050 IrInstSrc *target_value_ptr, IrInstSrc **prong_values, size_t prong_values_len,
8000 ZigList<IrBasicBlock *> *incoming_blocks, ZigList<IrInstruction *> *incoming_values,9051 ZigList<IrBasicBlockSrc *> *incoming_blocks, ZigList<IrInstSrc *> *incoming_values,
8001 IrInstructionSwitchElseVar **out_switch_else_var, LVal lval, ResultLoc *result_loc)9052 IrInstSrcSwitchElseVar **out_switch_else_var, LVal lval, ResultLoc *result_loc)
8002{9053{
8003 assert(switch_node->type == NodeTypeSwitchExpr);9054 assert(switch_node->type == NodeTypeSwitchExpr);
8004 assert(prong_node->type == NodeTypeSwitchProng);9055 assert(prong_node->type == NodeTypeSwitchProng);
...@@ -8016,28 +9067,28 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit...@@ -8016,28 +9067,28 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit
8016 ZigVar *var = ir_create_var(irb, var_symbol_node, scope,9067 ZigVar *var = ir_create_var(irb, var_symbol_node, scope,
8017 var_name, is_const, is_const, is_shadowable, var_is_comptime);9068 var_name, is_const, is_const, is_shadowable, var_is_comptime);
8018 child_scope = var->child_scope;9069 child_scope = var->child_scope;
8019 IrInstruction *var_ptr;9070 IrInstSrc *var_ptr;
8020 if (out_switch_else_var != nullptr) {9071 if (out_switch_else_var != nullptr) {
8021 IrInstructionSwitchElseVar *switch_else_var = ir_build_switch_else_var(irb, scope, var_symbol_node,9072 IrInstSrcSwitchElseVar *switch_else_var = ir_build_switch_else_var(irb, scope, var_symbol_node,
8022 target_value_ptr);9073 target_value_ptr);
8023 *out_switch_else_var = switch_else_var;9074 *out_switch_else_var = switch_else_var;
8024 IrInstruction *payload_ptr = &switch_else_var->base;9075 IrInstSrc *payload_ptr = &switch_else_var->base;
8025 var_ptr = var_is_ptr ? ir_build_ref(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr;9076 var_ptr = var_is_ptr ? ir_build_ref_src(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr;
8026 } else if (prong_values != nullptr) {9077 } else if (prong_values != nullptr) {
8027 IrInstruction *payload_ptr = ir_build_switch_var(irb, scope, var_symbol_node, target_value_ptr,9078 IrInstSrc *payload_ptr = ir_build_switch_var(irb, scope, var_symbol_node, target_value_ptr,
8028 prong_values, prong_values_len);9079 prong_values, prong_values_len);
8029 var_ptr = var_is_ptr ? ir_build_ref(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr;9080 var_ptr = var_is_ptr ? ir_build_ref_src(irb, scope, var_symbol_node, payload_ptr, true, false) : payload_ptr;
8030 } else {9081 } else {
8031 var_ptr = var_is_ptr ?9082 var_ptr = var_is_ptr ?
8032 ir_build_ref(irb, scope, var_symbol_node, target_value_ptr, true, false) : target_value_ptr;9083 ir_build_ref_src(irb, scope, var_symbol_node, target_value_ptr, true, false) : target_value_ptr;
8033 }9084 }
8034 ir_build_var_decl_src(irb, scope, var_symbol_node, var, nullptr, var_ptr);9085 ir_build_var_decl_src(irb, scope, var_symbol_node, var, nullptr, var_ptr);
8035 } else {9086 } else {
8036 child_scope = scope;9087 child_scope = scope;
8037 }9088 }
80389089
8039 IrInstruction *expr_result = ir_gen_node_extra(irb, expr_node, child_scope, lval, result_loc);9090 IrInstSrc *expr_result = ir_gen_node_extra(irb, expr_node, child_scope, lval, result_loc);
8040 if (expr_result == irb->codegen->invalid_instruction)9091 if (expr_result == irb->codegen->invalid_inst_src)
8041 return false;9092 return false;
8042 if (!instr_is_unreachable(expr_result))9093 if (!instr_is_unreachable(expr_result))
8043 ir_mark_gen(ir_build_br(irb, scope, switch_node, end_block, is_comptime));9094 ir_mark_gen(ir_build_br(irb, scope, switch_node, end_block, is_comptime));
...@@ -8046,25 +9097,25 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit...@@ -8046,25 +9097,25 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit
8046 return true;9097 return true;
8047}9098}
80489099
8049static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,9100static IrInstSrc *ir_gen_switch_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
8050 ResultLoc *result_loc)9101 ResultLoc *result_loc)
8051{9102{
8052 assert(node->type == NodeTypeSwitchExpr);9103 assert(node->type == NodeTypeSwitchExpr);
80539104
8054 AstNode *target_node = node->data.switch_expr.expr;9105 AstNode *target_node = node->data.switch_expr.expr;
8055 IrInstruction *target_value_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr);9106 IrInstSrc *target_value_ptr = ir_gen_node_extra(irb, target_node, scope, LValPtr, nullptr);
8056 if (target_value_ptr == irb->codegen->invalid_instruction)9107 if (target_value_ptr == irb->codegen->invalid_inst_src)
8057 return target_value_ptr;9108 return target_value_ptr;
8058 IrInstruction *target_value = ir_build_switch_target(irb, scope, node, target_value_ptr);9109 IrInstSrc *target_value = ir_build_switch_target(irb, scope, node, target_value_ptr);
80599110
8060 IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "SwitchElse");9111 IrBasicBlockSrc *else_block = ir_create_basic_block(irb, scope, "SwitchElse");
8061 IrBasicBlock *end_block = ir_create_basic_block(irb, scope, "SwitchEnd");9112 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, scope, "SwitchEnd");
80629113
8063 size_t prong_count = node->data.switch_expr.prongs.length;9114 size_t prong_count = node->data.switch_expr.prongs.length;
8064 ZigList<IrInstructionSwitchBrCase> cases = {0};9115 ZigList<IrInstSrcSwitchBrCase> cases = {0};
80659116
8066 IrInstruction *is_comptime;9117 IrInstSrc *is_comptime;
8067 IrInstruction *var_is_comptime;9118 IrInstSrc *var_is_comptime;
8068 if (ir_should_inline(irb->exec, scope)) {9119 if (ir_should_inline(irb->exec, scope)) {
8069 is_comptime = ir_build_const_bool(irb, scope, node, true);9120 is_comptime = ir_build_const_bool(irb, scope, node, true);
8070 var_is_comptime = is_comptime;9121 var_is_comptime = is_comptime;
...@@ -8073,11 +9124,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8073,11 +9124,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8073 var_is_comptime = ir_build_test_comptime(irb, scope, node, target_value_ptr);9124 var_is_comptime = ir_build_test_comptime(irb, scope, node, target_value_ptr);
8074 }9125 }
80759126
8076 ZigList<IrInstruction *> incoming_values = {0};9127 ZigList<IrInstSrc *> incoming_values = {0};
8077 ZigList<IrBasicBlock *> incoming_blocks = {0};9128 ZigList<IrBasicBlockSrc *> incoming_blocks = {0};
8078 ZigList<IrInstructionCheckSwitchProngsRange> check_ranges = {0};9129 ZigList<IrInstSrcCheckSwitchProngsRange> check_ranges = {0};
80799130
8080 IrInstructionSwitchElseVar *switch_else_var = nullptr;9131 IrInstSrcSwitchElseVar *switch_else_var = nullptr;
80819132
8082 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);9133 ResultLocPeerParent *peer_parent = allocate<ResultLocPeerParent>(1);
8083 peer_parent->base.id = ResultLocIdPeerParent;9134 peer_parent->base.id = ResultLocIdPeerParent;
...@@ -8099,7 +9150,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8099,7 +9150,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8099 if (prong_node->data.switch_prong.any_items_are_range) {9150 if (prong_node->data.switch_prong.any_items_are_range) {
8100 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);9151 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);
81019152
8102 IrInstruction *ok_bit = nullptr;9153 IrInstSrc *ok_bit = nullptr;
8103 AstNode *last_item_node = nullptr;9154 AstNode *last_item_node = nullptr;
8104 for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) {9155 for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) {
8105 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);9156 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
...@@ -8108,23 +9159,23 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8108,23 +9159,23 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8108 AstNode *start_node = item_node->data.switch_range.start;9159 AstNode *start_node = item_node->data.switch_range.start;
8109 AstNode *end_node = item_node->data.switch_range.end;9160 AstNode *end_node = item_node->data.switch_range.end;
81109161
8111 IrInstruction *start_value = ir_gen_node(irb, start_node, comptime_scope);9162 IrInstSrc *start_value = ir_gen_node(irb, start_node, comptime_scope);
8112 if (start_value == irb->codegen->invalid_instruction)9163 if (start_value == irb->codegen->invalid_inst_src)
8113 return irb->codegen->invalid_instruction;9164 return irb->codegen->invalid_inst_src;
81149165
8115 IrInstruction *end_value = ir_gen_node(irb, end_node, comptime_scope);9166 IrInstSrc *end_value = ir_gen_node(irb, end_node, comptime_scope);
8116 if (end_value == irb->codegen->invalid_instruction)9167 if (end_value == irb->codegen->invalid_inst_src)
8117 return irb->codegen->invalid_instruction;9168 return irb->codegen->invalid_inst_src;
81189169
8119 IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one();9170 IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one();
8120 check_range->start = start_value;9171 check_range->start = start_value;
8121 check_range->end = end_value;9172 check_range->end = end_value;
81229173
8123 IrInstruction *lower_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpGreaterOrEq,9174 IrInstSrc *lower_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpGreaterOrEq,
8124 target_value, start_value, false);9175 target_value, start_value, false);
8125 IrInstruction *upper_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpLessOrEq,9176 IrInstSrc *upper_range_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpLessOrEq,
8126 target_value, end_value, false);9177 target_value, end_value, false);
8127 IrInstruction *both_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolAnd,9178 IrInstSrc *both_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolAnd,
8128 lower_range_ok, upper_range_ok, false);9179 lower_range_ok, upper_range_ok, false);
8129 if (ok_bit) {9180 if (ok_bit) {
8130 ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, both_ok, ok_bit, false);9181 ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, both_ok, ok_bit, false);
...@@ -8132,15 +9183,15 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8132,15 +9183,15 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8132 ok_bit = both_ok;9183 ok_bit = both_ok;
8133 }9184 }
8134 } else {9185 } else {
8135 IrInstruction *item_value = ir_gen_node(irb, item_node, comptime_scope);9186 IrInstSrc *item_value = ir_gen_node(irb, item_node, comptime_scope);
8136 if (item_value == irb->codegen->invalid_instruction)9187 if (item_value == irb->codegen->invalid_inst_src)
8137 return irb->codegen->invalid_instruction;9188 return irb->codegen->invalid_inst_src;
81389189
8139 IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one();9190 IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one();
8140 check_range->start = item_value;9191 check_range->start = item_value;
8141 check_range->end = item_value;9192 check_range->end = item_value;
81429193
8143 IrInstruction *cmp_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpEq,9194 IrInstSrc *cmp_ok = ir_build_bin_op(irb, scope, item_node, IrBinOpCmpEq,
8144 item_value, target_value, false);9195 item_value, target_value, false);
8145 if (ok_bit) {9196 if (ok_bit) {
8146 ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, cmp_ok, ok_bit, false);9197 ok_bit = ir_build_bin_op(irb, scope, item_node, IrBinOpBoolOr, cmp_ok, ok_bit, false);
...@@ -8150,12 +9201,12 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8150,12 +9201,12 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8150 }9201 }
8151 }9202 }
81529203
8153 IrBasicBlock *range_block_yes = ir_create_basic_block(irb, scope, "SwitchRangeYes");9204 IrBasicBlockSrc *range_block_yes = ir_create_basic_block(irb, scope, "SwitchRangeYes");
8154 IrBasicBlock *range_block_no = ir_create_basic_block(irb, scope, "SwitchRangeNo");9205 IrBasicBlockSrc *range_block_no = ir_create_basic_block(irb, scope, "SwitchRangeNo");
81559206
8156 assert(ok_bit);9207 assert(ok_bit);
8157 assert(last_item_node);9208 assert(last_item_node);
8158 IrInstruction *br_inst = ir_mark_gen(ir_build_cond_br(irb, scope, last_item_node, ok_bit,9209 IrInstSrc *br_inst = ir_mark_gen(ir_build_cond_br(irb, scope, last_item_node, ok_bit,
8159 range_block_yes, range_block_no, is_comptime));9210 range_block_yes, range_block_no, is_comptime));
8160 if (peer_parent->base.source_instruction == nullptr) {9211 if (peer_parent->base.source_instruction == nullptr) {
8161 peer_parent->base.source_instruction = br_inst;9212 peer_parent->base.source_instruction = br_inst;
...@@ -8170,7 +9221,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8170,7 +9221,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8170 is_comptime, var_is_comptime, target_value_ptr, nullptr, 0,9221 is_comptime, var_is_comptime, target_value_ptr, nullptr, 0,
8171 &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base))9222 &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base))
8172 {9223 {
8173 return irb->codegen->invalid_instruction;9224 return irb->codegen->invalid_inst_src;
8174 }9225 }
81759226
8176 ir_set_cursor_at_end_and_append_block(irb, range_block_no);9227 ir_set_cursor_at_end_and_append_block(irb, range_block_no);
...@@ -8181,7 +9232,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8181,7 +9232,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8181 buf_sprintf("multiple else prongs in switch expression"));9232 buf_sprintf("multiple else prongs in switch expression"));
8182 add_error_note(irb->codegen, msg, else_prong,9233 add_error_note(irb->codegen, msg, else_prong,
8183 buf_sprintf("previous else prong is here"));9234 buf_sprintf("previous else prong is here"));
8184 return irb->codegen->invalid_instruction;9235 return irb->codegen->invalid_inst_src;
8185 }9236 }
8186 else_prong = prong_node;9237 else_prong = prong_node;
8187 } else if (prong_item_count == 1 && 9238 } else if (prong_item_count == 1 &&
...@@ -8192,7 +9243,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8192,7 +9243,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8192 buf_sprintf("multiple '_' prongs in switch expression"));9243 buf_sprintf("multiple '_' prongs in switch expression"));
8193 add_error_note(irb->codegen, msg, underscore_prong,9244 add_error_note(irb->codegen, msg, underscore_prong,
8194 buf_sprintf("previous '_' prong is here"));9245 buf_sprintf("previous '_' prong is here"));
8195 return irb->codegen->invalid_instruction;9246 return irb->codegen->invalid_inst_src;
8196 }9247 }
8197 underscore_prong = prong_node;9248 underscore_prong = prong_node;
8198 } else {9249 } else {
...@@ -8207,11 +9258,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8207,11 +9258,11 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8207 else9258 else
8208 add_error_note(irb->codegen, msg, underscore_prong,9259 add_error_note(irb->codegen, msg, underscore_prong,
8209 buf_sprintf("'_' prong is here"));9260 buf_sprintf("'_' prong is here"));
8210 return irb->codegen->invalid_instruction;9261 return irb->codegen->invalid_inst_src;
8211 }9262 }
8212 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);9263 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);
82139264
8214 IrBasicBlock *prev_block = irb->current_basic_block;9265 IrBasicBlockSrc *prev_block = irb->current_basic_block;
8215 if (peer_parent->peers.length > 0) {9266 if (peer_parent->peers.length > 0) {
8216 peer_parent->peers.last()->next_bb = else_block;9267 peer_parent->peers.last()->next_bb = else_block;
8217 }9268 }
...@@ -8221,7 +9272,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8221,7 +9272,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8221 is_comptime, var_is_comptime, target_value_ptr, nullptr, 0, &incoming_blocks, &incoming_values,9272 is_comptime, var_is_comptime, target_value_ptr, nullptr, 0, &incoming_blocks, &incoming_values,
8222 &switch_else_var, LValNone, &this_peer_result_loc->base))9273 &switch_else_var, LValNone, &this_peer_result_loc->base))
8223 {9274 {
8224 return irb->codegen->invalid_instruction;9275 return irb->codegen->invalid_inst_src;
8225 }9276 }
8226 ir_set_cursor_at_end(irb, prev_block);9277 ir_set_cursor_at_end(irb, prev_block);
8227 }9278 }
...@@ -8240,29 +9291,29 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8240,29 +9291,29 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
82409291
8241 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);9292 ResultLocPeer *this_peer_result_loc = create_peer_result(peer_parent);
82429293
8243 IrBasicBlock *prong_block = ir_create_basic_block(irb, scope, "SwitchProng");9294 IrBasicBlockSrc *prong_block = ir_create_basic_block(irb, scope, "SwitchProng");
8244 IrInstruction **items = allocate<IrInstruction *>(prong_item_count);9295 IrInstSrc **items = allocate<IrInstSrc *>(prong_item_count);
82459296
8246 for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) {9297 for (size_t item_i = 0; item_i < prong_item_count; item_i += 1) {
8247 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);9298 AstNode *item_node = prong_node->data.switch_prong.items.at(item_i);
8248 assert(item_node->type != NodeTypeSwitchRange);9299 assert(item_node->type != NodeTypeSwitchRange);
82499300
8250 IrInstruction *item_value = ir_gen_node(irb, item_node, comptime_scope);9301 IrInstSrc *item_value = ir_gen_node(irb, item_node, comptime_scope);
8251 if (item_value == irb->codegen->invalid_instruction)9302 if (item_value == irb->codegen->invalid_inst_src)
8252 return irb->codegen->invalid_instruction;9303 return irb->codegen->invalid_inst_src;
82539304
8254 IrInstructionCheckSwitchProngsRange *check_range = check_ranges.add_one();9305 IrInstSrcCheckSwitchProngsRange *check_range = check_ranges.add_one();
8255 check_range->start = item_value;9306 check_range->start = item_value;
8256 check_range->end = item_value;9307 check_range->end = item_value;
82579308
8258 IrInstructionSwitchBrCase *this_case = cases.add_one();9309 IrInstSrcSwitchBrCase *this_case = cases.add_one();
8259 this_case->value = item_value;9310 this_case->value = item_value;
8260 this_case->block = prong_block;9311 this_case->block = prong_block;
82619312
8262 items[item_i] = item_value;9313 items[item_i] = item_value;
8263 }9314 }
82649315
8265 IrBasicBlock *prev_block = irb->current_basic_block;9316 IrBasicBlockSrc *prev_block = irb->current_basic_block;
8266 if (peer_parent->peers.length > 0) {9317 if (peer_parent->peers.length > 0) {
8267 peer_parent->peers.last()->next_bb = prong_block;9318 peer_parent->peers.last()->next_bb = prong_block;
8268 }9319 }
...@@ -8272,21 +9323,21 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8272,21 +9323,21 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8272 is_comptime, var_is_comptime, target_value_ptr, items, prong_item_count,9323 is_comptime, var_is_comptime, target_value_ptr, items, prong_item_count,
8273 &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base))9324 &incoming_blocks, &incoming_values, nullptr, LValNone, &this_peer_result_loc->base))
8274 {9325 {
8275 return irb->codegen->invalid_instruction;9326 return irb->codegen->invalid_inst_src;
8276 }9327 }
82779328
8278 ir_set_cursor_at_end(irb, prev_block);9329 ir_set_cursor_at_end(irb, prev_block);
82799330
8280 }9331 }
82819332
8282 IrInstruction *switch_prongs_void = ir_build_check_switch_prongs(irb, scope, node, target_value,9333 IrInstSrc *switch_prongs_void = ir_build_check_switch_prongs(irb, scope, node, target_value,
8283 check_ranges.items, check_ranges.length, else_prong != nullptr, underscore_prong != nullptr);9334 check_ranges.items, check_ranges.length, else_prong != nullptr, underscore_prong != nullptr);
82849335
8285 IrInstruction *br_instruction;9336 IrInstSrc *br_instruction;
8286 if (cases.length == 0) {9337 if (cases.length == 0) {
8287 br_instruction = ir_build_br(irb, scope, node, else_block, is_comptime);9338 br_instruction = ir_build_br(irb, scope, node, else_block, is_comptime);
8288 } else {9339 } else {
8289 IrInstructionSwitchBr *switch_br = ir_build_switch_br(irb, scope, node, target_value, else_block,9340 IrInstSrcSwitchBr *switch_br = ir_build_switch_br_src(irb, scope, node, target_value, else_block,
8290 cases.length, cases.items, is_comptime, switch_prongs_void);9341 cases.length, cases.items, is_comptime, switch_prongs_void);
8291 if (switch_else_var != nullptr) {9342 if (switch_else_var != nullptr) {
8292 switch_else_var->switch_br = switch_br;9343 switch_else_var->switch_br = switch_br;
...@@ -8314,7 +9365,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8314,7 +9365,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
83149365
8315 ir_set_cursor_at_end_and_append_block(irb, end_block);9366 ir_set_cursor_at_end_and_append_block(irb, end_block);
8316 assert(incoming_blocks.length == incoming_values.length);9367 assert(incoming_blocks.length == incoming_values.length);
8317 IrInstruction *result_instruction;9368 IrInstSrc *result_instruction;
8318 if (incoming_blocks.length == 0) {9369 if (incoming_blocks.length == 0) {
8319 result_instruction = ir_build_const_void(irb, scope, node);9370 result_instruction = ir_build_const_void(irb, scope, node);
8320 } else {9371 } else {
...@@ -8324,7 +9375,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *...@@ -8324,7 +9375,7 @@ static IrInstruction *ir_gen_switch_expr(IrBuilder *irb, Scope *scope, AstNode *
8324 return ir_lval_wrap(irb, scope, result_instruction, lval, result_loc);9375 return ir_lval_wrap(irb, scope, result_instruction, lval, result_loc);
8325}9376}
83269377
8327static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval) {9378static IrInstSrc *ir_gen_comptime(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval) {
8328 assert(node->type == NodeTypeCompTime);9379 assert(node->type == NodeTypeCompTime);
83299380
8330 Scope *child_scope = create_comptime_scope(irb->codegen, node, parent_scope);9381 Scope *child_scope = create_comptime_scope(irb->codegen, node, parent_scope);
...@@ -8332,28 +9383,28 @@ static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -8332,28 +9383,28 @@ static IrInstruction *ir_gen_comptime(IrBuilder *irb, Scope *parent_scope, AstNo
8332 return ir_gen_node_extra(irb, node->data.comptime_expr.expr, child_scope, lval, nullptr);9383 return ir_gen_node_extra(irb, node->data.comptime_expr.expr, child_scope, lval, nullptr);
8333}9384}
83349385
8335static IrInstruction *ir_gen_return_from_block(IrBuilder *irb, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) {9386static IrInstSrc *ir_gen_return_from_block(IrBuilderSrc *irb, Scope *break_scope, AstNode *node, ScopeBlock *block_scope) {
8336 IrInstruction *is_comptime;9387 IrInstSrc *is_comptime;
8337 if (ir_should_inline(irb->exec, break_scope)) {9388 if (ir_should_inline(irb->exec, break_scope)) {
8338 is_comptime = ir_build_const_bool(irb, break_scope, node, true);9389 is_comptime = ir_build_const_bool(irb, break_scope, node, true);
8339 } else {9390 } else {
8340 is_comptime = block_scope->is_comptime;9391 is_comptime = block_scope->is_comptime;
8341 }9392 }
83429393
8343 IrInstruction *result_value;9394 IrInstSrc *result_value;
8344 if (node->data.break_expr.expr) {9395 if (node->data.break_expr.expr) {
8345 ResultLocPeer *peer_result = create_peer_result(block_scope->peer_parent);9396 ResultLocPeer *peer_result = create_peer_result(block_scope->peer_parent);
8346 block_scope->peer_parent->peers.append(peer_result);9397 block_scope->peer_parent->peers.append(peer_result);
83479398
8348 result_value = ir_gen_node_extra(irb, node->data.break_expr.expr, break_scope, block_scope->lval,9399 result_value = ir_gen_node_extra(irb, node->data.break_expr.expr, break_scope, block_scope->lval,
8349 &peer_result->base);9400 &peer_result->base);
8350 if (result_value == irb->codegen->invalid_instruction)9401 if (result_value == irb->codegen->invalid_inst_src)
8351 return irb->codegen->invalid_instruction;9402 return irb->codegen->invalid_inst_src;
8352 } else {9403 } else {
8353 result_value = ir_build_const_void(irb, break_scope, node);9404 result_value = ir_build_const_void(irb, break_scope, node);
8354 }9405 }
83559406
8356 IrBasicBlock *dest_block = block_scope->end_block;9407 IrBasicBlockSrc *dest_block = block_scope->end_block;
8357 ir_gen_defers_for_block(irb, break_scope, dest_block->scope, false);9408 ir_gen_defers_for_block(irb, break_scope, dest_block->scope, false);
83589409
8359 block_scope->incoming_blocks->append(irb->current_basic_block);9410 block_scope->incoming_blocks->append(irb->current_basic_block);
...@@ -8361,7 +9412,7 @@ static IrInstruction *ir_gen_return_from_block(IrBuilder *irb, Scope *break_scop...@@ -8361,7 +9412,7 @@ static IrInstruction *ir_gen_return_from_block(IrBuilder *irb, Scope *break_scop
8361 return ir_build_br(irb, break_scope, node, dest_block, is_comptime);9412 return ir_build_br(irb, break_scope, node, dest_block, is_comptime);
8362}9413}
83639414
8364static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *node) {9415static IrInstSrc *ir_gen_break(IrBuilderSrc *irb, Scope *break_scope, AstNode *node) {
8365 assert(node->type == NodeTypeBreak);9416 assert(node->type == NodeTypeBreak);
83669417
8367 // Search up the scope. We'll find one of these things first:9418 // Search up the scope. We'll find one of these things first:
...@@ -8376,14 +9427,14 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *...@@ -8376,14 +9427,14 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *
8376 if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) {9427 if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) {
8377 if (node->data.break_expr.name != nullptr) {9428 if (node->data.break_expr.name != nullptr) {
8378 add_node_error(irb->codegen, node, buf_sprintf("label not found: '%s'", buf_ptr(node->data.break_expr.name)));9429 add_node_error(irb->codegen, node, buf_sprintf("label not found: '%s'", buf_ptr(node->data.break_expr.name)));
8379 return irb->codegen->invalid_instruction;9430 return irb->codegen->invalid_inst_src;
8380 } else {9431 } else {
8381 add_node_error(irb->codegen, node, buf_sprintf("break expression outside loop"));9432 add_node_error(irb->codegen, node, buf_sprintf("break expression outside loop"));
8382 return irb->codegen->invalid_instruction;9433 return irb->codegen->invalid_inst_src;
8383 }9434 }
8384 } else if (search_scope->id == ScopeIdDeferExpr) {9435 } else if (search_scope->id == ScopeIdDeferExpr) {
8385 add_node_error(irb->codegen, node, buf_sprintf("cannot break out of defer expression"));9436 add_node_error(irb->codegen, node, buf_sprintf("cannot break out of defer expression"));
8386 return irb->codegen->invalid_instruction;9437 return irb->codegen->invalid_inst_src;
8387 } else if (search_scope->id == ScopeIdLoop) {9438 } else if (search_scope->id == ScopeIdLoop) {
8388 ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope;9439 ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope;
8389 if (node->data.break_expr.name == nullptr ||9440 if (node->data.break_expr.name == nullptr ||
...@@ -8402,32 +9453,32 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *...@@ -8402,32 +9453,32 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *
8402 }9453 }
8403 } else if (search_scope->id == ScopeIdSuspend) {9454 } else if (search_scope->id == ScopeIdSuspend) {
8404 add_node_error(irb->codegen, node, buf_sprintf("cannot break out of suspend block"));9455 add_node_error(irb->codegen, node, buf_sprintf("cannot break out of suspend block"));
8405 return irb->codegen->invalid_instruction;9456 return irb->codegen->invalid_inst_src;
8406 }9457 }
8407 search_scope = search_scope->parent;9458 search_scope = search_scope->parent;
8408 }9459 }
84099460
8410 IrInstruction *is_comptime;9461 IrInstSrc *is_comptime;
8411 if (ir_should_inline(irb->exec, break_scope)) {9462 if (ir_should_inline(irb->exec, break_scope)) {
8412 is_comptime = ir_build_const_bool(irb, break_scope, node, true);9463 is_comptime = ir_build_const_bool(irb, break_scope, node, true);
8413 } else {9464 } else {
8414 is_comptime = loop_scope->is_comptime;9465 is_comptime = loop_scope->is_comptime;
8415 }9466 }
84169467
8417 IrInstruction *result_value;9468 IrInstSrc *result_value;
8418 if (node->data.break_expr.expr) {9469 if (node->data.break_expr.expr) {
8419 ResultLocPeer *peer_result = create_peer_result(loop_scope->peer_parent);9470 ResultLocPeer *peer_result = create_peer_result(loop_scope->peer_parent);
8420 loop_scope->peer_parent->peers.append(peer_result);9471 loop_scope->peer_parent->peers.append(peer_result);
84219472
8422 result_value = ir_gen_node_extra(irb, node->data.break_expr.expr, break_scope,9473 result_value = ir_gen_node_extra(irb, node->data.break_expr.expr, break_scope,
8423 loop_scope->lval, &peer_result->base);9474 loop_scope->lval, &peer_result->base);
8424 if (result_value == irb->codegen->invalid_instruction)9475 if (result_value == irb->codegen->invalid_inst_src)
8425 return irb->codegen->invalid_instruction;9476 return irb->codegen->invalid_inst_src;
8426 } else {9477 } else {
8427 result_value = ir_build_const_void(irb, break_scope, node);9478 result_value = ir_build_const_void(irb, break_scope, node);
8428 }9479 }
84299480
8430 IrBasicBlock *dest_block = loop_scope->break_block;9481 IrBasicBlockSrc *dest_block = loop_scope->break_block;
8431 ir_gen_defers_for_block(irb, break_scope, dest_block->scope, false);9482 ir_gen_defers_for_block(irb, break_scope, dest_block->scope, false);
84329483
8433 loop_scope->incoming_blocks->append(irb->current_basic_block);9484 loop_scope->incoming_blocks->append(irb->current_basic_block);
...@@ -8435,7 +9486,7 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *...@@ -8435,7 +9486,7 @@ static IrInstruction *ir_gen_break(IrBuilder *irb, Scope *break_scope, AstNode *
8435 return ir_build_br(irb, break_scope, node, dest_block, is_comptime);9486 return ir_build_br(irb, break_scope, node, dest_block, is_comptime);
8436}9487}
84379488
8438static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, AstNode *node) {9489static IrInstSrc *ir_gen_continue(IrBuilderSrc *irb, Scope *continue_scope, AstNode *node) {
8439 assert(node->type == NodeTypeContinue);9490 assert(node->type == NodeTypeContinue);
84409491
8441 // Search up the scope. We'll find one of these things first:9492 // Search up the scope. We'll find one of these things first:
...@@ -8451,14 +9502,14 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast...@@ -8451,14 +9502,14 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
8451 if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) {9502 if (search_scope == nullptr || search_scope->id == ScopeIdFnDef) {
8452 if (node->data.continue_expr.name != nullptr) {9503 if (node->data.continue_expr.name != nullptr) {
8453 add_node_error(irb->codegen, node, buf_sprintf("labeled loop not found: '%s'", buf_ptr(node->data.continue_expr.name)));9504 add_node_error(irb->codegen, node, buf_sprintf("labeled loop not found: '%s'", buf_ptr(node->data.continue_expr.name)));
8454 return irb->codegen->invalid_instruction;9505 return irb->codegen->invalid_inst_src;
8455 } else {9506 } else {
8456 add_node_error(irb->codegen, node, buf_sprintf("continue expression outside loop"));9507 add_node_error(irb->codegen, node, buf_sprintf("continue expression outside loop"));
8457 return irb->codegen->invalid_instruction;9508 return irb->codegen->invalid_inst_src;
8458 }9509 }
8459 } else if (search_scope->id == ScopeIdDeferExpr) {9510 } else if (search_scope->id == ScopeIdDeferExpr) {
8460 add_node_error(irb->codegen, node, buf_sprintf("cannot continue out of defer expression"));9511 add_node_error(irb->codegen, node, buf_sprintf("cannot continue out of defer expression"));
8461 return irb->codegen->invalid_instruction;9512 return irb->codegen->invalid_inst_src;
8462 } else if (search_scope->id == ScopeIdLoop) {9513 } else if (search_scope->id == ScopeIdLoop) {
8463 ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope;9514 ScopeLoop *this_loop_scope = (ScopeLoop *)search_scope;
8464 if (node->data.continue_expr.name == nullptr ||9515 if (node->data.continue_expr.name == nullptr ||
...@@ -8474,7 +9525,7 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast...@@ -8474,7 +9525,7 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
8474 search_scope = search_scope->parent;9525 search_scope = search_scope->parent;
8475 }9526 }
84769527
8477 IrInstruction *is_comptime;9528 IrInstSrc *is_comptime;
8478 if (ir_should_inline(irb->exec, continue_scope)) {9529 if (ir_should_inline(irb->exec, continue_scope)) {
8479 is_comptime = ir_build_const_bool(irb, continue_scope, node, true);9530 is_comptime = ir_build_const_bool(irb, continue_scope, node, true);
8480 } else {9531 } else {
...@@ -8486,17 +9537,17 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast...@@ -8486,17 +9537,17 @@ static IrInstruction *ir_gen_continue(IrBuilder *irb, Scope *continue_scope, Ast
8486 ir_mark_gen(ir_build_check_runtime_scope(irb, continue_scope, node, scope_runtime->is_comptime, is_comptime));9537 ir_mark_gen(ir_build_check_runtime_scope(irb, continue_scope, node, scope_runtime->is_comptime, is_comptime));
8487 }9538 }
84889539
8489 IrBasicBlock *dest_block = loop_scope->continue_block;9540 IrBasicBlockSrc *dest_block = loop_scope->continue_block;
8490 ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, false);9541 ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, false);
8491 return ir_mark_gen(ir_build_br(irb, continue_scope, node, dest_block, is_comptime));9542 return ir_mark_gen(ir_build_br(irb, continue_scope, node, dest_block, is_comptime));
8492}9543}
84939544
8494static IrInstruction *ir_gen_error_type(IrBuilder *irb, Scope *scope, AstNode *node) {9545static IrInstSrc *ir_gen_error_type(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
8495 assert(node->type == NodeTypeErrorType);9546 assert(node->type == NodeTypeErrorType);
8496 return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_global_error_set);9547 return ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_global_error_set);
8497}9548}
84989549
8499static IrInstruction *ir_gen_defer(IrBuilder *irb, Scope *parent_scope, AstNode *node) {9550static IrInstSrc *ir_gen_defer(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
8500 assert(node->type == NodeTypeDefer);9551 assert(node->type == NodeTypeDefer);
85019552
8502 ScopeDefer *defer_child_scope = create_defer_scope(irb->codegen, node, parent_scope);9553 ScopeDefer *defer_child_scope = create_defer_scope(irb->codegen, node, parent_scope);
...@@ -8508,7 +9559,7 @@ static IrInstruction *ir_gen_defer(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -8508,7 +9559,7 @@ static IrInstruction *ir_gen_defer(IrBuilder *irb, Scope *parent_scope, AstNode
8508 return ir_build_const_void(irb, parent_scope, node);9559 return ir_build_const_void(irb, parent_scope, node);
8509}9560}
85109561
8511static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {9562static IrInstSrc *ir_gen_slice(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) {
8512 assert(node->type == NodeTypeSliceExpr);9563 assert(node->type == NodeTypeSliceExpr);
85139564
8514 AstNodeSliceExpr *slice_expr = &node->data.slice_expr;9565 AstNodeSliceExpr *slice_expr = &node->data.slice_expr;
...@@ -8517,38 +9568,38 @@ static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node,...@@ -8517,38 +9568,38 @@ static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node,
8517 AstNode *end_node = slice_expr->end;9568 AstNode *end_node = slice_expr->end;
8518 AstNode *sentinel_node = slice_expr->sentinel;9569 AstNode *sentinel_node = slice_expr->sentinel;
85199570
8520 IrInstruction *ptr_value = ir_gen_node_extra(irb, array_node, scope, LValPtr, nullptr);9571 IrInstSrc *ptr_value = ir_gen_node_extra(irb, array_node, scope, LValPtr, nullptr);
8521 if (ptr_value == irb->codegen->invalid_instruction)9572 if (ptr_value == irb->codegen->invalid_inst_src)
8522 return irb->codegen->invalid_instruction;9573 return irb->codegen->invalid_inst_src;
85239574
8524 IrInstruction *start_value = ir_gen_node(irb, start_node, scope);9575 IrInstSrc *start_value = ir_gen_node(irb, start_node, scope);
8525 if (start_value == irb->codegen->invalid_instruction)9576 if (start_value == irb->codegen->invalid_inst_src)
8526 return irb->codegen->invalid_instruction;9577 return irb->codegen->invalid_inst_src;
85279578
8528 IrInstruction *end_value;9579 IrInstSrc *end_value;
8529 if (end_node) {9580 if (end_node) {
8530 end_value = ir_gen_node(irb, end_node, scope);9581 end_value = ir_gen_node(irb, end_node, scope);
8531 if (end_value == irb->codegen->invalid_instruction)9582 if (end_value == irb->codegen->invalid_inst_src)
8532 return irb->codegen->invalid_instruction;9583 return irb->codegen->invalid_inst_src;
8533 } else {9584 } else {
8534 end_value = nullptr;9585 end_value = nullptr;
8535 }9586 }
85369587
8537 IrInstruction *sentinel_value;9588 IrInstSrc *sentinel_value;
8538 if (sentinel_node) {9589 if (sentinel_node) {
8539 sentinel_value = ir_gen_node(irb, sentinel_node, scope);9590 sentinel_value = ir_gen_node(irb, sentinel_node, scope);
8540 if (sentinel_value == irb->codegen->invalid_instruction)9591 if (sentinel_value == irb->codegen->invalid_inst_src)
8541 return irb->codegen->invalid_instruction;9592 return irb->codegen->invalid_inst_src;
8542 } else {9593 } else {
8543 sentinel_value = nullptr;9594 sentinel_value = nullptr;
8544 }9595 }
85459596
8546 IrInstruction *slice = ir_build_slice_src(irb, scope, node, ptr_value, start_value, end_value,9597 IrInstSrc *slice = ir_build_slice_src(irb, scope, node, ptr_value, start_value, end_value,
8547 sentinel_value, true, result_loc);9598 sentinel_value, true, result_loc);
8548 return ir_lval_wrap(irb, scope, slice, lval, result_loc);9599 return ir_lval_wrap(irb, scope, slice, lval, result_loc);
8549}9600}
85509601
8551static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval,9602static IrInstSrc *ir_gen_catch(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node, LVal lval,
8552 ResultLoc *result_loc)9603 ResultLoc *result_loc)
8553{9604{
8554 assert(node->type == NodeTypeCatchExpr);9605 assert(node->type == NodeTypeCatchExpr);
...@@ -8562,29 +9613,29 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -8562,29 +9613,29 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode
8562 assert(var_node->type == NodeTypeSymbol);9613 assert(var_node->type == NodeTypeSymbol);
8563 Buf *var_name = var_node->data.symbol_expr.symbol;9614 Buf *var_name = var_node->data.symbol_expr.symbol;
8564 add_node_error(irb->codegen, var_node, buf_sprintf("unused variable: '%s'", buf_ptr(var_name)));9615 add_node_error(irb->codegen, var_node, buf_sprintf("unused variable: '%s'", buf_ptr(var_name)));
8565 return irb->codegen->invalid_instruction;9616 return irb->codegen->invalid_inst_src;
8566 }9617 }
8567 return ir_gen_catch_unreachable(irb, parent_scope, node, op1_node, lval, result_loc);9618 return ir_gen_catch_unreachable(irb, parent_scope, node, op1_node, lval, result_loc);
8568 }9619 }
85699620
85709621
8571 IrInstruction *err_union_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr);9622 IrInstSrc *err_union_ptr = ir_gen_node_extra(irb, op1_node, parent_scope, LValPtr, nullptr);
8572 if (err_union_ptr == irb->codegen->invalid_instruction)9623 if (err_union_ptr == irb->codegen->invalid_inst_src)
8573 return irb->codegen->invalid_instruction;9624 return irb->codegen->invalid_inst_src;
85749625
8575 IrInstruction *is_err = ir_build_test_err_src(irb, parent_scope, node, err_union_ptr, true, false);9626 IrInstSrc *is_err = ir_build_test_err_src(irb, parent_scope, node, err_union_ptr, true, false);
85769627
8577 IrInstruction *is_comptime;9628 IrInstSrc *is_comptime;
8578 if (ir_should_inline(irb->exec, parent_scope)) {9629 if (ir_should_inline(irb->exec, parent_scope)) {
8579 is_comptime = ir_build_const_bool(irb, parent_scope, node, true);9630 is_comptime = ir_build_const_bool(irb, parent_scope, node, true);
8580 } else {9631 } else {
8581 is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_err);9632 is_comptime = ir_build_test_comptime(irb, parent_scope, node, is_err);
8582 }9633 }
85839634
8584 IrBasicBlock *ok_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrOk");9635 IrBasicBlockSrc *ok_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrOk");
8585 IrBasicBlock *err_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrError");9636 IrBasicBlockSrc *err_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrError");
8586 IrBasicBlock *end_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrEnd");9637 IrBasicBlockSrc *end_block = ir_create_basic_block(irb, parent_scope, "UnwrapErrEnd");
8587 IrInstruction *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_err, err_block, ok_block, is_comptime);9638 IrInstSrc *cond_br_inst = ir_build_cond_br(irb, parent_scope, node, is_err, err_block, ok_block, is_comptime);
85889639
8589 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, ok_block, end_block, result_loc,9640 ResultLocPeerParent *peer_parent = ir_build_binary_result_peers(irb, cond_br_inst, ok_block, end_block, result_loc,
8590 is_comptime);9641 is_comptime);
...@@ -8600,33 +9651,33 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode...@@ -8600,33 +9651,33 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode
8600 ZigVar *var = ir_create_var(irb, node, subexpr_scope, var_name,9651 ZigVar *var = ir_create_var(irb, node, subexpr_scope, var_name,
8601 is_const, is_const, is_shadowable, is_comptime);9652 is_const, is_const, is_shadowable, is_comptime);
8602 err_scope = var->child_scope;9653 err_scope = var->child_scope;
8603 IrInstruction *err_ptr = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr);9654 IrInstSrc *err_ptr = ir_build_unwrap_err_code_src(irb, err_scope, node, err_union_ptr);
8604 ir_build_var_decl_src(irb, err_scope, var_node, var, nullptr, err_ptr);9655 ir_build_var_decl_src(irb, err_scope, var_node, var, nullptr, err_ptr);
8605 } else {9656 } else {
8606 err_scope = subexpr_scope;9657 err_scope = subexpr_scope;
8607 }9658 }
8608 IrInstruction *err_result = ir_gen_node_extra(irb, op2_node, err_scope, LValNone, &peer_parent->peers.at(0)->base);9659 IrInstSrc *err_result = ir_gen_node_extra(irb, op2_node, err_scope, LValNone, &peer_parent->peers.at(0)->base);
8609 if (err_result == irb->codegen->invalid_instruction)9660 if (err_result == irb->codegen->invalid_inst_src)
8610 return irb->codegen->invalid_instruction;9661 return irb->codegen->invalid_inst_src;
8611 IrBasicBlock *after_err_block = irb->current_basic_block;9662 IrBasicBlockSrc *after_err_block = irb->current_basic_block;
8612 if (!instr_is_unreachable(err_result))9663 if (!instr_is_unreachable(err_result))
8613 ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime));9664 ir_mark_gen(ir_build_br(irb, parent_scope, node, end_block, is_comptime));
86149665
8615 ir_set_cursor_at_end_and_append_block(irb, ok_block);9666 ir_set_cursor_at_end_and_append_block(irb, ok_block);
8616 IrInstruction *unwrapped_ptr = ir_build_unwrap_err_payload(irb, parent_scope, node, err_union_ptr, false, false);9667 IrInstSrc *unwrapped_ptr = ir_build_unwrap_err_payload_src(irb, parent_scope, node, err_union_ptr, false, false);
8617 IrInstruction *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr);9668 IrInstSrc *unwrapped_payload = ir_build_load_ptr(irb, parent_scope, node, unwrapped_ptr);
8618 ir_build_end_expr(irb, parent_scope, node, unwrapped_payload, &peer_parent->peers.at(1)->base);9669 ir_build_end_expr(irb, parent_scope, node, unwrapped_payload, &peer_parent->peers.at(1)->base);
8619 IrBasicBlock *after_ok_block = irb->current_basic_block;9670 IrBasicBlockSrc *after_ok_block = irb->current_basic_block;
8620 ir_build_br(irb, parent_scope, node, end_block, is_comptime);9671 ir_build_br(irb, parent_scope, node, end_block, is_comptime);
86219672
8622 ir_set_cursor_at_end_and_append_block(irb, end_block);9673 ir_set_cursor_at_end_and_append_block(irb, end_block);
8623 IrInstruction **incoming_values = allocate<IrInstruction *>(2);9674 IrInstSrc **incoming_values = allocate<IrInstSrc *>(2);
8624 incoming_values[0] = err_result;9675 incoming_values[0] = err_result;
8625 incoming_values[1] = unwrapped_payload;9676 incoming_values[1] = unwrapped_payload;
8626 IrBasicBlock **incoming_blocks = allocate<IrBasicBlock *>(2, "IrBasicBlock *");9677 IrBasicBlockSrc **incoming_blocks = allocate<IrBasicBlockSrc *>(2, "IrBasicBlockSrc *");
8627 incoming_blocks[0] = after_err_block;9678 incoming_blocks[0] = after_err_block;
8628 incoming_blocks[1] = after_ok_block;9679 incoming_blocks[1] = after_ok_block;
8629 IrInstruction *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);9680 IrInstSrc *phi = ir_build_phi(irb, parent_scope, node, 2, incoming_blocks, incoming_values, peer_parent);
8630 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);9681 return ir_lval_wrap(irb, parent_scope, phi, lval, result_loc);
8631}9682}
86329683
...@@ -8644,7 +9695,7 @@ static bool render_instance_name_recursive(CodeGen *codegen, Buf *name, Scope *o...@@ -8644,7 +9695,7 @@ static bool render_instance_name_recursive(CodeGen *codegen, Buf *name, Scope *o
8644 return true;9695 return true;
8645}9696}
86469697
8647static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char *kind_name,9698static Buf *get_anon_type_name(CodeGen *codegen, IrExecutableSrc *exec, const char *kind_name,
8648 Scope *scope, AstNode *source_node, Buf *out_bare_name)9699 Scope *scope, AstNode *source_node, Buf *out_bare_name)
8649{9700{
8650 if (exec != nullptr && exec->name) {9701 if (exec != nullptr && exec->name) {
...@@ -8673,7 +9724,7 @@ static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char...@@ -8673,7 +9724,7 @@ static Buf *get_anon_type_name(CodeGen *codegen, IrExecutable *exec, const char
8673 }9724 }
8674}9725}
86759726
8676static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, AstNode *node) {9727static IrInstSrc *ir_gen_container_decl(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
8677 assert(node->type == NodeTypeContainerDecl);9728 assert(node->type == NodeTypeContainerDecl);
86789729
8679 ContainerKind kind = node->data.container_decl.kind;9730 ContainerKind kind = node->data.container_decl.kind;
...@@ -8798,7 +9849,7 @@ static AstNode *ast_field_to_symbol_node(AstNode *err_set_field_node) {...@@ -8798,7 +9849,7 @@ static AstNode *ast_field_to_symbol_node(AstNode *err_set_field_node) {
8798 }9849 }
8799}9850}
88009851
8801static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, AstNode *node) {9852static IrInstSrc *ir_gen_err_set_decl(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
8802 assert(node->type == NodeTypeErrorSetDecl);9853 assert(node->type == NodeTypeErrorSetDecl);
88039854
8804 uint32_t err_count = node->data.err_set_decl.decls.length;9855 uint32_t err_count = node->data.err_set_decl.decls.length;
...@@ -8841,7 +9892,7 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A...@@ -8841,7 +9892,7 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A
8841 buf_sprintf("duplicate error: '%s'", buf_ptr(&err->name)));9892 buf_sprintf("duplicate error: '%s'", buf_ptr(&err->name)));
8842 add_error_note(irb->codegen, msg, ast_field_to_symbol_node(prev_err->decl_node),9893 add_error_note(irb->codegen, msg, ast_field_to_symbol_node(prev_err->decl_node),
8843 buf_sprintf("other error here"));9894 buf_sprintf("other error here"));
8844 return irb->codegen->invalid_instruction;9895 return irb->codegen->invalid_inst_src;
8845 }9896 }
8846 errors[err->value] = err;9897 errors[err->value] = err;
8847 }9898 }
...@@ -8849,11 +9900,11 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A...@@ -8849,11 +9900,11 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A
8849 return ir_build_const_type(irb, parent_scope, node, err_set_type);9900 return ir_build_const_type(irb, parent_scope, node, err_set_type);
8850}9901}
88519902
8852static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNode *node) {9903static IrInstSrc *ir_gen_fn_proto(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
8853 assert(node->type == NodeTypeFnProto);9904 assert(node->type == NodeTypeFnProto);
88549905
8855 size_t param_count = node->data.fn_proto.params.length;9906 size_t param_count = node->data.fn_proto.params.length;
8856 IrInstruction **param_types = allocate<IrInstruction*>(param_count);9907 IrInstSrc **param_types = allocate<IrInstSrc*>(param_count);
88579908
8858 bool is_var_args = false;9909 bool is_var_args = false;
8859 for (size_t i = 0; i < param_count; i += 1) {9910 for (size_t i = 0; i < param_count; i += 1) {
...@@ -8864,59 +9915,59 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo...@@ -8864,59 +9915,59 @@ static IrInstruction *ir_gen_fn_proto(IrBuilder *irb, Scope *parent_scope, AstNo
8864 }9915 }
8865 if (param_node->data.param_decl.var_token == nullptr) {9916 if (param_node->data.param_decl.var_token == nullptr) {
8866 AstNode *type_node = param_node->data.param_decl.type;9917 AstNode *type_node = param_node->data.param_decl.type;
8867 IrInstruction *type_value = ir_gen_node(irb, type_node, parent_scope);9918 IrInstSrc *type_value = ir_gen_node(irb, type_node, parent_scope);
8868 if (type_value == irb->codegen->invalid_instruction)9919 if (type_value == irb->codegen->invalid_inst_src)
8869 return irb->codegen->invalid_instruction;9920 return irb->codegen->invalid_inst_src;
8870 param_types[i] = type_value;9921 param_types[i] = type_value;
8871 } else {9922 } else {
8872 param_types[i] = nullptr;9923 param_types[i] = nullptr;
8873 }9924 }
8874 }9925 }
88759926
8876 IrInstruction *align_value = nullptr;9927 IrInstSrc *align_value = nullptr;
8877 if (node->data.fn_proto.align_expr != nullptr) {9928 if (node->data.fn_proto.align_expr != nullptr) {
8878 align_value = ir_gen_node(irb, node->data.fn_proto.align_expr, parent_scope);9929 align_value = ir_gen_node(irb, node->data.fn_proto.align_expr, parent_scope);
8879 if (align_value == irb->codegen->invalid_instruction)9930 if (align_value == irb->codegen->invalid_inst_src)
8880 return irb->codegen->invalid_instruction;9931 return irb->codegen->invalid_inst_src;
8881 }9932 }
88829933
8883 IrInstruction *callconv_value = nullptr;9934 IrInstSrc *callconv_value = nullptr;
8884 if (node->data.fn_proto.callconv_expr != nullptr) {9935 if (node->data.fn_proto.callconv_expr != nullptr) {
8885 callconv_value = ir_gen_node(irb, node->data.fn_proto.callconv_expr, parent_scope);9936 callconv_value = ir_gen_node(irb, node->data.fn_proto.callconv_expr, parent_scope);
8886 if (callconv_value == irb->codegen->invalid_instruction)9937 if (callconv_value == irb->codegen->invalid_inst_src)
8887 return irb->codegen->invalid_instruction;9938 return irb->codegen->invalid_inst_src;
8888 }9939 }
88899940
8890 IrInstruction *return_type;9941 IrInstSrc *return_type;
8891 if (node->data.fn_proto.return_var_token == nullptr) {9942 if (node->data.fn_proto.return_var_token == nullptr) {
8892 if (node->data.fn_proto.return_type == nullptr) {9943 if (node->data.fn_proto.return_type == nullptr) {
8893 return_type = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_void);9944 return_type = ir_build_const_type(irb, parent_scope, node, irb->codegen->builtin_types.entry_void);
8894 } else {9945 } else {
8895 return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope);9946 return_type = ir_gen_node(irb, node->data.fn_proto.return_type, parent_scope);
8896 if (return_type == irb->codegen->invalid_instruction)9947 if (return_type == irb->codegen->invalid_inst_src)
8897 return irb->codegen->invalid_instruction;9948 return irb->codegen->invalid_inst_src;
8898 }9949 }
8899 } else {9950 } else {
8900 add_node_error(irb->codegen, node,9951 add_node_error(irb->codegen, node,
8901 buf_sprintf("TODO implement inferred return types https://github.com/ziglang/zig/issues/447"));9952 buf_sprintf("TODO implement inferred return types https://github.com/ziglang/zig/issues/447"));
8902 return irb->codegen->invalid_instruction;9953 return irb->codegen->invalid_inst_src;
8903 //return_type = nullptr;9954 //return_type = nullptr;
8904 }9955 }
89059956
8906 return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, callconv_value, return_type, is_var_args);9957 return ir_build_fn_proto(irb, parent_scope, node, param_types, align_value, callconv_value, return_type, is_var_args);
8907}9958}
89089959
8909static IrInstruction *ir_gen_resume(IrBuilder *irb, Scope *scope, AstNode *node) {9960static IrInstSrc *ir_gen_resume(IrBuilderSrc *irb, Scope *scope, AstNode *node) {
8910 assert(node->type == NodeTypeResume);9961 assert(node->type == NodeTypeResume);
89119962
8912 IrInstruction *target_inst = ir_gen_node_extra(irb, node->data.resume_expr.expr, scope, LValPtr, nullptr);9963 IrInstSrc *target_inst = ir_gen_node_extra(irb, node->data.resume_expr.expr, scope, LValPtr, nullptr);
8913 if (target_inst == irb->codegen->invalid_instruction)9964 if (target_inst == irb->codegen->invalid_inst_src)
8914 return irb->codegen->invalid_instruction;9965 return irb->codegen->invalid_inst_src;
89159966
8916 return ir_build_resume(irb, scope, node, target_inst);9967 return ir_build_resume_src(irb, scope, node, target_inst);
8917}9968}
89189969
8919static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval,9970static IrInstSrc *ir_gen_await_expr(IrBuilderSrc *irb, Scope *scope, AstNode *node, LVal lval,
8920 ResultLoc *result_loc)9971 ResultLoc *result_loc)
8921{9972{
8922 assert(node->type == NodeTypeAwaitExpr);9973 assert(node->type == NodeTypeAwaitExpr);
...@@ -8937,7 +9988,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -8937,7 +9988,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
8937 ZigFn *fn_entry = exec_fn_entry(irb->exec);9988 ZigFn *fn_entry = exec_fn_entry(irb->exec);
8938 if (!fn_entry) {9989 if (!fn_entry) {
8939 add_node_error(irb->codegen, node, buf_sprintf("await outside function definition"));9990 add_node_error(irb->codegen, node, buf_sprintf("await outside function definition"));
8940 return irb->codegen->invalid_instruction;9991 return irb->codegen->invalid_inst_src;
8941 }9992 }
8942 ScopeSuspend *existing_suspend_scope = get_scope_suspend(scope);9993 ScopeSuspend *existing_suspend_scope = get_scope_suspend(scope);
8943 if (existing_suspend_scope) {9994 if (existing_suspend_scope) {
...@@ -8946,24 +9997,24 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n...@@ -8946,24 +9997,24 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
8946 add_error_note(irb->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("suspend block here"));9997 add_error_note(irb->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("suspend block here"));
8947 existing_suspend_scope->reported_err = true;9998 existing_suspend_scope->reported_err = true;
8948 }9999 }
8949 return irb->codegen->invalid_instruction;10000 return irb->codegen->invalid_inst_src;
8950 }10001 }
895110002
8952 IrInstruction *target_inst = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);10003 IrInstSrc *target_inst = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
8953 if (target_inst == irb->codegen->invalid_instruction)10004 if (target_inst == irb->codegen->invalid_inst_src)
8954 return irb->codegen->invalid_instruction;10005 return irb->codegen->invalid_inst_src;
895510006
8956 IrInstruction *await_inst = ir_build_await_src(irb, scope, node, target_inst, result_loc);10007 IrInstSrc *await_inst = ir_build_await_src(irb, scope, node, target_inst, result_loc);
8957 return ir_lval_wrap(irb, scope, await_inst, lval, result_loc);10008 return ir_lval_wrap(irb, scope, await_inst, lval, result_loc);
8958}10009}
895910010
8960static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNode *node) {10011static IrInstSrc *ir_gen_suspend(IrBuilderSrc *irb, Scope *parent_scope, AstNode *node) {
8961 assert(node->type == NodeTypeSuspend);10012 assert(node->type == NodeTypeSuspend);
896210013
8963 ZigFn *fn_entry = exec_fn_entry(irb->exec);10014 ZigFn *fn_entry = exec_fn_entry(irb->exec);
8964 if (!fn_entry) {10015 if (!fn_entry) {
8965 add_node_error(irb->codegen, node, buf_sprintf("suspend outside function definition"));10016 add_node_error(irb->codegen, node, buf_sprintf("suspend outside function definition"));
8966 return irb->codegen->invalid_instruction;10017 return irb->codegen->invalid_inst_src;
8967 }10018 }
8968 ScopeSuspend *existing_suspend_scope = get_scope_suspend(parent_scope);10019 ScopeSuspend *existing_suspend_scope = get_scope_suspend(parent_scope);
8969 if (existing_suspend_scope) {10020 if (existing_suspend_scope) {
...@@ -8972,21 +10023,21 @@ static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNod...@@ -8972,21 +10023,21 @@ static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNod
8972 add_error_note(irb->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("other suspend block here"));10023 add_error_note(irb->codegen, msg, existing_suspend_scope->base.source_node, buf_sprintf("other suspend block here"));
8973 existing_suspend_scope->reported_err = true;10024 existing_suspend_scope->reported_err = true;
8974 }10025 }
8975 return irb->codegen->invalid_instruction;10026 return irb->codegen->invalid_inst_src;
8976 }10027 }
897710028
8978 IrInstructionSuspendBegin *begin = ir_build_suspend_begin(irb, parent_scope, node);10029 IrInstSrcSuspendBegin *begin = ir_build_suspend_begin_src(irb, parent_scope, node);
8979 if (node->data.suspend.block != nullptr) {10030 if (node->data.suspend.block != nullptr) {
8980 ScopeSuspend *suspend_scope = create_suspend_scope(irb->codegen, node, parent_scope);10031 ScopeSuspend *suspend_scope = create_suspend_scope(irb->codegen, node, parent_scope);
8981 Scope *child_scope = &suspend_scope->base;10032 Scope *child_scope = &suspend_scope->base;
8982 IrInstruction *susp_res = ir_gen_node(irb, node->data.suspend.block, child_scope);10033 IrInstSrc *susp_res = ir_gen_node(irb, node->data.suspend.block, child_scope);
8983 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.suspend.block, susp_res));10034 ir_mark_gen(ir_build_check_statement_is_void(irb, child_scope, node->data.suspend.block, susp_res));
8984 }10035 }
898510036
8986 return ir_mark_gen(ir_build_suspend_finish(irb, parent_scope, node, begin));10037 return ir_mark_gen(ir_build_suspend_finish_src(irb, parent_scope, node, begin));
8987}10038}
898810039
8989static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scope,10040static IrInstSrc *ir_gen_node_raw(IrBuilderSrc *irb, AstNode *node, Scope *scope,
8990 LVal lval, ResultLoc *result_loc)10041 LVal lval, ResultLoc *result_loc)
8991{10042{
8992 assert(scope);10043 assert(scope);
...@@ -9035,39 +10086,39 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop...@@ -9035,39 +10086,39 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
9035 return ir_gen_return(irb, scope, node, lval, result_loc);10086 return ir_gen_return(irb, scope, node, lval, result_loc);
9036 case NodeTypeFieldAccessExpr:10087 case NodeTypeFieldAccessExpr:
9037 {10088 {
9038 IrInstruction *ptr_instruction = ir_gen_field_access(irb, scope, node);10089 IrInstSrc *ptr_instruction = ir_gen_field_access(irb, scope, node);
9039 if (ptr_instruction == irb->codegen->invalid_instruction)10090 if (ptr_instruction == irb->codegen->invalid_inst_src)
9040 return ptr_instruction;10091 return ptr_instruction;
9041 if (lval == LValPtr)10092 if (lval == LValPtr)
9042 return ptr_instruction;10093 return ptr_instruction;
904310094
9044 IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);10095 IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, ptr_instruction);
9045 return ir_expr_wrap(irb, scope, load_ptr, result_loc);10096 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
9046 }10097 }
9047 case NodeTypePtrDeref: {10098 case NodeTypePtrDeref: {
9048 AstNode *expr_node = node->data.ptr_deref_expr.target;10099 AstNode *expr_node = node->data.ptr_deref_expr.target;
9049 IrInstruction *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr);10100 IrInstSrc *value = ir_gen_node_extra(irb, expr_node, scope, lval, nullptr);
9050 if (value == irb->codegen->invalid_instruction)10101 if (value == irb->codegen->invalid_inst_src)
9051 return value;10102 return value;
905210103
9053 // We essentially just converted any lvalue from &(x.*) to (&x).*;10104 // We essentially just converted any lvalue from &(x.*) to (&x).*;
9054 // this inhibits checking that x is a pointer later, so we directly10105 // this inhibits checking that x is a pointer later, so we directly
9055 // record whether the pointer check is needed10106 // record whether the pointer check is needed
9056 IrInstruction *un_op = ir_build_un_op_lval(irb, scope, node, IrUnOpDereference, value, lval, result_loc);10107 IrInstSrc *un_op = ir_build_un_op_lval(irb, scope, node, IrUnOpDereference, value, lval, result_loc);
9057 return ir_expr_wrap(irb, scope, un_op, result_loc);10108 return ir_expr_wrap(irb, scope, un_op, result_loc);
9058 }10109 }
9059 case NodeTypeUnwrapOptional: {10110 case NodeTypeUnwrapOptional: {
9060 AstNode *expr_node = node->data.unwrap_optional.expr;10111 AstNode *expr_node = node->data.unwrap_optional.expr;
906110112
9062 IrInstruction *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);10113 IrInstSrc *maybe_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr);
9063 if (maybe_ptr == irb->codegen->invalid_instruction)10114 if (maybe_ptr == irb->codegen->invalid_inst_src)
9064 return irb->codegen->invalid_instruction;10115 return irb->codegen->invalid_inst_src;
906510116
9066 IrInstruction *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, scope, node, maybe_ptr, true, false);10117 IrInstSrc *unwrapped_ptr = ir_build_optional_unwrap_ptr(irb, scope, node, maybe_ptr, true, false);
9067 if (lval == LValPtr)10118 if (lval == LValPtr)
9068 return unwrapped_ptr;10119 return unwrapped_ptr;
906910120
9070 IrInstruction *load_ptr = ir_build_load_ptr(irb, scope, node, unwrapped_ptr);10121 IrInstSrc *load_ptr = ir_build_load_ptr(irb, scope, node, unwrapped_ptr);
9071 return ir_expr_wrap(irb, scope, load_ptr, result_loc);10122 return ir_expr_wrap(irb, scope, load_ptr, result_loc);
9072 }10123 }
9073 case NodeTypeBoolLiteral:10124 case NodeTypeBoolLiteral:
...@@ -9125,7 +10176,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop...@@ -9125,7 +10176,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
9125 case NodeTypeInferredArrayType:10176 case NodeTypeInferredArrayType:
9126 add_node_error(irb->codegen, node,10177 add_node_error(irb->codegen, node,
9127 buf_sprintf("inferred array size invalid here"));10178 buf_sprintf("inferred array size invalid here"));
9128 return irb->codegen->invalid_instruction;10179 return irb->codegen->invalid_inst_src;
9129 case NodeTypeVarFieldType:10180 case NodeTypeVarFieldType:
9130 return ir_lval_wrap(irb, scope,10181 return ir_lval_wrap(irb, scope,
9131 ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_var), lval, result_loc);10182 ir_build_const_type(irb, scope, node, irb->codegen->builtin_types.entry_var), lval, result_loc);
...@@ -9139,7 +10190,7 @@ static ResultLoc *no_result_loc(void) {...@@ -9139,7 +10190,7 @@ static ResultLoc *no_result_loc(void) {
9139 return &result_loc_none->base;10190 return &result_loc_none->base;
9140}10191}
914110192
9142static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval,10193static IrInstSrc *ir_gen_node_extra(IrBuilderSrc *irb, AstNode *node, Scope *scope, LVal lval,
9143 ResultLoc *result_loc)10194 ResultLoc *result_loc)
9144{10195{
9145 if (result_loc == nullptr) {10196 if (result_loc == nullptr) {
...@@ -9156,8 +10207,8 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc...@@ -9156,8 +10207,8 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc
9156 } else {10207 } else {
9157 child_scope = &create_expr_scope(irb->codegen, node, scope)->base;10208 child_scope = &create_expr_scope(irb->codegen, node, scope)->base;
9158 }10209 }
9159 IrInstruction *result = ir_gen_node_raw(irb, node, child_scope, lval, result_loc);10210 IrInstSrc *result = ir_gen_node_raw(irb, node, child_scope, lval, result_loc);
9160 if (result == irb->codegen->invalid_instruction) {10211 if (result == irb->codegen->invalid_inst_src) {
9161 if (irb->exec->first_err_trace_msg == nullptr) {10212 if (irb->exec->first_err_trace_msg == nullptr) {
9162 irb->exec->first_err_trace_msg = irb->codegen->trace_err;10213 irb->exec->first_err_trace_msg = irb->codegen->trace_err;
9163 }10214 }
...@@ -9165,11 +10216,22 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc...@@ -9165,11 +10216,22 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc
9165 return result;10216 return result;
9166}10217}
916710218
9168static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope) {10219static IrInstSrc *ir_gen_node(IrBuilderSrc *irb, AstNode *node, Scope *scope) {
9169 return ir_gen_node_extra(irb, node, scope, LValNone, nullptr);10220 return ir_gen_node_extra(irb, node, scope, LValNone, nullptr);
9170}10221}
917110222
9172static void invalidate_exec(IrExecutable *exec, ErrorMsg *msg) {10223static void invalidate_exec(IrExecutableSrc *exec, ErrorMsg *msg) {
10224 if (exec->first_err_trace_msg != nullptr)
10225 return;
10226
10227 exec->first_err_trace_msg = msg;
10228
10229 for (size_t i = 0; i < exec->tld_list.length; i += 1) {
10230 exec->tld_list.items[i]->resolution = TldResolutionInvalid;
10231 }
10232}
10233
10234static void invalidate_exec_gen(IrExecutableGen *exec, ErrorMsg *msg) {
9173 if (exec->first_err_trace_msg != nullptr)10235 if (exec->first_err_trace_msg != nullptr)
9174 return;10236 return;
917510237
...@@ -9183,24 +10245,25 @@ static void invalidate_exec(IrExecutable *exec, ErrorMsg *msg) {...@@ -9183,24 +10245,25 @@ static void invalidate_exec(IrExecutable *exec, ErrorMsg *msg) {
9183 invalidate_exec(exec->source_exec, msg);10245 invalidate_exec(exec->source_exec, msg);
9184}10246}
918510247
9186bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_executable) {10248
10249bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutableSrc *ir_executable) {
9187 assert(node->owner);10250 assert(node->owner);
918810251
9189 IrBuilder ir_builder = {0};10252 IrBuilderSrc ir_builder = {0};
9190 IrBuilder *irb = &ir_builder;10253 IrBuilderSrc *irb = &ir_builder;
919110254
9192 irb->codegen = codegen;10255 irb->codegen = codegen;
9193 irb->exec = ir_executable;10256 irb->exec = ir_executable;
9194 irb->main_block_node = node;10257 irb->main_block_node = node;
919510258
9196 IrBasicBlock *entry_block = ir_create_basic_block(irb, scope, "Entry");10259 IrBasicBlockSrc *entry_block = ir_create_basic_block(irb, scope, "Entry");
9197 ir_set_cursor_at_end_and_append_block(irb, entry_block);10260 ir_set_cursor_at_end_and_append_block(irb, entry_block);
9198 // Entry block gets a reference because we enter it to begin.10261 // Entry block gets a reference because we enter it to begin.
9199 ir_ref_bb(irb->current_basic_block);10262 ir_ref_bb(irb->current_basic_block);
920010263
9201 IrInstruction *result = ir_gen_node_extra(irb, node, scope, LValNone, nullptr);10264 IrInstSrc *result = ir_gen_node_extra(irb, node, scope, LValNone, nullptr);
920210265
9203 if (result == irb->codegen->invalid_instruction)10266 if (result == irb->codegen->invalid_inst_src)
9204 return false;10267 return false;
920510268
9206 if (irb->exec->first_err_trace_msg != nullptr) {10269 if (irb->exec->first_err_trace_msg != nullptr) {
...@@ -9209,9 +10272,13 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -9209,9 +10272,13 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
9209 }10272 }
921010273
9211 if (!instr_is_unreachable(result)) {10274 if (!instr_is_unreachable(result)) {
9212 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->source_node, result, nullptr));10275 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->base.source_node, result, nullptr));
9213 // no need for save_err_ret_addr because this cannot return error10276 // no need for save_err_ret_addr because this cannot return error
9214 ir_mark_gen(ir_build_return(irb, scope, result->source_node, result));10277 ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1, "ResultLocReturn");
10278 result_loc_ret->base.id = ResultLocIdReturn;
10279 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);
10280 ir_mark_gen(ir_build_end_expr(irb, scope, node, result, &result_loc_ret->base));
10281 ir_mark_gen(ir_build_return_src(irb, scope, result->base.source_node, result));
9215 }10282 }
921610283
9217 return true;10284 return true;
...@@ -9220,7 +10287,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec...@@ -9220,7 +10287,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
9220bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) {10287bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) {
9221 assert(fn_entry);10288 assert(fn_entry);
922210289
9223 IrExecutable *ir_executable = fn_entry->ir_executable;10290 IrExecutableSrc *ir_executable = fn_entry->ir_executable;
9224 AstNode *body_node = fn_entry->body_node;10291 AstNode *body_node = fn_entry->body_node;
922510292
9226 assert(fn_entry->child_scope);10293 assert(fn_entry->child_scope);
...@@ -9228,14 +10295,21 @@ bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) {...@@ -9228,14 +10295,21 @@ bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) {
9228 return ir_gen(codegen, body_node, fn_entry->child_scope, ir_executable);10295 return ir_gen(codegen, body_node, fn_entry->child_scope, ir_executable);
9229}10296}
923010297
9231static void ir_add_call_stack_errors(CodeGen *codegen, IrExecutable *exec, ErrorMsg *err_msg, int limit) {10298static void ir_add_call_stack_errors_gen(CodeGen *codegen, IrExecutableGen *exec, ErrorMsg *err_msg, int limit) {
10299 if (!exec || !exec->source_node || limit < 0) return;
10300 add_error_note(codegen, err_msg, exec->source_node, buf_sprintf("called from here"));
10301
10302 ir_add_call_stack_errors_gen(codegen, exec->parent_exec, err_msg, limit - 1);
10303}
10304
10305static void ir_add_call_stack_errors(CodeGen *codegen, IrExecutableSrc *exec, ErrorMsg *err_msg, int limit) {
9232 if (!exec || !exec->source_node || limit < 0) return;10306 if (!exec || !exec->source_node || limit < 0) return;
9233 add_error_note(codegen, err_msg, exec->source_node, buf_sprintf("called from here"));10307 add_error_note(codegen, err_msg, exec->source_node, buf_sprintf("called from here"));
923410308
9235 ir_add_call_stack_errors(codegen, exec->parent_exec, err_msg, limit - 1);10309 ir_add_call_stack_errors_gen(codegen, exec->parent_exec, err_msg, limit - 1);
9236}10310}
923710311
9238static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg) {10312static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutableSrc *exec, AstNode *source_node, Buf *msg) {
9239 ErrorMsg *err_msg = add_node_error(codegen, source_node, msg);10313 ErrorMsg *err_msg = add_node_error(codegen, source_node, msg);
9240 invalidate_exec(exec, err_msg);10314 invalidate_exec(exec, err_msg);
9241 if (exec->parent_exec) {10315 if (exec->parent_exec) {
...@@ -9244,26 +10318,40 @@ static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNo...@@ -9244,26 +10318,40 @@ static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNo
9244 return err_msg;10318 return err_msg;
9245}10319}
924610320
10321static ErrorMsg *exec_add_error_node_gen(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node, Buf *msg) {
10322 ErrorMsg *err_msg = add_node_error(codegen, source_node, msg);
10323 invalidate_exec_gen(exec, err_msg);
10324 if (exec->parent_exec) {
10325 ir_add_call_stack_errors_gen(codegen, exec, err_msg, 10);
10326 }
10327 return err_msg;
10328}
10329
9247static ErrorMsg *ir_add_error_node(IrAnalyze *ira, AstNode *source_node, Buf *msg) {10330static ErrorMsg *ir_add_error_node(IrAnalyze *ira, AstNode *source_node, Buf *msg) {
9248 return exec_add_error_node(ira->codegen, ira->new_irb.exec, source_node, msg);10331 return exec_add_error_node_gen(ira->codegen, ira->new_irb.exec, source_node, msg);
9249}10332}
925010333
9251static ErrorMsg *opt_ir_add_error_node(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, Buf *msg) {10334static ErrorMsg *opt_ir_add_error_node(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, Buf *msg) {
9252 if (ira != nullptr)10335 if (ira != nullptr)
9253 return exec_add_error_node(codegen, ira->new_irb.exec, source_node, msg);10336 return exec_add_error_node_gen(codegen, ira->new_irb.exec, source_node, msg);
9254 else10337 else
9255 return add_node_error(codegen, source_node, msg);10338 return add_node_error(codegen, source_node, msg);
9256}10339}
925710340
9258static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, Buf *msg) {10341static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInst *source_instruction, Buf *msg) {
9259 return ir_add_error_node(ira, source_instruction->source_node, msg);10342 return ir_add_error_node(ira, source_instruction->source_node, msg);
9260}10343}
926110344
9262static void ir_assert(bool ok, IrInstruction *source_instruction) {10345static void ir_assert(bool ok, IrInst *source_instruction) {
9263 if (ok) return;10346 if (ok) return;
9264 src_assert(ok, source_instruction->source_node);10347 src_assert(ok, source_instruction->source_node);
9265}10348}
926610349
10350static void ir_assert_gen(bool ok, IrInstGen *source_instruction) {
10351 if (ok) return;
10352 src_assert(ok, source_instruction->base.source_node);
10353}
10354
9267// This function takes a comptime ptr and makes the child const value conform to the type10355// This function takes a comptime ptr and makes the child const value conform to the type
9268// described by the pointer.10356// described by the pointer.
9269static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,10357static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node,
...@@ -9309,43 +10397,37 @@ ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_va...@@ -9309,43 +10397,37 @@ ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_va
9309 return val;10397 return val;
9310}10398}
931110399
9312static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) {10400static Error ir_exec_scan_for_side_effects(CodeGen *codegen, IrExecutableGen *exec) {
9313 IrBasicBlock *bb = exec->basic_block_list.at(0);10401 IrBasicBlockGen *bb = exec->basic_block_list.at(0);
9314 for (size_t i = 0; i < bb->instruction_list.length; i += 1) {10402 for (size_t i = 0; i < bb->instruction_list.length; i += 1) {
9315 IrInstruction *instruction = bb->instruction_list.at(i);10403 IrInstGen *instruction = bb->instruction_list.at(i);
9316 if (instruction->id == IrInstructionIdReturn) {10404 if (instruction->id == IrInstGenIdReturn) {
9317 IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction;10405 return ErrorNone;
9318 IrInstruction *operand = ret_inst->operand;10406 } else if (ir_inst_gen_has_side_effects(instruction)) {
9319 if (operand->value->special == ConstValSpecialRuntime) {
9320 exec_add_error_node(codegen, exec, operand->source_node,
9321 buf_sprintf("unable to evaluate constant expression"));
9322 return codegen->invalid_instruction->value;
9323 }
9324 return operand->value;
9325 } else if (ir_has_side_effects(instruction)) {
9326 if (instr_is_comptime(instruction)) {10407 if (instr_is_comptime(instruction)) {
9327 switch (instruction->id) {10408 switch (instruction->id) {
9328 case IrInstructionIdUnwrapErrPayload:10409 case IrInstGenIdUnwrapErrPayload:
9329 case IrInstructionIdUnionFieldPtr:10410 case IrInstGenIdOptionalUnwrapPtr:
10411 case IrInstGenIdUnionFieldPtr:
9330 continue;10412 continue;
9331 default:10413 default:
9332 break;10414 break;
9333 }10415 }
9334 }10416 }
9335 if (get_scope_typeof(instruction->scope) != nullptr) {10417 if (get_scope_typeof(instruction->base.scope) != nullptr) {
9336 // doesn't count, it's inside a @TypeOf()10418 // doesn't count, it's inside a @TypeOf()
9337 continue;10419 continue;
9338 }10420 }
9339 exec_add_error_node(codegen, exec, instruction->source_node,10421 exec_add_error_node_gen(codegen, exec, instruction->base.source_node,
9340 buf_sprintf("unable to evaluate constant expression"));10422 buf_sprintf("unable to evaluate constant expression"));
9341 return codegen->invalid_instruction->value;10423 return ErrorSemanticAnalyzeFail;
9342 }10424 }
9343 }10425 }
9344 zig_unreachable();10426 zig_unreachable();
9345}10427}
934610428
9347static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *source_instruction) {10429static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInst* source_instruction) {
9348 if (ir_should_inline(ira->new_irb.exec, source_instruction->scope)) {10430 if (ir_should_inline(ira->old_irb.exec, source_instruction->scope)) {
9349 ir_add_error(ira, source_instruction, buf_sprintf("unable to evaluate constant expression"));10431 ir_add_error(ira, source_instruction, buf_sprintf("unable to evaluate constant expression"));
9350 return false;10432 return false;
9351 }10433 }
...@@ -10079,7 +11161,39 @@ void float_read_ieee597(ZigValue *val, uint8_t *buf, bool is_big_endian) {...@@ -10079,7 +11161,39 @@ void float_read_ieee597(ZigValue *val, uint8_t *buf, bool is_big_endian) {
10079 }11161 }
10080}11162}
1008111163
10082static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruction, ZigType *other_type,11164static void value_to_bigfloat(BigFloat *out, ZigValue *val) {
11165 switch (val->type->id) {
11166 case ZigTypeIdInt:
11167 case ZigTypeIdComptimeInt:
11168 bigfloat_init_bigint(out, &val->data.x_bigint);
11169 return;
11170 case ZigTypeIdComptimeFloat:
11171 *out = val->data.x_bigfloat;
11172 return;
11173 case ZigTypeIdFloat: switch (val->type->data.floating.bit_count) {
11174 case 16:
11175 bigfloat_init_16(out, val->data.x_f16);
11176 return;
11177 case 32:
11178 bigfloat_init_32(out, val->data.x_f32);
11179 return;
11180 case 64:
11181 bigfloat_init_64(out, val->data.x_f64);
11182 return;
11183 case 80:
11184 zig_panic("TODO");
11185 case 128:
11186 bigfloat_init_128(out, val->data.x_f128);
11187 return;
11188 default:
11189 zig_unreachable();
11190 }
11191 default:
11192 zig_unreachable();
11193 }
11194}
11195
11196static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstGen *instruction, ZigType *other_type,
10083 bool explicit_cast)11197 bool explicit_cast)
10084{11198{
10085 if (type_is_invalid(other_type)) {11199 if (type_is_invalid(other_type)) {
...@@ -10173,7 +11287,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -10173,7 +11287,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
10173 }11287 }
10174 Buf *val_buf = buf_alloc();11288 Buf *val_buf = buf_alloc();
10175 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);11289 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
10176 ir_add_error(ira, instruction,11290 ir_add_error_node(ira, instruction->base.source_node,
10177 buf_sprintf("integer value %s has no representation in type '%s'",11291 buf_sprintf("integer value %s has no representation in type '%s'",
10178 buf_ptr(val_buf),11292 buf_ptr(val_buf),
10179 buf_ptr(&other_type->name)));11293 buf_ptr(&other_type->name)));
...@@ -10268,7 +11382,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -10268,7 +11382,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
10268 }11382 }
10269 Buf *val_buf = buf_alloc();11383 Buf *val_buf = buf_alloc();
10270 float_append_buf(val_buf, const_val);11384 float_append_buf(val_buf, const_val);
10271 ir_add_error(ira, instruction,11385 ir_add_error_node(ira, instruction->base.source_node,
10272 buf_sprintf("cast of value %s to type '%s' loses information",11386 buf_sprintf("cast of value %s to type '%s' loses information",
10273 buf_ptr(val_buf),11387 buf_ptr(val_buf),
10274 buf_ptr(&other_type->name)));11388 buf_ptr(&other_type->name)));
...@@ -10277,7 +11391,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -10277,7 +11391,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
10277 if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {11391 if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {
10278 Buf *val_buf = buf_alloc();11392 Buf *val_buf = buf_alloc();
10279 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);11393 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
10280 ir_add_error(ira, instruction,11394 ir_add_error_node(ira, instruction->base.source_node,
10281 buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'",11395 buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'",
10282 buf_ptr(val_buf),11396 buf_ptr(val_buf),
10283 buf_ptr(&other_type->name)));11397 buf_ptr(&other_type->name)));
...@@ -10298,7 +11412,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -10298,7 +11412,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
10298 if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {11412 if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) {
10299 Buf *val_buf = buf_alloc();11413 Buf *val_buf = buf_alloc();
10300 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);11414 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
10301 ir_add_error(ira, instruction,11415 ir_add_error_node(ira, instruction->base.source_node,
10302 buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'",11416 buf_sprintf("cannot cast negative value %s to unsigned integer type '%s'",
10303 buf_ptr(val_buf),11417 buf_ptr(val_buf),
10304 buf_ptr(&child_type->name)));11418 buf_ptr(&child_type->name)));
...@@ -10321,7 +11435,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -10321,7 +11435,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
10321 Buf *val_buf = buf_alloc();11435 Buf *val_buf = buf_alloc();
10322 float_append_buf(val_buf, const_val);11436 float_append_buf(val_buf, const_val);
1032311437
10324 ir_add_error(ira, instruction,11438 ir_add_error_node(ira, instruction->base.source_node,
10325 buf_sprintf("fractional component prevents float value %s from being casted to type '%s'",11439 buf_sprintf("fractional component prevents float value %s from being casted to type '%s'",
10326 buf_ptr(val_buf),11440 buf_ptr(val_buf),
10327 buf_ptr(&other_type->name)));11441 buf_ptr(&other_type->name)));
...@@ -10351,7 +11465,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc...@@ -10351,7 +11465,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
10351 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);11465 bigint_append_buf(val_buf, &const_val->data.x_bigint, 10);
10352 }11466 }
1035311467
10354 ir_add_error(ira, instruction,11468 ir_add_error_node(ira, instruction->base.source_node,
10355 buf_sprintf("%s value %s cannot be coerced to type '%s'",11469 buf_sprintf("%s value %s cannot be coerced to type '%s'",
10356 num_lit_str,11470 num_lit_str,
10357 buf_ptr(val_buf),11471 buf_ptr(val_buf),
...@@ -10805,11 +11919,11 @@ static void update_errors_helper(CodeGen *g, ErrorTableEntry ***errors, size_t *...@@ -10805,11 +11919,11 @@ static void update_errors_helper(CodeGen *g, ErrorTableEntry ***errors, size_t *
10805}11919}
1080611920
10807static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigType *expected_type,11921static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigType *expected_type,
10808 IrInstruction **instructions, size_t instruction_count)11922 IrInstGen **instructions, size_t instruction_count)
10809{11923{
10810 Error err;11924 Error err;
10811 assert(instruction_count >= 1);11925 assert(instruction_count >= 1);
10812 IrInstruction *prev_inst;11926 IrInstGen *prev_inst;
10813 size_t i = 0;11927 size_t i = 0;
10814 for (;;) {11928 for (;;) {
10815 prev_inst = instructions[i];11929 prev_inst = instructions[i];
...@@ -10829,7 +11943,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10829,7 +11943,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10829 size_t errors_count = 0;11943 size_t errors_count = 0;
10830 ZigType *err_set_type = nullptr;11944 ZigType *err_set_type = nullptr;
10831 if (prev_inst->value->type->id == ZigTypeIdErrorSet) {11945 if (prev_inst->value->type->id == ZigTypeIdErrorSet) {
10832 if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->source_node)) {11946 if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->base.source_node)) {
10833 return ira->codegen->builtin_types.entry_invalid;11947 return ira->codegen->builtin_types.entry_invalid;
10834 }11948 }
10835 if (type_is_global_error_set(prev_inst->value->type)) {11949 if (type_is_global_error_set(prev_inst->value->type)) {
...@@ -10849,7 +11963,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10849,7 +11963,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10849 bool any_are_null = (prev_inst->value->type->id == ZigTypeIdNull);11963 bool any_are_null = (prev_inst->value->type->id == ZigTypeIdNull);
10850 bool convert_to_const_slice = false;11964 bool convert_to_const_slice = false;
10851 for (; i < instruction_count; i += 1) {11965 for (; i < instruction_count; i += 1) {
10852 IrInstruction *cur_inst = instructions[i];11966 IrInstGen *cur_inst = instructions[i];
10853 ZigType *cur_type = cur_inst->value->type;11967 ZigType *cur_type = cur_inst->value->type;
10854 ZigType *prev_type = prev_inst->value->type;11968 ZigType *prev_type = prev_inst->value->type;
1085511969
...@@ -10871,14 +11985,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10871,14 +11985,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10871 }11985 }
1087211986
10873 if (prev_type->id == ZigTypeIdErrorSet) {11987 if (prev_type->id == ZigTypeIdErrorSet) {
10874 ir_assert(err_set_type != nullptr, prev_inst);11988 ir_assert_gen(err_set_type != nullptr, prev_inst);
10875 if (cur_type->id == ZigTypeIdErrorSet) {11989 if (cur_type->id == ZigTypeIdErrorSet) {
10876 if (type_is_global_error_set(err_set_type)) {11990 if (type_is_global_error_set(err_set_type)) {
10877 continue;11991 continue;
10878 }11992 }
10879 bool allow_infer = cur_type->data.error_set.infer_fn != nullptr &&11993 bool allow_infer = cur_type->data.error_set.infer_fn != nullptr &&
10880 cur_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;11994 cur_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;
10881 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) {11995 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->base.source_node)) {
10882 return ira->codegen->builtin_types.entry_invalid;11996 return ira->codegen->builtin_types.entry_invalid;
10883 }11997 }
10884 if (!allow_infer && type_is_global_error_set(cur_type)) {11998 if (!allow_infer && type_is_global_error_set(cur_type)) {
...@@ -10946,7 +12060,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -10946,7 +12060,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
10946 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;12060 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;
10947 bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr &&12061 bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr &&
10948 cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;12062 cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;
10949 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {12063 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) {
10950 return ira->codegen->builtin_types.entry_invalid;12064 return ira->codegen->builtin_types.entry_invalid;
10951 }12065 }
10952 if (!allow_infer && type_is_global_error_set(cur_err_set_type)) {12066 if (!allow_infer && type_is_global_error_set(cur_err_set_type)) {
...@@ -11001,7 +12115,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -11001,7 +12115,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
11001 if (cur_type->id == ZigTypeIdErrorSet) {12115 if (cur_type->id == ZigTypeIdErrorSet) {
11002 bool allow_infer = cur_type->data.error_set.infer_fn != nullptr &&12116 bool allow_infer = cur_type->data.error_set.infer_fn != nullptr &&
11003 cur_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;12117 cur_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;
11004 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->source_node)) {12118 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_type, cur_inst->base.source_node)) {
11005 return ira->codegen->builtin_types.entry_invalid;12119 return ira->codegen->builtin_types.entry_invalid;
11006 }12120 }
11007 if (!allow_infer && type_is_global_error_set(cur_type)) {12121 if (!allow_infer && type_is_global_error_set(cur_type)) {
...@@ -11024,7 +12138,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -11024,7 +12138,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
11024 err_set_type = cur_type;12138 err_set_type = cur_type;
11025 }12139 }
1102612140
11027 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, err_set_type, cur_inst->source_node)) {12141 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, err_set_type, cur_inst->base.source_node)) {
11028 return ira->codegen->builtin_types.entry_invalid;12142 return ira->codegen->builtin_types.entry_invalid;
11029 }12143 }
1103012144
...@@ -11087,11 +12201,11 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -11087,11 +12201,11 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
11087 bool allow_infer_cur = cur_err_set_type->data.error_set.infer_fn != nullptr &&12201 bool allow_infer_cur = cur_err_set_type->data.error_set.infer_fn != nullptr &&
11088 cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;12202 cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;
1108912203
11090 if (!allow_infer_prev && !resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->source_node)) {12204 if (!allow_infer_prev && !resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->base.source_node)) {
11091 return ira->codegen->builtin_types.entry_invalid;12205 return ira->codegen->builtin_types.entry_invalid;
11092 }12206 }
1109312207
11094 if (!allow_infer_cur && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {12208 if (!allow_infer_cur && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) {
11095 return ira->codegen->builtin_types.entry_invalid;12209 return ira->codegen->builtin_types.entry_invalid;
11096 }12210 }
1109712211
...@@ -11268,7 +12382,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -11268,7 +12382,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
11268 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;12382 ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type;
11269 bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr &&12383 bool allow_infer = cur_err_set_type->data.error_set.infer_fn != nullptr &&
11270 cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;12384 cur_err_set_type->data.error_set.infer_fn == ira->new_irb.exec->fn_entry;
11271 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) {12385 if (!allow_infer && !resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->base.source_node)) {
11272 return ira->codegen->builtin_types.entry_invalid;12386 return ira->codegen->builtin_types.entry_invalid;
11273 }12387 }
11274 if ((!allow_infer && type_is_global_error_set(cur_err_set_type)) ||12388 if ((!allow_infer && type_is_global_error_set(cur_err_set_type)) ||
...@@ -11463,9 +12577,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -11463,9 +12577,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
11463 ErrorMsg *msg = ir_add_error_node(ira, source_node,12577 ErrorMsg *msg = ir_add_error_node(ira, source_node,
11464 buf_sprintf("incompatible types: '%s' and '%s'",12578 buf_sprintf("incompatible types: '%s' and '%s'",
11465 buf_ptr(&prev_type->name), buf_ptr(&cur_type->name)));12579 buf_ptr(&prev_type->name), buf_ptr(&cur_type->name)));
11466 add_error_note(ira->codegen, msg, prev_inst->source_node,12580 add_error_note(ira->codegen, msg, prev_inst->base.source_node,
11467 buf_sprintf("type '%s' here", buf_ptr(&prev_type->name)));12581 buf_sprintf("type '%s' here", buf_ptr(&prev_type->name)));
11468 add_error_note(ira->codegen, msg, cur_inst->source_node,12582 add_error_note(ira->codegen, msg, cur_inst->base.source_node,
11469 buf_sprintf("type '%s' here", buf_ptr(&cur_type->name)));12583 buf_sprintf("type '%s' here", buf_ptr(&cur_type->name)));
1147012584
11471 return ira->codegen->builtin_types.entry_invalid;12585 return ira->codegen->builtin_types.entry_invalid;
...@@ -11535,7 +12649,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT...@@ -11535,7 +12649,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
11535 }12649 }
11536}12650}
1153712651
11538static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr,12652static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInst *source_instr,
11539 CastOp cast_op,12653 CastOp cast_op,
11540 ZigValue *other_val, ZigType *other_type,12654 ZigValue *other_val, ZigType *other_type,
11541 ZigValue *const_val, ZigType *new_type)12655 ZigValue *const_val, ZigType *new_type)
...@@ -11635,58 +12749,56 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_...@@ -11635,58 +12749,56 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_
11635 return true;12749 return true;
11636}12750}
1163712751
11638static IrInstruction *ir_const(IrAnalyze *ira, IrInstruction *old_instruction, ZigType *ty) {12752static IrInstGen *ir_const(IrAnalyze *ira, IrInst *inst, ZigType *ty) {
11639 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,12753 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
11640 old_instruction->scope, old_instruction->source_node);12754 inst->scope, inst->source_node);
11641 IrInstruction *new_instruction = &const_instruction->base;12755 IrInstGen *new_instruction = &const_instruction->base;
11642 new_instruction->value->type = ty;12756 new_instruction->value->type = ty;
11643 new_instruction->value->special = ConstValSpecialStatic;12757 new_instruction->value->special = ConstValSpecialStatic;
11644 return new_instruction;12758 return new_instruction;
11645}12759}
1164612760
11647static IrInstruction *ir_const_noval(IrAnalyze *ira, IrInstruction *old_instruction) {12761static IrInstGen *ir_const_noval(IrAnalyze *ira, IrInst *old_instruction) {
11648 IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(&ira->new_irb,12762 IrInstGenConst *const_instruction = ir_create_inst_noval<IrInstGenConst>(&ira->new_irb,
11649 old_instruction->scope, old_instruction->source_node);12763 old_instruction->scope, old_instruction->source_node);
11650 return &const_instruction->base;12764 return &const_instruction->base;
11651}12765}
1165212766
11653// This function initializes the new IrInstruction with the provided ZigValue,12767// This function initializes the new IrInstGen with the provided ZigValue,
11654// rather than creating a new one.12768// rather than creating a new one.
11655static IrInstruction *ir_const_move(IrAnalyze *ira, IrInstruction *old_instruction, ZigValue *val) {12769static IrInstGen *ir_const_move(IrAnalyze *ira, IrInst *old_instruction, ZigValue *val) {
11656 IrInstruction *result = ir_const_noval(ira, old_instruction);12770 IrInstGen *result = ir_const_noval(ira, old_instruction);
11657 result->value = val;12771 result->value = val;
11658 return result;12772 return result;
11659}12773}
1166012774
11661static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,12775static IrInstGen *ir_resolve_cast(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value,
11662 ZigType *wanted_type, CastOp cast_op)12776 ZigType *wanted_type, CastOp cast_op)
11663{12777{
11664 if (instr_is_comptime(value) || !type_has_bits(wanted_type)) {12778 if (instr_is_comptime(value) || !type_has_bits(wanted_type)) {
11665 IrInstruction *result = ir_const(ira, source_instr, wanted_type);12779 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
11666 if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, value->value, value->value->type,12780 if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, value->value, value->value->type,
11667 result->value, wanted_type))12781 result->value, wanted_type))
11668 {12782 {
11669 return ira->codegen->invalid_instruction;12783 return ira->codegen->invalid_inst_gen;
11670 }12784 }
11671 return result;12785 return result;
11672 } else {12786 } else {
11673 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, cast_op);12787 return ir_build_cast(ira, source_instr, wanted_type, value, cast_op);
11674 result->value->type = wanted_type;
11675 return result;
11676 }12788 }
11677}12789}
1167812790
11679static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr,12791static IrInstGen *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInst* source_instr,
11680 IrInstruction *value, ZigType *wanted_type)12792 IrInstGen *value, ZigType *wanted_type)
11681{12793{
11682 assert(value->value->type->id == ZigTypeIdPointer);12794 ir_assert(value->value->type->id == ZigTypeIdPointer, source_instr);
1168312795
11684 Error err;12796 Error err;
1168512797
11686 if ((err = type_resolve(ira->codegen, value->value->type->data.pointer.child_type,12798 if ((err = type_resolve(ira->codegen, value->value->type->data.pointer.child_type,
11687 ResolveStatusAlignmentKnown)))12799 ResolveStatusAlignmentKnown)))
11688 {12800 {
11689 return ira->codegen->invalid_instruction;12801 return ira->codegen->invalid_inst_gen;
11690 }12802 }
1169112803
11692 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value->type));12804 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value->type));
...@@ -11694,9 +12806,9 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,...@@ -11694,9 +12806,9 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,
11694 if (instr_is_comptime(value)) {12806 if (instr_is_comptime(value)) {
11695 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, value->value, source_instr->source_node);12807 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, value->value, source_instr->source_node);
11696 if (pointee == nullptr)12808 if (pointee == nullptr)
11697 return ira->codegen->invalid_instruction;12809 return ira->codegen->invalid_inst_gen;
11698 if (pointee->special != ConstValSpecialRuntime) {12810 if (pointee->special != ConstValSpecialRuntime) {
11699 IrInstruction *result = ir_const(ira, source_instr, wanted_type);12811 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
11700 result->value->data.x_ptr.special = ConstPtrSpecialBaseArray;12812 result->value->data.x_ptr.special = ConstPtrSpecialBaseArray;
11701 result->value->data.x_ptr.mut = value->value->data.x_ptr.mut;12813 result->value->data.x_ptr.mut = value->value->data.x_ptr.mut;
11702 result->value->data.x_ptr.data.base_array.array_val = pointee;12814 result->value->data.x_ptr.data.base_array.array_val = pointee;
...@@ -11705,70 +12817,71 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,...@@ -11705,70 +12817,71 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira,
11705 }12817 }
11706 }12818 }
1170712819
11708 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,12820 return ir_build_cast(ira, source_instr, wanted_type, value, CastOpBitCast);
11709 wanted_type, value, CastOpBitCast);
11710 result->value->type = wanted_type;
11711 return result;
11712}12821}
1171312822
11714static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr,12823static IrInstGen *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInst* source_instr,
11715 IrInstruction *array_ptr, ZigType *wanted_type, ResultLoc *result_loc)12824 IrInstGen *array_ptr, ZigType *wanted_type, ResultLoc *result_loc)
11716{12825{
11717 Error err;12826 Error err;
1171812827
11719 if ((err = type_resolve(ira->codegen, array_ptr->value->type->data.pointer.child_type,12828 if ((err = type_resolve(ira->codegen, array_ptr->value->type->data.pointer.child_type,
11720 ResolveStatusAlignmentKnown)))12829 ResolveStatusAlignmentKnown)))
11721 {12830 {
11722 return ira->codegen->invalid_instruction;12831 return ira->codegen->invalid_inst_gen;
11723 }12832 }
1172412833
11725 wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value->type));12834 wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value->type));
1172612835
11727 if (instr_is_comptime(array_ptr)) {12836 if (instr_is_comptime(array_ptr)) {
11728 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr->value, source_instr->source_node);12837 ZigValue *array_ptr_val = ir_resolve_const(ira, array_ptr, UndefBad);
12838 if (array_ptr_val == nullptr)
12839 return ira->codegen->invalid_inst_gen;
12840 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr_val, source_instr->source_node);
11729 if (pointee == nullptr)12841 if (pointee == nullptr)
11730 return ira->codegen->invalid_instruction;12842 return ira->codegen->invalid_inst_gen;
11731 if (pointee->special != ConstValSpecialRuntime) {12843 if (pointee->special != ConstValSpecialRuntime) {
11732 assert(array_ptr->value->type->id == ZigTypeIdPointer);12844 assert(array_ptr_val->type->id == ZigTypeIdPointer);
11733 ZigType *array_type = array_ptr->value->type->data.pointer.child_type;12845 ZigType *array_type = array_ptr_val->type->data.pointer.child_type;
11734 assert(is_slice(wanted_type));12846 assert(is_slice(wanted_type));
11735 bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const;12847 bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const;
1173612848
11737 IrInstruction *result = ir_const(ira, source_instr, wanted_type);12849 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
11738 init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, is_const);12850 init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, is_const);
11739 result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr->value->data.x_ptr.mut;12851 result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;
11740 result->value->type = wanted_type;12852 result->value->type = wanted_type;
11741 return result;12853 return result;
11742 }12854 }
11743 }12855 }
1174412856
11745 if (result_loc == nullptr) result_loc = no_result_loc();12857 if (result_loc == nullptr) result_loc = no_result_loc();
11746 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true,12858 IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true);
11747 false, true);12859 if (type_is_invalid(result_loc_inst->value->type) ||
11748 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {12860 result_loc_inst->value->type->id == ZigTypeIdUnreachable)
12861 {
11749 return result_loc_inst;12862 return result_loc_inst;
11750 }12863 }
11751 return ir_build_ptr_of_array_to_slice(ira, source_instr, wanted_type, array_ptr, result_loc_inst);12864 return ir_build_ptr_of_array_to_slice(ira, source_instr, wanted_type, array_ptr, result_loc_inst);
11752}12865}
1175312866
11754static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) {12867static IrBasicBlockGen *ir_get_new_bb(IrAnalyze *ira, IrBasicBlockSrc *old_bb, IrInst *ref_old_instruction) {
11755 assert(old_bb);12868 assert(old_bb);
1175612869
11757 if (old_bb->other) {12870 if (old_bb->child) {
11758 if (ref_old_instruction == nullptr || old_bb->other->ref_instruction != ref_old_instruction) {12871 if (ref_old_instruction == nullptr || old_bb->child->ref_instruction != ref_old_instruction) {
11759 return old_bb->other;12872 return old_bb->child;
11760 }12873 }
11761 }12874 }
1176212875
11763 IrBasicBlock *new_bb = ir_build_bb_from(&ira->new_irb, old_bb);12876 IrBasicBlockGen *new_bb = ir_build_bb_from(ira, old_bb);
11764 new_bb->ref_instruction = ref_old_instruction;12877 new_bb->ref_instruction = ref_old_instruction;
1176512878
11766 return new_bb;12879 return new_bb;
11767}12880}
1176812881
11769static IrBasicBlock *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) {12882static IrBasicBlockGen *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlockSrc *old_bb, IrInst *ref_old_instruction) {
11770 assert(ref_old_instruction != nullptr);12883 assert(ref_old_instruction != nullptr);
11771 IrBasicBlock *new_bb = ir_get_new_bb(ira, old_bb, ref_old_instruction);12884 IrBasicBlockGen *new_bb = ir_get_new_bb(ira, old_bb, ref_old_instruction);
11772 if (new_bb->must_be_comptime_source_instr) {12885 if (new_bb->must_be_comptime_source_instr) {
11773 ErrorMsg *msg = ir_add_error(ira, ref_old_instruction,12886 ErrorMsg *msg = ir_add_error(ira, ref_old_instruction,
11774 buf_sprintf("control flow attempts to use compile-time variable at runtime"));12887 buf_sprintf("control flow attempts to use compile-time variable at runtime"));
...@@ -11779,24 +12892,24 @@ static IrBasicBlock *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlock *old_bb,...@@ -11779,24 +12892,24 @@ static IrBasicBlock *ir_get_new_bb_runtime(IrAnalyze *ira, IrBasicBlock *old_bb,
11779 return new_bb;12892 return new_bb;
11780}12893}
1178112894
11782static void ir_start_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrBasicBlock *const_predecessor_bb) {12895static void ir_start_bb(IrAnalyze *ira, IrBasicBlockSrc *old_bb, IrBasicBlockSrc *const_predecessor_bb) {
11783 ir_assert(!old_bb->suspended, (old_bb->instruction_list.length != 0) ? old_bb->instruction_list.at(0) : nullptr);12896 ir_assert(!old_bb->suspended, (old_bb->instruction_list.length != 0) ? &old_bb->instruction_list.at(0)->base : nullptr);
11784 ira->instruction_index = 0;12897 ira->instruction_index = 0;
11785 ira->old_irb.current_basic_block = old_bb;12898 ira->old_irb.current_basic_block = old_bb;
11786 ira->const_predecessor_bb = const_predecessor_bb;12899 ira->const_predecessor_bb = const_predecessor_bb;
11787 ira->old_bb_index = old_bb->index;12900 ira->old_bb_index = old_bb->index;
11788}12901}
1178912902
11790static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction, IrBasicBlock *next_bb,12903static IrInstGen *ira_suspend(IrAnalyze *ira, IrInst *old_instruction, IrBasicBlockSrc *next_bb,
11791 IrSuspendPosition *suspend_pos)12904 IrSuspendPosition *suspend_pos)
11792{12905{
11793 if (ira->codegen->verbose_ir) {12906 if (ira->codegen->verbose_ir) {
11794 fprintf(stderr, "suspend %s_%zu %s_%zu #%" PRIu32 " (%zu,%zu)\n",12907 fprintf(stderr, "suspend %s_%" PRIu32 " %s_%" PRIu32 " #%" PRIu32 " (%zu,%zu)\n",
11795 ira->old_irb.current_basic_block->name_hint,12908 ira->old_irb.current_basic_block->name_hint,
11796 ira->old_irb.current_basic_block->debug_id,12909 ira->old_irb.current_basic_block->debug_id,
11797 ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->name_hint,12910 ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->name_hint,
11798 ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->debug_id,12911 ira->old_irb.exec->basic_block_list.at(ira->old_bb_index)->debug_id,
11799 ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index)->debug_id,12912 ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index)->base.debug_id,
11800 ira->old_bb_index, ira->instruction_index);12913 ira->old_bb_index, ira->instruction_index);
11801 }12914 }
11802 suspend_pos->basic_block_index = ira->old_bb_index;12915 suspend_pos->basic_block_index = ira->old_bb_index;
...@@ -11811,13 +12924,13 @@ static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction...@@ -11811,13 +12924,13 @@ static IrInstruction *ira_suspend(IrAnalyze *ira, IrInstruction *old_instruction
11811 assert(ira->old_irb.current_basic_block == next_bb);12924 assert(ira->old_irb.current_basic_block == next_bb);
11812 ira->instruction_index = 0;12925 ira->instruction_index = 0;
11813 ira->const_predecessor_bb = nullptr;12926 ira->const_predecessor_bb = nullptr;
11814 next_bb->other = ir_get_new_bb_runtime(ira, next_bb, old_instruction);12927 next_bb->child = ir_get_new_bb_runtime(ira, next_bb, old_instruction);
11815 ira->new_irb.current_basic_block = next_bb->other;12928 ira->new_irb.current_basic_block = next_bb->child;
11816 }12929 }
11817 return ira->codegen->unreach_instruction;12930 return ira->codegen->unreach_instruction;
11818}12931}
1181912932
11820static IrInstruction *ira_resume(IrAnalyze *ira) {12933static IrInstGen *ira_resume(IrAnalyze *ira) {
11821 IrSuspendPosition pos = ira->resume_stack.pop();12934 IrSuspendPosition pos = ira->resume_stack.pop();
11822 if (ira->codegen->verbose_ir) {12935 if (ira->codegen->verbose_ir) {
11823 fprintf(stderr, "resume (%zu,%zu) ", pos.basic_block_index, pos.instruction_index);12936 fprintf(stderr, "resume (%zu,%zu) ", pos.basic_block_index, pos.instruction_index);
...@@ -11830,12 +12943,12 @@ static IrInstruction *ira_resume(IrAnalyze *ira) {...@@ -11830,12 +12943,12 @@ static IrInstruction *ira_resume(IrAnalyze *ira) {
11830 ira->instruction_index = pos.instruction_index;12943 ira->instruction_index = pos.instruction_index;
11831 assert(pos.instruction_index < ira->old_irb.current_basic_block->instruction_list.length);12944 assert(pos.instruction_index < ira->old_irb.current_basic_block->instruction_list.length);
11832 if (ira->codegen->verbose_ir) {12945 if (ira->codegen->verbose_ir) {
11833 fprintf(stderr, "%s_%zu #%" PRIu32 "\n", ira->old_irb.current_basic_block->name_hint,12946 fprintf(stderr, "%s_%" PRIu32 " #%" PRIu32 "\n", ira->old_irb.current_basic_block->name_hint,
11834 ira->old_irb.current_basic_block->debug_id,12947 ira->old_irb.current_basic_block->debug_id,
11835 ira->old_irb.current_basic_block->instruction_list.at(pos.instruction_index)->debug_id);12948 ira->old_irb.current_basic_block->instruction_list.at(pos.instruction_index)->base.debug_id);
11836 }12949 }
11837 ira->const_predecessor_bb = nullptr;12950 ira->const_predecessor_bb = nullptr;
11838 ira->new_irb.current_basic_block = ira->old_irb.current_basic_block->other;12951 ira->new_irb.current_basic_block = ira->old_irb.current_basic_block->child;
11839 assert(ira->new_irb.current_basic_block != nullptr);12952 assert(ira->new_irb.current_basic_block != nullptr);
11840 return ira->codegen->unreach_instruction;12953 return ira->codegen->unreach_instruction;
11841}12954}
...@@ -11846,8 +12959,8 @@ static void ir_start_next_bb(IrAnalyze *ira) {...@@ -11846,8 +12959,8 @@ static void ir_start_next_bb(IrAnalyze *ira) {
11846 bool need_repeat = true;12959 bool need_repeat = true;
11847 for (;;) {12960 for (;;) {
11848 while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) {12961 while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) {
11849 IrBasicBlock *old_bb = ira->old_irb.exec->basic_block_list.at(ira->old_bb_index);12962 IrBasicBlockSrc *old_bb = ira->old_irb.exec->basic_block_list.at(ira->old_bb_index);
11850 if (old_bb->other == nullptr && old_bb->suspend_instruction_ref == nullptr) {12963 if (old_bb->child == nullptr && old_bb->suspend_instruction_ref == nullptr) {
11851 ira->old_bb_index += 1;12964 ira->old_bb_index += 1;
11852 continue;12965 continue;
11853 }12966 }
...@@ -11855,8 +12968,8 @@ static void ir_start_next_bb(IrAnalyze *ira) {...@@ -11855,8 +12968,8 @@ static void ir_start_next_bb(IrAnalyze *ira) {
11855 // if it's a suspended block,12968 // if it's a suspended block,
11856 // then skip it12969 // then skip it
11857 if (old_bb->suspended ||12970 if (old_bb->suspended ||
11858 (old_bb->other != nullptr && old_bb->other->instruction_list.length != 0) ||12971 (old_bb->child != nullptr && old_bb->child->instruction_list.length != 0) ||
11859 (old_bb->other != nullptr && old_bb->other->already_appended))12972 (old_bb->child != nullptr && old_bb->child->already_appended))
11860 {12973 {
11861 ira->old_bb_index += 1;12974 ira->old_bb_index += 1;
11862 continue;12975 continue;
...@@ -11870,10 +12983,10 @@ static void ir_start_next_bb(IrAnalyze *ira) {...@@ -11870,10 +12983,10 @@ static void ir_start_next_bb(IrAnalyze *ira) {
11870 return;12983 return;
11871 }12984 }
1187212985
11873 if (old_bb->other == nullptr) {12986 if (old_bb->child == nullptr) {
11874 old_bb->other = ir_get_new_bb_runtime(ira, old_bb, old_bb->suspend_instruction_ref);12987 old_bb->child = ir_get_new_bb_runtime(ira, old_bb, old_bb->suspend_instruction_ref);
11875 }12988 }
11876 ira->new_irb.current_basic_block = old_bb->other;12989 ira->new_irb.current_basic_block = old_bb->child;
11877 ir_start_bb(ira, old_bb, nullptr);12990 ir_start_bb(ira, old_bb, nullptr);
11878 return;12991 return;
11879 }12992 }
...@@ -11893,16 +13006,16 @@ static void ir_finish_bb(IrAnalyze *ira) {...@@ -11893,16 +13006,16 @@ static void ir_finish_bb(IrAnalyze *ira) {
11893 if (!ira->new_irb.current_basic_block->already_appended) {13006 if (!ira->new_irb.current_basic_block->already_appended) {
11894 ira->new_irb.current_basic_block->already_appended = true;13007 ira->new_irb.current_basic_block->already_appended = true;
11895 if (ira->codegen->verbose_ir) {13008 if (ira->codegen->verbose_ir) {
11896 fprintf(stderr, "append new bb %s_%zu\n", ira->new_irb.current_basic_block->name_hint,13009 fprintf(stderr, "append new bb %s_%" PRIu32 "\n", ira->new_irb.current_basic_block->name_hint,
11897 ira->new_irb.current_basic_block->debug_id);13010 ira->new_irb.current_basic_block->debug_id);
11898 }13011 }
11899 ira->new_irb.exec->basic_block_list.append(ira->new_irb.current_basic_block);13012 ira->new_irb.exec->basic_block_list.append(ira->new_irb.current_basic_block);
11900 }13013 }
11901 ira->instruction_index += 1;13014 ira->instruction_index += 1;
11902 while (ira->instruction_index < ira->old_irb.current_basic_block->instruction_list.length) {13015 while (ira->instruction_index < ira->old_irb.current_basic_block->instruction_list.length) {
11903 IrInstruction *next_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index);13016 IrInstSrc *next_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index);
11904 if (!next_instruction->is_gen) {13017 if (!next_instruction->is_gen) {
11905 ir_add_error(ira, next_instruction, buf_sprintf("unreachable code"));13018 ir_add_error(ira, &next_instruction->base, buf_sprintf("unreachable code"));
11906 break;13019 break;
11907 }13020 }
11908 ira->instruction_index += 1;13021 ira->instruction_index += 1;
...@@ -11911,7 +13024,7 @@ static void ir_finish_bb(IrAnalyze *ira) {...@@ -11911,7 +13024,7 @@ static void ir_finish_bb(IrAnalyze *ira) {
11911 ir_start_next_bb(ira);13024 ir_start_next_bb(ira);
11912}13025}
1191313026
11914static IrInstruction *ir_unreach_error(IrAnalyze *ira) {13027static IrInstGen *ir_unreach_error(IrAnalyze *ira) {
11915 ira->old_bb_index = SIZE_MAX;13028 ira->old_bb_index = SIZE_MAX;
11916 if (ira->new_irb.exec->first_err_trace_msg == nullptr) {13029 if (ira->new_irb.exec->first_err_trace_msg == nullptr) {
11917 ira->new_irb.exec->first_err_trace_msg = ira->codegen->trace_err;13030 ira->new_irb.exec->first_err_trace_msg = ira->codegen->trace_err;
...@@ -11919,7 +13032,7 @@ static IrInstruction *ir_unreach_error(IrAnalyze *ira) {...@@ -11919,7 +13032,7 @@ static IrInstruction *ir_unreach_error(IrAnalyze *ira) {
11919 return ira->codegen->unreach_instruction;13032 return ira->codegen->unreach_instruction;
11920}13033}
1192113034
11922static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instruction) {13035static bool ir_emit_backward_branch(IrAnalyze *ira, IrInst* source_instruction) {
11923 size_t *bbc = ira->new_irb.exec->backward_branch_count;13036 size_t *bbc = ira->new_irb.exec->backward_branch_count;
11924 size_t *quota = ira->new_irb.exec->backward_branch_quota;13037 size_t *quota = ira->new_irb.exec->backward_branch_quota;
1192513038
...@@ -11938,66 +13051,85 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instru...@@ -11938,66 +13051,85 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instru
11938 return true;13051 return true;
11939}13052}
1194013053
11941static IrInstruction *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruction, IrBasicBlock *old_bb) {13054static IrInstGen *ir_inline_bb(IrAnalyze *ira, IrInst* source_instruction, IrBasicBlockSrc *old_bb) {
11942 if (old_bb->debug_id <= ira->old_irb.current_basic_block->debug_id) {13055 if (old_bb->debug_id <= ira->old_irb.current_basic_block->debug_id) {
11943 if (!ir_emit_backward_branch(ira, source_instruction))13056 if (!ir_emit_backward_branch(ira, source_instruction))
11944 return ir_unreach_error(ira);13057 return ir_unreach_error(ira);
11945 }13058 }
1194613059
11947 old_bb->other = ira->old_irb.current_basic_block->other;13060 old_bb->child = ira->old_irb.current_basic_block->child;
11948 ir_start_bb(ira, old_bb, ira->old_irb.current_basic_block);13061 ir_start_bb(ira, old_bb, ira->old_irb.current_basic_block);
11949 return ira->codegen->unreach_instruction;13062 return ira->codegen->unreach_instruction;
11950}13063}
1195113064
11952static IrInstruction *ir_finish_anal(IrAnalyze *ira, IrInstruction *instruction) {13065static IrInstGen *ir_finish_anal(IrAnalyze *ira, IrInstGen *instruction) {
11953 if (instruction->value->type->id == ZigTypeIdUnreachable)13066 if (instruction->value->type->id == ZigTypeIdUnreachable)
11954 ir_finish_bb(ira);13067 ir_finish_bb(ira);
11955 return instruction;13068 return instruction;
11956}13069}
1195713070
11958static IrInstruction *ir_const_type(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {13071static IrInstGen *ir_const_fn(IrAnalyze *ira, IrInst *source_instr, ZigFn *fn_entry) {
11959 IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_type);13072 IrInstGen *result = ir_const(ira, source_instr, fn_entry->type_entry);
13073 result->value->special = ConstValSpecialStatic;
13074 result->value->data.x_ptr.data.fn.fn_entry = fn_entry;
13075 result->value->data.x_ptr.mut = ConstPtrMutComptimeConst;
13076 result->value->data.x_ptr.special = ConstPtrSpecialFunction;
13077 return result;
13078}
13079
13080static IrInstGen *ir_const_bound_fn(IrAnalyze *ira, IrInst *src_inst, ZigFn *fn_entry, IrInstGen *first_arg,
13081 IrInst *first_arg_src)
13082{
13083 IrInstGen *result = ir_const(ira, src_inst, get_bound_fn_type(ira->codegen, fn_entry));
13084 result->value->data.x_bound_fn.fn = fn_entry;
13085 result->value->data.x_bound_fn.first_arg = first_arg;
13086 result->value->data.x_bound_fn.first_arg_src = first_arg_src;
13087 return result;
13088}
13089
13090static IrInstGen *ir_const_type(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) {
13091 IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_type);
11960 result->value->data.x_type = ty;13092 result->value->data.x_type = ty;
11961 return result;13093 return result;
11962}13094}
1196313095
11964static IrInstruction *ir_const_bool(IrAnalyze *ira, IrInstruction *source_instruction, bool value) {13096static IrInstGen *ir_const_bool(IrAnalyze *ira, IrInst *source_instruction, bool value) {
11965 IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_bool);13097 IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_bool);
11966 result->value->data.x_bool = value;13098 result->value->data.x_bool = value;
11967 return result;13099 return result;
11968}13100}
1196913101
11970static IrInstruction *ir_const_undef(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) {13102static IrInstGen *ir_const_undef(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty) {
11971 IrInstruction *result = ir_const(ira, source_instruction, ty);13103 IrInstGen *result = ir_const(ira, source_instruction, ty);
11972 result->value->special = ConstValSpecialUndef;13104 result->value->special = ConstValSpecialUndef;
11973 return result;13105 return result;
11974}13106}
1197513107
11976static IrInstruction *ir_const_unreachable(IrAnalyze *ira, IrInstruction *source_instruction) {13108static IrInstGen *ir_const_unreachable(IrAnalyze *ira, IrInst *source_instruction) {
11977 IrInstruction *result = ir_const_noval(ira, source_instruction);13109 IrInstGen *result = ir_const_noval(ira, source_instruction);
11978 result->value = ira->codegen->intern.for_unreachable();13110 result->value = ira->codegen->intern.for_unreachable();
11979 return result;13111 return result;
11980}13112}
1198113113
11982static IrInstruction *ir_const_void(IrAnalyze *ira, IrInstruction *source_instruction) {13114static IrInstGen *ir_const_void(IrAnalyze *ira, IrInst *source_instruction) {
11983 IrInstruction *result = ir_const_noval(ira, source_instruction);13115 IrInstGen *result = ir_const_noval(ira, source_instruction);
11984 result->value = ira->codegen->intern.for_void();13116 result->value = ira->codegen->intern.for_void();
11985 return result;13117 return result;
11986}13118}
1198713119
11988static IrInstruction *ir_const_unsigned(IrAnalyze *ira, IrInstruction *source_instruction, uint64_t value) {13120static IrInstGen *ir_const_unsigned(IrAnalyze *ira, IrInst *source_instruction, uint64_t value) {
11989 IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_num_lit_int);13121 IrInstGen *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_num_lit_int);
11990 bigint_init_unsigned(&result->value->data.x_bigint, value);13122 bigint_init_unsigned(&result->value->data.x_bigint, value);
11991 return result;13123 return result;
11992}13124}
1199313125
11994static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction,13126static IrInstGen *ir_get_const_ptr(IrAnalyze *ira, IrInst *instruction,
11995 ZigValue *pointee, ZigType *pointee_type,13127 ZigValue *pointee, ZigType *pointee_type,
11996 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)13128 ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align)
11997{13129{
11998 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,13130 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type,
11999 ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0, false);13131 ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0, false);
12000 IrInstruction *const_instr = ir_const(ira, instruction, ptr_type);13132 IrInstGen *const_instr = ir_const(ira, instruction, ptr_type);
12001 ZigValue *const_val = const_instr->value;13133 ZigValue *const_val = const_instr->value;
12002 const_val->data.x_ptr.special = ConstPtrSpecialRef;13134 const_val->data.x_ptr.special = ConstPtrSpecialRef;
12003 const_val->data.x_ptr.mut = ptr_mut;13135 const_val->data.x_ptr.mut = ptr_mut;
...@@ -12005,7 +13137,7 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio...@@ -12005,7 +13137,7 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio
12005 return const_instr;13137 return const_instr;
12006}13138}
1200713139
12008static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,13140static Error ir_resolve_const_val(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node,
12009 ZigValue *val, UndefAllowed undef_allowed)13141 ZigValue *val, UndefAllowed undef_allowed)
12010{13142{
12011 Error err;13143 Error err;
...@@ -12017,14 +13149,14 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode...@@ -12017,14 +13149,14 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode
12017 if (!type_has_bits(val->type))13149 if (!type_has_bits(val->type))
12018 return ErrorNone;13150 return ErrorNone;
1201913151
12020 exec_add_error_node(codegen, exec, source_node,13152 exec_add_error_node_gen(codegen, exec, source_node,
12021 buf_sprintf("unable to evaluate constant expression"));13153 buf_sprintf("unable to evaluate constant expression"));
12022 return ErrorSemanticAnalyzeFail;13154 return ErrorSemanticAnalyzeFail;
12023 case ConstValSpecialUndef:13155 case ConstValSpecialUndef:
12024 if (undef_allowed == UndefOk || undef_allowed == LazyOk)13156 if (undef_allowed == UndefOk || undef_allowed == LazyOk)
12025 return ErrorNone;13157 return ErrorNone;
1202613158
12027 exec_add_error_node(codegen, exec, source_node,13159 exec_add_error_node_gen(codegen, exec, source_node,
12028 buf_sprintf("use of undefined value here causes undefined behavior"));13160 buf_sprintf("use of undefined value here causes undefined behavior"));
12029 return ErrorSemanticAnalyzeFail;13161 return ErrorSemanticAnalyzeFail;
12030 case ConstValSpecialLazy:13162 case ConstValSpecialLazy:
...@@ -12039,9 +13171,9 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode...@@ -12039,9 +13171,9 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode
12039 }13171 }
12040}13172}
1204113173
12042static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed) {13174static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstGen *value, UndefAllowed undef_allowed) {
12043 Error err;13175 Error err;
12044 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->source_node,13176 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->base.source_node,
12045 value->value, undef_allowed)))13177 value->value, undef_allowed)))
12046 {13178 {
12047 return nullptr;13179 return nullptr;
...@@ -12049,17 +13181,19 @@ static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAll...@@ -12049,17 +13181,19 @@ static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAll
12049 return value->value;13181 return value->value;
12050}13182}
1205113183
12052ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,13184Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
12053 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,13185 ZigValue *return_ptr, size_t *backward_branch_count, size_t *backward_branch_quota,
12054 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,13186 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
12055 IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed)13187 IrExecutableGen *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed)
12056{13188{
12057 Error err;13189 Error err;
1205813190
12059 if (expected_type != nullptr && type_is_invalid(expected_type))13191 src_assert(return_ptr->type->id == ZigTypeIdPointer, source_node);
12060 return codegen->invalid_instruction->value;13192
13193 if (type_is_invalid(return_ptr->type))
13194 return ErrorSemanticAnalyzeFail;
1206113195
12062 IrExecutable *ir_executable = allocate<IrExecutable>(1, "IrExecutablePass1");13196 IrExecutableSrc *ir_executable = allocate<IrExecutableSrc>(1, "IrExecutableSrc");
12063 ir_executable->source_node = source_node;13197 ir_executable->source_node = source_node;
12064 ir_executable->parent_exec = parent_exec;13198 ir_executable->parent_exec = parent_exec;
12065 ir_executable->name = exec_name;13199 ir_executable->name = exec_name;
...@@ -12069,21 +13203,21 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,...@@ -12069,21 +13203,21 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
12069 ir_executable->begin_scope = scope;13203 ir_executable->begin_scope = scope;
1207013204
12071 if (!ir_gen(codegen, node, scope, ir_executable))13205 if (!ir_gen(codegen, node, scope, ir_executable))
12072 return codegen->invalid_instruction->value;13206 return ErrorSemanticAnalyzeFail;
1207313207
12074 if (ir_executable->first_err_trace_msg != nullptr) {13208 if (ir_executable->first_err_trace_msg != nullptr) {
12075 codegen->trace_err = ir_executable->first_err_trace_msg;13209 codegen->trace_err = ir_executable->first_err_trace_msg;
12076 return codegen->invalid_instruction->value;13210 return ErrorSemanticAnalyzeFail;
12077 }13211 }
1207813212
12079 if (codegen->verbose_ir) {13213 if (codegen->verbose_ir) {
12080 fprintf(stderr, "\nSource: ");13214 fprintf(stderr, "\nSource: ");
12081 ast_render(stderr, node, 4);13215 ast_render(stderr, node, 4);
12082 fprintf(stderr, "\n{ // (IR)\n");13216 fprintf(stderr, "\n{ // (IR)\n");
12083 ir_print(codegen, stderr, ir_executable, 2, IrPassSrc);13217 ir_print_src(codegen, stderr, ir_executable, 2);
12084 fprintf(stderr, "}\n");13218 fprintf(stderr, "}\n");
12085 }13219 }
12086 IrExecutable *analyzed_executable = allocate<IrExecutable>(1, "IrExecutablePass2");13220 IrExecutableGen *analyzed_executable = allocate<IrExecutableGen>(1, "IrExecutableGen");
12087 analyzed_executable->source_node = source_node;13221 analyzed_executable->source_node = source_node;
12088 analyzed_executable->parent_exec = parent_exec;13222 analyzed_executable->parent_exec = parent_exec;
12089 analyzed_executable->source_exec = ir_executable;13223 analyzed_executable->source_exec = ir_executable;
...@@ -12094,33 +13228,36 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,...@@ -12094,33 +13228,36 @@ ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
12094 analyzed_executable->backward_branch_count = backward_branch_count;13228 analyzed_executable->backward_branch_count = backward_branch_count;
12095 analyzed_executable->backward_branch_quota = backward_branch_quota;13229 analyzed_executable->backward_branch_quota = backward_branch_quota;
12096 analyzed_executable->begin_scope = scope;13230 analyzed_executable->begin_scope = scope;
12097 ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, expected_type_source_node);13231 ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable,
13232 return_ptr->type->data.pointer.child_type, expected_type_source_node, return_ptr);
12098 if (type_is_invalid(result_type)) {13233 if (type_is_invalid(result_type)) {
12099 return codegen->invalid_instruction->value;13234 return ErrorSemanticAnalyzeFail;
12100 }13235 }
1210113236
12102 if (codegen->verbose_ir) {13237 if (codegen->verbose_ir) {
12103 fprintf(stderr, "{ // (analyzed)\n");13238 fprintf(stderr, "{ // (analyzed)\n");
12104 ir_print(codegen, stderr, analyzed_executable, 2, IrPassGen);13239 ir_print_gen(codegen, stderr, analyzed_executable, 2);
12105 fprintf(stderr, "}\n");13240 fprintf(stderr, "}\n");
12106 }13241 }
1210713242
12108 ZigValue *result = ir_exec_const_result(codegen, analyzed_executable);13243 if ((err = ir_exec_scan_for_side_effects(codegen, analyzed_executable)))
12109 if (type_is_invalid(result->type))13244 return err;
12110 return codegen->invalid_instruction->value;
1211113245
13246 ZigValue *result = const_ptr_pointee(nullptr, codegen, return_ptr, source_node);
13247 if (result == nullptr)
13248 return ErrorSemanticAnalyzeFail;
12112 if ((err = ir_resolve_const_val(codegen, analyzed_executable, node, result, undef_allowed)))13249 if ((err = ir_resolve_const_val(codegen, analyzed_executable, node, result, undef_allowed)))
12113 return codegen->invalid_instruction->value;13250 return err;
1211413251
12115 return result;13252 return ErrorNone;
12116}13253}
1211713254
12118static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_value) {13255static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstGen *err_value) {
12119 if (type_is_invalid(err_value->value->type))13256 if (type_is_invalid(err_value->value->type))
12120 return nullptr;13257 return nullptr;
1212113258
12122 if (err_value->value->type->id != ZigTypeIdErrorSet) {13259 if (err_value->value->type->id != ZigTypeIdErrorSet) {
12123 ir_add_error(ira, err_value,13260 ir_add_error_node(ira, err_value->base.source_node,
12124 buf_sprintf("expected error, found '%s'", buf_ptr(&err_value->value->type->name)));13261 buf_sprintf("expected error, found '%s'", buf_ptr(&err_value->value->type->name)));
12125 return nullptr;13262 return nullptr;
12126 }13263 }
...@@ -12133,7 +13270,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_valu...@@ -12133,7 +13270,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_valu
12133 return const_val->data.x_err_set;13270 return const_val->data.x_err_set;
12134}13271}
1213513272
12136static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,13273static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node,
12137 ZigValue *val)13274 ZigValue *val)
12138{13275{
12139 Error err;13276 Error err;
...@@ -12144,18 +13281,18 @@ static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstN...@@ -12144,18 +13281,18 @@ static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstN
12144 return val->data.x_type;13281 return val->data.x_type;
12145}13282}
1214613283
12147static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value) {13284static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstGen *type_value) {
12148 if (type_is_invalid(type_value->value->type))13285 if (type_is_invalid(type_value->value->type))
12149 return nullptr;13286 return nullptr;
1215013287
12151 if (type_value->value->type->id != ZigTypeIdMetaType) {13288 if (type_value->value->type->id != ZigTypeIdMetaType) {
12152 ir_add_error(ira, type_value,13289 ir_add_error_node(ira, type_value->base.source_node,
12153 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value->type->name)));13290 buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value->type->name)));
12154 return nullptr;13291 return nullptr;
12155 }13292 }
1215613293
12157 Error err;13294 Error err;
12158 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->source_node,13295 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->base.source_node,
12159 type_value->value, LazyOk)))13296 type_value->value, LazyOk)))
12160 {13297 {
12161 return nullptr;13298 return nullptr;
...@@ -12164,17 +13301,17 @@ static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value)...@@ -12164,17 +13301,17 @@ static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value)
12164 return type_value->value;13301 return type_value->value;
12165}13302}
1216613303
12167static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {13304static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstGen *type_value) {
12168 ZigValue *val = ir_resolve_type_lazy(ira, type_value);13305 ZigValue *val = ir_resolve_type_lazy(ira, type_value);
12169 if (val == nullptr)13306 if (val == nullptr)
12170 return ira->codegen->builtin_types.entry_invalid;13307 return ira->codegen->builtin_types.entry_invalid;
1217113308
12172 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, type_value->source_node, val);13309 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, type_value->base.source_node, val);
12173}13310}
1217413311
12175static Error ir_validate_vector_elem_type(IrAnalyze *ira, IrInstruction *source_instr, ZigType *elem_type) {13312static Error ir_validate_vector_elem_type(IrAnalyze *ira, AstNode *source_node, ZigType *elem_type) {
12176 if (!is_valid_vector_elem_type(elem_type)) {13313 if (!is_valid_vector_elem_type(elem_type)) {
12177 ir_add_error(ira, source_instr,13314 ir_add_error_node(ira, source_node,
12178 buf_sprintf("vector element type must be integer, float, bool, or pointer; '%s' is invalid",13315 buf_sprintf("vector element type must be integer, float, bool, or pointer; '%s' is invalid",
12179 buf_ptr(&elem_type->name)));13316 buf_ptr(&elem_type->name)));
12180 return ErrorSemanticAnalyzeFail;13317 return ErrorSemanticAnalyzeFail;
...@@ -12182,28 +13319,28 @@ static Error ir_validate_vector_elem_type(IrAnalyze *ira, IrInstruction *source_...@@ -12182,28 +13319,28 @@ static Error ir_validate_vector_elem_type(IrAnalyze *ira, IrInstruction *source_
12182 return ErrorNone;13319 return ErrorNone;
12183}13320}
1218413321
12185static ZigType *ir_resolve_vector_elem_type(IrAnalyze *ira, IrInstruction *elem_type_value) {13322static ZigType *ir_resolve_vector_elem_type(IrAnalyze *ira, IrInstGen *elem_type_value) {
12186 Error err;13323 Error err;
12187 ZigType *elem_type = ir_resolve_type(ira, elem_type_value);13324 ZigType *elem_type = ir_resolve_type(ira, elem_type_value);
12188 if (type_is_invalid(elem_type))13325 if (type_is_invalid(elem_type))
12189 return ira->codegen->builtin_types.entry_invalid;13326 return ira->codegen->builtin_types.entry_invalid;
12190 if ((err = ir_validate_vector_elem_type(ira, elem_type_value, elem_type)))13327 if ((err = ir_validate_vector_elem_type(ira, elem_type_value->base.source_node, elem_type)))
12191 return ira->codegen->builtin_types.entry_invalid;13328 return ira->codegen->builtin_types.entry_invalid;
12192 return elem_type;13329 return elem_type;
12193}13330}
1219413331
12195static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstruction *type_value) {13332static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstGen *type_value) {
12196 ZigType *ty = ir_resolve_type(ira, type_value);13333 ZigType *ty = ir_resolve_type(ira, type_value);
12197 if (type_is_invalid(ty))13334 if (type_is_invalid(ty))
12198 return ira->codegen->builtin_types.entry_invalid;13335 return ira->codegen->builtin_types.entry_invalid;
1219913336
12200 if (ty->id != ZigTypeIdInt) {13337 if (ty->id != ZigTypeIdInt) {
12201 ErrorMsg *msg = ir_add_error(ira, type_value,13338 ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node,
12202 buf_sprintf("expected integer type, found '%s'", buf_ptr(&ty->name)));13339 buf_sprintf("expected integer type, found '%s'", buf_ptr(&ty->name)));
12203 if (ty->id == ZigTypeIdVector &&13340 if (ty->id == ZigTypeIdVector &&
12204 ty->data.vector.elem_type->id == ZigTypeIdInt)13341 ty->data.vector.elem_type->id == ZigTypeIdInt)
12205 {13342 {
12206 add_error_note(ira->codegen, msg, type_value->source_node,13343 add_error_note(ira->codegen, msg, type_value->base.source_node,
12207 buf_sprintf("represent vectors with their element types, i.e. '%s'",13344 buf_sprintf("represent vectors with their element types, i.e. '%s'",
12208 buf_ptr(&ty->data.vector.elem_type->name)));13345 buf_ptr(&ty->data.vector.elem_type->name)));
12209 }13346 }
...@@ -12213,12 +13350,12 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstruction *type_value) {...@@ -12213,12 +13350,12 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstruction *type_value) {
12213 return ty;13350 return ty;
12214}13351}
1221513352
12216static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_source, IrInstruction *type_value) {13353static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInst *op_source, IrInstGen *type_value) {
12217 if (type_is_invalid(type_value->value->type))13354 if (type_is_invalid(type_value->value->type))
12218 return ira->codegen->builtin_types.entry_invalid;13355 return ira->codegen->builtin_types.entry_invalid;
1221913356
12220 if (type_value->value->type->id != ZigTypeIdMetaType) {13357 if (type_value->value->type->id != ZigTypeIdMetaType) {
12221 ErrorMsg *msg = ir_add_error(ira, type_value,13358 ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node,
12222 buf_sprintf("expected error set type, found '%s'", buf_ptr(&type_value->value->type->name)));13359 buf_sprintf("expected error set type, found '%s'", buf_ptr(&type_value->value->type->name)));
12223 add_error_note(ira->codegen, msg, op_source->source_node,13360 add_error_note(ira->codegen, msg, op_source->source_node,
12224 buf_sprintf("`||` merges error sets; `or` performs boolean OR"));13361 buf_sprintf("`||` merges error sets; `or` performs boolean OR"));
...@@ -12232,7 +13369,7 @@ static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_sour...@@ -12232,7 +13369,7 @@ static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_sour
12232 assert(const_val->data.x_type != nullptr);13369 assert(const_val->data.x_type != nullptr);
12233 ZigType *result_type = const_val->data.x_type;13370 ZigType *result_type = const_val->data.x_type;
12234 if (result_type->id != ZigTypeIdErrorSet) {13371 if (result_type->id != ZigTypeIdErrorSet) {
12235 ErrorMsg *msg = ir_add_error(ira, type_value,13372 ErrorMsg *msg = ir_add_error_node(ira, type_value->base.source_node,
12236 buf_sprintf("expected error set type, found type '%s'", buf_ptr(&result_type->name)));13373 buf_sprintf("expected error set type, found type '%s'", buf_ptr(&result_type->name)));
12237 add_error_note(ira->codegen, msg, op_source->source_node,13374 add_error_note(ira->codegen, msg, op_source->source_node,
12238 buf_sprintf("`||` merges error sets; `or` performs boolean OR"));13375 buf_sprintf("`||` merges error sets; `or` performs boolean OR"));
...@@ -12241,15 +13378,12 @@ static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_sour...@@ -12241,15 +13378,12 @@ static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_sour
12241 return result_type;13378 return result_type;
12242}13379}
1224313380
12244static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {13381static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstGen *fn_value) {
12245 if (fn_value == ira->codegen->invalid_instruction)
12246 return nullptr;
12247
12248 if (type_is_invalid(fn_value->value->type))13382 if (type_is_invalid(fn_value->value->type))
12249 return nullptr;13383 return nullptr;
1225013384
12251 if (fn_value->value->type->id != ZigTypeIdFn) {13385 if (fn_value->value->type->id != ZigTypeIdFn) {
12252 ir_add_error_node(ira, fn_value->source_node,13386 ir_add_error_node(ira, fn_value->base.source_node,
12253 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value->type->name)));13387 buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value->type->name)));
12254 return nullptr;13388 return nullptr;
12255 }13389 }
...@@ -12265,22 +13399,22 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {...@@ -12265,22 +13399,22 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
12265 return const_val->data.x_ptr.data.fn.fn_entry;13399 return const_val->data.x_ptr.data.fn.fn_entry;
12266}13400}
1226713401
12268static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,13402static IrInstGen *ir_analyze_optional_wrap(IrAnalyze *ira, IrInst* source_instr,
12269 ZigType *wanted_type, ResultLoc *result_loc)13403 IrInstGen *value, ZigType *wanted_type, ResultLoc *result_loc)
12270{13404{
12271 assert(wanted_type->id == ZigTypeIdOptional);13405 assert(wanted_type->id == ZigTypeIdOptional);
1227213406
12273 if (instr_is_comptime(value)) {13407 if (instr_is_comptime(value)) {
12274 ZigType *payload_type = wanted_type->data.maybe.child_type;13408 ZigType *payload_type = wanted_type->data.maybe.child_type;
12275 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);13409 IrInstGen *casted_payload = ir_implicit_cast(ira, value, payload_type);
12276 if (type_is_invalid(casted_payload->value->type))13410 if (type_is_invalid(casted_payload->value->type))
12277 return ira->codegen->invalid_instruction;13411 return ira->codegen->invalid_inst_gen;
1227813412
12279 ZigValue *val = ir_resolve_const(ira, casted_payload, UndefOk);13413 ZigValue *val = ir_resolve_const(ira, casted_payload, UndefOk);
12280 if (!val)13414 if (!val)
12281 return ira->codegen->invalid_instruction;13415 return ira->codegen->invalid_inst_gen;
1228213416
12283 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,13417 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
12284 source_instr->scope, source_instr->source_node);13418 source_instr->scope, source_instr->source_node);
12285 const_instruction->base.value->special = ConstValSpecialStatic;13419 const_instruction->base.value->special = ConstValSpecialStatic;
12286 if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) {13420 if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) {
...@@ -12295,40 +13429,42 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so...@@ -12295,40 +13429,42 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so
12295 if (result_loc == nullptr && handle_is_ptr(wanted_type)) {13429 if (result_loc == nullptr && handle_is_ptr(wanted_type)) {
12296 result_loc = no_result_loc();13430 result_loc = no_result_loc();
12297 }13431 }
12298 IrInstruction *result_loc_inst = nullptr;13432 IrInstGen *result_loc_inst = nullptr;
12299 if (result_loc != nullptr) {13433 if (result_loc != nullptr) {
12300 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true);13434 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true);
12301 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {13435 if (type_is_invalid(result_loc_inst->value->type) ||
13436 result_loc_inst->value->type->id == ZigTypeIdUnreachable)
13437 {
12302 return result_loc_inst;13438 return result_loc_inst;
12303 }13439 }
12304 }13440 }
12305 IrInstruction *result = ir_build_optional_wrap(ira, source_instr, wanted_type, value, result_loc_inst);13441 IrInstGen *result = ir_build_optional_wrap(ira, source_instr, wanted_type, value, result_loc_inst);
12306 result->value->data.rh_maybe = RuntimeHintOptionalNonNull;13442 result->value->data.rh_maybe = RuntimeHintOptionalNonNull;
12307 return result;13443 return result;
12308}13444}
1230913445
12310static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr,13446static IrInstGen *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInst* source_instr,
12311 IrInstruction *value, ZigType *wanted_type, ResultLoc *result_loc)13447 IrInstGen *value, ZigType *wanted_type, ResultLoc *result_loc)
12312{13448{
12313 assert(wanted_type->id == ZigTypeIdErrorUnion);13449 assert(wanted_type->id == ZigTypeIdErrorUnion);
1231413450
12315 ZigType *payload_type = wanted_type->data.error_union.payload_type;13451 ZigType *payload_type = wanted_type->data.error_union.payload_type;
12316 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;13452 ZigType *err_set_type = wanted_type->data.error_union.err_set_type;
12317 if (instr_is_comptime(value)) {13453 if (instr_is_comptime(value)) {
12318 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);13454 IrInstGen *casted_payload = ir_implicit_cast(ira, value, payload_type);
12319 if (type_is_invalid(casted_payload->value->type))13455 if (type_is_invalid(casted_payload->value->type))
12320 return ira->codegen->invalid_instruction;13456 return ira->codegen->invalid_inst_gen;
1232113457
12322 ZigValue *val = ir_resolve_const(ira, casted_payload, UndefBad);13458 ZigValue *val = ir_resolve_const(ira, casted_payload, UndefOk);
12323 if (!val)13459 if (val == nullptr)
12324 return ira->codegen->invalid_instruction;13460 return ira->codegen->invalid_inst_gen;
1232513461
12326 ZigValue *err_set_val = create_const_vals(1);13462 ZigValue *err_set_val = create_const_vals(1);
12327 err_set_val->type = err_set_type;13463 err_set_val->type = err_set_type;
12328 err_set_val->special = ConstValSpecialStatic;13464 err_set_val->special = ConstValSpecialStatic;
12329 err_set_val->data.x_err_set = nullptr;13465 err_set_val->data.x_err_set = nullptr;
1233013466
12331 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,13467 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
12332 source_instr->scope, source_instr->source_node);13468 source_instr->scope, source_instr->source_node);
12333 const_instruction->base.value->type = wanted_type;13469 const_instruction->base.value->type = wanted_type;
12334 const_instruction->base.value->special = ConstValSpecialStatic;13470 const_instruction->base.value->special = ConstValSpecialStatic;
...@@ -12337,23 +13473,24 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction...@@ -12337,23 +13473,24 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
12337 return &const_instruction->base;13473 return &const_instruction->base;
12338 }13474 }
1233913475
12340 IrInstruction *result_loc_inst;13476 IrInstGen *result_loc_inst;
12341 if (handle_is_ptr(wanted_type)) {13477 if (handle_is_ptr(wanted_type)) {
12342 if (result_loc == nullptr) result_loc = no_result_loc();13478 if (result_loc == nullptr) result_loc = no_result_loc();
12343 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true);13479 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true);
12344 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {13480 if (type_is_invalid(result_loc_inst->value->type) ||
13481 result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
12345 return result_loc_inst;13482 return result_loc_inst;
12346 }13483 }
12347 } else {13484 } else {
12348 result_loc_inst = nullptr;13485 result_loc_inst = nullptr;
12349 }13486 }
1235013487
12351 IrInstruction *result = ir_build_err_wrap_payload(ira, source_instr, wanted_type, value, result_loc_inst);13488 IrInstGen *result = ir_build_err_wrap_payload(ira, source_instr, wanted_type, value, result_loc_inst);
12352 result->value->data.rh_error_union = RuntimeHintErrorUnionNonError;13489 result->value->data.rh_error_union = RuntimeHintErrorUnionNonError;
12353 return result;13490 return result;
12354}13491}
1235513492
12356static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,13493static IrInstGen *ir_analyze_err_set_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,
12357 ZigType *wanted_type)13494 ZigType *wanted_type)
12358{13495{
12359 assert(value->value->type->id == ZigTypeIdErrorSet);13496 assert(value->value->type->id == ZigTypeIdErrorSet);
...@@ -12362,10 +13499,10 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou...@@ -12362,10 +13499,10 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
12362 if (instr_is_comptime(value)) {13499 if (instr_is_comptime(value)) {
12363 ZigValue *val = ir_resolve_const(ira, value, UndefBad);13500 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
12364 if (!val)13501 if (!val)
12365 return ira->codegen->invalid_instruction;13502 return ira->codegen->invalid_inst_gen;
1236613503
12367 if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) {13504 if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) {
12368 return ira->codegen->invalid_instruction;13505 return ira->codegen->invalid_inst_gen;
12369 }13506 }
12370 if (!type_is_global_error_set(wanted_type)) {13507 if (!type_is_global_error_set(wanted_type)) {
12371 bool subset = false;13508 bool subset = false;
...@@ -12379,11 +13516,11 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou...@@ -12379,11 +13516,11 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
12379 ir_add_error(ira, source_instr,13516 ir_add_error(ira, source_instr,
12380 buf_sprintf("error.%s not a member of error set '%s'",13517 buf_sprintf("error.%s not a member of error set '%s'",
12381 buf_ptr(&val->data.x_err_set->name), buf_ptr(&wanted_type->name)));13518 buf_ptr(&val->data.x_err_set->name), buf_ptr(&wanted_type->name)));
12382 return ira->codegen->invalid_instruction;13519 return ira->codegen->invalid_inst_gen;
12383 }13520 }
12384 }13521 }
1238513522
12386 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,13523 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
12387 source_instr->scope, source_instr->source_node);13524 source_instr->scope, source_instr->source_node);
12388 const_instruction->base.value->type = wanted_type;13525 const_instruction->base.value->type = wanted_type;
12389 const_instruction->base.value->special = ConstValSpecialStatic;13526 const_instruction->base.value->special = ConstValSpecialStatic;
...@@ -12391,18 +13528,16 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou...@@ -12391,18 +13528,16 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou
12391 return &const_instruction->base;13528 return &const_instruction->base;
12392 }13529 }
1239313530
12394 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, CastOpErrSet);13531 return ir_build_cast(ira, source_instr, wanted_type, value, CastOpErrSet);
12395 result->value->type = wanted_type;
12396 return result;
12397}13532}
1239813533
12399static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruction *source_instr,13534static IrInstGen *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInst* source_instr,
12400 IrInstruction *frame_ptr, ZigType *wanted_type)13535 IrInstGen *frame_ptr, ZigType *wanted_type)
12401{13536{
12402 if (instr_is_comptime(frame_ptr)) {13537 if (instr_is_comptime(frame_ptr)) {
12403 ZigValue *ptr_val = ir_resolve_const(ira, frame_ptr, UndefBad);13538 ZigValue *ptr_val = ir_resolve_const(ira, frame_ptr, UndefBad);
12404 if (ptr_val == nullptr)13539 if (ptr_val == nullptr)
12405 return ira->codegen->invalid_instruction;13540 return ira->codegen->invalid_inst_gen;
1240613541
12407 ir_assert(ptr_val->type->id == ZigTypeIdPointer, source_instr);13542 ir_assert(ptr_val->type->id == ZigTypeIdPointer, source_instr);
12408 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {13543 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
...@@ -12410,44 +13545,38 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc...@@ -12410,44 +13545,38 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc
12410 }13545 }
12411 }13546 }
1241213547
12413 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,13548 return ir_build_cast(ira, source_instr, wanted_type, frame_ptr, CastOpBitCast);
12414 wanted_type, frame_ptr, CastOpBitCast);
12415 result->value->type = wanted_type;
12416 return result;
12417}13549}
1241813550
12419static IrInstruction *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInstruction *source_instr,13551static IrInstGen *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInst* source_instr,
12420 IrInstruction *value, ZigType *wanted_type)13552 IrInstGen *value, ZigType *wanted_type)
12421{13553{
12422 if (instr_is_comptime(value)) {13554 if (instr_is_comptime(value)) {
12423 zig_panic("TODO comptime anyframe->T to anyframe");13555 zig_panic("TODO comptime anyframe->T to anyframe");
12424 }13556 }
1242513557
12426 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node,13558 return ir_build_cast(ira, source_instr, wanted_type, value, CastOpBitCast);
12427 wanted_type, value, CastOpBitCast);
12428 result->value->type = wanted_type;
12429 return result;
12430}13559}
1243113560
1243213561
12433static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,13562static IrInstGen *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,
12434 ZigType *wanted_type, ResultLoc *result_loc)13563 ZigType *wanted_type, ResultLoc *result_loc)
12435{13564{
12436 assert(wanted_type->id == ZigTypeIdErrorUnion);13565 assert(wanted_type->id == ZigTypeIdErrorUnion);
1243713566
12438 IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type);13567 IrInstGen *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type);
1243913568
12440 if (instr_is_comptime(casted_value)) {13569 if (instr_is_comptime(casted_value)) {
12441 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);13570 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);
12442 if (!val)13571 if (!val)
12443 return ira->codegen->invalid_instruction;13572 return ira->codegen->invalid_inst_gen;
1244413573
12445 ZigValue *err_set_val = create_const_vals(1);13574 ZigValue *err_set_val = create_const_vals(1);
12446 err_set_val->special = ConstValSpecialStatic;13575 err_set_val->special = ConstValSpecialStatic;
12447 err_set_val->type = wanted_type->data.error_union.err_set_type;13576 err_set_val->type = wanted_type->data.error_union.err_set_type;
12448 err_set_val->data.x_err_set = val->data.x_err_set;13577 err_set_val->data.x_err_set = val->data.x_err_set;
1244913578
12450 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,13579 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
12451 source_instr->scope, source_instr->source_node);13580 source_instr->scope, source_instr->source_node);
12452 const_instruction->base.value->type = wanted_type;13581 const_instruction->base.value->type = wanted_type;
12453 const_instruction->base.value->special = ConstValSpecialStatic;13582 const_instruction->base.value->special = ConstValSpecialStatic;
...@@ -12456,11 +13585,13 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so...@@ -12456,11 +13585,13 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
12456 return &const_instruction->base;13585 return &const_instruction->base;
12457 }13586 }
1245813587
12459 IrInstruction *result_loc_inst;13588 IrInstGen *result_loc_inst;
12460 if (handle_is_ptr(wanted_type)) {13589 if (handle_is_ptr(wanted_type)) {
12461 if (result_loc == nullptr) result_loc = no_result_loc();13590 if (result_loc == nullptr) result_loc = no_result_loc();
12462 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true);13591 result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, true);
12463 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {13592 if (type_is_invalid(result_loc_inst->value->type) ||
13593 result_loc_inst->value->type->id == ZigTypeIdUnreachable)
13594 {
12464 return result_loc_inst;13595 return result_loc_inst;
12465 }13596 }
12466 } else {13597 } else {
...@@ -12468,19 +13599,19 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so...@@ -12468,19 +13599,19 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
12468 }13599 }
1246913600
1247013601
12471 IrInstruction *result = ir_build_err_wrap_code(ira, source_instr, wanted_type, value, result_loc_inst);13602 IrInstGen *result = ir_build_err_wrap_code(ira, source_instr, wanted_type, value, result_loc_inst);
12472 result->value->data.rh_error_union = RuntimeHintErrorUnionError;13603 result->value->data.rh_error_union = RuntimeHintErrorUnionError;
12473 return result;13604 return result;
12474}13605}
1247513606
12476static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) {13607static IrInstGen *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInst *source_instr, IrInstGen *value, ZigType *wanted_type) {
12477 assert(wanted_type->id == ZigTypeIdOptional);13608 assert(wanted_type->id == ZigTypeIdOptional);
12478 assert(instr_is_comptime(value));13609 assert(instr_is_comptime(value));
1247913610
12480 ZigValue *val = ir_resolve_const(ira, value, UndefBad);13611 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
12481 assert(val != nullptr);13612 assert(val != nullptr);
1248213613
12483 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13614 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
12484 result->value->special = ConstValSpecialStatic;13615 result->value->special = ConstValSpecialStatic;
12485 if (get_codegen_ptr_type(wanted_type) != nullptr) {13616 if (get_codegen_ptr_type(wanted_type) != nullptr) {
12486 result->value->data.x_ptr.special = ConstPtrSpecialNull;13617 result->value->data.x_ptr.special = ConstPtrSpecialNull;
...@@ -12492,8 +13623,8 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so...@@ -12492,8 +13623,8 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so
12492 return result;13623 return result;
12493}13624}
1249413625
12495static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction *source_instr,13626static IrInstGen *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInst *source_instr,
12496 IrInstruction *value, ZigType *wanted_type)13627 IrInstGen *value, ZigType *wanted_type)
12497{13628{
12498 assert(wanted_type->id == ZigTypeIdPointer);13629 assert(wanted_type->id == ZigTypeIdPointer);
12499 assert(wanted_type->data.pointer.ptr_len == PtrLenC);13630 assert(wanted_type->data.pointer.ptr_len == PtrLenC);
...@@ -12502,48 +13633,53 @@ static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction...@@ -12502,48 +13633,53 @@ static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction
12502 ZigValue *val = ir_resolve_const(ira, value, UndefBad);13633 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
12503 assert(val != nullptr);13634 assert(val != nullptr);
1250413635
12505 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13636 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
12506 result->value->data.x_ptr.special = ConstPtrSpecialNull;13637 result->value->data.x_ptr.special = ConstPtrSpecialNull;
12507 result->value->data.x_ptr.mut = ConstPtrMutComptimeConst;13638 result->value->data.x_ptr.mut = ConstPtrMutComptimeConst;
12508 return result;13639 return result;
12509}13640}
1251013641
12511static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value,13642static IrInstGen *ir_get_ref2(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *value,
12512 bool is_const, bool is_volatile)13643 ZigType *elem_type, bool is_const, bool is_volatile)
12513{13644{
12514 Error err;13645 Error err;
1251513646
12516 if (type_is_invalid(value->value->type))13647 if (type_is_invalid(elem_type))
12517 return ira->codegen->invalid_instruction;13648 return ira->codegen->invalid_inst_gen;
1251813649
12519 if (instr_is_comptime(value)) {13650 if (instr_is_comptime(value)) {
12520 ZigValue *val = ir_resolve_const(ira, value, LazyOk);13651 ZigValue *val = ir_resolve_const(ira, value, LazyOk);
12521 if (!val)13652 if (!val)
12522 return ira->codegen->invalid_instruction;13653 return ira->codegen->invalid_inst_gen;
12523 return ir_get_const_ptr(ira, source_instruction, val, value->value->type,13654 return ir_get_const_ptr(ira, source_instruction, val, elem_type,
12524 ConstPtrMutComptimeConst, is_const, is_volatile, 0);13655 ConstPtrMutComptimeConst, is_const, is_volatile, 0);
12525 }13656 }
1252613657
12527 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value->type,13658 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, elem_type,
12528 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);13659 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);
1252913660
12530 if ((err = type_resolve(ira->codegen, ptr_type, ResolveStatusZeroBitsKnown)))13661 if ((err = type_resolve(ira->codegen, ptr_type, ResolveStatusZeroBitsKnown)))
12531 return ira->codegen->invalid_instruction;13662 return ira->codegen->invalid_inst_gen;
1253213663
12533 IrInstruction *result_loc;13664 IrInstGen *result_loc;
12534 if (type_has_bits(ptr_type) && !handle_is_ptr(value->value->type)) {13665 if (type_has_bits(ptr_type) && !handle_is_ptr(elem_type)) {
12535 result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value->type, nullptr, true,13666 result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), elem_type, nullptr, true, true);
12536 false, true);
12537 } else {13667 } else {
12538 result_loc = nullptr;13668 result_loc = nullptr;
12539 }13669 }
1254013670
12541 IrInstruction *new_instruction = ir_build_ref_gen(ira, source_instruction, ptr_type, value, result_loc);13671 IrInstGen *new_instruction = ir_build_ref_gen(ira, source_instruction, ptr_type, value, result_loc);
12542 new_instruction->value->data.rh_ptr = RuntimeHintPtrStack;13672 new_instruction->value->data.rh_ptr = RuntimeHintPtrStack;
12543 return new_instruction;13673 return new_instruction;
12544}13674}
1254513675
12546static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_instr, ZigType *union_type) {13676static IrInstGen *ir_get_ref(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *value,
13677 bool is_const, bool is_volatile)
13678{
13679 return ir_get_ref2(ira, source_instruction, value, value->value->type, is_const, is_volatile);
13680}
13681
13682static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, AstNode *source_node, ZigType *union_type) {
12547 assert(union_type->id == ZigTypeIdUnion);13683 assert(union_type->id == ZigTypeIdUnion);
1254813684
12549 Error err;13685 Error err;
...@@ -12555,36 +13691,36 @@ static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_...@@ -12555,36 +13691,36 @@ static ZigType *ir_resolve_union_tag_type(IrAnalyze *ira, IrInstruction *source_
12555 assert(union_type->data.unionation.tag_type != nullptr);13691 assert(union_type->data.unionation.tag_type != nullptr);
12556 return union_type->data.unionation.tag_type;13692 return union_type->data.unionation.tag_type;
12557 } else {13693 } else {
12558 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union '%s' has no tag",13694 ErrorMsg *msg = ir_add_error_node(ira, source_node, buf_sprintf("union '%s' has no tag",
12559 buf_ptr(&union_type->name)));13695 buf_ptr(&union_type->name)));
12560 add_error_note(ira->codegen, msg, decl_node, buf_sprintf("consider 'union(enum)' here"));13696 add_error_note(ira->codegen, msg, decl_node, buf_sprintf("consider 'union(enum)' here"));
12561 return ira->codegen->builtin_types.entry_invalid;13697 return ira->codegen->builtin_types.entry_invalid;
12562 }13698 }
12563}13699}
1256413700
12565static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target) {13701static IrInstGen *ir_analyze_enum_to_int(IrAnalyze *ira, IrInst *source_instr, IrInstGen *target) {
12566 Error err;13702 Error err;
1256713703
12568 IrInstruction *enum_target;13704 IrInstGen *enum_target;
12569 ZigType *enum_type;13705 ZigType *enum_type;
12570 if (target->value->type->id == ZigTypeIdUnion) {13706 if (target->value->type->id == ZigTypeIdUnion) {
12571 enum_type = ir_resolve_union_tag_type(ira, target, target->value->type);13707 enum_type = ir_resolve_union_tag_type(ira, target->base.source_node, target->value->type);
12572 if (type_is_invalid(enum_type))13708 if (type_is_invalid(enum_type))
12573 return ira->codegen->invalid_instruction;13709 return ira->codegen->invalid_inst_gen;
12574 enum_target = ir_implicit_cast(ira, target, enum_type);13710 enum_target = ir_implicit_cast(ira, target, enum_type);
12575 if (type_is_invalid(enum_target->value->type))13711 if (type_is_invalid(enum_target->value->type))
12576 return ira->codegen->invalid_instruction;13712 return ira->codegen->invalid_inst_gen;
12577 } else if (target->value->type->id == ZigTypeIdEnum) {13713 } else if (target->value->type->id == ZigTypeIdEnum) {
12578 enum_target = target;13714 enum_target = target;
12579 enum_type = target->value->type;13715 enum_type = target->value->type;
12580 } else {13716 } else {
12581 ir_add_error(ira, target,13717 ir_add_error_node(ira, target->base.source_node,
12582 buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value->type->name)));13718 buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value->type->name)));
12583 return ira->codegen->invalid_instruction;13719 return ira->codegen->invalid_inst_gen;
12584 }13720 }
1258513721
12586 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusSizeKnown)))13722 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusSizeKnown)))
12587 return ira->codegen->invalid_instruction;13723 return ira->codegen->invalid_inst_gen;
1258813724
12589 ZigType *tag_type = enum_type->data.enumeration.tag_int_type;13725 ZigType *tag_type = enum_type->data.enumeration.tag_int_type;
12590 assert(tag_type->id == ZigTypeIdInt || tag_type->id == ZigTypeIdComptimeInt);13726 assert(tag_type->id == ZigTypeIdInt || tag_type->id == ZigTypeIdComptimeInt);
...@@ -12593,7 +13729,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour...@@ -12593,7 +13729,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
12593 if (enum_type->data.enumeration.layout == ContainerLayoutAuto &&13729 if (enum_type->data.enumeration.layout == ContainerLayoutAuto &&
12594 enum_type->data.enumeration.src_field_count == 1)13730 enum_type->data.enumeration.src_field_count == 1)
12595 {13731 {
12596 IrInstruction *result = ir_const(ira, source_instr, tag_type);13732 IrInstGen *result = ir_const(ira, source_instr, tag_type);
12597 init_const_bigint(result->value, tag_type,13733 init_const_bigint(result->value, tag_type,
12598 &enum_type->data.enumeration.fields[0].value);13734 &enum_type->data.enumeration.fields[0].value);
12599 return result;13735 return result;
...@@ -12602,20 +13738,17 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour...@@ -12602,20 +13738,17 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour
12602 if (instr_is_comptime(enum_target)) {13738 if (instr_is_comptime(enum_target)) {
12603 ZigValue *val = ir_resolve_const(ira, enum_target, UndefBad);13739 ZigValue *val = ir_resolve_const(ira, enum_target, UndefBad);
12604 if (!val)13740 if (!val)
12605 return ira->codegen->invalid_instruction;13741 return ira->codegen->invalid_inst_gen;
12606 IrInstruction *result = ir_const(ira, source_instr, tag_type);13742 IrInstGen *result = ir_const(ira, source_instr, tag_type);
12607 init_const_bigint(result->value, tag_type, &val->data.x_enum_tag);13743 init_const_bigint(result->value, tag_type, &val->data.x_enum_tag);
12608 return result;13744 return result;
12609 }13745 }
1261013746
12611 IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope,13747 return ir_build_widen_or_shorten(ira, source_instr->scope, source_instr->source_node, enum_target, tag_type);
12612 source_instr->source_node, enum_target);
12613 result->value->type = tag_type;
12614 return result;
12615}13748}
1261613749
12617static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr,13750static IrInstGen *ir_analyze_union_to_tag(IrAnalyze *ira, IrInst* source_instr,
12618 IrInstruction *target, ZigType *wanted_type)13751 IrInstGen *target, ZigType *wanted_type)
12619{13752{
12620 assert(target->value->type->id == ZigTypeIdUnion);13753 assert(target->value->type->id == ZigTypeIdUnion);
12621 assert(wanted_type->id == ZigTypeIdEnum);13754 assert(wanted_type->id == ZigTypeIdEnum);
...@@ -12624,8 +13757,8 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou...@@ -12624,8 +13757,8 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou
12624 if (instr_is_comptime(target)) {13757 if (instr_is_comptime(target)) {
12625 ZigValue *val = ir_resolve_const(ira, target, UndefBad);13758 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12626 if (!val)13759 if (!val)
12627 return ira->codegen->invalid_instruction;13760 return ira->codegen->invalid_inst_gen;
12628 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13761 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
12629 result->value->special = ConstValSpecialStatic;13762 result->value->special = ConstValSpecialStatic;
12630 result->value->type = wanted_type;13763 result->value->type = wanted_type;
12631 bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_union.tag);13764 bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_union.tag);
...@@ -12636,7 +13769,7 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou...@@ -12636,7 +13769,7 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou
12636 if (wanted_type->data.enumeration.layout == ContainerLayoutAuto &&13769 if (wanted_type->data.enumeration.layout == ContainerLayoutAuto &&
12637 wanted_type->data.enumeration.src_field_count == 1)13770 wanted_type->data.enumeration.src_field_count == 1)
12638 {13771 {
12639 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13772 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
12640 result->value->special = ConstValSpecialStatic;13773 result->value->special = ConstValSpecialStatic;
12641 result->value->type = wanted_type;13774 result->value->type = wanted_type;
12642 TypeEnumField *enum_field = target->value->type->data.unionation.fields[0].enum_field;13775 TypeEnumField *enum_field = target->value->type->data.unionation.fields[0].enum_field;
...@@ -12644,48 +13777,45 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou...@@ -12644,48 +13777,45 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou
12644 return result;13777 return result;
12645 }13778 }
1264613779
12647 IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope,13780 return ir_build_union_tag(ira, source_instr, target, wanted_type);
12648 source_instr->source_node, target);
12649 result->value->type = wanted_type;
12650 return result;
12651}13781}
1265213782
12653static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruction *source_instr,13783static IrInstGen *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInst* source_instr,
12654 IrInstruction *target, ZigType *wanted_type)13784 IrInstGen *target, ZigType *wanted_type)
12655{13785{
12656 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13786 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
12657 result->value->special = ConstValSpecialUndef;13787 result->value->special = ConstValSpecialUndef;
12658 return result;13788 return result;
12659}13789}
1266013790
12661static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *source_instr,13791static IrInstGen *ir_analyze_enum_to_union(IrAnalyze *ira, IrInst* source_instr,
12662 IrInstruction *uncasted_target, ZigType *wanted_type)13792 IrInstGen *uncasted_target, ZigType *wanted_type)
12663{13793{
12664 Error err;13794 Error err;
12665 assert(wanted_type->id == ZigTypeIdUnion);13795 assert(wanted_type->id == ZigTypeIdUnion);
1266613796
12667 if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusZeroBitsKnown)))13797 if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusZeroBitsKnown)))
12668 return ira->codegen->invalid_instruction;13798 return ira->codegen->invalid_inst_gen;
1266913799
12670 IrInstruction *target = ir_implicit_cast(ira, uncasted_target, wanted_type->data.unionation.tag_type);13800 IrInstGen *target = ir_implicit_cast(ira, uncasted_target, wanted_type->data.unionation.tag_type);
12671 if (type_is_invalid(target->value->type))13801 if (type_is_invalid(target->value->type))
12672 return ira->codegen->invalid_instruction;13802 return ira->codegen->invalid_inst_gen;
1267313803
12674 if (instr_is_comptime(target)) {13804 if (instr_is_comptime(target)) {
12675 ZigValue *val = ir_resolve_const(ira, target, UndefBad);13805 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12676 if (!val)13806 if (!val)
12677 return ira->codegen->invalid_instruction;13807 return ira->codegen->invalid_inst_gen;
12678 TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag);13808 TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag);
12679 assert(union_field != nullptr);13809 assert(union_field != nullptr);
12680 ZigType *field_type = resolve_union_field_type(ira->codegen, union_field);13810 ZigType *field_type = resolve_union_field_type(ira->codegen, union_field);
12681 if (field_type == nullptr)13811 if (field_type == nullptr)
12682 return ira->codegen->invalid_instruction;13812 return ira->codegen->invalid_inst_gen;
12683 if ((err = type_resolve(ira->codegen, field_type, ResolveStatusZeroBitsKnown)))13813 if ((err = type_resolve(ira->codegen, field_type, ResolveStatusZeroBitsKnown)))
12684 return ira->codegen->invalid_instruction;13814 return ira->codegen->invalid_inst_gen;
1268513815
12686 switch (type_has_one_possible_value(ira->codegen, field_type)) {13816 switch (type_has_one_possible_value(ira->codegen, field_type)) {
12687 case OnePossibleValueInvalid:13817 case OnePossibleValueInvalid:
12688 return ira->codegen->invalid_instruction;13818 return ira->codegen->invalid_inst_gen;
12689 case OnePossibleValueNo: {13819 case OnePossibleValueNo: {
12690 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(13820 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(
12691 union_field->enum_field->decl_index);13821 union_field->enum_field->decl_index);
...@@ -12696,13 +13826,13 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so...@@ -12696,13 +13826,13 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
12696 buf_ptr(union_field->name)));13826 buf_ptr(union_field->name)));
12697 add_error_note(ira->codegen, msg, field_node,13827 add_error_note(ira->codegen, msg, field_node,
12698 buf_sprintf("field '%s' declared here", buf_ptr(union_field->name)));13828 buf_sprintf("field '%s' declared here", buf_ptr(union_field->name)));
12699 return ira->codegen->invalid_instruction;13829 return ira->codegen->invalid_inst_gen;
12700 }13830 }
12701 case OnePossibleValueYes:13831 case OnePossibleValueYes:
12702 break;13832 break;
12703 }13833 }
1270413834
12705 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13835 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
12706 result->value->special = ConstValSpecialStatic;13836 result->value->special = ConstValSpecialStatic;
12707 result->value->type = wanted_type;13837 result->value->type = wanted_type;
12708 bigint_init_bigint(&result->value->data.x_union.tag, &val->data.x_enum_tag);13838 bigint_init_bigint(&result->value->data.x_union.tag, &val->data.x_enum_tag);
...@@ -12715,9 +13845,7 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so...@@ -12715,9 +13845,7 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
12715 // if the union has all fields 0 bits, we can do it13845 // if the union has all fields 0 bits, we can do it
12716 // and in fact it's a noop cast because the union value is just the enum value13846 // and in fact it's a noop cast because the union value is just the enum value
12717 if (wanted_type->data.unionation.gen_field_count == 0) {13847 if (wanted_type->data.unionation.gen_field_count == 0) {
12718 IrInstruction *result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, wanted_type, target, CastOpNoop);13848 return ir_build_cast(ira, &target->base, wanted_type, target, CastOpNoop);
12719 result->value->type = wanted_type;
12720 return result;
12721 }13849 }
1272213850
12723 ErrorMsg *msg = ir_add_error(ira, source_instr,13851 ErrorMsg *msg = ir_add_error(ira, source_instr,
...@@ -12727,10 +13855,10 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so...@@ -12727,10 +13855,10 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
12727 TypeUnionField *union_field = &wanted_type->data.unionation.fields[i];13855 TypeUnionField *union_field = &wanted_type->data.unionation.fields[i];
12728 ZigType *field_type = resolve_union_field_type(ira->codegen, union_field);13856 ZigType *field_type = resolve_union_field_type(ira->codegen, union_field);
12729 if (field_type == nullptr)13857 if (field_type == nullptr)
12730 return ira->codegen->invalid_instruction;13858 return ira->codegen->invalid_inst_gen;
12731 bool has_bits;13859 bool has_bits;
12732 if ((err = type_has_bits2(ira->codegen, field_type, &has_bits)))13860 if ((err = type_has_bits2(ira->codegen, field_type, &has_bits)))
12733 return ira->codegen->invalid_instruction;13861 return ira->codegen->invalid_inst_gen;
12734 if (has_bits) {13862 if (has_bits) {
12735 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(i);13863 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(i);
12736 add_error_note(ira->codegen, msg, field_node,13864 add_error_note(ira->codegen, msg, field_node,
...@@ -12739,23 +13867,23 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so...@@ -12739,23 +13867,23 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
12739 buf_ptr(&field_type->name)));13867 buf_ptr(&field_type->name)));
12740 }13868 }
12741 }13869 }
12742 return ira->codegen->invalid_instruction;13870 return ira->codegen->invalid_inst_gen;
12743}13871}
1274413872
12745static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction *source_instr,13873static IrInstGen *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInst* source_instr,
12746 IrInstruction *target, ZigType *wanted_type)13874 IrInstGen *target, ZigType *wanted_type)
12747{13875{
12748 assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat);13876 assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat);
1274913877
12750 if (instr_is_comptime(target)) {13878 if (instr_is_comptime(target)) {
12751 ZigValue *val = ir_resolve_const(ira, target, UndefBad);13879 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12752 if (!val)13880 if (!val)
12753 return ira->codegen->invalid_instruction;13881 return ira->codegen->invalid_inst_gen;
12754 if (wanted_type->id == ZigTypeIdInt) {13882 if (wanted_type->id == ZigTypeIdInt) {
12755 if (bigint_cmp_zero(&val->data.x_bigint) == CmpLT && !wanted_type->data.integral.is_signed) {13883 if (bigint_cmp_zero(&val->data.x_bigint) == CmpLT && !wanted_type->data.integral.is_signed) {
12756 ir_add_error(ira, source_instr,13884 ir_add_error(ira, source_instr,
12757 buf_sprintf("attempt to cast negative value to unsigned integer"));13885 buf_sprintf("attempt to cast negative value to unsigned integer"));
12758 return ira->codegen->invalid_instruction;13886 return ira->codegen->invalid_inst_gen;
12759 }13887 }
12760 if (!bigint_fits_in_bits(&val->data.x_bigint, wanted_type->data.integral.bit_count,13888 if (!bigint_fits_in_bits(&val->data.x_bigint, wanted_type->data.integral.bit_count,
12761 wanted_type->data.integral.is_signed))13889 wanted_type->data.integral.is_signed))
...@@ -12763,10 +13891,10 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction...@@ -12763,10 +13891,10 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
12763 ir_add_error(ira, source_instr,13891 ir_add_error(ira, source_instr,
12764 buf_sprintf("cast from '%s' to '%s' truncates bits",13892 buf_sprintf("cast from '%s' to '%s' truncates bits",
12765 buf_ptr(&target->value->type->name), buf_ptr(&wanted_type->name)));13893 buf_ptr(&target->value->type->name), buf_ptr(&wanted_type->name)));
12766 return ira->codegen->invalid_instruction;13894 return ira->codegen->invalid_inst_gen;
12767 }13895 }
12768 }13896 }
12769 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13897 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
12770 result->value->type = wanted_type;13898 result->value->type = wanted_type;
12771 if (wanted_type->id == ZigTypeIdInt) {13899 if (wanted_type->id == ZigTypeIdInt) {
12772 bigint_init_bigint(&result->value->data.x_bigint, &val->data.x_bigint);13900 bigint_init_bigint(&result->value->data.x_bigint, &val->data.x_bigint);
...@@ -12783,19 +13911,16 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction...@@ -12783,19 +13911,16 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction
12783 assert(wanted_type->id == ZigTypeIdInt);13911 assert(wanted_type->id == ZigTypeIdInt);
12784 assert(type_has_bits(target->value->type));13912 assert(type_has_bits(target->value->type));
12785 ir_build_assert_zero(ira, source_instr, target);13913 ir_build_assert_zero(ira, source_instr, target);
12786 IrInstruction *result = ir_const_unsigned(ira, source_instr, 0);13914 IrInstGen *result = ir_const_unsigned(ira, source_instr, 0);
12787 result->value->type = wanted_type;13915 result->value->type = wanted_type;
12788 return result;13916 return result;
12789 }13917 }
1279013918
12791 IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope,13919 return ir_build_widen_or_shorten(ira, source_instr->scope, source_instr->source_node, target, wanted_type);
12792 source_instr->source_node, target);
12793 result->value->type = wanted_type;
12794 return result;
12795}13920}
1279613921
12797static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *source_instr,13922static IrInstGen *ir_analyze_int_to_enum(IrAnalyze *ira, IrInst* source_instr,
12798 IrInstruction *target, ZigType *wanted_type)13923 IrInstGen *target, ZigType *wanted_type)
12799{13924{
12800 Error err;13925 Error err;
12801 assert(wanted_type->id == ZigTypeIdEnum);13926 assert(wanted_type->id == ZigTypeIdEnum);
...@@ -12803,14 +13928,14 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour...@@ -12803,14 +13928,14 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
12803 ZigType *actual_type = target->value->type;13928 ZigType *actual_type = target->value->type;
1280413929
12805 if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusSizeKnown)))13930 if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusSizeKnown)))
12806 return ira->codegen->invalid_instruction;13931 return ira->codegen->invalid_inst_gen;
1280713932
12808 if (actual_type != wanted_type->data.enumeration.tag_int_type) {13933 if (actual_type != wanted_type->data.enumeration.tag_int_type) {
12809 ir_add_error(ira, source_instr,13934 ir_add_error(ira, source_instr,
12810 buf_sprintf("integer to enum cast from '%s' instead of its tag type, '%s'",13935 buf_sprintf("integer to enum cast from '%s' instead of its tag type, '%s'",
12811 buf_ptr(&actual_type->name),13936 buf_ptr(&actual_type->name),
12812 buf_ptr(&wanted_type->data.enumeration.tag_int_type->name)));13937 buf_ptr(&wanted_type->data.enumeration.tag_int_type->name)));
12813 return ira->codegen->invalid_instruction;13938 return ira->codegen->invalid_inst_gen;
12814 }13939 }
1281513940
12816 assert(actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt);13941 assert(actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt);
...@@ -12818,7 +13943,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour...@@ -12818,7 +13943,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
12818 if (instr_is_comptime(target)) {13943 if (instr_is_comptime(target)) {
12819 ZigValue *val = ir_resolve_const(ira, target, UndefBad);13944 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12820 if (!val)13945 if (!val)
12821 return ira->codegen->invalid_instruction;13946 return ira->codegen->invalid_inst_gen;
1282213947
12823 TypeEnumField *field = find_enum_field_by_tag(wanted_type, &val->data.x_bigint);13948 TypeEnumField *field = find_enum_field_by_tag(wanted_type, &val->data.x_bigint);
12824 if (field == nullptr && !wanted_type->data.enumeration.non_exhaustive) {13949 if (field == nullptr && !wanted_type->data.enumeration.non_exhaustive) {
...@@ -12829,28 +13954,25 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour...@@ -12829,28 +13954,25 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour
12829 buf_ptr(&wanted_type->name), buf_ptr(val_buf)));13954 buf_ptr(&wanted_type->name), buf_ptr(val_buf)));
12830 add_error_note(ira->codegen, msg, wanted_type->data.enumeration.decl_node,13955 add_error_note(ira->codegen, msg, wanted_type->data.enumeration.decl_node,
12831 buf_sprintf("'%s' declared here", buf_ptr(&wanted_type->name)));13956 buf_sprintf("'%s' declared here", buf_ptr(&wanted_type->name)));
12832 return ira->codegen->invalid_instruction;13957 return ira->codegen->invalid_inst_gen;
12833 }13958 }
1283413959
12835 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13960 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
12836 bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_bigint);13961 bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_bigint);
12837 return result;13962 return result;
12838 }13963 }
1283913964
12840 IrInstruction *result = ir_build_int_to_enum(&ira->new_irb, source_instr->scope,13965 return ir_build_int_to_enum_gen(ira, source_instr->scope, source_instr->source_node, wanted_type, target);
12841 source_instr->source_node, nullptr, target);
12842 result->value->type = wanted_type;
12843 return result;
12844}13966}
1284513967
12846static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction *source_instr,13968static IrInstGen *ir_analyze_number_to_literal(IrAnalyze *ira, IrInst* source_instr,
12847 IrInstruction *target, ZigType *wanted_type)13969 IrInstGen *target, ZigType *wanted_type)
12848{13970{
12849 ZigValue *val = ir_resolve_const(ira, target, UndefBad);13971 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12850 if (!val)13972 if (!val)
12851 return ira->codegen->invalid_instruction;13973 return ira->codegen->invalid_inst_gen;
1285213974
12853 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13975 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
12854 if (wanted_type->id == ZigTypeIdComptimeFloat) {13976 if (wanted_type->id == ZigTypeIdComptimeFloat) {
12855 float_init_float(result->value, val);13977 float_init_float(result->value, val);
12856 } else if (wanted_type->id == ZigTypeIdComptimeInt) {13978 } else if (wanted_type->id == ZigTypeIdComptimeInt) {
...@@ -12861,7 +13983,7 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction...@@ -12861,7 +13983,7 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction
12861 return result;13983 return result;
12862}13984}
1286313985
12864static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,13986static IrInstGen *ir_analyze_int_to_err(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,
12865 ZigType *wanted_type)13987 ZigType *wanted_type)
12866{13988{
12867 assert(target->value->type->id == ZigTypeIdInt);13989 assert(target->value->type->id == ZigTypeIdInt);
...@@ -12871,12 +13993,12 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc...@@ -12871,12 +13993,12 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
12871 if (instr_is_comptime(target)) {13993 if (instr_is_comptime(target)) {
12872 ZigValue *val = ir_resolve_const(ira, target, UndefBad);13994 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12873 if (!val)13995 if (!val)
12874 return ira->codegen->invalid_instruction;13996 return ira->codegen->invalid_inst_gen;
1287513997
12876 IrInstruction *result = ir_const(ira, source_instr, wanted_type);13998 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1287713999
12878 if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) {14000 if (!resolve_inferred_error_set(ira->codegen, wanted_type, source_instr->source_node)) {
12879 return ira->codegen->invalid_instruction;14001 return ira->codegen->invalid_inst_gen;
12880 }14002 }
1288114003
12882 if (type_is_global_error_set(wanted_type)) {14004 if (type_is_global_error_set(wanted_type)) {
...@@ -12888,7 +14010,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc...@@ -12888,7 +14010,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
12888 bigint_append_buf(val_buf, &val->data.x_bigint, 10);14010 bigint_append_buf(val_buf, &val->data.x_bigint, 10);
12889 ir_add_error(ira, source_instr,14011 ir_add_error(ira, source_instr,
12890 buf_sprintf("integer value %s represents no error", buf_ptr(val_buf)));14012 buf_sprintf("integer value %s represents no error", buf_ptr(val_buf)));
12891 return ira->codegen->invalid_instruction;14013 return ira->codegen->invalid_inst_gen;
12892 }14014 }
1289314015
12894 size_t index = bigint_as_usize(&val->data.x_bigint);14016 size_t index = bigint_as_usize(&val->data.x_bigint);
...@@ -12912,7 +14034,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc...@@ -12912,7 +14034,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
12912 bigint_append_buf(val_buf, &val->data.x_bigint, 10);14034 bigint_append_buf(val_buf, &val->data.x_bigint, 10);
12913 ir_add_error(ira, source_instr,14035 ir_add_error(ira, source_instr,
12914 buf_sprintf("integer value %s represents no error in '%s'", buf_ptr(val_buf), buf_ptr(&wanted_type->name)));14036 buf_sprintf("integer value %s represents no error in '%s'", buf_ptr(val_buf), buf_ptr(&wanted_type->name)));
12915 return ira->codegen->invalid_instruction;14037 return ira->codegen->invalid_inst_gen;
12916 }14038 }
1291714039
12918 result->value->data.x_err_set = err;14040 result->value->data.x_err_set = err;
...@@ -12920,12 +14042,10 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc...@@ -12920,12 +14042,10 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc
12920 }14042 }
12921 }14043 }
1292214044
12923 IrInstruction *result = ir_build_int_to_err(&ira->new_irb, source_instr->scope, source_instr->source_node, target);14045 return ir_build_int_to_err_gen(ira, source_instr->scope, source_instr->source_node, target, wanted_type);
12924 result->value->type = wanted_type;
12925 return result;
12926}14046}
1292714047
12928static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,14048static IrInstGen *ir_analyze_err_to_int(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,
12929 ZigType *wanted_type)14049 ZigType *wanted_type)
12930{14050{
12931 assert(wanted_type->id == ZigTypeIdInt);14051 assert(wanted_type->id == ZigTypeIdInt);
...@@ -12935,9 +14055,9 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -12935,9 +14055,9 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
12935 if (instr_is_comptime(target)) {14055 if (instr_is_comptime(target)) {
12936 ZigValue *val = ir_resolve_const(ira, target, UndefBad);14056 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
12937 if (!val)14057 if (!val)
12938 return ira->codegen->invalid_instruction;14058 return ira->codegen->invalid_inst_gen;
1293914059
12940 IrInstruction *result = ir_const(ira, source_instr, wanted_type);14060 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
1294114061
12942 ErrorTableEntry *err;14062 ErrorTableEntry *err;
12943 if (err_type->id == ZigTypeIdErrorUnion) {14063 if (err_type->id == ZigTypeIdErrorUnion) {
...@@ -12957,7 +14077,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -12957,7 +14077,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
12957 ir_add_error_node(ira, source_instr->source_node,14077 ir_add_error_node(ira, source_instr->source_node,
12958 buf_sprintf("error code '%s' does not fit in '%s'",14078 buf_sprintf("error code '%s' does not fit in '%s'",
12959 buf_ptr(&err->name), buf_ptr(&wanted_type->name)));14079 buf_ptr(&err->name), buf_ptr(&wanted_type->name)));
12960 return ira->codegen->invalid_instruction;14080 return ira->codegen->invalid_inst_gen;
12961 }14081 }
1296214082
12963 return result;14083 return result;
...@@ -12973,14 +14093,14 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -12973,14 +14093,14 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
12973 }14093 }
12974 if (!type_is_global_error_set(err_set_type)) {14094 if (!type_is_global_error_set(err_set_type)) {
12975 if (!resolve_inferred_error_set(ira->codegen, err_set_type, source_instr->source_node)) {14095 if (!resolve_inferred_error_set(ira->codegen, err_set_type, source_instr->source_node)) {
12976 return ira->codegen->invalid_instruction;14096 return ira->codegen->invalid_inst_gen;
12977 }14097 }
12978 if (err_set_type->data.error_set.err_count == 0) {14098 if (err_set_type->data.error_set.err_count == 0) {
12979 IrInstruction *result = ir_const(ira, source_instr, wanted_type);14099 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
12980 bigint_init_unsigned(&result->value->data.x_bigint, 0);14100 bigint_init_unsigned(&result->value->data.x_bigint, 0);
12981 return result;14101 return result;
12982 } else if (err_set_type->data.error_set.err_count == 1) {14102 } else if (err_set_type->data.error_set.err_count == 1) {
12983 IrInstruction *result = ir_const(ira, source_instr, wanted_type);14103 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
12984 ErrorTableEntry *err = err_set_type->data.error_set.errors[0];14104 ErrorTableEntry *err = err_set_type->data.error_set.errors[0];
12985 bigint_init_unsigned(&result->value->data.x_bigint, err->value);14105 bigint_init_unsigned(&result->value->data.x_bigint, err->value);
12986 return result;14106 return result;
...@@ -12992,21 +14112,19 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc...@@ -12992,21 +14112,19 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc
12992 if (!bigint_fits_in_bits(&bn, wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed)) {14112 if (!bigint_fits_in_bits(&bn, wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed)) {
12993 ir_add_error_node(ira, source_instr->source_node,14113 ir_add_error_node(ira, source_instr->source_node,
12994 buf_sprintf("too many error values to fit in '%s'", buf_ptr(&wanted_type->name)));14114 buf_sprintf("too many error values to fit in '%s'", buf_ptr(&wanted_type->name)));
12995 return ira->codegen->invalid_instruction;14115 return ira->codegen->invalid_inst_gen;
12996 }14116 }
1299714117
12998 IrInstruction *result = ir_build_err_to_int(&ira->new_irb, source_instr->scope, source_instr->source_node, target);14118 return ir_build_err_to_int_gen(ira, source_instr->scope, source_instr->source_node, target, wanted_type);
12999 result->value->type = wanted_type;
13000 return result;
13001}14119}
1300214120
13003static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,14121static IrInstGen *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,
13004 ZigType *wanted_type)14122 ZigType *wanted_type)
13005{14123{
13006 assert(wanted_type->id == ZigTypeIdPointer);14124 assert(wanted_type->id == ZigTypeIdPointer);
13007 Error err;14125 Error err;
13008 if ((err = type_resolve(ira->codegen, target->value->type->data.pointer.child_type, ResolveStatusAlignmentKnown)))14126 if ((err = type_resolve(ira->codegen, target->value->type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
13009 return ira->codegen->invalid_instruction;14127 return ira->codegen->invalid_inst_gen;
13010 assert((wanted_type->data.pointer.is_const && target->value->type->data.pointer.is_const) || !target->value->type->data.pointer.is_const);14128 assert((wanted_type->data.pointer.is_const && target->value->type->data.pointer.is_const) || !target->value->type->data.pointer.is_const);
13011 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, target->value->type));14129 wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, target->value->type));
13012 ZigType *array_type = wanted_type->data.pointer.child_type;14130 ZigType *array_type = wanted_type->data.pointer.child_type;
...@@ -13016,12 +14134,12 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou...@@ -13016,12 +14134,12 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
13016 if (instr_is_comptime(target)) {14134 if (instr_is_comptime(target)) {
13017 ZigValue *val = ir_resolve_const(ira, target, UndefBad);14135 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
13018 if (!val)14136 if (!val)
13019 return ira->codegen->invalid_instruction;14137 return ira->codegen->invalid_inst_gen;
1302014138
13021 assert(val->type->id == ZigTypeIdPointer);14139 assert(val->type->id == ZigTypeIdPointer);
13022 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);14140 ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);
13023 if (pointee == nullptr)14141 if (pointee == nullptr)
13024 return ira->codegen->invalid_instruction;14142 return ira->codegen->invalid_inst_gen;
13025 if (pointee->special != ConstValSpecialRuntime) {14143 if (pointee->special != ConstValSpecialRuntime) {
13026 ZigValue *array_val = create_const_vals(1);14144 ZigValue *array_val = create_const_vals(1);
13027 array_val->special = ConstValSpecialStatic;14145 array_val->special = ConstValSpecialStatic;
...@@ -13031,7 +14149,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou...@@ -13031,7 +14149,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
13031 array_val->parent.id = ConstParentIdScalar;14149 array_val->parent.id = ConstParentIdScalar;
13032 array_val->parent.data.p_scalar.scalar_val = pointee;14150 array_val->parent.data.p_scalar.scalar_val = pointee;
1303314151
13034 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,14152 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
13035 source_instr->scope, source_instr->source_node);14153 source_instr->scope, source_instr->source_node);
13036 const_instruction->base.value->type = wanted_type;14154 const_instruction->base.value->type = wanted_type;
13037 const_instruction->base.value->special = ConstValSpecialStatic;14155 const_instruction->base.value->special = ConstValSpecialStatic;
...@@ -13043,10 +14161,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou...@@ -13043,10 +14161,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou
13043 }14161 }
1304414162
13045 // pointer to array and pointer to single item are represented the same way at runtime14163 // pointer to array and pointer to single item are represented the same way at runtime
13046 IrInstruction *result = ir_build_cast(&ira->new_irb, target->scope, target->source_node,14164 return ir_build_cast(ira, &target->base, wanted_type, target, CastOpBitCast);
13047 wanted_type, target, CastOpBitCast);
13048 result->value->type = wanted_type;
13049 return result;
13050}14165}
1305114166
13052static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCastOnly *cast_result,14167static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCastOnly *cast_result,
...@@ -13234,12 +14349,12 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa...@@ -13234,12 +14349,12 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa
13234 }14349 }
13235}14350}
1323614351
13237static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *source_instr,14352static IrInstGen *ir_analyze_array_to_vector(IrAnalyze *ira, IrInst* source_instr,
13238 IrInstruction *array, ZigType *vector_type)14353 IrInstGen *array, ZigType *vector_type)
13239{14354{
13240 if (instr_is_comptime(array)) {14355 if (instr_is_comptime(array)) {
13241 // arrays and vectors have the same ZigValue representation14356 // arrays and vectors have the same ZigValue representation
13242 IrInstruction *result = ir_const(ira, source_instr, vector_type);14357 IrInstGen *result = ir_const(ira, source_instr, vector_type);
13243 copy_const_val(result->value, array->value);14358 copy_const_val(result->value, array->value);
13244 result->value->type = vector_type;14359 result->value->type = vector_type;
13245 return result;14360 return result;
...@@ -13247,12 +14362,12 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *...@@ -13247,12 +14362,12 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction *
13247 return ir_build_array_to_vector(ira, source_instr, array, vector_type);14362 return ir_build_array_to_vector(ira, source_instr, array, vector_type);
13248}14363}
1324914364
13250static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *source_instr,14365static IrInstGen *ir_analyze_vector_to_array(IrAnalyze *ira, IrInst* source_instr,
13251 IrInstruction *vector, ZigType *array_type, ResultLoc *result_loc)14366 IrInstGen *vector, ZigType *array_type, ResultLoc *result_loc)
13252{14367{
13253 if (instr_is_comptime(vector)) {14368 if (instr_is_comptime(vector)) {
13254 // arrays and vectors have the same ZigValue representation14369 // arrays and vectors have the same ZigValue representation
13255 IrInstruction *result = ir_const(ira, source_instr, array_type);14370 IrInstGen *result = ir_const(ira, source_instr, array_type);
13256 copy_const_val(result->value, vector->value);14371 copy_const_val(result->value, vector->value);
13257 result->value->type = array_type;14372 result->value->type = array_type;
13258 return result;14373 return result;
...@@ -13260,18 +14375,17 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *...@@ -13260,18 +14375,17 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *
13260 if (result_loc == nullptr) {14375 if (result_loc == nullptr) {
13261 result_loc = no_result_loc();14376 result_loc = no_result_loc();
13262 }14377 }
13263 IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr,14378 IrInstGen *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, true, true);
13264 true, false, true);14379 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
13265 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
13266 return result_loc_inst;14380 return result_loc_inst;
13267 }14381 }
13268 return ir_build_vector_to_array(ira, source_instr, array_type, vector, result_loc_inst);14382 return ir_build_vector_to_array(ira, source_instr, array_type, vector, result_loc_inst);
13269}14383}
1327014384
13271static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *source_instr,14385static IrInstGen *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInst* source_instr,
13272 IrInstruction *integer, ZigType *dest_type)14386 IrInstGen *integer, ZigType *dest_type)
13273{14387{
13274 IrInstruction *unsigned_integer;14388 IrInstGen *unsigned_integer;
13275 if (instr_is_comptime(integer)) {14389 if (instr_is_comptime(integer)) {
13276 unsigned_integer = integer;14390 unsigned_integer = integer;
13277 } else {14391 } else {
...@@ -13284,7 +14398,7 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou...@@ -13284,7 +14398,7 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou
13284 buf_sprintf("integer type '%s' too big for implicit @intToPtr to type '%s'",14398 buf_sprintf("integer type '%s' too big for implicit @intToPtr to type '%s'",
13285 buf_ptr(&integer->value->type->name),14399 buf_ptr(&integer->value->type->name),
13286 buf_ptr(&dest_type->name)));14400 buf_ptr(&dest_type->name)));
13287 return ira->codegen->invalid_instruction;14401 return ira->codegen->invalid_inst_gen;
13288 }14402 }
1328914403
13290 if (integer->value->type->data.integral.is_signed) {14404 if (integer->value->type->data.integral.is_signed) {
...@@ -13292,7 +14406,7 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou...@@ -13292,7 +14406,7 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou
13292 integer->value->type->data.integral.bit_count);14406 integer->value->type->data.integral.bit_count);
13293 unsigned_integer = ir_analyze_bit_cast(ira, source_instr, integer, unsigned_int_type);14407 unsigned_integer = ir_analyze_bit_cast(ira, source_instr, integer, unsigned_int_type);
13294 if (type_is_invalid(unsigned_integer->value->type))14408 if (type_is_invalid(unsigned_integer->value->type))
13295 return ira->codegen->invalid_instruction;14409 return ira->codegen->invalid_inst_gen;
13296 } else {14410 } else {
13297 unsigned_integer = integer;14411 unsigned_integer = integer;
13298 }14412 }
...@@ -13312,14 +14426,14 @@ static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) {...@@ -13312,14 +14426,14 @@ static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) {
13312 return false;14426 return false;
13313}14427}
1331414428
13315static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,14429static IrInstGen *ir_analyze_enum_literal(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,
13316 ZigType *enum_type)14430 ZigType *enum_type)
13317{14431{
13318 assert(enum_type->id == ZigTypeIdEnum);14432 assert(enum_type->id == ZigTypeIdEnum);
1331914433
13320 Error err;14434 Error err;
13321 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusZeroBitsKnown)))14435 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusZeroBitsKnown)))
13322 return ira->codegen->invalid_instruction;14436 return ira->codegen->invalid_inst_gen;
1332314437
13324 TypeEnumField *field = find_enum_type_field(enum_type, value->value->data.x_enum_literal);14438 TypeEnumField *field = find_enum_type_field(enum_type, value->value->data.x_enum_literal);
13325 if (field == nullptr) {14439 if (field == nullptr) {
...@@ -13327,40 +14441,40 @@ static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *sou...@@ -13327,40 +14441,40 @@ static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *sou
13327 buf_ptr(&enum_type->name), buf_ptr(value->value->data.x_enum_literal)));14441 buf_ptr(&enum_type->name), buf_ptr(value->value->data.x_enum_literal)));
13328 add_error_note(ira->codegen, msg, enum_type->data.enumeration.decl_node,14442 add_error_note(ira->codegen, msg, enum_type->data.enumeration.decl_node,
13329 buf_sprintf("'%s' declared here", buf_ptr(&enum_type->name)));14443 buf_sprintf("'%s' declared here", buf_ptr(&enum_type->name)));
13330 return ira->codegen->invalid_instruction;14444 return ira->codegen->invalid_inst_gen;
13331 }14445 }
13332 IrInstruction *result = ir_const(ira, source_instr, enum_type);14446 IrInstGen *result = ir_const(ira, source_instr, enum_type);
13333 bigint_init_bigint(&result->value->data.x_enum_tag, &field->value);14447 bigint_init_bigint(&result->value->data.x_enum_tag, &field->value);
1333414448
13335 return result;14449 return result;
13336}14450}
1333714451
13338static IrInstruction *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInstruction *source_instr,14452static IrInstGen *ir_analyze_struct_literal_to_array(IrAnalyze *ira, IrInst* source_instr,
13339 IrInstruction *value, ZigType *wanted_type)14453 IrInstGen *value, ZigType *wanted_type)
13340{14454{
13341 ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon list literal to array"));14455 ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon list literal to array"));
13342 return ira->codegen->invalid_instruction;14456 return ira->codegen->invalid_inst_gen;
13343}14457}
1334414458
13345static IrInstruction *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInstruction *source_instr,14459static IrInstGen *ir_analyze_struct_literal_to_struct(IrAnalyze *ira, IrInst* source_instr,
13346 IrInstruction *value, ZigType *wanted_type)14460 IrInstGen *value, ZigType *wanted_type)
13347{14461{
13348 ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon struct literal to struct"));14462 ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon struct literal to struct"));
13349 return ira->codegen->invalid_instruction;14463 return ira->codegen->invalid_inst_gen;
13350}14464}
1335114465
13352static IrInstruction *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInstruction *source_instr,14466static IrInstGen *ir_analyze_struct_literal_to_union(IrAnalyze *ira, IrInst* source_instr,
13353 IrInstruction *value, ZigType *wanted_type)14467 IrInstGen *value, ZigType *wanted_type)
13354{14468{
13355 ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon struct literal to union"));14469 ir_add_error(ira, source_instr, buf_sprintf("TODO: type coercion of anon struct literal to union"));
13356 return ira->codegen->invalid_instruction;14470 return ira->codegen->invalid_inst_gen;
13357}14471}
1335814472
13359// Add a compile error and return ErrorSemanticAnalyzeFail if the pointer alignment does not work,14473// Add a compile error and return ErrorSemanticAnalyzeFail if the pointer alignment does not work,
13360// otherwise return ErrorNone. Does not emit any instructions.14474// otherwise return ErrorNone. Does not emit any instructions.
13361// Assumes that the pointer types have element types with the same ABI alignment. Avoids resolving the14475// Assumes that the pointer types have element types with the same ABI alignment. Avoids resolving the
13362// pointer types' alignments if both of the pointer types are ABI aligned.14476// pointer types' alignments if both of the pointer types are ABI aligned.
13363static Error ir_cast_ptr_align(IrAnalyze *ira, IrInstruction *source_instr, ZigType *dest_ptr_type,14477static Error ir_cast_ptr_align(IrAnalyze *ira, IrInst* source_instr, ZigType *dest_ptr_type,
13364 ZigType *src_ptr_type, AstNode *src_source_node)14478 ZigType *src_ptr_type, AstNode *src_source_node)
13365{14479{
13366 Error err;14480 Error err;
...@@ -13394,37 +14508,37 @@ static Error ir_cast_ptr_align(IrAnalyze *ira, IrInstruction *source_instr, ZigT...@@ -13394,37 +14508,37 @@ static Error ir_cast_ptr_align(IrAnalyze *ira, IrInstruction *source_instr, ZigT
13394 return ErrorNone;14508 return ErrorNone;
13395}14509}
1339614510
13397static IrInstruction *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInstruction *source_instr,14511static IrInstGen *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInst* source_instr,
13398 IrInstruction *struct_operand, TypeStructField *field)14512 IrInstGen *struct_operand, TypeStructField *field)
13399{14513{
13400 IrInstruction *struct_ptr = ir_get_ref(ira, source_instr, struct_operand, true, false);14514 IrInstGen *struct_ptr = ir_get_ref(ira, source_instr, struct_operand, true, false);
13401 if (type_is_invalid(struct_ptr->value->type))14515 if (type_is_invalid(struct_ptr->value->type))
13402 return ira->codegen->invalid_instruction;14516 return ira->codegen->invalid_inst_gen;
13403 IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, struct_ptr,14517 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, struct_ptr,
13404 struct_operand->value->type, false);14518 struct_operand->value->type, false);
13405 if (type_is_invalid(field_ptr->value->type))14519 if (type_is_invalid(field_ptr->value->type))
13406 return ira->codegen->invalid_instruction;14520 return ira->codegen->invalid_inst_gen;
13407 return ir_get_deref(ira, source_instr, field_ptr, nullptr);14521 return ir_get_deref(ira, source_instr, field_ptr, nullptr);
13408}14522}
1340914523
13410static IrInstruction *ir_analyze_optional_value_payload_value(IrAnalyze *ira, IrInstruction *source_instr,14524static IrInstGen *ir_analyze_optional_value_payload_value(IrAnalyze *ira, IrInst* source_instr,
13411 IrInstruction *optional_operand, bool safety_check_on)14525 IrInstGen *optional_operand, bool safety_check_on)
13412{14526{
13413 IrInstruction *opt_ptr = ir_get_ref(ira, source_instr, optional_operand, true, false);14527 IrInstGen *opt_ptr = ir_get_ref(ira, source_instr, optional_operand, true, false);
13414 IrInstruction *payload_ptr = ir_analyze_unwrap_optional_payload(ira, source_instr, opt_ptr,14528 IrInstGen *payload_ptr = ir_analyze_unwrap_optional_payload(ira, source_instr, opt_ptr,
13415 safety_check_on, false);14529 safety_check_on, false);
13416 return ir_get_deref(ira, source_instr, payload_ptr, nullptr);14530 return ir_get_deref(ira, source_instr, payload_ptr, nullptr);
13417}14531}
1341814532
13419static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_instr,14533static IrInstGen *ir_analyze_cast(IrAnalyze *ira, IrInst *source_instr,
13420 ZigType *wanted_type, IrInstruction *value)14534 ZigType *wanted_type, IrInstGen *value)
13421{14535{
13422 Error err;14536 Error err;
13423 ZigType *actual_type = value->value->type;14537 ZigType *actual_type = value->value->type;
13424 AstNode *source_node = source_instr->source_node;14538 AstNode *source_node = source_instr->source_node;
1342514539
13426 if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) {14540 if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) {
13427 return ira->codegen->invalid_instruction;14541 return ira->codegen->invalid_inst_gen;
13428 }14542 }
1342914543
13430 // This means the wanted type is anything.14544 // This means the wanted type is anything.
...@@ -13436,7 +14550,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13436,7 +14550,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13436 ConstCastOnly const_cast_result = types_match_const_cast_only(ira, wanted_type, actual_type,14550 ConstCastOnly const_cast_result = types_match_const_cast_only(ira, wanted_type, actual_type,
13437 source_node, false);14551 source_node, false);
13438 if (const_cast_result.id == ConstCastResultIdInvalid)14552 if (const_cast_result.id == ConstCastResultIdInvalid)
13439 return ira->codegen->invalid_instruction;14553 return ira->codegen->invalid_inst_gen;
13440 if (const_cast_result.id == ConstCastResultIdOk) {14554 if (const_cast_result.id == ConstCastResultIdOk) {
13441 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop);14555 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop);
13442 }14556 }
...@@ -13470,7 +14584,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13470,7 +14584,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13470 if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) {14584 if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) {
13471 return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr);14585 return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr);
13472 } else {14586 } else {
13473 return ira->codegen->invalid_instruction;14587 return ira->codegen->invalid_inst_gen;
13474 }14588 }
13475 } else if (14589 } else if (
13476 wanted_child_type->id == ZigTypeIdPointer &&14590 wanted_child_type->id == ZigTypeIdPointer &&
...@@ -13480,18 +14594,18 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13480,18 +14594,18 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13480 actual_type->data.pointer.child_type->id == ZigTypeIdArray)14594 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
13481 {14595 {
13482 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))14596 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
13483 return ira->codegen->invalid_instruction;14597 return ira->codegen->invalid_inst_gen;
13484 if ((err = type_resolve(ira->codegen, wanted_child_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))14598 if ((err = type_resolve(ira->codegen, wanted_child_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
13485 return ira->codegen->invalid_instruction;14599 return ira->codegen->invalid_inst_gen;
13486 if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_child_type) &&14600 if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_child_type) &&
13487 types_match_const_cast_only(ira, wanted_child_type->data.pointer.child_type,14601 types_match_const_cast_only(ira, wanted_child_type->data.pointer.child_type,
13488 actual_type->data.pointer.child_type->data.array.child_type, source_node,14602 actual_type->data.pointer.child_type->data.array.child_type, source_node,
13489 !wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk)14603 !wanted_child_type->data.pointer.is_const).id == ConstCastResultIdOk)
13490 {14604 {
13491 IrInstruction *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value,14605 IrInstGen *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value,
13492 wanted_child_type);14606 wanted_child_type);
13493 if (type_is_invalid(cast1->value->type))14607 if (type_is_invalid(cast1->value->type))
13494 return ira->codegen->invalid_instruction;14608 return ira->codegen->invalid_inst_gen;
13495 return ir_analyze_optional_wrap(ira, source_instr, cast1, wanted_type, nullptr);14609 return ir_analyze_optional_wrap(ira, source_instr, cast1, wanted_type, nullptr);
13496 }14610 }
13497 }14611 }
...@@ -13509,7 +14623,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13509,7 +14623,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13509 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) {14623 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) {
13510 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr);14624 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr);
13511 } else {14625 } else {
13512 return ira->codegen->invalid_instruction;14626 return ira->codegen->invalid_inst_gen;
13513 }14627 }
13514 }14628 }
13515 }14629 }
...@@ -13525,13 +14639,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13525,13 +14639,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13525 actual_type->id == ZigTypeIdComptimeInt ||14639 actual_type->id == ZigTypeIdComptimeInt ||
13526 actual_type->id == ZigTypeIdComptimeFloat)14640 actual_type->id == ZigTypeIdComptimeFloat)
13527 {14641 {
13528 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);14642 IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
13529 if (type_is_invalid(cast1->value->type))14643 if (type_is_invalid(cast1->value->type))
13530 return ira->codegen->invalid_instruction;14644 return ira->codegen->invalid_inst_gen;
1353114645
13532 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);14646 IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
13533 if (type_is_invalid(cast2->value->type))14647 if (type_is_invalid(cast2->value->type))
13534 return ira->codegen->invalid_instruction;14648 return ira->codegen->invalid_inst_gen;
1353514649
13536 return cast2;14650 return cast2;
13537 }14651 }
...@@ -13546,13 +14660,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13546,13 +14660,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13546 wanted_type->id == ZigTypeIdFloat || wanted_type->id == ZigTypeIdComptimeFloat))14660 wanted_type->id == ZigTypeIdFloat || wanted_type->id == ZigTypeIdComptimeFloat))
13547 {14661 {
13548 if (value->value->special == ConstValSpecialUndef) {14662 if (value->value->special == ConstValSpecialUndef) {
13549 IrInstruction *result = ir_const(ira, source_instr, wanted_type);14663 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
13550 result->value->special = ConstValSpecialUndef;14664 result->value->special = ConstValSpecialUndef;
13551 return result;14665 return result;
13552 }14666 }
13553 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {14667 if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {
13554 if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) {14668 if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) {
13555 IrInstruction *result = ir_const(ira, source_instr, wanted_type);14669 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
13556 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {14670 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {
13557 copy_const_val(result->value, value->value);14671 copy_const_val(result->value, value->value);
13558 result->value->type = wanted_type;14672 result->value->type = wanted_type;
...@@ -13561,7 +14675,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13561,7 +14675,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13561 }14675 }
13562 return result;14676 return result;
13563 } else if (wanted_type->id == ZigTypeIdComptimeFloat || wanted_type->id == ZigTypeIdFloat) {14677 } else if (wanted_type->id == ZigTypeIdComptimeFloat || wanted_type->id == ZigTypeIdFloat) {
13564 IrInstruction *result = ir_const(ira, source_instr, wanted_type);14678 IrInstGen *result = ir_const(ira, source_instr, wanted_type);
13565 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {14679 if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) {
13566 BigFloat bf;14680 BigFloat bf;
13567 bigfloat_init_bigint(&bf, &value->value->data.x_bigint);14681 bigfloat_init_bigint(&bf, &value->value->data.x_bigint);
...@@ -13573,7 +14687,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13573,7 +14687,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13573 }14687 }
13574 zig_unreachable();14688 zig_unreachable();
13575 } else {14689 } else {
13576 return ira->codegen->invalid_instruction;14690 return ira->codegen->invalid_inst_gen;
13577 }14691 }
13578 }14692 }
1357914693
...@@ -13609,13 +14723,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13609,13 +14723,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13609 actual_type->data.pointer.ptr_len == PtrLenSingle &&14723 actual_type->data.pointer.ptr_len == PtrLenSingle &&
13610 actual_type->data.pointer.child_type->id == ZigTypeIdArray)14724 actual_type->data.pointer.child_type->id == ZigTypeIdArray)
13611 {14725 {
13612 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);14726 IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);
13613 if (type_is_invalid(cast1->value->type))14727 if (type_is_invalid(cast1->value->type))
13614 return ira->codegen->invalid_instruction;14728 return ira->codegen->invalid_inst_gen;
1361514729
13616 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);14730 IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
13617 if (type_is_invalid(cast2->value->type))14731 if (type_is_invalid(cast2->value->type))
13618 return ira->codegen->invalid_instruction;14732 return ira->codegen->invalid_inst_gen;
1361914733
13620 return cast2;14734 return cast2;
13621 }14735 }
...@@ -13636,9 +14750,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13636,9 +14750,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13636 actual_array_type->data.array.sentinel)))14750 actual_array_type->data.array.sentinel)))
13637 {14751 {
13638 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))14752 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
13639 return ira->codegen->invalid_instruction;14753 return ira->codegen->invalid_inst_gen;
13640 if ((err = type_resolve(ira->codegen, wanted_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))14754 if ((err = type_resolve(ira->codegen, wanted_type->data.pointer.child_type, ResolveStatusAlignmentKnown)))
13641 return ira->codegen->invalid_instruction;14755 return ira->codegen->invalid_inst_gen;
13642 if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_type) &&14756 if (get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, wanted_type) &&
13643 types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,14757 types_match_const_cast_only(ira, wanted_type->data.pointer.child_type,
13644 actual_type->data.pointer.child_type->data.array.child_type, source_node,14758 actual_type->data.pointer.child_type->data.array.child_type, source_node,
...@@ -13679,24 +14793,24 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13679,24 +14793,24 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13679 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type,14793 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type,
13680 ResolveStatusAlignmentKnown)))14794 ResolveStatusAlignmentKnown)))
13681 {14795 {
13682 return ira->codegen->invalid_instruction;14796 return ira->codegen->invalid_inst_gen;
13683 }14797 }
13684 if ((err = type_resolve(ira->codegen, slice_ptr_type->data.pointer.child_type,14798 if ((err = type_resolve(ira->codegen, slice_ptr_type->data.pointer.child_type,
13685 ResolveStatusAlignmentKnown)))14799 ResolveStatusAlignmentKnown)))
13686 {14800 {
13687 return ira->codegen->invalid_instruction;14801 return ira->codegen->invalid_inst_gen;
13688 }14802 }
13689 ok_align = get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, slice_ptr_type);14803 ok_align = get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, slice_ptr_type);
13690 }14804 }
13691 if (ok_align) {14805 if (ok_align) {
13692 if (wanted_type->id == ZigTypeIdErrorUnion) {14806 if (wanted_type->id == ZigTypeIdErrorUnion) {
13693 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value);14807 IrInstGen *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value);
13694 if (type_is_invalid(cast1->value->type))14808 if (type_is_invalid(cast1->value->type))
13695 return ira->codegen->invalid_instruction;14809 return ira->codegen->invalid_inst_gen;
1369614810
13697 IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);14811 IrInstGen *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1);
13698 if (type_is_invalid(cast2->value->type))14812 if (type_is_invalid(cast2->value->type))
13699 return ira->codegen->invalid_instruction;14813 return ira->codegen->invalid_inst_gen;
1370014814
13701 return cast2;14815 return cast2;
13702 } else {14816 } else {
...@@ -13731,12 +14845,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13731,12 +14845,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13731 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type,14845 if ((err = type_resolve(ira->codegen, actual_type->data.pointer.child_type,
13732 ResolveStatusAlignmentKnown)))14846 ResolveStatusAlignmentKnown)))
13733 {14847 {
13734 return ira->codegen->invalid_instruction;14848 return ira->codegen->invalid_inst_gen;
13735 }14849 }
13736 if ((err = type_resolve(ira->codegen, slice_ptr_type->data.pointer.child_type,14850 if ((err = type_resolve(ira->codegen, slice_ptr_type->data.pointer.child_type,
13737 ResolveStatusAlignmentKnown)))14851 ResolveStatusAlignmentKnown)))
13738 {14852 {
13739 return ira->codegen->invalid_instruction;14853 return ira->codegen->invalid_inst_gen;
13740 }14854 }
13741 ok_align = get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, slice_ptr_type);14855 ok_align = get_ptr_align(ira->codegen, actual_type) >= get_ptr_align(ira->codegen, slice_ptr_type);
13742 }14856 }
...@@ -13777,7 +14891,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13777,7 +14891,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13777 }14891 }
13778 }14892 }
13779 if (ok) {14893 if (ok) {
13780 IrInstruction *cast1 = ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, anyframe_type);14894 IrInstGen *cast1 = ir_analyze_frame_ptr_to_anyframe(ira, source_instr, value, anyframe_type);
13781 if (anyframe_type == wanted_type)14895 if (anyframe_type == wanted_type)
13782 return cast1;14896 return cast1;
13783 return ir_analyze_cast(ira, source_instr, wanted_type, cast1);14897 return ir_analyze_cast(ira, source_instr, wanted_type, cast1);
...@@ -13832,28 +14946,28 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13832,28 +14946,28 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13832 if (actual_type->id == ZigTypeIdEnumLiteral &&14946 if (actual_type->id == ZigTypeIdEnumLiteral &&
13833 (wanted_type->id == ZigTypeIdOptional && wanted_type->data.maybe.child_type->id == ZigTypeIdEnum))14947 (wanted_type->id == ZigTypeIdOptional && wanted_type->data.maybe.child_type->id == ZigTypeIdEnum))
13834 {14948 {
13835 IrInstruction *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.maybe.child_type);14949 IrInstGen *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.maybe.child_type);
13836 if (result == ira->codegen->invalid_instruction)14950 if (type_is_invalid(result->value->type))
13837 return result;14951 return result;
1383814952
13839 return ir_analyze_optional_wrap(ira, result, value, wanted_type, nullptr);14953 return ir_analyze_optional_wrap(ira, source_instr, value, wanted_type, nullptr);
13840 }14954 }
1384114955
13842 // cast from enum literal to error union when payload is an enum14956 // cast from enum literal to error union when payload is an enum
13843 if (actual_type->id == ZigTypeIdEnumLiteral &&14957 if (actual_type->id == ZigTypeIdEnumLiteral &&
13844 (wanted_type->id == ZigTypeIdErrorUnion && wanted_type->data.error_union.payload_type->id == ZigTypeIdEnum))14958 (wanted_type->id == ZigTypeIdErrorUnion && wanted_type->data.error_union.payload_type->id == ZigTypeIdEnum))
13845 {14959 {
13846 IrInstruction *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.error_union.payload_type);14960 IrInstGen *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.error_union.payload_type);
13847 if (result == ira->codegen->invalid_instruction)14961 if (type_is_invalid(result->value->type))
13848 return result;14962 return result;
1384914963
13850 return ir_analyze_err_wrap_payload(ira, result, value, wanted_type, nullptr);14964 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type, nullptr);
13851 }14965 }
1385214966
13853 // cast from union to the enum type of the union14967 // cast from union to the enum type of the union
13854 if (actual_type->id == ZigTypeIdUnion && wanted_type->id == ZigTypeIdEnum) {14968 if (actual_type->id == ZigTypeIdUnion && wanted_type->id == ZigTypeIdEnum) {
13855 if ((err = type_resolve(ira->codegen, actual_type, ResolveStatusZeroBitsKnown)))14969 if ((err = type_resolve(ira->codegen, actual_type, ResolveStatusZeroBitsKnown)))
13856 return ira->codegen->invalid_instruction;14970 return ira->codegen->invalid_inst_gen;
1385714971
13858 if (actual_type->data.unionation.tag_type == wanted_type) {14972 if (actual_type->data.unionation.tag_type == wanted_type) {
13859 return ir_analyze_union_to_tag(ira, source_instr, value, wanted_type);14973 return ir_analyze_union_to_tag(ira, source_instr, value, wanted_type);
...@@ -13881,8 +14995,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13881,8 +14995,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13881 (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) &&14995 (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) &&
13882 (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile))14996 (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile))
13883 {14997 {
13884 if ((err = ir_cast_ptr_align(ira, source_instr, wanted_type, actual_type, value->source_node)))14998 if ((err = ir_cast_ptr_align(ira, source_instr, wanted_type, actual_type, value->base.source_node)))
13885 return ira->codegen->invalid_instruction;14999 return ira->codegen->invalid_inst_gen;
1388615000
13887 return ir_analyze_ptr_to_array(ira, source_instr, value, wanted_type);15001 return ir_analyze_ptr_to_array(ira, source_instr, value, wanted_type);
13888 }15002 }
...@@ -13905,7 +15019,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13905,7 +15019,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13905 slice_ptr_type->data.pointer.sentinel))))15019 slice_ptr_type->data.pointer.sentinel))))
13906 {15020 {
13907 TypeStructField *ptr_field = actual_type->data.structure.fields[slice_ptr_index];15021 TypeStructField *ptr_field = actual_type->data.structure.fields[slice_ptr_index];
13908 IrInstruction *slice_ptr = ir_analyze_struct_value_field_value(ira, source_instr, value, ptr_field);15022 IrInstGen *slice_ptr = ir_analyze_struct_value_field_value(ira, source_instr, value, ptr_field);
13909 return ir_implicit_cast2(ira, source_instr, slice_ptr, wanted_type);15023 return ir_implicit_cast2(ira, source_instr, slice_ptr, wanted_type);
13910 }15024 }
13911 }15025 }
...@@ -13925,7 +15039,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13925,7 +15039,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13925 dest_ptr_type = wanted_type->data.maybe.child_type;15039 dest_ptr_type = wanted_type->data.maybe.child_type;
13926 }15040 }
13927 if (dest_ptr_type != nullptr) {15041 if (dest_ptr_type != nullptr) {
13928 return ir_analyze_ptr_cast(ira, source_instr, value, wanted_type, source_instr, true);15042 return ir_analyze_ptr_cast(ira, source_instr, value, source_instr, wanted_type, source_instr, true);
13929 }15043 }
13930 }15044 }
1393115045
...@@ -13936,7 +15050,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13936,7 +15050,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13936 {15050 {
13937 bool has_bits;15051 bool has_bits;
13938 if ((err = type_has_bits2(ira->codegen, actual_type, &has_bits)))15052 if ((err = type_has_bits2(ira->codegen, actual_type, &has_bits)))
13939 return ira->codegen->invalid_instruction;15053 return ira->codegen->invalid_inst_gen;
13940 if (!has_bits) {15054 if (!has_bits) {
13941 return ir_get_ref(ira, source_instr, value, false, false);15055 return ir_get_ref(ira, source_instr, value, false, false);
13942 }15056 }
...@@ -13967,7 +15081,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -13967,7 +15081,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
13967 actual_type->data.pointer.child_type, source_node,15081 actual_type->data.pointer.child_type, source_node,
13968 !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)15082 !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk)
13969 {15083 {
13970 return ir_analyze_ptr_cast(ira, source_instr, value, wanted_type, source_instr, true);15084 return ir_analyze_ptr_cast(ira, source_instr, value, source_instr, wanted_type, source_instr, true);
13971 }15085 }
1397215086
13973 // cast from integer to C pointer15087 // cast from integer to C pointer
...@@ -14003,9 +15117,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -14003,9 +15117,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1400315117
14004 // T to ?U, where T implicitly casts to U15118 // T to ?U, where T implicitly casts to U
14005 if (wanted_type->id == ZigTypeIdOptional && actual_type->id != ZigTypeIdOptional) {15119 if (wanted_type->id == ZigTypeIdOptional && actual_type->id != ZigTypeIdOptional) {
14006 IrInstruction *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.maybe.child_type);15120 IrInstGen *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.maybe.child_type);
14007 if (type_is_invalid(cast1->value->type))15121 if (type_is_invalid(cast1->value->type))
14008 return ira->codegen->invalid_instruction;15122 return ira->codegen->invalid_inst_gen;
14009 return ir_implicit_cast2(ira, source_instr, cast1, wanted_type);15123 return ir_implicit_cast2(ira, source_instr, cast1, wanted_type);
14010 }15124 }
1401115125
...@@ -14013,9 +15127,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -14013,9 +15127,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
14013 if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id != ZigTypeIdErrorUnion &&15127 if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id != ZigTypeIdErrorUnion &&
14014 actual_type->id != ZigTypeIdErrorSet)15128 actual_type->id != ZigTypeIdErrorSet)
14015 {15129 {
14016 IrInstruction *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.error_union.payload_type);15130 IrInstGen *cast1 = ir_implicit_cast2(ira, source_instr, value, wanted_type->data.error_union.payload_type);
14017 if (type_is_invalid(cast1->value->type))15131 if (type_is_invalid(cast1->value->type))
14018 return ira->codegen->invalid_instruction;15132 return ira->codegen->invalid_inst_gen;
14019 return ir_implicit_cast2(ira, source_instr, cast1, wanted_type);15133 return ir_implicit_cast2(ira, source_instr, cast1, wanted_type);
14020 }15134 }
1402115135
...@@ -14024,14 +15138,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -14024,14 +15138,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
14024 buf_ptr(&wanted_type->name),15138 buf_ptr(&wanted_type->name),
14025 buf_ptr(&actual_type->name)));15139 buf_ptr(&actual_type->name)));
14026 report_recursive_error(ira, source_instr->source_node, &const_cast_result, parent_msg);15140 report_recursive_error(ira, source_instr->source_node, &const_cast_result, parent_msg);
14027 return ira->codegen->invalid_instruction;15141 return ira->codegen->invalid_inst_gen;
14028}15142}
1402915143
14030static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_source_instr,15144static IrInstGen *ir_implicit_cast2(IrAnalyze *ira, IrInst *value_source_instr,
14031 IrInstruction *value, ZigType *expected_type)15145 IrInstGen *value, ZigType *expected_type)
14032{15146{
14033 assert(value);15147 assert(value);
14034 assert(value != ira->codegen->invalid_instruction);
14035 assert(!expected_type || !type_is_invalid(expected_type));15148 assert(!expected_type || !type_is_invalid(expected_type));
14036 assert(value->value->type);15149 assert(value->value->type);
14037 assert(!type_is_invalid(value->value->type));15150 assert(!type_is_invalid(value->value->type));
...@@ -14045,17 +15158,17 @@ static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_sou...@@ -14045,17 +15158,17 @@ static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_sou
14045 return ir_analyze_cast(ira, value_source_instr, expected_type, value);15158 return ir_analyze_cast(ira, value_source_instr, expected_type, value);
14046}15159}
1404715160
14048static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type) {15161static IrInstGen *ir_implicit_cast(IrAnalyze *ira, IrInstGen *value, ZigType *expected_type) {
14049 return ir_implicit_cast2(ira, value, value, expected_type);15162 return ir_implicit_cast2(ira, &value->base, value, expected_type);
14050}15163}
1405115164
14052static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) {15165static ZigType *get_ptr_elem_type(CodeGen *g, IrInstGen *ptr) {
14053 ir_assert(ptr->value->type->id == ZigTypeIdPointer, ptr);15166 ir_assert_gen(ptr->value->type->id == ZigTypeIdPointer, ptr);
14054 ZigType *elem_type = ptr->value->type->data.pointer.child_type;15167 ZigType *elem_type = ptr->value->type->data.pointer.child_type;
14055 if (elem_type != g->builtin_types.entry_var)15168 if (elem_type != g->builtin_types.entry_var)
14056 return elem_type;15169 return elem_type;
1405715170
14058 if (ir_resolve_lazy(g, ptr->source_node, ptr->value))15171 if (ir_resolve_lazy(g, ptr->base.source_node, ptr->value))
14059 return g->builtin_types.entry_invalid;15172 return g->builtin_types.entry_invalid;
1406015173
14061 assert(value_is_comptime(ptr->value));15174 assert(value_is_comptime(ptr->value));
...@@ -14063,28 +15176,28 @@ static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) {...@@ -14063,28 +15176,28 @@ static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) {
14063 return pointee->type;15176 return pointee->type;
14064}15177}
1406515178
14066static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr,15179static IrInstGen *ir_get_deref(IrAnalyze *ira, IrInst* source_instruction, IrInstGen *ptr,
14067 ResultLoc *result_loc)15180 ResultLoc *result_loc)
14068{15181{
14069 Error err;15182 Error err;
14070 ZigType *ptr_type = ptr->value->type;15183 ZigType *ptr_type = ptr->value->type;
14071 if (type_is_invalid(ptr_type))15184 if (type_is_invalid(ptr_type))
14072 return ira->codegen->invalid_instruction;15185 return ira->codegen->invalid_inst_gen;
1407315186
14074 if (ptr_type->id != ZigTypeIdPointer) {15187 if (ptr_type->id != ZigTypeIdPointer) {
14075 ir_add_error_node(ira, source_instruction->source_node,15188 ir_add_error_node(ira, source_instruction->source_node,
14076 buf_sprintf("attempt to dereference non-pointer type '%s'",15189 buf_sprintf("attempt to dereference non-pointer type '%s'",
14077 buf_ptr(&ptr_type->name)));15190 buf_ptr(&ptr_type->name)));
14078 return ira->codegen->invalid_instruction;15191 return ira->codegen->invalid_inst_gen;
14079 }15192 }
1408015193
14081 ZigType *child_type = ptr_type->data.pointer.child_type;15194 ZigType *child_type = ptr_type->data.pointer.child_type;
14082 if (type_is_invalid(child_type))15195 if (type_is_invalid(child_type))
14083 return ira->codegen->invalid_instruction;15196 return ira->codegen->invalid_inst_gen;
14084 // if the child type has one possible value, the deref is comptime15197 // if the child type has one possible value, the deref is comptime
14085 switch (type_has_one_possible_value(ira->codegen, child_type)) {15198 switch (type_has_one_possible_value(ira->codegen, child_type)) {
14086 case OnePossibleValueInvalid:15199 case OnePossibleValueInvalid:
14087 return ira->codegen->invalid_instruction;15200 return ira->codegen->invalid_inst_gen;
14088 case OnePossibleValueYes:15201 case OnePossibleValueYes:
14089 return ir_const_move(ira, source_instruction,15202 return ir_const_move(ira, source_instruction,
14090 get_the_one_possible_value(ira->codegen, child_type));15203 get_the_one_possible_value(ira->codegen, child_type));
...@@ -14093,8 +15206,8 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -14093,8 +15206,8 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
14093 }15206 }
14094 if (instr_is_comptime(ptr)) {15207 if (instr_is_comptime(ptr)) {
14095 if (ptr->value->special == ConstValSpecialUndef) {15208 if (ptr->value->special == ConstValSpecialUndef) {
14096 ir_add_error(ira, ptr, buf_sprintf("attempt to dereference undefined value"));15209 ir_add_error(ira, &ptr->base, buf_sprintf("attempt to dereference undefined value"));
14097 return ira->codegen->invalid_instruction;15210 return ira->codegen->invalid_inst_gen;
14098 }15211 }
14099 if (ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {15212 if (ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
14100 ZigValue *pointee = const_ptr_pointee_unchecked(ira->codegen, ptr->value);15213 ZigValue *pointee = const_ptr_pointee_unchecked(ira->codegen, ptr->value);
...@@ -14102,12 +15215,12 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -14102,12 +15215,12 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
14102 child_type = pointee->type;15215 child_type = pointee->type;
14103 }15216 }
14104 if (pointee->special != ConstValSpecialRuntime) {15217 if (pointee->special != ConstValSpecialRuntime) {
14105 IrInstruction *result = ir_const(ira, source_instruction, child_type);15218 IrInstGen *result = ir_const(ira, source_instruction, child_type);
1410615219
14107 if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, result->value,15220 if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, result->value,
14108 ptr->value)))15221 ptr->value)))
14109 {15222 {
14110 return ira->codegen->invalid_instruction;15223 return ira->codegen->invalid_inst_gen;
14111 }15224 }
14112 result->value->type = child_type;15225 result->value->type = child_type;
14113 return result;15226 return result;
...@@ -14116,38 +15229,37 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -14116,38 +15229,37 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
14116 }15229 }
1411715230
14118 // if the instruction is a const ref instruction we can skip it15231 // if the instruction is a const ref instruction we can skip it
14119 if (ptr->id == IrInstructionIdRef) {15232 if (ptr->id == IrInstGenIdRef) {
14120 IrInstructionRef *ref_inst = reinterpret_cast<IrInstructionRef *>(ptr);15233 IrInstGenRef *ref_inst = reinterpret_cast<IrInstGenRef *>(ptr);
14121 return ref_inst->value;15234 return ref_inst->operand;
14122 }15235 }
1412315236
14124 // If the instruction is a element pointer instruction to a vector, we emit15237 // If the instruction is a element pointer instruction to a vector, we emit
14125 // vector element extract instruction rather than load pointer. If the15238 // vector element extract instruction rather than load pointer. If the
14126 // pointer type has non-VECTOR_INDEX_RUNTIME value, it would have been15239 // pointer type has non-VECTOR_INDEX_RUNTIME value, it would have been
14127 // possible to implement this in the codegen for IrInstructionLoadPtrGen.15240 // possible to implement this in the codegen for IrInstGenLoadPtr.
14128 // However if it has VECTOR_INDEX_RUNTIME then we must emit a compile error15241 // However if it has VECTOR_INDEX_RUNTIME then we must emit a compile error
14129 // if the vector index cannot be determined right here, right now, because15242 // if the vector index cannot be determined right here, right now, because
14130 // the type information does not contain enough information to actually15243 // the type information does not contain enough information to actually
14131 // perform a dereference.15244 // perform a dereference.
14132 if (ptr_type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) {15245 if (ptr_type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) {
14133 if (ptr->id == IrInstructionIdElemPtr) {15246 if (ptr->id == IrInstGenIdElemPtr) {
14134 IrInstructionElemPtr *elem_ptr = (IrInstructionElemPtr *)ptr;15247 IrInstGenElemPtr *elem_ptr = (IrInstGenElemPtr *)ptr;
14135 IrInstruction *vector_loaded = ir_get_deref(ira, elem_ptr->array_ptr,15248 IrInstGen *vector_loaded = ir_get_deref(ira, &elem_ptr->array_ptr->base,
14136 elem_ptr->array_ptr, nullptr);15249 elem_ptr->array_ptr, nullptr);
14137 IrInstruction *elem_index = elem_ptr->elem_index;15250 IrInstGen *elem_index = elem_ptr->elem_index;
14138 return ir_build_vector_extract_elem(ira, source_instruction, vector_loaded, elem_index);15251 return ir_build_vector_extract_elem(ira, source_instruction, vector_loaded, elem_index);
14139 }15252 }
14140 ir_add_error(ira, ptr,15253 ir_add_error(ira, &ptr->base,
14141 buf_sprintf("unable to determine vector element index of type '%s'", buf_ptr(&ptr_type->name)));15254 buf_sprintf("unable to determine vector element index of type '%s'", buf_ptr(&ptr_type->name)));
14142 return ira->codegen->invalid_instruction;15255 return ira->codegen->invalid_inst_gen;
14143 }15256 }
1414415257
14145 IrInstruction *result_loc_inst;15258 IrInstGen *result_loc_inst;
14146 if (ptr_type->data.pointer.host_int_bytes != 0 && handle_is_ptr(child_type)) {15259 if (ptr_type->data.pointer.host_int_bytes != 0 && handle_is_ptr(child_type)) {
14147 if (result_loc == nullptr) result_loc = no_result_loc();15260 if (result_loc == nullptr) result_loc = no_result_loc();
14148 result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr,15261 result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, true, true);
14149 true, false, true);15262 if (type_is_invalid(result_loc_inst->value->type) || result_loc_inst->value->type->id == ZigTypeIdUnreachable) {
14150 if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) {
14151 return result_loc_inst;15263 return result_loc_inst;
14152 }15264 }
14153 } else {15265 } else {
...@@ -14157,7 +15269,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -14157,7 +15269,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
14157 return ir_build_load_ptr_gen(ira, source_instruction, ptr, child_type, result_loc_inst);15269 return ir_build_load_ptr_gen(ira, source_instruction, ptr, child_type, result_loc_inst);
14158}15270}
1415915271
14160static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode *source_node,15272static bool ir_resolve_const_align(CodeGen *codegen, IrExecutableGen *exec, AstNode *source_node,
14161 ZigValue *const_val, uint32_t *out)15273 ZigValue *const_val, uint32_t *out)
14162{15274{
14163 Error err;15275 Error err;
...@@ -14166,12 +15278,12 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode...@@ -14166,12 +15278,12 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode
1416615278
14167 uint32_t align_bytes = bigint_as_u32(&const_val->data.x_bigint);15279 uint32_t align_bytes = bigint_as_u32(&const_val->data.x_bigint);
14168 if (align_bytes == 0) {15280 if (align_bytes == 0) {
14169 exec_add_error_node(codegen, exec, source_node, buf_sprintf("alignment must be >= 1"));15281 exec_add_error_node_gen(codegen, exec, source_node, buf_sprintf("alignment must be >= 1"));
14170 return false;15282 return false;
14171 }15283 }
1417215284
14173 if (!is_power_of_2(align_bytes)) {15285 if (!is_power_of_2(align_bytes)) {
14174 exec_add_error_node(codegen, exec, source_node,15286 exec_add_error_node_gen(codegen, exec, source_node,
14175 buf_sprintf("alignment value %" PRIu32 " is not a power of 2", align_bytes));15287 buf_sprintf("alignment value %" PRIu32 " is not a power of 2", align_bytes));
14176 return false;15288 return false;
14177 }15289 }
...@@ -14180,7 +15292,7 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode...@@ -14180,7 +15292,7 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode
14180 return true;15292 return true;
14181}15293}
1418215294
14183static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem_type, uint32_t *out) {15295static bool ir_resolve_align(IrAnalyze *ira, IrInstGen *value, ZigType *elem_type, uint32_t *out) {
14184 if (type_is_invalid(value->value->type))15296 if (type_is_invalid(value->value->type))
14185 return false;15297 return false;
1418615298
...@@ -14201,19 +15313,19 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem...@@ -14201,19 +15313,19 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem
14201 }15313 }
14202 }15314 }
1420315315
14204 IrInstruction *casted_value = ir_implicit_cast(ira, value, get_align_amt_type(ira->codegen));15316 IrInstGen *casted_value = ir_implicit_cast(ira, value, get_align_amt_type(ira->codegen));
14205 if (type_is_invalid(casted_value->value->type))15317 if (type_is_invalid(casted_value->value->type))
14206 return false;15318 return false;
1420715319
14208 return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->source_node,15320 return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->base.source_node,
14209 casted_value->value, out);15321 casted_value->value, out);
14210}15322}
1421115323
14212static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *int_type, uint64_t *out) {15324static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstGen *value, ZigType *int_type, uint64_t *out) {
14213 if (type_is_invalid(value->value->type))15325 if (type_is_invalid(value->value->type))
14214 return false;15326 return false;
1421515327
14216 IrInstruction *casted_value = ir_implicit_cast(ira, value, int_type);15328 IrInstGen *casted_value = ir_implicit_cast(ira, value, int_type);
14217 if (type_is_invalid(casted_value->value->type))15329 if (type_is_invalid(casted_value->value->type))
14218 return false;15330 return false;
1421915331
...@@ -14225,15 +15337,15 @@ static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *i...@@ -14225,15 +15337,15 @@ static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *i
14225 return true;15337 return true;
14226}15338}
1422715339
14228static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out) {15340static bool ir_resolve_usize(IrAnalyze *ira, IrInstGen *value, uint64_t *out) {
14229 return ir_resolve_unsigned(ira, value, ira->codegen->builtin_types.entry_usize, out);15341 return ir_resolve_unsigned(ira, value, ira->codegen->builtin_types.entry_usize, out);
14230}15342}
1423115343
14232static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {15344static bool ir_resolve_bool(IrAnalyze *ira, IrInstGen *value, bool *out) {
14233 if (type_is_invalid(value->value->type))15345 if (type_is_invalid(value->value->type))
14234 return false;15346 return false;
1423515347
14236 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool);15348 IrInstGen *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool);
14237 if (type_is_invalid(casted_value->value->type))15349 if (type_is_invalid(casted_value->value->type))
14238 return false;15350 return false;
1423915351
...@@ -14245,7 +15357,7 @@ static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {...@@ -14245,7 +15357,7 @@ static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {
14245 return true;15357 return true;
14246}15358}
1424715359
14248static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out) {15360static bool ir_resolve_comptime(IrAnalyze *ira, IrInstGen *value, bool *out) {
14249 if (!value) {15361 if (!value) {
14250 *out = false;15362 *out = false;
14251 return true;15363 return true;
...@@ -14253,13 +15365,13 @@ static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out)...@@ -14253,13 +15365,13 @@ static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out)
14253 return ir_resolve_bool(ira, value, out);15365 return ir_resolve_bool(ira, value, out);
14254}15366}
1425515367
14256static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, AtomicOrder *out) {15368static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstGen *value, AtomicOrder *out) {
14257 if (type_is_invalid(value->value->type))15369 if (type_is_invalid(value->value->type))
14258 return false;15370 return false;
1425915371
14260 ZigType *atomic_order_type = get_builtin_type(ira->codegen, "AtomicOrder");15372 ZigType *atomic_order_type = get_builtin_type(ira->codegen, "AtomicOrder");
1426115373
14262 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type);15374 IrInstGen *casted_value = ir_implicit_cast(ira, value, atomic_order_type);
14263 if (type_is_invalid(casted_value->value->type))15375 if (type_is_invalid(casted_value->value->type))
14264 return false;15376 return false;
1426515377
...@@ -14271,13 +15383,13 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic...@@ -14271,13 +15383,13 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic
14271 return true;15383 return true;
14272}15384}
1427315385
14274static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, AtomicRmwOp *out) {15386static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstGen *value, AtomicRmwOp *out) {
14275 if (type_is_invalid(value->value->type))15387 if (type_is_invalid(value->value->type))
14276 return false;15388 return false;
1427715389
14278 ZigType *atomic_rmw_op_type = get_builtin_type(ira->codegen, "AtomicRmwOp");15390 ZigType *atomic_rmw_op_type = get_builtin_type(ira->codegen, "AtomicRmwOp");
1427915391
14280 IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type);15392 IrInstGen *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type);
14281 if (type_is_invalid(casted_value->value->type))15393 if (type_is_invalid(casted_value->value->type))
14282 return false;15394 return false;
1428315395
...@@ -14289,13 +15401,13 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi...@@ -14289,13 +15401,13 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi
14289 return true;15401 return true;
14290}15402}
1429115403
14292static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, GlobalLinkageId *out) {15404static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstGen *value, GlobalLinkageId *out) {
14293 if (type_is_invalid(value->value->type))15405 if (type_is_invalid(value->value->type))
14294 return false;15406 return false;
1429515407
14296 ZigType *global_linkage_type = get_builtin_type(ira->codegen, "GlobalLinkage");15408 ZigType *global_linkage_type = get_builtin_type(ira->codegen, "GlobalLinkage");
1429715409
14298 IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type);15410 IrInstGen *casted_value = ir_implicit_cast(ira, value, global_linkage_type);
14299 if (type_is_invalid(casted_value->value->type))15411 if (type_is_invalid(casted_value->value->type))
14300 return false;15412 return false;
1430115413
...@@ -14307,13 +15419,13 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob...@@ -14307,13 +15419,13 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob
14307 return true;15419 return true;
14308}15420}
1430915421
14310static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMode *out) {15422static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstGen *value, FloatMode *out) {
14311 if (type_is_invalid(value->value->type))15423 if (type_is_invalid(value->value->type))
14312 return false;15424 return false;
1431315425
14314 ZigType *float_mode_type = get_builtin_type(ira->codegen, "FloatMode");15426 ZigType *float_mode_type = get_builtin_type(ira->codegen, "FloatMode");
1431515427
14316 IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type);15428 IrInstGen *casted_value = ir_implicit_cast(ira, value, float_mode_type);
14317 if (type_is_invalid(casted_value->value->type))15429 if (type_is_invalid(casted_value->value->type))
14318 return false;15430 return false;
1431915431
...@@ -14325,14 +15437,14 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod...@@ -14325,14 +15437,14 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod
14325 return true;15437 return true;
14326}15438}
1432715439
14328static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {15440static Buf *ir_resolve_str(IrAnalyze *ira, IrInstGen *value) {
14329 if (type_is_invalid(value->value->type))15441 if (type_is_invalid(value->value->type))
14330 return nullptr;15442 return nullptr;
1433115443
14332 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,15444 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
14333 true, false, PtrLenUnknown, 0, 0, 0, false);15445 true, false, PtrLenUnknown, 0, 0, 0, false);
14334 ZigType *str_type = get_slice_type(ira->codegen, ptr_type);15446 ZigType *str_type = get_slice_type(ira->codegen, ptr_type);
14335 IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type);15447 IrInstGen *casted_value = ir_implicit_cast(ira, value, str_type);
14336 if (type_is_invalid(casted_value->value->type))15448 if (type_is_invalid(casted_value->value->type))
14337 return nullptr;15449 return nullptr;
1433815450
...@@ -14356,7 +15468,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {...@@ -14356,7 +15468,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
14356 size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i;15468 size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i;
14357 ZigValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index];15469 ZigValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index];
14358 if (char_val->special == ConstValSpecialUndef) {15470 if (char_val->special == ConstValSpecialUndef) {
14359 ir_add_error(ira, casted_value, buf_sprintf("use of undefined value"));15471 ir_add_error(ira, &casted_value->base, buf_sprintf("use of undefined value"));
14360 return nullptr;15472 return nullptr;
14361 }15473 }
14362 uint64_t big_c = bigint_as_u64(&char_val->data.x_bigint);15474 uint64_t big_c = bigint_as_u64(&char_val->data.x_bigint);
...@@ -14367,10 +15479,10 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {...@@ -14367,10 +15479,10 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
14367 return result;15479 return result;
14368}15480}
1436915481
14370static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira,15482static IrInstGen *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira,
14371 IrInstructionAddImplicitReturnType *instruction)15483 IrInstSrcAddImplicitReturnType *instruction)
14372{15484{
14373 IrInstruction *value = instruction->value->child;15485 IrInstGen *value = instruction->value->child;
14374 if (type_is_invalid(value->value->type))15486 if (type_is_invalid(value->value->type))
14375 return ir_unreach_error(ira);15487 return ir_unreach_error(ira);
1437615488
...@@ -14378,15 +15490,15 @@ static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze...@@ -14378,15 +15490,15 @@ static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze
14378 ira->src_implicit_return_type_list.append(value);15490 ira->src_implicit_return_type_list.append(value);
14379 }15491 }
1438015492
14381 return ir_const_void(ira, &instruction->base);15493 return ir_const_void(ira, &instruction->base.base);
14382}15494}
1438315495
14384static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructionReturn *instruction) {15496static IrInstGen *ir_analyze_instruction_return(IrAnalyze *ira, IrInstSrcReturn *instruction) {
14385 IrInstruction *operand = instruction->operand->child;15497 IrInstGen *operand = instruction->operand->child;
14386 if (type_is_invalid(operand->value->type))15498 if (type_is_invalid(operand->value->type))
14387 return ir_unreach_error(ira);15499 return ir_unreach_error(ira);
1438815500
14389 IrInstruction *casted_operand = ir_implicit_cast(ira, operand, ira->explicit_return_type);15501 IrInstGen *casted_operand = ir_implicit_cast(ira, operand, ira->explicit_return_type);
14390 if (type_is_invalid(casted_operand->value->type)) {15502 if (type_is_invalid(casted_operand->value->type)) {
14391 AstNode *source_node = ira->explicit_return_type_source_node;15503 AstNode *source_node = ira->explicit_return_type_source_node;
14392 if (source_node != nullptr) {15504 if (source_node != nullptr) {
...@@ -14401,9 +15513,7 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio...@@ -14401,9 +15513,7 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
14401 handle_is_ptr(ira->explicit_return_type))15513 handle_is_ptr(ira->explicit_return_type))
14402 {15514 {
14403 // result location mechanism took care of it.15515 // result location mechanism took care of it.
14404 IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope,15516 IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, nullptr);
14405 instruction->base.source_node, nullptr);
14406 result->value->type = ira->codegen->builtin_types.entry_unreachable;
14407 return ir_finish_anal(ira, result);15517 return ir_finish_anal(ira, result);
14408 }15518 }
1440915519
...@@ -14411,47 +15521,45 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio...@@ -14411,47 +15521,45 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio
14411 casted_operand->value->type->id == ZigTypeIdPointer &&15521 casted_operand->value->type->id == ZigTypeIdPointer &&
14412 casted_operand->value->data.rh_ptr == RuntimeHintPtrStack)15522 casted_operand->value->data.rh_ptr == RuntimeHintPtrStack)
14413 {15523 {
14414 ir_add_error(ira, casted_operand, buf_sprintf("function returns address of local variable"));15524 ir_add_error(ira, &instruction->operand->base, buf_sprintf("function returns address of local variable"));
14415 return ir_unreach_error(ira);15525 return ir_unreach_error(ira);
14416 }15526 }
1441715527
14418 IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope,15528 IrInstGen *result = ir_build_return_gen(ira, &instruction->base.base, casted_operand);
14419 instruction->base.source_node, casted_operand);
14420 result->value->type = ira->codegen->builtin_types.entry_unreachable;
14421 return ir_finish_anal(ira, result);15529 return ir_finish_anal(ira, result);
14422}15530}
1442315531
14424static IrInstruction *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *instruction) {15532static IrInstGen *ir_analyze_instruction_const(IrAnalyze *ira, IrInstSrcConst *instruction) {
14425 return ir_const_move(ira, &instruction->base, instruction->base.value);15533 return ir_const_move(ira, &instruction->base.base, instruction->value);
14426}15534}
1442715535
14428static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {15536static IrInstGen *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {
14429 IrInstruction *op1 = bin_op_instruction->op1->child;15537 IrInstGen *op1 = bin_op_instruction->op1->child;
14430 if (type_is_invalid(op1->value->type))15538 if (type_is_invalid(op1->value->type))
14431 return ira->codegen->invalid_instruction;15539 return ira->codegen->invalid_inst_gen;
1443215540
14433 IrInstruction *op2 = bin_op_instruction->op2->child;15541 IrInstGen *op2 = bin_op_instruction->op2->child;
14434 if (type_is_invalid(op2->value->type))15542 if (type_is_invalid(op2->value->type))
14435 return ira->codegen->invalid_instruction;15543 return ira->codegen->invalid_inst_gen;
1443615544
14437 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;15545 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
1443815546
14439 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, bool_type);15547 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, bool_type);
14440 if (casted_op1 == ira->codegen->invalid_instruction)15548 if (type_is_invalid(casted_op1->value->type))
14441 return ira->codegen->invalid_instruction;15549 return ira->codegen->invalid_inst_gen;
1444215550
14443 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, bool_type);15551 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, bool_type);
14444 if (casted_op2 == ira->codegen->invalid_instruction)15552 if (type_is_invalid(casted_op2->value->type))
14445 return ira->codegen->invalid_instruction;15553 return ira->codegen->invalid_inst_gen;
1444615554
14447 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {15555 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {
14448 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);15556 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
14449 if (op1_val == nullptr)15557 if (op1_val == nullptr)
14450 return ira->codegen->invalid_instruction;15558 return ira->codegen->invalid_inst_gen;
1445115559
14452 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);15560 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
14453 if (op2_val == nullptr)15561 if (op2_val == nullptr)
14454 return ira->codegen->invalid_instruction;15562 return ira->codegen->invalid_inst_gen;
1445515563
14456 assert(casted_op1->value->type->id == ZigTypeIdBool);15564 assert(casted_op1->value->type->id == ZigTypeIdBool);
14457 assert(casted_op2->value->type->id == ZigTypeIdBool);15565 assert(casted_op2->value->type->id == ZigTypeIdBool);
...@@ -14463,14 +15571,11 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp...@@ -14463,14 +15571,11 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp
14463 } else {15571 } else {
14464 zig_unreachable();15572 zig_unreachable();
14465 }15573 }
14466 return ir_const_bool(ira, &bin_op_instruction->base, result_bool);15574 return ir_const_bool(ira, &bin_op_instruction->base.base, result_bool);
14467 }15575 }
1446815576
14469 IrInstruction *result = ir_build_bin_op(&ira->new_irb,15577 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, bool_type,
14470 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
14471 bin_op_instruction->op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);15578 bin_op_instruction->op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);
14472 result->value->type = bool_type;
14473 return result;
14474}15579}
1447515580
14476static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) {15581static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) {
...@@ -14535,12 +15640,13 @@ static void set_optional_payload(ZigValue *opt_val, ZigValue *payload) {...@@ -14535,12 +15640,13 @@ static void set_optional_payload(ZigValue *opt_val, ZigValue *payload) {
14535 }15640 }
14536}15641}
1453715642
14538static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,15643static IrInstGen *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type,
14539 ZigValue *op1_val, ZigValue *op2_val, IrInstructionBinOp *bin_op_instruction, IrBinOp op_id,15644 ZigValue *op1_val, ZigValue *op2_val, IrInstSrcBinOp *bin_op_instruction, IrBinOp op_id,
14540 bool one_possible_value) {15645 bool one_possible_value)
15646{
14541 if (op1_val->special == ConstValSpecialUndef ||15647 if (op1_val->special == ConstValSpecialUndef ||
14542 op2_val->special == ConstValSpecialUndef)15648 op2_val->special == ConstValSpecialUndef)
14543 return ir_const_undef(ira, &bin_op_instruction->base, resolved_type);15649 return ir_const_undef(ira, &bin_op_instruction->base.base, resolved_type);
14544 if (resolved_type->id == ZigTypeIdPointer && op_id != IrBinOpCmpEq && op_id != IrBinOpCmpNotEq) {15650 if (resolved_type->id == ZigTypeIdPointer && op_id != IrBinOpCmpEq && op_id != IrBinOpCmpNotEq) {
14545 if ((op1_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr ||15651 if ((op1_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr ||
14546 op1_val->data.x_ptr.special == ConstPtrSpecialNull) &&15652 op1_val->data.x_ptr.special == ConstPtrSpecialNull) &&
...@@ -14560,7 +15666,7 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t...@@ -14560,7 +15666,7 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t
14560 cmp_result = CmpEQ;15666 cmp_result = CmpEQ;
14561 }15667 }
14562 bool answer = resolve_cmp_op_id(op_id, cmp_result);15668 bool answer = resolve_cmp_op_id(op_id, cmp_result);
14563 return ir_const_bool(ira, &bin_op_instruction->base, answer);15669 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
14564 }15670 }
14565 } else {15671 } else {
14566 bool are_equal = one_possible_value || const_values_equal(ira->codegen, op1_val, op2_val);15672 bool are_equal = one_possible_value || const_values_equal(ira->codegen, op1_val, op2_val);
...@@ -14572,15 +15678,33 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t...@@ -14572,15 +15678,33 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t
14572 } else {15678 } else {
14573 zig_unreachable();15679 zig_unreachable();
14574 }15680 }
14575 return ir_const_bool(ira, &bin_op_instruction->base, answer);15681 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
14576 }15682 }
14577 zig_unreachable();15683 zig_unreachable();
14578}15684}
1457915685
14580// Returns ErrorNotLazy when the value cannot be determined15686// Returns ErrorNotLazy when the value cannot be determined
14581static Error lazy_cmp_zero(AstNode *source_node, ZigValue *val, Cmp *result) {15687static Error lazy_cmp_zero(CodeGen *codegen, AstNode *source_node, ZigValue *val, Cmp *result) {
14582 Error err;15688 Error err;
1458315689
15690 switch (type_has_one_possible_value(codegen, val->type)) {
15691 case OnePossibleValueInvalid:
15692 return ErrorSemanticAnalyzeFail;
15693 case OnePossibleValueNo:
15694 break;
15695 case OnePossibleValueYes:
15696 switch (val->type->id) {
15697 case ZigTypeIdInt:
15698 src_assert(val->type->data.integral.bit_count == 0, source_node);
15699 *result = CmpEQ;
15700 return ErrorNone;
15701 case ZigTypeIdUndefined:
15702 return ErrorNotLazy;
15703 default:
15704 zig_unreachable();
15705 }
15706 }
15707
14584 switch (val->special) {15708 switch (val->special) {
14585 case ConstValSpecialRuntime:15709 case ConstValSpecialRuntime:
14586 case ConstValSpecialUndef:15710 case ConstValSpecialUndef:
...@@ -14626,7 +15750,7 @@ static Error lazy_cmp_zero(AstNode *source_node, ZigValue *val, Cmp *result) {...@@ -14626,7 +15750,7 @@ static Error lazy_cmp_zero(AstNode *source_node, ZigValue *val, Cmp *result) {
14626 zig_unreachable();15750 zig_unreachable();
14627}15751}
1462815752
14629static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInstruction *source_instr,15753static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInst* source_instr,
14630 ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val)15754 ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val)
14631{15755{
14632 Error err;15756 Error err;
...@@ -14634,12 +15758,12 @@ static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInstruction *source...@@ -14634,12 +15758,12 @@ static ErrorMsg *ir_eval_bin_op_cmp_scalar(IrAnalyze *ira, IrInstruction *source
14634 // Before resolving the values, we special case comparisons against zero. These can often15758 // Before resolving the values, we special case comparisons against zero. These can often
14635 // be done without resolving lazy values, preventing potential dependency loops.15759 // be done without resolving lazy values, preventing potential dependency loops.
14636 Cmp op1_cmp_zero;15760 Cmp op1_cmp_zero;
14637 if ((err = lazy_cmp_zero(source_instr->source_node, op1_val, &op1_cmp_zero))) {15761 if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op1_val, &op1_cmp_zero))) {
14638 if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally;15762 if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally;
14639 return ira->codegen->trace_err;15763 return ira->codegen->trace_err;
14640 }15764 }
14641 Cmp op2_cmp_zero;15765 Cmp op2_cmp_zero;
14642 if ((err = lazy_cmp_zero(source_instr->source_node, op2_val, &op2_cmp_zero))) {15766 if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op2_val, &op2_cmp_zero))) {
14643 if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally;15767 if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally;
14644 return ira->codegen->trace_err;15768 return ira->codegen->trace_err;
14645 }15769 }
...@@ -14704,14 +15828,14 @@ never_mind_just_calculate_it_normally:...@@ -14704,14 +15828,14 @@ never_mind_just_calculate_it_normally:
14704 return nullptr;15828 return nullptr;
14705 }15829 }
14706 if (op1_val->type->id == ZigTypeIdComptimeFloat) {15830 if (op1_val->type->id == ZigTypeIdComptimeFloat) {
14707 IrInstruction *tmp = ir_const_noval(ira, source_instr);15831 IrInstGen *tmp = ir_const_noval(ira, source_instr);
14708 tmp->value = op1_val;15832 tmp->value = op1_val;
14709 IrInstruction *casted = ir_implicit_cast(ira, tmp, op2_val->type);15833 IrInstGen *casted = ir_implicit_cast(ira, tmp, op2_val->type);
14710 op1_val = casted->value;15834 op1_val = casted->value;
14711 } else if (op2_val->type->id == ZigTypeIdComptimeFloat) {15835 } else if (op2_val->type->id == ZigTypeIdComptimeFloat) {
14712 IrInstruction *tmp = ir_const_noval(ira, source_instr);15836 IrInstGen *tmp = ir_const_noval(ira, source_instr);
14713 tmp->value = op2_val;15837 tmp->value = op2_val;
14714 IrInstruction *casted = ir_implicit_cast(ira, tmp, op1_val->type);15838 IrInstGen *casted = ir_implicit_cast(ira, tmp, op1_val->type);
14715 op2_val = casted->value;15839 op2_val = casted->value;
14716 }15840 }
14717 Cmp cmp_result = float_cmp(op1_val, op2_val);15841 Cmp cmp_result = float_cmp(op1_val, op2_val);
...@@ -14723,38 +15847,49 @@ never_mind_just_calculate_it_normally:...@@ -14723,38 +15847,49 @@ never_mind_just_calculate_it_normally:
14723 bool op1_is_int = op1_val->type->id == ZigTypeIdInt || op1_val->type->id == ZigTypeIdComptimeInt;15847 bool op1_is_int = op1_val->type->id == ZigTypeIdInt || op1_val->type->id == ZigTypeIdComptimeInt;
14724 bool op2_is_int = op2_val->type->id == ZigTypeIdInt || op2_val->type->id == ZigTypeIdComptimeInt;15848 bool op2_is_int = op2_val->type->id == ZigTypeIdInt || op2_val->type->id == ZigTypeIdComptimeInt;
1472515849
14726 BigInt *op1_bigint;15850 if (op1_is_int && op2_is_int) {
14727 BigInt *op2_bigint;15851 Cmp cmp_result = bigint_cmp(&op1_val->data.x_bigint, &op2_val->data.x_bigint);
14728 bool need_to_free_op1_bigint = false;15852 out_val->special = ConstValSpecialStatic;
14729 bool need_to_free_op2_bigint = false;15853 out_val->data.x_bool = resolve_cmp_op_id(op_id, cmp_result);
14730 if (op1_is_float) {15854
14731 op1_bigint = allocate<BigInt>(1, "BigInt");15855 return nullptr;
14732 need_to_free_op1_bigint = true;
14733 float_init_bigint(op1_bigint, op1_val);
14734 } else {
14735 assert(op1_is_int);
14736 op1_bigint = &op1_val->data.x_bigint;
14737 }15856 }
14738 if (op2_is_float) {15857
14739 op2_bigint = allocate<BigInt>(1, "BigInt");15858 // Handle the case where one of the two operands is a fp value and the other
14740 need_to_free_op2_bigint = true;15859 // is an integer value
14741 float_init_bigint(op2_bigint, op2_val);15860 ZigValue *float_val;
15861 if (op1_is_int && op2_is_float) {
15862 float_val = op2_val;
15863 } else if (op1_is_float && op2_is_int) {
15864 float_val = op1_val;
14742 } else {15865 } else {
14743 assert(op2_is_int);15866 zig_unreachable();
14744 op2_bigint = &op2_val->data.x_bigint;15867 }
15868
15869 // They can never be equal if the fp value has a non-zero decimal part
15870 if (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq) {
15871 if (float_has_fraction(float_val)) {
15872 out_val->special = ConstValSpecialStatic;
15873 out_val->data.x_bool = op_id == IrBinOpCmpNotEq;
15874 return nullptr;
15875 }
14745 }15876 }
1474615877
14747 Cmp cmp_result = bigint_cmp(op1_bigint, op2_bigint);15878 // Cast the integer operand into a fp value to perform the comparison
15879 BigFloat op1_bigfloat;
15880 BigFloat op2_bigfloat;
15881 value_to_bigfloat(&op1_bigfloat, op1_val);
15882 value_to_bigfloat(&op2_bigfloat, op2_val);
15883
15884 Cmp cmp_result = bigfloat_cmp(&op1_bigfloat, &op2_bigfloat);
14748 out_val->special = ConstValSpecialStatic;15885 out_val->special = ConstValSpecialStatic;
14749 out_val->data.x_bool = resolve_cmp_op_id(op_id, cmp_result);15886 out_val->data.x_bool = resolve_cmp_op_id(op_id, cmp_result);
1475015887
14751 if (need_to_free_op1_bigint) destroy(op1_bigint, "BigInt");
14752 if (need_to_free_op2_bigint) destroy(op2_bigint, "BigInt");
14753 return nullptr;15888 return nullptr;
14754}15889}
1475515890
14756static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstruction *source_instr,15891static IrInstGen *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInst *source_instr,
14757 IrInstruction *op1, IrInstruction *op2, IrBinOp op_id)15892 IrInstGen *op1, IrInstGen *op2, IrBinOp op_id)
14758{15893{
14759 Error err;15894 Error err;
1476015895
...@@ -14767,7 +15902,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio...@@ -14767,7 +15902,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
14767 ir_add_error(ira, source_instr,15902 ir_add_error(ira, source_instr,
14768 buf_sprintf("vector length mismatch: %" PRIu32 " and %" PRIu32,15903 buf_sprintf("vector length mismatch: %" PRIu32 " and %" PRIu32,
14769 op1->value->type->data.vector.len, op2->value->type->data.vector.len));15904 op1->value->type->data.vector.len, op2->value->type->data.vector.len));
14770 return ira->codegen->invalid_instruction;15905 return ira->codegen->invalid_inst_gen;
14771 }15906 }
14772 result_type = get_vector_type(ira->codegen, op1->value->type->data.vector.len, scalar_result_type);15907 result_type = get_vector_type(ira->codegen, op1->value->type->data.vector.len, scalar_result_type);
14773 op1_scalar_type = op1->value->type->data.vector.elem_type;15908 op1_scalar_type = op1->value->type->data.vector.elem_type;
...@@ -14776,13 +15911,13 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio...@@ -14776,13 +15911,13 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
14776 ir_add_error(ira, source_instr,15911 ir_add_error(ira, source_instr,
14777 buf_sprintf("mixed scalar and vector operands to comparison operator: '%s' and '%s'",15912 buf_sprintf("mixed scalar and vector operands to comparison operator: '%s' and '%s'",
14778 buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name)));15913 buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name)));
14779 return ira->codegen->invalid_instruction;15914 return ira->codegen->invalid_inst_gen;
14780 }15915 }
1478115916
14782 bool opv_op1;15917 bool opv_op1;
14783 switch (type_has_one_possible_value(ira->codegen, op1->value->type)) {15918 switch (type_has_one_possible_value(ira->codegen, op1->value->type)) {
14784 case OnePossibleValueInvalid:15919 case OnePossibleValueInvalid:
14785 return ira->codegen->invalid_instruction;15920 return ira->codegen->invalid_inst_gen;
14786 case OnePossibleValueYes:15921 case OnePossibleValueYes:
14787 opv_op1 = true;15922 opv_op1 = true;
14788 break;15923 break;
...@@ -14793,7 +15928,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio...@@ -14793,7 +15928,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
14793 bool opv_op2;15928 bool opv_op2;
14794 switch (type_has_one_possible_value(ira->codegen, op2->value->type)) {15929 switch (type_has_one_possible_value(ira->codegen, op2->value->type)) {
14795 case OnePossibleValueInvalid:15930 case OnePossibleValueInvalid:
14796 return ira->codegen->invalid_instruction;15931 return ira->codegen->invalid_inst_gen;
14797 case OnePossibleValueYes:15932 case OnePossibleValueYes:
14798 opv_op2 = true;15933 opv_op2 = true;
14799 break;15934 break;
...@@ -14803,22 +15938,22 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio...@@ -14803,22 +15938,22 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
14803 }15938 }
14804 Cmp op1_cmp_zero;15939 Cmp op1_cmp_zero;
14805 bool have_op1_cmp_zero = false;15940 bool have_op1_cmp_zero = false;
14806 if ((err = lazy_cmp_zero(source_instr->source_node, op1->value, &op1_cmp_zero))) {15941 if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op1->value, &op1_cmp_zero))) {
14807 if (err != ErrorNotLazy) return ira->codegen->invalid_instruction;15942 if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen;
14808 } else {15943 } else {
14809 have_op1_cmp_zero = true;15944 have_op1_cmp_zero = true;
14810 }15945 }
14811 Cmp op2_cmp_zero;15946 Cmp op2_cmp_zero;
14812 bool have_op2_cmp_zero = false;15947 bool have_op2_cmp_zero = false;
14813 if ((err = lazy_cmp_zero(source_instr->source_node, op2->value, &op2_cmp_zero))) {15948 if ((err = lazy_cmp_zero(ira->codegen, source_instr->source_node, op2->value, &op2_cmp_zero))) {
14814 if (err != ErrorNotLazy) return ira->codegen->invalid_instruction;15949 if (err != ErrorNotLazy) return ira->codegen->invalid_inst_gen;
14815 } else {15950 } else {
14816 have_op2_cmp_zero = true;15951 have_op2_cmp_zero = true;
14817 }15952 }
14818 if (((opv_op1 || instr_is_comptime(op1)) && (opv_op2 || instr_is_comptime(op2))) ||15953 if (((opv_op1 || instr_is_comptime(op1)) && (opv_op2 || instr_is_comptime(op2))) ||
14819 (have_op1_cmp_zero && have_op2_cmp_zero))15954 (have_op1_cmp_zero && have_op2_cmp_zero))
14820 {15955 {
14821 IrInstruction *result_instruction = ir_const(ira, source_instr, result_type);15956 IrInstGen *result_instruction = ir_const(ira, source_instr, result_type);
14822 ZigValue *out_val = result_instruction->value;15957 ZigValue *out_val = result_instruction->value;
14823 if (result_type->id == ZigTypeIdVector) {15958 if (result_type->id == ZigTypeIdVector) {
14824 size_t len = result_type->data.vector.len;15959 size_t len = result_type->data.vector.len;
...@@ -14836,7 +15971,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio...@@ -14836,7 +15971,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
14836 if (msg != nullptr) {15971 if (msg != nullptr) {
14837 add_error_note(ira->codegen, msg, source_instr->source_node,15972 add_error_note(ira->codegen, msg, source_instr->source_node,
14838 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));15973 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));
14839 return ira->codegen->invalid_instruction;15974 return ira->codegen->invalid_inst_gen;
14840 }15975 }
14841 }15976 }
14842 out_val->type = result_type;15977 out_val->type = result_type;
...@@ -14845,7 +15980,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio...@@ -14845,7 +15980,7 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
14845 if (ir_eval_bin_op_cmp_scalar(ira, source_instr, op1->value, op_id,15980 if (ir_eval_bin_op_cmp_scalar(ira, source_instr, op1->value, op_id,
14846 op2->value, out_val) != nullptr)15981 op2->value, out_val) != nullptr)
14847 {15982 {
14848 return ira->codegen->invalid_instruction;15983 return ira->codegen->invalid_inst_gen;
14849 }15984 }
14850 }15985 }
14851 return result_instruction;15986 return result_instruction;
...@@ -14939,10 +16074,10 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio...@@ -14939,10 +16074,10 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
14939 }16074 }
14940 ZigType *dest_type = (result_type->id == ZigTypeIdVector) ?16075 ZigType *dest_type = (result_type->id == ZigTypeIdVector) ?
14941 get_vector_type(ira->codegen, result_type->data.vector.len, dest_scalar_type) : dest_scalar_type;16076 get_vector_type(ira->codegen, result_type->data.vector.len, dest_scalar_type) : dest_scalar_type;
14942 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type);16077 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, dest_type);
14943 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, dest_type);16078 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, dest_type);
14944 if (type_is_invalid(casted_op1->value->type) || type_is_invalid(casted_op2->value->type))16079 if (type_is_invalid(casted_op1->value->type) || type_is_invalid(casted_op2->value->type))
14945 return ira->codegen->invalid_instruction;16080 return ira->codegen->invalid_inst_gen;
14946 return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true);16081 return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true);
14947 }16082 }
1494816083
...@@ -14972,12 +16107,12 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio...@@ -14972,12 +16107,12 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
14972 if (instr_is_comptime(op1)) {16107 if (instr_is_comptime(op1)) {
14973 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefOk);16108 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefOk);
14974 if (op1_val == nullptr)16109 if (op1_val == nullptr)
14975 return ira->codegen->invalid_instruction;16110 return ira->codegen->invalid_inst_gen;
14976 if (op1_val->special == ConstValSpecialUndef)16111 if (op1_val->special == ConstValSpecialUndef)
14977 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);16112 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);
14978 if (result_type->id == ZigTypeIdVector) {16113 if (result_type->id == ZigTypeIdVector) {
14979 ir_add_error(ira, op1, buf_sprintf("compiler bug: TODO: support comptime vector here"));16114 ir_add_error(ira, &op1->base, buf_sprintf("compiler bug: TODO: support comptime vector here"));
14980 return ira->codegen->invalid_instruction;16115 return ira->codegen->invalid_inst_gen;
14981 }16116 }
14982 bool is_unsigned;16117 bool is_unsigned;
14983 if (op1_is_float) {16118 if (op1_is_float) {
...@@ -15016,12 +16151,12 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio...@@ -15016,12 +16151,12 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
15016 if (instr_is_comptime(op2)) {16151 if (instr_is_comptime(op2)) {
15017 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefOk);16152 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefOk);
15018 if (op2_val == nullptr)16153 if (op2_val == nullptr)
15019 return ira->codegen->invalid_instruction;16154 return ira->codegen->invalid_inst_gen;
15020 if (op2_val->special == ConstValSpecialUndef)16155 if (op2_val->special == ConstValSpecialUndef)
15021 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);16156 return ir_const_undef(ira, source_instr, ira->codegen->builtin_types.entry_bool);
15022 if (result_type->id == ZigTypeIdVector) {16157 if (result_type->id == ZigTypeIdVector) {
15023 ir_add_error(ira, op2, buf_sprintf("compiler bug: TODO: support comptime vector here"));16158 ir_add_error(ira, &op2->base, buf_sprintf("compiler bug: TODO: support comptime vector here"));
15024 return ira->codegen->invalid_instruction;16159 return ira->codegen->invalid_inst_gen;
15025 }16160 }
15026 bool is_unsigned;16161 bool is_unsigned;
15027 if (op2_is_float) {16162 if (op2_is_float) {
...@@ -15062,35 +16197,35 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio...@@ -15062,35 +16197,35 @@ static IrInstruction *ir_analyze_bin_op_cmp_numeric(IrAnalyze *ira, IrInstructio
15062 ZigType *dest_type = (result_type->id == ZigTypeIdVector) ?16197 ZigType *dest_type = (result_type->id == ZigTypeIdVector) ?
15063 get_vector_type(ira->codegen, result_type->data.vector.len, dest_scalar_type) : dest_scalar_type;16198 get_vector_type(ira->codegen, result_type->data.vector.len, dest_scalar_type) : dest_scalar_type;
1506416199
15065 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type);16200 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, dest_type);
15066 if (type_is_invalid(casted_op1->value->type))16201 if (type_is_invalid(casted_op1->value->type))
15067 return ira->codegen->invalid_instruction;16202 return ira->codegen->invalid_inst_gen;
15068 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, dest_type);16203 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, dest_type);
15069 if (type_is_invalid(casted_op2->value->type))16204 if (type_is_invalid(casted_op2->value->type))
15070 return ira->codegen->invalid_instruction;16205 return ira->codegen->invalid_inst_gen;
15071 return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true);16206 return ir_build_bin_op_gen(ira, source_instr, result_type, op_id, casted_op1, casted_op2, true);
15072}16207}
1507316208
15074static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {16209static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {
15075 IrInstruction *op1 = bin_op_instruction->op1->child;16210 IrInstGen *op1 = bin_op_instruction->op1->child;
15076 if (type_is_invalid(op1->value->type))16211 if (type_is_invalid(op1->value->type))
15077 return ira->codegen->invalid_instruction;16212 return ira->codegen->invalid_inst_gen;
1507816213
15079 IrInstruction *op2 = bin_op_instruction->op2->child;16214 IrInstGen *op2 = bin_op_instruction->op2->child;
15080 if (type_is_invalid(op2->value->type))16215 if (type_is_invalid(op2->value->type))
15081 return ira->codegen->invalid_instruction;16216 return ira->codegen->invalid_inst_gen;
1508216217
15083 AstNode *source_node = bin_op_instruction->base.source_node;16218 AstNode *source_node = bin_op_instruction->base.base.source_node;
1508416219
15085 IrBinOp op_id = bin_op_instruction->op_id;16220 IrBinOp op_id = bin_op_instruction->op_id;
15086 bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);16221 bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);
15087 if (is_equality_cmp && op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdNull) {16222 if (is_equality_cmp && op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdNull) {
15088 return ir_const_bool(ira, &bin_op_instruction->base, (op_id == IrBinOpCmpEq));16223 return ir_const_bool(ira, &bin_op_instruction->base.base, (op_id == IrBinOpCmpEq));
15089 } else if (is_equality_cmp &&16224 } else if (is_equality_cmp &&
15090 ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdOptional) ||16225 ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdOptional) ||
15091 (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdOptional)))16226 (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdOptional)))
15092 {16227 {
15093 IrInstruction *maybe_op;16228 IrInstGen *maybe_op;
15094 if (op1->value->type->id == ZigTypeIdNull) {16229 if (op1->value->type->id == ZigTypeIdNull) {
15095 maybe_op = op2;16230 maybe_op = op2;
15096 } else if (op2->value->type->id == ZigTypeIdNull) {16231 } else if (op2->value->type->id == ZigTypeIdNull) {
...@@ -15101,21 +16236,16 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -15101,21 +16236,16 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15101 if (instr_is_comptime(maybe_op)) {16236 if (instr_is_comptime(maybe_op)) {
15102 ZigValue *maybe_val = ir_resolve_const(ira, maybe_op, UndefBad);16237 ZigValue *maybe_val = ir_resolve_const(ira, maybe_op, UndefBad);
15103 if (!maybe_val)16238 if (!maybe_val)
15104 return ira->codegen->invalid_instruction;16239 return ira->codegen->invalid_inst_gen;
15105 bool is_null = optional_value_is_null(maybe_val);16240 bool is_null = optional_value_is_null(maybe_val);
15106 bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null;16241 bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null;
15107 return ir_const_bool(ira, &bin_op_instruction->base, bool_result);16242 return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result);
15108 }16243 }
1510916244
15110 IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope,16245 IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, &bin_op_instruction->base.base, maybe_op);
15111 source_node, maybe_op);
15112 is_non_null->value->type = ira->codegen->builtin_types.entry_bool;
1511316246
15114 if (op_id == IrBinOpCmpEq) {16247 if (op_id == IrBinOpCmpEq) {
15115 IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope,16248 return ir_build_bool_not_gen(ira, &bin_op_instruction->base.base, is_non_null);
15116 bin_op_instruction->base.source_node, is_non_null);
15117 result->value->type = ira->codegen->builtin_types.entry_bool;
15118 return result;
15119 } else {16249 } else {
15120 return is_non_null;16250 return is_non_null;
15121 }16251 }
...@@ -15125,7 +16255,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -15125,7 +16255,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15125 (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdPointer &&16255 (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdPointer &&
15126 op1->value->type->data.pointer.ptr_len == PtrLenC)))16256 op1->value->type->data.pointer.ptr_len == PtrLenC)))
15127 {16257 {
15128 IrInstruction *c_ptr_op;16258 IrInstGen *c_ptr_op;
15129 if (op1->value->type->id == ZigTypeIdNull) {16259 if (op1->value->type->id == ZigTypeIdNull) {
15130 c_ptr_op = op2;16260 c_ptr_op = op2;
15131 } else if (op2->value->type->id == ZigTypeIdNull) {16261 } else if (op2->value->type->id == ZigTypeIdNull) {
...@@ -15136,24 +16266,19 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -15136,24 +16266,19 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15136 if (instr_is_comptime(c_ptr_op)) {16266 if (instr_is_comptime(c_ptr_op)) {
15137 ZigValue *c_ptr_val = ir_resolve_const(ira, c_ptr_op, UndefOk);16267 ZigValue *c_ptr_val = ir_resolve_const(ira, c_ptr_op, UndefOk);
15138 if (!c_ptr_val)16268 if (!c_ptr_val)
15139 return ira->codegen->invalid_instruction;16269 return ira->codegen->invalid_inst_gen;
15140 if (c_ptr_val->special == ConstValSpecialUndef)16270 if (c_ptr_val->special == ConstValSpecialUndef)
15141 return ir_const_undef(ira, &bin_op_instruction->base, ira->codegen->builtin_types.entry_bool);16271 return ir_const_undef(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool);
15142 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||16272 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||
15143 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&16273 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
15144 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);16274 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);
15145 bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null;16275 bool bool_result = (op_id == IrBinOpCmpEq) ? is_null : !is_null;
15146 return ir_const_bool(ira, &bin_op_instruction->base, bool_result);16276 return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result);
15147 }16277 }
15148 IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope,16278 IrInstGen *is_non_null = ir_build_test_non_null_gen(ira, &bin_op_instruction->base.base, c_ptr_op);
15149 source_node, c_ptr_op);
15150 is_non_null->value->type = ira->codegen->builtin_types.entry_bool;
1515116279
15152 if (op_id == IrBinOpCmpEq) {16280 if (op_id == IrBinOpCmpEq) {
15153 IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope,16281 return ir_build_bool_not_gen(ira, &bin_op_instruction->base.base, is_non_null);
15154 bin_op_instruction->base.source_node, is_non_null);
15155 result->value->type = ira->codegen->builtin_types.entry_bool;
15156 return result;
15157 } else {16282 } else {
15158 return is_non_null;16283 return is_non_null;
15159 }16284 }
...@@ -15161,61 +16286,57 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -15161,61 +16286,57 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15161 ZigType *non_null_type = (op1->value->type->id == ZigTypeIdNull) ? op2->value->type : op1->value->type;16286 ZigType *non_null_type = (op1->value->type->id == ZigTypeIdNull) ? op2->value->type : op1->value->type;
15162 ir_add_error_node(ira, source_node, buf_sprintf("comparison of '%s' with null",16287 ir_add_error_node(ira, source_node, buf_sprintf("comparison of '%s' with null",
15163 buf_ptr(&non_null_type->name)));16288 buf_ptr(&non_null_type->name)));
15164 return ira->codegen->invalid_instruction;16289 return ira->codegen->invalid_inst_gen;
15165 } else if (is_equality_cmp && (16290 } else if (is_equality_cmp && (
15166 (op1->value->type->id == ZigTypeIdEnumLiteral && op2->value->type->id == ZigTypeIdUnion) ||16291 (op1->value->type->id == ZigTypeIdEnumLiteral && op2->value->type->id == ZigTypeIdUnion) ||
15167 (op2->value->type->id == ZigTypeIdEnumLiteral && op1->value->type->id == ZigTypeIdUnion)))16292 (op2->value->type->id == ZigTypeIdEnumLiteral && op1->value->type->id == ZigTypeIdUnion)))
15168 {16293 {
15169 // Support equality comparison between a union's tag value and a enum literal16294 // Support equality comparison between a union's tag value and a enum literal
15170 IrInstruction *union_val = op1->value->type->id == ZigTypeIdUnion ? op1 : op2;16295 IrInstGen *union_val = op1->value->type->id == ZigTypeIdUnion ? op1 : op2;
15171 IrInstruction *enum_val = op1->value->type->id == ZigTypeIdUnion ? op2 : op1;16296 IrInstGen *enum_val = op1->value->type->id == ZigTypeIdUnion ? op2 : op1;
1517216297
15173 ZigType *tag_type = union_val->value->type->data.unionation.tag_type;16298 ZigType *tag_type = union_val->value->type->data.unionation.tag_type;
15174 assert(tag_type != nullptr);16299 assert(tag_type != nullptr);
1517516300
15176 IrInstruction *casted_union = ir_implicit_cast(ira, union_val, tag_type);16301 IrInstGen *casted_union = ir_implicit_cast(ira, union_val, tag_type);
15177 if (type_is_invalid(casted_union->value->type))16302 if (type_is_invalid(casted_union->value->type))
15178 return ira->codegen->invalid_instruction;16303 return ira->codegen->invalid_inst_gen;
1517916304
15180 IrInstruction *casted_val = ir_implicit_cast(ira, enum_val, tag_type);16305 IrInstGen *casted_val = ir_implicit_cast(ira, enum_val, tag_type);
15181 if (type_is_invalid(casted_val->value->type))16306 if (type_is_invalid(casted_val->value->type))
15182 return ira->codegen->invalid_instruction;16307 return ira->codegen->invalid_inst_gen;
1518316308
15184 if (instr_is_comptime(casted_union)) {16309 if (instr_is_comptime(casted_union)) {
15185 ZigValue *const_union_val = ir_resolve_const(ira, casted_union, UndefBad);16310 ZigValue *const_union_val = ir_resolve_const(ira, casted_union, UndefBad);
15186 if (!const_union_val)16311 if (!const_union_val)
15187 return ira->codegen->invalid_instruction;16312 return ira->codegen->invalid_inst_gen;
1518816313
15189 ZigValue *const_enum_val = ir_resolve_const(ira, casted_val, UndefBad);16314 ZigValue *const_enum_val = ir_resolve_const(ira, casted_val, UndefBad);
15190 if (!const_enum_val)16315 if (!const_enum_val)
15191 return ira->codegen->invalid_instruction;16316 return ira->codegen->invalid_inst_gen;
1519216317
15193 Cmp cmp_result = bigint_cmp(&const_union_val->data.x_union.tag, &const_enum_val->data.x_enum_tag);16318 Cmp cmp_result = bigint_cmp(&const_union_val->data.x_union.tag, &const_enum_val->data.x_enum_tag);
15194 bool bool_result = (op_id == IrBinOpCmpEq) ? cmp_result == CmpEQ : cmp_result != CmpEQ;16319 bool bool_result = (op_id == IrBinOpCmpEq) ? cmp_result == CmpEQ : cmp_result != CmpEQ;
1519516320
15196 return ir_const_bool(ira, &bin_op_instruction->base, bool_result);16321 return ir_const_bool(ira, &bin_op_instruction->base.base, bool_result);
15197 }16322 }
1519816323
15199 IrInstruction *result = ir_build_bin_op(&ira->new_irb,16324 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool,
15200 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
15201 op_id, casted_union, casted_val, bin_op_instruction->safety_check_on);16325 op_id, casted_union, casted_val, bin_op_instruction->safety_check_on);
15202 result->value->type = ira->codegen->builtin_types.entry_bool;
15203
15204 return result;
15205 }16326 }
1520616327
15207 if (op1->value->type->id == ZigTypeIdErrorSet && op2->value->type->id == ZigTypeIdErrorSet) {16328 if (op1->value->type->id == ZigTypeIdErrorSet && op2->value->type->id == ZigTypeIdErrorSet) {
15208 if (!is_equality_cmp) {16329 if (!is_equality_cmp) {
15209 ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors"));16330 ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors"));
15210 return ira->codegen->invalid_instruction;16331 return ira->codegen->invalid_inst_gen;
15211 }16332 }
15212 ZigType *intersect_type = get_error_set_intersection(ira, op1->value->type, op2->value->type, source_node);16333 ZigType *intersect_type = get_error_set_intersection(ira, op1->value->type, op2->value->type, source_node);
15213 if (type_is_invalid(intersect_type)) {16334 if (type_is_invalid(intersect_type)) {
15214 return ira->codegen->invalid_instruction;16335 return ira->codegen->invalid_inst_gen;
15215 }16336 }
1521616337
15217 if (!resolve_inferred_error_set(ira->codegen, intersect_type, source_node)) {16338 if (!resolve_inferred_error_set(ira->codegen, intersect_type, source_node)) {
15218 return ira->codegen->invalid_instruction;16339 return ira->codegen->invalid_inst_gen;
15219 }16340 }
1522016341
15221 // exception if one of the operators has the type of the empty error set, we allow the comparison16342 // exception if one of the operators has the type of the empty error set, we allow the comparison
...@@ -15232,7 +16353,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -15232,7 +16353,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15232 } else {16353 } else {
15233 zig_unreachable();16354 zig_unreachable();
15234 }16355 }
15235 return ir_const_bool(ira, &bin_op_instruction->base, answer);16356 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
15236 }16357 }
1523716358
15238 if (!type_is_global_error_set(intersect_type)) {16359 if (!type_is_global_error_set(intersect_type)) {
...@@ -15240,7 +16361,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -15240,7 +16361,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15240 ir_add_error_node(ira, source_node,16361 ir_add_error_node(ira, source_node,
15241 buf_sprintf("error sets '%s' and '%s' have no common errors",16362 buf_sprintf("error sets '%s' and '%s' have no common errors",
15242 buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name)));16363 buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name)));
15243 return ira->codegen->invalid_instruction;16364 return ira->codegen->invalid_inst_gen;
15244 }16365 }
15245 if (op1->value->type->data.error_set.err_count == 1 && op2->value->type->data.error_set.err_count == 1) {16366 if (op1->value->type->data.error_set.err_count == 1 && op2->value->type->data.error_set.err_count == 1) {
15246 bool are_equal = true;16367 bool are_equal = true;
...@@ -15252,17 +16373,17 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -15252,17 +16373,17 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15252 } else {16373 } else {
15253 zig_unreachable();16374 zig_unreachable();
15254 }16375 }
15255 return ir_const_bool(ira, &bin_op_instruction->base, answer);16376 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
15256 }16377 }
15257 }16378 }
1525816379
15259 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {16380 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
15260 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);16381 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
15261 if (op1_val == nullptr)16382 if (op1_val == nullptr)
15262 return ira->codegen->invalid_instruction;16383 return ira->codegen->invalid_inst_gen;
15263 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);16384 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
15264 if (op2_val == nullptr)16385 if (op2_val == nullptr)
15265 return ira->codegen->invalid_instruction;16386 return ira->codegen->invalid_inst_gen;
1526616387
15267 bool answer;16388 bool answer;
15268 bool are_equal = op1_val->data.x_err_set->value == op2_val->data.x_err_set->value;16389 bool are_equal = op1_val->data.x_err_set->value == op2_val->data.x_err_set->value;
...@@ -15274,27 +16395,24 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -15274,27 +16395,24 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15274 zig_unreachable();16395 zig_unreachable();
15275 }16396 }
1527616397
15277 return ir_const_bool(ira, &bin_op_instruction->base, answer);16398 return ir_const_bool(ira, &bin_op_instruction->base.base, answer);
15278 }16399 }
1527916400
15280 IrInstruction *result = ir_build_bin_op(&ira->new_irb,16401 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, ira->codegen->builtin_types.entry_bool,
15281 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
15282 op_id, op1, op2, bin_op_instruction->safety_check_on);16402 op_id, op1, op2, bin_op_instruction->safety_check_on);
15283 result->value->type = ira->codegen->builtin_types.entry_bool;
15284 return result;
15285 }16403 }
1528616404
15287 if (type_is_numeric(op1->value->type) && type_is_numeric(op2->value->type)) {16405 if (type_is_numeric(op1->value->type) && type_is_numeric(op2->value->type)) {
15288 // This operation allows any combination of integer and float types, regardless of the16406 // This operation allows any combination of integer and float types, regardless of the
15289 // signed-ness, comptime-ness, and bit-width. So peer type resolution is incorrect for16407 // signed-ness, comptime-ness, and bit-width. So peer type resolution is incorrect for
15290 // numeric types.16408 // numeric types.
15291 return ir_analyze_bin_op_cmp_numeric(ira, &bin_op_instruction->base, op1, op2, op_id);16409 return ir_analyze_bin_op_cmp_numeric(ira, &bin_op_instruction->base.base, op1, op2, op_id);
15292 }16410 }
1529316411
15294 IrInstruction *instructions[] = {op1, op2};16412 IrInstGen *instructions[] = {op1, op2};
15295 ZigType *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2);16413 ZigType *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2);
15296 if (type_is_invalid(resolved_type))16414 if (type_is_invalid(resolved_type))
15297 return ira->codegen->invalid_instruction;16415 return ira->codegen->invalid_inst_gen;
1529816416
15299 bool operator_allowed;16417 bool operator_allowed;
15300 switch (resolved_type->id) {16418 switch (resolved_type->id) {
...@@ -15342,21 +16460,21 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -15342,21 +16460,21 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15342 if (!operator_allowed) {16460 if (!operator_allowed) {
15343 ir_add_error_node(ira, source_node,16461 ir_add_error_node(ira, source_node,
15344 buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));16462 buf_sprintf("operator not allowed for type '%s'", buf_ptr(&resolved_type->name)));
15345 return ira->codegen->invalid_instruction;16463 return ira->codegen->invalid_inst_gen;
15346 }16464 }
1534716465
15348 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);16466 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);
15349 if (casted_op1 == ira->codegen->invalid_instruction)16467 if (type_is_invalid(casted_op1->value->type))
15350 return ira->codegen->invalid_instruction;16468 return ira->codegen->invalid_inst_gen;
1535116469
15352 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);16470 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
15353 if (casted_op2 == ira->codegen->invalid_instruction)16471 if (type_is_invalid(casted_op2->value->type))
15354 return ira->codegen->invalid_instruction;16472 return ira->codegen->invalid_inst_gen;
1535516473
15356 bool one_possible_value;16474 bool one_possible_value;
15357 switch (type_has_one_possible_value(ira->codegen, resolved_type)) {16475 switch (type_has_one_possible_value(ira->codegen, resolved_type)) {
15358 case OnePossibleValueInvalid:16476 case OnePossibleValueInvalid:
15359 return ira->codegen->invalid_instruction;16477 return ira->codegen->invalid_inst_gen;
15360 case OnePossibleValueYes:16478 case OnePossibleValueYes:
15361 one_possible_value = true;16479 one_possible_value = true;
15362 break;16480 break;
...@@ -15368,20 +16486,20 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -15368,20 +16486,20 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15368 if (one_possible_value || (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2))) {16486 if (one_possible_value || (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2))) {
15369 ZigValue *op1_val = one_possible_value ? casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad);16487 ZigValue *op1_val = one_possible_value ? casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad);
15370 if (op1_val == nullptr)16488 if (op1_val == nullptr)
15371 return ira->codegen->invalid_instruction;16489 return ira->codegen->invalid_inst_gen;
15372 ZigValue *op2_val = one_possible_value ? casted_op2->value : ir_resolve_const(ira, casted_op2, UndefBad);16490 ZigValue *op2_val = one_possible_value ? casted_op2->value : ir_resolve_const(ira, casted_op2, UndefBad);
15373 if (op2_val == nullptr)16491 if (op2_val == nullptr)
15374 return ira->codegen->invalid_instruction;16492 return ira->codegen->invalid_inst_gen;
15375 if (resolved_type->id != ZigTypeIdVector)16493 if (resolved_type->id != ZigTypeIdVector)
15376 return ir_evaluate_bin_op_cmp(ira, resolved_type, op1_val, op2_val, bin_op_instruction, op_id, one_possible_value);16494 return ir_evaluate_bin_op_cmp(ira, resolved_type, op1_val, op2_val, bin_op_instruction, op_id, one_possible_value);
15377 IrInstruction *result = ir_const(ira, &bin_op_instruction->base,16495 IrInstGen *result = ir_const(ira, &bin_op_instruction->base.base,
15378 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool));16496 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool));
15379 result->value->data.x_array.data.s_none.elements =16497 result->value->data.x_array.data.s_none.elements =
15380 create_const_vals(resolved_type->data.vector.len);16498 create_const_vals(resolved_type->data.vector.len);
1538116499
15382 expand_undef_array(ira->codegen, result->value);16500 expand_undef_array(ira->codegen, result->value);
15383 for (size_t i = 0;i < resolved_type->data.vector.len;i++) {16501 for (size_t i = 0;i < resolved_type->data.vector.len;i++) {
15384 IrInstruction *cur_res = ir_evaluate_bin_op_cmp(ira, resolved_type->data.vector.elem_type,16502 IrInstGen *cur_res = ir_evaluate_bin_op_cmp(ira, resolved_type->data.vector.elem_type,
15385 &op1_val->data.x_array.data.s_none.elements[i],16503 &op1_val->data.x_array.data.s_none.elements[i],
15386 &op2_val->data.x_array.data.s_none.elements[i],16504 &op2_val->data.x_array.data.s_none.elements[i],
15387 bin_op_instruction, op_id, one_possible_value);16505 bin_op_instruction, op_id, one_possible_value);
...@@ -15390,19 +16508,14 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *...@@ -15390,19 +16508,14 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
15390 return result;16508 return result;
15391 }16509 }
1539216510
15393 IrInstruction *result = ir_build_bin_op(&ira->new_irb,16511 ZigType *res_type = (resolved_type->id == ZigTypeIdVector) ?
15394 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,16512 get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool) :
16513 ira->codegen->builtin_types.entry_bool;
16514 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, res_type,
15395 op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);16515 op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on);
15396 if (resolved_type->id == ZigTypeIdVector) {
15397 result->value->type = get_vector_type(ira->codegen, resolved_type->data.vector.len,
15398 ira->codegen->builtin_types.entry_bool);
15399 } else {
15400 result->value->type = ira->codegen->builtin_types.entry_bool;
15401 }
15402 return result;
15403}16516}
1540416517
15405static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry,16518static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInst* source_instr, ZigType *type_entry,
15406 ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val)16519 ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val)
15407{16520{
15408 bool is_int;16521 bool is_int;
...@@ -15582,10 +16695,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in...@@ -15582,10 +16695,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in
15582}16695}
1558316696
15584// This works on operands that have already been checked to be comptime known.16697// This works on operands that have already been checked to be comptime known.
15585static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_instr,16698static IrInstGen *ir_analyze_math_op(IrAnalyze *ira, IrInst* source_instr,
15586 ZigType *type_entry, ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val)16699 ZigType *type_entry, ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val)
15587{16700{
15588 IrInstruction *result_instruction = ir_const(ira, source_instr, type_entry);16701 IrInstGen *result_instruction = ir_const(ira, source_instr, type_entry);
15589 ZigValue *out_val = result_instruction->value;16702 ZigValue *out_val = result_instruction->value;
15590 if (type_entry->id == ZigTypeIdVector) {16703 if (type_entry->id == ZigTypeIdVector) {
15591 expand_undef_array(ira->codegen, op1_val);16704 expand_undef_array(ira->codegen, op1_val);
...@@ -15606,43 +16719,43 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i...@@ -15606,43 +16719,43 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i
15606 if (msg != nullptr) {16719 if (msg != nullptr) {
15607 add_error_note(ira->codegen, msg, source_instr->source_node,16720 add_error_note(ira->codegen, msg, source_instr->source_node,
15608 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));16721 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));
15609 return ira->codegen->invalid_instruction;16722 return ira->codegen->invalid_inst_gen;
15610 }16723 }
15611 }16724 }
15612 out_val->type = type_entry;16725 out_val->type = type_entry;
15613 out_val->special = ConstValSpecialStatic;16726 out_val->special = ConstValSpecialStatic;
15614 } else {16727 } else {
15615 if (ir_eval_math_op_scalar(ira, source_instr, type_entry, op1_val, op_id, op2_val, out_val) != nullptr) {16728 if (ir_eval_math_op_scalar(ira, source_instr, type_entry, op1_val, op_id, op2_val, out_val) != nullptr) {
15616 return ira->codegen->invalid_instruction;16729 return ira->codegen->invalid_inst_gen;
15617 }16730 }
15618 }16731 }
15619 return ir_implicit_cast(ira, result_instruction, type_entry);16732 return ir_implicit_cast(ira, result_instruction, type_entry);
15620}16733}
1562116734
15622static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {16735static IrInstGen *ir_analyze_bit_shift(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {
15623 IrInstruction *op1 = bin_op_instruction->op1->child;16736 IrInstGen *op1 = bin_op_instruction->op1->child;
15624 if (type_is_invalid(op1->value->type))16737 if (type_is_invalid(op1->value->type))
15625 return ira->codegen->invalid_instruction;16738 return ira->codegen->invalid_inst_gen;
1562616739
15627 if (op1->value->type->id != ZigTypeIdInt && op1->value->type->id != ZigTypeIdComptimeInt) {16740 if (op1->value->type->id != ZigTypeIdInt && op1->value->type->id != ZigTypeIdComptimeInt) {
15628 ir_add_error(ira, bin_op_instruction->op1,16741 ir_add_error(ira, &bin_op_instruction->op1->base,
15629 buf_sprintf("bit shifting operation expected integer type, found '%s'",16742 buf_sprintf("bit shifting operation expected integer type, found '%s'",
15630 buf_ptr(&op1->value->type->name)));16743 buf_ptr(&op1->value->type->name)));
15631 return ira->codegen->invalid_instruction;16744 return ira->codegen->invalid_inst_gen;
15632 }16745 }
1563316746
15634 IrInstruction *op2 = bin_op_instruction->op2->child;16747 IrInstGen *op2 = bin_op_instruction->op2->child;
15635 if (type_is_invalid(op2->value->type))16748 if (type_is_invalid(op2->value->type))
15636 return ira->codegen->invalid_instruction;16749 return ira->codegen->invalid_inst_gen;
1563716750
15638 if (op2->value->type->id != ZigTypeIdInt && op2->value->type->id != ZigTypeIdComptimeInt) {16751 if (op2->value->type->id != ZigTypeIdInt && op2->value->type->id != ZigTypeIdComptimeInt) {
15639 ir_add_error(ira, bin_op_instruction->op2,16752 ir_add_error(ira, &bin_op_instruction->op2->base,
15640 buf_sprintf("shift amount has to be an integer type, but found '%s'",16753 buf_sprintf("shift amount has to be an integer type, but found '%s'",
15641 buf_ptr(&op2->value->type->name)));16754 buf_ptr(&op2->value->type->name)));
15642 return ira->codegen->invalid_instruction;16755 return ira->codegen->invalid_inst_gen;
15643 }16756 }
1564416757
15645 IrInstruction *casted_op2;16758 IrInstGen *casted_op2;
15646 IrBinOp op_id = bin_op_instruction->op_id;16759 IrBinOp op_id = bin_op_instruction->op_id;
15647 if (op1->value->type->id == ZigTypeIdComptimeInt) {16760 if (op1->value->type->id == ZigTypeIdComptimeInt) {
15648 casted_op2 = op2;16761 casted_op2 = op2;
...@@ -15654,8 +16767,8 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b...@@ -15654,8 +16767,8 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b
15654 if (casted_op2->value->data.x_bigint.is_negative) {16767 if (casted_op2->value->data.x_bigint.is_negative) {
15655 Buf *val_buf = buf_alloc();16768 Buf *val_buf = buf_alloc();
15656 bigint_append_buf(val_buf, &casted_op2->value->data.x_bigint, 10);16769 bigint_append_buf(val_buf, &casted_op2->value->data.x_bigint, 10);
15657 ir_add_error(ira, casted_op2, buf_sprintf("shift by negative value %s", buf_ptr(val_buf)));16770 ir_add_error(ira, &casted_op2->base, buf_sprintf("shift by negative value %s", buf_ptr(val_buf)));
15658 return ira->codegen->invalid_instruction;16771 return ira->codegen->invalid_inst_gen;
15659 }16772 }
15660 } else {16773 } else {
15661 ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,16774 ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,
...@@ -15665,57 +16778,51 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b...@@ -15665,57 +16778,51 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b
1566516778
15666 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);16779 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
15667 if (op2_val == nullptr)16780 if (op2_val == nullptr)
15668 return ira->codegen->invalid_instruction;16781 return ira->codegen->invalid_inst_gen;
15669 if (!bigint_fits_in_bits(&op2_val->data.x_bigint,16782 if (!bigint_fits_in_bits(&op2_val->data.x_bigint,
15670 shift_amt_type->data.integral.bit_count,16783 shift_amt_type->data.integral.bit_count,
15671 op2_val->data.x_bigint.is_negative)) {16784 op2_val->data.x_bigint.is_negative)) {
15672 Buf *val_buf = buf_alloc();16785 Buf *val_buf = buf_alloc();
15673 bigint_append_buf(val_buf, &op2_val->data.x_bigint, 10);16786 bigint_append_buf(val_buf, &op2_val->data.x_bigint, 10);
15674 ErrorMsg* msg = ir_add_error(ira,16787 ErrorMsg* msg = ir_add_error(ira,
15675 &bin_op_instruction->base,16788 &bin_op_instruction->base.base,
15676 buf_sprintf("RHS of shift is too large for LHS type"));16789 buf_sprintf("RHS of shift is too large for LHS type"));
15677 add_error_note(16790 add_error_note(
15678 ira->codegen,16791 ira->codegen,
15679 msg,16792 msg,
15680 op2->source_node,16793 op2->base.source_node,
15681 buf_sprintf("value %s cannot fit into type %s",16794 buf_sprintf("value %s cannot fit into type %s",
15682 buf_ptr(val_buf),16795 buf_ptr(val_buf),
15683 buf_ptr(&shift_amt_type->name)));16796 buf_ptr(&shift_amt_type->name)));
15684 return ira->codegen->invalid_instruction;16797 return ira->codegen->invalid_inst_gen;
15685 }16798 }
15686 }16799 }
1568716800
15688 casted_op2 = ir_implicit_cast(ira, op2, shift_amt_type);16801 casted_op2 = ir_implicit_cast(ira, op2, shift_amt_type);
15689 if (casted_op2 == ira->codegen->invalid_instruction)16802 if (type_is_invalid(casted_op2->value->type))
15690 return ira->codegen->invalid_instruction;16803 return ira->codegen->invalid_inst_gen;
15691 }16804 }
1569216805
15693 if (instr_is_comptime(op1) && instr_is_comptime(casted_op2)) {16806 if (instr_is_comptime(op1) && instr_is_comptime(casted_op2)) {
15694 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);16807 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
15695 if (op1_val == nullptr)16808 if (op1_val == nullptr)
15696 return ira->codegen->invalid_instruction;16809 return ira->codegen->invalid_inst_gen;
1569716810
15698 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);16811 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
15699 if (op2_val == nullptr)16812 if (op2_val == nullptr)
15700 return ira->codegen->invalid_instruction;16813 return ira->codegen->invalid_inst_gen;
1570116814
15702 return ir_analyze_math_op(ira, &bin_op_instruction->base, op1->value->type, op1_val, op_id, op2_val);16815 return ir_analyze_math_op(ira, &bin_op_instruction->base.base, op1->value->type, op1_val, op_id, op2_val);
15703 } else if (op1->value->type->id == ZigTypeIdComptimeInt) {16816 } else if (op1->value->type->id == ZigTypeIdComptimeInt) {
15704 ir_add_error(ira, &bin_op_instruction->base,16817 ir_add_error(ira, &bin_op_instruction->base.base,
15705 buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known"));16818 buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known"));
15706 return ira->codegen->invalid_instruction;16819 return ira->codegen->invalid_inst_gen;
15707 } else if (instr_is_comptime(casted_op2) && bigint_cmp_zero(&casted_op2->value->data.x_bigint) == CmpEQ) {16820 } else if (instr_is_comptime(casted_op2) && bigint_cmp_zero(&casted_op2->value->data.x_bigint) == CmpEQ) {
15708 IrInstruction *result = ir_build_cast(&ira->new_irb, bin_op_instruction->base.scope,16821 return ir_build_cast(ira, &bin_op_instruction->base.base, op1->value->type, op1, CastOpNoop);
15709 bin_op_instruction->base.source_node, op1->value->type, op1, CastOpNoop);
15710 result->value->type = op1->value->type;
15711 return result;
15712 }16822 }
1571316823
15714 IrInstruction *result = ir_build_bin_op(&ira->new_irb, bin_op_instruction->base.scope,16824 return ir_build_bin_op_gen(ira, &bin_op_instruction->base.base, op1->value->type,
15715 bin_op_instruction->base.source_node, op_id,16825 op_id, op1, casted_op2, bin_op_instruction->safety_check_on);
15716 op1, casted_op2, bin_op_instruction->safety_check_on);
15717 result->value->type = op1->value->type;
15718 return result;
15719}16826}
1572016827
15721static bool ok_float_op(IrBinOp op) {16828static bool ok_float_op(IrBinOp op) {
...@@ -15779,24 +16886,24 @@ static bool is_pointer_arithmetic_allowed(ZigType *lhs_type, IrBinOp op) {...@@ -15779,24 +16886,24 @@ static bool is_pointer_arithmetic_allowed(ZigType *lhs_type, IrBinOp op) {
15779 zig_unreachable();16886 zig_unreachable();
15780}16887}
1578116888
15782static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *instruction) {16889static IrInstGen *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstSrcBinOp *instruction) {
15783 Error err;16890 Error err;
1578416891
15785 IrInstruction *op1 = instruction->op1->child;16892 IrInstGen *op1 = instruction->op1->child;
15786 if (type_is_invalid(op1->value->type))16893 if (type_is_invalid(op1->value->type))
15787 return ira->codegen->invalid_instruction;16894 return ira->codegen->invalid_inst_gen;
1578816895
15789 IrInstruction *op2 = instruction->op2->child;16896 IrInstGen *op2 = instruction->op2->child;
15790 if (type_is_invalid(op2->value->type))16897 if (type_is_invalid(op2->value->type))
15791 return ira->codegen->invalid_instruction;16898 return ira->codegen->invalid_inst_gen;
1579216899
15793 IrBinOp op_id = instruction->op_id;16900 IrBinOp op_id = instruction->op_id;
1579416901
15795 // look for pointer math16902 // look for pointer math
15796 if (is_pointer_arithmetic_allowed(op1->value->type, op_id)) {16903 if (is_pointer_arithmetic_allowed(op1->value->type, op_id)) {
15797 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize);16904 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize);
15798 if (type_is_invalid(casted_op2->value->type))16905 if (type_is_invalid(casted_op2->value->type))
15799 return ira->codegen->invalid_instruction;16906 return ira->codegen->invalid_inst_gen;
1580016907
15801 // If either operand is undef, result is undef.16908 // If either operand is undef, result is undef.
15802 ZigValue *op1_val = nullptr;16909 ZigValue *op1_val = nullptr;
...@@ -15804,28 +16911,28 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15804,28 +16911,28 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15804 if (instr_is_comptime(op1)) {16911 if (instr_is_comptime(op1)) {
15805 op1_val = ir_resolve_const(ira, op1, UndefOk);16912 op1_val = ir_resolve_const(ira, op1, UndefOk);
15806 if (op1_val == nullptr)16913 if (op1_val == nullptr)
15807 return ira->codegen->invalid_instruction;16914 return ira->codegen->invalid_inst_gen;
15808 if (op1_val->special == ConstValSpecialUndef)16915 if (op1_val->special == ConstValSpecialUndef)
15809 return ir_const_undef(ira, &instruction->base, op1->value->type);16916 return ir_const_undef(ira, &instruction->base.base, op1->value->type);
15810 }16917 }
15811 if (instr_is_comptime(casted_op2)) {16918 if (instr_is_comptime(casted_op2)) {
15812 op2_val = ir_resolve_const(ira, casted_op2, UndefOk);16919 op2_val = ir_resolve_const(ira, casted_op2, UndefOk);
15813 if (op2_val == nullptr)16920 if (op2_val == nullptr)
15814 return ira->codegen->invalid_instruction;16921 return ira->codegen->invalid_inst_gen;
15815 if (op2_val->special == ConstValSpecialUndef)16922 if (op2_val->special == ConstValSpecialUndef)
15816 return ir_const_undef(ira, &instruction->base, op1->value->type);16923 return ir_const_undef(ira, &instruction->base.base, op1->value->type);
15817 }16924 }
1581816925
15819 ZigType *elem_type = op1->value->type->data.pointer.child_type;16926 ZigType *elem_type = op1->value->type->data.pointer.child_type;
15820 if ((err = type_resolve(ira->codegen, elem_type, ResolveStatusSizeKnown)))16927 if ((err = type_resolve(ira->codegen, elem_type, ResolveStatusSizeKnown)))
15821 return ira->codegen->invalid_instruction;16928 return ira->codegen->invalid_inst_gen;
1582216929
15823 // NOTE: this variable is meaningful iff op2_val is not null!16930 // NOTE: this variable is meaningful iff op2_val is not null!
15824 uint64_t byte_offset;16931 uint64_t byte_offset;
15825 if (op2_val != nullptr) {16932 if (op2_val != nullptr) {
15826 uint64_t elem_offset;16933 uint64_t elem_offset;
15827 if (!ir_resolve_usize(ira, casted_op2, &elem_offset))16934 if (!ir_resolve_usize(ira, casted_op2, &elem_offset))
15828 return ira->codegen->invalid_instruction;16935 return ira->codegen->invalid_inst_gen;
1582916936
15830 byte_offset = type_size(ira->codegen, elem_type) * elem_offset;16937 byte_offset = type_size(ira->codegen, elem_type) * elem_offset;
15831 }16938 }
...@@ -15840,7 +16947,7 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15840,7 +16947,7 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15840 {16947 {
15841 uint32_t align_bytes;16948 uint32_t align_bytes;
15842 if ((err = resolve_ptr_align(ira, op1->value->type, &align_bytes)))16949 if ((err = resolve_ptr_align(ira, op1->value->type, &align_bytes)))
15843 return ira->codegen->invalid_instruction;16950 return ira->codegen->invalid_inst_gen;
1584416951
15845 // If the addend is not a comptime-known value we can still count on16952 // If the addend is not a comptime-known value we can still count on
15846 // it being a multiple of the type size16953 // it being a multiple of the type size
...@@ -15869,23 +16976,20 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15869,23 +16976,20 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15869 } else {16976 } else {
15870 zig_unreachable();16977 zig_unreachable();
15871 }16978 }
15872 IrInstruction *result = ir_const(ira, &instruction->base, result_type);16979 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
15873 result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;16980 result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
15874 result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;16981 result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
15875 result->value->data.x_ptr.data.hard_coded_addr.addr = new_addr;16982 result->value->data.x_ptr.data.hard_coded_addr.addr = new_addr;
15876 return result;16983 return result;
15877 }16984 }
1587816985
15879 IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope,16986 return ir_build_bin_op_gen(ira, &instruction->base.base, result_type, op_id, op1, casted_op2, true);
15880 instruction->base.source_node, op_id, op1, casted_op2, true);
15881 result->value->type = result_type;
15882 return result;
15883 }16987 }
1588416988
15885 IrInstruction *instructions[] = {op1, op2};16989 IrInstGen *instructions[] = {op1, op2};
15886 ZigType *resolved_type = ir_resolve_peer_types(ira, instruction->base.source_node, nullptr, instructions, 2);16990 ZigType *resolved_type = ir_resolve_peer_types(ira, instruction->base.base.source_node, nullptr, instructions, 2);
15887 if (type_is_invalid(resolved_type))16991 if (type_is_invalid(resolved_type))
15888 return ira->codegen->invalid_instruction;16992 return ira->codegen->invalid_inst_gen;
1588916993
15890 bool is_int = resolved_type->id == ZigTypeIdInt || resolved_type->id == ZigTypeIdComptimeInt;16994 bool is_int = resolved_type->id == ZigTypeIdInt || resolved_type->id == ZigTypeIdComptimeInt;
15891 bool is_float = resolved_type->id == ZigTypeIdFloat || resolved_type->id == ZigTypeIdComptimeFloat;16995 bool is_float = resolved_type->id == ZigTypeIdFloat || resolved_type->id == ZigTypeIdComptimeFloat;
...@@ -15905,11 +17009,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15905,11 +17009,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15905 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {17009 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
15906 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);17010 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
15907 if (op1_val == nullptr)17011 if (op1_val == nullptr)
15908 return ira->codegen->invalid_instruction;17012 return ira->codegen->invalid_inst_gen;
1590917013
15910 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);17014 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
15911 if (op2_val == nullptr)17015 if (op2_val == nullptr)
15912 return ira->codegen->invalid_instruction;17016 return ira->codegen->invalid_inst_gen;
1591317017
15914 if (bigint_cmp_zero(&op2_val->data.x_bigint) == CmpEQ) {17018 if (bigint_cmp_zero(&op2_val->data.x_bigint) == CmpEQ) {
15915 // the division by zero error will be caught later, but we don't have a17019 // the division by zero error will be caught later, but we don't have a
...@@ -15928,11 +17032,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15928,11 +17032,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15928 }17032 }
15929 }17033 }
15930 if (!ok) {17034 if (!ok) {
15931 ir_add_error(ira, &instruction->base,17035 ir_add_error(ira, &instruction->base.base,
15932 buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact",17036 buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact",
15933 buf_ptr(&op1->value->type->name),17037 buf_ptr(&op1->value->type->name),
15934 buf_ptr(&op2->value->type->name)));17038 buf_ptr(&op2->value->type->name)));
15935 return ira->codegen->invalid_instruction;17039 return ira->codegen->invalid_inst_gen;
15936 }17040 }
15937 } else {17041 } else {
15938 op_id = IrBinOpDivTrunc;17042 op_id = IrBinOpDivTrunc;
...@@ -15943,12 +17047,12 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15943,12 +17047,12 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15943 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {17047 if (instr_is_comptime(op1) && instr_is_comptime(op2)) {
15944 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);17048 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
15945 if (op1_val == nullptr)17049 if (op1_val == nullptr)
15946 return ira->codegen->invalid_instruction;17050 return ira->codegen->invalid_inst_gen;
1594717051
15948 if (is_int) {17052 if (is_int) {
15949 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);17053 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
15950 if (op2_val == nullptr)17054 if (op2_val == nullptr)
15951 return ira->codegen->invalid_instruction;17055 return ira->codegen->invalid_inst_gen;
1595217056
15953 if (bigint_cmp_zero(&op2->value->data.x_bigint) == CmpEQ) {17057 if (bigint_cmp_zero(&op2->value->data.x_bigint) == CmpEQ) {
15954 // the division by zero error will be caught later, but we don't17058 // the division by zero error will be caught later, but we don't
...@@ -15962,13 +17066,13 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15962,13 +17066,13 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15962 ok = bigint_cmp(&rem_result, &mod_result) == CmpEQ;17066 ok = bigint_cmp(&rem_result, &mod_result) == CmpEQ;
15963 }17067 }
15964 } else {17068 } else {
15965 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);17069 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
15966 if (casted_op2 == ira->codegen->invalid_instruction)17070 if (type_is_invalid(casted_op2->value->type))
15967 return ira->codegen->invalid_instruction;17071 return ira->codegen->invalid_inst_gen;
1596817072
15969 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);17073 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
15970 if (op2_val == nullptr)17074 if (op2_val == nullptr)
15971 return ira->codegen->invalid_instruction;17075 return ira->codegen->invalid_inst_gen;
1597217076
15973 if (float_cmp_zero(casted_op2->value) == CmpEQ) {17077 if (float_cmp_zero(casted_op2->value) == CmpEQ) {
15974 // the division by zero error will be caught later, but we don't17078 // the division by zero error will be caught later, but we don't
...@@ -15984,11 +17088,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -15984,11 +17088,11 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
15984 }17088 }
15985 }17089 }
15986 if (!ok) {17090 if (!ok) {
15987 ir_add_error(ira, &instruction->base,17091 ir_add_error(ira, &instruction->base.base,
15988 buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod",17092 buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod",
15989 buf_ptr(&op1->value->type->name),17093 buf_ptr(&op1->value->type->name),
15990 buf_ptr(&op2->value->type->name)));17094 buf_ptr(&op2->value->type->name)));
15991 return ira->codegen->invalid_instruction;17095 return ira->codegen->invalid_inst_gen;
15992 }17096 }
15993 }17097 }
15994 op_id = IrBinOpRemRem;17098 op_id = IrBinOpRemRem;
...@@ -16008,12 +17112,12 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -16008,12 +17112,12 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
16008 }17112 }
16009 }17113 }
16010 if (!ok) {17114 if (!ok) {
16011 AstNode *source_node = instruction->base.source_node;17115 AstNode *source_node = instruction->base.base.source_node;
16012 ir_add_error_node(ira, source_node,17116 ir_add_error_node(ira, source_node,
16013 buf_sprintf("invalid operands to binary expression: '%s' and '%s'",17117 buf_sprintf("invalid operands to binary expression: '%s' and '%s'",
16014 buf_ptr(&op1->value->type->name),17118 buf_ptr(&op1->value->type->name),
16015 buf_ptr(&op2->value->type->name)));17119 buf_ptr(&op2->value->type->name)));
16016 return ira->codegen->invalid_instruction;17120 return ira->codegen->invalid_inst_gen;
16017 }17121 }
1601817122
16019 if (resolved_type->id == ZigTypeIdComptimeInt) {17123 if (resolved_type->id == ZigTypeIdComptimeInt) {
...@@ -16026,33 +17130,31 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp...@@ -16026,33 +17130,31 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
16026 }17130 }
16027 }17131 }
1602817132
16029 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);17133 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, resolved_type);
16030 if (casted_op1 == ira->codegen->invalid_instruction)17134 if (type_is_invalid(casted_op1->value->type))
16031 return ira->codegen->invalid_instruction;17135 return ira->codegen->invalid_inst_gen;
1603217136
16033 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);17137 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, resolved_type);
16034 if (casted_op2 == ira->codegen->invalid_instruction)17138 if (type_is_invalid(casted_op2->value->type))
16035 return ira->codegen->invalid_instruction;17139 return ira->codegen->invalid_inst_gen;
1603617140
16037 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {17141 if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) {
16038 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);17142 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
16039 if (op1_val == nullptr)17143 if (op1_val == nullptr)
16040 return ira->codegen->invalid_instruction;17144 return ira->codegen->invalid_inst_gen;
16041 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);17145 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
16042 if (op2_val == nullptr)17146 if (op2_val == nullptr)
16043 return ira->codegen->invalid_instruction;17147 return ira->codegen->invalid_inst_gen;
1604417148
16045 return ir_analyze_math_op(ira, &instruction->base, resolved_type, op1_val, op_id, op2_val);17149 return ir_analyze_math_op(ira, &instruction->base.base, resolved_type, op1_val, op_id, op2_val);
16046 }17150 }
1604717151
16048 IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope,17152 return ir_build_bin_op_gen(ira, &instruction->base.base, resolved_type,
16049 instruction->base.source_node, op_id, casted_op1, casted_op2, instruction->safety_check_on);17153 op_id, casted_op1, casted_op2, instruction->safety_check_on);
16050 result->value->type = resolved_type;
16051 return result;
16052}17154}
1605317155
16054static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source_instr,17156static IrInstGen *ir_analyze_tuple_cat(IrAnalyze *ira, IrInst* source_instr,
16055 IrInstruction *op1, IrInstruction *op2)17157 IrInstGen *op1, IrInstGen *op2)
16056{17158{
16057 Error err;17159 Error err;
16058 ZigType *op1_type = op1->value->type;17160 ZigType *op1_type = op1->value->type;
...@@ -16069,10 +17171,10 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source...@@ -16069,10 +17171,10 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source
16069 new_type->data.structure.special = StructSpecialInferredTuple;17171 new_type->data.structure.special = StructSpecialInferredTuple;
16070 new_type->data.structure.resolve_status = ResolveStatusBeingInferred;17172 new_type->data.structure.resolve_status = ResolveStatusBeingInferred;
1607117173
16072 bool is_comptime = ir_should_inline(ira->new_irb.exec, source_instr->scope);17174 bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instr->scope);
1607317175
16074 IrInstruction *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(),17176 IrInstGen *new_struct_ptr = ir_resolve_result(ira, source_instr, no_result_loc(),
16075 new_type, nullptr, false, false, true);17177 new_type, nullptr, false, true);
16076 uint32_t new_field_count = op1_field_count + op2_field_count;17178 uint32_t new_field_count = op1_field_count + op2_field_count;
1607717179
16078 new_type->data.structure.src_field_count = new_field_count;17180 new_type->data.structure.src_field_count = new_field_count;
...@@ -16095,13 +17197,13 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source...@@ -16095,13 +17197,13 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source
16095 new_field->is_comptime = src_field->is_comptime;17197 new_field->is_comptime = src_field->is_comptime;
16096 }17198 }
16097 if ((err = type_resolve(ira->codegen, new_type, ResolveStatusZeroBitsKnown)))17199 if ((err = type_resolve(ira->codegen, new_type, ResolveStatusZeroBitsKnown)))
16098 return ira->codegen->invalid_instruction;17200 return ira->codegen->invalid_inst_gen;
1609917201
16100 ZigList<IrInstruction *> const_ptrs = {};17202 ZigList<IrInstGen *> const_ptrs = {};
16101 IrInstruction *first_non_const_instruction = nullptr;17203 IrInstGen *first_non_const_instruction = nullptr;
16102 for (uint32_t i = 0; i < new_field_count; i += 1) {17204 for (uint32_t i = 0; i < new_field_count; i += 1) {
16103 TypeStructField *dst_field = new_type->data.structure.fields[i];17205 TypeStructField *dst_field = new_type->data.structure.fields[i];
16104 IrInstruction *src_struct_op;17206 IrInstGen *src_struct_op;
16105 TypeStructField *src_field;17207 TypeStructField *src_field;
16106 if (i < op1_field_count) {17208 if (i < op1_field_count) {
16107 src_field = op1_type->data.structure.fields[i];17209 src_field = op1_type->data.structure.fields[i];
...@@ -16110,73 +17212,73 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source...@@ -16110,73 +17212,73 @@ static IrInstruction *ir_analyze_tuple_cat(IrAnalyze *ira, IrInstruction *source
16110 src_field = op2_type->data.structure.fields[i - op1_field_count];17212 src_field = op2_type->data.structure.fields[i - op1_field_count];
16111 src_struct_op = op2;17213 src_struct_op = op2;
16112 }17214 }
16113 IrInstruction *field_value = ir_analyze_struct_value_field_value(ira, source_instr,17215 IrInstGen *field_value = ir_analyze_struct_value_field_value(ira, source_instr,
16114 src_struct_op, src_field);17216 src_struct_op, src_field);
16115 if (type_is_invalid(field_value->value->type))17217 if (type_is_invalid(field_value->value->type))
16116 return ira->codegen->invalid_instruction;17218 return ira->codegen->invalid_inst_gen;
16117 IrInstruction *dest_ptr = ir_analyze_struct_field_ptr(ira, source_instr, dst_field,17219 IrInstGen *dest_ptr = ir_analyze_struct_field_ptr(ira, source_instr, dst_field,
16118 new_struct_ptr, new_type, true);17220 new_struct_ptr, new_type, true);
16119 if (type_is_invalid(dest_ptr->value->type))17221 if (type_is_invalid(dest_ptr->value->type))
16120 return ira->codegen->invalid_instruction;17222 return ira->codegen->invalid_inst_gen;
16121 if (instr_is_comptime(field_value)) {17223 if (instr_is_comptime(field_value)) {
16122 const_ptrs.append(dest_ptr);17224 const_ptrs.append(dest_ptr);
16123 } else {17225 } else {
16124 first_non_const_instruction = field_value;17226 first_non_const_instruction = field_value;
16125 }17227 }
16126 IrInstruction *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, dest_ptr, field_value,17228 IrInstGen *store_ptr_inst = ir_analyze_store_ptr(ira, source_instr, dest_ptr, field_value,
16127 true);17229 true);
16128 if (type_is_invalid(store_ptr_inst->value->type))17230 if (type_is_invalid(store_ptr_inst->value->type))
16129 return ira->codegen->invalid_instruction;17231 return ira->codegen->invalid_inst_gen;
16130 }17232 }
16131 if (const_ptrs.length != new_field_count) {17233 if (const_ptrs.length != new_field_count) {
16132 new_struct_ptr->value->special = ConstValSpecialRuntime;17234 new_struct_ptr->value->special = ConstValSpecialRuntime;
16133 for (size_t i = 0; i < const_ptrs.length; i += 1) {17235 for (size_t i = 0; i < const_ptrs.length; i += 1) {
16134 IrInstruction *elem_result_loc = const_ptrs.at(i);17236 IrInstGen *elem_result_loc = const_ptrs.at(i);
16135 assert(elem_result_loc->value->special == ConstValSpecialStatic);17237 assert(elem_result_loc->value->special == ConstValSpecialStatic);
16136 if (elem_result_loc->value->type->data.pointer.inferred_struct_field != nullptr) {17238 if (elem_result_loc->value->type->data.pointer.inferred_struct_field != nullptr) {
16137 // This field will be generated comptime; no need to do this.17239 // This field will be generated comptime; no need to do this.
16138 continue;17240 continue;
16139 }17241 }
16140 IrInstruction *deref = ir_get_deref(ira, elem_result_loc, elem_result_loc, nullptr);17242 IrInstGen *deref = ir_get_deref(ira, &elem_result_loc->base, elem_result_loc, nullptr);
16141 elem_result_loc->value->special = ConstValSpecialRuntime;17243 elem_result_loc->value->special = ConstValSpecialRuntime;
16142 ir_analyze_store_ptr(ira, elem_result_loc, elem_result_loc, deref, false);17244 ir_analyze_store_ptr(ira, &elem_result_loc->base, elem_result_loc, deref, false);
16143 }17245 }
16144 }17246 }
16145 IrInstruction *result = ir_get_deref(ira, source_instr, new_struct_ptr, nullptr);17247 IrInstGen *result = ir_get_deref(ira, source_instr, new_struct_ptr, nullptr);
16146 if (instr_is_comptime(result))17248 if (instr_is_comptime(result))
16147 return result;17249 return result;
1614817250
16149 if (is_comptime) {17251 if (is_comptime) {
16150 ir_add_error_node(ira, first_non_const_instruction->source_node,17252 ir_add_error(ira, &first_non_const_instruction->base,
16151 buf_sprintf("unable to evaluate constant expression"));17253 buf_sprintf("unable to evaluate constant expression"));
16152 return ira->codegen->invalid_instruction;17254 return ira->codegen->invalid_inst_gen;
16153 }17255 }
1615417256
16155 return result;17257 return result;
16156}17258}
1615717259
16158static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) {17260static IrInstGen *ir_analyze_array_cat(IrAnalyze *ira, IrInstSrcBinOp *instruction) {
16159 IrInstruction *op1 = instruction->op1->child;17261 IrInstGen *op1 = instruction->op1->child;
16160 ZigType *op1_type = op1->value->type;17262 ZigType *op1_type = op1->value->type;
16161 if (type_is_invalid(op1_type))17263 if (type_is_invalid(op1_type))
16162 return ira->codegen->invalid_instruction;17264 return ira->codegen->invalid_inst_gen;
1616317265
16164 IrInstruction *op2 = instruction->op2->child;17266 IrInstGen *op2 = instruction->op2->child;
16165 ZigType *op2_type = op2->value->type;17267 ZigType *op2_type = op2->value->type;
16166 if (type_is_invalid(op2_type))17268 if (type_is_invalid(op2_type))
16167 return ira->codegen->invalid_instruction;17269 return ira->codegen->invalid_inst_gen;
1616817270
16169 if (is_tuple(op1_type) && is_tuple(op2_type)) {17271 if (is_tuple(op1_type) && is_tuple(op2_type)) {
16170 return ir_analyze_tuple_cat(ira, &instruction->base, op1, op2);17272 return ir_analyze_tuple_cat(ira, &instruction->base.base, op1, op2);
16171 }17273 }
1617217274
16173 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);17275 ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
16174 if (!op1_val)17276 if (!op1_val)
16175 return ira->codegen->invalid_instruction;17277 return ira->codegen->invalid_inst_gen;
1617617278
16177 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);17279 ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
16178 if (!op2_val)17280 if (!op2_val)
16179 return ira->codegen->invalid_instruction;17281 return ira->codegen->invalid_inst_gen;
1618017282
16181 ZigValue *sentinel1 = nullptr;17283 ZigValue *sentinel1 = nullptr;
16182 ZigValue *op1_array_val;17284 ZigValue *op1_array_val;
...@@ -16214,15 +17316,15 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -16214,15 +17316,15 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
16214 {17316 {
16215 ZigType *array_type = op1_type->data.pointer.child_type;17317 ZigType *array_type = op1_type->data.pointer.child_type;
16216 child_type = array_type->data.array.child_type;17318 child_type = array_type->data.array.child_type;
16217 op1_array_val = const_ptr_pointee(ira, ira->codegen, op1_val, op1->source_node);17319 op1_array_val = const_ptr_pointee(ira, ira->codegen, op1_val, op1->base.source_node);
16218 if (op1_array_val == nullptr)17320 if (op1_array_val == nullptr)
16219 return ira->codegen->invalid_instruction;17321 return ira->codegen->invalid_inst_gen;
16220 op1_array_index = 0;17322 op1_array_index = 0;
16221 op1_array_end = array_type->data.array.len;17323 op1_array_end = array_type->data.array.len;
16222 sentinel1 = array_type->data.array.sentinel;17324 sentinel1 = array_type->data.array.sentinel;
16223 } else {17325 } else {
16224 ir_add_error(ira, op1, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name)));17326 ir_add_error(ira, &op1->base, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name)));
16225 return ira->codegen->invalid_instruction;17327 return ira->codegen->invalid_inst_gen;
16226 }17328 }
1622717329
16228 ZigValue *sentinel2 = nullptr;17330 ZigValue *sentinel2 = nullptr;
...@@ -16262,23 +17364,23 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -16262,23 +17364,23 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
16262 {17364 {
16263 ZigType *array_type = op2_type->data.pointer.child_type;17365 ZigType *array_type = op2_type->data.pointer.child_type;
16264 op2_type_valid = array_type->data.array.child_type == child_type;17366 op2_type_valid = array_type->data.array.child_type == child_type;
16265 op2_array_val = const_ptr_pointee(ira, ira->codegen, op2_val, op2->source_node);17367 op2_array_val = const_ptr_pointee(ira, ira->codegen, op2_val, op2->base.source_node);
16266 if (op2_array_val == nullptr)17368 if (op2_array_val == nullptr)
16267 return ira->codegen->invalid_instruction;17369 return ira->codegen->invalid_inst_gen;
16268 op2_array_index = 0;17370 op2_array_index = 0;
16269 op2_array_end = array_type->data.array.len;17371 op2_array_end = array_type->data.array.len;
1627017372
16271 sentinel2 = array_type->data.array.sentinel;17373 sentinel2 = array_type->data.array.sentinel;
16272 } else {17374 } else {
16273 ir_add_error(ira, op2,17375 ir_add_error(ira, &op2->base,
16274 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value->type->name)));17376 buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value->type->name)));
16275 return ira->codegen->invalid_instruction;17377 return ira->codegen->invalid_inst_gen;
16276 }17378 }
16277 if (!op2_type_valid) {17379 if (!op2_type_valid) {
16278 ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'",17380 ir_add_error(ira, &op2->base, buf_sprintf("expected array of type '%s', found '%s'",
16279 buf_ptr(&child_type->name),17381 buf_ptr(&child_type->name),
16280 buf_ptr(&op2->value->type->name)));17382 buf_ptr(&op2->value->type->name)));
16281 return ira->codegen->invalid_instruction;17383 return ira->codegen->invalid_inst_gen;
16282 }17384 }
1628317385
16284 ZigValue *sentinel;17386 ZigValue *sentinel;
...@@ -16295,7 +17397,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -16295,7 +17397,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
16295 }17397 }
1629617398
16297 // The type of result is populated in the following if blocks17399 // The type of result is populated in the following if blocks
16298 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);17400 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
16299 ZigValue *out_val = result->value;17401 ZigValue *out_val = result->value;
1630017402
16301 ZigValue *out_array_val;17403 ZigValue *out_array_val;
...@@ -16383,14 +17485,14 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i...@@ -16383,14 +17485,14 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i
16383 return result;17485 return result;
16384}17486}
1638517487
16386static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) {17488static IrInstGen *ir_analyze_array_mult(IrAnalyze *ira, IrInstSrcBinOp *instruction) {
16387 IrInstruction *op1 = instruction->op1->child;17489 IrInstGen *op1 = instruction->op1->child;
16388 if (type_is_invalid(op1->value->type))17490 if (type_is_invalid(op1->value->type))
16389 return ira->codegen->invalid_instruction;17491 return ira->codegen->invalid_inst_gen;
1639017492
16391 IrInstruction *op2 = instruction->op2->child;17493 IrInstGen *op2 = instruction->op2->child;
16392 if (type_is_invalid(op2->value->type))17494 if (type_is_invalid(op2->value->type))
16393 return ira->codegen->invalid_instruction;17495 return ira->codegen->invalid_inst_gen;
1639417496
16395 bool want_ptr_to_array = false;17497 bool want_ptr_to_array = false;
16396 ZigType *array_type;17498 ZigType *array_type;
...@@ -16399,49 +17501,49 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *...@@ -16399,49 +17501,49 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
16399 array_type = op1->value->type;17501 array_type = op1->value->type;
16400 array_val = ir_resolve_const(ira, op1, UndefOk);17502 array_val = ir_resolve_const(ira, op1, UndefOk);
16401 if (array_val == nullptr)17503 if (array_val == nullptr)
16402 return ira->codegen->invalid_instruction;17504 return ira->codegen->invalid_inst_gen;
16403 } else if (op1->value->type->id == ZigTypeIdPointer && op1->value->type->data.pointer.ptr_len == PtrLenSingle &&17505 } else if (op1->value->type->id == ZigTypeIdPointer && op1->value->type->data.pointer.ptr_len == PtrLenSingle &&
16404 op1->value->type->data.pointer.child_type->id == ZigTypeIdArray)17506 op1->value->type->data.pointer.child_type->id == ZigTypeIdArray)
16405 {17507 {
16406 array_type = op1->value->type->data.pointer.child_type;17508 array_type = op1->value->type->data.pointer.child_type;
16407 IrInstruction *array_inst = ir_get_deref(ira, op1, op1, nullptr);17509 IrInstGen *array_inst = ir_get_deref(ira, &op1->base, op1, nullptr);
16408 if (type_is_invalid(array_inst->value->type))17510 if (type_is_invalid(array_inst->value->type))
16409 return ira->codegen->invalid_instruction;17511 return ira->codegen->invalid_inst_gen;
16410 array_val = ir_resolve_const(ira, array_inst, UndefOk);17512 array_val = ir_resolve_const(ira, array_inst, UndefOk);
16411 if (array_val == nullptr)17513 if (array_val == nullptr)
16412 return ira->codegen->invalid_instruction;17514 return ira->codegen->invalid_inst_gen;
16413 want_ptr_to_array = true;17515 want_ptr_to_array = true;
16414 } else {17516 } else {
16415 ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name)));17517 ir_add_error(ira, &op1->base, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name)));
16416 return ira->codegen->invalid_instruction;17518 return ira->codegen->invalid_inst_gen;
16417 }17519 }
1641817520
16419 uint64_t mult_amt;17521 uint64_t mult_amt;
16420 if (!ir_resolve_usize(ira, op2, &mult_amt))17522 if (!ir_resolve_usize(ira, op2, &mult_amt))
16421 return ira->codegen->invalid_instruction;17523 return ira->codegen->invalid_inst_gen;
1642217524
16423 uint64_t old_array_len = array_type->data.array.len;17525 uint64_t old_array_len = array_type->data.array.len;
16424 uint64_t new_array_len;17526 uint64_t new_array_len;
1642517527
16426 if (mul_u64_overflow(old_array_len, mult_amt, &new_array_len)) {17528 if (mul_u64_overflow(old_array_len, mult_amt, &new_array_len)) {
16427 ir_add_error(ira, &instruction->base, buf_sprintf("operation results in overflow"));17529 ir_add_error(ira, &instruction->base.base, buf_sprintf("operation results in overflow"));
16428 return ira->codegen->invalid_instruction;17530 return ira->codegen->invalid_inst_gen;
16429 }17531 }
1643017532
16431 ZigType *child_type = array_type->data.array.child_type;17533 ZigType *child_type = array_type->data.array.child_type;
16432 ZigType *result_array_type = get_array_type(ira->codegen, child_type, new_array_len,17534 ZigType *result_array_type = get_array_type(ira->codegen, child_type, new_array_len,
16433 array_type->data.array.sentinel);17535 array_type->data.array.sentinel);
1643417536
16435 IrInstruction *array_result;17537 IrInstGen *array_result;
16436 if (array_val->special == ConstValSpecialUndef || array_val->data.x_array.special == ConstArraySpecialUndef) {17538 if (array_val->special == ConstValSpecialUndef || array_val->data.x_array.special == ConstArraySpecialUndef) {
16437 array_result = ir_const_undef(ira, &instruction->base, result_array_type);17539 array_result = ir_const_undef(ira, &instruction->base.base, result_array_type);
16438 } else {17540 } else {
16439 array_result = ir_const(ira, &instruction->base, result_array_type);17541 array_result = ir_const(ira, &instruction->base.base, result_array_type);
16440 ZigValue *out_val = array_result->value;17542 ZigValue *out_val = array_result->value;
1644117543
16442 switch (type_has_one_possible_value(ira->codegen, result_array_type)) {17544 switch (type_has_one_possible_value(ira->codegen, result_array_type)) {
16443 case OnePossibleValueInvalid:17545 case OnePossibleValueInvalid:
16444 return ira->codegen->invalid_instruction;17546 return ira->codegen->invalid_inst_gen;
16445 case OnePossibleValueYes:17547 case OnePossibleValueYes:
16446 goto skip_computation;17548 goto skip_computation;
16447 case OnePossibleValueNo:17549 case OnePossibleValueNo:
...@@ -16477,35 +17579,35 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *...@@ -16477,35 +17579,35 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *
16477 }17579 }
16478skip_computation:17580skip_computation:
16479 if (want_ptr_to_array) {17581 if (want_ptr_to_array) {
16480 return ir_get_ref(ira, &instruction->base, array_result, true, false);17582 return ir_get_ref(ira, &instruction->base.base, array_result, true, false);
16481 } else {17583 } else {
16482 return array_result;17584 return array_result;
16483 }17585 }
16484}17586}
1648517587
16486static IrInstruction *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,17588static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
16487 IrInstructionMergeErrSets *instruction)17589 IrInstSrcMergeErrSets *instruction)
16488{17590{
16489 ZigType *op1_type = ir_resolve_error_set_type(ira, &instruction->base, instruction->op1->child);17591 ZigType *op1_type = ir_resolve_error_set_type(ira, &instruction->base.base, instruction->op1->child);
16490 if (type_is_invalid(op1_type))17592 if (type_is_invalid(op1_type))
16491 return ira->codegen->invalid_instruction;17593 return ira->codegen->invalid_inst_gen;
1649217594
16493 ZigType *op2_type = ir_resolve_error_set_type(ira, &instruction->base, instruction->op2->child);17595 ZigType *op2_type = ir_resolve_error_set_type(ira, &instruction->base.base, instruction->op2->child);
16494 if (type_is_invalid(op2_type))17596 if (type_is_invalid(op2_type))
16495 return ira->codegen->invalid_instruction;17597 return ira->codegen->invalid_inst_gen;
1649617598
16497 if (type_is_global_error_set(op1_type) ||17599 if (type_is_global_error_set(op1_type) ||
16498 type_is_global_error_set(op2_type))17600 type_is_global_error_set(op2_type))
16499 {17601 {
16500 return ir_const_type(ira, &instruction->base, ira->codegen->builtin_types.entry_global_error_set);17602 return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_global_error_set);
16501 }17603 }
1650217604
16503 if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->source_node)) {17605 if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->base.source_node)) {
16504 return ira->codegen->invalid_instruction;17606 return ira->codegen->invalid_inst_gen;
16505 }17607 }
1650617608
16507 if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->source_node)) {17609 if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->base.source_node)) {
16508 return ira->codegen->invalid_instruction;17610 return ira->codegen->invalid_inst_gen;
16509 }17611 }
1651017612
16511 size_t errors_count = ira->codegen->errors_by_index.length;17613 size_t errors_count = ira->codegen->errors_by_index.length;
...@@ -16518,11 +17620,11 @@ static IrInstruction *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,...@@ -16518,11 +17620,11 @@ static IrInstruction *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
16518 ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type, instruction->type_name);17620 ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type, instruction->type_name);
16519 deallocate(errors, errors_count, "ErrorTableEntry *");17621 deallocate(errors, errors_count, "ErrorTableEntry *");
1652017622
16521 return ir_const_type(ira, &instruction->base, result_type);17623 return ir_const_type(ira, &instruction->base.base, result_type);
16522}17624}
1652317625
1652417626
16525static IrInstruction *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {17627static IrInstGen *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstSrcBinOp *bin_op_instruction) {
16526 IrBinOp op_id = bin_op_instruction->op_id;17628 IrBinOp op_id = bin_op_instruction->op_id;
16527 switch (op_id) {17629 switch (op_id) {
16528 case IrBinOpInvalid:17630 case IrBinOpInvalid:
...@@ -16567,41 +17669,39 @@ static IrInstruction *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructio...@@ -16567,41 +17669,39 @@ static IrInstruction *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructio
16567 zig_unreachable();17669 zig_unreachable();
16568}17670}
1656917671
16570static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,17672static IrInstGen *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstSrcDeclVar *decl_var_instruction) {
16571 IrInstructionDeclVarSrc *decl_var_instruction)
16572{
16573 Error err;17673 Error err;
16574 ZigVar *var = decl_var_instruction->var;17674 ZigVar *var = decl_var_instruction->var;
1657517675
16576 ZigType *explicit_type = nullptr;17676 ZigType *explicit_type = nullptr;
16577 IrInstruction *var_type = nullptr;17677 IrInstGen *var_type = nullptr;
16578 if (decl_var_instruction->var_type != nullptr) {17678 if (decl_var_instruction->var_type != nullptr) {
16579 var_type = decl_var_instruction->var_type->child;17679 var_type = decl_var_instruction->var_type->child;
16580 ZigType *proposed_type = ir_resolve_type(ira, var_type);17680 ZigType *proposed_type = ir_resolve_type(ira, var_type);
16581 explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type);17681 explicit_type = validate_var_type(ira->codegen, var_type->base.source_node, proposed_type);
16582 if (type_is_invalid(explicit_type)) {17682 if (type_is_invalid(explicit_type)) {
16583 var->var_type = ira->codegen->builtin_types.entry_invalid;17683 var->var_type = ira->codegen->builtin_types.entry_invalid;
16584 return ira->codegen->invalid_instruction;17684 return ira->codegen->invalid_inst_gen;
16585 }17685 }
16586 }17686 }
1658717687
16588 AstNode *source_node = decl_var_instruction->base.source_node;17688 AstNode *source_node = decl_var_instruction->base.base.source_node;
1658917689
16590 bool is_comptime_var = ir_get_var_is_comptime(var);17690 bool is_comptime_var = ir_get_var_is_comptime(var);
1659117691
16592 bool var_class_requires_const = false;17692 bool var_class_requires_const = false;
1659317693
16594 IrInstruction *var_ptr = decl_var_instruction->ptr->child;17694 IrInstGen *var_ptr = decl_var_instruction->ptr->child;
16595 // if this is null, a compiler error happened and did not initialize the variable.17695 // if this is null, a compiler error happened and did not initialize the variable.
16596 // if there are no compile errors there may be a missing ir_expr_wrap in pass1 IR generation.17696 // if there are no compile errors there may be a missing ir_expr_wrap in pass1 IR generation.
16597 if (var_ptr == nullptr || type_is_invalid(var_ptr->value->type)) {17697 if (var_ptr == nullptr || type_is_invalid(var_ptr->value->type)) {
16598 ir_assert(var_ptr != nullptr || ira->codegen->errors.length != 0, &decl_var_instruction->base);17698 ir_assert(var_ptr != nullptr || ira->codegen->errors.length != 0, &decl_var_instruction->base.base);
16599 var->var_type = ira->codegen->builtin_types.entry_invalid;17699 var->var_type = ira->codegen->builtin_types.entry_invalid;
16600 return ira->codegen->invalid_instruction;17700 return ira->codegen->invalid_inst_gen;
16601 }17701 }
1660217702
16603 // The ir_build_var_decl_src call is supposed to pass a pointer to the allocation, not an initialization value.17703 // The ir_build_var_decl_src call is supposed to pass a pointer to the allocation, not an initialization value.
16604 ir_assert(var_ptr->value->type->id == ZigTypeIdPointer, &decl_var_instruction->base);17704 ir_assert(var_ptr->value->type->id == ZigTypeIdPointer, &decl_var_instruction->base.base);
1660517705
16606 ZigType *result_type = var_ptr->value->type->data.pointer.child_type;17706 ZigType *result_type = var_ptr->value->type->data.pointer.child_type;
16607 if (type_is_invalid(result_type)) {17707 if (type_is_invalid(result_type)) {
...@@ -16612,7 +17712,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -16612,7 +17712,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1661217712
16613 ZigValue *init_val = nullptr;17713 ZigValue *init_val = nullptr;
16614 if (instr_is_comptime(var_ptr) && var_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {17714 if (instr_is_comptime(var_ptr) && var_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
16615 init_val = const_ptr_pointee(ira, ira->codegen, var_ptr->value, decl_var_instruction->base.source_node);17715 init_val = const_ptr_pointee(ira, ira->codegen, var_ptr->value, decl_var_instruction->base.base.source_node);
16616 if (is_comptime_var) {17716 if (is_comptime_var) {
16617 if (var->gen_is_const) {17717 if (var->gen_is_const) {
16618 var->const_value = init_val;17718 var->const_value = init_val;
...@@ -16639,7 +17739,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -16639,7 +17739,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
16639 case ReqCompTimeNo:17739 case ReqCompTimeNo:
16640 if (init_val != nullptr && value_is_comptime(init_val)) {17740 if (init_val != nullptr && value_is_comptime(init_val)) {
16641 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,17741 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
16642 decl_var_instruction->base.source_node, init_val, UndefOk)))17742 decl_var_instruction->base.base.source_node, init_val, UndefOk)))
16643 {17743 {
16644 result_type = ira->codegen->builtin_types.entry_invalid;17744 result_type = ira->codegen->builtin_types.entry_invalid;
16645 } else if (init_val->type->id == ZigTypeIdFn &&17745 } else if (init_val->type->id == ZigTypeIdFn &&
...@@ -16660,42 +17760,27 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -16660,42 +17760,27 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
16660 break;17760 break;
16661 }17761 }
1666217762
16663 if (var->var_type != nullptr && !is_comptime_var) {17763 while (var->next_var != nullptr) {
16664 // This is at least the second time we've seen this variable declaration during analysis.17764 var = var->next_var;
16665 // This means that this is actually a different variable due to, e.g. an inline while loop.
16666 // We make a new variable so that it can hold a different type, and so the debug info can
16667 // be distinct.
16668 ZigVar *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope,
16669 buf_create_from_str(var->name), var->src_is_const, var->gen_is_const,
16670 var->shadowable, var->is_comptime, true);
16671 new_var->owner_exec = var->owner_exec;
16672 new_var->align_bytes = var->align_bytes;
16673 if (var->mem_slot_index != SIZE_MAX) {
16674 ZigValue *vals = create_const_vals(1);
16675 new_var->mem_slot_index = ira->exec_context.mem_slot_list.length;
16676 ira->exec_context.mem_slot_list.append(vals);
16677 }
16678
16679 var->next_var = new_var;
16680 var = new_var;
16681 }17765 }
1668217766
16683 // This must be done after possibly creating a new variable above17767 // This must be done after possibly creating a new variable above
16684 var->ref_count = 0;17768 var->ref_count = 0;
1668517769
17770 var->ptr_instruction = var_ptr;
16686 var->var_type = result_type;17771 var->var_type = result_type;
16687 assert(var->var_type);17772 assert(var->var_type);
1668817773
16689 if (type_is_invalid(result_type)) {17774 if (type_is_invalid(result_type)) {
16690 return ir_const_void(ira, &decl_var_instruction->base);17775 return ir_const_void(ira, &decl_var_instruction->base.base);
16691 }17776 }
1669217777
16693 if (decl_var_instruction->align_value == nullptr) {17778 if (decl_var_instruction->align_value == nullptr) {
16694 if ((err = type_resolve(ira->codegen, result_type, ResolveStatusAlignmentKnown))) {17779 if ((err = type_resolve(ira->codegen, result_type, ResolveStatusAlignmentKnown))) {
16695 var->var_type = ira->codegen->builtin_types.entry_invalid;17780 var->var_type = ira->codegen->builtin_types.entry_invalid;
16696 return ir_const_void(ira, &decl_var_instruction->base);17781 return ir_const_void(ira, &decl_var_instruction->base.base);
16697 }17782 }
16698 var->align_bytes = get_abi_alignment(ira->codegen, result_type);17783 var->align_bytes = get_ptr_align(ira->codegen, var_ptr->value->type);
16699 } else {17784 } else {
16700 if (!ir_resolve_align(ira, decl_var_instruction->align_value->child, nullptr, &var->align_bytes)) {17785 if (!ir_resolve_align(ira, decl_var_instruction->align_value->child, nullptr, &var->align_bytes)) {
16701 var->var_type = ira->codegen->builtin_types.entry_invalid;17786 var->var_type = ira->codegen->builtin_types.entry_invalid;
...@@ -16712,104 +17797,96 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,...@@ -16712,104 +17797,96 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
16712 // we need a runtime ptr but we have a comptime val.17797 // we need a runtime ptr but we have a comptime val.
16713 // since it's a comptime val there are no instructions for it.17798 // since it's a comptime val there are no instructions for it.
16714 // we memcpy the init value here17799 // we memcpy the init value here
16715 IrInstruction *deref = ir_get_deref(ira, var_ptr, var_ptr, nullptr);17800 IrInstGen *deref = ir_get_deref(ira, &var_ptr->base, var_ptr, nullptr);
16716 if (type_is_invalid(deref->value->type)) {17801 if (type_is_invalid(deref->value->type)) {
16717 var->var_type = ira->codegen->builtin_types.entry_invalid;17802 var->var_type = ira->codegen->builtin_types.entry_invalid;
16718 return ira->codegen->invalid_instruction;17803 return ira->codegen->invalid_inst_gen;
16719 }17804 }
16720 // If this assertion trips, something is wrong with the IR instructions, because17805 // If this assertion trips, something is wrong with the IR instructions, because
16721 // we expected the above deref to return a constant value, but it created a runtime17806 // we expected the above deref to return a constant value, but it created a runtime
16722 // instruction.17807 // instruction.
16723 assert(deref->value->special != ConstValSpecialRuntime);17808 assert(deref->value->special != ConstValSpecialRuntime);
16724 var_ptr->value->special = ConstValSpecialRuntime;17809 var_ptr->value->special = ConstValSpecialRuntime;
16725 ir_analyze_store_ptr(ira, var_ptr, var_ptr, deref, false);17810 ir_analyze_store_ptr(ira, &var_ptr->base, var_ptr, deref, false);
16726 }17811 }
1672717812 if (instr_is_comptime(var_ptr) && (is_comptime_var || (var_class_requires_const && var->gen_is_const))) {
16728 if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) {17813 return ir_const_void(ira, &decl_var_instruction->base.base);
16729 assert(var->mem_slot_index < ira->exec_context.mem_slot_list.length);
16730 ZigValue *mem_slot = ira->exec_context.mem_slot_list.at(var->mem_slot_index);
16731 copy_const_val(mem_slot, init_val);
16732 ira_ref(var->owner_exec->analysis);
16733
16734 if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) {
16735 return ir_const_void(ira, &decl_var_instruction->base);
16736 }
16737 }17814 }
16738 } else if (is_comptime_var) {17815 } else if (is_comptime_var) {
16739 ir_add_error(ira, &decl_var_instruction->base,17816 ir_add_error(ira, &decl_var_instruction->base.base,
16740 buf_sprintf("cannot store runtime value in compile time variable"));17817 buf_sprintf("cannot store runtime value in compile time variable"));
16741 var->var_type = ira->codegen->builtin_types.entry_invalid;17818 var->var_type = ira->codegen->builtin_types.entry_invalid;
16742 return ira->codegen->invalid_instruction;17819 return ira->codegen->invalid_inst_gen;
16743 }17820 }
1674417821
16745 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);17822 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
16746 if (fn_entry)17823 if (fn_entry)
16747 fn_entry->variable_list.append(var);17824 fn_entry->variable_list.append(var);
1674817825
16749 return ir_build_var_decl_gen(ira, &decl_var_instruction->base, var, var_ptr);17826 return ir_build_var_decl_gen(ira, &decl_var_instruction->base.base, var, var_ptr);
16750}17827}
1675117828
16752static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) {17829static IrInstGen *ir_analyze_instruction_export(IrAnalyze *ira, IrInstSrcExport *instruction) {
16753 IrInstruction *target = instruction->target->child;17830 IrInstGen *target = instruction->target->child;
16754 if (type_is_invalid(target->value->type))17831 if (type_is_invalid(target->value->type))
16755 return ira->codegen->invalid_instruction;17832 return ira->codegen->invalid_inst_gen;
1675617833
16757 IrInstruction *options = instruction->options->child;17834 IrInstGen *options = instruction->options->child;
16758 if (type_is_invalid(options->value->type))17835 if (type_is_invalid(options->value->type))
16759 return ira->codegen->invalid_instruction;17836 return ira->codegen->invalid_inst_gen;
1676017837
16761 ZigType *options_type = options->value->type;17838 ZigType *options_type = options->value->type;
16762 assert(options_type->id == ZigTypeIdStruct);17839 assert(options_type->id == ZigTypeIdStruct);
1676317840
16764 TypeStructField *name_field = find_struct_type_field(options_type, buf_create_from_str("name"));17841 TypeStructField *name_field = find_struct_type_field(options_type, buf_create_from_str("name"));
16765 ir_assert(name_field != nullptr, &instruction->base);17842 ir_assert(name_field != nullptr, &instruction->base.base);
16766 IrInstruction *name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base, options, name_field);17843 IrInstGen *name_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, name_field);
16767 if (type_is_invalid(name_inst->value->type))17844 if (type_is_invalid(name_inst->value->type))
16768 return ira->codegen->invalid_instruction;17845 return ira->codegen->invalid_inst_gen;
1676917846
16770 TypeStructField *linkage_field = find_struct_type_field(options_type, buf_create_from_str("linkage"));17847 TypeStructField *linkage_field = find_struct_type_field(options_type, buf_create_from_str("linkage"));
16771 ir_assert(linkage_field != nullptr, &instruction->base);17848 ir_assert(linkage_field != nullptr, &instruction->base.base);
16772 IrInstruction *linkage_inst = ir_analyze_struct_value_field_value(ira, &instruction->base, options, linkage_field);17849 IrInstGen *linkage_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, linkage_field);
16773 if (type_is_invalid(linkage_inst->value->type))17850 if (type_is_invalid(linkage_inst->value->type))
16774 return ira->codegen->invalid_instruction;17851 return ira->codegen->invalid_inst_gen;
1677517852
16776 TypeStructField *section_field = find_struct_type_field(options_type, buf_create_from_str("section"));17853 TypeStructField *section_field = find_struct_type_field(options_type, buf_create_from_str("section"));
16777 ir_assert(section_field != nullptr, &instruction->base);17854 ir_assert(section_field != nullptr, &instruction->base.base);
16778 IrInstruction *section_inst = ir_analyze_struct_value_field_value(ira, &instruction->base, options, section_field);17855 IrInstGen *section_inst = ir_analyze_struct_value_field_value(ira, &instruction->base.base, options, section_field);
16779 if (type_is_invalid(section_inst->value->type))17856 if (type_is_invalid(section_inst->value->type))
16780 return ira->codegen->invalid_instruction;17857 return ira->codegen->invalid_inst_gen;
1678117858
16782 // The `section` field is optional, we have to unwrap it first17859 // The `section` field is optional, we have to unwrap it first
16783 IrInstruction *non_null_check = ir_analyze_test_non_null(ira, &instruction->base, section_inst);17860 IrInstGen *non_null_check = ir_analyze_test_non_null(ira, &instruction->base.base, section_inst);
16784 bool is_non_null;17861 bool is_non_null;
16785 if (!ir_resolve_bool(ira, non_null_check, &is_non_null))17862 if (!ir_resolve_bool(ira, non_null_check, &is_non_null))
16786 return ira->codegen->invalid_instruction;17863 return ira->codegen->invalid_inst_gen;
1678717864
16788 IrInstruction *section_str_inst = nullptr;17865 IrInstGen *section_str_inst = nullptr;
16789 if (is_non_null) {17866 if (is_non_null) {
16790 section_str_inst = ir_analyze_optional_value_payload_value(ira, &instruction->base, section_inst, false);17867 section_str_inst = ir_analyze_optional_value_payload_value(ira, &instruction->base.base, section_inst, false);
16791 if (type_is_invalid(section_str_inst->value->type))17868 if (type_is_invalid(section_str_inst->value->type))
16792 return ira->codegen->invalid_instruction;17869 return ira->codegen->invalid_inst_gen;
16793 }17870 }
1679417871
16795 // Resolve all the comptime values17872 // Resolve all the comptime values
16796 Buf *symbol_name = ir_resolve_str(ira, name_inst);17873 Buf *symbol_name = ir_resolve_str(ira, name_inst);
16797 if (!symbol_name)17874 if (!symbol_name)
16798 return ira->codegen->invalid_instruction;17875 return ira->codegen->invalid_inst_gen;
1679917876
16800 if (buf_len(symbol_name) < 1) {17877 if (buf_len(symbol_name) < 1) {
16801 ir_add_error(ira, name_inst,17878 ir_add_error(ira, &name_inst->base,
16802 buf_sprintf("exported symbol name cannot be empty"));17879 buf_sprintf("exported symbol name cannot be empty"));
16803 return ira->codegen->invalid_instruction;17880 return ira->codegen->invalid_inst_gen;
16804 }17881 }
1680517882
16806 GlobalLinkageId global_linkage_id;17883 GlobalLinkageId global_linkage_id;
16807 if (!ir_resolve_global_linkage(ira, linkage_inst, &global_linkage_id))17884 if (!ir_resolve_global_linkage(ira, linkage_inst, &global_linkage_id))
16808 return ira->codegen->invalid_instruction;17885 return ira->codegen->invalid_inst_gen;
1680917886
16810 Buf *section_name = nullptr;17887 Buf *section_name = nullptr;
16811 if (section_str_inst != nullptr && !(section_name = ir_resolve_str(ira, section_str_inst)))17888 if (section_str_inst != nullptr && !(section_name = ir_resolve_str(ira, section_str_inst)))
16812 return ira->codegen->invalid_instruction;17889 return ira->codegen->invalid_inst_gen;
1681317890
16814 // TODO: This function needs to be audited.17891 // TODO: This function needs to be audited.
16815 // It's not clear how all the different types are supposed to be handled.17892 // It's not clear how all the different types are supposed to be handled.
...@@ -16817,15 +17894,15 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -16817,15 +17894,15 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
16817 // in another file.17894 // in another file.
16818 TldFn *tld_fn = allocate<TldFn>(1);17895 TldFn *tld_fn = allocate<TldFn>(1);
16819 tld_fn->base.id = TldIdFn;17896 tld_fn->base.id = TldIdFn;
16820 tld_fn->base.source_node = instruction->base.source_node;17897 tld_fn->base.source_node = instruction->base.base.source_node;
1682117898
16822 auto entry = ira->codegen->exported_symbol_names.put_unique(symbol_name, &tld_fn->base);17899 auto entry = ira->codegen->exported_symbol_names.put_unique(symbol_name, &tld_fn->base);
16823 if (entry) {17900 if (entry) {
16824 AstNode *other_export_node = entry->value->source_node;17901 AstNode *other_export_node = entry->value->source_node;
16825 ErrorMsg *msg = ir_add_error(ira, &instruction->base,17902 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
16826 buf_sprintf("exported symbol collision: '%s'", buf_ptr(symbol_name)));17903 buf_sprintf("exported symbol collision: '%s'", buf_ptr(symbol_name)));
16827 add_error_note(ira->codegen, msg, other_export_node, buf_sprintf("other symbol is here"));17904 add_error_note(ira->codegen, msg, other_export_node, buf_sprintf("other symbol is here"));
16828 return ira->codegen->invalid_instruction;17905 return ira->codegen->invalid_inst_gen;
16829 }17906 }
1683017907
16831 Error err;17908 Error err;
...@@ -16841,12 +17918,12 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -16841,12 +17918,12 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
16841 CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc;17918 CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc;
16842 switch (cc) {17919 switch (cc) {
16843 case CallingConventionUnspecified: {17920 case CallingConventionUnspecified: {
16844 ErrorMsg *msg = ir_add_error(ira, target,17921 ErrorMsg *msg = ir_add_error(ira, &target->base,
16845 buf_sprintf("exported function must specify calling convention"));17922 buf_sprintf("exported function must specify calling convention"));
16846 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));17923 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));
16847 } break;17924 } break;
16848 case CallingConventionAsync: {17925 case CallingConventionAsync: {
16849 ErrorMsg *msg = ir_add_error(ira, target,17926 ErrorMsg *msg = ir_add_error(ira, &target->base,
16850 buf_sprintf("exported function cannot be async"));17927 buf_sprintf("exported function cannot be async"));
16851 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));17928 add_error_note(ira->codegen, msg, fn_entry->proto_node, buf_sprintf("declared here"));
16852 } break;17929 } break;
...@@ -16869,10 +17946,10 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -16869,10 +17946,10 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
16869 } break;17946 } break;
16870 case ZigTypeIdStruct:17947 case ZigTypeIdStruct:
16871 if (is_slice(target->value->type)) {17948 if (is_slice(target->value->type)) {
16872 ir_add_error(ira, target,17949 ir_add_error(ira, &target->base,
16873 buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value->type->name)));17950 buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value->type->name)));
16874 } else if (target->value->type->data.structure.layout != ContainerLayoutExtern) {17951 } else if (target->value->type->data.structure.layout != ContainerLayoutExtern) {
16875 ErrorMsg *msg = ir_add_error(ira, target,17952 ErrorMsg *msg = ir_add_error(ira, &target->base,
16876 buf_sprintf("exported struct value must be declared extern"));17953 buf_sprintf("exported struct value must be declared extern"));
16877 add_error_note(ira->codegen, msg, target->value->type->data.structure.decl_node, buf_sprintf("declared here"));17954 add_error_note(ira->codegen, msg, target->value->type->data.structure.decl_node, buf_sprintf("declared here"));
16878 } else {17955 } else {
...@@ -16881,7 +17958,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -16881,7 +17958,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
16881 break;17958 break;
16882 case ZigTypeIdUnion:17959 case ZigTypeIdUnion:
16883 if (target->value->type->data.unionation.layout != ContainerLayoutExtern) {17960 if (target->value->type->data.unionation.layout != ContainerLayoutExtern) {
16884 ErrorMsg *msg = ir_add_error(ira, target,17961 ErrorMsg *msg = ir_add_error(ira, &target->base,
16885 buf_sprintf("exported union value must be declared extern"));17962 buf_sprintf("exported union value must be declared extern"));
16886 add_error_note(ira->codegen, msg, target->value->type->data.unionation.decl_node, buf_sprintf("declared here"));17963 add_error_note(ira->codegen, msg, target->value->type->data.unionation.decl_node, buf_sprintf("declared here"));
16887 } else {17964 } else {
...@@ -16890,7 +17967,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -16890,7 +17967,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
16890 break;17967 break;
16891 case ZigTypeIdEnum:17968 case ZigTypeIdEnum:
16892 if (target->value->type->data.enumeration.layout != ContainerLayoutExtern) {17969 if (target->value->type->data.enumeration.layout != ContainerLayoutExtern) {
16893 ErrorMsg *msg = ir_add_error(ira, target,17970 ErrorMsg *msg = ir_add_error(ira, &target->base,
16894 buf_sprintf("exported enum value must be declared extern"));17971 buf_sprintf("exported enum value must be declared extern"));
16895 add_error_note(ira->codegen, msg, target->value->type->data.enumeration.decl_node, buf_sprintf("declared here"));17972 add_error_note(ira->codegen, msg, target->value->type->data.enumeration.decl_node, buf_sprintf("declared here"));
16896 } else {17973 } else {
...@@ -16900,10 +17977,10 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -16900,10 +17977,10 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
16900 case ZigTypeIdArray: {17977 case ZigTypeIdArray: {
16901 bool ok_type;17978 bool ok_type;
16902 if ((err = type_allowed_in_extern(ira->codegen, target->value->type->data.array.child_type, &ok_type)))17979 if ((err = type_allowed_in_extern(ira->codegen, target->value->type->data.array.child_type, &ok_type)))
16903 return ira->codegen->invalid_instruction;17980 return ira->codegen->invalid_inst_gen;
1690417981
16905 if (!ok_type) {17982 if (!ok_type) {
16906 ir_add_error(ira, target,17983 ir_add_error(ira, &target->base,
16907 buf_sprintf("array element type '%s' not extern-compatible",17984 buf_sprintf("array element type '%s' not extern-compatible",
16908 buf_ptr(&target->value->type->data.array.child_type->name)));17985 buf_ptr(&target->value->type->data.array.child_type->name)));
16909 } else {17986 } else {
...@@ -16918,31 +17995,31 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -16918,31 +17995,31 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
16918 zig_unreachable();17995 zig_unreachable();
16919 case ZigTypeIdStruct:17996 case ZigTypeIdStruct:
16920 if (is_slice(type_value)) {17997 if (is_slice(type_value)) {
16921 ir_add_error(ira, target,17998 ir_add_error(ira, &target->base,
16922 buf_sprintf("unable to export type '%s'", buf_ptr(&type_value->name)));17999 buf_sprintf("unable to export type '%s'", buf_ptr(&type_value->name)));
16923 } else if (type_value->data.structure.layout != ContainerLayoutExtern) {18000 } else if (type_value->data.structure.layout != ContainerLayoutExtern) {
16924 ErrorMsg *msg = ir_add_error(ira, target,18001 ErrorMsg *msg = ir_add_error(ira, &target->base,
16925 buf_sprintf("exported struct must be declared extern"));18002 buf_sprintf("exported struct must be declared extern"));
16926 add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here"));18003 add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here"));
16927 }18004 }
16928 break;18005 break;
16929 case ZigTypeIdUnion:18006 case ZigTypeIdUnion:
16930 if (type_value->data.unionation.layout != ContainerLayoutExtern) {18007 if (type_value->data.unionation.layout != ContainerLayoutExtern) {
16931 ErrorMsg *msg = ir_add_error(ira, target,18008 ErrorMsg *msg = ir_add_error(ira, &target->base,
16932 buf_sprintf("exported union must be declared extern"));18009 buf_sprintf("exported union must be declared extern"));
16933 add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here"));18010 add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here"));
16934 }18011 }
16935 break;18012 break;
16936 case ZigTypeIdEnum:18013 case ZigTypeIdEnum:
16937 if (type_value->data.enumeration.layout != ContainerLayoutExtern) {18014 if (type_value->data.enumeration.layout != ContainerLayoutExtern) {
16938 ErrorMsg *msg = ir_add_error(ira, target,18015 ErrorMsg *msg = ir_add_error(ira, &target->base,
16939 buf_sprintf("exported enum must be declared extern"));18016 buf_sprintf("exported enum must be declared extern"));
16940 add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here"));18017 add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here"));
16941 }18018 }
16942 break;18019 break;
16943 case ZigTypeIdFn: {18020 case ZigTypeIdFn: {
16944 if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) {18021 if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) {
16945 ir_add_error(ira, target,18022 ir_add_error(ira, &target->base,
16946 buf_sprintf("exported function type must specify calling convention"));18023 buf_sprintf("exported function type must specify calling convention"));
16947 }18024 }
16948 } break;18025 } break;
...@@ -16968,7 +18045,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -16968,7 +18045,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
16968 case ZigTypeIdOpaque:18045 case ZigTypeIdOpaque:
16969 case ZigTypeIdFnFrame:18046 case ZigTypeIdFnFrame:
16970 case ZigTypeIdAnyFrame:18047 case ZigTypeIdAnyFrame:
16971 ir_add_error(ira, target,18048 ir_add_error(ira, &target->base,
16972 buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));18049 buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name)));
16973 break;18050 break;
16974 }18051 }
...@@ -16993,61 +18070,55 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio...@@ -16993,61 +18070,55 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
16993 case ZigTypeIdEnumLiteral:18070 case ZigTypeIdEnumLiteral:
16994 case ZigTypeIdFnFrame:18071 case ZigTypeIdFnFrame:
16995 case ZigTypeIdAnyFrame:18072 case ZigTypeIdAnyFrame:
16996 ir_add_error(ira, target,18073 ir_add_error(ira, &target->base,
16997 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value->type->name)));18074 buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value->type->name)));
16998 break;18075 break;
16999 }18076 }
1700018077
17001 // TODO audit the various ways to use @export18078 // TODO audit the various ways to use @export
17002 if (want_var_export && target->id == IrInstructionIdLoadPtrGen) {18079 if (want_var_export && target->id == IrInstGenIdLoadPtr) {
17003 IrInstructionLoadPtrGen *load_ptr = reinterpret_cast<IrInstructionLoadPtrGen *>(target);18080 IrInstGenLoadPtr *load_ptr = reinterpret_cast<IrInstGenLoadPtr *>(target);
17004 if (load_ptr->ptr->id == IrInstructionIdVarPtr) {18081 if (load_ptr->ptr->id == IrInstGenIdVarPtr) {
17005 IrInstructionVarPtr *var_ptr = reinterpret_cast<IrInstructionVarPtr *>(load_ptr->ptr);18082 IrInstGenVarPtr *var_ptr = reinterpret_cast<IrInstGenVarPtr *>(load_ptr->ptr);
17006 ZigVar *var = var_ptr->var;18083 ZigVar *var = var_ptr->var;
17007 add_var_export(ira->codegen, var, buf_ptr(symbol_name), global_linkage_id);18084 add_var_export(ira->codegen, var, buf_ptr(symbol_name), global_linkage_id);
17008 var->section_name = section_name;18085 var->section_name = section_name;
17009 }18086 }
17010 }18087 }
1701118088
17012 return ir_const_void(ira, &instruction->base);18089 return ir_const_void(ira, &instruction->base.base);
17013}18090}
1701418091
17015static bool exec_has_err_ret_trace(CodeGen *g, IrExecutable *exec) {18092static bool exec_has_err_ret_trace(CodeGen *g, IrExecutableSrc *exec) {
17016 ZigFn *fn_entry = exec_fn_entry(exec);18093 ZigFn *fn_entry = exec_fn_entry(exec);
17017 return fn_entry != nullptr && fn_entry->calls_or_awaits_errorable_fn && g->have_err_ret_tracing;18094 return fn_entry != nullptr && fn_entry->calls_or_awaits_errorable_fn && g->have_err_ret_tracing;
17018}18095}
1701918096
17020static IrInstruction *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,18097static IrInstGen *ir_analyze_instruction_error_return_trace(IrAnalyze *ira,
17021 IrInstructionErrorReturnTrace *instruction)18098 IrInstSrcErrorReturnTrace *instruction)
17022{18099{
17023 ZigType *ptr_to_stack_trace_type = get_pointer_to_type(ira->codegen, get_stack_trace_type(ira->codegen), false);18100 ZigType *ptr_to_stack_trace_type = get_pointer_to_type(ira->codegen, get_stack_trace_type(ira->codegen), false);
17024 if (instruction->optional == IrInstructionErrorReturnTrace::Null) {18101 if (instruction->optional == IrInstErrorReturnTraceNull) {
17025 ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type);18102 ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type);
17026 if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) {18103 if (!exec_has_err_ret_trace(ira->codegen, ira->old_irb.exec)) {
17027 IrInstruction *result = ir_const(ira, &instruction->base, optional_type);18104 IrInstGen *result = ir_const(ira, &instruction->base.base, optional_type);
17028 ZigValue *out_val = result->value;18105 ZigValue *out_val = result->value;
17029 assert(get_codegen_ptr_type(optional_type) != nullptr);18106 assert(get_codegen_ptr_type(optional_type) != nullptr);
17030 out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;18107 out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
17031 out_val->data.x_ptr.data.hard_coded_addr.addr = 0;18108 out_val->data.x_ptr.data.hard_coded_addr.addr = 0;
17032 return result;18109 return result;
17033 }18110 }
17034 IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope,18111 return ir_build_error_return_trace_gen(ira, instruction->base.base.scope,
17035 instruction->base.source_node, instruction->optional);18112 instruction->base.base.source_node, instruction->optional, optional_type);
17036 new_instruction->value->type = optional_type;
17037 return new_instruction;
17038 } else {18113 } else {
17039 assert(ira->codegen->have_err_ret_tracing);18114 assert(ira->codegen->have_err_ret_tracing);
17040 IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope,18115 return ir_build_error_return_trace_gen(ira, instruction->base.base.scope,
17041 instruction->base.source_node, instruction->optional);18116 instruction->base.base.source_node, instruction->optional, ptr_to_stack_trace_type);
17042 new_instruction->value->type = ptr_to_stack_trace_type;
17043 return new_instruction;
17044 }18117 }
17045}18118}
1704618119
17047static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira,18120static IrInstGen *ir_analyze_instruction_error_union(IrAnalyze *ira, IrInstSrcErrorUnion *instruction) {
17048 IrInstructionErrorUnion *instruction)18121 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
17049{
17050 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);
17051 result->value->special = ConstValSpecialLazy;18122 result->value->special = ConstValSpecialLazy;
1705218123
17053 LazyValueErrUnionType *lazy_err_union_type = allocate<LazyValueErrUnionType>(1, "LazyValueErrUnionType");18124 LazyValueErrUnionType *lazy_err_union_type = allocate<LazyValueErrUnionType>(1, "LazyValueErrUnionType");
...@@ -17057,24 +18128,25 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira,...@@ -17057,24 +18128,25 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira,
1705718128
17058 lazy_err_union_type->err_set_type = instruction->err_set->child;18129 lazy_err_union_type->err_set_type = instruction->err_set->child;
17059 if (ir_resolve_type_lazy(ira, lazy_err_union_type->err_set_type) == nullptr)18130 if (ir_resolve_type_lazy(ira, lazy_err_union_type->err_set_type) == nullptr)
17060 return ira->codegen->invalid_instruction;18131 return ira->codegen->invalid_inst_gen;
1706118132
17062 lazy_err_union_type->payload_type = instruction->payload->child;18133 lazy_err_union_type->payload_type = instruction->payload->child;
17063 if (ir_resolve_type_lazy(ira, lazy_err_union_type->payload_type) == nullptr)18134 if (ir_resolve_type_lazy(ira, lazy_err_union_type->payload_type) == nullptr)
17064 return ira->codegen->invalid_instruction;18135 return ira->codegen->invalid_inst_gen;
1706518136
17066 return result;18137 return result;
17067}18138}
1706818139
17069static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_inst, ZigType *var_type,18140static IrInstGen *ir_analyze_alloca(IrAnalyze *ira, IrInst *source_inst, ZigType *var_type,
17070 uint32_t align, const char *name_hint, bool force_comptime)18141 uint32_t align, const char *name_hint, bool force_comptime)
17071{18142{
17072 Error err;18143 Error err;
1707318144
17074 ZigValue *pointee = create_const_vals(1);18145 ZigValue *pointee = create_const_vals(1);
17075 pointee->special = ConstValSpecialUndef;18146 pointee->special = ConstValSpecialUndef;
18147 pointee->llvm_align = align;
1707618148
17077 IrInstructionAllocaGen *result = ir_build_alloca_gen(ira, source_inst, align, name_hint);18149 IrInstGenAlloca *result = ir_build_alloca_gen(ira, source_inst, align, name_hint);
17078 result->base.value->special = ConstValSpecialStatic;18150 result->base.value->special = ConstValSpecialStatic;
17079 result->base.value->data.x_ptr.special = ConstPtrSpecialRef;18151 result->base.value->data.x_ptr.special = ConstPtrSpecialRef;
17080 result->base.value->data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer;18152 result->base.value->data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer;
...@@ -17082,15 +18154,15 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in...@@ -17082,15 +18154,15 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in
1708218154
17083 bool var_type_has_bits;18155 bool var_type_has_bits;
17084 if ((err = type_has_bits2(ira->codegen, var_type, &var_type_has_bits)))18156 if ((err = type_has_bits2(ira->codegen, var_type, &var_type_has_bits)))
17085 return ira->codegen->invalid_instruction;18157 return ira->codegen->invalid_inst_gen;
17086 if (align != 0) {18158 if (align != 0) {
17087 if ((err = type_resolve(ira->codegen, var_type, ResolveStatusAlignmentKnown)))18159 if ((err = type_resolve(ira->codegen, var_type, ResolveStatusAlignmentKnown)))
17088 return ira->codegen->invalid_instruction;18160 return ira->codegen->invalid_inst_gen;
17089 if (!var_type_has_bits) {18161 if (!var_type_has_bits) {
17090 ir_add_error(ira, source_inst,18162 ir_add_error(ira, source_inst,
17091 buf_sprintf("variable '%s' of zero-bit type '%s' has no in-memory representation, it cannot be aligned",18163 buf_sprintf("variable '%s' of zero-bit type '%s' has no in-memory representation, it cannot be aligned",
17092 name_hint, buf_ptr(&var_type->name)));18164 name_hint, buf_ptr(&var_type->name)));
17093 return ira->codegen->invalid_instruction;18165 return ira->codegen->invalid_inst_gen;
17094 }18166 }
17095 }18167 }
17096 assert(result->base.value->data.x_ptr.special != ConstPtrSpecialInvalid);18168 assert(result->base.value->data.x_ptr.special != ConstPtrSpecialInvalid);
...@@ -17099,15 +18171,16 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in...@@ -17099,15 +18171,16 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in
17099 result->base.value->type = get_pointer_to_type_extra(ira->codegen, var_type, false, false,18171 result->base.value->type = get_pointer_to_type_extra(ira->codegen, var_type, false, false,
17100 PtrLenSingle, align, 0, 0, false);18172 PtrLenSingle, align, 0, 0, false);
1710118173
17102 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);18174 if (!force_comptime) {
17103 if (fn_entry != nullptr) {18175 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
17104 fn_entry->alloca_gen_list.append(result);18176 if (fn_entry != nullptr) {
18177 fn_entry->alloca_gen_list.append(result);
18178 }
17105 }18179 }
17106 result->base.is_gen = true;
17107 return &result->base;18180 return &result->base;
17108}18181}
1710918182
17110static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInstruction *suspend_source_instr,18183static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInst *suspend_source_instr,
17111 ResultLoc *result_loc)18184 ResultLoc *result_loc)
17112{18185{
17113 switch (result_loc->id) {18186 switch (result_loc->id) {
...@@ -17150,7 +18223,7 @@ static bool type_can_bit_cast(ZigType *t) {...@@ -17150,7 +18223,7 @@ static bool type_can_bit_cast(ZigType *t) {
17150 }18223 }
17151}18224}
1715218225
17153static void set_up_result_loc_for_inferred_comptime(IrInstruction *ptr) {18226static void set_up_result_loc_for_inferred_comptime(IrInstGen *ptr) {
17154 ZigValue *undef_child = create_const_vals(1);18227 ZigValue *undef_child = create_const_vals(1);
17155 undef_child->type = ptr->value->type->data.pointer.child_type;18228 undef_child->type = ptr->value->type->data.pointer.child_type;
17156 undef_child->special = ConstValSpecialUndef;18229 undef_child->special = ConstValSpecialUndef;
...@@ -17189,16 +18262,16 @@ static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out...@@ -17189,16 +18262,16 @@ static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out
17189 zig_unreachable();18262 zig_unreachable();
17190}18263}
1719118264
17192static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *suspend_source_instr,18265static IrInstGen *ir_resolve_no_result_loc(IrAnalyze *ira, IrInst *suspend_source_instr,
17193 ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime)18266 ResultLoc *result_loc, ZigType *value_type)
17194{18267{
17195 if (type_is_invalid(value_type))18268 if (type_is_invalid(value_type))
17196 return ira->codegen->invalid_instruction;18269 return ira->codegen->invalid_inst_gen;
17197 IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");18270 IrInstGenAlloca *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, "");
17198 alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,18271 alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false,
17199 PtrLenSingle, 0, 0, 0, false);18272 PtrLenSingle, 0, 0, 0, false);
17200 set_up_result_loc_for_inferred_comptime(&alloca_gen->base);18273 set_up_result_loc_for_inferred_comptime(&alloca_gen->base);
17201 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);18274 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
17202 if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) {18275 if (fn_entry != nullptr && get_scope_typeof(suspend_source_instr->scope) == nullptr) {
17203 fn_entry->alloca_gen_list.append(alloca_gen);18276 fn_entry->alloca_gen_list.append(alloca_gen);
17204 }18277 }
...@@ -17207,10 +18280,25 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su...@@ -17207,10 +18280,25 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su
17207 return result_loc->resolved_loc;18280 return result_loc->resolved_loc;
17208}18281}
1720918282
18283static bool result_loc_is_discard(ResultLoc *result_loc_pass1) {
18284 if (result_loc_pass1->id == ResultLocIdInstruction &&
18285 result_loc_pass1->source_instruction->id == IrInstSrcIdConst)
18286 {
18287 IrInstSrcConst *const_inst = reinterpret_cast<IrInstSrcConst *>(result_loc_pass1->source_instruction);
18288 if (value_is_comptime(const_inst->value) &&
18289 const_inst->value->type->id == ZigTypeIdPointer &&
18290 const_inst->value->data.x_ptr.special == ConstPtrSpecialDiscard)
18291 {
18292 return true;
18293 }
18294 }
18295 return false;
18296}
18297
17210// when calling this function, at the callsite must check for result type noreturn and propagate it up18298// when calling this function, at the callsite must check for result type noreturn and propagate it up
17211static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,18299static IrInstGen *ir_resolve_result_raw(IrAnalyze *ira, IrInst *suspend_source_instr,
17212 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime,18300 ResultLoc *result_loc, ZigType *value_type, IrInstGen *value, bool force_runtime,
17213 bool non_null_comptime, bool allow_discard)18301 bool allow_discard)
17214{18302{
17215 Error err;18303 Error err;
17216 if (result_loc->resolved_loc != nullptr) {18304 if (result_loc->resolved_loc != nullptr) {
...@@ -17230,54 +18318,56 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17230,54 +18318,56 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
17230 return nullptr;18318 return nullptr;
17231 }18319 }
17232 // need to return a result location and don't have one. use a stack allocation18320 // need to return a result location and don't have one. use a stack allocation
17233 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,18321 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type);
17234 force_runtime, non_null_comptime);
17235 }18322 }
17236 case ResultLocIdVar: {18323 case ResultLocIdVar: {
17237 ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc);18324 ResultLocVar *result_loc_var = reinterpret_cast<ResultLocVar *>(result_loc);
17238 assert(result_loc->source_instruction->id == IrInstructionIdAllocaSrc);18325 assert(result_loc->source_instruction->id == IrInstSrcIdAlloca);
1723918326 IrInstSrcAlloca *alloca_src = reinterpret_cast<IrInstSrcAlloca *>(result_loc->source_instruction);
18327
18328 ZigVar *var = result_loc_var->var;
18329 if (var->var_type != nullptr && !ir_get_var_is_comptime(var)) {
18330 // This is at least the second time we've seen this variable declaration during analysis.
18331 // This means that this is actually a different variable due to, e.g. an inline while loop.
18332 // We make a new variable so that it can hold a different type, and so the debug info can
18333 // be distinct.
18334 ZigVar *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope,
18335 buf_create_from_str(var->name), var->src_is_const, var->gen_is_const,
18336 var->shadowable, var->is_comptime, true);
18337 new_var->owner_exec = var->owner_exec;
18338 new_var->align_bytes = var->align_bytes;
18339
18340 var->next_var = new_var;
18341 var = new_var;
18342 }
17240 if (value_type->id == ZigTypeIdUnreachable || value_type->id == ZigTypeIdOpaque) {18343 if (value_type->id == ZigTypeIdUnreachable || value_type->id == ZigTypeIdOpaque) {
17241 ir_add_error(ira, result_loc->source_instruction,18344 ir_add_error(ira, &result_loc->source_instruction->base,
17242 buf_sprintf("variable of type '%s' not allowed", buf_ptr(&value_type->name)));18345 buf_sprintf("variable of type '%s' not allowed", buf_ptr(&value_type->name)));
17243 return ira->codegen->invalid_instruction;18346 return ira->codegen->invalid_inst_gen;
17244 }18347 }
1724518348 if (alloca_src->base.child == nullptr || var->ptr_instruction == nullptr) {
17246 IrInstructionAllocaSrc *alloca_src =18349 bool force_comptime;
17247 reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction);18350 if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime))
17248 bool force_comptime;18351 return ira->codegen->invalid_inst_gen;
17249 if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime))
17250 return ira->codegen->invalid_instruction;
17251 bool is_comptime = force_comptime || (!force_runtime && value != nullptr &&
17252 value->value->special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const);
17253
17254 if (alloca_src->base.child == nullptr || is_comptime) {
17255 uint32_t align = 0;18352 uint32_t align = 0;
17256 if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, nullptr, &align)) {18353 if (alloca_src->align != nullptr && !ir_resolve_align(ira, alloca_src->align->child, nullptr, &align)) {
17257 return ira->codegen->invalid_instruction;18354 return ira->codegen->invalid_inst_gen;
17258 }18355 }
17259 IrInstruction *alloca_gen;18356 IrInstGen *alloca_gen = ir_analyze_alloca(ira, &result_loc->source_instruction->base, value_type,
17260 if (is_comptime && value != nullptr) {18357 align, alloca_src->name_hint, force_comptime);
17261 if (align > value->value->llvm_align) {18358 if (force_runtime) {
17262 value->value->llvm_align = align;18359 alloca_gen->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
17263 }18360 alloca_gen->value->special = ConstValSpecialRuntime;
17264 alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false);
17265 } else {
17266 alloca_gen = ir_analyze_alloca(ira, result_loc->source_instruction, value_type, align,
17267 alloca_src->name_hint, force_comptime);
17268 if (force_runtime) {
17269 alloca_gen->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
17270 alloca_gen->value->special = ConstValSpecialRuntime;
17271 }
17272 }18361 }
17273 if (alloca_src->base.child != nullptr && !result_loc->written) {18362 if (alloca_src->base.child != nullptr && !result_loc->written) {
17274 alloca_src->base.child->ref_count = 0;18363 alloca_src->base.child->base.ref_count = 0;
17275 }18364 }
17276 alloca_src->base.child = alloca_gen;18365 alloca_src->base.child = alloca_gen;
18366 var->ptr_instruction = alloca_gen;
17277 }18367 }
17278 result_loc->written = true;18368 result_loc->written = true;
17279 result_loc->resolved_loc = is_comptime ? nullptr : alloca_src->base.child;18369 result_loc->resolved_loc = alloca_src->base.child;
17280 return result_loc->resolved_loc;18370 return alloca_src->base.child;
17281 }18371 }
17282 case ResultLocIdInstruction: {18372 case ResultLocIdInstruction: {
17283 result_loc->written = true;18373 result_loc->written = true;
...@@ -17289,27 +18379,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17289,27 +18379,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
17289 reinterpret_cast<ResultLocReturn *>(result_loc)->implicit_return_type_done = true;18379 reinterpret_cast<ResultLocReturn *>(result_loc)->implicit_return_type_done = true;
17290 ira->src_implicit_return_type_list.append(value);18380 ira->src_implicit_return_type_list.append(value);
17291 }18381 }
17292 if (!non_null_comptime) {
17293 bool is_comptime = value != nullptr && value->value->special != ConstValSpecialRuntime;
17294 if (is_comptime)
17295 return nullptr;
17296 }
17297 bool has_bits;
17298 if ((err = type_has_bits2(ira->codegen, ira->explicit_return_type, &has_bits)))
17299 return ira->codegen->invalid_instruction;
17300 if (!has_bits || !handle_is_ptr(ira->explicit_return_type)) {
17301 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
17302 if (fn_entry == nullptr || fn_entry->inferred_async_node == nullptr) {
17303 return nullptr;
17304 }
17305 }
17306
17307 ZigType *ptr_return_type = get_pointer_to_type(ira->codegen, ira->explicit_return_type, false);
17308 result_loc->written = true;18382 result_loc->written = true;
17309 result_loc->resolved_loc = ir_build_return_ptr(ira, result_loc->source_instruction, ptr_return_type);18383 result_loc->resolved_loc = ira->return_ptr;
17310 if (ir_should_inline(ira->old_irb.exec, result_loc->source_instruction->scope)) {
17311 set_up_result_loc_for_inferred_comptime(result_loc->resolved_loc);
17312 }
17313 return result_loc->resolved_loc;18384 return result_loc->resolved_loc;
17314 }18385 }
17315 case ResultLocIdPeer: {18386 case ResultLocIdPeer: {
...@@ -17317,8 +18388,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17317,8 +18388,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
17317 ResultLocPeerParent *peer_parent = result_peer->parent;18388 ResultLocPeerParent *peer_parent = result_peer->parent;
1731818389
17319 if (peer_parent->peers.length == 1) {18390 if (peer_parent->peers.length == 1) {
17320 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,18391 IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
17321 value_type, value, force_runtime, non_null_comptime, true);18392 value_type, value, force_runtime, true);
17322 result_peer->suspend_pos.basic_block_index = SIZE_MAX;18393 result_peer->suspend_pos.basic_block_index = SIZE_MAX;
17323 result_peer->suspend_pos.instruction_index = SIZE_MAX;18394 result_peer->suspend_pos.instruction_index = SIZE_MAX;
17324 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||18395 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
...@@ -17333,22 +18404,19 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17333,22 +18404,19 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1733318404
17334 bool is_condition_comptime;18405 bool is_condition_comptime;
17335 if (!ir_resolve_comptime(ira, peer_parent->is_comptime->child, &is_condition_comptime))18406 if (!ir_resolve_comptime(ira, peer_parent->is_comptime->child, &is_condition_comptime))
17336 return ira->codegen->invalid_instruction;18407 return ira->codegen->invalid_inst_gen;
17337 if (is_condition_comptime) {18408 if (is_condition_comptime) {
17338 peer_parent->skipped = true;18409 peer_parent->skipped = true;
17339 if (non_null_comptime) {18410 return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
17340 return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,18411 value_type, value, force_runtime, true);
17341 value_type, value, force_runtime, non_null_comptime, true);
17342 }
17343 return nullptr;
17344 }18412 }
17345 bool peer_parent_has_type;18413 bool peer_parent_has_type;
17346 if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type)))18414 if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type)))
17347 return ira->codegen->invalid_instruction;18415 return ira->codegen->invalid_inst_gen;
17348 if (peer_parent_has_type) {18416 if (peer_parent_has_type) {
17349 peer_parent->skipped = true;18417 peer_parent->skipped = true;
17350 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,18418 IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
17351 value_type, value, force_runtime || !is_condition_comptime, true, true);18419 value_type, value, force_runtime || !is_condition_comptime, true);
17352 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||18420 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
17353 parent_result_loc->value->type->id == ZigTypeIdUnreachable)18421 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
17354 {18422 {
...@@ -17364,7 +18432,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17364,7 +18432,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
17364 if (peer_parent->end_bb->suspend_instruction_ref == nullptr) {18432 if (peer_parent->end_bb->suspend_instruction_ref == nullptr) {
17365 peer_parent->end_bb->suspend_instruction_ref = suspend_source_instr;18433 peer_parent->end_bb->suspend_instruction_ref = suspend_source_instr;
17366 }18434 }
17367 IrInstruction *unreach_inst = ira_suspend(ira, suspend_source_instr, result_peer->next_bb,18435 IrInstGen *unreach_inst = ira_suspend(ira, suspend_source_instr, result_peer->next_bb,
17368 &result_peer->suspend_pos);18436 &result_peer->suspend_pos);
17369 if (result_peer->next_bb == nullptr) {18437 if (result_peer->next_bb == nullptr) {
17370 ir_start_next_bb(ira);18438 ir_start_next_bb(ira);
...@@ -17372,8 +18440,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17372,8 +18440,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
17372 return unreach_inst;18440 return unreach_inst;
17373 }18441 }
1737418442
17375 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,18443 IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
17376 peer_parent->resolved_type, nullptr, force_runtime, non_null_comptime, true);18444 peer_parent->resolved_type, nullptr, force_runtime, true);
17377 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||18445 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
17378 parent_result_loc->value->type->id == ZigTypeIdUnreachable)18446 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
17379 {18447 {
...@@ -17386,30 +18454,27 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17386,30 +18454,27 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
17386 return result_loc->resolved_loc;18454 return result_loc->resolved_loc;
17387 }18455 }
17388 case ResultLocIdCast: {18456 case ResultLocIdCast: {
17389 if (value != nullptr && value->value->special != ConstValSpecialRuntime && !non_null_comptime)
17390 return nullptr;
17391 ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc);18457 ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc);
17392 ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child);18458 ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child);
17393 if (type_is_invalid(dest_type))18459 if (type_is_invalid(dest_type))
17394 return ira->codegen->invalid_instruction;18460 return ira->codegen->invalid_inst_gen;
1739518461
17396 if (dest_type == ira->codegen->builtin_types.entry_var) {18462 if (dest_type == ira->codegen->builtin_types.entry_var) {
17397 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,18463 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type);
17398 force_runtime, non_null_comptime);
17399 }18464 }
1740018465
17401 IrInstruction *casted_value;18466 IrInstGen *casted_value;
17402 if (value != nullptr) {18467 if (value != nullptr) {
17403 casted_value = ir_implicit_cast(ira, value, dest_type);18468 casted_value = ir_implicit_cast2(ira, suspend_source_instr, value, dest_type);
17404 if (type_is_invalid(casted_value->value->type))18469 if (type_is_invalid(casted_value->value->type))
17405 return ira->codegen->invalid_instruction;18470 return ira->codegen->invalid_inst_gen;
17406 dest_type = casted_value->value->type;18471 dest_type = casted_value->value->type;
17407 } else {18472 } else {
17408 casted_value = nullptr;18473 casted_value = nullptr;
17409 }18474 }
1741018475
17411 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent,18476 IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent,
17412 dest_type, casted_value, force_runtime, non_null_comptime, true);18477 dest_type, casted_value, force_runtime, true);
17413 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||18478 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
17414 parent_result_loc->value->type->id == ZigTypeIdUnreachable)18479 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
17415 {18480 {
...@@ -17422,11 +18487,11 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17422,11 +18487,11 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
17422 if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type,18487 if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type,
17423 ResolveStatusAlignmentKnown)))18488 ResolveStatusAlignmentKnown)))
17424 {18489 {
17425 return ira->codegen->invalid_instruction;18490 return ira->codegen->invalid_inst_gen;
17426 }18491 }
17427 uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);18492 uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);
17428 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {18493 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {
17429 return ira->codegen->invalid_instruction;18494 return ira->codegen->invalid_inst_gen;
17430 }18495 }
17431 if (!type_has_bits(value_type)) {18496 if (!type_has_bits(value_type)) {
17432 parent_ptr_align = 0;18497 parent_ptr_align = 0;
...@@ -17449,9 +18514,9 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17449,9 +18514,9 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1744918514
17450 ConstCastOnly const_cast_result = types_match_const_cast_only(ira,18515 ConstCastOnly const_cast_result = types_match_const_cast_only(ira,
17451 parent_result_loc->value->type, ptr_type,18516 parent_result_loc->value->type, ptr_type,
17452 result_cast->base.source_instruction->source_node, false);18517 result_cast->base.source_instruction->base.source_node, false);
17453 if (const_cast_result.id == ConstCastResultIdInvalid)18518 if (const_cast_result.id == ConstCastResultIdInvalid)
17454 return ira->codegen->invalid_instruction;18519 return ira->codegen->invalid_inst_gen;
17455 if (const_cast_result.id != ConstCastResultIdOk) {18520 if (const_cast_result.id != ConstCastResultIdOk) {
17456 if (allow_discard) {18521 if (allow_discard) {
17457 return parent_result_loc;18522 return parent_result_loc;
...@@ -17459,59 +18524,59 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17459,59 +18524,59 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
17459 // We will not be able to provide a result location for this value. Create18524 // We will not be able to provide a result location for this value. Create
17460 // a new result location.18525 // a new result location.
17461 result_cast->parent->written = false;18526 result_cast->parent->written = false;
17462 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type,18527 return ir_resolve_no_result_loc(ira, suspend_source_instr, result_loc, value_type);
17463 force_runtime, non_null_comptime);
17464 }18528 }
1746518529
17466 result_loc->written = true;18530 result_loc->written = true;
17467 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,18531 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,
17468 ptr_type, result_cast->base.source_instruction, false);18532 &parent_result_loc->base, ptr_type, &result_cast->base.source_instruction->base, false);
17469 return result_loc->resolved_loc;18533 return result_loc->resolved_loc;
17470 }18534 }
17471 case ResultLocIdBitCast: {18535 case ResultLocIdBitCast: {
17472 ResultLocBitCast *result_bit_cast = reinterpret_cast<ResultLocBitCast *>(result_loc);18536 ResultLocBitCast *result_bit_cast = reinterpret_cast<ResultLocBitCast *>(result_loc);
17473 ZigType *dest_type = ir_resolve_type(ira, result_bit_cast->base.source_instruction->child);18537 ZigType *dest_type = ir_resolve_type(ira, result_bit_cast->base.source_instruction->child);
17474 if (type_is_invalid(dest_type))18538 if (type_is_invalid(dest_type))
17475 return ira->codegen->invalid_instruction;18539 return ira->codegen->invalid_inst_gen;
1747618540
17477 if (get_codegen_ptr_type(dest_type) != nullptr) {18541 if (get_codegen_ptr_type(dest_type) != nullptr) {
17478 ir_add_error(ira, result_loc->source_instruction,18542 ir_add_error(ira, &result_loc->source_instruction->base,
17479 buf_sprintf("unable to @bitCast to pointer type '%s'", buf_ptr(&dest_type->name)));18543 buf_sprintf("unable to @bitCast to pointer type '%s'", buf_ptr(&dest_type->name)));
17480 return ira->codegen->invalid_instruction;18544 return ira->codegen->invalid_inst_gen;
17481 }18545 }
1748218546
17483 if (!type_can_bit_cast(dest_type)) {18547 if (!type_can_bit_cast(dest_type)) {
17484 ir_add_error(ira, result_loc->source_instruction,18548 ir_add_error(ira, &result_loc->source_instruction->base,
17485 buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name)));18549 buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name)));
17486 return ira->codegen->invalid_instruction;18550 return ira->codegen->invalid_inst_gen;
17487 }18551 }
1748818552
17489 if (get_codegen_ptr_type(value_type) != nullptr) {18553 if (get_codegen_ptr_type(value_type) != nullptr) {
17490 ir_add_error(ira, suspend_source_instr,18554 ir_add_error(ira, suspend_source_instr,
17491 buf_sprintf("unable to @bitCast from pointer type '%s'", buf_ptr(&value_type->name)));18555 buf_sprintf("unable to @bitCast from pointer type '%s'", buf_ptr(&value_type->name)));
17492 return ira->codegen->invalid_instruction;18556 return ira->codegen->invalid_inst_gen;
17493 }18557 }
1749418558
17495 if (!type_can_bit_cast(value_type)) {18559 if (!type_can_bit_cast(value_type)) {
17496 ir_add_error(ira, suspend_source_instr,18560 ir_add_error(ira, suspend_source_instr,
17497 buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&value_type->name)));18561 buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&value_type->name)));
17498 return ira->codegen->invalid_instruction;18562 return ira->codegen->invalid_inst_gen;
17499 }18563 }
1750018564
17501 IrInstruction *bitcasted_value;18565 IrInstGen *bitcasted_value;
17502 if (value != nullptr) {18566 if (value != nullptr) {
17503 bitcasted_value = ir_analyze_bit_cast(ira, result_loc->source_instruction, value, dest_type);18567 bitcasted_value = ir_analyze_bit_cast(ira, &result_loc->source_instruction->base, value, dest_type);
17504 dest_type = bitcasted_value->value->type;18568 dest_type = bitcasted_value->value->type;
17505 } else {18569 } else {
17506 bitcasted_value = nullptr;18570 bitcasted_value = nullptr;
17507 }18571 }
1750818572
17509 if (bitcasted_value == nullptr || type_is_invalid(bitcasted_value->value->type)) {18573 if (bitcasted_value != nullptr && type_is_invalid(bitcasted_value->value->type)) {
17510 return bitcasted_value;18574 return bitcasted_value;
17511 }18575 }
1751218576
17513 IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent,18577 bool parent_was_written = result_bit_cast->parent->written;
17514 dest_type, bitcasted_value, force_runtime, non_null_comptime, true);18578 IrInstGen *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent,
18579 dest_type, bitcasted_value, force_runtime, true);
17515 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||18580 if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) ||
17516 parent_result_loc->value->type->id == ZigTypeIdUnreachable)18581 parent_result_loc->value->type->id == ZigTypeIdUnreachable)
17517 {18582 {
...@@ -17521,55 +18586,59 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe...@@ -17521,55 +18586,59 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
17521 assert(parent_ptr_type->id == ZigTypeIdPointer);18586 assert(parent_ptr_type->id == ZigTypeIdPointer);
17522 ZigType *child_type = parent_ptr_type->data.pointer.child_type;18587 ZigType *child_type = parent_ptr_type->data.pointer.child_type;
1752318588
17524 bool has_bits;18589 if (result_loc_is_discard(result_bit_cast->parent)) {
17525 if ((err = type_has_bits2(ira->codegen, child_type, &has_bits))) {
17526 return ira->codegen->invalid_instruction;
17527 }
17528
17529 // This happens when the bitCast result is assigned to _
17530 if (!has_bits) {
17531 assert(allow_discard);18590 assert(allow_discard);
17532 return parent_result_loc;18591 return parent_result_loc;
17533 }18592 }
1753418593
17535 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusAlignmentKnown))) {18594 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown))) {
17536 return ira->codegen->invalid_instruction;18595 return ira->codegen->invalid_inst_gen;
17537 }18596 }
1753818597
17539 uint64_t parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);18598 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusSizeKnown))) {
17540 if ((err = type_resolve(ira->codegen, value_type, ResolveStatusAlignmentKnown))) {18599 return ira->codegen->invalid_inst_gen;
17541 return ira->codegen->invalid_instruction;18600 }
18601
18602 if (child_type != ira->codegen->builtin_types.entry_var) {
18603 if (type_size(ira->codegen, child_type) != type_size(ira->codegen, value_type)) {
18604 // pointer cast won't work; we need a temporary location.
18605 result_bit_cast->parent->written = parent_was_written;
18606 result_loc->written = true;
18607 result_loc->resolved_loc = ir_resolve_result(ira, suspend_source_instr, no_result_loc(),
18608 value_type, bitcasted_value, force_runtime, true);
18609 return result_loc->resolved_loc;
18610 }
17542 }18611 }
18612 uint64_t parent_ptr_align = 0;
18613 if (type_has_bits(value_type)) parent_ptr_align = get_ptr_align(ira->codegen, parent_ptr_type);
17543 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type,18614 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value_type,
17544 parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,18615 parent_ptr_type->data.pointer.is_const, parent_ptr_type->data.pointer.is_volatile, PtrLenSingle,
17545 parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);18616 parent_ptr_align, 0, 0, parent_ptr_type->data.pointer.allow_zero);
1754618617
17547 result_loc->written = true;18618 result_loc->written = true;
17548 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,18619 result_loc->resolved_loc = ir_analyze_ptr_cast(ira, suspend_source_instr, parent_result_loc,
17549 ptr_type, result_bit_cast->base.source_instruction, false);18620 &parent_result_loc->base, ptr_type, &result_bit_cast->base.source_instruction->base, false);
17550 return result_loc->resolved_loc;18621 return result_loc->resolved_loc;
17551 }18622 }
17552 }18623 }
17553 zig_unreachable();18624 zig_unreachable();
17554}18625}
1755518626
17556static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_source_instr,18627static IrInstGen *ir_resolve_result(IrAnalyze *ira, IrInst *suspend_source_instr,
17557 ResultLoc *result_loc_pass1, ZigType *value_type, IrInstruction *value, bool force_runtime,18628 ResultLoc *result_loc_pass1, ZigType *value_type, IrInstGen *value, bool force_runtime,
17558 bool non_null_comptime, bool allow_discard)18629 bool allow_discard)
17559{18630{
17560 Error err;18631 if (!allow_discard && result_loc_is_discard(result_loc_pass1)) {
17561 if (!allow_discard && result_loc_pass1->id == ResultLocIdInstruction &&
17562 instr_is_comptime(result_loc_pass1->source_instruction) &&
17563 result_loc_pass1->source_instruction->value->type->id == ZigTypeIdPointer &&
17564 result_loc_pass1->source_instruction->value->data.x_ptr.special == ConstPtrSpecialDiscard)
17565 {
17566 result_loc_pass1 = no_result_loc();18632 result_loc_pass1 = no_result_loc();
17567 }18633 }
17568 bool was_already_resolved = result_loc_pass1->resolved_loc != nullptr;18634 bool was_written = result_loc_pass1->written;
17569 IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,18635 IrInstGen *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type,
17570 value, force_runtime, non_null_comptime, allow_discard);18636 value, force_runtime, allow_discard);
17571 if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type)))18637 if (result_loc == nullptr || result_loc->value->type->id == ZigTypeIdUnreachable ||
18638 type_is_invalid(result_loc->value->type))
18639 {
17572 return result_loc;18640 return result_loc;
18641 }
1757318642
17574 if ((force_runtime || (value != nullptr && !instr_is_comptime(value))) &&18643 if ((force_runtime || (value != nullptr && !instr_is_comptime(value))) &&
17575 result_loc_pass1->written && result_loc->value->data.x_ptr.mut == ConstPtrMutInfer)18644 result_loc_pass1->written && result_loc->value->data.x_ptr.mut == ConstPtrMutInfer)
...@@ -17578,56 +18647,63 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s...@@ -17578,56 +18647,63 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
17578 }18647 }
1757918648
17580 InferredStructField *isf = result_loc->value->type->data.pointer.inferred_struct_field;18649 InferredStructField *isf = result_loc->value->type->data.pointer.inferred_struct_field;
17581 if (!was_already_resolved && isf != nullptr) {18650 if (isf != nullptr) {
17582 // Now it's time to add the field to the struct type.18651 TypeStructField *field;
17583 uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count;18652 IrInstGen *casted_ptr;
17584 uint32_t new_field_count = old_field_count + 1;18653 if (isf->already_resolved) {
17585 isf->inferred_struct_type->data.structure.src_field_count = new_field_count;18654 field = find_struct_type_field(isf->inferred_struct_type, isf->field_name);
17586 isf->inferred_struct_type->data.structure.fields = realloc_type_struct_fields(
17587 isf->inferred_struct_type->data.structure.fields, old_field_count, new_field_count);
17588
17589 TypeStructField *field = isf->inferred_struct_type->data.structure.fields[old_field_count];
17590 field->name = isf->field_name;
17591 field->type_entry = value_type;
17592 field->type_val = create_const_type(ira->codegen, field->type_entry);
17593 field->src_index = old_field_count;
17594 field->decl_node = value ? value->source_node : suspend_source_instr->source_node;
17595 if (value && instr_is_comptime(value)) {
17596 ZigValue *val = ir_resolve_const(ira, value, UndefOk);
17597 if (!val)
17598 return ira->codegen->invalid_instruction;
17599 field->is_comptime = true;
17600 field->init_val = create_const_vals(1);
17601 copy_const_val(field->init_val, val);
17602 return result_loc;
17603 }
17604
17605 ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false);
17606 IrInstruction *casted_ptr;
17607 if (instr_is_comptime(result_loc)) {
17608 casted_ptr = ir_const(ira, suspend_source_instr, struct_ptr_type);
17609 copy_const_val(casted_ptr->value, result_loc->value);
17610 casted_ptr->value->type = struct_ptr_type;
17611 } else {
17612 casted_ptr = result_loc;18655 casted_ptr = result_loc;
17613 }18656 } else {
17614 if (instr_is_comptime(casted_ptr)) {18657 isf->already_resolved = true;
17615 ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad);18658 // Now it's time to add the field to the struct type.
17616 if (!ptr_val)18659 uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count;
17617 return ira->codegen->invalid_instruction;18660 uint32_t new_field_count = old_field_count + 1;
17618 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {18661 isf->inferred_struct_type->data.structure.src_field_count = new_field_count;
17619 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val,18662 isf->inferred_struct_type->data.structure.fields = realloc_type_struct_fields(
17620 suspend_source_instr->source_node);18663 isf->inferred_struct_type->data.structure.fields, old_field_count, new_field_count);
17621 struct_val->special = ConstValSpecialStatic;18664
17622 struct_val->data.x_struct.fields = realloc_const_vals_ptrs(struct_val->data.x_struct.fields,18665 field = isf->inferred_struct_type->data.structure.fields[old_field_count];
17623 old_field_count, new_field_count);18666 field->name = isf->field_name;
18667 field->type_entry = value_type;
18668 field->type_val = create_const_type(ira->codegen, field->type_entry);
18669 field->src_index = old_field_count;
18670 field->decl_node = value ? value->base.source_node : suspend_source_instr->source_node;
18671 if (value && instr_is_comptime(value)) {
18672 ZigValue *val = ir_resolve_const(ira, value, UndefOk);
18673 if (!val)
18674 return ira->codegen->invalid_inst_gen;
18675 field->is_comptime = true;
18676 field->init_val = create_const_vals(1);
18677 copy_const_val(field->init_val, val);
18678 return result_loc;
18679 }
1762418680
17625 ZigValue *field_val = struct_val->data.x_struct.fields[old_field_count];18681 ZigType *struct_ptr_type = get_pointer_to_type(ira->codegen, isf->inferred_struct_type, false);
17626 field_val->special = ConstValSpecialUndef;18682 if (instr_is_comptime(result_loc)) {
17627 field_val->type = field->type_entry;18683 casted_ptr = ir_const(ira, suspend_source_instr, struct_ptr_type);
17628 field_val->parent.id = ConstParentIdStruct;18684 copy_const_val(casted_ptr->value, result_loc->value);
17629 field_val->parent.data.p_struct.struct_val = struct_val;18685 casted_ptr->value->type = struct_ptr_type;
17630 field_val->parent.data.p_struct.field_index = old_field_count;18686 } else {
18687 casted_ptr = result_loc;
18688 }
18689 if (instr_is_comptime(casted_ptr)) {
18690 ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad);
18691 if (!ptr_val)
18692 return ira->codegen->invalid_inst_gen;
18693 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
18694 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val,
18695 suspend_source_instr->source_node);
18696 struct_val->special = ConstValSpecialStatic;
18697 struct_val->data.x_struct.fields = realloc_const_vals_ptrs(struct_val->data.x_struct.fields,
18698 old_field_count, new_field_count);
18699
18700 ZigValue *field_val = struct_val->data.x_struct.fields[old_field_count];
18701 field_val->special = ConstValSpecialUndef;
18702 field_val->type = field->type_entry;
18703 field_val->parent.id = ConstParentIdStruct;
18704 field_val->parent.data.p_struct.struct_val = struct_val;
18705 field_val->parent.data.p_struct.field_index = old_field_count;
18706 }
17631 }18707 }
17632 }18708 }
1763318709
...@@ -17636,73 +18712,70 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s...@@ -17636,73 +18712,70 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s
17636 result_loc_pass1->resolved_loc = result_loc;18712 result_loc_pass1->resolved_loc = result_loc;
17637 }18713 }
1763818714
18715 if (was_written) {
18716 return result_loc;
18717 }
1763918718
17640 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr);18719 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr);
17641 ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type;18720 ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type;
17642 if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&18721 if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
17643 value_type->id != ZigTypeIdNull)18722 value_type->id != ZigTypeIdNull && value_type->id != ZigTypeIdUndefined)
17644 {18723 {
17645 bool has_bits;18724 bool same_comptime_repr = types_have_same_zig_comptime_repr(ira->codegen, actual_elem_type, value_type);
17646 if ((err = type_has_bits2(ira->codegen, value_type, &has_bits)))18725 if (!same_comptime_repr) {
17647 return ira->codegen->invalid_instruction;18726 result_loc_pass1->written = was_written;
17648 if (has_bits) {
17649 result_loc_pass1->written = false;
17650 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true);18727 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true);
17651 }18728 }
17652 } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion) {18729 } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion &&
17653 bool has_bits;18730 value_type->id != ZigTypeIdUndefined)
17654 if ((err = type_has_bits2(ira->codegen, value_type, &has_bits)))18731 {
17655 return ira->codegen->invalid_instruction;18732 if (value_type->id == ZigTypeIdErrorSet) {
17656 if (has_bits) {18733 return ir_analyze_unwrap_err_code(ira, suspend_source_instr, result_loc, true);
17657 if (value_type->id == ZigTypeIdErrorSet) {18734 } else {
17658 return ir_analyze_unwrap_err_code(ira, suspend_source_instr, result_loc, true);18735 IrInstGen *unwrapped_err_ptr = ir_analyze_unwrap_error_payload(ira, suspend_source_instr,
18736 result_loc, false, true);
18737 ZigType *actual_payload_type = actual_elem_type->data.error_union.payload_type;
18738 if (actual_payload_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
18739 value_type->id != ZigTypeIdNull && value_type->id != ZigTypeIdUndefined)
18740 {
18741 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, unwrapped_err_ptr, false, true);
17659 } else {18742 } else {
17660 IrInstruction *unwrapped_err_ptr = ir_analyze_unwrap_error_payload(ira, suspend_source_instr,18743 return unwrapped_err_ptr;
17661 result_loc, false, true);
17662 ZigType *actual_payload_type = actual_elem_type->data.error_union.payload_type;
17663 if (actual_payload_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional &&
17664 value_type->id != ZigTypeIdNull) {
17665 return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, unwrapped_err_ptr, false, true);
17666 } else {
17667 return unwrapped_err_ptr;
17668 }
17669 }18744 }
17670 }18745 }
17671 }18746 }
17672 return result_loc;18747 return result_loc;
17673}18748}
1767418749
17675static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,18750static IrInstGen *ir_analyze_instruction_resolve_result(IrAnalyze *ira, IrInstSrcResolveResult *instruction) {
17676 IrInstructionResolveResult *instruction)
17677{
17678 ZigType *implicit_elem_type;18751 ZigType *implicit_elem_type;
17679 if (instruction->ty == nullptr) {18752 if (instruction->ty == nullptr) {
17680 if (instruction->result_loc->id == ResultLocIdCast) {18753 if (instruction->result_loc->id == ResultLocIdCast) {
17681 implicit_elem_type = ir_resolve_type(ira,18754 implicit_elem_type = ir_resolve_type(ira,
17682 instruction->result_loc->source_instruction->child);18755 instruction->result_loc->source_instruction->child);
17683 if (type_is_invalid(implicit_elem_type))18756 if (type_is_invalid(implicit_elem_type))
17684 return ira->codegen->invalid_instruction;18757 return ira->codegen->invalid_inst_gen;
17685 } else if (instruction->result_loc->id == ResultLocIdReturn) {18758 } else if (instruction->result_loc->id == ResultLocIdReturn) {
17686 implicit_elem_type = ira->explicit_return_type;18759 implicit_elem_type = ira->explicit_return_type;
17687 if (type_is_invalid(implicit_elem_type))18760 if (type_is_invalid(implicit_elem_type))
17688 return ira->codegen->invalid_instruction;18761 return ira->codegen->invalid_inst_gen;
17689 } else {18762 } else {
17690 implicit_elem_type = ira->codegen->builtin_types.entry_var;18763 implicit_elem_type = ira->codegen->builtin_types.entry_var;
17691 }18764 }
17692 if (implicit_elem_type == ira->codegen->builtin_types.entry_var) {18765 if (implicit_elem_type == ira->codegen->builtin_types.entry_var) {
17693 Buf *bare_name = buf_alloc();18766 Buf *bare_name = buf_alloc();
17694 Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct),18767 Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct),
17695 instruction->base.scope, instruction->base.source_node, bare_name);18768 instruction->base.base.scope, instruction->base.base.source_node, bare_name);
1769618769
17697 StructSpecial struct_special = StructSpecialInferredStruct;18770 StructSpecial struct_special = StructSpecialInferredStruct;
17698 if (instruction->base.source_node->type == NodeTypeContainerInitExpr &&18771 if (instruction->base.base.source_node->type == NodeTypeContainerInitExpr &&
17699 instruction->base.source_node->data.container_init_expr.kind == ContainerInitKindArray)18772 instruction->base.base.source_node->data.container_init_expr.kind == ContainerInitKindArray)
17700 {18773 {
17701 struct_special = StructSpecialInferredTuple;18774 struct_special = StructSpecialInferredTuple;
17702 }18775 }
1770318776
17704 ZigType *inferred_struct_type = get_partial_container_type(ira->codegen,18777 ZigType *inferred_struct_type = get_partial_container_type(ira->codegen,
17705 instruction->base.scope, ContainerKindStruct, instruction->base.source_node,18778 instruction->base.base.scope, ContainerKindStruct, instruction->base.base.source_node,
17706 buf_ptr(name), bare_name, ContainerLayoutAuto);18779 buf_ptr(name), bare_name, ContainerLayoutAuto);
17707 inferred_struct_type->data.structure.special = struct_special;18780 inferred_struct_type->data.structure.special = struct_special;
17708 inferred_struct_type->data.structure.resolve_status = ResolveStatusBeingInferred;18781 inferred_struct_type->data.structure.resolve_status = ResolveStatusBeingInferred;
...@@ -17711,21 +18784,21 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,...@@ -17711,21 +18784,21 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,
17711 } else {18784 } else {
17712 implicit_elem_type = ir_resolve_type(ira, instruction->ty->child);18785 implicit_elem_type = ir_resolve_type(ira, instruction->ty->child);
17713 if (type_is_invalid(implicit_elem_type))18786 if (type_is_invalid(implicit_elem_type))
17714 return ira->codegen->invalid_instruction;18787 return ira->codegen->invalid_inst_gen;
17715 }18788 }
17716 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,18789 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
17717 implicit_elem_type, nullptr, false, true, true);18790 implicit_elem_type, nullptr, false, true);
17718 if (result_loc != nullptr)18791 if (result_loc != nullptr)
17719 return result_loc;18792 return result_loc;
1772018793
17721 ZigFn *fn = exec_fn_entry(ira->new_irb.exec);18794 ZigFn *fn = ira->new_irb.exec->fn_entry;
17722 if (fn != nullptr && fn->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync &&18795 if (fn != nullptr && fn->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync &&
17723 instruction->result_loc->id == ResultLocIdReturn)18796 instruction->result_loc->id == ResultLocIdReturn)
17724 {18797 {
17725 result_loc = ir_resolve_result(ira, &instruction->base, no_result_loc(),18798 result_loc = ir_resolve_result(ira, &instruction->base.base, no_result_loc(),
17726 implicit_elem_type, nullptr, false, true, true);18799 implicit_elem_type, nullptr, false, true);
17727 if (result_loc != nullptr &&18800 if (result_loc != nullptr &&
17728 (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))18801 (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable))
17729 {18802 {
17730 return result_loc;18803 return result_loc;
17731 }18804 }
...@@ -17733,9 +18806,9 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,...@@ -17733,9 +18806,9 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,
17733 return result_loc;18806 return result_loc;
17734 }18807 }
1773518808
17736 IrInstruction *result = ir_const(ira, &instruction->base, implicit_elem_type);18809 IrInstGen *result = ir_const(ira, &instruction->base.base, implicit_elem_type);
17737 result->value->special = ConstValSpecialUndef;18810 result->value->special = ConstValSpecialUndef;
17738 IrInstruction *ptr = ir_get_ref(ira, &instruction->base, result, false, false);18811 IrInstGen *ptr = ir_get_ref(ira, &instruction->base.base, result, false, false);
17739 ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar;18812 ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar;
17740 return ptr;18813 return ptr;
17741}18814}
...@@ -17759,8 +18832,7 @@ static void ir_reset_result(ResultLoc *result_loc) {...@@ -17759,8 +18832,7 @@ static void ir_reset_result(ResultLoc *result_loc) {
17759 break;18832 break;
17760 }18833 }
17761 case ResultLocIdVar: {18834 case ResultLocIdVar: {
17762 IrInstructionAllocaSrc *alloca_src =18835 IrInstSrcAlloca *alloca_src = reinterpret_cast<IrInstSrcAlloca *>(result_loc->source_instruction);
17763 reinterpret_cast<IrInstructionAllocaSrc *>(result_loc->source_instruction);
17764 alloca_src->base.child = nullptr;18836 alloca_src->base.child = nullptr;
17765 break;18837 break;
17766 }18838 }
...@@ -17776,18 +18848,18 @@ static void ir_reset_result(ResultLoc *result_loc) {...@@ -17776,18 +18848,18 @@ static void ir_reset_result(ResultLoc *result_loc) {
17776 }18848 }
17777}18849}
1777818850
17779static IrInstruction *ir_analyze_instruction_reset_result(IrAnalyze *ira, IrInstructionResetResult *instruction) {18851static IrInstGen *ir_analyze_instruction_reset_result(IrAnalyze *ira, IrInstSrcResetResult *instruction) {
17780 ir_reset_result(instruction->result_loc);18852 ir_reset_result(instruction->result_loc);
17781 return ir_const_void(ira, &instruction->base);18853 return ir_const_void(ira, &instruction->base.base);
17782}18854}
1778318855
17784static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstruction *source_instr,18856static IrInstGen *get_async_call_result_loc(IrAnalyze *ira, IrInst* source_instr,
17785 ZigType *fn_ret_type, bool is_async_call_builtin, IrInstruction **args_ptr, size_t args_len,18857 ZigType *fn_ret_type, bool is_async_call_builtin, IrInstGen **args_ptr, size_t args_len,
17786 IrInstruction *ret_ptr_uncasted)18858 IrInstGen *ret_ptr_uncasted)
17787{18859{
17788 ir_assert(is_async_call_builtin, source_instr);18860 ir_assert(is_async_call_builtin, source_instr);
17789 if (type_is_invalid(ret_ptr_uncasted->value->type))18861 if (type_is_invalid(ret_ptr_uncasted->value->type))
17790 return ira->codegen->invalid_instruction;18862 return ira->codegen->invalid_inst_gen;
17791 if (ret_ptr_uncasted->value->type->id == ZigTypeIdVoid) {18863 if (ret_ptr_uncasted->value->type->id == ZigTypeIdVoid) {
17792 // Result location will be inside the async frame.18864 // Result location will be inside the async frame.
17793 return nullptr;18865 return nullptr;
...@@ -17795,57 +18867,58 @@ static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstruction *s...@@ -17795,57 +18867,58 @@ static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstruction *s
17795 return ir_implicit_cast(ira, ret_ptr_uncasted, get_pointer_to_type(ira->codegen, fn_ret_type, false));18867 return ir_implicit_cast(ira, ret_ptr_uncasted, get_pointer_to_type(ira->codegen, fn_ret_type, false));
17796}18868}
1779718869
17798static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstruction *source_instr, ZigFn *fn_entry,18870static IrInstGen *ir_analyze_async_call(IrAnalyze *ira, IrInst* source_instr, ZigFn *fn_entry,
17799 ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count,18871 ZigType *fn_type, IrInstGen *fn_ref, IrInstGen **casted_args, size_t arg_count,
17800 IrInstruction *casted_new_stack, bool is_async_call_builtin, IrInstruction *ret_ptr_uncasted,18872 IrInstGen *casted_new_stack, bool is_async_call_builtin, IrInstGen *ret_ptr_uncasted,
17801 ResultLoc *call_result_loc)18873 ResultLoc *call_result_loc)
17802{18874{
17803 if (fn_entry == nullptr) {18875 if (fn_entry == nullptr) {
17804 if (fn_type->data.fn.fn_type_id.cc != CallingConventionAsync) {18876 if (fn_type->data.fn.fn_type_id.cc != CallingConventionAsync) {
17805 ir_add_error(ira, fn_ref,18877 ir_add_error(ira, &fn_ref->base,
17806 buf_sprintf("expected async function, found '%s'", buf_ptr(&fn_type->name)));18878 buf_sprintf("expected async function, found '%s'", buf_ptr(&fn_type->name)));
17807 return ira->codegen->invalid_instruction;18879 return ira->codegen->invalid_inst_gen;
17808 }18880 }
17809 if (casted_new_stack == nullptr) {18881 if (casted_new_stack == nullptr) {
17810 ir_add_error(ira, fn_ref, buf_sprintf("function is not comptime-known; @asyncCall required"));18882 ir_add_error(ira, &fn_ref->base, buf_sprintf("function is not comptime-known; @asyncCall required"));
17811 return ira->codegen->invalid_instruction;18883 return ira->codegen->invalid_inst_gen;
17812 }18884 }
17813 }18885 }
17814 if (casted_new_stack != nullptr) {18886 if (casted_new_stack != nullptr) {
17815 ZigType *fn_ret_type = fn_type->data.fn.fn_type_id.return_type;18887 ZigType *fn_ret_type = fn_type->data.fn.fn_type_id.return_type;
17816 IrInstruction *ret_ptr = get_async_call_result_loc(ira, source_instr, fn_ret_type, is_async_call_builtin,18888 IrInstGen *ret_ptr = get_async_call_result_loc(ira, source_instr, fn_ret_type, is_async_call_builtin,
17817 casted_args, arg_count, ret_ptr_uncasted);18889 casted_args, arg_count, ret_ptr_uncasted);
17818 if (ret_ptr != nullptr && type_is_invalid(ret_ptr->value->type))18890 if (ret_ptr != nullptr && type_is_invalid(ret_ptr->value->type))
17819 return ira->codegen->invalid_instruction;18891 return ira->codegen->invalid_inst_gen;
1782018892
17821 ZigType *anyframe_type = get_any_frame_type(ira->codegen, fn_ret_type);18893 ZigType *anyframe_type = get_any_frame_type(ira->codegen, fn_ret_type);
1782218894
17823 IrInstructionCallGen *call_gen = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref,18895 IrInstGenCall *call_gen = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref,
17824 arg_count, casted_args, CallModifierAsync, casted_new_stack,18896 arg_count, casted_args, CallModifierAsync, casted_new_stack,
17825 is_async_call_builtin, ret_ptr, anyframe_type);18897 is_async_call_builtin, ret_ptr, anyframe_type);
17826 return &call_gen->base;18898 return &call_gen->base;
17827 } else {18899 } else {
17828 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry);18900 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry);
17829 IrInstruction *result_loc = ir_resolve_result(ira, source_instr, call_result_loc,18901 IrInstGen *result_loc = ir_resolve_result(ira, source_instr, call_result_loc,
17830 frame_type, nullptr, true, true, false);18902 frame_type, nullptr, true, false);
17831 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {18903 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
17832 return result_loc;18904 return result_loc;
17833 }18905 }
17834 result_loc = ir_implicit_cast(ira, result_loc, get_pointer_to_type(ira->codegen, frame_type, false));18906 result_loc = ir_implicit_cast2(ira, &call_result_loc->source_instruction->base, result_loc,
18907 get_pointer_to_type(ira->codegen, frame_type, false));
17835 if (type_is_invalid(result_loc->value->type))18908 if (type_is_invalid(result_loc->value->type))
17836 return ira->codegen->invalid_instruction;18909 return ira->codegen->invalid_inst_gen;
17837 return &ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, arg_count,18910 return &ir_build_call_gen(ira, source_instr, fn_entry, fn_ref, arg_count,
17838 casted_args, CallModifierAsync, casted_new_stack,18911 casted_args, CallModifierAsync, casted_new_stack,
17839 is_async_call_builtin, result_loc, frame_type)->base;18912 is_async_call_builtin, result_loc, frame_type)->base;
17840 }18913 }
17841}18914}
17842static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node,18915static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node,
17843 IrInstruction *arg, Scope **exec_scope, size_t *next_proto_i)18916 IrInstGen *arg, Scope **exec_scope, size_t *next_proto_i)
17844{18917{
17845 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i);18918 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i);
17846 assert(param_decl_node->type == NodeTypeParamDecl);18919 assert(param_decl_node->type == NodeTypeParamDecl);
1784718920
17848 IrInstruction *casted_arg;18921 IrInstGen *casted_arg;
17849 if (param_decl_node->data.param_decl.var_token == nullptr) {18922 if (param_decl_node->data.param_decl.var_token == nullptr) {
17850 AstNode *param_type_node = param_decl_node->data.param_decl.type;18923 AstNode *param_type_node = param_decl_node->data.param_decl.type;
17851 ZigType *param_type = ir_analyze_type_expr(ira, *exec_scope, param_type_node);18924 ZigType *param_type = ir_analyze_type_expr(ira, *exec_scope, param_type_node);
...@@ -17873,15 +18946,15 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node...@@ -17873,15 +18946,15 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
17873}18946}
1787418947
17875static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node,18948static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node,
17876 IrInstruction *arg, Scope **child_scope, size_t *next_proto_i,18949 IrInstGen *arg, IrInst *arg_src, Scope **child_scope, size_t *next_proto_i,
17877 GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstruction **casted_args,18950 GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstGen **casted_args,
17878 ZigFn *impl_fn)18951 ZigFn *impl_fn)
17879{18952{
17880 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i);18953 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i);
17881 assert(param_decl_node->type == NodeTypeParamDecl);18954 assert(param_decl_node->type == NodeTypeParamDecl);
17882 bool is_var_args = param_decl_node->data.param_decl.is_var_args;18955 bool is_var_args = param_decl_node->data.param_decl.is_var_args;
17883 bool arg_part_of_generic_id = false;18956 bool arg_part_of_generic_id = false;
17884 IrInstruction *casted_arg;18957 IrInstGen *casted_arg;
17885 if (is_var_args) {18958 if (is_var_args) {
17886 arg_part_of_generic_id = true;18959 arg_part_of_generic_id = true;
17887 casted_arg = arg;18960 casted_arg = arg;
...@@ -17892,7 +18965,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -17892,7 +18965,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
17892 if (type_is_invalid(param_type))18965 if (type_is_invalid(param_type))
17893 return false;18966 return false;
1789418967
17895 casted_arg = ir_implicit_cast(ira, arg, param_type);18968 casted_arg = ir_implicit_cast2(ira, arg_src, arg, param_type);
17896 if (type_is_invalid(casted_arg->value->type))18969 if (type_is_invalid(casted_arg->value->type))
17897 return false;18970 return false;
17898 } else {18971 } else {
...@@ -17941,7 +19014,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -17941,7 +19014,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
17941 } else if (casted_arg->value->type->id == ZigTypeIdComptimeInt ||19014 } else if (casted_arg->value->type->id == ZigTypeIdComptimeInt ||
17942 casted_arg->value->type->id == ZigTypeIdComptimeFloat)19015 casted_arg->value->type->id == ZigTypeIdComptimeFloat)
17943 {19016 {
17944 ir_add_error(ira, casted_arg,19017 ir_add_error(ira, &casted_arg->base,
17945 buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557"));19018 buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557"));
17946 return false;19019 return false;
17947 }19020 }
...@@ -17958,47 +19031,33 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -17958,47 +19031,33 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
17958 return true;19031 return true;
17959}19032}
1796019033
17961static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var) {19034static IrInstGen *ir_get_var_ptr(IrAnalyze *ira, IrInst *source_instr, ZigVar *var) {
17962 while (var->next_var != nullptr) {19035 while (var->next_var != nullptr) {
17963 var = var->next_var;19036 var = var->next_var;
17964 }19037 }
1796519038
17966 if (var->mem_slot_index != SIZE_MAX && var->owner_exec->analysis == nullptr) {
17967 assert(ira->codegen->errors.length != 0);
17968 return ira->codegen->invalid_instruction;
17969 }
17970 if (var->var_type == nullptr || type_is_invalid(var->var_type))19039 if (var->var_type == nullptr || type_is_invalid(var->var_type))
17971 return ira->codegen->invalid_instruction;19040 return ira->codegen->invalid_inst_gen;
1797219041
17973 ZigValue *mem_slot = nullptr;
17974
17975 bool comptime_var_mem = ir_get_var_is_comptime(var);
17976 bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern;
17977 bool is_volatile = false;19042 bool is_volatile = false;
1797819043 ZigType *var_ptr_type = get_pointer_to_type_extra(ira->codegen, var->var_type,
17979 IrInstruction *result = ir_build_var_ptr(&ira->new_irb,
17980 instruction->scope, instruction->source_node, var);
17981 result->value->type = get_pointer_to_type_extra(ira->codegen, var->var_type,
17982 var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0, false);19044 var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0, false);
1798319045
17984 if (linkage_makes_it_runtime || var->is_thread_local)19046 if (var->ptr_instruction != nullptr) {
17985 goto no_mem_slot;19047 return ir_implicit_cast(ira, var->ptr_instruction, var_ptr_type);
17986
17987 if (value_is_comptime(var->const_value)) {
17988 mem_slot = var->const_value;
17989 } else if (var->mem_slot_index != SIZE_MAX && (comptime_var_mem || var->gen_is_const)) {
17990 // find the relevant exec_context
17991 assert(var->owner_exec != nullptr);
17992 assert(var->owner_exec->analysis != nullptr);
17993 IrExecContext *exec_context = &var->owner_exec->analysis->exec_context;
17994 assert(var->mem_slot_index < exec_context->mem_slot_list.length);
17995 mem_slot = exec_context->mem_slot_list.at(var->mem_slot_index);
17996 }19048 }
1799719049
17998 if (mem_slot != nullptr) {19050 bool comptime_var_mem = ir_get_var_is_comptime(var);
17999 switch (mem_slot->special) {19051 bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern;
19052
19053 IrInstGen *result = ir_build_var_ptr_gen(ira, source_instr, var);
19054 result->value->type = var_ptr_type;
19055
19056 if (!linkage_makes_it_runtime && !var->is_thread_local && value_is_comptime(var->const_value)) {
19057 ZigValue *val = var->const_value;
19058 switch (val->special) {
18000 case ConstValSpecialRuntime:19059 case ConstValSpecialRuntime:
18001 goto no_mem_slot;19060 break;
18002 case ConstValSpecialStatic: // fallthrough19061 case ConstValSpecialStatic: // fallthrough
18003 case ConstValSpecialLazy: // fallthrough19062 case ConstValSpecialLazy: // fallthrough
18004 case ConstValSpecialUndef: {19063 case ConstValSpecialUndef: {
...@@ -18014,15 +19073,12 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,...@@ -18014,15 +19073,12 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction,
18014 result->value->special = ConstValSpecialStatic;19073 result->value->special = ConstValSpecialStatic;
18015 result->value->data.x_ptr.mut = ptr_mut;19074 result->value->data.x_ptr.mut = ptr_mut;
18016 result->value->data.x_ptr.special = ConstPtrSpecialRef;19075 result->value->data.x_ptr.special = ConstPtrSpecialRef;
18017 result->value->data.x_ptr.data.ref.pointee = mem_slot;19076 result->value->data.x_ptr.data.ref.pointee = val;
18018 return result;19077 return result;
18019 }19078 }
18020 }19079 }
18021 zig_unreachable();
18022 }19080 }
1802319081
18024no_mem_slot:
18025
18026 bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr);19082 bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr);
18027 result->value->data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack;19083 result->value->data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack;
1802819084
...@@ -18030,7 +19086,7 @@ no_mem_slot:...@@ -18030,7 +19086,7 @@ no_mem_slot:
18030}19086}
1803119087
18032// This function is called when a comptime value becomes accessible at runtime.19088// This function is called when a comptime value becomes accessible at runtime.
18033static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *val) {19089static void mark_comptime_value_escape(IrAnalyze *ira, IrInst* source_instr, ZigValue *val) {
18034 ir_assert(value_is_comptime(val), source_instr);19090 ir_assert(value_is_comptime(val), source_instr);
18035 if (val->special == ConstValSpecialUndef)19091 if (val->special == ConstValSpecialUndef)
18036 return;19092 return;
...@@ -18043,8 +19099,8 @@ static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_ins...@@ -18043,8 +19099,8 @@ static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_ins
18043 }19099 }
18044}19100}
1804519101
18046static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr,19102static IrInstGen *ir_analyze_store_ptr(IrAnalyze *ira, IrInst* source_instr,
18047 IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const)19103 IrInstGen *ptr, IrInstGen *uncasted_value, bool allow_write_through_const)
18048{19104{
18049 assert(ptr->value->type->id == ZigTypeIdPointer);19105 assert(ptr->value->type->id == ZigTypeIdPointer);
1805019106
...@@ -18053,24 +19109,24 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -18053,24 +19109,24 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
18053 uncasted_value->value->type->id == ZigTypeIdErrorSet)19109 uncasted_value->value->type->id == ZigTypeIdErrorSet)
18054 {19110 {
18055 ir_add_error(ira, source_instr, buf_sprintf("error is discarded"));19111 ir_add_error(ira, source_instr, buf_sprintf("error is discarded"));
18056 return ira->codegen->invalid_instruction;19112 return ira->codegen->invalid_inst_gen;
18057 }19113 }
18058 return ir_const_void(ira, source_instr);19114 return ir_const_void(ira, source_instr);
18059 }19115 }
1806019116
18061 if (ptr->value->type->data.pointer.is_const && !allow_write_through_const) {19117 if (ptr->value->type->data.pointer.is_const && !allow_write_through_const) {
18062 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));19118 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));
18063 return ira->codegen->invalid_instruction;19119 return ira->codegen->invalid_inst_gen;
18064 }19120 }
1806519121
18066 ZigType *child_type = ptr->value->type->data.pointer.child_type;19122 ZigType *child_type = ptr->value->type->data.pointer.child_type;
18067 IrInstruction *value = ir_implicit_cast(ira, uncasted_value, child_type);19123 IrInstGen *value = ir_implicit_cast(ira, uncasted_value, child_type);
18068 if (value == ira->codegen->invalid_instruction)19124 if (type_is_invalid(value->value->type))
18069 return ira->codegen->invalid_instruction;19125 return ira->codegen->invalid_inst_gen;
1807019126
18071 switch (type_has_one_possible_value(ira->codegen, child_type)) {19127 switch (type_has_one_possible_value(ira->codegen, child_type)) {
18072 case OnePossibleValueInvalid:19128 case OnePossibleValueInvalid:
18073 return ira->codegen->invalid_instruction;19129 return ira->codegen->invalid_inst_gen;
18074 case OnePossibleValueYes:19130 case OnePossibleValueYes:
18075 return ir_const_void(ira, source_instr);19131 return ir_const_void(ira, source_instr);
18076 case OnePossibleValueNo:19132 case OnePossibleValueNo:
...@@ -18080,7 +19136,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -18080,7 +19136,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
18080 if (instr_is_comptime(ptr) && ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {19136 if (instr_is_comptime(ptr) && ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
18081 if (!allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) {19137 if (!allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) {
18082 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));19138 ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant"));
18083 return ira->codegen->invalid_instruction;19139 return ira->codegen->invalid_inst_gen;
18084 }19140 }
18085 if ((allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) ||19141 if ((allow_write_through_const && ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) ||
18086 ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar ||19142 ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar ||
...@@ -18089,7 +19145,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -18089,7 +19145,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
18089 if (instr_is_comptime(value)) {19145 if (instr_is_comptime(value)) {
18090 ZigValue *dest_val = const_ptr_pointee(ira, ira->codegen, ptr->value, source_instr->source_node);19146 ZigValue *dest_val = const_ptr_pointee(ira, ira->codegen, ptr->value, source_instr->source_node);
18091 if (dest_val == nullptr)19147 if (dest_val == nullptr)
18092 return ira->codegen->invalid_instruction;19148 return ira->codegen->invalid_inst_gen;
18093 if (dest_val->special != ConstValSpecialRuntime) {19149 if (dest_val->special != ConstValSpecialRuntime) {
18094 copy_const_val(dest_val, value->value);19150 copy_const_val(dest_val, value->value);
1809519151
...@@ -18109,7 +19165,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -18109,7 +19165,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
18109 ZigValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, ptr->value);19165 ZigValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, ptr->value);
18110 dest_val->type = ira->codegen->builtin_types.entry_invalid;19166 dest_val->type = ira->codegen->builtin_types.entry_invalid;
1811119167
18112 return ira->codegen->invalid_instruction;19168 return ira->codegen->invalid_inst_gen;
18113 }19169 }
18114 }19170 }
18115 }19171 }
...@@ -18122,15 +19178,15 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -18122,15 +19178,15 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
1812219178
18123 switch (type_requires_comptime(ira->codegen, child_type)) {19179 switch (type_requires_comptime(ira->codegen, child_type)) {
18124 case ReqCompTimeInvalid:19180 case ReqCompTimeInvalid:
18125 return ira->codegen->invalid_instruction;19181 return ira->codegen->invalid_inst_gen;
18126 case ReqCompTimeYes:19182 case ReqCompTimeYes:
18127 switch (type_has_one_possible_value(ira->codegen, ptr->value->type)) {19183 switch (type_has_one_possible_value(ira->codegen, ptr->value->type)) {
18128 case OnePossibleValueInvalid:19184 case OnePossibleValueInvalid:
18129 return ira->codegen->invalid_instruction;19185 return ira->codegen->invalid_inst_gen;
18130 case OnePossibleValueNo:19186 case OnePossibleValueNo:
18131 ir_add_error(ira, source_instr,19187 ir_add_error(ira, source_instr,
18132 buf_sprintf("cannot store runtime value in type '%s'", buf_ptr(&child_type->name)));19188 buf_sprintf("cannot store runtime value in type '%s'", buf_ptr(&child_type->name)));
18133 return ira->codegen->invalid_instruction;19189 return ira->codegen->invalid_inst_gen;
18134 case OnePossibleValueYes:19190 case OnePossibleValueYes:
18135 return ir_const_void(ira, source_instr);19191 return ir_const_void(ira, source_instr);
18136 }19192 }
...@@ -18144,30 +19200,28 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source...@@ -18144,30 +19200,28 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
18144 }19200 }
1814519201
18146 // If this is a store to a pointer with a runtime-known vector index,19202 // If this is a store to a pointer with a runtime-known vector index,
18147 // we have to figure out the IrInstruction which represents the index and19203 // we have to figure out the IrInstGen which represents the index and
18148 // emit a IrInstructionVectorStoreElem, or emit a compile error19204 // emit a IrInstGenVectorStoreElem, or emit a compile error
18149 // explaining why it is impossible for this store to work. Which is that19205 // explaining why it is impossible for this store to work. Which is that
18150 // the pointer address is of the vector; without the element index being known19206 // the pointer address is of the vector; without the element index being known
18151 // we cannot properly perform the insertion.19207 // we cannot properly perform the insertion.
18152 if (ptr->value->type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) {19208 if (ptr->value->type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) {
18153 if (ptr->id == IrInstructionIdElemPtr) {19209 if (ptr->id == IrInstGenIdElemPtr) {
18154 IrInstructionElemPtr *elem_ptr = (IrInstructionElemPtr *)ptr;19210 IrInstGenElemPtr *elem_ptr = (IrInstGenElemPtr *)ptr;
18155 return ir_build_vector_store_elem(ira, source_instr, elem_ptr->array_ptr,19211 return ir_build_vector_store_elem(ira, source_instr, elem_ptr->array_ptr,
18156 elem_ptr->elem_index, value);19212 elem_ptr->elem_index, value);
18157 }19213 }
18158 ir_add_error(ira, ptr,19214 ir_add_error(ira, &ptr->base,
18159 buf_sprintf("unable to determine vector element index of type '%s'",19215 buf_sprintf("unable to determine vector element index of type '%s'",
18160 buf_ptr(&ptr->value->type->name)));19216 buf_ptr(&ptr->value->type->name)));
18161 return ira->codegen->invalid_instruction;19217 return ira->codegen->invalid_inst_gen;
18162 }19218 }
1816319219
18164 IrInstructionStorePtr *store_ptr = ir_build_store_ptr(&ira->new_irb, source_instr->scope,19220 return ir_build_store_ptr_gen(ira, source_instr, ptr, value);
18165 source_instr->source_node, ptr, value);
18166 return &store_ptr->base;
18167}19221}
1816819222
18169static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstruction *source_instr,19223static IrInstGen *analyze_casted_new_stack(IrAnalyze *ira, IrInst* source_instr,
18170 IrInstruction *new_stack, bool is_async_call_builtin, ZigFn *fn_entry)19224 IrInstGen *new_stack, IrInst *new_stack_src, bool is_async_call_builtin, ZigFn *fn_entry)
18171{19225{
18172 if (new_stack == nullptr)19226 if (new_stack == nullptr)
18173 return nullptr;19227 return nullptr;
...@@ -18192,15 +19246,15 @@ static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstruction *so...@@ -18192,15 +19246,15 @@ static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstruction *so
18192 false, false, PtrLenUnknown, target_fn_align(ira->codegen->zig_target), 0, 0, false);19246 false, false, PtrLenUnknown, target_fn_align(ira->codegen->zig_target), 0, 0, false);
18193 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);19247 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);
18194 ira->codegen->need_frame_size_prefix_data = true;19248 ira->codegen->need_frame_size_prefix_data = true;
18195 return ir_implicit_cast(ira, new_stack, u8_slice);19249 return ir_implicit_cast2(ira, new_stack_src, new_stack, u8_slice);
18196 }19250 }
18197}19251}
1819819252
18199static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_instr,19253static IrInstGen *ir_analyze_fn_call(IrAnalyze *ira, IrInst* source_instr,
18200 ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref,19254 ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref,
18201 IrInstruction *first_arg_ptr, CallModifier modifier,19255 IrInstGen *first_arg_ptr, IrInst *first_arg_ptr_src, CallModifier modifier,
18202 IrInstruction *new_stack, bool is_async_call_builtin,19256 IrInstGen *new_stack, IrInst *new_stack_src, bool is_async_call_builtin,
18203 IrInstruction **args_ptr, size_t args_len, IrInstruction *ret_ptr, ResultLoc *call_result_loc)19257 IrInstGen **args_ptr, size_t args_len, IrInstGen *ret_ptr, ResultLoc *call_result_loc)
18204{19258{
18205 Error err;19259 Error err;
18206 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;19260 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
...@@ -18221,11 +19275,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18221,11 +19275,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18221 AstNode *fn_proto_node = fn_entry ? fn_entry->proto_node : nullptr;;19275 AstNode *fn_proto_node = fn_entry ? fn_entry->proto_node : nullptr;;
1822219276
18223 if (fn_type_id->cc == CallingConventionNaked) {19277 if (fn_type_id->cc == CallingConventionNaked) {
18224 ErrorMsg *msg = ir_add_error(ira, fn_ref, buf_sprintf("unable to call function with naked calling convention"));19278 ErrorMsg *msg = ir_add_error(ira, &fn_ref->base, buf_sprintf("unable to call function with naked calling convention"));
18225 if (fn_proto_node) {19279 if (fn_proto_node) {
18226 add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("declared here"));19280 add_error_note(ira->codegen, msg, fn_proto_node, buf_sprintf("declared here"));
18227 }19281 }
18228 return ira->codegen->invalid_instruction;19282 return ira->codegen->invalid_inst_gen;
18229 }19283 }
1823019284
18231 if (fn_type_id->is_var_args) {19285 if (fn_type_id->is_var_args) {
...@@ -18236,7 +19290,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18236,7 +19290,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18236 add_error_note(ira->codegen, msg, fn_proto_node,19290 add_error_note(ira->codegen, msg, fn_proto_node,
18237 buf_sprintf("declared here"));19291 buf_sprintf("declared here"));
18238 }19292 }
18239 return ira->codegen->invalid_instruction;19293 return ira->codegen->invalid_inst_gen;
18240 }19294 }
18241 } else if (src_param_count != call_param_count) {19295 } else if (src_param_count != call_param_count) {
18242 ErrorMsg *msg = ir_add_error_node(ira, source_node,19296 ErrorMsg *msg = ir_add_error_node(ira, source_node,
...@@ -18245,18 +19299,18 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18245,18 +19299,18 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18245 add_error_note(ira->codegen, msg, fn_proto_node,19299 add_error_note(ira->codegen, msg, fn_proto_node,
18246 buf_sprintf("declared here"));19300 buf_sprintf("declared here"));
18247 }19301 }
18248 return ira->codegen->invalid_instruction;19302 return ira->codegen->invalid_inst_gen;
18249 }19303 }
1825019304
18251 if (modifier == CallModifierCompileTime) {19305 if (modifier == CallModifierCompileTime) {
18252 // No special handling is needed for compile time evaluation of generic functions.19306 // No special handling is needed for compile time evaluation of generic functions.
18253 if (!fn_entry || fn_entry->body_node == nullptr) {19307 if (!fn_entry || fn_entry->body_node == nullptr) {
18254 ir_add_error(ira, fn_ref, buf_sprintf("unable to evaluate constant expression"));19308 ir_add_error(ira, &fn_ref->base, buf_sprintf("unable to evaluate constant expression"));
18255 return ira->codegen->invalid_instruction;19309 return ira->codegen->invalid_inst_gen;
18256 }19310 }
1825719311
18258 if (!ir_emit_backward_branch(ira, source_instr))19312 if (!ir_emit_backward_branch(ira, source_instr))
18259 return ira->codegen->invalid_instruction;19313 return ira->codegen->invalid_inst_gen;
1826019314
18261 // Fork a scope of the function with known values for the parameters.19315 // Fork a scope of the function with known values for the parameters.
18262 Scope *exec_scope = &fn_entry->fndef_scope->base;19316 Scope *exec_scope = &fn_entry->fndef_scope->base;
...@@ -18269,47 +19323,40 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18269,47 +19323,40 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18269 if (fn_type_id->next_param_index >= 1) {19323 if (fn_type_id->next_param_index >= 1) {
18270 ZigType *param_type = fn_type_id->param_info[next_proto_i].type;19324 ZigType *param_type = fn_type_id->param_info[next_proto_i].type;
18271 if (type_is_invalid(param_type))19325 if (type_is_invalid(param_type))
18272 return ira->codegen->invalid_instruction;19326 return ira->codegen->invalid_inst_gen;
18273 first_arg_known_bare = param_type->id != ZigTypeIdPointer;19327 first_arg_known_bare = param_type->id != ZigTypeIdPointer;
18274 }19328 }
1827519329
18276 IrInstruction *first_arg;19330 IrInstGen *first_arg;
18277 if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) {19331 if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) {
18278 first_arg = first_arg_ptr;19332 first_arg = first_arg_ptr;
18279 } else {19333 } else {
18280 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr);19334 first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr);
18281 if (type_is_invalid(first_arg->value->type))19335 if (type_is_invalid(first_arg->value->type))
18282 return ira->codegen->invalid_instruction;19336 return ira->codegen->invalid_inst_gen;
18283 }19337 }
1828419338
18285 if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, first_arg, &exec_scope, &next_proto_i))19339 if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, first_arg, &exec_scope, &next_proto_i))
18286 return ira->codegen->invalid_instruction;19340 return ira->codegen->invalid_inst_gen;
18287 }
18288
18289 if (fn_proto_node->data.fn_proto.is_var_args) {
18290 ir_add_error(ira, source_instr,
18291 buf_sprintf("compiler bug: unable to call var args function at compile time. https://github.com/ziglang/zig/issues/313"));
18292 return ira->codegen->invalid_instruction;
18293 }19341 }
1829419342
18295
18296 for (size_t call_i = 0; call_i < args_len; call_i += 1) {19343 for (size_t call_i = 0; call_i < args_len; call_i += 1) {
18297 IrInstruction *old_arg = args_ptr[call_i];19344 IrInstGen *old_arg = args_ptr[call_i];
1829819345
18299 if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, old_arg, &exec_scope, &next_proto_i))19346 if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, old_arg, &exec_scope, &next_proto_i))
18300 return ira->codegen->invalid_instruction;19347 return ira->codegen->invalid_inst_gen;
18301 }19348 }
1830219349
18303 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;19350 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
18304 ZigType *specified_return_type = ir_analyze_type_expr(ira, exec_scope, return_type_node);19351 ZigType *specified_return_type = ir_analyze_type_expr(ira, exec_scope, return_type_node);
18305 if (type_is_invalid(specified_return_type))19352 if (type_is_invalid(specified_return_type))
18306 return ira->codegen->invalid_instruction;19353 return ira->codegen->invalid_inst_gen;
18307 ZigType *return_type;19354 ZigType *return_type;
18308 ZigType *inferred_err_set_type = nullptr;19355 ZigType *inferred_err_set_type = nullptr;
18309 if (fn_proto_node->data.fn_proto.auto_err_set) {19356 if (fn_proto_node->data.fn_proto.auto_err_set) {
18310 inferred_err_set_type = get_auto_err_set_type(ira->codegen, fn_entry);19357 inferred_err_set_type = get_auto_err_set_type(ira->codegen, fn_entry);
18311 if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown)))19358 if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown)))
18312 return ira->codegen->invalid_instruction;19359 return ira->codegen->invalid_inst_gen;
18313 return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);19360 return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);
18314 } else {19361 } else {
18315 return_type = specified_return_type;19362 return_type = specified_return_type;
...@@ -18326,10 +19373,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18326,10 +19373,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18326 if (result == nullptr) {19373 if (result == nullptr) {
18327 // Analyze the fn body block like any other constant expression.19374 // Analyze the fn body block like any other constant expression.
18328 AstNode *body_node = fn_entry->body_node;19375 AstNode *body_node = fn_entry->body_node;
18329 result = ir_eval_const_value(ira->codegen, exec_scope, body_node, return_type,19376 ZigValue *result_ptr;
18330 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, fn_entry,19377 create_result_ptr(ira->codegen, return_type, &result, &result_ptr);
18331 nullptr, source_instr->source_node, nullptr, ira->new_irb.exec, return_type_node,19378 if ((err = ir_eval_const_value(ira->codegen, exec_scope, body_node, result_ptr,
18332 UndefOk);19379 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota,
19380 fn_entry, nullptr, source_instr->source_node, nullptr, ira->new_irb.exec, return_type_node,
19381 UndefOk)))
19382 {
19383 return ira->codegen->invalid_inst_gen;
19384 }
19385 destroy(result_ptr, "ZigValue");
19386 result_ptr = nullptr;
1833319387
18334 if (inferred_err_set_type != nullptr) {19388 if (inferred_err_set_type != nullptr) {
18335 inferred_err_set_type->data.error_set.incomplete = false;19389 inferred_err_set_type->data.error_set.incomplete = false;
...@@ -18354,24 +19408,24 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18354,24 +19408,24 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18354 }19408 }
1835519409
18356 if (type_is_invalid(result->type)) {19410 if (type_is_invalid(result->type)) {
18357 return ira->codegen->invalid_instruction;19411 return ira->codegen->invalid_inst_gen;
18358 }19412 }
18359 }19413 }
1836019414
18361 IrInstruction *new_instruction = ir_const_move(ira, source_instr, result);19415 IrInstGen *new_instruction = ir_const_move(ira, source_instr, result);
18362 return ir_finish_anal(ira, new_instruction);19416 return ir_finish_anal(ira, new_instruction);
18363 }19417 }
1836419418
18365 if (fn_type->data.fn.is_generic) {19419 if (fn_type->data.fn.is_generic) {
18366 if (!fn_entry) {19420 if (!fn_entry) {
18367 ir_add_error(ira, fn_ref,19421 ir_add_error(ira, &fn_ref->base,
18368 buf_sprintf("calling a generic function requires compile-time known function value"));19422 buf_sprintf("calling a generic function requires compile-time known function value"));
18369 return ira->codegen->invalid_instruction;19423 return ira->codegen->invalid_inst_gen;
18370 }19424 }
1837119425
18372 size_t new_fn_arg_count = first_arg_1_or_0 + args_len;19426 size_t new_fn_arg_count = first_arg_1_or_0 + args_len;
1837319427
18374 IrInstruction **casted_args = allocate<IrInstruction *>(new_fn_arg_count);19428 IrInstGen **casted_args = allocate<IrInstGen *>(new_fn_arg_count);
1837519429
18376 // Fork a scope of the function with known values for the parameters.19430 // Fork a scope of the function with known values for the parameters.
18377 Scope *parent_scope = fn_entry->fndef_scope->base.parent;19431 Scope *parent_scope = fn_entry->fndef_scope->base.parent;
...@@ -18400,50 +19454,57 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18400,50 +19454,57 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18400 if (fn_type_id->next_param_index >= 1) {19454 if (fn_type_id->next_param_index >= 1) {
18401 ZigType *param_type = fn_type_id->param_info[next_proto_i].type;19455 ZigType *param_type = fn_type_id->param_info[next_proto_i].type;
18402 if (type_is_invalid(param_type))19456 if (type_is_invalid(param_type))
18403 return ira->codegen->invalid_instruction;19457 return ira->codegen->invalid_inst_gen;
18404 first_arg_known_bare = param_type->id != ZigTypeIdPointer;19458 first_arg_known_bare = param_type->id != ZigTypeIdPointer;
18405 }19459 }
1840619460
18407 IrInstruction *first_arg;19461 IrInstGen *first_arg;
18408 if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) {19462 if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) {
18409 first_arg = first_arg_ptr;19463 first_arg = first_arg_ptr;
18410 } else {19464 } else {
18411 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr);19465 first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr);
18412 if (type_is_invalid(first_arg->value->type))19466 if (type_is_invalid(first_arg->value->type))
18413 return ira->codegen->invalid_instruction;19467 return ira->codegen->invalid_inst_gen;
18414 }19468 }
1841519469
18416 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, first_arg, &impl_fn->child_scope,19470 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, first_arg, first_arg_ptr_src,
18417 &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))19471 &impl_fn->child_scope, &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))
18418 {19472 {
18419 return ira->codegen->invalid_instruction;19473 return ira->codegen->invalid_inst_gen;
18420 }19474 }
18421 }19475 }
1842219476
18423 ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);19477 ZigFn *parent_fn_entry = ira->new_irb.exec->fn_entry;
18424 assert(parent_fn_entry);19478 assert(parent_fn_entry);
18425 for (size_t call_i = 0; call_i < args_len; call_i += 1) {19479 for (size_t call_i = 0; call_i < args_len; call_i += 1) {
18426 IrInstruction *arg = args_ptr[call_i];19480 IrInstGen *arg = args_ptr[call_i];
1842719481
18428 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i);19482 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i);
18429 assert(param_decl_node->type == NodeTypeParamDecl);19483 assert(param_decl_node->type == NodeTypeParamDecl);
1843019484
18431 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &impl_fn->child_scope,19485 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &arg->base, &impl_fn->child_scope,
18432 &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))19486 &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))
18433 {19487 {
18434 return ira->codegen->invalid_instruction;19488 return ira->codegen->invalid_inst_gen;
18435 }19489 }
18436 }19490 }
1843719491
18438 if (fn_proto_node->data.fn_proto.align_expr != nullptr) {19492 if (fn_proto_node->data.fn_proto.align_expr != nullptr) {
18439 ZigValue *align_result = ir_eval_const_value(ira->codegen, impl_fn->child_scope,19493 ZigValue *align_result;
18440 fn_proto_node->data.fn_proto.align_expr, get_align_amt_type(ira->codegen),19494 ZigValue *result_ptr;
18441 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota,19495 create_result_ptr(ira->codegen, get_align_amt_type(ira->codegen), &align_result, &result_ptr);
18442 nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec,19496 if ((err = ir_eval_const_value(ira->codegen, impl_fn->child_scope,
18443 nullptr, UndefBad);19497 fn_proto_node->data.fn_proto.align_expr, result_ptr,
18444 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,19498 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota,
19499 nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec,
19500 nullptr, UndefBad)))
19501 {
19502 return ira->codegen->invalid_inst_gen;
19503 }
19504 IrInstGenConst *const_instruction = ir_create_inst_noval<IrInstGenConst>(&ira->new_irb,
18445 impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr);19505 impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr);
18446 copy_const_val(const_instruction->base.value, align_result);19506 const_instruction->base.value = align_result;
19507 destroy(result_ptr, "ZigValue");
1844719508
18448 uint32_t align_bytes = 0;19509 uint32_t align_bytes = 0;
18449 ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes);19510 ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes);
...@@ -18455,11 +19516,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18455,11 +19516,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18455 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;19516 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
18456 ZigType *specified_return_type = ir_analyze_type_expr(ira, impl_fn->child_scope, return_type_node);19517 ZigType *specified_return_type = ir_analyze_type_expr(ira, impl_fn->child_scope, return_type_node);
18457 if (type_is_invalid(specified_return_type))19518 if (type_is_invalid(specified_return_type))
18458 return ira->codegen->invalid_instruction;19519 return ira->codegen->invalid_inst_gen;
18459 if (fn_proto_node->data.fn_proto.auto_err_set) {19520 if (fn_proto_node->data.fn_proto.auto_err_set) {
18460 ZigType *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn);19521 ZigType *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn);
18461 if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown)))19522 if ((err = type_resolve(ira->codegen, specified_return_type, ResolveStatusSizeKnown)))
18462 return ira->codegen->invalid_instruction;19523 return ira->codegen->invalid_inst_gen;
18463 inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);19524 inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);
18464 } else {19525 } else {
18465 inst_fn_type_id.return_type = specified_return_type;19526 inst_fn_type_id.return_type = specified_return_type;
...@@ -18469,10 +19530,10 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18469,10 +19530,10 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18469 case ReqCompTimeYes:19530 case ReqCompTimeYes:
18470 // Throw out our work and call the function as if it were comptime.19531 // Throw out our work and call the function as if it were comptime.
18471 return ir_analyze_fn_call(ira, source_instr, fn_entry, fn_type, fn_ref, first_arg_ptr,19532 return ir_analyze_fn_call(ira, source_instr, fn_entry, fn_type, fn_ref, first_arg_ptr,
18472 CallModifierCompileTime, new_stack, is_async_call_builtin, args_ptr, args_len,19533 first_arg_ptr_src, CallModifierCompileTime, new_stack, new_stack_src, is_async_call_builtin,
18473 ret_ptr, call_result_loc);19534 args_ptr, args_len, ret_ptr, call_result_loc);
18474 case ReqCompTimeInvalid:19535 case ReqCompTimeInvalid:
18475 return ira->codegen->invalid_instruction;19536 return ira->codegen->invalid_inst_gen;
18476 case ReqCompTimeNo:19537 case ReqCompTimeNo:
18477 break;19538 break;
18478 }19539 }
...@@ -18486,7 +19547,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18486,7 +19547,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18486 // finish instantiating the function19547 // finish instantiating the function
18487 impl_fn->type_entry = get_fn_type(ira->codegen, &inst_fn_type_id);19548 impl_fn->type_entry = get_fn_type(ira->codegen, &inst_fn_type_id);
18488 if (type_is_invalid(impl_fn->type_entry))19549 if (type_is_invalid(impl_fn->type_entry))
18489 return ira->codegen->invalid_instruction;19550 return ira->codegen->invalid_inst_gen;
1849019551
18491 impl_fn->ir_executable->source_node = source_instr->source_node;19552 impl_fn->ir_executable->source_node = source_instr->source_node;
18492 impl_fn->ir_executable->parent_exec = ira->new_irb.exec;19553 impl_fn->ir_executable->parent_exec = ira->new_irb.exec;
...@@ -18504,25 +19565,25 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18504,25 +19565,25 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18504 parent_fn_entry->calls_or_awaits_errorable_fn = true;19565 parent_fn_entry->calls_or_awaits_errorable_fn = true;
18505 }19566 }
1850619567
18507 IrInstruction *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack,19568 IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack,
18508 is_async_call_builtin, impl_fn);19569 new_stack_src, is_async_call_builtin, impl_fn);
18509 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))19570 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))
18510 return ira->codegen->invalid_instruction;19571 return ira->codegen->invalid_inst_gen;
1851119572
18512 size_t impl_param_count = impl_fn_type_id->param_count;19573 size_t impl_param_count = impl_fn_type_id->param_count;
18513 if (modifier == CallModifierAsync) {19574 if (modifier == CallModifierAsync) {
18514 IrInstruction *result = ir_analyze_async_call(ira, source_instr, impl_fn, impl_fn->type_entry,19575 IrInstGen *result = ir_analyze_async_call(ira, source_instr, impl_fn, impl_fn->type_entry,
18515 nullptr, casted_args, impl_param_count, casted_new_stack, is_async_call_builtin, ret_ptr,19576 nullptr, casted_args, impl_param_count, casted_new_stack, is_async_call_builtin, ret_ptr,
18516 call_result_loc);19577 call_result_loc);
18517 return ir_finish_anal(ira, result);19578 return ir_finish_anal(ira, result);
18518 }19579 }
1851919580
18520 IrInstruction *result_loc;19581 IrInstGen *result_loc;
18521 if (handle_is_ptr(impl_fn_type_id->return_type)) {19582 if (handle_is_ptr(impl_fn_type_id->return_type)) {
18522 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,19583 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,
18523 impl_fn_type_id->return_type, nullptr, true, true, false);19584 impl_fn_type_id->return_type, nullptr, true, false);
18524 if (result_loc != nullptr) {19585 if (result_loc != nullptr) {
18525 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {19586 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
18526 return result_loc;19587 return result_loc;
18527 }19588 }
18528 ZigType *res_child_type = result_loc->value->type->data.pointer.child_type;19589 ZigType *res_child_type = result_loc->value->type->data.pointer.child_type;
...@@ -18538,7 +19599,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18538,7 +19599,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18538 result_loc = get_async_call_result_loc(ira, source_instr, impl_fn_type_id->return_type,19599 result_loc = get_async_call_result_loc(ira, source_instr, impl_fn_type_id->return_type,
18539 is_async_call_builtin, args_ptr, args_len, ret_ptr);19600 is_async_call_builtin, args_ptr, args_len, ret_ptr);
18540 if (result_loc != nullptr && type_is_invalid(result_loc->value->type))19601 if (result_loc != nullptr && type_is_invalid(result_loc->value->type))
18541 return ira->codegen->invalid_instruction;19602 return ira->codegen->invalid_inst_gen;
18542 } else {19603 } else {
18543 result_loc = nullptr;19604 result_loc = nullptr;
18544 }19605 }
...@@ -18547,11 +19608,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18547,11 +19608,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18547 parent_fn_entry->inferred_async_node == nullptr &&19608 parent_fn_entry->inferred_async_node == nullptr &&
18548 modifier != CallModifierNoAsync)19609 modifier != CallModifierNoAsync)
18549 {19610 {
18550 parent_fn_entry->inferred_async_node = fn_ref->source_node;19611 parent_fn_entry->inferred_async_node = fn_ref->base.source_node;
18551 parent_fn_entry->inferred_async_fn = impl_fn;19612 parent_fn_entry->inferred_async_fn = impl_fn;
18552 }19613 }
1855319614
18554 IrInstructionCallGen *new_call_instruction = ir_build_call_gen(ira, source_instr,19615 IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, source_instr,
18555 impl_fn, nullptr, impl_param_count, casted_args, modifier, casted_new_stack,19616 impl_fn, nullptr, impl_param_count, casted_args, modifier, casted_new_stack,
18556 is_async_call_builtin, result_loc, impl_fn_type_id->return_type);19617 is_async_call_builtin, result_loc, impl_fn_type_id->return_type);
1855719618
...@@ -18562,7 +19623,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18562,7 +19623,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18562 return ir_finish_anal(ira, &new_call_instruction->base);19623 return ir_finish_anal(ira, &new_call_instruction->base);
18563 }19624 }
1856419625
18565 ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);19626 ZigFn *parent_fn_entry = ira->new_irb.exec->fn_entry;
18566 assert(fn_type_id->return_type != nullptr);19627 assert(fn_type_id->return_type != nullptr);
18567 assert(parent_fn_entry != nullptr);19628 assert(parent_fn_entry != nullptr);
18568 if (fn_type_can_fail(fn_type_id)) {19629 if (fn_type_can_fail(fn_type_id)) {
...@@ -18570,46 +19631,46 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18570,46 +19631,46 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18570 }19631 }
1857119632
1857219633
18573 IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count);19634 IrInstGen **casted_args = allocate<IrInstGen *>(call_param_count);
18574 size_t next_arg_index = 0;19635 size_t next_arg_index = 0;
18575 if (first_arg_ptr) {19636 if (first_arg_ptr) {
18576 assert(first_arg_ptr->value->type->id == ZigTypeIdPointer);19637 assert(first_arg_ptr->value->type->id == ZigTypeIdPointer);
1857719638
18578 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;19639 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
18579 if (type_is_invalid(param_type))19640 if (type_is_invalid(param_type))
18580 return ira->codegen->invalid_instruction;19641 return ira->codegen->invalid_inst_gen;
1858119642
18582 IrInstruction *first_arg;19643 IrInstGen *first_arg;
18583 if (param_type->id == ZigTypeIdPointer &&19644 if (param_type->id == ZigTypeIdPointer &&
18584 handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type))19645 handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type))
18585 {19646 {
18586 first_arg = first_arg_ptr;19647 first_arg = first_arg_ptr;
18587 } else {19648 } else {
18588 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr);19649 first_arg = ir_get_deref(ira, &first_arg_ptr->base, first_arg_ptr, nullptr);
18589 if (type_is_invalid(first_arg->value->type))19650 if (type_is_invalid(first_arg->value->type))
18590 return ira->codegen->invalid_instruction;19651 return ira->codegen->invalid_inst_gen;
18591 }19652 }
1859219653
18593 IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, param_type);19654 IrInstGen *casted_arg = ir_implicit_cast2(ira, first_arg_ptr_src, first_arg, param_type);
18594 if (type_is_invalid(casted_arg->value->type))19655 if (type_is_invalid(casted_arg->value->type))
18595 return ira->codegen->invalid_instruction;19656 return ira->codegen->invalid_inst_gen;
1859619657
18597 casted_args[next_arg_index] = casted_arg;19658 casted_args[next_arg_index] = casted_arg;
18598 next_arg_index += 1;19659 next_arg_index += 1;
18599 }19660 }
18600 for (size_t call_i = 0; call_i < args_len; call_i += 1) {19661 for (size_t call_i = 0; call_i < args_len; call_i += 1) {
18601 IrInstruction *old_arg = args_ptr[call_i];19662 IrInstGen *old_arg = args_ptr[call_i];
18602 if (type_is_invalid(old_arg->value->type))19663 if (type_is_invalid(old_arg->value->type))
18603 return ira->codegen->invalid_instruction;19664 return ira->codegen->invalid_inst_gen;
1860419665
18605 IrInstruction *casted_arg;19666 IrInstGen *casted_arg;
18606 if (next_arg_index < src_param_count) {19667 if (next_arg_index < src_param_count) {
18607 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;19668 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
18608 if (type_is_invalid(param_type))19669 if (type_is_invalid(param_type))
18609 return ira->codegen->invalid_instruction;19670 return ira->codegen->invalid_inst_gen;
18610 casted_arg = ir_implicit_cast(ira, old_arg, param_type);19671 casted_arg = ir_implicit_cast(ira, old_arg, param_type);
18611 if (type_is_invalid(casted_arg->value->type))19672 if (type_is_invalid(casted_arg->value->type))
18612 return ira->codegen->invalid_instruction;19673 return ira->codegen->invalid_inst_gen;
18613 } else {19674 } else {
18614 casted_arg = old_arg;19675 casted_arg = old_arg;
18615 }19676 }
...@@ -18622,21 +19683,21 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18622,21 +19683,21 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1862219683
18623 ZigType *return_type = fn_type_id->return_type;19684 ZigType *return_type = fn_type_id->return_type;
18624 if (type_is_invalid(return_type))19685 if (type_is_invalid(return_type))
18625 return ira->codegen->invalid_instruction;19686 return ira->codegen->invalid_inst_gen;
1862619687
18627 if (fn_entry != nullptr && fn_entry->fn_inline == FnInlineAlways && modifier == CallModifierNeverInline) {19688 if (fn_entry != nullptr && fn_entry->fn_inline == FnInlineAlways && modifier == CallModifierNeverInline) {
18628 ir_add_error(ira, source_instr,19689 ir_add_error(ira, source_instr,
18629 buf_sprintf("no-inline call of inline function"));19690 buf_sprintf("no-inline call of inline function"));
18630 return ira->codegen->invalid_instruction;19691 return ira->codegen->invalid_inst_gen;
18631 }19692 }
1863219693
18633 IrInstruction *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack,19694 IrInstGen *casted_new_stack = analyze_casted_new_stack(ira, source_instr, new_stack, new_stack_src,
18634 is_async_call_builtin, fn_entry);19695 is_async_call_builtin, fn_entry);
18635 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))19696 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type))
18636 return ira->codegen->invalid_instruction;19697 return ira->codegen->invalid_inst_gen;
1863719698
18638 if (modifier == CallModifierAsync) {19699 if (modifier == CallModifierAsync) {
18639 IrInstruction *result = ir_analyze_async_call(ira, source_instr, fn_entry, fn_type, fn_ref,19700 IrInstGen *result = ir_analyze_async_call(ira, source_instr, fn_entry, fn_type, fn_ref,
18640 casted_args, call_param_count, casted_new_stack, is_async_call_builtin, ret_ptr, call_result_loc);19701 casted_args, call_param_count, casted_new_stack, is_async_call_builtin, ret_ptr, call_result_loc);
18641 return ir_finish_anal(ira, result);19702 return ir_finish_anal(ira, result);
18642 }19703 }
...@@ -18645,16 +19706,16 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18645,16 +19706,16 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18645 parent_fn_entry->inferred_async_node == nullptr &&19706 parent_fn_entry->inferred_async_node == nullptr &&
18646 modifier != CallModifierNoAsync)19707 modifier != CallModifierNoAsync)
18647 {19708 {
18648 parent_fn_entry->inferred_async_node = fn_ref->source_node;19709 parent_fn_entry->inferred_async_node = fn_ref->base.source_node;
18649 parent_fn_entry->inferred_async_fn = fn_entry;19710 parent_fn_entry->inferred_async_fn = fn_entry;
18650 }19711 }
1865119712
18652 IrInstruction *result_loc;19713 IrInstGen *result_loc;
18653 if (handle_is_ptr(return_type)) {19714 if (handle_is_ptr(return_type)) {
18654 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,19715 result_loc = ir_resolve_result(ira, source_instr, call_result_loc,
18655 return_type, nullptr, true, true, false);19716 return_type, nullptr, true, false);
18656 if (result_loc != nullptr) {19717 if (result_loc != nullptr) {
18657 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {19718 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
18658 return result_loc;19719 return result_loc;
18659 }19720 }
18660 ZigType *res_child_type = result_loc->value->type->data.pointer.child_type;19721 ZigType *res_child_type = result_loc->value->type->data.pointer.child_type;
...@@ -18670,12 +19731,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18670,12 +19731,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18670 result_loc = get_async_call_result_loc(ira, source_instr, return_type, is_async_call_builtin,19731 result_loc = get_async_call_result_loc(ira, source_instr, return_type, is_async_call_builtin,
18671 args_ptr, args_len, ret_ptr);19732 args_ptr, args_len, ret_ptr);
18672 if (result_loc != nullptr && type_is_invalid(result_loc->value->type))19733 if (result_loc != nullptr && type_is_invalid(result_loc->value->type))
18673 return ira->codegen->invalid_instruction;19734 return ira->codegen->invalid_inst_gen;
18674 } else {19735 } else {
18675 result_loc = nullptr;19736 result_loc = nullptr;
18676 }19737 }
1867719738
18678 IrInstructionCallGen *new_call_instruction = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref,19739 IrInstGenCall *new_call_instruction = ir_build_call_gen(ira, source_instr, fn_entry, fn_ref,
18679 call_param_count, casted_args, modifier, casted_new_stack,19740 call_param_count, casted_args, modifier, casted_new_stack,
18680 is_async_call_builtin, result_loc, return_type);19741 is_async_call_builtin, result_loc, return_type);
18681 if (get_scope_typeof(source_instr->scope) == nullptr) {19742 if (get_scope_typeof(source_instr->scope) == nullptr) {
...@@ -18684,62 +19745,65 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i...@@ -18684,62 +19745,65 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
18684 return ir_finish_anal(ira, &new_call_instruction->base);19745 return ir_finish_anal(ira, &new_call_instruction->base);
18685}19746}
1868619747
18687static IrInstruction *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstructionCallSrc *call_instruction,19748static IrInstGen *ir_analyze_fn_call_src(IrAnalyze *ira, IrInstSrcCall *call_instruction,
18688 ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref,19749 ZigFn *fn_entry, ZigType *fn_type, IrInstGen *fn_ref,
18689 IrInstruction *first_arg_ptr, CallModifier modifier)19750 IrInstGen *first_arg_ptr, IrInst *first_arg_ptr_src, CallModifier modifier)
18690{19751{
18691 IrInstruction *new_stack = nullptr;19752 IrInstGen *new_stack = nullptr;
19753 IrInst *new_stack_src = nullptr;
18692 if (call_instruction->new_stack) {19754 if (call_instruction->new_stack) {
18693 new_stack = call_instruction->new_stack->child;19755 new_stack = call_instruction->new_stack->child;
18694 if (type_is_invalid(new_stack->value->type))19756 if (type_is_invalid(new_stack->value->type))
18695 return ira->codegen->invalid_instruction;19757 return ira->codegen->invalid_inst_gen;
19758 new_stack_src = &call_instruction->new_stack->base;
18696 }19759 }
18697 IrInstruction **args_ptr = allocate<IrInstruction *>(call_instruction->arg_count, "IrInstruction *");19760 IrInstGen **args_ptr = allocate<IrInstGen *>(call_instruction->arg_count, "IrInstGen *");
18698 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {19761 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
18699 args_ptr[i] = call_instruction->args[i]->child;19762 args_ptr[i] = call_instruction->args[i]->child;
18700 if (type_is_invalid(args_ptr[i]->value->type))19763 if (type_is_invalid(args_ptr[i]->value->type))
18701 return ira->codegen->invalid_instruction;19764 return ira->codegen->invalid_inst_gen;
18702 }19765 }
18703 IrInstruction *ret_ptr = nullptr;19766 IrInstGen *ret_ptr = nullptr;
18704 if (call_instruction->ret_ptr != nullptr) {19767 if (call_instruction->ret_ptr != nullptr) {
18705 ret_ptr = call_instruction->ret_ptr->child;19768 ret_ptr = call_instruction->ret_ptr->child;
18706 if (type_is_invalid(ret_ptr->value->type))19769 if (type_is_invalid(ret_ptr->value->type))
18707 return ira->codegen->invalid_instruction;19770 return ira->codegen->invalid_inst_gen;
18708 }19771 }
18709 IrInstruction *result = ir_analyze_fn_call(ira, &call_instruction->base, fn_entry, fn_type, fn_ref,19772 IrInstGen *result = ir_analyze_fn_call(ira, &call_instruction->base.base, fn_entry, fn_type, fn_ref,
18710 first_arg_ptr, modifier, new_stack, call_instruction->is_async_call_builtin,19773 first_arg_ptr, first_arg_ptr_src, modifier, new_stack, new_stack_src,
18711 args_ptr, call_instruction->arg_count, ret_ptr, call_instruction->result_loc);19774 call_instruction->is_async_call_builtin, args_ptr, call_instruction->arg_count, ret_ptr,
18712 deallocate(args_ptr, call_instruction->arg_count, "IrInstruction *");19775 call_instruction->result_loc);
19776 deallocate(args_ptr, call_instruction->arg_count, "IrInstGen *");
18713 return result;19777 return result;
18714}19778}
1871519779
18716static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *source_instr,19780static IrInstGen *ir_analyze_call_extra(IrAnalyze *ira, IrInst* source_instr,
18717 IrInstruction *pass1_options, IrInstruction *pass1_fn_ref, IrInstruction **args_ptr, size_t args_len,19781 IrInstSrc *pass1_options, IrInstSrc *pass1_fn_ref, IrInstGen **args_ptr, size_t args_len,
18718 ResultLoc *result_loc)19782 ResultLoc *result_loc)
18719{19783{
18720 IrInstruction *options = pass1_options->child;19784 IrInstGen *options = pass1_options->child;
18721 if (type_is_invalid(options->value->type))19785 if (type_is_invalid(options->value->type))
18722 return ira->codegen->invalid_instruction;19786 return ira->codegen->invalid_inst_gen;
1872319787
18724 IrInstruction *fn_ref = pass1_fn_ref->child;19788 IrInstGen *fn_ref = pass1_fn_ref->child;
18725 if (type_is_invalid(fn_ref->value->type))19789 if (type_is_invalid(fn_ref->value->type))
18726 return ira->codegen->invalid_instruction;19790 return ira->codegen->invalid_inst_gen;
1872719791
18728 TypeStructField *modifier_field = find_struct_type_field(options->value->type, buf_create_from_str("modifier"));19792 TypeStructField *modifier_field = find_struct_type_field(options->value->type, buf_create_from_str("modifier"));
18729 ir_assert(modifier_field != nullptr, source_instr);19793 ir_assert(modifier_field != nullptr, source_instr);
18730 IrInstruction *modifier_inst = ir_analyze_struct_value_field_value(ira, source_instr, options, modifier_field);19794 IrInstGen *modifier_inst = ir_analyze_struct_value_field_value(ira, source_instr, options, modifier_field);
18731 ZigValue *modifier_val = ir_resolve_const(ira, modifier_inst, UndefBad);19795 ZigValue *modifier_val = ir_resolve_const(ira, modifier_inst, UndefBad);
18732 if (modifier_val == nullptr)19796 if (modifier_val == nullptr)
18733 return ira->codegen->invalid_instruction;19797 return ira->codegen->invalid_inst_gen;
18734 CallModifier modifier = (CallModifier)bigint_as_u32(&modifier_val->data.x_enum_tag);19798 CallModifier modifier = (CallModifier)bigint_as_u32(&modifier_val->data.x_enum_tag);
1873519799
18736 if (ir_should_inline(ira->new_irb.exec, source_instr->scope)) {19800 if (ir_should_inline(ira->old_irb.exec, source_instr->scope)) {
18737 switch (modifier) {19801 switch (modifier) {
18738 case CallModifierBuiltin:19802 case CallModifierBuiltin:
18739 zig_unreachable();19803 zig_unreachable();
18740 case CallModifierAsync:19804 case CallModifierAsync:
18741 ir_add_error(ira, source_instr, buf_sprintf("TODO: comptime @call with async modifier"));19805 ir_add_error(ira, source_instr, buf_sprintf("TODO: comptime @call with async modifier"));
18742 return ira->codegen->invalid_instruction;19806 return ira->codegen->invalid_inst_gen;
18743 case CallModifierCompileTime:19807 case CallModifierCompileTime:
18744 case CallModifierNone:19808 case CallModifierNone:
18745 case CallModifierAlwaysInline:19809 case CallModifierAlwaysInline:
...@@ -18750,23 +19814,25 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc...@@ -18750,23 +19814,25 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc
18750 case CallModifierNeverInline:19814 case CallModifierNeverInline:
18751 ir_add_error(ira, source_instr,19815 ir_add_error(ira, source_instr,
18752 buf_sprintf("unable to perform 'never_inline' call at compile-time"));19816 buf_sprintf("unable to perform 'never_inline' call at compile-time"));
18753 return ira->codegen->invalid_instruction;19817 return ira->codegen->invalid_inst_gen;
18754 case CallModifierNeverTail:19818 case CallModifierNeverTail:
18755 ir_add_error(ira, source_instr,19819 ir_add_error(ira, source_instr,
18756 buf_sprintf("unable to perform 'never_tail' call at compile-time"));19820 buf_sprintf("unable to perform 'never_tail' call at compile-time"));
18757 return ira->codegen->invalid_instruction;19821 return ira->codegen->invalid_inst_gen;
18758 }19822 }
18759 }19823 }
1876019824
18761 IrInstruction *first_arg_ptr = nullptr;19825 IrInstGen *first_arg_ptr = nullptr;
19826 IrInst *first_arg_ptr_src = nullptr;
18762 ZigFn *fn = nullptr;19827 ZigFn *fn = nullptr;
18763 if (instr_is_comptime(fn_ref)) {19828 if (instr_is_comptime(fn_ref)) {
18764 if (fn_ref->value->type->id == ZigTypeIdBoundFn) {19829 if (fn_ref->value->type->id == ZigTypeIdBoundFn) {
18765 assert(fn_ref->value->special == ConstValSpecialStatic);19830 assert(fn_ref->value->special == ConstValSpecialStatic);
18766 fn = fn_ref->value->data.x_bound_fn.fn;19831 fn = fn_ref->value->data.x_bound_fn.fn;
18767 first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;19832 first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;
19833 first_arg_ptr_src = fn_ref->value->data.x_bound_fn.first_arg_src;
18768 if (type_is_invalid(first_arg_ptr->value->type))19834 if (type_is_invalid(first_arg_ptr->value->type))
18769 return ira->codegen->invalid_instruction;19835 return ira->codegen->invalid_inst_gen;
18770 } else {19836 } else {
18771 fn = ir_resolve_fn(ira, fn_ref);19837 fn = ir_resolve_fn(ira, fn_ref);
18772 }19838 }
...@@ -18778,9 +19844,9 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc...@@ -18778,9 +19844,9 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc
18778 case CallModifierAlwaysInline:19844 case CallModifierAlwaysInline:
18779 case CallModifierAsync:19845 case CallModifierAsync:
18780 if (fn == nullptr) {19846 if (fn == nullptr) {
18781 ir_add_error(ira, modifier_inst,19847 ir_add_error(ira, &modifier_inst->base,
18782 buf_sprintf("the specified modifier requires a comptime-known function"));19848 buf_sprintf("the specified modifier requires a comptime-known function"));
18783 return ira->codegen->invalid_instruction;19849 return ira->codegen->invalid_inst_gen;
18784 }19850 }
18785 default:19851 default:
18786 break;19852 break;
...@@ -18790,120 +19856,121 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc...@@ -18790,120 +19856,121 @@ static IrInstruction *ir_analyze_call_extra(IrAnalyze *ira, IrInstruction *sourc
1879019856
18791 TypeStructField *stack_field = find_struct_type_field(options->value->type, buf_create_from_str("stack"));19857 TypeStructField *stack_field = find_struct_type_field(options->value->type, buf_create_from_str("stack"));
18792 ir_assert(stack_field != nullptr, source_instr);19858 ir_assert(stack_field != nullptr, source_instr);
18793 IrInstruction *opt_stack = ir_analyze_struct_value_field_value(ira, source_instr, options, stack_field);19859 IrInstGen *opt_stack = ir_analyze_struct_value_field_value(ira, source_instr, options, stack_field);
18794 if (type_is_invalid(opt_stack->value->type))19860 if (type_is_invalid(opt_stack->value->type))
18795 return ira->codegen->invalid_instruction;19861 return ira->codegen->invalid_inst_gen;
1879619862
18797 IrInstruction *stack_is_non_null_inst = ir_analyze_test_non_null(ira, source_instr, opt_stack);19863 IrInstGen *stack_is_non_null_inst = ir_analyze_test_non_null(ira, source_instr, opt_stack);
18798 bool stack_is_non_null;19864 bool stack_is_non_null;
18799 if (!ir_resolve_bool(ira, stack_is_non_null_inst, &stack_is_non_null))19865 if (!ir_resolve_bool(ira, stack_is_non_null_inst, &stack_is_non_null))
18800 return ira->codegen->invalid_instruction;19866 return ira->codegen->invalid_inst_gen;
1880119867
18802 IrInstruction *stack = nullptr;19868 IrInstGen *stack = nullptr;
18803 if (stack_is_non_null) {19869 if (stack_is_non_null) {
18804 stack = ir_analyze_optional_value_payload_value(ira, source_instr, opt_stack, false);19870 stack = ir_analyze_optional_value_payload_value(ira, source_instr, opt_stack, false);
18805 if (type_is_invalid(stack->value->type))19871 if (type_is_invalid(stack->value->type))
18806 return ira->codegen->invalid_instruction;19872 return ira->codegen->invalid_inst_gen;
18807 }19873 }
1880819874
18809 return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr,19875 return ir_analyze_fn_call(ira, source_instr, fn, fn_type, fn_ref, first_arg_ptr, first_arg_ptr_src,
18810 modifier, stack, false, args_ptr, args_len, nullptr, result_loc);19876 modifier, stack, &stack->base, false, args_ptr, args_len, nullptr, result_loc);
18811}19877}
1881219878
18813static IrInstruction *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstructionCallExtra *instruction) {19879static IrInstGen *ir_analyze_instruction_call_extra(IrAnalyze *ira, IrInstSrcCallExtra *instruction) {
18814 IrInstruction *args = instruction->args->child;19880 IrInstGen *args = instruction->args->child;
18815 ZigType *args_type = args->value->type;19881 ZigType *args_type = args->value->type;
18816 if (type_is_invalid(args_type))19882 if (type_is_invalid(args_type))
18817 return ira->codegen->invalid_instruction;19883 return ira->codegen->invalid_inst_gen;
1881819884
18819 if (args_type->id != ZigTypeIdStruct) {19885 if (args_type->id != ZigTypeIdStruct) {
18820 ir_add_error(ira, args,19886 ir_add_error(ira, &args->base,
18821 buf_sprintf("expected tuple or struct, found '%s'", buf_ptr(&args_type->name)));19887 buf_sprintf("expected tuple or struct, found '%s'", buf_ptr(&args_type->name)));
18822 return ira->codegen->invalid_instruction;19888 return ira->codegen->invalid_inst_gen;
18823 }19889 }
1882419890
18825 IrInstruction **args_ptr = nullptr;19891 IrInstGen **args_ptr = nullptr;
18826 size_t args_len = 0;19892 size_t args_len = 0;
1882719893
18828 if (is_tuple(args_type)) {19894 if (is_tuple(args_type)) {
18829 args_len = args_type->data.structure.src_field_count;19895 args_len = args_type->data.structure.src_field_count;
18830 args_ptr = allocate<IrInstruction *>(args_len, "IrInstruction *");19896 args_ptr = allocate<IrInstGen *>(args_len, "IrInstGen *");
18831 for (size_t i = 0; i < args_len; i += 1) {19897 for (size_t i = 0; i < args_len; i += 1) {
18832 TypeStructField *arg_field = args_type->data.structure.fields[i];19898 TypeStructField *arg_field = args_type->data.structure.fields[i];
18833 args_ptr[i] = ir_analyze_struct_value_field_value(ira, &instruction->base, args, arg_field);19899 args_ptr[i] = ir_analyze_struct_value_field_value(ira, &instruction->base.base, args, arg_field);
18834 if (type_is_invalid(args_ptr[i]->value->type))19900 if (type_is_invalid(args_ptr[i]->value->type))
18835 return ira->codegen->invalid_instruction;19901 return ira->codegen->invalid_inst_gen;
18836 }19902 }
18837 } else {19903 } else {
18838 ir_add_error(ira, args, buf_sprintf("TODO: struct args"));19904 ir_add_error(ira, &args->base, buf_sprintf("TODO: struct args"));
18839 return ira->codegen->invalid_instruction;19905 return ira->codegen->invalid_inst_gen;
18840 }19906 }
18841 IrInstruction *result = ir_analyze_call_extra(ira, &instruction->base, instruction->options,19907 IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options,
18842 instruction->fn_ref, args_ptr, args_len, instruction->result_loc);19908 instruction->fn_ref, args_ptr, args_len, instruction->result_loc);
18843 deallocate(args_ptr, args_len, "IrInstruction *");19909 deallocate(args_ptr, args_len, "IrInstGen *");
18844 return result;19910 return result;
18845}19911}
1884619912
18847static IrInstruction *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstructionCallSrcArgs *instruction) {19913static IrInstGen *ir_analyze_instruction_call_args(IrAnalyze *ira, IrInstSrcCallArgs *instruction) {
18848 IrInstruction **args_ptr = allocate<IrInstruction *>(instruction->args_len, "IrInstruction *");19914 IrInstGen **args_ptr = allocate<IrInstGen *>(instruction->args_len, "IrInstGen *");
18849 for (size_t i = 0; i < instruction->args_len; i += 1) {19915 for (size_t i = 0; i < instruction->args_len; i += 1) {
18850 args_ptr[i] = instruction->args_ptr[i]->child;19916 args_ptr[i] = instruction->args_ptr[i]->child;
18851 if (type_is_invalid(args_ptr[i]->value->type))19917 if (type_is_invalid(args_ptr[i]->value->type))
18852 return ira->codegen->invalid_instruction;19918 return ira->codegen->invalid_inst_gen;
18853 }19919 }
1885419920
18855 IrInstruction *result = ir_analyze_call_extra(ira, &instruction->base, instruction->options,19921 IrInstGen *result = ir_analyze_call_extra(ira, &instruction->base.base, instruction->options,
18856 instruction->fn_ref, args_ptr, instruction->args_len, instruction->result_loc);19922 instruction->fn_ref, args_ptr, instruction->args_len, instruction->result_loc);
18857 deallocate(args_ptr, instruction->args_len, "IrInstruction *");19923 deallocate(args_ptr, instruction->args_len, "IrInstGen *");
18858 return result;19924 return result;
18859}19925}
1886019926
18861static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction) {19927static IrInstGen *ir_analyze_instruction_call(IrAnalyze *ira, IrInstSrcCall *call_instruction) {
18862 IrInstruction *fn_ref = call_instruction->fn_ref->child;19928 IrInstGen *fn_ref = call_instruction->fn_ref->child;
18863 if (type_is_invalid(fn_ref->value->type))19929 if (type_is_invalid(fn_ref->value->type))
18864 return ira->codegen->invalid_instruction;19930 return ira->codegen->invalid_inst_gen;
1886519931
18866 bool is_comptime = (call_instruction->modifier == CallModifierCompileTime) ||19932 bool is_comptime = (call_instruction->modifier == CallModifierCompileTime) ||
18867 ir_should_inline(ira->new_irb.exec, call_instruction->base.scope);19933 ir_should_inline(ira->old_irb.exec, call_instruction->base.base.scope);
18868 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;19934 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;
1886919935
18870 if (is_comptime || instr_is_comptime(fn_ref)) {19936 if (is_comptime || instr_is_comptime(fn_ref)) {
18871 if (fn_ref->value->type->id == ZigTypeIdMetaType) {19937 if (fn_ref->value->type->id == ZigTypeIdMetaType) {
18872 ZigType *ty = ir_resolve_type(ira, fn_ref);19938 ZigType *ty = ir_resolve_type(ira, fn_ref);
18873 if (ty == nullptr)19939 if (ty == nullptr)
18874 return ira->codegen->invalid_instruction;19940 return ira->codegen->invalid_inst_gen;
18875 ErrorMsg *msg = ir_add_error_node(ira, fn_ref->source_node,19941 ErrorMsg *msg = ir_add_error(ira, &fn_ref->base,
18876 buf_sprintf("type '%s' not a function", buf_ptr(&ty->name)));19942 buf_sprintf("type '%s' not a function", buf_ptr(&ty->name)));
18877 add_error_note(ira->codegen, msg, call_instruction->base.source_node,19943 add_error_note(ira->codegen, msg, call_instruction->base.base.source_node,
18878 buf_sprintf("use @as builtin for type coercion"));19944 buf_sprintf("use @as builtin for type coercion"));
18879 return ira->codegen->invalid_instruction;19945 return ira->codegen->invalid_inst_gen;
18880 } else if (fn_ref->value->type->id == ZigTypeIdFn) {19946 } else if (fn_ref->value->type->id == ZigTypeIdFn) {
18881 ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref);19947 ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref);
18882 ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value->type;19948 ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value->type;
18883 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;19949 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;
18884 return ir_analyze_fn_call_src(ira, call_instruction, fn_table_entry, fn_type,19950 return ir_analyze_fn_call_src(ira, call_instruction, fn_table_entry, fn_type,
18885 fn_ref, nullptr, modifier);19951 fn_ref, nullptr, nullptr, modifier);
18886 } else if (fn_ref->value->type->id == ZigTypeIdBoundFn) {19952 } else if (fn_ref->value->type->id == ZigTypeIdBoundFn) {
18887 assert(fn_ref->value->special == ConstValSpecialStatic);19953 assert(fn_ref->value->special == ConstValSpecialStatic);
18888 ZigFn *fn_table_entry = fn_ref->value->data.x_bound_fn.fn;19954 ZigFn *fn_table_entry = fn_ref->value->data.x_bound_fn.fn;
18889 IrInstruction *first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;19955 IrInstGen *first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg;
19956 IrInst *first_arg_ptr_src = fn_ref->value->data.x_bound_fn.first_arg_src;
18890 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;19957 CallModifier modifier = is_comptime ? CallModifierCompileTime : call_instruction->modifier;
18891 return ir_analyze_fn_call_src(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,19958 return ir_analyze_fn_call_src(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry,
18892 fn_ref, first_arg_ptr, modifier);19959 fn_ref, first_arg_ptr, first_arg_ptr_src, modifier);
18893 } else {19960 } else {
18894 ir_add_error_node(ira, fn_ref->source_node,19961 ir_add_error(ira, &fn_ref->base,
18895 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));19962 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));
18896 return ira->codegen->invalid_instruction;19963 return ira->codegen->invalid_inst_gen;
18897 }19964 }
18898 }19965 }
1889919966
18900 if (fn_ref->value->type->id == ZigTypeIdFn) {19967 if (fn_ref->value->type->id == ZigTypeIdFn) {
18901 return ir_analyze_fn_call_src(ira, call_instruction, nullptr, fn_ref->value->type,19968 return ir_analyze_fn_call_src(ira, call_instruction, nullptr, fn_ref->value->type,
18902 fn_ref, nullptr, modifier);19969 fn_ref, nullptr, nullptr, modifier);
18903 } else {19970 } else {
18904 ir_add_error_node(ira, fn_ref->source_node,19971 ir_add_error(ira, &fn_ref->base,
18905 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));19972 buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name)));
18906 return ira->codegen->invalid_instruction;19973 return ira->codegen->invalid_inst_gen;
18907 }19974 }
18908}19975}
1890919976
...@@ -18992,8 +20059,8 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source...@@ -18992,8 +20059,8 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source
18992 zig_unreachable();20059 zig_unreachable();
18993}20060}
1899420061
18995static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp *instruction) {20062static IrInstGen *ir_analyze_optional_type(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
18996 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);20063 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
18997 result->value->special = ConstValSpecialLazy;20064 result->value->special = ConstValSpecialLazy;
1899820065
18999 LazyValueOptType *lazy_opt_type = allocate<LazyValueOptType>(1, "LazyValueOptType");20066 LazyValueOptType *lazy_opt_type = allocate<LazyValueOptType>(1, "LazyValueOptType");
...@@ -19003,12 +20070,12 @@ static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp...@@ -19003,12 +20070,12 @@ static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp
1900320070
19004 lazy_opt_type->payload_type = instruction->value->child;20071 lazy_opt_type->payload_type = instruction->value->child;
19005 if (ir_resolve_type_lazy(ira, lazy_opt_type->payload_type) == nullptr)20072 if (ir_resolve_type_lazy(ira, lazy_opt_type->payload_type) == nullptr)
19006 return ira->codegen->invalid_instruction;20073 return ira->codegen->invalid_inst_gen;
1900720074
19008 return result;20075 return result;
19009}20076}
1901020077
19011static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *scalar_type,20078static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInst* source_instr, ZigType *scalar_type,
19012 ZigValue *operand_val, ZigValue *scalar_out_val, bool is_wrap_op)20079 ZigValue *operand_val, ZigValue *scalar_out_val, bool is_wrap_op)
19013{20080{
19014 bool is_float = (scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat);20081 bool is_float = (scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat);
...@@ -19043,19 +20110,19 @@ static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_i...@@ -19043,19 +20110,19 @@ static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_i
19043 return nullptr;20110 return nullptr;
19044}20111}
1904520112
19046static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *instruction) {20113static IrInstGen *ir_analyze_negation(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
19047 IrInstruction *value = instruction->value->child;20114 IrInstGen *value = instruction->value->child;
19048 ZigType *expr_type = value->value->type;20115 ZigType *expr_type = value->value->type;
19049 if (type_is_invalid(expr_type))20116 if (type_is_invalid(expr_type))
19050 return ira->codegen->invalid_instruction;20117 return ira->codegen->invalid_inst_gen;
1905120118
19052 if (!(expr_type->id == ZigTypeIdInt || expr_type->id == ZigTypeIdComptimeInt ||20119 if (!(expr_type->id == ZigTypeIdInt || expr_type->id == ZigTypeIdComptimeInt ||
19053 expr_type->id == ZigTypeIdFloat || expr_type->id == ZigTypeIdComptimeFloat ||20120 expr_type->id == ZigTypeIdFloat || expr_type->id == ZigTypeIdComptimeFloat ||
19054 expr_type->id == ZigTypeIdVector))20121 expr_type->id == ZigTypeIdVector))
19055 {20122 {
19056 ir_add_error(ira, &instruction->base,20123 ir_add_error(ira, &instruction->base.base,
19057 buf_sprintf("negation of type '%s'", buf_ptr(&expr_type->name)));20124 buf_sprintf("negation of type '%s'", buf_ptr(&expr_type->name)));
19058 return ira->codegen->invalid_instruction;20125 return ira->codegen->invalid_inst_gen;
19059 }20126 }
1906020127
19061 bool is_wrap_op = (instruction->op_id == IrUnOpNegationWrap);20128 bool is_wrap_op = (instruction->op_id == IrUnOpNegationWrap);
...@@ -19065,9 +20132,9 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins...@@ -19065,9 +20132,9 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins
19065 if (instr_is_comptime(value)) {20132 if (instr_is_comptime(value)) {
19066 ZigValue *operand_val = ir_resolve_const(ira, value, UndefBad);20133 ZigValue *operand_val = ir_resolve_const(ira, value, UndefBad);
19067 if (!operand_val)20134 if (!operand_val)
19068 return ira->codegen->invalid_instruction;20135 return ira->codegen->invalid_inst_gen;
1906920136
19070 IrInstruction *result_instruction = ir_const(ira, &instruction->base, expr_type);20137 IrInstGen *result_instruction = ir_const(ira, &instruction->base.base, expr_type);
19071 ZigValue *out_val = result_instruction->value;20138 ZigValue *out_val = result_instruction->value;
19072 if (expr_type->id == ZigTypeIdVector) {20139 if (expr_type->id == ZigTypeIdVector) {
19073 expand_undef_array(ira->codegen, operand_val);20140 expand_undef_array(ira->codegen, operand_val);
...@@ -19079,63 +20146,60 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins...@@ -19079,63 +20146,60 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins
19079 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];20146 ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i];
19080 assert(scalar_operand_val->type == scalar_type);20147 assert(scalar_operand_val->type == scalar_type);
19081 assert(scalar_out_val->type == scalar_type);20148 assert(scalar_out_val->type == scalar_type);
19082 ErrorMsg *msg = ir_eval_negation_scalar(ira, &instruction->base, scalar_type,20149 ErrorMsg *msg = ir_eval_negation_scalar(ira, &instruction->base.base, scalar_type,
19083 scalar_operand_val, scalar_out_val, is_wrap_op);20150 scalar_operand_val, scalar_out_val, is_wrap_op);
19084 if (msg != nullptr) {20151 if (msg != nullptr) {
19085 add_error_note(ira->codegen, msg, instruction->base.source_node,20152 add_error_note(ira->codegen, msg, instruction->base.base.source_node,
19086 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));20153 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));
19087 return ira->codegen->invalid_instruction;20154 return ira->codegen->invalid_inst_gen;
19088 }20155 }
19089 }20156 }
19090 out_val->type = expr_type;20157 out_val->type = expr_type;
19091 out_val->special = ConstValSpecialStatic;20158 out_val->special = ConstValSpecialStatic;
19092 } else {20159 } else {
19093 if (ir_eval_negation_scalar(ira, &instruction->base, scalar_type, operand_val, out_val,20160 if (ir_eval_negation_scalar(ira, &instruction->base.base, scalar_type, operand_val, out_val,
19094 is_wrap_op) != nullptr)20161 is_wrap_op) != nullptr)
19095 {20162 {
19096 return ira->codegen->invalid_instruction;20163 return ira->codegen->invalid_inst_gen;
19097 }20164 }
19098 }20165 }
19099 return result_instruction;20166 return result_instruction;
19100 }20167 }
1910120168
19102 IrInstruction *result = ir_build_un_op(&ira->new_irb,20169 if (is_wrap_op) {
19103 instruction->base.scope, instruction->base.source_node,20170 return ir_build_negation_wrapping(ira, &instruction->base.base, value, expr_type);
19104 instruction->op_id, value);20171 } else {
19105 result->value->type = expr_type;20172 return ir_build_negation(ira, &instruction->base.base, value, expr_type);
19106 return result;20173 }
19107}20174}
1910820175
19109static IrInstruction *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) {20176static IrInstGen *ir_analyze_bin_not(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
19110 IrInstruction *value = instruction->value->child;20177 IrInstGen *value = instruction->value->child;
19111 ZigType *expr_type = value->value->type;20178 ZigType *expr_type = value->value->type;
19112 if (type_is_invalid(expr_type))20179 if (type_is_invalid(expr_type))
19113 return ira->codegen->invalid_instruction;20180 return ira->codegen->invalid_inst_gen;
1911420181
19115 if (expr_type->id == ZigTypeIdInt) {20182 if (expr_type->id == ZigTypeIdInt) {
19116 if (instr_is_comptime(value)) {20183 if (instr_is_comptime(value)) {
19117 ZigValue *target_const_val = ir_resolve_const(ira, value, UndefBad);20184 ZigValue *target_const_val = ir_resolve_const(ira, value, UndefBad);
19118 if (target_const_val == nullptr)20185 if (target_const_val == nullptr)
19119 return ira->codegen->invalid_instruction;20186 return ira->codegen->invalid_inst_gen;
1912020187
19121 IrInstruction *result = ir_const(ira, &instruction->base, expr_type);20188 IrInstGen *result = ir_const(ira, &instruction->base.base, expr_type);
19122 bigint_not(&result->value->data.x_bigint, &target_const_val->data.x_bigint,20189 bigint_not(&result->value->data.x_bigint, &target_const_val->data.x_bigint,
19123 expr_type->data.integral.bit_count, expr_type->data.integral.is_signed);20190 expr_type->data.integral.bit_count, expr_type->data.integral.is_signed);
19124 return result;20191 return result;
19125 }20192 }
1912620193
19127 IrInstruction *result = ir_build_un_op(&ira->new_irb, instruction->base.scope,20194 return ir_build_binary_not(ira, &instruction->base.base, value, expr_type);
19128 instruction->base.source_node, IrUnOpBinNot, value);
19129 result->value->type = expr_type;
19130 return result;
19131 }20195 }
1913220196
19133 ir_add_error(ira, &instruction->base,20197 ir_add_error(ira, &instruction->base.base,
19134 buf_sprintf("unable to perform binary not operation on type '%s'", buf_ptr(&expr_type->name)));20198 buf_sprintf("unable to perform binary not operation on type '%s'", buf_ptr(&expr_type->name)));
19135 return ira->codegen->invalid_instruction;20199 return ira->codegen->invalid_inst_gen;
19136}20200}
1913720201
19138static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructionUnOp *instruction) {20202static IrInstGen *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstSrcUnOp *instruction) {
19139 IrUnOp op_id = instruction->op_id;20203 IrUnOp op_id = instruction->op_id;
19140 switch (op_id) {20204 switch (op_id) {
19141 case IrUnOpInvalid:20205 case IrUnOpInvalid:
...@@ -19146,26 +20210,26 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction...@@ -19146,26 +20210,26 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction
19146 case IrUnOpNegationWrap:20210 case IrUnOpNegationWrap:
19147 return ir_analyze_negation(ira, instruction);20211 return ir_analyze_negation(ira, instruction);
19148 case IrUnOpDereference: {20212 case IrUnOpDereference: {
19149 IrInstruction *ptr = instruction->value->child;20213 IrInstGen *ptr = instruction->value->child;
19150 if (type_is_invalid(ptr->value->type))20214 if (type_is_invalid(ptr->value->type))
19151 return ira->codegen->invalid_instruction;20215 return ira->codegen->invalid_inst_gen;
19152 ZigType *ptr_type = ptr->value->type;20216 ZigType *ptr_type = ptr->value->type;
19153 if (ptr_type->id == ZigTypeIdPointer && ptr_type->data.pointer.ptr_len == PtrLenUnknown) {20217 if (ptr_type->id == ZigTypeIdPointer && ptr_type->data.pointer.ptr_len == PtrLenUnknown) {
19154 ir_add_error_node(ira, instruction->base.source_node,20218 ir_add_error_node(ira, instruction->base.base.source_node,
19155 buf_sprintf("index syntax required for unknown-length pointer type '%s'",20219 buf_sprintf("index syntax required for unknown-length pointer type '%s'",
19156 buf_ptr(&ptr_type->name)));20220 buf_ptr(&ptr_type->name)));
19157 return ira->codegen->invalid_instruction;20221 return ira->codegen->invalid_inst_gen;
19158 }20222 }
1915920223
19160 IrInstruction *result = ir_get_deref(ira, &instruction->base, ptr, instruction->result_loc);20224 IrInstGen *result = ir_get_deref(ira, &instruction->base.base, ptr, instruction->result_loc);
19161 if (result == ira->codegen->invalid_instruction)20225 if (type_is_invalid(result->value->type))
19162 return ira->codegen->invalid_instruction;20226 return ira->codegen->invalid_inst_gen;
1916320227
19164 // If the result needs to be an lvalue, type check it20228 // If the result needs to be an lvalue, type check it
19165 if (instruction->lval == LValPtr && result->value->type->id != ZigTypeIdPointer) {20229 if (instruction->lval == LValPtr && result->value->type->id != ZigTypeIdPointer) {
19166 ir_add_error(ira, &instruction->base,20230 ir_add_error(ira, &instruction->base.base,
19167 buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value->type->name)));20231 buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value->type->name)));
19168 return ira->codegen->invalid_instruction;20232 return ira->codegen->invalid_inst_gen;
19169 }20233 }
1917020234
19171 return result;20235 return result;
...@@ -19177,42 +20241,40 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction...@@ -19177,42 +20241,40 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction
19177}20241}
1917820242
19179static void ir_push_resume(IrAnalyze *ira, IrSuspendPosition pos) {20243static void ir_push_resume(IrAnalyze *ira, IrSuspendPosition pos) {
19180 IrBasicBlock *old_bb = ira->old_irb.exec->basic_block_list.at(pos.basic_block_index);20244 IrBasicBlockSrc *old_bb = ira->old_irb.exec->basic_block_list.at(pos.basic_block_index);
19181 if (old_bb->in_resume_stack) return;20245 if (old_bb->in_resume_stack) return;
19182 ira->resume_stack.append(pos);20246 ira->resume_stack.append(pos);
19183 old_bb->in_resume_stack = true;20247 old_bb->in_resume_stack = true;
19184}20248}
1918520249
19186static void ir_push_resume_block(IrAnalyze *ira, IrBasicBlock *old_bb) {20250static void ir_push_resume_block(IrAnalyze *ira, IrBasicBlockSrc *old_bb) {
19187 if (ira->resume_stack.length != 0) {20251 if (ira->resume_stack.length != 0) {
19188 ir_push_resume(ira, {old_bb->index, 0});20252 ir_push_resume(ira, {old_bb->index, 0});
19189 }20253 }
19190}20254}
1919120255
19192static IrInstruction *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr *br_instruction) {20256static IrInstGen *ir_analyze_instruction_br(IrAnalyze *ira, IrInstSrcBr *br_instruction) {
19193 IrBasicBlock *old_dest_block = br_instruction->dest_block;20257 IrBasicBlockSrc *old_dest_block = br_instruction->dest_block;
1919420258
19195 bool is_comptime;20259 bool is_comptime;
19196 if (!ir_resolve_comptime(ira, br_instruction->is_comptime->child, &is_comptime))20260 if (!ir_resolve_comptime(ira, br_instruction->is_comptime->child, &is_comptime))
19197 return ir_unreach_error(ira);20261 return ir_unreach_error(ira);
1919820262
19199 if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr))20263 if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr))
19200 return ir_inline_bb(ira, &br_instruction->base, old_dest_block);20264 return ir_inline_bb(ira, &br_instruction->base.base, old_dest_block);
1920120265
19202 IrBasicBlock *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base);20266 IrBasicBlockGen *new_bb = ir_get_new_bb_runtime(ira, old_dest_block, &br_instruction->base.base);
19203 if (new_bb == nullptr)20267 if (new_bb == nullptr)
19204 return ir_unreach_error(ira);20268 return ir_unreach_error(ira);
1920520269
19206 ir_push_resume_block(ira, old_dest_block);20270 ir_push_resume_block(ira, old_dest_block);
1920720271
19208 IrInstruction *result = ir_build_br(&ira->new_irb,20272 IrInstGen *result = ir_build_br_gen(ira, &br_instruction->base.base, new_bb);
19209 br_instruction->base.scope, br_instruction->base.source_node, new_bb, nullptr);
19210 result->value->type = ira->codegen->builtin_types.entry_unreachable;
19211 return ir_finish_anal(ira, result);20273 return ir_finish_anal(ira, result);
19212}20274}
1921320275
19214static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) {20276static IrInstGen *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstSrcCondBr *cond_br_instruction) {
19215 IrInstruction *condition = cond_br_instruction->condition->child;20277 IrInstGen *condition = cond_br_instruction->condition->child;
19216 if (type_is_invalid(condition->value->type))20278 if (type_is_invalid(condition->value->type))
19217 return ir_unreach_error(ira);20279 return ir_unreach_error(ira);
1921820280
...@@ -19221,7 +20283,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi...@@ -19221,7 +20283,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi
19221 return ir_unreach_error(ira);20283 return ir_unreach_error(ira);
1922220284
19223 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;20285 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
19224 IrInstruction *casted_condition = ir_implicit_cast(ira, condition, bool_type);20286 IrInstGen *casted_condition = ir_implicit_cast(ira, condition, bool_type);
19225 if (type_is_invalid(casted_condition->value->type))20287 if (type_is_invalid(casted_condition->value->type))
19226 return ir_unreach_error(ira);20288 return ir_unreach_error(ira);
1922720289
...@@ -19230,67 +20292,61 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi...@@ -19230,67 +20292,61 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi
19230 if (!ir_resolve_bool(ira, casted_condition, &cond_is_true))20292 if (!ir_resolve_bool(ira, casted_condition, &cond_is_true))
19231 return ir_unreach_error(ira);20293 return ir_unreach_error(ira);
1923220294
19233 IrBasicBlock *old_dest_block = cond_is_true ?20295 IrBasicBlockSrc *old_dest_block = cond_is_true ?
19234 cond_br_instruction->then_block : cond_br_instruction->else_block;20296 cond_br_instruction->then_block : cond_br_instruction->else_block;
1923520297
19236 if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr))20298 if (is_comptime || (old_dest_block->ref_count == 1 && old_dest_block->suspend_instruction_ref == nullptr))
19237 return ir_inline_bb(ira, &cond_br_instruction->base, old_dest_block);20299 return ir_inline_bb(ira, &cond_br_instruction->base.base, old_dest_block);
1923820300
19239 IrBasicBlock *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base);20301 IrBasicBlockGen *new_dest_block = ir_get_new_bb_runtime(ira, old_dest_block, &cond_br_instruction->base.base);
19240 if (new_dest_block == nullptr)20302 if (new_dest_block == nullptr)
19241 return ir_unreach_error(ira);20303 return ir_unreach_error(ira);
1924220304
19243 ir_push_resume_block(ira, old_dest_block);20305 ir_push_resume_block(ira, old_dest_block);
1924420306
19245 IrInstruction *result = ir_build_br(&ira->new_irb,20307 IrInstGen *result = ir_build_br_gen(ira, &cond_br_instruction->base.base, new_dest_block);
19246 cond_br_instruction->base.scope, cond_br_instruction->base.source_node, new_dest_block, nullptr);
19247 result->value->type = ira->codegen->builtin_types.entry_unreachable;
19248 return ir_finish_anal(ira, result);20308 return ir_finish_anal(ira, result);
19249 }20309 }
1925020310
19251 assert(cond_br_instruction->then_block != cond_br_instruction->else_block);20311 assert(cond_br_instruction->then_block != cond_br_instruction->else_block);
19252 IrBasicBlock *new_then_block = ir_get_new_bb_runtime(ira, cond_br_instruction->then_block, &cond_br_instruction->base);20312 IrBasicBlockGen *new_then_block = ir_get_new_bb_runtime(ira, cond_br_instruction->then_block, &cond_br_instruction->base.base);
19253 if (new_then_block == nullptr)20313 if (new_then_block == nullptr)
19254 return ir_unreach_error(ira);20314 return ir_unreach_error(ira);
1925520315
19256 IrBasicBlock *new_else_block = ir_get_new_bb_runtime(ira, cond_br_instruction->else_block, &cond_br_instruction->base);20316 IrBasicBlockGen *new_else_block = ir_get_new_bb_runtime(ira, cond_br_instruction->else_block, &cond_br_instruction->base.base);
19257 if (new_else_block == nullptr)20317 if (new_else_block == nullptr)
19258 return ir_unreach_error(ira);20318 return ir_unreach_error(ira);
1925920319
19260 ir_push_resume_block(ira, cond_br_instruction->else_block);20320 ir_push_resume_block(ira, cond_br_instruction->else_block);
19261 ir_push_resume_block(ira, cond_br_instruction->then_block);20321 ir_push_resume_block(ira, cond_br_instruction->then_block);
1926220322
19263 IrInstruction *result = ir_build_cond_br(&ira->new_irb,20323 IrInstGen *result = ir_build_cond_br_gen(ira, &cond_br_instruction->base.base,
19264 cond_br_instruction->base.scope, cond_br_instruction->base.source_node,20324 casted_condition, new_then_block, new_else_block);
19265 casted_condition, new_then_block, new_else_block, nullptr);
19266 result->value->type = ira->codegen->builtin_types.entry_unreachable;
19267 return ir_finish_anal(ira, result);20325 return ir_finish_anal(ira, result);
19268}20326}
1926920327
19270static IrInstruction *ir_analyze_instruction_unreachable(IrAnalyze *ira,20328static IrInstGen *ir_analyze_instruction_unreachable(IrAnalyze *ira,
19271 IrInstructionUnreachable *unreachable_instruction)20329 IrInstSrcUnreachable *unreachable_instruction)
19272{20330{
19273 IrInstruction *result = ir_build_unreachable(&ira->new_irb,20331 IrInstGen *result = ir_build_unreachable_gen(ira, &unreachable_instruction->base.base);
19274 unreachable_instruction->base.scope, unreachable_instruction->base.source_node);
19275 result->value->type = ira->codegen->builtin_types.entry_unreachable;
19276 return ir_finish_anal(ira, result);20332 return ir_finish_anal(ira, result);
19277}20333}
1927820334
19279static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi_instruction) {20335static IrInstGen *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstSrcPhi *phi_instruction) {
19280 Error err;20336 Error err;
1928120337
19282 if (ira->const_predecessor_bb) {20338 if (ira->const_predecessor_bb) {
19283 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {20339 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {
19284 IrBasicBlock *predecessor = phi_instruction->incoming_blocks[i];20340 IrBasicBlockSrc *predecessor = phi_instruction->incoming_blocks[i];
19285 if (predecessor != ira->const_predecessor_bb)20341 if (predecessor != ira->const_predecessor_bb)
19286 continue;20342 continue;
19287 IrInstruction *value = phi_instruction->incoming_values[i]->child;20343 IrInstGen *value = phi_instruction->incoming_values[i]->child;
19288 assert(value->value->type);20344 assert(value->value->type);
19289 if (type_is_invalid(value->value->type))20345 if (type_is_invalid(value->value->type))
19290 return ira->codegen->invalid_instruction;20346 return ira->codegen->invalid_inst_gen;
1929120347
19292 if (value->value->special != ConstValSpecialRuntime) {20348 if (value->value->special != ConstValSpecialRuntime) {
19293 IrInstruction *result = ir_const(ira, &phi_instruction->base, nullptr);20349 IrInstGen *result = ir_const(ira, &phi_instruction->base.base, nullptr);
19294 copy_const_val(result->value, value->value);20350 copy_const_val(result->value, value->value);
19295 return result;20351 return result;
19296 } else {20352 } else {
...@@ -19305,17 +20361,17 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -19305,17 +20361,17 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
19305 peer_parent->peers.length >= 2)20361 peer_parent->peers.length >= 2)
19306 {20362 {
19307 if (peer_parent->resolved_type == nullptr) {20363 if (peer_parent->resolved_type == nullptr) {
19308 IrInstruction **instructions = allocate<IrInstruction *>(peer_parent->peers.length);20364 IrInstGen **instructions = allocate<IrInstGen *>(peer_parent->peers.length);
19309 for (size_t i = 0; i < peer_parent->peers.length; i += 1) {20365 for (size_t i = 0; i < peer_parent->peers.length; i += 1) {
19310 ResultLocPeer *this_peer = peer_parent->peers.at(i);20366 ResultLocPeer *this_peer = peer_parent->peers.at(i);
1931120367
19312 IrInstruction *gen_instruction = this_peer->base.gen_instruction;20368 IrInstGen *gen_instruction = this_peer->base.gen_instruction;
19313 if (gen_instruction == nullptr) {20369 if (gen_instruction == nullptr) {
19314 // unreachable instructions will cause implicit_elem_type to be null20370 // unreachable instructions will cause implicit_elem_type to be null
19315 if (this_peer->base.implicit_elem_type == nullptr) {20371 if (this_peer->base.implicit_elem_type == nullptr) {
19316 instructions[i] = ir_const_unreachable(ira, this_peer->base.source_instruction);20372 instructions[i] = ir_const_unreachable(ira, &this_peer->base.source_instruction->base);
19317 } else {20373 } else {
19318 instructions[i] = ir_const(ira, this_peer->base.source_instruction,20374 instructions[i] = ir_const(ira, &this_peer->base.source_instruction->base,
19319 this_peer->base.implicit_elem_type);20375 this_peer->base.implicit_elem_type);
19320 instructions[i]->value->special = ConstValSpecialRuntime;20376 instructions[i]->value->special = ConstValSpecialRuntime;
19321 }20377 }
...@@ -19324,34 +20380,34 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -19324,34 +20380,34 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
19324 }20380 }
1932520381
19326 }20382 }
19327 ZigType *expected_type = ir_result_loc_expected_type(ira, &phi_instruction->base, peer_parent->parent);20383 ZigType *expected_type = ir_result_loc_expected_type(ira, &phi_instruction->base.base, peer_parent->parent);
19328 peer_parent->resolved_type = ir_resolve_peer_types(ira,20384 peer_parent->resolved_type = ir_resolve_peer_types(ira,
19329 peer_parent->base.source_instruction->source_node, expected_type, instructions,20385 peer_parent->base.source_instruction->base.source_node, expected_type, instructions,
19330 peer_parent->peers.length);20386 peer_parent->peers.length);
19331 if (type_is_invalid(peer_parent->resolved_type))20387 if (type_is_invalid(peer_parent->resolved_type))
19332 return ira->codegen->invalid_instruction;20388 return ira->codegen->invalid_inst_gen;
1933320389
19334 // the logic below assumes there are no instructions in the new current basic block yet20390 // the logic below assumes there are no instructions in the new current basic block yet
19335 ir_assert(ira->new_irb.current_basic_block->instruction_list.length == 0, &phi_instruction->base);20391 ir_assert(ira->new_irb.current_basic_block->instruction_list.length == 0, &phi_instruction->base.base);
1933620392
19337 // In case resolving the parent activates a suspend, do it now20393 // In case resolving the parent activates a suspend, do it now
19338 IrInstruction *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent,20394 IrInstGen *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base.base, peer_parent->parent,
19339 peer_parent->resolved_type, nullptr, false, false, true);20395 peer_parent->resolved_type, nullptr, false, true);
19340 if (parent_result_loc != nullptr &&20396 if (parent_result_loc != nullptr &&
19341 (type_is_invalid(parent_result_loc->value->type) || instr_is_unreachable(parent_result_loc)))20397 (type_is_invalid(parent_result_loc->value->type) || parent_result_loc->value->type->id == ZigTypeIdUnreachable))
19342 {20398 {
19343 return parent_result_loc;20399 return parent_result_loc;
19344 }20400 }
19345 // If the above code generated any instructions in the current basic block, we need20401 // If the above code generated any instructions in the current basic block, we need
19346 // to move them to the peer parent predecessor.20402 // to move them to the peer parent predecessor.
19347 ZigList<IrInstruction *> instrs_to_move = {};20403 ZigList<IrInstGen *> instrs_to_move = {};
19348 while (ira->new_irb.current_basic_block->instruction_list.length != 0) {20404 while (ira->new_irb.current_basic_block->instruction_list.length != 0) {
19349 instrs_to_move.append(ira->new_irb.current_basic_block->instruction_list.pop());20405 instrs_to_move.append(ira->new_irb.current_basic_block->instruction_list.pop());
19350 }20406 }
19351 if (instrs_to_move.length != 0) {20407 if (instrs_to_move.length != 0) {
19352 IrBasicBlock *predecessor = peer_parent->base.source_instruction->child->owner_bb;20408 IrBasicBlockGen *predecessor = peer_parent->base.source_instruction->child->owner_bb;
19353 IrInstruction *branch_instruction = predecessor->instruction_list.pop();20409 IrInstGen *branch_instruction = predecessor->instruction_list.pop();
19354 ir_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable, &phi_instruction->base);20410 ir_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable, &phi_instruction->base.base);
19355 while (instrs_to_move.length != 0) {20411 while (instrs_to_move.length != 0) {
19356 predecessor->instruction_list.append(instrs_to_move.pop());20412 predecessor->instruction_list.append(instrs_to_move.pop());
19357 }20413 }
...@@ -19360,7 +20416,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -19360,7 +20416,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
19360 }20416 }
1936120417
19362 IrSuspendPosition suspend_pos;20418 IrSuspendPosition suspend_pos;
19363 ira_suspend(ira, &phi_instruction->base, nullptr, &suspend_pos);20419 ira_suspend(ira, &phi_instruction->base.base, nullptr, &suspend_pos);
19364 ir_push_resume(ira, suspend_pos);20420 ir_push_resume(ira, suspend_pos);
1936520421
19366 for (size_t i = 0; i < peer_parent->peers.length; i += 1) {20422 for (size_t i = 0; i < peer_parent->peers.length; i += 1) {
...@@ -19376,34 +20432,32 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -19376,34 +20432,32 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
19376 return ira_resume(ira);20432 return ira_resume(ira);
19377 }20433 }
1937820434
19379 ZigList<IrBasicBlock*> new_incoming_blocks = {0};20435 ZigList<IrBasicBlockGen*> new_incoming_blocks = {0};
19380 ZigList<IrInstruction*> new_incoming_values = {0};20436 ZigList<IrInstGen*> new_incoming_values = {0};
1938120437
19382 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {20438 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {
19383 IrBasicBlock *predecessor = phi_instruction->incoming_blocks[i];20439 IrBasicBlockSrc *predecessor = phi_instruction->incoming_blocks[i];
19384 if (predecessor->ref_count == 0)20440 if (predecessor->ref_count == 0)
19385 continue;20441 continue;
1938620442
1938720443
19388 IrInstruction *old_value = phi_instruction->incoming_values[i];20444 IrInstSrc *old_value = phi_instruction->incoming_values[i];
19389 assert(old_value);20445 assert(old_value);
19390 IrInstruction *new_value = old_value->child;20446 IrInstGen *new_value = old_value->child;
19391 if (!new_value || new_value->value->type->id == ZigTypeIdUnreachable || predecessor->other == nullptr)20447 if (!new_value || new_value->value->type->id == ZigTypeIdUnreachable || predecessor->child == nullptr)
19392 continue;20448 continue;
1939320449
19394 if (type_is_invalid(new_value->value->type))20450 if (type_is_invalid(new_value->value->type))
19395 return ira->codegen->invalid_instruction;20451 return ira->codegen->invalid_inst_gen;
1939620452
1939720453
19398 assert(predecessor->other);20454 assert(predecessor->child);
19399 new_incoming_blocks.append(predecessor->other);20455 new_incoming_blocks.append(predecessor->child);
19400 new_incoming_values.append(new_value);20456 new_incoming_values.append(new_value);
19401 }20457 }
1940220458
19403 if (new_incoming_blocks.length == 0) {20459 if (new_incoming_blocks.length == 0) {
19404 IrInstruction *result = ir_build_unreachable(&ira->new_irb,20460 IrInstGen *result = ir_build_unreachable_gen(ira, &phi_instruction->base.base);
19405 phi_instruction->base.scope, phi_instruction->base.source_node);
19406 result->value->type = ira->codegen->builtin_types.entry_unreachable;
19407 return ir_finish_anal(ira, result);20461 return ir_finish_anal(ira, result);
19408 }20462 }
1940920463
...@@ -19415,7 +20469,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -19415,7 +20469,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
19415 if (peer_parent != nullptr) {20469 if (peer_parent != nullptr) {
19416 bool peer_parent_has_type;20470 bool peer_parent_has_type;
19417 if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type)))20471 if ((err = ir_result_has_type(ira, peer_parent->parent, &peer_parent_has_type)))
19418 return ira->codegen->invalid_instruction;20472 return ira->codegen->invalid_inst_gen;
19419 if (peer_parent_has_type) {20473 if (peer_parent_has_type) {
19420 if (peer_parent->parent->id == ResultLocIdReturn) {20474 if (peer_parent->parent->id == ResultLocIdReturn) {
19421 resolved_type = ira->explicit_return_type;20475 resolved_type = ira->explicit_return_type;
...@@ -19423,27 +20477,27 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -19423,27 +20477,27 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
19423 resolved_type = ir_resolve_type(ira, peer_parent->parent->source_instruction->child);20477 resolved_type = ir_resolve_type(ira, peer_parent->parent->source_instruction->child);
19424 } else if (peer_parent->parent->resolved_loc) {20478 } else if (peer_parent->parent->resolved_loc) {
19425 ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value->type;20479 ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value->type;
19426 ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base);20480 ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base.base);
19427 resolved_type = resolved_loc_ptr_type->data.pointer.child_type;20481 resolved_type = resolved_loc_ptr_type->data.pointer.child_type;
19428 }20482 }
1942920483
19430 if (resolved_type != nullptr && type_is_invalid(resolved_type))20484 if (resolved_type != nullptr && type_is_invalid(resolved_type))
19431 return ira->codegen->invalid_instruction;20485 return ira->codegen->invalid_inst_gen;
19432 }20486 }
19433 }20487 }
1943420488
19435 if (resolved_type == nullptr) {20489 if (resolved_type == nullptr) {
19436 resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr,20490 resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.base.source_node, nullptr,
19437 new_incoming_values.items, new_incoming_values.length);20491 new_incoming_values.items, new_incoming_values.length);
19438 if (type_is_invalid(resolved_type))20492 if (type_is_invalid(resolved_type))
19439 return ira->codegen->invalid_instruction;20493 return ira->codegen->invalid_inst_gen;
19440 }20494 }
1944120495
19442 switch (type_has_one_possible_value(ira->codegen, resolved_type)) {20496 switch (type_has_one_possible_value(ira->codegen, resolved_type)) {
19443 case OnePossibleValueInvalid:20497 case OnePossibleValueInvalid:
19444 return ira->codegen->invalid_instruction;20498 return ira->codegen->invalid_inst_gen;
19445 case OnePossibleValueYes:20499 case OnePossibleValueYes:
19446 return ir_const_move(ira, &phi_instruction->base,20500 return ir_const_move(ira, &phi_instruction->base.base,
19447 get_the_one_possible_value(ira->codegen, resolved_type));20501 get_the_one_possible_value(ira->codegen, resolved_type));
19448 case OnePossibleValueNo:20502 case OnePossibleValueNo:
19449 break;20503 break;
...@@ -19451,11 +20505,11 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -19451,11 +20505,11 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1945120505
19452 switch (type_requires_comptime(ira->codegen, resolved_type)) {20506 switch (type_requires_comptime(ira->codegen, resolved_type)) {
19453 case ReqCompTimeInvalid:20507 case ReqCompTimeInvalid:
19454 return ira->codegen->invalid_instruction;20508 return ira->codegen->invalid_inst_gen;
19455 case ReqCompTimeYes:20509 case ReqCompTimeYes:
19456 ir_add_error_node(ira, phi_instruction->base.source_node,20510 ir_add_error(ira, &phi_instruction->base.base,
19457 buf_sprintf("values of type '%s' must be comptime known", buf_ptr(&resolved_type->name)));20511 buf_sprintf("values of type '%s' must be comptime known", buf_ptr(&resolved_type->name)));
19458 return ira->codegen->invalid_instruction;20512 return ira->codegen->invalid_inst_gen;
19459 case ReqCompTimeNo:20513 case ReqCompTimeNo:
19460 break;20514 break;
19461 }20515 }
...@@ -19465,16 +20519,16 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -19465,16 +20519,16 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
19465 // cast all values to the resolved type. however we can't put cast instructions in front of the phi instruction.20519 // cast all values to the resolved type. however we can't put cast instructions in front of the phi instruction.
19466 // so we go back and insert the casts as the last instruction in the corresponding predecessor blocks, and20520 // so we go back and insert the casts as the last instruction in the corresponding predecessor blocks, and
19467 // then make sure the branch instruction is preserved.20521 // then make sure the branch instruction is preserved.
19468 IrBasicBlock *cur_bb = ira->new_irb.current_basic_block;20522 IrBasicBlockGen *cur_bb = ira->new_irb.current_basic_block;
19469 for (size_t i = 0; i < new_incoming_values.length; i += 1) {20523 for (size_t i = 0; i < new_incoming_values.length; i += 1) {
19470 IrInstruction *new_value = new_incoming_values.at(i);20524 IrInstGen *new_value = new_incoming_values.at(i);
19471 IrBasicBlock *predecessor = new_incoming_blocks.at(i);20525 IrBasicBlockGen *predecessor = new_incoming_blocks.at(i);
19472 ir_assert(predecessor->instruction_list.length != 0, &phi_instruction->base);20526 ir_assert(predecessor->instruction_list.length != 0, &phi_instruction->base.base);
19473 IrInstruction *branch_instruction = predecessor->instruction_list.pop();20527 IrInstGen *branch_instruction = predecessor->instruction_list.pop();
19474 ir_set_cursor_at_end(&ira->new_irb, predecessor);20528 ir_set_cursor_at_end_gen(&ira->new_irb, predecessor);
19475 IrInstruction *casted_value = ir_implicit_cast(ira, new_value, resolved_type);20529 IrInstGen *casted_value = ir_implicit_cast(ira, new_value, resolved_type);
19476 if (type_is_invalid(casted_value->value->type)) {20530 if (type_is_invalid(casted_value->value->type)) {
19477 return ira->codegen->invalid_instruction;20531 return ira->codegen->invalid_inst_gen;
19478 }20532 }
19479 new_incoming_values.items[i] = casted_value;20533 new_incoming_values.items[i] = casted_value;
19480 predecessor->instruction_list.append(branch_instruction);20534 predecessor->instruction_list.append(branch_instruction);
...@@ -19485,12 +20539,10 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -19485,12 +20539,10 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
19485 all_stack_ptrs = false;20539 all_stack_ptrs = false;
19486 }20540 }
19487 }20541 }
19488 ir_set_cursor_at_end(&ira->new_irb, cur_bb);20542 ir_set_cursor_at_end_gen(&ira->new_irb, cur_bb);
1948920543
19490 IrInstruction *result = ir_build_phi(&ira->new_irb,20544 IrInstGen *result = ir_build_phi_gen(ira, &phi_instruction->base.base,
19491 phi_instruction->base.scope, phi_instruction->base.source_node,20545 new_incoming_blocks.length, new_incoming_blocks.items, new_incoming_values.items, resolved_type);
19492 new_incoming_blocks.length, new_incoming_blocks.items, new_incoming_values.items, nullptr);
19493 result->value->type = resolved_type;
1949420546
19495 if (all_stack_ptrs) {20547 if (all_stack_ptrs) {
19496 assert(result->value->special == ConstValSpecialRuntime);20548 assert(result->value->special == ConstValSpecialRuntime);
...@@ -19500,17 +20552,17 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh...@@ -19500,17 +20552,17 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
19500 return result;20552 return result;
19501}20553}
1950220554
19503static IrInstruction *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *instruction) {20555static IrInstGen *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstSrcVarPtr *instruction) {
19504 ZigVar *var = instruction->var;20556 ZigVar *var = instruction->var;
19505 IrInstruction *result = ir_get_var_ptr(ira, &instruction->base, var);20557 IrInstGen *result = ir_get_var_ptr(ira, &instruction->base.base, var);
19506 if (instruction->crossed_fndef_scope != nullptr && !instr_is_comptime(result)) {20558 if (instruction->crossed_fndef_scope != nullptr && !instr_is_comptime(result)) {
19507 ErrorMsg *msg = ir_add_error(ira, &instruction->base,20559 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
19508 buf_sprintf("'%s' not accessible from inner function", var->name));20560 buf_sprintf("'%s' not accessible from inner function", var->name));
19509 add_error_note(ira->codegen, msg, instruction->crossed_fndef_scope->base.source_node,20561 add_error_note(ira->codegen, msg, instruction->crossed_fndef_scope->base.source_node,
19510 buf_sprintf("crossed function definition here"));20562 buf_sprintf("crossed function definition here"));
19511 add_error_note(ira->codegen, msg, var->decl_node,20563 add_error_note(ira->codegen, msg, var->decl_node,
19512 buf_sprintf("declared here"));20564 buf_sprintf("declared here"));
19513 return ira->codegen->invalid_instruction;20565 return ira->codegen->invalid_inst_gen;
19514 }20566 }
19515 return result;20567 return result;
19516}20568}
...@@ -19561,17 +20613,17 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) {...@@ -19561,17 +20613,17 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) {
19561 ptr_type->data.pointer.allow_zero);20613 ptr_type->data.pointer.allow_zero);
19562}20614}
1956320615
19564static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) {20616static IrInstGen *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstSrcElemPtr *elem_ptr_instruction) {
19565 Error err;20617 Error err;
19566 IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->child;20618 IrInstGen *array_ptr = elem_ptr_instruction->array_ptr->child;
19567 if (type_is_invalid(array_ptr->value->type))20619 if (type_is_invalid(array_ptr->value->type))
19568 return ira->codegen->invalid_instruction;20620 return ira->codegen->invalid_inst_gen;
1956920621
19570 ZigValue *orig_array_ptr_val = array_ptr->value;20622 ZigValue *orig_array_ptr_val = array_ptr->value;
1957120623
19572 IrInstruction *elem_index = elem_ptr_instruction->elem_index->child;20624 IrInstGen *elem_index = elem_ptr_instruction->elem_index->child;
19573 if (type_is_invalid(elem_index->value->type))20625 if (type_is_invalid(elem_index->value->type))
19574 return ira->codegen->invalid_instruction;20626 return ira->codegen->invalid_inst_gen;
1957520627
19576 ZigType *ptr_type = orig_array_ptr_val->type;20628 ZigType *ptr_type = orig_array_ptr_val->type;
19577 assert(ptr_type->id == ZigTypeIdPointer);20629 assert(ptr_type->id == ZigTypeIdPointer);
...@@ -19583,7 +20635,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19583,7 +20635,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19583 ZigType *return_type;20635 ZigType *return_type;
1958420636
19585 if (type_is_invalid(array_type)) {20637 if (type_is_invalid(array_type)) {
19586 return ira->codegen->invalid_instruction;20638 return ira->codegen->invalid_inst_gen;
19587 } else if (array_type->id == ZigTypeIdArray ||20639 } else if (array_type->id == ZigTypeIdArray ||
19588 (array_type->id == ZigTypeIdPointer &&20640 (array_type->id == ZigTypeIdPointer &&
19589 array_type->data.pointer.ptr_len == PtrLenSingle &&20641 array_type->data.pointer.ptr_len == PtrLenSingle &&
...@@ -19594,15 +20646,15 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19594,15 +20646,15 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19594 ptr_type = ptr_type->data.pointer.child_type;20646 ptr_type = ptr_type->data.pointer.child_type;
19595 if (orig_array_ptr_val->special != ConstValSpecialRuntime) {20647 if (orig_array_ptr_val->special != ConstValSpecialRuntime) {
19596 orig_array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,20648 orig_array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,
19597 elem_ptr_instruction->base.source_node);20649 elem_ptr_instruction->base.base.source_node);
19598 if (orig_array_ptr_val == nullptr)20650 if (orig_array_ptr_val == nullptr)
19599 return ira->codegen->invalid_instruction;20651 return ira->codegen->invalid_inst_gen;
19600 }20652 }
19601 }20653 }
19602 if (array_type->data.array.len == 0) {20654 if (array_type->data.array.len == 0) {
19603 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,20655 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
19604 buf_sprintf("index 0 outside array of size 0"));20656 buf_sprintf("index 0 outside array of size 0"));
19605 return ira->codegen->invalid_instruction;20657 return ira->codegen->invalid_inst_gen;
19606 }20658 }
19607 ZigType *child_type = array_type->data.array.child_type;20659 ZigType *child_type = array_type->data.array.child_type;
19608 if (ptr_type->data.pointer.host_int_bytes == 0) {20660 if (ptr_type->data.pointer.host_int_bytes == 0) {
...@@ -19613,7 +20665,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19613,7 +20665,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19613 } else {20665 } else {
19614 uint64_t elem_val_scalar;20666 uint64_t elem_val_scalar;
19615 if (!ir_resolve_usize(ira, elem_index, &elem_val_scalar))20667 if (!ir_resolve_usize(ira, elem_index, &elem_val_scalar))
19616 return ira->codegen->invalid_instruction;20668 return ira->codegen->invalid_inst_gen;
1961720669
19618 size_t bit_width = type_size_bits(ira->codegen, child_type);20670 size_t bit_width = type_size_bits(ira->codegen, child_type);
19619 size_t bit_offset = bit_width * elem_val_scalar;20671 size_t bit_offset = bit_width * elem_val_scalar;
...@@ -19625,9 +20677,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19625,9 +20677,9 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19625 }20677 }
19626 } else if (array_type->id == ZigTypeIdPointer) {20678 } else if (array_type->id == ZigTypeIdPointer) {
19627 if (array_type->data.pointer.ptr_len == PtrLenSingle) {20679 if (array_type->data.pointer.ptr_len == PtrLenSingle) {
19628 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,20680 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
19629 buf_sprintf("index of single-item pointer"));20681 buf_sprintf("index of single-item pointer"));
19630 return ira->codegen->invalid_instruction;20682 return ira->codegen->invalid_inst_gen;
19631 }20683 }
19632 return_type = adjust_ptr_len(ira->codegen, array_type, elem_ptr_instruction->ptr_len);20684 return_type = adjust_ptr_len(ira->codegen, array_type, elem_ptr_instruction->ptr_len);
19633 } else if (is_slice(array_type)) {20685 } else if (is_slice(array_type)) {
...@@ -19641,38 +20693,38 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19641,38 +20693,38 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19641 array_type->data.structure.resolve_status == ResolveStatusBeingInferred)20693 array_type->data.structure.resolve_status == ResolveStatusBeingInferred)
19642 {20694 {
19643 ZigType *usize = ira->codegen->builtin_types.entry_usize;20695 ZigType *usize = ira->codegen->builtin_types.entry_usize;
19644 IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);20696 IrInstGen *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);
19645 if (type_is_invalid(casted_elem_index->value->type))20697 if (type_is_invalid(casted_elem_index->value->type))
19646 return ira->codegen->invalid_instruction;20698 return ira->codegen->invalid_inst_gen;
19647 ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base);20699 ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base.base);
19648 Buf *field_name = buf_alloc();20700 Buf *field_name = buf_alloc();
19649 bigint_append_buf(field_name, &casted_elem_index->value->data.x_bigint, 10);20701 bigint_append_buf(field_name, &casted_elem_index->value->data.x_bigint, 10);
19650 return ir_analyze_inferred_field_ptr(ira, field_name, &elem_ptr_instruction->base,20702 return ir_analyze_inferred_field_ptr(ira, field_name, &elem_ptr_instruction->base.base,
19651 array_ptr, array_type);20703 array_ptr, array_type);
19652 } else if (is_tuple(array_type)) {20704 } else if (is_tuple(array_type)) {
19653 uint64_t elem_index_scalar;20705 uint64_t elem_index_scalar;
19654 if (!ir_resolve_usize(ira, elem_index, &elem_index_scalar))20706 if (!ir_resolve_usize(ira, elem_index, &elem_index_scalar))
19655 return ira->codegen->invalid_instruction;20707 return ira->codegen->invalid_inst_gen;
19656 if (elem_index_scalar >= array_type->data.structure.src_field_count) {20708 if (elem_index_scalar >= array_type->data.structure.src_field_count) {
19657 ir_add_error(ira, &elem_ptr_instruction->base, buf_sprintf(20709 ir_add_error(ira, &elem_ptr_instruction->base.base, buf_sprintf(
19658 "field index %" ZIG_PRI_u64 " outside tuple '%s' which has %" PRIu32 " fields",20710 "field index %" ZIG_PRI_u64 " outside tuple '%s' which has %" PRIu32 " fields",
19659 elem_index_scalar, buf_ptr(&array_type->name),20711 elem_index_scalar, buf_ptr(&array_type->name),
19660 array_type->data.structure.src_field_count));20712 array_type->data.structure.src_field_count));
19661 return ira->codegen->invalid_instruction;20713 return ira->codegen->invalid_inst_gen;
19662 }20714 }
19663 TypeStructField *field = array_type->data.structure.fields[elem_index_scalar];20715 TypeStructField *field = array_type->data.structure.fields[elem_index_scalar];
19664 return ir_analyze_struct_field_ptr(ira, &elem_ptr_instruction->base, field, array_ptr,20716 return ir_analyze_struct_field_ptr(ira, &elem_ptr_instruction->base.base, field, array_ptr,
19665 array_type, false);20717 array_type, false);
19666 } else {20718 } else {
19667 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,20719 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
19668 buf_sprintf("array access of non-array type '%s'", buf_ptr(&array_type->name)));20720 buf_sprintf("array access of non-array type '%s'", buf_ptr(&array_type->name)));
19669 return ira->codegen->invalid_instruction;20721 return ira->codegen->invalid_inst_gen;
19670 }20722 }
1967120723
19672 ZigType *usize = ira->codegen->builtin_types.entry_usize;20724 ZigType *usize = ira->codegen->builtin_types.entry_usize;
19673 IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);20725 IrInstGen *casted_elem_index = ir_implicit_cast(ira, elem_index, usize);
19674 if (casted_elem_index == ira->codegen->invalid_instruction)20726 if (type_is_invalid(casted_elem_index->value->type))
19675 return ira->codegen->invalid_instruction;20727 return ira->codegen->invalid_inst_gen;
1967620728
19677 bool safety_check_on = elem_ptr_instruction->safety_check_on;20729 bool safety_check_on = elem_ptr_instruction->safety_check_on;
19678 if (instr_is_comptime(casted_elem_index)) {20730 if (instr_is_comptime(casted_elem_index)) {
...@@ -19681,15 +20733,15 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19681,15 +20733,15 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19681 uint64_t array_len = array_type->data.array.len;20733 uint64_t array_len = array_type->data.array.len;
19682 if (index == array_len && array_type->data.array.sentinel != nullptr) {20734 if (index == array_len && array_type->data.array.sentinel != nullptr) {
19683 ZigType *elem_type = array_type->data.array.child_type;20735 ZigType *elem_type = array_type->data.array.child_type;
19684 IrInstruction *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base, elem_type);20736 IrInstGen *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base.base, elem_type);
19685 copy_const_val(sentinel_elem->value, array_type->data.array.sentinel);20737 copy_const_val(sentinel_elem->value, array_type->data.array.sentinel);
19686 return ir_get_ref(ira, &elem_ptr_instruction->base, sentinel_elem, true, false);20738 return ir_get_ref(ira, &elem_ptr_instruction->base.base, sentinel_elem, true, false);
19687 }20739 }
19688 if (index >= array_len) {20740 if (index >= array_len) {
19689 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,20741 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
19690 buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64,20742 buf_sprintf("index %" ZIG_PRI_u64 " outside array of size %" ZIG_PRI_u64,
19691 index, array_len));20743 index, array_len));
19692 return ira->codegen->invalid_instruction;20744 return ira->codegen->invalid_inst_gen;
19693 }20745 }
19694 safety_check_on = false;20746 safety_check_on = false;
19695 }20747 }
...@@ -19705,7 +20757,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19705,7 +20757,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19705 // figure out the largest alignment possible20757 // figure out the largest alignment possible
1970620758
19707 if ((err = type_resolve(ira->codegen, return_type->data.pointer.child_type, ResolveStatusSizeKnown)))20759 if ((err = type_resolve(ira->codegen, return_type->data.pointer.child_type, ResolveStatusSizeKnown)))
19708 return ira->codegen->invalid_instruction;20760 return ira->codegen->invalid_inst_gen;
1970920761
19710 uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type);20762 uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type);
19711 uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type);20763 uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type);
...@@ -19729,15 +20781,17 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19729,15 +20781,17 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19729 return_type = adjust_ptr_align(ira->codegen, return_type, chosen_align);20781 return_type = adjust_ptr_align(ira->codegen, return_type, chosen_align);
19730 }20782 }
1973120783
20784 // TODO The `array_type->id == ZigTypeIdArray` exception here should not be an exception;
20785 // the `orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar` clause should be omitted completely.
20786 // However there are bugs to fix before this improvement can be made.
19732 if (orig_array_ptr_val->special != ConstValSpecialRuntime &&20787 if (orig_array_ptr_val->special != ConstValSpecialRuntime &&
19733 orig_array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&20788 orig_array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&
19734 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar ||20789 (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || array_type->id == ZigTypeIdArray))
19735 array_type->id == ZigTypeIdArray))
19736 {20790 {
19737 ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,20791 ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val,
19738 elem_ptr_instruction->base.source_node);20792 elem_ptr_instruction->base.base.source_node);
19739 if (array_ptr_val == nullptr)20793 if (array_ptr_val == nullptr)
19740 return ira->codegen->invalid_instruction;20794 return ira->codegen->invalid_inst_gen;
1974120795
19742 if (array_ptr_val->special == ConstValSpecialUndef &&20796 if (array_ptr_val->special == ConstValSpecialUndef &&
19743 elem_ptr_instruction->init_array_type_source_node != nullptr)20797 elem_ptr_instruction->init_array_type_source_node != nullptr)
...@@ -19755,16 +20809,16 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19755,16 +20809,16 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19755 elem_val->parent.data.p_array.elem_index = i;20809 elem_val->parent.data.p_array.elem_index = i;
19756 }20810 }
19757 } else if (is_slice(array_type)) {20811 } else if (is_slice(array_type)) {
19758 ir_assert(array_ptr->value->type->id == ZigTypeIdPointer, &elem_ptr_instruction->base);20812 ir_assert(array_ptr->value->type->id == ZigTypeIdPointer, &elem_ptr_instruction->base.base);
19759 ZigType *actual_array_type = array_ptr->value->type->data.pointer.child_type;20813 ZigType *actual_array_type = array_ptr->value->type->data.pointer.child_type;
1976020814
19761 if (type_is_invalid(actual_array_type))20815 if (type_is_invalid(actual_array_type))
19762 return ira->codegen->invalid_instruction;20816 return ira->codegen->invalid_inst_gen;
19763 if (actual_array_type->id != ZigTypeIdArray) {20817 if (actual_array_type->id != ZigTypeIdArray) {
19764 ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node,20818 ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node,
19765 buf_sprintf("array literal requires address-of operator to coerce to slice type '%s'",20819 buf_sprintf("array literal requires address-of operator to coerce to slice type '%s'",
19766 buf_ptr(&actual_array_type->name)));20820 buf_ptr(&actual_array_type->name)));
19767 return ira->codegen->invalid_instruction;20821 return ira->codegen->invalid_inst_gen;
19768 }20822 }
1976920823
19770 ZigValue *array_init_val = create_const_vals(1);20824 ZigValue *array_init_val = create_const_vals(1);
...@@ -19789,7 +20843,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19789,7 +20843,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19789 ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node,20843 ir_add_error_node(ira, elem_ptr_instruction->init_array_type_source_node,
19790 buf_sprintf("expected array type or [_], found '%s'",20844 buf_sprintf("expected array type or [_], found '%s'",
19791 buf_ptr(&array_type->name)));20845 buf_ptr(&array_type->name)));
19792 return ira->codegen->invalid_instruction;20846 return ira->codegen->invalid_inst_gen;
19793 }20847 }
19794 }20848 }
1979520849
...@@ -19797,8 +20851,13 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19797,8 +20851,13 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19797 (array_type->id != ZigTypeIdPointer ||20851 (array_type->id != ZigTypeIdPointer ||
19798 array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr))20852 array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr))
19799 {20853 {
20854 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
20855 elem_ptr_instruction->base.base.source_node, array_ptr_val, UndefOk)))
20856 {
20857 return ira->codegen->invalid_inst_gen;
20858 }
19800 if (array_type->id == ZigTypeIdPointer) {20859 if (array_type->id == ZigTypeIdPointer) {
19801 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);20860 IrInstGen *result = ir_const(ira, &elem_ptr_instruction->base.base, return_type);
19802 ZigValue *out_val = result->value;20861 ZigValue *out_val = result->value;
19803 out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;20862 out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut;
19804 size_t new_index;20863 size_t new_index;
...@@ -19867,33 +20926,31 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19867,33 +20926,31 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19867 zig_panic("TODO elem ptr on a null pointer");20926 zig_panic("TODO elem ptr on a null pointer");
19868 }20927 }
19869 if (new_index >= mem_size) {20928 if (new_index >= mem_size) {
19870 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,20929 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
19871 buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size));20930 buf_sprintf("index %" ZIG_PRI_u64 " outside pointer of size %" ZIG_PRI_usize "", index, old_size));
19872 return ira->codegen->invalid_instruction;20931 return ira->codegen->invalid_inst_gen;
19873 }20932 }
19874 return result;20933 return result;
19875 } else if (is_slice(array_type)) {20934 } else if (is_slice(array_type)) {
19876 ZigValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index];20935 ZigValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index];
19877 ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base);20936 ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base.base);
19878 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {20937 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
19879 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,20938 return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope,
19880 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, false,20939 elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, false,
19881 elem_ptr_instruction->ptr_len, nullptr);20940 return_type);
19882 result->value->type = return_type;
19883 return result;
19884 }20941 }
19885 ZigValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index];20942 ZigValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index];
19886 IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type);20943 IrInstGen *result = ir_const(ira, &elem_ptr_instruction->base.base, return_type);
19887 ZigValue *out_val = result->value;20944 ZigValue *out_val = result->value;
19888 ZigType *slice_ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry;20945 ZigType *slice_ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry;
19889 uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint);20946 uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint);
19890 uint64_t full_slice_len = slice_len +20947 uint64_t full_slice_len = slice_len +
19891 ((slice_ptr_type->data.pointer.sentinel != nullptr) ? 1 : 0);20948 ((slice_ptr_type->data.pointer.sentinel != nullptr) ? 1 : 0);
19892 if (index >= full_slice_len) {20949 if (index >= full_slice_len) {
19893 ir_add_error_node(ira, elem_ptr_instruction->base.source_node,20950 ir_add_error_node(ira, elem_ptr_instruction->base.base.source_node,
19894 buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64,20951 buf_sprintf("index %" ZIG_PRI_u64 " outside slice of size %" ZIG_PRI_u64,
19895 index, slice_len));20952 index, slice_len));
19896 return ira->codegen->invalid_instruction;20953 return ira->codegen->invalid_inst_gen;
19897 }20954 }
19898 out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut;20955 out_val->data.x_ptr.mut = ptr_field->data.x_ptr.mut;
19899 switch (ptr_field->data.x_ptr.special) {20956 switch (ptr_field->data.x_ptr.special) {
...@@ -19913,7 +20970,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19913,7 +20970,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19913 {20970 {
19914 ir_assert(new_index <20971 ir_assert(new_index <
19915 ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len,20972 ptr_field->data.x_ptr.data.base_array.array_val->type->data.array.len,
19916 &elem_ptr_instruction->base);20973 &elem_ptr_instruction->base.base);
19917 }20974 }
19918 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;20975 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
19919 out_val->data.x_ptr.data.base_array.array_val =20976 out_val->data.x_ptr.data.base_array.array_val =
...@@ -19938,15 +20995,14 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19938,15 +20995,14 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19938 }20995 }
19939 return result;20996 return result;
19940 } else if (array_type->id == ZigTypeIdArray || array_type->id == ZigTypeIdVector) {20997 } else if (array_type->id == ZigTypeIdArray || array_type->id == ZigTypeIdVector) {
19941 IrInstruction *result;20998 IrInstGen *result;
19942 if (orig_array_ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {20999 if (orig_array_ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
19943 result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,21000 result = ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope,
19944 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index,21001 elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index,
19945 false, elem_ptr_instruction->ptr_len, nullptr);21002 false, return_type);
19946 result->value->type = return_type;
19947 result->value->special = ConstValSpecialStatic;21003 result->value->special = ConstValSpecialStatic;
19948 } else {21004 } else {
19949 result = ir_const(ira, &elem_ptr_instruction->base, return_type);21005 result = ir_const(ira, &elem_ptr_instruction->base.base, return_type);
19950 }21006 }
19951 ZigValue *out_val = result->value;21007 ZigValue *out_val = result->value;
19952 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;21008 out_val->data.x_ptr.special = ConstPtrSpecialBaseArray;
...@@ -19972,19 +21028,19 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -19972,19 +21028,19 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
19972 // runtime known element index21028 // runtime known element index
19973 switch (type_requires_comptime(ira->codegen, return_type)) {21029 switch (type_requires_comptime(ira->codegen, return_type)) {
19974 case ReqCompTimeYes:21030 case ReqCompTimeYes:
19975 ir_add_error(ira, elem_index,21031 ir_add_error(ira, &elem_index->base,
19976 buf_sprintf("values of type '%s' must be comptime known, but index value is runtime known",21032 buf_sprintf("values of type '%s' must be comptime known, but index value is runtime known",
19977 buf_ptr(&return_type->data.pointer.child_type->name)));21033 buf_ptr(&return_type->data.pointer.child_type->name)));
19978 return ira->codegen->invalid_instruction;21034 return ira->codegen->invalid_inst_gen;
19979 case ReqCompTimeInvalid:21035 case ReqCompTimeInvalid:
19980 return ira->codegen->invalid_instruction;21036 return ira->codegen->invalid_inst_gen;
19981 case ReqCompTimeNo:21037 case ReqCompTimeNo:
19982 break;21038 break;
19983 }21039 }
1998421040
19985 if (return_type->data.pointer.explicit_alignment != 0) {21041 if (return_type->data.pointer.explicit_alignment != 0) {
19986 if ((err = type_resolve(ira->codegen, return_type->data.pointer.child_type, ResolveStatusSizeKnown)))21042 if ((err = type_resolve(ira->codegen, return_type->data.pointer.child_type, ResolveStatusSizeKnown)))
19987 return ira->codegen->invalid_instruction;21043 return ira->codegen->invalid_inst_gen;
1998821044
19989 uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type);21045 uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type);
19990 uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type);21046 uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type);
...@@ -20002,16 +21058,13 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct...@@ -20002,16 +21058,13 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
20002 }21058 }
20003 }21059 }
2000421060
20005 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,21061 return ir_build_elem_ptr_gen(ira, elem_ptr_instruction->base.base.scope,
20006 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, safety_check_on,21062 elem_ptr_instruction->base.base.source_node, array_ptr, casted_elem_index, safety_check_on, return_type);
20007 elem_ptr_instruction->ptr_len, nullptr);
20008 result->value->type = return_type;
20009 return result;
20010}21063}
2001121064
20012static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,21065static IrInstGen *ir_analyze_container_member_access_inner(IrAnalyze *ira,
20013 ZigType *bare_struct_type, Buf *field_name, IrInstruction *source_instr,21066 ZigType *bare_struct_type, Buf *field_name, IrInst* source_instr,
20014 IrInstruction *container_ptr, ZigType *container_type)21067 IrInstGen *container_ptr, IrInst *container_ptr_src, ZigType *container_type)
20015{21068{
20016 if (!is_slice(bare_struct_type)) {21069 if (!is_slice(bare_struct_type)) {
20017 ScopeDecls *container_scope = get_container_scope(bare_struct_type);21070 ScopeDecls *container_scope = get_container_scope(bare_struct_type);
...@@ -20021,29 +21074,39 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -20021,29 +21074,39 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
20021 if (tld->id == TldIdFn) {21074 if (tld->id == TldIdFn) {
20022 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);21075 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);
20023 if (tld->resolution == TldResolutionInvalid)21076 if (tld->resolution == TldResolutionInvalid)
20024 return ira->codegen->invalid_instruction;21077 return ira->codegen->invalid_inst_gen;
21078 if (tld->resolution == TldResolutionResolving)
21079 return ir_error_dependency_loop(ira, source_instr);
21080
20025 TldFn *tld_fn = (TldFn *)tld;21081 TldFn *tld_fn = (TldFn *)tld;
20026 ZigFn *fn_entry = tld_fn->fn_entry;21082 ZigFn *fn_entry = tld_fn->fn_entry;
21083 assert(fn_entry != nullptr);
21084
20027 if (type_is_invalid(fn_entry->type_entry))21085 if (type_is_invalid(fn_entry->type_entry))
20028 return ira->codegen->invalid_instruction;21086 return ira->codegen->invalid_inst_gen;
2002921087
20030 IrInstruction *bound_fn_value = ir_build_const_bound_fn(&ira->new_irb, source_instr->scope,21088 IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn_entry, container_ptr,
20031 source_instr->source_node, fn_entry, container_ptr);21089 container_ptr_src);
20032 return ir_get_ref(ira, source_instr, bound_fn_value, true, false);21090 return ir_get_ref(ira, source_instr, bound_fn_value, true, false);
20033 } else if (tld->id == TldIdVar) {21091 } else if (tld->id == TldIdVar) {
20034 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);21092 resolve_top_level_decl(ira->codegen, tld, source_instr->source_node, false);
20035 if (tld->resolution == TldResolutionInvalid)21093 if (tld->resolution == TldResolutionInvalid)
20036 return ira->codegen->invalid_instruction;21094 return ira->codegen->invalid_inst_gen;
21095 if (tld->resolution == TldResolutionResolving)
21096 return ir_error_dependency_loop(ira, source_instr);
21097
20037 TldVar *tld_var = (TldVar *)tld;21098 TldVar *tld_var = (TldVar *)tld;
20038 ZigVar *var = tld_var->var;21099 ZigVar *var = tld_var->var;
21100 assert(var != nullptr);
21101
20039 if (type_is_invalid(var->var_type))21102 if (type_is_invalid(var->var_type))
20040 return ira->codegen->invalid_instruction;21103 return ira->codegen->invalid_inst_gen;
2004121104
20042 if (var->const_value->type->id == ZigTypeIdFn) {21105 if (var->const_value->type->id == ZigTypeIdFn) {
20043 ir_assert(var->const_value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr);21106 ir_assert(var->const_value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr);
20044 ZigFn *fn = var->const_value->data.x_ptr.data.fn.fn_entry;21107 ZigFn *fn = var->const_value->data.x_ptr.data.fn.fn_entry;
20045 IrInstruction *bound_fn_value = ir_build_const_bound_fn(&ira->new_irb, source_instr->scope,21108 IrInstGen *bound_fn_value = ir_const_bound_fn(ira, source_instr, fn, container_ptr,
20046 source_instr->source_node, fn, container_ptr);21109 container_ptr_src);
20047 return ir_get_ref(ira, source_instr, bound_fn_value, true, false);21110 return ir_get_ref(ira, source_instr, bound_fn_value, true, false);
20048 }21111 }
20049 }21112 }
...@@ -20063,7 +21126,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,...@@ -20063,7 +21126,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira,
20063 }21126 }
20064 ir_add_error_node(ira, source_instr->source_node,21127 ir_add_error_node(ira, source_instr->source_node,
20065 buf_sprintf("no member named '%s' in %s'%s'", buf_ptr(field_name), prefix_name, buf_ptr(&bare_struct_type->name)));21128 buf_sprintf("no member named '%s' in %s'%s'", buf_ptr(field_name), prefix_name, buf_ptr(&bare_struct_type->name)));
20066 return ira->codegen->invalid_instruction;21129 return ira->codegen->invalid_inst_gen;
20067}21130}
2006821131
20069static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, TypeStructField *field) {21132static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, TypeStructField *field) {
...@@ -20078,24 +21141,24 @@ static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, Ty...@@ -20078,24 +21141,24 @@ static void memoize_field_init_val(CodeGen *codegen, ZigType *container_type, Ty
20078 field->type_entry, nullptr, UndefOk);21141 field->type_entry, nullptr, UndefOk);
20079}21142}
2008021143
20081static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction *source_instr,21144static IrInstGen *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInst* source_instr,
20082 TypeStructField *field, IrInstruction *struct_ptr, ZigType *struct_type, bool initializing)21145 TypeStructField *field, IrInstGen *struct_ptr, ZigType *struct_type, bool initializing)
20083{21146{
20084 Error err;21147 Error err;
20085 ZigType *field_type = resolve_struct_field_type(ira->codegen, field);21148 ZigType *field_type = resolve_struct_field_type(ira->codegen, field);
20086 if (field_type == nullptr)21149 if (field_type == nullptr)
20087 return ira->codegen->invalid_instruction;21150 return ira->codegen->invalid_inst_gen;
20088 if (field->is_comptime) {21151 if (field->is_comptime) {
20089 IrInstruction *elem = ir_const(ira, source_instr, field_type);21152 IrInstGen *elem = ir_const(ira, source_instr, field_type);
20090 memoize_field_init_val(ira->codegen, struct_type, field);21153 memoize_field_init_val(ira->codegen, struct_type, field);
20091 copy_const_val(elem->value, field->init_val);21154 copy_const_val(elem->value, field->init_val);
20092 return ir_get_ref(ira, source_instr, elem, true, false);21155 return ir_get_ref2(ira, source_instr, elem, field_type, true, false);
20093 }21156 }
20094 switch (type_has_one_possible_value(ira->codegen, field_type)) {21157 switch (type_has_one_possible_value(ira->codegen, field_type)) {
20095 case OnePossibleValueInvalid:21158 case OnePossibleValueInvalid:
20096 return ira->codegen->invalid_instruction;21159 return ira->codegen->invalid_inst_gen;
20097 case OnePossibleValueYes: {21160 case OnePossibleValueYes: {
20098 IrInstruction *elem = ir_const_move(ira, source_instr,21161 IrInstGen *elem = ir_const_move(ira, source_instr,
20099 get_the_one_possible_value(ira->codegen, field_type));21162 get_the_one_possible_value(ira->codegen, field_type));
20100 return ir_get_ref(ira, source_instr, elem, false, false);21163 return ir_get_ref(ira, source_instr, elem, false, false);
20101 }21164 }
...@@ -20113,7 +21176,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction...@@ -20113,7 +21176,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
20113 (struct_type->data.structure.layout == ContainerLayoutAuto) ?21176 (struct_type->data.structure.layout == ContainerLayoutAuto) ?
20114 ResolveStatusZeroBitsKnown : ResolveStatusSizeKnown;21177 ResolveStatusZeroBitsKnown : ResolveStatusSizeKnown;
20115 if ((err = type_resolve(ira->codegen, struct_type, needed_resolve_status)))21178 if ((err = type_resolve(ira->codegen, struct_type, needed_resolve_status)))
20116 return ira->codegen->invalid_instruction;21179 return ira->codegen->invalid_inst_gen;
20117 assert(struct_ptr->value->type->id == ZigTypeIdPointer);21180 assert(struct_ptr->value->type->id == ZigTypeIdPointer);
20118 uint32_t ptr_bit_offset = struct_ptr->value->type->data.pointer.bit_offset_in_host;21181 uint32_t ptr_bit_offset = struct_ptr->value->type->data.pointer.bit_offset_in_host;
20119 uint32_t ptr_host_int_bytes = struct_ptr->value->type->data.pointer.host_int_bytes;21182 uint32_t ptr_host_int_bytes = struct_ptr->value->type->data.pointer.host_int_bytes;
...@@ -20127,14 +21190,14 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction...@@ -20127,14 +21190,14 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
20127 if (instr_is_comptime(struct_ptr)) {21190 if (instr_is_comptime(struct_ptr)) {
20128 ZigValue *ptr_val = ir_resolve_const(ira, struct_ptr, UndefBad);21191 ZigValue *ptr_val = ir_resolve_const(ira, struct_ptr, UndefBad);
20129 if (!ptr_val)21192 if (!ptr_val)
20130 return ira->codegen->invalid_instruction;21193 return ira->codegen->invalid_inst_gen;
2013121194
20132 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {21195 if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
20133 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);21196 ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
20134 if (struct_val == nullptr)21197 if (struct_val == nullptr)
20135 return ira->codegen->invalid_instruction;21198 return ira->codegen->invalid_inst_gen;
20136 if (type_is_invalid(struct_val->type))21199 if (type_is_invalid(struct_val->type))
20137 return ira->codegen->invalid_instruction;21200 return ira->codegen->invalid_inst_gen;
20138 if (initializing && struct_val->special == ConstValSpecialUndef) {21201 if (initializing && struct_val->special == ConstValSpecialUndef) {
20139 struct_val->data.x_struct.fields = alloc_const_vals_ptrs(struct_type->data.structure.src_field_count);21202 struct_val->data.x_struct.fields = alloc_const_vals_ptrs(struct_type->data.structure.src_field_count);
20140 struct_val->special = ConstValSpecialStatic;21203 struct_val->special = ConstValSpecialStatic;
...@@ -20148,11 +21211,9 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction...@@ -20148,11 +21211,9 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
20148 field_val->parent.data.p_struct.field_index = i;21211 field_val->parent.data.p_struct.field_index = i;
20149 }21212 }
20150 }21213 }
20151 IrInstruction *result;21214 IrInstGen *result;
20152 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {21215 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
20153 result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope,21216 result = ir_build_struct_field_ptr(ira, source_instr, struct_ptr, field, ptr_type);
20154 source_instr->source_node, struct_ptr, field);
20155 result->value->type = ptr_type;
20156 result->value->special = ConstValSpecialStatic;21217 result->value->special = ConstValSpecialStatic;
20157 } else {21218 } else {
20158 result = ir_const(ira, source_instr, ptr_type);21219 result = ir_const(ira, source_instr, ptr_type);
...@@ -20165,14 +21226,11 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction...@@ -20165,14 +21226,11 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
20165 return result;21226 return result;
20166 }21227 }
20167 }21228 }
20168 IrInstruction *result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node,21229 return ir_build_struct_field_ptr(ira, source_instr, struct_ptr, field, ptr_type);
20169 struct_ptr, field);
20170 result->value->type = ptr_type;
20171 return result;
20172}21230}
2017321231
20174static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,21232static IrInstGen *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_name,
20175 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type)21233 IrInst* source_instr, IrInstGen *container_ptr, ZigType *container_type)
20176{21234{
20177 // The type of the field is not available until a store using this pointer happens.21235 // The type of the field is not available until a store using this pointer happens.
20178 // So, here we create a special pointer type which has the inferred struct type and21236 // So, here we create a special pointer type which has the inferred struct type and
...@@ -20195,12 +21253,11 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n...@@ -20195,12 +21253,11 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n
20195 if (instr_is_comptime(container_ptr)) {21253 if (instr_is_comptime(container_ptr)) {
20196 ZigValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);21254 ZigValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
20197 if (ptr_val == nullptr)21255 if (ptr_val == nullptr)
20198 return ira->codegen->invalid_instruction;21256 return ira->codegen->invalid_inst_gen;
2019921257
20200 IrInstruction *result;21258 IrInstGen *result;
20201 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {21259 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
20202 result = ir_build_cast(&ira->new_irb, source_instr->scope,21260 result = ir_build_cast(ira, source_instr, container_ptr_type, container_ptr, CastOpNoop);
20203 source_instr->source_node, container_ptr_type, container_ptr, CastOpNoop);
20204 } else {21261 } else {
20205 result = ir_const(ira, source_instr, field_ptr_type);21262 result = ir_const(ira, source_instr, field_ptr_type);
20206 }21263 }
...@@ -20209,14 +21266,12 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n...@@ -20209,14 +21266,12 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n
20209 return result;21266 return result;
20210 }21267 }
2021121268
20212 IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope,21269 return ir_build_cast(ira, source_instr, field_ptr_type, container_ptr, CastOpNoop);
20213 source_instr->source_node, field_ptr_type, container_ptr, CastOpNoop);
20214 result->value->type = field_ptr_type;
20215 return result;
20216}21270}
2021721271
20218static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,21272static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name,
20219 IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type, bool initializing)21273 IrInst* source_instr, IrInstGen *container_ptr, IrInst *container_ptr_src,
21274 ZigType *container_type, bool initializing)
20220{21275{
20221 Error err;21276 Error err;
2022221277
...@@ -20229,7 +21284,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -20229,7 +21284,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
20229 }21284 }
2023021285
20231 if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown)))21286 if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown)))
20232 return ira->codegen->invalid_instruction;21287 return ira->codegen->invalid_inst_gen;
2023321288
20234 assert(container_ptr->value->type->id == ZigTypeIdPointer);21289 assert(container_ptr->value->type->id == ZigTypeIdPointer);
20235 if (bare_type->id == ZigTypeIdStruct) {21290 if (bare_type->id == ZigTypeIdStruct) {
...@@ -20238,13 +21293,13 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -20238,13 +21293,13 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
20238 return ir_analyze_struct_field_ptr(ira, source_instr, field, container_ptr, bare_type, initializing);21293 return ir_analyze_struct_field_ptr(ira, source_instr, field, container_ptr, bare_type, initializing);
20239 } else {21294 } else {
20240 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,21295 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
20241 source_instr, container_ptr, container_type);21296 source_instr, container_ptr, container_ptr_src, container_type);
20242 }21297 }
20243 }21298 }
2024421299
20245 if (bare_type->id == ZigTypeIdEnum) {21300 if (bare_type->id == ZigTypeIdEnum) {
20246 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,21301 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
20247 source_instr, container_ptr, container_type);21302 source_instr, container_ptr, container_ptr_src, container_type);
20248 }21303 }
2024921304
20250 if (bare_type->id == ZigTypeIdUnion) {21305 if (bare_type->id == ZigTypeIdUnion) {
...@@ -20254,27 +21309,27 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -20254,27 +21309,27 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
20254 TypeUnionField *field = find_union_type_field(bare_type, field_name);21309 TypeUnionField *field = find_union_type_field(bare_type, field_name);
20255 if (field == nullptr) {21310 if (field == nullptr) {
20256 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,21311 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
20257 source_instr, container_ptr, container_type);21312 source_instr, container_ptr, container_ptr_src, container_type);
20258 }21313 }
2025921314
20260 ZigType *field_type = resolve_union_field_type(ira->codegen, field);21315 ZigType *field_type = resolve_union_field_type(ira->codegen, field);
20261 if (field_type == nullptr)21316 if (field_type == nullptr)
20262 return ira->codegen->invalid_instruction;21317 return ira->codegen->invalid_inst_gen;
2026321318
20264 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,21319 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
20265 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);21320 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);
20266 if (instr_is_comptime(container_ptr)) {21321 if (instr_is_comptime(container_ptr)) {
20267 ZigValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);21322 ZigValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
20268 if (!ptr_val)21323 if (!ptr_val)
20269 return ira->codegen->invalid_instruction;21324 return ira->codegen->invalid_inst_gen;
2027021325
20271 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&21326 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
20272 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {21327 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
20273 ZigValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);21328 ZigValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
20274 if (union_val == nullptr)21329 if (union_val == nullptr)
20275 return ira->codegen->invalid_instruction;21330 return ira->codegen->invalid_inst_gen;
20276 if (type_is_invalid(union_val->type))21331 if (type_is_invalid(union_val->type))
20277 return ira->codegen->invalid_instruction;21332 return ira->codegen->invalid_inst_gen;
2027821333
20279 if (initializing) {21334 if (initializing) {
20280 ZigValue *payload_val = create_const_vals(1);21335 ZigValue *payload_val = create_const_vals(1);
...@@ -20295,17 +21350,16 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -20295,17 +21350,16 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
20295 ir_add_error_node(ira, source_instr->source_node,21350 ir_add_error_node(ira, source_instr->source_node,
20296 buf_sprintf("accessing union field '%s' while field '%s' is set", buf_ptr(field_name),21351 buf_sprintf("accessing union field '%s' while field '%s' is set", buf_ptr(field_name),
20297 buf_ptr(actual_field->name)));21352 buf_ptr(actual_field->name)));
20298 return ira->codegen->invalid_instruction;21353 return ira->codegen->invalid_inst_gen;
20299 }21354 }
20300 }21355 }
2030121356
20302 ZigValue *payload_val = union_val->data.x_union.payload;21357 ZigValue *payload_val = union_val->data.x_union.payload;
2030321358
20304 IrInstruction *result;21359 IrInstGen *result;
20305 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {21360 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
20306 result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope,21361 result = ir_build_union_field_ptr(ira, source_instr, container_ptr, field, true,
20307 source_instr->source_node, container_ptr, field, true, initializing);21362 initializing, ptr_type);
20308 result->value->type = ptr_type;
20309 result->value->special = ConstValSpecialStatic;21363 result->value->special = ConstValSpecialStatic;
20310 } else {21364 } else {
20311 result = ir_const(ira, source_instr, ptr_type);21365 result = ir_const(ira, source_instr, ptr_type);
...@@ -20318,10 +21372,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_...@@ -20318,10 +21372,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
20318 }21372 }
20319 }21373 }
2032021374
20321 IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope,21375 return ir_build_union_field_ptr(ira, source_instr, container_ptr, field, true, initializing, ptr_type);
20322 source_instr->source_node, container_ptr, field, true, initializing);
20323 result->value->type = ptr_type;
20324 return result;
20325 }21376 }
2032621377
20327 zig_unreachable();21378 zig_unreachable();
...@@ -20362,16 +21413,18 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,...@@ -20362,16 +21413,18 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name,
20362 link_lib->symbols.append(symbol_name);21413 link_lib->symbols.append(symbol_name);
20363}21414}
2036421415
20365static IrInstruction *ir_error_dependency_loop(IrAnalyze *ira, IrInstruction *source_instr) {21416static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst* source_instr) {
20366 ir_add_error(ira, source_instr, buf_sprintf("dependency loop detected"));21417 ir_add_error(ira, source_instr, buf_sprintf("dependency loop detected"));
20367 return ira->codegen->invalid_instruction;21418 return ira->codegen->invalid_inst_gen;
20368}21419}
2036921420
20370static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) {21421static IrInstGen *ir_analyze_decl_ref(IrAnalyze *ira, IrInst* source_instruction, Tld *tld) {
20371 resolve_top_level_decl(ira->codegen, tld, source_instruction->source_node, true);21422 resolve_top_level_decl(ira->codegen, tld, source_instruction->source_node, true);
20372 if (tld->resolution == TldResolutionInvalid) {21423 if (tld->resolution == TldResolutionInvalid) {
20373 return ira->codegen->invalid_instruction;21424 return ira->codegen->invalid_inst_gen;
20374 }21425 }
21426 if (tld->resolution == TldResolutionResolving)
21427 return ir_error_dependency_loop(ira, source_instruction);
2037521428
20376 switch (tld->id) {21429 switch (tld->id) {
20377 case TldIdContainer:21430 case TldIdContainer:
...@@ -20381,9 +21434,8 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_...@@ -20381,9 +21434,8 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_
20381 case TldIdVar: {21434 case TldIdVar: {
20382 TldVar *tld_var = (TldVar *)tld;21435 TldVar *tld_var = (TldVar *)tld;
20383 ZigVar *var = tld_var->var;21436 ZigVar *var = tld_var->var;
20384 if (var == nullptr) {21437 assert(var != nullptr);
20385 return ir_error_dependency_loop(ira, source_instruction);21438
20386 }
20387 if (tld_var->extern_lib_name != nullptr) {21439 if (tld_var->extern_lib_name != nullptr) {
20388 add_link_lib_symbol(ira, tld_var->extern_lib_name, buf_create_from_str(var->name),21440 add_link_lib_symbol(ira, tld_var->extern_lib_name, buf_create_from_str(var->name),
20389 source_instruction->source_node);21441 source_instruction->source_node);
...@@ -20394,17 +21446,16 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_...@@ -20394,17 +21446,16 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_
20394 case TldIdFn: {21446 case TldIdFn: {
20395 TldFn *tld_fn = (TldFn *)tld;21447 TldFn *tld_fn = (TldFn *)tld;
20396 ZigFn *fn_entry = tld_fn->fn_entry;21448 ZigFn *fn_entry = tld_fn->fn_entry;
20397 assert(fn_entry->type_entry);21449 assert(fn_entry->type_entry != nullptr);
2039821450
20399 if (type_is_invalid(fn_entry->type_entry))21451 if (type_is_invalid(fn_entry->type_entry))
20400 return ira->codegen->invalid_instruction;21452 return ira->codegen->invalid_inst_gen;
2040121453
20402 if (tld_fn->extern_lib_name != nullptr) {21454 if (tld_fn->extern_lib_name != nullptr) {
20403 add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, source_instruction->source_node);21455 add_link_lib_symbol(ira, tld_fn->extern_lib_name, &fn_entry->symbol_name, source_instruction->source_node);
20404 }21456 }
2040521457
20406 IrInstruction *fn_inst = ir_create_const_fn(&ira->new_irb, source_instruction->scope,21458 IrInstGen *fn_inst = ir_const_fn(ira, source_instruction, fn_entry);
20407 source_instruction->source_node, fn_entry);
20408 return ir_get_ref(ira, source_instruction, fn_inst, true, false);21459 return ir_get_ref(ira, source_instruction, fn_inst, true, false);
20409 }21460 }
20410 }21461 }
...@@ -20422,40 +21473,44 @@ static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_n...@@ -20422,40 +21473,44 @@ static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_n
20422 return nullptr;21473 return nullptr;
20423}21474}
2042421475
20425static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) {21476static IrInstGen *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstSrcFieldPtr *field_ptr_instruction) {
20426 Error err;21477 Error err;
20427 IrInstruction *container_ptr = field_ptr_instruction->container_ptr->child;21478 IrInstGen *container_ptr = field_ptr_instruction->container_ptr->child;
20428 if (type_is_invalid(container_ptr->value->type))21479 if (type_is_invalid(container_ptr->value->type))
20429 return ira->codegen->invalid_instruction;21480 return ira->codegen->invalid_inst_gen;
2043021481
20431 ZigType *container_type = container_ptr->value->type->data.pointer.child_type;21482 ZigType *container_type = container_ptr->value->type->data.pointer.child_type;
2043221483
20433 Buf *field_name = field_ptr_instruction->field_name_buffer;21484 Buf *field_name = field_ptr_instruction->field_name_buffer;
20434 if (!field_name) {21485 if (!field_name) {
20435 IrInstruction *field_name_expr = field_ptr_instruction->field_name_expr->child;21486 IrInstGen *field_name_expr = field_ptr_instruction->field_name_expr->child;
20436 field_name = ir_resolve_str(ira, field_name_expr);21487 field_name = ir_resolve_str(ira, field_name_expr);
20437 if (!field_name)21488 if (!field_name)
20438 return ira->codegen->invalid_instruction;21489 return ira->codegen->invalid_inst_gen;
20439 }21490 }
2044021491
2044121492
20442 AstNode *source_node = field_ptr_instruction->base.source_node;21493 AstNode *source_node = field_ptr_instruction->base.base.source_node;
2044321494
20444 if (type_is_invalid(container_type)) {21495 if (type_is_invalid(container_type)) {
20445 return ira->codegen->invalid_instruction;21496 return ira->codegen->invalid_inst_gen;
20446 } else if (is_tuple(container_type) && !field_ptr_instruction->initializing && buf_eql_str(field_name, "len")) {21497 } else if (is_tuple(container_type) && !field_ptr_instruction->initializing && buf_eql_str(field_name, "len")) {
20447 IrInstruction *len_inst = ir_const_unsigned(ira, &field_ptr_instruction->base,21498 IrInstGen *len_inst = ir_const_unsigned(ira, &field_ptr_instruction->base.base,
20448 container_type->data.structure.src_field_count);21499 container_type->data.structure.src_field_count);
20449 return ir_get_ref(ira, &field_ptr_instruction->base, len_inst, true, false);21500 return ir_get_ref(ira, &field_ptr_instruction->base.base, len_inst, true, false);
20450 } else if (is_slice(container_type) || is_container_ref(container_type)) {21501 } else if (is_slice(container_type) || is_container_ref(container_type)) {
20451 assert(container_ptr->value->type->id == ZigTypeIdPointer);21502 assert(container_ptr->value->type->id == ZigTypeIdPointer);
20452 if (container_type->id == ZigTypeIdPointer) {21503 if (container_type->id == ZigTypeIdPointer) {
20453 ZigType *bare_type = container_ref_type(container_type);21504 ZigType *bare_type = container_ref_type(container_type);
20454 IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr, nullptr);21505 IrInstGen *container_child = ir_get_deref(ira, &field_ptr_instruction->base.base, container_ptr, nullptr);
20455 IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_child, bare_type, field_ptr_instruction->initializing);21506 IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base,
21507 container_child, &field_ptr_instruction->container_ptr->base, bare_type,
21508 field_ptr_instruction->initializing);
20456 return result;21509 return result;
20457 } else {21510 } else {
20458 IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_ptr, container_type, field_ptr_instruction->initializing);21511 IrInstGen *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base.base,
21512 container_ptr, &field_ptr_instruction->container_ptr->base, container_type,
21513 field_ptr_instruction->initializing);
20459 return result;21514 return result;
20460 }21515 }
20461 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {21516 } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) {
...@@ -20470,42 +21525,42 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -20470,42 +21525,42 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
20470 ZigType *usize = ira->codegen->builtin_types.entry_usize;21525 ZigType *usize = ira->codegen->builtin_types.entry_usize;
20471 bool ptr_is_const = true;21526 bool ptr_is_const = true;
20472 bool ptr_is_volatile = false;21527 bool ptr_is_volatile = false;
20473 return ir_get_const_ptr(ira, &field_ptr_instruction->base, len_val,21528 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, len_val,
20474 usize, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21529 usize, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20475 } else {21530 } else {
20476 ir_add_error_node(ira, source_node,21531 ir_add_error_node(ira, source_node,
20477 buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name),21532 buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name),
20478 buf_ptr(&container_type->name)));21533 buf_ptr(&container_type->name)));
20479 return ira->codegen->invalid_instruction;21534 return ira->codegen->invalid_inst_gen;
20480 }21535 }
20481 } else if (container_type->id == ZigTypeIdMetaType) {21536 } else if (container_type->id == ZigTypeIdMetaType) {
20482 ZigValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);21537 ZigValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
20483 if (!container_ptr_val)21538 if (!container_ptr_val)
20484 return ira->codegen->invalid_instruction;21539 return ira->codegen->invalid_inst_gen;
2048521540
20486 assert(container_ptr->value->type->id == ZigTypeIdPointer);21541 assert(container_ptr->value->type->id == ZigTypeIdPointer);
20487 ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);21542 ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);
20488 if (child_val == nullptr)21543 if (child_val == nullptr)
20489 return ira->codegen->invalid_instruction;21544 return ira->codegen->invalid_inst_gen;
20490 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,21545 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
20491 field_ptr_instruction->base.source_node, child_val, UndefBad)))21546 field_ptr_instruction->base.base.source_node, child_val, UndefBad)))
20492 {21547 {
20493 return ira->codegen->invalid_instruction;21548 return ira->codegen->invalid_inst_gen;
20494 }21549 }
20495 ZigType *child_type = child_val->data.x_type;21550 ZigType *child_type = child_val->data.x_type;
2049621551
20497 if (type_is_invalid(child_type)) {21552 if (type_is_invalid(child_type)) {
20498 return ira->codegen->invalid_instruction;21553 return ira->codegen->invalid_inst_gen;
20499 } else if (is_container(child_type)) {21554 } else if (is_container(child_type)) {
20500 if (child_type->id == ZigTypeIdEnum) {21555 if (child_type->id == ZigTypeIdEnum) {
20501 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown)))21556 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown)))
20502 return ira->codegen->invalid_instruction;21557 return ira->codegen->invalid_inst_gen;
2050321558
20504 TypeEnumField *field = find_enum_type_field(child_type, field_name);21559 TypeEnumField *field = find_enum_type_field(child_type, field_name);
20505 if (field) {21560 if (field) {
20506 bool ptr_is_const = true;21561 bool ptr_is_const = true;
20507 bool ptr_is_volatile = false;21562 bool ptr_is_volatile = false;
20508 return ir_get_const_ptr(ira, &field_ptr_instruction->base,21563 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
20509 create_const_enum(child_type, &field->value), child_type,21564 create_const_enum(child_type, &field->value), child_type,
20510 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21565 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20511 }21566 }
...@@ -20514,37 +21569,37 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -20514,37 +21569,37 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
20514 Tld *tld = find_container_decl(ira->codegen, container_scope, field_name);21569 Tld *tld = find_container_decl(ira->codegen, container_scope, field_name);
20515 if (tld) {21570 if (tld) {
20516 if (tld->visib_mod == VisibModPrivate &&21571 if (tld->visib_mod == VisibModPrivate &&
20517 tld->import != get_scope_import(field_ptr_instruction->base.scope))21572 tld->import != get_scope_import(field_ptr_instruction->base.base.scope))
20518 {21573 {
20519 ErrorMsg *msg = ir_add_error(ira, &field_ptr_instruction->base,21574 ErrorMsg *msg = ir_add_error(ira, &field_ptr_instruction->base.base,
20520 buf_sprintf("'%s' is private", buf_ptr(field_name)));21575 buf_sprintf("'%s' is private", buf_ptr(field_name)));
20521 add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here"));21576 add_error_note(ira->codegen, msg, tld->source_node, buf_sprintf("declared here"));
20522 return ira->codegen->invalid_instruction;21577 return ira->codegen->invalid_inst_gen;
20523 }21578 }
20524 return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld);21579 return ir_analyze_decl_ref(ira, &field_ptr_instruction->base.base, tld);
20525 }21580 }
20526 if (child_type->id == ZigTypeIdUnion &&21581 if (child_type->id == ZigTypeIdUnion &&
20527 (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr ||21582 (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr ||
20528 child_type->data.unionation.decl_node->data.container_decl.auto_enum))21583 child_type->data.unionation.decl_node->data.container_decl.auto_enum))
20529 {21584 {
20530 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown)))21585 if ((err = type_resolve(ira->codegen, child_type, ResolveStatusSizeKnown)))
20531 return ira->codegen->invalid_instruction;21586 return ira->codegen->invalid_inst_gen;
20532 TypeUnionField *field = find_union_type_field(child_type, field_name);21587 TypeUnionField *field = find_union_type_field(child_type, field_name);
20533 if (field) {21588 if (field) {
20534 ZigType *enum_type = child_type->data.unionation.tag_type;21589 ZigType *enum_type = child_type->data.unionation.tag_type;
20535 bool ptr_is_const = true;21590 bool ptr_is_const = true;
20536 bool ptr_is_volatile = false;21591 bool ptr_is_volatile = false;
20537 return ir_get_const_ptr(ira, &field_ptr_instruction->base,21592 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
20538 create_const_enum(enum_type, &field->enum_field->value), enum_type,21593 create_const_enum(enum_type, &field->enum_field->value), enum_type,
20539 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21594 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20540 }21595 }
20541 }21596 }
20542 const char *container_name = (child_type == ira->codegen->root_import) ?21597 const char *container_name = (child_type == ira->codegen->root_import) ?
20543 "root source file" : buf_ptr(buf_sprintf("container '%s'", buf_ptr(&child_type->name)));21598 "root source file" : buf_ptr(buf_sprintf("container '%s'", buf_ptr(&child_type->name)));
20544 ir_add_error(ira, &field_ptr_instruction->base,21599 ir_add_error(ira, &field_ptr_instruction->base.base,
20545 buf_sprintf("%s has no member called '%s'",21600 buf_sprintf("%s has no member called '%s'",
20546 container_name, buf_ptr(field_name)));21601 container_name, buf_ptr(field_name)));
20547 return ira->codegen->invalid_instruction;21602 return ira->codegen->invalid_inst_gen;
20548 } else if (child_type->id == ZigTypeIdErrorSet) {21603 } else if (child_type->id == ZigTypeIdErrorSet) {
20549 ErrorTableEntry *err_entry;21604 ErrorTableEntry *err_entry;
20550 ZigType *err_set_type;21605 ZigType *err_set_type;
...@@ -20554,7 +21609,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -20554,7 +21609,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
20554 err_entry = existing_entry->value;21609 err_entry = existing_entry->value;
20555 } else {21610 } else {
20556 err_entry = allocate<ErrorTableEntry>(1);21611 err_entry = allocate<ErrorTableEntry>(1);
20557 err_entry->decl_node = field_ptr_instruction->base.source_node;21612 err_entry->decl_node = field_ptr_instruction->base.base.source_node;
20558 buf_init_from_buf(&err_entry->name, field_name);21613 buf_init_from_buf(&err_entry->name, field_name);
20559 size_t error_value_count = ira->codegen->errors_by_index.length;21614 size_t error_value_count = ira->codegen->errors_by_index.length;
20560 assert((uint32_t)error_value_count < (((uint32_t)1) << (uint32_t)ira->codegen->err_tag_type->data.integral.bit_count));21615 assert((uint32_t)error_value_count < (((uint32_t)1) << (uint32_t)ira->codegen->err_tag_type->data.integral.bit_count));
...@@ -20564,19 +21619,19 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -20564,19 +21619,19 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
20564 }21619 }
20565 if (err_entry->set_with_only_this_in_it == nullptr) {21620 if (err_entry->set_with_only_this_in_it == nullptr) {
20566 err_entry->set_with_only_this_in_it = make_err_set_with_one_item(ira->codegen,21621 err_entry->set_with_only_this_in_it = make_err_set_with_one_item(ira->codegen,
20567 field_ptr_instruction->base.scope, field_ptr_instruction->base.source_node,21622 field_ptr_instruction->base.base.scope, field_ptr_instruction->base.base.source_node,
20568 err_entry);21623 err_entry);
20569 }21624 }
20570 err_set_type = err_entry->set_with_only_this_in_it;21625 err_set_type = err_entry->set_with_only_this_in_it;
20571 } else {21626 } else {
20572 if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.source_node)) {21627 if (!resolve_inferred_error_set(ira->codegen, child_type, field_ptr_instruction->base.base.source_node)) {
20573 return ira->codegen->invalid_instruction;21628 return ira->codegen->invalid_inst_gen;
20574 }21629 }
20575 err_entry = find_err_table_entry(child_type, field_name);21630 err_entry = find_err_table_entry(child_type, field_name);
20576 if (err_entry == nullptr) {21631 if (err_entry == nullptr) {
20577 ir_add_error(ira, &field_ptr_instruction->base,21632 ir_add_error(ira, &field_ptr_instruction->base.base,
20578 buf_sprintf("no error named '%s' in '%s'", buf_ptr(field_name), buf_ptr(&child_type->name)));21633 buf_sprintf("no error named '%s' in '%s'", buf_ptr(field_name), buf_ptr(&child_type->name)));
20579 return ira->codegen->invalid_instruction;21634 return ira->codegen->invalid_inst_gen;
20580 }21635 }
20581 err_set_type = child_type;21636 err_set_type = child_type;
20582 }21637 }
...@@ -20587,13 +21642,13 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -20587,13 +21642,13 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
2058721642
20588 bool ptr_is_const = true;21643 bool ptr_is_const = true;
20589 bool ptr_is_volatile = false;21644 bool ptr_is_volatile = false;
20590 return ir_get_const_ptr(ira, &field_ptr_instruction->base, const_val,21645 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base, const_val,
20591 err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21646 err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20592 } else if (child_type->id == ZigTypeIdInt) {21647 } else if (child_type->id == ZigTypeIdInt) {
20593 if (buf_eql_str(field_name, "bit_count")) {21648 if (buf_eql_str(field_name, "bit_count")) {
20594 bool ptr_is_const = true;21649 bool ptr_is_const = true;
20595 bool ptr_is_volatile = false;21650 bool ptr_is_volatile = false;
20596 return ir_get_const_ptr(ira, &field_ptr_instruction->base,21651 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
20597 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,21652 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
20598 child_type->data.integral.bit_count, false),21653 child_type->data.integral.bit_count, false),
20599 ira->codegen->builtin_types.entry_num_lit_int,21654 ira->codegen->builtin_types.entry_num_lit_int,
...@@ -20601,36 +21656,36 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -20601,36 +21656,36 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
20601 } else if (buf_eql_str(field_name, "is_signed")) {21656 } else if (buf_eql_str(field_name, "is_signed")) {
20602 bool ptr_is_const = true;21657 bool ptr_is_const = true;
20603 bool ptr_is_volatile = false;21658 bool ptr_is_volatile = false;
20604 return ir_get_const_ptr(ira, &field_ptr_instruction->base,21659 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
20605 create_const_bool(ira->codegen, child_type->data.integral.is_signed),21660 create_const_bool(ira->codegen, child_type->data.integral.is_signed),
20606 ira->codegen->builtin_types.entry_bool,21661 ira->codegen->builtin_types.entry_bool,
20607 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21662 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20608 } else {21663 } else {
20609 ir_add_error(ira, &field_ptr_instruction->base,21664 ir_add_error(ira, &field_ptr_instruction->base.base,
20610 buf_sprintf("type '%s' has no member called '%s'",21665 buf_sprintf("type '%s' has no member called '%s'",
20611 buf_ptr(&child_type->name), buf_ptr(field_name)));21666 buf_ptr(&child_type->name), buf_ptr(field_name)));
20612 return ira->codegen->invalid_instruction;21667 return ira->codegen->invalid_inst_gen;
20613 }21668 }
20614 } else if (child_type->id == ZigTypeIdFloat) {21669 } else if (child_type->id == ZigTypeIdFloat) {
20615 if (buf_eql_str(field_name, "bit_count")) {21670 if (buf_eql_str(field_name, "bit_count")) {
20616 bool ptr_is_const = true;21671 bool ptr_is_const = true;
20617 bool ptr_is_volatile = false;21672 bool ptr_is_volatile = false;
20618 return ir_get_const_ptr(ira, &field_ptr_instruction->base,21673 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
20619 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,21674 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
20620 child_type->data.floating.bit_count, false),21675 child_type->data.floating.bit_count, false),
20621 ira->codegen->builtin_types.entry_num_lit_int,21676 ira->codegen->builtin_types.entry_num_lit_int,
20622 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21677 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20623 } else {21678 } else {
20624 ir_add_error(ira, &field_ptr_instruction->base,21679 ir_add_error(ira, &field_ptr_instruction->base.base,
20625 buf_sprintf("type '%s' has no member called '%s'",21680 buf_sprintf("type '%s' has no member called '%s'",
20626 buf_ptr(&child_type->name), buf_ptr(field_name)));21681 buf_ptr(&child_type->name), buf_ptr(field_name)));
20627 return ira->codegen->invalid_instruction;21682 return ira->codegen->invalid_inst_gen;
20628 }21683 }
20629 } else if (child_type->id == ZigTypeIdPointer) {21684 } else if (child_type->id == ZigTypeIdPointer) {
20630 if (buf_eql_str(field_name, "Child")) {21685 if (buf_eql_str(field_name, "Child")) {
20631 bool ptr_is_const = true;21686 bool ptr_is_const = true;
20632 bool ptr_is_volatile = false;21687 bool ptr_is_volatile = false;
20633 return ir_get_const_ptr(ira, &field_ptr_instruction->base,21688 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
20634 create_const_type(ira->codegen, child_type->data.pointer.child_type),21689 create_const_type(ira->codegen, child_type->data.pointer.child_type),
20635 ira->codegen->builtin_types.entry_type,21690 ira->codegen->builtin_types.entry_type,
20636 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21691 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
...@@ -20640,75 +21695,75 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -20640,75 +21695,75 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
20640 if ((err = type_resolve(ira->codegen, child_type->data.pointer.child_type,21695 if ((err = type_resolve(ira->codegen, child_type->data.pointer.child_type,
20641 ResolveStatusAlignmentKnown)))21696 ResolveStatusAlignmentKnown)))
20642 {21697 {
20643 return ira->codegen->invalid_instruction;21698 return ira->codegen->invalid_inst_gen;
20644 }21699 }
20645 return ir_get_const_ptr(ira, &field_ptr_instruction->base,21700 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
20646 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,21701 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
20647 get_ptr_align(ira->codegen, child_type), false),21702 get_ptr_align(ira->codegen, child_type), false),
20648 ira->codegen->builtin_types.entry_num_lit_int,21703 ira->codegen->builtin_types.entry_num_lit_int,
20649 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21704 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20650 } else {21705 } else {
20651 ir_add_error(ira, &field_ptr_instruction->base,21706 ir_add_error(ira, &field_ptr_instruction->base.base,
20652 buf_sprintf("type '%s' has no member called '%s'",21707 buf_sprintf("type '%s' has no member called '%s'",
20653 buf_ptr(&child_type->name), buf_ptr(field_name)));21708 buf_ptr(&child_type->name), buf_ptr(field_name)));
20654 return ira->codegen->invalid_instruction;21709 return ira->codegen->invalid_inst_gen;
20655 }21710 }
20656 } else if (child_type->id == ZigTypeIdArray) {21711 } else if (child_type->id == ZigTypeIdArray) {
20657 if (buf_eql_str(field_name, "Child")) {21712 if (buf_eql_str(field_name, "Child")) {
20658 bool ptr_is_const = true;21713 bool ptr_is_const = true;
20659 bool ptr_is_volatile = false;21714 bool ptr_is_volatile = false;
20660 return ir_get_const_ptr(ira, &field_ptr_instruction->base,21715 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
20661 create_const_type(ira->codegen, child_type->data.array.child_type),21716 create_const_type(ira->codegen, child_type->data.array.child_type),
20662 ira->codegen->builtin_types.entry_type,21717 ira->codegen->builtin_types.entry_type,
20663 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21718 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20664 } else if (buf_eql_str(field_name, "len")) {21719 } else if (buf_eql_str(field_name, "len")) {
20665 bool ptr_is_const = true;21720 bool ptr_is_const = true;
20666 bool ptr_is_volatile = false;21721 bool ptr_is_volatile = false;
20667 return ir_get_const_ptr(ira, &field_ptr_instruction->base,21722 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
20668 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,21723 create_const_unsigned_negative(ira->codegen->builtin_types.entry_num_lit_int,
20669 child_type->data.array.len, false),21724 child_type->data.array.len, false),
20670 ira->codegen->builtin_types.entry_num_lit_int,21725 ira->codegen->builtin_types.entry_num_lit_int,
20671 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21726 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20672 } else {21727 } else {
20673 ir_add_error(ira, &field_ptr_instruction->base,21728 ir_add_error(ira, &field_ptr_instruction->base.base,
20674 buf_sprintf("type '%s' has no member called '%s'",21729 buf_sprintf("type '%s' has no member called '%s'",
20675 buf_ptr(&child_type->name), buf_ptr(field_name)));21730 buf_ptr(&child_type->name), buf_ptr(field_name)));
20676 return ira->codegen->invalid_instruction;21731 return ira->codegen->invalid_inst_gen;
20677 }21732 }
20678 } else if (child_type->id == ZigTypeIdErrorUnion) {21733 } else if (child_type->id == ZigTypeIdErrorUnion) {
20679 if (buf_eql_str(field_name, "Payload")) {21734 if (buf_eql_str(field_name, "Payload")) {
20680 bool ptr_is_const = true;21735 bool ptr_is_const = true;
20681 bool ptr_is_volatile = false;21736 bool ptr_is_volatile = false;
20682 return ir_get_const_ptr(ira, &field_ptr_instruction->base,21737 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
20683 create_const_type(ira->codegen, child_type->data.error_union.payload_type),21738 create_const_type(ira->codegen, child_type->data.error_union.payload_type),
20684 ira->codegen->builtin_types.entry_type,21739 ira->codegen->builtin_types.entry_type,
20685 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21740 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20686 } else if (buf_eql_str(field_name, "ErrorSet")) {21741 } else if (buf_eql_str(field_name, "ErrorSet")) {
20687 bool ptr_is_const = true;21742 bool ptr_is_const = true;
20688 bool ptr_is_volatile = false;21743 bool ptr_is_volatile = false;
20689 return ir_get_const_ptr(ira, &field_ptr_instruction->base,21744 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
20690 create_const_type(ira->codegen, child_type->data.error_union.err_set_type),21745 create_const_type(ira->codegen, child_type->data.error_union.err_set_type),
20691 ira->codegen->builtin_types.entry_type,21746 ira->codegen->builtin_types.entry_type,
20692 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21747 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20693 } else {21748 } else {
20694 ir_add_error(ira, &field_ptr_instruction->base,21749 ir_add_error(ira, &field_ptr_instruction->base.base,
20695 buf_sprintf("type '%s' has no member called '%s'",21750 buf_sprintf("type '%s' has no member called '%s'",
20696 buf_ptr(&child_type->name), buf_ptr(field_name)));21751 buf_ptr(&child_type->name), buf_ptr(field_name)));
20697 return ira->codegen->invalid_instruction;21752 return ira->codegen->invalid_inst_gen;
20698 }21753 }
20699 } else if (child_type->id == ZigTypeIdOptional) {21754 } else if (child_type->id == ZigTypeIdOptional) {
20700 if (buf_eql_str(field_name, "Child")) {21755 if (buf_eql_str(field_name, "Child")) {
20701 bool ptr_is_const = true;21756 bool ptr_is_const = true;
20702 bool ptr_is_volatile = false;21757 bool ptr_is_volatile = false;
20703 return ir_get_const_ptr(ira, &field_ptr_instruction->base,21758 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
20704 create_const_type(ira->codegen, child_type->data.maybe.child_type),21759 create_const_type(ira->codegen, child_type->data.maybe.child_type),
20705 ira->codegen->builtin_types.entry_type,21760 ira->codegen->builtin_types.entry_type,
20706 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21761 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20707 } else {21762 } else {
20708 ir_add_error(ira, &field_ptr_instruction->base,21763 ir_add_error(ira, &field_ptr_instruction->base.base,
20709 buf_sprintf("type '%s' has no member called '%s'",21764 buf_sprintf("type '%s' has no member called '%s'",
20710 buf_ptr(&child_type->name), buf_ptr(field_name)));21765 buf_ptr(&child_type->name), buf_ptr(field_name)));
20711 return ira->codegen->invalid_instruction;21766 return ira->codegen->invalid_inst_gen;
20712 }21767 }
20713 } else if (child_type->id == ZigTypeIdFn) {21768 } else if (child_type->id == ZigTypeIdFn) {
20714 if (buf_eql_str(field_name, "ReturnType")) {21769 if (buf_eql_str(field_name, "ReturnType")) {
...@@ -20716,121 +21771,121 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc...@@ -20716,121 +21771,121 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
20716 // Return type can only ever be null, if the function is generic21771 // Return type can only ever be null, if the function is generic
20717 assert(child_type->data.fn.is_generic);21772 assert(child_type->data.fn.is_generic);
2071821773
20719 ir_add_error(ira, &field_ptr_instruction->base,21774 ir_add_error(ira, &field_ptr_instruction->base.base,
20720 buf_sprintf("ReturnType has not been resolved because '%s' is generic", buf_ptr(&child_type->name)));21775 buf_sprintf("ReturnType has not been resolved because '%s' is generic", buf_ptr(&child_type->name)));
20721 return ira->codegen->invalid_instruction;21776 return ira->codegen->invalid_inst_gen;
20722 }21777 }
2072321778
20724 bool ptr_is_const = true;21779 bool ptr_is_const = true;
20725 bool ptr_is_volatile = false;21780 bool ptr_is_volatile = false;
20726 return ir_get_const_ptr(ira, &field_ptr_instruction->base,21781 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
20727 create_const_type(ira->codegen, child_type->data.fn.fn_type_id.return_type),21782 create_const_type(ira->codegen, child_type->data.fn.fn_type_id.return_type),
20728 ira->codegen->builtin_types.entry_type,21783 ira->codegen->builtin_types.entry_type,
20729 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21784 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20730 } else if (buf_eql_str(field_name, "is_var_args")) {21785 } else if (buf_eql_str(field_name, "is_var_args")) {
20731 bool ptr_is_const = true;21786 bool ptr_is_const = true;
20732 bool ptr_is_volatile = false;21787 bool ptr_is_volatile = false;
20733 return ir_get_const_ptr(ira, &field_ptr_instruction->base,21788 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
20734 create_const_bool(ira->codegen, child_type->data.fn.fn_type_id.is_var_args),21789 create_const_bool(ira->codegen, child_type->data.fn.fn_type_id.is_var_args),
20735 ira->codegen->builtin_types.entry_bool,21790 ira->codegen->builtin_types.entry_bool,
20736 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21791 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20737 } else if (buf_eql_str(field_name, "arg_count")) {21792 } else if (buf_eql_str(field_name, "arg_count")) {
20738 bool ptr_is_const = true;21793 bool ptr_is_const = true;
20739 bool ptr_is_volatile = false;21794 bool ptr_is_volatile = false;
20740 return ir_get_const_ptr(ira, &field_ptr_instruction->base,21795 return ir_get_const_ptr(ira, &field_ptr_instruction->base.base,
20741 create_const_usize(ira->codegen, child_type->data.fn.fn_type_id.param_count),21796 create_const_usize(ira->codegen, child_type->data.fn.fn_type_id.param_count),
20742 ira->codegen->builtin_types.entry_usize,21797 ira->codegen->builtin_types.entry_usize,
20743 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);21798 ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20744 } else {21799 } else {
20745 ir_add_error(ira, &field_ptr_instruction->base,21800 ir_add_error(ira, &field_ptr_instruction->base.base,
20746 buf_sprintf("type '%s' has no member called '%s'",21801 buf_sprintf("type '%s' has no member called '%s'",
20747 buf_ptr(&child_type->name), buf_ptr(field_name)));21802 buf_ptr(&child_type->name), buf_ptr(field_name)));
20748 return ira->codegen->invalid_instruction;21803 return ira->codegen->invalid_inst_gen;
20749 }21804 }
20750 } else {21805 } else {
20751 ir_add_error(ira, &field_ptr_instruction->base,21806 ir_add_error(ira, &field_ptr_instruction->base.base,
20752 buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name)));21807 buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name)));
20753 return ira->codegen->invalid_instruction;21808 return ira->codegen->invalid_inst_gen;
20754 }21809 }
20755 } else if (field_ptr_instruction->initializing) {21810 } else if (field_ptr_instruction->initializing) {
20756 ir_add_error(ira, &field_ptr_instruction->base,21811 ir_add_error(ira, &field_ptr_instruction->base.base,
20757 buf_sprintf("type '%s' does not support struct initialization syntax", buf_ptr(&container_type->name)));21812 buf_sprintf("type '%s' does not support struct initialization syntax", buf_ptr(&container_type->name)));
20758 return ira->codegen->invalid_instruction;21813 return ira->codegen->invalid_inst_gen;
20759 } else {21814 } else {
20760 ir_add_error_node(ira, field_ptr_instruction->base.source_node,21815 ir_add_error_node(ira, field_ptr_instruction->base.base.source_node,
20761 buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name)));21816 buf_sprintf("type '%s' does not support field access", buf_ptr(&container_type->name)));
20762 return ira->codegen->invalid_instruction;21817 return ira->codegen->invalid_inst_gen;
20763 }21818 }
20764}21819}
2076521820
20766static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *instruction) {21821static IrInstGen *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstSrcStorePtr *instruction) {
20767 IrInstruction *ptr = instruction->ptr->child;21822 IrInstGen *ptr = instruction->ptr->child;
20768 if (type_is_invalid(ptr->value->type))21823 if (type_is_invalid(ptr->value->type))
20769 return ira->codegen->invalid_instruction;21824 return ira->codegen->invalid_inst_gen;
2077021825
20771 IrInstruction *value = instruction->value->child;21826 IrInstGen *value = instruction->value->child;
20772 if (type_is_invalid(value->value->type))21827 if (type_is_invalid(value->value->type))
20773 return ira->codegen->invalid_instruction;21828 return ira->codegen->invalid_inst_gen;
2077421829
20775 return ir_analyze_store_ptr(ira, &instruction->base, ptr, value, instruction->allow_write_through_const);21830 return ir_analyze_store_ptr(ira, &instruction->base.base, ptr, value, instruction->allow_write_through_const);
20776}21831}
2077721832
20778static IrInstruction *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *instruction) {21833static IrInstGen *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstSrcLoadPtr *instruction) {
20779 IrInstruction *ptr = instruction->ptr->child;21834 IrInstGen *ptr = instruction->ptr->child;
20780 if (type_is_invalid(ptr->value->type))21835 if (type_is_invalid(ptr->value->type))
20781 return ira->codegen->invalid_instruction;21836 return ira->codegen->invalid_inst_gen;
20782 return ir_get_deref(ira, &instruction->base, ptr, nullptr);21837 return ir_get_deref(ira, &instruction->base.base, ptr, nullptr);
20783}21838}
2078421839
20785static IrInstruction *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) {21840static IrInstGen *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstSrcTypeOf *typeof_instruction) {
20786 IrInstruction *expr_value = typeof_instruction->value->child;21841 IrInstGen *expr_value = typeof_instruction->value->child;
20787 ZigType *type_entry = expr_value->value->type;21842 ZigType *type_entry = expr_value->value->type;
20788 if (type_is_invalid(type_entry))21843 if (type_is_invalid(type_entry))
20789 return ira->codegen->invalid_instruction;21844 return ira->codegen->invalid_inst_gen;
20790 return ir_const_type(ira, &typeof_instruction->base, type_entry);21845 return ir_const_type(ira, &typeof_instruction->base.base, type_entry);
20791}21846}
2079221847
20793static IrInstruction *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSetCold *instruction) {21848static IrInstGen *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstSrcSetCold *instruction) {
20794 if (ira->new_irb.exec->is_inline) {21849 if (ira->new_irb.exec->is_inline) {
20795 // ignore setCold when running functions at compile time21850 // ignore setCold when running functions at compile time
20796 return ir_const_void(ira, &instruction->base);21851 return ir_const_void(ira, &instruction->base.base);
20797 }21852 }
2079821853
20799 IrInstruction *is_cold_value = instruction->is_cold->child;21854 IrInstGen *is_cold_value = instruction->is_cold->child;
20800 bool want_cold;21855 bool want_cold;
20801 if (!ir_resolve_bool(ira, is_cold_value, &want_cold))21856 if (!ir_resolve_bool(ira, is_cold_value, &want_cold))
20802 return ira->codegen->invalid_instruction;21857 return ira->codegen->invalid_inst_gen;
2080321858
20804 ZigFn *fn_entry = scope_fn_entry(instruction->base.scope);21859 ZigFn *fn_entry = scope_fn_entry(instruction->base.base.scope);
20805 if (fn_entry == nullptr) {21860 if (fn_entry == nullptr) {
20806 ir_add_error(ira, &instruction->base, buf_sprintf("@setCold outside function"));21861 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setCold outside function"));
20807 return ira->codegen->invalid_instruction;21862 return ira->codegen->invalid_inst_gen;
20808 }21863 }
2080921864
20810 if (fn_entry->set_cold_node != nullptr) {21865 if (fn_entry->set_cold_node != nullptr) {
20811 ErrorMsg *msg = ir_add_error(ira, &instruction->base, buf_sprintf("cold set twice in same function"));21866 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base, buf_sprintf("cold set twice in same function"));
20812 add_error_note(ira->codegen, msg, fn_entry->set_cold_node, buf_sprintf("first set here"));21867 add_error_note(ira->codegen, msg, fn_entry->set_cold_node, buf_sprintf("first set here"));
20813 return ira->codegen->invalid_instruction;21868 return ira->codegen->invalid_inst_gen;
20814 }21869 }
2081521870
20816 fn_entry->set_cold_node = instruction->base.source_node;21871 fn_entry->set_cold_node = instruction->base.base.source_node;
20817 fn_entry->is_cold = want_cold;21872 fn_entry->is_cold = want_cold;
2081821873
20819 return ir_const_void(ira, &instruction->base);21874 return ir_const_void(ira, &instruction->base.base);
20820}21875}
2082121876
20822static IrInstruction *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,21877static IrInstGen *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
20823 IrInstructionSetRuntimeSafety *set_runtime_safety_instruction)21878 IrInstSrcSetRuntimeSafety *set_runtime_safety_instruction)
20824{21879{
20825 if (ira->new_irb.exec->is_inline) {21880 if (ira->new_irb.exec->is_inline) {
20826 // ignore setRuntimeSafety when running functions at compile time21881 // ignore setRuntimeSafety when running functions at compile time
20827 return ir_const_void(ira, &set_runtime_safety_instruction->base);21882 return ir_const_void(ira, &set_runtime_safety_instruction->base.base);
20828 }21883 }
2082921884
20830 bool *safety_off_ptr;21885 bool *safety_off_ptr;
20831 AstNode **safety_set_node_ptr;21886 AstNode **safety_set_node_ptr;
2083221887
20833 Scope *scope = set_runtime_safety_instruction->base.scope;21888 Scope *scope = set_runtime_safety_instruction->base.base.scope;
20834 while (scope != nullptr) {21889 while (scope != nullptr) {
20835 if (scope->id == ScopeIdBlock) {21890 if (scope->id == ScopeIdBlock) {
20836 ScopeBlock *block_scope = (ScopeBlock *)scope;21891 ScopeBlock *block_scope = (ScopeBlock *)scope;
...@@ -20856,36 +21911,36 @@ static IrInstruction *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,...@@ -20856,36 +21911,36 @@ static IrInstruction *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
20856 }21911 }
20857 assert(scope != nullptr);21912 assert(scope != nullptr);
2085821913
20859 IrInstruction *safety_on_value = set_runtime_safety_instruction->safety_on->child;21914 IrInstGen *safety_on_value = set_runtime_safety_instruction->safety_on->child;
20860 bool want_runtime_safety;21915 bool want_runtime_safety;
20861 if (!ir_resolve_bool(ira, safety_on_value, &want_runtime_safety))21916 if (!ir_resolve_bool(ira, safety_on_value, &want_runtime_safety))
20862 return ira->codegen->invalid_instruction;21917 return ira->codegen->invalid_inst_gen;
2086321918
20864 AstNode *source_node = set_runtime_safety_instruction->base.source_node;21919 AstNode *source_node = set_runtime_safety_instruction->base.base.source_node;
20865 if (*safety_set_node_ptr) {21920 if (*safety_set_node_ptr) {
20866 ErrorMsg *msg = ir_add_error_node(ira, source_node,21921 ErrorMsg *msg = ir_add_error_node(ira, source_node,
20867 buf_sprintf("runtime safety set twice for same scope"));21922 buf_sprintf("runtime safety set twice for same scope"));
20868 add_error_note(ira->codegen, msg, *safety_set_node_ptr, buf_sprintf("first set here"));21923 add_error_note(ira->codegen, msg, *safety_set_node_ptr, buf_sprintf("first set here"));
20869 return ira->codegen->invalid_instruction;21924 return ira->codegen->invalid_inst_gen;
20870 }21925 }
20871 *safety_set_node_ptr = source_node;21926 *safety_set_node_ptr = source_node;
20872 *safety_off_ptr = !want_runtime_safety;21927 *safety_off_ptr = !want_runtime_safety;
2087321928
20874 return ir_const_void(ira, &set_runtime_safety_instruction->base);21929 return ir_const_void(ira, &set_runtime_safety_instruction->base.base);
20875}21930}
2087621931
20877static IrInstruction *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,21932static IrInstGen *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
20878 IrInstructionSetFloatMode *instruction)21933 IrInstSrcSetFloatMode *instruction)
20879{21934{
20880 if (ira->new_irb.exec->is_inline) {21935 if (ira->new_irb.exec->is_inline) {
20881 // ignore setFloatMode when running functions at compile time21936 // ignore setFloatMode when running functions at compile time
20882 return ir_const_void(ira, &instruction->base);21937 return ir_const_void(ira, &instruction->base.base);
20883 }21938 }
2088421939
20885 bool *fast_math_on_ptr;21940 bool *fast_math_on_ptr;
20886 AstNode **fast_math_set_node_ptr;21941 AstNode **fast_math_set_node_ptr;
2088721942
20888 Scope *scope = instruction->base.scope;21943 Scope *scope = instruction->base.base.scope;
20889 while (scope != nullptr) {21944 while (scope != nullptr) {
20890 if (scope->id == ScopeIdBlock) {21945 if (scope->id == ScopeIdBlock) {
20891 ScopeBlock *block_scope = (ScopeBlock *)scope;21946 ScopeBlock *block_scope = (ScopeBlock *)scope;
...@@ -20911,42 +21966,38 @@ static IrInstruction *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,...@@ -20911,42 +21966,38 @@ static IrInstruction *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
20911 }21966 }
20912 assert(scope != nullptr);21967 assert(scope != nullptr);
2091321968
20914 IrInstruction *float_mode_value = instruction->mode_value->child;21969 IrInstGen *float_mode_value = instruction->mode_value->child;
20915 FloatMode float_mode_scalar;21970 FloatMode float_mode_scalar;
20916 if (!ir_resolve_float_mode(ira, float_mode_value, &float_mode_scalar))21971 if (!ir_resolve_float_mode(ira, float_mode_value, &float_mode_scalar))
20917 return ira->codegen->invalid_instruction;21972 return ira->codegen->invalid_inst_gen;
2091821973
20919 AstNode *source_node = instruction->base.source_node;21974 AstNode *source_node = instruction->base.base.source_node;
20920 if (*fast_math_set_node_ptr) {21975 if (*fast_math_set_node_ptr) {
20921 ErrorMsg *msg = ir_add_error_node(ira, source_node,21976 ErrorMsg *msg = ir_add_error_node(ira, source_node,
20922 buf_sprintf("float mode set twice for same scope"));21977 buf_sprintf("float mode set twice for same scope"));
20923 add_error_note(ira->codegen, msg, *fast_math_set_node_ptr, buf_sprintf("first set here"));21978 add_error_note(ira->codegen, msg, *fast_math_set_node_ptr, buf_sprintf("first set here"));
20924 return ira->codegen->invalid_instruction;21979 return ira->codegen->invalid_inst_gen;
20925 }21980 }
20926 *fast_math_set_node_ptr = source_node;21981 *fast_math_set_node_ptr = source_node;
20927 *fast_math_on_ptr = (float_mode_scalar == FloatModeOptimized);21982 *fast_math_on_ptr = (float_mode_scalar == FloatModeOptimized);
2092821983
20929 return ir_const_void(ira, &instruction->base);21984 return ir_const_void(ira, &instruction->base.base);
20930}21985}
2093121986
20932static IrInstruction *ir_analyze_instruction_any_frame_type(IrAnalyze *ira,21987static IrInstGen *ir_analyze_instruction_any_frame_type(IrAnalyze *ira, IrInstSrcAnyFrameType *instruction) {
20933 IrInstructionAnyFrameType *instruction)
20934{
20935 ZigType *payload_type = nullptr;21988 ZigType *payload_type = nullptr;
20936 if (instruction->payload_type != nullptr) {21989 if (instruction->payload_type != nullptr) {
20937 payload_type = ir_resolve_type(ira, instruction->payload_type->child);21990 payload_type = ir_resolve_type(ira, instruction->payload_type->child);
20938 if (type_is_invalid(payload_type))21991 if (type_is_invalid(payload_type))
20939 return ira->codegen->invalid_instruction;21992 return ira->codegen->invalid_inst_gen;
20940 }21993 }
2094121994
20942 ZigType *any_frame_type = get_any_frame_type(ira->codegen, payload_type);21995 ZigType *any_frame_type = get_any_frame_type(ira->codegen, payload_type);
20943 return ir_const_type(ira, &instruction->base, any_frame_type);21996 return ir_const_type(ira, &instruction->base.base, any_frame_type);
20944}21997}
2094521998
20946static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,21999static IrInstGen *ir_analyze_instruction_slice_type(IrAnalyze *ira, IrInstSrcSliceType *slice_type_instruction) {
20947 IrInstructionSliceType *slice_type_instruction)22000 IrInstGen *result = ir_const(ira, &slice_type_instruction->base.base, ira->codegen->builtin_types.entry_type);
20948{
20949 IrInstruction *result = ir_const(ira, &slice_type_instruction->base, ira->codegen->builtin_types.entry_type);
20950 result->value->special = ConstValSpecialLazy;22001 result->value->special = ConstValSpecialLazy;
2095122002
20952 LazyValueSliceType *lazy_slice_type = allocate<LazyValueSliceType>(1, "LazyValueSliceType");22003 LazyValueSliceType *lazy_slice_type = allocate<LazyValueSliceType>(1, "LazyValueSliceType");
...@@ -20957,18 +22008,18 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,...@@ -20957,18 +22008,18 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
20957 if (slice_type_instruction->align_value != nullptr) {22008 if (slice_type_instruction->align_value != nullptr) {
20958 lazy_slice_type->align_inst = slice_type_instruction->align_value->child;22009 lazy_slice_type->align_inst = slice_type_instruction->align_value->child;
20959 if (ir_resolve_const(ira, lazy_slice_type->align_inst, LazyOk) == nullptr)22010 if (ir_resolve_const(ira, lazy_slice_type->align_inst, LazyOk) == nullptr)
20960 return ira->codegen->invalid_instruction;22011 return ira->codegen->invalid_inst_gen;
20961 }22012 }
2096222013
20963 if (slice_type_instruction->sentinel != nullptr) {22014 if (slice_type_instruction->sentinel != nullptr) {
20964 lazy_slice_type->sentinel = slice_type_instruction->sentinel->child;22015 lazy_slice_type->sentinel = slice_type_instruction->sentinel->child;
20965 if (ir_resolve_const(ira, lazy_slice_type->sentinel, LazyOk) == nullptr)22016 if (ir_resolve_const(ira, lazy_slice_type->sentinel, LazyOk) == nullptr)
20966 return ira->codegen->invalid_instruction;22017 return ira->codegen->invalid_inst_gen;
20967 }22018 }
2096822019
20969 lazy_slice_type->elem_type = slice_type_instruction->child_type->child;22020 lazy_slice_type->elem_type = slice_type_instruction->child_type->child;
20970 if (ir_resolve_type_lazy(ira, lazy_slice_type->elem_type) == nullptr)22021 if (ir_resolve_type_lazy(ira, lazy_slice_type->elem_type) == nullptr)
20971 return ira->codegen->invalid_instruction;22022 return ira->codegen->invalid_inst_gen;
2097222023
20973 lazy_slice_type->is_const = slice_type_instruction->is_const;22024 lazy_slice_type->is_const = slice_type_instruction->is_const;
20974 lazy_slice_type->is_volatile = slice_type_instruction->is_volatile;22025 lazy_slice_type->is_volatile = slice_type_instruction->is_volatile;
...@@ -20977,31 +22028,31 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,...@@ -20977,31 +22028,31 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira,
20977 return result;22028 return result;
20978}22029}
2097922030
20980static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAsmSrc *asm_instruction) {22031static IrInstGen *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstSrcAsm *asm_instruction) {
20981 Error err;22032 Error err;
2098222033
20983 assert(asm_instruction->base.source_node->type == NodeTypeAsmExpr);22034 assert(asm_instruction->base.base.source_node->type == NodeTypeAsmExpr);
2098422035
20985 AstNode *node = asm_instruction->base.source_node;22036 AstNode *node = asm_instruction->base.base.source_node;
20986 AstNodeAsmExpr *asm_expr = &asm_instruction->base.source_node->data.asm_expr;22037 AstNodeAsmExpr *asm_expr = &asm_instruction->base.base.source_node->data.asm_expr;
2098722038
20988 Buf *template_buf = ir_resolve_str(ira, asm_instruction->asm_template->child);22039 Buf *template_buf = ir_resolve_str(ira, asm_instruction->asm_template->child);
20989 if (template_buf == nullptr)22040 if (template_buf == nullptr)
20990 return ira->codegen->invalid_instruction;22041 return ira->codegen->invalid_inst_gen;
2099122042
20992 if (asm_instruction->is_global) {22043 if (asm_instruction->is_global) {
20993 buf_append_char(&ira->codegen->global_asm, '\n');22044 buf_append_char(&ira->codegen->global_asm, '\n');
20994 buf_append_buf(&ira->codegen->global_asm, template_buf);22045 buf_append_buf(&ira->codegen->global_asm, template_buf);
2099522046
20996 return ir_const_void(ira, &asm_instruction->base);22047 return ir_const_void(ira, &asm_instruction->base.base);
20997 }22048 }
2099822049
20999 if (!ir_emit_global_runtime_side_effect(ira, &asm_instruction->base))22050 if (!ir_emit_global_runtime_side_effect(ira, &asm_instruction->base.base))
21000 return ira->codegen->invalid_instruction;22051 return ira->codegen->invalid_inst_gen;
2100122052
21002 ZigList<AsmToken> tok_list = {};22053 ZigList<AsmToken> tok_list = {};
21003 if ((err = parse_asm_template(ira, node, template_buf, &tok_list))) {22054 if ((err = parse_asm_template(ira, node, template_buf, &tok_list))) {
21004 return ira->codegen->invalid_instruction;22055 return ira->codegen->invalid_inst_gen;
21005 }22056 }
2100622057
21007 for (size_t token_i = 0; token_i < tok_list.length; token_i += 1) {22058 for (size_t token_i = 0; token_i < tok_list.length; token_i += 1) {
...@@ -21015,15 +22066,15 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs...@@ -21015,15 +22066,15 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs
21015 add_node_error(ira->codegen, node,22066 add_node_error(ira->codegen, node,
21016 buf_sprintf("could not find '%.*s' in the inputs or outputs",22067 buf_sprintf("could not find '%.*s' in the inputs or outputs",
21017 len, ptr));22068 len, ptr));
21018 return ira->codegen->invalid_instruction;22069 return ira->codegen->invalid_inst_gen;
21019 }22070 }
21020 }22071 }
21021 }22072 }
2102222073
21023 // TODO validate the output types and variable types22074 // TODO validate the output types and variable types
2102422075
21025 IrInstruction **input_list = allocate<IrInstruction *>(asm_expr->input_list.length);22076 IrInstGen **input_list = allocate<IrInstGen *>(asm_expr->input_list.length);
21026 IrInstruction **output_types = allocate<IrInstruction *>(asm_expr->output_list.length);22077 IrInstGen **output_types = allocate<IrInstGen *>(asm_expr->output_list.length);
2102722078
21028 ZigType *return_type = ira->codegen->builtin_types.entry_void;22079 ZigType *return_type = ira->codegen->builtin_types.entry_void;
21029 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {22080 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {
...@@ -21032,39 +22083,34 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs...@@ -21032,39 +22083,34 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs
21032 output_types[i] = asm_instruction->output_types[i]->child;22083 output_types[i] = asm_instruction->output_types[i]->child;
21033 return_type = ir_resolve_type(ira, output_types[i]);22084 return_type = ir_resolve_type(ira, output_types[i]);
21034 if (type_is_invalid(return_type))22085 if (type_is_invalid(return_type))
21035 return ira->codegen->invalid_instruction;22086 return ira->codegen->invalid_inst_gen;
21036 }22087 }
21037 }22088 }
2103822089
21039 for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {22090 for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {
21040 IrInstruction *const input_value = asm_instruction->input_list[i]->child;22091 IrInstGen *const input_value = asm_instruction->input_list[i]->child;
21041 if (type_is_invalid(input_value->value->type))22092 if (type_is_invalid(input_value->value->type))
21042 return ira->codegen->invalid_instruction;22093 return ira->codegen->invalid_inst_gen;
2104322094
21044 if (instr_is_comptime(input_value) &&22095 if (instr_is_comptime(input_value) &&
21045 (input_value->value->type->id == ZigTypeIdComptimeInt ||22096 (input_value->value->type->id == ZigTypeIdComptimeInt ||
21046 input_value->value->type->id == ZigTypeIdComptimeFloat)) {22097 input_value->value->type->id == ZigTypeIdComptimeFloat)) {
21047 ir_add_error_node(ira, input_value->source_node,22098 ir_add_error(ira, &input_value->base,
21048 buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value->type->name)));22099 buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value->type->name)));
21049 return ira->codegen->invalid_instruction;22100 return ira->codegen->invalid_inst_gen;
21050 }22101 }
2105122102
21052 input_list[i] = input_value;22103 input_list[i] = input_value;
21053 }22104 }
2105422105
21055 IrInstruction *result = ir_build_asm_gen(ira,22106 return ir_build_asm_gen(ira, &asm_instruction->base.base,
21056 asm_instruction->base.scope, asm_instruction->base.source_node,
21057 template_buf, tok_list.items, tok_list.length,22107 template_buf, tok_list.items, tok_list.length,
21058 input_list, output_types, asm_instruction->output_vars, asm_instruction->return_count,22108 input_list, output_types, asm_instruction->output_vars, asm_instruction->return_count,
21059 asm_instruction->has_side_effects);22109 asm_instruction->has_side_effects, return_type);
21060 result->value->type = return_type;
21061 return result;
21062}22110}
2106322111
21064static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,22112static IrInstGen *ir_analyze_instruction_array_type(IrAnalyze *ira, IrInstSrcArrayType *array_type_instruction) {
21065 IrInstructionArrayType *array_type_instruction)22113 IrInstGen *result = ir_const(ira, &array_type_instruction->base.base, ira->codegen->builtin_types.entry_type);
21066{
21067 IrInstruction *result = ir_const(ira, &array_type_instruction->base, ira->codegen->builtin_types.entry_type);
21068 result->value->special = ConstValSpecialLazy;22114 result->value->special = ConstValSpecialLazy;
2106922115
21070 LazyValueArrayType *lazy_array_type = allocate<LazyValueArrayType>(1, "LazyValueArrayType");22116 LazyValueArrayType *lazy_array_type = allocate<LazyValueArrayType>(1, "LazyValueArrayType");
...@@ -21074,22 +22120,22 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,...@@ -21074,22 +22120,22 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira,
2107422120
21075 lazy_array_type->elem_type = array_type_instruction->child_type->child;22121 lazy_array_type->elem_type = array_type_instruction->child_type->child;
21076 if (ir_resolve_type_lazy(ira, lazy_array_type->elem_type) == nullptr)22122 if (ir_resolve_type_lazy(ira, lazy_array_type->elem_type) == nullptr)
21077 return ira->codegen->invalid_instruction;22123 return ira->codegen->invalid_inst_gen;
2107822124
21079 if (!ir_resolve_usize(ira, array_type_instruction->size->child, &lazy_array_type->length))22125 if (!ir_resolve_usize(ira, array_type_instruction->size->child, &lazy_array_type->length))
21080 return ira->codegen->invalid_instruction;22126 return ira->codegen->invalid_inst_gen;
2108122127
21082 if (array_type_instruction->sentinel != nullptr) {22128 if (array_type_instruction->sentinel != nullptr) {
21083 lazy_array_type->sentinel = array_type_instruction->sentinel->child;22129 lazy_array_type->sentinel = array_type_instruction->sentinel->child;
21084 if (ir_resolve_const(ira, lazy_array_type->sentinel, LazyOk) == nullptr)22130 if (ir_resolve_const(ira, lazy_array_type->sentinel, LazyOk) == nullptr)
21085 return ira->codegen->invalid_instruction;22131 return ira->codegen->invalid_inst_gen;
21086 }22132 }
2108722133
21088 return result;22134 return result;
21089}22135}
2109022136
21091static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructionSizeOf *instruction) {22137static IrInstGen *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstSrcSizeOf *instruction) {
21092 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);22138 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
21093 result->value->special = ConstValSpecialLazy;22139 result->value->special = ConstValSpecialLazy;
2109422140
21095 LazyValueSizeOf *lazy_size_of = allocate<LazyValueSizeOf>(1, "LazyValueSizeOf");22141 LazyValueSizeOf *lazy_size_of = allocate<LazyValueSizeOf>(1, "LazyValueSizeOf");
...@@ -21100,19 +22146,19 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructi...@@ -21100,19 +22146,19 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructi
2110022146
21101 lazy_size_of->target_type = instruction->type_value->child;22147 lazy_size_of->target_type = instruction->type_value->child;
21102 if (ir_resolve_type_lazy(ira, lazy_size_of->target_type) == nullptr)22148 if (ir_resolve_type_lazy(ira, lazy_size_of->target_type) == nullptr)
21103 return ira->codegen->invalid_instruction;22149 return ira->codegen->invalid_inst_gen;
2110422150
21105 return result;22151 return result;
21106}22152}
2110722153
21108static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *source_inst, IrInstruction *value) {22154static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value) {
21109 ZigType *type_entry = value->value->type;22155 ZigType *type_entry = value->value->type;
2111022156
21111 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.allow_zero) {22157 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.allow_zero) {
21112 if (instr_is_comptime(value)) {22158 if (instr_is_comptime(value)) {
21113 ZigValue *c_ptr_val = ir_resolve_const(ira, value, UndefOk);22159 ZigValue *c_ptr_val = ir_resolve_const(ira, value, UndefOk);
21114 if (c_ptr_val == nullptr)22160 if (c_ptr_val == nullptr)
21115 return ira->codegen->invalid_instruction;22161 return ira->codegen->invalid_inst_gen;
21116 if (c_ptr_val->special == ConstValSpecialUndef)22162 if (c_ptr_val->special == ConstValSpecialUndef)
21117 return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool);22163 return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool);
21118 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||22164 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||
...@@ -21121,25 +22167,19 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so...@@ -21121,25 +22167,19 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so
21121 return ir_const_bool(ira, source_inst, !is_null);22167 return ir_const_bool(ira, source_inst, !is_null);
21122 }22168 }
2112322169
21124 IrInstruction *result = ir_build_test_nonnull(&ira->new_irb,22170 return ir_build_test_non_null_gen(ira, source_inst, value);
21125 source_inst->scope, source_inst->source_node, value);
21126 result->value->type = ira->codegen->builtin_types.entry_bool;
21127 return result;
21128 } else if (type_entry->id == ZigTypeIdOptional) {22171 } else if (type_entry->id == ZigTypeIdOptional) {
21129 if (instr_is_comptime(value)) {22172 if (instr_is_comptime(value)) {
21130 ZigValue *maybe_val = ir_resolve_const(ira, value, UndefOk);22173 ZigValue *maybe_val = ir_resolve_const(ira, value, UndefOk);
21131 if (maybe_val == nullptr)22174 if (maybe_val == nullptr)
21132 return ira->codegen->invalid_instruction;22175 return ira->codegen->invalid_inst_gen;
21133 if (maybe_val->special == ConstValSpecialUndef)22176 if (maybe_val->special == ConstValSpecialUndef)
21134 return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool);22177 return ir_const_undef(ira, source_inst, ira->codegen->builtin_types.entry_bool);
2113522178
21136 return ir_const_bool(ira, source_inst, !optional_value_is_null(maybe_val));22179 return ir_const_bool(ira, source_inst, !optional_value_is_null(maybe_val));
21137 }22180 }
2113822181
21139 IrInstruction *result = ir_build_test_nonnull(&ira->new_irb,22182 return ir_build_test_non_null_gen(ira, source_inst, value);
21140 source_inst->scope, source_inst->source_node, value);
21141 result->value->type = ira->codegen->builtin_types.entry_bool;
21142 return result;
21143 } else if (type_entry->id == ZigTypeIdNull) {22183 } else if (type_entry->id == ZigTypeIdNull) {
21144 return ir_const_bool(ira, source_inst, false);22184 return ir_const_bool(ira, source_inst, false);
21145 } else {22185 } else {
...@@ -21147,51 +22187,53 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so...@@ -21147,51 +22187,53 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so
21147 }22187 }
21148}22188}
2114922189
21150static IrInstruction *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) {22190static IrInstGen *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstSrcTestNonNull *instruction) {
21151 IrInstruction *value = instruction->value->child;22191 IrInstGen *value = instruction->value->child;
21152 if (type_is_invalid(value->value->type))22192 if (type_is_invalid(value->value->type))
21153 return ira->codegen->invalid_instruction;22193 return ira->codegen->invalid_inst_gen;
2115422194
21155 return ir_analyze_test_non_null(ira, &instruction->base, value);22195 return ir_analyze_test_non_null(ira, &instruction->base.base, value);
21156}22196}
2115722197
21158static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstruction *source_instr,22198static IrInstGen *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInst* source_instr,
21159 IrInstruction *base_ptr, bool safety_check_on, bool initializing)22199 IrInstGen *base_ptr, bool safety_check_on, bool initializing)
21160{22200{
22201 Error err;
22202
21161 ZigType *type_entry = get_ptr_elem_type(ira->codegen, base_ptr);22203 ZigType *type_entry = get_ptr_elem_type(ira->codegen, base_ptr);
21162 if (type_is_invalid(type_entry))22204 if (type_is_invalid(type_entry))
21163 return ira->codegen->invalid_instruction;22205 return ira->codegen->invalid_inst_gen;
2116422206
21165 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.ptr_len == PtrLenC) {22207 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.ptr_len == PtrLenC) {
21166 if (instr_is_comptime(base_ptr)) {22208 if (instr_is_comptime(base_ptr)) {
21167 ZigValue *val = ir_resolve_const(ira, base_ptr, UndefBad);22209 ZigValue *val = ir_resolve_const(ira, base_ptr, UndefBad);
21168 if (!val)22210 if (!val)
21169 return ira->codegen->invalid_instruction;22211 return ira->codegen->invalid_inst_gen;
21170 if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {22212 if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
21171 ZigValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);22213 ZigValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node);
21172 if (c_ptr_val == nullptr)22214 if (c_ptr_val == nullptr)
21173 return ira->codegen->invalid_instruction;22215 return ira->codegen->invalid_inst_gen;
21174 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||22216 bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull ||
21175 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&22217 (c_ptr_val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
21176 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);22218 c_ptr_val->data.x_ptr.data.hard_coded_addr.addr == 0);
21177 if (is_null) {22219 if (is_null) {
21178 ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null"));22220 ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null"));
21179 return ira->codegen->invalid_instruction;22221 return ira->codegen->invalid_inst_gen;
21180 }22222 }
21181 return base_ptr;22223 return base_ptr;
21182 }22224 }
21183 }22225 }
21184 if (!safety_check_on)22226 if (!safety_check_on)
21185 return base_ptr;22227 return base_ptr;
21186 IrInstruction *c_ptr_val = ir_get_deref(ira, source_instr, base_ptr, nullptr);22228 IrInstGen *c_ptr_val = ir_get_deref(ira, source_instr, base_ptr, nullptr);
21187 ir_build_assert_non_null(ira, source_instr, c_ptr_val);22229 ir_build_assert_non_null(ira, source_instr, c_ptr_val);
21188 return base_ptr;22230 return base_ptr;
21189 }22231 }
2119022232
21191 if (type_entry->id != ZigTypeIdOptional) {22233 if (type_entry->id != ZigTypeIdOptional) {
21192 ir_add_error_node(ira, base_ptr->source_node,22234 ir_add_error(ira, &base_ptr->base,
21193 buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name)));22235 buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name)));
21194 return ira->codegen->invalid_instruction;22236 return ira->codegen->invalid_inst_gen;
21195 }22237 }
2119622238
21197 ZigType *child_type = type_entry->data.maybe.child_type;22239 ZigType *child_type = type_entry->data.maybe.child_type;
...@@ -21203,17 +22245,17 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr...@@ -21203,17 +22245,17 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
2120322245
21204 if (instr_is_comptime(base_ptr)) {22246 if (instr_is_comptime(base_ptr)) {
21205 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);22247 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);
21206 if (!ptr_val)22248 if (ptr_val == nullptr)
21207 return ira->codegen->invalid_instruction;22249 return ira->codegen->invalid_inst_gen;
21208 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {22250 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
21209 ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);22251 ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
21210 if (optional_val == nullptr)22252 if (optional_val == nullptr)
21211 return ira->codegen->invalid_instruction;22253 return ira->codegen->invalid_inst_gen;
2121222254
21213 if (initializing) {22255 if (initializing) {
21214 switch (type_has_one_possible_value(ira->codegen, child_type)) {22256 switch (type_has_one_possible_value(ira->codegen, child_type)) {
21215 case OnePossibleValueInvalid:22257 case OnePossibleValueInvalid:
21216 return ira->codegen->invalid_instruction;22258 return ira->codegen->invalid_inst_gen;
21217 case OnePossibleValueNo:22259 case OnePossibleValueNo:
21218 if (!same_comptime_repr) {22260 if (!same_comptime_repr) {
21219 ZigValue *payload_val = create_const_vals(1);22261 ZigValue *payload_val = create_const_vals(1);
...@@ -21227,27 +22269,25 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr...@@ -21227,27 +22269,25 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
21227 }22269 }
21228 break;22270 break;
21229 case OnePossibleValueYes: {22271 case OnePossibleValueYes: {
21230 ZigValue *pointee = create_const_vals(1);
21231 pointee->special = ConstValSpecialStatic;
21232 pointee->type = child_type;
21233 pointee->parent.id = ConstParentIdOptionalPayload;
21234 pointee->parent.data.p_optional_payload.optional_val = optional_val;
21235
21236 optional_val->special = ConstValSpecialStatic;22272 optional_val->special = ConstValSpecialStatic;
21237 optional_val->data.x_optional = pointee;22273 optional_val->data.x_optional = get_the_one_possible_value(ira->codegen, child_type);
21238 break;22274 break;
21239 }22275 }
21240 }22276 }
21241 } else if (optional_value_is_null(optional_val)) {22277 } else {
21242 ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null"));22278 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec,
21243 return ira->codegen->invalid_instruction;22279 source_instr->source_node, optional_val, UndefBad)))
22280 return ira->codegen->invalid_inst_gen;
22281 if (optional_value_is_null(optional_val)) {
22282 ir_add_error(ira, source_instr, buf_sprintf("unable to unwrap null"));
22283 return ira->codegen->invalid_inst_gen;
22284 }
21244 }22285 }
2124522286
21246 IrInstruction *result;22287 IrInstGen *result;
21247 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {22288 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
21248 result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope,22289 result = ir_build_optional_unwrap_ptr_gen(ira, source_instr, base_ptr, false,
21249 source_instr->source_node, base_ptr, false, initializing);22290 initializing, result_type);
21250 result->value->type = result_type;
21251 result->value->special = ConstValSpecialStatic;22291 result->value->special = ConstValSpecialStatic;
21252 } else {22292 } else {
21253 result = ir_const(ira, source_instr, result_type);22293 result = ir_const(ira, source_instr, result_type);
...@@ -21257,7 +22297,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr...@@ -21257,7 +22297,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
21257 result_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;22297 result_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut;
21258 switch (type_has_one_possible_value(ira->codegen, child_type)) {22298 switch (type_has_one_possible_value(ira->codegen, child_type)) {
21259 case OnePossibleValueInvalid:22299 case OnePossibleValueInvalid:
21260 return ira->codegen->invalid_instruction;22300 return ira->codegen->invalid_inst_gen;
21261 case OnePossibleValueNo:22301 case OnePossibleValueNo:
21262 if (same_comptime_repr) {22302 if (same_comptime_repr) {
21263 result_val->data.x_ptr.data.ref.pointee = optional_val;22303 result_val->data.x_ptr.data.ref.pointee = optional_val;
...@@ -21275,131 +22315,120 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr...@@ -21275,131 +22315,120 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
21275 }22315 }
21276 }22316 }
2127722317
21278 IrInstruction *result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope,22318 return ir_build_optional_unwrap_ptr_gen(ira, source_instr, base_ptr, safety_check_on,
21279 source_instr->source_node, base_ptr, safety_check_on, initializing);22319 initializing, result_type);
21280 result->value->type = result_type;
21281 return result;
21282}22320}
2128322321
21284static IrInstruction *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira,22322static IrInstGen *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira,
21285 IrInstructionOptionalUnwrapPtr *instruction)22323 IrInstSrcOptionalUnwrapPtr *instruction)
21286{22324{
21287 IrInstruction *base_ptr = instruction->base_ptr->child;22325 IrInstGen *base_ptr = instruction->base_ptr->child;
21288 if (type_is_invalid(base_ptr->value->type))22326 if (type_is_invalid(base_ptr->value->type))
21289 return ira->codegen->invalid_instruction;22327 return ira->codegen->invalid_inst_gen;
2129022328
21291 return ir_analyze_unwrap_optional_payload(ira, &instruction->base, base_ptr,22329 return ir_analyze_unwrap_optional_payload(ira, &instruction->base.base, base_ptr,
21292 instruction->safety_check_on, false);22330 instruction->safety_check_on, false);
21293}22331}
2129422332
21295static IrInstruction *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *instruction) {22333static IrInstGen *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstSrcCtz *instruction) {
21296 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);22334 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
21297 if (type_is_invalid(int_type))22335 if (type_is_invalid(int_type))
21298 return ira->codegen->invalid_instruction;22336 return ira->codegen->invalid_inst_gen;
2129922337
21300 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);22338 IrInstGen *op = ir_implicit_cast(ira, instruction->op->child, int_type);
21301 if (type_is_invalid(op->value->type))22339 if (type_is_invalid(op->value->type))
21302 return ira->codegen->invalid_instruction;22340 return ira->codegen->invalid_inst_gen;
2130322341
21304 if (int_type->data.integral.bit_count == 0)22342 if (int_type->data.integral.bit_count == 0)
21305 return ir_const_unsigned(ira, &instruction->base, 0);22343 return ir_const_unsigned(ira, &instruction->base.base, 0);
2130622344
21307 if (instr_is_comptime(op)) {22345 if (instr_is_comptime(op)) {
21308 ZigValue *val = ir_resolve_const(ira, op, UndefOk);22346 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
21309 if (val == nullptr)22347 if (val == nullptr)
21310 return ira->codegen->invalid_instruction;22348 return ira->codegen->invalid_inst_gen;
21311 if (val->special == ConstValSpecialUndef)22349 if (val->special == ConstValSpecialUndef)
21312 return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);22350 return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
21313 size_t result_usize = bigint_ctz(&op->value->data.x_bigint, int_type->data.integral.bit_count);22351 size_t result_usize = bigint_ctz(&op->value->data.x_bigint, int_type->data.integral.bit_count);
21314 return ir_const_unsigned(ira, &instruction->base, result_usize);22352 return ir_const_unsigned(ira, &instruction->base.base, result_usize);
21315 }22353 }
2131622354
21317 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);22355 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
21318 IrInstruction *result = ir_build_ctz(&ira->new_irb, instruction->base.scope,22356 return ir_build_ctz_gen(ira, &instruction->base.base, return_type, op);
21319 instruction->base.source_node, nullptr, op);
21320 result->value->type = return_type;
21321 return result;
21322}22357}
2132322358
21324static IrInstruction *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *instruction) {22359static IrInstGen *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstSrcClz *instruction) {
21325 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);22360 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
21326 if (type_is_invalid(int_type))22361 if (type_is_invalid(int_type))
21327 return ira->codegen->invalid_instruction;22362 return ira->codegen->invalid_inst_gen;
2132822363
21329 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);22364 IrInstGen *op = ir_implicit_cast(ira, instruction->op->child, int_type);
21330 if (type_is_invalid(op->value->type))22365 if (type_is_invalid(op->value->type))
21331 return ira->codegen->invalid_instruction;22366 return ira->codegen->invalid_inst_gen;
2133222367
21333 if (int_type->data.integral.bit_count == 0)22368 if (int_type->data.integral.bit_count == 0)
21334 return ir_const_unsigned(ira, &instruction->base, 0);22369 return ir_const_unsigned(ira, &instruction->base.base, 0);
2133522370
21336 if (instr_is_comptime(op)) {22371 if (instr_is_comptime(op)) {
21337 ZigValue *val = ir_resolve_const(ira, op, UndefOk);22372 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
21338 if (val == nullptr)22373 if (val == nullptr)
21339 return ira->codegen->invalid_instruction;22374 return ira->codegen->invalid_inst_gen;
21340 if (val->special == ConstValSpecialUndef)22375 if (val->special == ConstValSpecialUndef)
21341 return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);22376 return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
21342 size_t result_usize = bigint_clz(&op->value->data.x_bigint, int_type->data.integral.bit_count);22377 size_t result_usize = bigint_clz(&op->value->data.x_bigint, int_type->data.integral.bit_count);
21343 return ir_const_unsigned(ira, &instruction->base, result_usize);22378 return ir_const_unsigned(ira, &instruction->base.base, result_usize);
21344 }22379 }
2134522380
21346 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);22381 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
21347 IrInstruction *result = ir_build_clz(&ira->new_irb, instruction->base.scope,22382 return ir_build_clz_gen(ira, &instruction->base.base, return_type, op);
21348 instruction->base.source_node, nullptr, op);
21349 result->value->type = return_type;
21350 return result;
21351}22383}
2135222384
21353static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPopCount *instruction) {22385static IrInstGen *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstSrcPopCount *instruction) {
21354 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);22386 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
21355 if (type_is_invalid(int_type))22387 if (type_is_invalid(int_type))
21356 return ira->codegen->invalid_instruction;22388 return ira->codegen->invalid_inst_gen;
2135722389
21358 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);22390 IrInstGen *op = ir_implicit_cast(ira, instruction->op->child, int_type);
21359 if (type_is_invalid(op->value->type))22391 if (type_is_invalid(op->value->type))
21360 return ira->codegen->invalid_instruction;22392 return ira->codegen->invalid_inst_gen;
2136122393
21362 if (int_type->data.integral.bit_count == 0)22394 if (int_type->data.integral.bit_count == 0)
21363 return ir_const_unsigned(ira, &instruction->base, 0);22395 return ir_const_unsigned(ira, &instruction->base.base, 0);
2136422396
21365 if (instr_is_comptime(op)) {22397 if (instr_is_comptime(op)) {
21366 ZigValue *val = ir_resolve_const(ira, op, UndefOk);22398 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
21367 if (val == nullptr)22399 if (val == nullptr)
21368 return ira->codegen->invalid_instruction;22400 return ira->codegen->invalid_inst_gen;
21369 if (val->special == ConstValSpecialUndef)22401 if (val->special == ConstValSpecialUndef)
21370 return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);22402 return ir_const_undef(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
2137122403
21372 if (bigint_cmp_zero(&val->data.x_bigint) != CmpLT) {22404 if (bigint_cmp_zero(&val->data.x_bigint) != CmpLT) {
21373 size_t result = bigint_popcount_unsigned(&val->data.x_bigint);22405 size_t result = bigint_popcount_unsigned(&val->data.x_bigint);
21374 return ir_const_unsigned(ira, &instruction->base, result);22406 return ir_const_unsigned(ira, &instruction->base.base, result);
21375 }22407 }
21376 size_t result = bigint_popcount_signed(&val->data.x_bigint, int_type->data.integral.bit_count);22408 size_t result = bigint_popcount_signed(&val->data.x_bigint, int_type->data.integral.bit_count);
21377 return ir_const_unsigned(ira, &instruction->base, result);22409 return ir_const_unsigned(ira, &instruction->base.base, result);
21378 }22410 }
2137922411
21380 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);22412 ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count);
21381 IrInstruction *result = ir_build_pop_count(&ira->new_irb, instruction->base.scope,22413 return ir_build_pop_count_gen(ira, &instruction->base.base, return_type, op);
21382 instruction->base.source_node, nullptr, op);
21383 result->value->type = return_type;
21384 return result;
21385}22414}
2138622415
21387static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value) {22416static IrInstGen *ir_analyze_union_tag(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value, bool is_gen) {
21388 if (type_is_invalid(value->value->type))22417 if (type_is_invalid(value->value->type))
21389 return ira->codegen->invalid_instruction;22418 return ira->codegen->invalid_inst_gen;
2139022419
21391 if (value->value->type->id != ZigTypeIdUnion) {22420 if (value->value->type->id != ZigTypeIdUnion) {
21392 ir_add_error(ira, value,22421 ir_add_error(ira, &value->base,
21393 buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value->type->name)));22422 buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value->type->name)));
21394 return ira->codegen->invalid_instruction;22423 return ira->codegen->invalid_inst_gen;
21395 }22424 }
21396 if (!value->value->type->data.unionation.have_explicit_tag_type && !source_instr->is_gen) {22425 if (!value->value->type->data.unionation.have_explicit_tag_type && !is_gen) {
21397 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union has no associated enum"));22426 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union has no associated enum"));
21398 if (value->value->type->data.unionation.decl_node != nullptr) {22427 if (value->value->type->data.unionation.decl_node != nullptr) {
21399 add_error_note(ira->codegen, msg, value->value->type->data.unionation.decl_node,22428 add_error_note(ira->codegen, msg, value->value->type->data.unionation.decl_node,
21400 buf_sprintf("declared here"));22429 buf_sprintf("declared here"));
21401 }22430 }
21402 return ira->codegen->invalid_instruction;22431 return ira->codegen->invalid_inst_gen;
21403 }22432 }
2140422433
21405 ZigType *tag_type = value->value->type->data.unionation.tag_type;22434 ZigType *tag_type = value->value->type->data.unionation.tag_type;
...@@ -21408,9 +22437,9 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source...@@ -21408,9 +22437,9 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
21408 if (instr_is_comptime(value)) {22437 if (instr_is_comptime(value)) {
21409 ZigValue *val = ir_resolve_const(ira, value, UndefBad);22438 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
21410 if (!val)22439 if (!val)
21411 return ira->codegen->invalid_instruction;22440 return ira->codegen->invalid_inst_gen;
2141222441
21413 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,22442 IrInstGenConst *const_instruction = ir_create_inst_gen<IrInstGenConst>(&ira->new_irb,
21414 source_instr->scope, source_instr->source_node);22443 source_instr->scope, source_instr->source_node);
21415 const_instruction->base.value->type = tag_type;22444 const_instruction->base.value->type = tag_type;
21416 const_instruction->base.value->special = ConstValSpecialStatic;22445 const_instruction->base.value->special = ConstValSpecialStatic;
...@@ -21418,15 +22447,13 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source...@@ -21418,15 +22447,13 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source
21418 return &const_instruction->base;22447 return &const_instruction->base;
21419 }22448 }
2142022449
21421 IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope, source_instr->source_node, value);22450 return ir_build_union_tag(ira, source_instr, value, tag_type);
21422 result->value->type = tag_type;
21423 return result;
21424}22451}
2142522452
21426static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,22453static IrInstGen *ir_analyze_instruction_switch_br(IrAnalyze *ira,
21427 IrInstructionSwitchBr *switch_br_instruction)22454 IrInstSrcSwitchBr *switch_br_instruction)
21428{22455{
21429 IrInstruction *target_value = switch_br_instruction->target_value->child;22456 IrInstGen *target_value = switch_br_instruction->target_value->child;
21430 if (type_is_invalid(target_value->value->type))22457 if (type_is_invalid(target_value->value->type))
21431 return ir_unreach_error(ira);22458 return ir_unreach_error(ira);
2143222459
...@@ -21441,21 +22468,21 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -21441,21 +22468,21 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
2144122468
21442 bool is_comptime;22469 bool is_comptime;
21443 if (!ir_resolve_comptime(ira, switch_br_instruction->is_comptime->child, &is_comptime))22470 if (!ir_resolve_comptime(ira, switch_br_instruction->is_comptime->child, &is_comptime))
21444 return ira->codegen->invalid_instruction;22471 return ira->codegen->invalid_inst_gen;
2144522472
21446 if (is_comptime || instr_is_comptime(target_value)) {22473 if (is_comptime || instr_is_comptime(target_value)) {
21447 ZigValue *target_val = ir_resolve_const(ira, target_value, UndefBad);22474 ZigValue *target_val = ir_resolve_const(ira, target_value, UndefBad);
21448 if (!target_val)22475 if (!target_val)
21449 return ir_unreach_error(ira);22476 return ir_unreach_error(ira);
2145022477
21451 IrBasicBlock *old_dest_block = switch_br_instruction->else_block;22478 IrBasicBlockSrc *old_dest_block = switch_br_instruction->else_block;
21452 for (size_t i = 0; i < case_count; i += 1) {22479 for (size_t i = 0; i < case_count; i += 1) {
21453 IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i];22480 IrInstSrcSwitchBrCase *old_case = &switch_br_instruction->cases[i];
21454 IrInstruction *case_value = old_case->value->child;22481 IrInstGen *case_value = old_case->value->child;
21455 if (type_is_invalid(case_value->value->type))22482 if (type_is_invalid(case_value->value->type))
21456 return ir_unreach_error(ira);22483 return ir_unreach_error(ira);
2145722484
21458 IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value->type);22485 IrInstGen *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value->type);
21459 if (type_is_invalid(casted_case_value->value->type))22486 if (type_is_invalid(casted_case_value->value->type))
21460 return ir_unreach_error(ira);22487 return ir_unreach_error(ira);
2146122488
...@@ -21470,23 +22497,20 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -21470,23 +22497,20 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
21470 }22497 }
2147122498
21472 if (is_comptime || old_dest_block->ref_count == 1) {22499 if (is_comptime || old_dest_block->ref_count == 1) {
21473 return ir_inline_bb(ira, &switch_br_instruction->base, old_dest_block);22500 return ir_inline_bb(ira, &switch_br_instruction->base.base, old_dest_block);
21474 } else {22501 } else {
21475 IrBasicBlock *new_dest_block = ir_get_new_bb(ira, old_dest_block, &switch_br_instruction->base);22502 IrBasicBlockGen *new_dest_block = ir_get_new_bb(ira, old_dest_block, &switch_br_instruction->base.base);
21476 IrInstruction *result = ir_build_br(&ira->new_irb,22503 IrInstGen *result = ir_build_br_gen(ira, &switch_br_instruction->base.base, new_dest_block);
21477 switch_br_instruction->base.scope, switch_br_instruction->base.source_node,
21478 new_dest_block, nullptr);
21479 result->value->type = ira->codegen->builtin_types.entry_unreachable;
21480 return ir_finish_anal(ira, result);22504 return ir_finish_anal(ira, result);
21481 }22505 }
21482 }22506 }
2148322507
21484 IrInstructionSwitchBrCase *cases = allocate<IrInstructionSwitchBrCase>(case_count);22508 IrInstGenSwitchBrCase *cases = allocate<IrInstGenSwitchBrCase>(case_count);
21485 for (size_t i = 0; i < case_count; i += 1) {22509 for (size_t i = 0; i < case_count; i += 1) {
21486 IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i];22510 IrInstSrcSwitchBrCase *old_case = &switch_br_instruction->cases[i];
21487 IrInstructionSwitchBrCase *new_case = &cases[i];22511 IrInstGenSwitchBrCase *new_case = &cases[i];
21488 new_case->block = ir_get_new_bb(ira, old_case->block, &switch_br_instruction->base);22512 new_case->block = ir_get_new_bb(ira, old_case->block, &switch_br_instruction->base.base);
21489 new_case->value = ira->codegen->invalid_instruction;22513 new_case->value = ira->codegen->invalid_inst_gen;
2149022514
21491 // Calling ir_get_new_bb set the ref_instruction on the new basic block.22515 // Calling ir_get_new_bb set the ref_instruction on the new basic block.
21492 // However a switch br may branch to the same basic block which would trigger an22516 // However a switch br may branch to the same basic block which would trigger an
...@@ -21494,12 +22518,12 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -21494,12 +22518,12 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
21494 // it back after the loop.22518 // it back after the loop.
21495 new_case->block->ref_instruction = nullptr;22519 new_case->block->ref_instruction = nullptr;
2149622520
21497 IrInstruction *old_value = old_case->value;22521 IrInstSrc *old_value = old_case->value;
21498 IrInstruction *new_value = old_value->child;22522 IrInstGen *new_value = old_value->child;
21499 if (type_is_invalid(new_value->value->type))22523 if (type_is_invalid(new_value->value->type))
21500 continue;22524 continue;
2150122525
21502 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value->type);22526 IrInstGen *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value->type);
21503 if (type_is_invalid(casted_new_value->value->type))22527 if (type_is_invalid(casted_new_value->value->type))
21504 continue;22528 continue;
2150522529
...@@ -21510,47 +22534,45 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -21510,47 +22534,45 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira,
21510 }22534 }
2151122535
21512 for (size_t i = 0; i < case_count; i += 1) {22536 for (size_t i = 0; i < case_count; i += 1) {
21513 IrInstructionSwitchBrCase *new_case = &cases[i];22537 IrInstGenSwitchBrCase *new_case = &cases[i];
21514 if (new_case->value == ira->codegen->invalid_instruction)22538 if (type_is_invalid(new_case->value->value->type))
21515 return ir_unreach_error(ira);22539 return ir_unreach_error(ira);
21516 new_case->block->ref_instruction = &switch_br_instruction->base;22540 new_case->block->ref_instruction = &switch_br_instruction->base.base;
21517 }22541 }
2151822542
21519 IrBasicBlock *new_else_block = ir_get_new_bb(ira, switch_br_instruction->else_block, &switch_br_instruction->base);22543 IrBasicBlockGen *new_else_block = ir_get_new_bb(ira, switch_br_instruction->else_block, &switch_br_instruction->base.base);
21520 IrInstructionSwitchBr *switch_br = ir_build_switch_br(&ira->new_irb,22544 IrInstGenSwitchBr *switch_br = ir_build_switch_br_gen(ira, &switch_br_instruction->base.base,
21521 switch_br_instruction->base.scope, switch_br_instruction->base.source_node,22545 target_value, new_else_block, case_count, cases);
21522 target_value, new_else_block, case_count, cases, nullptr, nullptr);
21523 switch_br->base.value->type = ira->codegen->builtin_types.entry_unreachable;
21524 return ir_finish_anal(ira, &switch_br->base);22546 return ir_finish_anal(ira, &switch_br->base);
21525}22547}
2152622548
21527static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,22549static IrInstGen *ir_analyze_instruction_switch_target(IrAnalyze *ira,
21528 IrInstructionSwitchTarget *switch_target_instruction)22550 IrInstSrcSwitchTarget *switch_target_instruction)
21529{22551{
21530 Error err;22552 Error err;
21531 IrInstruction *target_value_ptr = switch_target_instruction->target_value_ptr->child;22553 IrInstGen *target_value_ptr = switch_target_instruction->target_value_ptr->child;
21532 if (type_is_invalid(target_value_ptr->value->type))22554 if (type_is_invalid(target_value_ptr->value->type))
21533 return ira->codegen->invalid_instruction;22555 return ira->codegen->invalid_inst_gen;
2153422556
21535 if (target_value_ptr->value->type->id == ZigTypeIdMetaType) {22557 if (target_value_ptr->value->type->id == ZigTypeIdMetaType) {
21536 assert(instr_is_comptime(target_value_ptr));22558 assert(instr_is_comptime(target_value_ptr));
21537 ZigType *ptr_type = target_value_ptr->value->data.x_type;22559 ZigType *ptr_type = target_value_ptr->value->data.x_type;
21538 assert(ptr_type->id == ZigTypeIdPointer);22560 assert(ptr_type->id == ZigTypeIdPointer);
21539 return ir_const_type(ira, &switch_target_instruction->base, ptr_type->data.pointer.child_type);22561 return ir_const_type(ira, &switch_target_instruction->base.base, ptr_type->data.pointer.child_type);
21540 }22562 }
2154122563
21542 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;22564 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;
21543 ZigValue *pointee_val = nullptr;22565 ZigValue *pointee_val = nullptr;
21544 if (instr_is_comptime(target_value_ptr) && target_value_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {22566 if (instr_is_comptime(target_value_ptr) && target_value_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
21545 pointee_val = const_ptr_pointee(ira, ira->codegen, target_value_ptr->value, target_value_ptr->source_node);22567 pointee_val = const_ptr_pointee(ira, ira->codegen, target_value_ptr->value, target_value_ptr->base.source_node);
21546 if (pointee_val == nullptr)22568 if (pointee_val == nullptr)
21547 return ira->codegen->invalid_instruction;22569 return ira->codegen->invalid_inst_gen;
2154822570
21549 if (pointee_val->special == ConstValSpecialRuntime)22571 if (pointee_val->special == ConstValSpecialRuntime)
21550 pointee_val = nullptr;22572 pointee_val = nullptr;
21551 }22573 }
21552 if ((err = type_resolve(ira->codegen, target_type, ResolveStatusSizeKnown)))22574 if ((err = type_resolve(ira->codegen, target_type, ResolveStatusSizeKnown)))
21553 return ira->codegen->invalid_instruction;22575 return ira->codegen->invalid_inst_gen;
2155422576
21555 switch (target_type->id) {22577 switch (target_type->id) {
21556 case ZigTypeIdInvalid:22578 case ZigTypeIdInvalid:
...@@ -21567,13 +22589,13 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -21567,13 +22589,13 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
21567 case ZigTypeIdFn:22589 case ZigTypeIdFn:
21568 case ZigTypeIdErrorSet: {22590 case ZigTypeIdErrorSet: {
21569 if (pointee_val) {22591 if (pointee_val) {
21570 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr);22592 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, nullptr);
21571 copy_const_val(result->value, pointee_val);22593 copy_const_val(result->value, pointee_val);
21572 result->value->type = target_type;22594 result->value->type = target_type;
21573 return result;22595 return result;
21574 }22596 }
2157522597
21576 IrInstruction *result = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr);22598 IrInstGen *result = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr);
21577 result->value->type = target_type;22599 result->value->type = target_type;
21578 return result;22600 return result;
21579 }22601 }
...@@ -21582,52 +22604,49 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -21582,52 +22604,49 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
21582 if (!decl_node->data.container_decl.auto_enum &&22604 if (!decl_node->data.container_decl.auto_enum &&
21583 decl_node->data.container_decl.init_arg_expr == nullptr)22605 decl_node->data.container_decl.init_arg_expr == nullptr)
21584 {22606 {
21585 ErrorMsg *msg = ir_add_error(ira, target_value_ptr,22607 ErrorMsg *msg = ir_add_error(ira, &target_value_ptr->base,
21586 buf_sprintf("switch on union which has no attached enum"));22608 buf_sprintf("switch on union which has no attached enum"));
21587 add_error_note(ira->codegen, msg, decl_node,22609 add_error_note(ira->codegen, msg, decl_node,
21588 buf_sprintf("consider 'union(enum)' here"));22610 buf_sprintf("consider 'union(enum)' here"));
21589 return ira->codegen->invalid_instruction;22611 return ira->codegen->invalid_inst_gen;
21590 }22612 }
21591 ZigType *tag_type = target_type->data.unionation.tag_type;22613 ZigType *tag_type = target_type->data.unionation.tag_type;
21592 assert(tag_type != nullptr);22614 assert(tag_type != nullptr);
21593 assert(tag_type->id == ZigTypeIdEnum);22615 assert(tag_type->id == ZigTypeIdEnum);
21594 if (pointee_val) {22616 if (pointee_val) {
21595 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type);22617 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, tag_type);
21596 bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_union.tag);22618 bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_union.tag);
21597 return result;22619 return result;
21598 }22620 }
21599 if (tag_type->data.enumeration.src_field_count == 1) {22621 if (tag_type->data.enumeration.src_field_count == 1) {
21600 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type);22622 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, tag_type);
21601 TypeEnumField *only_field = &tag_type->data.enumeration.fields[0];22623 TypeEnumField *only_field = &tag_type->data.enumeration.fields[0];
21602 bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value);22624 bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value);
21603 return result;22625 return result;
21604 }22626 }
2160522627
21606 IrInstruction *union_value = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr);22628 IrInstGen *union_value = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr);
21607 union_value->value->type = target_type;22629 union_value->value->type = target_type;
2160822630
21609 IrInstruction *union_tag_inst = ir_build_union_tag(&ira->new_irb, switch_target_instruction->base.scope,22631 return ir_build_union_tag(ira, &switch_target_instruction->base.base, union_value, tag_type);
21610 switch_target_instruction->base.source_node, union_value);
21611 union_tag_inst->value->type = tag_type;
21612 return union_tag_inst;
21613 }22632 }
21614 case ZigTypeIdEnum: {22633 case ZigTypeIdEnum: {
21615 if ((err = type_resolve(ira->codegen, target_type, ResolveStatusZeroBitsKnown)))22634 if ((err = type_resolve(ira->codegen, target_type, ResolveStatusZeroBitsKnown)))
21616 return ira->codegen->invalid_instruction;22635 return ira->codegen->invalid_inst_gen;
21617 if (target_type->data.enumeration.src_field_count == 1) {22636 if (target_type->data.enumeration.src_field_count == 1) {
21618 TypeEnumField *only_field = &target_type->data.enumeration.fields[0];22637 TypeEnumField *only_field = &target_type->data.enumeration.fields[0];
21619 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type);22638 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, target_type);
21620 bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value);22639 bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value);
21621 return result;22640 return result;
21622 }22641 }
2162322642
21624 if (pointee_val) {22643 if (pointee_val) {
21625 IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type);22644 IrInstGen *result = ir_const(ira, &switch_target_instruction->base.base, target_type);
21626 bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_enum_tag);22645 bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_enum_tag);
21627 return result;22646 return result;
21628 }22647 }
2162922648
21630 IrInstruction *enum_value = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr);22649 IrInstGen *enum_value = ir_get_deref(ira, &switch_target_instruction->base.base, target_value_ptr, nullptr);
21631 enum_value->value->type = target_type;22650 enum_value->value->type = target_type;
21632 return enum_value;22651 return enum_value;
21633 }22652 }
...@@ -21643,17 +22662,17 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,...@@ -21643,17 +22662,17 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
21643 case ZigTypeIdVector:22662 case ZigTypeIdVector:
21644 case ZigTypeIdFnFrame:22663 case ZigTypeIdFnFrame:
21645 case ZigTypeIdAnyFrame:22664 case ZigTypeIdAnyFrame:
21646 ir_add_error(ira, &switch_target_instruction->base,22665 ir_add_error(ira, &switch_target_instruction->base.base,
21647 buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name)));22666 buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name)));
21648 return ira->codegen->invalid_instruction;22667 return ira->codegen->invalid_inst_gen;
21649 }22668 }
21650 zig_unreachable();22669 zig_unreachable();
21651}22670}
2165222671
21653static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) {22672static IrInstGen *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstSrcSwitchVar *instruction) {
21654 IrInstruction *target_value_ptr = instruction->target_value_ptr->child;22673 IrInstGen *target_value_ptr = instruction->target_value_ptr->child;
21655 if (type_is_invalid(target_value_ptr->value->type))22674 if (type_is_invalid(target_value_ptr->value->type))
21656 return ira->codegen->invalid_instruction;22675 return ira->codegen->invalid_inst_gen;
2165722676
21658 ZigType *ref_type = target_value_ptr->value->type;22677 ZigType *ref_type = target_value_ptr->value->type;
21659 assert(ref_type->id == ZigTypeIdPointer);22678 assert(ref_type->id == ZigTypeIdPointer);
...@@ -21664,62 +22683,62 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru...@@ -21664,62 +22683,62 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
21664 assert(enum_type->id == ZigTypeIdEnum);22683 assert(enum_type->id == ZigTypeIdEnum);
21665 assert(instruction->prongs_len > 0);22684 assert(instruction->prongs_len > 0);
2166622685
21667 IrInstruction *first_prong_value = instruction->prongs_ptr[0]->child;22686 IrInstGen *first_prong_value = instruction->prongs_ptr[0]->child;
21668 if (type_is_invalid(first_prong_value->value->type))22687 if (type_is_invalid(first_prong_value->value->type))
21669 return ira->codegen->invalid_instruction;22688 return ira->codegen->invalid_inst_gen;
2167022689
21671 IrInstruction *first_casted_prong_value = ir_implicit_cast(ira, first_prong_value, enum_type);22690 IrInstGen *first_casted_prong_value = ir_implicit_cast(ira, first_prong_value, enum_type);
21672 if (type_is_invalid(first_casted_prong_value->value->type))22691 if (type_is_invalid(first_casted_prong_value->value->type))
21673 return ira->codegen->invalid_instruction;22692 return ira->codegen->invalid_inst_gen;
2167422693
21675 ZigValue *first_prong_val = ir_resolve_const(ira, first_casted_prong_value, UndefBad);22694 ZigValue *first_prong_val = ir_resolve_const(ira, first_casted_prong_value, UndefBad);
21676 if (first_prong_val == nullptr)22695 if (first_prong_val == nullptr)
21677 return ira->codegen->invalid_instruction;22696 return ira->codegen->invalid_inst_gen;
2167822697
21679 TypeUnionField *first_field = find_union_field_by_tag(target_type, &first_prong_val->data.x_enum_tag);22698 TypeUnionField *first_field = find_union_field_by_tag(target_type, &first_prong_val->data.x_enum_tag);
2168022699
21681 ErrorMsg *invalid_payload_msg = nullptr;22700 ErrorMsg *invalid_payload_msg = nullptr;
21682 for (size_t prong_i = 1; prong_i < instruction->prongs_len; prong_i += 1) {22701 for (size_t prong_i = 1; prong_i < instruction->prongs_len; prong_i += 1) {
21683 IrInstruction *this_prong_inst = instruction->prongs_ptr[prong_i]->child;22702 IrInstGen *this_prong_inst = instruction->prongs_ptr[prong_i]->child;
21684 if (type_is_invalid(this_prong_inst->value->type))22703 if (type_is_invalid(this_prong_inst->value->type))
21685 return ira->codegen->invalid_instruction;22704 return ira->codegen->invalid_inst_gen;
2168622705
21687 IrInstruction *this_casted_prong_value = ir_implicit_cast(ira, this_prong_inst, enum_type);22706 IrInstGen *this_casted_prong_value = ir_implicit_cast(ira, this_prong_inst, enum_type);
21688 if (type_is_invalid(this_casted_prong_value->value->type))22707 if (type_is_invalid(this_casted_prong_value->value->type))
21689 return ira->codegen->invalid_instruction;22708 return ira->codegen->invalid_inst_gen;
2169022709
21691 ZigValue *this_prong = ir_resolve_const(ira, this_casted_prong_value, UndefBad);22710 ZigValue *this_prong = ir_resolve_const(ira, this_casted_prong_value, UndefBad);
21692 if (this_prong == nullptr)22711 if (this_prong == nullptr)
21693 return ira->codegen->invalid_instruction;22712 return ira->codegen->invalid_inst_gen;
2169422713
21695 TypeUnionField *payload_field = find_union_field_by_tag(target_type, &this_prong->data.x_enum_tag);22714 TypeUnionField *payload_field = find_union_field_by_tag(target_type, &this_prong->data.x_enum_tag);
21696 ZigType *payload_type = payload_field->type_entry;22715 ZigType *payload_type = payload_field->type_entry;
21697 if (first_field->type_entry != payload_type) {22716 if (first_field->type_entry != payload_type) {
21698 if (invalid_payload_msg == nullptr) {22717 if (invalid_payload_msg == nullptr) {
21699 invalid_payload_msg = ir_add_error(ira, &instruction->base,22718 invalid_payload_msg = ir_add_error(ira, &instruction->base.base,
21700 buf_sprintf("capture group with incompatible types"));22719 buf_sprintf("capture group with incompatible types"));
21701 add_error_note(ira->codegen, invalid_payload_msg, first_prong_value->source_node,22720 add_error_note(ira->codegen, invalid_payload_msg, first_prong_value->base.source_node,
21702 buf_sprintf("type '%s' here", buf_ptr(&first_field->type_entry->name)));22721 buf_sprintf("type '%s' here", buf_ptr(&first_field->type_entry->name)));
21703 }22722 }
21704 add_error_note(ira->codegen, invalid_payload_msg, this_prong_inst->source_node,22723 add_error_note(ira->codegen, invalid_payload_msg, this_prong_inst->base.source_node,
21705 buf_sprintf("type '%s' here", buf_ptr(&payload_field->type_entry->name)));22724 buf_sprintf("type '%s' here", buf_ptr(&payload_field->type_entry->name)));
21706 }22725 }
21707 }22726 }
2170822727
21709 if (invalid_payload_msg != nullptr) {22728 if (invalid_payload_msg != nullptr) {
21710 return ira->codegen->invalid_instruction;22729 return ira->codegen->invalid_inst_gen;
21711 }22730 }
2171222731
21713 if (instr_is_comptime(target_value_ptr)) {22732 if (instr_is_comptime(target_value_ptr)) {
21714 ZigValue *target_val_ptr = ir_resolve_const(ira, target_value_ptr, UndefBad);22733 ZigValue *target_val_ptr = ir_resolve_const(ira, target_value_ptr, UndefBad);
21715 if (!target_value_ptr)22734 if (!target_value_ptr)
21716 return ira->codegen->invalid_instruction;22735 return ira->codegen->invalid_inst_gen;
2171722736
21718 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.source_node);22737 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.base.source_node);
21719 if (pointee_val == nullptr)22738 if (pointee_val == nullptr)
21720 return ira->codegen->invalid_instruction;22739 return ira->codegen->invalid_inst_gen;
2172122740
21722 IrInstruction *result = ir_const(ira, &instruction->base,22741 IrInstGen *result = ir_const(ira, &instruction->base.base,
21723 get_pointer_to_type(ira->codegen, first_field->type_entry,22742 get_pointer_to_type(ira->codegen, first_field->type_entry,
21724 target_val_ptr->type->data.pointer.is_const));22743 target_val_ptr->type->data.pointer.is_const));
21725 ZigValue *out_val = result->value;22744 ZigValue *out_val = result->value;
...@@ -21729,11 +22748,10 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru...@@ -21729,11 +22748,10 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
21729 return result;22748 return result;
21730 }22749 }
2173122750
21732 IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb,22751 ZigType *result_type = get_pointer_to_type(ira->codegen, first_field->type_entry,
21733 instruction->base.scope, instruction->base.source_node, target_value_ptr, first_field, false, false);
21734 result->value->type = get_pointer_to_type(ira->codegen, first_field->type_entry,
21735 target_value_ptr->value->type->data.pointer.is_const);22752 target_value_ptr->value->type->data.pointer.is_const);
21736 return result;22753 return ir_build_union_field_ptr(ira, &instruction->base.base, target_value_ptr, first_field,
22754 false, false, result_type);
21737 } else if (target_type->id == ZigTypeIdErrorSet) {22755 } else if (target_type->id == ZigTypeIdErrorSet) {
21738 // construct an error set from the prong values22756 // construct an error set from the prong values
21739 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);22757 ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet);
...@@ -21746,7 +22764,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru...@@ -21746,7 +22764,7 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
21746 for (size_t i = 0; i < instruction->prongs_len; i += 1) {22764 for (size_t i = 0; i < instruction->prongs_len; i += 1) {
21747 ErrorTableEntry *err = ir_resolve_error(ira, instruction->prongs_ptr[i]->child);22765 ErrorTableEntry *err = ir_resolve_error(ira, instruction->prongs_ptr[i]->child);
21748 if (err == nullptr)22766 if (err == nullptr)
21749 return ira->codegen->invalid_instruction;22767 return ira->codegen->invalid_inst_gen;
21750 error_list.append(err);22768 error_list.append(err);
21751 buf_appendf(&err_set_type->name, "%s,", buf_ptr(&err->name));22769 buf_appendf(&err_set_type->name, "%s,", buf_ptr(&err->name));
21752 }22770 }
...@@ -21762,29 +22780,29 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru...@@ -21762,29 +22780,29 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru
21762 ref_type->data.pointer.explicit_alignment,22780 ref_type->data.pointer.explicit_alignment,
21763 ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes,22781 ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes,
21764 ref_type->data.pointer.allow_zero);22782 ref_type->data.pointer.allow_zero);
21765 return ir_analyze_ptr_cast(ira, &instruction->base, target_value_ptr, new_target_value_ptr_type,22783 return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr,
21766 &instruction->base, false);22784 &instruction->target_value_ptr->base, new_target_value_ptr_type, &instruction->base.base, false);
21767 } else {22785 } else {
21768 ir_add_error(ira, &instruction->base,22786 ir_add_error(ira, &instruction->base.base,
21769 buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name)));22787 buf_sprintf("switch on type '%s' provides no expression parameter", buf_ptr(&target_type->name)));
21770 return ira->codegen->invalid_instruction;22788 return ira->codegen->invalid_inst_gen;
21771 }22789 }
21772}22790}
2177322791
21774static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,22792static IrInstGen *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
21775 IrInstructionSwitchElseVar *instruction)22793 IrInstSrcSwitchElseVar *instruction)
21776{22794{
21777 IrInstruction *target_value_ptr = instruction->target_value_ptr->child;22795 IrInstGen *target_value_ptr = instruction->target_value_ptr->child;
21778 if (type_is_invalid(target_value_ptr->value->type))22796 if (type_is_invalid(target_value_ptr->value->type))
21779 return ira->codegen->invalid_instruction;22797 return ira->codegen->invalid_inst_gen;
2178022798
21781 ZigType *ref_type = target_value_ptr->value->type;22799 ZigType *ref_type = target_value_ptr->value->type;
21782 assert(ref_type->id == ZigTypeIdPointer);22800 assert(ref_type->id == ZigTypeIdPointer);
21783 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;22801 ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type;
21784 if (target_type->id == ZigTypeIdErrorSet) {22802 if (target_type->id == ZigTypeIdErrorSet) {
21785 // make a new set that has the other cases removed22803 // make a new set that has the other cases removed
21786 if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.source_node)) {22804 if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.base.source_node)) {
21787 return ira->codegen->invalid_instruction;22805 return ira->codegen->invalid_inst_gen;
21788 }22806 }
21789 if (type_is_global_error_set(target_type)) {22807 if (type_is_global_error_set(target_type)) {
21790 // the type of the else capture variable still has to be the global error set.22808 // the type of the else capture variable still has to be the global error set.
...@@ -21793,18 +22811,20 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,...@@ -21793,18 +22811,20 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
21793 }22811 }
21794 // Make note of the errors handled by other cases22812 // Make note of the errors handled by other cases
21795 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length);22813 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(ira->codegen->errors_by_index.length);
21796 for (size_t case_i = 0; case_i < instruction->switch_br->case_count; case_i += 1) {22814 // We may not have any case in the switch if this is a lone else
21797 IrInstructionSwitchBrCase *br_case = &instruction->switch_br->cases[case_i];22815 const size_t switch_cases = instruction->switch_br ? instruction->switch_br->case_count : 0;
21798 IrInstruction *case_expr = br_case->value->child;22816 for (size_t case_i = 0; case_i < switch_cases; case_i += 1) {
22817 IrInstSrcSwitchBrCase *br_case = &instruction->switch_br->cases[case_i];
22818 IrInstGen *case_expr = br_case->value->child;
21799 if (case_expr->value->type->id == ZigTypeIdErrorSet) {22819 if (case_expr->value->type->id == ZigTypeIdErrorSet) {
21800 ErrorTableEntry *err = ir_resolve_error(ira, case_expr);22820 ErrorTableEntry *err = ir_resolve_error(ira, case_expr);
21801 if (err == nullptr)22821 if (err == nullptr)
21802 return ira->codegen->invalid_instruction;22822 return ira->codegen->invalid_inst_gen;
21803 errors[err->value] = err;22823 errors[err->value] = err;
21804 } else if (case_expr->value->type->id == ZigTypeIdMetaType) {22824 } else if (case_expr->value->type->id == ZigTypeIdMetaType) {
21805 ZigType *err_set_type = ir_resolve_type(ira, case_expr);22825 ZigType *err_set_type = ir_resolve_type(ira, case_expr);
21806 if (type_is_invalid(err_set_type))22826 if (type_is_invalid(err_set_type))
21807 return ira->codegen->invalid_instruction;22827 return ira->codegen->invalid_inst_gen;
21808 populate_error_set_table(errors, err_set_type);22828 populate_error_set_table(errors, err_set_type);
21809 } else {22829 } else {
21810 zig_unreachable();22830 zig_unreachable();
...@@ -21843,27 +22863,22 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,...@@ -21843,27 +22863,22 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira,
21843 ref_type->data.pointer.explicit_alignment,22863 ref_type->data.pointer.explicit_alignment,
21844 ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes,22864 ref_type->data.pointer.bit_offset_in_host, ref_type->data.pointer.host_int_bytes,
21845 ref_type->data.pointer.allow_zero);22865 ref_type->data.pointer.allow_zero);
21846 return ir_analyze_ptr_cast(ira, &instruction->base, target_value_ptr, new_target_value_ptr_type,22866 return ir_analyze_ptr_cast(ira, &instruction->base.base, target_value_ptr,
21847 &instruction->base, false);22867 &instruction->target_value_ptr->base, new_target_value_ptr_type, &instruction->base.base, false);
21848 }22868 }
2184922869
21850 return target_value_ptr;22870 return target_value_ptr;
21851}22871}
2185222872
21853static IrInstruction *ir_analyze_instruction_union_tag(IrAnalyze *ira, IrInstructionUnionTag *instruction) {22873static IrInstGen *ir_analyze_instruction_import(IrAnalyze *ira, IrInstSrcImport *import_instruction) {
21854 IrInstruction *value = instruction->value->child;
21855 return ir_analyze_union_tag(ira, &instruction->base, value);
21856}
21857
21858static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImport *import_instruction) {
21859 Error err;22874 Error err;
2186022875
21861 IrInstruction *name_value = import_instruction->name->child;22876 IrInstGen *name_value = import_instruction->name->child;
21862 Buf *import_target_str = ir_resolve_str(ira, name_value);22877 Buf *import_target_str = ir_resolve_str(ira, name_value);
21863 if (!import_target_str)22878 if (!import_target_str)
21864 return ira->codegen->invalid_instruction;22879 return ira->codegen->invalid_inst_gen;
2186522880
21866 AstNode *source_node = import_instruction->base.source_node;22881 AstNode *source_node = import_instruction->base.base.source_node;
21867 ZigType *import = source_node->owner;22882 ZigType *import = source_node->owner;
2186822883
21869 ZigType *target_import;22884 ZigType *target_import;
...@@ -21876,48 +22891,48 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio...@@ -21876,48 +22891,48 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio
21876 ir_add_error_node(ira, source_node,22891 ir_add_error_node(ira, source_node,
21877 buf_sprintf("import of file outside package path: '%s'",22892 buf_sprintf("import of file outside package path: '%s'",
21878 buf_ptr(import_target_path)));22893 buf_ptr(import_target_path)));
21879 return ira->codegen->invalid_instruction;22894 return ira->codegen->invalid_inst_gen;
21880 } else if (err == ErrorFileNotFound) {22895 } else if (err == ErrorFileNotFound) {
21881 ir_add_error_node(ira, source_node,22896 ir_add_error_node(ira, source_node,
21882 buf_sprintf("unable to find '%s'", buf_ptr(import_target_path)));22897 buf_sprintf("unable to find '%s'", buf_ptr(import_target_path)));
21883 return ira->codegen->invalid_instruction;22898 return ira->codegen->invalid_inst_gen;
21884 } else {22899 } else {
21885 ir_add_error_node(ira, source_node,22900 ir_add_error_node(ira, source_node,
21886 buf_sprintf("unable to open '%s': %s", buf_ptr(&full_path), err_str(err)));22901 buf_sprintf("unable to open '%s': %s", buf_ptr(&full_path), err_str(err)));
21887 return ira->codegen->invalid_instruction;22902 return ira->codegen->invalid_inst_gen;
21888 }22903 }
21889 }22904 }
2189022905
21891 return ir_const_type(ira, &import_instruction->base, target_import);22906 return ir_const_type(ira, &import_instruction->base.base, target_import);
21892}22907}
2189322908
21894static IrInstruction *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) {22909static IrInstGen *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstSrcRef *ref_instruction) {
21895 IrInstruction *value = ref_instruction->value->child;22910 IrInstGen *value = ref_instruction->value->child;
21896 if (type_is_invalid(value->value->type))22911 if (type_is_invalid(value->value->type))
21897 return ira->codegen->invalid_instruction;22912 return ira->codegen->invalid_inst_gen;
21898 return ir_get_ref(ira, &ref_instruction->base, value, ref_instruction->is_const, ref_instruction->is_volatile);22913 return ir_get_ref(ira, &ref_instruction->base.base, value, ref_instruction->is_const, ref_instruction->is_volatile);
21899}22914}
2190022915
21901static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *source_instruction,22916static IrInstGen *ir_analyze_union_init(IrAnalyze *ira, IrInst* source_instruction,
21902 AstNode *field_source_node, ZigType *union_type, Buf *field_name, IrInstruction *field_result_loc,22917 AstNode *field_source_node, ZigType *union_type, Buf *field_name, IrInstGen *field_result_loc,
21903 IrInstruction *result_loc)22918 IrInstGen *result_loc)
21904{22919{
21905 Error err;22920 Error err;
21906 assert(union_type->id == ZigTypeIdUnion);22921 assert(union_type->id == ZigTypeIdUnion);
2190722922
21908 if ((err = type_resolve(ira->codegen, union_type, ResolveStatusSizeKnown)))22923 if ((err = type_resolve(ira->codegen, union_type, ResolveStatusSizeKnown)))
21909 return ira->codegen->invalid_instruction;22924 return ira->codegen->invalid_inst_gen;
2191022925
21911 TypeUnionField *type_field = find_union_type_field(union_type, field_name);22926 TypeUnionField *type_field = find_union_type_field(union_type, field_name);
21912 if (type_field == nullptr) {22927 if (type_field == nullptr) {
21913 ir_add_error_node(ira, field_source_node,22928 ir_add_error_node(ira, field_source_node,
21914 buf_sprintf("no member named '%s' in union '%s'",22929 buf_sprintf("no member named '%s' in union '%s'",
21915 buf_ptr(field_name), buf_ptr(&union_type->name)));22930 buf_ptr(field_name), buf_ptr(&union_type->name)));
21916 return ira->codegen->invalid_instruction;22931 return ira->codegen->invalid_inst_gen;
21917 }22932 }
2191822933
21919 if (type_is_invalid(type_field->type_entry))22934 if (type_is_invalid(type_field->type_entry))
21920 return ira->codegen->invalid_instruction;22935 return ira->codegen->invalid_inst_gen;
2192122936
21922 if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) {22937 if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) {
21923 if (instr_is_comptime(field_result_loc) &&22938 if (instr_is_comptime(field_result_loc) &&
...@@ -21929,42 +22944,42 @@ static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *sourc...@@ -21929,42 +22944,42 @@ static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *sourc
21929 }22944 }
21930 }22945 }
2193122946
21932 bool is_comptime = ir_should_inline(ira->new_irb.exec, source_instruction->scope)22947 bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instruction->scope)
21933 || type_requires_comptime(ira->codegen, union_type) == ReqCompTimeYes;22948 || type_requires_comptime(ira->codegen, union_type) == ReqCompTimeYes;
2193422949
21935 IrInstruction *result = ir_get_deref(ira, source_instruction, result_loc, nullptr);22950 IrInstGen *result = ir_get_deref(ira, source_instruction, result_loc, nullptr);
21936 if (is_comptime && !instr_is_comptime(result)) {22951 if (is_comptime && !instr_is_comptime(result)) {
21937 ir_add_error(ira, field_result_loc,22952 ir_add_error(ira, &field_result_loc->base,
21938 buf_sprintf("unable to evaluate constant expression"));22953 buf_sprintf("unable to evaluate constant expression"));
21939 return ira->codegen->invalid_instruction;22954 return ira->codegen->invalid_inst_gen;
21940 }22955 }
21941 return result;22956 return result;
21942}22957}
2194322958
21944static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction,22959static IrInstGen *ir_analyze_container_init_fields(IrAnalyze *ira, IrInst *source_instr,
21945 ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields,22960 ZigType *container_type, size_t instr_field_count, IrInstSrcContainerInitFieldsField *fields,
21946 IrInstruction *result_loc)22961 IrInstGen *result_loc)
21947{22962{
21948 Error err;22963 Error err;
21949 if (container_type->id == ZigTypeIdUnion) {22964 if (container_type->id == ZigTypeIdUnion) {
21950 if (instr_field_count != 1) {22965 if (instr_field_count != 1) {
21951 ir_add_error(ira, instruction,22966 ir_add_error(ira, source_instr,
21952 buf_sprintf("union initialization expects exactly one field"));22967 buf_sprintf("union initialization expects exactly one field"));
21953 return ira->codegen->invalid_instruction;22968 return ira->codegen->invalid_inst_gen;
21954 }22969 }
21955 IrInstructionContainerInitFieldsField *field = &fields[0];22970 IrInstSrcContainerInitFieldsField *field = &fields[0];
21956 IrInstruction *field_result_loc = field->result_loc->child;22971 IrInstGen *field_result_loc = field->result_loc->child;
21957 if (type_is_invalid(field_result_loc->value->type))22972 if (type_is_invalid(field_result_loc->value->type))
21958 return ira->codegen->invalid_instruction;22973 return ira->codegen->invalid_inst_gen;
2195922974
21960 return ir_analyze_union_init(ira, instruction, field->source_node, container_type, field->name,22975 return ir_analyze_union_init(ira, source_instr, field->source_node, container_type, field->name,
21961 field_result_loc, result_loc);22976 field_result_loc, result_loc);
21962 }22977 }
21963 if (container_type->id != ZigTypeIdStruct || is_slice(container_type)) {22978 if (container_type->id != ZigTypeIdStruct || is_slice(container_type)) {
21964 ir_add_error(ira, instruction,22979 ir_add_error(ira, source_instr,
21965 buf_sprintf("type '%s' does not support struct initialization syntax",22980 buf_sprintf("type '%s' does not support struct initialization syntax",
21966 buf_ptr(&container_type->name)));22981 buf_ptr(&container_type->name)));
21967 return ira->codegen->invalid_instruction;22982 return ira->codegen->invalid_inst_gen;
21968 }22983 }
2196922984
21970 if (container_type->data.structure.resolve_status == ResolveStatusBeingInferred) {22985 if (container_type->data.structure.resolve_status == ResolveStatusBeingInferred) {
...@@ -21973,16 +22988,16 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc...@@ -21973,16 +22988,16 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
21973 }22988 }
2197422989
21975 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))22990 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
21976 return ira->codegen->invalid_instruction;22991 return ira->codegen->invalid_inst_gen;
2197722992
21978 size_t actual_field_count = container_type->data.structure.src_field_count;22993 size_t actual_field_count = container_type->data.structure.src_field_count;
2197922994
21980 IrInstruction *first_non_const_instruction = nullptr;22995 IrInstGen *first_non_const_instruction = nullptr;
2198122996
21982 AstNode **field_assign_nodes = allocate<AstNode *>(actual_field_count);22997 AstNode **field_assign_nodes = allocate<AstNode *>(actual_field_count);
21983 ZigList<IrInstruction *> const_ptrs = {};22998 ZigList<IrInstGen *> const_ptrs = {};
2198422999
21985 bool is_comptime = ir_should_inline(ira->new_irb.exec, instruction->scope)23000 bool is_comptime = ir_should_inline(ira->old_irb.exec, source_instr->scope)
21986 || type_requires_comptime(ira->codegen, container_type) == ReqCompTimeYes;23001 || type_requires_comptime(ira->codegen, container_type) == ReqCompTimeYes;
2198723002
2198823003
...@@ -21998,29 +23013,29 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc...@@ -21998,29 +23013,29 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
21998 // comptime-known values.23013 // comptime-known values.
2199923014
22000 for (size_t i = 0; i < instr_field_count; i += 1) {23015 for (size_t i = 0; i < instr_field_count; i += 1) {
22001 IrInstructionContainerInitFieldsField *field = &fields[i];23016 IrInstSrcContainerInitFieldsField *field = &fields[i];
2200223017
22003 IrInstruction *field_result_loc = field->result_loc->child;23018 IrInstGen *field_result_loc = field->result_loc->child;
22004 if (type_is_invalid(field_result_loc->value->type))23019 if (type_is_invalid(field_result_loc->value->type))
22005 return ira->codegen->invalid_instruction;23020 return ira->codegen->invalid_inst_gen;
2200623021
22007 TypeStructField *type_field = find_struct_type_field(container_type, field->name);23022 TypeStructField *type_field = find_struct_type_field(container_type, field->name);
22008 if (!type_field) {23023 if (!type_field) {
22009 ir_add_error_node(ira, field->source_node,23024 ir_add_error_node(ira, field->source_node,
22010 buf_sprintf("no member named '%s' in struct '%s'",23025 buf_sprintf("no member named '%s' in struct '%s'",
22011 buf_ptr(field->name), buf_ptr(&container_type->name)));23026 buf_ptr(field->name), buf_ptr(&container_type->name)));
22012 return ira->codegen->invalid_instruction;23027 return ira->codegen->invalid_inst_gen;
22013 }23028 }
2201423029
22015 if (type_is_invalid(type_field->type_entry))23030 if (type_is_invalid(type_field->type_entry))
22016 return ira->codegen->invalid_instruction;23031 return ira->codegen->invalid_inst_gen;
2201723032
22018 size_t field_index = type_field->src_index;23033 size_t field_index = type_field->src_index;
22019 AstNode *existing_assign_node = field_assign_nodes[field_index];23034 AstNode *existing_assign_node = field_assign_nodes[field_index];
22020 if (existing_assign_node) {23035 if (existing_assign_node) {
22021 ErrorMsg *msg = ir_add_error_node(ira, field->source_node, buf_sprintf("duplicate field"));23036 ErrorMsg *msg = ir_add_error_node(ira, field->source_node, buf_sprintf("duplicate field"));
22022 add_error_note(ira->codegen, msg, existing_assign_node, buf_sprintf("other field here"));23037 add_error_note(ira->codegen, msg, existing_assign_node, buf_sprintf("other field here"));
22023 return ira->codegen->invalid_instruction;23038 return ira->codegen->invalid_inst_gen;
22024 }23039 }
22025 field_assign_nodes[field_index] = field->source_node;23040 field_assign_nodes[field_index] = field->source_node;
2202623041
...@@ -22041,20 +23056,20 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc...@@ -22041,20 +23056,20 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
22041 TypeStructField *field = container_type->data.structure.fields[i];23056 TypeStructField *field = container_type->data.structure.fields[i];
22042 memoize_field_init_val(ira->codegen, container_type, field);23057 memoize_field_init_val(ira->codegen, container_type, field);
22043 if (field->init_val == nullptr) {23058 if (field->init_val == nullptr) {
22044 ir_add_error_node(ira, instruction->source_node,23059 ir_add_error(ira, source_instr,
22045 buf_sprintf("missing field: '%s'", buf_ptr(container_type->data.structure.fields[i]->name)));23060 buf_sprintf("missing field: '%s'", buf_ptr(container_type->data.structure.fields[i]->name)));
22046 any_missing = true;23061 any_missing = true;
22047 continue;23062 continue;
22048 }23063 }
22049 if (type_is_invalid(field->init_val->type))23064 if (type_is_invalid(field->init_val->type))
22050 return ira->codegen->invalid_instruction;23065 return ira->codegen->invalid_inst_gen;
2205123066
22052 IrInstruction *runtime_inst = ir_const(ira, instruction, field->init_val->type);23067 IrInstGen *runtime_inst = ir_const(ira, source_instr, field->init_val->type);
22053 copy_const_val(runtime_inst->value, field->init_val);23068 copy_const_val(runtime_inst->value, field->init_val);
2205423069
22055 IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, instruction, field, result_loc,23070 IrInstGen *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, result_loc,
22056 container_type, true);23071 container_type, true);
22057 ir_analyze_store_ptr(ira, instruction, field_ptr, runtime_inst, false);23072 ir_analyze_store_ptr(ira, source_instr, field_ptr, runtime_inst, false);
22058 if (instr_is_comptime(field_ptr) && field_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {23073 if (instr_is_comptime(field_ptr) && field_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
22059 const_ptrs.append(field_ptr);23074 const_ptrs.append(field_ptr);
22060 } else {23075 } else {
...@@ -22062,39 +23077,39 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc...@@ -22062,39 +23077,39 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
22062 }23077 }
22063 }23078 }
22064 if (any_missing)23079 if (any_missing)
22065 return ira->codegen->invalid_instruction;23080 return ira->codegen->invalid_inst_gen;
2206623081
22067 if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) {23082 if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) {
22068 if (const_ptrs.length != actual_field_count) {23083 if (const_ptrs.length != actual_field_count) {
22069 result_loc->value->special = ConstValSpecialRuntime;23084 result_loc->value->special = ConstValSpecialRuntime;
22070 for (size_t i = 0; i < const_ptrs.length; i += 1) {23085 for (size_t i = 0; i < const_ptrs.length; i += 1) {
22071 IrInstruction *field_result_loc = const_ptrs.at(i);23086 IrInstGen *field_result_loc = const_ptrs.at(i);
22072 IrInstruction *deref = ir_get_deref(ira, field_result_loc, field_result_loc, nullptr);23087 IrInstGen *deref = ir_get_deref(ira, &field_result_loc->base, field_result_loc, nullptr);
22073 field_result_loc->value->special = ConstValSpecialRuntime;23088 field_result_loc->value->special = ConstValSpecialRuntime;
22074 ir_analyze_store_ptr(ira, field_result_loc, field_result_loc, deref, false);23089 ir_analyze_store_ptr(ira, &field_result_loc->base, field_result_loc, deref, false);
22075 }23090 }
22076 }23091 }
22077 }23092 }
2207823093
22079 IrInstruction *result = ir_get_deref(ira, instruction, result_loc, nullptr);23094 IrInstGen *result = ir_get_deref(ira, source_instr, result_loc, nullptr);
2208023095
22081 if (is_comptime && !instr_is_comptime(result)) {23096 if (is_comptime && !instr_is_comptime(result)) {
22082 ir_add_error_node(ira, first_non_const_instruction->source_node,23097 ir_add_error_node(ira, first_non_const_instruction->base.source_node,
22083 buf_sprintf("unable to evaluate constant expression"));23098 buf_sprintf("unable to evaluate constant expression"));
22084 return ira->codegen->invalid_instruction;23099 return ira->codegen->invalid_inst_gen;
22085 }23100 }
2208623101
22087 return result;23102 return result;
22088}23103}
2208923104
22090static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,23105static IrInstGen *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
22091 IrInstructionContainerInitList *instruction)23106 IrInstSrcContainerInitList *instruction)
22092{23107{
22093 ir_assert(instruction->result_loc != nullptr, &instruction->base);23108 ir_assert(instruction->result_loc != nullptr, &instruction->base.base);
22094 IrInstruction *result_loc = instruction->result_loc->child;23109 IrInstGen *result_loc = instruction->result_loc->child;
22095 if (type_is_invalid(result_loc->value->type))23110 if (type_is_invalid(result_loc->value->type))
22096 return result_loc;23111 return result_loc;
22097 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base);23112 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base);
2209823113
22099 ZigType *container_type = result_loc->value->type->data.pointer.child_type;23114 ZigType *container_type = result_loc->value->type->data.pointer.child_type;
2210023115
...@@ -22104,24 +23119,24 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -22104,24 +23119,24 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
22104 ir_add_error_node(ira, instruction->init_array_type_source_node,23119 ir_add_error_node(ira, instruction->init_array_type_source_node,
22105 buf_sprintf("array literal requires address-of operator to coerce to slice type '%s'",23120 buf_sprintf("array literal requires address-of operator to coerce to slice type '%s'",
22106 buf_ptr(&container_type->name)));23121 buf_ptr(&container_type->name)));
22107 return ira->codegen->invalid_instruction;23122 return ira->codegen->invalid_inst_gen;
22108 }23123 }
2210923124
22110 if (container_type->id == ZigTypeIdVoid) {23125 if (container_type->id == ZigTypeIdVoid) {
22111 if (elem_count != 0) {23126 if (elem_count != 0) {
22112 ir_add_error_node(ira, instruction->base.source_node,23127 ir_add_error_node(ira, instruction->base.base.source_node,
22113 buf_sprintf("void expression expects no arguments"));23128 buf_sprintf("void expression expects no arguments"));
22114 return ira->codegen->invalid_instruction;23129 return ira->codegen->invalid_inst_gen;
22115 }23130 }
22116 return ir_const_void(ira, &instruction->base);23131 return ir_const_void(ira, &instruction->base.base);
22117 }23132 }
2211823133
22119 if (container_type->id == ZigTypeIdStruct && elem_count == 0) {23134 if (container_type->id == ZigTypeIdStruct && elem_count == 0) {
22120 ir_assert(instruction->result_loc != nullptr, &instruction->base);23135 ir_assert(instruction->result_loc != nullptr, &instruction->base.base);
22121 IrInstruction *result_loc = instruction->result_loc->child;23136 IrInstGen *result_loc = instruction->result_loc->child;
22122 if (type_is_invalid(result_loc->value->type))23137 if (type_is_invalid(result_loc->value->type))
22123 return result_loc;23138 return result_loc;
22124 return ir_analyze_container_init_fields(ira, &instruction->base, container_type, 0, nullptr, result_loc);23139 return ir_analyze_container_init_fields(ira, &instruction->base.base, container_type, 0, nullptr, result_loc);
22125 }23140 }
2212623141
22127 if (container_type->id == ZigTypeIdArray) {23142 if (container_type->id == ZigTypeIdArray) {
...@@ -22129,10 +23144,10 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -22129,10 +23144,10 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
22129 if (container_type->data.array.len != elem_count) {23144 if (container_type->data.array.len != elem_count) {
22130 ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count, nullptr);23145 ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count, nullptr);
2213123146
22132 ir_add_error(ira, &instruction->base,23147 ir_add_error(ira, &instruction->base.base,
22133 buf_sprintf("expected %s literal, found %s literal",23148 buf_sprintf("expected %s literal, found %s literal",
22134 buf_ptr(&container_type->name), buf_ptr(&literal_type->name)));23149 buf_ptr(&container_type->name), buf_ptr(&literal_type->name)));
22135 return ira->codegen->invalid_instruction;23150 return ira->codegen->invalid_inst_gen;
22136 }23151 }
22137 } else if (container_type->id == ZigTypeIdStruct &&23152 } else if (container_type->id == ZigTypeIdStruct &&
22138 container_type->data.structure.resolve_status == ResolveStatusBeingInferred)23153 container_type->data.structure.resolve_status == ResolveStatusBeingInferred)
...@@ -22142,17 +23157,17 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -22142,17 +23157,17 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
22142 } else if (container_type->id == ZigTypeIdVector) {23157 } else if (container_type->id == ZigTypeIdVector) {
22143 // OK23158 // OK
22144 } else {23159 } else {
22145 ir_add_error_node(ira, instruction->base.source_node,23160 ir_add_error(ira, &instruction->base.base,
22146 buf_sprintf("type '%s' does not support array initialization",23161 buf_sprintf("type '%s' does not support array initialization",
22147 buf_ptr(&container_type->name)));23162 buf_ptr(&container_type->name)));
22148 return ira->codegen->invalid_instruction;23163 return ira->codegen->invalid_inst_gen;
22149 }23164 }
2215023165
22151 switch (type_has_one_possible_value(ira->codegen, container_type)) {23166 switch (type_has_one_possible_value(ira->codegen, container_type)) {
22152 case OnePossibleValueInvalid:23167 case OnePossibleValueInvalid:
22153 return ira->codegen->invalid_instruction;23168 return ira->codegen->invalid_inst_gen;
22154 case OnePossibleValueYes:23169 case OnePossibleValueYes:
22155 return ir_const_move(ira, &instruction->base,23170 return ir_const_move(ira, &instruction->base.base,
22156 get_the_one_possible_value(ira->codegen, container_type));23171 get_the_one_possible_value(ira->codegen, container_type));
22157 case OnePossibleValueNo:23172 case OnePossibleValueNo:
22158 break;23173 break;
...@@ -22161,16 +23176,16 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -22161,16 +23176,16 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
22161 bool is_comptime;23176 bool is_comptime;
22162 switch (type_requires_comptime(ira->codegen, container_type)) {23177 switch (type_requires_comptime(ira->codegen, container_type)) {
22163 case ReqCompTimeInvalid:23178 case ReqCompTimeInvalid:
22164 return ira->codegen->invalid_instruction;23179 return ira->codegen->invalid_inst_gen;
22165 case ReqCompTimeNo:23180 case ReqCompTimeNo:
22166 is_comptime = ir_should_inline(ira->new_irb.exec, instruction->base.scope);23181 is_comptime = ir_should_inline(ira->old_irb.exec, instruction->base.base.scope);
22167 break;23182 break;
22168 case ReqCompTimeYes:23183 case ReqCompTimeYes:
22169 is_comptime = true;23184 is_comptime = true;
22170 break;23185 break;
22171 }23186 }
2217223187
22173 IrInstruction *first_non_const_instruction = nullptr;23188 IrInstGen *first_non_const_instruction = nullptr;
2217423189
22175 // The Result Location Mechanism has already emitted runtime instructions to23190 // The Result Location Mechanism has already emitted runtime instructions to
22176 // initialize runtime elements and has omitted instructions for the comptime23191 // initialize runtime elements and has omitted instructions for the comptime
...@@ -22179,12 +23194,12 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -22179,12 +23194,12 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
22179 // array initialization can be a comptime value, overwrite ConstPtrMutInfer with23194 // array initialization can be a comptime value, overwrite ConstPtrMutInfer with
22180 // ConstPtrMutComptimeConst. Otherwise, emit instructions to runtime-initialize the23195 // ConstPtrMutComptimeConst. Otherwise, emit instructions to runtime-initialize the
22181 // elements that have comptime-known values.23196 // elements that have comptime-known values.
22182 ZigList<IrInstruction *> const_ptrs = {};23197 ZigList<IrInstGen *> const_ptrs = {};
2218323198
22184 for (size_t i = 0; i < elem_count; i += 1) {23199 for (size_t i = 0; i < elem_count; i += 1) {
22185 IrInstruction *elem_result_loc = instruction->elem_result_loc_list[i]->child;23200 IrInstGen *elem_result_loc = instruction->elem_result_loc_list[i]->child;
22186 if (type_is_invalid(elem_result_loc->value->type))23201 if (type_is_invalid(elem_result_loc->value->type))
22187 return ira->codegen->invalid_instruction;23202 return ira->codegen->invalid_inst_gen;
2218823203
22189 assert(elem_result_loc->value->type->id == ZigTypeIdPointer);23204 assert(elem_result_loc->value->type->id == ZigTypeIdPointer);
2219023205
...@@ -22201,81 +23216,79 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,...@@ -22201,81 +23216,79 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira,
22201 if (const_ptrs.length != elem_count) {23216 if (const_ptrs.length != elem_count) {
22202 result_loc->value->special = ConstValSpecialRuntime;23217 result_loc->value->special = ConstValSpecialRuntime;
22203 for (size_t i = 0; i < const_ptrs.length; i += 1) {23218 for (size_t i = 0; i < const_ptrs.length; i += 1) {
22204 IrInstruction *elem_result_loc = const_ptrs.at(i);23219 IrInstGen *elem_result_loc = const_ptrs.at(i);
22205 assert(elem_result_loc->value->special == ConstValSpecialStatic);23220 assert(elem_result_loc->value->special == ConstValSpecialStatic);
22206 if (elem_result_loc->value->type->data.pointer.inferred_struct_field != nullptr) {23221 if (elem_result_loc->value->type->data.pointer.inferred_struct_field != nullptr) {
22207 // This field will be generated comptime; no need to do this.23222 // This field will be generated comptime; no need to do this.
22208 continue;23223 continue;
22209 }23224 }
22210 IrInstruction *deref = ir_get_deref(ira, elem_result_loc, elem_result_loc, nullptr);23225 IrInstGen *deref = ir_get_deref(ira, &elem_result_loc->base, elem_result_loc, nullptr);
22211 elem_result_loc->value->special = ConstValSpecialRuntime;23226 elem_result_loc->value->special = ConstValSpecialRuntime;
22212 ir_analyze_store_ptr(ira, elem_result_loc, elem_result_loc, deref, false);23227 ir_analyze_store_ptr(ira, &elem_result_loc->base, elem_result_loc, deref, false);
22213 }23228 }
22214 }23229 }
22215 }23230 }
2221623231
22217 IrInstruction *result = ir_get_deref(ira, &instruction->base, result_loc, nullptr);23232 IrInstGen *result = ir_get_deref(ira, &instruction->base.base, result_loc, nullptr);
22218 if (instr_is_comptime(result))23233 if (instr_is_comptime(result))
22219 return result;23234 return result;
2222023235
22221 if (is_comptime) {23236 if (is_comptime) {
22222 ir_add_error_node(ira, first_non_const_instruction->source_node,23237 ir_add_error(ira, &first_non_const_instruction->base,
22223 buf_sprintf("unable to evaluate constant expression"));23238 buf_sprintf("unable to evaluate constant expression"));
22224 return ira->codegen->invalid_instruction;23239 return ira->codegen->invalid_inst_gen;
22225 }23240 }
2222623241
22227 ZigType *result_elem_type = result_loc->value->type->data.pointer.child_type;23242 ZigType *result_elem_type = result_loc->value->type->data.pointer.child_type;
22228 if (is_slice(result_elem_type)) {23243 if (is_slice(result_elem_type)) {
22229 ErrorMsg *msg = ir_add_error(ira, &instruction->base,23244 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
22230 buf_sprintf("runtime-initialized array cannot be casted to slice type '%s'",23245 buf_sprintf("runtime-initialized array cannot be casted to slice type '%s'",
22231 buf_ptr(&result_elem_type->name)));23246 buf_ptr(&result_elem_type->name)));
22232 add_error_note(ira->codegen, msg, first_non_const_instruction->source_node,23247 add_error_note(ira->codegen, msg, first_non_const_instruction->base.source_node,
22233 buf_sprintf("this value is not comptime-known"));23248 buf_sprintf("this value is not comptime-known"));
22234 return ira->codegen->invalid_instruction;23249 return ira->codegen->invalid_inst_gen;
22235 }23250 }
22236 return result;23251 return result;
22237}23252}
2223823253
22239static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ira,23254static IrInstGen *ir_analyze_instruction_container_init_fields(IrAnalyze *ira,
22240 IrInstructionContainerInitFields *instruction)23255 IrInstSrcContainerInitFields *instruction)
22241{23256{
22242 ir_assert(instruction->result_loc != nullptr, &instruction->base);23257 ir_assert(instruction->result_loc != nullptr, &instruction->base.base);
22243 IrInstruction *result_loc = instruction->result_loc->child;23258 IrInstGen *result_loc = instruction->result_loc->child;
22244 if (type_is_invalid(result_loc->value->type))23259 if (type_is_invalid(result_loc->value->type))
22245 return result_loc;23260 return result_loc;
2224623261
22247 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base);23262 ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base.base);
22248 ZigType *container_type = result_loc->value->type->data.pointer.child_type;23263 ZigType *container_type = result_loc->value->type->data.pointer.child_type;
2224923264
22250 return ir_analyze_container_init_fields(ira, &instruction->base, container_type,23265 return ir_analyze_container_init_fields(ira, &instruction->base.base, container_type,
22251 instruction->field_count, instruction->fields, result_loc);23266 instruction->field_count, instruction->fields, result_loc);
22252}23267}
2225323268
22254static IrInstruction *ir_analyze_instruction_compile_err(IrAnalyze *ira,23269static IrInstGen *ir_analyze_instruction_compile_err(IrAnalyze *ira, IrInstSrcCompileErr *instruction) {
22255 IrInstructionCompileErr *instruction)23270 IrInstGen *msg_value = instruction->msg->child;
22256{
22257 IrInstruction *msg_value = instruction->msg->child;
22258 Buf *msg_buf = ir_resolve_str(ira, msg_value);23271 Buf *msg_buf = ir_resolve_str(ira, msg_value);
22259 if (!msg_buf)23272 if (!msg_buf)
22260 return ira->codegen->invalid_instruction;23273 return ira->codegen->invalid_inst_gen;
2226123274
22262 ir_add_error(ira, &instruction->base, msg_buf);23275 ir_add_error(ira, &instruction->base.base, msg_buf);
2226323276
22264 return ira->codegen->invalid_instruction;23277 return ira->codegen->invalid_inst_gen;
22265}23278}
2226623279
22267static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstructionCompileLog *instruction) {23280static IrInstGen *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstSrcCompileLog *instruction) {
22268 Buf buf = BUF_INIT;23281 Buf buf = BUF_INIT;
22269 fprintf(stderr, "| ");23282 fprintf(stderr, "| ");
22270 for (size_t i = 0; i < instruction->msg_count; i += 1) {23283 for (size_t i = 0; i < instruction->msg_count; i += 1) {
22271 IrInstruction *msg = instruction->msg_list[i]->child;23284 IrInstGen *msg = instruction->msg_list[i]->child;
22272 if (type_is_invalid(msg->value->type))23285 if (type_is_invalid(msg->value->type))
22273 return ira->codegen->invalid_instruction;23286 return ira->codegen->invalid_inst_gen;
22274 buf_resize(&buf, 0);23287 buf_resize(&buf, 0);
22275 if (msg->value->special == ConstValSpecialLazy) {23288 if (msg->value->special == ConstValSpecialLazy) {
22276 // Resolve any lazy value that's passed, we need its value23289 // Resolve any lazy value that's passed, we need its value
22277 if (ir_resolve_lazy(ira->codegen, msg->source_node, msg->value))23290 if (ir_resolve_lazy(ira->codegen, msg->base.source_node, msg->value))
22278 return ira->codegen->invalid_instruction;23291 return ira->codegen->invalid_inst_gen;
22279 }23292 }
22280 render_const_value(ira->codegen, &buf, msg->value);23293 render_const_value(ira->codegen, &buf, msg->value);
22281 const char *comma_str = (i != 0) ? ", " : "";23294 const char *comma_str = (i != 0) ? ", " : "";
...@@ -22283,25 +23296,25 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr...@@ -22283,25 +23296,25 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr
22283 }23296 }
22284 fprintf(stderr, "\n");23297 fprintf(stderr, "\n");
2228523298
22286 auto *expr = &instruction->base.source_node->data.fn_call_expr;23299 auto *expr = &instruction->base.base.source_node->data.fn_call_expr;
22287 if (!expr->seen) {23300 if (!expr->seen) {
22288 // Here we bypass higher level functions such as ir_add_error because we do not want23301 // Here we bypass higher level functions such as ir_add_error because we do not want
22289 // invalidate_exec to be called.23302 // invalidate_exec to be called.
22290 add_node_error(ira->codegen, instruction->base.source_node, buf_sprintf("found compile log statement"));23303 add_node_error(ira->codegen, instruction->base.base.source_node, buf_sprintf("found compile log statement"));
22291 }23304 }
22292 expr->seen = true;23305 expr->seen = true;
2229323306
22294 return ir_const_void(ira, &instruction->base);23307 return ir_const_void(ira, &instruction->base.base);
22295}23308}
2229623309
22297static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) {23310static IrInstGen *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstSrcErrName *instruction) {
22298 IrInstruction *value = instruction->value->child;23311 IrInstGen *value = instruction->value->child;
22299 if (type_is_invalid(value->value->type))23312 if (type_is_invalid(value->value->type))
22300 return ira->codegen->invalid_instruction;23313 return ira->codegen->invalid_inst_gen;
2230123314
22302 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_global_error_set);23315 IrInstGen *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_global_error_set);
22303 if (type_is_invalid(casted_value->value->type))23316 if (type_is_invalid(casted_value->value->type))
22304 return ira->codegen->invalid_instruction;23317 return ira->codegen->invalid_inst_gen;
2230523318
22306 ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,23319 ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
22307 true, false, PtrLenUnknown, 0, 0, 0, false);23320 true, false, PtrLenUnknown, 0, 0, 0, false);
...@@ -22309,13 +23322,13 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct...@@ -22309,13 +23322,13 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct
22309 if (instr_is_comptime(casted_value)) {23322 if (instr_is_comptime(casted_value)) {
22310 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);23323 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);
22311 if (val == nullptr)23324 if (val == nullptr)
22312 return ira->codegen->invalid_instruction;23325 return ira->codegen->invalid_inst_gen;
22313 ErrorTableEntry *err = casted_value->value->data.x_err_set;23326 ErrorTableEntry *err = casted_value->value->data.x_err_set;
22314 if (!err->cached_error_name_val) {23327 if (!err->cached_error_name_val) {
22315 ZigValue *array_val = create_const_str_lit(ira->codegen, &err->name)->data.x_ptr.data.ref.pointee;23328 ZigValue *array_val = create_const_str_lit(ira->codegen, &err->name)->data.x_ptr.data.ref.pointee;
22316 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);23329 err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true);
22317 }23330 }
22318 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);23331 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
22319 copy_const_val(result->value, err->cached_error_name_val);23332 copy_const_val(result->value, err->cached_error_name_val);
22320 result->value->type = str_type;23333 result->value->type = str_type;
22321 return result;23334 return result;
...@@ -22323,20 +23336,17 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct...@@ -22323,20 +23336,17 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct
2232323336
22324 ira->codegen->generate_error_name_table = true;23337 ira->codegen->generate_error_name_table = true;
2232523338
22326 IrInstruction *result = ir_build_err_name(&ira->new_irb,23339 return ir_build_err_name_gen(ira, &instruction->base.base, value, str_type);
22327 instruction->base.scope, instruction->base.source_node, value);
22328 result->value->type = str_type;
22329 return result;
22330}23340}
2233123341
22332static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) {23342static IrInstGen *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstSrcTagName *instruction) {
22333 Error err;23343 Error err;
22334 IrInstruction *target = instruction->target->child;23344 IrInstGen *target = instruction->target->child;
22335 if (type_is_invalid(target->value->type))23345 if (type_is_invalid(target->value->type))
22336 return ira->codegen->invalid_instruction;23346 return ira->codegen->invalid_inst_gen;
2233723347
22338 if (target->value->type->id == ZigTypeIdEnumLiteral) {23348 if (target->value->type->id == ZigTypeIdEnumLiteral) {
22339 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);23349 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
22340 Buf *field_name = target->value->data.x_enum_literal;23350 Buf *field_name = target->value->data.x_enum_literal;
22341 ZigValue *array_val = create_const_str_lit(ira->codegen, field_name)->data.x_ptr.data.ref.pointee;23351 ZigValue *array_val = create_const_str_lit(ira->codegen, field_name)->data.x_ptr.data.ref.pointee;
22342 init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(field_name), true);23352 init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(field_name), true);
...@@ -22344,86 +23354,88 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns...@@ -22344,86 +23354,88 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns
22344 }23354 }
2234523355
22346 if (target->value->type->id == ZigTypeIdUnion) {23356 if (target->value->type->id == ZigTypeIdUnion) {
22347 target = ir_analyze_union_tag(ira, &instruction->base, target);23357 target = ir_analyze_union_tag(ira, &instruction->base.base, target, instruction->base.is_gen);
22348 if (type_is_invalid(target->value->type))23358 if (type_is_invalid(target->value->type))
22349 return ira->codegen->invalid_instruction;23359 return ira->codegen->invalid_inst_gen;
22350 }23360 }
2235123361
22352 assert(target->value->type->id == ZigTypeIdEnum);23362 if (target->value->type->id != ZigTypeIdEnum) {
23363 ir_add_error(ira, &target->base,
23364 buf_sprintf("expected enum tag, found '%s'", buf_ptr(&target->value->type->name)));
23365 return ira->codegen->invalid_inst_gen;
23366 }
2235323367
22354 if (target->value->type->data.enumeration.src_field_count == 1 &&23368 if (target->value->type->data.enumeration.src_field_count == 1 &&
22355 !target->value->type->data.enumeration.non_exhaustive) {23369 !target->value->type->data.enumeration.non_exhaustive) {
22356 TypeEnumField *only_field = &target->value->type->data.enumeration.fields[0];23370 TypeEnumField *only_field = &target->value->type->data.enumeration.fields[0];
22357 ZigValue *array_val = create_const_str_lit(ira->codegen, only_field->name)->data.x_ptr.data.ref.pointee;23371 ZigValue *array_val = create_const_str_lit(ira->codegen, only_field->name)->data.x_ptr.data.ref.pointee;
22358 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);23372 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
22359 init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(only_field->name), true);23373 init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(only_field->name), true);
22360 return result;23374 return result;
22361 }23375 }
2236223376
22363 if (instr_is_comptime(target)) {23377 if (instr_is_comptime(target)) {
22364 if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusZeroBitsKnown)))23378 if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusZeroBitsKnown)))
22365 return ira->codegen->invalid_instruction;23379 return ira->codegen->invalid_inst_gen;
22366 if (target->value->type->data.enumeration.non_exhaustive) {23380 if (target->value->type->data.enumeration.non_exhaustive) {
22367 add_node_error(ira->codegen, instruction->base.source_node,23381 ir_add_error(ira, &instruction->base.base,
22368 buf_sprintf("TODO @tagName on non-exhaustive enum https://github.com/ziglang/zig/issues/3991"));23382 buf_sprintf("TODO @tagName on non-exhaustive enum https://github.com/ziglang/zig/issues/3991"));
22369 return ira->codegen->invalid_instruction;23383 return ira->codegen->invalid_inst_gen;
22370 }23384 }
22371 TypeEnumField *field = find_enum_field_by_tag(target->value->type, &target->value->data.x_bigint);23385 TypeEnumField *field = find_enum_field_by_tag(target->value->type, &target->value->data.x_bigint);
22372 ZigValue *array_val = create_const_str_lit(ira->codegen, field->name)->data.x_ptr.data.ref.pointee;23386 ZigValue *array_val = create_const_str_lit(ira->codegen, field->name)->data.x_ptr.data.ref.pointee;
22373 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);23387 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
22374 init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(field->name), true);23388 init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(field->name), true);
22375 return result;23389 return result;
22376 }23390 }
2237723391
22378 IrInstruction *result = ir_build_tag_name(&ira->new_irb, instruction->base.scope,
22379 instruction->base.source_node, target);
22380 ZigType *u8_ptr_type = get_pointer_to_type_extra(23392 ZigType *u8_ptr_type = get_pointer_to_type_extra(
22381 ira->codegen, ira->codegen->builtin_types.entry_u8,23393 ira->codegen, ira->codegen->builtin_types.entry_u8,
22382 true, false, PtrLenUnknown,23394 true, false, PtrLenUnknown,
22383 0, 0, 0, false);23395 0, 0, 0, false);
22384 result->value->type = get_slice_type(ira->codegen, u8_ptr_type);23396 ZigType *result_type = get_slice_type(ira->codegen, u8_ptr_type);
22385 return result;23397 return ir_build_tag_name_gen(ira, &instruction->base.base, target, result_type);
22386}23398}
2238723399
22388static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,23400static IrInstGen *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
22389 IrInstructionFieldParentPtr *instruction)23401 IrInstSrcFieldParentPtr *instruction)
22390{23402{
22391 Error err;23403 Error err;
22392 IrInstruction *type_value = instruction->type_value->child;23404 IrInstGen *type_value = instruction->type_value->child;
22393 ZigType *container_type = ir_resolve_type(ira, type_value);23405 ZigType *container_type = ir_resolve_type(ira, type_value);
22394 if (type_is_invalid(container_type))23406 if (type_is_invalid(container_type))
22395 return ira->codegen->invalid_instruction;23407 return ira->codegen->invalid_inst_gen;
2239623408
22397 IrInstruction *field_name_value = instruction->field_name->child;23409 IrInstGen *field_name_value = instruction->field_name->child;
22398 Buf *field_name = ir_resolve_str(ira, field_name_value);23410 Buf *field_name = ir_resolve_str(ira, field_name_value);
22399 if (!field_name)23411 if (!field_name)
22400 return ira->codegen->invalid_instruction;23412 return ira->codegen->invalid_inst_gen;
2240123413
22402 IrInstruction *field_ptr = instruction->field_ptr->child;23414 IrInstGen *field_ptr = instruction->field_ptr->child;
22403 if (type_is_invalid(field_ptr->value->type))23415 if (type_is_invalid(field_ptr->value->type))
22404 return ira->codegen->invalid_instruction;23416 return ira->codegen->invalid_inst_gen;
2240523417
22406 if (container_type->id != ZigTypeIdStruct) {23418 if (container_type->id != ZigTypeIdStruct) {
22407 ir_add_error(ira, type_value,23419 ir_add_error(ira, &type_value->base,
22408 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));23420 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
22409 return ira->codegen->invalid_instruction;23421 return ira->codegen->invalid_inst_gen;
22410 }23422 }
2241123423
22412 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))23424 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
22413 return ira->codegen->invalid_instruction;23425 return ira->codegen->invalid_inst_gen;
2241423426
22415 TypeStructField *field = find_struct_type_field(container_type, field_name);23427 TypeStructField *field = find_struct_type_field(container_type, field_name);
22416 if (field == nullptr) {23428 if (field == nullptr) {
22417 ir_add_error(ira, field_name_value,23429 ir_add_error(ira, &field_name_value->base,
22418 buf_sprintf("struct '%s' has no field '%s'",23430 buf_sprintf("struct '%s' has no field '%s'",
22419 buf_ptr(&container_type->name), buf_ptr(field_name)));23431 buf_ptr(&container_type->name), buf_ptr(field_name)));
22420 return ira->codegen->invalid_instruction;23432 return ira->codegen->invalid_inst_gen;
22421 }23433 }
2242223434
22423 if (field_ptr->value->type->id != ZigTypeIdPointer) {23435 if (field_ptr->value->type->id != ZigTypeIdPointer) {
22424 ir_add_error(ira, field_ptr,23436 ir_add_error(ira, &field_ptr->base,
22425 buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value->type->name)));23437 buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value->type->name)));
22426 return ira->codegen->invalid_instruction;23438 return ira->codegen->invalid_inst_gen;
22427 }23439 }
2242823440
22429 bool is_packed = (container_type->data.structure.layout == ContainerLayoutPacked);23441 bool is_packed = (container_type->data.structure.layout == ContainerLayoutPacked);
...@@ -22435,9 +23447,9 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -22435,9 +23447,9 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
22435 field_ptr->value->type->data.pointer.is_volatile,23447 field_ptr->value->type->data.pointer.is_volatile,
22436 PtrLenSingle,23448 PtrLenSingle,
22437 field_ptr_align, 0, 0, false);23449 field_ptr_align, 0, 0, false);
22438 IrInstruction *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type);23450 IrInstGen *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type);
22439 if (type_is_invalid(casted_field_ptr->value->type))23451 if (type_is_invalid(casted_field_ptr->value->type))
22440 return ira->codegen->invalid_instruction;23452 return ira->codegen->invalid_inst_gen;
2244123453
22442 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, container_type,23454 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, container_type,
22443 casted_field_ptr->value->type->data.pointer.is_const,23455 casted_field_ptr->value->type->data.pointer.is_const,
...@@ -22448,23 +23460,23 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -22448,23 +23460,23 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
22448 if (instr_is_comptime(casted_field_ptr)) {23460 if (instr_is_comptime(casted_field_ptr)) {
22449 ZigValue *field_ptr_val = ir_resolve_const(ira, casted_field_ptr, UndefBad);23461 ZigValue *field_ptr_val = ir_resolve_const(ira, casted_field_ptr, UndefBad);
22450 if (!field_ptr_val)23462 if (!field_ptr_val)
22451 return ira->codegen->invalid_instruction;23463 return ira->codegen->invalid_inst_gen;
2245223464
22453 if (field_ptr_val->data.x_ptr.special != ConstPtrSpecialBaseStruct) {23465 if (field_ptr_val->data.x_ptr.special != ConstPtrSpecialBaseStruct) {
22454 ir_add_error(ira, field_ptr, buf_sprintf("pointer value not based on parent struct"));23466 ir_add_error(ira, &field_ptr->base, buf_sprintf("pointer value not based on parent struct"));
22455 return ira->codegen->invalid_instruction;23467 return ira->codegen->invalid_inst_gen;
22456 }23468 }
2245723469
22458 size_t ptr_field_index = field_ptr_val->data.x_ptr.data.base_struct.field_index;23470 size_t ptr_field_index = field_ptr_val->data.x_ptr.data.base_struct.field_index;
22459 if (ptr_field_index != field->src_index) {23471 if (ptr_field_index != field->src_index) {
22460 ir_add_error(ira, &instruction->base,23472 ir_add_error(ira, &instruction->base.base,
22461 buf_sprintf("field '%s' has index %" ZIG_PRI_usize " but pointer value is index %" ZIG_PRI_usize " of struct '%s'",23473 buf_sprintf("field '%s' has index %" ZIG_PRI_usize " but pointer value is index %" ZIG_PRI_usize " of struct '%s'",
22462 buf_ptr(field->name), field->src_index,23474 buf_ptr(field->name), field->src_index,
22463 ptr_field_index, buf_ptr(&container_type->name)));23475 ptr_field_index, buf_ptr(&container_type->name)));
22464 return ira->codegen->invalid_instruction;23476 return ira->codegen->invalid_inst_gen;
22465 }23477 }
2246623478
22467 IrInstruction *result = ir_const(ira, &instruction->base, result_type);23479 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
22468 ZigValue *out_val = result->value;23480 ZigValue *out_val = result->value;
22469 out_val->data.x_ptr.special = ConstPtrSpecialRef;23481 out_val->data.x_ptr.special = ConstPtrSpecialRef;
22470 out_val->data.x_ptr.data.ref.pointee = field_ptr_val->data.x_ptr.data.base_struct.struct_val;23482 out_val->data.x_ptr.data.ref.pointee = field_ptr_val->data.x_ptr.data.base_struct.struct_val;
...@@ -22472,15 +23484,12 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,...@@ -22472,15 +23484,12 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira,
22472 return result;23484 return result;
22473 }23485 }
2247423486
22475 IrInstruction *result = ir_build_field_parent_ptr(&ira->new_irb, instruction->base.scope,23487 return ir_build_field_parent_ptr_gen(ira, &instruction->base.base, casted_field_ptr, field, result_type);
22476 instruction->base.source_node, type_value, field_name_value, casted_field_ptr, field);
22477 result->value->type = result_type;
22478 return result;
22479}23488}
2248023489
22481static TypeStructField *validate_byte_offset(IrAnalyze *ira,23490static TypeStructField *validate_byte_offset(IrAnalyze *ira,
22482 IrInstruction *type_value,23491 IrInstGen *type_value,
22483 IrInstruction *field_name_value,23492 IrInstGen *field_name_value,
22484 size_t *byte_offset)23493 size_t *byte_offset)
22485{23494{
22486 ZigType *container_type = ir_resolve_type(ira, type_value);23495 ZigType *container_type = ir_resolve_type(ira, type_value);
...@@ -22496,21 +23505,21 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira,...@@ -22496,21 +23505,21 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira,
22496 return nullptr;23505 return nullptr;
2249723506
22498 if (container_type->id != ZigTypeIdStruct) {23507 if (container_type->id != ZigTypeIdStruct) {
22499 ir_add_error(ira, type_value,23508 ir_add_error(ira, &type_value->base,
22500 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));23509 buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name)));
22501 return nullptr;23510 return nullptr;
22502 }23511 }
2250323512
22504 TypeStructField *field = find_struct_type_field(container_type, field_name);23513 TypeStructField *field = find_struct_type_field(container_type, field_name);
22505 if (field == nullptr) {23514 if (field == nullptr) {
22506 ir_add_error(ira, field_name_value,23515 ir_add_error(ira, &field_name_value->base,
22507 buf_sprintf("struct '%s' has no field '%s'",23516 buf_sprintf("struct '%s' has no field '%s'",
22508 buf_ptr(&container_type->name), buf_ptr(field_name)));23517 buf_ptr(&container_type->name), buf_ptr(field_name)));
22509 return nullptr;23518 return nullptr;
22510 }23519 }
2251123520
22512 if (!type_has_bits(field->type_entry)) {23521 if (!type_has_bits(field->type_entry)) {
22513 ir_add_error(ira, field_name_value,23522 ir_add_error(ira, &field_name_value->base,
22514 buf_sprintf("zero-bit field '%s' in struct '%s' has no offset",23523 buf_sprintf("zero-bit field '%s' in struct '%s' has no offset",
22515 buf_ptr(field_name), buf_ptr(&container_type->name)));23524 buf_ptr(field_name), buf_ptr(&container_type->name)));
22516 return nullptr;23525 return nullptr;
...@@ -22520,36 +23529,32 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira,...@@ -22520,36 +23529,32 @@ static TypeStructField *validate_byte_offset(IrAnalyze *ira,
22520 return field;23529 return field;
22521}23530}
2252223531
22523static IrInstruction *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira,23532static IrInstGen *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira, IrInstSrcByteOffsetOf *instruction) {
22524 IrInstructionByteOffsetOf *instruction)23533 IrInstGen *type_value = instruction->type_value->child;
22525{
22526 IrInstruction *type_value = instruction->type_value->child;
22527 if (type_is_invalid(type_value->value->type))23534 if (type_is_invalid(type_value->value->type))
22528 return ira->codegen->invalid_instruction;23535 return ira->codegen->invalid_inst_gen;
2252923536
22530 IrInstruction *field_name_value = instruction->field_name->child;23537 IrInstGen *field_name_value = instruction->field_name->child;
22531 size_t byte_offset = 0;23538 size_t byte_offset = 0;
22532 if (!validate_byte_offset(ira, type_value, field_name_value, &byte_offset))23539 if (!validate_byte_offset(ira, type_value, field_name_value, &byte_offset))
22533 return ira->codegen->invalid_instruction;23540 return ira->codegen->invalid_inst_gen;
2253423541
2253523542
22536 return ir_const_unsigned(ira, &instruction->base, byte_offset);23543 return ir_const_unsigned(ira, &instruction->base.base, byte_offset);
22537}23544}
2253823545
22539static IrInstruction *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira,23546static IrInstGen *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, IrInstSrcBitOffsetOf *instruction) {
22540 IrInstructionBitOffsetOf *instruction)23547 IrInstGen *type_value = instruction->type_value->child;
22541{
22542 IrInstruction *type_value = instruction->type_value->child;
22543 if (type_is_invalid(type_value->value->type))23548 if (type_is_invalid(type_value->value->type))
22544 return ira->codegen->invalid_instruction;23549 return ira->codegen->invalid_inst_gen;
22545 IrInstruction *field_name_value = instruction->field_name->child;23550 IrInstGen *field_name_value = instruction->field_name->child;
22546 size_t byte_offset = 0;23551 size_t byte_offset = 0;
22547 TypeStructField *field = nullptr;23552 TypeStructField *field = nullptr;
22548 if (!(field = validate_byte_offset(ira, type_value, field_name_value, &byte_offset)))23553 if (!(field = validate_byte_offset(ira, type_value, field_name_value, &byte_offset)))
22549 return ira->codegen->invalid_instruction;23554 return ira->codegen->invalid_inst_gen;
2255023555
22551 size_t bit_offset = byte_offset * 8 + field->bit_offset_in_host;23556 size_t bit_offset = byte_offset * 8 + field->bit_offset_in_host;
22552 return ir_const_unsigned(ira, &instruction->base, bit_offset);23557 return ir_const_unsigned(ira, &instruction->base.base, bit_offset);
22553}23558}
2255423559
22555static void ensure_field_index(ZigType *type, const char *field_name, size_t index) {23560static void ensure_field_index(ZigType *type, const char *field_name, size_t index) {
...@@ -22597,7 +23602,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig...@@ -22597,7 +23602,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig
22597 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, nullptr, var->const_value);23602 return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, nullptr, var->const_value);
22598}23603}
2259923604
22600static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *out_val,23605static Error ir_make_type_info_decls(IrAnalyze *ira, IrInst* source_instr, ZigValue *out_val,
22601 ScopeDecls *decls_scope)23606 ScopeDecls *decls_scope)
22602{23607{
22603 Error err;23608 Error err;
...@@ -22628,11 +23633,14 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -22628,11 +23633,14 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2262823633
22629 while ((curr_entry = decl_it.next()) != nullptr) {23634 while ((curr_entry = decl_it.next()) != nullptr) {
22630 // If the declaration is unresolved, force it to be resolved again.23635 // If the declaration is unresolved, force it to be resolved again.
22631 if (curr_entry->value->resolution == TldResolutionUnresolved) {23636 resolve_top_level_decl(ira->codegen, curr_entry->value, curr_entry->value->source_node, false);
22632 resolve_top_level_decl(ira->codegen, curr_entry->value, curr_entry->value->source_node, false);23637 if (curr_entry->value->resolution == TldResolutionInvalid) {
22633 if (curr_entry->value->resolution != TldResolutionOk) {23638 return ErrorSemanticAnalyzeFail;
22634 return ErrorSemanticAnalyzeFail;23639 }
22635 }23640
23641 if (curr_entry->value->resolution == TldResolutionResolving) {
23642 ir_error_dependency_loop(ira, source_instr);
23643 return ErrorSemanticAnalyzeFail;
22636 }23644 }
2263723645
22638 // Skip comptime blocks and test functions.23646 // Skip comptime blocks and test functions.
...@@ -22689,6 +23697,8 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -22689,6 +23697,8 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
22689 case TldIdVar:23697 case TldIdVar:
22690 {23698 {
22691 ZigVar *var = ((TldVar *)curr_entry->value)->var;23699 ZigVar *var = ((TldVar *)curr_entry->value)->var;
23700 assert(var != nullptr);
23701
22692 if ((err = type_resolve(ira->codegen, var->const_value->type, ResolveStatusSizeKnown)))23702 if ((err = type_resolve(ira->codegen, var->const_value->type, ResolveStatusSizeKnown)))
22693 return ErrorSemanticAnalyzeFail;23703 return ErrorSemanticAnalyzeFail;
2269423704
...@@ -22719,11 +23729,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr...@@ -22719,11 +23729,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2271923729
22720 ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;23730 ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
22721 assert(!fn_entry->is_test);23731 assert(!fn_entry->is_test);
2272223732 assert(fn_entry->type_entry != nullptr);
22723 if (fn_entry->type_entry == nullptr) {
22724 ir_error_dependency_loop(ira, source_instr);
22725 return ErrorSemanticAnalyzeFail;
22726 }
2272723733
22728 AstNodeFnProto *fn_node = &fn_entry->proto_node->data.fn_proto;23734 AstNodeFnProto *fn_node = &fn_entry->proto_node->data.fn_proto;
2272923735
...@@ -22955,7 +23961,7 @@ static void make_enum_field_val(IrAnalyze *ira, ZigValue *enum_field_val, TypeEn...@@ -22955,7 +23961,7 @@ static void make_enum_field_val(IrAnalyze *ira, ZigValue *enum_field_val, TypeEn
22955 enum_field_val->data.x_struct.fields = inner_fields;23961 enum_field_val->data.x_struct.fields = inner_fields;
22956}23962}
2295723963
22958static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry,23964static Error ir_make_type_info_value(IrAnalyze *ira, IrInst* source_instr, ZigType *type_entry,
22959 ZigValue **out)23965 ZigValue **out)
22960{23966{
22961 Error err;23967 Error err;
...@@ -23543,22 +24549,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -23543,22 +24549,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
23543 return ErrorNone;24549 return ErrorNone;
23544}24550}
2354524551
23546static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,24552static IrInstGen *ir_analyze_instruction_type_info(IrAnalyze *ira, IrInstSrcTypeInfo *instruction) {
23547 IrInstructionTypeInfo *instruction)
23548{
23549 Error err;24553 Error err;
23550 IrInstruction *type_value = instruction->type_value->child;24554 IrInstGen *type_value = instruction->type_value->child;
23551 ZigType *type_entry = ir_resolve_type(ira, type_value);24555 ZigType *type_entry = ir_resolve_type(ira, type_value);
23552 if (type_is_invalid(type_entry))24556 if (type_is_invalid(type_entry))
23553 return ira->codegen->invalid_instruction;24557 return ira->codegen->invalid_inst_gen;
2355424558
23555 ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);24559 ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr);
2355624560
23557 ZigValue *payload;24561 ZigValue *payload;
23558 if ((err = ir_make_type_info_value(ira, &instruction->base, type_entry, &payload)))24562 if ((err = ir_make_type_info_value(ira, &instruction->base.base, type_entry, &payload)))
23559 return ira->codegen->invalid_instruction;24563 return ira->codegen->invalid_inst_gen;
2356024564
23561 IrInstruction *result = ir_const(ira, &instruction->base, result_type);24565 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
23562 ZigValue *out_val = result->value;24566 ZigValue *out_val = result->value;
23563 bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry));24567 bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry));
23564 out_val->data.x_union.payload = payload;24568 out_val->data.x_union.payload = payload;
...@@ -23582,15 +24586,15 @@ static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue...@@ -23582,15 +24586,15 @@ static ZigValue *get_const_field(IrAnalyze *ira, AstNode *source_node, ZigValue
23582 return val;24586 return val;
23583}24587}
2358424588
23585static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *struct_value,24589static Error get_const_field_sentinel(IrAnalyze *ira, IrInst* source_instr, ZigValue *struct_value,
23586 const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)24590 const char *name, size_t field_index, ZigType *elem_type, ZigValue **result)
23587{24591{
23588 ZigValue *field_val = get_const_field(ira, source_instr->source_node, struct_value, name, field_index);24592 ZigValue *field_val = get_const_field(ira, source_instr->source_node, struct_value, name, field_index);
23589 if (field_val == nullptr)24593 if (field_val == nullptr)
23590 return ErrorSemanticAnalyzeFail;24594 return ErrorSemanticAnalyzeFail;
2359124595
23592 IrInstruction *field_inst = ir_const_move(ira, source_instr, field_val);24596 IrInstGen *field_inst = ir_const_move(ira, source_instr, field_val);
23593 IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst,24597 IrInstGen *casted_field_inst = ir_implicit_cast(ira, field_inst,
23594 get_optional_type(ira->codegen, elem_type));24598 get_optional_type(ira->codegen, elem_type));
23595 if (type_is_invalid(casted_field_inst->value->type))24599 if (type_is_invalid(casted_field_inst->value->type))
23596 return ErrorSemanticAnalyzeFail;24600 return ErrorSemanticAnalyzeFail;
...@@ -23629,12 +24633,12 @@ static ZigType *get_const_field_meta_type(IrAnalyze *ira, AstNode *source_node,...@@ -23629,12 +24633,12 @@ static ZigType *get_const_field_meta_type(IrAnalyze *ira, AstNode *source_node,
23629{24633{
23630 ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index);24634 ZigValue *value = get_const_field(ira, source_node, struct_value, name, field_index);
23631 if (value == nullptr)24635 if (value == nullptr)
23632 return ira->codegen->invalid_instruction->value->type;24636 return ira->codegen->invalid_inst_gen->value->type;
23633 assert(value->type == ira->codegen->builtin_types.entry_type);24637 assert(value->type == ira->codegen->builtin_types.entry_type);
23634 return value->data.x_type;24638 return value->data.x_type;
23635}24639}
2363624640
23637static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, ZigTypeId tagTypeId, ZigValue *payload) {24641static ZigType *type_info_to_type(IrAnalyze *ira, IrInst *source_instr, ZigTypeId tagTypeId, ZigValue *payload) {
23638 Error err;24642 Error err;
23639 switch (tagTypeId) {24643 switch (tagTypeId) {
23640 case ZigTypeIdInvalid:24644 case ZigTypeIdInvalid:
...@@ -23650,21 +24654,21 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -23650,21 +24654,21 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
23650 case ZigTypeIdInt: {24654 case ZigTypeIdInt: {
23651 assert(payload->special == ConstValSpecialStatic);24655 assert(payload->special == ConstValSpecialStatic);
23652 assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr));24656 assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr));
23653 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "bits", 1);24657 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "bits", 1);
23654 if (bi == nullptr)24658 if (bi == nullptr)
23655 return ira->codegen->invalid_instruction->value->type;24659 return ira->codegen->invalid_inst_gen->value->type;
23656 bool is_signed;24660 bool is_signed;
23657 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_signed", 0, &is_signed)))24661 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_signed", 0, &is_signed)))
23658 return ira->codegen->invalid_instruction->value->type;24662 return ira->codegen->invalid_inst_gen->value->type;
23659 return get_int_type(ira->codegen, is_signed, bigint_as_u32(bi));24663 return get_int_type(ira->codegen, is_signed, bigint_as_u32(bi));
23660 }24664 }
23661 case ZigTypeIdFloat:24665 case ZigTypeIdFloat:
23662 {24666 {
23663 assert(payload->special == ConstValSpecialStatic);24667 assert(payload->special == ConstValSpecialStatic);
23664 assert(payload->type == ir_type_info_get_type(ira, "Float", nullptr));24668 assert(payload->type == ir_type_info_get_type(ira, "Float", nullptr));
23665 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "bits", 0);24669 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "bits", 0);
23666 if (bi == nullptr)24670 if (bi == nullptr)
23667 return ira->codegen->invalid_instruction->value->type;24671 return ira->codegen->invalid_inst_gen->value->type;
23668 uint32_t bits = bigint_as_u32(bi);24672 uint32_t bits = bigint_as_u32(bi);
23669 switch (bits) {24673 switch (bits) {
23670 case 16: return ira->codegen->builtin_types.entry_f16;24674 case 16: return ira->codegen->builtin_types.entry_f16;
...@@ -23672,48 +24676,47 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -23672,48 +24676,47 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
23672 case 64: return ira->codegen->builtin_types.entry_f64;24676 case 64: return ira->codegen->builtin_types.entry_f64;
23673 case 128: return ira->codegen->builtin_types.entry_f128;24677 case 128: return ira->codegen->builtin_types.entry_f128;
23674 }24678 }
23675 ir_add_error(ira, instruction,24679 ir_add_error(ira, source_instr, buf_sprintf("%d-bit float unsupported", bits));
23676 buf_sprintf("%d-bit float unsupported", bits));24680 return ira->codegen->invalid_inst_gen->value->type;
23677 return ira->codegen->invalid_instruction->value->type;
23678 }24681 }
23679 case ZigTypeIdPointer:24682 case ZigTypeIdPointer:
23680 {24683 {
23681 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);24684 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
23682 assert(payload->special == ConstValSpecialStatic);24685 assert(payload->special == ConstValSpecialStatic);
23683 assert(payload->type == type_info_pointer_type);24686 assert(payload->type == type_info_pointer_type);
23684 ZigValue *size_value = get_const_field(ira, instruction->source_node, payload, "size", 0);24687 ZigValue *size_value = get_const_field(ira, source_instr->source_node, payload, "size", 0);
23685 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));24688 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));
23686 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);24689 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);
23687 PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);24690 PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);
23688 ZigType *elem_type = get_const_field_meta_type(ira, instruction->source_node, payload, "child", 4);24691 ZigType *elem_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 4);
23689 if (type_is_invalid(elem_type))24692 if (type_is_invalid(elem_type))
23690 return ira->codegen->invalid_instruction->value->type;24693 return ira->codegen->invalid_inst_gen->value->type;
23691 ZigValue *sentinel;24694 ZigValue *sentinel;
23692 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6,24695 if ((err = get_const_field_sentinel(ira, source_instr, payload, "sentinel", 6,
23693 elem_type, &sentinel)))24696 elem_type, &sentinel)))
23694 {24697 {
23695 return ira->codegen->invalid_instruction->value->type;24698 return ira->codegen->invalid_inst_gen->value->type;
23696 }24699 }
23697 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "alignment", 3);24700 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "alignment", 3);
23698 if (bi == nullptr)24701 if (bi == nullptr)
23699 return ira->codegen->invalid_instruction->value->type;24702 return ira->codegen->invalid_inst_gen->value->type;
2370024703
23701 bool is_const;24704 bool is_const;
23702 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_const", 1, &is_const)))24705 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_const", 1, &is_const)))
23703 return ira->codegen->invalid_instruction->value->type;24706 return ira->codegen->invalid_inst_gen->value->type;
2370424707
23705 bool is_volatile;24708 bool is_volatile;
23706 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_volatile", 2,24709 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_volatile", 2,
23707 &is_volatile)))24710 &is_volatile)))
23708 {24711 {
23709 return ira->codegen->invalid_instruction->value->type;24712 return ira->codegen->invalid_inst_gen->value->type;
23710 }24713 }
2371124714
23712 bool is_allowzero;24715 bool is_allowzero;
23713 if ((err = get_const_field_bool(ira, instruction->source_node, payload, "is_allowzero", 5,24716 if ((err = get_const_field_bool(ira, source_instr->source_node, payload, "is_allowzero", 5,
23714 &is_allowzero)))24717 &is_allowzero)))
23715 {24718 {
23716 return ira->codegen->invalid_instruction->value->type;24719 return ira->codegen->invalid_inst_gen->value->type;
23717 }24720 }
2371824721
2371924722
...@@ -23734,18 +24737,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -23734,18 +24737,18 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
23734 case ZigTypeIdArray: {24737 case ZigTypeIdArray: {
23735 assert(payload->special == ConstValSpecialStatic);24738 assert(payload->special == ConstValSpecialStatic);
23736 assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr));24739 assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr));
23737 ZigType *elem_type = get_const_field_meta_type(ira, instruction->source_node, payload, "child", 1);24740 ZigType *elem_type = get_const_field_meta_type(ira, source_instr->source_node, payload, "child", 1);
23738 if (type_is_invalid(elem_type))24741 if (type_is_invalid(elem_type))
23739 return ira->codegen->invalid_instruction->value->type;24742 return ira->codegen->invalid_inst_gen->value->type;
23740 ZigValue *sentinel;24743 ZigValue *sentinel;
23741 if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2,24744 if ((err = get_const_field_sentinel(ira, source_instr, payload, "sentinel", 2,
23742 elem_type, &sentinel)))24745 elem_type, &sentinel)))
23743 {24746 {
23744 return ira->codegen->invalid_instruction->value->type;24747 return ira->codegen->invalid_inst_gen->value->type;
23745 }24748 }
23746 BigInt *bi = get_const_field_lit_int(ira, instruction->source_node, payload, "len", 0);24749 BigInt *bi = get_const_field_lit_int(ira, source_instr->source_node, payload, "len", 0);
23747 if (bi == nullptr)24750 if (bi == nullptr)
23748 return ira->codegen->invalid_instruction->value->type;24751 return ira->codegen->invalid_inst_gen->value->type;
23749 return get_array_type(ira->codegen, elem_type, bigint_as_u64(bi), sentinel);24752 return get_array_type(ira->codegen, elem_type, bigint_as_u64(bi), sentinel);
23750 }24753 }
23751 case ZigTypeIdComptimeFloat:24754 case ZigTypeIdComptimeFloat:
...@@ -23765,78 +24768,77 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi...@@ -23765,78 +24768,77 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
23765 case ZigTypeIdAnyFrame:24768 case ZigTypeIdAnyFrame:
23766 case ZigTypeIdVector:24769 case ZigTypeIdVector:
23767 case ZigTypeIdEnumLiteral:24770 case ZigTypeIdEnumLiteral:
23768 ir_add_error(ira, instruction, buf_sprintf(24771 ir_add_error(ira, source_instr, buf_sprintf(
23769 "TODO implement @Type for 'TypeInfo.%s': see https://github.com/ziglang/zig/issues/2907", type_id_name(tagTypeId)));24772 "TODO implement @Type for 'TypeInfo.%s': see https://github.com/ziglang/zig/issues/2907", type_id_name(tagTypeId)));
23770 return ira->codegen->invalid_instruction->value->type;24773 return ira->codegen->invalid_inst_gen->value->type;
23771 case ZigTypeIdUnion:24774 case ZigTypeIdUnion:
23772 case ZigTypeIdFn:24775 case ZigTypeIdFn:
23773 case ZigTypeIdBoundFn:24776 case ZigTypeIdBoundFn:
23774 case ZigTypeIdStruct:24777 case ZigTypeIdStruct:
23775 ir_add_error(ira, instruction, buf_sprintf(24778 ir_add_error(ira, source_instr, buf_sprintf(
23776 "@Type not availble for 'TypeInfo.%s'", type_id_name(tagTypeId)));24779 "@Type not availble for 'TypeInfo.%s'", type_id_name(tagTypeId)));
23777 return ira->codegen->invalid_instruction->value->type;24780 return ira->codegen->invalid_inst_gen->value->type;
23778 }24781 }
23779 zig_unreachable();24782 zig_unreachable();
23780}24783}
2378124784
23782static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionType *instruction) {24785static IrInstGen *ir_analyze_instruction_type(IrAnalyze *ira, IrInstSrcType *instruction) {
23783 IrInstruction *type_info_ir = instruction->type_info->child;24786 IrInstGen *uncasted_type_info = instruction->type_info->child;
23784 if (type_is_invalid(type_info_ir->value->type))24787 if (type_is_invalid(uncasted_type_info->value->type))
23785 return ira->codegen->invalid_instruction;24788 return ira->codegen->invalid_inst_gen;
2378624789
23787 IrInstruction *casted_ir = ir_implicit_cast(ira, type_info_ir, ir_type_info_get_type(ira, nullptr, nullptr));24790 IrInstGen *type_info = ir_implicit_cast(ira, uncasted_type_info, ir_type_info_get_type(ira, nullptr, nullptr));
23788 if (type_is_invalid(casted_ir->value->type))24791 if (type_is_invalid(type_info->value->type))
23789 return ira->codegen->invalid_instruction;24792 return ira->codegen->invalid_inst_gen;
2379024793
23791 ZigValue *type_info_value = ir_resolve_const(ira, casted_ir, UndefBad);24794 ZigValue *type_info_val = ir_resolve_const(ira, type_info, UndefBad);
23792 if (!type_info_value)24795 if (type_info_val == nullptr)
23793 return ira->codegen->invalid_instruction;24796 return ira->codegen->invalid_inst_gen;
23794 ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag));24797 ZigTypeId type_id_tag = type_id_at_index(bigint_as_usize(&type_info_val->data.x_union.tag));
23795 ZigType *type = type_info_to_type(ira, type_info_ir, typeId, type_info_value->data.x_union.payload);24798 ZigType *type = type_info_to_type(ira, &uncasted_type_info->base, type_id_tag,
24799 type_info_val->data.x_union.payload);
23796 if (type_is_invalid(type))24800 if (type_is_invalid(type))
23797 return ira->codegen->invalid_instruction;24801 return ira->codegen->invalid_inst_gen;
23798 return ir_const_type(ira, &instruction->base, type);24802 return ir_const_type(ira, &instruction->base.base, type);
23799}24803}
2380024804
23801static IrInstruction *ir_analyze_instruction_type_id(IrAnalyze *ira,24805static IrInstGen *ir_analyze_instruction_type_id(IrAnalyze *ira, IrInstSrcTypeId *instruction) {
23802 IrInstructionTypeId *instruction)24806 IrInstGen *type_value = instruction->type_value->child;
23803{
23804 IrInstruction *type_value = instruction->type_value->child;
23805 ZigType *type_entry = ir_resolve_type(ira, type_value);24807 ZigType *type_entry = ir_resolve_type(ira, type_value);
23806 if (type_is_invalid(type_entry))24808 if (type_is_invalid(type_entry))
23807 return ira->codegen->invalid_instruction;24809 return ira->codegen->invalid_inst_gen;
2380824810
23809 ZigType *result_type = get_builtin_type(ira->codegen, "TypeId");24811 ZigType *result_type = get_builtin_type(ira->codegen, "TypeId");
2381024812
23811 IrInstruction *result = ir_const(ira, &instruction->base, result_type);24813 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
23812 bigint_init_unsigned(&result->value->data.x_enum_tag, type_id_index(type_entry));24814 bigint_init_unsigned(&result->value->data.x_enum_tag, type_id_index(type_entry));
23813 return result;24815 return result;
23814}24816}
2381524817
23816static IrInstruction *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,24818static IrInstGen *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira,
23817 IrInstructionSetEvalBranchQuota *instruction)24819 IrInstSrcSetEvalBranchQuota *instruction)
23818{24820{
23819 uint64_t new_quota;24821 uint64_t new_quota;
23820 if (!ir_resolve_usize(ira, instruction->new_quota->child, &new_quota))24822 if (!ir_resolve_usize(ira, instruction->new_quota->child, &new_quota))
23821 return ira->codegen->invalid_instruction;24823 return ira->codegen->invalid_inst_gen;
2382224824
23823 if (new_quota > *ira->new_irb.exec->backward_branch_quota) {24825 if (new_quota > *ira->new_irb.exec->backward_branch_quota) {
23824 *ira->new_irb.exec->backward_branch_quota = new_quota;24826 *ira->new_irb.exec->backward_branch_quota = new_quota;
23825 }24827 }
2382624828
23827 return ir_const_void(ira, &instruction->base);24829 return ir_const_void(ira, &instruction->base.base);
23828}24830}
2382924831
23830static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) {24832static IrInstGen *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstSrcTypeName *instruction) {
23831 IrInstruction *type_value = instruction->type_value->child;24833 IrInstGen *type_value = instruction->type_value->child;
23832 ZigType *type_entry = ir_resolve_type(ira, type_value);24834 ZigType *type_entry = ir_resolve_type(ira, type_value);
23833 if (type_is_invalid(type_entry))24835 if (type_is_invalid(type_entry))
23834 return ira->codegen->invalid_instruction;24836 return ira->codegen->invalid_inst_gen;
2383524837
23836 if (!type_entry->cached_const_name_val) {24838 if (!type_entry->cached_const_name_val) {
23837 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));24839 type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry));
23838 }24840 }
23839 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);24841 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
23840 copy_const_val(result->value, type_entry->cached_const_name_val);24842 copy_const_val(result->value, type_entry->cached_const_name_val);
23841 return result;24843 return result;
23842}24844}
...@@ -23848,23 +24850,30 @@ static void ir_cimport_cache_paths(Buf *cache_dir, Buf *tmp_c_file_digest, Buf *...@@ -23848,23 +24850,30 @@ static void ir_cimport_cache_paths(Buf *cache_dir, Buf *tmp_c_file_digest, Buf *
23848 buf_ptr(cache_dir), buf_ptr(tmp_c_file_digest));24850 buf_ptr(cache_dir), buf_ptr(tmp_c_file_digest));
23849 buf_appendf(out_zig_path, "%s" OS_SEP "cimport.zig", buf_ptr(out_zig_dir));24851 buf_appendf(out_zig_path, "%s" OS_SEP "cimport.zig", buf_ptr(out_zig_dir));
23850}24852}
23851static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCImport *instruction) {24853static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImport *instruction) {
23852 Error err;24854 Error err;
23853 AstNode *node = instruction->base.source_node;24855 AstNode *node = instruction->base.base.source_node;
23854 assert(node->type == NodeTypeFnCallExpr);24856 assert(node->type == NodeTypeFnCallExpr);
23855 AstNode *block_node = node->data.fn_call_expr.params.at(0);24857 AstNode *block_node = node->data.fn_call_expr.params.at(0);
2385624858
23857 ScopeCImport *cimport_scope = create_cimport_scope(ira->codegen, node, instruction->base.scope);24859 ScopeCImport *cimport_scope = create_cimport_scope(ira->codegen, node, instruction->base.base.scope);
2385824860
23859 // Execute the C import block like an inline function24861 // Execute the C import block like an inline function
23860 ZigType *void_type = ira->codegen->builtin_types.entry_void;24862 ZigType *void_type = ira->codegen->builtin_types.entry_void;
23861 ZigValue *cimport_result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type,24863 ZigValue *cimport_result;
24864 ZigValue *result_ptr;
24865 create_result_ptr(ira->codegen, void_type, &cimport_result, &result_ptr);
24866 if ((err = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, result_ptr,
23862 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,24867 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,
23863 &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad);24868 &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad)))
24869 {
24870 return ira->codegen->invalid_inst_gen;
24871 }
23864 if (type_is_invalid(cimport_result->type))24872 if (type_is_invalid(cimport_result->type))
23865 return ira->codegen->invalid_instruction;24873 return ira->codegen->invalid_inst_gen;
24874 destroy(result_ptr, "ZigValue");
2386624875
23867 ZigPackage *cur_scope_pkg = scope_package(instruction->base.scope);24876 ZigPackage *cur_scope_pkg = scope_package(instruction->base.base.scope);
23868 Buf *namespace_name = buf_sprintf("%s.cimport:%" ZIG_PRI_usize ":%" ZIG_PRI_usize,24877 Buf *namespace_name = buf_sprintf("%s.cimport:%" ZIG_PRI_usize ":%" ZIG_PRI_usize,
23869 buf_ptr(&cur_scope_pkg->pkg_path), node->line + 1, node->column + 1);24878 buf_ptr(&cur_scope_pkg->pkg_path), node->line + 1, node->column + 1);
2387024879
...@@ -23876,7 +24885,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct...@@ -23876,7 +24885,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
23876 CacheHash *cache_hash;24885 CacheHash *cache_hash;
23877 if ((err = create_c_object_cache(ira->codegen, &cache_hash, false))) {24886 if ((err = create_c_object_cache(ira->codegen, &cache_hash, false))) {
23878 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to create cache: %s", err_str(err)));24887 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to create cache: %s", err_str(err)));
23879 return ira->codegen->invalid_instruction;24888 return ira->codegen->invalid_inst_gen;
23880 }24889 }
23881 cache_buf(cache_hash, &cimport_scope->buf);24890 cache_buf(cache_hash, &cimport_scope->buf);
2388224891
...@@ -23888,7 +24897,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct...@@ -23888,7 +24897,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
23888 if ((err = cache_hit(cache_hash, &tmp_c_file_digest))) {24897 if ((err = cache_hit(cache_hash, &tmp_c_file_digest))) {
23889 if (err != ErrorInvalidFormat) {24898 if (err != ErrorInvalidFormat) {
23890 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to check cache: %s", err_str(err)));24899 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to check cache: %s", err_str(err)));
23891 return ira->codegen->invalid_instruction;24900 return ira->codegen->invalid_inst_gen;
23892 }24901 }
23893 }24902 }
23894 ira->codegen->caches_to_release.append(cache_hash);24903 ira->codegen->caches_to_release.append(cache_hash);
...@@ -23907,12 +24916,12 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct...@@ -23907,12 +24916,12 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2390724916
23908 if ((err = os_make_path(tmp_c_file_dir))) {24917 if ((err = os_make_path(tmp_c_file_dir))) {
23909 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to make dir: %s", err_str(err)));24918 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to make dir: %s", err_str(err)));
23910 return ira->codegen->invalid_instruction;24919 return ira->codegen->invalid_inst_gen;
23911 }24920 }
2391224921
23913 if ((err = os_write_file(&tmp_c_file_path, &cimport_scope->buf))) {24922 if ((err = os_write_file(&tmp_c_file_path, &cimport_scope->buf))) {
23914 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to write .h file: %s", err_str(err)));24923 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to write .h file: %s", err_str(err)));
23915 return ira->codegen->invalid_instruction;24924 return ira->codegen->invalid_inst_gen;
23916 }24925 }
23917 if (ira->codegen->verbose_cimport) {24926 if (ira->codegen->verbose_cimport) {
23918 fprintf(stderr, "@cImport source: %s\n", buf_ptr(&tmp_c_file_path));24927 fprintf(stderr, "@cImport source: %s\n", buf_ptr(&tmp_c_file_path));
...@@ -23947,7 +24956,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct...@@ -23947,7 +24956,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
23947 {24956 {
23948 if (err != ErrorCCompileErrors) {24957 if (err != ErrorCCompileErrors) {
23949 ir_add_error_node(ira, node, buf_sprintf("C import failed: %s", err_str(err)));24958 ir_add_error_node(ira, node, buf_sprintf("C import failed: %s", err_str(err)));
23950 return ira->codegen->invalid_instruction;24959 return ira->codegen->invalid_inst_gen;
23951 }24960 }
2395224961
23953 ErrorMsg *parent_err_msg = ir_add_error_node(ira, node, buf_sprintf("C import failed"));24962 ErrorMsg *parent_err_msg = ir_add_error_node(ira, node, buf_sprintf("C import failed"));
...@@ -23968,7 +24977,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct...@@ -23968,7 +24977,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
23968 }24977 }
23969 }24978 }
2397024979
23971 return ira->codegen->invalid_instruction;24980 return ira->codegen->invalid_inst_gen;
23972 }24981 }
23973 if (ira->codegen->verbose_cimport) {24982 if (ira->codegen->verbose_cimport) {
23974 fprintf(stderr, "@cImport .d file: %s\n", buf_ptr(tmp_dep_file));24983 fprintf(stderr, "@cImport .d file: %s\n", buf_ptr(tmp_dep_file));
...@@ -23976,29 +24985,29 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct...@@ -23976,29 +24985,29 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
2397624985
23977 if ((err = cache_add_dep_file(cache_hash, tmp_dep_file, false))) {24986 if ((err = cache_add_dep_file(cache_hash, tmp_dep_file, false))) {
23978 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to parse .d file: %s", err_str(err)));24987 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to parse .d file: %s", err_str(err)));
23979 return ira->codegen->invalid_instruction;24988 return ira->codegen->invalid_inst_gen;
23980 }24989 }
23981 if ((err = cache_final(cache_hash, &tmp_c_file_digest))) {24990 if ((err = cache_final(cache_hash, &tmp_c_file_digest))) {
23982 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to finalize cache: %s", err_str(err)));24991 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to finalize cache: %s", err_str(err)));
23983 return ira->codegen->invalid_instruction;24992 return ira->codegen->invalid_inst_gen;
23984 }24993 }
2398524994
23986 ir_cimport_cache_paths(ira->codegen->cache_dir, &tmp_c_file_digest, out_zig_dir, out_zig_path);24995 ir_cimport_cache_paths(ira->codegen->cache_dir, &tmp_c_file_digest, out_zig_dir, out_zig_path);
23987 if ((err = os_make_path(out_zig_dir))) {24996 if ((err = os_make_path(out_zig_dir))) {
23988 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to make output dir: %s", err_str(err)));24997 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to make output dir: %s", err_str(err)));
23989 return ira->codegen->invalid_instruction;24998 return ira->codegen->invalid_inst_gen;
23990 }24999 }
23991 FILE *out_file = fopen(buf_ptr(out_zig_path), "wb");25000 FILE *out_file = fopen(buf_ptr(out_zig_path), "wb");
23992 if (out_file == nullptr) {25001 if (out_file == nullptr) {
23993 ir_add_error_node(ira, node,25002 ir_add_error_node(ira, node,
23994 buf_sprintf("C import failed: unable to open output file: %s", strerror(errno)));25003 buf_sprintf("C import failed: unable to open output file: %s", strerror(errno)));
23995 return ira->codegen->invalid_instruction;25004 return ira->codegen->invalid_inst_gen;
23996 }25005 }
23997 stage2_render_ast(ast, out_file);25006 stage2_render_ast(ast, out_file);
23998 if (fclose(out_file) != 0) {25007 if (fclose(out_file) != 0) {
23999 ir_add_error_node(ira, node,25008 ir_add_error_node(ira, node,
24000 buf_sprintf("C import failed: unable to write to output file: %s", strerror(errno)));25009 buf_sprintf("C import failed: unable to write to output file: %s", strerror(errno)));
24001 return ira->codegen->invalid_instruction;25010 return ira->codegen->invalid_inst_gen;
24002 }25011 }
2400325012
24004 if (ira->codegen->verbose_cimport) {25013 if (ira->codegen->verbose_cimport) {
...@@ -24017,90 +25026,90 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct...@@ -24017,90 +25026,90 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
24017 if ((err = file_fetch(ira->codegen, out_zig_path, import_code))) {25026 if ((err = file_fetch(ira->codegen, out_zig_path, import_code))) {
24018 ir_add_error_node(ira, node,25027 ir_add_error_node(ira, node,
24019 buf_sprintf("unable to open '%s': %s", buf_ptr(out_zig_path), err_str(err)));25028 buf_sprintf("unable to open '%s': %s", buf_ptr(out_zig_path), err_str(err)));
24020 return ira->codegen->invalid_instruction;25029 return ira->codegen->invalid_inst_gen;
24021 }25030 }
24022 ZigType *child_import = add_source_file(ira->codegen, cimport_pkg, out_zig_path,25031 ZigType *child_import = add_source_file(ira->codegen, cimport_pkg, out_zig_path,
24023 import_code, SourceKindCImport);25032 import_code, SourceKindCImport);
24024 return ir_const_type(ira, &instruction->base, child_import);25033 return ir_const_type(ira, &instruction->base.base, child_import);
24025}25034}
2402625035
24027static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) {25036static IrInstGen *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstSrcCInclude *instruction) {
24028 IrInstruction *name_value = instruction->name->child;25037 IrInstGen *name_value = instruction->name->child;
24029 if (type_is_invalid(name_value->value->type))25038 if (type_is_invalid(name_value->value->type))
24030 return ira->codegen->invalid_instruction;25039 return ira->codegen->invalid_inst_gen;
2403125040
24032 Buf *include_name = ir_resolve_str(ira, name_value);25041 Buf *include_name = ir_resolve_str(ira, name_value);
24033 if (!include_name)25042 if (!include_name)
24034 return ira->codegen->invalid_instruction;25043 return ira->codegen->invalid_inst_gen;
2403525044
24036 Buf *c_import_buf = exec_c_import_buf(ira->new_irb.exec);25045 Buf *c_import_buf = ira->new_irb.exec->c_import_buf;
24037 // We check for this error in pass125046 // We check for this error in pass1
24038 assert(c_import_buf);25047 assert(c_import_buf);
2403925048
24040 buf_appendf(c_import_buf, "#include <%s>\n", buf_ptr(include_name));25049 buf_appendf(c_import_buf, "#include <%s>\n", buf_ptr(include_name));
2404125050
24042 return ir_const_void(ira, &instruction->base);25051 return ir_const_void(ira, &instruction->base.base);
24043}25052}
2404425053
24045static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) {25054static IrInstGen *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstSrcCDefine *instruction) {
24046 IrInstruction *name = instruction->name->child;25055 IrInstGen *name = instruction->name->child;
24047 if (type_is_invalid(name->value->type))25056 if (type_is_invalid(name->value->type))
24048 return ira->codegen->invalid_instruction;25057 return ira->codegen->invalid_inst_gen;
2404925058
24050 Buf *define_name = ir_resolve_str(ira, name);25059 Buf *define_name = ir_resolve_str(ira, name);
24051 if (!define_name)25060 if (!define_name)
24052 return ira->codegen->invalid_instruction;25061 return ira->codegen->invalid_inst_gen;
2405325062
24054 IrInstruction *value = instruction->value->child;25063 IrInstGen *value = instruction->value->child;
24055 if (type_is_invalid(value->value->type))25064 if (type_is_invalid(value->value->type))
24056 return ira->codegen->invalid_instruction;25065 return ira->codegen->invalid_inst_gen;
2405725066
24058 Buf *define_value = nullptr;25067 Buf *define_value = nullptr;
24059 // The second parameter is either a string or void (equivalent to "")25068 // The second parameter is either a string or void (equivalent to "")
24060 if (value->value->type->id != ZigTypeIdVoid) {25069 if (value->value->type->id != ZigTypeIdVoid) {
24061 define_value = ir_resolve_str(ira, value);25070 define_value = ir_resolve_str(ira, value);
24062 if (!define_value)25071 if (!define_value)
24063 return ira->codegen->invalid_instruction;25072 return ira->codegen->invalid_inst_gen;
24064 }25073 }
2406525074
24066 Buf *c_import_buf = exec_c_import_buf(ira->new_irb.exec);25075 Buf *c_import_buf = ira->new_irb.exec->c_import_buf;
24067 // We check for this error in pass125076 // We check for this error in pass1
24068 assert(c_import_buf);25077 assert(c_import_buf);
2406925078
24070 buf_appendf(c_import_buf, "#define %s %s\n", buf_ptr(define_name),25079 buf_appendf(c_import_buf, "#define %s %s\n", buf_ptr(define_name),
24071 define_value ? buf_ptr(define_value) : "");25080 define_value ? buf_ptr(define_value) : "");
2407225081
24073 return ir_const_void(ira, &instruction->base);25082 return ir_const_void(ira, &instruction->base.base);
24074}25083}
2407525084
24076static IrInstruction *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) {25085static IrInstGen *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstSrcCUndef *instruction) {
24077 IrInstruction *name = instruction->name->child;25086 IrInstGen *name = instruction->name->child;
24078 if (type_is_invalid(name->value->type))25087 if (type_is_invalid(name->value->type))
24079 return ira->codegen->invalid_instruction;25088 return ira->codegen->invalid_inst_gen;
2408025089
24081 Buf *undef_name = ir_resolve_str(ira, name);25090 Buf *undef_name = ir_resolve_str(ira, name);
24082 if (!undef_name)25091 if (!undef_name)
24083 return ira->codegen->invalid_instruction;25092 return ira->codegen->invalid_inst_gen;
2408425093
24085 Buf *c_import_buf = exec_c_import_buf(ira->new_irb.exec);25094 Buf *c_import_buf = ira->new_irb.exec->c_import_buf;
24086 // We check for this error in pass125095 // We check for this error in pass1
24087 assert(c_import_buf);25096 assert(c_import_buf);
2408825097
24089 buf_appendf(c_import_buf, "#undef %s\n", buf_ptr(undef_name));25098 buf_appendf(c_import_buf, "#undef %s\n", buf_ptr(undef_name));
2409025099
24091 return ir_const_void(ira, &instruction->base);25100 return ir_const_void(ira, &instruction->base.base);
24092}25101}
2409325102
24094static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) {25103static IrInstGen *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstSrcEmbedFile *instruction) {
24095 IrInstruction *name = instruction->name->child;25104 IrInstGen *name = instruction->name->child;
24096 if (type_is_invalid(name->value->type))25105 if (type_is_invalid(name->value->type))
24097 return ira->codegen->invalid_instruction;25106 return ira->codegen->invalid_inst_gen;
2409825107
24099 Buf *rel_file_path = ir_resolve_str(ira, name);25108 Buf *rel_file_path = ir_resolve_str(ira, name);
24100 if (!rel_file_path)25109 if (!rel_file_path)
24101 return ira->codegen->invalid_instruction;25110 return ira->codegen->invalid_inst_gen;
2410225111
24103 ZigType *import = get_scope_import(instruction->base.scope);25112 ZigType *import = get_scope_import(instruction->base.base.scope);
24104 // figure out absolute path to resource25113 // figure out absolute path to resource
24105 Buf source_dir_path = BUF_INIT;25114 Buf source_dir_path = BUF_INIT;
24106 os_path_dirname(import->data.structure.root_struct->path, &source_dir_path);25115 os_path_dirname(import->data.structure.root_struct->path, &source_dir_path);
...@@ -24117,93 +25126,95 @@ static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstru...@@ -24117,93 +25126,95 @@ static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstru
24117 Error err;25126 Error err;
24118 if ((err = file_fetch(ira->codegen, file_path, file_contents))) {25127 if ((err = file_fetch(ira->codegen, file_path, file_contents))) {
24119 if (err == ErrorFileNotFound) {25128 if (err == ErrorFileNotFound) {
24120 ir_add_error(ira, instruction->name, buf_sprintf("unable to find '%s'", buf_ptr(file_path)));25129 ir_add_error(ira, &instruction->name->base,
24121 return ira->codegen->invalid_instruction;25130 buf_sprintf("unable to find '%s'", buf_ptr(file_path)));
25131 return ira->codegen->invalid_inst_gen;
24122 } else {25132 } else {
24123 ir_add_error(ira, instruction->name, buf_sprintf("unable to open '%s': %s", buf_ptr(file_path), err_str(err)));25133 ir_add_error(ira, &instruction->name->base,
24124 return ira->codegen->invalid_instruction;25134 buf_sprintf("unable to open '%s': %s", buf_ptr(file_path), err_str(err)));
25135 return ira->codegen->invalid_inst_gen;
24125 }25136 }
24126 }25137 }
2412725138
24128 ZigType *result_type = get_array_type(ira->codegen,25139 ZigType *result_type = get_array_type(ira->codegen,
24129 ira->codegen->builtin_types.entry_u8, buf_len(file_contents), nullptr);25140 ira->codegen->builtin_types.entry_u8, buf_len(file_contents), nullptr);
24130 IrInstruction *result = ir_const(ira, &instruction->base, result_type);25141 IrInstGen *result = ir_const(ira, &instruction->base.base, result_type);
24131 init_const_str_lit(ira->codegen, result->value, file_contents);25142 init_const_str_lit(ira->codegen, result->value, file_contents);
24132 return result;25143 return result;
24133}25144}
2413425145
24135static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchgSrc *instruction) {25146static IrInstGen *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstSrcCmpxchg *instruction) {
24136 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->child);25147 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->child);
24137 if (type_is_invalid(operand_type))25148 if (type_is_invalid(operand_type))
24138 return ira->codegen->invalid_instruction;25149 return ira->codegen->invalid_inst_gen;
2413925150
24140 if (operand_type->id == ZigTypeIdFloat) {25151 if (operand_type->id == ZigTypeIdFloat) {
24141 ir_add_error(ira, instruction->type_value->child,25152 ir_add_error(ira, &instruction->type_value->child->base,
24142 buf_sprintf("expected integer, enum or pointer type, found '%s'", buf_ptr(&operand_type->name)));25153 buf_sprintf("expected integer, enum or pointer type, found '%s'", buf_ptr(&operand_type->name)));
24143 return ira->codegen->invalid_instruction;25154 return ira->codegen->invalid_inst_gen;
24144 }25155 }
2414525156
24146 IrInstruction *ptr = instruction->ptr->child;25157 IrInstGen *ptr = instruction->ptr->child;
24147 if (type_is_invalid(ptr->value->type))25158 if (type_is_invalid(ptr->value->type))
24148 return ira->codegen->invalid_instruction;25159 return ira->codegen->invalid_inst_gen;
2414925160
24150 // TODO let this be volatile25161 // TODO let this be volatile
24151 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);25162 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
24152 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type);25163 IrInstGen *casted_ptr = ir_implicit_cast2(ira, &instruction->ptr->base, ptr, ptr_type);
24153 if (type_is_invalid(casted_ptr->value->type))25164 if (type_is_invalid(casted_ptr->value->type))
24154 return ira->codegen->invalid_instruction;25165 return ira->codegen->invalid_inst_gen;
2415525166
24156 IrInstruction *cmp_value = instruction->cmp_value->child;25167 IrInstGen *cmp_value = instruction->cmp_value->child;
24157 if (type_is_invalid(cmp_value->value->type))25168 if (type_is_invalid(cmp_value->value->type))
24158 return ira->codegen->invalid_instruction;25169 return ira->codegen->invalid_inst_gen;
2415925170
24160 IrInstruction *new_value = instruction->new_value->child;25171 IrInstGen *new_value = instruction->new_value->child;
24161 if (type_is_invalid(new_value->value->type))25172 if (type_is_invalid(new_value->value->type))
24162 return ira->codegen->invalid_instruction;25173 return ira->codegen->invalid_inst_gen;
2416325174
24164 IrInstruction *success_order_value = instruction->success_order_value->child;25175 IrInstGen *success_order_value = instruction->success_order_value->child;
24165 if (type_is_invalid(success_order_value->value->type))25176 if (type_is_invalid(success_order_value->value->type))
24166 return ira->codegen->invalid_instruction;25177 return ira->codegen->invalid_inst_gen;
2416725178
24168 AtomicOrder success_order;25179 AtomicOrder success_order;
24169 if (!ir_resolve_atomic_order(ira, success_order_value, &success_order))25180 if (!ir_resolve_atomic_order(ira, success_order_value, &success_order))
24170 return ira->codegen->invalid_instruction;25181 return ira->codegen->invalid_inst_gen;
2417125182
24172 IrInstruction *failure_order_value = instruction->failure_order_value->child;25183 IrInstGen *failure_order_value = instruction->failure_order_value->child;
24173 if (type_is_invalid(failure_order_value->value->type))25184 if (type_is_invalid(failure_order_value->value->type))
24174 return ira->codegen->invalid_instruction;25185 return ira->codegen->invalid_inst_gen;
2417525186
24176 AtomicOrder failure_order;25187 AtomicOrder failure_order;
24177 if (!ir_resolve_atomic_order(ira, failure_order_value, &failure_order))25188 if (!ir_resolve_atomic_order(ira, failure_order_value, &failure_order))
24178 return ira->codegen->invalid_instruction;25189 return ira->codegen->invalid_inst_gen;
2417925190
24180 IrInstruction *casted_cmp_value = ir_implicit_cast(ira, cmp_value, operand_type);25191 IrInstGen *casted_cmp_value = ir_implicit_cast2(ira, &instruction->cmp_value->base, cmp_value, operand_type);
24181 if (type_is_invalid(casted_cmp_value->value->type))25192 if (type_is_invalid(casted_cmp_value->value->type))
24182 return ira->codegen->invalid_instruction;25193 return ira->codegen->invalid_inst_gen;
2418325194
24184 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, operand_type);25195 IrInstGen *casted_new_value = ir_implicit_cast2(ira, &instruction->new_value->base, new_value, operand_type);
24185 if (type_is_invalid(casted_new_value->value->type))25196 if (type_is_invalid(casted_new_value->value->type))
24186 return ira->codegen->invalid_instruction;25197 return ira->codegen->invalid_inst_gen;
2418725198
24188 if (success_order < AtomicOrderMonotonic) {25199 if (success_order < AtomicOrderMonotonic) {
24189 ir_add_error(ira, success_order_value,25200 ir_add_error(ira, &success_order_value->base,
24190 buf_sprintf("success atomic ordering must be Monotonic or stricter"));25201 buf_sprintf("success atomic ordering must be Monotonic or stricter"));
24191 return ira->codegen->invalid_instruction;25202 return ira->codegen->invalid_inst_gen;
24192 }25203 }
24193 if (failure_order < AtomicOrderMonotonic) {25204 if (failure_order < AtomicOrderMonotonic) {
24194 ir_add_error(ira, failure_order_value,25205 ir_add_error(ira, &failure_order_value->base,
24195 buf_sprintf("failure atomic ordering must be Monotonic or stricter"));25206 buf_sprintf("failure atomic ordering must be Monotonic or stricter"));
24196 return ira->codegen->invalid_instruction;25207 return ira->codegen->invalid_inst_gen;
24197 }25208 }
24198 if (failure_order > success_order) {25209 if (failure_order > success_order) {
24199 ir_add_error(ira, failure_order_value,25210 ir_add_error(ira, &failure_order_value->base,
24200 buf_sprintf("failure atomic ordering must be no stricter than success"));25211 buf_sprintf("failure atomic ordering must be no stricter than success"));
24201 return ira->codegen->invalid_instruction;25212 return ira->codegen->invalid_inst_gen;
24202 }25213 }
24203 if (failure_order == AtomicOrderRelease || failure_order == AtomicOrderAcqRel) {25214 if (failure_order == AtomicOrderRelease || failure_order == AtomicOrderAcqRel) {
24204 ir_add_error(ira, failure_order_value,25215 ir_add_error(ira, &failure_order_value->base,
24205 buf_sprintf("failure atomic ordering must not be Release or AcqRel"));25216 buf_sprintf("failure atomic ordering must not be Release or AcqRel"));
24206 return ira->codegen->invalid_instruction;25217 return ira->codegen->invalid_inst_gen;
24207 }25218 }
2420825219
24209 if (instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar &&25220 if (instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
...@@ -24212,152 +25223,146 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi...@@ -24212,152 +25223,146 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi
24212 }25223 }
2421325224
24214 ZigType *result_type = get_optional_type(ira->codegen, operand_type);25225 ZigType *result_type = get_optional_type(ira->codegen, operand_type);
24215 IrInstruction *result_loc;25226 IrInstGen *result_loc;
24216 if (handle_is_ptr(result_type)) {25227 if (handle_is_ptr(result_type)) {
24217 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,25228 result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
24218 result_type, nullptr, true, false, true);25229 result_type, nullptr, true, true);
24219 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {25230 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
24220 return result_loc;25231 return result_loc;
24221 }25232 }
24222 } else {25233 } else {
24223 result_loc = nullptr;25234 result_loc = nullptr;
24224 }25235 }
2422525236
24226 return ir_build_cmpxchg_gen(ira, &instruction->base, result_type,25237 return ir_build_cmpxchg_gen(ira, &instruction->base.base, result_type,
24227 casted_ptr, casted_cmp_value, casted_new_value,25238 casted_ptr, casted_cmp_value, casted_new_value,
24228 success_order, failure_order, instruction->is_weak, result_loc);25239 success_order, failure_order, instruction->is_weak, result_loc);
24229}25240}
2423025241
24231static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) {25242static IrInstGen *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstSrcFence *instruction) {
24232 IrInstruction *order_value = instruction->order_value->child;25243 IrInstGen *order_inst = instruction->order->child;
24233 if (type_is_invalid(order_value->value->type))25244 if (type_is_invalid(order_inst->value->type))
24234 return ira->codegen->invalid_instruction;25245 return ira->codegen->invalid_inst_gen;
2423525246
24236 AtomicOrder order;25247 AtomicOrder order;
24237 if (!ir_resolve_atomic_order(ira, order_value, &order))25248 if (!ir_resolve_atomic_order(ira, order_inst, &order))
24238 return ira->codegen->invalid_instruction;25249 return ira->codegen->invalid_inst_gen;
2423925250
24240 if (order < AtomicOrderAcquire) {25251 if (order < AtomicOrderAcquire) {
24241 ir_add_error(ira, order_value,25252 ir_add_error(ira, &order_inst->base,
24242 buf_sprintf("atomic ordering must be Acquire or stricter"));25253 buf_sprintf("atomic ordering must be Acquire or stricter"));
24243 return ira->codegen->invalid_instruction;25254 return ira->codegen->invalid_inst_gen;
24244 }25255 }
2424525256
24246 IrInstruction *result = ir_build_fence(&ira->new_irb,25257 return ir_build_fence_gen(ira, &instruction->base.base, order);
24247 instruction->base.scope, instruction->base.source_node, order_value, order);
24248 result->value->type = ira->codegen->builtin_types.entry_void;
24249 return result;
24250}25258}
2425125259
24252static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) {25260static IrInstGen *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstSrcTruncate *instruction) {
24253 IrInstruction *dest_type_value = instruction->dest_type->child;25261 IrInstGen *dest_type_value = instruction->dest_type->child;
24254 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);25262 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
24255 if (type_is_invalid(dest_type))25263 if (type_is_invalid(dest_type))
24256 return ira->codegen->invalid_instruction;25264 return ira->codegen->invalid_inst_gen;
2425725265
24258 if (dest_type->id != ZigTypeIdInt &&25266 if (dest_type->id != ZigTypeIdInt &&
24259 dest_type->id != ZigTypeIdComptimeInt)25267 dest_type->id != ZigTypeIdComptimeInt)
24260 {25268 {
24261 ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));25269 ir_add_error(ira, &dest_type_value->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
24262 return ira->codegen->invalid_instruction;25270 return ira->codegen->invalid_inst_gen;
24263 }25271 }
2426425272
24265 IrInstruction *target = instruction->target->child;25273 IrInstGen *target = instruction->target->child;
24266 ZigType *src_type = target->value->type;25274 ZigType *src_type = target->value->type;
24267 if (type_is_invalid(src_type))25275 if (type_is_invalid(src_type))
24268 return ira->codegen->invalid_instruction;25276 return ira->codegen->invalid_inst_gen;
2426925277
24270 if (src_type->id != ZigTypeIdInt &&25278 if (src_type->id != ZigTypeIdInt &&
24271 src_type->id != ZigTypeIdComptimeInt)25279 src_type->id != ZigTypeIdComptimeInt)
24272 {25280 {
24273 ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));25281 ir_add_error(ira, &target->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));
24274 return ira->codegen->invalid_instruction;25282 return ira->codegen->invalid_inst_gen;
24275 }25283 }
2427625284
24277 if (dest_type->id == ZigTypeIdComptimeInt) {25285 if (dest_type->id == ZigTypeIdComptimeInt) {
24278 return ir_implicit_cast(ira, target, dest_type);25286 return ir_implicit_cast2(ira, &instruction->target->base, target, dest_type);
24279 }25287 }
2428025288
24281 if (instr_is_comptime(target)) {25289 if (instr_is_comptime(target)) {
24282 ZigValue *val = ir_resolve_const(ira, target, UndefBad);25290 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
24283 if (val == nullptr)25291 if (val == nullptr)
24284 return ira->codegen->invalid_instruction;25292 return ira->codegen->invalid_inst_gen;
2428525293
24286 IrInstruction *result = ir_const(ira, &instruction->base, dest_type);25294 IrInstGen *result = ir_const(ira, &instruction->base.base, dest_type);
24287 bigint_truncate(&result->value->data.x_bigint, &val->data.x_bigint,25295 bigint_truncate(&result->value->data.x_bigint, &val->data.x_bigint,
24288 dest_type->data.integral.bit_count, dest_type->data.integral.is_signed);25296 dest_type->data.integral.bit_count, dest_type->data.integral.is_signed);
24289 return result;25297 return result;
24290 }25298 }
2429125299
24292 if (src_type->data.integral.bit_count == 0 || dest_type->data.integral.bit_count == 0) {25300 if (src_type->data.integral.bit_count == 0 || dest_type->data.integral.bit_count == 0) {
24293 IrInstruction *result = ir_const(ira, &instruction->base, dest_type);25301 IrInstGen *result = ir_const(ira, &instruction->base.base, dest_type);
24294 bigint_init_unsigned(&result->value->data.x_bigint, 0);25302 bigint_init_unsigned(&result->value->data.x_bigint, 0);
24295 return result;25303 return result;
24296 }25304 }
2429725305
24298 if (src_type->data.integral.is_signed != dest_type->data.integral.is_signed) {25306 if (src_type->data.integral.is_signed != dest_type->data.integral.is_signed) {
24299 const char *sign_str = dest_type->data.integral.is_signed ? "signed" : "unsigned";25307 const char *sign_str = dest_type->data.integral.is_signed ? "signed" : "unsigned";
24300 ir_add_error(ira, target, buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name)));25308 ir_add_error(ira, &target->base, buf_sprintf("expected %s integer type, found '%s'", sign_str, buf_ptr(&src_type->name)));
24301 return ira->codegen->invalid_instruction;25309 return ira->codegen->invalid_inst_gen;
24302 } else if (src_type->data.integral.bit_count < dest_type->data.integral.bit_count) {25310 } else if (src_type->data.integral.bit_count < dest_type->data.integral.bit_count) {
24303 ir_add_error(ira, target, buf_sprintf("type '%s' has fewer bits than destination type '%s'",25311 ir_add_error(ira, &target->base, buf_sprintf("type '%s' has fewer bits than destination type '%s'",
24304 buf_ptr(&src_type->name), buf_ptr(&dest_type->name)));25312 buf_ptr(&src_type->name), buf_ptr(&dest_type->name)));
24305 return ira->codegen->invalid_instruction;25313 return ira->codegen->invalid_inst_gen;
24306 }25314 }
2430725315
24308 IrInstruction *new_instruction = ir_build_truncate(&ira->new_irb, instruction->base.scope,25316 return ir_build_truncate_gen(ira, &instruction->base.base, dest_type, target);
24309 instruction->base.source_node, dest_type_value, target);
24310 new_instruction->value->type = dest_type;
24311 return new_instruction;
24312}25317}
2431325318
24314static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) {25319static IrInstGen *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstSrcIntCast *instruction) {
24315 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);25320 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
24316 if (type_is_invalid(dest_type))25321 if (type_is_invalid(dest_type))
24317 return ira->codegen->invalid_instruction;25322 return ira->codegen->invalid_inst_gen;
2431825323
24319 if (dest_type->id != ZigTypeIdInt && dest_type->id != ZigTypeIdComptimeInt) {25324 if (dest_type->id != ZigTypeIdInt && dest_type->id != ZigTypeIdComptimeInt) {
24320 ir_add_error(ira, instruction->dest_type, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));25325 ir_add_error(ira, &instruction->dest_type->base, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
24321 return ira->codegen->invalid_instruction;25326 return ira->codegen->invalid_inst_gen;
24322 }25327 }
2432325328
24324 IrInstruction *target = instruction->target->child;25329 IrInstGen *target = instruction->target->child;
24325 if (type_is_invalid(target->value->type))25330 if (type_is_invalid(target->value->type))
24326 return ira->codegen->invalid_instruction;25331 return ira->codegen->invalid_inst_gen;
2432725332
24328 if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) {25333 if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) {
24329 ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'",25334 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected integer type, found '%s'",
24330 buf_ptr(&target->value->type->name)));25335 buf_ptr(&target->value->type->name)));
24331 return ira->codegen->invalid_instruction;25336 return ira->codegen->invalid_inst_gen;
24332 }25337 }
2433325338
24334 if (instr_is_comptime(target)) {25339 if (instr_is_comptime(target)) {
24335 return ir_implicit_cast(ira, target, dest_type);25340 return ir_implicit_cast2(ira, &instruction->target->base, target, dest_type);
24336 }25341 }
2433725342
24338 if (dest_type->id == ZigTypeIdComptimeInt) {25343 if (dest_type->id == ZigTypeIdComptimeInt) {
24339 ir_add_error(ira, instruction->target, buf_sprintf("attempt to cast runtime value to '%s'",25344 ir_add_error(ira, &instruction->target->base, buf_sprintf("attempt to cast runtime value to '%s'",
24340 buf_ptr(&dest_type->name)));25345 buf_ptr(&dest_type->name)));
24341 return ira->codegen->invalid_instruction;25346 return ira->codegen->invalid_inst_gen;
24342 }25347 }
2434325348
24344 return ir_analyze_widen_or_shorten(ira, &instruction->base, target, dest_type);25349 return ir_analyze_widen_or_shorten(ira, &instruction->base.base, target, dest_type);
24345}25350}
2434625351
24347static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) {25352static IrInstGen *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstSrcFloatCast *instruction) {
24348 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);25353 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
24349 if (type_is_invalid(dest_type))25354 if (type_is_invalid(dest_type))
24350 return ira->codegen->invalid_instruction;25355 return ira->codegen->invalid_inst_gen;
2435125356
24352 if (dest_type->id != ZigTypeIdFloat) {25357 if (dest_type->id != ZigTypeIdFloat) {
24353 ir_add_error(ira, instruction->dest_type,25358 ir_add_error(ira, &instruction->dest_type->base,
24354 buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name)));25359 buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name)));
24355 return ira->codegen->invalid_instruction;25360 return ira->codegen->invalid_inst_gen;
24356 }25361 }
2435725362
24358 IrInstruction *target = instruction->target->child;25363 IrInstGen *target = instruction->target->child;
24359 if (type_is_invalid(target->value->type))25364 if (type_is_invalid(target->value->type))
24360 return ira->codegen->invalid_instruction;25365 return ira->codegen->invalid_inst_gen;
2436125366
24362 if (target->value->type->id == ZigTypeIdComptimeInt ||25367 if (target->value->type->id == ZigTypeIdComptimeInt ||
24363 target->value->type->id == ZigTypeIdComptimeFloat)25368 target->value->type->id == ZigTypeIdComptimeFloat)
...@@ -24369,55 +25374,55 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru...@@ -24369,55 +25374,55 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru
24369 } else {25374 } else {
24370 op = CastOpNumLitToConcrete;25375 op = CastOpNumLitToConcrete;
24371 }25376 }
24372 return ir_resolve_cast(ira, &instruction->base, target, dest_type, op);25377 return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, op);
24373 } else {25378 } else {
24374 return ira->codegen->invalid_instruction;25379 return ira->codegen->invalid_inst_gen;
24375 }25380 }
24376 }25381 }
2437725382
24378 if (target->value->type->id != ZigTypeIdFloat) {25383 if (target->value->type->id != ZigTypeIdFloat) {
24379 ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'",25384 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected float type, found '%s'",
24380 buf_ptr(&target->value->type->name)));25385 buf_ptr(&target->value->type->name)));
24381 return ira->codegen->invalid_instruction;25386 return ira->codegen->invalid_inst_gen;
24382 }25387 }
2438325388
24384 return ir_analyze_widen_or_shorten(ira, &instruction->base, target, dest_type);25389 return ir_analyze_widen_or_shorten(ira, &instruction->base.base, target, dest_type);
24385}25390}
2438625391
24387static IrInstruction *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) {25392static IrInstGen *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstSrcErrSetCast *instruction) {
24388 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);25393 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
24389 if (type_is_invalid(dest_type))25394 if (type_is_invalid(dest_type))
24390 return ira->codegen->invalid_instruction;25395 return ira->codegen->invalid_inst_gen;
2439125396
24392 if (dest_type->id != ZigTypeIdErrorSet) {25397 if (dest_type->id != ZigTypeIdErrorSet) {
24393 ir_add_error(ira, instruction->dest_type,25398 ir_add_error(ira, &instruction->dest_type->base,
24394 buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name)));25399 buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name)));
24395 return ira->codegen->invalid_instruction;25400 return ira->codegen->invalid_inst_gen;
24396 }25401 }
2439725402
24398 IrInstruction *target = instruction->target->child;25403 IrInstGen *target = instruction->target->child;
24399 if (type_is_invalid(target->value->type))25404 if (type_is_invalid(target->value->type))
24400 return ira->codegen->invalid_instruction;25405 return ira->codegen->invalid_inst_gen;
2440125406
24402 if (target->value->type->id != ZigTypeIdErrorSet) {25407 if (target->value->type->id != ZigTypeIdErrorSet) {
24403 ir_add_error(ira, instruction->target,25408 ir_add_error(ira, &instruction->target->base,
24404 buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value->type->name)));25409 buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value->type->name)));
24405 return ira->codegen->invalid_instruction;25410 return ira->codegen->invalid_inst_gen;
24406 }25411 }
2440725412
24408 return ir_analyze_err_set_cast(ira, &instruction->base, target, dest_type);25413 return ir_analyze_err_set_cast(ira, &instruction->base.base, target, dest_type);
24409}25414}
2441025415
24411static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) {25416static IrInstGen *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstSrcFromBytes *instruction) {
24412 Error err;25417 Error err;
2441325418
24414 ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->child);25419 ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->child);
24415 if (type_is_invalid(dest_child_type))25420 if (type_is_invalid(dest_child_type))
24416 return ira->codegen->invalid_instruction;25421 return ira->codegen->invalid_inst_gen;
2441725422
24418 IrInstruction *target = instruction->target->child;25423 IrInstGen *target = instruction->target->child;
24419 if (type_is_invalid(target->value->type))25424 if (type_is_invalid(target->value->type))
24420 return ira->codegen->invalid_instruction;25425 return ira->codegen->invalid_inst_gen;
2442125426
24422 bool src_ptr_const;25427 bool src_ptr_const;
24423 bool src_ptr_volatile;25428 bool src_ptr_volatile;
...@@ -24427,27 +25432,27 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru...@@ -24427,27 +25432,27 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
24427 src_ptr_volatile = target->value->type->data.pointer.is_volatile;25432 src_ptr_volatile = target->value->type->data.pointer.is_volatile;
2442825433
24429 if ((err = resolve_ptr_align(ira, target->value->type, &src_ptr_align)))25434 if ((err = resolve_ptr_align(ira, target->value->type, &src_ptr_align)))
24430 return ira->codegen->invalid_instruction;25435 return ira->codegen->invalid_inst_gen;
24431 } else if (is_slice(target->value->type)) {25436 } else if (is_slice(target->value->type)) {
24432 ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry;25437 ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry;
24433 src_ptr_const = src_ptr_type->data.pointer.is_const;25438 src_ptr_const = src_ptr_type->data.pointer.is_const;
24434 src_ptr_volatile = src_ptr_type->data.pointer.is_volatile;25439 src_ptr_volatile = src_ptr_type->data.pointer.is_volatile;
2443525440
24436 if ((err = resolve_ptr_align(ira, src_ptr_type, &src_ptr_align)))25441 if ((err = resolve_ptr_align(ira, src_ptr_type, &src_ptr_align)))
24437 return ira->codegen->invalid_instruction;25442 return ira->codegen->invalid_inst_gen;
24438 } else {25443 } else {
24439 src_ptr_const = true;25444 src_ptr_const = true;
24440 src_ptr_volatile = false;25445 src_ptr_volatile = false;
2444125446
24442 if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusAlignmentKnown)))25447 if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusAlignmentKnown)))
24443 return ira->codegen->invalid_instruction;25448 return ira->codegen->invalid_inst_gen;
2444425449
24445 src_ptr_align = get_abi_alignment(ira->codegen, target->value->type);25450 src_ptr_align = get_abi_alignment(ira->codegen, target->value->type);
24446 }25451 }
2444725452
24448 if (src_ptr_align != 0) {25453 if (src_ptr_align != 0) {
24449 if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusAlignmentKnown)))25454 if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusAlignmentKnown)))
24450 return ira->codegen->invalid_instruction;25455 return ira->codegen->invalid_inst_gen;
24451 }25456 }
2445225457
24453 ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_child_type,25458 ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_child_type,
...@@ -24460,9 +25465,9 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru...@@ -24460,9 +25465,9 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
24460 src_ptr_align, 0, 0, false);25465 src_ptr_align, 0, 0, false);
24461 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);25466 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);
2446225467
24463 IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice);25468 IrInstGen *casted_value = ir_implicit_cast2(ira, &instruction->target->base, target, u8_slice);
24464 if (type_is_invalid(casted_value->value->type))25469 if (type_is_invalid(casted_value->value->type))
24465 return ira->codegen->invalid_instruction;25470 return ira->codegen->invalid_inst_gen;
2446625471
24467 bool have_known_len = false;25472 bool have_known_len = false;
24468 uint64_t known_len;25473 uint64_t known_len;
...@@ -24470,7 +25475,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru...@@ -24470,7 +25475,7 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
24470 if (instr_is_comptime(casted_value)) {25475 if (instr_is_comptime(casted_value)) {
24471 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);25476 ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad);
24472 if (!val)25477 if (!val)
24473 return ira->codegen->invalid_instruction;25478 return ira->codegen->invalid_inst_gen;
2447425479
24475 ZigValue *len_val = val->data.x_struct.fields[slice_len_index];25480 ZigValue *len_val = val->data.x_struct.fields[slice_len_index];
24476 if (value_is_comptime(len_val)) {25481 if (value_is_comptime(len_val)) {
...@@ -24479,9 +25484,9 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru...@@ -24479,9 +25484,9 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
24479 }25484 }
24480 }25485 }
2448125486
24482 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,25487 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
24483 dest_slice_type, nullptr, true, false, true);25488 dest_slice_type, nullptr, true, true);
24484 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) {25489 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable)) {
24485 return result_loc;25490 return result_loc;
24486 }25491 }
2448725492
...@@ -24498,41 +25503,41 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru...@@ -24498,41 +25503,41 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru
2449825503
24499 if (have_known_len) {25504 if (have_known_len) {
24500 if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusSizeKnown)))25505 if ((err = type_resolve(ira->codegen, dest_child_type, ResolveStatusSizeKnown)))
24501 return ira->codegen->invalid_instruction;25506 return ira->codegen->invalid_inst_gen;
24502 uint64_t child_type_size = type_size(ira->codegen, dest_child_type);25507 uint64_t child_type_size = type_size(ira->codegen, dest_child_type);
24503 uint64_t remainder = known_len % child_type_size;25508 uint64_t remainder = known_len % child_type_size;
24504 if (remainder != 0) {25509 if (remainder != 0) {
24505 ErrorMsg *msg = ir_add_error(ira, &instruction->base,25510 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
24506 buf_sprintf("unable to convert [%" ZIG_PRI_u64 "]u8 to %s: size mismatch",25511 buf_sprintf("unable to convert [%" ZIG_PRI_u64 "]u8 to %s: size mismatch",
24507 known_len, buf_ptr(&dest_slice_type->name)));25512 known_len, buf_ptr(&dest_slice_type->name)));
24508 add_error_note(ira->codegen, msg, instruction->dest_child_type->source_node,25513 add_error_note(ira->codegen, msg, instruction->dest_child_type->base.source_node,
24509 buf_sprintf("%s has size %" ZIG_PRI_u64 "; remaining bytes: %" ZIG_PRI_u64,25514 buf_sprintf("%s has size %" ZIG_PRI_u64 "; remaining bytes: %" ZIG_PRI_u64,
24510 buf_ptr(&dest_child_type->name), child_type_size, remainder));25515 buf_ptr(&dest_child_type->name), child_type_size, remainder));
24511 return ira->codegen->invalid_instruction;25516 return ira->codegen->invalid_inst_gen;
24512 }25517 }
24513 }25518 }
2451425519
24515 return ir_build_resize_slice(ira, &instruction->base, casted_value, dest_slice_type, result_loc);25520 return ir_build_resize_slice(ira, &instruction->base.base, casted_value, dest_slice_type, result_loc);
24516}25521}
2451725522
24518static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) {25523static IrInstGen *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstSrcToBytes *instruction) {
24519 Error err;25524 Error err;
2452025525
24521 IrInstruction *target = instruction->target->child;25526 IrInstGen *target = instruction->target->child;
24522 if (type_is_invalid(target->value->type))25527 if (type_is_invalid(target->value->type))
24523 return ira->codegen->invalid_instruction;25528 return ira->codegen->invalid_inst_gen;
2452425529
24525 if (!is_slice(target->value->type)) {25530 if (!is_slice(target->value->type)) {
24526 ir_add_error(ira, instruction->target,25531 ir_add_error(ira, &instruction->target->base,
24527 buf_sprintf("expected slice, found '%s'", buf_ptr(&target->value->type->name)));25532 buf_sprintf("expected slice, found '%s'", buf_ptr(&target->value->type->name)));
24528 return ira->codegen->invalid_instruction;25533 return ira->codegen->invalid_inst_gen;
24529 }25534 }
2453025535
24531 ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry;25536 ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry;
2453225537
24533 uint32_t alignment;25538 uint32_t alignment;
24534 if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment)))25539 if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment)))
24535 return ira->codegen->invalid_instruction;25540 return ira->codegen->invalid_inst_gen;
2453625541
24537 ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,25542 ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
24538 src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown,25543 src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown,
...@@ -24542,9 +25547,9 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct...@@ -24542,9 +25547,9 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
24542 if (instr_is_comptime(target)) {25547 if (instr_is_comptime(target)) {
24543 ZigValue *target_val = ir_resolve_const(ira, target, UndefBad);25548 ZigValue *target_val = ir_resolve_const(ira, target, UndefBad);
24544 if (target_val == nullptr)25549 if (target_val == nullptr)
24545 return ira->codegen->invalid_instruction;25550 return ira->codegen->invalid_inst_gen;
2454625551
24547 IrInstruction *result = ir_const(ira, &instruction->base, dest_slice_type);25552 IrInstGen *result = ir_const(ira, &instruction->base.base, dest_slice_type);
24548 result->value->data.x_struct.fields = alloc_const_vals_ptrs(2);25553 result->value->data.x_struct.fields = alloc_const_vals_ptrs(2);
2454925554
24550 ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index];25555 ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index];
...@@ -24564,13 +25569,13 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct...@@ -24564,13 +25569,13 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct
24564 return result;25569 return result;
24565 }25570 }
2456625571
24567 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,25572 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
24568 dest_slice_type, nullptr, true, false, true);25573 dest_slice_type, nullptr, true, true);
24569 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {25574 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
24570 return result_loc;25575 return result_loc;
24571 }25576 }
2457225577
24573 return ir_build_resize_slice(ira, &instruction->base, target, dest_slice_type, result_loc);25578 return ir_build_resize_slice(ira, &instruction->base.base, target, dest_slice_type, result_loc);
24574}25579}
2457525580
24576static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align) {25581static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align) {
...@@ -24587,26 +25592,26 @@ static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_ali...@@ -24587,26 +25592,26 @@ static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_ali
24587 return ErrorNone;25592 return ErrorNone;
24588}25593}
2458925594
24590static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) {25595static IrInstGen *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstSrcIntToFloat *instruction) {
24591 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);25596 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
24592 if (type_is_invalid(dest_type))25597 if (type_is_invalid(dest_type))
24593 return ira->codegen->invalid_instruction;25598 return ira->codegen->invalid_inst_gen;
2459425599
24595 IrInstruction *target = instruction->target->child;25600 IrInstGen *target = instruction->target->child;
24596 if (type_is_invalid(target->value->type))25601 if (type_is_invalid(target->value->type))
24597 return ira->codegen->invalid_instruction;25602 return ira->codegen->invalid_inst_gen;
2459825603
24599 if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) {25604 if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) {
24600 ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'",25605 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected int type, found '%s'",
24601 buf_ptr(&target->value->type->name)));25606 buf_ptr(&target->value->type->name)));
24602 return ira->codegen->invalid_instruction;25607 return ira->codegen->invalid_inst_gen;
24603 }25608 }
2460425609
24605 return ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpIntToFloat);25610 return ir_resolve_cast(ira, &instruction->base.base, target, dest_type, CastOpIntToFloat);
24606}25611}
2460725612
24608static IrInstruction *ir_analyze_float_to_int(IrAnalyze *ira, IrInstruction *source_instr,25613static IrInstGen *ir_analyze_float_to_int(IrAnalyze *ira, IrInst* source_instr,
24609 ZigType *dest_type, IrInstruction *operand, AstNode *operand_source_node)25614 ZigType *dest_type, IrInstGen *operand, AstNode *operand_source_node)
24610{25615{
24611 if (operand->value->type->id == ZigTypeIdComptimeInt) {25616 if (operand->value->type->id == ZigTypeIdComptimeInt) {
24612 return ir_implicit_cast(ira, operand, dest_type);25617 return ir_implicit_cast(ira, operand, dest_type);
...@@ -24615,106 +25620,107 @@ static IrInstruction *ir_analyze_float_to_int(IrAnalyze *ira, IrInstruction *sou...@@ -24615,106 +25620,107 @@ static IrInstruction *ir_analyze_float_to_int(IrAnalyze *ira, IrInstruction *sou
24615 if (operand->value->type->id != ZigTypeIdFloat && operand->value->type->id != ZigTypeIdComptimeFloat) {25620 if (operand->value->type->id != ZigTypeIdFloat && operand->value->type->id != ZigTypeIdComptimeFloat) {
24616 ir_add_error_node(ira, operand_source_node, buf_sprintf("expected float type, found '%s'",25621 ir_add_error_node(ira, operand_source_node, buf_sprintf("expected float type, found '%s'",
24617 buf_ptr(&operand->value->type->name)));25622 buf_ptr(&operand->value->type->name)));
24618 return ira->codegen->invalid_instruction;25623 return ira->codegen->invalid_inst_gen;
24619 }25624 }
2462025625
24621 return ir_resolve_cast(ira, source_instr, operand, dest_type, CastOpFloatToInt);25626 return ir_resolve_cast(ira, source_instr, operand, dest_type, CastOpFloatToInt);
24622}25627}
2462325628
24624static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) {25629static IrInstGen *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstSrcFloatToInt *instruction) {
24625 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);25630 ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->child);
24626 if (type_is_invalid(dest_type))25631 if (type_is_invalid(dest_type))
24627 return ira->codegen->invalid_instruction;25632 return ira->codegen->invalid_inst_gen;
2462825633
24629 IrInstruction *operand = instruction->target->child;25634 IrInstGen *operand = instruction->target->child;
24630 if (type_is_invalid(operand->value->type))25635 if (type_is_invalid(operand->value->type))
24631 return ira->codegen->invalid_instruction;25636 return ira->codegen->invalid_inst_gen;
2463225637
24633 return ir_analyze_float_to_int(ira, &instruction->base, dest_type, operand, instruction->target->source_node);25638 return ir_analyze_float_to_int(ira, &instruction->base.base, dest_type, operand,
25639 instruction->target->base.source_node);
24634}25640}
2463525641
24636static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) {25642static IrInstGen *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstSrcErrToInt *instruction) {
24637 IrInstruction *target = instruction->target->child;25643 IrInstGen *target = instruction->target->child;
24638 if (type_is_invalid(target->value->type))25644 if (type_is_invalid(target->value->type))
24639 return ira->codegen->invalid_instruction;25645 return ira->codegen->invalid_inst_gen;
2464025646
24641 IrInstruction *casted_target;25647 IrInstGen *casted_target;
24642 if (target->value->type->id == ZigTypeIdErrorSet) {25648 if (target->value->type->id == ZigTypeIdErrorSet) {
24643 casted_target = target;25649 casted_target = target;
24644 } else {25650 } else {
24645 casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set);25651 casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set);
24646 if (type_is_invalid(casted_target->value->type))25652 if (type_is_invalid(casted_target->value->type))
24647 return ira->codegen->invalid_instruction;25653 return ira->codegen->invalid_inst_gen;
24648 }25654 }
2464925655
24650 return ir_analyze_err_to_int(ira, &instruction->base, casted_target, ira->codegen->err_tag_type);25656 return ir_analyze_err_to_int(ira, &instruction->base.base, casted_target, ira->codegen->err_tag_type);
24651}25657}
2465225658
24653static IrInstruction *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) {25659static IrInstGen *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstSrcIntToErr *instruction) {
24654 IrInstruction *target = instruction->target->child;25660 IrInstGen *target = instruction->target->child;
24655 if (type_is_invalid(target->value->type))25661 if (type_is_invalid(target->value->type))
24656 return ira->codegen->invalid_instruction;25662 return ira->codegen->invalid_inst_gen;
2465725663
24658 IrInstruction *casted_target = ir_implicit_cast(ira, target, ira->codegen->err_tag_type);25664 IrInstGen *casted_target = ir_implicit_cast(ira, target, ira->codegen->err_tag_type);
24659 if (type_is_invalid(casted_target->value->type))25665 if (type_is_invalid(casted_target->value->type))
24660 return ira->codegen->invalid_instruction;25666 return ira->codegen->invalid_inst_gen;
2466125667
24662 return ir_analyze_int_to_err(ira, &instruction->base, casted_target, ira->codegen->builtin_types.entry_global_error_set);25668 return ir_analyze_int_to_err(ira, &instruction->base.base, casted_target, ira->codegen->builtin_types.entry_global_error_set);
24663}25669}
2466425670
24665static IrInstruction *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) {25671static IrInstGen *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstSrcBoolToInt *instruction) {
24666 IrInstruction *target = instruction->target->child;25672 IrInstGen *target = instruction->target->child;
24667 if (type_is_invalid(target->value->type))25673 if (type_is_invalid(target->value->type))
24668 return ira->codegen->invalid_instruction;25674 return ira->codegen->invalid_inst_gen;
2466925675
24670 if (target->value->type->id != ZigTypeIdBool) {25676 if (target->value->type->id != ZigTypeIdBool) {
24671 ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'",25677 ir_add_error(ira, &instruction->target->base, buf_sprintf("expected bool, found '%s'",
24672 buf_ptr(&target->value->type->name)));25678 buf_ptr(&target->value->type->name)));
24673 return ira->codegen->invalid_instruction;25679 return ira->codegen->invalid_inst_gen;
24674 }25680 }
2467525681
24676 if (instr_is_comptime(target)) {25682 if (instr_is_comptime(target)) {
24677 bool is_true;25683 bool is_true;
24678 if (!ir_resolve_bool(ira, target, &is_true))25684 if (!ir_resolve_bool(ira, target, &is_true))
24679 return ira->codegen->invalid_instruction;25685 return ira->codegen->invalid_inst_gen;
2468025686
24681 return ir_const_unsigned(ira, &instruction->base, is_true ? 1 : 0);25687 return ir_const_unsigned(ira, &instruction->base.base, is_true ? 1 : 0);
24682 }25688 }
2468325689
24684 ZigType *u1_type = get_int_type(ira->codegen, false, 1);25690 ZigType *u1_type = get_int_type(ira->codegen, false, 1);
24685 return ir_resolve_cast(ira, &instruction->base, target, u1_type, CastOpBoolToInt);25691 return ir_resolve_cast(ira, &instruction->base.base, target, u1_type, CastOpBoolToInt);
24686}25692}
2468725693
24688static IrInstruction *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) {25694static IrInstGen *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstSrcIntType *instruction) {
24689 IrInstruction *is_signed_value = instruction->is_signed->child;25695 IrInstGen *is_signed_value = instruction->is_signed->child;
24690 bool is_signed;25696 bool is_signed;
24691 if (!ir_resolve_bool(ira, is_signed_value, &is_signed))25697 if (!ir_resolve_bool(ira, is_signed_value, &is_signed))
24692 return ira->codegen->invalid_instruction;25698 return ira->codegen->invalid_inst_gen;
2469325699
24694 IrInstruction *bit_count_value = instruction->bit_count->child;25700 IrInstGen *bit_count_value = instruction->bit_count->child;
24695 uint64_t bit_count;25701 uint64_t bit_count;
24696 if (!ir_resolve_unsigned(ira, bit_count_value, ira->codegen->builtin_types.entry_u16, &bit_count))25702 if (!ir_resolve_unsigned(ira, bit_count_value, ira->codegen->builtin_types.entry_u16, &bit_count))
24697 return ira->codegen->invalid_instruction;25703 return ira->codegen->invalid_inst_gen;
2469825704
24699 return ir_const_type(ira, &instruction->base, get_int_type(ira->codegen, is_signed, (uint32_t)bit_count));25705 return ir_const_type(ira, &instruction->base.base, get_int_type(ira->codegen, is_signed, (uint32_t)bit_count));
24700}25706}
2470125707
24702static IrInstruction *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstructionVectorType *instruction) {25708static IrInstGen *ir_analyze_instruction_vector_type(IrAnalyze *ira, IrInstSrcVectorType *instruction) {
24703 uint64_t len;25709 uint64_t len;
24704 if (!ir_resolve_unsigned(ira, instruction->len->child, ira->codegen->builtin_types.entry_u32, &len))25710 if (!ir_resolve_unsigned(ira, instruction->len->child, ira->codegen->builtin_types.entry_u32, &len))
24705 return ira->codegen->invalid_instruction;25711 return ira->codegen->invalid_inst_gen;
2470625712
24707 ZigType *elem_type = ir_resolve_vector_elem_type(ira, instruction->elem_type->child);25713 ZigType *elem_type = ir_resolve_vector_elem_type(ira, instruction->elem_type->child);
24708 if (type_is_invalid(elem_type))25714 if (type_is_invalid(elem_type))
24709 return ira->codegen->invalid_instruction;25715 return ira->codegen->invalid_inst_gen;
2471025716
24711 ZigType *vector_type = get_vector_type(ira->codegen, len, elem_type);25717 ZigType *vector_type = get_vector_type(ira->codegen, len, elem_type);
2471225718
24713 return ir_const_type(ira, &instruction->base, vector_type);25719 return ir_const_type(ira, &instruction->base.base, vector_type);
24714}25720}
2471525721
24716static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *source_instr,25722static IrInstGen *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInst* source_instr,
24717 ZigType *scalar_type, IrInstruction *a, IrInstruction *b, IrInstruction *mask)25723 ZigType *scalar_type, IrInstGen *a, IrInstGen *b, IrInstGen *mask)
24718{25724{
24719 ir_assert(source_instr && scalar_type && a && b && mask, source_instr);25725 ir_assert(source_instr && scalar_type && a && b && mask, source_instr);
24720 ir_assert(is_valid_vector_elem_type(scalar_type), source_instr);25726 ir_assert(is_valid_vector_elem_type(scalar_type), source_instr);
...@@ -24725,15 +25731,15 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -24725,15 +25731,15 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
24725 } else if (mask->value->type->id == ZigTypeIdArray) {25731 } else if (mask->value->type->id == ZigTypeIdArray) {
24726 len_mask = mask->value->type->data.array.len;25732 len_mask = mask->value->type->data.array.len;
24727 } else {25733 } else {
24728 ir_add_error(ira, mask,25734 ir_add_error(ira, &mask->base,
24729 buf_sprintf("expected vector or array, found '%s'",25735 buf_sprintf("expected vector or array, found '%s'",
24730 buf_ptr(&mask->value->type->name)));25736 buf_ptr(&mask->value->type->name)));
24731 return ira->codegen->invalid_instruction;25737 return ira->codegen->invalid_inst_gen;
24732 }25738 }
24733 mask = ir_implicit_cast(ira, mask, get_vector_type(ira->codegen, len_mask,25739 mask = ir_implicit_cast(ira, mask, get_vector_type(ira->codegen, len_mask,
24734 ira->codegen->builtin_types.entry_i32));25740 ira->codegen->builtin_types.entry_i32));
24735 if (type_is_invalid(mask->value->type))25741 if (type_is_invalid(mask->value->type))
24736 return ira->codegen->invalid_instruction;25742 return ira->codegen->invalid_inst_gen;
2473725743
24738 uint32_t len_a;25744 uint32_t len_a;
24739 if (a->value->type->id == ZigTypeIdVector) {25745 if (a->value->type->id == ZigTypeIdVector) {
...@@ -24743,11 +25749,11 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -24743,11 +25749,11 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
24743 } else if (a->value->type->id == ZigTypeIdUndefined) {25749 } else if (a->value->type->id == ZigTypeIdUndefined) {
24744 len_a = UINT32_MAX;25750 len_a = UINT32_MAX;
24745 } else {25751 } else {
24746 ir_add_error(ira, a,25752 ir_add_error(ira, &a->base,
24747 buf_sprintf("expected vector or array with element type '%s', found '%s'",25753 buf_sprintf("expected vector or array with element type '%s', found '%s'",
24748 buf_ptr(&scalar_type->name),25754 buf_ptr(&scalar_type->name),
24749 buf_ptr(&a->value->type->name)));25755 buf_ptr(&a->value->type->name)));
24750 return ira->codegen->invalid_instruction;25756 return ira->codegen->invalid_inst_gen;
24751 }25757 }
2475225758
24753 uint32_t len_b;25759 uint32_t len_b;
...@@ -24758,38 +25764,38 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -24758,38 +25764,38 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
24758 } else if (b->value->type->id == ZigTypeIdUndefined) {25764 } else if (b->value->type->id == ZigTypeIdUndefined) {
24759 len_b = UINT32_MAX;25765 len_b = UINT32_MAX;
24760 } else {25766 } else {
24761 ir_add_error(ira, b,25767 ir_add_error(ira, &b->base,
24762 buf_sprintf("expected vector or array with element type '%s', found '%s'",25768 buf_sprintf("expected vector or array with element type '%s', found '%s'",
24763 buf_ptr(&scalar_type->name),25769 buf_ptr(&scalar_type->name),
24764 buf_ptr(&b->value->type->name)));25770 buf_ptr(&b->value->type->name)));
24765 return ira->codegen->invalid_instruction;25771 return ira->codegen->invalid_inst_gen;
24766 }25772 }
2476725773
24768 if (len_a == UINT32_MAX && len_b == UINT32_MAX) {25774 if (len_a == UINT32_MAX && len_b == UINT32_MAX) {
24769 return ir_const_undef(ira, a, get_vector_type(ira->codegen, len_mask, scalar_type));25775 return ir_const_undef(ira, &a->base, get_vector_type(ira->codegen, len_mask, scalar_type));
24770 }25776 }
2477125777
24772 if (len_a == UINT32_MAX) {25778 if (len_a == UINT32_MAX) {
24773 len_a = len_b;25779 len_a = len_b;
24774 a = ir_const_undef(ira, a, get_vector_type(ira->codegen, len_a, scalar_type));25780 a = ir_const_undef(ira, &a->base, get_vector_type(ira->codegen, len_a, scalar_type));
24775 } else {25781 } else {
24776 a = ir_implicit_cast(ira, a, get_vector_type(ira->codegen, len_a, scalar_type));25782 a = ir_implicit_cast(ira, a, get_vector_type(ira->codegen, len_a, scalar_type));
24777 if (type_is_invalid(a->value->type))25783 if (type_is_invalid(a->value->type))
24778 return ira->codegen->invalid_instruction;25784 return ira->codegen->invalid_inst_gen;
24779 }25785 }
2478025786
24781 if (len_b == UINT32_MAX) {25787 if (len_b == UINT32_MAX) {
24782 len_b = len_a;25788 len_b = len_a;
24783 b = ir_const_undef(ira, b, get_vector_type(ira->codegen, len_b, scalar_type));25789 b = ir_const_undef(ira, &b->base, get_vector_type(ira->codegen, len_b, scalar_type));
24784 } else {25790 } else {
24785 b = ir_implicit_cast(ira, b, get_vector_type(ira->codegen, len_b, scalar_type));25791 b = ir_implicit_cast(ira, b, get_vector_type(ira->codegen, len_b, scalar_type));
24786 if (type_is_invalid(b->value->type))25792 if (type_is_invalid(b->value->type))
24787 return ira->codegen->invalid_instruction;25793 return ira->codegen->invalid_inst_gen;
24788 }25794 }
2478925795
24790 ZigValue *mask_val = ir_resolve_const(ira, mask, UndefOk);25796 ZigValue *mask_val = ir_resolve_const(ira, mask, UndefOk);
24791 if (mask_val == nullptr)25797 if (mask_val == nullptr)
24792 return ira->codegen->invalid_instruction;25798 return ira->codegen->invalid_inst_gen;
2479325799
24794 expand_undef_array(ira->codegen, mask_val);25800 expand_undef_array(ira->codegen, mask_val);
2479525801
...@@ -24799,7 +25805,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -24799,7 +25805,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
24799 continue;25805 continue;
24800 int32_t v_i32 = bigint_as_signed(&mask_elem_val->data.x_bigint);25806 int32_t v_i32 = bigint_as_signed(&mask_elem_val->data.x_bigint);
24801 uint32_t v;25807 uint32_t v;
24802 IrInstruction *chosen_operand;25808 IrInstGen *chosen_operand;
24803 if (v_i32 >= 0) {25809 if (v_i32 >= 0) {
24804 v = (uint32_t)v_i32;25810 v = (uint32_t)v_i32;
24805 chosen_operand = a;25811 chosen_operand = a;
...@@ -24808,16 +25814,16 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -24808,16 +25814,16 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
24808 chosen_operand = b;25814 chosen_operand = b;
24809 }25815 }
24810 if (v >= chosen_operand->value->type->data.vector.len) {25816 if (v >= chosen_operand->value->type->data.vector.len) {
24811 ErrorMsg *msg = ir_add_error(ira, mask,25817 ErrorMsg *msg = ir_add_error(ira, &mask->base,
24812 buf_sprintf("mask index '%u' has out-of-bounds selection", i));25818 buf_sprintf("mask index '%u' has out-of-bounds selection", i));
24813 add_error_note(ira->codegen, msg, chosen_operand->source_node,25819 add_error_note(ira->codegen, msg, chosen_operand->base.source_node,
24814 buf_sprintf("selected index '%u' out of bounds of %s", v,25820 buf_sprintf("selected index '%u' out of bounds of %s", v,
24815 buf_ptr(&chosen_operand->value->type->name)));25821 buf_ptr(&chosen_operand->value->type->name)));
24816 if (chosen_operand == a && v < len_a + len_b) {25822 if (chosen_operand == a && v < len_a + len_b) {
24817 add_error_note(ira->codegen, msg, b->source_node,25823 add_error_note(ira->codegen, msg, b->base.source_node,
24818 buf_create_from_str("selections from the second vector are specified with negative numbers"));25824 buf_create_from_str("selections from the second vector are specified with negative numbers"));
24819 }25825 }
24820 return ira->codegen->invalid_instruction;25826 return ira->codegen->invalid_inst_gen;
24821 }25827 }
24822 }25828 }
2482325829
...@@ -24825,16 +25831,16 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -24825,16 +25831,16 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
24825 if (instr_is_comptime(a) && instr_is_comptime(b)) {25831 if (instr_is_comptime(a) && instr_is_comptime(b)) {
24826 ZigValue *a_val = ir_resolve_const(ira, a, UndefOk);25832 ZigValue *a_val = ir_resolve_const(ira, a, UndefOk);
24827 if (a_val == nullptr)25833 if (a_val == nullptr)
24828 return ira->codegen->invalid_instruction;25834 return ira->codegen->invalid_inst_gen;
2482925835
24830 ZigValue *b_val = ir_resolve_const(ira, b, UndefOk);25836 ZigValue *b_val = ir_resolve_const(ira, b, UndefOk);
24831 if (b_val == nullptr)25837 if (b_val == nullptr)
24832 return ira->codegen->invalid_instruction;25838 return ira->codegen->invalid_inst_gen;
2483325839
24834 expand_undef_array(ira->codegen, a_val);25840 expand_undef_array(ira->codegen, a_val);
24835 expand_undef_array(ira->codegen, b_val);25841 expand_undef_array(ira->codegen, b_val);
2483625842
24837 IrInstruction *result = ir_const(ira, source_instr, result_type);25843 IrInstGen *result = ir_const(ira, source_instr, result_type);
24838 result->value->data.x_array.data.s_none.elements = create_const_vals(len_mask);25844 result->value->data.x_array.data.s_none.elements = create_const_vals(len_mask);
24839 for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) {25845 for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) {
24840 ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i];25846 ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i];
...@@ -24866,7 +25872,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -24866,7 +25872,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
24866 uint32_t len_min = min(len_a, len_b);25872 uint32_t len_min = min(len_a, len_b);
24867 uint32_t len_max = max(len_a, len_b);25873 uint32_t len_max = max(len_a, len_b);
2486825874
24869 IrInstruction *expand_mask = ir_const(ira, mask,25875 IrInstGen *expand_mask = ir_const(ira, &mask->base,
24870 get_vector_type(ira->codegen, len_max, ira->codegen->builtin_types.entry_i32));25876 get_vector_type(ira->codegen, len_max, ira->codegen->builtin_types.entry_i32));
24871 expand_mask->value->data.x_array.data.s_none.elements = create_const_vals(len_max);25877 expand_mask->value->data.x_array.data.s_none.elements = create_const_vals(len_max);
24872 uint32_t i = 0;25878 uint32_t i = 0;
...@@ -24875,7 +25881,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -24875,7 +25881,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
24875 for (; i < len_max; i += 1)25881 for (; i < len_max; i += 1)
24876 bigint_init_signed(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, -1);25882 bigint_init_signed(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, -1);
2487725883
24878 IrInstruction *undef = ir_const_undef(ira, source_instr,25884 IrInstGen *undef = ir_const_undef(ira, source_instr,
24879 get_vector_type(ira->codegen, len_min, scalar_type));25885 get_vector_type(ira->codegen, len_min, scalar_type));
2488025886
24881 if (len_b < len_a) {25887 if (len_b < len_a) {
...@@ -24885,62 +25891,59 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s...@@ -24885,62 +25891,59 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s
24885 }25891 }
24886 }25892 }
2488725893
24888 IrInstruction *result = ir_build_shuffle_vector(&ira->new_irb,25894 return ir_build_shuffle_vector_gen(ira, source_instr->scope, source_instr->source_node,
24889 source_instr->scope, source_instr->source_node,25895 result_type, a, b, mask);
24890 nullptr, a, b, mask);
24891 result->value->type = result_type;
24892 return result;
24893}25896}
2489425897
24895static IrInstruction *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrInstructionShuffleVector *instruction) {25898static IrInstGen *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrInstSrcShuffleVector *instruction) {
24896 ZigType *scalar_type = ir_resolve_vector_elem_type(ira, instruction->scalar_type);25899 ZigType *scalar_type = ir_resolve_vector_elem_type(ira, instruction->scalar_type->child);
24897 if (type_is_invalid(scalar_type))25900 if (type_is_invalid(scalar_type))
24898 return ira->codegen->invalid_instruction;25901 return ira->codegen->invalid_inst_gen;
2489925902
24900 IrInstruction *a = instruction->a->child;25903 IrInstGen *a = instruction->a->child;
24901 if (type_is_invalid(a->value->type))25904 if (type_is_invalid(a->value->type))
24902 return ira->codegen->invalid_instruction;25905 return ira->codegen->invalid_inst_gen;
2490325906
24904 IrInstruction *b = instruction->b->child;25907 IrInstGen *b = instruction->b->child;
24905 if (type_is_invalid(b->value->type))25908 if (type_is_invalid(b->value->type))
24906 return ira->codegen->invalid_instruction;25909 return ira->codegen->invalid_inst_gen;
2490725910
24908 IrInstruction *mask = instruction->mask->child;25911 IrInstGen *mask = instruction->mask->child;
24909 if (type_is_invalid(mask->value->type))25912 if (type_is_invalid(mask->value->type))
24910 return ira->codegen->invalid_instruction;25913 return ira->codegen->invalid_inst_gen;
2491125914
24912 return ir_analyze_shuffle_vector(ira, &instruction->base, scalar_type, a, b, mask);25915 return ir_analyze_shuffle_vector(ira, &instruction->base.base, scalar_type, a, b, mask);
24913}25916}
2491425917
24915static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstructionSplatSrc *instruction) {25918static IrInstGen *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstSrcSplat *instruction) {
24916 Error err;25919 Error err;
2491725920
24918 IrInstruction *len = instruction->len->child;25921 IrInstGen *len = instruction->len->child;
24919 if (type_is_invalid(len->value->type))25922 if (type_is_invalid(len->value->type))
24920 return ira->codegen->invalid_instruction;25923 return ira->codegen->invalid_inst_gen;
2492125924
24922 IrInstruction *scalar = instruction->scalar->child;25925 IrInstGen *scalar = instruction->scalar->child;
24923 if (type_is_invalid(scalar->value->type))25926 if (type_is_invalid(scalar->value->type))
24924 return ira->codegen->invalid_instruction;25927 return ira->codegen->invalid_inst_gen;
2492525928
24926 uint64_t len_u64;25929 uint64_t len_u64;
24927 if (!ir_resolve_unsigned(ira, len, ira->codegen->builtin_types.entry_u32, &len_u64))25930 if (!ir_resolve_unsigned(ira, len, ira->codegen->builtin_types.entry_u32, &len_u64))
24928 return ira->codegen->invalid_instruction;25931 return ira->codegen->invalid_inst_gen;
24929 uint32_t len_int = len_u64;25932 uint32_t len_int = len_u64;
2493025933
24931 if ((err = ir_validate_vector_elem_type(ira, scalar, scalar->value->type)))25934 if ((err = ir_validate_vector_elem_type(ira, scalar->base.source_node, scalar->value->type)))
24932 return ira->codegen->invalid_instruction;25935 return ira->codegen->invalid_inst_gen;
2493325936
24934 ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value->type);25937 ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value->type);
2493525938
24936 if (instr_is_comptime(scalar)) {25939 if (instr_is_comptime(scalar)) {
24937 ZigValue *scalar_val = ir_resolve_const(ira, scalar, UndefOk);25940 ZigValue *scalar_val = ir_resolve_const(ira, scalar, UndefOk);
24938 if (scalar_val == nullptr)25941 if (scalar_val == nullptr)
24939 return ira->codegen->invalid_instruction;25942 return ira->codegen->invalid_inst_gen;
24940 if (scalar_val->special == ConstValSpecialUndef)25943 if (scalar_val->special == ConstValSpecialUndef)
24941 return ir_const_undef(ira, &instruction->base, return_type);25944 return ir_const_undef(ira, &instruction->base.base, return_type);
2494225945
24943 IrInstruction *result = ir_const(ira, &instruction->base, return_type);25946 IrInstGen *result = ir_const(ira, &instruction->base.base, return_type);
24944 result->value->data.x_array.data.s_none.elements = create_const_vals(len_int);25947 result->value->data.x_array.data.s_none.elements = create_const_vals(len_int);
24945 for (uint32_t i = 0; i < len_int; i += 1) {25948 for (uint32_t i = 0; i < len_int; i += 1) {
24946 copy_const_val(&result->value->data.x_array.data.s_none.elements[i], scalar_val);25949 copy_const_val(&result->value->data.x_array.data.s_none.elements[i], scalar_val);
...@@ -24948,48 +25951,45 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction...@@ -24948,48 +25951,45 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction
24948 return result;25951 return result;
24949 }25952 }
2495025953
24951 return ir_build_splat_gen(ira, &instruction->base, return_type, scalar);25954 return ir_build_splat_gen(ira, &instruction->base.base, return_type, scalar);
24952}25955}
2495325956
24954static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) {25957static IrInstGen *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstSrcBoolNot *instruction) {
24955 IrInstruction *value = instruction->value->child;25958 IrInstGen *value = instruction->value->child;
24956 if (type_is_invalid(value->value->type))25959 if (type_is_invalid(value->value->type))
24957 return ira->codegen->invalid_instruction;25960 return ira->codegen->invalid_inst_gen;
2495825961
24959 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;25962 ZigType *bool_type = ira->codegen->builtin_types.entry_bool;
2496025963
24961 IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type);25964 IrInstGen *casted_value = ir_implicit_cast(ira, value, bool_type);
24962 if (type_is_invalid(casted_value->value->type))25965 if (type_is_invalid(casted_value->value->type))
24963 return ira->codegen->invalid_instruction;25966 return ira->codegen->invalid_inst_gen;
2496425967
24965 if (instr_is_comptime(casted_value)) {25968 if (instr_is_comptime(casted_value)) {
24966 ZigValue *value = ir_resolve_const(ira, casted_value, UndefBad);25969 ZigValue *value = ir_resolve_const(ira, casted_value, UndefBad);
24967 if (value == nullptr)25970 if (value == nullptr)
24968 return ira->codegen->invalid_instruction;25971 return ira->codegen->invalid_inst_gen;
2496925972
24970 return ir_const_bool(ira, &instruction->base, !value->data.x_bool);25973 return ir_const_bool(ira, &instruction->base.base, !value->data.x_bool);
24971 }25974 }
2497225975
24973 IrInstruction *result = ir_build_bool_not(&ira->new_irb, instruction->base.scope,25976 return ir_build_bool_not_gen(ira, &instruction->base.base, casted_value);
24974 instruction->base.source_node, casted_value);
24975 result->value->type = bool_type;
24976 return result;
24977}25977}
2497825978
24979static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) {25979static IrInstGen *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstSrcMemset *instruction) {
24980 Error err;25980 Error err;
2498125981
24982 IrInstruction *dest_ptr = instruction->dest_ptr->child;25982 IrInstGen *dest_ptr = instruction->dest_ptr->child;
24983 if (type_is_invalid(dest_ptr->value->type))25983 if (type_is_invalid(dest_ptr->value->type))
24984 return ira->codegen->invalid_instruction;25984 return ira->codegen->invalid_inst_gen;
2498525985
24986 IrInstruction *byte_value = instruction->byte->child;25986 IrInstGen *byte_value = instruction->byte->child;
24987 if (type_is_invalid(byte_value->value->type))25987 if (type_is_invalid(byte_value->value->type))
24988 return ira->codegen->invalid_instruction;25988 return ira->codegen->invalid_inst_gen;
2498925989
24990 IrInstruction *count_value = instruction->count->child;25990 IrInstGen *count_value = instruction->count->child;
24991 if (type_is_invalid(count_value->value->type))25991 if (type_is_invalid(count_value->value->type))
24992 return ira->codegen->invalid_instruction;25992 return ira->codegen->invalid_inst_gen;
2499325993
24994 ZigType *dest_uncasted_type = dest_ptr->value->type;25994 ZigType *dest_uncasted_type = dest_ptr->value->type;
24995 bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) &&25995 bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) &&
...@@ -25000,24 +26000,24 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio...@@ -25000,24 +26000,24 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
25000 uint32_t dest_align;26000 uint32_t dest_align;
25001 if (dest_uncasted_type->id == ZigTypeIdPointer) {26001 if (dest_uncasted_type->id == ZigTypeIdPointer) {
25002 if ((err = resolve_ptr_align(ira, dest_uncasted_type, &dest_align)))26002 if ((err = resolve_ptr_align(ira, dest_uncasted_type, &dest_align)))
25003 return ira->codegen->invalid_instruction;26003 return ira->codegen->invalid_inst_gen;
25004 } else {26004 } else {
25005 dest_align = get_abi_alignment(ira->codegen, u8);26005 dest_align = get_abi_alignment(ira->codegen, u8);
25006 }26006 }
25007 ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,26007 ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile,
25008 PtrLenUnknown, dest_align, 0, 0, false);26008 PtrLenUnknown, dest_align, 0, 0, false);
2500926009
25010 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr);26010 IrInstGen *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr);
25011 if (type_is_invalid(casted_dest_ptr->value->type))26011 if (type_is_invalid(casted_dest_ptr->value->type))
25012 return ira->codegen->invalid_instruction;26012 return ira->codegen->invalid_inst_gen;
2501326013
25014 IrInstruction *casted_byte = ir_implicit_cast(ira, byte_value, u8);26014 IrInstGen *casted_byte = ir_implicit_cast(ira, byte_value, u8);
25015 if (type_is_invalid(casted_byte->value->type))26015 if (type_is_invalid(casted_byte->value->type))
25016 return ira->codegen->invalid_instruction;26016 return ira->codegen->invalid_inst_gen;
2501726017
25018 IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize);26018 IrInstGen *casted_count = ir_implicit_cast(ira, count_value, usize);
25019 if (type_is_invalid(casted_count->value->type))26019 if (type_is_invalid(casted_count->value->type))
25020 return ira->codegen->invalid_instruction;26020 return ira->codegen->invalid_inst_gen;
2502126021
25022 // TODO test this at comptime with u8 and non-u8 types26022 // TODO test this at comptime with u8 and non-u8 types
25023 if (instr_is_comptime(casted_dest_ptr) &&26023 if (instr_is_comptime(casted_dest_ptr) &&
...@@ -25026,15 +26026,15 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio...@@ -25026,15 +26026,15 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
25026 {26026 {
25027 ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad);26027 ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad);
25028 if (dest_ptr_val == nullptr)26028 if (dest_ptr_val == nullptr)
25029 return ira->codegen->invalid_instruction;26029 return ira->codegen->invalid_inst_gen;
2503026030
25031 ZigValue *byte_val = ir_resolve_const(ira, casted_byte, UndefOk);26031 ZigValue *byte_val = ir_resolve_const(ira, casted_byte, UndefOk);
25032 if (byte_val == nullptr)26032 if (byte_val == nullptr)
25033 return ira->codegen->invalid_instruction;26033 return ira->codegen->invalid_inst_gen;
2503426034
25035 ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad);26035 ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad);
25036 if (count_val == nullptr)26036 if (count_val == nullptr)
25037 return ira->codegen->invalid_instruction;26037 return ira->codegen->invalid_inst_gen;
2503826038
25039 if (casted_dest_ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&26039 if (casted_dest_ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&
25040 casted_dest_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar)26040 casted_dest_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar)
...@@ -25079,38 +26079,35 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio...@@ -25079,38 +26079,35 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio
25079 size_t count = bigint_as_usize(&count_val->data.x_bigint);26079 size_t count = bigint_as_usize(&count_val->data.x_bigint);
25080 size_t end = start + count;26080 size_t end = start + count;
25081 if (end > bound_end) {26081 if (end > bound_end) {
25082 ir_add_error(ira, count_value, buf_sprintf("out of bounds pointer access"));26082 ir_add_error(ira, &count_value->base, buf_sprintf("out of bounds pointer access"));
25083 return ira->codegen->invalid_instruction;26083 return ira->codegen->invalid_inst_gen;
25084 }26084 }
2508526085
25086 for (size_t i = start; i < end; i += 1) {26086 for (size_t i = start; i < end; i += 1) {
25087 copy_const_val(&dest_elements[i], byte_val);26087 copy_const_val(&dest_elements[i], byte_val);
25088 }26088 }
2508926089
25090 return ir_const_void(ira, &instruction->base);26090 return ir_const_void(ira, &instruction->base.base);
25091 }26091 }
25092 }26092 }
2509326093
25094 IrInstruction *result = ir_build_memset(&ira->new_irb, instruction->base.scope, instruction->base.source_node,26094 return ir_build_memset_gen(ira, &instruction->base.base, casted_dest_ptr, casted_byte, casted_count);
25095 casted_dest_ptr, casted_byte, casted_count);
25096 result->value->type = ira->codegen->builtin_types.entry_void;
25097 return result;
25098}26095}
2509926096
25100static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) {26097static IrInstGen *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstSrcMemcpy *instruction) {
25101 Error err;26098 Error err;
2510226099
25103 IrInstruction *dest_ptr = instruction->dest_ptr->child;26100 IrInstGen *dest_ptr = instruction->dest_ptr->child;
25104 if (type_is_invalid(dest_ptr->value->type))26101 if (type_is_invalid(dest_ptr->value->type))
25105 return ira->codegen->invalid_instruction;26102 return ira->codegen->invalid_inst_gen;
2510626103
25107 IrInstruction *src_ptr = instruction->src_ptr->child;26104 IrInstGen *src_ptr = instruction->src_ptr->child;
25108 if (type_is_invalid(src_ptr->value->type))26105 if (type_is_invalid(src_ptr->value->type))
25109 return ira->codegen->invalid_instruction;26106 return ira->codegen->invalid_inst_gen;
2511026107
25111 IrInstruction *count_value = instruction->count->child;26108 IrInstGen *count_value = instruction->count->child;
25112 if (type_is_invalid(count_value->value->type))26109 if (type_is_invalid(count_value->value->type))
25113 return ira->codegen->invalid_instruction;26110 return ira->codegen->invalid_inst_gen;
2511426111
25115 ZigType *u8 = ira->codegen->builtin_types.entry_u8;26112 ZigType *u8 = ira->codegen->builtin_types.entry_u8;
25116 ZigType *dest_uncasted_type = dest_ptr->value->type;26113 ZigType *dest_uncasted_type = dest_ptr->value->type;
...@@ -25123,7 +26120,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -25123,7 +26120,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
25123 uint32_t dest_align;26120 uint32_t dest_align;
25124 if (dest_uncasted_type->id == ZigTypeIdPointer) {26121 if (dest_uncasted_type->id == ZigTypeIdPointer) {
25125 if ((err = resolve_ptr_align(ira, dest_uncasted_type, &dest_align)))26122 if ((err = resolve_ptr_align(ira, dest_uncasted_type, &dest_align)))
25126 return ira->codegen->invalid_instruction;26123 return ira->codegen->invalid_inst_gen;
25127 } else {26124 } else {
25128 dest_align = get_abi_alignment(ira->codegen, u8);26125 dest_align = get_abi_alignment(ira->codegen, u8);
25129 }26126 }
...@@ -25131,7 +26128,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -25131,7 +26128,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
25131 uint32_t src_align;26128 uint32_t src_align;
25132 if (src_uncasted_type->id == ZigTypeIdPointer) {26129 if (src_uncasted_type->id == ZigTypeIdPointer) {
25133 if ((err = resolve_ptr_align(ira, src_uncasted_type, &src_align)))26130 if ((err = resolve_ptr_align(ira, src_uncasted_type, &src_align)))
25134 return ira->codegen->invalid_instruction;26131 return ira->codegen->invalid_inst_gen;
25135 } else {26132 } else {
25136 src_align = get_abi_alignment(ira->codegen, u8);26133 src_align = get_abi_alignment(ira->codegen, u8);
25137 }26134 }
...@@ -25142,17 +26139,17 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -25142,17 +26139,17 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
25142 ZigType *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile,26139 ZigType *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile,
25143 PtrLenUnknown, src_align, 0, 0, false);26140 PtrLenUnknown, src_align, 0, 0, false);
2514426141
25145 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut);26142 IrInstGen *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut);
25146 if (type_is_invalid(casted_dest_ptr->value->type))26143 if (type_is_invalid(casted_dest_ptr->value->type))
25147 return ira->codegen->invalid_instruction;26144 return ira->codegen->invalid_inst_gen;
2514826145
25149 IrInstruction *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const);26146 IrInstGen *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const);
25150 if (type_is_invalid(casted_src_ptr->value->type))26147 if (type_is_invalid(casted_src_ptr->value->type))
25151 return ira->codegen->invalid_instruction;26148 return ira->codegen->invalid_inst_gen;
2515226149
25153 IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize);26150 IrInstGen *casted_count = ir_implicit_cast(ira, count_value, usize);
25154 if (type_is_invalid(casted_count->value->type))26151 if (type_is_invalid(casted_count->value->type))
25155 return ira->codegen->invalid_instruction;26152 return ira->codegen->invalid_inst_gen;
2515626153
25157 // TODO test this at comptime with u8 and non-u8 types26154 // TODO test this at comptime with u8 and non-u8 types
25158 // TODO test with dest ptr being a global runtime variable26155 // TODO test with dest ptr being a global runtime variable
...@@ -25162,15 +26159,15 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -25162,15 +26159,15 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
25162 {26159 {
25163 ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad);26160 ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad);
25164 if (dest_ptr_val == nullptr)26161 if (dest_ptr_val == nullptr)
25165 return ira->codegen->invalid_instruction;26162 return ira->codegen->invalid_inst_gen;
2516626163
25167 ZigValue *src_ptr_val = ir_resolve_const(ira, casted_src_ptr, UndefBad);26164 ZigValue *src_ptr_val = ir_resolve_const(ira, casted_src_ptr, UndefBad);
25168 if (src_ptr_val == nullptr)26165 if (src_ptr_val == nullptr)
25169 return ira->codegen->invalid_instruction;26166 return ira->codegen->invalid_inst_gen;
2517026167
25171 ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad);26168 ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad);
25172 if (count_val == nullptr)26169 if (count_val == nullptr)
25173 return ira->codegen->invalid_instruction;26170 return ira->codegen->invalid_inst_gen;
2517426171
25175 if (dest_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {26172 if (dest_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) {
25176 size_t count = bigint_as_usize(&count_val->data.x_bigint);26173 size_t count = bigint_as_usize(&count_val->data.x_bigint);
...@@ -25213,8 +26210,8 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -25213,8 +26210,8 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
25213 }26210 }
2521426211
25215 if (dest_start + count > dest_end) {26212 if (dest_start + count > dest_end) {
25216 ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds pointer access"));26213 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds pointer access"));
25217 return ira->codegen->invalid_instruction;26214 return ira->codegen->invalid_inst_gen;
25218 }26215 }
2521926216
25220 ZigValue *src_elements;26217 ZigValue *src_elements;
...@@ -25256,8 +26253,8 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -25256,8 +26253,8 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
25256 }26253 }
2525726254
25258 if (src_start + count > src_end) {26255 if (src_start + count > src_end) {
25259 ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds pointer access"));26256 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds pointer access"));
25260 return ira->codegen->invalid_instruction;26257 return ira->codegen->invalid_inst_gen;
25261 }26258 }
2526226259
25263 // TODO check for noalias violations - this should be generalized to work for any function26260 // TODO check for noalias violations - this should be generalized to work for any function
...@@ -25266,42 +26263,39 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio...@@ -25266,42 +26263,39 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio
25266 copy_const_val(&dest_elements[dest_start + i], &src_elements[src_start + i]);26263 copy_const_val(&dest_elements[dest_start + i], &src_elements[src_start + i]);
25267 }26264 }
2526826265
25269 return ir_const_void(ira, &instruction->base);26266 return ir_const_void(ira, &instruction->base.base);
25270 }26267 }
25271 }26268 }
2527226269
25273 IrInstruction *result = ir_build_memcpy(&ira->new_irb, instruction->base.scope, instruction->base.source_node,26270 return ir_build_memcpy_gen(ira, &instruction->base.base, casted_dest_ptr, casted_src_ptr, casted_count);
25274 casted_dest_ptr, casted_src_ptr, casted_count);
25275 result->value->type = ira->codegen->builtin_types.entry_void;
25276 return result;
25277}26271}
2527826272
25279static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSliceSrc *instruction) {26273static IrInstGen *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstSrcSlice *instruction) {
25280 IrInstruction *ptr_ptr = instruction->ptr->child;26274 IrInstGen *ptr_ptr = instruction->ptr->child;
25281 if (type_is_invalid(ptr_ptr->value->type))26275 if (type_is_invalid(ptr_ptr->value->type))
25282 return ira->codegen->invalid_instruction;26276 return ira->codegen->invalid_inst_gen;
2528326277
25284 ZigType *ptr_ptr_type = ptr_ptr->value->type;26278 ZigType *ptr_ptr_type = ptr_ptr->value->type;
25285 assert(ptr_ptr_type->id == ZigTypeIdPointer);26279 assert(ptr_ptr_type->id == ZigTypeIdPointer);
25286 ZigType *array_type = ptr_ptr_type->data.pointer.child_type;26280 ZigType *array_type = ptr_ptr_type->data.pointer.child_type;
2528726281
25288 IrInstruction *start = instruction->start->child;26282 IrInstGen *start = instruction->start->child;
25289 if (type_is_invalid(start->value->type))26283 if (type_is_invalid(start->value->type))
25290 return ira->codegen->invalid_instruction;26284 return ira->codegen->invalid_inst_gen;
2529126285
25292 ZigType *usize = ira->codegen->builtin_types.entry_usize;26286 ZigType *usize = ira->codegen->builtin_types.entry_usize;
25293 IrInstruction *casted_start = ir_implicit_cast(ira, start, usize);26287 IrInstGen *casted_start = ir_implicit_cast(ira, start, usize);
25294 if (type_is_invalid(casted_start->value->type))26288 if (type_is_invalid(casted_start->value->type))
25295 return ira->codegen->invalid_instruction;26289 return ira->codegen->invalid_inst_gen;
2529626290
25297 IrInstruction *end;26291 IrInstGen *end;
25298 if (instruction->end) {26292 if (instruction->end) {
25299 end = instruction->end->child;26293 end = instruction->end->child;
25300 if (type_is_invalid(end->value->type))26294 if (type_is_invalid(end->value->type))
25301 return ira->codegen->invalid_instruction;26295 return ira->codegen->invalid_inst_gen;
25302 end = ir_implicit_cast(ira, end, usize);26296 end = ir_implicit_cast(ira, end, usize);
25303 if (type_is_invalid(end->value->type))26297 if (type_is_invalid(end->value->type))
25304 return ira->codegen->invalid_instruction;26298 return ira->codegen->invalid_inst_gen;
25305 } else {26299 } else {
25306 end = nullptr;26300 end = nullptr;
25307 }26301 }
...@@ -25329,8 +26323,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -25329,8 +26323,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
25329 PtrLenUnknown,26323 PtrLenUnknown,
25330 array_type->data.pointer.explicit_alignment, 0, 0, false);26324 array_type->data.pointer.explicit_alignment, 0, 0, false);
25331 } else {26325 } else {
25332 ir_add_error(ira, &instruction->base, buf_sprintf("slice of single-item pointer"));26326 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of single-item pointer"));
25333 return ira->codegen->invalid_instruction;26327 return ira->codegen->invalid_inst_gen;
25334 }26328 }
25335 } else {26329 } else {
25336 elem_type = array_type->data.pointer.child_type;26330 elem_type = array_type->data.pointer.child_type;
...@@ -25340,8 +26334,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -25340,8 +26334,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
25340 ZigType *maybe_sentineled_slice_ptr_type = array_type;26334 ZigType *maybe_sentineled_slice_ptr_type = array_type;
25341 non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr);26335 non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr);
25342 if (!end) {26336 if (!end) {
25343 ir_add_error(ira, &instruction->base, buf_sprintf("slice of pointer must include end value"));26337 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of pointer must include end value"));
25344 return ira->codegen->invalid_instruction;26338 return ira->codegen->invalid_inst_gen;
25345 }26339 }
25346 }26340 }
25347 } else if (is_slice(array_type)) {26341 } else if (is_slice(array_type)) {
...@@ -25349,23 +26343,23 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -25349,23 +26343,23 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
25349 non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr);26343 non_sentinel_slice_ptr_type = adjust_ptr_sentinel(ira->codegen, maybe_sentineled_slice_ptr_type, nullptr);
25350 elem_type = non_sentinel_slice_ptr_type->data.pointer.child_type;26344 elem_type = non_sentinel_slice_ptr_type->data.pointer.child_type;
25351 } else {26345 } else {
25352 ir_add_error(ira, &instruction->base,26346 ir_add_error(ira, &instruction->base.base,
25353 buf_sprintf("slice of non-array type '%s'", buf_ptr(&array_type->name)));26347 buf_sprintf("slice of non-array type '%s'", buf_ptr(&array_type->name)));
25354 return ira->codegen->invalid_instruction;26348 return ira->codegen->invalid_inst_gen;
25355 }26349 }
2535626350
25357 ZigType *return_type;26351 ZigType *return_type;
25358 ZigValue *sentinel_val = nullptr;26352 ZigValue *sentinel_val = nullptr;
25359 if (instruction->sentinel) {26353 if (instruction->sentinel) {
25360 IrInstruction *uncasted_sentinel = instruction->sentinel->child;26354 IrInstGen *uncasted_sentinel = instruction->sentinel->child;
25361 if (type_is_invalid(uncasted_sentinel->value->type))26355 if (type_is_invalid(uncasted_sentinel->value->type))
25362 return ira->codegen->invalid_instruction;26356 return ira->codegen->invalid_inst_gen;
25363 IrInstruction *sentinel = ir_implicit_cast(ira, uncasted_sentinel, elem_type);26357 IrInstGen *sentinel = ir_implicit_cast(ira, uncasted_sentinel, elem_type);
25364 if (type_is_invalid(sentinel->value->type))26358 if (type_is_invalid(sentinel->value->type))
25365 return ira->codegen->invalid_instruction;26359 return ira->codegen->invalid_inst_gen;
25366 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);26360 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
25367 if (sentinel_val == nullptr)26361 if (sentinel_val == nullptr)
25368 return ira->codegen->invalid_instruction;26362 return ira->codegen->invalid_inst_gen;
25369 ZigType *slice_ptr_type = adjust_ptr_sentinel(ira->codegen, non_sentinel_slice_ptr_type, sentinel_val);26363 ZigType *slice_ptr_type = adjust_ptr_sentinel(ira->codegen, non_sentinel_slice_ptr_type, sentinel_val);
25370 return_type = get_slice_type(ira->codegen, slice_ptr_type);26364 return_type = get_slice_type(ira->codegen, slice_ptr_type);
25371 } else {26365 } else {
...@@ -25387,9 +26381,9 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -25387,9 +26381,9 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
25387 if (array_type->id == ZigTypeIdPointer) {26381 if (array_type->id == ZigTypeIdPointer) {
25388 ZigType *child_array_type = array_type->data.pointer.child_type;26382 ZigType *child_array_type = array_type->data.pointer.child_type;
25389 assert(child_array_type->id == ZigTypeIdArray);26383 assert(child_array_type->id == ZigTypeIdArray);
25390 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);26384 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);
25391 if (parent_ptr == nullptr)26385 if (parent_ptr == nullptr)
25392 return ira->codegen->invalid_instruction;26386 return ira->codegen->invalid_inst_gen;
2539326387
2539426388
25395 if (parent_ptr->special == ConstValSpecialUndef) {26389 if (parent_ptr->special == ConstValSpecialUndef) {
...@@ -25398,26 +26392,26 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -25398,26 +26392,26 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
25398 rel_end = SIZE_MAX;26392 rel_end = SIZE_MAX;
25399 ptr_is_undef = true;26393 ptr_is_undef = true;
25400 } else {26394 } else {
25401 array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.source_node);26395 array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.base.source_node);
25402 if (array_val == nullptr)26396 if (array_val == nullptr)
25403 return ira->codegen->invalid_instruction;26397 return ira->codegen->invalid_inst_gen;
2540426398
25405 rel_end = child_array_type->data.array.len;26399 rel_end = child_array_type->data.array.len;
25406 abs_offset = 0;26400 abs_offset = 0;
25407 }26401 }
25408 } else {26402 } else {
25409 array_val = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);26403 array_val = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);
25410 if (array_val == nullptr)26404 if (array_val == nullptr)
25411 return ira->codegen->invalid_instruction;26405 return ira->codegen->invalid_inst_gen;
25412 rel_end = array_type->data.array.len;26406 rel_end = array_type->data.array.len;
25413 parent_ptr = nullptr;26407 parent_ptr = nullptr;
25414 abs_offset = 0;26408 abs_offset = 0;
25415 }26409 }
25416 } else if (array_type->id == ZigTypeIdPointer) {26410 } else if (array_type->id == ZigTypeIdPointer) {
25417 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);26411 assert(array_type->data.pointer.ptr_len == PtrLenUnknown);
25418 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);26412 parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);
25419 if (parent_ptr == nullptr)26413 if (parent_ptr == nullptr)
25420 return ira->codegen->invalid_instruction;26414 return ira->codegen->invalid_inst_gen;
2542126415
25422 if (parent_ptr->special == ConstValSpecialUndef) {26416 if (parent_ptr->special == ConstValSpecialUndef) {
25423 array_val = nullptr;26417 array_val = nullptr;
...@@ -25463,19 +26457,19 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -25463,19 +26457,19 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
25463 zig_panic("TODO slice of null ptr");26457 zig_panic("TODO slice of null ptr");
25464 }26458 }
25465 } else if (is_slice(array_type)) {26459 } else if (is_slice(array_type)) {
25466 ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node);26460 ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.base.source_node);
25467 if (slice_ptr == nullptr)26461 if (slice_ptr == nullptr)
25468 return ira->codegen->invalid_instruction;26462 return ira->codegen->invalid_inst_gen;
2546926463
25470 if (slice_ptr->special == ConstValSpecialUndef) {26464 if (slice_ptr->special == ConstValSpecialUndef) {
25471 ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined"));26465 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of undefined"));
25472 return ira->codegen->invalid_instruction;26466 return ira->codegen->invalid_inst_gen;
25473 }26467 }
2547426468
25475 parent_ptr = slice_ptr->data.x_struct.fields[slice_ptr_index];26469 parent_ptr = slice_ptr->data.x_struct.fields[slice_ptr_index];
25476 if (parent_ptr->special == ConstValSpecialUndef) {26470 if (parent_ptr->special == ConstValSpecialUndef) {
25477 ir_add_error(ira, &instruction->base, buf_sprintf("slice of undefined"));26471 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice of undefined"));
25478 return ira->codegen->invalid_instruction;26472 return ira->codegen->invalid_inst_gen;
25479 }26473 }
2548026474
25481 ZigValue *len_val = slice_ptr->data.x_struct.fields[slice_len_index];26475 ZigValue *len_val = slice_ptr->data.x_struct.fields[slice_len_index];
...@@ -25518,37 +26512,37 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -25518,37 +26512,37 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
2551826512
25519 ZigValue *start_val = ir_resolve_const(ira, casted_start, UndefBad);26513 ZigValue *start_val = ir_resolve_const(ira, casted_start, UndefBad);
25520 if (!start_val)26514 if (!start_val)
25521 return ira->codegen->invalid_instruction;26515 return ira->codegen->invalid_inst_gen;
2552226516
25523 uint64_t start_scalar = bigint_as_u64(&start_val->data.x_bigint);26517 uint64_t start_scalar = bigint_as_u64(&start_val->data.x_bigint);
25524 if (!ptr_is_undef && start_scalar > rel_end) {26518 if (!ptr_is_undef && start_scalar > rel_end) {
25525 ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds slice"));26519 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice"));
25526 return ira->codegen->invalid_instruction;26520 return ira->codegen->invalid_inst_gen;
25527 }26521 }
2552826522
25529 uint64_t end_scalar = rel_end;26523 uint64_t end_scalar = rel_end;
25530 if (end) {26524 if (end) {
25531 ZigValue *end_val = ir_resolve_const(ira, end, UndefBad);26525 ZigValue *end_val = ir_resolve_const(ira, end, UndefBad);
25532 if (!end_val)26526 if (!end_val)
25533 return ira->codegen->invalid_instruction;26527 return ira->codegen->invalid_inst_gen;
25534 end_scalar = bigint_as_u64(&end_val->data.x_bigint);26528 end_scalar = bigint_as_u64(&end_val->data.x_bigint);
25535 }26529 }
25536 if (!ptr_is_undef) {26530 if (!ptr_is_undef) {
25537 if (end_scalar > rel_end) {26531 if (end_scalar > rel_end) {
25538 ir_add_error(ira, &instruction->base, buf_sprintf("out of bounds slice"));26532 ir_add_error(ira, &instruction->base.base, buf_sprintf("out of bounds slice"));
25539 return ira->codegen->invalid_instruction;26533 return ira->codegen->invalid_inst_gen;
25540 }26534 }
25541 if (start_scalar > end_scalar) {26535 if (start_scalar > end_scalar) {
25542 ir_add_error(ira, &instruction->base, buf_sprintf("slice start is greater than end"));26536 ir_add_error(ira, &instruction->base.base, buf_sprintf("slice start is greater than end"));
25543 return ira->codegen->invalid_instruction;26537 return ira->codegen->invalid_inst_gen;
25544 }26538 }
25545 }26539 }
25546 if (ptr_is_undef && start_scalar != end_scalar) {26540 if (ptr_is_undef && start_scalar != end_scalar) {
25547 ir_add_error(ira, &instruction->base, buf_sprintf("non-zero length slice of undefined pointer"));26541 ir_add_error(ira, &instruction->base.base, buf_sprintf("non-zero length slice of undefined pointer"));
25548 return ira->codegen->invalid_instruction;26542 return ira->codegen->invalid_inst_gen;
25549 }26543 }
2555026544
25551 IrInstruction *result = ir_const(ira, &instruction->base, return_type);26545 IrInstGen *result = ir_const(ira, &instruction->base.base, return_type);
25552 ZigValue *out_val = result->value;26546 ZigValue *out_val = result->value;
25553 out_val->data.x_struct.fields = alloc_const_vals_ptrs(2);26547 out_val->data.x_struct.fields = alloc_const_vals_ptrs(2);
2555426548
...@@ -25605,28 +26599,28 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction...@@ -25605,28 +26599,28 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
25605 return result;26599 return result;
25606 }26600 }
2560726601
25608 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,26602 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
25609 return_type, nullptr, true, false, true);26603 return_type, nullptr, true, true);
25610 if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) {26604 if (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable) {
25611 return result_loc;26605 return result_loc;
25612 }26606 }
25613 return ir_build_slice_gen(ira, &instruction->base, return_type,26607 return ir_build_slice_gen(ira, &instruction->base.base, return_type,
25614 ptr_ptr, casted_start, end, instruction->safety_check_on, result_loc);26608 ptr_ptr, casted_start, end, instruction->safety_check_on, result_loc);
25615}26609}
2561626610
25617static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) {26611static IrInstGen *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstSrcMemberCount *instruction) {
25618 Error err;26612 Error err;
25619 IrInstruction *container = instruction->container->child;26613 IrInstGen *container = instruction->container->child;
25620 if (type_is_invalid(container->value->type))26614 if (type_is_invalid(container->value->type))
25621 return ira->codegen->invalid_instruction;26615 return ira->codegen->invalid_inst_gen;
25622 ZigType *container_type = ir_resolve_type(ira, container);26616 ZigType *container_type = ir_resolve_type(ira, container);
2562326617
25624 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))26618 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
25625 return ira->codegen->invalid_instruction;26619 return ira->codegen->invalid_inst_gen;
2562626620
25627 uint64_t result;26621 uint64_t result;
25628 if (type_is_invalid(container_type)) {26622 if (type_is_invalid(container_type)) {
25629 return ira->codegen->invalid_instruction;26623 return ira->codegen->invalid_inst_gen;
25630 } else if (container_type->id == ZigTypeIdEnum) {26624 } else if (container_type->id == ZigTypeIdEnum) {
25631 result = container_type->data.enumeration.src_field_count;26625 result = container_type->data.enumeration.src_field_count;
25632 } else if (container_type->id == ZigTypeIdStruct) {26626 } else if (container_type->id == ZigTypeIdStruct) {
...@@ -25634,135 +26628,135 @@ static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInst...@@ -25634,135 +26628,135 @@ static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInst
25634 } else if (container_type->id == ZigTypeIdUnion) {26628 } else if (container_type->id == ZigTypeIdUnion) {
25635 result = container_type->data.unionation.src_field_count;26629 result = container_type->data.unionation.src_field_count;
25636 } else if (container_type->id == ZigTypeIdErrorSet) {26630 } else if (container_type->id == ZigTypeIdErrorSet) {
25637 if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.source_node)) {26631 if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.base.source_node)) {
25638 return ira->codegen->invalid_instruction;26632 return ira->codegen->invalid_inst_gen;
25639 }26633 }
25640 if (type_is_global_error_set(container_type)) {26634 if (type_is_global_error_set(container_type)) {
25641 ir_add_error(ira, &instruction->base, buf_sprintf("global error set member count not available at comptime"));26635 ir_add_error(ira, &instruction->base.base, buf_sprintf("global error set member count not available at comptime"));
25642 return ira->codegen->invalid_instruction;26636 return ira->codegen->invalid_inst_gen;
25643 }26637 }
25644 result = container_type->data.error_set.err_count;26638 result = container_type->data.error_set.err_count;
25645 } else {26639 } else {
25646 ir_add_error(ira, &instruction->base, buf_sprintf("no value count available for type '%s'", buf_ptr(&container_type->name)));26640 ir_add_error(ira, &instruction->base.base, buf_sprintf("no value count available for type '%s'", buf_ptr(&container_type->name)));
25647 return ira->codegen->invalid_instruction;26641 return ira->codegen->invalid_inst_gen;
25648 }26642 }
2564926643
25650 return ir_const_unsigned(ira, &instruction->base, result);26644 return ir_const_unsigned(ira, &instruction->base.base, result);
25651}26645}
2565226646
25653static IrInstruction *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) {26647static IrInstGen *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstSrcMemberType *instruction) {
25654 Error err;26648 Error err;
25655 IrInstruction *container_type_value = instruction->container_type->child;26649 IrInstGen *container_type_value = instruction->container_type->child;
25656 ZigType *container_type = ir_resolve_type(ira, container_type_value);26650 ZigType *container_type = ir_resolve_type(ira, container_type_value);
25657 if (type_is_invalid(container_type))26651 if (type_is_invalid(container_type))
25658 return ira->codegen->invalid_instruction;26652 return ira->codegen->invalid_inst_gen;
2565926653
25660 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))26654 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
25661 return ira->codegen->invalid_instruction;26655 return ira->codegen->invalid_inst_gen;
2566226656
2566326657
25664 uint64_t member_index;26658 uint64_t member_index;
25665 IrInstruction *index_value = instruction->member_index->child;26659 IrInstGen *index_value = instruction->member_index->child;
25666 if (!ir_resolve_usize(ira, index_value, &member_index))26660 if (!ir_resolve_usize(ira, index_value, &member_index))
25667 return ira->codegen->invalid_instruction;26661 return ira->codegen->invalid_inst_gen;
2566826662
25669 if (container_type->id == ZigTypeIdStruct) {26663 if (container_type->id == ZigTypeIdStruct) {
25670 if (member_index >= container_type->data.structure.src_field_count) {26664 if (member_index >= container_type->data.structure.src_field_count) {
25671 ir_add_error(ira, index_value,26665 ir_add_error(ira, &index_value->base,
25672 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",26666 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
25673 member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count));26667 member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count));
25674 return ira->codegen->invalid_instruction;26668 return ira->codegen->invalid_inst_gen;
25675 }26669 }
25676 TypeStructField *field = container_type->data.structure.fields[member_index];26670 TypeStructField *field = container_type->data.structure.fields[member_index];
2567726671
25678 return ir_const_type(ira, &instruction->base, field->type_entry);26672 return ir_const_type(ira, &instruction->base.base, field->type_entry);
25679 } else if (container_type->id == ZigTypeIdUnion) {26673 } else if (container_type->id == ZigTypeIdUnion) {
25680 if (member_index >= container_type->data.unionation.src_field_count) {26674 if (member_index >= container_type->data.unionation.src_field_count) {
25681 ir_add_error(ira, index_value,26675 ir_add_error(ira, &index_value->base,
25682 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",26676 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
25683 member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count));26677 member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count));
25684 return ira->codegen->invalid_instruction;26678 return ira->codegen->invalid_inst_gen;
25685 }26679 }
25686 TypeUnionField *field = &container_type->data.unionation.fields[member_index];26680 TypeUnionField *field = &container_type->data.unionation.fields[member_index];
2568726681
25688 return ir_const_type(ira, &instruction->base, field->type_entry);26682 return ir_const_type(ira, &instruction->base.base, field->type_entry);
25689 } else {26683 } else {
25690 ir_add_error(ira, container_type_value,26684 ir_add_error(ira, &container_type_value->base,
25691 buf_sprintf("type '%s' does not support @memberType", buf_ptr(&container_type->name)));26685 buf_sprintf("type '%s' does not support @memberType", buf_ptr(&container_type->name)));
25692 return ira->codegen->invalid_instruction;26686 return ira->codegen->invalid_inst_gen;
25693 }26687 }
25694}26688}
2569526689
25696static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) {26690static IrInstGen *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstSrcMemberName *instruction) {
25697 Error err;26691 Error err;
25698 IrInstruction *container_type_value = instruction->container_type->child;26692 IrInstGen *container_type_value = instruction->container_type->child;
25699 ZigType *container_type = ir_resolve_type(ira, container_type_value);26693 ZigType *container_type = ir_resolve_type(ira, container_type_value);
25700 if (type_is_invalid(container_type))26694 if (type_is_invalid(container_type))
25701 return ira->codegen->invalid_instruction;26695 return ira->codegen->invalid_inst_gen;
2570226696
25703 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))26697 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusSizeKnown)))
25704 return ira->codegen->invalid_instruction;26698 return ira->codegen->invalid_inst_gen;
2570526699
25706 uint64_t member_index;26700 uint64_t member_index;
25707 IrInstruction *index_value = instruction->member_index->child;26701 IrInstGen *index_value = instruction->member_index->child;
25708 if (!ir_resolve_usize(ira, index_value, &member_index))26702 if (!ir_resolve_usize(ira, index_value, &member_index))
25709 return ira->codegen->invalid_instruction;26703 return ira->codegen->invalid_inst_gen;
2571026704
25711 if (container_type->id == ZigTypeIdStruct) {26705 if (container_type->id == ZigTypeIdStruct) {
25712 if (member_index >= container_type->data.structure.src_field_count) {26706 if (member_index >= container_type->data.structure.src_field_count) {
25713 ir_add_error(ira, index_value,26707 ir_add_error(ira, &index_value->base,
25714 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",26708 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
25715 member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count));26709 member_index, buf_ptr(&container_type->name), container_type->data.structure.src_field_count));
25716 return ira->codegen->invalid_instruction;26710 return ira->codegen->invalid_inst_gen;
25717 }26711 }
25718 TypeStructField *field = container_type->data.structure.fields[member_index];26712 TypeStructField *field = container_type->data.structure.fields[member_index];
2571926713
25720 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);26714 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
25721 init_const_str_lit(ira->codegen, result->value, field->name);26715 init_const_str_lit(ira->codegen, result->value, field->name);
25722 return result;26716 return result;
25723 } else if (container_type->id == ZigTypeIdEnum) {26717 } else if (container_type->id == ZigTypeIdEnum) {
25724 if (member_index >= container_type->data.enumeration.src_field_count) {26718 if (member_index >= container_type->data.enumeration.src_field_count) {
25725 ir_add_error(ira, index_value,26719 ir_add_error(ira, &index_value->base,
25726 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",26720 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
25727 member_index, buf_ptr(&container_type->name), container_type->data.enumeration.src_field_count));26721 member_index, buf_ptr(&container_type->name), container_type->data.enumeration.src_field_count));
25728 return ira->codegen->invalid_instruction;26722 return ira->codegen->invalid_inst_gen;
25729 }26723 }
25730 TypeEnumField *field = &container_type->data.enumeration.fields[member_index];26724 TypeEnumField *field = &container_type->data.enumeration.fields[member_index];
2573126725
25732 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);26726 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
25733 init_const_str_lit(ira->codegen, result->value, field->name);26727 init_const_str_lit(ira->codegen, result->value, field->name);
25734 return result;26728 return result;
25735 } else if (container_type->id == ZigTypeIdUnion) {26729 } else if (container_type->id == ZigTypeIdUnion) {
25736 if (member_index >= container_type->data.unionation.src_field_count) {26730 if (member_index >= container_type->data.unionation.src_field_count) {
25737 ir_add_error(ira, index_value,26731 ir_add_error(ira, &index_value->base,
25738 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",26732 buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members",
25739 member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count));26733 member_index, buf_ptr(&container_type->name), container_type->data.unionation.src_field_count));
25740 return ira->codegen->invalid_instruction;26734 return ira->codegen->invalid_inst_gen;
25741 }26735 }
25742 TypeUnionField *field = &container_type->data.unionation.fields[member_index];26736 TypeUnionField *field = &container_type->data.unionation.fields[member_index];
2574326737
25744 IrInstruction *result = ir_const(ira, &instruction->base, nullptr);26738 IrInstGen *result = ir_const(ira, &instruction->base.base, nullptr);
25745 init_const_str_lit(ira->codegen, result->value, field->name);26739 init_const_str_lit(ira->codegen, result->value, field->name);
25746 return result;26740 return result;
25747 } else {26741 } else {
25748 ir_add_error(ira, container_type_value,26742 ir_add_error(ira, &container_type_value->base,
25749 buf_sprintf("type '%s' does not support @memberName", buf_ptr(&container_type->name)));26743 buf_sprintf("type '%s' does not support @memberName", buf_ptr(&container_type->name)));
25750 return ira->codegen->invalid_instruction;26744 return ira->codegen->invalid_inst_gen;
25751 }26745 }
25752}26746}
2575326747
25754static IrInstruction *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstructionHasField *instruction) {26748static IrInstGen *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstSrcHasField *instruction) {
25755 Error err;26749 Error err;
25756 ZigType *container_type = ir_resolve_type(ira, instruction->container_type->child);26750 ZigType *container_type = ir_resolve_type(ira, instruction->container_type->child);
25757 if (type_is_invalid(container_type))26751 if (type_is_invalid(container_type))
25758 return ira->codegen->invalid_instruction;26752 return ira->codegen->invalid_inst_gen;
2575926753
25760 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusZeroBitsKnown)))26754 if ((err = type_resolve(ira->codegen, container_type, ResolveStatusZeroBitsKnown)))
25761 return ira->codegen->invalid_instruction;26755 return ira->codegen->invalid_inst_gen;
2576226756
25763 Buf *field_name = ir_resolve_str(ira, instruction->field_name->child);26757 Buf *field_name = ir_resolve_str(ira, instruction->field_name->child);
25764 if (field_name == nullptr)26758 if (field_name == nullptr)
25765 return ira->codegen->invalid_instruction;26759 return ira->codegen->invalid_inst_gen;
2576626760
25767 bool result;26761 bool result;
25768 if (container_type->id == ZigTypeIdStruct) {26762 if (container_type->id == ZigTypeIdStruct) {
...@@ -25772,91 +26766,77 @@ static IrInstruction *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstruc...@@ -25772,91 +26766,77 @@ static IrInstruction *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstruc
25772 } else if (container_type->id == ZigTypeIdUnion) {26766 } else if (container_type->id == ZigTypeIdUnion) {
25773 result = find_union_type_field(container_type, field_name) != nullptr;26767 result = find_union_type_field(container_type, field_name) != nullptr;
25774 } else {26768 } else {
25775 ir_add_error(ira, instruction->container_type,26769 ir_add_error(ira, &instruction->container_type->base,
25776 buf_sprintf("type '%s' does not support @hasField", buf_ptr(&container_type->name)));26770 buf_sprintf("type '%s' does not support @hasField", buf_ptr(&container_type->name)));
25777 return ira->codegen->invalid_instruction;26771 return ira->codegen->invalid_inst_gen;
25778 }26772 }
25779 return ir_const_bool(ira, &instruction->base, result);26773 return ir_const_bool(ira, &instruction->base.base, result);
25780}26774}
2578126775
25782static IrInstruction *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) {26776static IrInstGen *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstSrcBreakpoint *instruction) {
25783 IrInstruction *result = ir_build_breakpoint(&ira->new_irb,26777 return ir_build_breakpoint_gen(ira, &instruction->base.base);
25784 instruction->base.scope, instruction->base.source_node);
25785 result->value->type = ira->codegen->builtin_types.entry_void;
25786 return result;
25787}26778}
2578826779
25789static IrInstruction *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) {26780static IrInstGen *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstSrcReturnAddress *instruction) {
25790 IrInstruction *result = ir_build_return_address(&ira->new_irb,26781 return ir_build_return_address_gen(ira, &instruction->base.base);
25791 instruction->base.scope, instruction->base.source_node);
25792 result->value->type = ira->codegen->builtin_types.entry_usize;
25793 return result;
25794}26782}
2579526783
25796static IrInstruction *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) {26784static IrInstGen *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstSrcFrameAddress *instruction) {
25797 IrInstruction *result = ir_build_frame_address(&ira->new_irb,26785 return ir_build_frame_address_gen(ira, &instruction->base.base);
25798 instruction->base.scope, instruction->base.source_node);
25799 result->value->type = ira->codegen->builtin_types.entry_usize;
25800 return result;
25801}26786}
2580226787
25803static IrInstruction *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInstructionFrameHandle *instruction) {26788static IrInstGen *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInstSrcFrameHandle *instruction) {
25804 ZigFn *fn = exec_fn_entry(ira->new_irb.exec);26789 ZigFn *fn = ira->new_irb.exec->fn_entry;
25805 ir_assert(fn != nullptr, &instruction->base);26790 ir_assert(fn != nullptr, &instruction->base.base);
2580626791
25807 if (fn->inferred_async_node == nullptr) {26792 if (fn->inferred_async_node == nullptr) {
25808 fn->inferred_async_node = instruction->base.source_node;26793 fn->inferred_async_node = instruction->base.base.source_node;
25809 }26794 }
2581026795
25811 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn);26796 ZigType *frame_type = get_fn_frame_type(ira->codegen, fn);
25812 ZigType *ptr_frame_type = get_pointer_to_type(ira->codegen, frame_type, false);26797 ZigType *ptr_frame_type = get_pointer_to_type(ira->codegen, frame_type, false);
2581326798
25814 IrInstruction *result = ir_build_handle(&ira->new_irb, instruction->base.scope, instruction->base.source_node);26799 return ir_build_handle_gen(ira, &instruction->base.base, ptr_frame_type);
25815 result->value->type = ptr_frame_type;
25816 return result;
25817}26800}
2581826801
25819static IrInstruction *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstructionFrameType *instruction) {26802static IrInstGen *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstSrcFrameType *instruction) {
25820 ZigFn *fn = ir_resolve_fn(ira, instruction->fn->child);26803 ZigFn *fn = ir_resolve_fn(ira, instruction->fn->child);
25821 if (fn == nullptr)26804 if (fn == nullptr)
25822 return ira->codegen->invalid_instruction;26805 return ira->codegen->invalid_inst_gen;
2582326806
25824 if (fn->type_entry->data.fn.is_generic) {26807 if (fn->type_entry->data.fn.is_generic) {
25825 ir_add_error(ira, &instruction->base,26808 ir_add_error(ira, &instruction->base.base,
25826 buf_sprintf("@Frame() of generic function"));26809 buf_sprintf("@Frame() of generic function"));
25827 return ira->codegen->invalid_instruction;26810 return ira->codegen->invalid_inst_gen;
25828 }26811 }
2582926812
25830 ZigType *ty = get_fn_frame_type(ira->codegen, fn);26813 ZigType *ty = get_fn_frame_type(ira->codegen, fn);
25831 return ir_const_type(ira, &instruction->base, ty);26814 return ir_const_type(ira, &instruction->base.base, ty);
25832}26815}
2583326816
25834static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstructionFrameSizeSrc *instruction) {26817static IrInstGen *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstSrcFrameSize *instruction) {
25835 IrInstruction *fn = instruction->fn->child;26818 IrInstGen *fn = instruction->fn->child;
25836 if (type_is_invalid(fn->value->type))26819 if (type_is_invalid(fn->value->type))
25837 return ira->codegen->invalid_instruction;26820 return ira->codegen->invalid_inst_gen;
2583826821
25839 if (fn->value->type->id != ZigTypeIdFn) {26822 if (fn->value->type->id != ZigTypeIdFn) {
25840 ir_add_error(ira, fn,26823 ir_add_error(ira, &fn->base,
25841 buf_sprintf("expected function, found '%s'", buf_ptr(&fn->value->type->name)));26824 buf_sprintf("expected function, found '%s'", buf_ptr(&fn->value->type->name)));
25842 return ira->codegen->invalid_instruction;26825 return ira->codegen->invalid_inst_gen;
25843 }26826 }
2584426827
25845 ira->codegen->need_frame_size_prefix_data = true;26828 ira->codegen->need_frame_size_prefix_data = true;
2584626829
25847 IrInstruction *result = ir_build_frame_size_gen(&ira->new_irb, instruction->base.scope,26830 return ir_build_frame_size_gen(ira, &instruction->base.base, fn);
25848 instruction->base.source_node, fn);
25849 result->value->type = ira->codegen->builtin_types.entry_usize;
25850 return result;
25851}26831}
2585226832
25853static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) {26833static IrInstGen *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstSrcAlignOf *instruction) {
25854 // Here we create a lazy value in order to avoid resolving the alignment of the type26834 // Here we create a lazy value in order to avoid resolving the alignment of the type
25855 // immediately. This avoids false positive dependency loops such as:26835 // immediately. This avoids false positive dependency loops such as:
25856 // const Node = struct {26836 // const Node = struct {
25857 // field: []align(@alignOf(Node)) Node,26837 // field: []align(@alignOf(Node)) Node,
25858 // };26838 // };
25859 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int);26839 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_num_lit_int);
25860 result->value->special = ConstValSpecialLazy;26840 result->value->special = ConstValSpecialLazy;
2586126841
25862 LazyValueAlignOf *lazy_align_of = allocate<LazyValueAlignOf>(1, "LazyValueAlignOf");26842 LazyValueAlignOf *lazy_align_of = allocate<LazyValueAlignOf>(1, "LazyValueAlignOf");
...@@ -25866,41 +26846,41 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct...@@ -25866,41 +26846,41 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct
2586626846
25867 lazy_align_of->target_type = instruction->type_value->child;26847 lazy_align_of->target_type = instruction->type_value->child;
25868 if (ir_resolve_type_lazy(ira, lazy_align_of->target_type) == nullptr)26848 if (ir_resolve_type_lazy(ira, lazy_align_of->target_type) == nullptr)
25869 return ira->codegen->invalid_instruction;26849 return ira->codegen->invalid_inst_gen;
2587026850
25871 return result;26851 return result;
25872}26852}
2587326853
25874static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) {26854static IrInstGen *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstSrcOverflowOp *instruction) {
25875 Error err;26855 Error err;
2587626856
25877 IrInstruction *type_value = instruction->type_value->child;26857 IrInstGen *type_value = instruction->type_value->child;
25878 if (type_is_invalid(type_value->value->type))26858 if (type_is_invalid(type_value->value->type))
25879 return ira->codegen->invalid_instruction;26859 return ira->codegen->invalid_inst_gen;
2588026860
25881 ZigType *dest_type = ir_resolve_type(ira, type_value);26861 ZigType *dest_type = ir_resolve_type(ira, type_value);
25882 if (type_is_invalid(dest_type))26862 if (type_is_invalid(dest_type))
25883 return ira->codegen->invalid_instruction;26863 return ira->codegen->invalid_inst_gen;
2588426864
25885 if (dest_type->id != ZigTypeIdInt) {26865 if (dest_type->id != ZigTypeIdInt) {
25886 ir_add_error(ira, type_value,26866 ir_add_error(ira, &type_value->base,
25887 buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));26867 buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
25888 return ira->codegen->invalid_instruction;26868 return ira->codegen->invalid_inst_gen;
25889 }26869 }
2589026870
25891 IrInstruction *op1 = instruction->op1->child;26871 IrInstGen *op1 = instruction->op1->child;
25892 if (type_is_invalid(op1->value->type))26872 if (type_is_invalid(op1->value->type))
25893 return ira->codegen->invalid_instruction;26873 return ira->codegen->invalid_inst_gen;
2589426874
25895 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type);26875 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, dest_type);
25896 if (type_is_invalid(casted_op1->value->type))26876 if (type_is_invalid(casted_op1->value->type))
25897 return ira->codegen->invalid_instruction;26877 return ira->codegen->invalid_inst_gen;
2589826878
25899 IrInstruction *op2 = instruction->op2->child;26879 IrInstGen *op2 = instruction->op2->child;
25900 if (type_is_invalid(op2->value->type))26880 if (type_is_invalid(op2->value->type))
25901 return ira->codegen->invalid_instruction;26881 return ira->codegen->invalid_inst_gen;
2590226882
25903 IrInstruction *casted_op2;26883 IrInstGen *casted_op2;
25904 if (instruction->op == IrOverflowOpShl) {26884 if (instruction->op == IrOverflowOpShl) {
25905 ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,26885 ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen,
25906 dest_type->data.integral.bit_count - 1);26886 dest_type->data.integral.bit_count - 1);
...@@ -25909,17 +26889,17 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -25909,17 +26889,17 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
25909 casted_op2 = ir_implicit_cast(ira, op2, dest_type);26889 casted_op2 = ir_implicit_cast(ira, op2, dest_type);
25910 }26890 }
25911 if (type_is_invalid(casted_op2->value->type))26891 if (type_is_invalid(casted_op2->value->type))
25912 return ira->codegen->invalid_instruction;26892 return ira->codegen->invalid_inst_gen;
2591326893
25914 IrInstruction *result_ptr = instruction->result_ptr->child;26894 IrInstGen *result_ptr = instruction->result_ptr->child;
25915 if (type_is_invalid(result_ptr->value->type))26895 if (type_is_invalid(result_ptr->value->type))
25916 return ira->codegen->invalid_instruction;26896 return ira->codegen->invalid_inst_gen;
2591726897
25918 ZigType *expected_ptr_type;26898 ZigType *expected_ptr_type;
25919 if (result_ptr->value->type->id == ZigTypeIdPointer) {26899 if (result_ptr->value->type->id == ZigTypeIdPointer) {
25920 uint32_t alignment;26900 uint32_t alignment;
25921 if ((err = resolve_ptr_align(ira, result_ptr->value->type, &alignment)))26901 if ((err = resolve_ptr_align(ira, result_ptr->value->type, &alignment)))
25922 return ira->codegen->invalid_instruction;26902 return ira->codegen->invalid_inst_gen;
25923 expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type,26903 expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type,
25924 false, result_ptr->value->type->data.pointer.is_volatile,26904 false, result_ptr->value->type->data.pointer.is_volatile,
25925 PtrLenSingle,26905 PtrLenSingle,
...@@ -25928,9 +26908,9 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -25928,9 +26908,9 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
25928 expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false);26908 expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false);
25929 }26909 }
2593026910
25931 IrInstruction *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type);26911 IrInstGen *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type);
25932 if (type_is_invalid(casted_result_ptr->value->type))26912 if (type_is_invalid(casted_result_ptr->value->type))
25933 return ira->codegen->invalid_instruction;26913 return ira->codegen->invalid_inst_gen;
2593426914
25935 if (instr_is_comptime(casted_op1) &&26915 if (instr_is_comptime(casted_op1) &&
25936 instr_is_comptime(casted_op2) &&26916 instr_is_comptime(casted_op2) &&
...@@ -25938,22 +26918,22 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -25938,22 +26918,22 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
25938 {26918 {
25939 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);26919 ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
25940 if (op1_val == nullptr)26920 if (op1_val == nullptr)
25941 return ira->codegen->invalid_instruction;26921 return ira->codegen->invalid_inst_gen;
2594226922
25943 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);26923 ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
25944 if (op2_val == nullptr)26924 if (op2_val == nullptr)
25945 return ira->codegen->invalid_instruction;26925 return ira->codegen->invalid_inst_gen;
2594626926
25947 ZigValue *result_val = ir_resolve_const(ira, casted_result_ptr, UndefBad);26927 ZigValue *result_val = ir_resolve_const(ira, casted_result_ptr, UndefBad);
25948 if (result_val == nullptr)26928 if (result_val == nullptr)
25949 return ira->codegen->invalid_instruction;26929 return ira->codegen->invalid_inst_gen;
2595026930
25951 BigInt *op1_bigint = &op1_val->data.x_bigint;26931 BigInt *op1_bigint = &op1_val->data.x_bigint;
25952 BigInt *op2_bigint = &op2_val->data.x_bigint;26932 BigInt *op2_bigint = &op2_val->data.x_bigint;
25953 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, result_val,26933 ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, result_val,
25954 casted_result_ptr->source_node);26934 casted_result_ptr->base.source_node);
25955 if (pointee_val == nullptr)26935 if (pointee_val == nullptr)
25956 return ira->codegen->invalid_instruction;26936 return ira->codegen->invalid_inst_gen;
25957 BigInt *dest_bigint = &pointee_val->data.x_bigint;26937 BigInt *dest_bigint = &pointee_val->data.x_bigint;
25958 switch (instruction->op) {26938 switch (instruction->op) {
25959 case IrOverflowOpAdd:26939 case IrOverflowOpAdd:
...@@ -25980,17 +26960,14 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr...@@ -25980,17 +26960,14 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr
25980 dest_type->data.integral.is_signed);26960 dest_type->data.integral.is_signed);
25981 }26961 }
25982 pointee_val->special = ConstValSpecialStatic;26962 pointee_val->special = ConstValSpecialStatic;
25983 return ir_const_bool(ira, &instruction->base, result_bool);26963 return ir_const_bool(ira, &instruction->base.base, result_bool);
25984 }26964 }
2598526965
25986 IrInstruction *result = ir_build_overflow_op(&ira->new_irb,26966 return ir_build_overflow_op_gen(ira, &instruction->base.base, instruction->op,
25987 instruction->base.scope, instruction->base.source_node,26967 casted_op1, casted_op2, casted_result_ptr, dest_type);
25988 instruction->op, type_value, casted_op1, casted_op2, casted_result_ptr, dest_type);
25989 result->value->type = ira->codegen->builtin_types.entry_bool;
25990 return result;
25991}26968}
2599226969
25993static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, ZigType *float_type,26970static void ir_eval_mul_add(IrAnalyze *ira, IrInstSrcMulAdd *source_instr, ZigType *float_type,
25994 ZigValue *op1, ZigValue *op2, ZigValue *op3, ZigValue *out_val) {26971 ZigValue *op1, ZigValue *op2, ZigValue *op3, ZigValue *out_val) {
25995 if (float_type->id == ZigTypeIdComptimeFloat) {26972 if (float_type->id == ZigTypeIdComptimeFloat) {
25996 f128M_mulAdd(&out_val->data.x_bigfloat.value, &op1->data.x_bigfloat.value, &op2->data.x_bigfloat.value,26973 f128M_mulAdd(&out_val->data.x_bigfloat.value, &op1->data.x_bigfloat.value, &op2->data.x_bigfloat.value,
...@@ -26017,61 +26994,61 @@ static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, Z...@@ -26017,61 +26994,61 @@ static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, Z
26017 }26994 }
26018}26995}
2601926996
26020static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructionMulAdd *instruction) {26997static IrInstGen *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstSrcMulAdd *instruction) {
26021 IrInstruction *type_value = instruction->type_value->child;26998 IrInstGen *type_value = instruction->type_value->child;
26022 if (type_is_invalid(type_value->value->type))26999 if (type_is_invalid(type_value->value->type))
26023 return ira->codegen->invalid_instruction;27000 return ira->codegen->invalid_inst_gen;
2602427001
26025 ZigType *expr_type = ir_resolve_type(ira, type_value);27002 ZigType *expr_type = ir_resolve_type(ira, type_value);
26026 if (type_is_invalid(expr_type))27003 if (type_is_invalid(expr_type))
26027 return ira->codegen->invalid_instruction;27004 return ira->codegen->invalid_inst_gen;
2602827005
26029 // Only allow float types, and vectors of floats.27006 // Only allow float types, and vectors of floats.
26030 ZigType *float_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type;27007 ZigType *float_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type;
26031 if (float_type->id != ZigTypeIdFloat) {27008 if (float_type->id != ZigTypeIdFloat) {
26032 ir_add_error(ira, type_value,27009 ir_add_error(ira, &type_value->base,
26033 buf_sprintf("expected float or vector of float type, found '%s'", buf_ptr(&float_type->name)));27010 buf_sprintf("expected float or vector of float type, found '%s'", buf_ptr(&float_type->name)));
26034 return ira->codegen->invalid_instruction;27011 return ira->codegen->invalid_inst_gen;
26035 }27012 }
2603627013
26037 IrInstruction *op1 = instruction->op1->child;27014 IrInstGen *op1 = instruction->op1->child;
26038 if (type_is_invalid(op1->value->type))27015 if (type_is_invalid(op1->value->type))
26039 return ira->codegen->invalid_instruction;27016 return ira->codegen->invalid_inst_gen;
2604027017
26041 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, expr_type);27018 IrInstGen *casted_op1 = ir_implicit_cast(ira, op1, expr_type);
26042 if (type_is_invalid(casted_op1->value->type))27019 if (type_is_invalid(casted_op1->value->type))
26043 return ira->codegen->invalid_instruction;27020 return ira->codegen->invalid_inst_gen;
2604427021
26045 IrInstruction *op2 = instruction->op2->child;27022 IrInstGen *op2 = instruction->op2->child;
26046 if (type_is_invalid(op2->value->type))27023 if (type_is_invalid(op2->value->type))
26047 return ira->codegen->invalid_instruction;27024 return ira->codegen->invalid_inst_gen;
2604827025
26049 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, expr_type);27026 IrInstGen *casted_op2 = ir_implicit_cast(ira, op2, expr_type);
26050 if (type_is_invalid(casted_op2->value->type))27027 if (type_is_invalid(casted_op2->value->type))
26051 return ira->codegen->invalid_instruction;27028 return ira->codegen->invalid_inst_gen;
2605227029
26053 IrInstruction *op3 = instruction->op3->child;27030 IrInstGen *op3 = instruction->op3->child;
26054 if (type_is_invalid(op3->value->type))27031 if (type_is_invalid(op3->value->type))
26055 return ira->codegen->invalid_instruction;27032 return ira->codegen->invalid_inst_gen;
2605627033
26057 IrInstruction *casted_op3 = ir_implicit_cast(ira, op3, expr_type);27034 IrInstGen *casted_op3 = ir_implicit_cast(ira, op3, expr_type);
26058 if (type_is_invalid(casted_op3->value->type))27035 if (type_is_invalid(casted_op3->value->type))
26059 return ira->codegen->invalid_instruction;27036 return ira->codegen->invalid_inst_gen;
2606027037
26061 if (instr_is_comptime(casted_op1) &&27038 if (instr_is_comptime(casted_op1) &&
26062 instr_is_comptime(casted_op2) &&27039 instr_is_comptime(casted_op2) &&
26063 instr_is_comptime(casted_op3)) {27040 instr_is_comptime(casted_op3)) {
26064 ZigValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad);27041 ZigValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad);
26065 if (!op1_const)27042 if (!op1_const)
26066 return ira->codegen->invalid_instruction;27043 return ira->codegen->invalid_inst_gen;
26067 ZigValue *op2_const = ir_resolve_const(ira, casted_op2, UndefBad);27044 ZigValue *op2_const = ir_resolve_const(ira, casted_op2, UndefBad);
26068 if (!op2_const)27045 if (!op2_const)
26069 return ira->codegen->invalid_instruction;27046 return ira->codegen->invalid_inst_gen;
26070 ZigValue *op3_const = ir_resolve_const(ira, casted_op3, UndefBad);27047 ZigValue *op3_const = ir_resolve_const(ira, casted_op3, UndefBad);
26071 if (!op3_const)27048 if (!op3_const)
26072 return ira->codegen->invalid_instruction;27049 return ira->codegen->invalid_inst_gen;
2607327050
26074 IrInstruction *result = ir_const(ira, &instruction->base, expr_type);27051 IrInstGen *result = ir_const(ira, &instruction->base.base, expr_type);
26075 ZigValue *out_val = result->value;27052 ZigValue *out_val = result->value;
2607627053
26077 if (expr_type->id == ZigTypeIdVector) {27054 if (expr_type->id == ZigTypeIdVector) {
...@@ -26102,63 +27079,59 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi...@@ -26102,63 +27079,59 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi
26102 return result;27079 return result;
26103 }27080 }
2610427081
26105 IrInstruction *result = ir_build_mul_add(&ira->new_irb,27082 return ir_build_mul_add_gen(ira, &instruction->base.base, casted_op1, casted_op2, casted_op3, expr_type);
26106 instruction->base.scope, instruction->base.source_node,
26107 type_value, casted_op1, casted_op2, casted_op3);
26108 result->value->type = expr_type;
26109 return result;
26110}27083}
2611127084
26112static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErrSrc *instruction) {27085static IrInstGen *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstSrcTestErr *instruction) {
26113 IrInstruction *base_ptr = instruction->base_ptr->child;27086 IrInstGen *base_ptr = instruction->base_ptr->child;
26114 if (type_is_invalid(base_ptr->value->type))27087 if (type_is_invalid(base_ptr->value->type))
26115 return ira->codegen->invalid_instruction;27088 return ira->codegen->invalid_inst_gen;
2611627089
26117 IrInstruction *value;27090 IrInstGen *value;
26118 if (instruction->base_ptr_is_payload) {27091 if (instruction->base_ptr_is_payload) {
26119 value = base_ptr;27092 value = base_ptr;
26120 } else {27093 } else {
26121 value = ir_get_deref(ira, &instruction->base, base_ptr, nullptr);27094 value = ir_get_deref(ira, &instruction->base.base, base_ptr, nullptr);
26122 }27095 }
2612327096
26124 ZigType *type_entry = value->value->type;27097 ZigType *type_entry = value->value->type;
26125 if (type_is_invalid(type_entry))27098 if (type_is_invalid(type_entry))
26126 return ira->codegen->invalid_instruction;27099 return ira->codegen->invalid_inst_gen;
26127 if (type_entry->id == ZigTypeIdErrorUnion) {27100 if (type_entry->id == ZigTypeIdErrorUnion) {
26128 if (instr_is_comptime(value)) {27101 if (instr_is_comptime(value)) {
26129 ZigValue *err_union_val = ir_resolve_const(ira, value, UndefBad);27102 ZigValue *err_union_val = ir_resolve_const(ira, value, UndefBad);
26130 if (!err_union_val)27103 if (!err_union_val)
26131 return ira->codegen->invalid_instruction;27104 return ira->codegen->invalid_inst_gen;
2613227105
26133 if (err_union_val->special != ConstValSpecialRuntime) {27106 if (err_union_val->special != ConstValSpecialRuntime) {
26134 ErrorTableEntry *err = err_union_val->data.x_err_union.error_set->data.x_err_set;27107 ErrorTableEntry *err = err_union_val->data.x_err_union.error_set->data.x_err_set;
26135 return ir_const_bool(ira, &instruction->base, (err != nullptr));27108 return ir_const_bool(ira, &instruction->base.base, (err != nullptr));
26136 }27109 }
26137 }27110 }
2613827111
26139 if (instruction->resolve_err_set) {27112 if (instruction->resolve_err_set) {
26140 ZigType *err_set_type = type_entry->data.error_union.err_set_type;27113 ZigType *err_set_type = type_entry->data.error_union.err_set_type;
26141 if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) {27114 if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.base.source_node)) {
26142 return ira->codegen->invalid_instruction;27115 return ira->codegen->invalid_inst_gen;
26143 }27116 }
26144 if (!type_is_global_error_set(err_set_type) &&27117 if (!type_is_global_error_set(err_set_type) &&
26145 err_set_type->data.error_set.err_count == 0)27118 err_set_type->data.error_set.err_count == 0)
26146 {27119 {
26147 assert(!err_set_type->data.error_set.incomplete);27120 assert(!err_set_type->data.error_set.incomplete);
26148 return ir_const_bool(ira, &instruction->base, false);27121 return ir_const_bool(ira, &instruction->base.base, false);
26149 }27122 }
26150 }27123 }
2615127124
26152 return ir_build_test_err_gen(ira, &instruction->base, value);27125 return ir_build_test_err_gen(ira, &instruction->base.base, value);
26153 } else if (type_entry->id == ZigTypeIdErrorSet) {27126 } else if (type_entry->id == ZigTypeIdErrorSet) {
26154 return ir_const_bool(ira, &instruction->base, true);27127 return ir_const_bool(ira, &instruction->base.base, true);
26155 } else {27128 } else {
26156 return ir_const_bool(ira, &instruction->base, false);27129 return ir_const_bool(ira, &instruction->base.base, false);
26157 }27130 }
26158}27131}
2615927132
26160static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *source_instr,27133static IrInstGen *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInst* source_instr,
26161 IrInstruction *base_ptr, bool initializing)27134 IrInstGen *base_ptr, bool initializing)
26162{27135{
26163 ZigType *ptr_type = base_ptr->value->type;27136 ZigType *ptr_type = base_ptr->value->type;
2616427137
...@@ -26167,12 +27140,12 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *...@@ -26167,12 +27140,12 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
2616727140
26168 ZigType *type_entry = ptr_type->data.pointer.child_type;27141 ZigType *type_entry = ptr_type->data.pointer.child_type;
26169 if (type_is_invalid(type_entry))27142 if (type_is_invalid(type_entry))
26170 return ira->codegen->invalid_instruction;27143 return ira->codegen->invalid_inst_gen;
2617127144
26172 if (type_entry->id != ZigTypeIdErrorUnion) {27145 if (type_entry->id != ZigTypeIdErrorUnion) {
26173 ir_add_error(ira, base_ptr,27146 ir_add_error(ira, &base_ptr->base,
26174 buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name)));27147 buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name)));
26175 return ira->codegen->invalid_instruction;27148 return ira->codegen->invalid_inst_gen;
26176 }27149 }
2617727150
26178 ZigType *err_set_type = type_entry->data.error_union.err_set_type;27151 ZigType *err_set_type = type_entry->data.error_union.err_set_type;
...@@ -26183,13 +27156,13 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *...@@ -26183,13 +27156,13 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
26183 if (instr_is_comptime(base_ptr)) {27156 if (instr_is_comptime(base_ptr)) {
26184 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);27157 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);
26185 if (!ptr_val)27158 if (!ptr_val)
26186 return ira->codegen->invalid_instruction;27159 return ira->codegen->invalid_inst_gen;
26187 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&27160 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar &&
26188 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)27161 ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)
26189 {27162 {
26190 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);27163 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
26191 if (err_union_val == nullptr)27164 if (err_union_val == nullptr)
26192 return ira->codegen->invalid_instruction;27165 return ira->codegen->invalid_inst_gen;
2619327166
26194 if (initializing && err_union_val->special == ConstValSpecialUndef) {27167 if (initializing && err_union_val->special == ConstValSpecialUndef) {
26195 ZigValue *vals = create_const_vals(2);27168 ZigValue *vals = create_const_vals(2);
...@@ -26212,11 +27185,10 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *...@@ -26212,11 +27185,10 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
26212 }27185 }
26213 ir_assert(err_union_val->special != ConstValSpecialRuntime, source_instr);27186 ir_assert(err_union_val->special != ConstValSpecialRuntime, source_instr);
2621427187
26215 IrInstruction *result;27188 IrInstGen *result;
26216 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {27189 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
26217 result = ir_build_unwrap_err_code(&ira->new_irb, source_instr->scope,27190 result = ir_build_unwrap_err_code_gen(ira, source_instr->scope,
26218 source_instr->source_node, base_ptr);27191 source_instr->source_node, base_ptr, result_type);
26219 result->value->type = result_type;
26220 result->value->special = ConstValSpecialStatic;27192 result->value->special = ConstValSpecialStatic;
26221 } else {27193 } else {
26222 result = ir_const(ira, source_instr, result_type);27194 result = ir_const(ira, source_instr, result_type);
...@@ -26229,23 +27201,18 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *...@@ -26229,23 +27201,18 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *
26229 }27201 }
26230 }27202 }
2623127203
26232 IrInstruction *result = ir_build_unwrap_err_code(&ira->new_irb,27204 return ir_build_unwrap_err_code_gen(ira, source_instr->scope, source_instr->source_node, base_ptr, result_type);
26233 source_instr->scope, source_instr->source_node, base_ptr);
26234 result->value->type = result_type;
26235 return result;
26236}27205}
2623727206
26238static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,27207static IrInstGen *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, IrInstSrcUnwrapErrCode *instruction) {
26239 IrInstructionUnwrapErrCode *instruction)27208 IrInstGen *base_ptr = instruction->err_union_ptr->child;
26240{
26241 IrInstruction *base_ptr = instruction->err_union_ptr->child;
26242 if (type_is_invalid(base_ptr->value->type))27209 if (type_is_invalid(base_ptr->value->type))
26243 return ira->codegen->invalid_instruction;27210 return ira->codegen->invalid_inst_gen;
26244 return ir_analyze_unwrap_err_code(ira, &instruction->base, base_ptr, false);27211 return ir_analyze_unwrap_err_code(ira, &instruction->base.base, base_ptr, false);
26245}27212}
2624627213
26247static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr,27214static IrInstGen *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInst* source_instr,
26248 IrInstruction *base_ptr, bool safety_check_on, bool initializing)27215 IrInstGen *base_ptr, bool safety_check_on, bool initializing)
26249{27216{
26250 ZigType *ptr_type = base_ptr->value->type;27217 ZigType *ptr_type = base_ptr->value->type;
2625127218
...@@ -26254,17 +27221,17 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct...@@ -26254,17 +27221,17 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
2625427221
26255 ZigType *type_entry = ptr_type->data.pointer.child_type;27222 ZigType *type_entry = ptr_type->data.pointer.child_type;
26256 if (type_is_invalid(type_entry))27223 if (type_is_invalid(type_entry))
26257 return ira->codegen->invalid_instruction;27224 return ira->codegen->invalid_inst_gen;
2625827225
26259 if (type_entry->id != ZigTypeIdErrorUnion) {27226 if (type_entry->id != ZigTypeIdErrorUnion) {
26260 ir_add_error(ira, base_ptr,27227 ir_add_error(ira, &base_ptr->base,
26261 buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name)));27228 buf_sprintf("expected error union type, found '%s'", buf_ptr(&type_entry->name)));
26262 return ira->codegen->invalid_instruction;27229 return ira->codegen->invalid_inst_gen;
26263 }27230 }
2626427231
26265 ZigType *payload_type = type_entry->data.error_union.payload_type;27232 ZigType *payload_type = type_entry->data.error_union.payload_type;
26266 if (type_is_invalid(payload_type))27233 if (type_is_invalid(payload_type))
26267 return ira->codegen->invalid_instruction;27234 return ira->codegen->invalid_inst_gen;
2626827235
26269 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, payload_type,27236 ZigType *result_type = get_pointer_to_type_extra(ira->codegen, payload_type,
26270 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,27237 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile,
...@@ -26273,11 +27240,11 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct...@@ -26273,11 +27240,11 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
26273 if (instr_is_comptime(base_ptr)) {27240 if (instr_is_comptime(base_ptr)) {
26274 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);27241 ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad);
26275 if (!ptr_val)27242 if (!ptr_val)
26276 return ira->codegen->invalid_instruction;27243 return ira->codegen->invalid_inst_gen;
26277 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {27244 if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) {
26278 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);27245 ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
26279 if (err_union_val == nullptr)27246 if (err_union_val == nullptr)
26280 return ira->codegen->invalid_instruction;27247 return ira->codegen->invalid_inst_gen;
26281 if (initializing && err_union_val->special == ConstValSpecialUndef) {27248 if (initializing && err_union_val->special == ConstValSpecialUndef) {
26282 ZigValue *vals = create_const_vals(2);27249 ZigValue *vals = create_const_vals(2);
26283 ZigValue *err_set_val = &vals[0];27250 ZigValue *err_set_val = &vals[0];
...@@ -26300,14 +27267,13 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct...@@ -26300,14 +27267,13 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
26300 if (err != nullptr) {27267 if (err != nullptr) {
26301 ir_add_error(ira, source_instr,27268 ir_add_error(ira, source_instr,
26302 buf_sprintf("caught unexpected error '%s'", buf_ptr(&err->name)));27269 buf_sprintf("caught unexpected error '%s'", buf_ptr(&err->name)));
26303 return ira->codegen->invalid_instruction;27270 return ira->codegen->invalid_inst_gen;
26304 }27271 }
2630527272
26306 IrInstruction *result;27273 IrInstGen *result;
26307 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {27274 if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) {
26308 result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope,27275 result = ir_build_unwrap_err_payload_gen(ira, source_instr->scope,
26309 source_instr->source_node, base_ptr, safety_check_on, initializing);27276 source_instr->source_node, base_ptr, safety_check_on, initializing, result_type);
26310 result->value->type = result_type;
26311 result->value->special = ConstValSpecialStatic;27277 result->value->special = ConstValSpecialStatic;
26312 } else {27278 } else {
26313 result = ir_const(ira, source_instr, result_type);27279 result = ir_const(ira, source_instr, result_type);
...@@ -26320,28 +27286,26 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct...@@ -26320,28 +27286,26 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
26320 }27286 }
26321 }27287 }
2632227288
26323 IrInstruction *result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope,27289 return ir_build_unwrap_err_payload_gen(ira, source_instr->scope, source_instr->source_node,
26324 source_instr->source_node, base_ptr, safety_check_on, initializing);27290 base_ptr, safety_check_on, initializing, result_type);
26325 result->value->type = result_type;
26326 return result;
26327}27291}
2632827292
26329static IrInstruction *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,27293static IrInstGen *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
26330 IrInstructionUnwrapErrPayload *instruction)27294 IrInstSrcUnwrapErrPayload *instruction)
26331{27295{
26332 assert(instruction->value->child);27296 assert(instruction->value->child);
26333 IrInstruction *value = instruction->value->child;27297 IrInstGen *value = instruction->value->child;
26334 if (type_is_invalid(value->value->type))27298 if (type_is_invalid(value->value->type))
26335 return ira->codegen->invalid_instruction;27299 return ira->codegen->invalid_inst_gen;
2633627300
26337 return ir_analyze_unwrap_error_payload(ira, &instruction->base, value, instruction->safety_check_on, false);27301 return ir_analyze_unwrap_error_payload(ira, &instruction->base.base, value, instruction->safety_check_on, false);
26338}27302}
2633927303
26340static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnProto *instruction) {27304static IrInstGen *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstSrcFnProto *instruction) {
26341 AstNode *proto_node = instruction->base.source_node;27305 AstNode *proto_node = instruction->base.base.source_node;
26342 assert(proto_node->type == NodeTypeFnProto);27306 assert(proto_node->type == NodeTypeFnProto);
2634327307
26344 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);27308 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
26345 result->value->special = ConstValSpecialLazy;27309 result->value->special = ConstValSpecialLazy;
2634627310
26347 LazyValueFnType *lazy_fn_type = allocate<LazyValueFnType>(1, "LazyValueFnType");27311 LazyValueFnType *lazy_fn_type = allocate<LazyValueFnType>(1, "LazyValueFnType");
...@@ -26350,29 +27314,29 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct...@@ -26350,29 +27314,29 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
26350 lazy_fn_type->base.id = LazyValueIdFnType;27314 lazy_fn_type->base.id = LazyValueIdFnType;
2635127315
26352 if (proto_node->data.fn_proto.auto_err_set) {27316 if (proto_node->data.fn_proto.auto_err_set) {
26353 ir_add_error(ira, &instruction->base,27317 ir_add_error(ira, &instruction->base.base,
26354 buf_sprintf("inferring error set of return type valid only for function definitions"));27318 buf_sprintf("inferring error set of return type valid only for function definitions"));
26355 return ira->codegen->invalid_instruction;27319 return ira->codegen->invalid_inst_gen;
26356 }27320 }
2635727321
26358 lazy_fn_type->cc = cc_from_fn_proto(&proto_node->data.fn_proto);27322 lazy_fn_type->cc = cc_from_fn_proto(&proto_node->data.fn_proto);
26359 if (instruction->callconv_value != nullptr) {27323 if (instruction->callconv_value != nullptr) {
26360 ZigType *cc_enum_type = get_builtin_type(ira->codegen, "CallingConvention");27324 ZigType *cc_enum_type = get_builtin_type(ira->codegen, "CallingConvention");
2636127325
26362 IrInstruction *casted_value = ir_implicit_cast(ira, instruction->callconv_value, cc_enum_type);27326 IrInstGen *casted_value = ir_implicit_cast(ira, instruction->callconv_value->child, cc_enum_type);
26363 if (type_is_invalid(casted_value->value->type))27327 if (type_is_invalid(casted_value->value->type))
26364 return ira->codegen->invalid_instruction;27328 return ira->codegen->invalid_inst_gen;
2636527329
26366 ZigValue *const_value = ir_resolve_const(ira, casted_value, UndefBad);27330 ZigValue *const_value = ir_resolve_const(ira, casted_value, UndefBad);
26367 if (const_value == nullptr)27331 if (const_value == nullptr)
26368 return ira->codegen->invalid_instruction;27332 return ira->codegen->invalid_inst_gen;
2636927333
26370 lazy_fn_type->cc = (CallingConvention)bigint_as_u32(&const_value->data.x_enum_tag);27334 lazy_fn_type->cc = (CallingConvention)bigint_as_u32(&const_value->data.x_enum_tag);
26371 }27335 }
2637227336
26373 size_t param_count = proto_node->data.fn_proto.params.length;27337 size_t param_count = proto_node->data.fn_proto.params.length;
26374 lazy_fn_type->proto_node = proto_node;27338 lazy_fn_type->proto_node = proto_node;
26375 lazy_fn_type->param_types = allocate<IrInstruction *>(param_count);27339 lazy_fn_type->param_types = allocate<IrInstGen *>(param_count);
2637627340
26377 for (size_t param_index = 0; param_index < param_count; param_index += 1) {27341 for (size_t param_index = 0; param_index < param_count; param_index += 1) {
26378 AstNode *param_node = proto_node->data.fn_proto.params.at(param_index);27342 AstNode *param_node = proto_node->data.fn_proto.params.at(param_index);
...@@ -26397,63 +27361,63 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct...@@ -26397,63 +27361,63 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct
26397 return result;27361 return result;
26398 }27362 }
2639927363
26400 IrInstruction *param_type_value = instruction->param_types[param_index]->child;27364 IrInstGen *param_type_value = instruction->param_types[param_index]->child;
26401 if (type_is_invalid(param_type_value->value->type))27365 if (type_is_invalid(param_type_value->value->type))
26402 return ira->codegen->invalid_instruction;27366 return ira->codegen->invalid_inst_gen;
26403 if (ir_resolve_const(ira, param_type_value, LazyOk) == nullptr)27367 if (ir_resolve_const(ira, param_type_value, LazyOk) == nullptr)
26404 return ira->codegen->invalid_instruction;27368 return ira->codegen->invalid_inst_gen;
26405 lazy_fn_type->param_types[param_index] = param_type_value;27369 lazy_fn_type->param_types[param_index] = param_type_value;
26406 }27370 }
2640727371
26408 if (instruction->align_value != nullptr) {27372 if (instruction->align_value != nullptr) {
26409 lazy_fn_type->align_inst = instruction->align_value->child;27373 lazy_fn_type->align_inst = instruction->align_value->child;
26410 if (ir_resolve_const(ira, lazy_fn_type->align_inst, LazyOk) == nullptr)27374 if (ir_resolve_const(ira, lazy_fn_type->align_inst, LazyOk) == nullptr)
26411 return ira->codegen->invalid_instruction;27375 return ira->codegen->invalid_inst_gen;
26412 }27376 }
2641327377
26414 lazy_fn_type->return_type = instruction->return_type->child;27378 lazy_fn_type->return_type = instruction->return_type->child;
26415 if (ir_resolve_const(ira, lazy_fn_type->return_type, LazyOk) == nullptr)27379 if (ir_resolve_const(ira, lazy_fn_type->return_type, LazyOk) == nullptr)
26416 return ira->codegen->invalid_instruction;27380 return ira->codegen->invalid_inst_gen;
2641727381
26418 return result;27382 return result;
26419}27383}
2642027384
26421static IrInstruction *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) {27385static IrInstGen *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstSrcTestComptime *instruction) {
26422 IrInstruction *value = instruction->value->child;27386 IrInstGen *value = instruction->value->child;
26423 if (type_is_invalid(value->value->type))27387 if (type_is_invalid(value->value->type))
26424 return ira->codegen->invalid_instruction;27388 return ira->codegen->invalid_inst_gen;
2642527389
26426 return ir_const_bool(ira, &instruction->base, instr_is_comptime(value));27390 return ir_const_bool(ira, &instruction->base.base, instr_is_comptime(value));
26427}27391}
2642827392
26429static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,27393static IrInstGen *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
26430 IrInstructionCheckSwitchProngs *instruction)27394 IrInstSrcCheckSwitchProngs *instruction)
26431{27395{
26432 IrInstruction *target_value = instruction->target_value->child;27396 IrInstGen *target_value = instruction->target_value->child;
26433 ZigType *switch_type = target_value->value->type;27397 ZigType *switch_type = target_value->value->type;
26434 if (type_is_invalid(switch_type))27398 if (type_is_invalid(switch_type))
26435 return ira->codegen->invalid_instruction;27399 return ira->codegen->invalid_inst_gen;
2643627400
26437 if (switch_type->id == ZigTypeIdEnum) {27401 if (switch_type->id == ZigTypeIdEnum) {
26438 HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> field_prev_uses = {};27402 HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> field_prev_uses = {};
26439 field_prev_uses.init(switch_type->data.enumeration.src_field_count);27403 field_prev_uses.init(switch_type->data.enumeration.src_field_count);
2644027404
26441 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {27405 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
26442 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];27406 IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i];
2644327407
26444 IrInstruction *start_value_uncasted = range->start->child;27408 IrInstGen *start_value_uncasted = range->start->child;
26445 if (type_is_invalid(start_value_uncasted->value->type))27409 if (type_is_invalid(start_value_uncasted->value->type))
26446 return ira->codegen->invalid_instruction;27410 return ira->codegen->invalid_inst_gen;
26447 IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);27411 IrInstGen *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);
26448 if (type_is_invalid(start_value->value->type))27412 if (type_is_invalid(start_value->value->type))
26449 return ira->codegen->invalid_instruction;27413 return ira->codegen->invalid_inst_gen;
2645027414
26451 IrInstruction *end_value_uncasted = range->end->child;27415 IrInstGen *end_value_uncasted = range->end->child;
26452 if (type_is_invalid(end_value_uncasted->value->type))27416 if (type_is_invalid(end_value_uncasted->value->type))
26453 return ira->codegen->invalid_instruction;27417 return ira->codegen->invalid_inst_gen;
26454 IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);27418 IrInstGen *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);
26455 if (type_is_invalid(end_value->value->type))27419 if (type_is_invalid(end_value->value->type))
26456 return ira->codegen->invalid_instruction;27420 return ira->codegen->invalid_inst_gen;
2645727421
26458 assert(start_value->value->type->id == ZigTypeIdEnum);27422 assert(start_value->value->type->id == ZigTypeIdEnum);
26459 BigInt start_index;27423 BigInt start_index;
...@@ -26464,7 +27428,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -26464,7 +27428,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
26464 bigint_init_bigint(&end_index, &end_value->value->data.x_enum_tag);27428 bigint_init_bigint(&end_index, &end_value->value->data.x_enum_tag);
2646527429
26466 if (bigint_cmp(&start_index, &end_index) == CmpGT) {27430 if (bigint_cmp(&start_index, &end_index) == CmpGT) {
26467 ir_add_error(ira, start_value,27431 ir_add_error(ira, &start_value->base,
26468 buf_sprintf("range start value is greater than the end value"));27432 buf_sprintf("range start value is greater than the end value"));
26469 }27433 }
2647027434
...@@ -26475,12 +27439,12 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -26475,12 +27439,12 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
26475 if (cmp == CmpGT) {27439 if (cmp == CmpGT) {
26476 break;27440 break;
26477 }27441 }
26478 auto entry = field_prev_uses.put_unique(field_index, start_value->source_node);27442 auto entry = field_prev_uses.put_unique(field_index, start_value->base.source_node);
26479 if (entry) {27443 if (entry) {
26480 AstNode *prev_node = entry->value;27444 AstNode *prev_node = entry->value;
26481 TypeEnumField *enum_field = find_enum_field_by_tag(switch_type, &field_index);27445 TypeEnumField *enum_field = find_enum_field_by_tag(switch_type, &field_index);
26482 assert(enum_field != nullptr);27446 assert(enum_field != nullptr);
26483 ErrorMsg *msg = ir_add_error(ira, start_value,27447 ErrorMsg *msg = ir_add_error(ira, &start_value->base,
26484 buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name),27448 buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name),
26485 buf_ptr(enum_field->name)));27449 buf_ptr(enum_field->name)));
26486 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value is here"));27450 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value is here"));
...@@ -26490,7 +27454,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -26490,7 +27454,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
26490 }27454 }
26491 if (instruction->have_underscore_prong) {27455 if (instruction->have_underscore_prong) {
26492 if (!switch_type->data.enumeration.non_exhaustive){27456 if (!switch_type->data.enumeration.non_exhaustive){
26493 ir_add_error(ira, &instruction->base,27457 ir_add_error(ira, &instruction->base.base,
26494 buf_sprintf("switch on non-exhaustive enum has `_` prong"));27458 buf_sprintf("switch on non-exhaustive enum has `_` prong"));
26495 }27459 }
26496 for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) {27460 for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) {
...@@ -26500,14 +27464,14 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -26500,14 +27464,14 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2650027464
26501 auto entry = field_prev_uses.maybe_get(enum_field->value);27465 auto entry = field_prev_uses.maybe_get(enum_field->value);
26502 if (!entry) {27466 if (!entry) {
26503 ir_add_error(ira, &instruction->base,27467 ir_add_error(ira, &instruction->base.base,
26504 buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name),27468 buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name),
26505 buf_ptr(enum_field->name)));27469 buf_ptr(enum_field->name)));
26506 }27470 }
26507 }27471 }
26508 } else if (!instruction->have_else_prong) {27472 } else if (!instruction->have_else_prong) {
26509 if (switch_type->data.enumeration.non_exhaustive) {27473 if (switch_type->data.enumeration.non_exhaustive) {
26510 ir_add_error(ira, &instruction->base,27474 ir_add_error(ira, &instruction->base.base,
26511 buf_sprintf("switch on non-exhaustive enum must include `else` or `_` prong"));27475 buf_sprintf("switch on non-exhaustive enum must include `else` or `_` prong"));
26512 }27476 }
26513 for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) {27477 for (uint32_t i = 0; i < switch_type->data.enumeration.src_field_count; i += 1) {
...@@ -26515,69 +27479,69 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -26515,69 +27479,69 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
2651527479
26516 auto entry = field_prev_uses.maybe_get(enum_field->value);27480 auto entry = field_prev_uses.maybe_get(enum_field->value);
26517 if (!entry) {27481 if (!entry) {
26518 ir_add_error(ira, &instruction->base,27482 ir_add_error(ira, &instruction->base.base,
26519 buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name),27483 buf_sprintf("enumeration value '%s.%s' not handled in switch", buf_ptr(&switch_type->name),
26520 buf_ptr(enum_field->name)));27484 buf_ptr(enum_field->name)));
26521 }27485 }
26522 }27486 }
26523 }27487 }
26524 } else if (switch_type->id == ZigTypeIdErrorSet) {27488 } else if (switch_type->id == ZigTypeIdErrorSet) {
26525 if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) {27489 if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->base.source_node)) {
26526 return ira->codegen->invalid_instruction;27490 return ira->codegen->invalid_inst_gen;
26527 }27491 }
2652827492
26529 size_t field_prev_uses_count = ira->codegen->errors_by_index.length;27493 size_t field_prev_uses_count = ira->codegen->errors_by_index.length;
26530 AstNode **field_prev_uses = allocate<AstNode *>(field_prev_uses_count, "AstNode *");27494 AstNode **field_prev_uses = allocate<AstNode *>(field_prev_uses_count, "AstNode *");
2653127495
26532 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {27496 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
26533 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];27497 IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i];
2653427498
26535 IrInstruction *start_value_uncasted = range->start->child;27499 IrInstGen *start_value_uncasted = range->start->child;
26536 if (type_is_invalid(start_value_uncasted->value->type))27500 if (type_is_invalid(start_value_uncasted->value->type))
26537 return ira->codegen->invalid_instruction;27501 return ira->codegen->invalid_inst_gen;
26538 IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);27502 IrInstGen *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type);
26539 if (type_is_invalid(start_value->value->type))27503 if (type_is_invalid(start_value->value->type))
26540 return ira->codegen->invalid_instruction;27504 return ira->codegen->invalid_inst_gen;
2654127505
26542 IrInstruction *end_value_uncasted = range->end->child;27506 IrInstGen *end_value_uncasted = range->end->child;
26543 if (type_is_invalid(end_value_uncasted->value->type))27507 if (type_is_invalid(end_value_uncasted->value->type))
26544 return ira->codegen->invalid_instruction;27508 return ira->codegen->invalid_inst_gen;
26545 IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);27509 IrInstGen *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type);
26546 if (type_is_invalid(end_value->value->type))27510 if (type_is_invalid(end_value->value->type))
26547 return ira->codegen->invalid_instruction;27511 return ira->codegen->invalid_inst_gen;
2654827512
26549 ir_assert(start_value->value->type->id == ZigTypeIdErrorSet, &instruction->base);27513 ir_assert(start_value->value->type->id == ZigTypeIdErrorSet, &instruction->base.base);
26550 uint32_t start_index = start_value->value->data.x_err_set->value;27514 uint32_t start_index = start_value->value->data.x_err_set->value;
2655127515
26552 ir_assert(end_value->value->type->id == ZigTypeIdErrorSet, &instruction->base);27516 ir_assert(end_value->value->type->id == ZigTypeIdErrorSet, &instruction->base.base);
26553 uint32_t end_index = end_value->value->data.x_err_set->value;27517 uint32_t end_index = end_value->value->data.x_err_set->value;
2655427518
26555 if (start_index != end_index) {27519 if (start_index != end_index) {
26556 ir_add_error(ira, end_value, buf_sprintf("ranges not allowed when switching on errors"));27520 ir_add_error(ira, &end_value->base, buf_sprintf("ranges not allowed when switching on errors"));
26557 return ira->codegen->invalid_instruction;27521 return ira->codegen->invalid_inst_gen;
26558 }27522 }
2655927523
26560 AstNode *prev_node = field_prev_uses[start_index];27524 AstNode *prev_node = field_prev_uses[start_index];
26561 if (prev_node != nullptr) {27525 if (prev_node != nullptr) {
26562 Buf *err_name = &ira->codegen->errors_by_index.at(start_index)->name;27526 Buf *err_name = &ira->codegen->errors_by_index.at(start_index)->name;
26563 ErrorMsg *msg = ir_add_error(ira, start_value,27527 ErrorMsg *msg = ir_add_error(ira, &start_value->base,
26564 buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name), buf_ptr(err_name)));27528 buf_sprintf("duplicate switch value: '%s.%s'", buf_ptr(&switch_type->name), buf_ptr(err_name)));
26565 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value is here"));27529 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("other value is here"));
26566 }27530 }
26567 field_prev_uses[start_index] = start_value->source_node;27531 field_prev_uses[start_index] = start_value->base.source_node;
26568 }27532 }
26569 if (!instruction->have_else_prong) {27533 if (!instruction->have_else_prong) {
26570 if (type_is_global_error_set(switch_type)) {27534 if (type_is_global_error_set(switch_type)) {
26571 ir_add_error(ira, &instruction->base,27535 ir_add_error(ira, &instruction->base.base,
26572 buf_sprintf("else prong required when switching on type 'anyerror'"));27536 buf_sprintf("else prong required when switching on type 'anyerror'"));
26573 return ira->codegen->invalid_instruction;27537 return ira->codegen->invalid_inst_gen;
26574 } else {27538 } else {
26575 for (uint32_t i = 0; i < switch_type->data.error_set.err_count; i += 1) {27539 for (uint32_t i = 0; i < switch_type->data.error_set.err_count; i += 1) {
26576 ErrorTableEntry *err_entry = switch_type->data.error_set.errors[i];27540 ErrorTableEntry *err_entry = switch_type->data.error_set.errors[i];
2657727541
26578 AstNode *prev_node = field_prev_uses[err_entry->value];27542 AstNode *prev_node = field_prev_uses[err_entry->value];
26579 if (prev_node == nullptr) {27543 if (prev_node == nullptr) {
26580 ir_add_error(ira, &instruction->base,27544 ir_add_error(ira, &instruction->base.base,
26581 buf_sprintf("error.%s not handled in switch", buf_ptr(&err_entry->name)));27545 buf_sprintf("error.%s not handled in switch", buf_ptr(&err_entry->name)));
26582 }27546 }
26583 }27547 }
...@@ -26588,44 +27552,44 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -26588,44 +27552,44 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
26588 } else if (switch_type->id == ZigTypeIdInt) {27552 } else if (switch_type->id == ZigTypeIdInt) {
26589 RangeSet rs = {0};27553 RangeSet rs = {0};
26590 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {27554 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
26591 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];27555 IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i];
2659227556
26593 IrInstruction *start_value = range->start->child;27557 IrInstGen *start_value = range->start->child;
26594 if (type_is_invalid(start_value->value->type))27558 if (type_is_invalid(start_value->value->type))
26595 return ira->codegen->invalid_instruction;27559 return ira->codegen->invalid_inst_gen;
26596 IrInstruction *casted_start_value = ir_implicit_cast(ira, start_value, switch_type);27560 IrInstGen *casted_start_value = ir_implicit_cast(ira, start_value, switch_type);
26597 if (type_is_invalid(casted_start_value->value->type))27561 if (type_is_invalid(casted_start_value->value->type))
26598 return ira->codegen->invalid_instruction;27562 return ira->codegen->invalid_inst_gen;
2659927563
26600 IrInstruction *end_value = range->end->child;27564 IrInstGen *end_value = range->end->child;
26601 if (type_is_invalid(end_value->value->type))27565 if (type_is_invalid(end_value->value->type))
26602 return ira->codegen->invalid_instruction;27566 return ira->codegen->invalid_inst_gen;
26603 IrInstruction *casted_end_value = ir_implicit_cast(ira, end_value, switch_type);27567 IrInstGen *casted_end_value = ir_implicit_cast(ira, end_value, switch_type);
26604 if (type_is_invalid(casted_end_value->value->type))27568 if (type_is_invalid(casted_end_value->value->type))
26605 return ira->codegen->invalid_instruction;27569 return ira->codegen->invalid_inst_gen;
2660627570
26607 ZigValue *start_val = ir_resolve_const(ira, casted_start_value, UndefBad);27571 ZigValue *start_val = ir_resolve_const(ira, casted_start_value, UndefBad);
26608 if (!start_val)27572 if (!start_val)
26609 return ira->codegen->invalid_instruction;27573 return ira->codegen->invalid_inst_gen;
2661027574
26611 ZigValue *end_val = ir_resolve_const(ira, casted_end_value, UndefBad);27575 ZigValue *end_val = ir_resolve_const(ira, casted_end_value, UndefBad);
26612 if (!end_val)27576 if (!end_val)
26613 return ira->codegen->invalid_instruction;27577 return ira->codegen->invalid_inst_gen;
2661427578
26615 assert(start_val->type->id == ZigTypeIdInt || start_val->type->id == ZigTypeIdComptimeInt);27579 assert(start_val->type->id == ZigTypeIdInt || start_val->type->id == ZigTypeIdComptimeInt);
26616 assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt);27580 assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt);
2661727581
26618 if (bigint_cmp(&start_val->data.x_bigint, &end_val->data.x_bigint) == CmpGT) {27582 if (bigint_cmp(&start_val->data.x_bigint, &end_val->data.x_bigint) == CmpGT) {
26619 ir_add_error(ira, start_value,27583 ir_add_error(ira, &start_value->base,
26620 buf_sprintf("range start value is greater than the end value"));27584 buf_sprintf("range start value is greater than the end value"));
26621 }27585 }
2662227586
26623 AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint,27587 AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint,
26624 start_value->source_node);27588 start_value->base.source_node);
26625 if (prev_node != nullptr) {27589 if (prev_node != nullptr) {
26626 ErrorMsg *msg = ir_add_error(ira, start_value, buf_sprintf("duplicate switch value"));27590 ErrorMsg *msg = ir_add_error(ira, &start_value->base, buf_sprintf("duplicate switch value"));
26627 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("previous value is here"));27591 add_error_note(ira->codegen, msg, prev_node, buf_sprintf("previous value is here"));
26628 return ira->codegen->invalid_instruction;27592 return ira->codegen->invalid_inst_gen;
26629 }27593 }
26630 }27594 }
26631 if (!instruction->have_else_prong) {27595 if (!instruction->have_else_prong) {
...@@ -26634,25 +27598,25 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -26634,25 +27598,25 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
26634 BigInt max_val;27598 BigInt max_val;
26635 eval_min_max_value_int(ira->codegen, switch_type, &max_val, true);27599 eval_min_max_value_int(ira->codegen, switch_type, &max_val, true);
26636 if (!rangeset_spans(&rs, &min_val, &max_val)) {27600 if (!rangeset_spans(&rs, &min_val, &max_val)) {
26637 ir_add_error(ira, &instruction->base, buf_sprintf("switch must handle all possibilities"));27601 ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities"));
26638 return ira->codegen->invalid_instruction;27602 return ira->codegen->invalid_inst_gen;
26639 }27603 }
26640 }27604 }
26641 } else if (switch_type->id == ZigTypeIdBool) {27605 } else if (switch_type->id == ZigTypeIdBool) {
26642 int seenTrue = 0;27606 int seenTrue = 0;
26643 int seenFalse = 0;27607 int seenFalse = 0;
26644 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {27608 for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) {
26645 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];27609 IrInstSrcCheckSwitchProngsRange *range = &instruction->ranges[range_i];
2664627610
26647 IrInstruction *value = range->start->child;27611 IrInstGen *value = range->start->child;
2664827612
26649 IrInstruction *casted_value = ir_implicit_cast(ira, value, switch_type);27613 IrInstGen *casted_value = ir_implicit_cast(ira, value, switch_type);
26650 if (type_is_invalid(casted_value->value->type))27614 if (type_is_invalid(casted_value->value->type))
26651 return ira->codegen->invalid_instruction;27615 return ira->codegen->invalid_inst_gen;
2665227616
26653 ZigValue *const_expr_val = ir_resolve_const(ira, casted_value, UndefBad);27617 ZigValue *const_expr_val = ir_resolve_const(ira, casted_value, UndefBad);
26654 if (!const_expr_val)27618 if (!const_expr_val)
26655 return ira->codegen->invalid_instruction;27619 return ira->codegen->invalid_inst_gen;
2665627620
26657 assert(const_expr_val->type->id == ZigTypeIdBool);27621 assert(const_expr_val->type->id == ZigTypeIdBool);
2665827622
...@@ -26663,60 +27627,59 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,...@@ -26663,60 +27627,59 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira,
26663 }27627 }
2666427628
26665 if ((seenTrue > 1) || (seenFalse > 1)) {27629 if ((seenTrue > 1) || (seenFalse > 1)) {
26666 ir_add_error(ira, value, buf_sprintf("duplicate switch value"));27630 ir_add_error(ira, &value->base, buf_sprintf("duplicate switch value"));
26667 return ira->codegen->invalid_instruction;27631 return ira->codegen->invalid_inst_gen;
26668 }27632 }
26669 }27633 }
26670 if (((seenTrue < 1) || (seenFalse < 1)) && !instruction->have_else_prong) {27634 if (((seenTrue < 1) || (seenFalse < 1)) && !instruction->have_else_prong) {
26671 ir_add_error(ira, &instruction->base, buf_sprintf("switch must handle all possibilities"));27635 ir_add_error(ira, &instruction->base.base, buf_sprintf("switch must handle all possibilities"));
26672 return ira->codegen->invalid_instruction;27636 return ira->codegen->invalid_inst_gen;
26673 }27637 }
26674 } else if (!instruction->have_else_prong) {27638 } else if (!instruction->have_else_prong) {
26675 ir_add_error(ira, &instruction->base,27639 ir_add_error(ira, &instruction->base.base,
26676 buf_sprintf("else prong required when switching on type '%s'", buf_ptr(&switch_type->name)));27640 buf_sprintf("else prong required when switching on type '%s'", buf_ptr(&switch_type->name)));
26677 return ira->codegen->invalid_instruction;27641 return ira->codegen->invalid_inst_gen;
26678 }27642 }
26679 return ir_const_void(ira, &instruction->base);27643 return ir_const_void(ira, &instruction->base.base);
26680}27644}
2668127645
26682static IrInstruction *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,27646static IrInstGen *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira,
26683 IrInstructionCheckStatementIsVoid *instruction)27647 IrInstSrcCheckStatementIsVoid *instruction)
26684{27648{
26685 IrInstruction *statement_value = instruction->statement_value->child;27649 IrInstGen *statement_value = instruction->statement_value->child;
26686 ZigType *statement_type = statement_value->value->type;27650 ZigType *statement_type = statement_value->value->type;
26687 if (type_is_invalid(statement_type))27651 if (type_is_invalid(statement_type))
26688 return ira->codegen->invalid_instruction;27652 return ira->codegen->invalid_inst_gen;
2668927653
26690 if (statement_type->id != ZigTypeIdVoid && statement_type->id != ZigTypeIdUnreachable) {27654 if (statement_type->id != ZigTypeIdVoid && statement_type->id != ZigTypeIdUnreachable) {
26691 ir_add_error(ira, &instruction->base, buf_sprintf("expression value is ignored"));27655 ir_add_error(ira, &instruction->base.base, buf_sprintf("expression value is ignored"));
26692 }27656 }
2669327657
26694 return ir_const_void(ira, &instruction->base);27658 return ir_const_void(ira, &instruction->base.base);
26695}27659}
2669627660
26697static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) {27661static IrInstGen *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstSrcPanic *instruction) {
26698 IrInstruction *msg = instruction->msg->child;27662 IrInstGen *msg = instruction->msg->child;
26699 if (type_is_invalid(msg->value->type))27663 if (type_is_invalid(msg->value->type))
26700 return ir_unreach_error(ira);27664 return ir_unreach_error(ira);
2670127665
26702 if (ir_should_inline(ira->new_irb.exec, instruction->base.scope)) {27666 if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope)) {
26703 ir_add_error(ira, &instruction->base, buf_sprintf("encountered @panic at compile-time"));27667 ir_add_error(ira, &instruction->base.base, buf_sprintf("encountered @panic at compile-time"));
26704 return ir_unreach_error(ira);27668 return ir_unreach_error(ira);
26705 }27669 }
2670627670
26707 ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,27671 ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
26708 true, false, PtrLenUnknown, 0, 0, 0, false);27672 true, false, PtrLenUnknown, 0, 0, 0, false);
26709 ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);27673 ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type);
26710 IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type);27674 IrInstGen *casted_msg = ir_implicit_cast(ira, msg, str_type);
26711 if (type_is_invalid(casted_msg->value->type))27675 if (type_is_invalid(casted_msg->value->type))
26712 return ir_unreach_error(ira);27676 return ir_unreach_error(ira);
2671327677
26714 IrInstruction *new_instruction = ir_build_panic(&ira->new_irb, instruction->base.scope,27678 IrInstGen *new_instruction = ir_build_panic_gen(ira, &instruction->base.base, casted_msg);
26715 instruction->base.source_node, casted_msg);
26716 return ir_finish_anal(ira, new_instruction);27679 return ir_finish_anal(ira, new_instruction);
26717}27680}
2671827681
26719static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) {27682static IrInstGen *ir_align_cast(IrAnalyze *ira, IrInstGen *target, uint32_t align_bytes, bool safety_check_on) {
26720 Error err;27683 Error err;
2672127684
26722 ZigType *target_type = target->value->type;27685 ZigType *target_type = target->value->type;
...@@ -26728,7 +27691,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3...@@ -26728,7 +27691,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
26728 if (target_type->id == ZigTypeIdPointer) {27691 if (target_type->id == ZigTypeIdPointer) {
26729 result_type = adjust_ptr_align(ira->codegen, target_type, align_bytes);27692 result_type = adjust_ptr_align(ira->codegen, target_type, align_bytes);
26730 if ((err = resolve_ptr_align(ira, target_type, &old_align_bytes)))27693 if ((err = resolve_ptr_align(ira, target_type, &old_align_bytes)))
26731 return ira->codegen->invalid_instruction;27694 return ira->codegen->invalid_inst_gen;
26732 } else if (target_type->id == ZigTypeIdFn) {27695 } else if (target_type->id == ZigTypeIdFn) {
26733 FnTypeId fn_type_id = target_type->data.fn.fn_type_id;27696 FnTypeId fn_type_id = target_type->data.fn.fn_type_id;
26734 old_align_bytes = fn_type_id.alignment;27697 old_align_bytes = fn_type_id.alignment;
...@@ -26739,7 +27702,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3...@@ -26739,7 +27702,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
26739 {27702 {
26740 ZigType *ptr_type = target_type->data.maybe.child_type;27703 ZigType *ptr_type = target_type->data.maybe.child_type;
26741 if ((err = resolve_ptr_align(ira, ptr_type, &old_align_bytes)))27704 if ((err = resolve_ptr_align(ira, ptr_type, &old_align_bytes)))
26742 return ira->codegen->invalid_instruction;27705 return ira->codegen->invalid_inst_gen;
26743 ZigType *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes);27706 ZigType *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes);
2674427707
26745 result_type = get_optional_type(ira->codegen, better_ptr_type);27708 result_type = get_optional_type(ira->codegen, better_ptr_type);
...@@ -26754,47 +27717,44 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3...@@ -26754,47 +27717,44 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3
26754 } else if (is_slice(target_type)) {27717 } else if (is_slice(target_type)) {
26755 ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index]->type_entry;27718 ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index]->type_entry;
26756 if ((err = resolve_ptr_align(ira, slice_ptr_type, &old_align_bytes)))27719 if ((err = resolve_ptr_align(ira, slice_ptr_type, &old_align_bytes)))
26757 return ira->codegen->invalid_instruction;27720 return ira->codegen->invalid_inst_gen;
26758 ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes);27721 ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes);
26759 result_type = get_slice_type(ira->codegen, result_ptr_type);27722 result_type = get_slice_type(ira->codegen, result_ptr_type);
26760 } else {27723 } else {
26761 ir_add_error(ira, target,27724 ir_add_error(ira, &target->base,
26762 buf_sprintf("expected pointer or slice, found '%s'", buf_ptr(&target_type->name)));27725 buf_sprintf("expected pointer or slice, found '%s'", buf_ptr(&target_type->name)));
26763 return ira->codegen->invalid_instruction;27726 return ira->codegen->invalid_inst_gen;
26764 }27727 }
2676527728
26766 if (instr_is_comptime(target)) {27729 if (instr_is_comptime(target)) {
26767 ZigValue *val = ir_resolve_const(ira, target, UndefBad);27730 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
26768 if (!val)27731 if (!val)
26769 return ira->codegen->invalid_instruction;27732 return ira->codegen->invalid_inst_gen;
2677027733
26771 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&27734 if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr &&
26772 val->data.x_ptr.data.hard_coded_addr.addr % align_bytes != 0)27735 val->data.x_ptr.data.hard_coded_addr.addr % align_bytes != 0)
26773 {27736 {
26774 ir_add_error(ira, target,27737 ir_add_error(ira, &target->base,
26775 buf_sprintf("pointer address 0x%" ZIG_PRI_x64 " is not aligned to %" PRIu32 " bytes",27738 buf_sprintf("pointer address 0x%" ZIG_PRI_x64 " is not aligned to %" PRIu32 " bytes",
26776 val->data.x_ptr.data.hard_coded_addr.addr, align_bytes));27739 val->data.x_ptr.data.hard_coded_addr.addr, align_bytes));
26777 return ira->codegen->invalid_instruction;27740 return ira->codegen->invalid_inst_gen;
26778 }27741 }
2677927742
26780 IrInstruction *result = ir_const(ira, target, result_type);27743 IrInstGen *result = ir_const(ira, &target->base, result_type);
26781 copy_const_val(result->value, val);27744 copy_const_val(result->value, val);
26782 result->value->type = result_type;27745 result->value->type = result_type;
26783 return result;27746 return result;
26784 }27747 }
2678527748
26786 IrInstruction *result;
26787 if (safety_check_on && align_bytes > old_align_bytes && align_bytes != 1) {27749 if (safety_check_on && align_bytes > old_align_bytes && align_bytes != 1) {
26788 result = ir_build_align_cast(&ira->new_irb, target->scope, target->source_node, nullptr, target);27750 return ir_build_align_cast_gen(ira, target->base.scope, target->base.source_node, target, result_type);
26789 } else {27751 } else {
26790 result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, result_type, target, CastOpNoop);27752 return ir_build_cast(ira, &target->base, result_type, target, CastOpNoop);
26791 }27753 }
26792 result->value->type = result_type;
26793 return result;
26794}27754}
2679527755
26796static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr,27756static IrInstGen *ir_analyze_ptr_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *ptr,
26797 ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on)27757 IrInst *ptr_src, ZigType *dest_type, IrInst *dest_type_src, bool safety_check_on)
26798{27758{
26799 Error err;27759 Error err;
2680027760
...@@ -26810,52 +27770,52 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_...@@ -26810,52 +27770,52 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2681027770
26811 ZigType *src_ptr_type = get_src_ptr_type(src_type);27771 ZigType *src_ptr_type = get_src_ptr_type(src_type);
26812 if (src_ptr_type == nullptr) {27772 if (src_ptr_type == nullptr) {
26813 ir_add_error(ira, ptr, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));27773 ir_add_error(ira, ptr_src, buf_sprintf("expected pointer, found '%s'", buf_ptr(&src_type->name)));
26814 return ira->codegen->invalid_instruction;27774 return ira->codegen->invalid_inst_gen;
26815 }27775 }
2681627776
26817 ZigType *dest_ptr_type = get_src_ptr_type(dest_type);27777 ZigType *dest_ptr_type = get_src_ptr_type(dest_type);
26818 if (dest_ptr_type == nullptr) {27778 if (dest_ptr_type == nullptr) {
26819 ir_add_error(ira, dest_type_src,27779 ir_add_error(ira, dest_type_src,
26820 buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));27780 buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
26821 return ira->codegen->invalid_instruction;27781 return ira->codegen->invalid_inst_gen;
26822 }27782 }
2682327783
26824 if (get_ptr_const(src_type) && !get_ptr_const(dest_type)) {27784 if (get_ptr_const(src_type) && !get_ptr_const(dest_type)) {
26825 ir_add_error(ira, source_instr, buf_sprintf("cast discards const qualifier"));27785 ir_add_error(ira, source_instr, buf_sprintf("cast discards const qualifier"));
26826 return ira->codegen->invalid_instruction;27786 return ira->codegen->invalid_inst_gen;
26827 }27787 }
26828 uint32_t src_align_bytes;27788 uint32_t src_align_bytes;
26829 if ((err = resolve_ptr_align(ira, src_type, &src_align_bytes)))27789 if ((err = resolve_ptr_align(ira, src_type, &src_align_bytes)))
26830 return ira->codegen->invalid_instruction;27790 return ira->codegen->invalid_inst_gen;
2683127791
26832 uint32_t dest_align_bytes;27792 uint32_t dest_align_bytes;
26833 if ((err = resolve_ptr_align(ira, dest_type, &dest_align_bytes)))27793 if ((err = resolve_ptr_align(ira, dest_type, &dest_align_bytes)))
26834 return ira->codegen->invalid_instruction;27794 return ira->codegen->invalid_inst_gen;
2683527795
26836 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))27796 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))
26837 return ira->codegen->invalid_instruction;27797 return ira->codegen->invalid_inst_gen;
2683827798
26839 if ((err = type_resolve(ira->codegen, src_type, ResolveStatusZeroBitsKnown)))27799 if ((err = type_resolve(ira->codegen, src_type, ResolveStatusZeroBitsKnown)))
26840 return ira->codegen->invalid_instruction;27800 return ira->codegen->invalid_inst_gen;
2684127801
26842 if (type_has_bits(dest_type) && !type_has_bits(src_type)) {27802 if (type_has_bits(dest_type) && !type_has_bits(src_type) && safety_check_on) {
26843 ErrorMsg *msg = ir_add_error(ira, source_instr,27803 ErrorMsg *msg = ir_add_error(ira, source_instr,
26844 buf_sprintf("'%s' and '%s' do not have the same in-memory representation",27804 buf_sprintf("'%s' and '%s' do not have the same in-memory representation",
26845 buf_ptr(&src_type->name), buf_ptr(&dest_type->name)));27805 buf_ptr(&src_type->name), buf_ptr(&dest_type->name)));
26846 add_error_note(ira->codegen, msg, ptr->source_node,27806 add_error_note(ira->codegen, msg, ptr_src->source_node,
26847 buf_sprintf("'%s' has no in-memory bits", buf_ptr(&src_type->name)));27807 buf_sprintf("'%s' has no in-memory bits", buf_ptr(&src_type->name)));
26848 add_error_note(ira->codegen, msg, dest_type_src->source_node,27808 add_error_note(ira->codegen, msg, dest_type_src->source_node,
26849 buf_sprintf("'%s' has in-memory bits", buf_ptr(&dest_type->name)));27809 buf_sprintf("'%s' has in-memory bits", buf_ptr(&dest_type->name)));
26850 return ira->codegen->invalid_instruction;27810 return ira->codegen->invalid_inst_gen;
26851 }27811 }
2685227812
26853 if (instr_is_comptime(ptr)) {27813 if (instr_is_comptime(ptr)) {
26854 bool dest_allows_addr_zero = ptr_allows_addr_zero(dest_type);27814 bool dest_allows_addr_zero = ptr_allows_addr_zero(dest_type);
26855 UndefAllowed is_undef_allowed = dest_allows_addr_zero ? UndefOk : UndefBad;27815 UndefAllowed is_undef_allowed = dest_allows_addr_zero ? UndefOk : UndefBad;
26856 ZigValue *val = ir_resolve_const(ira, ptr, is_undef_allowed);27816 ZigValue *val = ir_resolve_const(ira, ptr, is_undef_allowed);
26857 if (!val)27817 if (val == nullptr)
26858 return ira->codegen->invalid_instruction;27818 return ira->codegen->invalid_inst_gen;
2685927819
26860 if (value_is_comptime(val) && val->special != ConstValSpecialUndef) {27820 if (value_is_comptime(val) && val->special != ConstValSpecialUndef) {
26861 bool is_addr_zero = val->data.x_ptr.special == ConstPtrSpecialNull ||27821 bool is_addr_zero = val->data.x_ptr.special == ConstPtrSpecialNull ||
...@@ -26864,20 +27824,36 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_...@@ -26864,20 +27824,36 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
26864 if (is_addr_zero && !dest_allows_addr_zero) {27824 if (is_addr_zero && !dest_allows_addr_zero) {
26865 ir_add_error(ira, source_instr,27825 ir_add_error(ira, source_instr,
26866 buf_sprintf("null pointer casted to type '%s'", buf_ptr(&dest_type->name)));27826 buf_sprintf("null pointer casted to type '%s'", buf_ptr(&dest_type->name)));
26867 return ira->codegen->invalid_instruction;27827 return ira->codegen->invalid_inst_gen;
26868 }27828 }
26869 }27829 }
2687027830
26871 IrInstruction *result;27831 IrInstGen *result;
26872 if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) {27832 if (val->data.x_ptr.mut == ConstPtrMutInfer) {
26873 result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);27833 result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);
26874
26875 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))
26876 return ira->codegen->invalid_instruction;
26877 } else {27834 } else {
26878 result = ir_const(ira, source_instr, dest_type);27835 result = ir_const(ira, source_instr, dest_type);
26879 }27836 }
26880 copy_const_val(result->value, val);27837 InferredStructField *isf = (val->type->id == ZigTypeIdPointer) ?
27838 val->type->data.pointer.inferred_struct_field : nullptr;
27839 if (isf == nullptr) {
27840 copy_const_val(result->value, val);
27841 } else {
27842 // The destination value should have x_ptr struct pointing to underlying struct value
27843 result->value->data.x_ptr.mut = val->data.x_ptr.mut;
27844 TypeStructField *field = find_struct_type_field(isf->inferred_struct_type, isf->field_name);
27845 assert(field != nullptr);
27846 if (field->is_comptime) {
27847 result->value->data.x_ptr.special = ConstPtrSpecialRef;
27848 result->value->data.x_ptr.data.ref.pointee = field->init_val;
27849 } else {
27850 assert(val->data.x_ptr.special == ConstPtrSpecialRef);
27851 result->value->data.x_ptr.special = ConstPtrSpecialBaseStruct;
27852 result->value->data.x_ptr.data.base_struct.struct_val = val->data.x_ptr.data.ref.pointee;
27853 result->value->data.x_ptr.data.base_struct.field_index = field->src_index;
27854 }
27855 result->value->special = ConstValSpecialStatic;
27856 }
26881 result->value->type = dest_type;27857 result->value->type = dest_type;
2688227858
26883 // Keep the bigger alignment, it can only help-27859 // Keep the bigger alignment, it can only help-
...@@ -26891,41 +27867,41 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_...@@ -26891,41 +27867,41 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_
2689127867
26892 if (dest_align_bytes > src_align_bytes) {27868 if (dest_align_bytes > src_align_bytes) {
26893 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment"));27869 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("cast increases pointer alignment"));
26894 add_error_note(ira->codegen, msg, ptr->source_node,27870 add_error_note(ira->codegen, msg, ptr_src->source_node,
26895 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_type->name), src_align_bytes));27871 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&src_type->name), src_align_bytes));
26896 add_error_note(ira->codegen, msg, dest_type_src->source_node,27872 add_error_note(ira->codegen, msg, dest_type_src->source_node,
26897 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&dest_type->name), dest_align_bytes));27873 buf_sprintf("'%s' has alignment %" PRIu32, buf_ptr(&dest_type->name), dest_align_bytes));
26898 return ira->codegen->invalid_instruction;27874 return ira->codegen->invalid_inst_gen;
26899 }27875 }
2690027876
26901 IrInstruction *casted_ptr = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);27877 IrInstGen *casted_ptr = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on);
2690227878
26903 // Keep the bigger alignment, it can only help-27879 // Keep the bigger alignment, it can only help-
26904 // unless the target is zero bits.27880 // unless the target is zero bits.
26905 IrInstruction *result;27881 IrInstGen *result;
26906 if (src_align_bytes > dest_align_bytes && type_has_bits(dest_type)) {27882 if (src_align_bytes > dest_align_bytes && type_has_bits(dest_type)) {
26907 result = ir_align_cast(ira, casted_ptr, src_align_bytes, false);27883 result = ir_align_cast(ira, casted_ptr, src_align_bytes, false);
26908 if (type_is_invalid(result->value->type))27884 if (type_is_invalid(result->value->type))
26909 return ira->codegen->invalid_instruction;27885 return ira->codegen->invalid_inst_gen;
26910 } else {27886 } else {
26911 result = casted_ptr;27887 result = casted_ptr;
26912 }27888 }
26913 return result;27889 return result;
26914}27890}
2691527891
26916static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCastSrc *instruction) {27892static IrInstGen *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstSrcPtrCast *instruction) {
26917 IrInstruction *dest_type_value = instruction->dest_type->child;27893 IrInstGen *dest_type_value = instruction->dest_type->child;
26918 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);27894 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
26919 if (type_is_invalid(dest_type))27895 if (type_is_invalid(dest_type))
26920 return ira->codegen->invalid_instruction;27896 return ira->codegen->invalid_inst_gen;
2692127897
26922 IrInstruction *ptr = instruction->ptr->child;27898 IrInstGen *ptr = instruction->ptr->child;
26923 ZigType *src_type = ptr->value->type;27899 ZigType *src_type = ptr->value->type;
26924 if (type_is_invalid(src_type))27900 if (type_is_invalid(src_type))
26925 return ira->codegen->invalid_instruction;27901 return ira->codegen->invalid_inst_gen;
2692627902
26927 return ir_analyze_ptr_cast(ira, &instruction->base, ptr, dest_type, dest_type_value,27903 return ir_analyze_ptr_cast(ira, &instruction->base.base, ptr, &instruction->ptr->base,
26928 instruction->safety_check_on);27904 dest_type, &dest_type_value->base, instruction->safety_check_on);
26929}27905}
2693027906
26931static void buf_write_value_bytes_array(CodeGen *codegen, uint8_t *buf, ZigValue *val, size_t len) {27907static void buf_write_value_bytes_array(CodeGen *codegen, uint8_t *buf, ZigValue *val, size_t len) {
...@@ -27255,7 +28231,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou...@@ -27255,7 +28231,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
27255 zig_unreachable();28231 zig_unreachable();
27256}28232}
2725728233
27258static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,28234static IrInstGen *ir_analyze_bit_cast(IrAnalyze *ira, IrInst* source_instr, IrInstGen *value,
27259 ZigType *dest_type)28235 ZigType *dest_type)
27260{28236{
27261 Error err;28237 Error err;
...@@ -27271,14 +28247,14 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_...@@ -27271,14 +28247,14 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
27271 buf_sprintf("cannot cast a value of type '%s'", buf_ptr(&dest_type->name)));28247 buf_sprintf("cannot cast a value of type '%s'", buf_ptr(&dest_type->name)));
27272 add_error_note(ira->codegen, msg, source_instr->source_node,28248 add_error_note(ira->codegen, msg, source_instr->source_node,
27273 buf_sprintf("use @intToEnum for type coercion"));28249 buf_sprintf("use @intToEnum for type coercion"));
27274 return ira->codegen->invalid_instruction;28250 return ira->codegen->invalid_inst_gen;
27275 }28251 }
2727628252
27277 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusSizeKnown)))28253 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusSizeKnown)))
27278 return ira->codegen->invalid_instruction;28254 return ira->codegen->invalid_inst_gen;
2727928255
27280 if ((err = type_resolve(ira->codegen, src_type, ResolveStatusSizeKnown)))28256 if ((err = type_resolve(ira->codegen, src_type, ResolveStatusSizeKnown)))
27281 return ira->codegen->invalid_instruction;28257 return ira->codegen->invalid_inst_gen;
2728228258
27283 uint64_t dest_size_bytes = type_size(ira->codegen, dest_type);28259 uint64_t dest_size_bytes = type_size(ira->codegen, dest_type);
27284 uint64_t src_size_bytes = type_size(ira->codegen, src_type);28260 uint64_t src_size_bytes = type_size(ira->codegen, src_type);
...@@ -27287,7 +28263,7 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_...@@ -27287,7 +28263,7 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
27287 buf_sprintf("destination type '%s' has size %" ZIG_PRI_u64 " but source type '%s' has size %" ZIG_PRI_u64,28263 buf_sprintf("destination type '%s' has size %" ZIG_PRI_u64 " but source type '%s' has size %" ZIG_PRI_u64,
27288 buf_ptr(&dest_type->name), dest_size_bytes,28264 buf_ptr(&dest_type->name), dest_size_bytes,
27289 buf_ptr(&src_type->name), src_size_bytes));28265 buf_ptr(&src_type->name), src_size_bytes));
27290 return ira->codegen->invalid_instruction;28266 return ira->codegen->invalid_inst_gen;
27291 }28267 }
2729228268
27293 uint64_t dest_size_bits = type_size_bits(ira->codegen, dest_type);28269 uint64_t dest_size_bits = type_size_bits(ira->codegen, dest_type);
...@@ -27297,26 +28273,26 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_...@@ -27297,26 +28273,26 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_
27297 buf_sprintf("destination type '%s' has %" ZIG_PRI_u64 " bits but source type '%s' has %" ZIG_PRI_u64 " bits",28273 buf_sprintf("destination type '%s' has %" ZIG_PRI_u64 " bits but source type '%s' has %" ZIG_PRI_u64 " bits",
27298 buf_ptr(&dest_type->name), dest_size_bits,28274 buf_ptr(&dest_type->name), dest_size_bits,
27299 buf_ptr(&src_type->name), src_size_bits));28275 buf_ptr(&src_type->name), src_size_bits));
27300 return ira->codegen->invalid_instruction;28276 return ira->codegen->invalid_inst_gen;
27301 }28277 }
2730228278
27303 if (instr_is_comptime(value)) {28279 if (instr_is_comptime(value)) {
27304 ZigValue *val = ir_resolve_const(ira, value, UndefBad);28280 ZigValue *val = ir_resolve_const(ira, value, UndefBad);
27305 if (!val)28281 if (!val)
27306 return ira->codegen->invalid_instruction;28282 return ira->codegen->invalid_inst_gen;
2730728283
27308 IrInstruction *result = ir_const(ira, source_instr, dest_type);28284 IrInstGen *result = ir_const(ira, source_instr, dest_type);
27309 uint8_t *buf = allocate_nonzero<uint8_t>(src_size_bytes);28285 uint8_t *buf = allocate_nonzero<uint8_t>(src_size_bytes);
27310 buf_write_value_bytes(ira->codegen, buf, val);28286 buf_write_value_bytes(ira->codegen, buf, val);
27311 if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value)))28287 if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value)))
27312 return ira->codegen->invalid_instruction;28288 return ira->codegen->invalid_inst_gen;
27313 return result;28289 return result;
27314 }28290 }
2731528291
27316 return ir_build_bit_cast_gen(ira, source_instr, value, dest_type);28292 return ir_build_bit_cast_gen(ira, source_instr, value, dest_type);
27317}28293}
2731828294
27319static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target,28295static IrInstGen *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInst* source_instr, IrInstGen *target,
27320 ZigType *ptr_type)28296 ZigType *ptr_type)
27321{28297{
27322 Error err;28298 Error err;
...@@ -27324,136 +28300,128 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc...@@ -27324,136 +28300,128 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc
27324 ir_assert(get_src_ptr_type(ptr_type) != nullptr, source_instr);28300 ir_assert(get_src_ptr_type(ptr_type) != nullptr, source_instr);
27325 ir_assert(type_has_bits(ptr_type), source_instr);28301 ir_assert(type_has_bits(ptr_type), source_instr);
2732628302
27327 IrInstruction *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize);28303 IrInstGen *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize);
27328 if (type_is_invalid(casted_int->value->type))28304 if (type_is_invalid(casted_int->value->type))
27329 return ira->codegen->invalid_instruction;28305 return ira->codegen->invalid_inst_gen;
2733028306
27331 if (instr_is_comptime(casted_int)) {28307 if (instr_is_comptime(casted_int)) {
27332 ZigValue *val = ir_resolve_const(ira, casted_int, UndefBad);28308 ZigValue *val = ir_resolve_const(ira, casted_int, UndefBad);
27333 if (!val)28309 if (!val)
27334 return ira->codegen->invalid_instruction;28310 return ira->codegen->invalid_inst_gen;
2733528311
27336 uint64_t addr = bigint_as_u64(&val->data.x_bigint);28312 uint64_t addr = bigint_as_u64(&val->data.x_bigint);
27337 if (!ptr_allows_addr_zero(ptr_type) && addr == 0) {28313 if (!ptr_allows_addr_zero(ptr_type) && addr == 0) {
27338 ir_add_error(ira, source_instr,28314 ir_add_error(ira, source_instr,
27339 buf_sprintf("pointer type '%s' does not allow address zero", buf_ptr(&ptr_type->name)));28315 buf_sprintf("pointer type '%s' does not allow address zero", buf_ptr(&ptr_type->name)));
27340 return ira->codegen->invalid_instruction;28316 return ira->codegen->invalid_inst_gen;
27341 }28317 }
2734228318
27343 uint32_t align_bytes;28319 uint32_t align_bytes;
27344 if ((err = resolve_ptr_align(ira, ptr_type, &align_bytes)))28320 if ((err = resolve_ptr_align(ira, ptr_type, &align_bytes)))
27345 return ira->codegen->invalid_instruction;28321 return ira->codegen->invalid_inst_gen;
2734628322
27347 if (addr != 0 && addr % align_bytes != 0) {28323 if (addr != 0 && addr % align_bytes != 0) {
27348 ir_add_error(ira, source_instr,28324 ir_add_error(ira, source_instr,
27349 buf_sprintf("pointer type '%s' requires aligned address",28325 buf_sprintf("pointer type '%s' requires aligned address",
27350 buf_ptr(&ptr_type->name)));28326 buf_ptr(&ptr_type->name)));
27351 return ira->codegen->invalid_instruction;28327 return ira->codegen->invalid_inst_gen;
27352 }28328 }
2735328329
27354 IrInstruction *result = ir_const(ira, source_instr, ptr_type);28330 IrInstGen *result = ir_const(ira, source_instr, ptr_type);
27355 result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;28331 result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr;
27356 result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;28332 result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar;
27357 result->value->data.x_ptr.data.hard_coded_addr.addr = addr;28333 result->value->data.x_ptr.data.hard_coded_addr.addr = addr;
27358 return result;28334 return result;
27359 }28335 }
2736028336
27361 IrInstruction *result = ir_build_int_to_ptr(&ira->new_irb, source_instr->scope,28337 return ir_build_int_to_ptr_gen(ira, source_instr->scope, source_instr->source_node, casted_int, ptr_type);
27362 source_instr->source_node, nullptr, casted_int);
27363 result->value->type = ptr_type;
27364 return result;
27365}28338}
2736628339
27367static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionIntToPtr *instruction) {28340static IrInstGen *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstSrcIntToPtr *instruction) {
27368 Error err;28341 Error err;
27369 IrInstruction *dest_type_value = instruction->dest_type->child;28342 IrInstGen *dest_type_value = instruction->dest_type->child;
27370 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);28343 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
27371 if (type_is_invalid(dest_type))28344 if (type_is_invalid(dest_type))
27372 return ira->codegen->invalid_instruction;28345 return ira->codegen->invalid_inst_gen;
2737328346
27374 // We explicitly check for the size, so we can use get_src_ptr_type28347 // We explicitly check for the size, so we can use get_src_ptr_type
27375 if (get_src_ptr_type(dest_type) == nullptr) {28348 if (get_src_ptr_type(dest_type) == nullptr) {
27376 ir_add_error(ira, dest_type_value, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));28349 ir_add_error(ira, &dest_type_value->base, buf_sprintf("expected pointer, found '%s'", buf_ptr(&dest_type->name)));
27377 return ira->codegen->invalid_instruction;28350 return ira->codegen->invalid_inst_gen;
27378 }28351 }
2737928352
27380 bool has_bits;28353 bool has_bits;
27381 if ((err = type_has_bits2(ira->codegen, dest_type, &has_bits)))28354 if ((err = type_has_bits2(ira->codegen, dest_type, &has_bits)))
27382 return ira->codegen->invalid_instruction;28355 return ira->codegen->invalid_inst_gen;
2738328356
27384 if (!has_bits) {28357 if (!has_bits) {
27385 ir_add_error(ira, dest_type_value,28358 ir_add_error(ira, &dest_type_value->base,
27386 buf_sprintf("type '%s' has 0 bits and cannot store information", buf_ptr(&dest_type->name)));28359 buf_sprintf("type '%s' has 0 bits and cannot store information", buf_ptr(&dest_type->name)));
27387 return ira->codegen->invalid_instruction;28360 return ira->codegen->invalid_inst_gen;
27388 }28361 }
2738928362
27390 IrInstruction *target = instruction->target->child;28363 IrInstGen *target = instruction->target->child;
27391 if (type_is_invalid(target->value->type))28364 if (type_is_invalid(target->value->type))
27392 return ira->codegen->invalid_instruction;28365 return ira->codegen->invalid_inst_gen;
2739328366
27394 return ir_analyze_int_to_ptr(ira, &instruction->base, target, dest_type);28367 return ir_analyze_int_to_ptr(ira, &instruction->base.base, target, dest_type);
27395}28368}
2739628369
27397static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira,28370static IrInstGen *ir_analyze_instruction_decl_ref(IrAnalyze *ira, IrInstSrcDeclRef *instruction) {
27398 IrInstructionDeclRef *instruction)28371 IrInstGen *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base.base, instruction->tld);
27399{
27400 IrInstruction *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base, instruction->tld);
27401 if (type_is_invalid(ref_instruction->value->type)) {28372 if (type_is_invalid(ref_instruction->value->type)) {
27402 return ira->codegen->invalid_instruction;28373 return ira->codegen->invalid_inst_gen;
27403 }28374 }
2740428375
27405 if (instruction->lval == LValPtr) {28376 if (instruction->lval == LValPtr) {
27406 return ref_instruction;28377 return ref_instruction;
27407 } else {28378 } else {
27408 return ir_get_deref(ira, &instruction->base, ref_instruction, nullptr);28379 return ir_get_deref(ira, &instruction->base.base, ref_instruction, nullptr);
27409 }28380 }
27410}28381}
2741128382
27412static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) {28383static IrInstGen *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstSrcPtrToInt *instruction) {
27413 Error err;28384 Error err;
27414 IrInstruction *target = instruction->target->child;28385 IrInstGen *target = instruction->target->child;
27415 if (type_is_invalid(target->value->type))28386 if (type_is_invalid(target->value->type))
27416 return ira->codegen->invalid_instruction;28387 return ira->codegen->invalid_inst_gen;
2741728388
27418 ZigType *usize = ira->codegen->builtin_types.entry_usize;28389 ZigType *usize = ira->codegen->builtin_types.entry_usize;
2741928390
27420 // We check size explicitly so we can use get_src_ptr_type here.28391 // We check size explicitly so we can use get_src_ptr_type here.
27421 if (get_src_ptr_type(target->value->type) == nullptr) {28392 if (get_src_ptr_type(target->value->type) == nullptr) {
27422 ir_add_error(ira, target,28393 ir_add_error(ira, &target->base,
27423 buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value->type->name)));28394 buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value->type->name)));
27424 return ira->codegen->invalid_instruction;28395 return ira->codegen->invalid_inst_gen;
27425 }28396 }
2742628397
27427 bool has_bits;28398 bool has_bits;
27428 if ((err = type_has_bits2(ira->codegen, target->value->type, &has_bits)))28399 if ((err = type_has_bits2(ira->codegen, target->value->type, &has_bits)))
27429 return ira->codegen->invalid_instruction;28400 return ira->codegen->invalid_inst_gen;
2743028401
27431 if (!has_bits) {28402 if (!has_bits) {
27432 ir_add_error(ira, target,28403 ir_add_error(ira, &target->base,
27433 buf_sprintf("pointer to size 0 type has no address"));28404 buf_sprintf("pointer to size 0 type has no address"));
27434 return ira->codegen->invalid_instruction;28405 return ira->codegen->invalid_inst_gen;
27435 }28406 }
2743628407
27437 if (instr_is_comptime(target)) {28408 if (instr_is_comptime(target)) {
27438 ZigValue *val = ir_resolve_const(ira, target, UndefBad);28409 ZigValue *val = ir_resolve_const(ira, target, UndefBad);
27439 if (!val)28410 if (!val)
27440 return ira->codegen->invalid_instruction;28411 return ira->codegen->invalid_inst_gen;
27441 if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {28412 if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
27442 IrInstruction *result = ir_const(ira, &instruction->base, usize);28413 IrInstGen *result = ir_const(ira, &instruction->base.base, usize);
27443 bigint_init_unsigned(&result->value->data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr);28414 bigint_init_unsigned(&result->value->data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr);
27444 result->value->type = usize;28415 result->value->type = usize;
27445 return result;28416 return result;
27446 }28417 }
27447 }28418 }
2744828419
27449 IrInstruction *result = ir_build_ptr_to_int(&ira->new_irb, instruction->base.scope,28420 return ir_build_ptr_to_int_gen(ira, &instruction->base.base, target);
27450 instruction->base.source_node, target);
27451 result->value->type = usize;
27452 return result;
27453}28421}
2745428422
27455static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) {28423static IrInstGen *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstSrcPtrType *instruction) {
27456 IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type);28424 IrInstGen *result = ir_const(ira, &instruction->base.base, ira->codegen->builtin_types.entry_type);
27457 result->value->special = ConstValSpecialLazy;28425 result->value->special = ConstValSpecialLazy;
2745828426
27459 LazyValuePtrType *lazy_ptr_type = allocate<LazyValuePtrType>(1, "LazyValuePtrType");28427 LazyValuePtrType *lazy_ptr_type = allocate<LazyValuePtrType>(1, "LazyValuePtrType");
...@@ -27464,17 +28432,17 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct...@@ -27464,17 +28432,17 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct
27464 if (instruction->sentinel != nullptr) {28432 if (instruction->sentinel != nullptr) {
27465 lazy_ptr_type->sentinel = instruction->sentinel->child;28433 lazy_ptr_type->sentinel = instruction->sentinel->child;
27466 if (ir_resolve_const(ira, lazy_ptr_type->sentinel, LazyOk) == nullptr)28434 if (ir_resolve_const(ira, lazy_ptr_type->sentinel, LazyOk) == nullptr)
27467 return ira->codegen->invalid_instruction;28435 return ira->codegen->invalid_inst_gen;
27468 }28436 }
2746928437
27470 lazy_ptr_type->elem_type = instruction->child_type->child;28438 lazy_ptr_type->elem_type = instruction->child_type->child;
27471 if (ir_resolve_type_lazy(ira, lazy_ptr_type->elem_type) == nullptr)28439 if (ir_resolve_type_lazy(ira, lazy_ptr_type->elem_type) == nullptr)
27472 return ira->codegen->invalid_instruction;28440 return ira->codegen->invalid_inst_gen;
2747328441
27474 if (instruction->align_value != nullptr) {28442 if (instruction->align_value != nullptr) {
27475 lazy_ptr_type->align_inst = instruction->align_value->child;28443 lazy_ptr_type->align_inst = instruction->align_value->child;
27476 if (ir_resolve_const(ira, lazy_ptr_type->align_inst, LazyOk) == nullptr)28444 if (ir_resolve_const(ira, lazy_ptr_type->align_inst, LazyOk) == nullptr)
27477 return ira->codegen->invalid_instruction;28445 return ira->codegen->invalid_inst_gen;
27478 }28446 }
2747928447
27480 lazy_ptr_type->ptr_len = instruction->ptr_len;28448 lazy_ptr_type->ptr_len = instruction->ptr_len;
...@@ -27487,10 +28455,10 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct...@@ -27487,10 +28455,10 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct
27487 return result;28455 return result;
27488}28456}
2748928457
27490static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) {28458static IrInstGen *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstSrcAlignCast *instruction) {
27491 IrInstruction *target = instruction->target->child;28459 IrInstGen *target = instruction->target->child;
27492 if (type_is_invalid(target->value->type))28460 if (type_is_invalid(target->value->type))
27493 return ira->codegen->invalid_instruction;28461 return ira->codegen->invalid_inst_gen;
2749428462
27495 ZigType *elem_type = nullptr;28463 ZigType *elem_type = nullptr;
27496 if (is_slice(target->value->type)) {28464 if (is_slice(target->value->type)) {
...@@ -27501,192 +28469,192 @@ static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstru...@@ -27501,192 +28469,192 @@ static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstru
27501 }28469 }
2750228470
27503 uint32_t align_bytes;28471 uint32_t align_bytes;
27504 IrInstruction *align_bytes_inst = instruction->align_bytes->child;28472 IrInstGen *align_bytes_inst = instruction->align_bytes->child;
27505 if (!ir_resolve_align(ira, align_bytes_inst, elem_type, &align_bytes))28473 if (!ir_resolve_align(ira, align_bytes_inst, elem_type, &align_bytes))
27506 return ira->codegen->invalid_instruction;28474 return ira->codegen->invalid_inst_gen;
2750728475
27508 IrInstruction *result = ir_align_cast(ira, target, align_bytes, true);28476 IrInstGen *result = ir_align_cast(ira, target, align_bytes, true);
27509 if (type_is_invalid(result->value->type))28477 if (type_is_invalid(result->value->type))
27510 return ira->codegen->invalid_instruction;28478 return ira->codegen->invalid_inst_gen;
2751128479
27512 return result;28480 return result;
27513}28481}
2751428482
27515static IrInstruction *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) {28483static IrInstGen *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstSrcOpaqueType *instruction) {
27516 Buf *bare_name = buf_alloc();28484 Buf *bare_name = buf_alloc();
27517 Buf *full_name = get_anon_type_name(ira->codegen, ira->new_irb.exec, "opaque",28485 Buf *full_name = get_anon_type_name(ira->codegen, ira->old_irb.exec, "opaque",
27518 instruction->base.scope, instruction->base.source_node, bare_name);28486 instruction->base.base.scope, instruction->base.base.source_node, bare_name);
27519 ZigType *result_type = get_opaque_type(ira->codegen, instruction->base.scope, instruction->base.source_node,28487 ZigType *result_type = get_opaque_type(ira->codegen, instruction->base.base.scope,
27520 buf_ptr(full_name), bare_name);28488 instruction->base.base.source_node, buf_ptr(full_name), bare_name);
27521 return ir_const_type(ira, &instruction->base, result_type);28489 return ir_const_type(ira, &instruction->base.base, result_type);
27522}28490}
2752328491
27524static IrInstruction *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstructionSetAlignStack *instruction) {28492static IrInstGen *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstSrcSetAlignStack *instruction) {
27525 uint32_t align_bytes;28493 uint32_t align_bytes;
27526 IrInstruction *align_bytes_inst = instruction->align_bytes->child;28494 IrInstGen *align_bytes_inst = instruction->align_bytes->child;
27527 if (!ir_resolve_align(ira, align_bytes_inst, nullptr, &align_bytes))28495 if (!ir_resolve_align(ira, align_bytes_inst, nullptr, &align_bytes))
27528 return ira->codegen->invalid_instruction;28496 return ira->codegen->invalid_inst_gen;
2752928497
27530 if (align_bytes > 256) {28498 if (align_bytes > 256) {
27531 ir_add_error(ira, &instruction->base, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes));28499 ir_add_error(ira, &instruction->base.base, buf_sprintf("attempt to @setAlignStack(%" PRIu32 "); maximum is 256", align_bytes));
27532 return ira->codegen->invalid_instruction;28500 return ira->codegen->invalid_inst_gen;
27533 }28501 }
2753428502
27535 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);28503 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
27536 if (fn_entry == nullptr) {28504 if (fn_entry == nullptr) {
27537 ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack outside function"));28505 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack outside function"));
27538 return ira->codegen->invalid_instruction;28506 return ira->codegen->invalid_inst_gen;
27539 }28507 }
27540 if (fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionNaked) {28508 if (fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionNaked) {
27541 ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack in naked function"));28509 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack in naked function"));
27542 return ira->codegen->invalid_instruction;28510 return ira->codegen->invalid_inst_gen;
27543 }28511 }
2754428512
27545 if (fn_entry->fn_inline == FnInlineAlways) {28513 if (fn_entry->fn_inline == FnInlineAlways) {
27546 ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack in inline function"));28514 ir_add_error(ira, &instruction->base.base, buf_sprintf("@setAlignStack in inline function"));
27547 return ira->codegen->invalid_instruction;28515 return ira->codegen->invalid_inst_gen;
27548 }28516 }
2754928517
27550 if (fn_entry->set_alignstack_node != nullptr) {28518 if (fn_entry->set_alignstack_node != nullptr) {
27551 ErrorMsg *msg = ir_add_error_node(ira, instruction->base.source_node,28519 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
27552 buf_sprintf("alignstack set twice"));28520 buf_sprintf("alignstack set twice"));
27553 add_error_note(ira->codegen, msg, fn_entry->set_alignstack_node, buf_sprintf("first set here"));28521 add_error_note(ira->codegen, msg, fn_entry->set_alignstack_node, buf_sprintf("first set here"));
27554 return ira->codegen->invalid_instruction;28522 return ira->codegen->invalid_inst_gen;
27555 }28523 }
2755628524
27557 fn_entry->set_alignstack_node = instruction->base.source_node;28525 fn_entry->set_alignstack_node = instruction->base.base.source_node;
27558 fn_entry->alignstack_value = align_bytes;28526 fn_entry->alignstack_value = align_bytes;
2755928527
27560 return ir_const_void(ira, &instruction->base);28528 return ir_const_void(ira, &instruction->base.base);
27561}28529}
2756228530
27563static IrInstruction *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) {28531static IrInstGen *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstSrcArgType *instruction) {
27564 IrInstruction *fn_type_inst = instruction->fn_type->child;28532 IrInstGen *fn_type_inst = instruction->fn_type->child;
27565 ZigType *fn_type = ir_resolve_type(ira, fn_type_inst);28533 ZigType *fn_type = ir_resolve_type(ira, fn_type_inst);
27566 if (type_is_invalid(fn_type))28534 if (type_is_invalid(fn_type))
27567 return ira->codegen->invalid_instruction;28535 return ira->codegen->invalid_inst_gen;
2756828536
27569 IrInstruction *arg_index_inst = instruction->arg_index->child;28537 IrInstGen *arg_index_inst = instruction->arg_index->child;
27570 uint64_t arg_index;28538 uint64_t arg_index;
27571 if (!ir_resolve_usize(ira, arg_index_inst, &arg_index))28539 if (!ir_resolve_usize(ira, arg_index_inst, &arg_index))
27572 return ira->codegen->invalid_instruction;28540 return ira->codegen->invalid_inst_gen;
2757328541
27574 if (fn_type->id == ZigTypeIdBoundFn) {28542 if (fn_type->id == ZigTypeIdBoundFn) {
27575 fn_type = fn_type->data.bound_fn.fn_type;28543 fn_type = fn_type->data.bound_fn.fn_type;
27576 arg_index += 1;28544 arg_index += 1;
27577 }28545 }
27578 if (fn_type->id != ZigTypeIdFn) {28546 if (fn_type->id != ZigTypeIdFn) {
27579 ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));28547 ir_add_error(ira, &fn_type_inst->base, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name)));
27580 return ira->codegen->invalid_instruction;28548 return ira->codegen->invalid_inst_gen;
27581 }28549 }
2758228550
27583 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;28551 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
27584 if (arg_index >= fn_type_id->param_count) {28552 if (arg_index >= fn_type_id->param_count) {
27585 if (instruction->allow_var) {28553 if (instruction->allow_var) {
27586 // TODO remove this with var args28554 // TODO remove this with var args
27587 return ir_const_type(ira, &instruction->base, ira->codegen->builtin_types.entry_var);28555 return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_var);
27588 }28556 }
27589 ir_add_error(ira, arg_index_inst,28557 ir_add_error(ira, &arg_index_inst->base,
27590 buf_sprintf("arg index %" ZIG_PRI_u64 " out of bounds; '%s' has %" ZIG_PRI_usize " arguments",28558 buf_sprintf("arg index %" ZIG_PRI_u64 " out of bounds; '%s' has %" ZIG_PRI_usize " arguments",
27591 arg_index, buf_ptr(&fn_type->name), fn_type_id->param_count));28559 arg_index, buf_ptr(&fn_type->name), fn_type_id->param_count));
27592 return ira->codegen->invalid_instruction;28560 return ira->codegen->invalid_inst_gen;
27593 }28561 }
2759428562
27595 ZigType *result_type = fn_type_id->param_info[arg_index].type;28563 ZigType *result_type = fn_type_id->param_info[arg_index].type;
27596 if (result_type == nullptr) {28564 if (result_type == nullptr) {
27597 // Args are only unresolved if our function is generic.28565 // Args are only unresolved if our function is generic.
27598 ir_assert(fn_type->data.fn.is_generic, &instruction->base);28566 ir_assert(fn_type->data.fn.is_generic, &instruction->base.base);
2759928567
27600 if (instruction->allow_var) {28568 if (instruction->allow_var) {
27601 return ir_const_type(ira, &instruction->base, ira->codegen->builtin_types.entry_var);28569 return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_var);
27602 } else {28570 } else {
27603 ir_add_error(ira, arg_index_inst,28571 ir_add_error(ira, &arg_index_inst->base,
27604 buf_sprintf("@ArgType could not resolve the type of arg %" ZIG_PRI_u64 " because '%s' is generic",28572 buf_sprintf("@ArgType could not resolve the type of arg %" ZIG_PRI_u64 " because '%s' is generic",
27605 arg_index, buf_ptr(&fn_type->name)));28573 arg_index, buf_ptr(&fn_type->name)));
27606 return ira->codegen->invalid_instruction;28574 return ira->codegen->invalid_inst_gen;
27607 }28575 }
27608 }28576 }
27609 return ir_const_type(ira, &instruction->base, result_type);28577 return ir_const_type(ira, &instruction->base.base, result_type);
27610}28578}
2761128579
27612static IrInstruction *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) {28580static IrInstGen *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstSrcTagType *instruction) {
27613 Error err;28581 Error err;
27614 IrInstruction *target_inst = instruction->target->child;28582 IrInstGen *target_inst = instruction->target->child;
27615 ZigType *enum_type = ir_resolve_type(ira, target_inst);28583 ZigType *enum_type = ir_resolve_type(ira, target_inst);
27616 if (type_is_invalid(enum_type))28584 if (type_is_invalid(enum_type))
27617 return ira->codegen->invalid_instruction;28585 return ira->codegen->invalid_inst_gen;
2761828586
27619 if (enum_type->id == ZigTypeIdEnum) {28587 if (enum_type->id == ZigTypeIdEnum) {
27620 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusSizeKnown)))28588 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusSizeKnown)))
27621 return ira->codegen->invalid_instruction;28589 return ira->codegen->invalid_inst_gen;
2762228590
27623 return ir_const_type(ira, &instruction->base, enum_type->data.enumeration.tag_int_type);28591 return ir_const_type(ira, &instruction->base.base, enum_type->data.enumeration.tag_int_type);
27624 } else if (enum_type->id == ZigTypeIdUnion) {28592 } else if (enum_type->id == ZigTypeIdUnion) {
27625 ZigType *tag_type = ir_resolve_union_tag_type(ira, instruction->target, enum_type);28593 ZigType *tag_type = ir_resolve_union_tag_type(ira, instruction->target->base.source_node, enum_type);
27626 if (type_is_invalid(tag_type))28594 if (type_is_invalid(tag_type))
27627 return ira->codegen->invalid_instruction;28595 return ira->codegen->invalid_inst_gen;
27628 return ir_const_type(ira, &instruction->base, tag_type);28596 return ir_const_type(ira, &instruction->base.base, tag_type);
27629 } else {28597 } else {
27630 ir_add_error(ira, target_inst, buf_sprintf("expected enum or union, found '%s'",28598 ir_add_error(ira, &target_inst->base, buf_sprintf("expected enum or union, found '%s'",
27631 buf_ptr(&enum_type->name)));28599 buf_ptr(&enum_type->name)));
27632 return ira->codegen->invalid_instruction;28600 return ira->codegen->invalid_inst_gen;
27633 }28601 }
27634}28602}
2763528603
27636static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) {28604static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstGen *op) {
27637 ZigType *operand_type = ir_resolve_type(ira, op);28605 ZigType *operand_type = ir_resolve_type(ira, op);
27638 if (type_is_invalid(operand_type))28606 if (type_is_invalid(operand_type))
27639 return ira->codegen->builtin_types.entry_invalid;28607 return ira->codegen->builtin_types.entry_invalid;
2764028608
27641 if (operand_type->id == ZigTypeIdInt) {28609 if (operand_type->id == ZigTypeIdInt) {
27642 if (operand_type->data.integral.bit_count < 8) {28610 if (operand_type->data.integral.bit_count < 8) {
27643 ir_add_error(ira, op,28611 ir_add_error(ira, &op->base,
27644 buf_sprintf("expected integer type 8 bits or larger, found %" PRIu32 "-bit integer type",28612 buf_sprintf("expected integer type 8 bits or larger, found %" PRIu32 "-bit integer type",
27645 operand_type->data.integral.bit_count));28613 operand_type->data.integral.bit_count));
27646 return ira->codegen->builtin_types.entry_invalid;28614 return ira->codegen->builtin_types.entry_invalid;
27647 }28615 }
27648 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);28616 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);
27649 if (operand_type->data.integral.bit_count > max_atomic_bits) {28617 if (operand_type->data.integral.bit_count > max_atomic_bits) {
27650 ir_add_error(ira, op,28618 ir_add_error(ira, &op->base,
27651 buf_sprintf("expected %" PRIu32 "-bit integer type or smaller, found %" PRIu32 "-bit integer type",28619 buf_sprintf("expected %" PRIu32 "-bit integer type or smaller, found %" PRIu32 "-bit integer type",
27652 max_atomic_bits, operand_type->data.integral.bit_count));28620 max_atomic_bits, operand_type->data.integral.bit_count));
27653 return ira->codegen->builtin_types.entry_invalid;28621 return ira->codegen->builtin_types.entry_invalid;
27654 }28622 }
27655 if (!is_power_of_2(operand_type->data.integral.bit_count)) {28623 if (!is_power_of_2(operand_type->data.integral.bit_count)) {
27656 ir_add_error(ira, op,28624 ir_add_error(ira, &op->base,
27657 buf_sprintf("%" PRIu32 "-bit integer type is not a power of 2", operand_type->data.integral.bit_count));28625 buf_sprintf("%" PRIu32 "-bit integer type is not a power of 2", operand_type->data.integral.bit_count));
27658 return ira->codegen->builtin_types.entry_invalid;28626 return ira->codegen->builtin_types.entry_invalid;
27659 }28627 }
27660 } else if (operand_type->id == ZigTypeIdEnum) {28628 } else if (operand_type->id == ZigTypeIdEnum) {
27661 ZigType *int_type = operand_type->data.enumeration.tag_int_type;28629 ZigType *int_type = operand_type->data.enumeration.tag_int_type;
27662 if (int_type->data.integral.bit_count < 8) {28630 if (int_type->data.integral.bit_count < 8) {
27663 ir_add_error(ira, op,28631 ir_add_error(ira, &op->base,
27664 buf_sprintf("expected enum tag type 8 bits or larger, found %" PRIu32 "-bit tag type",28632 buf_sprintf("expected enum tag type 8 bits or larger, found %" PRIu32 "-bit tag type",
27665 int_type->data.integral.bit_count));28633 int_type->data.integral.bit_count));
27666 return ira->codegen->builtin_types.entry_invalid;28634 return ira->codegen->builtin_types.entry_invalid;
27667 }28635 }
27668 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);28636 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);
27669 if (int_type->data.integral.bit_count > max_atomic_bits) {28637 if (int_type->data.integral.bit_count > max_atomic_bits) {
27670 ir_add_error(ira, op,28638 ir_add_error(ira, &op->base,
27671 buf_sprintf("expected %" PRIu32 "-bit enum tag type or smaller, found %" PRIu32 "-bit tag type",28639 buf_sprintf("expected %" PRIu32 "-bit enum tag type or smaller, found %" PRIu32 "-bit tag type",
27672 max_atomic_bits, int_type->data.integral.bit_count));28640 max_atomic_bits, int_type->data.integral.bit_count));
27673 return ira->codegen->builtin_types.entry_invalid;28641 return ira->codegen->builtin_types.entry_invalid;
27674 }28642 }
27675 if (!is_power_of_2(int_type->data.integral.bit_count)) {28643 if (!is_power_of_2(int_type->data.integral.bit_count)) {
27676 ir_add_error(ira, op,28644 ir_add_error(ira, &op->base,
27677 buf_sprintf("%" PRIu32 "-bit enum tag type is not a power of 2", int_type->data.integral.bit_count));28645 buf_sprintf("%" PRIu32 "-bit enum tag type is not a power of 2", int_type->data.integral.bit_count));
27678 return ira->codegen->builtin_types.entry_invalid;28646 return ira->codegen->builtin_types.entry_invalid;
27679 }28647 }
27680 } else if (operand_type->id == ZigTypeIdFloat) {28648 } else if (operand_type->id == ZigTypeIdFloat) {
27681 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);28649 uint32_t max_atomic_bits = target_arch_largest_atomic_bits(ira->codegen->zig_target->arch);
27682 if (operand_type->data.floating.bit_count > max_atomic_bits) {28650 if (operand_type->data.floating.bit_count > max_atomic_bits) {
27683 ir_add_error(ira, op,28651 ir_add_error(ira, &op->base,
27684 buf_sprintf("expected %" PRIu32 "-bit float or smaller, found %" PRIu32 "-bit float",28652 buf_sprintf("expected %" PRIu32 "-bit float or smaller, found %" PRIu32 "-bit float",
27685 max_atomic_bits, (uint32_t) operand_type->data.floating.bit_count));28653 max_atomic_bits, (uint32_t) operand_type->data.floating.bit_count));
27686 return ira->codegen->builtin_types.entry_invalid;28654 return ira->codegen->builtin_types.entry_invalid;
27687 }28655 }
27688 } else if (get_codegen_ptr_type(operand_type) == nullptr) {28656 } else if (get_codegen_ptr_type(operand_type) == nullptr) {
27689 ir_add_error(ira, op,28657 ir_add_error(ira, &op->base,
27690 buf_sprintf("expected integer, float, enum or pointer type, found '%s'", buf_ptr(&operand_type->name)));28658 buf_sprintf("expected integer, float, enum or pointer type, found '%s'", buf_ptr(&operand_type->name)));
27691 return ira->codegen->builtin_types.entry_invalid;28659 return ira->codegen->builtin_types.entry_invalid;
27692 }28660 }
...@@ -27694,172 +28662,146 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op...@@ -27694,172 +28662,146 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op
27694 return operand_type;28662 return operand_type;
27695}28663}
2769628664
27697static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionAtomicRmw *instruction) {28665static IrInstGen *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstSrcAtomicRmw *instruction) {
27698 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child);28666 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child);
27699 if (type_is_invalid(operand_type))28667 if (type_is_invalid(operand_type))
27700 return ira->codegen->invalid_instruction;28668 return ira->codegen->invalid_inst_gen;
2770128669
27702 IrInstruction *ptr_inst = instruction->ptr->child;28670 IrInstGen *ptr_inst = instruction->ptr->child;
27703 if (type_is_invalid(ptr_inst->value->type))28671 if (type_is_invalid(ptr_inst->value->type))
27704 return ira->codegen->invalid_instruction;28672 return ira->codegen->invalid_inst_gen;
2770528673
27706 // TODO let this be volatile28674 // TODO let this be volatile
27707 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);28675 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
27708 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);28676 IrInstGen *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
27709 if (type_is_invalid(casted_ptr->value->type))28677 if (type_is_invalid(casted_ptr->value->type))
27710 return ira->codegen->invalid_instruction;28678 return ira->codegen->invalid_inst_gen;
2771128679
27712 AtomicRmwOp op;28680 AtomicRmwOp op;
27713 if (instruction->op == nullptr) {28681 if (!ir_resolve_atomic_rmw_op(ira, instruction->op->child, &op)) {
27714 op = instruction->resolved_op;28682 return ira->codegen->invalid_inst_gen;
27715 } else {
27716 if (!ir_resolve_atomic_rmw_op(ira, instruction->op->child, &op)) {
27717 return ira->codegen->invalid_instruction;
27718 }
27719 }28683 }
2772028684
27721 if (operand_type->id == ZigTypeIdEnum && op != AtomicRmwOp_xchg) {28685 if (operand_type->id == ZigTypeIdEnum && op != AtomicRmwOp_xchg) {
27722 ir_add_error(ira, instruction->op,28686 ir_add_error(ira, &instruction->op->base,
27723 buf_sprintf("@atomicRmw on enum only works with .Xchg"));28687 buf_sprintf("@atomicRmw on enum only works with .Xchg"));
27724 return ira->codegen->invalid_instruction;28688 return ira->codegen->invalid_inst_gen;
27725 } else if (operand_type->id == ZigTypeIdFloat && op > AtomicRmwOp_sub) {28689 } else if (operand_type->id == ZigTypeIdFloat && op > AtomicRmwOp_sub) {
27726 ir_add_error(ira, instruction->op,28690 ir_add_error(ira, &instruction->op->base,
27727 buf_sprintf("@atomicRmw with float only works with .Xchg, .Add and .Sub"));28691 buf_sprintf("@atomicRmw with float only works with .Xchg, .Add and .Sub"));
27728 return ira->codegen->invalid_instruction;28692 return ira->codegen->invalid_inst_gen;
27729 }28693 }
2773028694
27731 IrInstruction *operand = instruction->operand->child;28695 IrInstGen *operand = instruction->operand->child;
27732 if (type_is_invalid(operand->value->type))28696 if (type_is_invalid(operand->value->type))
27733 return ira->codegen->invalid_instruction;28697 return ira->codegen->invalid_inst_gen;
2773428698
27735 IrInstruction *casted_operand = ir_implicit_cast(ira, operand, operand_type);28699 IrInstGen *casted_operand = ir_implicit_cast(ira, operand, operand_type);
27736 if (type_is_invalid(casted_operand->value->type))28700 if (type_is_invalid(casted_operand->value->type))
27737 return ira->codegen->invalid_instruction;28701 return ira->codegen->invalid_inst_gen;
2773828702
27739 AtomicOrder ordering;28703 AtomicOrder ordering;
27740 if (instruction->ordering == nullptr) {28704 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
27741 ordering = instruction->resolved_ordering;28705 return ira->codegen->invalid_inst_gen;
27742 } else {28706 if (ordering == AtomicOrderUnordered) {
27743 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))28707 ir_add_error(ira, &instruction->ordering->base,
27744 return ira->codegen->invalid_instruction;28708 buf_sprintf("@atomicRmw atomic ordering must not be Unordered"));
27745 if (ordering == AtomicOrderUnordered) {28709 return ira->codegen->invalid_inst_gen;
27746 ir_add_error(ira, instruction->ordering,
27747 buf_sprintf("@atomicRmw atomic ordering must not be Unordered"));
27748 return ira->codegen->invalid_instruction;
27749 }
27750 }28710 }
2775128711
27752 if (instr_is_comptime(casted_operand) && instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar)28712 if (instr_is_comptime(casted_operand) && instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar)
27753 {28713 {
27754 zig_panic("TODO compile-time execution of atomicRmw");28714 ir_add_error(ira, &instruction->base.base,
28715 buf_sprintf("compiler bug: TODO compile-time execution of @atomicRmw"));
28716 return ira->codegen->invalid_inst_gen;
27755 }28717 }
2775628718
27757 IrInstruction *result = ir_build_atomic_rmw(&ira->new_irb, instruction->base.scope,28719 return ir_build_atomic_rmw_gen(ira, &instruction->base.base, casted_ptr, casted_operand, op,
27758 instruction->base.source_node, nullptr, casted_ptr, nullptr, casted_operand, nullptr,28720 ordering, operand_type);
27759 op, ordering);
27760 result->value->type = operand_type;
27761 return result;
27762}28721}
2776328722
27764static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstructionAtomicLoad *instruction) {28723static IrInstGen *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstSrcAtomicLoad *instruction) {
27765 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child);28724 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child);
27766 if (type_is_invalid(operand_type))28725 if (type_is_invalid(operand_type))
27767 return ira->codegen->invalid_instruction;28726 return ira->codegen->invalid_inst_gen;
2776828727
27769 IrInstruction *ptr_inst = instruction->ptr->child;28728 IrInstGen *ptr_inst = instruction->ptr->child;
27770 if (type_is_invalid(ptr_inst->value->type))28729 if (type_is_invalid(ptr_inst->value->type))
27771 return ira->codegen->invalid_instruction;28730 return ira->codegen->invalid_inst_gen;
2777228731
27773 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true);28732 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true);
27774 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);28733 IrInstGen *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
27775 if (type_is_invalid(casted_ptr->value->type))28734 if (type_is_invalid(casted_ptr->value->type))
27776 return ira->codegen->invalid_instruction;28735 return ira->codegen->invalid_inst_gen;
2777728736
27778 AtomicOrder ordering;28737 AtomicOrder ordering;
27779 if (instruction->ordering == nullptr) {28738 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
27780 ordering = instruction->resolved_ordering;28739 return ira->codegen->invalid_inst_gen;
27781 } else {
27782 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
27783 return ira->codegen->invalid_instruction;
27784 }
2778528740
27786 if (ordering == AtomicOrderRelease || ordering == AtomicOrderAcqRel) {28741 if (ordering == AtomicOrderRelease || ordering == AtomicOrderAcqRel) {
27787 ir_assert(instruction->ordering != nullptr, &instruction->base);28742 ir_assert(instruction->ordering != nullptr, &instruction->base.base);
27788 ir_add_error(ira, instruction->ordering,28743 ir_add_error(ira, &instruction->ordering->base,
27789 buf_sprintf("@atomicLoad atomic ordering must not be Release or AcqRel"));28744 buf_sprintf("@atomicLoad atomic ordering must not be Release or AcqRel"));
27790 return ira->codegen->invalid_instruction;28745 return ira->codegen->invalid_inst_gen;
27791 }28746 }
2779228747
27793 if (instr_is_comptime(casted_ptr)) {28748 if (instr_is_comptime(casted_ptr)) {
27794 IrInstruction *result = ir_get_deref(ira, &instruction->base, casted_ptr, nullptr);28749 IrInstGen *result = ir_get_deref(ira, &instruction->base.base, casted_ptr, nullptr);
27795 ir_assert(result->value->type != nullptr, &instruction->base);28750 ir_assert(result->value->type != nullptr, &instruction->base.base);
27796 return result;28751 return result;
27797 }28752 }
2779828753
27799 IrInstruction *result = ir_build_atomic_load(&ira->new_irb, instruction->base.scope,28754 return ir_build_atomic_load_gen(ira, &instruction->base.base, casted_ptr, ordering, operand_type);
27800 instruction->base.source_node, nullptr, casted_ptr, nullptr, ordering);
27801 result->value->type = operand_type;
27802 return result;
27803}28755}
2780428756
27805static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstructionAtomicStore *instruction) {28757static IrInstGen *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInstSrcAtomicStore *instruction) {
27806 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child);28758 ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->child);
27807 if (type_is_invalid(operand_type))28759 if (type_is_invalid(operand_type))
27808 return ira->codegen->invalid_instruction;28760 return ira->codegen->invalid_inst_gen;
2780928761
27810 IrInstruction *ptr_inst = instruction->ptr->child;28762 IrInstGen *ptr_inst = instruction->ptr->child;
27811 if (type_is_invalid(ptr_inst->value->type))28763 if (type_is_invalid(ptr_inst->value->type))
27812 return ira->codegen->invalid_instruction;28764 return ira->codegen->invalid_inst_gen;
2781328765
27814 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);28766 ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false);
27815 IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);28767 IrInstGen *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type);
27816 if (type_is_invalid(casted_ptr->value->type))28768 if (type_is_invalid(casted_ptr->value->type))
27817 return ira->codegen->invalid_instruction;28769 return ira->codegen->invalid_inst_gen;
2781828770
27819 IrInstruction *value = instruction->value->child;28771 IrInstGen *value = instruction->value->child;
27820 if (type_is_invalid(value->value->type))28772 if (type_is_invalid(value->value->type))
27821 return ira->codegen->invalid_instruction;28773 return ira->codegen->invalid_inst_gen;
2782228774
27823 IrInstruction *casted_value = ir_implicit_cast(ira, value, operand_type);28775 IrInstGen *casted_value = ir_implicit_cast(ira, value, operand_type);
27824 if (type_is_invalid(casted_value->value->type))28776 if (type_is_invalid(casted_value->value->type))
27825 return ira->codegen->invalid_instruction;28777 return ira->codegen->invalid_inst_gen;
2782628778
2782728779
27828 AtomicOrder ordering;28780 AtomicOrder ordering;
27829 if (instruction->ordering == nullptr) {28781 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
27830 ordering = instruction->resolved_ordering;28782 return ira->codegen->invalid_inst_gen;
27831 } else {
27832 if (!ir_resolve_atomic_order(ira, instruction->ordering->child, &ordering))
27833 return ira->codegen->invalid_instruction;
27834 }
2783528783
27836 if (ordering == AtomicOrderAcquire || ordering == AtomicOrderAcqRel) {28784 if (ordering == AtomicOrderAcquire || ordering == AtomicOrderAcqRel) {
27837 ir_assert(instruction->ordering != nullptr, &instruction->base);28785 ir_assert(instruction->ordering != nullptr, &instruction->base.base);
27838 ir_add_error(ira, instruction->ordering,28786 ir_add_error(ira, &instruction->ordering->base,
27839 buf_sprintf("@atomicStore atomic ordering must not be Acquire or AcqRel"));28787 buf_sprintf("@atomicStore atomic ordering must not be Acquire or AcqRel"));
27840 return ira->codegen->invalid_instruction;28788 return ira->codegen->invalid_inst_gen;
27841 }28789 }
2784228790
27843 if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) {28791 if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) {
27844 IrInstruction *result = ir_analyze_store_ptr(ira, &instruction->base, casted_ptr, value, false);28792 IrInstGen *result = ir_analyze_store_ptr(ira, &instruction->base.base, casted_ptr, value, false);
27845 result->value->type = ira->codegen->builtin_types.entry_void;28793 result->value->type = ira->codegen->builtin_types.entry_void;
27846 return result;28794 return result;
27847 }28795 }
2784828796
27849 IrInstruction *result = ir_build_atomic_store(&ira->new_irb, instruction->base.scope,28797 return ir_build_atomic_store_gen(ira, &instruction->base.base, casted_ptr, casted_value, ordering);
27850 instruction->base.source_node, nullptr, casted_ptr, casted_value, nullptr, ordering);
27851 result->value->type = ira->codegen->builtin_types.entry_void;
27852 return result;
27853}28798}
2785428799
27855static IrInstruction *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) {28800static IrInstGen *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstSrcSaveErrRetAddr *instruction) {
27856 IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope,28801 return ir_build_save_err_ret_addr_gen(ira, &instruction->base.base);
27857 instruction->base.source_node);
27858 result->value->type = ira->codegen->builtin_types.entry_void;
27859 return result;
27860}28802}
2786128803
27862static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInstruction *source_instr, BuiltinFnId fop, ZigType *float_type,28804static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInst* source_instr, BuiltinFnId fop, ZigType *float_type,
27863 ZigValue *op, ZigValue *out_val)28805 ZigValue *op, ZigValue *out_val)
27864{28806{
27865 assert(ira && source_instr && float_type && out_val && op);28807 assert(ira && source_instr && float_type && out_val && op);
...@@ -28072,30 +29014,30 @@ static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInstruction *source_instr, B...@@ -28072,30 +29014,30 @@ static ErrorMsg *ir_eval_float_op(IrAnalyze *ira, IrInstruction *source_instr, B
28072 return nullptr;29014 return nullptr;
28073}29015}
2807429016
28075static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstructionFloatOp *instruction) {29017static IrInstGen *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstSrcFloatOp *instruction) {
28076 IrInstruction *operand = instruction->operand->child;29018 IrInstGen *operand = instruction->operand->child;
28077 ZigType *operand_type = operand->value->type;29019 ZigType *operand_type = operand->value->type;
28078 if (type_is_invalid(operand_type))29020 if (type_is_invalid(operand_type))
28079 return ira->codegen->invalid_instruction;29021 return ira->codegen->invalid_inst_gen;
2808029022
28081 // This instruction accepts floats and vectors of floats.29023 // This instruction accepts floats and vectors of floats.
28082 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ?29024 ZigType *scalar_type = (operand_type->id == ZigTypeIdVector) ?
28083 operand_type->data.vector.elem_type : operand_type;29025 operand_type->data.vector.elem_type : operand_type;
2808429026
28085 if (scalar_type->id != ZigTypeIdFloat && scalar_type->id != ZigTypeIdComptimeFloat) {29027 if (scalar_type->id != ZigTypeIdFloat && scalar_type->id != ZigTypeIdComptimeFloat) {
28086 ir_add_error(ira, operand,29028 ir_add_error(ira, &operand->base,
28087 buf_sprintf("expected float type, found '%s'", buf_ptr(&scalar_type->name)));29029 buf_sprintf("expected float type, found '%s'", buf_ptr(&scalar_type->name)));
28088 return ira->codegen->invalid_instruction;29030 return ira->codegen->invalid_inst_gen;
28089 }29031 }
2809029032
28091 if (instr_is_comptime(operand)) {29033 if (instr_is_comptime(operand)) {
28092 ZigValue *operand_val = ir_resolve_const(ira, operand, UndefOk);29034 ZigValue *operand_val = ir_resolve_const(ira, operand, UndefOk);
28093 if (operand_val == nullptr)29035 if (operand_val == nullptr)
28094 return ira->codegen->invalid_instruction;29036 return ira->codegen->invalid_inst_gen;
28095 if (operand_val->special == ConstValSpecialUndef)29037 if (operand_val->special == ConstValSpecialUndef)
28096 return ir_const_undef(ira, &instruction->base, operand_type);29038 return ir_const_undef(ira, &instruction->base.base, operand_type);
2809729039
28098 IrInstruction *result = ir_const(ira, &instruction->base, operand_type);29040 IrInstGen *result = ir_const(ira, &instruction->base.base, operand_type);
28099 ZigValue *out_val = result->value;29041 ZigValue *out_val = result->value;
2810029042
28101 if (operand_type->id == ZigTypeIdVector) {29043 if (operand_type->id == ZigTypeIdVector) {
...@@ -28106,47 +29048,44 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct...@@ -28106,47 +29048,44 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct
28106 for (size_t i = 0; i < len; i += 1) {29048 for (size_t i = 0; i < len; i += 1) {
28107 ZigValue *elem_operand = &operand_val->data.x_array.data.s_none.elements[i];29049 ZigValue *elem_operand = &operand_val->data.x_array.data.s_none.elements[i];
28108 ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i];29050 ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i];
28109 ir_assert(elem_operand->type == scalar_type, &instruction->base);29051 ir_assert(elem_operand->type == scalar_type, &instruction->base.base);
28110 ir_assert(float_out_val->type == scalar_type, &instruction->base);29052 ir_assert(float_out_val->type == scalar_type, &instruction->base.base);
28111 ErrorMsg *msg = ir_eval_float_op(ira, &instruction->base, instruction->fn_id, scalar_type,29053 ErrorMsg *msg = ir_eval_float_op(ira, &instruction->base.base, instruction->fn_id, scalar_type,
28112 elem_operand, float_out_val);29054 elem_operand, float_out_val);
28113 if (msg != nullptr) {29055 if (msg != nullptr) {
28114 add_error_note(ira->codegen, msg, instruction->base.source_node,29056 add_error_note(ira->codegen, msg, instruction->base.base.source_node,
28115 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));29057 buf_sprintf("when computing vector element at index %" ZIG_PRI_usize, i));
28116 return ira->codegen->invalid_instruction;29058 return ira->codegen->invalid_inst_gen;
28117 }29059 }
28118 float_out_val->type = scalar_type;29060 float_out_val->type = scalar_type;
28119 }29061 }
28120 out_val->type = operand_type;29062 out_val->type = operand_type;
28121 out_val->special = ConstValSpecialStatic;29063 out_val->special = ConstValSpecialStatic;
28122 } else {29064 } else {
28123 if (ir_eval_float_op(ira, &instruction->base, instruction->fn_id, scalar_type,29065 if (ir_eval_float_op(ira, &instruction->base.base, instruction->fn_id, scalar_type,
28124 operand_val, out_val) != nullptr)29066 operand_val, out_val) != nullptr)
28125 {29067 {
28126 return ira->codegen->invalid_instruction;29068 return ira->codegen->invalid_inst_gen;
28127 }29069 }
28128 }29070 }
28129 return result;29071 return result;
28130 }29072 }
2813129073
28132 ir_assert(scalar_type->id == ZigTypeIdFloat, &instruction->base);29074 ir_assert(scalar_type->id == ZigTypeIdFloat, &instruction->base.base);
2813329075
28134 IrInstruction *result = ir_build_float_op(&ira->new_irb, instruction->base.scope,29076 return ir_build_float_op_gen(ira, &instruction->base.base, operand, instruction->fn_id, operand_type);
28135 instruction->base.source_node, operand, instruction->fn_id);
28136 result->value->type = operand_type;
28137 return result;
28138}29077}
2813929078
28140static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstructionBswap *instruction) {29079static IrInstGen *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstSrcBswap *instruction) {
28141 Error err;29080 Error err;
2814229081
28143 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);29082 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
28144 if (type_is_invalid(int_type))29083 if (type_is_invalid(int_type))
28145 return ira->codegen->invalid_instruction;29084 return ira->codegen->invalid_inst_gen;
2814629085
28147 IrInstruction *uncasted_op = instruction->op->child;29086 IrInstGen *uncasted_op = instruction->op->child;
28148 if (type_is_invalid(uncasted_op->value->type))29087 if (type_is_invalid(uncasted_op->value->type))
28149 return ira->codegen->invalid_instruction;29088 return ira->codegen->invalid_inst_gen;
2815029089
28151 uint32_t vector_len; // UINT32_MAX means not a vector29090 uint32_t vector_len; // UINT32_MAX means not a vector
28152 if (uncasted_op->value->type->id == ZigTypeIdArray &&29091 if (uncasted_op->value->type->id == ZigTypeIdArray &&
...@@ -28162,28 +29101,28 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction...@@ -28162,28 +29101,28 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
28162 bool is_vector = (vector_len != UINT32_MAX);29101 bool is_vector = (vector_len != UINT32_MAX);
28163 ZigType *op_type = is_vector ? get_vector_type(ira->codegen, vector_len, int_type) : int_type;29102 ZigType *op_type = is_vector ? get_vector_type(ira->codegen, vector_len, int_type) : int_type;
2816429103
28165 IrInstruction *op = ir_implicit_cast(ira, uncasted_op, op_type);29104 IrInstGen *op = ir_implicit_cast(ira, uncasted_op, op_type);
28166 if (type_is_invalid(op->value->type))29105 if (type_is_invalid(op->value->type))
28167 return ira->codegen->invalid_instruction;29106 return ira->codegen->invalid_inst_gen;
2816829107
28169 if (int_type->data.integral.bit_count == 8 || int_type->data.integral.bit_count == 0)29108 if (int_type->data.integral.bit_count == 8 || int_type->data.integral.bit_count == 0)
28170 return op;29109 return op;
2817129110
28172 if (int_type->data.integral.bit_count % 8 != 0) {29111 if (int_type->data.integral.bit_count % 8 != 0) {
28173 ir_add_error(ira, instruction->op,29112 ir_add_error(ira, &instruction->op->base,
28174 buf_sprintf("@byteSwap integer type '%s' has %" PRIu32 " bits which is not evenly divisible by 8",29113 buf_sprintf("@byteSwap integer type '%s' has %" PRIu32 " bits which is not evenly divisible by 8",
28175 buf_ptr(&int_type->name), int_type->data.integral.bit_count));29114 buf_ptr(&int_type->name), int_type->data.integral.bit_count));
28176 return ira->codegen->invalid_instruction;29115 return ira->codegen->invalid_inst_gen;
28177 }29116 }
2817829117
28179 if (instr_is_comptime(op)) {29118 if (instr_is_comptime(op)) {
28180 ZigValue *val = ir_resolve_const(ira, op, UndefOk);29119 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
28181 if (val == nullptr)29120 if (val == nullptr)
28182 return ira->codegen->invalid_instruction;29121 return ira->codegen->invalid_inst_gen;
28183 if (val->special == ConstValSpecialUndef)29122 if (val->special == ConstValSpecialUndef)
28184 return ir_const_undef(ira, &instruction->base, op_type);29123 return ir_const_undef(ira, &instruction->base.base, op_type);
2818529124
28186 IrInstruction *result = ir_const(ira, &instruction->base, op_type);29125 IrInstGen *result = ir_const(ira, &instruction->base.base, op_type);
28187 size_t buf_size = int_type->data.integral.bit_count / 8;29126 size_t buf_size = int_type->data.integral.bit_count / 8;
28188 uint8_t *buf = allocate_nonzero<uint8_t>(buf_size);29127 uint8_t *buf = allocate_nonzero<uint8_t>(buf_size);
28189 if (is_vector) {29128 if (is_vector) {
...@@ -28191,10 +29130,10 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction...@@ -28191,10 +29130,10 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
28191 result->value->data.x_array.data.s_none.elements = create_const_vals(op_type->data.vector.len);29130 result->value->data.x_array.data.s_none.elements = create_const_vals(op_type->data.vector.len);
28192 for (unsigned i = 0; i < op_type->data.vector.len; i += 1) {29131 for (unsigned i = 0; i < op_type->data.vector.len; i += 1) {
28193 ZigValue *op_elem_val = &val->data.x_array.data.s_none.elements[i];29132 ZigValue *op_elem_val = &val->data.x_array.data.s_none.elements[i];
28194 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.source_node,29133 if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.base.source_node,
28195 op_elem_val, UndefOk)))29134 op_elem_val, UndefOk)))
28196 {29135 {
28197 return ira->codegen->invalid_instruction;29136 return ira->codegen->invalid_inst_gen;
28198 }29137 }
28199 ZigValue *result_elem_val = &result->value->data.x_array.data.s_none.elements[i];29138 ZigValue *result_elem_val = &result->value->data.x_array.data.s_none.elements[i];
28200 result_elem_val->type = int_type;29139 result_elem_val->type = int_type;
...@@ -28216,23 +29155,20 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction...@@ -28216,23 +29155,20 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction
28216 return result;29155 return result;
28217 }29156 }
2821829157
28219 IrInstruction *result = ir_build_bswap(&ira->new_irb, instruction->base.scope,29158 return ir_build_bswap_gen(ira, &instruction->base.base, op_type, op);
28220 instruction->base.source_node, nullptr, op);
28221 result->value->type = op_type;
28222 return result;
28223}29159}
2822429160
28225static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstructionBitReverse *instruction) {29161static IrInstGen *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstSrcBitReverse *instruction) {
28226 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);29162 ZigType *int_type = ir_resolve_int_type(ira, instruction->type->child);
28227 if (type_is_invalid(int_type))29163 if (type_is_invalid(int_type))
28228 return ira->codegen->invalid_instruction;29164 return ira->codegen->invalid_inst_gen;
2822929165
28230 IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type);29166 IrInstGen *op = ir_implicit_cast(ira, instruction->op->child, int_type);
28231 if (type_is_invalid(op->value->type))29167 if (type_is_invalid(op->value->type))
28232 return ira->codegen->invalid_instruction;29168 return ira->codegen->invalid_inst_gen;
2823329169
28234 if (int_type->data.integral.bit_count == 0) {29170 if (int_type->data.integral.bit_count == 0) {
28235 IrInstruction *result = ir_const(ira, &instruction->base, int_type);29171 IrInstGen *result = ir_const(ira, &instruction->base.base, int_type);
28236 bigint_init_unsigned(&result->value->data.x_bigint, 0);29172 bigint_init_unsigned(&result->value->data.x_bigint, 0);
28237 return result;29173 return result;
28238 }29174 }
...@@ -28240,11 +29176,11 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr...@@ -28240,11 +29176,11 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr
28240 if (instr_is_comptime(op)) {29176 if (instr_is_comptime(op)) {
28241 ZigValue *val = ir_resolve_const(ira, op, UndefOk);29177 ZigValue *val = ir_resolve_const(ira, op, UndefOk);
28242 if (val == nullptr)29178 if (val == nullptr)
28243 return ira->codegen->invalid_instruction;29179 return ira->codegen->invalid_inst_gen;
28244 if (val->special == ConstValSpecialUndef)29180 if (val->special == ConstValSpecialUndef)
28245 return ir_const_undef(ira, &instruction->base, int_type);29181 return ir_const_undef(ira, &instruction->base.base, int_type);
2824629182
28247 IrInstruction *result = ir_const(ira, &instruction->base, int_type);29183 IrInstGen *result = ir_const(ira, &instruction->base.base, int_type);
28248 size_t num_bits = int_type->data.integral.bit_count;29184 size_t num_bits = int_type->data.integral.bit_count;
28249 size_t buf_size = (num_bits + 7) / 8;29185 size_t buf_size = (num_bits + 7) / 8;
28250 uint8_t *comptime_buf = allocate_nonzero<uint8_t>(buf_size);29186 uint8_t *comptime_buf = allocate_nonzero<uint8_t>(buf_size);
...@@ -28271,128 +29207,125 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr...@@ -28271,128 +29207,125 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr
28271 return result;29207 return result;
28272 }29208 }
2827329209
28274 IrInstruction *result = ir_build_bit_reverse(&ira->new_irb, instruction->base.scope,29210 return ir_build_bit_reverse_gen(ira, &instruction->base.base, int_type, op);
28275 instruction->base.source_node, nullptr, op);
28276 result->value->type = int_type;
28277 return result;
28278}29211}
2827929212
2828029213
28281static IrInstruction *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) {29214static IrInstGen *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstSrcEnumToInt *instruction) {
28282 IrInstruction *target = instruction->target->child;29215 IrInstGen *target = instruction->target->child;
28283 if (type_is_invalid(target->value->type))29216 if (type_is_invalid(target->value->type))
28284 return ira->codegen->invalid_instruction;29217 return ira->codegen->invalid_inst_gen;
2828529218
28286 return ir_analyze_enum_to_int(ira, &instruction->base, target);29219 return ir_analyze_enum_to_int(ira, &instruction->base.base, target);
28287}29220}
2828829221
28289static IrInstruction *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstructionIntToEnum *instruction) {29222static IrInstGen *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstSrcIntToEnum *instruction) {
28290 Error err;29223 Error err;
28291 IrInstruction *dest_type_value = instruction->dest_type->child;29224 IrInstGen *dest_type_value = instruction->dest_type->child;
28292 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);29225 ZigType *dest_type = ir_resolve_type(ira, dest_type_value);
28293 if (type_is_invalid(dest_type))29226 if (type_is_invalid(dest_type))
28294 return ira->codegen->invalid_instruction;29227 return ira->codegen->invalid_inst_gen;
2829529228
28296 if (dest_type->id != ZigTypeIdEnum) {29229 if (dest_type->id != ZigTypeIdEnum) {
28297 ir_add_error(ira, instruction->dest_type,29230 ir_add_error(ira, &instruction->dest_type->base,
28298 buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name)));29231 buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name)));
28299 return ira->codegen->invalid_instruction;29232 return ira->codegen->invalid_inst_gen;
28300 }29233 }
2830129234
28302 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))29235 if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown)))
28303 return ira->codegen->invalid_instruction;29236 return ira->codegen->invalid_inst_gen;
2830429237
28305 ZigType *tag_type = dest_type->data.enumeration.tag_int_type;29238 ZigType *tag_type = dest_type->data.enumeration.tag_int_type;
2830629239
28307 IrInstruction *target = instruction->target->child;29240 IrInstGen *target = instruction->target->child;
28308 if (type_is_invalid(target->value->type))29241 if (type_is_invalid(target->value->type))
28309 return ira->codegen->invalid_instruction;29242 return ira->codegen->invalid_inst_gen;
2831029243
28311 IrInstruction *casted_target = ir_implicit_cast(ira, target, tag_type);29244 IrInstGen *casted_target = ir_implicit_cast(ira, target, tag_type);
28312 if (type_is_invalid(casted_target->value->type))29245 if (type_is_invalid(casted_target->value->type))
28313 return ira->codegen->invalid_instruction;29246 return ira->codegen->invalid_inst_gen;
2831429247
28315 return ir_analyze_int_to_enum(ira, &instruction->base, casted_target, dest_type);29248 return ir_analyze_int_to_enum(ira, &instruction->base.base, casted_target, dest_type);
28316}29249}
2831729250
28318static IrInstruction *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstructionCheckRuntimeScope *instruction) {29251static IrInstGen *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstSrcCheckRuntimeScope *instruction) {
28319 IrInstruction *block_comptime_inst = instruction->scope_is_comptime->child;29252 IrInstGen *block_comptime_inst = instruction->scope_is_comptime->child;
28320 bool scope_is_comptime;29253 bool scope_is_comptime;
28321 if (!ir_resolve_bool(ira, block_comptime_inst, &scope_is_comptime))29254 if (!ir_resolve_bool(ira, block_comptime_inst, &scope_is_comptime))
28322 return ira->codegen->invalid_instruction;29255 return ira->codegen->invalid_inst_gen;
2832329256
28324 IrInstruction *is_comptime_inst = instruction->is_comptime->child;29257 IrInstGen *is_comptime_inst = instruction->is_comptime->child;
28325 bool is_comptime;29258 bool is_comptime;
28326 if (!ir_resolve_bool(ira, is_comptime_inst, &is_comptime))29259 if (!ir_resolve_bool(ira, is_comptime_inst, &is_comptime))
28327 return ira->codegen->invalid_instruction;29260 return ira->codegen->invalid_inst_gen;
2832829261
28329 if (!scope_is_comptime && is_comptime) {29262 if (!scope_is_comptime && is_comptime) {
28330 ErrorMsg *msg = ir_add_error(ira, &instruction->base,29263 ErrorMsg *msg = ir_add_error(ira, &instruction->base.base,
28331 buf_sprintf("comptime control flow inside runtime block"));29264 buf_sprintf("comptime control flow inside runtime block"));
28332 add_error_note(ira->codegen, msg, block_comptime_inst->source_node,29265 add_error_note(ira->codegen, msg, block_comptime_inst->base.source_node,
28333 buf_sprintf("runtime block created here"));29266 buf_sprintf("runtime block created here"));
28334 return ira->codegen->invalid_instruction;29267 return ira->codegen->invalid_inst_gen;
28335 }29268 }
2833629269
28337 return ir_const_void(ira, &instruction->base);29270 return ir_const_void(ira, &instruction->base.base);
28338}29271}
2833929272
28340static IrInstruction *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstructionHasDecl *instruction) {29273static IrInstGen *ir_analyze_instruction_has_decl(IrAnalyze *ira, IrInstSrcHasDecl *instruction) {
28341 ZigType *container_type = ir_resolve_type(ira, instruction->container->child);29274 ZigType *container_type = ir_resolve_type(ira, instruction->container->child);
28342 if (type_is_invalid(container_type))29275 if (type_is_invalid(container_type))
28343 return ira->codegen->invalid_instruction;29276 return ira->codegen->invalid_inst_gen;
2834429277
28345 Buf *name = ir_resolve_str(ira, instruction->name->child);29278 Buf *name = ir_resolve_str(ira, instruction->name->child);
28346 if (name == nullptr)29279 if (name == nullptr)
28347 return ira->codegen->invalid_instruction;29280 return ira->codegen->invalid_inst_gen;
2834829281
28349 if (!is_container(container_type)) {29282 if (!is_container(container_type)) {
28350 ir_add_error(ira, instruction->container,29283 ir_add_error(ira, &instruction->container->base,
28351 buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&container_type->name)));29284 buf_sprintf("expected struct, enum, or union; found '%s'", buf_ptr(&container_type->name)));
28352 return ira->codegen->invalid_instruction;29285 return ira->codegen->invalid_inst_gen;
28353 }29286 }
2835429287
28355 ScopeDecls *container_scope = get_container_scope(container_type);29288 ScopeDecls *container_scope = get_container_scope(container_type);
28356 Tld *tld = find_container_decl(ira->codegen, container_scope, name);29289 Tld *tld = find_container_decl(ira->codegen, container_scope, name);
28357 if (tld == nullptr)29290 if (tld == nullptr)
28358 return ir_const_bool(ira, &instruction->base, false);29291 return ir_const_bool(ira, &instruction->base.base, false);
2835929292
28360 if (tld->visib_mod == VisibModPrivate && tld->import != get_scope_import(instruction->base.scope)) {29293 if (tld->visib_mod == VisibModPrivate && tld->import != get_scope_import(instruction->base.base.scope)) {
28361 return ir_const_bool(ira, &instruction->base, false);29294 return ir_const_bool(ira, &instruction->base.base, false);
28362 }29295 }
2836329296
28364 return ir_const_bool(ira, &instruction->base, true);29297 return ir_const_bool(ira, &instruction->base.base, true);
28365}29298}
2836629299
28367static IrInstruction *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, IrInstructionUndeclaredIdent *instruction) {29300static IrInstGen *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, IrInstSrcUndeclaredIdent *instruction) {
28368 // put a variable of same name with invalid type in global scope29301 // put a variable of same name with invalid type in global scope
28369 // so that future references to this same name will find a variable with an invalid type29302 // so that future references to this same name will find a variable with an invalid type
28370 populate_invalid_variable_in_scope(ira->codegen, instruction->base.scope, instruction->base.source_node,29303 populate_invalid_variable_in_scope(ira->codegen, instruction->base.base.scope,
28371 instruction->name);29304 instruction->base.base.source_node, instruction->name);
28372 ir_add_error(ira, &instruction->base,29305 ir_add_error(ira, &instruction->base.base,
28373 buf_sprintf("use of undeclared identifier '%s'", buf_ptr(instruction->name)));29306 buf_sprintf("use of undeclared identifier '%s'", buf_ptr(instruction->name)));
28374 return ira->codegen->invalid_instruction;29307 return ira->codegen->invalid_inst_gen;
28375}29308}
2837629309
28377static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstructionEndExpr *instruction) {29310static IrInstGen *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstSrcEndExpr *instruction) {
28378 IrInstruction *value = instruction->value->child;29311 IrInstGen *value = instruction->value->child;
28379 if (type_is_invalid(value->value->type))29312 if (type_is_invalid(value->value->type))
28380 return ira->codegen->invalid_instruction;29313 return ira->codegen->invalid_inst_gen;
2838129314
28382 bool was_written = instruction->result_loc->written;29315 bool was_written = instruction->result_loc->written;
28383 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,29316 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
28384 value->value->type, value, false, false, true);29317 value->value->type, value, false, true);
28385 if (result_loc != nullptr) {29318 if (result_loc != nullptr) {
28386 if (type_is_invalid(result_loc->value->type))29319 if (type_is_invalid(result_loc->value->type))
28387 return ira->codegen->invalid_instruction;29320 return ira->codegen->invalid_inst_gen;
28388 if (result_loc->value->type->id == ZigTypeIdUnreachable)29321 if (result_loc->value->type->id == ZigTypeIdUnreachable)
28389 return result_loc;29322 return result_loc;
2839029323
28391 if (!was_written || instruction->result_loc->id == ResultLocIdPeer) {29324 if (!was_written || instruction->result_loc->id == ResultLocIdPeer) {
28392 IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value,29325 IrInstGen *store_ptr = ir_analyze_store_ptr(ira, &instruction->base.base, result_loc, value,
28393 instruction->result_loc->allow_write_through_const);29326 instruction->result_loc->allow_write_through_const);
28394 if (type_is_invalid(store_ptr->value->type)) {29327 if (type_is_invalid(store_ptr->value->type)) {
28395 return ira->codegen->invalid_instruction;29328 return ira->codegen->invalid_inst_gen;
28396 }29329 }
28397 }29330 }
2839829331
...@@ -28407,106 +29340,100 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct...@@ -28407,106 +29340,100 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
28407 }29340 }
28408 }29341 }
2840929342
28410 return ir_const_void(ira, &instruction->base);29343 return ir_const_void(ira, &instruction->base.base);
28411}29344}
2841229345
28413static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) {29346static IrInstGen *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstSrcImplicitCast *instruction) {
28414 IrInstruction *operand = instruction->operand->child;29347 IrInstGen *operand = instruction->operand->child;
28415 if (type_is_invalid(operand->value->type))29348 if (type_is_invalid(operand->value->type))
28416 return operand;29349 return operand;
2841729350
28418 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base,
28419 &instruction->result_loc_cast->base, operand->value->type, operand, false, false, true);
28420 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))
28421 return result_loc;
28422
28423 ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child);29351 ZigType *dest_type = ir_resolve_type(ira, instruction->result_loc_cast->base.source_instruction->child);
28424 if (type_is_invalid(dest_type))29352 if (type_is_invalid(dest_type))
28425 return ira->codegen->invalid_instruction;29353 return ira->codegen->invalid_inst_gen;
28426 return ir_implicit_cast2(ira, &instruction->base, operand, dest_type);29354 return ir_implicit_cast2(ira, &instruction->base.base, operand, dest_type);
28427}29355}
2842829356
28429static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) {29357static IrInstGen *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstSrcBitCast *instruction) {
28430 IrInstruction *operand = instruction->operand->child;29358 IrInstGen *operand = instruction->operand->child;
28431 if (type_is_invalid(operand->value->type))29359 if (type_is_invalid(operand->value->type))
28432 return operand;29360 return operand;
2843329361
28434 IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base,29362 IrInstGen *result_loc = ir_resolve_result(ira, &instruction->base.base,
28435 &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, false, true);29363 &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, true);
28436 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))29364 if (result_loc != nullptr &&
29365 (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable))
29366 {
28437 return result_loc;29367 return result_loc;
28438
28439 if (instruction->result_loc_bit_cast->parent->gen_instruction != nullptr) {
28440 return instruction->result_loc_bit_cast->parent->gen_instruction;
28441 }29368 }
2844229369
28443 return result_loc;29370 ZigType *dest_type = ir_resolve_type(ira,
29371 instruction->result_loc_bit_cast->base.source_instruction->child);
29372 if (type_is_invalid(dest_type))
29373 return ira->codegen->invalid_inst_gen;
29374 return ir_analyze_bit_cast(ira, &instruction->base.base, operand, dest_type);
28444}29375}
2844529376
28446static IrInstruction *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira,29377static IrInstGen *ir_analyze_instruction_union_init_named_field(IrAnalyze *ira,
28447 IrInstructionUnionInitNamedField *instruction)29378 IrInstSrcUnionInitNamedField *instruction)
28448{29379{
28449 ZigType *union_type = ir_resolve_type(ira, instruction->union_type->child);29380 ZigType *union_type = ir_resolve_type(ira, instruction->union_type->child);
28450 if (type_is_invalid(union_type))29381 if (type_is_invalid(union_type))
28451 return ira->codegen->invalid_instruction;29382 return ira->codegen->invalid_inst_gen;
2845229383
28453 if (union_type->id != ZigTypeIdUnion) {29384 if (union_type->id != ZigTypeIdUnion) {
28454 ir_add_error(ira, instruction->union_type,29385 ir_add_error(ira, &instruction->union_type->base,
28455 buf_sprintf("non-union type '%s' passed to @unionInit", buf_ptr(&union_type->name)));29386 buf_sprintf("non-union type '%s' passed to @unionInit", buf_ptr(&union_type->name)));
28456 return ira->codegen->invalid_instruction;29387 return ira->codegen->invalid_inst_gen;
28457 }29388 }
2845829389
28459 Buf *field_name = ir_resolve_str(ira, instruction->field_name->child);29390 Buf *field_name = ir_resolve_str(ira, instruction->field_name->child);
28460 if (field_name == nullptr)29391 if (field_name == nullptr)
28461 return ira->codegen->invalid_instruction;29392 return ira->codegen->invalid_inst_gen;
2846229393
28463 IrInstruction *field_result_loc = instruction->field_result_loc->child;29394 IrInstGen *field_result_loc = instruction->field_result_loc->child;
28464 if (type_is_invalid(field_result_loc->value->type))29395 if (type_is_invalid(field_result_loc->value->type))
28465 return ira->codegen->invalid_instruction;29396 return ira->codegen->invalid_inst_gen;
2846629397
28467 IrInstruction *result_loc = instruction->result_loc->child;29398 IrInstGen *result_loc = instruction->result_loc->child;
28468 if (type_is_invalid(result_loc->value->type))29399 if (type_is_invalid(result_loc->value->type))
28469 return ira->codegen->invalid_instruction;29400 return ira->codegen->invalid_inst_gen;
2847029401
28471 return ir_analyze_union_init(ira, &instruction->base, instruction->base.source_node,29402 return ir_analyze_union_init(ira, &instruction->base.base, instruction->base.base.source_node,
28472 union_type, field_name, field_result_loc, result_loc);29403 union_type, field_name, field_result_loc, result_loc);
28473}29404}
2847429405
28475static IrInstruction *ir_analyze_instruction_suspend_begin(IrAnalyze *ira, IrInstructionSuspendBegin *instruction) {29406static IrInstGen *ir_analyze_instruction_suspend_begin(IrAnalyze *ira, IrInstSrcSuspendBegin *instruction) {
28476 IrInstructionSuspendBegin *result = ir_build_suspend_begin(&ira->new_irb, instruction->base.scope,29407 return ir_build_suspend_begin_gen(ira, &instruction->base.base);
28477 instruction->base.source_node);
28478 return &result->base;
28479}29408}
2848029409
28481static IrInstruction *ir_analyze_instruction_suspend_finish(IrAnalyze *ira,29410static IrInstGen *ir_analyze_instruction_suspend_finish(IrAnalyze *ira, IrInstSrcSuspendFinish *instruction) {
28482 IrInstructionSuspendFinish *instruction)29411 IrInstGen *begin_base = instruction->begin->base.child;
28483{
28484 IrInstruction *begin_base = instruction->begin->base.child;
28485 if (type_is_invalid(begin_base->value->type))29412 if (type_is_invalid(begin_base->value->type))
28486 return ira->codegen->invalid_instruction;29413 return ira->codegen->invalid_inst_gen;
28487 ir_assert(begin_base->id == IrInstructionIdSuspendBegin, &instruction->base);29414 ir_assert(begin_base->id == IrInstGenIdSuspendBegin, &instruction->base.base);
28488 IrInstructionSuspendBegin *begin = reinterpret_cast<IrInstructionSuspendBegin *>(begin_base);29415 IrInstGenSuspendBegin *begin = reinterpret_cast<IrInstGenSuspendBegin *>(begin_base);
2848929416
28490 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);29417 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
28491 ir_assert(fn_entry != nullptr, &instruction->base);29418 ir_assert(fn_entry != nullptr, &instruction->base.base);
2849229419
28493 if (fn_entry->inferred_async_node == nullptr) {29420 if (fn_entry->inferred_async_node == nullptr) {
28494 fn_entry->inferred_async_node = instruction->base.source_node;29421 fn_entry->inferred_async_node = instruction->base.base.source_node;
28495 }29422 }
2849629423
28497 return ir_build_suspend_finish(&ira->new_irb, instruction->base.scope, instruction->base.source_node, begin);29424 return ir_build_suspend_finish_gen(ira, &instruction->base.base, begin);
28498}29425}
2849929426
28500static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruction *source_instr,29427static IrInstGen *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInst* source_instr,
28501 IrInstruction *frame_ptr, ZigFn **target_fn)29428 IrInstGen *frame_ptr, ZigFn **target_fn)
28502{29429{
28503 if (type_is_invalid(frame_ptr->value->type))29430 if (type_is_invalid(frame_ptr->value->type))
28504 return ira->codegen->invalid_instruction;29431 return ira->codegen->invalid_inst_gen;
2850529432
28506 *target_fn = nullptr;29433 *target_fn = nullptr;
2850729434
28508 ZigType *result_type;29435 ZigType *result_type;
28509 IrInstruction *frame;29436 IrInstGen *frame;
28510 if (frame_ptr->value->type->id == ZigTypeIdPointer &&29437 if (frame_ptr->value->type->id == ZigTypeIdPointer &&
28511 frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle &&29438 frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle &&
28512 frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)29439 frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)
...@@ -28529,38 +29456,38 @@ static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruct...@@ -28529,38 +29456,38 @@ static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruct
28529 {29456 {
28530 ir_add_error(ira, source_instr,29457 ir_add_error(ira, source_instr,
28531 buf_sprintf("expected anyframe->T, found '%s'", buf_ptr(&frame->value->type->name)));29458 buf_sprintf("expected anyframe->T, found '%s'", buf_ptr(&frame->value->type->name)));
28532 return ira->codegen->invalid_instruction;29459 return ira->codegen->invalid_inst_gen;
28533 } else {29460 } else {
28534 result_type = frame->value->type->data.any_frame.result_type;29461 result_type = frame->value->type->data.any_frame.result_type;
28535 }29462 }
28536 }29463 }
2853729464
28538 ZigType *any_frame_type = get_any_frame_type(ira->codegen, result_type);29465 ZigType *any_frame_type = get_any_frame_type(ira->codegen, result_type);
28539 IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type);29466 IrInstGen *casted_frame = ir_implicit_cast(ira, frame, any_frame_type);
28540 if (type_is_invalid(casted_frame->value->type))29467 if (type_is_invalid(casted_frame->value->type))
28541 return ira->codegen->invalid_instruction;29468 return ira->codegen->invalid_inst_gen;
2854229469
28543 return casted_frame;29470 return casted_frame;
28544}29471}
2854529472
28546static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstructionAwaitSrc *instruction) {29473static IrInstGen *ir_analyze_instruction_await(IrAnalyze *ira, IrInstSrcAwait *instruction) {
28547 IrInstruction *operand = instruction->frame->child;29474 IrInstGen *operand = instruction->frame->child;
28548 if (type_is_invalid(operand->value->type))29475 if (type_is_invalid(operand->value->type))
28549 return ira->codegen->invalid_instruction;29476 return ira->codegen->invalid_inst_gen;
28550 ZigFn *target_fn;29477 ZigFn *target_fn;
28551 IrInstruction *frame = analyze_frame_ptr_to_anyframe_T(ira, &instruction->base, operand, &target_fn);29478 IrInstGen *frame = analyze_frame_ptr_to_anyframe_T(ira, &instruction->base.base, operand, &target_fn);
28552 if (type_is_invalid(frame->value->type))29479 if (type_is_invalid(frame->value->type))
28553 return ira->codegen->invalid_instruction;29480 return ira->codegen->invalid_inst_gen;
2855429481
28555 ZigType *result_type = frame->value->type->data.any_frame.result_type;29482 ZigType *result_type = frame->value->type->data.any_frame.result_type;
2855629483
28557 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);29484 ZigFn *fn_entry = ira->new_irb.exec->fn_entry;
28558 ir_assert(fn_entry != nullptr, &instruction->base);29485 ir_assert(fn_entry != nullptr, &instruction->base.base);
2855929486
28560 // If it's not @Frame(func) then it's definitely a suspend point29487 // If it's not @Frame(func) then it's definitely a suspend point
28561 if (target_fn == nullptr) {29488 if (target_fn == nullptr) {
28562 if (fn_entry->inferred_async_node == nullptr) {29489 if (fn_entry->inferred_async_node == nullptr) {
28563 fn_entry->inferred_async_node = instruction->base.source_node;29490 fn_entry->inferred_async_node = instruction->base.base.source_node;
28564 }29491 }
28565 }29492 }
2856629493
...@@ -28568,402 +29495,368 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction...@@ -28568,402 +29495,368 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction
28568 fn_entry->calls_or_awaits_errorable_fn = true;29495 fn_entry->calls_or_awaits_errorable_fn = true;
28569 }29496 }
2857029497
28571 IrInstruction *result_loc;29498 IrInstGen *result_loc;
28572 if (type_has_bits(result_type)) {29499 if (type_has_bits(result_type)) {
28573 result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc,29500 result_loc = ir_resolve_result(ira, &instruction->base.base, instruction->result_loc,
28574 result_type, nullptr, true, true, true);29501 result_type, nullptr, true, true);
28575 if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)))29502 if (result_loc != nullptr &&
29503 (type_is_invalid(result_loc->value->type) || result_loc->value->type->id == ZigTypeIdUnreachable))
29504 {
28576 return result_loc;29505 return result_loc;
29506 }
28577 } else {29507 } else {
28578 result_loc = nullptr;29508 result_loc = nullptr;
28579 }29509 }
2858029510
28581 IrInstructionAwaitGen *result = ir_build_await_gen(ira, &instruction->base, frame, result_type, result_loc);29511 IrInstGenAwait *result = ir_build_await_gen(ira, &instruction->base.base, frame, result_type, result_loc);
28582 result->target_fn = target_fn;29512 result->target_fn = target_fn;
28583 fn_entry->await_list.append(result);29513 fn_entry->await_list.append(result);
28584 return ir_finish_anal(ira, &result->base);29514 return ir_finish_anal(ira, &result->base);
28585}29515}
2858629516
28587static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructionResume *instruction) {29517static IrInstGen *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstSrcResume *instruction) {
28588 IrInstruction *frame_ptr = instruction->frame->child;29518 IrInstGen *frame_ptr = instruction->frame->child;
28589 if (type_is_invalid(frame_ptr->value->type))29519 if (type_is_invalid(frame_ptr->value->type))
28590 return ira->codegen->invalid_instruction;29520 return ira->codegen->invalid_inst_gen;
2859129521
28592 IrInstruction *frame;29522 IrInstGen *frame;
28593 if (frame_ptr->value->type->id == ZigTypeIdPointer &&29523 if (frame_ptr->value->type->id == ZigTypeIdPointer &&
28594 frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle &&29524 frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle &&
28595 frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)29525 frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame)
28596 {29526 {
28597 frame = frame_ptr;29527 frame = frame_ptr;
28598 } else {29528 } else {
28599 frame = ir_get_deref(ira, &instruction->base, frame_ptr, nullptr);29529 frame = ir_get_deref(ira, &instruction->base.base, frame_ptr, nullptr);
28600 }29530 }
2860129531
28602 ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr);29532 ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr);
28603 IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type);29533 IrInstGen *casted_frame = ir_implicit_cast2(ira, &instruction->frame->base, frame, any_frame_type);
28604 if (type_is_invalid(casted_frame->value->type))29534 if (type_is_invalid(casted_frame->value->type))
28605 return ira->codegen->invalid_instruction;29535 return ira->codegen->invalid_inst_gen;
2860629536
28607 return ir_build_resume(&ira->new_irb, instruction->base.scope, instruction->base.source_node, casted_frame);29537 return ir_build_resume_gen(ira, &instruction->base.base, casted_frame);
28608}29538}
2860929539
28610static IrInstruction *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstructionSpillBegin *instruction) {29540static IrInstGen *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstSrcSpillBegin *instruction) {
28611 if (ir_should_inline(ira->new_irb.exec, instruction->base.scope))29541 if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope))
28612 return ir_const_void(ira, &instruction->base);29542 return ir_const_void(ira, &instruction->base.base);
2861329543
28614 IrInstruction *operand = instruction->operand->child;29544 IrInstGen *operand = instruction->operand->child;
28615 if (type_is_invalid(operand->value->type))29545 if (type_is_invalid(operand->value->type))
28616 return ira->codegen->invalid_instruction;29546 return ira->codegen->invalid_inst_gen;
2861729547
28618 if (!type_has_bits(operand->value->type))29548 if (!type_has_bits(operand->value->type))
28619 return ir_const_void(ira, &instruction->base);29549 return ir_const_void(ira, &instruction->base.base);
2862029550
28621 ir_assert(instruction->spill_id == SpillIdRetErrCode, &instruction->base);29551 ir_assert(instruction->spill_id == SpillIdRetErrCode, &instruction->base.base);
28622 ira->new_irb.exec->need_err_code_spill = true;29552 ira->new_irb.exec->need_err_code_spill = true;
2862329553
28624 IrInstructionSpillBegin *result = ir_build_spill_begin(&ira->new_irb, instruction->base.scope,29554 return ir_build_spill_begin_gen(ira, &instruction->base.base, operand, instruction->spill_id);
28625 instruction->base.source_node, operand, instruction->spill_id);
28626 return &result->base;
28627}29555}
2862829556
28629static IrInstruction *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstructionSpillEnd *instruction) {29557static IrInstGen *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstSrcSpillEnd *instruction) {
28630 IrInstruction *operand = instruction->begin->operand->child;29558 IrInstGen *operand = instruction->begin->operand->child;
28631 if (type_is_invalid(operand->value->type))29559 if (type_is_invalid(operand->value->type))
28632 return ira->codegen->invalid_instruction;29560 return ira->codegen->invalid_inst_gen;
2863329561
28634 if (ir_should_inline(ira->new_irb.exec, instruction->base.scope) || !type_has_bits(operand->value->type))29562 if (ir_should_inline(ira->old_irb.exec, instruction->base.base.scope) || !type_has_bits(operand->value->type))
28635 return operand;29563 return operand;
2863629564
28637 ir_assert(instruction->begin->base.child->id == IrInstructionIdSpillBegin, &instruction->base);29565 ir_assert(instruction->begin->base.child->id == IrInstGenIdSpillBegin, &instruction->base.base);
28638 IrInstructionSpillBegin *begin = reinterpret_cast<IrInstructionSpillBegin *>(instruction->begin->base.child);29566 IrInstGenSpillBegin *begin = reinterpret_cast<IrInstGenSpillBegin *>(instruction->begin->base.child);
2863929567
28640 IrInstruction *result = ir_build_spill_end(&ira->new_irb, instruction->base.scope,29568 return ir_build_spill_end_gen(ira, &instruction->base.base, begin, operand->value->type);
28641 instruction->base.source_node, begin);
28642 result->value->type = operand->value->type;
28643 return result;
28644}29569}
2864529570
28646static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction *instruction) {29571static IrInstGen *ir_analyze_instruction_base(IrAnalyze *ira, IrInstSrc *instruction) {
28647 switch (instruction->id) {29572 switch (instruction->id) {
28648 case IrInstructionIdInvalid:29573 case IrInstSrcIdInvalid:
28649 case IrInstructionIdWidenOrShorten:
28650 case IrInstructionIdStructFieldPtr:
28651 case IrInstructionIdUnionFieldPtr:
28652 case IrInstructionIdOptionalWrap:
28653 case IrInstructionIdErrWrapCode:
28654 case IrInstructionIdErrWrapPayload:
28655 case IrInstructionIdCast:
28656 case IrInstructionIdDeclVarGen:
28657 case IrInstructionIdPtrCastGen:
28658 case IrInstructionIdCmpxchgGen:
28659 case IrInstructionIdArrayToVector:
28660 case IrInstructionIdVectorToArray:
28661 case IrInstructionIdPtrOfArrayToSlice:
28662 case IrInstructionIdAssertZero:
28663 case IrInstructionIdAssertNonNull:
28664 case IrInstructionIdResizeSlice:
28665 case IrInstructionIdLoadPtrGen:
28666 case IrInstructionIdBitCastGen:
28667 case IrInstructionIdCallGen:
28668 case IrInstructionIdReturnPtr:
28669 case IrInstructionIdAllocaGen:
28670 case IrInstructionIdSliceGen:
28671 case IrInstructionIdRefGen:
28672 case IrInstructionIdTestErrGen:
28673 case IrInstructionIdFrameSizeGen:
28674 case IrInstructionIdAwaitGen:
28675 case IrInstructionIdSplatGen:
28676 case IrInstructionIdVectorExtractElem:
28677 case IrInstructionIdVectorStoreElem:
28678 case IrInstructionIdAsmGen:
28679 zig_unreachable();29574 zig_unreachable();
2868029575
28681 case IrInstructionIdReturn:29576 case IrInstSrcIdReturn:
28682 return ir_analyze_instruction_return(ira, (IrInstructionReturn *)instruction);29577 return ir_analyze_instruction_return(ira, (IrInstSrcReturn *)instruction);
28683 case IrInstructionIdConst:29578 case IrInstSrcIdConst:
28684 return ir_analyze_instruction_const(ira, (IrInstructionConst *)instruction);29579 return ir_analyze_instruction_const(ira, (IrInstSrcConst *)instruction);
28685 case IrInstructionIdUnOp:29580 case IrInstSrcIdUnOp:
28686 return ir_analyze_instruction_un_op(ira, (IrInstructionUnOp *)instruction);29581 return ir_analyze_instruction_un_op(ira, (IrInstSrcUnOp *)instruction);
28687 case IrInstructionIdBinOp:29582 case IrInstSrcIdBinOp:
28688 return ir_analyze_instruction_bin_op(ira, (IrInstructionBinOp *)instruction);29583 return ir_analyze_instruction_bin_op(ira, (IrInstSrcBinOp *)instruction);
28689 case IrInstructionIdMergeErrSets:29584 case IrInstSrcIdMergeErrSets:
28690 return ir_analyze_instruction_merge_err_sets(ira, (IrInstructionMergeErrSets *)instruction);29585 return ir_analyze_instruction_merge_err_sets(ira, (IrInstSrcMergeErrSets *)instruction);
28691 case IrInstructionIdDeclVarSrc:29586 case IrInstSrcIdDeclVar:
28692 return ir_analyze_instruction_decl_var(ira, (IrInstructionDeclVarSrc *)instruction);29587 return ir_analyze_instruction_decl_var(ira, (IrInstSrcDeclVar *)instruction);
28693 case IrInstructionIdLoadPtr:29588 case IrInstSrcIdLoadPtr:
28694 return ir_analyze_instruction_load_ptr(ira, (IrInstructionLoadPtr *)instruction);29589 return ir_analyze_instruction_load_ptr(ira, (IrInstSrcLoadPtr *)instruction);
28695 case IrInstructionIdStorePtr:29590 case IrInstSrcIdStorePtr:
28696 return ir_analyze_instruction_store_ptr(ira, (IrInstructionStorePtr *)instruction);29591 return ir_analyze_instruction_store_ptr(ira, (IrInstSrcStorePtr *)instruction);
28697 case IrInstructionIdElemPtr:29592 case IrInstSrcIdElemPtr:
28698 return ir_analyze_instruction_elem_ptr(ira, (IrInstructionElemPtr *)instruction);29593 return ir_analyze_instruction_elem_ptr(ira, (IrInstSrcElemPtr *)instruction);
28699 case IrInstructionIdVarPtr:29594 case IrInstSrcIdVarPtr:
28700 return ir_analyze_instruction_var_ptr(ira, (IrInstructionVarPtr *)instruction);29595 return ir_analyze_instruction_var_ptr(ira, (IrInstSrcVarPtr *)instruction);
28701 case IrInstructionIdFieldPtr:29596 case IrInstSrcIdFieldPtr:
28702 return ir_analyze_instruction_field_ptr(ira, (IrInstructionFieldPtr *)instruction);29597 return ir_analyze_instruction_field_ptr(ira, (IrInstSrcFieldPtr *)instruction);
28703 case IrInstructionIdCallSrc:29598 case IrInstSrcIdCall:
28704 return ir_analyze_instruction_call(ira, (IrInstructionCallSrc *)instruction);29599 return ir_analyze_instruction_call(ira, (IrInstSrcCall *)instruction);
28705 case IrInstructionIdCallSrcArgs:29600 case IrInstSrcIdCallArgs:
28706 return ir_analyze_instruction_call_args(ira, (IrInstructionCallSrcArgs *)instruction);29601 return ir_analyze_instruction_call_args(ira, (IrInstSrcCallArgs *)instruction);
28707 case IrInstructionIdCallExtra:29602 case IrInstSrcIdCallExtra:
28708 return ir_analyze_instruction_call_extra(ira, (IrInstructionCallExtra *)instruction);29603 return ir_analyze_instruction_call_extra(ira, (IrInstSrcCallExtra *)instruction);
28709 case IrInstructionIdBr:29604 case IrInstSrcIdBr:
28710 return ir_analyze_instruction_br(ira, (IrInstructionBr *)instruction);29605 return ir_analyze_instruction_br(ira, (IrInstSrcBr *)instruction);
28711 case IrInstructionIdCondBr:29606 case IrInstSrcIdCondBr:
28712 return ir_analyze_instruction_cond_br(ira, (IrInstructionCondBr *)instruction);29607 return ir_analyze_instruction_cond_br(ira, (IrInstSrcCondBr *)instruction);
28713 case IrInstructionIdUnreachable:29608 case IrInstSrcIdUnreachable:
28714 return ir_analyze_instruction_unreachable(ira, (IrInstructionUnreachable *)instruction);29609 return ir_analyze_instruction_unreachable(ira, (IrInstSrcUnreachable *)instruction);
28715 case IrInstructionIdPhi:29610 case IrInstSrcIdPhi:
28716 return ir_analyze_instruction_phi(ira, (IrInstructionPhi *)instruction);29611 return ir_analyze_instruction_phi(ira, (IrInstSrcPhi *)instruction);
28717 case IrInstructionIdTypeOf:29612 case IrInstSrcIdTypeOf:
28718 return ir_analyze_instruction_typeof(ira, (IrInstructionTypeOf *)instruction);29613 return ir_analyze_instruction_typeof(ira, (IrInstSrcTypeOf *)instruction);
28719 case IrInstructionIdSetCold:29614 case IrInstSrcIdSetCold:
28720 return ir_analyze_instruction_set_cold(ira, (IrInstructionSetCold *)instruction);29615 return ir_analyze_instruction_set_cold(ira, (IrInstSrcSetCold *)instruction);
28721 case IrInstructionIdSetRuntimeSafety:29616 case IrInstSrcIdSetRuntimeSafety:
28722 return ir_analyze_instruction_set_runtime_safety(ira, (IrInstructionSetRuntimeSafety *)instruction);29617 return ir_analyze_instruction_set_runtime_safety(ira, (IrInstSrcSetRuntimeSafety *)instruction);
28723 case IrInstructionIdSetFloatMode:29618 case IrInstSrcIdSetFloatMode:
28724 return ir_analyze_instruction_set_float_mode(ira, (IrInstructionSetFloatMode *)instruction);29619 return ir_analyze_instruction_set_float_mode(ira, (IrInstSrcSetFloatMode *)instruction);
28725 case IrInstructionIdAnyFrameType:29620 case IrInstSrcIdAnyFrameType:
28726 return ir_analyze_instruction_any_frame_type(ira, (IrInstructionAnyFrameType *)instruction);29621 return ir_analyze_instruction_any_frame_type(ira, (IrInstSrcAnyFrameType *)instruction);
28727 case IrInstructionIdSliceType:29622 case IrInstSrcIdSliceType:
28728 return ir_analyze_instruction_slice_type(ira, (IrInstructionSliceType *)instruction);29623 return ir_analyze_instruction_slice_type(ira, (IrInstSrcSliceType *)instruction);
28729 case IrInstructionIdAsmSrc:29624 case IrInstSrcIdAsm:
28730 return ir_analyze_instruction_asm(ira, (IrInstructionAsmSrc *)instruction);29625 return ir_analyze_instruction_asm(ira, (IrInstSrcAsm *)instruction);
28731 case IrInstructionIdArrayType:29626 case IrInstSrcIdArrayType:
28732 return ir_analyze_instruction_array_type(ira, (IrInstructionArrayType *)instruction);29627 return ir_analyze_instruction_array_type(ira, (IrInstSrcArrayType *)instruction);
28733 case IrInstructionIdSizeOf:29628 case IrInstSrcIdSizeOf:
28734 return ir_analyze_instruction_size_of(ira, (IrInstructionSizeOf *)instruction);29629 return ir_analyze_instruction_size_of(ira, (IrInstSrcSizeOf *)instruction);
28735 case IrInstructionIdTestNonNull:29630 case IrInstSrcIdTestNonNull:
28736 return ir_analyze_instruction_test_non_null(ira, (IrInstructionTestNonNull *)instruction);29631 return ir_analyze_instruction_test_non_null(ira, (IrInstSrcTestNonNull *)instruction);
28737 case IrInstructionIdOptionalUnwrapPtr:29632 case IrInstSrcIdOptionalUnwrapPtr:
28738 return ir_analyze_instruction_optional_unwrap_ptr(ira, (IrInstructionOptionalUnwrapPtr *)instruction);29633 return ir_analyze_instruction_optional_unwrap_ptr(ira, (IrInstSrcOptionalUnwrapPtr *)instruction);
28739 case IrInstructionIdClz:29634 case IrInstSrcIdClz:
28740 return ir_analyze_instruction_clz(ira, (IrInstructionClz *)instruction);29635 return ir_analyze_instruction_clz(ira, (IrInstSrcClz *)instruction);
28741 case IrInstructionIdCtz:29636 case IrInstSrcIdCtz:
28742 return ir_analyze_instruction_ctz(ira, (IrInstructionCtz *)instruction);29637 return ir_analyze_instruction_ctz(ira, (IrInstSrcCtz *)instruction);
28743 case IrInstructionIdPopCount:29638 case IrInstSrcIdPopCount:
28744 return ir_analyze_instruction_pop_count(ira, (IrInstructionPopCount *)instruction);29639 return ir_analyze_instruction_pop_count(ira, (IrInstSrcPopCount *)instruction);
28745 case IrInstructionIdBswap:29640 case IrInstSrcIdBswap:
28746 return ir_analyze_instruction_bswap(ira, (IrInstructionBswap *)instruction);29641 return ir_analyze_instruction_bswap(ira, (IrInstSrcBswap *)instruction);
28747 case IrInstructionIdBitReverse:29642 case IrInstSrcIdBitReverse:
28748 return ir_analyze_instruction_bit_reverse(ira, (IrInstructionBitReverse *)instruction);29643 return ir_analyze_instruction_bit_reverse(ira, (IrInstSrcBitReverse *)instruction);
28749 case IrInstructionIdSwitchBr:29644 case IrInstSrcIdSwitchBr:
28750 return ir_analyze_instruction_switch_br(ira, (IrInstructionSwitchBr *)instruction);29645 return ir_analyze_instruction_switch_br(ira, (IrInstSrcSwitchBr *)instruction);
28751 case IrInstructionIdSwitchTarget:29646 case IrInstSrcIdSwitchTarget:
28752 return ir_analyze_instruction_switch_target(ira, (IrInstructionSwitchTarget *)instruction);29647 return ir_analyze_instruction_switch_target(ira, (IrInstSrcSwitchTarget *)instruction);
28753 case IrInstructionIdSwitchVar:29648 case IrInstSrcIdSwitchVar:
28754 return ir_analyze_instruction_switch_var(ira, (IrInstructionSwitchVar *)instruction);29649 return ir_analyze_instruction_switch_var(ira, (IrInstSrcSwitchVar *)instruction);
28755 case IrInstructionIdSwitchElseVar:29650 case IrInstSrcIdSwitchElseVar:
28756 return ir_analyze_instruction_switch_else_var(ira, (IrInstructionSwitchElseVar *)instruction);29651 return ir_analyze_instruction_switch_else_var(ira, (IrInstSrcSwitchElseVar *)instruction);
28757 case IrInstructionIdUnionTag:29652 case IrInstSrcIdImport:
28758 return ir_analyze_instruction_union_tag(ira, (IrInstructionUnionTag *)instruction);29653 return ir_analyze_instruction_import(ira, (IrInstSrcImport *)instruction);
28759 case IrInstructionIdImport:29654 case IrInstSrcIdRef:
28760 return ir_analyze_instruction_import(ira, (IrInstructionImport *)instruction);29655 return ir_analyze_instruction_ref(ira, (IrInstSrcRef *)instruction);
28761 case IrInstructionIdRef:29656 case IrInstSrcIdContainerInitList:
28762 return ir_analyze_instruction_ref(ira, (IrInstructionRef *)instruction);29657 return ir_analyze_instruction_container_init_list(ira, (IrInstSrcContainerInitList *)instruction);
28763 case IrInstructionIdContainerInitList:29658 case IrInstSrcIdContainerInitFields:
28764 return ir_analyze_instruction_container_init_list(ira, (IrInstructionContainerInitList *)instruction);29659 return ir_analyze_instruction_container_init_fields(ira, (IrInstSrcContainerInitFields *)instruction);
28765 case IrInstructionIdContainerInitFields:29660 case IrInstSrcIdCompileErr:
28766 return ir_analyze_instruction_container_init_fields(ira, (IrInstructionContainerInitFields *)instruction);29661 return ir_analyze_instruction_compile_err(ira, (IrInstSrcCompileErr *)instruction);
28767 case IrInstructionIdCompileErr:29662 case IrInstSrcIdCompileLog:
28768 return ir_analyze_instruction_compile_err(ira, (IrInstructionCompileErr *)instruction);29663 return ir_analyze_instruction_compile_log(ira, (IrInstSrcCompileLog *)instruction);
28769 case IrInstructionIdCompileLog:29664 case IrInstSrcIdErrName:
28770 return ir_analyze_instruction_compile_log(ira, (IrInstructionCompileLog *)instruction);29665 return ir_analyze_instruction_err_name(ira, (IrInstSrcErrName *)instruction);
28771 case IrInstructionIdErrName:29666 case IrInstSrcIdTypeName:
28772 return ir_analyze_instruction_err_name(ira, (IrInstructionErrName *)instruction);29667 return ir_analyze_instruction_type_name(ira, (IrInstSrcTypeName *)instruction);
28773 case IrInstructionIdTypeName:29668 case IrInstSrcIdCImport:
28774 return ir_analyze_instruction_type_name(ira, (IrInstructionTypeName *)instruction);29669 return ir_analyze_instruction_c_import(ira, (IrInstSrcCImport *)instruction);
28775 case IrInstructionIdCImport:29670 case IrInstSrcIdCInclude:
28776 return ir_analyze_instruction_c_import(ira, (IrInstructionCImport *)instruction);29671 return ir_analyze_instruction_c_include(ira, (IrInstSrcCInclude *)instruction);
28777 case IrInstructionIdCInclude:29672 case IrInstSrcIdCDefine:
28778 return ir_analyze_instruction_c_include(ira, (IrInstructionCInclude *)instruction);29673 return ir_analyze_instruction_c_define(ira, (IrInstSrcCDefine *)instruction);
28779 case IrInstructionIdCDefine:29674 case IrInstSrcIdCUndef:
28780 return ir_analyze_instruction_c_define(ira, (IrInstructionCDefine *)instruction);29675 return ir_analyze_instruction_c_undef(ira, (IrInstSrcCUndef *)instruction);
28781 case IrInstructionIdCUndef:29676 case IrInstSrcIdEmbedFile:
28782 return ir_analyze_instruction_c_undef(ira, (IrInstructionCUndef *)instruction);29677 return ir_analyze_instruction_embed_file(ira, (IrInstSrcEmbedFile *)instruction);
28783 case IrInstructionIdEmbedFile:29678 case IrInstSrcIdCmpxchg:
28784 return ir_analyze_instruction_embed_file(ira, (IrInstructionEmbedFile *)instruction);29679 return ir_analyze_instruction_cmpxchg(ira, (IrInstSrcCmpxchg *)instruction);
28785 case IrInstructionIdCmpxchgSrc:29680 case IrInstSrcIdFence:
28786 return ir_analyze_instruction_cmpxchg(ira, (IrInstructionCmpxchgSrc *)instruction);29681 return ir_analyze_instruction_fence(ira, (IrInstSrcFence *)instruction);
28787 case IrInstructionIdFence:29682 case IrInstSrcIdTruncate:
28788 return ir_analyze_instruction_fence(ira, (IrInstructionFence *)instruction);29683 return ir_analyze_instruction_truncate(ira, (IrInstSrcTruncate *)instruction);
28789 case IrInstructionIdTruncate:29684 case IrInstSrcIdIntCast:
28790 return ir_analyze_instruction_truncate(ira, (IrInstructionTruncate *)instruction);29685 return ir_analyze_instruction_int_cast(ira, (IrInstSrcIntCast *)instruction);
28791 case IrInstructionIdIntCast:29686 case IrInstSrcIdFloatCast:
28792 return ir_analyze_instruction_int_cast(ira, (IrInstructionIntCast *)instruction);29687 return ir_analyze_instruction_float_cast(ira, (IrInstSrcFloatCast *)instruction);
28793 case IrInstructionIdFloatCast:29688 case IrInstSrcIdErrSetCast:
28794 return ir_analyze_instruction_float_cast(ira, (IrInstructionFloatCast *)instruction);29689 return ir_analyze_instruction_err_set_cast(ira, (IrInstSrcErrSetCast *)instruction);
28795 case IrInstructionIdErrSetCast:29690 case IrInstSrcIdFromBytes:
28796 return ir_analyze_instruction_err_set_cast(ira, (IrInstructionErrSetCast *)instruction);29691 return ir_analyze_instruction_from_bytes(ira, (IrInstSrcFromBytes *)instruction);
28797 case IrInstructionIdFromBytes:29692 case IrInstSrcIdToBytes:
28798 return ir_analyze_instruction_from_bytes(ira, (IrInstructionFromBytes *)instruction);29693 return ir_analyze_instruction_to_bytes(ira, (IrInstSrcToBytes *)instruction);
28799 case IrInstructionIdToBytes:29694 case IrInstSrcIdIntToFloat:
28800 return ir_analyze_instruction_to_bytes(ira, (IrInstructionToBytes *)instruction);29695 return ir_analyze_instruction_int_to_float(ira, (IrInstSrcIntToFloat *)instruction);
28801 case IrInstructionIdIntToFloat:29696 case IrInstSrcIdFloatToInt:
28802 return ir_analyze_instruction_int_to_float(ira, (IrInstructionIntToFloat *)instruction);29697 return ir_analyze_instruction_float_to_int(ira, (IrInstSrcFloatToInt *)instruction);
28803 case IrInstructionIdFloatToInt:29698 case IrInstSrcIdBoolToInt:
28804 return ir_analyze_instruction_float_to_int(ira, (IrInstructionFloatToInt *)instruction);29699 return ir_analyze_instruction_bool_to_int(ira, (IrInstSrcBoolToInt *)instruction);
28805 case IrInstructionIdBoolToInt:29700 case IrInstSrcIdIntType:
28806 return ir_analyze_instruction_bool_to_int(ira, (IrInstructionBoolToInt *)instruction);29701 return ir_analyze_instruction_int_type(ira, (IrInstSrcIntType *)instruction);
28807 case IrInstructionIdIntType:29702 case IrInstSrcIdVectorType:
28808 return ir_analyze_instruction_int_type(ira, (IrInstructionIntType *)instruction);29703 return ir_analyze_instruction_vector_type(ira, (IrInstSrcVectorType *)instruction);
28809 case IrInstructionIdVectorType:29704 case IrInstSrcIdShuffleVector:
28810 return ir_analyze_instruction_vector_type(ira, (IrInstructionVectorType *)instruction);29705 return ir_analyze_instruction_shuffle_vector(ira, (IrInstSrcShuffleVector *)instruction);
28811 case IrInstructionIdShuffleVector:29706 case IrInstSrcIdSplat:
28812 return ir_analyze_instruction_shuffle_vector(ira, (IrInstructionShuffleVector *)instruction);29707 return ir_analyze_instruction_splat(ira, (IrInstSrcSplat *)instruction);
28813 case IrInstructionIdSplatSrc:29708 case IrInstSrcIdBoolNot:
28814 return ir_analyze_instruction_splat(ira, (IrInstructionSplatSrc *)instruction);29709 return ir_analyze_instruction_bool_not(ira, (IrInstSrcBoolNot *)instruction);
28815 case IrInstructionIdBoolNot:29710 case IrInstSrcIdMemset:
28816 return ir_analyze_instruction_bool_not(ira, (IrInstructionBoolNot *)instruction);29711 return ir_analyze_instruction_memset(ira, (IrInstSrcMemset *)instruction);
28817 case IrInstructionIdMemset:29712 case IrInstSrcIdMemcpy:
28818 return ir_analyze_instruction_memset(ira, (IrInstructionMemset *)instruction);29713 return ir_analyze_instruction_memcpy(ira, (IrInstSrcMemcpy *)instruction);
28819 case IrInstructionIdMemcpy:29714 case IrInstSrcIdSlice:
28820 return ir_analyze_instruction_memcpy(ira, (IrInstructionMemcpy *)instruction);29715 return ir_analyze_instruction_slice(ira, (IrInstSrcSlice *)instruction);
28821 case IrInstructionIdSliceSrc:29716 case IrInstSrcIdMemberCount:
28822 return ir_analyze_instruction_slice(ira, (IrInstructionSliceSrc *)instruction);29717 return ir_analyze_instruction_member_count(ira, (IrInstSrcMemberCount *)instruction);
28823 case IrInstructionIdMemberCount:29718 case IrInstSrcIdMemberType:
28824 return ir_analyze_instruction_member_count(ira, (IrInstructionMemberCount *)instruction);29719 return ir_analyze_instruction_member_type(ira, (IrInstSrcMemberType *)instruction);
28825 case IrInstructionIdMemberType:29720 case IrInstSrcIdMemberName:
28826 return ir_analyze_instruction_member_type(ira, (IrInstructionMemberType *)instruction);29721 return ir_analyze_instruction_member_name(ira, (IrInstSrcMemberName *)instruction);
28827 case IrInstructionIdMemberName:29722 case IrInstSrcIdBreakpoint:
28828 return ir_analyze_instruction_member_name(ira, (IrInstructionMemberName *)instruction);29723 return ir_analyze_instruction_breakpoint(ira, (IrInstSrcBreakpoint *)instruction);
28829 case IrInstructionIdBreakpoint:29724 case IrInstSrcIdReturnAddress:
28830 return ir_analyze_instruction_breakpoint(ira, (IrInstructionBreakpoint *)instruction);29725 return ir_analyze_instruction_return_address(ira, (IrInstSrcReturnAddress *)instruction);
28831 case IrInstructionIdReturnAddress:29726 case IrInstSrcIdFrameAddress:
28832 return ir_analyze_instruction_return_address(ira, (IrInstructionReturnAddress *)instruction);29727 return ir_analyze_instruction_frame_address(ira, (IrInstSrcFrameAddress *)instruction);
28833 case IrInstructionIdFrameAddress:29728 case IrInstSrcIdFrameHandle:
28834 return ir_analyze_instruction_frame_address(ira, (IrInstructionFrameAddress *)instruction);29729 return ir_analyze_instruction_frame_handle(ira, (IrInstSrcFrameHandle *)instruction);
28835 case IrInstructionIdFrameHandle:29730 case IrInstSrcIdFrameType:
28836 return ir_analyze_instruction_frame_handle(ira, (IrInstructionFrameHandle *)instruction);29731 return ir_analyze_instruction_frame_type(ira, (IrInstSrcFrameType *)instruction);
28837 case IrInstructionIdFrameType:29732 case IrInstSrcIdFrameSize:
28838 return ir_analyze_instruction_frame_type(ira, (IrInstructionFrameType *)instruction);29733 return ir_analyze_instruction_frame_size(ira, (IrInstSrcFrameSize *)instruction);
28839 case IrInstructionIdFrameSizeSrc:29734 case IrInstSrcIdAlignOf:
28840 return ir_analyze_instruction_frame_size(ira, (IrInstructionFrameSizeSrc *)instruction);29735 return ir_analyze_instruction_align_of(ira, (IrInstSrcAlignOf *)instruction);
28841 case IrInstructionIdAlignOf:29736 case IrInstSrcIdOverflowOp:
28842 return ir_analyze_instruction_align_of(ira, (IrInstructionAlignOf *)instruction);29737 return ir_analyze_instruction_overflow_op(ira, (IrInstSrcOverflowOp *)instruction);
28843 case IrInstructionIdOverflowOp:29738 case IrInstSrcIdTestErr:
28844 return ir_analyze_instruction_overflow_op(ira, (IrInstructionOverflowOp *)instruction);29739 return ir_analyze_instruction_test_err(ira, (IrInstSrcTestErr *)instruction);
28845 case IrInstructionIdTestErrSrc:29740 case IrInstSrcIdUnwrapErrCode:
28846 return ir_analyze_instruction_test_err(ira, (IrInstructionTestErrSrc *)instruction);29741 return ir_analyze_instruction_unwrap_err_code(ira, (IrInstSrcUnwrapErrCode *)instruction);
28847 case IrInstructionIdUnwrapErrCode:29742 case IrInstSrcIdUnwrapErrPayload:
28848 return ir_analyze_instruction_unwrap_err_code(ira, (IrInstructionUnwrapErrCode *)instruction);29743 return ir_analyze_instruction_unwrap_err_payload(ira, (IrInstSrcUnwrapErrPayload *)instruction);
28849 case IrInstructionIdUnwrapErrPayload:29744 case IrInstSrcIdFnProto:
28850 return ir_analyze_instruction_unwrap_err_payload(ira, (IrInstructionUnwrapErrPayload *)instruction);29745 return ir_analyze_instruction_fn_proto(ira, (IrInstSrcFnProto *)instruction);
28851 case IrInstructionIdFnProto:29746 case IrInstSrcIdTestComptime:
28852 return ir_analyze_instruction_fn_proto(ira, (IrInstructionFnProto *)instruction);29747 return ir_analyze_instruction_test_comptime(ira, (IrInstSrcTestComptime *)instruction);
28853 case IrInstructionIdTestComptime:29748 case IrInstSrcIdCheckSwitchProngs:
28854 return ir_analyze_instruction_test_comptime(ira, (IrInstructionTestComptime *)instruction);29749 return ir_analyze_instruction_check_switch_prongs(ira, (IrInstSrcCheckSwitchProngs *)instruction);
28855 case IrInstructionIdCheckSwitchProngs:29750 case IrInstSrcIdCheckStatementIsVoid:
28856 return ir_analyze_instruction_check_switch_prongs(ira, (IrInstructionCheckSwitchProngs *)instruction);29751 return ir_analyze_instruction_check_statement_is_void(ira, (IrInstSrcCheckStatementIsVoid *)instruction);
28857 case IrInstructionIdCheckStatementIsVoid:29752 case IrInstSrcIdDeclRef:
28858 return ir_analyze_instruction_check_statement_is_void(ira, (IrInstructionCheckStatementIsVoid *)instruction);29753 return ir_analyze_instruction_decl_ref(ira, (IrInstSrcDeclRef *)instruction);
28859 case IrInstructionIdDeclRef:29754 case IrInstSrcIdPanic:
28860 return ir_analyze_instruction_decl_ref(ira, (IrInstructionDeclRef *)instruction);29755 return ir_analyze_instruction_panic(ira, (IrInstSrcPanic *)instruction);
28861 case IrInstructionIdPanic:29756 case IrInstSrcIdPtrCast:
28862 return ir_analyze_instruction_panic(ira, (IrInstructionPanic *)instruction);29757 return ir_analyze_instruction_ptr_cast(ira, (IrInstSrcPtrCast *)instruction);
28863 case IrInstructionIdPtrCastSrc:29758 case IrInstSrcIdIntToPtr:
28864 return ir_analyze_instruction_ptr_cast(ira, (IrInstructionPtrCastSrc *)instruction);29759 return ir_analyze_instruction_int_to_ptr(ira, (IrInstSrcIntToPtr *)instruction);
28865 case IrInstructionIdIntToPtr:29760 case IrInstSrcIdPtrToInt:
28866 return ir_analyze_instruction_int_to_ptr(ira, (IrInstructionIntToPtr *)instruction);29761 return ir_analyze_instruction_ptr_to_int(ira, (IrInstSrcPtrToInt *)instruction);
28867 case IrInstructionIdPtrToInt:29762 case IrInstSrcIdTagName:
28868 return ir_analyze_instruction_ptr_to_int(ira, (IrInstructionPtrToInt *)instruction);29763 return ir_analyze_instruction_enum_tag_name(ira, (IrInstSrcTagName *)instruction);
28869 case IrInstructionIdTagName:29764 case IrInstSrcIdFieldParentPtr:
28870 return ir_analyze_instruction_enum_tag_name(ira, (IrInstructionTagName *)instruction);29765 return ir_analyze_instruction_field_parent_ptr(ira, (IrInstSrcFieldParentPtr *)instruction);
28871 case IrInstructionIdFieldParentPtr:29766 case IrInstSrcIdByteOffsetOf:
28872 return ir_analyze_instruction_field_parent_ptr(ira, (IrInstructionFieldParentPtr *)instruction);29767 return ir_analyze_instruction_byte_offset_of(ira, (IrInstSrcByteOffsetOf *)instruction);
28873 case IrInstructionIdByteOffsetOf:29768 case IrInstSrcIdBitOffsetOf:
28874 return ir_analyze_instruction_byte_offset_of(ira, (IrInstructionByteOffsetOf *)instruction);29769 return ir_analyze_instruction_bit_offset_of(ira, (IrInstSrcBitOffsetOf *)instruction);
28875 case IrInstructionIdBitOffsetOf:29770 case IrInstSrcIdTypeInfo:
28876 return ir_analyze_instruction_bit_offset_of(ira, (IrInstructionBitOffsetOf *)instruction);29771 return ir_analyze_instruction_type_info(ira, (IrInstSrcTypeInfo *) instruction);
28877 case IrInstructionIdTypeInfo:29772 case IrInstSrcIdType:
28878 return ir_analyze_instruction_type_info(ira, (IrInstructionTypeInfo *) instruction);29773 return ir_analyze_instruction_type(ira, (IrInstSrcType *)instruction);
28879 case IrInstructionIdType:29774 case IrInstSrcIdHasField:
28880 return ir_analyze_instruction_type(ira, (IrInstructionType *)instruction);29775 return ir_analyze_instruction_has_field(ira, (IrInstSrcHasField *) instruction);
28881 case IrInstructionIdHasField:29776 case IrInstSrcIdTypeId:
28882 return ir_analyze_instruction_has_field(ira, (IrInstructionHasField *) instruction);29777 return ir_analyze_instruction_type_id(ira, (IrInstSrcTypeId *)instruction);
28883 case IrInstructionIdTypeId:29778 case IrInstSrcIdSetEvalBranchQuota:
28884 return ir_analyze_instruction_type_id(ira, (IrInstructionTypeId *)instruction);29779 return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstSrcSetEvalBranchQuota *)instruction);
28885 case IrInstructionIdSetEvalBranchQuota:29780 case IrInstSrcIdPtrType:
28886 return ir_analyze_instruction_set_eval_branch_quota(ira, (IrInstructionSetEvalBranchQuota *)instruction);29781 return ir_analyze_instruction_ptr_type(ira, (IrInstSrcPtrType *)instruction);
28887 case IrInstructionIdPtrType:29782 case IrInstSrcIdAlignCast:
28888 return ir_analyze_instruction_ptr_type(ira, (IrInstructionPtrType *)instruction);29783 return ir_analyze_instruction_align_cast(ira, (IrInstSrcAlignCast *)instruction);
28889 case IrInstructionIdAlignCast:29784 case IrInstSrcIdImplicitCast:
28890 return ir_analyze_instruction_align_cast(ira, (IrInstructionAlignCast *)instruction);29785 return ir_analyze_instruction_implicit_cast(ira, (IrInstSrcImplicitCast *)instruction);
28891 case IrInstructionIdImplicitCast:29786 case IrInstSrcIdResolveResult:
28892 return ir_analyze_instruction_implicit_cast(ira, (IrInstructionImplicitCast *)instruction);29787 return ir_analyze_instruction_resolve_result(ira, (IrInstSrcResolveResult *)instruction);
28893 case IrInstructionIdResolveResult:29788 case IrInstSrcIdResetResult:
28894 return ir_analyze_instruction_resolve_result(ira, (IrInstructionResolveResult *)instruction);29789 return ir_analyze_instruction_reset_result(ira, (IrInstSrcResetResult *)instruction);
28895 case IrInstructionIdResetResult:29790 case IrInstSrcIdOpaqueType:
28896 return ir_analyze_instruction_reset_result(ira, (IrInstructionResetResult *)instruction);29791 return ir_analyze_instruction_opaque_type(ira, (IrInstSrcOpaqueType *)instruction);
28897 case IrInstructionIdOpaqueType:29792 case IrInstSrcIdSetAlignStack:
28898 return ir_analyze_instruction_opaque_type(ira, (IrInstructionOpaqueType *)instruction);29793 return ir_analyze_instruction_set_align_stack(ira, (IrInstSrcSetAlignStack *)instruction);
28899 case IrInstructionIdSetAlignStack:29794 case IrInstSrcIdArgType:
28900 return ir_analyze_instruction_set_align_stack(ira, (IrInstructionSetAlignStack *)instruction);29795 return ir_analyze_instruction_arg_type(ira, (IrInstSrcArgType *)instruction);
28901 case IrInstructionIdArgType:29796 case IrInstSrcIdTagType:
28902 return ir_analyze_instruction_arg_type(ira, (IrInstructionArgType *)instruction);29797 return ir_analyze_instruction_tag_type(ira, (IrInstSrcTagType *)instruction);
28903 case IrInstructionIdTagType:29798 case IrInstSrcIdExport:
28904 return ir_analyze_instruction_tag_type(ira, (IrInstructionTagType *)instruction);29799 return ir_analyze_instruction_export(ira, (IrInstSrcExport *)instruction);
28905 case IrInstructionIdExport:29800 case IrInstSrcIdErrorReturnTrace:
28906 return ir_analyze_instruction_export(ira, (IrInstructionExport *)instruction);29801 return ir_analyze_instruction_error_return_trace(ira, (IrInstSrcErrorReturnTrace *)instruction);
28907 case IrInstructionIdErrorReturnTrace:29802 case IrInstSrcIdErrorUnion:
28908 return ir_analyze_instruction_error_return_trace(ira, (IrInstructionErrorReturnTrace *)instruction);29803 return ir_analyze_instruction_error_union(ira, (IrInstSrcErrorUnion *)instruction);
28909 case IrInstructionIdErrorUnion:29804 case IrInstSrcIdAtomicRmw:
28910 return ir_analyze_instruction_error_union(ira, (IrInstructionErrorUnion *)instruction);29805 return ir_analyze_instruction_atomic_rmw(ira, (IrInstSrcAtomicRmw *)instruction);
28911 case IrInstructionIdAtomicRmw:29806 case IrInstSrcIdAtomicLoad:
28912 return ir_analyze_instruction_atomic_rmw(ira, (IrInstructionAtomicRmw *)instruction);29807 return ir_analyze_instruction_atomic_load(ira, (IrInstSrcAtomicLoad *)instruction);
28913 case IrInstructionIdAtomicLoad:29808 case IrInstSrcIdAtomicStore:
28914 return ir_analyze_instruction_atomic_load(ira, (IrInstructionAtomicLoad *)instruction);29809 return ir_analyze_instruction_atomic_store(ira, (IrInstSrcAtomicStore *)instruction);
28915 case IrInstructionIdAtomicStore:29810 case IrInstSrcIdSaveErrRetAddr:
28916 return ir_analyze_instruction_atomic_store(ira, (IrInstructionAtomicStore *)instruction);29811 return ir_analyze_instruction_save_err_ret_addr(ira, (IrInstSrcSaveErrRetAddr *)instruction);
28917 case IrInstructionIdSaveErrRetAddr:29812 case IrInstSrcIdAddImplicitReturnType:
28918 return ir_analyze_instruction_save_err_ret_addr(ira, (IrInstructionSaveErrRetAddr *)instruction);29813 return ir_analyze_instruction_add_implicit_return_type(ira, (IrInstSrcAddImplicitReturnType *)instruction);
28919 case IrInstructionIdAddImplicitReturnType:29814 case IrInstSrcIdFloatOp:
28920 return ir_analyze_instruction_add_implicit_return_type(ira, (IrInstructionAddImplicitReturnType *)instruction);29815 return ir_analyze_instruction_float_op(ira, (IrInstSrcFloatOp *)instruction);
28921 case IrInstructionIdFloatOp:29816 case IrInstSrcIdMulAdd:
28922 return ir_analyze_instruction_float_op(ira, (IrInstructionFloatOp *)instruction);29817 return ir_analyze_instruction_mul_add(ira, (IrInstSrcMulAdd *)instruction);
28923 case IrInstructionIdMulAdd:29818 case IrInstSrcIdIntToErr:
28924 return ir_analyze_instruction_mul_add(ira, (IrInstructionMulAdd *)instruction);29819 return ir_analyze_instruction_int_to_err(ira, (IrInstSrcIntToErr *)instruction);
28925 case IrInstructionIdIntToErr:29820 case IrInstSrcIdErrToInt:
28926 return ir_analyze_instruction_int_to_err(ira, (IrInstructionIntToErr *)instruction);29821 return ir_analyze_instruction_err_to_int(ira, (IrInstSrcErrToInt *)instruction);
28927 case IrInstructionIdErrToInt:29822 case IrInstSrcIdIntToEnum:
28928 return ir_analyze_instruction_err_to_int(ira, (IrInstructionErrToInt *)instruction);29823 return ir_analyze_instruction_int_to_enum(ira, (IrInstSrcIntToEnum *)instruction);
28929 case IrInstructionIdIntToEnum:29824 case IrInstSrcIdEnumToInt:
28930 return ir_analyze_instruction_int_to_enum(ira, (IrInstructionIntToEnum *)instruction);29825 return ir_analyze_instruction_enum_to_int(ira, (IrInstSrcEnumToInt *)instruction);
28931 case IrInstructionIdEnumToInt:29826 case IrInstSrcIdCheckRuntimeScope:
28932 return ir_analyze_instruction_enum_to_int(ira, (IrInstructionEnumToInt *)instruction);29827 return ir_analyze_instruction_check_runtime_scope(ira, (IrInstSrcCheckRuntimeScope *)instruction);
28933 case IrInstructionIdCheckRuntimeScope:29828 case IrInstSrcIdHasDecl:
28934 return ir_analyze_instruction_check_runtime_scope(ira, (IrInstructionCheckRuntimeScope *)instruction);29829 return ir_analyze_instruction_has_decl(ira, (IrInstSrcHasDecl *)instruction);
28935 case IrInstructionIdHasDecl:29830 case IrInstSrcIdUndeclaredIdent:
28936 return ir_analyze_instruction_has_decl(ira, (IrInstructionHasDecl *)instruction);29831 return ir_analyze_instruction_undeclared_ident(ira, (IrInstSrcUndeclaredIdent *)instruction);
28937 case IrInstructionIdUndeclaredIdent:29832 case IrInstSrcIdAlloca:
28938 return ir_analyze_instruction_undeclared_ident(ira, (IrInstructionUndeclaredIdent *)instruction);
28939 case IrInstructionIdAllocaSrc:
28940 return nullptr;29833 return nullptr;
28941 case IrInstructionIdEndExpr:29834 case IrInstSrcIdEndExpr:
28942 return ir_analyze_instruction_end_expr(ira, (IrInstructionEndExpr *)instruction);29835 return ir_analyze_instruction_end_expr(ira, (IrInstSrcEndExpr *)instruction);
28943 case IrInstructionIdBitCastSrc:29836 case IrInstSrcIdBitCast:
28944 return ir_analyze_instruction_bit_cast_src(ira, (IrInstructionBitCastSrc *)instruction);29837 return ir_analyze_instruction_bit_cast_src(ira, (IrInstSrcBitCast *)instruction);
28945 case IrInstructionIdUnionInitNamedField:29838 case IrInstSrcIdUnionInitNamedField:
28946 return ir_analyze_instruction_union_init_named_field(ira, (IrInstructionUnionInitNamedField *)instruction);29839 return ir_analyze_instruction_union_init_named_field(ira, (IrInstSrcUnionInitNamedField *)instruction);
28947 case IrInstructionIdSuspendBegin:29840 case IrInstSrcIdSuspendBegin:
28948 return ir_analyze_instruction_suspend_begin(ira, (IrInstructionSuspendBegin *)instruction);29841 return ir_analyze_instruction_suspend_begin(ira, (IrInstSrcSuspendBegin *)instruction);
28949 case IrInstructionIdSuspendFinish:29842 case IrInstSrcIdSuspendFinish:
28950 return ir_analyze_instruction_suspend_finish(ira, (IrInstructionSuspendFinish *)instruction);29843 return ir_analyze_instruction_suspend_finish(ira, (IrInstSrcSuspendFinish *)instruction);
28951 case IrInstructionIdResume:29844 case IrInstSrcIdResume:
28952 return ir_analyze_instruction_resume(ira, (IrInstructionResume *)instruction);29845 return ir_analyze_instruction_resume(ira, (IrInstSrcResume *)instruction);
28953 case IrInstructionIdAwaitSrc:29846 case IrInstSrcIdAwait:
28954 return ir_analyze_instruction_await(ira, (IrInstructionAwaitSrc *)instruction);29847 return ir_analyze_instruction_await(ira, (IrInstSrcAwait *)instruction);
28955 case IrInstructionIdSpillBegin:29848 case IrInstSrcIdSpillBegin:
28956 return ir_analyze_instruction_spill_begin(ira, (IrInstructionSpillBegin *)instruction);29849 return ir_analyze_instruction_spill_begin(ira, (IrInstSrcSpillBegin *)instruction);
28957 case IrInstructionIdSpillEnd:29850 case IrInstSrcIdSpillEnd:
28958 return ir_analyze_instruction_spill_end(ira, (IrInstructionSpillEnd *)instruction);29851 return ir_analyze_instruction_spill_end(ira, (IrInstSrcSpillEnd *)instruction);
28959 }29852 }
28960 zig_unreachable();29853 zig_unreachable();
28961}29854}
2896229855
28963// This function attempts to evaluate IR code while doing type checking and other analysis.29856// This function attempts to evaluate IR code while doing type checking and other analysis.
28964// It emits a new IrExecutable which is partially evaluated IR code.29857// It emits to a new IrExecutableGen which is partially evaluated IR code.
28965ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec,29858ZigType *ir_analyze(CodeGen *codegen, IrExecutableSrc *old_exec, IrExecutableGen *new_exec,
28966 ZigType *expected_type, AstNode *expected_type_source_node)29859 ZigType *expected_type, AstNode *expected_type_source_node, ZigValue *result_ptr)
28967{29860{
28968 assert(old_exec->first_err_trace_msg == nullptr);29861 assert(old_exec->first_err_trace_msg == nullptr);
28969 assert(expected_type == nullptr || !type_is_invalid(expected_type));29862 assert(expected_type == nullptr || !type_is_invalid(expected_type));
...@@ -28982,24 +29875,31 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -28982,24 +29875,31 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
28982 ira->new_irb.codegen = codegen;29875 ira->new_irb.codegen = codegen;
28983 ira->new_irb.exec = new_exec;29876 ira->new_irb.exec = new_exec;
2898429877
28985 ZigValue *vals = create_const_vals(ira->old_irb.exec->mem_slot_count);29878 IrBasicBlockSrc *old_entry_bb = ira->old_irb.exec->basic_block_list.at(0);
28986 ira->exec_context.mem_slot_list.resize(ira->old_irb.exec->mem_slot_count);29879 IrBasicBlockGen *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr);
28987 for (size_t i = 0; i < ira->exec_context.mem_slot_list.length; i += 1) {29880 ir_ref_bb_gen(new_entry_bb);
28988 ira->exec_context.mem_slot_list.items[i] = &vals[i];
28989 }
28990
28991 IrBasicBlock *old_entry_bb = ira->old_irb.exec->basic_block_list.at(0);
28992 IrBasicBlock *new_entry_bb = ir_get_new_bb(ira, old_entry_bb, nullptr);
28993 ir_ref_bb(new_entry_bb);
28994 ira->new_irb.current_basic_block = new_entry_bb;29881 ira->new_irb.current_basic_block = new_entry_bb;
28995 ira->old_bb_index = 0;29882 ira->old_bb_index = 0;
2899629883
28997 ir_start_bb(ira, old_entry_bb, nullptr);29884 ir_start_bb(ira, old_entry_bb, nullptr);
2899829885
29886 if (result_ptr != nullptr) {
29887 assert(result_ptr->type->id == ZigTypeIdPointer);
29888 IrInstGenConst *const_inst = ir_create_inst_noval<IrInstGenConst>(
29889 &ira->new_irb, new_exec->begin_scope, new_exec->source_node);
29890 const_inst->base.value = result_ptr;
29891 ira->return_ptr = &const_inst->base;
29892 } else {
29893 assert(new_exec->begin_scope != nullptr);
29894 assert(new_exec->source_node != nullptr);
29895 ira->return_ptr = ir_build_return_ptr(ira, new_exec->begin_scope, new_exec->source_node,
29896 get_pointer_to_type(codegen, expected_type, false));
29897 }
29898
28999 while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) {29899 while (ira->old_bb_index < ira->old_irb.exec->basic_block_list.length) {
29000 IrInstruction *old_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index);29900 IrInstSrc *old_instruction = ira->old_irb.current_basic_block->instruction_list.at(ira->instruction_index);
2900129901
29002 if (old_instruction->ref_count == 0 && !ir_has_side_effects(old_instruction)) {29902 if (old_instruction->base.ref_count == 0 && !ir_inst_src_has_side_effects(old_instruction)) {
29003 ira->instruction_index += 1;29903 ira->instruction_index += 1;
29004 continue;29904 continue;
29005 }29905 }
...@@ -29008,14 +29908,14 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -29008,14 +29908,14 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
29008 fprintf(stderr, "~ ");29908 fprintf(stderr, "~ ");
29009 old_instruction->src();29909 old_instruction->src();
29010 fprintf(stderr, "~ ");29910 fprintf(stderr, "~ ");
29011 ir_print_instruction(codegen, stderr, old_instruction, 0, IrPassSrc);29911 ir_print_inst_src(codegen, stderr, old_instruction, 0);
29012 bool want_break = false;29912 bool want_break = false;
29013 if (ira->break_debug_id == old_instruction->debug_id) {29913 if (ira->break_debug_id == old_instruction->base.debug_id) {
29014 want_break = true;29914 want_break = true;
29015 } else if (old_instruction->source_node != nullptr) {29915 } else if (old_instruction->base.source_node != nullptr) {
29016 for (size_t i = 0; i < dbg_ir_breakpoints_count; i += 1) {29916 for (size_t i = 0; i < dbg_ir_breakpoints_count; i += 1) {
29017 if (dbg_ir_breakpoints_buf[i].line == old_instruction->source_node->line + 1 &&29917 if (dbg_ir_breakpoints_buf[i].line == old_instruction->base.source_node->line + 1 &&
29018 buf_ends_with_str(old_instruction->source_node->owner->data.structure.root_struct->path,29918 buf_ends_with_str(old_instruction->base.source_node->owner->data.structure.root_struct->path,
29019 dbg_ir_breakpoints_buf[i].src_file))29919 dbg_ir_breakpoints_buf[i].src_file))
29020 {29920 {
29021 want_break = true;29921 want_break = true;
...@@ -29024,9 +29924,9 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -29024,9 +29924,9 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
29024 }29924 }
29025 if (want_break) BREAKPOINT;29925 if (want_break) BREAKPOINT;
29026 }29926 }
29027 IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction);29927 IrInstGen *new_instruction = ir_analyze_instruction_base(ira, old_instruction);
29028 if (new_instruction != nullptr) {29928 if (new_instruction != nullptr) {
29029 ir_assert(new_instruction->value->type != nullptr || new_instruction->value->type != nullptr, old_instruction);29929 ir_assert(new_instruction->value->type != nullptr || new_instruction->value->type != nullptr, &old_instruction->base);
29030 old_instruction->child = new_instruction;29930 old_instruction->child = new_instruction;
2903129931
29032 if (type_is_invalid(new_instruction->value->type)) {29932 if (type_is_invalid(new_instruction->value->type)) {
...@@ -29040,19 +29940,19 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -29040,19 +29940,19 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
29040 new_exec->first_err_trace_msg = ira->codegen->trace_err;29940 new_exec->first_err_trace_msg = ira->codegen->trace_err;
29041 }29941 }
29042 if (new_exec->first_err_trace_msg != nullptr &&29942 if (new_exec->first_err_trace_msg != nullptr &&
29043 !old_instruction->source_node->already_traced_this_node)29943 !old_instruction->base.source_node->already_traced_this_node)
29044 {29944 {
29045 old_instruction->source_node->already_traced_this_node = true;29945 old_instruction->base.source_node->already_traced_this_node = true;
29046 new_exec->first_err_trace_msg = add_error_note(ira->codegen, new_exec->first_err_trace_msg,29946 new_exec->first_err_trace_msg = add_error_note(ira->codegen, new_exec->first_err_trace_msg,
29047 old_instruction->source_node, buf_create_from_str("referenced here"));29947 old_instruction->base.source_node, buf_create_from_str("referenced here"));
29048 }29948 }
29049 return ira->codegen->builtin_types.entry_invalid;29949 return ira->codegen->builtin_types.entry_invalid;
29050 } else if (ira->codegen->verbose_ir) {29950 } else if (ira->codegen->verbose_ir) {
29051 fprintf(stderr, "-> ");29951 fprintf(stderr, "-> ");
29052 if (instr_is_unreachable(new_instruction)) {29952 if (new_instruction->value->type->id == ZigTypeIdUnreachable) {
29053 fprintf(stderr, "(noreturn)\n");29953 fprintf(stderr, "(noreturn)\n");
29054 } else {29954 } else {
29055 ir_print_instruction(codegen, stderr, new_instruction, 0, IrPassGen);29955 ir_print_inst_gen(codegen, stderr, new_instruction, 0);
29056 }29956 }
29057 }29957 }
2905829958
...@@ -29092,204 +29992,280 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_...@@ -29092,204 +29992,280 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_
29092 return res_type;29992 return res_type;
29093}29993}
2909429994
29095bool ir_has_side_effects(IrInstruction *instruction) {29995bool ir_inst_gen_has_side_effects(IrInstGen *instruction) {
29096 switch (instruction->id) {29996 switch (instruction->id) {
29097 case IrInstructionIdInvalid:29997 case IrInstGenIdInvalid:
29098 zig_unreachable();29998 zig_unreachable();
29099 case IrInstructionIdBr:29999 case IrInstGenIdBr:
29100 case IrInstructionIdCondBr:30000 case IrInstGenIdCondBr:
29101 case IrInstructionIdSwitchBr:30001 case IrInstGenIdSwitchBr:
29102 case IrInstructionIdDeclVarSrc:30002 case IrInstGenIdDeclVar:
29103 case IrInstructionIdDeclVarGen:30003 case IrInstGenIdStorePtr:
29104 case IrInstructionIdStorePtr:30004 case IrInstGenIdVectorStoreElem:
29105 case IrInstructionIdVectorStoreElem:30005 case IrInstGenIdCall:
29106 case IrInstructionIdCallExtra:30006 case IrInstGenIdReturn:
29107 case IrInstructionIdCallSrc:30007 case IrInstGenIdUnreachable:
29108 case IrInstructionIdCallSrcArgs:30008 case IrInstGenIdFence:
29109 case IrInstructionIdCallGen:30009 case IrInstGenIdMemset:
29110 case IrInstructionIdReturn:30010 case IrInstGenIdMemcpy:
29111 case IrInstructionIdUnreachable:30011 case IrInstGenIdBreakpoint:
29112 case IrInstructionIdSetCold:30012 case IrInstGenIdOverflowOp: // TODO when we support multiple returns this can be side effect free
29113 case IrInstructionIdSetRuntimeSafety:30013 case IrInstGenIdPanic:
29114 case IrInstructionIdSetFloatMode:30014 case IrInstGenIdSaveErrRetAddr:
29115 case IrInstructionIdImport:30015 case IrInstGenIdAtomicRmw:
29116 case IrInstructionIdCompileErr:30016 case IrInstGenIdAtomicStore:
29117 case IrInstructionIdCompileLog:30017 case IrInstGenIdCmpxchg:
29118 case IrInstructionIdCImport:30018 case IrInstGenIdAssertZero:
29119 case IrInstructionIdCInclude:30019 case IrInstGenIdAssertNonNull:
29120 case IrInstructionIdCDefine:30020 case IrInstGenIdResizeSlice:
29121 case IrInstructionIdCUndef:30021 case IrInstGenIdPtrOfArrayToSlice:
29122 case IrInstructionIdFence:30022 case IrInstGenIdSlice:
29123 case IrInstructionIdMemset:30023 case IrInstGenIdOptionalWrap:
29124 case IrInstructionIdMemcpy:30024 case IrInstGenIdVectorToArray:
29125 case IrInstructionIdBreakpoint:30025 case IrInstGenIdSuspendBegin:
29126 case IrInstructionIdOverflowOp: // TODO when we support multiple returns this can be side effect free30026 case IrInstGenIdSuspendFinish:
29127 case IrInstructionIdCheckSwitchProngs:30027 case IrInstGenIdResume:
29128 case IrInstructionIdCheckStatementIsVoid:30028 case IrInstGenIdAwait:
29129 case IrInstructionIdCheckRuntimeScope:30029 case IrInstGenIdSpillBegin:
29130 case IrInstructionIdPanic:
29131 case IrInstructionIdSetEvalBranchQuota:
29132 case IrInstructionIdPtrType:
29133 case IrInstructionIdSetAlignStack:
29134 case IrInstructionIdExport:
29135 case IrInstructionIdSaveErrRetAddr:
29136 case IrInstructionIdAddImplicitReturnType:
29137 case IrInstructionIdAtomicRmw:
29138 case IrInstructionIdAtomicStore:
29139 case IrInstructionIdCmpxchgGen:
29140 case IrInstructionIdCmpxchgSrc:
29141 case IrInstructionIdAssertZero:
29142 case IrInstructionIdAssertNonNull:
29143 case IrInstructionIdResizeSlice:
29144 case IrInstructionIdUndeclaredIdent:
29145 case IrInstructionIdEndExpr:
29146 case IrInstructionIdPtrOfArrayToSlice:
29147 case IrInstructionIdSliceGen:
29148 case IrInstructionIdOptionalWrap:
29149 case IrInstructionIdVectorToArray:
29150 case IrInstructionIdResetResult:
29151 case IrInstructionIdSuspendBegin:
29152 case IrInstructionIdSuspendFinish:
29153 case IrInstructionIdResume:
29154 case IrInstructionIdAwaitSrc:
29155 case IrInstructionIdAwaitGen:
29156 case IrInstructionIdSpillBegin:
29157 return true;30030 return true;
2915830031
29159 case IrInstructionIdPhi:30032 case IrInstGenIdPhi:
29160 case IrInstructionIdUnOp:30033 case IrInstGenIdBinOp:
29161 case IrInstructionIdBinOp:30034 case IrInstGenIdConst:
29162 case IrInstructionIdMergeErrSets:30035 case IrInstGenIdCast:
29163 case IrInstructionIdLoadPtr:30036 case IrInstGenIdElemPtr:
29164 case IrInstructionIdConst:30037 case IrInstGenIdVarPtr:
29165 case IrInstructionIdCast:30038 case IrInstGenIdReturnPtr:
29166 case IrInstructionIdContainerInitList:30039 case IrInstGenIdStructFieldPtr:
29167 case IrInstructionIdContainerInitFields:30040 case IrInstGenIdTestNonNull:
29168 case IrInstructionIdUnionInitNamedField:30041 case IrInstGenIdClz:
29169 case IrInstructionIdFieldPtr:30042 case IrInstGenIdCtz:
29170 case IrInstructionIdElemPtr:30043 case IrInstGenIdPopCount:
29171 case IrInstructionIdVarPtr:30044 case IrInstGenIdBswap:
29172 case IrInstructionIdReturnPtr:30045 case IrInstGenIdBitReverse:
29173 case IrInstructionIdTypeOf:30046 case IrInstGenIdUnionTag:
29174 case IrInstructionIdStructFieldPtr:30047 case IrInstGenIdTruncate:
29175 case IrInstructionIdArrayType:30048 case IrInstGenIdShuffleVector:
29176 case IrInstructionIdSliceType:30049 case IrInstGenIdSplat:
29177 case IrInstructionIdAnyFrameType:30050 case IrInstGenIdBoolNot:
29178 case IrInstructionIdSizeOf:30051 case IrInstGenIdReturnAddress:
29179 case IrInstructionIdTestNonNull:30052 case IrInstGenIdFrameAddress:
29180 case IrInstructionIdOptionalUnwrapPtr:30053 case IrInstGenIdFrameHandle:
29181 case IrInstructionIdClz:30054 case IrInstGenIdFrameSize:
29182 case IrInstructionIdCtz:30055 case IrInstGenIdTestErr:
29183 case IrInstructionIdPopCount:30056 case IrInstGenIdPtrCast:
29184 case IrInstructionIdBswap:30057 case IrInstGenIdBitCast:
29185 case IrInstructionIdBitReverse:30058 case IrInstGenIdWidenOrShorten:
29186 case IrInstructionIdSwitchVar:30059 case IrInstGenIdPtrToInt:
29187 case IrInstructionIdSwitchElseVar:30060 case IrInstGenIdIntToPtr:
29188 case IrInstructionIdSwitchTarget:30061 case IrInstGenIdIntToEnum:
29189 case IrInstructionIdUnionTag:30062 case IrInstGenIdIntToErr:
29190 case IrInstructionIdRef:30063 case IrInstGenIdErrToInt:
29191 case IrInstructionIdEmbedFile:30064 case IrInstGenIdErrName:
29192 case IrInstructionIdTruncate:30065 case IrInstGenIdTagName:
29193 case IrInstructionIdIntType:30066 case IrInstGenIdFieldParentPtr:
29194 case IrInstructionIdVectorType:30067 case IrInstGenIdAlignCast:
29195 case IrInstructionIdShuffleVector:30068 case IrInstGenIdErrorReturnTrace:
29196 case IrInstructionIdSplatSrc:30069 case IrInstGenIdFloatOp:
29197 case IrInstructionIdSplatGen:30070 case IrInstGenIdMulAdd:
29198 case IrInstructionIdBoolNot:30071 case IrInstGenIdAtomicLoad:
29199 case IrInstructionIdSliceSrc:30072 case IrInstGenIdArrayToVector:
29200 case IrInstructionIdMemberCount:30073 case IrInstGenIdAlloca:
29201 case IrInstructionIdMemberType:30074 case IrInstGenIdSpillEnd:
29202 case IrInstructionIdMemberName:30075 case IrInstGenIdVectorExtractElem:
29203 case IrInstructionIdAlignOf:30076 case IrInstGenIdBinaryNot:
29204 case IrInstructionIdReturnAddress:30077 case IrInstGenIdNegation:
29205 case IrInstructionIdFrameAddress:30078 case IrInstGenIdNegationWrapping:
29206 case IrInstructionIdFrameHandle:
29207 case IrInstructionIdFrameType:
29208 case IrInstructionIdFrameSizeSrc:
29209 case IrInstructionIdFrameSizeGen:
29210 case IrInstructionIdTestErrSrc:
29211 case IrInstructionIdTestErrGen:
29212 case IrInstructionIdFnProto:
29213 case IrInstructionIdTestComptime:
29214 case IrInstructionIdPtrCastSrc:
29215 case IrInstructionIdPtrCastGen:
29216 case IrInstructionIdBitCastSrc:
29217 case IrInstructionIdBitCastGen:
29218 case IrInstructionIdWidenOrShorten:
29219 case IrInstructionIdPtrToInt:
29220 case IrInstructionIdIntToPtr:
29221 case IrInstructionIdIntToEnum:
29222 case IrInstructionIdIntToErr:
29223 case IrInstructionIdErrToInt:
29224 case IrInstructionIdDeclRef:
29225 case IrInstructionIdErrName:
29226 case IrInstructionIdTypeName:
29227 case IrInstructionIdTagName:
29228 case IrInstructionIdFieldParentPtr:
29229 case IrInstructionIdByteOffsetOf:
29230 case IrInstructionIdBitOffsetOf:
29231 case IrInstructionIdTypeInfo:
29232 case IrInstructionIdType:
29233 case IrInstructionIdHasField:
29234 case IrInstructionIdTypeId:
29235 case IrInstructionIdAlignCast:
29236 case IrInstructionIdImplicitCast:
29237 case IrInstructionIdResolveResult:
29238 case IrInstructionIdOpaqueType:
29239 case IrInstructionIdArgType:
29240 case IrInstructionIdTagType:
29241 case IrInstructionIdErrorReturnTrace:
29242 case IrInstructionIdErrorUnion:
29243 case IrInstructionIdFloatOp:
29244 case IrInstructionIdMulAdd:
29245 case IrInstructionIdAtomicLoad:
29246 case IrInstructionIdIntCast:
29247 case IrInstructionIdFloatCast:
29248 case IrInstructionIdErrSetCast:
29249 case IrInstructionIdIntToFloat:
29250 case IrInstructionIdFloatToInt:
29251 case IrInstructionIdBoolToInt:
29252 case IrInstructionIdFromBytes:
29253 case IrInstructionIdToBytes:
29254 case IrInstructionIdEnumToInt:
29255 case IrInstructionIdArrayToVector:
29256 case IrInstructionIdHasDecl:
29257 case IrInstructionIdAllocaSrc:
29258 case IrInstructionIdAllocaGen:
29259 case IrInstructionIdSpillEnd:
29260 case IrInstructionIdVectorExtractElem:
29261 return false;30079 return false;
2926230080
29263 case IrInstructionIdAsmSrc:30081 case IrInstGenIdAsm:
29264 {30082 {
29265 IrInstructionAsmSrc *asm_instruction = (IrInstructionAsmSrc *)instruction;30083 IrInstGenAsm *asm_instruction = (IrInstGenAsm *)instruction;
29266 return asm_instruction->has_side_effects;30084 return asm_instruction->has_side_effects;
29267 }30085 }
30086 case IrInstGenIdUnwrapErrPayload:
30087 {
30088 IrInstGenUnwrapErrPayload *unwrap_err_payload_instruction =
30089 (IrInstGenUnwrapErrPayload *)instruction;
30090 return unwrap_err_payload_instruction->safety_check_on ||
30091 unwrap_err_payload_instruction->initializing;
30092 }
30093 case IrInstGenIdUnwrapErrCode:
30094 return reinterpret_cast<IrInstGenUnwrapErrCode *>(instruction)->initializing;
30095 case IrInstGenIdUnionFieldPtr:
30096 return reinterpret_cast<IrInstGenUnionFieldPtr *>(instruction)->initializing;
30097 case IrInstGenIdOptionalUnwrapPtr:
30098 return reinterpret_cast<IrInstGenOptionalUnwrapPtr *>(instruction)->initializing;
30099 case IrInstGenIdErrWrapPayload:
30100 return reinterpret_cast<IrInstGenErrWrapPayload *>(instruction)->result_loc != nullptr;
30101 case IrInstGenIdErrWrapCode:
30102 return reinterpret_cast<IrInstGenErrWrapCode *>(instruction)->result_loc != nullptr;
30103 case IrInstGenIdLoadPtr:
30104 return reinterpret_cast<IrInstGenLoadPtr *>(instruction)->result_loc != nullptr;
30105 case IrInstGenIdRef:
30106 return reinterpret_cast<IrInstGenRef *>(instruction)->result_loc != nullptr;
30107 }
30108 zig_unreachable();
30109}
30110
30111bool ir_inst_src_has_side_effects(IrInstSrc *instruction) {
30112 switch (instruction->id) {
30113 case IrInstSrcIdInvalid:
30114 zig_unreachable();
30115 case IrInstSrcIdBr:
30116 case IrInstSrcIdCondBr:
30117 case IrInstSrcIdSwitchBr:
30118 case IrInstSrcIdDeclVar:
30119 case IrInstSrcIdStorePtr:
30120 case IrInstSrcIdCallExtra:
30121 case IrInstSrcIdCall:
30122 case IrInstSrcIdCallArgs:
30123 case IrInstSrcIdReturn:
30124 case IrInstSrcIdUnreachable:
30125 case IrInstSrcIdSetCold:
30126 case IrInstSrcIdSetRuntimeSafety:
30127 case IrInstSrcIdSetFloatMode:
30128 case IrInstSrcIdImport:
30129 case IrInstSrcIdCompileErr:
30130 case IrInstSrcIdCompileLog:
30131 case IrInstSrcIdCImport:
30132 case IrInstSrcIdCInclude:
30133 case IrInstSrcIdCDefine:
30134 case IrInstSrcIdCUndef:
30135 case IrInstSrcIdFence:
30136 case IrInstSrcIdMemset:
30137 case IrInstSrcIdMemcpy:
30138 case IrInstSrcIdBreakpoint:
30139 case IrInstSrcIdOverflowOp: // TODO when we support multiple returns this can be side effect free
30140 case IrInstSrcIdCheckSwitchProngs:
30141 case IrInstSrcIdCheckStatementIsVoid:
30142 case IrInstSrcIdCheckRuntimeScope:
30143 case IrInstSrcIdPanic:
30144 case IrInstSrcIdSetEvalBranchQuota:
30145 case IrInstSrcIdPtrType:
30146 case IrInstSrcIdSetAlignStack:
30147 case IrInstSrcIdExport:
30148 case IrInstSrcIdSaveErrRetAddr:
30149 case IrInstSrcIdAddImplicitReturnType:
30150 case IrInstSrcIdAtomicRmw:
30151 case IrInstSrcIdAtomicStore:
30152 case IrInstSrcIdCmpxchg:
30153 case IrInstSrcIdUndeclaredIdent:
30154 case IrInstSrcIdEndExpr:
30155 case IrInstSrcIdResetResult:
30156 case IrInstSrcIdSuspendBegin:
30157 case IrInstSrcIdSuspendFinish:
30158 case IrInstSrcIdResume:
30159 case IrInstSrcIdAwait:
30160 case IrInstSrcIdSpillBegin:
30161 return true;
30162
30163 case IrInstSrcIdPhi:
30164 case IrInstSrcIdUnOp:
30165 case IrInstSrcIdBinOp:
30166 case IrInstSrcIdMergeErrSets:
30167 case IrInstSrcIdLoadPtr:
30168 case IrInstSrcIdConst:
30169 case IrInstSrcIdContainerInitList:
30170 case IrInstSrcIdContainerInitFields:
30171 case IrInstSrcIdUnionInitNamedField:
30172 case IrInstSrcIdFieldPtr:
30173 case IrInstSrcIdElemPtr:
30174 case IrInstSrcIdVarPtr:
30175 case IrInstSrcIdTypeOf:
30176 case IrInstSrcIdArrayType:
30177 case IrInstSrcIdSliceType:
30178 case IrInstSrcIdAnyFrameType:
30179 case IrInstSrcIdSizeOf:
30180 case IrInstSrcIdTestNonNull:
30181 case IrInstSrcIdOptionalUnwrapPtr:
30182 case IrInstSrcIdClz:
30183 case IrInstSrcIdCtz:
30184 case IrInstSrcIdPopCount:
30185 case IrInstSrcIdBswap:
30186 case IrInstSrcIdBitReverse:
30187 case IrInstSrcIdSwitchVar:
30188 case IrInstSrcIdSwitchElseVar:
30189 case IrInstSrcIdSwitchTarget:
30190 case IrInstSrcIdRef:
30191 case IrInstSrcIdEmbedFile:
30192 case IrInstSrcIdTruncate:
30193 case IrInstSrcIdIntType:
30194 case IrInstSrcIdVectorType:
30195 case IrInstSrcIdShuffleVector:
30196 case IrInstSrcIdSplat:
30197 case IrInstSrcIdBoolNot:
30198 case IrInstSrcIdSlice:
30199 case IrInstSrcIdMemberCount:
30200 case IrInstSrcIdMemberType:
30201 case IrInstSrcIdMemberName:
30202 case IrInstSrcIdAlignOf:
30203 case IrInstSrcIdReturnAddress:
30204 case IrInstSrcIdFrameAddress:
30205 case IrInstSrcIdFrameHandle:
30206 case IrInstSrcIdFrameType:
30207 case IrInstSrcIdFrameSize:
30208 case IrInstSrcIdTestErr:
30209 case IrInstSrcIdFnProto:
30210 case IrInstSrcIdTestComptime:
30211 case IrInstSrcIdPtrCast:
30212 case IrInstSrcIdBitCast:
30213 case IrInstSrcIdPtrToInt:
30214 case IrInstSrcIdIntToPtr:
30215 case IrInstSrcIdIntToEnum:
30216 case IrInstSrcIdIntToErr:
30217 case IrInstSrcIdErrToInt:
30218 case IrInstSrcIdDeclRef:
30219 case IrInstSrcIdErrName:
30220 case IrInstSrcIdTypeName:
30221 case IrInstSrcIdTagName:
30222 case IrInstSrcIdFieldParentPtr:
30223 case IrInstSrcIdByteOffsetOf:
30224 case IrInstSrcIdBitOffsetOf:
30225 case IrInstSrcIdTypeInfo:
30226 case IrInstSrcIdType:
30227 case IrInstSrcIdHasField:
30228 case IrInstSrcIdTypeId:
30229 case IrInstSrcIdAlignCast:
30230 case IrInstSrcIdImplicitCast:
30231 case IrInstSrcIdResolveResult:
30232 case IrInstSrcIdOpaqueType:
30233 case IrInstSrcIdArgType:
30234 case IrInstSrcIdTagType:
30235 case IrInstSrcIdErrorReturnTrace:
30236 case IrInstSrcIdErrorUnion:
30237 case IrInstSrcIdFloatOp:
30238 case IrInstSrcIdMulAdd:
30239 case IrInstSrcIdAtomicLoad:
30240 case IrInstSrcIdIntCast:
30241 case IrInstSrcIdFloatCast:
30242 case IrInstSrcIdErrSetCast:
30243 case IrInstSrcIdIntToFloat:
30244 case IrInstSrcIdFloatToInt:
30245 case IrInstSrcIdBoolToInt:
30246 case IrInstSrcIdFromBytes:
30247 case IrInstSrcIdToBytes:
30248 case IrInstSrcIdEnumToInt:
30249 case IrInstSrcIdHasDecl:
30250 case IrInstSrcIdAlloca:
30251 case IrInstSrcIdSpillEnd:
30252 return false;
2926830253
29269 case IrInstructionIdAsmGen:30254 case IrInstSrcIdAsm:
29270 {30255 {
29271 IrInstructionAsmGen *asm_instruction = (IrInstructionAsmGen *)instruction;30256 IrInstSrcAsm *asm_instruction = (IrInstSrcAsm *)instruction;
29272 return asm_instruction->has_side_effects;30257 return asm_instruction->has_side_effects;
29273 }30258 }
29274 case IrInstructionIdUnwrapErrPayload:30259
30260 case IrInstSrcIdUnwrapErrPayload:
29275 {30261 {
29276 IrInstructionUnwrapErrPayload *unwrap_err_payload_instruction =30262 IrInstSrcUnwrapErrPayload *unwrap_err_payload_instruction =
29277 (IrInstructionUnwrapErrPayload *)instruction;30263 (IrInstSrcUnwrapErrPayload *)instruction;
29278 return unwrap_err_payload_instruction->safety_check_on ||30264 return unwrap_err_payload_instruction->safety_check_on ||
29279 unwrap_err_payload_instruction->initializing;30265 unwrap_err_payload_instruction->initializing;
29280 }30266 }
29281 case IrInstructionIdUnwrapErrCode:30267 case IrInstSrcIdUnwrapErrCode:
29282 return reinterpret_cast<IrInstructionUnwrapErrCode *>(instruction)->initializing;30268 return reinterpret_cast<IrInstSrcUnwrapErrCode *>(instruction)->initializing;
29283 case IrInstructionIdUnionFieldPtr:
29284 return reinterpret_cast<IrInstructionUnionFieldPtr *>(instruction)->initializing;
29285 case IrInstructionIdErrWrapPayload:
29286 return reinterpret_cast<IrInstructionErrWrapPayload *>(instruction)->result_loc != nullptr;
29287 case IrInstructionIdErrWrapCode:
29288 return reinterpret_cast<IrInstructionErrWrapCode *>(instruction)->result_loc != nullptr;
29289 case IrInstructionIdLoadPtrGen:
29290 return reinterpret_cast<IrInstructionLoadPtrGen *>(instruction)->result_loc != nullptr;
29291 case IrInstructionIdRefGen:
29292 return reinterpret_cast<IrInstructionRefGen *>(instruction)->result_loc != nullptr;
29293 }30269 }
29294 zig_unreachable();30270 zig_unreachable();
29295}30271}
...@@ -29323,14 +30299,14 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La...@@ -29323,14 +30299,14 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
29323 param_info->type = nullptr;30299 param_info->type = nullptr;
29324 return get_generic_fn_type(ira->codegen, &fn_type_id);30300 return get_generic_fn_type(ira->codegen, &fn_type_id);
29325 } else {30301 } else {
29326 IrInstruction *param_type_inst = lazy_fn_type->param_types[fn_type_id.next_param_index];30302 IrInstGen *param_type_inst = lazy_fn_type->param_types[fn_type_id.next_param_index];
29327 ZigType *param_type = ir_resolve_type(ira, param_type_inst);30303 ZigType *param_type = ir_resolve_type(ira, param_type_inst);
29328 if (type_is_invalid(param_type))30304 if (type_is_invalid(param_type))
29329 return nullptr;30305 return nullptr;
29330 switch (type_requires_comptime(ira->codegen, param_type)) {30306 switch (type_requires_comptime(ira->codegen, param_type)) {
29331 case ReqCompTimeYes:30307 case ReqCompTimeYes:
29332 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {30308 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
29333 ir_add_error(ira, param_type_inst,30309 ir_add_error(ira, &param_type_inst->base,
29334 buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'",30310 buf_sprintf("parameter of type '%s' not allowed in function with calling convention '%s'",
29335 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));30311 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));
29336 return nullptr;30312 return nullptr;
...@@ -29348,7 +30324,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La...@@ -29348,7 +30324,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
29348 if ((err = type_has_bits2(ira->codegen, param_type, &has_bits)))30324 if ((err = type_has_bits2(ira->codegen, param_type, &has_bits)))
29349 return nullptr;30325 return nullptr;
29350 if (!has_bits) {30326 if (!has_bits) {
29351 ir_add_error(ira, param_type_inst,30327 ir_add_error(ira, &param_type_inst->base,
29352 buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'",30328 buf_sprintf("parameter of type '%s' has 0 bits; not allowed in function with calling convention '%s'",
29353 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));30329 buf_ptr(&param_type->name), calling_convention_name(fn_type_id.cc)));
29354 return nullptr;30330 return nullptr;
...@@ -29367,7 +30343,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La...@@ -29367,7 +30343,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La
29367 if (type_is_invalid(fn_type_id.return_type))30343 if (type_is_invalid(fn_type_id.return_type))
29368 return nullptr;30344 return nullptr;
29369 if (fn_type_id.return_type->id == ZigTypeIdOpaque) {30345 if (fn_type_id.return_type->id == ZigTypeIdOpaque) {
29370 ir_add_error(ira, lazy_fn_type->return_type, buf_create_from_str("return type cannot be opaque"));30346 ir_add_error(ira, &lazy_fn_type->return_type->base, buf_create_from_str("return type cannot be opaque"));
29371 return nullptr;30347 return nullptr;
29372 }30348 }
2937330349
...@@ -29399,7 +30375,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29399,7 +30375,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29399 case ZigTypeIdBoundFn:30375 case ZigTypeIdBoundFn:
29400 case ZigTypeIdVoid:30376 case ZigTypeIdVoid:
29401 case ZigTypeIdOpaque:30377 case ZigTypeIdOpaque:
29402 ir_add_error(ira, lazy_align_of->target_type,30378 ir_add_error(ira, &lazy_align_of->target_type->base,
29403 buf_sprintf("no align available for type '%s'",30379 buf_sprintf("no align available for type '%s'",
29404 buf_ptr(&lazy_align_of->target_type->value->data.x_type->name)));30380 buf_ptr(&lazy_align_of->target_type->value->data.x_type->name)));
29405 return ErrorSemanticAnalyzeFail;30381 return ErrorSemanticAnalyzeFail;
...@@ -29449,7 +30425,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29449,7 +30425,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29449 case ZigTypeIdNull:30425 case ZigTypeIdNull:
29450 case ZigTypeIdBoundFn:30426 case ZigTypeIdBoundFn:
29451 case ZigTypeIdOpaque:30427 case ZigTypeIdOpaque:
29452 ir_add_error(ira, lazy_size_of->target_type,30428 ir_add_error(ira, &lazy_size_of->target_type->base,
29453 buf_sprintf("no size available for type '%s'",30429 buf_sprintf("no size available for type '%s'",
29454 buf_ptr(&lazy_size_of->target_type->value->data.x_type->name)));30430 buf_ptr(&lazy_size_of->target_type->value->data.x_type->name)));
29455 return ErrorSemanticAnalyzeFail;30431 return ErrorSemanticAnalyzeFail;
...@@ -29507,7 +30483,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29507,7 +30483,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29507 if (lazy_slice_type->sentinel != nullptr) {30483 if (lazy_slice_type->sentinel != nullptr) {
29508 if (type_is_invalid(lazy_slice_type->sentinel->value->type))30484 if (type_is_invalid(lazy_slice_type->sentinel->value->type))
29509 return ErrorSemanticAnalyzeFail;30485 return ErrorSemanticAnalyzeFail;
29510 IrInstruction *sentinel = ir_implicit_cast(ira, lazy_slice_type->sentinel, elem_type);30486 IrInstGen *sentinel = ir_implicit_cast(ira, lazy_slice_type->sentinel, elem_type);
29511 if (type_is_invalid(sentinel->value->type))30487 if (type_is_invalid(sentinel->value->type))
29512 return ErrorSemanticAnalyzeFail;30488 return ErrorSemanticAnalyzeFail;
29513 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);30489 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
...@@ -29530,7 +30506,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29530,7 +30506,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29530 case ZigTypeIdUndefined:30506 case ZigTypeIdUndefined:
29531 case ZigTypeIdNull:30507 case ZigTypeIdNull:
29532 case ZigTypeIdOpaque:30508 case ZigTypeIdOpaque:
29533 ir_add_error(ira, lazy_slice_type->elem_type,30509 ir_add_error(ira, &lazy_slice_type->elem_type->base,
29534 buf_sprintf("slice of type '%s' not allowed", buf_ptr(&elem_type->name)));30510 buf_sprintf("slice of type '%s' not allowed", buf_ptr(&elem_type->name)));
29535 return ErrorSemanticAnalyzeFail;30511 return ErrorSemanticAnalyzeFail;
29536 case ZigTypeIdMetaType:30512 case ZigTypeIdMetaType:
...@@ -29586,7 +30562,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29586,7 +30562,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29586 if (lazy_ptr_type->sentinel != nullptr) {30562 if (lazy_ptr_type->sentinel != nullptr) {
29587 if (type_is_invalid(lazy_ptr_type->sentinel->value->type))30563 if (type_is_invalid(lazy_ptr_type->sentinel->value->type))
29588 return ErrorSemanticAnalyzeFail;30564 return ErrorSemanticAnalyzeFail;
29589 IrInstruction *sentinel = ir_implicit_cast(ira, lazy_ptr_type->sentinel, elem_type);30565 IrInstGen *sentinel = ir_implicit_cast(ira, lazy_ptr_type->sentinel, elem_type);
29590 if (type_is_invalid(sentinel->value->type))30566 if (type_is_invalid(sentinel->value->type))
29591 return ErrorSemanticAnalyzeFail;30567 return ErrorSemanticAnalyzeFail;
29592 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);30568 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
...@@ -29603,11 +30579,11 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29603,11 +30579,11 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29603 }30579 }
2960430580
29605 if (elem_type->id == ZigTypeIdUnreachable) {30581 if (elem_type->id == ZigTypeIdUnreachable) {
29606 ir_add_error(ira, lazy_ptr_type->elem_type,30582 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
29607 buf_create_from_str("pointer to noreturn not allowed"));30583 buf_create_from_str("pointer to noreturn not allowed"));
29608 return ErrorSemanticAnalyzeFail;30584 return ErrorSemanticAnalyzeFail;
29609 } else if (elem_type->id == ZigTypeIdOpaque && lazy_ptr_type->ptr_len == PtrLenUnknown) {30585 } else if (elem_type->id == ZigTypeIdOpaque && lazy_ptr_type->ptr_len == PtrLenUnknown) {
29610 ir_add_error(ira, lazy_ptr_type->elem_type,30586 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
29611 buf_create_from_str("unknown-length pointer to opaque"));30587 buf_create_from_str("unknown-length pointer to opaque"));
29612 return ErrorSemanticAnalyzeFail;30588 return ErrorSemanticAnalyzeFail;
29613 } else if (lazy_ptr_type->ptr_len == PtrLenC) {30589 } else if (lazy_ptr_type->ptr_len == PtrLenC) {
...@@ -29615,16 +30591,16 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29615,16 +30591,16 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29615 if ((err = type_allowed_in_extern(ira->codegen, elem_type, &ok_type)))30591 if ((err = type_allowed_in_extern(ira->codegen, elem_type, &ok_type)))
29616 return err;30592 return err;
29617 if (!ok_type) {30593 if (!ok_type) {
29618 ir_add_error(ira, lazy_ptr_type->elem_type,30594 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
29619 buf_sprintf("C pointers cannot point to non-C-ABI-compatible type '%s'",30595 buf_sprintf("C pointers cannot point to non-C-ABI-compatible type '%s'",
29620 buf_ptr(&elem_type->name)));30596 buf_ptr(&elem_type->name)));
29621 return ErrorSemanticAnalyzeFail;30597 return ErrorSemanticAnalyzeFail;
29622 } else if (elem_type->id == ZigTypeIdOpaque) {30598 } else if (elem_type->id == ZigTypeIdOpaque) {
29623 ir_add_error(ira, lazy_ptr_type->elem_type,30599 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
29624 buf_sprintf("C pointers cannot point opaque types"));30600 buf_sprintf("C pointers cannot point opaque types"));
29625 return ErrorSemanticAnalyzeFail;30601 return ErrorSemanticAnalyzeFail;
29626 } else if (lazy_ptr_type->is_allowzero) {30602 } else if (lazy_ptr_type->is_allowzero) {
29627 ir_add_error(ira, lazy_ptr_type->elem_type,30603 ir_add_error(ira, &lazy_ptr_type->elem_type->base,
29628 buf_sprintf("C pointers always allow address zero"));30604 buf_sprintf("C pointers always allow address zero"));
29629 return ErrorSemanticAnalyzeFail;30605 return ErrorSemanticAnalyzeFail;
29630 }30606 }
...@@ -29662,7 +30638,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29662,7 +30638,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29662 case ZigTypeIdUndefined:30638 case ZigTypeIdUndefined:
29663 case ZigTypeIdNull:30639 case ZigTypeIdNull:
29664 case ZigTypeIdOpaque:30640 case ZigTypeIdOpaque:
29665 ir_add_error(ira, lazy_array_type->elem_type,30641 ir_add_error(ira, &lazy_array_type->elem_type->base,
29666 buf_sprintf("array of type '%s' not allowed",30642 buf_sprintf("array of type '%s' not allowed",
29667 buf_ptr(&elem_type->name)));30643 buf_ptr(&elem_type->name)));
29668 return ErrorSemanticAnalyzeFail;30644 return ErrorSemanticAnalyzeFail;
...@@ -29697,7 +30673,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29697,7 +30673,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29697 if (lazy_array_type->sentinel != nullptr) {30673 if (lazy_array_type->sentinel != nullptr) {
29698 if (type_is_invalid(lazy_array_type->sentinel->value->type))30674 if (type_is_invalid(lazy_array_type->sentinel->value->type))
29699 return ErrorSemanticAnalyzeFail;30675 return ErrorSemanticAnalyzeFail;
29700 IrInstruction *sentinel = ir_implicit_cast(ira, lazy_array_type->sentinel, elem_type);30676 IrInstGen *sentinel = ir_implicit_cast(ira, lazy_array_type->sentinel, elem_type);
29701 if (type_is_invalid(sentinel->value->type))30677 if (type_is_invalid(sentinel->value->type))
29702 return ErrorSemanticAnalyzeFail;30678 return ErrorSemanticAnalyzeFail;
29703 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);30679 sentinel_val = ir_resolve_const(ira, sentinel, UndefBad);
...@@ -29721,7 +30697,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29721,7 +30697,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29721 return ErrorSemanticAnalyzeFail;30697 return ErrorSemanticAnalyzeFail;
2972230698
29723 if (payload_type->id == ZigTypeIdOpaque || payload_type->id == ZigTypeIdUnreachable) {30699 if (payload_type->id == ZigTypeIdOpaque || payload_type->id == ZigTypeIdUnreachable) {
29724 ir_add_error(ira, lazy_opt_type->payload_type,30700 ir_add_error(ira, &lazy_opt_type->payload_type->base,
29725 buf_sprintf("type '%s' cannot be optional", buf_ptr(&payload_type->name)));30701 buf_sprintf("type '%s' cannot be optional", buf_ptr(&payload_type->name)));
29726 return ErrorSemanticAnalyzeFail;30702 return ErrorSemanticAnalyzeFail;
29727 }30703 }
...@@ -29763,7 +30739,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {...@@ -29763,7 +30739,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
29763 return ErrorSemanticAnalyzeFail;30739 return ErrorSemanticAnalyzeFail;
2976430740
29765 if (err_set_type->id != ZigTypeIdErrorSet) {30741 if (err_set_type->id != ZigTypeIdErrorSet) {
29766 ir_add_error(ira, lazy_err_union_type->err_set_type,30742 ir_add_error(ira, &lazy_err_union_type->err_set_type->base,
29767 buf_sprintf("expected error set type, found type '%s'",30743 buf_sprintf("expected error set type, found type '%s'",
29768 buf_ptr(&err_set_type->name)));30744 buf_ptr(&err_set_type->name)));
29769 return ErrorSemanticAnalyzeFail;30745 return ErrorSemanticAnalyzeFail;
...@@ -29799,8 +30775,8 @@ Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) {...@@ -29799,8 +30775,8 @@ Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) {
29799 return ErrorNone;30775 return ErrorNone;
29800}30776}
2980130777
29802void IrInstruction::src() {30778void IrInst::src() {
29803 IrInstruction *inst = this;30779 IrInst *inst = this;
29804 if (inst->source_node != nullptr) {30780 if (inst->source_node != nullptr) {
29805 inst->source_node->src();30781 inst->source_node->src();
29806 } else {30782 } else {
...@@ -29808,26 +30784,45 @@ void IrInstruction::src() {...@@ -29808,26 +30784,45 @@ void IrInstruction::src() {
29808 }30784 }
29809}30785}
2981030786
29811void IrInstruction::dump() {30787void IrInst::dump() {
29812 IrInstruction *inst = this;30788 this->src();
30789 fprintf(stderr, "IrInst(#%" PRIu32 ")\n", this->debug_id);
30790}
30791
30792void IrInstSrc::src() {
30793 this->base.src();
30794}
30795
30796void IrInstGen::src() {
30797 this->base.src();
30798}
30799
30800void IrInstSrc::dump() {
30801 IrInstSrc *inst = this;
29813 inst->src();30802 inst->src();
29814 IrPass pass = (inst->child == nullptr) ? IrPassGen : IrPassSrc;30803 if (inst->base.scope == nullptr) {
29815 if (inst->scope == nullptr) {
29816 fprintf(stderr, "(null scope)\n");30804 fprintf(stderr, "(null scope)\n");
29817 } else {30805 } else {
29818 ir_print_instruction(inst->scope->codegen, stderr, inst, 0, pass);30806 ir_print_inst_src(inst->base.scope->codegen, stderr, inst, 0);
29819 if (pass == IrPassSrc) {30807 fprintf(stderr, "-> ");
29820 fprintf(stderr, "-> ");30808 ir_print_inst_gen(inst->base.scope->codegen, stderr, inst->child, 0);
29821 ir_print_instruction(inst->scope->codegen, stderr, inst->child, 0, IrPassGen);30809 }
29822 }30810}
30811void IrInstGen::dump() {
30812 IrInstGen *inst = this;
30813 inst->src();
30814 if (inst->base.scope == nullptr) {
30815 fprintf(stderr, "(null scope)\n");
30816 } else {
30817 ir_print_inst_gen(inst->base.scope->codegen, stderr, inst, 0);
29823 }30818 }
29824}30819}
2982530820
29826void IrAnalyze::dump() {30821void IrAnalyze::dump() {
29827 ir_print(this->codegen, stderr, this->new_irb.exec, 0, IrPassGen);30822 ir_print_gen(this->codegen, stderr, this->new_irb.exec, 0);
29828 if (this->new_irb.current_basic_block != nullptr) {30823 if (this->new_irb.current_basic_block != nullptr) {
29829 fprintf(stderr, "Current basic block:\n");30824 fprintf(stderr, "Current basic block:\n");
29830 ir_print_basic_block(this->codegen, stderr, this->new_irb.current_basic_block, 1, IrPassGen);30825 ir_print_basic_block_gen(this->codegen, stderr, this->new_irb.current_basic_block, 1);
29831 }30826 }
29832}30827}
2983330828
src/ir.hpp+13-13
...@@ -10,33 +10,33 @@...@@ -10,33 +10,33 @@
1010
11#include "all_types.hpp"11#include "all_types.hpp"
1212
13enum IrPass {13bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutableSrc *ir_executable);
14 IrPassSrc,
15 IrPassGen,
16};
17
18bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable);
19bool ir_gen_fn(CodeGen *g, ZigFn *fn_entry);14bool ir_gen_fn(CodeGen *g, ZigFn *fn_entry);
2015
21ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,16IrInstGen *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigFn *fn,
22 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,17 ZigType *var_type, const char *name_hint);
18
19Error ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
20 ZigValue *return_ptr, size_t *backward_branch_count, size_t *backward_branch_quota,
23 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,21 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
24 IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef);22 IrExecutableGen *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef);
2523
26Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val);24Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val);
2725
28ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable,26ZigType *ir_analyze(CodeGen *g, IrExecutableSrc *old_executable, IrExecutableGen *new_executable,
29 ZigType *expected_type, AstNode *expected_type_source_node);27 ZigType *expected_type, AstNode *expected_type_source_node, ZigValue *return_ptr);
3028
31bool ir_has_side_effects(IrInstruction *instruction);29bool ir_inst_gen_has_side_effects(IrInstGen *inst);
30bool ir_inst_src_has_side_effects(IrInstSrc *inst);
3231
33struct IrAnalyze;32struct IrAnalyze;
34ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_val,33ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_val,
35 AstNode *source_node);34 AstNode *source_node);
36const char *float_op_to_name(BuiltinFnId op);
3735
38// for debugging purposes36// for debugging purposes
39void dbg_ir_break(const char *src_file, uint32_t line);37void dbg_ir_break(const char *src_file, uint32_t line);
40void dbg_ir_clear(void);38void dbg_ir_clear(void);
4139
40void destroy_instruction_gen(IrInstGen *inst);
41
42#endif42#endif
src/ir_print.cpp+1998-1281
...@@ -10,19 +10,35 @@...@@ -10,19 +10,35 @@
10#include "ir_print.hpp"10#include "ir_print.hpp"
11#include "os.hpp"11#include "os.hpp"
1212
13static uint32_t hash_instruction_ptr(IrInstruction* instruction) {13static uint32_t hash_inst_src_ptr(IrInstSrc* instruction) {
14 return (uint32_t)(uintptr_t)instruction;14 return (uint32_t)(uintptr_t)instruction;
15}15}
1616
17static bool instruction_ptr_equal(IrInstruction* a, IrInstruction* b) {17static uint32_t hash_inst_gen_ptr(IrInstGen* instruction) {
18 return (uint32_t)(uintptr_t)instruction;
19}
20
21static bool inst_src_ptr_eql(IrInstSrc* a, IrInstSrc* b) {
18 return a == b;22 return a == b;
19}23}
2024
21using InstructionSet = HashMap<IrInstruction*, uint8_t, hash_instruction_ptr, instruction_ptr_equal>;25static bool inst_gen_ptr_eql(IrInstGen* a, IrInstGen* b) {
22using InstructionList = ZigList<IrInstruction*>;26 return a == b;
27}
28
29using InstSetSrc = HashMap<IrInstSrc*, uint8_t, hash_inst_src_ptr, inst_src_ptr_eql>;
30using InstSetGen = HashMap<IrInstGen*, uint8_t, hash_inst_gen_ptr, inst_gen_ptr_eql>;
31using InstListSrc = ZigList<IrInstSrc*>;
32using InstListGen = ZigList<IrInstGen*>;
33
34struct IrPrintSrc {
35 CodeGen *codegen;
36 FILE *f;
37 int indent;
38 int indent_size;
39};
2340
24struct IrPrint {41struct IrPrintGen {
25 IrPass pass;
26 CodeGen *codegen;42 CodeGen *codegen;
27 FILE *f;43 FILE *f;
28 int indent;44 int indent;
...@@ -32,417 +48,590 @@ struct IrPrint {...@@ -32,417 +48,590 @@ struct IrPrint {
32 // present in the instruction list. Thus we track which instructions48 // present in the instruction list. Thus we track which instructions
33 // are printed (per executable) and after each pass 2 instruction those49 // are printed (per executable) and after each pass 2 instruction those
34 // var instructions are rendered in a trailing fashion.50 // var instructions are rendered in a trailing fashion.
35 InstructionSet printed;51 InstSetGen printed;
36 InstructionList pending;52 InstListGen pending;
37};53};
3854
39static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction);55static void ir_print_other_inst_src(IrPrintSrc *irp, IrInstSrc *inst);
56static void ir_print_other_inst_gen(IrPrintGen *irp, IrInstGen *inst);
4057
41const char* ir_instruction_type_str(IrInstructionId id) {58const char* ir_inst_src_type_str(IrInstSrcId id) {
42 switch (id) {59 switch (id) {
43 case IrInstructionIdInvalid:60 case IrInstSrcIdInvalid:
44 return "Invalid";61 return "SrcInvalid";
45 case IrInstructionIdShuffleVector:62 case IrInstSrcIdShuffleVector:
46 return "Shuffle";63 return "SrcShuffle";
47 case IrInstructionIdSplatSrc:64 case IrInstSrcIdSplat:
48 return "SplatSrc";65 return "SrcSplat";
49 case IrInstructionIdSplatGen:66 case IrInstSrcIdDeclVar:
50 return "SplatGen";67 return "SrcDeclVar";
51 case IrInstructionIdDeclVarSrc:68 case IrInstSrcIdBr:
52 return "DeclVarSrc";69 return "SrcBr";
53 case IrInstructionIdDeclVarGen:70 case IrInstSrcIdCondBr:
54 return "DeclVarGen";71 return "SrcCondBr";
55 case IrInstructionIdBr:72 case IrInstSrcIdSwitchBr:
56 return "Br";73 return "SrcSwitchBr";
57 case IrInstructionIdCondBr:74 case IrInstSrcIdSwitchVar:
58 return "CondBr";75 return "SrcSwitchVar";
59 case IrInstructionIdSwitchBr:76 case IrInstSrcIdSwitchElseVar:
60 return "SwitchBr";77 return "SrcSwitchElseVar";
61 case IrInstructionIdSwitchVar:78 case IrInstSrcIdSwitchTarget:
62 return "SwitchVar";79 return "SrcSwitchTarget";
63 case IrInstructionIdSwitchElseVar:80 case IrInstSrcIdPhi:
64 return "SwitchElseVar";81 return "SrcPhi";
65 case IrInstructionIdSwitchTarget:82 case IrInstSrcIdUnOp:
66 return "SwitchTarget";83 return "SrcUnOp";
67 case IrInstructionIdPhi:84 case IrInstSrcIdBinOp:
68 return "Phi";85 return "SrcBinOp";
69 case IrInstructionIdUnOp:86 case IrInstSrcIdMergeErrSets:
70 return "UnOp";87 return "SrcMergeErrSets";
71 case IrInstructionIdBinOp:88 case IrInstSrcIdLoadPtr:
72 return "BinOp";89 return "SrcLoadPtr";
73 case IrInstructionIdMergeErrSets:90 case IrInstSrcIdStorePtr:
74 return "MergeErrSets";91 return "SrcStorePtr";
75 case IrInstructionIdLoadPtr:92 case IrInstSrcIdFieldPtr:
76 return "LoadPtr";93 return "SrcFieldPtr";
77 case IrInstructionIdLoadPtrGen:94 case IrInstSrcIdElemPtr:
78 return "LoadPtrGen";95 return "SrcElemPtr";
79 case IrInstructionIdStorePtr:96 case IrInstSrcIdVarPtr:
80 return "StorePtr";97 return "SrcVarPtr";
81 case IrInstructionIdVectorStoreElem:98 case IrInstSrcIdCallExtra:
82 return "VectorStoreElem";99 return "SrcCallExtra";
83 case IrInstructionIdFieldPtr:100 case IrInstSrcIdCall:
84 return "FieldPtr";101 return "SrcCall";
85 case IrInstructionIdStructFieldPtr:102 case IrInstSrcIdCallArgs:
86 return "StructFieldPtr";103 return "SrcCallArgs";
87 case IrInstructionIdUnionFieldPtr:104 case IrInstSrcIdConst:
88 return "UnionFieldPtr";105 return "SrcConst";
89 case IrInstructionIdElemPtr:106 case IrInstSrcIdReturn:
90 return "ElemPtr";107 return "SrcReturn";
91 case IrInstructionIdVarPtr:108 case IrInstSrcIdContainerInitList:
92 return "VarPtr";109 return "SrcContainerInitList";
93 case IrInstructionIdReturnPtr:110 case IrInstSrcIdContainerInitFields:
94 return "ReturnPtr";111 return "SrcContainerInitFields";
95 case IrInstructionIdCallExtra:112 case IrInstSrcIdUnreachable:
96 return "CallExtra";113 return "SrcUnreachable";
97 case IrInstructionIdCallSrc:114 case IrInstSrcIdTypeOf:
98 return "CallSrc";115 return "SrcTypeOf";
99 case IrInstructionIdCallSrcArgs:116 case IrInstSrcIdSetCold:
100 return "CallSrcArgs";117 return "SrcSetCold";
101 case IrInstructionIdCallGen:118 case IrInstSrcIdSetRuntimeSafety:
102 return "CallGen";119 return "SrcSetRuntimeSafety";
103 case IrInstructionIdConst:120 case IrInstSrcIdSetFloatMode:
104 return "Const";121 return "SrcSetFloatMode";
105 case IrInstructionIdReturn:122 case IrInstSrcIdArrayType:
106 return "Return";123 return "SrcArrayType";
107 case IrInstructionIdCast:124 case IrInstSrcIdAnyFrameType:
108 return "Cast";125 return "SrcAnyFrameType";
109 case IrInstructionIdResizeSlice:126 case IrInstSrcIdSliceType:
110 return "ResizeSlice";127 return "SrcSliceType";
111 case IrInstructionIdContainerInitList:128 case IrInstSrcIdAsm:
112 return "ContainerInitList";129 return "SrcAsm";
113 case IrInstructionIdContainerInitFields:130 case IrInstSrcIdSizeOf:
114 return "ContainerInitFields";131 return "SrcSizeOf";
115 case IrInstructionIdUnreachable:132 case IrInstSrcIdTestNonNull:
116 return "Unreachable";133 return "SrcTestNonNull";
117 case IrInstructionIdTypeOf:134 case IrInstSrcIdOptionalUnwrapPtr:
118 return "TypeOf";135 return "SrcOptionalUnwrapPtr";
119 case IrInstructionIdSetCold:136 case IrInstSrcIdClz:
120 return "SetCold";137 return "SrcClz";
121 case IrInstructionIdSetRuntimeSafety:138 case IrInstSrcIdCtz:
122 return "SetRuntimeSafety";139 return "SrcCtz";
123 case IrInstructionIdSetFloatMode:140 case IrInstSrcIdPopCount:
124 return "SetFloatMode";141 return "SrcPopCount";
125 case IrInstructionIdArrayType:142 case IrInstSrcIdBswap:
126 return "ArrayType";143 return "SrcBswap";
127 case IrInstructionIdAnyFrameType:144 case IrInstSrcIdBitReverse:
128 return "AnyFrameType";145 return "SrcBitReverse";
129 case IrInstructionIdSliceType:146 case IrInstSrcIdImport:
130 return "SliceType";147 return "SrcImport";
131 case IrInstructionIdAsmSrc:148 case IrInstSrcIdCImport:
132 return "AsmSrc";149 return "SrcCImport";
133 case IrInstructionIdAsmGen:150 case IrInstSrcIdCInclude:
134 return "AsmGen";151 return "SrcCInclude";
135 case IrInstructionIdSizeOf:152 case IrInstSrcIdCDefine:
136 return "SizeOf";153 return "SrcCDefine";
137 case IrInstructionIdTestNonNull:154 case IrInstSrcIdCUndef:
138 return "TestNonNull";155 return "SrcCUndef";
139 case IrInstructionIdOptionalUnwrapPtr:156 case IrInstSrcIdRef:
140 return "OptionalUnwrapPtr";157 return "SrcRef";
141 case IrInstructionIdOptionalWrap:158 case IrInstSrcIdCompileErr:
142 return "OptionalWrap";159 return "SrcCompileErr";
143 case IrInstructionIdUnionTag:160 case IrInstSrcIdCompileLog:
144 return "UnionTag";161 return "SrcCompileLog";
145 case IrInstructionIdClz:162 case IrInstSrcIdErrName:
146 return "Clz";163 return "SrcErrName";
147 case IrInstructionIdCtz:164 case IrInstSrcIdEmbedFile:
148 return "Ctz";165 return "SrcEmbedFile";
149 case IrInstructionIdPopCount:166 case IrInstSrcIdCmpxchg:
150 return "PopCount";167 return "SrcCmpxchg";
151 case IrInstructionIdBswap:168 case IrInstSrcIdFence:
152 return "Bswap";169 return "SrcFence";
153 case IrInstructionIdBitReverse:170 case IrInstSrcIdTruncate:
154 return "BitReverse";171 return "SrcTruncate";
155 case IrInstructionIdImport:172 case IrInstSrcIdIntCast:
156 return "Import";173 return "SrcIntCast";
157 case IrInstructionIdCImport:174 case IrInstSrcIdFloatCast:
158 return "CImport";175 return "SrcFloatCast";
159 case IrInstructionIdCInclude:176 case IrInstSrcIdIntToFloat:
160 return "CInclude";177 return "SrcIntToFloat";
161 case IrInstructionIdCDefine:178 case IrInstSrcIdFloatToInt:
162 return "CDefine";179 return "SrcFloatToInt";
163 case IrInstructionIdCUndef:180 case IrInstSrcIdBoolToInt:
164 return "CUndef";181 return "SrcBoolToInt";
165 case IrInstructionIdRef:182 case IrInstSrcIdIntType:
166 return "Ref";183 return "SrcIntType";
167 case IrInstructionIdRefGen:184 case IrInstSrcIdVectorType:
168 return "RefGen";185 return "SrcVectorType";
169 case IrInstructionIdCompileErr:186 case IrInstSrcIdBoolNot:
170 return "CompileErr";187 return "SrcBoolNot";
171 case IrInstructionIdCompileLog:188 case IrInstSrcIdMemset:
172 return "CompileLog";189 return "SrcMemset";
173 case IrInstructionIdErrName:190 case IrInstSrcIdMemcpy:
174 return "ErrName";191 return "SrcMemcpy";
175 case IrInstructionIdEmbedFile:192 case IrInstSrcIdSlice:
176 return "EmbedFile";193 return "SrcSlice";
177 case IrInstructionIdCmpxchgSrc:194 case IrInstSrcIdMemberCount:
178 return "CmpxchgSrc";195 return "SrcMemberCount";
179 case IrInstructionIdCmpxchgGen:196 case IrInstSrcIdMemberType:
180 return "CmpxchgGen";197 return "SrcMemberType";
181 case IrInstructionIdFence:198 case IrInstSrcIdMemberName:
182 return "Fence";199 return "SrcMemberName";
183 case IrInstructionIdTruncate:200 case IrInstSrcIdBreakpoint:
184 return "Truncate";201 return "SrcBreakpoint";
185 case IrInstructionIdIntCast:202 case IrInstSrcIdReturnAddress:
186 return "IntCast";203 return "SrcReturnAddress";
187 case IrInstructionIdFloatCast:204 case IrInstSrcIdFrameAddress:
188 return "FloatCast";205 return "SrcFrameAddress";
189 case IrInstructionIdIntToFloat:206 case IrInstSrcIdFrameHandle:
190 return "IntToFloat";207 return "SrcFrameHandle";
191 case IrInstructionIdFloatToInt:208 case IrInstSrcIdFrameType:
192 return "FloatToInt";209 return "SrcFrameType";
193 case IrInstructionIdBoolToInt:210 case IrInstSrcIdFrameSize:
194 return "BoolToInt";211 return "SrcFrameSize";
195 case IrInstructionIdIntType:212 case IrInstSrcIdAlignOf:
196 return "IntType";213 return "SrcAlignOf";
197 case IrInstructionIdVectorType:214 case IrInstSrcIdOverflowOp:
198 return "VectorType";215 return "SrcOverflowOp";
199 case IrInstructionIdBoolNot:216 case IrInstSrcIdTestErr:
200 return "BoolNot";217 return "SrcTestErr";
201 case IrInstructionIdMemset:218 case IrInstSrcIdMulAdd:
202 return "Memset";219 return "SrcMulAdd";
203 case IrInstructionIdMemcpy:220 case IrInstSrcIdFloatOp:
204 return "Memcpy";221 return "SrcFloatOp";
205 case IrInstructionIdSliceSrc:222 case IrInstSrcIdUnwrapErrCode:
206 return "SliceSrc";223 return "SrcUnwrapErrCode";
207 case IrInstructionIdSliceGen:224 case IrInstSrcIdUnwrapErrPayload:
208 return "SliceGen";225 return "SrcUnwrapErrPayload";
209 case IrInstructionIdMemberCount:226 case IrInstSrcIdFnProto:
210 return "MemberCount";227 return "SrcFnProto";
211 case IrInstructionIdMemberType:228 case IrInstSrcIdTestComptime:
212 return "MemberType";229 return "SrcTestComptime";
213 case IrInstructionIdMemberName:230 case IrInstSrcIdPtrCast:
214 return "MemberName";231 return "SrcPtrCast";
215 case IrInstructionIdBreakpoint:232 case IrInstSrcIdBitCast:
216 return "Breakpoint";233 return "SrcBitCast";
217 case IrInstructionIdReturnAddress:234 case IrInstSrcIdIntToPtr:
218 return "ReturnAddress";235 return "SrcIntToPtr";
219 case IrInstructionIdFrameAddress:236 case IrInstSrcIdPtrToInt:
220 return "FrameAddress";237 return "SrcPtrToInt";
221 case IrInstructionIdFrameHandle:238 case IrInstSrcIdIntToEnum:
222 return "FrameHandle";239 return "SrcIntToEnum";
223 case IrInstructionIdFrameType:240 case IrInstSrcIdEnumToInt:
224 return "FrameType";241 return "SrcEnumToInt";
225 case IrInstructionIdFrameSizeSrc:242 case IrInstSrcIdIntToErr:
226 return "FrameSizeSrc";243 return "SrcIntToErr";
227 case IrInstructionIdFrameSizeGen:244 case IrInstSrcIdErrToInt:
228 return "FrameSizeGen";245 return "SrcErrToInt";
229 case IrInstructionIdAlignOf:246 case IrInstSrcIdCheckSwitchProngs:
230 return "AlignOf";247 return "SrcCheckSwitchProngs";
231 case IrInstructionIdOverflowOp:248 case IrInstSrcIdCheckStatementIsVoid:
232 return "OverflowOp";249 return "SrcCheckStatementIsVoid";
233 case IrInstructionIdTestErrSrc:250 case IrInstSrcIdTypeName:
234 return "TestErrSrc";251 return "SrcTypeName";
235 case IrInstructionIdTestErrGen:252 case IrInstSrcIdDeclRef:
236 return "TestErrGen";253 return "SrcDeclRef";
237 case IrInstructionIdMulAdd:254 case IrInstSrcIdPanic:
238 return "MulAdd";255 return "SrcPanic";
239 case IrInstructionIdFloatOp:256 case IrInstSrcIdTagName:
240 return "FloatOp";257 return "SrcTagName";
241 case IrInstructionIdUnwrapErrCode:258 case IrInstSrcIdTagType:
242 return "UnwrapErrCode";259 return "SrcTagType";
243 case IrInstructionIdUnwrapErrPayload:260 case IrInstSrcIdFieldParentPtr:
244 return "UnwrapErrPayload";261 return "SrcFieldParentPtr";
245 case IrInstructionIdErrWrapCode:262 case IrInstSrcIdByteOffsetOf:
246 return "ErrWrapCode";263 return "SrcByteOffsetOf";
247 case IrInstructionIdErrWrapPayload:264 case IrInstSrcIdBitOffsetOf:
248 return "ErrWrapPayload";265 return "SrcBitOffsetOf";
249 case IrInstructionIdFnProto:266 case IrInstSrcIdTypeInfo:
250 return "FnProto";267 return "SrcTypeInfo";
251 case IrInstructionIdTestComptime:268 case IrInstSrcIdType:
252 return "TestComptime";269 return "SrcType";
253 case IrInstructionIdPtrCastSrc:270 case IrInstSrcIdHasField:
254 return "PtrCastSrc";271 return "SrcHasField";
255 case IrInstructionIdPtrCastGen:272 case IrInstSrcIdTypeId:
256 return "PtrCastGen";273 return "SrcTypeId";
257 case IrInstructionIdBitCastSrc:274 case IrInstSrcIdSetEvalBranchQuota:
258 return "BitCastSrc";275 return "SrcSetEvalBranchQuota";
259 case IrInstructionIdBitCastGen:276 case IrInstSrcIdPtrType:
260 return "BitCastGen";277 return "SrcPtrType";
261 case IrInstructionIdWidenOrShorten:278 case IrInstSrcIdAlignCast:
262 return "WidenOrShorten";279 return "SrcAlignCast";
263 case IrInstructionIdIntToPtr:280 case IrInstSrcIdImplicitCast:
264 return "IntToPtr";281 return "SrcImplicitCast";
265 case IrInstructionIdPtrToInt:282 case IrInstSrcIdResolveResult:
266 return "PtrToInt";283 return "SrcResolveResult";
267 case IrInstructionIdIntToEnum:284 case IrInstSrcIdResetResult:
268 return "IntToEnum";285 return "SrcResetResult";
269 case IrInstructionIdEnumToInt:286 case IrInstSrcIdOpaqueType:
270 return "EnumToInt";287 return "SrcOpaqueType";
271 case IrInstructionIdIntToErr:288 case IrInstSrcIdSetAlignStack:
272 return "IntToErr";289 return "SrcSetAlignStack";
273 case IrInstructionIdErrToInt:290 case IrInstSrcIdArgType:
274 return "ErrToInt";291 return "SrcArgType";
275 case IrInstructionIdCheckSwitchProngs:292 case IrInstSrcIdExport:
276 return "CheckSwitchProngs";293 return "SrcExport";
277 case IrInstructionIdCheckStatementIsVoid:294 case IrInstSrcIdErrorReturnTrace:
278 return "CheckStatementIsVoid";295 return "SrcErrorReturnTrace";
279 case IrInstructionIdTypeName:296 case IrInstSrcIdErrorUnion:
280 return "TypeName";297 return "SrcErrorUnion";
281 case IrInstructionIdDeclRef:298 case IrInstSrcIdAtomicRmw:
282 return "DeclRef";299 return "SrcAtomicRmw";
283 case IrInstructionIdPanic:300 case IrInstSrcIdAtomicLoad:
284 return "Panic";301 return "SrcAtomicLoad";
285 case IrInstructionIdTagName:302 case IrInstSrcIdAtomicStore:
286 return "TagName";303 return "SrcAtomicStore";
287 case IrInstructionIdTagType:304 case IrInstSrcIdSaveErrRetAddr:
288 return "TagType";305 return "SrcSaveErrRetAddr";
289 case IrInstructionIdFieldParentPtr:306 case IrInstSrcIdAddImplicitReturnType:
290 return "FieldParentPtr";307 return "SrcAddImplicitReturnType";
291 case IrInstructionIdByteOffsetOf:308 case IrInstSrcIdErrSetCast:
292 return "ByteOffsetOf";309 return "SrcErrSetCast";
293 case IrInstructionIdBitOffsetOf:310 case IrInstSrcIdToBytes:
294 return "BitOffsetOf";311 return "SrcToBytes";
295 case IrInstructionIdTypeInfo:312 case IrInstSrcIdFromBytes:
296 return "TypeInfo";313 return "SrcFromBytes";
297 case IrInstructionIdType:314 case IrInstSrcIdCheckRuntimeScope:
298 return "Type";315 return "SrcCheckRuntimeScope";
299 case IrInstructionIdHasField:316 case IrInstSrcIdHasDecl:
300 return "HasField";317 return "SrcHasDecl";
301 case IrInstructionIdTypeId:318 case IrInstSrcIdUndeclaredIdent:
302 return "TypeId";319 return "SrcUndeclaredIdent";
303 case IrInstructionIdSetEvalBranchQuota:320 case IrInstSrcIdAlloca:
304 return "SetEvalBranchQuota";321 return "SrcAlloca";
305 case IrInstructionIdPtrType:322 case IrInstSrcIdEndExpr:
306 return "PtrType";323 return "SrcEndExpr";
307 case IrInstructionIdAlignCast:324 case IrInstSrcIdUnionInitNamedField:
308 return "AlignCast";325 return "SrcUnionInitNamedField";
309 case IrInstructionIdImplicitCast:326 case IrInstSrcIdSuspendBegin:
310 return "ImplicitCast";327 return "SrcSuspendBegin";
311 case IrInstructionIdResolveResult:328 case IrInstSrcIdSuspendFinish:
312 return "ResolveResult";329 return "SrcSuspendFinish";
313 case IrInstructionIdResetResult:330 case IrInstSrcIdAwait:
314 return "ResetResult";331 return "SrcAwaitSr";
315 case IrInstructionIdOpaqueType:332 case IrInstSrcIdResume:
316 return "OpaqueType";333 return "SrcResume";
317 case IrInstructionIdSetAlignStack:334 case IrInstSrcIdSpillBegin:
318 return "SetAlignStack";335 return "SrcSpillBegin";
319 case IrInstructionIdArgType:336 case IrInstSrcIdSpillEnd:
320 return "ArgType";337 return "SrcSpillEnd";
321 case IrInstructionIdExport:
322 return "Export";
323 case IrInstructionIdErrorReturnTrace:
324 return "ErrorReturnTrace";
325 case IrInstructionIdErrorUnion:
326 return "ErrorUnion";
327 case IrInstructionIdAtomicRmw:
328 return "AtomicRmw";
329 case IrInstructionIdAtomicLoad:
330 return "AtomicLoad";
331 case IrInstructionIdAtomicStore:
332 return "AtomicStore";
333 case IrInstructionIdSaveErrRetAddr:
334 return "SaveErrRetAddr";
335 case IrInstructionIdAddImplicitReturnType:
336 return "AddImplicitReturnType";
337 case IrInstructionIdErrSetCast:
338 return "ErrSetCast";
339 case IrInstructionIdToBytes:
340 return "ToBytes";
341 case IrInstructionIdFromBytes:
342 return "FromBytes";
343 case IrInstructionIdCheckRuntimeScope:
344 return "CheckRuntimeScope";
345 case IrInstructionIdVectorToArray:
346 return "VectorToArray";
347 case IrInstructionIdArrayToVector:
348 return "ArrayToVector";
349 case IrInstructionIdAssertZero:
350 return "AssertZero";
351 case IrInstructionIdAssertNonNull:
352 return "AssertNonNull";
353 case IrInstructionIdHasDecl:
354 return "HasDecl";
355 case IrInstructionIdUndeclaredIdent:
356 return "UndeclaredIdent";
357 case IrInstructionIdAllocaSrc:
358 return "AllocaSrc";
359 case IrInstructionIdAllocaGen:
360 return "AllocaGen";
361 case IrInstructionIdEndExpr:
362 return "EndExpr";
363 case IrInstructionIdPtrOfArrayToSlice:
364 return "PtrOfArrayToSlice";
365 case IrInstructionIdUnionInitNamedField:
366 return "UnionInitNamedField";
367 case IrInstructionIdSuspendBegin:
368 return "SuspendBegin";
369 case IrInstructionIdSuspendFinish:
370 return "SuspendFinish";
371 case IrInstructionIdAwaitSrc:
372 return "AwaitSrc";
373 case IrInstructionIdAwaitGen:
374 return "AwaitGen";
375 case IrInstructionIdResume:
376 return "Resume";
377 case IrInstructionIdSpillBegin:
378 return "SpillBegin";
379 case IrInstructionIdSpillEnd:
380 return "SpillEnd";
381 case IrInstructionIdVectorExtractElem:
382 return "VectorExtractElem";
383 }338 }
384 zig_unreachable();339 zig_unreachable();
385}340}
386341
387static void ir_print_indent(IrPrint *irp) {342const char* ir_inst_gen_type_str(IrInstGenId id) {
343 switch (id) {
344 case IrInstGenIdInvalid:
345 return "GenInvalid";
346 case IrInstGenIdShuffleVector:
347 return "GenShuffle";
348 case IrInstGenIdSplat:
349 return "GenSplat";
350 case IrInstGenIdDeclVar:
351 return "GenDeclVar";
352 case IrInstGenIdBr:
353 return "GenBr";
354 case IrInstGenIdCondBr:
355 return "GenCondBr";
356 case IrInstGenIdSwitchBr:
357 return "GenSwitchBr";
358 case IrInstGenIdPhi:
359 return "GenPhi";
360 case IrInstGenIdBinOp:
361 return "GenBinOp";
362 case IrInstGenIdLoadPtr:
363 return "GenLoadPtr";
364 case IrInstGenIdStorePtr:
365 return "GenStorePtr";
366 case IrInstGenIdVectorStoreElem:
367 return "GenVectorStoreElem";
368 case IrInstGenIdStructFieldPtr:
369 return "GenStructFieldPtr";
370 case IrInstGenIdUnionFieldPtr:
371 return "GenUnionFieldPtr";
372 case IrInstGenIdElemPtr:
373 return "GenElemPtr";
374 case IrInstGenIdVarPtr:
375 return "GenVarPtr";
376 case IrInstGenIdReturnPtr:
377 return "GenReturnPtr";
378 case IrInstGenIdCall:
379 return "GenCall";
380 case IrInstGenIdConst:
381 return "GenConst";
382 case IrInstGenIdReturn:
383 return "GenReturn";
384 case IrInstGenIdCast:
385 return "GenCast";
386 case IrInstGenIdResizeSlice:
387 return "GenResizeSlice";
388 case IrInstGenIdUnreachable:
389 return "GenUnreachable";
390 case IrInstGenIdAsm:
391 return "GenAsm";
392 case IrInstGenIdTestNonNull:
393 return "GenTestNonNull";
394 case IrInstGenIdOptionalUnwrapPtr:
395 return "GenOptionalUnwrapPtr";
396 case IrInstGenIdOptionalWrap:
397 return "GenOptionalWrap";
398 case IrInstGenIdUnionTag:
399 return "GenUnionTag";
400 case IrInstGenIdClz:
401 return "GenClz";
402 case IrInstGenIdCtz:
403 return "GenCtz";
404 case IrInstGenIdPopCount:
405 return "GenPopCount";
406 case IrInstGenIdBswap:
407 return "GenBswap";
408 case IrInstGenIdBitReverse:
409 return "GenBitReverse";
410 case IrInstGenIdRef:
411 return "GenRef";
412 case IrInstGenIdErrName:
413 return "GenErrName";
414 case IrInstGenIdCmpxchg:
415 return "GenCmpxchg";
416 case IrInstGenIdFence:
417 return "GenFence";
418 case IrInstGenIdTruncate:
419 return "GenTruncate";
420 case IrInstGenIdBoolNot:
421 return "GenBoolNot";
422 case IrInstGenIdMemset:
423 return "GenMemset";
424 case IrInstGenIdMemcpy:
425 return "GenMemcpy";
426 case IrInstGenIdSlice:
427 return "GenSlice";
428 case IrInstGenIdBreakpoint:
429 return "GenBreakpoint";
430 case IrInstGenIdReturnAddress:
431 return "GenReturnAddress";
432 case IrInstGenIdFrameAddress:
433 return "GenFrameAddress";
434 case IrInstGenIdFrameHandle:
435 return "GenFrameHandle";
436 case IrInstGenIdFrameSize:
437 return "GenFrameSize";
438 case IrInstGenIdOverflowOp:
439 return "GenOverflowOp";
440 case IrInstGenIdTestErr:
441 return "GenTestErr";
442 case IrInstGenIdMulAdd:
443 return "GenMulAdd";
444 case IrInstGenIdFloatOp:
445 return "GenFloatOp";
446 case IrInstGenIdUnwrapErrCode:
447 return "GenUnwrapErrCode";
448 case IrInstGenIdUnwrapErrPayload:
449 return "GenUnwrapErrPayload";
450 case IrInstGenIdErrWrapCode:
451 return "GenErrWrapCode";
452 case IrInstGenIdErrWrapPayload:
453 return "GenErrWrapPayload";
454 case IrInstGenIdPtrCast:
455 return "GenPtrCast";
456 case IrInstGenIdBitCast:
457 return "GenBitCast";
458 case IrInstGenIdWidenOrShorten:
459 return "GenWidenOrShorten";
460 case IrInstGenIdIntToPtr:
461 return "GenIntToPtr";
462 case IrInstGenIdPtrToInt:
463 return "GenPtrToInt";
464 case IrInstGenIdIntToEnum:
465 return "GenIntToEnum";
466 case IrInstGenIdIntToErr:
467 return "GenIntToErr";
468 case IrInstGenIdErrToInt:
469 return "GenErrToInt";
470 case IrInstGenIdPanic:
471 return "GenPanic";
472 case IrInstGenIdTagName:
473 return "GenTagName";
474 case IrInstGenIdFieldParentPtr:
475 return "GenFieldParentPtr";
476 case IrInstGenIdAlignCast:
477 return "GenAlignCast";
478 case IrInstGenIdErrorReturnTrace:
479 return "GenErrorReturnTrace";
480 case IrInstGenIdAtomicRmw:
481 return "GenAtomicRmw";
482 case IrInstGenIdAtomicLoad:
483 return "GenAtomicLoad";
484 case IrInstGenIdAtomicStore:
485 return "GenAtomicStore";
486 case IrInstGenIdSaveErrRetAddr:
487 return "GenSaveErrRetAddr";
488 case IrInstGenIdVectorToArray:
489 return "GenVectorToArray";
490 case IrInstGenIdArrayToVector:
491 return "GenArrayToVector";
492 case IrInstGenIdAssertZero:
493 return "GenAssertZero";
494 case IrInstGenIdAssertNonNull:
495 return "GenAssertNonNull";
496 case IrInstGenIdAlloca:
497 return "GenAlloca";
498 case IrInstGenIdPtrOfArrayToSlice:
499 return "GenPtrOfArrayToSlice";
500 case IrInstGenIdSuspendBegin:
501 return "GenSuspendBegin";
502 case IrInstGenIdSuspendFinish:
503 return "GenSuspendFinish";
504 case IrInstGenIdAwait:
505 return "GenAwait";
506 case IrInstGenIdResume:
507 return "GenResume";
508 case IrInstGenIdSpillBegin:
509 return "GenSpillBegin";
510 case IrInstGenIdSpillEnd:
511 return "GenSpillEnd";
512 case IrInstGenIdVectorExtractElem:
513 return "GenVectorExtractElem";
514 case IrInstGenIdBinaryNot:
515 return "GenBinaryNot";
516 case IrInstGenIdNegation:
517 return "GenNegation";
518 case IrInstGenIdNegationWrapping:
519 return "GenNegationWrapping";
520 }
521 zig_unreachable();
522}
523
524static void ir_print_indent_src(IrPrintSrc *irp) {
388 for (int i = 0; i < irp->indent; i += 1) {525 for (int i = 0; i < irp->indent; i += 1) {
389 fprintf(irp->f, " ");526 fprintf(irp->f, " ");
390 }527 }
391}528}
392529
393static void ir_print_prefix(IrPrint *irp, IrInstruction *instruction, bool trailing) {530static void ir_print_indent_gen(IrPrintGen *irp) {
394 ir_print_indent(irp);531 for (int i = 0; i < irp->indent; i += 1) {
532 fprintf(irp->f, " ");
533 }
534}
535
536static void ir_print_prefix_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trailing) {
537 ir_print_indent_src(irp);
538 const char mark = trailing ? ':' : '#';
539 const char *type_name;
540 if (instruction->id == IrInstSrcIdConst) {
541 type_name = buf_ptr(&reinterpret_cast<IrInstSrcConst *>(instruction)->value->type->name);
542 } else if (instruction->is_noreturn) {
543 type_name = "noreturn";
544 } else {
545 type_name = "(unknown)";
546 }
547 const char *ref_count = ir_inst_src_has_side_effects(instruction) ?
548 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->base.ref_count));
549 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->base.debug_id,
550 ir_inst_src_type_str(instruction->id), type_name, ref_count);
551}
552
553static void ir_print_prefix_gen(IrPrintGen *irp, IrInstGen *instruction, bool trailing) {
554 ir_print_indent_gen(irp);
395 const char mark = trailing ? ':' : '#';555 const char mark = trailing ? ':' : '#';
396 const char *type_name = instruction->value->type ? buf_ptr(&instruction->value->type->name) : "(unknown)";556 const char *type_name = instruction->value->type ? buf_ptr(&instruction->value->type->name) : "(unknown)";
397 const char *ref_count = ir_has_side_effects(instruction) ?557 const char *ref_count = ir_inst_gen_has_side_effects(instruction) ?
398 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->ref_count));558 "-" : buf_ptr(buf_sprintf("%" PRIu32 "", instruction->base.ref_count));
399 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->debug_id,559 fprintf(irp->f, "%c%-3" PRIu32 "| %-22s| %-12s| %-2s| ", mark, instruction->base.debug_id,
400 ir_instruction_type_str(instruction->id), type_name, ref_count);560 ir_inst_gen_type_str(instruction->id), type_name, ref_count);
401}561}
402562
403static void ir_print_const_value(IrPrint *irp, ZigValue *const_val) {563static void ir_print_var_src(IrPrintSrc *irp, IrInstSrc *inst) {
404 Buf buf = BUF_INIT;564 fprintf(irp->f, "#%" PRIu32 "", inst->base.debug_id);
405 buf_resize(&buf, 0);
406 render_const_value(irp->codegen, &buf, const_val);
407 fprintf(irp->f, "%s", buf_ptr(&buf));
408}565}
409566
410static void ir_print_var_instruction(IrPrint *irp, IrInstruction *instruction) {567static void ir_print_var_gen(IrPrintGen *irp, IrInstGen *inst) {
411 fprintf(irp->f, "#%" PRIu32 "", instruction->debug_id);568 fprintf(irp->f, "#%" PRIu32 "", inst->base.debug_id);
412 if (irp->pass != IrPassSrc && irp->printed.maybe_get(instruction) == nullptr) {569 if (irp->printed.maybe_get(inst) == nullptr) {
413 irp->printed.put(instruction, 0);570 irp->printed.put(inst, 0);
414 irp->pending.append(instruction);571 irp->pending.append(inst);
415 }572 }
416}573}
417574
418static void ir_print_other_instruction(IrPrint *irp, IrInstruction *instruction) {575static void ir_print_other_inst_src(IrPrintSrc *irp, IrInstSrc *inst) {
419 if (instruction == nullptr) {576 if (inst == nullptr) {
420 fprintf(irp->f, "(null)");577 fprintf(irp->f, "(null)");
421 return;578 return;
422 }579 }
580 ir_print_var_src(irp, inst);
581}
582
583static void ir_print_const_value(CodeGen *g, FILE *f, ZigValue *const_val) {
584 Buf buf = BUF_INIT;
585 buf_resize(&buf, 0);
586 render_const_value(g, &buf, const_val);
587 fprintf(f, "%s", buf_ptr(&buf));
588}
589
590static void ir_print_other_inst_gen(IrPrintGen *irp, IrInstGen *inst) {
591 if (inst == nullptr) {
592 fprintf(irp->f, "(null)");
593 return;
594 }
595
596 if (inst->value->special != ConstValSpecialRuntime) {
597 ir_print_const_value(irp->codegen, irp->f, inst->value);
598 } else {
599 ir_print_var_gen(irp, inst);
600 }
601}
423602
424 if (instruction->value->special != ConstValSpecialRuntime) {603static void ir_print_other_block(IrPrintSrc *irp, IrBasicBlockSrc *bb) {
425 ir_print_const_value(irp, instruction->value);604 if (bb == nullptr) {
605 fprintf(irp->f, "(null block)");
426 } else {606 } else {
427 ir_print_var_instruction(irp, instruction);607 fprintf(irp->f, "$%s_%" PRIu32 "", bb->name_hint, bb->debug_id);
428 }608 }
429}609}
430610
431static void ir_print_other_block(IrPrint *irp, IrBasicBlock *bb) {611static void ir_print_other_block_gen(IrPrintGen *irp, IrBasicBlockGen *bb) {
432 if (bb == nullptr) {612 if (bb == nullptr) {
433 fprintf(irp->f, "(null block)");613 fprintf(irp->f, "(null block)");
434 } else {614 } else {
435 fprintf(irp->f, "$%s_%" ZIG_PRI_usize "", bb->name_hint, bb->debug_id);615 fprintf(irp->f, "$%s_%" PRIu32 "", bb->name_hint, bb->debug_id);
436 }616 }
437}617}
438618
439static void ir_print_return(IrPrint *irp, IrInstructionReturn *instruction) {619static void ir_print_return_src(IrPrintSrc *irp, IrInstSrcReturn *inst) {
440 fprintf(irp->f, "return ");620 fprintf(irp->f, "return ");
441 ir_print_other_instruction(irp, instruction->operand);621 ir_print_other_inst_src(irp, inst->operand);
442}622}
443623
444static void ir_print_const(IrPrint *irp, IrInstructionConst *const_instruction) {624static void ir_print_return_gen(IrPrintGen *irp, IrInstGenReturn *inst) {
445 ir_print_const_value(irp, const_instruction->base.value);625 fprintf(irp->f, "return ");
626 ir_print_other_inst_gen(irp, inst->operand);
627}
628
629static void ir_print_const(IrPrintSrc *irp, IrInstSrcConst *const_instruction) {
630 ir_print_const_value(irp->codegen, irp->f, const_instruction->value);
631}
632
633static void ir_print_const(IrPrintGen *irp, IrInstGenConst *const_instruction) {
634 ir_print_const_value(irp->codegen, irp->f, const_instruction->base.value);
446}635}
447636
448static const char *ir_bin_op_id_str(IrBinOp op_id) {637static const char *ir_bin_op_id_str(IrBinOp op_id) {
...@@ -531,89 +720,111 @@ static const char *ir_un_op_id_str(IrUnOp op_id) {...@@ -531,89 +720,111 @@ static const char *ir_un_op_id_str(IrUnOp op_id) {
531 zig_unreachable();720 zig_unreachable();
532}721}
533722
534static void ir_print_un_op(IrPrint *irp, IrInstructionUnOp *un_op_instruction) {723static void ir_print_un_op(IrPrintSrc *irp, IrInstSrcUnOp *inst) {
535 fprintf(irp->f, "%s ", ir_un_op_id_str(un_op_instruction->op_id));724 fprintf(irp->f, "%s ", ir_un_op_id_str(inst->op_id));
536 ir_print_other_instruction(irp, un_op_instruction->value);725 ir_print_other_inst_src(irp, inst->value);
726}
727
728static void ir_print_bin_op(IrPrintSrc *irp, IrInstSrcBinOp *bin_op_instruction) {
729 ir_print_other_inst_src(irp, bin_op_instruction->op1);
730 fprintf(irp->f, " %s ", ir_bin_op_id_str(bin_op_instruction->op_id));
731 ir_print_other_inst_src(irp, bin_op_instruction->op2);
732 if (!bin_op_instruction->safety_check_on) {
733 fprintf(irp->f, " // no safety");
734 }
537}735}
538736
539static void ir_print_bin_op(IrPrint *irp, IrInstructionBinOp *bin_op_instruction) {737static void ir_print_bin_op(IrPrintGen *irp, IrInstGenBinOp *bin_op_instruction) {
540 ir_print_other_instruction(irp, bin_op_instruction->op1);738 ir_print_other_inst_gen(irp, bin_op_instruction->op1);
541 fprintf(irp->f, " %s ", ir_bin_op_id_str(bin_op_instruction->op_id));739 fprintf(irp->f, " %s ", ir_bin_op_id_str(bin_op_instruction->op_id));
542 ir_print_other_instruction(irp, bin_op_instruction->op2);740 ir_print_other_inst_gen(irp, bin_op_instruction->op2);
543 if (!bin_op_instruction->safety_check_on) {741 if (!bin_op_instruction->safety_check_on) {
544 fprintf(irp->f, " // no safety");742 fprintf(irp->f, " // no safety");
545 }743 }
546}744}
547745
548static void ir_print_merge_err_sets(IrPrint *irp, IrInstructionMergeErrSets *instruction) {746static void ir_print_merge_err_sets(IrPrintSrc *irp, IrInstSrcMergeErrSets *instruction) {
549 ir_print_other_instruction(irp, instruction->op1);747 ir_print_other_inst_src(irp, instruction->op1);
550 fprintf(irp->f, " || ");748 fprintf(irp->f, " || ");
551 ir_print_other_instruction(irp, instruction->op2);749 ir_print_other_inst_src(irp, instruction->op2);
552 if (instruction->type_name != nullptr) {750 if (instruction->type_name != nullptr) {
553 fprintf(irp->f, " // name=%s", buf_ptr(instruction->type_name));751 fprintf(irp->f, " // name=%s", buf_ptr(instruction->type_name));
554 }752 }
555}753}
556754
557static void ir_print_decl_var_src(IrPrint *irp, IrInstructionDeclVarSrc *decl_var_instruction) {755static void ir_print_decl_var_src(IrPrintSrc *irp, IrInstSrcDeclVar *decl_var_instruction) {
558 const char *var_or_const = decl_var_instruction->var->gen_is_const ? "const" : "var";756 const char *var_or_const = decl_var_instruction->var->gen_is_const ? "const" : "var";
559 const char *name = decl_var_instruction->var->name;757 const char *name = decl_var_instruction->var->name;
560 if (decl_var_instruction->var_type) {758 if (decl_var_instruction->var_type) {
561 fprintf(irp->f, "%s %s: ", var_or_const, name);759 fprintf(irp->f, "%s %s: ", var_or_const, name);
562 ir_print_other_instruction(irp, decl_var_instruction->var_type);760 ir_print_other_inst_src(irp, decl_var_instruction->var_type);
563 fprintf(irp->f, " ");761 fprintf(irp->f, " ");
564 } else {762 } else {
565 fprintf(irp->f, "%s %s ", var_or_const, name);763 fprintf(irp->f, "%s %s ", var_or_const, name);
566 }764 }
567 if (decl_var_instruction->align_value) {765 if (decl_var_instruction->align_value) {
568 fprintf(irp->f, "align ");766 fprintf(irp->f, "align ");
569 ir_print_other_instruction(irp, decl_var_instruction->align_value);767 ir_print_other_inst_src(irp, decl_var_instruction->align_value);
570 fprintf(irp->f, " ");768 fprintf(irp->f, " ");
571 }769 }
572 fprintf(irp->f, "= ");770 fprintf(irp->f, "= ");
573 ir_print_other_instruction(irp, decl_var_instruction->ptr);771 ir_print_other_inst_src(irp, decl_var_instruction->ptr);
574 if (decl_var_instruction->var->is_comptime != nullptr) {772 if (decl_var_instruction->var->is_comptime != nullptr) {
575 fprintf(irp->f, " // comptime = ");773 fprintf(irp->f, " // comptime = ");
576 ir_print_other_instruction(irp, decl_var_instruction->var->is_comptime);774 ir_print_other_inst_src(irp, decl_var_instruction->var->is_comptime);
577 }775 }
578}776}
579777
580static void ir_print_cast(IrPrint *irp, IrInstructionCast *cast_instruction) {778static const char *cast_op_str(CastOp op) {
581 fprintf(irp->f, "cast ");779 switch (op) {
582 ir_print_other_instruction(irp, cast_instruction->value);780 case CastOpNoCast: return "NoCast";
583 fprintf(irp->f, " to %s", buf_ptr(&cast_instruction->dest_type->name));781 case CastOpNoop: return "NoOp";
782 case CastOpIntToFloat: return "IntToFloat";
783 case CastOpFloatToInt: return "FloatToInt";
784 case CastOpBoolToInt: return "BoolToInt";
785 case CastOpNumLitToConcrete: return "NumLitToConcrate";
786 case CastOpErrSet: return "ErrSet";
787 case CastOpBitCast: return "BitCast";
788 }
789 zig_unreachable();
790}
791
792static void ir_print_cast(IrPrintGen *irp, IrInstGenCast *cast_instruction) {
793 fprintf(irp->f, "%s cast ", cast_op_str(cast_instruction->cast_op));
794 ir_print_other_inst_gen(irp, cast_instruction->value);
584}795}
585796
586static void ir_print_result_loc_var(IrPrint *irp, ResultLocVar *result_loc_var) {797static void ir_print_result_loc_var(IrPrintSrc *irp, ResultLocVar *result_loc_var) {
587 fprintf(irp->f, "var(");798 fprintf(irp->f, "var(");
588 ir_print_other_instruction(irp, result_loc_var->base.source_instruction);799 ir_print_other_inst_src(irp, result_loc_var->base.source_instruction);
589 fprintf(irp->f, ")");800 fprintf(irp->f, ")");
590}801}
591802
592static void ir_print_result_loc_instruction(IrPrint *irp, ResultLocInstruction *result_loc_inst) {803static void ir_print_result_loc_instruction(IrPrintSrc *irp, ResultLocInstruction *result_loc_inst) {
593 fprintf(irp->f, "inst(");804 fprintf(irp->f, "inst(");
594 ir_print_other_instruction(irp, result_loc_inst->base.source_instruction);805 ir_print_other_inst_src(irp, result_loc_inst->base.source_instruction);
595 fprintf(irp->f, ")");806 fprintf(irp->f, ")");
596}807}
597808
598static void ir_print_result_loc_peer(IrPrint *irp, ResultLocPeer *result_loc_peer) {809static void ir_print_result_loc_peer(IrPrintSrc *irp, ResultLocPeer *result_loc_peer) {
599 fprintf(irp->f, "peer(next=");810 fprintf(irp->f, "peer(next=");
600 ir_print_other_block(irp, result_loc_peer->next_bb);811 ir_print_other_block(irp, result_loc_peer->next_bb);
601 fprintf(irp->f, ")");812 fprintf(irp->f, ")");
602}813}
603814
604static void ir_print_result_loc_bit_cast(IrPrint *irp, ResultLocBitCast *result_loc_bit_cast) {815static void ir_print_result_loc_bit_cast(IrPrintSrc *irp, ResultLocBitCast *result_loc_bit_cast) {
605 fprintf(irp->f, "bitcast(ty=");816 fprintf(irp->f, "bitcast(ty=");
606 ir_print_other_instruction(irp, result_loc_bit_cast->base.source_instruction);817 ir_print_other_inst_src(irp, result_loc_bit_cast->base.source_instruction);
607 fprintf(irp->f, ")");818 fprintf(irp->f, ")");
608}819}
609820
610static void ir_print_result_loc_cast(IrPrint *irp, ResultLocCast *result_loc_cast) {821static void ir_print_result_loc_cast(IrPrintSrc *irp, ResultLocCast *result_loc_cast) {
611 fprintf(irp->f, "cast(ty=");822 fprintf(irp->f, "cast(ty=");
612 ir_print_other_instruction(irp, result_loc_cast->base.source_instruction);823 ir_print_other_inst_src(irp, result_loc_cast->base.source_instruction);
613 fprintf(irp->f, ")");824 fprintf(irp->f, ")");
614}825}
615826
616static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {827static void ir_print_result_loc(IrPrintSrc *irp, ResultLoc *result_loc) {
617 switch (result_loc->id) {828 switch (result_loc->id) {
618 case ResultLocIdInvalid:829 case ResultLocIdInvalid:
619 zig_unreachable();830 zig_unreachable();
...@@ -640,34 +851,34 @@ static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {...@@ -640,34 +851,34 @@ static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {
640 zig_unreachable();851 zig_unreachable();
641}852}
642853
643static void ir_print_call_extra(IrPrint *irp, IrInstructionCallExtra *instruction) {854static void ir_print_call_extra(IrPrintSrc *irp, IrInstSrcCallExtra *instruction) {
644 fprintf(irp->f, "opts=");855 fprintf(irp->f, "opts=");
645 ir_print_other_instruction(irp, instruction->options);856 ir_print_other_inst_src(irp, instruction->options);
646 fprintf(irp->f, ", fn=");857 fprintf(irp->f, ", fn=");
647 ir_print_other_instruction(irp, instruction->fn_ref);858 ir_print_other_inst_src(irp, instruction->fn_ref);
648 fprintf(irp->f, ", args=");859 fprintf(irp->f, ", args=");
649 ir_print_other_instruction(irp, instruction->args);860 ir_print_other_inst_src(irp, instruction->args);
650 fprintf(irp->f, ", result=");861 fprintf(irp->f, ", result=");
651 ir_print_result_loc(irp, instruction->result_loc);862 ir_print_result_loc(irp, instruction->result_loc);
652}863}
653864
654static void ir_print_call_src_args(IrPrint *irp, IrInstructionCallSrcArgs *instruction) {865static void ir_print_call_args(IrPrintSrc *irp, IrInstSrcCallArgs *instruction) {
655 fprintf(irp->f, "opts=");866 fprintf(irp->f, "opts=");
656 ir_print_other_instruction(irp, instruction->options);867 ir_print_other_inst_src(irp, instruction->options);
657 fprintf(irp->f, ", fn=");868 fprintf(irp->f, ", fn=");
658 ir_print_other_instruction(irp, instruction->fn_ref);869 ir_print_other_inst_src(irp, instruction->fn_ref);
659 fprintf(irp->f, ", args=(");870 fprintf(irp->f, ", args=(");
660 for (size_t i = 0; i < instruction->args_len; i += 1) {871 for (size_t i = 0; i < instruction->args_len; i += 1) {
661 IrInstruction *arg = instruction->args_ptr[i];872 IrInstSrc *arg = instruction->args_ptr[i];
662 if (i != 0)873 if (i != 0)
663 fprintf(irp->f, ", ");874 fprintf(irp->f, ", ");
664 ir_print_other_instruction(irp, arg);875 ir_print_other_inst_src(irp, arg);
665 }876 }
666 fprintf(irp->f, "), result=");877 fprintf(irp->f, "), result=");
667 ir_print_result_loc(irp, instruction->result_loc);878 ir_print_result_loc(irp, instruction->result_loc);
668}879}
669880
670static void ir_print_call_src(IrPrint *irp, IrInstructionCallSrc *call_instruction) {881static void ir_print_call_src(IrPrintSrc *irp, IrInstSrcCall *call_instruction) {
671 switch (call_instruction->modifier) {882 switch (call_instruction->modifier) {
672 case CallModifierNone:883 case CallModifierNone:
673 break;884 break;
...@@ -699,20 +910,20 @@ static void ir_print_call_src(IrPrint *irp, IrInstructionCallSrc *call_instructi...@@ -699,20 +910,20 @@ static void ir_print_call_src(IrPrint *irp, IrInstructionCallSrc *call_instructi
699 fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));910 fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));
700 } else {911 } else {
701 assert(call_instruction->fn_ref);912 assert(call_instruction->fn_ref);
702 ir_print_other_instruction(irp, call_instruction->fn_ref);913 ir_print_other_inst_src(irp, call_instruction->fn_ref);
703 }914 }
704 fprintf(irp->f, "(");915 fprintf(irp->f, "(");
705 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {916 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
706 IrInstruction *arg = call_instruction->args[i];917 IrInstSrc *arg = call_instruction->args[i];
707 if (i != 0)918 if (i != 0)
708 fprintf(irp->f, ", ");919 fprintf(irp->f, ", ");
709 ir_print_other_instruction(irp, arg);920 ir_print_other_inst_src(irp, arg);
710 }921 }
711 fprintf(irp->f, ")result=");922 fprintf(irp->f, ")result=");
712 ir_print_result_loc(irp, call_instruction->result_loc);923 ir_print_result_loc(irp, call_instruction->result_loc);
713}924}
714925
715static void ir_print_call_gen(IrPrint *irp, IrInstructionCallGen *call_instruction) {926static void ir_print_call_gen(IrPrintGen *irp, IrInstGenCall *call_instruction) {
716 switch (call_instruction->modifier) {927 switch (call_instruction->modifier) {
717 case CallModifierNone:928 case CallModifierNone:
718 break;929 break;
...@@ -744,221 +955,291 @@ static void ir_print_call_gen(IrPrint *irp, IrInstructionCallGen *call_instructi...@@ -744,221 +955,291 @@ static void ir_print_call_gen(IrPrint *irp, IrInstructionCallGen *call_instructi
744 fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));955 fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));
745 } else {956 } else {
746 assert(call_instruction->fn_ref);957 assert(call_instruction->fn_ref);
747 ir_print_other_instruction(irp, call_instruction->fn_ref);958 ir_print_other_inst_gen(irp, call_instruction->fn_ref);
748 }959 }
749 fprintf(irp->f, "(");960 fprintf(irp->f, "(");
750 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {961 for (size_t i = 0; i < call_instruction->arg_count; i += 1) {
751 IrInstruction *arg = call_instruction->args[i];962 IrInstGen *arg = call_instruction->args[i];
752 if (i != 0)963 if (i != 0)
753 fprintf(irp->f, ", ");964 fprintf(irp->f, ", ");
754 ir_print_other_instruction(irp, arg);965 ir_print_other_inst_gen(irp, arg);
755 }966 }
756 fprintf(irp->f, ")result=");967 fprintf(irp->f, ")result=");
757 ir_print_other_instruction(irp, call_instruction->result_loc);968 ir_print_other_inst_gen(irp, call_instruction->result_loc);
758}969}
759970
760static void ir_print_cond_br(IrPrint *irp, IrInstructionCondBr *cond_br_instruction) {971static void ir_print_cond_br(IrPrintSrc *irp, IrInstSrcCondBr *inst) {
761 fprintf(irp->f, "if (");972 fprintf(irp->f, "if (");
762 ir_print_other_instruction(irp, cond_br_instruction->condition);973 ir_print_other_inst_src(irp, inst->condition);
763 fprintf(irp->f, ") ");974 fprintf(irp->f, ") ");
764 ir_print_other_block(irp, cond_br_instruction->then_block);975 ir_print_other_block(irp, inst->then_block);
765 fprintf(irp->f, " else ");976 fprintf(irp->f, " else ");
766 ir_print_other_block(irp, cond_br_instruction->else_block);977 ir_print_other_block(irp, inst->else_block);
767 if (cond_br_instruction->is_comptime != nullptr) {978 if (inst->is_comptime != nullptr) {
768 fprintf(irp->f, " // comptime = ");979 fprintf(irp->f, " // comptime = ");
769 ir_print_other_instruction(irp, cond_br_instruction->is_comptime);980 ir_print_other_inst_src(irp, inst->is_comptime);
770 }981 }
771}982}
772983
773static void ir_print_br(IrPrint *irp, IrInstructionBr *br_instruction) {984static void ir_print_cond_br(IrPrintGen *irp, IrInstGenCondBr *inst) {
985 fprintf(irp->f, "if (");
986 ir_print_other_inst_gen(irp, inst->condition);
987 fprintf(irp->f, ") ");
988 ir_print_other_block_gen(irp, inst->then_block);
989 fprintf(irp->f, " else ");
990 ir_print_other_block_gen(irp, inst->else_block);
991}
992
993static void ir_print_br(IrPrintSrc *irp, IrInstSrcBr *br_instruction) {
774 fprintf(irp->f, "goto ");994 fprintf(irp->f, "goto ");
775 ir_print_other_block(irp, br_instruction->dest_block);995 ir_print_other_block(irp, br_instruction->dest_block);
776 if (br_instruction->is_comptime != nullptr) {996 if (br_instruction->is_comptime != nullptr) {
777 fprintf(irp->f, " // comptime = ");997 fprintf(irp->f, " // comptime = ");
778 ir_print_other_instruction(irp, br_instruction->is_comptime);998 ir_print_other_inst_src(irp, br_instruction->is_comptime);
779 }999 }
780}1000}
7811001
782static void ir_print_phi(IrPrint *irp, IrInstructionPhi *phi_instruction) {1002static void ir_print_br(IrPrintGen *irp, IrInstGenBr *inst) {
1003 fprintf(irp->f, "goto ");
1004 ir_print_other_block_gen(irp, inst->dest_block);
1005}
1006
1007static void ir_print_phi(IrPrintSrc *irp, IrInstSrcPhi *phi_instruction) {
783 assert(phi_instruction->incoming_count != 0);1008 assert(phi_instruction->incoming_count != 0);
784 assert(phi_instruction->incoming_count != SIZE_MAX);1009 assert(phi_instruction->incoming_count != SIZE_MAX);
785 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {1010 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {
786 IrBasicBlock *incoming_block = phi_instruction->incoming_blocks[i];1011 IrBasicBlockSrc *incoming_block = phi_instruction->incoming_blocks[i];
787 IrInstruction *incoming_value = phi_instruction->incoming_values[i];1012 IrInstSrc *incoming_value = phi_instruction->incoming_values[i];
788 if (i != 0)1013 if (i != 0)
789 fprintf(irp->f, " ");1014 fprintf(irp->f, " ");
790 ir_print_other_block(irp, incoming_block);1015 ir_print_other_block(irp, incoming_block);
791 fprintf(irp->f, ":");1016 fprintf(irp->f, ":");
792 ir_print_other_instruction(irp, incoming_value);1017 ir_print_other_inst_src(irp, incoming_value);
793 }1018 }
794}1019}
7951020
796static void ir_print_container_init_list(IrPrint *irp, IrInstructionContainerInitList *instruction) {1021static void ir_print_phi(IrPrintGen *irp, IrInstGenPhi *phi_instruction) {
1022 assert(phi_instruction->incoming_count != 0);
1023 assert(phi_instruction->incoming_count != SIZE_MAX);
1024 for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) {
1025 IrBasicBlockGen *incoming_block = phi_instruction->incoming_blocks[i];
1026 IrInstGen *incoming_value = phi_instruction->incoming_values[i];
1027 if (i != 0)
1028 fprintf(irp->f, " ");
1029 ir_print_other_block_gen(irp, incoming_block);
1030 fprintf(irp->f, ":");
1031 ir_print_other_inst_gen(irp, incoming_value);
1032 }
1033}
1034
1035static void ir_print_container_init_list(IrPrintSrc *irp, IrInstSrcContainerInitList *instruction) {
797 fprintf(irp->f, "{");1036 fprintf(irp->f, "{");
798 if (instruction->item_count > 50) {1037 if (instruction->item_count > 50) {
799 fprintf(irp->f, "...(%" ZIG_PRI_usize " items)...", instruction->item_count);1038 fprintf(irp->f, "...(%" ZIG_PRI_usize " items)...", instruction->item_count);
800 } else {1039 } else {
801 for (size_t i = 0; i < instruction->item_count; i += 1) {1040 for (size_t i = 0; i < instruction->item_count; i += 1) {
802 IrInstruction *result_loc = instruction->elem_result_loc_list[i];1041 IrInstSrc *result_loc = instruction->elem_result_loc_list[i];
803 if (i != 0)1042 if (i != 0)
804 fprintf(irp->f, ", ");1043 fprintf(irp->f, ", ");
805 ir_print_other_instruction(irp, result_loc);1044 ir_print_other_inst_src(irp, result_loc);
806 }1045 }
807 }1046 }
808 fprintf(irp->f, "}result=");1047 fprintf(irp->f, "}result=");
809 ir_print_other_instruction(irp, instruction->result_loc);1048 ir_print_other_inst_src(irp, instruction->result_loc);
810}1049}
8111050
812static void ir_print_container_init_fields(IrPrint *irp, IrInstructionContainerInitFields *instruction) {1051static void ir_print_container_init_fields(IrPrintSrc *irp, IrInstSrcContainerInitFields *instruction) {
813 fprintf(irp->f, "{");1052 fprintf(irp->f, "{");
814 for (size_t i = 0; i < instruction->field_count; i += 1) {1053 for (size_t i = 0; i < instruction->field_count; i += 1) {
815 IrInstructionContainerInitFieldsField *field = &instruction->fields[i];1054 IrInstSrcContainerInitFieldsField *field = &instruction->fields[i];
816 const char *comma = (i == 0) ? "" : ", ";1055 const char *comma = (i == 0) ? "" : ", ";
817 fprintf(irp->f, "%s.%s = ", comma, buf_ptr(field->name));1056 fprintf(irp->f, "%s.%s = ", comma, buf_ptr(field->name));
818 ir_print_other_instruction(irp, field->result_loc);1057 ir_print_other_inst_src(irp, field->result_loc);
819 }1058 }
820 fprintf(irp->f, "}result=");1059 fprintf(irp->f, "}result=");
821 ir_print_other_instruction(irp, instruction->result_loc);1060 ir_print_other_inst_src(irp, instruction->result_loc);
1061}
1062
1063static void ir_print_unreachable(IrPrintSrc *irp, IrInstSrcUnreachable *instruction) {
1064 fprintf(irp->f, "unreachable");
822}1065}
8231066
824static void ir_print_unreachable(IrPrint *irp, IrInstructionUnreachable *instruction) {1067static void ir_print_unreachable(IrPrintGen *irp, IrInstGenUnreachable *instruction) {
825 fprintf(irp->f, "unreachable");1068 fprintf(irp->f, "unreachable");
826}1069}
8271070
828static void ir_print_elem_ptr(IrPrint *irp, IrInstructionElemPtr *instruction) {1071static void ir_print_elem_ptr(IrPrintSrc *irp, IrInstSrcElemPtr *instruction) {
829 fprintf(irp->f, "&");1072 fprintf(irp->f, "&");
830 ir_print_other_instruction(irp, instruction->array_ptr);1073 ir_print_other_inst_src(irp, instruction->array_ptr);
831 fprintf(irp->f, "[");1074 fprintf(irp->f, "[");
832 ir_print_other_instruction(irp, instruction->elem_index);1075 ir_print_other_inst_src(irp, instruction->elem_index);
833 fprintf(irp->f, "]");1076 fprintf(irp->f, "]");
834 if (!instruction->safety_check_on) {1077 if (!instruction->safety_check_on) {
835 fprintf(irp->f, " // no safety");1078 fprintf(irp->f, " // no safety");
836 }1079 }
837}1080}
8381081
839static void ir_print_var_ptr(IrPrint *irp, IrInstructionVarPtr *instruction) {1082static void ir_print_elem_ptr(IrPrintGen *irp, IrInstGenElemPtr *instruction) {
1083 fprintf(irp->f, "&");
1084 ir_print_other_inst_gen(irp, instruction->array_ptr);
1085 fprintf(irp->f, "[");
1086 ir_print_other_inst_gen(irp, instruction->elem_index);
1087 fprintf(irp->f, "]");
1088 if (!instruction->safety_check_on) {
1089 fprintf(irp->f, " // no safety");
1090 }
1091}
1092
1093static void ir_print_var_ptr(IrPrintSrc *irp, IrInstSrcVarPtr *instruction) {
1094 fprintf(irp->f, "&%s", instruction->var->name);
1095}
1096
1097static void ir_print_var_ptr(IrPrintGen *irp, IrInstGenVarPtr *instruction) {
840 fprintf(irp->f, "&%s", instruction->var->name);1098 fprintf(irp->f, "&%s", instruction->var->name);
841}1099}
8421100
843static void ir_print_return_ptr(IrPrint *irp, IrInstructionReturnPtr *instruction) {1101static void ir_print_return_ptr(IrPrintGen *irp, IrInstGenReturnPtr *instruction) {
844 fprintf(irp->f, "@ReturnPtr");1102 fprintf(irp->f, "@ReturnPtr");
845}1103}
8461104
847static void ir_print_load_ptr(IrPrint *irp, IrInstructionLoadPtr *instruction) {1105static void ir_print_load_ptr(IrPrintSrc *irp, IrInstSrcLoadPtr *instruction) {
848 ir_print_other_instruction(irp, instruction->ptr);1106 ir_print_other_inst_src(irp, instruction->ptr);
849 fprintf(irp->f, ".*");1107 fprintf(irp->f, ".*");
850}1108}
8511109
852static void ir_print_load_ptr_gen(IrPrint *irp, IrInstructionLoadPtrGen *instruction) {1110static void ir_print_load_ptr_gen(IrPrintGen *irp, IrInstGenLoadPtr *instruction) {
853 fprintf(irp->f, "loadptr(");1111 fprintf(irp->f, "loadptr(");
854 ir_print_other_instruction(irp, instruction->ptr);1112 ir_print_other_inst_gen(irp, instruction->ptr);
855 fprintf(irp->f, ")result=");1113 fprintf(irp->f, ")result=");
856 ir_print_other_instruction(irp, instruction->result_loc);1114 ir_print_other_inst_gen(irp, instruction->result_loc);
1115}
1116
1117static void ir_print_store_ptr(IrPrintSrc *irp, IrInstSrcStorePtr *instruction) {
1118 fprintf(irp->f, "*");
1119 ir_print_var_src(irp, instruction->ptr);
1120 fprintf(irp->f, " = ");
1121 ir_print_other_inst_src(irp, instruction->value);
857}1122}
8581123
859static void ir_print_store_ptr(IrPrint *irp, IrInstructionStorePtr *instruction) {1124static void ir_print_store_ptr(IrPrintGen *irp, IrInstGenStorePtr *instruction) {
860 fprintf(irp->f, "*");1125 fprintf(irp->f, "*");
861 ir_print_var_instruction(irp, instruction->ptr);1126 ir_print_var_gen(irp, instruction->ptr);
862 fprintf(irp->f, " = ");1127 fprintf(irp->f, " = ");
863 ir_print_other_instruction(irp, instruction->value);1128 ir_print_other_inst_gen(irp, instruction->value);
864}1129}
8651130
866static void ir_print_vector_store_elem(IrPrint *irp, IrInstructionVectorStoreElem *instruction) {1131static void ir_print_vector_store_elem(IrPrintGen *irp, IrInstGenVectorStoreElem *instruction) {
867 fprintf(irp->f, "vector_ptr=");1132 fprintf(irp->f, "vector_ptr=");
868 ir_print_var_instruction(irp, instruction->vector_ptr);1133 ir_print_var_gen(irp, instruction->vector_ptr);
869 fprintf(irp->f, ",index=");1134 fprintf(irp->f, ",index=");
870 ir_print_var_instruction(irp, instruction->index);1135 ir_print_var_gen(irp, instruction->index);
871 fprintf(irp->f, ",value=");1136 fprintf(irp->f, ",value=");
872 ir_print_other_instruction(irp, instruction->value);1137 ir_print_other_inst_gen(irp, instruction->value);
873}1138}
8741139
875static void ir_print_typeof(IrPrint *irp, IrInstructionTypeOf *instruction) {1140static void ir_print_typeof(IrPrintSrc *irp, IrInstSrcTypeOf *instruction) {
876 fprintf(irp->f, "@TypeOf(");1141 fprintf(irp->f, "@TypeOf(");
877 ir_print_other_instruction(irp, instruction->value);1142 ir_print_other_inst_src(irp, instruction->value);
878 fprintf(irp->f, ")");1143 fprintf(irp->f, ")");
879}1144}
8801145
881static void ir_print_field_ptr(IrPrint *irp, IrInstructionFieldPtr *instruction) {1146static void ir_print_binary_not(IrPrintGen *irp, IrInstGenBinaryNot *instruction) {
1147 fprintf(irp->f, "~");
1148 ir_print_other_inst_gen(irp, instruction->operand);
1149}
1150
1151static void ir_print_negation(IrPrintGen *irp, IrInstGenNegation *instruction) {
1152 fprintf(irp->f, "-");
1153 ir_print_other_inst_gen(irp, instruction->operand);
1154}
1155
1156static void ir_print_negation_wrapping(IrPrintGen *irp, IrInstGenNegationWrapping *instruction) {
1157 fprintf(irp->f, "-%%");
1158 ir_print_other_inst_gen(irp, instruction->operand);
1159}
1160
1161
1162static void ir_print_field_ptr(IrPrintSrc *irp, IrInstSrcFieldPtr *instruction) {
882 if (instruction->field_name_buffer) {1163 if (instruction->field_name_buffer) {
883 fprintf(irp->f, "fieldptr ");1164 fprintf(irp->f, "fieldptr ");
884 ir_print_other_instruction(irp, instruction->container_ptr);1165 ir_print_other_inst_src(irp, instruction->container_ptr);
885 fprintf(irp->f, ".%s", buf_ptr(instruction->field_name_buffer));1166 fprintf(irp->f, ".%s", buf_ptr(instruction->field_name_buffer));
886 } else {1167 } else {
887 assert(instruction->field_name_expr);1168 assert(instruction->field_name_expr);
888 fprintf(irp->f, "@field(");1169 fprintf(irp->f, "@field(");
889 ir_print_other_instruction(irp, instruction->container_ptr);1170 ir_print_other_inst_src(irp, instruction->container_ptr);
890 fprintf(irp->f, ", ");1171 fprintf(irp->f, ", ");
891 ir_print_other_instruction(irp, instruction->field_name_expr);1172 ir_print_other_inst_src(irp, instruction->field_name_expr);
892 fprintf(irp->f, ")");1173 fprintf(irp->f, ")");
893 }1174 }
894}1175}
8951176
896static void ir_print_struct_field_ptr(IrPrint *irp, IrInstructionStructFieldPtr *instruction) {1177static void ir_print_struct_field_ptr(IrPrintGen *irp, IrInstGenStructFieldPtr *instruction) {
897 fprintf(irp->f, "@StructFieldPtr(&");1178 fprintf(irp->f, "@StructFieldPtr(&");
898 ir_print_other_instruction(irp, instruction->struct_ptr);1179 ir_print_other_inst_gen(irp, instruction->struct_ptr);
899 fprintf(irp->f, ".%s", buf_ptr(instruction->field->name));1180 fprintf(irp->f, ".%s", buf_ptr(instruction->field->name));
900 fprintf(irp->f, ")");1181 fprintf(irp->f, ")");
901}1182}
9021183
903static void ir_print_union_field_ptr(IrPrint *irp, IrInstructionUnionFieldPtr *instruction) {1184static void ir_print_union_field_ptr(IrPrintGen *irp, IrInstGenUnionFieldPtr *instruction) {
904 fprintf(irp->f, "@UnionFieldPtr(&");1185 fprintf(irp->f, "@UnionFieldPtr(&");
905 ir_print_other_instruction(irp, instruction->union_ptr);1186 ir_print_other_inst_gen(irp, instruction->union_ptr);
906 fprintf(irp->f, ".%s", buf_ptr(instruction->field->enum_field->name));1187 fprintf(irp->f, ".%s", buf_ptr(instruction->field->enum_field->name));
907 fprintf(irp->f, ")");1188 fprintf(irp->f, ")");
908}1189}
9091190
910static void ir_print_set_cold(IrPrint *irp, IrInstructionSetCold *instruction) {1191static void ir_print_set_cold(IrPrintSrc *irp, IrInstSrcSetCold *instruction) {
911 fprintf(irp->f, "@setCold(");1192 fprintf(irp->f, "@setCold(");
912 ir_print_other_instruction(irp, instruction->is_cold);1193 ir_print_other_inst_src(irp, instruction->is_cold);
913 fprintf(irp->f, ")");1194 fprintf(irp->f, ")");
914}1195}
9151196
916static void ir_print_set_runtime_safety(IrPrint *irp, IrInstructionSetRuntimeSafety *instruction) {1197static void ir_print_set_runtime_safety(IrPrintSrc *irp, IrInstSrcSetRuntimeSafety *instruction) {
917 fprintf(irp->f, "@setRuntimeSafety(");1198 fprintf(irp->f, "@setRuntimeSafety(");
918 ir_print_other_instruction(irp, instruction->safety_on);1199 ir_print_other_inst_src(irp, instruction->safety_on);
919 fprintf(irp->f, ")");1200 fprintf(irp->f, ")");
920}1201}
9211202
922static void ir_print_set_float_mode(IrPrint *irp, IrInstructionSetFloatMode *instruction) {1203static void ir_print_set_float_mode(IrPrintSrc *irp, IrInstSrcSetFloatMode *instruction) {
923 fprintf(irp->f, "@setFloatMode(");1204 fprintf(irp->f, "@setFloatMode(");
924 ir_print_other_instruction(irp, instruction->scope_value);1205 ir_print_other_inst_src(irp, instruction->scope_value);
925 fprintf(irp->f, ", ");1206 fprintf(irp->f, ", ");
926 ir_print_other_instruction(irp, instruction->mode_value);1207 ir_print_other_inst_src(irp, instruction->mode_value);
927 fprintf(irp->f, ")");1208 fprintf(irp->f, ")");
928}1209}
9291210
930static void ir_print_array_type(IrPrint *irp, IrInstructionArrayType *instruction) {1211static void ir_print_array_type(IrPrintSrc *irp, IrInstSrcArrayType *instruction) {
931 fprintf(irp->f, "[");1212 fprintf(irp->f, "[");
932 ir_print_other_instruction(irp, instruction->size);1213 ir_print_other_inst_src(irp, instruction->size);
933 if (instruction->sentinel != nullptr) {1214 if (instruction->sentinel != nullptr) {
934 fprintf(irp->f, ":");1215 fprintf(irp->f, ":");
935 ir_print_other_instruction(irp, instruction->sentinel);1216 ir_print_other_inst_src(irp, instruction->sentinel);
936 }1217 }
937 fprintf(irp->f, "]");1218 fprintf(irp->f, "]");
938 ir_print_other_instruction(irp, instruction->child_type);1219 ir_print_other_inst_src(irp, instruction->child_type);
939}1220}
9401221
941static void ir_print_slice_type(IrPrint *irp, IrInstructionSliceType *instruction) {1222static void ir_print_slice_type(IrPrintSrc *irp, IrInstSrcSliceType *instruction) {
942 const char *const_kw = instruction->is_const ? "const " : "";1223 const char *const_kw = instruction->is_const ? "const " : "";
943 fprintf(irp->f, "[]%s", const_kw);1224 fprintf(irp->f, "[]%s", const_kw);
944 ir_print_other_instruction(irp, instruction->child_type);1225 ir_print_other_inst_src(irp, instruction->child_type);
945}1226}
9461227
947static void ir_print_any_frame_type(IrPrint *irp, IrInstructionAnyFrameType *instruction) {1228static void ir_print_any_frame_type(IrPrintSrc *irp, IrInstSrcAnyFrameType *instruction) {
948 if (instruction->payload_type == nullptr) {1229 if (instruction->payload_type == nullptr) {
949 fprintf(irp->f, "anyframe");1230 fprintf(irp->f, "anyframe");
950 } else {1231 } else {
951 fprintf(irp->f, "anyframe->");1232 fprintf(irp->f, "anyframe->");
952 ir_print_other_instruction(irp, instruction->payload_type);1233 ir_print_other_inst_src(irp, instruction->payload_type);
953 }1234 }
954}1235}
9551236
956static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {1237static void ir_print_asm_src(IrPrintSrc *irp, IrInstSrcAsm *instruction) {
957 assert(instruction->base.source_node->type == NodeTypeAsmExpr);1238 assert(instruction->base.base.source_node->type == NodeTypeAsmExpr);
958 AstNodeAsmExpr *asm_expr = &instruction->base.source_node->data.asm_expr;1239 AstNodeAsmExpr *asm_expr = &instruction->base.base.source_node->data.asm_expr;
959 const char *volatile_kw = instruction->has_side_effects ? " volatile" : "";1240 const char *volatile_kw = instruction->has_side_effects ? " volatile" : "";
960 fprintf(irp->f, "asm%s (", volatile_kw);1241 fprintf(irp->f, "asm%s (", volatile_kw);
961 ir_print_other_instruction(irp, instruction->asm_template);1242 ir_print_other_inst_src(irp, instruction->asm_template);
9621243
963 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {1244 for (size_t i = 0; i < asm_expr->output_list.length; i += 1) {
964 AsmOutput *asm_output = asm_expr->output_list.at(i);1245 AsmOutput *asm_output = asm_expr->output_list.at(i);
...@@ -969,7 +1250,7 @@ static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {...@@ -969,7 +1250,7 @@ static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {
969 buf_ptr(asm_output->constraint));1250 buf_ptr(asm_output->constraint));
970 if (asm_output->return_type) {1251 if (asm_output->return_type) {
971 fprintf(irp->f, "-> ");1252 fprintf(irp->f, "-> ");
972 ir_print_other_instruction(irp, instruction->output_types[i]);1253 ir_print_other_inst_src(irp, instruction->output_types[i]);
973 } else {1254 } else {
974 fprintf(irp->f, "%s", buf_ptr(asm_output->variable_name));1255 fprintf(irp->f, "%s", buf_ptr(asm_output->variable_name));
975 }1256 }
...@@ -984,7 +1265,7 @@ static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {...@@ -984,7 +1265,7 @@ static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {
984 fprintf(irp->f, "[%s] \"%s\" (",1265 fprintf(irp->f, "[%s] \"%s\" (",
985 buf_ptr(asm_input->asm_symbolic_name),1266 buf_ptr(asm_input->asm_symbolic_name),
986 buf_ptr(asm_input->constraint));1267 buf_ptr(asm_input->constraint));
987 ir_print_other_instruction(irp, instruction->input_list[i]);1268 ir_print_other_inst_src(irp, instruction->input_list[i]);
988 fprintf(irp->f, ")");1269 fprintf(irp->f, ")");
989 }1270 }
990 fprintf(irp->f, " : ");1271 fprintf(irp->f, " : ");
...@@ -996,9 +1277,9 @@ static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {...@@ -996,9 +1277,9 @@ static void ir_print_asm_src(IrPrint *irp, IrInstructionAsmSrc *instruction) {
996 fprintf(irp->f, ")");1277 fprintf(irp->f, ")");
997}1278}
9981279
999static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {1280static void ir_print_asm_gen(IrPrintGen *irp, IrInstGenAsm *instruction) {
1000 assert(instruction->base.source_node->type == NodeTypeAsmExpr);1281 assert(instruction->base.base.source_node->type == NodeTypeAsmExpr);
1001 AstNodeAsmExpr *asm_expr = &instruction->base.source_node->data.asm_expr;1282 AstNodeAsmExpr *asm_expr = &instruction->base.base.source_node->data.asm_expr;
1002 const char *volatile_kw = instruction->has_side_effects ? " volatile" : "";1283 const char *volatile_kw = instruction->has_side_effects ? " volatile" : "";
1003 fprintf(irp->f, "asm%s (\"%s\") : ", volatile_kw, buf_ptr(instruction->asm_template));1284 fprintf(irp->f, "asm%s (\"%s\") : ", volatile_kw, buf_ptr(instruction->asm_template));
10041285
...@@ -1011,7 +1292,7 @@ static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {...@@ -1011,7 +1292,7 @@ static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {
1011 buf_ptr(asm_output->constraint));1292 buf_ptr(asm_output->constraint));
1012 if (asm_output->return_type) {1293 if (asm_output->return_type) {
1013 fprintf(irp->f, "-> ");1294 fprintf(irp->f, "-> ");
1014 ir_print_other_instruction(irp, instruction->output_types[i]);1295 ir_print_other_inst_gen(irp, instruction->output_types[i]);
1015 } else {1296 } else {
1016 fprintf(irp->f, "%s", buf_ptr(asm_output->variable_name));1297 fprintf(irp->f, "%s", buf_ptr(asm_output->variable_name));
1017 }1298 }
...@@ -1026,7 +1307,7 @@ static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {...@@ -1026,7 +1307,7 @@ static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {
1026 fprintf(irp->f, "[%s] \"%s\" (",1307 fprintf(irp->f, "[%s] \"%s\" (",
1027 buf_ptr(asm_input->asm_symbolic_name),1308 buf_ptr(asm_input->asm_symbolic_name),
1028 buf_ptr(asm_input->constraint));1309 buf_ptr(asm_input->constraint));
1029 ir_print_other_instruction(irp, instruction->input_list[i]);1310 ir_print_other_inst_gen(irp, instruction->input_list[i]);
1030 fprintf(irp->f, ")");1311 fprintf(irp->f, ")");
1031 }1312 }
1032 fprintf(irp->f, " : ");1313 fprintf(irp->f, " : ");
...@@ -1038,96 +1319,120 @@ static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {...@@ -1038,96 +1319,120 @@ static void ir_print_asm_gen(IrPrint *irp, IrInstructionAsmGen *instruction) {
1038 fprintf(irp->f, ")");1319 fprintf(irp->f, ")");
1039}1320}
10401321
1041static void ir_print_size_of(IrPrint *irp, IrInstructionSizeOf *instruction) {1322static void ir_print_size_of(IrPrintSrc *irp, IrInstSrcSizeOf *instruction) {
1042 if (instruction->bit_size)1323 if (instruction->bit_size)
1043 fprintf(irp->f, "@bitSizeOf(");1324 fprintf(irp->f, "@bitSizeOf(");
1044 else1325 else
1045 fprintf(irp->f, "@sizeOf(");1326 fprintf(irp->f, "@sizeOf(");
1046 ir_print_other_instruction(irp, instruction->type_value);1327 ir_print_other_inst_src(irp, instruction->type_value);
1047 fprintf(irp->f, ")");1328 fprintf(irp->f, ")");
1048}1329}
10491330
1050static void ir_print_test_non_null(IrPrint *irp, IrInstructionTestNonNull *instruction) {1331static void ir_print_test_non_null(IrPrintSrc *irp, IrInstSrcTestNonNull *instruction) {
1051 ir_print_other_instruction(irp, instruction->value);1332 ir_print_other_inst_src(irp, instruction->value);
1333 fprintf(irp->f, " != null");
1334}
1335
1336static void ir_print_test_non_null(IrPrintGen *irp, IrInstGenTestNonNull *instruction) {
1337 ir_print_other_inst_gen(irp, instruction->value);
1052 fprintf(irp->f, " != null");1338 fprintf(irp->f, " != null");
1053}1339}
10541340
1055static void ir_print_optional_unwrap_ptr(IrPrint *irp, IrInstructionOptionalUnwrapPtr *instruction) {1341static void ir_print_optional_unwrap_ptr(IrPrintSrc *irp, IrInstSrcOptionalUnwrapPtr *instruction) {
1056 fprintf(irp->f, "&");1342 fprintf(irp->f, "&");
1057 ir_print_other_instruction(irp, instruction->base_ptr);1343 ir_print_other_inst_src(irp, instruction->base_ptr);
1058 fprintf(irp->f, ".*.?");1344 fprintf(irp->f, ".*.?");
1059 if (!instruction->safety_check_on) {1345 if (!instruction->safety_check_on) {
1060 fprintf(irp->f, " // no safety");1346 fprintf(irp->f, " // no safety");
1061 }1347 }
1062}1348}
10631349
1064static void ir_print_clz(IrPrint *irp, IrInstructionClz *instruction) {1350static void ir_print_optional_unwrap_ptr(IrPrintGen *irp, IrInstGenOptionalUnwrapPtr *instruction) {
1065 fprintf(irp->f, "@clz(");1351 fprintf(irp->f, "&");
1066 if (instruction->type != nullptr) {1352 ir_print_other_inst_gen(irp, instruction->base_ptr);
1067 ir_print_other_instruction(irp, instruction->type);1353 fprintf(irp->f, ".*.?");
1068 } else {1354 if (!instruction->safety_check_on) {
1069 fprintf(irp->f, "null");1355 fprintf(irp->f, " // no safety");
1070 }1356 }
1357}
1358
1359static void ir_print_clz(IrPrintSrc *irp, IrInstSrcClz *instruction) {
1360 fprintf(irp->f, "@clz(");
1361 ir_print_other_inst_src(irp, instruction->type);
1071 fprintf(irp->f, ",");1362 fprintf(irp->f, ",");
1072 ir_print_other_instruction(irp, instruction->op);1363 ir_print_other_inst_src(irp, instruction->op);
1073 fprintf(irp->f, ")");1364 fprintf(irp->f, ")");
1074}1365}
10751366
1076static void ir_print_ctz(IrPrint *irp, IrInstructionCtz *instruction) {1367static void ir_print_clz(IrPrintGen *irp, IrInstGenClz *instruction) {
1368 fprintf(irp->f, "@clz(");
1369 ir_print_other_inst_gen(irp, instruction->op);
1370 fprintf(irp->f, ")");
1371}
1372
1373static void ir_print_ctz(IrPrintSrc *irp, IrInstSrcCtz *instruction) {
1077 fprintf(irp->f, "@ctz(");1374 fprintf(irp->f, "@ctz(");
1078 if (instruction->type != nullptr) {1375 ir_print_other_inst_src(irp, instruction->type);
1079 ir_print_other_instruction(irp, instruction->type);
1080 } else {
1081 fprintf(irp->f, "null");
1082 }
1083 fprintf(irp->f, ",");1376 fprintf(irp->f, ",");
1084 ir_print_other_instruction(irp, instruction->op);1377 ir_print_other_inst_src(irp, instruction->op);
1085 fprintf(irp->f, ")");1378 fprintf(irp->f, ")");
1086}1379}
10871380
1088static void ir_print_pop_count(IrPrint *irp, IrInstructionPopCount *instruction) {1381static void ir_print_ctz(IrPrintGen *irp, IrInstGenCtz *instruction) {
1382 fprintf(irp->f, "@ctz(");
1383 ir_print_other_inst_gen(irp, instruction->op);
1384 fprintf(irp->f, ")");
1385}
1386
1387static void ir_print_pop_count(IrPrintSrc *irp, IrInstSrcPopCount *instruction) {
1089 fprintf(irp->f, "@popCount(");1388 fprintf(irp->f, "@popCount(");
1090 if (instruction->type != nullptr) {1389 ir_print_other_inst_src(irp, instruction->type);
1091 ir_print_other_instruction(irp, instruction->type);
1092 } else {
1093 fprintf(irp->f, "null");
1094 }
1095 fprintf(irp->f, ",");1390 fprintf(irp->f, ",");
1096 ir_print_other_instruction(irp, instruction->op);1391 ir_print_other_inst_src(irp, instruction->op);
1097 fprintf(irp->f, ")");1392 fprintf(irp->f, ")");
1098}1393}
10991394
1100static void ir_print_bswap(IrPrint *irp, IrInstructionBswap *instruction) {1395static void ir_print_pop_count(IrPrintGen *irp, IrInstGenPopCount *instruction) {
1396 fprintf(irp->f, "@popCount(");
1397 ir_print_other_inst_gen(irp, instruction->op);
1398 fprintf(irp->f, ")");
1399}
1400
1401static void ir_print_bswap(IrPrintSrc *irp, IrInstSrcBswap *instruction) {
1101 fprintf(irp->f, "@byteSwap(");1402 fprintf(irp->f, "@byteSwap(");
1102 if (instruction->type != nullptr) {1403 ir_print_other_inst_src(irp, instruction->type);
1103 ir_print_other_instruction(irp, instruction->type);
1104 } else {
1105 fprintf(irp->f, "null");
1106 }
1107 fprintf(irp->f, ",");1404 fprintf(irp->f, ",");
1108 ir_print_other_instruction(irp, instruction->op);1405 ir_print_other_inst_src(irp, instruction->op);
1109 fprintf(irp->f, ")");1406 fprintf(irp->f, ")");
1110}1407}
11111408
1112static void ir_print_bit_reverse(IrPrint *irp, IrInstructionBitReverse *instruction) {1409static void ir_print_bswap(IrPrintGen *irp, IrInstGenBswap *instruction) {
1410 fprintf(irp->f, "@byteSwap(");
1411 ir_print_other_inst_gen(irp, instruction->op);
1412 fprintf(irp->f, ")");
1413}
1414
1415static void ir_print_bit_reverse(IrPrintSrc *irp, IrInstSrcBitReverse *instruction) {
1113 fprintf(irp->f, "@bitReverse(");1416 fprintf(irp->f, "@bitReverse(");
1114 if (instruction->type != nullptr) {1417 ir_print_other_inst_src(irp, instruction->type);
1115 ir_print_other_instruction(irp, instruction->type);
1116 } else {
1117 fprintf(irp->f, "null");
1118 }
1119 fprintf(irp->f, ",");1418 fprintf(irp->f, ",");
1120 ir_print_other_instruction(irp, instruction->op);1419 ir_print_other_inst_src(irp, instruction->op);
1121 fprintf(irp->f, ")");1420 fprintf(irp->f, ")");
1122}1421}
11231422
1124static void ir_print_switch_br(IrPrint *irp, IrInstructionSwitchBr *instruction) {1423static void ir_print_bit_reverse(IrPrintGen *irp, IrInstGenBitReverse *instruction) {
1424 fprintf(irp->f, "@bitReverse(");
1425 ir_print_other_inst_gen(irp, instruction->op);
1426 fprintf(irp->f, ")");
1427}
1428
1429static void ir_print_switch_br(IrPrintSrc *irp, IrInstSrcSwitchBr *instruction) {
1125 fprintf(irp->f, "switch (");1430 fprintf(irp->f, "switch (");
1126 ir_print_other_instruction(irp, instruction->target_value);1431 ir_print_other_inst_src(irp, instruction->target_value);
1127 fprintf(irp->f, ") ");1432 fprintf(irp->f, ") ");
1128 for (size_t i = 0; i < instruction->case_count; i += 1) {1433 for (size_t i = 0; i < instruction->case_count; i += 1) {
1129 IrInstructionSwitchBrCase *this_case = &instruction->cases[i];1434 IrInstSrcSwitchBrCase *this_case = &instruction->cases[i];
1130 ir_print_other_instruction(irp, this_case->value);1435 ir_print_other_inst_src(irp, this_case->value);
1131 fprintf(irp->f, " => ");1436 fprintf(irp->f, " => ");
1132 ir_print_other_block(irp, this_case->block);1437 ir_print_other_block(irp, this_case->block);
1133 fprintf(irp->f, ", ");1438 fprintf(irp->f, ", ");
...@@ -1136,359 +1441,453 @@ static void ir_print_switch_br(IrPrint *irp, IrInstructionSwitchBr *instruction)...@@ -1136,359 +1441,453 @@ static void ir_print_switch_br(IrPrint *irp, IrInstructionSwitchBr *instruction)
1136 ir_print_other_block(irp, instruction->else_block);1441 ir_print_other_block(irp, instruction->else_block);
1137 if (instruction->is_comptime != nullptr) {1442 if (instruction->is_comptime != nullptr) {
1138 fprintf(irp->f, " // comptime = ");1443 fprintf(irp->f, " // comptime = ");
1139 ir_print_other_instruction(irp, instruction->is_comptime);1444 ir_print_other_inst_src(irp, instruction->is_comptime);
1445 }
1446}
1447
1448static void ir_print_switch_br(IrPrintGen *irp, IrInstGenSwitchBr *instruction) {
1449 fprintf(irp->f, "switch (");
1450 ir_print_other_inst_gen(irp, instruction->target_value);
1451 fprintf(irp->f, ") ");
1452 for (size_t i = 0; i < instruction->case_count; i += 1) {
1453 IrInstGenSwitchBrCase *this_case = &instruction->cases[i];
1454 ir_print_other_inst_gen(irp, this_case->value);
1455 fprintf(irp->f, " => ");
1456 ir_print_other_block_gen(irp, this_case->block);
1457 fprintf(irp->f, ", ");
1140 }1458 }
1459 fprintf(irp->f, "else => ");
1460 ir_print_other_block_gen(irp, instruction->else_block);
1141}1461}
11421462
1143static void ir_print_switch_var(IrPrint *irp, IrInstructionSwitchVar *instruction) {1463static void ir_print_switch_var(IrPrintSrc *irp, IrInstSrcSwitchVar *instruction) {
1144 fprintf(irp->f, "switchvar ");1464 fprintf(irp->f, "switchvar ");
1145 ir_print_other_instruction(irp, instruction->target_value_ptr);1465 ir_print_other_inst_src(irp, instruction->target_value_ptr);
1146 for (size_t i = 0; i < instruction->prongs_len; i += 1) {1466 for (size_t i = 0; i < instruction->prongs_len; i += 1) {
1147 fprintf(irp->f, ", ");1467 fprintf(irp->f, ", ");
1148 ir_print_other_instruction(irp, instruction->prongs_ptr[i]);1468 ir_print_other_inst_src(irp, instruction->prongs_ptr[i]);
1149 }1469 }
1150}1470}
11511471
1152static void ir_print_switch_else_var(IrPrint *irp, IrInstructionSwitchElseVar *instruction) {1472static void ir_print_switch_else_var(IrPrintSrc *irp, IrInstSrcSwitchElseVar *instruction) {
1153 fprintf(irp->f, "switchelsevar ");1473 fprintf(irp->f, "switchelsevar ");
1154 ir_print_other_instruction(irp, &instruction->switch_br->base);1474 ir_print_other_inst_src(irp, &instruction->switch_br->base);
1155}1475}
11561476
1157static void ir_print_switch_target(IrPrint *irp, IrInstructionSwitchTarget *instruction) {1477static void ir_print_switch_target(IrPrintSrc *irp, IrInstSrcSwitchTarget *instruction) {
1158 fprintf(irp->f, "switchtarget ");1478 fprintf(irp->f, "switchtarget ");
1159 ir_print_other_instruction(irp, instruction->target_value_ptr);1479 ir_print_other_inst_src(irp, instruction->target_value_ptr);
1160}1480}
11611481
1162static void ir_print_union_tag(IrPrint *irp, IrInstructionUnionTag *instruction) {1482static void ir_print_union_tag(IrPrintGen *irp, IrInstGenUnionTag *instruction) {
1163 fprintf(irp->f, "uniontag ");1483 fprintf(irp->f, "uniontag ");
1164 ir_print_other_instruction(irp, instruction->value);1484 ir_print_other_inst_gen(irp, instruction->value);
1165}1485}
11661486
1167static void ir_print_import(IrPrint *irp, IrInstructionImport *instruction) {1487static void ir_print_import(IrPrintSrc *irp, IrInstSrcImport *instruction) {
1168 fprintf(irp->f, "@import(");1488 fprintf(irp->f, "@import(");
1169 ir_print_other_instruction(irp, instruction->name);1489 ir_print_other_inst_src(irp, instruction->name);
1170 fprintf(irp->f, ")");1490 fprintf(irp->f, ")");
1171}1491}
11721492
1173static void ir_print_ref(IrPrint *irp, IrInstructionRef *instruction) {1493static void ir_print_ref(IrPrintSrc *irp, IrInstSrcRef *instruction) {
1174 const char *const_str = instruction->is_const ? "const " : "";1494 const char *const_str = instruction->is_const ? "const " : "";
1175 const char *volatile_str = instruction->is_volatile ? "volatile " : "";1495 const char *volatile_str = instruction->is_volatile ? "volatile " : "";
1176 fprintf(irp->f, "%s%sref ", const_str, volatile_str);1496 fprintf(irp->f, "%s%sref ", const_str, volatile_str);
1177 ir_print_other_instruction(irp, instruction->value);1497 ir_print_other_inst_src(irp, instruction->value);
1178}1498}
11791499
1180static void ir_print_ref_gen(IrPrint *irp, IrInstructionRefGen *instruction) {1500static void ir_print_ref_gen(IrPrintGen *irp, IrInstGenRef *instruction) {
1181 fprintf(irp->f, "@ref(");1501 fprintf(irp->f, "@ref(");
1182 ir_print_other_instruction(irp, instruction->operand);1502 ir_print_other_inst_gen(irp, instruction->operand);
1183 fprintf(irp->f, ")result=");1503 fprintf(irp->f, ")result=");
1184 ir_print_other_instruction(irp, instruction->result_loc);1504 ir_print_other_inst_gen(irp, instruction->result_loc);
1185}1505}
11861506
1187static void ir_print_compile_err(IrPrint *irp, IrInstructionCompileErr *instruction) {1507static void ir_print_compile_err(IrPrintSrc *irp, IrInstSrcCompileErr *instruction) {
1188 fprintf(irp->f, "@compileError(");1508 fprintf(irp->f, "@compileError(");
1189 ir_print_other_instruction(irp, instruction->msg);1509 ir_print_other_inst_src(irp, instruction->msg);
1190 fprintf(irp->f, ")");1510 fprintf(irp->f, ")");
1191}1511}
11921512
1193static void ir_print_compile_log(IrPrint *irp, IrInstructionCompileLog *instruction) {1513static void ir_print_compile_log(IrPrintSrc *irp, IrInstSrcCompileLog *instruction) {
1194 fprintf(irp->f, "@compileLog(");1514 fprintf(irp->f, "@compileLog(");
1195 for (size_t i = 0; i < instruction->msg_count; i += 1) {1515 for (size_t i = 0; i < instruction->msg_count; i += 1) {
1196 if (i != 0)1516 if (i != 0)
1197 fprintf(irp->f, ",");1517 fprintf(irp->f, ",");
1198 IrInstruction *msg = instruction->msg_list[i];1518 IrInstSrc *msg = instruction->msg_list[i];
1199 ir_print_other_instruction(irp, msg);1519 ir_print_other_inst_src(irp, msg);
1200 }1520 }
1201 fprintf(irp->f, ")");1521 fprintf(irp->f, ")");
1202}1522}
12031523
1204static void ir_print_err_name(IrPrint *irp, IrInstructionErrName *instruction) {1524static void ir_print_err_name(IrPrintSrc *irp, IrInstSrcErrName *instruction) {
1205 fprintf(irp->f, "@errorName(");1525 fprintf(irp->f, "@errorName(");
1206 ir_print_other_instruction(irp, instruction->value);1526 ir_print_other_inst_src(irp, instruction->value);
1207 fprintf(irp->f, ")");1527 fprintf(irp->f, ")");
1208}1528}
12091529
1210static void ir_print_c_import(IrPrint *irp, IrInstructionCImport *instruction) {1530static void ir_print_err_name(IrPrintGen *irp, IrInstGenErrName *instruction) {
1531 fprintf(irp->f, "@errorName(");
1532 ir_print_other_inst_gen(irp, instruction->value);
1533 fprintf(irp->f, ")");
1534}
1535
1536static void ir_print_c_import(IrPrintSrc *irp, IrInstSrcCImport *instruction) {
1211 fprintf(irp->f, "@cImport(...)");1537 fprintf(irp->f, "@cImport(...)");
1212}1538}
12131539
1214static void ir_print_c_include(IrPrint *irp, IrInstructionCInclude *instruction) {1540static void ir_print_c_include(IrPrintSrc *irp, IrInstSrcCInclude *instruction) {
1215 fprintf(irp->f, "@cInclude(");1541 fprintf(irp->f, "@cInclude(");
1216 ir_print_other_instruction(irp, instruction->name);1542 ir_print_other_inst_src(irp, instruction->name);
1217 fprintf(irp->f, ")");1543 fprintf(irp->f, ")");
1218}1544}
12191545
1220static void ir_print_c_define(IrPrint *irp, IrInstructionCDefine *instruction) {1546static void ir_print_c_define(IrPrintSrc *irp, IrInstSrcCDefine *instruction) {
1221 fprintf(irp->f, "@cDefine(");1547 fprintf(irp->f, "@cDefine(");
1222 ir_print_other_instruction(irp, instruction->name);1548 ir_print_other_inst_src(irp, instruction->name);
1223 fprintf(irp->f, ", ");1549 fprintf(irp->f, ", ");
1224 ir_print_other_instruction(irp, instruction->value);1550 ir_print_other_inst_src(irp, instruction->value);
1225 fprintf(irp->f, ")");1551 fprintf(irp->f, ")");
1226}1552}
12271553
1228static void ir_print_c_undef(IrPrint *irp, IrInstructionCUndef *instruction) {1554static void ir_print_c_undef(IrPrintSrc *irp, IrInstSrcCUndef *instruction) {
1229 fprintf(irp->f, "@cUndef(");1555 fprintf(irp->f, "@cUndef(");
1230 ir_print_other_instruction(irp, instruction->name);1556 ir_print_other_inst_src(irp, instruction->name);
1231 fprintf(irp->f, ")");1557 fprintf(irp->f, ")");
1232}1558}
12331559
1234static void ir_print_embed_file(IrPrint *irp, IrInstructionEmbedFile *instruction) {1560static void ir_print_embed_file(IrPrintSrc *irp, IrInstSrcEmbedFile *instruction) {
1235 fprintf(irp->f, "@embedFile(");1561 fprintf(irp->f, "@embedFile(");
1236 ir_print_other_instruction(irp, instruction->name);1562 ir_print_other_inst_src(irp, instruction->name);
1237 fprintf(irp->f, ")");1563 fprintf(irp->f, ")");
1238}1564}
12391565
1240static void ir_print_cmpxchg_src(IrPrint *irp, IrInstructionCmpxchgSrc *instruction) {1566static void ir_print_cmpxchg_src(IrPrintSrc *irp, IrInstSrcCmpxchg *instruction) {
1241 fprintf(irp->f, "@cmpxchg(");1567 fprintf(irp->f, "@cmpxchg(");
1242 ir_print_other_instruction(irp, instruction->ptr);1568 ir_print_other_inst_src(irp, instruction->ptr);
1243 fprintf(irp->f, ", ");1569 fprintf(irp->f, ", ");
1244 ir_print_other_instruction(irp, instruction->cmp_value);1570 ir_print_other_inst_src(irp, instruction->cmp_value);
1245 fprintf(irp->f, ", ");1571 fprintf(irp->f, ", ");
1246 ir_print_other_instruction(irp, instruction->new_value);1572 ir_print_other_inst_src(irp, instruction->new_value);
1247 fprintf(irp->f, ", ");1573 fprintf(irp->f, ", ");
1248 ir_print_other_instruction(irp, instruction->success_order_value);1574 ir_print_other_inst_src(irp, instruction->success_order_value);
1249 fprintf(irp->f, ", ");1575 fprintf(irp->f, ", ");
1250 ir_print_other_instruction(irp, instruction->failure_order_value);1576 ir_print_other_inst_src(irp, instruction->failure_order_value);
1251 fprintf(irp->f, ")result=");1577 fprintf(irp->f, ")result=");
1252 ir_print_result_loc(irp, instruction->result_loc);1578 ir_print_result_loc(irp, instruction->result_loc);
1253}1579}
12541580
1255static void ir_print_cmpxchg_gen(IrPrint *irp, IrInstructionCmpxchgGen *instruction) {1581static void ir_print_cmpxchg_gen(IrPrintGen *irp, IrInstGenCmpxchg *instruction) {
1256 fprintf(irp->f, "@cmpxchg(");1582 fprintf(irp->f, "@cmpxchg(");
1257 ir_print_other_instruction(irp, instruction->ptr);1583 ir_print_other_inst_gen(irp, instruction->ptr);
1258 fprintf(irp->f, ", ");1584 fprintf(irp->f, ", ");
1259 ir_print_other_instruction(irp, instruction->cmp_value);1585 ir_print_other_inst_gen(irp, instruction->cmp_value);
1260 fprintf(irp->f, ", ");1586 fprintf(irp->f, ", ");
1261 ir_print_other_instruction(irp, instruction->new_value);1587 ir_print_other_inst_gen(irp, instruction->new_value);
1262 fprintf(irp->f, ", TODO print atomic orders)result=");1588 fprintf(irp->f, ", TODO print atomic orders)result=");
1263 ir_print_other_instruction(irp, instruction->result_loc);1589 ir_print_other_inst_gen(irp, instruction->result_loc);
1264}1590}
12651591
1266static void ir_print_fence(IrPrint *irp, IrInstructionFence *instruction) {1592static void ir_print_fence(IrPrintSrc *irp, IrInstSrcFence *instruction) {
1267 fprintf(irp->f, "@fence(");1593 fprintf(irp->f, "@fence(");
1268 ir_print_other_instruction(irp, instruction->order_value);1594 ir_print_other_inst_src(irp, instruction->order);
1269 fprintf(irp->f, ")");1595 fprintf(irp->f, ")");
1270}1596}
12711597
1272static void ir_print_truncate(IrPrint *irp, IrInstructionTruncate *instruction) {1598static const char *atomic_order_str(AtomicOrder order) {
1599 switch (order) {
1600 case AtomicOrderUnordered: return "Unordered";
1601 case AtomicOrderMonotonic: return "Monotonic";
1602 case AtomicOrderAcquire: return "Acquire";
1603 case AtomicOrderRelease: return "Release";
1604 case AtomicOrderAcqRel: return "AcqRel";
1605 case AtomicOrderSeqCst: return "SeqCst";
1606 }
1607 zig_unreachable();
1608}
1609
1610static void ir_print_fence(IrPrintGen *irp, IrInstGenFence *instruction) {
1611 fprintf(irp->f, "fence %s", atomic_order_str(instruction->order));
1612}
1613
1614static void ir_print_truncate(IrPrintSrc *irp, IrInstSrcTruncate *instruction) {
1273 fprintf(irp->f, "@truncate(");1615 fprintf(irp->f, "@truncate(");
1274 ir_print_other_instruction(irp, instruction->dest_type);1616 ir_print_other_inst_src(irp, instruction->dest_type);
1275 fprintf(irp->f, ", ");1617 fprintf(irp->f, ", ");
1276 ir_print_other_instruction(irp, instruction->target);1618 ir_print_other_inst_src(irp, instruction->target);
1277 fprintf(irp->f, ")");1619 fprintf(irp->f, ")");
1278}1620}
12791621
1280static void ir_print_int_cast(IrPrint *irp, IrInstructionIntCast *instruction) {1622static void ir_print_truncate(IrPrintGen *irp, IrInstGenTruncate *instruction) {
1623 fprintf(irp->f, "@truncate(");
1624 ir_print_other_inst_gen(irp, instruction->target);
1625 fprintf(irp->f, ")");
1626}
1627
1628static void ir_print_int_cast(IrPrintSrc *irp, IrInstSrcIntCast *instruction) {
1281 fprintf(irp->f, "@intCast(");1629 fprintf(irp->f, "@intCast(");
1282 ir_print_other_instruction(irp, instruction->dest_type);1630 ir_print_other_inst_src(irp, instruction->dest_type);
1283 fprintf(irp->f, ", ");1631 fprintf(irp->f, ", ");
1284 ir_print_other_instruction(irp, instruction->target);1632 ir_print_other_inst_src(irp, instruction->target);
1285 fprintf(irp->f, ")");1633 fprintf(irp->f, ")");
1286}1634}
12871635
1288static void ir_print_float_cast(IrPrint *irp, IrInstructionFloatCast *instruction) {1636static void ir_print_float_cast(IrPrintSrc *irp, IrInstSrcFloatCast *instruction) {
1289 fprintf(irp->f, "@floatCast(");1637 fprintf(irp->f, "@floatCast(");
1290 ir_print_other_instruction(irp, instruction->dest_type);1638 ir_print_other_inst_src(irp, instruction->dest_type);
1291 fprintf(irp->f, ", ");1639 fprintf(irp->f, ", ");
1292 ir_print_other_instruction(irp, instruction->target);1640 ir_print_other_inst_src(irp, instruction->target);
1293 fprintf(irp->f, ")");1641 fprintf(irp->f, ")");
1294}1642}
12951643
1296static void ir_print_err_set_cast(IrPrint *irp, IrInstructionErrSetCast *instruction) {1644static void ir_print_err_set_cast(IrPrintSrc *irp, IrInstSrcErrSetCast *instruction) {
1297 fprintf(irp->f, "@errSetCast(");1645 fprintf(irp->f, "@errSetCast(");
1298 ir_print_other_instruction(irp, instruction->dest_type);1646 ir_print_other_inst_src(irp, instruction->dest_type);
1299 fprintf(irp->f, ", ");1647 fprintf(irp->f, ", ");
1300 ir_print_other_instruction(irp, instruction->target);1648 ir_print_other_inst_src(irp, instruction->target);
1301 fprintf(irp->f, ")");1649 fprintf(irp->f, ")");
1302}1650}
13031651
1304static void ir_print_from_bytes(IrPrint *irp, IrInstructionFromBytes *instruction) {1652static void ir_print_from_bytes(IrPrintSrc *irp, IrInstSrcFromBytes *instruction) {
1305 fprintf(irp->f, "@bytesToSlice(");1653 fprintf(irp->f, "@bytesToSlice(");
1306 ir_print_other_instruction(irp, instruction->dest_child_type);1654 ir_print_other_inst_src(irp, instruction->dest_child_type);
1307 fprintf(irp->f, ", ");1655 fprintf(irp->f, ", ");
1308 ir_print_other_instruction(irp, instruction->target);1656 ir_print_other_inst_src(irp, instruction->target);
1309 fprintf(irp->f, ")");1657 fprintf(irp->f, ")");
1310}1658}
13111659
1312static void ir_print_to_bytes(IrPrint *irp, IrInstructionToBytes *instruction) {1660static void ir_print_to_bytes(IrPrintSrc *irp, IrInstSrcToBytes *instruction) {
1313 fprintf(irp->f, "@sliceToBytes(");1661 fprintf(irp->f, "@sliceToBytes(");
1314 ir_print_other_instruction(irp, instruction->target);1662 ir_print_other_inst_src(irp, instruction->target);
1315 fprintf(irp->f, ")");1663 fprintf(irp->f, ")");
1316}1664}
13171665
1318static void ir_print_int_to_float(IrPrint *irp, IrInstructionIntToFloat *instruction) {1666static void ir_print_int_to_float(IrPrintSrc *irp, IrInstSrcIntToFloat *instruction) {
1319 fprintf(irp->f, "@intToFloat(");1667 fprintf(irp->f, "@intToFloat(");
1320 ir_print_other_instruction(irp, instruction->dest_type);1668 ir_print_other_inst_src(irp, instruction->dest_type);
1321 fprintf(irp->f, ", ");1669 fprintf(irp->f, ", ");
1322 ir_print_other_instruction(irp, instruction->target);1670 ir_print_other_inst_src(irp, instruction->target);
1323 fprintf(irp->f, ")");1671 fprintf(irp->f, ")");
1324}1672}
13251673
1326static void ir_print_float_to_int(IrPrint *irp, IrInstructionFloatToInt *instruction) {1674static void ir_print_float_to_int(IrPrintSrc *irp, IrInstSrcFloatToInt *instruction) {
1327 fprintf(irp->f, "@floatToInt(");1675 fprintf(irp->f, "@floatToInt(");
1328 ir_print_other_instruction(irp, instruction->dest_type);1676 ir_print_other_inst_src(irp, instruction->dest_type);
1329 fprintf(irp->f, ", ");1677 fprintf(irp->f, ", ");
1330 ir_print_other_instruction(irp, instruction->target);1678 ir_print_other_inst_src(irp, instruction->target);
1331 fprintf(irp->f, ")");1679 fprintf(irp->f, ")");
1332}1680}
13331681
1334static void ir_print_bool_to_int(IrPrint *irp, IrInstructionBoolToInt *instruction) {1682static void ir_print_bool_to_int(IrPrintSrc *irp, IrInstSrcBoolToInt *instruction) {
1335 fprintf(irp->f, "@boolToInt(");1683 fprintf(irp->f, "@boolToInt(");
1336 ir_print_other_instruction(irp, instruction->target);1684 ir_print_other_inst_src(irp, instruction->target);
1337 fprintf(irp->f, ")");1685 fprintf(irp->f, ")");
1338}1686}
13391687
1340static void ir_print_int_type(IrPrint *irp, IrInstructionIntType *instruction) {1688static void ir_print_int_type(IrPrintSrc *irp, IrInstSrcIntType *instruction) {
1341 fprintf(irp->f, "@IntType(");1689 fprintf(irp->f, "@IntType(");
1342 ir_print_other_instruction(irp, instruction->is_signed);1690 ir_print_other_inst_src(irp, instruction->is_signed);
1343 fprintf(irp->f, ", ");1691 fprintf(irp->f, ", ");
1344 ir_print_other_instruction(irp, instruction->bit_count);1692 ir_print_other_inst_src(irp, instruction->bit_count);
1345 fprintf(irp->f, ")");1693 fprintf(irp->f, ")");
1346}1694}
13471695
1348static void ir_print_vector_type(IrPrint *irp, IrInstructionVectorType *instruction) {1696static void ir_print_vector_type(IrPrintSrc *irp, IrInstSrcVectorType *instruction) {
1349 fprintf(irp->f, "@Vector(");1697 fprintf(irp->f, "@Vector(");
1350 ir_print_other_instruction(irp, instruction->len);1698 ir_print_other_inst_src(irp, instruction->len);
1351 fprintf(irp->f, ", ");1699 fprintf(irp->f, ", ");
1352 ir_print_other_instruction(irp, instruction->elem_type);1700 ir_print_other_inst_src(irp, instruction->elem_type);
1353 fprintf(irp->f, ")");1701 fprintf(irp->f, ")");
1354}1702}
13551703
1356static void ir_print_shuffle_vector(IrPrint *irp, IrInstructionShuffleVector *instruction) {1704static void ir_print_shuffle_vector(IrPrintSrc *irp, IrInstSrcShuffleVector *instruction) {
1357 fprintf(irp->f, "@shuffle(");1705 fprintf(irp->f, "@shuffle(");
1358 ir_print_other_instruction(irp, instruction->scalar_type);1706 ir_print_other_inst_src(irp, instruction->scalar_type);
1359 fprintf(irp->f, ", ");1707 fprintf(irp->f, ", ");
1360 ir_print_other_instruction(irp, instruction->a);1708 ir_print_other_inst_src(irp, instruction->a);
1361 fprintf(irp->f, ", ");1709 fprintf(irp->f, ", ");
1362 ir_print_other_instruction(irp, instruction->b);1710 ir_print_other_inst_src(irp, instruction->b);
1363 fprintf(irp->f, ", ");1711 fprintf(irp->f, ", ");
1364 ir_print_other_instruction(irp, instruction->mask);1712 ir_print_other_inst_src(irp, instruction->mask);
1365 fprintf(irp->f, ")");1713 fprintf(irp->f, ")");
1366}1714}
13671715
1368static void ir_print_splat_src(IrPrint *irp, IrInstructionSplatSrc *instruction) {1716static void ir_print_shuffle_vector(IrPrintGen *irp, IrInstGenShuffleVector *instruction) {
1717 fprintf(irp->f, "@shuffle(");
1718 ir_print_other_inst_gen(irp, instruction->a);
1719 fprintf(irp->f, ", ");
1720 ir_print_other_inst_gen(irp, instruction->b);
1721 fprintf(irp->f, ", ");
1722 ir_print_other_inst_gen(irp, instruction->mask);
1723 fprintf(irp->f, ")");
1724}
1725
1726static void ir_print_splat_src(IrPrintSrc *irp, IrInstSrcSplat *instruction) {
1369 fprintf(irp->f, "@splat(");1727 fprintf(irp->f, "@splat(");
1370 ir_print_other_instruction(irp, instruction->len);1728 ir_print_other_inst_src(irp, instruction->len);
1371 fprintf(irp->f, ", ");1729 fprintf(irp->f, ", ");
1372 ir_print_other_instruction(irp, instruction->scalar);1730 ir_print_other_inst_src(irp, instruction->scalar);
1373 fprintf(irp->f, ")");1731 fprintf(irp->f, ")");
1374}1732}
13751733
1376static void ir_print_splat_gen(IrPrint *irp, IrInstructionSplatGen *instruction) {1734static void ir_print_splat_gen(IrPrintGen *irp, IrInstGenSplat *instruction) {
1377 fprintf(irp->f, "@splat(");1735 fprintf(irp->f, "@splat(");
1378 ir_print_other_instruction(irp, instruction->scalar);1736 ir_print_other_inst_gen(irp, instruction->scalar);
1379 fprintf(irp->f, ")");1737 fprintf(irp->f, ")");
1380}1738}
13811739
1382static void ir_print_bool_not(IrPrint *irp, IrInstructionBoolNot *instruction) {1740static void ir_print_bool_not(IrPrintSrc *irp, IrInstSrcBoolNot *instruction) {
1741 fprintf(irp->f, "! ");
1742 ir_print_other_inst_src(irp, instruction->value);
1743}
1744
1745static void ir_print_bool_not(IrPrintGen *irp, IrInstGenBoolNot *instruction) {
1383 fprintf(irp->f, "! ");1746 fprintf(irp->f, "! ");
1384 ir_print_other_instruction(irp, instruction->value);1747 ir_print_other_inst_gen(irp, instruction->value);
1385}1748}
13861749
1387static void ir_print_memset(IrPrint *irp, IrInstructionMemset *instruction) {1750static void ir_print_memset(IrPrintSrc *irp, IrInstSrcMemset *instruction) {
1388 fprintf(irp->f, "@memset(");1751 fprintf(irp->f, "@memset(");
1389 ir_print_other_instruction(irp, instruction->dest_ptr);1752 ir_print_other_inst_src(irp, instruction->dest_ptr);
1753 fprintf(irp->f, ", ");
1754 ir_print_other_inst_src(irp, instruction->byte);
1755 fprintf(irp->f, ", ");
1756 ir_print_other_inst_src(irp, instruction->count);
1757 fprintf(irp->f, ")");
1758}
1759
1760static void ir_print_memset(IrPrintGen *irp, IrInstGenMemset *instruction) {
1761 fprintf(irp->f, "@memset(");
1762 ir_print_other_inst_gen(irp, instruction->dest_ptr);
1763 fprintf(irp->f, ", ");
1764 ir_print_other_inst_gen(irp, instruction->byte);
1765 fprintf(irp->f, ", ");
1766 ir_print_other_inst_gen(irp, instruction->count);
1767 fprintf(irp->f, ")");
1768}
1769
1770static void ir_print_memcpy(IrPrintSrc *irp, IrInstSrcMemcpy *instruction) {
1771 fprintf(irp->f, "@memcpy(");
1772 ir_print_other_inst_src(irp, instruction->dest_ptr);
1390 fprintf(irp->f, ", ");1773 fprintf(irp->f, ", ");
1391 ir_print_other_instruction(irp, instruction->byte);1774 ir_print_other_inst_src(irp, instruction->src_ptr);
1392 fprintf(irp->f, ", ");1775 fprintf(irp->f, ", ");
1393 ir_print_other_instruction(irp, instruction->count);1776 ir_print_other_inst_src(irp, instruction->count);
1394 fprintf(irp->f, ")");1777 fprintf(irp->f, ")");
1395}1778}
13961779
1397static void ir_print_memcpy(IrPrint *irp, IrInstructionMemcpy *instruction) {1780static void ir_print_memcpy(IrPrintGen *irp, IrInstGenMemcpy *instruction) {
1398 fprintf(irp->f, "@memcpy(");1781 fprintf(irp->f, "@memcpy(");
1399 ir_print_other_instruction(irp, instruction->dest_ptr);1782 ir_print_other_inst_gen(irp, instruction->dest_ptr);
1400 fprintf(irp->f, ", ");1783 fprintf(irp->f, ", ");
1401 ir_print_other_instruction(irp, instruction->src_ptr);1784 ir_print_other_inst_gen(irp, instruction->src_ptr);
1402 fprintf(irp->f, ", ");1785 fprintf(irp->f, ", ");
1403 ir_print_other_instruction(irp, instruction->count);1786 ir_print_other_inst_gen(irp, instruction->count);
1404 fprintf(irp->f, ")");1787 fprintf(irp->f, ")");
1405}1788}
14061789
1407static void ir_print_slice_src(IrPrint *irp, IrInstructionSliceSrc *instruction) {1790static void ir_print_slice_src(IrPrintSrc *irp, IrInstSrcSlice *instruction) {
1408 ir_print_other_instruction(irp, instruction->ptr);1791 ir_print_other_inst_src(irp, instruction->ptr);
1409 fprintf(irp->f, "[");1792 fprintf(irp->f, "[");
1410 ir_print_other_instruction(irp, instruction->start);1793 ir_print_other_inst_src(irp, instruction->start);
1411 fprintf(irp->f, "..");1794 fprintf(irp->f, "..");
1412 if (instruction->end)1795 if (instruction->end)
1413 ir_print_other_instruction(irp, instruction->end);1796 ir_print_other_inst_src(irp, instruction->end);
1414 fprintf(irp->f, "]result=");1797 fprintf(irp->f, "]result=");
1415 ir_print_result_loc(irp, instruction->result_loc);1798 ir_print_result_loc(irp, instruction->result_loc);
1416}1799}
14171800
1418static void ir_print_slice_gen(IrPrint *irp, IrInstructionSliceGen *instruction) {1801static void ir_print_slice_gen(IrPrintGen *irp, IrInstGenSlice *instruction) {
1419 ir_print_other_instruction(irp, instruction->ptr);1802 ir_print_other_inst_gen(irp, instruction->ptr);
1420 fprintf(irp->f, "[");1803 fprintf(irp->f, "[");
1421 ir_print_other_instruction(irp, instruction->start);1804 ir_print_other_inst_gen(irp, instruction->start);
1422 fprintf(irp->f, "..");1805 fprintf(irp->f, "..");
1423 if (instruction->end)1806 if (instruction->end)
1424 ir_print_other_instruction(irp, instruction->end);1807 ir_print_other_inst_gen(irp, instruction->end);
1425 fprintf(irp->f, "]result=");1808 fprintf(irp->f, "]result=");
1426 ir_print_other_instruction(irp, instruction->result_loc);1809 ir_print_other_inst_gen(irp, instruction->result_loc);
1427}1810}
14281811
1429static void ir_print_member_count(IrPrint *irp, IrInstructionMemberCount *instruction) {1812static void ir_print_member_count(IrPrintSrc *irp, IrInstSrcMemberCount *instruction) {
1430 fprintf(irp->f, "@memberCount(");1813 fprintf(irp->f, "@memberCount(");
1431 ir_print_other_instruction(irp, instruction->container);1814 ir_print_other_inst_src(irp, instruction->container);
1432 fprintf(irp->f, ")");1815 fprintf(irp->f, ")");
1433}1816}
14341817
1435static void ir_print_member_type(IrPrint *irp, IrInstructionMemberType *instruction) {1818static void ir_print_member_type(IrPrintSrc *irp, IrInstSrcMemberType *instruction) {
1436 fprintf(irp->f, "@memberType(");1819 fprintf(irp->f, "@memberType(");
1437 ir_print_other_instruction(irp, instruction->container_type);1820 ir_print_other_inst_src(irp, instruction->container_type);
1438 fprintf(irp->f, ", ");1821 fprintf(irp->f, ", ");
1439 ir_print_other_instruction(irp, instruction->member_index);1822 ir_print_other_inst_src(irp, instruction->member_index);
1440 fprintf(irp->f, ")");1823 fprintf(irp->f, ")");
1441}1824}
14421825
1443static void ir_print_member_name(IrPrint *irp, IrInstructionMemberName *instruction) {1826static void ir_print_member_name(IrPrintSrc *irp, IrInstSrcMemberName *instruction) {
1444 fprintf(irp->f, "@memberName(");1827 fprintf(irp->f, "@memberName(");
1445 ir_print_other_instruction(irp, instruction->container_type);1828 ir_print_other_inst_src(irp, instruction->container_type);
1446 fprintf(irp->f, ", ");1829 fprintf(irp->f, ", ");
1447 ir_print_other_instruction(irp, instruction->member_index);1830 ir_print_other_inst_src(irp, instruction->member_index);
1448 fprintf(irp->f, ")");1831 fprintf(irp->f, ")");
1449}1832}
14501833
1451static void ir_print_breakpoint(IrPrint *irp, IrInstructionBreakpoint *instruction) {1834static void ir_print_breakpoint(IrPrintSrc *irp, IrInstSrcBreakpoint *instruction) {
1835 fprintf(irp->f, "@breakpoint()");
1836}
1837
1838static void ir_print_breakpoint(IrPrintGen *irp, IrInstGenBreakpoint *instruction) {
1452 fprintf(irp->f, "@breakpoint()");1839 fprintf(irp->f, "@breakpoint()");
1453}1840}
14541841
1455static void ir_print_frame_address(IrPrint *irp, IrInstructionFrameAddress *instruction) {1842static void ir_print_frame_address(IrPrintSrc *irp, IrInstSrcFrameAddress *instruction) {
1843 fprintf(irp->f, "@frameAddress()");
1844}
1845
1846static void ir_print_frame_address(IrPrintGen *irp, IrInstGenFrameAddress *instruction) {
1456 fprintf(irp->f, "@frameAddress()");1847 fprintf(irp->f, "@frameAddress()");
1457}1848}
14581849
1459static void ir_print_handle(IrPrint *irp, IrInstructionFrameHandle *instruction) {1850static void ir_print_handle(IrPrintSrc *irp, IrInstSrcFrameHandle *instruction) {
1460 fprintf(irp->f, "@frame()");1851 fprintf(irp->f, "@frame()");
1461}1852}
14621853
1463static void ir_print_frame_type(IrPrint *irp, IrInstructionFrameType *instruction) {1854static void ir_print_handle(IrPrintGen *irp, IrInstGenFrameHandle *instruction) {
1855 fprintf(irp->f, "@frame()");
1856}
1857
1858static void ir_print_frame_type(IrPrintSrc *irp, IrInstSrcFrameType *instruction) {
1464 fprintf(irp->f, "@Frame(");1859 fprintf(irp->f, "@Frame(");
1465 ir_print_other_instruction(irp, instruction->fn);1860 ir_print_other_inst_src(irp, instruction->fn);
1466 fprintf(irp->f, ")");1861 fprintf(irp->f, ")");
1467}1862}
14681863
1469static void ir_print_frame_size_src(IrPrint *irp, IrInstructionFrameSizeSrc *instruction) {1864static void ir_print_frame_size_src(IrPrintSrc *irp, IrInstSrcFrameSize *instruction) {
1470 fprintf(irp->f, "@frameSize(");1865 fprintf(irp->f, "@frameSize(");
1471 ir_print_other_instruction(irp, instruction->fn);1866 ir_print_other_inst_src(irp, instruction->fn);
1472 fprintf(irp->f, ")");1867 fprintf(irp->f, ")");
1473}1868}
14741869
1475static void ir_print_frame_size_gen(IrPrint *irp, IrInstructionFrameSizeGen *instruction) {1870static void ir_print_frame_size_gen(IrPrintGen *irp, IrInstGenFrameSize *instruction) {
1476 fprintf(irp->f, "@frameSize(");1871 fprintf(irp->f, "@frameSize(");
1477 ir_print_other_instruction(irp, instruction->fn);1872 ir_print_other_inst_gen(irp, instruction->fn);
1478 fprintf(irp->f, ")");1873 fprintf(irp->f, ")");
1479}1874}
14801875
1481static void ir_print_return_address(IrPrint *irp, IrInstructionReturnAddress *instruction) {1876static void ir_print_return_address(IrPrintSrc *irp, IrInstSrcReturnAddress *instruction) {
1877 fprintf(irp->f, "@returnAddress()");
1878}
1879
1880static void ir_print_return_address(IrPrintGen *irp, IrInstGenReturnAddress *instruction) {
1482 fprintf(irp->f, "@returnAddress()");1881 fprintf(irp->f, "@returnAddress()");
1483}1882}
14841883
1485static void ir_print_align_of(IrPrint *irp, IrInstructionAlignOf *instruction) {1884static void ir_print_align_of(IrPrintSrc *irp, IrInstSrcAlignOf *instruction) {
1486 fprintf(irp->f, "@alignOf(");1885 fprintf(irp->f, "@alignOf(");
1487 ir_print_other_instruction(irp, instruction->type_value);1886 ir_print_other_inst_src(irp, instruction->type_value);
1488 fprintf(irp->f, ")");1887 fprintf(irp->f, ")");
1489}1888}
14901889
1491static void ir_print_overflow_op(IrPrint *irp, IrInstructionOverflowOp *instruction) {1890static void ir_print_overflow_op(IrPrintSrc *irp, IrInstSrcOverflowOp *instruction) {
1492 switch (instruction->op) {1891 switch (instruction->op) {
1493 case IrOverflowOpAdd:1892 case IrOverflowOpAdd:
1494 fprintf(irp->f, "@addWithOverflow(");1893 fprintf(irp->f, "@addWithOverflow(");
...@@ -1503,1146 +1902,1457 @@ static void ir_print_overflow_op(IrPrint *irp, IrInstructionOverflowOp *instruct...@@ -1503,1146 +1902,1457 @@ static void ir_print_overflow_op(IrPrint *irp, IrInstructionOverflowOp *instruct
1503 fprintf(irp->f, "@shlWithOverflow(");1902 fprintf(irp->f, "@shlWithOverflow(");
1504 break;1903 break;
1505 }1904 }
1506 ir_print_other_instruction(irp, instruction->type_value);1905 ir_print_other_inst_src(irp, instruction->type_value);
1507 fprintf(irp->f, ", ");1906 fprintf(irp->f, ", ");
1508 ir_print_other_instruction(irp, instruction->op1);1907 ir_print_other_inst_src(irp, instruction->op1);
1908 fprintf(irp->f, ", ");
1909 ir_print_other_inst_src(irp, instruction->op2);
1910 fprintf(irp->f, ", ");
1911 ir_print_other_inst_src(irp, instruction->result_ptr);
1912 fprintf(irp->f, ")");
1913}
1914
1915static void ir_print_overflow_op(IrPrintGen *irp, IrInstGenOverflowOp *instruction) {
1916 switch (instruction->op) {
1917 case IrOverflowOpAdd:
1918 fprintf(irp->f, "@addWithOverflow(");
1919 break;
1920 case IrOverflowOpSub:
1921 fprintf(irp->f, "@subWithOverflow(");
1922 break;
1923 case IrOverflowOpMul:
1924 fprintf(irp->f, "@mulWithOverflow(");
1925 break;
1926 case IrOverflowOpShl:
1927 fprintf(irp->f, "@shlWithOverflow(");
1928 break;
1929 }
1930 ir_print_other_inst_gen(irp, instruction->op1);
1509 fprintf(irp->f, ", ");1931 fprintf(irp->f, ", ");
1510 ir_print_other_instruction(irp, instruction->op2);1932 ir_print_other_inst_gen(irp, instruction->op2);
1511 fprintf(irp->f, ", ");1933 fprintf(irp->f, ", ");
1512 ir_print_other_instruction(irp, instruction->result_ptr);1934 ir_print_other_inst_gen(irp, instruction->result_ptr);
1513 fprintf(irp->f, ")");1935 fprintf(irp->f, ")");
1514}1936}
15151937
1516static void ir_print_test_err_src(IrPrint *irp, IrInstructionTestErrSrc *instruction) {1938static void ir_print_test_err_src(IrPrintSrc *irp, IrInstSrcTestErr *instruction) {
1517 fprintf(irp->f, "@testError(");1939 fprintf(irp->f, "@testError(");
1518 ir_print_other_instruction(irp, instruction->base_ptr);1940 ir_print_other_inst_src(irp, instruction->base_ptr);
1519 fprintf(irp->f, ")");1941 fprintf(irp->f, ")");
1520}1942}
15211943
1522static void ir_print_test_err_gen(IrPrint *irp, IrInstructionTestErrGen *instruction) {1944static void ir_print_test_err_gen(IrPrintGen *irp, IrInstGenTestErr *instruction) {
1523 fprintf(irp->f, "@testError(");1945 fprintf(irp->f, "@testError(");
1524 ir_print_other_instruction(irp, instruction->err_union);1946 ir_print_other_inst_gen(irp, instruction->err_union);
1947 fprintf(irp->f, ")");
1948}
1949
1950static void ir_print_unwrap_err_code(IrPrintSrc *irp, IrInstSrcUnwrapErrCode *instruction) {
1951 fprintf(irp->f, "UnwrapErrorCode(");
1952 ir_print_other_inst_src(irp, instruction->err_union_ptr);
1525 fprintf(irp->f, ")");1953 fprintf(irp->f, ")");
1526}1954}
15271955
1528static void ir_print_unwrap_err_code(IrPrint *irp, IrInstructionUnwrapErrCode *instruction) {1956static void ir_print_unwrap_err_code(IrPrintGen *irp, IrInstGenUnwrapErrCode *instruction) {
1529 fprintf(irp->f, "UnwrapErrorCode(");1957 fprintf(irp->f, "UnwrapErrorCode(");
1530 ir_print_other_instruction(irp, instruction->err_union_ptr);1958 ir_print_other_inst_gen(irp, instruction->err_union_ptr);
1531 fprintf(irp->f, ")");1959 fprintf(irp->f, ")");
1532}1960}
15331961
1534static void ir_print_unwrap_err_payload(IrPrint *irp, IrInstructionUnwrapErrPayload *instruction) {1962static void ir_print_unwrap_err_payload(IrPrintSrc *irp, IrInstSrcUnwrapErrPayload *instruction) {
1963 fprintf(irp->f, "ErrorUnionFieldPayload(");
1964 ir_print_other_inst_src(irp, instruction->value);
1965 fprintf(irp->f, ")safety=%d,init=%d",instruction->safety_check_on, instruction->initializing);
1966}
1967
1968static void ir_print_unwrap_err_payload(IrPrintGen *irp, IrInstGenUnwrapErrPayload *instruction) {
1535 fprintf(irp->f, "ErrorUnionFieldPayload(");1969 fprintf(irp->f, "ErrorUnionFieldPayload(");
1536 ir_print_other_instruction(irp, instruction->value);1970 ir_print_other_inst_gen(irp, instruction->value);
1537 fprintf(irp->f, ")safety=%d,init=%d",instruction->safety_check_on, instruction->initializing);1971 fprintf(irp->f, ")safety=%d,init=%d",instruction->safety_check_on, instruction->initializing);
1538}1972}
15391973
1540static void ir_print_optional_wrap(IrPrint *irp, IrInstructionOptionalWrap *instruction) {1974static void ir_print_optional_wrap(IrPrintGen *irp, IrInstGenOptionalWrap *instruction) {
1541 fprintf(irp->f, "@optionalWrap(");1975 fprintf(irp->f, "@optionalWrap(");
1542 ir_print_other_instruction(irp, instruction->operand);1976 ir_print_other_inst_gen(irp, instruction->operand);
1543 fprintf(irp->f, ")result=");1977 fprintf(irp->f, ")result=");
1544 ir_print_other_instruction(irp, instruction->result_loc);1978 ir_print_other_inst_gen(irp, instruction->result_loc);
1545}1979}
15461980
1547static void ir_print_err_wrap_code(IrPrint *irp, IrInstructionErrWrapCode *instruction) {1981static void ir_print_err_wrap_code(IrPrintGen *irp, IrInstGenErrWrapCode *instruction) {
1548 fprintf(irp->f, "@errWrapCode(");1982 fprintf(irp->f, "@errWrapCode(");
1549 ir_print_other_instruction(irp, instruction->operand);1983 ir_print_other_inst_gen(irp, instruction->operand);
1550 fprintf(irp->f, ")result=");1984 fprintf(irp->f, ")result=");
1551 ir_print_other_instruction(irp, instruction->result_loc);1985 ir_print_other_inst_gen(irp, instruction->result_loc);
1552}1986}
15531987
1554static void ir_print_err_wrap_payload(IrPrint *irp, IrInstructionErrWrapPayload *instruction) {1988static void ir_print_err_wrap_payload(IrPrintGen *irp, IrInstGenErrWrapPayload *instruction) {
1555 fprintf(irp->f, "@errWrapPayload(");1989 fprintf(irp->f, "@errWrapPayload(");
1556 ir_print_other_instruction(irp, instruction->operand);1990 ir_print_other_inst_gen(irp, instruction->operand);
1557 fprintf(irp->f, ")result=");1991 fprintf(irp->f, ")result=");
1558 ir_print_other_instruction(irp, instruction->result_loc);1992 ir_print_other_inst_gen(irp, instruction->result_loc);
1559}1993}
15601994
1561static void ir_print_fn_proto(IrPrint *irp, IrInstructionFnProto *instruction) {1995static void ir_print_fn_proto(IrPrintSrc *irp, IrInstSrcFnProto *instruction) {
1562 fprintf(irp->f, "fn(");1996 fprintf(irp->f, "fn(");
1563 for (size_t i = 0; i < instruction->base.source_node->data.fn_proto.params.length; i += 1) {1997 for (size_t i = 0; i < instruction->base.base.source_node->data.fn_proto.params.length; i += 1) {
1564 if (i != 0)1998 if (i != 0)
1565 fprintf(irp->f, ",");1999 fprintf(irp->f, ",");
1566 if (instruction->is_var_args && i == instruction->base.source_node->data.fn_proto.params.length - 1) {2000 if (instruction->is_var_args && i == instruction->base.base.source_node->data.fn_proto.params.length - 1) {
1567 fprintf(irp->f, "...");2001 fprintf(irp->f, "...");
1568 } else {2002 } else {
1569 ir_print_other_instruction(irp, instruction->param_types[i]);2003 ir_print_other_inst_src(irp, instruction->param_types[i]);
1570 }2004 }
1571 }2005 }
1572 fprintf(irp->f, ")");2006 fprintf(irp->f, ")");
1573 if (instruction->align_value != nullptr) {2007 if (instruction->align_value != nullptr) {
1574 fprintf(irp->f, " align ");2008 fprintf(irp->f, " align ");
1575 ir_print_other_instruction(irp, instruction->align_value);2009 ir_print_other_inst_src(irp, instruction->align_value);
1576 fprintf(irp->f, " ");2010 fprintf(irp->f, " ");
1577 }2011 }
1578 fprintf(irp->f, "->");2012 fprintf(irp->f, "->");
1579 ir_print_other_instruction(irp, instruction->return_type);2013 ir_print_other_inst_src(irp, instruction->return_type);
1580}2014}
15812015
1582static void ir_print_test_comptime(IrPrint *irp, IrInstructionTestComptime *instruction) {2016static void ir_print_test_comptime(IrPrintSrc *irp, IrInstSrcTestComptime *instruction) {
1583 fprintf(irp->f, "@testComptime(");2017 fprintf(irp->f, "@testComptime(");
1584 ir_print_other_instruction(irp, instruction->value);2018 ir_print_other_inst_src(irp, instruction->value);
1585 fprintf(irp->f, ")");2019 fprintf(irp->f, ")");
1586}2020}
15872021
1588static void ir_print_ptr_cast_src(IrPrint *irp, IrInstructionPtrCastSrc *instruction) {2022static void ir_print_ptr_cast_src(IrPrintSrc *irp, IrInstSrcPtrCast *instruction) {
1589 fprintf(irp->f, "@ptrCast(");2023 fprintf(irp->f, "@ptrCast(");
1590 if (instruction->dest_type) {2024 if (instruction->dest_type) {
1591 ir_print_other_instruction(irp, instruction->dest_type);2025 ir_print_other_inst_src(irp, instruction->dest_type);
1592 }2026 }
1593 fprintf(irp->f, ",");2027 fprintf(irp->f, ",");
1594 ir_print_other_instruction(irp, instruction->ptr);2028 ir_print_other_inst_src(irp, instruction->ptr);
1595 fprintf(irp->f, ")");2029 fprintf(irp->f, ")");
1596}2030}
15972031
1598static void ir_print_ptr_cast_gen(IrPrint *irp, IrInstructionPtrCastGen *instruction) {2032static void ir_print_ptr_cast_gen(IrPrintGen *irp, IrInstGenPtrCast *instruction) {
1599 fprintf(irp->f, "@ptrCast(");2033 fprintf(irp->f, "@ptrCast(");
1600 ir_print_other_instruction(irp, instruction->ptr);2034 ir_print_other_inst_gen(irp, instruction->ptr);
1601 fprintf(irp->f, ")");2035 fprintf(irp->f, ")");
1602}2036}
16032037
1604static void ir_print_implicit_cast(IrPrint *irp, IrInstructionImplicitCast *instruction) {2038static void ir_print_implicit_cast(IrPrintSrc *irp, IrInstSrcImplicitCast *instruction) {
1605 fprintf(irp->f, "@implicitCast(");2039 fprintf(irp->f, "@implicitCast(");
1606 ir_print_other_instruction(irp, instruction->operand);2040 ir_print_other_inst_src(irp, instruction->operand);
1607 fprintf(irp->f, ")result=");2041 fprintf(irp->f, ")result=");
1608 ir_print_result_loc(irp, &instruction->result_loc_cast->base);2042 ir_print_result_loc(irp, &instruction->result_loc_cast->base);
1609}2043}
16102044
1611static void ir_print_bit_cast_src(IrPrint *irp, IrInstructionBitCastSrc *instruction) {2045static void ir_print_bit_cast_src(IrPrintSrc *irp, IrInstSrcBitCast *instruction) {
1612 fprintf(irp->f, "@bitCast(");2046 fprintf(irp->f, "@bitCast(");
1613 ir_print_other_instruction(irp, instruction->operand);2047 ir_print_other_inst_src(irp, instruction->operand);
1614 fprintf(irp->f, ")result=");2048 fprintf(irp->f, ")result=");
1615 ir_print_result_loc(irp, &instruction->result_loc_bit_cast->base);2049 ir_print_result_loc(irp, &instruction->result_loc_bit_cast->base);
1616}2050}
16172051
1618static void ir_print_bit_cast_gen(IrPrint *irp, IrInstructionBitCastGen *instruction) {2052static void ir_print_bit_cast_gen(IrPrintGen *irp, IrInstGenBitCast *instruction) {
1619 fprintf(irp->f, "@bitCast(");2053 fprintf(irp->f, "@bitCast(");
1620 ir_print_other_instruction(irp, instruction->operand);2054 ir_print_other_inst_gen(irp, instruction->operand);
1621 fprintf(irp->f, ")");2055 fprintf(irp->f, ")");
1622}2056}
16232057
1624static void ir_print_widen_or_shorten(IrPrint *irp, IrInstructionWidenOrShorten *instruction) {2058static void ir_print_widen_or_shorten(IrPrintGen *irp, IrInstGenWidenOrShorten *instruction) {
1625 fprintf(irp->f, "WidenOrShorten(");2059 fprintf(irp->f, "WidenOrShorten(");
1626 ir_print_other_instruction(irp, instruction->target);2060 ir_print_other_inst_gen(irp, instruction->target);
1627 fprintf(irp->f, ")");2061 fprintf(irp->f, ")");
1628}2062}
16292063
1630static void ir_print_ptr_to_int(IrPrint *irp, IrInstructionPtrToInt *instruction) {2064static void ir_print_ptr_to_int(IrPrintSrc *irp, IrInstSrcPtrToInt *instruction) {
1631 fprintf(irp->f, "@ptrToInt(");2065 fprintf(irp->f, "@ptrToInt(");
1632 ir_print_other_instruction(irp, instruction->target);2066 ir_print_other_inst_src(irp, instruction->target);
1633 fprintf(irp->f, ")");2067 fprintf(irp->f, ")");
1634}2068}
16352069
1636static void ir_print_int_to_ptr(IrPrint *irp, IrInstructionIntToPtr *instruction) {2070static void ir_print_ptr_to_int(IrPrintGen *irp, IrInstGenPtrToInt *instruction) {
2071 fprintf(irp->f, "@ptrToInt(");
2072 ir_print_other_inst_gen(irp, instruction->target);
2073 fprintf(irp->f, ")");
2074}
2075
2076static void ir_print_int_to_ptr(IrPrintSrc *irp, IrInstSrcIntToPtr *instruction) {
1637 fprintf(irp->f, "@intToPtr(");2077 fprintf(irp->f, "@intToPtr(");
1638 if (instruction->dest_type == nullptr) {2078 ir_print_other_inst_src(irp, instruction->dest_type);
1639 fprintf(irp->f, "(null)");
1640 } else {
1641 ir_print_other_instruction(irp, instruction->dest_type);
1642 }
1643 fprintf(irp->f, ",");2079 fprintf(irp->f, ",");
1644 ir_print_other_instruction(irp, instruction->target);2080 ir_print_other_inst_src(irp, instruction->target);
1645 fprintf(irp->f, ")");2081 fprintf(irp->f, ")");
1646}2082}
16472083
1648static void ir_print_int_to_enum(IrPrint *irp, IrInstructionIntToEnum *instruction) {2084static void ir_print_int_to_ptr(IrPrintGen *irp, IrInstGenIntToPtr *instruction) {
2085 fprintf(irp->f, "@intToPtr(");
2086 ir_print_other_inst_gen(irp, instruction->target);
2087 fprintf(irp->f, ")");
2088}
2089
2090static void ir_print_int_to_enum(IrPrintSrc *irp, IrInstSrcIntToEnum *instruction) {
1649 fprintf(irp->f, "@intToEnum(");2091 fprintf(irp->f, "@intToEnum(");
1650 if (instruction->dest_type == nullptr) {2092 ir_print_other_inst_src(irp, instruction->dest_type);
1651 fprintf(irp->f, "(null)");2093 fprintf(irp->f, ",");
1652 } else {2094 ir_print_other_inst_src(irp, instruction->target);
1653 ir_print_other_instruction(irp, instruction->dest_type);
1654 }
1655 ir_print_other_instruction(irp, instruction->target);
1656 fprintf(irp->f, ")");2095 fprintf(irp->f, ")");
1657}2096}
16582097
1659static void ir_print_enum_to_int(IrPrint *irp, IrInstructionEnumToInt *instruction) {2098static void ir_print_int_to_enum(IrPrintGen *irp, IrInstGenIntToEnum *instruction) {
2099 fprintf(irp->f, "@intToEnum(");
2100 ir_print_other_inst_gen(irp, instruction->target);
2101 fprintf(irp->f, ")");
2102}
2103
2104static void ir_print_enum_to_int(IrPrintSrc *irp, IrInstSrcEnumToInt *instruction) {
1660 fprintf(irp->f, "@enumToInt(");2105 fprintf(irp->f, "@enumToInt(");
1661 ir_print_other_instruction(irp, instruction->target);2106 ir_print_other_inst_src(irp, instruction->target);
1662 fprintf(irp->f, ")");2107 fprintf(irp->f, ")");
1663}2108}
16642109
1665static void ir_print_check_runtime_scope(IrPrint *irp, IrInstructionCheckRuntimeScope *instruction) {2110static void ir_print_check_runtime_scope(IrPrintSrc *irp, IrInstSrcCheckRuntimeScope *instruction) {
1666 fprintf(irp->f, "@checkRuntimeScope(");2111 fprintf(irp->f, "@checkRuntimeScope(");
1667 ir_print_other_instruction(irp, instruction->scope_is_comptime);2112 ir_print_other_inst_src(irp, instruction->scope_is_comptime);
1668 fprintf(irp->f, ",");2113 fprintf(irp->f, ",");
1669 ir_print_other_instruction(irp, instruction->is_comptime);2114 ir_print_other_inst_src(irp, instruction->is_comptime);
1670 fprintf(irp->f, ")");2115 fprintf(irp->f, ")");
1671}2116}
16722117
1673static void ir_print_array_to_vector(IrPrint *irp, IrInstructionArrayToVector *instruction) {2118static void ir_print_array_to_vector(IrPrintGen *irp, IrInstGenArrayToVector *instruction) {
1674 fprintf(irp->f, "ArrayToVector(");2119 fprintf(irp->f, "ArrayToVector(");
1675 ir_print_other_instruction(irp, instruction->array);2120 ir_print_other_inst_gen(irp, instruction->array);
1676 fprintf(irp->f, ")");2121 fprintf(irp->f, ")");
1677}2122}
16782123
1679static void ir_print_vector_to_array(IrPrint *irp, IrInstructionVectorToArray *instruction) {2124static void ir_print_vector_to_array(IrPrintGen *irp, IrInstGenVectorToArray *instruction) {
1680 fprintf(irp->f, "VectorToArray(");2125 fprintf(irp->f, "VectorToArray(");
1681 ir_print_other_instruction(irp, instruction->vector);2126 ir_print_other_inst_gen(irp, instruction->vector);
1682 fprintf(irp->f, ")result=");2127 fprintf(irp->f, ")result=");
1683 ir_print_other_instruction(irp, instruction->result_loc);2128 ir_print_other_inst_gen(irp, instruction->result_loc);
1684}2129}
16852130
1686static void ir_print_ptr_of_array_to_slice(IrPrint *irp, IrInstructionPtrOfArrayToSlice *instruction) {2131static void ir_print_ptr_of_array_to_slice(IrPrintGen *irp, IrInstGenPtrOfArrayToSlice *instruction) {
1687 fprintf(irp->f, "PtrOfArrayToSlice(");2132 fprintf(irp->f, "PtrOfArrayToSlice(");
1688 ir_print_other_instruction(irp, instruction->operand);2133 ir_print_other_inst_gen(irp, instruction->operand);
1689 fprintf(irp->f, ")result=");2134 fprintf(irp->f, ")result=");
1690 ir_print_other_instruction(irp, instruction->result_loc);2135 ir_print_other_inst_gen(irp, instruction->result_loc);
1691}2136}
16922137
1693static void ir_print_assert_zero(IrPrint *irp, IrInstructionAssertZero *instruction) {2138static void ir_print_assert_zero(IrPrintGen *irp, IrInstGenAssertZero *instruction) {
1694 fprintf(irp->f, "AssertZero(");2139 fprintf(irp->f, "AssertZero(");
1695 ir_print_other_instruction(irp, instruction->target);2140 ir_print_other_inst_gen(irp, instruction->target);
1696 fprintf(irp->f, ")");2141 fprintf(irp->f, ")");
1697}2142}
16982143
1699static void ir_print_assert_non_null(IrPrint *irp, IrInstructionAssertNonNull *instruction) {2144static void ir_print_assert_non_null(IrPrintGen *irp, IrInstGenAssertNonNull *instruction) {
1700 fprintf(irp->f, "AssertNonNull(");2145 fprintf(irp->f, "AssertNonNull(");
1701 ir_print_other_instruction(irp, instruction->target);2146 ir_print_other_inst_gen(irp, instruction->target);
1702 fprintf(irp->f, ")");2147 fprintf(irp->f, ")");
1703}2148}
17042149
1705static void ir_print_resize_slice(IrPrint *irp, IrInstructionResizeSlice *instruction) {2150static void ir_print_resize_slice(IrPrintGen *irp, IrInstGenResizeSlice *instruction) {
1706 fprintf(irp->f, "@resizeSlice(");2151 fprintf(irp->f, "@resizeSlice(");
1707 ir_print_other_instruction(irp, instruction->operand);2152 ir_print_other_inst_gen(irp, instruction->operand);
1708 fprintf(irp->f, ")result=");2153 fprintf(irp->f, ")result=");
1709 ir_print_other_instruction(irp, instruction->result_loc);2154 ir_print_other_inst_gen(irp, instruction->result_loc);
1710}2155}
17112156
1712static void ir_print_alloca_src(IrPrint *irp, IrInstructionAllocaSrc *instruction) {2157static void ir_print_alloca_src(IrPrintSrc *irp, IrInstSrcAlloca *instruction) {
1713 fprintf(irp->f, "Alloca(align=");2158 fprintf(irp->f, "Alloca(align=");
1714 ir_print_other_instruction(irp, instruction->align);2159 ir_print_other_inst_src(irp, instruction->align);
1715 fprintf(irp->f, ",name=%s)", instruction->name_hint);2160 fprintf(irp->f, ",name=%s)", instruction->name_hint);
1716}2161}
17172162
1718static void ir_print_alloca_gen(IrPrint *irp, IrInstructionAllocaGen *instruction) {2163static void ir_print_alloca_gen(IrPrintGen *irp, IrInstGenAlloca *instruction) {
1719 fprintf(irp->f, "Alloca(align=%" PRIu32 ",name=%s)", instruction->align, instruction->name_hint);2164 fprintf(irp->f, "Alloca(align=%" PRIu32 ",name=%s)", instruction->align, instruction->name_hint);
1720}2165}
17212166
1722static void ir_print_end_expr(IrPrint *irp, IrInstructionEndExpr *instruction) {2167static void ir_print_end_expr(IrPrintSrc *irp, IrInstSrcEndExpr *instruction) {
1723 fprintf(irp->f, "EndExpr(result=");2168 fprintf(irp->f, "EndExpr(result=");
1724 ir_print_result_loc(irp, instruction->result_loc);2169 ir_print_result_loc(irp, instruction->result_loc);
1725 fprintf(irp->f, ",value=");2170 fprintf(irp->f, ",value=");
1726 ir_print_other_instruction(irp, instruction->value);2171 ir_print_other_inst_src(irp, instruction->value);
1727 fprintf(irp->f, ")");2172 fprintf(irp->f, ")");
1728}2173}
17292174
1730static void ir_print_int_to_err(IrPrint *irp, IrInstructionIntToErr *instruction) {2175static void ir_print_int_to_err(IrPrintSrc *irp, IrInstSrcIntToErr *instruction) {
1731 fprintf(irp->f, "inttoerr ");2176 fprintf(irp->f, "inttoerr ");
1732 ir_print_other_instruction(irp, instruction->target);2177 ir_print_other_inst_src(irp, instruction->target);
1733}2178}
17342179
1735static void ir_print_err_to_int(IrPrint *irp, IrInstructionErrToInt *instruction) {2180static void ir_print_int_to_err(IrPrintGen *irp, IrInstGenIntToErr *instruction) {
2181 fprintf(irp->f, "inttoerr ");
2182 ir_print_other_inst_gen(irp, instruction->target);
2183}
2184
2185static void ir_print_err_to_int(IrPrintSrc *irp, IrInstSrcErrToInt *instruction) {
2186 fprintf(irp->f, "errtoint ");
2187 ir_print_other_inst_src(irp, instruction->target);
2188}
2189
2190static void ir_print_err_to_int(IrPrintGen *irp, IrInstGenErrToInt *instruction) {
1736 fprintf(irp->f, "errtoint ");2191 fprintf(irp->f, "errtoint ");
1737 ir_print_other_instruction(irp, instruction->target);2192 ir_print_other_inst_gen(irp, instruction->target);
1738}2193}
17392194
1740static void ir_print_check_switch_prongs(IrPrint *irp, IrInstructionCheckSwitchProngs *instruction) {2195static void ir_print_check_switch_prongs(IrPrintSrc *irp, IrInstSrcCheckSwitchProngs *instruction) {
1741 fprintf(irp->f, "@checkSwitchProngs(");2196 fprintf(irp->f, "@checkSwitchProngs(");
1742 ir_print_other_instruction(irp, instruction->target_value);2197 ir_print_other_inst_src(irp, instruction->target_value);
1743 fprintf(irp->f, ",");2198 fprintf(irp->f, ",");
1744 for (size_t i = 0; i < instruction->range_count; i += 1) {2199 for (size_t i = 0; i < instruction->range_count; i += 1) {
1745 if (i != 0)2200 if (i != 0)
1746 fprintf(irp->f, ",");2201 fprintf(irp->f, ",");
1747 ir_print_other_instruction(irp, instruction->ranges[i].start);2202 ir_print_other_inst_src(irp, instruction->ranges[i].start);
1748 fprintf(irp->f, "...");2203 fprintf(irp->f, "...");
1749 ir_print_other_instruction(irp, instruction->ranges[i].end);2204 ir_print_other_inst_src(irp, instruction->ranges[i].end);
1750 }2205 }
1751 const char *have_else_str = instruction->have_else_prong ? "yes" : "no";2206 const char *have_else_str = instruction->have_else_prong ? "yes" : "no";
1752 fprintf(irp->f, ")else:%s", have_else_str);2207 fprintf(irp->f, ")else:%s", have_else_str);
1753}2208}
17542209
1755static void ir_print_check_statement_is_void(IrPrint *irp, IrInstructionCheckStatementIsVoid *instruction) {2210static void ir_print_check_statement_is_void(IrPrintSrc *irp, IrInstSrcCheckStatementIsVoid *instruction) {
1756 fprintf(irp->f, "@checkStatementIsVoid(");2211 fprintf(irp->f, "@checkStatementIsVoid(");
1757 ir_print_other_instruction(irp, instruction->statement_value);2212 ir_print_other_inst_src(irp, instruction->statement_value);
1758 fprintf(irp->f, ")");2213 fprintf(irp->f, ")");
1759}2214}
17602215
1761static void ir_print_type_name(IrPrint *irp, IrInstructionTypeName *instruction) {2216static void ir_print_type_name(IrPrintSrc *irp, IrInstSrcTypeName *instruction) {
1762 fprintf(irp->f, "typename ");2217 fprintf(irp->f, "typename ");
1763 ir_print_other_instruction(irp, instruction->type_value);2218 ir_print_other_inst_src(irp, instruction->type_value);
2219}
2220
2221static void ir_print_tag_name(IrPrintSrc *irp, IrInstSrcTagName *instruction) {
2222 fprintf(irp->f, "tagname ");
2223 ir_print_other_inst_src(irp, instruction->target);
1764}2224}
17652225
1766static void ir_print_tag_name(IrPrint *irp, IrInstructionTagName *instruction) {2226static void ir_print_tag_name(IrPrintGen *irp, IrInstGenTagName *instruction) {
1767 fprintf(irp->f, "tagname ");2227 fprintf(irp->f, "tagname ");
1768 ir_print_other_instruction(irp, instruction->target);2228 ir_print_other_inst_gen(irp, instruction->target);
1769}2229}
17702230
1771static void ir_print_ptr_type(IrPrint *irp, IrInstructionPtrType *instruction) {2231static void ir_print_ptr_type(IrPrintSrc *irp, IrInstSrcPtrType *instruction) {
1772 fprintf(irp->f, "&");2232 fprintf(irp->f, "&");
1773 if (instruction->align_value != nullptr) {2233 if (instruction->align_value != nullptr) {
1774 fprintf(irp->f, "align(");2234 fprintf(irp->f, "align(");
1775 ir_print_other_instruction(irp, instruction->align_value);2235 ir_print_other_inst_src(irp, instruction->align_value);
1776 fprintf(irp->f, ")");2236 fprintf(irp->f, ")");
1777 }2237 }
1778 const char *const_str = instruction->is_const ? "const " : "";2238 const char *const_str = instruction->is_const ? "const " : "";
1779 const char *volatile_str = instruction->is_volatile ? "volatile " : "";2239 const char *volatile_str = instruction->is_volatile ? "volatile " : "";
1780 fprintf(irp->f, ":%" PRIu32 ":%" PRIu32 " %s%s", instruction->bit_offset_start, instruction->host_int_bytes,2240 fprintf(irp->f, ":%" PRIu32 ":%" PRIu32 " %s%s", instruction->bit_offset_start, instruction->host_int_bytes,
1781 const_str, volatile_str);2241 const_str, volatile_str);
1782 ir_print_other_instruction(irp, instruction->child_type);2242 ir_print_other_inst_src(irp, instruction->child_type);
1783}2243}
17842244
1785static void ir_print_decl_ref(IrPrint *irp, IrInstructionDeclRef *instruction) {2245static void ir_print_decl_ref(IrPrintSrc *irp, IrInstSrcDeclRef *instruction) {
1786 const char *ptr_str = (instruction->lval == LValPtr) ? "ptr " : "";2246 const char *ptr_str = (instruction->lval == LValPtr) ? "ptr " : "";
1787 fprintf(irp->f, "declref %s%s", ptr_str, buf_ptr(instruction->tld->name));2247 fprintf(irp->f, "declref %s%s", ptr_str, buf_ptr(instruction->tld->name));
1788}2248}
17892249
1790static void ir_print_panic(IrPrint *irp, IrInstructionPanic *instruction) {2250static void ir_print_panic(IrPrintSrc *irp, IrInstSrcPanic *instruction) {
1791 fprintf(irp->f, "@panic(");2251 fprintf(irp->f, "@panic(");
1792 ir_print_other_instruction(irp, instruction->msg);2252 ir_print_other_inst_src(irp, instruction->msg);
1793 fprintf(irp->f, ")");2253 fprintf(irp->f, ")");
1794}2254}
17952255
1796static void ir_print_field_parent_ptr(IrPrint *irp, IrInstructionFieldParentPtr *instruction) {2256static void ir_print_panic(IrPrintGen *irp, IrInstGenPanic *instruction) {
2257 fprintf(irp->f, "@panic(");
2258 ir_print_other_inst_gen(irp, instruction->msg);
2259 fprintf(irp->f, ")");
2260}
2261
2262static void ir_print_field_parent_ptr(IrPrintSrc *irp, IrInstSrcFieldParentPtr *instruction) {
1797 fprintf(irp->f, "@fieldParentPtr(");2263 fprintf(irp->f, "@fieldParentPtr(");
1798 ir_print_other_instruction(irp, instruction->type_value);2264 ir_print_other_inst_src(irp, instruction->type_value);
1799 fprintf(irp->f, ",");2265 fprintf(irp->f, ",");
1800 ir_print_other_instruction(irp, instruction->field_name);2266 ir_print_other_inst_src(irp, instruction->field_name);
1801 fprintf(irp->f, ",");2267 fprintf(irp->f, ",");
1802 ir_print_other_instruction(irp, instruction->field_ptr);2268 ir_print_other_inst_src(irp, instruction->field_ptr);
1803 fprintf(irp->f, ")");2269 fprintf(irp->f, ")");
1804}2270}
18052271
1806static void ir_print_byte_offset_of(IrPrint *irp, IrInstructionByteOffsetOf *instruction) {2272static void ir_print_field_parent_ptr(IrPrintGen *irp, IrInstGenFieldParentPtr *instruction) {
2273 fprintf(irp->f, "@fieldParentPtr(%s,", buf_ptr(instruction->field->name));
2274 ir_print_other_inst_gen(irp, instruction->field_ptr);
2275 fprintf(irp->f, ")");
2276}
2277
2278static void ir_print_byte_offset_of(IrPrintSrc *irp, IrInstSrcByteOffsetOf *instruction) {
1807 fprintf(irp->f, "@byte_offset_of(");2279 fprintf(irp->f, "@byte_offset_of(");
1808 ir_print_other_instruction(irp, instruction->type_value);2280 ir_print_other_inst_src(irp, instruction->type_value);
1809 fprintf(irp->f, ",");2281 fprintf(irp->f, ",");
1810 ir_print_other_instruction(irp, instruction->field_name);2282 ir_print_other_inst_src(irp, instruction->field_name);
1811 fprintf(irp->f, ")");2283 fprintf(irp->f, ")");
1812}2284}
18132285
1814static void ir_print_bit_offset_of(IrPrint *irp, IrInstructionBitOffsetOf *instruction) {2286static void ir_print_bit_offset_of(IrPrintSrc *irp, IrInstSrcBitOffsetOf *instruction) {
1815 fprintf(irp->f, "@bit_offset_of(");2287 fprintf(irp->f, "@bit_offset_of(");
1816 ir_print_other_instruction(irp, instruction->type_value);2288 ir_print_other_inst_src(irp, instruction->type_value);
1817 fprintf(irp->f, ",");2289 fprintf(irp->f, ",");
1818 ir_print_other_instruction(irp, instruction->field_name);2290 ir_print_other_inst_src(irp, instruction->field_name);
1819 fprintf(irp->f, ")");2291 fprintf(irp->f, ")");
1820}2292}
18212293
1822static void ir_print_type_info(IrPrint *irp, IrInstructionTypeInfo *instruction) {2294static void ir_print_type_info(IrPrintSrc *irp, IrInstSrcTypeInfo *instruction) {
1823 fprintf(irp->f, "@typeInfo(");2295 fprintf(irp->f, "@typeInfo(");
1824 ir_print_other_instruction(irp, instruction->type_value);2296 ir_print_other_inst_src(irp, instruction->type_value);
1825 fprintf(irp->f, ")");2297 fprintf(irp->f, ")");
1826}2298}
18272299
1828static void ir_print_type(IrPrint *irp, IrInstructionType *instruction) {2300static void ir_print_type(IrPrintSrc *irp, IrInstSrcType *instruction) {
1829 fprintf(irp->f, "@Type(");2301 fprintf(irp->f, "@Type(");
1830 ir_print_other_instruction(irp, instruction->type_info);2302 ir_print_other_inst_src(irp, instruction->type_info);
1831 fprintf(irp->f, ")");2303 fprintf(irp->f, ")");
1832}2304}
18332305
1834static void ir_print_has_field(IrPrint *irp, IrInstructionHasField *instruction) {2306static void ir_print_has_field(IrPrintSrc *irp, IrInstSrcHasField *instruction) {
1835 fprintf(irp->f, "@hasField(");2307 fprintf(irp->f, "@hasField(");
1836 ir_print_other_instruction(irp, instruction->container_type);2308 ir_print_other_inst_src(irp, instruction->container_type);
1837 fprintf(irp->f, ",");2309 fprintf(irp->f, ",");
1838 ir_print_other_instruction(irp, instruction->field_name);2310 ir_print_other_inst_src(irp, instruction->field_name);
1839 fprintf(irp->f, ")");2311 fprintf(irp->f, ")");
1840}2312}
18412313
1842static void ir_print_type_id(IrPrint *irp, IrInstructionTypeId *instruction) {2314static void ir_print_type_id(IrPrintSrc *irp, IrInstSrcTypeId *instruction) {
1843 fprintf(irp->f, "@typeId(");2315 fprintf(irp->f, "@typeId(");
1844 ir_print_other_instruction(irp, instruction->type_value);2316 ir_print_other_inst_src(irp, instruction->type_value);
1845 fprintf(irp->f, ")");2317 fprintf(irp->f, ")");
1846}2318}
18472319
1848static void ir_print_set_eval_branch_quota(IrPrint *irp, IrInstructionSetEvalBranchQuota *instruction) {2320static void ir_print_set_eval_branch_quota(IrPrintSrc *irp, IrInstSrcSetEvalBranchQuota *instruction) {
1849 fprintf(irp->f, "@setEvalBranchQuota(");2321 fprintf(irp->f, "@setEvalBranchQuota(");
1850 ir_print_other_instruction(irp, instruction->new_quota);2322 ir_print_other_inst_src(irp, instruction->new_quota);
1851 fprintf(irp->f, ")");2323 fprintf(irp->f, ")");
1852}2324}
18532325
1854static void ir_print_align_cast(IrPrint *irp, IrInstructionAlignCast *instruction) {2326static void ir_print_align_cast(IrPrintSrc *irp, IrInstSrcAlignCast *instruction) {
1855 fprintf(irp->f, "@alignCast(");2327 fprintf(irp->f, "@alignCast(");
1856 if (instruction->align_bytes == nullptr) {2328 ir_print_other_inst_src(irp, instruction->align_bytes);
1857 fprintf(irp->f, "null");
1858 } else {
1859 ir_print_other_instruction(irp, instruction->align_bytes);
1860 }
1861 fprintf(irp->f, ",");2329 fprintf(irp->f, ",");
1862 ir_print_other_instruction(irp, instruction->target);2330 ir_print_other_inst_src(irp, instruction->target);
2331 fprintf(irp->f, ")");
2332}
2333
2334static void ir_print_align_cast(IrPrintGen *irp, IrInstGenAlignCast *instruction) {
2335 fprintf(irp->f, "@alignCast(");
2336 ir_print_other_inst_gen(irp, instruction->target);
1863 fprintf(irp->f, ")");2337 fprintf(irp->f, ")");
1864}2338}
18652339
1866static void ir_print_resolve_result(IrPrint *irp, IrInstructionResolveResult *instruction) {2340static void ir_print_resolve_result(IrPrintSrc *irp, IrInstSrcResolveResult *instruction) {
1867 fprintf(irp->f, "ResolveResult(");2341 fprintf(irp->f, "ResolveResult(");
1868 ir_print_result_loc(irp, instruction->result_loc);2342 ir_print_result_loc(irp, instruction->result_loc);
1869 fprintf(irp->f, ")");2343 fprintf(irp->f, ")");
1870}2344}
18712345
1872static void ir_print_reset_result(IrPrint *irp, IrInstructionResetResult *instruction) {2346static void ir_print_reset_result(IrPrintSrc *irp, IrInstSrcResetResult *instruction) {
1873 fprintf(irp->f, "ResetResult(");2347 fprintf(irp->f, "ResetResult(");
1874 ir_print_result_loc(irp, instruction->result_loc);2348 ir_print_result_loc(irp, instruction->result_loc);
1875 fprintf(irp->f, ")");2349 fprintf(irp->f, ")");
1876}2350}
18772351
1878static void ir_print_opaque_type(IrPrint *irp, IrInstructionOpaqueType *instruction) {2352static void ir_print_opaque_type(IrPrintSrc *irp, IrInstSrcOpaqueType *instruction) {
1879 fprintf(irp->f, "@OpaqueType()");2353 fprintf(irp->f, "@OpaqueType()");
1880}2354}
18812355
1882static void ir_print_set_align_stack(IrPrint *irp, IrInstructionSetAlignStack *instruction) {2356static void ir_print_set_align_stack(IrPrintSrc *irp, IrInstSrcSetAlignStack *instruction) {
1883 fprintf(irp->f, "@setAlignStack(");2357 fprintf(irp->f, "@setAlignStack(");
1884 ir_print_other_instruction(irp, instruction->align_bytes);2358 ir_print_other_inst_src(irp, instruction->align_bytes);
1885 fprintf(irp->f, ")");2359 fprintf(irp->f, ")");
1886}2360}
18872361
1888static void ir_print_arg_type(IrPrint *irp, IrInstructionArgType *instruction) {2362static void ir_print_arg_type(IrPrintSrc *irp, IrInstSrcArgType *instruction) {
1889 fprintf(irp->f, "@ArgType(");2363 fprintf(irp->f, "@ArgType(");
1890 ir_print_other_instruction(irp, instruction->fn_type);2364 ir_print_other_inst_src(irp, instruction->fn_type);
1891 fprintf(irp->f, ",");2365 fprintf(irp->f, ",");
1892 ir_print_other_instruction(irp, instruction->arg_index);2366 ir_print_other_inst_src(irp, instruction->arg_index);
1893 fprintf(irp->f, ")");2367 fprintf(irp->f, ")");
1894}2368}
18952369
1896static void ir_print_enum_tag_type(IrPrint *irp, IrInstructionTagType *instruction) {2370static void ir_print_enum_tag_type(IrPrintSrc *irp, IrInstSrcTagType *instruction) {
1897 fprintf(irp->f, "@TagType(");2371 fprintf(irp->f, "@TagType(");
1898 ir_print_other_instruction(irp, instruction->target);2372 ir_print_other_inst_src(irp, instruction->target);
1899 fprintf(irp->f, ")");2373 fprintf(irp->f, ")");
1900}2374}
19012375
1902static void ir_print_export(IrPrint *irp, IrInstructionExport *instruction) {2376static void ir_print_export(IrPrintSrc *irp, IrInstSrcExport *instruction) {
1903 fprintf(irp->f, "@export(");2377 fprintf(irp->f, "@export(");
1904 ir_print_other_instruction(irp, instruction->target);2378 ir_print_other_inst_src(irp, instruction->target);
1905 fprintf(irp->f, ",");2379 fprintf(irp->f, ",");
1906 ir_print_other_instruction(irp, instruction->options);2380 ir_print_other_inst_src(irp, instruction->options);
2381 fprintf(irp->f, ")");
2382}
2383
2384static void ir_print_error_return_trace(IrPrintSrc *irp, IrInstSrcErrorReturnTrace *instruction) {
2385 fprintf(irp->f, "@errorReturnTrace(");
2386 switch (instruction->optional) {
2387 case IrInstErrorReturnTraceNull:
2388 fprintf(irp->f, "Null");
2389 break;
2390 case IrInstErrorReturnTraceNonNull:
2391 fprintf(irp->f, "NonNull");
2392 break;
2393 }
1907 fprintf(irp->f, ")");2394 fprintf(irp->f, ")");
1908}2395}
19092396
1910static void ir_print_error_return_trace(IrPrint *irp, IrInstructionErrorReturnTrace *instruction) {2397static void ir_print_error_return_trace(IrPrintGen *irp, IrInstGenErrorReturnTrace *instruction) {
1911 fprintf(irp->f, "@errorReturnTrace(");2398 fprintf(irp->f, "@errorReturnTrace(");
1912 switch (instruction->optional) {2399 switch (instruction->optional) {
1913 case IrInstructionErrorReturnTrace::Null:2400 case IrInstErrorReturnTraceNull:
1914 fprintf(irp->f, "Null");2401 fprintf(irp->f, "Null");
1915 break;2402 break;
1916 case IrInstructionErrorReturnTrace::NonNull:2403 case IrInstErrorReturnTraceNonNull:
1917 fprintf(irp->f, "NonNull");2404 fprintf(irp->f, "NonNull");
1918 break;2405 break;
1919 }2406 }
1920 fprintf(irp->f, ")");2407 fprintf(irp->f, ")");
1921}2408}
19222409
1923static void ir_print_error_union(IrPrint *irp, IrInstructionErrorUnion *instruction) {2410static void ir_print_error_union(IrPrintSrc *irp, IrInstSrcErrorUnion *instruction) {
1924 ir_print_other_instruction(irp, instruction->err_set);2411 ir_print_other_inst_src(irp, instruction->err_set);
1925 fprintf(irp->f, "!");2412 fprintf(irp->f, "!");
1926 ir_print_other_instruction(irp, instruction->payload);2413 ir_print_other_inst_src(irp, instruction->payload);
1927}2414}
19282415
1929static void ir_print_atomic_rmw(IrPrint *irp, IrInstructionAtomicRmw *instruction) {2416static void ir_print_atomic_rmw(IrPrintSrc *irp, IrInstSrcAtomicRmw *instruction) {
1930 fprintf(irp->f, "@atomicRmw(");2417 fprintf(irp->f, "@atomicRmw(");
1931 if (instruction->operand_type != nullptr) {2418 ir_print_other_inst_src(irp, instruction->operand_type);
1932 ir_print_other_instruction(irp, instruction->operand_type);
1933 } else {
1934 fprintf(irp->f, "[TODO print]");
1935 }
1936 fprintf(irp->f, ",");2419 fprintf(irp->f, ",");
1937 ir_print_other_instruction(irp, instruction->ptr);2420 ir_print_other_inst_src(irp, instruction->ptr);
1938 fprintf(irp->f, ",");2421 fprintf(irp->f, ",");
1939 if (instruction->op != nullptr) {2422 ir_print_other_inst_src(irp, instruction->op);
1940 ir_print_other_instruction(irp, instruction->op);
1941 } else {
1942 fprintf(irp->f, "[TODO print]");
1943 }
1944 fprintf(irp->f, ",");2423 fprintf(irp->f, ",");
1945 ir_print_other_instruction(irp, instruction->operand);2424 ir_print_other_inst_src(irp, instruction->operand);
1946 fprintf(irp->f, ",");2425 fprintf(irp->f, ",");
1947 if (instruction->ordering != nullptr) {2426 ir_print_other_inst_src(irp, instruction->ordering);
1948 ir_print_other_instruction(irp, instruction->ordering);
1949 } else {
1950 fprintf(irp->f, "[TODO print]");
1951 }
1952 fprintf(irp->f, ")");2427 fprintf(irp->f, ")");
1953}2428}
19542429
1955static void ir_print_atomic_load(IrPrint *irp, IrInstructionAtomicLoad *instruction) {2430static void ir_print_atomic_rmw(IrPrintGen *irp, IrInstGenAtomicRmw *instruction) {
2431 fprintf(irp->f, "@atomicRmw(");
2432 ir_print_other_inst_gen(irp, instruction->ptr);
2433 fprintf(irp->f, ",[TODO print op],");
2434 ir_print_other_inst_gen(irp, instruction->operand);
2435 fprintf(irp->f, ",%s)", atomic_order_str(instruction->ordering));
2436}
2437
2438static void ir_print_atomic_load(IrPrintSrc *irp, IrInstSrcAtomicLoad *instruction) {
1956 fprintf(irp->f, "@atomicLoad(");2439 fprintf(irp->f, "@atomicLoad(");
1957 if (instruction->operand_type != nullptr) {2440 ir_print_other_inst_src(irp, instruction->operand_type);
1958 ir_print_other_instruction(irp, instruction->operand_type);
1959 } else {
1960 fprintf(irp->f, "[TODO print]");
1961 }
1962 fprintf(irp->f, ",");2441 fprintf(irp->f, ",");
1963 ir_print_other_instruction(irp, instruction->ptr);2442 ir_print_other_inst_src(irp, instruction->ptr);
1964 fprintf(irp->f, ",");2443 fprintf(irp->f, ",");
1965 if (instruction->ordering != nullptr) {2444 ir_print_other_inst_src(irp, instruction->ordering);
1966 ir_print_other_instruction(irp, instruction->ordering);
1967 } else {
1968 fprintf(irp->f, "[TODO print]");
1969 }
1970 fprintf(irp->f, ")");2445 fprintf(irp->f, ")");
1971}2446}
19722447
1973static void ir_print_atomic_store(IrPrint *irp, IrInstructionAtomicStore *instruction) {2448static void ir_print_atomic_load(IrPrintGen *irp, IrInstGenAtomicLoad *instruction) {
2449 fprintf(irp->f, "@atomicLoad(");
2450 ir_print_other_inst_gen(irp, instruction->ptr);
2451 fprintf(irp->f, ",%s)", atomic_order_str(instruction->ordering));
2452}
2453
2454static void ir_print_atomic_store(IrPrintSrc *irp, IrInstSrcAtomicStore *instruction) {
1974 fprintf(irp->f, "@atomicStore(");2455 fprintf(irp->f, "@atomicStore(");
1975 if (instruction->operand_type != nullptr) {2456 ir_print_other_inst_src(irp, instruction->operand_type);
1976 ir_print_other_instruction(irp, instruction->operand_type);
1977 } else {
1978 fprintf(irp->f, "[TODO print]");
1979 }
1980 fprintf(irp->f, ",");2457 fprintf(irp->f, ",");
1981 ir_print_other_instruction(irp, instruction->ptr);2458 ir_print_other_inst_src(irp, instruction->ptr);
1982 fprintf(irp->f, ",");2459 fprintf(irp->f, ",");
1983 ir_print_other_instruction(irp, instruction->value);2460 ir_print_other_inst_src(irp, instruction->value);
1984 fprintf(irp->f, ",");2461 fprintf(irp->f, ",");
1985 if (instruction->ordering != nullptr) {2462 ir_print_other_inst_src(irp, instruction->ordering);
1986 ir_print_other_instruction(irp, instruction->ordering);
1987 } else {
1988 fprintf(irp->f, "[TODO print]");
1989 }
1990 fprintf(irp->f, ")");2463 fprintf(irp->f, ")");
1991}2464}
19922465
2466static void ir_print_atomic_store(IrPrintGen *irp, IrInstGenAtomicStore *instruction) {
2467 fprintf(irp->f, "@atomicStore(");
2468 ir_print_other_inst_gen(irp, instruction->ptr);
2469 fprintf(irp->f, ",");
2470 ir_print_other_inst_gen(irp, instruction->value);
2471 fprintf(irp->f, ",%s)", atomic_order_str(instruction->ordering));
2472}
2473
2474
2475static void ir_print_save_err_ret_addr(IrPrintSrc *irp, IrInstSrcSaveErrRetAddr *instruction) {
2476 fprintf(irp->f, "@saveErrRetAddr()");
2477}
19932478
1994static void ir_print_save_err_ret_addr(IrPrint *irp, IrInstructionSaveErrRetAddr *instruction) {2479static void ir_print_save_err_ret_addr(IrPrintGen *irp, IrInstGenSaveErrRetAddr *instruction) {
1995 fprintf(irp->f, "@saveErrRetAddr()");2480 fprintf(irp->f, "@saveErrRetAddr()");
1996}2481}
19972482
1998static void ir_print_add_implicit_return_type(IrPrint *irp, IrInstructionAddImplicitReturnType *instruction) {2483static void ir_print_add_implicit_return_type(IrPrintSrc *irp, IrInstSrcAddImplicitReturnType *instruction) {
1999 fprintf(irp->f, "@addImplicitReturnType(");2484 fprintf(irp->f, "@addImplicitReturnType(");
2000 ir_print_other_instruction(irp, instruction->value);2485 ir_print_other_inst_src(irp, instruction->value);
2486 fprintf(irp->f, ")");
2487}
2488
2489static void ir_print_float_op(IrPrintSrc *irp, IrInstSrcFloatOp *instruction) {
2490 fprintf(irp->f, "@%s(", float_op_to_name(instruction->fn_id));
2491 ir_print_other_inst_src(irp, instruction->operand);
2001 fprintf(irp->f, ")");2492 fprintf(irp->f, ")");
2002}2493}
20032494
2004static void ir_print_float_op(IrPrint *irp, IrInstructionFloatOp *instruction) {2495static void ir_print_float_op(IrPrintGen *irp, IrInstGenFloatOp *instruction) {
2005 fprintf(irp->f, "@%s(", float_op_to_name(instruction->fn_id));2496 fprintf(irp->f, "@%s(", float_op_to_name(instruction->fn_id));
2006 ir_print_other_instruction(irp, instruction->operand);2497 ir_print_other_inst_gen(irp, instruction->operand);
2007 fprintf(irp->f, ")");2498 fprintf(irp->f, ")");
2008}2499}
20092500
2010static void ir_print_mul_add(IrPrint *irp, IrInstructionMulAdd *instruction) {2501static void ir_print_mul_add(IrPrintSrc *irp, IrInstSrcMulAdd *instruction) {
2011 fprintf(irp->f, "@mulAdd(");2502 fprintf(irp->f, "@mulAdd(");
2012 if (instruction->type_value != nullptr) {2503 ir_print_other_inst_src(irp, instruction->type_value);
2013 ir_print_other_instruction(irp, instruction->type_value);
2014 } else {
2015 fprintf(irp->f, "null");
2016 }
2017 fprintf(irp->f, ",");2504 fprintf(irp->f, ",");
2018 ir_print_other_instruction(irp, instruction->op1);2505 ir_print_other_inst_src(irp, instruction->op1);
2019 fprintf(irp->f, ",");2506 fprintf(irp->f, ",");
2020 ir_print_other_instruction(irp, instruction->op2);2507 ir_print_other_inst_src(irp, instruction->op2);
2021 fprintf(irp->f, ",");2508 fprintf(irp->f, ",");
2022 ir_print_other_instruction(irp, instruction->op3);2509 ir_print_other_inst_src(irp, instruction->op3);
2023 fprintf(irp->f, ")");2510 fprintf(irp->f, ")");
2024}2511}
20252512
2026static void ir_print_decl_var_gen(IrPrint *irp, IrInstructionDeclVarGen *decl_var_instruction) {2513static void ir_print_mul_add(IrPrintGen *irp, IrInstGenMulAdd *instruction) {
2514 fprintf(irp->f, "@mulAdd(");
2515 ir_print_other_inst_gen(irp, instruction->op1);
2516 fprintf(irp->f, ",");
2517 ir_print_other_inst_gen(irp, instruction->op2);
2518 fprintf(irp->f, ",");
2519 ir_print_other_inst_gen(irp, instruction->op3);
2520 fprintf(irp->f, ")");
2521}
2522
2523static void ir_print_decl_var_gen(IrPrintGen *irp, IrInstGenDeclVar *decl_var_instruction) {
2027 ZigVar *var = decl_var_instruction->var;2524 ZigVar *var = decl_var_instruction->var;
2028 const char *var_or_const = decl_var_instruction->var->gen_is_const ? "const" : "var";2525 const char *var_or_const = decl_var_instruction->var->gen_is_const ? "const" : "var";
2029 const char *name = decl_var_instruction->var->name;2526 const char *name = decl_var_instruction->var->name;
2030 fprintf(irp->f, "%s %s: %s align(%u) = ", var_or_const, name, buf_ptr(&var->var_type->name),2527 fprintf(irp->f, "%s %s: %s align(%u) = ", var_or_const, name, buf_ptr(&var->var_type->name),
2031 var->align_bytes);2528 var->align_bytes);
20322529
2033 ir_print_other_instruction(irp, decl_var_instruction->var_ptr);2530 ir_print_other_inst_gen(irp, decl_var_instruction->var_ptr);
2034 if (decl_var_instruction->var->is_comptime != nullptr) {
2035 fprintf(irp->f, " // comptime = ");
2036 ir_print_other_instruction(irp, decl_var_instruction->var->is_comptime);
2037 }
2038}2531}
20392532
2040static void ir_print_has_decl(IrPrint *irp, IrInstructionHasDecl *instruction) {2533static void ir_print_has_decl(IrPrintSrc *irp, IrInstSrcHasDecl *instruction) {
2041 fprintf(irp->f, "@hasDecl(");2534 fprintf(irp->f, "@hasDecl(");
2042 ir_print_other_instruction(irp, instruction->container);2535 ir_print_other_inst_src(irp, instruction->container);
2043 fprintf(irp->f, ",");2536 fprintf(irp->f, ",");
2044 ir_print_other_instruction(irp, instruction->name);2537 ir_print_other_inst_src(irp, instruction->name);
2045 fprintf(irp->f, ")");2538 fprintf(irp->f, ")");
2046}2539}
20472540
2048static void ir_print_undeclared_ident(IrPrint *irp, IrInstructionUndeclaredIdent *instruction) {2541static void ir_print_undeclared_ident(IrPrintSrc *irp, IrInstSrcUndeclaredIdent *instruction) {
2049 fprintf(irp->f, "@undeclaredIdent(%s)", buf_ptr(instruction->name));2542 fprintf(irp->f, "@undeclaredIdent(%s)", buf_ptr(instruction->name));
2050}2543}
20512544
2052static void ir_print_union_init_named_field(IrPrint *irp, IrInstructionUnionInitNamedField *instruction) {2545static void ir_print_union_init_named_field(IrPrintSrc *irp, IrInstSrcUnionInitNamedField *instruction) {
2053 fprintf(irp->f, "@unionInit(");2546 fprintf(irp->f, "@unionInit(");
2054 ir_print_other_instruction(irp, instruction->union_type);2547 ir_print_other_inst_src(irp, instruction->union_type);
2055 fprintf(irp->f, ", ");2548 fprintf(irp->f, ", ");
2056 ir_print_other_instruction(irp, instruction->field_name);2549 ir_print_other_inst_src(irp, instruction->field_name);
2057 fprintf(irp->f, ", ");2550 fprintf(irp->f, ", ");
2058 ir_print_other_instruction(irp, instruction->field_result_loc);2551 ir_print_other_inst_src(irp, instruction->field_result_loc);
2059 fprintf(irp->f, ", ");2552 fprintf(irp->f, ", ");
2060 ir_print_other_instruction(irp, instruction->result_loc);2553 ir_print_other_inst_src(irp, instruction->result_loc);
2061 fprintf(irp->f, ")");2554 fprintf(irp->f, ")");
2062}2555}
20632556
2064static void ir_print_suspend_begin(IrPrint *irp, IrInstructionSuspendBegin *instruction) {2557static void ir_print_suspend_begin(IrPrintSrc *irp, IrInstSrcSuspendBegin *instruction) {
2558 fprintf(irp->f, "@suspendBegin()");
2559}
2560
2561static void ir_print_suspend_begin(IrPrintGen *irp, IrInstGenSuspendBegin *instruction) {
2065 fprintf(irp->f, "@suspendBegin()");2562 fprintf(irp->f, "@suspendBegin()");
2066}2563}
20672564
2068static void ir_print_suspend_finish(IrPrint *irp, IrInstructionSuspendFinish *instruction) {2565static void ir_print_suspend_finish(IrPrintSrc *irp, IrInstSrcSuspendFinish *instruction) {
2566 fprintf(irp->f, "@suspendFinish()");
2567}
2568
2569static void ir_print_suspend_finish(IrPrintGen *irp, IrInstGenSuspendFinish *instruction) {
2069 fprintf(irp->f, "@suspendFinish()");2570 fprintf(irp->f, "@suspendFinish()");
2070}2571}
20712572
2072static void ir_print_resume(IrPrint *irp, IrInstructionResume *instruction) {2573static void ir_print_resume(IrPrintSrc *irp, IrInstSrcResume *instruction) {
2073 fprintf(irp->f, "resume ");2574 fprintf(irp->f, "resume ");
2074 ir_print_other_instruction(irp, instruction->frame);2575 ir_print_other_inst_src(irp, instruction->frame);
2075}2576}
20762577
2077static void ir_print_await_src(IrPrint *irp, IrInstructionAwaitSrc *instruction) {2578static void ir_print_resume(IrPrintGen *irp, IrInstGenResume *instruction) {
2579 fprintf(irp->f, "resume ");
2580 ir_print_other_inst_gen(irp, instruction->frame);
2581}
2582
2583static void ir_print_await_src(IrPrintSrc *irp, IrInstSrcAwait *instruction) {
2078 fprintf(irp->f, "@await(");2584 fprintf(irp->f, "@await(");
2079 ir_print_other_instruction(irp, instruction->frame);2585 ir_print_other_inst_src(irp, instruction->frame);
2080 fprintf(irp->f, ",");2586 fprintf(irp->f, ",");
2081 ir_print_result_loc(irp, instruction->result_loc);2587 ir_print_result_loc(irp, instruction->result_loc);
2082 fprintf(irp->f, ")");2588 fprintf(irp->f, ")");
2083}2589}
20842590
2085static void ir_print_await_gen(IrPrint *irp, IrInstructionAwaitGen *instruction) {2591static void ir_print_await_gen(IrPrintGen *irp, IrInstGenAwait *instruction) {
2086 fprintf(irp->f, "@await(");2592 fprintf(irp->f, "@await(");
2087 ir_print_other_instruction(irp, instruction->frame);2593 ir_print_other_inst_gen(irp, instruction->frame);
2088 fprintf(irp->f, ",");2594 fprintf(irp->f, ",");
2089 ir_print_other_instruction(irp, instruction->result_loc);2595 ir_print_other_inst_gen(irp, instruction->result_loc);
2596 fprintf(irp->f, ")");
2597}
2598
2599static void ir_print_spill_begin(IrPrintSrc *irp, IrInstSrcSpillBegin *instruction) {
2600 fprintf(irp->f, "@spillBegin(");
2601 ir_print_other_inst_src(irp, instruction->operand);
2090 fprintf(irp->f, ")");2602 fprintf(irp->f, ")");
2091}2603}
20922604
2093static void ir_print_spill_begin(IrPrint *irp, IrInstructionSpillBegin *instruction) {2605static void ir_print_spill_begin(IrPrintGen *irp, IrInstGenSpillBegin *instruction) {
2094 fprintf(irp->f, "@spillBegin(");2606 fprintf(irp->f, "@spillBegin(");
2095 ir_print_other_instruction(irp, instruction->operand);2607 ir_print_other_inst_gen(irp, instruction->operand);
2096 fprintf(irp->f, ")");2608 fprintf(irp->f, ")");
2097}2609}
20982610
2099static void ir_print_spill_end(IrPrint *irp, IrInstructionSpillEnd *instruction) {2611static void ir_print_spill_end(IrPrintSrc *irp, IrInstSrcSpillEnd *instruction) {
2100 fprintf(irp->f, "@spillEnd(");2612 fprintf(irp->f, "@spillEnd(");
2101 ir_print_other_instruction(irp, &instruction->begin->base);2613 ir_print_other_inst_src(irp, &instruction->begin->base);
2102 fprintf(irp->f, ")");2614 fprintf(irp->f, ")");
2103}2615}
21042616
2105static void ir_print_vector_extract_elem(IrPrint *irp, IrInstructionVectorExtractElem *instruction) {2617static void ir_print_spill_end(IrPrintGen *irp, IrInstGenSpillEnd *instruction) {
2618 fprintf(irp->f, "@spillEnd(");
2619 ir_print_other_inst_gen(irp, &instruction->begin->base);
2620 fprintf(irp->f, ")");
2621}
2622
2623static void ir_print_vector_extract_elem(IrPrintGen *irp, IrInstGenVectorExtractElem *instruction) {
2106 fprintf(irp->f, "@vectorExtractElem(");2624 fprintf(irp->f, "@vectorExtractElem(");
2107 ir_print_other_instruction(irp, instruction->vector);2625 ir_print_other_inst_gen(irp, instruction->vector);
2108 fprintf(irp->f, ",");2626 fprintf(irp->f, ",");
2109 ir_print_other_instruction(irp, instruction->index);2627 ir_print_other_inst_gen(irp, instruction->index);
2110 fprintf(irp->f, ")");2628 fprintf(irp->f, ")");
2111}2629}
21122630
2113static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction, bool trailing) {2631static void ir_print_inst_src(IrPrintSrc *irp, IrInstSrc *instruction, bool trailing) {
2114 ir_print_prefix(irp, instruction, trailing);2632 ir_print_prefix_src(irp, instruction, trailing);
2115 switch (instruction->id) {2633 switch (instruction->id) {
2116 case IrInstructionIdInvalid:2634 case IrInstSrcIdInvalid:
2117 zig_unreachable();2635 zig_unreachable();
2118 case IrInstructionIdReturn:2636 case IrInstSrcIdReturn:
2119 ir_print_return(irp, (IrInstructionReturn *)instruction);2637 ir_print_return_src(irp, (IrInstSrcReturn *)instruction);
2638 break;
2639 case IrInstSrcIdConst:
2640 ir_print_const(irp, (IrInstSrcConst *)instruction);
2641 break;
2642 case IrInstSrcIdBinOp:
2643 ir_print_bin_op(irp, (IrInstSrcBinOp *)instruction);
2644 break;
2645 case IrInstSrcIdMergeErrSets:
2646 ir_print_merge_err_sets(irp, (IrInstSrcMergeErrSets *)instruction);
2647 break;
2648 case IrInstSrcIdDeclVar:
2649 ir_print_decl_var_src(irp, (IrInstSrcDeclVar *)instruction);
2650 break;
2651 case IrInstSrcIdCallExtra:
2652 ir_print_call_extra(irp, (IrInstSrcCallExtra *)instruction);
2653 break;
2654 case IrInstSrcIdCall:
2655 ir_print_call_src(irp, (IrInstSrcCall *)instruction);
2656 break;
2657 case IrInstSrcIdCallArgs:
2658 ir_print_call_args(irp, (IrInstSrcCallArgs *)instruction);
2659 break;
2660 case IrInstSrcIdUnOp:
2661 ir_print_un_op(irp, (IrInstSrcUnOp *)instruction);
2662 break;
2663 case IrInstSrcIdCondBr:
2664 ir_print_cond_br(irp, (IrInstSrcCondBr *)instruction);
2120 break;2665 break;
2121 case IrInstructionIdConst:2666 case IrInstSrcIdBr:
2122 ir_print_const(irp, (IrInstructionConst *)instruction);2667 ir_print_br(irp, (IrInstSrcBr *)instruction);
2123 break;2668 break;
2124 case IrInstructionIdBinOp:2669 case IrInstSrcIdPhi:
2125 ir_print_bin_op(irp, (IrInstructionBinOp *)instruction);2670 ir_print_phi(irp, (IrInstSrcPhi *)instruction);
2126 break;2671 break;
2127 case IrInstructionIdMergeErrSets:2672 case IrInstSrcIdContainerInitList:
2128 ir_print_merge_err_sets(irp, (IrInstructionMergeErrSets *)instruction);2673 ir_print_container_init_list(irp, (IrInstSrcContainerInitList *)instruction);
2129 break;2674 break;
2130 case IrInstructionIdDeclVarSrc:2675 case IrInstSrcIdContainerInitFields:
2131 ir_print_decl_var_src(irp, (IrInstructionDeclVarSrc *)instruction);2676 ir_print_container_init_fields(irp, (IrInstSrcContainerInitFields *)instruction);
2132 break;2677 break;
2133 case IrInstructionIdCast:2678 case IrInstSrcIdUnreachable:
2134 ir_print_cast(irp, (IrInstructionCast *)instruction);2679 ir_print_unreachable(irp, (IrInstSrcUnreachable *)instruction);
2135 break;2680 break;
2136 case IrInstructionIdCallExtra:2681 case IrInstSrcIdElemPtr:
2137 ir_print_call_extra(irp, (IrInstructionCallExtra *)instruction);2682 ir_print_elem_ptr(irp, (IrInstSrcElemPtr *)instruction);
2138 break;2683 break;
2139 case IrInstructionIdCallSrc:2684 case IrInstSrcIdVarPtr:
2140 ir_print_call_src(irp, (IrInstructionCallSrc *)instruction);2685 ir_print_var_ptr(irp, (IrInstSrcVarPtr *)instruction);
2141 break;2686 break;
2142 case IrInstructionIdCallSrcArgs:2687 case IrInstSrcIdLoadPtr:
2143 ir_print_call_src_args(irp, (IrInstructionCallSrcArgs *)instruction);2688 ir_print_load_ptr(irp, (IrInstSrcLoadPtr *)instruction);
2144 break;2689 break;
2145 case IrInstructionIdCallGen:2690 case IrInstSrcIdStorePtr:
2146 ir_print_call_gen(irp, (IrInstructionCallGen *)instruction);2691 ir_print_store_ptr(irp, (IrInstSrcStorePtr *)instruction);
2147 break;2692 break;
2148 case IrInstructionIdUnOp:2693 case IrInstSrcIdTypeOf:
2149 ir_print_un_op(irp, (IrInstructionUnOp *)instruction);2694 ir_print_typeof(irp, (IrInstSrcTypeOf *)instruction);
2150 break;2695 break;
2151 case IrInstructionIdCondBr:2696 case IrInstSrcIdFieldPtr:
2152 ir_print_cond_br(irp, (IrInstructionCondBr *)instruction);2697 ir_print_field_ptr(irp, (IrInstSrcFieldPtr *)instruction);
2153 break;2698 break;
2154 case IrInstructionIdBr:2699 case IrInstSrcIdSetCold:
2155 ir_print_br(irp, (IrInstructionBr *)instruction);2700 ir_print_set_cold(irp, (IrInstSrcSetCold *)instruction);
2156 break;2701 break;
2157 case IrInstructionIdPhi:2702 case IrInstSrcIdSetRuntimeSafety:
2158 ir_print_phi(irp, (IrInstructionPhi *)instruction);2703 ir_print_set_runtime_safety(irp, (IrInstSrcSetRuntimeSafety *)instruction);
2159 break;2704 break;
2160 case IrInstructionIdContainerInitList:2705 case IrInstSrcIdSetFloatMode:
2161 ir_print_container_init_list(irp, (IrInstructionContainerInitList *)instruction);2706 ir_print_set_float_mode(irp, (IrInstSrcSetFloatMode *)instruction);
2162 break;2707 break;
2163 case IrInstructionIdContainerInitFields:2708 case IrInstSrcIdArrayType:
2164 ir_print_container_init_fields(irp, (IrInstructionContainerInitFields *)instruction);2709 ir_print_array_type(irp, (IrInstSrcArrayType *)instruction);
2165 break;2710 break;
2166 case IrInstructionIdUnreachable:2711 case IrInstSrcIdSliceType:
2167 ir_print_unreachable(irp, (IrInstructionUnreachable *)instruction);2712 ir_print_slice_type(irp, (IrInstSrcSliceType *)instruction);
2168 break;2713 break;
2169 case IrInstructionIdElemPtr:2714 case IrInstSrcIdAnyFrameType:
2170 ir_print_elem_ptr(irp, (IrInstructionElemPtr *)instruction);2715 ir_print_any_frame_type(irp, (IrInstSrcAnyFrameType *)instruction);
2171 break;2716 break;
2172 case IrInstructionIdVarPtr:2717 case IrInstSrcIdAsm:
2173 ir_print_var_ptr(irp, (IrInstructionVarPtr *)instruction);2718 ir_print_asm_src(irp, (IrInstSrcAsm *)instruction);
2174 break;2719 break;
2175 case IrInstructionIdReturnPtr:2720 case IrInstSrcIdSizeOf:
2176 ir_print_return_ptr(irp, (IrInstructionReturnPtr *)instruction);2721 ir_print_size_of(irp, (IrInstSrcSizeOf *)instruction);
2177 break;2722 break;
2178 case IrInstructionIdLoadPtr:2723 case IrInstSrcIdTestNonNull:
2179 ir_print_load_ptr(irp, (IrInstructionLoadPtr *)instruction);2724 ir_print_test_non_null(irp, (IrInstSrcTestNonNull *)instruction);
2180 break;2725 break;
2181 case IrInstructionIdLoadPtrGen:2726 case IrInstSrcIdOptionalUnwrapPtr:
2182 ir_print_load_ptr_gen(irp, (IrInstructionLoadPtrGen *)instruction);2727 ir_print_optional_unwrap_ptr(irp, (IrInstSrcOptionalUnwrapPtr *)instruction);
2183 break;2728 break;
2184 case IrInstructionIdStorePtr:2729 case IrInstSrcIdPopCount:
2185 ir_print_store_ptr(irp, (IrInstructionStorePtr *)instruction);2730 ir_print_pop_count(irp, (IrInstSrcPopCount *)instruction);
2186 break;2731 break;
2187 case IrInstructionIdVectorStoreElem:2732 case IrInstSrcIdCtz:
2188 ir_print_vector_store_elem(irp, (IrInstructionVectorStoreElem *)instruction);2733 ir_print_ctz(irp, (IrInstSrcCtz *)instruction);
2189 break;2734 break;
2190 case IrInstructionIdTypeOf:2735 case IrInstSrcIdBswap:
2191 ir_print_typeof(irp, (IrInstructionTypeOf *)instruction);2736 ir_print_bswap(irp, (IrInstSrcBswap *)instruction);
2192 break;2737 break;
2193 case IrInstructionIdFieldPtr:2738 case IrInstSrcIdBitReverse:
2194 ir_print_field_ptr(irp, (IrInstructionFieldPtr *)instruction);2739 ir_print_bit_reverse(irp, (IrInstSrcBitReverse *)instruction);
2195 break;2740 break;
2196 case IrInstructionIdStructFieldPtr:2741 case IrInstSrcIdSwitchBr:
2197 ir_print_struct_field_ptr(irp, (IrInstructionStructFieldPtr *)instruction);2742 ir_print_switch_br(irp, (IrInstSrcSwitchBr *)instruction);
2198 break;2743 break;
2199 case IrInstructionIdUnionFieldPtr:2744 case IrInstSrcIdSwitchVar:
2200 ir_print_union_field_ptr(irp, (IrInstructionUnionFieldPtr *)instruction);2745 ir_print_switch_var(irp, (IrInstSrcSwitchVar *)instruction);
2201 break;2746 break;
2202 case IrInstructionIdSetCold:2747 case IrInstSrcIdSwitchElseVar:
2203 ir_print_set_cold(irp, (IrInstructionSetCold *)instruction);2748 ir_print_switch_else_var(irp, (IrInstSrcSwitchElseVar *)instruction);
2204 break;2749 break;
2205 case IrInstructionIdSetRuntimeSafety:2750 case IrInstSrcIdSwitchTarget:
2206 ir_print_set_runtime_safety(irp, (IrInstructionSetRuntimeSafety *)instruction);2751 ir_print_switch_target(irp, (IrInstSrcSwitchTarget *)instruction);
2207 break;2752 break;
2208 case IrInstructionIdSetFloatMode:2753 case IrInstSrcIdImport:
2209 ir_print_set_float_mode(irp, (IrInstructionSetFloatMode *)instruction);2754 ir_print_import(irp, (IrInstSrcImport *)instruction);
2210 break;2755 break;
2211 case IrInstructionIdArrayType:2756 case IrInstSrcIdRef:
2212 ir_print_array_type(irp, (IrInstructionArrayType *)instruction);2757 ir_print_ref(irp, (IrInstSrcRef *)instruction);
2213 break;2758 break;
2214 case IrInstructionIdSliceType:2759 case IrInstSrcIdCompileErr:
2215 ir_print_slice_type(irp, (IrInstructionSliceType *)instruction);2760 ir_print_compile_err(irp, (IrInstSrcCompileErr *)instruction);
2216 break;2761 break;
2217 case IrInstructionIdAnyFrameType:2762 case IrInstSrcIdCompileLog:
2218 ir_print_any_frame_type(irp, (IrInstructionAnyFrameType *)instruction);2763 ir_print_compile_log(irp, (IrInstSrcCompileLog *)instruction);
2219 break;2764 break;
2220 case IrInstructionIdAsmSrc:2765 case IrInstSrcIdErrName:
2221 ir_print_asm_src(irp, (IrInstructionAsmSrc *)instruction);2766 ir_print_err_name(irp, (IrInstSrcErrName *)instruction);
2222 break;2767 break;
2223 case IrInstructionIdAsmGen:2768 case IrInstSrcIdCImport:
2224 ir_print_asm_gen(irp, (IrInstructionAsmGen *)instruction);2769 ir_print_c_import(irp, (IrInstSrcCImport *)instruction);
2225 break;2770 break;
2226 case IrInstructionIdSizeOf:2771 case IrInstSrcIdCInclude:
2227 ir_print_size_of(irp, (IrInstructionSizeOf *)instruction);2772 ir_print_c_include(irp, (IrInstSrcCInclude *)instruction);
2228 break;2773 break;
2229 case IrInstructionIdTestNonNull:2774 case IrInstSrcIdCDefine:
2230 ir_print_test_non_null(irp, (IrInstructionTestNonNull *)instruction);2775 ir_print_c_define(irp, (IrInstSrcCDefine *)instruction);
2231 break;2776 break;
2232 case IrInstructionIdOptionalUnwrapPtr:2777 case IrInstSrcIdCUndef:
2233 ir_print_optional_unwrap_ptr(irp, (IrInstructionOptionalUnwrapPtr *)instruction);2778 ir_print_c_undef(irp, (IrInstSrcCUndef *)instruction);
2234 break;2779 break;
2235 case IrInstructionIdPopCount:2780 case IrInstSrcIdEmbedFile:
2236 ir_print_pop_count(irp, (IrInstructionPopCount *)instruction);2781 ir_print_embed_file(irp, (IrInstSrcEmbedFile *)instruction);
2237 break;2782 break;
2238 case IrInstructionIdClz:2783 case IrInstSrcIdCmpxchg:
2239 ir_print_clz(irp, (IrInstructionClz *)instruction);2784 ir_print_cmpxchg_src(irp, (IrInstSrcCmpxchg *)instruction);
2240 break;2785 break;
2241 case IrInstructionIdCtz:2786 case IrInstSrcIdFence:
2242 ir_print_ctz(irp, (IrInstructionCtz *)instruction);2787 ir_print_fence(irp, (IrInstSrcFence *)instruction);
2243 break;2788 break;
2244 case IrInstructionIdBswap:2789 case IrInstSrcIdTruncate:
2245 ir_print_bswap(irp, (IrInstructionBswap *)instruction);2790 ir_print_truncate(irp, (IrInstSrcTruncate *)instruction);
2246 break;2791 break;
2247 case IrInstructionIdBitReverse:2792 case IrInstSrcIdIntCast:
2248 ir_print_bit_reverse(irp, (IrInstructionBitReverse *)instruction);2793 ir_print_int_cast(irp, (IrInstSrcIntCast *)instruction);
2249 break;2794 break;
2250 case IrInstructionIdSwitchBr:2795 case IrInstSrcIdFloatCast:
2251 ir_print_switch_br(irp, (IrInstructionSwitchBr *)instruction);2796 ir_print_float_cast(irp, (IrInstSrcFloatCast *)instruction);
2252 break;2797 break;
2253 case IrInstructionIdSwitchVar:2798 case IrInstSrcIdErrSetCast:
2254 ir_print_switch_var(irp, (IrInstructionSwitchVar *)instruction);2799 ir_print_err_set_cast(irp, (IrInstSrcErrSetCast *)instruction);
2255 break;2800 break;
2256 case IrInstructionIdSwitchElseVar:2801 case IrInstSrcIdFromBytes:
2257 ir_print_switch_else_var(irp, (IrInstructionSwitchElseVar *)instruction);2802 ir_print_from_bytes(irp, (IrInstSrcFromBytes *)instruction);
2258 break;2803 break;
2259 case IrInstructionIdSwitchTarget:2804 case IrInstSrcIdToBytes:
2260 ir_print_switch_target(irp, (IrInstructionSwitchTarget *)instruction);2805 ir_print_to_bytes(irp, (IrInstSrcToBytes *)instruction);
2261 break;2806 break;
2262 case IrInstructionIdUnionTag:2807 case IrInstSrcIdIntToFloat:
2263 ir_print_union_tag(irp, (IrInstructionUnionTag *)instruction);2808 ir_print_int_to_float(irp, (IrInstSrcIntToFloat *)instruction);
2264 break;2809 break;
2265 case IrInstructionIdImport:2810 case IrInstSrcIdFloatToInt:
2266 ir_print_import(irp, (IrInstructionImport *)instruction);2811 ir_print_float_to_int(irp, (IrInstSrcFloatToInt *)instruction);
2267 break;2812 break;
2268 case IrInstructionIdRef:2813 case IrInstSrcIdBoolToInt:
2269 ir_print_ref(irp, (IrInstructionRef *)instruction);2814 ir_print_bool_to_int(irp, (IrInstSrcBoolToInt *)instruction);
2270 break;2815 break;
2271 case IrInstructionIdRefGen:2816 case IrInstSrcIdIntType:
2272 ir_print_ref_gen(irp, (IrInstructionRefGen *)instruction);2817 ir_print_int_type(irp, (IrInstSrcIntType *)instruction);
2273 break;2818 break;
2274 case IrInstructionIdCompileErr:2819 case IrInstSrcIdVectorType:
2275 ir_print_compile_err(irp, (IrInstructionCompileErr *)instruction);2820 ir_print_vector_type(irp, (IrInstSrcVectorType *)instruction);
2276 break;2821 break;
2277 case IrInstructionIdCompileLog:2822 case IrInstSrcIdShuffleVector:
2278 ir_print_compile_log(irp, (IrInstructionCompileLog *)instruction);2823 ir_print_shuffle_vector(irp, (IrInstSrcShuffleVector *)instruction);
2279 break;2824 break;
2280 case IrInstructionIdErrName:2825 case IrInstSrcIdSplat:
2281 ir_print_err_name(irp, (IrInstructionErrName *)instruction);2826 ir_print_splat_src(irp, (IrInstSrcSplat *)instruction);
2282 break;2827 break;
2283 case IrInstructionIdCImport:2828 case IrInstSrcIdBoolNot:
2284 ir_print_c_import(irp, (IrInstructionCImport *)instruction);2829 ir_print_bool_not(irp, (IrInstSrcBoolNot *)instruction);
2285 break;2830 break;
2286 case IrInstructionIdCInclude:2831 case IrInstSrcIdMemset:
2287 ir_print_c_include(irp, (IrInstructionCInclude *)instruction);2832 ir_print_memset(irp, (IrInstSrcMemset *)instruction);
2288 break;2833 break;
2289 case IrInstructionIdCDefine:2834 case IrInstSrcIdMemcpy:
2290 ir_print_c_define(irp, (IrInstructionCDefine *)instruction);2835 ir_print_memcpy(irp, (IrInstSrcMemcpy *)instruction);
2291 break;2836 break;
2292 case IrInstructionIdCUndef:2837 case IrInstSrcIdSlice:
2293 ir_print_c_undef(irp, (IrInstructionCUndef *)instruction);2838 ir_print_slice_src(irp, (IrInstSrcSlice *)instruction);
2294 break;2839 break;
2295 case IrInstructionIdEmbedFile:2840 case IrInstSrcIdMemberCount:
2296 ir_print_embed_file(irp, (IrInstructionEmbedFile *)instruction);2841 ir_print_member_count(irp, (IrInstSrcMemberCount *)instruction);
2297 break;2842 break;
2298 case IrInstructionIdCmpxchgSrc:2843 case IrInstSrcIdMemberType:
2299 ir_print_cmpxchg_src(irp, (IrInstructionCmpxchgSrc *)instruction);2844 ir_print_member_type(irp, (IrInstSrcMemberType *)instruction);
2300 break;2845 break;
2301 case IrInstructionIdCmpxchgGen:2846 case IrInstSrcIdMemberName:
2302 ir_print_cmpxchg_gen(irp, (IrInstructionCmpxchgGen *)instruction);2847 ir_print_member_name(irp, (IrInstSrcMemberName *)instruction);
2303 break;2848 break;
2304 case IrInstructionIdFence:2849 case IrInstSrcIdBreakpoint:
2305 ir_print_fence(irp, (IrInstructionFence *)instruction);2850 ir_print_breakpoint(irp, (IrInstSrcBreakpoint *)instruction);
2306 break;2851 break;
2307 case IrInstructionIdTruncate:2852 case IrInstSrcIdReturnAddress:
2308 ir_print_truncate(irp, (IrInstructionTruncate *)instruction);2853 ir_print_return_address(irp, (IrInstSrcReturnAddress *)instruction);
2309 break;2854 break;
2310 case IrInstructionIdIntCast:2855 case IrInstSrcIdFrameAddress:
2311 ir_print_int_cast(irp, (IrInstructionIntCast *)instruction);2856 ir_print_frame_address(irp, (IrInstSrcFrameAddress *)instruction);
2312 break;2857 break;
2313 case IrInstructionIdFloatCast:2858 case IrInstSrcIdFrameHandle:
2314 ir_print_float_cast(irp, (IrInstructionFloatCast *)instruction);2859 ir_print_handle(irp, (IrInstSrcFrameHandle *)instruction);
2315 break;2860 break;
2316 case IrInstructionIdErrSetCast:2861 case IrInstSrcIdFrameType:
2317 ir_print_err_set_cast(irp, (IrInstructionErrSetCast *)instruction);2862 ir_print_frame_type(irp, (IrInstSrcFrameType *)instruction);
2318 break;2863 break;
2319 case IrInstructionIdFromBytes:2864 case IrInstSrcIdFrameSize:
2320 ir_print_from_bytes(irp, (IrInstructionFromBytes *)instruction);2865 ir_print_frame_size_src(irp, (IrInstSrcFrameSize *)instruction);
2321 break;2866 break;
2322 case IrInstructionIdToBytes:2867 case IrInstSrcIdAlignOf:
2323 ir_print_to_bytes(irp, (IrInstructionToBytes *)instruction);2868 ir_print_align_of(irp, (IrInstSrcAlignOf *)instruction);
2324 break;2869 break;
2325 case IrInstructionIdIntToFloat:2870 case IrInstSrcIdOverflowOp:
2326 ir_print_int_to_float(irp, (IrInstructionIntToFloat *)instruction);2871 ir_print_overflow_op(irp, (IrInstSrcOverflowOp *)instruction);
2327 break;2872 break;
2328 case IrInstructionIdFloatToInt:2873 case IrInstSrcIdTestErr:
2329 ir_print_float_to_int(irp, (IrInstructionFloatToInt *)instruction);2874 ir_print_test_err_src(irp, (IrInstSrcTestErr *)instruction);
2330 break;2875 break;
2331 case IrInstructionIdBoolToInt:2876 case IrInstSrcIdUnwrapErrCode:
2332 ir_print_bool_to_int(irp, (IrInstructionBoolToInt *)instruction);2877 ir_print_unwrap_err_code(irp, (IrInstSrcUnwrapErrCode *)instruction);
2333 break;2878 break;
2334 case IrInstructionIdIntType:2879 case IrInstSrcIdUnwrapErrPayload:
2335 ir_print_int_type(irp, (IrInstructionIntType *)instruction);2880 ir_print_unwrap_err_payload(irp, (IrInstSrcUnwrapErrPayload *)instruction);
2336 break;2881 break;
2337 case IrInstructionIdVectorType:2882 case IrInstSrcIdFnProto:
2338 ir_print_vector_type(irp, (IrInstructionVectorType *)instruction);2883 ir_print_fn_proto(irp, (IrInstSrcFnProto *)instruction);
2339 break;2884 break;
2340 case IrInstructionIdShuffleVector:2885 case IrInstSrcIdTestComptime:
2341 ir_print_shuffle_vector(irp, (IrInstructionShuffleVector *)instruction);2886 ir_print_test_comptime(irp, (IrInstSrcTestComptime *)instruction);
2342 break;2887 break;
2343 case IrInstructionIdSplatSrc:2888 case IrInstSrcIdPtrCast:
2344 ir_print_splat_src(irp, (IrInstructionSplatSrc *)instruction);2889 ir_print_ptr_cast_src(irp, (IrInstSrcPtrCast *)instruction);
2345 break;2890 break;
2346 case IrInstructionIdSplatGen:2891 case IrInstSrcIdBitCast:
2347 ir_print_splat_gen(irp, (IrInstructionSplatGen *)instruction);2892 ir_print_bit_cast_src(irp, (IrInstSrcBitCast *)instruction);
2348 break;2893 break;
2349 case IrInstructionIdBoolNot:2894 case IrInstSrcIdPtrToInt:
2350 ir_print_bool_not(irp, (IrInstructionBoolNot *)instruction);2895 ir_print_ptr_to_int(irp, (IrInstSrcPtrToInt *)instruction);
2351 break;2896 break;
2352 case IrInstructionIdMemset:2897 case IrInstSrcIdIntToPtr:
2353 ir_print_memset(irp, (IrInstructionMemset *)instruction);2898 ir_print_int_to_ptr(irp, (IrInstSrcIntToPtr *)instruction);
2354 break;2899 break;
2355 case IrInstructionIdMemcpy:2900 case IrInstSrcIdIntToEnum:
2356 ir_print_memcpy(irp, (IrInstructionMemcpy *)instruction);2901 ir_print_int_to_enum(irp, (IrInstSrcIntToEnum *)instruction);
2357 break;2902 break;
2358 case IrInstructionIdSliceSrc:2903 case IrInstSrcIdIntToErr:
2359 ir_print_slice_src(irp, (IrInstructionSliceSrc *)instruction);2904 ir_print_int_to_err(irp, (IrInstSrcIntToErr *)instruction);
2360 break;2905 break;
2361 case IrInstructionIdSliceGen:2906 case IrInstSrcIdErrToInt:
2362 ir_print_slice_gen(irp, (IrInstructionSliceGen *)instruction);2907 ir_print_err_to_int(irp, (IrInstSrcErrToInt *)instruction);
2363 break;2908 break;
2364 case IrInstructionIdMemberCount:2909 case IrInstSrcIdCheckSwitchProngs:
2365 ir_print_member_count(irp, (IrInstructionMemberCount *)instruction);2910 ir_print_check_switch_prongs(irp, (IrInstSrcCheckSwitchProngs *)instruction);
2366 break;2911 break;
2367 case IrInstructionIdMemberType:2912 case IrInstSrcIdCheckStatementIsVoid:
2368 ir_print_member_type(irp, (IrInstructionMemberType *)instruction);2913 ir_print_check_statement_is_void(irp, (IrInstSrcCheckStatementIsVoid *)instruction);
2369 break;2914 break;
2370 case IrInstructionIdMemberName:2915 case IrInstSrcIdTypeName:
2371 ir_print_member_name(irp, (IrInstructionMemberName *)instruction);2916 ir_print_type_name(irp, (IrInstSrcTypeName *)instruction);
2372 break;2917 break;
2373 case IrInstructionIdBreakpoint:2918 case IrInstSrcIdTagName:
2374 ir_print_breakpoint(irp, (IrInstructionBreakpoint *)instruction);2919 ir_print_tag_name(irp, (IrInstSrcTagName *)instruction);
2375 break;2920 break;
2376 case IrInstructionIdReturnAddress:2921 case IrInstSrcIdPtrType:
2377 ir_print_return_address(irp, (IrInstructionReturnAddress *)instruction);2922 ir_print_ptr_type(irp, (IrInstSrcPtrType *)instruction);
2378 break;2923 break;
2379 case IrInstructionIdFrameAddress:2924 case IrInstSrcIdDeclRef:
2380 ir_print_frame_address(irp, (IrInstructionFrameAddress *)instruction);2925 ir_print_decl_ref(irp, (IrInstSrcDeclRef *)instruction);
2381 break;2926 break;
2382 case IrInstructionIdFrameHandle:2927 case IrInstSrcIdPanic:
2383 ir_print_handle(irp, (IrInstructionFrameHandle *)instruction);2928 ir_print_panic(irp, (IrInstSrcPanic *)instruction);
2384 break;2929 break;
2385 case IrInstructionIdFrameType:2930 case IrInstSrcIdFieldParentPtr:
2386 ir_print_frame_type(irp, (IrInstructionFrameType *)instruction);2931 ir_print_field_parent_ptr(irp, (IrInstSrcFieldParentPtr *)instruction);
2387 break;2932 break;
2388 case IrInstructionIdFrameSizeSrc:2933 case IrInstSrcIdByteOffsetOf:
2389 ir_print_frame_size_src(irp, (IrInstructionFrameSizeSrc *)instruction);2934 ir_print_byte_offset_of(irp, (IrInstSrcByteOffsetOf *)instruction);
2390 break;2935 break;
2391 case IrInstructionIdFrameSizeGen:2936 case IrInstSrcIdBitOffsetOf:
2392 ir_print_frame_size_gen(irp, (IrInstructionFrameSizeGen *)instruction);2937 ir_print_bit_offset_of(irp, (IrInstSrcBitOffsetOf *)instruction);
2393 break;2938 break;
2394 case IrInstructionIdAlignOf:2939 case IrInstSrcIdTypeInfo:
2395 ir_print_align_of(irp, (IrInstructionAlignOf *)instruction);2940 ir_print_type_info(irp, (IrInstSrcTypeInfo *)instruction);
2396 break;2941 break;
2397 case IrInstructionIdOverflowOp:2942 case IrInstSrcIdType:
2398 ir_print_overflow_op(irp, (IrInstructionOverflowOp *)instruction);2943 ir_print_type(irp, (IrInstSrcType *)instruction);
2399 break;2944 break;
2400 case IrInstructionIdTestErrSrc:2945 case IrInstSrcIdHasField:
2401 ir_print_test_err_src(irp, (IrInstructionTestErrSrc *)instruction);2946 ir_print_has_field(irp, (IrInstSrcHasField *)instruction);
2402 break;2947 break;
2403 case IrInstructionIdTestErrGen:2948 case IrInstSrcIdTypeId:
2404 ir_print_test_err_gen(irp, (IrInstructionTestErrGen *)instruction);2949 ir_print_type_id(irp, (IrInstSrcTypeId *)instruction);
2405 break;2950 break;
2406 case IrInstructionIdUnwrapErrCode:2951 case IrInstSrcIdSetEvalBranchQuota:
2407 ir_print_unwrap_err_code(irp, (IrInstructionUnwrapErrCode *)instruction);2952 ir_print_set_eval_branch_quota(irp, (IrInstSrcSetEvalBranchQuota *)instruction);
2408 break;2953 break;
2409 case IrInstructionIdUnwrapErrPayload:2954 case IrInstSrcIdAlignCast:
2410 ir_print_unwrap_err_payload(irp, (IrInstructionUnwrapErrPayload *)instruction);2955 ir_print_align_cast(irp, (IrInstSrcAlignCast *)instruction);
2411 break;2956 break;
2412 case IrInstructionIdOptionalWrap:2957 case IrInstSrcIdImplicitCast:
2413 ir_print_optional_wrap(irp, (IrInstructionOptionalWrap *)instruction);2958 ir_print_implicit_cast(irp, (IrInstSrcImplicitCast *)instruction);
2414 break;2959 break;
2415 case IrInstructionIdErrWrapCode:2960 case IrInstSrcIdResolveResult:
2416 ir_print_err_wrap_code(irp, (IrInstructionErrWrapCode *)instruction);2961 ir_print_resolve_result(irp, (IrInstSrcResolveResult *)instruction);
2417 break;2962 break;
2418 case IrInstructionIdErrWrapPayload:2963 case IrInstSrcIdResetResult:
2419 ir_print_err_wrap_payload(irp, (IrInstructionErrWrapPayload *)instruction);2964 ir_print_reset_result(irp, (IrInstSrcResetResult *)instruction);
2420 break;2965 break;
2421 case IrInstructionIdFnProto:2966 case IrInstSrcIdOpaqueType:
2422 ir_print_fn_proto(irp, (IrInstructionFnProto *)instruction);2967 ir_print_opaque_type(irp, (IrInstSrcOpaqueType *)instruction);
2423 break;2968 break;
2424 case IrInstructionIdTestComptime:2969 case IrInstSrcIdSetAlignStack:
2425 ir_print_test_comptime(irp, (IrInstructionTestComptime *)instruction);2970 ir_print_set_align_stack(irp, (IrInstSrcSetAlignStack *)instruction);
2426 break;2971 break;
2427 case IrInstructionIdPtrCastSrc:2972 case IrInstSrcIdArgType:
2428 ir_print_ptr_cast_src(irp, (IrInstructionPtrCastSrc *)instruction);2973 ir_print_arg_type(irp, (IrInstSrcArgType *)instruction);
2429 break;2974 break;
2430 case IrInstructionIdPtrCastGen:2975 case IrInstSrcIdTagType:
2431 ir_print_ptr_cast_gen(irp, (IrInstructionPtrCastGen *)instruction);2976 ir_print_enum_tag_type(irp, (IrInstSrcTagType *)instruction);
2432 break;2977 break;
2433 case IrInstructionIdBitCastSrc:2978 case IrInstSrcIdExport:
2434 ir_print_bit_cast_src(irp, (IrInstructionBitCastSrc *)instruction);2979 ir_print_export(irp, (IrInstSrcExport *)instruction);
2435 break;2980 break;
2436 case IrInstructionIdBitCastGen:2981 case IrInstSrcIdErrorReturnTrace:
2437 ir_print_bit_cast_gen(irp, (IrInstructionBitCastGen *)instruction);2982 ir_print_error_return_trace(irp, (IrInstSrcErrorReturnTrace *)instruction);
2438 break;2983 break;
2439 case IrInstructionIdWidenOrShorten:2984 case IrInstSrcIdErrorUnion:
2440 ir_print_widen_or_shorten(irp, (IrInstructionWidenOrShorten *)instruction);2985 ir_print_error_union(irp, (IrInstSrcErrorUnion *)instruction);
2441 break;2986 break;
2442 case IrInstructionIdPtrToInt:2987 case IrInstSrcIdAtomicRmw:
2443 ir_print_ptr_to_int(irp, (IrInstructionPtrToInt *)instruction);2988 ir_print_atomic_rmw(irp, (IrInstSrcAtomicRmw *)instruction);
2444 break;2989 break;
2445 case IrInstructionIdIntToPtr:2990 case IrInstSrcIdSaveErrRetAddr:
2446 ir_print_int_to_ptr(irp, (IrInstructionIntToPtr *)instruction);2991 ir_print_save_err_ret_addr(irp, (IrInstSrcSaveErrRetAddr *)instruction);
2992 break;
2993 case IrInstSrcIdAddImplicitReturnType:
2994 ir_print_add_implicit_return_type(irp, (IrInstSrcAddImplicitReturnType *)instruction);
2995 break;
2996 case IrInstSrcIdFloatOp:
2997 ir_print_float_op(irp, (IrInstSrcFloatOp *)instruction);
2998 break;
2999 case IrInstSrcIdMulAdd:
3000 ir_print_mul_add(irp, (IrInstSrcMulAdd *)instruction);
3001 break;
3002 case IrInstSrcIdAtomicLoad:
3003 ir_print_atomic_load(irp, (IrInstSrcAtomicLoad *)instruction);
3004 break;
3005 case IrInstSrcIdAtomicStore:
3006 ir_print_atomic_store(irp, (IrInstSrcAtomicStore *)instruction);
3007 break;
3008 case IrInstSrcIdEnumToInt:
3009 ir_print_enum_to_int(irp, (IrInstSrcEnumToInt *)instruction);
3010 break;
3011 case IrInstSrcIdCheckRuntimeScope:
3012 ir_print_check_runtime_scope(irp, (IrInstSrcCheckRuntimeScope *)instruction);
3013 break;
3014 case IrInstSrcIdHasDecl:
3015 ir_print_has_decl(irp, (IrInstSrcHasDecl *)instruction);
3016 break;
3017 case IrInstSrcIdUndeclaredIdent:
3018 ir_print_undeclared_ident(irp, (IrInstSrcUndeclaredIdent *)instruction);
3019 break;
3020 case IrInstSrcIdAlloca:
3021 ir_print_alloca_src(irp, (IrInstSrcAlloca *)instruction);
3022 break;
3023 case IrInstSrcIdEndExpr:
3024 ir_print_end_expr(irp, (IrInstSrcEndExpr *)instruction);
3025 break;
3026 case IrInstSrcIdUnionInitNamedField:
3027 ir_print_union_init_named_field(irp, (IrInstSrcUnionInitNamedField *)instruction);
3028 break;
3029 case IrInstSrcIdSuspendBegin:
3030 ir_print_suspend_begin(irp, (IrInstSrcSuspendBegin *)instruction);
3031 break;
3032 case IrInstSrcIdSuspendFinish:
3033 ir_print_suspend_finish(irp, (IrInstSrcSuspendFinish *)instruction);
3034 break;
3035 case IrInstSrcIdResume:
3036 ir_print_resume(irp, (IrInstSrcResume *)instruction);
3037 break;
3038 case IrInstSrcIdAwait:
3039 ir_print_await_src(irp, (IrInstSrcAwait *)instruction);
3040 break;
3041 case IrInstSrcIdSpillBegin:
3042 ir_print_spill_begin(irp, (IrInstSrcSpillBegin *)instruction);
3043 break;
3044 case IrInstSrcIdSpillEnd:
3045 ir_print_spill_end(irp, (IrInstSrcSpillEnd *)instruction);
3046 break;
3047 case IrInstSrcIdClz:
3048 ir_print_clz(irp, (IrInstSrcClz *)instruction);
3049 break;
3050 }
3051 fprintf(irp->f, "\n");
3052}
3053
3054static void ir_print_inst_gen(IrPrintGen *irp, IrInstGen *instruction, bool trailing) {
3055 ir_print_prefix_gen(irp, instruction, trailing);
3056 switch (instruction->id) {
3057 case IrInstGenIdInvalid:
3058 zig_unreachable();
3059 case IrInstGenIdReturn:
3060 ir_print_return_gen(irp, (IrInstGenReturn *)instruction);
2447 break;3061 break;
2448 case IrInstructionIdIntToEnum:3062 case IrInstGenIdConst:
2449 ir_print_int_to_enum(irp, (IrInstructionIntToEnum *)instruction);3063 ir_print_const(irp, (IrInstGenConst *)instruction);
2450 break;3064 break;
2451 case IrInstructionIdIntToErr:3065 case IrInstGenIdBinOp:
2452 ir_print_int_to_err(irp, (IrInstructionIntToErr *)instruction);3066 ir_print_bin_op(irp, (IrInstGenBinOp *)instruction);
2453 break;3067 break;
2454 case IrInstructionIdErrToInt:3068 case IrInstGenIdDeclVar:
2455 ir_print_err_to_int(irp, (IrInstructionErrToInt *)instruction);3069 ir_print_decl_var_gen(irp, (IrInstGenDeclVar *)instruction);
2456 break;3070 break;
2457 case IrInstructionIdCheckSwitchProngs:3071 case IrInstGenIdCast:
2458 ir_print_check_switch_prongs(irp, (IrInstructionCheckSwitchProngs *)instruction);3072 ir_print_cast(irp, (IrInstGenCast *)instruction);
2459 break;3073 break;
2460 case IrInstructionIdCheckStatementIsVoid:3074 case IrInstGenIdCall:
2461 ir_print_check_statement_is_void(irp, (IrInstructionCheckStatementIsVoid *)instruction);3075 ir_print_call_gen(irp, (IrInstGenCall *)instruction);
2462 break;3076 break;
2463 case IrInstructionIdTypeName:3077 case IrInstGenIdCondBr:
2464 ir_print_type_name(irp, (IrInstructionTypeName *)instruction);3078 ir_print_cond_br(irp, (IrInstGenCondBr *)instruction);
2465 break;3079 break;
2466 case IrInstructionIdTagName:3080 case IrInstGenIdBr:
2467 ir_print_tag_name(irp, (IrInstructionTagName *)instruction);3081 ir_print_br(irp, (IrInstGenBr *)instruction);
2468 break;3082 break;
2469 case IrInstructionIdPtrType:3083 case IrInstGenIdPhi:
2470 ir_print_ptr_type(irp, (IrInstructionPtrType *)instruction);3084 ir_print_phi(irp, (IrInstGenPhi *)instruction);
2471 break;3085 break;
2472 case IrInstructionIdDeclRef:3086 case IrInstGenIdUnreachable:
2473 ir_print_decl_ref(irp, (IrInstructionDeclRef *)instruction);3087 ir_print_unreachable(irp, (IrInstGenUnreachable *)instruction);
2474 break;3088 break;
2475 case IrInstructionIdPanic:3089 case IrInstGenIdElemPtr:
2476 ir_print_panic(irp, (IrInstructionPanic *)instruction);3090 ir_print_elem_ptr(irp, (IrInstGenElemPtr *)instruction);
2477 break;3091 break;
2478 case IrInstructionIdFieldParentPtr:3092 case IrInstGenIdVarPtr:
2479 ir_print_field_parent_ptr(irp, (IrInstructionFieldParentPtr *)instruction);3093 ir_print_var_ptr(irp, (IrInstGenVarPtr *)instruction);
2480 break;3094 break;
2481 case IrInstructionIdByteOffsetOf:3095 case IrInstGenIdReturnPtr:
2482 ir_print_byte_offset_of(irp, (IrInstructionByteOffsetOf *)instruction);3096 ir_print_return_ptr(irp, (IrInstGenReturnPtr *)instruction);
2483 break;3097 break;
2484 case IrInstructionIdBitOffsetOf:3098 case IrInstGenIdLoadPtr:
2485 ir_print_bit_offset_of(irp, (IrInstructionBitOffsetOf *)instruction);3099 ir_print_load_ptr_gen(irp, (IrInstGenLoadPtr *)instruction);
2486 break;3100 break;
2487 case IrInstructionIdTypeInfo:3101 case IrInstGenIdStorePtr:
2488 ir_print_type_info(irp, (IrInstructionTypeInfo *)instruction);3102 ir_print_store_ptr(irp, (IrInstGenStorePtr *)instruction);
2489 break;3103 break;
2490 case IrInstructionIdType:3104 case IrInstGenIdStructFieldPtr:
2491 ir_print_type(irp, (IrInstructionType *)instruction);3105 ir_print_struct_field_ptr(irp, (IrInstGenStructFieldPtr *)instruction);
2492 break;3106 break;
2493 case IrInstructionIdHasField:3107 case IrInstGenIdUnionFieldPtr:
2494 ir_print_has_field(irp, (IrInstructionHasField *)instruction);3108 ir_print_union_field_ptr(irp, (IrInstGenUnionFieldPtr *)instruction);
2495 break;3109 break;
2496 case IrInstructionIdTypeId:3110 case IrInstGenIdAsm:
2497 ir_print_type_id(irp, (IrInstructionTypeId *)instruction);3111 ir_print_asm_gen(irp, (IrInstGenAsm *)instruction);
2498 break;3112 break;
2499 case IrInstructionIdSetEvalBranchQuota:3113 case IrInstGenIdTestNonNull:
2500 ir_print_set_eval_branch_quota(irp, (IrInstructionSetEvalBranchQuota *)instruction);3114 ir_print_test_non_null(irp, (IrInstGenTestNonNull *)instruction);
2501 break;3115 break;
2502 case IrInstructionIdAlignCast:3116 case IrInstGenIdOptionalUnwrapPtr:
2503 ir_print_align_cast(irp, (IrInstructionAlignCast *)instruction);3117 ir_print_optional_unwrap_ptr(irp, (IrInstGenOptionalUnwrapPtr *)instruction);
2504 break;3118 break;
2505 case IrInstructionIdImplicitCast:3119 case IrInstGenIdPopCount:
2506 ir_print_implicit_cast(irp, (IrInstructionImplicitCast *)instruction);3120 ir_print_pop_count(irp, (IrInstGenPopCount *)instruction);
2507 break;3121 break;
2508 case IrInstructionIdResolveResult:3122 case IrInstGenIdClz:
2509 ir_print_resolve_result(irp, (IrInstructionResolveResult *)instruction);3123 ir_print_clz(irp, (IrInstGenClz *)instruction);
2510 break;3124 break;
2511 case IrInstructionIdResetResult:3125 case IrInstGenIdCtz:
2512 ir_print_reset_result(irp, (IrInstructionResetResult *)instruction);3126 ir_print_ctz(irp, (IrInstGenCtz *)instruction);
2513 break;3127 break;
2514 case IrInstructionIdOpaqueType:3128 case IrInstGenIdBswap:
2515 ir_print_opaque_type(irp, (IrInstructionOpaqueType *)instruction);3129 ir_print_bswap(irp, (IrInstGenBswap *)instruction);
2516 break;3130 break;
2517 case IrInstructionIdSetAlignStack:3131 case IrInstGenIdBitReverse:
2518 ir_print_set_align_stack(irp, (IrInstructionSetAlignStack *)instruction);3132 ir_print_bit_reverse(irp, (IrInstGenBitReverse *)instruction);
2519 break;3133 break;
2520 case IrInstructionIdArgType:3134 case IrInstGenIdSwitchBr:
2521 ir_print_arg_type(irp, (IrInstructionArgType *)instruction);3135 ir_print_switch_br(irp, (IrInstGenSwitchBr *)instruction);
2522 break;3136 break;
2523 case IrInstructionIdTagType:3137 case IrInstGenIdUnionTag:
2524 ir_print_enum_tag_type(irp, (IrInstructionTagType *)instruction);3138 ir_print_union_tag(irp, (IrInstGenUnionTag *)instruction);
2525 break;3139 break;
2526 case IrInstructionIdExport:3140 case IrInstGenIdRef:
2527 ir_print_export(irp, (IrInstructionExport *)instruction);3141 ir_print_ref_gen(irp, (IrInstGenRef *)instruction);
2528 break;3142 break;
2529 case IrInstructionIdErrorReturnTrace:3143 case IrInstGenIdErrName:
2530 ir_print_error_return_trace(irp, (IrInstructionErrorReturnTrace *)instruction);3144 ir_print_err_name(irp, (IrInstGenErrName *)instruction);
2531 break;3145 break;
2532 case IrInstructionIdErrorUnion:3146 case IrInstGenIdCmpxchg:
2533 ir_print_error_union(irp, (IrInstructionErrorUnion *)instruction);3147 ir_print_cmpxchg_gen(irp, (IrInstGenCmpxchg *)instruction);
2534 break;3148 break;
2535 case IrInstructionIdAtomicRmw:3149 case IrInstGenIdFence:
2536 ir_print_atomic_rmw(irp, (IrInstructionAtomicRmw *)instruction);3150 ir_print_fence(irp, (IrInstGenFence *)instruction);
2537 break;3151 break;
2538 case IrInstructionIdSaveErrRetAddr:3152 case IrInstGenIdTruncate:
2539 ir_print_save_err_ret_addr(irp, (IrInstructionSaveErrRetAddr *)instruction);3153 ir_print_truncate(irp, (IrInstGenTruncate *)instruction);
2540 break;3154 break;
2541 case IrInstructionIdAddImplicitReturnType:3155 case IrInstGenIdShuffleVector:
2542 ir_print_add_implicit_return_type(irp, (IrInstructionAddImplicitReturnType *)instruction);3156 ir_print_shuffle_vector(irp, (IrInstGenShuffleVector *)instruction);
2543 break;3157 break;
2544 case IrInstructionIdFloatOp:3158 case IrInstGenIdSplat:
2545 ir_print_float_op(irp, (IrInstructionFloatOp *)instruction);3159 ir_print_splat_gen(irp, (IrInstGenSplat *)instruction);
2546 break;3160 break;
2547 case IrInstructionIdMulAdd:3161 case IrInstGenIdBoolNot:
2548 ir_print_mul_add(irp, (IrInstructionMulAdd *)instruction);3162 ir_print_bool_not(irp, (IrInstGenBoolNot *)instruction);
2549 break;3163 break;
2550 case IrInstructionIdAtomicLoad:3164 case IrInstGenIdMemset:
2551 ir_print_atomic_load(irp, (IrInstructionAtomicLoad *)instruction);3165 ir_print_memset(irp, (IrInstGenMemset *)instruction);
2552 break;3166 break;
2553 case IrInstructionIdAtomicStore:3167 case IrInstGenIdMemcpy:
2554 ir_print_atomic_store(irp, (IrInstructionAtomicStore *)instruction);3168 ir_print_memcpy(irp, (IrInstGenMemcpy *)instruction);
2555 break;3169 break;
2556 case IrInstructionIdEnumToInt:3170 case IrInstGenIdSlice:
2557 ir_print_enum_to_int(irp, (IrInstructionEnumToInt *)instruction);3171 ir_print_slice_gen(irp, (IrInstGenSlice *)instruction);
2558 break;3172 break;
2559 case IrInstructionIdCheckRuntimeScope:3173 case IrInstGenIdBreakpoint:
2560 ir_print_check_runtime_scope(irp, (IrInstructionCheckRuntimeScope *)instruction);3174 ir_print_breakpoint(irp, (IrInstGenBreakpoint *)instruction);
2561 break;3175 break;
2562 case IrInstructionIdDeclVarGen:3176 case IrInstGenIdReturnAddress:
2563 ir_print_decl_var_gen(irp, (IrInstructionDeclVarGen *)instruction);3177 ir_print_return_address(irp, (IrInstGenReturnAddress *)instruction);
2564 break;3178 break;
2565 case IrInstructionIdArrayToVector:3179 case IrInstGenIdFrameAddress:
2566 ir_print_array_to_vector(irp, (IrInstructionArrayToVector *)instruction);3180 ir_print_frame_address(irp, (IrInstGenFrameAddress *)instruction);
2567 break;3181 break;
2568 case IrInstructionIdVectorToArray:3182 case IrInstGenIdFrameHandle:
2569 ir_print_vector_to_array(irp, (IrInstructionVectorToArray *)instruction);3183 ir_print_handle(irp, (IrInstGenFrameHandle *)instruction);
2570 break;3184 break;
2571 case IrInstructionIdPtrOfArrayToSlice:3185 case IrInstGenIdFrameSize:
2572 ir_print_ptr_of_array_to_slice(irp, (IrInstructionPtrOfArrayToSlice *)instruction);3186 ir_print_frame_size_gen(irp, (IrInstGenFrameSize *)instruction);
2573 break;3187 break;
2574 case IrInstructionIdAssertZero:3188 case IrInstGenIdOverflowOp:
2575 ir_print_assert_zero(irp, (IrInstructionAssertZero *)instruction);3189 ir_print_overflow_op(irp, (IrInstGenOverflowOp *)instruction);
2576 break;3190 break;
2577 case IrInstructionIdAssertNonNull:3191 case IrInstGenIdTestErr:
2578 ir_print_assert_non_null(irp, (IrInstructionAssertNonNull *)instruction);3192 ir_print_test_err_gen(irp, (IrInstGenTestErr *)instruction);
2579 break;3193 break;
2580 case IrInstructionIdResizeSlice:3194 case IrInstGenIdUnwrapErrCode:
2581 ir_print_resize_slice(irp, (IrInstructionResizeSlice *)instruction);3195 ir_print_unwrap_err_code(irp, (IrInstGenUnwrapErrCode *)instruction);
2582 break;3196 break;
2583 case IrInstructionIdHasDecl:3197 case IrInstGenIdUnwrapErrPayload:
2584 ir_print_has_decl(irp, (IrInstructionHasDecl *)instruction);3198 ir_print_unwrap_err_payload(irp, (IrInstGenUnwrapErrPayload *)instruction);
2585 break;3199 break;
2586 case IrInstructionIdUndeclaredIdent:3200 case IrInstGenIdOptionalWrap:
2587 ir_print_undeclared_ident(irp, (IrInstructionUndeclaredIdent *)instruction);3201 ir_print_optional_wrap(irp, (IrInstGenOptionalWrap *)instruction);
2588 break;3202 break;
2589 case IrInstructionIdAllocaSrc:3203 case IrInstGenIdErrWrapCode:
2590 ir_print_alloca_src(irp, (IrInstructionAllocaSrc *)instruction);3204 ir_print_err_wrap_code(irp, (IrInstGenErrWrapCode *)instruction);
2591 break;3205 break;
2592 case IrInstructionIdAllocaGen:3206 case IrInstGenIdErrWrapPayload:
2593 ir_print_alloca_gen(irp, (IrInstructionAllocaGen *)instruction);3207 ir_print_err_wrap_payload(irp, (IrInstGenErrWrapPayload *)instruction);
2594 break;3208 break;
2595 case IrInstructionIdEndExpr:3209 case IrInstGenIdPtrCast:
2596 ir_print_end_expr(irp, (IrInstructionEndExpr *)instruction);3210 ir_print_ptr_cast_gen(irp, (IrInstGenPtrCast *)instruction);
2597 break;3211 break;
2598 case IrInstructionIdUnionInitNamedField:3212 case IrInstGenIdBitCast:
2599 ir_print_union_init_named_field(irp, (IrInstructionUnionInitNamedField *)instruction);3213 ir_print_bit_cast_gen(irp, (IrInstGenBitCast *)instruction);
2600 break;3214 break;
2601 case IrInstructionIdSuspendBegin:3215 case IrInstGenIdWidenOrShorten:
2602 ir_print_suspend_begin(irp, (IrInstructionSuspendBegin *)instruction);3216 ir_print_widen_or_shorten(irp, (IrInstGenWidenOrShorten *)instruction);
2603 break;3217 break;
2604 case IrInstructionIdSuspendFinish:3218 case IrInstGenIdPtrToInt:
2605 ir_print_suspend_finish(irp, (IrInstructionSuspendFinish *)instruction);3219 ir_print_ptr_to_int(irp, (IrInstGenPtrToInt *)instruction);
2606 break;3220 break;
2607 case IrInstructionIdResume:3221 case IrInstGenIdIntToPtr:
2608 ir_print_resume(irp, (IrInstructionResume *)instruction);3222 ir_print_int_to_ptr(irp, (IrInstGenIntToPtr *)instruction);
2609 break;3223 break;
2610 case IrInstructionIdAwaitSrc:3224 case IrInstGenIdIntToEnum:
2611 ir_print_await_src(irp, (IrInstructionAwaitSrc *)instruction);3225 ir_print_int_to_enum(irp, (IrInstGenIntToEnum *)instruction);
2612 break;3226 break;
2613 case IrInstructionIdAwaitGen:3227 case IrInstGenIdIntToErr:
2614 ir_print_await_gen(irp, (IrInstructionAwaitGen *)instruction);3228 ir_print_int_to_err(irp, (IrInstGenIntToErr *)instruction);
2615 break;3229 break;
2616 case IrInstructionIdSpillBegin:3230 case IrInstGenIdErrToInt:
2617 ir_print_spill_begin(irp, (IrInstructionSpillBegin *)instruction);3231 ir_print_err_to_int(irp, (IrInstGenErrToInt *)instruction);
2618 break;3232 break;
2619 case IrInstructionIdSpillEnd:3233 case IrInstGenIdTagName:
2620 ir_print_spill_end(irp, (IrInstructionSpillEnd *)instruction);3234 ir_print_tag_name(irp, (IrInstGenTagName *)instruction);
2621 break;3235 break;
2622 case IrInstructionIdVectorExtractElem:3236 case IrInstGenIdPanic:
2623 ir_print_vector_extract_elem(irp, (IrInstructionVectorExtractElem *)instruction);3237 ir_print_panic(irp, (IrInstGenPanic *)instruction);
3238 break;
3239 case IrInstGenIdFieldParentPtr:
3240 ir_print_field_parent_ptr(irp, (IrInstGenFieldParentPtr *)instruction);
3241 break;
3242 case IrInstGenIdAlignCast:
3243 ir_print_align_cast(irp, (IrInstGenAlignCast *)instruction);
3244 break;
3245 case IrInstGenIdErrorReturnTrace:
3246 ir_print_error_return_trace(irp, (IrInstGenErrorReturnTrace *)instruction);
3247 break;
3248 case IrInstGenIdAtomicRmw:
3249 ir_print_atomic_rmw(irp, (IrInstGenAtomicRmw *)instruction);
3250 break;
3251 case IrInstGenIdSaveErrRetAddr:
3252 ir_print_save_err_ret_addr(irp, (IrInstGenSaveErrRetAddr *)instruction);
3253 break;
3254 case IrInstGenIdFloatOp:
3255 ir_print_float_op(irp, (IrInstGenFloatOp *)instruction);
3256 break;
3257 case IrInstGenIdMulAdd:
3258 ir_print_mul_add(irp, (IrInstGenMulAdd *)instruction);
3259 break;
3260 case IrInstGenIdAtomicLoad:
3261 ir_print_atomic_load(irp, (IrInstGenAtomicLoad *)instruction);
3262 break;
3263 case IrInstGenIdAtomicStore:
3264 ir_print_atomic_store(irp, (IrInstGenAtomicStore *)instruction);
3265 break;
3266 case IrInstGenIdArrayToVector:
3267 ir_print_array_to_vector(irp, (IrInstGenArrayToVector *)instruction);
3268 break;
3269 case IrInstGenIdVectorToArray:
3270 ir_print_vector_to_array(irp, (IrInstGenVectorToArray *)instruction);
3271 break;
3272 case IrInstGenIdPtrOfArrayToSlice:
3273 ir_print_ptr_of_array_to_slice(irp, (IrInstGenPtrOfArrayToSlice *)instruction);
3274 break;
3275 case IrInstGenIdAssertZero:
3276 ir_print_assert_zero(irp, (IrInstGenAssertZero *)instruction);
3277 break;
3278 case IrInstGenIdAssertNonNull:
3279 ir_print_assert_non_null(irp, (IrInstGenAssertNonNull *)instruction);
3280 break;
3281 case IrInstGenIdResizeSlice:
3282 ir_print_resize_slice(irp, (IrInstGenResizeSlice *)instruction);
3283 break;
3284 case IrInstGenIdAlloca:
3285 ir_print_alloca_gen(irp, (IrInstGenAlloca *)instruction);
3286 break;
3287 case IrInstGenIdSuspendBegin:
3288 ir_print_suspend_begin(irp, (IrInstGenSuspendBegin *)instruction);
3289 break;
3290 case IrInstGenIdSuspendFinish:
3291 ir_print_suspend_finish(irp, (IrInstGenSuspendFinish *)instruction);
3292 break;
3293 case IrInstGenIdResume:
3294 ir_print_resume(irp, (IrInstGenResume *)instruction);
3295 break;
3296 case IrInstGenIdAwait:
3297 ir_print_await_gen(irp, (IrInstGenAwait *)instruction);
3298 break;
3299 case IrInstGenIdSpillBegin:
3300 ir_print_spill_begin(irp, (IrInstGenSpillBegin *)instruction);
3301 break;
3302 case IrInstGenIdSpillEnd:
3303 ir_print_spill_end(irp, (IrInstGenSpillEnd *)instruction);
3304 break;
3305 case IrInstGenIdVectorExtractElem:
3306 ir_print_vector_extract_elem(irp, (IrInstGenVectorExtractElem *)instruction);
3307 break;
3308 case IrInstGenIdVectorStoreElem:
3309 ir_print_vector_store_elem(irp, (IrInstGenVectorStoreElem *)instruction);
3310 break;
3311 case IrInstGenIdBinaryNot:
3312 ir_print_binary_not(irp, (IrInstGenBinaryNot *)instruction);
3313 break;
3314 case IrInstGenIdNegation:
3315 ir_print_negation(irp, (IrInstGenNegation *)instruction);
3316 break;
3317 case IrInstGenIdNegationWrapping:
3318 ir_print_negation_wrapping(irp, (IrInstGenNegationWrapping *)instruction);
2624 break;3319 break;
2625 }3320 }
2626 fprintf(irp->f, "\n");3321 fprintf(irp->f, "\n");
2627}3322}
26283323
2629static void irp_print_basic_block(IrPrint *irp, IrBasicBlock *current_block) {3324static void irp_print_basic_block_src(IrPrintSrc *irp, IrBasicBlockSrc *current_block) {
2630 fprintf(irp->f, "%s_%" ZIG_PRI_usize ":\n", current_block->name_hint, current_block->debug_id);3325 fprintf(irp->f, "%s_%" PRIu32 ":\n", current_block->name_hint, current_block->debug_id);
2631 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {3326 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {
2632 IrInstruction *instruction = current_block->instruction_list.at(instr_i);3327 IrInstSrc *instruction = current_block->instruction_list.at(instr_i);
2633 if (irp->pass != IrPassSrc) {3328 ir_print_inst_src(irp, instruction, false);
2634 irp->printed.put(instruction, 0);3329 }
2635 irp->pending.clear();3330}
2636 }3331
2637 ir_print_instruction(irp, instruction, false);3332static void irp_print_basic_block_gen(IrPrintGen *irp, IrBasicBlockGen *current_block) {
3333 fprintf(irp->f, "%s_%" PRIu32 ":\n", current_block->name_hint, current_block->debug_id);
3334 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {
3335 IrInstGen *instruction = current_block->instruction_list.at(instr_i);
3336 irp->printed.put(instruction, 0);
3337 irp->pending.clear();
3338 ir_print_inst_gen(irp, instruction, false);
2638 for (size_t j = 0; j < irp->pending.length; ++j)3339 for (size_t j = 0; j < irp->pending.length; ++j)
2639 ir_print_instruction(irp, irp->pending.at(j), true);3340 ir_print_inst_gen(irp, irp->pending.at(j), true);
2640 }3341 }
2641}3342}
26423343
2643void ir_print_basic_block(CodeGen *codegen, FILE *f, IrBasicBlock *bb, int indent_size, IrPass pass) {3344void ir_print_basic_block_src(CodeGen *codegen, FILE *f, IrBasicBlockSrc *bb, int indent_size) {
2644 IrPrint ir_print = {};3345 IrPrintSrc ir_print = {};
2645 ir_print.pass = pass;3346 ir_print.codegen = codegen;
3347 ir_print.f = f;
3348 ir_print.indent = indent_size;
3349 ir_print.indent_size = indent_size;
3350
3351 irp_print_basic_block_src(&ir_print, bb);
3352}
3353
3354void ir_print_basic_block_gen(CodeGen *codegen, FILE *f, IrBasicBlockGen *bb, int indent_size) {
3355 IrPrintGen ir_print = {};
2646 ir_print.codegen = codegen;3356 ir_print.codegen = codegen;
2647 ir_print.f = f;3357 ir_print.f = f;
2648 ir_print.indent = indent_size;3358 ir_print.indent = indent_size;
...@@ -2651,16 +3361,28 @@ void ir_print_basic_block(CodeGen *codegen, FILE *f, IrBasicBlock *bb, int inden...@@ -2651,16 +3361,28 @@ void ir_print_basic_block(CodeGen *codegen, FILE *f, IrBasicBlock *bb, int inden
2651 ir_print.printed.init(64);3361 ir_print.printed.init(64);
2652 ir_print.pending = {};3362 ir_print.pending = {};
26533363
2654 irp_print_basic_block(&ir_print, bb);3364 irp_print_basic_block_gen(&ir_print, bb);
26553365
2656 ir_print.pending.deinit();3366 ir_print.pending.deinit();
2657 ir_print.printed.deinit();3367 ir_print.printed.deinit();
2658}3368}
26593369
2660void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass) {3370void ir_print_src(CodeGen *codegen, FILE *f, IrExecutableSrc *executable, int indent_size) {
2661 IrPrint ir_print = {};3371 IrPrintSrc ir_print = {};
2662 IrPrint *irp = &ir_print;3372 IrPrintSrc *irp = &ir_print;
2663 irp->pass = pass;3373 irp->codegen = codegen;
3374 irp->f = f;
3375 irp->indent = indent_size;
3376 irp->indent_size = indent_size;
3377
3378 for (size_t bb_i = 0; bb_i < executable->basic_block_list.length; bb_i += 1) {
3379 irp_print_basic_block_src(irp, executable->basic_block_list.at(bb_i));
3380 }
3381}
3382
3383void ir_print_gen(CodeGen *codegen, FILE *f, IrExecutableGen *executable, int indent_size) {
3384 IrPrintGen ir_print = {};
3385 IrPrintGen *irp = &ir_print;
2664 irp->codegen = codegen;3386 irp->codegen = codegen;
2665 irp->f = f;3387 irp->f = f;
2666 irp->indent = indent_size;3388 irp->indent = indent_size;
...@@ -2670,32 +3392,27 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_si...@@ -2670,32 +3392,27 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_si
2670 irp->pending = {};3392 irp->pending = {};
26713393
2672 for (size_t bb_i = 0; bb_i < executable->basic_block_list.length; bb_i += 1) {3394 for (size_t bb_i = 0; bb_i < executable->basic_block_list.length; bb_i += 1) {
2673 irp_print_basic_block(irp, executable->basic_block_list.at(bb_i));3395 irp_print_basic_block_gen(irp, executable->basic_block_list.at(bb_i));
2674 }3396 }
26753397
2676 irp->pending.deinit();3398 irp->pending.deinit();
2677 irp->printed.deinit();3399 irp->printed.deinit();
2678}3400}
26793401
2680void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass) {3402void ir_print_inst_src(CodeGen *codegen, FILE *f, IrInstSrc *instruction, int indent_size) {
2681 IrPrint ir_print = {};3403 IrPrintSrc ir_print = {};
2682 IrPrint *irp = &ir_print;3404 IrPrintSrc *irp = &ir_print;
2683 irp->pass = pass;
2684 irp->codegen = codegen;3405 irp->codegen = codegen;
2685 irp->f = f;3406 irp->f = f;
2686 irp->indent = indent_size;3407 irp->indent = indent_size;
2687 irp->indent_size = indent_size;3408 irp->indent_size = indent_size;
2688 irp->printed = {};
2689 irp->printed.init(4);
2690 irp->pending = {};
26913409
2692 ir_print_instruction(irp, instruction, false);3410 ir_print_inst_src(irp, instruction, false);
2693}3411}
26943412
2695void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_size, IrPass pass) {3413void ir_print_inst_gen(CodeGen *codegen, FILE *f, IrInstGen *instruction, int indent_size) {
2696 IrPrint ir_print = {};3414 IrPrintGen ir_print = {};
2697 IrPrint *irp = &ir_print;3415 IrPrintGen *irp = &ir_print;
2698 irp->pass = pass;
2699 irp->codegen = codegen;3416 irp->codegen = codegen;
2700 irp->f = f;3417 irp->f = f;
2701 irp->indent = indent_size;3418 irp->indent = indent_size;
...@@ -2704,5 +3421,5 @@ void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_...@@ -2704,5 +3421,5 @@ void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_
2704 irp->printed.init(4);3421 irp->printed.init(4);
2705 irp->pending = {};3422 irp->pending = {};
27063423
2707 ir_print_const_value(irp, value);3424 ir_print_inst_gen(irp, instruction, false);
2708}3425}
src/ir_print.hpp+8-5
...@@ -12,11 +12,14 @@...@@ -12,11 +12,14 @@
1212
13#include <stdio.h>13#include <stdio.h>
1414
15void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass);15void ir_print_src(CodeGen *codegen, FILE *f, IrExecutableSrc *executable, int indent_size);
16void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass);16void ir_print_gen(CodeGen *codegen, FILE *f, IrExecutableGen *executable, int indent_size);
17void ir_print_const_expr(CodeGen *codegen, FILE *f, ZigValue *value, int indent_size, IrPass pass);17void ir_print_inst_src(CodeGen *codegen, FILE *f, IrInstSrc *inst, int indent_size);
18void ir_print_basic_block(CodeGen *codegen, FILE *f, IrBasicBlock *bb, int indent_size, IrPass pass);18void ir_print_inst_gen(CodeGen *codegen, FILE *f, IrInstGen *inst, int indent_size);
19void ir_print_basic_block_src(CodeGen *codegen, FILE *f, IrBasicBlockSrc *bb, int indent_size);
20void ir_print_basic_block_gen(CodeGen *codegen, FILE *f, IrBasicBlockGen *bb, int indent_size);
1921
20const char* ir_instruction_type_str(IrInstructionId id);22const char* ir_inst_src_type_str(IrInstSrcId id);
23const char* ir_inst_gen_type_str(IrInstGenId id);
2124
22#endif25#endif
src/link.cpp+13
...@@ -1502,6 +1502,19 @@ static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path,...@@ -1502,6 +1502,19 @@ static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path,
1502 new_link_lib->provided_explicitly = parent_gen->libc_link_lib->provided_explicitly;1502 new_link_lib->provided_explicitly = parent_gen->libc_link_lib->provided_explicitly;
1503 }1503 }
15041504
1505 // Override the inherited build mode parameter
1506 if (!parent_gen->is_test_build) {
1507 switch (parent_gen->build_mode) {
1508 case BuildModeDebug:
1509 case BuildModeFastRelease:
1510 case BuildModeSafeRelease:
1511 child_gen->build_mode = BuildModeFastRelease;
1512 break;
1513 case BuildModeSmallRelease:
1514 break;
1515 }
1516 }
1517
1505 child_gen->function_sections = true;1518 child_gen->function_sections = true;
1506 child_gen->want_stack_check = WantStackCheckDisabled;1519 child_gen->want_stack_check = WantStackCheckDisabled;
15071520
src/main.cpp+52-91
...@@ -93,6 +93,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {...@@ -93,6 +93,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
93 " --verbose-llvm-ir enable compiler debug output for LLVM IR\n"93 " --verbose-llvm-ir enable compiler debug output for LLVM IR\n"
94 " --verbose-cimport enable compiler debug output for C imports\n"94 " --verbose-cimport enable compiler debug output for C imports\n"
95 " --verbose-cc enable compiler debug output for C compilation\n"95 " --verbose-cc enable compiler debug output for C compilation\n"
96 " --verbose-llvm-cpu-features enable compiler debug output for LLVM CPU features\n"
96 " -dirafter [dir] add directory to AFTER include search path\n"97 " -dirafter [dir] add directory to AFTER include search path\n"
97 " -isystem [dir] add directory to SYSTEM include search path\n"98 " -isystem [dir] add directory to SYSTEM include search path\n"
98 " -I[dir] add directory to include search path\n"99 " -I[dir] add directory to include search path\n"
...@@ -100,6 +101,11 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {...@@ -100,6 +101,11 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
100 " --override-lib-dir [arg] override path to Zig lib directory\n"101 " --override-lib-dir [arg] override path to Zig lib directory\n"
101 " -ffunction-sections places each function in a separate section\n"102 " -ffunction-sections places each function in a separate section\n"
102 " -D[macro]=[value] define C [macro] to [value] (1 if [value] omitted)\n"103 " -D[macro]=[value] define C [macro] to [value] (1 if [value] omitted)\n"
104 " -target-cpu [cpu] target one specific CPU by name\n"
105 " -target-feature [features] specify the set of CPU features to target\n"
106 " -code-model [default|tiny| set target code model\n"
107 " small|kernel|\n"
108 " medium|large]\n"
103 "\n"109 "\n"
104 "Link Options:\n"110 "Link Options:\n"
105 " --bundle-compiler-rt for static libraries, include compiler-rt symbols\n"111 " --bundle-compiler-rt for static libraries, include compiler-rt symbols\n"
...@@ -141,100 +147,18 @@ static int print_libc_usage(const char *arg0, FILE *file, int return_code) {...@@ -141,100 +147,18 @@ static int print_libc_usage(const char *arg0, FILE *file, int return_code) {
141 "You can save this into a file and then edit the paths to create a cross\n"147 "You can save this into a file and then edit the paths to create a cross\n"
142 "compilation libc kit. Then you can pass `--libc [file]` for Zig to use it.\n"148 "compilation libc kit. Then you can pass `--libc [file]` for Zig to use it.\n"
143 "\n"149 "\n"
144 "When compiling natively and no `--libc` argument provided, Zig automatically\n"150 "When compiling natively and no `--libc` argument provided, Zig will create\n"
145 "creates zig-cache/native_libc.txt so that it does not have to detect libc\n"151 "`%s/native_libc.txt`\n"
146 "on every invocation. You can remove this file to have Zig re-detect the\n"152 "so that it does not have to detect libc on every invocation. You can remove\n"
147 "native libc.\n"153 "this file to have Zig re-detect the native libc.\n"
148 "\n\n"154 "\n\n"
149 "Usage: %s libc [file]\n"155 "Usage: %s libc [file]\n"
150 "\n"156 "\n"
151 "Parse a libc installation text file and validate it.\n"157 "Parse a libc installation text file and validate it.\n"
152 , arg0, arg0);158 , arg0, buf_ptr(get_global_cache_dir()), arg0);
153 return return_code;159 return return_code;
154}160}
155161
156static bool arch_available_in_llvm(ZigLLVM_ArchType arch) {
157 LLVMTargetRef target_ref;
158 char *err_msg = nullptr;
159 char triple_string[128];
160 sprintf(triple_string, "%s-unknown-unknown-unknown", ZigLLVMGetArchTypeName(arch));
161 return !LLVMGetTargetFromTriple(triple_string, &target_ref, &err_msg);
162}
163
164static int print_target_list(FILE *f) {
165 ZigTarget native;
166 get_native_target(&native);
167
168 fprintf(f, "Architectures:\n");
169 size_t arch_count = target_arch_count();
170 for (size_t arch_i = 0; arch_i < arch_count; arch_i += 1) {
171 ZigLLVM_ArchType arch = target_arch_enum(arch_i);
172 if (!arch_available_in_llvm(arch))
173 continue;
174 const char *arch_name = target_arch_name(arch);
175 SubArchList sub_arch_list = target_subarch_list(arch);
176 size_t sub_count = target_subarch_count(sub_arch_list);
177 const char *arch_native_str = (native.arch == arch) ? " (native)" : "";
178 fprintf(f, " %s%s\n", arch_name, arch_native_str);
179 for (size_t sub_i = 0; sub_i < sub_count; sub_i += 1) {
180 ZigLLVM_SubArchType sub = target_subarch_enum(sub_arch_list, sub_i);
181 const char *sub_name = target_subarch_name(sub);
182 const char *sub_native_str = (native.arch == arch && native.sub_arch == sub) ? " (native)" : "";
183 fprintf(f, " %s%s\n", sub_name, sub_native_str);
184 }
185 }
186
187 fprintf(f, "\nOperating Systems:\n");
188 size_t os_count = target_os_count();
189 for (size_t i = 0; i < os_count; i += 1) {
190 Os os_type = target_os_enum(i);
191 const char *native_str = (native.os == os_type) ? " (native)" : "";
192 fprintf(f, " %s%s\n", target_os_name(os_type), native_str);
193 }
194
195 fprintf(f, "\nC ABIs:\n");
196 size_t abi_count = target_abi_count();
197 for (size_t i = 0; i < abi_count; i += 1) {
198 ZigLLVM_EnvironmentType abi = target_abi_enum(i);
199 const char *native_str = (native.abi == abi) ? " (native)" : "";
200 fprintf(f, " %s%s\n", target_abi_name(abi), native_str);
201 }
202
203 fprintf(f, "\nAvailable libcs:\n");
204 size_t libc_count = target_libc_count();
205 for (size_t i = 0; i < libc_count; i += 1) {
206 ZigTarget libc_target;
207 target_libc_enum(i, &libc_target);
208 bool is_native = native.arch == libc_target.arch &&
209 native.os == libc_target.os &&
210 native.abi == libc_target.abi;
211 const char *native_str = is_native ? " (native)" : "";
212 fprintf(f, " %s-%s-%s%s\n", target_arch_name(libc_target.arch),
213 target_os_name(libc_target.os), target_abi_name(libc_target.abi), native_str);
214 }
215
216 fprintf(f, "\nAvailable glibc versions:\n");
217 ZigGLibCAbi *glibc_abi;
218 Error err;
219 if ((err = glibc_load_metadata(&glibc_abi, get_zig_lib_dir(), true))) {
220 return EXIT_FAILURE;
221 }
222 for (size_t i = 0; i < glibc_abi->all_versions.length; i += 1) {
223 ZigGLibCVersion *this_ver = &glibc_abi->all_versions.at(i);
224 bool is_native = native.glibc_version != nullptr &&
225 native.glibc_version->major == this_ver->major &&
226 native.glibc_version->minor == this_ver->minor &&
227 native.glibc_version->patch == this_ver->patch;
228 const char *native_str = is_native ? " (native)" : "";
229 if (this_ver->patch == 0) {
230 fprintf(f, " %d.%d%s\n", this_ver->major, this_ver->minor, native_str);
231 } else {
232 fprintf(f, " %d.%d.%d%s\n", this_ver->major, this_ver->minor, this_ver->patch, native_str);
233 }
234 }
235 return EXIT_SUCCESS;
236}
237
238enum Cmd {162enum Cmd {
239 CmdNone,163 CmdNone,
240 CmdBuild,164 CmdBuild,
...@@ -478,6 +402,7 @@ int main(int argc, char **argv) {...@@ -478,6 +402,7 @@ int main(int argc, char **argv) {
478 bool verbose_llvm_ir = false;402 bool verbose_llvm_ir = false;
479 bool verbose_cimport = false;403 bool verbose_cimport = false;
480 bool verbose_cc = false;404 bool verbose_cc = false;
405 bool verbose_llvm_cpu_features = false;
481 bool link_eh_frame_hdr = false;406 bool link_eh_frame_hdr = false;
482 ErrColor color = ErrColorAuto;407 ErrColor color = ErrColorAuto;
483 CacheOpt enable_cache = CacheOptAuto;408 CacheOpt enable_cache = CacheOptAuto;
...@@ -528,6 +453,9 @@ int main(int argc, char **argv) {...@@ -528,6 +453,9 @@ int main(int argc, char **argv) {
528 WantStackCheck want_stack_check = WantStackCheckAuto;453 WantStackCheck want_stack_check = WantStackCheckAuto;
529 WantCSanitize want_sanitize_c = WantCSanitizeAuto;454 WantCSanitize want_sanitize_c = WantCSanitizeAuto;
530 bool function_sections = false;455 bool function_sections = false;
456 const char *cpu = nullptr;
457 const char *features = nullptr;
458 CodeModel code_model = CodeModelDefault;
531459
532 ZigList<const char *> llvm_argv = {0};460 ZigList<const char *> llvm_argv = {0};
533 llvm_argv.append("zig (LLVM option parsing)");461 llvm_argv.append("zig (LLVM option parsing)");
...@@ -692,6 +620,8 @@ int main(int argc, char **argv) {...@@ -692,6 +620,8 @@ int main(int argc, char **argv) {
692 verbose_cimport = true;620 verbose_cimport = true;
693 } else if (strcmp(arg, "--verbose-cc") == 0) {621 } else if (strcmp(arg, "--verbose-cc") == 0) {
694 verbose_cc = true;622 verbose_cc = true;
623 } else if (strcmp(arg, "--verbose-llvm-cpu-features") == 0) {
624 verbose_llvm_cpu_features = true;
695 } else if (strcmp(arg, "-rdynamic") == 0) {625 } else if (strcmp(arg, "-rdynamic") == 0) {
696 rdynamic = true;626 rdynamic = true;
697 } else if (strcmp(arg, "--each-lib-rpath") == 0) {627 } else if (strcmp(arg, "--each-lib-rpath") == 0) {
...@@ -842,6 +772,23 @@ int main(int argc, char **argv) {...@@ -842,6 +772,23 @@ int main(int argc, char **argv) {
842 clang_argv.append(argv[i]);772 clang_argv.append(argv[i]);
843773
844 llvm_argv.append(argv[i]);774 llvm_argv.append(argv[i]);
775 } else if (strcmp(arg, "-code-model") == 0) {
776 if (strcmp(argv[i], "default") == 0) {
777 code_model = CodeModelDefault;
778 } else if (strcmp(argv[i], "tiny") == 0) {
779 code_model = CodeModelTiny;
780 } else if (strcmp(argv[i], "small") == 0) {
781 code_model = CodeModelSmall;
782 } else if (strcmp(argv[i], "kernel") == 0) {
783 code_model = CodeModelKernel;
784 } else if (strcmp(argv[i], "medium") == 0) {
785 code_model = CodeModelMedium;
786 } else if (strcmp(argv[i], "large") == 0) {
787 code_model = CodeModelLarge;
788 } else {
789 fprintf(stderr, "-code-model options are 'default', 'tiny', 'small', 'kernel', 'medium', or 'large'\n");
790 return print_error_usage(arg0);
791 }
845 } else if (strcmp(arg, "--override-lib-dir") == 0) {792 } else if (strcmp(arg, "--override-lib-dir") == 0) {
846 override_lib_dir = buf_create_from_str(argv[i]);793 override_lib_dir = buf_create_from_str(argv[i]);
847 } else if (strcmp(arg, "--main-pkg-path") == 0) {794 } else if (strcmp(arg, "--main-pkg-path") == 0) {
...@@ -936,6 +883,10 @@ int main(int argc, char **argv) {...@@ -936,6 +883,10 @@ int main(int argc, char **argv) {
936 , argv[i]);883 , argv[i]);
937 return EXIT_FAILURE;884 return EXIT_FAILURE;
938 }885 }
886 } else if (strcmp(arg, "-target-cpu") == 0) {
887 cpu = argv[i];
888 } else if (strcmp(arg, "-target-feature") == 0) {
889 features = argv[i];
939 } else {890 } else {
940 fprintf(stderr, "Invalid argument: %s\n", arg);891 fprintf(stderr, "Invalid argument: %s\n", arg);
941 return print_error_usage(arg0);892 return print_error_usage(arg0);
...@@ -1051,15 +1002,22 @@ int main(int argc, char **argv) {...@@ -1051,15 +1002,22 @@ int main(int argc, char **argv) {
1051 }1002 }
1052 }1003 }
10531004
1005 Buf zig_triple_buf = BUF_INIT;
1006 target_triple_zig(&zig_triple_buf, &target);
1007
1008 const char *stage2_triple_arg = target.is_native ? nullptr : buf_ptr(&zig_triple_buf);
1009 if ((err = stage2_cpu_features_parse(&target.cpu_features, stage2_triple_arg, cpu, features))) {
1010 fprintf(stderr, "unable to initialize CPU features: %s\n", err_str(err));
1011 return main_exit(root_progress_node, EXIT_FAILURE);
1012 }
1013
1054 if (output_dir != nullptr && enable_cache == CacheOptOn) {1014 if (output_dir != nullptr && enable_cache == CacheOptOn) {
1055 fprintf(stderr, "`--output-dir` is incompatible with --cache on.\n");1015 fprintf(stderr, "`--output-dir` is incompatible with --cache on.\n");
1056 return print_error_usage(arg0);1016 return print_error_usage(arg0);
1057 }1017 }
10581018
1059 if (target_requires_pic(&target, have_libc) && want_pic == WantPICDisabled) {1019 if (target_requires_pic(&target, have_libc) && want_pic == WantPICDisabled) {
1060 Buf triple_buf = BUF_INIT;1020 fprintf(stderr, "`--disable-pic` is incompatible with target '%s'\n", buf_ptr(&zig_triple_buf));
1061 target_triple_zig(&triple_buf, &target);
1062 fprintf(stderr, "`--disable-pic` is incompatible with target '%s'\n", buf_ptr(&triple_buf));
1063 return print_error_usage(arg0);1021 return print_error_usage(arg0);
1064 }1022 }
10651023
...@@ -1226,12 +1184,15 @@ int main(int argc, char **argv) {...@@ -1226,12 +1184,15 @@ int main(int argc, char **argv) {
1226 g->verbose_llvm_ir = verbose_llvm_ir;1184 g->verbose_llvm_ir = verbose_llvm_ir;
1227 g->verbose_cimport = verbose_cimport;1185 g->verbose_cimport = verbose_cimport;
1228 g->verbose_cc = verbose_cc;1186 g->verbose_cc = verbose_cc;
1187 g->verbose_llvm_cpu_features = verbose_llvm_cpu_features;
1229 g->output_dir = output_dir;1188 g->output_dir = output_dir;
1230 g->disable_gen_h = disable_gen_h;1189 g->disable_gen_h = disable_gen_h;
1231 g->bundle_compiler_rt = bundle_compiler_rt;1190 g->bundle_compiler_rt = bundle_compiler_rt;
1232 codegen_set_errmsg_color(g, color);1191 codegen_set_errmsg_color(g, color);
1233 g->system_linker_hack = system_linker_hack;1192 g->system_linker_hack = system_linker_hack;
1234 g->function_sections = function_sections;1193 g->function_sections = function_sections;
1194 g->code_model = code_model;
1195
12351196
1236 for (size_t i = 0; i < lib_dirs.length; i += 1) {1197 for (size_t i = 0; i < lib_dirs.length; i += 1) {
1237 codegen_add_lib_dir(g, lib_dirs.at(i));1198 codegen_add_lib_dir(g, lib_dirs.at(i));
...@@ -1413,7 +1374,7 @@ int main(int argc, char **argv) {...@@ -1413,7 +1374,7 @@ int main(int argc, char **argv) {
1413 return main_exit(root_progress_node, EXIT_SUCCESS);1374 return main_exit(root_progress_node, EXIT_SUCCESS);
1414 }1375 }
1415 case CmdTargets:1376 case CmdTargets:
1416 return print_target_list(stdout);1377 return stage2_cmd_targets(buf_ptr(&zig_triple_buf));
1417 case CmdNone:1378 case CmdNone:
1418 return print_full_usage(arg0, stderr, EXIT_FAILURE);1379 return print_full_usage(arg0, stderr, EXIT_FAILURE);
1419 }1380 }
src/parser.cpp+1-1
...@@ -147,7 +147,7 @@ static void ast_invalid_token_error(ParseContext *pc, Token *token) {...@@ -147,7 +147,7 @@ static void ast_invalid_token_error(ParseContext *pc, Token *token) {
147}147}
148148
149static AstNode *ast_create_node_no_line_info(ParseContext *pc, NodeType type) {149static AstNode *ast_create_node_no_line_info(ParseContext *pc, NodeType type) {
150 AstNode *node = allocate<AstNode>(1);150 AstNode *node = allocate<AstNode>(1, "AstNode");
151 node->type = type;151 node->type = type;
152 node->owner = pc->owner;152 node->owner = pc->owner;
153 return node;153 return node;
src/softfloat.hpp+17
...@@ -12,4 +12,21 @@ extern "C" {...@@ -12,4 +12,21 @@ extern "C" {
12#include "softfloat.h"12#include "softfloat.h"
13}13}
1414
15static inline float16_t zig_double_to_f16(double x) {
16 float64_t y;
17 static_assert(sizeof(x) == sizeof(y), "");
18 memcpy(&y, &x, sizeof(x));
19 return f64_to_f16(y);
20}
21
22
23// Return value is safe to coerce to float even when |x| is NaN or Infinity.
24static inline double zig_f16_to_double(float16_t x) {
25 float64_t y = f16_to_f64(x);
26 double z;
27 static_assert(sizeof(y) == sizeof(z), "");
28 memcpy(&z, &y, sizeof(y));
29 return z;
30}
31
15#endif32#endif
src/target.cpp+6-9
...@@ -58,9 +58,6 @@ static const ZigLLVM_SubArchType subarch_list_arm64[] = {...@@ -58,9 +58,6 @@ static const ZigLLVM_SubArchType subarch_list_arm64[] = {
58 ZigLLVM_ARMSubArch_v8_2a,58 ZigLLVM_ARMSubArch_v8_2a,
59 ZigLLVM_ARMSubArch_v8_1a,59 ZigLLVM_ARMSubArch_v8_1a,
60 ZigLLVM_ARMSubArch_v8,60 ZigLLVM_ARMSubArch_v8,
61 ZigLLVM_ARMSubArch_v8r,
62 ZigLLVM_ARMSubArch_v8m_baseline,
63 ZigLLVM_ARMSubArch_v8m_mainline,
64};61};
6562
66static const ZigLLVM_SubArchType subarch_list_kalimba[] = {63static const ZigLLVM_SubArchType subarch_list_kalimba[] = {
...@@ -693,7 +690,7 @@ const char *target_subarch_name(ZigLLVM_SubArchType subarch) {...@@ -693,7 +690,7 @@ const char *target_subarch_name(ZigLLVM_SubArchType subarch) {
693 case ZigLLVM_ARMSubArch_v8_1a:690 case ZigLLVM_ARMSubArch_v8_1a:
694 return "v8_1a";691 return "v8_1a";
695 case ZigLLVM_ARMSubArch_v8:692 case ZigLLVM_ARMSubArch_v8:
696 return "v8";693 return "v8a";
697 case ZigLLVM_ARMSubArch_v8r:694 case ZigLLVM_ARMSubArch_v8r:
698 return "v8r";695 return "v8r";
699 case ZigLLVM_ARMSubArch_v8m_baseline:696 case ZigLLVM_ARMSubArch_v8m_baseline:
...@@ -703,7 +700,7 @@ const char *target_subarch_name(ZigLLVM_SubArchType subarch) {...@@ -703,7 +700,7 @@ const char *target_subarch_name(ZigLLVM_SubArchType subarch) {
703 case ZigLLVM_ARMSubArch_v8_1m_mainline:700 case ZigLLVM_ARMSubArch_v8_1m_mainline:
704 return "v8_1m_mainline";701 return "v8_1m_mainline";
705 case ZigLLVM_ARMSubArch_v7:702 case ZigLLVM_ARMSubArch_v7:
706 return "v7";703 return "v7a";
707 case ZigLLVM_ARMSubArch_v7em:704 case ZigLLVM_ARMSubArch_v7em:
708 return "v7em";705 return "v7em";
709 case ZigLLVM_ARMSubArch_v7m:706 case ZigLLVM_ARMSubArch_v7m:
...@@ -846,10 +843,10 @@ void init_all_targets(void) {...@@ -846,10 +843,10 @@ void init_all_targets(void) {
846void target_triple_zig(Buf *triple, const ZigTarget *target) {843void target_triple_zig(Buf *triple, const ZigTarget *target) {
847 buf_resize(triple, 0);844 buf_resize(triple, 0);
848 buf_appendf(triple, "%s%s-%s-%s",845 buf_appendf(triple, "%s%s-%s-%s",
849 ZigLLVMGetArchTypeName(target->arch),846 target_arch_name(target->arch),
850 ZigLLVMGetSubArchTypeName(target->sub_arch),847 target_subarch_name(target->sub_arch),
851 ZigLLVMGetOSTypeName(get_llvm_os_type(target->os)),848 target_os_name(target->os),
852 ZigLLVMGetEnvironmentTypeName(target->abi));849 target_abi_name(target->abi));
853}850}
854851
855void target_triple_llvm(Buf *triple, const ZigTarget *target) {852void target_triple_llvm(Buf *triple, const ZigTarget *target) {
src/target.hpp+1
...@@ -92,6 +92,7 @@ struct ZigTarget {...@@ -92,6 +92,7 @@ struct ZigTarget {
92 Os os;92 Os os;
93 ZigLLVM_EnvironmentType abi;93 ZigLLVM_EnvironmentType abi;
94 ZigGLibCVersion *glibc_version; // null means default94 ZigGLibCVersion *glibc_version; // null means default
95 Stage2CpuFeatures *cpu_features;
95 bool is_native;96 bool is_native;
96};97};
9798
src/userland.cpp+57-1
...@@ -2,7 +2,8 @@...@@ -2,7 +2,8 @@
2// src-self-hosted/stage1.zig2// src-self-hosted/stage1.zig
33
4#include "userland.h"4#include "userland.h"
5#include "ast_render.hpp"5#include "util.hpp"
6#include "zig_llvm.h"
6#include <stdio.h>7#include <stdio.h>
7#include <stdlib.h>8#include <stdlib.h>
8#include <string.h>9#include <string.h>
...@@ -88,3 +89,58 @@ void stage2_progress_end(Stage2ProgressNode *node) {}...@@ -88,3 +89,58 @@ void stage2_progress_end(Stage2ProgressNode *node) {}
88void stage2_progress_complete_one(Stage2ProgressNode *node) {}89void stage2_progress_complete_one(Stage2ProgressNode *node) {}
89void stage2_progress_disable_tty(Stage2Progress *progress) {}90void stage2_progress_disable_tty(Stage2Progress *progress) {}
90void stage2_progress_update_node(Stage2ProgressNode *node, size_t completed_count, size_t estimated_total_items){}91void stage2_progress_update_node(Stage2ProgressNode *node, size_t completed_count, size_t estimated_total_items){}
92
93struct Stage2CpuFeatures {
94 const char *llvm_cpu_name;
95 const char *llvm_cpu_features;
96 const char *builtin_str;
97 const char *cache_hash;
98};
99
100Error stage2_cpu_features_parse(struct Stage2CpuFeatures **out, const char *zig_triple,
101 const char *cpu_name, const char *cpu_features)
102{
103 if (zig_triple == nullptr) {
104 Stage2CpuFeatures *result = allocate<Stage2CpuFeatures>(1, "Stage2CpuFeatures");
105 result->llvm_cpu_name = ZigLLVMGetHostCPUName();
106 result->llvm_cpu_features = ZigLLVMGetNativeFeatures();
107 result->builtin_str = "arch.getBaselineCpuFeatures();\n";
108 result->cache_hash = "native\n\n";
109 *out = result;
110 return ErrorNone;
111 }
112 if (cpu_name == nullptr && cpu_features == nullptr) {
113 Stage2CpuFeatures *result = allocate<Stage2CpuFeatures>(1, "Stage2CpuFeatures");
114 result->builtin_str = "arch.getBaselineCpuFeatures();\n";
115 result->cache_hash = "\n\n";
116 *out = result;
117 return ErrorNone;
118 }
119
120 const char *msg = "stage0 called stage2_cpu_features_parse with non-null cpu name or features";
121 stage2_panic(msg, strlen(msg));
122}
123
124void stage2_cpu_features_get_cache_hash(const Stage2CpuFeatures *cpu_features,
125 const char **ptr, size_t *len)
126{
127 *ptr = cpu_features->cache_hash;
128 *len = strlen(cpu_features->cache_hash);
129}
130const char *stage2_cpu_features_get_llvm_cpu(const Stage2CpuFeatures *cpu_features) {
131 return cpu_features->llvm_cpu_name;
132}
133const char *stage2_cpu_features_get_llvm_features(const Stage2CpuFeatures *cpu_features) {
134 return cpu_features->llvm_cpu_features;
135}
136void stage2_cpu_features_get_builtin_str(const Stage2CpuFeatures *cpu_features,
137 const char **ptr, size_t *len)
138{
139 *ptr = cpu_features->builtin_str;
140 *len = strlen(cpu_features->builtin_str);
141}
142
143int stage2_cmd_targets(const char *zig_triple) {
144 const char *msg = "stage0 called stage2_cmd_targets";
145 stage2_panic(msg, strlen(msg));
146}
src/userland.h+31
...@@ -78,6 +78,12 @@ enum Error {...@@ -78,6 +78,12 @@ enum Error {
78 ErrorNotLazy,78 ErrorNotLazy,
79 ErrorIsAsync,79 ErrorIsAsync,
80 ErrorImportOutsidePkgPath,80 ErrorImportOutsidePkgPath,
81 ErrorUnknownCpu,
82 ErrorUnknownSubArchitecture,
83 ErrorUnknownCpuFeature,
84 ErrorInvalidCpuFeatures,
85 ErrorInvalidLlvmCpuFeaturesFormat,
86 ErrorUnknownApplicationBinaryInterface,
81};87};
8288
83// ABI warning89// ABI warning
...@@ -174,4 +180,29 @@ ZIG_EXTERN_C void stage2_progress_complete_one(Stage2ProgressNode *node);...@@ -174,4 +180,29 @@ ZIG_EXTERN_C void stage2_progress_complete_one(Stage2ProgressNode *node);
174ZIG_EXTERN_C void stage2_progress_update_node(Stage2ProgressNode *node,180ZIG_EXTERN_C void stage2_progress_update_node(Stage2ProgressNode *node,
175 size_t completed_count, size_t estimated_total_items);181 size_t completed_count, size_t estimated_total_items);
176182
183// ABI warning
184struct Stage2CpuFeatures;
185
186// ABI warning
187ZIG_EXTERN_C Error stage2_cpu_features_parse(struct Stage2CpuFeatures **result,
188 const char *zig_triple, const char *cpu_name, const char *cpu_features);
189
190// ABI warning
191ZIG_EXTERN_C const char *stage2_cpu_features_get_llvm_cpu(const struct Stage2CpuFeatures *cpu_features);
192
193// ABI warning
194ZIG_EXTERN_C const char *stage2_cpu_features_get_llvm_features(const struct Stage2CpuFeatures *cpu_features);
195
196// ABI warning
197ZIG_EXTERN_C void stage2_cpu_features_get_builtin_str(const struct Stage2CpuFeatures *cpu_features,
198 const char **ptr, size_t *len);
199
200// ABI warning
201ZIG_EXTERN_C void stage2_cpu_features_get_cache_hash(const struct Stage2CpuFeatures *cpu_features,
202 const char **ptr, size_t *len);
203
204// ABI warning
205ZIG_EXTERN_C int stage2_cmd_targets(const char *zig_triple);
206
207
177#endif208#endif
src/util.hpp+2-19
...@@ -38,6 +38,8 @@...@@ -38,6 +38,8 @@
3838
39#if defined(__MINGW32__) || defined(__MINGW64__)39#if defined(__MINGW32__) || defined(__MINGW64__)
40#define BREAKPOINT __debugbreak()40#define BREAKPOINT __debugbreak()
41#elif defined(__i386__) || defined(__x86_64__)
42#define BREAKPOINT __asm__ volatile("int $0x03");
41#elif defined(__clang__)43#elif defined(__clang__)
42#define BREAKPOINT __builtin_debugtrap()44#define BREAKPOINT __builtin_debugtrap()
43#elif defined(__GNUC__)45#elif defined(__GNUC__)
...@@ -49,8 +51,6 @@...@@ -49,8 +51,6 @@
4951
50#endif52#endif
5153
52#include "softfloat.hpp"
53
54ATTRIBUTE_COLD54ATTRIBUTE_COLD
55ATTRIBUTE_NORETURN55ATTRIBUTE_NORETURN
56ATTRIBUTE_PRINTF(1, 2)56ATTRIBUTE_PRINTF(1, 2)
...@@ -244,23 +244,6 @@ static inline uint8_t log2_u64(uint64_t x) {...@@ -244,23 +244,6 @@ static inline uint8_t log2_u64(uint64_t x) {
244 return (63 - clzll(x));244 return (63 - clzll(x));
245}245}
246246
247static inline float16_t zig_double_to_f16(double x) {
248 float64_t y;
249 static_assert(sizeof(x) == sizeof(y), "");
250 memcpy(&y, &x, sizeof(x));
251 return f64_to_f16(y);
252}
253
254
255// Return value is safe to coerce to float even when |x| is NaN or Infinity.
256static inline double zig_f16_to_double(float16_t x) {
257 float64_t y = f16_to_f64(x);
258 double z;
259 static_assert(sizeof(y) == sizeof(z), "");
260 memcpy(&z, &y, sizeof(y));
261 return z;
262}
263
264void zig_pretty_print_bytes(FILE *f, double n);247void zig_pretty_print_bytes(FILE *f, double n);
265248
266template<typename T>249template<typename T>
src/zig_clang.cpp+9
...@@ -1668,6 +1668,10 @@ unsigned ZigClangFunctionDecl_getAlignedAttribute(const struct ZigClangFunctionD...@@ -1668,6 +1668,10 @@ unsigned ZigClangFunctionDecl_getAlignedAttribute(const struct ZigClangFunctionD
1668 return 0;1668 return 0;
1669}1669}
16701670
1671ZigClangQualType ZigClangParmVarDecl_getOriginalType(const struct ZigClangParmVarDecl *self) {
1672 return bitcast(reinterpret_cast<const clang::ParmVarDecl *>(self)->getOriginalType());
1673}
1674
1671const ZigClangRecordDecl *ZigClangRecordDecl_getDefinition(const ZigClangRecordDecl *zig_record_decl) {1675const ZigClangRecordDecl *ZigClangRecordDecl_getDefinition(const ZigClangRecordDecl *zig_record_decl) {
1672 const clang::RecordDecl *record_decl = reinterpret_cast<const clang::RecordDecl *>(zig_record_decl);1676 const clang::RecordDecl *record_decl = reinterpret_cast<const clang::RecordDecl *>(zig_record_decl);
1673 const clang::RecordDecl *definition = record_decl->getDefinition();1677 const clang::RecordDecl *definition = record_decl->getDefinition();
...@@ -1920,6 +1924,11 @@ bool ZigClangType_isRecordType(const ZigClangType *self) {...@@ -1920,6 +1924,11 @@ bool ZigClangType_isRecordType(const ZigClangType *self) {
1920 return casted->isRecordType();1924 return casted->isRecordType();
1921}1925}
19221926
1927bool ZigClangType_isConstantArrayType(const ZigClangType *self) {
1928 auto casted = reinterpret_cast<const clang::Type *>(self);
1929 return casted->isConstantArrayType();
1930}
1931
1923const char *ZigClangType_getTypeClassName(const ZigClangType *self) {1932const char *ZigClangType_getTypeClassName(const ZigClangType *self) {
1924 auto casted = reinterpret_cast<const clang::Type *>(self);1933 auto casted = reinterpret_cast<const clang::Type *>(self);
1925 return casted->getTypeClassName();1934 return casted->getTypeClassName();
src/zig_clang.h+3
...@@ -886,6 +886,8 @@ ZIG_EXTERN_C const char* ZigClangVarDecl_getSectionAttribute(const struct ZigCla...@@ -886,6 +886,8 @@ ZIG_EXTERN_C const char* ZigClangVarDecl_getSectionAttribute(const struct ZigCla
886ZIG_EXTERN_C unsigned ZigClangVarDecl_getAlignedAttribute(const struct ZigClangVarDecl *self, const ZigClangASTContext* ctx);886ZIG_EXTERN_C unsigned ZigClangVarDecl_getAlignedAttribute(const struct ZigClangVarDecl *self, const ZigClangASTContext* ctx);
887ZIG_EXTERN_C unsigned ZigClangFunctionDecl_getAlignedAttribute(const struct ZigClangFunctionDecl *self, const ZigClangASTContext* ctx);887ZIG_EXTERN_C unsigned ZigClangFunctionDecl_getAlignedAttribute(const struct ZigClangFunctionDecl *self, const ZigClangASTContext* ctx);
888888
889ZIG_EXTERN_C struct ZigClangQualType ZigClangParmVarDecl_getOriginalType(const struct ZigClangParmVarDecl *self);
890
889ZIG_EXTERN_C bool ZigClangRecordDecl_getPackedAttribute(const struct ZigClangRecordDecl *);891ZIG_EXTERN_C bool ZigClangRecordDecl_getPackedAttribute(const struct ZigClangRecordDecl *);
890ZIG_EXTERN_C const struct ZigClangRecordDecl *ZigClangRecordDecl_getDefinition(const struct ZigClangRecordDecl *);892ZIG_EXTERN_C const struct ZigClangRecordDecl *ZigClangRecordDecl_getDefinition(const struct ZigClangRecordDecl *);
891ZIG_EXTERN_C const struct ZigClangEnumDecl *ZigClangEnumDecl_getDefinition(const struct ZigClangEnumDecl *);893ZIG_EXTERN_C const struct ZigClangEnumDecl *ZigClangEnumDecl_getDefinition(const struct ZigClangEnumDecl *);
...@@ -965,6 +967,7 @@ ZIG_EXTERN_C bool ZigClangType_isBooleanType(const struct ZigClangType *self);...@@ -965,6 +967,7 @@ ZIG_EXTERN_C bool ZigClangType_isBooleanType(const struct ZigClangType *self);
965ZIG_EXTERN_C bool ZigClangType_isVoidType(const struct ZigClangType *self);967ZIG_EXTERN_C bool ZigClangType_isVoidType(const struct ZigClangType *self);
966ZIG_EXTERN_C bool ZigClangType_isArrayType(const struct ZigClangType *self);968ZIG_EXTERN_C bool ZigClangType_isArrayType(const struct ZigClangType *self);
967ZIG_EXTERN_C bool ZigClangType_isRecordType(const struct ZigClangType *self);969ZIG_EXTERN_C bool ZigClangType_isRecordType(const struct ZigClangType *self);
970ZIG_EXTERN_C bool ZigClangType_isConstantArrayType(const ZigClangType *self);
968ZIG_EXTERN_C const char *ZigClangType_getTypeClassName(const struct ZigClangType *self);971ZIG_EXTERN_C const char *ZigClangType_getTypeClassName(const struct ZigClangType *self);
969ZIG_EXTERN_C const struct ZigClangArrayType *ZigClangType_getAsArrayTypeUnsafe(const struct ZigClangType *self);972ZIG_EXTERN_C const struct ZigClangArrayType *ZigClangType_getAsArrayTypeUnsafe(const struct ZigClangType *self);
970ZIG_EXTERN_C const ZigClangRecordType *ZigClangType_getAsRecordType(const ZigClangType *self);973ZIG_EXTERN_C const ZigClangRecordType *ZigClangType_getAsRecordType(const ZigClangType *self);
src/zig_llvm.cpp+2-2
...@@ -824,7 +824,7 @@ const char *ZigLLVMGetSubArchTypeName(ZigLLVM_SubArchType sub_arch) {...@@ -824,7 +824,7 @@ const char *ZigLLVMGetSubArchTypeName(ZigLLVM_SubArchType sub_arch) {
824 case ZigLLVM_ARMSubArch_v8_1a:824 case ZigLLVM_ARMSubArch_v8_1a:
825 return "v8.1a";825 return "v8.1a";
826 case ZigLLVM_ARMSubArch_v8:826 case ZigLLVM_ARMSubArch_v8:
827 return "v8";827 return "v8a";
828 case ZigLLVM_ARMSubArch_v8r:828 case ZigLLVM_ARMSubArch_v8r:
829 return "v8r";829 return "v8r";
830 case ZigLLVM_ARMSubArch_v8m_baseline:830 case ZigLLVM_ARMSubArch_v8m_baseline:
...@@ -834,7 +834,7 @@ const char *ZigLLVMGetSubArchTypeName(ZigLLVM_SubArchType sub_arch) {...@@ -834,7 +834,7 @@ const char *ZigLLVMGetSubArchTypeName(ZigLLVM_SubArchType sub_arch) {
834 case ZigLLVM_ARMSubArch_v8_1m_mainline:834 case ZigLLVM_ARMSubArch_v8_1m_mainline:
835 return "v8.1m.main";835 return "v8.1m.main";
836 case ZigLLVM_ARMSubArch_v7:836 case ZigLLVM_ARMSubArch_v7:
837 return "v7";837 return "v7a";
838 case ZigLLVM_ARMSubArch_v7em:838 case ZigLLVM_ARMSubArch_v7em:
839 return "v7em";839 return "v7em";
840 case ZigLLVM_ARMSubArch_v7m:840 case ZigLLVM_ARMSubArch_v7m:
test/compile_errors.zig+19-11
...@@ -1,7 +1,14 @@...@@ -1,7 +1,14 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const Target = @import("std").Target;
34
4pub fn addCases(cases: *tests.CompileErrorContext) void {5pub fn addCases(cases: *tests.CompileErrorContext) void {
6 cases.addTest("dependency loop in top-level decl with @TypeInfo",
7 \\export const foo = @typeInfo(@This());
8 , &[_][]const u8{
9 "tmp.zig:1:20: error: dependency loop detected",
10 });
11
5 cases.addTest("non-exhaustive enums",12 cases.addTest("non-exhaustive enums",
6 \\const A = enum {13 \\const A = enum {
7 \\ a,14 \\ a,
...@@ -272,9 +279,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -272,9 +279,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
272 , &[_][]const u8{279 , &[_][]const u8{
273 "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack",280 "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack",
274 });281 });
275 tc.target = tests.Target{282 tc.target = Target{
276 .Cross = tests.CrossTarget{283 .Cross = .{
277 .arch = .wasm32,284 .arch = .wasm32,
285 .cpu_features = Target.Arch.wasm32.getBaselineCpuFeatures(),
278 .os = .wasi,286 .os = .wasi,
279 .abi = .none,287 .abi = .none,
280 },288 },
...@@ -673,9 +681,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -673,9 +681,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
673 , &[_][]const u8{681 , &[_][]const u8{
674 "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs",682 "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs",
675 });683 });
676 tc.target = tests.Target{684 tc.target = Target{
677 .Cross = tests.CrossTarget{685 .Cross = .{
678 .arch = .x86_64,686 .arch = .x86_64,
687 .cpu_features = Target.Arch.x86_64.getBaselineCpuFeatures(),
679 .os = .linux,688 .os = .linux,
680 .abi = .gnu,689 .abi = .gnu,
681 },690 },
...@@ -1649,7 +1658,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1649,7 +1658,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1649 cases.addTest("return invalid type from test",1658 cases.addTest("return invalid type from test",
1650 \\test "example" { return 1; }1659 \\test "example" { return 1; }
1651 , &[_][]const u8{1660 , &[_][]const u8{
1652 "tmp.zig:1:25: error: integer value 1 cannot be coerced to type 'void'",1661 "tmp.zig:1:25: error: expected type 'void', found 'comptime_int'",
1653 });1662 });
16541663
1655 cases.add("threadlocal qualifier on const",1664 cases.add("threadlocal qualifier on const",
...@@ -2478,7 +2487,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -2478,7 +2487,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
2478 \\ var rule_set = try Foo.init();2487 \\ var rule_set = try Foo.init();
2479 \\}2488 \\}
2480 , &[_][]const u8{2489 , &[_][]const u8{
2481 "tmp.zig:2:10: error: expected type 'i32', found 'type'",2490 "tmp.zig:2:19: error: expected type 'i32', found 'type'",
2482 });2491 });
24832492
2484 cases.add("slicing single-item pointer",2493 cases.add("slicing single-item pointer",
...@@ -3384,7 +3393,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3384,7 +3393,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3384 \\3393 \\
3385 \\fn b() void {}3394 \\fn b() void {}
3386 , &[_][]const u8{3395 , &[_][]const u8{
3387 "tmp.zig:3:6: error: unreachable code",3396 "tmp.zig:3:5: error: unreachable code",
3388 });3397 });
33893398
3390 cases.add("bad import",3399 cases.add("bad import",
...@@ -4002,8 +4011,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4002,8 +4011,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4002 \\4011 \\
4003 \\export fn entry() usize { return @sizeOf(@TypeOf(Foo)); }4012 \\export fn entry() usize { return @sizeOf(@TypeOf(Foo)); }
4004 , &[_][]const u8{4013 , &[_][]const u8{
4005 "tmp.zig:5:25: error: unable to evaluate constant expression",4014 "tmp.zig:5:25: error: cannot store runtime value in compile time variable",
4006 "tmp.zig:2:12: note: referenced here",4015 "tmp.zig:2:12: note: called from here",
4007 });4016 });
40084017
4009 cases.add("addition with non numbers",4018 cases.add("addition with non numbers",
...@@ -4643,7 +4652,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -4643,7 +4652,6 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
4643 \\fn something() anyerror!void { }4652 \\fn something() anyerror!void { }
4644 , &[_][]const u8{4653 , &[_][]const u8{
4645 "tmp.zig:2:5: error: expected type 'void', found 'anyerror'",4654 "tmp.zig:2:5: error: expected type 'void', found 'anyerror'",
4646 "tmp.zig:1:15: note: return type declared here",
4647 });4655 });
46484656
4649 cases.add("invalid pointer for var type",4657 cases.add("invalid pointer for var type",
...@@ -5734,7 +5742,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5734,7 +5742,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5734 \\ @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) });5742 \\ @export(entry, .{.name = "entry", .linkage = @as(u32, 1234) });
5735 \\}5743 \\}
5736 , &[_][]const u8{5744 , &[_][]const u8{
5737 "tmp.zig:3:50: error: expected type 'std.builtin.GlobalLinkage', found 'u32'",5745 "tmp.zig:3:59: error: expected type 'std.builtin.GlobalLinkage', found 'comptime_int'",
5738 });5746 });
57395747
5740 cases.add("struct with invalid field",5748 cases.add("struct with invalid field",
test/stack_traces.zig+98
...@@ -51,11 +51,15 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -51,11 +51,15 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
51 // debug51 // debug
52 \\error: TheSkyIsFalling52 \\error: TheSkyIsFalling
53 \\source.zig:4:5: [address] in main (test)53 \\source.zig:4:5: [address] in main (test)
54 \\ return error.TheSkyIsFalling;
55 \\ ^
54 \\56 \\
55 ,57 ,
56 // release-safe58 // release-safe
57 \\error: TheSkyIsFalling59 \\error: TheSkyIsFalling
58 \\source.zig:4:5: [address] in std.start.main (test)60 \\source.zig:4:5: [address] in std.start.main (test)
61 \\ return error.TheSkyIsFalling;
62 \\ ^
59 \\63 \\
60 ,64 ,
61 // release-fast65 // release-fast
...@@ -74,13 +78,21 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -74,13 +78,21 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
74 // debug78 // debug
75 \\error: TheSkyIsFalling79 \\error: TheSkyIsFalling
76 \\source.zig:4:5: [address] in foo (test)80 \\source.zig:4:5: [address] in foo (test)
81 \\ return error.TheSkyIsFalling;
82 \\ ^
77 \\source.zig:8:5: [address] in main (test)83 \\source.zig:8:5: [address] in main (test)
84 \\ try foo();
85 \\ ^
78 \\86 \\
79 ,87 ,
80 // release-safe88 // release-safe
81 \\error: TheSkyIsFalling89 \\error: TheSkyIsFalling
82 \\source.zig:4:5: [address] in std.start.main (test)90 \\source.zig:4:5: [address] in std.start.main (test)
91 \\ return error.TheSkyIsFalling;
92 \\ ^
83 \\source.zig:8:5: [address] in std.start.main (test)93 \\source.zig:8:5: [address] in std.start.main (test)
94 \\ try foo();
95 \\ ^
84 \\96 \\
85 ,97 ,
86 // release-fast98 // release-fast
...@@ -99,17 +111,33 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -99,17 +111,33 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
99 // debug111 // debug
100 \\error: TheSkyIsFalling112 \\error: TheSkyIsFalling
101 \\source.zig:12:5: [address] in make_error (test)113 \\source.zig:12:5: [address] in make_error (test)
114 \\ return error.TheSkyIsFalling;
115 \\ ^
102 \\source.zig:8:5: [address] in bar (test)116 \\source.zig:8:5: [address] in bar (test)
117 \\ return make_error();
118 \\ ^
103 \\source.zig:4:5: [address] in foo (test)119 \\source.zig:4:5: [address] in foo (test)
120 \\ try bar();
121 \\ ^
104 \\source.zig:16:5: [address] in main (test)122 \\source.zig:16:5: [address] in main (test)
123 \\ try foo();
124 \\ ^
105 \\125 \\
106 ,126 ,
107 // release-safe127 // release-safe
108 \\error: TheSkyIsFalling128 \\error: TheSkyIsFalling
109 \\source.zig:12:5: [address] in std.start.main (test)129 \\source.zig:12:5: [address] in std.start.main (test)
130 \\ return error.TheSkyIsFalling;
131 \\ ^
110 \\source.zig:8:5: [address] in std.start.main (test)132 \\source.zig:8:5: [address] in std.start.main (test)
133 \\ return make_error();
134 \\ ^
111 \\source.zig:4:5: [address] in std.start.main (test)135 \\source.zig:4:5: [address] in std.start.main (test)
136 \\ try bar();
137 \\ ^
112 \\source.zig:16:5: [address] in std.start.main (test)138 \\source.zig:16:5: [address] in std.start.main (test)
139 \\ try foo();
140 \\ ^
113 \\141 \\
114 ,142 ,
115 // release-fast143 // release-fast
...@@ -130,11 +158,15 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -130,11 +158,15 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
130 // debug158 // debug
131 \\error: TheSkyIsFalling159 \\error: TheSkyIsFalling
132 \\source.zig:4:5: [address] in main (test)160 \\source.zig:4:5: [address] in main (test)
161 \\ return error.TheSkyIsFalling;
162 \\ ^
133 \\163 \\
134 ,164 ,
135 // release-safe165 // release-safe
136 \\error: TheSkyIsFalling166 \\error: TheSkyIsFalling
137 \\source.zig:4:5: [address] in std.start.posixCallMainAndExit (test)167 \\source.zig:4:5: [address] in std.start.posixCallMainAndExit (test)
168 \\ return error.TheSkyIsFalling;
169 \\ ^
138 \\170 \\
139 ,171 ,
140 // release-fast172 // release-fast
...@@ -153,13 +185,21 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -153,13 +185,21 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
153 // debug185 // debug
154 \\error: TheSkyIsFalling186 \\error: TheSkyIsFalling
155 \\source.zig:4:5: [address] in foo (test)187 \\source.zig:4:5: [address] in foo (test)
188 \\ return error.TheSkyIsFalling;
189 \\ ^
156 \\source.zig:8:5: [address] in main (test)190 \\source.zig:8:5: [address] in main (test)
191 \\ try foo();
192 \\ ^
157 \\193 \\
158 ,194 ,
159 // release-safe195 // release-safe
160 \\error: TheSkyIsFalling196 \\error: TheSkyIsFalling
161 \\source.zig:4:5: [address] in std.start.posixCallMainAndExit (test)197 \\source.zig:4:5: [address] in std.start.posixCallMainAndExit (test)
198 \\ return error.TheSkyIsFalling;
199 \\ ^
162 \\source.zig:8:5: [address] in std.start.posixCallMainAndExit (test)200 \\source.zig:8:5: [address] in std.start.posixCallMainAndExit (test)
201 \\ try foo();
202 \\ ^
163 \\203 \\
164 ,204 ,
165 // release-fast205 // release-fast
...@@ -178,17 +218,33 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -178,17 +218,33 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
178 // debug218 // debug
179 \\error: TheSkyIsFalling219 \\error: TheSkyIsFalling
180 \\source.zig:12:5: [address] in make_error (test)220 \\source.zig:12:5: [address] in make_error (test)
221 \\ return error.TheSkyIsFalling;
222 \\ ^
181 \\source.zig:8:5: [address] in bar (test)223 \\source.zig:8:5: [address] in bar (test)
224 \\ return make_error();
225 \\ ^
182 \\source.zig:4:5: [address] in foo (test)226 \\source.zig:4:5: [address] in foo (test)
227 \\ try bar();
228 \\ ^
183 \\source.zig:16:5: [address] in main (test)229 \\source.zig:16:5: [address] in main (test)
230 \\ try foo();
231 \\ ^
184 \\232 \\
185 ,233 ,
186 // release-safe234 // release-safe
187 \\error: TheSkyIsFalling235 \\error: TheSkyIsFalling
188 \\source.zig:12:5: [address] in std.start.posixCallMainAndExit (test)236 \\source.zig:12:5: [address] in std.start.posixCallMainAndExit (test)
237 \\ return error.TheSkyIsFalling;
238 \\ ^
189 \\source.zig:8:5: [address] in std.start.posixCallMainAndExit (test)239 \\source.zig:8:5: [address] in std.start.posixCallMainAndExit (test)
240 \\ return make_error();
241 \\ ^
190 \\source.zig:4:5: [address] in std.start.posixCallMainAndExit (test)242 \\source.zig:4:5: [address] in std.start.posixCallMainAndExit (test)
243 \\ try bar();
244 \\ ^
191 \\source.zig:16:5: [address] in std.start.posixCallMainAndExit (test)245 \\source.zig:16:5: [address] in std.start.posixCallMainAndExit (test)
246 \\ try foo();
247 \\ ^
192 \\248 \\
193 ,249 ,
194 // release-fast250 // release-fast
...@@ -209,11 +265,15 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -209,11 +265,15 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
209 // debug265 // debug
210 \\error: TheSkyIsFalling266 \\error: TheSkyIsFalling
211 \\source.zig:4:5: [address] in _main.0 (test.o)267 \\source.zig:4:5: [address] in _main.0 (test.o)
268 \\ return error.TheSkyIsFalling;
269 \\ ^
212 \\270 \\
213 ,271 ,
214 // release-safe272 // release-safe
215 \\error: TheSkyIsFalling273 \\error: TheSkyIsFalling
216 \\source.zig:4:5: [address] in _main (test.o)274 \\source.zig:4:5: [address] in _main (test.o)
275 \\ return error.TheSkyIsFalling;
276 \\ ^
217 \\277 \\
218 ,278 ,
219 // release-fast279 // release-fast
...@@ -232,13 +292,21 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -232,13 +292,21 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
232 // debug292 // debug
233 \\error: TheSkyIsFalling293 \\error: TheSkyIsFalling
234 \\source.zig:4:5: [address] in _foo (test.o)294 \\source.zig:4:5: [address] in _foo (test.o)
295 \\ return error.TheSkyIsFalling;
296 \\ ^
235 \\source.zig:8:5: [address] in _main.0 (test.o)297 \\source.zig:8:5: [address] in _main.0 (test.o)
298 \\ try foo();
299 \\ ^
236 \\300 \\
237 ,301 ,
238 // release-safe302 // release-safe
239 \\error: TheSkyIsFalling303 \\error: TheSkyIsFalling
240 \\source.zig:4:5: [address] in _main (test.o)304 \\source.zig:4:5: [address] in _main (test.o)
305 \\ return error.TheSkyIsFalling;
306 \\ ^
241 \\source.zig:8:5: [address] in _main (test.o)307 \\source.zig:8:5: [address] in _main (test.o)
308 \\ try foo();
309 \\ ^
242 \\310 \\
243 ,311 ,
244 // release-fast312 // release-fast
...@@ -257,17 +325,33 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -257,17 +325,33 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
257 // debug325 // debug
258 \\error: TheSkyIsFalling326 \\error: TheSkyIsFalling
259 \\source.zig:12:5: [address] in _make_error (test.o)327 \\source.zig:12:5: [address] in _make_error (test.o)
328 \\ return error.TheSkyIsFalling;
329 \\ ^
260 \\source.zig:8:5: [address] in _bar (test.o)330 \\source.zig:8:5: [address] in _bar (test.o)
331 \\ return make_error();
332 \\ ^
261 \\source.zig:4:5: [address] in _foo (test.o)333 \\source.zig:4:5: [address] in _foo (test.o)
334 \\ try bar();
335 \\ ^
262 \\source.zig:16:5: [address] in _main.0 (test.o)336 \\source.zig:16:5: [address] in _main.0 (test.o)
337 \\ try foo();
338 \\ ^
263 \\339 \\
264 ,340 ,
265 // release-safe341 // release-safe
266 \\error: TheSkyIsFalling342 \\error: TheSkyIsFalling
267 \\source.zig:12:5: [address] in _main (test.o)343 \\source.zig:12:5: [address] in _main (test.o)
344 \\ return error.TheSkyIsFalling;
345 \\ ^
268 \\source.zig:8:5: [address] in _main (test.o)346 \\source.zig:8:5: [address] in _main (test.o)
347 \\ return make_error();
348 \\ ^
269 \\source.zig:4:5: [address] in _main (test.o)349 \\source.zig:4:5: [address] in _main (test.o)
350 \\ try bar();
351 \\ ^
270 \\source.zig:16:5: [address] in _main (test.o)352 \\source.zig:16:5: [address] in _main (test.o)
353 \\ try foo();
354 \\ ^
271 \\355 \\
272 ,356 ,
273 // release-fast357 // release-fast
...@@ -288,6 +372,8 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -288,6 +372,8 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
288 // debug372 // debug
289 \\error: TheSkyIsFalling373 \\error: TheSkyIsFalling
290 \\source.zig:4:5: [address] in main (test.obj)374 \\source.zig:4:5: [address] in main (test.obj)
375 \\ return error.TheSkyIsFalling;
376 \\ ^
291 \\377 \\
292 ,378 ,
293 // release-safe379 // release-safe
...@@ -309,7 +395,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -309,7 +395,11 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
309 // debug395 // debug
310 \\error: TheSkyIsFalling396 \\error: TheSkyIsFalling
311 \\source.zig:4:5: [address] in foo (test.obj)397 \\source.zig:4:5: [address] in foo (test.obj)
398 \\ return error.TheSkyIsFalling;
399 \\ ^
312 \\source.zig:8:5: [address] in main (test.obj)400 \\source.zig:8:5: [address] in main (test.obj)
401 \\ try foo();
402 \\ ^
313 \\403 \\
314 ,404 ,
315 // release-safe405 // release-safe
...@@ -331,9 +421,17 @@ pub fn addCases(cases: *tests.StackTracesContext) void {...@@ -331,9 +421,17 @@ pub fn addCases(cases: *tests.StackTracesContext) void {
331 // debug421 // debug
332 \\error: TheSkyIsFalling422 \\error: TheSkyIsFalling
333 \\source.zig:12:5: [address] in make_error (test.obj)423 \\source.zig:12:5: [address] in make_error (test.obj)
424 \\ return error.TheSkyIsFalling;
425 \\ ^
334 \\source.zig:8:5: [address] in bar (test.obj)426 \\source.zig:8:5: [address] in bar (test.obj)
427 \\ return make_error();
428 \\ ^
335 \\source.zig:4:5: [address] in foo (test.obj)429 \\source.zig:4:5: [address] in foo (test.obj)
430 \\ try bar();
431 \\ ^
336 \\source.zig:16:5: [address] in main (test.obj)432 \\source.zig:16:5: [address] in main (test.obj)
433 \\ try foo();
434 \\ ^
337 \\435 \\
338 ,436 ,
339 // release-safe437 // release-safe
test/stage1/behavior/async_fn.zig+36
...@@ -1182,6 +1182,42 @@ test "suspend in for loop" {...@@ -1182,6 +1182,42 @@ test "suspend in for loop" {
1182 S.doTheTest();1182 S.doTheTest();
1183}1183}
11841184
1185test "suspend in while loop" {
1186 const S = struct {
1187 var global_frame: ?anyframe = null;
1188
1189 fn doTheTest() void {
1190 _ = async atest();
1191 while (global_frame) |f| resume f;
1192 }
1193
1194 fn atest() void {
1195 expect(optional(6) == 6);
1196 expect(errunion(6) == 6);
1197 }
1198 fn optional(stuff: ?u32) u32 {
1199 global_frame = @frame();
1200 defer global_frame = null;
1201 while (stuff) |val| {
1202 suspend;
1203 return val;
1204 }
1205 return 0;
1206 }
1207 fn errunion(stuff: anyerror!u32) u32 {
1208 global_frame = @frame();
1209 defer global_frame = null;
1210 while (stuff) |val| {
1211 suspend;
1212 return val;
1213 } else |err| {
1214 return 0;
1215 }
1216 }
1217 };
1218 S.doTheTest();
1219}
1220
1185test "correctly spill when returning the error union result of another async fn" {1221test "correctly spill when returning the error union result of another async fn" {
1186 const S = struct {1222 const S = struct {
1187 var global_frame: anyframe = undefined;1223 var global_frame: anyframe = undefined;
test/stage1/behavior/bitcast.zig+20
...@@ -167,3 +167,23 @@ test "nested bitcast" {...@@ -167,3 +167,23 @@ test "nested bitcast" {
167 S.foo(42);167 S.foo(42);
168 comptime S.foo(42);168 comptime S.foo(42);
169}169}
170
171test "bitcast passed as tuple element" {
172 const S = struct {
173 fn foo(args: var) void {
174 comptime expect(@TypeOf(args[0]) == f32);
175 expect(args[0] == 12.34);
176 }
177 };
178 S.foo(.{@bitCast(f32, @as(u32, 0x414570A4))});
179}
180
181test "triple level result location with bitcast sandwich passed as tuple element" {
182 const S = struct {
183 fn foo(args: var) void {
184 comptime expect(@TypeOf(args[0]) == f64);
185 expect(args[0] > 12.33 and args[0] < 12.35);
186 }
187 };
188 S.foo(.{@as(f64, @bitCast(f32, @as(u32, 0x414570A4)))});
189}
test/stage1/behavior/eval.zig+13
...@@ -804,3 +804,16 @@ test "comptime assign int to optional int" {...@@ -804,3 +804,16 @@ test "comptime assign int to optional int" {
804 expectEqual(20, x.?);804 expectEqual(20, x.?);
805 }805 }
806}806}
807
808test "return 0 from function that has u0 return type" {
809 const S = struct {
810 fn foo_zero() u0 {
811 return 0;
812 }
813 };
814 comptime {
815 if (S.foo_zero() != 0) {
816 @compileError("test failed");
817 }
818 }
819}
test/stage1/behavior/floatop.zig+42-12
...@@ -36,7 +36,7 @@ fn testSqrt() void {...@@ -36,7 +36,7 @@ fn testSqrt() void {
36 // expect(@sqrt(a) == 7);36 // expect(@sqrt(a) == 7);
37 //}37 //}
38 {38 {
39 var v: @Vector(4, f32) = [_]f32{1.1, 2.2, 3.3, 4.4};39 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
40 var result = @sqrt(v);40 var result = @sqrt(v);
41 expect(math.approxEq(f32, @sqrt(@as(f32, 1.1)), result[0], epsilon));41 expect(math.approxEq(f32, @sqrt(@as(f32, 1.1)), result[0], epsilon));
42 expect(math.approxEq(f32, @sqrt(@as(f32, 2.2)), result[1], epsilon));42 expect(math.approxEq(f32, @sqrt(@as(f32, 2.2)), result[1], epsilon));
...@@ -86,7 +86,7 @@ fn testSin() void {...@@ -86,7 +86,7 @@ fn testSin() void {
86 expect(@sin(a) == 0);86 expect(@sin(a) == 0);
87 }87 }
88 {88 {
89 var v: @Vector(4, f32) = [_]f32{1.1, 2.2, 3.3, 4.4};89 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
90 var result = @sin(v);90 var result = @sin(v);
91 expect(math.approxEq(f32, @sin(@as(f32, 1.1)), result[0], epsilon));91 expect(math.approxEq(f32, @sin(@as(f32, 1.1)), result[0], epsilon));
92 expect(math.approxEq(f32, @sin(@as(f32, 2.2)), result[1], epsilon));92 expect(math.approxEq(f32, @sin(@as(f32, 2.2)), result[1], epsilon));
...@@ -116,7 +116,7 @@ fn testCos() void {...@@ -116,7 +116,7 @@ fn testCos() void {
116 expect(@cos(a) == 1);116 expect(@cos(a) == 1);
117 }117 }
118 {118 {
119 var v: @Vector(4, f32) = [_]f32{1.1, 2.2, 3.3, 4.4};119 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 3.3, 4.4 };
120 var result = @cos(v);120 var result = @cos(v);
121 expect(math.approxEq(f32, @cos(@as(f32, 1.1)), result[0], epsilon));121 expect(math.approxEq(f32, @cos(@as(f32, 1.1)), result[0], epsilon));
122 expect(math.approxEq(f32, @cos(@as(f32, 2.2)), result[1], epsilon));122 expect(math.approxEq(f32, @cos(@as(f32, 2.2)), result[1], epsilon));
...@@ -146,7 +146,7 @@ fn testExp() void {...@@ -146,7 +146,7 @@ fn testExp() void {
146 expect(@exp(a) == 1);146 expect(@exp(a) == 1);
147 }147 }
148 {148 {
149 var v: @Vector(4, f32) = [_]f32{1.1, 2.2, 0.3, 0.4};149 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
150 var result = @exp(v);150 var result = @exp(v);
151 expect(math.approxEq(f32, @exp(@as(f32, 1.1)), result[0], epsilon));151 expect(math.approxEq(f32, @exp(@as(f32, 1.1)), result[0], epsilon));
152 expect(math.approxEq(f32, @exp(@as(f32, 2.2)), result[1], epsilon));152 expect(math.approxEq(f32, @exp(@as(f32, 2.2)), result[1], epsilon));
...@@ -176,7 +176,7 @@ fn testExp2() void {...@@ -176,7 +176,7 @@ fn testExp2() void {
176 expect(@exp2(a) == 4);176 expect(@exp2(a) == 4);
177 }177 }
178 {178 {
179 var v: @Vector(4, f32) = [_]f32{1.1, 2.2, 0.3, 0.4};179 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
180 var result = @exp2(v);180 var result = @exp2(v);
181 expect(math.approxEq(f32, @exp2(@as(f32, 1.1)), result[0], epsilon));181 expect(math.approxEq(f32, @exp2(@as(f32, 1.1)), result[0], epsilon));
182 expect(math.approxEq(f32, @exp2(@as(f32, 2.2)), result[1], epsilon));182 expect(math.approxEq(f32, @exp2(@as(f32, 2.2)), result[1], epsilon));
...@@ -208,7 +208,7 @@ fn testLog() void {...@@ -208,7 +208,7 @@ fn testLog() void {
208 expect(@log(a) == 1 or @log(a) == @bitCast(f64, @as(u64, 0x3ff0000000000000)));208 expect(@log(a) == 1 or @log(a) == @bitCast(f64, @as(u64, 0x3ff0000000000000)));
209 }209 }
210 {210 {
211 var v: @Vector(4, f32) = [_]f32{1.1, 2.2, 0.3, 0.4};211 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
212 var result = @log(v);212 var result = @log(v);
213 expect(math.approxEq(f32, @log(@as(f32, 1.1)), result[0], epsilon));213 expect(math.approxEq(f32, @log(@as(f32, 1.1)), result[0], epsilon));
214 expect(math.approxEq(f32, @log(@as(f32, 2.2)), result[1], epsilon));214 expect(math.approxEq(f32, @log(@as(f32, 2.2)), result[1], epsilon));
...@@ -238,7 +238,7 @@ fn testLog2() void {...@@ -238,7 +238,7 @@ fn testLog2() void {
238 expect(@log2(a) == 2);238 expect(@log2(a) == 2);
239 }239 }
240 {240 {
241 var v: @Vector(4, f32) = [_]f32{1.1, 2.2, 0.3, 0.4};241 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
242 var result = @log2(v);242 var result = @log2(v);
243 expect(math.approxEq(f32, @log2(@as(f32, 1.1)), result[0], epsilon));243 expect(math.approxEq(f32, @log2(@as(f32, 1.1)), result[0], epsilon));
244 expect(math.approxEq(f32, @log2(@as(f32, 2.2)), result[1], epsilon));244 expect(math.approxEq(f32, @log2(@as(f32, 2.2)), result[1], epsilon));
...@@ -268,7 +268,7 @@ fn testLog10() void {...@@ -268,7 +268,7 @@ fn testLog10() void {
268 expect(@log10(a) == 3);268 expect(@log10(a) == 3);
269 }269 }
270 {270 {
271 var v: @Vector(4, f32) = [_]f32{1.1, 2.2, 0.3, 0.4};271 var v: @Vector(4, f32) = [_]f32{ 1.1, 2.2, 0.3, 0.4 };
272 var result = @log10(v);272 var result = @log10(v);
273 expect(math.approxEq(f32, @log10(@as(f32, 1.1)), result[0], epsilon));273 expect(math.approxEq(f32, @log10(@as(f32, 1.1)), result[0], epsilon));
274 expect(math.approxEq(f32, @log10(@as(f32, 2.2)), result[1], epsilon));274 expect(math.approxEq(f32, @log10(@as(f32, 2.2)), result[1], epsilon));
...@@ -304,7 +304,7 @@ fn testFabs() void {...@@ -304,7 +304,7 @@ fn testFabs() void {
304 expect(@fabs(b) == 2.5);304 expect(@fabs(b) == 2.5);
305 }305 }
306 {306 {
307 var v: @Vector(4, f32) = [_]f32{1.1, -2.2, 0.3, -0.4};307 var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
308 var result = @fabs(v);308 var result = @fabs(v);
309 expect(math.approxEq(f32, @fabs(@as(f32, 1.1)), result[0], epsilon));309 expect(math.approxEq(f32, @fabs(@as(f32, 1.1)), result[0], epsilon));
310 expect(math.approxEq(f32, @fabs(@as(f32, -2.2)), result[1], epsilon));310 expect(math.approxEq(f32, @fabs(@as(f32, -2.2)), result[1], epsilon));
...@@ -334,7 +334,7 @@ fn testFloor() void {...@@ -334,7 +334,7 @@ fn testFloor() void {
334 expect(@floor(a) == 3);334 expect(@floor(a) == 3);
335 }335 }
336 {336 {
337 var v: @Vector(4, f32) = [_]f32{1.1, -2.2, 0.3, -0.4};337 var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
338 var result = @floor(v);338 var result = @floor(v);
339 expect(math.approxEq(f32, @floor(@as(f32, 1.1)), result[0], epsilon));339 expect(math.approxEq(f32, @floor(@as(f32, 1.1)), result[0], epsilon));
340 expect(math.approxEq(f32, @floor(@as(f32, -2.2)), result[1], epsilon));340 expect(math.approxEq(f32, @floor(@as(f32, -2.2)), result[1], epsilon));
...@@ -364,7 +364,7 @@ fn testCeil() void {...@@ -364,7 +364,7 @@ fn testCeil() void {
364 expect(@ceil(a) == 4);364 expect(@ceil(a) == 4);
365 }365 }
366 {366 {
367 var v: @Vector(4, f32) = [_]f32{1.1, -2.2, 0.3, -0.4};367 var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
368 var result = @ceil(v);368 var result = @ceil(v);
369 expect(math.approxEq(f32, @ceil(@as(f32, 1.1)), result[0], epsilon));369 expect(math.approxEq(f32, @ceil(@as(f32, 1.1)), result[0], epsilon));
370 expect(math.approxEq(f32, @ceil(@as(f32, -2.2)), result[1], epsilon));370 expect(math.approxEq(f32, @ceil(@as(f32, -2.2)), result[1], epsilon));
...@@ -394,7 +394,7 @@ fn testTrunc() void {...@@ -394,7 +394,7 @@ fn testTrunc() void {
394 expect(@trunc(a) == -3);394 expect(@trunc(a) == -3);
395 }395 }
396 {396 {
397 var v: @Vector(4, f32) = [_]f32{1.1, -2.2, 0.3, -0.4};397 var v: @Vector(4, f32) = [_]f32{ 1.1, -2.2, 0.3, -0.4 };
398 var result = @trunc(v);398 var result = @trunc(v);
399 expect(math.approxEq(f32, @trunc(@as(f32, 1.1)), result[0], epsilon));399 expect(math.approxEq(f32, @trunc(@as(f32, 1.1)), result[0], epsilon));
400 expect(math.approxEq(f32, @trunc(@as(f32, -2.2)), result[1], epsilon));400 expect(math.approxEq(f32, @trunc(@as(f32, -2.2)), result[1], epsilon));
...@@ -403,6 +403,36 @@ fn testTrunc() void {...@@ -403,6 +403,36 @@ fn testTrunc() void {
403 }403 }
404}404}
405405
406test "floating point comparisons" {
407 testFloatComparisons();
408 comptime testFloatComparisons();
409}
410
411fn testFloatComparisons() void {
412 inline for ([_]type{ f16, f32, f64, f128 }) |ty| {
413 // No decimal part
414 {
415 const x: ty = 1.0;
416 expect(x == 1);
417 expect(x != 0);
418 expect(x > 0);
419 expect(x < 2);
420 expect(x >= 1);
421 expect(x <= 1);
422 }
423 // Non-zero decimal part
424 {
425 const x: ty = 1.5;
426 expect(x != 1);
427 expect(x != 2);
428 expect(x > 1);
429 expect(x < 2);
430 expect(x >= 1);
431 expect(x <= 2);
432 }
433 }
434}
435
406// TODO This is waiting on library support for the Windows build (not sure why the other's don't need it)436// TODO This is waiting on library support for the Windows build (not sure why the other's don't need it)
407//test "@nearbyint" {437//test "@nearbyint" {
408// comptime testNearbyInt();438// comptime testNearbyInt();
test/stage1/behavior/if.zig+1-1
...@@ -72,7 +72,7 @@ test "const result loc, runtime if cond, else unreachable" {...@@ -72,7 +72,7 @@ test "const result loc, runtime if cond, else unreachable" {
7272
73 var t = true;73 var t = true;
74 const x = if (t) Num.Two else unreachable;74 const x = if (t) Num.Two else unreachable;
75 if (x != .Two) @compileError("bad");75 expect(x == .Two);
76}76}
7777
78test "if prongs cast to expected type instead of peer type resolution" {78test "if prongs cast to expected type instead of peer type resolution" {
test/stage1/behavior/math.zig+8
...@@ -529,6 +529,10 @@ test "comptime_int xor" {...@@ -529,6 +529,10 @@ test "comptime_int xor" {
529}529}
530530
531test "f128" {531test "f128" {
532 if (std.Target.current.isWindows()) {
533 // TODO https://github.com/ziglang/zig/issues/508
534 return error.SkipZigTest;
535 }
532 test_f128();536 test_f128();
533 comptime test_f128();537 comptime test_f128();
534}538}
...@@ -627,6 +631,10 @@ test "NaN comparison" {...@@ -627,6 +631,10 @@ test "NaN comparison" {
627 // TODO: https://github.com/ziglang/zig/issues/3338631 // TODO: https://github.com/ziglang/zig/issues/3338
628 return error.SkipZigTest;632 return error.SkipZigTest;
629 }633 }
634 if (std.Target.current.isWindows()) {
635 // TODO https://github.com/ziglang/zig/issues/508
636 return error.SkipZigTest;
637 }
630 testNanEqNan(f16);638 testNanEqNan(f16);
631 testNanEqNan(f32);639 testNanEqNan(f32);
632 testNanEqNan(f64);640 testNanEqNan(f64);
test/stage1/behavior/misc.zig+13
...@@ -781,3 +781,16 @@ test "pointer to thread local array" {...@@ -781,3 +781,16 @@ test "pointer to thread local array" {
781 std.mem.copy(u8, buffer[0..], s);781 std.mem.copy(u8, buffer[0..], s);
782 std.testing.expectEqualSlices(u8, buffer[0..], s);782 std.testing.expectEqualSlices(u8, buffer[0..], s);
783}783}
784
785test "auto created variables have correct alignment" {
786 const S = struct {
787 fn foo(str: [*]const u8) u32 {
788 for (@ptrCast([*]align(1) const u32, str)[0..1]) |v| {
789 return v;
790 }
791 return 0;
792 }
793 };
794 expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
795 comptime expect(S.foo("\x7a\x7a\x7a\x7a") == 0x7a7a7a7a);
796}
test/stage1/behavior/optional.zig+22
...@@ -153,3 +153,25 @@ test "optional with void type" {...@@ -153,3 +153,25 @@ test "optional with void type" {
153 var x = Foo{ .x = null };153 var x = Foo{ .x = null };
154 expect(x.x == null);154 expect(x.x == null);
155}155}
156
157test "0-bit child type coerced to optional return ptr result location" {
158 const S = struct {
159 fn doTheTest() void {
160 var y = Foo{};
161 var z = y.thing();
162 expect(z != null);
163 }
164
165 const Foo = struct {
166 pub const Bar = struct {
167 field: *Foo,
168 };
169
170 pub fn thing(self: *Foo) ?Bar {
171 return Bar{ .field = self };
172 }
173 };
174 };
175 S.doTheTest();
176 comptime S.doTheTest();
177}
test/stage1/behavior/switch.zig+14
...@@ -479,3 +479,17 @@ test "switch on pointer type" {...@@ -479,3 +479,17 @@ test "switch on pointer type" {
479 comptime expect(2 == S.doTheTest(S.P2));479 comptime expect(2 == S.doTheTest(S.P2));
480 comptime expect(3 == S.doTheTest(S.P3));480 comptime expect(3 == S.doTheTest(S.P3));
481}481}
482
483test "switch on error set with single else" {
484 const S = struct {
485 fn doTheTest() void {
486 var some: error{Foo} = error.Foo;
487 expect(switch (some) {
488 else => |a| true,
489 });
490 }
491 };
492
493 S.doTheTest();
494 comptime S.doTheTest();
495}
test/stage1/behavior/undefined.zig+3-2
...@@ -1,5 +1,6 @@...@@ -1,5 +1,6 @@
1const expect = @import("std").testing.expect;1const std = @import("std");
2const mem = @import("std").mem;2const expect = std.testing.expect;
3const mem = std.mem;
34
4fn initStaticArray() [10]i32 {5fn initStaticArray() [10]i32 {
5 var array: [10]i32 = undefined;6 var array: [10]i32 = undefined;
test/tests.zig+223-196
...@@ -38,236 +38,260 @@ const TestTarget = struct {...@@ -38,236 +38,260 @@ const TestTarget = struct {
38 disable_native: bool = false,38 disable_native: bool = false,
39};39};
4040
41const test_targets = [_]TestTarget{41const test_targets = blk: {
42 TestTarget{},42 // getBaselineCpuFeatures calls populateDependencies which has a O(N ^ 2) algorithm
43 TestTarget{43 // (where N is roughly 160, which technically makes it O(1), but it adds up to a
44 .link_libc = true,44 // lot of branches)
45 },45 @setEvalBranchQuota(50000);
46 TestTarget{46 break :blk [_]TestTarget{
47 .single_threaded = true,47 TestTarget{},
48 },48 TestTarget{
4949 .link_libc = true,
50 TestTarget{50 },
51 .target = Target{51 TestTarget{
52 .Cross = CrossTarget{52 .single_threaded = true,
53 .os = .linux,53 },
54 .arch = .x86_64,54
55 .abi = .none,55 TestTarget{
56 .target = Target{
57 .Cross = CrossTarget{
58 .os = .linux,
59 .arch = .x86_64,
60 .abi = .none,
61 .cpu_features = Target.Arch.x86_64.getBaselineCpuFeatures(),
62 },
56 },63 },
57 },64 },
58 },65 TestTarget{
59 TestTarget{66 .target = Target{
60 .target = Target{67 .Cross = CrossTarget{
61 .Cross = CrossTarget{68 .os = .linux,
62 .os = .linux,69 .arch = .x86_64,
63 .arch = .x86_64,70 .abi = .gnu,
64 .abi = .gnu,71 .cpu_features = Target.Arch.x86_64.getBaselineCpuFeatures(),
72 },
65 },73 },
74 .link_libc = true,
66 },75 },
67 .link_libc = true,76 TestTarget{
68 },77 .target = Target{
69 TestTarget{78 .Cross = CrossTarget{
70 .target = Target{79 .os = .linux,
71 .Cross = CrossTarget{80 .arch = .x86_64,
72 .os = .linux,81 .cpu_features = Target.Arch.x86_64.getBaselineCpuFeatures(),
73 .arch = .x86_64,82 .abi = .musl,
74 .abi = .musl,83 },
75 },84 },
85 .link_libc = true,
76 },86 },
77 .link_libc = true,87
78 },88 TestTarget{
7989 .target = Target{
80 TestTarget{90 .Cross = CrossTarget{
81 .target = Target{91 .os = .linux,
82 .Cross = CrossTarget{92 .arch = .i386,
83 .os = .linux,93 .cpu_features = Target.Arch.i386.getBaselineCpuFeatures(),
84 .arch = .i386,94 .abi = .none,
85 .abi = .none,95 },
86 },96 },
87 },97 },
88 },98 TestTarget{
89 TestTarget{99 .target = Target{
90 .target = Target{100 .Cross = CrossTarget{
91 .Cross = CrossTarget{101 .os = .linux,
92 .os = .linux,102 .arch = .i386,
93 .arch = .i386,103 .cpu_features = Target.Arch.i386.getBaselineCpuFeatures(),
94 .abi = .musl,104 .abi = .musl,
105 },
95 },106 },
107 .link_libc = true,
96 },108 },
97 .link_libc = true,109
98 },110 TestTarget{
99111 .target = Target{
100 TestTarget{112 .Cross = CrossTarget{
101 .target = Target{113 .os = .linux,
102 .Cross = CrossTarget{114 .arch = Target.Arch{ .aarch64 = .v8a },
103 .os = .linux,115 .cpu_features = (Target.Arch{ .aarch64 = .v8a }).getBaselineCpuFeatures(),
104 .arch = builtin.Arch{ .aarch64 = builtin.Arch.Arm64.v8_5a },116 .abi = .none,
105 .abi = .none,117 },
106 },118 },
107 },119 },
108 },120 TestTarget{
109 TestTarget{121 .target = Target{
110 .target = Target{122 .Cross = CrossTarget{
111 .Cross = CrossTarget{123 .os = .linux,
112 .os = .linux,124 .arch = Target.Arch{ .aarch64 = .v8a },
113 .arch = builtin.Arch{ .aarch64 = builtin.Arch.Arm64.v8_5a },125 .cpu_features = (Target.Arch{ .aarch64 = .v8a }).getBaselineCpuFeatures(),
114 .abi = .musl,126 .abi = .musl,
127 },
115 },128 },
129 .link_libc = true,
116 },130 },
117 .link_libc = true,131 TestTarget{
118 },132 .target = Target{
119 TestTarget{133 .Cross = CrossTarget{
120 .target = Target{134 .os = .linux,
121 .Cross = CrossTarget{135 .arch = Target.Arch{ .aarch64 = .v8a },
122 .os = .linux,136 .cpu_features = (Target.Arch{ .aarch64 = .v8a }).getBaselineCpuFeatures(),
123 .arch = builtin.Arch{ .aarch64 = builtin.Arch.Arm64.v8_5a },137 .abi = .gnu,
124 .abi = .gnu,138 },
125 },139 },
140 .link_libc = true,
126 },141 },
127 .link_libc = true,142
128 },143 TestTarget{
129144 .target = Target{
130 TestTarget{145 .Cross = CrossTarget{
131 .target = Target{146 .os = .linux,
132 .Cross = CrossTarget{147 .arch = Target.Arch{ .arm = .v8a },
133 .os = .linux,148 .cpu_features = (Target.Arch{ .arm = .v8a }).getBaselineCpuFeatures(),
134 .arch = builtin.Arch{ .arm = builtin.Arch.Arm32.v8_5a },149 .abi = .none,
135 .abi = .none,150 },
136 },151 },
137 },152 },
138 },153 TestTarget{
139 TestTarget{154 .target = Target{
140 .target = Target{155 .Cross = CrossTarget{
141 .Cross = CrossTarget{156 .os = .linux,
142 .os = .linux,157 .arch = Target.Arch{ .arm = .v8a },
143 .arch = builtin.Arch{ .arm = builtin.Arch.Arm32.v8_5a },158 .cpu_features = (Target.Arch{ .arm = .v8a }).getBaselineCpuFeatures(),
144 .abi = .musleabihf,159 .abi = .musleabihf,
160 },
145 },161 },
162 .link_libc = true,
146 },163 },
147 .link_libc = true,164 // TODO https://github.com/ziglang/zig/issues/3287
148 },165 //TestTarget{
149 // TODO https://github.com/ziglang/zig/issues/3287166 // .target = Target{
150 //TestTarget{167 // .Cross = CrossTarget{
151 // .target = Target{168 // .os = .linux,
152 // .Cross = CrossTarget{169 // .arch = Target.Arch{ .arm = .v8a },
153 // .os = .linux,170 // .cpu_features = (Target.Arch{ .arm = .v8a }).getBaselineCpuFeatures(),
154 // .arch = builtin.Arch{ .arm = builtin.Arch.Arm32.v8_5a },171 // .abi = .gnueabihf,
155 // .abi = .gnueabihf,172 // },
156 // },173 // },
157 // },174 // .link_libc = true,
158 // .link_libc = true,175 //},
159 //},176
160177 TestTarget{
161 TestTarget{178 .target = Target{
162 .target = Target{179 .Cross = CrossTarget{
163 .Cross = CrossTarget{180 .os = .linux,
164 .os = .linux,181 .arch = .mipsel,
165 .arch = .mipsel,182 .cpu_features = Target.Arch.mipsel.getBaselineCpuFeatures(),
166 .abi = .none,183 .abi = .none,
184 },
167 },185 },
168 },186 },
169 },187 TestTarget{
170 TestTarget{188 .target = Target{
171 .target = Target{189 .Cross = CrossTarget{
172 .Cross = CrossTarget{190 .os = .linux,
173 .os = .linux,191 .arch = .mipsel,
174 .arch = .mipsel,192 .cpu_features = Target.Arch.mipsel.getBaselineCpuFeatures(),
175 .abi = .musl,193 .abi = .musl,
194 },
176 },195 },
196 .link_libc = true,
177 },197 },
178 .link_libc = true,198
179 },199 TestTarget{
180200 .target = Target{
181 TestTarget{201 .Cross = CrossTarget{
182 .target = Target{202 .os = .macosx,
183 .Cross = CrossTarget{203 .arch = .x86_64,
184 .os = .macosx,204 .cpu_features = Target.Arch.x86_64.getBaselineCpuFeatures(),
185 .arch = .x86_64,205 .abi = .gnu,
186 .abi = .gnu,206 },
187 },207 },
208 // TODO https://github.com/ziglang/zig/issues/3295
209 .disable_native = true,
188 },210 },
189 // TODO https://github.com/ziglang/zig/issues/3295211
190 .disable_native = true,212 TestTarget{
191 },213 .target = Target{
192214 .Cross = CrossTarget{
193 TestTarget{215 .os = .windows,
194 .target = Target{216 .arch = .i386,
195 .Cross = CrossTarget{217 .cpu_features = Target.Arch.i386.getBaselineCpuFeatures(),
196 .os = .windows,218 .abi = .msvc,
197 .arch = .i386,219 },
198 .abi = .msvc,
199 },220 },
200 },221 },
201 },222
202223 TestTarget{
203 TestTarget{224 .target = Target{
204 .target = Target{225 .Cross = CrossTarget{
205 .Cross = CrossTarget{226 .os = .windows,
206 .os = .windows,227 .arch = .x86_64,
207 .arch = .x86_64,228 .cpu_features = Target.Arch.x86_64.getBaselineCpuFeatures(),
208 .abi = .msvc,229 .abi = .msvc,
230 },
209 },231 },
210 },232 },
211 },233
212234 TestTarget{
213 TestTarget{235 .target = Target{
214 .target = Target{236 .Cross = CrossTarget{
215 .Cross = CrossTarget{237 .os = .windows,
216 .os = .windows,238 .arch = .i386,
217 .arch = .i386,239 .cpu_features = Target.Arch.i386.getBaselineCpuFeatures(),
218 .abi = .gnu,240 .abi = .gnu,
241 },
219 },242 },
243 .link_libc = true,
220 },244 },
221 .link_libc = true,245
222 },246 TestTarget{
223247 .target = Target{
224 TestTarget{248 .Cross = CrossTarget{
225 .target = Target{249 .os = .windows,
226 .Cross = CrossTarget{250 .arch = .x86_64,
227 .os = .windows,251 .cpu_features = Target.Arch.x86_64.getBaselineCpuFeatures(),
228 .arch = .x86_64,252 .abi = .gnu,
229 .abi = .gnu,253 },
230 },254 },
255 .link_libc = true,
231 },256 },
232 .link_libc = true,257
233 },258 // Do the release tests last because they take a long time
234259 TestTarget{
235 // Do the release tests last because they take a long time260 .mode = .ReleaseFast,
236 TestTarget{261 },
237 .mode = .ReleaseFast,262 TestTarget{
238 },263 .link_libc = true,
239 TestTarget{264 .mode = .ReleaseFast,
240 .link_libc = true,265 },
241 .mode = .ReleaseFast,266 TestTarget{
242 },267 .mode = .ReleaseFast,
243 TestTarget{268 .single_threaded = true,
244 .mode = .ReleaseFast,269 },
245 .single_threaded = true,270
246 },271 TestTarget{
247272 .mode = .ReleaseSafe,
248 TestTarget{273 },
249 .mode = .ReleaseSafe,274 TestTarget{
250 },275 .link_libc = true,
251 TestTarget{276 .mode = .ReleaseSafe,
252 .link_libc = true,277 },
253 .mode = .ReleaseSafe,278 TestTarget{
254 },279 .mode = .ReleaseSafe,
255 TestTarget{280 .single_threaded = true,
256 .mode = .ReleaseSafe,281 },
257 .single_threaded = true,282
258 },283 TestTarget{
259284 .mode = .ReleaseSmall,
260 TestTarget{285 },
261 .mode = .ReleaseSmall,286 TestTarget{
262 },287 .link_libc = true,
263 TestTarget{288 .mode = .ReleaseSmall,
264 .link_libc = true,289 },
265 .mode = .ReleaseSmall,290 TestTarget{
266 },291 .mode = .ReleaseSmall,
267 TestTarget{292 .single_threaded = true,
268 .mode = .ReleaseSmall,293 },
269 .single_threaded = true,294 };
270 },
271};295};
272296
273const max_stdout_size = 1 * 1024 * 1024; // 1 MB297const max_stdout_size = 1 * 1024 * 1024; // 1 MB
...@@ -598,6 +622,9 @@ pub const StackTracesContext = struct {...@@ -598,6 +622,9 @@ pub const StackTracesContext = struct {
598 child.stderr_behavior = .Pipe;622 child.stderr_behavior = .Pipe;
599 child.env_map = b.env_map;623 child.env_map = b.env_map;
600624
625 if (b.verbose) {
626 printInvocation(args.toSliceConst());
627 }
601 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });628 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", .{ full_exe_path, @errorName(err) });
602629
603 var stdout = Buffer.initNull(b.allocator);630 var stdout = Buffer.initNull(b.allocator);
test/translate_c.zig+65-3
...@@ -1,7 +1,43 @@...@@ -1,7 +1,43 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const Target = @import("std").Target;
34
4pub fn addCases(cases: *tests.TranslateCContext) void {5pub fn addCases(cases: *tests.TranslateCContext) void {
6 cases.add("function prototype with parenthesis",
7 \\void (f0) (void *L);
8 \\void ((f1)) (void *L);
9 \\void (((f2))) (void *L);
10 , &[_][]const u8{
11 \\pub extern fn f0(L: ?*c_void) void;
12 \\pub extern fn f1(L: ?*c_void) void;
13 \\pub extern fn f2(L: ?*c_void) void;
14 });
15
16 cases.add("array initializer w/ typedef",
17 \\typedef unsigned char uuid_t[16];
18 \\static const uuid_t UUID_NULL __attribute__ ((unused)) = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
19 , &[_][]const u8{
20 \\pub const uuid_t = [16]u8;
21 \\pub const UUID_NULL: uuid_t = .{
22 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
23 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
24 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
25 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
26 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
27 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
28 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
29 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
30 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
31 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
32 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
33 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
34 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
35 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
36 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
37 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),
38 \\};
39 });
40
5 cases.add("empty declaration",41 cases.add("empty declaration",
6 \\;42 \\;
7 , &[_][]const u8{""});43 , &[_][]const u8{""});
...@@ -1005,7 +1041,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1005,7 +1041,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1005 });1041 });
10061042
1007 cases.addWithTarget("Calling convention", tests.Target{1043 cases.addWithTarget("Calling convention", tests.Target{
1008 .Cross = .{ .os = .linux, .arch = .i386, .abi = .none },1044 .Cross = .{
1045 .os = .linux,
1046 .arch = .i386,
1047 .abi = .none,
1048 .cpu_features = Target.Arch.i386.getBaselineCpuFeatures(),
1049 },
1009 },1050 },
1010 \\void __attribute__((fastcall)) foo1(float *a);1051 \\void __attribute__((fastcall)) foo1(float *a);
1011 \\void __attribute__((stdcall)) foo2(float *a);1052 \\void __attribute__((stdcall)) foo2(float *a);
...@@ -1021,7 +1062,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1021,7 +1062,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1021 });1062 });
10221063
1023 cases.addWithTarget("Calling convention", tests.Target{1064 cases.addWithTarget("Calling convention", tests.Target{
1024 .Cross = .{ .os = .linux, .arch = .{ .arm = .v8_5a }, .abi = .none },1065 .Cross = .{
1066 .os = .linux,
1067 .arch = .{ .arm = .v8_5a },
1068 .abi = .none,
1069 .cpu_features = (Target.Arch{ .arm = .v8_5a }).getBaselineCpuFeatures(),
1070 },
1025 },1071 },
1026 \\void __attribute__((pcs("aapcs"))) foo1(float *a);1072 \\void __attribute__((pcs("aapcs"))) foo1(float *a);
1027 \\void __attribute__((pcs("aapcs-vfp"))) foo2(float *a);1073 \\void __attribute__((pcs("aapcs-vfp"))) foo2(float *a);
...@@ -1031,7 +1077,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1031,7 +1077,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1031 });1077 });
10321078
1033 cases.addWithTarget("Calling convention", tests.Target{1079 cases.addWithTarget("Calling convention", tests.Target{
1034 .Cross = .{ .os = .linux, .arch = .{ .aarch64 = .v8_5a }, .abi = .none },1080 .Cross = .{
1081 .os = .linux,
1082 .arch = .{ .aarch64 = .v8_5a },
1083 .abi = .none,
1084 .cpu_features = (Target.Arch{ .aarch64 = .v8_5a }).getBaselineCpuFeatures(),
1085 },
1035 },1086 },
1036 \\void __attribute__((aarch64_vector_pcs)) foo1(float *a);1087 \\void __attribute__((aarch64_vector_pcs)) foo1(float *a);
1037 , &[_][]const u8{1088 , &[_][]const u8{
...@@ -2590,4 +2641,15 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2590,4 +2641,15 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2590 \\ return foo((@intCast(c_int, @bitCast(i1, @intCast(u1, @boolToInt(c)))) != @intCast(c_int, @bitCast(i1, @intCast(u1, @boolToInt(b))))));2641 \\ return foo((@intCast(c_int, @bitCast(i1, @intCast(u1, @boolToInt(c)))) != @intCast(c_int, @bitCast(i1, @intCast(u1, @boolToInt(b))))));
2591 \\}2642 \\}
2592 });2643 });
2644
2645 cases.add("Don't make const parameters mutable",
2646 \\int max(const int x, int y) {
2647 \\ return (x > y) ? x : y;
2648 \\}
2649 , &[_][]const u8{
2650 \\pub export fn max(x: c_int, arg_y: c_int) c_int {
2651 \\ var y = arg_y;
2652 \\ return if (x > y) x else y;
2653 \\}
2654 });
2593}2655}