1use std::collections::VecDeque;
2
3use super::Block;
4
5pub struct IRBuilder<'a> {
7 pub(crate) blocks: VecDeque<&'a mut Block>,
8 pub(crate) curr: usize,
10}
11
12impl<'a> IRBuilder<'a> {
13 pub fn new() -> Self {
15 Self {
16 blocks: VecDeque::new(),
17 curr: 0,
18 }
19 }
20
21 pub fn positionAtEnd(&mut self, block: &'a mut Block) {
23 self.blocks.push_back(block);
24 self.curr = self.blocks.len() - 1; }
26
27 pub fn positionAtStart(&mut self, block: &'a mut Block) {
29 self.blocks.push_front(block);
30 self.curr = 0; }
32
33 pub fn getLastBlock(&mut self) -> Option<&Block> {
35 Some(self.blocks.back()?.to_owned().to_owned())
36 }
37}
38
39pub fn IRBuilder<'a>() -> IRBuilder<'a> {
41 IRBuilder::new()
42}