예제 #1
0
        public void CreateDotFile(Graph graph)
        {
            FileStream   file         = new FileStream(graph.Name + ".dot", FileMode.Create, FileAccess.ReadWrite);
            StreamWriter streamWriter = new StreamWriter(file, Encoding.GetEncoding(1251));
            var          dotWriter    = new DotWriter(streamWriter);

            dotWriter.Write(graph);
            streamWriter.Close();
        }
예제 #2
0
 private static void DumpCilAst(DevirtualisationContext context, VirtualisedMethod method, string suffix = null)
 {
     using (var fs = File.CreateText(Path.Combine(context.Options.OutputOptions.CilAstDumpsDirectory, $"function_{method.Function.EntrypointAddress:X4}{suffix}.dot")))
     {
         WriteHeader(fs, method);
         var writer = new DotWriter(fs, new BasicBlockSerializer(method.CallerMethod.CilMethodBody));
         writer.Write(method.ControlFlowGraph.ConvertToGraphViz(CilAstBlock.AstBlockProperty));
     }
 }
예제 #3
0
 private static void DumpILAstTree(DevirtualisationContext context, VirtualisedMethod method)
 {
     using (var fs = File.CreateText(Path.Combine(context.Options.OutputOptions.ILAstDumpsDirectory,
                                                  $"function_{method.Function.EntrypointAddress:X4}_tree.dot")))
     {
         WriteHeader(fs, method);
         var writer = new DotWriter(fs, new BasicBlockSerializer());
         writer.Write(method.ILCompilationUnit.ConvertToGraphViz());
     }
 }
예제 #4
0
 private static void DumpControlFlowGraph(DevirtualisationContext context, VirtualisedMethod method)
 {
     using (var fs = File.CreateText(Path.Combine(
                                         context.Options.OutputOptions.ILDumpsDirectory,
                                         $"function_{method.Function.EntrypointAddress:X4}.dot")))
     {
         var writer = new DotWriter(fs, new BasicBlockSerializer());
         writer.Write(method.ControlFlowGraph.ConvertToGraphViz(ILBasicBlock.BasicBlockProperty));
     }
 }
예제 #5
0
        /// <summary>
        /// Serializes the data flow graph to the provided output text writer using the dot file format.
        /// </summary>
        /// <param name="writer">The output stream.</param>
        /// <remarks>
        /// To customize the look of the resulting dot file graph, use the <see cref="DotWriter"/> class
        /// instead of this function.
        /// </remarks>
        public void ToDotGraph(TextWriter writer)
        {
            var dotWriter = new DotWriter(writer)
            {
                NodeIdentifier = new IdentifiedNodeIdentifier(),
                NodeAdorner    = new DataFlowNodeAdorner <TContents>(),
                EdgeAdorner    = new DataFlowEdgeAdorner <TContents>()
            };

            dotWriter.Write(this);
        }
        private void SaveAsDot(string path)
        {
            var writer = new DotWriter(path);

            if (Model.Presentation.GetModule <IGraphLayoutModule>().Algorithm == LayoutAlgorithm.Flow)
            {
                writer.Settings = DotPresets.Flow;
            }

            writer.Write(Model.Presentation.GetModule <ITransformationModule>().Graph, Model.Presentation.Picking, Model.Presentation);
        }
예제 #7
0
        private static void Validate(Graph g)
        {
            var writer    = new StringWriter();
            var dotWriter = new DotWriter(writer);

            dotWriter.Write(g);

            var reader    = new StringReader(writer.ToString());
            var dotReader = new DotReader(reader);
            var h         = dotReader.Read();

            Assert.Equal(g, h, new GraphComparer());
        }
예제 #8
0
        private void SyncToDocument(IGraphPresentation p, string path)
        {
            myFileWatcher.EnableRaisingEvents = false;

            using (new Profile("GraphToDotSynchronizer:OnTransformationsChanged"))
            {
                var graph = new Graph();
                foreach (var n in p.Graph.Nodes)
                {
                    graph.TryAdd(n);
                }
                foreach (var e in p.Graph.Edges)
                {
                    graph.TryAdd(e);
                }

                var transformationModule = p.GetModule <ITransformationModule>();
                foreach (var cluster in transformationModule.Graph.Clusters.OrderBy(c => c.Id))
                {
                    // we do not want to see the pseudo node added for folding but the full expanded list of nodes of this cluster
                    var folding = transformationModule.Items
                                  .OfType <ClusterFoldingTransformation>()
                                  .SingleOrDefault(f => f.Clusters.Contains(cluster.Id));

                    // the nodes we get through ITransformationModule might be new instances!
                    // -> get the right node instances based on the returned ids
                    //    (otherwiese the writer below will remove them from the output)
                    var nodes = (folding == null ? cluster.Nodes : folding.GetNodes(cluster.Id))
                                .Select(n => graph.GetNode(n.Id))
                                .ToList();

                    graph.TryAdd(new Cluster(cluster.Id, nodes));
                }

                var writer = new DotWriter(path);
                writer.PrettyPrint = true;
                if (p.GetModule <IGraphLayoutModule>().Algorithm == LayoutAlgorithm.Flow)
                {
                    writer.Settings = DotPresets.Flow;
                }

                writer.Write(graph, new NullGraphPicking(), p);
            }

            myFileWatcher.EnableRaisingEvents = true;
        }
예제 #9
0
        private static void Validate(Graph g, bool separate, bool semicolons)
        {
            var writer    = new StringWriter();
            var dotWriter = new DotWriter(writer);

            dotWriter.SeparateNodesAndEdges = separate;
            dotWriter.IncludeSemicolons     = semicolons;
            dotWriter.Write(g);

            var reader    = new StringReader(writer.ToString());
            var dotReader = new DotReader(reader);
            var h         = dotReader.Read();

            Assert.Equal(g, h, new GraphComparer
            {
                IncludeUserData = true
            });
        }
예제 #10
0
        public static int Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += (s, a) => { Console.WriteLine($"Unhandled exception: {((Exception)a.ExceptionObject).Message}"); };

            var options = ParseCommandLine(args);

            string clonePath = options.ClonePath;
            var    cloneUrls = File.ReadAllLines(options.CloneUrlsFile);

            // load
            var gitConfig = new GitConfig
            {
                CloneBaseFolder     = clonePath,
                UserName            = options.UserName,
                Password            = options.Password,
                RepositoryCloneUrls = cloneUrls,
                ShallowClone        = true
            };

            Console.WriteLine($"Starting git clone operation on {cloneUrls.Length} repositories...");
            using (var loader = new GitLoader(gitConfig))
            {
                if (!loader.Success)
                {
                    Console.WriteLine("Loader failed to load; exiting");
                    return(1);
                }

                // read
                var dependencies = ReadDependencies(new NuGetReader(loader.Location));

                // write
                var writer = new DotWriter(options.GraphName, options.OutputFileName);
                writer.Write(dependencies);

                Console.WriteLine("Cleaning up...");
            }

            Console.WriteLine("Done.");
            return(0);
        }
예제 #11
0
        public static void Serialize(string file, IGraphPresentation presentation)
        {
            var graph = presentation.GetModule <ITransformationModule>().Graph;

            if (graph.Nodes.Any(n => presentation.Picking.Pick(n)))
            {
                Console.WriteLine("Dumping graph ...");

                var writer = new DotWriter(file);
                writer.PrettyPrint = true;
                writer.Write(graph, presentation.Picking, presentation);
            }
            else
            {
                Console.WriteLine("Graph is empty");

                if (File.Exists(file))
                {
                    File.Delete(file);
                }
            }
        }
예제 #12
0
        public void BuildTest()
        {
            int inchannels = 4, outchannels = 6, inwidth = 13, inheight = 17, kwidth = 3, kheight = 5, stride = 2, batch = 7;

            VariableField x = new Tensor(Shape.Map2D(inchannels, inwidth, inheight, batch));

            Layer layer = new Convolution2D(inchannels, outchannels, kwidth, kheight, stride, use_bias: true, pad_mode: PaddingMode.Edge, "conv");

            Field y = layer.Forward(x);

            (Graph.Node[] nodes, Graph.Edge[] edges) = Graph.Build(y);

            Assert.AreEqual(9, nodes.Length);
            Assert.AreEqual(8, edges.Length);

            foreach (var node in nodes)
            {
                Console.WriteLine(node.Name);
            }
            foreach (var edge in edges)
            {
                Console.WriteLine($"{edge.InNode.Name} -> {edge.OutNode.Name}");
            }

            DotWriter.Write("test.dot", nodes, edges);

            Graph.WriteDotFile("test2.dot", y);

            (Flow flow, Parameters parameters) = Flow.Optimize(y);
            flow.Execute();

            Assert.AreEqual(2, parameters.Count);
            Assert.AreEqual(inchannels, layer.InChannels);
            Assert.AreEqual(outchannels, layer.OutChannels);
            Assert.AreEqual(kwidth, layer.Width);
            Assert.AreEqual(kheight, layer.Height);
        }