CIRCT  19.0.0git
VerifVisitors.h
Go to the documentation of this file.
1 //===- VerifVisitors.h - Verif dialect visitors -----------------*- 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 #ifndef CIRCT_DIALECT_VERIF_VERIFVISITORS_H
10 #define CIRCT_DIALECT_VERIF_VERIFVISITORS_H
11 
13 #include "llvm/ADT/TypeSwitch.h"
14 
15 namespace circt {
16 namespace verif {
17 template <typename ConcreteType, typename ResultType = void,
18  typename... ExtraArgs>
19 class Visitor {
20 public:
21  ResultType dispatchVerifVisitor(Operation *op, ExtraArgs... args) {
22  auto *thisCast = static_cast<ConcreteType *>(this);
23  return TypeSwitch<Operation *, ResultType>(op)
24  .template Case<AssertOp, AssumeOp, CoverOp>([&](auto op) -> ResultType {
25  return thisCast->visitVerif(op, args...);
26  })
27  .Default([&](auto) -> ResultType {
28  return thisCast->visitInvalidVerif(op, args...);
29  });
30  }
31 
32  /// This callback is invoked on any non-verif operations.
33  ResultType visitInvalidVerif(Operation *op, ExtraArgs... args) {
34  op->emitOpError("is not a verif operation");
35  abort();
36  }
37 
38  /// This callback is invoked on any verif operations that were not handled by
39  /// their concrete `visitVerif(...)` callback.
40  ResultType visitUnhandledVerif(Operation *op, ExtraArgs... args) {
41  return ResultType();
42  }
43 
44 #define HANDLE(OPTYPE, OPKIND) \
45  ResultType visitVerif(OPTYPE op, ExtraArgs... args) { \
46  return static_cast<ConcreteType *>(this)->visit##OPKIND##Verif(op, \
47  args...); \
48  }
49 
50  HANDLE(AssertOp, Unhandled);
51  HANDLE(AssumeOp, Unhandled);
52  HANDLE(CoverOp, Unhandled);
53 #undef HANDLE
54 };
55 
56 } // namespace verif
57 } // namespace circt
58 
59 #endif // CIRCT_DIALECT_VERIF_VERIFVISITORS_H
ResultType dispatchVerifVisitor(Operation *op, ExtraArgs... args)
Definition: VerifVisitors.h:21
HANDLE(AssertOp, Unhandled)
HANDLE(CoverOp, Unhandled)
HANDLE(AssumeOp, Unhandled)
ResultType visitInvalidVerif(Operation *op, ExtraArgs... args)
This callback is invoked on any non-verif operations.
Definition: VerifVisitors.h:33
ResultType visitUnhandledVerif(Operation *op, ExtraArgs... args)
This callback is invoked on any verif operations that were not handled by their concrete visitVerif(....
Definition: VerifVisitors.h:40
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
Definition: DebugAnalysis.h:21
Definition: verif.py:1