Skip to content

Conversation

@tertsdiepraam
Copy link
Contributor

No description provided.

@tertsdiepraam tertsdiepraam linked an issue Jun 20, 2025 that may be closed by this pull request
Closed
@tertsdiepraam tertsdiepraam marked this pull request as ready for review July 1, 2025 12:39
@tertsdiepraam tertsdiepraam changed the title WIP: Introduce a new compiler pass: MIR Introduce a new compiler pass: MIR Jul 1, 2025
@tertsdiepraam
Copy link
Contributor Author

Alright, this is ready for review. Not saying it's great, but I need a second pair of eyes on it now. All the tests pass at least.

@tertsdiepraam tertsdiepraam requested a review from bal-e July 1, 2025 12:39
@tertsdiepraam
Copy link
Contributor Author

I'll list out some notable changes I made along the way:

  • Variables in the MIR and LIR are now declared separately.
  • && and || are now short-circuiting.
  • IR printing is much improved and cleaner.

Copy link

@bal-e bal-e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazingly well done, @tertsdiepraam! This is a major change and it's going to make it way easier to develop Roto further. I've left some minor notes, but they can all be addressed later.

Comment on lines +134 to +146
/// Integer addition
Add {
to: Var,
left: Operand,
right: Operand,
},

/// Integer subtraction
Sub {
to: Var,
left: Operand,
right: Operand,
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see FAdd or FSub... do these instructions cover floating-points too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the codegen step makes that distinction, div is different because it needs info on signedness for integers. I should refactor this to a binop instruction or something. But that's for later.

src/lir/print.rs Outdated
label_store: printer.label_store,
};

s.push_str(&format!(
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use write!(&mut s, ...)?

@@ -0,0 +1,99 @@
//! Dead code elimination on the MIR
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only eliminates dead branches, not dead instructions within used blocks, right? That'll be a lot harder to do, but also a lot more interesting.

Copy link
Contributor Author

@tertsdiepraam tertsdiepraam Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's true

src/mir/mod.rs Outdated
@@ -0,0 +1,156 @@
//! Mid-level intermediate representation (MIR)
//!
//! This is the first intermediate representation. It is baed on basic blocks
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: 'baed' -> 'based'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based comment

@tertsdiepraam tertsdiepraam merged commit d9fb55a into main Jul 4, 2025
13 checks passed
@tertsdiepraam tertsdiepraam deleted the mir branch July 14, 2025 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MIR

2 participants