1 //===-- jitcs_instruction.h - interface to single instruction ---*- C++ -*-===//
5 //===----------------------------------------------------------------------===//
7 #ifndef _JITCS_INSTRUCTION_H_
8 #define _JITCS_INSTRUCTION_H_
10 #include "jitcs_adt_ref.h"
11 #include "jitcs_base.h"
12 #include "jitcs_ids.h"
17 struct MemoryReference
;
18 struct VirtualRegister
;
23 template <typename
...T
>
24 void setAll(InsId id
, T
... args
) { setInsId(id
); _setAll(1, args
...); }
26 void setInsId(InsId id
) { _ptr
[0] = id
; }
27 void setRRefOp(size_t i
, Ref
<const VirtualRegister
> r
) { _setOpRef
<const VirtualRegister
>(i
, r
); }
28 void setMRefOp(size_t i
, Ref
<MemoryReference
> m
) { _setOpRef
<MemoryReference
>(i
, m
); }
29 void setBBOp (size_t i
, Ref
<BasicBlock
> bb
) { _setOpRef
<BasicBlock
>(i
, bb
); }
30 void setImmOp (size_t i
, iptr imm
) { _ptr
[i
] = imm
; }
32 InsId
getInsId() const { return static_cast<InsId
>(_ptr
[0]); }
34 Ref
<const VirtualRegister
> getRRefOp(size_t i
) const {
35 return _getOpRef
<const VirtualRegister
>(i
);
37 Ref
<const VirtualRegister
> getConstRRefOp(size_t i
) const {
38 return _getConstOpRef
<VirtualRegister
>(i
);
41 Ref
<MemoryReference
> getMRefOp(size_t i
) const { return _getOpRef
<MemoryReference
>(i
); }
42 Ref
<BasicBlock
> getBBOp (size_t i
) const { return _getOpRef
<BasicBlock
>(i
); }
43 Ref
<BasicBlockImpl
> getBBIOp (size_t i
) const { return _getOpRef
<BasicBlockImpl
>(i
); }
44 iptr
getImmOp (size_t i
) const { return _ptr
[i
]; }
46 Ref
<MemoryReference
> getMRefOp(size_t i
) { return _getOpRef
<MemoryReference
>(i
); }
47 Ref
<BasicBlock
> getBBOp (size_t i
) { return _getOpRef
<BasicBlock
>(i
); }
48 Ref
<BasicBlockImpl
> getBBIOp (size_t i
) { return _getOpRef
<BasicBlockImpl
>(i
); }
50 Ref
<const MemoryReference
> getConstMRefOp(size_t i
) const { return _getConstOpRef
<MemoryReference
>(i
); }
51 Ref
<const BasicBlock
> getConstBBOp (size_t i
) const { return _getConstOpRef
<BasicBlock
>(i
); }
52 Ref
<const BasicBlockImpl
> getConstBBIOp (size_t i
) const { return _getConstOpRef
<BasicBlockImpl
>(i
); }
56 inline void _setOp(int i
, T
* p
) { _ptr
[i
] = reinterpret_cast<intptr_t>(p
); }
58 inline void _setOpRef(int i
, Ref
<T
> p
) { _setOp(i
, p
._ptr
); }
60 inline T
_getOp(int i
) const { return reinterpret_cast<T
>(_ptr
[i
]); }
62 inline Ref
<T
> _getOpRef(int i
) const { return Ref
<T
>(_getOp
<T
*>(i
)); }
64 inline Ref
<const T
> _getConstOpRef(int i
) const { return Ref
<const T
>(_getOp
<T
*>(i
)); }
66 inline void _set(int i
, Ref
<const VirtualRegister
> r
) { setRRefOp(i
, r
); }
67 inline void _set(int i
, Ref
<MemoryReference
> m
) { setMRefOp(i
, m
); }
68 inline void _set(int i
, Ref
<BasicBlock
> bb
) { setBBOp(i
, bb
); }
69 inline void _set(int i
, iptr imm
) { setImmOp(i
, imm
); }
70 inline void _setAll(int i
) {}
71 template <typename U
, typename
...T
>
72 inline void _setAll(int i
, U first
, T
... args
) { _set(i
, first
); _setAll(i
+ 1, args
...); }
75 } // end of namespace jitcs
78 // _JITCS_INSTRUCTION_H_