Cleanup
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Nub.Lang;
|
||||
using Nub.Lang.Frontend;
|
||||
using Nub.Lang.Frontend.Generation;
|
||||
using Nub.Lang.Frontend.Lexing;
|
||||
using Nub.Lang.Frontend.Parsing;
|
||||
@@ -20,38 +21,43 @@ if (!Directory.Exists(srcDir))
|
||||
}
|
||||
|
||||
var error = false;
|
||||
var lexer = new Lexer();
|
||||
var parser = new Parser();
|
||||
var typeChecker = new TypeChecker();
|
||||
|
||||
List<SourceFile> files = [];
|
||||
List<CompilationUnit> compilationUnits = [];
|
||||
|
||||
foreach (var file in Directory.EnumerateFiles(srcDir, "*.nub", SearchOption.AllDirectories))
|
||||
{
|
||||
var content = File.ReadAllText(file);
|
||||
|
||||
var tokenizeResult = lexer.Tokenize(new SourceText(file, content));
|
||||
var tokenizeResult = Lexer.Tokenize(new SourceText(file, content));
|
||||
tokenizeResult.PrintAllDiagnostics();
|
||||
error = error || tokenizeResult.HasErrors;
|
||||
|
||||
var parseResult = parser.ParseModule(tokenizeResult.Value);
|
||||
var parseResult = Parser.ParseFile(tokenizeResult.Value);
|
||||
parseResult.PrintAllDiagnostics();
|
||||
error = error || parseResult.HasErrors;
|
||||
|
||||
if (parseResult.Value != null)
|
||||
{
|
||||
files.Add(parseResult.Value);
|
||||
compilationUnits.Add(parseResult.Value);
|
||||
}
|
||||
}
|
||||
|
||||
var typeCheckResult = typeChecker.TypeCheck(files);
|
||||
typeCheckResult.PrintAllDiagnostics();
|
||||
error = error || typeCheckResult.HasErrors;
|
||||
if (error)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (error) return 1;
|
||||
var definitionTable = new DefinitionTable(compilationUnits);
|
||||
|
||||
var generator = new QBEGenerator();
|
||||
var result = generator.Generate(files);
|
||||
foreach (var compilationUnit in compilationUnits)
|
||||
{
|
||||
var typeCheckResult = TypeChecker.Check(compilationUnit, definitionTable);
|
||||
typeCheckResult.PrintAllDiagnostics();
|
||||
error = error || typeCheckResult.HasErrors;
|
||||
|
||||
Console.Out.Write(result);
|
||||
var result = QBEGenerator.Generate(compilationUnit, definitionTable);
|
||||
|
||||
return 0;
|
||||
File.WriteAllText($"bin-int/{Guid.NewGuid():N}.ssa", result);
|
||||
}
|
||||
|
||||
return error ? 1 : 0;
|
||||
Reference in New Issue
Block a user