1.1 --- a/TO_DO.txt Thu Nov 17 01:49:57 2011 +0100
1.2 +++ b/TO_DO.txt Wed Nov 23 00:13:21 2011 +0100
1.3 @@ -64,6 +64,12 @@
1.4 Attribute Usage
1.5 ===============
1.6
1.7 +Consolidate interface observations by taking all cached table accesses and determining
1.8 +which usage patterns lead to the same types. For example, if full usage of {a, b} and
1.9 +{a, b, c} leads to A and B in both cases, either {a, b} can be considered as partial usage
1.10 +of the complete interface {a, b, c}, or the latter can be considered as an
1.11 +overspecification of the former.
1.12 +
1.13 Make the gathering of usage parameterisable according to the optimisation level so that a
1.14 choice can be made between control-flow-dependent observations and the simple collection
1.15 of all attributes used with a name (producing a more static interface observation).
2.1 --- a/micropython/report.py Thu Nov 17 01:49:57 2011 +0100
2.2 +++ b/micropython/report.py Wed Nov 23 00:13:21 2011 +0100
2.3 @@ -3,7 +3,7 @@
2.4 """
2.5 View annotated sources.
2.6
2.7 -Copyright (C) 2006, 2007, 2010 Paul Boddie <paul@boddie.org.uk>
2.8 +Copyright (C) 2006, 2007, 2010, 2011 Paul Boddie <paul@boddie.org.uk>
2.9
2.10 This program is free software; you can redistribute it and/or modify it under
2.11 the terms of the GNU General Public License as published by the Free Software
2.12 @@ -34,7 +34,7 @@
2.13 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2.14 <html xmlns="http://www.w3.org/1999/xhtml">
2.15 <head>
2.16 - <title>Module: %(full_name)s</title>
2.17 + <title>%(title)s</title>
2.18 <style type="text/css">
2.19 html {
2.20 background-color: black; color: white;
2.21 @@ -125,11 +125,27 @@
2.22 vertical-align: top;
2.23 }
2.24
2.25 + th.summary-class {
2.26 + font-weight: normal;
2.27 + }
2.28 +
2.29 .summary-attr {
2.30 background-color: #070;
2.31 + }
2.32 +
2.33 + .summary-interface,
2.34 + .summary-attr {
2.35 font-size: smaller;
2.36 }
2.37
2.38 + .summary-interface.complete {
2.39 + background-color: #050;
2.40 + }
2.41 +
2.42 + .summary-interface.partial {
2.43 + background-color: #005;
2.44 + }
2.45 +
2.46 .summary-attr-absent {
2.47 border-left: 0.2em solid #070;
2.48 font-size: small;
2.49 @@ -348,7 +364,9 @@
2.50 "Write the summary to the given 'stream'."
2.51
2.52 self.stream = stream
2.53 - self.stream.write(html_header % {"full_name" : self.module.full_name()})
2.54 + self.stream.write(html_header % {
2.55 + "title" : "Module: %s" % self.module.full_name()
2.56 + })
2.57 self._write_classes(self.module)
2.58 self.stream.write(html_footer)
2.59
2.60 @@ -424,6 +442,58 @@
2.61 self.stream.write("</tr>\n")
2.62 self.stream.write("</tbody>\n")
2.63
2.64 +class Interfaces(Writer):
2.65 +
2.66 + "Summarise the interfaces used by reading the object table cache."
2.67 +
2.68 + def __init__(self, program):
2.69 + self.program = program
2.70 +
2.71 + def to_stream(self, stream):
2.72 +
2.73 + "Write the summary to the given 'stream'."
2.74 +
2.75 + self.stream = stream
2.76 + self.stream.write(html_header % {
2.77 + "title" : "Interfaces"
2.78 + })
2.79 + self._write_interfaces()
2.80 + self.stream.write(html_footer)
2.81 +
2.82 + def _write_interfaces(self):
2.83 + objtable = self.program.get_object_table()
2.84 + all_interfaces = objtable.all_cache.items()
2.85 + any_interfaces = objtable.any_cache.items()
2.86 + all_interfaces.sort()
2.87 + any_interfaces.sort()
2.88 +
2.89 + self.stream.write("<table cellspacing='5' cellpadding='5'>\n")
2.90 + self.stream.write("<thead>\n")
2.91 + self.stream.write("<tr>\n")
2.92 + self.stream.write("<th>Complete Interfaces</th>\n")
2.93 + self.stream.write("</tr>\n")
2.94 + self.stream.write("</thead>\n")
2.95 + self._write_interface_type(all_interfaces, "complete")
2.96 + self.stream.write("<thead>\n")
2.97 + self.stream.write("<tr>\n")
2.98 + self.stream.write("<th>Partial Interfaces</th>\n")
2.99 + self.stream.write("</tr>\n")
2.100 + self.stream.write("</thead>\n")
2.101 + self._write_interface_type(any_interfaces, "partial")
2.102 + self.stream.write("</table>\n")
2.103 +
2.104 + def _write_interface_type(self, interfaces, classes=""):
2.105 + self.stream.write("<tbody>\n")
2.106 +
2.107 + for names, objects in interfaces:
2.108 + if names:
2.109 + names.sort()
2.110 + self.stream.write("<tr>\n")
2.111 + self.stream.write("<td class='summary-interface %s'>%s</td>" % (classes, ", ".join(names)))
2.112 + self.stream.write("</tr>\n")
2.113 +
2.114 + self.stream.write("</tbody>\n")
2.115 +
2.116 # Source code classes.
2.117
2.118 class AnnotatedSource(ASTVisitor, Writer):
2.119 @@ -443,7 +513,9 @@
2.120 "Write the annotated code to the given 'stream'."
2.121
2.122 self.stream = stream
2.123 - self.stream.write(html_header % {"full_name" : self.module.full_name()})
2.124 + self.stream.write(html_header % {
2.125 + "title" : "Module: %s" % self.module.full_name()
2.126 + })
2.127 self.dispatch(self.module.astnode)
2.128 self.stream.write(html_footer)
2.129
2.130 @@ -1168,6 +1240,14 @@
2.131 finally:
2.132 stream.close()
2.133
2.134 +def interfaces(program, filename):
2.135 + stream = open(filename, "wb")
2.136 + try:
2.137 + source = Interfaces(program)
2.138 + source.to_stream(stream)
2.139 + finally:
2.140 + stream.close()
2.141 +
2.142 def report(program, directory):
2.143 if not exists(directory):
2.144 os.mkdir(directory)
2.145 @@ -1176,4 +1256,6 @@
2.146 annotate(module, program, join(directory, "%s%sxhtml" % (module.full_name(), extsep)))
2.147 summarise(module, program, join(directory, "%s-summary%sxhtml" % (module.full_name(), extsep)))
2.148
2.149 + interfaces(program, join(directory, "-interfaces%sxhtml" % extsep))
2.150 +
2.151 # vim: tabstop=4 expandtab shiftwidth=4