forked from M-Labs/artiq
1
0
Fork 0

compiler.iodelay: fold MUToS and SToMU.

This commit is contained in:
whitequark 2015-11-21 17:23:20 +08:00
parent 82b470891f
commit 5cd12ffd28
1 changed files with 12 additions and 0 deletions

View File

@ -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