aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/compiler/qv4bytecodegenerator_p.h
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 /src/qml/compiler/qv4bytecodegenerator_p.h
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>
Diffstat (limited to 'src/qml/compiler/qv4bytecodegenerator_p.h')
-rw-r--r--src/qml/compiler/qv4bytecodegenerator_p.h23
1 files changed, 19 insertions, 4 deletions
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
};