Skip to content

Commit

Permalink
Merge pull request #1164 from taichi-ishitani/default_port_value
Browse files Browse the repository at this point in the history
Support port default value
  • Loading branch information
dalance authored Dec 26, 2024
2 parents 1bff7d0 + d0e303f commit a34ee69
Show file tree
Hide file tree
Showing 34 changed files with 16,059 additions and 15,256 deletions.
25 changes: 25 additions & 0 deletions crates/analyzer/src/analyzer_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,17 @@ pub enum AnalyzerError {
error_location: SourceSpan,
},

#[diagnostic(severity(Error), code(invalid_port_default_value), help(""), url(""))]
#[error("#{direction} port #{identifier} cannot have a port default value")]
InvalidPortDefaultValue {
identifier: String,
direction: String,
#[source_code]
input: NamedSource<String>,
#[label("Error location")]
error_location: SourceSpan,
},

#[diagnostic(
severity(Error),
code(invalid_reset),
Expand Down Expand Up @@ -1283,6 +1294,20 @@ impl AnalyzerError {
}
}

pub fn invalid_port_default_value(
identifier: &str,
direction: &str,
source: &str,
token: &TokenRange,
) -> Self {
AnalyzerError::InvalidPortDefaultValue {
identifier: identifier.into(),
direction: direction.into(),
input: AnalyzerError::named_source(source, token),
error_location: token.into(),
}
}

pub fn incompat_proto(
identifier: &str,
proto: &str,
Expand Down
6 changes: 3 additions & 3 deletions crates/analyzer/src/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,13 +675,13 @@ impl Evaluator {
fn factor(&mut self, arg: &Factor) -> Evaluated {
match arg {
Factor::Number(x) => self.number(&x.number),
Factor::ExpressionIdentifierFactorOpt(x) => {
if x.factor_opt.is_some() {
Factor::IdentifierFactor(x) => {
if x.identifier_factor.identifier_factor_opt.is_some() {
// Function call
Evaluated::Unknown
} else {
// Identifier
self.expression_identifier(x.expression_identifier.as_ref())
self.expression_identifier(x.identifier_factor.expression_identifier.as_ref())
}
}
Factor::LParenExpressionRParen(x) => self.expression(&x.expression),
Expand Down
12 changes: 6 additions & 6 deletions crates/analyzer/src/handlers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
pub mod check_attribute;
pub mod check_clock_domain;
pub mod check_clock_reset;
pub mod check_direction;
pub mod check_embed_include;
pub mod check_enum;
pub mod check_expression;
Expand All @@ -10,6 +9,7 @@ pub mod check_identifier;
pub mod check_modport;
pub mod check_msb_lsb;
pub mod check_number;
pub mod check_port;
pub mod check_proto;
pub mod check_separator;
pub mod check_statement;
Expand All @@ -21,7 +21,6 @@ pub mod create_symbol_table;
use check_attribute::*;
use check_clock_domain::*;
use check_clock_reset::*;
use check_direction::*;
use check_embed_include::*;
use check_enum::*;
use check_expression::*;
Expand All @@ -30,6 +29,7 @@ use check_identifier::*;
use check_modport::*;
use check_msb_lsb::*;
use check_number::*;
use check_port::*;
use check_proto::*;
use check_separator::*;
use check_statement::*;
Expand All @@ -45,7 +45,7 @@ use veryl_parser::veryl_walker::Handler;

pub struct Pass1Handlers<'a> {
check_attribute: CheckAttribute<'a>,
check_direction: CheckDirection<'a>,
check_port: CheckPort<'a>,
check_embed_include: CheckEmbedInclude<'a>,
check_identifier: CheckIdentifier<'a>,
check_number: CheckNumber<'a>,
Expand All @@ -58,7 +58,7 @@ impl<'a> Pass1Handlers<'a> {
pub fn new(text: &'a str, build_opt: &'a Build, lint_opt: &'a Lint) -> Self {
Self {
check_attribute: CheckAttribute::new(text),
check_direction: CheckDirection::new(text),
check_port: CheckPort::new(text),
check_embed_include: CheckEmbedInclude::new(text),
check_identifier: CheckIdentifier::new(text, lint_opt),
check_number: CheckNumber::new(text),
Expand All @@ -71,7 +71,7 @@ impl<'a> Pass1Handlers<'a> {
pub fn get_handlers(&mut self) -> Vec<&mut dyn Handler> {
vec![
&mut self.check_attribute as &mut dyn Handler,
&mut self.check_direction as &mut dyn Handler,
&mut self.check_port as &mut dyn Handler,
&mut self.check_embed_include as &mut dyn Handler,
&mut self.check_identifier as &mut dyn Handler,
&mut self.check_number as &mut dyn Handler,
Expand All @@ -84,7 +84,7 @@ impl<'a> Pass1Handlers<'a> {
pub fn get_errors(&mut self) -> Vec<AnalyzerError> {
let mut ret = Vec::new();
ret.append(&mut self.check_attribute.errors);
ret.append(&mut self.check_direction.errors);
ret.append(&mut self.check_port.errors);
ret.append(&mut self.check_embed_include.errors);
ret.append(&mut self.check_identifier.errors);
ret.append(&mut self.check_number.errors);
Expand Down
2 changes: 1 addition & 1 deletion crates/analyzer/src/handlers/check_clock_domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl VerylGrammarTrait for CheckClockDomain<'_> {
let mut connection_table =
HashMap::<ClockDomain, (ClockDomain, TokenRange)>::new();
for x in &x.ports {
if let Some(connected) = self.inst_clock_domains.get(&x.name) {
if let Some(connected) = self.inst_clock_domains.get(&x.name()) {
let port_domain = x.property().clock_domain;
if let Some(assigned) = connection_table.get(&port_domain) {
if !assigned.0.compatible(&connected.0)
Expand Down
Loading

0 comments on commit a34ee69

Please sign in to comment.