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>
69std::string mangleArrayLiteral(
70 mlir::Type,
71 const Fortran::evaluate::Constant<Fortran::evaluate::Type<TC>> &x) {
72 const int kind{x.kind()};
73 return mangleArrayLiteral(x.values().size() * sizeof(x.values()[0]),
74 x.shape(), TC, kind);
75}
76
77inline std::string mangleArrayLiteral(
78 mlir::Type,
79 const Fortran::evaluate::Constant<
80 Fortran::evaluate::Type<Fortran::common::TypeCategory::Character>> &x) {
81 const int kind{x.kind()};
82 return mangleArrayLiteral(x.values().size() * sizeof(x.values()[0]),
83 x.shape(), Fortran::common::TypeCategory::Character,
84 kind, x.LEN());
85}
86
87inline std::string mangleArrayLiteral(
88 mlir::Type eleTy,
89 const Fortran::evaluate::Constant<Fortran::evaluate::SomeDerived> &x) {
90 return mangleArrayLiteral(x.values().size() * sizeof(x.values()[0]),
91 x.shape(), Fortran::common::TypeCategory::Derived,
92 /*kind=*/0, /*charLen=*/-1,
93 mlir::cast<fir::RecordType>(eleTy).getName());
94}
95
97std::string globalNamelistDescriptorName(const Fortran::semantics::Symbol &sym);
98
103std::string getRecordTypeFieldName(const Fortran::semantics::Symbol &component,
104 ScopeBlockIdMap &);
105
106} // namespace lower::mangle
107} // namespace Fortran
108
109#endif // FORTRAN_LOWER_MANGLER_H
Definition reference.h:18
Definition scope.h:69
Definition symbol.h:918
Definition bit-population-count.h:20
Definition bit-population-count.h:20