llir-opt
0.0.1
Low-Level Post-Link Optimiser for OCaml and C
core
inst_visitor.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/insts.h"
8
9
10
14
template
<
typename
T>
15
class
InstVisitor
{
16
public
:
17
virtual
~
InstVisitor
() {}
18
19
T Dispatch(
Inst
&i)
20
{
21
switch
(i.
GetKind
()) {
22
#define GET_INST(kind, type, name, sort) \
23
case Inst::Kind::kind: return Visit##type(static_cast<type &>(i));
24
#include "instructions.def"
25
}
26
llvm_unreachable(
"invalid instruction kind"
);
27
}
28
29
public
:
30
virtual
T VisitInst(
Inst
&i) = 0;
31
32
public
:
33
#define GET_KIND(base, sort) \
34
virtual T Visit##base(base &i) { return Visit##sort(i); }
35
#include "instructions.def"
36
37
#define GET_INST(kind, type, name, sort) \
38
virtual T Visit##type(type &i) { return Visit##sort(i); }
39
#include "instructions.def"
40
};
41
45
template
<
typename
T>
46
class
ConstInstVisitor
{
47
public
:
48
virtual
~
ConstInstVisitor
() {}
49
50
T Dispatch(
const
Inst
&i)
51
{
52
switch
(i.
GetKind
()) {
53
#define GET_INST(kind, type, name, sort) \
54
case Inst::Kind::kind: return Visit##type(static_cast<const type &>(i));
55
#include "instructions.def"
56
}
57
llvm_unreachable(
"invalid instruction kind"
);
58
}
59
60
public
:
61
virtual
T VisitInst(
const
Inst
&i) = 0;
62
63
public
:
64
#define GET_KIND(base, sort) \
65
virtual T Visit##base(const base &i) { return Visit##sort(i); }
66
#include "instructions.def"
67
68
#define GET_INST(kind, type, name, sort) \
69
virtual T Visit##type(const type &i) { return Visit##sort(i); }
70
#include "instructions.def"
71
};
Inst
Definition:
inst.h:53
Inst::GetKind
Kind GetKind() const
Returns the instruction kind.
Definition:
inst.h:82
ConstInstVisitor
Definition:
inst_visitor.h:46
InstVisitor
Definition:
inst_visitor.h:15
Generated by
1.8.17