Changeset 58fe85a for src/SymTab/Mangler.cc
- Timestamp:
- Jan 7, 2021, 3:27:00 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 2b4daf2, 64aeca0
- Parents:
- 3c64c668 (diff), eef8dfb (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
-
src/SymTab/Mangler.cc (modified) (42 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Mangler.cc
r3c64c668 r58fe85a 10 10 // Created On : Sun May 17 21:40:29 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sat Feb 15 13:55:12202013 // Update Count : 3312 // Last Modified On : Wed Nov 18 12:01:38 2020 13 // Update Count : 64 14 14 // 15 15 #include "Mangler.h" … … 65 65 void postvisit( const QualifiedType * qualType ); 66 66 67 std::string get_mangleName() { return mangleName .str(); }67 std::string get_mangleName() { return mangleName; } 68 68 private: 69 std:: ostringstream mangleName;///< Mangled name being constructed69 std::string mangleName; ///< Mangled name being constructed 70 70 typedef std::map< std::string, std::pair< int, int > > VarMapType; 71 71 VarMapType varNums; ///< Map of type variables to indices … … 127 127 isTopLevel = false; 128 128 } // if 129 mangleName <<Encoding::manglePrefix;129 mangleName += Encoding::manglePrefix; 130 130 const CodeGen::OperatorInfo * opInfo = CodeGen::operatorLookup( declaration->get_name() ); 131 131 if ( opInfo ) { 132 mangleName << opInfo->outputName.size() <<opInfo->outputName;132 mangleName += std::to_string( opInfo->outputName.size() ) + opInfo->outputName; 133 133 } else { 134 mangleName << declaration->name.size() <<declaration->name;134 mangleName += std::to_string( declaration->name.size() ) + declaration->name; 135 135 } // if 136 136 maybeAccept( declaration->get_type(), *visitor ); … … 139 139 // so they need a different name mangling 140 140 if ( declaration->get_linkage() == LinkageSpec::AutoGen ) { 141 mangleName <<Encoding::autogen;141 mangleName += Encoding::autogen; 142 142 } else if ( declaration->get_linkage() == LinkageSpec::Intrinsic ) { 143 mangleName <<Encoding::intrinsic;143 mangleName += Encoding::intrinsic; 144 144 } else { 145 145 // if we add another kind of overridable function, this has to change … … 160 160 void Mangler_old::postvisit( const VoidType * voidType ) { 161 161 printQualifiers( voidType ); 162 mangleName <<Encoding::void_t;162 mangleName += Encoding::void_t; 163 163 } 164 164 … … 166 166 printQualifiers( basicType ); 167 167 assertf( basicType->kind < BasicType::NUMBER_OF_BASIC_TYPES, "Unhandled basic type: %d", basicType->kind ); 168 mangleName <<Encoding::basicTypes[ basicType->kind ];168 mangleName += Encoding::basicTypes[ basicType->kind ]; 169 169 } 170 170 … … 172 172 printQualifiers( pointerType ); 173 173 // mangle void (*f)() and void f() to the same name to prevent overloading on functions and function pointers 174 if ( ! dynamic_cast<FunctionType *>( pointerType->base ) ) mangleName <<Encoding::pointer;174 if ( ! dynamic_cast<FunctionType *>( pointerType->base ) ) mangleName += Encoding::pointer; 175 175 maybeAccept( pointerType->base, *visitor ); 176 176 } … … 179 179 // TODO: encode dimension 180 180 printQualifiers( arrayType ); 181 mangleName << Encoding::array <<"0";181 mangleName += Encoding::array + "0"; 182 182 maybeAccept( arrayType->base, *visitor ); 183 183 } … … 204 204 void Mangler_old::postvisit( const FunctionType * functionType ) { 205 205 printQualifiers( functionType ); 206 mangleName <<Encoding::function;206 mangleName += Encoding::function; 207 207 // turn on inFunctionType so that printQualifiers does not print most qualifiers for function parameters, 208 208 // since qualifiers on outermost parameter type do not differentiate function types, e.g., … … 211 211 inFunctionType = true; 212 212 std::list< Type* > returnTypes = getTypes( functionType->returnVals ); 213 if (returnTypes.empty()) mangleName <<Encoding::void_t;213 if (returnTypes.empty()) mangleName += Encoding::void_t; 214 214 else acceptAll( returnTypes, *visitor ); 215 mangleName <<"_";215 mangleName += "_"; 216 216 std::list< Type* > paramTypes = getTypes( functionType->parameters ); 217 217 acceptAll( paramTypes, *visitor ); 218 mangleName <<"_";218 mangleName += "_"; 219 219 } 220 220 … … 222 222 printQualifiers( refType ); 223 223 224 mangleName << prefix << refType->name.length() <<refType->name;224 mangleName += prefix + std::to_string( refType->name.length() ) + refType->name; 225 225 226 226 if ( mangleGenericParams ) { 227 227 const std::list< Expression* > & params = refType->parameters; 228 228 if ( ! params.empty() ) { 229 mangleName <<"_";229 mangleName += "_"; 230 230 for ( const Expression * param : params ) { 231 231 const TypeExpr * paramType = dynamic_cast< const TypeExpr * >( param ); … … 233 233 maybeAccept( paramType->type, *visitor ); 234 234 } 235 mangleName <<"_";235 mangleName += "_"; 236 236 } 237 237 } … … 262 262 // are first found and prefixing with the appropriate encoding for the type class. 263 263 assertf( varNum->second.second < TypeDecl::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", varNum->second.second ); 264 mangleName << Encoding::typeVariables[varNum->second.second] << varNum->second.first;264 mangleName += Encoding::typeVariables[varNum->second.second] + std::to_string( varNum->second.first ); 265 265 } // if 266 266 } … … 268 268 void Mangler_old::postvisit( const TraitInstType * inst ) { 269 269 printQualifiers( inst ); 270 mangleName << inst->name.size() <<inst->name;270 mangleName += std::to_string( inst->name.size() ) + inst->name; 271 271 } 272 272 273 273 void Mangler_old::postvisit( const TupleType * tupleType ) { 274 274 printQualifiers( tupleType ); 275 mangleName << Encoding::tuple << tupleType->types.size();275 mangleName += Encoding::tuple + std::to_string( tupleType->types.size() ); 276 276 acceptAll( tupleType->types, *visitor ); 277 277 } … … 280 280 printQualifiers( varArgsType ); 281 281 static const std::string vargs = "__builtin_va_list"; 282 mangleName << Encoding::type << vargs.size() <<vargs;282 mangleName += Encoding::type + std::to_string( vargs.size() ) + vargs; 283 283 } 284 284 285 285 void Mangler_old::postvisit( const ZeroType * ) { 286 mangleName <<Encoding::zero;286 mangleName += Encoding::zero; 287 287 } 288 288 289 289 void Mangler_old::postvisit( const OneType * ) { 290 mangleName <<Encoding::one;290 mangleName += Encoding::one; 291 291 } 292 292 … … 296 296 // N marks the start of a qualified type 297 297 inQualifiedType = true; 298 mangleName <<Encoding::qualifiedTypeStart;298 mangleName += Encoding::qualifiedTypeStart; 299 299 } 300 300 maybeAccept( qualType->parent, *visitor ); … … 303 303 // E marks the end of a qualified type 304 304 inQualifiedType = false; 305 mangleName <<Encoding::qualifiedTypeEnd;305 mangleName += Encoding::qualifiedTypeEnd; 306 306 } 307 307 } … … 315 315 assertf(false, "Mangler_old should not visit typedecl: %s", toCString(decl)); 316 316 assertf( decl->kind < TypeDecl::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", decl->kind ); 317 mangleName << Encoding::typeVariables[ decl->kind ] << ( decl->name.length() ) <<decl->name;317 mangleName += Encoding::typeVariables[ decl->kind ] + std::to_string( decl->name.length() ) + decl->name; 318 318 } 319 319 … … 330 330 std::list< std::string > assertionNames; 331 331 int dcount = 0, fcount = 0, vcount = 0, acount = 0; 332 mangleName <<Encoding::forall;332 mangleName += Encoding::forall; 333 333 for ( const TypeDecl * i : type->forall ) { 334 334 switch ( i->kind ) { … … 354 354 } // for 355 355 } // for 356 mangleName << dcount << "_" << fcount << "_" << vcount << "_" << acount << "_"; 357 std::copy( assertionNames.begin(), assertionNames.end(), std::ostream_iterator< std::string >( mangleName, "" ) ); 358 mangleName << "_"; 356 mangleName += std::to_string( dcount ) + "_" + std::to_string( fcount ) + "_" + std::to_string( vcount ) + "_" + std::to_string( acount ) + "_"; 357 for(const auto & a : assertionNames) mangleName += a; 358 // std::copy( assertionNames.begin(), assertionNames.end(), std::ostream_iterator< std::string >( mangleName, "" ) ); 359 mangleName += "_"; 359 360 } // if 360 361 if ( ! inFunctionType ) { 361 362 // these qualifiers do not distinguish the outermost type of a function parameter 362 363 if ( type->get_const() ) { 363 mangleName <<Encoding::qualifiers.at(Type::Const);364 mangleName += Encoding::qualifiers.at(Type::Const); 364 365 } // if 365 366 if ( type->get_volatile() ) { 366 mangleName <<Encoding::qualifiers.at(Type::Volatile);367 mangleName += Encoding::qualifiers.at(Type::Volatile); 367 368 } // if 368 369 // Removed due to restrict not affecting function compatibility in GCC 369 370 // if ( type->get_isRestrict() ) { 370 // mangleName <<"E";371 // mangleName += "E"; 371 372 // } // if 372 373 if ( type->get_atomic() ) { 373 mangleName <<Encoding::qualifiers.at(Type::Atomic);374 mangleName += Encoding::qualifiers.at(Type::Atomic); 374 375 } // if 375 376 } 376 377 if ( type->get_mutex() ) { 377 mangleName <<Encoding::qualifiers.at(Type::Mutex);378 mangleName += Encoding::qualifiers.at(Type::Mutex); 378 379 } // if 379 380 if ( inFunctionType ) { … … 383 384 } 384 385 } 385 } // namespace386 } // namespace 386 387 } // namespace Mangler 387 388 } // namespace SymTab … … 417 418 void postvisit( const ast::QualifiedType * qualType ); 418 419 419 std::string get_mangleName() { return mangleName .str(); }420 std::string get_mangleName() { return mangleName; } 420 421 private: 421 std:: ostringstream mangleName;///< Mangled name being constructed422 std::string mangleName; ///< Mangled name being constructed 422 423 typedef std::map< std::string, std::pair< int, int > > VarMapType; 423 424 VarMapType varNums; ///< Map of type variables to indices … … 437 438 private: 438 439 void mangleDecl( const ast::DeclWithType *declaration ); 439 void mangleRef( const ast:: ReferenceToType *refType, std::string prefix );440 void mangleRef( const ast::BaseInstType *refType, std::string prefix ); 440 441 441 442 void printQualifiers( const ast::Type *type ); … … 447 448 ast::Pass<Mangler_new> mangler( mode ); 448 449 maybeAccept( decl, mangler ); 449 return mangler. pass.get_mangleName();450 return mangler.core.get_mangleName(); 450 451 } 451 452 … … 470 471 isTopLevel = false; 471 472 } // if 472 mangleName <<Encoding::manglePrefix;473 mangleName += Encoding::manglePrefix; 473 474 const CodeGen::OperatorInfo * opInfo = CodeGen::operatorLookup( decl->name ); 474 475 if ( opInfo ) { 475 mangleName << opInfo->outputName.size() <<opInfo->outputName;476 mangleName += std::to_string( opInfo->outputName.size() ) + opInfo->outputName; 476 477 } else { 477 mangleName << decl->name.size() <<decl->name;478 mangleName += std::to_string( decl->name.size() ) + decl->name; 478 479 } // if 479 480 maybeAccept( decl->get_type(), *visitor ); … … 482 483 // so they need a different name mangling 483 484 if ( decl->linkage == ast::Linkage::AutoGen ) { 484 mangleName <<Encoding::autogen;485 mangleName += Encoding::autogen; 485 486 } else if ( decl->linkage == ast::Linkage::Intrinsic ) { 486 mangleName <<Encoding::intrinsic;487 mangleName += Encoding::intrinsic; 487 488 } else { 488 489 // if we add another kind of overridable function, this has to change … … 503 504 void Mangler_new::postvisit( const ast::VoidType * voidType ) { 504 505 printQualifiers( voidType ); 505 mangleName <<Encoding::void_t;506 mangleName += Encoding::void_t; 506 507 } 507 508 … … 509 510 printQualifiers( basicType ); 510 511 assertf( basicType->kind < ast::BasicType::NUMBER_OF_BASIC_TYPES, "Unhandled basic type: %d", basicType->kind ); 511 mangleName <<Encoding::basicTypes[ basicType->kind ];512 mangleName += Encoding::basicTypes[ basicType->kind ]; 512 513 } 513 514 … … 515 516 printQualifiers( pointerType ); 516 517 // mangle void (*f)() and void f() to the same name to prevent overloading on functions and function pointers 517 if ( ! pointerType->base.as<ast::FunctionType>() ) mangleName <<Encoding::pointer;518 if ( ! pointerType->base.as<ast::FunctionType>() ) mangleName += Encoding::pointer; 518 519 maybe_accept( pointerType->base.get(), *visitor ); 519 520 } … … 522 523 // TODO: encode dimension 523 524 printQualifiers( arrayType ); 524 mangleName << Encoding::array <<"0";525 mangleName += Encoding::array + "0"; 525 526 maybeAccept( arrayType->base.get(), *visitor ); 526 527 } … … 545 546 void Mangler_new::postvisit( const ast::FunctionType * functionType ) { 546 547 printQualifiers( functionType ); 547 mangleName <<Encoding::function;548 mangleName += Encoding::function; 548 549 // turn on inFunctionType so that printQualifiers does not print most qualifiers for function parameters, 549 550 // since qualifiers on outermost parameter type do not differentiate function types, e.g., … … 551 552 GuardValue( inFunctionType ); 552 553 inFunctionType = true; 553 std::vector< ast::ptr< ast::Type > > returnTypes = getTypes( functionType->returns ); 554 if (returnTypes.empty()) mangleName << Encoding::void_t; 555 else accept_each( returnTypes, *visitor ); 556 mangleName << "_"; 557 std::vector< ast::ptr< ast::Type > > paramTypes = getTypes( functionType->params ); 558 accept_each( paramTypes, *visitor ); 559 mangleName << "_"; 560 } 561 562 void Mangler_new::mangleRef( const ast::ReferenceToType * refType, std::string prefix ) { 554 if (functionType->returns.empty()) mangleName += Encoding::void_t; 555 else accept_each( functionType->returns, *visitor ); 556 mangleName += "_"; 557 accept_each( functionType->params, *visitor ); 558 mangleName += "_"; 559 } 560 561 void Mangler_new::mangleRef( const ast::BaseInstType * refType, std::string prefix ) { 563 562 printQualifiers( refType ); 564 563 565 mangleName << prefix << refType->name.length() <<refType->name;564 mangleName += prefix + std::to_string( refType->name.length() ) + refType->name; 566 565 567 566 if ( mangleGenericParams ) { 568 567 if ( ! refType->params.empty() ) { 569 mangleName <<"_";568 mangleName += "_"; 570 569 for ( const ast::Expr * param : refType->params ) { 571 570 auto paramType = dynamic_cast< const ast::TypeExpr * >( param ); … … 573 572 maybeAccept( paramType->type.get(), *visitor ); 574 573 } 575 mangleName <<"_";574 mangleName += "_"; 576 575 } 577 576 } … … 602 601 // are first found and prefixing with the appropriate encoding for the type class. 603 602 assertf( varNum->second.second < TypeDecl::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", varNum->second.second ); 604 mangleName << Encoding::typeVariables[varNum->second.second] << varNum->second.first;603 mangleName += Encoding::typeVariables[varNum->second.second] + std::to_string( varNum->second.first ); 605 604 } // if 606 605 } … … 608 607 void Mangler_new::postvisit( const ast::TraitInstType * inst ) { 609 608 printQualifiers( inst ); 610 mangleName << inst->name.size() <<inst->name;609 mangleName += std::to_string( inst->name.size() ) + inst->name; 611 610 } 612 611 613 612 void Mangler_new::postvisit( const ast::TupleType * tupleType ) { 614 613 printQualifiers( tupleType ); 615 mangleName << Encoding::tuple << tupleType->types.size();614 mangleName += Encoding::tuple + std::to_string( tupleType->types.size() ); 616 615 accept_each( tupleType->types, *visitor ); 617 616 } … … 620 619 printQualifiers( varArgsType ); 621 620 static const std::string vargs = "__builtin_va_list"; 622 mangleName << Encoding::type << vargs.size() <<vargs;621 mangleName += Encoding::type + std::to_string( vargs.size() ) + vargs; 623 622 } 624 623 625 624 void Mangler_new::postvisit( const ast::ZeroType * ) { 626 mangleName <<Encoding::zero;625 mangleName += Encoding::zero; 627 626 } 628 627 629 628 void Mangler_new::postvisit( const ast::OneType * ) { 630 mangleName <<Encoding::one;629 mangleName += Encoding::one; 631 630 } 632 631 … … 636 635 // N marks the start of a qualified type 637 636 inQualifiedType = true; 638 mangleName <<Encoding::qualifiedTypeStart;637 mangleName += Encoding::qualifiedTypeStart; 639 638 } 640 639 maybeAccept( qualType->parent.get(), *visitor ); … … 643 642 // E marks the end of a qualified type 644 643 inQualifiedType = false; 645 mangleName <<Encoding::qualifiedTypeEnd;644 mangleName += Encoding::qualifiedTypeEnd; 646 645 } 647 646 } … … 655 654 assertf(false, "Mangler_new should not visit typedecl: %s", toCString(decl)); 656 655 assertf( decl->kind < ast::TypeDecl::Kind::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", decl->kind ); 657 mangleName << Encoding::typeVariables[ decl->kind ] << ( decl->name.length() ) <<decl->name;656 mangleName += Encoding::typeVariables[ decl->kind ] + std::to_string( decl->name.length() ) + decl->name; 658 657 } 659 658 … … 667 666 // skip if not including qualifiers 668 667 if ( typeMode ) return; 669 if ( auto ptype = dynamic_cast< const ast:: ParameterizedType * >(type) ) {668 if ( auto ptype = dynamic_cast< const ast::FunctionType * >(type) ) { 670 669 if ( ! ptype->forall.empty() ) { 671 670 std::list< std::string > assertionNames; 672 671 int dcount = 0, fcount = 0, vcount = 0, acount = 0; 673 mangleName <<Encoding::forall;674 for ( const ast::TypeDecl *decl : ptype->forall ) {672 mangleName += Encoding::forall; 673 for ( auto & decl : ptype->forall ) { 675 674 switch ( decl->kind ) { 676 675 case ast::TypeDecl::Kind::Dtype: … … 687 686 } // switch 688 687 varNums[ decl->name ] = std::make_pair( nextVarNum, (int)decl->kind ); 689 for ( const ast::DeclWithType * assert : decl->assertions ) {690 ast::Pass<Mangler_new> sub_mangler(691 mangleOverridable, typeMode, mangleGenericParams, nextVarNum, varNums );692 assert->accept( sub_mangler );693 assertionNames.push_back( sub_mangler.pass.get_mangleName() );694 acount++;695 } // for696 688 } // for 697 mangleName << dcount << "_" << fcount << "_" << vcount << "_" << acount << "_"; 698 std::copy( assertionNames.begin(), assertionNames.end(), std::ostream_iterator< std::string >( mangleName, "" ) ); 699 mangleName << "_"; 689 for ( auto & assert : ptype->assertions ) { 690 ast::Pass<Mangler_new> sub_mangler( 691 mangleOverridable, typeMode, mangleGenericParams, nextVarNum, varNums ); 692 assert->var->accept( sub_mangler ); 693 assertionNames.push_back( sub_mangler.core.get_mangleName() ); 694 acount++; 695 } // for 696 mangleName += std::to_string( dcount ) + "_" + std::to_string( fcount ) + "_" + std::to_string( vcount ) + "_" + std::to_string( acount ) + "_"; 697 for(const auto & a : assertionNames) mangleName += a; 698 // std::copy( assertionNames.begin(), assertionNames.end(), std::ostream_iterator< std::string >( mangleName, "" ) ); 699 mangleName += "_"; 700 700 } // if 701 701 } // if … … 703 703 // these qualifiers do not distinguish the outermost type of a function parameter 704 704 if ( type->is_const() ) { 705 mangleName <<Encoding::qualifiers.at(Type::Const);705 mangleName += Encoding::qualifiers.at(Type::Const); 706 706 } // if 707 707 if ( type->is_volatile() ) { 708 mangleName <<Encoding::qualifiers.at(Type::Volatile);708 mangleName += Encoding::qualifiers.at(Type::Volatile); 709 709 } // if 710 710 // Removed due to restrict not affecting function compatibility in GCC 711 711 // if ( type->get_isRestrict() ) { 712 // mangleName <<"E";712 // mangleName += "E"; 713 713 // } // if 714 714 if ( type->is_atomic() ) { 715 mangleName <<Encoding::qualifiers.at(Type::Atomic);715 mangleName += Encoding::qualifiers.at(Type::Atomic); 716 716 } // if 717 717 } 718 718 if ( type->is_mutex() ) { 719 mangleName <<Encoding::qualifiers.at(Type::Mutex);719 mangleName += Encoding::qualifiers.at(Type::Mutex); 720 720 } // if 721 721 if ( inFunctionType ) {
Note:
See TracChangeset
for help on using the changeset viewer.