Allow for implicit int conversion to larger type
This commit is contained in:
@@ -600,6 +600,8 @@ public class QBEGenerator
|
||||
FuncCallNode funcCall => EmitFuncCall(funcCall),
|
||||
InterfaceFuncCallNode interfaceFuncCall => EmitInterfaceFuncCall(interfaceFuncCall),
|
||||
InterfaceInitializerNode interfaceInitializer => EmitInterfaceInitializer(interfaceInitializer),
|
||||
ConvertIntNode convertInt => EmitConvertInt(convertInt),
|
||||
ConvertFloatNode convertFloat => EmitConvertFloat(convertFloat),
|
||||
ExternFuncIdentNode externFuncIdent => EmitExternFuncIdent(externFuncIdent),
|
||||
LocalFuncIdentNode localFuncIdent => EmitLocalFuncIdent(localFuncIdent),
|
||||
VariableIdentNode variableIdent => EmitVariableIdent(variableIdent),
|
||||
@@ -1118,6 +1120,59 @@ public class QBEGenerator
|
||||
return destination;
|
||||
}
|
||||
|
||||
private string EmitConvertInt(ConvertIntNode convertInt)
|
||||
{
|
||||
var value = EmitExpression(convertInt.Value);
|
||||
|
||||
if (convertInt.ValueType == convertInt.TargetType || convertInt.ValueType.Width > convertInt.TargetType.Width)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
var method = convertInt.ValueType.Signed switch
|
||||
{
|
||||
true => convertInt.ValueType.Width switch
|
||||
{
|
||||
8 => "extsb",
|
||||
16 => "extsh",
|
||||
32 => "extsw",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
},
|
||||
false => convertInt.ValueType.Width switch
|
||||
{
|
||||
8 => "extub",
|
||||
16 => "extuh",
|
||||
32 => "extuw",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
}
|
||||
};
|
||||
|
||||
var result = TmpName();
|
||||
_writer.Indented($"{result} {QBEAssign(convertInt.TargetType)} {method} {value}");
|
||||
return result;
|
||||
}
|
||||
|
||||
private string EmitConvertFloat(ConvertFloatNode convertFloat)
|
||||
{
|
||||
var value = EmitExpression(convertFloat.Value);
|
||||
|
||||
if (convertFloat.ValueType == convertFloat.TargetType)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
var method = convertFloat.ValueType.Width switch
|
||||
{
|
||||
32 => "exts",
|
||||
64 => "truncd",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
|
||||
var result = TmpName();
|
||||
_writer.Indented($"{result} {QBEAssign(convertFloat.TargetType)} {method} {value}");
|
||||
return result;
|
||||
}
|
||||
|
||||
private string EmitFuncCall(FuncCallNode funcCall)
|
||||
{
|
||||
var funcPointer = EmitExpression(funcCall.Expression);
|
||||
|
||||
Reference in New Issue
Block a user