Some cleanup
This commit is contained in:
@@ -6,8 +6,6 @@ using NubLang.Generation;
|
||||
using NubLang.Modules;
|
||||
using NubLang.Syntax;
|
||||
|
||||
var sw = Stopwatch.StartNew();
|
||||
|
||||
var options = new Options();
|
||||
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
@@ -34,9 +32,6 @@ for (var i = 0; i < args.Length; i++)
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"Parse cli args: {sw.ElapsedMilliseconds}ms");
|
||||
sw.Restart();
|
||||
|
||||
foreach (var file in options.Files)
|
||||
{
|
||||
if (!File.Exists(file))
|
||||
@@ -46,9 +41,6 @@ foreach (var file in options.Files)
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"Check file exists: {sw.ElapsedMilliseconds}ms");
|
||||
sw.Restart();
|
||||
|
||||
var diagnostics = new List<Diagnostic>();
|
||||
|
||||
var syntaxTrees = new List<SyntaxTree>();
|
||||
@@ -58,26 +50,15 @@ foreach (var file in options.Files)
|
||||
tokenizer.Tokenize();
|
||||
diagnostics.AddRange(tokenizer.Diagnostics);
|
||||
|
||||
Console.WriteLine($" Tokenize: {Path.GetFileName(file)}: {sw.ElapsedMilliseconds}ms");
|
||||
sw.Restart();
|
||||
|
||||
var parser = new Parser();
|
||||
var syntaxTree = parser.Parse(tokenizer.Tokens);
|
||||
diagnostics.AddRange(parser.Diagnostics);
|
||||
|
||||
Console.WriteLine($" Parse: {Path.GetFileName(file)}: {sw.ElapsedMilliseconds}ms");
|
||||
sw.Restart();
|
||||
|
||||
syntaxTrees.Add(syntaxTree);
|
||||
}
|
||||
|
||||
sw.Restart();
|
||||
|
||||
var moduleRepository = new ModuleRepository(syntaxTrees);
|
||||
|
||||
Console.WriteLine($"Create module repository: {sw.ElapsedMilliseconds}ms");
|
||||
sw.Restart();
|
||||
|
||||
var definitions = new List<DefinitionNode>();
|
||||
|
||||
var referencedStructTypes = new HashSet<NubStructType>();
|
||||
@@ -87,9 +68,6 @@ foreach (var syntaxTree in syntaxTrees)
|
||||
var typeChecker = new TypeChecker(syntaxTree, moduleRepository);
|
||||
typeChecker.Check();
|
||||
|
||||
Console.WriteLine($" Type check {syntaxTree.Metadata.ModuleName}: {sw.ElapsedMilliseconds}ms");
|
||||
sw.Restart();
|
||||
|
||||
definitions.AddRange(typeChecker.Definitions);
|
||||
diagnostics.AddRange(typeChecker.Diagnostics);
|
||||
|
||||
@@ -99,16 +77,11 @@ foreach (var syntaxTree in syntaxTrees)
|
||||
}
|
||||
}
|
||||
|
||||
sw.Restart();
|
||||
|
||||
foreach (var diagnostic in diagnostics)
|
||||
{
|
||||
Console.Error.WriteLine(diagnostic.FormatANSI());
|
||||
}
|
||||
|
||||
Console.WriteLine($"Print diagnostics: {sw.ElapsedMilliseconds}ms");
|
||||
sw.Restart();
|
||||
|
||||
if (diagnostics.Any(diagnostic => diagnostic.Severity == DiagnosticSeverity.Error))
|
||||
{
|
||||
return 1;
|
||||
@@ -116,38 +89,20 @@ if (diagnostics.Any(diagnostic => diagnostic.Severity == DiagnosticSeverity.Erro
|
||||
|
||||
Directory.CreateDirectory(".build");
|
||||
|
||||
var generator = new CGenerator(definitions, referencedStructTypes);
|
||||
var generator = new Generator(definitions, referencedStructTypes);
|
||||
var c = generator.Emit();
|
||||
var cFilePath = Path.Combine(".build", "out.c");
|
||||
|
||||
File.WriteAllText(cFilePath, c);
|
||||
|
||||
var objFilePath = Path.Combine(".build", "out.o");
|
||||
var asmSuccess = await GCC.Compile(cFilePath, objFilePath);
|
||||
if (!asmSuccess) return 1;
|
||||
using var process = Process.Start("gcc", ["-ffreestanding", "-nostartfiles", "-c", "-o", Path.Combine(".build", "out.o"), cFilePath]);
|
||||
|
||||
// sw.Restart();
|
||||
//
|
||||
// var generator = new QBEGenerator(definitions, referencedStructTypes);
|
||||
// var ssa = generator.Emit();
|
||||
// var ssaFilePath = Path.Combine(".build", "out.ssa");
|
||||
// File.WriteAllText(ssaFilePath, ssa);
|
||||
//
|
||||
// Console.WriteLine($"Emit ssa: {sw.ElapsedMilliseconds}ms");
|
||||
// sw.Restart();
|
||||
//
|
||||
// var asmFilePath = Path.Combine(".build", "out.asm");
|
||||
// var qbeSuccess = await QBE.Invoke(ssaFilePath, asmFilePath);
|
||||
// if (!qbeSuccess) return 1;
|
||||
//
|
||||
// Console.WriteLine($"Emit asm: {sw.ElapsedMilliseconds}ms");
|
||||
// sw.Restart();
|
||||
//
|
||||
// var objFilePath = Path.Combine(".build", "out.o");
|
||||
// var asmSuccess = await GCC.Assemble(asmFilePath, objFilePath);
|
||||
// if (!asmSuccess) return 1;
|
||||
//
|
||||
// Console.WriteLine($"Assemble: {sw.ElapsedMilliseconds}ms");
|
||||
sw.Restart();
|
||||
process.WaitForExit();
|
||||
|
||||
if (process.ExitCode != 0)
|
||||
{
|
||||
Console.Error.WriteLine($"gcc failed with exit code {process.ExitCode}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
Reference in New Issue
Block a user