Skip to content

Commit

Permalink
Merge pull request #18 from Alignof/hotfix/no_std
Browse files Browse the repository at this point in the history
Fix no_std environment
  • Loading branch information
Alignof authored Aug 16, 2024
2 parents f772ee4 + b8a2945 commit d2ea3e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 79 deletions.
32 changes: 9 additions & 23 deletions src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,29 +199,15 @@ impl Display for Instruction {
InstFormat::CsrCntrFormat => {
write!(f, "{} {}", self.opc, reg2str(self.rd.unwrap()),)
}
InstFormat::Uncategorized => {
write!(
f,
"{}{}{}{}{}",
self.opc,
match self.rd {
Some(rd) => format!(" {}", reg2str(rd)),
None => String::new(),
},
match self.rs1 {
Some(rs1) => format!(" {rs1}"),
None => String::new(),
},
match self.rs2 {
Some(rs2) => format!(" {rs2}"),
None => String::new(),
},
match self.imm {
Some(imm) => format!(" {imm}"),
None => String::new(),
},
)
}
InstFormat::Uncategorized => match self.opc {
OpcodeKind::BaseI(BaseIOpcode::ECALL | BaseIOpcode::EBREAK)
| OpcodeKind::Zifencei(ZifenceiOpcode::FENCE)
| OpcodeKind::C(COpcode::NOP | COpcode::EBREAK)
| OpcodeKind::Priv(
PrivOpcode::MRET | PrivOpcode::SRET | PrivOpcode::WFI | PrivOpcode::SFENCE_VMA,
) => write!(f, "{}", self.opc),
_ => unreachable!(),
},
}
}
}
Expand Down
60 changes: 4 additions & 56 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@
//! // addi t0, t0, -276
//! ```

#![no_std]

mod decode;
mod instruction;

// re-export
pub use crate::decode::{Decode, DecodingError};
pub use crate::instruction::{
a_extension::AOpcode, base_i::BaseIOpcode, c_extension::COpcode, m_extension::MOpcode,
priv_extension::PrivOpcode, zicsr_extension::ZicsrOpcode, zifencei_extension::ZifenceiOpcode,
InstFormat, Instruction, OpcodeKind,
priv_extension::PrivOpcode, zicntr_extension::ZicntrOpcode, zicsr_extension::ZicsrOpcode,
zifencei_extension::ZifenceiOpcode, InstFormat, Instruction, OpcodeKind,
};

/// Target isa.
Expand Down Expand Up @@ -68,60 +70,6 @@ enum Extensions {

#[cfg(test)]
mod tests {
#[test]
fn display_32bit_test() {
use crate::decode::Decode;
use crate::instruction::Instruction;
use crate::Isa;

let instructions: [u32; 8] = [
0b1110_1110_1100_0010_1000_0010_1001_0011,
0b110_1001_1000_0001_1000_0111_1001_0011,
0b1_1100_1110_0100_0010_0110_1010_1111,
0b1111_0101_0000_0000_0000_0000_1111,
0b1000_1111_0100_0010_0111_1010_1111,
0b111_0011,
0b110_0101_1111_0000_0011_0000_1110_1111,
0b110_1001_0111,
];

for inst in &instructions {
let inst: Instruction = match inst.decode(Isa::Rv32) {
Ok(inst) => inst,
Err(e) => panic!("decoding failed due to {e:?}"),
};

println!("{inst}");
}
}

#[test]
fn display_16bit_test() {
use crate::decode::Decode;
use crate::instruction::Instruction;
use crate::Isa;

let instructions: [u16; 8] = [
0b1110_0100_0010_0110,
0b110_1100_0000_0100,
0b1110_0101_0001_0001,
0b1000_0101_0010_0110,
0b1011_0111_1111_0101,
0b11_0000,
0b1000_0000_1000_0010,
0b11_0111_1111_1101,
];

for inst in &instructions {
let inst: Instruction = match inst.decode(Isa::Rv64) {
Ok(inst) => inst,
Err(e) => panic!("decoding failed due to {e:?}"),
};

println!("{inst}");
}
}

#[test]
fn inst_eq_test() {
use crate::decode::Decode;
Expand Down

0 comments on commit d2ea3e9

Please sign in to comment.