feature. See also
. The project being documented here (as the example) is the Zig library itself.
AstGen.floatRoundOp
fn floatRoundOp(
gz: *GenZir,
scope: *Scope,
ri: ResultInfo,
node: Ast.Node.Index,
operand_node: Ast.Node.Index,
float_tag: Zir.Inst.Tag,
) InnerError!Zir.Inst.Ref
File
Code
fn floatRoundOp(
gz: *GenZir,
scope: *Scope,
ri: ResultInfo,
node: Ast.Node.Index,
operand_node: Ast.Node.Index,
float_tag: Zir.Inst.Tag,
) InnerError!Zir.Inst.Ref {
if (try ri.rl.resultType(gz, node)) |dest_type| {
const cursor = maybeAdvanceSourceCursorToMainToken(gz, node);
const operand_ty_inst = try gz.addExtendedPayload(.round_op_ty, Zir.Inst.UnNode{
.node = gz.nodeIndexToRelative(node),
.operand = dest_type,
});
const operand = try expr(gz, scope, .{ .rl = .{ .coerced_ty = operand_ty_inst } }, operand_node);
try emitDbgStmt(gz, cursor);
const round_op: Zir.Inst.RoundOp = switch (float_tag) {
.round => .round,
.floor => .floor,
.ceil => .ceil,
.trunc => .trunc,
else => unreachable,
};
const result = try gz.addExtendedPayloadSmall(.round_op, @backingInt(round_op), Zir.Inst.BinNode{
.node = gz.nodeIndexToRelative(node),
.lhs = dest_type,
.rhs = operand,
});
return rvalue(gz, ri, result, node);
} else {
return floatUnOp(gz, scope, ri, node, operand_node, float_tag);
}
}