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 : Andrew Beach |
---|
12 | // Last Modified On : Thu 11 12:18:00 2022 |
---|
13 | // Update Count : 677 |
---|
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 | using namespace std; |
---|
32 | |
---|
33 | #include "AST/Convert.hpp" |
---|
34 | #include "CompilationState.h" |
---|
35 | #include "../config.h" // for CFA_LIBDIR |
---|
36 | #include "CodeGen/FixMain.h" // for FixMain |
---|
37 | #include "CodeGen/FixNames.h" // for fixNames |
---|
38 | #include "CodeGen/Generate.h" // for generate |
---|
39 | #include "CodeGen/LinkOnce.h" // for translateLinkOnce |
---|
40 | #include "CodeTools/DeclStats.h" // for printDeclStats |
---|
41 | #include "CodeTools/ResolvProtoDump.h" // for dumpAsResolvProto |
---|
42 | #include "CodeTools/TrackLoc.h" // for fillLocations |
---|
43 | #include "Common/CodeLocationTools.hpp" // for forceFillCodeLocations |
---|
44 | #include "Common/CompilerError.h" // for CompilerError |
---|
45 | #include "Common/DeclStats.hpp" // for printDeclStats |
---|
46 | #include "Common/ResolvProtoDump.hpp" // for dumpAsResolverProto |
---|
47 | #include "Common/Stats.h" |
---|
48 | #include "Common/PassVisitor.h" |
---|
49 | #include "Common/SemanticError.h" // for SemanticError |
---|
50 | #include "Common/UnimplementedError.h" // for UnimplementedError |
---|
51 | #include "Common/utility.h" // for deleteAll, filter, printAll |
---|
52 | #include "Concurrency/Keywords.h" // for implementMutex, implement... |
---|
53 | #include "Concurrency/Waitfor.h" // for generateWaitfor |
---|
54 | #include "ControlStruct/ExceptDecl.h" // for translateExcept |
---|
55 | #include "ControlStruct/ExceptTranslate.h" // for translateEHM |
---|
56 | #include "ControlStruct/FixLabels.hpp" // for fixLabels |
---|
57 | #include "ControlStruct/HoistControlDecls.hpp" // hoistControlDecls |
---|
58 | #include "ControlStruct/Mutate.h" // for mutate |
---|
59 | #include "GenPoly/Box.h" // for box |
---|
60 | #include "GenPoly/InstantiateGeneric.h" // for instantiateGeneric |
---|
61 | #include "GenPoly/Lvalue.h" // for convertLvalue |
---|
62 | #include "GenPoly/Specialize.h" // for convertSpecializations |
---|
63 | #include "InitTweak/FixInit.h" // for fix |
---|
64 | #include "InitTweak/GenInit.h" // for genInit |
---|
65 | #include "MakeLibCfa.h" // for makeLibCfa |
---|
66 | #include "Parser/ParseNode.h" // for DeclarationNode, buildList |
---|
67 | #include "Parser/TypedefTable.h" // for TypedefTable |
---|
68 | #include "ResolvExpr/AlternativePrinter.h" // for AlternativePrinter |
---|
69 | #include "ResolvExpr/CandidatePrinter.hpp" // for printCandidates |
---|
70 | #include "ResolvExpr/Resolver.h" // for resolve |
---|
71 | #include "SymTab/Validate.h" // for validate |
---|
72 | #include "SymTab/ValidateType.h" // for linkReferenceToTypes |
---|
73 | #include "SynTree/LinkageSpec.h" // for Spec, Cforall, Intrinsic |
---|
74 | #include "SynTree/Declaration.h" // for Declaration |
---|
75 | #include "SynTree/Visitor.h" // for acceptAll |
---|
76 | #include "Tuples/Tuples.h" // for expandMemberTuples, expan... |
---|
77 | #include "Validate/Autogen.hpp" // for autogenerateRoutines |
---|
78 | #include "Validate/CompoundLiteral.hpp" // for handleCompoundLiterals |
---|
79 | #include "Validate/EliminateTypedef.hpp" // for eliminateTypedef |
---|
80 | #include "Validate/EnumAndPointerDecay.hpp" // for decayEnumsAndPointers |
---|
81 | #include "Validate/FindSpecialDecls.h" // for findGlobalDecls |
---|
82 | #include "Validate/FixQualifiedTypes.hpp" // for fixQualifiedTypes |
---|
83 | #include "Validate/FixReturnTypes.hpp" // for fixReturnTypes |
---|
84 | #include "Validate/ForallPointerDecay.hpp" // for decayForallPointers |
---|
85 | #include "Validate/GenericParameter.hpp" // for fillGenericParameters, tr... |
---|
86 | #include "Validate/HoistStruct.hpp" // for hoistStruct |
---|
87 | #include "Validate/HoistTypeDecls.hpp" // for hoistTypeDecls |
---|
88 | #include "Validate/InitializerLength.hpp" // for setLengthFromInitializer |
---|
89 | #include "Validate/LabelAddressFixer.hpp" // for fixLabelAddresses |
---|
90 | #include "Validate/LinkReferenceToTypes.hpp" // for linkReferenceToTypes |
---|
91 | #include "Validate/ReplaceTypedef.hpp" // for replaceTypedef |
---|
92 | #include "Validate/ReturnCheck.hpp" // for checkReturnStatements |
---|
93 | #include "Validate/VerifyCtorDtorAssign.hpp" // for verifyCtorDtorAssign |
---|
94 | #include "Virtual/ExpandCasts.h" // for expandCasts |
---|
95 | |
---|
96 | static void NewPass( const char * const name ) { |
---|
97 | Stats::Heap::newPass( name ); |
---|
98 | using namespace Stats::Counters; |
---|
99 | { |
---|
100 | static auto group = build<CounterGroup>( "Pass Visitor" ); |
---|
101 | auto pass = build<CounterGroup>( name, group ); |
---|
102 | pass_visitor_stats.depth = 0; |
---|
103 | pass_visitor_stats.avg = build<AverageCounter<double>>( "Average Depth", pass ); |
---|
104 | pass_visitor_stats.max = build<MaxCounter<double>>( "Max Depth", pass ); |
---|
105 | } |
---|
106 | { |
---|
107 | static auto group = build<CounterGroup>( "Syntax Node" ); |
---|
108 | auto pass = build<CounterGroup>( name, group ); |
---|
109 | BaseSyntaxNode::new_nodes = build<SimpleCounter>( "Allocs", pass ); |
---|
110 | } |
---|
111 | } |
---|
112 | |
---|
113 | #define PASS( name, pass ) \ |
---|
114 | if ( errorp ) { cerr << name << endl; } \ |
---|
115 | NewPass(name); \ |
---|
116 | Stats::Time::StartBlock(name); \ |
---|
117 | pass; \ |
---|
118 | Stats::Time::StopBlock(); |
---|
119 | |
---|
120 | LinkageSpec::Spec linkage = LinkageSpec::Cforall; |
---|
121 | TypedefTable typedefTable; |
---|
122 | DeclarationNode * parseTree = nullptr; // program parse tree |
---|
123 | |
---|
124 | static bool waiting_for_gdb = false; // flag to set cfa-cpp to wait for gdb on start |
---|
125 | |
---|
126 | static string PreludeDirector = ""; |
---|
127 | |
---|
128 | static void parse_cmdline( int argc, char * argv[] ); |
---|
129 | static void parse( FILE * input, LinkageSpec::Spec linkage, bool shouldExit = false ); |
---|
130 | static void dump( list< Declaration * > & translationUnit, ostream & out = cout ); |
---|
131 | static void dump( ast::TranslationUnit && transUnit, ostream & out = cout ); |
---|
132 | |
---|
133 | static void backtrace( int start ) { // skip first N stack frames |
---|
134 | enum { Frames = 50, }; // maximum number of stack frames |
---|
135 | void * array[Frames]; |
---|
136 | size_t size = ::backtrace( array, Frames ); |
---|
137 | char ** messages = ::backtrace_symbols( array, size ); // does not demangle names |
---|
138 | |
---|
139 | *index( messages[0], '(' ) = '\0'; // find executable name |
---|
140 | cerr << "Stack back trace for: " << messages[0] << endl; |
---|
141 | |
---|
142 | // skip last 2 stack frames after main |
---|
143 | for ( unsigned int i = start; i < size - 2 && messages != nullptr; i += 1 ) { |
---|
144 | char * mangled_name = nullptr, * offset_begin = nullptr, * offset_end = nullptr; |
---|
145 | |
---|
146 | for ( char * p = messages[i]; *p; p += 1 ) { // find parantheses and +offset |
---|
147 | if ( *p == '(' ) { |
---|
148 | mangled_name = p; |
---|
149 | } else if ( *p == '+' ) { |
---|
150 | offset_begin = p; |
---|
151 | } else if ( *p == ')' ) { |
---|
152 | offset_end = p; |
---|
153 | break; |
---|
154 | } // if |
---|
155 | } // for |
---|
156 | |
---|
157 | // if line contains symbol, attempt to demangle |
---|
158 | int frameNo = i - start; |
---|
159 | if ( mangled_name && offset_begin && offset_end && mangled_name < offset_begin ) { |
---|
160 | *mangled_name++ = '\0'; // delimit strings |
---|
161 | *offset_begin++ = '\0'; |
---|
162 | *offset_end++ = '\0'; |
---|
163 | |
---|
164 | int status; |
---|
165 | char * real_name = __cxxabiv1::__cxa_demangle( mangled_name, 0, 0, &status ); |
---|
166 | // bug in __cxa_demangle for single-character lower-case non-mangled names |
---|
167 | if ( status == 0 ) { // demangling successful ? |
---|
168 | cerr << "(" << frameNo << ") " << messages[i] << " : " |
---|
169 | << real_name << "+" << offset_begin << offset_end << endl; |
---|
170 | } else { // otherwise, output mangled name |
---|
171 | cerr << "(" << frameNo << ") " << messages[i] << " : " |
---|
172 | << mangled_name << "(/*unknown*/)+" << offset_begin << offset_end << endl; |
---|
173 | } // if |
---|
174 | |
---|
175 | free( real_name ); |
---|
176 | } else { // otherwise, print the whole line |
---|
177 | cerr << "(" << frameNo << ") " << messages[i] << endl; |
---|
178 | } // if |
---|
179 | } // for |
---|
180 | |
---|
181 | free( messages ); |
---|
182 | } // backtrace |
---|
183 | |
---|
184 | #define SIGPARMS int sig __attribute__(( unused )), siginfo_t * sfp __attribute__(( unused )), ucontext_t * cxt __attribute__(( unused )) |
---|
185 | |
---|
186 | static void _Signal(struct sigaction & act, int sig, int flags ) { |
---|
187 | act.sa_flags = flags; |
---|
188 | |
---|
189 | if ( sigaction( sig, &act, nullptr ) == -1 ) { |
---|
190 | cerr << "*cfa-cpp compilation error* problem installing signal handler, error(" << errno << ") " << strerror( errno ) << endl; |
---|
191 | _exit( EXIT_FAILURE ); |
---|
192 | } // if |
---|
193 | } |
---|
194 | |
---|
195 | static void Signal( int sig, void (* handler)(SIGPARMS), int flags ) { |
---|
196 | struct sigaction act; |
---|
197 | act.sa_sigaction = (void (*)(int, siginfo_t *, void *))handler; |
---|
198 | _Signal(act, sig, flags); |
---|
199 | } // Signal |
---|
200 | |
---|
201 | static void Signal( int sig, void (* handler)(int), int flags ) { |
---|
202 | struct sigaction act; |
---|
203 | act.sa_handler = handler; |
---|
204 | _Signal(act, sig, flags); |
---|
205 | } // Signal |
---|
206 | |
---|
207 | static void sigSegvBusHandler( SIGPARMS ) { |
---|
208 | if ( sfp->si_addr == nullptr ) { |
---|
209 | cerr << "Null pointer (nullptr) dereference." << endl; |
---|
210 | } else { |
---|
211 | cerr << (sig == SIGSEGV ? "Segment fault" : "Bus error") << " at memory location " << sfp->si_addr << "." << endl |
---|
212 | << "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; |
---|
213 | } // if |
---|
214 | backtrace( 2 ); // skip first 2 stack frames |
---|
215 | abort(); // cause core dump for debugging |
---|
216 | } // sigSegvBusHandler |
---|
217 | |
---|
218 | static void sigFpeHandler( SIGPARMS ) { |
---|
219 | const char * msg; |
---|
220 | |
---|
221 | switch ( sfp->si_code ) { |
---|
222 | case FPE_INTDIV: case FPE_FLTDIV: msg = "divide by zero"; break; |
---|
223 | case FPE_FLTOVF: msg = "overflow"; break; |
---|
224 | case FPE_FLTUND: msg = "underflow"; break; |
---|
225 | case FPE_FLTRES: msg = "inexact result"; break; |
---|
226 | case FPE_FLTINV: msg = "invalid operation"; break; |
---|
227 | default: msg = "unknown"; |
---|
228 | } // choose |
---|
229 | cerr << "Computation error " << msg << " at location " << sfp->si_addr << endl |
---|
230 | << "Possible cause is constant-expression evaluation invalid." << endl; |
---|
231 | backtrace( 2 ); // skip first 2 stack frames |
---|
232 | abort(); // cause core dump for debugging |
---|
233 | } // sigFpeHandler |
---|
234 | |
---|
235 | static void sigAbortHandler( SIGPARMS ) { |
---|
236 | backtrace( 6 ); // skip first 6 stack frames |
---|
237 | Signal( SIGABRT, SIG_DFL, SA_SIGINFO ); // reset default signal handler |
---|
238 | raise( SIGABRT ); // reraise SIGABRT |
---|
239 | } // sigAbortHandler |
---|
240 | |
---|
241 | int main( int argc, char * argv[] ) { |
---|
242 | FILE * input; // use FILE rather than istream because yyin is FILE |
---|
243 | ostream * output = & cout; |
---|
244 | list< Declaration * > translationUnit; |
---|
245 | |
---|
246 | Signal( SIGSEGV, sigSegvBusHandler, SA_SIGINFO ); |
---|
247 | Signal( SIGBUS, sigSegvBusHandler, SA_SIGINFO ); |
---|
248 | Signal( SIGFPE, sigFpeHandler, SA_SIGINFO ); |
---|
249 | Signal( SIGABRT, sigAbortHandler, SA_SIGINFO ); |
---|
250 | |
---|
251 | // cout << "main" << endl; |
---|
252 | // for ( int i = 0; i < argc; i += 1 ) { |
---|
253 | // cout << '\t' << argv[i] << endl; |
---|
254 | // } // for |
---|
255 | |
---|
256 | parse_cmdline( argc, argv ); // process command-line arguments |
---|
257 | CodeGen::FixMain::setReplaceMain( !nomainp ); |
---|
258 | |
---|
259 | if ( waiting_for_gdb ) { |
---|
260 | cerr << "Waiting for gdb" << endl; |
---|
261 | cerr << "run :" << endl; |
---|
262 | cerr << " gdb attach " << getpid() << endl; |
---|
263 | raise(SIGSTOP); |
---|
264 | } // if |
---|
265 | |
---|
266 | try { |
---|
267 | // choose to read the program from a file or stdin |
---|
268 | if ( optind < argc ) { // any commands after the flags ? => input file name |
---|
269 | input = fopen( argv[ optind ], "r" ); |
---|
270 | assertf( input, "cannot open %s because %s\n", argv[ optind ], strerror( errno ) ); |
---|
271 | optind += 1; |
---|
272 | } else { // no input file name |
---|
273 | input = stdin; |
---|
274 | } // if |
---|
275 | |
---|
276 | Stats::Time::StartGlobal(); |
---|
277 | NewPass("Parse"); |
---|
278 | Stats::Time::StartBlock("Parse"); |
---|
279 | |
---|
280 | // read in the builtins, extras, and the prelude |
---|
281 | if ( ! nopreludep ) { // include gcc builtins |
---|
282 | // -l is for initial build ONLY and builtins.cf is not in the lib directory so access it here. |
---|
283 | |
---|
284 | assertf( !PreludeDirector.empty(), "Can't find prelude without option --prelude-dir must be used." ); |
---|
285 | |
---|
286 | // Read to gcc builtins, if not generating the cfa library |
---|
287 | FILE * gcc_builtins = fopen( (PreludeDirector + "/gcc-builtins.cf").c_str(), "r" ); |
---|
288 | assertf( gcc_builtins, "cannot open gcc-builtins.cf\n" ); |
---|
289 | parse( gcc_builtins, LinkageSpec::Compiler ); |
---|
290 | |
---|
291 | // read the extra prelude in, if not generating the cfa library |
---|
292 | FILE * extras = fopen( (PreludeDirector + "/extras.cf").c_str(), "r" ); |
---|
293 | assertf( extras, "cannot open extras.cf\n" ); |
---|
294 | parse( extras, LinkageSpec::BuiltinC ); |
---|
295 | |
---|
296 | if ( ! libcfap ) { |
---|
297 | // read the prelude in, if not generating the cfa library |
---|
298 | FILE * prelude = fopen( (PreludeDirector + "/prelude.cfa").c_str(), "r" ); |
---|
299 | assertf( prelude, "cannot open prelude.cfa\n" ); |
---|
300 | parse( prelude, LinkageSpec::Intrinsic ); |
---|
301 | |
---|
302 | // Read to cfa builtins, if not generating the cfa library |
---|
303 | FILE * builtins = fopen( (PreludeDirector + "/builtins.cf").c_str(), "r" ); |
---|
304 | assertf( builtins, "cannot open builtins.cf\n" ); |
---|
305 | parse( builtins, LinkageSpec::BuiltinCFA ); |
---|
306 | } // if |
---|
307 | } // if |
---|
308 | |
---|
309 | parse( input, libcfap ? LinkageSpec::Intrinsic : LinkageSpec::Cforall, yydebug ); |
---|
310 | |
---|
311 | if ( parsep ) { |
---|
312 | parseTree->printList( cout ); |
---|
313 | delete parseTree; |
---|
314 | return EXIT_SUCCESS; |
---|
315 | } // if |
---|
316 | |
---|
317 | buildList( parseTree, translationUnit ); |
---|
318 | delete parseTree; |
---|
319 | parseTree = nullptr; |
---|
320 | |
---|
321 | if ( astp ) { |
---|
322 | dump( translationUnit ); |
---|
323 | return EXIT_SUCCESS; |
---|
324 | } // if |
---|
325 | |
---|
326 | // Temporary: fill locations after parsing so that every node has a location, for early error messages. |
---|
327 | // Eventually we should pass the locations from the parser to every node, but this quick and dirty solution |
---|
328 | // works okay for now. |
---|
329 | CodeTools::fillLocations( translationUnit ); |
---|
330 | Stats::Time::StopBlock(); |
---|
331 | |
---|
332 | if( useNewAST ) { |
---|
333 | if (Stats::Counters::enabled) { |
---|
334 | ast::pass_visitor_stats.avg = Stats::Counters::build<Stats::Counters::AverageCounter<double>>("Average Depth - New"); |
---|
335 | ast::pass_visitor_stats.max = Stats::Counters::build<Stats::Counters::MaxCounter<double>>("Max depth - New"); |
---|
336 | } |
---|
337 | auto transUnit = convert( move( translationUnit ) ); |
---|
338 | |
---|
339 | forceFillCodeLocations( transUnit ); |
---|
340 | |
---|
341 | PASS( "Translate Exception Declarations", ControlStruct::translateExcept( transUnit ) ); |
---|
342 | if ( exdeclp ) { |
---|
343 | dump( move( transUnit ) ); |
---|
344 | return EXIT_SUCCESS; |
---|
345 | } |
---|
346 | |
---|
347 | PASS( "Verify Ctor, Dtor & Assign", Validate::verifyCtorDtorAssign( transUnit ) ); |
---|
348 | PASS( "Hoist Type Decls", Validate::hoistTypeDecls( transUnit ) ); |
---|
349 | // Hoist Type Decls pulls some declarations out of contexts where |
---|
350 | // locations are not tracked. Perhaps they should be, but for now |
---|
351 | // the full fill solves it. |
---|
352 | forceFillCodeLocations( transUnit ); |
---|
353 | |
---|
354 | PASS( "Replace Typedefs", Validate::replaceTypedef( transUnit ) ); |
---|
355 | PASS( "Fix Return Types", Validate::fixReturnTypes( transUnit ) ); |
---|
356 | PASS( "Enum and Pointer Decay", Validate::decayEnumsAndPointers( transUnit ) ); |
---|
357 | |
---|
358 | PASS( "Link Reference To Types", Validate::linkReferenceToTypes( transUnit ) ); |
---|
359 | |
---|
360 | PASS( "Fix Qualified Types", Validate::fixQualifiedTypes( transUnit ) ); |
---|
361 | PASS( "Hoist Struct", Validate::hoistStruct( transUnit ) ); |
---|
362 | PASS( "Eliminate Typedef", Validate::eliminateTypedef( transUnit ) ); |
---|
363 | PASS( "Validate Generic Parameters", Validate::fillGenericParameters( transUnit ) ); |
---|
364 | PASS( "Translate Dimensions", Validate::translateDimensionParameters( transUnit ) ); |
---|
365 | PASS( "Check Function Returns", Validate::checkReturnStatements( transUnit ) ); |
---|
366 | PASS( "Fix Return Statements", InitTweak::fixReturnStatements( transUnit ) ); |
---|
367 | PASS( "Implement Concurrent Keywords", Concurrency::implementKeywords( transUnit ) ); |
---|
368 | PASS( "Forall Pointer Decay", Validate::decayForallPointers( transUnit ) ); |
---|
369 | PASS( "Hoist Control Declarations", ControlStruct::hoistControlDecls( transUnit ) ); |
---|
370 | |
---|
371 | PASS( "Generate Autogen Routines", Validate::autogenerateRoutines( transUnit ) ); |
---|
372 | |
---|
373 | PASS( "Implement Mutex", Concurrency::implementMutex( transUnit ) ); |
---|
374 | PASS( "Implement Thread Start", Concurrency::implementThreadStarter( transUnit ) ); |
---|
375 | PASS( "Compound Literal", Validate::handleCompoundLiterals( transUnit ) ); |
---|
376 | PASS( "Set Length From Initializer", Validate::setLengthFromInitializer( transUnit ) ); |
---|
377 | PASS( "Find Global Decls", Validate::findGlobalDecls( transUnit ) ); |
---|
378 | PASS( "Fix Label Address", Validate::fixLabelAddresses( transUnit ) ); |
---|
379 | |
---|
380 | if ( symtabp ) { |
---|
381 | return EXIT_SUCCESS; |
---|
382 | } // if |
---|
383 | |
---|
384 | if ( expraltp ) { |
---|
385 | ResolvExpr::printCandidates( transUnit ); |
---|
386 | return EXIT_SUCCESS; |
---|
387 | } // if |
---|
388 | |
---|
389 | if ( validp ) { |
---|
390 | dump( move( transUnit ) ); |
---|
391 | return EXIT_SUCCESS; |
---|
392 | } // if |
---|
393 | |
---|
394 | PASS( "Translate Throws", ControlStruct::translateThrows( transUnit ) ); |
---|
395 | PASS( "Fix Labels", ControlStruct::fixLabels( transUnit ) ); |
---|
396 | PASS( "Fix Names", CodeGen::fixNames( transUnit ) ); |
---|
397 | PASS( "Gen Init", InitTweak::genInit( transUnit ) ); |
---|
398 | PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( transUnit ) ); |
---|
399 | |
---|
400 | if ( libcfap ) { |
---|
401 | // Generate the bodies of cfa library functions. |
---|
402 | LibCfa::makeLibCfa( transUnit ); |
---|
403 | } // if |
---|
404 | |
---|
405 | if ( declstatsp ) { |
---|
406 | printDeclStats( transUnit ); |
---|
407 | return EXIT_SUCCESS; |
---|
408 | } // if |
---|
409 | |
---|
410 | if ( bresolvep ) { |
---|
411 | dump( move( transUnit ) ); |
---|
412 | return EXIT_SUCCESS; |
---|
413 | } // if |
---|
414 | |
---|
415 | if ( resolvprotop ) { |
---|
416 | dumpAsResolverProto( transUnit ); |
---|
417 | return EXIT_SUCCESS; |
---|
418 | } // if |
---|
419 | |
---|
420 | PASS( "Resolve", ResolvExpr::resolve( transUnit ) ); |
---|
421 | if ( exprp ) { |
---|
422 | dump( move( transUnit ) ); |
---|
423 | return EXIT_SUCCESS; |
---|
424 | } // if |
---|
425 | |
---|
426 | forceFillCodeLocations( transUnit ); |
---|
427 | |
---|
428 | PASS( "Fix Init", InitTweak::fix(transUnit, buildingLibrary())); |
---|
429 | |
---|
430 | // fix ObjectDecl - replaces ConstructorInit nodes |
---|
431 | if ( ctorinitp ) { |
---|
432 | dump( move( transUnit ) ); |
---|
433 | return EXIT_SUCCESS; |
---|
434 | } // if |
---|
435 | |
---|
436 | // Currently not working due to unresolved issues with UniqueExpr |
---|
437 | 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 |
---|
438 | |
---|
439 | PASS( "Translate Tries", ControlStruct::translateTries( transUnit ) ); |
---|
440 | PASS( "Gen Waitfor", Concurrency::generateWaitFor( transUnit ) ); |
---|
441 | |
---|
442 | // Needs to happen before tuple types are expanded. |
---|
443 | PASS( "Convert Specializations", GenPoly::convertSpecializations( transUnit ) ); |
---|
444 | |
---|
445 | PASS( "Expand Tuples", Tuples::expandTuples( transUnit ) ); |
---|
446 | |
---|
447 | if ( tuplep ) { |
---|
448 | dump( move( transUnit ) ); |
---|
449 | return EXIT_SUCCESS; |
---|
450 | } // if |
---|
451 | |
---|
452 | // Must come after Translate Tries. |
---|
453 | PASS( "Virtual Expand Casts", Virtual::expandCasts( transUnit ) ); |
---|
454 | |
---|
455 | translationUnit = convert( move( transUnit ) ); |
---|
456 | } else { |
---|
457 | PASS( "Translate Exception Declarations", ControlStruct::translateExcept( translationUnit ) ); |
---|
458 | if ( exdeclp ) { |
---|
459 | dump( translationUnit ); |
---|
460 | return EXIT_SUCCESS; |
---|
461 | } // if |
---|
462 | |
---|
463 | // add the assignment statement after the initialization of a type parameter |
---|
464 | PASS( "Validate", SymTab::validate( translationUnit ) ); |
---|
465 | |
---|
466 | if ( symtabp ) { |
---|
467 | deleteAll( translationUnit ); |
---|
468 | return EXIT_SUCCESS; |
---|
469 | } // if |
---|
470 | |
---|
471 | if ( expraltp ) { |
---|
472 | PassVisitor<ResolvExpr::AlternativePrinter> printer( cout ); |
---|
473 | acceptAll( translationUnit, printer ); |
---|
474 | return EXIT_SUCCESS; |
---|
475 | } // if |
---|
476 | |
---|
477 | if ( validp ) { |
---|
478 | dump( translationUnit ); |
---|
479 | return EXIT_SUCCESS; |
---|
480 | } // if |
---|
481 | |
---|
482 | PASS( "Translate Throws", ControlStruct::translateThrows( translationUnit ) ); |
---|
483 | PASS( "Fix Labels", ControlStruct::fixLabels( translationUnit ) ); |
---|
484 | PASS( "Fix Names", CodeGen::fixNames( translationUnit ) ); |
---|
485 | PASS( "Gen Init", InitTweak::genInit( translationUnit ) ); |
---|
486 | PASS( "Expand Member Tuples" , Tuples::expandMemberTuples( translationUnit ) ); |
---|
487 | |
---|
488 | if ( libcfap ) { |
---|
489 | // Generate the bodies of cfa library functions. |
---|
490 | LibCfa::makeLibCfa( translationUnit ); |
---|
491 | } // if |
---|
492 | |
---|
493 | if ( declstatsp ) { |
---|
494 | CodeTools::printDeclStats( translationUnit ); |
---|
495 | deleteAll( translationUnit ); |
---|
496 | return EXIT_SUCCESS; |
---|
497 | } // if |
---|
498 | |
---|
499 | if ( bresolvep ) { |
---|
500 | dump( translationUnit ); |
---|
501 | return EXIT_SUCCESS; |
---|
502 | } // if |
---|
503 | |
---|
504 | CodeTools::fillLocations( translationUnit ); |
---|
505 | |
---|
506 | if ( resolvprotop ) { |
---|
507 | CodeTools::dumpAsResolvProto( translationUnit ); |
---|
508 | return EXIT_SUCCESS; |
---|
509 | } // if |
---|
510 | |
---|
511 | PASS( "Resolve", ResolvExpr::resolve( translationUnit ) ); |
---|
512 | if ( exprp ) { |
---|
513 | dump( translationUnit ); |
---|
514 | return EXIT_SUCCESS; |
---|
515 | } |
---|
516 | |
---|
517 | PASS( "Fix Init", InitTweak::fix( translationUnit, buildingLibrary() ) ); |
---|
518 | |
---|
519 | // fix ObjectDecl - replaces ConstructorInit nodes |
---|
520 | if ( ctorinitp ) { |
---|
521 | dump ( translationUnit ); |
---|
522 | return EXIT_SUCCESS; |
---|
523 | } // if |
---|
524 | |
---|
525 | 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 |
---|
526 | PASS( "Translate Tries", ControlStruct::translateTries( translationUnit ) ); |
---|
527 | PASS( "Gen Waitfor", Concurrency::generateWaitFor( translationUnit ) ); |
---|
528 | PASS( "Convert Specializations", GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded |
---|
529 | PASS( "Expand Tuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this? |
---|
530 | |
---|
531 | if ( tuplep ) { |
---|
532 | dump( translationUnit ); |
---|
533 | return EXIT_SUCCESS; |
---|
534 | } // if |
---|
535 | |
---|
536 | PASS( "Virtual Expand Casts", Virtual::expandCasts( translationUnit ) ); // Must come after translateEHM |
---|
537 | } |
---|
538 | |
---|
539 | PASS( "Instantiate Generics", GenPoly::instantiateGeneric( translationUnit ) ); |
---|
540 | if ( genericsp ) { |
---|
541 | dump( translationUnit ); |
---|
542 | return EXIT_SUCCESS; |
---|
543 | } // if |
---|
544 | |
---|
545 | PASS( "Convert L-Value", GenPoly::convertLvalue( translationUnit ) ); |
---|
546 | |
---|
547 | if ( bboxp ) { |
---|
548 | dump( translationUnit ); |
---|
549 | return EXIT_SUCCESS; |
---|
550 | } // if |
---|
551 | PASS( "Box", GenPoly::box( translationUnit ) ); |
---|
552 | |
---|
553 | PASS( "Link-Once", CodeGen::translateLinkOnce( translationUnit ) ); |
---|
554 | |
---|
555 | // Code has been lowered to C, now we can start generation. |
---|
556 | |
---|
557 | if ( bcodegenp ) { |
---|
558 | dump( translationUnit ); |
---|
559 | return EXIT_SUCCESS; |
---|
560 | } // if |
---|
561 | |
---|
562 | if ( optind < argc ) { // any commands after the flags and input file ? => output file name |
---|
563 | output = new ofstream( argv[ optind ] ); |
---|
564 | } // if |
---|
565 | |
---|
566 | CodeTools::fillLocations( translationUnit ); |
---|
567 | PASS( "Code Gen", CodeGen::generate( translationUnit, *output, ! genproto, prettycodegenp, true, linemarks ) ); |
---|
568 | |
---|
569 | CodeGen::FixMain::fix( translationUnit, *output, |
---|
570 | (PreludeDirector + "/bootloader.c").c_str() ); |
---|
571 | if ( output != &cout ) { |
---|
572 | delete output; |
---|
573 | } // if |
---|
574 | } catch ( SemanticErrorException & e ) { |
---|
575 | if ( errorp ) { |
---|
576 | cerr << "---AST at error:---" << endl; |
---|
577 | dump( translationUnit, cerr ); |
---|
578 | cerr << endl << "---End of AST, begin error message:---\n" << endl; |
---|
579 | } // if |
---|
580 | e.print(); |
---|
581 | if ( output != &cout ) { |
---|
582 | delete output; |
---|
583 | } // if |
---|
584 | return EXIT_FAILURE; |
---|
585 | } catch ( UnimplementedError & e ) { |
---|
586 | cout << "Sorry, " << e.get_what() << " is not currently implemented" << endl; |
---|
587 | if ( output != &cout ) { |
---|
588 | delete output; |
---|
589 | } // if |
---|
590 | return EXIT_FAILURE; |
---|
591 | } catch ( CompilerError & e ) { |
---|
592 | cerr << "Compiler Error: " << e.get_what() << endl; |
---|
593 | cerr << "(please report bugs to [REDACTED])" << endl; |
---|
594 | if ( output != &cout ) { |
---|
595 | delete output; |
---|
596 | } // if |
---|
597 | return EXIT_FAILURE; |
---|
598 | } catch ( std::bad_alloc & ) { |
---|
599 | cerr << "*cfa-cpp compilation error* std::bad_alloc" << endl; |
---|
600 | backtrace( 1 ); |
---|
601 | abort(); |
---|
602 | } catch ( ... ) { |
---|
603 | exception_ptr eptr = current_exception(); |
---|
604 | try { |
---|
605 | if (eptr) { |
---|
606 | rethrow_exception(eptr); |
---|
607 | } else { |
---|
608 | cerr << "*cfa-cpp compilation error* exception uncaught and unknown" << endl; |
---|
609 | } // if |
---|
610 | } catch( const exception & e ) { |
---|
611 | cerr << "*cfa-cpp compilation error* uncaught exception \"" << e.what() << "\"\n"; |
---|
612 | } // try |
---|
613 | return EXIT_FAILURE; |
---|
614 | } // try |
---|
615 | |
---|
616 | deleteAll( translationUnit ); |
---|
617 | Stats::print(); |
---|
618 | return EXIT_SUCCESS; |
---|
619 | } // main |
---|
620 | |
---|
621 | |
---|
622 | static const char optstring[] = ":c:ghlLmNnpdOAP:S:twW:D:"; |
---|
623 | |
---|
624 | enum { PreludeDir = 128 }; |
---|
625 | static struct option long_opts[] = { |
---|
626 | { "colors", required_argument, nullptr, 'c' }, |
---|
627 | { "gdb", no_argument, nullptr, 'g' }, |
---|
628 | { "help", no_argument, nullptr, 'h' }, |
---|
629 | { "libcfa", no_argument, nullptr, 'l' }, |
---|
630 | { "linemarks", no_argument, nullptr, 'L' }, |
---|
631 | { "no-main", no_argument, 0, 'm' }, |
---|
632 | { "no-linemarks", no_argument, nullptr, 'N' }, |
---|
633 | { "no-prelude", no_argument, nullptr, 'n' }, |
---|
634 | { "prototypes", no_argument, nullptr, 'p' }, |
---|
635 | { "deterministic-out", no_argument, nullptr, 'd' }, |
---|
636 | { "old-ast", no_argument, nullptr, 'O'}, |
---|
637 | { "new-ast", no_argument, nullptr, 'A'}, |
---|
638 | { "print", required_argument, nullptr, 'P' }, |
---|
639 | { "prelude-dir", required_argument, nullptr, PreludeDir }, |
---|
640 | { "statistics", required_argument, nullptr, 'S' }, |
---|
641 | { "tree", no_argument, nullptr, 't' }, |
---|
642 | { "", no_argument, nullptr, 0 }, // -w |
---|
643 | { "", no_argument, nullptr, 0 }, // -W |
---|
644 | { "", no_argument, nullptr, 0 }, // -D |
---|
645 | { nullptr, 0, nullptr, 0 } |
---|
646 | }; // long_opts |
---|
647 | |
---|
648 | static const char * description[] = { |
---|
649 | "diagnostic color: never, always, auto", // -c |
---|
650 | "wait for gdb to attach", // -g |
---|
651 | "print translator help message", // -h |
---|
652 | "generate libcfa.c", // -l |
---|
653 | "generate line marks", // -L |
---|
654 | "do not replace main", // -m |
---|
655 | "do not generate line marks", // -N |
---|
656 | "do not read prelude", // -n |
---|
657 | "do not generate prelude prototypes => prelude not printed", // -p |
---|
658 | "only print deterministic output", // -d |
---|
659 | "Use the old-ast", // -O |
---|
660 | "Use the new-ast", // -A |
---|
661 | "print", // -P |
---|
662 | "<directory> prelude directory for debug/nodebug", // no flag |
---|
663 | "<option-list> enable profiling information: counters, heap, time, all, none", // -S |
---|
664 | "building cfa standard lib", // -t |
---|
665 | "", // -w |
---|
666 | "", // -W |
---|
667 | "", // -D |
---|
668 | }; // description |
---|
669 | |
---|
670 | static_assert( sizeof( long_opts ) / sizeof( long_opts[0] ) - 1 == sizeof( description ) / sizeof( description[0] ), "Long opts and description must match" ); |
---|
671 | |
---|
672 | static struct Printopts { |
---|
673 | const char * name; |
---|
674 | int & flag; |
---|
675 | int val; |
---|
676 | const char * descript; |
---|
677 | } printopts[] = { |
---|
678 | { "ascodegen", codegenp, true, "print AST as codegen rather than AST" }, |
---|
679 | { "asterr", errorp, true, "print AST on error" }, |
---|
680 | { "declstats", declstatsp, true, "code property statistics" }, |
---|
681 | { "parse", yydebug, true, "yacc (parsing) debug information" }, |
---|
682 | { "pretty", prettycodegenp, true, "prettyprint for ascodegen flag" }, |
---|
683 | { "rproto", resolvprotop, true, "resolver-proto instance" }, |
---|
684 | { "rsteps", resolvep, true, "print resolver steps" }, |
---|
685 | { "tree", parsep, true, "print parse tree" }, |
---|
686 | // code dumps |
---|
687 | { "ast", astp, true, "print AST after parsing" }, |
---|
688 | { "exdecl", exdeclp, true, "print AST after translating exception decls" }, |
---|
689 | { "symevt", symtabp, true, "print AST after symbol table events" }, |
---|
690 | { "altexpr", expraltp, true, "print alternatives for expressions" }, |
---|
691 | { "astdecl", validp, true, "print AST after declaration validation pass" }, |
---|
692 | { "resolver", bresolvep, true, "print AST before resolver step" }, |
---|
693 | { "astexpr", exprp, true, "print AST after expression analysis" }, |
---|
694 | { "ctordtor", ctorinitp, true, "print AST after ctor/dtor are replaced" }, |
---|
695 | { "tuple", tuplep, true, "print AST after tuple expansion" }, |
---|
696 | { "astgen", genericsp, true, "print AST after instantiate generics" }, |
---|
697 | { "box", bboxp, true, "print AST before box step" }, |
---|
698 | { "codegen", bcodegenp, true, "print AST before code generation" }, |
---|
699 | }; |
---|
700 | enum { printoptsSize = sizeof( printopts ) / sizeof( printopts[0] ) }; |
---|
701 | |
---|
702 | static void usage( char * argv[] ) { |
---|
703 | cout << "Usage: " << argv[0] << " [options] [input-file (default stdin)] [output-file (default stdout)], where options are:" << endl; |
---|
704 | int i = 0, j = 1; // j skips starting colon |
---|
705 | for ( ; long_opts[i].name != 0 && optstring[j] != '\0'; i += 1, j += 1 ) { |
---|
706 | if ( long_opts[i].name[0] != '\0' ) { // hidden option, internal usage only |
---|
707 | if ( strcmp( long_opts[i].name, "prelude-dir" ) != 0 ) { // flag |
---|
708 | cout << " -" << optstring[j] << ","; |
---|
709 | } else { // no flag |
---|
710 | j -= 1; // compensate |
---|
711 | cout << " "; |
---|
712 | } // if |
---|
713 | cout << " --" << left << setw(12) << long_opts[i].name << " "; |
---|
714 | if ( strcmp( long_opts[i].name, "print" ) == 0 ) { |
---|
715 | cout << "one of: " << endl; |
---|
716 | for ( int i = 0; i < printoptsSize; i += 1 ) { |
---|
717 | cout << setw(10) << " " << left << setw(10) << printopts[i].name << " " << printopts[i].descript << endl; |
---|
718 | } // for |
---|
719 | } else { |
---|
720 | cout << description[i] << endl; |
---|
721 | } // if |
---|
722 | } // if |
---|
723 | if ( optstring[j + 1] == ':' ) j += 1; |
---|
724 | } // for |
---|
725 | if ( long_opts[i].name != 0 || optstring[j] != '\0' ) assertf( false, "internal error, mismatch of option flags and names\n" ); |
---|
726 | exit( EXIT_FAILURE ); |
---|
727 | } // usage |
---|
728 | |
---|
729 | static void parse_cmdline( int argc, char * argv[] ) { |
---|
730 | opterr = 0; // (global) prevent getopt from printing error messages |
---|
731 | |
---|
732 | bool Wsuppress = false, Werror = false; |
---|
733 | int c; |
---|
734 | while ( (c = getopt_long( argc, argv, optstring, long_opts, nullptr )) != -1 ) { |
---|
735 | switch ( c ) { |
---|
736 | case 'c': // diagnostic colors |
---|
737 | if ( strcmp( optarg, "always" ) == 0 ) { |
---|
738 | ErrorHelpers::colors = ErrorHelpers::Colors::Always; |
---|
739 | } else if ( strcmp( optarg, "never" ) == 0 ) { |
---|
740 | ErrorHelpers::colors = ErrorHelpers::Colors::Never; |
---|
741 | } else if ( strcmp( optarg, "auto" ) == 0 ) { |
---|
742 | ErrorHelpers::colors = ErrorHelpers::Colors::Auto; |
---|
743 | } // if |
---|
744 | break; |
---|
745 | case 'h': // help message |
---|
746 | usage( argv ); // no return |
---|
747 | break; |
---|
748 | case 'l': // generate libcfa.c |
---|
749 | libcfap = true; |
---|
750 | break; |
---|
751 | case 'L': // generate line marks |
---|
752 | linemarks = true; |
---|
753 | break; |
---|
754 | case 'm': // do not replace main |
---|
755 | nomainp = true; |
---|
756 | break; |
---|
757 | case 'N': // do not generate line marks |
---|
758 | linemarks = false; |
---|
759 | break; |
---|
760 | case 'n': // do not read prelude |
---|
761 | nopreludep = true; |
---|
762 | break; |
---|
763 | case 'p': // generate prototypes for prelude functions |
---|
764 | genproto = true; |
---|
765 | break; |
---|
766 | case 'd': // don't print non-deterministic output |
---|
767 | deterministic_output = true; |
---|
768 | break; |
---|
769 | case 'O': // don't print non-deterministic output |
---|
770 | useNewAST = false; |
---|
771 | break; |
---|
772 | case 'A': // don't print non-deterministic output |
---|
773 | useNewAST = true; |
---|
774 | break; |
---|
775 | case 'P': // print options |
---|
776 | for ( int i = 0;; i += 1 ) { |
---|
777 | if ( i == printoptsSize ) { |
---|
778 | cout << "Unknown --print option " << optarg << endl; |
---|
779 | goto Default; |
---|
780 | } // if |
---|
781 | if ( strcmp( optarg, printopts[i].name ) == 0 ) { |
---|
782 | printopts[i].flag = printopts[i].val; |
---|
783 | break; |
---|
784 | } // if |
---|
785 | } // for |
---|
786 | break; |
---|
787 | case PreludeDir: // prelude directory for debug/nodebug, hidden |
---|
788 | PreludeDirector = optarg; |
---|
789 | break; |
---|
790 | case 'S': // enable profiling information, argument comma separated list of names |
---|
791 | Stats::parse_params( optarg ); |
---|
792 | break; |
---|
793 | case 't': // building cfa stdlib |
---|
794 | treep = true; |
---|
795 | break; |
---|
796 | case 'g': // wait for gdb |
---|
797 | waiting_for_gdb = true; |
---|
798 | break; |
---|
799 | case 'w': // suppress all warnings, hidden |
---|
800 | Wsuppress = true; |
---|
801 | break; |
---|
802 | case 'W': // coordinate gcc -W with CFA, hidden |
---|
803 | if ( strcmp( optarg, "all" ) == 0 ) { |
---|
804 | SemanticWarning_EnableAll(); |
---|
805 | } else if ( strcmp( optarg, "error" ) == 0 ) { |
---|
806 | Werror = true; |
---|
807 | } else { |
---|
808 | char * warning = optarg; |
---|
809 | Severity s; |
---|
810 | if ( strncmp( optarg, "no-", 3 ) == 0 ) { |
---|
811 | warning += 3; |
---|
812 | s = Severity::Suppress; |
---|
813 | } else { |
---|
814 | s = Severity::Warn; |
---|
815 | } // if |
---|
816 | SemanticWarning_Set( warning, s ); |
---|
817 | } // if |
---|
818 | break; |
---|
819 | case 'D': // ignore -Dxxx, forwarded by cpp, hidden |
---|
820 | break; |
---|
821 | case '?': // unknown option |
---|
822 | if ( optopt ) { // short option ? |
---|
823 | cout << "Unknown option -" << (char)optopt << endl; |
---|
824 | } else { |
---|
825 | cout << "Unknown option " << argv[optind - 1] << endl; |
---|
826 | } // if |
---|
827 | goto Default; |
---|
828 | case ':': // missing option |
---|
829 | if ( optopt ) { // short option ? |
---|
830 | cout << "Missing option for -" << (char)optopt << endl; |
---|
831 | } else { |
---|
832 | cout << "Missing option for " << argv[optind - 1] << endl; |
---|
833 | } // if |
---|
834 | goto Default; |
---|
835 | Default: |
---|
836 | default: |
---|
837 | usage( argv ); // no return |
---|
838 | } // switch |
---|
839 | } // while |
---|
840 | |
---|
841 | if ( Werror ) { |
---|
842 | SemanticWarning_WarningAsError(); |
---|
843 | } // if |
---|
844 | if ( Wsuppress ) { |
---|
845 | SemanticWarning_SuppressAll(); |
---|
846 | } // if |
---|
847 | // for ( const auto w : WarningFormats ) { |
---|
848 | // cout << w.name << ' ' << (int)w.severity << endl; |
---|
849 | // } // for |
---|
850 | } // parse_cmdline |
---|
851 | |
---|
852 | static void parse( FILE * input, LinkageSpec::Spec linkage, bool shouldExit ) { |
---|
853 | extern int yyparse( void ); |
---|
854 | extern FILE * yyin; |
---|
855 | extern int yylineno; |
---|
856 | |
---|
857 | ::linkage = linkage; // set globals |
---|
858 | yyin = input; |
---|
859 | yylineno = 1; |
---|
860 | int parseStatus = yyparse(); |
---|
861 | |
---|
862 | fclose( input ); |
---|
863 | if ( shouldExit || parseStatus != 0 ) { |
---|
864 | exit( parseStatus ); |
---|
865 | } // if |
---|
866 | } // parse |
---|
867 | |
---|
868 | static bool notPrelude( Declaration * decl ) { |
---|
869 | return ! LinkageSpec::isBuiltin( decl->get_linkage() ); |
---|
870 | } // notPrelude |
---|
871 | |
---|
872 | static void dump( list< Declaration * > & translationUnit, ostream & out ) { |
---|
873 | list< Declaration * > decls; |
---|
874 | |
---|
875 | if ( genproto ) { |
---|
876 | filter( translationUnit.begin(), translationUnit.end(), back_inserter( decls ), notPrelude ); |
---|
877 | } else { |
---|
878 | decls = translationUnit; |
---|
879 | } // if |
---|
880 | |
---|
881 | // depending on commandline options, either generate code or dump the AST |
---|
882 | if ( codegenp ) { |
---|
883 | CodeGen::generate( decls, out, ! genproto, prettycodegenp ); |
---|
884 | } else { |
---|
885 | printAll( decls, out ); |
---|
886 | } // if |
---|
887 | deleteAll( translationUnit ); |
---|
888 | } // dump |
---|
889 | |
---|
890 | static void dump( ast::TranslationUnit && transUnit, ostream & out ) { |
---|
891 | std::list< Declaration * > translationUnit = convert( move( transUnit ) ); |
---|
892 | dump( translationUnit, out ); |
---|
893 | } |
---|
894 | |
---|
895 | // Local Variables: // |
---|
896 | // tab-width: 4 // |
---|
897 | // mode: c++ // |
---|
898 | // compile-command: "make install" // |
---|
899 | // End: // |
---|