private FunctionVariableStorage RunAllocator(DfirRoot function) { var cancellationToken = new CompileCancellationToken(); RunCompilationUpToAsyncNodeDecomposition(function, cancellationToken); ExecutionOrderSortingVisitor.SortDiagrams(function); var asyncStateGrouper = new AsyncStateGrouper(); asyncStateGrouper.Execute(function, cancellationToken); IEnumerable <AsyncStateGroup> asyncStateGroups = asyncStateGrouper.GetAsyncStateGroups(); using (var contextWrapper = new ContextWrapper()) { var module = contextWrapper.CreateModule("module"); var functionImporter = new FunctionImporter(contextWrapper, module); var codeGenExpander = new CodeGenExpander( function, new FunctionModuleContext(contextWrapper, module, functionImporter), new Dictionary <CompilableDefinitionName, bool>()); asyncStateGroups.ForEach(codeGenExpander.ExpandAsyncStateGroup); var variableStorage = new FunctionVariableStorage(); var allocator = new Allocator(contextWrapper, variableStorage, asyncStateGroups); allocator.Execute(function, cancellationToken); return(variableStorage); } }
internal static Function CompileFunctionForBytecodeInterpreter(DfirRoot dfirRoot, CompileCancellationToken cancellationToken) { ExecutionOrderSortingVisitor.SortDiagrams(dfirRoot); var variableAllocations = VariableReference.CreateDictionaryWithUniqueVariableKeys <ValueSource>(); var allocator = new BytecodeInterpreterAllocator(variableAllocations); allocator.Execute(dfirRoot, cancellationToken); IEnumerable <LocalAllocationValueSource> localAllocations = variableAllocations.Values.OfType <LocalAllocationValueSource>(); int[] localSizes = new int[localAllocations.Count()]; foreach (var allocation in localAllocations) { localSizes[allocation.Index] = allocation.Size; } var functionBuilder = new FunctionBuilder() { Name = dfirRoot.SpecAndQName.EditorName, LocalSizes = localSizes }; new FunctionCompiler(functionBuilder, variableAllocations).Execute(dfirRoot, cancellationToken); return(functionBuilder.CreateFunction()); }
internal static LLVM.FunctionCompileResult CompileFunctionForLLVM( DfirRoot dfirRoot, CompileCancellationToken cancellationToken, Dictionary <CompilableDefinitionName, bool> calleesIsYielding, Dictionary <CompilableDefinitionName, bool> calleesMayPanic, string compiledFunctionName = "") { // TODO: running this here because it needs to know which callee Functions are yielding/panicking. new AsyncNodeDecompositionTransform(calleesIsYielding, calleesMayPanic, new NodeInsertionTypeUnificationResultFactory()) .Execute(dfirRoot, cancellationToken); ExecutionOrderSortingVisitor.SortDiagrams(dfirRoot); var asyncStateGrouper = new AsyncStateGrouper(); asyncStateGrouper.Execute(dfirRoot, cancellationToken); IEnumerable <AsyncStateGroup> asyncStateGroups = asyncStateGrouper.GetAsyncStateGroups(); using (var contextWrapper = new LLVM.ContextWrapper()) { var module = contextWrapper.CreateModule("module"); var functionImporter = new LLVM.FunctionImporter(contextWrapper, module); var codeGenExpander = new CodeGenExpander( dfirRoot, new LLVM.FunctionModuleContext(contextWrapper, module, functionImporter), calleesMayPanic); asyncStateGroups.ForEach(codeGenExpander.ExpandAsyncStateGroup); #if DEBUG string prettyPrintAsyncStateGroups = asyncStateGroups.PrettyPrintAsyncStateGroups(); #endif bool isYielding = asyncStateGroups.Select(g => g.FunctionId).Distinct().HasMoreThan(1); bool mayPanic = asyncStateGroups.Any(group => group.StartsWithPanicOrContinue); var variableStorage = new LLVM.FunctionVariableStorage(); var allocator = new Allocator(contextWrapper, variableStorage, asyncStateGroups); allocator.Execute(dfirRoot, cancellationToken); compiledFunctionName = string.IsNullOrEmpty(compiledFunctionName) ? FunctionLLVMName(dfirRoot.CompileSpecification.Name) : compiledFunctionName; var parameterInfos = dfirRoot.DataItems.OrderBy(d => d.ConnectorPaneIndex).Select(ToParameterInfo).ToArray(); var sharedData = new LLVM.FunctionCompilerSharedData( contextWrapper, module, parameterInfos, allocator.AllocationSet, variableStorage, functionImporter); var moduleBuilder = isYielding ? new LLVM.AsynchronousFunctionModuleBuilder(sharedData, compiledFunctionName, asyncStateGroups) : (LLVM.FunctionModuleBuilder) new LLVM.SynchronousFunctionModuleBuilder(sharedData, compiledFunctionName, asyncStateGroups); sharedData.VisitationHandler = new LLVM.FunctionCompiler(moduleBuilder, sharedData, codeGenExpander.ReservedIndexCount); moduleBuilder.CompileFunction(); module.VerifyAndThrowIfInvalid(); return(new LLVM.FunctionCompileResult(new LLVM.ContextFreeModule(module), isYielding, mayPanic)); } }
private IEnumerable <AsyncStateGroup> GroupAsyncStates(DfirRoot function) { ExecutionOrderSortingVisitor.SortDiagrams(function); var asyncStateGrouper = new AsyncStateGrouper(); asyncStateGrouper.Execute(function, new NationalInstruments.Compiler.CompileCancellationToken()); return(asyncStateGrouper.GetAsyncStateGroups()); }
internal static Module CompileFunctionForLLVM(DfirRoot dfirRoot, CompileCancellationToken cancellationToken, string compiledFunctionName = "") { ExecutionOrderSortingVisitor.SortDiagrams(dfirRoot); Dictionary <VariableReference, LLVM.ValueSource> valueSources = VariableReference.CreateDictionaryWithUniqueVariableKeys <LLVM.ValueSource>(); LLVM.Allocator allocator = new LLVM.Allocator(valueSources); allocator.Execute(dfirRoot, cancellationToken); Module module = new Module("module"); compiledFunctionName = string.IsNullOrEmpty(compiledFunctionName) ? dfirRoot.SpecAndQName.RuntimeName : compiledFunctionName; LLVM.FunctionCompiler functionCompiler = new LLVM.FunctionCompiler(module, compiledFunctionName, valueSources); functionCompiler.Execute(dfirRoot, cancellationToken); return(module); }
public override MocTransformManager GenerateMocTransformManagerAndSourceDfir(DfirCreationArguments creationArguments) { var dfirBuilder = new FunctionDfirBuilder(); var function = (Function)creationArguments.SourceModel; dfirBuilder.VisitFunction(function); var dfirRoot = dfirBuilder.CreatedDfirRoot; FunctionMocReflector reflector = new FunctionMocReflector( function, creationArguments.ReflectionCancellationToken, _host.GetSharedExportedValue <ScheduledActivityManager>(), AdditionalErrorTexts, creationArguments.BuildSpecSource, creationArguments.SpecAndQName, dfirBuilder.DfirModelMap); creationArguments.PrebuildTransform(dfirRoot, reflector, this); ExecutionOrderSortingVisitor.SortDiagrams(dfirRoot); return(GenerateMocTransformManager(creationArguments.SpecAndQName, dfirRoot, new CompileCancellationToken())); }
public override MocTransformManager GenerateMocTransformManagerAndSourceDfir(DfirCreationArguments creationArguments) { var typeDiagramDefinition = (TypeDiagramDefinition)creationArguments.SourceModel; var typeDiagramDfirBuilder = new TypeDiagramDfirBuilder(); typeDiagramDfirBuilder.VisitTypeDiagram(typeDiagramDefinition.RootDiagram); DfirRoot dfirRoot = typeDiagramDfirBuilder.TypeDiagramDfirRoot; TypeDiagramMocReflector reflector = new TypeDiagramMocReflector( typeDiagramDefinition, creationArguments.ReflectionCancellationToken, _host.GetSharedExportedValue <ScheduledActivityManager>(), AdditionalErrorTexts, creationArguments.BuildSpecSource, creationArguments.CompileSpecification, typeDiagramDfirBuilder.DfirModelMap); creationArguments.PrebuildTransform(dfirRoot, reflector, this); ExecutionOrderSortingVisitor.SortDiagrams(dfirRoot); return(GenerateMocTransformManager(creationArguments.CompileSpecification, dfirRoot, new CompileCancellationToken())); }
protected void RunSemanticAnalysisUpToCreateNodeFacades(DfirRoot dfirRoot, CompileCancellationToken cancellationToken = null) { ExecutionOrderSortingVisitor.SortDiagrams(dfirRoot); cancellationToken = cancellationToken ?? new CompileCancellationToken(); new CreateNodeFacadesTransform().Execute(dfirRoot, cancellationToken); }