From d21e095397ebbe45757cbaf06385878f3670062d Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sat, 17 Dec 2011 20:31:42 +0100 Subject: [PATCH] fhdl: fix series of if/elif/else --- migen/fhdl/structure.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/migen/fhdl/structure.py b/migen/fhdl/structure.py index 9a03b599..92f767a8 100644 --- a/migen/fhdl/structure.py +++ b/migen/fhdl/structure.py @@ -161,13 +161,21 @@ class If: self.f = StatementList() def Else(self, *f): - self.f = StatementList(f) + _insert_else(self, StatementList(f)) return self def Elif(self, cond, *t): - self.f = StatementList([If(cond, *t)]) + _insert_else(self, StatementList([If(cond, *t)])) 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): if isinstance(x, list): return StatementList(x) -- 2.30.2