Changeset c123609 in mainline


Ignore:
Timestamp:
2009-10-09T14:18:20Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0772aff, f307f12
Parents:
8e21512e
Message:

represent provided and required interfaces
merge common binding, subsume and delegate paths to a single edge
(this generates a slightly more readable figure)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • contrib/arch/hadlbppp.py

    r8e21512e rc123609  
    554554        return result
    555555
    556 def merge_subarch(prefix, arch, outdir):
     556def merge_arch(prefix, arch, outdir):
    557557        "Merge subarchitecture into architecture"
    558558       
     
    566566                        subarch = get_arch(inst['type'])
    567567                        if (not subarch is None):
    568                                 (subinsts, subbinds, subdelegates, subsubsumes) = merge_subarch("%s_%s" % (prefix, subarch['name']), subarch, outdir)
     568                                (subinsts, subbinds, subdelegates, subsubsumes) = merge_arch("%s_%s" % (prefix, subarch['name']), subarch, outdir)
    569569                                insts.extend(subinsts)
    570570                                binds.extend(subbinds)
     
    613613                        subarch = get_arch(inst['type'])
    614614                        if (not subarch is None):
    615                                 (subinsts, subbinds, subdelegates, subsubsumes) = merge_subarch(subarch['name'], subarch, outdir)
     615                                (subinsts, subbinds, subdelegates, subsubsumes) = merge_arch(subarch['name'], subarch, outdir)
    616616                                insts.extend(subinsts)
    617617                                binds.extend(subbinds)
     
    15851585                        recursion(base, canon, output, level + 1)
    15861586
    1587 def merge_bind(subarchs, delegates, subsumes, prefix, bfrom, bto, outf, indent):
    1588         "Update binding according to bound object types"
    1589        
    1590         pfrom = "%s%s" % (prefix, bfrom[0])
    1591         pto = "%s%s" % (prefix, bto[0])
    1592         attrs = []
    1593        
    1594         if (bfrom[0] in subarchs):
    1595                 sfrom = subsumes[pfrom][bfrom[1]]
    1596                 attrs.append("ltail=cluster_%s" % pfrom)
    1597         else:
    1598                 sfrom = pfrom
    1599        
    1600         if (bto[0] in subarchs):
    1601                 sto = delegates[pto][bto[1]]
    1602                 attrs.append("lhead=cluster_%s" % pto)
    1603         else:
    1604                 sto = pto
    1605        
    1606         outf.write("%s\t%s -> %s" % (tabs(indent), sfrom, sto))
    1607         if (len(attrs) > 0):
    1608                 outf.write(" [%s]" % ", ".join(attrs))
    1609         outf.write(";\n")
    1610 
    1611 def merge_dot_subarch(prefix, name, arch, outf, indent):
     1587def merge_dot_frame(prefix, name, frame, outf, indent):
     1588        "Dump Dot frame"
     1589       
     1590        outf.write("%ssubgraph cluster_%s {\n" % (tabs(indent), prefix))
     1591        outf.write("%s\tlabel=\"%s\";\n" % (tabs(indent), name))
     1592        outf.write("%s\tstyle=filled;\n" % tabs(indent))
     1593        outf.write("%s\tcolor=red;\n" % tabs(indent))
     1594        outf.write("%s\tfillcolor=yellow;\n" % tabs(indent))
     1595        outf.write("%s\t\n" % tabs(indent))
     1596       
     1597        if ('provides' in frame):
     1598                outf.write("%s\t%s__provides [label=\"\", shape=doublecircle, style=filled, color=green, fillcolor=yellow];\n" % (tabs(indent), prefix))
     1599       
     1600        if ('requires' in frame):
     1601                outf.write("%s\t%s__requires [label=\"\", shape=circle, style=filled, color=red, fillcolor=yellow];\n" % (tabs(indent), prefix))
     1602       
     1603        outf.write("%s}\n" % tabs(indent))
     1604        outf.write("%s\n" % tabs(indent))
     1605
     1606def merge_dot_arch(prefix, name, arch, outf, indent):
    16121607        "Dump Dot subarchitecture"
    16131608       
     
    16171612        outf.write("%s\t\n" % tabs(indent))
    16181613       
    1619         subarchs = set()
    1620         delegates = {}
    1621         subsumes = {}
    1622        
    1623         delegates[prefix] = {}
    1624         subsumes[prefix] = {}
    1625        
    16261614        if ('inst' in arch):
    16271615                for inst in arch['inst']:
    16281616                        subarch = get_arch(inst['type'])
    16291617                        if (not subarch is None):
    1630                                 (subdelegates, subsubsumes) = merge_dot_subarch("%s_%s" % (prefix, inst['var']), inst['var'], subarch, outf, indent + 1)
    1631                                 subarchs.add(inst['var'])
    1632                                 delegates.update(subdelegates)
    1633                                 subsumes.update(subsubsumes)
     1618                                merge_dot_arch("%s_%s" % (prefix, inst['var']), inst['var'], subarch, outf, indent + 1)
    16341619                        else:
    16351620                                subframe = get_frame(inst['type'])
    16361621                                if (not subframe is None):
    1637                                         outf.write("%s\t%s_%s [label=\"%s\", shape=component, style=filled, color=red, fillcolor=yellow];\n" % (tabs(indent), prefix, inst['var'], inst['var']))
     1622                                        merge_dot_frame("%s_%s" % (prefix, inst['var']), inst['var'], subframe, outf, indent + 1)
    16381623                                else:
    16391624                                        print "%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type'])
    16401625       
    16411626        if ('bind' in arch):
     1627                labels = {}
    16421628                for bind in arch['bind']:
    1643                         merge_bind(subarchs, delegates, subsumes, "%s_" % prefix, bind['from'], bind['to'], outf, indent)
     1629                        if (bind['from'][1] != bind['to'][1]):
     1630                                label = "%s:%s" % (bind['from'][1], bind['to'][1])
     1631                        else:
     1632                                label = bind['from'][1]
     1633                       
     1634                        if (not (bind['from'][0], bind['to'][0]) in labels):
     1635                                labels[(bind['from'][0], bind['to'][0])] = []
     1636                       
     1637                        labels[(bind['from'][0], bind['to'][0])].append(label)
     1638               
     1639                for bind in arch['bind']:
     1640                        if (not (bind['from'][0], bind['to'][0]) in labels):
     1641                                continue
     1642                       
     1643                        attrs = []
     1644                       
     1645                        if (bind['from'][0] != bind['to'][0]):
     1646                                attrs.append("ltail=cluster_%s_%s" % (prefix, bind['from'][0]))
     1647                                attrs.append("lhead=cluster_%s_%s" % (prefix, bind['to'][0]))
     1648                       
     1649                        attrs.append("label=\"%s\"" % "\\n".join(labels[(bind['from'][0], bind['to'][0])]))
     1650                        del labels[(bind['from'][0], bind['to'][0])]
     1651                       
     1652                        outf.write("%s\t%s_%s__requires -> %s_%s__provides [%s];\n" % (tabs(indent), prefix, bind['from'][0], prefix, bind['to'][0], ", ".join(attrs)))
    16441653       
    16451654        if ('delegate' in arch):
     1655                outf.write("%s\t%s__provides [label=\"\", shape=doublecircle, color=green];\n" % (tabs(indent), prefix))
     1656               
     1657                labels = {}
    16461658                for delegate in arch['delegate']:
    1647                         delegates[prefix][delegate['from']] = "%s_%s" % (prefix, delegate['to'][0])
     1659                        if (delegate['from'] != delegate['to'][1]):
     1660                                label = "%s:%s" % (delegate['from'], delegate['to'][1])
     1661                        else:
     1662                                label = delegate['from']
     1663                       
     1664                        if (not delegate['to'][0] in labels):
     1665                                labels[delegate['to'][0]] = []
     1666                       
     1667                        labels[delegate['to'][0]].append(label)
     1668               
     1669                for delegate in arch['delegate']:
     1670                        if (not delegate['to'][0] in labels):
     1671                                continue
     1672                       
     1673                        attrs = []
     1674                        attrs.append("color=gray")
     1675                        attrs.append("lhead=cluster_%s_%s" % (prefix, delegate['to'][0]))
     1676                        attrs.append("label=\"%s\"" % "\\n".join(labels[delegate['to'][0]]))
     1677                        del labels[delegate['to'][0]]
     1678                       
     1679                        outf.write("%s\t%s__provides -> %s_%s__provides [%s];\n" % (tabs(indent), prefix, prefix, delegate['to'][0], ", ".join(attrs)))
    16481680       
    16491681        if ('subsume' in arch):
     1682                outf.write("%s\t%s__requires [label=\"\", shape=circle, color=red];\n" % (tabs(indent), prefix))
     1683               
     1684                labels = {}
    16501685                for subsume in arch['subsume']:
    1651                         subsumes[prefix][subsume['to']] = "%s_%s" % (prefix, subsume['from'][0])
     1686                        if (subsume['from'][1] != subsume['to']):
     1687                                label = "%s:%s" % (subsume['from'][1], subsume['to'])
     1688                        else:
     1689                                label = subsume['to']
     1690                       
     1691                        if (not subsume['from'][0] in labels):
     1692                                labels[subsume['from'][0]] = []
     1693                       
     1694                        labels[subsume['from'][0]].append(label)
     1695               
     1696                for subsume in arch['subsume']:
     1697                        if (not subsume['from'][0] in labels):
     1698                                continue
     1699                       
     1700                        attrs = []
     1701                        attrs.append("color=gray")
     1702                        attrs.append("ltail=cluster_%s_%s" % (prefix, subsume['from'][0]))
     1703                        attrs.append("label=\"%s\"" % "\\n".join(labels[subsume['from'][0]]))
     1704                        del labels[subsume['from'][0]]
     1705                       
     1706                        outf.write("%s\t%s_%s__requires -> %s__requires [%s];\n" % (tabs(indent), prefix, subsume['from'][0], prefix, ", ".join(attrs)))
    16521707       
    16531708        outf.write("%s}\n" % tabs(indent))
    16541709        outf.write("%s\n" % tabs(indent))
    1655        
    1656         return (delegates, subsumes)
    16571710
    16581711def dump_dot(outdir):
     
    16741727                outf.write("\tlabel=\"%s\";\n" % arch['name'])
    16751728                outf.write("\tcompound=true;\n")
     1729                outf.write("\tedge [fontsize=8];\n")
    16761730                outf.write("\t\n")
    1677                
    1678                 subarchs = set()
    1679                 delegates = {}
    1680                 subsumes = {}
    16811731               
    16821732                if ('inst' in arch):
     
    16841734                                subarch = get_arch(inst['type'])
    16851735                                if (not subarch is None):
    1686                                         (subdelegates, subsubsumes) = merge_dot_subarch(inst['var'], inst['var'], subarch, outf, 1)
    1687                                         subarchs.add(inst['var'])
    1688                                         delegates.update(subdelegates)
    1689                                         subsumes.update(subsubsumes)
     1736                                        merge_dot_arch(inst['var'], inst['var'], subarch, outf, 1)
    16901737                                else:
    16911738                                        subframe = get_frame(inst['type'])
    16921739                                        if (not subframe is None):
    1693                                                 outf.write("\t%s [shape=component, style=filled, color=red, fillcolor=yellow];\n" % inst['var'])
     1740                                                merge_dot_frame("%s" % inst['var'], inst['var'], subframe, outf, 1)
    16941741                                        else:
    16951742                                                print "%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type'])
    16961743               
    16971744                if ('bind' in arch):
     1745                        labels = {}
    16981746                        for bind in arch['bind']:
    1699                                 merge_bind(subarchs, delegates, subsumes, "", bind['from'], bind['to'], outf, 0)
     1747                                if (bind['from'][1] != bind['to'][1]):
     1748                                        label = "%s:%s" % (bind['from'][1], bind['to'][1])
     1749                                else:
     1750                                        label = bind['from'][1]
     1751                               
     1752                                if (not (bind['from'][0], bind['to'][0]) in labels):
     1753                                        labels[(bind['from'][0], bind['to'][0])] = []
     1754                               
     1755                                labels[(bind['from'][0], bind['to'][0])].append(label)
     1756                       
     1757                        for bind in arch['bind']:
     1758                                if (not (bind['from'][0], bind['to'][0]) in labels):
     1759                                        continue
     1760                               
     1761                                attrs = []
     1762                               
     1763                                if (bind['from'][0] != bind['to'][0]):
     1764                                        attrs.append("ltail=cluster_%s" % bind['from'][0])
     1765                                        attrs.append("lhead=cluster_%s" % bind['to'][0])
     1766                               
     1767                                attrs.append("label=\"%s\"" % "\\n".join(labels[(bind['from'][0], bind['to'][0])]))
     1768                                del labels[(bind['from'][0], bind['to'][0])]
     1769                               
     1770                                outf.write("\t%s__requires -> %s__provides [%s];\n" % (bind['from'][0], bind['to'][0], ", ".join(attrs)))
    17001771               
    17011772                if ('delegate' in arch):
Note: See TracChangeset for help on using the changeset viewer.