public override void WriteDependencyLog(string outputFileName) { using (FileStream dgmlOutput = new FileStream(outputFileName, FileMode.Create)) { DgmlWriter.WriteDependencyGraphToStream(dgmlOutput, _dependencyGraph, _nodeFactory); dgmlOutput.Flush(); } }
void ICompilation.WriteDependencyLog(string fileName) { using (FileStream dgmlOutput = new FileStream(fileName, FileMode.Create)) { DgmlWriter.WriteDependencyGraphToStream(dgmlOutput, _dependencyGraph, _nodeFactory); dgmlOutput.Flush(); } }
public void WriteDependencyLog(string fileName) { using (FileStream dgmlOutput = new FileStream(fileName, FileMode.Create)) { DgmlWriter.WriteDependencyGraphToStream(dgmlOutput, _graph, _factory); dgmlOutput.Flush(); } }
public Grapher(AppSettings settings) { InputFolder = settings.InputFolder; GroupFolder = settings.GroupFolder; UsePrefixes = settings.UsePrefixes; Verbose = settings.Verbose; _dgmlWriter = new DgmlWriter(); CustomizeGraph(); }
public string SaveDgml(string filePath, bool whatIf = false) { var writer = new DgmlWriter(); Console.WriteLine("Analyzing the async graphs..."); var visualContext = VisuaNodes.VisualContext.Create(Nodes, simplify: true); foreach (var node in visualContext.EnumerateVisualNodes()) { writer.AddNode(new DgmlWriter.Node(id: node.Id, label: node.DisplayText)); //foreach (var dependency in node.Dependencies.OrderBy(d => d.Id)) foreach (var dependency in node.AwaitsOn) { writer.AddLink(new DgmlWriter.Link( source: node.Id, target: dependency.Id, label: null)); } } if (whatIf) { return(writer.SerializeAsString()); } if (File.Exists(filePath)) { var existingFile = File.ReadAllText(filePath); var newFile = writer.SerializeAsString(); if (existingFile == newFile) { Console.WriteLine("No changes were detected!"); } else { Console.WriteLine("The diagram has changaed!"); writer.Serialize(filePath); } } else { writer.Serialize(filePath); } return(writer.SerializeAsString()); }
/// <summary> /// Exports the contents of the given pip graph. It is expected to no longer change as of the start of this call. /// </summary> public override int Analyze() { DgmlWriter writer = new DgmlWriter(); Dictionary <PipId, PipReference> concretePipValues = new Dictionary <PipId, PipReference>(); HashSet <PipReference> allValuePips = new HashSet <PipReference>(PipGraph.RetrievePipReferencesOfType(PipType.Value)); foreach (var valuePip in allValuePips) { foreach (var incoming in DataflowGraph.GetIncomingEdges(valuePip.PipId.ToNodeId())) { if (!PipTable.GetPipType(incoming.OtherNode.ToPipId()).IsMetaPip()) { concretePipValues[valuePip.PipId] = valuePip; } } } foreach (var concretePipValue in concretePipValues.Values) { var value = ((ValuePip)concretePipValue.HydratePip()).Symbol.ToString(SymbolTable); writer.AddNode(new DgmlWriter.Node(concretePipValue.PipId.ToString(), value)); foreach (var incoming in DataflowGraph.GetIncomingEdges(concretePipValue.PipId.ToNodeId())) { var incomingId = incoming.OtherNode.ToPipId(); if (concretePipValues.ContainsKey(incomingId)) { writer.AddLink(new DgmlWriter.Link( incomingId.ToString(), concretePipValue.PipId.ToString(), label: null)); } } } writer.Serialize(m_dgmlFilePath); return(0); }
public void CreateDiagram(string path) { var parser = new BoardDgmlParser(); // Get all links var edges = new List <Edge <Component> >(); foreach (var cycle in _board.Cycle()) { edges.AddRange(parser.ParseCyclesToEdge(cycle)); } parser.Parse(new BoardDgmlStrategy(), edges); var dgmlWriter = new DgmlWriter(); dgmlWriter.Nodes = parser.Nodes; dgmlWriter.Links = parser.Links; dgmlWriter.Serialize(path); }
public void TestDGMLOutput() { Dictionary <string, string> dgmlOutputs = new Dictionary <string, string>(); TestOnGraphTypes((TestGraph testGraph, DependencyAnalyzerBase <TestGraph> analyzer) => { BuildGraphUsingAllTypesOfRules(testGraph, analyzer); MemoryStream dgmlOutput = new MemoryStream(); DgmlWriter.WriteDependencyGraphToStream(dgmlOutput, analyzer); dgmlOutput.Seek(0, SeekOrigin.Begin); TextReader tr = new StreamReader(dgmlOutput); dgmlOutputs[analyzer.GetType().FullName] = tr.ReadToEnd(); }); foreach (var pair in dgmlOutputs) { int nodeCount = pair.Value.Split(new string[] { "<Node " }, StringSplitOptions.None).Length - 1; int edgeCount = pair.Value.Split(new string[] { "<Link " }, StringSplitOptions.None).Length - 1; if (pair.Key.Contains("FullGraph")) { Assert.Equal(21, nodeCount); Assert.Equal(23, edgeCount); } else if (pair.Key.Contains("FirstMark")) { // There are 2 edges in the all types of rules graph that are duplicates. Note that the edge count is // 2 less than the full graph edge count Assert.Equal(21, nodeCount); Assert.Equal(21, edgeCount); } else { Assert.Contains("NoLog", pair.Key); Assert.Equal(11, nodeCount); Assert.Equal(0, edgeCount); } } }
public void Compile() { NodeFactory.NameMangler = NameMangler; string systemModuleName = ((IAssemblyDesc)_typeSystemContext.SystemModule).GetName().Name; // TODO: just something to get Runtime.Base compiled if (systemModuleName != "System.Private.CoreLib") { NodeFactory.CompilationUnitPrefix = systemModuleName.Replace(".", "_"); } else { NodeFactory.CompilationUnitPrefix = NameMangler.SanitizeName(Path.GetFileNameWithoutExtension(Options.OutputFilePath)); } if (_options.IsCppCodeGen) { _nodeFactory = new CppCodegenNodeFactory(_typeSystemContext, _compilationModuleGroup); } else { _nodeFactory = new RyuJitNodeFactory(_typeSystemContext, _compilationModuleGroup); } // Choose which dependency graph implementation to use based on the amount of logging requested. if (_options.DgmlLog == null) { // No log uses the NoLogStrategy _dependencyGraph = new DependencyAnalyzer <NoLogStrategy <NodeFactory>, NodeFactory>(_nodeFactory, null); } else { if (_options.FullLog) { // Full log uses the full log strategy _dependencyGraph = new DependencyAnalyzer <FullGraphLogStrategy <NodeFactory>, NodeFactory>(_nodeFactory, null); } else { // Otherwise, use the first mark strategy _dependencyGraph = new DependencyAnalyzer <FirstMarkLogStrategy <NodeFactory>, NodeFactory>(_nodeFactory, null); } } _nodeFactory.AttachToDependencyGraph(_dependencyGraph); if (_options.IsCppCodeGen) { _cppWriter = new CppCodeGen.CppWriter(this); _dependencyGraph.ComputeDependencyRoutine += CppCodeGenComputeDependencyNodeDependencies; var nodes = _dependencyGraph.MarkedNodeList; _cppWriter.OutputCode(nodes, _compilationModuleGroup.StartupCodeMain, _nodeFactory); } else { _corInfo = new CorInfoImpl(this); _dependencyGraph.ComputeDependencyRoutine += ComputeDependencyNodeDependencies; var nodes = _dependencyGraph.MarkedNodeList; ObjectWriter.EmitObject(_options.OutputFilePath, nodes, _nodeFactory); } if (_options.DgmlLog != null) { using (FileStream dgmlOutput = new FileStream(_options.DgmlLog, FileMode.Create)) { DgmlWriter.WriteDependencyGraphToStream(dgmlOutput, _dependencyGraph); dgmlOutput.Flush(); } } }
public void CompileSingleFile() { NodeFactory.NameMangler = NameMangler; _nodeFactory = new NodeFactory(_typeSystemContext, _options.IsCppCodeGen); // Choose which dependency graph implementation to use based on the amount of logging requested. if (_options.DgmlLog == null) { // No log uses the NoLogStrategy _dependencyGraph = new DependencyAnalyzer <NoLogStrategy <NodeFactory>, NodeFactory>(_nodeFactory, null); } else { if (_options.FullLog) { // Full log uses the full log strategy _dependencyGraph = new DependencyAnalyzer <FullGraphLogStrategy <NodeFactory>, NodeFactory>(_nodeFactory, null); } else { // Otherwise, use the first mark strategy _dependencyGraph = new DependencyAnalyzer <FirstMarkLogStrategy <NodeFactory>, NodeFactory>(_nodeFactory, null); } } _nodeFactory.AttachToDependencyGraph(_dependencyGraph); AddWellKnownTypes(); AddCompilationRoots(); if (_options.IsCppCodeGen) { _cppWriter = new CppCodeGen.CppWriter(this); _dependencyGraph.ComputeDependencyRoutine += CppCodeGenComputeDependencyNodeDependencies; var nodes = _dependencyGraph.MarkedNodeList; _cppWriter.OutputCode(nodes); } else { _corInfo = new CorInfoImpl(this); _dependencyGraph.ComputeDependencyRoutine += ComputeDependencyNodeDependencies; var nodes = _dependencyGraph.MarkedNodeList; ObjectWriter.EmitObject(_options.OutputFilePath, nodes, _nodeFactory); } if (_options.DgmlLog != null) { using (FileStream dgmlOutput = new FileStream(_options.DgmlLog, FileMode.Create)) { DgmlWriter.WriteDependencyGraphToStream(dgmlOutput, _dependencyGraph); dgmlOutput.Flush(); } } }
public void CompileSingleFile() { NodeFactory.NameMangler = NameMangler; _nodeFactory = new NodeFactory(_typeSystemContext, _typeInitManager, _compilationModuleGroup, _options.IsCppCodeGen); // Choose which dependency graph implementation to use based on the amount of logging requested. if (_options.DgmlLog == null) { // No log uses the NoLogStrategy _dependencyGraph = new DependencyAnalyzer <NoLogStrategy <NodeFactory>, NodeFactory>(_nodeFactory, null); } else { if (_options.FullLog) { // Full log uses the full log strategy _dependencyGraph = new DependencyAnalyzer <FullGraphLogStrategy <NodeFactory>, NodeFactory>(_nodeFactory, null); } else { // Otherwise, use the first mark strategy _dependencyGraph = new DependencyAnalyzer <FirstMarkLogStrategy <NodeFactory>, NodeFactory>(_nodeFactory, null); } } _nodeFactory.AttachToDependencyGraph(_dependencyGraph); _compilationModuleGroup.AddWellKnownTypes(); _compilationModuleGroup.AddCompilationRoots(); if (!_options.IsCppCodeGen && !_options.MultiFile) { // TODO: build a general purpose way to hook up pieces that would be part of the core library // if factoring of the core library respected how things are, versus how they would be in // a magic world (future customers of this mechanism will be interop and serialization). var refExec = _typeSystemContext.GetModuleForSimpleName("System.Private.Reflection.Execution"); var exec = refExec.GetKnownType("Internal.Reflection.Execution", "ReflectionExecution"); AddCompilationRoot(exec.GetStaticConstructor(), "Reflection execution"); } if (_options.IsCppCodeGen) { _cppWriter = new CppCodeGen.CppWriter(this); _dependencyGraph.ComputeDependencyRoutine += CppCodeGenComputeDependencyNodeDependencies; var nodes = _dependencyGraph.MarkedNodeList; _cppWriter.OutputCode(nodes, _compilationModuleGroup.StartupCodeMain); } else { _corInfo = new CorInfoImpl(this); _dependencyGraph.ComputeDependencyRoutine += ComputeDependencyNodeDependencies; var nodes = _dependencyGraph.MarkedNodeList; ObjectWriter.EmitObject(_options.OutputFilePath, nodes, _nodeFactory); } if (_options.DgmlLog != null) { using (FileStream dgmlOutput = new FileStream(_options.DgmlLog, FileMode.Create)) { DgmlWriter.WriteDependencyGraphToStream(dgmlOutput, _dependencyGraph); dgmlOutput.Flush(); } } }
public void CompileSingleFile(MethodDesc mainMethod) { if (_options.IsCppCodeGen) { _cppWriter = new CppCodeGen.CppWriter(this); } else { _corInfo = new CorInfoImpl(this); } _mainMethod = mainMethod; if (!_options.IsCppCodeGen) { _nodeFactory = new NodeFactory(this._typeSystemContext); NodeFactory.NameMangler = NameMangler; // Choose which dependency graph implementation to use based on the amount of logging requested. if (_options.DgmlLog == null) { // No log uses the NoLogStrategy _dependencyGraph = new DependencyAnalyzer <NoLogStrategy <NodeFactory>, NodeFactory>(_nodeFactory, null); } else { if (_options.FullLog) { // Full log uses the full log strategy _dependencyGraph = new DependencyAnalyzer <FullGraphLogStrategy <NodeFactory>, NodeFactory>(_nodeFactory, null); } else { // Otherwise, use the first mark strategy _dependencyGraph = new DependencyAnalyzer <FirstMarkLogStrategy <NodeFactory>, NodeFactory>(_nodeFactory, null); } } _nodeFactory.AttachToDependencyGraph(_dependencyGraph); AddWellKnownTypes(); AddCompilationRoots(); _dependencyGraph.ComputeDependencyRoutine += ComputeDependencyNodeDependencies; var nodes = _dependencyGraph.MarkedNodeList; var mainMethodNode = (_mainMethod != null) ? _nodeFactory.MethodEntrypoint(_mainMethod) : null; ObjectWriter.EmitObject(OutputPath, nodes, mainMethodNode, _nodeFactory); if (_options.DgmlLog != null) { using (FileStream dgmlOutput = new FileStream(_options.DgmlLog, FileMode.Create)) { DgmlWriter.WriteDependencyGraphToStream(dgmlOutput, _dependencyGraph); dgmlOutput.Flush(); } } } else { AddWellKnownTypes(); AddCompilationRoots(); while (_methodsThatNeedsCompilation != null) { CompileMethods(); ExpandVirtualMethods(); } _cppWriter.OutputCode(); } }