hdl.ast: actually implement the // operator.

This commit is contained in:
whitequark 2019-09-28 19:33:24 +00:00
parent 450d7efdf2
commit 1621ceb65a
5 changed files with 29 additions and 5 deletions

View file

@ -87,10 +87,10 @@ class Value(metaclass=ABCMeta):
return Operator("%", [self, other])
def __rmod__(self, other):
return Operator("%", [other, self])
def __div__(self, other):
return Operator("/", [self, other])
def __rdiv__(self, other):
return Operator("/", [other, self])
def __floordiv__(self, other):
return Operator("//", [self, other])
def __rfloordiv__(self, other):
return Operator("//", [other, self])
def __lshift__(self, other):
return Operator("<<", [self, other])
def __rlshift__(self, other):
@ -475,6 +475,9 @@ class Operator(Value):
return width + 1, signed
if self.op == "*":
return a_width + b_width, a_signed or b_signed
if self.op == "//":
# division by -1 can overflow
return a_width + b_signed, a_signed or b_signed
if self.op == "%":
return a_width, a_signed
if self.op in ("<", "<=", "==", "!=", ">", ">="):