Changeset 8e21512e in mainline
- Timestamp:
- 2009-10-08T16:48:21Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c123609
- Parents:
- afe34be
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
contrib/arch/hadlbppp.py
rafe34be r8e21512e 42 42 "Print usage syntax" 43 43 44 print "%s <--bp|--ebp|--adl|--nop>+ <OUTPUT>" % prname 44 print "%s <--bp|--ebp|--adl|--dot|--nop>+ <OUTPUT>" % prname 45 print 46 print "--bp Dump original Behavior Protocols (dChecker, BPSlicer)" 47 print "--ebp Dump Extended Behavior Protocols (bp2promela)" 48 print "--adl Dump Architecture Description Language (modified SOFA ADL/CDL)" 49 print "--dot Dump Dot architecture diagram (GraphViz)" 50 print "--nop Do not dump anything (just input files syntax check)" 51 print 45 52 46 53 def tabs(cnt): … … 632 639 break 633 640 634 635 641 outname = os.path.join(outdir, "%s.archbp" % arch['name']) 636 642 if ((opt_bp) or (opt_ebp)): … … 1579 1585 recursion(base, canon, output, level + 1) 1580 1586 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): 1612 "Dump Dot subarchitecture" 1613 1614 outf.write("%ssubgraph cluster_%s {\n" % (tabs(indent), prefix)) 1615 outf.write("%s\tlabel=\"%s\";\n" % (tabs(indent), name)) 1616 outf.write("%s\tcolor=red;\n" % tabs(indent)) 1617 outf.write("%s\t\n" % tabs(indent)) 1618 1619 subarchs = set() 1620 delegates = {} 1621 subsumes = {} 1622 1623 delegates[prefix] = {} 1624 subsumes[prefix] = {} 1625 1626 if ('inst' in arch): 1627 for inst in arch['inst']: 1628 subarch = get_arch(inst['type']) 1629 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) 1634 else: 1635 subframe = get_frame(inst['type']) 1636 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'])) 1638 else: 1639 print "%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type']) 1640 1641 if ('bind' in arch): 1642 for bind in arch['bind']: 1643 merge_bind(subarchs, delegates, subsumes, "%s_" % prefix, bind['from'], bind['to'], outf, indent) 1644 1645 if ('delegate' in arch): 1646 for delegate in arch['delegate']: 1647 delegates[prefix][delegate['from']] = "%s_%s" % (prefix, delegate['to'][0]) 1648 1649 if ('subsume' in arch): 1650 for subsume in arch['subsume']: 1651 subsumes[prefix][subsume['to']] = "%s_%s" % (prefix, subsume['from'][0]) 1652 1653 outf.write("%s}\n" % tabs(indent)) 1654 outf.write("%s\n" % tabs(indent)) 1655 1656 return (delegates, subsumes) 1657 1658 def dump_dot(outdir): 1659 "Dump Dot architecture" 1660 1661 global opt_dot 1662 1663 arch = get_system_arch() 1664 1665 if (arch is None): 1666 print "Unable to find system architecture" 1667 return 1668 1669 if (opt_dot): 1670 outname = os.path.join(outdir, "%s.dot" % arch['name']) 1671 outf = file(outname, "w") 1672 1673 outf.write("digraph {\n") 1674 outf.write("\tlabel=\"%s\";\n" % arch['name']) 1675 outf.write("\tcompound=true;\n") 1676 outf.write("\t\n") 1677 1678 subarchs = set() 1679 delegates = {} 1680 subsumes = {} 1681 1682 if ('inst' in arch): 1683 for inst in arch['inst']: 1684 subarch = get_arch(inst['type']) 1685 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) 1690 else: 1691 subframe = get_frame(inst['type']) 1692 if (not subframe is None): 1693 outf.write("\t%s [shape=component, style=filled, color=red, fillcolor=yellow];\n" % inst['var']) 1694 else: 1695 print "%s: '%s' is neither an architecture nor a frame" % (arch['name'], inst['type']) 1696 1697 if ('bind' in arch): 1698 for bind in arch['bind']: 1699 merge_bind(subarchs, delegates, subsumes, "", bind['from'], bind['to'], outf, 0) 1700 1701 if ('delegate' in arch): 1702 for delegate in arch['delegate']: 1703 print "Unable to delegate interface in system architecture" 1704 break 1705 1706 if ('subsume' in arch): 1707 for subsume in arch['subsume']: 1708 print "Unable to subsume interface in system architecture" 1709 break 1710 1711 outf.write("}\n") 1712 1713 outf.close() 1714 1581 1715 def main(): 1582 1716 global iface_properties … … 1586 1720 global opt_ebp 1587 1721 global opt_adl 1722 global opt_dot 1588 1723 1589 1724 if (len(sys.argv) < 3): … … 1594 1729 opt_ebp = False 1595 1730 opt_adl = False 1731 opt_dot = False 1596 1732 1597 1733 for arg in sys.argv[1:(len(sys.argv) - 1)]: … … 1602 1738 elif (arg == "--adl"): 1603 1739 opt_adl = True 1740 elif (arg == "--dot"): 1741 opt_dot = True 1604 1742 elif (arg == "--nop"): 1605 1743 pass … … 1623 1761 recursion(".", ".", path, 0) 1624 1762 dump_archbp(path) 1763 dump_dot(path) 1625 1764 1626 1765 if __name__ == '__main__':
Note:
See TracChangeset
for help on using the changeset viewer.