aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2017-06-13 23:37:40 +0200
committerLars Knoll <lars.knoll@qt.io>2017-06-20 09:47:20 +0000
commitf129f9469e074defe470b10e1b357e98786e8d22 (patch)
tree1ead061e78ad1b81dc58723f9465faf6c70232c4
parent196f8365b386de6c0761b864481ab2beed6b8d2d (diff)
Allow defining Labels as destinations for Jumps
Those Labels can be linked to a code location further ahead. Change-Id: I82f1a719654162db0e0abb46df602ee2e01154da Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io>
-rw-r--r--src/qml/compiler/qv4bytecodegenerator.cpp10
-rw-r--r--src/qml/compiler/qv4bytecodegenerator_p.h23
2 files changed, 25 insertions, 8 deletions
diff --git a/src/qml/compiler/qv4bytecodegenerator.cpp b/src/qml/compiler/qv4bytecodegenerator.cpp
index 444d8385d4..6ccdeef777 100644
--- a/src/qml/compiler/qv4bytecodegenerator.cpp
+++ b/src/qml/compiler/qv4bytecodegenerator.cpp
@@ -72,13 +72,15 @@ QByteArray BytecodeGenerator::finalize()
// resolve jumps
// qDebug() << "resolving jumps";
for (const auto &j : jumps) {
- Q_ASSERT(j.linkedInstruction != -1);
+ Q_ASSERT(j.linkedLabel != -1);
+ int linkedInstruction = labels.at(j.linkedLabel);
+ Q_ASSERT(linkedInstruction != -1);
int offset = instructionOffsets.at(j.instructionIndex) + j.offset;
// qDebug() << "offset data is at" << offset;
char *c = code.data() + offset;
- ptrdiff_t linkedInstruction = instructionOffsets.at(j.linkedInstruction) - offset;
-// qDebug() << "linked instruction" << j.linkedInstruction << "at " << instructionOffsets.at(j.linkedInstruction);
- memcpy(c, &linkedInstruction, sizeof(ptrdiff_t));
+ ptrdiff_t linkedInstructionOffset = instructionOffsets.at(linkedInstruction) - offset;
+// qDebug() << "linked instruction" << linkedInstruction << "at " << instructionOffsets.at(linkedInstruction);
+ memcpy(c, &linkedInstructionOffset, sizeof(ptrdiff_t));
}
return code;
diff --git a/src/qml/compiler/qv4bytecodegenerator_p.h b/src/qml/compiler/qv4bytecodegenerator_p.h
index 384fb22aa3..383b27e8d1 100644
--- a/src/qml/compiler/qv4bytecodegenerator_p.h
+++ b/src/qml/compiler/qv4bytecodegenerator_p.h
@@ -56,7 +56,13 @@ public:
: function(function) {}
struct Label {
+ BytecodeGenerator *generator;
int index;
+
+ void link() {
+ Q_ASSERT(generator->labels[index] == -1);
+ generator->labels[index] = generator->instructions.size();
+ }
};
struct Jump {
@@ -74,13 +80,21 @@ public:
link(generator->label());
}
void link(Label l) {
- Q_ASSERT(generator->jumps[index].linkedInstruction == -1);
- generator->jumps[index].linkedInstruction = l.index;
+ Q_ASSERT(generator->jumps[index].linkedLabel == -1);
+ generator->jumps[index].linkedLabel = l.index;
}
};
Label label() {
- return { instructions.size() };
+ Label l = { this, labels.size() };
+ labels.append(instructions.size());
+ return l;
+ }
+
+ Label newLabel() {
+ Label l = { this, labels.size() };
+ labels.append(-1);
+ return l;
}
template<int InstrT>
@@ -145,7 +159,7 @@ private:
struct JumpData {
int instructionIndex;
int offset;
- int linkedInstruction = -1;
+ int linkedLabel = -1;
};
struct I {
@@ -154,6 +168,7 @@ private:
};
QVector<I> instructions;
+ QVector<int> labels;
QVector<JumpData> jumps;
IR::Function *function; // ### remove me at some point
};