Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: fba72cc0a217
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a29d7ec6fed2
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Nov 3, 2014

  1. Copy the full SHA
    171d56a View commit details
  2. Copy the full SHA
    a29d7ec View commit details
Showing with 31 additions and 4 deletions.
  1. +16 −4 artiq/transforms/remove_inter_assigns.py
  2. +15 −0 artiq/transforms/tools.py
20 changes: 16 additions & 4 deletions artiq/transforms/remove_inter_assigns.py
Original file line number Diff line number Diff line change
@@ -2,8 +2,7 @@
from copy import copy, deepcopy
from collections import defaultdict

from artiq.transforms.tools import is_ref_transparent

from artiq.transforms.tools import is_ref_transparent, count_all_nodes

class _TargetLister(ast.NodeVisitor):
def __init__(self):
@@ -47,7 +46,7 @@ def visit_Assign(self, node):
node.value = self.visit(node.value)
node.targets = [self.visit(target) for target in node.targets]
rt, depends_on = is_ref_transparent(node.value)
if rt:
if rt and count_all_nodes(node.value) < 100:
for target in node.targets:
if isinstance(target, ast.Name):
if target.id not in depends_on:
@@ -80,7 +79,20 @@ def modified_names_pop(self, prev_modified_names):

def visit_Try(self, node):
prev_modified_names = self.modified_names_push()
self.generic_visit(node)
node.body = [self.visit(stmt) for stmt in node.body]
self.modified_names_pop(prev_modified_names)

prev_modified_names = self.modified_names_push()
prev_replacements = self.replacements
for handler in node.handlers:
self.replacements = copy(prev_replacements)
handler.body = [self.visit(stmt) for stmt in handler.body]
self.replacements = copy(prev_replacements)
node.orelse = [self.visit(stmt) for stmt in node.orelse]
self.modified_names_pop(prev_modified_names)

prev_modified_names = self.modified_names_push()
node.finalbody = [self.visit(stmt) for stmt in node.finalbody]
self.modified_names_pop(prev_modified_names)
return node

15 changes: 15 additions & 0 deletions artiq/transforms/tools.py
Original file line number Diff line number Diff line change
@@ -115,3 +115,18 @@ def is_ref_transparent(expr):
return True, dependencies
else:
return False, None


class _NodeCounter(ast.NodeVisitor):
def __init__(self):
self.count = 0

def generic_visit(self, node):
self.count += 1
ast.NodeVisitor.generic_visit(self, node)


def count_all_nodes(node):
nc = _NodeCounter()
nc.visit(node)
return nc.count