diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-07-13 21:49:22 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-07-20 12:19:16 -0700 |
| commit | dbd3529d1fa02d5e720df0fbf2436d646f5a4f57 (patch) | |
| tree | b75125e6b9847fe962c69550ae9e9e9ce9169e79 /src/Module.zig | |
| parent | f17a05bfb7ca0ff010fef9654264eed7342298d2 (diff) | |
| download | zig-dbd3529d1fa02d5e720df0fbf2436d646f5a4f57.tar.gz zig-dbd3529d1fa02d5e720df0fbf2436d646f5a4f57.zip | |
Sema: first pass reworking for AIR memory layout
Diffstat (limited to 'src/Module.zig')
| -rw-r--r-- | src/Module.zig | 50 |
1 files changed, 40 insertions, 10 deletions
diff --git a/src/Module.zig b/src/Module.zig index 7ec9c7e93d..3ce3c47f14 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -1232,22 +1232,52 @@ pub const Scope = struct { ty: Type, operand: Air.Inst.Ref, ) error{OutOfMemory}!Air.Inst.Ref { + return block.addInst(.{ + .tag = tag, + .data = .{ .ty_op = .{ + .ty = try block.sema.addType(ty), + .operand = operand, + } }, + }); + } + + pub fn addUnOp( + block: *Block, + tag: Air.Inst.Tag, + operand: Air.Inst.Ref, + ) error{OutOfMemory}!Air.Inst.Ref { + return block.addInst(.{ + .tag = tag, + .data = .{ .un_op = operand }, + }); + } + + pub fn addBinOp( + block: *Block, + tag: Air.Inst.Tag, + lhs: Air.Inst.Ref, + rhs: Air.Inst.Ref, + ) error{OutOfMemory}!Air.Inst.Ref { + return block.addInst(.{ + .tag = tag, + .data = .{ .bin_op = .{ + .lhs = lhs, + .rhs = rhs, + } }, + }); + } + + pub fn addInst(block: *Block, inst: Air.Inst) error{OutOfMemory}!Air.Inst.Ref { const sema = block.sema; const gpa = sema.gpa; try sema.air_instructions.ensureUnusedCapacity(gpa, 1); try block.instructions.ensureUnusedCapacity(gpa, 1); - const inst = @intCast(Air.Inst.Index, sema.air_instructions.len); - sema.air_instructions.appendAssumeCapacity(.{ - .tag = tag, - .data = .{ .ty_op = .{ - .ty = try sema.addType(ty), - .operand = operand, - } }, - }); - block.instructions.appendAssumeCapacity(inst); - return Sema.indexToRef(inst); + const result_index = @intCast(Air.Inst.Index, sema.air_instructions.len); + sema.air_instructions.appendAssumeCapacity(inst); + block.instructions.appendAssumeCapacity(result_index); + return Sema.indexToRef(result_index); } }; }; |
