2020-01-09 05:27:32 +08:00
|
|
|
//===-- runtime/terminator.h ------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
//
|
2020-01-11 04:12:03 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2020-01-09 05:27:32 +08:00
|
|
|
|
|
|
|
// Termination of the image
|
|
|
|
|
|
|
|
#ifndef FORTRAN_RUNTIME_TERMINATOR_H_
|
|
|
|
#define FORTRAN_RUNTIME_TERMINATOR_H_
|
|
|
|
|
2021-09-02 07:00:53 +08:00
|
|
|
#include "flang/Runtime/entry-names.h"
|
2020-01-09 05:27:32 +08:00
|
|
|
#include <cstdarg>
|
|
|
|
|
|
|
|
namespace Fortran::runtime {
|
|
|
|
|
|
|
|
// A mixin class for statement-specific image error termination
|
|
|
|
// for errors detected in the runtime library
|
|
|
|
class Terminator {
|
|
|
|
public:
|
|
|
|
Terminator() {}
|
2020-02-05 08:55:45 +08:00
|
|
|
Terminator(const Terminator &) = default;
|
2020-01-09 05:27:32 +08:00
|
|
|
explicit Terminator(const char *sourceFileName, int sourceLine = 0)
|
2020-03-29 12:00:16 +08:00
|
|
|
: sourceFileName_{sourceFileName}, sourceLine_{sourceLine} {}
|
2021-04-21 00:19:21 +08:00
|
|
|
|
|
|
|
const char *sourceFileName() const { return sourceFileName_; }
|
|
|
|
int sourceLine() const { return sourceLine_; }
|
|
|
|
|
2020-01-09 05:27:32 +08:00
|
|
|
void SetLocation(const char *sourceFileName = nullptr, int sourceLine = 0) {
|
|
|
|
sourceFileName_ = sourceFileName;
|
|
|
|
sourceLine_ = sourceLine;
|
|
|
|
}
|
2020-02-05 08:55:45 +08:00
|
|
|
[[noreturn]] void Crash(const char *message, ...) const;
|
|
|
|
[[noreturn]] void CrashArgs(const char *message, va_list &) const;
|
2020-01-17 05:51:25 +08:00
|
|
|
[[noreturn]] void CheckFailed(
|
2020-02-05 08:55:45 +08:00
|
|
|
const char *predicate, const char *file, int line) const;
|
2020-11-11 07:13:02 +08:00
|
|
|
[[noreturn]] void CheckFailed(const char *predicate) const;
|
2020-01-09 05:27:32 +08:00
|
|
|
|
2020-02-14 06:41:56 +08:00
|
|
|
// For test harnessing - overrides CrashArgs().
|
2020-07-05 05:24:32 +08:00
|
|
|
static void RegisterCrashHandler(void (*)(const char *sourceFile,
|
|
|
|
int sourceLine, const char *message, va_list &ap));
|
2020-02-14 06:41:56 +08:00
|
|
|
|
2020-01-09 05:27:32 +08:00
|
|
|
private:
|
|
|
|
const char *sourceFileName_{nullptr};
|
|
|
|
int sourceLine_{0};
|
|
|
|
};
|
|
|
|
|
2020-02-14 06:41:56 +08:00
|
|
|
// RUNTIME_CHECK() guarantees evaluation of its predicate.
|
2020-01-17 05:51:25 +08:00
|
|
|
#define RUNTIME_CHECK(terminator, pred) \
|
|
|
|
if (pred) \
|
|
|
|
; \
|
|
|
|
else \
|
|
|
|
(terminator).CheckFailed(#pred, __FILE__, __LINE__)
|
|
|
|
|
2020-11-11 07:13:02 +08:00
|
|
|
#define INTERNAL_CHECK(pred) \
|
|
|
|
if (pred) \
|
|
|
|
; \
|
|
|
|
else \
|
|
|
|
Terminator{__FILE__, __LINE__}.CheckFailed(#pred)
|
|
|
|
|
2020-01-09 05:27:32 +08:00
|
|
|
void NotifyOtherImagesOfNormalEnd();
|
|
|
|
void NotifyOtherImagesOfFailImageStatement();
|
|
|
|
void NotifyOtherImagesOfErrorTermination();
|
2020-03-29 12:00:16 +08:00
|
|
|
} // namespace Fortran::runtime
|
2020-02-05 08:55:45 +08:00
|
|
|
|
|
|
|
namespace Fortran::runtime::io {
|
|
|
|
void FlushOutputOnCrash(const Terminator &);
|
|
|
|
}
|
|
|
|
|
2020-03-29 12:00:16 +08:00
|
|
|
#endif // FORTRAN_RUNTIME_TERMINATOR_H_
|