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 <mlir/IR/Diagnostics.h>
13#include <mlir/IR/Operation.h>
14
15#include <llvm/ADT/STLFunctionalExtras.h>
16#include <llvm/ADT/Twine.h>
17#include <llvm/Support/ErrorHandling.h>
18
19namespace llzk {
20
21using EmitErrorFn = llvm::function_ref<mlir::InFlightDiagnostic()>;
22
23// This type is required by the functions below to take ownership of the lambda so it is not
24// destroyed upon return from the function. It can be implicitly converted to EmitErrorFn.
25using OwningEmitErrorFn = std::function<mlir::InFlightDiagnostic()>;
26
27inline OwningEmitErrorFn getEmitOpErrFn(mlir::Operation *op) {
28 return [op]() { return op->emitOpError(); };
29}
30
31template <typename TypeClass> inline OwningEmitErrorFn getEmitOpErrFn(TypeClass *opImpl) {
32 return getEmitOpErrFn(opImpl->getOperation());
33}
34
35inline void ensure(bool condition, llvm::Twine errMsg) {
36 if (!condition) {
37 llvm::report_fatal_error(errMsg);
38 }
39}
40
41} // namespace llzk
llvm::function_ref< mlir::InFlightDiagnostic()> EmitErrorFn
Definition ErrorHelper.h:21
void ensure(bool condition, llvm::Twine errMsg)
Definition ErrorHelper.h:35
std::function< mlir::InFlightDiagnostic()> OwningEmitErrorFn
Definition ErrorHelper.h:25
OwningEmitErrorFn getEmitOpErrFn(mlir::Operation *op)
Definition ErrorHelper.h:27