This is the detail logger TODO(kai): describe this better, please.
Exemplo n.º 1
0
 public ModCompiler(DetailLogger log, SymbolTableWalker walker,
     LLVMContextRef context, LLVMModuleRef module, LLVMBuilderRef builder)
 {
     this.log = log;
     this.walker = walker;
     this.context = context;
     this.module = module;
     this.builder = builder;
 }
Exemplo n.º 2
0
        public Ast Parse(DetailLogger log, TokenList tokens, string fileName)
        {
            var state = new ParserState(log, tokens, fileName);

            var ast = new Ast();
            // TODO(kai): actually run a parser loop.
            while (true)
            {
                //Console.WriteLine("Attempting to parse");
                var node = state.ParseTopLevel();
                if (node == null)
                    break;
                ast.children.Add(node);
            }

            return ast;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns a list of all tokens in the given file.
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="encoding"></param>
        /// <returns></returns>
        public TokenList GetTokens(DetailLogger log, string fileName, Encoding encoding = null)
        {
            // TODO(kai): check that a file exists.
            // also, just more error checking is a good idea.

            var result = new List<Token>();
            // Use a separate state so that this object itself can be used in multiple threads, hopefully.
            var state = new LexerState(log, fileName, encoding);

            while (true)
            {
                var token = state.GetToken();
                // If no token was returned, just break.
                // If errors happened, they should be addressed outside the lexer.
                if (token == null)
                    break;
                result.Add(token);
                //Console.WriteLine(token);
            }

            return new TokenList(result);
        }
Exemplo n.º 4
0
 public ScoreCompiler(DetailLogger log)
 {
     this.log = log;
 }
Exemplo n.º 5
0
 public ModAnalyzer(DetailLogger log, SymbolTable symbols)
 {
     this.log = log;
     this.symbols = symbols;
 }
Exemplo n.º 6
0
 public TypeChecker(DetailLogger log)
 {
     this.log = log;
 }
Exemplo n.º 7
0
 public TyChecker(DetailLogger log, SymbolTableWalker walker)
 {
     this.log = log;
     this.walker = walker;
 }
Exemplo n.º 8
0
 public TyResolver(DetailLogger log)
 {
     this.log = log;
 }
Exemplo n.º 9
0
 public LexerState(DetailLogger log, string fileName, Encoding encoding)
 {
     this.log = log;
     source = File.ReadAllText(this.fileName = fileName, encoding ?? Encoding.UTF8);
     Advance();
 }
Exemplo n.º 10
0
 public SemanticAnalyzer(DetailLogger log)
 {
     this.log = log;
 }
Exemplo n.º 11
0
 public ParserState(DetailLogger log, TokenList tokens, string fileName)
 {
     this.log = log;
     this.tokens = tokens;
     this.fileName = fileName;
 }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            // TODO(kai): parse out the args and do things

            if (args.Length == 0)
            {
                Console.WriteLine("No file passed to compile.");
                Wait();
                return;
            }

            var filePath = args[0];
            var dir = Path.GetDirectoryName(filePath);
            var fileName = Path.GetFileNameWithoutExtension(filePath);

            var log = new DetailLogger();

            var lexer = new Lexer();
            var tokens = lexer.GetTokens(log, filePath);

            if (log.HasErrors)
            {
                Fail(log);
                return;
            }

            var parser = new Parser();
            var ast = parser.Parse(log, tokens, filePath);

            if (log.HasErrors)
            {
                Fail(log);
                return;
            }

            var writer = new AstWriter(Console.Out);
            writer.Visit(ast);

            var semantics = new SemanticAnalyzer(log);
            var symbols = semantics.Analyze(ast);

            if (log.HasErrors)
            {
                Fail(log);
                return;
            }

            Console.WriteLine(symbols);

            var tyChecker = new TypeChecker(log);
            tyChecker.Check(ast, symbols);

            if (log.HasErrors)
            {
                Fail(log);
                return;
            }

            var compiler = new ScoreCompiler(log);
            var module = compiler.Compile(fileName, ast, symbols);

            if (log.HasErrors)
            {
                Fail(log);
                return;
            }

            DumpModule(module);
            var bcFilePath = Path.Combine(dir, fileName + ".bc");
            WriteBitcodeToFile(module, bcFilePath);

            /*
            // Run the interpreter!
            Console.WriteLine();
            Console.WriteLine("Interpreting:");
            var cmd = @"/c ..\..\..\..\TEST_FILES\lli.exe " + bcFilePath;
            //Console.WriteLine(cmd);
            var processInfo = new ProcessStartInfo("cmd.exe", cmd);
            processInfo.CreateNoWindow = false;
            processInfo.UseShellExecute = false;
            processInfo.RedirectStandardOutput = true;
            processInfo.RedirectStandardError = true;

            var process = Process.Start(processInfo);
            process.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
            {
                Console.WriteLine(e.Data);
            };
            process.BeginOutputReadLine();

            process.WaitForExit();
            //*/

            Wait();
        }
Exemplo n.º 13
0
 private static void Fail(DetailLogger log)
 {
     log.Print(Console.Out);
     Console.WriteLine(Environment.NewLine + "Compilation failed.");
     Console.ReadLine();
 }