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 "mlir/IR/BuiltinTypes.h"
19#include "llvm/ADT/StringRef.h"
20#include <string>
21
22namespace Fortran {
23namespace common {
24template <typename>
25class Reference;
26}
27
28namespace semantics {
29class Scope;
30class Symbol;
31class DerivedTypeSpec;
32} // namespace semantics
33
34namespace lower::mangle {
35
36using ScopeBlockIdMap =
37 llvm::DenseMap<Fortran::semantics::Scope *, std::int64_t>;
38
45std::string mangleName(const semantics::Symbol &, ScopeBlockIdMap &,
46 bool keepExternalInScope = false,
47 bool underscoring = true);
48std::string mangleName(const semantics::Symbol &,
49 bool keepExternalInScope = false,
50 bool underscoring = true);
51
53std::string mangleName(const semantics::DerivedTypeSpec &, ScopeBlockIdMap &);
54
56std::string mangleName(std::string &, const Fortran::semantics::Scope &,
57 ScopeBlockIdMap &);
58
60std::string demangleName(llvm::StringRef name);
61
62std::string
63mangleArrayLiteral(size_t size,
64 const Fortran::evaluate::ConstantSubscripts &shape,
65 Fortran::common::TypeCategory cat, int kind = 0,
66 Fortran::common::ConstantSubscript charLen = -1,
67 llvm::StringRef derivedName = {});
68
69template <Fortran::common::TypeCategory TC, int KIND>
70std::string mangleArrayLiteral(
71 mlir::Type,
73 return mangleArrayLiteral(x.values().size() * sizeof(x.values()[0]),
74 x.shape(), TC, KIND);
75}
76
77template <int KIND>
78std::string
79mangleArrayLiteral(mlir::Type,
81 Fortran::common::TypeCategory::Character, KIND>> &x) {
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,
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: constant.h:141
Definition: type.h:56
Definition: scope.h:58
Definition: symbol.h:712
Definition: bit-population-count.h:20