This commit is contained in:
nub31
2025-06-26 15:15:01 +02:00
parent 9f20e71740
commit 3d06f40516
5 changed files with 41 additions and 18 deletions

View File

@@ -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", ["-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<bool> Link(List<string> 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,

View File

@@ -24,10 +24,31 @@ if (Directory.Exists(BIN_INT_DIR))
Directory.CreateDirectory(BIN_DIR);
Directory.CreateDirectory(BIN_INT_DIR);
var files = new List<string>();
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<Diagnostic>();
var syntaxTrees = new List<SyntaxTree>();
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<string>();
objectFiles.Add("/home/oliste/repos/nub-lang/src/runtime/runtime.o");
var objectFiles = new List<string>
{
"libruntime.a"
};
foreach (var boundSyntaxTree in boundSyntaxTrees)
{

View File

@@ -1,2 +1,2 @@
*.o
out
out-int

View File

@@ -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