inkwell icon indicating copy to clipboard operation
inkwell copied to clipboard

Ensure that basic blocks end with branch

Open gavrilikhin-d opened this issue 1 year ago • 3 comments

Is your feature request related to a problem? Please describe. Forgetting branch at the end of basic block is a common mistake, that leads to invalid IR.

Describe the solution you'd like Add 2 builder classes for basic block:

  1. Allows to insert any instruction until branch, then switches to second. If first builder is dropped produce a compile error, as IR is invalid.
  2. Doesn't allow to insert any instruction, because we already have branch. No error on drop

Describe possible drawbacks to your solution Must explicitly check for return or branch before adding an unknown instruction

Additional context When I say "branch" I mean branch or return instruction.

gavrilikhin-d avatar Nov 05 '22 09:11 gavrilikhin-d

Not sure that there's a good way to do this in inkwell. I think I always expected this sorta thing to be in a higher level abstraction ontop of inkwell. But it's worth exploring I suppose

TheDan64 avatar Nov 06 '22 03:11 TheDan64

Not sure that there's a good way to do this in inkwell. I think I always expected this sorta thing to be in a higher level abstraction ontop of inkwell. But it's worth exploring I suppose

I just thought that if inkwell adds type safety on top of llvm_sys, it may add "ir-safety" in some trivial cases as well

gavrilikhin-d avatar Nov 06 '22 04:11 gavrilikhin-d

Indeed, we can if it makes sense to do so

TheDan64 avatar Nov 06 '22 04:11 TheDan64