| 1 |
------------------------------------------------------------------------------ |
| 2 |
-- -- |
| 3 |
-- GNAT COMPILER COMPONENTS -- |
| 4 |
-- -- |
| 5 |
-- R E P I N F O -- |
| 6 |
-- -- |
| 7 |
-- B o d y -- |
| 8 |
-- -- |
| 9 |
-- Copyright (C) 1999-2025, Free Software Foundation, Inc. -- |
| 10 |
-- -- |
| 11 |
-- GNAT is free software; you can redistribute it and/or modify it under -- |
| 12 |
-- terms of the GNU General Public License as published by the Free Soft- -- |
| 13 |
-- ware Foundation; either version 3, or (at your option) any later ver- -- |
| 14 |
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- -- |
| 15 |
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -- |
| 16 |
-- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -- |
| 17 |
-- for more details. You should have received a copy of the GNU General -- |
| 18 |
-- Public License distributed with GNAT; see file COPYING3. If not, go to -- |
| 19 |
-- http://www.gnu.org/licenses for a complete copy of the license. -- |
| 20 |
-- -- |
| 21 |
-- GNAT was originally developed by the GNAT team at New York University. -- |
| 22 |
-- Extensive contributions were provided by Ada Core Technologies Inc. -- |
| 23 |
-- -- |
| 24 |
------------------------------------------------------------------------------ |
| 25 |
|
| 26 |
with Alloc; |
| 27 |
with Atree; use Atree; |
| 28 |
with Casing; use Casing; |
| 29 |
with Debug; use Debug; |
| 30 |
with Einfo; use Einfo; |
| 31 |
with Einfo.Entities; use Einfo.Entities; |
| 32 |
with Einfo.Utils; use Einfo.Utils; |
| 33 |
with Lib; use Lib; |
| 34 |
with Namet; use Namet; |
| 35 |
with Nlists; use Nlists; |
| 36 |
with Opt; use Opt; |
| 37 |
with Output; use Output; |
| 38 |
with Osint.C; use Osint.C; |
| 39 |
with Sem_Aux; use Sem_Aux; |
| 40 |
with Sem_Eval; use Sem_Eval; |
| 41 |
with Sem_Util; |
| 42 |
with Sinfo; use Sinfo; |
| 43 |
with Sinfo.Nodes; use Sinfo.Nodes; |
| 44 |
with Sinfo.Utils; use Sinfo.Utils; |
| 45 |
with Sinput; use Sinput; |
| 46 |
with Snames; use Snames; |
| 47 |
with Stand; use Stand; |
| 48 |
with Stringt; use Stringt; |
| 49 |
with Table; |
| 50 |
with Ttypes; |
| 51 |
with Uname; use Uname; |
| 52 |
with Urealp; use Urealp; |
| 53 |
|
| 54 |
with Ada.Unchecked_Conversion; |
| 55 |
|
| 56 |
with GNAT.HTable; |
| 57 |
|
| 58 |
package body Repinfo is |
| 59 |
|
| 60 |
SSU : Pos renames Ttypes.System_Storage_Unit; |
| 61 |
-- Value for Storage_Unit |
| 62 |
|
| 63 |
--------------------------------------- |
| 64 |
-- Representation of GCC Expressions -- |
| 65 |
--------------------------------------- |
| 66 |
|
| 67 |
-- A table internal to this unit is used to hold the values of back |
| 68 |
-- annotated expressions. |
| 69 |
|
| 70 |
-- Node values are stored as Uint values using the negative of the node |
| 71 |
-- index in this table. Constants appear as non-negative Uint values. |
| 72 |
|
| 73 |
type Exp_Node is record |
| 74 |
Expr : TCode; |
| 75 |
Op1 : Node_Ref_Or_Val; |
| 76 |
Op2 : Node_Ref_Or_Val; |
| 77 |
Op3 : Node_Ref_Or_Val; |
| 78 |
end record; |
| 79 |
|
| 80 |
-- The following representation clause ensures that the above record |
| 81 |
-- has no holes. We do this so that when instances of this record are |
| 82 |
-- written, we do not write uninitialized values to the file. |
| 83 |
|
| 84 |
for Exp_Node use record |
| 85 |
Expr at 0 range 0 .. 31; |
| 86 |
Op1 at 4 range 0 .. 31; |
| 87 |
Op2 at 8 range 0 .. 31; |
| 88 |
Op3 at 12 range 0 .. 31; |
| 89 |
end record; |
| 90 |
|
| 91 |
for Exp_Node'Size use 16 * 8; |
| 92 |
-- This ensures that we did not leave out any fields |
| 93 |
|
| 94 |
package Rep_Table is new Table.Table ( |
| 95 |
Table_Component_Type => Exp_Node, |
| 96 |
Table_Index_Type => Nat, |
| 97 |
Table_Low_Bound => 1, |
| 98 |
Table_Initial => Alloc.Rep_Table_Initial, |
| 99 |
Table_Increment => Alloc.Rep_Table_Increment, |
| 100 |
Table_Name => "BE_Rep_Table"); |
| 101 |
|
| 102 |
-------------------------------------------------------------- |
| 103 |
-- Representation of Front-End Dynamic Size/Offset Entities -- |
| 104 |
-------------------------------------------------------------- |
| 105 |
|
| 106 |
package Dynamic_SO_Entity_Table is new Table.Table ( |
| 107 |
Table_Component_Type => Entity_Id, |
| 108 |
Table_Index_Type => Nat, |
| 109 |
Table_Low_Bound => 1, |
| 110 |
Table_Initial => Alloc.Rep_Table_Initial, |
| 111 |
Table_Increment => Alloc.Rep_Table_Increment, |
| 112 |
Table_Name => "FE_Rep_Table"); |
| 113 |
|
| 114 |
Unit_Casing : Casing_Type; |
| 115 |
-- Identifier casing for current unit. This is set by List_Rep_Info for |
| 116 |
-- each unit, before calling subprograms which may read it. |
| 117 |
|
| 118 |
Need_Separator : Boolean; |
| 119 |
-- Set True if a separator is needed before outputting any information for |
| 120 |
-- the current entity. |
| 121 |
|
| 122 |
------------------------------ |
| 123 |
-- Set of Relevant Entities -- |
| 124 |
------------------------------ |
| 125 |
|
| 126 |
Relevant_Entities_Size : constant := 4093; |
| 127 |
-- Number of headers in hash table |
| 128 |
|
| 129 |
subtype Entity_Header_Num is Integer range 0 .. Relevant_Entities_Size - 1; |
| 130 |
-- Range of headers in hash table |
| 131 |
|
| 132 |
function Entity_Hash (Id : Entity_Id) return Entity_Header_Num; |
| 133 |
-- Simple hash function for Entity_Ids |
| 134 |
|
| 135 |
package Relevant_Entities is new GNAT.Htable.Simple_HTable |
| 136 |
(Header_Num => Entity_Header_Num, |
| 137 |
Element => Boolean, |
| 138 |
No_Element => False, |
| 139 |
Key => Entity_Id, |
| 140 |
Hash => Entity_Hash, |
| 141 |
Equal => "="); |
| 142 |
-- Hash table to record which compiler-generated entities are relevant |
| 143 |
|
| 144 |
----------------------- |
| 145 |
-- Local Subprograms -- |
| 146 |
----------------------- |
| 147 |
|
| 148 |
procedure List_Entities |
| 149 |
(Ent : Entity_Id; |
| 150 |
Bytes_Big_Endian : Boolean; |
| 151 |
In_Subprogram : Boolean := False); |
| 152 |
-- This procedure lists the entities associated with the entity E, starting |
| 153 |
-- with the First_Entity and using the Next_Entity link. If a nested |
| 154 |
-- package is found, entities within the package are recursively processed. |
| 155 |
-- When recursing within a subprogram body, Is_Subprogram suppresses |
| 156 |
-- duplicate information about signature. |
| 157 |
|
| 158 |
procedure List_Name (Ent : Entity_Id); |
| 159 |
-- List name of entity Ent in appropriate case. The name is listed with |
| 160 |
-- full qualification up to but not including the compilation unit name. |
| 161 |
|
| 162 |
procedure List_Array_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean); |
| 163 |
-- List representation info for array type Ent |
| 164 |
|
| 165 |
procedure List_Common_Type_Info (Ent : Entity_Id); |
| 166 |
-- List common type info (name, size, alignment) for type Ent |
| 167 |
|
| 168 |
procedure List_Linker_Section (Ent : Entity_Id); |
| 169 |
-- List linker section for Ent (caller has checked that Ent is an entity |
| 170 |
-- for which the Linker_Section_Pragma field is defined). |
| 171 |
|
| 172 |
procedure List_Location (Ent : Entity_Id); |
| 173 |
-- List location information for Ent |
| 174 |
|
| 175 |
procedure List_Object_Info (Ent : Entity_Id); |
| 176 |
-- List representation info for object Ent |
| 177 |
|
| 178 |
procedure List_Record_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean); |
| 179 |
-- List representation info for record type Ent |
| 180 |
|
| 181 |
procedure List_Scalar_Storage_Order |
| 182 |
(Ent : Entity_Id; |
| 183 |
Bytes_Big_Endian : Boolean); |
| 184 |
-- List scalar storage order information for record or array type Ent. |
| 185 |
-- Also includes bit order information for record types, if necessary. |
| 186 |
|
| 187 |
procedure List_Subprogram_Info (Ent : Entity_Id); |
| 188 |
-- List subprogram info for subprogram Ent |
| 189 |
|
| 190 |
procedure List_Type_Info (Ent : Entity_Id); |
| 191 |
-- List type info for type Ent |
| 192 |
|
| 193 |
function Compile_Time_Known_Rep (Val : Node_Ref_Or_Val) return Boolean; |
| 194 |
-- Returns True if Val represents a representation value that is known at |
| 195 |
-- compile time. |
| 196 |
|
| 197 |
procedure Spaces (N : Natural); |
| 198 |
-- Output given number of spaces |
| 199 |
|
| 200 |
procedure Write_Info_Line (S : String); |
| 201 |
-- Routine to write a line to Repinfo output file. This routine is passed |
| 202 |
-- as a special output procedure to Output.Set_Special_Output. Note that |
| 203 |
-- Write_Info_Line is called with an EOL character at the end of each line, |
| 204 |
-- as per the Output spec, but the internal call to the appropriate routine |
| 205 |
-- in Osint requires that the end of line sequence be stripped off. |
| 206 |
|
| 207 |
procedure Write_Mechanism (M : Mechanism_Type); |
| 208 |
-- Writes symbolic string for mechanism represented by M |
| 209 |
|
| 210 |
procedure Write_Separator; |
| 211 |
-- Called before outputting anything for an entity. Ensures that |
| 212 |
-- a separator precedes the output for a particular entity. |
| 213 |
|
| 214 |
procedure Write_Unknown_Val; |
| 215 |
-- Writes symbolic string for an unknown or non-representable value |
| 216 |
|
| 217 |
procedure Write_Val (Val : Node_Ref_Or_Val; Paren : Boolean := False); |
| 218 |
-- Given a representation value, write it out. No_Uint values or values |
| 219 |
-- dependent on discriminants are written as two question marks. If the |
| 220 |
-- flag Paren is set, then the output is surrounded in parentheses if it is |
| 221 |
-- other than a simple value. |
| 222 |
|
| 223 |
------------------------ |
| 224 |
-- Create_Discrim_Ref -- |
| 225 |
------------------------ |
| 226 |
|
| 227 |
function Create_Discrim_Ref (Discr : Entity_Id) return Node_Ref is |
| 228 |
begin |
| 229 |
return Create_Node |
| 230 |
(Expr => Discrim_Val, |
| 231 |
Op1 => Discriminant_Number (Discr)); |
| 232 |
end Create_Discrim_Ref; |
| 233 |
|
| 234 |
--------------------------- |
| 235 |
-- Create_Dynamic_SO_Ref -- |
| 236 |
--------------------------- |
| 237 |
|
| 238 |
function Create_Dynamic_SO_Ref (E : Entity_Id) return Dynamic_SO_Ref is |
| 239 |
begin |
| 240 |
Dynamic_SO_Entity_Table.Append (E); |
| 241 |
return UI_From_Int (-Dynamic_SO_Entity_Table.Last); |
| 242 |
end Create_Dynamic_SO_Ref; |
| 243 |
|
| 244 |
----------------- |
| 245 |
-- Create_Node -- |
| 246 |
----------------- |
| 247 |
|
| 248 |
function Create_Node |
| 249 |
(Expr : TCode; |
| 250 |
Op1 : Node_Ref_Or_Val; |
| 251 |
Op2 : Node_Ref_Or_Val := No_Uint; |
| 252 |
Op3 : Node_Ref_Or_Val := No_Uint) return Node_Ref |
| 253 |
is |
| 254 |
begin |
| 255 |
Rep_Table.Append ( |
| 256 |
(Expr => Expr, |
| 257 |
Op1 => Op1, |
| 258 |
Op2 => Op2, |
| 259 |
Op3 => Op3)); |
| 260 |
return UI_From_Int (-Rep_Table.Last); |
| 261 |
end Create_Node; |
| 262 |
|
| 263 |
----------------- |
| 264 |
-- Entity_Hash -- |
| 265 |
----------------- |
| 266 |
|
| 267 |
function Entity_Hash (Id : Entity_Id) return Entity_Header_Num is |
| 268 |
begin |
| 269 |
return Entity_Header_Num (Id mod Relevant_Entities_Size); |
| 270 |
end Entity_Hash; |
| 271 |
|
| 272 |
--------------------------- |
| 273 |
-- Get_Dynamic_SO_Entity -- |
| 274 |
--------------------------- |
| 275 |
|
| 276 |
function Get_Dynamic_SO_Entity (U : Dynamic_SO_Ref) return Entity_Id is |
| 277 |
begin |
| 278 |
return Dynamic_SO_Entity_Table.Table (-UI_To_Int (U)); |
| 279 |
end Get_Dynamic_SO_Entity; |
| 280 |
|
| 281 |
----------------------- |
| 282 |
-- Is_Dynamic_SO_Ref -- |
| 283 |
----------------------- |
| 284 |
|
| 285 |
function Is_Dynamic_SO_Ref (U : SO_Ref) return Boolean is |
| 286 |
begin |
| 287 |
return U < Uint_0; |
| 288 |
end Is_Dynamic_SO_Ref; |
| 289 |
|
| 290 |
---------------------- |
| 291 |
-- Is_Static_SO_Ref -- |
| 292 |
---------------------- |
| 293 |
|
| 294 |
function Is_Static_SO_Ref (U : SO_Ref) return Boolean is |
| 295 |
begin |
| 296 |
return U >= Uint_0; |
| 297 |
end Is_Static_SO_Ref; |
| 298 |
|
| 299 |
--------- |
| 300 |
-- lgx -- |
| 301 |
--------- |
| 302 |
|
| 303 |
procedure lgx (U : Node_Ref_Or_Val) is |
| 304 |
begin |
| 305 |
List_GCC_Expression (U); |
| 306 |
Write_Eol; |
| 307 |
end lgx; |
| 308 |
|
| 309 |
---------------------- |
| 310 |
-- List_Array_Info -- |
| 311 |
---------------------- |
| 312 |
|
| 313 |
procedure List_Array_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean) is |
| 314 |
begin |
| 315 |
Write_Separator; |
| 316 |
|
| 317 |
if List_Representation_Info_To_JSON then |
| 318 |
Write_Line ("{"); |
| 319 |
end if; |
| 320 |
|
| 321 |
List_Common_Type_Info (Ent); |
| 322 |
|
| 323 |
if List_Representation_Info_To_JSON then |
| 324 |
Write_Line (","); |
| 325 |
Write_Str (" ""Component_Size"": "); |
| 326 |
Write_Val (Component_Size (Ent)); |
| 327 |
else |
| 328 |
Write_Str ("for "); |
| 329 |
List_Name (Ent); |
| 330 |
Write_Str ("'Component_Size use "); |
| 331 |
Write_Val (Component_Size (Ent)); |
| 332 |
Write_Line (";"); |
| 333 |
end if; |
| 334 |
|
| 335 |
List_Scalar_Storage_Order (Ent, Bytes_Big_Endian); |
| 336 |
|
| 337 |
List_Linker_Section (Ent); |
| 338 |
|
| 339 |
if List_Representation_Info_To_JSON then |
| 340 |
Write_Eol; |
| 341 |
Write_Line ("}"); |
| 342 |
end if; |
| 343 |
|
| 344 |
-- The component type is relevant for an array |
| 345 |
|
| 346 |
if List_Representation_Info = 4 |
| 347 |
and then Is_Itype (Component_Type (Base_Type (Ent))) |
| 348 |
then |
| 349 |
Relevant_Entities.Set (Component_Type (Base_Type (Ent)), True); |
| 350 |
end if; |
| 351 |
end List_Array_Info; |
| 352 |
|
| 353 |
--------------------------- |
| 354 |
-- List_Common_Type_Info -- |
| 355 |
--------------------------- |
| 356 |
|
| 357 |
procedure List_Common_Type_Info (Ent : Entity_Id) is |
| 358 |
begin |
| 359 |
if List_Representation_Info_To_JSON then |
| 360 |
Write_Str (" ""name"": """); |
| 361 |
List_Name (Ent); |
| 362 |
Write_Line (""","); |
| 363 |
List_Location (Ent); |
| 364 |
end if; |
| 365 |
|
| 366 |
-- Do not list size info for unconstrained arrays, not meaningful |
| 367 |
|
| 368 |
if Is_Array_Type (Ent) and then not Is_Constrained (Ent) then |
| 369 |
null; |
| 370 |
|
| 371 |
else |
| 372 |
if Known_Esize (Ent) and then Known_RM_Size (Ent) then |
| 373 |
-- If Esize and RM_Size are the same, list as Size. This is a |
| 374 |
-- common case, which we may as well list in simple form. |
| 375 |
|
| 376 |
if Esize (Ent) = RM_Size (Ent) then |
| 377 |
if List_Representation_Info_To_JSON then |
| 378 |
Write_Line (","); |
| 379 |
Write_Str (" ""Size"": "); |
| 380 |
Write_Val (Esize (Ent)); |
| 381 |
else |
| 382 |
Write_Str ("for "); |
| 383 |
List_Name (Ent); |
| 384 |
Write_Str ("'Size use "); |
| 385 |
Write_Val (Esize (Ent)); |
| 386 |
Write_Line (";"); |
| 387 |
end if; |
| 388 |
|
| 389 |
-- Otherwise list size values separately |
| 390 |
|
| 391 |
else |
| 392 |
if List_Representation_Info_To_JSON then |
| 393 |
Write_Line (","); |
| 394 |
Write_Str (" ""Object_Size"": "); |
| 395 |
Write_Val (Esize (Ent)); |
| 396 |
|
| 397 |
Write_Line (","); |
| 398 |
Write_Str (" ""Value_Size"": "); |
| 399 |
Write_Val (RM_Size (Ent)); |
| 400 |
|
| 401 |
else |
| 402 |
Write_Str ("for "); |
| 403 |
List_Name (Ent); |
| 404 |
Write_Str ("'Object_Size use "); |
| 405 |
Write_Val (Esize (Ent)); |
| 406 |
Write_Line (";"); |
| 407 |
|
| 408 |
Write_Str ("for "); |
| 409 |
List_Name (Ent); |
| 410 |
Write_Str ("'Value_Size use "); |
| 411 |
Write_Val (RM_Size (Ent)); |
| 412 |
Write_Line (";"); |
| 413 |
end if; |
| 414 |
end if; |
| 415 |
end if; |
| 416 |
end if; |
| 417 |
|
| 418 |
if Known_Alignment (Ent) then |
| 419 |
if List_Representation_Info_To_JSON then |
| 420 |
Write_Line (","); |
| 421 |
Write_Str (" ""Alignment"": "); |
| 422 |
Write_Val (Alignment (Ent)); |
| 423 |
else |
| 424 |
Write_Str ("for "); |
| 425 |
List_Name (Ent); |
| 426 |
Write_Str ("'Alignment use "); |
| 427 |
Write_Val (Alignment (Ent)); |
| 428 |
Write_Line (";"); |
| 429 |
end if; |
| 430 |
|
| 431 |
-- Alignment is not always set for task, protected, and class-wide |
| 432 |
-- types, or when doing semantic analysis only. Representation aspects |
| 433 |
-- are not computed for types in a generic unit. |
| 434 |
|
| 435 |
else |
| 436 |
pragma Assert (not Expander_Active |
| 437 |
or else Is_Concurrent_Type (Ent) |
| 438 |
or else Is_Class_Wide_Type (Ent) |
| 439 |
or else Sem_Util.In_Generic_Scope (Ent)); |
| 440 |
end if; |
| 441 |
end List_Common_Type_Info; |
| 442 |
|
| 443 |
------------------- |
| 444 |
-- List_Entities -- |
| 445 |
------------------- |
| 446 |
|
| 447 |
procedure List_Entities |
| 448 |
(Ent : Entity_Id; |
| 449 |
Bytes_Big_Endian : Boolean; |
| 450 |
In_Subprogram : Boolean := False) |
| 451 |
is |
| 452 |
E : Entity_Id; |
| 453 |
|
| 454 |
begin |
| 455 |
-- List entity if we have one, and it is not a renaming declaration. |
| 456 |
-- For renamings, we don't get proper information, and really it makes |
| 457 |
-- sense to restrict the output to the renamed entity. |
| 458 |
|
| 459 |
if Present (Ent) |
| 460 |
and then Nkind (Declaration_Node (Ent)) not in N_Renaming_Declaration |
| 461 |
and then not Is_Ignored_Ghost_Entity (Ent) |
| 462 |
then |
| 463 |
-- If entity is a subprogram and we are listing mechanisms, |
| 464 |
-- then we need to list mechanisms for this entity. We skip this |
| 465 |
-- if it is a nested subprogram, as the information has already |
| 466 |
-- been produced when listing the enclosing scope. |
| 467 |
|
| 468 |
if List_Representation_Info_Mechanisms |
| 469 |
and then Is_Subprogram_Or_Entry (Ent) |
| 470 |
and then not In_Subprogram |
| 471 |
then |
| 472 |
List_Subprogram_Info (Ent); |
| 473 |
end if; |
| 474 |
|
| 475 |
E := First_Entity (Ent); |
| 476 |
while Present (E) loop |
| 477 |
-- We list entities that come from source (except for incomplete, |
| 478 |
-- private and generic types, as well as deferred constants, for |
| 479 |
-- which we list the information for the full view). If requested |
| 480 |
-- by the -gnatR4 switch, we also list relevant entities that have |
| 481 |
-- been created when processing the original entities coming from |
| 482 |
-- source. If debug switch -gnatdA is specified, then all entities |
| 483 |
-- are listed. |
| 484 |
|
| 485 |
if ((Comes_From_Source (E) |
| 486 |
or else (Ekind (E) = E_Block |
| 487 |
and then |
| 488 |
Nkind (Parent (E)) = N_Implicit_Label_Declaration |
| 489 |
and then |
| 490 |
Comes_From_Source (Label_Construct (Parent (E))))) |
| 491 |
and then not Is_Incomplete_Or_Private_Type (E) |
| 492 |
and then not Is_Generic_Type (E) |
| 493 |
and then not (Ekind (E) = E_Constant |
| 494 |
and then Present (Full_View (E)))) |
| 495 |
or else (List_Representation_Info = 4 |
| 496 |
and then Relevant_Entities.Get (E)) |
| 497 |
or else Debug_Flag_AA |
| 498 |
then |
| 499 |
if Is_Subprogram (E) then |
| 500 |
if List_Representation_Info_Mechanisms then |
| 501 |
List_Subprogram_Info (E); |
| 502 |
end if; |
| 503 |
|
| 504 |
-- Recurse into entities local to subprogram |
| 505 |
|
| 506 |
List_Entities (E, Bytes_Big_Endian, True); |
| 507 |
|
| 508 |
elsif Ekind (E) in E_Entry |
| 509 |
| E_Entry_Family |
| 510 |
| E_Subprogram_Type |
| 511 |
then |
| 512 |
if List_Representation_Info_Mechanisms then |
| 513 |
List_Subprogram_Info (E); |
| 514 |
end if; |
| 515 |
|
| 516 |
elsif Is_Record_Type (E) then |
| 517 |
if List_Representation_Info >= 1 then |
| 518 |
if Is_Private_Type (E) then |
| 519 |
List_Record_Info (Full_View (E), Bytes_Big_Endian); |
| 520 |
else |
| 521 |
List_Record_Info (E, Bytes_Big_Endian); |
| 522 |
end if; |
| 523 |
|
| 524 |
-- Recurse into entities local to a record type |
| 525 |
|
| 526 |
if List_Representation_Info = 4 then |
| 527 |
List_Entities (E, Bytes_Big_Endian, False); |
| 528 |
end if; |
| 529 |
end if; |
| 530 |
|
| 531 |
elsif Is_Array_Type (E) then |
| 532 |
if List_Representation_Info >= 1 then |
| 533 |
List_Array_Info (E, Bytes_Big_Endian); |
| 534 |
end if; |
| 535 |
|
| 536 |
elsif Is_Type (E) then |
| 537 |
if List_Representation_Info >= 2 then |
| 538 |
List_Type_Info (E); |
| 539 |
end if; |
| 540 |
|
| 541 |
-- Note that formals are not annotated so we skip them here |
| 542 |
|
| 543 |
elsif Ekind (E) in E_Constant |
| 544 |
| E_Loop_Parameter |
| 545 |
| E_Variable |
| 546 |
then |
| 547 |
if List_Representation_Info >= 2 then |
| 548 |
List_Object_Info (E); |
| 549 |
end if; |
| 550 |
end if; |
| 551 |
|
| 552 |
-- Recurse into nested package, but not child packages, and not |
| 553 |
-- nested package renamings (in particular renamings of the |
| 554 |
-- enclosing package, as for some Java bindings and for generic |
| 555 |
-- instances). |
| 556 |
|
| 557 |
if Ekind (E) = E_Package then |
| 558 |
if No (Renamed_Entity (E)) and then not Is_Child_Unit (E) |
| 559 |
then |
| 560 |
List_Entities (E, Bytes_Big_Endian); |
| 561 |
end if; |
| 562 |
|
| 563 |
-- Recurse into bodies |
| 564 |
|
| 565 |
elsif Ekind (E) in E_Package_Body |
| 566 |
| E_Protected_Body |
| 567 |
| E_Protected_Type |
| 568 |
| E_Subprogram_Body |
| 569 |
| E_Task_Body |
| 570 |
| E_Task_Type |
| 571 |
then |
| 572 |
List_Entities (E, Bytes_Big_Endian); |
| 573 |
|
| 574 |
-- Recurse into blocks |
| 575 |
|
| 576 |
elsif Ekind (E) = E_Block then |
| 577 |
List_Entities (E, Bytes_Big_Endian); |
| 578 |
end if; |
| 579 |
end if; |
| 580 |
|
| 581 |
Next_Entity (E); |
| 582 |
end loop; |
| 583 |
end if; |
| 584 |
end List_Entities; |
| 585 |
|
| 586 |
------------------------- |
| 587 |
-- List_GCC_Expression -- |
| 588 |
------------------------- |
| 589 |
|
| 590 |
procedure List_GCC_Expression (U : Node_Ref_Or_Val) is |
| 591 |
|
| 592 |
procedure Print_Expr (Val : Node_Ref_Or_Val); |
| 593 |
-- Internal recursive procedure to print expression |
| 594 |
|
| 595 |
---------------- |
| 596 |
-- Print_Expr -- |
| 597 |
---------------- |
| 598 |
|
| 599 |
procedure Print_Expr (Val : Node_Ref_Or_Val) is |
| 600 |
begin |
| 601 |
if Val >= 0 then |
| 602 |
UI_Write (Val, Decimal); |
| 603 |
|
| 604 |
else |
| 605 |
declare |
| 606 |
Node : Exp_Node renames Rep_Table.Table (-UI_To_Int (Val)); |
| 607 |
|
| 608 |
procedure Unop (S : String); |
| 609 |
-- Output text for unary operator with S being operator name |
| 610 |
|
| 611 |
procedure Binop (S : String); |
| 612 |
-- Output text for binary operator with S being operator name |
| 613 |
|
| 614 |
---------- |
| 615 |
-- Unop -- |
| 616 |
---------- |
| 617 |
|
| 618 |
procedure Unop (S : String) is |
| 619 |
begin |
| 620 |
if List_Representation_Info_To_JSON then |
| 621 |
Write_Str ("{ ""code"": """); |
| 622 |
if S (S'Last) = ' ' then |
| 623 |
Write_Str (S (S'First .. S'Last - 1)); |
| 624 |
else |
| 625 |
Write_Str (S); |
| 626 |
end if; |
| 627 |
Write_Str (""", ""operands"": [ "); |
| 628 |
Print_Expr (Node.Op1); |
| 629 |
Write_Str (" ] }"); |
| 630 |
else |
| 631 |
Write_Str (S); |
| 632 |
Print_Expr (Node.Op1); |
| 633 |
end if; |
| 634 |
end Unop; |
| 635 |
|
| 636 |
----------- |
| 637 |
-- Binop -- |
| 638 |
----------- |
| 639 |
|
| 640 |
procedure Binop (S : String) is |
| 641 |
begin |
| 642 |
if List_Representation_Info_To_JSON then |
| 643 |
Write_Str ("{ ""code"": """); |
| 644 |
Write_Str (S (S'First + 1 .. S'Last - 1)); |
| 645 |
Write_Str (""", ""operands"": [ "); |
| 646 |
Print_Expr (Node.Op1); |
| 647 |
Write_Str (", "); |
| 648 |
Print_Expr (Node.Op2); |
| 649 |
Write_Str (" ] }"); |
| 650 |
else |
| 651 |
Write_Char ('('); |
| 652 |
Print_Expr (Node.Op1); |
| 653 |
Write_Str (S); |
| 654 |
Print_Expr (Node.Op2); |
| 655 |
Write_Char (')'); |
| 656 |
end if; |
| 657 |
end Binop; |
| 658 |
|
| 659 |
-- Start of processing for Print_Expr |
| 660 |
|
| 661 |
begin |
| 662 |
case Node.Expr is |
| 663 |
when Cond_Expr => |
| 664 |
if List_Representation_Info_To_JSON then |
| 665 |
Write_Str ("{ ""code"": ""?<>"""); |
| 666 |
Write_Str (", ""operands"": [ "); |
| 667 |
Print_Expr (Node.Op1); |
| 668 |
Write_Str (", "); |
| 669 |
Print_Expr (Node.Op2); |
| 670 |
Write_Str (", "); |
| 671 |
Print_Expr (Node.Op3); |
| 672 |
Write_Str (" ] }"); |
| 673 |
else |
| 674 |
Write_Str ("(if "); |
| 675 |
Print_Expr (Node.Op1); |
| 676 |
Write_Str (" then "); |
| 677 |
Print_Expr (Node.Op2); |
| 678 |
Write_Str (" else "); |
| 679 |
Print_Expr (Node.Op3); |
| 680 |
Write_Str (")"); |
| 681 |
end if; |
| 682 |
|
| 683 |
when Plus_Expr => |
| 684 |
Binop (" + "); |
| 685 |
|
| 686 |
when Minus_Expr => |
| 687 |
Binop (" - "); |
| 688 |
|
| 689 |
when Mult_Expr => |
| 690 |
Binop (" * "); |
| 691 |
|
| 692 |
when Trunc_Div_Expr => |
| 693 |
Binop (" /t "); |
| 694 |
|
| 695 |
when Ceil_Div_Expr => |
| 696 |
Binop (" /c "); |
| 697 |
|
| 698 |
when Floor_Div_Expr => |
| 699 |
Binop (" /f "); |
| 700 |
|
| 701 |
when Trunc_Mod_Expr => |
| 702 |
Binop (" modt "); |
| 703 |
|
| 704 |
when Ceil_Mod_Expr => |
| 705 |
Binop (" modc "); |
| 706 |
|
| 707 |
when Floor_Mod_Expr => |
| 708 |
Binop (" modf "); |
| 709 |
|
| 710 |
when Exact_Div_Expr => |
| 711 |
Binop (" /e "); |
| 712 |
|
| 713 |
when Negate_Expr => |
| 714 |
Unop ("-"); |
| 715 |
|
| 716 |
when Min_Expr => |
| 717 |
Binop (" min "); |
| 718 |
|
| 719 |
when Max_Expr => |
| 720 |
Binop (" max "); |
| 721 |
|
| 722 |
when Abs_Expr => |
| 723 |
Unop ("abs "); |
| 724 |
|
| 725 |
when Truth_And_Expr => |
| 726 |
Binop (" and "); |
| 727 |
|
| 728 |
when Truth_Or_Expr => |
| 729 |
Binop (" or "); |
| 730 |
|
| 731 |
when Truth_Xor_Expr => |
| 732 |
Binop (" xor "); |
| 733 |
|
| 734 |
when Truth_Not_Expr => |
| 735 |
Unop ("not "); |
| 736 |
|
| 737 |
when Lt_Expr => |
| 738 |
Binop (" < "); |
| 739 |
|
| 740 |
when Le_Expr => |
| 741 |
Binop (" <= "); |
| 742 |
|
| 743 |
when Gt_Expr => |
| 744 |
Binop (" > "); |
| 745 |
|
| 746 |
when Ge_Expr => |
| 747 |
Binop (" >= "); |
| 748 |
|
| 749 |
when Eq_Expr => |
| 750 |
Binop (" == "); |
| 751 |
|
| 752 |
when Ne_Expr => |
| 753 |
Binop (" != "); |
| 754 |
|
| 755 |
when Bit_And_Expr => |
| 756 |
Binop (" & "); |
| 757 |
|
| 758 |
when Discrim_Val => |
| 759 |
Unop ("#"); |
| 760 |
|
| 761 |
when Dynamic_Val => |
| 762 |
Unop ("var"); |
| 763 |
end case; |
| 764 |
end; |
| 765 |
end if; |
| 766 |
end Print_Expr; |
| 767 |
|
| 768 |
-- Start of processing for List_GCC_Expression |
| 769 |
|
| 770 |
begin |
| 771 |
if No (U) then |
| 772 |
Write_Unknown_Val; |
| 773 |
else |
| 774 |
Print_Expr (U); |
| 775 |
end if; |
| 776 |
end List_GCC_Expression; |
| 777 |
|
| 778 |
------------------------- |
| 779 |
-- List_Linker_Section -- |
| 780 |
------------------------- |
| 781 |
|
| 782 |
procedure List_Linker_Section (Ent : Entity_Id) is |
| 783 |
Args : List_Id; |
| 784 |
Sect : Node_Id; |
| 785 |
|
| 786 |
begin |
| 787 |
if Present (Linker_Section_Pragma (Ent)) then |
| 788 |
Args := Pragma_Argument_Associations (Linker_Section_Pragma (Ent)); |
| 789 |
Sect := Expr_Value_S (Get_Pragma_Arg (Last (Args))); |
| 790 |
|
| 791 |
if List_Representation_Info_To_JSON then |
| 792 |
Write_Line (","); |
| 793 |
Write_Str (" ""Linker_Section"": """); |
| 794 |
else |
| 795 |
Write_Str ("pragma Linker_Section ("); |
| 796 |
List_Name (Ent); |
| 797 |
Write_Str (", """); |
| 798 |
end if; |
| 799 |
|
| 800 |
pragma Assert (Nkind (Sect) = N_String_Literal); |
| 801 |
String_To_Name_Buffer (Strval (Sect)); |
| 802 |
Write_Str (Name_Buffer (1 .. Name_Len)); |
| 803 |
Write_Str (""""); |
| 804 |
if not List_Representation_Info_To_JSON then |
| 805 |
Write_Line (");"); |
| 806 |
end if; |
| 807 |
end if; |
| 808 |
end List_Linker_Section; |
| 809 |
|
| 810 |
------------------- |
| 811 |
-- List_Location -- |
| 812 |
------------------- |
| 813 |
|
| 814 |
procedure List_Location (Ent : Entity_Id) is |
| 815 |
begin |
| 816 |
pragma Assert (List_Representation_Info_To_JSON); |
| 817 |
Write_Str (" ""location"": """); |
| 818 |
Write_Location (Sloc (Ent)); |
| 819 |
Write_Str (""""); |
| 820 |
end List_Location; |
| 821 |
|
| 822 |
--------------- |
| 823 |
-- List_Name -- |
| 824 |
--------------- |
| 825 |
|
| 826 |
procedure List_Name (Ent : Entity_Id) is |
| 827 |
C : Character; |
| 828 |
|
| 829 |
begin |
| 830 |
-- In JSON mode, we recurse up to Standard. This is also valid in |
| 831 |
-- default mode where we recurse up to the first compilation unit and |
| 832 |
-- should not get to Standard. |
| 833 |
|
| 834 |
if Scope (Ent) = Standard_Standard then |
| 835 |
null; |
| 836 |
elsif not Is_Compilation_Unit (Scope (Ent)) |
| 837 |
or else List_Representation_Info_To_JSON |
| 838 |
then |
| 839 |
List_Name (Scope (Ent)); |
| 840 |
Write_Char ('.'); |
| 841 |
end if; |
| 842 |
|
| 843 |
Get_Unqualified_Decoded_Name_String (Chars (Ent)); |
| 844 |
Set_Casing (Unit_Casing); |
| 845 |
|
| 846 |
-- The name of operators needs to be properly escaped for JSON |
| 847 |
|
| 848 |
for J in 1 .. Name_Len loop |
| 849 |
C := Name_Buffer (J); |
| 850 |
if C = '"' and then List_Representation_Info_To_JSON then |
| 851 |
Write_Char ('\'); |
| 852 |
end if; |
| 853 |
Write_Char (C); |
| 854 |
end loop; |
| 855 |
end List_Name; |
| 856 |
|
| 857 |
--------------------- |
| 858 |
-- List_Object_Info -- |
| 859 |
--------------------- |
| 860 |
|
| 861 |
procedure List_Object_Info (Ent : Entity_Id) is |
| 862 |
begin |
| 863 |
-- If size and alignment have not been computed (e.g. if we are in a |
| 864 |
-- generic unit, or if the back end is not being run), don't try to |
| 865 |
-- print them. |
| 866 |
|
| 867 |
pragma Assert (Known_Esize (Ent) = Known_Alignment (Ent)); |
| 868 |
if not Known_Alignment (Ent) then |
| 869 |
return; |
| 870 |
end if; |
| 871 |
|
| 872 |
Write_Separator; |
| 873 |
|
| 874 |
if List_Representation_Info_To_JSON then |
| 875 |
Write_Line ("{"); |
| 876 |
|
| 877 |
Write_Str (" ""name"": """); |
| 878 |
List_Name (Ent); |
| 879 |
Write_Line (""","); |
| 880 |
List_Location (Ent); |
| 881 |
Write_Line (","); |
| 882 |
|
| 883 |
Write_Str (" ""Size"": "); |
| 884 |
Write_Val (Esize (Ent)); |
| 885 |
Write_Line (","); |
| 886 |
|
| 887 |
Write_Str (" ""Alignment"": "); |
| 888 |
Write_Val (Alignment (Ent)); |
| 889 |
|
| 890 |
List_Linker_Section (Ent); |
| 891 |
|
| 892 |
Write_Eol; |
| 893 |
Write_Line ("}"); |
| 894 |
else |
| 895 |
Write_Str ("for "); |
| 896 |
List_Name (Ent); |
| 897 |
Write_Str ("'Size use "); |
| 898 |
Write_Val (Esize (Ent)); |
| 899 |
Write_Line (";"); |
| 900 |
|
| 901 |
Write_Str ("for "); |
| 902 |
List_Name (Ent); |
| 903 |
Write_Str ("'Alignment use "); |
| 904 |
Write_Val (Alignment (Ent)); |
| 905 |
Write_Line (";"); |
| 906 |
|
| 907 |
List_Linker_Section (Ent); |
| 908 |
end if; |
| 909 |
|
| 910 |
-- The type is relevant for an object |
| 911 |
|
| 912 |
if List_Representation_Info = 4 and then Is_Itype (Etype (Ent)) then |
| 913 |
Relevant_Entities.Set (Etype (Ent), True); |
| 914 |
end if; |
| 915 |
end List_Object_Info; |
| 916 |
|
| 917 |
---------------------- |
| 918 |
-- List_Record_Info -- |
| 919 |
---------------------- |
| 920 |
|
| 921 |
procedure List_Record_Info (Ent : Entity_Id; Bytes_Big_Endian : Boolean) is |
| 922 |
procedure Compute_Max_Length |
| 923 |
(Ent : Entity_Id; |
| 924 |
Starting_Position : Uint := Uint_0; |
| 925 |
Starting_First_Bit : Uint := Uint_0; |
| 926 |
Prefix_Length : Natural := 0); |
| 927 |
-- Internal recursive procedure to compute the max length |
| 928 |
|
| 929 |
procedure List_Component_Layout |
| 930 |
(Ent : Entity_Id; |
| 931 |
Starting_Position : Uint := Uint_0; |
| 932 |
Starting_First_Bit : Uint := Uint_0; |
| 933 |
Prefix : String := ""; |
| 934 |
Indent : Natural := 0); |
| 935 |
-- Procedure to display the layout of a single component |
| 936 |
|
| 937 |
procedure List_Record_Layout |
| 938 |
(Ent : Entity_Id; |
| 939 |
Starting_Position : Uint := Uint_0; |
| 940 |
Starting_First_Bit : Uint := Uint_0; |
| 941 |
Prefix : String := ""); |
| 942 |
-- Internal recursive procedure to display the layout |
| 943 |
|
| 944 |
procedure List_Structural_Record_Layout |
| 945 |
(Ent : Entity_Id; |
| 946 |
Ext_Ent : Entity_Id; |
| 947 |
Ext_Level : Integer := 0; |
| 948 |
Variant : Node_Id := Empty; |
| 949 |
Indent : Natural := 0); |
| 950 |
-- Internal recursive procedure to display the structural layout. |
| 951 |
-- If Ext_Ent is not equal to Ent, it is an extension of Ent and |
| 952 |
-- Ext_Level is the number of successive extensions between them, |
| 953 |
-- with the convention that this number is positive when we are |
| 954 |
-- called from the fixed part of Ext_Ent and negative when we are |
| 955 |
-- called from the variant part of Ext_Ent, if any; this is needed |
| 956 |
-- because the fixed and variant parts of a parent of an extension |
| 957 |
-- cannot be listed contiguously from this extension's viewpoint. |
| 958 |
-- If Variant is present, it's for a variant in the variant part |
| 959 |
-- instead of the common part of Ent. Indent is the indentation. |
| 960 |
|
| 961 |
Incomplete_Layout : exception; |
| 962 |
-- Exception raised if the layout is incomplete in -gnatc mode |
| 963 |
|
| 964 |
Not_In_Extended_Main : exception; |
| 965 |
-- Exception raised when an ancestor is not declared in the main unit |
| 966 |
|
| 967 |
Max_Name_Length : Natural := 0; |
| 968 |
Max_Spos_Length : Natural := 0; |
| 969 |
|
| 970 |
------------------------ |
| 971 |
-- Compute_Max_Length -- |
| 972 |
------------------------ |
| 973 |
|
| 974 |
procedure Compute_Max_Length |
| 975 |
(Ent : Entity_Id; |
| 976 |
Starting_Position : Uint := Uint_0; |
| 977 |
Starting_First_Bit : Uint := Uint_0; |
| 978 |
Prefix_Length : Natural := 0) |
| 979 |
is |
| 980 |
Comp : Entity_Id; |
| 981 |
|
| 982 |
begin |
| 983 |
Comp := First_Component_Or_Discriminant (Ent); |
| 984 |
while Present (Comp) loop |
| 985 |
|
| 986 |
-- Skip a completely hidden discriminant or a discriminant in an |
| 987 |
-- unchecked union (since it is not there). |
| 988 |
|
| 989 |
if Ekind (Comp) = E_Discriminant |
| 990 |
and then (Is_Completely_Hidden (Comp) |
| 991 |
or else Is_Unchecked_Union (Ent)) |
| 992 |
then |
| 993 |
goto Continue; |
| 994 |
end if; |
| 995 |
|
| 996 |
-- Skip _Parent component in extension (to avoid overlap) |
| 997 |
|
| 998 |
if Chars (Comp) = Name_uParent then |
| 999 |
goto Continue; |
| 1000 |
end if; |
| 1001 |
|
| 1002 |
-- All other cases |
| 1003 |
|
| 1004 |
declare |
| 1005 |
Ctyp : constant Entity_Id := Underlying_Type (Etype (Comp)); |
| 1006 |
Bofs : constant Uint := Component_Bit_Offset (Comp); |
| 1007 |
Npos : Uint; |
| 1008 |
Fbit : Uint; |
| 1009 |
Spos : Uint; |
| 1010 |
Sbit : Uint; |
| 1011 |
|
| 1012 |
Name_Length : Natural; |
| 1013 |
|
| 1014 |
begin |
| 1015 |
Get_Decoded_Name_String (Chars (Comp)); |
| 1016 |
Name_Length := Prefix_Length + Name_Len; |
| 1017 |
|
| 1018 |
if Compile_Time_Known_Rep (Bofs) then |
| 1019 |
Npos := Bofs / SSU; |
| 1020 |
Fbit := Bofs mod SSU; |
| 1021 |
|
| 1022 |
-- Complete annotation in case not done |
| 1023 |
|
| 1024 |
if not Known_Normalized_First_Bit (Comp) then |
| 1025 |
Set_Normalized_Position (Comp, Npos); |
| 1026 |
Set_Normalized_First_Bit (Comp, Fbit); |
| 1027 |
end if; |
| 1028 |
|
| 1029 |
Spos := Starting_Position + Npos; |
| 1030 |
Sbit := Starting_First_Bit + Fbit; |
| 1031 |
|
| 1032 |
if Sbit >= SSU then |
| 1033 |
Spos := Spos + 1; |
| 1034 |
Sbit := Sbit - SSU; |
| 1035 |
end if; |
| 1036 |
|
| 1037 |
-- If extended information is requested, recurse fully into |
| 1038 |
-- record components, i.e. skip the outer level. |
| 1039 |
|
| 1040 |
if List_Representation_Info_Extended |
| 1041 |
and then Is_Record_Type (Ctyp) |
| 1042 |
then |
| 1043 |
Compute_Max_Length (Ctyp, Spos, Sbit, Name_Length + 1); |
| 1044 |
goto Continue; |
| 1045 |
end if; |
| 1046 |
|
| 1047 |
UI_Image (Spos, Format => Decimal); |
| 1048 |
else |
| 1049 |
-- If the record is not packed, then we know that all fields |
| 1050 |
-- whose position is not specified have starting normalized |
| 1051 |
-- bit position of zero. |
| 1052 |
|
| 1053 |
if not Known_Normalized_First_Bit (Comp) |
| 1054 |
and then not Is_Packed (Ent) |
| 1055 |
then |
| 1056 |
Set_Normalized_First_Bit (Comp, Uint_0); |
| 1057 |
end if; |
| 1058 |
|
| 1059 |
UI_Image_Length := 2; -- For "??" marker |
| 1060 |
end if; |
| 1061 |
|
| 1062 |
Max_Name_Length := Natural'Max (Max_Name_Length, Name_Length); |
| 1063 |
Max_Spos_Length := |
| 1064 |
Natural'Max (Max_Spos_Length, UI_Image_Length); |
| 1065 |
end; |
| 1066 |
|
| 1067 |
<<Continue>> |
| 1068 |
Next_Component_Or_Discriminant (Comp); |
| 1069 |
end loop; |
| 1070 |
end Compute_Max_Length; |
| 1071 |
|
| 1072 |
--------------------------- |
| 1073 |
-- List_Component_Layout -- |
| 1074 |
--------------------------- |
| 1075 |
|
| 1076 |
procedure List_Component_Layout |
| 1077 |
(Ent : Entity_Id; |
| 1078 |
Starting_Position : Uint := Uint_0; |
| 1079 |
Starting_First_Bit : Uint := Uint_0; |
| 1080 |
Prefix : String := ""; |
| 1081 |
Indent : Natural := 0) |
| 1082 |
is |
| 1083 |
Esiz : constant Uint := Esize (Ent); |
| 1084 |
Npos : constant Uint := Normalized_Position (Ent); |
| 1085 |
Fbit : constant Uint := Normalized_First_Bit (Ent); |
| 1086 |
Spos : Uint; |
| 1087 |
Sbit : Uint := No_Uint; |
| 1088 |
Lbit : Uint; |
| 1089 |
|
| 1090 |
begin |
| 1091 |
if List_Representation_Info_To_JSON then |
| 1092 |
Spaces (Indent); |
| 1093 |
Write_Line (" {"); |
| 1094 |
Spaces (Indent); |
| 1095 |
Write_Str (" ""name"": """); |
| 1096 |
Write_Str (Prefix); |
| 1097 |
Write_Str (Name_Buffer (1 .. Name_Len)); |
| 1098 |
Write_Line (""","); |
| 1099 |
if Ekind (Ent) = E_Discriminant then |
| 1100 |
Spaces (Indent); |
| 1101 |
Write_Str (" ""discriminant"": "); |
| 1102 |
UI_Write (Discriminant_Number (Ent), Decimal); |
| 1103 |
Write_Line (","); |
| 1104 |
end if; |
| 1105 |
Spaces (Indent); |
| 1106 |
Write_Str (" ""Position"": "); |
| 1107 |
else |
| 1108 |
Write_Str (" "); |
| 1109 |
Write_Str (Prefix); |
| 1110 |
Write_Str (Name_Buffer (1 .. Name_Len)); |
| 1111 |
Spaces (Max_Name_Length - Prefix'Length - Name_Len); |
| 1112 |
Write_Str (" at "); |
| 1113 |
end if; |
| 1114 |
|
| 1115 |
if Known_Static_Normalized_Position (Ent) then |
| 1116 |
Spos := Starting_Position + Npos; |
| 1117 |
Sbit := Starting_First_Bit + Fbit; |
| 1118 |
|
| 1119 |
if Sbit >= SSU then |
| 1120 |
Spos := Spos + 1; |
| 1121 |
end if; |
| 1122 |
|
| 1123 |
UI_Image (Spos, Format => Decimal); |
| 1124 |
Spaces (Max_Spos_Length - UI_Image_Length); |
| 1125 |
Write_Str (UI_Image_Buffer (1 .. UI_Image_Length)); |
| 1126 |
|
| 1127 |
elsif Known_Normalized_Position (Ent) |
| 1128 |
and then List_Representation_Info >= 3 |
| 1129 |
then |
| 1130 |
Spaces (Max_Spos_Length - 2); |
| 1131 |
|
| 1132 |
if Starting_Position /= Uint_0 then |
| 1133 |
UI_Write (Starting_Position, Decimal); |
| 1134 |
Write_Str (" + "); |
| 1135 |
end if; |
| 1136 |
|
| 1137 |
Write_Val (Npos); |
| 1138 |
|
| 1139 |
else |
| 1140 |
Write_Unknown_Val; |
| 1141 |
end if; |
| 1142 |
|
| 1143 |
if List_Representation_Info_To_JSON then |
| 1144 |
Write_Line (","); |
| 1145 |
Spaces (Indent); |
| 1146 |
Write_Str (" ""First_Bit"": "); |
| 1147 |
else |
| 1148 |
Write_Str (" range "); |
| 1149 |
end if; |
| 1150 |
|
| 1151 |
if Known_Static_Normalized_First_Bit (Ent) then |
| 1152 |
Sbit := Starting_First_Bit + Fbit; |
| 1153 |
|
| 1154 |
if Sbit >= SSU then |
| 1155 |
Sbit := Sbit - SSU; |
| 1156 |
end if; |
| 1157 |
|
| 1158 |
UI_Write (Sbit, Decimal); |
| 1159 |
else |
| 1160 |
Write_Unknown_Val; |
| 1161 |
end if; |
| 1162 |
|
| 1163 |
if List_Representation_Info_To_JSON then |
| 1164 |
Write_Line (", "); |
| 1165 |
Spaces (Indent); |
| 1166 |
Write_Str (" ""Size"": "); |
| 1167 |
else |
| 1168 |
Write_Str (" .. "); |
| 1169 |
end if; |
| 1170 |
|
| 1171 |
if Known_Static_Esize (Ent) |
| 1172 |
and then Known_Static_Normalized_First_Bit (Ent) |
| 1173 |
then |
| 1174 |
Lbit := Sbit + Esiz - 1; |
| 1175 |
|
| 1176 |
if List_Representation_Info_To_JSON then |
| 1177 |
UI_Write (Esiz, Decimal); |
| 1178 |
else |
| 1179 |
if Lbit >= 0 and then Lbit < 10 then |
| 1180 |
Write_Char (' '); |
| 1181 |
end if; |
| 1182 |
|
| 1183 |
UI_Write (Lbit, Decimal); |
| 1184 |
end if; |
| 1185 |
|
| 1186 |
elsif List_Representation_Info < 3 or else not Known_Esize (Ent) then |
| 1187 |
Write_Unknown_Val; |
| 1188 |
|
| 1189 |
-- List_Representation >= 3 and Known_Esize (Ent) |
| 1190 |
|
| 1191 |
else |
| 1192 |
Write_Val (Esiz, Paren => not List_Representation_Info_To_JSON); |
| 1193 |
|
| 1194 |
-- Add appropriate first bit offset |
| 1195 |
|
| 1196 |
if not List_Representation_Info_To_JSON then |
| 1197 |
if Sbit = 0 then |
| 1198 |
Write_Str (" - 1"); |
| 1199 |
|
| 1200 |
elsif Sbit = 1 then |
| 1201 |
null; |
| 1202 |
|
| 1203 |
else |
| 1204 |
Write_Str (" + "); |
| 1205 |
Write_Int (UI_To_Int (Sbit) - 1); |
| 1206 |
end if; |
| 1207 |
end if; |
| 1208 |
end if; |
| 1209 |
|
| 1210 |
if List_Representation_Info_To_JSON then |
| 1211 |
Write_Eol; |
| 1212 |
Spaces (Indent); |
| 1213 |
Write_Str (" }"); |
| 1214 |
else |
| 1215 |
Write_Line (";"); |
| 1216 |
end if; |
| 1217 |
|
| 1218 |
-- The type is relevant for a component |
| 1219 |
|
| 1220 |
if List_Representation_Info = 4 and then Is_Itype (Etype (Ent)) then |
| 1221 |
Relevant_Entities.Set (Etype (Ent), True); |
| 1222 |
end if; |
| 1223 |
end List_Component_Layout; |
| 1224 |
|
| 1225 |
------------------------ |
| 1226 |
-- List_Record_Layout -- |
| 1227 |
------------------------ |
| 1228 |
|
| 1229 |
procedure List_Record_Layout |
| 1230 |
(Ent : Entity_Id; |
| 1231 |
Starting_Position : Uint := Uint_0; |
| 1232 |
Starting_First_Bit : Uint := Uint_0; |
| 1233 |
Prefix : String := "") |
| 1234 |
is |
| 1235 |
Comp : Entity_Id; |
| 1236 |
First : Boolean := True; |
| 1237 |
|
| 1238 |
begin |
| 1239 |
Comp := First_Component_Or_Discriminant (Ent); |
| 1240 |
while Present (Comp) loop |
| 1241 |
|
| 1242 |
-- Skip a completely hidden discriminant or a discriminant in an |
| 1243 |
-- unchecked union (since it is not there). |
| 1244 |
|
| 1245 |
if Ekind (Comp) = E_Discriminant |
| 1246 |
and then (Is_Completely_Hidden (Comp) |
| 1247 |
or else Is_Unchecked_Union (Ent)) |
| 1248 |
then |
| 1249 |
goto Continue; |
| 1250 |
end if; |
| 1251 |
|
| 1252 |
-- Skip _Parent component in extension (to avoid overlap) |
| 1253 |
|
| 1254 |
if Chars (Comp) = Name_uParent then |
| 1255 |
goto Continue; |
| 1256 |
end if; |
| 1257 |
|
| 1258 |
-- All other cases |
| 1259 |
|
| 1260 |
declare |
| 1261 |
Ctyp : constant Entity_Id := Underlying_Type (Etype (Comp)); |
| 1262 |
Npos : constant Uint := Normalized_Position (Comp); |
| 1263 |
Fbit : constant Uint := Normalized_First_Bit (Comp); |
| 1264 |
Spos : Uint; |
| 1265 |
Sbit : Uint; |
| 1266 |
|
| 1267 |
begin |
| 1268 |
Get_Decoded_Name_String (Chars (Comp)); |
| 1269 |
Set_Casing (Unit_Casing); |
| 1270 |
|
| 1271 |
-- If extended information is requested, recurse fully into |
| 1272 |
-- record components, i.e. skip the outer level. |
| 1273 |
|
| 1274 |
if List_Representation_Info_Extended |
| 1275 |
and then Is_Record_Type (Ctyp) |
| 1276 |
and then Known_Static_Normalized_Position (Comp) |
| 1277 |
and then Known_Static_Normalized_First_Bit (Comp) |
| 1278 |
then |
| 1279 |
Spos := Starting_Position + Npos; |
| 1280 |
Sbit := Starting_First_Bit + Fbit; |
| 1281 |
|
| 1282 |
if Sbit >= SSU then |
| 1283 |
Spos := Spos + 1; |
| 1284 |
Sbit := Sbit - SSU; |
| 1285 |
end if; |
| 1286 |
|
| 1287 |
List_Record_Layout (Ctyp, |
| 1288 |
Spos, Sbit, Prefix & Name_Buffer (1 .. Name_Len) & "."); |
| 1289 |
|
| 1290 |
goto Continue; |
| 1291 |
end if; |
| 1292 |
|
| 1293 |
if List_Representation_Info_To_JSON then |
| 1294 |
if First then |
| 1295 |
Write_Eol; |
| 1296 |
First := False; |
| 1297 |
else |
| 1298 |
Write_Line (","); |
| 1299 |
end if; |
| 1300 |
end if; |
| 1301 |
|
| 1302 |
-- The Parent_Subtype in an extension is not back-annotated |
| 1303 |
|
| 1304 |
List_Component_Layout ( |
| 1305 |
(if Known_Normalized_Position (Comp) |
| 1306 |
then Comp |
| 1307 |
else Original_Record_Component (Comp)), |
| 1308 |
Starting_Position, Starting_First_Bit, Prefix); |
| 1309 |
end; |
| 1310 |
|
| 1311 |
<<Continue>> |
| 1312 |
Next_Component_Or_Discriminant (Comp); |
| 1313 |
end loop; |
| 1314 |
end List_Record_Layout; |
| 1315 |
|
| 1316 |
----------------------------------- |
| 1317 |
-- List_Structural_Record_Layout -- |
| 1318 |
----------------------------------- |
| 1319 |
|
| 1320 |
procedure List_Structural_Record_Layout |
| 1321 |
(Ent : Entity_Id; |
| 1322 |
Ext_Ent : Entity_Id; |
| 1323 |
Ext_Level : Integer := 0; |
| 1324 |
Variant : Node_Id := Empty; |
| 1325 |
Indent : Natural := 0) |
| 1326 |
is |
| 1327 |
function Derived_Discriminant (Disc : Entity_Id) return Entity_Id; |
| 1328 |
-- This function assumes that Ext_Ent is an extension of Ent. |
| 1329 |
-- Disc is a discriminant of Ent that does not itself constrain a |
| 1330 |
-- discriminant of the parent type of Ent. Return the discriminant |
| 1331 |
-- of Ext_Ent that ultimately constrains Disc, if any. |
| 1332 |
|
| 1333 |
---------------------------- |
| 1334 |
-- Derived_Discriminant -- |
| 1335 |
---------------------------- |
| 1336 |
|
| 1337 |
function Derived_Discriminant (Disc : Entity_Id) return Entity_Id is |
| 1338 |
Corr_Disc : Entity_Id; |
| 1339 |
Derived_Disc : Entity_Id; |
| 1340 |
|
| 1341 |
begin |
| 1342 |
-- Deal with an extension of a type with unknown discriminants |
| 1343 |
|
| 1344 |
if Has_Unknown_Discriminants (Ext_Ent) |
| 1345 |
and then Present (Underlying_Record_View (Ext_Ent)) |
| 1346 |
then |
| 1347 |
Derived_Disc := |
| 1348 |
First_Discriminant (Underlying_Record_View (Ext_Ent)); |
| 1349 |
else |
| 1350 |
Derived_Disc := First_Discriminant (Ext_Ent); |
| 1351 |
end if; |
| 1352 |
|
| 1353 |
-- Loop over the discriminants of the extension |
| 1354 |
|
| 1355 |
while Present (Derived_Disc) loop |
| 1356 |
|
| 1357 |
-- Check if this discriminant constrains another discriminant. |
| 1358 |
-- If so, find the ultimately constrained discriminant and |
| 1359 |
-- compare with the original components in the base type. |
| 1360 |
|
| 1361 |
if Present (Corresponding_Discriminant (Derived_Disc)) then |
| 1362 |
Corr_Disc := Corresponding_Discriminant (Derived_Disc); |
| 1363 |
|
| 1364 |
while Present (Corresponding_Discriminant (Corr_Disc)) loop |
| 1365 |
Corr_Disc := Corresponding_Discriminant (Corr_Disc); |
| 1366 |
end loop; |
| 1367 |
|
| 1368 |
if Original_Record_Component (Corr_Disc) = |
| 1369 |
Original_Record_Component (Disc) |
| 1370 |
then |
| 1371 |
return Derived_Disc; |
| 1372 |
end if; |
| 1373 |
end if; |
| 1374 |
|
| 1375 |
Next_Discriminant (Derived_Disc); |
| 1376 |
end loop; |
| 1377 |
|
| 1378 |
-- Disc is not constrained by a discriminant of Ext_Ent |
| 1379 |
|
| 1380 |
return Empty; |
| 1381 |
end Derived_Discriminant; |
| 1382 |
|
| 1383 |
-- Local declarations |
| 1384 |
|
| 1385 |
Comp : Node_Id; |
| 1386 |
Comp_List : Node_Id; |
| 1387 |
First : Boolean := True; |
| 1388 |
Parent_Ent : Entity_Id := Empty; |
| 1389 |
Var : Node_Id; |
| 1390 |
|
| 1391 |
-- Start of processing for List_Structural_Record_Layout |
| 1392 |
|
| 1393 |
begin |
| 1394 |
-- If we are dealing with a variant, just process the components |
| 1395 |
|
| 1396 |
if Present (Variant) then |
| 1397 |
Comp_List := Component_List (Variant); |
| 1398 |
|
| 1399 |
-- Otherwise, we are dealing with the full record and need to get |
| 1400 |
-- to its definition in order to retrieve its structural layout. |
| 1401 |
|
| 1402 |
else |
| 1403 |
declare |
| 1404 |
Definition : Node_Id := |
| 1405 |
Type_Definition (Declaration_Node (Ent)); |
| 1406 |
|
| 1407 |
Is_Extension : constant Boolean := |
| 1408 |
Is_Tagged_Type (Ent) |
| 1409 |
and then Nkind (Definition) = |
| 1410 |
N_Derived_Type_Definition; |
| 1411 |
|
| 1412 |
Disc : Entity_Id; |
| 1413 |
Listed_Disc : Entity_Id; |
| 1414 |
Parent_Type : Entity_Id; |
| 1415 |
|
| 1416 |
begin |
| 1417 |
-- If this is an extension, first list the layout of the parent |
| 1418 |
-- and then proceed to the extension part, if any. |
| 1419 |
|
| 1420 |
if Is_Extension then |
| 1421 |
Parent_Type := Parent_Subtype (Ent); |
| 1422 |
if No (Parent_Type) then |
| 1423 |
raise Incomplete_Layout; |
| 1424 |
end if; |
| 1425 |
|
| 1426 |
if Is_Private_Type (Parent_Type) then |
| 1427 |
Parent_Type := Full_View (Parent_Type); |
| 1428 |
pragma Assert (Present (Parent_Type)); |
| 1429 |
end if; |
| 1430 |
|
| 1431 |
-- Do not list variants if one of them has been selected |
| 1432 |
|
| 1433 |
if Has_Static_Discriminants (Parent_Type) then |
| 1434 |
List_Record_Layout (Parent_Type); |
| 1435 |
|
| 1436 |
else |
| 1437 |
Parent_Type := Base_Type (Parent_Type); |
| 1438 |
|
| 1439 |
if Is_Private_Type (Parent_Type) then |
| 1440 |
Parent_Type := Full_View (Parent_Type); |
| 1441 |
pragma Assert (Present (Parent_Type)); |
| 1442 |
end if; |
| 1443 |
|
| 1444 |
if not In_Extended_Main_Source_Unit (Parent_Type) then |
| 1445 |
raise Not_In_Extended_Main; |
| 1446 |
end if; |
| 1447 |
|
| 1448 |
Parent_Ent := Parent_Type; |
| 1449 |
if Ext_Level >= 0 then |
| 1450 |
List_Structural_Record_Layout |
| 1451 |
(Parent_Ent, Ext_Ent, Ext_Level + 1); |
| 1452 |
end if; |
| 1453 |
end if; |
| 1454 |
|
| 1455 |
First := False; |
| 1456 |
|
| 1457 |
if Present (Record_Extension_Part (Definition)) then |
| 1458 |
Definition := Record_Extension_Part (Definition); |
| 1459 |
end if; |
| 1460 |
end if; |
| 1461 |
|
| 1462 |
-- If the record has discriminants and is not an unchecked |
| 1463 |
-- union, then display them now. Note that, even if this is |
| 1464 |
-- a structural layout, we list the visible discriminants. |
| 1465 |
|
| 1466 |
if Has_Discriminants (Ent) |
| 1467 |
and then not Is_Unchecked_Union (Ent) |
| 1468 |
and then Ext_Level >= 0 |
| 1469 |
then |
| 1470 |
Disc := First_Discriminant (Ent); |
| 1471 |
while Present (Disc) loop |
| 1472 |
|
| 1473 |
-- If this is a record extension and the discriminant is |
| 1474 |
-- the renaming of another discriminant, skip it. |
| 1475 |
|
| 1476 |
if Is_Extension |
| 1477 |
and then Present (Corresponding_Discriminant (Disc)) |
| 1478 |
then |
| 1479 |
goto Continue_Disc; |
| 1480 |
end if; |
| 1481 |
|
| 1482 |
-- If this is the parent type of an extension, retrieve |
| 1483 |
-- the derived discriminant from the extension, if any. |
| 1484 |
|
| 1485 |
if Ent /= Ext_Ent then |
| 1486 |
Listed_Disc := Derived_Discriminant (Disc); |
| 1487 |
|
| 1488 |
if No (Listed_Disc) then |
| 1489 |
goto Continue_Disc; |
| 1490 |
|
| 1491 |
elsif not Known_Normalized_Position (Listed_Disc) then |
| 1492 |
Listed_Disc := |
| 1493 |
Original_Record_Component (Listed_Disc); |
| 1494 |
end if; |
| 1495 |
|
| 1496 |
else |
| 1497 |
Listed_Disc := Disc; |
| 1498 |
end if; |
| 1499 |
|
| 1500 |
Get_Decoded_Name_String (Chars (Listed_Disc)); |
| 1501 |
Set_Casing (Unit_Casing); |
| 1502 |
|
| 1503 |
if First then |
| 1504 |
Write_Eol; |
| 1505 |
First := False; |
| 1506 |
else |
| 1507 |
Write_Line (","); |
| 1508 |
end if; |
| 1509 |
|
| 1510 |
List_Component_Layout (Listed_Disc, Indent => Indent); |
| 1511 |
|
| 1512 |
<<Continue_Disc>> |
| 1513 |
Next_Discriminant (Disc); |
| 1514 |
end loop; |
| 1515 |
end if; |
| 1516 |
|
| 1517 |
Comp_List := Component_List (Definition); |
| 1518 |
end; |
| 1519 |
end if; |
| 1520 |
|
| 1521 |
-- Bail out for the null record |
| 1522 |
|
| 1523 |
if No (Comp_List) then |
| 1524 |
return; |
| 1525 |
end if; |
| 1526 |
|
| 1527 |
-- Now deal with the regular components, if any |
| 1528 |
|
| 1529 |
if Present (Component_Items (Comp_List)) |
| 1530 |
and then (Present (Variant) or else Ext_Level >= 0) |
| 1531 |
then |
| 1532 |
Comp := First_Non_Pragma (Component_Items (Comp_List)); |
| 1533 |
while Present (Comp) loop |
| 1534 |
|
| 1535 |
-- Skip _Parent component in extension (to avoid overlap) |
| 1536 |
|
| 1537 |
if Chars (Defining_Identifier (Comp)) = Name_uParent then |
| 1538 |
goto Continue_Comp; |
| 1539 |
end if; |
| 1540 |
|
| 1541 |
Get_Decoded_Name_String (Chars (Defining_Identifier (Comp))); |
| 1542 |
Set_Casing (Unit_Casing); |
| 1543 |
|
| 1544 |
if First then |
| 1545 |
Write_Eol; |
| 1546 |
First := False; |
| 1547 |
else |
| 1548 |
Write_Line (","); |
| 1549 |
end if; |
| 1550 |
|
| 1551 |
List_Component_Layout |
| 1552 |
(Defining_Identifier (Comp), Indent => Indent); |
| 1553 |
|
| 1554 |
<<Continue_Comp>> |
| 1555 |
Next_Non_Pragma (Comp); |
| 1556 |
end loop; |
| 1557 |
end if; |
| 1558 |
|
| 1559 |
-- Stop there if we are called from the fixed part of Ext_Ent, |
| 1560 |
-- we'll do the variant part when called from its variant part. |
| 1561 |
|
| 1562 |
if Ext_Level > 0 then |
| 1563 |
return; |
| 1564 |
end if; |
| 1565 |
|
| 1566 |
-- List the layout of the variant part of the parent, if any |
| 1567 |
|
| 1568 |
if Present (Parent_Ent) then |
| 1569 |
List_Structural_Record_Layout |
| 1570 |
(Parent_Ent, Ext_Ent, Ext_Level - 1); |
| 1571 |
end if; |
| 1572 |
|
| 1573 |
-- We are done if there is no variant part |
| 1574 |
|
| 1575 |
if No (Variant_Part (Comp_List)) then |
| 1576 |
return; |
| 1577 |
end if; |
| 1578 |
|
| 1579 |
Write_Eol; |
| 1580 |
Spaces (Indent); |
| 1581 |
Write_Line (" ],"); |
| 1582 |
Spaces (Indent); |
| 1583 |
Write_Str (" """); |
| 1584 |
for J in Ext_Level .. -1 loop |
| 1585 |
Write_Str ("parent_"); |
| 1586 |
end loop; |
| 1587 |
Write_Str ("variant"" : ["); |
| 1588 |
|
| 1589 |
-- Otherwise we recurse on each variant |
| 1590 |
|
| 1591 |
Var := First_Non_Pragma (Variants (Variant_Part (Comp_List))); |
| 1592 |
First := True; |
| 1593 |
while Present (Var) loop |
| 1594 |
if First then |
| 1595 |
Write_Eol; |
| 1596 |
First := False; |
| 1597 |
else |
| 1598 |
Write_Line (","); |
| 1599 |
end if; |
| 1600 |
|
| 1601 |
Spaces (Indent); |
| 1602 |
Write_Line (" {"); |
| 1603 |
Spaces (Indent); |
| 1604 |
Write_Str (" ""present"": "); |
| 1605 |
Write_Val (Present_Expr (Var)); |
| 1606 |
Write_Line (","); |
| 1607 |
Spaces (Indent); |
| 1608 |
Write_Str (" ""record"": ["); |
| 1609 |
|
| 1610 |
List_Structural_Record_Layout |
| 1611 |
(Ent, Ext_Ent, Ext_Level, Var, Indent + 4); |
| 1612 |
|
| 1613 |
Write_Eol; |
| 1614 |
Spaces (Indent); |
| 1615 |
Write_Line (" ]"); |
| 1616 |
Spaces (Indent); |
| 1617 |
Write_Str (" }"); |
| 1618 |
Next_Non_Pragma (Var); |
| 1619 |
end loop; |
| 1620 |
end List_Structural_Record_Layout; |
| 1621 |
|
| 1622 |
-- Start of processing for List_Record_Info |
| 1623 |
|
| 1624 |
begin |
| 1625 |
Write_Separator; |
| 1626 |
|
| 1627 |
if List_Representation_Info_To_JSON then |
| 1628 |
Write_Line ("{"); |
| 1629 |
end if; |
| 1630 |
|
| 1631 |
List_Common_Type_Info (Ent); |
| 1632 |
|
| 1633 |
-- First find out max line length and max starting position |
| 1634 |
-- length, for the purpose of lining things up nicely. |
| 1635 |
|
| 1636 |
Compute_Max_Length (Ent); |
| 1637 |
|
| 1638 |
-- Then do actual output based on those values |
| 1639 |
|
| 1640 |
if List_Representation_Info_To_JSON then |
| 1641 |
Write_Line (","); |
| 1642 |
Write_Str (" ""record"": ["); |
| 1643 |
|
| 1644 |
-- ??? We can output structural layout only for base types fully |
| 1645 |
-- declared in the extended main source unit for the time being, |
| 1646 |
-- because otherwise declarations might not be processed at all. |
| 1647 |
|
| 1648 |
if Is_Base_Type (Ent) then |
| 1649 |
begin |
| 1650 |
List_Structural_Record_Layout (Ent, Ent); |
| 1651 |
|
| 1652 |
exception |
| 1653 |
when Incomplete_Layout |
| 1654 |
| Not_In_Extended_Main |
| 1655 |
=> |
| 1656 |
List_Record_Layout (Ent); |
| 1657 |
|
| 1658 |
when others => |
| 1659 |
raise Program_Error; |
| 1660 |
end; |
| 1661 |
else |
| 1662 |
List_Record_Layout (Ent); |
| 1663 |
end if; |
| 1664 |
|
| 1665 |
Write_Eol; |
| 1666 |
Write_Str (" ]"); |
| 1667 |
else |
| 1668 |
Write_Str ("for "); |
| 1669 |
List_Name (Ent); |
| 1670 |
Write_Line (" use record"); |
| 1671 |
|
| 1672 |
List_Record_Layout (Ent); |
| 1673 |
|
| 1674 |
Write_Line ("end record;"); |
| 1675 |
end if; |
| 1676 |
|
| 1677 |
List_Scalar_Storage_Order (Ent, Bytes_Big_Endian); |
| 1678 |
|
| 1679 |
List_Linker_Section (Ent); |
| 1680 |
|
| 1681 |
if List_Representation_Info_To_JSON then |
| 1682 |
Write_Eol; |
| 1683 |
Write_Line ("}"); |
| 1684 |
end if; |
| 1685 |
|
| 1686 |
-- The type is relevant for a record subtype |
| 1687 |
|
| 1688 |
if List_Representation_Info = 4 |
| 1689 |
and then not Is_Base_Type (Ent) |
| 1690 |
and then Is_Itype (Etype (Ent)) |
| 1691 |
then |
| 1692 |
Relevant_Entities.Set (Etype (Ent), True); |
| 1693 |
end if; |
| 1694 |
end List_Record_Info; |
| 1695 |
|
| 1696 |
------------------- |
| 1697 |
-- List_Rep_Info -- |
| 1698 |
------------------- |
| 1699 |
|
| 1700 |
procedure List_Rep_Info (Bytes_Big_Endian : Boolean) is |
| 1701 |
Col : Nat; |
| 1702 |
|
| 1703 |
begin |
| 1704 |
if List_Representation_Info /= 0 |
| 1705 |
or else List_Representation_Info_Mechanisms |
| 1706 |
then |
| 1707 |
-- For the normal case, we output a single JSON stream |
| 1708 |
|
| 1709 |
if not List_Representation_Info_To_File |
| 1710 |
and then List_Representation_Info_To_JSON |
| 1711 |
then |
| 1712 |
Write_Line ("["); |
| 1713 |
Need_Separator := False; |
| 1714 |
end if; |
| 1715 |
|
| 1716 |
for U in Main_Unit .. Last_Unit loop |
| 1717 |
if In_Extended_Main_Source_Unit (Cunit_Entity (U)) then |
| 1718 |
Unit_Casing := Identifier_Casing (Source_Index (U)); |
| 1719 |
|
| 1720 |
if List_Representation_Info = 4 then |
| 1721 |
Relevant_Entities.Reset; |
| 1722 |
end if; |
| 1723 |
|
| 1724 |
-- Normal case, list to standard output |
| 1725 |
|
| 1726 |
if not List_Representation_Info_To_File then |
| 1727 |
if not List_Representation_Info_To_JSON then |
| 1728 |
Write_Eol; |
| 1729 |
Write_Str ("Representation information for unit "); |
| 1730 |
Write_Unit_Name (Unit_Name (U)); |
| 1731 |
Col := Column; |
| 1732 |
Write_Eol; |
| 1733 |
|
| 1734 |
for J in 1 .. Col - 1 loop |
| 1735 |
Write_Char ('-'); |
| 1736 |
end loop; |
| 1737 |
|
| 1738 |
Write_Eol; |
| 1739 |
Need_Separator := True; |
| 1740 |
end if; |
| 1741 |
|
| 1742 |
List_Entities (Cunit_Entity (U), Bytes_Big_Endian); |
| 1743 |
|
| 1744 |
-- List representation information to file |
| 1745 |
|
| 1746 |
else |
| 1747 |
Create_Repinfo_File |
| 1748 |
(Get_Name_String (File_Name (Source_Index (U)))); |
| 1749 |
Set_Special_Output (Write_Info_Line'Access); |
| 1750 |
if List_Representation_Info_To_JSON then |
| 1751 |
Write_Line ("["); |
| 1752 |
end if; |
| 1753 |
Need_Separator := False; |
| 1754 |
List_Entities (Cunit_Entity (U), Bytes_Big_Endian); |
| 1755 |
if List_Representation_Info_To_JSON then |
| 1756 |
Write_Line ("]"); |
| 1757 |
end if; |
| 1758 |
Cancel_Special_Output; |
| 1759 |
Close_Repinfo_File; |
| 1760 |
end if; |
| 1761 |
end if; |
| 1762 |
end loop; |
| 1763 |
|
| 1764 |
if not List_Representation_Info_To_File |
| 1765 |
and then List_Representation_Info_To_JSON |
| 1766 |
then |
| 1767 |
Write_Line ("]"); |
| 1768 |
end if; |
| 1769 |
end if; |
| 1770 |
end List_Rep_Info; |
| 1771 |
|
| 1772 |
------------------------------- |
| 1773 |
-- List_Scalar_Storage_Order -- |
| 1774 |
------------------------------- |
| 1775 |
|
| 1776 |
procedure List_Scalar_Storage_Order |
| 1777 |
(Ent : Entity_Id; |
| 1778 |
Bytes_Big_Endian : Boolean) |
| 1779 |
is |
| 1780 |
procedure List_Attr (Attr_Name : String; Is_Reversed : Boolean); |
| 1781 |
-- Show attribute definition clause for Attr_Name (an endianness |
| 1782 |
-- attribute), depending on whether or not the endianness is reversed |
| 1783 |
-- compared to native endianness. |
| 1784 |
|
| 1785 |
--------------- |
| 1786 |
-- List_Attr -- |
| 1787 |
--------------- |
| 1788 |
|
| 1789 |
procedure List_Attr (Attr_Name : String; Is_Reversed : Boolean) is |
| 1790 |
begin |
| 1791 |
if List_Representation_Info_To_JSON then |
| 1792 |
Write_Line (","); |
| 1793 |
Write_Str (" """); |
| 1794 |
Write_Str (Attr_Name); |
| 1795 |
Write_Str (""": ""System."); |
| 1796 |
else |
| 1797 |
Write_Str ("for "); |
| 1798 |
List_Name (Ent); |
| 1799 |
Write_Char ('''); |
| 1800 |
Write_Str (Attr_Name); |
| 1801 |
Write_Str (" use System."); |
| 1802 |
end if; |
| 1803 |
|
| 1804 |
if Bytes_Big_Endian xor Is_Reversed then |
| 1805 |
Write_Str ("High"); |
| 1806 |
else |
| 1807 |
Write_Str ("Low"); |
| 1808 |
end if; |
| 1809 |
|
| 1810 |
Write_Str ("_Order_First"); |
| 1811 |
if List_Representation_Info_To_JSON then |
| 1812 |
Write_Str (""""); |
| 1813 |
else |
| 1814 |
Write_Line (";"); |
| 1815 |
end if; |
| 1816 |
end List_Attr; |
| 1817 |
|
| 1818 |
List_SSO : constant Boolean := |
| 1819 |
Has_Rep_Item (Ent, Name_Scalar_Storage_Order) |
| 1820 |
or else SSO_Set_Low_By_Default (Ent) |
| 1821 |
or else SSO_Set_High_By_Default (Ent); |
| 1822 |
-- Scalar_Storage_Order is displayed if specified explicitly or set by |
| 1823 |
-- Default_Scalar_Storage_Order. |
| 1824 |
|
| 1825 |
-- Start of processing for List_Scalar_Storage_Order |
| 1826 |
|
| 1827 |
begin |
| 1828 |
-- For record types, list Bit_Order if not default, or if SSO is shown |
| 1829 |
|
| 1830 |
-- Also, when -gnatR4 is in effect always list bit order and scalar |
| 1831 |
-- storage order explicitly, so that you don't need to know the native |
| 1832 |
-- endianness of the target for which the output was produced in order |
| 1833 |
-- to interpret it. |
| 1834 |
|
| 1835 |
if Is_Record_Type (Ent) |
| 1836 |
and then (List_SSO |
| 1837 |
or else Reverse_Bit_Order (Ent) |
| 1838 |
or else List_Representation_Info = 4) |
| 1839 |
then |
| 1840 |
List_Attr ("Bit_Order", Reverse_Bit_Order (Ent)); |
| 1841 |
end if; |
| 1842 |
|
| 1843 |
-- List SSO if required. If not, then storage is supposed to be in |
| 1844 |
-- native order. |
| 1845 |
|
| 1846 |
if List_SSO or else List_Representation_Info = 4 then |
| 1847 |
List_Attr ("Scalar_Storage_Order", Reverse_Storage_Order (Ent)); |
| 1848 |
else |
| 1849 |
pragma Assert (not Reverse_Storage_Order (Ent)); |
| 1850 |
null; |
| 1851 |
end if; |
| 1852 |
end List_Scalar_Storage_Order; |
| 1853 |
|
| 1854 |
-------------------------- |
| 1855 |
-- List_Subprogram_Info -- |
| 1856 |
-------------------------- |
| 1857 |
|
| 1858 |
procedure List_Subprogram_Info (Ent : Entity_Id) is |
| 1859 |
First : Boolean := True; |
| 1860 |
Plen : Natural; |
| 1861 |
Form : Entity_Id; |
| 1862 |
|
| 1863 |
begin |
| 1864 |
Write_Separator; |
| 1865 |
|
| 1866 |
if List_Representation_Info_To_JSON then |
| 1867 |
Write_Line ("{"); |
| 1868 |
Write_Str (" ""name"": """); |
| 1869 |
List_Name (Ent); |
| 1870 |
Write_Line (""","); |
| 1871 |
List_Location (Ent); |
| 1872 |
Write_Line (","); |
| 1873 |
|
| 1874 |
Write_Str (" ""Convention"": """); |
| 1875 |
else |
| 1876 |
case Ekind (Ent) is |
| 1877 |
when E_Function => |
| 1878 |
Write_Str ("function "); |
| 1879 |
|
| 1880 |
when E_Operator => |
| 1881 |
Write_Str ("operator "); |
| 1882 |
|
| 1883 |
when E_Procedure => |
| 1884 |
Write_Str ("procedure "); |
| 1885 |
|
| 1886 |
when E_Subprogram_Type => |
| 1887 |
Write_Str ("type "); |
| 1888 |
|
| 1889 |
when E_Entry |
| 1890 |
| E_Entry_Family |
| 1891 |
=> |
| 1892 |
Write_Str ("entry "); |
| 1893 |
|
| 1894 |
when others => |
| 1895 |
raise Program_Error; |
| 1896 |
end case; |
| 1897 |
|
| 1898 |
List_Name (Ent); |
| 1899 |
Write_Str (" declared at "); |
| 1900 |
Write_Location (Sloc (Ent)); |
| 1901 |
Write_Eol; |
| 1902 |
|
| 1903 |
Write_Str ("convention : "); |
| 1904 |
end if; |
| 1905 |
|
| 1906 |
case Convention (Ent) is |
| 1907 |
when Convention_Ada => |
| 1908 |
Write_Str ("Ada"); |
| 1909 |
|
| 1910 |
when Convention_Ada_Pass_By_Copy => |
| 1911 |
Write_Str ("Ada_Pass_By_Copy"); |
| 1912 |
|
| 1913 |
when Convention_Ada_Pass_By_Reference => |
| 1914 |
Write_Str ("Ada_Pass_By_Reference"); |
| 1915 |
|
| 1916 |
when Convention_Intrinsic => |
| 1917 |
Write_Str ("Intrinsic"); |
| 1918 |
|
| 1919 |
when Convention_Entry => |
| 1920 |
Write_Str ("Entry"); |
| 1921 |
|
| 1922 |
when Convention_Protected => |
| 1923 |
Write_Str ("Protected"); |
| 1924 |
|
| 1925 |
when Convention_Assembler => |
| 1926 |
Write_Str ("Assembler"); |
| 1927 |
|
| 1928 |
when Convention_C => |
| 1929 |
Write_Str ("C"); |
| 1930 |
|
| 1931 |
when Convention_C_Variadic => |
| 1932 |
declare |
| 1933 |
N : Nat := |
| 1934 |
Convention_Id'Pos (Convention (Ent)) - |
| 1935 |
Convention_Id'Pos (Convention_C_Variadic_0); |
| 1936 |
begin |
| 1937 |
Write_Str ("C_Variadic_"); |
| 1938 |
if N >= 10 then |
| 1939 |
Write_Char ('1'); |
| 1940 |
N := N - 10; |
| 1941 |
end if; |
| 1942 |
pragma Assert (N < 10); |
| 1943 |
Write_Char (Character'Val (Character'Pos ('0') + N)); |
| 1944 |
end; |
| 1945 |
|
| 1946 |
when Convention_COBOL => |
| 1947 |
Write_Str ("COBOL"); |
| 1948 |
|
| 1949 |
when Convention_CPP => |
| 1950 |
Write_Str ("C++"); |
| 1951 |
|
| 1952 |
when Convention_Fortran => |
| 1953 |
Write_Str ("Fortran"); |
| 1954 |
|
| 1955 |
when Convention_Stdcall => |
| 1956 |
Write_Str ("Stdcall"); |
| 1957 |
|
| 1958 |
when Convention_Stubbed => |
| 1959 |
Write_Str ("Stubbed"); |
| 1960 |
end case; |
| 1961 |
|
| 1962 |
if List_Representation_Info_To_JSON then |
| 1963 |
Write_Line (""","); |
| 1964 |
Write_Str (" ""formal"": ["); |
| 1965 |
else |
| 1966 |
Write_Eol; |
| 1967 |
end if; |
| 1968 |
|
| 1969 |
-- Find max length of formal name |
| 1970 |
|
| 1971 |
Plen := 0; |
| 1972 |
Form := First_Formal (Ent); |
| 1973 |
while Present (Form) loop |
| 1974 |
Get_Unqualified_Decoded_Name_String (Chars (Form)); |
| 1975 |
|
| 1976 |
if Name_Len > Plen then |
| 1977 |
Plen := Name_Len; |
| 1978 |
end if; |
| 1979 |
|
| 1980 |
Next_Formal (Form); |
| 1981 |
end loop; |
| 1982 |
|
| 1983 |
-- Output formals and mechanisms |
| 1984 |
|
| 1985 |
Form := First_Formal (Ent); |
| 1986 |
while Present (Form) loop |
| 1987 |
Get_Unqualified_Decoded_Name_String (Chars (Form)); |
| 1988 |
Set_Casing (Unit_Casing); |
| 1989 |
|
| 1990 |
if List_Representation_Info_To_JSON then |
| 1991 |
if First then |
| 1992 |
Write_Eol; |
| 1993 |
First := False; |
| 1994 |
else |
| 1995 |
Write_Line (","); |
| 1996 |
end if; |
| 1997 |
|
| 1998 |
Write_Line (" {"); |
| 1999 |
Write_Str (" ""name"": """); |
| 2000 |
Write_Str (Name_Buffer (1 .. Name_Len)); |
| 2001 |
Write_Line (""","); |
| 2002 |
|
| 2003 |
Write_Str (" ""mechanism"": """); |
| 2004 |
Write_Mechanism (Mechanism (Form)); |
| 2005 |
Write_Line (""""); |
| 2006 |
Write_Str (" }"); |
| 2007 |
else |
| 2008 |
while Name_Len <= Plen loop |
| 2009 |
Name_Len := Name_Len + 1; |
| 2010 |
Name_Buffer (Name_Len) := ' '; |
| 2011 |
end loop; |
| 2012 |
|
| 2013 |
Write_Str (" "); |
| 2014 |
Write_Str (Name_Buffer (1 .. Plen + 1)); |
| 2015 |
Write_Str (": passed by "); |
| 2016 |
|
| 2017 |
Write_Mechanism (Mechanism (Form)); |
| 2018 |
Write_Eol; |
| 2019 |
end if; |
| 2020 |
|
| 2021 |
Next_Formal (Form); |
| 2022 |
end loop; |
| 2023 |
|
| 2024 |
if List_Representation_Info_To_JSON then |
| 2025 |
Write_Eol; |
| 2026 |
Write_Str (" ]"); |
| 2027 |
end if; |
| 2028 |
|
| 2029 |
if Ekind (Ent) = E_Function then |
| 2030 |
if List_Representation_Info_To_JSON then |
| 2031 |
Write_Line (","); |
| 2032 |
Write_Str (" ""mechanism"": """); |
| 2033 |
Write_Mechanism (Mechanism (Ent)); |
| 2034 |
Write_Str (""""); |
| 2035 |
else |
| 2036 |
Write_Str ("returns by "); |
| 2037 |
Write_Mechanism (Mechanism (Ent)); |
| 2038 |
Write_Eol; |
| 2039 |
end if; |
| 2040 |
end if; |
| 2041 |
|
| 2042 |
if not Is_Entry (Ent) then |
| 2043 |
List_Linker_Section (Ent); |
| 2044 |
end if; |
| 2045 |
|
| 2046 |
if List_Representation_Info_To_JSON then |
| 2047 |
Write_Eol; |
| 2048 |
Write_Line ("}"); |
| 2049 |
end if; |
| 2050 |
end List_Subprogram_Info; |
| 2051 |
|
| 2052 |
-------------------- |
| 2053 |
-- List_Type_Info -- |
| 2054 |
-------------------- |
| 2055 |
|
| 2056 |
procedure List_Type_Info (Ent : Entity_Id) is |
| 2057 |
begin |
| 2058 |
Write_Separator; |
| 2059 |
|
| 2060 |
if List_Representation_Info_To_JSON then |
| 2061 |
Write_Line ("{"); |
| 2062 |
end if; |
| 2063 |
|
| 2064 |
List_Common_Type_Info (Ent); |
| 2065 |
|
| 2066 |
-- Special stuff for fixed-point |
| 2067 |
|
| 2068 |
if Is_Fixed_Point_Type (Ent) then |
| 2069 |
|
| 2070 |
-- Write small (always a static constant) |
| 2071 |
|
| 2072 |
if List_Representation_Info_To_JSON then |
| 2073 |
Write_Line (","); |
| 2074 |
Write_Str (" ""Small"": "); |
| 2075 |
UR_Write_To_JSON (Small_Value (Ent)); |
| 2076 |
else |
| 2077 |
Write_Str ("for "); |
| 2078 |
List_Name (Ent); |
| 2079 |
Write_Str ("'Small use "); |
| 2080 |
UR_Write (Small_Value (Ent)); |
| 2081 |
Write_Line (";"); |
| 2082 |
end if; |
| 2083 |
|
| 2084 |
-- Write range if static |
| 2085 |
|
| 2086 |
declare |
| 2087 |
R : constant Node_Id := Scalar_Range (Ent); |
| 2088 |
|
| 2089 |
begin |
| 2090 |
if Nkind (Low_Bound (R)) = N_Real_Literal |
| 2091 |
and then |
| 2092 |
Nkind (High_Bound (R)) = N_Real_Literal |
| 2093 |
then |
| 2094 |
if List_Representation_Info_To_JSON then |
| 2095 |
Write_Line (","); |
| 2096 |
Write_Str (" ""Range"": [ "); |
| 2097 |
UR_Write_To_JSON (Realval (Low_Bound (R))); |
| 2098 |
Write_Str (", "); |
| 2099 |
UR_Write_To_JSON (Realval (High_Bound (R))); |
| 2100 |
Write_Str (" ]"); |
| 2101 |
else |
| 2102 |
Write_Str ("for "); |
| 2103 |
List_Name (Ent); |
| 2104 |
Write_Str ("'Range use "); |
| 2105 |
UR_Write (Realval (Low_Bound (R))); |
| 2106 |
Write_Str (" .. "); |
| 2107 |
UR_Write (Realval (High_Bound (R))); |
| 2108 |
Write_Line (";"); |
| 2109 |
end if; |
| 2110 |
end if; |
| 2111 |
end; |
| 2112 |
end if; |
| 2113 |
|
| 2114 |
List_Linker_Section (Ent); |
| 2115 |
|
| 2116 |
if List_Representation_Info_To_JSON then |
| 2117 |
Write_Eol; |
| 2118 |
Write_Line ("}"); |
| 2119 |
end if; |
| 2120 |
end List_Type_Info; |
| 2121 |
|
| 2122 |
---------------------------- |
| 2123 |
-- Compile_Time_Known_Rep -- |
| 2124 |
---------------------------- |
| 2125 |
|
| 2126 |
function Compile_Time_Known_Rep (Val : Node_Ref_Or_Val) return Boolean is |
| 2127 |
begin |
| 2128 |
return Present (Val) and then Val >= 0; |
| 2129 |
end Compile_Time_Known_Rep; |
| 2130 |
|
| 2131 |
--------------- |
| 2132 |
-- Rep_Value -- |
| 2133 |
--------------- |
| 2134 |
|
| 2135 |
function Rep_Value (Val : Node_Ref_Or_Val; D : Discrim_List) return Uint is |
| 2136 |
|
| 2137 |
function B (Val : Boolean) return Ubool; |
| 2138 |
-- Returns Uint_0 for False, Uint_1 for True |
| 2139 |
|
| 2140 |
function T (Val : Node_Ref_Or_Val) return Boolean; |
| 2141 |
-- Returns True for 0, False for any non-zero (i.e. True) |
| 2142 |
|
| 2143 |
function V (Val : Node_Ref_Or_Val) return Uint; |
| 2144 |
-- Internal recursive routine to evaluate tree |
| 2145 |
|
| 2146 |
function W (Val : Uint) return Word; |
| 2147 |
-- Convert Val to Word, assuming Val is always in the Int range. This |
| 2148 |
-- is a helper function for the evaluation of bitwise expressions like |
| 2149 |
-- Bit_And_Expr, for which there is no direct support in uintp. Uint |
| 2150 |
-- values out of the Int range are expected to be seen in such |
| 2151 |
-- expressions only with overflowing byte sizes around, introducing |
| 2152 |
-- inherent unreliabilities in computations anyway. |
| 2153 |
|
| 2154 |
------- |
| 2155 |
-- B -- |
| 2156 |
------- |
| 2157 |
|
| 2158 |
function B (Val : Boolean) return Ubool is |
| 2159 |
begin |
| 2160 |
if Val then |
| 2161 |
return Uint_1; |
| 2162 |
else |
| 2163 |
return Uint_0; |
| 2164 |
end if; |
| 2165 |
end B; |
| 2166 |
|
| 2167 |
------- |
| 2168 |
-- T -- |
| 2169 |
------- |
| 2170 |
|
| 2171 |
function T (Val : Node_Ref_Or_Val) return Boolean is |
| 2172 |
begin |
| 2173 |
if V (Val) = 0 then |
| 2174 |
return False; |
| 2175 |
else |
| 2176 |
return True; |
| 2177 |
end if; |
| 2178 |
end T; |
| 2179 |
|
| 2180 |
------- |
| 2181 |
-- V -- |
| 2182 |
------- |
| 2183 |
|
| 2184 |
function V (Val : Node_Ref_Or_Val) return Uint is |
| 2185 |
L, R, Q : Uint; |
| 2186 |
|
| 2187 |
begin |
| 2188 |
if Val >= 0 then |
| 2189 |
return Val; |
| 2190 |
|
| 2191 |
else |
| 2192 |
declare |
| 2193 |
Node : Exp_Node renames Rep_Table.Table (-UI_To_Int (Val)); |
| 2194 |
|
| 2195 |
begin |
| 2196 |
case Node.Expr is |
| 2197 |
when Cond_Expr => |
| 2198 |
if T (Node.Op1) then |
| 2199 |
return V (Node.Op2); |
| 2200 |
else |
| 2201 |
return V (Node.Op3); |
| 2202 |
end if; |
| 2203 |
|
| 2204 |
when Plus_Expr => |
| 2205 |
return V (Node.Op1) + V (Node.Op2); |
| 2206 |
|
| 2207 |
when Minus_Expr => |
| 2208 |
return V (Node.Op1) - V (Node.Op2); |
| 2209 |
|
| 2210 |
when Mult_Expr => |
| 2211 |
return V (Node.Op1) * V (Node.Op2); |
| 2212 |
|
| 2213 |
when Trunc_Div_Expr => |
| 2214 |
return V (Node.Op1) / V (Node.Op2); |
| 2215 |
|
| 2216 |
when Ceil_Div_Expr => |
| 2217 |
return |
| 2218 |
UR_Ceiling |
| 2219 |
(V (Node.Op1) / UR_From_Uint (V (Node.Op2))); |
| 2220 |
|
| 2221 |
when Floor_Div_Expr => |
| 2222 |
return |
| 2223 |
UR_Floor |
| 2224 |
(V (Node.Op1) / UR_From_Uint (V (Node.Op2))); |
| 2225 |
|
| 2226 |
when Trunc_Mod_Expr => |
| 2227 |
return V (Node.Op1) rem V (Node.Op2); |
| 2228 |
|
| 2229 |
when Floor_Mod_Expr => |
| 2230 |
return V (Node.Op1) mod V (Node.Op2); |
| 2231 |
|
| 2232 |
when Ceil_Mod_Expr => |
| 2233 |
L := V (Node.Op1); |
| 2234 |
R := V (Node.Op2); |
| 2235 |
Q := UR_Ceiling (L / UR_From_Uint (R)); |
| 2236 |
return L - R * Q; |
| 2237 |
|
| 2238 |
when Exact_Div_Expr => |
| 2239 |
return V (Node.Op1) / V (Node.Op2); |
| 2240 |
|
| 2241 |
when Negate_Expr => |
| 2242 |
return -V (Node.Op1); |
| 2243 |
|
| 2244 |
when Min_Expr => |
| 2245 |
return UI_Min (V (Node.Op1), V (Node.Op2)); |
| 2246 |
|
| 2247 |
when Max_Expr => |
| 2248 |
return UI_Max (V (Node.Op1), V (Node.Op2)); |
| 2249 |
|
| 2250 |
when Abs_Expr => |
| 2251 |
return UI_Abs (V (Node.Op1)); |
| 2252 |
|
| 2253 |
when Truth_And_Expr => |
| 2254 |
return B (T (Node.Op1) and then T (Node.Op2)); |
| 2255 |
|
| 2256 |
when Truth_Or_Expr => |
| 2257 |
return B (T (Node.Op1) or else T (Node.Op2)); |
| 2258 |
|
| 2259 |
when Truth_Xor_Expr => |
| 2260 |
return B (T (Node.Op1) xor T (Node.Op2)); |
| 2261 |
|
| 2262 |
when Truth_Not_Expr => |
| 2263 |
return B (not T (Node.Op1)); |
| 2264 |
|
| 2265 |
when Bit_And_Expr => |
| 2266 |
L := V (Node.Op1); |
| 2267 |
R := V (Node.Op2); |
| 2268 |
return UI_From_Int (Int (W (L) and W (R))); |
| 2269 |
|
| 2270 |
when Lt_Expr => |
| 2271 |
return B (V (Node.Op1) < V (Node.Op2)); |
| 2272 |
|
| 2273 |
when Le_Expr => |
| 2274 |
return B (V (Node.Op1) <= V (Node.Op2)); |
| 2275 |
|
| 2276 |
when Gt_Expr => |
| 2277 |
return B (V (Node.Op1) > V (Node.Op2)); |
| 2278 |
|
| 2279 |
when Ge_Expr => |
| 2280 |
return B (V (Node.Op1) >= V (Node.Op2)); |
| 2281 |
|
| 2282 |
when Eq_Expr => |
| 2283 |
return B (V (Node.Op1) = V (Node.Op2)); |
| 2284 |
|
| 2285 |
when Ne_Expr => |
| 2286 |
return B (V (Node.Op1) /= V (Node.Op2)); |
| 2287 |
|
| 2288 |
when Discrim_Val => |
| 2289 |
declare |
| 2290 |
Sub : constant Int := UI_To_Int (Node.Op1); |
| 2291 |
begin |
| 2292 |
pragma Assert (Sub in D'Range); |
| 2293 |
return D (Sub); |
| 2294 |
end; |
| 2295 |
|
| 2296 |
when Dynamic_Val => |
| 2297 |
return No_Uint; |
| 2298 |
end case; |
| 2299 |
end; |
| 2300 |
end if; |
| 2301 |
end V; |
| 2302 |
|
| 2303 |
------- |
| 2304 |
-- W -- |
| 2305 |
------- |
| 2306 |
|
| 2307 |
-- We use an unchecked conversion to map Int values to their Word |
| 2308 |
-- bitwise equivalent, which we could not achieve with a normal type |
| 2309 |
-- conversion for negative Ints. We want bitwise equivalents because W |
| 2310 |
-- is used as a helper for bit operators like Bit_And_Expr, and can be |
| 2311 |
-- called for negative Ints in the context of aligning expressions like |
| 2312 |
-- X+Align & -Align. |
| 2313 |
|
| 2314 |
function W (Val : Uint) return Word is |
| 2315 |
function To_Word is new Ada.Unchecked_Conversion (Int, Word); |
| 2316 |
begin |
| 2317 |
return To_Word (UI_To_Int (Val)); |
| 2318 |
end W; |
| 2319 |
|
| 2320 |
-- Start of processing for Rep_Value |
| 2321 |
|
| 2322 |
begin |
| 2323 |
if No (Val) then |
| 2324 |
return No_Uint; |
| 2325 |
|
| 2326 |
else |
| 2327 |
return V (Val); |
| 2328 |
end if; |
| 2329 |
end Rep_Value; |
| 2330 |
|
| 2331 |
------------ |
| 2332 |
-- Spaces -- |
| 2333 |
------------ |
| 2334 |
|
| 2335 |
procedure Spaces (N : Natural) is |
| 2336 |
begin |
| 2337 |
for J in 1 .. N loop |
| 2338 |
Write_Char (' '); |
| 2339 |
end loop; |
| 2340 |
end Spaces; |
| 2341 |
|
| 2342 |
--------------------- |
| 2343 |
-- Write_Info_Line -- |
| 2344 |
--------------------- |
| 2345 |
|
| 2346 |
procedure Write_Info_Line (S : String) is |
| 2347 |
begin |
| 2348 |
Write_Repinfo_Line (S (S'First .. S'Last - 1)); |
| 2349 |
end Write_Info_Line; |
| 2350 |
|
| 2351 |
--------------------- |
| 2352 |
-- Write_Mechanism -- |
| 2353 |
--------------------- |
| 2354 |
|
| 2355 |
procedure Write_Mechanism (M : Mechanism_Type) is |
| 2356 |
begin |
| 2357 |
case M is |
| 2358 |
when 0 => |
| 2359 |
Write_Str ("default"); |
| 2360 |
|
| 2361 |
when -1 => |
| 2362 |
Write_Str ("copy"); |
| 2363 |
|
| 2364 |
when -2 => |
| 2365 |
Write_Str ("reference"); |
| 2366 |
|
| 2367 |
when others => |
| 2368 |
raise Program_Error; |
| 2369 |
end case; |
| 2370 |
end Write_Mechanism; |
| 2371 |
|
| 2372 |
--------------------- |
| 2373 |
-- Write_Separator -- |
| 2374 |
--------------------- |
| 2375 |
|
| 2376 |
procedure Write_Separator is |
| 2377 |
begin |
| 2378 |
if Need_Separator then |
| 2379 |
if List_Representation_Info_To_JSON then |
| 2380 |
Write_Line (","); |
| 2381 |
else |
| 2382 |
Write_Eol; |
| 2383 |
end if; |
| 2384 |
else |
| 2385 |
Need_Separator := True; |
| 2386 |
end if; |
| 2387 |
end Write_Separator; |
| 2388 |
|
| 2389 |
----------------------- |
| 2390 |
-- Write_Unknown_Val -- |
| 2391 |
----------------------- |
| 2392 |
|
| 2393 |
procedure Write_Unknown_Val is |
| 2394 |
begin |
| 2395 |
if List_Representation_Info_To_JSON then |
| 2396 |
Write_Str ("""??"""); |
| 2397 |
else |
| 2398 |
Write_Str ("??"); |
| 2399 |
end if; |
| 2400 |
end Write_Unknown_Val; |
| 2401 |
|
| 2402 |
--------------- |
| 2403 |
-- Write_Val -- |
| 2404 |
--------------- |
| 2405 |
|
| 2406 |
procedure Write_Val (Val : Node_Ref_Or_Val; Paren : Boolean := False) is |
| 2407 |
begin |
| 2408 |
if Compile_Time_Known_Rep (Val) then |
| 2409 |
UI_Write (Val, Decimal); |
| 2410 |
elsif List_Representation_Info < 3 or else No (Val) then |
| 2411 |
Write_Unknown_Val; |
| 2412 |
else |
| 2413 |
if Paren then |
| 2414 |
Write_Char ('('); |
| 2415 |
end if; |
| 2416 |
|
| 2417 |
List_GCC_Expression (Val); |
| 2418 |
|
| 2419 |
if Paren then |
| 2420 |
Write_Char (')'); |
| 2421 |
end if; |
| 2422 |
end if; |
| 2423 |
end Write_Val; |
| 2424 |
|
| 2425 |
end Repinfo; |