add support for - input

This commit is contained in:
nora 2023-05-28 18:59:27 +02:00
parent d0be270de2
commit 2b39ddebb2
8 changed files with 50 additions and 27 deletions

View file

@ -4,7 +4,7 @@ use std::{
};
use parser::{
ast::{self, IntSign, IntTyKind, IntTy},
ast::{self, IntSign, IntTy, IntTyKind},
Symbol,
};
use rustc_hash::{FxHashMap, FxHashSet};

View file

@ -37,12 +37,11 @@ mod pretty;
mod validate;
mod visit;
#[doc(hidden)]
pub use custom::help as custom_help;
use std::fmt::{Debug, Display};
pub use custom::define_ir_func;
#[doc(hidden)]
pub use custom::help as custom_help;
use either::Either;
use parser::{ast, Span, Symbol};
pub use pretty::{func_to_string, ir_to_string};

View file

@ -1,5 +1,5 @@
pub mod help {
use crate::ir::{Operand, Register, ConstValue};
use crate::ir::{ConstValue, Operand, Register};
pub trait AsOperand {
fn as_operand(self) -> Operand;

View file

@ -1,8 +1,7 @@
use rustc_hash::FxHashSet;
use crate::ir::visit::Visitor;
use super::{BbIdx, Branch, Func, Location, Operand};
use crate::ir::visit::Visitor;
pub fn traverse_postorder<'a>(func: &'a Func<'_>) -> Vec<BbIdx> {
// the final traversial, backwards.

View file

@ -65,7 +65,11 @@ impl<W: Write> PrettyPrinter<W> {
for stmt in &bb.statements {
match stmt.kind {
StatementKind::Alloca { result: reg, size, align } => {
StatementKind::Alloca {
result: reg,
size,
align,
} => {
writeln!(
self.out,
" {} = alloca, size={}, align={}",

View file

@ -38,7 +38,7 @@ pub trait Visitor {
self.visit_reg(result);
self.visit_operand(size);
self.visit_operand(align);
},
}
StatementKind::Store {
ptr,
value,
@ -49,7 +49,7 @@ pub trait Visitor {
self.visit_operand(value);
self.visit_operand(size);
self.visit_operand(align);
},
}
StatementKind::Load {
result,
ptr,
@ -60,7 +60,7 @@ pub trait Visitor {
self.visit_operand(ptr);
self.visit_operand(size);
self.visit_operand(align);
},
}
StatementKind::BinOp {
kind: _,
lhs,
@ -70,11 +70,15 @@ pub trait Visitor {
self.visit_reg(result);
self.visit_operand(lhs);
self.visit_operand(rhs);
},
StatementKind::UnaryOperation { rhs, kind: _, result } => {
}
StatementKind::UnaryOperation {
rhs,
kind: _,
result,
} => {
self.visit_reg(result);
self.visit_operand(rhs);
},
}
StatementKind::PtrOffset {
result,
ptr,
@ -83,14 +87,18 @@ pub trait Visitor {
self.visit_reg(result);
self.visit_operand(ptr);
self.visit_operand(amount);
},
StatementKind::Call { result, func, ref args } => {
}
StatementKind::Call {
result,
func,
ref args,
} => {
self.visit_reg(result);
self.visit_operand(func);
for &arg in args {
self.visit_operand(arg);
}
},
}
}
}