...
This commit is contained in:
@@ -38,6 +38,5 @@ export func main(args: []^string): i64 {
|
||||
i = i + 1
|
||||
}
|
||||
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ public static class GCC
|
||||
public static async Task<bool> Assemble(string asmPath, string objPath)
|
||||
{
|
||||
using var gccProcess = new Process();
|
||||
gccProcess.StartInfo = new ProcessStartInfo("gcc", ["-c", asmPath, "-o", objPath])
|
||||
gccProcess.StartInfo = new ProcessStartInfo("gcc", ["-g", "-c", asmPath, "-o", objPath])
|
||||
{
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
@@ -30,7 +30,7 @@ public static class GCC
|
||||
public static async Task<bool> Link(List<string> objectFiles, string outputPath)
|
||||
{
|
||||
using var gccProcess = new Process();
|
||||
gccProcess.StartInfo = new ProcessStartInfo("gcc", ["-nostartfiles", "-o", outputPath, ..objectFiles])
|
||||
gccProcess.StartInfo = new ProcessStartInfo("gcc", ["-g", "-nostartfiles", "-o", outputPath, ..objectFiles])
|
||||
{
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
.intel_Syntax noprefix
|
||||
.intel_syntax noprefix
|
||||
.extern main
|
||||
.section .text
|
||||
|
||||
.global _start
|
||||
_start:
|
||||
mov rdi, rsp
|
||||
sub rsp, 8
|
||||
mov [rsp], rdi
|
||||
mov rdi, rsp
|
||||
# func main(args: []^string): i64
|
||||
call main
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.intel_Syntax noprefix
|
||||
.intel_syntax noprefix
|
||||
.section .text
|
||||
|
||||
# func nub_memcpy(destination: ^u8, source: ^u8, count: u64): ^u8
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.intel_Syntax noprefix
|
||||
.intel_syntax noprefix
|
||||
.section .text
|
||||
|
||||
# func nub_memset(destination: ^u8, value: i8, count: u64): ^u8
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
.intel_Syntax noprefix
|
||||
.section .text
|
||||
.intel_syntax noprefix
|
||||
|
||||
# func nub_panic(message: ^u8, message_length: u64): void
|
||||
.global nub_panic
|
||||
nub_panic:
|
||||
mov rdx, rsi
|
||||
mov rsi, rdi
|
||||
mov rax, 1
|
||||
mov rdi, 2
|
||||
.section .data
|
||||
.align 8
|
||||
array_out_of_bounds:
|
||||
.ascii "Index is out of bounds of array\n"
|
||||
|
||||
.section .text
|
||||
.global nub_panic_array_oob
|
||||
nub_panic_array_oob:
|
||||
mov rax, 1 # syscall = sys_write
|
||||
mov rdi, 2 # fd = stderr
|
||||
lea rsi, [rip + array_out_of_bounds] # message
|
||||
mov rdx, 32 # message length
|
||||
syscall
|
||||
mov rax, 60
|
||||
mov rdi, 101
|
||||
|
||||
mov rax, 60 # sys_exit
|
||||
mov rdi, 101 # exit code
|
||||
syscall
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.intel_Syntax noprefix
|
||||
.intel_syntax noprefix
|
||||
.section .text
|
||||
|
||||
# func nub_strcmp(lhs: ^u8, rhs: ^u8): bool
|
||||
|
||||
@@ -13,8 +13,6 @@ namespace Generation.QBE;
|
||||
|
||||
public static class QBEGenerator
|
||||
{
|
||||
private const string OutOfBoundsMessage = "Index is out of bounds\\n";
|
||||
|
||||
private static CompilationUnit _compilationUnit = null!;
|
||||
private static DefinitionTable _definitionTable = null!;
|
||||
|
||||
@@ -65,12 +63,9 @@ public static class QBEGenerator
|
||||
_builder.AppendLine();
|
||||
}
|
||||
|
||||
_builder.AppendLine($"data $oob_message = {{ b \"{OutOfBoundsMessage}\" }}");
|
||||
|
||||
for (var i = 0; i < _strings.Count; i++)
|
||||
{
|
||||
var str = _strings[i];
|
||||
_builder.AppendLine($"data $string{i + 1} = {{ b \"{str}\", b 0 }}");
|
||||
_builder.AppendLine($"data $string{i + 1} = {{ b \"{_strings[i]}\", b 0 }}");
|
||||
}
|
||||
|
||||
return _builder.ToString();
|
||||
@@ -806,7 +801,7 @@ public static class QBEGenerator
|
||||
_builder.AppendLine($" jnz {anyOobName}, {oobLabel}, {notOobLabel}");
|
||||
|
||||
_builder.AppendLine(oobLabel);
|
||||
_builder.AppendLine($" call $nub_panic(l $oob_message, l {OutOfBoundsMessage.Length})");
|
||||
_builder.AppendLine($" call $nub_panic_array_oob()");
|
||||
|
||||
_builder.AppendLine(notOobLabel);
|
||||
}
|
||||
@@ -1146,7 +1141,6 @@ public static class QBEGenerator
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static string GenerateStructInitializer(StructInitializerNode structInitializer)
|
||||
{
|
||||
var structDefinition = _definitionTable.LookupStruct(structInitializer.StructType.Namespace, structInitializer.StructType.Name).GetValue();
|
||||
|
||||
Reference in New Issue
Block a user