mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
fhdl: fix series of if/elif/else
This commit is contained in:
parent
1a845d4553
commit
d21e095397
1 changed files with 10 additions and 2 deletions
|
@ -161,13 +161,21 @@ class If:
|
||||||
self.f = StatementList()
|
self.f = StatementList()
|
||||||
|
|
||||||
def Else(self, *f):
|
def Else(self, *f):
|
||||||
self.f = StatementList(f)
|
_insert_else(self, StatementList(f))
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def Elif(self, cond, *t):
|
def Elif(self, cond, *t):
|
||||||
self.f = StatementList([If(cond, *t)])
|
_insert_else(self, StatementList([If(cond, *t)]))
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def _insert_else(obj, clause):
|
||||||
|
o = obj
|
||||||
|
while o.f.l:
|
||||||
|
assert(len(o.f.l) == 1)
|
||||||
|
assert(isinstance(o.f.l[0], If))
|
||||||
|
o = o.f.l[0]
|
||||||
|
o.f = clause
|
||||||
|
|
||||||
def _sl(x):
|
def _sl(x):
|
||||||
if isinstance(x, list):
|
if isinstance(x, list):
|
||||||
return StatementList(x)
|
return StatementList(x)
|
||||||
|
|
Loading…
Reference in a new issue