restructure
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,3 @@
|
||||
src/tools/syntax-highlighting/out
|
||||
tools/syntax-highlighting/out
|
||||
bin
|
||||
bin-int
|
||||
|
||||
2
build.sh
2
build.sh
@@ -1,2 +1,2 @@
|
||||
#!/bin/bash
|
||||
dotnet run --project src/lang/Nub.Lang.CLI/ example
|
||||
dotnet run --project src/Nub.Lang.CLI/ example
|
||||
0
src/lang/.gitignore → src/.gitignore
vendored
0
src/lang/.gitignore → src/.gitignore
vendored
@@ -2,5 +2,6 @@
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -13,4 +13,12 @@
|
||||
<ProjectReference Include="..\Nub.Lang\Nub.Lang.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Runtime\entry.s" />
|
||||
<EmbeddedResource Include="Runtime\nub_memcpy.s" />
|
||||
<EmbeddedResource Include="Runtime\nub_memset.s" />
|
||||
<EmbeddedResource Include="Runtime\nub_panic.s" />
|
||||
<EmbeddedResource Include="Runtime\nub_strcmp.s" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using Nub.Lang;
|
||||
using Nub.Lang.Frontend;
|
||||
using Nub.Lang.Frontend.Generation;
|
||||
@@ -105,40 +106,44 @@ foreach (var compilationUnit in compilationUnits)
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"Error processing {sourceTexts[compilationUnit].Path}: {ex.Message}");
|
||||
error = true;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (error)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
var runtimeResources = assembly.GetManifestResourceNames().Where(name => name.EndsWith(".s", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
const string RUNTIME_DIR = "src/runtime";
|
||||
if (Directory.Exists(RUNTIME_DIR))
|
||||
foreach (var resourceName in runtimeResources)
|
||||
{
|
||||
foreach (var runtimeFile in Directory.EnumerateFiles(RUNTIME_DIR, "*.s", SearchOption.AllDirectories))
|
||||
try
|
||||
{
|
||||
try
|
||||
await using var stream = assembly.GetManifestResourceStream(resourceName);
|
||||
if (stream == null)
|
||||
{
|
||||
var runtimeFileName = Path.GetFileNameWithoutExtension(runtimeFile);
|
||||
var objPath = Path.Combine(BIN_INT_DIR, $"runtime_{runtimeFileName}.o");
|
||||
Console.Error.WriteLine($"Warning: Could not load embedded resource {resourceName}");
|
||||
continue;
|
||||
}
|
||||
|
||||
await InvokeAssembler(runtimeFile, objPath);
|
||||
objectFiles.Add(objPath);
|
||||
Console.Out.WriteLine($"Runtime assembled: {objPath}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"Error assembling runtime file {runtimeFile}: {ex.Message}");
|
||||
error = true;
|
||||
}
|
||||
using var reader = new StreamReader(stream);
|
||||
var assemblyCode = await reader.ReadToEndAsync();
|
||||
|
||||
var fileName = resourceName.Split('.').Reverse().Skip(1).First();
|
||||
var asmPath = Path.Combine(BIN_INT_DIR, $"runtime_{fileName}.s");
|
||||
var objPath = Path.Combine(BIN_INT_DIR, $"runtime_{fileName}.o");
|
||||
|
||||
await File.WriteAllTextAsync(asmPath, assemblyCode);
|
||||
|
||||
await InvokeAssembler(asmPath, objPath);
|
||||
objectFiles.Add(objPath);
|
||||
Console.Out.WriteLine($"Runtime assembled: {objPath}");
|
||||
|
||||
File.Delete(asmPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Error.WriteLine($"Error processing runtime resource {resourceName}: {ex.Message}");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (error)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
try
|
||||
@@ -206,7 +211,7 @@ static async Task InvokeAssembler(string asmPath, string objPath)
|
||||
|
||||
if (asProcess.ExitCode != 0)
|
||||
{
|
||||
throw new Exception($"Assembler failed for {asmPath}:\n{asErrors}");
|
||||
throw new Exception($"Assembler errors:\n{asErrors}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,6 +235,6 @@ static async Task InvokeLinker(List<string> objectFiles, string outputPath)
|
||||
|
||||
if (gccProcess.ExitCode != 0)
|
||||
{
|
||||
throw new Exception($"Linker failed:\n{gccErrors}");
|
||||
throw new Exception($"Linker errors:\n{gccErrors}");
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
.intel_syntax noprefix
|
||||
.global core_syscall
|
||||
.section .text
|
||||
|
||||
core_syscall:
|
||||
mov rax, rdi
|
||||
mov rdi, rsi
|
||||
mov rsi, rdx
|
||||
mov r10, rcx
|
||||
syscall
|
||||
ret
|
||||
Reference in New Issue
Block a user