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