private static DiagnosticsReport ParseAndIdentify(string source, NativeDB?nativeDB = null) { using var sourceReader = new StringReader($@" {source}"); var d = new DiagnosticsReport(); var p = new Parser(sourceReader, "test.sc"); p.Parse(d); var globalSymbols = GlobalSymbolTableBuilder.Build(p.OutputAst, d); IdentificationVisitor.Visit(p.OutputAst, d, globalSymbols, nativeDB ?? NativeDB.Empty); return(d); }
private static DiagnosticsReport TypeCheck(string source) { using var sourceReader = new StringReader(source); var d = new DiagnosticsReport(); var p = new Parser(sourceReader, "test.sc"); p.Parse(d); var globalSymbols = GlobalSymbolTableBuilder.Build(p.OutputAst, d); IdentificationVisitor.Visit(p.OutputAst, d, globalSymbols, NativeDB.Empty); TypeChecker.Check(p.OutputAst, d, globalSymbols); return(d); }
private static void Parse(string filePath, NativeDB nativeDB) { using var r = new StreamReader(filePath); var d = new DiagnosticsReport(); var sw = Stopwatch.StartNew(); var p = new Parser(r, filePath) { UsingResolver = new FileUsingResolver() }; p.Parse(d); sw.Stop(); Console.WriteLine(sw.Elapsed); //d.PrintAll(Console.Out); var globalSymbols = GlobalSymbolTableBuilder.Build(p.OutputAst, d); IdentificationVisitor.Visit(p.OutputAst, d, globalSymbols, nativeDB); TypeChecker.Check(p.OutputAst, d, globalSymbols); //d.PrintAll(Console.Out); ; if (!d.HasErrors) { Console.WriteLine("CodeGen..."); using var sink = new StringWriter(); new CodeGenerator(sink, p.OutputAst, globalSymbols, d, nativeDB).Generate(); var s = sink.ToString(); ; using var reader = new StringReader(s); var assembler = Assembler.Assemble(reader, Path.ChangeExtension(filePath, "scasm"), nativeDB, options: new() { IncludeFunctionNames = true }); assembler.Diagnostics.PrintAll(Console.Out); ; } d.PrintAll(Console.Out); ; }