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