llir-opt  0.0.1
Low-Level Post-Link Optimiser for OCaml and C
verifier.h
1 // This file if part of the llir-opt project.
2 // Licensing information can be found in the LICENSE file.
3 // (C) 2018 Nandor Licker. All rights reserved.
4 
5 #pragma once
6 
7 #include "core/inst_visitor.h"
8 
9 class Func;
10 class MovInst;
11 
12 
13 
17 class Verifier final : public ConstInstVisitor<void> {
18 public:
20  Verifier(Target *target);
21 
23  bool Run(Prog &prog);
24 
25 private:
27  void Verify(Func &func);
28 
30  void CheckInteger(
31  const Inst &inst,
32  ConstRef<Inst> ref,
33  const char *msg = "not an integer"
34  );
35 
37  void CheckPointer(
38  const Inst &inst,
39  ConstRef<Inst> ref,
40  const char *msg = "not a pointer"
41  );
42 
44  void CheckType(
45  const Inst &inst,
46  ConstRef<Inst> ref,
47  Type type
48  );
50  [[noreturn]] void Error(const Block &i, llvm::Twine msg);
52  [[noreturn]] void Error(const Inst &i, llvm::Twine msg);
53 
54 private:
55  void VisitInst(const Inst &i) override { }
56  void VisitConstInst(const ConstInst &i) override;
57  void VisitOperatorInst(const OperatorInst &i) override {}
58  void VisitUnaryInst(const UnaryInst &i) override;
59  void VisitConversionInst(const ConversionInst &i) override {}
60  void VisitBinaryInst(const BinaryInst &i) override;
61  void VisitOverflowInst(const OverflowInst &i) override;
62  void VisitShiftRotateInst(const ShiftRotateInst &i) override;
63  void VisitDivisionRemainderInst(const DivisionRemainderInst &i) override {}
64  void VisitMemoryInst(const MemoryInst &i) override;
65  void VisitBarrierInst(const BarrierInst &i) override;
66  void VisitMemoryExchangeInst(const MemoryExchangeInst &i) override;
67  void VisitMemoryCompareExchangeInst(const MemoryCompareExchangeInst &i) override;
68  void VisitLoadLinkInst(const LoadLinkInst &i) override;
69  void VisitStoreCondInst(const StoreCondInst &i) override;
70  void VisitControlInst(const ControlInst &i) override {}
71  void VisitTerminatorInst(const TerminatorInst &i) override {}
72  void VisitCallSite(const CallSite &i) override;
73  void VisitX86_FPUControlInst(const X86_FPUControlInst &i) override;
74  void VisitPhiInst(const PhiInst &i) override;
75  void VisitMovInst(const MovInst &i) override;
76  void VisitAllocaInst(const AllocaInst &i) override;
77  void VisitFrameInst(const FrameInst &i) override;
78  void VisitSetInst(const SetInst &i) override;
79  void VisitGetInst(const GetInst &i) override;
80  void VisitCmpInst(const CmpInst &i) override;
81  void VisitSyscallInst(const SyscallInst &i) override;
82  void VisitArgInst(const ArgInst &i) override;
83  void VisitRaiseInst(const RaiseInst &i) override;
84  void VisitLandingPadInst(const LandingPadInst &i) override;
85  void VisitLoadInst(const LoadInst &i) override;
86  void VisitStoreInst(const StoreInst &i) override;
87  void VisitVaStartInst(const VaStartInst &i) override;
88  void VisitSelectInst(const SelectInst &i) override;
89 
90 private:
92  Type ptrTy_;
93 };
Inst
Definition: inst.h:53
Func
Definition: func.h:30
ConstRef< Inst >
Verifier
Definition: verifier.h:18
Target
Definition: target.h:24
MovInst
Definition: mov.h:17
ConstInstVisitor
Definition: inst_visitor.h:46
Prog
Definition: prog.h:33
Verifier::Verifier
Verifier(const Target *target)
Initialises the pass.
Definition: verifier.cpp:27
Block
Definition: block.h:29
PhiInst
Definition: phi.h:14
Verifier::Run
bool Run(Prog &prog)
Runs the pass.
Definition: verifier.cpp:33