FLANG
Mangler.h
1//===-- Lower/Mangler.h -- name mangling ------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef FORTRAN_LOWER_MANGLER_H
14#define FORTRAN_LOWER_MANGLER_H
15
16#include "flang/Evaluate/expression.h"
17#include "flang/Optimizer/Dialect/FIRType.h"
18#include "llvm/ADT/StringRef.h"
19#include <string>
20
21namespace Fortran {
22namespace common {
23template <typename>
24class Reference;
25}
26
27namespace semantics {
28class Scope;
29class Symbol;
30class DerivedTypeSpec;
31} // namespace semantics
32
33namespace lower::mangle {
34
35using ScopeBlockIdMap =
36 llvm::DenseMap<Fortran::semantics::Scope *, std::int64_t>;
37
44std::string mangleName(const semantics::Symbol &, ScopeBlockIdMap &,
45 bool keepExternalInScope = false,
46 bool underscoring = true);
47std::string mangleName(const semantics::Symbol &,
48 bool keepExternalInScope = false,
49 bool underscoring = true);
50
52std::string mangleName(const semantics::DerivedTypeSpec &, ScopeBlockIdMap &);
53
55std::string mangleName(std::string &, const Fortran::semantics::Scope &,
56 ScopeBlockIdMap &);
57
59std::string demangleName(llvm::StringRef name);
60
61std::string
62mangleArrayLiteral(size_t size,
63 const Fortran::evaluate::ConstantSubscripts &shape,
64 Fortran::common::TypeCategory cat, int kind = 0,
65 Fortran::common::ConstantSubscript charLen = -1,
66 llvm::StringRef derivedName = {});
67
68template <Fortran::common::TypeCategory TC, int KIND>
69std::string mangleArrayLiteral(
70 mlir::Type,
71 const Fortran::evaluate::Constant<Fortran::evaluate::Type<TC, KIND>> &x) {
72 return mangleArrayLiteral(x.values().size() * sizeof(x.values()[0]),
73 x.shape(), TC, KIND);
74}
75
76template <int KIND>
77std::string
78mangleArrayLiteral(mlir::Type,
79 const Fortran::evaluate::Constant<Fortran::evaluate::Type<
80 Fortran::common::TypeCategory::Character, KIND>> &x) {
81 return mangleArrayLiteral(x.values().size() * sizeof(x.values()[0]),
82 x.shape(), Fortran::common::TypeCategory::Character,
83 KIND, x.LEN());
84}
85
86inline std::string mangleArrayLiteral(
87 mlir::Type eleTy,
88 const Fortran::evaluate::Constant<Fortran::evaluate::SomeDerived> &x) {
89 return mangleArrayLiteral(x.values().size() * sizeof(x.values()[0]),
90 x.shape(), Fortran::common::TypeCategory::Derived,
91 /*kind=*/0, /*charLen=*/-1,
92 mlir::cast<fir::RecordType>(eleTy).getName());
93}
94
96std::string globalNamelistDescriptorName(const Fortran::semantics::Symbol &sym);
97
102std::string getRecordTypeFieldName(const Fortran::semantics::Symbol &component,
103 ScopeBlockIdMap &);
104
105} // namespace lower::mangle
106} // namespace Fortran
107
108#endif // FORTRAN_LOWER_MANGLER_H
Definition reference.h:18
Definition scope.h:68
Definition symbol.h:896
Definition bit-population-count.h:20
Definition bit-population-count.h:20