Skip to content

Commit

Permalink
Allow type parameter override
Browse files Browse the repository at this point in the history
  • Loading branch information
dalance committed Sep 12, 2024
1 parent 1c94e76 commit 43798ff
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
18 changes: 18 additions & 0 deletions crates/analyzer/src/handlers/check_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct CheckExpression<'a> {
evaluator: Evaluator,
call_stack_kind: Vec<FunctionKind>,
in_inst_declaration: bool,
in_inst_parameter: bool,
}

#[derive(Debug, Clone, Copy, PartialEq)]
Expand Down Expand Up @@ -94,6 +95,15 @@ impl<'a> VerylGrammarTrait for CheckExpression<'a> {
}
// instance can be used as factor in inst_declaration
SymbolKind::Instance(_) if self.in_inst_declaration => (),
// type can be used as factor in inst_parameter
SymbolKind::TypeDef(_)
| SymbolKind::Struct(_)
| SymbolKind::Enum(_)
| SymbolKind::Union(_)
if self.in_inst_parameter =>
{
()
}
SymbolKind::Module(_)
| SymbolKind::ProtoModule(_)
| SymbolKind::Interface(_)
Expand Down Expand Up @@ -186,4 +196,12 @@ impl<'a> VerylGrammarTrait for CheckExpression<'a> {
}
Ok(())
}

fn inst_parameter(&mut self, _arg: &InstParameter) -> Result<(), ParolError> {
match self.point {
HandlerPoint::Before => self.in_inst_parameter = true,
HandlerPoint::After => self.in_inst_parameter = false,
}
Ok(())
}
}
1 change: 1 addition & 0 deletions testcases/map/testcases/sv/71_type_parameter.sv.map

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

20 changes: 20 additions & 0 deletions testcases/sv/71_type_parameter.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module veryl_testcase_Module71 #(
parameter type param_type = logic
);
typedef logic [32-1:0] type_type;

typedef struct packed {
logic a;
} struct_type;

veryl_testcase_Module71A #(.T1 (param_type), .T2 (type_type), .T3 (struct_type) /*T4: logic,*/) m ();
endmodule

module veryl_testcase_Module71A #(
parameter type T1 = logic,
parameter type T2 = logic,
parameter type T3 = logic,
parameter type T4 = logic
);
endmodule
//# sourceMappingURL=../map/testcases/sv/71_type_parameter.sv.map
18 changes: 18 additions & 0 deletions testcases/veryl/71_type_parameter.veryl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Module71 #(
param param_type: type = logic,
) {
type type_type = logic<32>;

struct struct_type {
a: logic,
}

inst m: Module71A #(T1: param_type, T2: type_type, T3: struct_type, /*T4: logic,*/);
}

module Module71A #(
param T1: type = logic,
param T2: type = logic,
param T3: type = logic,
param T4: type = logic,
) {}

0 comments on commit 43798ff

Please sign in to comment.