| [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 | //
 | 
|---|
| [25bd9074] | 7 | // Mangler.h --
 | 
|---|
| [0dd3a2f] | 8 | //
 | 
|---|
 | 9 | // Author           : Richard C. Bilson
 | 
|---|
 | 10 | // Created On       : Sun May 17 21:44:03 2015
 | 
|---|
| [6b0b624] | 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
 | 12 | // Last Modified On : Sat Jul 22 09:45:30 2017
 | 
|---|
 | 13 | // Update Count     : 15
 | 
|---|
| [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"
 | 
|---|
 | 24 | #include "AST/Fwd.hpp"
 | 
|---|
| [30f9072] | 25 | #include "SynTree/SynTree.h"  // for Types
 | 
|---|
 | 26 | #include "SynTree/Visitor.h"  // for Visitor, maybeAccept
 | 
|---|
| [51b73452] | 27 | 
 | 
|---|
| [642bc83] | 28 | // https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling
 | 
|---|
 | 29 | // The CFA name mangling scheme is based closely on the itanium C++ name mangling scheme, with the following key differences:
 | 
|---|
 | 30 | // * Variable names are also mangled to include type information, not just functions
 | 
|---|
 | 31 | // * CFA does not have template expansion, so the rules for function specialization do not apply.
 | 
|---|
 | 32 | // * CFA instead has to handle type parameters and assertion parameters.
 | 
|---|
 | 33 | // * Currently name compression is not implemented.
 | 
|---|
 | 34 | 
 | 
|---|
| [ff5caaf] | 35 | namespace ResolvExpr {
 | 
|---|
 | 36 |         class TypeEnvironment;
 | 
|---|
 | 37 | }
 | 
|---|
 | 38 | 
 | 
|---|
| [51b73452] | 39 | namespace SymTab {
 | 
|---|
| [d7d9a60] | 40 |         namespace Mangler {
 | 
|---|
| [69911c11] | 41 |                 /// Mangle syntax tree object; primary interface to clients
 | 
|---|
| [d7d9a60] | 42 |                 std::string mangle( BaseSyntaxNode * decl, bool mangleOverridable = true, bool typeMode = false, bool mangleGenericParams = true );
 | 
|---|
 | 43 | 
 | 
|---|
| [69911c11] | 44 |                 /// Mangle a type name; secondary interface
 | 
|---|
| [d7d9a60] | 45 |                 std::string mangleType( Type* ty );
 | 
|---|
| [e35f30a] | 46 |                 /// Mangle ignoring generic type parameters
 | 
|---|
| [d7d9a60] | 47 |                 std::string mangleConcrete( Type* ty );
 | 
|---|
| [d1e0979] | 48 | 
 | 
|---|
| [642bc83] | 49 |                 namespace Encoding {
 | 
|---|
 | 50 |                         extern const std::string manglePrefix;
 | 
|---|
 | 51 |                         extern const std::string basicTypes[];
 | 
|---|
 | 52 |                         extern const std::map<int, std::string> qualifiers;
 | 
|---|
 | 53 | 
 | 
|---|
| [7804e2a] | 54 |                         extern const std::string void_t;
 | 
|---|
| [642bc83] | 55 |                         extern const std::string zero;
 | 
|---|
 | 56 |                         extern const std::string one;
 | 
|---|
 | 57 | 
 | 
|---|
 | 58 |                         extern const std::string function;
 | 
|---|
 | 59 |                         extern const std::string tuple;
 | 
|---|
 | 60 |                         extern const std::string pointer;
 | 
|---|
 | 61 |                         extern const std::string array;
 | 
|---|
 | 62 |                         extern const std::string qualifiedTypeStart;
 | 
|---|
 | 63 |                         extern const std::string qualifiedTypeEnd;
 | 
|---|
 | 64 | 
 | 
|---|
| [0e73845] | 65 |                         extern const std::string forall;
 | 
|---|
 | 66 |                         extern const std::string typeVariables[];
 | 
|---|
 | 67 | 
 | 
|---|
| [7804e2a] | 68 |                         extern const std::string struct_t;
 | 
|---|
 | 69 |                         extern const std::string union_t;
 | 
|---|
 | 70 |                         extern const std::string enum_t;
 | 
|---|
| [d8cb7df] | 71 |                         extern const std::string type;
 | 
|---|
| [7804e2a] | 72 | 
 | 
|---|
| [642bc83] | 73 |                         extern const std::string autogen;
 | 
|---|
 | 74 |                         extern const std::string intrinsic;
 | 
|---|
 | 75 |                 };
 | 
|---|
| [d7d9a60] | 76 |         } // Mangler
 | 
|---|
| [ea3eb06] | 77 | } // SymTab
 | 
|---|
 | 78 | 
 | 
|---|
| [d76c588] | 79 | namespace Mangle {
 | 
|---|
 | 80 |         /// Bitflags for mangle modes
 | 
|---|
 | 81 |         enum {
 | 
|---|
 | 82 |                 NoOverrideable  = 1 << 0,
 | 
|---|
 | 83 |                 Type            = 1 << 1,
 | 
|---|
 | 84 |                 NoGenericParams = 1 << 2
 | 
|---|
 | 85 |         };
 | 
|---|
 | 86 | 
 | 
|---|
 | 87 |         /// Bitflag type for mangler modes
 | 
|---|
 | 88 |         struct mangle_flags {
 | 
|---|
 | 89 |                 union {
 | 
|---|
 | 90 |                         unsigned int val;
 | 
|---|
 | 91 |                         struct {
 | 
|---|
 | 92 |                                 bool no_overrideable   : 1;
 | 
|---|
 | 93 |                                 bool type              : 1;
 | 
|---|
 | 94 |                                 bool no_generic_params : 1;
 | 
|---|
 | 95 |                         };
 | 
|---|
 | 96 |                 };
 | 
|---|
 | 97 | 
 | 
|---|
 | 98 |                 constexpr mangle_flags( unsigned int val ) : val(val) {}
 | 
|---|
 | 99 |         };
 | 
|---|
 | 100 | 
 | 
|---|
 | 101 |         using Mode = bitfield<mangle_flags>;
 | 
|---|
 | 102 | 
 | 
|---|
| [b69233ac] | 103 |         static inline Mode typeMode() { return NoOverrideable | Type; }
 | 
|---|
 | 104 | 
 | 
|---|
| [d76c588] | 105 |         /// Mangle declaration name
 | 
|---|
 | 106 |         std::string mangle( const ast::Node * decl, Mode mode = {} );
 | 
|---|
 | 107 | 
 | 
|---|
 | 108 |         namespace Encoding {
 | 
|---|
 | 109 |                 using namespace SymTab::Mangler::Encoding;
 | 
|---|
 | 110 |         };
 | 
|---|
 | 111 | }
 | 
|---|
 | 112 | 
 | 
|---|
| [d1e0979] | 113 | extern "C" {
 | 
|---|
| [90cac45] | 114 |         char * cforall_demangle(const char *, int);
 | 
|---|
| [d1e0979] | 115 | }
 | 
|---|
 | 116 | 
 | 
|---|
| [0dd3a2f] | 117 | // Local Variables: //
 | 
|---|
 | 118 | // tab-width: 4 //
 | 
|---|
 | 119 | // mode: c++ //
 | 
|---|
 | 120 | // compile-command: "make install" //
 | 
|---|
 | 121 | // End: //
 | 
|---|