forked from M-Labs/artiq
1
0
Fork 0

transforms/inline,unroll_loops: fix aliasing problems

This commit is contained in:
Sebastien Bourdeauducq 2014-10-29 17:09:16 +08:00
parent 97ce1d6c2d
commit f012151506
2 changed files with 9 additions and 6 deletions

View File

@ -4,6 +4,7 @@ import inspect
import textwrap
import ast
import builtins
from copy import deepcopy
from artiq.transforms.tools import eval_ast, value_to_ast
from artiq.language import core as core_language
@ -193,7 +194,7 @@ class _ReferenceReplacer(ast.NodeVisitor):
newnode = ast.Name(ival.name, node.ctx)
elif isinstance(ival, ast.AST):
assert(not store)
newnode = ival
newnode = deepcopy(ival)
else:
if store:
raise NotImplementedError(
@ -209,7 +210,7 @@ class _ReferenceReplacer(ast.NodeVisitor):
if isinstance(node, ast.Name):
ival = self.rm.resolve_name(self.obj, self.func_name, node.id, False)
if isinstance(ival, _UserVariable):
return ast.copy_location(ast.Name(ival.name, ast.Load()), node)
return ast.Name(ival.name, ast.Load())
else:
return ival
elif isinstance(node, ast.Attribute):
@ -225,11 +226,12 @@ class _ReferenceReplacer(ast.NodeVisitor):
def visit_Attribute(self, node):
ival = self._resolve_attribute(node)
if isinstance(ival, ast.AST):
return ival
newnode = deepcopy(ival)
elif isinstance(ival, _UserVariable):
return ast.copy_location(ast.Name(ival.name, node.ctx), node)
newnode = ast.Name(ival.name, node.ctx)
else:
return value_to_ast(ival)
newnode = value_to_ast(ival)
return ast.copy_location(newnode, node)
def visit_Call(self, node):
func = self.rm.resolve_constant(self.obj, self.func_name, node.func)

View File

@ -1,4 +1,5 @@
import ast
from copy import deepcopy
from artiq.transforms.tools import eval_ast, value_to_ast
@ -66,7 +67,7 @@ class _LoopUnroller(ast.NodeTransformer):
ast.Assign(targets=[node.target],
value=value_to_ast(i)),
node))
replacement += node.body
replacement += deepcopy(node.body)
if replacement is not None:
return replacement
else: