pr 02
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use super::instr::Instr;
|
||||
use super::terminator::Terminator;
|
||||
|
||||
/// A basic block in a function's control flow graph.
|
||||
/// Contains a sequence of instructions and ends with a terminator.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Block {
|
||||
pub id: u32,
|
||||
pub instrs: Vec<Instr>,
|
||||
pub terminator: Terminator,
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use super::ids::FunctionId;
|
||||
use super::block::Block;
|
||||
|
||||
/// A function within a module, composed of basic blocks forming a CFG.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Function {
|
||||
pub id: FunctionId,
|
||||
pub name: String,
|
||||
pub blocks: Vec<Block>,
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Unique identifier for a function within a program.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct FunctionId(pub u32);
|
||||
|
||||
/// Unique identifier for a constant value.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct ConstId(pub u32);
|
||||
|
||||
/// Unique identifier for a type.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
#[serde(transparent)]
|
||||
pub struct TypeId(pub u32);
|
||||
@@ -0,0 +1,11 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use super::ids::{ConstId, FunctionId};
|
||||
|
||||
/// Instructions within a basic block.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub enum Instr {
|
||||
/// Placeholder for constant loading.
|
||||
PushConst(ConstId),
|
||||
/// Placeholder for function calls.
|
||||
Call(FunctionId),
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
pub mod ids;
|
||||
pub mod program;
|
||||
pub mod module;
|
||||
pub mod function;
|
||||
pub mod block;
|
||||
pub mod instr;
|
||||
pub mod terminator;
|
||||
|
||||
pub use ids::*;
|
||||
pub use program::*;
|
||||
pub use module::*;
|
||||
pub use function::*;
|
||||
pub use block::*;
|
||||
pub use instr::*;
|
||||
pub use terminator::*;
|
||||
@@ -0,0 +1,9 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use super::function::Function;
|
||||
|
||||
/// A module within a program, containing functions and other declarations.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Module {
|
||||
pub name: String,
|
||||
pub functions: Vec<Function>,
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use super::module::Module;
|
||||
|
||||
/// A complete PBS program, consisting of multiple modules.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct Program {
|
||||
pub modules: Vec<Module>,
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Terminators that end a basic block and handle control flow.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub enum Terminator {
|
||||
/// Returns from the current function.
|
||||
Return,
|
||||
/// Unconditional jump to another block (by index/ID).
|
||||
Jump(u32),
|
||||
}
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
pub mod common;
|
||||
pub mod ir;
|
||||
pub mod ir_core;
|
||||
pub mod backend;
|
||||
pub mod frontends;
|
||||
pub mod compiler;
|
||||
|
||||
Reference in New Issue
Block a user