...
This commit is contained in:
@@ -110,8 +110,8 @@ foreach (var resourceName in runtimeResources)
|
||||
await using var stream = assembly.GetManifestResourceStream(resourceName);
|
||||
if (stream == null)
|
||||
{
|
||||
Console.Error.WriteLine($"Warning: Could not load embedded resource {resourceName}");
|
||||
continue;
|
||||
Console.Error.WriteLine($"Could not load embedded resource {resourceName}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
using var reader = new StreamReader(stream);
|
||||
|
||||
@@ -90,86 +90,86 @@ public static class QBEGenerator
|
||||
|
||||
private static string QBEStore(NubType type)
|
||||
{
|
||||
return $"store{type switch
|
||||
return type switch
|
||||
{
|
||||
NubArrayType => "l",
|
||||
NubPointerType => "l",
|
||||
NubArrayType => "storel",
|
||||
NubPointerType => "storel",
|
||||
NubPrimitiveType primitiveType => primitiveType.Kind switch
|
||||
{
|
||||
PrimitiveTypeKind.I64 => "l",
|
||||
PrimitiveTypeKind.I32 => "w",
|
||||
PrimitiveTypeKind.I16 => "h",
|
||||
PrimitiveTypeKind.I8 => "b",
|
||||
PrimitiveTypeKind.U64 => "l",
|
||||
PrimitiveTypeKind.U32 => "w",
|
||||
PrimitiveTypeKind.U16 => "h",
|
||||
PrimitiveTypeKind.U8 => "b",
|
||||
PrimitiveTypeKind.F64 => "d",
|
||||
PrimitiveTypeKind.F32 => "s",
|
||||
PrimitiveTypeKind.Bool => "w",
|
||||
PrimitiveTypeKind.I64 => "storel",
|
||||
PrimitiveTypeKind.I32 => "storew",
|
||||
PrimitiveTypeKind.I16 => "storeh",
|
||||
PrimitiveTypeKind.I8 => "storeb",
|
||||
PrimitiveTypeKind.U64 => "storel",
|
||||
PrimitiveTypeKind.U32 => "storew",
|
||||
PrimitiveTypeKind.U16 => "storeh",
|
||||
PrimitiveTypeKind.U8 => "storeb",
|
||||
PrimitiveTypeKind.F64 => "stored",
|
||||
PrimitiveTypeKind.F32 => "stores",
|
||||
PrimitiveTypeKind.Bool => "storew",
|
||||
_ => throw new UnreachableException()
|
||||
},
|
||||
NubStructType => "l",
|
||||
NubFixedArrayType => "l",
|
||||
NubFuncType => "l",
|
||||
NubStructType => "storel",
|
||||
NubFixedArrayType => "storel",
|
||||
NubFuncType => "storel",
|
||||
_ => throw new NotSupportedException($"'{type}' type cannot be used in store instructions")
|
||||
}}";
|
||||
};
|
||||
}
|
||||
|
||||
private static string QBELoad(NubType type)
|
||||
{
|
||||
return $"load{type switch
|
||||
return type switch
|
||||
{
|
||||
NubArrayType => "l",
|
||||
NubPointerType => "l",
|
||||
NubArrayType => "loadl",
|
||||
NubPointerType => "loadl",
|
||||
NubPrimitiveType primitiveType => primitiveType.Kind switch
|
||||
{
|
||||
PrimitiveTypeKind.I64 => "l",
|
||||
PrimitiveTypeKind.I32 => "w",
|
||||
PrimitiveTypeKind.I16 => "sh",
|
||||
PrimitiveTypeKind.I8 => "sb",
|
||||
PrimitiveTypeKind.U64 => "l",
|
||||
PrimitiveTypeKind.U32 => "w",
|
||||
PrimitiveTypeKind.U16 => "uh",
|
||||
PrimitiveTypeKind.U8 => "ub",
|
||||
PrimitiveTypeKind.F64 => "d",
|
||||
PrimitiveTypeKind.F32 => "s",
|
||||
PrimitiveTypeKind.Bool => "w",
|
||||
PrimitiveTypeKind.I64 => "loadl",
|
||||
PrimitiveTypeKind.I32 => "loadw",
|
||||
PrimitiveTypeKind.I16 => "loadsh",
|
||||
PrimitiveTypeKind.I8 => "loadsb",
|
||||
PrimitiveTypeKind.U64 => "loadl",
|
||||
PrimitiveTypeKind.U32 => "loadw",
|
||||
PrimitiveTypeKind.U16 => "loaduh",
|
||||
PrimitiveTypeKind.U8 => "loadub",
|
||||
PrimitiveTypeKind.F64 => "loadd",
|
||||
PrimitiveTypeKind.F32 => "loads",
|
||||
PrimitiveTypeKind.Bool => "loadw",
|
||||
_ => throw new UnreachableException()
|
||||
},
|
||||
NubStructType => "l",
|
||||
NubFixedArrayType => "l",
|
||||
NubFuncType => "l",
|
||||
NubStructType => "loadl",
|
||||
NubFixedArrayType => "loadl",
|
||||
NubFuncType => "loadl",
|
||||
_ => throw new NotSupportedException($"'{type}' type cannot be used in load instructions")
|
||||
}}";
|
||||
};
|
||||
}
|
||||
|
||||
private static string QBEAssign(NubType type)
|
||||
{
|
||||
return $"={type switch
|
||||
return type switch
|
||||
{
|
||||
NubArrayType => "l",
|
||||
NubPointerType => "l",
|
||||
NubArrayType => "=l",
|
||||
NubPointerType => "=l",
|
||||
NubPrimitiveType primitiveType => primitiveType.Kind switch
|
||||
{
|
||||
PrimitiveTypeKind.I64 => "l",
|
||||
PrimitiveTypeKind.I32 => "w",
|
||||
PrimitiveTypeKind.I16 => "w",
|
||||
PrimitiveTypeKind.I8 => "w",
|
||||
PrimitiveTypeKind.U64 => "l",
|
||||
PrimitiveTypeKind.U32 => "w",
|
||||
PrimitiveTypeKind.U16 => "w",
|
||||
PrimitiveTypeKind.U8 => "w",
|
||||
PrimitiveTypeKind.F64 => "d",
|
||||
PrimitiveTypeKind.F32 => "s",
|
||||
PrimitiveTypeKind.Bool => "w",
|
||||
PrimitiveTypeKind.I64 => "=l",
|
||||
PrimitiveTypeKind.I32 => "=w",
|
||||
PrimitiveTypeKind.I16 => "=w",
|
||||
PrimitiveTypeKind.I8 => "=w",
|
||||
PrimitiveTypeKind.U64 => "=l",
|
||||
PrimitiveTypeKind.U32 => "=w",
|
||||
PrimitiveTypeKind.U16 => "=w",
|
||||
PrimitiveTypeKind.U8 => "=w",
|
||||
PrimitiveTypeKind.F64 => "=d",
|
||||
PrimitiveTypeKind.F32 => "=s",
|
||||
PrimitiveTypeKind.Bool => "=w",
|
||||
_ => throw new UnreachableException()
|
||||
},
|
||||
NubStructType => "l",
|
||||
NubFixedArrayType => "l",
|
||||
NubFuncType => "l",
|
||||
NubStructType => "=l",
|
||||
NubFixedArrayType => "=l",
|
||||
NubFuncType => "=l",
|
||||
_ => throw new NotSupportedException($"'{type}' type cannot be used in variables")
|
||||
}}";
|
||||
};
|
||||
}
|
||||
|
||||
private static int AlignmentOf(NubType type)
|
||||
@@ -349,7 +349,9 @@ public static class QBEGenerator
|
||||
|
||||
_builder.Append(name);
|
||||
|
||||
var parameterStrings = parameters.Select(parameter => $"{parameter.Type switch
|
||||
var parameterStrings = parameters.Select(parameter =>
|
||||
{
|
||||
var qbeType = parameter.Type switch
|
||||
{
|
||||
NubArrayType => "l",
|
||||
NubPointerType => "l",
|
||||
@@ -372,7 +374,10 @@ public static class QBEGenerator
|
||||
NubFixedArrayType => "l",
|
||||
NubFuncType => "l",
|
||||
_ => throw new NotSupportedException($"'{parameter.Type}' type cannot be used as a function parameter type")
|
||||
}} %{parameter.Name}");
|
||||
};
|
||||
|
||||
return $"{qbeType} %{parameter.Name}";
|
||||
});
|
||||
|
||||
_builder.AppendLine($"({string.Join(", ", parameterStrings)}) {{");
|
||||
_builder.AppendLine("@start");
|
||||
@@ -427,7 +432,7 @@ public static class QBEGenerator
|
||||
_builder.Append($"type :{structDefinition.Namespace}_{structDefinition.Name} = {{ ");
|
||||
foreach (var structDefinitionField in structDefinition.Fields)
|
||||
{
|
||||
var fieldQbeType = structDefinitionField.Type switch
|
||||
var qbeType = structDefinitionField.Type switch
|
||||
{
|
||||
NubArrayType => "l",
|
||||
NubPointerType => "l",
|
||||
@@ -451,7 +456,7 @@ public static class QBEGenerator
|
||||
NubFuncType => "l",
|
||||
_ => throw new NotSupportedException($"'{structDefinitionField.Type}' type cannot be used in structs")
|
||||
};
|
||||
_builder.Append(fieldQbeType + ", ");
|
||||
_builder.Append(qbeType + ", ");
|
||||
}
|
||||
_builder.AppendLine("}");
|
||||
}
|
||||
@@ -1286,7 +1291,7 @@ public static class QBEGenerator
|
||||
var parameter = funcCall.Parameters[i];
|
||||
var result = GenerateExpression(parameter);
|
||||
|
||||
var qbeParameterType = parameter.Type switch
|
||||
var qbeType = parameter.Type switch
|
||||
{
|
||||
NubArrayType => "l",
|
||||
NubPointerType => "l",
|
||||
@@ -1310,7 +1315,7 @@ public static class QBEGenerator
|
||||
NubFuncType => "l",
|
||||
_ => throw new NotSupportedException($"'{parameter.Type}' type cannot be used in function calls")
|
||||
};
|
||||
parameterStrings.Add($"{qbeParameterType} {result}");
|
||||
parameterStrings.Add($"{qbeType} {result}");
|
||||
}
|
||||
|
||||
string funcTarget;
|
||||
|
||||
Reference in New Issue
Block a user