aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-04-22 23:47:31 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-04-22 23:47:31 -0700
commit715abe8ebeebb6d49db1e265748554404c3aab98 (patch)
tree19c0fc7880bb3d9205877b31043a757de61f9cda /src/Module.zig
parent2d290d6f82b780fc5c1448bcc41fec602359dfec (diff)
downloadzig-715abe8ebeebb6d49db1e265748554404c3aab98.tar.gz
zig-715abe8ebeebb6d49db1e265748554404c3aab98.zip
AstGen: implement integers bigger than u64
also get rid of the `optional_type_from_ptr_elem` instruction.
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig36
1 files changed, 20 insertions, 16 deletions
diff --git a/src/Module.zig b/src/Module.zig
index f58a66a16f..502f94367a 100644
--- a/src/Module.zig
+++ b/src/Module.zig
@@ -1423,6 +1423,26 @@ pub const Scope = struct {
});
}
+ pub fn addIntBig(gz: *GenZir, limbs: []const std.math.big.Limb) !Zir.Inst.Ref {
+ const astgen = gz.astgen;
+ const gpa = astgen.gpa;
+ try gz.instructions.ensureUnusedCapacity(gpa, 1);
+ try astgen.instructions.ensureUnusedCapacity(gpa, 1);
+ try astgen.string_bytes.ensureUnusedCapacity(gpa, @sizeOf(std.math.big.Limb) * limbs.len);
+
+ const new_index = @intCast(Zir.Inst.Index, astgen.instructions.len);
+ astgen.instructions.appendAssumeCapacity(.{
+ .tag = .int_big,
+ .data = .{ .str = .{
+ .start = @intCast(u32, astgen.string_bytes.items.len),
+ .len = @intCast(u32, limbs.len),
+ } },
+ });
+ gz.instructions.appendAssumeCapacity(new_index);
+ astgen.string_bytes.appendSliceAssumeCapacity(mem.sliceAsBytes(limbs));
+ return gz.indexToRef(new_index);
+ }
+
pub fn addFloat(gz: *GenZir, number: f32, src_node: ast.Node.Index) !Zir.Inst.Ref {
return gz.add(.{
.tag = .float,
@@ -1683,22 +1703,6 @@ pub const Scope = struct {
return gz.indexToRef(new_index);
}
- /// Asserts that `str` is 8 or fewer bytes.
- pub fn addSmallStr(
- gz: *GenZir,
- tag: Zir.Inst.Tag,
- str: []const u8,
- ) !Zir.Inst.Ref {
- var buf: [9]u8 = undefined;
- mem.copy(u8, &buf, str);
- buf[str.len] = 0;
-
- return gz.add(.{
- .tag = tag,
- .data = .{ .small_str = .{ .bytes = buf[0..8].* } },
- });
- }
-
/// Note that this returns a `Zir.Inst.Index` not a ref.
/// Does *not* append the block instruction to the scope.
/// Leaves the `payload_index` field undefined.