| [0dd3a2f] | 1 | //
 | 
|---|
 | 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
 | 
|---|
 | 3 | //
 | 
|---|
 | 4 | // The contents of this file are covered under the licence agreement in the
 | 
|---|
 | 5 | // file "LICENCE" distributed with Cforall.
 | 
|---|
 | 6 | //
 | 
|---|
| [c92bdcc] | 7 | // Mangler.hpp --
 | 
|---|
| [0dd3a2f] | 8 | //
 | 
|---|
 | 9 | // Author           : Richard C. Bilson
 | 
|---|
 | 10 | // Created On       : Sun May 17 21:44:03 2015
 | 
|---|
| [0026d67] | 11 | // Last Modified By : Andrew Beach
 | 
|---|
 | 12 | // Last Modified On : Thu Oct 27 11:58:00 2022
 | 
|---|
 | 13 | // Update Count     : 16
 | 
|---|
| [0dd3a2f] | 14 | //
 | 
|---|
 | 15 | 
 | 
|---|
| [6b0b624] | 16 | #pragma once
 | 
|---|
| [51b73452] | 17 | 
 | 
|---|
| [30f9072] | 18 | #include <map>                // for map, map<>::value_compare
 | 
|---|
 | 19 | #include <sstream>            // for ostringstream
 | 
|---|
 | 20 | #include <string>             // for string
 | 
|---|
 | 21 | #include <utility>            // for pair
 | 
|---|
 | 22 | 
 | 
|---|
| [d76c588] | 23 | #include "AST/Bitfield.hpp"
 | 
|---|
| [51b73452] | 24 | 
 | 
|---|
| [642bc83] | 25 | // https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling
 | 
|---|
 | 26 | // The CFA name mangling scheme is based closely on the itanium C++ name mangling scheme, with the following key differences:
 | 
|---|
 | 27 | // * Variable names are also mangled to include type information, not just functions
 | 
|---|
 | 28 | // * CFA does not have template expansion, so the rules for function specialization do not apply.
 | 
|---|
 | 29 | // * CFA instead has to handle type parameters and assertion parameters.
 | 
|---|
 | 30 | // * Currently name compression is not implemented.
 | 
|---|
 | 31 | 
 | 
|---|
| [0026d67] | 32 | namespace ast {
 | 
|---|
 | 33 |         class Node;
 | 
|---|
 | 34 | }
 | 
|---|
| [ff5caaf] | 35 | 
 | 
|---|
| [d76c588] | 36 | namespace Mangle {
 | 
|---|
 | 37 | 
 | 
|---|
| [b0845f9] | 38 | /// Bitflags for mangle Mode:
 | 
|---|
 | 39 | enum {
 | 
|---|
 | 40 |         NoOverrideable  = 1 << 0,
 | 
|---|
 | 41 |         Type            = 1 << 1,
 | 
|---|
 | 42 |         NoGenericParams = 1 << 2
 | 
|---|
 | 43 | };
 | 
|---|
 | 44 | 
 | 
|---|
 | 45 | /// Bitflag type for mangle Mode:
 | 
|---|
 | 46 | struct mangle_flags {
 | 
|---|
 | 47 |         union {
 | 
|---|
 | 48 |                 unsigned int val;
 | 
|---|
 | 49 |                 struct {
 | 
|---|
 | 50 |                         bool no_overrideable   : 1;
 | 
|---|
 | 51 |                         bool type              : 1;
 | 
|---|
 | 52 |                         bool no_generic_params : 1;
 | 
|---|
| [d76c588] | 53 |                 };
 | 
|---|
 | 54 |         };
 | 
|---|
 | 55 | 
 | 
|---|
| [b0845f9] | 56 |         constexpr mangle_flags( unsigned int val ) : val(val) {}
 | 
|---|
 | 57 | };
 | 
|---|
| [d76c588] | 58 | 
 | 
|---|
| [b0845f9] | 59 | using Mode = bitfield<mangle_flags>;
 | 
|---|
| [d76c588] | 60 | 
 | 
|---|
| [b0845f9] | 61 | /// Mangle declaration name.
 | 
|---|
 | 62 | std::string mangle( const ast::Node * decl, Mode mode = {} );
 | 
|---|
 | 63 | 
 | 
|---|
 | 64 | /// Most common mangle configuration for types.
 | 
|---|
 | 65 | static inline std::string mangleType( const ast::Node * type ) {
 | 
|---|
 | 66 |         return mangle( type, { NoOverrideable | Type } );
 | 
|---|
 | 67 | }
 | 
|---|
 | 68 | 
 | 
|---|
 | 69 | /// The substrings used in name mangling and demangling.
 | 
|---|
 | 70 | namespace Encoding {
 | 
|---|
 | 71 |         extern const std::string manglePrefix;
 | 
|---|
 | 72 |         extern const std::string basicTypes[];
 | 
|---|
 | 73 |         extern const std::map<int, std::string> qualifiers;
 | 
|---|
 | 74 | 
 | 
|---|
 | 75 |         extern const std::string void_t;
 | 
|---|
 | 76 |         extern const std::string zero;
 | 
|---|
 | 77 |         extern const std::string one;
 | 
|---|
 | 78 | 
 | 
|---|
 | 79 |         extern const std::string function;
 | 
|---|
 | 80 |         extern const std::string tuple;
 | 
|---|
 | 81 |         extern const std::string pointer;
 | 
|---|
 | 82 |         extern const std::string array;
 | 
|---|
 | 83 |         extern const std::string qualifiedTypeStart;
 | 
|---|
 | 84 |         extern const std::string qualifiedTypeEnd;
 | 
|---|
 | 85 | 
 | 
|---|
 | 86 |         extern const std::string forall;
 | 
|---|
 | 87 |         extern const std::string typeVariables[];
 | 
|---|
 | 88 | 
 | 
|---|
 | 89 |         extern const std::string struct_t;
 | 
|---|
 | 90 |         extern const std::string union_t;
 | 
|---|
 | 91 |         extern const std::string enum_t;
 | 
|---|
 | 92 |         extern const std::string type;
 | 
|---|
 | 93 | 
 | 
|---|
 | 94 |         extern const std::string autogen;
 | 
|---|
 | 95 |         extern const std::string intrinsic;
 | 
|---|
 | 96 | }
 | 
|---|
| [0026d67] | 97 | 
 | 
|---|
| [d76c588] | 98 | }
 | 
|---|
 | 99 | 
 | 
|---|
| [0dd3a2f] | 100 | // Local Variables: //
 | 
|---|
 | 101 | // tab-width: 4 //
 | 
|---|
 | 102 | // mode: c++ //
 | 
|---|
 | 103 | // compile-command: "make install" //
 | 
|---|
 | 104 | // End: //
 | 
|---|