| 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 | //
 | 
|---|
| 7 | // Mangler.h --
 | 
|---|
| 8 | //
 | 
|---|
| 9 | // Author           : Richard C. Bilson
 | 
|---|
| 10 | // Created On       : Sun May 17 21:44:03 2015
 | 
|---|
| 11 | // Last Modified By : Peter A. Buhr
 | 
|---|
| 12 | // Last Modified On : Fri Dec 13 14:54:38 2019
 | 
|---|
| 13 | // Update Count     : 28
 | 
|---|
| 14 | //
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #include "Mangler.h"
 | 
|---|
| 17 | #include "SynTree/Type.h"
 | 
|---|
| 18 | #include "SynTree/Declaration.h"
 | 
|---|
| 19 | 
 | 
|---|
| 20 | namespace SymTab {
 | 
|---|
| 21 |         namespace Mangler {
 | 
|---|
| 22 |                 namespace Encoding {
 | 
|---|
| 23 |                         const std::string manglePrefix = "_X";
 | 
|---|
| 24 | 
 | 
|---|
| 25 |                         // GENERATED START, DO NOT EDIT
 | 
|---|
| 26 |                         // GENERATED BY BasicTypes-gen.cc
 | 
|---|
| 27 |                         // NOTES ON MANGLING:
 | 
|---|
| 28 |                         // * Itanium spec says that Float80 encodes to "e" (like LongDouble), but the distinct lengths cause resolution problems.
 | 
|---|
| 29 |                         // * Float128 is supposed to encode to "g", but I wanted it to mangle equal to LongDouble.
 | 
|---|
| 30 |                         // * Mangling for non-standard complex types is by best guess
 | 
|---|
| 31 |                         // * _FloatN is supposed to encode as "DF"N"_"; modified for same reason as above.
 | 
|---|
| 32 |                         // * unused mangling identifiers:
 | 
|---|
| 33 |                         //   - "z" ellipsis
 | 
|---|
| 34 |                         //   - "Dd" IEEE 754r 64-bit decimal floating point (borrowed for _Float32x)
 | 
|---|
| 35 |                         //   - "De" IEEE 754r 128-bit decimal floating point
 | 
|---|
| 36 |                         //   - "Df" IEEE 754r 32-bit decimal floating point
 | 
|---|
| 37 |                         //   - "Dh" IEEE 754r 16-bit decimal floating point (borrowed for _Float16)
 | 
|---|
| 38 |                         //   - "DF"N"_" ISO/IEC TS 18661 N-bit binary floating point (_FloatN)
 | 
|---|
| 39 |                         //   - "Di" char32_t
 | 
|---|
| 40 |                         //   - "Ds" char16_t
 | 
|---|
| 41 |                         const std::string basicTypes[BasicType::NUMBER_OF_BASIC_TYPES] = {
 | 
|---|
| 42 |                                 "b",        // _Bool
 | 
|---|
| 43 |                                 "c",        // char
 | 
|---|
| 44 |                                 "a",        // signed char
 | 
|---|
| 45 |                                 "h",        // unsigned char
 | 
|---|
| 46 |                                 "s",        // signed short int
 | 
|---|
| 47 |                                 "t",        // unsigned short int
 | 
|---|
| 48 |                                 "i",        // signed int
 | 
|---|
| 49 |                                 "j",        // unsigned int
 | 
|---|
| 50 |                                 "l",        // signed long int
 | 
|---|
| 51 |                                 "m",        // unsigned long int
 | 
|---|
| 52 |                                 "x",        // signed long long int
 | 
|---|
| 53 |                                 "y",        // unsigned long long int
 | 
|---|
| 54 |                                 "n",        // __int128
 | 
|---|
| 55 |                                 "o",        // unsigned __int128
 | 
|---|
| 56 |                                 "DF16_",    // _Float16
 | 
|---|
| 57 |                                 "CDF16_",   // _Float16 _Complex
 | 
|---|
| 58 |                                 "DF32_",    // _Float32
 | 
|---|
| 59 |                                 "CDF32_",   // _Float32 _Complex
 | 
|---|
| 60 |                                 "f",        // float
 | 
|---|
| 61 |                                 "Cf",       // float _Complex
 | 
|---|
| 62 |                                 "DF32x_",   // _Float32x
 | 
|---|
| 63 |                                 "CDF32x_",  // _Float32x _Complex
 | 
|---|
| 64 |                                 "DF64_",    // _Float64
 | 
|---|
| 65 |                                 "CDF64_",   // _Float64 _Complex
 | 
|---|
| 66 |                                 "d",        // double
 | 
|---|
| 67 |                                 "Cd",       // double _Complex
 | 
|---|
| 68 |                                 "DF64x_",   // _Float64x
 | 
|---|
| 69 |                                 "CDF64x_",  // _Float64x _Complex
 | 
|---|
| 70 |                                 "Dq",       // __float80
 | 
|---|
| 71 |                                 "DF128_",   // _Float128
 | 
|---|
| 72 |                                 "CDF128_",  // _Float128 _Complex
 | 
|---|
| 73 |                                 "g",        // __float128
 | 
|---|
| 74 |                                 "e",        // long double
 | 
|---|
| 75 |                                 "Ce",       // long double _Complex
 | 
|---|
| 76 |                                 "DF128x_",  // _Float128x
 | 
|---|
| 77 |                                 "CDF128x_", // _Float128x _Complex
 | 
|---|
| 78 |                         }; // basicTypes
 | 
|---|
| 79 |                         // GENERATED END
 | 
|---|
| 80 |                         static_assert(
 | 
|---|
| 81 |                                 sizeof(basicTypes)/sizeof(basicTypes[0]) == BasicType::NUMBER_OF_BASIC_TYPES,
 | 
|---|
| 82 |                                 "Each basic type kind should have a corresponding mangler letter"
 | 
|---|
| 83 |                         );
 | 
|---|
| 84 | 
 | 
|---|
| 85 |                         const std::map<int, std::string> qualifiers = {
 | 
|---|
| 86 |                                 { Type::Const, "K" },
 | 
|---|
| 87 |                                 { Type::Volatile, "V" },
 | 
|---|
| 88 |                                 { Type::Atomic, "DA" }, // A is array, so need something unique for atmoic. For now, go with multiletter DA
 | 
|---|
| 89 |                                 { Type::Mutex, "X" },
 | 
|---|
| 90 |                         };
 | 
|---|
| 91 | 
 | 
|---|
| 92 |                         const std::string void_t = "v";
 | 
|---|
| 93 |                         const std::string zero = "Z";
 | 
|---|
| 94 |                         const std::string one = "O";
 | 
|---|
| 95 | 
 | 
|---|
| 96 |                         const std::string function = "F";
 | 
|---|
| 97 |                         const std::string tuple = "T";
 | 
|---|
| 98 |                         const std::string pointer = "P";
 | 
|---|
| 99 |                         const std::string array = "A";
 | 
|---|
| 100 |                         const std::string qualifiedTypeStart = "N";
 | 
|---|
| 101 |                         const std::string qualifiedTypeEnd = "E";
 | 
|---|
| 102 | 
 | 
|---|
| 103 |                         const std::string forall = "Q";
 | 
|---|
| 104 |                         const std::string typeVariables[] = {
 | 
|---|
| 105 |                                 "BD", // dtype
 | 
|---|
| 106 |                                 "BO", // otype
 | 
|---|
| 107 |                                 "BF", // ftype
 | 
|---|
| 108 |                                 "BT", // ttype
 | 
|---|
| 109 |                         };
 | 
|---|
| 110 |                         static_assert(
 | 
|---|
| 111 |                                 sizeof(typeVariables)/sizeof(typeVariables[0]) == TypeDecl::NUMBER_OF_KINDS,
 | 
|---|
| 112 |                                 "Each type variable kind should have a corresponding mangler prefix"
 | 
|---|
| 113 |                         );
 | 
|---|
| 114 | 
 | 
|---|
| 115 |                         const std::string struct_t = "S";
 | 
|---|
| 116 |                         const std::string union_t = "U";
 | 
|---|
| 117 |                         const std::string enum_t = "M";
 | 
|---|
| 118 |                         const std::string type = "Y";
 | 
|---|
| 119 | 
 | 
|---|
| 120 |                         const std::string autogen = "autogen__";
 | 
|---|
| 121 |                         const std::string intrinsic = "intrinsic__";
 | 
|---|
| 122 |                 } // namespace Encoding
 | 
|---|
| 123 |         } // namespace Mangler
 | 
|---|
| 124 | } // namespace SymTab
 | 
|---|