1const std = @import("std");
2const Allocator = std.mem.Allocator;
3
4const spec = @import("spec.zig");
5const Word = spec.Word;
6const Id = spec.Id;
7
8const InternPool = @import("../../InternPool.zig");
9const CodeGen = @import("CodeGen.zig");
10
11const Mir = @This();
12
13id_bound: Word,
14owner_nav: InternPool.Nav.Index,
15kind: CodeGen.Decl.Kind,
16decl_result_id: Id,
17extended_instruction_set: []const Word,
18globals: []const Word,
19functions: []const Word,
20annotations: []const Word,
21debug_names: []const Word,
22debug_strings: []const Word,
23execution_modes: []const Word,
24nav_refs: []const NavRef,
25uav_refs: []const UavRef,
26decl_deps: []const DeclDep,
27internal_globals: []const Id,
28entry_points: []const EntryPoint,
29
30pub const NavRef = struct {
31 local_id: Id,
32 nav: InternPool.Nav.Index,
33 kind: CodeGen.Decl.Kind,
34};
35
36pub const UavRef = struct {
37 local_id: Id,
38 val: InternPool.Index,
39 storage_class: spec.StorageClass,
40 kind: CodeGen.Decl.Kind,
41};
42
43pub const DeclDep = struct {
44 kind: CodeGen.Decl.Kind,
45 nav: InternPool.Nav.Index,
46};
47
48pub const EntryPoint = struct {
49 local_id: Id,
50 name: []const u8,
51 cc: std.builtin.CallingConvention,
52};
53
54pub fn deinit(mir: *Mir, gpa: Allocator) void {
55 gpa.free(mir.extended_instruction_set);
56 gpa.free(mir.globals);
57 gpa.free(mir.functions);
58 gpa.free(mir.annotations);
59 gpa.free(mir.debug_names);
60 gpa.free(mir.debug_strings);
61 gpa.free(mir.execution_modes);
62 gpa.free(mir.nav_refs);
63 gpa.free(mir.uav_refs);
64 gpa.free(mir.decl_deps);
65 gpa.free(mir.internal_globals);
66 for (mir.entry_points) |ep| {
67 gpa.free(ep.name);
68 }
69 gpa.free(mir.entry_points);
70 mir.* = undefined;
71}