• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# PEModuleBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中PEModuleBuilder的典型用法代码示例。如果您正苦于以下问题:C# PEModuleBuilder类的具体用法?C# PEModuleBuilder怎么用?C# PEModuleBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PEModuleBuilder类属于命名空间,在下文中一共展示了PEModuleBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: CodeGenerator

        public CodeGenerator(
            MethodSymbol method,
            BoundStatement boundBody,
            ILBuilder builder,
            PEModuleBuilder moduleBuilder,
            DiagnosticBag diagnostics,
            OptimizationLevel optimizations,
            bool emittingPdb)
        {
            Debug.Assert((object)method != null);
            Debug.Assert(boundBody != null);
            Debug.Assert(builder != null);
            Debug.Assert(moduleBuilder != null);
            Debug.Assert(diagnostics != null);

            _method = method;
            _boundBody = boundBody;
            _builder = builder;
            _module = moduleBuilder;
            _diagnostics = diagnostics;

            if (!method.GenerateDebugInfo)
            {
                // Always optimize synthesized methods that don't contain user code.
                // 
                // Specifically, 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).
                _ilEmitStyle = ILEmitStyle.Release;
            }
            else
            {
                if (optimizations == OptimizationLevel.Debug)
                {
                    _ilEmitStyle = ILEmitStyle.Debug;
                }
                else
                {
                    _ilEmitStyle = IsDebugPlus() ? 
                        ILEmitStyle.DebugFriendlyRelease : 
                        ILEmitStyle.Release;
                }
            }

            // Emit sequence points unless
            // - the PDBs are not being generated
            // - debug information for the method is not generated since the method does not contain
            //   user code that can be stepped through, or changed during EnC.
            // 
            // This setting only affects generating PDB sequence points, it shall not affect generated IL in any way.
            _emitPdbSequencePoints = emittingPdb && method.GenerateDebugInfo;

            _boundBody = Optimizer.Optimize(
                boundBody, 
                debugFriendly: _ilEmitStyle != ILEmitStyle.Release, 
                stackLocals: out _stackLocals);

            _methodBodySyntaxOpt = (method as SourceMethodSymbol)?.BodySyntax;
        }
开发者ID:nemec,项目名称:roslyn,代码行数:59,代码来源:CodeGenerator.cs


示例2: ModuleReference

        internal ModuleReference(PEModuleBuilder moduleBeingBuilt, ModuleSymbol underlyingModule)
        {
            Debug.Assert(moduleBeingBuilt != null);
            Debug.Assert((object)underlyingModule != null);

            this.moduleBeingBuilt = moduleBeingBuilt;
            this.underlyingModule = underlyingModule;
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:8,代码来源:ModuleReference.cs


示例3: ProcessSynthesizedMembers

        /// <summary>
        /// Traverse the symbol table and call Module.AddSynthesizedDefinition for each
        /// synthesized explicit implementation stub that has been generated (e.g. when the real
        /// implementation doesn't have the appropriate custom modifiers).
        /// </summary>
        public static void ProcessSynthesizedMembers(
            CSharpCompilation compilation,
            PEModuleBuilder moduleBeingBuilt,
            CancellationToken cancellationToken)
        {
            Debug.Assert(moduleBeingBuilt != null);

            var compiler = new SynthesizedMetadataCompiler(moduleBeingBuilt, cancellationToken);
            compiler.Visit(compilation.SourceModule.GlobalNamespace);
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:15,代码来源:SynthesizedMetadataCompiler.cs


示例4: ResolvedFieldImpl

        private Cci.IFieldDefinition ResolvedFieldImpl(PEModuleBuilder moduleBeingBuilt)
        {
            Debug.Assert(this.IsDefinitionOrDistinct());

            if (this.IsDefinition &&
                this.ContainingModule == moduleBeingBuilt.SourceModule)
            {
                return this;
            }

            return null;
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:12,代码来源:FieldSymbolAdapter.cs


示例5: ProcessSynthesizedMembers

        /// <summary>
        /// Traverse the symbol table and call Module.AddSynthesizedDefinition for each
        /// synthesized explicit implementation stub that has been generated (e.g. when the real
        /// implementation doesn't have the appropriate custom modifiers).
        /// </summary>
        public static void ProcessSynthesizedMembers(
            CSharpCompilation compilation,
            PEModuleBuilder moduleBeingBuilt,
            CancellationToken cancellationToken)
        {
            Debug.Assert(moduleBeingBuilt != null);

            using (Logger.LogBlock(FunctionId.CSharp_Compiler_CompileSynthesizedMethodMetadata, message: compilation.AssemblyName, cancellationToken: cancellationToken))
            {
                var compiler = new SynthesizedMetadataCompiler(moduleBeingBuilt, cancellationToken);
                compiler.Visit(compilation.SourceModule.GlobalNamespace);
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:18,代码来源:SynthesizedMetadataCompiler.cs


示例6: CodeGenerator

        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;
            }
        }
开发者ID:riversky,项目名称:roslyn,代码行数:49,代码来源:CodeGenerator.cs


示例7: CodeGenerator

        private CodeGenerator(
            MethodSymbol method,
            BoundStatement block,
            ILBuilder builder,
            PEModuleBuilder moduleBuilder,
            DiagnosticBag diagnostics,
            OptimizationLevel optimizations,
            bool emittingPdbs)
        {
            this.method = method;
            this.block = block;
            this.builder = builder;
            this.module = moduleBuilder;
            this.diagnostics = diagnostics;

            // Always optimize synthesized methods that don't contain user code.
            // 
            // Specifically, 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).

            this.optimizations = method.GenerateDebugInfo ? optimizations : OptimizationLevel.Release;

            // Emit sequence points unless
            // - the PDBs are not being generated
            // - debug information for the method is not generated since the method does not contain
            //   user code that can be stepped thru, or changed during EnC.
            // 
            // This setting only affects generating PDB sequence points, it shall not affect generated IL in any way.
            this.emitPdbSequencePoints = emittingPdbs && method.GenerateDebugInfo;

            if (this.optimizations == OptimizationLevel.Release)
            {
                this.block = Optimizer.Optimize(block, out stackLocals);
            }

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

            var asSourceMethod = method as SourceMethodSymbol;
            if ((object)asSourceMethod != null)
            {
                methodBlockSyntax = asSourceMethod.BlockSyntax;
            }
        }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:47,代码来源:CodeGenerator.cs


示例8: CompileMethodBodies

        public static void CompileMethodBodies(
            CSharpCompilation compilation,
            PEModuleBuilder moduleBeingBuilt,
            bool generateDebugInfo,
            bool hasDeclarationErrors,
            Predicate<Symbol> filter,
            SyntaxTree filterTree,
            TextSpan? filterSpanWithinTree,
            DiagnosticBag diagnostics,
            CancellationToken cancellationToken)
        {
            using (Logger.LogBlock(FunctionId.CSharp_Compiler_CompileMethodBodies, message: compilation.AssemblyName, cancellationToken: cancellationToken))
            {
                Debug.Assert(filter == null || filterTree == null, "Cannot provide both a filter predicate and a filter tree.");

                if (filter == null && filterTree != null)
                {
                    filter = s => s.IsDefinedInSourceTree(filterTree, filterSpanWithinTree);
                }

                if (compilation.PreviousSubmission != null)
                {
                    // In case there is a previous submission, we should ensure 
                    // it has already created anonymous type/delegates templates

                    // NOTE: if there are any errors, we will pick up what was created anyway
                    compilation.PreviousSubmission.EnsureAnonymousTypeTemplates(cancellationToken);

                    // TODO: revise to use a loop instead of a recursion
                }

                MethodBodyCompiler.CompileMethodBodies(compilation, moduleBeingBuilt, generateDebugInfo, hasDeclarationErrors, diagnostics, filter, cancellationToken);

                MethodSymbol entryPoint = GetEntryPoint(compilation, moduleBeingBuilt, hasDeclarationErrors, diagnostics, cancellationToken);
                if (moduleBeingBuilt != null)
                {
                    moduleBeingBuilt.SetEntryPoint(entryPoint);
                }
            }
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:40,代码来源:Compiler.cs


示例9: SynthesizedMetadataCompiler

 private SynthesizedMetadataCompiler(PEModuleBuilder moduleBeingBuilt, CancellationToken cancellationToken)
 {
     Debug.Assert(moduleBeingBuilt != null);
     _moduleBeingBuilt = moduleBeingBuilt;
     _cancellationToken = cancellationToken;
 }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:6,代码来源:SynthesizedMetadataCompiler.cs


示例10: AddDebugSourceDocumentsForChecksumDirectives

        private static void AddDebugSourceDocumentsForChecksumDirectives(
            PEModuleBuilder moduleBeingBuilt,
            SyntaxTree tree,
            DiagnosticBag diagnostics)
        {
            var checksumDirectives = tree.GetRoot().GetDirectives(d => d.Kind == SyntaxKind.PragmaChecksumDirectiveTrivia &&
                                                                 !d.ContainsDiagnostics);

            foreach (var directive in checksumDirectives)
            {
                var checkSumDirective = (PragmaChecksumDirectiveTriviaSyntax)directive;
                var path = checkSumDirective.File.ValueText;

                var checkSumText = checkSumDirective.Bytes.ValueText;
                var normalizedPath = moduleBeingBuilt.NormalizeDebugDocumentPath(path, basePath: tree.FilePath);
                var existingDoc = moduleBeingBuilt.TryGetDebugDocumentForNormalizedPath(normalizedPath);

                // duplicate checksum pragmas are valid as long as values match
                // if we have seen this document already, check for matching values.
                if (existingDoc != null)
                {
                    // pragma matches a file path on an actual tree.
                    // Dev12 compiler just ignores the pragma in this case which means that
                    // checksum of the actual tree always wins and no warning is given.
                    // We will continue doing the same.
                    if (existingDoc.IsComputedChecksum)
                    {
                        continue;
                    }

                    if (CheckSumMatches(checkSumText, existingDoc.SourceHash))
                    {
                        var guid = Guid.Parse(checkSumDirective.Guid.ValueText);
                        if (guid == existingDoc.SourceHashKind)
                        {
                            // all parts match, nothing to do
                            continue;
                        }
                    }

                    // did not match to an existing document
                    // produce a warning and ignore the pragma
                    diagnostics.Add(ErrorCode.WRN_ConflictingChecksum, new SourceLocation(checkSumDirective), path);
                }
                else
                {
                    var newDocument = new Cci.DebugSourceDocument(
                        normalizedPath,
                        Cci.DebugSourceDocument.CorSymLanguageTypeCSharp,
                        MakeCheckSumBytes(checkSumDirective.Bytes.ValueText),
                        Guid.Parse(checkSumDirective.Guid.ValueText));

                    moduleBeingBuilt.AddDebugDocument(newDocument);
                }
            }
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:56,代码来源:CSharpCompilation.cs


示例11: GetType

 protected override Cci.ITypeReference GetType(PEModuleBuilder moduleBuilder, CSharpSyntaxNode syntaxNodeOpt, DiagnosticBag diagnostics)
 {
     return moduleBuilder.Translate(UnderlyingProperty.Type, syntaxNodeOpt, diagnostics);
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:4,代码来源:EmbeddedProperty.cs


示例12: FixedImplementationType

 internal override NamedTypeSymbol FixedImplementationType(PEModuleBuilder emitModule)
 {
     return emitModule.SetFixedImplementationType(this);
 }
开发者ID:orthoxerox,项目名称:roslyn,代码行数:4,代码来源:SourceFixedFieldSymbol.cs


示例13: AddToType

        internal void AddToType(NamedTypeSymbol containingType, PEModuleBuilder moduleBeingBuilt)
        {
            foreach (var field in FieldSymbols)
            {
                moduleBeingBuilt.AddSynthesizedDefinition(containingType, field);
            }

            FieldSymbol hostObjectField = GetHostObjectField();
            if ((object)hostObjectField != null)
            {
                moduleBeingBuilt.AddSynthesizedDefinition(containingType, hostObjectField);
            }
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:13,代码来源:SynthesizedSubmissionFields.cs


示例14: SynthesizedMethodMetadataCompiler

 public SynthesizedMethodMetadataCompiler(PEModuleBuilder moduleBeingBuilt, CancellationToken cancellationToken)
 {
     Debug.Assert(moduleBeingBuilt != null);
     this.moduleBeingBuilt = moduleBeingBuilt;
     this.cancellationToken = cancellationToken;
 }
开发者ID:riversky,项目名称:roslyn,代码行数:6,代码来源:SynthesizedMethodMetadataCompiler.cs


示例15: FixedImplementationType

 internal override NamedTypeSymbol FixedImplementationType(PEModuleBuilder emitModule)
 {
     EnsureSignatureIsLoaded();
     return _lazyFixedImplementationType;
 }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:5,代码来源:PEFieldSymbol.cs


示例16: FixedImplementationType

 internal override NamedTypeSymbol FixedImplementationType(PEModuleBuilder emitModule)
 {
     // This occurs rarely, if ever.  The scenario would be a generic struct
     // containing a fixed-size buffer.  Given the rarity there would be little
     // benefit to "optimizing" the performance of this by cacheing the
     // translated implementation type.
     return (NamedTypeSymbol)_containingType.TypeSubstitution.SubstituteType(_originalDefinition.FixedImplementationType(emitModule));
 }
开发者ID:GloryChou,项目名称:roslyn,代码行数:8,代码来源:SubstitutedFieldSymbol.cs


示例17: TypeCompilationState

 public TypeCompilationState(NamedTypeSymbol typeOpt, CSharpCompilation compilation, PEModuleBuilder moduleBuilderOpt)
 {
     this.Compilation = compilation;
     _typeOpt = typeOpt;
     this.ModuleBuilderOpt = moduleBuilderOpt;
 }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:6,代码来源:TypeCompilationState.cs


示例18: Run

        public static void Run(MethodSymbol method, BoundStatement block, ILBuilder builder, PEModuleBuilder module, DiagnosticBag diagnostics, bool optimize, bool emitSequencePoints)
        {
            CodeGenerator generator = new CodeGenerator(method, block, builder, module, diagnostics, optimize, emitSequencePoints);
            generator.Generate();
            Debug.Assert(generator.asyncCatchHandlerOffset < 0);
            Debug.Assert(generator.asyncYieldPoints == null);
            Debug.Assert(generator.asyncResumePoints == null);

            if (!diagnostics.HasAnyErrors())
            {
                builder.Realize();
            }
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:13,代码来源:CodeGenerator.cs


示例19: GetEntryPoint

        internal static MethodSymbol GetEntryPoint(CSharpCompilation compilation, PEModuleBuilder moduleBeingBuilt, bool hasDeclarationErrors, DiagnosticBag diagnostics, CancellationToken cancellationToken)
        {
            CSharpCompilationOptions options = compilation.Options;
            if (!options.OutputKind.IsApplication())
            {
                Debug.Assert(compilation.GetEntryPointAndDiagnostics(cancellationToken) == null);
                return compilation.IsSubmission
                    ? DefineScriptEntryPoint(compilation, moduleBeingBuilt, compilation.GetSubmissionReturnType(), hasDeclarationErrors, diagnostics)
                    : null;
            }

            Debug.Assert(!compilation.IsSubmission);
            Debug.Assert(options.OutputKind.IsApplication());

            CSharpCompilation.EntryPoint entryPoint = compilation.GetEntryPointAndDiagnostics(cancellationToken);
            Debug.Assert(entryPoint != null);
            Debug.Assert(!entryPoint.Diagnostics.IsDefault);

            diagnostics.AddRange(entryPoint.Diagnostics);

            if ((object)compilation.ScriptClass != null)
            {
                Debug.Assert((object)entryPoint.MethodSymbol == null);
                return DefineScriptEntryPoint(compilation, moduleBeingBuilt, compilation.GetSpecialType(SpecialType.System_Void), hasDeclarationErrors, diagnostics);
            }

            Debug.Assert((object)entryPoint.MethodSymbol != null || entryPoint.Diagnostics.HasAnyErrors() || !compilation.Options.Errors.IsDefaultOrEmpty);
            return entryPoint.MethodSymbol;
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:29,代码来源:Compiler.cs


示例20: DefineScriptEntryPoint

        internal static MethodSymbol DefineScriptEntryPoint(CSharpCompilation compilation, PEModuleBuilder moduleBeingBuilt, TypeSymbol returnType, bool hasDeclarationErrors, DiagnosticBag diagnostics)
        {
            var scriptEntryPoint = new SynthesizedEntryPointSymbol(compilation.ScriptClass, returnType, diagnostics);
            if (moduleBeingBuilt != null && !hasDeclarationErrors && !diagnostics.HasAnyErrors())
            {
                var compilationState = new TypeCompilationState(compilation.ScriptClass, moduleBeingBuilt);
                var body = scriptEntryPoint.CreateBody();

                var emittedBody = GenerateMethodBody(
                    compilationState,
                    scriptEntryPoint,
                    body,
                    diagnostics,
                    compilation.Options.Optimize,
                    debugDocumentProvider: null,
                    namespaceScopes: default(ImmutableArray<NamespaceScope>));

                moduleBeingBuilt.SetMethodBody(scriptEntryPoint, emittedBody);
                moduleBeingBuilt.AddCompilerGeneratedDefinition(compilation.ScriptClass, scriptEntryPoint);
            }

            return scriptEntryPoint;
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:23,代码来源:Compiler.cs



注:本文中的PEModuleBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# PEReader类代码示例发布时间:2022-05-24
下一篇:
C# PEFileToObjectModel类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap