private static async Task <DfirRoot> GenerateDfirAsync( ICompositionHost host, Envoy documentEnvoy, ProgressToken progressToken, CompileCancellationToken compileCancellationToken) { ExtendedQualifiedName topLevelDocumentName = documentEnvoy.CreateExtendedQualifiedName(); TargetCompiler targetCompiler = documentEnvoy.QueryInheritedService <ITargetCompilerServices>().First().Compiler; AnyMocCompiler compiler = host.GetSharedExportedValue <AnyMocCompiler>(); IReadOnlySymbolTable symbolTable = documentEnvoy.ComputeSymbolTable(); // A specAndQName is used by the compiler to identify the document for which we're asking for DFIR. var specAndQName = new SpecAndQName(targetCompiler.CreateDefaultBuildSpec(topLevelDocumentName, symbolTable), topLevelDocumentName); try { DfirRoot sourceDfirRoot = await compiler.GetTargetDfirAsync(specAndQName, compileCancellationToken, progressToken); if (sourceDfirRoot == null) { await ShowErrorMessageBoxAsync(host, WaitForCompileErrorMessageBoxText); } return(sourceDfirRoot); } catch { await ShowErrorMessageBoxAsync(host, DfirGenerationErrorMessageBoxText); return(null); } }
public override MocTransformManager GenerateMocTransformManager( CompileSpecification compileSpecification, DfirRoot sourceDfir, CompileCancellationToken cancellationToken) { var semanticAnalysisTransforms = new List <IDfirTransformBase>() { new CreateTypeDiagramNodeFacadesTransform(), new UnifyTypesAcrossWiresTransform(), new ValidateTypeUsagesTransform(), new ReflectVariablesToTerminalsTransform(), new StandardTypeReflectionTransform() }; ReflectErrorsTransform.AddErrorReflection(semanticAnalysisTransforms, CompilePhase.SemanticAnalysis); var toTargetDfirTransforms = new List <IDfirTransformBase>() { }; return(new StandardMocTransformManager( compileSpecification, sourceDfir, semanticAnalysisTransforms, toTargetDfirTransforms, _host.GetSharedExportedValue <ScheduledActivityManager>())); }
public Task DecomposeAsync(Diagram diagram, DecompositionTerminalAssociator terminalAssociator, ISemanticAnalysisTargetInfo targetInfo, CompileCancellationToken cancellationToken) { // Don't do anything; one of the transforms added by FunctionMocPlugin should remove all of these nodes from the DfirGraph during // target DFIR translation. return(AsyncHelpers.CompletedTask); }
protected void RunTypeDiagramSemanticAnalysisUpToValidation(DfirRoot typeDiagram) { var cancellationToken = new CompileCancellationToken(); RunSemanticAnalysisUpToTypeInference(typeDiagram, cancellationToken); new ValidateTypeUsagesTransform().Execute(typeDiagram, cancellationToken); }
internal LLVMSharp.Module RunSemanticAnalysisUpToLLVMCodeGeneration(DfirRoot dfirRoot, string compiledFunctionName) { var cancellationToken = new CompileCancellationToken(); RunCompilationUpToAutomaticNodeInsertion(dfirRoot, cancellationToken); return(FunctionCompileHandler.CompileFunctionForLLVM(dfirRoot, cancellationToken, compiledFunctionName)); }
internal global::Rebar.RebarTarget.BytecodeInterpreter.Function RunSemanticAnalysisUpToCodeGeneration(DfirRoot dfirRoot) { var cancellationToken = new CompileCancellationToken(); RunCompilationUpToAutomaticNodeInsertion(dfirRoot, cancellationToken); return(FunctionCompileHandler.CompileFunctionForBytecodeInterpreter(dfirRoot, cancellationToken)); }
protected void RunCompilationUpToAutomaticNodeInsertion(DfirRoot dfirRoot, CompileCancellationToken cancellationToken = null) { cancellationToken = cancellationToken ?? new CompileCancellationToken(); var lifetimeVariableAssociation = new LifetimeVariableAssociation(); RunSemanticAnalysisUpToValidation(dfirRoot, cancellationToken, lifetimeVariableAssociation); if (DfirMessageHelper.CalculateIsBroken(dfirRoot)) { var messageBuilder = new StringBuilder("Compilation failed because DfirRoot has semantic errors:\n"); foreach (DfirNodeMessagePair messagePair in DfirMessageHelper.ListAllNodeUserMessages(dfirRoot, false)) { messageBuilder.AppendLine($"{messagePair.Node}: {messagePair.Message.Descriptor}"); } Assert.Fail(messageBuilder.ToString()); } new AutoBorrowTransform(lifetimeVariableAssociation).Execute(dfirRoot, cancellationToken); var nodeInsertionTypeUnificationResultFactory = new NodeInsertionTypeUnificationResultFactory(); new InsertTerminateLifetimeTransform(lifetimeVariableAssociation, nodeInsertionTypeUnificationResultFactory) .Execute(dfirRoot, cancellationToken); new InsertDropTransform(lifetimeVariableAssociation, nodeInsertionTypeUnificationResultFactory) .Execute(dfirRoot, cancellationToken); }
/// <summary> /// An example of modifying the DFIR. Remove debug points, maybe because they are noise in the Dfir graph for our purposes. /// </summary> private static void RemoveDebugPoints(DfirRoot sourceDfirRoot, CompileCancellationToken compileCancellationToken) { if (sourceDfirRoot == null) { return; } if (compileCancellationToken.IsCancellationRequested) { CompileCanceledException.ThrowIt(); } List <DebugPoint> debugPoints = sourceDfirRoot.GetAllNodesIncludingSelf().OfType <DebugPoint>().ToList(); foreach (DebugPoint debugPoint in debugPoints) { foreach (Terminal terminal in debugPoint.Terminals) { if (!terminal.IsConnected) { continue; } Terminal connectedTerminal = terminal.ConnectedTerminal; var wire = connectedTerminal.ParentNode as Wire; terminal.Disconnect(); wire?.RemoveOutput(connectedTerminal); } debugPoint.RemoveFromGraph(); } }
public virtual void Execute(DfirRoot dfirRoot, CompileCancellationToken cancellationToken) { VisitDfirRoot(dfirRoot); VisitDiagram(dfirRoot.BlockDiagram); TraverseDiagram(dfirRoot.BlockDiagram); PostVisitDiagram(dfirRoot.BlockDiagram); }
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 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)); } }
/// <inheritdoc /> public override async Task <Tuple <CompileCacheEntry, CompileSignature> > BackEndCompileAsyncCore( SpecAndQName specAndQName, DfirRoot targetDfir, CompileCancellationToken cancellationToken, ProgressToken progressToken, CompileThreadState compileThreadState) { CompileSignature topSignature = new CompileSignature( targetDfir.Name, Enumerable.Empty <CompileSignatureParameter>(), // GenerateParameters(targetDfir), targetDfir.GetDeclaringType(), targetDfir.Reentrancy, true, true, ThreadAffinity.Standard, false, true, ExecutionPriority.Normal, CallingConvention.StdCall); BuildSpec htmlVIBuildSpec = specAndQName.BuildSpec; foreach (var dependency in targetDfir.Dependencies.OfType <CompileInvalidationDfirDependency>().ToList()) { var compileSignature = await Compiler.GetCompileSignatureAsync(dependency.SpecAndQName, cancellationToken, progressToken, compileThreadState); if (compileSignature != null) { targetDfir.AddDependency( targetDfir, new CompileSignatureDependency(dependency.SpecAndQName, compileSignature)); } } IBuiltPackage builtPackage = null; if (!RebarFeatureToggles.IsLLVMCompilerEnabled) { Function compiledFunction = CompileFunctionForBytecodeInterpreter(targetDfir, cancellationToken); builtPackage = new FunctionBuiltPackage(specAndQName, Compiler.TargetName, compiledFunction); } else { Module compiledFunctionModule = CompileFunctionForLLVM(targetDfir, cancellationToken); builtPackage = new LLVM.FunctionBuiltPackage(specAndQName, Compiler.TargetName, compiledFunctionModule); } BuiltPackageToken token = Compiler.AddToBuiltPackagesCache(builtPackage); CompileCacheEntry entry = await Compiler.CreateStandardCompileCacheEntryFromDfirRootAsync( CompileState.Complete, targetDfir, new Dictionary <ExtendedQualifiedName, CompileSignature>(), token, cancellationToken, progressToken, compileThreadState, false); return(new Tuple <CompileCacheEntry, CompileSignature>(entry, topSignature)); }
/// <inheritdoc /> public Task <CompileInformation> GetCompileInformationAsync( CompileSpecification itemCompileSpecification, CompileCancellationToken cancellationToken, ProgressToken progressToken, CompileThreadState compileThreadState) { return(Compiler.CompileAsTopLevelAsync(itemCompileSpecification, cancellationToken, progressToken, compileThreadState)); }
public void Execute(DfirRoot dfirRoot, CompileCancellationToken cancellationToken) { var lifetimeGraphTree = dfirRoot.GetLifetimeGraphTree(); BoundedLifetimeLiveVariableSet boundedLifetimeLiveVariableSet; while (_lifetimeVariableAssociation.TryGetBoundedLifetimeWithLiveVariables(out boundedLifetimeLiveVariableSet)) { if (lifetimeGraphTree.IsDiagramLifetimeOfAnyLifetimeGraph(boundedLifetimeLiveVariableSet.Lifetime)) { // Since we assume there are no semantic errors at this point, just mark any remaining live variables // in a diagram lifetime as consumed. boundedLifetimeLiveVariableSet.LiveVariables.Select(l => l.Variable).ForEach(_lifetimeVariableAssociation.MarkVariableConsumed); continue; } int inputVariableCount = boundedLifetimeLiveVariableSet.LiveVariables.Count(); IEnumerable <VariableReference> interruptedVariables = _lifetimeVariableAssociation.GetVariablesInterruptedByLifetime(boundedLifetimeLiveVariableSet.Lifetime); int outputVariableCount = interruptedVariables.Count(); Diagram startSearch = boundedLifetimeLiveVariableSet.LiveVariables.First().Terminal.ParentDiagram; LifetimeGraphIdentifier originGraphIdentifier = lifetimeGraphTree.GetBoundedLifetimeGraphIdentifier(boundedLifetimeLiveVariableSet.Lifetime); Diagram originDiagram = originGraphIdentifier.FindDiagramForGraphIdentifier(startSearch); LiveVariable[] liveVariables = boundedLifetimeLiveVariableSet.LiveVariables.ToArray(); for (int i = 0; i < liveVariables.Length; ++i) { LiveVariable liveVariable = liveVariables[i]; while (liveVariable.Terminal.ParentDiagram != originDiagram) { liveVariable = PullLiveVariableUpToNextHigherDiagram(liveVariable); } liveVariables[i] = liveVariable; } TerminateLifetimeNode terminateLifetime = TerminateLifetimeNodeHelpers.CreateTerminateLifetimeWithFacades(originDiagram, inputVariableCount, outputVariableCount); int inputIndex = 0; foreach (LiveVariable liveVariable in liveVariables) { // TODO: maybe assert that liveVariable.Terminal is unwired here? Terminal terminateLifetimeInputTerminal = terminateLifetime.InputTerminals[inputIndex]; Wire.Create(originDiagram, liveVariable.Terminal, terminateLifetimeInputTerminal); terminateLifetimeInputTerminal.GetFacadeVariable().MergeInto(liveVariable.Variable); _lifetimeVariableAssociation.MarkVariableConsumed(liveVariable.Variable); ++inputIndex; } int outputIndex = 0; foreach (VariableReference interruptedVariable in interruptedVariables) { Terminal terminateLifetimeOutputTerminal = terminateLifetime.OutputTerminals[outputIndex]; terminateLifetimeOutputTerminal.GetFacadeVariable().MergeInto(interruptedVariable); _lifetimeVariableAssociation.MarkVariableLive(interruptedVariable, terminateLifetimeOutputTerminal); ++outputIndex; } } }
/// <inheritdoc /> public void Execute(DfirRoot dfirRoot, CompileCancellationToken cancellationToken) { dfirRoot.MarkErrorCategoryChanged(TransformCategory); if (_semanticAnalysisTargetInfo.TargetKind != RebarTarget.TargetCompiler.Kind) { dfirRoot.SetDfirMessage(MessageSeverity.Error, TransformCategory, AllModelsOfComputationErrorMessages.UnsupportedDocumentTypeOnTarget); } }
/// <inheritdoc /> public override async Task <Tuple <CompileCacheEntry, CompileSignature> > CompileCoreAsync( CompileSpecification compileSpecification, DfirRoot targetDfir, CompileCancellationToken cancellationToken, ProgressToken progressToken, CompileThreadState compileThreadState) { CompileSignature topSignature = new CompileSignature( targetDfir.Name, Enumerable.Empty <CompileSignatureParameter>(), // GenerateParameters(targetDfir), targetDfir.GetDeclaringType(), targetDfir.Reentrancy, true, true, ThreadAffinity.Standard, false, true, ExecutionPriority.Normal, CallingConvention.StdCall); BuildSpec typeDiagramBuildSpec = compileSpecification.BuildSpec; #if FALSE foreach (var dependency in targetDfir.Dependencies.OfType <CompileInvalidationDfirDependency>().ToList()) { var compileSignature = await Compiler.GetCompileSignatureAsync(dependency.SpecAndQName, cancellationToken, progressToken, compileThreadState); if (compileSignature != null) { targetDfir.AddDependency( targetDfir, new CompileSignatureDependency(dependency.SpecAndQName, compileSignature)); } } #endif IBuiltPackage builtPackage = null; // TODO: create TypeDiagramBuiltPackage builtPackage = new EmptyBuiltPackage( compileSpecification, Compiler.TargetName, Enumerable.Empty <CompileSpecification>(), CompileMetadata.Empty); BuiltPackageToken token = Compiler.AddToBuiltPackagesCache(builtPackage); CompileCacheEntry entry = await Compiler.CreateStandardCompileCacheEntryFromDfirRootAsync( CompileState.Complete, targetDfir, new Dictionary <CompilableDefinitionName, CompileSignature>(), token, cancellationToken, progressToken, compileThreadState, false); return(new Tuple <CompileCacheEntry, CompileSignature>(entry, topSignature)); }
protected void RunCompilationUpToAutomaticNodeInsertion(DfirRoot dfirRoot, CompileCancellationToken cancellationToken = null) { cancellationToken = cancellationToken ?? new CompileCancellationToken(); var lifetimeVariableAssociation = new LifetimeVariableAssociation(); RunSemanticAnalysisUpToValidation(dfirRoot, cancellationToken, lifetimeVariableAssociation); new AutoBorrowTransform(lifetimeVariableAssociation).Execute(dfirRoot, cancellationToken); new InsertTerminateLifetimeTransform(lifetimeVariableAssociation).Execute(dfirRoot, cancellationToken); new InsertDropTransform(lifetimeVariableAssociation).Execute(dfirRoot, cancellationToken); }
protected void RunCompilationUpToAsyncNodeDecomposition(DfirRoot dfirRoot, CompileCancellationToken cancellationToken = null) { cancellationToken = cancellationToken ?? new CompileCancellationToken(); RunCompilationUpToAutomaticNodeInsertion(dfirRoot, cancellationToken); var nodeInsertionTypeUnificationResultFactory = new NodeInsertionTypeUnificationResultFactory(); var emptyDictionary = new Dictionary <CompilableDefinitionName, bool>(); new AsyncNodeDecompositionTransform(emptyDictionary, emptyDictionary, nodeInsertionTypeUnificationResultFactory) .Execute(dfirRoot, cancellationToken); }
/// <summary> /// Returns a dictionary that maps subVI names of method calls in the source <see cref="DfirRoot"/> to /// the corresponding <see cref="DfirRoot"/> objects. /// </summary> /// <param name="sourceDfirRoot">The parent document that does the method call</param> /// <param name="nameDictionary">The dictionary to fill out with names to dfir maps.</param> /// <param name="compileCancellationToken">The cancellation token</param> /// <param name="progressToken">The progress token</param> /// <param name="host">The composition host</param> /// <returns>The task to wait on</returns> private static async Task GetSubDfirRootsAsync( DfirRoot sourceDfirRoot, IDictionary <ExtendedQualifiedName, DfirRoot> nameDictionary, CompileCancellationToken compileCancellationToken, ProgressToken progressToken, ICompositionHost host) { if (sourceDfirRoot == null) { return; } // Maintain a queue of VIs to visit, and visit each one. var rootsToProcess = new Queue <DfirRoot>(); // Add the top-level VI to the queue so it is visited first. rootsToProcess.Enqueue(sourceDfirRoot); while (rootsToProcess.Count > 0) { DfirRoot root = rootsToProcess.Dequeue(); foreach (MethodCall node in root.BlockDiagram.GetAllNodes().OfType <MethodCall>()) { var specAndQName = new SpecAndQName(node.TargetBuildSpec, node.TargetName); var compiler = host.GetSharedExportedValue <AnyMocCompiler>(); DfirRoot subDfirRoot; try { subDfirRoot = await compiler.GetTargetDfirAsync(specAndQName, compileCancellationToken, progressToken); RemoveDebugPoints(subDfirRoot, compileCancellationToken); } catch { await ShowErrorMessageBoxAsync(host, DfirGenerationErrorMessageBoxText); return; } if (subDfirRoot == null) { continue; } if (nameDictionary.ContainsKey(node.TargetName)) { // If the subVI has already been visited, then don't enqueue it to be visited again. continue; } // The subVI has not been visited. Add the subVI to the queue of VIs to visit. nameDictionary[node.TargetName] = subDfirRoot; rootsToProcess.Enqueue(subDfirRoot); } } }
internal FunctionCompileResult RunSemanticAnalysisUpToLLVMCodeGeneration( DfirRoot dfirRoot, string compiledFunctionName, Dictionary <CompilableDefinitionName, bool> calleesIsYielding, Dictionary <CompilableDefinitionName, bool> calleesMayPanic) { var cancellationToken = new CompileCancellationToken(); RunCompilationUpToAutomaticNodeInsertion(dfirRoot, cancellationToken); return(FunctionCompileHandler.CompileFunctionForLLVM(dfirRoot, cancellationToken, calleesIsYielding, calleesMayPanic, compiledFunctionName)); }
internal void RunSemanticAnalysisUpToValidation( DfirRoot dfirRoot, CompileCancellationToken cancellationToken = null, LifetimeVariableAssociation lifetimeVariableAssociation = null) { cancellationToken = cancellationToken ?? new CompileCancellationToken(); var unificationResults = new TerminalTypeUnificationResults(); RunSemanticAnalysisUpToSetVariableTypes(dfirRoot, cancellationToken, unificationResults, lifetimeVariableAssociation); new ValidateVariableUsagesTransform(unificationResults).Execute(dfirRoot, cancellationToken); }
internal void RunSemanticAnalysisUpToSetVariableTypes( DfirRoot dfirRoot, CompileCancellationToken cancellationToken = null, TerminalTypeUnificationResults unificationResults = null, LifetimeVariableAssociation lifetimeVariableAssociation = null) { cancellationToken = cancellationToken ?? new CompileCancellationToken(); unificationResults = unificationResults ?? new TerminalTypeUnificationResults(); lifetimeVariableAssociation = lifetimeVariableAssociation ?? new LifetimeVariableAssociation(); RunSemanticAnalysisUpToCreateNodeFacades(dfirRoot, cancellationToken); new MergeVariablesAcrossWiresTransform(lifetimeVariableAssociation, unificationResults).Execute(dfirRoot, cancellationToken); new FinalizeAutoBorrowsTransform().Execute(dfirRoot, cancellationToken); new MarkConsumedVariablesTransform(lifetimeVariableAssociation).Execute(dfirRoot, cancellationToken); }
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 void Execute(DfirRoot dfirRoot, CompileCancellationToken cancellationToken) { LiveVariable liveUnboundedLifetimeVariable; while (_lifetimeVariableAssociation.TryGetLiveVariableWithUnboundedLifetime(out liveUnboundedLifetimeVariable)) { Diagram parentDiagram = liveUnboundedLifetimeVariable.Terminal.ParentDiagram; var drop = new DropNode(parentDiagram); Terminal inputTerminal = drop.InputTerminals[0]; AutoBorrowNodeFacade nodeFacade = AutoBorrowNodeFacade.GetNodeFacade(drop); nodeFacade[inputTerminal] = new SimpleTerminalFacade(inputTerminal, default(TypeVariableReference)); Wire.Create(parentDiagram, liveUnboundedLifetimeVariable.Terminal, inputTerminal); inputTerminal.GetFacadeVariable().MergeInto(liveUnboundedLifetimeVariable.Variable); _lifetimeVariableAssociation.MarkVariableConsumed(liveUnboundedLifetimeVariable.Variable); } }
public override MocTransformManager GenerateMocTransformManager( CompileSpecification compileSpecification, DfirRoot sourceDfir, CompileCancellationToken cancellationToken) { TerminalTypeUnificationResults unificationResults = new TerminalTypeUnificationResults(); LifetimeVariableAssociation lifetimeVariableAssociation = new LifetimeVariableAssociation(); List <IDfirTransformBase> semanticAnalysisTransforms = new List <IDfirTransformBase>() { new CreateNodeFacadesTransform(), new MergeVariablesAcrossWiresTransform(lifetimeVariableAssociation, unificationResults), new FinalizeAutoBorrowsTransform(), new MarkConsumedVariablesTransform(lifetimeVariableAssociation), new ValidateVariableUsagesTransform(unificationResults), new ReflectVariablesToTerminalsTransform(), }; if (RebarFeatureToggles.IsRebarTargetEnabled) { semanticAnalysisTransforms.Add(new RebarSupportedTargetTransform(SemanticAnalysisTargetInfo)); } semanticAnalysisTransforms.Add(new StandardTypeReflectionTransform()); ReflectErrorsTransform.AddErrorReflection(semanticAnalysisTransforms, CompilePhase.SemanticAnalysis); if (!RebarFeatureToggles.IsRebarTargetEnabled) { semanticAnalysisTransforms.Add(new EmptyTargetDfirTransform()); } var nodeInsertionTypeUnificationResultFactory = new NodeInsertionTypeUnificationResultFactory(); List <IDfirTransformBase> toTargetDfirTransforms = new List <IDfirTransformBase>() { new AutoBorrowTransform(lifetimeVariableAssociation), new InsertTerminateLifetimeTransform(lifetimeVariableAssociation, nodeInsertionTypeUnificationResultFactory), new InsertDropTransform(lifetimeVariableAssociation, nodeInsertionTypeUnificationResultFactory), }; return(new StandardMocTransformManager( compileSpecification, sourceDfir, semanticAnalysisTransforms, toTargetDfirTransforms, _host.GetSharedExportedValue <ScheduledActivityManager>())); }
/// <summary> /// Generate DFIR for the document and for its subVIs. /// </summary> /// <param name="host">The composition host</param> /// <param name="documentEnvoy">The <see cref="Envoy"/> for the <see cref="Document"/> for which to generate DFIR</param> /// <returns>An awaitable task with the result DfirRoot(s)</returns> internal static async Task <Tuple <DfirRoot, IDictionary <ExtendedQualifiedName, DfirRoot> > > GenerateDfirForDocumentAndSubVIsAsync(ICompositionHost host, Envoy documentEnvoy) { var compileCancellationToken = new CompileCancellationToken(); var progressToken = new ProgressToken(); // Generate DFIR for the document DfirRoot sourceDfirRoot = await GenerateDfirAsync(host, documentEnvoy, progressToken, compileCancellationToken); if (sourceDfirRoot == null) { return(null); } // Generate DFIR for subVIs IDictionary <ExtendedQualifiedName, DfirRoot> subDfirRoots = new Dictionary <ExtendedQualifiedName, DfirRoot>(); await GetSubDfirRootsAsync(sourceDfirRoot, subDfirRoots, compileCancellationToken, progressToken, host); RemoveDebugPoints(sourceDfirRoot, compileCancellationToken); return(new Tuple <DfirRoot, IDictionary <ExtendedQualifiedName, DfirRoot> >(sourceDfirRoot, subDfirRoots)); }
/// <inheritdoc /> public override async Task <Tuple <CompileCacheEntry, CompileSignature> > CompileCoreAsync( CompileSpecification compileSpecification, DfirRoot targetDfir, CompileCancellationToken cancellationToken, ProgressToken progressToken, CompileThreadState compileThreadState) { CompileSignature topSignature = new CompileSignature( targetDfir.Name, Enumerable.Empty <CompileSignatureParameter>(), targetDfir.GetDeclaringType(), targetDfir.Reentrancy, true, true, ThreadAffinity.Standard, false, true, ExecutionPriority.Normal, CallingConvention.StdCall); var builtPackage = new EmptyBuiltPackage( compileSpecification, Compiler.TargetName, Enumerable.Empty <CompileSpecification>(), CompileMetadata.Empty); BuiltPackageToken token = Compiler.AddToBuiltPackagesCache(builtPackage); CompileCacheEntry entry = await Compiler.CreateStandardCompileCacheEntryFromDfirRootAsync( CompileState.Complete, targetDfir, new Dictionary <CompilableDefinitionName, CompileSignature>(), token, cancellationToken, progressToken, compileThreadState, false); return(new Tuple <CompileCacheEntry, CompileSignature>(entry, topSignature)); }
public void Execute(DfirRoot dfirRoot, CompileCancellationToken cancellationToken) { LiveVariable liveUnboundedLifetimeVariable; while (_lifetimeVariableAssociation.TryGetLiveVariableWithUnboundedLifetime(out liveUnboundedLifetimeVariable)) { Diagram parentDiagram = liveUnboundedLifetimeVariable.Terminal.ParentDiagram; NIType variableType = liveUnboundedLifetimeVariable.Variable.Type; if (variableType.IsCluster()) { DecomposeTupleNode decomposeTuple = InsertDecompositionForTupleVariable( parentDiagram, liveUnboundedLifetimeVariable, _unificationResultFactory); foreach (Terminal outputTerminal in decomposeTuple.OutputTerminals) { _lifetimeVariableAssociation.MarkVariableLive(outputTerminal.GetFacadeVariable(), outputTerminal); } _lifetimeVariableAssociation.MarkVariableConsumed(liveUnboundedLifetimeVariable.Variable); continue; } if (variableType.IsValueClass() && variableType.GetFields().Any()) { DecomposeStructNode decomposeStruct = InsertDecompositionForStructVariable( parentDiagram, liveUnboundedLifetimeVariable, _unificationResultFactory); foreach (Terminal outputTerminal in decomposeStruct.OutputTerminals) { _lifetimeVariableAssociation.MarkVariableLive(outputTerminal.GetFacadeVariable(), outputTerminal); } _lifetimeVariableAssociation.MarkVariableConsumed(liveUnboundedLifetimeVariable.Variable); continue; } InsertDropForVariable(parentDiagram, liveUnboundedLifetimeVariable, _unificationResultFactory); _lifetimeVariableAssociation.MarkVariableConsumed(liveUnboundedLifetimeVariable.Variable); } }
protected void RunSemanticAnalysisUpToTypeInference(DfirRoot typeDiagram, CompileCancellationToken cancellationToken = null) { cancellationToken = cancellationToken ?? new CompileCancellationToken(); new CreateTypeDiagramNodeFacadesTransform().Execute(typeDiagram, cancellationToken); new UnifyTypesAcrossWiresTransform().Execute(typeDiagram, cancellationToken); }
private async Task <bool> BuildComponentAsync(ComponentConfigurationReference configurationReference) { var progressToken = new ProgressToken(); CancellationTokenSource <CompileCancellationToken> cancellationTokenSource = CompileCancellationToken.CreateNewSource(); using (var buildMonitor = new CommandLineBuildJobMonitor(configurationReference.Configuration, progressToken, cancellationTokenSource)) { bool result = await StartBuildAsync(configurationReference, progressToken, cancellationTokenSource); return(result && await buildMonitor.WaitForBuildToFinishAsync()); } }