source: src/CodeGen/CodeGenerator.cc @ d60ccbf

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since d60ccbf was d60ccbf, checked in by Rob Schluntz <rschlunt@…>, 9 years ago

Merge branch 'master' into designate

Conflicts:

src/CodeGen/CodeGenerator.h

  • Property mode set to 100644
File size: 19.9 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// CodeGenerator.cc --
8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Mon Jul 27 14:40:06 2015
13// Update Count     : 218
14//
15
16#include <algorithm>
17#include <iostream>
18#include <cassert>
19#include <list>
20
21#include "Parser/ParseNode.h"
22
23#include "SynTree/Type.h"
24#include "SynTree/Expression.h"
25#include "SynTree/Initializer.h"
26#include "SynTree/Statement.h"
27
28#include "utility.h"
29#include "UnimplementedError.h"
30
31#include "CodeGenerator.h"
32#include "OperatorTable.h"
33#include "GenType.h"
34
35using namespace std;
36
37namespace CodeGen {
38        int CodeGenerator::tabsize = 4;
39
40        // the kinds of statements that would ideally be followed by whitespace
41        bool wantSpacing( Statement * stmt) {
42                return dynamic_cast< IfStmt * >( stmt ) || dynamic_cast< CompoundStmt * >( stmt ) ||
43                        dynamic_cast< WhileStmt * >( stmt ) || dynamic_cast< ForStmt * > ( stmt ) || dynamic_cast< SwitchStmt *>( stmt );
44        }
45
46        ostream & CodeGenerator::Indenter::operator()( ostream & output ) {
47          return output << string( cg.cur_indent, ' ' );
48        }
49
50        ostream & operator<<( ostream & output, CodeGenerator::Indenter &indent ) {
51                return indent( output );
52        }
53
54        CodeGenerator::CodeGenerator( std::ostream &os ) : indent( *this), cur_indent( 0 ), insideFunction( false ), output( os ) { }
55
56        CodeGenerator::CodeGenerator( std::ostream &os, std::string init, int indentation, bool infunp )
57                        : indent( *this), cur_indent( indentation ), insideFunction( infunp ), output( os ) {
58                //output << std::string( init );
59        }
60
61        CodeGenerator::CodeGenerator( std::ostream &os, char *init, int indentation, bool infunp )
62                        : indent( *this ), cur_indent( indentation ), insideFunction( infunp ), output( os ) {
63                //output << std::string( init );
64        }
65
66        string mangleName( DeclarationWithType *decl ) {
67                if ( decl->get_mangleName() != "" ) {
68                        return decl->get_mangleName();
69                } else {
70                        return decl->get_name();
71                } // if
72        }
73
74        //*** Declarations
75        void CodeGenerator::visit( FunctionDecl *functionDecl ) {
76                handleStorageClass( functionDecl );
77                if ( functionDecl->get_isInline() ) {
78                        output << "inline ";
79                } // if
80                if ( functionDecl->get_isNoreturn() ) {
81                        output << "_Noreturn ";
82                } // if
83                output << genType( functionDecl->get_functionType(), mangleName( functionDecl ) );
84
85                // how to get this to the Functype?
86                std::list< Declaration * > olds = functionDecl->get_oldDecls();
87                if ( ! olds.empty() ) {
88                        output << " /* function has old declaration */";
89                } // if
90
91                // acceptAll( functionDecl->get_oldDecls(), *this );
92                if ( functionDecl->get_statements() ) {
93                        functionDecl->get_statements()->accept( *this );
94                } // if
95        }
96
97        void CodeGenerator::visit( ObjectDecl *objectDecl ) {
98                handleStorageClass( objectDecl );
99                output << genType( objectDecl->get_type(), mangleName( objectDecl ) );
100       
101                if ( objectDecl->get_init() ) {
102                        output << " = ";
103                        objectDecl->get_init()->accept( *this );
104                } // if
105                if ( objectDecl->get_bitfieldWidth() ) {
106                        output << ":";
107                        objectDecl->get_bitfieldWidth()->accept( *this );
108                } // if
109        }
110
111        void CodeGenerator::handleAggregate( AggregateDecl *aggDecl ) {
112                if ( aggDecl->get_name() != "" )
113                        output << aggDecl->get_name();
114       
115                std::list< Declaration * > &memb = aggDecl->get_members();
116
117                if ( ! memb.empty() ) {
118                        output << " {" << endl;
119
120                        cur_indent += CodeGenerator::tabsize; 
121                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
122                                output << indent; 
123                                (*i)->accept( *this );
124                                output << ";" << endl;
125                        }
126
127                        cur_indent -= CodeGenerator::tabsize; 
128
129                        output << indent << "}";
130                } // if
131        }
132
133        void CodeGenerator::visit( StructDecl *structDecl ) {
134                output << "struct ";
135                handleAggregate( structDecl );
136        }
137
138        void CodeGenerator::visit( UnionDecl *aggregateDecl ) {
139                output << "union ";
140                handleAggregate( aggregateDecl );
141        }
142 
143        void CodeGenerator::visit( EnumDecl *aggDecl ) {
144                output << "enum ";
145
146                if ( aggDecl->get_name() != "" )
147                        output << aggDecl->get_name();
148       
149                std::list< Declaration* > &memb = aggDecl->get_members();
150
151                if ( ! memb.empty() ) {
152                        output << " {" << endl;
153
154                        cur_indent += CodeGenerator::tabsize; 
155                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
156                                ObjectDecl *obj = dynamic_cast< ObjectDecl* >( *i );
157                                assert( obj );
158                                output << indent << mangleName( obj ); 
159                                if ( obj->get_init() ) {
160                                        output << " = ";
161                                        obj->get_init()->accept( *this );
162                                } // if
163                                output << "," << endl;
164                        } // for
165
166                        cur_indent -= CodeGenerator::tabsize; 
167
168                        output << indent << "}";
169                } // if
170        }
171 
172        void CodeGenerator::visit( ContextDecl *aggregateDecl ) {}
173 
174        void CodeGenerator::visit( TypedefDecl *typeDecl ) {
175                output << "typedef ";
176                output << genType( typeDecl->get_base(), typeDecl->get_name() );
177        }
178 
179        void CodeGenerator::visit( TypeDecl *typeDecl ) {
180                // really, we should mutate this into something that isn't a TypeDecl but that requires large-scale changes,
181                // still to be done
182                output << "extern unsigned long " << typeDecl->get_name();
183                if ( typeDecl->get_base() ) {
184                        output << " = sizeof( " << genType( typeDecl->get_base(), "" ) << " )";
185                } // if
186        }
187
188        void CodeGenerator::printDesignators( std::list< Expression * > & designators ) {
189                typedef std::list< Expression * > DesignatorList;
190                if ( designators.size() == 0 ) return;
191                for ( DesignatorList::iterator iter = designators.begin(); iter != designators.end(); ++iter ) {
192                        // if expression is a name, then initializing aggregate member, if constant expression then array
193                        if ( NameExpr * nm = dynamic_cast< NameExpr * >( *iter ) ) {
194                                if ( nm->get_name() == "0" || nm->get_name() == "1" ) {
195                                        // except if name is 0 or 1...
196                                        output << "[";
197                                        nm->accept( *this );
198                                        output << "]";
199                                } else {
200                                        output << ".";
201                                        nm->accept( *this );
202                                }
203                        } else if ( dynamic_cast< ConstantExpr * >( *iter ) ) {
204                                output << "[";
205                                (*iter)->accept( *this );
206                                output << "]";
207                        } else {
208                                assert(0);
209                        }
210                }
211                output << " = ";
212        }
213
214        void CodeGenerator::visit( SingleInit *init ) {
215                printDesignators( init->get_designators() );
216                init->get_value()->accept( *this );
217        }
218
219        void CodeGenerator::visit( ListInit *init ) {
220                printDesignators( init->get_designators() );
221                output << "{ ";
222                genCommaList( init->begin_initializers(), init->end_initializers() );
223                output << " }";
224        }
225
226        void CodeGenerator::visit( Constant *constant ) { 
227                output << constant->get_value() ;
228        }
229
230        //*** Expressions
231        void CodeGenerator::visit( ApplicationExpr *applicationExpr ) {
232                if ( VariableExpr *varExpr = dynamic_cast< VariableExpr* >( applicationExpr->get_function() ) ) {
233                        OperatorInfo opInfo;
234                        if ( varExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( varExpr->get_var()->get_name(), opInfo ) ) {
235                                std::list< Expression* >::iterator arg = applicationExpr->get_args().begin();
236                                switch ( opInfo.type ) {
237                                  case OT_PREFIXASSIGN:
238                                  case OT_POSTFIXASSIGN:
239                                  case OT_INFIXASSIGN:
240                                        {
241                                                assert( arg != applicationExpr->get_args().end() );
242                                                if ( AddressExpr *addrExpr = dynamic_cast< AddressExpr * >( *arg ) ) {
243               
244                                                        *arg = addrExpr->get_arg();
245                                                } else {
246                                                        UntypedExpr *newExpr = new UntypedExpr( new NameExpr( "*?" ) );
247                                                        newExpr->get_args().push_back( *arg );
248                                                        *arg = newExpr;
249                                                } // if
250                                                break;
251                                        }
252             
253                                  default:
254                                        // do nothing
255                                        ;
256                                }
257           
258                                switch ( opInfo.type ) {
259                                  case OT_INDEX:
260                                        assert( applicationExpr->get_args().size() == 2 );
261                                        (*arg++)->accept( *this );
262                                        output << "[";
263                                        (*arg)->accept( *this );
264                                        output << "]";
265                                        break;
266             
267                                  case OT_CALL:
268                                        // there are no intrinsic definitions of the function call operator
269                                        assert( false );
270                                        break;
271             
272                                  case OT_PREFIX:
273                                  case OT_PREFIXASSIGN:
274                                        assert( applicationExpr->get_args().size() == 1 );
275                                        output << "(";
276                                        output << opInfo.symbol;
277                                        (*arg)->accept( *this );
278                                        output << ")";
279                                        break;
280             
281                                  case OT_POSTFIX:
282                                  case OT_POSTFIXASSIGN:
283                                        assert( applicationExpr->get_args().size() == 1 );
284                                        (*arg)->accept( *this );
285                                        output << opInfo.symbol;
286                                        break;
287
288                                  case OT_INFIX:
289                                  case OT_INFIXASSIGN:
290                                        assert( applicationExpr->get_args().size() == 2 );
291                                        output << "(";
292                                        (*arg++)->accept( *this );
293                                        output << opInfo.symbol;
294                                        (*arg)->accept( *this );
295                                        output << ")";
296                                        break;
297             
298                                  case OT_CONSTANT:
299                                  case OT_LABELADDRESS:
300                                        // there are no intrinsic definitions of 0/1 or label addresses as functions
301                                        assert( false );
302                                }
303                        } else {
304                                varExpr->accept( *this );
305                                output << "(";
306                                genCommaList( applicationExpr->get_args().begin(), applicationExpr->get_args().end() );
307                                output << ")";
308                        } // if
309                } else {
310                        applicationExpr->get_function()->accept( *this );
311                        output << "(";
312                        genCommaList( applicationExpr->get_args().begin(), applicationExpr->get_args().end() );
313                        output << ")";
314                } // if
315        }
316 
317        void CodeGenerator::visit( UntypedExpr *untypedExpr ) {
318                if ( NameExpr *nameExpr = dynamic_cast< NameExpr* >( untypedExpr->get_function() ) ) {
319                        OperatorInfo opInfo;
320                        if ( operatorLookup( nameExpr->get_name(), opInfo ) ) {
321                                std::list< Expression* >::iterator arg = untypedExpr->get_args().begin();
322                                switch ( opInfo.type ) {
323                                  case OT_INDEX:
324                                        assert( untypedExpr->get_args().size() == 2 );
325                                        (*arg++)->accept( *this );
326                                        output << "[";
327                                        (*arg)->accept( *this );
328                                        output << "]";
329                                        break;
330             
331                                  case OT_CALL:
332                                        assert( false );
333                                        break;
334             
335                                  case OT_PREFIX:
336                                  case OT_PREFIXASSIGN:
337                                  case OT_LABELADDRESS:
338                                        assert( untypedExpr->get_args().size() == 1 );
339                                        output << "(";
340                                        output << opInfo.symbol;
341                                        (*arg)->accept( *this );
342                                        output << ")";
343                                        break;
344             
345                                  case OT_POSTFIX:
346                                  case OT_POSTFIXASSIGN:
347                                        assert( untypedExpr->get_args().size() == 1 );
348                                        (*arg)->accept( *this );
349                                        output << opInfo.symbol;
350                                        break;
351 
352                                  case OT_INFIX:
353                                  case OT_INFIXASSIGN:
354                                        assert( untypedExpr->get_args().size() == 2 );
355                                        output << "(";
356                                        (*arg++)->accept( *this );
357                                        output << opInfo.symbol;
358                                        (*arg)->accept( *this );
359                                        output << ")";
360                                        break;
361                                       
362                                  case OT_CONSTANT:
363                                        // there are no intrinsic definitions of 0 or 1 as functions
364                                        assert( false );
365                                }
366                        } else {
367                                nameExpr->accept( *this );
368                                output << "(";
369                                genCommaList( untypedExpr->get_args().begin(), untypedExpr->get_args().end() );
370                                output << ")";
371                        } // if
372                } else {
373                        untypedExpr->get_function()->accept( *this );
374                        output << "(";
375                        genCommaList( untypedExpr->get_args().begin(), untypedExpr->get_args().end() );
376                        output << ")";
377                } // if
378        }
379 
380        void CodeGenerator::visit( NameExpr *nameExpr ) {
381                OperatorInfo opInfo;
382                if ( operatorLookup( nameExpr->get_name(), opInfo ) ) {
383                        assert( opInfo.type == OT_CONSTANT );
384                        output << opInfo.symbol;
385                } else {
386                        output << nameExpr->get_name();
387                } // if
388        }
389 
390        void CodeGenerator::visit( AddressExpr *addressExpr ) {
391                output << "(&";
392                // this hack makes sure that we don't convert "constant_zero" to "0" if we're taking its address
393                if ( VariableExpr *variableExpr = dynamic_cast< VariableExpr* >( addressExpr->get_arg() ) ) {
394                        output << mangleName( variableExpr->get_var() );
395                } else {
396                        addressExpr->get_arg()->accept( *this );
397                } // if
398                output << ")";
399        }
400
401        void CodeGenerator::visit( CastExpr *castExpr ) {
402                output << "((";
403                if ( castExpr->get_results().empty() ) {
404                        output << "void" ;
405                } else {
406                        output << genType( castExpr->get_results().front(), "" );
407                } // if
408                output << ")";
409                castExpr->get_arg()->accept( *this );
410                output << ")";
411        }
412 
413        void CodeGenerator::visit( UntypedMemberExpr *memberExpr ) {
414                assert( false );
415        }
416 
417        void CodeGenerator::visit( MemberExpr *memberExpr ) {
418                memberExpr->get_aggregate()->accept( *this );
419                output << "." << mangleName( memberExpr->get_member() );
420        }
421 
422        void CodeGenerator::visit( VariableExpr *variableExpr ) {
423                OperatorInfo opInfo;
424                if ( variableExpr->get_var()->get_linkage() == LinkageSpec::Intrinsic && operatorLookup( variableExpr->get_var()->get_name(), opInfo ) && opInfo.type == OT_CONSTANT ) {
425                        output << opInfo.symbol;
426                } else {
427                        output << mangleName( variableExpr->get_var() );
428                } // if
429        }
430 
431        void CodeGenerator::visit( ConstantExpr *constantExpr ) {
432                assert( constantExpr->get_constant() );
433                constantExpr->get_constant()->accept( *this );
434        }
435 
436        void CodeGenerator::visit( SizeofExpr *sizeofExpr ) {
437                output << "sizeof(";
438                if ( sizeofExpr->get_isType() ) {
439                        output << genType( sizeofExpr->get_type(), "" );
440                } else {
441                        sizeofExpr->get_expr()->accept( *this );
442                } // if
443                output << ")";
444        }
445 
446        void CodeGenerator::visit( LogicalExpr *logicalExpr ) {
447                output << "(";
448                logicalExpr->get_arg1()->accept( *this );
449                if ( logicalExpr->get_isAnd() ) {
450                        output << " && ";
451                } else {
452                        output << " || ";
453                } // if
454                logicalExpr->get_arg2()->accept( *this );
455                output << ")";
456        }
457 
458        void CodeGenerator::visit( ConditionalExpr *conditionalExpr ) {
459                output << "(";
460                conditionalExpr->get_arg1()->accept( *this );
461                output << " ? ";
462                conditionalExpr->get_arg2()->accept( *this );
463                output << " : ";
464                conditionalExpr->get_arg3()->accept( *this );
465                output << ")";
466        }
467 
468        void CodeGenerator::visit( CommaExpr *commaExpr ) {
469                output << "(";
470                commaExpr->get_arg1()->accept( *this );
471                output << " , ";
472                commaExpr->get_arg2()->accept( *this );
473                output << ")";
474        }
475 
476        void CodeGenerator::visit( TupleExpr *tupleExpr ) {}
477 
478        void CodeGenerator::visit( TypeExpr *typeExpr ) {}
479
480        void CodeGenerator::visit( AsmExpr *asmExpr ) {
481                if ( asmExpr->get_inout() ) {
482                        output << "[ ";
483                        asmExpr->get_inout()->accept( *this );
484                        output << " ] ";
485                } // if
486                asmExpr->get_constraint()->accept( *this );
487                output << " ( ";
488                asmExpr->get_operand()->accept( *this );
489                output << " )";
490        }
491
492        //*** Statements
493        void CodeGenerator::visit( CompoundStmt *compoundStmt ) {
494                std::list<Statement*> ks = compoundStmt->get_kids();
495                output << "{" << endl;
496
497                cur_indent += CodeGenerator::tabsize;
498
499                for ( std::list<Statement *>::iterator i = ks.begin(); i != ks.end();  i++ ) {
500                        output << indent << printLabels( (*i)->get_labels() );
501                        (*i)->accept( *this );
502
503                        output << endl;
504                        if ( wantSpacing( *i ) ) {
505                                output << endl;
506                        }
507                }
508                cur_indent -= CodeGenerator::tabsize; 
509
510                output << indent << "}";
511        }
512
513        void CodeGenerator::visit( ExprStmt *exprStmt ) {
514                // I don't see why this check is necessary.
515                // If this starts to cause problems then put it back in,
516                // with an explanation
517                assert( exprStmt );
518
519                // if ( exprStmt != 0 ) {
520                exprStmt->get_expr()->accept( *this );
521                output << ";" ;
522                // } // if
523        }
524
525        void CodeGenerator::visit( AsmStmt *asmStmt ) {
526                output << "asm ";
527                if ( asmStmt->get_voltile() ) output << "volatile ";
528                if ( ! asmStmt->get_gotolabels().empty()  ) output << "goto ";
529                output << "( ";
530                if ( asmStmt->get_instruction() ) asmStmt->get_instruction()->accept( *this );
531                output << " : ";
532                genCommaList( asmStmt->get_output().begin(), asmStmt->get_output().end() );
533                output << " : ";
534                genCommaList( asmStmt->get_input().begin(), asmStmt->get_input().end() );
535                output << " : ";
536                genCommaList( asmStmt->get_clobber().begin(), asmStmt->get_clobber().end() );
537                if ( ! asmStmt->get_gotolabels().empty() ) {
538                        output << " : ";
539                        for ( std::list<Label>::iterator begin = asmStmt->get_gotolabels().begin();; ) {
540                                output << *begin++;
541                                if ( begin == asmStmt->get_gotolabels().end() ) break;
542                                output << ", ";
543                        } // for
544                } // if
545                output << " );" ;
546        }
547
548        void CodeGenerator::visit( IfStmt *ifStmt ) {
549                output << "if ( ";
550                ifStmt->get_condition()->accept( *this );
551                output << " ) ";
552
553                ifStmt->get_thenPart()->accept( *this );
554
555                if ( ifStmt->get_elsePart() != 0) {
556                        output << " else ";
557                        ifStmt->get_elsePart()->accept( *this );
558                } // if
559        }
560
561        void CodeGenerator::visit( SwitchStmt *switchStmt ) {
562                output << "switch ( " ;
563                switchStmt->get_condition()->accept( *this );
564                output << " ) ";
565               
566                output << "{" << std::endl;
567                cur_indent += CodeGenerator::tabsize;
568
569                acceptAll( switchStmt->get_branches(), *this );
570
571                cur_indent -= CodeGenerator::tabsize;
572
573                output << indent << "}";
574        }
575
576        void CodeGenerator::visit( CaseStmt *caseStmt ) {
577                output << indent;
578                if ( caseStmt->isDefault()) {
579                        output << "default";
580                } else {
581                        output << "case ";
582                        caseStmt->get_condition()->accept( *this );
583                } // if
584                output << ":\n";
585               
586                std::list<Statement *> sts = caseStmt->get_statements();
587
588                cur_indent += CodeGenerator::tabsize;
589                for ( std::list<Statement *>::iterator i = sts.begin(); i != sts.end();  i++) {
590                        output << indent << printLabels( (*i)->get_labels() )  ;
591                        (*i)->accept( *this );
592                        output << endl;
593                }
594                cur_indent -= CodeGenerator::tabsize;
595        }
596
597        void CodeGenerator::visit( BranchStmt *branchStmt ) {
598                switch ( branchStmt->get_type()) {
599                  case BranchStmt::Goto:
600                        if ( ! branchStmt->get_target().empty() )
601                                output << "goto " << branchStmt->get_target();
602                        else { 
603                                if ( branchStmt->get_computedTarget() != 0 ) {
604                                        output << "goto *";
605                                        branchStmt->get_computedTarget()->accept( *this );
606                                } // if
607                        } // if
608                        break;
609                  case BranchStmt::Break:
610                        output << "break";
611                        break;
612                  case BranchStmt::Continue:
613                        output << "continue";
614                        break;
615                }
616                output << ";";
617        }
618
619
620        void CodeGenerator::visit( ReturnStmt *returnStmt ) {
621                output << "return ";
622
623                // xxx -- check for null expression;
624                if ( returnStmt->get_expr() ) {
625                        returnStmt->get_expr()->accept( *this );
626                } // if
627                output << ";";
628        }
629
630        void CodeGenerator::visit( WhileStmt *whileStmt ) {
631                if ( whileStmt->get_isDoWhile() )
632                        output << "do" ;
633                else {
634                        output << "while (" ;
635                        whileStmt->get_condition()->accept( *this );
636                        output << ")";
637                } // if
638                output << " ";
639
640                output << CodeGenerator::printLabels( whileStmt->get_body()->get_labels() );
641                whileStmt->get_body()->accept( *this );
642
643                output << indent;
644
645                if ( whileStmt->get_isDoWhile() ) {
646                        output << " while (" ;
647                        whileStmt->get_condition()->accept( *this );
648                        output << ");";
649                } // if
650        }
651
652        void CodeGenerator::visit( ForStmt *forStmt ) {
653                // initialization is always hoisted, so don't
654                // bother doing anything with that
655                output << "for (;";
656
657                if ( forStmt->get_condition() != 0 )
658                        forStmt->get_condition()->accept( *this );
659                output << ";";
660
661                if ( forStmt->get_increment() != 0 )
662                        forStmt->get_increment()->accept( *this );
663                output << ") ";
664
665                if ( forStmt->get_body() != 0 ) {
666                        output << CodeGenerator::printLabels( forStmt->get_body()->get_labels() );
667                        forStmt->get_body()->accept( *this );
668                } // if
669        }
670
671        void CodeGenerator::visit( NullStmt *nullStmt ) {
672                //output << indent << CodeGenerator::printLabels( nullStmt->get_labels() );
673                output << "/* null statement */ ;";
674        }
675
676        void CodeGenerator::visit( DeclStmt *declStmt ) {
677                declStmt->get_decl()->accept( *this );
678       
679                if ( doSemicolon( declStmt->get_decl() ) ) {
680                        output << ";";
681                } // if
682        }
683
684        std::string CodeGenerator::printLabels( std::list< Label > &l ) {
685                std::string str( "" );
686                l.unique(); // assumes a sorted list. Why not use set?
687
688                for ( std::list< Label >::iterator i = l.begin(); i != l.end(); i++ )
689                        str += *i + ": ";
690
691                return str;
692        }
693
694        void CodeGenerator::handleStorageClass( Declaration *decl ) {
695                switch ( decl->get_storageClass() ) {
696                  case DeclarationNode::Extern:
697                        output << "extern ";
698                        break;
699                  case DeclarationNode::Static:
700                        output << "static ";
701                        break;
702                  case DeclarationNode::Auto:
703                        // silently drop storage class
704                        break;
705                  case DeclarationNode::Register:
706                        output << "register ";
707                        break;
708                  case DeclarationNode::Inline:
709                        output << "inline ";
710                        break;
711                  case DeclarationNode::Fortran:
712                        output << "fortran ";
713                        break;
714                  case DeclarationNode::Noreturn:
715                        output << "_Noreturn ";
716                        break;
717                  case DeclarationNode::Threadlocal:
718                        output << "_Thread_local ";
719                        break;
720                  case DeclarationNode::NoStorageClass:
721                        break;
722                } // switch
723        }
724} // namespace CodeGen
725
726// Local Variables: //
727// tab-width: 4 //
728// mode: c++ //
729// compile-command: "make install" //
730// End: //
Note: See TracBrowser for help on using the repository browser.