1 //===-- Derived.cpp -- derived type runtime API ---------------------------===//
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 #include "flang/Optimizer/Builder/Runtime/Derived.h"
10 #include "flang/Optimizer/Builder/FIRBuilder.h"
11 #include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
12 #include "flang/Runtime/derived-api.h"
13 
14 using namespace Fortran::runtime;
15 
genDerivedTypeInitialize(fir::FirOpBuilder & builder,mlir::Location loc,mlir::Value box)16 void fir::runtime::genDerivedTypeInitialize(fir::FirOpBuilder &builder,
17                                             mlir::Location loc,
18                                             mlir::Value box) {
19   auto func = fir::runtime::getRuntimeFunc<mkRTKey(Initialize)>(loc, builder);
20   auto fTy = func.getFunctionType();
21   auto sourceFile = fir::factory::locationToFilename(builder, loc);
22   auto sourceLine =
23       fir::factory::locationToLineNo(builder, loc, fTy.getInput(2));
24   auto args = fir::runtime::createArguments(builder, loc, fTy, box, sourceFile,
25                                             sourceLine);
26   builder.create<fir::CallOp>(loc, func, args);
27 }
28 
genDerivedTypeDestroy(fir::FirOpBuilder & builder,mlir::Location loc,mlir::Value box)29 void fir::runtime::genDerivedTypeDestroy(fir::FirOpBuilder &builder,
30                                          mlir::Location loc, mlir::Value box) {
31   auto func = fir::runtime::getRuntimeFunc<mkRTKey(Destroy)>(loc, builder);
32   auto fTy = func.getFunctionType();
33   auto args = fir::runtime::createArguments(builder, loc, fTy, box);
34   builder.create<fir::CallOp>(loc, func, args);
35 }
36