Exemple #1
0
def main_module(path, optimizers):

    mod = loader.ModuleLoader(path).load()

    for optimizer in optimizers:
        optimizer(mod)

    print SourceCodeRenderer.render(mod.node)
Exemple #2
0
def main_package(path, optimizers):

    pkg = loader.PackageLoader(path).load()

    for mod in pkg.modules():
        for optimizer in optimizers:
            optimizer(mod, package=pkg)

        print SourceCodeRenderer.render(mod.node)
 def _make_expected_result(self, decision, *conditions_hit):
     node_source = SourceCodeRenderer.render(self.node)
     result_lines = []
     result_lines.append("Decision -> %s:%s < %s >" % (self.modulename,
                                                       self.label,
                                                       node_source)
                         )
     result_lines.append("")
     for condition in ("T", "F"):
         tag = 'X' if condition in conditions_hit else ''
         result_lines.append("%s ==> %s" % (condition, tag))
     return "\n".join(result_lines)
Exemple #4
0
 def __init__(self, modulename, label, node, pragmas):
     self.modulename = modulename
     self.label = label
     self.node = deepcopy(node)
     self.pragmas = pragmas
     self.lineno = node.lineno
     self.source = SourceCodeRenderer.render(node)
     self.conditions = {True: set(), False: set()}
     for pragma in pragmas:
         if hasattr(pragma, 'selector'):
             pragma_label = '%s.%s' % (node.lineno, pragma.selector)
             if label == pragma_label:
                 pragma.apply(self)
Exemple #5
0
 def _get_code(self, fullname):
     """ Get the instrumented code for a module
         
         Given a dotted module name, return a tuple that looks like
         (<is the module a package>, <module's code object instrumented>)
     """
     # packages are loaded from __init__.py files
     ispkg = self.fullpath.endswith('__init__.py')
     code_str = self._get_source(self.fullpath)
     visitor = self.visitor_factory.create(fullname, code_str)
     code_tree = ast.parse(code_str)
     new_code_tree = visitor.visit(code_tree)
     log.debug(SourceCodeRenderer.render(new_code_tree))
     code = compile(new_code_tree, self.fullpath, 'exec')
     return (ispkg, code)
Exemple #6
0
 def __init__(self, modulename, label, node, pragmas):
     self.modulename = modulename
     self.label = label
     self.node = deepcopy(node)
     self.pragmas = pragmas
     self.source = SourceCodeRenderer.render(node)
     self.pins = len(node.values)
     self.conditions =\
         dict((i, set()) for i in range(self.pins + 1))
     self.literals = self._gather_literals(node)
     self._set_unreachable_conditions()
     for pragma in pragmas:
         if hasattr(pragma, 'selector'):
             pragma_label = '%s.%s' % (node.lineno, pragma.selector)
             if label == pragma_label:
                 pragma.apply(self)
Exemple #7
0
 def _load_and_compile_module(self, module_func):
     module, source = load_module(module_func)
     from instrumental.pragmas import PragmaFinder
     pragmas = PragmaFinder().find_pragmas(source)
     from instrumental.metadata import MetadataGatheringVisitor
     config = DummyConfig()
     self.recorder.add_metadata(
         MetadataGatheringVisitor.analyze(config, module_func.__name__,
                                          source, pragmas))
     # self.recorder.add_source(module_func.__name__, source)
     transformer = CoverageAnnotator(config, module_func.__name__,
                                     self.recorder)
     inst_module = transformer.visit(module)
     sys.stdout.write(renderer.render(inst_module) + "\n")
     code = compile(inst_module, '<string>', 'exec')
     return code
Exemple #8
0
 def __call__(self, node):
     """Compile the AST into source code."""
     return SourceCodeRenderer.render(node)
Exemple #9
0
 def __call__(self, node):
     """Compile the AST into source code."""
     return SourceCodeRenderer.render(node)