Skip to content

Commit

Permalink
x86-64: do not modify Constant objects passed as instruction operands
Browse files Browse the repository at this point in the history
  • Loading branch information
Maratyszcza committed Oct 19, 2015
1 parent 8ef5818 commit 9d5c541
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions peachpy/x86_64/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def __init__(self, name, arguments, result_type=None,

# This set is only used to ensure that all labels references in branches are defined
self._label_names = set()
# Map from id of Name objects to their copies.
# This ensures that Name objects without name can be compared for equality using id
self._names_memo = dict()
self._scope = peachpy.name.Namespace(None)

self._local_variables_count = 0
Expand Down
5 changes: 5 additions & 0 deletions peachpy/x86_64/operand.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ def check_operand(operand):
raise ValueError("Memory operands must be represented by a list with only one element")
return MemoryOperand(operand[0])
elif isinstance(operand, Constant):
from copy import copy, deepcopy
operand = copy(operand)
import peachpy.x86_64.function
if peachpy.x86_64.function.active_function:
operand.name = deepcopy(operand.name, peachpy.x86_64.function.active_function._names_memo)
return MemoryOperand(operand)
elif isinstance(operand, LocalVariable):
return MemoryOperand(operand)
Expand Down

0 comments on commit 9d5c541

Please sign in to comment.