aboutsummaryrefslogtreecommitdiff
path: root/src-self-hosted/ir.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-04-21 13:24:25 -0400
committerAndrew Kelley <andrew@ziglang.org>2020-04-21 13:24:25 -0400
commitfb63ba25779a4e482d2acc4c2cfc265c68c1b1eb (patch)
treee069c18c34b85016b5abc2e979f07affa3e169a0 /src-self-hosted/ir.zig
parent8e0bcaca9b597f510eae2b3ed7423b84a904beb8 (diff)
downloadzig-fb63ba25779a4e482d2acc4c2cfc265c68c1b1eb.tar.gz
zig-fb63ba25779a4e482d2acc4c2cfc265c68c1b1eb.zip
ir: type coercion skeleton
Diffstat (limited to 'src-self-hosted/ir.zig')
-rw-r--r--src-self-hosted/ir.zig27
1 files changed, 27 insertions, 0 deletions
diff --git a/src-self-hosted/ir.zig b/src-self-hosted/ir.zig
index a36a745f87..28f1f4061f 100644
--- a/src-self-hosted/ir.zig
+++ b/src-self-hosted/ir.zig
@@ -232,6 +232,18 @@ const Analyze = struct {
}
fn coerce(self: *Analyze, dest_type: Type, inst: *Inst) !*Inst {
+ // *[N]T to []T
+ if (inst.ty.isSinglePointer() and dest_type.isSlice() and
+ (!inst.ty.pointerIsConst() or dest_type.pointerIsConst()))
+ {
+ const array_type = inst.ty.elemType();
+ const dst_elem_type = dest_type.elemType();
+ if (array_type.zigTypeTag() == .Array and
+ coerceInMemoryAllowed(dst_elem_type, array_type.elemType()) == .ok)
+ {
+ return self.fail(inst.src_offset, "TODO do the type coercion", .{});
+ }
+ }
return self.fail(inst.src_offset, "TODO implement type coercion", .{});
}
@@ -244,6 +256,21 @@ const Analyze = struct {
};
return error.AnalysisFail;
}
+
+ const InMemoryCoercionResult = enum {
+ ok,
+ no_match,
+ };
+
+ fn coerceInMemoryAllowed(dest_type: Type, src_type: Type) InMemoryCoercionResult {
+ // As a shortcut, if the small tags / addresses match, we're done.
+ if (dest_type.tag_if_small_enough == src_type.tag_if_small_enough)
+ return .ok;
+
+ // TODO: implement more of this function
+
+ return .no_match;
+ }
};
pub fn main() anyerror!void {