Exemple #1
0
        internal string VisualizeIL(CompilationTestData.MethodData methodData, bool realIL, string sequencePoints = null, string source = null)
        {
            Dictionary <int, string> markers = null;

            if (sequencePoints != null)
            {
                if (EmittedAssemblyPdb == null)
                {
                    throw new InvalidOperationException($"{nameof(EmittedAssemblyPdb)} is not set");
                }

                if (EmittedAssemblyData == null)
                {
                    throw new InvalidOperationException($"{nameof(EmittedAssemblyData)} is not set");
                }

                var actualPdbXml = PdbToXmlConverter.ToXml(
                    pdbStream: new MemoryStream(EmittedAssemblyPdb.ToArray()),
                    peStream: new MemoryStream(EmittedAssemblyData.ToArray()),
                    options: PdbToXmlOptions.ResolveTokens |
                    PdbToXmlOptions.ThrowOnError |
                    PdbToXmlOptions.ExcludeDocuments |
                    PdbToXmlOptions.ExcludeCustomDebugInformation |
                    PdbToXmlOptions.ExcludeScopes,
                    methodName: sequencePoints);

                if (actualPdbXml.StartsWith("<error>"))
                {
                    throw new Exception($"Failed to extract PDB information for method '{sequencePoints}'. PdbToXmlConverter returned:\r\n{actualPdbXml}");
                }

                markers = ILValidation.GetSequencePointMarkers(actualPdbXml, source);
            }

            if (!realIL)
            {
                return(ILBuilderVisualizer.ILBuilderToString(methodData.ILBuilder, markers: markers));
            }

            if (_lazyModuleSymbol == null)
            {
                var targetReference = LoadTestEmittedExecutableForSymbolValidation(EmittedAssemblyData, _compilation.Options.OutputKind, display: _compilation.AssemblyName);
                _lazyModuleSymbol = GetSymbolFromMetadata(targetReference, MetadataImportOptions.All);
            }

            if (_lazyModuleSymbol != null)
            {
                if (_visualizeRealIL == null)
                {
                    throw new InvalidOperationException("IL visualization function is not set");
                }

                return(_visualizeRealIL(_lazyModuleSymbol, methodData, markers, _testData.Module.GetMethodBody(methodData.Method).AreLocalsZeroed));
            }

            return(null);
        }
            private string VisualizeIL(CompilationTestData.MethodData methodData, bool realIL, bool useRefEmitter)
            {
                if (!realIL)
                {
                    return(ILBuilderVisualizer.ILBuilderToString(methodData.ILBuilder));
                }

                var module = this.GetModuleSymbolForEmittedImage();

                return(module != null?test.VisualizeRealIL(module, methodData) : null);
            }
        internal void VerifyIL(
            string qualifiedMethodName,
            string expectedIL,
            Func <Cci.ILocalDefinition, ILVisualizer.LocalInfo> mapLocal = null,
            MethodDefinitionHandle methodToken = default,
            [CallerFilePath] string callerPath = null,
            [CallerLineNumber] int callerLine  = 0
            )
        {
            var ilBuilder = TestData.GetMethodData(qualifiedMethodName).ILBuilder;

            Dictionary <int, string> sequencePointMarkers = null;

            if (!methodToken.IsNil)
            {
                string actualPdb = PdbToXmlConverter.DeltaPdbToXml(
                    new ImmutableMemoryStream(PdbDelta),
                    new[] { MetadataTokens.GetToken(methodToken) }
                    );
                sequencePointMarkers = ILValidation.GetSequencePointMarkers(actualPdb);

                Assert.True(
                    sequencePointMarkers.Count > 0,
                    $"No sequence points found in:{Environment.NewLine}{actualPdb}"
                    );
            }

            string actualIL = ILBuilderVisualizer.ILBuilderToString(
                ilBuilder,
                mapLocal ?? ToLocalInfo,
                sequencePointMarkers
                );

            AssertEx.AssertEqualToleratingWhitespaceDifferences(
                expectedIL,
                actualIL,
                escapeQuotes: true,
                expectedValueSourcePath: callerPath,
                expectedValueSourceLine: callerLine
                );
        }
        public void VerifyIL(
            string qualifiedMethodName,
            string expectedIL,
            Func <Cci.ILocalDefinition, ILVisualizer.LocalInfo> mapLocal = null,
            MethodDefinitionHandle methodToken = default(MethodDefinitionHandle),
            [CallerFilePath] string callerPath = null,
            [CallerLineNumber] int callerLine  = 0)
        {
            var ilBuilder = TestData.GetMethodData(qualifiedMethodName).ILBuilder;

            Dictionary <int, string> sequencePointMarkers = null;

            if (!methodToken.IsNil)
            {
                string actualPdb = PdbToXmlConverter.DeltaPdbToXml(PdbDelta, new[] { MetadataTokens.GetToken(methodToken) });
                sequencePointMarkers = TestBase.GetMarkers(actualPdb);
            }

            string actualIL = ILBuilderVisualizer.ILBuilderToString(ilBuilder, mapLocal ?? ToLocalInfo, sequencePointMarkers);

            AssertEx.AssertEqualToleratingWhitespaceDifferences(expectedIL, actualIL, escapeQuotes: true, expectedValueSourcePath: callerPath, expectedValueSourceLine: callerLine);
        }
            private string VisualizeIL(CompilationTestData.MethodData methodData, bool realIL, string sequencePoints, bool useRefEmitter)
            {
                Dictionary <int, string> markers = null;

                if (sequencePoints != null)
                {
                    var actualPdbXml = PdbToXmlConverter.ToXml(
                        pdbStream: new MemoryStream(EmittedAssemblyPdb.ToArray()),
                        peStream: new MemoryStream(EmittedAssemblyData.ToArray()),
                        options: PdbToXmlOptions.ResolveTokens | PdbToXmlOptions.ThrowOnError,
                        methodName: sequencePoints);

                    markers = GetMarkers(actualPdbXml);
                }

                if (!realIL)
                {
                    return(ILBuilderVisualizer.ILBuilderToString(methodData.ILBuilder, markers: markers));
                }

                var module = this.GetModuleSymbolForEmittedImage();

                return(module != null?_test.VisualizeRealIL(module, methodData, markers) : null);
            }
Exemple #6
0
 internal static string GetMethodIL(this CompilationTestData.MethodData method)
 {
     return(ILBuilderVisualizer.ILBuilderToString(method.ILBuilder));
 }
Exemple #7
0
 internal string GetMethodIL(string qualifiedMethodName)
 {
     return(ILBuilderVisualizer.ILBuilderToString(this.TestData.GetMethodData(qualifiedMethodName).ILBuilder, ToLocalInfo));
 }
        internal static string VisualizeIL(CompilationTestData testData, Func <MethodSymbol, bool> predicate)
        {
            var builder = testData.GetIL(m => predicate((MethodSymbol)m));

            return(ILBuilderVisualizer.ILBuilderToString(builder));
        }