brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 5629371 Raw
46 lines · cpp
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-exception6//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 15using namespace Fortran::runtime;16 17void 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  fir::CallOp::create(builder, loc, exitFunc, args);23}24 25void fir::runtime::genAbort(fir::FirOpBuilder &builder, mlir::Location loc) {26  mlir::func::FuncOp abortFunc =27      fir::runtime::getRuntimeFunc<mkRTKey(Abort)>(loc, builder);28  fir::CallOp::create(builder, loc, abortFunc, mlir::ValueRange{});29}30 31void 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  fir::CallOp::create(builder, loc, crashFunc, args);45}46