/// <summary>Raised when the compiler pushes a message.</summary>
 /// <param name="sender">The sender.</param>
 /// <param name="args">The event args.</param>
 private void BethesdaCompilerNotify(object sender, PCompiler.CompilerNotifyEventArgs args)
 {
     this.OnCompilerNotify(sender, new CompilerNotifyEventArgs(args.sMessage));
 }
Ejemplo n.º 2
0
        private int TestPc(TestConfig config, TextWriter tmpWriter, DirectoryInfo workDirectory, string activeDirectory, CompilerOutput outputLanguage)
        {
            List <string> pFiles = workDirectory.EnumerateFiles("*.p").Select(pFile => pFile.FullName).ToList();

            if (!pFiles.Any())
            {
                throw new Exception("no .p file found in test directory");
            }

            string inputFileName = pFiles.First();
            string linkFileName  = Path.ChangeExtension(inputFileName, ".4ml");

            var compilerOutput = new CompilerTestOutputStream(tmpWriter);
            var compileArgs    = new CommandLineOptions
            {
                inputFileNames = new List <string>(pFiles),
                shortFileNames = true,
                outputDir      = workDirectory.FullName,
                unitName       = linkFileName,
                //liveness = LivenessOption.None,
                liveness = (outputLanguage == CompilerOutput.Zing && config.Arguments.Contains("/liveness")) ? LivenessOption.Standard
                            : LivenessOption.None,
                compilerOutput = outputLanguage
            };

            // Compile
            if (!PCompiler.Compile(compilerOutput, compileArgs))
            {
                tmpWriter.WriteLine("EXIT: -1");
                return(-1);
            }

            // Link
            compileArgs.dependencies.Add(linkFileName);
            compileArgs.inputFileNames.Clear();

            if (config.Link != null)
            {
                compileArgs.inputFileNames.Add(Path.Combine(activeDirectory, config.Link));
            }

            if (!PCompiler.Link(compilerOutput, compileArgs))
            {
                tmpWriter.WriteLine("EXIT: -1");
                return(-1);
            }
            //pc.exe with Zing option is called when outputLanguage is C;
            //pc.exe with CSharp option is called when outputLanguage is CSharp;
            if (outputLanguage == CompilerOutput.C)
            {
                // compile *.p again, this time with Zing option:
                compileArgs.compilerOutput = CompilerOutput.Zing;
                compileArgs.inputFileNames = new List <string>(pFiles);
                compileArgs.dependencies.Clear();
                int zingResult = PCompiler.Compile(compilerOutput, compileArgs) ? 0 : -1;
                tmpWriter.WriteLine($"EXIT: {zingResult}");
                if (!(zingResult == 0))
                {
                    return(-1);
                }
            }
            if (outputLanguage == CompilerOutput.CSharp)
            {
                // compile *.p again, this time with CSharp option:
                compileArgs.compilerOutput = CompilerOutput.CSharp;
                compileArgs.inputFileNames = new List <string>(pFiles);
                compileArgs.dependencies.Clear();
                if (!PCompiler.Compile(compilerOutput, compileArgs))
                {
                    tmpWriter.WriteLine("EXIT: -1");
                    return(-1);
                }
                else
                {
                    tmpWriter.WriteLine("EXIT: 0");
                }
            }

            return(0);
        }
 /// <summary>Raised when the compiler pushes an error.</summary>
 /// <param name="sender">The sender.</param>
 /// <param name="args">The args.</param>
 private void BethesdaCompilerError(object sender, PCompiler.CompilerErrorEventArgs args)
 {
     this.OnCompilerError(sender, new CompilerErrorEventArgs(args.Message, args.Filename, args.LineNumber, args.ColumnNumber));
 }