Skip to content

Commit f04bd6b

Browse files
committed
temp
1 parent b90ba7b commit f04bd6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+4912
-217
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,12 @@ console = "0.16.1"
3939
futures = "0.3.31"
4040
fxhash = "0.2.1"
4141
handlebars = "6.3"
42+
itertools = "0.14.0"
4243
log = "0.4.28"
4344
mdbook = "0.4.51"
4445
miette = {version = "7.6"}
46+
num-bigint = "0.4.6"
47+
num-traits = "0.2.19"
4548
once_cell = "1.21"
4649
parol_runtime = "4.0"
4750
pulldown-cmark = "0.13.0"

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ install:
7777
gen_sv:
7878
cargo run --bin veryl -- build
7979

80+
gen_ir:
81+
cargo run --bin veryl -- dump --ir
82+
8083
fmt_veryl:
8184
cargo run --bin veryl -- fmt
8285

crates/analyzer/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ edition.workspace = true
1616
bimap = "0.6.3"
1717
daggy = "0.9.0"
1818
fxhash = {workspace = true}
19-
itertools = "0.14.0"
19+
indent = "0.1.1"
20+
itertools = {workspace = true}
2021
log = {workspace = true}
21-
num-bigint = "0.4.6"
22-
num-traits = "0.2.19"
22+
num-bigint = {workspace = true}
23+
num-traits = {workspace = true}
2324
smallvec = {workspace = true}
2425
strnum_bitwidth = {workspace = true}
2526
thiserror = {workspace = true}

crates/analyzer/src/analyzer.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::attribute_table;
55
use crate::handlers::check_expression::CheckExpression;
66
use crate::handlers::*;
77
use crate::instance_history;
8+
use crate::ir::{Ir, ir_table};
89
use crate::msb_table;
910
use crate::namespace::Namespace;
1011
use crate::namespace_table;
@@ -377,11 +378,18 @@ impl Analyzer {
377378
ret
378379
}
379380

381+
fn create_ir(input: &Veryl) -> (Ir, Vec<AnalyzerError>) {
382+
let ir = input.into();
383+
let errors = ir_table::drain_errors();
384+
(ir, errors)
385+
}
386+
380387
pub fn analyze_pass2<T: AsRef<Path>>(
381388
&self,
382389
project_name: &str,
383390
_path: T,
384391
input: &Veryl,
392+
ir: Option<&mut Ir>,
385393
) -> Vec<AnalyzerError> {
386394
let mut ret = Vec::new();
387395

@@ -393,6 +401,14 @@ impl Analyzer {
393401
pass2.veryl(input);
394402
ret.append(&mut pass2.handlers.get_errors());
395403

404+
// some pass2 errors are generated in create_ir
405+
// The actual implementation is under crate/analyzer/src/ir/conv
406+
let mut ir_result = Self::create_ir(input);
407+
ret.append(&mut ir_result.1);
408+
if let Some(x) = ir {
409+
x.append(&mut ir_result.0);
410+
}
411+
396412
ret
397413
}
398414

crates/analyzer/src/handlers.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub mod check_msb_lsb;
1313
pub mod check_number;
1414
pub mod check_port;
1515
pub mod check_proto;
16-
pub mod check_separator;
1716
pub mod check_statement;
1817
pub mod check_type;
1918
pub mod check_unsafe;
@@ -34,7 +33,6 @@ use check_msb_lsb::*;
3433
use check_number::*;
3534
use check_port::*;
3635
use check_proto::*;
37-
use check_separator::*;
3836
use check_statement::*;
3937
use check_type::*;
4038
use check_unsafe::*;
@@ -101,7 +99,6 @@ impl Pass1Handlers {
10199
}
102100

103101
pub struct Pass2Handlers {
104-
check_separator: CheckSeparator,
105102
check_enum: CheckEnum,
106103
check_modport: CheckModport,
107104
check_function: CheckFunction,
@@ -114,13 +111,12 @@ pub struct Pass2Handlers {
114111
check_clock_domain: CheckClockDomain,
115112
check_proto: CheckProto,
116113
check_type: CheckType,
117-
enables: [bool; 13],
114+
enables: [bool; 12],
118115
}
119116

120117
impl Pass2Handlers {
121118
pub fn new(_build_opt: &Build, _lint_opt: &Lint, env_var: &EnvVar) -> Self {
122119
Self {
123-
check_separator: CheckSeparator::new(),
124120
check_enum: CheckEnum::new(),
125121
check_modport: CheckModport::new(),
126122
check_function: CheckFunction::new(),
@@ -140,25 +136,23 @@ impl Pass2Handlers {
140136
pub fn get_handlers(&mut self) -> Vec<(bool, &mut dyn Handler)> {
141137
let en = &self.enables;
142138
vec![
143-
(en[0], &mut self.check_separator as &mut dyn Handler),
144-
(en[1], &mut self.check_enum as &mut dyn Handler),
145-
(en[2], &mut self.check_modport as &mut dyn Handler),
146-
(en[3], &mut self.check_function as &mut dyn Handler),
147-
(en[4], &mut self.check_msb_lsb as &mut dyn Handler),
148-
(en[5], &mut self.check_connect_operation as &mut dyn Handler),
149-
(en[6], &mut self.check_var_ref as &mut dyn Handler),
150-
(en[7], &mut self.check_clock_reset as &mut dyn Handler),
151-
(en[8], &mut self.check_anonymous as &mut dyn Handler),
152-
(en[9], &mut self.check_expression as &mut dyn Handler),
153-
(en[10], &mut self.check_clock_domain as &mut dyn Handler),
154-
(en[11], &mut self.check_proto as &mut dyn Handler),
155-
(en[12], &mut self.check_type as &mut dyn Handler),
139+
(en[0], &mut self.check_enum as &mut dyn Handler),
140+
(en[1], &mut self.check_modport as &mut dyn Handler),
141+
(en[2], &mut self.check_function as &mut dyn Handler),
142+
(en[3], &mut self.check_msb_lsb as &mut dyn Handler),
143+
(en[4], &mut self.check_connect_operation as &mut dyn Handler),
144+
(en[5], &mut self.check_var_ref as &mut dyn Handler),
145+
(en[6], &mut self.check_clock_reset as &mut dyn Handler),
146+
(en[7], &mut self.check_anonymous as &mut dyn Handler),
147+
(en[8], &mut self.check_expression as &mut dyn Handler),
148+
(en[9], &mut self.check_clock_domain as &mut dyn Handler),
149+
(en[10], &mut self.check_proto as &mut dyn Handler),
150+
(en[11], &mut self.check_type as &mut dyn Handler),
156151
]
157152
}
158153

159154
pub fn get_errors(&mut self) -> Vec<AnalyzerError> {
160155
let mut ret = Vec::new();
161-
ret.append(&mut self.check_separator.errors);
162156
ret.append(&mut self.check_enum.errors);
163157
ret.append(&mut self.check_modport.errors);
164158
ret.append(&mut self.check_function.errors);

crates/analyzer/src/handlers/check_anonymous.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl VerylGrammarTrait for CheckAnonymous {
117117
if let Some(port) = self
118118
.inst_ports
119119
.iter()
120-
.find(|x| x.name() == arg.identifier.identifier_token.token.text)
120+
.find(|x| x.name() == arg.identifier.text())
121121
{
122122
if let SymbolKind::Port(port) = symbol_table::get(port.symbol).unwrap().kind
123123
{

crates/analyzer/src/handlers/check_clock_domain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl VerylGrammarTrait for CheckClockDomain {
253253
let domain = self.check_expr_clock_domains(&arg.identifier.identifier_token.token);
254254
let range: TokenRange = arg.identifier.as_ref().into();
255255
self.inst_clock_domains
256-
.insert(arg.identifier.identifier_token.token.text, (domain, range));
256+
.insert(arg.identifier.text(), (domain, range));
257257
}
258258
}
259259
Ok(())

crates/analyzer/src/handlers/check_expression.rs

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pub struct CheckExpression {
2727
point: HandlerPoint,
2828
evaluator: Evaluator,
2929
port_direction: Option<Direction>,
30-
in_proto: bool,
3130
in_input_port_default_value: bool,
3231
disable: bool,
3332
disable_block_beg: HashSet<TokenId>,
@@ -253,7 +252,7 @@ impl CheckExpression {
253252
};
254253

255254
for param in params {
256-
let name = param.identifier.identifier_token.token.text;
255+
let name = param.identifier.text();
257256

258257
let Ok(target) =
259258
symbol_table::resolve((param.identifier.as_ref(), &component_namespace))
@@ -303,7 +302,7 @@ impl CheckExpression {
303302

304303
for connect in connections {
305304
let token: TokenRange = (&connect).into();
306-
let dst = connect.identifier.identifier_token.token.text;
305+
let dst = connect.identifier.text();
307306

308307
match (connect.inst_port_item_opt, ports.get(&dst)) {
309308
(Some(src), Some(dst)) => {
@@ -738,31 +737,24 @@ impl VerylGrammarTrait for CheckExpression {
738737
fn with_parameter_item(&mut self, arg: &WithParameterItem) -> Result<(), ParolError> {
739738
if !self.disable
740739
&& let HandlerPoint::Before = self.point
740+
&& let Some(x) = &arg.with_parameter_item_opt
741741
{
742-
if let Some(x) = &arg.with_parameter_item_opt {
743-
let type_expression = matches!(
744-
*arg.with_parameter_item_group0,
745-
WithParameterItemGroup0::Type(_)
742+
let type_expression = matches!(
743+
*arg.with_parameter_item_group0,
744+
WithParameterItemGroup0::Type(_)
745+
);
746+
if !type_expression && let Ok(dst) = symbol_table::resolve(arg.identifier.as_ref()) {
747+
self.evaluate_connection(
748+
Context::ParameterConnection,
749+
&x.expression,
750+
&dst.found,
751+
&[],
752+
&arg.into(),
746753
);
747-
if !type_expression && let Ok(dst) = symbol_table::resolve(arg.identifier.as_ref())
748-
{
749-
self.evaluate_connection(
750-
Context::ParameterConnection,
751-
&x.expression,
752-
&dst.found,
753-
&[],
754-
&arg.into(),
755-
);
756-
} else {
757-
self.evaluate_expression(&x.expression, type_expression);
758-
}
759-
// TODO type check
760-
} else if !self.in_proto {
761-
self.errors.push(AnalyzerError::missing_default_argument(
762-
&arg.identifier.identifier_token.token.to_string(),
763-
&arg.identifier.as_ref().into(),
764-
));
754+
} else {
755+
self.evaluate_expression(&x.expression, type_expression);
765756
}
757+
// TODO type check
766758
}
767759

768760
Ok(())
@@ -910,26 +902,4 @@ impl VerylGrammarTrait for CheckExpression {
910902

911903
Ok(())
912904
}
913-
914-
fn proto_module_declaration(
915-
&mut self,
916-
_arg: &ProtoModuleDeclaration,
917-
) -> Result<(), ParolError> {
918-
match self.point {
919-
HandlerPoint::Before => self.in_proto = true,
920-
HandlerPoint::After => self.in_proto = false,
921-
}
922-
Ok(())
923-
}
924-
925-
fn proto_interface_declaration(
926-
&mut self,
927-
_arg: &ProtoInterfaceDeclaration,
928-
) -> Result<(), ParolError> {
929-
match self.point {
930-
HandlerPoint::Before => self.in_proto = true,
931-
HandlerPoint::After => self.in_proto = false,
932-
}
933-
Ok(())
934-
}
935905
}

crates/analyzer/src/handlers/check_msb_lsb.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,7 @@ impl VerylGrammarTrait for CheckMsbLsb {
153153
if let HandlerPoint::Before = self.point
154154
&& self.is_in_expression_identifier()
155155
{
156-
self.identifier_path
157-
.last_mut()
158-
.unwrap()
159-
.0
160-
.push(arg.identifier_token.token.text);
156+
self.identifier_path.last_mut().unwrap().0.push(arg.text());
161157
}
162158
Ok(())
163159
}

0 commit comments

Comments
 (0)