4 #define NANY_PRINT_sequence_OPCODES 0 5 #if NANY_PRINT_sequence_OPCODES != 0 15 if (m_capacity < count)
31 assert(offset < m_size);
32 return m_body[offset];
37 assert(offset < m_size);
38 return m_body[offset];
43 assert(offset < m_size);
50 assert(offset < m_size);
57 assert(m_size > 0 and m_capacity > 0);
58 assert(&instr >= m_body);
59 assert(&instr < m_body + m_size);
60 auto start =
reinterpret_cast<std::uintptr_t
>(m_body);
61 auto end =
reinterpret_cast<std::uintptr_t
>(&instr);
62 assert((end - start) /
sizeof(
Instruction) < 512 * 1024 * 1024);
63 uint32_t r =
static_cast<uint32_t
>(((end - start) /
sizeof(
Instruction)));
70 return (m_size > 0 and m_capacity > 0)
71 and (&instr >= m_body)
72 and (&instr < m_body + m_size);
79 return offsetOf(ir::Instruction::fromOpcode(instr));
84 cursor = m_body + m_size;
89 cursor = m_body + m_size;
94 const auto*
const end = m_body + m_size;
96 while (++instr < end) {
97 if (instr->opcodes[0] == static_cast<uint32_t>(ir::isa::Op::label)) {
98 auto& operands = (*instr).
to<ir::isa::Op::label>();
99 if (operands.label == label) {
111 const auto*
const base = m_body;
113 while (instr-- > base) {
114 if (instr->opcodes[0] == static_cast<uint32_t>(ir::isa::Op::label)) {
115 auto& operands = (*instr).
to<ir::isa::Op::label>();
116 if (operands.label == label) {
128 if (likely(offset < m_size)) {
129 auto* it = m_body + offset;
130 const auto*
const end = m_body + m_size;
131 visitor.cursor = ⁢
132 for ( ; it < end; ++it) {
133 #if NANY_PRINT_sequence_OPCODES != 0 134 std::cout <<
"== opcode == at " << (it - m_body) <<
"|" << (
void*) it <<
" :: ";
135 std::cout << it->opcodes[0] <<
": " << ir::isa::print(*
this, *it) <<
'\n';
143 template<
class T>
inline void Sequence::each(T& visitor, uint32_t offset)
const {
144 if (likely(offset < m_size)) {
145 const auto* it = m_body + offset;
146 const auto*
const end = m_body + m_size;
147 visitor.cursor = ⁢
148 for ( ; it < end; ++it) {
149 #if NANY_PRINT_sequence_OPCODES != 0 150 std::cout <<
"== opcode == at " << (it - m_body) <<
"|" << (
void*) it <<
" :: ";
151 std::cout << it->opcodes[0] <<
": " << ir::isa::print(*
this, *it) <<
'\n';
160 if (unlikely(m_capacity < m_size + 1))
163 assert(m_size + 1 <= m_capacity);
164 auto& result = at<O>(m_size++);
165 result.opcode =
static_cast<uint32_t
>(O);
isa::Operand< O > & at(uint32_t offset)
Fetch an instruction at a given offset.
Definition: sequence.hxx:42
void each(T &visitor, uint32_t offset=0)
Visit each instruction.
Definition: sequence.hxx:127
void reserve(uint32_t count)
Reserve enough memory for N instructions.
Definition: sequence.hxx:14
isa::Operand< O > & to()
Convert the instruction into an Opcode struct.
Definition: instruction.h:16
bool jumpToLabelBackward(const Instruction *&cursor, uint32_t label) const
Go to a previous label.
Definition: sequence.hxx:110
isa::Operand< O > & emit()
emit a new Instruction
Definition: sequence.hxx:159
uint32_t opcodeCount() const
Get how many instructions the sequence has.
Definition: sequence.hxx:20
Definition: instruction.h:12
bool jumpToLabelForward(const Instruction *&cursor, uint32_t label) const
Go to the next label.
Definition: sequence.hxx:93
uint32_t capacity() const
Get the capacity of the sequence (in instructions)
Definition: sequence.hxx:25
bool isCursorValid(const Instruction &instr) const
Get if a cursor is valid.
Definition: sequence.hxx:69
uint32_t offsetOf(const isa::Operand< O > &instr) const
Get the offset of an instruction within the sequence.
Definition: sequence.hxx:77
void invalidateCursor(const Instruction *&cusror) const
Get the upper limit.
Definition: sequence.hxx:83