LCOV - code coverage report
Current view: top level - /mnt/build/buildbot/bld/build-lcov/gcc/m2/gm2-compiler-boot - M2Code.c (source / functions) Coverage Total Hit
Test: gcc.info Lines: 77.8 % 198 154
Test Date: 2025-10-18 14:39:06 Functions: 82.4 % 17 14
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* do not edit automatically generated by mc from M2Code.  */
       2                 :             : /* M2Code.mod coordinate the activity of the front end.
       3                 :             : 
       4                 :             : Copyright (C) 2001-2025 Free Software Foundation, Inc.
       5                 :             : Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
       6                 :             : 
       7                 :             : This file is part of GNU Modula-2.
       8                 :             : 
       9                 :             : GNU Modula-2 is free software; you can redistribute it and/or modify
      10                 :             : it under the terms of the GNU General Public License as published by
      11                 :             : the Free Software Foundation; either version 3, or (at your option)
      12                 :             : any later version.
      13                 :             : 
      14                 :             : GNU Modula-2 is distributed in the hope that it will be useful, but
      15                 :             : WITHOUT ANY WARRANTY; without even the implied warranty of
      16                 :             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17                 :             : General Public License for more details.
      18                 :             : 
      19                 :             : You should have received a copy of the GNU General Public License
      20                 :             : along with GNU Modula-2; see the file COPYING3.  If not see
      21                 :             : <http://www.gnu.org/licenses/>.  */
      22                 :             : 
      23                 :             : #include "config.h"
      24                 :             : #include "system.h"
      25                 :             : #include "gcc-consolidation.h"
      26                 :             : 
      27                 :             : #include <stdbool.h>
      28                 :             : #   if !defined (PROC_D)
      29                 :             : #      define PROC_D
      30                 :             :        typedef void (*PROC_t) (void);
      31                 :             :        typedef struct { PROC_t proc; } PROC;
      32                 :             : #   endif
      33                 :             : 
      34                 :             : #   if !defined (TRUE)
      35                 :             : #      define TRUE (1==1)
      36                 :             : #   endif
      37                 :             : 
      38                 :             : #   if !defined (FALSE)
      39                 :             : #      define FALSE (1==0)
      40                 :             : #   endif
      41                 :             : 
      42                 :             : #define _M2Code_C
      43                 :             : 
      44                 :             : #include "GM2Code.h"
      45                 :             : #   include "GSYSTEM.h"
      46                 :             : #   include "GM2Options.h"
      47                 :             : #   include "GM2LangDump.h"
      48                 :             : #   include "GM2Error.h"
      49                 :             : #   include "GM2Students.h"
      50                 :             : #   include "GSymbolTable.h"
      51                 :             : #   include "GM2Printf.h"
      52                 :             : #   include "GNameKey.h"
      53                 :             : #   include "GM2Batch.h"
      54                 :             : #   include "GM2Quads.h"
      55                 :             : #   include "GM2SymInit.h"
      56                 :             : #   include "GM2Pass.h"
      57                 :             : #   include "GM2BasicBlock.h"
      58                 :             : #   include "GM2Optimize.h"
      59                 :             : #   include "GM2GenGCC.h"
      60                 :             : #   include "GM2GCCDeclare.h"
      61                 :             : #   include "GM2Scope.h"
      62                 :             : #   include "Gm2top.h"
      63                 :             : #   include "GM2Swig.h"
      64                 :             : #   include "Gm2flex.h"
      65                 :             : #   include "GFIO.h"
      66                 :             : #   include "GM2Quiet.h"
      67                 :             : #   include "GM2SSA.h"
      68                 :             : #   include "Gm2pp.h"
      69                 :             : #   include "GDynamicStrings.h"
      70                 :             : #   include "GM2Diagnostic.h"
      71                 :             : 
      72                 :             : #   define MaxOptimTimes 10
      73                 :             : #   define Debugging true
      74                 :             : #   define TraceQuadruples false
      75                 :             : static unsigned int Total;
      76                 :             : static unsigned int Count;
      77                 :             : static unsigned int OptimTimes;
      78                 :             : static unsigned int DeltaProc;
      79                 :             : static unsigned int Proc;
      80                 :             : static unsigned int DeltaConst;
      81                 :             : static unsigned int Const;
      82                 :             : static unsigned int DeltaJump;
      83                 :             : static unsigned int Jump;
      84                 :             : static unsigned int DeltaBasicB;
      85                 :             : static unsigned int BasicB;
      86                 :             : 
      87                 :             : /*
      88                 :             :    Code - calls procedures to generates trees from the quadruples.
      89                 :             :           All front end quadruple optimization is performed via this call.
      90                 :             : */
      91                 :             : 
      92                 :             : extern "C" void M2Code_Code (void);
      93                 :             : 
      94                 :             : /*
      95                 :             :    CodeBlock - generates all code for this block and also declares
      96                 :             :                all types and procedures for this block. It will
      97                 :             :                also optimize quadruples within this scope.
      98                 :             : */
      99                 :             : 
     100                 :             : extern "C" void M2Code_CodeBlock (unsigned int scope);
     101                 :             : 
     102                 :             : /*
     103                 :             :    Percent - calculates the percentage from numerator and divisor
     104                 :             : */
     105                 :             : 
     106                 :             : static void Percent (unsigned int numerator, unsigned int divisor);
     107                 :             : 
     108                 :             : /*
     109                 :             :    ResourceAnalysis - displays resource analysis relating to the front end.
     110                 :             : */
     111                 :             : 
     112                 :             : static void ResourceAnalysis (void);
     113                 :             : 
     114                 :             : /*
     115                 :             :    RemoveUnreachableCode -
     116                 :             : */
     117                 :             : 
     118                 :             : static void RemoveUnreachableCode (void);
     119                 :             : 
     120                 :             : /*
     121                 :             :    DoModuleDeclare - declare all constants, types, variables, procedures for the
     122                 :             :                      main module or all modules.
     123                 :             : */
     124                 :             : 
     125                 :             : static void DoModuleDeclare (void);
     126                 :             : 
     127                 :             : /*
     128                 :             :    DoCodeBlock - generate code for the main module or all modules.
     129                 :             : */
     130                 :             : 
     131                 :             : static void DoCodeBlock (void);
     132                 :             : 
     133                 :             : /*
     134                 :             :    DetermineSubExpTemporaries -
     135                 :             : */
     136                 :             : 
     137                 :             : static void DetermineSubExpTemporaries (void);
     138                 :             : static void InitialDeclareAndOptimize (unsigned int scope, unsigned int start, unsigned int end);
     139                 :             : static void SecondDeclareAndOptimize (unsigned int scope, unsigned int start, unsigned int end);
     140                 :             : 
     141                 :             : /*
     142                 :             :    InitOptimizeVariables -
     143                 :             : */
     144                 :             : 
     145                 :             : static void InitOptimizeVariables (void);
     146                 :             : 
     147                 :             : /*
     148                 :             :    Init -
     149                 :             : */
     150                 :             : 
     151                 :             : static void Init (void);
     152                 :             : 
     153                 :             : /*
     154                 :             :    OptimizeScopeBlock -
     155                 :             : */
     156                 :             : 
     157                 :             : static void OptimizeScopeBlock (M2Scope_ScopeBlock sb);
     158                 :             : 
     159                 :             : /*
     160                 :             :    CodeProceduresWithinBlock - codes the procedures within the module scope.
     161                 :             : */
     162                 :             : 
     163                 :             : static void CodeProceduresWithinBlock (unsigned int scope);
     164                 :             : 
     165                 :             : /*
     166                 :             :    CodeProcedures -
     167                 :             : */
     168                 :             : 
     169                 :             : static void CodeProcedures (unsigned int scope);
     170                 :             : 
     171                 :             : 
     172                 :             : /*
     173                 :             :    Percent - calculates the percentage from numerator and divisor
     174                 :             : */
     175                 :             : 
     176                 :           0 : static void Percent (unsigned int numerator, unsigned int divisor)
     177                 :             : {
     178                 :           0 :   unsigned int value;
     179                 :             : 
     180                 :           0 :   M2Printf_printf0 ((const char *) "  (", 3);
     181                 :           0 :   if (divisor == 0)
     182                 :             :     {
     183                 :           0 :       M2Printf_printf0 ((const char *) "overflow error", 14);
     184                 :             :     }
     185                 :             :   else
     186                 :             :     {
     187                 :           0 :       value = (numerator*100) / divisor;
     188                 :           0 :       M2Printf_printf1 ((const char *) "%3d", 3, (const unsigned char *) &value, (sizeof (value)-1));
     189                 :             :     }
     190                 :           0 :   M2Printf_printf0 ((const char *) "\\%)", 3);
     191                 :           0 : }
     192                 :             : 
     193                 :             : 
     194                 :             : /*
     195                 :             :    ResourceAnalysis - displays resource analysis relating to the front end.
     196                 :             : */
     197                 :             : 
     198                 :       14227 : static void ResourceAnalysis (void)
     199                 :             : {
     200                 :       14227 :   unsigned int value;
     201                 :             : 
     202                 :       14227 :   if (M2Options_Statistics)
     203                 :             :     {
     204                 :           0 :       Count = M2Quads_CountQuads ();
     205                 :           0 :       M2Printf_printf1 ((const char *) "M2 initial number of quadruples: %6d", 36, (const unsigned char *) &Total, (sizeof (Total)-1));
     206                 :           0 :       Percent (Total, Total);
     207                 :           0 :       M2Printf_printf0 ((const char *) "\\n", 2);
     208                 :           0 :       M2Printf_printf1 ((const char *) "M2 constant folding achieved   : %6d", 36, (const unsigned char *) &Const, (sizeof (Const)-1));
     209                 :           0 :       Percent (Const, Total);
     210                 :           0 :       M2Printf_printf0 ((const char *) "\\n", 2);
     211                 :           0 :       M2Printf_printf1 ((const char *) "M2 branch folding achieved     : %6d", 36, (const unsigned char *) &Jump, (sizeof (Jump)-1));
     212                 :           0 :       Percent (Jump, Total);
     213                 :           0 :       M2Printf_printf0 ((const char *) "\\n", 2);
     214                 :           0 :       value = (Const+Jump)+Proc;
     215                 :           0 :       M2Printf_printf1 ((const char *) "Front end optimization removed : %6d", 36, (const unsigned char *) &value, (sizeof (value)-1));
     216                 :           0 :       Percent (value, Total);
     217                 :           0 :       M2Printf_printf0 ((const char *) "\\n", 2);
     218                 :           0 :       M2Printf_printf1 ((const char *) "Front end final                : %6d", 36, (const unsigned char *) &Count, (sizeof (Count)-1));
     219                 :           0 :       Percent (Count, Total);
     220                 :           0 :       M2Printf_printf0 ((const char *) "\\n", 2);
     221                 :           0 :       Count = m2flex_GetTotalLines ();
     222                 :           0 :       M2Printf_printf1 ((const char *) "Total source lines compiled    : %6d\\n", 38, (const unsigned char *) &Count, (sizeof (Count)-1));
     223                 :           0 :       FIO_FlushBuffer (FIO_StdOut);
     224                 :             :     }
     225                 :       14227 :   M2Quads_DumpQuadruples ((const char *) "after all front end optimization\\n", 34);
     226                 :       14227 : }
     227                 :             : 
     228                 :             : 
     229                 :             : /*
     230                 :             :    RemoveUnreachableCode -
     231                 :             : */
     232                 :             : 
     233                 :       14515 : static void RemoveUnreachableCode (void)
     234                 :             : {
     235                 :       14515 :   if (M2Options_WholeProgram)
     236                 :             :     {
     237                 :          24 :       M2Batch_ForeachSourceModuleDo ((M2Batch_DoProcedure) {(M2Batch_DoProcedure_t) M2Optimize_RemoveProcedures});
     238                 :             :     }
     239                 :             :   else
     240                 :             :     {
     241                 :       14491 :       M2Optimize_RemoveProcedures (SymbolTable_GetMainModule ());
     242                 :             :     }
     243                 :       14515 : }
     244                 :             : 
     245                 :             : 
     246                 :             : /*
     247                 :             :    DoModuleDeclare - declare all constants, types, variables, procedures for the
     248                 :             :                      main module or all modules.
     249                 :             : */
     250                 :             : 
     251                 :       14515 : static void DoModuleDeclare (void)
     252                 :             : {
     253                 :       14515 :   if (M2Options_GetDumpDecl ())
     254                 :             :     {
     255                 :           0 :       M2LangDump_CreateDumpDecl ((const char *) "symbol resolver of filtered symbols\\n", 37);
     256                 :           0 :       M2GCCDeclare_DumpFilteredResolver ();
     257                 :             :     }
     258                 :       14515 :   if (M2Options_WholeProgram)
     259                 :             :     {
     260                 :          24 :       M2Batch_ForeachSourceModuleDo ((M2Batch_DoProcedure) {(M2Batch_DoProcedure_t) M2GCCDeclare_StartDeclareScope});
     261                 :             :     }
     262                 :             :   else
     263                 :             :     {
     264                 :       14491 :       M2GCCDeclare_StartDeclareScope (SymbolTable_GetMainModule ());
     265                 :             :     }
     266                 :       14455 :   if (M2Options_GetDumpDecl ())
     267                 :             :     {
     268                 :           0 :       M2LangDump_CloseDumpDecl ();
     269                 :           0 :       M2LangDump_CreateDumpDecl ((const char *) "definitive declaration of filtered symbols\\n", 44);
     270                 :           0 :       M2GCCDeclare_DumpFilteredDefinitive ();
     271                 :           0 :       M2LangDump_CloseDumpDecl ();
     272                 :             :     }
     273                 :       14455 : }
     274                 :             : 
     275                 :             : 
     276                 :             : /*
     277                 :             :    DoCodeBlock - generate code for the main module or all modules.
     278                 :             : */
     279                 :             : 
     280                 :       14371 : static void DoCodeBlock (void)
     281                 :             : {
     282                 :       14371 :   DynamicStrings_String filename;
     283                 :       14371 :   unsigned int len;
     284                 :             : 
     285                 :       14371 :   if (M2Options_GetDumpGimple ())
     286                 :             :     {
     287                 :           0 :       filename = M2LangDump_MakeGimpleTemplate (&len);
     288                 :           0 :       m2pp_CreateDumpGimple (reinterpret_cast <void *> (filename), len);
     289                 :           0 :       filename = DynamicStrings_KillString (filename);
     290                 :           0 :       M2Code_CodeBlock (SymbolTable_GetMainModule ());
     291                 :           0 :       m2pp_CloseDumpGimple ();
     292                 :             :     }
     293                 :             :   else
     294                 :             :     {
     295                 :       14371 :       M2Code_CodeBlock (SymbolTable_GetMainModule ());
     296                 :             :     }
     297                 :       14227 : }
     298                 :             : 
     299                 :             : 
     300                 :             : /*
     301                 :             :    DetermineSubExpTemporaries -
     302                 :             : */
     303                 :             : 
     304                 :       14515 : static void DetermineSubExpTemporaries (void)
     305                 :             : {
     306                 :       14515 :   if (M2Options_WholeProgram)
     307                 :             :     {
     308                 :          24 :       M2Batch_ForeachSourceModuleDo ((M2Batch_DoProcedure) {(M2Batch_DoProcedure_t) M2SSA_DiscoverSSA});
     309                 :             :     }
     310                 :             :   else
     311                 :             :     {
     312                 :       14491 :       M2SSA_DiscoverSSA (SymbolTable_GetMainModule ());
     313                 :             :     }
     314                 :       14515 : }
     315                 :             : 
     316                 :      404486 : static void InitialDeclareAndOptimize (unsigned int scope, unsigned int start, unsigned int end)
     317                 :             : {
     318                 :             :   /* 
     319                 :             :    InitialDeclareAndCodeBlock - declares all objects within scope,
     320                 :             :   */
     321                 :      404486 :   Count = M2Quads_CountQuads ();
     322                 :      404486 :   M2BasicBlock_FreeBasicBlocks (M2BasicBlock_InitBasicBlocksFromRange (scope, start, end));
     323                 :      404486 :   BasicB = Count-(M2Quads_CountQuads ());
     324                 :      404486 :   Count = M2Quads_CountQuads ();
     325                 :      404486 :   M2Optimize_FoldBranches (start, end);
     326                 :      404486 :   Jump = Count-(M2Quads_CountQuads ());
     327                 :      404486 :   Count = M2Quads_CountQuads ();
     328                 :      404486 : }
     329                 :             : 
     330                 :      700043 : static void SecondDeclareAndOptimize (unsigned int scope, unsigned int start, unsigned int end)
     331                 :             : {
     332                 :      782830 :   M2BasicBlock_BasicBlock bb;
     333                 :             : 
     334                 :             :   /* 
     335                 :             :    DeclareAndCodeBlock - declares all objects within scope,
     336                 :             :   */
     337                 :      782830 :   do {
     338                 :      782830 :     bb = M2BasicBlock_InitBasicBlocksFromRange (scope, start, end);
     339                 :      782830 :     M2BasicBlock_ForeachBasicBlockDo (bb, (M2BasicBlock_BasicBlockProc) {(M2BasicBlock_BasicBlockProc_t) M2GCCDeclare_FoldConstants});
     340                 :      782698 :     M2BasicBlock_FreeBasicBlocks (bb);
     341                 :      782698 :     DeltaConst = Count-(M2Quads_CountQuads ());
     342                 :      782698 :     Count = M2Quads_CountQuads ();
     343                 :      782698 :     M2BasicBlock_FreeBasicBlocks (M2BasicBlock_InitBasicBlocksFromRange (scope, start, end));
     344                 :      782698 :     DeltaBasicB = Count-(M2Quads_CountQuads ());
     345                 :      782698 :     Count = M2Quads_CountQuads ();
     346                 :      782698 :     M2BasicBlock_FreeBasicBlocks (M2BasicBlock_InitBasicBlocksFromRange (scope, start, end));
     347                 :      782698 :     M2Optimize_FoldBranches (start, end);
     348                 :      782698 :     DeltaJump = Count-(M2Quads_CountQuads ());
     349                 :      782698 :     Count = M2Quads_CountQuads ();
     350                 :      782698 :     M2BasicBlock_FreeBasicBlocks (M2BasicBlock_InitBasicBlocksFromRange (scope, start, end));
     351                 :      782698 :     DeltaBasicB += Count-(M2Quads_CountQuads ());
     352                 :      782698 :     Count = M2Quads_CountQuads ();
     353                 :             :     /* now total the optimization components  */
     354                 :      782698 :     Proc += DeltaProc;
     355                 :      782698 :     Const += DeltaConst;
     356                 :      782698 :     Jump += DeltaJump;
     357                 :      782698 :     BasicB += DeltaBasicB;
     358                 :      782698 :   } while (! ((OptimTimes >= MaxOptimTimes) || ((((DeltaProc == 0) && (DeltaConst == 0)) && (DeltaJump == 0)) && (DeltaBasicB == 0))));
     359                 :      699911 :   if ((((DeltaProc != 0) || (DeltaConst != 0)) || (DeltaJump != 0)) || (DeltaBasicB != 0))
     360                 :             :     {
     361                 :           0 :       M2Printf_printf0 ((const char *) "optimization finished although more reduction may be possible (increase MaxOptimTimes)\\n", 88);
     362                 :             :     }
     363                 :      699911 : }
     364                 :             : 
     365                 :             : 
     366                 :             : /*
     367                 :             :    InitOptimizeVariables -
     368                 :             : */
     369                 :             : 
     370                 :      235714 : static void InitOptimizeVariables (void)
     371                 :             : {
     372                 :      235714 :   Count = M2Quads_CountQuads ();
     373                 :      235714 :   OptimTimes = 0;
     374                 :      235714 :   DeltaProc = 0;
     375                 :      235714 :   DeltaConst = 0;
     376                 :      235714 :   DeltaJump = 0;
     377                 :      235714 :   DeltaBasicB = 0;
     378                 :      235714 : }
     379                 :             : 
     380                 :             : 
     381                 :             : /*
     382                 :             :    Init -
     383                 :             : */
     384                 :             : 
     385                 :       15506 : static void Init (void)
     386                 :             : {
     387                 :       15506 :   Proc = 0;
     388                 :       15506 :   Const = 0;
     389                 :       15506 :   Jump = 0;
     390                 :       15506 :   BasicB = 0;
     391                 :           0 : }
     392                 :             : 
     393                 :             : 
     394                 :             : /*
     395                 :             :    OptimizeScopeBlock -
     396                 :             : */
     397                 :             : 
     398                 :      235714 : static void OptimizeScopeBlock (M2Scope_ScopeBlock sb)
     399                 :             : {
     400                 :      235714 :   unsigned int OptimTimes;
     401                 :      235714 :   unsigned int Previous;
     402                 :      235714 :   unsigned int Current;
     403                 :             : 
     404                 :      235714 :   InitOptimizeVariables ();
     405                 :      235714 :   OptimTimes = 1;
     406                 :      235714 :   Current = M2Quads_CountQuads ();
     407                 :      235714 :   M2Scope_ForeachScopeBlockDo3 (sb, (M2Scope_ScopeProcedure3) {(M2Scope_ScopeProcedure3_t) InitialDeclareAndOptimize});
     408                 :      235714 :   M2Scope_ForeachScopeBlockDo3 (sb, (M2Scope_ScopeProcedure3) {(M2Scope_ScopeProcedure3_t) M2SymInit_ScopeBlockVariableAnalysis});
     409                 :      319676 :   do {
     410                 :      319676 :     M2Scope_ForeachScopeBlockDo3 (sb, (M2Scope_ScopeProcedure3) {(M2Scope_ScopeProcedure3_t) SecondDeclareAndOptimize});
     411                 :      319544 :     Previous = Current;
     412                 :      319544 :     Current = M2Quads_CountQuads ();
     413                 :      319544 :     OptimTimes += 1;
     414                 :      319544 :   } while (! ((OptimTimes == MaxOptimTimes) || (Current == Previous)));
     415                 :      235582 :   M2Scope_ForeachScopeBlockDo3 (sb, (M2Scope_ScopeProcedure3) {(M2Scope_ScopeProcedure3_t) M2Quads_LoopAnalysis});
     416                 :      235582 : }
     417                 :             : 
     418                 :             : 
     419                 :             : /*
     420                 :             :    CodeProceduresWithinBlock - codes the procedures within the module scope.
     421                 :             : */
     422                 :             : 
     423                 :         222 : static void CodeProceduresWithinBlock (unsigned int scope)
     424                 :             : {
     425                 :         222 :   SymbolTable_ForeachProcedureDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2Code_CodeBlock});
     426                 :         222 : }
     427                 :             : 
     428                 :             : 
     429                 :             : /*
     430                 :             :    CodeProcedures -
     431                 :             : */
     432                 :             : 
     433                 :         552 : static void CodeProcedures (unsigned int scope)
     434                 :             : {
     435                 :         552 :   if ((SymbolTable_IsDefImp (scope)) || (SymbolTable_IsModule (scope)))
     436                 :             :     {
     437                 :         552 :       SymbolTable_ForeachProcedureDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2Code_CodeBlock});
     438                 :             :     }
     439                 :         552 : }
     440                 :             : 
     441                 :             : 
     442                 :             : /*
     443                 :             :    Code - calls procedures to generates trees from the quadruples.
     444                 :             :           All front end quadruple optimization is performed via this call.
     445                 :             : */
     446                 :             : 
     447                 :       14515 : extern "C" void M2Code_Code (void)
     448                 :             : {
     449                 :       14515 :   M2Quads_DumpQuadruples ((const char *) "before any optimization\\n", 25);
     450                 :       14515 :   SymbolTable_CheckHiddenTypeAreAddress ();
     451                 :       14515 :   M2Pass_SetPassToNoPass ();
     452                 :       14515 :   M2Quads_BackPatchSubrangesAndOptParam ();
     453                 :       14515 :   Total = M2Quads_CountQuads ();
     454                 :       14515 :   M2Quads_ForLoopAnalysis ();  /* must be done before any optimization as the index variable increment quad might change  */
     455                 :       14515 :   M2Quads_DumpQuadruples ((const char *) "before declaring symbols to gcc\\n", 33);
     456                 :             :   /* we know all the front end symbols must be resolved.  */
     457                 :       14515 :   if (M2Options_StyleChecking)
     458                 :             :     {
     459                 :         608 :       M2Students_StudentVariableCheck ();
     460                 :             :     }
     461                 :       14515 :   M2Pass_SetPassToCodeGeneration ();
     462                 :       14515 :   m2top_SetFlagUnitAtATime (M2Options_Optimizing);
     463                 :       14515 :   m2top_StartGlobalContext ();
     464                 :       14515 :   M2GCCDeclare_InitDeclarations ();  /* default and fixed sized types are all declared from now on.  */
     465                 :       14515 :   RemoveUnreachableCode ();  /* default and fixed sized types are all declared from now on.  */
     466                 :       14515 :   M2Quads_DumpQuadruples ((const char *) "after dead procedure elimination\\n", 34);
     467                 :       14515 :   DetermineSubExpTemporaries ();
     468                 :       14515 :   M2Quads_DumpQuadruples ((const char *) "after identifying simple subexpression temporaries\\n", 52);
     469                 :       14515 :   M2Quiet_qprintf0 ((const char *) "        symbols to gcc trees\\n", 30);
     470                 :       14515 :   DoModuleDeclare ();
     471                 :       14455 :   M2Error_FlushWarnings ();
     472                 :       14455 :   M2Error_FlushErrors ();
     473                 :       14371 :   M2Quiet_qprintf0 ((const char *) "        statements to gcc trees\\n", 33);
     474                 :       14371 :   DoCodeBlock ();
     475                 :       14227 :   M2GCCDeclare_MarkExported (SymbolTable_GetMainModule ());
     476                 :       14227 :   M2Swig_GenerateSwigFile (SymbolTable_GetMainModule ());
     477                 :       14227 :   SymbolTable_DebugLineNumbers (SymbolTable_GetMainModule ());
     478                 :       14227 :   M2Quiet_qprintf0 ((const char *) "        gcc trees given to the gcc backend\\n", 44);
     479                 :       14227 :   m2top_EndGlobalContext ();
     480                 :       14227 :   ResourceAnalysis ();
     481                 :       14227 : }
     482                 :             : 
     483                 :             : 
     484                 :             : /*
     485                 :             :    CodeBlock - generates all code for this block and also declares
     486                 :             :                all types and procedures for this block. It will
     487                 :             :                also optimize quadruples within this scope.
     488                 :             : */
     489                 :             : 
     490                 :      235714 : extern "C" void M2Code_CodeBlock (unsigned int scope)
     491                 :             : {
     492                 :      235714 :   M2Scope_ScopeBlock sb;
     493                 :      235714 :   NameKey_Name n;
     494                 :             : 
     495                 :      235714 :   if (TraceQuadruples)
     496                 :             :     {
     497                 :             :       n = SymbolTable_GetSymName (scope);
     498                 :             :       M2Printf_printf1 ((const char *) "before coding block %a\\n", 24, (const unsigned char *) &n, (sizeof (n)-1));
     499                 :             :     }
     500                 :      235714 :   sb = M2Scope_InitScopeBlock (scope);
     501                 :      235714 :   OptimizeScopeBlock (sb);
     502                 :      235582 :   if (SymbolTable_IsProcedure (scope))
     503                 :             :     {
     504                 :      221193 :       if (TraceQuadruples)
     505                 :             :         {
     506                 :             :           n = SymbolTable_GetSymName (scope);
     507                 :             :           M2Printf_printf1 ((const char *) "before coding procedure %a\\n", 28, (const unsigned char *) &n, (sizeof (n)-1));
     508                 :             :           M2Scope_ForeachScopeBlockDo3 (sb, (M2Scope_ScopeProcedure3) {(M2Scope_ScopeProcedure3_t) M2Quads_DisplayQuadRange});
     509                 :             :           M2Printf_printf0 ((const char *) "===============\\n", 17);
     510                 :             :         }
     511                 :      221193 :       M2Scope_ForeachScopeBlockDo2 (sb, (M2Scope_ScopeProcedure2) {(M2Scope_ScopeProcedure2_t) M2GenGCC_ConvertQuadsToTree});
     512                 :             :     }
     513                 :       14389 :   else if (SymbolTable_IsModuleWithinProcedure (scope))
     514                 :             :     {
     515                 :             :       /* avoid dangling else.  */
     516                 :         144 :       if (TraceQuadruples)
     517                 :             :         {
     518                 :             :           n = SymbolTable_GetSymName (scope);
     519                 :             :           M2Printf_printf1 ((const char *) "before coding module %a within procedure\\n", 42, (const unsigned char *) &n, (sizeof (n)-1));
     520                 :             :           M2Scope_ForeachScopeBlockDo3 (sb, (M2Scope_ScopeProcedure3) {(M2Scope_ScopeProcedure3_t) M2Quads_DisplayQuadRange});
     521                 :             :           M2Printf_printf0 ((const char *) "===============\\n", 17);
     522                 :             :         }
     523                 :         144 :       M2Scope_ForeachScopeBlockDo2 (sb, (M2Scope_ScopeProcedure2) {(M2Scope_ScopeProcedure2_t) M2GenGCC_ConvertQuadsToTree});
     524                 :         144 :       SymbolTable_ForeachProcedureDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2Code_CodeBlock});
     525                 :             :     }
     526                 :             :   else
     527                 :             :     {
     528                 :             :       /* avoid dangling else.  */
     529                 :       14245 :       if (TraceQuadruples)
     530                 :             :         {
     531                 :             :           n = SymbolTable_GetSymName (scope);
     532                 :             :           M2Printf_printf1 ((const char *) "before coding module %a\\n", 25, (const unsigned char *) &n, (sizeof (n)-1));
     533                 :             :           M2Scope_ForeachScopeBlockDo3 (sb, (M2Scope_ScopeProcedure3) {(M2Scope_ScopeProcedure3_t) M2Quads_DisplayQuadRange});
     534                 :             :           M2Printf_printf0 ((const char *) "===============\\n", 17);
     535                 :             :         }
     536                 :       14245 :       M2Scope_ForeachScopeBlockDo2 (sb, (M2Scope_ScopeProcedure2) {(M2Scope_ScopeProcedure2_t) M2GenGCC_ConvertQuadsToTree});
     537                 :       14245 :       if (M2Options_WholeProgram)
     538                 :             :         {
     539                 :          24 :           M2Batch_ForeachSourceModuleDo ((M2Batch_DoProcedure) {(M2Batch_DoProcedure_t) CodeProcedures});
     540                 :             :         }
     541                 :             :       else
     542                 :             :         {
     543                 :       14221 :           SymbolTable_ForeachProcedureDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) M2Code_CodeBlock});
     544                 :             :         }
     545                 :       14227 :       SymbolTable_ForeachInnerModuleDo (scope, (SymbolKey_PerformOperation) {(SymbolKey_PerformOperation_t) CodeProceduresWithinBlock});
     546                 :             :     }
     547                 :      235552 :   M2Scope_KillScopeBlock (&sb);
     548                 :      235552 : }
     549                 :             : 
     550                 :       15506 : extern "C" void _M2_M2Code_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
     551                 :             : {
     552                 :       15506 :   Init ();
     553                 :       15506 : }
     554                 :             : 
     555                 :           0 : extern "C" void _M2_M2Code_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
     556                 :             : {
     557                 :           0 : }
        

Generated by: LCOV version 2.1-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.