Skip to content

Commit

Permalink
Merge branch 'difftest'
Browse files Browse the repository at this point in the history
  • Loading branch information
Clo91eaf committed Apr 1, 2024
2 parents bd429ec + 9ac7514 commit 6672a79
Show file tree
Hide file tree
Showing 12 changed files with 40,376 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.vscode
/logs
/dependencies/elf
Cargo.lock
136 changes: 97 additions & 39 deletions Cargo.lock

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

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ name = "hemu"
version = "0.1.0"
edition = "2021"

build = "build.rs"

[dependencies]
verilated = { path = "../../Miscellaneous/verilated-rs/verilated" }
verilated-module = { path = "../../Miscellaneous/verilated-rs/verilated-module" }
clap = { version = "4.3.11", features = ["derive"] }
anyhow = "1.0.80"
goblin = "0.8.0"

[build-dependencies]
verilator = { path = "../../Miscellaneous/verilated-rs/verilator", features = ["gen", "module"] }
44 changes: 44 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use std::path::Path;
use std::path::PathBuf;
use std::{env, fs};
use verilator::gen::{Standard, Verilator};
use verilator::module::ModuleGenerator;

macro_rules! t {
($e:expr) => {
match $e {
Ok(e) => e,
Err(e) => panic!("{} failed with {}", stringify!($e), e),
}
};
}

fn main() {
let out_dir = env::var("OUT_DIR").unwrap();
let out_dir = PathBuf::from(out_dir);
let _ = fs::remove_dir_all(&out_dir);
t!(fs::create_dir_all(&out_dir));

// Generate CPP shim from RUST
let mut module = ModuleGenerator::default();
module.generate("src/dut/top.rs");

// Generate CPP from Verilog
let mut verilator = Verilator::default();

let dir = Path::new("myCPU");
let files: Vec<_> = fs::read_dir(dir)
.expect("Directory not found")
.filter_map(|entry| entry.ok().and_then(|e| e.path().to_str().map(|s| String::from(s))))
.collect();

println!("Files: {:?}", files);

verilator.with_coverage(true).with_trace(true);

for file in &files {
verilator.file_with_standard(file, Standard::Verilog2005);
}

verilator.file(out_dir.join("mycpu_top.cpp")).build("mycpu_top");
}
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 6672a79

Please sign in to comment.