1 //===-- Lower/ConvertType.h -- lowering of types ----------------*- 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 /// Conversion of front-end TYPE, KIND, ATTRIBUTE (TKA) information to FIR/MLIR.
14 /// This is meant to be the single point of truth (SPOT) for all type
15 /// conversions when lowering to FIR.  This implements all lowering of parse
16 /// tree TKA to the FIR type system. If one is converting front-end types and
17 /// not using one of the routines provided here, it's being done wrong.
18 ///
19 //===----------------------------------------------------------------------===//
20 
21 #ifndef FORTRAN_LOWER_CONVERT_TYPE_H
22 #define FORTRAN_LOWER_CONVERT_TYPE_H
23 
24 #include "flang/Common/Fortran.h"
25 #include "mlir/IR/BuiltinTypes.h"
26 
27 namespace mlir {
28 class Location;
29 class MLIRContext;
30 class Type;
31 } // namespace mlir
32 
33 namespace Fortran {
34 namespace common {
35 template <typename>
36 class Reference;
37 } // namespace common
38 
39 namespace evaluate {
40 template <typename>
41 class Expr;
42 struct SomeType;
43 } // namespace evaluate
44 
45 namespace semantics {
46 class Symbol;
47 class DerivedTypeSpec;
48 } // namespace semantics
49 
50 namespace lower {
51 class AbstractConverter;
52 namespace pft {
53 struct Variable;
54 }
55 
56 using SomeExpr = evaluate::Expr<evaluate::SomeType>;
57 using SymbolRef = common::Reference<const semantics::Symbol>;
58 
59 // Type for compile time constant length type parameters.
60 using LenParameterTy = std::int64_t;
61 
62 /// Get a FIR type based on a category and kind.
63 mlir::Type getFIRType(mlir::MLIRContext *ctxt, common::TypeCategory tc,
64                       int kind, llvm::ArrayRef<LenParameterTy>);
65 
66 /// Get a FIR type for a derived type
67 mlir::Type
68 translateDerivedTypeToFIRType(Fortran::lower::AbstractConverter &,
69                               const Fortran::semantics::DerivedTypeSpec &);
70 
71 /// Translate a SomeExpr to an mlir::Type.
72 mlir::Type translateSomeExprToFIRType(Fortran::lower::AbstractConverter &,
73                                       const SomeExpr &expr);
74 
75 /// Translate a Fortran::semantics::Symbol to an mlir::Type.
76 mlir::Type translateSymbolToFIRType(Fortran::lower::AbstractConverter &,
77                                     const SymbolRef symbol);
78 
79 /// Translate a Fortran::lower::pft::Variable to an mlir::Type.
80 mlir::Type translateVariableToFIRType(Fortran::lower::AbstractConverter &,
81                                       const pft::Variable &variable);
82 
83 /// Translate a REAL of KIND to the mlir::Type.
84 mlir::Type convertReal(mlir::MLIRContext *ctxt, int KIND);
85 
86 } // namespace lower
87 } // namespace Fortran
88 
89 #endif // FORTRAN_LOWER_CONVERT_TYPE_H
90