/// <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 void Execute(DfirRoot dfirRoot, CompileCancellationToken cancellationToken) { var nodesToDecompose = dfirRoot.GetAllNodesIncludingSelf().Where(CanDecompose).ToList(); nodesToDecompose.ForEach(Decompose); }
/// <inheritdoc /> public override async Task <Tuple <CompileCacheEntry, CompileSignature> > CompileCoreAsync( CompileSpecification compileSpecification, DfirRoot targetDfir, CompileCancellationToken cancellationToken, ProgressToken progressToken, CompileThreadState compileThreadState) { var compileSignatureParameters = new List <CompileSignatureParameter>(); foreach (DataItem dataItem in targetDfir.DataItems.OrderBy(dataItem => dataItem.ConnectorPaneIndex)) { var compileSignatureParameter = new CompileSignatureParameter( dataItem.Name, dataItem.Name, dataItem.DataType, dataItem.ConnectorPaneInputPassingRule, dataItem.ConnectorPaneOutputPassingRule, dataItem.ConnectorPaneIndex); compileSignatureParameters.Add(compileSignatureParameter); } var compileSignatures = new Dictionary <CompilableDefinitionName, CompileSignature>(); var dependencyIdentities = new HashSet <CompileSpecification>(); foreach (var dependency in targetDfir.Dependencies.OfType <CompileInvalidationDfirDependency>().ToList()) { dependencyIdentities.Add(ConvertToCompileSpecificationDuringMigration(dependency.DependeeName)); var compileSignature = await Compiler.GetCompileSignatureAsync(dependency.DependeeName, cancellationToken, progressToken, compileThreadState); if (compileSignature != null) { targetDfir.AddDependency( targetDfir, new CompileSignatureDependency(dependency.DependeeName, compileSignature)); compileSignatures[ConvertToCompilableDefinitionNameDuringMigration(dependency.DependeeName)] = compileSignature; } } var calleesIsYielding = new Dictionary <CompilableDefinitionName, bool>(); var calleesMayPanic = new Dictionary <CompilableDefinitionName, bool>(); foreach (var methodCallNode in targetDfir.GetAllNodesIncludingSelf().OfType <MethodCallNode>()) { CompileSignature calleeSignature = compileSignatures[methodCallNode.TargetName]; var functionCompileSignature = calleeSignature as FunctionCompileSignature; bool mayPanic = functionCompileSignature?.MayPanic ?? false; calleesIsYielding[methodCallNode.TargetName] = calleeSignature.IsYielding; calleesMayPanic[methodCallNode.TargetName] = mayPanic; } LLVM.FunctionCompileResult functionCompileResult = CompileFunctionForLLVM( targetDfir, cancellationToken, calleesIsYielding, calleesMayPanic); var builtPackage = new LLVM.FunctionBuiltPackage( compileSpecification, Compiler.TargetName, dependencyIdentities.ToArray(), functionCompileResult.Module, functionCompileResult.IsYielding); BuiltPackageToken token = Compiler.AddToBuiltPackagesCache(builtPackage); CompileCacheEntry entry = await Compiler.CreateStandardCompileCacheEntryFromDfirRootAsync( CompileState.Complete, targetDfir, compileSignatures, token, cancellationToken, progressToken, compileThreadState, false); var topSignature = new FunctionCompileSignature( functionName: targetDfir.Name, compileSignatureParameters: compileSignatureParameters, isYielding: functionCompileResult.IsYielding, mayPanic: functionCompileResult.MayPanic); return(new Tuple <CompileCacheEntry, CompileSignature>(entry, topSignature)); }