aboutsummaryrefslogtreecommitdiffstats
path: root/src/simul/simul-vhdl_simul.ads
blob: 66a032f22a5da2a0328029b416eb8e441dd175bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
--  Simulation of VHDL
--  Copyright (C) 2022 Tristan Gingold
--
--  This file is part of GHDL.
--
--  This program is free software: you can redistribute it and/or modify
--  it under the terms of the GNU General Public License as published by
--  the Free Software Foundation, either version 2 of the License, or
--  (at your option) any later version.
--
--  This program 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.  See the
--  GNU General Public License for more details.
--
--  You should have received a copy of the GNU General Public License
--  along with this program.  If not, see <gnu.org/licenses>.

with Types; use Types;
with Tables;
with Areapools;

with Vhdl.Nodes; use Vhdl.Nodes;

with Grt.Vhdl_Types; use Grt.Vhdl_Types;

with Elab.Memtype; use Elab.Memtype;
with Elab.Vhdl_Context; use Elab.Vhdl_Context;

with Simul.Vhdl_Elab; use Simul.Vhdl_Elab;

with Grt.Signals;

package Simul.Vhdl_Simul is
   Break_Time : Std_Time;

   Trace_Simulation : Boolean := False;

   Flag_Interractive : Boolean := False;
   Flag_Debug_Elab : Boolean := False;

   Trace_Residues : Boolean := False;

   type Process_Kind is (Kind_Process, Kind_PSL);

   type Boolean_Vector is array (Nat32 range <>) of Boolean;
   type Boolean_Vector_Acc is access Boolean_Vector;

   -- State associed with each process.
   type Process_State_Type (Kind : Process_Kind := Kind_Process) is record
      --  True if the process has a suspend state.
      --  (Used for procedure calls)
      Has_State : Boolean;

      --  The process instance.
      Top_Instance : Synth_Instance_Acc := null;
      Proc : Node := Null_Node;

      Idx : Process_Index_Type;

      -- The stack of the process.
      Instance : Synth_Instance_Acc := null;

      case Kind is
         when Kind_Process =>
            --  Memory pool to allocate objects from.
            Pool : Areapools.Areapool_Acc;
         when Kind_PSL =>
            Done : Boolean;
            States: Boolean_Vector_Acc;
      end case;
   end record;
   type Process_State_Acc is access all Process_State_Type;

   type Process_State_Array is
      array (Process_Index_Type range <>) of aliased Process_State_Type;
   type Process_State_Array_Acc is access Process_State_Array;

   --  Array containing all processes.
   Processes_State: Process_State_Array_Acc;

   Current_Process: Process_State_Acc;

   -- If true, disp current time in assert message.
   Disp_Time_Before_Values: Boolean := False;

   Simulation_Finished : exception;

   procedure Simulation;

   --  Low level functions, for debugger.
   function Sig_Index (Base : Memory_Ptr; Idx : Uns32) return Memory_Ptr;
   function Read_Sig (Mem : Memory_Ptr) return Grt.Signals.Ghdl_Signal_Ptr;


   --  Tables visible to the debugger.

   type Scalar_Quantity_Record is record
      --  Index in Y or Yp vector.
      Idx : Integer;
      --  If there is a 'Dot, the corresponding entry.
      Deriv : Scalar_Quantity_Index;
      --  If there is a 'Integ, the corresponding entry.
      Integ : Scalar_Quantity_Index;
   end record;

   package Scalar_Quantities_Table is new Tables
     (Table_Component_Type => Scalar_Quantity_Record,
      Table_Index_Type => Scalar_Quantity_Index,
      Table_Low_Bound => No_Scalar_Quantity + 1,
      Table_Initial => 128);

   type Contrib_Index_Type is new Uns32;

   type Scalar_Terminal_Record is record
      --  Index in Y vector
      Ref_Idx : Integer;
      --  Number of contributions.
      Nbr_Contrib : Natural;
      First_Contrib : Contrib_Index_Type;
   end record;

   package Scalar_Terminals_Table is new Tables
     (Table_Component_Type => Scalar_Terminal_Record,
      Table_Index_Type => Scalar_Terminal_Index,
      Table_Low_Bound => No_Scalar_Terminal + 1,
      Table_Initial => 64);

   type Augmentation_Kind is
     (
      Aug_Noise,
      Aug_Spectrum,
      Aug_Dot,
      Aug_Integ,
      Aug_Delayed
     );

   pragma Unreferenced (Aug_Spectrum, Aug_Integ, Aug_Delayed);

   type Augmentation_Entry (Kind : Augmentation_Kind := Aug_Noise) is record
      Q : Scalar_Quantity_Index;
   end record;

   package Augmentations_Set is new Tables
     (Table_Component_Type => Augmentation_Entry,
      Table_Index_Type => Natural,
      Table_Low_Bound => 1,
      Table_Initial => 64);

   Nbr_Solver_Variables : Natural := 0;

end Simul.Vhdl_Simul;