]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
add -app option to nesdoc to generate app-level graphs
authoridgay <idgay>
Fri, 1 Jun 2007 23:07:20 +0000 (23:07 +0000)
committeridgay <idgay>
Fri, 1 Jun 2007 23:07:20 +0000 (23:07 +0000)
tools/tinyos/ncc/nesdoc-py/archive.py
tools/tinyos/ncc/nesdoc-py/components.py
tools/tinyos/ncc/nesdoc-py/genhtml.py
tools/tinyos/ncc/nesdoc-py/graph.py
tools/tinyos/ncc/nesdoc.in

index d0acc40048b0e747c363fbed6ea39c9338da55a9..ea9cbff0506c6a669e6a9676938099cd3b84ef61 100644 (file)
@@ -40,6 +40,8 @@ from sys import *
 from getopt import getopt
 from string import *
 from nesdoc.utils import *
+from nesdoc.graph import generate_graph
+from nesdoc.html import *
 import os
 
 def check(x):
@@ -52,11 +54,13 @@ def get1(x, tag):
   return check(xml_tagfind(x, tag))
 
 def usage():
-  print "Usage: %s [-t dir] [--topdir dir] [--preserve] repository" % argv[0]
+  print "Usage: %s [-t dir] [--topdir dir] [--preserve] [--app] repository" % argv[0]
   print "  where -t/--topdir specify prefixes to remove from file names"
   print "  to create nice, package-like names for interface and components"
   print "  (based on their full filename)."
   print "  If --preserve is specified, existing XML files are preserved."
+  print "  If --app is specified, a page for this application is created in the"
+  print "  current directory."
   print "  The XML input is read from stdin."
 
 # Return package name for elem, or None if no valid name is found
@@ -99,9 +103,10 @@ def canonicalisedir(dirname):
     return dirname
 
 # option processing. See usage string for details.
-(opts, args) = getopt(argv[1:], "t:", [ "topdir=", "preserve" ])
-topopts = filter(lambda (x): x[0] != "--preserve", opts)
+(opts, args) = getopt(argv[1:], "t:", [ "topdir=", "preserve", "app" ])
+topopts = filter(lambda (x): x[0] != "--preserve" and x[0] != "--app", opts)
 preserve = filter(lambda(x): x[0] == "--preserve", opts) != []
+app = filter(lambda(x): x[0] == "--app", opts) != []
 topdirs = map(lambda (x): canonicalisedir(x[1]), topopts)
 if len(args) != 1:
   usage()
@@ -172,6 +177,30 @@ for x in dom.getElementsByTagName("interfacedef-ref"):
 for x in dom.getElementsByTagName("component-ref"):
   set_nicename(x)
 
+# Do the app stuff if requested
+if app:
+  # The firt component is the main application component.
+  toplevel = xml_idx(components, 0)
+  name = toplevel.getAttribute("qname")
+  nicename = toplevel.getAttribute("nicename")
+  wiring = xml_tag(xml_tag(dom, "nesc"), "wiring")
+  generate_graph(".", repository, dom, wiring, name, nicename)
+
+  ht = Html("%s.html" % nicename)
+  ht.title("Application: " + nicename)
+  ht.body()
+  ht.push("h2");
+  ht.p("Application: " + nicename)
+  ht.popln();
+  ht.pushln("map", 'name="comp"')
+  cmap = file("%s.cmap" % nicename)
+  for line in cmap.readlines():
+    ht.pln(line)
+  cmap.close()
+  ht.popln()
+  ht.tag("img", 'src="%s.png"' % nicename, 'usemap="#comp"', 'id=imgwiring')
+  ht.close()
+
 # save xml information per-interface and per-component in the specified
 # repository
 nmkdir(repository)
index f6ee41ac86c40ccab7e0b8571e3f1d616d9d8a05..e27ac18dfff4fb4e8f1c94ef7693c1abf40b737c 100644 (file)
@@ -116,5 +116,5 @@ def generate_component(comp):
       ht.pln(line)
     cmap.close()
     ht.popln()
-    ht.tag("img", 'src="%s.gif"' % nicename, 'usemap="#comp"', 'id=imgwiring')
+    ht.tag("img", 'src="%s.png"' % nicename, 'usemap="#comp"', 'id=imgwiring')
   ht.close()
index 6aa3e6d9ef2fecf75bb4832f16df43154f85dfb2..e775198bce246be81b2303c31eae4a8e73b925fc 100644 (file)
@@ -25,7 +25,7 @@
 from nesdoc.utils import *
 from nesdoc.interfaces import generate_interface
 from nesdoc.components import generate_component
-from nesdoc.graph import generate_graph
+from nesdoc.graph import generate_component_graph
 from nesdoc.index import generate_indices
 from sys import *
 from re import search, compile
@@ -84,7 +84,7 @@ for comp in compfiles:
   if search("\\.xml$", comp):
     stderr.write("component " + comp + "\n")
     ixml = parse("components/" + comp)
-    generate_graph(ixml.documentElement)
+    generate_component_graph(ixml.documentElement)
     generate_component(ixml.documentElement)
     ixml.unlink()
 
index 28766c877da423fd405239603a4fead7135ad6f6..0fe7238dfe290e806be5d9dc9e18127ecead4850 100644 (file)
@@ -14,13 +14,14 @@ from nesdoc.generators import *
 from sys import *
 from os import system
 
-def generate_graph(comp):
-  name = comp.getAttribute("qname")
-  nicename = comp.getAttribute("nicename")
-  wiring = xml_tag(comp, "wiring")
+def generate_component_graph(comp):
+  generate_graph("chtml", "..", comp, xml_tag(comp, "wiring"),
+                 comp.getAttribute("qname"), comp.getAttribute("nicename"))
+  
+def generate_graph(dir, repository, xml, wiring, name, nicename):
   if not wiring:
     return
-  
+
   # Return the element definition for a given wiring endpoint
   def lookup_elem(endpoint):
     elemref = xml_tagset(endpoint, [ "interface-ref", "function-ref" ])
@@ -79,10 +80,10 @@ def generate_graph(comp):
           styles.append('label="%s"' % instanceof_name)
         else:
           styles.append('label="%s\\n(%s)"' % (instanceof_name, iname))
-        styles.append('URL="%s.html"' % instanceof.getAttribute("nicename"))
+        styles.append('URL="%s/chtml/%s.html"' % (repository, instanceof.getAttribute("nicename")))
       else:
         # Just a regular component
-        styles.append('URL="%s.html"' % ncomp.getAttribute("nicename"))
+        styles.append('URL="%s/chtml/%s.html"' % (repository, ncomp.getAttribute("nicename")))
       if styles != []:
         gf.write("[%s]" % join(styles, ", "))
       gf.write(";\n")
@@ -116,7 +117,7 @@ def generate_graph(comp):
       styles = [ 'label="%s"' % sig ]
       if xml_tag(elem, "interface-parameters"):
         styles.append('style=bold')
-      styles.append('URL="../ihtml/%s.html"' % idef.getAttribute("nicename"))
+      styles.append('URL="%s/ihtml/%s.html"' % (repository, idef.getAttribute("nicename")))
     styles.append("fontsize=10")
     return styles
 
@@ -124,15 +125,15 @@ def generate_graph(comp):
   # build indices from ref attribute values to the corresponding elements
   refidx = {}
   compidx = {}
-  for intf in comp.getElementsByTagName("interface"):
+  for intf in xml.getElementsByTagName("interface"):
     refidx[intf.getAttribute("ref")] = intf
-  for fn in comp.getElementsByTagName("function"):
+  for fn in xml.getElementsByTagName("function"):
     refidx[fn.getAttribute("ref")] = fn
-  for ncomp in comp.getElementsByTagName("component"):
+  for ncomp in xml.getElementsByTagName("component"):
     compidx[ncomp.getAttribute("qname")] = ncomp
   
   # create the dot graph specification
-  gf = file("chtml/%s.dot" % nicename, "w")
+  gf = file("%s/%s.dot" % (dir, nicename), "w")
   gf.write('digraph "%s" {\n' % nicename)
   
   endpoints = {}
@@ -149,5 +150,5 @@ def generate_graph(comp):
   gf.close()
 
   # Run dot twice to get a picture and cmap
-  system("dot -Tgif -ochtml/%s.gif chtml/%s.dot" % (nicename, nicename))
-  system("dot -Tcmap -ochtml/%s.cmap chtml/%s.dot" % (nicename, nicename))
+  system("dot -Tpng -o%s/%s.png %s/%s.dot" % (dir, nicename, dir, nicename))
+  system("dot -Tcmap -o%s/%s.cmap %s/%s.dot" % (dir, nicename, dir, nicename))
index 783493b2c8d7697da2389f00ddeffbcb2c5a9630..47a731de3daa21977550d753db5dbd4ad116d4e4 100644 (file)
@@ -93,6 +93,10 @@ for ($i = 0; $i <= $#ARGV; $i++) {
            $preserve = 1;
            $strip = 1;
        }
+       elsif (/^-app$/) {
+           $app = 1;
+           $strip = 1;
+       }
     }
     push @ncc_args, $_ if !$strip;
 }
@@ -120,6 +124,7 @@ if ($genhtml) {
 # nesdoc-archive
 
 unshift @ncc_args, "-fsyntax-only";
+unshift @ncc_args, "-fnesc-dump=wiring" if $app;
 unshift @ncc_args, "-fnesc-dump=interfacedefs";
 unshift @ncc_args, "-fnesc-dump=components(wiring)";
 unshift @ncc_args, "-fnesc-dump=interfaces";
@@ -144,6 +149,7 @@ $toscontainer = `dirname $tosdir`;
 chomp $toscontainer;
 push @archive_args, "--topdir=$toscontainer";
 push @archive_args, "--preserve" if $preserve;
+push @archive_args, "--app" if $app;
 push @archive_args, "$docdir";
 unshift @archive_args, "$libprogs/nesdoc/archive.py";
 unshift @archive_args, $python;
@@ -172,6 +178,10 @@ Usage: nesdoc -o <documentation directory> <ncc options and nesC files>
 
        nesdoc -o <documentation directory> -html
         Generate nesdoc html pages from archived nesdoc information.
+
+       nesdoc -o <documentation directory> -app <ncc options and nesC file>
+         Compile specified nesC application and generate a wiring graph
+        for the whole program in the current directory.
 EOM
 )
 }