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

@chiselName on a Module with a nested ChiselEnum results an error #1100

Closed
kammoh opened this issue May 22, 2019 · 3 comments · Fixed by #1104
Closed

@chiselName on a Module with a nested ChiselEnum results an error #1100

kammoh opened this issue May 22, 2019 · 3 comments · Fixed by #1104

Comments

@kammoh
Copy link
Contributor

kammoh commented May 22, 2019

Type of issue: bug report

Impact: unknown

Development Phase: request

Other information

Applying @chiselName annotation on a Module with a ChiselEnum object results in compilation error.

If the current behavior is a bug, please provide the steps to reproduce the problem:

@chiselName
class MyModule extends MultiIOModule {
  object State extends ChiselEnum {
    val x, y, z = Value
  }
}

Scala compile error:
Error: Value cannot be called without assigning to an enum val x, y, z = Value
What is the current behavior?

What is the expected behavior?

Please tell us about your environment:

  • version: 3.0-SNAPSHOT
  • OS: macOS

What is the use case for changing the behavior?

@edwardcwang edwardcwang changed the title @chiselName on a Module with a ChiselEnum results an error @chiselName on a Module with a nested ChiselEnum results an error May 22, 2019
@hngenc
Copy link
Contributor

hngenc commented May 23, 2019

It seems the problem is that @chiselName will change val x = Value to val x = context.name(Value, x), at least judging by this line: https://github.com/freechipsproject/chisel3/blob/820e2688f0cb966d4528ff074fdbdc623ed8f940/coreMacros/src/main/scala/chisel3/internal/sourceinfo/NamingAnnotations.scala#L156

Value is a macro which tries to figure out the name of the variable that it is being assigned to, so it is searching for assignments like val x = Value, and will fail if it cannot find them. I am busy this week, but I can fix this over the weekend or early next week.

In the meantime, I think you could work around this by just rewriting your code to:

object State extends ChiselEnum {
  val x, y, z = Value
}

@chiselName
class MyModule extends MultiIOModule {
  val state = RegInit(State.x)
  // ...
}

@ducky64
Copy link
Contributor

ducky64 commented May 23, 2019

That sounds like a reasonable root-cause - the chiselName macro really mostly is a simple rewrite that adds a context.name call to anything of the form val name = expr. Blacklisting Value would be one possible solution, though it's not a selective / general one. Thoughts? Perhaps if type information is available to macros, we could whitelist only expressions that type to Data?

@hngenc
Copy link
Contributor

hngenc commented May 24, 2019

My plan was to change the Value macro so that it also recognizes statements of the form val x = foo(x, ...). Macros can be tricky, but I think that would be possible.

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

Successfully merging a pull request may close this issue.

3 participants