1--  Common types.
2--  Copyright (C) 2002 - 2015 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>.
16with Interfaces;
17with System;
18with Ada.Unchecked_Conversion;
19
20package Types is
21   pragma Preelaborate (Types);
22
23   -- A tri state type.
24   type Tri_State_Type is (Unknown, False, True);
25
26   --  32 bits integer.
27   type Int32 is range -2**31 .. 2**31 - 1;
28   for Int32'Size use 32;
29
30   --  64 bits integer.
31   type Int64 is range -2**63 .. 2**63 - 1;
32   for Int64'Size use 64;
33
34   subtype Nat32 is Int32 range 0 .. Int32'Last;
35   subtype Pos32 is Nat32 range 1 .. Nat32'Last;
36
37   subtype Nat8 is Nat32 range 0 .. 255;
38
39   type Uns32 is new Interfaces.Unsigned_32;
40   type Uns64 is new Interfaces.Unsigned_64;
41
42   type Fp64 is new Interfaces.IEEE_Float_64;
43   type Fp32 is new Interfaces.IEEE_Float_32;
44
45   --  The verilog logic type (when used in a vector).
46   --  Coding of 01zx:
47   --  For 0 and 1, ZX is 0, VAL is the bit value.
48   --  For z: ZX is 1, VAL is 0.
49   --  For x: ZX is 1, VAL is 1.
50   type Logic_32 is record
51      Val : Uns32;  --  AKA aval
52      Zx  : Uns32;  --  AKA bval
53   end record;
54
55   --  Useful types.
56   type String_Acc is access String;
57   type String_Cst is access constant String;
58   type String_Acc_Array is array (Natural range <>) of String_Acc;
59
60   --  Fat strings, for compatibility with C.
61   type Thin_String_Ptr is access String (Positive);
62   pragma Convention (C, Thin_String_Ptr);
63   function To_Thin_String_Ptr is new Ada.Unchecked_Conversion
64     (System.Address, Thin_String_Ptr);
65
66   --  The name table is defined in Name_Table package.  This is an hash table
67   --  that associate a uniq Name_Id to a string.  Name_Id are allocated in
68   --  increasing numbers, so it is possible to create a parallel table
69   --  indexed on Name_Id to associate additional data to the names.
70   type Name_Id is new Nat32;
71
72   --  Null entry in the name table.
73   --  It is sure that this entry is never allocated.
74   No_Name_Id : constant Name_Id := 0;
75   Null_Identifier: constant Name_Id := 0;
76
77   --  A String8_Id represents a string stored in a dedicated table.  Contrary
78   --  to Name_Id, String8 aren't uniq: two different String8_Id can correspond
79   --  to a same String.  The purpose of an integer number for string is to
80   --  have a 32 bit type to represent a string (contrary to pointers that
81   --  could be 32 or 64 bit - in general - or to an access type which can be
82   --  even wider in Ada).
83   type String8_Id is new Uns32;
84   for String8_Id'Size use 32;
85
86   Null_String8 : constant String8_Id := 0;
87
88   --  The length of a string is not stored in the string table.  Create a
89   --  tuple that is meaningful.
90   type String8_Len_Type is record
91      Str : String8_Id;
92      Len : Nat32;
93   end record;
94
95   --  Index type is the source file table.
96   --  This table is defined in the files_map package.
97   type Source_File_Entry is new Uns32;
98   No_Source_File_Entry: constant Source_File_Entry := 0;
99
100   --  Index into a file buffer.  Use a signed integers, so that empty string
101   --  works correctly.
102   type Source_Ptr is new Int32 range 0 .. Int32'Last;
103
104   --  Valid bounds of any file buffer.
105   Source_Ptr_Org : constant Source_Ptr := 0;
106   Source_Ptr_Last : constant Source_Ptr := Source_Ptr'Last - 1;
107
108   --  Bad file buffer index (used to mark no line).
109   Source_Ptr_Bad : constant Source_Ptr := Source_Ptr'Last;
110
111   --  Type of a file buffer.
112   type File_Buffer is array (Source_Ptr range <>) of Character;
113   type File_Buffer_Acc is access File_Buffer;
114   type File_Buffer_Ptr is access File_Buffer (Source_Ptr);
115
116   function To_File_Buffer_Ptr is new Ada.Unchecked_Conversion
117     (System.Address, File_Buffer_Ptr);
118
119   --  This type contains everything necessary to get a file name, a line
120   --  number and a column number.
121   type Location_Type is new Uns32;
122   for Location_Type'Size use 32;
123   Location_Nil : constant Location_Type := 0;
124   No_Location : constant Location_Type := 0;
125
126   --  Source coordinates.  An expanded form of location, almost ready to be
127   --  printed.
128   --  FILE is the reference to the source file.
129   --  LINE_POS is the position in the source file of the first character of
130   --   the line.  It usually comes for free but can be a little bit difficult
131   --   to compute if the line table is being built.
132   --  LINE is the line number; first line is 1 and 0 means unknown.
133   --  OFFSET is the index in the line; first character is 0, any character
134   --   (even tabulation) counts as 1 character.
135   type Source_Coord_Type is record
136      File : Source_File_Entry;
137      Line_Pos : Source_Ptr;
138      Line : Natural;
139      Offset : Natural;
140   end record;
141
142   No_Source_Coord : constant Source_Coord_Type :=
143     (No_Source_File_Entry, Source_Ptr_Bad, 0, 0);
144
145   --  Indentation.
146   --  This is used by all packages that display vhdl code or informations.
147   Indentation : constant := 2;
148
149   --  For array dimensions.  First dimension is 1.
150   type Dim_Type is new Pos32;
151
152   --  String representing a date/time (format is YYYYMMDDHHmmSS.sss).
153   subtype Time_Stamp_String is String (1 .. 18);
154   type Time_Stamp_Id is new String8_Id;
155   Null_Time_Stamp : constant Time_Stamp_Id := 0;
156
157   --  In order to detect file changes, a checksum of the content is computed.
158   --  Currently SHA1 is used, but the cryptographic aspect is not a strong
159   --  requirement.
160   type File_Checksum_Id is new String8_Id;
161   No_File_Checksum_Id : constant File_Checksum_Id := 0;
162
163   --  String image of a File_Hash_Id.  SHA1 digests are 5 * 32 bytes long, so
164   --  the hexadecimal image is 40 characters.
165   subtype File_Checksum_String is String (1 .. 40);
166
167   --  Self-explaining: raised when an internal error (such as consistency)
168   --  is detected.
169   Internal_Error : exception;
170
171   --  Unrecoverable error.  Just exit() with an error status.
172   Fatal_Error : exception;
173
174   --  List of languages
175   type Language_Type is
176     (
177      Language_Unknown,
178      Language_Vhdl,
179      Language_Psl,
180      Language_Verilog
181     );
182
183   --  Result of a comparaison of two numeric values.
184   type Order_Type is (Less, Equal, Greater);
185
186   --  Direction for a range.  Used by many HDLs!
187   type Direction_Type is (Dir_To, Dir_Downto);
188
189   --  Modular type for the size.  We don't use Storage_Offset in order to
190   --  make alignment computation efficient (knowing that alignment is a
191   --  power of two).
192   type Size_Type is mod System.Memory_Size;
193end Types;
194