feat(backend): Add backend
This commit is contained in:
+32
-1
@@ -43,6 +43,15 @@ pub enum IRType {
|
||||
I1,
|
||||
Void,
|
||||
}
|
||||
impl IRType {
|
||||
pub fn size_in_bytes(&self) -> usize {
|
||||
match self {
|
||||
IRType::I32 => 4,
|
||||
IRType::I1 => 1,
|
||||
IRType::Void => 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Display for IRType {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
@@ -72,7 +81,7 @@ impl Display for MoveRValue {
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
|
||||
pub enum VariableType {
|
||||
Global,
|
||||
ParamTemp,
|
||||
@@ -86,6 +95,28 @@ pub struct Variable {
|
||||
pub var_type: VariableType,
|
||||
pub data_type: IRType,
|
||||
}
|
||||
impl PartialEq for Variable {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.index == other.index && self.var_type == other.var_type
|
||||
}
|
||||
}
|
||||
impl Eq for Variable {}
|
||||
impl PartialOrd for Variable {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
Some(match self.index.cmp(&other.index) {
|
||||
std::cmp::Ordering::Equal => self.var_type.cmp(&other.var_type),
|
||||
ord => ord,
|
||||
})
|
||||
}
|
||||
}
|
||||
impl Ord for Variable {
|
||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||
match self.index.cmp(&other.index) {
|
||||
std::cmp::Ordering::Equal => self.var_type.cmp(&other.var_type),
|
||||
ord => ord,
|
||||
}
|
||||
}
|
||||
}
|
||||
impl Display for Variable {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let prefix = match self.var_type {
|
||||
|
||||
Reference in New Issue
Block a user