Skip to content

Commit

Permalink
Change compare operator and width/array notation #94 #93
Browse files Browse the repository at this point in the history
  • Loading branch information
dalance committed Jan 27, 2023
1 parent 491c118 commit 7a78335
Show file tree
Hide file tree
Showing 78 changed files with 22,973 additions and 34,673 deletions.
4 changes: 2 additions & 2 deletions Veryl.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ indent_width = 4

[dependencies]
veryl_sample1 = {git = "https://github.com/dalance/veryl_sample"}
veryl_sample2 = {git = "https://github.com/dalance/veryl_sample", rev = "a3fb1fe"}
veryl_sample3 = {git = "https://github.com/dalance/veryl_sample", tag = "v0.1"}
veryl_sample2 = {git = "https://github.com/dalance/veryl_sample", rev = "9e9a30a"}
veryl_sample3 = {git = "https://github.com/dalance/veryl_sample", tag = "v0.4"}
veryl_sample4 = {git = "https://github.com/dalance/veryl_sample", branch = "branch"}
1 change: 0 additions & 1 deletion crates/analyzer/src/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,6 @@ impl Evaluator {
}
}
}
Factor::BuiltinTypeFactorList(_) => Evaluated::Unknown,
Factor::LParenExpressionRParen(x) => self.expression(&x.expression),
Factor::LBraceConcatenationListRBrace(x) => {
self.concatenation_list(&x.concatenation_list)
Expand Down
2 changes: 1 addition & 1 deletion crates/analyzer/src/handlers/check_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<'a> VerylGrammarTrait for CheckEnum<'a> {
}
HandlerPoint::After => {
let mut evaluator = Evaluator::new();
let r#type: crate::symbol::Type = arg.r#type.as_ref().into();
let r#type: crate::symbol::Type = arg.scalar_type.as_ref().into();
let width = evaluator.type_width(r#type);
if let Some(width) = width {
let max_members = 2_usize.pow(width as u32);
Expand Down
4 changes: 2 additions & 2 deletions crates/analyzer/src/handlers/check_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ impl<'a> VerylGrammarTrait for CheckFunction<'a> {

let mut args = 0;
if let Some(ref x) = x.factor_opt {
if let Some(ref x) = x.factor_opt0 {
if let Some(ref x) = x.function_call.function_call_opt {
args += 1;
args += x.function_call_arg.function_call_arg_list.len();
args += x.argument_list.argument_list_list.len();
}
}

Expand Down
80 changes: 59 additions & 21 deletions crates/analyzer/src/handlers/create_symbol_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use crate::symbol::Type as SymType;
use crate::symbol::{
EnumMemberProperty, EnumProperty, FunctionProperty, InstanceProperty, InterfaceProperty,
ModportMember, ModportProperty, ModuleProperty, ParameterProperty, ParameterScope,
PortProperty, StructMemberProperty, Symbol, SymbolKind, VariableProperty,
ParameterValue, PortProperty, StructMemberProperty, Symbol, SymbolKind, TypeKind,
VariableProperty,
};
use crate::symbol_table;
use veryl_parser::resource_table::{self, StrId};
Expand Down Expand Up @@ -69,7 +70,7 @@ impl<'a> VerylGrammarTrait for CreateSymbolTable<'a> {
self.namespace.push(name);
self.anonymous_namespace += 1;

let r#type: SymType = arg.r#type.as_ref().into();
let r#type: SymType = arg.scalar_type.as_ref().into();
let property = VariableProperty { r#type };
let kind = SymbolKind::Variable(property);
self.insert_symbol(&arg.identifier.identifier_token, kind);
Expand All @@ -81,7 +82,7 @@ impl<'a> VerylGrammarTrait for CreateSymbolTable<'a> {

fn var_declaration(&mut self, arg: &VarDeclaration) -> Result<(), ParolError> {
if let HandlerPoint::Before = self.point {
let r#type: SymType = arg.r#type.as_ref().into();
let r#type: SymType = arg.array_type.as_ref().into();
let property = VariableProperty { r#type };
let kind = SymbolKind::Variable(property);
self.insert_symbol(&arg.identifier.identifier_token, kind);
Expand All @@ -91,13 +92,32 @@ impl<'a> VerylGrammarTrait for CreateSymbolTable<'a> {

fn localparam_declaration(&mut self, arg: &LocalparamDeclaration) -> Result<(), ParolError> {
if let HandlerPoint::Before = self.point {
let r#type: SymType = arg.r#type.as_ref().into();
let value = *arg.expression.clone();
let kind = SymbolKind::Parameter(ParameterProperty {
r#type,
scope: ParameterScope::Local,
value,
});
let property = match &*arg.localparam_declaration_group {
LocalparamDeclarationGroup::ArrayTypeEquExpression(x) => {
let r#type: SymType = x.array_type.as_ref().into();
let value = ParameterValue::Expression(*x.expression.clone());
ParameterProperty {
r#type,
scope: ParameterScope::Local,
value,
}
}
LocalparamDeclarationGroup::TypeEquTypeExpression(x) => {
let r#type: SymType = SymType {
modifier: vec![],
kind: TypeKind::Type,
width: vec![],
array: vec![],
};
let value = ParameterValue::TypeExpression(*x.type_expression.clone());
ParameterProperty {
r#type,
scope: ParameterScope::Local,
value,
}
}
};
let kind = SymbolKind::Parameter(property);
self.insert_symbol(&arg.identifier.identifier_token, kind);
}
Ok(())
Expand All @@ -124,7 +144,7 @@ impl<'a> VerylGrammarTrait for CreateSymbolTable<'a> {
fn enum_declaration(&mut self, arg: &EnumDeclaration) -> Result<(), ParolError> {
match self.point {
HandlerPoint::Before => {
let r#type = arg.r#type.as_ref().into();
let r#type = arg.scalar_type.as_ref().into();
let property = EnumProperty { r#type };
let kind = SymbolKind::Enum(property);
self.insert_symbol(&arg.identifier.identifier_token, kind);
Expand Down Expand Up @@ -163,7 +183,7 @@ impl<'a> VerylGrammarTrait for CreateSymbolTable<'a> {

fn struct_item(&mut self, arg: &StructItem) -> Result<(), ParolError> {
if let HandlerPoint::Before = self.point {
let r#type = arg.r#type.as_ref().into();
let r#type = arg.scalar_type.as_ref().into();
let property = StructMemberProperty { r#type };
let kind = SymbolKind::StructMember(property);
self.insert_symbol(&arg.identifier.identifier_token, kind);
Expand All @@ -190,12 +210,30 @@ impl<'a> VerylGrammarTrait for CreateSymbolTable<'a> {
WithParameterItemGroup::Parameter(_) => ParameterScope::Global,
WithParameterItemGroup::Localparam(_) => ParameterScope::Local,
};
let r#type: SymType = arg.r#type.as_ref().into();
let value = *arg.expression.clone();
let property = ParameterProperty {
r#type,
scope,
value,
let property = match &*arg.with_parameter_item_group0 {
WithParameterItemGroup0::ArrayTypeEquExpression(x) => {
let r#type: SymType = x.array_type.as_ref().into();
let value = ParameterValue::Expression(*x.expression.clone());
ParameterProperty {
r#type,
scope,
value,
}
}
WithParameterItemGroup0::TypeEquTypeExpression(x) => {
let r#type: SymType = SymType {
modifier: vec![],
kind: TypeKind::Type,
width: vec![],
array: vec![],
};
let value = ParameterValue::TypeExpression(*x.type_expression.clone());
ParameterProperty {
r#type,
scope,
value,
}
}
};
let kind = SymbolKind::Parameter(property);
self.insert_symbol(&arg.identifier.identifier_token, kind);
Expand All @@ -206,15 +244,15 @@ impl<'a> VerylGrammarTrait for CreateSymbolTable<'a> {
fn port_declaration_item(&mut self, arg: &PortDeclarationItem) -> Result<(), ParolError> {
if let HandlerPoint::Before = self.point {
let property = match &*arg.port_declaration_item_group {
PortDeclarationItemGroup::DirectionType(x) => {
let r#type: SymType = x.r#type.as_ref().into();
PortDeclarationItemGroup::DirectionArrayType(x) => {
let r#type: SymType = x.array_type.as_ref().into();
let direction: SymDirection = x.direction.as_ref().into();
PortProperty {
r#type: Some(r#type),
direction,
}
}
PortDeclarationItemGroup::Interface(_) => PortProperty {
PortDeclarationItemGroup::InterfacePortDeclarationItemOpt(_) => PortProperty {
r#type: None,
direction: SymDirection::Interface,
},
Expand Down
4 changes: 2 additions & 2 deletions crates/analyzer/src/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ impl fmt::Display for Namespace {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut text = String::new();
if let Some(first) = self.paths.first() {
text.push_str(&format!("{}", first));
text.push_str(&format!("{first}"));
for path in &self.paths[1..] {
text.push_str(&format!("::{}", path));
text.push_str(&format!("::{path}"));
}
}
text.fmt(f)
Expand Down
4 changes: 2 additions & 2 deletions crates/analyzer/src/namespace_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl NamespaceTable {
}

pub fn dump(&self) -> String {
format!("{}", self)
format!("{self}")
}

pub fn drop(&mut self, file_path: PathId) {
Expand Down Expand Up @@ -57,7 +57,7 @@ impl fmt::Display for NamespaceTable {
let mut vec: Vec<_> = self.table.iter().collect();
vec.sort_by(|x, y| x.0.cmp(y.0));
for (k, v) in &vec {
id_witdh = id_witdh.max(format!("{}", k).len());
id_witdh = id_witdh.max(format!("{k}").len());
namespace_width = namespace_width.max(format!("{}", v.0).len());
}
for (k, v) in &vec {
Expand Down
Loading

0 comments on commit 7a78335

Please sign in to comment.