stage4/generate_c/generate_c.cc
changeset 279 c0453b7f99df
parent 272 579db02bebd9
child 283 214d3fdee596
equal deleted inserted replaced
278:050d31dd7c74 279:c0453b7f99df
     1 /*
     1 /*
     2  *  matiec - a compiler for the programming languages defined in IEC 61131-3
     2  *  matiec - a compiler for the programming languages defined in IEC 61131-3
     3  *
     3  *
     4  *  Copyright (C) 2003-2011  Mario de Sousa (msousa@fe.up.pt)
     4  *  Copyright (C) 2003-2011  Mario de Sousa (msousa@fe.up.pt)
       
     5  *  Copyright (C) 2007-2011  Laurent Bessard and Edouard Tisserant
     5  *
     6  *
     6  *  This program is free software: you can redistribute it and/or modify
     7  *  This program is free software: you can redistribute it and/or modify
     7  *  it under the terms of the GNU General Public License as published by
     8  *  it under the terms of the GNU General Public License as published by
     8  *  the Free Software Foundation, either version 3 of the License, or
     9  *  the Free Software Foundation, either version 3 of the License, or
     9  *  (at your option) any later version.
    10  *  (at your option) any later version.
    19  *
    20  *
    20  * This code is made available on the understanding that it will not be
    21  * This code is made available on the understanding that it will not be
    21  * used in safety-critical situations without a full and competent review.
    22  * used in safety-critical situations without a full and competent review.
    22  */
    23  */
    23 
    24 
    24 /*
       
    25  * An IEC 61131-3 compiler.
       
    26  *
       
    27  * Based on the
       
    28  * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
       
    29  *
       
    30  */
       
    31 
       
    32 
       
    33 /*
       
    34  * This is one of the versions available for the 4th stage.
       
    35  *
       
    36  * This 4th stage generates a c++ source program equivalent
       
    37  * to the IL and ST code.
       
    38  */
       
    39 
       
    40 
       
    41 
       
    42 
       
    43 
       
    44 
       
    45 // #include <stdio.h>  /* required for NULL */
       
    46 #include <string>
    25 #include <string>
    47 #include <iostream>
    26 #include <iostream>
    48 #include <sstream>
    27 #include <sstream>
    49 #include <typeinfo>
    28 #include <typeinfo>
    50 #include <list>
    29 #include <list>
    55 #include "../../absyntax/visitor.hh"
    34 #include "../../absyntax/visitor.hh"
    56 #include "../../absyntax_utils/absyntax_utils.hh"
    35 #include "../../absyntax_utils/absyntax_utils.hh"
    57 
    36 
    58 #include "../stage4.hh"
    37 #include "../stage4.hh"
    59 
    38 
    60 
       
    61 
       
    62 
       
    63 
       
    64 
       
    65 
       
    66 //#define DEBUG
    39 //#define DEBUG
    67 #ifdef DEBUG
    40 #ifdef DEBUG
    68 #define TRACE(classname) printf("\n____%s____\n",classname);
    41 #define TRACE(classname) printf("\n____%s____\n",classname);
    69 #else
    42 #else
    70 #define TRACE(classname)
    43 #define TRACE(classname)
    71 #endif
    44 #endif
    72 
    45 
    73 
       
    74 
       
    75 #define ERROR error_exit(__FILE__,__LINE__)
    46 #define ERROR error_exit(__FILE__,__LINE__)
    76 /* function defined in main.cc */
    47 /* function defined in main.cc */
    77 extern void error_exit(const char *file_name, int line_no);
    48 extern void error_exit(const char *file_name, int line_no);
    78 
    49 
    79 
       
    80 
       
    81 
       
    82 /***********************************************************************/
       
    83 /***********************************************************************/
       
    84 /***********************************************************************/
       
    85 /***********************************************************************/
    50 /***********************************************************************/
    86 
    51 
    87 /* Unlike Programs and Configurations which get mapped onto C++ classes,
    52 /* Unlike Programs and Configurations which get mapped onto C++ classes,
    88  * Function Blocks are mapped onto a C structure containing the variables, and
    53  * Function Blocks are mapped onto a C structure containing the variables, and
    89  * a C function containing the code in the FB's body. This is to allow direct allocation
    54  * a C function containing the code in the FB's body. This is to allow direct allocation