authorgravatar for daniele.cocca@gmail.comDaniele Cocca <daniele.cocca@gmail.com> 2022-03-20 20:57:56+00:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-03-30 11:57:16+03:00
logebafdb958c1aa6b41c28fc7d45f44e38a69a3bd5
treef61152ba5bbd2fe77fbfcdedc9e876a5d982550b
parent633fe41a2c2310d8cfab53ee9d87bb50ac4efc41

AstGen: don't coerce inputs to usize in asmExpr

Instead, use ResultLoc.none to allow for the expression type to be inferred [^1]. This effectively moves the type coercion to Sema, in order to turn comptime values into usable values for the backends to consume. Right now the coercion is applies as comptime_int -> usize and comptime_float -> f64, as an arbitrary choice. [^1]: https://github.com/ziglang/zig/blob/9f25c8140cb859fcea7023362afcb29b1e4df41f/src/AstGen.zig#L207-L208

2 files changed, 9 insertions(+), 2 deletions(-)

src/AstGen.zig+1-1
......@@ -6842,7 +6842,7 @@ fn asmExpr(
68426842 const name = try astgen.identAsString(symbolic_name);
68436843 const constraint_token = symbolic_name + 2;
68446844 const constraint = (try astgen.strLitAsString(constraint_token)).index;
6845 const operand = try expr(gz, scope, .{ .ty = .usize_type }, node_datas[input_node].lhs);
6845 const operand = try expr(gz, scope, .none, node_datas[input_node].lhs);
68466846 inputs[i] = .{
68476847 .name = name,
68486848 .constraint = constraint,
src/Sema.zig+8-1
......@@ -10304,7 +10304,14 @@ fn zirAsm(
1030410304 const name = sema.code.nullTerminatedString(input.data.name);
1030510305 _ = name; // TODO: use the name
1030610306
10307 arg.* = sema.resolveInst(input.data.operand);
10307 const uncasted_arg = sema.resolveInst(input.data.operand);
10308 const uncasted_arg_ty = sema.typeOf(uncasted_arg);
10309 switch (uncasted_arg_ty.zigTypeTag()) {
10310 .ComptimeInt => arg.* = try sema.coerce(block, Type.initTag(.usize), uncasted_arg, src),
10311 .ComptimeFloat => arg.* = try sema.coerce(block, Type.initTag(.f64), uncasted_arg, src),
10312 else => arg.* = uncasted_arg,
10313 }
10314
1030810315 const constraint = sema.code.nullTerminatedString(input.data.constraint);
1030910316 needed_capacity += constraint.len / 4 + 1;
1031010317 inputs[arg_i] = constraint;