65 Pass 4: executes stage 4+1 |
65 Pass 4: executes stage 4+1 |
66 */ |
66 */ |
67 |
67 |
68 |
68 |
69 |
69 |
70 //#include <stdio.h> // printf() |
70 #include <stdio.h> |
71 #include <getopt.h> |
71 #include <getopt.h> |
72 #include <string.h> |
72 #include <string.h> |
73 #include <stdlib.h> // EXIT_FAILURE |
73 #include <stdlib.h> |
74 #include "absyntax/absyntax.hh" // symbol_c type |
74 #include <stdarg.h> |
75 |
75 #include <iostream> |
76 /* A macro for printing out internal parser errors... */ |
76 |
77 #include <iostream> // required for std::cerr |
77 |
|
78 #include "config/config.h" |
|
79 #include "absyntax/absyntax.hh" |
|
80 #include "absyntax_utils/absyntax_utils.hh" |
|
81 #include "stage1_2/stage1_2.hh" |
|
82 #include "stage3/stage3.hh" |
|
83 #include "stage4/stage4.hh" |
|
84 #include "main.hh" |
|
85 |
78 |
86 |
79 #ifndef HGVERSION |
87 #ifndef HGVERSION |
80 #define HGVERSION "" |
88 #define HGVERSION "" |
81 #endif |
89 #endif |
82 |
90 |
83 #include "main.hh" // symbol_c type |
91 |
84 #include <stdarg.h> // required for va_start(), va_list |
|
85 |
92 |
86 void error_exit(const char *file_name, int line_no, const char *errmsg, ...) { |
93 void error_exit(const char *file_name, int line_no, const char *errmsg, ...) { |
87 va_list argptr; |
94 va_list argptr; |
88 va_start(argptr, errmsg); /* second argument is last fixed pamater of error_exit() */ |
95 va_start(argptr, errmsg); /* second argument is last fixed pamater of error_exit() */ |
89 |
96 |
99 |
106 |
100 exit(EXIT_FAILURE); |
107 exit(EXIT_FAILURE); |
101 } |
108 } |
102 |
109 |
103 |
110 |
104 |
|
105 #include "config/config.h" |
|
106 #include "stage1_2/stage1_2.hh" |
|
107 #include "absyntax_utils/absyntax_utils.hh" |
|
108 |
|
109 int stage3(symbol_c *tree_root); |
|
110 int stage4(symbol_c *tree_root, const char *builddir); |
|
111 |
|
112 |
|
113 static void printusage(const char *cmd) { |
111 static void printusage(const char *cmd) { |
114 printf("syntax: %s [-h] [-v] [-f] [-s] [-I <include_directory>] [-T <target_directory>] <input_file>\n", cmd); |
112 printf("\nsyntax: %s [-h] [-v] [-f] [-s] [-c] [-I <include_directory>] [-T <target_directory>] <input_file>\n", cmd); |
115 printf(" h : show this help message\n"); |
113 printf(" h : show this help message\n"); |
116 printf(" v : print version number\n"); |
114 printf(" v : print version number\n"); |
117 printf(" f : display full token location on error messages\n"); |
115 printf(" f : display full token location on error messages\n"); |
118 /******************************************************/ |
116 /******************************************************/ |
119 /* whether we are suporting safe extensions */ |
117 /* whether we are supporting safe extensions */ |
120 /* as defined in PLCopen - Technical Committee 5 */ |
118 /* as defined in PLCopen - Technical Committee 5 */ |
121 /* Safety Software Technical Specification, */ |
119 /* Safety Software Technical Specification, */ |
122 /* Part 1: Concepts and Function Blocks, */ |
120 /* Part 1: Concepts and Function Blocks, */ |
123 /* Version 1.0 – Official Release */ |
121 /* Version 1.0 is Official Release */ |
124 /******************************************************/ |
122 /******************************************************/ |
125 printf(" s : allow use of safe extensions\n"); |
123 printf(" s : allow use of safe extensions\n"); |
|
124 printf(" c : create conversion functions\n"); |
126 printf("\n"); |
125 printf("\n"); |
127 printf("%s - Copyright (C) 2003-2011 \n" |
126 printf("%s - Copyright (C) 2003-2011 \n" |
128 "This program comes with ABSOLUTELY NO WARRANTY!\n" |
127 "This program comes with ABSOLUTELY NO WARRANTY!\n" |
129 "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); |
128 "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); |
130 } |
129 } |
135 symbol_c *tree_root; |
134 symbol_c *tree_root; |
136 char * builddir = NULL; |
135 char * builddir = NULL; |
137 stage1_2_options_t stage1_2_options = {false, false, NULL}; |
136 stage1_2_options_t stage1_2_options = {false, false, NULL}; |
138 int optres, errflg = 0; |
137 int optres, errflg = 0; |
139 int path_len; |
138 int path_len; |
140 /* |
139 |
141 extern char *optarg; |
|
142 extern int optind, optopt; |
|
143 */ |
|
144 |
140 |
145 /******************************************/ |
141 /******************************************/ |
146 /* Parse command line options... */ |
142 /* Parse command line options... */ |
147 /******************************************/ |
143 /******************************************/ |
148 while ((optres = getopt(argc, argv, ":hvfsI:T:")) != -1) { |
144 while ((optres = getopt(argc, argv, ":hvfscI:T:")) != -1) { |
149 switch(optres) { |
145 switch(optres) { |
150 case 'h': |
146 case 'h': |
151 printusage(argv[0]); |
147 printusage(argv[0]); |
152 return 0; |
148 return 0; |
|
149 |
153 case 'v': |
150 case 'v': |
154 fprintf(stdout, "%s version %s\n" |
151 fprintf(stdout, "%s version %s\n" |
155 "changeset id: %s\n", PACKAGE_NAME, PACKAGE_VERSION, HGVERSION); |
152 "changeset id: %s\n", PACKAGE_NAME, PACKAGE_VERSION, HGVERSION); |
156 return 0; |
153 return 0; |
|
154 |
157 case 'f': |
155 case 'f': |
158 stage1_2_options.full_token_loc = true; |
156 stage1_2_options.full_token_loc = true; |
159 break; |
157 break; |
|
158 |
160 case 's': |
159 case 's': |
161 stage1_2_options.safe_extensions = true; |
160 stage1_2_options.safe_extensions = true; |
162 break; |
161 break; |
|
162 |
|
163 case 'c': |
|
164 stage1_2_options.conversion_functions = true; |
|
165 break; |
|
166 |
163 case 'I': |
167 case 'I': |
164 /* NOTE: To improve the usability under windows: |
168 /* NOTE: To improve the usability under windows: |
165 * We delete last char's path if it ends with "\". |
169 * We delete last char's path if it ends with "\". |
166 * In this way compiler front-end accepts paths with or without |
170 * In this way compiler front-end accepts paths with or without |
167 * slash terminator. |
171 * slash terminator. |
168 */ |
172 */ |
169 path_len = strlen(optarg) - 1; |
173 path_len = strlen(optarg) - 1; |
170 if (optarg[path_len] == '\\') optarg[path_len]= '\0'; |
174 if (optarg[path_len] == '\\') optarg[path_len]= '\0'; |
171 stage1_2_options.includedir = optarg; |
175 stage1_2_options.includedir = optarg; |
172 break; |
176 break; |
|
177 |
173 case 'T': |
178 case 'T': |
174 /* NOTE: see note above */ |
179 /* NOTE: see note above */ |
175 path_len = strlen(optarg) - 1; |
180 path_len = strlen(optarg) - 1; |
176 if (optarg[path_len] == '\\') optarg[path_len]= '\0'; |
181 if (optarg[path_len] == '\\') optarg[path_len]= '\0'; |
177 builddir = optarg; |
182 builddir = optarg; |
178 break; |
183 break; |
|
184 |
179 case ':': /* -I or -T without operand */ |
185 case ':': /* -I or -T without operand */ |
180 fprintf(stderr, "Option -%c requires an operand\n", optopt); |
186 fprintf(stderr, "Option -%c requires an operand\n", optopt); |
181 errflg++; |
187 errflg++; |
182 break; |
188 break; |
|
189 |
183 case '?': |
190 case '?': |
184 fprintf(stderr, "Unrecognized option: -%c\n", optopt); |
191 fprintf(stderr, "Unrecognized option: -%c\n", optopt); |
185 errflg++; |
192 errflg++; |
186 break; |
193 break; |
|
194 |
187 default: |
195 default: |
188 fprintf(stderr, "Unknown error while parsing command line options."); |
196 fprintf(stderr, "Unknown error while parsing command line options."); |
189 errflg++; |
197 errflg++; |
190 break; |
198 break; |
191 } |
199 } |