Skip to content

Commit

Permalink
begin working on an MIR type.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lokathor committed Dec 30, 2024
1 parent 3504261 commit 67becf3
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub mod errors;
pub mod file_span;
pub mod file_spanned;
pub mod internal_iterator_mut;
pub mod mir;
pub mod src_file;
pub mod str_id;

Expand Down
90 changes: 90 additions & 0 deletions src/mir/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use super::*;

#[derive(Debug, Clone)]
pub enum Mir {
/// standard looping over a body of "inner" steps
Loop(MirLoop),

/// both break and continue are just "jump"
///
/// * if necessary, you can tell if it was break or continue by the tail of
/// the label it targets.
Jump(MirJump),

/// call to another function
///
/// * No actual abi system currently, so basically all calls are total
/// optimization black holes.
Call(MirCall),

/// go back to the caller
Return(MirReturn),

/// when a condition holds, do this
If(MirIf),

/// `inc reg16`
///
/// * **Flags:** none
Inc16(Reg16),

/// `dec reg16`
///
/// * **Flags:** none
Dec16(Reg16),

/// `inc reg8`
///
/// * **Flags:** `z`
Inc8(Reg8),

/// `dec reg8`
///
/// * **Flags:** `z`
Dec8(Reg8),

/// `a = [reg16]`
AssignAReg16t(Reg16),

/// `[reg16] = a`
AssignReg16tA(Reg16),
}

#[derive(Debug, Clone)]
pub struct MirLoop {
pub steps: Vec<Mir>,
pub canonical_name: StrID,
pub canonical_start: StrID,
pub canonical_end: StrID,
}

#[derive(Debug, Clone)]
pub struct MirJump {
pub condition: Condition,
pub target: StrID,
}

#[derive(Debug, Clone)]
pub struct MirCall {
pub condition: Condition,
pub target: StrID,
pub abi: Abi,
}

#[derive(Debug, Clone)]
pub struct Abi {
// todo: an ABI system
}

#[derive(Debug, Clone)]
pub struct MirReturn {
pub condition: Condition,
}

#[derive(Debug, Clone)]
pub struct MirIf {
pub condition: Condition,
pub steps: Vec<Mir>,
pub canonical_name: StrID,
pub canonical_end: StrID,
}

0 comments on commit 67becf3

Please sign in to comment.