1 //===-- Stop.h - generate stop runtime API calls ----------------*- 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 #include "flang/Optimizer/Builder/Runtime/Stop.h"
10 #include "flang/Optimizer/Builder/BoxValue.h"
11 #include "flang/Optimizer/Builder/FIRBuilder.h"
12 #include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
13 #include "flang/Runtime/stop.h"
14
15 using namespace Fortran::runtime;
16
genExit(fir::FirOpBuilder & builder,mlir::Location loc,mlir::Value status)17 void fir::runtime::genExit(fir::FirOpBuilder &builder, mlir::Location loc,
18 mlir::Value status) {
19 auto exitFunc = fir::runtime::getRuntimeFunc<mkRTKey(Exit)>(loc, builder);
20 llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments(
21 builder, loc, exitFunc.getFunctionType(), status);
22 builder.create<fir::CallOp>(loc, exitFunc, args);
23 }
24
genReportFatalUserError(fir::FirOpBuilder & builder,mlir::Location loc,llvm::StringRef message)25 void fir::runtime::genReportFatalUserError(fir::FirOpBuilder &builder,
26 mlir::Location loc,
27 llvm::StringRef message) {
28 mlir::func::FuncOp crashFunc =
29 fir::runtime::getRuntimeFunc<mkRTKey(ReportFatalUserError)>(loc, builder);
30 mlir::FunctionType funcTy = crashFunc.getFunctionType();
31 mlir::Value msgVal = fir::getBase(
32 fir::factory::createStringLiteral(builder, loc, message.str() + '\0'));
33 mlir::Value sourceLine =
34 fir::factory::locationToLineNo(builder, loc, funcTy.getInput(2));
35 mlir::Value sourceFile = fir::factory::locationToFilename(builder, loc);
36 llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments(
37 builder, loc, funcTy, msgVal, sourceFile, sourceLine);
38 builder.create<fir::CallOp>(loc, crashFunc, args);
39 }
40