...
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using System.Reflection;
|
||||
using NubLang.CLI;
|
||||
using NubLang;
|
||||
using NubLang.Code;
|
||||
using NubLang.Common;
|
||||
using NubLang.Diagnostics;
|
||||
using NubLang.Generation;
|
||||
@@ -62,16 +62,16 @@ for (var i = 0; i < args.Length; i++)
|
||||
}
|
||||
else
|
||||
{
|
||||
options.Files.Add(arg);
|
||||
options.Files.Add(new SourceFile(arg));
|
||||
}
|
||||
}
|
||||
|
||||
var diagnostics = new List<Diagnostic>();
|
||||
var syntaxTrees = new Dictionary<string, SyntaxTree>();
|
||||
var syntaxTrees = new List<SyntaxTree>();
|
||||
|
||||
foreach (var file in options.Files)
|
||||
{
|
||||
if (!File.Exists(file))
|
||||
if (!File.Exists(file.Path))
|
||||
{
|
||||
Console.Error.WriteLine($"File '{file}' does not exist");
|
||||
return 1;
|
||||
@@ -80,30 +80,27 @@ foreach (var file in options.Files)
|
||||
|
||||
foreach (var file in options.Files)
|
||||
{
|
||||
var content = File.ReadAllText(file);
|
||||
var sourceText = new SourceText(file, content);
|
||||
|
||||
var tokenizer = new Tokenizer(sourceText);
|
||||
var tokenizer = new Tokenizer(file.GetText());
|
||||
var tokenizeResult = tokenizer.Tokenize(out var tokenizerDiagnostics);
|
||||
diagnostics.AddRange(tokenizerDiagnostics);
|
||||
|
||||
var parser = new Parser(tokenizeResult);
|
||||
var syntaxTree = parser.Parse();
|
||||
diagnostics.AddRange(syntaxTree.Diagnostics);
|
||||
var syntaxTree = parser.Parse(out var parserDiagnostics);
|
||||
diagnostics.AddRange(parserDiagnostics);
|
||||
|
||||
syntaxTrees[file] = syntaxTree;
|
||||
syntaxTrees.Add(syntaxTree);
|
||||
}
|
||||
|
||||
var definitionTable = new DefinitionTable(syntaxTrees.Values);
|
||||
var definitionTable = new DefinitionTable(syntaxTrees);
|
||||
|
||||
var boundSyntaxTrees = new Dictionary<string, BoundSyntaxTree>();
|
||||
var boundSyntaxTrees = new List<BoundSyntaxTree>();
|
||||
|
||||
foreach (var (file, syntaxTree) in syntaxTrees)
|
||||
foreach (var syntaxTree in syntaxTrees)
|
||||
{
|
||||
var binder = new Binder(syntaxTree, definitionTable);
|
||||
var boundSyntaxTree = binder.Bind();
|
||||
diagnostics.AddRange(boundSyntaxTree.Diagnostics);
|
||||
boundSyntaxTrees[file] = boundSyntaxTree;
|
||||
boundSyntaxTrees.Add(boundSyntaxTree);
|
||||
}
|
||||
|
||||
foreach (var diagnostic in diagnostics)
|
||||
@@ -116,15 +113,15 @@ if (diagnostics.Any(diagnostic => diagnostic.Severity == DiagnosticSeverity.Erro
|
||||
return 1;
|
||||
}
|
||||
|
||||
var boundDefinitionTable = new BoundDefinitionTable(boundSyntaxTrees.Values);
|
||||
var boundDefinitionTable = new BoundDefinitionTable(boundSyntaxTrees);
|
||||
|
||||
var objectFiles = new List<string>();
|
||||
|
||||
foreach (var file in options.Files)
|
||||
foreach (var syntaxTree in boundSyntaxTrees)
|
||||
{
|
||||
var outFileName = $"{HexString.CreateUnique(8)}_{Path.GetFileNameWithoutExtension(file)}";
|
||||
var outFileName = HexString.CreateUnique(8);
|
||||
|
||||
var generator = new QBEGenerator(boundSyntaxTrees[file], boundDefinitionTable, file);
|
||||
var generator = new QBEGenerator(syntaxTree, boundDefinitionTable);
|
||||
var ssa = generator.Emit();
|
||||
File.WriteAllText(Path.Join(INT_DEBUG_DIR, $"{outFileName}.ssa"), ssa);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user