stage4/stage4.cc
author Conti Manuele <conti.ma@alice.it>
Thu, 03 May 2012 17:43:32 +0200
changeset 539 1ff26534a54f
parent 522 f9cff11ae622
child 546 8cc4c51c4bfc
permissions -rwxr-xr-x
Fix __dt_to_timespec primitive function.
Set tm_isdst = 0 to disable DayLight Savig Time.
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     1
/*
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
     2
 *  Copyright (C) 2003-2011  Mario de Sousa (msousa@fe.up.pt)
279
c0453b7f99df Re-generated std lib related code, with updated headers, updated all forgotten headers
Edouard Tisserant
parents: 267
diff changeset
     3
 *  Copyright (C) 2007-2011  Laurent Bessard and Edouard Tisserant
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
     4
 *
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
     5
 *  This program is free software: you can redistribute it and/or modify
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
     6
 *  it under the terms of the GNU General Public License as published by
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
     7
 *  the Free Software Foundation, either version 3 of the License, or
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
     8
 *  (at your option) any later version.
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
     9
 *
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    10
 *  This program is distributed in the hope that it will be useful,
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    13
 *  GNU General Public License for more details.
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    14
 *
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    15
 *  You should have received a copy of the GNU General Public License
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    16
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    17
 *
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    18
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    19
 * 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
    20
 * 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
    21
 */
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
/*
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    24
 * An IEC 61131-3 compiler.
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    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
 * 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
    27
 * 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
    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
 */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    30
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    31
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    32
/*
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    33
 * This file contains the code that stores the output generated
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    34
 * by each specific version of the 4th stage.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    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
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    39
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    40
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    41
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    42
// #include <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
    43
#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
    44
#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
    45
#include <fstream>
139
668a54686827 added missing includes on some platform (gentoo/gcc-4.3.1)
etisserant
parents: 55
diff changeset
    46
#include <stdlib.h>
0
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
522
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    51
#define FIRST_(symbol1, symbol2) (((symbol1)->first_order < (symbol2)->first_order)   ? (symbol1) : (symbol2))
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    52
#define  LAST_(symbol1, symbol2) (((symbol1)->last_order  > (symbol2)->last_order)    ? (symbol1) : (symbol2))
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    53
#include <stdarg.h>
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    54
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    55
void stage4err(const char *stage4_generator_id, symbol_c *symbol1, symbol_c *symbol2, const char *errmsg, ...) {
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    56
    va_list argptr;
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    57
    va_start(argptr, errmsg); /* second argument is last fixed pamater of stage4err() */
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    58
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    59
    fprintf(stderr, "%s:%d-%d..%d-%d: error %s: ",
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    60
            FIRST_(symbol1,symbol2)->first_file, FIRST_(symbol1,symbol2)->first_line, FIRST_(symbol1,symbol2)->first_column,
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    61
                                                 LAST_(symbol1,symbol2) ->last_line,  LAST_(symbol1,symbol2) ->last_column,
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    62
            stage4_generator_id);
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    63
    vfprintf(stderr, errmsg, argptr);
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    64
    fprintf(stderr, "\n");
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    65
    // error_count++;
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    66
    va_end(argptr);
f9cff11ae622 Start having nicer stage 4 error messages.
Mario de Sousa <msousa@fe.up.pt>
parents: 397
diff changeset
    67
}
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    68
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
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
    71
stage4out_c::stage4out_c(std::string indent_level):
667721cf52c5 Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents: 26
diff changeset
    72
	m_file(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
    73
  out = &std::cout;
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    74
  this->indent_level = indent_level;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    75
  this->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
    76
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    77
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
    78
stage4out_c::stage4out_c(const char *dir, const char *radix, const char *extension, std::string indent_level) {	
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
    79
  std::string filename(radix);
667721cf52c5 Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents: 26
diff changeset
    80
  filename += ".";
667721cf52c5 Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents: 26
diff changeset
    81
  filename += extension;
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
    82
  std::string filepath("");
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
    83
  if (dir != NULL) {
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
    84
    filepath += dir;
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
    85
    filepath += "/";
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
    86
  }
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
    87
  filepath += filename;
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
    88
  std::fstream *file = new std::fstream(filepath.c_str(), std::fstream::out);
41
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 28
diff changeset
    89
  if(file->fail()){
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 28
diff changeset
    90
    std::cerr << "Cannot open " << filename << " for write access \n";
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 28
diff changeset
    91
    exit(EXIT_FAILURE);
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 28
diff changeset
    92
  }else{
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 28
diff changeset
    93
    std::cout << filename << "\n";
8998c8b24b60 First working IEC std lib test, actually test from string and to_string functions.
etisserant
parents: 28
diff changeset
    94
  }
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
    95
  out = file;
667721cf52c5 Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents: 26
diff changeset
    96
  m_file = file;
667721cf52c5 Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents: 26
diff changeset
    97
  this->indent_level = indent_level;
667721cf52c5 Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents: 26
diff changeset
    98
  this->indent_spaces = "";
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
    99
  allow_output = true;
27
667721cf52c5 Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents: 26
diff changeset
   100
}
667721cf52c5 Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents: 26
diff changeset
   101
667721cf52c5 Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents: 26
diff changeset
   102
stage4out_c::~stage4out_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
   103
  if(m_file)
667721cf52c5 Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents: 26
diff changeset
   104
  {
667721cf52c5 Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents: 26
diff changeset
   105
    m_file->close();
667721cf52c5 Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents: 26
diff changeset
   106
    delete m_file;
667721cf52c5 Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents: 26
diff changeset
   107
  }
667721cf52c5 Now, stage4out can address files. Generate_cc have been split into one visitor per C file : pous, ressource and config. Work in progress.
etisserant
parents: 26
diff changeset
   108
}
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   109
296
9cf0d701d211 Adding fflush capabilities. It is sometimes usefull when debuging the compiler...
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   110
void stage4out_c::flush(void) {
9cf0d701d211 Adding fflush capabilities. It is sometimes usefull when debuging the compiler...
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   111
  out->flush();
9cf0d701d211 Adding fflush capabilities. It is sometimes usefull when debuging the compiler...
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   112
}
9cf0d701d211 Adding fflush capabilities. It is sometimes usefull when debuging the compiler...
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   113
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
   114
void stage4out_c::enable_output(void) {
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
   115
  allow_output = true;
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
   116
}
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
   117
    
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
   118
void stage4out_c::disable_output(void) {
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
   119
  allow_output = false;
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
   120
}
0
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
void stage4out_c::indent_right(void) {
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   123
  indent_spaces+=indent_level;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   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
void stage4out_c::indent_left(void) {
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   127
  if (indent_spaces.length() >= indent_level.length())
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   128
    indent_spaces.erase(indent_spaces.length() - indent_level.length(), indent_level.length());
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   129
  else
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   130
    indent_spaces.erase();
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   131
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   132
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   133
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   134
void *stage4out_c::print(const char *str) {
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
   135
  if (!allow_output) 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
   136
  *out << str;
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   137
  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
   138
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   139
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   140
void *stage4out_c::print_integer(int integer) {
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
   141
  if (!allow_output) return NULL;
28
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   142
  *out << integer;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   143
  return NULL;
5b170c9ce134 Multi-file configuration and resource generation finished
lbessard
parents: 27
diff changeset
   144
}
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   145
397
85151b2f35ca Adding Common_Ticktime to informations printed in VARIABLES.csv file
laurent
parents: 369
diff changeset
   146
void *stage4out_c::print_long_integer(unsigned long l_integer, bool suffix) {
85151b2f35ca Adding Common_Ticktime to informations printed in VARIABLES.csv file
laurent
parents: 369
diff changeset
   147
  if (!allow_output) return NULL;
85151b2f35ca Adding Common_Ticktime to informations printed in VARIABLES.csv file
laurent
parents: 369
diff changeset
   148
  *out << l_integer;
85151b2f35ca Adding Common_Ticktime to informations printed in VARIABLES.csv file
laurent
parents: 369
diff changeset
   149
  if (suffix) *out << "UL";
85151b2f35ca Adding Common_Ticktime to informations printed in VARIABLES.csv file
laurent
parents: 369
diff changeset
   150
  return NULL;
85151b2f35ca Adding Common_Ticktime to informations printed in VARIABLES.csv file
laurent
parents: 369
diff changeset
   151
}
85151b2f35ca Adding Common_Ticktime to informations printed in VARIABLES.csv file
laurent
parents: 369
diff changeset
   152
85151b2f35ca Adding Common_Ticktime to informations printed in VARIABLES.csv file
laurent
parents: 369
diff changeset
   153
void *stage4out_c::print_long_long_integer(unsigned long long ll_integer, bool suffix) {
85151b2f35ca Adding Common_Ticktime to informations printed in VARIABLES.csv file
laurent
parents: 369
diff changeset
   154
  if (!allow_output) return NULL;
85151b2f35ca Adding Common_Ticktime to informations printed in VARIABLES.csv file
laurent
parents: 369
diff changeset
   155
  *out << ll_integer;
85151b2f35ca Adding Common_Ticktime to informations printed in VARIABLES.csv file
laurent
parents: 369
diff changeset
   156
  if (suffix) *out << "ULL";
210
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 202
diff changeset
   157
  return NULL;
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 202
diff changeset
   158
}
8387cac2aba6 Adding support for forcing tick count to return to zero as the same time than all tasks firing are synchronized
laurent
parents: 202
diff changeset
   159
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   160
void *stage4out_c::printupper(const char *str) {
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
   161
  if (!allow_output) return NULL;
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   162
  for (int i = 0; str[i] != '\0'; i++)
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
   163
    *out << (unsigned char)toupper(str[i]);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   164
  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
   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
26
fd67f54e64e1 Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents: 0
diff changeset
   167
void *stage4out_c::printlocation(const char *str) {
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
   168
  if (!allow_output) 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
   169
  *out << "__";
26
fd67f54e64e1 Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents: 0
diff changeset
   170
  for (int i = 0; str[i] != '\0'; i++)
fd67f54e64e1 Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents: 0
diff changeset
   171
    if(str[i] == '.')
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
   172
      *out << '_';
26
fd67f54e64e1 Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents: 0
diff changeset
   173
    else
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
   174
      *out << (unsigned char)toupper(str[i]);
26
fd67f54e64e1 Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents: 0
diff changeset
   175
  return NULL;
fd67f54e64e1 Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents: 0
diff changeset
   176
}
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   177
55
8b7a21820737 Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents: 46
diff changeset
   178
void *stage4out_c::printlocation_comasep(const char *str) {
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
   179
  if (!allow_output) return NULL;
55
8b7a21820737 Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents: 46
diff changeset
   180
  *out << (unsigned char)toupper(str[0]);
8b7a21820737 Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents: 46
diff changeset
   181
  *out << ',';
8b7a21820737 Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents: 46
diff changeset
   182
  *out << (unsigned char)toupper(str[1]);
8b7a21820737 Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents: 46
diff changeset
   183
  *out << ',';
8b7a21820737 Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents: 46
diff changeset
   184
  for (int i = 2; str[i] != '\0'; i++)
8b7a21820737 Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents: 46
diff changeset
   185
    if(str[i] == '.')
8b7a21820737 Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents: 46
diff changeset
   186
      *out << ',';
8b7a21820737 Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents: 46
diff changeset
   187
    else
8b7a21820737 Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents: 46
diff changeset
   188
      *out << (unsigned char)toupper(str[i]);
8b7a21820737 Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents: 46
diff changeset
   189
  return NULL;
8b7a21820737 Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents: 46
diff changeset
   190
}
8b7a21820737 Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents: 46
diff changeset
   191
8b7a21820737 Started support for long long (LL suffix) 64 bit literals on 32 bit platforms (unfinished)
etisserant
parents: 46
diff changeset
   192
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   193
void *stage4out_c::print(std::string str) {
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
   194
  if (!allow_output) 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
   195
  *out << str;
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   196
  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
   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
void *stage4out_c::printupper(std::string str) {
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
   201
  if (!allow_output) return NULL;
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   202
  /* The string standard class does not have a converter member function to upper case.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   203
   * We have to do it ourselves, a character at a time...
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   204
   */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   205
#if 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
  /* The C++ way of doint things... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   207
  for (string::const_iterator p = str.begin(); p != str.end(); ++p)
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
   208
    *out << (unsigned char)toupper(*p);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   209
#else
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   210
  /* Or more simply... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   211
    printupper(str.c_str());
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   212
#endif
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   213
  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
   214
}
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 139
diff changeset
   215
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 139
diff changeset
   216
26
fd67f54e64e1 Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents: 0
diff changeset
   217
void *stage4out_c::printlocation(std::string str) {
267
0a1204bcc9af starting to add proper header file with declaration of standard functions
Mario de Sousa <msousa@fe.up.pt>
parents: 210
diff changeset
   218
  if (!allow_output) 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
   219
  return printlocation(str.c_str());
26
fd67f54e64e1 Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
etisserant
parents: 0
diff changeset
   220
}
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   221
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   222
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   223
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   224
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   225
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   226
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   227
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   228
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   229
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   230
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   231
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   232
/***********************************************************************/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   233
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   234
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   235
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   236
/* forward declarations... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   237
/* These functions will be implemented in generate_XXX.cc */
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
   238
visitor_c *new_code_generator(stage4out_c *s4o, const char *builddir);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   239
void delete_code_generator(visitor_c *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
   240
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   241
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
   242
int stage4(symbol_c *tree_root, const char *builddir) {
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   243
  stage4out_c s4o;
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 41
diff changeset
   244
  visitor_c *generate_code = new_code_generator(&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
   245
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   246
  if (NULL == generate_code)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   247
    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
   248
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   249
  tree_root->accept(*generate_code);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   250
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   251
  delete_code_generator(generate_code);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   252
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   253
  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
   254
}
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   255