// Defaults correspond to the compiler's defaults or indicate that the user did not specify when that is significant.
 // That's significant when one option depends on another's setting. SubsystemVersion depends on Platform and Target.
 public CSharpCompilationOptions(
     OutputKind outputKind,
     string moduleName           = null,
     string mainTypeName         = null,
     string scriptClassName      = WellKnownMemberNames.DefaultScriptClassName,
     IEnumerable <string> usings = null,
     bool optimize             = false,
     bool checkOverflow        = false,
     bool allowUnsafe          = false,
     string cryptoKeyContainer = null,
     string cryptoKeyFile      = null,
     bool?delaySign            = null,
     int fileAlignment         = 0,
     ulong baseAddress         = 0,
     Platform platform         = Platform.AnyCpu,
     ReportDiagnostic generalDiagnosticOption = ReportDiagnostic.Default,
     int warningLevel = 4,
     IEnumerable <KeyValuePair <string, ReportDiagnostic> > specificDiagnosticOptions = null,
     bool highEntropyVirtualAddressSpace       = false,
     DebugInformationKind debugInformationKind = DebugInformationKind.None,
     SubsystemVersion subsystemVersion         = default(SubsystemVersion),
     string runtimeMetadataVersion             = null,
     bool concurrentBuild = true,
     XmlReferenceResolver xmlReferenceResolver           = null,
     SourceReferenceResolver sourceReferenceResolver     = null,
     MetadataReferenceResolver metadataReferenceResolver = null,
     MetadataReferenceProvider metadataReferenceProvider = null,
     AssemblyIdentityComparer assemblyIdentityComparer   = null,
     StrongNameProvider strongNameProvider = null)
     : this(outputKind, moduleName, mainTypeName, scriptClassName, usings, optimize, checkOverflow, allowUnsafe,
            cryptoKeyContainer, cryptoKeyFile, delaySign, fileAlignment, baseAddress, platform, generalDiagnosticOption, warningLevel,
            specificDiagnosticOptions, highEntropyVirtualAddressSpace, debugInformationKind, subsystemVersion, runtimeMetadataVersion, concurrentBuild,
            xmlReferenceResolver, sourceReferenceResolver, metadataReferenceResolver, metadataReferenceProvider, assemblyIdentityComparer, strongNameProvider, MetadataImportOptions.Public, features : null)
 {
 }
 // Expects correct arguments.
 internal CompilationOptions(
     OutputKind outputKind,
     string moduleName,
     string mainTypeName,
     string scriptClassName,
     string cryptoKeyContainer,
     string cryptoKeyFile,
     bool?delaySign,
     bool optimize,
     bool checkOverflow,
     int fileAlignment,
     ulong baseAddress,
     Platform platform,
     ReportDiagnostic generalDiagnosticOption,
     int warningLevel,
     IEnumerable <KeyValuePair <string, ReportDiagnostic> > specificDiagnosticOptions,
     bool highEntropyVirtualAddressSpace,
     DebugInformationKind debugInformationKind,
     SubsystemVersion subsystemVersion,
     bool concurrentBuild,
     XmlReferenceResolver xmlReferenceResolver,
     SourceReferenceResolver sourceReferenceResolver,
     MetadataReferenceResolver metadataReferenceResolver,
     MetadataReferenceProvider metadataReferenceProvider,
     AssemblyIdentityComparer assemblyIdentityComparer,
     StrongNameProvider strongNameProvider,
     MetadataImportOptions metadataImportOptions)
 {
     Initialize(
         outputKind, moduleName, mainTypeName, scriptClassName, cryptoKeyContainer, cryptoKeyFile, delaySign, optimize, checkOverflow, fileAlignment,
         baseAddress, platform, generalDiagnosticOption, warningLevel, specificDiagnosticOptions, highEntropyVirtualAddressSpace, debugInformationKind,
         subsystemVersion, concurrentBuild, xmlReferenceResolver, sourceReferenceResolver, metadataReferenceResolver, metadataReferenceProvider, assemblyIdentityComparer, strongNameProvider,
         metadataImportOptions);
 }
        internal void Initialize(
            OutputKind outputKind,
            string moduleName,
            string mainTypeName,
            string scriptClassName,
            string cryptoKeyContainer,
            string cryptoKeyFile,
            bool?delaySign,
            bool optimize,
            bool checkOverflow,
            int fileAlignment,
            ulong baseAddress,
            Platform platform,
            ReportDiagnostic generalDiagnosticOption,
            int warningLevel,
            IEnumerable <KeyValuePair <string, ReportDiagnostic> > specificDiagnosticOptions,
            bool highEntropyVirtualAddressSpace,
            DebugInformationKind debugInformationKind,
            SubsystemVersion subsystemVersion,
            bool concurrentBuild,
            FileResolver fileResolver,
            MetadataReferenceProvider metadataReferenceProvider,
            AssemblyIdentityComparer assemblyIdentityComparer,
            StrongNameProvider strongNameProvider,
            MetadataImportOptions metadataImportOptions)
        {
            this.OutputKind                     = outputKind;
            this.ModuleName                     = moduleName;
            this.MainTypeName                   = mainTypeName;
            this.ScriptClassName                = scriptClassName;
            this.CryptoKeyContainer             = cryptoKeyContainer;
            this.CryptoKeyFile                  = cryptoKeyFile;
            this.DelaySign                      = delaySign;
            this.CheckOverflow                  = checkOverflow;
            this.FileAlignment                  = fileAlignment;
            this.BaseAddress                    = baseAddress;
            this.Platform                       = platform;
            this.GeneralDiagnosticOption        = generalDiagnosticOption;
            this.WarningLevel                   = warningLevel;
            this.SpecificDiagnosticOptions      = specificDiagnosticOptions.ToImmutableDictionaryOrEmpty();
            this.HighEntropyVirtualAddressSpace = highEntropyVirtualAddressSpace;
            this.DebugInformationKind           = debugInformationKind;
            this.Optimize                       = optimize;
            this.ConcurrentBuild                = concurrentBuild;
            this.SubsystemVersion               = subsystemVersion;
            this.FileResolver                   = fileResolver ?? FileResolver.Default;
            this.MetadataReferenceProvider      = metadataReferenceProvider ?? MetadataReferenceProvider.Default;
            this.StrongNameProvider             = strongNameProvider;
            this.AssemblyIdentityComparer       = assemblyIdentityComparer ?? AssemblyIdentityComparer.Default;
            this.MetadataImportOptions          = metadataImportOptions;

            this.lazyErrors = new Lazy <ImmutableArray <Diagnostic> >(() =>
            {
                var builder = ArrayBuilder <Diagnostic> .GetInstance();
                ValidateOptions(builder);
                return(builder.ToImmutableAndFree());
            });
        }
        public CSharpCompilationOptions WithDebugInformationKind(DebugInformationKind kind)
        {
            if (kind == this.DebugInformationKind)
            {
                return(this);
            }

            return(new CSharpCompilationOptions(this)
            {
                DebugInformationKind = kind
            });
        }
Exemple #5
0
        private CodeGenerator(MethodSymbol method,
                              BoundStatement block,
                              ILBuilder builder,
                              PEModuleBuilder module,
                              DiagnosticBag diagnostics,
                              bool optimize,
                              bool emitSequencePoints)
        {
            this.method      = method;
            this.block       = block;
            this.builder     = builder;
            this.module      = module;
            this.diagnostics = diagnostics;

            this.noOptimizations      = !optimize;
            this.debugInformationKind = module.Compilation.Options.DebugInformationKind;

            if (!this.debugInformationKind.IsValid())
            {
                this.debugInformationKind = DebugInformationKind.None;
            }

            // Special case: always optimize synthesized explicit interface implementation methods
            // (aka bridge methods) with by-ref returns because peverify produces errors if we
            // return a ref local (which the return local will be in such cases).
            if (this.noOptimizations && method.ReturnType is ByRefReturnErrorTypeSymbol)
            {
                Debug.Assert(method is SynthesizedExplicitImplementationMethod);
                this.noOptimizations = false;
            }

            this.emitSequencePoints = emitSequencePoints;

            if (!this.noOptimizations)
            {
                this.block = Optimizer.Optimize(block, out stackLocals);
            }

            Debug.Assert((object)method != null);
            Debug.Assert(block != null);
            Debug.Assert(builder != null);
            Debug.Assert(module != null);

            var asSourceMethod = method as SourceMethodSymbol;

            if ((object)asSourceMethod != null)
            {
                methodBlockSyntax = asSourceMethod.BlockSyntax;
            }
        }
        public static bool IsNamed(this SynthesizedLocalKind kind, DebugInformationKind debugInformationKind)
        {
            if (debugInformationKind == DebugInformationKind.Full)
            {
                return(IsLongLived(kind));
            }

            switch (kind)
            {
            // TODO: The following variables should be named whenever we emit any debugging information,
            // so that EE can recognize these variables by name. Synthesized variables that EE doesn't
            // need to know about don't need to be named unless we are emitting debug info for EnC.
            case SynthesizedLocalKind.LambdaDisplayClass:
                return(true);

            default:
                return(false);
            }
        }
 // Expects correct arguments.
 internal CSharpCompilationOptions(
     OutputKind outputKind,
     string moduleName,
     string mainTypeName,
     string scriptClassName,
     IEnumerable <string> usings,
     bool optimize,
     bool checkOverflow,
     bool allowUnsafe,
     string cryptoKeyContainer,
     string cryptoKeyFile,
     bool?delaySign,
     int fileAlignment,
     ulong baseAddress,
     Platform platform,
     ReportDiagnostic generalDiagnosticOption,
     int warningLevel,
     IEnumerable <KeyValuePair <string, ReportDiagnostic> > specificDiagnosticOptions,
     bool highEntropyVirtualAddressSpace,
     DebugInformationKind debugInformationKind,
     SubsystemVersion subsystemVersion,
     string runtimeMetadataVersion,
     bool concurrentBuild,
     XmlReferenceResolver xmlReferenceResolver,
     SourceReferenceResolver sourceReferenceResolver,
     MetadataReferenceResolver metadataReferenceResolver,
     MetadataReferenceProvider metadataReferenceProvider,
     AssemblyIdentityComparer assemblyIdentityComparer,
     StrongNameProvider strongNameProvider,
     MetadataImportOptions metadataImportOptions,
     ImmutableArray <string> features)
     : base(outputKind, moduleName, mainTypeName, scriptClassName, cryptoKeyContainer, cryptoKeyFile, delaySign, optimize, checkOverflow, fileAlignment, baseAddress,
            platform, generalDiagnosticOption, warningLevel, specificDiagnosticOptions, highEntropyVirtualAddressSpace, debugInformationKind,
            subsystemVersion, concurrentBuild, xmlReferenceResolver, sourceReferenceResolver, metadataReferenceResolver, metadataReferenceProvider, assemblyIdentityComparer, strongNameProvider, metadataImportOptions, features)
 {
     this.Usings                 = usings.AsImmutableOrEmpty();
     this.AllowUnsafe            = allowUnsafe;
     this.RuntimeMetadataVersion = runtimeMetadataVersion;
 }
 internal static bool IsValid(this DebugInformationKind value)
 {
     return value >= DebugInformationKind.None && value <= DebugInformationKind.Full;
 }
Exemple #9
0
        private CodeGenerator(MethodSymbol method,
            BoundStatement block,
            ILBuilder builder,
            PEModuleBuilder module,
            DiagnosticBag diagnostics,
            bool optimize,
            bool emitSequencePoints)
        {
            this.method = method;
            this.block = block;
            this.builder = builder;
            this.module = module;
            this.diagnostics = diagnostics;

            this.noOptimizations = !optimize;
            this.debugInformationKind = module.Compilation.Options.DebugInformationKind;

            Debug.Assert(this.debugInformationKind.IsValid());

            // Special case: always optimize synthesized explicit interface implementation methods
            // (aka bridge methods) with by-ref returns because peverify produces errors if we
            // return a ref local (which the return local will be in such cases).
            if (this.noOptimizations && method.ReturnType is ByRefReturnErrorTypeSymbol)
            {
                Debug.Assert(method is SynthesizedExplicitImplementationForwardingMethod);
                this.noOptimizations = false;
            }

            this.emitSequencePoints = emitSequencePoints;

            if (!this.noOptimizations)
            {
                this.block = Optimizer.Optimize(block, out stackLocals);
            }

            Debug.Assert((object)method != null);
            Debug.Assert(block != null);
            Debug.Assert(builder != null);
            Debug.Assert(module != null);

            var asSourceMethod = method as SourceMethodSymbol;
            if ((object)asSourceMethod != null)
            {
                methodBlockSyntax = asSourceMethod.BlockSyntax;
            }
        }
        internal override void ValidateOptions(ArrayBuilder <Diagnostic> builder)
        {
            //  /main & /target:{library|netmodule|winmdobj}
            if (this.MainTypeName != null)
            {
                if (this.OutputKind.IsValid() && !this.OutputKind.IsApplication())
                {
                    builder.Add(Diagnostic.Create(MessageProvider.Instance, (int)ErrorCode.ERR_NoMainOnDLL));
                }

                if (!MainTypeName.IsValidClrTypeName())
                {
                    builder.Add(Diagnostic.Create(MessageProvider.Instance, (int)ErrorCode.ERR_BadCompilationOptionValue, "MainTypeName", MainTypeName));
                }
            }

            if (FileAlignment != 0 && !IsValidFileAlignment(FileAlignment))
            {
                builder.Add(Diagnostic.Create(MessageProvider.Instance, (int)ErrorCode.ERR_BadFileAlignment, FileAlignment));
            }

            if (!Platform.IsValid())
            {
                builder.Add(Diagnostic.Create(MessageProvider.Instance, (int)ErrorCode.ERR_BadPlatformType, Platform));
            }

            if (ModuleName != null)
            {
                Exception e = MetadataHelpers.CheckAssemblyOrModuleName(ModuleName, "ModuleName");
                if (e != null)
                {
                    builder.Add(Diagnostic.Create(MessageProvider.Instance, (int)ErrorCode.ERR_BadCompilationOption, e.Message));
                }
            }

            if (!OutputKind.IsValid())
            {
                builder.Add(Diagnostic.Create(MessageProvider.Instance, (int)ErrorCode.ERR_BadCompilationOptionValue, "OutputKind", OutputKind));
            }

            if (!DebugInformationKind.IsValid())
            {
                builder.Add(Diagnostic.Create(MessageProvider.Instance, (int)ErrorCode.ERR_BadCompilationOptionValue, "DebugInformationKind", DebugInformationKind));
            }

            if (!SubsystemVersion.Equals(SubsystemVersion.None) && !SubsystemVersion.IsValid)
            {
                builder.Add(Diagnostic.Create(MessageProvider.Instance, (int)ErrorCode.ERR_BadSubsystemVersion, SubsystemVersion.ToString()));
            }

            if (ScriptClassName == null || !ScriptClassName.IsValidClrTypeName())
            {
                builder.Add(Diagnostic.Create(MessageProvider.Instance, (int)ErrorCode.ERR_BadCompilationOptionValue, "ScriptClassName", ScriptClassName ?? "null"));
            }

            if (Features == null)
            {
                builder.Add(Diagnostic.Create(MessageProvider.Instance, (int)ErrorCode.ERR_BadCompilationOptionValue, "Features", "null"));
            }

            if (WarningLevel < 0 || WarningLevel > 4)
            {
                builder.Add(Diagnostic.Create(MessageProvider.Instance, (int)ErrorCode.ERR_BadCompilationOptionValue, "WarningLevel", WarningLevel));
            }

            if (Usings != null && Usings.Any(u => !u.IsValidClrNamespaceName()))
            {
                builder.Add(Diagnostic.Create(MessageProvider.Instance, (int)ErrorCode.ERR_BadCompilationOptionValue, "Usings", Usings.Where(u => !u.IsValidClrNamespaceName()).First() ?? "null"));
            }

            if (Platform == Platform.AnyCpu32BitPreferred && OutputKind.IsValid() && !(OutputKind == OutputKind.ConsoleApplication || OutputKind == OutputKind.WindowsApplication || OutputKind == OutputKind.WindowsRuntimeApplication))
            {
                builder.Add(Diagnostic.Create(MessageProvider.Instance, (int)ErrorCode.ERR_BadPrefer32OnLib));
            }

            // TODO: add check for
            //          (kind == 'arm' || kind == 'appcontainer' || kind == 'winmdobj') &&
            //          (version >= "6.2")
        }
Exemple #11
0
 // Expects correct arguments.
 internal CompilationOptions(
     OutputKind outputKind,
     string moduleName,
     string mainTypeName,
     string scriptClassName,
     string cryptoKeyContainer,
     string cryptoKeyFile,
     bool? delaySign,
     bool optimize,
     bool checkOverflow,
     int fileAlignment,
     ulong baseAddress,
     Platform platform,
     ReportDiagnostic generalDiagnosticOption,
     int warningLevel,
     IEnumerable<KeyValuePair<string, ReportDiagnostic>> specificDiagnosticOptions,
     bool highEntropyVirtualAddressSpace,
     DebugInformationKind debugInformationKind,
     SubsystemVersion subsystemVersion,
     bool concurrentBuild,
     XmlReferenceResolver xmlReferenceResolver,
     SourceReferenceResolver sourceReferenceResolver,
     MetadataReferenceResolver metadataReferenceResolver,
     MetadataReferenceProvider metadataReferenceProvider,
     AssemblyIdentityComparer assemblyIdentityComparer,
     StrongNameProvider strongNameProvider,
     MetadataImportOptions metadataImportOptions,
     ImmutableArray<string> features)
 {
     this.OutputKind = outputKind;
     this.ModuleName = moduleName;
     this.MainTypeName = mainTypeName;
     this.ScriptClassName = scriptClassName;
     this.CryptoKeyContainer = cryptoKeyContainer;
     this.CryptoKeyFile = cryptoKeyFile;
     this.DelaySign = delaySign;
     this.CheckOverflow = checkOverflow;
     this.FileAlignment = fileAlignment;
     this.BaseAddress = baseAddress;
     this.Platform = platform;
     this.GeneralDiagnosticOption = generalDiagnosticOption;
     this.WarningLevel = warningLevel;
     this.SpecificDiagnosticOptions = specificDiagnosticOptions.ToImmutableDictionaryOrEmpty();
     this.HighEntropyVirtualAddressSpace = highEntropyVirtualAddressSpace;
     this.DebugInformationKind = debugInformationKind;
     this.Optimize = optimize;
     this.ConcurrentBuild = concurrentBuild;
     this.SubsystemVersion = subsystemVersion;
     this.XmlReferenceResolver = xmlReferenceResolver;
     this.SourceReferenceResolver = sourceReferenceResolver;
     this.MetadataReferenceResolver = metadataReferenceResolver;
     this.MetadataReferenceProvider = metadataReferenceProvider;
     this.StrongNameProvider = strongNameProvider;
     this.AssemblyIdentityComparer = assemblyIdentityComparer ?? AssemblyIdentityComparer.Default;
     this.MetadataImportOptions = metadataImportOptions;
     this.Features = features;
     
     this.lazyErrors = new Lazy<ImmutableArray<Diagnostic>>(() =>
     {
         var builder = ArrayBuilder<Diagnostic>.GetInstance();
         ValidateOptions(builder);
         return builder.ToImmutableAndFree();
     });
 }
        private void TestDebuggableAttributeCommon(
            string source,
            Action<CSharpCompilation> validator,
            bool includeMscorlibRef,
            bool compileAndVerify,
            OutputKind outputKind,
            DebugInformationKind emitDebugInfoKind,
            bool optimizationsEnabled)
        {
            var compilation = CSharpCompilation.Create("comp", 
                new[] { Parse(source) },
                includeMscorlibRef ? new[] { MscorlibRef } : null,
                new CSharpCompilationOptions(outputKind, debugInformationKind: emitDebugInfoKind, optimize: optimizationsEnabled));

            validator(compilation);

            if (compileAndVerify)
            {
                // NYI: /addmodule support
                // TODO: PEVerify currently fails for netmodules with error: "The module X was expected to contain an assembly manifest".
                // TODO: Remove the 'verify' named argument once /addmodule support has been added.
                CompileAndVerify(compilation, verify: !outputKind.IsNetModule());
            }
        }
        private void VerifySynthesizedDebuggableAttribute(CSharpAttributeData attribute, SourceAssemblySymbol sourceAssembly, DebugInformationKind emitDebugInfoKind, bool optimizationsEnabled)
        {
            Assert.NotEqual(DebugInformationKind.None, emitDebugInfoKind);

            var expectedDebuggingMode = DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints;

            bool emittingFullDebugInfo = emitDebugInfoKind == DebugInformationKind.Full;
            if (emittingFullDebugInfo)
            {
                expectedDebuggingMode |= DebuggableAttribute.DebuggingModes.Default;
            }

            if (!optimizationsEnabled)
            {
                expectedDebuggingMode |= DebuggableAttribute.DebuggingModes.DisableOptimizations;

                if (emittingFullDebugInfo)
                {
                    expectedDebuggingMode |= DebuggableAttribute.DebuggingModes.EnableEditAndContinue;
                }
            }

            VerifyDebuggableAttribute(attribute, sourceAssembly, expectedDebuggingMode);
        }
Exemple #14
0
        private ImmutableArray <byte> GetBytesEmitted(string source, Platform platform, DebugInformationKind debug, bool deterministic)
        {
            var options = new CSharpCompilationOptions(OutputKind.ConsoleApplication, platform: platform, debugInformationKind: debug);

            if (deterministic)
            {
                options = options.WithFeatures((new[] { "dEtErmInIstIc" }).AsImmutable()); // expect case-insensitivity
            }

            var compilation = CreateCompilation(source, assemblyName: "DeterminismTest", references: new[] { MscorlibRef }, compOptions: options);

            // The resolution of the PE header time date stamp is seconds, and we want to make sure that has an opportunity to change
            // between calls to Emit.
            Thread.Sleep(TimeSpan.FromSeconds(1));

            return(compilation.EmitToArray());
        }
        public static bool IsNamed(this SynthesizedLocalKind kind, DebugInformationKind debugInformationKind)
        {
            if (debugInformationKind == DebugInformationKind.Full)
            {
                return IsLongLived(kind);
            }

            switch (kind)
            {
                // TODO: The following variables should be named whenever we emit any debugging information,
                // so that EE can recognize these variables by name. Synthesized variables that EE doesn't 
                // need to know about don't need to be named unless we are emitting debug info for EnC.
                case SynthesizedLocalKind.LambdaDisplayClass:
                    return true;

                default:
                    return false;
            }
        }
Exemple #16
0
 // Expects correct arguments.
 internal CompilationOptions(
     OutputKind outputKind,
     string moduleName,
     string mainTypeName,
     string scriptClassName,
     string cryptoKeyContainer,
     string cryptoKeyFile,
     bool? delaySign,
     bool optimize,
     bool checkOverflow,
     int fileAlignment,
     ulong baseAddress,
     Platform platform,
     ReportDiagnostic generalDiagnosticOption,
     int warningLevel,
     IEnumerable<KeyValuePair<string, ReportDiagnostic>> specificDiagnosticOptions,
     bool highEntropyVirtualAddressSpace,
     DebugInformationKind debugInformationKind,
     SubsystemVersion subsystemVersion,
     bool concurrentBuild,
     XmlReferenceResolver xmlReferenceResolver,
     SourceReferenceResolver sourceReferenceResolver,
     MetadataReferenceResolver metadataReferenceResolver,
     MetadataReferenceProvider metadataReferenceProvider,
     AssemblyIdentityComparer assemblyIdentityComparer,
     StrongNameProvider strongNameProvider,
     MetadataImportOptions metadataImportOptions)
 {
     Initialize(
         outputKind, moduleName, mainTypeName, scriptClassName, cryptoKeyContainer, cryptoKeyFile, delaySign, optimize, checkOverflow, fileAlignment, 
         baseAddress, platform, generalDiagnosticOption, warningLevel, specificDiagnosticOptions, highEntropyVirtualAddressSpace, debugInformationKind, 
         subsystemVersion, concurrentBuild, xmlReferenceResolver, sourceReferenceResolver, metadataReferenceResolver, metadataReferenceProvider, assemblyIdentityComparer, strongNameProvider, 
         metadataImportOptions);
 }