Exemple #1
0
        public void MakeObjectFile()
        {
            var asm = app.GetService <ICodeBuilderService>().
                      RunBuilder <CompiledAssembly>(sci.Text, app.Document(), BuildOptions.Output | BuildOptions.ErrorList, ElaCodeBuilder.ForceRecompile, ElaCodeBuilder.NoDebug);

            if (asm != null)
            {
                var fi = app.GetService <IDialogService>().ShowSaveDialog(app.Document().Title.Replace(".ela", String.Empty) + ".elaobj");

                if (fi != null)
                {
                    var wr = new ObjectFileWriter(fi.ToModuleFileInfo());
                    wr.Write(asm.Assembly.GetRootModule());
                }
            }
        }
Exemple #2
0
        private static bool Compile(DyaOptions options)
        {
            var ctx = new InteractiveContext(options);

            foreach (var f in options.GetFileNames())
            {
                var outFile = options.OutputDirectory;

                if (string.IsNullOrWhiteSpace(outFile))
                {
                    outFile = Path.Combine(Path.GetDirectoryName(f), Path.GetFileNameWithoutExtension(f) + ".dyo");
                }
                else if (Directory.Exists(outFile))
                {
                    outFile = Path.Combine(outFile, Path.GetFileNameWithoutExtension(f) + ".dyo");
                }

                if (!File.Exists(f) || !ctx.Compile(f, out var unit))
                {
                    Printer.Error($"Compilation of file \"{f}\" skipped.");
                    continue;
                }

#if !DEBUG
                try
#endif
                {
                    ObjectFileWriter.Write(outFile, unit);
                    Printer.Information($"Compilation completed. File saved: \"{outFile}\"");
                }
#if !DEBUG
                catch (Exception ex)
                {
                    Printer.Error(ex.Message);
                    Printer.Error($"Compilation of file \"{f}\" skipped.");
                    continue;
                }
#endif
            }

            return(true);
        }
Exemple #3
0
        private static int Compile()
        {
            var frame = default(CodeFrame);

            try
            {
                var copt = CreateLinkerOptions();
                copt.ForceRecompile = true;
                var el  = new ElaLinker(copt, CreateCompilerOptions(), new ModuleFileInfo(opt.FileName));
                var res = el.Build();
                helper.PrintErrors(res.Messages);

                if (!res.Success)
                {
                    return(R_ERR);
                }

                frame = res.Assembly.GetRootModule();
            }
            catch (ElaException ex)
            {
                helper.PrintInternalError(ex);
                return(R_ERR);
            }

            var fi = default(FileInfo);

            if (!String.IsNullOrEmpty(opt.OutputFile))
            {
                try
                {
                    fi = new FileInfo(opt.OutputFile);
                }
                catch (Exception ex)
                {
                    helper.PrintUnableWriteFile(opt.OutputFile, ex);
                    return(R_ERR);
                }
            }
            else
            {
                fi = new FileInfo(Path.ChangeExtension(opt.FileName, ".elaobj"));
            }

            if (!fi.Exists)
            {
                try
                {
                    fi.Delete();
                }
                catch (Exception ex)
                {
                    helper.PrintUnableWriteFile(opt.OutputFile, ex);
                    return(R_ERR);
                }
            }

            var obj = new ObjectFileWriter(new ModuleFileInfo(fi.FullName));

            try
            {
                obj.Write(frame);
            }
            catch (ElaException ex)
            {
                helper.PrintInternalError(ex);
                return(R_ERR);
            }

            Console.WriteLine("Compilation completed. File '{0}' created.", fi.FullName);
            return(R_OK);
        }