Skip to content

Commit

Permalink
Make CI pass
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoRiether committed Jun 11, 2024
1 parent fae65f1 commit e75fdf2
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 112 deletions.
137 changes: 60 additions & 77 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ version = "4.5"
features = ["suggestions", "color", "wrap_help", "cargo", "derive"]

[dev-dependencies]
criterion = { version = "0.3", features = ["html_reports"] }
criterion = { version = "0.5", features = ["html_reports"] }

[[bench]]
name = "simulator"
Expand Down
2 changes: 1 addition & 1 deletion benches/samples/video.s
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#######################################################

.data
times: .word 300
times: .word 30
color: .byte 0xf8 0x07

.align 1
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use owo_colors::OwoColorize;
use fpgrars::simulator::Simulator;
use owo_colors::OwoColorize;
use std::error::Error;
use std::thread;

Expand Down
13 changes: 12 additions & 1 deletion src/parser/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,17 @@ mod tests {
let Parsed { code, .. } = parse_tokens(tokens, DATA_SIZE).unwrap();

use crate::instruction::Instruction::{Ecall, Li};
assert_eq!(&code, &[Li(0, 4), Li(0, 10), Li(0, 16), Li(0, 16), Li(17, 10), Li(10, 0), Ecall])
assert_eq!(
&code,
&[
Li(0, 4),
Li(0, 10),
Li(0, 16),
Li(0, 16),
Li(17, 10),
Li(10, 0),
Ecall
]
)
}
}
2 changes: 1 addition & 1 deletion src/parser/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::{
data,
token::{self, ManyContexts, context::NormalizePathExt},
token::{self, context::NormalizePathExt, ManyContexts},
};
use core::fmt;
use owo_colors::OwoColorize;
Expand Down
2 changes: 1 addition & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl ParserContext {
/// Parses a RISC-V file into a `code` and `data` segments.
/// The `data_segment_size` parameter is the final size of the data segment, in bytes.
/// ```
/// parser::parse("riscv.s", DATA_SIZE)?
/// fpgrars::parser::parse("riscv.s", 0x1000).is_ok();
/// ```
pub fn parse(entry_file: &str, data_segment_size: usize) -> ParseResult {
let tokens = Lexer::new(entry_file)?.preprocess().peekable();
Expand Down
14 changes: 3 additions & 11 deletions src/parser/preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ lazy_static! {

/// Defines the `preprocess` methods for a lexer
/// ```
/// let tokens = Lexer::new("riscv.s").preprocess();
/// use fpgrars::parser::lexer::Lexer;
/// use crate::fpgrars::parser::Preprocess;
/// let tokens = Lexer::from_content("riscv.s".into(), "file.s".into()).preprocess();
/// ```
pub trait Preprocess {
fn preprocess(self) -> Preprocessor;
Expand Down Expand Up @@ -249,16 +251,6 @@ impl Preprocessor {
}

/// Reads tokens until a matching token is found.
///
/// For example:
/// ```
/// use token::Data;
/// let preprocessor = Lexer::from("%arg1, %arg2)".into(), "test.s");
/// let res = preprocessor.consume_until(Data::Char(')'))
///
/// let res: Vec<_> = res.unwrap().into_iter().map(|t| t.data).collect();
/// assert_eq!(res, &[Data::MacroArg("arg1".into()), Data::MacroArg("arg2".into())]);
/// ```
fn consume_until(
&mut self,
data: token::Data,
Expand Down
5 changes: 1 addition & 4 deletions src/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,7 @@ pub fn init(state: State) {

let color_provider = move |mmio: &[u8], y: usize, x: usize| {
let bytes_per_pixel = 4;
let (x, y) = (
x / pixel_scale,
height - 1 - y / pixel_scale,
);
let (x, y) = (x / pixel_scale, height - 1 - y / pixel_scale);
let index = (y * width + x) * bytes_per_pixel;

let get = |i| {
Expand Down
2 changes: 1 addition & 1 deletion src/simulator/memory/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub const MMIO_START: usize = 0xff00_0000;

pub const HEAP_START: usize = 0x1004_0000;

pub use crate::renderer::{FRAME_0, FRAME_1, KDMMIO_CONTROL, KDMMIO_DATA, FRAME_SIZE};
pub use crate::renderer::{FRAME_0, FRAME_1, FRAME_SIZE, KDMMIO_CONTROL, KDMMIO_DATA};
pub const VIDEO_START: usize = MMIO_START + FRAME_0;
pub const VIDEO_END: usize = MMIO_START + FRAME_1 + FRAME_SIZE;

Expand Down
14 changes: 1 addition & 13 deletions src/simulator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ mod midi;
mod util;

use crate::config::Config;
use crate::instruction::Instruction;
use crate::renderer::{FRAME_0, FRAME_1, FRAME_SIZE};
use crate::parser;
use crate::renderer::{FRAME_0, FRAME_1, FRAME_SIZE};
use into_register::*;
use memory::*;
use owo_colors::OwoColorize;
use std::hint::black_box;
use std::{mem, time};

/// Returned by the [ecall](struct.Simulator.html#method.ecall) procedure
Expand Down Expand Up @@ -98,16 +96,6 @@ impl Simulator {
}
}

// BUG: this shouldn't be here
pub fn nothing(&mut self) -> Result<(), parser::error::Error> {
self.code = executor::compile_all(black_box(&[
Instruction::Li(17, 10), // li a7 10
Instruction::Li(10, 0), // li a0 0
Instruction::Ecall,
]));
Ok(())
}

pub fn with_midi_port(mut self, midi_port: Option<usize>) -> Self {
self.midi_player = midi::MidiPlayer::new(midi_port);
self
Expand Down
5 changes: 5 additions & 0 deletions tests/riscv_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ fn run(path: &impl AsRef<Path>) {

#[test]
fn test_riscv() {
let fast = std::env::var("FAST");
if matches!(fast.as_deref(), Ok("1") | Ok("true") | Ok("t")) {
return;
}

let dir = Path::new("tests/riscv-tests");
assert!(dir.is_dir(), "riscv-tests directory not found!");

Expand Down

0 comments on commit e75fdf2

Please sign in to comment.