ocarina-be_aadl_ba-thread_dispatch.adb 6.71 KB
Newer Older
1 2 3 4 5 6 7 8
------------------------------------------------------------------------------
--                                                                          --
--                           OCARINA COMPONENTS                             --
--                                                                          --
--   O C A R I N A . B E _ A A D L _ B A . T H R E A D _ D I S P A T C H    --
--                                                                          --
--                                 B o d y                                  --
--                                                                          --
9
--       Copyright (C) 2009 Telecom ParisTech, 2010-2016 ESA & ISAE.        --
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
--                                                                          --
-- Ocarina  is free software; you can redistribute it and/or modify under   --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion. Ocarina is distributed in the hope that it will be useful, but     --
-- WITHOUT ANY WARRANTY; without even the implied warranty of               --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                     --
--                                                                          --
-- As a special exception under Section 7 of GPL version 3, you are granted --
-- additional permissions described in the GCC Runtime Library Exception,   --
-- version 3.1, as published by the Free Software Foundation.               --
--                                                                          --
-- You should have received a copy of the GNU General Public License and    --
-- a copy of the GCC Runtime Library Exception along with this program;     --
-- see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see    --
-- <http://www.gnu.org/licenses/>.                                          --
26
--                                                                          --
jhugues's avatar
jhugues committed
27 28
--                 Ocarina is maintained by the TASTE project               --
--                      (taste-users@lists.tuxfamily.org)                   --
29 30 31
--                                                                          --
------------------------------------------------------------------------------

32
with Ocarina.Output;
33 34 35 36 37 38 39 40 41 42

with Ocarina.ME_AADL_BA;
with Ocarina.ME_AADL_BA.BA_Tree.Nodes;
with Ocarina.ME_AADL_BA.BA_Tree.Nutils;

with Ocarina.BE_AADL_BA.Identifiers;
with Ocarina.BE_AADL_BA.Expressions;

package body Ocarina.BE_AADL_BA.Thread_Dispatch is

43
   use Ocarina.Output;
44 45 46 47 48 49 50 51

   use Ocarina.ME_AADL_BA;
   use Ocarina.ME_AADL_BA.BA_Tree.Nutils;
   use Ocarina.ME_AADL_BA.BA_Tree.Nodes;
   use Ocarina.BE_AADL_BA.Identifiers;
   use Ocarina.BE_AADL_BA.Expressions;

   procedure Print_Dispatch_Logical_Expressions (List : List_Id);
52 53 54 55
   procedure Print_Dispatch_Trigger_Kind        (Trigger_Kind : Byte);
   procedure Print_Dispatch_Trigger_Condition   (Node : Node_Id);
   procedure Print_Dispatch_Conjunction         (Node : Node_Id);
   procedure Print_Frozen_Ports                 (List : List_Id);
56 57 58 59 60 61

   ------------------------------
   -- Print_Dispatch_Condition --
   ------------------------------

   procedure Print_Dispatch_Condition (Node : Node_Id) is
62
      pragma Assert (Kind (Node) = K_Dispatch_Condition_Thread);
63 64 65 66

   begin
      Print_Tokens ((T_On, T_Dispatch));

67
      Print_Dispatch_Trigger_Condition (Dispatch_Trigger_Condition (Node));
68 69

      if not Is_Empty (Frozen_Ports (Node)) then
70 71
         Write_Space;
         Print_Token (T_Frozen);
72 73 74 75
         Print_Frozen_Ports (Frozen_Ports (Node));
      end if;
   end Print_Dispatch_Condition;

76 77 78
   --------------------------------------
   -- Print_Dispatch_Trigger_Condition --
   --------------------------------------
79

80 81
   procedure Print_Dispatch_Trigger_Condition (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Dispatch_Trigger_Condition);
82

83
   begin
84 85 86
      if not Is_Empty (Dispatch_Conjunction (Node)) then
         Write_Space;
         Print_Dispatch_Logical_Expressions (Dispatch_Conjunction (Node));
87 88 89 90 91 92 93 94 95 96
      end if;
      if Dispatch_Trigger_Kind'Val (Trigger_Kind (Node)) /= TRI_No_Kind then
         Write_Space;
         Print_Dispatch_Trigger_Kind (Trigger_Kind (Node));
      end if;

      if Present (Behavior_Time (Node)) then
         Write_Space;
         Print_Behavior_Time (Behavior_Time (Node));
      end if;
97
   end Print_Dispatch_Trigger_Condition;
98 99

   ----------------------------------------
100
   -- Print_Dispatch_Logical_Expressions --
101 102
   ----------------------------------------

103 104
   procedure Print_Dispatch_Logical_Expressions (List : List_Id) is
      pragma Assert (not Is_Empty (List));
105

106
      List_Node : Node_Id;
107
   begin
108
      List_Node := First_Node (List);
109

110 111
      while Present (List_Node) loop
         Print_Dispatch_Conjunction (List_Node);
112

113 114 115 116 117
         List_Node := Next_Node (List_Node);
         if Present (List_Node) then
            Write_Space;
            Print_Token (T_Or);
            Write_Space;
118
         end if;
119 120
      end loop;
   end Print_Dispatch_Logical_Expressions;
121

122 123 124
   --------------------------------
   -- Print_Dispatch_Conjunction --
   --------------------------------
125

126 127
   procedure Print_Dispatch_Conjunction (Node : Node_Id) is
      pragma Assert (Kind (Node) = K_Dispatch_Conjunction);
128

129 130 131
      List_Node : Node_Id;
   begin
      List_Node := First_Node (Dispatch_Triggers (Node));
132

133 134
      while Present (List_Node) loop
         Print_Identifier (List_Node);
135

136 137
         List_Node := Next_Node (List_Node);
         if Present (List_Node) then
138
            Write_Space;
139 140 141 142 143
            Print_Token (T_And);
            Write_Space;
         end if;
      end loop;
   end Print_Dispatch_Conjunction;
144

145 146 147
   ---------------------------------
   -- Print_Dispatch_Trigger_Kind --
   ---------------------------------
148

149 150 151 152 153 154 155 156
   procedure Print_Dispatch_Trigger_Kind (Trigger_Kind : Byte) is
   begin
      case Dispatch_Trigger_Kind'Val (Trigger_Kind) is
         when TRI_Stop    => Print_Token (T_Stop);
         when TRI_Timeout => Print_Token (T_Timeout);
         when others      => Write_Line  (Bug_Str);
      end case;
   end Print_Dispatch_Trigger_Kind;
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181

   ------------------------
   -- Print_Frozen_Ports --
   ------------------------

   procedure Print_Frozen_Ports (List : List_Id) is
      pragma Assert (not Is_Empty (List));

      List_Node : Node_Id;
   begin
      List_Node := First_Node (List);
      Write_Space;
      Print_Identifier (List_Node);

      List_Node := Next_Node (List_Node);
      while Present (List_Node) loop
         Print_Token (T_Comma);
         Write_Space;
         Print_Identifier (List_Node);

         List_Node := Next_Node (List_Node);
      end loop;
   end Print_Frozen_Ports;

end Ocarina.BE_AADL_BA.Thread_Dispatch;