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