Initial hierarchy tree graphs generation support

parent 9896e1fc
......@@ -35,7 +35,7 @@ from .module_pool import ModulePool
from .env import Env
from . import fetch as fetch_mod
from .action import (CheckCondition, CleanModules, FetchModules, GenerateFetchMakefile, ListFiles,
ListModules, MergeCores, GenerateSimulationMakefile,
ListModules, MergeCores, Tree, GenerateSimulationMakefile,
GenerateSynthesisMakefile, GenerateRemoteSynthesisMakefile, GenerateSynthesisProject)
from ._version import __version__
......@@ -163,6 +163,8 @@ def main():
action = [ MergeCores ]
elif options.command == "project":
action = [ GenerateSynthesisProject ]
elif options.command == "tree":
action = [ Tree ]
try:
for command in action:
......@@ -221,7 +223,10 @@ def _get_parser():
dest="generate_project_vhd", default=False, action="store_true")
quartus_proj = subparsers.add_parser("quartus-project", help="create/update a quartus project including list of project")
synthesis_proj = subparsers.add_parser("project", help="create/update a project for the appropriated tool")
tree = subparsers.add_parser("tree", help="generate a module hierarchy tree")
tree.add_argument("--with-files", help="Add files to the module hierarchy tree", default=False, action="store_true", dest="withfiles")
tree.add_argument("--graphviz", dest="graphviz", default=None, help="Activate graphviz and specify the program to be used to plot the graph (twopi, gvcolor, wc, ccomps, tred, sccmap, fdp, circo, neato, acyclic, nop, gvpr, dot, sfdp)")
tree.add_argument("--web", help="Edit the tree hierarchy in a web browser", default=False, action="store_true", dest="web")
condition_check = argparse.ArgumentParser()
condition_check.add_argument("--tool", dest="tool", required=True)
condition_check.add_argument("--reference", dest="reference", required=True)
......@@ -238,7 +243,7 @@ def _get_parser():
default="", help="add arbitrary code when evaluation all manifests")
parser.add_argument("--log", dest="log",
default="info", help="set logging level (one of debug, info, warning, error, critical")
default="info", help="set logging level (one of debug, info, warning, error, critical)")
parser.add_argument("--generate-project-vhd", help="generate project.vhd file with a meta package describing the project",
dest="generate_project_vhd", default=False, action="store_true")
parser.add_argument("--force", help="force hdlmake to generate the makefile, even if the specified tool is missing", default=False, action="store_true")
......
......@@ -28,6 +28,7 @@ from .fetch_makefile import GenerateFetchMakefile
from .list_files import ListFiles
from .list_modules import ListModules
from .merge_cores import MergeCores
from .tree import Tree
from .synthesis_project import GenerateSynthesisProject
from .synthesis import GenerateSynthesisMakefile
......
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2013 CERN
# Author: Pawel Szostek (pawel.szostek@cern.ch)
#
# This file is part of Hdlmake.
#
# Hdlmake is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Hdlmake is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Hdlmake. If not, see <http://www.gnu.org/licenses/>.
from .action import Action
from hdlmake.util import path
import logging
#import pygraphviz as pgv
import networkx as nx
import numpy as np
import colorsys
# THIS IS THE BEST I'VE FOUND: http://bl.ocks.org/robschmuecker/7880033
class Tree(Action):
def run(self):
unfetched_modules = False
files_str = []
hierarchy = nx.DiGraph()
#hierarchy = pgv.AGraph(directed=True, overlap=False, strict=False, rotate=1)
#hierarchy.node_attr['shape'] = 'box'
color_index = 0
for m in self.modules_pool:
if not m.isfetched:
unfetched_modules = True
else:
if m.parent:
hierarchy.add_node(path.relpath(m.path))
#hierarchy.add_node(m)
hierarchy.add_edge(path.relpath(m.parent.path), path.relpath(m.path))
#hierarchy.add_edge(m, m.parent)
else:
hierarchy.add_node(path.relpath(m.path))
top_id = path.relpath(m.path)
#hierarchy.add_node(m)
if self.options.withfiles:
if len(m.files):
for f in m.files:
hierarchy.add_edge(path.relpath(m.path), path.relpath(f.path))
#hierarchy.add_edge(f, m)
color_index += 1
if unfetched_modules: logging.warning("Some of the modules have not been fetched!")
#hierarchy.layout(prog='dot')
#hierarchy.layout(prog='sfdp')
#hierarchy.layout()
# Define the program used to write the graphviz:
# Program should be one of:
# twopi, gvcolor, wc, ccomps, tred, sccmap, fdp,
# circo, neato, acyclic, nop, gvpr, dot, sfdp.
if self.options.graphviz:
import matplotlib.pyplot as plt
pos=nx.graphviz_layout(hierarchy, prog=self.options.graphviz, root=top_id)
nx.draw(hierarchy, pos,
with_labels=True,
alpha=0.5,
node_size=100)
plt.savefig("hierarchy.png")
plt.show()
#pos=nx.spring_layout(hierarchy)
#colors=range(len(self.modules_pool))
#nx.draw(hierarchy,pos,node_color=colors,width=4,edge_cmap=plt.cm.Blues)
#print(hierarchy)
#print(top_id)
if self.options.web:
import json
from networkx.readwrite import json_graph
data = json_graph.tree_data(hierarchy, root=top_id)
#data = json_graph.tree_data(hierarchy, root='../../ip_cores/gn4124-core')
#print(data)
s = json.dumps(data)
#print(s)
json_file = open("hierarchy.json", "w")
json_file.write(s)
json_file.close()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment