private static void QuickCompileCodePatch(string inputAinFileName, string jafFileName, string outputAinFileName) { var ainFile = new AinFile(inputAinFileName); var compiler = new Compiler.Compiler(ainFile, 0); compiler.Error += new EventHandler <ErrorEventArgs>(compiler_Error); compiler.CompileCodeInPlace(new string[] { jafFileName }); ainFile.WriteAndEncryptAinFile(outputAinFileName, ZLibNet.CompressionLevel.BestSpeed); }
public void Compile(string projectFilename) { this.stopwatch.Start(); var lastDefaultAinFile = Expression.defaultAinFile; try { Expression.defaultAinFile = this.ainFile; if (worker != null) { worker.ReportProgress(0, "Loading files..."); } List <TokenExpression> tokens = new List <TokenExpression>(); PreprocessInclude(projectFilename, tokens); if (this.TargetVMVersion >= 430) { this.UseSimplifiedCode = true; } ainFile.Version = this.AinVersion; ainFile.TargetVMVersion = this.TargetVMVersion; ainFile.KeyCode = this.KeyCode; ainFile.IsAi2File = this.IsAi2File; ainFile.UsesMsg1 = this.UsesMsg1; ainFile.GameVersion = this.gameVersion; ainFile.UseSimplifiedCode = this.UseSimplifiedCode; if (ainFile.Version >= 6) { this.Messages.DoNotCombine = true; } if (worker != null) { worker.ReportProgress(20, "First pass, finding functions and classes and other symbols..."); } var firstPass = new FirstPass(); if (this.Error != null) { firstPass.Error += this.Error; } var result = firstPass.CompileFirstPass(tokens); if (firstPass.Errors.Count > 0) { return; } var functionsToOutput = CreateSymbols(result); GetInitialValues(result); DefineZeroFunction(); if (worker != null) { worker.ReportProgress(40, "Second pass, parsing the code..."); } if (!CompileSecondPass()) { return; } if (worker != null) { worker.ReportProgress(60, "Compiling the code..."); } GenerateExpressions(); if (worker != null) { worker.ReportProgress(80, "Generating binary code..."); } //List<object> FunctionsToOutput = GetFunctionsToOutput(tokens); string prefixLowercase = Path.GetFullPath(mainSourcePrefix).ToLowerInvariant(); if (!prefixLowercase.EndsWith(Path.DirectorySeparatorChar.ToString())) { prefixLowercase += Path.DirectorySeparatorChar; } var codeGenerator = new CodeGenerator(ainFile); foreach (var node in functionsToOutput) { var function = node as Function; if (function != null) { var expression = this.FunctionDefinitions.GetOrNull(function); function.Address = codeGenerator.Address + 6; codeGenerator.GenerateCodeForFunction(expression); } string filename = node as string; if (filename != null) { filename = Path.GetFullPath(filename); if (filename.StartsWith(prefixLowercase, StringComparison.OrdinalIgnoreCase)) { filename = filename.Substring(prefixLowercase.Length); } else { } int fileNameNumber = ainFile.Filenames.Count; ainFile.Filenames.Add(filename); codeGenerator.WriteInstruction(Instruction.EOF, fileNameNumber); } } ainFile.Code = codeGenerator.Code.ToArray(); string outputFileName = Path.Combine(Path.GetDirectoryName(projectFilename), this.codeName); ainFile.MAIN = Functions.Contains("main") ? (Functions.Get("main").Index) : -1; ainFile.MSGF = Functions.Contains("message") ? (Functions.Get("message").Index) : -1; ainFile.OJMP = Functions.Contains("onjump") ? (Functions.Get("onjump").Index) : -1; RemoveFunctypes(ainFile); FixStructs(ainFile); ainFile.ComputeFunctionHashes(); SortGlobalInitialValues(ainFile); SortSwitchCases(ainFile); if (worker != null) { worker.ReportProgress(100, "Saving AIN file..."); } ainFile.WriteAndEncryptAinFile(outputFileName); ainFile.OriginalFilename = outputFileName; } finally { Expression.defaultAinFile = lastDefaultAinFile; } }