2014-11-03 18:44:30 +08:00
|
|
|
import unittest
|
|
|
|
import ast
|
|
|
|
|
2015-04-19 11:40:49 +08:00
|
|
|
from artiq import ns
|
2014-11-03 18:44:30 +08:00
|
|
|
from artiq.coredevice import comm_dummy, core
|
|
|
|
from artiq.transforms.unparse import unparse
|
|
|
|
|
|
|
|
|
|
|
|
optimize_in = """
|
|
|
|
|
|
|
|
def run():
|
2015-06-26 22:20:13 +08:00
|
|
|
dds_sysclk = Fraction(1000000000, 1)
|
2015-07-02 04:22:53 +08:00
|
|
|
n = seconds_to_mu((1.2345 * Fraction(1, 1000000000)))
|
2014-11-03 18:44:30 +08:00
|
|
|
with sequential:
|
2015-06-26 22:20:13 +08:00
|
|
|
frequency = 345 * Fraction(1000000, 1)
|
2014-11-03 18:44:30 +08:00
|
|
|
frequency_to_ftw_return = int((((2 ** 32) * frequency) / dds_sysclk))
|
|
|
|
ftw = frequency_to_ftw_return
|
|
|
|
with sequential:
|
|
|
|
ftw2 = ftw
|
|
|
|
ftw_to_frequency_return = ((ftw2 * dds_sysclk) / (2 ** 32))
|
|
|
|
f = ftw_to_frequency_return
|
2015-07-02 04:22:53 +08:00
|
|
|
phi = ((1000 * mu_to_seconds(n)) * f)
|
2014-11-03 18:44:30 +08:00
|
|
|
do_something(int(phi))
|
|
|
|
"""
|
|
|
|
|
|
|
|
optimize_out = """
|
|
|
|
|
|
|
|
def run():
|
2015-05-12 23:06:33 +08:00
|
|
|
now = syscall('now_init')
|
|
|
|
try:
|
|
|
|
do_something(344)
|
|
|
|
finally:
|
|
|
|
syscall('now_save', now)
|
2014-11-03 18:44:30 +08:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
class OptimizeCase(unittest.TestCase):
|
|
|
|
def test_optimize(self):
|
2015-07-14 04:08:20 +08:00
|
|
|
dmgr = dict()
|
|
|
|
dmgr["comm"] = comm_dummy.Comm(dmgr)
|
|
|
|
coredev = core.Core(dmgr, ref_period=1*ns)
|
2014-11-03 18:44:30 +08:00
|
|
|
func_def = ast.parse(optimize_in).body[0]
|
|
|
|
coredev.transform_stack(func_def, dict(), dict())
|
|
|
|
self.assertEqual(unparse(func_def), optimize_out)
|