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

Ensure that basic blocks end with branch #368

Open
gavrilikhin-d opened this issue Nov 5, 2022 · 3 comments
Open

Ensure that basic blocks end with branch #368

gavrilikhin-d opened this issue Nov 5, 2022 · 3 comments

Comments

@gavrilikhin-d
Copy link
Contributor

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 gavrilikhin-d changed the title Add builder for basic blocks to ensure branching Ensure that basic blocks end with branch Nov 5, 2022
@TheDan64
Copy link
Owner

TheDan64 commented Nov 6, 2022

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

@gavrilikhin-d
Copy link
Contributor Author

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

@TheDan64
Copy link
Owner

TheDan64 commented Nov 6, 2022

Indeed, we can if it makes sense to do so

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

No branches or pull requests

2 participants