Add float to int builtin
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user