From a7784bc176ba281d52b68d2ba658eb7f0ec2bb14 Mon Sep 17 00:00:00 2001 From: Taichi Ishitani Date: Fri, 27 Dec 2024 12:41:53 +0900 Subject: [PATCH] raise error for package referecne before defnition (refs: veryl-lang/veryl#1166) --- crates/analyzer/src/analyzer_error.rs | 27 ++++++++ .../analyzer/src/handlers/create_reference.rs | 62 +++++++++++++++++-- crates/analyzer/src/symbol.rs | 11 ++++ crates/analyzer/src/tests.rs | 61 ++++++++++++++++++ .../map/testcases/sv/19_import_export.sv.map | 2 +- .../map/testcases/sv/37_package_ref.sv.map | 2 +- .../map/testcases/sv/44_import_resolve.sv.map | 2 +- .../testcases/sv/56_generic_interface.sv.map | 2 +- .../testcases/sv/57_generic_package.sv.map | 2 +- .../map/testcases/sv/58_generic_struct.sv.map | 2 +- testcases/sv/19_import_export.sv | 12 ++-- testcases/sv/37_package_ref.sv | 17 ++--- testcases/sv/44_import_resolve.sv | 16 ++--- testcases/sv/56_generic_interface.sv | 16 ++--- testcases/sv/57_generic_package.sv | 26 ++++---- testcases/sv/58_generic_struct.sv | 10 +-- testcases/veryl/19_import_export.veryl | 8 +-- testcases/veryl/37_package_ref.veryl | 11 ++-- testcases/veryl/44_import_resolve.veryl | 16 ++--- testcases/veryl/56_generic_interface.veryl | 16 ++--- testcases/veryl/57_generic_package.veryl | 26 ++++---- testcases/veryl/58_generic_struct.veryl | 10 +-- 22 files changed, 256 insertions(+), 101 deletions(-) diff --git a/crates/analyzer/src/analyzer_error.rs b/crates/analyzer/src/analyzer_error.rs index b7f2cae4..6524a36c 100644 --- a/crates/analyzer/src/analyzer_error.rs +++ b/crates/analyzer/src/analyzer_error.rs @@ -758,6 +758,21 @@ pub enum AnalyzerError { error_location: SourceSpan, }, + #[diagnostic( + severity(Error), + code(referring_package_before_definition), + help("change order of package definitions"), + url("") + )] + #[error("pakcakge {identifier} is referred before it is defined.")] + ReferringPackageBeforeDefinition { + identifier: String, + #[source_code] + input: NamedSource, + #[label("Error location")] + error_location: SourceSpan, + }, + #[diagnostic( severity(Error), code(unresolvable_generic_argument), @@ -1569,6 +1584,18 @@ impl AnalyzerError { } } + pub fn referring_package_before_definition( + identifier: &str, + source: &str, + token: &TokenRange, + ) -> Self { + AnalyzerError::ReferringPackageBeforeDefinition { + identifier: identifier.to_string(), + input: AnalyzerError::named_source(source, token), + error_location: token.into(), + } + } + pub fn unresolvable_generic_argument( identifier: &str, source: &str, diff --git a/crates/analyzer/src/handlers/create_reference.rs b/crates/analyzer/src/handlers/create_reference.rs index d660c511..48e241d8 100644 --- a/crates/analyzer/src/handlers/create_reference.rs +++ b/crates/analyzer/src/handlers/create_reference.rs @@ -10,7 +10,7 @@ use crate::type_dag::{self, Context, DagError}; use std::collections::HashMap; use veryl_parser::resource_table; use veryl_parser::veryl_grammar_trait::*; -use veryl_parser::veryl_token::{is_anonymous_text, Token, TokenRange}; +use veryl_parser::veryl_token::{is_anonymous_text, Token, TokenRange, TokenSource}; use veryl_parser::veryl_walker::{Handler, HandlerPoint}; use veryl_parser::ParolError; @@ -20,6 +20,7 @@ pub struct CreateReference<'a> { text: &'a str, point: HandlerPoint, inst_ports: Vec, + definition_token: Option, inst_sv_module: bool, is_anonymous_identifier: bool, port_direction: Option, @@ -107,6 +108,10 @@ impl<'a> CreateReference<'a> { match symbol_table::resolve((&base_path, namespace)) { Ok(symbol) => { + if (i + 1) == path.len() { + self.check_pacakge_reference(self.definition_token, &symbol.found); + } + symbol_table::add_reference(symbol.found.id, &path.paths[0].base); // Check number of arguments @@ -181,6 +186,39 @@ impl<'a> CreateReference<'a> { } } + fn check_pacakge_reference(&mut self, base_token: Option, symbol: &Symbol) { + if base_token.is_none() { + return; + } + + let package_symbol = symbol + .get_ancestors() + .into_iter() + .find(|x| matches!(x.kind, SymbolKind::Package(_))); + if package_symbol.is_none() { + return; + } + + let base_token = base_token.unwrap(); + let package_token = package_symbol.unwrap().token; + if let (TokenSource::File(package_file), TokenSource::File(base_file)) = + (package_token.source, base_token.source) + { + let referecne_before_definition = package_file == base_file + && (package_token.line > base_token.line + || package_token.line == base_token.line + && package_token.column > base_token.column); + if referecne_before_definition { + self.errors + .push(AnalyzerError::referring_package_before_definition( + &package_token.to_string(), + self.text, + &package_token.into(), + )); + } + } + } + fn insert_declaration_dag_node(&mut self, symbol: &Symbol) -> Option { if let Some(child) = self.insert_dag_node(symbol) { if let Some(parent) = self.dag_scope_parent.last().cloned() { @@ -599,9 +637,13 @@ impl VerylGrammarTrait for CreateReference<'_> { match self.point { HandlerPoint::Before => { let symbol = symbol_table::resolve(arg.identifier.as_ref()).unwrap(); + self.definition_token = Some(symbol.found.token); self.insert_scope_declaration_dag_node(&symbol.found, Context::Module); } - HandlerPoint::After => self.pop_scope_dag(), + HandlerPoint::After => { + self.definition_token = None; + self.pop_scope_dag(); + } } Ok(()) } @@ -610,9 +652,13 @@ impl VerylGrammarTrait for CreateReference<'_> { match self.point { HandlerPoint::Before => { let symbol = symbol_table::resolve(arg.identifier.as_ref()).unwrap(); + self.definition_token = Some(symbol.found.token); self.insert_scope_declaration_dag_node(&symbol.found, Context::Interface); } - HandlerPoint::After => self.pop_scope_dag(), + HandlerPoint::After => { + self.definition_token = None; + self.pop_scope_dag(); + } } Ok(()) } @@ -621,9 +667,13 @@ impl VerylGrammarTrait for CreateReference<'_> { match self.point { HandlerPoint::Before => { let symbol = symbol_table::resolve(arg.identifier.as_ref()).unwrap(); + self.definition_token = Some(symbol.found.token); self.insert_scope_declaration_dag_node(&symbol.found, Context::Package); } - HandlerPoint::After => self.pop_scope_dag(), + HandlerPoint::After => { + self.definition_token = None; + self.pop_scope_dag(); + } } Ok(()) } @@ -638,6 +688,10 @@ impl VerylGrammarTrait for CreateReference<'_> { if let Ok(symbol) = symbol_table::resolve( x.import_declaration.scoped_identifier.as_ref(), ) { + self.check_pacakge_reference( + Some(x.import_declaration.import.import_token.token), + &symbol.found, + ); if let Some(child) = self.insert_dag_node(&symbol.found) { self.dag_file_imports.push(child); } diff --git a/crates/analyzer/src/symbol.rs b/crates/analyzer/src/symbol.rs index 7307d2cc..c2afedd5 100644 --- a/crates/analyzer/src/symbol.rs +++ b/crates/analyzer/src/symbol.rs @@ -113,6 +113,17 @@ impl Symbol { None } + pub fn get_ancestors(&self) -> Vec { + let mut ancestors = Vec::new(); + + ancestors.push(self.clone()); + if let Some(parent) = self.get_parent() { + ancestors.append(&mut parent.get_ancestors()); + } + + ancestors + } + pub fn evaluate(&self) -> Evaluated { if let Some(evaluated) = self.evaluated.get() { evaluated diff --git a/crates/analyzer/src/tests.rs b/crates/analyzer/src/tests.rs index 5fca668c..f6bc029b 100644 --- a/crates/analyzer/src/tests.rs +++ b/crates/analyzer/src/tests.rs @@ -1758,6 +1758,67 @@ fn undefined_identifier() { )); } +#[test] +fn referring_package_before_definition() { + let code = r#" + module ModuleA { + const A: u32 = PakcageB::B; + } + package PakcageB { + const B: u32 = 0; + } + "#; + + let errors = analyze(code); + assert!(matches!( + errors[0], + AnalyzerError::ReferringPackageBeforeDefinition { .. } + )); + + let code = r#" + interface InterfaceA { + const A: u32 = PakcageB::B; + } + package PakcageB { + const B: u32 = 0; + } + "#; + + let errors = analyze(code); + assert!(matches!( + errors[0], + AnalyzerError::ReferringPackageBeforeDefinition { .. } + )); + + let code = r#" + package PackageA { + const A: u32 = PakcageB::B; + } + package PakcageB { + const B: u32 = 0; + } + "#; + + let errors = analyze(code); + assert!(matches!( + errors[0], + AnalyzerError::ReferringPackageBeforeDefinition { .. } + )); + + let code = r#" + import PakcageB::B; + package PakcageB { + const B: u32 = 0; + } + "#; + + let errors = analyze(code); + assert!(matches!( + errors[0], + AnalyzerError::ReferringPackageBeforeDefinition { .. } + )); +} + #[test] fn unknown_attribute() { let code = r#" diff --git a/testcases/map/testcases/sv/19_import_export.sv.map b/testcases/map/testcases/sv/19_import_export.sv.map index 751a2be7..8fec0ca8 100644 --- a/testcases/map/testcases/sv/19_import_export.sv.map +++ b/testcases/map/testcases/sv/19_import_export.sv.map @@ -1 +1 @@ -{"version":3,"file":"19_import_export.sv.map","sources":["../../../veryl/19_import_export.veryl"],"names":["","module","Module19",";","import","veryl_testcase_PackageA::A","veryl_testcase_PackageA","::","*","endmodule","interface","Interface19","endinterface","package","Package19","export","A","*::*","endpackage","PackageA","localparam","int unsigned","=","0"],"mappings":"AAAAA;;;AAGAC,sBAAOC;;;AAASC;IACZC,OAAOC,0BAAWF;IAClBC,OAAOE,uBAAQC,EAAEC,CAACL;AACtBM;;AAEAC,yBAAUC;;;AAAYR;IAClBC,OAAOC,0BAAWF;IAClBC,OAAOE,uBAAQC,EAAEC,CAACL;AACtBS;;AAEAC,uBAAQC,SAAUX;;;IACdC,OAAOC,0BAAWF;IAClBC,OAAOE,uBAAQC,EAAEC,CAACL;IAClBY,OAAOC,CAAWb;IAClBY,OAAOE,IAACd;AACZe;;AAEAL,uBAAQM,QAAShB;;;IACbiB,WAASC,aAAHL,EAAOM,EAAEC,CAACpB;AACpBe"} \ No newline at end of file +{"version":3,"file":"19_import_export.sv.map","sources":["../../../veryl/19_import_export.veryl"],"names":["","package","PackageA",";","localparam","int unsigned","A","=","0","endpackage","module","Module19","import","veryl_testcase_PackageA::A","veryl_testcase_PackageA","::","*","endmodule","interface","Interface19","endinterface","Package19","export","*::*"],"mappings":"AAAAA;;;AAGAC,uBAAQC,QAASC;;;IACbC,WAASC,aAAHC,EAAOC,EAAEC,CAACL;AACpBM;;AAEAC,sBAAOC;;;AAASR;IACZS,OAAOC,0BAAWV;IAClBS,OAAOE,uBAAQC,EAAEC,CAACb;AACtBc;;AAEAC,yBAAUC;;;AAAYhB;IAClBS,OAAOC,0BAAWV;IAClBS,OAAOE,uBAAQC,EAAEC,CAACb;AACtBiB;;AAEAnB,uBAAQoB,SAAUlB;;;IACdS,OAAOC,0BAAWV;IAClBS,OAAOE,uBAAQC,EAAEC,CAACb;IAClBmB,OAAOhB,CAAWH;IAClBmB,OAAOC,IAACpB;AACZM"} \ No newline at end of file diff --git a/testcases/map/testcases/sv/37_package_ref.sv.map b/testcases/map/testcases/sv/37_package_ref.sv.map index f39329fc..2ce91da7 100644 --- a/testcases/map/testcases/sv/37_package_ref.sv.map +++ b/testcases/map/testcases/sv/37_package_ref.sv.map @@ -1 +1 @@ -{"version":3,"file":"37_package_ref.sv.map","sources":["../../../veryl/37_package_ref.veryl"],"names":["","module","Module37",";","int unsigned","_a","=","veryl_testcase_Package37::A","_b","veryl_testcase_Package37::B_C","_c","veryl_testcase_Package37::X","(",")","endmodule","package","Package37","localparam","A","1","typedef enum","logic","{","B_C","B","function","X","return","0","endfunction","endpackage"],"mappings":"AAAAA,AAAAC,sBAAOC,QAASC;IACJC,aAAJC;mBAAQC,EAAEC,2BAAYJ;IAClBC,aAAJI;mBAAQF,EAAEG,6BAAeN;IACrBC,aAAJM;mBAAQJ,EAAEK,2BAAYC,CAACC,CAACV;AAChCW;AACAC,uBAAQC,SAAUb;IACdc,WAASb,aAAHc,EAAOZ,EAAEa,CAAChB;;IAEhBiB,aAAQC,MAAMC;QACVC,GAACvB;MADAwB,EAELxB;;IAEAyB,mBAAcrB,aAALsB,CAAE1B,CAAOA;QACd2B,OAAOC,CAACzB;IACZ0B;AACJC"} \ No newline at end of file +{"version":3,"file":"37_package_ref.sv.map","sources":["../../../veryl/37_package_ref.veryl"],"names":["","package","Package37",";","localparam","int unsigned","A","=","1","typedef enum","logic","{","B_C","B","function","X","return","0","endfunction","endpackage","module","Module37","_a","veryl_testcase_Package37::A","_b","veryl_testcase_Package37::B_C","_c","veryl_testcase_Package37::X","(",")","endmodule"],"mappings":"AAAAA,AAAAC,uBAAQC,SAAUC;IACdC,WAASC,aAAHC,EAAOC,EAAEC,CAACL;;IAEhBM,aAAQC,MAAMC;QACVC,GAACZ;MADAa,EAELb;;IAEAc,mBAAcT,aAALU,CAAEf,CAAOA;QACdgB,OAAOC,CAACd;IACZe;AACJC;;AAEAC,sBAAOC,QAASlB;IACJE,aAAJiB;mBAAQf,EAAEgB,2BAAYpB;IAClBE,aAAJmB;mBAAQjB,EAAEkB,6BAAetB;IACrBE,aAAJqB;mBAAQnB,EAAEoB,2BAAYC,CAACC,CAAC1B;AAChC2B"} \ No newline at end of file diff --git a/testcases/map/testcases/sv/44_import_resolve.sv.map b/testcases/map/testcases/sv/44_import_resolve.sv.map index 8059861e..04ccb547 100644 --- a/testcases/map/testcases/sv/44_import_resolve.sv.map +++ b/testcases/map/testcases/sv/44_import_resolve.sv.map @@ -1 +1 @@ -{"version":3,"file":"44_import_resolve.sv.map","sources":["../../../veryl/44_import_resolve.veryl"],"names":["","module","Module44",";","logic","[","10","]","a","b","c","import","veryl_testcase_Package44A::z","veryl_testcase_Package44B","::","*","always_comb","=","z","y","endmodule","package","Package44A","localparam","int unsigned","0","endpackage","Package44B"],"mappings":"AAAAA,AAAAC,sBAAOC,QAASC;IACLC,MAAKC,CAACC,MAAEC,EAAXC,CAAYL;IACTC,MAAKC,CAACC,MAAEC,EAAXE,CAAYN;IACTC,MAAKC,CAACC,MAAEC,EAAXG,CAAYP;;IAEhBQ,OAAOC,4BAAaT;IACpBQ,OAAOE,yBAAUC,EAAEC,CAACZ;;IAEpBa,YAAOR,EAAES,EAAEC,CAAaf;IACxBa,YAAOP,EAAEQ,EAAEC,CAACf;IACZa,YAAON,EAAEO,EAAEE,CAAChB;AAChBiB;;AAEAC,uBAAQC,UAAWnB;IACfoB,WAASC,aAAHN,EAAOD,EAAEQ,CAACtB;AACpBuB;;AAEAL,uBAAQM,UAAWxB;IACfoB,WAASC,aAAHL,EAAOF,EAAEQ,CAACtB;AACpBuB"} \ No newline at end of file +{"version":3,"file":"44_import_resolve.sv.map","sources":["../../../veryl/44_import_resolve.veryl"],"names":["","package","Package44A",";","localparam","int unsigned","z","=","0","endpackage","Package44B","y","module","Module44","logic","[","10","]","a","b","c","import","veryl_testcase_Package44A::z","veryl_testcase_Package44B","::","*","always_comb","endmodule"],"mappings":"AAAAA,AAAAC,uBAAQC,UAAWC;IACfC,WAASC,aAAHC,EAAOC,EAAEC,CAACL;AACpBM;;AAEAR,uBAAQS,UAAWP;IACfC,WAASC,aAAHM,EAAOJ,EAAEC,CAACL;AACpBM;;AAEAG,sBAAOC,QAASV;IACLW,MAAKC,CAACC,MAAEC,EAAXC,CAAYf;IACTW,MAAKC,CAACC,MAAEC,EAAXE,CAAYhB;IACTW,MAAKC,CAACC,MAAEC,EAAXG,CAAYjB;;IAEhBkB,OAAOC,4BAAanB;IACpBkB,OAAOE,yBAAUC,EAAEC,CAACtB;;IAEpBuB,YAAOR,EAAEX,EAAED,CAAaH;IACxBuB,YAAOP,EAAEZ,EAAED,CAACH;IACZuB,YAAON,EAAEb,EAAEI,CAACR;AAChBwB"} \ No newline at end of file diff --git a/testcases/map/testcases/sv/56_generic_interface.sv.map b/testcases/map/testcases/sv/56_generic_interface.sv.map index 0d4e5b5a..f72f3a7a 100644 --- a/testcases/map/testcases/sv/56_generic_interface.sv.map +++ b/testcases/map/testcases/sv/56_generic_interface.sv.map @@ -1 +1 @@ -{"version":3,"file":"56_generic_interface.sv.map","sources":["../../../veryl/56_generic_interface.veryl"],"names":["","module","Module56",";","import","veryl_testcase_Package56A::X","veryl_testcase___Interface56A__Package56A_X","u0","veryl_testcase___Interface56A__Package56B_X","u1","veryl_testcase___Interface56B__Package56A_X","u2","u3","veryl_testcase___Interface56B__3","u4","u5","veryl_testcase___Module56Sub__1","u6","logic","_a","=",".","_b","_c","endmodule","veryl_testcase___Interface56A__1","u","function","f","(",")","endfunction","interface","[","]","endinterface","veryl_testcase_Package56B::X","1","3","package","Package56A","localparam","int unsigned","X","endpackage","Package56B","2"],"mappings":"AAAAA,AAAAC,sBAAOC,QAASC;IACZC,OAAOC,4BAAaF;IACpBH,AAASM,4CAAJC,KAAiCJ;IACtCH,AAASQ,4CAAJC,KAAiCN;IACtCH,AAASU,4CAAJC,KAAiCR;IACtCH,AAASU,4CAAJE,KAAiCT;IACtCH,AAASa,iCAAJC,KAAoBX;IACzBH,AAASU,4CAAJK,KAAqBZ;IAC1BH,AAASgB,gCAAJC,KAAoBd;;IAEjBe,MAAJC;mBAAUC,EAAEb,EAAEc,CAACF,EAAEhB;IACbe,MAAJI;mBAAUF,EAAET,EAAEU,CAACC,EAAEnB;IACbe,MAAJK;mBAAUH,EAAEL,EAAEM,CAACC,EAAEnB;AACzBqB;;AAEAvB,sCAA+BE;IAC3BH,AAAQyB,iCAAHC,IAAoBvB;IACzBwB,wBAASC,CAAEC,CAACC,GAAE9B;IAAC+B;AACnBP;;;AAGIQ,qDAAmC7B;IAC3Be,MAAKe,CAAC5B,gCAAC6B,6BAAXf,EAAYhB;AACpBgC;;;AAFIH,qDAAmC7B;IAC3Be,MAAKe,CAACG,gCAACF,6BAAXf,EAAYhB;AACpBgC;;;AAFIH,0CAAmC7B;IAC3Be,MAAKe,CAACI,KAACH,6BAAXf,EAAYhB;AACpBgC;;;AAGIH,qDAAuC7B;IAC/Be,MAAKe,CAAC5B,gCAAC6B,6BAAXZ,EAAYnB;AACpBgC;AAFIH,0CAAuC7B;IAC/Be,MAAKe,CAACK,KAACJ,6BAAXZ,EAAYnB;AACpBgC;;AAEAI,uBAAQC,UAAWrC;IACfsC,WAASC,aAAHC,EAAOvB,EAAEiB,CAAClC;AACpByC;;AAEAL,uBAAQM,UAAW1C;IACfsC,WAASC,aAAHC,EAAOvB,EAAE0B,CAAC3C;AACpByC"} \ No newline at end of file +{"version":3,"file":"56_generic_interface.sv.map","sources":["../../../veryl/56_generic_interface.veryl"],"names":["","package","Package56A",";","localparam","int unsigned","X","=","1","endpackage","Package56B","2","module","Module56","import","veryl_testcase_Package56A::X","veryl_testcase___Interface56A__Package56A_X","u0","veryl_testcase___Interface56A__Package56B_X","u1","veryl_testcase___Interface56B__Package56A_X","u2","u3","veryl_testcase___Interface56B__3","u4","u5","veryl_testcase___Module56Sub__1","u6","logic","_a",".","_b","_c","endmodule","veryl_testcase___Interface56A__1","u","function","f","(",")","endfunction","interface","[","]","endinterface","veryl_testcase_Package56B::X","3"],"mappings":"AAAAA,AAAAC,uBAAQC,UAAWC;IACfC,WAASC,aAAHC,EAAOC,EAAEC,CAACL;AACpBM;;AAEAR,uBAAQS,UAAWP;IACfC,WAASC,aAAHC,EAAOC,EAAEI,CAACR;AACpBM;;AAEAG,sBAAOC,QAASV;IACZW,OAAOC,4BAAaZ;IACpBH,AAASgB,4CAAJC,KAAiCd;IACtCH,AAASkB,4CAAJC,KAAiChB;IACtCH,AAASoB,4CAAJC,KAAiClB;IACtCH,AAASoB,4CAAJE,KAAiCnB;IACtCH,AAASuB,iCAAJC,KAAoBrB;IACzBH,AAASoB,4CAAJK,KAAqBtB;IAC1BH,AAAS0B,gCAAJC,KAAoBxB;;IAEjByB,MAAJC;mBAAUtB,EAAEU,EAAEa,CAACD,EAAE1B;IACbyB,MAAJG;mBAAUxB,EAAEc,EAAES,CAACC,EAAE5B;IACbyB,MAAJI;mBAAUzB,EAAEkB,EAAEK,CAACC,EAAE5B;AACzB8B;;AAEArB,sCAA+BT;IAC3BH,AAAQkC,iCAAHC,IAAoBhC;IACzBiC,wBAASC,CAAEC,CAACC,GAAEvC;IAACwC;AACnBP;;;AAGIQ,qDAAmCtC;IAC3ByB,MAAKc,CAAC3B,gCAAC4B,6BAAXd,EAAY1B;AACpByC;;;AAFIH,qDAAmCtC;IAC3ByB,MAAKc,CAACG,gCAACF,6BAAXd,EAAY1B;AACpByC;;;AAFIH,0CAAmCtC;IAC3ByB,MAAKc,CAAClC,KAACmC,6BAAXd,EAAY1B;AACpByC;;;AAGIH,qDAAuCtC;IAC/ByB,MAAKc,CAAC3B,gCAAC4B,6BAAXZ,EAAY5B;AACpByC;AAFIH,0CAAuCtC;IAC/ByB,MAAKc,CAACI,KAACH,6BAAXZ,EAAY5B;AACpByC"} \ No newline at end of file diff --git a/testcases/map/testcases/sv/57_generic_package.sv.map b/testcases/map/testcases/sv/57_generic_package.sv.map index b326875a..cfc60c9d 100644 --- a/testcases/map/testcases/sv/57_generic_package.sv.map +++ b/testcases/map/testcases/sv/57_generic_package.sv.map @@ -1 +1 @@ -{"version":3,"file":"57_generic_package.sv.map","sources":["../../../veryl/57_generic_package.veryl"],"names":["","module","Module57",";","import","veryl_testcase_Package57D::Y","localparam","int unsigned","A","=","veryl_testcase___Package57A__1::X","longint unsigned","B","veryl_testcase___Package57A__2::X","C","veryl_testcase___Package57B__3::X","E","D","veryl_testcase___Package57B__4::X","F","veryl_testcase___Package57B__Package57D_Y::X","veryl_testcase___Package57C__2::StructC","_e","always_comb",".","c","1","endmodule","package","X","endpackage","2","3","4","typedef struct packed","{","logic","[","]","StructC","Package57D","Y"],"mappings":"AAAAA,AAAAC,sBAAOC,QAASC;IACZC,OAAOC,4BAAaF;IACpBG,WAASC,iBAAHC,EAAOC,EAAEC,iCAAkBP;IACjCG,WAASK,iBAAHC,EAAOH,EAAEI,iCAAkBV;IACjCG,WAASC,iBAAHO,EAAOL,EAAEM,iCAAkBZ;IACjCG,WAASC,iBAAHS,EAAOP,EAAEM,iCAAkBZ;IACjCG,WAASK,iBAAHM,EAAOR,EAAES,iCAAiBf;IAChCG,WAASK,iBAAHQ,EAAOV,EAAEW,4CAAkBjB;;IAEvBkB,wCAANC,IAA8BnB;IAClCoB,YAAOD,EAAEE,CAACC,EAAEhB,EAAEiB,CAACvB;AACnBwB;;;AAGIC,sCAA+BzB;IAC/BG,WAASC,aAAHsB,EAAOpB,EAAEiB,CAACvB;AACpB2B;;;AAFIF,sCAA+BzB;IAC/BG,WAASC,aAAHsB,EAAOpB,EAAEsB,CAAC5B;AACpB2B;;;AAGIF,sCAAmCzB;IACnCG,WAASC,aAAHsB,EAAOpB,EAAEuB,CAAC7B;AACpB2B;AAFIF,sCAAmCzB;IACnCG,WAASC,aAAHsB,EAAOpB,EAAEwB,CAAC9B;AACpB2B;AAFIF,iDAAmCzB;IACnCG,WAASC,aAAHsB,EAAOpB,EAAEJ,4BAACF;AACpB2B;;AAEAF,sCAA+BzB;IAC3B+B,sBAAeC;QACRC,MAAKC,CAACN,KAACO,EAAVb,CAAWtB;MADRoC,QAEPvC;AACJ8B;;AAEAF,uBAAQY,UAAWrC;IACfG,WAASC,aAAHkC,EAAOhC,EAAEiB,CAACvB;AACpB2B"} \ No newline at end of file +{"version":3,"file":"57_generic_package.sv.map","sources":["../../../veryl/57_generic_package.veryl"],"names":["","package",";","localparam","int unsigned","X","=","1","endpackage","2","3","4","veryl_testcase_Package57D::Y","typedef struct packed","{","logic","[","]","c","StructC","Package57D","Y","module","Module57","import","A","veryl_testcase___Package57A__1::X","longint unsigned","B","veryl_testcase___Package57A__2::X","C","veryl_testcase___Package57B__3::X","E","D","veryl_testcase___Package57B__4::X","F","veryl_testcase___Package57B__Package57D_Y::X","veryl_testcase___Package57C__2::StructC","_e","always_comb",".","endmodule"],"mappings":"AAAAA;AACIC,sCAA+BC;IAC/BC,WAASC,aAAHC,EAAOC,EAAEC,CAACL;AACpBM;;;AAFIP,sCAA+BC;IAC/BC,WAASC,aAAHC,EAAOC,EAAEG,CAACP;AACpBM;;;AAGIP,sCAAmCC;IACnCC,WAASC,aAAHC,EAAOC,EAAEI,CAACR;AACpBM;AAFIP,sCAAmCC;IACnCC,WAASC,aAAHC,EAAOC,EAAEK,CAACT;AACpBM;AAFIP,iDAAmCC;IACnCC,WAASC,aAAHC,EAAOC,EAAEM,4BAACV;AACpBM;;AAEAP,sCAA+BC;IAC3BW,sBAAeC;QACRC,MAAKC,CAACP,KAACQ,EAAVC,CAAWhB;MADRiB,QAEPnB;AACJQ;;AAEAP,uBAAQmB,UAAWlB;IACfC,WAASC,aAAHiB,EAAOf,EAAEC,CAACL;AACpBM;;AAEAc,sBAAOC,QAASrB;IACZsB,OAAOZ,4BAAaV;IACpBC,WAASC,iBAAHqB,EAAOnB,EAAEoB,iCAAkBxB;IACjCC,WAASwB,iBAAHC,EAAOtB,EAAEuB,iCAAkB3B;IACjCC,WAASC,iBAAH0B,EAAOxB,EAAEyB,iCAAkB7B;IACjCC,WAASC,iBAAH4B,EAAO1B,EAAEyB,iCAAkB7B;IACjCC,WAASwB,iBAAHM,EAAO3B,EAAE4B,iCAAiBhC;IAChCC,WAASwB,iBAAHQ,EAAO7B,EAAE8B,4CAAkBlC;;IAEvBmC,wCAANC,IAA8BpC;IAClCqC,YAAOD,EAAEE,CAACtB,EAAEZ,EAAEC,CAACL;AACnBuC"} \ No newline at end of file diff --git a/testcases/map/testcases/sv/58_generic_struct.sv.map b/testcases/map/testcases/sv/58_generic_struct.sv.map index aff638ed..946ae6a9 100644 --- a/testcases/map/testcases/sv/58_generic_struct.sv.map +++ b/testcases/map/testcases/sv/58_generic_struct.sv.map @@ -1 +1 @@ -{"version":3,"file":"58_generic_struct.sv.map","sources":["../../../veryl/58_generic_struct.veryl"],"names":["","module","Module58",";","typedef struct packed","{","veryl_testcase_Package58::B","A","veryl_testcase_Package58::C","C","typedef","int signed","B","__StructA__Package58_B","_a","__StructA__Package58_C","_b","__StructA__C","_c","__StructB__Package58_C","_d","_f","__StructB__C","_e","__StructC__C__C","_g","endmodule","package","Package58","int unsigned","longint unsigned","endpackage"],"mappings":"AAAAA,AAAAC,sBAAOC,QAASC;IACZC,sBAA0BC;QACnBC,4BAAHC,CAAIJ;6BACRH;IAFAI,sBAA0BC;QACnBG,4BAAHD,CAAIJ;6BACRH;IAFAI,sBAA0BC;QACnBI,4BAAHF,CAAIJ;mBACRH;;IAEAU,QAASC,WAAJF,CAAON;;IAEZC,sBAA8BC;QACvBG,4BAAHI,CAAIT;6BACRH;IAFAI,sBAA8BC;QACvBI,4BAAHG,CAAIT;mBACRH;;IAEAI,sBAAmCC;QAC5BI,EAAHG,CAAIT;QACDM,EAAHA,CAAIN;sBACRH;;IAEQa,uBAAJC,EAA2BX;IACvBY,uBAAJC,EAA2Bb;IACvBc,uBAAJC,EAA2Bf;IACvBgB,uBAAJC,EAA2BjB;IACvBgB,uBAAJE,EAA2BlB;IACvBmB,uBAAJC,EAA2BpB;IACvBqB,uBAAJC,EAA2BtB;AACnCuB;;AAEAC,uBAAQC,SAAUzB;IACdO,QAASmB,iBAAJjB,CAAOT;IACZO,QAASoB,iBAAJrB,CAAON;AAChB4B"} \ No newline at end of file +{"version":3,"file":"58_generic_struct.sv.map","sources":["../../../veryl/58_generic_struct.veryl"],"names":["","package","Package58",";","typedef","int unsigned","B","longint unsigned","C","endpackage","module","Module58","typedef struct packed","{","veryl_testcase_Package58::B","A","veryl_testcase_Package58::C","int signed","__StructA__Package58_B","_a","__StructA__Package58_C","_b","__StructA__C","_c","__StructB__Package58_C","_d","_f","__StructB__C","_e","__StructC__C__C","_g","endmodule"],"mappings":"AAAAA,AAAAC,uBAAQC,SAAUC;IACdC,QAASC,iBAAJC,CAAOH;IACZC,QAASG,iBAAJC,CAAOL;AAChBM;;AAEAC,sBAAOC,QAASR;IACZS,sBAA0BC;QACnBC,4BAAHC,CAAIZ;6BACRH;IAFAY,sBAA0BC;QACnBG,4BAAHD,CAAIZ;6BACRH;IAFAY,sBAA0BC;QACnBL,4BAAHO,CAAIZ;mBACRH;;IAEAI,QAASa,WAAJT,CAAOL;;IAEZS,sBAA8BC;QACvBG,4BAAHV,CAAIH;6BACRH;IAFAY,sBAA8BC;QACvBL,4BAAHF,CAAIH;mBACRH;;IAEAY,sBAAmCC;QAC5BL,EAAHF,CAAIH;QACDK,EAAHA,CAAIL;sBACRH;;IAEQkB,uBAAJC,EAA2BhB;IACvBiB,uBAAJC,EAA2BlB;IACvBmB,uBAAJC,EAA2BpB;IACvBqB,uBAAJC,EAA2BtB;IACvBqB,uBAAJE,EAA2BvB;IACvBwB,uBAAJC,EAA2BzB;IACvB0B,uBAAJC,EAA2B3B;AACnC4B"} \ No newline at end of file diff --git a/testcases/sv/19_import_export.sv b/testcases/sv/19_import_export.sv index 0eebbdf0..f705fc95 100644 --- a/testcases/sv/19_import_export.sv +++ b/testcases/sv/19_import_export.sv @@ -1,6 +1,12 @@ +package veryl_testcase_PackageA; + import PackageA::A; + import PackageA::*; + localparam int unsigned A = 0; +endpackage + module veryl_testcase_Module19 import PackageA::A; import PackageA::*; @@ -25,10 +31,4 @@ package veryl_testcase_Package19; export A; export *::*; endpackage - -package veryl_testcase_PackageA; - import PackageA::A; - import PackageA::*; - localparam int unsigned A = 0; -endpackage //# sourceMappingURL=../map/testcases/sv/19_import_export.sv.map diff --git a/testcases/sv/37_package_ref.sv b/testcases/sv/37_package_ref.sv index 85182648..7a5f06e1 100644 --- a/testcases/sv/37_package_ref.sv +++ b/testcases/sv/37_package_ref.sv @@ -1,11 +1,3 @@ -module veryl_testcase_Module37; - int unsigned _a; - always_comb _a = veryl_testcase_Package37::A; - int unsigned _b; - always_comb _b = veryl_testcase_Package37::B_C; - int unsigned _c; - always_comb _c = veryl_testcase_Package37::X(); -endmodule package veryl_testcase_Package37; localparam int unsigned A = 1; @@ -17,4 +9,13 @@ package veryl_testcase_Package37; return 0; endfunction endpackage + +module veryl_testcase_Module37; + int unsigned _a; + always_comb _a = veryl_testcase_Package37::A; + int unsigned _b; + always_comb _b = veryl_testcase_Package37::B_C; + int unsigned _c; + always_comb _c = veryl_testcase_Package37::X(); +endmodule //# sourceMappingURL=../map/testcases/sv/37_package_ref.sv.map diff --git a/testcases/sv/44_import_resolve.sv b/testcases/sv/44_import_resolve.sv index c322fa32..2a12094c 100644 --- a/testcases/sv/44_import_resolve.sv +++ b/testcases/sv/44_import_resolve.sv @@ -1,3 +1,11 @@ +package veryl_testcase_Package44A; + localparam int unsigned z = 0; +endpackage + +package veryl_testcase_Package44B; + localparam int unsigned y = 0; +endpackage + module veryl_testcase_Module44; logic [10-1:0] a; logic [10-1:0] b; @@ -10,12 +18,4 @@ module veryl_testcase_Module44; always_comb b = z; always_comb c = y; endmodule - -package veryl_testcase_Package44A; - localparam int unsigned z = 0; -endpackage - -package veryl_testcase_Package44B; - localparam int unsigned y = 0; -endpackage //# sourceMappingURL=../map/testcases/sv/44_import_resolve.sv.map diff --git a/testcases/sv/56_generic_interface.sv b/testcases/sv/56_generic_interface.sv index 4abac69d..ff6be25e 100644 --- a/testcases/sv/56_generic_interface.sv +++ b/testcases/sv/56_generic_interface.sv @@ -1,3 +1,11 @@ +package veryl_testcase_Package56A; + localparam int unsigned X = 1; +endpackage + +package veryl_testcase_Package56B; + localparam int unsigned X = 2; +endpackage + module veryl_testcase_Module56; import veryl_testcase_Package56A::X; veryl_testcase___Interface56A__Package56A_X u0 (); @@ -44,12 +52,4 @@ endinterface interface veryl_testcase___Interface56B__3; logic [3-1:0] _b; endinterface - -package veryl_testcase_Package56A; - localparam int unsigned X = 1; -endpackage - -package veryl_testcase_Package56B; - localparam int unsigned X = 2; -endpackage //# sourceMappingURL=../map/testcases/sv/56_generic_interface.sv.map diff --git a/testcases/sv/57_generic_package.sv b/testcases/sv/57_generic_package.sv index 8f31b6e5..47012f3a 100644 --- a/testcases/sv/57_generic_package.sv +++ b/testcases/sv/57_generic_package.sv @@ -1,16 +1,3 @@ -module veryl_testcase_Module57; - import veryl_testcase_Package57D::Y; - localparam int unsigned A = veryl_testcase___Package57A__1::X; - localparam longint unsigned B = veryl_testcase___Package57A__2::X; - localparam int unsigned C = veryl_testcase___Package57B__3::X; - localparam int unsigned E = veryl_testcase___Package57B__3::X; - localparam longint unsigned D = veryl_testcase___Package57B__4::X; - localparam longint unsigned F = veryl_testcase___Package57B__Package57D_Y::X; - - veryl_testcase___Package57C__2::StructC _e ; - always_comb _e.c = 1; -endmodule - /// Generic package test for doc comment package veryl_testcase___Package57A__1; localparam int unsigned X = 1; @@ -41,4 +28,17 @@ endpackage package veryl_testcase_Package57D; localparam int unsigned Y = 1; endpackage + +module veryl_testcase_Module57; + import veryl_testcase_Package57D::Y; + localparam int unsigned A = veryl_testcase___Package57A__1::X; + localparam longint unsigned B = veryl_testcase___Package57A__2::X; + localparam int unsigned C = veryl_testcase___Package57B__3::X; + localparam int unsigned E = veryl_testcase___Package57B__3::X; + localparam longint unsigned D = veryl_testcase___Package57B__4::X; + localparam longint unsigned F = veryl_testcase___Package57B__Package57D_Y::X; + + veryl_testcase___Package57C__2::StructC _e ; + always_comb _e.c = 1; +endmodule //# sourceMappingURL=../map/testcases/sv/57_generic_package.sv.map diff --git a/testcases/sv/58_generic_struct.sv b/testcases/sv/58_generic_struct.sv index 0b11cbf5..2b990363 100644 --- a/testcases/sv/58_generic_struct.sv +++ b/testcases/sv/58_generic_struct.sv @@ -1,3 +1,8 @@ +package veryl_testcase_Package58; + typedef int unsigned B; + typedef longint unsigned C; +endpackage + module veryl_testcase_Module58; typedef struct packed { veryl_testcase_Package58::B A; @@ -31,9 +36,4 @@ module veryl_testcase_Module58; __StructB__C _e; __StructC__C__C _g; endmodule - -package veryl_testcase_Package58; - typedef int unsigned B; - typedef longint unsigned C; -endpackage //# sourceMappingURL=../map/testcases/sv/58_generic_struct.sv.map diff --git a/testcases/veryl/19_import_export.veryl b/testcases/veryl/19_import_export.veryl index d9eba080..fc3240f3 100644 --- a/testcases/veryl/19_import_export.veryl +++ b/testcases/veryl/19_import_export.veryl @@ -1,6 +1,10 @@ import $sv::PackageA::A; import $sv::PackageA::*; +package PackageA { + const A: u32 = 0; +} + module Module19 { import PackageA::A; import PackageA::*; @@ -17,7 +21,3 @@ package Package19 { export PackageA::A; export *; } - -package PackageA { - const A: u32 = 0; -} diff --git a/testcases/veryl/37_package_ref.veryl b/testcases/veryl/37_package_ref.veryl index a2ae235d..cfc756d0 100644 --- a/testcases/veryl/37_package_ref.veryl +++ b/testcases/veryl/37_package_ref.veryl @@ -1,8 +1,3 @@ -module Module37 { - let _a: u32 = Package37::A; - let _b: u32 = Package37::B::C; - let _c: u32 = Package37::X(); -} package Package37 { const A: u32 = 1; @@ -14,3 +9,9 @@ package Package37 { return 0; } } + +module Module37 { + let _a: u32 = Package37::A; + let _b: u32 = Package37::B::C; + let _c: u32 = Package37::X(); +} diff --git a/testcases/veryl/44_import_resolve.veryl b/testcases/veryl/44_import_resolve.veryl index 8f8f44f2..41f40814 100644 --- a/testcases/veryl/44_import_resolve.veryl +++ b/testcases/veryl/44_import_resolve.veryl @@ -1,3 +1,11 @@ +package Package44A { + const z: u32 = 0; +} + +package Package44B { + const y: u32 = 0; +} + module Module44 { var a: logic<10>; var b: logic<10>; @@ -10,11 +18,3 @@ module Module44 { assign b = z; assign c = y; } - -package Package44A { - const z: u32 = 0; -} - -package Package44B { - const y: u32 = 0; -} diff --git a/testcases/veryl/56_generic_interface.veryl b/testcases/veryl/56_generic_interface.veryl index d5d97efc..8298712c 100644 --- a/testcases/veryl/56_generic_interface.veryl +++ b/testcases/veryl/56_generic_interface.veryl @@ -1,3 +1,11 @@ +package Package56A { + const X: u32 = 1; +} + +package Package56B { + const X: u32 = 2; +} + module Module56 { import Package56A::X; inst u0: Interface56A::; @@ -27,11 +35,3 @@ pub interface Interface56A:: { pub interface Interface56B:: { var _b: logic; } - -package Package56A { - const X: u32 = 1; -} - -package Package56B { - const X: u32 = 2; -} diff --git a/testcases/veryl/57_generic_package.veryl b/testcases/veryl/57_generic_package.veryl index 678c9892..7ae58a23 100644 --- a/testcases/veryl/57_generic_package.veryl +++ b/testcases/veryl/57_generic_package.veryl @@ -1,16 +1,3 @@ -module Module57 { - import Package57D::Y; - const A: u32 = Package57A::<1>::X; - const B: u64 = Package57A::<2>::X; - const C: u32 = Package57B::<3>::X; - const E: u32 = Package57B::<3>::X; - const D: u64 = Package57B::<>::X; - const F: u64 = Package57B::::X; - - var _e : Package57C::<2>::StructC; - assign _e.c = 1; -} - /// Generic package test for doc comment pub package Package57A:: { const X: u32 = T; @@ -30,3 +17,16 @@ package Package57C:: { package Package57D { const Y: u32 = 1; } + +module Module57 { + import Package57D::Y; + const A: u32 = Package57A::<1>::X; + const B: u64 = Package57A::<2>::X; + const C: u32 = Package57B::<3>::X; + const E: u32 = Package57B::<3>::X; + const D: u64 = Package57B::<>::X; + const F: u64 = Package57B::::X; + + var _e : Package57C::<2>::StructC; + assign _e.c = 1; +} diff --git a/testcases/veryl/58_generic_struct.veryl b/testcases/veryl/58_generic_struct.veryl index e0b4af02..27fbfb4e 100644 --- a/testcases/veryl/58_generic_struct.veryl +++ b/testcases/veryl/58_generic_struct.veryl @@ -1,3 +1,8 @@ +package Package58 { + type B = u32; + type C = u64; +} + module Module58 { struct StructA:: { A: T, @@ -22,8 +27,3 @@ module Module58 { var _e: StructB::<> ; var _g: StructC:: ; } - -package Package58 { - type B = u32; - type C = u64; -}