stage4/stage4.hh
author Mario de Sousa <msousa@fe.up.pt>
Fri, 26 Oct 2012 10:25:38 +0100
changeset 695 5760f1043ba4
parent 594 c8092e909886
child 746 c7219a37cc39
permissions -rwxr-xr-x
Code formating only.
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     1
/*
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     3
 *
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
     4
 *  Copyright (C) 2003-2011  Mario de Sousa (msousa@fe.up.pt)
279
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 267
diff changeset
     5
 *  Copyright (C) 2007-2011  Laurent Bessard and Edouard Tisserant
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     6
 *
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
     7
 *  This program is free software: you can redistribute it and/or modify
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
     8
 *  it under the terms of the GNU General Public License as published by
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
     9
 *  the Free Software Foundation, either version 3 of the License, or
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    10
 *  (at your option) any later version.
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    11
 *
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    12
 *  This program is distributed in the hope that it will be useful,
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    15
 *  GNU General Public License for more details.
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    16
 *
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    17
 *  You should have received a copy of the GNU General Public License
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    19
 *
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    20
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    21
 * This code is made available on the understanding that it will not be
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    22
 * used in safety-critical situations without a full and competent review.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    23
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    24
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    25
/*
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    26
 * An IEC 61131-3 compiler.
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    27
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    28
 * Based on the
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    29
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    30
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    31
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    32
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    33
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    34
/*
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    35
 * This file contains the code that stores the output generated
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    36
 * by each specific version of the 4th stage.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    37
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    38
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    39
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    40
#include "../absyntax/absyntax.hh"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    41
522
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    42
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    43
void stage4err(const char *stage4_generator_id, symbol_c *symbol1, symbol_c *symbol2, const char *errmsg, ...);
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    44
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    45
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    46
class stage4out_c {
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    47
  public:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    48
    std::string indent_level;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    49
    std::string indent_spaces;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    50
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    51
  public:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    52
    stage4out_c(std::string indent_level = "  ");
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 28
diff changeset
    53
    stage4out_c(const char *dir, const char *radix, const char *extension, std::string indent_level = "  ");
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    54
    ~stage4out_c(void);
296
9cf0d701d211 Adding fflush capabilities. It is sometimes usefull when debuging the compiler...
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
    55
    
9cf0d701d211 Adding fflush capabilities. It is sometimes usefull when debuging the compiler...
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
    56
    void flush(void);
9cf0d701d211 Adding fflush capabilities. It is sometimes usefull when debuging the compiler...
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
    57
    
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    58
    void enable_output(void);
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    59
    void disable_output(void);
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    60
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    61
    void indent_right(void);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    62
    void indent_left(void);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    63
594
c8092e909886 Clean up code (remove parsing of integers in stage 4).
Mario de Sousa <msousa@fe.up.pt>
parents: 580
diff changeset
    64
    void *print(          std::string  value);
c8092e909886 Clean up code (remove parsing of integers in stage 4).
Mario de Sousa <msousa@fe.up.pt>
parents: 580
diff changeset
    65
    void *print(           const char *value);
c8092e909886 Clean up code (remove parsing of integers in stage 4).
Mario de Sousa <msousa@fe.up.pt>
parents: 580
diff changeset
    66
    //void *print(               int64_t value); // not required, since we have long long int, or similar
c8092e909886 Clean up code (remove parsing of integers in stage 4).
Mario de Sousa <msousa@fe.up.pt>
parents: 580
diff changeset
    67
    //void *print(              uint64_t value); // not required, since we have long long int, or similar
c8092e909886 Clean up code (remove parsing of integers in stage 4).
Mario de Sousa <msousa@fe.up.pt>
parents: 580
diff changeset
    68
    void *print(              real64_t value);
c8092e909886 Clean up code (remove parsing of integers in stage 4).
Mario de Sousa <msousa@fe.up.pt>
parents: 580
diff changeset
    69
    void *print(                   int value);
c8092e909886 Clean up code (remove parsing of integers in stage 4).
Mario de Sousa <msousa@fe.up.pt>
parents: 580
diff changeset
    70
    void *print(              long int value);
c8092e909886 Clean up code (remove parsing of integers in stage 4).
Mario de Sousa <msousa@fe.up.pt>
parents: 580
diff changeset
    71
    void *print(         long long int value);
c8092e909886 Clean up code (remove parsing of integers in stage 4).
Mario de Sousa <msousa@fe.up.pt>
parents: 580
diff changeset
    72
    void *print(unsigned           int value);
c8092e909886 Clean up code (remove parsing of integers in stage 4).
Mario de Sousa <msousa@fe.up.pt>
parents: 580
diff changeset
    73
    void *print(unsigned      long int value);
c8092e909886 Clean up code (remove parsing of integers in stage 4).
Mario de Sousa <msousa@fe.up.pt>
parents: 580
diff changeset
    74
    void *print(unsigned long long int value);
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
    75
    
397
85151b2f35ca Adding Common_Ticktime to informations printed in VARIABLES.csv file
laurent
parents: 296
diff changeset
    76
    void *print_long_integer(unsigned long l_integer, bool suffix=true);
85151b2f35ca Adding Common_Ticktime to informations printed in VARIABLES.csv file
laurent
parents: 296
diff changeset
    77
    void *print_long_long_integer(unsigned long long ll_integer, bool suffix=true);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    78
580
b6350d9f204d Code for debugging const_value annotations in abstract syntax tree.
Mario de Sousa <msousa@fe.up.pt>
parents: 522
diff changeset
    79
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    80
    void *printupper(const char *str);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    81
    void *printupper(std::string str);
26
fd67f54e64e1 Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents: 0
diff changeset
    82
fd67f54e64e1 Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents: 0
diff changeset
    83
    void *printlocation(const char *str);
fd67f54e64e1 Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents: 0
diff changeset
    84
    void *printlocation(std::string str);
fd67f54e64e1 Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents: 0
diff changeset
    85
55
8b7a21820737 Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents: 46
diff changeset
    86
    void *printlocation_comasep(const char *str);
8b7a21820737 Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents: 46
diff changeset
    87
27
667721cf52c5 Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents: 26
diff changeset
    88
  protected:
667721cf52c5 Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents: 26
diff changeset
    89
    std::ostream *out;
667721cf52c5 Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents: 26
diff changeset
    90
    std::fstream *m_file;
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    91
    
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    92
    /* A flag to tell whether to really print to the file, or to ignore any request to print to the file */
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    93
    /* This is used to implement the no_code_generation pragmas, that lets the user tell the compiler
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    94
     * when to switch on and off the code generation, without stoping the lexical, syntatical, and
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    95
     * semantic analysers from analysing the code.
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    96
     */
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    97
    bool allow_output;
27
667721cf52c5 Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents: 26
diff changeset
    98
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    99
};
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   100
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   101
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   102
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   103
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   104
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   105
int stage4(symbol_c *tree_root);