From 5cd12ffd28abc66c185f2d1e36f0c8eb7e4b2b44 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 21 Nov 2015 17:23:20 +0800 Subject: [PATCH] compiler.iodelay: fold MUToS and SToMU. --- artiq/compiler/iodelay.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/artiq/compiler/iodelay.py b/artiq/compiler/iodelay.py index 47e04472a..099f0953a 100644 --- a/artiq/compiler/iodelay.py +++ b/artiq/compiler/iodelay.py @@ -106,6 +106,12 @@ class MUToS(Conv): def eval(self, env): return self.operand.eval(env) * self.ref_period + def fold(self, vars=None): + if isinstance(self.operand, Const): + return Const(self.operand.value * self.ref_period) + else: + return super().fold(vars) + class SToMU(Conv): def __str__(self): return "s->mu({})".format(self.operand) @@ -113,6 +119,12 @@ class SToMU(Conv): def eval(self, env): return self.operand.eval(env) / self.ref_period + def fold(self, vars=None): + if isinstance(self.operand, Const): + return Const(self.operand.value / self.ref_period) + else: + return super().fold(vars) + class BinOp(Expr): def __init__(self, lhs, rhs): self.lhs, self.rhs = lhs, rhs