35 m_generator->instructions.append(makeInstruction(Instruction::Debug(), line, before.statement));
41 QList<
int> &labels = m_generator->labels;
42 I jump = makeJumpInstruction(Instruction::Jump(), before.line, before.statement);
43 jump.linkedLabel = labels.size();
44 labels.append(m_generator->instructions.size() + 2);
45 m_generator->labelReachable.append(
true);
46 m_generator->instructions.append(jump);
52 Q_ASSERT(!m_generator->m_sourceLocationTable);
54 const QList<I> instructions = std::exchange(m_generator->instructions, {});
56 QList<
int> &labels = m_generator->labels;
57 const qsizetype labelCount = labels.size();
64 std::vector<
int> labelJumpLines(labelCount, NoJumpLine);
65 for (qsizetype i = 0, end = instructions.size(); i != end; ++i) {
66 const I &instruction = instructions[i];
67 if (instruction.linkedLabel == -1 || instruction.type == Instr::Type::SetUnwindHandler)
69 if (labels[instruction.linkedLabel] <= i)
71 int &jumpLine = labelJumpLines[instruction.linkedLabel];
72 jumpLine = mergeJumpLines(jumpLine, instruction.line);
76 std::vector<
int> positionJumpLines(instructions.size(), NoJumpLine);
77 for (qsizetype i = 0; i < labelCount; ++i) {
80 int &jumpLine = positionJumpLines[labels[i]];
81 jumpLine = mergeJumpLines(jumpLine, labelJumpLines[i]);
90 bool jumpOverDebug =
false;
92 std::vector<Position> positions(instructions.size());
94 for (qsizetype i = 0, end = instructions.size(); i != end; ++i) {
95 Position &position = positions[i];
96 position.first = m_generator->instructions.size();
97 const I &instruction = instructions[i];
101 const bool jumpFromOtherLine = instruction.locationSetAfterLabel
102 && isFromOtherLine(positionJumpLines[i], instruction.line);
104 if (i == 0 || instruction.line != instructions[i - 1].line) {
105 appendDebug(instruction.line, instruction);
106 }
else if (jumpFromOtherLine) {
109 if (!BytecodeGenerator::endsFlow(instructions[i - 1].type)) {
110 appendJumpOverDebug(instruction);
111 position.jumpOverDebug =
true;
113 position.debug = m_generator->instructions.size();
114 appendDebug(instruction.line, instruction);
115 }
else if (instruction.type == Instr::Type::Ret) {
117 appendDebug(-instruction.line, instruction);
120 position.instruction = m_generator->instructions.size();
121 m_generator->instructions.append(instruction);
124 for (qsizetype i = 0; i < labelCount; ++i) {
125 int &label = labels[i];
126 Q_ASSERT(label != BytecodeGenerator::Label::Unlinked);
128 if (label == BytecodeGenerator::Label::Dead)
130 Q_ASSERT(label < instructions.size());
131 const Position &position = positions[label];
132 if (!position.jumpOverDebug) {
133 label = position.first;
139 label = isFromOtherLine(labelJumpLines[i], instructions[label].line)
141 : position.instruction;