| 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 |
|
| 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 |
|
| 25 |
void fir::runtime::genAbort(fir::FirOpBuilder &builder, mlir::Location loc) { |
| 26 |
mlir::func::FuncOp abortFunc = |
| 27 |
fir::runtime::getRuntimeFunc<mkRTKey(Abort)>(loc, builder); |
| 28 |
builder.create<fir::CallOp>(loc, abortFunc, std::nullopt); |
| 29 |
} |
| 30 |
|
| 31 |
void fir::runtime::genReportFatalUserError(fir::FirOpBuilder &builder, |
| 32 |
mlir::Location loc, |
| 33 |
llvm::StringRef message) { |
| 34 |
mlir::func::FuncOp crashFunc = |
| 35 |
fir::runtime::getRuntimeFunc<mkRTKey(ReportFatalUserError)>(loc, builder); |
| 36 |
mlir::FunctionType funcTy = crashFunc.getFunctionType(); |
| 37 |
mlir::Value msgVal = fir::getBase( |
| 38 |
fir::factory::createStringLiteral(builder, loc, message.str() + '\0')); |
| 39 |
mlir::Value sourceLine = |
| 40 |
fir::factory::locationToLineNo(builder, loc, funcTy.getInput(2)); |
| 41 |
mlir::Value sourceFile = fir::factory::locationToFilename(builder, loc); |
| 42 |
llvm::SmallVector<mlir::Value> args = fir::runtime::createArguments( |
| 43 |
builder, loc, funcTy, msgVal, sourceFile, sourceLine); |
| 44 |
builder.create<fir::CallOp>(loc, crashFunc, args); |
| 45 |
} |