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