Changeset 7baed7d for src/CodeGen


Ignore:
Timestamp:
Jun 6, 2016, 5:46:09 PM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
64a32c6
Parents:
64071c2
Message:

generalize notion of a GCC attribute

Location:
src/CodeGen
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    r64071c2 r7baed7d  
    2626#include "SynTree/Statement.h"
    2727#include "SynTree/Type.h"
     28#include "SynTree/Attribute.h"
    2829
    2930#include "Common/utility.h"
     
    7677        }
    7778
     79        void CodeGenerator::genAttributes( std::list< Attribute * > & attributes ) {
     80                if ( ! attributes.empty() ) {
     81                        output << "__attribute__ ((";
     82                        for ( Attribute *& attr : attributes ) {
     83                                if ( ! attr->empty() ) {
     84                                        output << attr->get_name() << "(";
     85                                        genCommaList( attr->get_parameters().begin(), attr->get_parameters().end() );
     86                                        output << ")";
     87                                }
     88                                output << ",";
     89                        }
     90                        output << ")) ";
     91                }
     92        }
     93
     94
    7895        //*** Declarations
    7996        void CodeGenerator::visit( FunctionDecl *functionDecl ) {
    80                 // generalize this
    81                 FunctionDecl::Attribute attr = functionDecl->get_attribute();
    82                 switch ( attr.type ) {
    83                         case FunctionDecl::Attribute::Constructor:
    84                                 output << "__attribute__ ((constructor";
    85                                 if ( attr.priority != FunctionDecl::Attribute::Default ) {
    86                                         output << "(" << attr.priority << ")";
    87                                 }
    88                                 output << ")) ";
    89                                 break;
    90                         case FunctionDecl::Attribute::Destructor:
    91                                 output << "__attribute__ ((destructor";
    92                                 if ( attr.priority != FunctionDecl::Attribute::Default ) {
    93                                         output << "(" << attr.priority << ")";
    94                                 }
    95                                 output << ")) ";
    96                                 break;
    97                         default:
    98                                 break;
    99                 }
     97                genAttributes( functionDecl->get_attributes() );
     98
    10099                handleStorageClass( functionDecl );
    101100                if ( functionDecl->get_isInline() ) {
  • src/CodeGen/CodeGenerator.h

    r64071c2 r7baed7d  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // CodeGenerator.h -- 
     7// CodeGenerator.h --
    88//
    99// Author           : Richard C. Bilson
     
    6060                virtual void visit( MemberExpr *memberExpr );
    6161                virtual void visit( VariableExpr *variableExpr );
    62                 virtual void visit( ConstantExpr *constantExpr ); 
     62                virtual void visit( ConstantExpr *constantExpr );
    6363                virtual void visit( SizeofExpr *sizeofExpr );
    6464                virtual void visit( AlignofExpr *alignofExpr );
     
    8585                virtual void visit( ForStmt * );
    8686                virtual void visit( NullStmt * );
    87                 virtual void visit( DeclStmt * );
     87                virtual void visit( DeclStmt * );
     88
     89                void genAttributes( std::list< Attribute * > & attributes );
    8890
    8991                template< class Iterator > void genCommaList( Iterator begin, Iterator end );
     
    108110
    109111        };
    110        
     112
    111113        template< class Iterator >
    112114        void CodeGenerator::genCommaList( Iterator begin, Iterator end ) {
     
    119121                } // for
    120122        }
    121  
     123
    122124        inline bool doSemicolon( Declaration* decl ) {
    123125                if ( FunctionDecl* func = dynamic_cast< FunctionDecl* >( decl ) ) {
Note: See TracChangeset for help on using the changeset viewer.