Add float to int builtin

This commit is contained in:
nub31
2025-09-28 22:48:32 +02:00
parent a485b28103
commit 87155de49d
6 changed files with 111 additions and 15 deletions

View File

@@ -645,7 +645,8 @@ public class QBEGenerator
StructFuncCallNode expr => EmitStructFuncCall(expr),
StructInitializerNode expr => EmitStructInitializer(expr),
UnaryExpressionNode expr => EmitUnaryExpression(expr),
SizeCompilerMacroNode expr => $"{SizeOf(expr.TargetType)}",
SizeBuiltinNode expr => $"{SizeOf(expr.TargetType)}",
FloatToIntBuiltinNode expr => EmitFloatToIntBuiltin(expr),
_ => throw new ArgumentOutOfRangeException(nameof(rValue))
};
}
@@ -1106,6 +1107,31 @@ public class QBEGenerator
return result;
}
private string EmitFloatToIntBuiltin(FloatToIntBuiltinNode floatToInt)
{
var value = EmitExpression(floatToInt.Value);
var method = floatToInt.TargetType.Signed switch
{
true => floatToInt.ValueType.Width switch
{
32 => "stosi",
64 => "dtosi",
_ => throw new ArgumentOutOfRangeException()
},
false => floatToInt.ValueType.Width switch
{
32 => "stoui",
64 => "dtoui",
_ => throw new ArgumentOutOfRangeException()
}
};
var result = TmpName();
_writer.Indented($"{result} {QBEAssign(floatToInt.TargetType)} {method} {value}");
return result;
}
private string EmitFuncCall(FuncCallNode funcCall)
{
var funcPointer = EmitExpression(funcCall.Expression);