aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorJacob G-W <jacoblevgw@gmail.com>2021-09-30 21:29:52 -0400
committerJacob G-W <jacoblevgw@gmail.com>2021-09-30 21:29:52 -0400
commitb0e89ee499b8110bca6964e996c5862337147e32 (patch)
tree30b4eff80cddb2ad0df43ff27da72f8fe1017a15 /src/codegen
parent5e7406bdd9f942900dceb2f917ed5f64b6f2ba00 (diff)
downloadzig-b0e89ee499b8110bca6964e996c5862337147e32.tar.gz
zig-b0e89ee499b8110bca6964e996c5862337147e32.zip
stage2 llvm backend: implement codegen for Value.repeated
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/llvm.zig19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index a1e9f47df4..5954bd0b26 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -1021,6 +1021,7 @@ pub const DeclGen = struct {
else => |tag| return self.todo("implement const of pointer type '{}' ({})", .{ tv.ty, tag }),
},
.Array => {
+ const gpa = self.gpa;
if (tv.val.castTag(.bytes)) |payload| {
const zero_sentinel = if (tv.ty.sentinel()) |sentinel| blk: {
if (sentinel.tag() == .zero) break :blk true;
@@ -1034,7 +1035,6 @@ pub const DeclGen = struct {
);
}
if (tv.val.castTag(.array)) |payload| {
- const gpa = self.gpa;
const elem_ty = tv.ty.elemType();
const elem_vals = payload.data;
const sento = tv.ty.sentinel();
@@ -1050,6 +1050,23 @@ pub const DeclGen = struct {
@intCast(c_uint, llvm_elems.len),
);
}
+ if (tv.val.castTag(.repeated)) |payload| {
+ const val = payload.data;
+ const elem_ty = tv.ty.elemType();
+ const len = tv.ty.arrayLen();
+
+ const llvm_elems = try gpa.alloc(*const llvm.Value, len);
+ defer gpa.free(llvm_elems);
+ var i: u64 = 0;
+ while (i < len) : (i += 1) {
+ llvm_elems[i] = try self.genTypedValue(.{ .ty = elem_ty, .val = val });
+ }
+ const llvm_elem_ty = try self.llvmType(elem_ty);
+ return llvm_elem_ty.constArray(
+ llvm_elems.ptr,
+ @intCast(c_uint, llvm_elems.len),
+ );
+ }
return self.todo("handle more array values", .{});
},
.Optional => {