stage4/generate_cc/generate_cc.cc
author etisserant
Wed, 01 Aug 2007 13:50:14 +0200
changeset 48 3d24cc85bb3c
parent 46 fc1b78ea6d84
child 49 c96d1a4c23f8
permissions -rwxr-xr-x
Fixed some problems win 32 bits GCC and Long Long literals
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"
17
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   192
#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
   193
#include "generate_cc_typedecl.cc"
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;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   624
  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
   625
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   626
  /* 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
   627
   * 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
   628
   */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   629
  function_block_type_symtable.insert(symbol->fblock_name, symbol);
32
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 30
diff changeset
   630
  
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   631
  /* (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
   632
  /* (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
   633
  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
   634
  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
   635
  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
   636
  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
   637
  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
   638
  /* (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
   639
  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
   640
  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
   641
  				      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
   642
  				      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
   643
  				      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
   644
  				      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
   645
  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
   646
  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
   647
  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
   648
  /* (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
   649
  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
   650
  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
   651
  				      generate_cc_vardecl_c::local_vf,
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   652
				        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
   653
  				      generate_cc_vardecl_c::private_vt |
23
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   654
  				      generate_cc_vardecl_c::located_vt |
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   655
  				      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
   656
  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
   657
  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
   658
  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
   659
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   660
  /* (A.4) Function Block data structure type name. */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   661
  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
   662
  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
   663
  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
   664
  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
   665
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   666
23
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   667
  /* (B) Constructor */
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   668
  /* (B.1) Constructor name... */
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   669
  s4o.print(s4o.indent_spaces + "void ");
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   670
  symbol->fblock_name->accept(*this);
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   671
  s4o.print(FB_INIT_SUFFIX);
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   672
  s4o.print("(");
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   673
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   674
  /* first and only parameter is a pointer to the data */
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(" *");
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   677
  s4o.print(FB_FUNCTION_PARAM);
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   678
  s4o.print(") {\n");
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   679
  s4o.indent_right();
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   680
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   681
  /* (B.2) Member initializations... */
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   682
  s4o.print(s4o.indent_spaces);
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   683
  vardecl = new generate_cc_vardecl_c(&s4o,
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   684
  				      generate_cc_vardecl_c::constructorinit_vf,
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   685
  				      generate_cc_vardecl_c::input_vt |
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   686
  				      generate_cc_vardecl_c::output_vt |
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   687
  				      generate_cc_vardecl_c::inoutput_vt |
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   688
  				      generate_cc_vardecl_c::private_vt |
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   689
				        generate_cc_vardecl_c::located_vt |
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   690
				        generate_cc_vardecl_c::external_vt);
23
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   691
  vardecl->print(symbol->var_declarations, NULL,  FB_FUNCTION_PARAM"->");
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   692
  delete vardecl;
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   693
  s4o.indent_left();
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   694
  s4o.print("\n" + s4o.indent_spaces + "}\n\n");
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   695
d5b55ac4efe6 Adding init function on functionBlock
etisserant
parents: 18
diff changeset
   696
  
24
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   697
  /* (C) Function with FB body */
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   698
  /* (C.1) 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
   699
  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
   700
  /* 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
   701
  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
   702
  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
   703
  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
   704
  s4o.print("(");
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   705
  /* 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
   706
  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
   707
  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
   708
  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
   709
  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
   710
  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
   711
24
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   712
  /* (C.2) 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
   713
  /* 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
   714
  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
   715
  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
   716
  				      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
   717
				      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
   718
  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
   719
  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
   720
  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
   721
24
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   722
  /* (C.3) Function code */
17
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   723
  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
   724
  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
   725
  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
   726
  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
   727
  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
   728
  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
   729
  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
   730
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   731
  s4o.indent_left();
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   732
  s4o.print("\n\n\n\n");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   733
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   734
  return NULL;
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   735
}
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   736
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   737
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   738
/* 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
   739
 * 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
   740
 */
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   741
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   742
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   743
/**********************/
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   744
/* B 1.5.3 - Programs */
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   745
/**********************/
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   746
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   747
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   748
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   749
public:
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   750
/*  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
   751
//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
   752
void *visit(program_declaration_c *symbol) {
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   753
  generate_cc_vardecl_c *vardecl;
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   754
  TRACE("program_declaration_c");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   755
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   756
  /* 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
   757
   * program declaration symbol table...
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   758
   */
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   759
  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
   760
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   761
  /* (A) Program data structure declaration... */
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   762
  /* (A.1) Data structure declaration */
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   763
  s4o.print("// PROGRAM ");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   764
  symbol->program_type_name->accept(*this);
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   765
  s4o.print("\n// Data part\n");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   766
  s4o.print("typedef struct {\n");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   767
  s4o.indent_right();
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   768
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   769
  /* (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
   770
  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
   771
  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
   772
  				      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
   773
  				      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
   774
  				      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
   775
  				      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
   776
  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
   777
  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
   778
  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
   779
  /* (A.3) Private internal variables */
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   780
  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
   781
  vardecl = new generate_cc_vardecl_c(&s4o,
17
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   782
                generate_cc_vardecl_c::local_vf,
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   783
                generate_cc_vardecl_c::temp_vt |
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   784
                generate_cc_vardecl_c::private_vt |
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   785
                generate_cc_vardecl_c::located_vt |
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   786
                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
   787
  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
   788
  delete vardecl;
18
e6af5eb5f546 SFC generator improved
lbessard
parents: 17
diff changeset
   789
  /* (A.4) Generate private internal variables for SFC */
e6af5eb5f546 SFC generator improved
lbessard
parents: 17
diff changeset
   790
  generate_cc_sfctables_c generate_cc_sfctables(&s4o);
e6af5eb5f546 SFC generator improved
lbessard
parents: 17
diff changeset
   791
  symbol->function_block_body->accept(generate_cc_sfctables);
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   792
  s4o.print("\n");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   793
17
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   794
  /* (A.5) Program data structure type name. */
12
f01522b04810 can now generate C programs instead off Cc
tib
parents: 0
diff changeset
   795
  s4o.indent_left();
f01522b04810 can now generate C programs instead off Cc
tib
parents: 0
diff changeset
   796
  s4o.print("} ");
f01522b04810 can now generate C programs instead off Cc
tib
parents: 0
diff changeset
   797
  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
   798
  s4o.print(";\n\n");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   799
24
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   800
  /* (B) Constructor */
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   801
  /* (B.1) Constructor name... */
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   802
  s4o.print(s4o.indent_spaces + "void ");
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   803
  symbol->program_type_name->accept(*this);
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   804
  s4o.print(FB_INIT_SUFFIX);
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   805
  s4o.print("(");
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   806
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   807
  /* first and only parameter is a pointer to the data */
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   808
  symbol->program_type_name->accept(*this);
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   809
  s4o.print(" *");
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   810
  s4o.print(FB_FUNCTION_PARAM);
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   811
  s4o.print(") {\n");
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   812
  s4o.indent_right();
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   813
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   814
  /* (B.2) Member initializations... */
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   815
  s4o.print(s4o.indent_spaces);
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   816
  vardecl = new generate_cc_vardecl_c(&s4o,
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   817
  				      generate_cc_vardecl_c::constructorinit_vf,
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   818
  				      generate_cc_vardecl_c::input_vt |
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   819
  				      generate_cc_vardecl_c::output_vt |
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   820
  				      generate_cc_vardecl_c::inoutput_vt |
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   821
  				      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
   822
  				      generate_cc_vardecl_c::located_vt |
24
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   823
				      generate_cc_vardecl_c::external_vt);
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   824
  vardecl->print(symbol->var_declarations, NULL,  FB_FUNCTION_PARAM"->");
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   825
  delete vardecl;
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   826
  s4o.indent_left();
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   827
  s4o.print("\n" + s4o.indent_spaces + "}\n\n");
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   828
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   829
  /* (C) Function with PROGRAM body */
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   830
  /* (C.1) Step and Action definitions */
18
e6af5eb5f546 SFC generator improved
lbessard
parents: 17
diff changeset
   831
  generate_cc_sfcdecl_c generate_cc_sfcdecl(&s4o);
e6af5eb5f546 SFC generator improved
lbessard
parents: 17
diff changeset
   832
  symbol->function_block_body->accept(generate_cc_sfcdecl);
e6af5eb5f546 SFC generator improved
lbessard
parents: 17
diff changeset
   833
24
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   834
  /* (C.2) Function declaration */
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   835
  s4o.print("// Code part\n");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   836
  /* function interface */
12
f01522b04810 can now generate C programs instead off Cc
tib
parents: 0
diff changeset
   837
  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
   838
  symbol->program_type_name->accept(*this);
12
f01522b04810 can now generate C programs instead off Cc
tib
parents: 0
diff changeset
   839
  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
   840
  s4o.print("(");
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   841
  /* 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
   842
  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
   843
  s4o.print(" *");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   844
  s4o.print(FB_FUNCTION_PARAM);
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   845
  s4o.print(") {\n");
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   846
  s4o.indent_right();
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   847
24
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   848
  /* (C.3) Initialize TEMP variables */
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   849
  /* function body */
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   850
  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
   851
  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
   852
  				      generate_cc_vardecl_c::init_vf,
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   853
				      generate_cc_vardecl_c::temp_vt);
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   854
  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
   855
  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
   856
  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
   857
24
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   858
  /* (C.4) Function code */
17
38754701ac41 SFC state machine first approach generator implemented
lbessard
parents: 16
diff changeset
   859
  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
   860
  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
   861
  s4o.indent_left();
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   862
  s4o.print(s4o.indent_spaces + "} // ");
12
f01522b04810 can now generate C programs instead off Cc
tib
parents: 0
diff changeset
   863
  symbol->program_type_name->accept(*this);
f01522b04810 can now generate C programs instead off Cc
tib
parents: 0
diff changeset
   864
  s4o.print(FB_FUNCTION_SUFFIX);
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   865
  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
   866
24
7e830409f72a Adding init function on programs
etisserant
parents: 23
diff changeset
   867
  /* (C.5) Step and Action undefinitions */
18
e6af5eb5f546 SFC generator improved
lbessard
parents: 17
diff changeset
   868
  generate_cc_sfcundecl_c generate_cc_sfcundecl(&s4o);
e6af5eb5f546 SFC generator improved
lbessard
parents: 17
diff changeset
   869
  symbol->function_block_body->accept(generate_cc_sfcundecl);
e6af5eb5f546 SFC generator improved
lbessard
parents: 17
diff changeset
   870
16
e8b99f896416 Support for struct Time data Types manipulation into ST and IL added
lbessard
parents: 14
diff changeset
   871
  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
   872
  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
   873
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   874
  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
   875
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   876
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
   877
}; /* 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
   878
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
   879
/***********************************************************************/
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
   880
/***********************************************************************/
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
   881
/***********************************************************************/
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
   882
/***********************************************************************/
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
   883
/***********************************************************************/
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
   884
/***********************************************************************/
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
   885
/***********************************************************************/
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
   886
/***********************************************************************/
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
   887
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
   888
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
   889
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   890
    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
   891
    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
   892
      : 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
   893
    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
   894
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   895
    typedef enum {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   896
      initprotos_dt,
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   897
      initdeclare_dt,
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   898
      runprotos_dt,
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   899
      rundeclare_dt
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   900
    } declaretype_t;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   901
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   902
    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
   903
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   904
/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   905
/* 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
   906
/********************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   907
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   908
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   909
public:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   910
/*
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   911
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
   912
   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
   913
   (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
   914
   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
   915
   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
   916
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
   917
*/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   918
/*
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   919
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
   920
*/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   921
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
   922
  generate_cc_vardecl_c *vardecl;
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   923
  
30
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
   924
  /* Insert the header... */
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
   925
  s4o.print("/*******************************************/\n");
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
   926
  s4o.print("/*     FILE GENERATED BY iec2cc            */\n");
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
   927
  s4o.print("/* Editing this file is not recommended... */\n");
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
   928
  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
   929
  s4o.print("#include \"iec_std_lib.h\"\n\n");
30
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
   930
  
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   931
  /* (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
   932
  /* (A.1) configuration name in comment */
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   933
  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
   934
  symbol->configuration_name->accept(*this);
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   935
  s4o.print("\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   936
  
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   937
  /* (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
   938
  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
   939
  				      generate_cc_vardecl_c::local_vf,
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   940
  				      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
   941
  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
   942
  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
   943
  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
   944
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   945
  /* (B) Initialisation Function */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   946
  /* (B.1) Ressources initialisation protos... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   947
  wanted_declaretype = initprotos_dt;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   948
  symbol->resource_declarations->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   949
  s4o.print("\n");
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
  /* (B.2) Initialisation function name... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   952
  s4o.print(s4o.indent_spaces + "void config");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   953
  s4o.print(FB_INIT_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   954
  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
   955
  s4o.indent_right();
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   956
  
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   957
  /* (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
   958
  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
   959
  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
   960
  				      generate_cc_vardecl_c::constructorinit_vf,
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   961
  				      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
   962
  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
   963
  delete vardecl;
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   964
  s4o.print("\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   965
  
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   966
  /* (B.3) Resources initializations... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   967
  wanted_declaretype = initdeclare_dt;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   968
  symbol->resource_declarations->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   969
  
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   970
  s4o.indent_left();
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   971
  s4o.print(s4o.indent_spaces + "}\n\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   972
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   973
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   974
  /* (C) Run Function*/
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   975
  /* (C.1) Resources run functions protos... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   976
  wanted_declaretype = runprotos_dt;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   977
  symbol->resource_declarations->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   978
  s4o.print("\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   979
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   980
  /* (C.2) Run function name... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   981
  s4o.print(s4o.indent_spaces + "void config");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   982
  s4o.print(FB_RUN_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   983
  s4o.print("(int tick) {\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   984
  s4o.indent_right();
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
  /* (C.3) Resources initializations... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   987
  wanted_declaretype = rundeclare_dt;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   988
  symbol->resource_declarations->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   989
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   990
  /* (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
   991
  s4o.indent_left();
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   992
  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
   993
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   994
  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
   995
}
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   996
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   997
void *visit(resource_declaration_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   998
  if (wanted_declaretype == initprotos_dt || wanted_declaretype == runprotos_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   999
    s4o.print(s4o.indent_spaces + "void ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1000
    symbol->resource_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1001
    if (wanted_declaretype == initprotos_dt) {
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");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1004
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1005
    else {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1006
      s4o.print(FB_RUN_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1007
      s4o.print("(int tick);\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1008
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1009
  }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1010
  if (wanted_declaretype == initdeclare_dt || wanted_declaretype == rundeclare_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1011
    s4o.print(s4o.indent_spaces);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1012
    symbol->resource_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1013
    if (wanted_declaretype == initdeclare_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1014
      s4o.print(FB_INIT_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1015
      s4o.print("();\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1016
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1017
    else {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1018
      s4o.print(FB_RUN_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1019
      s4o.print("(tick);\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1020
    }
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
  return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1023
}
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1024
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1025
void *visit(single_resource_declaration_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1026
  if (wanted_declaretype == initprotos_dt || wanted_declaretype == runprotos_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1027
    s4o.print(s4o.indent_spaces + "void RESOURCE");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1028
    if (wanted_declaretype == initprotos_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1029
      s4o.print(FB_INIT_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1030
      s4o.print("(void);\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1031
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1032
    else {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1033
      s4o.print(FB_RUN_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1034
      s4o.print("(int tick);\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1035
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1036
  }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1037
  if (wanted_declaretype == initdeclare_dt || wanted_declaretype == rundeclare_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1038
    s4o.print(s4o.indent_spaces + "RESOURCE");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1039
    if (wanted_declaretype == initdeclare_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1040
      s4o.print(FB_INIT_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1041
      s4o.print("();\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1042
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1043
    else {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1044
      s4o.print(FB_RUN_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1045
      s4o.print("(tick);\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1046
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1047
  }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1048
  return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1049
}
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1050
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
  1051
};
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
  1052
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
  1053
/***********************************************************************/
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
  1054
/***********************************************************************/
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
  1055
/***********************************************************************/
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
  1056
/***********************************************************************/
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
  1057
/***********************************************************************/
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
  1058
/***********************************************************************/
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
  1059
/***********************************************************************/
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
  1060
/***********************************************************************/
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
  1061
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
  1062
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
  1063
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
  1064
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1065
  search_var_instance_decl_c *search_config_instance;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1066
  search_var_instance_decl_c *search_resource_instance;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1067
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1068
  private:
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1069
    /* The name of the resource curretnly being processed... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1070
    symbol_c *current_resource_name;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1071
    symbol_c *current_global_vars;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1072
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
  1073
  public:
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1074
    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
  1075
      : generate_cc_typedecl_c(s4o_ptr) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1076
      search_config_instance = new search_var_instance_decl_c(config_scope);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1077
      search_resource_instance = new search_var_instance_decl_c(resource_scope);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1078
      common_ticktime = time;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1079
      current_resource_name = NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1080
      current_global_vars = NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1081
    };
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1082
    virtual ~generate_cc_resources_c(void) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1083
      delete search_config_instance;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1084
      delete search_resource_instance;
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
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1087
    typedef enum {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1088
      declare_dt,
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1089
      init_dt,
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1090
      run_dt
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1091
    } declaretype_t;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1092
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1093
    declaretype_t wanted_declaretype;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1094
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1095
    unsigned long common_ticktime;
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
    const char *current_program_name;
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
    typedef enum {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1100
      assign_at,
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1101
      send_at
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1102
    } assigntype_t;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1103
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1104
    assigntype_t wanted_assigntype;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1105
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1106
/********************************/
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1107
/* B 1.7 Configuration elements */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1108
/********************************/
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1109
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1110
/*
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1111
RESOURCE resource_name ON resource_type_name
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1112
   optional_global_var_declarations
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1113
   single_resource_declaration
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1114
END_RESOURCE
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1115
*/
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1116
// 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
  1117
    void *visit(resource_declaration_c *symbol) {
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1118
      current_resource_name = symbol->resource_name;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1119
      current_global_vars = symbol->global_var_declarations;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1120
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1121
      symbol->resource_declaration->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1122
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1123
      current_resource_name = NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1124
      current_global_vars = NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1125
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1126
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1127
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1128
/* task_configuration_list program_configuration_list */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1129
// 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
  1130
    void *visit(single_resource_declaration_c *symbol) {
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1131
    	bool single_resource = current_resource_name == NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1132
      if (single_resource)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1133
        current_resource_name = new identifier_c("RESOURCE");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1134
      generate_cc_vardecl_c *vardecl;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1135
      
30
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1136
      /* Insert the header... */
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1137
      s4o.print("/*******************************************/\n");
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1138
      s4o.print("/*     FILE GENERATED BY iec2cc            */\n");
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1139
      s4o.print("/* Editing this file is not recommended... */\n");
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1140
      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
  1141
      s4o.print("#include \"iec_std_lib.h\"\n\n");
30
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1142
      
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1143
      /* (A) resource declaration... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1144
      /* (A.1) resource name in comment */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1145
      s4o.print("// RESOURCE ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1146
      current_resource_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1147
      s4o.print("\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1148
       
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1149
      /* (A.2) Global variables... */
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1150
      if (current_global_vars != NULL) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1151
        vardecl = new generate_cc_vardecl_c(&s4o,
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1152
                      generate_cc_vardecl_c::localstatic_vf,
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1153
                      generate_cc_vardecl_c::global_vt);
29
3ba8ef691003 Bug on resource global variables generation corrected
lbessard
parents: 28
diff changeset
  1154
        vardecl->print(current_global_vars);
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1155
        delete vardecl;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1156
      }
29
3ba8ef691003 Bug on resource global variables generation corrected
lbessard
parents: 28
diff changeset
  1157
      s4o.print("\n");
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1158
      
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1159
      /* (A.3) POUs inclusion */
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1160
      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
  1161
      
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1162
      /* (A.4) Resource programs declaration... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1163
      wanted_declaretype = declare_dt;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1164
      symbol->program_configuration_list->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1165
      s4o.print("\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1166
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1167
      /* (B) resource initialisation function... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1168
      /* (B.1) initialisation function name... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1169
      s4o.print("void ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1170
      current_resource_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1171
      s4o.print(FB_INIT_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1172
      s4o.print("(void) {\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1173
      s4o.indent_right();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1174
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1175
      /* (B.2) Global variables initialisations... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1176
      if (current_global_vars != NULL) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1177
        s4o.print(s4o.indent_spaces);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1178
        vardecl = new generate_cc_vardecl_c(&s4o,
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1179
                      generate_cc_vardecl_c::constructorinit_vf,
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1180
                      generate_cc_vardecl_c::global_vt);
29
3ba8ef691003 Bug on resource global variables generation corrected
lbessard
parents: 28
diff changeset
  1181
        vardecl->print(current_global_vars);
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1182
        delete vardecl;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1183
      }
29
3ba8ef691003 Bug on resource global variables generation corrected
lbessard
parents: 28
diff changeset
  1184
      s4o.print("\n");
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1185
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1186
      /* (B.3) Resource programs initialisations... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1187
      wanted_declaretype = init_dt;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1188
      symbol->program_configuration_list->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1189
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1190
      s4o.indent_left();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1191
      s4o.print("}\n\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1192
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1193
      /* (C) Resource run function... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1194
      /* (C.1) Run function name... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1195
      s4o.print("void ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1196
      current_resource_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1197
      s4o.print(FB_RUN_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1198
      s4o.print("(int tick) {\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1199
      s4o.indent_right();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1200
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1201
      /* (C.2) Task management... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1202
      symbol->task_configuration_list->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1203
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1204
      /* (C.3) Program run declaration... */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1205
      wanted_declaretype = run_dt;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1206
      symbol->program_configuration_list->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1207
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1208
      s4o.indent_left();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1209
      s4o.print("}\n\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1210
      
39
e08c65e27557 Bug on configuration generation fixed
lbessard
parents: 32
diff changeset
  1211
      if (single_resource) {
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1212
        delete current_resource_name;
39
e08c65e27557 Bug on configuration generation fixed
lbessard
parents: 32
diff changeset
  1213
        current_resource_name = NULL;
e08c65e27557 Bug on configuration generation fixed
lbessard
parents: 32
diff changeset
  1214
      }
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1215
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1216
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1217
    
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1218
/*  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
  1219
//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
  1220
    void *visit(program_configuration_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1221
      if (wanted_declaretype == declare_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1222
        s4o.print(s4o.indent_spaces);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1223
        symbol->program_type_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1224
        s4o.print(" ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1225
        symbol->program_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1226
        s4o.print(";\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1227
      }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1228
      if (wanted_declaretype == init_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1229
        s4o.print(s4o.indent_spaces);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1230
        symbol->program_type_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1231
        s4o.print(FB_INIT_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1232
        s4o.print("(&");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1233
        symbol->program_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1234
        s4o.print(");\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1235
      }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1236
      if (wanted_declaretype == run_dt) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1237
        current_program_name = ((identifier_c*)(symbol->program_name))->value;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1238
        if (symbol->task_name != NULL) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1239
          s4o.print(s4o.indent_spaces);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1240
          s4o.print("if (");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1241
          symbol->task_name->accept(*this);
30
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1242
          s4o.print(" == 0) {\n");
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1243
          s4o.indent_right(); 
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1244
        }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1245
        
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1246
        wanted_assigntype = assign_at;
39
e08c65e27557 Bug on configuration generation fixed
lbessard
parents: 32
diff changeset
  1247
        if (symbol->prog_conf_elements != NULL)
e08c65e27557 Bug on configuration generation fixed
lbessard
parents: 32
diff changeset
  1248
          symbol->prog_conf_elements->accept(*this);
28
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
        s4o.print(s4o.indent_spaces);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1251
        symbol->program_type_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1252
        s4o.print(FB_FUNCTION_SUFFIX);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1253
        s4o.print("(&");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1254
        symbol->program_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1255
        s4o.print(");\n");
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
        wanted_assigntype = send_at;
39
e08c65e27557 Bug on configuration generation fixed
lbessard
parents: 32
diff changeset
  1258
        if (symbol->prog_conf_elements != NULL)
e08c65e27557 Bug on configuration generation fixed
lbessard
parents: 32
diff changeset
  1259
          symbol->prog_conf_elements->accept(*this);
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1260
        
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1261
        if (symbol->task_name != NULL) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1262
          s4o.indent_left();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1263
          s4o.print(s4o.indent_spaces + "}\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1264
        }
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
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1267
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1268
    
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1269
/*  TASK task_name task_initialization */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1270
//SYM_REF2(task_configuration_c, task_name, task_initialization)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1271
    void *visit(task_configuration_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1272
      s4o.print(s4o.indent_spaces + "int ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1273
      symbol->task_name->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1274
      s4o.print(" = ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1275
      symbol->task_initialization->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1276
      s4o.print(";\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1277
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1278
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1279
    
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1280
/*  '(' [SINGLE ASSIGN data_source ','] [INTERVAL ASSIGN data_source ','] PRIORITY ASSIGN integer ')' */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1281
//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
  1282
    void *visit(task_initialization_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1283
      if (symbol->interval_data_source != NULL) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1284
        calculate_time_c calculate_time;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1285
        symbol->interval_data_source->accept(calculate_time);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1286
        unsigned long time = calculate_time.get_time();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1287
        if (time != 0) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1288
          s4o.print("tick % ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1289
          s4o.print_integer((int)(time / common_ticktime));
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1290
        }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1291
        else
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1292
          s4o.print("1");
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
      else
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1295
        s4o.print("1");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1296
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1297
    }
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
/*  any_symbolic_variable ASSIGN prog_data_source */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1300
//SYM_REF2(prog_cnxn_assign_c, symbolic_variable, prog_data_source)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1301
    void *visit(prog_cnxn_assign_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1302
      if (wanted_assigntype == assign_at) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1303
        symbol_c *var_decl;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1304
        unsigned int vartype = 0;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1305
        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
  1306
        var_decl = search_resource_instance->get_decl(current_var_reference);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1307
        if (var_decl == NULL) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1308
          var_decl = search_config_instance->get_decl(current_var_reference);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1309
          if (var_decl == NULL)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1310
            ERROR;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1311
          else
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1312
            vartype = search_config_instance->get_vartype();
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
        else
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1315
          vartype = search_resource_instance->get_vartype();
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
        s4o.print(s4o.indent_spaces + "{extern ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1318
        var_decl->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1319
        s4o.print(" ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1320
        symbol->prog_data_source->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1321
        s4o.print("; ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1322
        s4o.print(current_program_name);
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->symbolic_variable->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1325
        s4o.print(" = ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1326
        if (vartype || search_var_instance_decl_c::global_vt)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1327
          s4o.print("*");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1328
        symbol->prog_data_source->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1329
        s4o.print(";}\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1330
      }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1331
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1332
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1333
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1334
/* any_symbolic_variable SENDTO data_sink */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1335
//SYM_REF2(prog_cnxn_sendto_c, symbolic_variable, data_sink)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1336
    void *visit(prog_cnxn_sendto_c *symbol) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1337
      if (wanted_assigntype == send_at) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1338
        symbol_c *var_decl;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1339
        unsigned int vartype = 0;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1340
        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
  1341
        var_decl = search_resource_instance->get_decl(current_var_reference);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1342
        if (var_decl == NULL) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1343
          var_decl = search_config_instance->get_decl(current_var_reference);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1344
          if (var_decl == NULL)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1345
            ERROR;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1346
          else
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1347
            vartype = search_config_instance->get_vartype();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1348
        }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1349
        else
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1350
          vartype = search_resource_instance->get_vartype();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1351
        
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1352
        s4o.print(s4o.indent_spaces);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1353
        s4o.print(s4o.indent_spaces + "{extern ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1354
        var_decl->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1355
        s4o.print(" ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1356
        symbol->data_sink->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1357
        s4o.print("; ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1358
        if (vartype || search_var_instance_decl_c::global_vt)
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1359
          s4o.print("*");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1360
        symbol->data_sink->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1361
        s4o.print(" = ");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1362
        s4o.print(current_program_name);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1363
        s4o.print(".");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1364
        symbol->symbolic_variable->accept(*this);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1365
        s4o.print("};\n");
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1366
      }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1367
      return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1368
    }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1369
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
  1370
};
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1371
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
  1372
/***********************************************************************/
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
  1373
/***********************************************************************/
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
  1374
/***********************************************************************/
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
  1375
/***********************************************************************/
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
  1376
/***********************************************************************/
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
  1377
/***********************************************************************/
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
  1378
/***********************************************************************/
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
  1379
/***********************************************************************/
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
  1380
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
  1381
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
  1382
  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
  1383
    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
  1384
    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
  1385
    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
  1386
    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
  1387
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1388
    symbol_c *current_configuration;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1389
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
  1390
    const char *current_name;
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
  1391
    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
  1392
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1393
    unsigned long common_ticktime;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1394
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
  1395
  public:
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
  1396
    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
  1397
            s4o(*s4o_ptr),
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
  1398
            pous_s4o(builddir, "POUS", "c"),
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
  1399
            located_variables_s4o(builddir, "LOCATED_VARIABLES","h"),
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1400
            generate_cc_pous(&pous_s4o) {
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
  1401
      current_builddir = builddir;
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1402
      current_configuration = NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1403
    }
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
  1404
            
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
  1405
    ~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
  1406
30
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1407
/***************************/
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1408
/* B 0 - Programming Model */
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1409
/***************************/
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1410
    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
  1411
      generate_location_list_c generate_location_list(&located_variables_s4o);
30
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1412
      symbol->accept(generate_location_list);
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1413
      
32
289256ec66f1 Adding support for standard function block parsing
lbessard
parents: 30
diff changeset
  1414
      for(int i = 0; i < symbol->n; i++) {
30
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1415
        symbol->elements[i]->accept(*this);
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1416
      }
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1417
      return NULL;
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1418
    }
83201ec94ef4 Adding location list generation
lbessard
parents: 29
diff changeset
  1419
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
  1420
/*************************/
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
/* 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
  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
/* 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
  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
    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
  1427
    	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
  1428
    	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
  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
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
/**************************************/
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
/* 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
  1433
/**************************************/
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
  1434
/***********************/
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
/* 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
  1436
/***********************/
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
  1437
    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
  1438
    	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
  1439
    	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
  1440
    }
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
    
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
  1442
/*****************************/
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
  1443
/* 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
  1444
/*****************************/
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
  1445
    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
  1446
    	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
  1447
    	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
  1448
    }
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
  1449
    
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
  1450
/**********************/
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
  1451
/* 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
  1452
/**********************/    
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
    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
  1454
    	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
  1455
    	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
  1456
    }
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
  1457
    
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
  1458
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
  1459
/********************************/
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
  1460
/* 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
  1461
/********************************/
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
  1462
    void *visit(configuration_declaration_c *symbol) {
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1463
  	  static int configuration_count = 0;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1464
  
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1465
      if (configuration_count++) {
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1466
        /* the first configuration is the one we will use!! */
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1467
        ERROR;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1468
      }
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1469
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1470
      current_configuration = symbol;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1471
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1472
      calculate_common_ticktime_c calculate_common_ticktime;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1473
      symbol->accept(calculate_common_ticktime);
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1474
      common_ticktime = calculate_common_ticktime.get_ticktime();
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1475
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1476
      symbol->configuration_name->accept(*this);
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
  1477
      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
  1478
      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
  1479
      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
  1480
        
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 40
diff changeset
  1481
      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
  1482
      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
  1483
      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
  1484
      
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1485
      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
  1486
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1487
      current_configuration = NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1488
      
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1489
      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
  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
    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
  1493
    	symbol->resource_name->accept(*this);
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
  1494
    	stage4out_c resources_s4o(current_builddir, current_name, "c");
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1495
      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
  1496
    	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
  1497
    	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
  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
    void *visit(single_resource_declaration_c *symbol) {
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
  1501
    	stage4out_c resources_s4o(current_builddir, "RESOURCE", "c");
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
  1502
      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
  1503
    	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
  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
};
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1508
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1509
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1510
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1511
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1512
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1513
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1514
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1515
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1516
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1517
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1518
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1519
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1520
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
  1521
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
  1522
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
  1523
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
  1524