Skip to content

"Default Block" / more than one match per line for switch statement #526

Open
@jchang0

Description

@jchang0

Two separate feature requests

  1. Have a default block available for switch statements (where if none of the is block match, it will execute the default block)
    e.g.
switch(value) {
  is(1) {
  // do something
  }
  is(2) {
  // do something
  }
  default {
    error := true.B
    assert(0)
  }
}
  1. Allow more than one matched value for each is block match.
    e.g. (the first two cases are more useful, the subsequent examples have potential usages, but I haven't encountered it yet)
switch(value) {
  is(1) {
  // do something
  }
  is(2, 4) {
  // do something
  }
  // we might need to figure out what it means if the user duplicate a value in this case (perhaps 
  execute both is blocks?)  Or just error out and disallow it if it overlaps.
  is(4, 6) {
  }
  // or maybe even more fancy, but can no longer check for non-overlapping matches if that's a requirement
  is(>5) {
  }
  // Or even generalizing it by allowing a predicate function (Maybe this and the previous is too much, since if it gets that fancy, should probably just use when statement, and feature not in verilog anyway)
  is( (v: Int):Bool => { v<7 }) {
  }
}

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions