forked from M-Labs/artiq
transforms/inline,unroll_loops: fix aliasing problems
This commit is contained in:
parent
97ce1d6c2d
commit
f012151506
|
@ -4,6 +4,7 @@ import inspect
|
||||||
import textwrap
|
import textwrap
|
||||||
import ast
|
import ast
|
||||||
import builtins
|
import builtins
|
||||||
|
from copy import deepcopy
|
||||||
|
|
||||||
from artiq.transforms.tools import eval_ast, value_to_ast
|
from artiq.transforms.tools import eval_ast, value_to_ast
|
||||||
from artiq.language import core as core_language
|
from artiq.language import core as core_language
|
||||||
|
@ -193,7 +194,7 @@ class _ReferenceReplacer(ast.NodeVisitor):
|
||||||
newnode = ast.Name(ival.name, node.ctx)
|
newnode = ast.Name(ival.name, node.ctx)
|
||||||
elif isinstance(ival, ast.AST):
|
elif isinstance(ival, ast.AST):
|
||||||
assert(not store)
|
assert(not store)
|
||||||
newnode = ival
|
newnode = deepcopy(ival)
|
||||||
else:
|
else:
|
||||||
if store:
|
if store:
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
|
@ -209,7 +210,7 @@ class _ReferenceReplacer(ast.NodeVisitor):
|
||||||
if isinstance(node, ast.Name):
|
if isinstance(node, ast.Name):
|
||||||
ival = self.rm.resolve_name(self.obj, self.func_name, node.id, False)
|
ival = self.rm.resolve_name(self.obj, self.func_name, node.id, False)
|
||||||
if isinstance(ival, _UserVariable):
|
if isinstance(ival, _UserVariable):
|
||||||
return ast.copy_location(ast.Name(ival.name, ast.Load()), node)
|
return ast.Name(ival.name, ast.Load())
|
||||||
else:
|
else:
|
||||||
return ival
|
return ival
|
||||||
elif isinstance(node, ast.Attribute):
|
elif isinstance(node, ast.Attribute):
|
||||||
|
@ -225,11 +226,12 @@ class _ReferenceReplacer(ast.NodeVisitor):
|
||||||
def visit_Attribute(self, node):
|
def visit_Attribute(self, node):
|
||||||
ival = self._resolve_attribute(node)
|
ival = self._resolve_attribute(node)
|
||||||
if isinstance(ival, ast.AST):
|
if isinstance(ival, ast.AST):
|
||||||
return ival
|
newnode = deepcopy(ival)
|
||||||
elif isinstance(ival, _UserVariable):
|
elif isinstance(ival, _UserVariable):
|
||||||
return ast.copy_location(ast.Name(ival.name, node.ctx), node)
|
newnode = ast.Name(ival.name, node.ctx)
|
||||||
else:
|
else:
|
||||||
return value_to_ast(ival)
|
newnode = value_to_ast(ival)
|
||||||
|
return ast.copy_location(newnode, node)
|
||||||
|
|
||||||
def visit_Call(self, node):
|
def visit_Call(self, node):
|
||||||
func = self.rm.resolve_constant(self.obj, self.func_name, node.func)
|
func = self.rm.resolve_constant(self.obj, self.func_name, node.func)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import ast
|
import ast
|
||||||
|
from copy import deepcopy
|
||||||
|
|
||||||
from artiq.transforms.tools import eval_ast, value_to_ast
|
from artiq.transforms.tools import eval_ast, value_to_ast
|
||||||
|
|
||||||
|
@ -66,7 +67,7 @@ class _LoopUnroller(ast.NodeTransformer):
|
||||||
ast.Assign(targets=[node.target],
|
ast.Assign(targets=[node.target],
|
||||||
value=value_to_ast(i)),
|
value=value_to_ast(i)),
|
||||||
node))
|
node))
|
||||||
replacement += node.body
|
replacement += deepcopy(node.body)
|
||||||
if replacement is not None:
|
if replacement is not None:
|
||||||
return replacement
|
return replacement
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue