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
|
||||||
bin-int
|
bin-int
|
||||||
|
|||||||
2
build.sh
2
build.sh
@@ -1,2 +1,2 @@
|
|||||||
#!/bin/bash
|
#!/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">
|
<project version="4">
|
||||||
<component name="VcsDirectoryMappings">
|
<component name="VcsDirectoryMappings">
|
||||||
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
|
||||||
|
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -13,4 +13,12 @@
|
|||||||
<ProjectReference Include="..\Nub.Lang\Nub.Lang.csproj" />
|
<ProjectReference Include="..\Nub.Lang\Nub.Lang.csproj" />
|
||||||
</ItemGroup>
|
</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>
|
</Project>
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Reflection;
|
||||||
using Nub.Lang;
|
using Nub.Lang;
|
||||||
using Nub.Lang.Frontend;
|
using Nub.Lang.Frontend;
|
||||||
using Nub.Lang.Frontend.Generation;
|
using Nub.Lang.Frontend.Generation;
|
||||||
@@ -105,40 +106,44 @@ foreach (var compilationUnit in compilationUnits)
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.Error.WriteLine($"Error processing {sourceTexts[compilationUnit].Path}: {ex.Message}");
|
Console.Error.WriteLine($"Error processing {sourceTexts[compilationUnit].Path}: {ex.Message}");
|
||||||
error = true;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error)
|
var assembly = Assembly.GetExecutingAssembly();
|
||||||
{
|
var runtimeResources = assembly.GetManifestResourceNames().Where(name => name.EndsWith(".s", StringComparison.OrdinalIgnoreCase));
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
const string RUNTIME_DIR = "src/runtime";
|
foreach (var resourceName in runtimeResources)
|
||||||
if (Directory.Exists(RUNTIME_DIR))
|
|
||||||
{
|
{
|
||||||
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);
|
Console.Error.WriteLine($"Warning: Could not load embedded resource {resourceName}");
|
||||||
var objPath = Path.Combine(BIN_INT_DIR, $"runtime_{runtimeFileName}.o");
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (error)
|
using var reader = new StreamReader(stream);
|
||||||
{
|
var assemblyCode = await reader.ReadToEndAsync();
|
||||||
return 1;
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -206,7 +211,7 @@ static async Task InvokeAssembler(string asmPath, string objPath)
|
|||||||
|
|
||||||
if (asProcess.ExitCode != 0)
|
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)
|
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