From 3d06f4051601076f5cf9ff16f1bc0271f7c093e4 Mon Sep 17 00:00:00 2001 From: nub31 Date: Thu, 26 Jun 2025 15:15:01 +0200 Subject: [PATCH] ... --- src/compiler/CLI/GCC.cs | 4 ++-- src/compiler/CLI/Program.cs | 32 +++++++++++++++++++++---- src/runtime/.gitignore | 4 ++-- src/runtime/makefile | 19 ++++++++------- src/runtime/{platform => targets}/x64.s | 0 5 files changed, 41 insertions(+), 18 deletions(-) rename src/runtime/{platform => targets}/x64.s (100%) diff --git a/src/compiler/CLI/GCC.cs b/src/compiler/CLI/GCC.cs index 445814c..53e0037 100644 --- a/src/compiler/CLI/GCC.cs +++ b/src/compiler/CLI/GCC.cs @@ -7,7 +7,7 @@ public static class GCC public static async Task Assemble(string asmPath, string objPath) { using var gccProcess = new Process(); - gccProcess.StartInfo = new ProcessStartInfo("gcc", ["-g", "-c", asmPath, "-o", objPath]) + gccProcess.StartInfo = new ProcessStartInfo("gcc", ["-g", "-nostdlib", "-ffreestanding", "-c", asmPath, "-o", objPath]) { UseShellExecute = false, RedirectStandardOutput = true, @@ -30,7 +30,7 @@ public static class GCC public static async Task Link(List objectFiles, string outputPath) { using var gccProcess = new Process(); - gccProcess.StartInfo = new ProcessStartInfo("gcc", ["-g", "-nostartfiles", "-o", outputPath, ..objectFiles]) + gccProcess.StartInfo = new ProcessStartInfo("gcc", ["-g", "-nostdlib", "-ffreestanding", "-o", outputPath, ..objectFiles]) { UseShellExecute = false, RedirectStandardOutput = true, diff --git a/src/compiler/CLI/Program.cs b/src/compiler/CLI/Program.cs index 289d156..ae71806 100644 --- a/src/compiler/CLI/Program.cs +++ b/src/compiler/CLI/Program.cs @@ -24,10 +24,31 @@ if (Directory.Exists(BIN_INT_DIR)) Directory.CreateDirectory(BIN_DIR); Directory.CreateDirectory(BIN_INT_DIR); +var files = new List(); + +var compileOnly = false; +string? outPath = null; + +foreach (var arg in args) +{ + if (arg == "-c") + { + compileOnly = true; + } + else if (arg.StartsWith("-o=")) + { + outPath = arg.Substring("-o=".Length); + } + else + { + files.Add(arg); + } +} + var diagnostics = new List(); var syntaxTrees = new List(); -foreach (var file in args) +foreach (var file in files) { if (!File.Exists(file)) { @@ -36,7 +57,7 @@ foreach (var file in args) } } -foreach (var file in args) +foreach (var file in files) { var content = File.ReadAllText(file); var sourceText = new SourceText(file, content); @@ -78,9 +99,10 @@ if (diagnostics.Any(diagnostic => diagnostic.Severity == DiagnosticSeverity.Erro return 1; } -var objectFiles = new List(); - -objectFiles.Add("/home/oliste/repos/nub-lang/src/runtime/runtime.o"); +var objectFiles = new List +{ + "libruntime.a" +}; foreach (var boundSyntaxTree in boundSyntaxTrees) { diff --git a/src/runtime/.gitignore b/src/runtime/.gitignore index 80f93b0..4ad964a 100644 --- a/src/runtime/.gitignore +++ b/src/runtime/.gitignore @@ -1,2 +1,2 @@ -*.o -out \ No newline at end of file +out +out-int \ No newline at end of file diff --git a/src/runtime/makefile b/src/runtime/makefile index 5cc587b..6ed4637 100644 --- a/src/runtime/makefile +++ b/src/runtime/makefile @@ -1,15 +1,16 @@ -CC = gcc +CC ?= x86_64-linux-gnu-gcc +TARGET ?= x64 + CFLAGS = -nostdlib -ffreestanding -Wall -Werror -Wextra -x64: runtime.o x64.o +libruntime: out-int/runtime.o + $(CC) $(CFLAGS) -c targets/$(TARGET).s -o out-int/$(TARGET).o mkdir -p out - ar rcs out/libruntime.a runtime.o x64.o + ar rcs out/libruntime_$(TARGET).a out-int/runtime.o out-int/$(TARGET).o -runtime.o: runtime/runtime.c - $(CC) $(CFLAGS) -c runtime/runtime.c -o runtime.o - -x64.o: runtime.o platform/x64.s - $(CC) $(CFLAGS) -c platform/x64.s -o x64.o +out-int/runtime.o: runtime/runtime.c + mkdir -p out-int + $(CC) $(CFLAGS) -c runtime/runtime.c -o out-int/runtime.o clean: - rm -r out runtime.o x64.o + rm -r out out-int diff --git a/src/runtime/platform/x64.s b/src/runtime/targets/x64.s similarity index 100% rename from src/runtime/platform/x64.s rename to src/runtime/targets/x64.s