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: 6b173d0a9a34
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: a303293e8f8a
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Oct 13, 2014

  1. py2llvm: support BoolOp

    sbourdeauducq committed Oct 13, 2014
    Copy the full SHA
    d26a9d0 View commit details
  2. Copy the full SHA
    8a06f93 View commit details
  3. Copy the full SHA
    a303293 View commit details
Showing with 63 additions and 8 deletions.
  1. +3 −2 artiq/devices/dds_core.py
  2. +51 −0 artiq/py2llvm/ast_body.py
  3. +4 −3 artiq/transforms/inline.py
  4. +5 −3 test/py2llvm.py
5 changes: 3 additions & 2 deletions artiq/devices/dds_core.py
Original file line number Diff line number Diff line change
@@ -50,9 +50,10 @@ def on(self, frequency):
"""
if self.previous_frequency != frequency:
if self.sw.previous_timestamp != time_to_cycles(now()):
merge = self.sw.previous_timestamp == time_to_cycles(now())
if not merge:
self.sw.sync()
if self.sw.previous_value:
if merge or bool(self.sw.previous_value):
# Channel is already on.
# Precise timing of frequency change is required.
fud_time = time_to_cycles(now())
51 changes: 51 additions & 0 deletions artiq/py2llvm/ast_body.py
Original file line number Diff line number Diff line change
@@ -100,6 +100,57 @@ def _visit_expr_BinOp(self, node):
self.visit_expression(node.right),
self.builder)

def _visit_expr_BoolOp(self, node):
if self.builder is not None:
initial_block = self.builder.basic_block
function = initial_block.function
merge_block = function.append_basic_block("b_merge")

test_blocks = []
test_values = []
for i, value in enumerate(node.values):
if self.builder is not None:
test_block = function.append_basic_block("b_{}_test".format(i))
test_blocks.append(test_block)
self.builder.position_at_end(test_block)
test_values.append(self.visit_expression(value))

result = test_values[0].new()
for value in test_values[1:]:
result.merge(value)

if self.builder is not None:
self.builder.position_at_end(initial_block)
result.alloca(self.builder, "b_result")
self.builder.branch(test_blocks[0])

next_test_blocks = test_blocks[1:]
next_test_blocks.append(None)
for block, next_block, value in zip(test_blocks,
next_test_blocks,
test_values):
self.builder.position_at_end(block)
bval = value.o_bool(self.builder)
result.auto_store(self.builder,
value.auto_load(self.builder))
if next_block is None:
self.builder.branch(merge_block)
else:
if isinstance(node.op, ast.Or):
self.builder.cbranch(bval.auto_load(self.builder),
merge_block,
next_block)
elif isinstance(node.op, ast.And):
self.builder.cbranch(bval.auto_load(self.builder),
next_block,
merge_block)
else:
raise NotImplementedError
self.builder.position_at_end(merge_block)

return result


def _visit_expr_Compare(self, node):
comparisons = []
old_comparator = self.visit_expression(node.left)
7 changes: 4 additions & 3 deletions artiq/transforms/inline.py
Original file line number Diff line number Diff line change
@@ -51,8 +51,9 @@ def __init__(self):
# reserved names
for kg in core_language.kernel_globals:
self._use_count[kg] = 1
for name in ("int", "round", "int64", "round64", "float", "array",
"range", "Fraction", "Quantity", "EncodedException"):
for name in ("bool", "int", "round", "int64", "round64", "float",
"Fraction", "array", "Quantity", "EncodedException",
"range"):
self._use_count[name] = 1

# node_or_value can be a AST node, used to inline function parameter values
@@ -126,7 +127,7 @@ def resolve_constant(self, obj, func_name, node):
core_language.delay, core_language.at, core_language.now,
core_language.time_to_cycles, core_language.cycles_to_time,
core_language.syscall,
range, int, float, round,
range, bool, int, float, round,
core_language.int64, core_language.round64, core_language.array,
Fraction, units.Quantity, core_language.EncodedException
)
8 changes: 5 additions & 3 deletions test/py2llvm.py
Original file line number Diff line number Diff line change
@@ -15,10 +15,10 @@ def test_base_types(choice):
a = 2 # promoted later to int64
b = a + 1 # initially int32, becomes int64 after a is promoted
c = b//2 # initially int32, becomes int64 after b is promoted
d = 4 # stays int32
d = 4 and 5 # stays int32
x = int64(7)
a += x # promotes a to int64
foo = True | True
foo = True | True or False
bar = None
myf = 4.5
myf2 = myf + x
@@ -181,8 +181,10 @@ def array_test():
acc = 0
for i in range(5):
for j in range(5):
if i + j == 2:
if i + j == 2 or i + j == 1:
continue
if i and j and a[i][j]:
acc += 1
acc += a[i][j]
return acc