Skip to content

Commit

Permalink
Add filelist test
Browse files Browse the repository at this point in the history
  • Loading branch information
dalance committed Nov 11, 2024
1 parent 3e29476 commit e222f34
Show file tree
Hide file tree
Showing 13 changed files with 367 additions and 234 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ veryl_testcase.*
/book/po/messages.pot
/book/po/*~
/testcases/map/dependencies/
/testcases/filelist/dependencies/
/testcases/filelist/src/*.sv
/testcases/filelist/*.f
/testcases/filelist/Veryl.lock
/crates/metadata/std/
/crates/std/veryl/*.f
/crates/std/veryl/target/
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ veryl-formatter = {version = "0.13.2", path = "../formatter"}
veryl-metadata = {version = "0.13.2", path = "../metadata"}
veryl-parser = {version = "0.13.2", path = "../parser"}
veryl-path = {version = "0.13.2", path = "../path"}
veryl = {version = "0.13.2", path = "../veryl"}

[dev-dependencies]
criterion = "0.5.1"
Expand Down
87 changes: 87 additions & 0 deletions crates/tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,90 @@ mod path {
);
}
}

#[cfg(test)]
mod filelist {
use std::fs;
use std::path::PathBuf;
use veryl_analyzer::Analyzer;
use veryl_metadata::Metadata;
use veryl_parser::Parser;

fn check_list(paths: &[String], expected: &[&str]) {
let paths: Vec<_> = paths.iter().map(|x| x.as_str()).collect();
for x in &paths {
assert!(expected.contains(&x));
}
for x in expected {
assert!(paths.contains(x));
}
}

fn check_order(paths: &[String], path0: &str, path1: &str) {
let path0 = paths
.iter()
.enumerate()
.find_map(|(i, x)| if x == path0 { Some(i) } else { None });
let path1 = paths
.iter()
.enumerate()
.find_map(|(i, x)| if x == path1 { Some(i) } else { None });
assert!(path0 < path1);
}

#[test]
fn test() {
let path = std::env::current_dir().unwrap();
let path = path.join("../../testcases/filelist");
let metadata_path = Metadata::search_from(path).unwrap();
let mut metadata = Metadata::load(&metadata_path).unwrap();
let paths = metadata.paths::<PathBuf>(&[], false).unwrap();

let mut contexts = Vec::new();

for path in &paths {
let input = fs::read_to_string(&path.src).unwrap();
let parser = Parser::parse(&input, &path.src).unwrap();

let analyzer = Analyzer::new(&metadata);
let _ = analyzer.analyze_pass1(&path.prj, &input, &path.src, &parser.veryl);
contexts.push((path, input, parser, analyzer));
}

Analyzer::analyze_post_pass1();

for (path, input, parser, analyzer) in &contexts {
let _ = analyzer.analyze_pass2(&path.prj, input, &path.src, &parser.veryl);
}

for (path, input, parser, analyzer) in &contexts {
let _ = analyzer.analyze_pass3(&path.prj, input, &path.src, &parser.veryl);
}

let paths = veryl::cmd_build::CmdBuild::sort_filelist(&metadata, &paths);
let paths: Vec<_> = paths
.into_iter()
.map(|x| x.src.file_name().unwrap().to_string_lossy().into_owned())
.collect();

dbg!(&paths);

let all = &[
"package_a.veryl",
"package_b.veryl",
"module_a.veryl",
"module_b.veryl",
"module_c.veryl",
"fifo_controller.veryl",
"fifo.veryl",
"ram.veryl",
// This should be removed by #1064
"test_linear_sec.veryl",
];
check_list(&paths, all);

check_order(&paths, "package_a.veryl", "module_a.veryl");
check_order(&paths, "package_b.veryl", "module_b.veryl");
check_order(&paths, "ram.veryl", "module_c.veryl");
}
}
2 changes: 1 addition & 1 deletion crates/veryl/src/cmd_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl CmdBuild {
Ok(())
}

fn sort_filelist(metadata: &Metadata, paths: &[PathSet]) -> Vec<PathSet> {
pub fn sort_filelist(metadata: &Metadata, paths: &[PathSet]) -> Vec<PathSet> {
let mut table = HashMap::new();
for path in paths {
table.insert(path.src.clone(), path);
Expand Down
234 changes: 234 additions & 0 deletions crates/veryl/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
use clap::{Args, Parser, Subcommand, ValueEnum};
use std::path::PathBuf;

pub mod cmd_build;
pub mod cmd_check;
pub mod cmd_clean;
pub mod cmd_doc;
pub mod cmd_dump;
pub mod cmd_fmt;
pub mod cmd_init;
pub mod cmd_metadata;
pub mod cmd_new;
pub mod cmd_publish;
pub mod cmd_test;
pub mod cmd_update;
pub mod doc;
pub mod runner;

// ---------------------------------------------------------------------------------------------------------------------
// Opt
// ---------------------------------------------------------------------------------------------------------------------

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
pub struct Opt {
/// No output printed to stdout
#[arg(long, global = true)]
pub quiet: bool,

/// Use verbose output
#[arg(long, global = true)]
pub verbose: bool,

/// Generate tab-completion
#[arg(long, global = true, hide = true)]
pub completion: Option<CompletionShell>,

#[command(subcommand)]
pub command: Commands,
}

#[derive(Clone, ValueEnum)]
#[clap(rename_all = "lower")]
pub enum CompletionShell {
Bash,
Elvish,
Fish,
PowerShell,
Zsh,
}

#[derive(Subcommand)]
pub enum Commands {
New(OptNew),
Init(OptInit),
Fmt(OptFmt),
Check(OptCheck),
Build(OptBuild),
Clean(OptClean),
Update(OptUpdate),
Publish(OptPublish),
Doc(OptDoc),
Metadata(OptMetadata),
Dump(OptDump),
Test(OptTest),
}

/// Create a new project
#[derive(Args)]
pub struct OptNew {
pub path: PathBuf,
}

/// Create a new project in an existing directory
#[derive(Args)]
pub struct OptInit {
#[arg(default_value = ".")]
pub path: PathBuf,
}

/// Format the current project
#[derive(Args)]
pub struct OptFmt {
/// Target files
pub files: Vec<PathBuf>,

/// Run fmt in check mode
#[arg(long)]
pub check: bool,
}

/// Analyze the current project
#[derive(Args)]
pub struct OptCheck {
/// Target files
pub files: Vec<PathBuf>,
}

/// Build the target codes corresponding to the current project
#[derive(Args)]
pub struct OptBuild {
/// Target files
pub files: Vec<PathBuf>,
}

/// Clean-up the current project
#[derive(Args)]
pub struct OptClean {}

/// Update dependencies
#[derive(Args)]
pub struct OptUpdate {}

/// Publish the current project
#[derive(Args)]
pub struct OptPublish {
/// Bump version
#[arg(long)]
pub bump: Option<BumpKind>,
}

/// Build the document corresponding to the current project
#[derive(Args)]
pub struct OptDoc {
/// Target files
pub files: Vec<PathBuf>,
}

/// Execute tests
#[derive(Args)]
pub struct OptTest {
/// Target files
pub files: Vec<PathBuf>,

/// Simulator
#[arg(long, value_enum)]
pub sim: Option<SimType>,

/// Dump waveform
#[arg(long)]
pub wave: bool,
}

#[derive(Clone, Copy, Debug, ValueEnum)]
pub enum SimType {
/// Verilator
Verilator,
/// Synopsys VCS
Vcs,
/// AMD Vivado Simulator
Vivado,
}

impl From<SimType> for veryl_metadata::SimType {
fn from(x: SimType) -> Self {
match x {
SimType::Verilator => veryl_metadata::SimType::Verilator,
SimType::Vcs => veryl_metadata::SimType::Vcs,
SimType::Vivado => veryl_metadata::SimType::Vivado,
}
}
}

#[derive(Clone, Copy, Default, Debug, ValueEnum)]
pub enum BumpKind {
/// Increment majoir version
Major,
/// Increment minor version
Minor,
/// Increment patch version
#[default]
Patch,
}

impl From<BumpKind> for veryl_metadata::BumpKind {
fn from(x: BumpKind) -> Self {
match x {
BumpKind::Major => veryl_metadata::BumpKind::Major,
BumpKind::Minor => veryl_metadata::BumpKind::Minor,
BumpKind::Patch => veryl_metadata::BumpKind::Patch,
}
}
}

/// Dump metadata of the current packege
#[derive(Args)]
pub struct OptMetadata {
/// output format
#[arg(long, value_enum, default_value_t)]
pub format: Format,
}

#[derive(Clone, Copy, Default, Debug, ValueEnum)]
pub enum Format {
#[default]
Pretty,
Json,
}

/// Dump debug info
#[derive(Args)]
pub struct OptDump {
/// Target files
pub files: Vec<PathBuf>,

/// output syntex tree
#[arg(long)]
pub syntax_tree: bool,

/// output symbol table
#[arg(long)]
pub symbol_table: bool,

/// output assign list
#[arg(long)]
pub assign_list: bool,

/// output namespace table
#[arg(long)]
pub namespace_table: bool,

/// output type dag
#[arg(long)]
pub type_dag: bool,

/// output attribute table
#[arg(long)]
pub attribute_table: bool,

/// output unsafe table
#[arg(long)]
pub unsafe_table: bool,
}
Loading

0 comments on commit e222f34

Please sign in to comment.