Skip to content

Commit 221ec94

Browse files
committed
temp
1 parent 9bca888 commit 221ec94

Some content is hidden

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

56 files changed

+5497
-362
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/analyzer_error.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,40 @@ pub enum AnalyzerError {
169169
error_location: SourceSpan,
170170
},
171171

172+
#[diagnostic(
173+
severity(Error),
174+
code(invalid_operand),
175+
help(""),
176+
url("https://doc.veryl-lang.org/book/07_appendix/02_semantic_error.html#invalid_operand")
177+
)]
178+
#[error("{kind} cannot be used as a operand of {op} operator")]
179+
InvalidOperand {
180+
kind: String,
181+
op: String,
182+
#[source_code]
183+
input: MultiSources,
184+
#[label("Error location")]
185+
error_location: SourceSpan,
186+
// TODO
187+
//#[label(collection, "instantiated at")]
188+
//inst_context: Vec<SourceSpan>,
189+
},
190+
191+
#[diagnostic(
192+
severity(Warning),
193+
code(invalid_logical_operand),
194+
help(""),
195+
url("https://doc.veryl-lang.org/book/07_appendix/02_semantic_error.html#invalid_operand")
196+
)]
197+
#[error("{kind} should be 1-bit value")]
198+
InvalidLogicalOperand {
199+
kind: String,
200+
#[source_code]
201+
input: MultiSources,
202+
#[label("Error location")]
203+
error_location: SourceSpan,
204+
},
205+
172206
#[diagnostic(
173207
severity(Error),
174208
code(invalid_factor),
@@ -1487,6 +1521,28 @@ impl AnalyzerError {
14871521
}
14881522
}
14891523

1524+
pub fn invalid_operand(kind: &str, op: &str, token: &TokenRange) -> Self {
1525+
AnalyzerError::InvalidOperand {
1526+
kind: kind.to_string(),
1527+
op: op.to_string(),
1528+
input: source(token),
1529+
error_location: token.into(),
1530+
}
1531+
}
1532+
1533+
pub fn invalid_logical_operand(op: bool, token: &TokenRange) -> Self {
1534+
let kind = if op {
1535+
"Operand of logical operator"
1536+
} else {
1537+
"Conditional expression"
1538+
};
1539+
AnalyzerError::InvalidLogicalOperand {
1540+
kind: kind.to_string(),
1541+
input: source(token),
1542+
error_location: token.into(),
1543+
}
1544+
}
1545+
14901546
pub fn invalid_factor(
14911547
identifier: Option<&str>,
14921548
kind: &str,

crates/analyzer/src/handlers.rs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ pub mod check_modport;
1212
pub mod check_msb_lsb;
1313
pub mod check_number;
1414
pub mod check_port;
15-
pub mod check_proto;
16-
pub mod check_separator;
1715
pub mod check_statement;
1816
pub mod check_type;
1917
pub mod check_unsafe;
@@ -33,8 +31,6 @@ use check_modport::*;
3331
use check_msb_lsb::*;
3432
use check_number::*;
3533
use check_port::*;
36-
use check_proto::*;
37-
use check_separator::*;
3834
use check_statement::*;
3935
use check_type::*;
4036
use check_unsafe::*;
@@ -101,7 +97,6 @@ impl Pass1Handlers {
10197
}
10298

10399
pub struct Pass2Handlers {
104-
check_separator: CheckSeparator,
105100
check_enum: CheckEnum,
106101
check_modport: CheckModport,
107102
check_function: CheckFunction,
@@ -112,15 +107,13 @@ pub struct Pass2Handlers {
112107
check_anonymous: CheckAnonymous,
113108
check_expression: CheckExpression,
114109
check_clock_domain: CheckClockDomain,
115-
check_proto: CheckProto,
116110
check_type: CheckType,
117-
enables: [bool; 13],
111+
enables: [bool; 11],
118112
}
119113

120114
impl Pass2Handlers {
121115
pub fn new(_build_opt: &Build, _lint_opt: &Lint, env_var: &EnvVar) -> Self {
122116
Self {
123-
check_separator: CheckSeparator::new(),
124117
check_enum: CheckEnum::new(),
125118
check_modport: CheckModport::new(),
126119
check_function: CheckFunction::new(),
@@ -131,7 +124,6 @@ impl Pass2Handlers {
131124
check_anonymous: CheckAnonymous::new(),
132125
check_expression: CheckExpression::new(vec![]),
133126
check_clock_domain: CheckClockDomain::new(),
134-
check_proto: CheckProto::new(),
135127
check_type: CheckType::new(),
136128
enables: env_var.analyzer_pass2_enables,
137129
}
@@ -140,25 +132,22 @@ impl Pass2Handlers {
140132
pub fn get_handlers(&mut self) -> Vec<(bool, &mut dyn Handler)> {
141133
let en = &self.enables;
142134
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),
135+
(en[0], &mut self.check_enum as &mut dyn Handler),
136+
(en[1], &mut self.check_modport as &mut dyn Handler),
137+
(en[2], &mut self.check_function as &mut dyn Handler),
138+
(en[3], &mut self.check_msb_lsb as &mut dyn Handler),
139+
(en[4], &mut self.check_connect_operation as &mut dyn Handler),
140+
(en[5], &mut self.check_var_ref as &mut dyn Handler),
141+
(en[6], &mut self.check_clock_reset as &mut dyn Handler),
142+
(en[7], &mut self.check_anonymous as &mut dyn Handler),
143+
(en[8], &mut self.check_expression as &mut dyn Handler),
144+
(en[9], &mut self.check_clock_domain as &mut dyn Handler),
145+
(en[10], &mut self.check_type as &mut dyn Handler),
156146
]
157147
}
158148

159149
pub fn get_errors(&mut self) -> Vec<AnalyzerError> {
160150
let mut ret = Vec::new();
161-
ret.append(&mut self.check_separator.errors);
162151
ret.append(&mut self.check_enum.errors);
163152
ret.append(&mut self.check_modport.errors);
164153
ret.append(&mut self.check_function.errors);
@@ -169,7 +158,6 @@ impl Pass2Handlers {
169158
ret.append(&mut self.check_anonymous.errors);
170159
ret.append(&mut self.check_expression.errors);
171160
ret.append(&mut self.check_clock_domain.errors);
172-
ret.append(&mut self.check_proto.errors);
173161
ret.append(&mut self.check_type.errors);
174162
ret
175163
}

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(())

0 commit comments

Comments
 (0)