internal override CommonPEModuleBuilder CreateModuleBuilder(EmitOptions emitOptions, IMethodSymbol debugEntryPoint, IEnumerable <ResourceDescription> manifestResources, CompilationTestData testData, DiagnosticBag diagnostics, CancellationToken cancellationToken) { Debug.Assert(!IsSubmission || HasCodeToEmit()); var runtimeMDVersion = GetRuntimeMetadataVersion(emitOptions, diagnostics); if (runtimeMDVersion == null) { Debug.Assert(runtimeMDVersion != null, "Set PhpCommandLineArguments.EmitOptions"); return(null); } var moduleProps = ConstructModuleSerializationProperties(emitOptions, runtimeMDVersion); if (manifestResources == null) { manifestResources = SpecializedCollections.EmptyEnumerable <ResourceDescription>(); } PEModuleBuilder moduleBeingBuilt; if (_options.OutputKind.IsNetModule()) { moduleBeingBuilt = new PENetModuleBuilder( this, SourceModule, emitOptions, moduleProps, manifestResources); } else { var kind = _options.OutputKind.IsValid() ? _options.OutputKind : OutputKind.DynamicallyLinkedLibrary; moduleBeingBuilt = new PEAssemblyBuilder( SourceAssembly, moduleProps, manifestResources, kind, emitOptions); } if (debugEntryPoint != null) { moduleBeingBuilt.SetDebugEntryPoint(debugEntryPoint, diagnostics); } // testData is only passed when running tests. if (testData != null) { //moduleBeingBuilt.SetMethodTestData(testData.Methods); //testData.Module = moduleBeingBuilt; throw new NotImplementedException(); } return(moduleBeingBuilt); }
internal static BoundStatement ParseAndBindMethodBody(string program, bool lower, string typeName = DefaultTypeName, string methodName = DefaultMethodName) { var compilation = CreateCompilationWithMscorlib(program); var method = (MethodSymbol)compilation.GlobalNamespace.GetTypeMembers(typeName).Single().GetMembers(methodName).Single(); var diagnostics = DiagnosticBag.GetInstance(); try { // Provide an Emit.Module so that the lowering passes will be run var module = new PEAssemblyBuilder( (SourceAssemblySymbol)compilation.Assembly, EmitOptions.Default, OutputKind.ConsoleApplication, GetDefaultModulePropertiesForSerialization(), Enumerable.Empty <ResourceDescription>(), assemblySymbolMapper: null); TypeCompilationState compilationState = new TypeCompilationState(method.ContainingType, compilation, module); var block = MethodCompiler.BindMethodBody(method, compilationState, diagnostics); if ((block == null) || !lower) { return(block); } StateMachineTypeSymbol stateMachineTypeOpt; VariableSlotAllocator lazyVariableSlotAllocator = null; var lambdaDebugInfoBuilder = ArrayBuilder <LambdaDebugInfo> .GetInstance(); var closureDebugInfoBuilder = ArrayBuilder <ClosureDebugInfo> .GetInstance(); var body = MethodCompiler.LowerBodyOrInitializer( method: method, methodOrdinal: 0, body: block, previousSubmissionFields: null, compilationState: compilationState, diagnostics: diagnostics, lazyVariableSlotAllocator: ref lazyVariableSlotAllocator, lambdaDebugInfoBuilder: lambdaDebugInfoBuilder, closureDebugInfoBuilder: closureDebugInfoBuilder, stateMachineTypeOpt: out stateMachineTypeOpt); lambdaDebugInfoBuilder.Free(); closureDebugInfoBuilder.Free(); return(body); } finally { diagnostics.Free(); } }
internal static BoundBlock ParseAndBindMethodBody(string program, string typeName = DefaultTypeName, string methodName = DefaultMethodName) { var compilation = CreateCompilation(program); var method = (MethodSymbol)compilation.GlobalNamespace.GetTypeMembers(typeName).Single().GetMembers(methodName).Single(); // Provide an Emit.Module so that the lowering passes will be run var module = new PEAssemblyBuilder( (SourceAssemblySymbol)compilation.Assembly, emitOptions: EmitOptions.Default, outputKind: OutputKind.ConsoleApplication, serializationProperties: GetDefaultModulePropertiesForSerialization(), manifestResources: Enumerable.Empty <ResourceDescription>()); TypeCompilationState compilationState = new TypeCompilationState(method.ContainingType, compilation, module); var diagnostics = DiagnosticBag.GetInstance(); var block = MethodCompiler.BindMethodBody(method, compilationState, diagnostics); diagnostics.Free(); return(block); }
internal static BoundStatement ParseAndBindMethodBody(string program, bool lower, string typeName = DefaultTypeName, string methodName = DefaultMethodName) { var compilation = CreateCompilationWithMscorlib(program); var method = (MethodSymbol)compilation.GlobalNamespace.GetTypeMembers(typeName).Single().GetMembers(methodName).Single(); var diagnostics = DiagnosticBag.GetInstance(); try { var block = Compiler.BindMethodBody(method, diagnostics); if ((block == null) || !lower) { return(block); } // Provide an Emit.Module so that the lowering passes will be run var module = new PEAssemblyBuilder( (SourceAssemblySymbol)compilation.Assembly, null, OutputKind.ConsoleApplication, GetDefaultModulePropertiesForSerialization(), Enumerable.Empty <ResourceDescription>(), assemblySymbolMapper: null); TypeCompilationState compilationState = new TypeCompilationState(method.ContainingType, module); var body = Compiler.LowerStatement( generateDebugInfo: true, method: method, body: block, previousSubmissionFields: null, compilationState: compilationState, diagnostics: diagnostics); return(body); } finally { diagnostics.Free(); } }
internal static void VerifyParamArrayAttribute(ParameterSymbol parameter, SourceModuleSymbol module, bool expected = true, OutputKind outputKind = OutputKind.ConsoleApplication) { Assert.Equal(expected, parameter.IsParams); var emitModule = new PEAssemblyBuilder(module.ContainingSourceAssembly, EmitOptions.Default, outputKind, GetDefaultModulePropertiesForSerialization(), SpecializedCollections.EmptyEnumerable <ResourceDescription>()); var paramArrayAttributeCtor = (MethodSymbol)emitModule.Compilation.GetWellKnownTypeMember(WellKnownMember.System_ParamArrayAttribute__ctor); bool found = false; var context = new EmitContext(emitModule, null, new DiagnosticBag()); foreach (Microsoft.Cci.ICustomAttribute attr in parameter.GetSynthesizedAttributes()) { if (paramArrayAttributeCtor == (MethodSymbol)attr.Constructor(context)) { Assert.False(found, "Multiple ParamArrayAttribute"); found = true; } } Assert.Equal(expected, found); context.Diagnostics.Verify(); }