...
This commit is contained in:
@@ -77,9 +77,6 @@ var objectFiles = new List<string>();
|
||||
|
||||
foreach (var compilationUnit in compilationUnits)
|
||||
{
|
||||
var ssa = QBEGenerator.Generate(compilationUnit, definitionTable);
|
||||
var asm = await QBE.Invoke(ssa);
|
||||
|
||||
var relativeFilePath = Path.GetRelativePath(Environment.CurrentDirectory, sourceTexts[compilationUnit].Path);
|
||||
var outputPath = Path.Combine(BIN_INT_DIR, "program", relativeFilePath);
|
||||
|
||||
@@ -87,6 +84,9 @@ foreach (var compilationUnit in compilationUnits)
|
||||
Debug.Assert(!string.IsNullOrWhiteSpace(outputDirectory));
|
||||
Directory.CreateDirectory(outputDirectory);
|
||||
|
||||
var ssa = QBEGenerator.Generate(compilationUnit, definitionTable);
|
||||
var asm = await QBE.Invoke(ssa);
|
||||
|
||||
var asmPath = Path.ChangeExtension(outputPath, "s");
|
||||
await File.WriteAllTextAsync(asmPath, asm);
|
||||
|
||||
|
||||
@@ -86,18 +86,23 @@ public static class QBEGenerator
|
||||
return $"@l{++_labelIndex}";
|
||||
}
|
||||
|
||||
private static string FuncName(IFuncSignature func)
|
||||
private static string FuncName(IFuncSignature funcDef)
|
||||
{
|
||||
return func switch
|
||||
return funcDef switch
|
||||
{
|
||||
ExternFuncDefinitionNode externFuncDefinition => $"${externFuncDefinition.CallName}",
|
||||
LocalFuncDefinitionNode localFuncDefinition => localFuncDefinition.Exported
|
||||
? $"${localFuncDefinition.Name}"
|
||||
: $"${localFuncDefinition.Namespace}_{localFuncDefinition.Name}",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(func))
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(funcDef))
|
||||
};
|
||||
}
|
||||
|
||||
private static string StructName(StructDefinitionNode structDef)
|
||||
{
|
||||
return $":{structDef.Namespace}_{structDef.Name}";
|
||||
}
|
||||
|
||||
private static string QBEStore(NubType type)
|
||||
{
|
||||
return type switch
|
||||
@@ -349,7 +354,7 @@ public static class QBEGenerator
|
||||
PrimitiveTypeKind.Bool => "w",
|
||||
_ => throw new UnreachableException()
|
||||
},
|
||||
NubStructType structType => $":{structType.Namespace}_{structType.Name}",
|
||||
NubStructType structType => StructName(_definitionTable.LookupStruct(structType.Namespace, structType.Name).GetValue()),
|
||||
NubFixedArrayType => "l",
|
||||
NubFuncType => "l",
|
||||
_ => throw new NotSupportedException($"'{returnType}' type cannot be used as a function return type")
|
||||
@@ -380,7 +385,7 @@ public static class QBEGenerator
|
||||
PrimitiveTypeKind.Bool => "w",
|
||||
_ => throw new UnreachableException()
|
||||
},
|
||||
NubStructType structType => $":{structType.Namespace}_{structType.Name}",
|
||||
NubStructType structType => StructName(_definitionTable.LookupStruct(structType.Namespace, structType.Name).GetValue()),
|
||||
NubFixedArrayType => "l",
|
||||
NubFuncType => "l",
|
||||
_ => throw new NotSupportedException($"'{parameter.Type}' type cannot be used as a function parameter type")
|
||||
@@ -439,7 +444,7 @@ public static class QBEGenerator
|
||||
|
||||
private static void GenerateStructDefinition(StructDefinitionNode structDefinition)
|
||||
{
|
||||
_builder.Append($"type :{structDefinition.Namespace}_{structDefinition.Name} = {{ ");
|
||||
_builder.Append($"type {StructName(structDefinition)} = {{ ");
|
||||
foreach (var structDefinitionField in structDefinition.Fields)
|
||||
{
|
||||
var qbeType = structDefinitionField.Type switch
|
||||
@@ -461,7 +466,7 @@ public static class QBEGenerator
|
||||
PrimitiveTypeKind.Bool => "w",
|
||||
_ => throw new UnreachableException()
|
||||
},
|
||||
NubStructType structType => $":{structType.Namespace}_{structType.Name}",
|
||||
NubStructType structType => StructName(_definitionTable.LookupStruct(structType.Namespace, structType.Name).GetValue()),
|
||||
NubFixedArrayType fixedArrayType => $"b {SizeOf(fixedArrayType)}",
|
||||
NubFuncType => "l",
|
||||
_ => throw new NotSupportedException($"'{structDefinitionField.Type}' type cannot be used in structs")
|
||||
@@ -1320,7 +1325,7 @@ public static class QBEGenerator
|
||||
PrimitiveTypeKind.Bool => "w",
|
||||
_ => throw new ArgumentOutOfRangeException()
|
||||
},
|
||||
NubStructType structType => $":{structType.Namespace}_{structType.Name}",
|
||||
NubStructType structType => StructName(_definitionTable.LookupStruct(structType.Namespace, structType.Name).GetValue()),
|
||||
NubFixedArrayType => "l",
|
||||
NubFuncType => "l",
|
||||
_ => throw new NotSupportedException($"'{parameter.Type}' type cannot be used in function calls")
|
||||
|
||||
Reference in New Issue
Block a user