Changes in src/SymTab/Mangler.cc [0e761e40:e73becf]
- File:
-
- 1 edited
-
src/SymTab/Mangler.cc (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Mangler.cc
r0e761e40 re73becf 73 73 bool mangleGenericParams; ///< Include generic parameters in name mangling if true 74 74 bool inFunctionType = false; ///< Include type qualifiers if false. 75 bool inQualifiedType = false; ///< Add start/end delimiters around qualified type76 75 77 76 void mangleDecl( DeclarationWithType *declaration ); … … 111 110 isTopLevel = false; 112 111 } // if 113 mangleName << Encoding::manglePrefix;112 mangleName << "__"; 114 113 CodeGen::OperatorInfo opInfo; 115 114 if ( operatorLookup( declaration->get_name(), opInfo ) ) { 116 mangleName << opInfo.outputName .size() << opInfo.outputName;115 mangleName << opInfo.outputName; 117 116 } else { 118 mangleName << declaration-> name.size() << declaration->name;117 mangleName << declaration->get_name(); 119 118 } // if 119 mangleName << "__"; 120 120 maybeAccept( declaration->get_type(), *visitor ); 121 121 if ( mangleOverridable && LinkageSpec::isOverridable( declaration->get_linkage() ) ) { … … 123 123 // so they need a different name mangling 124 124 if ( declaration->get_linkage() == LinkageSpec::AutoGen ) { 125 mangleName << Encoding::autogen;125 mangleName << "autogen__"; 126 126 } else if ( declaration->get_linkage() == LinkageSpec::Intrinsic ) { 127 mangleName << Encoding::intrinsic;127 mangleName << "intrinsic__"; 128 128 } else { 129 129 // if we add another kind of overridable function, this has to change … … 144 144 void Mangler::postvisit( VoidType * voidType ) { 145 145 printQualifiers( voidType ); 146 mangleName << Encoding::void_t;146 mangleName << "v"; 147 147 } 148 148 149 149 void Mangler::postvisit( BasicType * basicType ) { 150 static const char *btLetter[] = { 151 "b", // Bool 152 "c", // Char 153 "Sc", // SignedChar 154 "Uc", // UnsignedChar 155 "s", // ShortSignedInt 156 "Us", // ShortUnsignedInt 157 "i", // SignedInt 158 "Ui", // UnsignedInt 159 "l", // LongSignedInt 160 "Ul", // LongUnsignedInt 161 "q", // LongLongSignedInt 162 "Uq", // LongLongUnsignedInt 163 "f", // Float 164 "d", // Double 165 "r", // LongDouble 166 "Xf", // FloatComplex 167 "Xd", // DoubleComplex 168 "Xr", // LongDoubleComplex 169 "If", // FloatImaginary 170 "Id", // DoubleImaginary 171 "Ir", // LongDoubleImaginary 172 "w", // SignedInt128 173 "Uw", // UnsignedInt128 174 "x", // Float80 175 "y", // Float128 176 }; 177 static_assert( 178 sizeof(btLetter)/sizeof(btLetter[0]) == BasicType::NUMBER_OF_BASIC_TYPES, 179 "Each basic type kind should have a corresponding mangler letter" 180 ); 181 150 182 printQualifiers( basicType ); 151 assert f( basicType->get_kind() < BasicType::NUMBER_OF_BASIC_TYPES, "Unhandled basic type: %d", basicType->get_kind() );152 mangleName << Encoding::basicTypes[ basicType->get_kind() ];183 assert( basicType->get_kind() < sizeof(btLetter)/sizeof(btLetter[0]) ); 184 mangleName << btLetter[ basicType->get_kind() ]; 153 185 } 154 186 … … 156 188 printQualifiers( pointerType ); 157 189 // mangle void (*f)() and void f() to the same name to prevent overloading on functions and function pointers 158 if ( ! dynamic_cast<FunctionType *>( pointerType->base ) ) mangleName << Encoding::pointer;190 if ( ! dynamic_cast<FunctionType *>( pointerType->base ) ) mangleName << "P"; 159 191 maybeAccept( pointerType->base, *visitor ); 160 192 } … … 163 195 // TODO: encode dimension 164 196 printQualifiers( arrayType ); 165 mangleName << Encoding::array << "0";197 mangleName << "A0"; 166 198 maybeAccept( arrayType->base, *visitor ); 167 199 } … … 188 220 void Mangler::postvisit( FunctionType * functionType ) { 189 221 printQualifiers( functionType ); 190 mangleName << Encoding::function;222 mangleName << "F"; 191 223 // turn on inFunctionType so that printQualifiers does not print most qualifiers for function parameters, 192 224 // since qualifiers on outermost parameter type do not differentiate function types, e.g., … … 195 227 inFunctionType = true; 196 228 std::list< Type* > returnTypes = getTypes( functionType->returnVals ); 197 if (returnTypes.empty()) mangleName << Encoding::void_t; 198 else acceptAll( returnTypes, *visitor ); 229 acceptAll( returnTypes, *visitor ); 199 230 mangleName << "_"; 200 231 std::list< Type* > paramTypes = getTypes( functionType->parameters ); … … 206 237 printQualifiers( refType ); 207 238 208 mangleName << prefix << refType->name.length()<< refType->name;239 mangleName << ( refType->name.length() + prefix.length() ) << prefix << refType->name; 209 240 210 241 if ( mangleGenericParams ) { … … 223 254 224 255 void Mangler::postvisit( StructInstType * aggregateUseType ) { 225 mangleRef( aggregateUseType, Encoding::struct_t);256 mangleRef( aggregateUseType, "s" ); 226 257 } 227 258 228 259 void Mangler::postvisit( UnionInstType * aggregateUseType ) { 229 mangleRef( aggregateUseType, Encoding::union_t);260 mangleRef( aggregateUseType, "u" ); 230 261 } 231 262 232 263 void Mangler::postvisit( EnumInstType * aggregateUseType ) { 233 mangleRef( aggregateUseType, Encoding::enum_t);264 mangleRef( aggregateUseType, "e" ); 234 265 } 235 266 … … 237 268 VarMapType::iterator varNum = varNums.find( typeInst->get_name() ); 238 269 if ( varNum == varNums.end() ) { 239 mangleRef( typeInst, Encoding::type);270 mangleRef( typeInst, "t" ); 240 271 } else { 241 272 printQualifiers( typeInst ); 242 // Note: Can't use name here, since type variable names do not actually disambiguate a function, e.g. 243 // forall(dtype T) void f(T); 244 // forall(dtype S) void f(S); 245 // are equivalent and should mangle the same way. This is accomplished by numbering the type variables when they 246 // are first found and prefixing with the appropriate encoding for the type class. 247 assertf( varNum->second.second < TypeDecl::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", varNum->second.second ); 248 mangleName << Encoding::typeVariables[varNum->second.second] << varNum->second.first; 273 std::ostringstream numStream; 274 numStream << varNum->second.first; 275 switch ( (TypeDecl::Kind )varNum->second.second ) { 276 case TypeDecl::Dtype: 277 mangleName << "d"; 278 break; 279 case TypeDecl::Ftype: 280 mangleName << "f"; 281 break; 282 case TypeDecl::Ttype: 283 mangleName << "tVARGS"; 284 break; 285 default: 286 assert( false ); 287 } // switch 288 mangleName << numStream.str(); 249 289 } // if 250 290 } … … 252 292 void Mangler::postvisit( TraitInstType * inst ) { 253 293 printQualifiers( inst ); 254 mangleName << inst->name.size() << inst->name;294 mangleName << "_Y" << inst->name << "_"; 255 295 } 256 296 257 297 void Mangler::postvisit( TupleType * tupleType ) { 258 298 printQualifiers( tupleType ); 259 mangleName << Encoding::tuple << tupleType->types.size();299 mangleName << "T"; 260 300 acceptAll( tupleType->types, *visitor ); 301 mangleName << "_"; 261 302 } 262 303 263 304 void Mangler::postvisit( VarArgsType * varArgsType ) { 264 305 printQualifiers( varArgsType ); 265 static const std::string vargs = "__builtin_va_list"; 266 mangleName << Encoding::type << vargs.size() << vargs; 306 mangleName << "VARGS"; 267 307 } 268 308 269 309 void Mangler::postvisit( ZeroType * ) { 270 mangleName << Encoding::zero;310 mangleName << "Z"; 271 311 } 272 312 273 313 void Mangler::postvisit( OneType * ) { 274 mangleName << Encoding::one;314 mangleName << "O"; 275 315 } 276 316 277 317 void Mangler::postvisit( QualifiedType * qualType ) { 278 bool inqual = inQualifiedType;279 if (! inqual ) {280 // N marks the start of a qualified type281 inQualifiedType = true;282 mangleName << Encoding::qualifiedTypeStart;283 }284 318 maybeAccept( qualType->parent, *visitor ); 319 mangleName << "__"; 285 320 maybeAccept( qualType->child, *visitor ); 286 if ( ! inqual ) {287 // E marks the end of a qualified type288 inQualifiedType = false;289 mangleName << Encoding::qualifiedTypeEnd;290 }291 321 } 292 322 293 323 void Mangler::postvisit( TypeDecl * decl ) { 294 // TODO: is there any case where mangling a TypeDecl makes sense? If so, this code needs to be 295 // fixed to ensure that two TypeDecls mangle to the same name when they are the same type and vice versa. 296 // Note: The current scheme may already work correctly for this case, I have not thought about this deeply 297 // and the case has not yet come up in practice. Alternatively, if not then this code can be removed 298 // aside from the assert false. 299 assertf(false, "Mangler should not visit typedecl: %s", toCString(decl)); 300 assertf( decl->get_kind() < TypeDecl::NUMBER_OF_KINDS, "Unhandled type variable kind: %d", decl->get_kind() ); 301 mangleName << Encoding::typeVariables[ decl->get_kind() ] << ( decl->name.length() ) << decl->name; 324 static const char *typePrefix[] = { "BT", "BD", "BF" }; 325 mangleName << typePrefix[ decl->get_kind() ] << ( decl->name.length() + 1 ) << decl->name; 302 326 } 303 327 … … 313 337 if ( ! type->get_forall().empty() ) { 314 338 std::list< std::string > assertionNames; 315 int dcount = 0, fcount = 0, vcount = 0, acount = 0;316 mangleName << Encoding::forall;339 int tcount = 0, dcount = 0, fcount = 0, vcount = 0; 340 mangleName << "A"; 317 341 for ( Type::ForallList::iterator i = type->forall.begin(); i != type->forall.end(); ++i ) { 318 342 switch ( (*i)->get_kind() ) { … … 337 361 (*assert)->accept( sub_mangler ); 338 362 assertionNames.push_back( sub_mangler.pass.mangleName.str() ); 339 acount++;340 363 } // for 341 364 } // for 342 mangleName << dcount << "_" << fcount << "_" << vcount << "_" << acount << "_";365 mangleName << tcount << "_" << dcount << "_" << fcount << "_" << vcount << "_"; 343 366 std::copy( assertionNames.begin(), assertionNames.end(), std::ostream_iterator< std::string >( mangleName, "" ) ); 344 367 mangleName << "_"; … … 347 370 // these qualifiers do not distinguish the outermost type of a function parameter 348 371 if ( type->get_const() ) { 349 mangleName << Encoding::qualifiers.at(Type::Const);372 mangleName << "C"; 350 373 } // if 351 374 if ( type->get_volatile() ) { 352 mangleName << Encoding::qualifiers.at(Type::Volatile);375 mangleName << "V"; 353 376 } // if 354 377 // Removed due to restrict not affecting function compatibility in GCC … … 357 380 // } // if 358 381 if ( type->get_atomic() ) { 359 mangleName << Encoding::qualifiers.at(Type::Atomic);382 mangleName << "A"; 360 383 } // if 361 384 } 362 385 if ( type->get_mutex() ) { 363 mangleName << Encoding::qualifiers.at(Type::Mutex);386 mangleName << "M"; 364 387 } // if 365 388 if ( type->get_lvalue() ) { 366 389 // mangle based on whether the type is lvalue, so that the resolver can differentiate lvalues and rvalues 367 mangleName << Encoding::qualifiers.at(Type::Lvalue);390 mangleName << "L"; 368 391 } 369 392
Note:
See TracChangeset
for help on using the changeset viewer.