Commit 6f12117a by Robert Dewar Committed by Arnaud Charlet

debug.adb: Add -gnatd.O to output SCO table

2009-07-15  Robert Dewar  <dewar@adacore.com>

	* debug.adb: Add -gnatd.O to output SCO table

	* lib-writ.adb (Write_Unit_Information): Use SCO_Output to output SCO
	information.

	* lib-writ.ads: Document addition of SCO lines to ALI file

	* par_sco.ads, par_sco.adb: New files.

	* opt.ads (Generate_SCO): New switch

	* par.adb (Par): Call SCO_Record to record SCO information

	* sem_warn.adb (Warn_On_Constant_Condition): Adjust SCO condition

	* switch-c.adb: Recognize -gnateS to generate SCO information

	* usage.adb: Add line for -gnateS

	* gcc-interface/Make-lang.in: Add dependency on par_sco.o for gnat1

From-SVN: r149669
parent 3a336262
2009-07-15 Robert Dewar <dewar@adacore.com>
* debug.adb: Add -gnatd.O to output SCO table
* lib-writ.adb (Write_Unit_Information): Use SCO_Output to output SCO
information.
* lib-writ.ads: Document addition of SCO lines to ALI file
* par_sco.ads, par_sco.adb: New files.
* opt.ads (Generate_SCO): New switch
* par.adb (Par): Call SCO_Record to record SCO information
* sem_warn.adb (Warn_On_Constant_Condition): Adjust SCO condition
* switch-c.adb: Recognize -gnateS to generate SCO information
* usage.adb: Add line for -gnateS
* gcc-interface/Make-lang.in: Add dependency on par_sco.o for gnat1
2009-07-15 Sergey Rybin <rybin@adacore.com>
* tree_in.ads, tree_io.ads: Add pragma Warnings Off/On for with clause
......
......@@ -126,13 +126,13 @@ package body Debug is
-- d.F
-- d.G
-- d.H
-- d.I Inspector mode
-- d.I SCIL generation mode
-- d.J
-- d.K
-- d.L
-- d.M
-- d.N
-- d.O
-- d.O Dump internal SCO table
-- d.P
-- d.Q
-- d.R
......@@ -559,6 +559,8 @@ package body Debug is
-- byte code, even in case of unsupported construct, for the sake
-- of static analysis tools.
-- d.O Dump internal SCO (Source Coverage Obligation) table in Par_Sco
-- d.S Force Optimize_Alignment (Space) mode as the default
-- d.T Force Optimize_Alignment (Time) mode as the default
......
......@@ -139,7 +139,7 @@ GNAT_ADA_OBJS = ada/s-bitops.o ada/ada.o ada/a-charac.o ada/a-chlat1.o ada/a-exc
ada/lib-load.o ada/lib-util.o ada/lib-xref.o ada/lib-writ.o ada/live.o \
ada/namet.o ada/namet-sp.o \
ada/nlists.o ada/nmake.o ada/opt.o ada/osint.o ada/osint-c.o \
ada/output.o \
ada/output.o ada/par_sco.o \
ada/par.o ada/prep.o ada/prepcomp.o ada/repinfo.o ada/restrict.o \
ada/rident.o ada/rtsfind.o \
ada/s-addope.o ada/s-assert.o ada/s-parame.o ada/s-stache.o \
......@@ -2765,6 +2765,11 @@ ada/par.o : ada/ada.ads ada/a-except.ads ada/a-unccon.ads ada/a-uncdea.ads \
ada/unchconv.ads ada/unchdeal.ads ada/urealp.ads ada/validsw.ads \
ada/widechar.ads
ada/par_sco.o : ada/par_sco.ads ada/par_sco.adb ada/types.ads \
ada/atree.ads ada/debug.ads ada/lib.ads ada/lib-util.ads ada/nlists.ads \
ada/output.ads ada/sinfo.ads ada/sinput.ads ada/table.ads \
ada/g-htable.ads ada/snames.ads
ada/prep.o : ada/ada.ads ada/a-except.ads ada/a-unccon.ads \
ada/a-uncdea.ads ada/alloc.ads ada/casing.ads ada/csets.ads \
ada/debug.ads ada/err_vars.ads ada/gnat.ads ada/g-dyntab.ads \
......
......@@ -6,7 +6,7 @@
-- --
-- B o d y --
-- --
-- Copyright (C) 1992-2008, Free Software Foundation, Inc. --
-- Copyright (C) 1992-2009, 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- --
......@@ -38,6 +38,7 @@ with Opt; use Opt;
with Osint; use Osint;
with Osint.C; use Osint.C;
with Par;
with Par_SCO; use Par_SCO;
with Restrict; use Restrict;
with Rident; use Rident;
with Scn; use Scn;
......@@ -631,6 +632,12 @@ package body Lib.Writ is
end if;
end;
end loop;
-- Output SCO information if present
if Generate_SCO then
SCO_Output (Unit_Num);
end if;
end Write_Unit_Information;
----------------------
......
......@@ -6,7 +6,7 @@
-- --
-- S p e c --
-- --
-- Copyright (C) 1992-2008, Free Software Foundation, Inc. --
-- Copyright (C) 1992-2009, 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- --
......@@ -579,6 +579,14 @@ package Lib.Writ is
-- the source file, so that this order is preserved by the binder
-- in constructing the set of linker arguments.
-- ------------------------------------
-- -- C Source Coverage Obligations --
-- -------------------------------------
-- Following the L lines (if any) are the SCO (Source Coverage Obligation)
-- lines if they are being generated. For the full format of these lines,
-- see the spec of Par_SCO.
---------------------
-- Reference Lines --
---------------------
......
......@@ -550,6 +550,12 @@ package Opt is
-- True when switch -gnateG is used. When True, create in a file
-- <source>.prep, if the source is preprocessed.
Generate_SCO : Boolean := False;
-- GNAT
-- True when switch -gnateS is used. When True, Source Coverage Obligation
-- (SCO) information is generated and output in the ALI file. See unit
-- Sem_SCO for full details.
Generating_Code : Boolean := False;
-- GNAT
-- True if the frontend finished its work and has called the backend to
......
......@@ -35,6 +35,7 @@ with Nlists; use Nlists;
with Nmake; use Nmake;
with Opt; use Opt;
with Output; use Output;
with Par_SCO; use Par_SCO;
with Scans; use Scans;
with Scn; use Scn;
with Sinput; use Sinput;
......@@ -51,6 +52,7 @@ with Tbuild; use Tbuild;
---------
function Par (Configuration_Pragmas : Boolean) return List_Id is
Num_Library_Units : Natural := 0;
-- Count number of units parsed (relevant only in syntax check only mode,
-- since in semantics check mode only a single unit is permitted anyway)
......@@ -1453,9 +1455,17 @@ begin
pragma Assert (Scope.Last = 0);
-- Remaining steps are to create implicit label declarations and to
-- load required subsidiary sources. These steps are required only
-- if we are doing semantic checking.
-- This is where we generate SCO output if required
if Generate_SCO
and then Operating_Mode = Generate_Code
then
SCO_Record (Current_Source_Unit);
end if;
-- Remaining steps are to create implicit label declarations and to load
-- required subsidiary sources. These steps are required only if we are
-- doing semantic checking.
if Operating_Mode /= Check_Syntax or else Debug_Flag_F then
Par.Labl;
......
------------------------------------------------------------------------------
-- --
-- GNAT COMPILER COMPONENTS --
-- --
-- P A R _ S C O --
-- --
-- S p e c --
-- --
-- Copyright (C) 2009, 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. See the GNU General Public License --
-- for more details. You should have received a copy of the GNU General --
-- Public License distributed with GNAT; see file COPYING3. If not, go to --
-- http://www.gnu.org/licenses for a complete copy of the license. --
-- --
-- GNAT was originally developed by the GNAT team at New York University. --
-- Extensive contributions were provided by Ada Core Technologies Inc. --
-- --
------------------------------------------------------------------------------
-- This package contains the routines used to deal with generation and output
-- of Soure Coverage Obligations (SCO's) used for coverage analysis purposes.
with Types; use Types;
package Par_SCO is
----------------
-- SCO Format --
----------------
-- Source coverage obligations are generated on a unit-by-unit basis in the
-- ALI file, using lines that start with the identifying character C. These
-- lines are generated if the -gnatC switch is set.
-- Sloc Ranges
-- In several places in the SCO lines, Sloc ranges appear. These are used
-- to indicate the first and last Sloc of some construct in the tree and
-- they have the form:
-- line:col-line:col ??? do we need generic instantiation stuff ???
-- Statements
-- For the purpose of SCO generation, the notion of statement includes
-- simple statements and also the following declaration types:
-- type_declaration
-- subtype_declaration
-- object_declaration
-- renaming_declaration
-- generic_instantiation
-- ??? is this list complete ???
-- ??? what is the exact story on complex statements such as blocks ???
-- ??? are the simple statements inside sufficient ???
-- Statement lines
-- These lines correspond to a sequence of one or more statements which
-- are always exeecuted in sequence, The first statement may be an entry
-- point (e.g. statement after a label), and the last statement may be
-- an exit point (e.g. an exit statement), but no other entry or exit
-- points may occur within the sequence of statements. The idea is that
-- the sequence can be treated as a single unit from a coverage point of
-- view, if any of the code for the statement sequence is executed, this
-- corresponds to coverage of the entire statement sequence. The form of
-- a statement line in the ALI file is:
-- CS sloc-range
-- Entry points
-- An entry point is a statement to which control may be passed other
-- than by falling into the statement for above. Examples are the first
-- statement of the body of a loop, and the statement following a label.
-- The form of an entry point in the ALI file is:
-- CY sloc-range
-- Exit points
-- An exit point is a statement that causes transfer of control. Examples
-- are exit statements, raise statements and return statements. The form
-- of an exit point in the ALI file is:
-- CT sloc-range
-- Decisions
-- Decisions represent the most significant section of the SCO lines
-- Note: in the following description, logical operator includes the
-- short circuited forms (so can be any of AND, OR, XOR, NOT, AND THEN,
-- or OR ELSE).
-- Decisions are either simple or complex. A simple decision is a boolean
-- expresssion that occurs in the context of a control structure in the
-- source program, including WHILE, IF, EXIT WHEN. Note that a boolean
-- expression in any other context, e.g. on the right side of an
-- assignment, is not considered to be a decision.
-- A complex decision is an occurrence of a logical operator which is not
-- itself an operand of some other logical operator. If any operand of
-- the logical operator is itself a logical operator, this is not a
-- separate decision, it is part of the same decision.
-- So for example, if we have
-- A, B, C, D : Boolean;
-- function F (Arg : Boolean) return Boolean);
-- ...
-- A and then (B or else F (C and then D))
-- There are two (complex) decisions here:
-- 1. X and then (Y or else Z)
-- where X = A, Y = B, and Z = F (C and then D)
-- 2. C and then D
-- For each decision, a decision line is generated with the form:
-- C* expression
-- Here * is one of the following characters:
-- I decision in IF statement or conditional expression
-- E decision in EXIT WHEN statement
-- W decision in WHILE iteration scheme
-- X decision appearing in some other expression context
-- The expression is a prefix polish form indicating the structure of
-- the decision, including logical operators and short circuit forms.
-- The following is a grammar showing the structure of expression:
-- expression ::= term (if expr is not logical operator)
-- expression ::= & term term (if expr is AND or AND THEN)
-- expression ::= | term term (if expr is OR or OR ELSE)
-- expression ::= ^ term term (if expr is XOR)
-- expression ::= !term (if expr is NOT)
-- term ::= element
-- term ::= expression
-- element ::= outcome sloc-range
-- outcome is one of the following letters:
-- c condition
-- t true condition
-- f false condition
-- where t/f are used to mark a condition that has been recognized by
-- the compiler as always being true or false.
-- & indicates either AND or AND THEN connecting two conditions. In the
-- context of couverture we only permit AND THEN in the source in any
-- case, so & can always be understood to be AND THEN.
-- | indicates either OR or OR ELSE connection two conditions. In the
-- context of couverture we only permit OR ELSE in the source in any
-- case, so | can always be understood to be OR ELSE.
-- ^ indicates XOR connecting two conditions. In the context of
-- couverture, we do not permit XOR, so this will never appear.
-- ! indicates NOT applied to the expression.
-----------------
-- Subprograms --
-----------------
procedure Init;
-- Initialize internal tables for a new compilation
procedure SCO_Record (U : Unit_Number_Type);
-- This procedure scans the tree for the unit identified by U, populating
-- internal tables recording the SCO information. Note that this is done
-- before any semantic analysis/expansion happens.
procedure Set_SCO_Condition (First_Loc : Source_Ptr; Typ : Character);
-- This procedure is called during semantic analysis to record a condition
-- which has been identified as always True (Typ = 't') or always False
-- (Typ = 'f') by the compiler. The condition is identified by the
-- First_Sloc value in the original tree.
procedure SCO_Output (U : Unit_Number_Type);
-- Outputs SCO lines for unit U in the ALI file, as recorded by a previous
-- call to SCO_Record, possibly modified by calls to Set_SCO_Condition.
end Par_SCO;
......@@ -33,6 +33,7 @@ with Lib; use Lib;
with Namet; use Namet;
with Nlists; use Nlists;
with Opt; use Opt;
with Par_SCO; use Par_SCO;
with Rtsfind; use Rtsfind;
with Sem; use Sem;
with Sem_Ch8; use Sem_Ch8;
......@@ -3307,7 +3308,8 @@ package body Sem_Warn is
-----------------------------
procedure Warn_On_Known_Condition (C : Node_Id) is
P : Node_Id;
P : Node_Id;
Orig : constant Node_Id := Original_Node (C);
procedure Track (N : Node_Id; Loc : Node_Id);
-- Adds continuation warning(s) pointing to reason (assignment or test)
......@@ -3356,6 +3358,35 @@ package body Sem_Warn is
-- Start of processing for Warn_On_Known_Condition
begin
-- Adjust SCO condition if from source
if Comes_From_Source (Orig) then
declare
Start : Source_Ptr;
Dummy : Source_Ptr;
Typ : Character;
Atrue : Boolean;
begin
Sloc_Range (Orig, Start, Dummy);
Atrue := Entity (C) = Standard_True;
if Present (Parent (C))
and then Nkind (Parent (C)) = N_Op_Not
then
Atrue := not Atrue;
end if;
if Atrue then
Typ := 't';
else
Typ := 'f';
end if;
Set_SCO_Condition (Start, Typ);
end;
end if;
-- Argument replacement in an inlined body can make conditions static.
-- Do not emit warnings in this case.
......
......@@ -462,11 +462,19 @@ package body Switch.C is
Ptr := Max + 1;
-- -gnatez ???
when 'z' =>
Store_Switch := False;
Disable_Switch_Storing;
Ptr := Ptr + 1;
-- -gnateS (Store SCO information)
when 'S' =>
Generate_SCO := True;
Ptr := Ptr + 1;
-- All other -gnate? switches are unassigned
when others =>
......
......@@ -202,6 +202,11 @@ begin
Write_Switch_Char ("ep=?");
Write_Line ("Specify preprocessing data file, e.g. -gnatep=prep.data");
-- Line for -gnateS switch
Write_Switch_Char ("eS");
Write_Line ("Generate SCO (Source Coverage Obligation) information");
-- Line for -gnatE switch
Write_Switch_Char ("E");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment