Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ fxhash = "0.2.1"
log = "0.4.26"
mdbook = "0.4.47"
miette = {version = "7.5"}
once_cell = "1.21"
pulldown-cmark = "0.12.2"
regex = "1.11.1"
semver = {version = "1.0", features = ["serde"]}
Expand Down
4 changes: 1 addition & 3 deletions crates/analyzer/src/instance_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ impl InstanceHistory {
if self.full.len() > self.total_limit {
return Err(InstanceHistoryError::ExceedTotalLimit);
}
if self.hierarchy.iter().any(|x| *x == sig)
&& sig.params.iter().all(|x| x.1.get_value().is_some())
{
if self.hierarchy.contains(&sig) && sig.params.iter().all(|x| x.1.get_value().is_some()) {
return Err(InstanceHistoryError::InfiniteRecursion);
}
if self.full.contains(&sig) {
Expand Down
4 changes: 2 additions & 2 deletions crates/analyzer/src/symbol_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct ResolveResult {

#[derive(Clone, Debug)]
pub struct ResolveError {
pub last_found: Option<Symbol>,
pub last_found: Option<Box<Symbol>>,
pub cause: ResolveErrorCause,
}

Expand All @@ -34,7 +34,7 @@ pub enum ResolveErrorCause {
impl ResolveError {
pub fn new(last_found: Option<&Symbol>, cause: ResolveErrorCause) -> Self {
Self {
last_found: last_found.cloned(),
last_found: last_found.map(|s| Box::new(s.clone())),
cause,
}
}
Expand Down
28 changes: 12 additions & 16 deletions crates/analyzer/src/type_dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub enum Context {

#[derive(Debug, Clone)]
pub enum DagError {
Cyclic(Symbol, Symbol),
Cyclic(Box<Symbol>, Box<Symbol>),
}

impl TypeDag {
Expand Down Expand Up @@ -80,13 +80,11 @@ impl TypeDag {
}
}

fn get_symbol(&self, node: u32) -> Symbol {
match self.symbols.get(&node) {
Some(x) => x.clone(),
None => {
panic!("Must insert node before accessing");
}
}
fn get_cloned_symbol(&self, node: u32) -> Symbol {
self.symbols
.get(&node)
.expect("Must insert node before accessing")
.clone()
}

fn insert_edge(&mut self, start: u32, end: u32, edge: Context) -> Result<(), DagError> {
Expand All @@ -98,9 +96,9 @@ impl TypeDag {
if matches!(edge, Context::Module | Context::Interface) && is_direct_recursion {
Ok(())
} else {
let ssym = self.get_symbol(start);
let esym = self.get_symbol(end);
Err(DagError::Cyclic(ssym, esym))
let ssym = self.get_cloned_symbol(start);
let esym = self.get_cloned_symbol(end);
Err(DagError::Cyclic(Box::new(ssym), Box::new(esym)))
}
}
}
Expand All @@ -122,8 +120,7 @@ impl TypeDag {
for node in nodes {
let index = node.index() as u32;
if self.paths.contains_key(&index) {
let sym = self.get_symbol(index);
ret.push(sym);
ret.push(self.get_cloned_symbol(index));
}
}
ret
Expand All @@ -142,8 +139,7 @@ impl TypeDag {
while let Some(x) = dfs.next(&graph) {
let index = x.index() as u32;
if self.paths.contains_key(&index) {
let symbol = self.get_symbol(index);
connected.push(symbol);
connected.push(self.get_cloned_symbol(index));
}
}
if !connected.is_empty() {
Expand Down Expand Up @@ -227,7 +223,7 @@ pub fn insert_node(symbol_id: SymbolId, name: &str) -> Result<u32, DagError> {
}

pub fn get_symbol(node: u32) -> Symbol {
TYPE_DAG.with(|f| f.borrow().get_symbol(node))
TYPE_DAG.with(|f| f.borrow().get_cloned_symbol(node))
}

pub fn toposort() -> Vec<Symbol> {
Expand Down
7 changes: 3 additions & 4 deletions crates/emitter/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4264,8 +4264,8 @@ pub fn symbol_string(token: &VerylToken, symbol: &Symbol, context: &SymbolContex
| SymbolKind::Union(_)
| SymbolKind::TypeDef(_)
| SymbolKind::Enum(_) => {
let visible = namespace.included(&symbol.namespace)
|| symbol.imported.iter().any(|x| *x == namespace);
let visible =
namespace.included(&symbol.namespace) || symbol.imported.contains(&namespace);
if visible & !context.in_import {
ret.push_str(&token_text);
} else {
Expand Down Expand Up @@ -4295,8 +4295,7 @@ pub fn symbol_string(token: &VerylToken, symbol: &Symbol, context: &SymbolContex
}
SymbolKind::GenericInstance(x) => {
let base = symbol_table::get(x.base).unwrap();
let visible = namespace.included(&base.namespace)
|| base.imported.iter().any(|x| *x == namespace);
let visible = namespace.included(&base.namespace) || base.imported.contains(&namespace);
let top_level = matches!(
base.kind,
SymbolKind::Module(_) | SymbolKind::Interface(_) | SymbolKind::Package(_)
Expand Down
1 change: 0 additions & 1 deletion crates/metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ edition.workspace = true
[dependencies]
git-repository = {version = "0.35.0", optional = true, features = ["blocking-network-client", "blocking-http-transport-reqwest", "blocking-http-transport-reqwest-rust-tls"]}
log = {workspace = true}
once_cell = {workspace = true}
regex = {workspace = true}
semver = {workspace = true}
serde = {workspace = true}
Expand Down
2 changes: 1 addition & 1 deletion crates/metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ pub use project::Project;
pub use pubfile::{Pubfile, Release};
pub use publish::Publish;
pub use semver;
pub use test::{SimType, Test, WaveFormTarget};
pub use test::{SimType, Test, WaveFormFormat, WaveFormTarget};
6 changes: 3 additions & 3 deletions crates/metadata/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::publish::Publish;
use crate::test::Test;
use crate::{FilelistType, MetadataError, SourceMapTarget};
use log::{debug, info};
use once_cell::sync::Lazy;
use regex::Regex;
use semver::VersionReq;
use serde::{Deserialize, Serialize};
Expand All @@ -21,6 +20,7 @@ use std::fmt;
use std::fs;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::LazyLock;
use url::Url;
use veryl_path::PathSet;

Expand Down Expand Up @@ -80,8 +80,8 @@ impl fmt::Display for UrlPath {
}
}

static VALID_PROJECT_NAME: Lazy<Regex> =
Lazy::new(|| Regex::new(r"^[a-zA-Z_][0-9a-zA-Z_]*$").unwrap());
static VALID_PROJECT_NAME: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"^[a-zA-Z_][0-9a-zA-Z_]*$").unwrap());

impl Metadata {
pub fn search_from_current() -> Result<PathBuf, MetadataError> {
Expand Down
20 changes: 20 additions & 0 deletions crates/metadata/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub struct Test {
pub vivado: VivadoProperty,
#[serde(default)]
pub waveform_target: WaveFormTarget,
#[serde(default)]
pub waveform_format: WaveFormFormat,
}

#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
Expand Down Expand Up @@ -65,3 +67,21 @@ pub enum WaveFormTarget {
#[serde(rename = "directory")]
Directory { path: PathBuf },
}

#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
pub enum WaveFormFormat {
#[default]
#[serde(rename = "vcd")]
Vcd,
#[serde(rename = "fst")]
Fst,
}

impl WaveFormFormat {
pub fn extension(self) -> &'static str {
match self {
WaveFormFormat::Vcd => "vcd",
WaveFormFormat::Fst => "fst",
}
}
}
1 change: 0 additions & 1 deletion crates/parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ exclude = ["build.rs"]
[dependencies]
anyhow = {workspace = true}
bimap = "0.6.3"
once_cell = {workspace = true}
parol_runtime = {version = "3.0", features = ["regex_automata"], default-features = false}
paste = "1.0"
regex = {workspace = true}
Expand Down
4 changes: 2 additions & 2 deletions crates/parser/src/generated/veryl_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
// lost after next build.
// ---------------------------------------------------------

use parol_runtime::once_cell::sync::Lazy;
#[allow(unused_imports)]
use parol_runtime::parser::{LLKParser, LookaheadDFA, ParseTreeType, ParseType, Production, Trans};
use parol_runtime::{ParolError, ParseTree, TerminalIndex};
use parol_runtime::{ScannerConfig, TokenStream, Tokenizer};
use std::path::Path;
use std::sync::LazyLock;

use crate::veryl_grammar::VerylGrammar;
use crate::veryl_grammar_trait::VerylGrammarAuto;
Expand Down Expand Up @@ -27553,7 +27553,7 @@ pub const PRODUCTIONS: &[Production; 1010] = &[
},
];

static SCANNERS: Lazy<Vec<ScannerConfig>> = Lazy::new(|| {
static SCANNERS: LazyLock<Vec<ScannerConfig>> = LazyLock::new(|| {
vec![
ScannerConfig::new(
"INITIAL",
Expand Down
6 changes: 3 additions & 3 deletions crates/parser/src/veryl_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use crate::doc_comment_table;
use crate::resource_table::{self, PathId, StrId, TokenId};
use crate::text_table::{self, TextId};
use crate::veryl_grammar_trait::*;
use once_cell::sync::Lazy;
use paste::paste;
use regex::Regex;
use std::fmt;
use std::sync::LazyLock;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TokenSource {
Expand Down Expand Up @@ -875,8 +875,8 @@ impl ExpressionIdentifier {
}
}

static COMMENT_REGEX: Lazy<Regex> =
Lazy::new(|| Regex::new(r"((?://.*(?:\r\n|\r|\n|$))|(?:(?ms)/\u{2a}.*?\u{2a}/))").unwrap());
static COMMENT_REGEX: LazyLock<Regex> =
LazyLock::new(|| Regex::new(r"((?://.*(?:\r\n|\r|\n|$))|(?:(?ms)/\u{2a}.*?\u{2a}/))").unwrap());

fn split_comment_token(token: Token) -> Vec<Token> {
let mut line = token.line;
Expand Down
1 change: 0 additions & 1 deletion crates/veryl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ fern = "0.7.0"
futures = {workspace = true}
handlebars = "6.3"
log = {workspace = true}
once_cell = {workspace = true}
mdbook = {workspace = true}
miette = {workspace = true}
pulldown-cmark = {workspace = true}
Expand Down
12 changes: 7 additions & 5 deletions crates/veryl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ fn main() -> Result<ExitCode> {
"{} {}{}",
style.apply_to(format!("[{:<5}]", record.level())),
" ".repeat(
12 - format!("{message}")
.split_ascii_whitespace()
.next()
.unwrap()
.len()
12_usize.saturating_sub(
format!("{message}")
.split_ascii_whitespace()
.next()
.unwrap()
.len()
)
),
message
))
Expand Down
37 changes: 23 additions & 14 deletions crates/veryl/src/runner.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use anstyle::{AnsiColor, Style};
use log::{Level, debug, log_enabled};
use miette::{IntoDiagnostic, Result};
use once_cell::sync::Lazy;
use regex::Regex;
use std::fs;
use std::path::{Path, PathBuf};
use std::sync::LazyLock;
use veryl_metadata::{Metadata, WaveFormTarget};
use veryl_parser::resource_table::{PathId, StrId};
use veryl_sourcemap::SourceMap;
Expand Down Expand Up @@ -39,33 +39,33 @@ pub trait Runner {
}

fn info(&self, line: &str) {
static STYLE: Lazy<Style> =
Lazy::new(|| Style::new().fg_color(Some(AnsiColor::Green.into())));
static STYLE: LazyLock<Style> =
LazyLock::new(|| Style::new().fg_color(Some(AnsiColor::Green.into())));
if !log_enabled!(Level::Debug) {
println!("{}{}{}", STYLE.render(), line, STYLE.render_reset());
}
}

fn warning(&mut self, line: &str) {
static STYLE: Lazy<Style> =
Lazy::new(|| Style::new().fg_color(Some(AnsiColor::Yellow.into())));
static STYLE: LazyLock<Style> =
LazyLock::new(|| Style::new().fg_color(Some(AnsiColor::Yellow.into())));
if !log_enabled!(Level::Debug) {
println!("{}{}{}", STYLE.render(), line, STYLE.render_reset());
}
}

fn error(&mut self, line: &str) {
static STYLE: Lazy<Style> =
Lazy::new(|| Style::new().fg_color(Some(AnsiColor::Red.into())));
static STYLE: LazyLock<Style> =
LazyLock::new(|| Style::new().fg_color(Some(AnsiColor::Red.into())));
if !log_enabled!(Level::Debug) {
println!("{}{}{}", STYLE.render(), line, STYLE.render_reset());
}
self.failure();
}

fn fatal(&mut self, line: &str) {
static STYLE: Lazy<Style> =
Lazy::new(|| Style::new().fg_color(Some(AnsiColor::Red.into())).bold());
static STYLE: LazyLock<Style> =
LazyLock::new(|| Style::new().fg_color(Some(AnsiColor::Red.into())).bold());
if !log_enabled!(Level::Debug) {
println!("{}{}{}", STYLE.render(), line, STYLE.render_reset());
}
Expand Down Expand Up @@ -106,13 +106,22 @@ pub fn copy_wave(
metadata: &Metadata,
work_path: &Path,
) -> Result<()> {
// The file always has a `.vcd` extension, because `$dumpfile` doesn't have the metadata information
let wave_src_path = work_path.join(format!("{}.vcd", test_name));

// but let's rename the target file to the correct extension, based on the selected format
let target_name = format!(
"{}.{}",
test_name,
metadata.test.waveform_format.extension()
);

let wave_dst_path = match &metadata.test.waveform_target {
WaveFormTarget::Target => {
let target = PathBuf::from(test_path.to_string());
target.parent().unwrap().join(format!("{}.vcd", test_name))
}
WaveFormTarget::Directory { path } => path.join(format!("{}.vcd", test_name)),
WaveFormTarget::Target => PathBuf::from(test_path.to_string())
.parent()
.unwrap()
.join(target_name),
WaveFormTarget::Directory { path } => path.join(target_name),
};

let wave_dst_dir = wave_dst_path.parent().unwrap();
Expand Down
Loading
Loading