main.cc
author Mario de Sousa <msousa@fe.up.pt>
Fri, 26 Aug 2011 11:29:43 +0100
changeset 368 63cee5103e8f
parent 362 6482d83fadee
child 370 f3cec8694f65
permissions -rwxr-xr-x
Update which files to ignore due to new autotools building environment.
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
/*
261
db2ad6541d92 Updating licensing information.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
     2
 *  matiec - a compiler for the programming languages defined in IEC 61131-3
db2ad6541d92 Updating licensing information.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
     3
 *  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: 261
diff changeset
     4
 *  Copyright (C) 2007-2011  Laurent Bessard and Edouard Tisserant
261
db2ad6541d92 Updating licensing information.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
     5
 *
db2ad6541d92 Updating licensing information.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
     6
 *  This program is free software: you can redistribute it and/or modify
db2ad6541d92 Updating licensing information.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
     7
 *  it under the terms of the GNU General Public License as published by
db2ad6541d92 Updating licensing information.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
     8
 *  the Free Software Foundation, either version 3 of the License, or
db2ad6541d92 Updating licensing information.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
     9
 *  (at your option) any later version.
db2ad6541d92 Updating licensing information.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    10
 *
db2ad6541d92 Updating licensing information.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    11
 *  This program is distributed in the hope that it will be useful,
db2ad6541d92 Updating licensing information.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
db2ad6541d92 Updating licensing information.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
db2ad6541d92 Updating licensing information.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    14
 *  GNU General Public License for more details.
db2ad6541d92 Updating licensing information.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    15
 *
db2ad6541d92 Updating licensing information.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    16
 *  You should have received a copy of the GNU General Public License
db2ad6541d92 Updating licensing information.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    17
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
db2ad6541d92 Updating licensing information.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    18
 *
0
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
 * 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
    21
 * 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
    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
/*
261
db2ad6541d92 Updating licensing information.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
    25
 * 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
    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
 * 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
    28
 * 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
    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
 ****************************************************************
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
 *********   O V E R A L L    A R C H I T E C T U R E   *********
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
 ****************************************************************
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
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    45
 The compiler works in 4(+1) stages:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    46
 Stage 1   - Lexical analyser      - implemented with flex (iec.flex)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    47
 Stage 2   - Syntax parser         - implemented with bison (iec.y)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    48
 Stage 3   - Semantics analyser    - not yet implemented
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    49
 Stage 4   - Code generator        - implemented in C++
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    50
 Stage 4+1 - Binary code generator - gcc, javac, etc...
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
 Data structures passed between stages, in global variables:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    54
 1->2   : tokens (int), and token values (char *)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    55
 2->1   : symbol tables (defined in 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
    56
 2->3   : abstract syntax tree (tree of C++ classes, in absyntax.hh file)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    57
 3->4   : Same as 2->3
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    58
 4->4+1 : file with program in c, java, etc...
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    59
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    60
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    61
 The compiler works in several passes:
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    62
 Pass 1: executes stages 1 and 2 simultaneously
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    63
 Pass 2: executes stage 3
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    64
 Pass 3: executes stage 4
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    65
 Pass 4: executes stage 4+1
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    66
*/
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    67
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
//#include <stdio.h>   // printf()
186
f0a41f731cea bug when compiling for windows (missing getopt.h) fixed
greg
parents: 181
diff changeset
    71
#include <getopt.h>
139
668a54686827 added missing includes on some platform (gentoo/gcc-4.3.1)
etisserant
parents: 136
diff changeset
    72
#include <string.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
    73
#include <stdlib.h>  // EXIT_FAILURE
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    74
#include "absyntax/absyntax.hh"  // symbol_c type
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 macro for printing out internal parser errors... */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    77
#include <iostream> // required for std::cerr
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 315
diff changeset
    78
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 315
diff changeset
    79
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 315
diff changeset
    80
#define ERROR          error_exit(__FILE__,__LINE__)
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    81
void error_exit(const char *file_name, int line_no) {
350
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 315
diff changeset
    82
  std::cerr << "\nInternal compiler error in file " << file_name
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 315
diff changeset
    83
            << " at line " << line_no << "\n";
2c3c4dc34979 Support for semantic verification of calls to standard functions.
Mario de Sousa <msousa@fe.up.pt>
parents: 315
diff changeset
    84
//   if (msg != NULL) std::cerr << message << "\n\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
    85
  exit(EXIT_FAILURE);
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    86
}
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
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    89
362
6482d83fadee Add print version command line option.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
    90
#include "config/config.h"
177
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
    91
#include "stage1_2/stage1_2.hh"
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents: 179
diff changeset
    92
#include "absyntax_utils/absyntax_utils.hh"
177
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
    93
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 186
diff changeset
    94
int stage3(symbol_c *tree_root);
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 0
diff changeset
    95
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
    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
static void printusage(const char *cmd) {
362
6482d83fadee Add print version command line option.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
    99
  printf("syntax: %s [-h] [-v] [-f] [-s] [-I <include_directory>] [-T <target_directory>] <input_file>\n", cmd);
177
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   100
  printf("  h : show this help message\n");
362
6482d83fadee Add print version command line option.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   101
  printf("  v : print version number\n");  
6482d83fadee Add print version command line option.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   102
  printf("  f : display full token location on error messages\n");
177
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   103
      /******************************************************/
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   104
      /* whether we are suporting safe extensions           */
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   105
      /* as defined in PLCopen - Technical Committee 5      */
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   106
      /* Safety Software Technical Specification,           */
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   107
      /* Part 1: Concepts and Function Blocks,              */
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   108
      /* Version 1.0 – Official Release                     */
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   109
      /******************************************************/
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   110
  printf("  s : allow use of safe extensions\n");
261
db2ad6541d92 Updating licensing information.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   111
  printf("\n");
db2ad6541d92 Updating licensing information.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   112
  printf("%s - Copyright (C) 2003-2011 \n"
db2ad6541d92 Updating licensing information.
Mario de Sousa <msousa@fe.up.pt>
parents: 202
diff changeset
   113
         "This program comes with ABSOLUTELY NO WARRANTY!\n"
362
6482d83fadee Add print version command line option.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   114
         "This is free software licensed under GPL v3, and you are welcome to redistribute it under the conditions specified by this license.\n", PACKAGE_NAME);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   115
}
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
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   118
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   119
int main(int argc, char **argv) {
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   120
  symbol_c *tree_root;
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 0
diff changeset
   121
  char * builddir = NULL;
177
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   122
  stage1_2_options_t stage1_2_options = {false, false, NULL};
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   123
  int optres, errflg = 0;
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   124
/*
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   125
  extern char *optarg;
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   126
  extern int optind, optopt;
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   127
*/
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 0
diff changeset
   128
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents: 179
diff changeset
   129
  /******************************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents: 179
diff changeset
   130
  /*   Parse command line options...        */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents: 179
diff changeset
   131
  /******************************************/
362
6482d83fadee Add print version command line option.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   132
  while ((optres = getopt(argc, argv, ":hvfsI:T:")) != -1) {
177
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   133
    switch(optres) {
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   134
    case 'h':
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   135
      printusage(argv[0]);
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   136
      return 0;
362
6482d83fadee Add print version command line option.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   137
    case 'v':
6482d83fadee Add print version command line option.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   138
      fprintf(stdout, "%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);      
6482d83fadee Add print version command line option.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   139
      return 0;        
177
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   140
    case 'f':
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   141
      stage1_2_options.full_token_loc = true;
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   142
      break;
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   143
    case 's':
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   144
      stage1_2_options.safe_extensions = true;
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   145
      break;
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   146
    case 'I':
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   147
      stage1_2_options.includedir = optarg;
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   148
      break;
179
a4eb4fd6b0d6 Target Directory not parsed in command line fixed
lbessard
parents: 178
diff changeset
   149
    case 'T':
a4eb4fd6b0d6 Target Directory not parsed in command line fixed
lbessard
parents: 178
diff changeset
   150
      builddir = optarg;
a4eb4fd6b0d6 Target Directory not parsed in command line fixed
lbessard
parents: 178
diff changeset
   151
      break;
177
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   152
    case ':':       /* -I or -T without operand */
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   153
      fprintf(stderr, "Option -%c requires an operand\n", optopt);
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   154
      errflg++;
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   155
      break;
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   156
    case '?':
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents: 179
diff changeset
   157
      fprintf(stderr, "Unrecognized option: -%c\n", optopt);
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents: 179
diff changeset
   158
      errflg++;
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents: 179
diff changeset
   159
      break;
177
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   160
    default:
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents: 179
diff changeset
   161
      fprintf(stderr, "Unknown error while parsing command line options.");
177
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   162
      errflg++;
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   163
      break;
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   164
    }
0
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
177
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   167
  if (optind == argc) {
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   168
    fprintf(stderr, "Missing input file\n");
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   169
    errflg++;
136
32bd7ef40897 Adding some improvements:
lbessard
parents: 47
diff changeset
   170
  }
32bd7ef40897 Adding some improvements:
lbessard
parents: 47
diff changeset
   171
177
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   172
  if (optind > argc) {
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   173
    fprintf(stderr, "Too many input files\n");
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   174
    errflg++;
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   175
  }
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   176
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   177
  if (errflg) {
362
6482d83fadee Add print version command line option.
Mario de Sousa <msousa@fe.up.pt>
parents: 350
diff changeset
   178
      printf("\n");
136
32bd7ef40897 Adding some improvements:
lbessard
parents: 47
diff changeset
   179
      printusage(argv[0]);
32bd7ef40897 Adding some improvements:
lbessard
parents: 47
diff changeset
   180
      return EXIT_FAILURE;
32bd7ef40897 Adding some improvements:
lbessard
parents: 47
diff changeset
   181
  }
32bd7ef40897 Adding some improvements:
lbessard
parents: 47
diff changeset
   182
32bd7ef40897 Adding some improvements:
lbessard
parents: 47
diff changeset
   183
181
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents: 179
diff changeset
   184
  /***************************/
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents: 179
diff changeset
   185
  /*   Run the compiler...   */
38d6eb056260 Moving absyntax utility files out from stage4/generate_c
mario
parents: 179
diff changeset
   186
  /***************************/
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   187
  /* 1st Pass */
177
697562a5da7c Adding support for SAFEBOOL. Some code generation yet to do...
mario
parents: 139
diff changeset
   188
  if (stage1_2(argv[optind], &tree_root, stage1_2_options) < 0)
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   189
    return EXIT_FAILURE;
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
  /* 2nd Pass */
315
c62a4078f269 Allow use of ENO keyword in structured variable field selector.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   192
    /* basically loads some symbol tables to speed up look ups later on */
c62a4078f269 Allow use of ENO keyword in structured variable field selector.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   193
  absyntax_utils_init(tree_root);  
c62a4078f269 Allow use of ENO keyword in structured variable field selector.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   194
    /* moved to bison, although it could perfectly well still be here instead of in bison code. */
c62a4078f269 Allow use of ENO keyword in structured variable field selector.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   195
  //add_en_eno_param_decl_c::add_to(tree_root);
c62a4078f269 Allow use of ENO keyword in structured variable field selector.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   196
c62a4078f269 Allow use of ENO keyword in structured variable field selector.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   197
  /* Only very simple (not yet complete) data type checking currently implemented... */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   198
  if (stage3(tree_root) < 0)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   199
    return EXIT_FAILURE;
202
da1a8186f86f Initial (very rough) version of semantic checker (stage3)
Catarina Boucinha <ccb@fe.up.pt>
parents: 186
diff changeset
   200
  
0
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
  /* 3rd Pass */
46
fc1b78ea6d84 Adding support for generating files into an user-defined folder
lbessard
parents: 0
diff changeset
   203
  if (stage4(tree_root, builddir) < 0)
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   204
    return EXIT_FAILURE;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   205
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   206
  /* 4th Pass */
315
c62a4078f269 Allow use of ENO keyword in structured variable field selector.
Mario de Sousa <msousa@fe.up.pt>
parents: 279
diff changeset
   207
  /* Call gcc, g++, or whatever... */
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   208
  /* Currently implemented in the Makefile! */
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   209
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   210
  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
   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
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   213