...
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using NubLang.Ast;
|
||||
using NubLang.Ast;
|
||||
using NubLang.Diagnostics;
|
||||
using NubLang.Generation;
|
||||
using NubLang.Syntax;
|
||||
@@ -42,62 +41,22 @@ if (diagnostics.Any(diagnostic => diagnostic.Severity == DiagnosticSeverity.Erro
|
||||
return 1;
|
||||
}
|
||||
|
||||
var cPaths = new List<string>();
|
||||
|
||||
Directory.CreateDirectory(".build");
|
||||
|
||||
var typedModules = modules.Select(x => (x.Key, TypedModule.FromModule(x.Key, x.Value, modules))).ToDictionary();
|
||||
|
||||
Directory.CreateDirectory(Path.Combine(".build", "modules"));
|
||||
|
||||
foreach (var typedModule in typedModules)
|
||||
{
|
||||
var header = HeaderGenerator.Generate(typedModule.Key, typedModule.Value);
|
||||
var headerOut = Path.Combine(Path.Combine(".build", "modules"), typedModule.Key + ".h");
|
||||
File.WriteAllText(headerOut, header);
|
||||
}
|
||||
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
var file = args[i];
|
||||
var compilationUnit = compilationUnits[i];
|
||||
|
||||
var generator = new Generator(compilationUnit);
|
||||
var generator = new LlvmGenerator();
|
||||
var directory = Path.GetDirectoryName(file);
|
||||
if (!string.IsNullOrWhiteSpace(directory))
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(".build", directory));
|
||||
}
|
||||
|
||||
var path = Path.Combine(".build", Path.ChangeExtension(file, "c"));
|
||||
File.WriteAllText(path, generator.Emit());
|
||||
cPaths.Add(path);
|
||||
var path = Path.Combine(".build", Path.ChangeExtension(file, "ll"));
|
||||
File.WriteAllText(path, generator.Emit(compilationUnit));
|
||||
}
|
||||
|
||||
var objectPaths = new List<string>();
|
||||
|
||||
foreach (var cPath in cPaths)
|
||||
{
|
||||
var objectPath = Path.ChangeExtension(cPath, "o");
|
||||
using var compileProcess = Process.Start("clang", [
|
||||
"-I.build",
|
||||
"-ffreestanding", "-std=c23",
|
||||
"-g", "-c",
|
||||
"-o", objectPath,
|
||||
cPath,
|
||||
]);
|
||||
|
||||
compileProcess.WaitForExit();
|
||||
|
||||
if (compileProcess.ExitCode != 0)
|
||||
{
|
||||
Console.Error.WriteLine($"clang failed with exit code {compileProcess.ExitCode}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
objectPaths.Add(objectPath);
|
||||
}
|
||||
|
||||
Console.Out.WriteLine(string.Join(' ', objectPaths));
|
||||
|
||||
return 0;
|
||||
Reference in New Issue
Block a user