| 1 | const std = @import("std"); |
| 2 | const Allocator = std.mem.Allocator; |
| 3 | |
| 4 | const spec = @import("spec.zig"); |
| 5 | const Word = spec.Word; |
| 6 | const Id = spec.Id; |
| 7 | |
| 8 | const InternPool = @import("../../InternPool.zig"); |
| 9 | const CodeGen = @import("CodeGen.zig"); |
| 10 | |
| 11 | const Mir = @This(); |
| 12 | |
| 13 | id_bound: Word, |
| 14 | owner_nav: InternPool.Nav.Index, |
| 15 | kind: CodeGen.Decl.Kind, |
| 16 | decl_result_id: Id, |
| 17 | extended_instruction_set: []const Word, |
| 18 | globals: []const Word, |
| 19 | functions: []const Word, |
| 20 | annotations: []const Word, |
| 21 | debug_names: []const Word, |
| 22 | debug_strings: []const Word, |
| 23 | execution_modes: []const Word, |
| 24 | nav_refs: []const NavRef, |
| 25 | uav_refs: []const UavRef, |
| 26 | decl_deps: []const DeclDep, |
| 27 | internal_globals: []const Id, |
| 28 | entry_points: []const EntryPoint, |
| 29 | |
| 30 | pub const NavRef = struct { |
| 31 | local_id: Id, |
| 32 | nav: InternPool.Nav.Index, |
| 33 | kind: CodeGen.Decl.Kind, |
| 34 | }; |
| 35 | |
| 36 | pub const UavRef = struct { |
| 37 | local_id: Id, |
| 38 | val: InternPool.Index, |
| 39 | storage_class: spec.StorageClass, |
| 40 | kind: CodeGen.Decl.Kind, |
| 41 | }; |
| 42 | |
| 43 | pub const DeclDep = struct { |
| 44 | kind: CodeGen.Decl.Kind, |
| 45 | nav: InternPool.Nav.Index, |
| 46 | }; |
| 47 | |
| 48 | pub const EntryPoint = struct { |
| 49 | local_id: Id, |
| 50 | name: []const u8, |
| 51 | cc: std.builtin.CallingConvention, |
| 52 | }; |
| 53 | |
| 54 | pub 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 | } |