Skip to content

Commit

Permalink
Finish 2-pass (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-schott authored and sjudson committed Feb 5, 2025
1 parent d5e8077 commit e67ac71
Show file tree
Hide file tree
Showing 22 changed files with 646 additions and 354 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ jobs:
run: rustup target add riscv32i-unknown-none-elf

- run: cargo test -r --all --all-features
timeout-minutes: 30
2 changes: 2 additions & 0 deletions common/src/constants/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub const MEMORY_TOP: u32 = 0x80400000;
pub const WORD_SIZE: usize = 4;
2 changes: 2 additions & 0 deletions common/src/constants/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod constants;
pub use constants::*;
1 change: 1 addition & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod constants;
pub mod cpu;
pub mod error;
pub mod memory;
Expand Down
34 changes: 34 additions & 0 deletions common/src/memory/alignment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// use crate::constants::WORD_SIZE;

#[macro_export]
macro_rules! word_align {
($len:expr) => {
($len + $crate::constants::WORD_SIZE - 1) & !($crate::constants::WORD_SIZE - 1)
};
}

#[macro_export]
macro_rules! bytes_to_words {
($bytes:expr) => {{
// Convert the associated data to word representation.
let mut bytes = $bytes.to_vec();
let padded_len = $crate::word_align!(bytes.len());
bytes.resize(padded_len, 0);
// Convert to u32 chunks.
bytes
.chunks($crate::constants::WORD_SIZE)
.map(|chunk| u32::from_le_bytes([chunk[0], chunk[1], chunk[2], chunk[3]]))
.collect::<Vec<u32>>()
}};
}

#[macro_export]
macro_rules! words_to_bytes {
($words:expr) => {{
let mut bytes: Vec<u8> = Vec::with_capacity($words.len() * $crate::constants::WORD_SIZE);
for word in $words {
bytes.extend_from_slice(&word.to_le_bytes());
}
bytes
}};
}
2 changes: 2 additions & 0 deletions common/src/memory/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
pub mod alignment;
pub use alignment::*;
pub mod traits;
pub use traits::*;
Loading

0 comments on commit e67ac71

Please sign in to comment.