stage4/generate_cc/generate_cc.cc
author mario
Tue, 23 Oct 2007 10:28:50 +0200
changeset 67 08097122a922
parent 66 501e9d494744
child 69 41cb5b80416e
permissions -rwxr-xr-x
CVS Test - removed blank line
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
/*
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     2
 * (c) 2003 Mario de Sousa
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     3
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     4
 * Offered to the public under the terms of the GNU General Public License
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     5
 * as published by the Free Software Foundation; either version 2 of the
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     6
 * License, or (at your option) any later version.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     7
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     8
 * This program is distributed in the hope that it will be useful, but
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     9
 * WITHOUT ANY WARRANTY; without even the implied warranty of
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    11
 * Public License for more details.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    12
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    13
 * 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
    14
 * 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
    15
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    16
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    17
/*
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    18
 * An IEC 61131-3 IL and ST compiler.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    19
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    20
 * 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
    21
 * 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
    22
 *
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
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    26
/*
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    27
 * This is one of the versions available for 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
    28
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    29
 * This 4th stage generates a c++ source program equivalent
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    30
 * to the IL and ST code.
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
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    36
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
// #include <stdio.h>  /* required for NULL */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    39
#include <string>
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 <iostream>
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
    41
#include <sstream>
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
    42
#include <typeinfo>
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    43
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    44
#include "../../util/symtable.hh"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    45
#include "../../util/dsymtable.hh"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    46
#include "../../absyntax/visitor.hh"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    47
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    48
#include "../stage4.hh"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    49
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
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
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    54
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    55
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    56
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    57
//#define DEBUG
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    58
#ifdef DEBUG
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    59
#define TRACE(classname) printf("\n____%s____\n",classname);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    60
#else
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    61
#define TRACE(classname)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    62
#endif
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    63
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    64
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    65
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    66
#define ERROR error_exit(__FILE__,__LINE__)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    67
/* function defined in main.cc */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    68
extern void error_exit(const char *file_name, int line_no);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    69
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    70
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    71
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    72
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    73
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    74
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    75
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    76
/* A symbol table with all globally declared functions... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    77
function_declaration_c null_symbol1(NULL,NULL,NULL,NULL);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    78
dsymtable_c<function_declaration_c *, &null_symbol1> function_symtable;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    79
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    80
/* A symbol table with all globally declared functions block types... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    81
function_block_declaration_c null_symbol2(NULL,NULL,NULL,NULL);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    82
symtable_c<function_block_declaration_c *, &null_symbol2> function_block_type_symtable;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    83
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    84
/* A symbol table with all globally declared program types... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    85
program_declaration_c null_symbol3(NULL,NULL,NULL,NULL);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    86
symtable_c<program_declaration_c *, &null_symbol3> program_type_symtable;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    87
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    88
/* A symbol table with all user declared type definitions... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    89
/* Note that function block types and program types have their
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    90
 * own symbol tables, so do not get placed in this symbol table!
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    91
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    92
symbol_c null_symbol4;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    93
symtable_c<symbol_c *, &null_symbol4> type_symtable;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    94
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    95
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    96
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    97
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    98
/***********************************************************************/
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
/* returns 0 if the names are equal!! */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   104
/* NOTE: it must ignore case!! */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   105
static int compare_identifiers(symbol_c *ident1, symbol_c *ident2) {
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   106
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   107
  token_c *name1 = dynamic_cast<token_c *>(ident1);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   108
  token_c *name2 = dynamic_cast<token_c *>(ident2);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   109
  
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   110
  if ((name1 == NULL) || (name2 == NULL))
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   111
    /* invalid identifiers... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   112
    return -1;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   113
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   114
  if (strcasecmp(name1->value, name2->value) == 0)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   115
    return 0;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   116
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   117
  /* identifiers do not match! */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   118
  return 1;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   119
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   120
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   121
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   122
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   123
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   124
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   125
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   126
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   127
/* Unlike Programs and Configurations which get mapped onto C++ classes,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   128
 * Function Blocks are mapped onto a C structure containing the variables, and
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   129
 * a C function containing the code in the FB's body. This is to allow direct allocation
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   130
 * of a FB variable (which is really an instance of the C data structure) to
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   131
 * a member of a union variable (note that classes with constructors cannot
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   132
 * be mebers of a union), which is done in IL when loading a FB onto IL's
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   133
 * default variable.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   134
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   135
 * So as not to clash the names of the C data structure and the C function,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   136
 * the C structure is given a name identical to that of the FB name, whereas
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   137
 * the name of the function is the FB name with a constant string appended.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   138
 * The value of that constant string which is appended is defined in the following
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   139
 * constant.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   140
 * In order not to clash with any variable in the IL and ST source codem the
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   141
 * following constant should contain a double underscore, which is not allowed
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   142
 * in IL and ST.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   143
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   144
 * e.g.:  FUNTION_BLOCK TEST
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   145
 * is mapped onto a TEST data structure, and a TEST_body__ function.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   146
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   147
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   148
#define FB_FUNCTION_SUFFIX "_body__"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   149
23
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   150
/* Idem as body, but for initializer FB function */
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   151
#define FB_INIT_SUFFIX "_init__"
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   152
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   153
/* Idem as body, but for run CONFIG and RESOURCE function */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   154
#define FB_RUN_SUFFIX "_run__"
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   155
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   156
/* The FB body function is passed as the only parameter a pointer to the FB data
18
e6af5eb5f546 SFC generator improved
lbessard
parents: 17
diff changeset
   157
 * structure instance. The name of this parameter is given by the following constant.
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   158
 * In order not to clash with any variable in the IL and ST source codem the
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   159
 * following constant should contain a double underscore, which is not allowed
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   160
 * in IL and ST.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   161
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   162
 * e.g.: the body of FUNTION_BLOCK TEST
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   163
 * is mapped onto the C function
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   164
 *  TEST_body__(TEST *data__)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   165
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   166
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   167
#define FB_FUNCTION_PARAM "data__"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   168
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   169
18
e6af5eb5f546 SFC generator improved
lbessard
parents: 17
diff changeset
   170
#define SFC_STEP_ACTION_PREFIX "__SFC_"
e6af5eb5f546 SFC generator improved
lbessard
parents: 17
diff changeset
   171
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   172
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   173
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   174
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   175
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   176
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   177
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   178
#include "spec_init_separator.cc"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   179
#include "function_param_iterator.cc"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   180
#include "function_call_iterator.cc"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   181
#include "function_call_param_iterator.cc"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   182
#include "type_initial_value.cc"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   183
#include "search_fb_instance_decl.cc"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   184
#include "search_base_type.cc"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   185
#include "search_var_instance_decl.cc"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   186
#include "decompose_var_instance_name.cc"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   187
#include "search_varfb_instance_type.cc"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   188
#include "search_constant_type.cc"
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   189
#include "search_expression_type.cc"
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   190
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   191
#include "generate_cc_base.cc"
49
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   192
#include "generate_cc_typedecl.cc"
17
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   193
#include "generate_cc_sfcdecl.cc"
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   194
#include "generate_cc_vardecl.cc"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   195
#include "generate_cc_configbody.cc"
30
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
   196
#include "generate_location_list.cc"
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   197
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   198
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   199
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   200
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   201
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   202
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   203
/* Generate a name for a temporary variable.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   204
 * Each new name generated is appended a different number,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   205
 * starting off from 0.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   206
 * After calling reset(), the names will start off again from 0.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   207
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   208
#define VAR_LEADER "__"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   209
#define TEMP_VAR VAR_LEADER "TMP_"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   210
#define SOURCE_VAR VAR_LEADER "SRC_"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   211
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   212
#include "generate_cc_tempvardecl.cc"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   213
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   214
#include "generate_cc_st.cc"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   215
#include "generate_cc_il.cc"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   216
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   217
#include "generate_cc.hh"
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   218
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   219
/***********************************************************************/
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   220
/***********************************************************************/
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   221
/***********************************************************************/
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   222
/***********************************************************************/
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   223
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   224
#define MILLISECOND 1000000
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   225
#define SECOND 1000 * MILLISECOND
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   226
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   227
/* A helper class that knows how to generate code for both the IL and ST languages... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   228
class calculate_time_c: public iterator_visitor_c {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   229
  private:
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   230
    unsigned long time;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   231
    float current_value;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   232
  
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   233
  public:
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   234
    calculate_time_c(void){time = 0;};
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   235
    
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   236
    unsigned long get_time(void) {return time;};
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   237
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   238
    void *get_integer_value(token_c *token) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   239
      std::string str = "";
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   240
      for (unsigned int i = 0; i < strlen(token->value); i++)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   241
        if (token->value[i] != '_')
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   242
          str += token->value[i];
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   243
      current_value = atof(str.c_str());
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   244
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   245
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   246
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   247
    void *get_float_value(token_c *token) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   248
      current_value = atof(token->value);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   249
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   250
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   251
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   252
/******************************/
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   253
/* B 1.2.1 - Numeric Literals */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   254
/******************************/
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   255
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   256
    void *visit(integer_c *symbol) {return get_integer_value(symbol);}
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   257
    
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   258
/************************/
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   259
/* B 1.2.3.1 - Duration */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   260
/************************/
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   261
  
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   262
    /* SYM_REF2(duration_c, neg, interval) */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   263
    void *visit(duration_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   264
      if (symbol->neg != NULL)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   265
        ERROR;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   266
      symbol->interval->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   267
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   268
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   269
    
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   270
    /* SYM_TOKEN(fixed_point_c) */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   271
    void *visit(fixed_point_c *symbol) {return get_float_value(symbol);}
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   272
    
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   273
    /* SYM_REF2(days_c, days, hours) */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   274
    void *visit(days_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   275
      if (symbol->hours)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   276
        symbol->hours->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   277
      symbol->days->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   278
      time += (unsigned long)(current_value * 24 * 3600 * SECOND);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   279
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   280
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   281
    
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   282
    /* SYM_REF2(hours_c, hours, minutes) */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   283
    void *visit(hours_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   284
      if (symbol->minutes)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   285
        symbol->minutes->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   286
      symbol->hours->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   287
      time += (unsigned long)(current_value * 3600 * SECOND);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   288
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   289
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   290
    
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   291
    /* SYM_REF2(minutes_c, minutes, seconds) */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   292
    void *visit(minutes_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   293
      if (symbol->seconds)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   294
        symbol->seconds->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   295
      symbol->minutes->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   296
      time += (unsigned long)(current_value * 60 * SECOND);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   297
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   298
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   299
    
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   300
    /* SYM_REF2(seconds_c, seconds, milliseconds) */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   301
    void *visit(seconds_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   302
      if (symbol->milliseconds)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   303
        symbol->milliseconds->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   304
      symbol->seconds->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   305
      time += (unsigned long)(current_value * SECOND);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   306
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   307
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   308
    
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   309
    /* SYM_REF2(milliseconds_c, milliseconds, unused) */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   310
    void *visit(milliseconds_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   311
      symbol->milliseconds->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   312
      time += (unsigned long)(current_value * MILLISECOND);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   313
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   314
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   315
};
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   316
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   317
/***********************************************************************/
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   318
/***********************************************************************/
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   319
/***********************************************************************/
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   320
/***********************************************************************/
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   321
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   322
class calculate_common_ticktime_c: public iterator_visitor_c {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   323
  private:
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   324
    unsigned long common_ticktime;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   325
    
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   326
  public:
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   327
    calculate_common_ticktime_c(void){common_ticktime = 0;}
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   328
    
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   329
    unsigned long euclide(unsigned long a, unsigned long b) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   330
      unsigned long c = a % b;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   331
      if (c == 0)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   332
        return b;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   333
      else
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   334
        return euclide(b, c);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   335
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   336
    
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   337
    void update_ticktime(unsigned long time) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   338
      if (common_ticktime == 0)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   339
        common_ticktime = time;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   340
      else if (time > common_ticktime)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   341
        common_ticktime = euclide(time, common_ticktime);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   342
      else
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   343
        common_ticktime = euclide(common_ticktime, time);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   344
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   345
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   346
    unsigned long get_ticktime(void) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   347
      return common_ticktime;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   348
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   349
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   350
/*  TASK task_name task_initialization */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   351
//SYM_REF2(task_configuration_c, task_name, task_initialization)  
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   352
    void *visit(task_initialization_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   353
      calculate_time_c calculate_time;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   354
      unsigned long time = 0;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   355
      if (symbol->interval_data_source != NULL) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   356
        symbol->interval_data_source->accept(calculate_time);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   357
        time = calculate_time.get_time();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   358
      }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   359
      if (time > 0)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   360
        update_ticktime(time);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   361
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   362
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   363
};    
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   364
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   365
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   366
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   367
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   368
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   369
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   370
/* A helper class that knows how to generate code for both the IL and ST languages... */
17
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   371
class generate_cc_SFC_IL_ST_c: public null_visitor_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
   372
  private:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   373
    stage4out_c *s4o_ptr;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   374
    symbol_c *scope;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   375
    const char *variable_prefix;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   376
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   377
  public:
17
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   378
    generate_cc_SFC_IL_ST_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix = NULL);
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   379
    /*********************************************/
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   380
    /* B.1.6  Sequential function chart elements */
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   381
    /*********************************************/
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   382
    
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   383
    /*| sequential_function_chart sfc_network*/
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   384
    void *visit(sequential_function_chart_c * symbol);
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   385
    
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   386
    /****************************************/
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   387
    /* B.2 - Language IL (Instruction List) */
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   388
    /****************************************/
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   389
    
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   390
    /***********************************/
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   391
    /* B 2.1 Instructions and Operands */
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   392
    /***********************************/
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   393
    /*| instruction_list il_instruction */
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   394
    void *visit(instruction_list_c *symbol);
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   395
    
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   396
    /* Remainder implemented in generate_cc_il_c... */
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   397
    
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   398
    /***************************************/
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   399
    /* B.3 - Language ST (Structured Text) */
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   400
    /***************************************/
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   401
    /***********************/
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   402
    /* B 3.1 - Expressions */
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   403
    /***********************/
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   404
    /* Implemented in generate_cc_st_c */
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   405
    
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   406
    /********************/
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   407
    /* B 3.2 Statements */
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   408
    /********************/
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   409
    void *visit(statement_list_c *symbol);
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   410
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   411
/* Remainder implemented in generate_cc_st_c... */
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   412
};
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   413
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   414
#include "generate_cc_sfc.cc"
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   415
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   416
generate_cc_SFC_IL_ST_c::generate_cc_SFC_IL_ST_c(stage4out_c *s4o_ptr, symbol_c *scope, const char *variable_prefix) {
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   417
  if (NULL == scope) ERROR;
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   418
  this->s4o_ptr = s4o_ptr;
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   419
  this->scope = scope;
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   420
  this->variable_prefix = variable_prefix;
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   421
}
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   422
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   423
void *generate_cc_SFC_IL_ST_c::visit(sequential_function_chart_c * symbol) {
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   424
  generate_cc_sfc_c generate_cc_sfc(s4o_ptr, scope, variable_prefix);
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   425
  generate_cc_sfc.generate(symbol);
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   426
  return NULL;
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   427
}
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   428
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   429
void *generate_cc_SFC_IL_ST_c::visit(instruction_list_c *symbol) {
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   430
  generate_cc_il_c generate_cc_il(s4o_ptr, scope, variable_prefix);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   431
  generate_cc_il.generate(symbol);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   432
  return NULL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   433
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   434
17
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   435
void *generate_cc_SFC_IL_ST_c::visit(statement_list_c *symbol) {
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   436
  generate_cc_st_c generate_cc_st(s4o_ptr, scope, variable_prefix);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   437
  generate_cc_st.generate(symbol);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   438
  return NULL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   439
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   440
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   441
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   442
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   443
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   444
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   445
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   446
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   447
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   448
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   449
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   450
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
   451
class generate_cc_pous_c: public generate_cc_typedecl_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
   452
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   453
  public:
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
   454
    generate_cc_pous_c(stage4out_c *s4o_ptr)
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   455
      : generate_cc_typedecl_c(s4o_ptr) {};
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
   456
    virtual ~generate_cc_pous_c(void) {}
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   457
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   458
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   459
  public:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   460
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   461
/*************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   462
/* B.1 - Common elements */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   463
/*************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   464
/*******************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   465
/* B 1.1 - Letters, digits and identifiers */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   466
/*******************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   467
  /* done in base class(es) */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   468
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   469
/*********************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   470
/* B 1.2 - Constants */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   471
/*********************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   472
  /* originally empty... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   473
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   474
/******************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   475
/* B 1.2.1 - Numeric Literals */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   476
/******************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   477
  /* done in base class(es) */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   478
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   479
/*******************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   480
/* B.1.2.2   Character Strings */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   481
/*******************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   482
  /* done in base class(es) */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   483
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   484
/***************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   485
/* B 1.2.3 - Time Literals */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   486
/***************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   487
/************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   488
/* B 1.2.3.1 - Duration */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   489
/************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   490
  /* done in base class(es) */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   491
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   492
/************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   493
/* B 1.2.3.2 - Time of day and Date */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   494
/************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   495
  /* done in base class(es) */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   496
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   497
/**********************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   498
/* B.1.3 - Data types */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   499
/**********************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   500
/***********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   501
/* B 1.3.1 - Elementary Data Types */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   502
/***********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   503
  /* done in base class(es) */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   504
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   505
/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   506
/* B.1.3.2 - Generic data types */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   507
/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   508
  /* originally empty... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   509
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   510
/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   511
/* B 1.3.3 - Derived data types */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   512
/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   513
  /* done in base class(es) */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   514
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   515
/*********************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   516
/* B 1.4 - Variables */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   517
/*********************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   518
  /* done in base class(es) */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   519
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   520
/********************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   521
/* B.1.4.1   Directly Represented Variables */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   522
/********************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   523
  /* done in base class(es) */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   524
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   525
/*************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   526
/* B.1.4.2   Multi-element Variables */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   527
/*************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   528
  /* done in base class(es) */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   529
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   530
/******************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   531
/* B 1.4.3 - Declaration & Initialisation */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   532
/******************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   533
  /* done in base class(es) */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   534
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   535
/**************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   536
/* B.1.5 - Program organization units */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   537
/**************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   538
/***********************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   539
/* B 1.5.1 - Functions */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   540
/***********************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   541
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   542
public:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   543
/*   FUNCTION derived_function_name ':' elementary_type_name io_OR_function_var_declarations_list function_body END_FUNCTION */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   544
/* | FUNCTION derived_function_name ':' derived_type_name io_OR_function_var_declarations_list function_body END_FUNCTION */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   545
void *visit(function_declaration_c *symbol) {
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   546
  generate_cc_vardecl_c *vardecl;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   547
  TRACE("function_declaration_c");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   548
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   549
  /* start off by adding this declaration to the global
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   550
   * function declaration symbol table...
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   551
   */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   552
  function_symtable.insert(symbol->derived_function_name, symbol);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   553
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   554
  /* (A) Function declaration... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   555
  /* (A.1) Function return type */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   556
  s4o.print("// FUNCTION\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   557
  symbol->type_name->accept(*this); /* return type */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   558
  s4o.print(" ");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   559
  /* (A.2) Function name */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   560
  symbol->derived_function_name->accept(*this);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   561
  s4o.print("(");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   562
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   563
  /* (A.3) Function parameters */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   564
  s4o.indent_right();
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   565
  vardecl = new generate_cc_vardecl_c(&s4o,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   566
  				      generate_cc_vardecl_c::finterface_vf,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   567
  				      generate_cc_vardecl_c::input_vt |
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   568
				      generate_cc_vardecl_c::output_vt |
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   569
				      generate_cc_vardecl_c::inoutput_vt);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   570
  vardecl->print(symbol->var_declarations_list);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   571
  delete vardecl;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   572
  s4o.indent_left();
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   573
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   574
  s4o.print(")\n" + s4o.indent_spaces + "{\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   575
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   576
  /* (B) Function local variable declaration */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   577
    /* (B.1) Variables declared in ST source code */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   578
  s4o.indent_right();
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   579
  vardecl = new generate_cc_vardecl_c(&s4o, generate_cc_vardecl_c::localinit_vf, generate_cc_vardecl_c::private_vt);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   580
  vardecl->print(symbol->var_declarations_list);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   581
  delete vardecl;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   582
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   583
    /* (B.2) Temporary variable for function's return value */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   584
  /* It will have the same name as the function itself! */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   585
  s4o.print(s4o.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
   586
  symbol->type_name->accept(*this); /* return type */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   587
  s4o.print(" ");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   588
  symbol->derived_function_name->accept(*this);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   589
  s4o.print(" = ");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   590
  {
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   591
    /* get the default value of this variable's type */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   592
    symbol_c *default_value = (symbol_c *)symbol->type_name->accept(*type_initial_value_c::instance());
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   593
    if (default_value == NULL) ERROR;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   594
    default_value->accept(*this);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   595
  }
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   596
  s4o.print(";\n\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   597
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   598
  /* (C) Function body */
17
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   599
  generate_cc_SFC_IL_ST_c generate_cc_code(&s4o, symbol);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   600
  symbol->function_body->accept(generate_cc_code);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   601
  s4o.print(s4o.indent_spaces + "return ");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   602
  symbol->derived_function_name->accept(*this);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   603
  s4o.print(";\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   604
  s4o.indent_left();
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   605
  s4o.print(s4o.indent_spaces + "}\n\n\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   606
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   607
  return NULL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   608
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   609
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   610
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   611
/* The remaining var_declarations_list_c, function_var_decls_c
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   612
 * and var2_init_decl_list_c are handled in the generate_cc_vardecl_c class
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   613
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   614
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   615
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   616
/*****************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   617
/* B 1.5.2 - Function Blocks */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   618
/*****************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   619
public:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   620
/*  FUNCTION_BLOCK derived_function_block_name io_OR_other_var_declarations function_block_body END_FUNCTION_BLOCK */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   621
//SYM_REF4(function_block_declaration_c, fblock_name, var_declarations, fblock_body, unused)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   622
void *visit(function_block_declaration_c *symbol) {
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   623
  generate_cc_vardecl_c *vardecl;
66
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   624
  generate_cc_sfcdecl_c *sfcdecl;
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   625
  TRACE("function_block_declaration_c");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   626
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   627
  /* start off by adding this declaration to the global
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   628
   * function block declaration symbol table...
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   629
   */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   630
  function_block_type_symtable.insert(symbol->fblock_name, symbol);
32
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 30
diff changeset
   631
  
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   632
  /* (A) Function Block data structure declaration... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   633
  /* (A.1) Data structure declaration */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   634
  s4o.print("// FUNCTION_BLOCK ");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   635
  symbol->fblock_name->accept(*this);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   636
  s4o.print("\n// Data part\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   637
  s4o.print("typedef struct {\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   638
  s4o.indent_right();
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   639
  /* (A.2) Public variables: i.e. the function parameters... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   640
  s4o.print(s4o.indent_spaces + "// FB Interface - IN, OUT, IN_OUT variables\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   641
  vardecl = new generate_cc_vardecl_c(&s4o,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   642
  				      generate_cc_vardecl_c::local_vf,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   643
  				      generate_cc_vardecl_c::input_vt |
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   644
  				      generate_cc_vardecl_c::output_vt |
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   645
  				      generate_cc_vardecl_c::inoutput_vt);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   646
  vardecl->print(symbol->var_declarations);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   647
  delete vardecl;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   648
  s4o.print("\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   649
  /* (A.3) Private internal variables */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   650
  s4o.print(s4o.indent_spaces + "// FB private variables - TEMP, private and located variables\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   651
  vardecl = new generate_cc_vardecl_c(&s4o,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   652
  				      generate_cc_vardecl_c::local_vf,
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   653
				        generate_cc_vardecl_c::temp_vt |
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   654
  				      generate_cc_vardecl_c::private_vt |
23
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   655
  				      generate_cc_vardecl_c::located_vt |
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   656
  				      generate_cc_vardecl_c::external_vt);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   657
  vardecl->print(symbol->var_declarations);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   658
  delete vardecl;
66
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   659
  /* (A.4) Generate private internal variables for SFC */
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   660
  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::sfcdecl_sd);
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   661
  sfcdecl->print(symbol->fblock_body);
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   662
  delete sfcdecl;
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   663
  s4o.print("\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   664
66
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   665
  /* (A.5) Function Block data structure type name. */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   666
  s4o.indent_left();
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   667
  s4o.print("} ");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   668
  symbol->fblock_name->accept(*this);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   669
  s4o.print(";\n\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   670
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   671
23
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   672
  /* (B) Constructor */
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   673
  /* (B.1) Constructor name... */
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   674
  s4o.print(s4o.indent_spaces + "void ");
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   675
  symbol->fblock_name->accept(*this);
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   676
  s4o.print(FB_INIT_SUFFIX);
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   677
  s4o.print("(");
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   678
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   679
  /* first and only parameter is a pointer to the data */
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   680
  symbol->fblock_name->accept(*this);
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   681
  s4o.print(" *");
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   682
  s4o.print(FB_FUNCTION_PARAM);
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   683
  s4o.print(") {\n");
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   684
  s4o.indent_right();
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   685
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   686
  /* (B.2) Member initializations... */
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   687
  s4o.print(s4o.indent_spaces);
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   688
  vardecl = new generate_cc_vardecl_c(&s4o,
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   689
  				      generate_cc_vardecl_c::constructorinit_vf,
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   690
  				      generate_cc_vardecl_c::input_vt |
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   691
  				      generate_cc_vardecl_c::output_vt |
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   692
  				      generate_cc_vardecl_c::inoutput_vt |
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   693
  				      generate_cc_vardecl_c::private_vt |
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   694
				        generate_cc_vardecl_c::located_vt |
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   695
				        generate_cc_vardecl_c::external_vt);
66
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   696
  vardecl->print(symbol->var_declarations, NULL, FB_FUNCTION_PARAM"->");
23
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   697
  delete vardecl;
66
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   698
  s4o.print("\n");
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   699
  /* (B.3) Generate private internal variables for SFC */
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   700
  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::sfcinit_sd);
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   701
  sfcdecl->print(symbol->fblock_body, FB_FUNCTION_PARAM"->");
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   702
  delete sfcdecl;
23
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   703
  s4o.indent_left();
66
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   704
  s4o.print(s4o.indent_spaces + "}\n\n");
23
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   705
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   706
  
24
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   707
  /* (C) Function with FB body */
66
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   708
  /* (C.1) Step definitions */
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   709
  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::stepdef_sd);
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   710
  sfcdecl->print(symbol->fblock_body);
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   711
  delete sfcdecl;
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   712
  
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   713
  /* (C.2) Action definitions */
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   714
  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::actiondef_sd);
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   715
  sfcdecl->print(symbol->fblock_body);
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   716
  delete sfcdecl;
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   717
  
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   718
  /* (C.3) Function declaration */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   719
  s4o.print("// Code part\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   720
  /* function interface */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   721
  s4o.print("void ");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   722
  symbol->fblock_name->accept(*this);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   723
  s4o.print(FB_FUNCTION_SUFFIX);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   724
  s4o.print("(");
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   725
  /* first and only parameter is a pointer to the data */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   726
  symbol->fblock_name->accept(*this);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   727
  s4o.print(" *");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   728
  s4o.print(FB_FUNCTION_PARAM);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   729
  s4o.print(") {\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   730
  s4o.indent_right();
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   731
66
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   732
  /* (C.4) Initialize TEMP variables */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   733
  /* function body */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   734
  s4o.print(s4o.indent_spaces + "// Initialise TEMP variables\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   735
  vardecl = new generate_cc_vardecl_c(&s4o,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   736
  				      generate_cc_vardecl_c::init_vf,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   737
				      generate_cc_vardecl_c::temp_vt);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   738
  vardecl->print(symbol->var_declarations, NULL,  FB_FUNCTION_PARAM"->");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   739
  delete vardecl;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   740
  s4o.print("\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   741
66
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   742
  /* (C.5) Function code */
17
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   743
  generate_cc_SFC_IL_ST_c generate_cc_code(&s4o, symbol, FB_FUNCTION_PARAM"->");
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   744
  symbol->fblock_body->accept(generate_cc_code);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   745
  s4o.indent_left();
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   746
  s4o.print(s4o.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
   747
  symbol->fblock_name->accept(*this);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   748
  s4o.print(FB_FUNCTION_SUFFIX);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   749
  s4o.print(s4o.indent_spaces + "() \n\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   750
66
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   751
  /* (C.6) Step undefinitions */
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   752
  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::stepundef_sd);
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   753
  sfcdecl->print(symbol->fblock_body);
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   754
  delete sfcdecl;
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   755
  
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   756
  /* (C.7) Action undefinitions */
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   757
  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::actionundef_sd);
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   758
  sfcdecl->print(symbol->fblock_body);
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   759
  delete sfcdecl;
501e9d494744 Bugs on SFC generation fixed
lbessard
parents: 65
diff changeset
   760
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   761
  s4o.indent_left();
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   762
  s4o.print("\n\n\n\n");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   763
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   764
  return NULL;
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   765
}
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   766
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   767
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   768
/* The remaining temp_var_decls_c, temp_var_decls_list_c
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   769
 * and non_retentive_var_decls_c are handled in the generate_cc_vardecl_c class
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   770
 */
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   771
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   772
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   773
/**********************/
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   774
/* B 1.5.3 - Programs */
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   775
/**********************/
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   776
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   777
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   778
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   779
public:
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   780
/*  PROGRAM program_type_name program_var_declarations_list function_block_body END_PROGRAM */
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   781
//SYM_REF4(program_declaration_c, program_type_name, var_declarations, function_block_body, unused)
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   782
void *visit(program_declaration_c *symbol) {
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   783
  generate_cc_vardecl_c *vardecl;
49
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   784
  generate_cc_sfcdecl_c *sfcdecl;
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   785
  TRACE("program_declaration_c");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   786
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   787
  /* start off by adding this declaration to the global
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   788
   * program declaration symbol table...
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   789
   */
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   790
  program_type_symtable.insert(symbol->program_type_name, symbol);
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   791
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   792
  /* (A) Program data structure declaration... */
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   793
  /* (A.1) Data structure declaration */
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   794
  s4o.print("// PROGRAM ");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   795
  symbol->program_type_name->accept(*this);
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   796
  s4o.print("\n// Data part\n");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   797
  s4o.print("typedef struct {\n");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   798
  s4o.indent_right();
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   799
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   800
  /* (A.2) Public variables: i.e. the program parameters... */
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   801
  s4o.print(s4o.indent_spaces + "// PROGRAM Interface - IN, OUT, IN_OUT variables\n");
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   802
  vardecl = new generate_cc_vardecl_c(&s4o,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   803
  				      generate_cc_vardecl_c::local_vf,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   804
  				      generate_cc_vardecl_c::input_vt |
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   805
  				      generate_cc_vardecl_c::output_vt |
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   806
  				      generate_cc_vardecl_c::inoutput_vt);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   807
  vardecl->print(symbol->var_declarations);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   808
  delete vardecl;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   809
  s4o.print("\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   810
  /* (A.3) Private internal variables */
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   811
  s4o.print(s4o.indent_spaces + "// PROGRAM private variables - TEMP, private and located variables\n");
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   812
  vardecl = new generate_cc_vardecl_c(&s4o,
17
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   813
                generate_cc_vardecl_c::local_vf,
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   814
                generate_cc_vardecl_c::temp_vt |
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   815
                generate_cc_vardecl_c::private_vt |
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   816
                generate_cc_vardecl_c::located_vt |
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   817
                generate_cc_vardecl_c::external_vt);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   818
  vardecl->print(symbol->var_declarations);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   819
  delete vardecl;
18
e6af5eb5f546 SFC generator improved
lbessard
parents: 17
diff changeset
   820
  /* (A.4) Generate private internal variables for SFC */
52
f44458d1fa29 Adding SET (S) and RESET(R) to action qualifier
lbessard
parents: 49
diff changeset
   821
  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::sfcdecl_sd);
49
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   822
  sfcdecl->print(symbol->function_block_body);
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   823
  delete sfcdecl;
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   824
  
17
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   825
  /* (A.5) Program data structure type name. */
12
f01522b04810 can now generate C programs instead off Cc
tib
parents: 0
diff changeset
   826
  s4o.indent_left();
f01522b04810 can now generate C programs instead off Cc
tib
parents: 0
diff changeset
   827
  s4o.print("} ");
f01522b04810 can now generate C programs instead off Cc
tib
parents: 0
diff changeset
   828
  symbol->program_type_name->accept(*this);
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   829
  s4o.print(";\n\n");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   830
24
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   831
  /* (B) Constructor */
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   832
  /* (B.1) Constructor name... */
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   833
  s4o.print(s4o.indent_spaces + "void ");
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   834
  symbol->program_type_name->accept(*this);
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   835
  s4o.print(FB_INIT_SUFFIX);
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   836
  s4o.print("(");
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   837
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   838
  /* first and only parameter is a pointer to the data */
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   839
  symbol->program_type_name->accept(*this);
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   840
  s4o.print(" *");
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   841
  s4o.print(FB_FUNCTION_PARAM);
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   842
  s4o.print(") {\n");
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   843
  s4o.indent_right();
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   844
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   845
  /* (B.2) Member initializations... */
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   846
  s4o.print(s4o.indent_spaces);
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   847
  vardecl = new generate_cc_vardecl_c(&s4o,
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   848
  				      generate_cc_vardecl_c::constructorinit_vf,
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   849
  				      generate_cc_vardecl_c::input_vt |
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   850
  				      generate_cc_vardecl_c::output_vt |
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   851
  				      generate_cc_vardecl_c::inoutput_vt |
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   852
  				      generate_cc_vardecl_c::private_vt |
26
fd67f54e64e1 Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents: 24
diff changeset
   853
  				      generate_cc_vardecl_c::located_vt |
24
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   854
				      generate_cc_vardecl_c::external_vt);
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   855
  vardecl->print(symbol->var_declarations, NULL,  FB_FUNCTION_PARAM"->");
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   856
  delete vardecl;
49
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   857
  s4o.print("\n");
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   858
  /* (B.3) Generate private internal variables for SFC */
52
f44458d1fa29 Adding SET (S) and RESET(R) to action qualifier
lbessard
parents: 49
diff changeset
   859
  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::sfcinit_sd);
49
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   860
  sfcdecl->print(symbol->function_block_body,FB_FUNCTION_PARAM"->");
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   861
  delete sfcdecl;
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   862
24
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   863
  s4o.indent_left();
49
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   864
  s4o.print(s4o.indent_spaces + "}\n\n");
24
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   865
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   866
  /* (C) Function with PROGRAM body */
49
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   867
  /* (C.1) Step definitions */
52
f44458d1fa29 Adding SET (S) and RESET(R) to action qualifier
lbessard
parents: 49
diff changeset
   868
  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::stepdef_sd);
49
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   869
  sfcdecl->print(symbol->function_block_body);
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   870
  delete sfcdecl;
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   871
  
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   872
  /* (C.2) Action definitions */
52
f44458d1fa29 Adding SET (S) and RESET(R) to action qualifier
lbessard
parents: 49
diff changeset
   873
  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::actiondef_sd);
49
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   874
  sfcdecl->print(symbol->function_block_body);
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   875
  delete sfcdecl;
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   876
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   877
  /* (C.3) Function declaration */
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   878
  s4o.print("// Code part\n");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   879
  /* function interface */
12
f01522b04810 can now generate C programs instead off Cc
tib
parents: 0
diff changeset
   880
  s4o.print("void ");
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   881
  symbol->program_type_name->accept(*this);
12
f01522b04810 can now generate C programs instead off Cc
tib
parents: 0
diff changeset
   882
  s4o.print(FB_FUNCTION_SUFFIX);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   883
  s4o.print("(");
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   884
  /* first and only parameter is a pointer to the data */
12
f01522b04810 can now generate C programs instead off Cc
tib
parents: 0
diff changeset
   885
  symbol->program_type_name->accept(*this);
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   886
  s4o.print(" *");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   887
  s4o.print(FB_FUNCTION_PARAM);
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   888
  s4o.print(") {\n");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   889
  s4o.indent_right();
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   890
49
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   891
  /* (C.4) Initialize TEMP variables */
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   892
  /* function body */
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   893
  s4o.print(s4o.indent_spaces + "// Initialise TEMP variables\n");
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   894
  vardecl = new generate_cc_vardecl_c(&s4o,
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   895
  				      generate_cc_vardecl_c::init_vf,
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   896
				      generate_cc_vardecl_c::temp_vt);
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   897
  vardecl->print(symbol->var_declarations, NULL,  FB_FUNCTION_PARAM"->");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   898
  delete vardecl;
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   899
  s4o.print("\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   900
49
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   901
  /* (C.5) Function code */
17
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   902
  generate_cc_SFC_IL_ST_c generate_cc_code(&s4o, symbol, FB_FUNCTION_PARAM"->");
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   903
  symbol->function_block_body->accept(generate_cc_code);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   904
  s4o.indent_left();
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   905
  s4o.print(s4o.indent_spaces + "} // ");
12
f01522b04810 can now generate C programs instead off Cc
tib
parents: 0
diff changeset
   906
  symbol->program_type_name->accept(*this);
f01522b04810 can now generate C programs instead off Cc
tib
parents: 0
diff changeset
   907
  s4o.print(FB_FUNCTION_SUFFIX);
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   908
  s4o.print(s4o.indent_spaces + "() \n\n");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   909
49
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   910
  /* (C.6) Step undefinitions */
52
f44458d1fa29 Adding SET (S) and RESET(R) to action qualifier
lbessard
parents: 49
diff changeset
   911
  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::stepundef_sd);
49
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   912
  sfcdecl->print(symbol->function_block_body);
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   913
  delete sfcdecl;
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   914
  
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   915
  /* (C.7) Action undefinitions */
52
f44458d1fa29 Adding SET (S) and RESET(R) to action qualifier
lbessard
parents: 49
diff changeset
   916
  sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::actionundef_sd);
49
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   917
  sfcdecl->print(symbol->function_block_body);
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   918
  delete sfcdecl;
c96d1a4c23f8 Changing file headers
lbessard
parents: 46
diff changeset
   919
  
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   920
  s4o.indent_left();
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   921
  s4o.print("\n\n\n\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   922
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   923
  return NULL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   924
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   925
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
   926
}; /* generate_cc_pous_c */
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
   927
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
   928
/***********************************************************************/
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
   929
/***********************************************************************/
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
   930
/***********************************************************************/
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
   931
/***********************************************************************/
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
   932
/***********************************************************************/
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
   933
/***********************************************************************/
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
   934
/***********************************************************************/
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
   935
/***********************************************************************/
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
   936
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
   937
class generate_cc_config_c: public generate_cc_typedecl_c {
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
   938
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   939
    public:
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
   940
    generate_cc_config_c(stage4out_c *s4o_ptr)
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
   941
      : generate_cc_typedecl_c(s4o_ptr) {};
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
   942
    virtual ~generate_cc_config_c(void) {}
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
   943
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   944
    typedef enum {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   945
      initprotos_dt,
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   946
      initdeclare_dt,
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   947
      runprotos_dt,
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   948
      rundeclare_dt
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   949
    } declaretype_t;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   950
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   951
    declaretype_t wanted_declaretype;
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   952
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   953
/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   954
/* B 1.7 Configuration elements */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   955
/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   956
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   957
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   958
public:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   959
/*
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   960
CONFIGURATION configuration_name
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   961
   optional_global_var_declarations
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   962
   (resource_declaration_list | single_resource_declaration)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   963
   optional_access_declarations
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   964
   optional_instance_specific_initializations
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   965
END_CONFIGURATION
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   966
*/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   967
/*
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   968
SYM_REF6(configuration_declaration_c, configuration_name, global_var_declarations, resource_declarations, access_declarations, instance_specific_initializations, unused)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   969
*/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   970
void *visit(configuration_declaration_c *symbol) {
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   971
  generate_cc_vardecl_c *vardecl;
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   972
  
30
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
   973
  /* Insert the header... */
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
   974
  s4o.print("/*******************************************/\n");
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
   975
  s4o.print("/*     FILE GENERATED BY iec2cc            */\n");
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
   976
  s4o.print("/* Editing this file is not recommended... */\n");
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
   977
  s4o.print("/*******************************************/\n\n");
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents: 39
diff changeset
   978
  s4o.print("#include \"iec_std_lib.h\"\n\n");
30
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
   979
  
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   980
  /* (A) configuration declaration... */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   981
  /* (A.1) configuration name in comment */
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   982
  s4o.print("// CONFIGURATION ");
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   983
  symbol->configuration_name->accept(*this);
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   984
  s4o.print("\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   985
  
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   986
  /* (A.2) Global variables */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   987
  vardecl = new generate_cc_vardecl_c(&s4o,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   988
  				      generate_cc_vardecl_c::local_vf,
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   989
  				      generate_cc_vardecl_c::global_vt);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   990
  vardecl->print(symbol);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   991
  delete vardecl;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   992
  s4o.print("\n");
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   993
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   994
  /* (B) Initialisation Function */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   995
  /* (B.1) Ressources initialisation protos... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   996
  wanted_declaretype = initprotos_dt;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   997
  symbol->resource_declarations->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   998
  s4o.print("\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   999
  
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1000
  /* (B.2) Initialisation function name... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1001
  s4o.print(s4o.indent_spaces + "void config");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1002
  s4o.print(FB_INIT_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1003
  s4o.print("(void) {\n");
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1004
  s4o.indent_right();
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1005
  
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1006
  /* (B.3) Global variables initializations... */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1007
  s4o.print(s4o.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
  1008
  vardecl = new generate_cc_vardecl_c(&s4o,
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1009
  				      generate_cc_vardecl_c::constructorinit_vf,
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1010
  				      generate_cc_vardecl_c::global_vt);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1011
  vardecl->print(symbol);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1012
  delete vardecl;
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1013
  s4o.print("\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1014
  
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1015
  /* (B.3) Resources initializations... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1016
  wanted_declaretype = initdeclare_dt;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1017
  symbol->resource_declarations->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1018
  
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1019
  s4o.indent_left();
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1020
  s4o.print(s4o.indent_spaces + "}\n\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1021
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1022
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1023
  /* (C) Run Function*/
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1024
  /* (C.1) Resources run functions protos... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1025
  wanted_declaretype = runprotos_dt;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1026
  symbol->resource_declarations->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1027
  s4o.print("\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1028
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1029
  /* (C.2) Run function name... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1030
  s4o.print(s4o.indent_spaces + "void config");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1031
  s4o.print(FB_RUN_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1032
  s4o.print("(int tick) {\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1033
  s4o.indent_right();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1034
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1035
  /* (C.3) Resources initializations... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1036
  wanted_declaretype = rundeclare_dt;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1037
  symbol->resource_declarations->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1038
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1039
  /* (C.3) Close Public Function body */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1040
  s4o.indent_left();
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1041
  s4o.print(s4o.indent_spaces + "}\n");
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1042
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1043
  return NULL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1044
}
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1045
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1046
void *visit(resource_declaration_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1047
  if (wanted_declaretype == initprotos_dt || wanted_declaretype == runprotos_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1048
    s4o.print(s4o.indent_spaces + "void ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1049
    symbol->resource_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1050
    if (wanted_declaretype == initprotos_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1051
      s4o.print(FB_INIT_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1052
      s4o.print("(void);\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1053
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1054
    else {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1055
      s4o.print(FB_RUN_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1056
      s4o.print("(int tick);\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1057
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1058
  }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1059
  if (wanted_declaretype == initdeclare_dt || wanted_declaretype == rundeclare_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1060
    s4o.print(s4o.indent_spaces);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1061
    symbol->resource_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1062
    if (wanted_declaretype == initdeclare_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1063
      s4o.print(FB_INIT_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1064
      s4o.print("();\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1065
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1066
    else {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1067
      s4o.print(FB_RUN_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1068
      s4o.print("(tick);\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1069
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1070
  }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1071
  return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1072
}
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1073
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1074
void *visit(single_resource_declaration_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1075
  if (wanted_declaretype == initprotos_dt || wanted_declaretype == runprotos_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1076
    s4o.print(s4o.indent_spaces + "void RESOURCE");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1077
    if (wanted_declaretype == initprotos_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1078
      s4o.print(FB_INIT_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1079
      s4o.print("(void);\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1080
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1081
    else {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1082
      s4o.print(FB_RUN_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1083
      s4o.print("(int tick);\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1084
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1085
  }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1086
  if (wanted_declaretype == initdeclare_dt || wanted_declaretype == rundeclare_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1087
    s4o.print(s4o.indent_spaces + "RESOURCE");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1088
    if (wanted_declaretype == initdeclare_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1089
      s4o.print(FB_INIT_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1090
      s4o.print("();\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1091
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1092
    else {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1093
      s4o.print(FB_RUN_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1094
      s4o.print("(tick);\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1095
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1096
  }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1097
  return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1098
}
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1099
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
  1100
};
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
  1101
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
  1102
/***********************************************************************/
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
  1103
/***********************************************************************/
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
  1104
/***********************************************************************/
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
  1105
/***********************************************************************/
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
  1106
/***********************************************************************/
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
  1107
/***********************************************************************/
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
  1108
/***********************************************************************/
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
  1109
/***********************************************************************/
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
  1110
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
  1111
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
  1112
class generate_cc_resources_c: public generate_cc_typedecl_c {
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
  1113
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1114
  search_var_instance_decl_c *search_config_instance;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1115
  search_var_instance_decl_c *search_resource_instance;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1116
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1117
  private:
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1118
    /* The name of the resource curretnly being processed... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1119
    symbol_c *current_resource_name;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1120
    symbol_c *current_global_vars;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1121
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
  1122
  public:
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1123
    generate_cc_resources_c(stage4out_c *s4o_ptr, symbol_c *config_scope, symbol_c *resource_scope, unsigned long time)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1124
      : generate_cc_typedecl_c(s4o_ptr) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1125
      search_config_instance = new search_var_instance_decl_c(config_scope);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1126
      search_resource_instance = new search_var_instance_decl_c(resource_scope);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1127
      common_ticktime = time;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1128
      current_resource_name = NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1129
      current_global_vars = NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1130
    };
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1131
    virtual ~generate_cc_resources_c(void) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1132
      delete search_config_instance;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1133
      delete search_resource_instance;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1134
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1135
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1136
    typedef enum {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1137
      declare_dt,
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1138
      init_dt,
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1139
      run_dt
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1140
    } declaretype_t;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1141
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1142
    declaretype_t wanted_declaretype;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1143
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1144
    unsigned long common_ticktime;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1145
    
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1146
    const char *current_program_name;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1147
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1148
    typedef enum {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1149
      assign_at,
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1150
      send_at
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1151
    } assigntype_t;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1152
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1153
    assigntype_t wanted_assigntype;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1154
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1155
/********************************/
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1156
/* B 1.7 Configuration elements */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1157
/********************************/
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1158
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1159
/*
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1160
RESOURCE resource_name ON resource_type_name
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1161
   optional_global_var_declarations
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1162
   single_resource_declaration
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1163
END_RESOURCE
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1164
*/
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1165
// SYM_REF4(resource_declaration_c, resource_name, resource_type_name, global_var_declarations, resource_declaration)
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
  1166
    void *visit(resource_declaration_c *symbol) {
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1167
      current_resource_name = symbol->resource_name;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1168
      current_global_vars = symbol->global_var_declarations;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1169
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1170
      symbol->resource_declaration->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1171
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1172
      current_resource_name = NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1173
      current_global_vars = NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1174
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1175
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1176
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1177
/* task_configuration_list program_configuration_list */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1178
// SYM_REF2(single_resource_declaration_c, task_configuration_list, program_configuration_list)
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
  1179
    void *visit(single_resource_declaration_c *symbol) {
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1180
    	bool single_resource = current_resource_name == NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1181
      if (single_resource)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1182
        current_resource_name = new identifier_c("RESOURCE");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1183
      generate_cc_vardecl_c *vardecl;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1184
      
30
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1185
      /* Insert the header... */
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1186
      s4o.print("/*******************************************/\n");
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1187
      s4o.print("/*     FILE GENERATED BY iec2cc            */\n");
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1188
      s4o.print("/* Editing this file is not recommended... */\n");
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1189
      s4o.print("/*******************************************/\n\n");
40
873a5b60a7ea Fixed -I library include path behavior + removed old lib implementation + added generated lib func names to stage 1_2 + added Makefile.Linux
etisserant
parents: 39
diff changeset
  1190
      s4o.print("#include \"iec_std_lib.h\"\n\n");
30
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1191
      
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1192
      /* (A) resource declaration... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1193
      /* (A.1) resource name in comment */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1194
      s4o.print("// RESOURCE ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1195
      current_resource_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1196
      s4o.print("\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1197
       
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1198
      /* (A.2) Global variables... */
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1199
      if (current_global_vars != NULL) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1200
        vardecl = new generate_cc_vardecl_c(&s4o,
65
c6d41c1287de Lots of bugs fixed
lbessard
parents: 52
diff changeset
  1201
                      generate_cc_vardecl_c::local_vf,
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1202
                      generate_cc_vardecl_c::global_vt);
29
3ba8ef691003 Bug on resource global variables generation corrected
lbessard
parents: 28
diff changeset
  1203
        vardecl->print(current_global_vars);
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1204
        delete vardecl;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1205
      }
29
3ba8ef691003 Bug on resource global variables generation corrected
lbessard
parents: 28
diff changeset
  1206
      s4o.print("\n");
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1207
      
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1208
      /* (A.3) POUs inclusion */
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1209
      s4o.print("#include \"POUS.c\"\n\n");
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1210
      
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1211
      /* (A.4) Resource programs declaration... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1212
      wanted_declaretype = declare_dt;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1213
      symbol->program_configuration_list->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1214
      s4o.print("\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1215
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1216
      /* (B) resource initialisation function... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1217
      /* (B.1) initialisation function name... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1218
      s4o.print("void ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1219
      current_resource_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1220
      s4o.print(FB_INIT_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1221
      s4o.print("(void) {\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1222
      s4o.indent_right();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1223
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1224
      /* (B.2) Global variables initialisations... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1225
      if (current_global_vars != NULL) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1226
        s4o.print(s4o.indent_spaces);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1227
        vardecl = new generate_cc_vardecl_c(&s4o,
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1228
                      generate_cc_vardecl_c::constructorinit_vf,
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1229
                      generate_cc_vardecl_c::global_vt);
29
3ba8ef691003 Bug on resource global variables generation corrected
lbessard
parents: 28
diff changeset
  1230
        vardecl->print(current_global_vars);
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1231
        delete vardecl;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1232
      }
29
3ba8ef691003 Bug on resource global variables generation corrected
lbessard
parents: 28
diff changeset
  1233
      s4o.print("\n");
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1234
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1235
      /* (B.3) Resource programs initialisations... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1236
      wanted_declaretype = init_dt;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1237
      symbol->program_configuration_list->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1238
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1239
      s4o.indent_left();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1240
      s4o.print("}\n\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1241
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1242
      /* (C) Resource run function... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1243
      /* (C.1) Run function name... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1244
      s4o.print("void ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1245
      current_resource_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1246
      s4o.print(FB_RUN_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1247
      s4o.print("(int tick) {\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1248
      s4o.indent_right();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1249
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1250
      /* (C.2) Task management... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1251
      symbol->task_configuration_list->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1252
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1253
      /* (C.3) Program run declaration... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1254
      wanted_declaretype = run_dt;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1255
      symbol->program_configuration_list->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1256
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1257
      s4o.indent_left();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1258
      s4o.print("}\n\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1259
      
39
e08c65e27557 Bug on configuration generation fixed
lbessard
parents: 32
diff changeset
  1260
      if (single_resource) {
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1261
        delete current_resource_name;
39
e08c65e27557 Bug on configuration generation fixed
lbessard
parents: 32
diff changeset
  1262
        current_resource_name = NULL;
e08c65e27557 Bug on configuration generation fixed
lbessard
parents: 32
diff changeset
  1263
      }
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1264
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1265
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1266
    
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1267
/*  PROGRAM [RETAIN | NON_RETAIN] program_name [WITH task_name] ':' program_type_name ['(' prog_conf_elements ')'] */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1268
//SYM_REF6(program_configuration_c, retain_option, program_name, task_name, program_type_name, prog_conf_elements, unused)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1269
    void *visit(program_configuration_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1270
      if (wanted_declaretype == declare_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1271
        s4o.print(s4o.indent_spaces);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1272
        symbol->program_type_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1273
        s4o.print(" ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1274
        symbol->program_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1275
        s4o.print(";\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1276
      }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1277
      if (wanted_declaretype == init_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1278
        s4o.print(s4o.indent_spaces);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1279
        symbol->program_type_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1280
        s4o.print(FB_INIT_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1281
        s4o.print("(&");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1282
        symbol->program_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1283
        s4o.print(");\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1284
      }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1285
      if (wanted_declaretype == run_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1286
        current_program_name = ((identifier_c*)(symbol->program_name))->value;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1287
        if (symbol->task_name != NULL) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1288
          s4o.print(s4o.indent_spaces);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1289
          s4o.print("if (");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1290
          symbol->task_name->accept(*this);
30
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1291
          s4o.print(" == 0) {\n");
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1292
          s4o.indent_right(); 
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1293
        }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1294
        
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1295
        wanted_assigntype = assign_at;
39
e08c65e27557 Bug on configuration generation fixed
lbessard
parents: 32
diff changeset
  1296
        if (symbol->prog_conf_elements != NULL)
e08c65e27557 Bug on configuration generation fixed
lbessard
parents: 32
diff changeset
  1297
          symbol->prog_conf_elements->accept(*this);
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1298
        
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1299
        s4o.print(s4o.indent_spaces);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1300
        symbol->program_type_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1301
        s4o.print(FB_FUNCTION_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1302
        s4o.print("(&");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1303
        symbol->program_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1304
        s4o.print(");\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1305
        
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1306
        wanted_assigntype = send_at;
39
e08c65e27557 Bug on configuration generation fixed
lbessard
parents: 32
diff changeset
  1307
        if (symbol->prog_conf_elements != NULL)
e08c65e27557 Bug on configuration generation fixed
lbessard
parents: 32
diff changeset
  1308
          symbol->prog_conf_elements->accept(*this);
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1309
        
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1310
        if (symbol->task_name != NULL) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1311
          s4o.indent_left();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1312
          s4o.print(s4o.indent_spaces + "}\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1313
        }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1314
      }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1315
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1316
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1317
    
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1318
/*  TASK task_name task_initialization */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1319
//SYM_REF2(task_configuration_c, task_name, task_initialization)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1320
    void *visit(task_configuration_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1321
      s4o.print(s4o.indent_spaces + "int ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1322
      symbol->task_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1323
      s4o.print(" = ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1324
      symbol->task_initialization->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1325
      s4o.print(";\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1326
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1327
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1328
    
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1329
/*  '(' [SINGLE ASSIGN data_source ','] [INTERVAL ASSIGN data_source ','] PRIORITY ASSIGN integer ')' */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1330
//SYM_REF4(task_initialization_c, single_data_source, interval_data_source, priority_data_source, unused)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1331
    void *visit(task_initialization_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1332
      if (symbol->interval_data_source != NULL) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1333
        calculate_time_c calculate_time;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1334
        symbol->interval_data_source->accept(calculate_time);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1335
        unsigned long time = calculate_time.get_time();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1336
        if (time != 0) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1337
          s4o.print("tick % ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1338
          s4o.print_integer((int)(time / common_ticktime));
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1339
        }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1340
        else
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1341
          s4o.print("1");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1342
      }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1343
      else
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1344
        s4o.print("1");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1345
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1346
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1347
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1348
/*  any_symbolic_variable ASSIGN prog_data_source */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1349
//SYM_REF2(prog_cnxn_assign_c, symbolic_variable, prog_data_source)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1350
    void *visit(prog_cnxn_assign_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1351
      if (wanted_assigntype == assign_at) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1352
        symbol_c *var_decl;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1353
        unsigned int vartype = 0;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1354
        symbol_c *current_var_reference = ((global_var_reference_c *)(symbol->prog_data_source))->global_var_name;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1355
        var_decl = search_resource_instance->get_decl(current_var_reference);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1356
        if (var_decl == NULL) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1357
          var_decl = search_config_instance->get_decl(current_var_reference);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1358
          if (var_decl == NULL)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1359
            ERROR;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1360
          else
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1361
            vartype = search_config_instance->get_vartype();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1362
        }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1363
        else
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1364
          vartype = search_resource_instance->get_vartype();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1365
        
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1366
        s4o.print(s4o.indent_spaces + "{extern ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1367
        var_decl->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1368
        s4o.print(" ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1369
        symbol->prog_data_source->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1370
        s4o.print("; ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1371
        s4o.print(current_program_name);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1372
        s4o.print(".");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1373
        symbol->symbolic_variable->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1374
        s4o.print(" = ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1375
        if (vartype || search_var_instance_decl_c::global_vt)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1376
          s4o.print("*");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1377
        symbol->prog_data_source->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1378
        s4o.print(";}\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1379
      }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1380
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1381
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1382
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1383
/* any_symbolic_variable SENDTO data_sink */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1384
//SYM_REF2(prog_cnxn_sendto_c, symbolic_variable, data_sink)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1385
    void *visit(prog_cnxn_sendto_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1386
      if (wanted_assigntype == send_at) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1387
        symbol_c *var_decl;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1388
        unsigned int vartype = 0;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1389
        symbol_c *current_var_reference = ((global_var_reference_c *)(symbol->data_sink))->global_var_name;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1390
        var_decl = search_resource_instance->get_decl(current_var_reference);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1391
        if (var_decl == NULL) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1392
          var_decl = search_config_instance->get_decl(current_var_reference);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1393
          if (var_decl == NULL)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1394
            ERROR;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1395
          else
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1396
            vartype = search_config_instance->get_vartype();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1397
        }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1398
        else
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1399
          vartype = search_resource_instance->get_vartype();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1400
        
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1401
        s4o.print(s4o.indent_spaces);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1402
        s4o.print(s4o.indent_spaces + "{extern ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1403
        var_decl->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1404
        s4o.print(" ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1405
        symbol->data_sink->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1406
        s4o.print("; ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1407
        if (vartype || search_var_instance_decl_c::global_vt)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1408
          s4o.print("*");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1409
        symbol->data_sink->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1410
        s4o.print(" = ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1411
        s4o.print(current_program_name);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1412
        s4o.print(".");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1413
        symbol->symbolic_variable->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1414
        s4o.print("};\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1415
      }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1416
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1417
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1418
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
  1419
};
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1420
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
  1421
/***********************************************************************/
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
  1422
/***********************************************************************/
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
  1423
/***********************************************************************/
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
  1424
/***********************************************************************/
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
  1425
/***********************************************************************/
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
  1426
/***********************************************************************/
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
  1427
/***********************************************************************/
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
  1428
/***********************************************************************/
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
  1429
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
  1430
class generate_cc_c: public iterator_visitor_c {
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
  1431
  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
  1432
    stage4out_c &s4o;
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
  1433
    stage4out_c pous_s4o;
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1434
    stage4out_c located_variables_s4o;
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
  1435
    generate_cc_pous_c generate_cc_pous;
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
  1436
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1437
    symbol_c *current_configuration;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1438
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
  1439
    const char *current_name;
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
  1440
    const char *current_builddir;
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
  1441
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1442
    unsigned long common_ticktime;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1443
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
  1444
  public:
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
  1445
    generate_cc_c(stage4out_c *s4o_ptr, const char *builddir): 
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
  1446
            s4o(*s4o_ptr),
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
  1447
            pous_s4o(builddir, "POUS", "c"),
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
  1448
            located_variables_s4o(builddir, "LOCATED_VARIABLES","h"),
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1449
            generate_cc_pous(&pous_s4o) {
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
  1450
      current_builddir = builddir;
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1451
      current_configuration = NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1452
    }
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
  1453
            
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
  1454
    ~generate_cc_c(void) {}
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
  1455
30
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1456
/***************************/
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1457
/* B 0 - Programming Model */
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1458
/***************************/
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1459
    void *visit(library_c *symbol) {
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1460
      generate_location_list_c generate_location_list(&located_variables_s4o);
30
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1461
      symbol->accept(generate_location_list);
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1462
      
32
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 30
diff changeset
  1463
      for(int i = 0; i < symbol->n; i++) {
30
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1464
        symbol->elements[i]->accept(*this);
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1465
      }
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1466
      return NULL;
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1467
    }
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1468
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
  1469
/*************************/
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
  1470
/* B.1 - Common elements */
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
  1471
/*************************/
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
  1472
/*******************************************/
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
  1473
/* B 1.1 - Letters, digits and identifiers */
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
  1474
/*******************************************/
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
  1475
    void *visit(identifier_c *symbol) {
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
  1476
    	current_name = symbol->value;
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
  1477
    	return NULL;
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
  1478
    }
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
  1479
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
  1480
/**************************************/
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
  1481
/* B.1.5 - Program organization units */
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
  1482
/**************************************/
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
  1483
/***********************/
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
  1484
/* B 1.5.1 - Functions */
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
  1485
/***********************/
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
  1486
    void *visit(function_declaration_c *symbol) {
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
  1487
    	symbol->accept(generate_cc_pous);
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
  1488
    	return NULL;
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
  1489
    }
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
  1490
    
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
  1491
/*****************************/
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
  1492
/* B 1.5.2 - Function Blocks */
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
  1493
/*****************************/
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
  1494
    void *visit(function_block_declaration_c *symbol) {
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
  1495
    	symbol->accept(generate_cc_pous);
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
  1496
    	return NULL;
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
  1497
    }
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
  1498
    
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
  1499
/**********************/
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
  1500
/* B 1.5.3 - Programs */
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
  1501
/**********************/    
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
  1502
    void *visit(program_declaration_c *symbol) {
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
  1503
    	symbol->accept(generate_cc_pous);
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
  1504
    	return NULL;
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
  1505
    }
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
  1506
    
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
  1507
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
  1508
/********************************/
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
  1509
/* B 1.7 Configuration elements */
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
  1510
/********************************/
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
  1511
    void *visit(configuration_declaration_c *symbol) {
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1512
  	  static int configuration_count = 0;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1513
  
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1514
      if (configuration_count++) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1515
        /* the first configuration is the one we will use!! */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1516
        ERROR;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1517
      }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1518
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1519
      current_configuration = symbol;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1520
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1521
      calculate_common_ticktime_c calculate_common_ticktime;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1522
      symbol->accept(calculate_common_ticktime);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1523
      common_ticktime = calculate_common_ticktime.get_ticktime();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1524
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1525
      symbol->configuration_name->accept(*this);
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
  1526
      stage4out_c config_s4o(current_builddir, current_name, "c");
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1527
      generate_cc_config_c generate_cc_config(&config_s4o);
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1528
      symbol->accept(generate_cc_config);
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1529
        
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1530
      config_s4o.print("int common_ticktime__ = ");
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1531
      config_s4o.print_integer((int)(common_ticktime / 1000000));
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1532
      config_s4o.print("; /*ms*/\n");
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1533
      
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1534
      symbol->resource_declarations->accept(*this);
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1535
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1536
      current_configuration = NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1537
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1538
      return NULL;
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
  1539
    }
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
  1540
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
  1541
    void *visit(resource_declaration_c *symbol) {
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
  1542
    	symbol->resource_name->accept(*this);
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
  1543
    	stage4out_c resources_s4o(current_builddir, current_name, "c");
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1544
      generate_cc_resources_c generate_cc_resources(&resources_s4o, current_configuration, symbol, common_ticktime);
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
  1545
    	symbol->accept(generate_cc_resources);
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
  1546
    	return NULL;
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
  1547
    }
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
  1548
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
  1549
    void *visit(single_resource_declaration_c *symbol) {
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
  1550
    	stage4out_c resources_s4o(current_builddir, "RESOURCE", "c");
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1551
      generate_cc_resources_c generate_cc_resources(&resources_s4o, current_configuration, symbol, common_ticktime);
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
  1552
    	symbol->accept(generate_cc_resources);
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
  1553
    	return NULL;
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
  1554
    }
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
  1555
    
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
  1556
};
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1557
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1558
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1559
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1560
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1561
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1562
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1563
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1564
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1565
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1566
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1567
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1568
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1569
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
  1570
visitor_c *new_code_generator(stage4out_c *s4o, const char *builddir)  {return new generate_cc_c(s4o, 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
  1571
void delete_code_generator(visitor_c *code_generator) {delete code_generator;}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1572
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1573