main.cc
changeset 946 c012a64dc2fa
parent 934 2a42a68f4b59
child 956 513809fbfaf9
equal deleted inserted replaced
945:477393b00f95 946:c012a64dc2fa
   111 static void printusage(const char *cmd) {
   111 static void printusage(const char *cmd) {
   112   printf("\nsyntax: %s [<options>] [-O <output_options>] [-I <include_directory>] [-T <target_directory>] <input_file>\n", cmd);
   112   printf("\nsyntax: %s [<options>] [-O <output_options>] [-I <include_directory>] [-T <target_directory>] <input_file>\n", cmd);
   113   printf(" -h : show this help message\n");
   113   printf(" -h : show this help message\n");
   114   printf(" -v : print version number\n");  
   114   printf(" -v : print version number\n");  
   115   printf(" -f : display full token location on error messages\n");
   115   printf(" -f : display full token location on error messages\n");
   116       /******************************************************/
   116   printf(" -l : use a relaxed datatype equivalence model       (a non-standard extension?)\n");  
   117       /* whether we are supporting safe extensions          */
   117   printf(" -s : allow use of safe datatypes (SAFEBOOL, etc.)   (defined in PLCOpen Safety)\n"); // PLCopen TC5 "Safety Software Technical Specification - Part 1" v1.0
   118       /* as defined in PLCopen - Technical Committee 5      */
       
   119       /* Safety Software Technical Specification,           */
       
   120       /* Part 1: Concepts and Function Blocks,              */
       
   121       /* Version 1.0 is Official Release                    */
       
   122       /******************************************************/
       
   123   printf(" -s : allow use of safe datatypes (SAFEBOOL, etc.)   (defined in PLCOpen Safety)\n");
       
   124   printf(" -n : allow use of nested comments                   (an IEC 61131-3 v3 feature)\n");
       
   125   printf(" -r : allow use of references (REF_TO, REF, ^, NULL) (an IEC 61131-3 v3 feature)\n");
   118   printf(" -r : allow use of references (REF_TO, REF, ^, NULL) (an IEC 61131-3 v3 feature)\n");
   126   printf(" -R : allow use of REF_TO ANY datatypes              (a non-standard extension!)\n");
   119   printf(" -R : allow use of REF_TO ANY datatypes              (a non-standard extension!)\n");
   127   printf("        as well as REF_TO in ARRAYs and STRUCTs      (a non-standard extension!)\n");
   120   printf("        as well as REF_TO in ARRAYs and STRUCTs      (a non-standard extension!)\n");
   128   printf(" -c : create conversion functions for enumerated data types\n");
   121   printf(" -c : create conversion functions for enumerated data types\n");
   129   printf(" -O : options for output (code generation) stage. Available options for %s are...\n", cmd);
   122   printf(" -O : options for output (code generation) stage. Available options for %s are...\n", cmd);
   133          "This program comes with ABSOLUTELY NO WARRANTY!\n"
   126          "This program comes with ABSOLUTELY NO WARRANTY!\n"
   134          "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);
   127          "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);
   135 }
   128 }
   136 
   129 
   137 
   130 
       
   131 /* declare the global options variable */
       
   132 runtime_options_t runtime_options;
       
   133 
   138 
   134 
   139 int main(int argc, char **argv) {
   135 int main(int argc, char **argv) {
   140   symbol_c *tree_root;
   136   symbol_c *tree_root;
   141   char * builddir = NULL;
   137   char * builddir = NULL;
   142   stage1_2_options_t stage1_2_options;
       
   143   int optres, errflg = 0;
   138   int optres, errflg = 0;
   144   int path_len;
   139   int path_len;
   145 
   140 
   146   /* Default values for the command line options... */
   141   /* Default values for the command line options... */
   147   stage1_2_options.safe_extensions         = false; /* allow use of SAFExxx datatypes */
   142   runtime_options.safe_extensions         = false; /* allow use of SAFExxx datatypes */
   148   stage1_2_options.full_token_loc          = false; /* error messages specify full token location */
   143   runtime_options.full_token_loc          = false; /* error messages specify full token location */
   149   stage1_2_options.conversion_functions    = false; /* Create a conversion function for derived datatype */
   144   runtime_options.conversion_functions    = false; /* Create a conversion function for derived datatype */
   150   stage1_2_options.nested_comments         = false; /* Allow the use of nested comments. */
   145   runtime_options.nested_comments         = false; /* Allow the use of nested comments. */
   151   stage1_2_options.ref_standard_extensions = false; /* Allow the use of REFerences (keywords REF_TO, REF, DREF, ^, NULL). */
   146   runtime_options.ref_standard_extensions = false; /* Allow the use of REFerences (keywords REF_TO, REF, DREF, ^, NULL). */
   152   stage1_2_options.ref_nonstand_extensions = false; /* Allow the use of non-standard extensions to REF_TO datatypes: REF_TO ANY, and REF_TO in struct elements! */
   147   runtime_options.ref_nonstand_extensions = false; /* Allow the use of non-standard extensions to REF_TO datatypes: REF_TO ANY, and REF_TO in struct elements! */
   153   stage1_2_options.includedir              = NULL;  /* Include directory, where included files will be searched for... */
   148   runtime_options.includedir              = NULL;  /* Include directory, where included files will be searched for... */
   154 
   149 
       
   150   /* Default values for the command line options... */
       
   151   runtime_options.relaxed_datatype_model    = false; /* by default use the strict datatype equivalence model */
       
   152   
   155   /******************************************/
   153   /******************************************/
   156   /*   Parse command line options...        */
   154   /*   Parse command line options...        */
   157   /******************************************/
   155   /******************************************/
   158   while ((optres = getopt(argc, argv, ":nhvfrRscI:T:O:")) != -1) {
   156   while ((optres = getopt(argc, argv, ":nhvflsrRcI:T:O:")) != -1) {
   159     switch(optres) {
   157     switch(optres) {
   160     case 'h':
   158     case 'h':
   161       printusage(argv[0]);
   159       printusage(argv[0]);
   162       return 0;
   160       return 0;
   163     case 'v':
   161     case 'v':
   164       fprintf(stdout, "%s version %s\n" "changeset id: %s\n", PACKAGE_NAME, PACKAGE_VERSION, HGVERSION);      
   162       fprintf(stdout, "%s version %s\n" "changeset id: %s\n", PACKAGE_NAME, PACKAGE_VERSION, HGVERSION);      
   165       return 0;
   163       return 0;
       
   164     case 'l':
       
   165       runtime_options.relaxed_datatype_model = true;
       
   166       break;
       
   167   
   166     case 'f':
   168     case 'f':
   167       stage1_2_options.full_token_loc = true;
   169       runtime_options.full_token_loc = true;
   168       break;
   170       break;
   169     case 's':
   171     case 's':
   170       stage1_2_options.safe_extensions = true;
   172       runtime_options.safe_extensions = true;
   171       break;
   173       break;
   172     case 'R':
   174     case 'R':
   173       stage1_2_options.ref_standard_extensions = true; /* use of REF_TO ANY implies activating support for REF extensions! */
   175       runtime_options.ref_standard_extensions = true; /* use of REF_TO ANY implies activating support for REF extensions! */
   174       stage1_2_options.ref_nonstand_extensions = true;
   176       runtime_options.ref_nonstand_extensions = true;
   175       break;
   177       break;
   176     case 'r':
   178     case 'r':
   177       stage1_2_options.ref_standard_extensions = true;
   179       runtime_options.ref_standard_extensions = true;
   178       break;
   180       break;
   179     case 'c':
   181     case 'c':
   180       stage1_2_options.conversion_functions = true;
   182       runtime_options.conversion_functions = true;
   181       break;
   183       break;
   182     case 'n':
   184     case 'n':
   183       stage1_2_options.nested_comments = true;
   185       runtime_options.nested_comments = true;
   184       break;
   186       break;
   185     case 'I':
   187     case 'I':
   186       /* NOTE: To improve the usability under windows:
   188       /* NOTE: To improve the usability under windows:
   187        *       We delete last char's path if it ends with "\".
   189        *       We delete last char's path if it ends with "\".
   188        *       In this way compiler front-end accepts paths with or without
   190        *       In this way compiler front-end accepts paths with or without
   189        *       slash terminator.
   191        *       slash terminator.
   190        */
   192        */
   191       path_len = strlen(optarg) - 1;
   193       path_len = strlen(optarg) - 1;
   192       if (optarg[path_len] == '\\') optarg[path_len]= '\0';
   194       if (optarg[path_len] == '\\') optarg[path_len]= '\0';
   193       stage1_2_options.includedir = optarg;
   195       runtime_options.includedir = optarg;
   194       break;
   196       break;
   195     case 'T':
   197     case 'T':
   196       /* NOTE: see note above */
   198       /* NOTE: see note above */
   197       path_len = strlen(optarg) - 1;
   199       path_len = strlen(optarg) - 1;
   198       if (optarg[path_len] == '\\') optarg[path_len]= '\0';
   200       if (optarg[path_len] == '\\') optarg[path_len]= '\0';
   234 
   236 
   235   /***************************/
   237   /***************************/
   236   /*   Run the compiler...   */
   238   /*   Run the compiler...   */
   237   /***************************/
   239   /***************************/
   238   /* 1st Pass */
   240   /* 1st Pass */
   239   if (stage1_2(argv[optind], &tree_root, stage1_2_options) < 0)
   241   if (stage1_2(argv[optind], &tree_root) < 0)
   240     return EXIT_FAILURE;
   242     return EXIT_FAILURE;
   241 
   243 
   242   /* 2nd Pass */
   244   /* 2nd Pass */
   243     /* basically loads some symbol tables to speed up look ups later on */
   245     /* basically loads some symbol tables to speed up look ups later on */
   244   absyntax_utils_init(tree_root);  
   246   absyntax_utils_init(tree_root);  
   245     /* moved to bison, although it could perfectly well still be here instead of in bison code. */
   247     /* moved to bison, although it could perfectly well still be here instead of in bison code. */
   246   //add_en_eno_param_decl_c::add_to(tree_root);
   248   //add_en_eno_param_decl_c::add_to(tree_root);
   247 
   249 
   248   /* Do semantic verification of code (data type and lvalue checking currently implemented) */
   250   /* Do semantic verification of code */
   249   if (stage3(tree_root) < 0)
   251   if (stage3(tree_root) < 0)
   250     return EXIT_FAILURE;
   252     return EXIT_FAILURE;
   251   
   253   
   252   /* 3rd Pass */
   254   /* 3rd Pass */
   253   if (stage4(tree_root, builddir) < 0)
   255   if (stage4(tree_root, builddir) < 0)