[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 | // |
---|
[71f4e4f] | 7 | // main.cc -- |
---|
[b87a5ed] | 8 | // |
---|
[3e96559] | 9 | // Author : Peter Buhr and Rob Schluntz |
---|
[b87a5ed] | 10 | // Created On : Fri May 15 23:12:02 2015 |
---|
[372b6d3] | 11 | // Last Modified By : Peter A. Buhr |
---|
[12f671e] | 12 | // Last Modified On : Thu Sep 28 22:28:45 2023 |
---|
| 13 | // Update Count : 687 |
---|
[b87a5ed] | 14 | // |
---|
| 15 | |
---|
[bf2438c] | 16 | #include <cxxabi.h> // for __cxa_demangle |
---|
| 17 | #include <execinfo.h> // for backtrace, backtrace_symbols |
---|
| 18 | #include <getopt.h> // for no_argument, optind, geto... |
---|
[08fc48f] | 19 | #include <cassert> // for assertf |
---|
[bf2438c] | 20 | #include <cstdio> // for fopen, FILE, fclose, stdin |
---|
| 21 | #include <cstdlib> // for exit, free, abort, EXIT_F... |
---|
[bffcd66] | 22 | #include <csignal> // for signal, SIGABRT, SIGSEGV |
---|
[bf2438c] | 23 | #include <cstring> // for index |
---|
[be9288a] | 24 | #include <fstream> // for ofstream |
---|
[bf2438c] | 25 | #include <iostream> // for operator<<, basic_ostream |
---|
[62ce290] | 26 | #include <iomanip> |
---|
[bf2438c] | 27 | #include <iterator> // for back_inserter |
---|
| 28 | #include <list> // for list |
---|
[08fc48f] | 29 | #include <string> // for char_traits, operator<< |
---|
[e6955b1] | 30 | |
---|
[9ea38de] | 31 | #include "AST/Convert.hpp" |
---|
[bccd70a] | 32 | #include "AST/Pass.hpp" // for pass_visitor_stats |
---|
| 33 | #include "AST/TranslationUnit.hpp" // for TranslationUnit |
---|
[52f9804] | 34 | #include "AST/Util.hpp" // for checkInvariants |
---|
[7f38b67a] | 35 | #include "CompilationState.h" |
---|
[bf2438c] | 36 | #include "../config.h" // for CFA_LIBDIR |
---|
| 37 | #include "CodeGen/FixMain.h" // for FixMain |
---|
| 38 | #include "CodeGen/FixNames.h" // for fixNames |
---|
| 39 | #include "CodeGen/Generate.h" // for generate |
---|
[aff7e86] | 40 | #include "CodeGen/LinkOnce.h" // for translateLinkOnce |
---|
[bf2438c] | 41 | #include "CodeTools/TrackLoc.h" // for fillLocations |
---|
[f57faf6f] | 42 | #include "Common/CodeLocationTools.hpp" // for forceFillCodeLocations |
---|
[55cbff8] | 43 | #include "Common/DeclStats.hpp" // for printDeclStats |
---|
| 44 | #include "Common/ResolvProtoDump.hpp" // for dumpAsResolverProto |
---|
[09366b8] | 45 | #include "Common/Stats.h" // for Stats |
---|
[bf2438c] | 46 | #include "Common/utility.h" // for deleteAll, filter, printAll |
---|
[3dd8f42] | 47 | #include "Concurrency/Actors.hpp" // for implementActors |
---|
[2cf3b87] | 48 | #include "Concurrency/Keywords.h" // for implementMutex, implement... |
---|
[9f5ecf5] | 49 | #include "Concurrency/Waitfor.h" // for generateWaitfor |
---|
[c86b08d] | 50 | #include "Concurrency/Waituntil.hpp" // for generateWaitUntil |
---|
[0c730d9] | 51 | #include "ControlStruct/ExceptDecl.h" // for translateExcept |
---|
[09366b8] | 52 | #include "ControlStruct/ExceptTranslate.h" // for translateThrows, translat... |
---|
[b8ab91a] | 53 | #include "ControlStruct/FixLabels.hpp" // for fixLabels |
---|
[a488783] | 54 | #include "ControlStruct/HoistControlDecls.hpp" // hoistControlDecls |
---|
[bf2438c] | 55 | #include "GenPoly/Box.h" // for box |
---|
| 56 | #include "GenPoly/InstantiateGeneric.h" // for instantiateGeneric |
---|
| 57 | #include "GenPoly/Lvalue.h" // for convertLvalue |
---|
| 58 | #include "GenPoly/Specialize.h" // for convertSpecializations |
---|
| 59 | #include "InitTweak/FixInit.h" // for fix |
---|
| 60 | #include "InitTweak/GenInit.h" // for genInit |
---|
| 61 | #include "MakeLibCfa.h" // for makeLibCfa |
---|
[cbd1ba8] | 62 | #include "Parser/RunParser.hpp" // for buildList, dumpParseTree,... |
---|
[1622af5] | 63 | #include "ResolvExpr/CandidatePrinter.hpp" // for printCandidates |
---|
[bf2438c] | 64 | #include "ResolvExpr/Resolver.h" // for resolve |
---|
[bffcd66] | 65 | #include "SynTree/LinkageSpec.h" // for Spec, Cforall, Intrinsic |
---|
[bf2438c] | 66 | #include "SynTree/Declaration.h" // for Declaration |
---|
| 67 | #include "Tuples/Tuples.h" // for expandMemberTuples, expan... |
---|
[a488783] | 68 | #include "Validate/Autogen.hpp" // for autogenerateRoutines |
---|
[298fe57] | 69 | #include "Validate/CompoundLiteral.hpp" // for handleCompoundLiterals |
---|
| 70 | #include "Validate/EliminateTypedef.hpp" // for eliminateTypedef |
---|
[1931bb01] | 71 | #include "Validate/EnumAndPointerDecay.hpp" // for decayEnumsAndPointers |
---|
[ce36b55] | 72 | #include "Validate/FindSpecialDecls.h" // for findGlobalDecls |
---|
[298fe57] | 73 | #include "Validate/FixQualifiedTypes.hpp" // for fixQualifiedTypes |
---|
[1931bb01] | 74 | #include "Validate/FixReturnTypes.hpp" // for fixReturnTypes |
---|
[9490621] | 75 | #include "Validate/ForallPointerDecay.hpp" // for decayForallPointers |
---|
[298fe57] | 76 | #include "Validate/GenericParameter.hpp" // for fillGenericParameters, tr... |
---|
| 77 | #include "Validate/HoistStruct.hpp" // for hoistStruct |
---|
[1931bb01] | 78 | #include "Validate/HoistTypeDecls.hpp" // for hoistTypeDecls |
---|
[ce36b55] | 79 | #include "Validate/InitializerLength.hpp" // for setLengthFromInitializer |
---|
| 80 | #include "Validate/LabelAddressFixer.hpp" // for fixLabelAddresses |
---|
[72e76fd] | 81 | #include "Validate/LinkReferenceToTypes.hpp" // for linkReferenceToTypes |
---|
[1931bb01] | 82 | #include "Validate/ReplaceTypedef.hpp" // for replaceTypedef |
---|
[4ec9513] | 83 | #include "Validate/ReturnCheck.hpp" // for checkReturnStatements |
---|
[1931bb01] | 84 | #include "Validate/VerifyCtorDtorAssign.hpp" // for verifyCtorDtorAssign |
---|
[a5f0529] | 85 | #include "Virtual/ExpandCasts.h" // for expandCasts |
---|
[3830c84] | 86 | #include "Virtual/VirtualDtor.hpp" // for implementVirtDtors |
---|
[51b7345] | 87 | |
---|
[2c38b15] | 88 | using namespace std; |
---|
| 89 | |
---|
[3e96559] | 90 | static void NewPass( const char * const name ) { |
---|
| 91 | Stats::Heap::newPass( name ); |
---|
[1cb7fab2] | 92 | using namespace Stats::Counters; |
---|
[b8665e3] | 93 | { |
---|
[3e96559] | 94 | static auto group = build<CounterGroup>( "Pass Visitor" ); |
---|
| 95 | auto pass = build<CounterGroup>( name, group ); |
---|
[b8665e3] | 96 | pass_visitor_stats.depth = 0; |
---|
[3e96559] | 97 | pass_visitor_stats.avg = build<AverageCounter<double>>( "Average Depth", pass ); |
---|
| 98 | pass_visitor_stats.max = build<MaxCounter<double>>( "Max Depth", pass ); |
---|
[b8665e3] | 99 | } |
---|
| 100 | { |
---|
[3e96559] | 101 | static auto group = build<CounterGroup>( "Syntax Node" ); |
---|
| 102 | auto pass = build<CounterGroup>( name, group ); |
---|
| 103 | BaseSyntaxNode::new_nodes = build<SimpleCounter>( "Allocs", pass ); |
---|
[b8665e3] | 104 | } |
---|
[675716e] | 105 | } |
---|
| 106 | |
---|
[52f9804] | 107 | // Helpers for checkInvariant: |
---|
| 108 | void checkInvariants( std::list< Declaration * > & ) {} |
---|
| 109 | using ast::checkInvariants; |
---|
| 110 | |
---|
| 111 | #define PASS( name, pass, unit, ... ) \ |
---|
[ecaeac6e] | 112 | if ( errorp ) { cerr << name << endl; } \ |
---|
[675716e] | 113 | NewPass(name); \ |
---|
[4f97937] | 114 | Stats::Time::StartBlock(name); \ |
---|
[52f9804] | 115 | pass(unit,##__VA_ARGS__); \ |
---|
| 116 | Stats::Time::StopBlock(); \ |
---|
| 117 | if ( invariant ) { \ |
---|
| 118 | checkInvariants(unit); \ |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | #define DUMP( cond, unit ) \ |
---|
| 122 | if ( cond ) { \ |
---|
| 123 | dump(unit); \ |
---|
| 124 | return EXIT_SUCCESS; \ |
---|
| 125 | } |
---|
[0da3e2c] | 126 | |
---|
[ef22ad6] | 127 | static bool waiting_for_gdb = false; // flag to set cfa-cpp to wait for gdb on start |
---|
[dee1f89] | 128 | |
---|
[bffcd66] | 129 | static string PreludeDirector = ""; |
---|
[4dcaed2] | 130 | |
---|
[77d601f] | 131 | static void parse_cmdline( int argc, char * argv[] ); |
---|
[e6955b1] | 132 | static void dump( list< Declaration * > & translationUnit, ostream & out = cout ); |
---|
[e499381] | 133 | static void dump( ast::TranslationUnit && transUnit, ostream & out = cout ); |
---|
[e6955b1] | 134 | |
---|
[0afffee] | 135 | static void backtrace( int start ) { // skip first N stack frames |
---|
[74330e7] | 136 | enum { Frames = 50, }; // maximum number of stack frames |
---|
[e6955b1] | 137 | void * array[Frames]; |
---|
[74330e7] | 138 | size_t size = ::backtrace( array, Frames ); |
---|
[0afffee] | 139 | char ** messages = ::backtrace_symbols( array, size ); // does not demangle names |
---|
| 140 | |
---|
| 141 | *index( messages[0], '(' ) = '\0'; // find executable name |
---|
| 142 | cerr << "Stack back trace for: " << messages[0] << endl; |
---|
[e6955b1] | 143 | |
---|
[b542bfb] | 144 | // skip last 2 stack frames after main |
---|
[74330e7] | 145 | for ( unsigned int i = start; i < size - 2 && messages != nullptr; i += 1 ) { |
---|
[e6955b1] | 146 | char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr; |
---|
[7006ba5] | 147 | |
---|
| 148 | for ( char * p = messages[i]; *p; p += 1 ) { // find parantheses and +offset |
---|
[0afffee] | 149 | if ( *p == '(' ) { |
---|
[46f6134] | 150 | mangled_name = p; |
---|
[0afffee] | 151 | } else if ( *p == '+' ) { |
---|
[e6955b1] | 152 | offset_begin = p; |
---|
[0afffee] | 153 | } else if ( *p == ')' ) { |
---|
[e6955b1] | 154 | offset_end = p; |
---|
| 155 | break; |
---|
| 156 | } // if |
---|
| 157 | } // for |
---|
| 158 | |
---|
| 159 | // if line contains symbol, attempt to demangle |
---|
[b542bfb] | 160 | int frameNo = i - start; |
---|
[e6955b1] | 161 | if ( mangled_name && offset_begin && offset_end && mangled_name < offset_begin ) { |
---|
[0afffee] | 162 | *mangled_name++ = '\0'; // delimit strings |
---|
[e6955b1] | 163 | *offset_begin++ = '\0'; |
---|
| 164 | *offset_end++ = '\0'; |
---|
| 165 | |
---|
[0afffee] | 166 | int status; |
---|
[e6955b1] | 167 | char * real_name = __cxxabiv1::__cxa_demangle( mangled_name, 0, 0, &status ); |
---|
[0afffee] | 168 | // bug in __cxa_demangle for single-character lower-case non-mangled names |
---|
[e6955b1] | 169 | if ( status == 0 ) { // demangling successful ? |
---|
[b542bfb] | 170 | cerr << "(" << frameNo << ") " << messages[i] << " : " |
---|
[e6955b1] | 171 | << real_name << "+" << offset_begin << offset_end << endl; |
---|
| 172 | } else { // otherwise, output mangled name |
---|
[b542bfb] | 173 | cerr << "(" << frameNo << ") " << messages[i] << " : " |
---|
[0afffee] | 174 | << mangled_name << "(/*unknown*/)+" << offset_begin << offset_end << endl; |
---|
[e6955b1] | 175 | } // if |
---|
[0afffee] | 176 | |
---|
[e6955b1] | 177 | free( real_name ); |
---|
| 178 | } else { // otherwise, print the whole line |
---|
[b542bfb] | 179 | cerr << "(" << frameNo << ") " << messages[i] << endl; |
---|
[e6955b1] | 180 | } // if |
---|
| 181 | } // for |
---|
[b542bfb] | 182 | |
---|
[e6955b1] | 183 | free( messages ); |
---|
[b542bfb] | 184 | } // backtrace |
---|
| 185 | |
---|
[bffcd66] | 186 | #define SIGPARMS int sig __attribute__(( unused )), siginfo_t * sfp __attribute__(( unused )), ucontext_t * cxt __attribute__(( unused )) |
---|
| 187 | |
---|
[1f68d5d] | 188 | static void _Signal(struct sigaction & act, int sig, int flags ) { |
---|
[bffcd66] | 189 | act.sa_flags = flags; |
---|
| 190 | |
---|
| 191 | if ( sigaction( sig, &act, nullptr ) == -1 ) { |
---|
[77d601f] | 192 | cerr << "*cfa-cpp compilation error* problem installing signal handler, error(" << errno << ") " << strerror( errno ) << endl; |
---|
[bffcd66] | 193 | _exit( EXIT_FAILURE ); |
---|
| 194 | } // if |
---|
[1f68d5d] | 195 | } |
---|
| 196 | |
---|
| 197 | static void Signal( int sig, void (* handler)(SIGPARMS), int flags ) { |
---|
| 198 | struct sigaction act; |
---|
| 199 | act.sa_sigaction = (void (*)(int, siginfo_t *, void *))handler; |
---|
| 200 | _Signal(act, sig, flags); |
---|
| 201 | } // Signal |
---|
| 202 | |
---|
| 203 | static void Signal( int sig, void (* handler)(int), int flags ) { |
---|
| 204 | struct sigaction act; |
---|
| 205 | act.sa_handler = handler; |
---|
| 206 | _Signal(act, sig, flags); |
---|
[bffcd66] | 207 | } // Signal |
---|
| 208 | |
---|
| 209 | static void sigSegvBusHandler( SIGPARMS ) { |
---|
| 210 | if ( sfp->si_addr == nullptr ) { |
---|
| 211 | cerr << "Null pointer (nullptr) dereference." << endl; |
---|
| 212 | } else { |
---|
| 213 | cerr << (sig == SIGSEGV ? "Segment fault" : "Bus error") << " at memory location " << sfp->si_addr << "." << endl |
---|
| 214 | << "Possible cause is reading outside the address space or writing to a protected area within the address space with an invalid pointer or subscript." << endl; |
---|
| 215 | } // if |
---|
[b542bfb] | 216 | backtrace( 2 ); // skip first 2 stack frames |
---|
[3e96559] | 217 | abort(); // cause core dump for debugging |
---|
[e6955b1] | 218 | } // sigSegvBusHandler |
---|
[0da3e2c] | 219 | |
---|
[74330e7] | 220 | static void sigFpeHandler( SIGPARMS ) { |
---|
| 221 | const char * msg; |
---|
| 222 | |
---|
| 223 | switch ( sfp->si_code ) { |
---|
| 224 | case FPE_INTDIV: case FPE_FLTDIV: msg = "divide by zero"; break; |
---|
| 225 | case FPE_FLTOVF: msg = "overflow"; break; |
---|
| 226 | case FPE_FLTUND: msg = "underflow"; break; |
---|
| 227 | case FPE_FLTRES: msg = "inexact result"; break; |
---|
| 228 | case FPE_FLTINV: msg = "invalid operation"; break; |
---|
| 229 | default: msg = "unknown"; |
---|
| 230 | } // choose |
---|
| 231 | cerr << "Computation error " << msg << " at location " << sfp->si_addr << endl |
---|
| 232 | << "Possible cause is constant-expression evaluation invalid." << endl; |
---|
| 233 | backtrace( 2 ); // skip first 2 stack frames |
---|
| 234 | abort(); // cause core dump for debugging |
---|
| 235 | } // sigFpeHandler |
---|
| 236 | |
---|
[bffcd66] | 237 | static void sigAbortHandler( SIGPARMS ) { |
---|
[b542bfb] | 238 | backtrace( 6 ); // skip first 6 stack frames |
---|
[1f68d5d] | 239 | Signal( SIGABRT, SIG_DFL, SA_SIGINFO ); // reset default signal handler |
---|
[9be45a2] | 240 | raise( SIGABRT ); // reraise SIGABRT |
---|
[b542bfb] | 241 | } // sigAbortHandler |
---|
| 242 | |
---|
[cbaee0d] | 243 | int main( int argc, char * argv[] ) { |
---|
[3b8e52c] | 244 | FILE * input; // use FILE rather than istream because yyin is FILE |
---|
[d08beee] | 245 | ostream * output = & cout; |
---|
[e6955b1] | 246 | list< Declaration * > translationUnit; |
---|
[64b3cda] | 247 | ast::TranslationUnit transUnit; |
---|
[e6955b1] | 248 | |
---|
[bffcd66] | 249 | Signal( SIGSEGV, sigSegvBusHandler, SA_SIGINFO ); |
---|
| 250 | Signal( SIGBUS, sigSegvBusHandler, SA_SIGINFO ); |
---|
[74330e7] | 251 | Signal( SIGFPE, sigFpeHandler, SA_SIGINFO ); |
---|
[bffcd66] | 252 | Signal( SIGABRT, sigAbortHandler, SA_SIGINFO ); |
---|
[b87a5ed] | 253 | |
---|
[bffcd66] | 254 | // cout << "main" << endl; |
---|
[44bca7f] | 255 | // for ( int i = 0; i < argc; i += 1 ) { |
---|
[bffcd66] | 256 | // cout << '\t' << argv[i] << endl; |
---|
[44bca7f] | 257 | // } // for |
---|
| 258 | |
---|
[e0bd0f9] | 259 | parse_cmdline( argc, argv ); // process command-line arguments |
---|
[13de47bc] | 260 | CodeGen::FixMain::setReplaceMain( !nomainp ); |
---|
[b87a5ed] | 261 | |
---|
[ef22ad6] | 262 | if ( waiting_for_gdb ) { |
---|
[bffcd66] | 263 | cerr << "Waiting for gdb" << endl; |
---|
| 264 | cerr << "run :" << endl; |
---|
| 265 | cerr << " gdb attach " << getpid() << endl; |
---|
[dee1f89] | 266 | raise(SIGSTOP); |
---|
[ef22ad6] | 267 | } // if |
---|
[dee1f89] | 268 | |
---|
[b87a5ed] | 269 | try { |
---|
[81419b5] | 270 | // choose to read the program from a file or stdin |
---|
[3b8e52c] | 271 | if ( optind < argc ) { // any commands after the flags ? => input file name |
---|
[b87a5ed] | 272 | input = fopen( argv[ optind ], "r" ); |
---|
[e0bd0f9] | 273 | assertf( input, "cannot open %s because %s\n", argv[ optind ], strerror( errno ) ); |
---|
[b87a5ed] | 274 | optind += 1; |
---|
[3b8e52c] | 275 | } else { // no input file name |
---|
[b87a5ed] | 276 | input = stdin; |
---|
| 277 | } // if |
---|
| 278 | |
---|
[79eaeb7] | 279 | Stats::Time::StartGlobal(); |
---|
[3c0d4cd] | 280 | NewPass("Parse"); |
---|
| 281 | Stats::Time::StartBlock("Parse"); |
---|
[675716e] | 282 | |
---|
[159c62e] | 283 | // read in the builtins, extras, and the prelude |
---|
[de62360d] | 284 | if ( ! nopreludep ) { // include gcc builtins |
---|
[faf8857] | 285 | // -l is for initial build ONLY and builtins.cf is not in the lib directory so access it here. |
---|
[807ce84] | 286 | |
---|
[37fe352] | 287 | assertf( !PreludeDirector.empty(), "Can't find prelude without option --prelude-dir must be used." ); |
---|
[4dcaed2] | 288 | |
---|
[807ce84] | 289 | // Read to gcc builtins, if not generating the cfa library |
---|
[37fe352] | 290 | FILE * gcc_builtins = fopen( (PreludeDirector + "/gcc-builtins.cf").c_str(), "r" ); |
---|
[6ce3ae9] | 291 | assertf( gcc_builtins, "cannot open gcc-builtins.cf\n" ); |
---|
[f2f595d7] | 292 | parse( gcc_builtins, ast::Linkage::Compiler ); |
---|
[81419b5] | 293 | |
---|
[159c62e] | 294 | // read the extra prelude in, if not generating the cfa library |
---|
[37fe352] | 295 | FILE * extras = fopen( (PreludeDirector + "/extras.cf").c_str(), "r" ); |
---|
[3b8e52c] | 296 | assertf( extras, "cannot open extras.cf\n" ); |
---|
[f2f595d7] | 297 | parse( extras, ast::Linkage::BuiltinC ); |
---|
[159c62e] | 298 | |
---|
[81419b5] | 299 | if ( ! libcfap ) { |
---|
[faf8857] | 300 | // read the prelude in, if not generating the cfa library |
---|
[e523b07] | 301 | FILE * prelude = fopen( (PreludeDirector + "/prelude.cfa").c_str(), "r" ); |
---|
| 302 | assertf( prelude, "cannot open prelude.cfa\n" ); |
---|
[f2f595d7] | 303 | parse( prelude, ast::Linkage::Intrinsic ); |
---|
[fa4805f] | 304 | |
---|
| 305 | // Read to cfa builtins, if not generating the cfa library |
---|
[37fe352] | 306 | FILE * builtins = fopen( (PreludeDirector + "/builtins.cf").c_str(), "r" ); |
---|
[fa4805f] | 307 | assertf( builtins, "cannot open builtins.cf\n" ); |
---|
[f2f595d7] | 308 | parse( builtins, ast::Linkage::BuiltinCFA ); |
---|
[b87a5ed] | 309 | } // if |
---|
| 310 | } // if |
---|
[81419b5] | 311 | |
---|
[f2f595d7] | 312 | parse( input, libcfap ? ast::Linkage::Intrinsic : ast::Linkage::Cforall, yydebug ); |
---|
[71f4e4f] | 313 | |
---|
[64b3cda] | 314 | transUnit = buildUnit(); |
---|
[b87a5ed] | 315 | |
---|
[52f9804] | 316 | DUMP( astp, std::move( transUnit ) ); |
---|
[b87a5ed] | 317 | |
---|
[3c0d4cd] | 318 | Stats::Time::StopBlock(); |
---|
[036dd5f] | 319 | |
---|
[09366b8] | 320 | if (Stats::Counters::enabled) { |
---|
| 321 | ast::pass_visitor_stats.avg = Stats::Counters::build<Stats::Counters::AverageCounter<double>>("Average Depth - New"); |
---|
| 322 | ast::pass_visitor_stats.max = Stats::Counters::build<Stats::Counters::MaxCounter<double>>("Max depth - New"); |
---|
| 323 | } |
---|
[b507dcd] | 324 | |
---|
[52f9804] | 325 | PASS( "Hoist Type Decls", Validate::hoistTypeDecls, transUnit ); |
---|
| 326 | |
---|
| 327 | PASS( "Translate Exception Declarations", ControlStruct::translateExcept, transUnit ); |
---|
| 328 | DUMP( exdeclp, std::move( transUnit ) ); |
---|
| 329 | PASS( "Verify Ctor, Dtor & Assign", Validate::verifyCtorDtorAssign, transUnit ); |
---|
| 330 | PASS( "Replace Typedefs", Validate::replaceTypedef, transUnit ); |
---|
| 331 | PASS( "Fix Return Types", Validate::fixReturnTypes, transUnit ); |
---|
| 332 | PASS( "Enum and Pointer Decay", Validate::decayEnumsAndPointers, transUnit ); |
---|
| 333 | |
---|
| 334 | PASS( "Link Reference To Types", Validate::linkReferenceToTypes, transUnit ); |
---|
| 335 | |
---|
[14c0f7b] | 336 | PASS( "Forall Pointer Decay", Validate::decayForallPointers, transUnit ); |
---|
[52f9804] | 337 | PASS( "Fix Qualified Types", Validate::fixQualifiedTypes, transUnit ); |
---|
| 338 | PASS( "Eliminate Typedef", Validate::eliminateTypedef, transUnit ); |
---|
[2c38b15] | 339 | PASS( "Hoist Struct", Validate::hoistStruct, transUnit ); |
---|
[52f9804] | 340 | PASS( "Validate Generic Parameters", Validate::fillGenericParameters, transUnit ); |
---|
| 341 | PASS( "Translate Dimensions", Validate::translateDimensionParameters, transUnit ); |
---|
| 342 | PASS( "Check Function Returns", Validate::checkReturnStatements, transUnit ); |
---|
| 343 | PASS( "Fix Return Statements", InitTweak::fixReturnStatements, transUnit ); |
---|
| 344 | PASS( "Implement Concurrent Keywords", Concurrency::implementKeywords, transUnit ); |
---|
[14c0f7b] | 345 | PASS( "Fix Unique Ids", Validate::fixUniqueIds, transUnit ); |
---|
[52f9804] | 346 | PASS( "Hoist Control Declarations", ControlStruct::hoistControlDecls, transUnit ); |
---|
| 347 | |
---|
| 348 | PASS( "Generate Autogen Routines", Validate::autogenerateRoutines, transUnit ); |
---|
| 349 | |
---|
| 350 | PASS( "Implement Actors", Concurrency::implementActors, transUnit ); |
---|
| 351 | PASS( "Implement Virtual Destructors", Virtual::implementVirtDtors, transUnit ); |
---|
| 352 | PASS( "Implement Mutex", Concurrency::implementMutex, transUnit ); |
---|
| 353 | PASS( "Implement Thread Start", Concurrency::implementThreadStarter, transUnit ); |
---|
| 354 | PASS( "Compound Literal", Validate::handleCompoundLiterals, transUnit ); |
---|
| 355 | PASS( "Set Length From Initializer", Validate::setLengthFromInitializer, transUnit ); |
---|
| 356 | PASS( "Find Global Decls", Validate::findGlobalDecls, transUnit ); |
---|
| 357 | PASS( "Fix Label Address", Validate::fixLabelAddresses, transUnit ); |
---|
[09366b8] | 358 | |
---|
| 359 | if ( symtabp ) { |
---|
| 360 | return EXIT_SUCCESS; |
---|
| 361 | } // if |
---|
[ccbc65c] | 362 | |
---|
[09366b8] | 363 | if ( expraltp ) { |
---|
| 364 | ResolvExpr::printCandidates( transUnit ); |
---|
| 365 | return EXIT_SUCCESS; |
---|
| 366 | } // if |
---|
[3606fe4] | 367 | |
---|
[52f9804] | 368 | DUMP( validp, std::move( transUnit ) ); |
---|
[6a896b0] | 369 | |
---|
[52f9804] | 370 | PASS( "Translate Throws", ControlStruct::translateThrows, transUnit ); |
---|
| 371 | PASS( "Fix Labels", ControlStruct::fixLabels, transUnit ); |
---|
[14c0f7b] | 372 | PASS( "Implement Waituntil", Concurrency::generateWaitUntil, transUnit ); |
---|
[52f9804] | 373 | PASS( "Fix Names", CodeGen::fixNames, transUnit ); |
---|
| 374 | PASS( "Gen Init", InitTweak::genInit, transUnit ); |
---|
| 375 | PASS( "Expand Member Tuples" , Tuples::expandMemberTuples, transUnit ); |
---|
[ce36b55] | 376 | |
---|
[09366b8] | 377 | if ( libcfap ) { |
---|
| 378 | // Generate the bodies of cfa library functions. |
---|
| 379 | LibCfa::makeLibCfa( transUnit ); |
---|
| 380 | } // if |
---|
[1622af5] | 381 | |
---|
[09366b8] | 382 | if ( declstatsp ) { |
---|
| 383 | printDeclStats( transUnit ); |
---|
| 384 | return EXIT_SUCCESS; |
---|
| 385 | } // if |
---|
[1622af5] | 386 | |
---|
[52f9804] | 387 | DUMP( bresolvep, std::move( transUnit ) ); |
---|
[1622af5] | 388 | |
---|
[09366b8] | 389 | if ( resolvprotop ) { |
---|
| 390 | dumpAsResolverProto( transUnit ); |
---|
| 391 | return EXIT_SUCCESS; |
---|
| 392 | } // if |
---|
[9f5a19fa] | 393 | |
---|
[52f9804] | 394 | PASS( "Resolve", ResolvExpr::resolve, transUnit ); |
---|
| 395 | DUMP( exprp, std::move( transUnit ) ); |
---|
[68fe946e] | 396 | |
---|
[52f9804] | 397 | PASS( "Fix Init", InitTweak::fix, transUnit, buildingLibrary() ); |
---|
[68fe946e] | 398 | |
---|
[09366b8] | 399 | // fix ObjectDecl - replaces ConstructorInit nodes |
---|
[52f9804] | 400 | DUMP( ctorinitp, std::move( transUnit ) ); |
---|
[68fe946e] | 401 | |
---|
[09366b8] | 402 | // Currently not working due to unresolved issues with UniqueExpr |
---|
[52f9804] | 403 | PASS( "Expand Unique Expr", Tuples::expandUniqueExpr, transUnit ); // 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 |
---|
[68fe946e] | 404 | |
---|
[52f9804] | 405 | PASS( "Translate Tries", ControlStruct::translateTries, transUnit ); |
---|
| 406 | PASS( "Gen Waitfor", Concurrency::generateWaitFor, transUnit ); |
---|
[4615ac8] | 407 | |
---|
[09366b8] | 408 | // Needs to happen before tuple types are expanded. |
---|
[52f9804] | 409 | PASS( "Convert Specializations", GenPoly::convertSpecializations, transUnit ); |
---|
[81419b5] | 410 | |
---|
[52f9804] | 411 | PASS( "Expand Tuples", Tuples::expandTuples, transUnit ); |
---|
| 412 | DUMP( tuplep, std::move( transUnit ) ); |
---|
[626dbc10] | 413 | |
---|
[09366b8] | 414 | // Must come after Translate Tries. |
---|
[52f9804] | 415 | PASS( "Virtual Expand Casts", Virtual::expandCasts, transUnit ); |
---|
[141b786] | 416 | |
---|
[52f9804] | 417 | PASS( "Instantiate Generics", GenPoly::instantiateGeneric, transUnit ); |
---|
| 418 | DUMP( genericsp, std::move( transUnit ) ); |
---|
[b4f8808] | 419 | |
---|
[52f9804] | 420 | PASS( "Convert L-Value", GenPoly::convertLvalue, transUnit ); |
---|
[7fffb1b] | 421 | |
---|
| 422 | translationUnit = convert( std::move( transUnit ) ); |
---|
[53d3ab4b] | 423 | |
---|
[52f9804] | 424 | DUMP( bboxp, translationUnit ); |
---|
| 425 | PASS( "Box", GenPoly::box, translationUnit ); |
---|
[81419b5] | 426 | |
---|
[52f9804] | 427 | PASS( "Link-Once", CodeGen::translateLinkOnce, translationUnit ); |
---|
[aff7e86] | 428 | |
---|
| 429 | // Code has been lowered to C, now we can start generation. |
---|
| 430 | |
---|
[52f9804] | 431 | DUMP( bcodegenp, translationUnit ); |
---|
[8905f56] | 432 | |
---|
[13de47bc] | 433 | if ( optind < argc ) { // any commands after the flags and input file ? => output file name |
---|
| 434 | output = new ofstream( argv[ optind ] ); |
---|
| 435 | } // if |
---|
[0270824] | 436 | |
---|
[7b15d7a] | 437 | CodeTools::fillLocations( translationUnit ); |
---|
[52f9804] | 438 | PASS( "Code Gen", CodeGen::generate, translationUnit, *output, ! genproto, prettycodegenp, true, linemarks ); |
---|
[0270824] | 439 | |
---|
[8e48fca4] | 440 | CodeGen::FixMain::fix( translationUnit, *output, |
---|
| 441 | (PreludeDirector + "/bootloader.c").c_str() ); |
---|
[e6955b1] | 442 | if ( output != &cout ) { |
---|
[b87a5ed] | 443 | delete output; |
---|
| 444 | } // if |
---|
[77d601f] | 445 | } catch ( SemanticErrorException & e ) { |
---|
[b87a5ed] | 446 | if ( errorp ) { |
---|
[e6955b1] | 447 | cerr << "---AST at error:---" << endl; |
---|
[64b3cda] | 448 | // We check which section the errors came from without looking at |
---|
| 449 | // transUnit because std::move means it could look like anything. |
---|
| 450 | if ( !translationUnit.empty() ) { |
---|
| 451 | dump( translationUnit, cerr ); |
---|
| 452 | } else { |
---|
| 453 | dump( std::move( transUnit ), cerr ); |
---|
| 454 | } |
---|
[e6955b1] | 455 | cerr << endl << "---End of AST, begin error message:---\n" << endl; |
---|
[926af74] | 456 | } // if |
---|
[d55d7a6] | 457 | e.print(); |
---|
[e6955b1] | 458 | if ( output != &cout ) { |
---|
[b87a5ed] | 459 | delete output; |
---|
| 460 | } // if |
---|
[3e96559] | 461 | return EXIT_FAILURE; |
---|
[77d601f] | 462 | } catch ( std::bad_alloc & ) { |
---|
| 463 | cerr << "*cfa-cpp compilation error* std::bad_alloc" << endl; |
---|
| 464 | backtrace( 1 ); |
---|
| 465 | abort(); |
---|
[3e96559] | 466 | } catch ( ... ) { |
---|
[bffcd66] | 467 | exception_ptr eptr = current_exception(); |
---|
[4990812] | 468 | try { |
---|
| 469 | if (eptr) { |
---|
[bffcd66] | 470 | rethrow_exception(eptr); |
---|
[3e96559] | 471 | } else { |
---|
[77d601f] | 472 | cerr << "*cfa-cpp compilation error* exception uncaught and unknown" << endl; |
---|
[3e96559] | 473 | } // if |
---|
[77d601f] | 474 | } catch( const exception & e ) { |
---|
| 475 | cerr << "*cfa-cpp compilation error* uncaught exception \"" << e.what() << "\"\n"; |
---|
[3e96559] | 476 | } // try |
---|
| 477 | return EXIT_FAILURE; |
---|
| 478 | } // try |
---|
[b87a5ed] | 479 | |
---|
[39786813] | 480 | deleteAll( translationUnit ); |
---|
[1cb7fab2] | 481 | Stats::print(); |
---|
[3e96559] | 482 | return EXIT_SUCCESS; |
---|
[d9a0e76] | 483 | } // main |
---|
[51b7345] | 484 | |
---|
[0da3e2c] | 485 | |
---|
[372b6d3] | 486 | static const char optstring[] = ":c:ghilLmNnpdP:S:twW:D:"; |
---|
[3e96559] | 487 | |
---|
[62ce290] | 488 | enum { PreludeDir = 128 }; |
---|
[3e96559] | 489 | static struct option long_opts[] = { |
---|
[1a69a90] | 490 | { "colors", required_argument, nullptr, 'c' }, |
---|
| 491 | { "gdb", no_argument, nullptr, 'g' }, |
---|
[3e96559] | 492 | { "help", no_argument, nullptr, 'h' }, |
---|
[372b6d3] | 493 | { "invariant", no_argument, nullptr, 'i' }, |
---|
[3e96559] | 494 | { "libcfa", no_argument, nullptr, 'l' }, |
---|
[62ce290] | 495 | { "linemarks", no_argument, nullptr, 'L' }, |
---|
[372b6d3] | 496 | { "no-main", no_argument, nullptr, 'm' }, |
---|
[62ce290] | 497 | { "no-linemarks", no_argument, nullptr, 'N' }, |
---|
| 498 | { "no-prelude", no_argument, nullptr, 'n' }, |
---|
[3e96559] | 499 | { "prototypes", no_argument, nullptr, 'p' }, |
---|
[7215000] | 500 | { "deterministic-out", no_argument, nullptr, 'd' }, |
---|
[62ce290] | 501 | { "print", required_argument, nullptr, 'P' }, |
---|
| 502 | { "prelude-dir", required_argument, nullptr, PreludeDir }, |
---|
| 503 | { "statistics", required_argument, nullptr, 'S' }, |
---|
[3e96559] | 504 | { "tree", no_argument, nullptr, 't' }, |
---|
| 505 | { "", no_argument, nullptr, 0 }, // -w |
---|
| 506 | { "", no_argument, nullptr, 0 }, // -W |
---|
| 507 | { "", no_argument, nullptr, 0 }, // -D |
---|
| 508 | { nullptr, 0, nullptr, 0 } |
---|
| 509 | }; // long_opts |
---|
| 510 | |
---|
| 511 | static const char * description[] = { |
---|
[aa88cb9a] | 512 | "diagnostic color: never, always, auto", // -c |
---|
[3e9de01] | 513 | "wait for gdb to attach", // -g |
---|
[aa88cb9a] | 514 | "print translator help message", // -h |
---|
[372b6d3] | 515 | "invariant checking during AST passes", // -i |
---|
[3e9de01] | 516 | "generate libcfa.c", // -l |
---|
| 517 | "generate line marks", // -L |
---|
| 518 | "do not replace main", // -m |
---|
| 519 | "do not generate line marks", // -N |
---|
| 520 | "do not read prelude", // -n |
---|
[aa88cb9a] | 521 | "do not generate prelude prototypes => prelude not printed", // -p |
---|
[3e9de01] | 522 | "only print deterministic output", // -d |
---|
| 523 | "print", // -P |
---|
[62ce290] | 524 | "<directory> prelude directory for debug/nodebug", // no flag |
---|
[aa88cb9a] | 525 | "<option-list> enable profiling information: counters, heap, time, all, none", // -S |
---|
[3e9de01] | 526 | "building cfa standard lib", // -t |
---|
| 527 | "", // -w |
---|
| 528 | "", // -W |
---|
| 529 | "", // -D |
---|
[3e96559] | 530 | }; // description |
---|
| 531 | |
---|
[0c0f548] | 532 | static_assert( sizeof( long_opts ) / sizeof( long_opts[0] ) - 1 == sizeof( description ) / sizeof( description[0] ), "Long opts and description must match" ); |
---|
[62ce290] | 533 | |
---|
| 534 | static struct Printopts { |
---|
| 535 | const char * name; |
---|
| 536 | int & flag; |
---|
| 537 | int val; |
---|
| 538 | const char * descript; |
---|
| 539 | } printopts[] = { |
---|
[0e464f6] | 540 | { "ascodegen", codegenp, true, "print AST as codegen rather than AST" }, |
---|
| 541 | { "asterr", errorp, true, "print AST on error" }, |
---|
[12f671e] | 542 | { "declstats", declstatsp, true, "print code property statistics" }, |
---|
| 543 | { "parse", yydebug, true, "print yacc (parsing) debug information" }, |
---|
[62ce290] | 544 | { "pretty", prettycodegenp, true, "prettyprint for ascodegen flag" }, |
---|
| 545 | { "rproto", resolvprotop, true, "resolver-proto instance" }, |
---|
[0e464f6] | 546 | { "rsteps", resolvep, true, "print resolver steps" }, |
---|
[5f917740] | 547 | // AST dumps |
---|
[0e464f6] | 548 | { "ast", astp, true, "print AST after parsing" }, |
---|
[5f917740] | 549 | { "excpdecl", exdeclp, true, "print AST after translating exception decls" }, |
---|
[0e464f6] | 550 | { "symevt", symtabp, true, "print AST after symbol table events" }, |
---|
[5f917740] | 551 | { "expralt", expraltp, true, "print AST after expressions alternatives" }, |
---|
| 552 | { "valdecl", validp, true, "print AST after declaration validation pass" }, |
---|
| 553 | { "bresolver", bresolvep, true, "print AST before resolver step" }, |
---|
| 554 | { "expranly", exprp, true, "print AST after expression analysis" }, |
---|
[0e464f6] | 555 | { "ctordtor", ctorinitp, true, "print AST after ctor/dtor are replaced" }, |
---|
| 556 | { "tuple", tuplep, true, "print AST after tuple expansion" }, |
---|
[5f917740] | 557 | { "instgen", genericsp, true, "print AST after instantiate generics" }, |
---|
| 558 | { "bbox", bboxp, true, "print AST before box pass" }, |
---|
| 559 | { "bcodegen", bcodegenp, true, "print AST before code generation" }, |
---|
[62ce290] | 560 | }; |
---|
| 561 | enum { printoptsSize = sizeof( printopts ) / sizeof( printopts[0] ) }; |
---|
| 562 | |
---|
[77d601f] | 563 | static void usage( char * argv[] ) { |
---|
[e0bd0f9] | 564 | cout << "Usage: " << argv[0] << " [options] [input-file (default stdin)] [output-file (default stdout)], where options are:" << endl; |
---|
[3e96559] | 565 | int i = 0, j = 1; // j skips starting colon |
---|
| 566 | for ( ; long_opts[i].name != 0 && optstring[j] != '\0'; i += 1, j += 1 ) { |
---|
| 567 | if ( long_opts[i].name[0] != '\0' ) { // hidden option, internal usage only |
---|
[62ce290] | 568 | if ( strcmp( long_opts[i].name, "prelude-dir" ) != 0 ) { // flag |
---|
| 569 | cout << " -" << optstring[j] << ","; |
---|
| 570 | } else { // no flag |
---|
| 571 | j -= 1; // compensate |
---|
| 572 | cout << " "; |
---|
| 573 | } // if |
---|
| 574 | cout << " --" << left << setw(12) << long_opts[i].name << " "; |
---|
| 575 | if ( strcmp( long_opts[i].name, "print" ) == 0 ) { |
---|
| 576 | cout << "one of: " << endl; |
---|
| 577 | for ( int i = 0; i < printoptsSize; i += 1 ) { |
---|
| 578 | cout << setw(10) << " " << left << setw(10) << printopts[i].name << " " << printopts[i].descript << endl; |
---|
| 579 | } // for |
---|
| 580 | } else { |
---|
| 581 | cout << description[i] << endl; |
---|
| 582 | } // if |
---|
[3e96559] | 583 | } // if |
---|
[62ce290] | 584 | if ( optstring[j + 1] == ':' ) j += 1; |
---|
[3e96559] | 585 | } // for |
---|
| 586 | if ( long_opts[i].name != 0 || optstring[j] != '\0' ) assertf( false, "internal error, mismatch of option flags and names\n" ); |
---|
| 587 | exit( EXIT_FAILURE ); |
---|
| 588 | } // usage |
---|
| 589 | |
---|
[e0bd0f9] | 590 | static void parse_cmdline( int argc, char * argv[] ) { |
---|
[0da3e2c] | 591 | opterr = 0; // (global) prevent getopt from printing error messages |
---|
| 592 | |
---|
[c5e5109] | 593 | bool Wsuppress = false, Werror = false; |
---|
[0da3e2c] | 594 | int c; |
---|
[3e96559] | 595 | while ( (c = getopt_long( argc, argv, optstring, long_opts, nullptr )) != -1 ) { |
---|
[0da3e2c] | 596 | switch ( c ) { |
---|
[1a69a90] | 597 | case 'c': // diagnostic colors |
---|
| 598 | if ( strcmp( optarg, "always" ) == 0 ) { |
---|
| 599 | ErrorHelpers::colors = ErrorHelpers::Colors::Always; |
---|
| 600 | } else if ( strcmp( optarg, "never" ) == 0 ) { |
---|
| 601 | ErrorHelpers::colors = ErrorHelpers::Colors::Never; |
---|
| 602 | } else if ( strcmp( optarg, "auto" ) == 0 ) { |
---|
| 603 | ErrorHelpers::colors = ErrorHelpers::Colors::Auto; |
---|
| 604 | } // if |
---|
| 605 | break; |
---|
[3e96559] | 606 | case 'h': // help message |
---|
| 607 | usage( argv ); // no return |
---|
[53d3ab4b] | 608 | break; |
---|
[372b6d3] | 609 | case 'i': // invariant checking |
---|
| 610 | invariant = true; |
---|
| 611 | break; |
---|
[3e96559] | 612 | case 'l': // generate libcfa.c |
---|
[0da3e2c] | 613 | libcfap = true; |
---|
| 614 | break; |
---|
[62ce290] | 615 | case 'L': // generate line marks |
---|
[6de43b6] | 616 | linemarks = true; |
---|
[c850687] | 617 | break; |
---|
[3e96559] | 618 | case 'm': // do not replace main |
---|
| 619 | nomainp = true; |
---|
[0da3e2c] | 620 | break; |
---|
[62ce290] | 621 | case 'N': // do not generate line marks |
---|
[6de43b6] | 622 | linemarks = false; |
---|
[c59bde6] | 623 | break; |
---|
[62ce290] | 624 | case 'n': // do not read prelude |
---|
[3e96559] | 625 | nopreludep = true; |
---|
[0da3e2c] | 626 | break; |
---|
[62ce290] | 627 | case 'p': // generate prototypes for prelude functions |
---|
| 628 | genproto = true; |
---|
[0da3e2c] | 629 | break; |
---|
[7215000] | 630 | case 'd': // don't print non-deterministic output |
---|
[a77257be] | 631 | deterministic_output = true; |
---|
| 632 | break; |
---|
[62ce290] | 633 | case 'P': // print options |
---|
| 634 | for ( int i = 0;; i += 1 ) { |
---|
| 635 | if ( i == printoptsSize ) { |
---|
| 636 | cout << "Unknown --print option " << optarg << endl; |
---|
| 637 | goto Default; |
---|
| 638 | } // if |
---|
| 639 | if ( strcmp( optarg, printopts[i].name ) == 0 ) { |
---|
| 640 | printopts[i].flag = printopts[i].val; |
---|
| 641 | break; |
---|
| 642 | } // if |
---|
| 643 | } // for |
---|
[0da3e2c] | 644 | break; |
---|
[62ce290] | 645 | case PreludeDir: // prelude directory for debug/nodebug, hidden |
---|
| 646 | PreludeDirector = optarg; |
---|
[3b3491b] | 647 | break; |
---|
[3e96559] | 648 | case 'S': // enable profiling information, argument comma separated list of names |
---|
| 649 | Stats::parse_params( optarg ); |
---|
[ebcc940] | 650 | break; |
---|
[dee1f89] | 651 | case 't': // building cfa stdlib |
---|
[0da3e2c] | 652 | treep = true; |
---|
| 653 | break; |
---|
[dee1f89] | 654 | case 'g': // wait for gdb |
---|
| 655 | waiting_for_gdb = true; |
---|
| 656 | break; |
---|
[3e96559] | 657 | case 'w': // suppress all warnings, hidden |
---|
[c5e5109] | 658 | Wsuppress = true; |
---|
[44bca7f] | 659 | break; |
---|
[3e96559] | 660 | case 'W': // coordinate gcc -W with CFA, hidden |
---|
[44bca7f] | 661 | if ( strcmp( optarg, "all" ) == 0 ) { |
---|
[68e9ace] | 662 | SemanticWarning_EnableAll(); |
---|
[44bca7f] | 663 | } else if ( strcmp( optarg, "error" ) == 0 ) { |
---|
| 664 | Werror = true; |
---|
| 665 | } else { |
---|
| 666 | char * warning = optarg; |
---|
| 667 | Severity s; |
---|
| 668 | if ( strncmp( optarg, "no-", 3 ) == 0 ) { |
---|
| 669 | warning += 3; |
---|
| 670 | s = Severity::Suppress; |
---|
| 671 | } else { |
---|
| 672 | s = Severity::Warn; |
---|
| 673 | } // if |
---|
[68e9ace] | 674 | SemanticWarning_Set( warning, s ); |
---|
[44bca7f] | 675 | } // if |
---|
| 676 | break; |
---|
[3e96559] | 677 | case 'D': // ignore -Dxxx, forwarded by cpp, hidden |
---|
[0da3e2c] | 678 | break; |
---|
[3e96559] | 679 | case '?': // unknown option |
---|
| 680 | if ( optopt ) { // short option ? |
---|
| 681 | cout << "Unknown option -" << (char)optopt << endl; |
---|
| 682 | } else { |
---|
| 683 | cout << "Unknown option " << argv[optind - 1] << endl; |
---|
| 684 | } // if |
---|
| 685 | goto Default; |
---|
| 686 | case ':': // missing option |
---|
[ae47a23] | 687 | if ( optopt ) { // short option ? |
---|
[3e96559] | 688 | cout << "Missing option for -" << (char)optopt << endl; |
---|
[ae47a23] | 689 | } else { |
---|
[3e96559] | 690 | cout << "Missing option for " << argv[optind - 1] << endl; |
---|
[ae47a23] | 691 | } // if |
---|
[3e96559] | 692 | goto Default; |
---|
| 693 | Default: |
---|
| 694 | default: |
---|
| 695 | usage( argv ); // no return |
---|
[0da3e2c] | 696 | } // switch |
---|
| 697 | } // while |
---|
[44bca7f] | 698 | |
---|
| 699 | if ( Werror ) { |
---|
[68e9ace] | 700 | SemanticWarning_WarningAsError(); |
---|
[44bca7f] | 701 | } // if |
---|
[c5e5109] | 702 | if ( Wsuppress ) { |
---|
| 703 | SemanticWarning_SuppressAll(); |
---|
| 704 | } // if |
---|
[44bca7f] | 705 | // for ( const auto w : WarningFormats ) { |
---|
| 706 | // cout << w.name << ' ' << (int)w.severity << endl; |
---|
| 707 | // } // for |
---|
[0da3e2c] | 708 | } // parse_cmdline |
---|
| 709 | |
---|
[1ab4ce2] | 710 | static bool notPrelude( Declaration * decl ) { |
---|
| 711 | return ! LinkageSpec::isBuiltin( decl->get_linkage() ); |
---|
[0da3e2c] | 712 | } // notPrelude |
---|
[1ab4ce2] | 713 | |
---|
[e6955b1] | 714 | static void dump( list< Declaration * > & translationUnit, ostream & out ) { |
---|
| 715 | list< Declaration * > decls; |
---|
[926af74] | 716 | |
---|
[62ce290] | 717 | if ( genproto ) { |
---|
[e6955b1] | 718 | filter( translationUnit.begin(), translationUnit.end(), back_inserter( decls ), notPrelude ); |
---|
[1ab4ce2] | 719 | } else { |
---|
| 720 | decls = translationUnit; |
---|
[926af74] | 721 | } // if |
---|
[1ab4ce2] | 722 | |
---|
[e39241b] | 723 | // depending on commandline options, either generate code or dump the AST |
---|
| 724 | if ( codegenp ) { |
---|
[62ce290] | 725 | CodeGen::generate( decls, out, ! genproto, prettycodegenp ); |
---|
[e39241b] | 726 | } else { |
---|
| 727 | printAll( decls, out ); |
---|
[3e96559] | 728 | } // if |
---|
[7f5566b] | 729 | deleteAll( translationUnit ); |
---|
[0da3e2c] | 730 | } // dump |
---|
[1ab4ce2] | 731 | |
---|
[e499381] | 732 | static void dump( ast::TranslationUnit && transUnit, ostream & out ) { |
---|
[09f34a84] | 733 | std::list< Declaration * > translationUnit = convert( std::move( transUnit ) ); |
---|
[e499381] | 734 | dump( translationUnit, out ); |
---|
| 735 | } |
---|
| 736 | |
---|
[51b7345] | 737 | // Local Variables: // |
---|
[b87a5ed] | 738 | // tab-width: 4 // |
---|
| 739 | // mode: c++ // |
---|
| 740 | // compile-command: "make install" // |
---|
[51b7345] | 741 | // End: // |
---|