1const Mir = @This();
2const InternPool = @import("../../InternPool.zig");
3
4const builtin = @import("builtin");
5const std = @import("std");
6const assert = std.debug.assert;
7
8instructions: std.MultiArrayList(Inst).Slice,
9
10extra: []const u32,
11
12pub const Inst = struct {
13 tag: Tag,
14 data: Data,
15
16 /// The position of a given MIR isntruction with the instruction list.
17 pub const Index = enum(u32) {
18 _,
19 };
20
21 pub const Tag = enum(u8) {
22 /// imm8
23 set_page_i = 0x04,
24 /// imm8
25 set_addr_i = 0x09,
26 /// imm8
27 load_i_outa = 0x15,
28 /// index
29 jump = 0x68,
30 /// nothing
31 halt = 0xE3,
32 };
33
34 /// All instructions contain a 4-byte payload, which is contained within
35 /// this union. `Tag` determines which union tag is active, as well as
36 /// how to interpret the data within.
37 pub const Data = union {
38 imm8: u8,
39 index: Index,
40 nothing: void,
41
42 comptime {
43 switch (builtin.mode) {
44 .Debug, .ReleaseSafe => {},
45 .ReleaseFast, .ReleaseSmall => assert(@sizeOf(Data) == 4),
46 }
47 }
48 };
49};
50
51pub fn deinit(mir: *Mir, gpa: std.mem.Allocator) void {
52 mir.instructions.deinit(gpa);
53 mir.* = undefined;
54}