1--  Interpreted simulation
2--  Copyright (C) 2014 Tristan Gingold
3--
4--  This program is free software: you can redistribute it and/or modify
5--  it under the terms of the GNU General Public License as published by
6--  the Free Software Foundation, either version 2 of the License, or
7--  (at your option) any later version.
8--
9--  This program is distributed in the hope that it will be useful,
10--  but WITHOUT ANY WARRANTY; without even the implied warranty of
11--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12--  GNU General Public License for more details.
13--
14--  You should have received a copy of the GNU General Public License
15--  along with this program.  If not, see <gnu.org/licenses>.
16
17with System;
18with Grt.Types; use Grt.Types;
19with Vhdl.Nodes; use Vhdl.Nodes;
20with Simul.Environments; use Simul.Environments;
21
22package Simul.Simulation is
23   Trace_Simulation : Boolean := False;
24   Disp_Tree : Boolean := False;
25   Disp_Stats : Boolean := False;
26   Disp_Ams : Boolean := False;
27
28   type Resolv_Instance_Type is record
29      Func : Iir;
30      Block : Block_Instance_Acc;
31      Sig : Iir_Value_Literal_Acc;
32   end record;
33   type Resolv_Instance_Acc is access Resolv_Instance_Type;
34
35   --  The resolution procedure for GRT.
36   procedure Resolution_Proc (Instance_Addr : System.Address;
37                              Val : System.Address;
38                              Bool_Vec : System.Address;
39                              Vec_Len : Ghdl_Index_Type;
40                              Nbr_Drv : Ghdl_Index_Type;
41                              Nbr_Ports : Ghdl_Index_Type);
42   pragma Convention (C, Resolution_Proc);
43
44   type Guard_Instance_Type is record
45      Instance : Block_Instance_Acc;
46      Guard : Iir;
47   end record;
48
49   type Guard_Instance_Acc is access Guard_Instance_Type;
50
51   function Guard_Func (Data : System.Address) return Ghdl_B1;
52   pragma Convention (C, Guard_Func);
53
54   function Execute_Signal_Value (Indirect: Iir_Value_Literal_Acc)
55                                 return Iir_Value_Literal_Acc;
56
57   function Execute_Event_Attribute (Lit: Iir_Value_Literal_Acc)
58                                    return Boolean;
59
60   function Execute_Active_Attribute (Lit: Iir_Value_Literal_Acc)
61                                     return Boolean;
62   function Execute_Driving_Attribute (Lit: Iir_Value_Literal_Acc)
63                                      return Boolean;
64
65   function Execute_Last_Value_Attribute (Indirect: Iir_Value_Literal_Acc)
66                                         return Iir_Value_Literal_Acc;
67   function Execute_Driving_Value_Attribute (Indirect: Iir_Value_Literal_Acc)
68                                            return Iir_Value_Literal_Acc;
69
70   --  Return the Last_Event absolute time.
71   function Execute_Last_Event_Attribute (Indirect: Iir_Value_Literal_Acc)
72                                         return Ghdl_I64;
73   function Execute_Last_Active_Attribute (Indirect: Iir_Value_Literal_Acc)
74                                          return Ghdl_I64;
75
76   -- Type for a transaction: it contains the value, the absolute time at which
77   -- the transaction should occur and a pointer to the next transaction.
78   -- This constitute a simple linked list, the elements must be ordered
79   -- according to time.
80   type Transaction_El_Type is record
81      -- The value of the waveform element.
82      -- Can't be an array.
83      -- Life must be target.
84      Value: Iir_Value_Literal_Acc;
85
86      -- After time at which the transaction should occur.
87      After : Grt.Types.Std_Time;
88   end record;
89
90   type Transaction_Array is array (Natural range <>) of Transaction_El_Type;
91
92   type Transaction_Type (Len : Natural) is record
93      -- Statement that created this transaction.  Used to disp location
94      -- in case of error (constraint error).
95      Stmt: Iir;
96
97      Reject : Std_Time;
98
99      Els : Transaction_Array (1 .. Len);
100   end record;
101
102   procedure Assign_Value_To_Signal (Instance: Block_Instance_Acc;
103                                     Target: Iir_Value_Literal_Acc;
104                                     Transaction: Transaction_Type);
105
106   procedure Disconnect_Signal (Sig : Iir_Value_Literal_Acc);
107
108   -- Return true if the process should be suspended.
109   function Execute_Wait_Statement (Instance : Block_Instance_Acc;
110                                    Stmt: Iir_Wait_Statement)
111                                   return Boolean;
112private
113   type Read_Signal_Value_Enum is
114     (Read_Signal_Last_Value,
115
116      --  For conversion functions.
117      Read_Signal_Driving_Value,
118      Read_Signal_Effective_Value,
119
120      --  'Driving_Value
121      Read_Signal_Driver_Value);
122
123   function Execute_Read_Signal_Value (Sig: Iir_Value_Literal_Acc;
124                                       Attr : Read_Signal_Value_Enum)
125                                      return Iir_Value_Literal_Acc;
126
127   type Write_Signal_Enum is
128     (Write_Signal_Driving_Value,
129      Write_Signal_Effective_Value);
130
131   procedure Execute_Write_Signal (Sig: Iir_Value_Literal_Acc;
132                                   Val : Iir_Value_Literal_Acc;
133                                   Attr : Write_Signal_Enum);
134end Simul.Simulation;
135