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 class Target;
12 
13 
14 
18 class Verifier final : public ConstInstVisitor<void> {
19 public:
21  Verifier(const Target *target);
22 
24  bool Run(Prog &prog);
25 
26 private:
28  void Verify(Func &func);
29 
31  void CheckInteger(
32  const Inst &inst,
33  ConstRef<Inst> ref,
34  const char *msg = "not an integer"
35  );
36 
38  void CheckPointer(
39  const Inst &inst,
40  ConstRef<Inst> ref,
41  const char *msg = "not a pointer"
42  );
43 
45  void CheckType(
46  const Inst &inst,
47  ConstRef<Inst> ref,
48  Type type
49  );
51  [[noreturn]] void Error(const Block &i, llvm::Twine msg);
53  [[noreturn]] void Error(const Inst &i, llvm::Twine msg);
54 
55 private:
56  void VisitInst(const Inst &i) override { }
57  void VisitConstInst(const ConstInst &i) override;
58  void VisitOperatorInst(const OperatorInst &i) override {}
59  void VisitUnaryInst(const UnaryInst &i) override;
60  void VisitConversionInst(const ConversionInst &i) override {}
61  void VisitBinaryInst(const BinaryInst &i) override;
62  void VisitOverflowInst(const OverflowInst &i) override;
63  void VisitShiftRotateInst(const ShiftRotateInst &i) override;
64  void VisitDivisionRemainderInst(const DivisionRemainderInst &i) override {}
65  void VisitMemoryInst(const MemoryInst &i) override;
66  void VisitBarrierInst(const BarrierInst &i) override;
67  void VisitMemoryExchangeInst(const MemoryExchangeInst &i) override;
68  void VisitMemoryCompareExchangeInst(const MemoryCompareExchangeInst &i) override;
69  void VisitLoadLinkInst(const LoadLinkInst &i) override;
70  void VisitStoreCondInst(const StoreCondInst &i) override;
71  void VisitControlInst(const ControlInst &i) override {}
72  void VisitTerminatorInst(const TerminatorInst &i) override {}
73  void VisitCallSite(const CallSite &i) override;
74  void VisitX86_FPUControlInst(const X86_FPUControlInst &i) override;
75  void VisitPhiInst(const PhiInst &i) override;
76  void VisitMovInst(const MovInst &i) override;
77  void VisitAllocaInst(const AllocaInst &i) override;
78  void VisitFrameInst(const FrameInst &i) override;
79  void VisitSetInst(const SetInst &i) override;
80  void VisitGetInst(const GetInst &i) override;
81  void VisitCmpInst(const CmpInst &i) override;
82  void VisitSyscallInst(const SyscallInst &i) override;
83  void VisitArgInst(const ArgInst &i) override;
84  void VisitRaiseInst(const RaiseInst &i) override;
85  void VisitLandingPadInst(const LandingPadInst &i) override;
86  void VisitLoadInst(const LoadInst &i) override;
87  void VisitStoreInst(const StoreInst &i) override;
88  void VisitVaStartInst(const VaStartInst &i) override;
89  void VisitSelectInst(const SelectInst &i) override;
90 
91 private:
93  Type ptrTy_;
94 };
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