Changeset 7baed7d
- Timestamp:
- Jun 6, 2016, 5:46:09 PM (8 years ago)
- 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
- Location:
- src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r64071c2 r7baed7d 26 26 #include "SynTree/Statement.h" 27 27 #include "SynTree/Type.h" 28 #include "SynTree/Attribute.h" 28 29 29 30 #include "Common/utility.h" … … 76 77 } 77 78 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 78 95 //*** Declarations 79 96 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 100 99 handleStorageClass( functionDecl ); 101 100 if ( functionDecl->get_isInline() ) { -
src/CodeGen/CodeGenerator.h
r64071c2 r7baed7d 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // CodeGenerator.h -- 7 // CodeGenerator.h -- 8 8 // 9 9 // Author : Richard C. Bilson … … 60 60 virtual void visit( MemberExpr *memberExpr ); 61 61 virtual void visit( VariableExpr *variableExpr ); 62 virtual void visit( ConstantExpr *constantExpr ); 62 virtual void visit( ConstantExpr *constantExpr ); 63 63 virtual void visit( SizeofExpr *sizeofExpr ); 64 64 virtual void visit( AlignofExpr *alignofExpr ); … … 85 85 virtual void visit( ForStmt * ); 86 86 virtual void visit( NullStmt * ); 87 virtual void visit( DeclStmt * ); 87 virtual void visit( DeclStmt * ); 88 89 void genAttributes( std::list< Attribute * > & attributes ); 88 90 89 91 template< class Iterator > void genCommaList( Iterator begin, Iterator end ); … … 108 110 109 111 }; 110 112 111 113 template< class Iterator > 112 114 void CodeGenerator::genCommaList( Iterator begin, Iterator end ) { … … 119 121 } // for 120 122 } 121 123 122 124 inline bool doSemicolon( Declaration* decl ) { 123 125 if ( FunctionDecl* func = dynamic_cast< FunctionDecl* >( decl ) ) { -
src/InitTweak/FixGlobalInit.cc
r64071c2 r7baed7d 22 22 #include "SynTree/Initializer.h" 23 23 #include "SynTree/Visitor.h" 24 #include "SynTree/Attribute.h" 24 25 #include <algorithm> 25 26 … … 116 117 GlobalFixer::GlobalFixer( const std::string & name, bool inLibrary ) : tempNamer( "_global_init" ) { 117 118 std::string fixedName = globalFunctionName( name ); 118 initFunction = new FunctionDecl( "_init_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false, FunctionDecl::Attribute( FunctionDecl::Attribute::Constructor, inLibrary ? FunctionDecl::Attribute::High : FunctionDecl::Attribute::Default ) ); 119 120 destroyFunction = new FunctionDecl( "_destroy_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false, FunctionDecl::Attribute( FunctionDecl::Attribute::Destructor, inLibrary ? FunctionDecl::Attribute::High : FunctionDecl::Attribute::Default ) ); 119 std::list< Expression * > ctorParameters; 120 std::list< Expression * > dtorParameters; 121 if ( inLibrary ) { 122 // Constructor/destructor attributes take a single parameter which 123 // is the priority, with lower numbers meaning higher priority. 124 // Functions specified with priority are guaranteed to run before 125 // functions without a priority. To ensure that constructors and destructors 126 // for library code are run before constructors and destructors for user code, 127 // specify a priority when building the library. Priorities 0-100 are reserved by gcc. 128 ctorParameters.push_back( new ConstantExpr( Constant::from_int( 101 ) ) ); 129 dtorParameters.push_back( new ConstantExpr( Constant::from_int( 101 ) ) ); 130 } 131 initFunction = new FunctionDecl( "_init_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false ); 132 initFunction->get_attributes().push_back( new Attribute( "constructor", ctorParameters ) ); 133 destroyFunction = new FunctionDecl( "_destroy_" + fixedName, DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false ); 134 destroyFunction->get_attributes().push_back( new Attribute( "destructor", dtorParameters ) ); 121 135 } 122 136 -
src/Makefile.in
r64071c2 r7baed7d 195 195 SynTree/driver_cfa_cpp-Mutator.$(OBJEXT) \ 196 196 SynTree/driver_cfa_cpp-TypeSubstitution.$(OBJEXT) \ 197 SynTree/driver_cfa_cpp-Attribute.$(OBJEXT) \ 197 198 Tuples/driver_cfa_cpp-Mutate.$(OBJEXT) \ 198 199 Tuples/driver_cfa_cpp-AssignExpand.$(OBJEXT) \ … … 383 384 SynTree/NamedTypeDecl.cc SynTree/TypeDecl.cc \ 384 385 SynTree/Initializer.cc SynTree/Visitor.cc SynTree/Mutator.cc \ 385 SynTree/TypeSubstitution.cc Tuples/Mutate.cc \386 Tuples/ AssignExpand.cc Tuples/FunctionFixer.cc \387 Tuples/ TupleAssignment.cc Tuples/FunctionChecker.cc \388 Tuples/ NameMatcher.cc386 SynTree/TypeSubstitution.cc SynTree/Attribute.cc \ 387 Tuples/Mutate.cc Tuples/AssignExpand.cc \ 388 Tuples/FunctionFixer.cc Tuples/TupleAssignment.cc \ 389 Tuples/FunctionChecker.cc Tuples/NameMatcher.cc 389 390 MAINTAINERCLEANFILES = Parser/parser.output ${libdir}/${notdir \ 390 391 ${cfa_cpplib_PROGRAMS}} … … 755 756 SynTree/driver_cfa_cpp-TypeSubstitution.$(OBJEXT): \ 756 757 SynTree/$(am__dirstamp) SynTree/$(DEPDIR)/$(am__dirstamp) 758 SynTree/driver_cfa_cpp-Attribute.$(OBJEXT): SynTree/$(am__dirstamp) \ 759 SynTree/$(DEPDIR)/$(am__dirstamp) 757 760 Tuples/$(am__dirstamp): 758 761 @$(MKDIR_P) Tuples … … 852 855 -rm -f SynTree/driver_cfa_cpp-ArrayType.$(OBJEXT) 853 856 -rm -f SynTree/driver_cfa_cpp-AttrType.$(OBJEXT) 857 -rm -f SynTree/driver_cfa_cpp-Attribute.$(OBJEXT) 854 858 -rm -f SynTree/driver_cfa_cpp-BasicType.$(OBJEXT) 855 859 -rm -f SynTree/driver_cfa_cpp-CommaExpr.$(OBJEXT) … … 961 965 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-ArrayType.Po@am__quote@ 962 966 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-AttrType.Po@am__quote@ 967 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-Attribute.Po@am__quote@ 963 968 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-BasicType.Po@am__quote@ 964 969 @AMDEP_TRUE@@am__include@ @am__quote@SynTree/$(DEPDIR)/driver_cfa_cpp-CommaExpr.Po@am__quote@ … … 2396 2401 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2397 2402 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-TypeSubstitution.obj `if test -f 'SynTree/TypeSubstitution.cc'; then $(CYGPATH_W) 'SynTree/TypeSubstitution.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/TypeSubstitution.cc'; fi` 2403 2404 SynTree/driver_cfa_cpp-Attribute.o: SynTree/Attribute.cc 2405 @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SynTree/driver_cfa_cpp-Attribute.o -MD -MP -MF SynTree/$(DEPDIR)/driver_cfa_cpp-Attribute.Tpo -c -o SynTree/driver_cfa_cpp-Attribute.o `test -f 'SynTree/Attribute.cc' || echo '$(srcdir)/'`SynTree/Attribute.cc 2406 @am__fastdepCXX_TRUE@ $(am__mv) SynTree/$(DEPDIR)/driver_cfa_cpp-Attribute.Tpo SynTree/$(DEPDIR)/driver_cfa_cpp-Attribute.Po 2407 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='SynTree/Attribute.cc' object='SynTree/driver_cfa_cpp-Attribute.o' libtool=no @AMDEPBACKSLASH@ 2408 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2409 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-Attribute.o `test -f 'SynTree/Attribute.cc' || echo '$(srcdir)/'`SynTree/Attribute.cc 2410 2411 SynTree/driver_cfa_cpp-Attribute.obj: SynTree/Attribute.cc 2412 @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT SynTree/driver_cfa_cpp-Attribute.obj -MD -MP -MF SynTree/$(DEPDIR)/driver_cfa_cpp-Attribute.Tpo -c -o SynTree/driver_cfa_cpp-Attribute.obj `if test -f 'SynTree/Attribute.cc'; then $(CYGPATH_W) 'SynTree/Attribute.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/Attribute.cc'; fi` 2413 @am__fastdepCXX_TRUE@ $(am__mv) SynTree/$(DEPDIR)/driver_cfa_cpp-Attribute.Tpo SynTree/$(DEPDIR)/driver_cfa_cpp-Attribute.Po 2414 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='SynTree/Attribute.cc' object='SynTree/driver_cfa_cpp-Attribute.obj' libtool=no @AMDEPBACKSLASH@ 2415 @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ 2416 @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o SynTree/driver_cfa_cpp-Attribute.obj `if test -f 'SynTree/Attribute.cc'; then $(CYGPATH_W) 'SynTree/Attribute.cc'; else $(CYGPATH_W) '$(srcdir)/SynTree/Attribute.cc'; fi` 2398 2417 2399 2418 Tuples/driver_cfa_cpp-Mutate.o: Tuples/Mutate.cc -
src/SynTree/Declaration.h
r64071c2 r7baed7d 115 115 typedef DeclarationWithType Parent; 116 116 public: 117 // temporary - merge this into general GCC attributes 118 struct Attribute { 119 enum Type { 120 NoAttribute, Constructor, Destructor, 121 } type; 122 enum Priority { 123 // priorities 0-100 are reserved by gcc, so it's okay to use 100 an exceptional case 124 Default = 100, High, 125 } priority; 126 Attribute(Type t = NoAttribute, Priority p = Default) : type(t), priority(p) {}; 127 }; 128 129 FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, Attribute attribute = Attribute() ); 117 FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, const std::list< Attribute * > attributes = std::list< Attribute * >() ); 130 118 FunctionDecl( const FunctionDecl &other ); 131 119 virtual ~FunctionDecl(); … … 140 128 std::list< std::string >& get_oldIdents() { return oldIdents; } 141 129 std::list< Declaration* >& get_oldDecls() { return oldDecls; } 142 Attribute get_attribute() const { return attribute; } 143 void set_attribute( Attribute newValue ) { attribute = newValue; } 130 std::list< Attribute * >& get_attributes() { return attributes; } 144 131 145 132 virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); } … … 153 140 std::list< std::string > oldIdents; 154 141 std::list< Declaration* > oldDecls; 155 Attribute attribute;142 std::list< Attribute * > attributes; 156 143 }; 157 144 -
src/SynTree/FunctionDecl.cc
r64071c2 r7baed7d 19 19 #include "Statement.h" 20 20 #include "Type.h" 21 #include "Attribute.h" 21 22 #include "Common/utility.h" 22 23 23 FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, Attribute attribute)24 : Parent( name, sc, linkage ), type( type ), statements( statements ), attribute ( attribute) {24 FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, std::list< Attribute * > attributes ) 25 : Parent( name, sc, linkage ), type( type ), statements( statements ), attributes( attributes ) { 25 26 set_isInline( isInline ); 26 27 set_isNoreturn( isNoreturn ); … … 32 33 33 34 FunctionDecl::FunctionDecl( const FunctionDecl &other ) 34 : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ), attribute( other.attribute ) { 35 : Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ) { 36 cloneAll( other.attributes, attributes ); 35 37 } 36 38 … … 38 40 delete type; 39 41 delete statements; 42 deleteAll( attributes ); 40 43 } 41 44 … … 65 68 os << "_Noreturn "; 66 69 } // if 67 switch ( attribute.type ) { 68 case Attribute::Constructor: 69 os << "Global Constructor "; 70 break; 71 case Attribute::Destructor: 72 os << "Global Destructor "; 73 break; 74 default: 75 break; 76 } 77 if ( attribute.priority != Attribute::Default ) { 78 os << "with priority " << attribute.priority << " "; 79 } 70 71 printAll( attributes, os, indent ); 72 80 73 if ( get_storageClass() != DeclarationNode::NoStorageClass ) { 81 74 os << DeclarationNode::storageName[ get_storageClass() ] << ' '; … … 118 111 os << "_Noreturn "; 119 112 } // if 120 switch ( attribute.type ) { 121 case Attribute::Constructor: 122 os << " Global Constructor "; 123 break; 124 case Attribute::Destructor: 125 os << " Global Destructor "; 126 break; 127 default: 128 break; 129 } 130 if ( attribute.priority != Attribute::Default ) { 131 os << "with priority " << attribute.priority << " "; 132 } 113 114 // xxx - should printShort print attributes? 115 133 116 if ( get_storageClass() != DeclarationNode::NoStorageClass ) { 134 117 os << DeclarationNode::storageName[ get_storageClass() ] << ' '; -
src/SynTree/SynTree.h
r64071c2 r7baed7d 118 118 class TypeSubstitution; 119 119 120 // gcc attribute 121 class Attribute; 122 120 123 #endif // SYNTREE_H 121 124 -
src/SynTree/module.mk
r64071c2 r7baed7d 6 6 ## file "LICENCE" distributed with Cforall. 7 7 ## 8 ## module.mk -- 8 ## module.mk -- 9 9 ## 10 10 ## Author : Richard C. Bilson … … 46 46 SynTree/Visitor.cc \ 47 47 SynTree/Mutator.cc \ 48 SynTree/TypeSubstitution.cc 48 SynTree/TypeSubstitution.cc \ 49 SynTree/Attribute.cc 49 50
Note: See TracChangeset
for help on using the changeset viewer.