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
153
154
155
156
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
-- GHDL driver - simulator commands.
-- Copyright (C) 2002, 2003, 2004, 2005 Tristan Gingold
--
-- GHDL 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, or (at your option) any later
-- version.
--
-- GHDL 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 GCC; see the file COPYING. If not, write to the Free
-- Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-- 02111-1307, USA.
with Ada.Text_IO;
with Ada.Command_Line;
with Ghdllocal; use Ghdllocal;
with GNAT.OS_Lib; use GNAT.OS_Lib;
with Types;
with Flags;
with Name_Table;
with Errorout; use Errorout;
with Vhdl.Std_Package;
with Libraries;
with Vhdl.Canon;
with Vhdl.Configuration;
with Iirs_Utils;
with Simul.Annotations;
with Simul.Elaboration;
with Simul.Simulation.Main;
with Simul.Debugger;
with Simul.Execution;
with Ghdlcomp; use Ghdlcomp;
with Grt.Types;
with Grt.Options;
with Grt.Errors;
with Grt.Stdio;
with Grtlink;
package body Ghdlsimul is
-- FIXME: reuse simulation.top_config
Top_Conf : Iir;
procedure Compile_Init (Analyze_Only : Boolean) is
begin
if Analyze_Only then
Setup_Libraries (True);
else
Setup_Libraries (False);
Libraries.Load_Std_Library;
-- WORK library is not loaded. FIXME: why ?
end if;
if Time_Resolution /= 'a' then
Vhdl.Std_Package.Set_Time_Resolution (Time_Resolution);
end if;
if Analyze_Only then
return;
end if;
Simul.Annotations.Annotate (Vhdl.Std_Package.Std_Standard_Unit);
Vhdl.Canon.Canon_Flag_Add_Labels := True;
Vhdl.Canon.Canon_Flag_Sequentials_Stmts := True;
Vhdl.Canon.Canon_Flag_Expressions := True;
Vhdl.Canon.Canon_Flag_All_Sensitivity := True;
end Compile_Init;
procedure Compile_Elab
(Cmd_Name : String; Args : Argument_List; Opt_Arg : out Natural)
is
use Name_Table;
use Types;
use Vhdl.Configuration;
First_Id : Name_Id;
Sec_Id : Name_Id;
begin
Extract_Elab_Unit (Cmd_Name, Args, Opt_Arg);
Flags.Flag_Elaborate := True;
-- Translation.Chap12.Elaborate (Prim_Name.all, Sec_Name.all, "", True);
if Errorout.Nbr_Errors > 0 then
-- This may happen (bad entity for example).
raise Compilation_Error;
end if;
First_Id := Get_Identifier (Prim_Name.all);
if Sec_Name = null then
Sec_Id := Null_Identifier;
else
Sec_Id := Get_Identifier (Sec_Name.all);
end if;
Top_Conf := Vhdl.Configuration.Configure (First_Id, Sec_Id);
if Top_Conf = Null_Iir then
raise Compilation_Error;
end if;
-- Check (and possibly abandon) if entity can be at the top of the
-- hierarchy.
declare
Conf_Unit : constant Iir := Get_Library_Unit (Top_Conf);
Arch : constant Iir := Get_Named_Entity
(Get_Block_Specification (Get_Block_Configuration (Conf_Unit)));
Entity : constant Iir := Iirs_Utils.Get_Entity (Arch);
begin
Vhdl.Configuration.Check_Entity_Declaration_Top (Entity);
if Nbr_Errors > 0 then
raise Compilation_Error;
end if;
end;
-- Annotate all units.
for I in Design_Units.First .. Design_Units.Last loop
Simul.Annotations.Annotate (Design_Units.Table (I));
end loop;
end Compile_Elab;
-- Set options.
procedure Set_Run_Options (Args : Argument_List)
is
use Grt.Options;
use Types;
Arg : String_Access;
Status : Decode_Option_Status;
Argv0 : String_Acc;
begin
-- Set progname (used for grt error messages)
Argv0 := new String'(Ada.Command_Line.Command_Name & ASCII.Nul);
Grt.Options.Progname := Grt.Types.To_Ghdl_C_String (Argv0.all'Address);
Grt.Errors.Set_Error_Stream (Grt.Stdio.stdout);
Grtlink.Flag_String := Flags.Flag_String;
Grt.Options.Set_Time_Resolution;
for I in Args'Range loop
Arg := Args (I);
if Arg.all = "--disp-tree" then
Simul.Simulation.Disp_Tree := True;
elsif Arg.all = "--expect-failure" then
Decode_Option (Arg.all, Status);
pragma Assert (Status = Decode_Option_Ok);
elsif Arg.all = "--trace-elab" then
Simul.Elaboration.Trace_Elaboration := True;
elsif Arg.all = "--trace-drivers" then
Simul.Elaboration.Trace_Drivers := True;
elsif Arg.all = "--trace-simu" then
Simul.Simulation.Trace_Simulation := True;
elsif Arg.all = "--trace-stmt" then
Simul.Execution.Trace_Statements := True;
elsif Arg.all = "--stats" then
Simul.Simulation.Disp_Stats := True;
elsif Arg.all = "-i" then
Simul.Debugger.Flag_Debugger := True;
Simul.Debugger.Flag_Interractive := True;
else
Decode_Option (Arg.all, Status);
case Status is
when Decode_Option_Last =>
exit;
when Decode_Option_Stop =>
Grt.Options.Flag_No_Run := True;
when Decode_Option_Ok =>
null;
end case;
-- Ghdlmain.Error ("unknown run options '" & Arg.all & "'");
-- raise Option_Error;
end if;
end loop;
end Set_Run_Options;
procedure Run
is
use Ada.Command_Line;
begin
if Grt.Options.Flag_No_Run then
-- Some options like --has-feature set the exit status.
Set_Exit_Status (Exit_Status (Grt.Errors.Exit_Status));
return;
end if;
Simul.Simulation.Main.Simulation_Entity (Top_Conf);
Set_Exit_Status (Exit_Status (Grt.Errors.Exit_Status));
end Run;
function Decode_Option (Option : String) return Boolean
is
begin
if Option = "--debug" or Option = "-g" then
Simul.Debugger.Flag_Debugger := True;
else
return False;
end if;
return True;
end Decode_Option;
procedure Disp_Long_Help
is
use Ada.Text_IO;
begin
Put_Line (" --debug Run with debugger");
end Disp_Long_Help;
function Get_Top_Config return Iir is
begin
return Top_Conf;
end Get_Top_Config;
procedure Set_Hooks is
begin
Ghdlcomp.Hooks := (Compile_Init'Access,
Compile_Elab'Access,
Set_Run_Options'Access,
Run'Access,
Decode_Option'Access,
Disp_Long_Help'Access);
end Set_Hooks;
procedure Register_Commands is
begin
Set_Hooks;
Ghdlcomp.Register_Commands;
end Register_Commands;
procedure Compile_Init is
begin
Ghdllocal.Compile_Init;
Set_Hooks;
end Compile_Init;
end Ghdlsimul;
|