bytecodealliance / cranelift

Cranelift code generator
https://cranelift.readthedocs.io/
2.49k stars 202 forks source link

Show existing entries in Switch #1357

Closed jyn514 closed 4 years ago

jyn514 commented 4 years ago

I would like Switch to have a new method entries() added which returns an immutable list of the existing entries.

This would allow me to check in the codegen module whether a case expression has already been added, instead of having to frontload it in the parser (which for various reasons would be possible but annoying).

fn entries(&self) -> &HashMap<EntryIndex, Ebb> {
    &self.cases
}

Alternatively, Cranelift could impl Deref<Target = HashMap<...>> for Switch. This would also provide more methods at the same time.

Cranelift could also choose to do nothing at all.

jyn514 commented 4 years ago

Added in https://github.com/bytecodealliance/cranelift/pull/1358