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

[Feature] case inside statement and expression #643

Open
taichi-ishitani opened this issue Apr 11, 2024 · 4 comments
Open

[Feature] case inside statement and expression #643

taichi-ishitani opened this issue Apr 11, 2024 · 4 comments
Labels
lang Language design

Comments

@taichi-ishitani
Copy link
Contributor

SystemVerilog has the case inside statement that is enhanced version of casex statetment.
Veryl should support it.

Originally posted by @taichi-ishitani in #641 (comment)

@dalance
Copy link
Collaborator

dalance commented Apr 11, 2024

Emitting case inside instead of case from Veryl's case seems to be good?
Is there cases to require the original case emitting?

From

case x {
    0      : a = 1,
    1..3   : a = 2,
    'h1xx  : a = 3,
    default: a = 4,
}

To

case (x) inside {
    0      : a = 1,
    [1:2]  : a = 2,
    'h1xx  : a = 3,
    default: a = 4,
}

@taichi-ishitani
Copy link
Contributor Author

Like the exmaple below, behavior of case and case inside are different when a case item expression has unknwon value.

case (a)
  b:      c = 1; // select only when a == b
  default c = 0;
endcase

case (a) inside
  b:      c = 1; // select when a == b or b is unknown
  default c = 0;
endcase

So I think these should be different syntax.

@taichi-ishitani
Copy link
Contributor Author

Like the exmaple below, behavior of case and case inside are different when a case item expression has unknwon value.

case (a)
  b:      c = 1; // select only when a == b
  default c = 0;
endcase

case (a) inside
  b:      c = 1; // select when a == b or b is unknown
  default c = 0;
endcase

So I think these should be different syntax.

This behavior may cause difference between simulation and synthesis result.
(refs: https://qiita.com/taichi-ishitani/items/d5bb34273fce8d4b0385#%E8%A4%87%E6%95%B0%E5%80%8B%E3%81%AE%E6%AF%94%E8%BC%83%E5%80%A4%E3%81%A8%E3%81%AE%E6%AF%94%E8%BC%83)

I think it can be solution for this problem to introduce limitation that case item expr should be a constant.

@dalance
Copy link
Collaborator

dalance commented Apr 11, 2024

I think the following case and switch seems to be good.

  • case statement
    • case item should not be expression
    • emits case inside
  • switch statement (refs case statement #11)
    • switch arm can be expression
    • emits case
case a {
    0      : c = 1;
    default: c = 2;
}

switch {
    a == b : c = 1;
    default: c = 2;
}
case (a) inside
    0: c = 1;
    default: c = 2;
endcase

case (1)
    a == b : c = 1;
    default: c = 2;
endcase

@dalance dalance added enhancement New feature or request lang Language design and removed enhancement New feature or request labels Apr 11, 2024
@dalance dalance mentioned this issue Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang Language design
Projects
None yet
Development

No branches or pull requests

2 participants