2019-03-17 18:52:21 +13:00
|
|
|
use crate::ir::IR;
|
2019-03-18 20:20:39 +13:00
|
|
|
use crate::stable::StringIdx;
|
|
|
|
use crate::ty::TyIdx;
|
2019-03-18 18:54:21 +13:00
|
|
|
use std::slice::IterMut;
|
2019-03-17 18:52:21 +13:00
|
|
|
|
2019-03-18 18:54:21 +13:00
|
|
|
#[derive(Debug, Default, PartialEq, Clone)]
|
2019-03-17 18:52:21 +13:00
|
|
|
pub struct Block {
|
2019-03-18 20:20:39 +13:00
|
|
|
arguments: Vec<(StringIdx, TyIdx)>,
|
2019-03-17 18:52:21 +13:00
|
|
|
ir: Vec<IR>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Block {
|
2019-03-18 18:54:21 +13:00
|
|
|
/// Consumes the block and returns the IR data.
|
|
|
|
pub fn ir(self) -> Vec<IR> {
|
|
|
|
self.ir
|
2019-03-17 18:52:21 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_empty(&self) -> bool {
|
|
|
|
self.ir.is_empty()
|
|
|
|
}
|
|
|
|
|
2019-03-18 18:54:21 +13:00
|
|
|
pub fn iter_mut(&mut self) -> IterMut<IR> {
|
|
|
|
self.ir.iter_mut()
|
|
|
|
}
|
|
|
|
|
2019-03-18 20:20:39 +13:00
|
|
|
pub fn new(arguments: Vec<(StringIdx, TyIdx)>) -> Block {
|
|
|
|
Block {
|
|
|
|
arguments,
|
|
|
|
ir: Vec::default(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-18 18:54:21 +13:00
|
|
|
pub fn pop(&mut self) -> Option<IR> {
|
|
|
|
self.ir.pop()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn push(&mut self, ir: IR) {
|
|
|
|
self.ir.push(ir);
|
2019-03-17 18:52:21 +13:00
|
|
|
}
|
2019-03-18 20:20:39 +13:00
|
|
|
|
|
|
|
pub fn set_arguments(&mut self, arguments: Vec<(StringIdx, TyIdx)>) {
|
|
|
|
self.arguments = arguments;
|
|
|
|
}
|
2019-03-17 18:52:21 +13:00
|
|
|
}
|
2019-03-18 11:56:44 +13:00
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
|
|
|
pub struct BlockIdx(usize);
|
|
|
|
|
|
|
|
impl From<usize> for BlockIdx {
|
|
|
|
fn from(i: usize) -> BlockIdx {
|
|
|
|
BlockIdx(i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<BlockIdx> for usize {
|
|
|
|
fn from(i: BlockIdx) -> usize {
|
|
|
|
i.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<&BlockIdx> for usize {
|
|
|
|
fn from(i: &BlockIdx) -> usize {
|
|
|
|
i.0
|
|
|
|
}
|
|
|
|
}
|