stage4/stage4.hh
author mjsousa
Mon, 11 Aug 2014 07:55:11 +0100
changeset 929 469de0f54b0e
parent 878 89eb85bab58f
permissions -rwxr-xr-x
Add comments, and make get_datatype_id_str_c equivalent to get_datatype_id_c
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
746
c7219a37cc39 Add conversion functions option.
Manuele Conti <conti.ma@alice.it>
parents: 594
diff changeset
    39
#ifndef _STAGE4_HH
c7219a37cc39 Add conversion functions option.
Manuele Conti <conti.ma@alice.it>
parents: 594
diff changeset
    40
#define _STAGE4_HH
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    41
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    42
#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
    43
522
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
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
    46
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    47
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    48
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
    49
  public:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    50
    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
    51
    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
    52
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    53
  public:
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(std::string indent_level = "  ");
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 28
diff changeset
    55
    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
    56
    ~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
    57
    
9cf0d701d211 Adding fflush capabilities. It is sometimes usefull when debuging the compiler...
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
    58
    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
    59
    
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    60
    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
    61
    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
    62
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    63
    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
    64
    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
    65
594
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(          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
    67
    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
    68
    //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
    69
    //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
    70
    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
    71
    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
    72
    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
    73
    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
    74
    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
    75
    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
    76
    void *print(unsigned long long int value);
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
    77
    
397
85151b2f35ca Adding Common_Ticktime to informations printed in VARIABLES.csv file
laurent
parents: 296
diff changeset
    78
    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
    79
    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
    80
580
b6350d9f204d Code for debugging const_value annotations in abstract syntax tree.
Mario de Sousa <msousa@fe.up.pt>
parents: 522
diff changeset
    81
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    82
    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
    83
    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
    84
fd67f54e64e1 Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents: 0
diff changeset
    85
    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
    86
    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
    87
55
8b7a21820737 Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents: 46
diff changeset
    88
    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
    89
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
    90
  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
    91
    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
    92
    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
    93
    
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    94
    /* 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
    95
    /* 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
    96
     * 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
    97
     * 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
    98
     */
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    99
    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
   100
0
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
746
c7219a37cc39 Add conversion functions option.
Manuele Conti <conti.ma@alice.it>
parents: 594
diff changeset
   105
int stage4(symbol_c *tree_root, const char *builddir);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   106
878
89eb85bab58f Make generation of #line directives optional.
mjsousa
parents: 746
diff changeset
   107
/* Functions to be implemented by each generate_XX version of stage 4 */
89eb85bab58f Make generation of #line directives optional.
mjsousa
parents: 746
diff changeset
   108
int  stage4_parse_options(char *options);
89eb85bab58f Make generation of #line directives optional.
mjsousa
parents: 746
diff changeset
   109
void stage4_print_options(void);
89eb85bab58f Make generation of #line directives optional.
mjsousa
parents: 746
diff changeset
   110
746
c7219a37cc39 Add conversion functions option.
Manuele Conti <conti.ma@alice.it>
parents: 594
diff changeset
   111
#endif /* _STAGE4_HH */