From 915b286dc54f36216dcc46cd8c8832ba1bd5fe67 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Mon, 15 Aug 2022 09:16:06 +0200 Subject: vhdl-prints: improve handling of PSL. For #2178 --- src/psl/psl-nodes.adb | 16 +++++ src/psl/psl-nodes.ads | 6 ++ src/psl/psl-nodes_meta.adb | 142 +++++++++++++++++++++++++++------------------ src/psl/psl-nodes_meta.ads | 2 + src/psl/psl-prints.adb | 1 + src/vhdl/vhdl-prints.adb | 80 +++++++++++++++++++++++-- 6 files changed, 184 insertions(+), 63 deletions(-) diff --git a/src/psl/psl-nodes.adb b/src/psl/psl-nodes.adb index 5eb9cd5f2..37f7a737b 100644 --- a/src/psl/psl-nodes.adb +++ b/src/psl/psl-nodes.adb @@ -717,6 +717,22 @@ package body PSL.Nodes is Set_Flag2 (N, B); end Set_Inclusive_Flag; + function Get_Has_Identifier_List (N : Node) return Boolean is + begin + pragma Assert (N /= Null_Node); + pragma Assert (Has_Has_Identifier_List (Get_Kind (N)), + "no field Has_Identifier_List"); + return Get_Flag1 (N); + end Get_Has_Identifier_List; + + procedure Set_Has_Identifier_List (N : Node; B : Boolean) is + begin + pragma Assert (N /= Null_Node); + pragma Assert (Has_Has_Identifier_List (Get_Kind (N)), + "no field Has_Identifier_List"); + Set_Flag1 (N, B); + end Set_Has_Identifier_List; + function Get_Low_Bound (N : Node) return Node is begin pragma Assert (N /= Null_Node); diff --git a/src/psl/psl-nodes.ads b/src/psl/psl-nodes.ads index 29a1943f4..2667c76b3 100644 --- a/src/psl/psl-nodes.ads +++ b/src/psl/psl-nodes.ads @@ -206,6 +206,8 @@ package PSL.Nodes is -- -- -- Current actual parameter. -- Get/Set_Actual (Field3) + -- + -- Get/Set_Has_Identifier_List (Flag1) -- N_Sequence_Instance (Short) -- N_Endpoint_Instance (Short) @@ -564,6 +566,10 @@ package PSL.Nodes is function Get_Inclusive_Flag (N : Node) return Boolean; procedure Set_Inclusive_Flag (N : Node; B : Boolean); + -- Field: Flag1 + function Get_Has_Identifier_List (N : Node) return Boolean; + procedure Set_Has_Identifier_List (N : Node; B : Boolean); + -- Field: Field1 function Get_Low_Bound (N : Node) return Node; procedure Set_Low_Bound (N : Node; S : Node); diff --git a/src/psl/psl-nodes_meta.adb b/src/psl/psl-nodes_meta.adb index b67498780..b69bd3f63 100644 --- a/src/psl/psl-nodes_meta.adb +++ b/src/psl/psl-nodes_meta.adb @@ -31,6 +31,7 @@ package body PSL.Nodes_Meta is Field_Sequence => Type_Node, Field_Strong_Flag => Type_Boolean, Field_Inclusive_Flag => Type_Boolean, + Field_Has_Identifier_List => Type_Boolean, Field_Low_Bound => Type_Node, Field_High_Bound => Type_Node, Field_Number => Type_Node, @@ -88,6 +89,8 @@ package body PSL.Nodes_Meta is return "strong_flag"; when Field_Inclusive_Flag => return "inclusive_flag"; + when Field_Has_Identifier_List => + return "has_identifier_list"; when Field_Low_Bound => return "low_bound"; when Field_High_Bound => @@ -300,6 +303,8 @@ package body PSL.Nodes_Meta is return Attr_None; when Field_Inclusive_Flag => return Attr_None; + when Field_Has_Identifier_List => + return Attr_None; when Field_Low_Bound => return Attr_None; when Field_High_Bound => @@ -386,18 +391,22 @@ package body PSL.Nodes_Meta is Field_Parameter_List, -- N_Const_Parameter Field_Identifier, + Field_Has_Identifier_List, Field_Chain, Field_Actual, -- N_Boolean_Parameter Field_Identifier, + Field_Has_Identifier_List, Field_Chain, Field_Actual, -- N_Property_Parameter Field_Identifier, + Field_Has_Identifier_List, Field_Chain, Field_Actual, -- N_Sequence_Parameter Field_Identifier, + Field_Has_Identifier_List, Field_Chain, Field_Actual, -- N_Sequence_Instance @@ -602,64 +611,64 @@ package body PSL.Nodes_Meta is N_Property_Declaration => 23, N_Sequence_Declaration => 27, N_Endpoint_Declaration => 31, - N_Const_Parameter => 34, - N_Boolean_Parameter => 37, - N_Property_Parameter => 40, - N_Sequence_Parameter => 43, - N_Sequence_Instance => 45, - N_Endpoint_Instance => 47, - N_Property_Instance => 49, - N_Actual => 52, - N_Clock_Event => 54, - N_Always => 55, - N_Never => 56, - N_Eventually => 57, - N_Strong => 58, - N_Imp_Seq => 60, - N_Overlap_Imp_Seq => 62, - N_Log_Imp_Prop => 64, - N_Log_Equiv_Prop => 66, - N_Next => 69, - N_Next_A => 73, - N_Next_E => 77, - N_Next_Event => 81, - N_Next_Event_A => 86, - N_Next_Event_E => 91, - N_Abort => 93, - N_Async_Abort => 95, - N_Sync_Abort => 97, - N_Until => 101, - N_Before => 105, - N_Or_Prop => 107, - N_And_Prop => 109, - N_Paren_Prop => 110, - N_Braced_SERE => 111, - N_Concat_SERE => 113, - N_Fusion_SERE => 115, - N_Within_SERE => 117, - N_Clocked_SERE => 119, - N_Match_And_Seq => 121, - N_And_Seq => 123, - N_Or_Seq => 125, - N_Star_Repeat_Seq => 128, - N_Goto_Repeat_Seq => 131, - N_Plus_Repeat_Seq => 132, - N_Equal_Repeat_Seq => 135, - N_Paren_Bool => 139, - N_Not_Bool => 143, - N_And_Bool => 148, - N_Or_Bool => 153, - N_Imp_Bool => 158, - N_Equiv_Bool => 163, - N_HDL_Expr => 165, - N_HDL_Bool => 170, - N_False => 170, - N_True => 170, - N_EOS => 173, - N_Name => 175, - N_Name_Decl => 177, - N_Inf => 177, - N_Number => 178 + N_Const_Parameter => 35, + N_Boolean_Parameter => 39, + N_Property_Parameter => 43, + N_Sequence_Parameter => 47, + N_Sequence_Instance => 49, + N_Endpoint_Instance => 51, + N_Property_Instance => 53, + N_Actual => 56, + N_Clock_Event => 58, + N_Always => 59, + N_Never => 60, + N_Eventually => 61, + N_Strong => 62, + N_Imp_Seq => 64, + N_Overlap_Imp_Seq => 66, + N_Log_Imp_Prop => 68, + N_Log_Equiv_Prop => 70, + N_Next => 73, + N_Next_A => 77, + N_Next_E => 81, + N_Next_Event => 85, + N_Next_Event_A => 90, + N_Next_Event_E => 95, + N_Abort => 97, + N_Async_Abort => 99, + N_Sync_Abort => 101, + N_Until => 105, + N_Before => 109, + N_Or_Prop => 111, + N_And_Prop => 113, + N_Paren_Prop => 114, + N_Braced_SERE => 115, + N_Concat_SERE => 117, + N_Fusion_SERE => 119, + N_Within_SERE => 121, + N_Clocked_SERE => 123, + N_Match_And_Seq => 125, + N_And_Seq => 127, + N_Or_Seq => 129, + N_Star_Repeat_Seq => 132, + N_Goto_Repeat_Seq => 135, + N_Plus_Repeat_Seq => 136, + N_Equal_Repeat_Seq => 139, + N_Paren_Bool => 143, + N_Not_Bool => 147, + N_And_Bool => 152, + N_Or_Bool => 157, + N_Imp_Bool => 162, + N_Equiv_Bool => 167, + N_HDL_Expr => 169, + N_HDL_Bool => 174, + N_False => 174, + N_True => 174, + N_EOS => 177, + N_Name => 179, + N_Name_Decl => 181, + N_Inf => 181, + N_Number => 182 ); function Get_Fields (K : Nkind) return Fields_Array @@ -685,6 +694,8 @@ package body PSL.Nodes_Meta is return Get_Strong_Flag (N); when Field_Inclusive_Flag => return Get_Inclusive_Flag (N); + when Field_Has_Identifier_List => + return Get_Has_Identifier_List (N); when others => raise Internal_Error; end case; @@ -699,6 +710,8 @@ package body PSL.Nodes_Meta is Set_Strong_Flag (N, V); when Field_Inclusive_Flag => Set_Inclusive_Flag (N, V); + when Field_Has_Identifier_List => + Set_Has_Identifier_List (N, V); when others => raise Internal_Error; end case; @@ -1183,6 +1196,19 @@ package body PSL.Nodes_Meta is end case; end Has_Inclusive_Flag; + function Has_Has_Identifier_List (K : Nkind) return Boolean is + begin + case K is + when N_Const_Parameter + | N_Boolean_Parameter + | N_Property_Parameter + | N_Sequence_Parameter => + return True; + when others => + return False; + end case; + end Has_Has_Identifier_List; + function Has_Low_Bound (K : Nkind) return Boolean is begin case K is diff --git a/src/psl/psl-nodes_meta.ads b/src/psl/psl-nodes_meta.ads index 2b08d62b7..8d766ee27 100644 --- a/src/psl/psl-nodes_meta.ads +++ b/src/psl/psl-nodes_meta.ads @@ -48,6 +48,7 @@ package PSL.Nodes_Meta is Field_Sequence, Field_Strong_Flag, Field_Inclusive_Flag, + Field_Has_Identifier_List, Field_Low_Bound, Field_High_Bound, Field_Number, @@ -152,6 +153,7 @@ package PSL.Nodes_Meta is function Has_Sequence (K : Nkind) return Boolean; function Has_Strong_Flag (K : Nkind) return Boolean; function Has_Inclusive_Flag (K : Nkind) return Boolean; + function Has_Has_Identifier_List (K : Nkind) return Boolean; function Has_Low_Bound (K : Nkind) return Boolean; function Has_High_Bound (K : Nkind) return Boolean; function Has_Number (K : Nkind) return Boolean; diff --git a/src/psl/psl-prints.adb b/src/psl/psl-prints.adb index a810d751a..eec861ce7 100644 --- a/src/psl/psl-prints.adb +++ b/src/psl/psl-prints.adb @@ -74,6 +74,7 @@ package body PSL.Prints is | N_EOS | N_HDL_Expr | N_HDL_Bool + | N_Boolean_Parameter | N_Property_Instance | N_Sequence_Instance => return Prio_HDL; diff --git a/src/vhdl/vhdl-prints.adb b/src/vhdl/vhdl-prints.adb index 509eb223c..51b042037 100644 --- a/src/vhdl/vhdl-prints.adb +++ b/src/vhdl/vhdl-prints.adb @@ -1998,10 +1998,10 @@ package body Vhdl.Prints is Disp_Str (Ctxt, "EOS"); Close_Lit (Ctxt); when N_Not_Bool => - Disp_Token (Ctxt, Tok_Exclam_Mark); - Disp_Token (Ctxt, Tok_Left_Paren); + Disp_Token (Ctxt, Tok_Not); +-- Disp_Token (Ctxt, Tok_Left_Paren); Print_Expr (Ctxt, Get_Boolean (N), Prio); - Disp_Token (Ctxt, Tok_Right_Paren); +-- Disp_Token (Ctxt, Tok_Right_Paren); when N_And_Bool => Disp_Token (Ctxt, Tok_Left_Paren); Print_Expr (Ctxt, Get_Left (N), Prio); @@ -2074,6 +2074,34 @@ package body Vhdl.Prints is Disp_Token (Ctxt, Tok_Right_Bracket); end Print_Bool_Repeat_Sere; + procedure Print_PSL_Instance (Ctxt : in out Ctxt_Class; Inst : PSL_Node) + is + Decl : constant PSL_Node := Get_Declaration (Inst); + Assoc : PSL_Node; + Actual, Formal : PSL_Node; + begin + Disp_Ident (Ctxt, Get_Identifier (Decl)); + Assoc := Get_Association_Chain (Inst); + if Assoc = Null_PSL_Node then + return; + end if; + Disp_Token (Ctxt, Tok_Left_Paren); + loop + Actual := Get_Actual (Assoc); + Formal := Get_Formal (Assoc); + case Get_Kind (Formal) is + when N_Boolean_Parameter => + Print_Expr (Ctxt, Actual); + when others => + PSL.Errors.Error_Kind ("print_psl_instance", Formal); + end case; + Assoc := Get_Chain (Assoc); + exit when Assoc = Null_PSL_Node; + Disp_Token (Ctxt, Tok_Comma); + end loop; + Disp_Token (Ctxt, Tok_Right_Paren); + end Print_PSL_Instance; + procedure Print_Sequence (Ctxt : in out Ctxt_Class; Seq : PSL_Node; Parent_Prio : Priority := Prio_Lowest) @@ -2082,6 +2110,11 @@ package body Vhdl.Prints is Add_Paren : constant Boolean := Prio < Parent_Prio or else Parent_Prio <= Prio_FL_Paren; begin + if Get_Kind (Seq) = N_Sequence_Instance then + Print_PSL_Instance (Ctxt, Seq); + return; + end if; + if Add_Paren then Disp_Token (Ctxt, Tok_Left_Curly); end if; @@ -2114,8 +2147,8 @@ package body Vhdl.Prints is when N_Booleans | N_Name_Decl => Print_Expr (Ctxt, Seq); - when N_Sequence_Instance => - Disp_Ident (Ctxt, Get_Identifier (Get_Declaration (Seq))); + when N_Boolean_Parameter => + Disp_Ident (Ctxt, Get_Identifier (Seq)); when others => PSL.Errors.Error_Kind ("print_sequence", Seq); end case; @@ -2391,6 +2424,40 @@ package body Vhdl.Prints is Disp_Token (Ctxt, Tok_Right_Paren); end Disp_Psl_Onehot0; + procedure Disp_Psl_Parameter_List + (Ctxt : in out Ctxt_Class; Decl : PSL_Node) + is + Param : PSL_Node; + begin + Param := Get_Parameter_List (Decl); + if Param = Null_PSL_Node then + return; + end if; + Disp_Token (Ctxt, Tok_Left_Paren); + loop + case Get_Kind (Param) is + when N_Boolean_Parameter => + Disp_Ident (Ctxt, Name_Boolean); + when N_Property_Parameter => + Disp_Token (Ctxt, Tok_Property); + when N_Sequence_Parameter => + Disp_Token (Ctxt, Tok_Sequence); + when others => + PSL.Errors.Error_Kind ("disp_psl_parameter_list", Param); + end case; + loop + Disp_Ident (Ctxt, Get_Identifier (Param)); + exit when not Get_Has_Identifier_List (Param); + Disp_Token (Ctxt, Tok_Comma); + Param := Get_Chain (Param); + end loop; + Param := Get_Chain (Param); + exit when Param = Null_PSL_Node; + Disp_Token (Ctxt, Tok_Semi_Colon); + end loop; + Disp_Token (Ctxt, Tok_Right_Paren); + end Disp_Psl_Parameter_List; + procedure Disp_Psl_Declaration (Ctxt : in out Ctxt_Class; Stmt : Iir) is Decl : constant PSL_Node := Get_Psl_Declaration (Stmt); @@ -2403,18 +2470,21 @@ package body Vhdl.Prints is when N_Property_Declaration => Disp_Token (Ctxt, Tok_Property); Disp_Ident (Ctxt, Get_Identifier (Decl)); + Disp_Psl_Parameter_List (Ctxt, Decl); Disp_Token (Ctxt, Tok_Is); Disp_Psl_Expression (Ctxt, Get_Property (Decl)); Disp_Token (Ctxt, Tok_Semi_Colon); when N_Sequence_Declaration => Disp_Token (Ctxt, Tok_Sequence); Disp_Ident (Ctxt, Get_Identifier (Decl)); + Disp_Psl_Parameter_List (Ctxt, Decl); Disp_Token (Ctxt, Tok_Is); Print_Sequence (Ctxt, Get_Sequence (Decl)); Disp_Token (Ctxt, Tok_Semi_Colon); when N_Endpoint_Declaration => Disp_Token (Ctxt, Tok_Psl_Endpoint); Disp_Ident (Ctxt, Get_Identifier (Decl)); + Disp_Psl_Parameter_List (Ctxt, Decl); Disp_Token (Ctxt, Tok_Is); Print_Sequence (Ctxt, Get_Sequence (Decl)); Disp_Token (Ctxt, Tok_Semi_Colon); -- cgit v1.2.3