stage3/constant_folding.hh
author Edouard Tisserant <edouard@beremiz.fr>
Mon, 22 Apr 2024 12:11:51 +0200
changeset 1104 0bc1f5a4f975
parent 990 4c235d65afdd
permissions -rw-r--r--
Continue changing STRING length from int8_t to uint8_t.

This fix segmentation faults caused by overflow when converting from string to numeric types.
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     1
/*
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     3
 *
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     4
 *  Copyright (C) 2009-2012  Mario de Sousa (msousa@fe.up.pt)
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     5
 *  Copyright (C) 2012       Manuele Conti (conti.ma@alice.it)
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     6
 *
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     7
 *  This program is free software: you can redistribute it and/or modify
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     8
 *  it under the terms of the GNU General Public License as published by
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
     9
 *  the Free Software Foundation, either version 3 of the License, or
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    10
 *  (at your option) any later version.
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    11
 *
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    12
 *  This program is distributed in the hope that it will be useful,
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    15
 *  GNU General Public License for more details.
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    16
 *
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    17
 *  You should have received a copy of the GNU General Public License
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    19
 *
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    20
 *
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    21
 * This code is made available on the understanding that it will not be
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    22
 * used in safety-critical situations without a full and competent review.
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    23
 */
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    24
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    25
/*
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    26
 * An IEC 61131-3 compiler.
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    27
 *
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    28
 * Based on the
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    29
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    30
 *
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    31
 */
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    32
781
577547327f67 Add note about How Constant Folding class is extended with a implementation constant propagation algorithm
Manuele Conti <conti.ma@alice.it>
parents: 780
diff changeset
    33
/* Determine the value of an constant expression.
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    34
 * A reference to the relevant type definition is returned.
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    35
 *
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    36
 * For example:
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    37
 *       2 + 3       -> returns reference 
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    38
 *       22.2 - 5    -> returns reference
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    39
 *       etc...
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    40
 */
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    41
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    42
#include <vector>
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    43
#include "../absyntax_utils/absyntax_utils.hh"
973
f86d5d6bb04e Do constant propagation of configuration/resource variables, taking into account scope of variables.
mjsousa
parents: 969
diff changeset
    44
#include "../util/symtable.hh"
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    45
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    46
792
78083edf93d5 disable not yet complete constant propagation algorithm (currently brocken and producing incorrect results),
Mario de Sousa <msousa@fe.up.pt>
parents: 783
diff changeset
    47
78083edf93d5 disable not yet complete constant propagation algorithm (currently brocken and producing incorrect results),
Mario de Sousa <msousa@fe.up.pt>
parents: 783
diff changeset
    48
/* For the moment we disable constant propagation algorithm as it is not yet complete, 
78083edf93d5 disable not yet complete constant propagation algorithm (currently brocken and producing incorrect results),
Mario de Sousa <msousa@fe.up.pt>
parents: 783
diff changeset
    49
 * and due to this is currently brocken and producing incorrect results!
78083edf93d5 disable not yet complete constant propagation algorithm (currently brocken and producing incorrect results),
Mario de Sousa <msousa@fe.up.pt>
parents: 783
diff changeset
    50
 */
78083edf93d5 disable not yet complete constant propagation algorithm (currently brocken and producing incorrect results),
Mario de Sousa <msousa@fe.up.pt>
parents: 783
diff changeset
    51
#define DO_CONSTANT_PROPAGATION__ 0
78083edf93d5 disable not yet complete constant propagation algorithm (currently brocken and producing incorrect results),
Mario de Sousa <msousa@fe.up.pt>
parents: 783
diff changeset
    52
78083edf93d5 disable not yet complete constant propagation algorithm (currently brocken and producing incorrect results),
Mario de Sousa <msousa@fe.up.pt>
parents: 783
diff changeset
    53
78083edf93d5 disable not yet complete constant propagation algorithm (currently brocken and producing incorrect results),
Mario de Sousa <msousa@fe.up.pt>
parents: 783
diff changeset
    54
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    55
class constant_folding_c : public iterator_visitor_c {
984
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
    56
  protected:
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    57
    int error_count;
568
5f79478142d7 make the compiler platform independent (i.e. no longer assume sizeof(double)==8).
Mario de Sousa <msousa@fe.up.pt>
parents: 564
diff changeset
    58
    bool warning_found;
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    59
    int current_display_error_level;
984
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
    60
  private:
612
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    61
    /* Pointer to the previous IL instruction, which contains the current cvalue of the data stored in the IL stack, i.e. the default variable, a.k.a. accumulator */
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    62
    symbol_c *prev_il_instruction;
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    63
    /* the current IL operand being analyzed */
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    64
    symbol_c *il_operand;
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    65
969
706a152731ab Do constant propagation inside Configurations and Resources (required for support of extension: array [1..max] OF int); (Resources is still buggy)
mjsousa
parents: 967
diff changeset
    66
706a152731ab Do constant propagation inside Configurations and Resources (required for support of extension: array [1..max] OF int); (Resources is still buggy)
mjsousa
parents: 967
diff changeset
    67
612
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    68
  public:
969
706a152731ab Do constant propagation inside Configurations and Resources (required for support of extension: array [1..max] OF int); (Resources is still buggy)
mjsousa
parents: 967
diff changeset
    69
    constant_folding_c(symbol_c *symbol = NULL);
706a152731ab Do constant propagation inside Configurations and Resources (required for support of extension: array [1..max] OF int); (Resources is still buggy)
mjsousa
parents: 967
diff changeset
    70
    virtual ~constant_folding_c(void);
706a152731ab Do constant propagation inside Configurations and Resources (required for support of extension: array [1..max] OF int); (Resources is still buggy)
mjsousa
parents: 967
diff changeset
    71
    int get_error_count();
984
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
    72
 
963
e3d4dca7520b Do constant folding of variable's initial value (allows correct C code generation with variables in the subrange of an array declaration: ARRAY [1..max] of INT).
mjsousa
parents: 945
diff changeset
    73
  private:
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    74
    /*********************/
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    75
    /* B 1.2 - Constants */
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    76
    /*********************/
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    77
    /******************************/
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    78
    /* B 1.2.1 - Numeric Literals */
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    79
    /******************************/
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    80
    void *visit(real_c *symbol);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    81
    void *visit(integer_c *symbol);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    82
    void *visit(neg_real_c *symbol);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    83
    void *visit(neg_integer_c *symbol);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    84
    void *visit(binary_integer_c *symbol);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    85
    void *visit(octal_integer_c *symbol);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    86
    void *visit(hex_integer_c *symbol);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    87
    void *visit(integer_literal_c *symbol);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    88
    void *visit(real_literal_c *symbol);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    89
    void *visit(bit_string_literal_c *symbol);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    90
    void *visit(boolean_literal_c *symbol);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    91
    void *visit(boolean_true_c *symbol);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    92
    void *visit(boolean_false_c *symbol);
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
    93
633
73b56dc69e61 Fix bug with task interval using fixed_point value for duration items
Laurent Bessard
parents: 612
diff changeset
    94
    /************************/
73b56dc69e61 Fix bug with task interval using fixed_point value for duration items
Laurent Bessard
parents: 612
diff changeset
    95
    /* B 1.2.3.1 - Duration */
73b56dc69e61 Fix bug with task interval using fixed_point value for duration items
Laurent Bessard
parents: 612
diff changeset
    96
    /********* **************/
73b56dc69e61 Fix bug with task interval using fixed_point value for duration items
Laurent Bessard
parents: 612
diff changeset
    97
    void *visit(fixed_point_c *symbol);
73b56dc69e61 Fix bug with task interval using fixed_point value for duration items
Laurent Bessard
parents: 612
diff changeset
    98
612
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
    99
    /****************************************/
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   100
    /* B.2 - Language IL (Instruction List) */
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   101
    /****************************************/
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   102
    /***********************************/
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   103
    /* B 2.1 Instructions and Operands */
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   104
    /***********************************/
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   105
    // void *visit(instruction_list_c *symbol); /* Not needed, since we inherit from iterator_visitor_c */
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   106
    void *visit(il_instruction_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   107
    void *visit(il_simple_operation_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   108
    //void *visit(il_function_call_c *symbol);  /* TODO */
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   109
    void *visit(il_expression_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   110
    void *visit(il_jump_operation_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   111
    void *visit(il_fb_call_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   112
    //void *visit(il_formal_funct_call_c *symbol);   /* TODO */
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   113
    //void *visit(il_operand_list_c *symbol);  /* Not needed, since we inherit from iterator_visitor_c */
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   114
    void *visit(simple_instr_list_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   115
    void *visit(il_simple_instruction_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   116
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   117
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   118
    /*******************/
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   119
    /* B 2.2 Operators */
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   120
    /*******************/
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   121
    void *visit(   LD_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   122
    void *visit(  LDN_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   123
    void *visit(   ST_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   124
    void *visit(  STN_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   125
    void *visit(  NOT_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   126
    void *visit(    S_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   127
    void *visit(    R_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   128
    void *visit(   S1_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   129
    void *visit(   R1_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   130
    void *visit(  CLK_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   131
    void *visit(   CU_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   132
    void *visit(   CD_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   133
    void *visit(   PV_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   134
    void *visit(   IN_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   135
    void *visit(   PT_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   136
    void *visit(  AND_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   137
    void *visit(   OR_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   138
    void *visit(  XOR_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   139
    void *visit( ANDN_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   140
    void *visit(  ORN_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   141
    void *visit( XORN_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   142
    void *visit(  ADD_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   143
    void *visit(  SUB_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   144
    void *visit(  MUL_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   145
    void *visit(  DIV_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   146
    void *visit(  MOD_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   147
    void *visit(   GT_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   148
    void *visit(   GE_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   149
    void *visit(   EQ_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   150
    void *visit(   LT_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   151
    void *visit(   LE_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   152
    void *visit(   NE_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   153
    void *visit(  CAL_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   154
    void *visit( CALC_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   155
    void *visit(CALCN_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   156
    void *visit(  RET_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   157
    void *visit( RETC_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   158
    void *visit(RETCN_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   159
    void *visit(  JMP_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   160
    void *visit( JMPC_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   161
    void *visit(JMPCN_operator_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   162
    /* Symbol class handled together with function call checks */
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   163
    // void *visit(il_assign_operator_c *symbol, variable_name);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   164
    /* Symbol class handled together with function call checks */
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   165
    // void *visit(il_assign_operator_c *symbol, option, variable_name);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   166
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   167
    /***************************************/
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   168
    /* B.3 - Language ST (Structured Text) */
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   169
    /***************************************/
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   170
    /***********************/
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   171
    /* B 3.1 - Expressions */
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   172
    /***********************/
612
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   173
    void *visit(    or_expression_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   174
    void *visit(   xor_expression_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   175
    void *visit(   and_expression_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   176
    void *visit(   equ_expression_c *symbol);
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   177
    void *visit(notequ_expression_c *symbol);
612
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   178
    void *visit(    lt_expression_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   179
    void *visit(    gt_expression_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   180
    void *visit(    le_expression_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   181
    void *visit(    ge_expression_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   182
    void *visit(   add_expression_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   183
    void *visit(   sub_expression_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   184
    void *visit(   mul_expression_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   185
    void *visit(   div_expression_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   186
    void *visit(   mod_expression_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   187
    void *visit( power_expression_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   188
    void *visit(   neg_expression_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   189
    void *visit(   not_expression_c *symbol);
c062ff18d04f Constant folding for IL.
Mario de Sousa <msousa@fe.up.pt>
parents: 568
diff changeset
   190
    //void *visit(function_invocation_c *symbol); /* TODO */
984
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   191
};
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   192
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   193
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   194
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   195
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   196
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   197
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   198
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   199
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   200
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   201
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   202
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   203
990
4c235d65afdd Do not allow constant_propagation algorithm go into infinite loop when analysing code with circular references.
mjsousa
parents: 988
diff changeset
   204
#include <deque>
984
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   205
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   206
class constant_propagation_c : public constant_folding_c {
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   207
  public:
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   208
    constant_propagation_c(symbol_c *symbol = NULL);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   209
    virtual ~constant_propagation_c(void);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   210
    typedef symtable_c<const_value_c> map_values_t;
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   211
  private:
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   212
    symbol_c *current_resource;
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   213
    symbol_c *current_configuration;
988
3b12a6cf9fbd Do constant propagation of instantiated FBs, so that variable sized arrays can be declared in FBs too.
mjsousa
parents: 984
diff changeset
   214
    map_values_t *values;
984
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   215
    map_values_t var_global_values;
990
4c235d65afdd Do not allow constant_propagation algorithm go into infinite loop when analysing code with circular references.
mjsousa
parents: 988
diff changeset
   216
    /* A stack of all the FB declarations currently being recursively constant propagated */
4c235d65afdd Do not allow constant_propagation algorithm go into infinite loop when analysing code with circular references.
mjsousa
parents: 988
diff changeset
   217
    std::deque<function_block_declaration_c *> fbs_currently_being_visited; // We use a deque instead of stack, so we can search in the stack using direct access to its elements!
4c235d65afdd Do not allow constant_propagation algorithm go into infinite loop when analysing code with circular references.
mjsousa
parents: 988
diff changeset
   218
988
3b12a6cf9fbd Do constant propagation of instantiated FBs, so that variable sized arrays can be declared in FBs too.
mjsousa
parents: 984
diff changeset
   219
    void *handle_var_list_decl(symbol_c *var_list, symbol_c *type_decl, bool is_global_var = false);
984
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   220
    void *handle_var_decl     (symbol_c *var_list, bool fixed_init_value);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   221
    // Flag to indicate whether the variables in the variable declaration list will always have a fixed value when the POU is executed!
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   222
    // VAR CONSTANT ... END_VAR will always be true
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   223
    // VAR          ... END_VAR will always be true for functions (who initialise local variables every time they are called), but false for FBs and PROGRAMS
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   224
    bool fixed_init_value_; 
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   225
    bool function_pou_;
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   226
    bool is_constant(symbol_c *option);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   227
    bool is_retain  (symbol_c *option);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   228
    static map_values_t inner_left_join_values(map_values_t m1, map_values_t m2);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   229
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   230
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   231
  private:
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   232
    /***************************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   233
    /* B 0 - Programming Model */
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   234
    /***************************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   235
    void *visit(library_c *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   236
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   237
    /*********************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   238
    /* B 1.4 - Variables */
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   239
    /*********************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   240
    #if DO_CONSTANT_PROPAGATION__
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   241
    void *visit(symbolic_variable_c *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   242
    #endif // DO_CONSTANT_PROPAGATION__
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   243
    void *visit(symbolic_constant_c *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   244
                             
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   245
    /******************************************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   246
    /* B 1.4.3 - Declaration & Initialisation */
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   247
    /******************************************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   248
    void *visit(        input_declarations_c *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   249
    void *visit(       output_declarations_c *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   250
    void *visit( input_output_declarations_c *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   251
    void *visit(          var_declarations_c *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   252
    void *visit(retentive_var_declarations_c *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   253
    void *visit( external_var_declarations_c *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   254
    void *visit(   global_var_declarations_c *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   255
    void *visit(  external_declaration_c     *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   256
    void *visit(global_var_decl_c            *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   257
    void *visit( var1_init_decl_c            *symbol);
988
3b12a6cf9fbd Do constant propagation of instantiated FBs, so that variable sized arrays can be declared in FBs too.
mjsousa
parents: 984
diff changeset
   258
    void *visit(   fb_name_decl_c            *symbol);
984
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   259
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   260
    /**************************************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   261
    /* B.1.5 - Program organization units */
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   262
    /**************************************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   263
    /***********************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   264
    /* B 1.5.1 - Functions */
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   265
    /***********************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   266
    void *visit(function_declaration_c *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   267
    void *visit(function_var_decls_c   *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   268
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   269
    /*****************************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   270
    /* B 1.5.2 - Function Blocks */
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   271
    /*****************************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   272
    void *visit(function_block_declaration_c *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   273
    void *visit(            temp_var_decls_c *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   274
    void *visit(   non_retentive_var_decls_c *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   275
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   276
    /**********************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   277
    /* B 1.5.3 - Programs */
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   278
    /**********************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   279
    void *visit(       program_declaration_c *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   280
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   281
    /********************************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   282
    /* B 1.7 Configuration elements */
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   283
    /********************************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   284
    void *visit( configuration_declaration_c *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   285
    void *visit(      resource_declaration_c *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   286
    void *visit(     program_configuration_c *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   287
    void *visit(                   fb_task_c *symbol);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   288
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   289
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   290
    /****************************************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   291
    /* B.2 - Language IL (Instruction List) */
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   292
    /****************************************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   293
    /***********************************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   294
    /* B 2.1 Instructions and Operands */
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   295
    /***********************************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   296
    //void *visit(il_function_call_c *symbol);  /* TODO */
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   297
    // void *visit(il_fb_call_c *symbol);       /* TODO: move from constant_folding_c */
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   298
    //void *visit(il_formal_funct_call_c *symbol);   /* TODO */
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   299
    //void *visit(il_operand_list_c *symbol);  /* Not needed, since we inherit from iterator_visitor_c */
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   300
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   301
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   302
    /*******************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   303
    /* B 2.2 Operators */
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   304
    /*******************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   305
    /* Symbol class handled together with function call checks */
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   306
    // void *visit(il_assign_operator_c *symbol, variable_name);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   307
    /* Symbol class handled together with function call checks */
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   308
    // void *visit(il_assign_operator_c *symbol, option, variable_name);
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   309
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   310
    /***************************************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   311
    /* B.3 - Language ST (Structured Text) */
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   312
    /***************************************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   313
    /***********************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   314
    /* B 3.1 - Expressions */
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   315
    /***********************/
634269b0f104 Break constant_folding_c in two classes: constant_folding_c and constant_propagation_c
mjsousa
parents: 982
diff changeset
   316
    //void *visit(function_invocation_c *symbol); /* TODO */
774
979af2009d88 Start to implement constant propagation algorithm.
Manuele Conti <conti.ma@alice.it>
parents: 667
diff changeset
   317
981
aad6aa35ce60 Disable constant propagation again (still not working correctly)
mjsousa
parents: 973
diff changeset
   318
    #if DO_CONSTANT_PROPAGATION__
774
979af2009d88 Start to implement constant propagation algorithm.
Manuele Conti <conti.ma@alice.it>
parents: 667
diff changeset
   319
    /*********************************/
979af2009d88 Start to implement constant propagation algorithm.
Manuele Conti <conti.ma@alice.it>
parents: 667
diff changeset
   320
    /* B 3.2.1 Assignment Statements */
979af2009d88 Start to implement constant propagation algorithm.
Manuele Conti <conti.ma@alice.it>
parents: 667
diff changeset
   321
    /*********************************/
979af2009d88 Start to implement constant propagation algorithm.
Manuele Conti <conti.ma@alice.it>
parents: 667
diff changeset
   322
    void *visit(assignment_statement_c *symbol);
979af2009d88 Start to implement constant propagation algorithm.
Manuele Conti <conti.ma@alice.it>
parents: 667
diff changeset
   323
979af2009d88 Start to implement constant propagation algorithm.
Manuele Conti <conti.ma@alice.it>
parents: 667
diff changeset
   324
    /********************************/
979af2009d88 Start to implement constant propagation algorithm.
Manuele Conti <conti.ma@alice.it>
parents: 667
diff changeset
   325
    /* B 3.2.3 Selection Statements */
979af2009d88 Start to implement constant propagation algorithm.
Manuele Conti <conti.ma@alice.it>
parents: 667
diff changeset
   326
    /********************************/
979af2009d88 Start to implement constant propagation algorithm.
Manuele Conti <conti.ma@alice.it>
parents: 667
diff changeset
   327
    void *visit(if_statement_c *symbol);
780
9fbdf8a7430e Add constant propagation algorithm for loop cycles.
Manuele Conti <conti.ma@alice.it>
parents: 774
diff changeset
   328
9fbdf8a7430e Add constant propagation algorithm for loop cycles.
Manuele Conti <conti.ma@alice.it>
parents: 774
diff changeset
   329
    /********************************/
9fbdf8a7430e Add constant propagation algorithm for loop cycles.
Manuele Conti <conti.ma@alice.it>
parents: 774
diff changeset
   330
    /* B 3.2.4 Iteration Statements */
9fbdf8a7430e Add constant propagation algorithm for loop cycles.
Manuele Conti <conti.ma@alice.it>
parents: 774
diff changeset
   331
    /********************************/
9fbdf8a7430e Add constant propagation algorithm for loop cycles.
Manuele Conti <conti.ma@alice.it>
parents: 774
diff changeset
   332
    void *visit(for_statement_c *symbol);
9fbdf8a7430e Add constant propagation algorithm for loop cycles.
Manuele Conti <conti.ma@alice.it>
parents: 774
diff changeset
   333
    void *visit(while_statement_c *symbol);
9fbdf8a7430e Add constant propagation algorithm for loop cycles.
Manuele Conti <conti.ma@alice.it>
parents: 774
diff changeset
   334
    void *visit(repeat_statement_c *symbol);
792
78083edf93d5 disable not yet complete constant propagation algorithm (currently brocken and producing incorrect results),
Mario de Sousa <msousa@fe.up.pt>
parents: 783
diff changeset
   335
    #endif // DO_CONSTANT_PROPAGATION__
564
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   336
};
dabffc3086dc Start constant_folding class.
Manuele Conti <conti.ma@alice.it>
parents:
diff changeset
   337