diff options
author | Lars Knoll <lars.knoll@qt.io> | 2017-08-24 14:46:45 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2017-08-28 13:18:48 +0000 |
commit | 7f0bb07631648ffbe70b92c42fb10e04280d95bd (patch) | |
tree | 02cdb455458fd80cbd80bf8de6f04e68ba20e2af /src/qml/compiler | |
parent | 062dd5c38379e660c75092260e94d3c5a103ae17 (diff) |
Get rid of the separate vector of Jumps
Instead add it to the unencoded instruction vector
Change-Id: I7e88d808bb94f75aecdf9d3ed9bace2055c1da5d
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/compiler')
-rw-r--r-- | src/qml/compiler/qv4bytecodegenerator.cpp | 13 | ||||
-rw-r--r-- | src/qml/compiler/qv4bytecodegenerator_p.h | 28 |
2 files changed, 19 insertions, 22 deletions
diff --git a/src/qml/compiler/qv4bytecodegenerator.cpp b/src/qml/compiler/qv4bytecodegenerator.cpp index 1d4e91bdf6..8c0f809a28 100644 --- a/src/qml/compiler/qv4bytecodegenerator.cpp +++ b/src/qml/compiler/qv4bytecodegenerator.cpp @@ -90,14 +90,17 @@ void BytecodeGenerator::finalize(Compiler::Context *context) // resolve jumps // qDebug() << "resolving jumps"; - for (const auto &j : jumps) { - Q_ASSERT(j.linkedLabel != -1); - int linkedInstruction = labels.at(j.linkedLabel); + for (int index = 0; index < instructions.size(); ++index) { + const auto &i = instructions.at(index); + if (i.offsetForJump == -1) // no jump + continue; + Q_ASSERT(i.linkedLabel != -1); + int linkedInstruction = labels.at(i.linkedLabel); Q_ASSERT(linkedInstruction != -1); - int offset = instructionOffsets.at(j.instructionIndex) + j.offset; + int offset = instructionOffsets.at(index) + i.offsetForJump; // qDebug() << "offset data is at" << offset; char *c = code.data() + offset; - int linkedInstructionOffset = instructionOffsets.at(linkedInstruction) - instructionOffsets.at(j.instructionIndex + 1); + int linkedInstructionOffset = instructionOffsets.at(linkedInstruction) - instructionOffsets.at(index + 1); // qDebug() << "linked instruction" << linkedInstruction << "at " << instructionOffsets.at(linkedInstruction); memcpy(c, &linkedInstructionOffset, sizeof(int)); } diff --git a/src/qml/compiler/qv4bytecodegenerator_p.h b/src/qml/compiler/qv4bytecodegenerator_p.h index c00c80f0f4..6439009230 100644 --- a/src/qml/compiler/qv4bytecodegenerator_p.h +++ b/src/qml/compiler/qv4bytecodegenerator_p.h @@ -99,13 +99,12 @@ public: }; struct Jump { - Jump(BytecodeGenerator *generator, int instruction, int offset) + Jump(BytecodeGenerator *generator, int instruction) : generator(generator), - index(generator->jumps.size()) { - generator->jumps.append({ instruction, offset, -1 }); - } + index(instruction) + {} ~Jump() { - Q_ASSERT(generator->jumps[index].linkedLabel != -1); + Q_ASSERT(generator->instructions[index].linkedLabel != -1); } @@ -117,8 +116,8 @@ public: } void link(Label l) { Q_ASSERT(l.index >= 0); - Q_ASSERT(generator->jumps[index].linkedLabel == -1); - generator->jumps[index].linkedLabel = l.index; + Q_ASSERT(generator->instructions[index].linkedLabel == -1); + generator->instructions[index].linkedLabel = l.index; } }; @@ -231,7 +230,7 @@ public: Instr genericInstr; genericInstr.Nop.instructionType = InstrT; InstrMeta<InstrT>::setDataNoCommon(genericInstr, data); - return Jump(this, addInstructionHelper(InstrMeta<InstrT>::Size, genericInstr), offsetof(InstrData<InstrT>, offset)); + return Jump(this, addInstructionHelper(InstrMeta<InstrT>::Size, genericInstr, offsetof(InstrData<InstrT>, offset))); } private: @@ -239,27 +238,22 @@ private: friend struct Label; friend struct ExceptionHandler; - int addInstructionHelper(uint size, const Instr &i) { + int addInstructionHelper(uint size, const Instr &i, int offsetOfOffset = -1) { int pos = instructions.size(); - instructions.append({size, currentLine, i}); + instructions.append({size, currentLine, offsetOfOffset, -1, i}); return pos; } - struct JumpData { - int instructionIndex; - int offset; - int linkedLabel; - }; - struct I { uint size; int line; + int offsetForJump; + int linkedLabel; Instr instr; }; QVector<I> instructions; QVector<int> labels; - QVector<JumpData> jumps; ExceptionHandler *currentExceptionHandler; int regCount = 0; public: |