cria 0.0.0

Cria is a Rust library that is mainly used by AlpacaIR as a representation between Machine Code & AlpacaIR
Documentation
use std::{cell::RefCell, rc::Rc};

use crate::{exprs::{CriaBasicBlock, CriaInstruction}, program::CriaProgram};

pub struct CriaBuilder {
    program: CriaProgram
}

impl CriaBuilder {
    pub fn new() -> Self {
        Self { program: CriaProgram::new() }
    }
    
    pub fn add_block(&mut self, name: &'static str) -> CriaBlockBuilder {
        let block = self.program.add_block(CriaBasicBlock { name, insts: Vec::new() });
        CriaBlockBuilder { block: self.program[block].clone() }
    }
    
    pub fn get_program(self) -> CriaProgram { self.program }
}

pub struct CriaBlockBuilder {
    block: Rc<RefCell<CriaBasicBlock>>
}

impl CriaBlockBuilder {
    pub fn add_instruction(&mut self, inst: CriaInstruction) { self.block.borrow_mut().insts.push(inst); }
}