...
This commit is contained in:
@@ -195,105 +195,86 @@ public static class QBEGenerator
|
||||
return size;
|
||||
}
|
||||
|
||||
private static void EmitCopyInto(NubType type, string source, string destination)
|
||||
private static void EmitCopyInto(NubType type, string source, string destinationPointer)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case NubArrayType nubArrayType:
|
||||
case NubComplexType complexType:
|
||||
{
|
||||
var size = EmitArraySizeInBytes(nubArrayType, source);
|
||||
var buffer = VarName();
|
||||
_builder.AppendLine($" {buffer} =l alloc8 {size}");
|
||||
EmitMemcpy(source, buffer, size);
|
||||
EmitStore(type, buffer, destination);
|
||||
break;
|
||||
var size = complexType switch
|
||||
{
|
||||
NubArrayType nubArrayType => EmitArraySizeInBytes(nubArrayType, source),
|
||||
NubCStringType => EmitCStringSizeInBytes(source),
|
||||
NubStringType => EmitStringSizeInBytes(source),
|
||||
NubStructType nubStructType => SizeOf(nubStructType).ToString(),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(complexType))
|
||||
};
|
||||
|
||||
switch (complexType)
|
||||
{
|
||||
case NubArrayType:
|
||||
case NubCStringType:
|
||||
case NubStringType:
|
||||
{
|
||||
var buffer = VarName();
|
||||
_builder.AppendLine($" {buffer} =l alloc8 {size}");
|
||||
EmitMemcpy(source, buffer, size);
|
||||
EmitStore(type, buffer, destinationPointer);
|
||||
return;
|
||||
}
|
||||
case NubStructType:
|
||||
{
|
||||
EmitMemcpy(source, destinationPointer, size);
|
||||
return;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(complexType));
|
||||
}
|
||||
}
|
||||
}
|
||||
case NubCStringType:
|
||||
case NubSimpleType simpleType:
|
||||
{
|
||||
var size = EmitCStringSizeInBytes(source);
|
||||
var buffer = VarName();
|
||||
_builder.AppendLine($" {buffer} =l alloc8 {size}");
|
||||
EmitMemcpy(source, buffer, size);
|
||||
EmitStore(type, buffer, destination);
|
||||
break;
|
||||
EmitStore(simpleType, source, destinationPointer);
|
||||
return;
|
||||
}
|
||||
case NubStringType:
|
||||
{
|
||||
var size = EmitStringSizeInBytes(source);
|
||||
var buffer = VarName();
|
||||
_builder.AppendLine($" {buffer} =l alloc8 {size}");
|
||||
EmitMemcpy(source, buffer, size);
|
||||
EmitStore(type, buffer, destination);
|
||||
break;
|
||||
}
|
||||
case NubStructType nubStructType:
|
||||
{
|
||||
var size = SizeOf(nubStructType);
|
||||
EmitMemcpy(source, destination, size.ToString());
|
||||
break;
|
||||
}
|
||||
case NubPointerType:
|
||||
case NubPrimitiveType:
|
||||
{
|
||||
EmitStore(type, source, destination);
|
||||
break;
|
||||
}
|
||||
case NubVoidType:
|
||||
case NubFuncType:
|
||||
case NubAnyType:
|
||||
throw new NotSupportedException($"Cannot copy type '{type}'");
|
||||
default:
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static string EmitCopy(NubType type, string source)
|
||||
{
|
||||
var destination = VarName();
|
||||
switch (type)
|
||||
{
|
||||
case NubArrayType nubArrayType:
|
||||
case NubComplexType complexType:
|
||||
{
|
||||
var size = EmitArraySizeInBytes(nubArrayType, source);
|
||||
var destination = VarName();
|
||||
|
||||
var size = complexType switch
|
||||
{
|
||||
NubArrayType nubArrayType => EmitArraySizeInBytes(nubArrayType, source),
|
||||
NubCStringType => EmitCStringSizeInBytes(source),
|
||||
NubStringType => EmitStringSizeInBytes(source),
|
||||
NubStructType nubStructType => SizeOf(nubStructType).ToString(),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(complexType))
|
||||
};
|
||||
|
||||
_builder.AppendLine($" {destination} =l alloc8 {size}");
|
||||
EmitMemcpy(source, destination, size);
|
||||
break;
|
||||
return destination;
|
||||
}
|
||||
case NubCStringType:
|
||||
{
|
||||
var size = EmitCStringSizeInBytes(source);
|
||||
_builder.AppendLine($" {destination} =l alloc8 {size}");
|
||||
EmitMemcpy(source, destination, size);
|
||||
break;
|
||||
}
|
||||
case NubStringType:
|
||||
{
|
||||
var size = EmitStringSizeInBytes(source);
|
||||
_builder.AppendLine($" {destination} =l alloc8 {size}");
|
||||
EmitMemcpy(source, destination, size);
|
||||
break;
|
||||
}
|
||||
case NubStructType nubStructType:
|
||||
{
|
||||
var size = SizeOf(nubStructType);
|
||||
_builder.AppendLine($" {destination} =l alloc8 {size}");
|
||||
EmitMemcpy(source, destination, size.ToString());
|
||||
break;
|
||||
}
|
||||
case NubPointerType:
|
||||
case NubPrimitiveType:
|
||||
case NubSimpleType:
|
||||
{
|
||||
return source;
|
||||
}
|
||||
case NubVoidType:
|
||||
case NubFuncType:
|
||||
case NubAnyType:
|
||||
throw new NotSupportedException($"Cannot copy type '{type}'");
|
||||
default:
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(type));
|
||||
}
|
||||
}
|
||||
|
||||
return destination;
|
||||
}
|
||||
|
||||
private static string QBEAssign(NubType type)
|
||||
|
||||
Reference in New Issue
Block a user