source: driver/cfa.cc@ d65f92c

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since d65f92c was 1ee048fd, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

All tests pass with distributed compilation

  • Property mode set to 100644
File size: 19.2 KB
RevLine 
[b87a5ed]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[76c7f65e]7// cfa.cc --
[b87a5ed]8//
[51b73452]9// Author : Peter A. Buhr
10// Created On : Tue Aug 20 13:44:49 2002
[201aeb9]11// Last Modified By : Peter A. Buhr
[4f5a8a2]12// Last Modified On : Sat Aug 10 08:44:15 2019
13// Update Count : 311
[b87a5ed]14//
[51b73452]15
16#include <iostream>
[b87a5ed]17#include <cstdio> // perror
18#include <cstdlib> // putenv, exit
19#include <unistd.h> // execvp
20#include <string> // STL version
[44bca7f]21#include <string.h> // strcmp
[8c63bb4]22#include <algorithm> // find
[51b73452]23
[37fe352]24#include <sys/types.h>
25#include <sys/stat.h>
26
[44bca7f]27#include "Common/SemanticError.h"
[b87a5ed]28#include "config.h" // configure info
[51b73452]29
[8c63bb4]30
[51b73452]31using std::cerr;
32using std::endl;
33using std::string;
[47a8d17]34using std::to_string;
[51b73452]35
36
37//#define __DEBUG_H__
38
39
[1ee048fd]40bool prefix( const string & arg, const string & pre ) {
[b87a5ed]41 return arg.substr( 0, pre.size() ) == pre;
[51b73452]42} // prefix
43
[1ee048fd]44inline bool ends_with(const string & str, const string & sfix) {
45 if (sfix.size() > str.size()) return false;
46 return std::equal(str.rbegin(), str.rbegin() + sfix.size(), sfix.rbegin(), sfix.rend());
47}
48
49bool suffix( const string & arg ) {
50 static const string suffixes[] = { ".cfa", ".hfa", ".cfa.ii" };
51 for(const auto sfix : suffixes) {
52 if(arg.size() <= sfix.size()) continue;
53 size_t pos = arg.find_last_of(sfix);
54 size_t exp = (arg.size() - 1);
55 if(pos == exp) return true;
56 }
57 return false;
[dffaeac]58} // suffix
59
[51b73452]60
[8c63bb4]61void shuffle( const char * args[], int S, int E, int N ) {
[b87a5ed]62 // S & E index 1 passed the end so adjust with -1
[dffaeac]63 #ifdef __DEBUG_H__
[b87a5ed]64 cerr << "shuffle:" << S << " " << E << " " << N << endl;
[dffaeac]65 #endif // __DEBUG_H__
[b87a5ed]66 for ( int j = E-1 + N; j > S-1 + N; j -=1 ) {
[dffaeac]67 #ifdef __DEBUG_H__
[b87a5ed]68 cerr << "\t" << j << " " << j-N << endl;
[dffaeac]69 #endif // __DEBUG_H__
[b87a5ed]70 args[j] = args[j-N];
71 } // for
[51b73452]72} // shuffle
73
[8c63bb4]74static inline bool dirExists( const string & path ) {
[37fe352]75 struct stat info;
76 if(stat( path.c_str(), &info ) != 0)
77 return false;
78 else if(info.st_mode & S_IFDIR)
79 return true;
80 else
81 return false;
82} //dirExists
83
[bbfd0e0]84static inline string dir(const string & path) {
85 return path.substr(0, path.find_last_of('/'));
86}
87
[51b73452]88
[4b1afb6]89#define str(s) #s
90
[8c63bb4]91int main( int argc, char * argv[] ) {
[4b1afb6]92 string Version( CFA_VERSION_LONG ); // current version number from CONFIG
93 string Major( str( CFA_VERSION_MAJOR ) ), Minor( str( CFA_VERSION_MINOR ) ), Patch( str( CFA_VERSION_PATCH ) );
[51b73452]94
[d6f4488]95 string installincdir( CFA_INCDIR ); // fixed location of include files
96 string installlibdir( CFA_LIBDIR ); // fixed location of cc1 and cfa-cpp commands when installed
97 string srcdriverdir ( TOP_BUILDDIR "driver"); // fixed location of cc1 and cfa-cpp commands when in tree
[51b73452]98
[b87a5ed]99 string heading; // banner printed at start of cfa compilation
100 string arg; // current command-line argument during command-line parsing
101 string Bprefix; // path where gcc looks for compiler command steps
102 string langstd; // language standard
[51b73452]103
[e24f13a]104 string compiler_path( CFA_BACKEND_CC ); // path/name of C compiler
[b87a5ed]105 string compiler_name; // name of C compiler
[51b73452]106
[4f5a8a2]107 bool x_flag = false; // -x flag
[b87a5ed]108 bool nonoptarg = false; // indicates non-option argument specified
109 bool link = true; // linking as well as compiling
110 bool verbose = false; // -v flag
[8c63bb4]111 bool quiet = false; // -quiet flag
112 bool debug = true; // -debug flag
113 bool nolib = false; // -nolib flag
114 bool help = false; // -help flag
[b87a5ed]115 bool CFA_flag = false; // -CFA flag
116 bool cpp_flag = false; // -E or -M flag, preprocessor only
[de62360d]117 bool std_flag = false; // -std= flag
[d746bc8]118 bool noincstd_flag = false; // -no-include-stdhdr= flag
[6e4b913]119 bool debugging __attribute(( unused )) = false; // -g flag
[8c63bb4]120 bool m32 = false; // -m32 flag
121 bool m64 = false; // -m64 flag
[37fe352]122 bool intree = false;
[1ee048fd]123 bool compiling_libs = false;
[bbfd0e0]124 bool disttree = false;
[51b73452]125
[b87a5ed]126 const char *args[argc + 100]; // cfa command line values, plus some space for additional flags
127 int sargs = 1; // starting location for arguments in args list
128 int nargs = sargs; // number of arguments in args list; 0 => command name
[51b73452]129
[b87a5ed]130 const char *libs[argc + 20]; // non-user libraries must come separately, plus some added libraries and flags
131 int nlibs = 0;
[51b73452]132
[dffaeac]133 #ifdef __DEBUG_H__
[b87a5ed]134 cerr << "CFA:" << endl;
[bec4d24]135 for ( int i = 1; i < argc; i += 1 ) {
136 cerr << "argv[" << i << "]:\"" << argv[i] << "\"" << endl;
137 } // for
[dffaeac]138 #endif // __DEBUG_H__
[51b73452]139
[b87a5ed]140 // process command-line arguments
[51b73452]141
[b87a5ed]142 for ( int i = 1; i < argc; i += 1 ) {
143 arg = argv[i]; // convert to string value
144 if ( prefix( arg, "-" ) ) {
145 // pass through arguments
146
147 if ( arg == "-Xlinker" || arg == "-o" ) {
148 args[nargs] = argv[i]; // pass the argument along
149 nargs += 1;
150 i += 1;
151 if ( i == argc ) continue; // next argument available ?
152 args[nargs] = argv[i]; // pass the argument along
153 nargs += 1;
154 } else if ( arg == "-XCFA" ) { // CFA pass through
155 i += 1;
156 args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + argv[i] ) ).c_str();
157 nargs += 1;
158
159 // CFA specific arguments
160
161 } else if ( arg == "-CFA" ) {
162 CFA_flag = true; // strip the -CFA flag
163 link = false;
164 args[nargs] = "-E"; // replace the argument with -E
165 nargs += 1;
166 } else if ( arg == "-debug" ) {
167 debug = true; // strip the debug flag
168 } else if ( arg == "-nodebug" ) {
[c9e640e]169 debug = false; // strip the debug flag
170 } else if ( arg == "-nolib" ) {
171 nolib = true; // strip the nodebug flag
[b87a5ed]172 } else if ( arg == "-quiet" ) {
173 quiet = true; // strip the quiet flag
174 } else if ( arg == "-noquiet" ) {
175 quiet = false; // strip the noquiet flag
176 } else if ( arg == "-help" ) {
177 help = true; // strip the help flag
178 } else if ( arg == "-nohelp" ) {
179 help = false; // strip the nohelp flag
[d746bc8]180 } else if ( arg == "-no-include-stdhdr" ) {
181 noincstd_flag = true; // strip the no-include-stdhdr flag
[37fe352]182 } else if ( arg == "-in-tree" ) {
183 intree = true;
[bbfd0e0]184 } else if ( arg == "-dist-tree" ) {
185 disttree = true;
[1ee048fd]186 } else if ( arg == "-cfalib") {
187 compiling_libs = true;
[b87a5ed]188 } else if ( arg == "-compiler" ) {
189 // use the user specified compiler
190 i += 1;
191 if ( i == argc ) continue; // next argument available ?
192 compiler_path = argv[i];
[d6f4488]193 if ( putenv( (char *)( *new string( string( "__CFA_COMPILER__=" ) + argv[i]) ).c_str() ) != 0 ) {
[b87a5ed]194 cerr << argv[0] << " error, cannot set environment variable." << endl;
195 exit( EXIT_FAILURE );
196 } // if
197
[de62360d]198 // C specific arguments
[b87a5ed]199
200 } else if ( arg == "-v" ) {
201 verbose = true; // verbosity required
202 args[nargs] = argv[i]; // pass the argument along
203 nargs += 1;
204 } else if ( arg == "-g" ) {
205 debugging = true; // symbolic debugging required
206 args[nargs] = argv[i]; // pass the argument along
207 nargs += 1;
[8c63bb4]208 } else if ( prefix( arg, "-x" ) ) { // file suffix ?
209 string lang;
210 args[nargs] = argv[i]; // pass the argument along
211 nargs += 1;
212 if ( arg.length() == 2 ) { // separate argument ?
213 i += 1;
214 if ( i == argc ) continue; // next argument available ?
215 lang = argv[i];
216 args[nargs] = argv[i]; // pass the argument along
217 nargs += 1;
218 } else {
219 lang = arg.substr( 2 );
220 } // if
[4f5a8a2]221 x_flag = lang != "none";
[e3215c5]222 } else if ( prefix( arg, "-std=" ) || prefix( arg, "--std=" ) ) {
[53ba273]223 std_flag = true; // -std=XX provided
[de62360d]224 args[nargs] = argv[i]; // pass the argument along
225 nargs += 1;
[44bca7f]226 } else if ( arg == "-w" ) {
227 args[nargs] = argv[i]; // pass the argument along
228 nargs += 1;
229 args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); // add the argument for cfa-cpp
230 nargs += 1;
231 } else if ( prefix( arg, "-W" ) ) { // check before next tests
232 if ( arg == "-Werror" || arg == "-Wall" ) {
233 args[nargs] = argv[i]; // pass the argument along
234 nargs += 1;
235 args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str(); // add the argument for cfa-cpp
236 nargs += 1;
237 } else {
238 unsigned int adv = prefix( arg, "-Wno-" ) ? 5 : 2;
239 args[nargs] = argv[i]; // conditionally pass the argument along
[af39199d]240 const char * warning = argv[i] + adv; // extract warning
241 if ( SemanticWarning_Exist( warning ) ) { // replace the argument for cfa-cpp
242 args[nargs] = ( *new string( string("-D__CFA_FLAG__=") + arg ) ).c_str();
243 } // if
[44bca7f]244 nargs += 1;
245 } // if
[b87a5ed]246 } else if ( prefix( arg, "-B" ) ) {
247 Bprefix = arg.substr(2); // strip the -B flag
248 args[nargs] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str();
249 nargs += 1;
250 } else if ( prefix( arg, "-b" ) ) {
251 if ( arg.length() == 2 ) { // separate argument ?
252 i += 1;
253 if ( i == argc ) continue; // next argument available ?
254 arg += argv[i]; // concatenate argument
255 } // if
256 // later versions of gcc require the -b option to appear at the start of the command line
257 shuffle( args, sargs, nargs, 1 ); // make room at front of argument list
258 args[sargs] = ( *new string( arg ) ).c_str(); // pass the argument along
259 if ( putenv( (char *)( *new string( string( "__GCC_MACHINE__=" ) + arg ) ).c_str() ) != 0 ) {
260 cerr << argv[0] << " error, cannot set environment variable." << endl;
261 exit( EXIT_FAILURE );
262 } // if
263 sargs += 1;
264 nargs += 1;
265 } else if ( prefix( arg, "-V" ) ) {
266 if ( arg.length() == 2 ) { // separate argument ?
267 i += 1;
268 if ( i == argc ) continue; // next argument available ?
269 arg += argv[i]; // concatenate argument
270 } // if
271 // later versions of gcc require the -V option to appear at the start of the command line
272 shuffle( args, sargs, nargs, 1 ); // make room at front of argument list
273 args[sargs] = ( *new string( arg ) ).c_str(); // pass the argument along
274 if ( putenv( (char *)( *new string( string( "__GCC_VERSION__=" ) + arg ) ).c_str() ) != 0 ) {
275 cerr << argv[0] << " error, cannot set environment variable." << endl;
276 exit( EXIT_FAILURE );
277 } // if
278 sargs += 1;
279 nargs += 1;
280 } else if ( arg == "-c" || arg == "-S" || arg == "-E" || arg == "-M" || arg == "-MM" ) {
281 args[nargs] = argv[i]; // pass the argument along
282 nargs += 1;
283 if ( arg == "-E" || arg == "-M" || arg == "-MM" ) {
284 cpp_flag = true; // cpp only
285 } // if
286 link = false; // no linkage required
287 } else if ( arg[1] == 'l' ) {
288 // if the user specifies a library, load it after user code
289 libs[nlibs] = argv[i];
290 nlibs += 1;
[37fe352]291 } else if ( arg == "-m32" ) {
292 m32 = true;
293 m64 = false;
294 args[nargs] = argv[i];
295 nargs += 1;
296 } else if ( arg == "-m64" ) {
297 m64 = true;
298 m32 = false;
299 args[nargs] = argv[i];
300 nargs += 1;
[b87a5ed]301 } else {
302 // concatenate any other arguments
303 args[nargs] = argv[i];
304 nargs += 1;
305 } // if
306 } else {
[8c63bb4]307 bool cfa = suffix( arg ); // check suffix
[4f5a8a2]308 if ( ! x_flag && cfa ) { // no explicit suffix and cfa suffix ?
[8c63bb4]309 args[nargs] = "-x";
310 nargs += 1;
311 args[nargs] = "c";
312 nargs += 1;
313 } // if
[bec4d24]314 args[nargs] = argv[i]; // concatenate file
[b87a5ed]315 nargs += 1;
[4f5a8a2]316 if ( ! x_flag && cfa ) { // no explicit suffix and cfa suffix ?
[dffaeac]317 args[nargs] = "-x";
318 nargs += 1;
319 args[nargs] = "none";
320 nargs += 1;
321 } // if
[b87a5ed]322 nonoptarg = true;
323 } // if
324 } // for
[51b73452]325
[dffaeac]326 #ifdef __x86_64__
[a83d08b]327 args[nargs] = "-mcx16"; // allow double-wide CAA
328 nargs += 1;
[dffaeac]329 #endif // __x86_64__
[e3215c5]330
[dffaeac]331 #ifdef __DEBUG_H__
[b87a5ed]332 cerr << "args:";
333 for ( int i = 1; i < nargs; i += 1 ) {
334 cerr << " " << args[i];
335 } // for
336 cerr << endl;
[dffaeac]337 #endif // __DEBUG_H__
[51b73452]338
[b87a5ed]339 if ( cpp_flag && CFA_flag ) {
340 cerr << argv[0] << " error, cannot use -E and -CFA flags together." << endl;
341 exit( EXIT_FAILURE );
342 } // if
[51b73452]343
[6e4b913]344 // add the CFA include-library paths, which allow direct access to header files without directory qualification
[a5121bf]345 if( !intree ) {
346 args[nargs] = "-I" CFA_INCDIR;
[d746bc8]347 nargs += 1;
[dfb7c96]348 if ( ! noincstd_flag ) { // do not use during build
[b740f0b]349 args[nargs] = "-I" CFA_INCDIR "stdhdr";
[a5121bf]350 nargs += 1;
351 } // if
[b740f0b]352 args[nargs] = "-I" CFA_INCDIR "concurrency";
[a5121bf]353 nargs += 1;
[b740f0b]354 args[nargs] = "-I" CFA_INCDIR "containers";
[a5121bf]355 nargs += 1;
356 } else {
357 args[nargs] = "-I" TOP_SRCDIR "libcfa/src";
358 nargs += 1;
[dfb7c96]359 if ( ! noincstd_flag ) { // do not use during build
[a5121bf]360 args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/stdhdr";
361 nargs += 1;
362 } // if
363 args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/concurrency";
364 nargs += 1;
365 args[nargs] = "-I" TOP_SRCDIR "libcfa/src" "/containers";
366 nargs += 1;
367 }
[76c7f65e]368
[a37133c]369 // add stdbool to get defines for bool/true/false
370 args[nargs] = "-imacros";
371 nargs += 1;
372 args[nargs] = "stdbool.h";
373 nargs += 1;
374
[a5121bf]375 string libbase;
[37fe352]376 if( !intree ) {
[a5121bf]377 libbase = CFA_LIBDIR;
[37fe352]378 } else {
[a5121bf]379 libbase = TOP_BUILDDIR "libcfa/";
[1ee048fd]380 }
381
382 if( compiling_libs ) {
[37fe352]383 args[nargs] = "-D__CFA_FLAG__=-t";
384 nargs += 1;
385 }
386
[dfb7c96]387 string arch = m32 ? CFA_32_CPU : (m64 ? CFA_64_CPU : CFA_DEFAULT_CPU);
[13a984c]388 if ( ! m32 && ! m64 ) {
389 if ( arch == "x86" ) {
390 args[nargs] = "-m32";
391 nargs += 1;
392 } else if ( arch == "x64" ) {
393 args[nargs] = "-m64";
394 nargs += 1;
395 } // if
[dfb7c96]396 } // if
[c9e640e]397 const char * config = nolib ? "nolib" : (debug ? "debug": "nodebug");
[a5121bf]398 string libdir = libbase + arch + "-" + config;
[dfb7c96]399
[bbfd0e0]400 if (!disttree) {
401 if ( ! nolib && ! dirExists( libdir ) ) {
402 cerr << argv[0] << " internal error, configuration " << config << " not installed." << endl;
403 cerr << "Was looking for " << libdir << endl;
404 for(int i = 1; i < argc; i++) {
405 cerr << argv[i] << " ";
406 }
407 cerr << endl;
408 libdir = libbase + arch + "-" + "nolib";
409 } // if
[a5121bf]410
[bbfd0e0]411 if ( ! dirExists( libdir ) ) {
412 cerr << argv[0] << " internal error, cannot find prelude directory." << endl;
413 cerr << "Was looking for " << libdir << endl;
414 exit( EXIT_FAILURE );
415 } // if
[dfb7c96]416 } // if
[a5121bf]417
[bbfd0e0]418 if(disttree) {
419 args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + dir(argv[0])) ).c_str();
420 } else if(intree) {
421 args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir + "/prelude") ).c_str();
422 } else {
423 args[nargs] = ( *new string( string("-D__CFA_FLAG__=--prelude-dir=" ) + libdir) ).c_str();
424 }
[a5121bf]425 nargs += 1;
426
[def9d4e]427 for ( int i = 0; i < nlibs; i += 1 ) { // copy non-user libraries after all user libraries
428 args[nargs] = libs[i];
429 nargs += 1;
430 } // for
431
[b87a5ed]432 if ( link ) {
[6bfe5cc]433 args[nargs] = "-Xlinker";
434 nargs += 1;
435 args[nargs] = "--undefined=__cfaabi_dbg_bits_write";
436 nargs += 1;
437 args[nargs] = "-Xlinker";
438 nargs += 1;
439 args[nargs] = "--undefined=__cfaabi_interpose_startup";
440 nargs += 1;
[c2ea058]441 args[nargs] = "-Xlinker";
442 nargs += 1;
443 args[nargs] = "--undefined=__cfaabi_appready_startup";
444 nargs += 1;
[6bfe5cc]445
[b87a5ed]446 // include the cfa library in case it's needed
[eed6f5b]447 args[nargs] = ( *new string( string("-L" ) + libdir + (intree ? "/src/.libs" : "")) ).c_str();
[a5121bf]448 nargs += 1;
[8bdc1c36]449 args[nargs] = ( *new string( string("-Wl,-rpath," ) + libdir + (intree ? "/src/.libs" : "")) ).c_str();
450 nargs += 1;
[2026bb6]451 args[nargs] = "-Wl,--push-state,--as-needed";
452 nargs += 1;
453 args[nargs] = "-lcfathread";
454 nargs += 1;
455 args[nargs] = "-Wl,--pop-state";
456 nargs += 1;
[37fe352]457 args[nargs] = "-lcfa";
[51b73452]458 nargs += 1;
[63f78f0]459 args[nargs] = "-lpthread";
460 nargs += 1;
[9d944b2]461 args[nargs] = "-ldl";
462 nargs += 1;
[c5ac6d5]463 args[nargs] = "-lrt";
464 nargs += 1;
[def9d4e]465 args[nargs] = "-lm";
466 nargs += 1;
[51b73452]467 } // if
468
[e9145a3]469 // Add exception flags (unconditionally)
470 args[nargs] = "-fexceptions";
471 nargs += 1;
472
[b87a5ed]473 // add the correct set of flags based on the type of compile this is
[8c17ab0]474
[ec129c4]475 args[nargs] = ( *new string( string("-D__CFA_MAJOR__=") + Major ) ).c_str();
[51b73452]476 nargs += 1;
[b87a5ed]477 args[nargs] = ( *new string( string("-D__CFA_MINOR__=") + Minor ) ).c_str();
[51b73452]478 nargs += 1;
[ec129c4]479 args[nargs] = ( *new string( string("-D__CFA_PATCH__=") + Patch ) ).c_str();
[1db21619]480 nargs += 1;
[4c82a3c]481 args[nargs] = "-D__CFA__";
482 nargs += 1;
483 args[nargs] = "-D__CFORALL__";
[02e5ab6]484 nargs += 1;
[6acb935]485 args[nargs] = "-D__cforall";
486 nargs += 1;
[51b73452]487
[b87a5ed]488 if ( cpp_flag ) {
489 args[nargs] = "-D__CPP__";
490 nargs += 1;
491 } // if
[51b73452]492
[fa477f7]493 shuffle( args, sargs, nargs, 1 ); // make room at front of argument list
494 nargs += 1;
[b87a5ed]495 if ( CFA_flag ) {
[fa477f7]496 args[sargs] = "-D__CFA_FLAG__=-N";
[4c82a3c]497 args[nargs] = "-D__CFA_PREPROCESS_";
[b87a5ed]498 nargs += 1;
[fa477f7]499 } else {
500 args[sargs] = "-D__CFA_FLAG__=-L";
[b87a5ed]501 } // if
[fa477f7]502 sargs += 1;
[51b73452]503
[b87a5ed]504 if ( debug ) {
505 heading += " (debug)";
506 args[nargs] = "-D__CFA_DEBUG__";
507 nargs += 1;
508 } else {
509 heading += " (no debug)";
510 } // if
[51b73452]511
[b87a5ed]512 if ( Bprefix.length() == 0 ) {
[bbfd0e0]513 if(disttree) {
514 Bprefix = dir(argv[0]);
515 } else if(intree) {
516 Bprefix = srcdriverdir;
517 } else {
518 Bprefix = installlibdir;
519 }
520
[b740f0b]521 if ( Bprefix[Bprefix.length() - 1] != '/' ) Bprefix += '/';
[b87a5ed]522 args[nargs] = ( *new string( string("-D__GCC_BPREFIX__=") + Bprefix ) ).c_str();
523 nargs += 1;
524 } // if
[51b73452]525
[37fe352]526 args[nargs] = "-Xlinker"; // used by backtrace
527 nargs += 1;
528 args[nargs] = "-export-dynamic";
529 nargs += 1;
[6bfe5cc]530
[b87a5ed]531 // execute the compilation command
[51b73452]532
[b87a5ed]533 args[0] = compiler_path.c_str(); // set compiler command for exec
534 // find actual name of the compiler independent of the path to it
535 int p = compiler_path.find_last_of( '/' ); // scan r -> l for first '/'
536 if ( p == -1 ) {
537 compiler_name = compiler_path;
538 } else {
539 compiler_name = *new string( compiler_path.substr( p + 1 ) );
540 } // if
[51b73452]541
[b87a5ed]542 if ( prefix( compiler_name, "gcc" ) ) { // allow suffix on gcc name
543 args[nargs] = "-no-integrated-cpp";
544 nargs += 1;
[76c7f65e]545 args[nargs] = "-Wno-deprecated";
[b87a5ed]546 nargs += 1;
[1f86d5e]547#ifdef HAVE_CAST_FUNCTION_TYPE
548 args[nargs] = "-Wno-cast-function-type";
549 nargs += 1;
550#endif // HAVE_CAST_FUNCTION_TYPE
[157d094]551 if ( ! std_flag ) { // default c11, if none specified
552 args[nargs] = "-std=gnu11";
[de62360d]553 nargs += 1;
554 } // if
[76c7f65e]555 args[nargs] = "-fgnu89-inline";
[6e991d6]556 nargs += 1;
[201aeb9]557 args[nargs] = "-D__int8_t_defined"; // prevent gcc type-size attributes
558 nargs += 1;
[b740f0b]559 args[nargs] = ( *new string( string("-B") + Bprefix ) ).c_str();
[b87a5ed]560 nargs += 1;
561 } else {
[e24f13a]562 cerr << argv[0] << " error, compiler \"" << compiler_name << "\" unsupported." << endl;
[b87a5ed]563 exit( EXIT_FAILURE );
564 } // if
[51b73452]565
[b87a5ed]566 args[nargs] = NULL; // terminate with NULL
[51b73452]567
[dffaeac]568 #ifdef __DEBUG_H__
[b87a5ed]569 cerr << "nargs: " << nargs << endl;
570 cerr << "args:" << endl;
571 for ( int i = 0; args[i] != NULL; i += 1 ) {
[1ee048fd]572 cerr << " \"" << args[i] << "\" ";
[b87a5ed]573 } // for
[1ee048fd]574 cerr << endl;
[dffaeac]575 #endif // __DEBUG_H__
[51b73452]576
[b87a5ed]577 if ( ! quiet ) {
578 cerr << "CFA " << "Version " << Version << heading << endl;
579 if ( help ) {
580 cerr <<
581 "-debug\t\t\t: use cfa runtime with debug checking" << endl <<
582 "-help\t\t\t: print this help message" << endl <<
583 "-quiet\t\t\t: print no messages from the cfa command" << endl <<
584 "-CFA\t\t\t: run the cpp preprocessor and the cfa-cpp translator" << endl <<
585 "-XCFA -cfa-cpp-flag\t: pass next flag as-is to the cfa-cpp translator" << endl <<
586 "...\t\t\t: any other " << compiler_name << " flags" << endl;
587 } // if
[51b73452]588 } // if
589
[b87a5ed]590 if ( verbose ) {
591 if ( argc == 2 ) exit( EXIT_SUCCESS ); // if only the -v flag is specified, do not invoke gcc
[51b73452]592
[b87a5ed]593 for ( int i = 0; args[i] != NULL; i += 1 ) {
594 cerr << args[i] << " ";
595 } // for
596 cerr << endl;
597 } // if
[51b73452]598
[b87a5ed]599 if ( ! nonoptarg ) {
600 cerr << argv[0] << " error, no input files" << endl;
601 exit( EXIT_FAILURE );
602 } // if
[51b73452]603
[b87a5ed]604 // execute the command and return the result
[51b73452]605
[b87a5ed]606 execvp( args[0], (char *const *)args ); // should not return
607 perror( "CFA Translator error: cfa level, execvp" );
608 exit( EXIT_FAILURE );
[51b73452]609} // main
610
611// Local Variables: //
[b87a5ed]612// tab-width: 4 //
613// mode: c++ //
[51b73452]614// compile-command: "make install" //
615// End: //
Note: See TracBrowser for help on using the repository browser.