[Ada] New Repinfo.Input unit to read back JSON representation info.
For some time the Repinfo unit has been able to output the representation information in the JSON data interchange format in addition to the usual text and binary formats. The new Repinfo.Input unit makes it possible to read back this information under this format and make it available to clients, the main one being ASIS. The big advantage of using this approach over manipulating a binary blob is that the writer and the reader of the JSON representation need not be binary compatible, i.e. in practice need not be the same version of the compiler or ASIS for the same target. The patch also adds a -gnatd_j switch to read back the information in the compiler itself, which makes it easy to keep the writer and the reader in sync using only one tool, namely the compiler. The typical usage is: gcc -c p.ads -gnatR4js gcc -c p.ads -gnatd_j to exercise respectively the writer and the reader from the compiler. 2019-07-11 Eric Botcazou <ebotcazou@adacore.com> gcc/ada/ * alloc.ads (Rep_JSON_Table_Initial): New constant. (Rep_JSON_Table_Increment): Likewise. * debug.adb: Document -gnatd_j switch. * gcc-interface/Make-lang.in (GNAT_ADA_OBJS): Add repinfo-input.o. * gnat1drv.adb: Add with clause for Repinfo.Input. Add with and use clauses for Sinput. (Read_JSON_Files_For_Repinfo): New procedure. (Gnat1drv1): Deal with -gnatd_j switch. * repinfo-input.ad[sb]: New unit. * snames.ads-tmpl (Name_Discriminant): New constant. (Name_Operands): Likewise. From-SVN: r273382
This commit is contained in:
parent
ccf1730596
commit
6c1657116a
@ -1,3 +1,18 @@
|
||||
2019-07-11 Eric Botcazou <ebotcazou@adacore.com>
|
||||
|
||||
* alloc.ads (Rep_JSON_Table_Initial): New constant.
|
||||
(Rep_JSON_Table_Increment): Likewise.
|
||||
* debug.adb: Document -gnatd_j switch.
|
||||
* gcc-interface/Make-lang.in (GNAT_ADA_OBJS): Add
|
||||
repinfo-input.o.
|
||||
* gnat1drv.adb: Add with clause for Repinfo.Input.
|
||||
Add with and use clauses for Sinput.
|
||||
(Read_JSON_Files_For_Repinfo): New procedure.
|
||||
(Gnat1drv1): Deal with -gnatd_j switch.
|
||||
* repinfo-input.ad[sb]: New unit.
|
||||
* snames.ads-tmpl (Name_Discriminant): New constant.
|
||||
(Name_Operands): Likewise.
|
||||
|
||||
2019-07-11 Justin Squirek <squirek@adacore.com>
|
||||
|
||||
* checks.adb (Apply_Accessibility_Check): Add check for constant
|
||||
|
@ -116,6 +116,9 @@ package Alloc is
|
||||
Rep_Table_Initial : constant := 1000; -- Repinfo
|
||||
Rep_Table_Increment : constant := 200;
|
||||
|
||||
Rep_JSON_Table_Initial : constant := 10; -- Repinfo
|
||||
Rep_JSON_Table_Increment : constant := 200;
|
||||
|
||||
Scope_Stack_Initial : constant := 10; -- Sem
|
||||
Scope_Stack_Increment : constant := 200;
|
||||
|
||||
|
@ -154,7 +154,7 @@ package body Debug is
|
||||
-- d_g
|
||||
-- d_h
|
||||
-- d_i Ignore activations and calls to instances for elaboration
|
||||
-- d_j
|
||||
-- d_j Read JSON files and populate Repinfo tables (opposite of -gnatRjs)
|
||||
-- d_k
|
||||
-- d_l
|
||||
-- d_m
|
||||
@ -988,6 +988,10 @@ package body Debug is
|
||||
-- subprogram or task type defined in an external instance for both
|
||||
-- the static and dynamic elaboration models.
|
||||
|
||||
-- d_j The compiler reads JSON files that would be generated by the same
|
||||
-- compilation session if -gnatRjs was passed, in order to populate
|
||||
-- the internal tables of the Repinfo unit from them.
|
||||
|
||||
-- d_p The compiler ignores calls to subprograms which verify the run-time
|
||||
-- semantics of invariants and postconditions in both the static and
|
||||
-- dynamic elaboration models.
|
||||
|
@ -355,6 +355,7 @@ GNAT_ADA_OBJS = \
|
||||
ada/prep.o \
|
||||
ada/prepcomp.o \
|
||||
ada/put_scos.o \
|
||||
ada/repinfo-input.o \
|
||||
ada/repinfo.o \
|
||||
ada/restrict.o \
|
||||
ada/rident.o \
|
||||
|
@ -51,6 +51,7 @@ with Output; use Output;
|
||||
with Par_SCO;
|
||||
with Prepcomp;
|
||||
with Repinfo;
|
||||
with Repinfo.Input;
|
||||
with Restrict;
|
||||
with Rident; use Rident;
|
||||
with Rtsfind;
|
||||
@ -66,6 +67,7 @@ with Sem_SPARK; use Sem_SPARK;
|
||||
with Sem_Type;
|
||||
with Set_Targ;
|
||||
with Sinfo; use Sinfo;
|
||||
with Sinput; use Sinput;
|
||||
with Sinput.L; use Sinput.L;
|
||||
with Snames; use Snames;
|
||||
with Sprint; use Sprint;
|
||||
@ -114,6 +116,12 @@ procedure Gnat1drv is
|
||||
-- the information provided by the back end in back annotation of declared
|
||||
-- entities (e.g. actual size and alignment values chosen by the back end).
|
||||
|
||||
procedure Read_JSON_Files_For_Repinfo;
|
||||
-- This procedure exercises the JSON parser of Repinfo by reading back the
|
||||
-- JSON files generated by -gnatRjs in a previous compilation session. It
|
||||
-- is intended to make sure that the JSON generator and the JSON parser are
|
||||
-- kept synchronized when the JSON format evolves.
|
||||
|
||||
----------------------------
|
||||
-- Adjust_Global_Switches --
|
||||
----------------------------
|
||||
@ -1037,6 +1045,38 @@ procedure Gnat1drv is
|
||||
-- end if;
|
||||
end Post_Compilation_Validation_Checks;
|
||||
|
||||
-----------------------------------
|
||||
-- Read_JSON_Files_For_Repinfo --
|
||||
-----------------------------------
|
||||
|
||||
procedure Read_JSON_Files_For_Repinfo is
|
||||
begin
|
||||
-- This is the same loop construct as in Repinfo.List_Rep_Info
|
||||
|
||||
for U in Main_Unit .. Last_Unit loop
|
||||
if In_Extended_Main_Source_Unit (Cunit_Entity (U)) then
|
||||
declare
|
||||
Nam : constant String :=
|
||||
Get_Name_String (File_Name (Source_Index (U))) & ".json";
|
||||
Namid : constant File_Name_Type := Name_Enter (Nam);
|
||||
Index : constant Source_File_Index := Load_Config_File (Namid);
|
||||
|
||||
begin
|
||||
if Index = No_Source_File then
|
||||
Write_Str ("cannot locate ");
|
||||
Write_Line (Nam);
|
||||
raise Unrecoverable_Error;
|
||||
end if;
|
||||
|
||||
Repinfo.Input.Read_JSON_Stream (Source_Text (Index).all, Nam);
|
||||
exception
|
||||
when Repinfo.Input.Invalid_JSON_Stream =>
|
||||
raise Unrecoverable_Error;
|
||||
end;
|
||||
end if;
|
||||
end loop;
|
||||
end Read_JSON_Files_For_Repinfo;
|
||||
|
||||
-- Local variables
|
||||
|
||||
Back_End_Mode : Back_End.Back_End_Mode_Type;
|
||||
@ -1103,7 +1143,6 @@ begin
|
||||
-- Acquire target parameters from system.ads (package System source)
|
||||
|
||||
Targparm_Acquire : declare
|
||||
use Sinput;
|
||||
|
||||
S : Source_File_Index;
|
||||
N : File_Name_Type;
|
||||
@ -1571,6 +1610,12 @@ begin
|
||||
Par_SCO.SCO_Record_Filtered;
|
||||
end if;
|
||||
|
||||
-- If -gnatd_j is specified, exercise the JSON parser of Repinfo
|
||||
|
||||
if Debug_Flag_Underscore_J then
|
||||
Read_JSON_Files_For_Repinfo;
|
||||
end if;
|
||||
|
||||
-- Back end needs to explicitly unlock tables it needs to touch
|
||||
|
||||
Atree.Lock;
|
||||
|
1350
gcc/ada/repinfo-input.adb
Normal file
1350
gcc/ada/repinfo-input.adb
Normal file
File diff suppressed because it is too large
Load Diff
78
gcc/ada/repinfo-input.ads
Normal file
78
gcc/ada/repinfo-input.ads
Normal file
@ -0,0 +1,78 @@
|
||||
------------------------------------------------------------------------------
|
||||
-- --
|
||||
-- GNAT COMPILER COMPONENTS --
|
||||
-- --
|
||||
-- R E P I N F O - I N P U T --
|
||||
-- --
|
||||
-- S p e c --
|
||||
-- --
|
||||
-- Copyright (C) 2018-2019, Free Software Foundation, Inc. --
|
||||
-- --
|
||||
-- GNAT is free software; you can redistribute it and/or modify it under --
|
||||
-- terms of the GNU General Public License as published by the Free Soft- --
|
||||
-- ware Foundation; either version 3, or (at your option) any later ver- --
|
||||
-- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
|
||||
-- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
|
||||
-- or FITNESS FOR A PARTICULAR PURPOSE. --
|
||||
-- --
|
||||
-- As a special exception under Section 7 of GPL version 3, you are granted --
|
||||
-- additional permissions described in the GCC Runtime Library Exception, --
|
||||
-- version 3.1, as published by the Free Software Foundation. --
|
||||
-- --
|
||||
-- You should have received a copy of the GNU General Public License and --
|
||||
-- a copy of the GCC Runtime Library Exception along with this program; --
|
||||
-- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
|
||||
-- <http://www.gnu.org/licenses/>. --
|
||||
-- --
|
||||
-- GNAT was originally developed by the GNAT team at New York University. --
|
||||
-- Extensive contributions were provided by Ada Core Technologies Inc. --
|
||||
-- --
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
-- This package provides an alternate way of populating the internal tables
|
||||
-- of Repinfo from a JSON input rather than the binary blob of the tree file.
|
||||
-- Note that this is an additive mechanism, i.e. nothing is destroyed in the
|
||||
-- internal state of the unit when it is used.
|
||||
|
||||
-- The first step is to feed the unit with a JSON stream of a specified format
|
||||
-- (see the spec of Repinfo for its description) by means of Read_JSON_Stream.
|
||||
-- Then, for each entity whose representation information is present in the
|
||||
-- JSON stream, the appropriate Get_JSON_* routines can be invoked to override
|
||||
-- the eponymous fields of the entity in the tree.
|
||||
|
||||
package Repinfo.Input is
|
||||
|
||||
function Get_JSON_Esize (Name : String) return Node_Ref_Or_Val;
|
||||
-- Returns the Esize value of the entity specified by Name, which is not
|
||||
-- the component of a record type, or else No_Uint if no representation
|
||||
-- information was supplied for the entity. Name is the full qualified name
|
||||
-- of the entity in lower case letters.
|
||||
|
||||
function Get_JSON_RM_Size (Name : String) return Node_Ref_Or_Val;
|
||||
-- Likewise for the RM_Size
|
||||
|
||||
function Get_JSON_Component_Size (Name : String) return Node_Ref_Or_Val;
|
||||
-- Likewise for the Component_Size of an array type
|
||||
|
||||
function Get_JSON_Component_Bit_Offset
|
||||
(Name : String;
|
||||
Record_Name : String) return Node_Ref_Or_Val;
|
||||
-- Returns the Component_Bit_Offset of the component specified by Name,
|
||||
-- which is declared in the record type specified by Record_Name, or else
|
||||
-- No_Uint if no representation information was supplied for the component.
|
||||
-- Name is the unqualified name of the component whereas Record_Name is the
|
||||
-- full qualified name of the record type, both in lower case letters.
|
||||
|
||||
function Get_JSON_Esize
|
||||
(Name : String;
|
||||
Record_Name : String) return Node_Ref_Or_Val;
|
||||
-- Likewise for the Esize
|
||||
|
||||
Invalid_JSON_Stream : exception;
|
||||
-- Raised if a format error is detected in the JSON stream
|
||||
|
||||
procedure Read_JSON_Stream (Text : Text_Buffer; File_Name : String);
|
||||
-- Reads a JSON stream and populates internal tables from it. File_Name is
|
||||
-- only used in error messages issued by the JSON parser.
|
||||
|
||||
end Repinfo.Input;
|
@ -1511,6 +1511,11 @@ package Snames is
|
||||
Name_Runtime_Library_Dir : constant Name_Id := N + $;
|
||||
Name_Runtime_Source_Dir : constant Name_Id := N + $;
|
||||
|
||||
-- Additional names used by the Repinfo unit
|
||||
|
||||
Name_Discriminant : constant Name_Id := N + $;
|
||||
Name_Operands : constant Name_Id := N + $;
|
||||
|
||||
-- Other miscellaneous names used in front end
|
||||
|
||||
Name_Unaligned_Valid : constant Name_Id := N + $;
|
||||
|
Loading…
Reference in New Issue
Block a user