source: src/main.cc@ 1fcc2f3

ADT arm-eh ast-experimental enum forall-pointer-decay jacob/cs343-translation new-ast new-ast-unique-expr pthread-emulation qualifiedEnum
Last change on this file since 1fcc2f3 was 3f3bfe5a, checked in by Andrew Beach <ajbeach@…>, 6 years ago

Merge from master to new-ast. Removing old lvalue support.

  • Property mode set to 100644
File size: 23.2 KB
Line 
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//
7// main.cc --
8//
9// Author : Peter Buhr and Rob Schluntz
10// Created On : Fri May 15 23:12:02 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Fri Aug 23 06:50:08 2019
13// Update Count : 607
14//
15
16#include <cxxabi.h> // for __cxa_demangle
17#include <execinfo.h> // for backtrace, backtrace_symbols
18#include <getopt.h> // for no_argument, optind, geto...
19#include <cassert> // for assertf
20#include <cstdio> // for fopen, FILE, fclose, stdin
21#include <cstdlib> // for exit, free, abort, EXIT_F...
22#include <csignal> // for signal, SIGABRT, SIGSEGV
23#include <cstring> // for index
24#include <fstream> // for ofstream
25#include <iostream> // for operator<<, basic_ostream
26#include <iomanip>
27#include <iterator> // for back_inserter
28#include <list> // for list
29#include <string> // for char_traits, operator<<
30
31#include "AST/Convert.hpp"
32#include "CompilationState.h"
33#include "../config.h" // for CFA_LIBDIR
34#include "CodeGen/FixMain.h" // for FixMain
35#include "CodeGen/FixNames.h" // for fixNames
36#include "CodeGen/Generate.h" // for generate
37#include "CodeTools/DeclStats.h" // for printDeclStats
38#include "CodeTools/ResolvProtoDump.h" // for dumpAsResolvProto
39#include "CodeTools/TrackLoc.h" // for fillLocations
40#include "Common/CompilerError.h" // for CompilerError
41#include "Common/Stats.h"
42#include "Common/PassVisitor.h"
43#include "Common/SemanticError.h" // for SemanticError
44#include "Common/UnimplementedError.h" // for UnimplementedError
45#include "Common/utility.h" // for deleteAll, filter, printAll
46#include "Concurrency/Waitfor.h" // for generateWaitfor
47#include "ControlStruct/ExceptTranslate.h" // for translateEHM
48#include "ControlStruct/Mutate.h" // for mutate
49#include "GenPoly/Box.h" // for box
50#include "GenPoly/InstantiateGeneric.h" // for instantiateGeneric
51#include "GenPoly/Lvalue.h" // for convertLvalue
52#include "GenPoly/Specialize.h" // for convertSpecializations
53#include "InitTweak/FixInit.h" // for fix
54#include "InitTweak/GenInit.h" // for genInit
55#include "MakeLibCfa.h" // for makeLibCfa
56#include "Parser/LinkageSpec.h" // for Spec, Cforall, Intrinsic
57#include "Parser/ParseNode.h" // for DeclarationNode, buildList
58#include "Parser/TypedefTable.h" // for TypedefTable
59#include "ResolvExpr/AlternativePrinter.h" // for AlternativePrinter
60#include "ResolvExpr/Resolver.h" // for resolve
61#include "SymTab/Validate.h" // for validate
62#include "SynTree/Declaration.h" // for Declaration
63#include "SynTree/Visitor.h" // for acceptAll
64#include "Tuples/Tuples.h" // for expandMemberTuples, expan...
65#include "Virtual/ExpandCasts.h" // for expandCasts
66
67
68using namespace std;
69
70static void NewPass( const char * const name ) {
71 Stats::Heap::newPass( name );
72 using namespace Stats::Counters;
73 {
74 static auto group = build<CounterGroup>( "Pass Visitor" );
75 auto pass = build<CounterGroup>( name, group );
76 pass_visitor_stats.depth = 0;
77 pass_visitor_stats.avg = build<AverageCounter<double>>( "Average Depth", pass );
78 pass_visitor_stats.max = build<MaxCounter<double>>( "Max Depth", pass );
79 }
80 {
81 static auto group = build<CounterGroup>( "Syntax Node" );
82 auto pass = build<CounterGroup>( name, group );
83 BaseSyntaxNode::new_nodes = build<SimpleCounter>( "Allocs", pass );
84 }
85}
86
87#define PASS( name, pass ) \
88 if ( errorp ) { cerr << name << endl; } \
89 NewPass(name); \
90 Stats::Time::StartBlock(name); \
91 pass; \
92 Stats::Time::StopBlock();
93
94LinkageSpec::Spec linkage = LinkageSpec::Cforall;
95TypedefTable typedefTable;
96DeclarationNode * parseTree = nullptr; // program parse tree
97
98static bool waiting_for_gdb = false; // flag to set cfa-cpp to wait for gdb on start
99
100static std::string PreludeDirector = "";
101
102static void parse_cmdline( int argc, char *argv[] );
103static void parse( FILE * input, LinkageSpec::Spec linkage, bool shouldExit = false );
104static void dump( list< Declaration * > & translationUnit, ostream & out = cout );
105
106static void backtrace( int start ) { // skip first N stack frames
107 enum { Frames = 50 };
108 void * array[Frames];
109 int size = ::backtrace( array, Frames );
110 char ** messages = ::backtrace_symbols( array, size ); // does not demangle names
111
112 *index( messages[0], '(' ) = '\0'; // find executable name
113 cerr << "Stack back trace for: " << messages[0] << endl;
114
115 // skip last 2 stack frames after main
116 for ( int i = start; i < size - 2 && messages != nullptr; i += 1 ) {
117 char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr;
118 for ( char *p = messages[i]; *p; ++p ) { // find parantheses and +offset
119 if ( *p == '(' ) {
120 mangled_name = p;
121 } else if ( *p == '+' ) {
122 offset_begin = p;
123 } else if ( *p == ')' ) {
124 offset_end = p;
125 break;
126 } // if
127 } // for
128
129 // if line contains symbol, attempt to demangle
130 int frameNo = i - start;
131 if ( mangled_name && offset_begin && offset_end && mangled_name < offset_begin ) {
132 *mangled_name++ = '\0'; // delimit strings
133 *offset_begin++ = '\0';
134 *offset_end++ = '\0';
135
136 int status;
137 char * real_name = __cxxabiv1::__cxa_demangle( mangled_name, 0, 0, &status );
138 // bug in __cxa_demangle for single-character lower-case non-mangled names
139 if ( status == 0 ) { // demangling successful ?
140 cerr << "(" << frameNo << ") " << messages[i] << " : "
141 << real_name << "+" << offset_begin << offset_end << endl;
142 } else { // otherwise, output mangled name
143 cerr << "(" << frameNo << ") " << messages[i] << " : "
144 << mangled_name << "(/*unknown*/)+" << offset_begin << offset_end << endl;
145 } // if
146
147 free( real_name );
148 } else { // otherwise, print the whole line
149 cerr << "(" << frameNo << ") " << messages[i] << endl;
150 } // if
151 } // for
152
153 free( messages );
154} // backtrace
155
156static void sigSegvBusHandler( int sig_num ) {
157 cerr << "*CFA runtime error* program cfa-cpp terminated with "
158 << (sig_num == SIGSEGV ? "segment fault" : "bus error")
159 << "." << endl;
160 backtrace( 2 ); // skip first 2 stack frames
161 //_exit( EXIT_FAILURE );
162 abort(); // cause core dump for debugging
163} // sigSegvBusHandler
164
165static void sigAbortHandler( __attribute__((unused)) int sig_num ) {
166 backtrace( 6 ); // skip first 6 stack frames
167 signal( SIGABRT, SIG_DFL); // reset default signal handler
168 raise( SIGABRT ); // reraise SIGABRT
169} // sigAbortHandler
170
171int main( int argc, char * argv[] ) {
172 FILE * input; // use FILE rather than istream because yyin is FILE
173 ostream * output = & cout;
174 list< Declaration * > translationUnit;
175
176 signal( SIGSEGV, sigSegvBusHandler );
177 signal( SIGBUS, sigSegvBusHandler );
178 signal( SIGABRT, sigAbortHandler );
179
180 // std::cout << "main" << std::endl;
181 // for ( int i = 0; i < argc; i += 1 ) {
182 // std::cout << '\t' << argv[i] << std::endl;
183 // } // for
184
185 parse_cmdline( argc, argv ); // process command-line arguments
186 CodeGen::FixMain::setReplaceMain( !nomainp );
187
188 if ( waiting_for_gdb ) {
189 std::cerr << "Waiting for gdb" << std::endl;
190 std::cerr << "run :" << std::endl;
191 std::cerr << " gdb attach " << getpid() << std::endl;
192 raise(SIGSTOP);
193 } // if
194
195 try {
196 // choose to read the program from a file or stdin
197 if ( optind < argc ) { // any commands after the flags ? => input file name
198 input = fopen( argv[ optind ], "r" );
199 assertf( input, "cannot open %s because %s\n", argv[ optind ], strerror( errno ) );
200 optind += 1;
201 } else { // no input file name
202 input = stdin;
203 } // if
204
205 Stats::Time::StartGlobal();
206 NewPass("Parse");
207 Stats::Time::StartBlock("Parse");
208
209 // read in the builtins, extras, and the prelude
210 if ( ! nopreludep ) { // include gcc builtins
211 // -l is for initial build ONLY and builtins.cf is not in the lib directory so access it here.
212
213 assertf( !PreludeDirector.empty(), "Can't find prelude without option --prelude-dir must be used." );
214
215 // Read to gcc builtins, if not generating the cfa library
216 FILE * gcc_builtins = fopen( (PreludeDirector + "/gcc-builtins.cf").c_str(), "r" );
217 assertf( gcc_builtins, "cannot open gcc-builtins.cf\n" );
218 parse( gcc_builtins, LinkageSpec::Compiler );
219
220 // read the extra prelude in, if not generating the cfa library
221 FILE * extras = fopen( (PreludeDirector + "/extras.cf").c_str(), "r" );
222 assertf( extras, "cannot open extras.cf\n" );
223 parse( extras, LinkageSpec::BuiltinC );
224
225 if ( ! libcfap ) {
226 // read the prelude in, if not generating the cfa library
227 FILE * prelude = fopen( (PreludeDirector + "/prelude.cfa").c_str(), "r" );
228 assertf( prelude, "cannot open prelude.cfa\n" );
229 parse( prelude, LinkageSpec::Intrinsic );
230
231 // Read to cfa builtins, if not generating the cfa library
232 FILE * builtins = fopen( (PreludeDirector + "/builtins.cf").c_str(), "r" );
233 assertf( builtins, "cannot open builtins.cf\n" );
234 parse( builtins, LinkageSpec::BuiltinCFA );
235 } // if
236 } // if
237
238 parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, yydebug );
239
240 if ( parsep ) {
241 parseTree->printList( cout );
242 delete parseTree;
243 return EXIT_SUCCESS;
244 } // if
245
246 buildList( parseTree, translationUnit );
247 delete parseTree;
248 parseTree = nullptr;
249
250 if ( astp ) {
251 dump( translationUnit );
252 return EXIT_SUCCESS;
253 } // if
254
255 // Temporary: fill locations after parsing so that every node has a location, for early error messages.
256 // Eventually we should pass the locations from the parser to every node, but this quick and dirty solution
257 // works okay for now.
258 CodeTools::fillLocations( translationUnit );
259 Stats::Time::StopBlock();
260
261 // add the assignment statement after the initialization of a type parameter
262 PASS( "Validate", SymTab::validate( translationUnit, symtabp ) );
263 if ( symtabp ) {
264 deleteAll( translationUnit );
265 return EXIT_SUCCESS;
266 } // if
267
268 if ( expraltp ) {
269 PassVisitor<ResolvExpr::AlternativePrinter> printer( cout );
270 acceptAll( translationUnit, printer );
271 return EXIT_SUCCESS;
272 } // if
273
274 if ( validp ) {
275 dump( translationUnit );
276 return EXIT_SUCCESS;
277 } // if
278
279 PASS( "Fix Labels", ControlStruct::fixLabels( translationUnit ) );
280 PASS( "Fix Names", CodeGen::fixNames( translationUnit ) );
281 PASS( "Gen Init", InitTweak::genInit( translationUnit ) );
282 PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( translationUnit ) );
283 if ( libcfap ) {
284 // generate the bodies of cfa library functions
285 LibCfa::makeLibCfa( translationUnit );
286 } // if
287
288 if ( declstatsp ) {
289 CodeTools::printDeclStats( translationUnit );
290 deleteAll( translationUnit );
291 return EXIT_SUCCESS;
292 } // if
293
294 if ( bresolvep ) {
295 dump( translationUnit );
296 return EXIT_SUCCESS;
297 } // if
298
299 CodeTools::fillLocations( translationUnit );
300
301 if ( resolvprotop ) {
302 CodeTools::dumpAsResolvProto( translationUnit );
303 return EXIT_SUCCESS;
304 } // if
305
306 // PASS( "Resolve", ResolvExpr::resolve( translationUnit ) );
307 {
308 auto transUnit = convert( move( translationUnit ) );
309 PASS( "Resolve", ResolvExpr::resolve( transUnit ) );
310 translationUnit = convert( move( transUnit ) );
311 }
312
313 if ( exprp ) {
314 dump( translationUnit );
315 return EXIT_SUCCESS;
316 } // if
317
318 // fix ObjectDecl - replaces ConstructorInit nodes
319 PASS( "Fix Init", InitTweak::fix( translationUnit, buildingLibrary() ) );
320 if ( ctorinitp ) {
321 dump ( translationUnit );
322 return EXIT_SUCCESS;
323 } // if
324
325 PASS( "Expand Unique Expr", Tuples::expandUniqueExpr( translationUnit ) ); // xxx - is this the right place for this? want to expand ASAP so tha, sequent passes don't need to worry about double-visiting a unique expr - needs to go after InitTweak::fix so that copy constructed return declarations are reused
326
327 PASS( "Translate EHM" , ControlStruct::translateEHM( translationUnit ) );
328
329 PASS( "Gen Waitfor" , Concurrency::generateWaitFor( translationUnit ) );
330
331 PASS( "Convert Specializations", GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded
332
333 PASS( "Expand Tuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this?
334
335 if ( tuplep ) {
336 dump( translationUnit );
337 return EXIT_SUCCESS;
338 } // if
339
340 PASS( "Virtual Expand Casts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM
341
342 PASS( "Instantiate Generics", GenPoly::instantiateGeneric( translationUnit ) );
343 if ( genericsp ) {
344 dump( translationUnit );
345 return EXIT_SUCCESS;
346 } // if
347
348 PASS( "Convert L-Value", GenPoly::convertLvalue( translationUnit ) );
349
350 if ( bboxp ) {
351 dump( translationUnit );
352 return EXIT_SUCCESS;
353 } // if
354 PASS( "Box", GenPoly::box( translationUnit ) );
355
356 if ( bcodegenp ) {
357 dump( translationUnit );
358 return EXIT_SUCCESS;
359 } // if
360
361 if ( optind < argc ) { // any commands after the flags and input file ? => output file name
362 output = new ofstream( argv[ optind ] );
363 } // if
364
365 CodeTools::fillLocations( translationUnit );
366 PASS( "Code Gen", CodeGen::generate( translationUnit, *output, ! genproto, prettycodegenp, true, linemarks ) );
367
368 CodeGen::FixMain::fix( *output, (PreludeDirector + "/bootloader.c").c_str() );
369 if ( output != &cout ) {
370 delete output;
371 } // if
372 } catch ( SemanticErrorException &e ) {
373 if ( errorp ) {
374 cerr << "---AST at error:---" << endl;
375 dump( translationUnit, cerr );
376 cerr << endl << "---End of AST, begin error message:---\n" << endl;
377 } // if
378 e.print();
379 if ( output != &cout ) {
380 delete output;
381 } // if
382 return EXIT_FAILURE;
383 } catch ( UnimplementedError &e ) {
384 cout << "Sorry, " << e.get_what() << " is not currently implemented" << endl;
385 if ( output != &cout ) {
386 delete output;
387 } // if
388 return EXIT_FAILURE;
389 } catch ( CompilerError &e ) {
390 cerr << "Compiler Error: " << e.get_what() << endl;
391 cerr << "(please report bugs to [REDACTED])" << endl;
392 if ( output != &cout ) {
393 delete output;
394 } // if
395 return EXIT_FAILURE;
396 } catch ( ... ) {
397 std::exception_ptr eptr = std::current_exception();
398 try {
399 if (eptr) {
400 std::rethrow_exception(eptr);
401 } else {
402 std::cerr << "Exception Uncaught and Unknown" << std::endl;
403 } // if
404 } catch(const std::exception& e) {
405 std::cerr << "Uncaught Exception \"" << e.what() << "\"\n";
406 } // try
407 return EXIT_FAILURE;
408 } // try
409
410 deleteAll( translationUnit );
411 Stats::print();
412 return EXIT_SUCCESS;
413} // main
414
415
416static const char optstring[] = ":hlLmNnpP:S:twW:D:";
417
418enum { PreludeDir = 128 };
419static struct option long_opts[] = {
420 { "help", no_argument, nullptr, 'h' },
421 { "libcfa", no_argument, nullptr, 'l' },
422 { "linemarks", no_argument, nullptr, 'L' },
423 { "no-main", no_argument, 0, 'm' },
424 { "no-linemarks", no_argument, nullptr, 'N' },
425 { "no-prelude", no_argument, nullptr, 'n' },
426 { "prototypes", no_argument, nullptr, 'p' },
427 { "print", required_argument, nullptr, 'P' },
428 { "prelude-dir", required_argument, nullptr, PreludeDir },
429 { "statistics", required_argument, nullptr, 'S' },
430 { "tree", no_argument, nullptr, 't' },
431 { "gdb", no_argument, nullptr, 'g' },
432 { "", no_argument, nullptr, 0 }, // -w
433 { "", no_argument, nullptr, 0 }, // -W
434 { "", no_argument, nullptr, 0 }, // -D
435 { nullptr, 0, nullptr, 0 }
436}; // long_opts
437
438static const char * description[] = {
439 "print help message", // -h
440 "generate libcfa.c", // -l
441 "generate line marks", // -L
442 "do not replace main", // -m
443 "do not generate line marks", // -N
444 "do not read prelude", // -n
445 "generate prototypes for prelude functions", // -p
446 "print", // -P
447 "<directory> prelude directory for debug/nodebug", // no flag
448 "<option-list> enable profiling information:\n counters,heap,time,all,none", // -S
449 "building cfa standard lib", // -t
450 "wait for gdb to attach", // -g
451 "", // -w
452 "", // -W
453 "", // -D
454}; // description
455
456static_assert( sizeof( long_opts ) / sizeof( long_opts[0] ) - 1 == sizeof( description ) / sizeof( description[0] ), "Long opts and description must match" );
457
458static struct Printopts {
459 const char * name;
460 int & flag;
461 int val;
462 const char * descript;
463} printopts[] = {
464 { "ascodegen", codegenp, true, "print AST as codegen rather than AST" },
465 { "asterr", errorp, true, "print AST on error" },
466 { "declstats", declstatsp, true, "code property statistics" },
467 { "parse", yydebug, true, "yacc (parsing) debug information" },
468 { "pretty", prettycodegenp, true, "prettyprint for ascodegen flag" },
469 { "rproto", resolvprotop, true, "resolver-proto instance" },
470 { "rsteps", resolvep, true, "print resolver steps" },
471 { "tree", parsep, true, "print parse tree" },
472 // code dumps
473 { "ast", astp, true, "print AST after parsing" },
474 { "symevt", symtabp, true, "print AST after symbol table events" },
475 { "altexpr", expraltp, true, "print alternatives for expressions" },
476 { "astdecl", validp, true, "print AST after declaration validation pass" },
477 { "resolver", bresolvep, true, "print AST before resolver step" },
478 { "astexpr", exprp, true, "print AST after expression analysis" },
479 { "ctordtor", ctorinitp, true, "print AST after ctor/dtor are replaced" },
480 { "tuple", tuplep, true, "print AST after tuple expansion" },
481 { "astgen", genericsp, true, "print AST after instantiate generics" },
482 { "box", bboxp, true, "print AST before box step" },
483 { "codegen", bcodegenp, true, "print AST before code generation" },
484};
485enum { printoptsSize = sizeof( printopts ) / sizeof( printopts[0] ) };
486
487static void usage( char *argv[] ) {
488 cout << "Usage: " << argv[0] << " [options] [input-file (default stdin)] [output-file (default stdout)], where options are:" << endl;
489 int i = 0, j = 1; // j skips starting colon
490 for ( ; long_opts[i].name != 0 && optstring[j] != '\0'; i += 1, j += 1 ) {
491 if ( long_opts[i].name[0] != '\0' ) { // hidden option, internal usage only
492 if ( strcmp( long_opts[i].name, "prelude-dir" ) != 0 ) { // flag
493 cout << " -" << optstring[j] << ",";
494 } else { // no flag
495 j -= 1; // compensate
496 cout << " ";
497 } // if
498 cout << " --" << left << setw(12) << long_opts[i].name << " ";
499 if ( strcmp( long_opts[i].name, "print" ) == 0 ) {
500 cout << "one of: " << endl;
501 for ( int i = 0; i < printoptsSize; i += 1 ) {
502 cout << setw(10) << " " << left << setw(10) << printopts[i].name << " " << printopts[i].descript << endl;
503 } // for
504 } else {
505 cout << description[i] << endl;
506 } // if
507 } // if
508 if ( optstring[j + 1] == ':' ) j += 1;
509 } // for
510 if ( long_opts[i].name != 0 || optstring[j] != '\0' ) assertf( false, "internal error, mismatch of option flags and names\n" );
511 exit( EXIT_FAILURE );
512} // usage
513
514static void parse_cmdline( int argc, char * argv[] ) {
515 opterr = 0; // (global) prevent getopt from printing error messages
516
517 bool Wsuppress = false, Werror = false;
518 int c;
519 while ( (c = getopt_long( argc, argv, optstring, long_opts, nullptr )) != -1 ) {
520 switch ( c ) {
521 case 'h': // help message
522 usage( argv ); // no return
523 break;
524 case 'l': // generate libcfa.c
525 libcfap = true;
526 break;
527 case 'L': // generate line marks
528 linemarks = true;
529 break;
530 case 'm': // do not replace main
531 nomainp = true;
532 break;
533 case 'N': // do not generate line marks
534 linemarks = false;
535 break;
536 case 'n': // do not read prelude
537 nopreludep = true;
538 break;
539 case 'p': // generate prototypes for prelude functions
540 genproto = true;
541 break;
542 case 'P': // print options
543 for ( int i = 0;; i += 1 ) {
544 if ( i == printoptsSize ) {
545 cout << "Unknown --print option " << optarg << endl;
546 goto Default;
547 } // if
548 if ( strcmp( optarg, printopts[i].name ) == 0 ) {
549 printopts[i].flag = printopts[i].val;
550 break;
551 } // if
552 } // for
553 break;
554 case PreludeDir: // prelude directory for debug/nodebug, hidden
555 PreludeDirector = optarg;
556 break;
557 case 'S': // enable profiling information, argument comma separated list of names
558 Stats::parse_params( optarg );
559 break;
560 case 't': // building cfa stdlib
561 treep = true;
562 break;
563 case 'g': // wait for gdb
564 waiting_for_gdb = true;
565 break;
566 case 'w': // suppress all warnings, hidden
567 Wsuppress = true;
568 break;
569 case 'W': // coordinate gcc -W with CFA, hidden
570 if ( strcmp( optarg, "all" ) == 0 ) {
571 SemanticWarning_EnableAll();
572 } else if ( strcmp( optarg, "error" ) == 0 ) {
573 Werror = true;
574 } else {
575 char * warning = optarg;
576 Severity s;
577 if ( strncmp( optarg, "no-", 3 ) == 0 ) {
578 warning += 3;
579 s = Severity::Suppress;
580 } else {
581 s = Severity::Warn;
582 } // if
583 SemanticWarning_Set( warning, s );
584 } // if
585 break;
586 case 'D': // ignore -Dxxx, forwarded by cpp, hidden
587 break;
588 case '?': // unknown option
589 if ( optopt ) { // short option ?
590 cout << "Unknown option -" << (char)optopt << endl;
591 } else {
592 cout << "Unknown option " << argv[optind - 1] << endl;
593 } // if
594 goto Default;
595 case ':': // missing option
596 if ( optopt ) { // short option ?
597 cout << "Missing option for -" << (char)optopt << endl;
598 } else {
599 cout << "Missing option for " << argv[optind - 1] << endl;
600 } // if
601 goto Default;
602 Default:
603 default:
604 usage( argv ); // no return
605 } // switch
606 } // while
607
608 if ( Werror ) {
609 SemanticWarning_WarningAsError();
610 } // if
611 if ( Wsuppress ) {
612 SemanticWarning_SuppressAll();
613 } // if
614 // for ( const auto w : WarningFormats ) {
615 // cout << w.name << ' ' << (int)w.severity << endl;
616 // } // for
617} // parse_cmdline
618
619static void parse( FILE * input, LinkageSpec::Spec linkage, bool shouldExit ) {
620 extern int yyparse( void );
621 extern FILE * yyin;
622 extern int yylineno;
623
624 ::linkage = linkage; // set globals
625 yyin = input;
626 yylineno = 1;
627 int parseStatus = yyparse();
628
629 fclose( input );
630 if ( shouldExit || parseStatus != 0 ) {
631 exit( parseStatus );
632 } // if
633} // parse
634
635static bool notPrelude( Declaration * decl ) {
636 return ! LinkageSpec::isBuiltin( decl->get_linkage() );
637} // notPrelude
638
639static void dump( list< Declaration * > & translationUnit, ostream & out ) {
640 list< Declaration * > decls;
641
642 if ( genproto ) {
643 filter( translationUnit.begin(), translationUnit.end(), back_inserter( decls ), notPrelude );
644 } else {
645 decls = translationUnit;
646 } // if
647
648 // depending on commandline options, either generate code or dump the AST
649 if ( codegenp ) {
650 CodeGen::generate( decls, out, ! genproto, prettycodegenp );
651 } else {
652 printAll( decls, out );
653 } // if
654 deleteAll( translationUnit );
655} // dump
656
657// Local Variables: //
658// tab-width: 4 //
659// mode: c++ //
660// compile-command: "make install" //
661// End: //
Note: See TracBrowser for help on using the repository browser.