mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-15 23:18:48 +00:00
Update skeleton
This commit is contained in:
@@ -421,8 +421,12 @@ pub enum IType {
|
||||
Xori,
|
||||
Ori,
|
||||
Andi,
|
||||
Slli,
|
||||
Srli,
|
||||
Slli(Option<DataSize>),
|
||||
Srli(Option<DataSize>),
|
||||
Srai(Option<DataSize>),
|
||||
Slti {
|
||||
is_signed: bool,
|
||||
},
|
||||
}
|
||||
|
||||
impl IType {
|
||||
@@ -457,6 +461,30 @@ impl IType {
|
||||
is_signed,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn slli(dtype: ir::Dtype) -> Self {
|
||||
let data_size =
|
||||
DataSize::try_from(dtype).expect("`data_size` must be derived from `dtype`");
|
||||
assert!(data_size.is_integer());
|
||||
|
||||
Self::Slli(data_size.word())
|
||||
}
|
||||
|
||||
pub fn srli(dtype: ir::Dtype) -> Self {
|
||||
let data_size =
|
||||
DataSize::try_from(dtype).expect("`data_size` must be derived from `dtype`");
|
||||
assert!(data_size.is_integer());
|
||||
|
||||
Self::Srli(data_size.word())
|
||||
}
|
||||
|
||||
pub fn srai(dtype: ir::Dtype) -> Self {
|
||||
let data_size =
|
||||
DataSize::try_from(dtype).expect("`data_size` must be derived from `dtype`");
|
||||
assert!(data_size.is_integer());
|
||||
|
||||
Self::Srai(data_size.word())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
||||
@@ -208,7 +208,7 @@ impl WriteString for RType {
|
||||
Self::Sub(data_size) => format!("sub{}", data_size.write_string()),
|
||||
Self::Sll(data_size) => format!("sll{}", data_size.write_string()),
|
||||
Self::Srl(data_size) => format!("srl{}", data_size.write_string()),
|
||||
Self::Sra(data_size) => format!("srl{}", data_size.write_string()),
|
||||
Self::Sra(data_size) => format!("sra{}", data_size.write_string()),
|
||||
Self::Mul(data_size) => format!("mul{}", data_size.write_string()),
|
||||
Self::Div {
|
||||
data_size,
|
||||
@@ -333,8 +333,10 @@ impl WriteString for IType {
|
||||
Self::Xori => "xori".to_string(),
|
||||
Self::Ori => "ori".to_string(),
|
||||
Self::Andi => "andi".to_string(),
|
||||
Self::Slli => "slli".to_string(),
|
||||
Self::Srli => "srli".to_string(),
|
||||
Self::Slli(data_size) => format!("slli{}", data_size.write_string()),
|
||||
Self::Srli(data_size) => format!("srli{}", data_size.write_string()),
|
||||
Self::Srai(data_size) => format!("srai{}", data_size.write_string()),
|
||||
Self::Slti { is_signed } => format!("slti{}", if *is_signed { "" } else { "u" }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ impl HasDtype for Declaration {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct FunctionSignature {
|
||||
pub ret: Dtype,
|
||||
pub params: Vec<Dtype>,
|
||||
@@ -155,7 +155,7 @@ impl HasDtype for FunctionSignature {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct FunctionDefinition {
|
||||
/// Memory allocations for local variables. The allocation is performed at the beginning of a
|
||||
/// function invocation.
|
||||
@@ -168,7 +168,7 @@ pub struct FunctionDefinition {
|
||||
pub bid_init: BlockId,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct BlockId(pub usize);
|
||||
|
||||
impl fmt::Display for BlockId {
|
||||
@@ -177,14 +177,14 @@ impl fmt::Display for BlockId {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct Block {
|
||||
pub phinodes: Vec<Named<Dtype>>,
|
||||
pub instructions: Vec<Named<Instruction>>,
|
||||
pub exit: BlockExit,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
pub enum Instruction {
|
||||
Nop,
|
||||
@@ -255,7 +255,7 @@ impl Instruction {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum BlockExit {
|
||||
Jump {
|
||||
arg: JumpArg,
|
||||
@@ -300,7 +300,7 @@ impl BlockExit {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct JumpArg {
|
||||
pub bid: BlockId,
|
||||
pub args: Vec<Operand>,
|
||||
@@ -327,7 +327,7 @@ impl fmt::Display for JumpArg {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum Operand {
|
||||
Constant(Constant),
|
||||
Register { rid: RegisterId, dtype: Dtype },
|
||||
@@ -849,7 +849,7 @@ impl HasDtype for Constant {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Named<T> {
|
||||
name: Option<String>,
|
||||
inner: T,
|
||||
|
||||
12
src/tests.rs
12
src/tests.rs
@@ -215,18 +215,6 @@ pub fn test_opt<P1: AsRef<Path>, P2: AsRef<Path>, O: Optimize<ir::TranslationUni
|
||||
}
|
||||
|
||||
pub fn test_asmgen(path: &Path) {
|
||||
// TODO: delete ignore list in the future
|
||||
let ignore_list = vec![
|
||||
"examples/asmgen/struct.ir",
|
||||
"examples/asmgen/struct2.ir",
|
||||
"examples/asmgen/struct3.ir",
|
||||
"examples/asmgen/temp2.ir",
|
||||
];
|
||||
if ignore_list.contains(&path.to_str().expect("`path` must be transformed to `&str`")) {
|
||||
println!("skip test");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the file has .ir extension
|
||||
assert_eq!(path.extension(), Some(std::ffi::OsStr::new("ir")));
|
||||
let unit = ir::Parse::default()
|
||||
|
||||
Reference in New Issue
Block a user