aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorDaniele Cocca <daniele.cocca@gmail.com>2022-03-20 20:57:56 +0000
committerVeikka Tuominen <git@vexu.eu>2022-03-30 11:57:16 +0300
commitebafdb958c1aa6b41c28fc7d45f44e38a69a3bd5 (patch)
treef61152ba5bbd2fe77fbfcdedc9e876a5d982550b /src/Sema.zig
parent633fe41a2c2310d8cfab53ee9d87bb50ac4efc41 (diff)
downloadzig-ebafdb958c1aa6b41c28fc7d45f44e38a69a3bd5.tar.gz
zig-ebafdb958c1aa6b41c28fc7d45f44e38a69a3bd5.zip
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
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index f13f97bbbb..112939c995 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -10304,7 +10304,14 @@ fn zirAsm(
const name = sema.code.nullTerminatedString(input.data.name);
_ = name; // TODO: use the name
- arg.* = sema.resolveInst(input.data.operand);
+ const uncasted_arg = sema.resolveInst(input.data.operand);
+ const uncasted_arg_ty = sema.typeOf(uncasted_arg);
+ switch (uncasted_arg_ty.zigTypeTag()) {
+ .ComptimeInt => arg.* = try sema.coerce(block, Type.initTag(.usize), uncasted_arg, src),
+ .ComptimeFloat => arg.* = try sema.coerce(block, Type.initTag(.f64), uncasted_arg, src),
+ else => arg.* = uncasted_arg,
+ }
+
const constraint = sema.code.nullTerminatedString(input.data.constraint);
needed_capacity += constraint.len / 4 + 1;
inputs[arg_i] = constraint;