Bool
This commit is contained in:
@@ -122,27 +122,17 @@ public static class QBEGenerator
|
||||
{
|
||||
var store = type switch
|
||||
{
|
||||
NubArrayType => "storel",
|
||||
NubPointerType => "storel",
|
||||
NubPrimitiveType primitiveType => primitiveType.Kind switch
|
||||
{
|
||||
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.I64 or PrimitiveTypeKind.U64 => "storel",
|
||||
PrimitiveTypeKind.I32 or PrimitiveTypeKind.U32 => "storew",
|
||||
PrimitiveTypeKind.I16 or PrimitiveTypeKind.U16 => "storeh",
|
||||
PrimitiveTypeKind.I8 or PrimitiveTypeKind.U8 or PrimitiveTypeKind.Bool => "storeb",
|
||||
PrimitiveTypeKind.F64 => "stored",
|
||||
PrimitiveTypeKind.F32 => "stores",
|
||||
PrimitiveTypeKind.Bool => "storew",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
},
|
||||
NubStructType => "storel",
|
||||
NubFuncType => "storel",
|
||||
NubCStringType => "storel",
|
||||
NubStringType => "storel",
|
||||
NubArrayType or NubPointerType or NubStructType or NubFuncType or NubCStringType or NubStringType => "storel",
|
||||
_ => throw new NotSupportedException($"'{type}' type cannot be used in store instructions")
|
||||
};
|
||||
|
||||
@@ -154,27 +144,19 @@ public static class QBEGenerator
|
||||
var into = VarName();
|
||||
var load = type switch
|
||||
{
|
||||
NubArrayType => "loadl",
|
||||
NubPointerType => "loadl",
|
||||
NubPrimitiveType primitiveType => primitiveType.Kind switch
|
||||
{
|
||||
PrimitiveTypeKind.I64 => "loadl",
|
||||
PrimitiveTypeKind.I32 => "loadw",
|
||||
PrimitiveTypeKind.I64 or PrimitiveTypeKind.U64 => "loadl",
|
||||
PrimitiveTypeKind.I32 or PrimitiveTypeKind.U32 => "loadw",
|
||||
PrimitiveTypeKind.I16 => "loadsh",
|
||||
PrimitiveTypeKind.I8 => "loadsb",
|
||||
PrimitiveTypeKind.U64 => "loadl",
|
||||
PrimitiveTypeKind.U32 => "loadw",
|
||||
PrimitiveTypeKind.U16 => "loaduh",
|
||||
PrimitiveTypeKind.U8 => "loadub",
|
||||
PrimitiveTypeKind.U8 or PrimitiveTypeKind.Bool => "loadub",
|
||||
PrimitiveTypeKind.F64 => "loadd",
|
||||
PrimitiveTypeKind.F32 => "loads",
|
||||
PrimitiveTypeKind.Bool => "loadw",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
},
|
||||
NubStructType => "loadl",
|
||||
NubFuncType => "loadl",
|
||||
NubCStringType => "loadl",
|
||||
NubStringType => "loadl",
|
||||
NubArrayType or NubPointerType or NubStructType or NubFuncType or NubCStringType or NubStringType => "loadl",
|
||||
_ => throw new NotSupportedException($"'{type}' type cannot be used in load instructions")
|
||||
};
|
||||
|
||||
@@ -318,27 +300,17 @@ public static class QBEGenerator
|
||||
{
|
||||
return type switch
|
||||
{
|
||||
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.I64 or PrimitiveTypeKind.U64 => "=l",
|
||||
PrimitiveTypeKind.I32 or PrimitiveTypeKind.U32 => "=w",
|
||||
PrimitiveTypeKind.I16 or PrimitiveTypeKind.U16 => "=w",
|
||||
PrimitiveTypeKind.I8 or PrimitiveTypeKind.U8 or PrimitiveTypeKind.Bool => "=w",
|
||||
PrimitiveTypeKind.F64 => "=d",
|
||||
PrimitiveTypeKind.F32 => "=s",
|
||||
PrimitiveTypeKind.Bool => "=w",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
},
|
||||
NubStructType => "=l",
|
||||
NubFuncType => "=l",
|
||||
NubCStringType => "=l",
|
||||
NubStringType => "=l",
|
||||
NubArrayType or NubPointerType or NubStructType or NubFuncType or NubCStringType or NubStringType => "=l",
|
||||
_ => throw new NotSupportedException($"'{type}' type cannot be used in variables")
|
||||
};
|
||||
}
|
||||
@@ -352,9 +324,9 @@ public static class QBEGenerator
|
||||
return primitiveType.Kind switch
|
||||
{
|
||||
PrimitiveTypeKind.I64 or PrimitiveTypeKind.U64 or PrimitiveTypeKind.F64 => 8,
|
||||
PrimitiveTypeKind.I32 or PrimitiveTypeKind.U32 or PrimitiveTypeKind.F32 or PrimitiveTypeKind.Bool => 4,
|
||||
PrimitiveTypeKind.I32 or PrimitiveTypeKind.U32 or PrimitiveTypeKind.F32 => 4,
|
||||
PrimitiveTypeKind.I16 or PrimitiveTypeKind.U16 => 2,
|
||||
PrimitiveTypeKind.I8 or PrimitiveTypeKind.U8 => 1,
|
||||
PrimitiveTypeKind.I8 or PrimitiveTypeKind.U8 or PrimitiveTypeKind.Bool => 1,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
@@ -368,13 +340,9 @@ public static class QBEGenerator
|
||||
case NubCStringType:
|
||||
case NubStringType:
|
||||
case NubFuncType:
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,9 +360,9 @@ public static class QBEGenerator
|
||||
return primitiveType.Kind switch
|
||||
{
|
||||
PrimitiveTypeKind.I64 or PrimitiveTypeKind.U64 or PrimitiveTypeKind.F64 => 8,
|
||||
PrimitiveTypeKind.I32 or PrimitiveTypeKind.U32 or PrimitiveTypeKind.F32 or PrimitiveTypeKind.Bool => 4,
|
||||
PrimitiveTypeKind.I32 or PrimitiveTypeKind.U32 or PrimitiveTypeKind.F32 => 4,
|
||||
PrimitiveTypeKind.I16 or PrimitiveTypeKind.U16 => 2,
|
||||
PrimitiveTypeKind.I8 or PrimitiveTypeKind.U8 => 1,
|
||||
PrimitiveTypeKind.I8 or PrimitiveTypeKind.U8 or PrimitiveTypeKind.Bool => 1,
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
@@ -423,13 +391,9 @@ public static class QBEGenerator
|
||||
case NubCStringType:
|
||||
case NubStringType:
|
||||
case NubFuncType:
|
||||
{
|
||||
return 8;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -468,27 +432,20 @@ public static class QBEGenerator
|
||||
{
|
||||
_builder.Append(returnType switch
|
||||
{
|
||||
NubArrayType => "l",
|
||||
NubPointerType => "l",
|
||||
NubPrimitiveType primitiveType => primitiveType.Kind switch
|
||||
{
|
||||
PrimitiveTypeKind.I64 => "l",
|
||||
PrimitiveTypeKind.I32 => "w",
|
||||
PrimitiveTypeKind.I64 or PrimitiveTypeKind.U64 => "l",
|
||||
PrimitiveTypeKind.I32 or PrimitiveTypeKind.U32 => "w",
|
||||
PrimitiveTypeKind.I16 => "sh",
|
||||
PrimitiveTypeKind.I8 => "sb",
|
||||
PrimitiveTypeKind.U64 => "l",
|
||||
PrimitiveTypeKind.U32 => "w",
|
||||
PrimitiveTypeKind.U16 => "uh",
|
||||
PrimitiveTypeKind.U8 => "ub",
|
||||
PrimitiveTypeKind.U8 or PrimitiveTypeKind.Bool => "ub",
|
||||
PrimitiveTypeKind.F64 => "d",
|
||||
PrimitiveTypeKind.F32 => "s",
|
||||
PrimitiveTypeKind.Bool => "w",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
},
|
||||
NubStructType structType => StructName(_definitionTable.LookupStruct(structType.Namespace, structType.Name).GetValue()),
|
||||
NubFuncType => "l",
|
||||
NubCStringType => "l",
|
||||
NubStringType => "l",
|
||||
NubArrayType or NubPointerType or NubFuncType or NubCStringType or NubStringType => "l",
|
||||
_ => throw new NotSupportedException($"'{returnType}' type cannot be used as a function return type")
|
||||
});
|
||||
_builder.Append(' ');
|
||||
@@ -500,27 +457,20 @@ public static class QBEGenerator
|
||||
{
|
||||
var qbeType = parameter.Type switch
|
||||
{
|
||||
NubArrayType => "l",
|
||||
NubPointerType => "l",
|
||||
NubPrimitiveType primitiveType => primitiveType.Kind switch
|
||||
{
|
||||
PrimitiveTypeKind.I64 => "l",
|
||||
PrimitiveTypeKind.I32 => "w",
|
||||
PrimitiveTypeKind.I64 or PrimitiveTypeKind.U64 => "l",
|
||||
PrimitiveTypeKind.I32 or PrimitiveTypeKind.U32 => "w",
|
||||
PrimitiveTypeKind.I16 => "sh",
|
||||
PrimitiveTypeKind.I8 => "sb",
|
||||
PrimitiveTypeKind.U64 => "l",
|
||||
PrimitiveTypeKind.U32 => "w",
|
||||
PrimitiveTypeKind.U16 => "uh",
|
||||
PrimitiveTypeKind.U8 => "ub",
|
||||
PrimitiveTypeKind.U8 or PrimitiveTypeKind.Bool => "ub",
|
||||
PrimitiveTypeKind.F64 => "d",
|
||||
PrimitiveTypeKind.F32 => "s",
|
||||
PrimitiveTypeKind.Bool => "w",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
},
|
||||
NubStructType structType => StructName(_definitionTable.LookupStruct(structType.Namespace, structType.Name).GetValue()),
|
||||
NubFuncType => "l",
|
||||
NubCStringType => "l",
|
||||
NubStringType => "l",
|
||||
NubArrayType or NubPointerType or NubFuncType or NubCStringType or NubStringType => "l",
|
||||
_ => throw new NotSupportedException($"'{parameter.Type}' type cannot be used as a function parameter type")
|
||||
};
|
||||
|
||||
@@ -582,27 +532,18 @@ public static class QBEGenerator
|
||||
{
|
||||
var qbeType = structDefinitionField.Type switch
|
||||
{
|
||||
NubArrayType => "l",
|
||||
NubPointerType => "l",
|
||||
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.I64 or PrimitiveTypeKind.U64 => "l",
|
||||
PrimitiveTypeKind.I32 or PrimitiveTypeKind.U32 => "w",
|
||||
PrimitiveTypeKind.I16 or PrimitiveTypeKind.U16 => "h",
|
||||
PrimitiveTypeKind.I8 or PrimitiveTypeKind.U8 or PrimitiveTypeKind.Bool => "b",
|
||||
PrimitiveTypeKind.F64 => "d",
|
||||
PrimitiveTypeKind.F32 => "s",
|
||||
PrimitiveTypeKind.Bool => "w",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
},
|
||||
NubStructType structType => StructName(_definitionTable.LookupStruct(structType.Namespace, structType.Name).GetValue()),
|
||||
NubFuncType => "l",
|
||||
NubCStringType => "l",
|
||||
NubStringType => "l",
|
||||
NubArrayType or NubPointerType or NubFuncType or NubCStringType or NubStringType => "l",
|
||||
_ => throw new NotSupportedException($"'{structDefinitionField.Type}' type cannot be used in structs")
|
||||
};
|
||||
_builder.Append(qbeType + ", ");
|
||||
@@ -1201,27 +1142,20 @@ public static class QBEGenerator
|
||||
{
|
||||
var qbeType = parameter.Type switch
|
||||
{
|
||||
NubArrayType => "l",
|
||||
NubPointerType => "l",
|
||||
NubPrimitiveType pointerType => pointerType.Kind switch
|
||||
{
|
||||
PrimitiveTypeKind.I64 => "l",
|
||||
PrimitiveTypeKind.I32 => "w",
|
||||
PrimitiveTypeKind.I64 or PrimitiveTypeKind.U64 => "l",
|
||||
PrimitiveTypeKind.I32 or PrimitiveTypeKind.U32 => "w",
|
||||
PrimitiveTypeKind.I16 => "sh",
|
||||
PrimitiveTypeKind.I8 => "sb",
|
||||
PrimitiveTypeKind.U64 => "l",
|
||||
PrimitiveTypeKind.U32 => "w",
|
||||
PrimitiveTypeKind.U16 => "uh",
|
||||
PrimitiveTypeKind.U8 => "ub",
|
||||
PrimitiveTypeKind.U8 or PrimitiveTypeKind.Bool => "ub",
|
||||
PrimitiveTypeKind.F64 => "d",
|
||||
PrimitiveTypeKind.F32 => "s",
|
||||
PrimitiveTypeKind.Bool => "w",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
},
|
||||
NubStructType structType => StructName(_definitionTable.LookupStruct(structType.Namespace, structType.Name).GetValue()),
|
||||
NubFuncType => "l",
|
||||
NubCStringType => "l",
|
||||
NubStringType => "l",
|
||||
NubArrayType or NubPointerType or NubFuncType or NubCStringType or NubStringType => "l",
|
||||
_ => throw new NotSupportedException($"'{parameter.Type}' type cannot be used in function calls")
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user