diff options
| author | Lars Knoll <lars.knoll@qt.io> | 2017-06-13 10:06:03 +0200 |
|---|---|---|
| committer | Erik Verbruggen <erik.verbruggen@qt.io> | 2017-06-19 13:36:00 +0000 |
| commit | 5e9551ec5b1a782882f93310f8f07be51bb17bf7 (patch) | |
| tree | 6db063718c5b6d602e2bc152a5a74843a5df16a1 /src/qml/compiler/qv4bytecodegenerator.cpp | |
| parent | 4d329ef984d0f64b9446321ef63fc5a70cd103cd (diff) | |
Rework and implement Jump handling in the bytecode generator
Add Label and Jump classes to facilitate the handling, and
resolve them to proper offsets at finalize() time.
Change-Id: Ic140a3ceb848fb29657a1b156c97b806db6dc434
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4bytecodegenerator.cpp')
| -rw-r--r-- | src/qml/compiler/qv4bytecodegenerator.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/qml/compiler/qv4bytecodegenerator.cpp b/src/qml/compiler/qv4bytecodegenerator.cpp index 71288b814c..0073cb4598 100644 --- a/src/qml/compiler/qv4bytecodegenerator.cpp +++ b/src/qml/compiler/qv4bytecodegenerator.cpp @@ -62,9 +62,21 @@ QByteArray BytecodeGenerator::finalize() code.append(reinterpret_cast<const char *>(&push), InstrMeta<Instr::Push>::Size); // content + QVector<int> instructionOffsets; + instructionOffsets.reserve(instructions.size()); for (const auto &i : qAsConst(instructions)) { + instructionOffsets.append(code.size()); code.append(reinterpret_cast<const char *>(&i.instr), i.size); } + // resolve jumps + for (const auto &j : jumps) { + Q_ASSERT(j.linkedInstruction != -1); + int offset = instructionOffsets.at(j.instructionIndex) + j.offset; + char *c = code.data() + offset; + int linkedInstruction = instructionOffsets.at(j.linkedInstruction) - offset; + memcpy(c, &linkedInstruction, sizeof(int)); + } + return code; } |
