Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do multiple If statements work? #2

Closed
mithro opened this issue Dec 14, 2018 · 3 comments
Closed

How do multiple If statements work? #2

mithro opened this issue Dec 14, 2018 · 3 comments
Labels

Comments

@mithro
Copy link

mithro commented Dec 14, 2018

I'm interested in how the If statement actually works. The m module seems to track the current "state" in some way?

        with m.If(self.a):
            m.d.comb += self.o.eq(self.sub.o)
        with m.If(self.b):
            m.d.comb += self.o.eq(self.add.o)
        with m.Else():
            m.d.comb += self.o.eq(self.rnd.o)
        return m.lower(platform)

How does it actually know that the m.Else() applies to the first m.If(?

@whitequark
Copy link
Contributor

whitequark commented Dec 14, 2018

How does it actually know that the m.Else() applies to the first m.If(?

It doesn't, just like it wouldn't in the following Python code:

if a:
  o = sub.o
if b:
  o = add.o
else:
  o = rnd.o

The m.Else() applies to the second m.If().

@mithro
Copy link
Author

mithro commented Dec 14, 2018

I actually meant the second m.If(). Is m tracking what the current if is?

@whitequark
Copy link
Contributor

Ah. Yes. It is tracking the current nesting level and pending statement. Effectively, there is a small FSM inside fhdl.dsl implementing a parser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants