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