private static void ValidateEntryPoint(CodeGenerator generator, RppOptions options, Diagnostic diagnostic) { if (options.Library == false && !generator.HasMain()) { diagnostic.Error(101, "Program doesn't contain a valid entry point"); } }
private static int RunAndReturnExitCode(RppOptions options) { Diagnostic diagnostic = new Diagnostic(); RppCompiler.CompileAndSave(options, diagnostic); diagnostic.Report(); if (diagnostic.Errors.Any()) { return 1; } return 0; }
public static void CompileAndSave(RppOptions options, Diagnostic diagnostic) { string outFileName = GetOutputFileName(options); Assembly stdlib = null; if (!options.Nostdlib) { stdlib = FindStdlib(); } CodeGenerator generator = Compile(program => Parse(options.InputFiles, program), diagnostic, stdlib, outFileName); if (generator != null) { ValidateEntryPoint(generator, options, diagnostic); if (!diagnostic.Errors.Any()) { generator.Save(options.Library ? ApplicationType.Library : ApplicationType.Application); } } }
private static string GenerateOutputFileName(RppOptions options) { string ext = options.Library ? ".dll" : ".exe"; string firstFile = options.InputFiles.First(); return Path.GetFileNameWithoutExtension(firstFile) + ext; }
private static string GetOutputFileName(RppOptions options) { return !string.IsNullOrEmpty(options.Out) ? options.Out : GenerateOutputFileName(options); }