Changeset 39f04ec for src/CodeGen/CodeGenerator.cc
- Timestamp:
- Jul 5, 2016, 11:10:14 AM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, 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:
- 9bb81bb8
- Parents:
- a43e1d7 (diff), d32c4e2 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
ra43e1d7 r39f04ec 10 10 // Created On : Mon May 18 07:44:20 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jun 9 13:21:00201613 // Update Count : 25612 // Last Modified On : Mon Jul 4 20:38:32 2016 13 // Update Count : 300 14 14 // 15 15 … … 47 47 dynamic_cast< WhileStmt * >( stmt ) || dynamic_cast< ForStmt * > ( stmt ) || dynamic_cast< SwitchStmt *>( stmt ); 48 48 } 49 50 void CodeGenerator::extension( Expression *expr ) { 51 if ( expr->get_extension() ) { 52 output << "__extension__ "; 53 } // if 54 } // extension 55 56 void CodeGenerator::extension( Declaration *decl ) { 57 if ( decl->get_extension() ) { 58 output << "__extension__ "; 59 } // if 60 } // extension 49 61 50 62 ostream & CodeGenerator::Indenter::operator()( ostream & output ) const { … … 110 122 //*** Declarations 111 123 void CodeGenerator::visit( FunctionDecl *functionDecl ) { 124 extension( functionDecl ); 112 125 genAttributes( functionDecl->get_attributes() ); 113 126 … … 134 147 135 148 void CodeGenerator::visit( ObjectDecl *objectDecl ) { 149 extension( objectDecl ); 136 150 handleStorageClass( objectDecl ); 137 151 output << genType( objectDecl->get_type(), mangleName( objectDecl ) ); … … 170 184 171 185 void CodeGenerator::visit( StructDecl *structDecl ) { 186 extension( structDecl ); 172 187 output << "struct "; 173 188 handleAggregate( structDecl ); 174 189 } 175 190 176 void CodeGenerator::visit( UnionDecl *aggregateDecl ) { 191 void CodeGenerator::visit( UnionDecl *unionDecl ) { 192 extension( unionDecl ); 177 193 output << "union "; 178 handleAggregate( aggregateDecl ); 179 } 180 181 void CodeGenerator::visit( EnumDecl *aggDecl ) { 194 handleAggregate( unionDecl ); 195 } 196 197 void CodeGenerator::visit( EnumDecl *enumDecl ) { 198 extension( enumDecl ); 182 199 output << "enum "; 183 200 184 if ( aggDecl->get_name() != "" )185 output << aggDecl->get_name();186 187 std::list< Declaration* > &memb = aggDecl->get_members();201 if ( enumDecl->get_name() != "" ) 202 output << enumDecl->get_name(); 203 204 std::list< Declaration* > &memb = enumDecl->get_members(); 188 205 189 206 if ( ! memb.empty() ) { … … 208 225 } 209 226 210 void CodeGenerator::visit( TraitDecl * aggregateDecl ) {}227 void CodeGenerator::visit( TraitDecl *traitDecl ) {} 211 228 212 229 void CodeGenerator::visit( TypedefDecl *typeDecl ) { 213 output << "typedef "; 214 output << genType( typeDecl->get_base(), typeDecl->get_name() ); 230 assert( false && "Typedefs are removed and substituted in earlier passes." ); 231 //output << "typedef "; 232 //output << genType( typeDecl->get_base(), typeDecl->get_name() ); 215 233 } 216 234 … … 218 236 // really, we should mutate this into something that isn't a TypeDecl but that requires large-scale changes, 219 237 // still to be done 238 extension( typeDecl ); 220 239 output << "extern unsigned long " << typeDecl->get_name(); 221 240 if ( typeDecl->get_base() ) { … … 251 270 output << "{ "; 252 271 if ( init->begin_initializers() == init->end_initializers() ) { 253 // illegal to leave initializer list empty for scalar initializers, 254 // but always legal to have 0 272 // illegal to leave initializer list empty for scalar initializers, but always legal to have 0 255 273 output << "0"; 256 274 } else { … … 317 335 case OT_DTOR: 318 336 if ( applicationExpr->get_args().size() == 1 ) { 319 // the expression fed into a single parameter constructor or destructor 320 // may contain sideeffects, so must still output this expression337 // the expression fed into a single parameter constructor or destructor may contain side 338 // effects, so must still output this expression 321 339 output << "("; 322 340 (*arg++)->accept( *this ); … … 403 421 case OT_DTOR: 404 422 if ( untypedExpr->get_args().size() == 1 ) { 405 // the expression fed into a single parameter constructor or destructor 406 // may contain sideeffects, so must still output this expression423 // the expression fed into a single parameter constructor or destructor may contain side 424 // effects, so must still output this expression 407 425 output << "("; 408 426 (*arg++)->accept( *this ); … … 500 518 output << ")"; 501 519 } else { 502 // otherwise, the cast is to an lvalue type, so the cast 503 // should be dropped, since the result of a cast is 520 // otherwise, the cast is to an lvalue type, so the cast should be dropped, since the result of a cast is 504 521 // never an lvalue in C 505 522 } … … 546 563 547 564 void CodeGenerator::visit( AlignofExpr *alignofExpr ) { 565 // use GCC extension to avoid bumping std to C11 548 566 extension( alignofExpr ); 549 // use GCC extension to avoid bumping std to C11550 567 output << "__alignof__("; 551 568 if ( alignofExpr->get_isType() ) { … … 558 575 559 576 void CodeGenerator::visit( UntypedOffsetofExpr *offsetofExpr ) { 560 assert( false && "UntypedOffsetofExpr should not reach code generation " );577 assert( false && "UntypedOffsetofExpr should not reach code generation." ); 561 578 } 562 579 563 580 void CodeGenerator::visit( OffsetofExpr *offsetofExpr ) { 564 extension( offsetofExpr );565 581 // use GCC builtin 566 582 output << "__builtin_offsetof("; … … 571 587 572 588 void CodeGenerator::visit( OffsetPackExpr *offsetPackExpr ) { 573 assert( false && "OffsetPackExpr should not reach code generation " );589 assert( false && "OffsetPackExpr should not reach code generation." ); 574 590 } 575 591 … … 612 628 613 629 void CodeGenerator::visit( AsmExpr *asmExpr ) { 614 extension( asmExpr );615 630 if ( asmExpr->get_inout() ) { 616 631 output << "[ "; … … 777 792 778 793 void CodeGenerator::visit( ForStmt *forStmt ) { 779 // initialization is always hoisted, so don't 780 // bother doing anything with that 794 // initialization is always hoisted, so don't bother doing anything with that 781 795 output << "for (;"; 782 796
Note: See TracChangeset
for help on using the changeset viewer.