LLZK 0.1.0
Veridise's ZK Language IR
Loading...
Searching...
No Matches
ErrorHelper.h
Go to the documentation of this file.
1//===-- ErrorHelper.h -------------------------------------------*- C++ -*-===//
2//
3// Part of the LLZK Project, under the Apache License v2.0.
4// See LICENSE.txt for license information.
5// Copyright 2025 Veridise Inc.
6// SPDX-License-Identifier: Apache-2.0
7//
8//===----------------------------------------------------------------------===//
9
10#pragma once
11
12#include <llvm/ADT/STLFunctionalExtras.h>
13#include <llvm/ADT/Twine.h>
14#include <llvm/Support/ErrorHandling.h>
15
16namespace llzk {
17
18using EmitErrorFn = llvm::function_ref<mlir::InFlightDiagnostic()>;
19
20// This type is required by the functions below to take ownership of the lambda so it is not
21// destroyed upon return from the function. It can be implicitly converted to EmitErrorFn.
22using OwningEmitErrorFn = std::function<mlir::InFlightDiagnostic()>;
23
24inline OwningEmitErrorFn getEmitOpErrFn(mlir::Operation *op) {
25 return [op]() { return op->emitOpError(); };
26}
27
28template <typename TypeClass> inline OwningEmitErrorFn getEmitOpErrFn(TypeClass *opImpl) {
29 return getEmitOpErrFn(opImpl->getOperation());
30}
31
32inline void ensure(bool condition, llvm::Twine errMsg) {
33 if (!condition) {
34 llvm::report_fatal_error(errMsg);
35 }
36}
37
38} // namespace llzk
llvm::function_ref< mlir::InFlightDiagnostic()> EmitErrorFn
Definition ErrorHelper.h:18
void ensure(bool condition, llvm::Twine errMsg)
Definition ErrorHelper.h:32
std::function< mlir::InFlightDiagnostic()> OwningEmitErrorFn
Definition ErrorHelper.h:22
OwningEmitErrorFn getEmitOpErrFn(mlir::Operation *op)
Definition ErrorHelper.h:24