(********************************************************************)
(*                                                                  *)
(*  stat.s7i      Statistics support.                               *)
(*  Copyright (C) 1990 - 1994, 2004 - 2014, 2022  Thomas Mertes     *)
(*                                                                  *)
(*  This file is part of the Seed7 compiler.                        *)
(*                                                                  *)
(*  This program is free software; you can redistribute it and/or   *)
(*  modify it under the terms of the GNU General Public License as  *)
(*  published by the Free Software Foundation; either version 2 of  *)
(*  the License, or (at your option) any later version.             *)
(*                                                                  *)
(*  This program is distributed in the hope that it will be useful, *)
(*  but WITHOUT ANY WARRANTY; without even the implied warranty of  *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   *)
(*  GNU General Public License for more details.                    *)
(*                                                                  *)
(*  You should have received a copy of the GNU General Public       *)
(*  License along with this program; if not, write to the           *)
(*  Free Software Foundation, Inc., 51 Franklin Street,             *)
(*  Fifth Floor, Boston, MA  02110-1301, USA.                       *)
(*                                                                  *)
(********************************************************************)


const type: compilerStatistic is new struct
    var integer: declarations             is 0;
    var integer: optimizations            is 0;
    var integer: inlinedFunctions         is 0;
    var integer: evaluations              is 0;
    var integer: divisionChecks           is 0;
    var integer: optimizedDivisionChecks  is 0;
    var integer: rangeChecks              is 0;
    var integer: optimizedRangeChecks     is 0;
    var integer: noRangeChecks            is 0;
    var integer: indexChecks              is 0;
    var integer: optimizedIndexChecks     is 0;
    var integer: suppressedIndexChecks    is 0;
    var integer: overflowChecks           is 0;
    var integer: optimizedOverflowChecks  is 0;
    var integer: suppressedOverflowChecks is 0;
  end struct;

var compilerStatistic: count is compilerStatistic.value;


const proc: countDivisionOptimizations (in expr_type: c_expr) is func
  begin
    incr(count.optimizedDivisionChecks);
    # writeln(c_expr.currentFile <& "(" <& c_expr.currentLine <& "): Division check optimized away.");
  end func;


const proc: countIndexOptimizations (in expr_type: c_expr) is func
  begin
    incr(count.optimizedIndexChecks);
    # writeln(c_expr.currentFile <& "(" <& c_expr.currentLine <& "): Index check optimized away.");
  end func;


const proc: countRangeOptimizations (in expr_type: c_expr) is func
  begin
    incr(count.optimizedRangeChecks);
    # writeln(c_expr.currentFile <& "(" <& c_expr.currentLine <& "): Range check optimized away.");
  end func;


const proc: countOverflowOptimizations (in expr_type: c_expr) is func
  begin
    incr(count.optimizedOverflowChecks);
    # writeln(c_expr.currentFile <& "(" <& c_expr.currentLine <& "): Overflow check optimized away.");
  end func;