Exemple #1
0
        public void Save()
        {
            PortableExecutableKinds pekind = PortableExecutableKinds.ILOnly;
            ImageFileMachine        machine;

            switch (Compiler.Settings.Platform)
            {
            case Platform.X86:
                pekind |= PortableExecutableKinds.Required32Bit;
                machine = ImageFileMachine.I386;
                break;

            case Platform.X64:
                pekind |= PortableExecutableKinds.PE32Plus;
                machine = ImageFileMachine.AMD64;
                break;

            case Platform.IA64:
                machine = ImageFileMachine.IA64;
                break;

            case Platform.AnyCPU32Preferred:
#if STATIC
                pekind |= PortableExecutableKinds.Preferred32Bit;
                machine = ImageFileMachine.I386;
                break;
#else
                throw new NotSupportedException();
#endif
            case Platform.Arm:
#if STATIC
                machine = ImageFileMachine.ARM;
                break;
#else
                throw new NotSupportedException();
#endif
            case Platform.AnyCPU:
            default:
                machine = ImageFileMachine.I386;
                break;
            }

            Compiler.TimeReporter.Start(TimeReporter.TimerType.OutputSave);
            try {
                if (Compiler.Settings.Target == Target.Module)
                {
                    SaveModule(pekind, machine);
                }
                else
                {
                    Builder.Save(module.Builder.ScopeName, pekind, machine);
                }
            } catch (Exception e) {
                Report.Error(16, "Could not write to file `" + name + "', cause: " + e.Message);
            }
            Compiler.TimeReporter.Stop(TimeReporter.TimerType.OutputSave);

            // Save debug symbols file
            if (symbol_writer != null && Compiler.Report.Errors == 0)
            {
                // TODO: it should run in parallel
                Compiler.TimeReporter.Start(TimeReporter.TimerType.DebugSave);

                var filename = file_name + ".mdb";
                try {
                    // We mmap the file, so unlink the previous version since it may be in use
                    File.Delete(filename);
                } catch {
                    // We can safely ignore
                }

                module.WriteDebugSymbol(symbol_writer);

                using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write)) {
                    symbol_writer.CreateSymbolFile(module.Builder.ModuleVersionId, fs);
                }

                Compiler.TimeReporter.Stop(TimeReporter.TimerType.DebugSave);
            }
        }