-- GHDL Run Time (GRT) - VPI interface. -- Copyright (C) 2002 - 2014 Tristan Gingold & Felix Bertram -- -- 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. -- Description: VPI interface for GRT runtime -- the main purpose of this code is to interface with the -- Icarus Verilog Interactive (IVI) simulator GUI with System; use System; with Interfaces; use Interfaces; with Ada.Unchecked_Conversion; with Grt.Types; use Grt.Types; with Grt.Avhpi; use Grt.Avhpi; with Grt.Vcd; with Grt.Callbacks; package Grt.Vpi is -- properties, see vpi_user.h vpiUndefined: constant integer := -1; vpiType: constant integer := 1; vpiName: constant integer := 2; vpiFullName: constant integer := 3; vpiSize: constant integer := 4; vpiTimePrecision: constant integer := 12; vpiScalar: constant integer := 17; vpiVector: constant integer := 18; -- object codes, see vpi_user.h vpiModule: constant integer := 32; vpiNet: constant integer := 36; vpiParameter: constant integer := 41; vpiLeftRange: constant integer := 79; vpiRightRange: constant integer := 83; vpiScope: constant integer := 84; vpiInternalScope: constant integer := 92; vpiStop : constant := 66; vpiFinish : constant := 67; vpiReset : constant := 68; -- Additionnal constants. vpiCallback : constant Integer := 200; -- codes for the format tag of the vpi_value structure vpiBinStrVal: constant integer := 1; vpiOctStrVal: constant integer := 2; vpiDecStrVal: constant integer := 3; vpiHexStrVal: constant integer := 4; vpiScalarVal: constant integer := 5; vpiIntVal: constant integer := 6; vpiRealVal: constant integer := 7; vpiStringVal: constant integer := 8; vpiVectorVal: constant integer := 9; vpiStrengthVal: constant integer := 10; vpiTimeVal: constant integer := 11; vpiObjTypeVal: constant integer := 12; vpiSuppressVal: constant integer := 13; -- codes for type tag of vpi_time structure vpiSimTime: constant integer := 2; -- codes for the reason tag of cb_data structure cbValueChange : constant := 1; cbReadWriteSynch : constant := 6; cbReadOnlySynch : constant := 7; cbNextSimTime : constant := 8; cbAfterDelay : constant := 9; cbEndOfCompile : constant := 10; cbStartOfSimulation : constant := 11; cbEndOfSimulation : constant := 12; -- Error types. vpiCompile : constant := 1; vpiPLI : constant := 2; vpiRun : constant := 3; -- Error severity levels. vpiNotive : constant := 1; vpiWarning : constant := 2; vpiError : constant := 3; vpiSystem : constant := 4; vpiInternal : constant := 5; type struct_vpiHandle (<>) is private; type vpiHandle is access struct_vpiHandle; pragma No_Strict_Aliasing (vpiHandle); -- typedef struct t_vpi_time { -- int type; -- unsigned int high; -- unsigned int low; -- double real; -- } s_vpi_time, *p_vpi_time; type s_vpi_time is record mType : Integer; mHigh : Unsigned_32; mLow : Unsigned_32; mReal : Long_Float; end record; pragma Convention (C, s_vpi_time); type p_vpi_time is access s_vpi_time; -- typedef struct t_vpi_value -- { int format; -- union -- { char*str; -- int scalar; -- int integer; -- double real; -- struct t_vpi_time *time; -- struct t_vpi_vecval *vector; -- struct t_vpi_strengthval *strength; -- char*misc; -- } value; -- } s_vpi_value, *p_vpi_value; type s_vpi_value (Format : integer) is record case Format is when vpiBinStrVal | vpiOctStrVal | vpiDecStrVal | vpiHexStrVal | vpiStringVal => Str : Ghdl_C_String; when vpiScalarVal => Scalar : Integer; when vpiIntVal => Integer_m : Integer; --when vpiRealVal=> null; -- what is the equivalent to double? --when vpiTimeVal=> mTime: p_vpi_time; --when vpiVectorVal=> mVector: p_vpi_vecval; --when vpiStrengthVal=> mStrength: p_vpi_strengthval; when others => null; end case; end record; -- No use of convention C, as there is no direct equivalent in the norm. type p_vpi_value is access s_vpi_value; --typedef struct t_cb_data { -- int reason; -- int (*cb_rtn)(struct t_cb_data*cb); -- vpiHandle obj; -- p_vpi_time time; -- p_vpi_value value; -- int index; -- char *user_data; --} s_cb_data, *p_cb_data; type s_cb_data; type p_cb_data is access all s_cb_data; pragma Convention (C, p_cb_data); function To_p_cb_data is new Ada.Unchecked_Conversion (Source => Address, Target => p_cb_data); type cb_rtn_type is access function (Cb : p_cb_data) return Integer; pragma Convention (C, cb_rtn_type); type s_cb_data is record Reason : Integer; Cb_Rtn : cb_rtn_type; Obj : vpiHandle; Time : p_vpi_time; Value : p_vpi_value; Index : Integer; User_Data : Address; end record; pragma Convention (C, s_cb_data); -- vpiHandle vpi_iterate(int type, vpiHandle ref) function vpi_iterate (aType : Integer; Ref : vpiHandle) return vpiHandle; pragma Export (C, vpi_iterate, "vpi_iterate"); -- int vpi_get(int property, vpiHandle ref) function vpi_get (Property : Integer; Ref : vpiHandle) ret
--  GHDL driver - compile 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 GNAT.OS_Lib; use GNAT.OS_Lib;
with Vhdl.Nodes; use Vhdl.Nodes;

package Ghdlcomp is
   --  This procedure is called at start of commands which call
   --  finish_compilation to generate code.
   type Compile_Init_Acc is access procedure (Analyze_Only : Boolean);

   --  This procedure is called for elaboration.
   --  CMD_NAME is the name of the command, used to report errors.
   --  ARGS is the argument list, starting from the unit name to be elaborated.
   --   The procedure should extract the unit.
   --  OPT_ARG is the index of the first argument from ARGS to be used as
   --   a run option.
   type Compile_Elab_Acc is access procedure
     (Cmd_Name : String; Args : Argument_List; Opt_Arg : out Natural);

   --  Use ARGS as run options.
   --  Should do all the work.
   type Set_Run_Options_Acc is access
     procedure (Args : Argument_List);

   --  Run the simulation.
   --  All the parameters were set through calling Compile_Elab and
   --  Set_Run_Options.
   type Run_Acc is access procedure;

   --  Called when an analysis/elaboration option is decoded.
   --  Return True if OPTION is known (and do the side effects).
   --  No parameters are allowed.
   type Decode_Option_Acc is access function (Option : String) return Boolean;

   --  Disp help for options decoded by Decode_Option.
   type Disp_Long_Help_Acc is access procedure;

   --  All the hooks gathered.
   --  A record is used to be sure all hooks are set.
   type Hooks_Type is record
      Compile_Init : Compile_Init_Acc := null;
      Compile_Elab : Compile_Elab_Acc := null;
      Set_Run_Options : Set_Run_Options_Acc := null;
      Run : Run_Acc := null;
      Decode_Option : Decode_Option_Acc := null;
      Disp_Long_Help : Disp_Long_Help_Acc := null;
   end record;

   Hooks : Hooks_Type;

   --  Register commands.
   procedure Register_Commands;

   --  Output of --disp-config.
   procedure Disp_Config;

   -- --time-resolution=X
   -- Where X corresponds to:
   -- fs => 'f'
   -- ps => 'p'
   -- ns => 'n'
   -- us => 'u'
   -- ms => 'm'
   -- sec => 's'
   -- min => 'M'
   -- hr => 'h'
   Time_Resolution: Character := 'f';

   --  Common action to perform before analysis: library setup.
   procedure Common_Compile_Init (Analyze_Only : Boolean);

   --  Common action to perform before elaboration:
   --  * extract PRIM_NAME and SEC_NAME from ARGS.
   --  * configure
   --  * Check top entity.
   procedure Common_Compile_Elab (Cmd_Name : String;
                                  Args : Argument_List;
                                  Opt_Arg : out Natural;
                                  Config : out Iir);

   --  Functionnal interface.
   --  Must be first initialized by Compile_Init
   procedure Compile_Analyze_Init (Load_Work : Boolean := True);

   --  Load and parse FILE, put library units in the work library (without
   --  analyzing them).
   procedure Compile_Load_File (File : String);

   --  Load, parse and analyze FILE.
   function Compile_Analyze_File (File : String) return Iir;

   procedure Compile_Elaborate (Unit_Name : String_Access);
   procedure Compile_Run;
end Ghdlcomp;