From e75fdf254ab491cbf0da8b0b497d4f108fa236b6 Mon Sep 17 00:00:00 2001 From: LeoRiether Date: Mon, 10 Jun 2024 21:15:58 -0300 Subject: [PATCH] Make CI pass --- Cargo.lock | 137 +++++++++++++++------------------ Cargo.toml | 2 +- benches/samples/video.s | 2 +- src/main.rs | 2 +- src/parser/data/mod.rs | 13 +++- src/parser/error.rs | 2 +- src/parser/mod.rs | 2 +- src/parser/preprocessor.rs | 14 +--- src/renderer/mod.rs | 5 +- src/simulator/memory/consts.rs | 2 +- src/simulator/mod.rs | 14 +--- tests/riscv_tests.rs | 5 ++ 12 files changed, 88 insertions(+), 112 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 05986a6..ee6b204 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,6 +67,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "000444226fcff248f2bc4c7625be32c63caccfecc2723a2b9f78a7487a49c407" +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + [[package]] name = "anstream" version = "0.6.14" @@ -116,17 +122,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -222,14 +217,30 @@ dependencies = [ ] [[package]] -name = "clap" -version = "2.34.0" +name = "ciborium" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" dependencies = [ - "bitflags 1.3.2", - "textwrap", - "unicode-width", + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" + +[[package]] +name = "ciborium-ll" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" +dependencies = [ + "ciborium-io", + "half", ] [[package]] @@ -414,24 +425,24 @@ dependencies = [ [[package]] name = "criterion" -version = "0.3.6" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b01d6de93b2b6c65e17c634a26653a29d107b3c98c607c765bf38d041531cd8f" +checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" dependencies = [ - "atty", + "anes", "cast", - "clap 2.34.0", + "ciborium", + "clap", "criterion-plot", - "csv", + "is-terminal", "itertools", - "lazy_static", "num-traits", + "once_cell", "oorandom", "plotters", "rayon", "regex", "serde", - "serde_cbor", "serde_derive", "serde_json", "tinytemplate", @@ -440,9 +451,9 @@ dependencies = [ [[package]] name = "criterion-plot" -version = "0.4.5" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2673cc8207403546f45f5fd319a974b1e6983ad1a3ee7e6041650013be041876" +checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" dependencies = [ "cast", "itertools", @@ -474,25 +485,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" [[package]] -name = "csv" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac574ff4d437a7b5ad237ef331c17ccca63c46479e5b5453eb8e10bb99a759fe" -dependencies = [ - "csv-core", - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "csv-core" -version = "0.1.11" +name = "crunchy" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5efa2b3d7902f4b634a20cae3c9c4e6209dc4779feb6863329607560143efa70" -dependencies = [ - "memchr", -] +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "cty" @@ -605,7 +601,7 @@ version = "2.4.0" dependencies = [ "ahash", "byteorder", - "clap 4.5.4", + "clap", "criterion", "glium", "hashbrown 0.13.2", @@ -739,9 +735,13 @@ dependencies = [ [[package]] name = "half" -version = "1.8.3" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b43ede17f21864e81be2fa654110bf1e793774238d86ef8555c37e6519c0403" +checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" +dependencies = [ + "cfg-if 1.0.0", + "crunchy", +] [[package]] name = "hashbrown" @@ -766,12 +766,9 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hermit-abi" -version = "0.1.19" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "ident_case" @@ -801,6 +798,17 @@ dependencies = [ "web-sys", ] +[[package]] +name = "is-terminal" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "is_terminal_polyfill" version = "1.70.0" @@ -1412,16 +1420,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde_cbor" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" -dependencies = [ - "half", - "serde", -] - [[package]] name = "serde_derive" version = "1.0.171" @@ -1538,15 +1536,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - [[package]] name = "thiserror" version = "1.0.40" @@ -1617,12 +1606,6 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" -[[package]] -name = "unicode-width" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68f5e5f3158ecfd4b8ff6fe086db7c8467a2dfdac97fe420f2b7c4aa97af66d6" - [[package]] name = "utf8parse" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index bb06891..f818f30 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/benches/samples/video.s b/benches/samples/video.s index b669684..1c8ffd7 100644 --- a/benches/samples/video.s +++ b/benches/samples/video.s @@ -5,7 +5,7 @@ ####################################################### .data -times: .word 300 +times: .word 30 color: .byte 0xf8 0x07 .align 1 diff --git a/src/main.rs b/src/main.rs index d47e9e8..db9d179 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ -use owo_colors::OwoColorize; use fpgrars::simulator::Simulator; +use owo_colors::OwoColorize; use std::error::Error; use std::thread; diff --git a/src/parser/data/mod.rs b/src/parser/data/mod.rs index 170a2f6..4da0331 100644 --- a/src/parser/data/mod.rs +++ b/src/parser/data/mod.rs @@ -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 + ] + ) } } diff --git a/src/parser/error.rs b/src/parser/error.rs index be2f307..588ca20 100644 --- a/src/parser/error.rs +++ b/src/parser/error.rs @@ -1,6 +1,6 @@ use super::{ data, - token::{self, ManyContexts, context::NormalizePathExt}, + token::{self, context::NormalizePathExt, ManyContexts}, }; use core::fmt; use owo_colors::OwoColorize; diff --git a/src/parser/mod.rs b/src/parser/mod.rs index a2eb427..49bd3ef 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -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(); diff --git a/src/parser/preprocessor.rs b/src/parser/preprocessor.rs index 0827e1f..fbbde31 100644 --- a/src/parser/preprocessor.rs +++ b/src/parser/preprocessor.rs @@ -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; @@ -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, diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 729e7c0..771f598 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -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| { diff --git a/src/simulator/memory/consts.rs b/src/simulator/memory/consts.rs index ba8f4a7..21c8082 100644 --- a/src/simulator/memory/consts.rs +++ b/src/simulator/memory/consts.rs @@ -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; diff --git a/src/simulator/mod.rs b/src/simulator/mod.rs index 532b6ed..21ea577 100644 --- a/src/simulator/mod.rs +++ b/src/simulator/mod.rs @@ -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 @@ -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) -> Self { self.midi_player = midi::MidiPlayer::new(midi_port); self diff --git a/tests/riscv_tests.rs b/tests/riscv_tests.rs index 05ced86..b4ae355 100644 --- a/tests/riscv_tests.rs +++ b/tests/riscv_tests.rs @@ -19,6 +19,11 @@ fn run(path: &impl AsRef) { #[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!");